Fix cases where app widget ids were not being cleaned up
Change-Id: Ie3f1ba0cc0fe459ae9fff2665c2ff4aa76e95994
This commit is contained in:
@@ -21,7 +21,6 @@ import static android.provider.Settings.System.SCREEN_OFF_TIMEOUT;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.KeyguardManager;
|
|
||||||
import android.app.admin.DevicePolicyManager;
|
import android.app.admin.DevicePolicyManager;
|
||||||
import android.appwidget.AppWidgetHost;
|
import android.appwidget.AppWidgetHost;
|
||||||
import android.appwidget.AppWidgetManager;
|
import android.appwidget.AppWidgetManager;
|
||||||
@@ -258,12 +257,7 @@ public class SecuritySettings extends SettingsPreferenceFragment
|
|||||||
mUserSelectedWidget = root.findPreference(KEY_CHOOSE_USER_SELECTED_LOCKSCREEN_WIDGET);
|
mUserSelectedWidget = root.findPreference(KEY_CHOOSE_USER_SELECTED_LOCKSCREEN_WIDGET);
|
||||||
if (mUserSelectedWidget != null) {
|
if (mUserSelectedWidget != null) {
|
||||||
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(getActivity());
|
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(getActivity());
|
||||||
int appWidgetId = -1;
|
int appWidgetId = getUserSelectedAppWidgetId();
|
||||||
String appWidgetIdString = Settings.Secure.getString(
|
|
||||||
getContentResolver(), Settings.Secure.LOCK_SCREEN_USER_SELECTED_APPWIDGET_ID);
|
|
||||||
if (appWidgetIdString != null) {;
|
|
||||||
appWidgetId = (int) Integer.decode(appWidgetIdString);
|
|
||||||
}
|
|
||||||
if (appWidgetId == -1) {
|
if (appWidgetId == -1) {
|
||||||
mUserSelectedWidget.setSummary(getResources().getString(R.string.widget_none));
|
mUserSelectedWidget.setSummary(getResources().getString(R.string.widget_none));
|
||||||
} else {
|
} else {
|
||||||
@@ -277,6 +271,16 @@ public class SecuritySettings extends SettingsPreferenceFragment
|
|||||||
return root;
|
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() {
|
private boolean isNonMarketAppsAllowed() {
|
||||||
return Settings.Global.getInt(getContentResolver(),
|
return Settings.Global.getInt(getContentResolver(),
|
||||||
Settings.Global.INSTALL_NON_MARKET_APPS, 0) > 0;
|
Settings.Global.INSTALL_NON_MARKET_APPS, 0) > 0;
|
||||||
@@ -587,15 +591,23 @@ public class SecuritySettings extends SettingsPreferenceFragment
|
|||||||
} else {
|
} else {
|
||||||
// Otherwise just add it
|
// Otherwise just add it
|
||||||
if (noWidget) {
|
if (noWidget) {
|
||||||
|
// If we selected "none", delete the allocated id
|
||||||
|
AppWidgetHost.deleteAppWidgetIdForHost(appWidgetId);
|
||||||
data.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
|
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.putString(getContentResolver(),
|
||||||
Settings.Secure.LOCK_SCREEN_USER_SELECTED_APPWIDGET_ID,
|
Settings.Secure.LOCK_SCREEN_USER_SELECTED_APPWIDGET_ID,
|
||||||
Integer.toString(appWidgetId));
|
Integer.toString(appWidgetId));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
AppWidgetHost.deleteAppWidgetIdForHost(appWidgetId);
|
AppWidgetHost.deleteAppWidgetIdForHost(appWidgetId);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user