diff options
| author | Samuel Fufa <sfufa@google.com> | 2019-08-27 18:19:52 -0700 |
|---|---|---|
| committer | Samuel Fufa <sfufa@google.com> | 2019-09-10 17:34:23 -0700 |
| commit | 59ef5e98f335e10a8874b6747d0a5919edd8a233 (patch) | |
| tree | 1201bb99e598d583361363acb60bf6dd7764e7d5 /core/java/android/appwidget/AppWidgetHost.java | |
| parent | a34d0b7831509b89fc9c3b3a27ef4fd47eb94431 (diff) | |
Setup OnAppWidgetRemoved on framework
Test: Manual
Bug:140140567
Change-Id: I3033b83ff8f55938b5cd898c7e30bb2259af9c5f
Diffstat (limited to 'core/java/android/appwidget/AppWidgetHost.java')
| -rw-r--r-- | core/java/android/appwidget/AppWidgetHost.java | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/core/java/android/appwidget/AppWidgetHost.java b/core/java/android/appwidget/AppWidgetHost.java index f003d4bea028..c20cb253a6be 100644 --- a/core/java/android/appwidget/AppWidgetHost.java +++ b/core/java/android/appwidget/AppWidgetHost.java @@ -56,6 +56,7 @@ public class AppWidgetHost { static final int HANDLE_PROVIDERS_CHANGED = 3; @UnsupportedAppUsage static final int HANDLE_VIEW_DATA_CHANGED = 4; + static final int HANDLE_APP_WIDGET_REMOVED = 5; final static Object sServiceLock = new Object(); @UnsupportedAppUsage @@ -103,6 +104,14 @@ public class AppWidgetHost { msg.sendToTarget(); } + public void appWidgetRemoved(int appWidgetId) { + Handler handler = mWeakHandler.get(); + if (handler == null) { + return; + } + handler.obtainMessage(HANDLE_APP_WIDGET_REMOVED, appWidgetId, 0).sendToTarget(); + } + public void providersChanged() { Handler handler = mWeakHandler.get(); if (handler == null) { @@ -137,6 +146,10 @@ public class AppWidgetHost { updateAppWidgetView(msg.arg1, (RemoteViews)msg.obj); break; } + case HANDLE_APP_WIDGET_REMOVED: { + dispatchOnAppWidgetRemoved(msg.arg1); + break; + } case HANDLE_PROVIDER_CHANGED: { onProviderChanged(msg.arg1, (AppWidgetProviderInfo)msg.obj); break; @@ -224,6 +237,10 @@ public class AppWidgetHost { break; case PendingHostUpdate.TYPE_VIEW_DATA_CHANGED: viewDataChanged(update.appWidgetId, update.viewId); + break; + case PendingHostUpdate.TYPE_APP_WIDGET_REMOVED: + dispatchOnAppWidgetRemoved(update.appWidgetId); + break; } } } @@ -426,6 +443,21 @@ public class AppWidgetHost { } } + void dispatchOnAppWidgetRemoved(int appWidgetId) { + synchronized (mViews) { + mViews.remove(appWidgetId); + } + onAppWidgetRemoved(appWidgetId); + } + + /** + * Called when the app widget is removed for appWidgetId + * @param appWidgetId + */ + public void onAppWidgetRemoved(int appWidgetId) { + // Does nothing + } + /** * Called when the set of available widgets changes (ie. widget containing packages * are added, updated or removed, or widget components are enabled or disabled.) |
