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

Commit d91cb3ea authored by Svetoslav Ganov's avatar Svetoslav Ganov
Browse files

The list of active print jobs in print service retunring wrong result.

1. The getActivePrintJobs() method in print service is designed to return
   the active print job i.e. ones scheduled to be processed by the print
   service. Now the correct list is returned.

2. The listeners for observing the state of print jobs may be called even
   after being unregistered. Ex: state change occurs and we schedule a
   message on the app's main thread to make the notificaion. Now the app
   unregisretes the callback and on the next loop the notification message
   is handled.

bug:11200258

Change-Id: I4a497b5c9a7287a22023cafe41ce966d14300ca6
parent d3c197d9
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -131,7 +131,7 @@ public final class PrintJobInfo implements Parcelable {
    /** The name of the printer - internally used */
    private String mPrinterName;

    /** The status of the print job. */
    /** The state of the print job. */
    private int mState;

    /** The id of the app that created the job. */
@@ -555,7 +555,7 @@ public final class PrintJobInfo implements Parcelable {
        builder.append("PrintJobInfo{");
        builder.append("label: ").append(mLabel);
        builder.append(", id: ").append(mId);
        builder.append(", status: ").append(stateToString(mState));
        builder.append(", state: ").append(stateToString(mState));
        builder.append(", printer: " + mPrinterId);
        builder.append(", tag: ").append(mTag);
        builder.append(", creationTime: " + mCreationTime);
@@ -583,6 +583,9 @@ public final class PrintJobInfo implements Parcelable {
            case STATE_STARTED: {
                return "STATE_STARTED";
            }
            case STATE_BLOCKED: {
                return "STATE_BLOCKED";
            }
            case STATE_FAILED: {
                return "STATE_FAILED";
            }
+17 −6
Original line number Diff line number Diff line
@@ -146,11 +146,14 @@ public final class PrintManager {
                switch (message.what) {
                    case MSG_NOTIFY_PRINT_JOB_STATE_CHANGED: {
                        SomeArgs args = (SomeArgs) message.obj;
                        PrintJobStateChangeListener listener =
                                (PrintJobStateChangeListener) args.arg1;
                        PrintJobStateChangeListenerWrapper wrapper =
                                (PrintJobStateChangeListenerWrapper) args.arg1;
                        PrintJobStateChangeListener listener = wrapper.getListener();
                        if (listener != null) {
                            PrintJobId printJobId = (PrintJobId) args.arg2;
                        args.recycle();
                            listener.onPrintJobStateChanged(printJobId);
                        }
                        args.recycle();
                    } break;
                }
            }
@@ -217,6 +220,7 @@ public final class PrintManager {
        if (mPrintJobStateChangeListeners.isEmpty()) {
            mPrintJobStateChangeListeners = null;
        }
        wrappedListener.destroy();
        try {
            mService.removePrintJobStateChangeListener(wrappedListener, mUserId);
        } catch (RemoteException re) {
@@ -769,12 +773,19 @@ public final class PrintManager {
            PrintJobStateChangeListener listener = mWeakListener.get();
            if (handler != null && listener != null) {
                SomeArgs args = SomeArgs.obtain();
                args.arg1 = listener;
                args.arg1 = this;
                args.arg2 = printJobId;
                handler.obtainMessage(MSG_NOTIFY_PRINT_JOB_STATE_CHANGED,
                        args).sendToTarget();
            }
        }

        public void destroy() {
            mWeakListener.clear();
        }

        public PrintJobStateChangeListener getListener() {
            return mWeakListener.get();
        }
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -189,7 +189,7 @@ public class NotificationController {
            if (i == printJobCount - 1) {
                builder.setLargeIcon(((BitmapDrawable) mContext.getResources().getDrawable(
                        computeNotificationIcon(printJob))).getBitmap());
                builder.setSmallIcon(com.android.internal.R.drawable.ic_print);
                builder.setSmallIcon(computeNotificationIcon(printJob));
                builder.setContentTitle(computeNotificationTitle(printJob));
                builder.setContentText(printJob.getPrinterName());
            }
+1 −1
Original line number Diff line number Diff line
@@ -682,7 +682,7 @@ final class RemotePrintService implements DeathRecipient {
                final long identity = Binder.clearCallingIdentity();
                try {
                    return service.mSpooler.getPrintJobInfos(service.mComponentName,
                            PrintJobInfo.STATE_ANY_VISIBLE_TO_CLIENTS, PrintManager.APP_ID_ANY);
                            PrintJobInfo.STATE_ANY_SCHEDULED, PrintManager.APP_ID_ANY);
                } finally {
                    Binder.restoreCallingIdentity(identity);
                }