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

Commit ed141331 authored by Nicholas Ambur's avatar Nicholas Ambur Committed by Android (Google) Code Review
Browse files

Merge changes from topic "hotword-battery-saver"

* changes:
  add API for ST clients run in battery saver mode
  add SOUND_TRIGGER_RUN_IN_BATTERY_SAVER permission
  add SoundTrigger service modes in battery saver
parents e327cb19 28cc6364
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -237,6 +237,7 @@ package android {
    field public static final String SET_WALLPAPER_COMPONENT = "android.permission.SET_WALLPAPER_COMPONENT";
    field public static final String SHOW_KEYGUARD_MESSAGE = "android.permission.SHOW_KEYGUARD_MESSAGE";
    field public static final String SHUTDOWN = "android.permission.SHUTDOWN";
    field public static final String SOUND_TRIGGER_RUN_IN_BATTERY_SAVER = "android.permission.SOUND_TRIGGER_RUN_IN_BATTERY_SAVER";
    field public static final String START_ACTIVITIES_FROM_BACKGROUND = "android.permission.START_ACTIVITIES_FROM_BACKGROUND";
    field public static final String START_FOREGROUND_SERVICES_FROM_BACKGROUND = "android.permission.START_FOREGROUND_SERVICES_FROM_BACKGROUND";
    field public static final String STATUS_BAR_SERVICE = "android.permission.STATUS_BAR_SERVICE";
@@ -5060,6 +5061,7 @@ package android.media.soundtrigger {
    field public static final int RECOGNITION_FLAG_CAPTURE_TRIGGER_AUDIO = 1; // 0x1
    field public static final int RECOGNITION_FLAG_ENABLE_AUDIO_ECHO_CANCELLATION = 4; // 0x4
    field public static final int RECOGNITION_FLAG_ENABLE_AUDIO_NOISE_SUPPRESSION = 8; // 0x8
    field public static final int RECOGNITION_FLAG_RUN_IN_BATTERY_SAVER = 16; // 0x10
  }
  public abstract static class SoundTriggerDetector.Callback {
@@ -7870,7 +7872,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 +7882,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 +7899,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 +7909,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 +8270,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
@@ -10198,6 +10205,7 @@ package android.service.voice {
    field public static final int RECOGNITION_FLAG_CAPTURE_TRIGGER_AUDIO = 1; // 0x1
    field public static final int RECOGNITION_FLAG_ENABLE_AUDIO_ECHO_CANCELLATION = 4; // 0x4
    field public static final int RECOGNITION_FLAG_ENABLE_AUDIO_NOISE_SUPPRESSION = 8; // 0x8
    field public static final int RECOGNITION_FLAG_RUN_IN_BATTERY_SAVER = 16; // 0x10
    field public static final int RECOGNITION_MODE_USER_IDENTIFICATION = 2; // 0x2
    field public static final int RECOGNITION_MODE_VOICE_TRIGGER = 1; // 0x1
    field public static final int STATE_ERROR = 3; // 0x3
+35 −8
Original line number Diff line number Diff line
@@ -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();
    }
@@ -242,12 +244,21 @@ public final class BatterySaverPolicyConfig implements Parcelable {
        return mDisableOptionalSensors;
    }

    /**
     * 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;
        }

+59 −0
Original line number Diff line number Diff line
@@ -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) {
@@ -1832,6 +1871,26 @@ public final class PowerManager {
        return powerSaveState.locationMode;
    }

    /**
     * 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
+10 −0
Original line number Diff line number Diff line
@@ -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;
+12 −1
Original line number Diff line number Diff line
@@ -125,6 +125,7 @@ public class AlwaysOnHotwordDetector {
            RECOGNITION_FLAG_ALLOW_MULTIPLE_TRIGGERS,
            RECOGNITION_FLAG_ENABLE_AUDIO_ECHO_CANCELLATION,
            RECOGNITION_FLAG_ENABLE_AUDIO_NOISE_SUPPRESSION,
            RECOGNITION_FLAG_RUN_IN_BATTERY_SAVER,
    })
    public @interface RecognitionFlags {}

@@ -171,6 +172,14 @@ public class AlwaysOnHotwordDetector {
     */
    public static final int RECOGNITION_FLAG_ENABLE_AUDIO_NOISE_SUPPRESSION = 0x8;

    /**
     * Recognition flag for {@link #startRecognition(int)} that indicates whether the recognition
     * should continue after battery saver mode is enabled.
     * When this flag is specified, the caller will be checked for
     * {@link android.Manifest.permission#SOUND_TRIGGER_RUN_IN_BATTERY_SAVER} permission granted.
     */
    public static final int RECOGNITION_FLAG_RUN_IN_BATTERY_SAVER = 0x10;

    //---- Recognition mode flags. Return codes for getSupportedRecognitionModes() ----//
    // Must be kept in sync with the related attribute defined as searchKeyphraseRecognitionFlags.

@@ -860,6 +869,7 @@ public class AlwaysOnHotwordDetector {
                (recognitionFlags&RECOGNITION_FLAG_CAPTURE_TRIGGER_AUDIO) != 0;
        boolean allowMultipleTriggers =
                (recognitionFlags&RECOGNITION_FLAG_ALLOW_MULTIPLE_TRIGGERS) != 0;
        boolean runInBatterySaver = (recognitionFlags&RECOGNITION_FLAG_RUN_IN_BATTERY_SAVER) != 0;

        int audioCapabilities = 0;
        if ((recognitionFlags & RECOGNITION_FLAG_ENABLE_AUDIO_ECHO_CANCELLATION) != 0) {
@@ -874,7 +884,8 @@ public class AlwaysOnHotwordDetector {
            code = mSoundTriggerSession.startRecognition(
                    mKeyphraseMetadata.getId(), mLocale.toLanguageTag(), mInternalCallback,
                    new RecognitionConfig(captureTriggerAudio, allowMultipleTriggers,
                            recognitionExtra, null /* additional data */, audioCapabilities));
                            recognitionExtra, null /* additional data */, audioCapabilities),
                    runInBatterySaver);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
Loading