@@ -98,21 +98,19 @@ public void systemReady(boolean safeMode) {
9898
9999 IntentFilter userFilter = new IntentFilter ();
100100 userFilter .addAction (Intent .ACTION_USER_REMOVED );
101+ userFilter .addAction (Intent .ACTION_USER_STOPPING );
101102 mContext .registerReceiver (new BroadcastReceiver () {
102103 @ Override
103104 public void onReceive (Context context , Intent intent ) {
104- onUserRemoved (intent .getIntExtra (Intent .EXTRA_USER_HANDLE , -1 ));
105+ if (Intent .ACTION_USER_REMOVED .equals (intent .getAction ())) {
106+ onUserRemoved (intent .getIntExtra (Intent .EXTRA_USER_HANDLE ,
107+ UserHandle .USER_NULL ));
108+ } else if (Intent .ACTION_USER_STOPPING .equals (intent .getAction ())) {
109+ onUserStopping (intent .getIntExtra (Intent .EXTRA_USER_HANDLE ,
110+ UserHandle .USER_NULL ));
111+ }
105112 }
106113 }, userFilter );
107-
108- IntentFilter userStopFilter = new IntentFilter ();
109- userStopFilter .addAction (Intent .ACTION_USER_STOPPED );
110- mContext .registerReceiverAsUser (new BroadcastReceiver () {
111- @ Override
112- public void onReceive (Context context , Intent intent ) {
113- onUserStopped (getSendingUserId ());
114- }
115- }, UserHandle .ALL , userFilter , null , null );
116114 }
117115
118116 /**
@@ -203,7 +201,7 @@ public void onUserRemoved(int userId) {
203201 synchronized (mAppWidgetServices ) {
204202 AppWidgetServiceImpl impl = mAppWidgetServices .get (userId );
205203 mAppWidgetServices .remove (userId );
206-
204+
207205 if (impl == null ) {
208206 AppWidgetServiceImpl .getSettingsFile (userId ).delete ();
209207 } else {
@@ -212,7 +210,15 @@ public void onUserRemoved(int userId) {
212210 }
213211 }
214212
215- public void onUserStopped (int userId ) {
213+ public void onUserStopping (int userId ) {
214+ if (userId < 1 ) return ;
215+ synchronized (mAppWidgetServices ) {
216+ AppWidgetServiceImpl impl = mAppWidgetServices .get (userId );
217+ if (impl != null ) {
218+ mAppWidgetServices .remove (userId );
219+ impl .onUserStopping ();
220+ }
221+ }
216222 }
217223
218224 private AppWidgetServiceImpl getImplForUser (int userId ) {
@@ -324,11 +330,11 @@ public void onReceive(Context context, Intent intent) {
324330 String action = intent .getAction ();
325331 // Slog.d(TAG, "received " + action);
326332 if (Intent .ACTION_BOOT_COMPLETED .equals (action )) {
327- int userId = intent .getIntExtra (Intent .EXTRA_USER_HANDLE , - 1 );
333+ int userId = intent .getIntExtra (Intent .EXTRA_USER_HANDLE , UserHandle . USER_NULL );
328334 if (userId >= 0 ) {
329335 getImplForUser (userId ).sendInitialBroadcasts ();
330336 } else {
331- Slog .w (TAG , "Not user handle supplied in " + intent );
337+ Slog .w (TAG , "Incorrect user handle supplied in " + intent );
332338 }
333339 } else if (Intent .ACTION_CONFIGURATION_CHANGED .equals (action )) {
334340 for (int i = 0 ; i < mAppWidgetServices .size (); i ++) {
0 commit comments