diff options
author | Michael Jurka <mikejurka@google.com> | 2012-10-25 11:44:31 -0700 |
---|---|---|
committer | Michael Jurka <mikejurka@google.com> | 2012-10-25 16:43:10 -0700 |
commit | 1254f2f42f7173ef51d0034975ab5cb7d44f8209 (patch) | |
tree | 3e861513eefd8ffe35982557b3c78a506e1ccf50 /core/java/com | |
parent | 6a8d6da9bb8829011bcc249e308461ea64e431e1 (diff) | |
download | frameworks_base-1254f2f42f7173ef51d0034975ab5cb7d44f8209.zip frameworks_base-1254f2f42f7173ef51d0034975ab5cb7d44f8209.tar.gz frameworks_base-1254f2f42f7173ef51d0034975ab5cb7d44f8209.tar.bz2 |
Persist reordering/deleting widgets on keyguard
Also, clean up warnings from unused imports
Change-Id: Id0ef12a584ffdaa8a4fb64ffe93d0dda0af398ec
Diffstat (limited to 'core/java/com')
-rw-r--r-- | core/java/com/android/internal/widget/LockPatternUtils.java | 44 |
1 files changed, 30 insertions, 14 deletions
diff --git a/core/java/com/android/internal/widget/LockPatternUtils.java b/core/java/com/android/internal/widget/LockPatternUtils.java index 9cc0341..50e0a47 100644 --- a/core/java/com/android/internal/widget/LockPatternUtils.java +++ b/core/java/com/android/internal/widget/LockPatternUtils.java @@ -16,10 +16,6 @@ package com.android.internal.widget; -import com.android.internal.R; -import com.android.internal.telephony.ITelephony; -import com.google.android.collect.Lists; - import android.app.ActivityManagerNative; import android.app.admin.DevicePolicyManager; import android.content.ContentResolver; @@ -42,12 +38,13 @@ import android.util.Log; import android.view.View; import android.widget.Button; -import org.apache.harmony.kernel.vm.StringUtils; +import com.android.internal.R; +import com.android.internal.telephony.ITelephony; +import com.google.android.collect.Lists; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; -import java.util.ArrayList; import java.util.List; /** @@ -127,6 +124,11 @@ public class LockPatternUtils { */ public static final int FLAG_BIOMETRIC_WEAK_LIVELINESS = 0x1; + /** + * Pseudo-appwidget id we use to represent the default clock status widget + */ + public static final int ID_DEFAULT_STATUS_WIDGET = -2; + protected final static String LOCKOUT_PERMANENT_KEY = "lockscreen.lockedoutpermanently"; protected final static String LOCKOUT_ATTEMPT_DEADLINE = "lockscreen.lockoutattemptdeadline"; protected final static String PATTERN_EVER_CHOSEN_KEY = "lockscreen.patterneverchosen"; @@ -1052,7 +1054,7 @@ public class LockPatternUtils { mContentResolver, Settings.Secure.LOCK_SCREEN_APPWIDGET_IDS, UserHandle.USER_CURRENT); String delims = ","; - if (appWidgetIdString != null) { + if (appWidgetIdString != null && appWidgetIdString.length() > 0) { String[] appWidgetStringIds = appWidgetIdString.split(delims); int[] appWidgetIds = new int[appWidgetStringIds.length]; for (int i = 0; i < appWidgetStringIds.length; i++) { @@ -1060,12 +1062,17 @@ public class LockPatternUtils { try { appWidgetIds[i] = Integer.decode(appWidget); } catch (NumberFormatException e) { + Log.d(TAG, "Error when parsing widget id " + appWidget); return null; } } return appWidgetIds; } - return new int[0]; + if (appWidgetIdString == null) { + return new int[] { LockPatternUtils.ID_DEFAULT_STATUS_WIDGET }; + } else { + return new int[0]; + } } private static String combineStrings(int[] list, String separator) { @@ -1111,8 +1118,15 @@ public class LockPatternUtils { UserHandle.USER_CURRENT); } - public void addAppWidget(int widgetId, int index) { + // TODO: log an error if this returns false + public boolean addAppWidget(int widgetId, int index) { int[] widgets = getAppWidgets(); + if (widgets == null) { + return false; + } + if (index < 0 || index >= widgets.length) { + return false; + } int[] newWidgets = new int[widgets.length + 1]; for (int i = 0, j = 0; i < newWidgets.length; i++) { if (index == i) { @@ -1125,17 +1139,19 @@ public class LockPatternUtils { } } writeAppWidgets(newWidgets); + return true; } - public boolean removeAppWidget(int widgetId, int index) { + public boolean removeAppWidget(int widgetId) { int[] widgets = getAppWidgets(); + int[] newWidgets = new int[widgets.length - 1]; for (int i = 0, j = 0; i < widgets.length; i++) { - if (index == i) { - if (widgets[i] != widgetId) { - return false; - } + if (widgets[i] == widgetId) { // continue... + } else if (j >= newWidgets.length) { + // we couldn't find the widget + return false; } else { newWidgets[j] = widgets[i]; j++; |