Revert "Do not use notifyAsUser or cancelAsUser"

This reverts commit 69fc7189464e1245c0851269e08e2ef383838dcd.

Reason for revert: bad merge causing breakages

Change-Id: Ib49372a850eefa1dd00e3eaad035cc59d538dc8e
diff --git a/src/com/android/phone/NotificationMgr.java b/src/com/android/phone/NotificationMgr.java
index 5a5b444..e556775 100644
--- a/src/com/android/phone/NotificationMgr.java
+++ b/src/com/android/phone/NotificationMgr.java
@@ -26,7 +26,6 @@
 import android.content.Context;
 import android.content.Intent;
 import android.content.SharedPreferences;
-import android.content.pm.PackageManager;
 import android.content.pm.ResolveInfo;
 import android.content.pm.UserInfo;
 import android.content.res.Resources;
@@ -108,6 +107,7 @@
     private PhoneGlobals mApp;
 
     private Context mContext;
+    private NotificationManager mNotificationManager;
     private StatusBarManager mStatusBarManager;
     private UserManager mUserManager;
     private Toast mToast;
@@ -152,6 +152,8 @@
     private NotificationMgr(PhoneGlobals app) {
         mApp = app;
         mContext = app;
+        mNotificationManager =
+                (NotificationManager) app.getSystemService(Context.NOTIFICATION_SERVICE);
         mStatusBarManager =
                 (StatusBarManager) app.getSystemService(Context.STATUS_BAR_SERVICE);
         mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
@@ -376,7 +378,7 @@
                         && !user.isManagedProfile()) {
                     if (!maybeSendVoicemailNotificationUsingDefaultDialer(phone, vmCount, vmNumber,
                             pendingIntent, isSettingsIntent, userHandle, isRefresh)) {
-                        notifyAsUser(
+                        mNotificationManager.notifyAsUser(
                                 Integer.toString(subId) /* tag */,
                                 VOICEMAIL_NOTIFICATION,
                                 notification,
@@ -394,7 +396,7 @@
                         && !user.isManagedProfile()) {
                     if (!maybeSendVoicemailNotificationUsingDefaultDialer(phone, 0, null, null,
                             false, userHandle, isRefresh)) {
-                        cancelAsUser(
+                        mNotificationManager.cancelAsUser(
                                 Integer.toString(subId) /* tag */,
                                 VOICEMAIL_NOTIFICATION,
                                 userHandle);
@@ -538,7 +540,7 @@
                     intent, mSubscriptionManager.getActiveSubscriptionInfo(subId));
             builder.setContentIntent(PendingIntent.getActivity(mContext, subId /* requestCode */,
                     intent, 0));
-            notifyAsUser(
+            mNotificationManager.notifyAsUser(
                     Integer.toString(subId) /* tag */,
                     CALL_FORWARD_NOTIFICATION,
                     builder.build(),
@@ -550,7 +552,7 @@
                     continue;
                 }
                 UserHandle userHandle = user.getUserHandle();
-                cancelAsUser(
+                mNotificationManager.cancelAsUser(
                         Integer.toString(subId) /* tag */,
                         CALL_FORWARD_NOTIFICATION,
                         userHandle);
@@ -598,35 +600,8 @@
                 .setContentIntent(contentIntent);
         final Notification notif =
                 new Notification.BigTextStyle(builder).bigText(contentText).build();
-        notifyAsUser(null /* tag */, DATA_ROAMING_NOTIFICATION, notif, UserHandle.ALL);
-    }
-
-    private void notifyAsUser(String tag, int id, Notification notification, UserHandle user) {
-        try {
-            Context contextForUser =
-                    mContext.createPackageContextAsUser(mContext.getPackageName(), 0, user);
-            NotificationManager notificationManager =
-                    (NotificationManager) contextForUser.getSystemService(
-                            Context.NOTIFICATION_SERVICE);
-            notificationManager.notify(tag, id, notification);
-        } catch (PackageManager.NameNotFoundException e) {
-            Log.e(LOG_TAG, "unable to notify for user " + user);
-            e.printStackTrace();
-        }
-    }
-
-    private void cancelAsUser(String tag, int id, UserHandle user) {
-        try {
-            Context contextForUser =
-                    mContext.createPackageContextAsUser(mContext.getPackageName(), 0, user);
-            NotificationManager notificationManager =
-                    (NotificationManager) contextForUser.getSystemService(
-                            Context.NOTIFICATION_SERVICE);
-            notificationManager.cancel(tag, id);
-        } catch (PackageManager.NameNotFoundException e) {
-            Log.e(LOG_TAG, "unable to cancel for user " + user);
-            e.printStackTrace();
-        }
+        mNotificationManager.notifyAsUser(
+                null /* tag */, DATA_ROAMING_NOTIFICATION, notif, UserHandle.ALL);
     }
 
     /**
@@ -634,7 +609,7 @@
      */
     /* package */ void hideDataRoamingNotification() {
         if (DBG) log("hideDataRoamingNotification()...");
-        cancelAsUser(null, DATA_ROAMING_NOTIFICATION, UserHandle.ALL);
+        mNotificationManager.cancel(DATA_ROAMING_NOTIFICATION);
     }
 
     /**
@@ -667,7 +642,7 @@
                 mContext.getString(R.string.mobile_network_settings_class)));
         intent.putExtra(GsmUmtsOptions.EXTRA_SUB_ID, subId);
         builder.setContentIntent(PendingIntent.getActivity(mContext, 0, intent, 0));
-        notifyAsUser(
+        mNotificationManager.notifyAsUser(
                 Integer.toString(subId) /* tag */,
                 SELECTED_OPERATOR_FAIL_NOTIFICATION,
                 builder.build(),
@@ -680,7 +655,7 @@
      */
     private void cancelNetworkSelection(int subId) {
         if (DBG) log("cancelNetworkSelection()...");
-        cancelAsUser(
+        mNotificationManager.cancelAsUser(
                 Integer.toString(subId) /* tag */, SELECTED_OPERATOR_FAIL_NOTIFICATION,
                 UserHandle.ALL);
     }