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

Commit fb818c51 authored by Thomas Vannet's avatar Thomas Vannet
Browse files

Catch exception when stopping OTP session twice

An uncaught IllegalArgumentException thrown in
ActivityManager.removeOnUidImportanceListener would result in a one-time
permission session for a background group sometimes not getting cleaned
up properly, leading to background permissions not geting revoked.

Test: run cts -m CtsPermissionTestCases -t
android.permission.cts.RevokeSelfPermissionTest
Bug: 225386829

Change-Id: Iad7f181866b407d556672457ade1f3312d10a95d
parent 017ebacd
Loading
Loading
Loading
Loading
+15 −3
Original line number Diff line number Diff line
@@ -317,9 +317,21 @@ public class OneTimePermissionUserManager {
            synchronized (mInnerLock) {
                mIsFinished = true;
                cancelAlarmLocked();
                try {
                    mActivityManager.removeOnUidImportanceListener(mStartTimerListener);
                } catch (IllegalArgumentException e) {
                    Log.e(LOG_TAG, "Could not remove start timer listener", e);
                }
                try {
                    mActivityManager.removeOnUidImportanceListener(mSessionKillableListener);
                } catch (IllegalArgumentException e) {
                    Log.e(LOG_TAG, "Could not remove session killable listener", e);
                }
                try {
                    mActivityManager.removeOnUidImportanceListener(mGoneListener);
                } catch (IllegalArgumentException e) {
                    Log.e(LOG_TAG, "Could not remove gone listener", e);
                }
            }
        }