use of android.appwidget.AppWidgetProviderInfo in project platform_frameworks_base by android.
the class AppWidgetHostActivity method handleAppWidgetConfigureResult.
void handleAppWidgetConfigureResult(int resultCode, Intent data) {
int appWidgetId = getPreferences(0).getInt(PENDING_APPWIDGET_ID, -1);
Log.d(TAG, "resultCode=" + resultCode + " appWidgetId=" + appWidgetId);
if (appWidgetId < 0) {
Log.w(TAG, "was no preference for PENDING_APPWIDGET_ID");
return;
}
if (resultCode == RESULT_OK) {
AppWidgetProviderInfo appWidget = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
addAppWidgetView(appWidgetId, appWidget);
} else {
mHost.deleteAppWidgetId(appWidgetId);
}
}
use of android.appwidget.AppWidgetProviderInfo in project platform_frameworks_base by android.
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);
}
}
use of android.appwidget.AppWidgetProviderInfo in project platform_frameworks_base by android.
the class AppWidgetHostActivity method onCreate.
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
mAppWidgetManager = AppWidgetManager.getInstance(this);
setContentView(R.layout.appwidget_host);
mHost = new AppWidgetHost(this, HOST_ID) {
protected AppWidgetHostView onCreateView(Context context, int appWidgetId, AppWidgetProviderInfo appWidget) {
return new MyAppWidgetView(appWidgetId);
}
};
findViewById(R.id.add_appwidget).setOnClickListener(mOnClickListener);
mAppWidgetContainer = (AppWidgetContainerView) findViewById(R.id.appwidget_container);
if (false) {
if (false) {
mHost.deleteHost();
} else {
AppWidgetHost.deleteAllHosts();
}
}
}
use of android.appwidget.AppWidgetProviderInfo in project platform_frameworks_base by android.
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 platform_frameworks_base by android.
the class AppWidgetServiceImpl method dumpProvider.
private static void dumpProvider(Provider provider, int index, PrintWriter pw) {
AppWidgetProviderInfo info = provider.info;
pw.print(" [");
pw.print(index);
pw.print("] provider ");
pw.println(provider.id);
pw.print(" min=(");
pw.print(info.minWidth);
pw.print("x");
pw.print(info.minHeight);
pw.print(") minResize=(");
pw.print(info.minResizeWidth);
pw.print("x");
pw.print(info.minResizeHeight);
pw.print(") updatePeriodMillis=");
pw.print(info.updatePeriodMillis);
pw.print(" resizeMode=");
pw.print(info.resizeMode);
pw.print(" widgetCategory=");
pw.print(info.widgetCategory);
pw.print(" autoAdvanceViewId=");
pw.print(info.autoAdvanceViewId);
pw.print(" initialLayout=#");
pw.print(Integer.toHexString(info.initialLayout));
pw.print(" initialKeyguardLayout=#");
pw.print(Integer.toHexString(info.initialKeyguardLayout));
pw.print(" zombie=");
pw.println(provider.zombie);
}
Aggregations