Loading packages/PrintSpooler/flags/flags.aconfig +7 −0 Original line number Diff line number Diff line Loading @@ -14,3 +14,10 @@ flag { description: "Metrics tracking final print job status, printer discovery, printer capabilities, and major UI actions." bug: "390478410" } flag { name: "enable_print_debug_option" namespace: "printing" description: "Enable extra debug logging by checking a runtime system property." bug: "397418860" } packages/PrintSpooler/src/com/android/printspooler/model/RemotePrintDocument.java +37 −25 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ import android.os.Looper; import android.os.Message; import android.os.ParcelFileDescriptor; import android.os.RemoteException; import android.os.SystemProperties; import android.print.ILayoutResultCallback; import android.print.IPrintDocumentAdapter; import android.print.IPrintDocumentAdapterObserver; Loading @@ -40,6 +41,7 @@ import android.util.Log; import com.android.internal.util.function.pooled.PooledLambda; import com.android.printspooler.R; import com.android.printspooler.flags.Flags; import com.android.printspooler.util.PageRangeUtils; import libcore.io.IoUtils; Loading @@ -59,6 +61,9 @@ public final class RemotePrintDocument { private static final boolean DEBUG = false; private static final String PRINT_DEBUG_LOG_PROP = "debug.printing.logs.enabled"; private static final String PRINT_DEBUG_LOG_PROP_ENABLED = "true"; private static final long FORCE_CANCEL_TIMEOUT = 1000; // ms private static final int STATE_INITIAL = 0; Loading Loading @@ -184,7 +189,7 @@ public final class RemotePrintDocument { } public void start() { if (DEBUG) { if (DEBUG || debugLogsEnabled()) { Log.i(LOG_TAG, "[CALLED] start()"); } if (mState == STATE_FAILED) { Loading @@ -208,7 +213,7 @@ public final class RemotePrintDocument { public boolean update(PrintAttributes attributes, PageRange[] pages, boolean preview) { boolean willUpdate; if (DEBUG) { if (DEBUG || debugLogsEnabled()) { Log.i(LOG_TAG, "[CALLED] update()"); } Loading Loading @@ -269,7 +274,7 @@ public final class RemotePrintDocument { mState = STATE_UPDATING; } else { willUpdate = false; if (DEBUG) { if (DEBUG || debugLogsEnabled()) { Log.i(LOG_TAG, "[SKIPPING] No update needed"); } } Loading @@ -283,7 +288,7 @@ public final class RemotePrintDocument { } public void finish() { if (DEBUG) { if (DEBUG || debugLogsEnabled()) { Log.i(LOG_TAG, "[CALLED] finish()"); } if (mState != STATE_STARTED && mState != STATE_UPDATED Loading @@ -306,14 +311,14 @@ public final class RemotePrintDocument { * Mark this document as invalid. */ public void invalid() { if (DEBUG) { if (DEBUG || debugLogsEnabled()) { Log.i(LOG_TAG, "[CALLED] invalid()"); } mState = STATE_INVALID; } public void cancel(boolean force) { if (DEBUG) { if (DEBUG || debugLogsEnabled()) { Log.i(LOG_TAG, "[CALLED] cancel(" + force + ")"); } Loading @@ -329,7 +334,7 @@ public final class RemotePrintDocument { } public void destroy() { if (DEBUG) { if (DEBUG || debugLogsEnabled()) { Log.i(LOG_TAG, "[CALLED] destroy()"); } if (mState == STATE_DESTROYED) { Loading Loading @@ -397,21 +402,21 @@ public final class RemotePrintDocument { } private void notifyUpdateCanceled() { if (DEBUG) { if (DEBUG || debugLogsEnabled()) { Log.i(LOG_TAG, "[CALLING] onUpdateCanceled()"); } mUpdateCallbacks.onUpdateCanceled(); } private void notifyUpdateCompleted() { if (DEBUG) { if (DEBUG || debugLogsEnabled()) { Log.i(LOG_TAG, "[CALLING] onUpdateCompleted()"); } mUpdateCallbacks.onUpdateCompleted(mDocumentInfo); } private void notifyUpdateFailed(CharSequence error) { if (DEBUG) { if (DEBUG || debugLogsEnabled()) { Log.i(LOG_TAG, "[CALLING] notifyUpdateFailed()"); } mUpdateCallbacks.onUpdateFailed(error); Loading Loading @@ -477,6 +482,13 @@ public final class RemotePrintDocument { } } private static boolean debugLogsEnabled() { if (!Flags.enablePrintDebugOption()) { return false; } return PRINT_DEBUG_LOG_PROP_ENABLED.equals(SystemProperties.get(PRINT_DEBUG_LOG_PROP)); } private static String stateToString(int state) { switch (state) { case STATE_FINISHED: { Loading Loading @@ -611,7 +623,7 @@ public final class RemotePrintDocument { * and thereby does not need to be canceled anymore. */ protected void removeForceCancel() { if (DEBUG) { if (DEBUG || debugLogsEnabled()) { if (mHandler.hasMessages(MSG_FORCE_CANCEL)) { Log.i(LOG_TAG, "[FORCE CANCEL] Removed"); } Loading Loading @@ -642,7 +654,7 @@ public final class RemotePrintDocument { if (isCanceling()) { if (force) { if (DEBUG) { if (DEBUG || debugLogsEnabled()) { Log.i(LOG_TAG, "[FORCE CANCEL] queued"); } mHandler.sendMessageDelayed( Loading Loading @@ -719,7 +731,7 @@ public final class RemotePrintDocument { private void forceCancel() { if (isCanceling()) { if (DEBUG) { if (DEBUG || debugLogsEnabled()) { Log.i(LOG_TAG, "[FORCE CANCEL] executed"); } failed("Command did not respond to cancellation in " Loading Loading @@ -755,7 +767,7 @@ public final class RemotePrintDocument { running(); try { if (DEBUG) { if (DEBUG || debugLogsEnabled()) { Log.i(LOG_TAG, "[PERFORMING] layout"); } mDocument.changed = false; Loading @@ -772,7 +784,7 @@ public final class RemotePrintDocument { return; } if (DEBUG) { if (DEBUG || debugLogsEnabled()) { Log.i(LOG_TAG, "[CALLBACK] onLayoutStarted"); } Loading @@ -794,7 +806,7 @@ public final class RemotePrintDocument { return; } if (DEBUG) { if (DEBUG || debugLogsEnabled()) { Log.i(LOG_TAG, "[CALLBACK] onLayoutFinished"); } Loading Loading @@ -828,7 +840,7 @@ public final class RemotePrintDocument { return; } if (DEBUG) { if (DEBUG || debugLogsEnabled()) { Log.i(LOG_TAG, "[CALLBACK] onLayoutFailed"); } Loading @@ -848,7 +860,7 @@ public final class RemotePrintDocument { return; } if (DEBUG) { if (DEBUG || debugLogsEnabled()) { Log.i(LOG_TAG, "[CALLBACK] onLayoutCanceled"); } Loading Loading @@ -894,7 +906,7 @@ public final class RemotePrintDocument { // The command might have been force canceled, see // AsyncCommand.AsyncCommandHandler#handleMessage if (isFailed()) { if (DEBUG) { if (DEBUG || debugLogsEnabled()) { Log.i(LOG_TAG, "[CALLBACK] on failed layout command"); } Loading Loading @@ -1055,7 +1067,7 @@ public final class RemotePrintDocument { out = new FileOutputStream(file); // Async call to initiate the other process writing the data. if (DEBUG) { if (DEBUG || debugLogsEnabled()) { Log.i(LOG_TAG, "[PERFORMING] write"); } mAdapter.write(mPages, sink, mRemoteResultCallback, mSequence); Loading Loading @@ -1094,7 +1106,7 @@ public final class RemotePrintDocument { return; } if (DEBUG) { if (DEBUG || debugLogsEnabled()) { Log.i(LOG_TAG, "[CALLBACK] onWriteStarted"); } Loading @@ -1115,7 +1127,7 @@ public final class RemotePrintDocument { return; } if (DEBUG) { if (DEBUG || debugLogsEnabled()) { Log.i(LOG_TAG, "[CALLBACK] onWriteFinished"); } Loading Loading @@ -1146,7 +1158,7 @@ public final class RemotePrintDocument { return; } if (DEBUG) { if (DEBUG || debugLogsEnabled()) { Log.i(LOG_TAG, "[CALLBACK] onWriteFailed"); } Loading @@ -1164,7 +1176,7 @@ public final class RemotePrintDocument { return; } if (DEBUG) { if (DEBUG || debugLogsEnabled()) { Log.i(LOG_TAG, "[CALLBACK] onWriteCanceled"); } Loading Loading @@ -1192,7 +1204,7 @@ public final class RemotePrintDocument { // The command might have been force canceled, see // AsyncCommand.AsyncCommandHandler#handleMessage if (isFailed()) { if (DEBUG) { if (DEBUG || debugLogsEnabled()) { Log.i(LOG_TAG, "[CALLBACK] on failed write command"); } Loading Loading
packages/PrintSpooler/flags/flags.aconfig +7 −0 Original line number Diff line number Diff line Loading @@ -14,3 +14,10 @@ flag { description: "Metrics tracking final print job status, printer discovery, printer capabilities, and major UI actions." bug: "390478410" } flag { name: "enable_print_debug_option" namespace: "printing" description: "Enable extra debug logging by checking a runtime system property." bug: "397418860" }
packages/PrintSpooler/src/com/android/printspooler/model/RemotePrintDocument.java +37 −25 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ import android.os.Looper; import android.os.Message; import android.os.ParcelFileDescriptor; import android.os.RemoteException; import android.os.SystemProperties; import android.print.ILayoutResultCallback; import android.print.IPrintDocumentAdapter; import android.print.IPrintDocumentAdapterObserver; Loading @@ -40,6 +41,7 @@ import android.util.Log; import com.android.internal.util.function.pooled.PooledLambda; import com.android.printspooler.R; import com.android.printspooler.flags.Flags; import com.android.printspooler.util.PageRangeUtils; import libcore.io.IoUtils; Loading @@ -59,6 +61,9 @@ public final class RemotePrintDocument { private static final boolean DEBUG = false; private static final String PRINT_DEBUG_LOG_PROP = "debug.printing.logs.enabled"; private static final String PRINT_DEBUG_LOG_PROP_ENABLED = "true"; private static final long FORCE_CANCEL_TIMEOUT = 1000; // ms private static final int STATE_INITIAL = 0; Loading Loading @@ -184,7 +189,7 @@ public final class RemotePrintDocument { } public void start() { if (DEBUG) { if (DEBUG || debugLogsEnabled()) { Log.i(LOG_TAG, "[CALLED] start()"); } if (mState == STATE_FAILED) { Loading @@ -208,7 +213,7 @@ public final class RemotePrintDocument { public boolean update(PrintAttributes attributes, PageRange[] pages, boolean preview) { boolean willUpdate; if (DEBUG) { if (DEBUG || debugLogsEnabled()) { Log.i(LOG_TAG, "[CALLED] update()"); } Loading Loading @@ -269,7 +274,7 @@ public final class RemotePrintDocument { mState = STATE_UPDATING; } else { willUpdate = false; if (DEBUG) { if (DEBUG || debugLogsEnabled()) { Log.i(LOG_TAG, "[SKIPPING] No update needed"); } } Loading @@ -283,7 +288,7 @@ public final class RemotePrintDocument { } public void finish() { if (DEBUG) { if (DEBUG || debugLogsEnabled()) { Log.i(LOG_TAG, "[CALLED] finish()"); } if (mState != STATE_STARTED && mState != STATE_UPDATED Loading @@ -306,14 +311,14 @@ public final class RemotePrintDocument { * Mark this document as invalid. */ public void invalid() { if (DEBUG) { if (DEBUG || debugLogsEnabled()) { Log.i(LOG_TAG, "[CALLED] invalid()"); } mState = STATE_INVALID; } public void cancel(boolean force) { if (DEBUG) { if (DEBUG || debugLogsEnabled()) { Log.i(LOG_TAG, "[CALLED] cancel(" + force + ")"); } Loading @@ -329,7 +334,7 @@ public final class RemotePrintDocument { } public void destroy() { if (DEBUG) { if (DEBUG || debugLogsEnabled()) { Log.i(LOG_TAG, "[CALLED] destroy()"); } if (mState == STATE_DESTROYED) { Loading Loading @@ -397,21 +402,21 @@ public final class RemotePrintDocument { } private void notifyUpdateCanceled() { if (DEBUG) { if (DEBUG || debugLogsEnabled()) { Log.i(LOG_TAG, "[CALLING] onUpdateCanceled()"); } mUpdateCallbacks.onUpdateCanceled(); } private void notifyUpdateCompleted() { if (DEBUG) { if (DEBUG || debugLogsEnabled()) { Log.i(LOG_TAG, "[CALLING] onUpdateCompleted()"); } mUpdateCallbacks.onUpdateCompleted(mDocumentInfo); } private void notifyUpdateFailed(CharSequence error) { if (DEBUG) { if (DEBUG || debugLogsEnabled()) { Log.i(LOG_TAG, "[CALLING] notifyUpdateFailed()"); } mUpdateCallbacks.onUpdateFailed(error); Loading Loading @@ -477,6 +482,13 @@ public final class RemotePrintDocument { } } private static boolean debugLogsEnabled() { if (!Flags.enablePrintDebugOption()) { return false; } return PRINT_DEBUG_LOG_PROP_ENABLED.equals(SystemProperties.get(PRINT_DEBUG_LOG_PROP)); } private static String stateToString(int state) { switch (state) { case STATE_FINISHED: { Loading Loading @@ -611,7 +623,7 @@ public final class RemotePrintDocument { * and thereby does not need to be canceled anymore. */ protected void removeForceCancel() { if (DEBUG) { if (DEBUG || debugLogsEnabled()) { if (mHandler.hasMessages(MSG_FORCE_CANCEL)) { Log.i(LOG_TAG, "[FORCE CANCEL] Removed"); } Loading Loading @@ -642,7 +654,7 @@ public final class RemotePrintDocument { if (isCanceling()) { if (force) { if (DEBUG) { if (DEBUG || debugLogsEnabled()) { Log.i(LOG_TAG, "[FORCE CANCEL] queued"); } mHandler.sendMessageDelayed( Loading Loading @@ -719,7 +731,7 @@ public final class RemotePrintDocument { private void forceCancel() { if (isCanceling()) { if (DEBUG) { if (DEBUG || debugLogsEnabled()) { Log.i(LOG_TAG, "[FORCE CANCEL] executed"); } failed("Command did not respond to cancellation in " Loading Loading @@ -755,7 +767,7 @@ public final class RemotePrintDocument { running(); try { if (DEBUG) { if (DEBUG || debugLogsEnabled()) { Log.i(LOG_TAG, "[PERFORMING] layout"); } mDocument.changed = false; Loading @@ -772,7 +784,7 @@ public final class RemotePrintDocument { return; } if (DEBUG) { if (DEBUG || debugLogsEnabled()) { Log.i(LOG_TAG, "[CALLBACK] onLayoutStarted"); } Loading @@ -794,7 +806,7 @@ public final class RemotePrintDocument { return; } if (DEBUG) { if (DEBUG || debugLogsEnabled()) { Log.i(LOG_TAG, "[CALLBACK] onLayoutFinished"); } Loading Loading @@ -828,7 +840,7 @@ public final class RemotePrintDocument { return; } if (DEBUG) { if (DEBUG || debugLogsEnabled()) { Log.i(LOG_TAG, "[CALLBACK] onLayoutFailed"); } Loading @@ -848,7 +860,7 @@ public final class RemotePrintDocument { return; } if (DEBUG) { if (DEBUG || debugLogsEnabled()) { Log.i(LOG_TAG, "[CALLBACK] onLayoutCanceled"); } Loading Loading @@ -894,7 +906,7 @@ public final class RemotePrintDocument { // The command might have been force canceled, see // AsyncCommand.AsyncCommandHandler#handleMessage if (isFailed()) { if (DEBUG) { if (DEBUG || debugLogsEnabled()) { Log.i(LOG_TAG, "[CALLBACK] on failed layout command"); } Loading Loading @@ -1055,7 +1067,7 @@ public final class RemotePrintDocument { out = new FileOutputStream(file); // Async call to initiate the other process writing the data. if (DEBUG) { if (DEBUG || debugLogsEnabled()) { Log.i(LOG_TAG, "[PERFORMING] write"); } mAdapter.write(mPages, sink, mRemoteResultCallback, mSequence); Loading Loading @@ -1094,7 +1106,7 @@ public final class RemotePrintDocument { return; } if (DEBUG) { if (DEBUG || debugLogsEnabled()) { Log.i(LOG_TAG, "[CALLBACK] onWriteStarted"); } Loading @@ -1115,7 +1127,7 @@ public final class RemotePrintDocument { return; } if (DEBUG) { if (DEBUG || debugLogsEnabled()) { Log.i(LOG_TAG, "[CALLBACK] onWriteFinished"); } Loading Loading @@ -1146,7 +1158,7 @@ public final class RemotePrintDocument { return; } if (DEBUG) { if (DEBUG || debugLogsEnabled()) { Log.i(LOG_TAG, "[CALLBACK] onWriteFailed"); } Loading @@ -1164,7 +1176,7 @@ public final class RemotePrintDocument { return; } if (DEBUG) { if (DEBUG || debugLogsEnabled()) { Log.i(LOG_TAG, "[CALLBACK] onWriteCanceled"); } Loading Loading @@ -1192,7 +1204,7 @@ public final class RemotePrintDocument { // The command might have been force canceled, see // AsyncCommand.AsyncCommandHandler#handleMessage if (isFailed()) { if (DEBUG) { if (DEBUG || debugLogsEnabled()) { Log.i(LOG_TAG, "[CALLBACK] on failed write command"); } Loading