Loading api/current.txt +1 −0 Original line number Diff line number Diff line Loading @@ -7878,6 +7878,7 @@ package android.appwidget { method public void deleteAppWidgetId(int); method public void deleteHost(); method public int[] getAppWidgetIds(); method public void onAppWidgetRemoved(int); method protected android.appwidget.AppWidgetHostView onCreateView(android.content.Context, int, android.appwidget.AppWidgetProviderInfo); method protected void onProviderChanged(int, android.appwidget.AppWidgetProviderInfo); method protected void onProvidersChanged(); core/java/android/appwidget/AppWidgetHost.java +32 −0 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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) { Loading Loading @@ -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; Loading Loading @@ -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; } } } Loading Loading @@ -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.) Loading core/java/android/appwidget/PendingHostUpdate.java +8 −0 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ public class PendingHostUpdate implements Parcelable { static final int TYPE_VIEWS_UPDATE = 0; static final int TYPE_PROVIDER_CHANGED = 1; static final int TYPE_VIEW_DATA_CHANGED = 2; static final int TYPE_APP_WIDGET_REMOVED = 3; final int appWidgetId; final int type; Loading @@ -53,6 +54,13 @@ public class PendingHostUpdate implements Parcelable { return update; } /** * IAppWidgetHost appWidgetRemoved implimentaion */ public static PendingHostUpdate appWidgetRemoved(int appWidgetId) { return new PendingHostUpdate(appWidgetId, TYPE_APP_WIDGET_REMOVED); } private PendingHostUpdate(int appWidgetId, int type) { this.appWidgetId = appWidgetId; this.type = type; Loading core/java/com/android/internal/appwidget/IAppWidgetHost.aidl +1 −0 Original line number Diff line number Diff line Loading @@ -27,5 +27,6 @@ oneway interface IAppWidgetHost { void providerChanged(int appWidgetId, in AppWidgetProviderInfo info); void providersChanged(); void viewDataChanged(int appWidgetId, int viewId); void appWidgetRemoved(int appWidgetId); } services/appwidget/java/com/android/server/appwidget/AppWidgetServiceImpl.java +58 −12 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package com.android.server.appwidget; import static android.content.Context.KEYGUARD_SERVICE; import static android.content.Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS; import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; import static com.android.server.pm.PackageManagerService.PLATFORM_PACKAGE_NAME; import android.annotation.UserIdInt; Loading Loading @@ -856,15 +857,15 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku ArrayList<PendingHostUpdate> outUpdates = new ArrayList<>(N); LongSparseArray<PendingHostUpdate> updatesMap = new LongSparseArray<>(); for (int i = 0; i < N; i++) { if (host.getPendingUpdatesForId(appWidgetIds[i], updatesMap)) { updatesMap.clear(); host.getPendingUpdatesForId(appWidgetIds[i], updatesMap); // We key the updates based on request id, so that the values are sorted in the // order they were received. int M = updatesMap.size(); for (int j = 0; j < M; j++) { int m = updatesMap.size(); for (int j = 0; j < m; j++) { outUpdates.add(updatesMap.valueAt(j)); } } } // Reset the update counter once all the updates have been calculated host.lastWidgetUpdateSequenceNo = updateSequenceNo; return new ParceledListSlice<>(outUpdates); Loading Loading @@ -2102,6 +2103,40 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku } } private void scheduleNotifyAppWidgetRemovedLocked(Widget widget) { long requestId = UPDATE_COUNTER.incrementAndGet(); if (widget != null) { widget.updateSequenceNos.clear(); } if (widget == null || widget.provider == null || widget.provider.zombie || widget.host.callbacks == null || widget.host.zombie) { return; } SomeArgs args = SomeArgs.obtain(); args.arg1 = widget.host; args.arg2 = widget.host.callbacks; args.arg3 = requestId; args.argi1 = widget.appWidgetId; mCallbackHandler.obtainMessage( CallbackHandler.MSG_NOTIFY_APP_WIDGET_REMOVED, args).sendToTarget(); } private void handleNotifyAppWidgetRemoved(Host host, IAppWidgetHost callbacks, int appWidgetId, long requestId) { try { callbacks.appWidgetRemoved(appWidgetId); host.lastWidgetUpdateSequenceNo = requestId; } catch (RemoteException re) { synchronized (mLock) { Slog.e(TAG, "Widget host dead: " + host.id, re); host.callbacks = null; } } } private void scheduleNotifyGroupHostsForProvidersChangedLocked(int userId) { final int[] profileIds = mSecurityPolicy.getEnabledGroupProfileIds(userId); Loading Loading @@ -2870,8 +2905,8 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku */ void removeWidgetLocked(Widget widget) { mWidgets.remove(widget); onWidgetRemovedLocked(widget); scheduleNotifyAppWidgetRemovedLocked(widget); } private void onWidgetRemovedLocked(Widget widget) { Loading Loading @@ -3587,6 +3622,7 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku public static final int MSG_NOTIFY_PROVIDER_CHANGED = 2; public static final int MSG_NOTIFY_PROVIDERS_CHANGED = 3; public static final int MSG_NOTIFY_VIEW_DATA_CHANGED = 4; public static final int MSG_NOTIFY_APP_WIDGET_REMOVED = 5; public CallbackHandler(Looper looper) { super(looper, null, false); Loading Loading @@ -3619,6 +3655,16 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku handleNotifyProviderChanged(host, callbacks, appWidgetId, info, requestId); } break; case MSG_NOTIFY_APP_WIDGET_REMOVED: { SomeArgs args = (SomeArgs) message.obj; Host host = (Host) args.arg1; IAppWidgetHost callbacks = (IAppWidgetHost) args.arg2; long requestId = (Long) args.arg3; final int appWidgetId = args.argi1; args.recycle(); handleNotifyAppWidgetRemoved(host, callbacks, appWidgetId, requestId); } break; case MSG_NOTIFY_PROVIDERS_CHANGED: { SomeArgs args = (SomeArgs) message.obj; Host host = (Host) args.arg1; Loading Loading @@ -4017,14 +4063,13 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku /** * Adds all pending updates in {@param outUpdates} keys by the update time. */ public boolean getPendingUpdatesForId(int appWidgetId, public void getPendingUpdatesForId(int appWidgetId, LongSparseArray<PendingHostUpdate> outUpdates) { long updateSequenceNo = lastWidgetUpdateSequenceNo; int N = widgets.size(); for (int i = 0; i < N; i++) { Widget widget = widgets.get(i); if (widget.appWidgetId == appWidgetId) { outUpdates.clear(); for (int j = widget.updateSequenceNos.size() - 1; j >= 0; j--) { long requestId = widget.updateSequenceNos.valueAt(j); if (requestId <= updateSequenceNo) { Loading @@ -4046,10 +4091,11 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku } outUpdates.put(requestId, update); } return true; return; } } return false; outUpdates.put(lastWidgetUpdateSequenceNo, PendingHostUpdate.appWidgetRemoved(appWidgetId)); } @Override Loading Loading
api/current.txt +1 −0 Original line number Diff line number Diff line Loading @@ -7878,6 +7878,7 @@ package android.appwidget { method public void deleteAppWidgetId(int); method public void deleteHost(); method public int[] getAppWidgetIds(); method public void onAppWidgetRemoved(int); method protected android.appwidget.AppWidgetHostView onCreateView(android.content.Context, int, android.appwidget.AppWidgetProviderInfo); method protected void onProviderChanged(int, android.appwidget.AppWidgetProviderInfo); method protected void onProvidersChanged();
core/java/android/appwidget/AppWidgetHost.java +32 −0 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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) { Loading Loading @@ -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; Loading Loading @@ -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; } } } Loading Loading @@ -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.) Loading
core/java/android/appwidget/PendingHostUpdate.java +8 −0 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ public class PendingHostUpdate implements Parcelable { static final int TYPE_VIEWS_UPDATE = 0; static final int TYPE_PROVIDER_CHANGED = 1; static final int TYPE_VIEW_DATA_CHANGED = 2; static final int TYPE_APP_WIDGET_REMOVED = 3; final int appWidgetId; final int type; Loading @@ -53,6 +54,13 @@ public class PendingHostUpdate implements Parcelable { return update; } /** * IAppWidgetHost appWidgetRemoved implimentaion */ public static PendingHostUpdate appWidgetRemoved(int appWidgetId) { return new PendingHostUpdate(appWidgetId, TYPE_APP_WIDGET_REMOVED); } private PendingHostUpdate(int appWidgetId, int type) { this.appWidgetId = appWidgetId; this.type = type; Loading
core/java/com/android/internal/appwidget/IAppWidgetHost.aidl +1 −0 Original line number Diff line number Diff line Loading @@ -27,5 +27,6 @@ oneway interface IAppWidgetHost { void providerChanged(int appWidgetId, in AppWidgetProviderInfo info); void providersChanged(); void viewDataChanged(int appWidgetId, int viewId); void appWidgetRemoved(int appWidgetId); }
services/appwidget/java/com/android/server/appwidget/AppWidgetServiceImpl.java +58 −12 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package com.android.server.appwidget; import static android.content.Context.KEYGUARD_SERVICE; import static android.content.Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS; import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; import static com.android.server.pm.PackageManagerService.PLATFORM_PACKAGE_NAME; import android.annotation.UserIdInt; Loading Loading @@ -856,15 +857,15 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku ArrayList<PendingHostUpdate> outUpdates = new ArrayList<>(N); LongSparseArray<PendingHostUpdate> updatesMap = new LongSparseArray<>(); for (int i = 0; i < N; i++) { if (host.getPendingUpdatesForId(appWidgetIds[i], updatesMap)) { updatesMap.clear(); host.getPendingUpdatesForId(appWidgetIds[i], updatesMap); // We key the updates based on request id, so that the values are sorted in the // order they were received. int M = updatesMap.size(); for (int j = 0; j < M; j++) { int m = updatesMap.size(); for (int j = 0; j < m; j++) { outUpdates.add(updatesMap.valueAt(j)); } } } // Reset the update counter once all the updates have been calculated host.lastWidgetUpdateSequenceNo = updateSequenceNo; return new ParceledListSlice<>(outUpdates); Loading Loading @@ -2102,6 +2103,40 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku } } private void scheduleNotifyAppWidgetRemovedLocked(Widget widget) { long requestId = UPDATE_COUNTER.incrementAndGet(); if (widget != null) { widget.updateSequenceNos.clear(); } if (widget == null || widget.provider == null || widget.provider.zombie || widget.host.callbacks == null || widget.host.zombie) { return; } SomeArgs args = SomeArgs.obtain(); args.arg1 = widget.host; args.arg2 = widget.host.callbacks; args.arg3 = requestId; args.argi1 = widget.appWidgetId; mCallbackHandler.obtainMessage( CallbackHandler.MSG_NOTIFY_APP_WIDGET_REMOVED, args).sendToTarget(); } private void handleNotifyAppWidgetRemoved(Host host, IAppWidgetHost callbacks, int appWidgetId, long requestId) { try { callbacks.appWidgetRemoved(appWidgetId); host.lastWidgetUpdateSequenceNo = requestId; } catch (RemoteException re) { synchronized (mLock) { Slog.e(TAG, "Widget host dead: " + host.id, re); host.callbacks = null; } } } private void scheduleNotifyGroupHostsForProvidersChangedLocked(int userId) { final int[] profileIds = mSecurityPolicy.getEnabledGroupProfileIds(userId); Loading Loading @@ -2870,8 +2905,8 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku */ void removeWidgetLocked(Widget widget) { mWidgets.remove(widget); onWidgetRemovedLocked(widget); scheduleNotifyAppWidgetRemovedLocked(widget); } private void onWidgetRemovedLocked(Widget widget) { Loading Loading @@ -3587,6 +3622,7 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku public static final int MSG_NOTIFY_PROVIDER_CHANGED = 2; public static final int MSG_NOTIFY_PROVIDERS_CHANGED = 3; public static final int MSG_NOTIFY_VIEW_DATA_CHANGED = 4; public static final int MSG_NOTIFY_APP_WIDGET_REMOVED = 5; public CallbackHandler(Looper looper) { super(looper, null, false); Loading Loading @@ -3619,6 +3655,16 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku handleNotifyProviderChanged(host, callbacks, appWidgetId, info, requestId); } break; case MSG_NOTIFY_APP_WIDGET_REMOVED: { SomeArgs args = (SomeArgs) message.obj; Host host = (Host) args.arg1; IAppWidgetHost callbacks = (IAppWidgetHost) args.arg2; long requestId = (Long) args.arg3; final int appWidgetId = args.argi1; args.recycle(); handleNotifyAppWidgetRemoved(host, callbacks, appWidgetId, requestId); } break; case MSG_NOTIFY_PROVIDERS_CHANGED: { SomeArgs args = (SomeArgs) message.obj; Host host = (Host) args.arg1; Loading Loading @@ -4017,14 +4063,13 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku /** * Adds all pending updates in {@param outUpdates} keys by the update time. */ public boolean getPendingUpdatesForId(int appWidgetId, public void getPendingUpdatesForId(int appWidgetId, LongSparseArray<PendingHostUpdate> outUpdates) { long updateSequenceNo = lastWidgetUpdateSequenceNo; int N = widgets.size(); for (int i = 0; i < N; i++) { Widget widget = widgets.get(i); if (widget.appWidgetId == appWidgetId) { outUpdates.clear(); for (int j = widget.updateSequenceNos.size() - 1; j >= 0; j--) { long requestId = widget.updateSequenceNos.valueAt(j); if (requestId <= updateSequenceNo) { Loading @@ -4046,10 +4091,11 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku } outUpdates.put(requestId, update); } return true; return; } } return false; outUpdates.put(lastWidgetUpdateSequenceNo, PendingHostUpdate.appWidgetRemoved(appWidgetId)); } @Override Loading