summaryrefslogtreecommitdiffstats
path: root/src/com/android/settings/SecuritySettings.java
diff options
context:
space:
mode:
authorMichael Jurka <mikejurka@google.com>2012-09-17 17:46:49 -0700
committerMichael Jurka <mikejurka@google.com>2012-09-17 17:56:37 -0700
commit3028051ba8e694da7a3e527092d7d99f964aabe9 (patch)
treedb73806f2a029e0d7bba50a817901635dfe67aff /src/com/android/settings/SecuritySettings.java
parentd0d925d96bf0c532cec203fdd2cb35464d247ad5 (diff)
downloadpackages_apps_Settings-3028051ba8e694da7a3e527092d7d99f964aabe9.tar.gz
packages_apps_Settings-3028051ba8e694da7a3e527092d7d99f964aabe9.tar.bz2
packages_apps_Settings-3028051ba8e694da7a3e527092d7d99f964aabe9.zip
Fix cases where app widget ids were not being cleaned up
Change-Id: Ie3f1ba0cc0fe459ae9fff2665c2ff4aa76e95994
Diffstat (limited to 'src/com/android/settings/SecuritySettings.java')
-rw-r--r--src/com/android/settings/SecuritySettings.java32
1 files changed, 22 insertions, 10 deletions
diff --git a/src/com/android/settings/SecuritySettings.java b/src/com/android/settings/SecuritySettings.java
index d896a68b6..588075e33 100644
--- a/src/com/android/settings/SecuritySettings.java
+++ b/src/com/android/settings/SecuritySettings.java
@@ -21,7 +21,6 @@ import static android.provider.Settings.System.SCREEN_OFF_TIMEOUT;
import android.app.Activity;
import android.app.AlertDialog;
-import android.app.KeyguardManager;
import android.app.admin.DevicePolicyManager;
import android.appwidget.AppWidgetHost;
import android.appwidget.AppWidgetManager;
@@ -258,12 +257,7 @@ public class SecuritySettings extends SettingsPreferenceFragment
mUserSelectedWidget = root.findPreference(KEY_CHOOSE_USER_SELECTED_LOCKSCREEN_WIDGET);
if (mUserSelectedWidget != null) {
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(getActivity());
- int appWidgetId = -1;
- String appWidgetIdString = Settings.Secure.getString(
- getContentResolver(), Settings.Secure.LOCK_SCREEN_USER_SELECTED_APPWIDGET_ID);
- if (appWidgetIdString != null) {;
- appWidgetId = (int) Integer.decode(appWidgetIdString);
- }
+ int appWidgetId = getUserSelectedAppWidgetId();
if (appWidgetId == -1) {
mUserSelectedWidget.setSummary(getResources().getString(R.string.widget_none));
} else {
@@ -277,6 +271,16 @@ public class SecuritySettings extends SettingsPreferenceFragment
return root;
}
+ private int getUserSelectedAppWidgetId() {
+ int appWidgetId = -1;
+ String appWidgetIdString = Settings.Secure.getString(
+ getContentResolver(), Settings.Secure.LOCK_SCREEN_USER_SELECTED_APPWIDGET_ID);
+ if (appWidgetIdString != null) {;
+ appWidgetId = (int) Integer.decode(appWidgetIdString);
+ }
+ return appWidgetId;
+ }
+
private boolean isNonMarketAppsAllowed() {
return Settings.Global.getInt(getContentResolver(),
Settings.Global.INSTALL_NON_MARKET_APPS, 0) > 0;
@@ -587,15 +591,23 @@ public class SecuritySettings extends SettingsPreferenceFragment
} else {
// Otherwise just add it
if (noWidget) {
+ // If we selected "none", delete the allocated id
+ AppWidgetHost.deleteAppWidgetIdForHost(appWidgetId);
data.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
+ } else {
+ onActivityResult(REQUEST_CREATE_APPWIDGET, Activity.RESULT_OK, data);
}
- onActivityResult(REQUEST_CREATE_APPWIDGET, Activity.RESULT_OK, data);
}
- } else if (requestCode == REQUEST_CREATE_APPWIDGET && resultCode == Activity.RESULT_OK) {
+ } else if (
+ requestCode == REQUEST_CREATE_APPWIDGET && resultCode == Activity.RESULT_OK) {
+ // If a widget existed before, delete it
+ int oldAppWidgetId = getUserSelectedAppWidgetId();
+ if (oldAppWidgetId != -1) {
+ AppWidgetHost.deleteAppWidgetIdForHost(oldAppWidgetId);
+ }
Settings.Secure.putString(getContentResolver(),
Settings.Secure.LOCK_SCREEN_USER_SELECTED_APPWIDGET_ID,
Integer.toString(appWidgetId));
-
} else {
AppWidgetHost.deleteAppWidgetIdForHost(appWidgetId);
}