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 /services/core/java/com/android/server/content | |
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
Diffstat (limited to 'services/core/java/com/android/server/content')
-rw-r--r-- | services/core/java/com/android/server/content/SyncManager.java | 22 |
1 files changed, 17 insertions, 5 deletions
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; + } + } } |