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

Commit bc581bd2 authored by Nicholas Ambur's avatar Nicholas Ambur
Browse files

add native SoundTrigger 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 libpowermanager_test
Test: build and verify backward compatibility with SoundTrigger system
service behavior

Change-Id: I087a5817c832e194fc8ba670d5c90506d548544e
parent 6069b58f
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -55,7 +55,6 @@ status_t BatterySaverPolicyConfig::readFromParcel(const android::Parcel *parcel)
        ?: parcel->readBool(&mDisableAod)
        ?: parcel->readBool(&mDisableLaunchBoost)
        ?: parcel->readBool(&mDisableOptionalSensors)
        ?: parcel->readBool(&mDisableSoundTrigger)
        ?: parcel->readBool(&mDisableVibration)
        ?: parcel->readBool(&mEnableAdjustBrightness)
        ?: parcel->readBool(&mEnableDataSaver)
@@ -64,7 +63,8 @@ status_t BatterySaverPolicyConfig::readFromParcel(const android::Parcel *parcel)
        ?: parcel->readBool(&mEnableQuickDoze)
        ?: parcel->readBool(&mForceAllAppsStandby)
        ?: parcel->readBool(&mForceBackgroundCheck)
        ?: parcel->readInt32(reinterpret_cast<int32_t *>(&mLocationMode));
        ?: parcel->readInt32(reinterpret_cast<int32_t *>(&mLocationMode))
        ?: parcel->readInt32(reinterpret_cast<int32_t *>(&mSoundTriggerMode));
}

status_t BatterySaverPolicyConfig::writeDeviceSpecificSettings(android::Parcel *parcel) const {
@@ -97,7 +97,6 @@ status_t BatterySaverPolicyConfig::writeToParcel(android::Parcel *parcel) const
        ?: parcel->writeBool(mDisableAod)
        ?: parcel->writeBool(mDisableLaunchBoost)
        ?: parcel->writeBool(mDisableOptionalSensors)
        ?: parcel->writeBool(mDisableSoundTrigger)
        ?: parcel->writeBool(mDisableVibration)
        ?: parcel->writeBool(mEnableAdjustBrightness)
        ?: parcel->writeBool(mEnableDataSaver)
@@ -106,7 +105,8 @@ status_t BatterySaverPolicyConfig::writeToParcel(android::Parcel *parcel) const
        ?: parcel->writeBool(mEnableQuickDoze)
        ?: parcel->writeBool(mForceAllAppsStandby)
        ?: parcel->writeBool(mForceBackgroundCheck)
        ?: parcel->writeInt32(static_cast<int32_t>(mLocationMode));
        ?: parcel->writeInt32(static_cast<int32_t>(mLocationMode))
        ?: parcel->writeInt32(static_cast<int32_t>(mSoundTriggerMode));
}

} // namespace android::os
+2 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ status_t PowerSaveState::readFromParcel(const android::Parcel *parcel) {
    return parcel->readBool(&mBatterySaverEnabled)
        ?: parcel->readBool(&mGlobalBatterySaverEnabled)
        ?: parcel->readInt32(reinterpret_cast<int32_t *>(&mLocationMode))
        ?: parcel->readInt32(reinterpret_cast<int32_t *>(&mSoundTriggerMode))
        ?: parcel->readFloat(&mBrightnessFactor);
}

@@ -43,6 +44,7 @@ status_t PowerSaveState::writeToParcel(android::Parcel *parcel) const {
    return parcel->writeBool(mBatterySaverEnabled)
        ?: parcel->writeBool(mGlobalBatterySaverEnabled)
        ?: parcel->writeInt32(static_cast<int32_t>(mLocationMode))
        ?: parcel->writeInt32(static_cast<int32_t>(mSoundTriggerMode))
        ?: parcel->writeFloat(mBrightnessFactor);
}

+9 −8
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@
namespace android::os {

enum class LocationMode : int32_t;
enum class SoundTriggerMode : int32_t;
/**
 * BatterySaverPolicyConfig is a structure of configs to set Battery Saver policy flags.
 * This file needs to be kept in sync with
@@ -40,7 +41,6 @@ struct BatterySaverPolicyConfig : public android::Parcelable {
                             bool disableAod = false,
                             bool disableLaunchBoost = false,
                             bool disableOptionalSensors = false,
                             bool disableSoundTrigger = false,
                             bool disableVibration = false,
                             bool enableAdjustBrightness = false,
                             bool enableDataSaver = false,
@@ -49,7 +49,8 @@ struct BatterySaverPolicyConfig : public android::Parcelable {
                             bool enableQuickDoze = false,
                             bool forceAllAppsStandby = false,
                             bool forceBackgroundCheck = false,
                             LocationMode locationMode = static_cast<LocationMode>(0))
                             LocationMode locationMode = static_cast<LocationMode>(0),
                             SoundTriggerMode soundTriggerMode = static_cast<SoundTriggerMode>(0))
        : mAdjustBrightnessFactor(adjustBrightnessFactor),
          mAdvertiseIsEnabled(advertiseIsEnabled),
          mDeferFullBackup(deferFullBackup),
@@ -59,7 +60,6 @@ struct BatterySaverPolicyConfig : public android::Parcelable {
          mDisableAod(disableAod),
          mDisableLaunchBoost(disableLaunchBoost),
          mDisableOptionalSensors(disableOptionalSensors),
          mDisableSoundTrigger(disableSoundTrigger),
          mDisableVibration(disableVibration),
          mEnableAdjustBrightness(enableAdjustBrightness),
          mEnableDataSaver(enableDataSaver),
@@ -68,7 +68,8 @@ struct BatterySaverPolicyConfig : public android::Parcelable {
          mEnableQuickDoze(enableQuickDoze),
          mForceAllAppsStandby(forceAllAppsStandby),
          mForceBackgroundCheck(forceBackgroundCheck),
          mLocationMode(locationMode) {
          mLocationMode(locationMode),
          mSoundTriggerMode(soundTriggerMode) {
    }

    status_t readFromParcel(const android::Parcel* parcel) override;
@@ -83,7 +84,6 @@ struct BatterySaverPolicyConfig : public android::Parcelable {
               mDisableAod == bsp.mDisableAod &&
               mDisableLaunchBoost == bsp.mDisableLaunchBoost &&
               mDisableOptionalSensors == bsp.mDisableOptionalSensors &&
               mDisableSoundTrigger == bsp.mDisableSoundTrigger &&
               mDisableVibration == bsp.mDisableVibration &&
               mEnableAdjustBrightness == bsp.mEnableAdjustBrightness &&
               mEnableDataSaver == bsp.mEnableDataSaver &&
@@ -92,7 +92,8 @@ struct BatterySaverPolicyConfig : public android::Parcelable {
               mEnableQuickDoze == bsp.mEnableQuickDoze &&
               mForceAllAppsStandby == bsp.mForceAllAppsStandby &&
               mForceBackgroundCheck == bsp.mForceBackgroundCheck &&
               mLocationMode == bsp.mLocationMode;
               mLocationMode == bsp.mLocationMode &&
               mSoundTriggerMode == bsp.mSoundTriggerMode;
    }

private:
@@ -116,8 +117,6 @@ private:
    bool mDisableLaunchBoost;
    /** Disable optional sensors */
    bool mDisableOptionalSensors;
    /** Disable sound trigger */
    bool mDisableSoundTrigger;
    /** Disable vibration */
    bool mDisableVibration;
    /** Enable adjust brightness */
@@ -136,6 +135,8 @@ private:
    bool mForceBackgroundCheck;
    /** Location mode */
    LocationMode mLocationMode;
    /** SoundTrigger mode */
    SoundTriggerMode mSoundTriggerMode;
};

} // namespace android::os
+6 −0
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@
namespace android::os {

enum class LocationMode : int32_t;
enum class SoundTriggerMode : int32_t;
/**
 * PowerSaveState is a structure to encapsulate PowerSaveState status.
 * This file needs to be kept in sync with frameworks/base/core/java/android/os/PowerSaveState.java
@@ -33,16 +34,19 @@ struct PowerSaveState : public android::Parcelable {
    PowerSaveState(bool batterySaverEnabled = false,
                   bool globalBatterySaverEnabled = false,
                   LocationMode locationMode = static_cast<LocationMode>(0),
                   SoundTriggerMode soundTriggerMode = static_cast<SoundTriggerMode>(0),
                   float brightnessFactor = 0.5f)
            : mBatterySaverEnabled(batterySaverEnabled),
              mGlobalBatterySaverEnabled(globalBatterySaverEnabled),
              mLocationMode(locationMode),
              mSoundTriggerMode(soundTriggerMode),
              mBrightnessFactor(brightnessFactor) {
    }

    bool getBatterySaverEnabled() const { return mBatterySaverEnabled; }
    bool getGlobalBatterySaverEnabled() const { return mGlobalBatterySaverEnabled; }
    LocationMode getLocationMode() const { return mLocationMode; }
    SoundTriggerMode getSoundTriggerMode() const { return mSoundTriggerMode; }
    float getBrightnessFactor() const { return mBrightnessFactor; }
    bool operator == (const PowerSaveState &ps) const {
        return mBatterySaverEnabled == ps.mBatterySaverEnabled &&
@@ -61,6 +65,8 @@ private:
    bool mGlobalBatterySaverEnabled;
    /** Location mode */
    LocationMode mLocationMode;
    /** SoundTrigger mode */
    SoundTriggerMode mSoundTriggerMode;
    /** Screen brightness factor. */
    float mBrightnessFactor;
};
+32 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef ANDROID_OS_SOUNDTRIGGER_MODE_H
#define ANDROID_OS_SOUNDTRIGGER_MODE_H

namespace android::os {

enum class SoundTriggerMode : int32_t {
    ALL_ENABLED = IPowerManager::SOUND_TRIGGER_MODE_ALL_ENABLED,
    CRITICAL_ONLY = IPowerManager::SOUND_TRIGGER_MODE_CRITICAL_ONLY,
    ALL_DISABLED = IPowerManager::SOUND_TRIGGER_MODE_ALL_DISABLED,
    MIN = IPowerManager::SOUND_TRIGGER_MODE_ALL_ENABLED,
    MAX = IPowerManager::SOUND_TRIGGER_MODE_ALL_DISABLED,
};

} // namespace android::os

#endif /* ANDROID_OS_SOUNDTRIGGER_MODE_H */