[Performance] avoid setting the same optimization mode again
Add a checking condition to avoid setting the same optimization mode again to improve the performance, since setting the optimization mode is a heavy operation when binding with system service. Bug: 192523697 Test: make SettingsRoboTests Change-Id: I4065e3c56201c1c9285d9cebedf670bc0c42c614
This commit is contained in:
@@ -36,13 +36,12 @@ public class BatteryOptimizeUtils {
|
||||
@VisibleForTesting AppOpsManager mAppOpsManager;
|
||||
@VisibleForTesting BatteryUtils mBatteryUtils;
|
||||
@VisibleForTesting PowerAllowlistBackend mPowerAllowListBackend;
|
||||
@VisibleForTesting int mMode;
|
||||
@VisibleForTesting boolean mAllowListed;
|
||||
|
||||
private final String mPackageName;
|
||||
private final int mUid;
|
||||
|
||||
private int mMode;
|
||||
private boolean mAllowListed;
|
||||
|
||||
// Optimization modes.
|
||||
static final int MODE_UNKNOWN = 0;
|
||||
static final int MODE_RESTRICTED = 1;
|
||||
@@ -92,6 +91,10 @@ public class BatteryOptimizeUtils {
|
||||
|
||||
/** Sets the {@link OptimizationMode} for associated app. */
|
||||
public void setAppOptimizationMode(@OptimizationMode int mode) {
|
||||
if (getAppOptimizationMode(mMode, mAllowListed) == mode) {
|
||||
Log.w(TAG, "set the same optimization mode for: " + mPackageName);
|
||||
return;
|
||||
}
|
||||
switch (mode) {
|
||||
case MODE_RESTRICTED:
|
||||
mBatteryUtils.setForceAppStandby(mUid, mPackageName, AppOpsManager.MODE_IGNORED);
|
||||
|
Reference in New Issue
Block a user