diff options
| author | 2020-12-04 08:33:17 -0800 | |
|---|---|---|
| committer | 2021-01-22 18:24:39 -0800 | |
| commit | c0a3c8c5f8b88a76e118f4c3a0165b0c8df84c82 (patch) | |
| tree | eef5352dc1cee4c0021c207634447489ed6917f2 | |
| parent | 54c8ade4b7defdfc0a893b3b3c361f8a7493d7c3 (diff) | |
add SoundTrigger service modes in battery saver
Control over the SoundTrigger service behavior in battery saver mode is
expanded to from a boolean to multiple modes. Modes include enabled,
disabled, and privileged. Adding the privedged mode allows for the
SoundTrigger service to selectively control clients which are deemed
esential to the Android system.
Bug: 172294448
Test: atest BatterySaverPolicyTest
Test: atest CtsBatterySavingTestCases
Test: atest PowerManagerTest
Test: build and verify backward compatibility with SoundTrigger system
service behavior
Change-Id: Ib701963b07b205e5902ef265198b390a9850cb88
8 files changed, 204 insertions, 65 deletions
diff --git a/core/api/system-current.txt b/core/api/system-current.txt index e4cf28ce1921..2e9aedd81237 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -7870,7 +7870,7 @@ package android.os { method public boolean getDisableAod(); method public boolean getDisableLaunchBoost(); method public boolean getDisableOptionalSensors(); - method public boolean getDisableSoundTrigger(); + method @Deprecated public boolean getDisableSoundTrigger(); method public boolean getDisableVibration(); method public boolean getEnableAdjustBrightness(); method public boolean getEnableDataSaver(); @@ -7880,6 +7880,7 @@ package android.os { method public boolean getForceAllAppsStandby(); method public boolean getForceBackgroundCheck(); method public int getLocationMode(); + method public int getSoundTriggerMode(); method public void writeToParcel(android.os.Parcel, int); field @NonNull public static final android.os.Parcelable.Creator<android.os.BatterySaverPolicyConfig> CREATOR; } @@ -7896,7 +7897,7 @@ package android.os { method @NonNull public android.os.BatterySaverPolicyConfig.Builder setDisableAod(boolean); method @NonNull public android.os.BatterySaverPolicyConfig.Builder setDisableLaunchBoost(boolean); method @NonNull public android.os.BatterySaverPolicyConfig.Builder setDisableOptionalSensors(boolean); - method @NonNull public android.os.BatterySaverPolicyConfig.Builder setDisableSoundTrigger(boolean); + method @Deprecated @NonNull public android.os.BatterySaverPolicyConfig.Builder setDisableSoundTrigger(boolean); method @NonNull public android.os.BatterySaverPolicyConfig.Builder setDisableVibration(boolean); method @NonNull public android.os.BatterySaverPolicyConfig.Builder setEnableAdjustBrightness(boolean); method @NonNull public android.os.BatterySaverPolicyConfig.Builder setEnableDataSaver(boolean); @@ -7906,6 +7907,7 @@ package android.os { method @NonNull public android.os.BatterySaverPolicyConfig.Builder setForceAllAppsStandby(boolean); method @NonNull public android.os.BatterySaverPolicyConfig.Builder setForceBackgroundCheck(boolean); method @NonNull public android.os.BatterySaverPolicyConfig.Builder setLocationMode(int); + method @NonNull public android.os.BatterySaverPolicyConfig.Builder setSoundTriggerMode(int); } public final class BatteryStatsManager { @@ -8266,6 +8268,9 @@ package android.os { field public static final int POWER_SAVE_MODE_TRIGGER_DYNAMIC = 1; // 0x1 field public static final int POWER_SAVE_MODE_TRIGGER_PERCENTAGE = 0; // 0x0 field public static final String REBOOT_USERSPACE = "userspace"; + field public static final int SOUND_TRIGGER_MODE_ALL_DISABLED = 2; // 0x2 + field public static final int SOUND_TRIGGER_MODE_ALL_ENABLED = 0; // 0x0 + field public static final int SOUND_TRIGGER_MODE_CRITICAL_ONLY = 1; // 0x1 field public static final int USER_ACTIVITY_EVENT_ACCESSIBILITY = 3; // 0x3 field public static final int USER_ACTIVITY_EVENT_BUTTON = 1; // 0x1 field public static final int USER_ACTIVITY_EVENT_OTHER = 0; // 0x0 diff --git a/core/java/android/os/BatterySaverPolicyConfig.java b/core/java/android/os/BatterySaverPolicyConfig.java index 3f6ce4fa807c..6f5139038e86 100644 --- a/core/java/android/os/BatterySaverPolicyConfig.java +++ b/core/java/android/os/BatterySaverPolicyConfig.java @@ -42,7 +42,6 @@ public final class BatterySaverPolicyConfig implements Parcelable { private final boolean mDisableAod; private final boolean mDisableLaunchBoost; private final boolean mDisableOptionalSensors; - private final boolean mDisableSoundTrigger; private final boolean mDisableVibration; private final boolean mEnableAdjustBrightness; private final boolean mEnableDataSaver; @@ -52,6 +51,7 @@ public final class BatterySaverPolicyConfig implements Parcelable { private final boolean mForceAllAppsStandby; private final boolean mForceBackgroundCheck; private final int mLocationMode; + private final int mSoundTriggerMode; private BatterySaverPolicyConfig(Builder in) { mAdjustBrightnessFactor = Math.max(0, Math.min(in.mAdjustBrightnessFactor, 1f)); @@ -64,7 +64,6 @@ public final class BatterySaverPolicyConfig implements Parcelable { mDisableAod = in.mDisableAod; mDisableLaunchBoost = in.mDisableLaunchBoost; mDisableOptionalSensors = in.mDisableOptionalSensors; - mDisableSoundTrigger = in.mDisableSoundTrigger; mDisableVibration = in.mDisableVibration; mEnableAdjustBrightness = in.mEnableAdjustBrightness; mEnableDataSaver = in.mEnableDataSaver; @@ -75,6 +74,8 @@ public final class BatterySaverPolicyConfig implements Parcelable { mForceBackgroundCheck = in.mForceBackgroundCheck; mLocationMode = Math.max(PowerManager.MIN_LOCATION_MODE, Math.min(in.mLocationMode, PowerManager.MAX_LOCATION_MODE)); + mSoundTriggerMode = Math.max(PowerManager.MIN_SOUND_TRIGGER_MODE, + Math.min(in.mSoundTriggerMode, PowerManager.MAX_SOUND_TRIGGER_MODE)); } private BatterySaverPolicyConfig(Parcel in) { @@ -99,7 +100,6 @@ public final class BatterySaverPolicyConfig implements Parcelable { mDisableAod = in.readBoolean(); mDisableLaunchBoost = in.readBoolean(); mDisableOptionalSensors = in.readBoolean(); - mDisableSoundTrigger = in.readBoolean(); mDisableVibration = in.readBoolean(); mEnableAdjustBrightness = in.readBoolean(); mEnableDataSaver = in.readBoolean(); @@ -110,6 +110,8 @@ public final class BatterySaverPolicyConfig implements Parcelable { mForceBackgroundCheck = in.readBoolean(); mLocationMode = Math.max(PowerManager.MIN_LOCATION_MODE, Math.min(in.readInt(), PowerManager.MAX_LOCATION_MODE)); + mSoundTriggerMode = Math.max(PowerManager.MIN_SOUND_TRIGGER_MODE, + Math.min(in.readInt(), PowerManager.MAX_SOUND_TRIGGER_MODE)); } public static final @android.annotation.NonNull Creator<BatterySaverPolicyConfig> CREATOR = @@ -149,7 +151,6 @@ public final class BatterySaverPolicyConfig implements Parcelable { dest.writeBoolean(mDisableAod); dest.writeBoolean(mDisableLaunchBoost); dest.writeBoolean(mDisableOptionalSensors); - dest.writeBoolean(mDisableSoundTrigger); dest.writeBoolean(mDisableVibration); dest.writeBoolean(mEnableAdjustBrightness); dest.writeBoolean(mEnableDataSaver); @@ -159,6 +160,7 @@ public final class BatterySaverPolicyConfig implements Parcelable { dest.writeBoolean(mForceAllAppsStandby); dest.writeBoolean(mForceBackgroundCheck); dest.writeInt(mLocationMode); + dest.writeInt(mSoundTriggerMode); } @NonNull @@ -184,7 +186,7 @@ public final class BatterySaverPolicyConfig implements Parcelable { + "launch_boost_disabled=" + mDisableLaunchBoost + "," + "optional_sensors_disabled=" + mDisableOptionalSensors + "," + "quick_doze_enabled=" + mEnableQuickDoze + "," - + "soundtrigger_disabled=" + mDisableSoundTrigger + "," + + "soundtrigger_mode=" + mSoundTriggerMode + "," + "vibration_disabled=" + mDisableVibration + "," + sb.toString(); } @@ -243,11 +245,20 @@ public final class BatterySaverPolicyConfig implements Parcelable { } /** + * Get the SoundTrigger mode while in Battery Saver. + */ + public int getSoundTriggerMode() { + return mSoundTriggerMode; + } + + /** * Whether or not to disable {@link android.hardware.soundtrigger.SoundTrigger} * while in Battery Saver. + * @deprecated Use {@link #getSoundTriggerMode()} instead. */ + @Deprecated public boolean getDisableSoundTrigger() { - return mDisableSoundTrigger; + return mSoundTriggerMode == PowerManager.SOUND_TRIGGER_MODE_ALL_DISABLED; } /** Whether or not to disable vibration while in Battery Saver. */ @@ -315,7 +326,6 @@ public final class BatterySaverPolicyConfig implements Parcelable { private boolean mDisableAod = false; private boolean mDisableLaunchBoost = false; private boolean mDisableOptionalSensors = false; - private boolean mDisableSoundTrigger = false; private boolean mDisableVibration = false; private boolean mEnableAdjustBrightness = false; private boolean mEnableDataSaver = false; @@ -325,6 +335,7 @@ public final class BatterySaverPolicyConfig implements Parcelable { private boolean mForceAllAppsStandby = false; private boolean mForceBackgroundCheck = false; private int mLocationMode = PowerManager.LOCATION_MODE_NO_CHANGE; + private int mSoundTriggerMode = PowerManager.SOUND_TRIGGER_MODE_ALL_ENABLED; public Builder() { } @@ -416,10 +427,26 @@ public final class BatterySaverPolicyConfig implements Parcelable { /** * Set whether or not to disable {@link android.hardware.soundtrigger.SoundTrigger} * while in Battery Saver. + * @deprecated Use {@link #setSoundTriggerMode(int)} instead. */ + @Deprecated @NonNull public Builder setDisableSoundTrigger(boolean disableSoundTrigger) { - mDisableSoundTrigger = disableSoundTrigger; + if (disableSoundTrigger) { + mSoundTriggerMode = PowerManager.SOUND_TRIGGER_MODE_ALL_DISABLED; + } else { + mSoundTriggerMode = PowerManager.SOUND_TRIGGER_MODE_ALL_ENABLED; + } + return this; + } + + /** + * Set the SoundTrigger mode while in Battery Saver. + */ + @NonNull + public Builder setSoundTriggerMode( + @PowerManager.SoundTriggerPowerSaveMode int soundTriggerMode) { + mSoundTriggerMode = soundTriggerMode; return this; } diff --git a/core/java/android/os/PowerManager.java b/core/java/android/os/PowerManager.java index d11f3ce0d112..90648325ae0e 100644 --- a/core/java/android/os/PowerManager.java +++ b/core/java/android/os/PowerManager.java @@ -885,6 +885,45 @@ public final class PowerManager { }) public @interface LocationPowerSaveMode {} + /** + * In this mode, all active SoundTrigger recognitions are enabled by the SoundTrigger system + * service. + * @hide + */ + @SystemApi + public static final int SOUND_TRIGGER_MODE_ALL_ENABLED = 0; + /** + * In this mode, only privileged components of the SoundTrigger system service should be + * enabled. This functionality is to be used to limit SoundTrigger recognitions to those only + * deemed necessary by the system. + * @hide + */ + @SystemApi + public static final int SOUND_TRIGGER_MODE_CRITICAL_ONLY = 1; + /** + * In this mode, all active SoundTrigger recognitions should be disabled by the SoundTrigger + * system service. + * @hide + */ + @SystemApi + public static final int SOUND_TRIGGER_MODE_ALL_DISABLED = 2; + + /** @hide */ + public static final int MIN_SOUND_TRIGGER_MODE = SOUND_TRIGGER_MODE_ALL_ENABLED; + /** @hide */ + public static final int MAX_SOUND_TRIGGER_MODE = SOUND_TRIGGER_MODE_ALL_DISABLED; + + /** + * @hide + */ + @Retention(RetentionPolicy.SOURCE) + @IntDef(prefix = {"SOUND_TRIGGER_MODE_"}, value = { + SOUND_TRIGGER_MODE_ALL_ENABLED, + SOUND_TRIGGER_MODE_CRITICAL_ONLY, + SOUND_TRIGGER_MODE_ALL_DISABLED, + }) + public @interface SoundTriggerPowerSaveMode {} + /** @hide */ public static String locationPowerSaveModeToString(@LocationPowerSaveMode int mode) { switch (mode) { @@ -1833,6 +1872,26 @@ public final class PowerManager { } /** + * Returns how SoundTrigger features should behave when battery saver is on. When battery saver + * is off, this will always return {@link #SOUND_TRIGGER_MODE_ALL_ENABLED}. + * + * <p>This API is normally only useful for components that provide use SoundTrigger features. + * + * @see #isPowerSaveMode() + * @see #ACTION_POWER_SAVE_MODE_CHANGED + * + * @hide + */ + @SoundTriggerPowerSaveMode + public int getSoundTriggerPowerSaveMode() { + final PowerSaveState powerSaveState = getPowerSaveState(ServiceType.SOUND); + if (!powerSaveState.batterySaverEnabled) { + return SOUND_TRIGGER_MODE_ALL_ENABLED; + } + return powerSaveState.soundTriggerMode; + } + + /** * Returns true if the device is currently in idle mode. This happens when a device * has been sitting unused and unmoving for a sufficiently long period of time, so that * it decides to go into a lower power-use state. This may involve things like turning diff --git a/core/java/android/os/PowerSaveState.java b/core/java/android/os/PowerSaveState.java index 4a5e89479ec0..7d3cd0687180 100644 --- a/core/java/android/os/PowerSaveState.java +++ b/core/java/android/os/PowerSaveState.java @@ -36,11 +36,13 @@ public class PowerSaveState implements Parcelable { */ public final boolean globalBatterySaverEnabled; public final int locationMode; + public final int soundTriggerMode; public final float brightnessFactor; public PowerSaveState(Builder builder) { batterySaverEnabled = builder.mBatterySaverEnabled; locationMode = builder.mLocationMode; + soundTriggerMode = builder.mSoundTriggerMode; brightnessFactor = builder.mBrightnessFactor; globalBatterySaverEnabled = builder.mGlobalBatterySaverEnabled; } @@ -49,6 +51,7 @@ public class PowerSaveState implements Parcelable { batterySaverEnabled = in.readByte() != 0; globalBatterySaverEnabled = in.readByte() != 0; locationMode = in.readInt(); + soundTriggerMode = in.readInt(); brightnessFactor = in.readFloat(); } @@ -62,6 +65,7 @@ public class PowerSaveState implements Parcelable { dest.writeByte((byte) (batterySaverEnabled ? 1 : 0)); dest.writeByte((byte) (globalBatterySaverEnabled ? 1 : 0)); dest.writeInt(locationMode); + dest.writeInt(soundTriggerMode); dest.writeFloat(brightnessFactor); } @@ -69,6 +73,7 @@ public class PowerSaveState implements Parcelable { private boolean mBatterySaverEnabled = false; private boolean mGlobalBatterySaverEnabled = false; private int mLocationMode = 0; + private int mSoundTriggerMode = PowerManager.SOUND_TRIGGER_MODE_ALL_ENABLED; private float mBrightnessFactor = 0.5f; public Builder() {} @@ -83,6 +88,11 @@ public class PowerSaveState implements Parcelable { return this; } + public Builder setSoundTriggerMode(int mode) { + mSoundTriggerMode = mode; + return this; + } + public Builder setLocationMode(int mode) { mLocationMode = mode; return this; diff --git a/core/tests/coretests/jni/NativePowerManagerTest.cpp b/core/tests/coretests/jni/NativePowerManagerTest.cpp index 50fb31ba085a..5f20e4f9c407 100644 --- a/core/tests/coretests/jni/NativePowerManagerTest.cpp +++ b/core/tests/coretests/jni/NativePowerManagerTest.cpp @@ -61,7 +61,6 @@ static struct BatterySaverPolicyConfigFieldId { jfieldID disableAod; jfieldID disableLaunchBoost; jfieldID disableOptionalSensors; - jfieldID disableSoundTrigger; jfieldID disableVibration; jfieldID enableAdjustBrightness; jfieldID enableDataSaver; @@ -71,6 +70,7 @@ static struct BatterySaverPolicyConfigFieldId { jfieldID forceAllAppsStandby; jfieldID forceBackgroundCheck; jfieldID locationMode; + jfieldID soundTriggerMode; } gBSPCFieldIds; static jobject nativeObtainParcel(JNIEnv* env) { @@ -171,10 +171,11 @@ static void nativeUnparcelAndVerifyWorkSource(JNIEnv* env, jobject /* obj */, jo static jobject nativeObtainPowerSaveStateParcel(JNIEnv* env, jobject /* obj */, jboolean batterySaverEnabled, jboolean globalBatterySaverEnabled, - jint locationMode, jfloat brightnessFactor) { + jint locationMode, jint soundTriggerMode, jfloat brightnessFactor) { PowerSaveState ps = PowerSaveState(static_cast<bool>(batterySaverEnabled), static_cast<bool>(globalBatterySaverEnabled), static_cast<LocationMode>(locationMode), + static_cast<SoundTriggerMode>(soundTriggerMode), static_cast<float>(brightnessFactor)); jobject psParcel = nativeObtainParcel(env); Parcel* parcel = nativeGetParcelData(env, psParcel); @@ -189,7 +190,7 @@ static jobject nativeObtainPowerSaveStateParcel(JNIEnv* env, jobject /* obj */, static void nativeUnparcelAndVerifyPowerSaveState(JNIEnv* env, jobject /* obj */, jobject psParcel, jboolean batterySaverEnabled, jboolean globalBatterySaverEnabled, - jint locationMode, jfloat brightnessFactor) { + jint locationMode, jint soundTriggerMode, jfloat brightnessFactor) { PowerSaveState ps = {}; Parcel* parcel = nativeGetParcelData(env, psParcel); status_t err = ps.readFromParcel(parcel); @@ -200,6 +201,7 @@ static void nativeUnparcelAndVerifyPowerSaveState(JNIEnv* env, jobject /* obj */ PowerSaveState psOrig = PowerSaveState(static_cast<bool>(batterySaverEnabled), static_cast<bool>(globalBatterySaverEnabled), static_cast<LocationMode>(locationMode), + static_cast<SoundTriggerMode>(soundTriggerMode), static_cast<float>(brightnessFactor)); if (ps == psOrig) { return; @@ -229,7 +231,6 @@ static jobject nativeObtainBSPConfigParcel(JNIEnv* env, jobject /* obj */, env->GetBooleanField(bsObj, gBSPCFieldIds.disableAod), env->GetBooleanField(bsObj, gBSPCFieldIds.disableLaunchBoost), env->GetBooleanField(bsObj, gBSPCFieldIds.disableOptionalSensors), - env->GetBooleanField(bsObj, gBSPCFieldIds.disableSoundTrigger), env->GetBooleanField(bsObj, gBSPCFieldIds.disableVibration), env->GetBooleanField(bsObj, gBSPCFieldIds.enableAdjustBrightness), env->GetBooleanField(bsObj, gBSPCFieldIds.enableDataSaver), @@ -238,7 +239,8 @@ static jobject nativeObtainBSPConfigParcel(JNIEnv* env, jobject /* obj */, env->GetBooleanField(bsObj, gBSPCFieldIds.enableQuickDoze), env->GetBooleanField(bsObj, gBSPCFieldIds.forceAllAppsStandby), env->GetBooleanField(bsObj, gBSPCFieldIds.forceBackgroundCheck), - static_cast<LocationMode>(env->GetIntField(bsObj, gBSPCFieldIds.locationMode))); + static_cast<LocationMode>(env->GetIntField(bsObj, gBSPCFieldIds.locationMode)), + static_cast<SoundTriggerMode>(env->GetIntField(bsObj, gBSPCFieldIds.soundTriggerMode))); jobject bsParcel = nativeObtainParcel(env); Parcel* parcel = nativeGetParcelData(env, bsParcel); @@ -279,7 +281,6 @@ static void nativeUnparcelAndVerifyBSPConfig(JNIEnv* env, jobject /* obj */, env->GetBooleanField(bsObj, gBSPCFieldIds.disableAod), env->GetBooleanField(bsObj, gBSPCFieldIds.disableLaunchBoost), env->GetBooleanField(bsObj, gBSPCFieldIds.disableOptionalSensors), - env->GetBooleanField(bsObj, gBSPCFieldIds.disableSoundTrigger), env->GetBooleanField(bsObj, gBSPCFieldIds.disableVibration), env->GetBooleanField(bsObj, gBSPCFieldIds.enableAdjustBrightness), env->GetBooleanField(bsObj, gBSPCFieldIds.enableDataSaver), @@ -288,7 +289,8 @@ static void nativeUnparcelAndVerifyBSPConfig(JNIEnv* env, jobject /* obj */, env->GetBooleanField(bsObj, gBSPCFieldIds.enableQuickDoze), env->GetBooleanField(bsObj, gBSPCFieldIds.forceAllAppsStandby), env->GetBooleanField(bsObj, gBSPCFieldIds.forceBackgroundCheck), - static_cast<LocationMode>(env->GetIntField(bsObj, gBSPCFieldIds.locationMode))); + static_cast<LocationMode>(env->GetIntField(bsObj, gBSPCFieldIds.locationMode)), + static_cast<SoundTriggerMode>(env->GetIntField(bsObj, gBSPCFieldIds.soundTriggerMode))); if (bs == bsOrig) { return; @@ -307,9 +309,9 @@ extern "C" jint JNI_OnLoad(JavaVM* vm, void* /* reserved */) (void*) nativeObtainWorkSourceParcel }, { "nativeUnparcelAndVerifyWorkSource", "(Landroid/os/Parcel;[I[Ljava/lang/String;)V", (void*) nativeUnparcelAndVerifyWorkSource }, - { "nativeObtainPowerSaveStateParcel", "(ZZIF)Landroid/os/Parcel;", + { "nativeObtainPowerSaveStateParcel", "(ZZIIF)Landroid/os/Parcel;", (void*) nativeObtainPowerSaveStateParcel }, - { "nativeUnparcelAndVerifyPowerSaveState", "(Landroid/os/Parcel;ZZIF)V", + { "nativeUnparcelAndVerifyPowerSaveState", "(Landroid/os/Parcel;ZZIIF)V", (void*) nativeUnparcelAndVerifyPowerSaveState }, { "nativeObtainBSPConfigParcel", "(Landroid/os/BatterySaverPolicyConfig;" @@ -340,7 +342,6 @@ extern "C" jint JNI_OnLoad(JavaVM* vm, void* /* reserved */) GET_FIELD_ID(gBSPCFieldIds.disableAod, bspcClazz, "mDisableAod", "Z"); GET_FIELD_ID(gBSPCFieldIds.disableLaunchBoost, bspcClazz, "mDisableLaunchBoost", "Z"); GET_FIELD_ID(gBSPCFieldIds.disableOptionalSensors, bspcClazz, "mDisableOptionalSensors", "Z"); - GET_FIELD_ID(gBSPCFieldIds.disableSoundTrigger, bspcClazz, "mDisableSoundTrigger", "Z"); GET_FIELD_ID(gBSPCFieldIds.disableVibration, bspcClazz, "mDisableVibration", "Z"); GET_FIELD_ID(gBSPCFieldIds.enableAdjustBrightness, bspcClazz, "mEnableAdjustBrightness", "Z"); GET_FIELD_ID(gBSPCFieldIds.enableDataSaver, bspcClazz, "mEnableDataSaver", "Z"); @@ -350,6 +351,7 @@ extern "C" jint JNI_OnLoad(JavaVM* vm, void* /* reserved */) GET_FIELD_ID(gBSPCFieldIds.forceAllAppsStandby, bspcClazz, "mForceAllAppsStandby", "Z"); GET_FIELD_ID(gBSPCFieldIds.forceBackgroundCheck, bspcClazz, "mForceBackgroundCheck", "Z"); GET_FIELD_ID(gBSPCFieldIds.locationMode, bspcClazz, "mLocationMode", "I"); + GET_FIELD_ID(gBSPCFieldIds.soundTriggerMode, bspcClazz, "mSoundTriggerMode", "I"); jniRegisterNativeMethods(env, "android/os/PowerManagerTest", methodTable, sizeof(methodTable) / sizeof(JNINativeMethod)); diff --git a/core/tests/coretests/src/android/os/PowerManagerTest.java b/core/tests/coretests/src/android/os/PowerManagerTest.java index d3baed34509e..0dfc37131f7f 100644 --- a/core/tests/coretests/src/android/os/PowerManagerTest.java +++ b/core/tests/coretests/src/android/os/PowerManagerTest.java @@ -53,10 +53,11 @@ public class PowerManagerTest extends AndroidTestCase { private native void nativeUnparcelAndVerifyWorkSource(Parcel parcel, int[] uids, String[] names); private native Parcel nativeObtainPowerSaveStateParcel(boolean batterySaverEnabled, - boolean globalBatterySaverEnabled, int locationMode, float brightnessFactor); + boolean globalBatterySaverEnabled, int locationMode, int soundTriggerMode, + float brightnessFactor); private native void nativeUnparcelAndVerifyPowerSaveState(Parcel parcel, boolean batterySaverEnabled, boolean globalBatterySaverEnabled, - int locationMode, float brightnessFactor); + int locationMode, int soundTriggerMode, float brightnessFactor); private native Parcel nativeObtainBSPConfigParcel(BatterySaverPolicyConfig bs, String[] keys, String[] values); private native void nativeUnparcelAndVerifyBSPConfig(Parcel parcel, BatterySaverPolicyConfig bs, @@ -351,15 +352,17 @@ public class PowerManagerTest extends AndroidTestCase { * specified parameters, and verify the PowerSaveState object created from the parcel. */ private void unparcelPowerSaveStateFromNativeAndVerify(boolean batterySaverEnabled, - boolean globalBatterySaverEnabled, int locationMode, float brightnessFactor) { + boolean globalBatterySaverEnabled, int locationMode, int soundTriggerMode, + float brightnessFactor) { // Obtain PowerSaveState as parcel from native, with parameters. Parcel psParcel = nativeObtainPowerSaveStateParcel(batterySaverEnabled, - globalBatterySaverEnabled, locationMode, brightnessFactor); + globalBatterySaverEnabled, locationMode, soundTriggerMode, brightnessFactor); // Verify the parcel. PowerSaveState ps = PowerSaveState.CREATOR.createFromParcel(psParcel); assertEquals(ps.batterySaverEnabled, batterySaverEnabled); assertEquals(ps.globalBatterySaverEnabled, globalBatterySaverEnabled); assertEquals(ps.locationMode, locationMode); + assertEquals(ps.soundTriggerMode, soundTriggerMode); assertEquals(ps.brightnessFactor, brightnessFactor, 0.01f); } @@ -368,7 +371,8 @@ public class PowerManagerTest extends AndroidTestCase { * specified parameters. Native will verify the PowerSaveState in native is expected. */ private void parcelPowerSaveStateToNativeAndVerify(boolean batterySaverEnabled, - boolean globalBatterySaverEnabled, int locationMode, float brightnessFactor) { + boolean globalBatterySaverEnabled, int locationMode, int soundTriggerMode, + float brightnessFactor) { Parcel psParcel = Parcel.obtain(); // PowerSaveState API blocks Builder.build(), generate a parcel instead of object. PowerSaveState ps = new PowerSaveState.Builder() @@ -380,7 +384,7 @@ public class PowerManagerTest extends AndroidTestCase { psParcel.setDataPosition(0); //Set the PowerSaveState as parcel to native and verify in native space. nativeUnparcelAndVerifyPowerSaveState(psParcel, batterySaverEnabled, - globalBatterySaverEnabled, locationMode, brightnessFactor); + globalBatterySaverEnabled, locationMode, soundTriggerMode, brightnessFactor); } /** @@ -463,10 +467,13 @@ public class PowerManagerTest extends AndroidTestCase { public void testPowerSaveStateNativeToJava() { unparcelPowerSaveStateFromNativeAndVerify(false /* batterySaverEnabled */, false /* globalBatterySaverEnabled */, - PowerManager.LOCATION_MODE_FOREGROUND_ONLY, 0.3f /* brightnessFactor */); + PowerManager.LOCATION_MODE_FOREGROUND_ONLY, + PowerManager.SOUND_TRIGGER_MODE_CRITICAL_ONLY, + 0.3f /* brightnessFactor */); unparcelPowerSaveStateFromNativeAndVerify(true /* batterySaverEnabled */, true /* globalBatterySaverEnabled */, PowerManager.LOCATION_MODE_GPS_DISABLED_WHEN_SCREEN_OFF, + PowerManager.SOUND_TRIGGER_MODE_ALL_DISABLED, 0.5f /* brightnessFactor */); } @@ -479,10 +486,13 @@ public class PowerManagerTest extends AndroidTestCase { public void testSetPowerSaveStateJavaToNative() { parcelPowerSaveStateToNativeAndVerify(false /* batterySaverEnabled */, false /* globalBatterySaverEnabled */, - PowerManager.LOCATION_MODE_FOREGROUND_ONLY, 0.3f /* brightnessFactor */); + PowerManager.LOCATION_MODE_FOREGROUND_ONLY, + PowerManager.SOUND_TRIGGER_MODE_CRITICAL_ONLY, + 0.3f /* brightnessFactor */); parcelPowerSaveStateToNativeAndVerify(true /* batterySaverEnabled */, true /* globalBatterySaverEnabled */, PowerManager.LOCATION_MODE_GPS_DISABLED_WHEN_SCREEN_OFF, + PowerManager.SOUND_TRIGGER_MODE_ALL_DISABLED, 0.5f /* brightnessFactor */); } diff --git a/services/core/java/com/android/server/power/batterysaver/BatterySaverPolicy.java b/services/core/java/com/android/server/power/batterysaver/BatterySaverPolicy.java index eea79f6eca95..ff50ebd07f54 100644 --- a/services/core/java/com/android/server/power/batterysaver/BatterySaverPolicy.java +++ b/services/core/java/com/android/server/power/batterysaver/BatterySaverPolicy.java @@ -72,7 +72,7 @@ public class BatterySaverPolicy extends ContentObserver implements @VisibleForTesting static final String KEY_DISABLE_ANIMATION = "disable_animation"; @VisibleForTesting - static final String KEY_DISABLE_SOUNDTRIGGER = "disable_soundtrigger"; + static final String KEY_SOUNDTRIGGER_MODE = "soundtrigger_mode"; /** * Turn on the network firewall when Battery Saver is turned on. @@ -144,7 +144,6 @@ public class BatterySaverPolicy extends ContentObserver implements false, /* disableAod */ false, /* disableLaunchBoost */ false, /* disableOptionalSensors */ - false, /* disableSoundTrigger */ false, /* disableVibration */ false, /* enableAdjustBrightness */ false, /* enableDataSaver */ @@ -155,7 +154,8 @@ public class BatterySaverPolicy extends ContentObserver implements new ArrayMap<>(), /* filesForNoninteractive */ false, /* forceAllAppsStandby */ false, /* forceBackgroundCheck */ - PowerManager.LOCATION_MODE_NO_CHANGE /* locationMode */ + PowerManager.LOCATION_MODE_NO_CHANGE, /* locationMode */ + PowerManager.SOUND_TRIGGER_MODE_ALL_ENABLED /* soundTriggerMode */ ); private static final Policy DEFAULT_ADAPTIVE_POLICY = OFF_POLICY; @@ -169,7 +169,6 @@ public class BatterySaverPolicy extends ContentObserver implements true, /* disableAod */ true, /* disableLaunchBoost */ true, /* disableOptionalSensors */ - true, /* disableSoundTrigger */ true, /* disableVibration */ false, /* enableAdjustBrightness */ false, /* enableDataSaver */ @@ -180,7 +179,8 @@ public class BatterySaverPolicy extends ContentObserver implements new ArrayMap<>(), /* filesForNoninteractive */ true, /* forceAllAppsStandby */ true, /* forceBackgroundCheck */ - PowerManager.LOCATION_MODE_ALL_DISABLED_WHEN_SCREEN_OFF /* locationMode */ + PowerManager.LOCATION_MODE_ALL_DISABLED_WHEN_SCREEN_OFF, /* locationMode */ + PowerManager.SOUND_TRIGGER_MODE_CRITICAL_ONLY /* soundTriggerMode */ ); private final Object mLock; @@ -494,7 +494,6 @@ public class BatterySaverPolicy extends ContentObserver implements rawPolicy.disableAod, rawPolicy.disableLaunchBoost, rawPolicy.disableOptionalSensors, - rawPolicy.disableSoundTrigger, // Don't disable vibration when accessibility is on. rawPolicy.disableVibration && !mAccessibilityEnabled.get(), rawPolicy.enableAdjustBrightness, @@ -507,7 +506,8 @@ public class BatterySaverPolicy extends ContentObserver implements rawPolicy.filesForNoninteractive, rawPolicy.forceAllAppsStandby, rawPolicy.forceBackgroundCheck, - locationMode + locationMode, + rawPolicy.soundTriggerMode ); @@ -518,7 +518,9 @@ public class BatterySaverPolicy extends ContentObserver implements if (mEffectivePolicyRaw.disableVibration) sb.append("v"); if (mEffectivePolicyRaw.disableAnimation) sb.append("a"); - if (mEffectivePolicyRaw.disableSoundTrigger) sb.append("s"); + + sb.append(mEffectivePolicyRaw.soundTriggerMode); + if (mEffectivePolicyRaw.deferFullBackup) sb.append("F"); if (mEffectivePolicyRaw.deferKeyValueBackup) sb.append("K"); if (mEffectivePolicyRaw.enableFirewall) sb.append("f"); @@ -599,9 +601,9 @@ public class BatterySaverPolicy extends ContentObserver implements * in battery saver mode. * * @see Settings.Global#BATTERY_SAVER_CONSTANTS - * @see #KEY_DISABLE_SOUNDTRIGGER + * @see #KEY_SOUNDTRIGGER_MODE */ - public final boolean disableSoundTrigger; + public final int soundTriggerMode; /** * {@code true} if vibration is disabled in battery saver mode. @@ -692,7 +694,6 @@ public class BatterySaverPolicy extends ContentObserver implements boolean disableAod, boolean disableLaunchBoost, boolean disableOptionalSensors, - boolean disableSoundTrigger, boolean disableVibration, boolean enableAdjustBrightness, boolean enableDataSaver, @@ -703,7 +704,8 @@ public class BatterySaverPolicy extends ContentObserver implements ArrayMap<String, String> filesForNoninteractive, boolean forceAllAppsStandby, boolean forceBackgroundCheck, - int locationMode) { + int locationMode, + int soundTriggerMode) { this.adjustBrightnessFactor = Math.min(1, Math.max(0, adjustBrightnessFactor)); this.advertiseIsEnabled = advertiseIsEnabled; @@ -713,7 +715,6 @@ public class BatterySaverPolicy extends ContentObserver implements this.disableAod = disableAod; this.disableLaunchBoost = disableLaunchBoost; this.disableOptionalSensors = disableOptionalSensors; - this.disableSoundTrigger = disableSoundTrigger; this.disableVibration = disableVibration; this.enableAdjustBrightness = enableAdjustBrightness; this.enableDataSaver = enableDataSaver; @@ -733,6 +734,14 @@ public class BatterySaverPolicy extends ContentObserver implements this.locationMode = locationMode; } + if (soundTriggerMode < PowerManager.MIN_SOUND_TRIGGER_MODE + || soundTriggerMode > PowerManager.MAX_SOUND_TRIGGER_MODE) { + Slog.e(TAG, "Invalid SoundTrigger mode: " + soundTriggerMode); + this.soundTriggerMode = PowerManager.SOUND_TRIGGER_MODE_ALL_ENABLED; + } else { + this.soundTriggerMode = soundTriggerMode; + } + mHashCode = Objects.hash( adjustBrightnessFactor, advertiseIsEnabled, @@ -742,7 +751,6 @@ public class BatterySaverPolicy extends ContentObserver implements disableAod, disableLaunchBoost, disableOptionalSensors, - disableSoundTrigger, disableVibration, enableAdjustBrightness, enableDataSaver, @@ -753,7 +761,8 @@ public class BatterySaverPolicy extends ContentObserver implements filesForNoninteractive, forceAllAppsStandby, forceBackgroundCheck, - locationMode); + locationMode, + soundTriggerMode); } static Policy fromConfig(BatterySaverPolicyConfig config) { @@ -778,7 +787,6 @@ public class BatterySaverPolicy extends ContentObserver implements config.getDisableAod(), config.getDisableLaunchBoost(), config.getDisableOptionalSensors(), - config.getDisableSoundTrigger(), config.getDisableVibration(), config.getEnableAdjustBrightness(), config.getEnableDataSaver(), @@ -791,7 +799,8 @@ public class BatterySaverPolicy extends ContentObserver implements (new CpuFrequencies()).parseString(cpuFreqNoninteractive).toSysFileMap(), config.getForceAllAppsStandby(), config.getForceBackgroundCheck(), - config.getLocationMode() + config.getLocationMode(), + config.getSoundTriggerMode() ); } @@ -851,9 +860,6 @@ public class BatterySaverPolicy extends ContentObserver implements final boolean disableOptionalSensors = parser.getBoolean(KEY_DISABLE_OPTIONAL_SENSORS, properties.getBoolean(KEY_DISABLE_OPTIONAL_SENSORS + configSuffix, defaultPolicy.disableOptionalSensors)); - final boolean disableSoundTrigger = parser.getBoolean(KEY_DISABLE_SOUNDTRIGGER, - properties.getBoolean(KEY_DISABLE_SOUNDTRIGGER + configSuffix, - defaultPolicy.disableSoundTrigger)); final boolean disableVibrationConfig = parser.getBoolean(KEY_DISABLE_VIBRATION, properties.getBoolean(KEY_DISABLE_VIBRATION + configSuffix, defaultPolicy.disableVibration)); @@ -882,7 +888,9 @@ public class BatterySaverPolicy extends ContentObserver implements final int locationMode = parser.getInt(KEY_LOCATION_MODE, properties.getInt(KEY_LOCATION_MODE + configSuffix, defaultPolicy.locationMode)); - + final int soundTriggerMode = parser.getInt(KEY_SOUNDTRIGGER_MODE, + properties.getInt(KEY_SOUNDTRIGGER_MODE + configSuffix, + defaultPolicy.soundTriggerMode)); return new Policy( adjustBrightnessFactor, advertiseIsEnabled, @@ -892,7 +900,6 @@ public class BatterySaverPolicy extends ContentObserver implements disableAod, disableLaunchBoost, disableOptionalSensors, - disableSoundTrigger, /* disableVibration */ disableVibrationConfig, enableBrightnessAdjustment, @@ -906,7 +913,8 @@ public class BatterySaverPolicy extends ContentObserver implements (new CpuFrequencies()).parseString(cpuFreqNoninteractive).toSysFileMap(), forceAllAppsStandby, forceBackgroundCheck, - locationMode + locationMode, + soundTriggerMode ); } @@ -923,7 +931,6 @@ public class BatterySaverPolicy extends ContentObserver implements && disableAod == other.disableAod && disableLaunchBoost == other.disableLaunchBoost && disableOptionalSensors == other.disableOptionalSensors - && disableSoundTrigger == other.disableSoundTrigger && disableVibration == other.disableVibration && enableAdjustBrightness == other.enableAdjustBrightness && enableDataSaver == other.enableDataSaver @@ -933,6 +940,7 @@ public class BatterySaverPolicy extends ContentObserver implements && forceAllAppsStandby == other.forceAllAppsStandby && forceBackgroundCheck == other.forceBackgroundCheck && locationMode == other.locationMode + && soundTriggerMode == other.soundTriggerMode && filesForInteractive.equals(other.filesForInteractive) && filesForNoninteractive.equals(other.filesForNoninteractive); } @@ -983,7 +991,11 @@ public class BatterySaverPolicy extends ContentObserver implements return builder.setBatterySaverEnabled(currPolicy.enableDataSaver) .build(); case ServiceType.SOUND: - return builder.setBatterySaverEnabled(currPolicy.disableSoundTrigger) + boolean soundTriggerBatterySaverEnabled = currPolicy.advertiseIsEnabled + || currPolicy.soundTriggerMode + != PowerManager.SOUND_TRIGGER_MODE_ALL_ENABLED; + return builder.setBatterySaverEnabled(soundTriggerBatterySaverEnabled) + .setSoundTriggerMode(currPolicy.soundTriggerMode) .build(); case ServiceType.VIBRATION: return builder.setBatterySaverEnabled(currPolicy.disableVibration) @@ -1172,7 +1184,7 @@ public class BatterySaverPolicy extends ContentObserver implements pw.println(KEY_FORCE_BACKGROUND_CHECK + "=" + p.forceBackgroundCheck); pw.println(KEY_DISABLE_OPTIONAL_SENSORS + "=" + p.disableOptionalSensors); pw.println(KEY_DISABLE_AOD + "=" + p.disableAod); - pw.println(KEY_DISABLE_SOUNDTRIGGER + "=" + p.disableSoundTrigger); + pw.println(KEY_SOUNDTRIGGER_MODE + "=" + p.soundTriggerMode); pw.println(KEY_ENABLE_QUICK_DOZE + "=" + p.enableQuickDoze); pw.println(KEY_ENABLE_NIGHT_MODE + "=" + p.enableNightMode); diff --git a/services/tests/servicestests/src/com/android/server/power/batterysaver/BatterySaverPolicyTest.java b/services/tests/servicestests/src/com/android/server/power/batterysaver/BatterySaverPolicyTest.java index 9bd488d3df7e..4671b09b5cff 100644 --- a/services/tests/servicestests/src/com/android/server/power/batterysaver/BatterySaverPolicyTest.java +++ b/services/tests/servicestests/src/com/android/server/power/batterysaver/BatterySaverPolicyTest.java @@ -48,10 +48,12 @@ public class BatterySaverPolicyTest extends AndroidTestCase { private static final int GPS_MODE = 0; // LOCATION_MODE_NO_CHANGE private static final int DEFAULT_GPS_MODE = PowerManager.LOCATION_MODE_ALL_DISABLED_WHEN_SCREEN_OFF; + private static final int SOUND_TRIGGER_MODE = 0; // SOUND_TRIGGER_MODE_ALL_ENABLED + private static final int DEFAULT_SOUND_TRIGGER_MODE = + PowerManager.SOUND_TRIGGER_MODE_CRITICAL_ONLY; private static final String BATTERY_SAVER_CONSTANTS = "disable_vibration=true," + "advertise_is_enabled=true," + "disable_animation=false," - + "disable_soundtrigger=true," + "enable_firewall=true," + "enable_datasaver=true," + "enable_brightness_adjustment=false," @@ -59,6 +61,7 @@ public class BatterySaverPolicyTest extends AndroidTestCase { + "defer_full_backup=true," + "defer_keyvalue_backup=false," + "location_mode=0," // LOCATION_MODE_NO_CHANGE + + "soundtrigger_mode=0," // SOUND_TRIGGER_MODE_ALL_ENABLE + "enable_night_mode=false," + "enable_quick_doze=true"; private static final String BATTERY_SAVER_INCORRECT_CONSTANTS = "vi*,!=,,true"; @@ -125,6 +128,11 @@ public class BatterySaverPolicyTest extends AndroidTestCase { @SmallTest public void testGetBatterySaverPolicy_PolicySound_DefaultValueCorrect() { testServiceDefaultValue_On(ServiceType.SOUND); + + mBatterySaverPolicy.setPolicyLevel(POLICY_LEVEL_FULL); + PowerSaveState stateOn = + mBatterySaverPolicy.getBatterySaverPolicy(ServiceType.SOUND); + assertThat(stateOn.soundTriggerMode).isEqualTo(DEFAULT_SOUND_TRIGGER_MODE); } @SmallTest @@ -211,6 +219,7 @@ public class BatterySaverPolicyTest extends AndroidTestCase { final PowerSaveState soundState = mBatterySaverPolicy.getBatterySaverPolicy(ServiceType.SOUND); assertThat(soundState.batterySaverEnabled).isTrue(); + assertThat(soundState.soundTriggerMode).isEqualTo(SOUND_TRIGGER_MODE); final PowerSaveState networkState = mBatterySaverPolicy.getBatterySaverPolicy( ServiceType.NETWORK_FIREWALL); @@ -408,7 +417,6 @@ public class BatterySaverPolicyTest extends AndroidTestCase { + "," + BatterySaverPolicy.KEY_DISABLE_AOD + "=true" + "," + BatterySaverPolicy.KEY_DISABLE_LAUNCH_BOOST + "=true" + "," + BatterySaverPolicy.KEY_DISABLE_OPTIONAL_SENSORS + "=true" - + "," + BatterySaverPolicy.KEY_DISABLE_SOUNDTRIGGER + "=true" + "," + BatterySaverPolicy.KEY_DISABLE_VIBRATION + "=true" + "," + BatterySaverPolicy.KEY_ENABLE_BRIGHTNESS_ADJUSTMENT + "=true" + "," + BatterySaverPolicy.KEY_ENABLE_DATASAVER + "=true" @@ -418,7 +426,9 @@ public class BatterySaverPolicyTest extends AndroidTestCase { + "," + BatterySaverPolicy.KEY_FORCE_ALL_APPS_STANDBY + "=true" + "," + BatterySaverPolicy.KEY_FORCE_BACKGROUND_CHECK + "=true" + "," + BatterySaverPolicy.KEY_LOCATION_MODE - + "=" + PowerManager.LOCATION_MODE_FOREGROUND_ONLY, + + "=" + PowerManager.LOCATION_MODE_FOREGROUND_ONLY + + "," + BatterySaverPolicy.KEY_SOUNDTRIGGER_MODE + + "=" + PowerManager.SOUND_TRIGGER_MODE_CRITICAL_ONLY, "", new DeviceConfig.Properties.Builder(DeviceConfig.NAMESPACE_BATTERY_SAVER) .setFloat(BatterySaverPolicy.KEY_ADJUST_BRIGHTNESS_FACTOR, .5f) @@ -429,7 +439,6 @@ public class BatterySaverPolicyTest extends AndroidTestCase { .setBoolean(BatterySaverPolicy.KEY_DISABLE_AOD, false) .setBoolean(BatterySaverPolicy.KEY_DISABLE_LAUNCH_BOOST, false) .setBoolean(BatterySaverPolicy.KEY_DISABLE_OPTIONAL_SENSORS, false) - .setBoolean(BatterySaverPolicy.KEY_DISABLE_SOUNDTRIGGER, false) .setBoolean(BatterySaverPolicy.KEY_DISABLE_VIBRATION, false) .setBoolean(BatterySaverPolicy.KEY_ENABLE_BRIGHTNESS_ADJUSTMENT, false) .setBoolean(BatterySaverPolicy.KEY_ENABLE_DATASAVER, false) @@ -440,6 +449,8 @@ public class BatterySaverPolicyTest extends AndroidTestCase { .setBoolean(BatterySaverPolicy.KEY_FORCE_BACKGROUND_CHECK, false) .setInt(BatterySaverPolicy.KEY_LOCATION_MODE, PowerManager.LOCATION_MODE_THROTTLE_REQUESTS_WHEN_SCREEN_OFF) + .setInt(BatterySaverPolicy.KEY_SOUNDTRIGGER_MODE, + PowerManager.SOUND_TRIGGER_MODE_ALL_DISABLED) .build(), null); assertEquals(.1f, policy.adjustBrightnessFactor); @@ -450,7 +461,6 @@ public class BatterySaverPolicyTest extends AndroidTestCase { assertTrue(policy.disableAod); assertTrue(policy.disableLaunchBoost); assertTrue(policy.disableOptionalSensors); - assertTrue(policy.disableSoundTrigger); assertTrue(policy.disableVibration); assertTrue(policy.enableAdjustBrightness); assertTrue(policy.enableDataSaver); @@ -460,6 +470,7 @@ public class BatterySaverPolicyTest extends AndroidTestCase { assertTrue(policy.forceAllAppsStandby); assertTrue(policy.forceBackgroundCheck); assertEquals(PowerManager.LOCATION_MODE_FOREGROUND_ONLY, policy.locationMode); + assertEquals(PowerManager.SOUND_TRIGGER_MODE_CRITICAL_ONLY, policy.soundTriggerMode); } public void testDeviceConfigOverridesDefaults() { @@ -474,7 +485,6 @@ public class BatterySaverPolicyTest extends AndroidTestCase { .setBoolean(BatterySaverPolicy.KEY_DISABLE_AOD, false) .setBoolean(BatterySaverPolicy.KEY_DISABLE_LAUNCH_BOOST, false) .setBoolean(BatterySaverPolicy.KEY_DISABLE_OPTIONAL_SENSORS, false) - .setBoolean(BatterySaverPolicy.KEY_DISABLE_SOUNDTRIGGER, false) .setBoolean(BatterySaverPolicy.KEY_DISABLE_VIBRATION, false) .setBoolean(BatterySaverPolicy.KEY_ENABLE_BRIGHTNESS_ADJUSTMENT, false) .setBoolean(BatterySaverPolicy.KEY_ENABLE_DATASAVER, false) @@ -485,6 +495,8 @@ public class BatterySaverPolicyTest extends AndroidTestCase { .setBoolean(BatterySaverPolicy.KEY_FORCE_BACKGROUND_CHECK, false) .setInt(BatterySaverPolicy.KEY_LOCATION_MODE, PowerManager.LOCATION_MODE_THROTTLE_REQUESTS_WHEN_SCREEN_OFF) + .setInt(BatterySaverPolicy.KEY_SOUNDTRIGGER_MODE, + PowerManager.SOUND_TRIGGER_MODE_ALL_DISABLED) .build(), null); assertEquals(.5f, policy.adjustBrightnessFactor); @@ -495,7 +507,6 @@ public class BatterySaverPolicyTest extends AndroidTestCase { assertFalse(policy.disableAod); assertFalse(policy.disableLaunchBoost); assertFalse(policy.disableOptionalSensors); - assertFalse(policy.disableSoundTrigger); assertFalse(policy.disableVibration); assertFalse(policy.enableAdjustBrightness); assertFalse(policy.enableDataSaver); @@ -506,6 +517,8 @@ public class BatterySaverPolicyTest extends AndroidTestCase { assertFalse(policy.forceBackgroundCheck); assertEquals(PowerManager.LOCATION_MODE_THROTTLE_REQUESTS_WHEN_SCREEN_OFF, policy.locationMode); + assertEquals(PowerManager.SOUND_TRIGGER_MODE_ALL_DISABLED, + policy.soundTriggerMode); } public void testDeviceConfig_AdaptiveValues() { @@ -521,7 +534,6 @@ public class BatterySaverPolicyTest extends AndroidTestCase { .setBoolean(BatterySaverPolicy.KEY_DISABLE_AOD, false) .setBoolean(BatterySaverPolicy.KEY_DISABLE_LAUNCH_BOOST, false) .setBoolean(BatterySaverPolicy.KEY_DISABLE_OPTIONAL_SENSORS, false) - .setBoolean(BatterySaverPolicy.KEY_DISABLE_SOUNDTRIGGER, false) .setBoolean(BatterySaverPolicy.KEY_DISABLE_VIBRATION, false) .setBoolean(BatterySaverPolicy.KEY_ENABLE_BRIGHTNESS_ADJUSTMENT, false) .setBoolean(BatterySaverPolicy.KEY_ENABLE_DATASAVER, false) @@ -532,6 +544,8 @@ public class BatterySaverPolicyTest extends AndroidTestCase { .setBoolean(BatterySaverPolicy.KEY_FORCE_BACKGROUND_CHECK, false) .setInt(BatterySaverPolicy.KEY_LOCATION_MODE, PowerManager.LOCATION_MODE_THROTTLE_REQUESTS_WHEN_SCREEN_OFF) + .setInt(BatterySaverPolicy.KEY_SOUNDTRIGGER_MODE, + PowerManager.SOUND_TRIGGER_MODE_ALL_DISABLED) .setFloat(BatterySaverPolicy.KEY_ADJUST_BRIGHTNESS_FACTOR + adaptiveSuffix, .9f) .setBoolean(BatterySaverPolicy.KEY_ADVERTISE_IS_ENABLED + adaptiveSuffix, @@ -546,8 +560,6 @@ public class BatterySaverPolicyTest extends AndroidTestCase { .setBoolean( BatterySaverPolicy.KEY_DISABLE_OPTIONAL_SENSORS + adaptiveSuffix, true) - .setBoolean(BatterySaverPolicy.KEY_DISABLE_SOUNDTRIGGER + adaptiveSuffix, - true) .setBoolean(BatterySaverPolicy.KEY_DISABLE_VIBRATION + adaptiveSuffix, true) .setBoolean(BatterySaverPolicy.KEY_ENABLE_BRIGHTNESS_ADJUSTMENT + adaptiveSuffix, true) @@ -561,6 +573,8 @@ public class BatterySaverPolicyTest extends AndroidTestCase { true) .setInt(BatterySaverPolicy.KEY_LOCATION_MODE + adaptiveSuffix, PowerManager.LOCATION_MODE_FOREGROUND_ONLY) + .setInt(BatterySaverPolicy.KEY_SOUNDTRIGGER_MODE + adaptiveSuffix, + PowerManager.SOUND_TRIGGER_MODE_CRITICAL_ONLY) .build(), adaptiveSuffix); assertEquals(.9f, policy.adjustBrightnessFactor); assertTrue(policy.advertiseIsEnabled); @@ -570,7 +584,6 @@ public class BatterySaverPolicyTest extends AndroidTestCase { assertTrue(policy.disableAod); assertTrue(policy.disableLaunchBoost); assertTrue(policy.disableOptionalSensors); - assertTrue(policy.disableSoundTrigger); assertTrue(policy.disableVibration); assertTrue(policy.enableAdjustBrightness); assertTrue(policy.enableDataSaver); @@ -580,5 +593,6 @@ public class BatterySaverPolicyTest extends AndroidTestCase { assertTrue(policy.forceAllAppsStandby); assertTrue(policy.forceBackgroundCheck); assertEquals(PowerManager.LOCATION_MODE_FOREGROUND_ONLY, policy.locationMode); + assertEquals(PowerManager.SOUND_TRIGGER_MODE_CRITICAL_ONLY, policy.soundTriggerMode); } } |