Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 51ad2f17 authored by Kevin Han's avatar Kevin Han Committed by Android (Google) Code Review
Browse files

Merge "Fix app hibernation spammy logging"

parents be992eb1 faad4a7d
Loading
Loading
Loading
Loading
+20 −14
Original line number Original line Diff line number Diff line
@@ -230,7 +230,9 @@ public final class AppHibernationService extends SystemService {
                "Caller did not have permission while calling " + methodName);
                "Caller did not have permission while calling " + methodName);
        userId = handleIncomingUser(userId, methodName);
        userId = handleIncomingUser(userId, methodName);
        synchronized (mLock) {
        synchronized (mLock) {
            if (!checkUserStatesExist(userId, methodName)) {
            // Don't log as this method can be called before user states exist as part of the
            // force-stop check.
            if (!checkUserStatesExist(userId, methodName, /* shouldLog= */ false)) {
                return false;
                return false;
            }
            }
            final Map<String, UserLevelState> packageStates = mUserStates.get(userId);
            final Map<String, UserLevelState> packageStates = mUserStates.get(userId);
@@ -238,8 +240,6 @@ public final class AppHibernationService extends SystemService {
            if (pkgState == null
            if (pkgState == null
                    || !mPackageManagerInternal.canQueryPackage(
                    || !mPackageManagerInternal.canQueryPackage(
                            Binder.getCallingUid(), packageName)) {
                            Binder.getCallingUid(), packageName)) {
                Slog.e(TAG, TextUtils.formatSimple("Package %s is not installed for user %s",
                        packageName, userId));
                return false;
                return false;
            }
            }
            return pkgState.hibernated;
            return pkgState.hibernated;
@@ -289,7 +289,7 @@ public final class AppHibernationService extends SystemService {
                "Caller does not have MANAGE_APP_HIBERNATION permission.");
                "Caller does not have MANAGE_APP_HIBERNATION permission.");
        final int realUserId = handleIncomingUser(userId, methodName);
        final int realUserId = handleIncomingUser(userId, methodName);
        synchronized (mLock) {
        synchronized (mLock) {
            if (!checkUserStatesExist(realUserId, methodName)) {
            if (!checkUserStatesExist(realUserId, methodName, /* shouldLog= */ true)) {
                return;
                return;
            }
            }
            final Map<String, UserLevelState> packageStates = mUserStates.get(realUserId);
            final Map<String, UserLevelState> packageStates = mUserStates.get(realUserId);
@@ -382,7 +382,7 @@ public final class AppHibernationService extends SystemService {
                "Caller does not have MANAGE_APP_HIBERNATION permission.");
                "Caller does not have MANAGE_APP_HIBERNATION permission.");
        userId = handleIncomingUser(userId, methodName);
        userId = handleIncomingUser(userId, methodName);
        synchronized (mLock) {
        synchronized (mLock) {
            if (!checkUserStatesExist(userId, methodName)) {
            if (!checkUserStatesExist(userId, methodName, /* shouldLog= */ true)) {
                return hibernatingPackages;
                return hibernatingPackages;
            }
            }
            Map<String, UserLevelState> userStates = mUserStates.get(userId);
            Map<String, UserLevelState> userStates = mUserStates.get(userId);
@@ -419,7 +419,7 @@ public final class AppHibernationService extends SystemService {
                "Caller does not have MANAGE_APP_HIBERNATION permission.");
                "Caller does not have MANAGE_APP_HIBERNATION permission.");
        userId = handleIncomingUser(userId, methodName);
        userId = handleIncomingUser(userId, methodName);
        synchronized (mLock) {
        synchronized (mLock) {
            if (!checkUserStatesExist(userId, methodName)) {
            if (!checkUserStatesExist(userId, methodName, /* shouldLog= */ true)) {
                return statsMap;
                return statsMap;
            }
            }
            final Map<String, UserLevelState> userPackageStates = mUserStates.get(userId);
            final Map<String, UserLevelState> userPackageStates = mUserStates.get(userId);
@@ -431,7 +431,7 @@ public final class AppHibernationService extends SystemService {
                }
                }
                if (!mGlobalHibernationStates.containsKey(pkgName)
                if (!mGlobalHibernationStates.containsKey(pkgName)
                        || !userPackageStates.containsKey(pkgName)) {
                        || !userPackageStates.containsKey(pkgName)) {
                    Slog.w(TAG, String.format(
                    Slog.w(TAG, TextUtils.formatSimple(
                            "No hibernation state associated with package %s user %d. Maybe"
                            "No hibernation state associated with package %s user %d. Maybe"
                                    + "the package was uninstalled? ", pkgName, userId));
                                    + "the package was uninstalled? ", pkgName, userId));
                    continue;
                    continue;
@@ -585,7 +585,7 @@ public final class AppHibernationService extends SystemService {
                PackageInfo pkgInfo = installedPackages.get(packageName);
                PackageInfo pkgInfo = installedPackages.get(packageName);
                UserLevelState currentState = diskStates.get(i);
                UserLevelState currentState = diskStates.get(i);
                if (pkgInfo == null) {
                if (pkgInfo == null) {
                    Slog.w(TAG, String.format(
                    Slog.w(TAG, TextUtils.formatSimple(
                            "No hibernation state associated with package %s user %d. Maybe"
                            "No hibernation state associated with package %s user %d. Maybe"
                                    + "the package was uninstalled? ", packageName, userId));
                                    + "the package was uninstalled? ", packageName, userId));
                    continue;
                    continue;
@@ -633,7 +633,7 @@ public final class AppHibernationService extends SystemService {
            for (int i = 0, size = diskStates.size(); i < size; i++) {
            for (int i = 0, size = diskStates.size(); i < size; i++) {
                GlobalLevelState state = diskStates.get(i);
                GlobalLevelState state = diskStates.get(i);
                if (!installedPackages.contains(state.packageName)) {
                if (!installedPackages.contains(state.packageName)) {
                    Slog.w(TAG, String.format(
                    Slog.w(TAG, TextUtils.formatSimple(
                            "No hibernation state associated with package %s. Maybe the "
                            "No hibernation state associated with package %s. Maybe the "
                                    + "package was uninstalled? ", state.packageName));
                                    + "package was uninstalled? ", state.packageName));
                    continue;
                    continue;
@@ -742,18 +742,24 @@ public final class AppHibernationService extends SystemService {
     *
     *
     * @param userId user to check
     * @param userId user to check
     * @param methodName method name that is calling. Used for logging purposes.
     * @param methodName method name that is calling. Used for logging purposes.
     * @param shouldLog whether we should log why the user state doesn't exist
     * @return true if user states exist
     * @return true if user states exist
     */
     */
    @GuardedBy("mLock")
    @GuardedBy("mLock")
    private boolean checkUserStatesExist(int userId, String methodName) {
    private boolean checkUserStatesExist(int userId, String methodName, boolean shouldLog) {
        if (!mUserManager.isUserUnlockingOrUnlocked(userId)) {
        if (!mUserManager.isUserUnlockingOrUnlocked(userId)) {
            Slog.e(TAG, String.format(
            if (shouldLog) {
                    "Attempt to call %s on stopped or nonexistent user %d", methodName, userId));
                Slog.w(TAG, TextUtils.formatSimple(
                        "Attempt to call %s on stopped or nonexistent user %d",
                        methodName, userId));
            }
            return false;
            return false;
        }
        }
        if (!mUserStates.contains(userId)) {
        if (!mUserStates.contains(userId)) {
            Slog.w(TAG, String.format(
            if (shouldLog) {
                Slog.w(TAG, TextUtils.formatSimple(
                        "Attempt to call %s before states have been read from disk", methodName));
                        "Attempt to call %s before states have been read from disk", methodName));
            }
            return false;
            return false;
        }
        }
        return true;
        return true;