Merge "Printing from secondary user not working." into klp-dev
diff --git a/services/java/com/android/server/print/PrintManagerService.java b/services/java/com/android/server/print/PrintManagerService.java
index 7538caf..edd6b25 100644
--- a/services/java/com/android/server/print/PrintManagerService.java
+++ b/services/java/com/android/server/print/PrintManagerService.java
@@ -474,7 +474,8 @@
                     ComponentName component = new ComponentName(serviceInfo.packageName,
                             serviceInfo.name);
                     String label = serviceInfo.loadLabel(mContext.getPackageManager()).toString();
-                    showEnableInstalledPrintServiceNotification(component, label);
+                    showEnableInstalledPrintServiceNotification(component, label,
+                            getChangingUserId());
                 }
             }
 
@@ -622,12 +623,14 @@
     }
 
     private void showEnableInstalledPrintServiceNotification(ComponentName component,
-            String label) {
+            String label, int userId) {
+        UserHandle userHandle = new UserHandle(userId);
+
         Intent intent = new Intent(Settings.ACTION_PRINT_SETTINGS);
         intent.putExtra(EXTRA_PRINT_SERVICE_COMPONENT_NAME, component.flattenToString());
 
-        PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, intent,
-                PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_CANCEL_CURRENT, null);
+        PendingIntent pendingIntent = PendingIntent.getActivityAsUser(mContext, 0, intent,
+                PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_CANCEL_CURRENT, null, userHandle);
 
         Notification.Builder builder = new Notification.Builder(mContext)
                 .setSmallIcon(R.drawable.ic_print)
@@ -642,6 +645,7 @@
                 .getSystemService(Context.NOTIFICATION_SERVICE);
 
         String notificationTag = getClass().getName() + ":" + component.flattenToString();
-        notificationManager.notify(notificationTag, 0, builder.build());
+        notificationManager.notifyAsUser(notificationTag, 0, builder.build(),
+                userHandle);
     }
 }
diff --git a/services/java/com/android/server/print/UserState.java b/services/java/com/android/server/print/UserState.java
index b894855d..b69dcee 100644
--- a/services/java/com/android/server/print/UserState.java
+++ b/services/java/com/android/server/print/UserState.java
@@ -37,6 +37,7 @@
 import android.os.Message;
 import android.os.RemoteCallbackList;
 import android.os.RemoteException;
+import android.os.UserHandle;
 import android.print.IPrintDocumentAdapter;
 import android.print.IPrintJobStateChangeListener;
 import android.print.IPrinterDiscoveryObserver;
@@ -199,9 +200,10 @@
             intent.putExtra(PrintManager.EXTRA_PRINT_JOB, printJob);
             intent.putExtra(DocumentsContract.EXTRA_PACKAGE_NAME, packageName);
 
-            IntentSender intentSender = PendingIntent.getActivity(
+            IntentSender intentSender = PendingIntent.getActivityAsUser(
                     mContext, 0, intent, PendingIntent.FLAG_ONE_SHOT
-                    | PendingIntent.FLAG_CANCEL_CURRENT).getIntentSender();
+                    | PendingIntent.FLAG_CANCEL_CURRENT, null, new UserHandle(mUserId))
+                    .getIntentSender();
 
             Bundle result = new Bundle();
             result.putParcelable(PrintManager.EXTRA_PRINT_JOB, printJob);