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

Commit 5d1462f7 authored by Dianne Hackborn's avatar Dianne Hackborn Committed by Android (Google) Code Review
Browse files

Merge "Fix issue #21930140: Add config to turn off auto power features" into mnc-dev

parents c242d9d2 92617036
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -157,6 +157,15 @@
         ActivityManager based on screen size. -->
    <integer name="config_extraFreeKbytesAdjust">0</integer>

    <!-- Set this to true to enable the platform's auto-power-save modes like doze and
         app standby.  These are not enabled by default because they require a standard
         cloud-to-device messaging service for apps to interact correctly with the modes
         (such as to be able to deliver an instant message to the device even when it is
         dozing).  This should be enabled if you have such services and expect apps to
         correctly use them when installed on your device.  Otherwise, keep this disabled
         so that applications can still use their own mechanisms. -->
    <bool name="config_enableAutoPowerModes">false</bool>

    <!-- The duration (in milliseconds) that the radio will scan for a signal
         when there's no network connection. If the scan doesn't timeout, use zero -->
    <integer name="config_radioScanningTimeout">0</integer>
+1 −0
Original line number Diff line number Diff line
@@ -251,6 +251,7 @@
  <java-symbol type="bool" name="config_bluetooth_le_peripheral_mode_supported" />
  <java-symbol type="bool" name="config_cellBroadcastAppLinks" />
  <java-symbol type="bool" name="config_duplicate_port_omadm_wappush" />
  <java-symbol type="bool" name="config_enableAutoPowerModes" />
  <java-symbol type="bool" name="config_enable_emergency_call_while_sim_locked" />
  <java-symbol type="bool" name="config_enable_puk_unlock_screen" />
  <java-symbol type="bool" name="config_enableBurnInProtection" />
+19 −15
Original line number Diff line number Diff line
@@ -97,9 +97,6 @@ public class DeviceIdleController extends SystemService
    private static final String ACTION_STEP_IDLE_STATE =
            "com.android.server.device_idle.STEP_IDLE_STATE";

    private static final String ACTION_ENTER_INACTIVE_STATE =
        "com.android.server.device_idle.ENTER_INACTIVE_STATE";

    private AlarmManager mAlarmManager;
    private IBatteryStats mBatteryStats;
    private PowerManagerInternal mLocalPowerManager;
@@ -112,7 +109,7 @@ public class DeviceIdleController extends SystemService
    private Intent mIdleIntent;
    private Display mCurDisplay;
    private AnyMotionDetector mAnyMotionDetector;
    private boolean mIdleDisabled;
    private boolean mEnabled;
    private boolean mScreenOn;
    private boolean mCharging;
    private boolean mSigMotionActive;
@@ -191,10 +188,6 @@ public class DeviceIdleController extends SystemService
                synchronized (DeviceIdleController.this) {
                    stepIdleStateLocked();
                }
            } else if (ACTION_ENTER_INACTIVE_STATE.equals(intent.getAction())) {
                synchronized (DeviceIdleController.this) {
                    enterInactiveStateLocked();
                }
            }
        }
    };
@@ -612,6 +605,8 @@ public class DeviceIdleController extends SystemService
        final PackageManager pm = getContext().getPackageManager();

        synchronized (this) {
            mEnabled = getContext().getResources().getBoolean(
                    com.android.internal.R.bool.config_enableAutoPowerModes);
            SystemConfig sysConfig = SystemConfig.getInstance();
            ArraySet<String> allowPower = sysConfig.getAllowInPowerSave();
            for (int i=0; i<allowPower.size(); i++) {
@@ -881,7 +876,7 @@ public class DeviceIdleController extends SystemService

    void becomeInactiveIfAppropriateLocked() {
        if (DEBUG) Slog.d(TAG, "becomeInactiveIfAppropriateLocked()");
        if (!mScreenOn && !mCharging && !mIdleDisabled && mState == STATE_ACTIVE) {
        if (!mScreenOn && !mCharging && mEnabled && mState == STATE_ACTIVE) {
            // Screen has turned off; we are now going to become inactive and start
            // waiting to see if we will ultimately go idle.
            mState = STATE_INACTIVE;
@@ -1216,8 +1211,12 @@ public class DeviceIdleController extends SystemService
        pw.println("    Completely disable device idle mode.");
        pw.println("  enable");
        pw.println("    Re-enable device idle mode after it had previously been disabled.");
        pw.println("  whitelist");
        pw.println("  enabled");
        pw.println("    Print 1 if device idle mode is currently enabled, else 0.");
        pw.println("  whitelist [package ...]");
        pw.println("    Add (prefix with +) or remove (prefix with -) packages.");
        pw.println("  tempwhitelist [package ..]");
        pw.println("    Temporarily place packages in whitelist for 10 seconds.");
    }

    void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
@@ -1252,8 +1251,8 @@ public class DeviceIdleController extends SystemService
                    return;
                } else if ("disable".equals(arg)) {
                    synchronized (this) {
                        if (!mIdleDisabled) {
                            mIdleDisabled = true;
                        if (mEnabled) {
                            mEnabled = false;
                            becomeActiveLocked("disabled", Process.myUid());
                            pw.println("Idle mode disabled");
                        }
@@ -1261,13 +1260,18 @@ public class DeviceIdleController extends SystemService
                    return;
                } else if ("enable".equals(arg)) {
                    synchronized (this) {
                        if (mIdleDisabled) {
                            mIdleDisabled = false;
                        if (!mEnabled) {
                            mEnabled = true;
                            becomeInactiveIfAppropriateLocked();
                            pw.println("Idle mode enabled");
                        }
                    }
                    return;
                } else if ("enabled".equals(arg)) {
                    synchronized (this) {
                        pw.println(mEnabled ? "1" : " 0");
                    }
                    return;
                } else if ("whitelist".equals(arg)) {
                    i++;
                    while (i < args.length) {
@@ -1364,9 +1368,9 @@ public class DeviceIdleController extends SystemService
                }
            }

            pw.print("  mEnabled="); pw.println(mEnabled);
            pw.print("  mSigMotionSensor="); pw.println(mSigMotionSensor);
            pw.print("  mCurDisplay="); pw.println(mCurDisplay);
            pw.print("  mIdleDisabled="); pw.println(mIdleDisabled);
            pw.print("  mScreenOn="); pw.println(mScreenOn);
            pw.print("  mCharging="); pw.println(mCharging);
            pw.print("  mSigMotionActive="); pw.println(mSigMotionActive);
+31 −8
Original line number Diff line number Diff line
@@ -35,8 +35,6 @@ import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SyncAdapterType;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.ParceledListSlice;
@@ -74,7 +72,6 @@ import com.android.internal.app.IBatteryStats;
import com.android.internal.os.BackgroundThread;
import com.android.internal.os.SomeArgs;
import com.android.internal.util.IndentingPrintWriter;
import com.android.server.DeviceIdleController;
import com.android.server.SystemService;

import java.io.BufferedReader;
@@ -138,6 +135,7 @@ public class UsageStatsService extends SystemService implements
    long mRealTimeSnapshot;
    long mSystemTimeSnapshot;

    boolean mAppIdleEnabled;
    boolean mAppIdleParoled;
    private boolean mScreenOn;
    private long mLastAppIdleParoledTime;
@@ -175,10 +173,15 @@ public class UsageStatsService extends SystemService implements
        getContext().registerReceiverAsUser(new UserActionsReceiver(), UserHandle.ALL, userActions,
                null, null);

        mAppIdleEnabled = getContext().getResources().getBoolean(
                com.android.internal.R.bool.config_enableAutoPowerModes);
        if (mAppIdleEnabled) {
            IntentFilter deviceStates = new IntentFilter(BatteryManager.ACTION_CHARGING);
            deviceStates.addAction(BatteryManager.ACTION_DISCHARGING);
            deviceStates.addAction(PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED);
            getContext().registerReceiver(new DeviceStateReceiver(), deviceStates);
        }

        synchronized (mLock) {
            cleanUpRemovedUsersLocked();
        }
@@ -186,7 +189,6 @@ public class UsageStatsService extends SystemService implements
        mRealTimeSnapshot = SystemClock.elapsedRealtime();
        mSystemTimeSnapshot = System.currentTimeMillis();


        publishLocalService(UsageStatsManagerInternal.class, new LocalService());
        publishBinderService(Context.USAGE_STATS_SERVICE, new BinderService());
    }
@@ -342,6 +344,10 @@ public class UsageStatsService extends SystemService implements

    /** Check all running users' or specified user's apps to see if they enter an idle state. */
    void checkIdleStates(int checkUserId) {
        if (!mAppIdleEnabled) {
            return;
        }

        final int[] userIds;
        try {
            if (checkUserId == UserHandle.USER_ALL) {
@@ -772,6 +778,10 @@ public class UsageStatsService extends SystemService implements
    private boolean isAppIdleFiltered(String packageName, int userId,
            UserUsageStatsService userService, long timeNow, long screenOnTime) {
        if (packageName == null) return false;
        // If not enabled at all, of course nobody is ever idle.
        if (!mAppIdleEnabled) {
            return false;
        }
        synchronized (mLock) {
            // Temporary exemption, probably due to device charging or occasional allowance to
            // be allowed to sync, etc.
@@ -900,6 +910,19 @@ public class UsageStatsService extends SystemService implements
            pw.print("  mAppIdleParoleDurationMillis=");
            TimeUtils.formatDuration(mAppIdleParoleDurationMillis, pw);
            pw.println();

            pw.println();
            pw.print("mAppIdleEnabled="); pw.print(mAppIdleEnabled);
            pw.print(" mAppIdleParoled="); pw.print(mAppIdleParoled);
            pw.print(" mScreenOn="); pw.println(mScreenOn);
            pw.print("mLastAppIdleParoledTime=");
            TimeUtils.formatDuration(mLastAppIdleParoledTime, pw);
            pw.println();
            pw.print("mScreenOnTime="); TimeUtils.formatDuration(mScreenOnTime, pw);
            pw.println();
            pw.print("mScreenOnSystemTimeSnapshot=");
            TimeUtils.formatDuration(mScreenOnSystemTimeSnapshot, pw);
            pw.println();
        }
    }