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

Commit 072bc7d6 authored by panhaihui's avatar panhaihui Committed by Sudheer Shanka
Browse files

[Bugfix] avoid deadlock caused by AppBatteryTracker.dump



AppBatteryTracker.dump -> BaseAppStatePolicy.shouldExemptUid -> getBackgroundRestrictionExemptionReason -> getPotentialSystemExemptionReason -> isProfileOwner
Getting mlock first in AppBatteryTracker.dump() and then getting AMS lock in isProfileOwner() is an inappropriate lock order in the above call chain. This is inconsistent with the method of getting AMS lock first and then mlock lock in most method calls, so it will cause deadlock and cause watchdog.

Similar bug cases include 366150181, 358274041

Bug:366150181
Test: Manual test

Change-Id: I8a1b509a1e95ad8570f3d4c248f9e0ed346962ad
Signed-off-by: default avatarpanhaihui <panhaihui@xiaomi.com>
parent 71a4fd54
Loading
Loading
Loading
Loading
+15 −10
Original line number Diff line number Diff line
@@ -749,12 +749,14 @@ public class ActivityManagerService extends IActivityManager.Stub
    /**
     * Map userId to its companion app uids.
     */
    @GuardedBy("mCompanionAppUidsMap")
    private final Map<Integer, Set<Integer>> mCompanionAppUidsMap = new ArrayMap<>();
    /**
     * The profile owner UIDs.
     */
    private ArraySet<Integer> mProfileOwnerUids = null;
    @GuardedBy("mProfileOwnerUids")
    private final ArraySet<Integer> mProfileOwnerUids = new ArraySet<>();
    final UserController mUserController;
    @VisibleForTesting
@@ -19604,33 +19606,36 @@ public class ActivityManagerService extends IActivityManager.Stub
        @Override
        public void setProfileOwnerUid(ArraySet<Integer> profileOwnerUids) {
            synchronized (ActivityManagerService.this) {
                mProfileOwnerUids = profileOwnerUids;
            synchronized (mProfileOwnerUids) {
                mProfileOwnerUids.clear();
                mProfileOwnerUids.addAll(profileOwnerUids);
            }
        }
        @Override
        public boolean isProfileOwner(int uid) {
            synchronized (ActivityManagerService.this) {
                return mProfileOwnerUids != null && mProfileOwnerUids.indexOf(uid) >= 0;
            synchronized (mProfileOwnerUids) {
                return mProfileOwnerUids.indexOf(uid) >= 0;
            }
        }
        @Override
        public void setCompanionAppUids(int userId, Set<Integer> companionAppUids) {
            synchronized (ActivityManagerService.this) {
            synchronized (mCompanionAppUidsMap) {
                mCompanionAppUidsMap.put(userId, companionAppUids);
            }
        }
        @Override
        public boolean isAssociatedCompanionApp(int userId, int uid) {
            synchronized (mCompanionAppUidsMap) {
                final Set<Integer> allUids = mCompanionAppUidsMap.get(userId);
                if (allUids == null) {
                    return false;
                }
                return allUids.contains(uid);
            }
        }
        @Override
        public void addPendingTopUid(int uid, int pid, @Nullable IApplicationThread thread) {