Loading services/print/java/com/android/server/print/RemotePrintSpooler.java +65 −69 Original line number Diff line number Diff line Loading @@ -43,6 +43,7 @@ import android.printservice.PrintService; import android.util.Slog; import android.util.TimedRemoteCaller; import com.android.internal.annotations.GuardedBy; import com.android.internal.os.TransferPipe; import libcore.io.IoUtils; Loading Loading @@ -112,6 +113,10 @@ final class RemotePrintSpooler { private boolean mCanUnbind; /** Whether a thread is currently trying to {@link #bindLocked() bind to the print service} */ @GuardedBy("mLock") private boolean mIsBinding; public static interface PrintSpoolerCallbacks { public void onPrintJobQueued(PrintJobInfo printJob); public void onAllPrintJobsForServiceHandled(ComponentName printService); Loading Loading @@ -164,10 +169,8 @@ final class RemotePrintSpooler { try { return mGetPrintJobInfosCaller.getPrintJobInfos(getRemoteInstanceLazy(), componentName, state, appId); } catch (RemoteException re) { Slog.e(LOG_TAG, "Error getting print jobs.", re); } catch (TimeoutException te) { Slog.e(LOG_TAG, "Error getting print jobs.", te); } catch (RemoteException | TimeoutException | InterruptedException e) { Slog.e(LOG_TAG, "Error getting print jobs.", e); } finally { if (DEBUG) { Slog.i(LOG_TAG, "[user: " + mUserHandle.getIdentifier() + "] getPrintJobInfos()"); Loading @@ -188,10 +191,8 @@ final class RemotePrintSpooler { } try { getRemoteInstanceLazy().createPrintJob(printJob); } catch (RemoteException re) { Slog.e(LOG_TAG, "Error creating print job.", re); } catch (TimeoutException te) { Slog.e(LOG_TAG, "Error creating print job.", te); } catch (RemoteException | TimeoutException | InterruptedException e) { Slog.e(LOG_TAG, "Error creating print job.", e); } finally { if (DEBUG) { Slog.i(LOG_TAG, "[user: " + mUserHandle.getIdentifier() + "] createPrintJob()"); Loading @@ -211,10 +212,8 @@ final class RemotePrintSpooler { } try { getRemoteInstanceLazy().writePrintJobData(fd, printJobId); } catch (RemoteException re) { Slog.e(LOG_TAG, "Error writing print job data.", re); } catch (TimeoutException te) { Slog.e(LOG_TAG, "Error writing print job data.", te); } catch (RemoteException | TimeoutException | InterruptedException e) { Slog.e(LOG_TAG, "Error writing print job data.", e); } finally { if (DEBUG) { Slog.i(LOG_TAG, "[user: " + mUserHandle.getIdentifier() + "] writePrintJobData()"); Loading @@ -238,10 +237,8 @@ final class RemotePrintSpooler { try { return mGetPrintJobInfoCaller.getPrintJobInfo(getRemoteInstanceLazy(), printJobId, appId); } catch (RemoteException re) { Slog.e(LOG_TAG, "Error getting print job info.", re); } catch (TimeoutException te) { Slog.e(LOG_TAG, "Error getting print job info.", te); } catch (RemoteException | TimeoutException | InterruptedException e) { Slog.e(LOG_TAG, "Error getting print job info.", e); } finally { if (DEBUG) { Slog.i(LOG_TAG, "[user: " + mUserHandle.getIdentifier() + "] getPrintJobInfo()"); Loading @@ -263,10 +260,8 @@ final class RemotePrintSpooler { try { return mSetPrintJobStatusCaller.setPrintJobState(getRemoteInstanceLazy(), printJobId, state, error); } catch (RemoteException re) { Slog.e(LOG_TAG, "Error setting print job state.", re); } catch (TimeoutException te) { Slog.e(LOG_TAG, "Error setting print job state.", te); } catch (RemoteException | TimeoutException | InterruptedException e) { Slog.e(LOG_TAG, "Error setting print job state.", e); } finally { if (DEBUG) { Slog.i(LOG_TAG, "[user: " + mUserHandle.getIdentifier() + "] setPrintJobState()"); Loading Loading @@ -294,7 +289,7 @@ final class RemotePrintSpooler { } try { getRemoteInstanceLazy().setProgress(printJobId, progress); } catch (RemoteException|TimeoutException re) { } catch (RemoteException | TimeoutException | InterruptedException re) { Slog.e(LOG_TAG, "Error setting progress.", re); } finally { if (DEBUG) { Loading @@ -321,8 +316,8 @@ final class RemotePrintSpooler { } try { getRemoteInstanceLazy().setStatus(printJobId, status); } catch (RemoteException|TimeoutException re) { Slog.e(LOG_TAG, "Error setting status.", re); } catch (RemoteException | TimeoutException | InterruptedException e) { Slog.e(LOG_TAG, "Error setting status.", e); } finally { if (DEBUG) { Slog.i(LOG_TAG, "[user: " + mUserHandle.getIdentifier() + "] setStatus()"); Loading Loading @@ -350,8 +345,8 @@ final class RemotePrintSpooler { } try { getRemoteInstanceLazy().setStatusRes(printJobId, status, appPackageName); } catch (RemoteException|TimeoutException re) { Slog.e(LOG_TAG, "Error setting status.", re); } catch (RemoteException | TimeoutException | InterruptedException e) { Slog.e(LOG_TAG, "Error setting status.", e); } finally { if (DEBUG) { Slog.i(LOG_TAG, "[user: " + mUserHandle.getIdentifier() + "] setStatus()"); Loading Loading @@ -380,7 +375,7 @@ final class RemotePrintSpooler { try { mCustomPrinterIconLoadedCaller.onCustomPrinterIconLoaded(getRemoteInstanceLazy(), printerId, icon); } catch (RemoteException|TimeoutException re) { } catch (RemoteException | TimeoutException | InterruptedException re) { Slog.e(LOG_TAG, "Error loading new custom printer icon.", re); } finally { if (DEBUG) { Loading Loading @@ -412,8 +407,8 @@ final class RemotePrintSpooler { try { return mGetCustomPrinterIconCaller.getCustomPrinterIcon(getRemoteInstanceLazy(), printerId); } catch (RemoteException|TimeoutException re) { Slog.e(LOG_TAG, "Error getting custom printer icon.", re); } catch (RemoteException | TimeoutException | InterruptedException e) { Slog.e(LOG_TAG, "Error getting custom printer icon.", e); return null; } finally { if (DEBUG) { Loading @@ -438,8 +433,8 @@ final class RemotePrintSpooler { } try { mClearCustomPrinterIconCache.clearCustomPrinterIconCache(getRemoteInstanceLazy()); } catch (RemoteException|TimeoutException re) { Slog.e(LOG_TAG, "Error clearing custom printer icon cache.", re); } catch (RemoteException | TimeoutException | InterruptedException e) { Slog.e(LOG_TAG, "Error clearing custom printer icon cache.", e); } finally { if (DEBUG) { Slog.i(LOG_TAG, Loading @@ -462,10 +457,8 @@ final class RemotePrintSpooler { try { return mSetPrintJobTagCaller.setPrintJobTag(getRemoteInstanceLazy(), printJobId, tag); } catch (RemoteException re) { Slog.e(LOG_TAG, "Error setting print job tag.", re); } catch (TimeoutException te) { Slog.e(LOG_TAG, "Error setting print job tag.", te); } catch (RemoteException | TimeoutException | InterruptedException e) { Slog.e(LOG_TAG, "Error setting print job tag.", e); } finally { if (DEBUG) { Slog.i(LOG_TAG, "[user: " + mUserHandle.getIdentifier() + "] setPrintJobTag()"); Loading @@ -487,10 +480,8 @@ final class RemotePrintSpooler { try { getRemoteInstanceLazy().setPrintJobCancelling(printJobId, cancelling); } catch (RemoteException re) { Slog.e(LOG_TAG, "Error setting print job cancelling.", re); } catch (TimeoutException te) { Slog.e(LOG_TAG, "Error setting print job cancelling.", te); } catch (RemoteException | TimeoutException | InterruptedException e) { Slog.e(LOG_TAG, "Error setting print job cancelling.", e); } finally { if (DEBUG) { Slog.i(LOG_TAG, "[user: " + mUserHandle.getIdentifier() Loading @@ -516,8 +507,8 @@ final class RemotePrintSpooler { } try { getRemoteInstanceLazy().pruneApprovedPrintServices(servicesToKeep); } catch (RemoteException|TimeoutException re) { Slog.e(LOG_TAG, "Error pruning approved print services.", re); } catch (RemoteException | TimeoutException | InterruptedException e) { Slog.e(LOG_TAG, "Error pruning approved print services.", e); } finally { if (DEBUG) { Slog.i(LOG_TAG, "[user: " + mUserHandle.getIdentifier() Loading @@ -538,9 +529,7 @@ final class RemotePrintSpooler { } try { getRemoteInstanceLazy().removeObsoletePrintJobs(); } catch (RemoteException re) { Slog.e(LOG_TAG, "Error removing obsolete print jobs .", re); } catch (TimeoutException te) { } catch (RemoteException | TimeoutException | InterruptedException te) { Slog.e(LOG_TAG, "Error removing obsolete print jobs .", te); } finally { if (DEBUG) { Loading Loading @@ -578,7 +567,7 @@ final class RemotePrintSpooler { try { TransferPipe.dumpAsync(getRemoteInstanceLazy().asBinder(), fd, new String[] { prefix }); } catch (IOException | TimeoutException | RemoteException e) { } catch (IOException | TimeoutException | RemoteException | InterruptedException e) { pw.println("Failed to dump remote instance: " + e); } } Loading @@ -595,7 +584,7 @@ final class RemotePrintSpooler { mCallbacks.onPrintJobStateChanged(printJob); } private IPrintSpooler getRemoteInstanceLazy() throws TimeoutException { private IPrintSpooler getRemoteInstanceLazy() throws TimeoutException, InterruptedException { synchronized (mLock) { if (mRemoteInstance != null) { return mRemoteInstance; Loading @@ -605,15 +594,23 @@ final class RemotePrintSpooler { } } private void bindLocked() throws TimeoutException { private void bindLocked() throws TimeoutException, InterruptedException { while (mIsBinding) { mLock.wait(); } if (mRemoteInstance != null) { return; } mIsBinding = true; if (DEBUG) { Slog.i(LOG_TAG, "[user: " + mUserHandle.getIdentifier() + "] bindLocked() " + (mIsLowPriority ? "low priority" : "")); } try { int flags; if (mIsLowPriority) { flags = Context.BIND_AUTO_CREATE; Loading @@ -633,16 +630,15 @@ final class RemotePrintSpooler { if (remainingMillis <= 0) { throw new TimeoutException("Cannot get spooler!"); } try { mLock.wait(remainingMillis); } catch (InterruptedException ie) { /* ignore */ } } mCanUnbind = true; } finally { mIsBinding = false; mLock.notifyAll(); } } private void unbindLocked() { if (mRemoteInstance == null) { Loading Loading
services/print/java/com/android/server/print/RemotePrintSpooler.java +65 −69 Original line number Diff line number Diff line Loading @@ -43,6 +43,7 @@ import android.printservice.PrintService; import android.util.Slog; import android.util.TimedRemoteCaller; import com.android.internal.annotations.GuardedBy; import com.android.internal.os.TransferPipe; import libcore.io.IoUtils; Loading Loading @@ -112,6 +113,10 @@ final class RemotePrintSpooler { private boolean mCanUnbind; /** Whether a thread is currently trying to {@link #bindLocked() bind to the print service} */ @GuardedBy("mLock") private boolean mIsBinding; public static interface PrintSpoolerCallbacks { public void onPrintJobQueued(PrintJobInfo printJob); public void onAllPrintJobsForServiceHandled(ComponentName printService); Loading Loading @@ -164,10 +169,8 @@ final class RemotePrintSpooler { try { return mGetPrintJobInfosCaller.getPrintJobInfos(getRemoteInstanceLazy(), componentName, state, appId); } catch (RemoteException re) { Slog.e(LOG_TAG, "Error getting print jobs.", re); } catch (TimeoutException te) { Slog.e(LOG_TAG, "Error getting print jobs.", te); } catch (RemoteException | TimeoutException | InterruptedException e) { Slog.e(LOG_TAG, "Error getting print jobs.", e); } finally { if (DEBUG) { Slog.i(LOG_TAG, "[user: " + mUserHandle.getIdentifier() + "] getPrintJobInfos()"); Loading @@ -188,10 +191,8 @@ final class RemotePrintSpooler { } try { getRemoteInstanceLazy().createPrintJob(printJob); } catch (RemoteException re) { Slog.e(LOG_TAG, "Error creating print job.", re); } catch (TimeoutException te) { Slog.e(LOG_TAG, "Error creating print job.", te); } catch (RemoteException | TimeoutException | InterruptedException e) { Slog.e(LOG_TAG, "Error creating print job.", e); } finally { if (DEBUG) { Slog.i(LOG_TAG, "[user: " + mUserHandle.getIdentifier() + "] createPrintJob()"); Loading @@ -211,10 +212,8 @@ final class RemotePrintSpooler { } try { getRemoteInstanceLazy().writePrintJobData(fd, printJobId); } catch (RemoteException re) { Slog.e(LOG_TAG, "Error writing print job data.", re); } catch (TimeoutException te) { Slog.e(LOG_TAG, "Error writing print job data.", te); } catch (RemoteException | TimeoutException | InterruptedException e) { Slog.e(LOG_TAG, "Error writing print job data.", e); } finally { if (DEBUG) { Slog.i(LOG_TAG, "[user: " + mUserHandle.getIdentifier() + "] writePrintJobData()"); Loading @@ -238,10 +237,8 @@ final class RemotePrintSpooler { try { return mGetPrintJobInfoCaller.getPrintJobInfo(getRemoteInstanceLazy(), printJobId, appId); } catch (RemoteException re) { Slog.e(LOG_TAG, "Error getting print job info.", re); } catch (TimeoutException te) { Slog.e(LOG_TAG, "Error getting print job info.", te); } catch (RemoteException | TimeoutException | InterruptedException e) { Slog.e(LOG_TAG, "Error getting print job info.", e); } finally { if (DEBUG) { Slog.i(LOG_TAG, "[user: " + mUserHandle.getIdentifier() + "] getPrintJobInfo()"); Loading @@ -263,10 +260,8 @@ final class RemotePrintSpooler { try { return mSetPrintJobStatusCaller.setPrintJobState(getRemoteInstanceLazy(), printJobId, state, error); } catch (RemoteException re) { Slog.e(LOG_TAG, "Error setting print job state.", re); } catch (TimeoutException te) { Slog.e(LOG_TAG, "Error setting print job state.", te); } catch (RemoteException | TimeoutException | InterruptedException e) { Slog.e(LOG_TAG, "Error setting print job state.", e); } finally { if (DEBUG) { Slog.i(LOG_TAG, "[user: " + mUserHandle.getIdentifier() + "] setPrintJobState()"); Loading Loading @@ -294,7 +289,7 @@ final class RemotePrintSpooler { } try { getRemoteInstanceLazy().setProgress(printJobId, progress); } catch (RemoteException|TimeoutException re) { } catch (RemoteException | TimeoutException | InterruptedException re) { Slog.e(LOG_TAG, "Error setting progress.", re); } finally { if (DEBUG) { Loading @@ -321,8 +316,8 @@ final class RemotePrintSpooler { } try { getRemoteInstanceLazy().setStatus(printJobId, status); } catch (RemoteException|TimeoutException re) { Slog.e(LOG_TAG, "Error setting status.", re); } catch (RemoteException | TimeoutException | InterruptedException e) { Slog.e(LOG_TAG, "Error setting status.", e); } finally { if (DEBUG) { Slog.i(LOG_TAG, "[user: " + mUserHandle.getIdentifier() + "] setStatus()"); Loading Loading @@ -350,8 +345,8 @@ final class RemotePrintSpooler { } try { getRemoteInstanceLazy().setStatusRes(printJobId, status, appPackageName); } catch (RemoteException|TimeoutException re) { Slog.e(LOG_TAG, "Error setting status.", re); } catch (RemoteException | TimeoutException | InterruptedException e) { Slog.e(LOG_TAG, "Error setting status.", e); } finally { if (DEBUG) { Slog.i(LOG_TAG, "[user: " + mUserHandle.getIdentifier() + "] setStatus()"); Loading Loading @@ -380,7 +375,7 @@ final class RemotePrintSpooler { try { mCustomPrinterIconLoadedCaller.onCustomPrinterIconLoaded(getRemoteInstanceLazy(), printerId, icon); } catch (RemoteException|TimeoutException re) { } catch (RemoteException | TimeoutException | InterruptedException re) { Slog.e(LOG_TAG, "Error loading new custom printer icon.", re); } finally { if (DEBUG) { Loading Loading @@ -412,8 +407,8 @@ final class RemotePrintSpooler { try { return mGetCustomPrinterIconCaller.getCustomPrinterIcon(getRemoteInstanceLazy(), printerId); } catch (RemoteException|TimeoutException re) { Slog.e(LOG_TAG, "Error getting custom printer icon.", re); } catch (RemoteException | TimeoutException | InterruptedException e) { Slog.e(LOG_TAG, "Error getting custom printer icon.", e); return null; } finally { if (DEBUG) { Loading @@ -438,8 +433,8 @@ final class RemotePrintSpooler { } try { mClearCustomPrinterIconCache.clearCustomPrinterIconCache(getRemoteInstanceLazy()); } catch (RemoteException|TimeoutException re) { Slog.e(LOG_TAG, "Error clearing custom printer icon cache.", re); } catch (RemoteException | TimeoutException | InterruptedException e) { Slog.e(LOG_TAG, "Error clearing custom printer icon cache.", e); } finally { if (DEBUG) { Slog.i(LOG_TAG, Loading @@ -462,10 +457,8 @@ final class RemotePrintSpooler { try { return mSetPrintJobTagCaller.setPrintJobTag(getRemoteInstanceLazy(), printJobId, tag); } catch (RemoteException re) { Slog.e(LOG_TAG, "Error setting print job tag.", re); } catch (TimeoutException te) { Slog.e(LOG_TAG, "Error setting print job tag.", te); } catch (RemoteException | TimeoutException | InterruptedException e) { Slog.e(LOG_TAG, "Error setting print job tag.", e); } finally { if (DEBUG) { Slog.i(LOG_TAG, "[user: " + mUserHandle.getIdentifier() + "] setPrintJobTag()"); Loading @@ -487,10 +480,8 @@ final class RemotePrintSpooler { try { getRemoteInstanceLazy().setPrintJobCancelling(printJobId, cancelling); } catch (RemoteException re) { Slog.e(LOG_TAG, "Error setting print job cancelling.", re); } catch (TimeoutException te) { Slog.e(LOG_TAG, "Error setting print job cancelling.", te); } catch (RemoteException | TimeoutException | InterruptedException e) { Slog.e(LOG_TAG, "Error setting print job cancelling.", e); } finally { if (DEBUG) { Slog.i(LOG_TAG, "[user: " + mUserHandle.getIdentifier() Loading @@ -516,8 +507,8 @@ final class RemotePrintSpooler { } try { getRemoteInstanceLazy().pruneApprovedPrintServices(servicesToKeep); } catch (RemoteException|TimeoutException re) { Slog.e(LOG_TAG, "Error pruning approved print services.", re); } catch (RemoteException | TimeoutException | InterruptedException e) { Slog.e(LOG_TAG, "Error pruning approved print services.", e); } finally { if (DEBUG) { Slog.i(LOG_TAG, "[user: " + mUserHandle.getIdentifier() Loading @@ -538,9 +529,7 @@ final class RemotePrintSpooler { } try { getRemoteInstanceLazy().removeObsoletePrintJobs(); } catch (RemoteException re) { Slog.e(LOG_TAG, "Error removing obsolete print jobs .", re); } catch (TimeoutException te) { } catch (RemoteException | TimeoutException | InterruptedException te) { Slog.e(LOG_TAG, "Error removing obsolete print jobs .", te); } finally { if (DEBUG) { Loading Loading @@ -578,7 +567,7 @@ final class RemotePrintSpooler { try { TransferPipe.dumpAsync(getRemoteInstanceLazy().asBinder(), fd, new String[] { prefix }); } catch (IOException | TimeoutException | RemoteException e) { } catch (IOException | TimeoutException | RemoteException | InterruptedException e) { pw.println("Failed to dump remote instance: " + e); } } Loading @@ -595,7 +584,7 @@ final class RemotePrintSpooler { mCallbacks.onPrintJobStateChanged(printJob); } private IPrintSpooler getRemoteInstanceLazy() throws TimeoutException { private IPrintSpooler getRemoteInstanceLazy() throws TimeoutException, InterruptedException { synchronized (mLock) { if (mRemoteInstance != null) { return mRemoteInstance; Loading @@ -605,15 +594,23 @@ final class RemotePrintSpooler { } } private void bindLocked() throws TimeoutException { private void bindLocked() throws TimeoutException, InterruptedException { while (mIsBinding) { mLock.wait(); } if (mRemoteInstance != null) { return; } mIsBinding = true; if (DEBUG) { Slog.i(LOG_TAG, "[user: " + mUserHandle.getIdentifier() + "] bindLocked() " + (mIsLowPriority ? "low priority" : "")); } try { int flags; if (mIsLowPriority) { flags = Context.BIND_AUTO_CREATE; Loading @@ -633,16 +630,15 @@ final class RemotePrintSpooler { if (remainingMillis <= 0) { throw new TimeoutException("Cannot get spooler!"); } try { mLock.wait(remainingMillis); } catch (InterruptedException ie) { /* ignore */ } } mCanUnbind = true; } finally { mIsBinding = false; mLock.notifyAll(); } } private void unbindLocked() { if (mRemoteInstance == null) { Loading