use of android.appwidget.AppWidgetProviderInfo in project android_frameworks_base by ResurrectionRemix.
the class AppWidgetServiceImpl method parseProviderInfoXml.
@SuppressWarnings("deprecation")
private Provider parseProviderInfoXml(ProviderId providerId, ResolveInfo ri) {
Provider provider = null;
ActivityInfo activityInfo = ri.activityInfo;
XmlResourceParser parser = null;
try {
parser = activityInfo.loadXmlMetaData(mContext.getPackageManager(), AppWidgetManager.META_DATA_APPWIDGET_PROVIDER);
if (parser == null) {
Slog.w(TAG, "No " + AppWidgetManager.META_DATA_APPWIDGET_PROVIDER + " meta-data for " + "AppWidget provider '" + providerId + '\'');
return null;
}
AttributeSet attrs = Xml.asAttributeSet(parser);
int type;
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && type != XmlPullParser.START_TAG) {
// drain whitespace, comments, etc.
}
String nodeName = parser.getName();
if (!"appwidget-provider".equals(nodeName)) {
Slog.w(TAG, "Meta-data does not start with appwidget-provider tag for" + " AppWidget provider " + providerId.componentName + " for user " + providerId.uid);
return null;
}
provider = new Provider();
provider.id = providerId;
AppWidgetProviderInfo info = provider.info = new AppWidgetProviderInfo();
info.provider = providerId.componentName;
info.providerInfo = activityInfo;
final Resources resources;
final long identity = Binder.clearCallingIdentity();
try {
final PackageManager pm = mContext.getPackageManager();
final int userId = UserHandle.getUserId(providerId.uid);
final ApplicationInfo app = pm.getApplicationInfoAsUser(activityInfo.packageName, 0, userId);
resources = pm.getResourcesForApplication(app);
} finally {
Binder.restoreCallingIdentity(identity);
}
TypedArray sa = resources.obtainAttributes(attrs, com.android.internal.R.styleable.AppWidgetProviderInfo);
// These dimensions has to be resolved in the application's context.
// We simply send back the raw complex data, which will be
// converted to dp in {@link AppWidgetManager#getAppWidgetInfo}.
TypedValue value = sa.peekValue(com.android.internal.R.styleable.AppWidgetProviderInfo_minWidth);
info.minWidth = value != null ? value.data : 0;
value = sa.peekValue(com.android.internal.R.styleable.AppWidgetProviderInfo_minHeight);
info.minHeight = value != null ? value.data : 0;
value = sa.peekValue(com.android.internal.R.styleable.AppWidgetProviderInfo_minResizeWidth);
info.minResizeWidth = value != null ? value.data : info.minWidth;
value = sa.peekValue(com.android.internal.R.styleable.AppWidgetProviderInfo_minResizeHeight);
info.minResizeHeight = value != null ? value.data : info.minHeight;
info.updatePeriodMillis = sa.getInt(com.android.internal.R.styleable.AppWidgetProviderInfo_updatePeriodMillis, 0);
info.initialLayout = sa.getResourceId(com.android.internal.R.styleable.AppWidgetProviderInfo_initialLayout, 0);
info.initialKeyguardLayout = sa.getResourceId(com.android.internal.R.styleable.AppWidgetProviderInfo_initialKeyguardLayout, 0);
String className = sa.getString(com.android.internal.R.styleable.AppWidgetProviderInfo_configure);
if (className != null) {
info.configure = new ComponentName(providerId.componentName.getPackageName(), className);
}
info.label = activityInfo.loadLabel(mContext.getPackageManager()).toString();
info.icon = ri.getIconResource();
info.previewImage = sa.getResourceId(com.android.internal.R.styleable.AppWidgetProviderInfo_previewImage, 0);
info.autoAdvanceViewId = sa.getResourceId(com.android.internal.R.styleable.AppWidgetProviderInfo_autoAdvanceViewId, -1);
info.resizeMode = sa.getInt(com.android.internal.R.styleable.AppWidgetProviderInfo_resizeMode, AppWidgetProviderInfo.RESIZE_NONE);
info.widgetCategory = sa.getInt(com.android.internal.R.styleable.AppWidgetProviderInfo_widgetCategory, AppWidgetProviderInfo.WIDGET_CATEGORY_HOME_SCREEN);
sa.recycle();
} catch (IOException | PackageManager.NameNotFoundException | XmlPullParserException e) {
// Ok to catch Exception here, because anything going wrong because
// of what a client process passes to us should not be fatal for the
// system process.
Slog.w(TAG, "XML parsing failed for AppWidget provider " + providerId.componentName + " for user " + providerId.uid, e);
return null;
} finally {
if (parser != null) {
parser.close();
}
}
return provider;
}
use of android.appwidget.AppWidgetProviderInfo in project android_frameworks_base by ResurrectionRemix.
the class AppWidgetServiceImpl method readProfileStateFromFileLocked.
private int readProfileStateFromFileLocked(FileInputStream stream, int userId, List<LoadedWidgetState> outLoadedWidgets) {
int version = -1;
try {
XmlPullParser parser = Xml.newPullParser();
parser.setInput(stream, StandardCharsets.UTF_8.name());
int legacyProviderIndex = -1;
int legacyHostIndex = -1;
int type;
do {
type = parser.next();
if (type == XmlPullParser.START_TAG) {
String tag = parser.getName();
if ("gs".equals(tag)) {
String attributeValue = parser.getAttributeValue(null, "version");
try {
version = Integer.parseInt(attributeValue);
} catch (NumberFormatException e) {
version = 0;
}
} else if ("p".equals(tag)) {
legacyProviderIndex++;
// TODO: do we need to check that this package has the same signature
// as before?
String pkg = parser.getAttributeValue(null, "pkg");
String cl = parser.getAttributeValue(null, "cl");
pkg = getCanonicalPackageName(pkg, cl, userId);
if (pkg == null) {
continue;
}
final int uid = getUidForPackage(pkg, userId);
if (uid < 0) {
continue;
}
ComponentName componentName = new ComponentName(pkg, cl);
ActivityInfo providerInfo = getProviderInfo(componentName, userId);
if (providerInfo == null) {
continue;
}
ProviderId providerId = new ProviderId(uid, componentName);
Provider provider = lookupProviderLocked(providerId);
if (provider == null && mSafeMode) {
// if we're in safe mode, make a temporary one
provider = new Provider();
provider.info = new AppWidgetProviderInfo();
provider.info.provider = providerId.componentName;
provider.info.providerInfo = providerInfo;
provider.zombie = true;
provider.id = providerId;
mProviders.add(provider);
}
String tagAttribute = parser.getAttributeValue(null, "tag");
final int providerTag = !TextUtils.isEmpty(tagAttribute) ? Integer.parseInt(tagAttribute, 16) : legacyProviderIndex;
provider.tag = providerTag;
} else if ("h".equals(tag)) {
legacyHostIndex++;
Host host = new Host();
// TODO: do we need to check that this package has the same signature
// as before?
String pkg = parser.getAttributeValue(null, "pkg");
final int uid = getUidForPackage(pkg, userId);
if (uid < 0) {
host.zombie = true;
}
if (!host.zombie || mSafeMode) {
// In safe mode, we don't discard the hosts we don't recognize
// so that they're not pruned from our list. Otherwise, we do.
final int hostId = Integer.parseInt(parser.getAttributeValue(null, "id"), 16);
String tagAttribute = parser.getAttributeValue(null, "tag");
final int hostTag = !TextUtils.isEmpty(tagAttribute) ? Integer.parseInt(tagAttribute, 16) : legacyHostIndex;
host.tag = hostTag;
host.id = new HostId(uid, hostId, pkg);
mHosts.add(host);
}
} else if ("b".equals(tag)) {
String packageName = parser.getAttributeValue(null, "packageName");
final int uid = getUidForPackage(packageName, userId);
if (uid >= 0) {
Pair<Integer, String> packageId = Pair.create(userId, packageName);
mPackagesWithBindWidgetPermission.add(packageId);
}
} else if ("g".equals(tag)) {
Widget widget = new Widget();
widget.appWidgetId = Integer.parseInt(parser.getAttributeValue(null, "id"), 16);
setMinAppWidgetIdLocked(userId, widget.appWidgetId + 1);
// restored ID is allowed to be absent
String restoredIdString = parser.getAttributeValue(null, "rid");
widget.restoredId = (restoredIdString == null) ? 0 : Integer.parseInt(restoredIdString, 16);
Bundle options = new Bundle();
String minWidthString = parser.getAttributeValue(null, "min_width");
if (minWidthString != null) {
options.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH, Integer.parseInt(minWidthString, 16));
}
String minHeightString = parser.getAttributeValue(null, "min_height");
if (minHeightString != null) {
options.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT, Integer.parseInt(minHeightString, 16));
}
String maxWidthString = parser.getAttributeValue(null, "max_width");
if (maxWidthString != null) {
options.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH, Integer.parseInt(maxWidthString, 16));
}
String maxHeightString = parser.getAttributeValue(null, "max_height");
if (maxHeightString != null) {
options.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT, Integer.parseInt(maxHeightString, 16));
}
String categoryString = parser.getAttributeValue(null, "host_category");
if (categoryString != null) {
options.putInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY, Integer.parseInt(categoryString, 16));
}
widget.options = options;
final int hostTag = Integer.parseInt(parser.getAttributeValue(null, "h"), 16);
String providerString = parser.getAttributeValue(null, "p");
final int providerTag = (providerString != null) ? Integer.parseInt(parser.getAttributeValue(null, "p"), 16) : TAG_UNDEFINED;
// We can match widgets with hosts and providers only after hosts
// and providers for all users have been loaded since the widget
// host and provider can be in different user profiles.
LoadedWidgetState loadedWidgets = new LoadedWidgetState(widget, hostTag, providerTag);
outLoadedWidgets.add(loadedWidgets);
}
}
} while (type != XmlPullParser.END_DOCUMENT);
} catch (NullPointerException | NumberFormatException | XmlPullParserException | IOException | IndexOutOfBoundsException e) {
Slog.w(TAG, "failed parsing " + e);
return -1;
}
return version;
}
use of android.appwidget.AppWidgetProviderInfo in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class AppWidgetLoader method putCustomAppWidgets.
/**
* Create list entries for any custom widgets requested through
* {@link AppWidgetManager#EXTRA_CUSTOM_INFO}.
*/
void putCustomAppWidgets(List<Item> items, Intent intent) {
// get and validate the extras they gave us
ArrayList<AppWidgetProviderInfo> customInfo = null;
ArrayList<Bundle> customExtras = null;
try_custom_items: {
customInfo = intent.getParcelableArrayListExtra(AppWidgetManager.EXTRA_CUSTOM_INFO);
if (customInfo == null || customInfo.size() == 0) {
Log.i(TAG, "EXTRA_CUSTOM_INFO not present.");
break try_custom_items;
}
int customInfoSize = customInfo.size();
for (int i = 0; i < customInfoSize; i++) {
Parcelable p = customInfo.get(i);
if (p == null || !(p instanceof AppWidgetProviderInfo)) {
customInfo = null;
Log.e(TAG, "error using EXTRA_CUSTOM_INFO index=" + i);
break try_custom_items;
}
}
customExtras = intent.getParcelableArrayListExtra(AppWidgetManager.EXTRA_CUSTOM_EXTRAS);
if (customExtras == null) {
customInfo = null;
Log.e(TAG, "EXTRA_CUSTOM_INFO without EXTRA_CUSTOM_EXTRAS");
break try_custom_items;
}
int customExtrasSize = customExtras.size();
if (customInfoSize != customExtrasSize) {
customInfo = null;
customExtras = null;
Log.e(TAG, "list size mismatch: EXTRA_CUSTOM_INFO: " + customInfoSize + " EXTRA_CUSTOM_EXTRAS: " + customExtrasSize);
break try_custom_items;
}
for (int i = 0; i < customExtrasSize; i++) {
Parcelable p = customExtras.get(i);
if (p == null || !(p instanceof Bundle)) {
customInfo = null;
customExtras = null;
Log.e(TAG, "error using EXTRA_CUSTOM_EXTRAS index=" + i);
break try_custom_items;
}
}
}
if (LOGD)
Log.d(TAG, "Using " + customInfo.size() + " custom items");
putAppWidgetItems(customInfo, customExtras, items, 0, true);
}
use of android.appwidget.AppWidgetProviderInfo in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class AppWidgetLoader method putAppWidgetItems.
/**
* Create list entries for the given {@link AppWidgetProviderInfo} widgets,
* inserting extras if provided.
*/
void putAppWidgetItems(List<AppWidgetProviderInfo> appWidgets, List<Bundle> customExtras, List<Item> items, int categoryFilter, boolean ignoreFilter) {
if (appWidgets == null)
return;
final int size = appWidgets.size();
for (int i = 0; i < size; i++) {
AppWidgetProviderInfo info = appWidgets.get(i);
// We remove any widgets whose category isn't included in the filter
if (!ignoreFilter && (info.widgetCategory & categoryFilter) == 0) {
continue;
}
Item item = mItemConstructor.createItem(mContext, info, customExtras != null ? customExtras.get(i) : null);
items.add(item);
}
}
use of android.appwidget.AppWidgetProviderInfo in project android_frameworks_base by ResurrectionRemix.
the class AppWidgetHostActivity method handleAppWidgetPickResult.
void handleAppWidgetPickResult(int resultCode, Intent intent) {
// BEGIN_INCLUDE(getExtra_EXTRA_APPWIDGET_ID)
Bundle extras = intent.getExtras();
int appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID);
// END_INCLUDE(getExtra_EXTRA_APPWIDGET_ID)
if (resultCode == RESULT_OK) {
AppWidgetProviderInfo appWidget = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
if (appWidget.configure != null) {
// configure the AppWidget if we should
configureAppWidget(CONFIGURE_APPWIDGET_REQUEST, appWidgetId, appWidget.configure);
} else {
// just add it as is
addAppWidgetView(appWidgetId, appWidget);
}
} else {
mHost.deleteAppWidgetId(appWidgetId);
}
}
Aggregations