Don't log on each call when hibernation not enabled
Don't spam log when hibernation is not enabled. Instead, we log once
when we determine the hibernation enable state has changed.
Also add enablement check on new hibernation stats API.
Bug: 216621450
Test: manual
Change-Id: Id023f8ec97f243ad016ca7f8ad5515b05c0f8000
(cherry picked from commit 5e1fc99040)
(cherry picked from commit b580eccca58104b977033f8e1ab369a114de8e3c)
Merged-In: Id023f8ec97f243ad016ca7f8ad5515b05c0f8000
This commit is contained in:
committed by
Cherrypicker Worker
parent
7330f43464
commit
9eba2b4095
@@ -208,7 +208,7 @@ public final class AppHibernationService extends SystemService {
|
||||
*/
|
||||
boolean isHibernatingForUser(String packageName, int userId) {
|
||||
String methodName = "isHibernatingForUser";
|
||||
if (!checkHibernationEnabled(methodName)) {
|
||||
if (!sIsServiceEnabled) {
|
||||
return false;
|
||||
}
|
||||
getContext().enforceCallingOrSelfPermission(
|
||||
@@ -237,7 +237,7 @@ public final class AppHibernationService extends SystemService {
|
||||
* @param packageName package to check
|
||||
*/
|
||||
boolean isHibernatingGlobally(String packageName) {
|
||||
if (!checkHibernationEnabled("isHibernatingGlobally")) {
|
||||
if (!sIsServiceEnabled) {
|
||||
return false;
|
||||
}
|
||||
getContext().enforceCallingOrSelfPermission(
|
||||
@@ -263,7 +263,7 @@ public final class AppHibernationService extends SystemService {
|
||||
*/
|
||||
void setHibernatingForUser(String packageName, int userId, boolean isHibernating) {
|
||||
String methodName = "setHibernatingForUser";
|
||||
if (!checkHibernationEnabled(methodName)) {
|
||||
if (!sIsServiceEnabled) {
|
||||
return;
|
||||
}
|
||||
getContext().enforceCallingOrSelfPermission(
|
||||
@@ -313,7 +313,7 @@ public final class AppHibernationService extends SystemService {
|
||||
* @param isHibernating new hibernation state
|
||||
*/
|
||||
void setHibernatingGlobally(String packageName, boolean isHibernating) {
|
||||
if (!checkHibernationEnabled("setHibernatingGlobally")) {
|
||||
if (!sIsServiceEnabled) {
|
||||
return;
|
||||
}
|
||||
getContext().enforceCallingOrSelfPermission(
|
||||
@@ -344,7 +344,7 @@ public final class AppHibernationService extends SystemService {
|
||||
@NonNull List<String> getHibernatingPackagesForUser(int userId) {
|
||||
ArrayList<String> hibernatingPackages = new ArrayList<>();
|
||||
String methodName = "getHibernatingPackagesForUser";
|
||||
if (!checkHibernationEnabled(methodName)) {
|
||||
if (!sIsServiceEnabled) {
|
||||
return hibernatingPackages;
|
||||
}
|
||||
getContext().enforceCallingOrSelfPermission(
|
||||
@@ -640,6 +640,7 @@ public final class AppHibernationService extends SystemService {
|
||||
for (String key : properties.getKeyset()) {
|
||||
if (TextUtils.equals(KEY_APP_HIBERNATION_ENABLED, key)) {
|
||||
sIsServiceEnabled = isDeviceConfigAppHibernationEnabled();
|
||||
Slog.d(TAG, "App hibernation changed to enabled=" + sIsServiceEnabled);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -676,13 +677,6 @@ public final class AppHibernationService extends SystemService {
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean checkHibernationEnabled(String methodName) {
|
||||
if (!sIsServiceEnabled) {
|
||||
Slog.w(TAG, String.format("Attempted to call %s on unsupported device.", methodName));
|
||||
}
|
||||
return sIsServiceEnabled;
|
||||
}
|
||||
|
||||
private void dump(PrintWriter pw) {
|
||||
// Check usage stats permission since hibernation indirectly informs usage.
|
||||
if (!DumpUtils.checkDumpAndUsageStatsPermission(getContext(), TAG, pw)) return;
|
||||
|
||||
Reference in New Issue
Block a user