summaryrefslogtreecommitdiff
path: root/services/core
diff options
context:
space:
mode:
authorKevin Han <kevhan@google.com>2021-03-20 01:37:29 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2021-03-20 01:37:29 +0000
commit4dfa5f8db4dfe13591c76c1526277c8a2ef08a8d (patch)
tree66dc4388da1367ee59fe828cb37df8c84f6d1e04 /services/core
parent64e333a2501c191a50bd14eb3bfbae0f9b3ebddb (diff)
parentf0df72a9c7268c2bde7443dfde708ab895e2bf30 (diff)
Merge changes from topic "app_hibernation_permission"
* changes: Add API to get hibernating packages Add MANAGE_APP_HIBERNATION permission
Diffstat (limited to 'services/core')
-rw-r--r--services/core/java/com/android/server/apphibernation/AppHibernationService.java47
1 files changed, 46 insertions, 1 deletions
diff --git a/services/core/java/com/android/server/apphibernation/AppHibernationService.java b/services/core/java/com/android/server/apphibernation/AppHibernationService.java
index 968cf5f1df91..b3373d0bb536 100644
--- a/services/core/java/com/android/server/apphibernation/AppHibernationService.java
+++ b/services/core/java/com/android/server/apphibernation/AppHibernationService.java
@@ -173,7 +173,9 @@ public final class AppHibernationService extends SystemService {
if (!checkHibernationEnabled("isHibernatingForUser")) {
return false;
}
-
+ getContext().enforceCallingOrSelfPermission(
+ android.Manifest.permission.MANAGE_APP_HIBERNATION,
+ "Caller does not have MANAGE_APP_HIBERNATION permission.");
userId = handleIncomingUser(userId, "isHibernating");
if (!mUserManager.isUserUnlockingOrUnlocked(userId)) {
Slog.e(TAG, "Attempt to get hibernation state of stopped or nonexistent user "
@@ -202,6 +204,9 @@ public final class AppHibernationService extends SystemService {
if (!checkHibernationEnabled("isHibernatingGlobally")) {
return false;
}
+ getContext().enforceCallingOrSelfPermission(
+ android.Manifest.permission.MANAGE_APP_HIBERNATION,
+ "Caller does not have MANAGE_APP_HIBERNATION permission.");
synchronized (mLock) {
GlobalLevelState state = mGlobalHibernationStates.get(packageName);
if (state == null) {
@@ -223,6 +228,9 @@ public final class AppHibernationService extends SystemService {
if (!checkHibernationEnabled("setHibernatingForUser")) {
return;
}
+ getContext().enforceCallingOrSelfPermission(
+ android.Manifest.permission.MANAGE_APP_HIBERNATION,
+ "Caller does not have MANAGE_APP_HIBERNATION permission.");
userId = handleIncomingUser(userId, "setHibernating");
if (!mUserManager.isUserUnlockingOrUnlocked(userId)) {
Slog.w(TAG, "Attempt to set hibernation state for a stopped or nonexistent user "
@@ -263,6 +271,9 @@ public final class AppHibernationService extends SystemService {
if (!checkHibernationEnabled("setHibernatingGlobally")) {
return;
}
+ getContext().enforceCallingOrSelfPermission(
+ android.Manifest.permission.MANAGE_APP_HIBERNATION,
+ "Caller does not have MANAGE_APP_HIBERNATION permission.");
synchronized (mLock) {
GlobalLevelState state = mGlobalHibernationStates.get(packageName);
if (state == null) {
@@ -282,6 +293,35 @@ public final class AppHibernationService extends SystemService {
}
/**
+ * Get the hibernating packages for the given user. This is equivalent to the list of
+ * packages for the user that return true for {@link #isHibernatingForUser}.
+ */
+ @NonNull List<String> getHibernatingPackagesForUser(int userId) {
+ ArrayList<String> hibernatingPackages = new ArrayList<>();
+ if (!checkHibernationEnabled("getHibernatingPackagesForUser")) {
+ return hibernatingPackages;
+ }
+ getContext().enforceCallingOrSelfPermission(
+ android.Manifest.permission.MANAGE_APP_HIBERNATION,
+ "Caller does not have MANAGE_APP_HIBERNATION permission.");
+ userId = handleIncomingUser(userId, "getHibernatingPackagesForUser");
+ if (!mUserManager.isUserUnlockingOrUnlocked(userId)) {
+ Slog.w(TAG, "Attempt to get hibernating packages for a stopped or nonexistent user "
+ + userId);
+ return hibernatingPackages;
+ }
+ synchronized (mLock) {
+ Map<String, UserLevelState> userStates = mUserStates.get(userId);
+ for (UserLevelState state : userStates.values()) {
+ if (state.hibernated) {
+ hibernatingPackages.add(state.packageName);
+ }
+ }
+ return hibernatingPackages;
+ }
+ }
+
+ /**
* Put an app into hibernation for a given user, allowing user-level optimizations to occur.
*
* @param pkgState package hibernation state
@@ -608,6 +648,11 @@ public final class AppHibernationService extends SystemService {
}
@Override
+ public List<String> getHibernatingPackagesForUser(int userId) {
+ return mService.getHibernatingPackagesForUser(userId);
+ }
+
+ @Override
public void onShellCommand(@Nullable FileDescriptor in, @Nullable FileDescriptor out,
@Nullable FileDescriptor err, @NonNull String[] args,
@Nullable ShellCallback callback, @NonNull ResultReceiver resultReceiver) {