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

Commit b40e3b04 authored by Kweku Adams's avatar Kweku Adams
Browse files

Fix proxied job logging attribution.

The statsd logging was incorrectly logging for only the source app.
Including the calling app will enable better metrics and debugging.

Bug: 138239687
Test: statsd_testdrive 8 while running CtsSyncManagerTestsCases
Test: statsd_testdrive 150 while running CtsSyncManagerTestsCases
Change-Id: I9ba3097135b1f11368df800b043d730d780f3a33
parent 96fe7f89
Loading
Loading
Loading
Loading
+20 −4
Original line number Diff line number Diff line
@@ -1762,8 +1762,16 @@ public class JobSchedulerService extends com.android.server.SystemService
                sEnqueuedJwiHighWaterMarkLogger.logSampleWithUid(uId, jobStatus.getWorkCount());
            }

            FrameworkStatsLog.write_non_chained(FrameworkStatsLog.SCHEDULED_JOB_STATE_CHANGED,
                    uId, null, jobStatus.getBatteryName(),
            final int sourceUid = uId;
            FrameworkStatsLog.write(FrameworkStatsLog.SCHEDULED_JOB_STATE_CHANGED,
                    jobStatus.isProxyJob()
                            ? new int[]{sourceUid, jobStatus.getUid()} : new int[]{sourceUid},
                    // Given that the source tag is set by the calling app, it should be connected
                    // to the calling app in the attribution for a proxied job.
                    jobStatus.isProxyJob()
                            ? new String[]{null, jobStatus.getSourceTag()}
                            : new String[]{jobStatus.getSourceTag()},
                    jobStatus.getBatteryName(),
                    FrameworkStatsLog.SCHEDULED_JOB_STATE_CHANGED__STATE__SCHEDULED,
                    JobProtoEnums.INTERNAL_STOP_REASON_UNKNOWN, jobStatus.getStandbyBucket(),
                    jobStatus.getLoggingJobId(),
@@ -2191,8 +2199,16 @@ public class JobSchedulerService extends com.android.server.SystemService
                cancelled, reason, internalReasonCode, debugReason);
        // If the job was running, the JobServiceContext should log with state FINISHED.
        if (!wasRunning) {
            FrameworkStatsLog.write_non_chained(FrameworkStatsLog.SCHEDULED_JOB_STATE_CHANGED,
                    cancelled.getSourceUid(), null, cancelled.getBatteryName(),
            final int sourceUid = cancelled.getSourceUid();
            FrameworkStatsLog.write(FrameworkStatsLog.SCHEDULED_JOB_STATE_CHANGED,
                    cancelled.isProxyJob()
                            ? new int[]{sourceUid, cancelled.getUid()} : new int[]{sourceUid},
                    // Given that the source tag is set by the calling app, it should be connected
                    // to the calling app in the attribution for a proxied job.
                    cancelled.isProxyJob()
                            ? new String[]{null, cancelled.getSourceTag()}
                            : new String[]{cancelled.getSourceTag()},
                    cancelled.getBatteryName(),
                    FrameworkStatsLog.SCHEDULED_JOB_STATE_CHANGED__STATE__CANCELLED,
                    internalReasonCode, cancelled.getStandbyBucket(),
                    cancelled.getLoggingJobId(),
+19 −4
Original line number Diff line number Diff line
@@ -470,8 +470,15 @@ public final class JobServiceContext implements ServiceConnection {
                return false;
            }
            mJobPackageTracker.noteActive(job);
            FrameworkStatsLog.write_non_chained(FrameworkStatsLog.SCHEDULED_JOB_STATE_CHANGED,
                    job.getSourceUid(), null, job.getBatteryName(),
            final int sourceUid = job.getSourceUid();
            FrameworkStatsLog.write(FrameworkStatsLog.SCHEDULED_JOB_STATE_CHANGED,
                    job.isProxyJob() ? new int[]{sourceUid, job.getUid()} : new int[]{sourceUid},
                    // Given that the source tag is set by the calling app, it should be connected
                    // to the calling app in the attribution for a proxied job.
                    job.isProxyJob()
                            ? new String[]{null, job.getSourceTag()}
                            : new String[]{job.getSourceTag()},
                    job.getBatteryName(),
                    FrameworkStatsLog.SCHEDULED_JOB_STATE_CHANGED__STATE__STARTED,
                    JobProtoEnums.INTERNAL_STOP_REASON_UNKNOWN,
                    job.getStandbyBucket(),
@@ -1531,8 +1538,16 @@ public final class JobServiceContext implements ServiceConnection {
        }
        mJobPackageTracker.noteInactive(completedJob,
                loggingInternalStopReason, loggingDebugReason);
        FrameworkStatsLog.write_non_chained(FrameworkStatsLog.SCHEDULED_JOB_STATE_CHANGED,
                completedJob.getSourceUid(), null, completedJob.getBatteryName(),
        final int sourceUid = completedJob.getSourceUid();
        FrameworkStatsLog.write(FrameworkStatsLog.SCHEDULED_JOB_STATE_CHANGED,
                completedJob.isProxyJob()
                        ? new int[]{sourceUid, completedJob.getUid()} : new int[]{sourceUid},
                // Given that the source tag is set by the calling app, it should be connected
                // to the calling app in the attribution for a proxied job.
                completedJob.isProxyJob()
                        ? new String[]{null, completedJob.getSourceTag()}
                        : new String[]{completedJob.getSourceTag()},
                completedJob.getBatteryName(),
                FrameworkStatsLog.SCHEDULED_JOB_STATE_CHANGED__STATE__FINISHED,
                loggingInternalStopReason, completedJob.getStandbyBucket(),
                completedJob.getLoggingJobId(),
+23 −2
Original line number Diff line number Diff line
@@ -255,6 +255,9 @@ public final class JobStatus {

    final String tag;

    /** Whether this job was scheduled by one app on behalf of another. */
    final boolean mIsProxyJob;

    private GrantedUriPermissions uriPerms;
    private boolean prepared;

@@ -626,6 +629,9 @@ public final class JobStatus {
                : bnNamespace + job.getService().flattenToShortString();
        this.tag = "*job*/" + this.batteryName + "#" + job.getId();

        final String componentPackage = job.getService().getPackageName();
        mIsProxyJob = !this.sourcePackageName.equals(componentPackage);

        this.earliestRunTimeElapsedMillis = earliestRunTimeElapsedMillis;
        this.latestRunTimeElapsedMillis = latestRunTimeElapsedMillis;
        this.mOriginalLatestRunTimeElapsedMillis = latestRunTimeElapsedMillis;
@@ -1048,6 +1054,11 @@ public final class JobStatus {
        return mLoggingJobId;
    }

    /** Returns whether this job was scheduled by one app on behalf of another. */
    public boolean isProxyJob() {
        return mIsProxyJob;
    }

    public void printUniqueId(PrintWriter pw) {
        if (mNamespace != null) {
            pw.print(mNamespace);
@@ -1292,6 +1303,12 @@ public final class JobStatus {
        return mNamespaceHash;
    }

    /**
     * Returns the tag passed by the calling app to describe the source app work. This is primarily
     * only valid if {@link #isProxyJob()} returns true, but may be non-null if an app uses
     * {@link JobScheduler#scheduleAsPackage(JobInfo, String, int, String)} for itself.
     */
    @Nullable
    public String getSourceTag() {
        return sourceTag;
    }
@@ -1871,9 +1888,13 @@ public final class JobStatus {
        mReadyDynamicSatisfied = mDynamicConstraints != 0
                && mDynamicConstraints == (satisfiedConstraints & mDynamicConstraints);
        if (STATS_LOG_ENABLED && (STATSD_CONSTRAINTS_TO_LOG & constraint) != 0) {
            FrameworkStatsLog.write_non_chained(
            FrameworkStatsLog.write(
                    FrameworkStatsLog.SCHEDULED_JOB_CONSTRAINT_CHANGED,
                    sourceUid, null, getBatteryName(), getProtoConstraint(constraint),
                    isProxyJob() ? new int[]{sourceUid, getUid()} : new int[]{sourceUid},
                    // Given that the source tag is set by the calling app, it should be connected
                    // to the calling app in the attribution for a proxied job.
                    isProxyJob() ? new String[]{null, sourceTag} : new String[]{sourceTag},
                    getBatteryName(), getProtoConstraint(constraint),
                    state ? FrameworkStatsLog.SCHEDULED_JOB_CONSTRAINT_CHANGED__STATE__SATISFIED
                            : FrameworkStatsLog
                                    .SCHEDULED_JOB_CONSTRAINT_CHANGED__STATE__UNSATISFIED);