1616
1717package com .android .server ;
1818
19+ import android .app .ActivityManagerNative ;
1920import android .app .AlarmManager ;
2021import android .app .PendingIntent ;
2122import android .appwidget .AppWidgetManager ;
2728import android .content .IntentFilter ;
2829import android .content .ServiceConnection ;
2930import android .content .pm .PackageManager ;
31+ import android .os .Binder ;
3032import android .os .Bundle ;
3133import android .os .IBinder ;
3234import android .os .RemoteException ;
@@ -193,66 +195,79 @@ public void onReceive(Context context, Intent intent) {
193195 }, UserHandle .ALL , userFilter , null , null );
194196 }
195197
198+ private int getCallingOrCurrentUserId () {
199+ int callingUid = Binder .getCallingUid ();
200+ if (callingUid == android .os .Process .myUid ()) {
201+ try {
202+ return ActivityManagerNative .getDefault ().getCurrentUser ().id ;
203+ } catch (RemoteException re ) {
204+ return UserHandle .getUserId (callingUid );
205+ }
206+ } else {
207+ return UserHandle .getUserId (callingUid );
208+ }
209+ }
210+
196211 @ Override
197212 public int allocateAppWidgetId (String packageName , int hostId ) throws RemoteException {
198- return getImplForUser (UserHandle . getCallingUserId ()).allocateAppWidgetId (
213+ return getImplForUser (getCallingOrCurrentUserId ()).allocateAppWidgetId (
199214 packageName , hostId );
200215 }
201216
202217 @ Override
203218 public void deleteAppWidgetId (int appWidgetId ) throws RemoteException {
204- getImplForUser (UserHandle . getCallingUserId ()).deleteAppWidgetId (appWidgetId );
219+ getImplForUser (getCallingOrCurrentUserId ()).deleteAppWidgetId (appWidgetId );
205220 }
206221
207222 @ Override
208223 public void deleteHost (int hostId ) throws RemoteException {
209- getImplForUser (UserHandle . getCallingUserId ()).deleteHost (hostId );
224+ getImplForUser (getCallingOrCurrentUserId ()).deleteHost (hostId );
210225 }
211226
212227 @ Override
213228 public void deleteAllHosts () throws RemoteException {
214- getImplForUser (UserHandle . getCallingUserId ()).deleteAllHosts ();
229+ getImplForUser (getCallingOrCurrentUserId ()).deleteAllHosts ();
215230 }
216231
217232 @ Override
218233 public void bindAppWidgetId (int appWidgetId , ComponentName provider , Bundle options )
219234 throws RemoteException {
220- getImplForUser (UserHandle . getCallingUserId ()).bindAppWidgetId (appWidgetId , provider ,
235+ getImplForUser (getCallingOrCurrentUserId ()).bindAppWidgetId (appWidgetId , provider ,
221236 options );
222237 }
223238
224239 @ Override
225240 public boolean bindAppWidgetIdIfAllowed (
226241 String packageName , int appWidgetId , ComponentName provider , Bundle options )
227242 throws RemoteException {
228- return getImplForUser (UserHandle . getCallingUserId ()).bindAppWidgetIdIfAllowed (
243+ return getImplForUser (getCallingOrCurrentUserId ()).bindAppWidgetIdIfAllowed (
229244 packageName , appWidgetId , provider , options );
230245 }
231246
232247 @ Override
233248 public boolean hasBindAppWidgetPermission (String packageName ) throws RemoteException {
234- return getImplForUser (UserHandle . getCallingUserId ()).hasBindAppWidgetPermission (
249+ return getImplForUser (getCallingOrCurrentUserId ()).hasBindAppWidgetPermission (
235250 packageName );
236251 }
237252
238253 @ Override
239254 public void setBindAppWidgetPermission (String packageName , boolean permission )
240255 throws RemoteException {
241- getImplForUser (UserHandle . getCallingUserId ()).setBindAppWidgetPermission (
256+ getImplForUser (getCallingOrCurrentUserId ()).setBindAppWidgetPermission (
242257 packageName , permission );
243258 }
244259
245260 @ Override
246261 public void bindRemoteViewsService (int appWidgetId , Intent intent , IBinder connection )
247262 throws RemoteException {
248- getImplForUser (UserHandle . getCallingUserId ()).bindRemoteViewsService (
263+ getImplForUser (getCallingOrCurrentUserId ()).bindRemoteViewsService (
249264 appWidgetId , intent , connection );
250265 }
251266
252267 @ Override
253268 public int [] startListening (IAppWidgetHost host , String packageName , int hostId ,
254269 List <RemoteViews > updatedViews ) throws RemoteException {
255- return getImplForUser (UserHandle . getCallingUserId ()).startListening (host ,
270+ return getImplForUser (getCallingOrCurrentUserId ()).startListening (host ,
256271 packageName , hostId , updatedViews );
257272 }
258273
@@ -287,27 +302,27 @@ private AppWidgetServiceImpl getImplForUser(int userId) {
287302
288303 @ Override
289304 public int [] getAppWidgetIds (ComponentName provider ) throws RemoteException {
290- return getImplForUser (UserHandle . getCallingUserId ()).getAppWidgetIds (provider );
305+ return getImplForUser (getCallingOrCurrentUserId ()).getAppWidgetIds (provider );
291306 }
292307
293308 @ Override
294309 public AppWidgetProviderInfo getAppWidgetInfo (int appWidgetId ) throws RemoteException {
295- return getImplForUser (UserHandle . getCallingUserId ()).getAppWidgetInfo (appWidgetId );
310+ return getImplForUser (getCallingOrCurrentUserId ()).getAppWidgetInfo (appWidgetId );
296311 }
297312
298313 @ Override
299314 public RemoteViews getAppWidgetViews (int appWidgetId ) throws RemoteException {
300- return getImplForUser (UserHandle . getCallingUserId ()).getAppWidgetViews (appWidgetId );
315+ return getImplForUser (getCallingOrCurrentUserId ()).getAppWidgetViews (appWidgetId );
301316 }
302317
303318 @ Override
304319 public void updateAppWidgetOptions (int appWidgetId , Bundle options ) {
305- getImplForUser (UserHandle . getCallingUserId ()).updateAppWidgetOptions (appWidgetId , options );
320+ getImplForUser (getCallingOrCurrentUserId ()).updateAppWidgetOptions (appWidgetId , options );
306321 }
307322
308323 @ Override
309324 public Bundle getAppWidgetOptions (int appWidgetId ) {
310- return getImplForUser (UserHandle . getCallingUserId ()).getAppWidgetOptions (appWidgetId );
325+ return getImplForUser (getCallingOrCurrentUserId ()).getAppWidgetOptions (appWidgetId );
311326 }
312327
313328 static int [] getAppWidgetIds (Provider p ) {
@@ -321,43 +336,43 @@ static int[] getAppWidgetIds(Provider p) {
321336
322337 @ Override
323338 public List <AppWidgetProviderInfo > getInstalledProviders () throws RemoteException {
324- return getImplForUser (UserHandle . getCallingUserId ()).getInstalledProviders ();
339+ return getImplForUser (getCallingOrCurrentUserId ()).getInstalledProviders ();
325340 }
326341
327342 @ Override
328343 public void notifyAppWidgetViewDataChanged (int [] appWidgetIds , int viewId )
329344 throws RemoteException {
330- getImplForUser (UserHandle . getCallingUserId ()).notifyAppWidgetViewDataChanged (
345+ getImplForUser (getCallingOrCurrentUserId ()).notifyAppWidgetViewDataChanged (
331346 appWidgetIds , viewId );
332347 }
333348
334349 @ Override
335350 public void partiallyUpdateAppWidgetIds (int [] appWidgetIds , RemoteViews views )
336351 throws RemoteException {
337- getImplForUser (UserHandle . getCallingUserId ()).partiallyUpdateAppWidgetIds (
352+ getImplForUser (getCallingOrCurrentUserId ()).partiallyUpdateAppWidgetIds (
338353 appWidgetIds , views );
339354 }
340355
341356 @ Override
342357 public void stopListening (int hostId ) throws RemoteException {
343- getImplForUser (UserHandle . getCallingUserId ()).stopListening (hostId );
358+ getImplForUser (getCallingOrCurrentUserId ()).stopListening (hostId );
344359 }
345360
346361 @ Override
347362 public void unbindRemoteViewsService (int appWidgetId , Intent intent ) throws RemoteException {
348- getImplForUser (UserHandle . getCallingUserId ()).unbindRemoteViewsService (
363+ getImplForUser (getCallingOrCurrentUserId ()).unbindRemoteViewsService (
349364 appWidgetId , intent );
350365 }
351366
352367 @ Override
353368 public void updateAppWidgetIds (int [] appWidgetIds , RemoteViews views ) throws RemoteException {
354- getImplForUser (UserHandle . getCallingUserId ()).updateAppWidgetIds (appWidgetIds , views );
369+ getImplForUser (getCallingOrCurrentUserId ()).updateAppWidgetIds (appWidgetIds , views );
355370 }
356371
357372 @ Override
358373 public void updateAppWidgetProvider (ComponentName provider , RemoteViews views )
359374 throws RemoteException {
360- getImplForUser (UserHandle . getCallingUserId ()).updateAppWidgetProvider (provider , views );
375+ getImplForUser (getCallingOrCurrentUserId ()).updateAppWidgetProvider (provider , views );
361376 }
362377
363378 @ Override
0 commit comments