Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4a82b455 authored by Svetoslav Ganov's avatar Svetoslav Ganov
Browse files

Printing from secondary user not working.

The last refactoring of how the print dialog activity is started moved
the code that creates the pending intent from the spooler which is a
per user app to the system process but failed to create the intent
for the right user. Also the code in the print manager service that
puts a notification for a newly isntalled print service was not taking
into account the current user.

bug:11199393

Change-Id: I64ecf9dc1457ec4d58cc1a62e53735bb0793a003
parent 7ff610ee
Loading
Loading
Loading
Loading
+9 −5
Original line number Original line Diff line number Diff line
@@ -474,7 +474,8 @@ public final class PrintManagerService extends IPrintManager.Stub {
                    ComponentName component = new ComponentName(serviceInfo.packageName,
                    ComponentName component = new ComponentName(serviceInfo.packageName,
                            serviceInfo.name);
                            serviceInfo.name);
                    String label = serviceInfo.loadLabel(mContext.getPackageManager()).toString();
                    String label = serviceInfo.loadLabel(mContext.getPackageManager()).toString();
                    showEnableInstalledPrintServiceNotification(component, label);
                    showEnableInstalledPrintServiceNotification(component, label,
                            getChangingUserId());
                }
                }
            }
            }


@@ -622,12 +623,14 @@ public final class PrintManagerService extends IPrintManager.Stub {
    }
    }


    private void showEnableInstalledPrintServiceNotification(ComponentName component,
    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 intent = new Intent(Settings.ACTION_PRINT_SETTINGS);
        intent.putExtra(EXTRA_PRINT_SERVICE_COMPONENT_NAME, component.flattenToString());
        intent.putExtra(EXTRA_PRINT_SERVICE_COMPONENT_NAME, component.flattenToString());


        PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, intent,
        PendingIntent pendingIntent = PendingIntent.getActivityAsUser(mContext, 0, intent,
                PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_CANCEL_CURRENT, null);
                PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_CANCEL_CURRENT, null, userHandle);


        Notification.Builder builder = new Notification.Builder(mContext)
        Notification.Builder builder = new Notification.Builder(mContext)
                .setSmallIcon(R.drawable.ic_print)
                .setSmallIcon(R.drawable.ic_print)
@@ -642,6 +645,7 @@ public final class PrintManagerService extends IPrintManager.Stub {
                .getSystemService(Context.NOTIFICATION_SERVICE);
                .getSystemService(Context.NOTIFICATION_SERVICE);


        String notificationTag = getClass().getName() + ":" + component.flattenToString();
        String notificationTag = getClass().getName() + ":" + component.flattenToString();
        notificationManager.notify(notificationTag, 0, builder.build());
        notificationManager.notifyAsUser(notificationTag, 0, builder.build(),
                userHandle);
    }
    }
}
}
+4 −2
Original line number Original line Diff line number Diff line
@@ -37,6 +37,7 @@ import android.os.Looper;
import android.os.Message;
import android.os.Message;
import android.os.RemoteCallbackList;
import android.os.RemoteCallbackList;
import android.os.RemoteException;
import android.os.RemoteException;
import android.os.UserHandle;
import android.print.IPrintDocumentAdapter;
import android.print.IPrintDocumentAdapter;
import android.print.IPrintJobStateChangeListener;
import android.print.IPrintJobStateChangeListener;
import android.print.IPrinterDiscoveryObserver;
import android.print.IPrinterDiscoveryObserver;
@@ -199,9 +200,10 @@ final class UserState implements PrintSpoolerCallbacks, PrintServiceCallbacks {
            intent.putExtra(PrintManager.EXTRA_PRINT_JOB, printJob);
            intent.putExtra(PrintManager.EXTRA_PRINT_JOB, printJob);
            intent.putExtra(DocumentsContract.EXTRA_PACKAGE_NAME, packageName);
            intent.putExtra(DocumentsContract.EXTRA_PACKAGE_NAME, packageName);


            IntentSender intentSender = PendingIntent.getActivity(
            IntentSender intentSender = PendingIntent.getActivityAsUser(
                    mContext, 0, intent, PendingIntent.FLAG_ONE_SHOT
                    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();
            Bundle result = new Bundle();
            result.putParcelable(PrintManager.EXTRA_PRINT_JOB, printJob);
            result.putParcelable(PrintManager.EXTRA_PRINT_JOB, printJob);