Refactor isAppHibernationEnabled check in AppHibernationService
Directly return the static field to avoid querying DeviceConfig everytime. Bug: 181183614 Test: atest AppHibernationServiceTest Test: atest CtsWindowManagerDeviceTestCases:ActivityMetricsLoggerTests Test: atest CtsStatsdAtomHostTestCases:AppStartStatsTests Change-Id: Id01a701dadb76655a24effbd9d3ce011d7f2f686
This commit is contained in:
@@ -109,7 +109,7 @@ public final class AppHibernationService extends SystemService {
|
||||
private final boolean mOatArtifactDeletionEnabled;
|
||||
|
||||
@VisibleForTesting
|
||||
boolean mIsServiceEnabled;
|
||||
static boolean sIsServiceEnabled;
|
||||
|
||||
/**
|
||||
* Initializes the system service.
|
||||
@@ -165,7 +165,7 @@ public final class AppHibernationService extends SystemService {
|
||||
});
|
||||
}
|
||||
if (phase == SystemService.PHASE_SYSTEM_SERVICES_READY) {
|
||||
mIsServiceEnabled = isAppHibernationEnabled();
|
||||
sIsServiceEnabled = isDeviceConfigAppHibernationEnabled();
|
||||
DeviceConfig.addOnPropertiesChangedListener(
|
||||
NAMESPACE_APP_HIBERNATION,
|
||||
ActivityThread.currentApplication().getMainExecutor(),
|
||||
@@ -536,7 +536,7 @@ public final class AppHibernationService extends SystemService {
|
||||
private void onDeviceConfigChanged(Properties properties) {
|
||||
for (String key : properties.getKeyset()) {
|
||||
if (TextUtils.equals(KEY_APP_HIBERNATION_ENABLED, key)) {
|
||||
mIsServiceEnabled = isAppHibernationEnabled();
|
||||
sIsServiceEnabled = isDeviceConfigAppHibernationEnabled();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -574,10 +574,10 @@ public final class AppHibernationService extends SystemService {
|
||||
}
|
||||
|
||||
private boolean checkHibernationEnabled(String methodName) {
|
||||
if (!mIsServiceEnabled) {
|
||||
if (!sIsServiceEnabled) {
|
||||
Slog.w(TAG, String.format("Attempted to call %s on unsupported device.", methodName));
|
||||
}
|
||||
return mIsServiceEnabled;
|
||||
return sIsServiceEnabled;
|
||||
}
|
||||
|
||||
private void dump(PrintWriter pw) {
|
||||
@@ -725,6 +725,10 @@ public final class AppHibernationService extends SystemService {
|
||||
* @return true if enabled, false otherwise
|
||||
*/
|
||||
public static boolean isAppHibernationEnabled() {
|
||||
return sIsServiceEnabled;
|
||||
}
|
||||
|
||||
private static boolean isDeviceConfigAppHibernationEnabled() {
|
||||
return DeviceConfig.getBoolean(
|
||||
NAMESPACE_APP_HIBERNATION,
|
||||
KEY_APP_HIBERNATION_ENABLED,
|
||||
|
||||
@@ -167,7 +167,6 @@ class ActivityMetricsLogger {
|
||||
@VisibleForTesting static final int LAUNCH_OBSERVER_ACTIVITY_RECORD_PROTO_CHUNK_SIZE = 512;
|
||||
private final ArrayMap<String, Boolean> mLastHibernationStates = new ArrayMap<>();
|
||||
private AppHibernationManagerInternal mAppHibernationManagerInternal;
|
||||
private boolean mIsAppHibernationEnabled;
|
||||
|
||||
/**
|
||||
* The information created when an intent is incoming but we do not yet know whether it will be
|
||||
@@ -796,8 +795,8 @@ class ActivityMetricsLogger {
|
||||
|
||||
@Nullable
|
||||
private AppHibernationManagerInternal getAppHibernationManagerInternal() {
|
||||
if (!AppHibernationService.isAppHibernationEnabled()) return null;
|
||||
if (mAppHibernationManagerInternal == null) {
|
||||
mIsAppHibernationEnabled = AppHibernationService.isAppHibernationEnabled();
|
||||
mAppHibernationManagerInternal =
|
||||
LocalServices.getService(AppHibernationManagerInternal.class);
|
||||
}
|
||||
@@ -810,7 +809,7 @@ class ActivityMetricsLogger {
|
||||
*/
|
||||
void notifyBeforePackageUnstopped(@NonNull String packageName) {
|
||||
final AppHibernationManagerInternal ahmInternal = getAppHibernationManagerInternal();
|
||||
if (ahmInternal != null && mIsAppHibernationEnabled) {
|
||||
if (ahmInternal != null) {
|
||||
mLastHibernationStates.put(packageName, ahmInternal.isHibernatingGlobally(packageName));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ public final class AppHibernationServiceTest {
|
||||
doReturn(true).when(mUserManager).isUserUnlockingOrUnlocked(USER_ID_1);
|
||||
mAppHibernationService.onUserUnlocking(new SystemService.TargetUser(userInfo));
|
||||
|
||||
mAppHibernationService.mIsServiceEnabled = true;
|
||||
mAppHibernationService.sIsServiceEnabled = true;
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user