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

Commit 88e45dcd authored by Daniel Nishi's avatar Daniel Nishi
Browse files

Add a flag to enable/disable the diskstats logging service.

Bug: 34704947
Test: Service tests
Change-Id: I224cfb38682f1fd2bd33750b664bd3aacdaa4bde
parent c399e4d9
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -9395,6 +9395,12 @@ public final class Settings {
         * @hide
         */
        public static final String WARNING_TEMPERATURE = "warning_temperature";

        /**
         * Whether the diskstats logging task is enabled/disabled.
         * @hide
         */
        public static final String ENABLE_DISKSTATS_LOGGING = "enable_diskstats_logging";
    }

    /**
+9 −1
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.app.job.JobParameters;
import android.app.job.JobScheduler;
import android.app.job.JobService;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.content.pm.PackageStats;
import android.os.AsyncTask;
@@ -28,6 +29,7 @@ import android.os.BatteryManager;
import android.os.Environment;
import android.os.Environment.UserEnvironment;
import android.os.UserHandle;
import android.provider.Settings;
import android.util.Log;

import com.android.internal.annotations.VisibleForTesting;
@@ -54,7 +56,7 @@ public class DiskStatsLoggingService extends JobService {
    public boolean onStartJob(JobParameters params) {
        // We need to check the preconditions again because they may not be enforced for
        // subsequent runs.
        if (!isCharging(this)) {
        if (!isCharging(this) || !isDumpsysTaskEnabled(getContentResolver())) {
            jobFinished(params, true);
            return false;
        }
@@ -104,6 +106,12 @@ public class DiskStatsLoggingService extends JobService {
        return false;
    }

    @VisibleForTesting
    static boolean isDumpsysTaskEnabled(ContentResolver resolver) {
        // The default is to treat the task as enabled.
        return Settings.Global.getInt(resolver, Settings.Global.ENABLE_DISKSTATS_LOGGING, 1) != 0;
    }

    @VisibleForTesting
    static class LogRunnable implements Runnable {
        private static final long TIMEOUT_MILLIS = TimeUnit.MINUTES.toMillis(10);