diff options
Diffstat (limited to 'services/core/java/com/android')
7 files changed, 133 insertions, 124 deletions
diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java index 9c6e16f..f645764 100644 --- a/services/core/java/com/android/server/ConnectivityService.java +++ b/services/core/java/com/android/server/ConnectivityService.java @@ -3289,7 +3289,6 @@ public class ConnectivityService extends IConnectivityManager.Stub CharSequence title; CharSequence details; int icon; - Notification notification = new Notification(); if (notifyType == NotificationType.NO_INTERNET && networkType == ConnectivityManager.TYPE_WIFI) { title = r.getString(R.string.wifi_no_internet, 0); @@ -3324,14 +3323,17 @@ public class ConnectivityService extends IConnectivityManager.Stub return; } - notification.when = 0; - notification.icon = icon; - notification.flags = Notification.FLAG_AUTO_CANCEL; - notification.tickerText = title; - notification.color = mContext.getColor( - com.android.internal.R.color.system_notification_accent_color); - notification.setLatestEventInfo(mContext, title, details, notification.contentIntent); - notification.contentIntent = intent; + Notification notification = new Notification.Builder(mContext) + .setWhen(0) + .setSmallIcon(icon) + .setAutoCancel(true) + .setTicker(title) + .setColor(mContext.getColor( + com.android.internal.R.color.system_notification_accent_color)) + .setContentTitle(title) + .setContentText(details) + .setContentIntent(intent) + .build(); try { notificationManager.notify(NOTIFICATION_ID, id, notification); diff --git a/services/core/java/com/android/server/InputMethodManagerService.java b/services/core/java/com/android/server/InputMethodManagerService.java index 6e6fb7f..a5d536e 100644 --- a/services/core/java/com/android/server/InputMethodManagerService.java +++ b/services/core/java/com/android/server/InputMethodManagerService.java @@ -71,6 +71,7 @@ import android.graphics.drawable.Drawable; import android.inputmethodservice.InputMethodService; import android.net.Uri; import android.os.Binder; +import android.os.Bundle; import android.os.Environment; import android.os.Handler; import android.os.IBinder; @@ -212,7 +213,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub private NotificationManager mNotificationManager; private KeyguardManager mKeyguardManager; private StatusBarManagerService mStatusBar; - private Notification mImeSwitcherNotification; + private Notification.Builder mImeSwitcherNotification; private PendingIntent mImeSwitchPendingIntent; private boolean mShowOngoingImeSwitcherForPhones; private boolean mNotificationShown; @@ -798,18 +799,15 @@ public class InputMethodManagerService extends IInputMethodManager.Stub mHasFeature = context.getPackageManager().hasSystemFeature( PackageManager.FEATURE_INPUT_METHODS); - mImeSwitcherNotification = new Notification(); - mImeSwitcherNotification.icon = com.android.internal.R.drawable.ic_notification_ime_default; - mImeSwitcherNotification.when = 0; - mImeSwitcherNotification.flags = Notification.FLAG_ONGOING_EVENT; - mImeSwitcherNotification.tickerText = null; - mImeSwitcherNotification.defaults = 0; // please be quiet - mImeSwitcherNotification.sound = null; - mImeSwitcherNotification.vibrate = null; - - // Tag this notification specially so SystemUI knows it's important - mImeSwitcherNotification.extras.putBoolean(Notification.EXTRA_ALLOW_DURING_SETUP, true); - mImeSwitcherNotification.category = Notification.CATEGORY_SYSTEM; + Bundle extras = new Bundle(); + extras.putBoolean(Notification.EXTRA_ALLOW_DURING_SETUP, true); + mImeSwitcherNotification = new Notification.Builder(mContext) + .setSmallIcon(com.android.internal.R.drawable.ic_notification_ime_default) + .setWhen(0) + .setOngoing(true) + .addExtras(extras) + .setCategory(Notification.CATEGORY_SYSTEM) + .setColor(com.android.internal.R.color.system_notification_accent_color); Intent intent = new Intent(Settings.ACTION_SHOW_INPUT_METHOD_PICKER); mImeSwitchPendingIntent = PendingIntent.getBroadcast(mContext, 0, intent, 0); @@ -1766,11 +1764,9 @@ public class InputMethodManagerService extends IInputMethodManager.Stub com.android.internal.R.string.select_input_method); final CharSequence summary = InputMethodUtils.getImeAndSubtypeDisplayName( mContext, imi, mCurrentSubtype); - - mImeSwitcherNotification.color = mContext.getColor( - com.android.internal.R.color.system_notification_accent_color); - mImeSwitcherNotification.setLatestEventInfo( - mContext, title, summary, mImeSwitchPendingIntent); + mImeSwitcherNotification.setContentTitle(title) + .setContentText(summary) + .setContentIntent(mImeSwitchPendingIntent); if ((mNotificationManager != null) && !mWindowManagerService.hasNavigationBar()) { if (DEBUG) { @@ -1778,7 +1774,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub } mNotificationManager.notifyAsUser(null, com.android.internal.R.string.select_input_method, - mImeSwitcherNotification, UserHandle.ALL); + mImeSwitcherNotification.build(), UserHandle.ALL); mNotificationShown = true; } } else { diff --git a/services/core/java/com/android/server/UiModeManagerService.java b/services/core/java/com/android/server/UiModeManagerService.java index 64f3070..0b67ad8 100644 --- a/services/core/java/com/android/server/UiModeManagerService.java +++ b/services/core/java/com/android/server/UiModeManagerService.java @@ -601,21 +601,22 @@ final class UiModeManagerService extends SystemService { if (mCarModeEnabled) { Intent carModeOffIntent = new Intent(context, DisableCarModeActivity.class); - Notification n = new Notification(); - n.icon = R.drawable.stat_notify_car_mode; - n.defaults = Notification.DEFAULT_LIGHTS; - n.flags = Notification.FLAG_ONGOING_EVENT; - n.when = 0; - n.color = context.getColor( - com.android.internal.R.color.system_notification_accent_color); - n.setLatestEventInfo( - context, - context.getString(R.string.car_mode_disable_notification_title), - context.getString(R.string.car_mode_disable_notification_message), - PendingIntent.getActivityAsUser(context, 0, carModeOffIntent, 0, - null, UserHandle.CURRENT)); + Notification.Builder n = new Notification.Builder(context) + .setSmallIcon(R.drawable.stat_notify_car_mode) + .setDefaults(Notification.DEFAULT_LIGHTS) + .setOngoing(true) + .setWhen(0) + .setColor(context.getColor( + com.android.internal.R.color.system_notification_accent_color)) + .setContentTitle( + context.getString(R.string.car_mode_disable_notification_title)) + .setContentText( + context.getString(R.string.car_mode_disable_notification_message)) + .setContentIntent( + PendingIntent.getActivityAsUser(context, 0, carModeOffIntent, 0, + null, UserHandle.CURRENT)); mNotificationManager.notifyAsUser(null, - R.string.car_mode_disable_notification_title, n, UserHandle.ALL); + R.string.car_mode_disable_notification_title, n.build(), UserHandle.ALL); } else { mNotificationManager.cancelAsUser(null, R.string.car_mode_disable_notification_title, UserHandle.ALL); diff --git a/services/core/java/com/android/server/accounts/AccountManagerService.java b/services/core/java/com/android/server/accounts/AccountManagerService.java index 21f96c9..cf9edcb 100644 --- a/services/core/java/com/android/server/accounts/AccountManagerService.java +++ b/services/core/java/com/android/server/accounts/AccountManagerService.java @@ -1961,8 +1961,6 @@ public class AccountManagerService String authTokenLabel = intent.getStringExtra( GrantCredentialsPermissionActivity.EXTRAS_AUTH_TOKEN_LABEL); - Notification n = new Notification(android.R.drawable.stat_sys_warning, null, - 0 /* when */); final String titleAndSubtitle = mContext.getString(R.string.permission_request_notification_with_subtitle, account.name); @@ -1975,11 +1973,16 @@ public class AccountManagerService } UserHandle user = new UserHandle(userId); Context contextForUser = getContextForUser(user); - n.color = contextForUser.getColor( - com.android.internal.R.color.system_notification_accent_color); - n.setLatestEventInfo(contextForUser, title, subtitle, - PendingIntent.getActivityAsUser(mContext, 0, intent, - PendingIntent.FLAG_CANCEL_CURRENT, null, user)); + Notification n = new Notification.Builder(contextForUser) + .setSmallIcon(android.R.drawable.stat_sys_warning) + .setWhen(0) + .setColor(contextForUser.getColor( + com.android.internal.R.color.system_notification_accent_color)) + .setContentTitle(title) + .setContentText(subtitle) + .setContentIntent(PendingIntent.getActivityAsUser(mContext, 0, intent, + PendingIntent.FLAG_CANCEL_CURRENT, null, user)) + .build(); installNotification(getCredentialPermissionNotificationId( account, authTokenType, uid), n, user); } @@ -3495,19 +3498,21 @@ public class AccountManagerService } else { final Integer notificationId = getSigninRequiredNotificationId(accounts, account); intent.addCategory(String.valueOf(notificationId)); - 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 = contextForUser.getText(R.string.notification_title).toString(); - n.color = contextForUser.getColor( - com.android.internal.R.color.system_notification_accent_color); - n.setLatestEventInfo(contextForUser, - String.format(notificationTitleFormat, account.name), - message, PendingIntent.getActivityAsUser( - mContext, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT, - null, user)); + Notification n = new Notification.Builder(contextForUser) + .setWhen(0) + .setSmallIcon(android.R.drawable.stat_sys_warning) + .setColor(contextForUser.getColor( + com.android.internal.R.color.system_notification_accent_color)) + .setContentTitle(String.format(notificationTitleFormat, account.name)) + .setContentText(message) + .setContentIntent(PendingIntent.getActivityAsUser( + mContext, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT, + null, user)) + .build(); installNotification(notificationId, n, user); } } finally { diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java index 0d08c2a..16b97fa 100644 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -1713,22 +1713,20 @@ public final class ActivityManagerService extends ActivityManagerNative Context context = mContext.createPackageContext(process.info.packageName, 0); String text = mContext.getString(R.string.heavy_weight_notification, context.getApplicationInfo().loadLabel(context.getPackageManager())); - Notification notification = new Notification(); - notification.icon = com.android.internal.R.drawable.stat_sys_adb; //context.getApplicationInfo().icon; - notification.when = 0; - notification.flags = Notification.FLAG_ONGOING_EVENT; - notification.tickerText = text; - notification.defaults = 0; // please be quiet - notification.sound = null; - notification.vibrate = null; - notification.color = mContext.getColor( - com.android.internal.R.color.system_notification_accent_color); - notification.setLatestEventInfo(context, text, - mContext.getText(R.string.heavy_weight_notification_detail), - PendingIntent.getActivityAsUser(mContext, 0, root.intent, - PendingIntent.FLAG_CANCEL_CURRENT, null, - new UserHandle(root.userId))); - + Notification notification = new Notification.Builder(context) + .setSmallIcon(com.android.internal.R.drawable.stat_sys_adb) + .setWhen(0) + .setOngoing(true) + .setTicker(text) + .setColor(mContext.getColor( + com.android.internal.R.color.system_notification_accent_color)) + .setContentTitle(text) + .setContentText( + mContext.getText(R.string.heavy_weight_notification_detail)) + .setContentIntent(PendingIntent.getActivityAsUser(mContext, 0, + root.intent, PendingIntent.FLAG_CANCEL_CURRENT, null, + new UserHandle(root.userId))) + .build(); try { int[] outId = new int[1]; inm.enqueueNotificationWithTag("android", "android", null, @@ -1947,20 +1945,10 @@ public final class ActivityManagerService extends ActivityManagerNative } String text = mContext.getString(R.string.dump_heap_notification, procName); - Notification notification = new Notification(); - notification.icon = com.android.internal.R.drawable.stat_sys_adb; - notification.when = 0; - notification.flags = Notification.FLAG_ONGOING_EVENT|Notification.FLAG_AUTO_CANCEL; - notification.tickerText = text; - notification.defaults = 0; // please be quiet - notification.sound = null; - notification.vibrate = null; - notification.color = mContext.getColor( - com.android.internal.R.color.system_notification_accent_color); + + Intent deleteIntent = new Intent(); deleteIntent.setAction(DumpHeapActivity.ACTION_DELETE_DUMPHEAP); - notification.deleteIntent = PendingIntent.getBroadcastAsUser(mContext, 0, - deleteIntent, 0, UserHandle.OWNER); Intent intent = new Intent(); intent.setClassName("android", DumpHeapActivity.class.getName()); intent.putExtra(DumpHeapActivity.KEY_PROCESS, procName); @@ -1969,11 +1957,23 @@ public final class ActivityManagerService extends ActivityManagerNative intent.putExtra(DumpHeapActivity.KEY_DIRECT_LAUNCH, reportPackage); } int userId = UserHandle.getUserId(uid); - notification.setLatestEventInfo(mContext, text, - mContext.getText(R.string.dump_heap_notification_detail), - PendingIntent.getActivityAsUser(mContext, 0, intent, - PendingIntent.FLAG_CANCEL_CURRENT, null, - new UserHandle(userId))); + Notification notification = new Notification.Builder(mContext) + .setSmallIcon(com.android.internal.R.drawable.stat_sys_adb) + .setWhen(0) + .setOngoing(true) + .setAutoCancel(true) + .setTicker(text) + .setColor(mContext.getColor( + com.android.internal.R.color.system_notification_accent_color)) + .setContentTitle(text) + .setContentText( + mContext.getText(R.string.dump_heap_notification_detail)) + .setContentIntent(PendingIntent.getActivityAsUser(mContext, 0, + intent, PendingIntent.FLAG_CANCEL_CURRENT, null, + new UserHandle(userId))) + .setDeleteIntent(PendingIntent.getBroadcastAsUser(mContext, 0, + deleteIntent, 0, UserHandle.OWNER)) + .build(); try { int[] outId = new int[1]; diff --git a/services/core/java/com/android/server/connectivity/Tethering.java b/services/core/java/com/android/server/connectivity/Tethering.java index 897300f..c1aaf07 100644 --- a/services/core/java/com/android/server/connectivity/Tethering.java +++ b/services/core/java/com/android/server/connectivity/Tethering.java @@ -130,7 +130,8 @@ public class Tethering extends BaseNetworkObserver { private StateMachine mTetherMasterSM; - private Notification mTetheredNotification; + private Notification.Builder mTetheredNotificationBuilder; + private int mLastNotificationId; private boolean mRndisEnabled; // track the RNDIS function enabled state private boolean mUsbTetherRequested; // true if USB tethering should be started @@ -450,12 +451,13 @@ public class Tethering extends BaseNetworkObserver { return; } - if (mTetheredNotification != null) { - if (mTetheredNotification.icon == icon) { + if (mLastNotificationId != 0) { + if (mLastNotificationId == icon) { return; } - notificationManager.cancelAsUser(null, mTetheredNotification.icon, + notificationManager.cancelAsUser(null, mLastNotificationId, UserHandle.ALL); + mLastNotificationId = 0; } Intent intent = new Intent(); @@ -470,31 +472,32 @@ public class Tethering extends BaseNetworkObserver { CharSequence message = r.getText(com.android.internal.R.string. tethered_notification_message); - if (mTetheredNotification == null) { - mTetheredNotification = new Notification(); - mTetheredNotification.when = 0; - } - mTetheredNotification.icon = icon; - mTetheredNotification.defaults &= ~Notification.DEFAULT_SOUND; - mTetheredNotification.flags = Notification.FLAG_ONGOING_EVENT; - mTetheredNotification.tickerText = title; - mTetheredNotification.visibility = Notification.VISIBILITY_PUBLIC; - mTetheredNotification.color = mContext.getColor( - com.android.internal.R.color.system_notification_accent_color); - mTetheredNotification.setLatestEventInfo(mContext, title, message, pi); - mTetheredNotification.category = Notification.CATEGORY_STATUS; - - notificationManager.notifyAsUser(null, mTetheredNotification.icon, - mTetheredNotification, UserHandle.ALL); + if (mTetheredNotificationBuilder == null) { + mTetheredNotificationBuilder = new Notification.Builder(mContext); + mTetheredNotificationBuilder.setWhen(0) + .setOngoing(true) + .setColor(mContext.getColor( + com.android.internal.R.color.system_notification_accent_color)) + .setVisibility(Notification.VISIBILITY_PUBLIC) + .setCategory(Notification.CATEGORY_STATUS); + } + mTetheredNotificationBuilder.setSmallIcon(icon) + .setContentTitle(title) + .setContentText(message) + .setContentIntent(pi); + mLastNotificationId = icon; + + notificationManager.notifyAsUser(null, mLastNotificationId, + mTetheredNotificationBuilder.build(), UserHandle.ALL); } private void clearTetheredNotification() { NotificationManager notificationManager = (NotificationManager)mContext.getSystemService(Context.NOTIFICATION_SERVICE); - if (notificationManager != null && mTetheredNotification != null) { - notificationManager.cancelAsUser(null, mTetheredNotification.icon, + if (notificationManager != null && mLastNotificationId != 0) { + notificationManager.cancelAsUser(null, mLastNotificationId, UserHandle.ALL); - mTetheredNotification = null; + mLastNotificationId = 0; } } diff --git a/services/core/java/com/android/server/content/SyncManager.java b/services/core/java/com/android/server/content/SyncManager.java index 3dc282b..f222dba 100644 --- a/services/core/java/com/android/server/content/SyncManager.java +++ b/services/core/java/com/android/server/content/SyncManager.java @@ -3260,16 +3260,18 @@ public class SyncManager { 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 = contextForUser.getColor( - com.android.internal.R.color.system_notification_accent_color); - notification.setLatestEventInfo(contextForUser, - contextForUser.getString(R.string.contentServiceSyncNotificationTitle), - String.format(tooManyDeletesDescFormat.toString(), authorityName), - pendingIntent); + Notification notification = new Notification.Builder(contextForUser) + .setSmallIcon(R.drawable.stat_notify_sync_error) + .setTicker(mContext.getString(R.string.contentServiceSync)) + .setWhen(System.currentTimeMillis()) + .setColor(contextForUser.getColor( + com.android.internal.R.color.system_notification_accent_color)) + .setContentTitle(contextForUser.getString( + R.string.contentServiceSyncNotificationTitle)) + .setContentText( + String.format(tooManyDeletesDescFormat.toString(), authorityName)) + .setContentIntent(pendingIntent) + .build(); notification.flags |= Notification.FLAG_ONGOING_EVENT; mNotificationMgr.notifyAsUser(null, account.hashCode() ^ authority.hashCode(), notification, user); |