diff options
Diffstat (limited to 'services/core/java/com/android/server/connectivity/Tethering.java')
-rw-r--r-- | services/core/java/com/android/server/connectivity/Tethering.java | 49 |
1 files changed, 26 insertions, 23 deletions
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; } } |