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

Commit 95071adc authored by Kweku Adams's avatar Kweku Adams
Browse files

Turn off prefetch constraint relaxation on battery.

Only let prefetch jobs use the opportunistic quota when the device
is on charger to reduce excess battery drain. The opportunistic quota
usage behavior is optional and not required for prefetch jobs, so we can
disable it without impacting app or developer expectations.

Bug: 295046507
Bug: 299329948
Test: atest FrameworksMockingServicesTests:ConnectivityControllerTest
Test: atest FrameworksMockingServicesTests:PrefetchControllerTest
Change-Id: Idc137279fea1100f53ecf20279153fe92fdb5617
parent 925853a9
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -13,6 +13,10 @@ java_library {
    name: "service-jobscheduler",
    installable: true,

    defaults: [
        "service-jobscheduler-aconfig-libraries",
    ],

    srcs: [
        "java/**/*.java",
        ":framework-jobscheduler-shared-srcs",
+29 −0
Original line number Diff line number Diff line
// JobScheduler
aconfig_declarations {
    name: "service-job.flags-aconfig",
    package: "com.android.server.job",
    srcs: [
        "job.aconfig",
    ],
}

java_aconfig_library {
    name: "service-jobscheduler-job.flags-aconfig-java",
    aconfig_declarations: "service-job.flags-aconfig",
    defaults: ["framework-minus-apex-aconfig-java-defaults"],
    visibility: ["//frameworks/base:__subpackages__"],
}

service_jobscheduler_aconfig_srcjars = [
    ":service-jobscheduler-job.flags-aconfig-java{.generated_srcjars}",
]

// Aconfig declarations and libraries for the core framework
java_defaults {
    name: "service-jobscheduler-aconfig-libraries",
    // Add java_aconfig_libraries to here to add them to the core framework
    srcs: service_jobscheduler_aconfig_srcjars,
    // Add aconfig-annotations-lib as a dependency for the optimization
    libs: ["aconfig-annotations-lib"],
    visibility: ["//frameworks/base:__subpackages__"],
}
+8 −0
Original line number Diff line number Diff line
package: "com.android.server.job"

flag {
    name: "relax_prefetch_connectivity_constraint_only_on_charger"
    namespace: "backstagepower"
    description: "Only relax a prefetch job's connectivity constraint when the device is charging"
    bug: "299329948"
}
 No newline at end of file
+15 −0
Original line number Diff line number Diff line
@@ -22,6 +22,8 @@ import static android.net.NetworkCapabilities.NET_CAPABILITY_TEMPORARILY_NOT_MET

import static com.android.server.job.JobSchedulerService.RESTRICTED_INDEX;
import static com.android.server.job.JobSchedulerService.sElapsedRealtimeClock;
import static com.android.server.job.Flags.FLAG_RELAX_PREFETCH_CONNECTIVITY_CONSTRAINT_ONLY_ON_CHARGER;
import static com.android.server.job.Flags.relaxPrefetchConnectivityConstraintOnlyOnCharger;

import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -929,6 +931,11 @@ public final class ConnectivityController extends RestrictingController implemen
            // Need to at least know the estimated download bytes for a prefetch job.
            return false;
        }
        if (relaxPrefetchConnectivityConstraintOnlyOnCharger()) {
            if (!mService.isBatteryCharging()) {
                return false;
            }
        }

        // See if we match after relaxing any unmetered request
        final NetworkCapabilities.Builder builder =
@@ -1735,6 +1742,14 @@ public final class ConnectivityController extends RestrictingController implemen
            Predicate<JobStatus> predicate) {
        final long nowElapsed = sElapsedRealtimeClock.millis();

        pw.println("Aconfig flags:");
        pw.increaseIndent();
        pw.print(FLAG_RELAX_PREFETCH_CONNECTIVITY_CONSTRAINT_ONLY_ON_CHARGER,
                relaxPrefetchConnectivityConstraintOnlyOnCharger());
        pw.println();
        pw.decreaseIndent();
        pw.println();

        if (mRequestedWhitelistJobs.size() > 0) {
            pw.print("Requested standby exceptions:");
            for (int i = 0; i < mRequestedWhitelistJobs.size(); i++) {
+1 −0
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ android_test {
        "androidx.test.espresso.core",
        "androidx.test.espresso.contrib",
        "androidx.test.ext.truth",
        "flag-junit",
        "frameworks-base-testutils",
        "hamcrest-library",
        "kotlin-test",
Loading