Ensuring that keyguard widgets are bound with correct options

-> We need to bind the widget and indicate that it is a keyguard widget

Change-Id: I8e76b45b86aecc671669022c6f5fad071b62837d
This commit is contained in:
Adam Cohen
2012-09-24 13:15:14 -07:00
parent ff571fee86
commit 85d4b5f78e
2 changed files with 24 additions and 4 deletions

View File

@@ -145,13 +145,20 @@ public class AppWidgetPickActivity extends ActivityPicker {
Intent intent = getIntentForPosition(which); Intent intent = getIntentForPosition(which);
int result; int result;
if (intent.getExtras() != null) { if (intent.getExtras() != null &&
// If there are any extras, it's because this entry is custom. (intent.getExtras().containsKey(AppWidgetManager.EXTRA_CUSTOM_INFO) ||
intent.getExtras().containsKey(AppWidgetManager.EXTRA_CUSTOM_EXTRAS))) {
// If these extras are present it's because this entry is custom.
// Don't try to bind it, just pass it back to the app. // Don't try to bind it, just pass it back to the app.
setResultData(RESULT_OK, intent); setResultData(RESULT_OK, intent);
} else { } else {
try { try {
mAppWidgetManager.bindAppWidgetId(mAppWidgetId, intent.getComponent()); Bundle options = null;
if (intent.getExtras() != null) {
options = intent.getExtras().getBundle(
AppWidgetManager.EXTRA_APPWIDGET_OPTIONS);
}
mAppWidgetManager.bindAppWidgetId(mAppWidgetId, intent.getComponent(), options);
result = RESULT_OK; result = RESULT_OK;
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
// This is thrown if they're already bound, or otherwise somehow // This is thrown if they're already bound, or otherwise somehow

View File

@@ -475,6 +475,17 @@ public class SecuritySettings extends SettingsPreferenceFragment
} }
} }
private Intent getBaseIntent() {
Intent baseIntent = new Intent(Intent.ACTION_MAIN, null);
baseIntent.addCategory(Intent.CATEGORY_DEFAULT);
Bundle options = new Bundle();
options.putInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY,
AppWidgetProviderInfo.WIDGET_CATEGORY_KEYGUARD);
baseIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
return baseIntent;
}
@Override @Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
final String key = preference.getKey(); final String key = preference.getKey();
@@ -511,6 +522,7 @@ public class SecuritySettings extends SettingsPreferenceFragment
// Launch the widget picker // Launch the widget picker
pickIntent.putExtra(AppWidgetManager.EXTRA_CUSTOM_INFO, extraInfos); pickIntent.putExtra(AppWidgetManager.EXTRA_CUSTOM_INFO, extraInfos);
pickIntent.putExtra(AppWidgetManager.EXTRA_CUSTOM_EXTRAS, extraExtras); pickIntent.putExtra(AppWidgetManager.EXTRA_CUSTOM_EXTRAS, extraExtras);
pickIntent.putExtra(Intent.EXTRA_INTENT, getBaseIntent());
startActivityForResult(pickIntent, REQUEST_PICK_USER_SELECTED_APPWIDGET); startActivityForResult(pickIntent, REQUEST_PICK_USER_SELECTED_APPWIDGET);
} else { } else {
Log.e(TAG, "Unable to allocate an AppWidget id in lock screen"); Log.e(TAG, "Unable to allocate an AppWidget id in lock screen");
@@ -545,6 +557,7 @@ public class SecuritySettings extends SettingsPreferenceFragment
// Launch the widget picker // Launch the widget picker
pickIntent.putExtra(AppWidgetManager.EXTRA_CUSTOM_INFO, extraInfos); pickIntent.putExtra(AppWidgetManager.EXTRA_CUSTOM_INFO, extraInfos);
pickIntent.putExtra(AppWidgetManager.EXTRA_CUSTOM_EXTRAS, extraExtras); pickIntent.putExtra(AppWidgetManager.EXTRA_CUSTOM_EXTRAS, extraExtras);
pickIntent.putExtra(Intent.EXTRA_INTENT, getBaseIntent());
startActivityForResult(pickIntent, REQUEST_PICK_STATUS_APPWIDGET); startActivityForResult(pickIntent, REQUEST_PICK_STATUS_APPWIDGET);
} else { } else {
Log.e(TAG, "Unable to allocate an AppWidget id in lock screen"); Log.e(TAG, "Unable to allocate an AppWidget id in lock screen");