diff options
Diffstat (limited to 'policy')
3 files changed, 43 insertions, 8 deletions
diff --git a/policy/src/com/android/internal/policy/impl/keyguard/KeyguardHostView.java b/policy/src/com/android/internal/policy/impl/keyguard/KeyguardHostView.java index de19bd5..0e25c84 100644 --- a/policy/src/com/android/internal/policy/impl/keyguard/KeyguardHostView.java +++ b/policy/src/com/android/internal/policy/impl/keyguard/KeyguardHostView.java @@ -26,7 +26,6 @@ import android.appwidget.AppWidgetHost; import android.appwidget.AppWidgetHostView; import android.appwidget.AppWidgetManager; import android.appwidget.AppWidgetProviderInfo; -import android.content.ActivityNotFoundException; import android.content.ComponentName; import android.content.Context; import android.content.Intent; @@ -128,6 +127,8 @@ public class KeyguardHostView extends KeyguardViewBase { mLockPatternUtils = new LockPatternUtils(context); mAppWidgetHost = new AppWidgetHost( context, APPWIDGET_HOST_ID, mOnClickHandler, Looper.myLooper()); + cleanupAppWidgetIds(); + mAppWidgetManager = AppWidgetManager.getInstance(mContext); mSecurityModel = new KeyguardSecurityModel(context); @@ -153,6 +154,33 @@ public class KeyguardHostView extends KeyguardViewBase { } } + private void cleanupAppWidgetIds() { + // Clean up appWidgetIds that are bound to lockscreen, but not actually used + // This is only to clean up after another bug: we used to not call + // deleteAppWidgetId when a user manually deleted a widget in keyguard. This code + // shouldn't have to run more than once per user. AppWidgetProviders rely on callbacks + // that are triggered by deleteAppWidgetId, which is why we're doing this + int[] appWidgetIdsInKeyguardSettings = mLockPatternUtils.getAppWidgets(); + int[] appWidgetIdsBoundToHost = mAppWidgetHost.getAppWidgetIds(); + for (int i = 0; i < appWidgetIdsBoundToHost.length; i++) { + int appWidgetId = appWidgetIdsBoundToHost[i]; + if (!contains(appWidgetIdsInKeyguardSettings, appWidgetId)) { + Log.d(TAG, "Found a appWidgetId that's not being used by keyguard, deleting id " + + appWidgetId); + mAppWidgetHost.deleteAppWidgetId(appWidgetId); + } + } + } + + private static boolean contains(int[] array, int target) { + for (int value : array) { + if (value == target) { + return true; + } + } + return false; + } + private KeyguardUpdateMonitorCallback mUpdateMonitorCallbacks = new KeyguardUpdateMonitorCallback() { @Override @@ -331,10 +359,17 @@ public class KeyguardHostView extends KeyguardViewBase { }; @Override - public void onRemoveView(View v) { + public void onRemoveView(View v, boolean deletePermanently) { if (numWidgets() < MAX_WIDGETS) { setAddWidgetEnabled(true); } + if (deletePermanently) { + final int appWidgetId = ((KeyguardWidgetFrame) v).getContentAppWidgetId(); + if (appWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID && + appWidgetId != LockPatternUtils.ID_DEFAULT_STATUS_WIDGET) { + mAppWidgetHost.deleteAppWidgetId(appWidgetId); + } + } } }; diff --git a/policy/src/com/android/internal/policy/impl/keyguard/KeyguardWidgetPager.java b/policy/src/com/android/internal/policy/impl/keyguard/KeyguardWidgetPager.java index 25e2781..85b5472 100644 --- a/policy/src/com/android/internal/policy/impl/keyguard/KeyguardWidgetPager.java +++ b/policy/src/com/android/internal/policy/impl/keyguard/KeyguardWidgetPager.java @@ -237,7 +237,7 @@ public class KeyguardWidgetPager extends PagedView implements PagedView.PageSwit public void userActivity(); public void onUserActivityTimeoutChanged(); public void onAddView(View v); - public void onRemoveView(View v); + public void onRemoveView(View v, boolean deletePermanently); } public void addWidget(View widget) { @@ -245,10 +245,10 @@ public class KeyguardWidgetPager extends PagedView implements PagedView.PageSwit } - public void onRemoveView(View v) { + public void onRemoveView(View v, final boolean deletePermanently) { final int appWidgetId = ((KeyguardWidgetFrame) v).getContentAppWidgetId(); if (mCallbacks != null) { - mCallbacks.onRemoveView(v); + mCallbacks.onRemoveView(v, deletePermanently); } mBackgroundWorkerHandler.post(new Runnable() { @Override diff --git a/policy/src/com/android/internal/policy/impl/keyguard/PagedView.java b/policy/src/com/android/internal/policy/impl/keyguard/PagedView.java index 3900ab4..0b06306 100644 --- a/policy/src/com/android/internal/policy/impl/keyguard/PagedView.java +++ b/policy/src/com/android/internal/policy/impl/keyguard/PagedView.java @@ -1457,7 +1457,7 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc } removeView(mDragView); - onRemoveView(mDragView); + onRemoveView(mDragView, false); addView(mDragView, pageUnderPointIndex); onAddView(mDragView, pageUnderPointIndex); mSidePageHoverIndex = -1; @@ -1587,7 +1587,7 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc } //public abstract void onFlingToDelete(View v); - public abstract void onRemoveView(View v); + public abstract void onRemoveView(View v, boolean deletePermanently); public abstract void onAddView(View v, int index); private void resetTouchState() { @@ -2391,7 +2391,7 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc slideAnimations.start(); removeView(dragView); - onRemoveView(dragView); + onRemoveView(dragView, true); } }; } |