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

Commit c16d0fa1 authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 10289553 from 5f433062 to udc-qpr1-release

Change-Id: I2c8efcb78445807f75ec378a9b7043c67fb43419
parents c64fb864 5f433062
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -59,6 +59,10 @@ public interface JobSchedulerInternal {
     */
    void reportAppUsage(String packageName, int userId);

    /** @return {@code true} if the app is considered buggy from JobScheduler's perspective. */
    boolean isAppConsideredBuggy(int callingUserId, @NonNull String callingPackageName,
            int timeoutBlameUserId, @NonNull String timeoutBlamePackageName);

    /**
     * @return {@code true} if the given notification is associated with any user-initiated jobs.
     */
+5 −5
Original line number Diff line number Diff line
@@ -123,21 +123,21 @@ class JobNotificationCoordinator {
        if (oldDetails == null) {
            if (jobStatus.startedAsUserInitiatedJob) {
                Counter.logIncrementWithUid(
                        "job_scheduler.value_cntr_w_uid_initial_setNotification_call_required",
                        "job_scheduler.value_cntr_w_uid_initial_set_notification_call_required",
                        jobStatus.getUid());
            } else {
                Counter.logIncrementWithUid(
                        "job_scheduler.value_cntr_w_uid_initial_setNotification_call_optional",
                        "job_scheduler.value_cntr_w_uid_initial_set_notification_call_optional",
                        jobStatus.getUid());
            }
        } else {
            if (jobStatus.startedAsUserInitiatedJob) {
                Counter.logIncrementWithUid(
                        "job_scheduler.value_cntr_w_uid_subsequent_setNotification_call_required",
                        "job_scheduler.value_cntr_w_uid_subsequent_set_notification_call_required",
                        jobStatus.getUid());
            } else {
                Counter.logIncrementWithUid(
                        "job_scheduler.value_cntr_w_uid_subsequent_setNotification_call_optional",
                        "job_scheduler.value_cntr_w_uid_subsequent_set_notification_call_optional",
                        jobStatus.getUid());
            }
            if (oldDetails.notificationId != notificationId) {
@@ -145,7 +145,7 @@ class JobNotificationCoordinator {
                removeNotificationAssociation(hostingContext, JobParameters.STOP_REASON_UNDEFINED,
                        jobStatus);
                Counter.logIncrementWithUid(
                        "job_scheduler.value_cntr_w_uid_setNotification_changed_notification_ids",
                        "job_scheduler.value_cntr_w_uid_set_notification_changed_notification_ids",
                        jobStatus.getUid());
            }
        }
+299 −18

File changed.

Preview size limit exceeded, changes collapsed.

+3 −3
Original line number Diff line number Diff line
@@ -1331,7 +1331,7 @@ public final class JobServiceContext implements ServiceConnection {
                // FINISHED/NO-RETRY.
                onSlowAppResponseLocked(/* reschedule */ false, /* updateStopReasons */ true,
                        /* texCounterMetricId */
                        "job_scheduler.value_cntr_w_uid_slow_app_response_onStartJob",
                        "job_scheduler.value_cntr_w_uid_slow_app_response_on_start_job",
                        /* debugReason */ "timed out while starting",
                        /* anrMessage */ "No response to onStartJob",
                        CompatChanges.isChangeEnabled(ANR_PRE_UDC_APIS_ON_SLOW_RESPONSES,
@@ -1343,7 +1343,7 @@ public final class JobServiceContext implements ServiceConnection {
                // other reason.
                onSlowAppResponseLocked(/* reschedule */ true, /* updateStopReasons */ false,
                        /* texCounterMetricId */
                        "job_scheduler.value_cntr_w_uid_slow_app_response_onStopJob",
                        "job_scheduler.value_cntr_w_uid_slow_app_response_on_stop_job",
                        /* debugReason */ "timed out while stopping",
                        /* anrMessage */ "No response to onStopJob",
                        CompatChanges.isChangeEnabled(ANR_PRE_UDC_APIS_ON_SLOW_RESPONSES,
@@ -1400,7 +1400,7 @@ public final class JobServiceContext implements ServiceConnection {
                } else if (mAwaitingNotification) {
                    onSlowAppResponseLocked(/* reschedule */ true, /* updateStopReasons */ true,
                            /* texCounterMetricId */
                            "job_scheduler.value_cntr_w_uid_slow_app_response_setNotification",
                            "job_scheduler.value_cntr_w_uid_slow_app_response_set_notification",
                            /* debugReason */ "timed out while stopping",
                            /* anrMessage */ "required notification not provided",
                            /* triggerAnr */ true);
+72 −3
Original line number Diff line number Diff line
@@ -1088,13 +1088,77 @@ public final class JobStatus {
        return UserHandle.getUserId(callingUid);
    }

    private boolean shouldBlameSourceForTimeout() {
        // If the system scheduled the job on behalf of an app, assume the app is the one
        // doing the work and blame the app directly. This is the case with things like
        // syncs via SyncManager.
        // If the system didn't schedule the job on behalf of an app, then
        // blame the app doing the actual work. Proxied jobs are a little tricky.
        // Proxied jobs scheduled by built-in system apps like DownloadManager may be fine
        // and we could consider exempting those jobs. For example, in DownloadManager's
        // case, all it does is download files and the code is vetted. A timeout likely
        // means it's downloading a large file, which isn't an error. For now, DownloadManager
        // is an exempted app, so this shouldn't be an issue.
        // However, proxied jobs coming from other system apps (such as those that can
        // be updated separately from an OTA) may not be fine and we would want to apply
        // this policy to those jobs/apps.
        // TODO(284512488): consider exempting DownloadManager or other system apps
        return UserHandle.isCore(callingUid);
    }

    /**
     * Returns the package name that should most likely be blamed for the job timing out.
     */
    public String getTimeoutBlamePackageName() {
        if (shouldBlameSourceForTimeout()) {
            return sourcePackageName;
        }
        return getServiceComponent().getPackageName();
    }

    /**
     * Returns the UID that should most likely be blamed for the job timing out.
     */
    public int getTimeoutBlameUid() {
        if (shouldBlameSourceForTimeout()) {
            return sourceUid;
        }
        return callingUid;
    }

    /**
     * Returns the userId that should most likely be blamed for the job timing out.
     */
    public int getTimeoutBlameUserId() {
        if (shouldBlameSourceForTimeout()) {
            return sourceUserId;
        }
        return UserHandle.getUserId(callingUid);
    }

    /**
     * Returns an appropriate standby bucket for the job, taking into account any standby
     * exemptions.
     */
    public int getEffectiveStandbyBucket() {
        final JobSchedulerInternal jsi = LocalServices.getService(JobSchedulerInternal.class);
        final boolean isBuggy = jsi.isAppConsideredBuggy(
                getUserId(), getServiceComponent().getPackageName(),
                getTimeoutBlameUserId(), getTimeoutBlamePackageName());

        final int actualBucket = getStandbyBucket();
        if (actualBucket == EXEMPTED_INDEX) {
            // EXEMPTED apps always have their jobs exempted, even if they're buggy, because the
            // user has explicitly told the system to avoid restricting the app for power reasons.
            if (isBuggy) {
                final String pkg;
                if (getServiceComponent().getPackageName().equals(sourcePackageName)) {
                    pkg = sourcePackageName;
                } else {
                    pkg = getServiceComponent().getPackageName() + "/" + sourcePackageName;
                }
                Slog.w(TAG, "Exempted app " + pkg + " considered buggy");
            }
            return actualBucket;
        }
        if (uidActive || getJob().isExemptedFromAppStandby()) {
@@ -1102,13 +1166,18 @@ public final class JobStatus {
            // like other ACTIVE apps.
            return ACTIVE_INDEX;
        }
        // If the app is considered buggy, but hasn't yet been put in the RESTRICTED bucket
        // (potentially because it's used frequently by the user), limit its effective bucket
        // so that it doesn't get to run as much as a normal ACTIVE app.
        final int highestBucket = isBuggy ? WORKING_INDEX : ACTIVE_INDEX;
        if (actualBucket != RESTRICTED_INDEX && actualBucket != NEVER_INDEX
                && mHasMediaBackupExemption) {
            // Cap it at WORKING_INDEX as media back up jobs are important to the user, and the
            // Treat it as if it's at least WORKING_INDEX since media backup jobs are important
            // to the user, and the
            // source package may not have been used directly in a while.
            return Math.min(WORKING_INDEX, actualBucket);
            return Math.max(highestBucket, Math.min(WORKING_INDEX, actualBucket));
        }
        return actualBucket;
        return Math.max(highestBucket, actualBucket);
    }

    /** Returns the real standby bucket of the job. */
Loading