diff options
| author | Kenny Guy <kennyguy@google.com> | 2014-09-01 20:56:12 +0100 |
|---|---|---|
| committer | Kenny Guy <kennyguy@google.com> | 2014-09-01 20:56:12 +0100 |
| commit | 07ad8dc2087aa02da48353acc19ba82e62d99f82 (patch) | |
| tree | 342c526eb30377c49be26ece7e1457555e8fb26c | |
| parent | e11ac78ccd907159f2b75fd3f90dd59c279ae11e (diff) | |
| download | frameworks_base-07ad8dc2087aa02da48353acc19ba82e62d99f82.zip frameworks_base-07ad8dc2087aa02da48353acc19ba82e62d99f82.tar.gz frameworks_base-07ad8dc2087aa02da48353acc19ba82e62d99f82.tar.bz2 | |
Use context for user when calling notifyAsUser
Create a context for the user the notification is
being posted for when using NotificationManager.notifyAsUser.
Bug: 17002733
Change-Id: Ie41d27bbb781ca38cc9bc910bd4410b8862edee1
3 files changed, 42 insertions, 11 deletions
diff --git a/services/core/java/com/android/server/accounts/AccountManagerService.java b/services/core/java/com/android/server/accounts/AccountManagerService.java index 94d979e..c469b42 100644 --- a/services/core/java/com/android/server/accounts/AccountManagerService.java +++ b/services/core/java/com/android/server/accounts/AccountManagerService.java @@ -1700,9 +1700,10 @@ public class AccountManagerService subtitle = titleAndSubtitle.substring(index + 1); } UserHandle user = new UserHandle(userId); - n.color = mContext.getResources().getColor( + Context contextForUser = getContextForUser(user); + n.color = contextForUser.getResources().getColor( com.android.internal.R.color.system_notification_accent_color); - n.setLatestEventInfo(mContext, title, subtitle, + n.setLatestEventInfo(contextForUser, title, subtitle, PendingIntent.getActivityAsUser(mContext, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT, null, user)); installNotification(getCredentialPermissionNotificationId( @@ -2968,11 +2969,12 @@ public class AccountManagerService Notification n = new Notification(android.R.drawable.stat_sys_warning, null, 0 /* when */); UserHandle user = new UserHandle(userId); + Context contextForUser = getContextForUser(user); final String notificationTitleFormat = - mContext.getText(R.string.notification_title).toString(); - n.color = mContext.getResources().getColor( + contextForUser.getText(R.string.notification_title).toString(); + n.color = contextForUser.getResources().getColor( com.android.internal.R.color.system_notification_accent_color); - n.setLatestEventInfo(mContext, + n.setLatestEventInfo(contextForUser, String.format(notificationTitleFormat, account.name), message, PendingIntent.getActivityAsUser( mContext, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT, @@ -3478,4 +3480,13 @@ public class AccountManagerService } return authTokensForAccount; } + + private Context getContextForUser(UserHandle user) { + try { + return mContext.createPackageContextAsUser(mContext.getPackageName(), 0, user); + } catch (NameNotFoundException e) { + // Default to mContext, not finding the package system is running as is unlikely. + return mContext; + } + } } diff --git a/services/core/java/com/android/server/content/SyncManager.java b/services/core/java/com/android/server/content/SyncManager.java index 9e169d9..f6beb9a 100644 --- a/services/core/java/com/android/server/content/SyncManager.java +++ b/services/core/java/com/android/server/content/SyncManager.java @@ -46,6 +46,7 @@ import android.content.SyncStatusInfo; import android.content.pm.ApplicationInfo; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; +import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.ProviderInfo; import android.content.pm.RegisteredServicesCache; import android.content.pm.RegisteredServicesCacheListener; @@ -3098,26 +3099,28 @@ public class SyncManager { return; } + UserHandle user = new UserHandle(userId); final PendingIntent pendingIntent = PendingIntent .getActivityAsUser(mContext, 0, clickIntent, - PendingIntent.FLAG_CANCEL_CURRENT, null, new UserHandle(userId)); + PendingIntent.FLAG_CANCEL_CURRENT, null, user); CharSequence tooManyDeletesDescFormat = mContext.getResources().getText( R.string.contentServiceTooManyDeletesNotificationDesc); + Context contextForUser = getContextForUser(user); Notification notification = new Notification(R.drawable.stat_notify_sync_error, mContext.getString(R.string.contentServiceSync), System.currentTimeMillis()); - notification.color = mContext.getResources().getColor( + notification.color = contextForUser.getResources().getColor( com.android.internal.R.color.system_notification_accent_color); - notification.setLatestEventInfo(mContext, - mContext.getString(R.string.contentServiceSyncNotificationTitle), + notification.setLatestEventInfo(contextForUser, + contextForUser.getString(R.string.contentServiceSyncNotificationTitle), String.format(tooManyDeletesDescFormat.toString(), authorityName), pendingIntent); notification.flags |= Notification.FLAG_ONGOING_EVENT; mNotificationMgr.notifyAsUser(null, account.hashCode() ^ authority.hashCode(), - notification, new UserHandle(userId)); + notification, user); } /** @@ -3305,4 +3308,13 @@ public class SyncManager { return mTable.size(); } } + + private Context getContextForUser(UserHandle user) { + try { + return mContext.createPackageContextAsUser(mContext.getPackageName(), 0, user); + } catch (NameNotFoundException e) { + // Default to mContext, not finding the package system is running as is unlikely. + return mContext; + } + } } diff --git a/services/print/java/com/android/server/print/PrintManagerService.java b/services/print/java/com/android/server/print/PrintManagerService.java index ce91f3d..64242ba 100644 --- a/services/print/java/com/android/server/print/PrintManagerService.java +++ b/services/print/java/com/android/server/print/PrintManagerService.java @@ -26,6 +26,7 @@ import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; +import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.ResolveInfo; import android.content.pm.ServiceInfo; import android.content.pm.UserInfo; @@ -730,7 +731,14 @@ public final class PrintManagerService extends SystemService { PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_CANCEL_CURRENT, null, userHandle); - Notification.Builder builder = new Notification.Builder(mContext) + Context builderContext = mContext; + try { + builderContext = mContext.createPackageContextAsUser(mContext.getPackageName(), 0, + userHandle); + } catch (NameNotFoundException e) { + // Ignore can't find the package the system is running as. + } + Notification.Builder builder = new Notification.Builder(builderContext) .setSmallIcon(R.drawable.ic_print) .setContentTitle(mContext.getString(R.string.print_service_installed_title, label)) |
