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

Commit c4681d3b authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "PrintSpooler: Add optional debuglogs to RemotePrintDocument" into main

parents 33268e6a cc6268dc
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -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"
}
+37 −25
Original line number Diff line number Diff line
@@ -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;
@@ -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;
@@ -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;
@@ -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) {
@@ -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()");
        }

@@ -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");
            }
        }
@@ -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
@@ -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 + ")");
        }

@@ -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) {
@@ -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);
@@ -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: {
@@ -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");
                }
@@ -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(
@@ -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 "
@@ -755,7 +767,7 @@ public final class RemotePrintDocument {
            running();

            try {
                if (DEBUG) {
                if (DEBUG || debugLogsEnabled()) {
                    Log.i(LOG_TAG, "[PERFORMING] layout");
                }
                mDocument.changed = false;
@@ -772,7 +784,7 @@ public final class RemotePrintDocument {
                return;
            }

            if (DEBUG) {
            if (DEBUG || debugLogsEnabled()) {
                Log.i(LOG_TAG, "[CALLBACK] onLayoutStarted");
            }

@@ -794,7 +806,7 @@ public final class RemotePrintDocument {
                return;
            }

            if (DEBUG) {
            if (DEBUG || debugLogsEnabled()) {
                Log.i(LOG_TAG, "[CALLBACK] onLayoutFinished");
            }

@@ -828,7 +840,7 @@ public final class RemotePrintDocument {
                return;
            }

            if (DEBUG) {
            if (DEBUG || debugLogsEnabled()) {
                Log.i(LOG_TAG, "[CALLBACK] onLayoutFailed");
            }

@@ -848,7 +860,7 @@ public final class RemotePrintDocument {
                return;
            }

            if (DEBUG) {
            if (DEBUG || debugLogsEnabled()) {
                Log.i(LOG_TAG, "[CALLBACK] onLayoutCanceled");
            }

@@ -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");
                    }

@@ -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);
@@ -1094,7 +1106,7 @@ public final class RemotePrintDocument {
                return;
            }

            if (DEBUG) {
            if (DEBUG || debugLogsEnabled()) {
                Log.i(LOG_TAG, "[CALLBACK] onWriteStarted");
            }

@@ -1115,7 +1127,7 @@ public final class RemotePrintDocument {
                return;
            }

            if (DEBUG) {
            if (DEBUG || debugLogsEnabled()) {
                Log.i(LOG_TAG, "[CALLBACK] onWriteFinished");
            }

@@ -1146,7 +1158,7 @@ public final class RemotePrintDocument {
                return;
            }

            if (DEBUG) {
            if (DEBUG || debugLogsEnabled()) {
                Log.i(LOG_TAG, "[CALLBACK] onWriteFailed");
            }

@@ -1164,7 +1176,7 @@ public final class RemotePrintDocument {
                return;
            }

            if (DEBUG) {
            if (DEBUG || debugLogsEnabled()) {
                Log.i(LOG_TAG, "[CALLBACK] onWriteCanceled");
            }

@@ -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");
                    }