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

Commit 33d6b13d authored by Aaron Massey's avatar Aaron Massey Committed by Android (Google) Code Review
Browse files

Merge "stats: Add PrintJob event" into main

parents fbb9bf7c 36f65aa0
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -78,6 +78,7 @@ import java.lang.annotation.RetentionPolicy;
 */
public final class PrintDocumentInfo implements Parcelable {

    // LINT.IfChange
    /**
     * Constant for unknown page count.
     */
@@ -119,6 +120,8 @@ public final class PrintDocumentInfo implements Parcelable {
     * </p>
     */
    public static final int CONTENT_TYPE_PHOTO = 1;
    // Update BuiltInPrintService stats logger too.
    // LINT.ThenChange(/packages/PrintSpooler/src/com/android/printspooler/stats/StatsAsyncLogger.kt)

    private @NonNull String mName;
    private @IntRange(from = -1) int mPageCount;
+54 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.app.Service;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager.NameNotFoundException;
import android.graphics.drawable.Icon;
import android.os.AsyncTask;
import android.os.Binder;
@@ -554,6 +555,58 @@ public final class PrintSpoolerService extends Service {
        mNotificationController.onUpdateNotifications(mPrintJobs);
    }

    // Stats Logging
    private void logPrintJobFinalState(PrinterId printerId, PrintJobInfo printJob) {
        if (!Flags.printingTelemetry()) {
            return;
        }
        final ComponentName service = (printerId == null) ? null : printerId.getServiceName();
        if (service == null) {
            // We don't know what to do without an identifiable service.
            Log.e(LOG_TAG, "Failed to get service ComponentName");
            return;
        }
        int serviceUId = 0;
        try {
            serviceUId =
                getPackageManager().getApplicationInfo(service.getPackageName(), 0).uid;
        } catch (NameNotFoundException e) {
            Log.e(LOG_TAG, String.format("Failed to get uid for service=%s",
                                         service.flattenToString()), e);
            // We don't know what to do without an identifiable service.
            return;
        }
        final boolean savedPdf = service.getPackageName().startsWith(this.getPackageName());
        final int state = printJob.getState();

        // The following values are all optional.

        final PrintAttributes attributes = printJob.getAttributes();
        final PrintAttributes.MediaSize size = (attributes == null)
                ? null : attributes.getMediaSize();
        final PrintAttributes.Resolution resolution = (attributes == null)
                ? null : attributes.getResolution();
        final int colorMode = (attributes == null) ? 0 : attributes.getColorMode();
        final int duplexMode = (attributes == null) ? 0 : attributes.getDuplexMode();

        final PrintDocumentInfo docInfo = printJob.getDocumentInfo();
        final int pageCount = (docInfo == null)
                ? PrintDocumentInfo.PAGE_COUNT_UNKNOWN : docInfo.getPageCount();
        final int docType = (docInfo == null)
                ? PrintDocumentInfo.CONTENT_TYPE_UNKNOWN : docInfo.getContentType();

        StatsAsyncLogger.INSTANCE.PrintJob(serviceUId,
                                           state,
                                           colorMode,
                                           size,
                                           resolution,
                                           duplexMode,
                                           docType,
                                           savedPdf,
                                           pageCount);

    }

    public boolean setPrintJobState(PrintJobId printJobId, int state, String error) {
        boolean success = false;

@@ -592,6 +645,7 @@ public final class PrintSpoolerService extends Service {
                    case PrintJobInfo.STATE_FAILED: {
                        PrinterId printerId = printJob.getPrinterId();
                        if (printerId != null) {
                            logPrintJobFinalState(printerId, printJob);
                            ComponentName service = printerId.getServiceName();
                            if (!hasActivePrintJobsForServiceLocked(service)) {
                                sendOnAllPrintJobsForServiceHandled(service);