Add flag to force expire the app optimization mode event.

Bug: 347444433
Test: atest
Change-Id: Id502607ed6c07870d14346656a65ceccb756b78f
This commit is contained in:
mxyyiyi
2024-06-17 13:55:27 +08:00
parent 3576f4840d
commit 08907935df
5 changed files with 39 additions and 1 deletions

View File

@@ -39,6 +39,9 @@ public interface PowerUsageFeatureProvider {
/** Check whether the battery tips card is enabled in the battery usage page */
boolean isBatteryTipsEnabled();
/** Check whether force expire the app optimization mode. */
boolean isForceExpireAppOptimizationModeEnabled();
/** Check whether to log the optimization mode of app entry in period job */
boolean isAppOptimizationModeLogged();

View File

@@ -83,6 +83,11 @@ public class PowerUsageFeatureProviderImpl implements PowerUsageFeatureProvider
return false;
}
@Override
public boolean isForceExpireAppOptimizationModeEnabled() {
return false;
}
@Override
public boolean isAppOptimizationModeLogged() {
return false;

View File

@@ -25,6 +25,7 @@ import androidx.annotation.VisibleForTesting
import com.android.settings.fuelgauge.BatteryOptimizeHistoricalLogEntry.Action
import com.android.settings.fuelgauge.BatteryOptimizeUtils
import com.android.settings.fuelgauge.BatteryUtils
import com.android.settings.overlay.FeatureFactory.Companion.featureFactory
/** A util to store and update app optimization mode expiration event data. */
object AppOptModeSharedPreferencesUtils {
@@ -74,10 +75,14 @@ object AppOptModeSharedPreferencesUtils {
@JvmStatic
fun resetExpiredAppOptModeBeforeTimestamp(context: Context, queryTimestampMs: Long) =
synchronized(appOptimizationModeLock) {
val forceExpireEnabled =
featureFactory
.powerUsageFeatureProvider.isForceExpireAppOptimizationModeEnabled
val eventsMap = getAppOptModeEventsMap(context)
val expirationUids = ArrayList<Int>(eventsMap.size)
for ((uid, event) in eventsMap) {
if (event.expirationTime > queryTimestampMs) {
// Not reset the mode if forceExpireEnabled is false and not expired.
if (!forceExpireEnabled && event.expirationTime > queryTimestampMs) {
continue
}
updateBatteryOptimizationMode(