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

Commit da4db580 authored by Makoto Onuki's avatar Makoto Onuki Committed by android-build-merger
Browse files

Merge "Tweak exemption for sync requests made by FG apps" into pi-dev am: 621fd20f

am: d8cf91c5

Change-Id: Icac177c8d404ce20d5e894d85df2b72a001d6d9a
parents 17b5748a d8cf91c5
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -211,10 +211,10 @@ public class RequestSync {
                mExtras.putBoolean(key, Boolean.valueOf(value));

            } else if (opt.equals("-f") || opt.equals("--foreground")) {
                mExemptionFlag = ContentResolver.SYNC_EXEMPTION_ACTIVE;
                mExemptionFlag = ContentResolver.SYNC_EXEMPTION_PROMOTE_BUCKET;

            } else if (opt.equals("-F") || opt.equals("--top")) {
                mExemptionFlag = ContentResolver.SYNC_EXEMPTION_ACTIVE_WITH_TEMP;
                mExemptionFlag = ContentResolver.SYNC_EXEMPTION_PROMOTE_BUCKET_WITH_TEMP;

            } else {
                System.err.println("Error: Unknown option: " + opt);
+14 −4
Original line number Diff line number Diff line
@@ -184,7 +184,11 @@ public final class UsageStatsManager {
    /** @hide */
    public static final int REASON_SUB_USAGE_SLICE_PINNED_PRIV  = 0x000A;
    /** @hide */
    public static final int REASON_SUB_USAGE_EXEMPTED_SYNC_START = 0x000B;
    public static final int REASON_SUB_USAGE_EXEMPTED_SYNC_SCHEDULED_NON_DOZE = 0x000B;
    /** @hide */
    public static final int REASON_SUB_USAGE_EXEMPTED_SYNC_SCHEDULED_DOZE = 0x000C;
    /** @hide */
    public static final int REASON_SUB_USAGE_EXEMPTED_SYNC_START = 0x000D;

    /** @hide */
    public static final int REASON_SUB_PREDICTED_RESTORED       = 0x0001;
@@ -669,13 +673,19 @@ public final class UsageStatsManager {
                        sb.append("-sa");
                        break;
                    case REASON_SUB_USAGE_SLICE_PINNED:
                        sb.append("slp");
                        sb.append("-lp");
                        break;
                    case REASON_SUB_USAGE_SLICE_PINNED_PRIV:
                        sb.append("slpp");
                        sb.append("-lv");
                        break;
                    case REASON_SUB_USAGE_EXEMPTED_SYNC_SCHEDULED_NON_DOZE:
                        sb.append("-en");
                        break;
                    case REASON_SUB_USAGE_EXEMPTED_SYNC_SCHEDULED_DOZE:
                        sb.append("-ed");
                        break;
                    case REASON_SUB_USAGE_EXEMPTED_SYNC_START:
                        sb.append("es");
                        sb.append("-es");
                        break;
                }
                break;
+9 −1
Original line number Diff line number Diff line
@@ -245,7 +245,15 @@ public abstract class UsageStatsManagerInternal {
            int numDeferredJobs, long timeSinceLastJobRun);

    /**
     * Report a sync that was scheduled by an active app is about to be executed.
     * Report a sync is scheduled by a foreground app.
     *
     * @param packageName name of the package that owns the sync adapter.
     * @param userId which user the app is associated with
     */
    public abstract void reportExemptedSyncScheduled(String packageName, @UserIdInt int userId);

    /**
     * Report a sync that was scheduled by a foreground app is about to be executed.
     *
     * @param packageName name of the package that owns the sync adapter.
     * @param userId which user the app is associated with
+18 −9
Original line number Diff line number Diff line
@@ -520,27 +520,36 @@ public abstract class ContentResolver {
    public static final int SYNC_EXEMPTION_NONE = 0;

    /**
     * When executing a sync with this exemption, we'll put the target app in the ACTIVE bucket
     * for 10 minutes. This will allow the sync adapter to schedule/run further syncs and jobs.
     * Exemption given to a sync request made by a foreground app (including
     * PROCESS_STATE_IMPORTANT_FOREGROUND).
     *
     * At the schedule time, we promote the sync adapter app for a higher bucket:
     * - If the device is not dozing (so the sync will start right away)
     *   promote to ACTIVE for 1 hour.
     * - If the device is dozing (so the sync *won't* start right away),
     * promote to WORKING_SET for 4 hours, so it'll get a higher chance to be started once the
     * device comes out of doze.
     * - When the sync actually starts, we promote the sync adapter app to ACTIVE for 10 minutes,
     * so it can schedule and start more syncs without getting throttled, even when the first
     * operation was canceled and now we're retrying.
     *
     *
     * Note this will still *not* let RARE apps to run syncs, because they still won't get network
     * connection.
     * @hide
     */
    public static final int SYNC_EXEMPTION_ACTIVE = 1;
    public static final int SYNC_EXEMPTION_PROMOTE_BUCKET = 1;

    /**
     * In addition to {@link #SYNC_EXEMPTION_ACTIVE}, we put the sync adapter app in the
     * In addition to {@link #SYNC_EXEMPTION_PROMOTE_BUCKET}, we put the sync adapter app in the
     * temp whitelist for 10 minutes, so that even RARE apps can run syncs right away.
     * @hide
     */
    public static final int SYNC_EXEMPTION_ACTIVE_WITH_TEMP = 2;
    public static final int SYNC_EXEMPTION_PROMOTE_BUCKET_WITH_TEMP = 2;

    /** @hide */
    @IntDef(flag = false, prefix = { "SYNC_EXEMPTION_" }, value = {
            SYNC_EXEMPTION_NONE,
            SYNC_EXEMPTION_ACTIVE,
            SYNC_EXEMPTION_ACTIVE_WITH_TEMP,
            SYNC_EXEMPTION_PROMOTE_BUCKET,
            SYNC_EXEMPTION_PROMOTE_BUCKET_WITH_TEMP,
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface SyncExemption {}
+2 −2
Original line number Diff line number Diff line
@@ -1310,10 +1310,10 @@ public final class ContentService extends IContentService.Stub {
                : ActivityManager.PROCESS_STATE_NONEXISTENT;

        if (procState <= ActivityManager.PROCESS_STATE_TOP) {
            return ContentResolver.SYNC_EXEMPTION_ACTIVE_WITH_TEMP;
            return ContentResolver.SYNC_EXEMPTION_PROMOTE_BUCKET_WITH_TEMP;
        }
        if (procState <= ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND) {
            return ContentResolver.SYNC_EXEMPTION_ACTIVE;
            return ContentResolver.SYNC_EXEMPTION_PROMOTE_BUCKET;
        }
        return ContentResolver.SYNC_EXEMPTION_NONE;
    }
Loading