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

Commit 733cc292 authored by Nilesh Poddar's avatar Nilesh Poddar Committed by Steve Kondik
Browse files

Fix alarm wakelock not being released.

Alarm wakelock was not released when the pending intent was served
by the package with a uid not the same as the one which created the
alarm.
Remove advanced for loop from PowerManagerService since the list is
modified during iteration and thus resulting to
ConcurrentModificationException error

Change-Id: I4e2ff1f4be1ad044aa350886a3ea69ee5a576f74
CRs-Fixed: 591170
CRs-Fixed: 591511
parent ac31b1a0
Loading
Loading
Loading
Loading
+10 −16
Original line number Diff line number Diff line
@@ -438,8 +438,10 @@ class AlarmManagerService extends IAlarmManager.Stub {
        final Pair<String, ComponentName> mTarget;
        final BroadcastStats mBroadcastStats;
        final FilterStats mFilterStats;
        final int mUid;

        InFlight(AlarmManagerService service, PendingIntent pendingIntent, WorkSource workSource) {
        InFlight(AlarmManagerService service, PendingIntent pendingIntent,
                      WorkSource workSource, int uid) {
            mPendingIntent = pendingIntent;
            mWorkSource = workSource;
            Intent intent = pendingIntent.getIntent();
@@ -453,6 +455,7 @@ class AlarmManagerService extends IAlarmManager.Stub {
                mBroadcastStats.filterStats.put(mTarget, fs);
            }
            mFilterStats = fs;
            mUid = uid;
        }
    }

@@ -1330,7 +1333,7 @@ class AlarmManagerService extends IAlarmManager.Stub {
                                mWakeLock.acquire();
                            }
                            final InFlight inflight = new InFlight(AlarmManagerService.this,
                                    alarm.operation, alarm.workSource);
                                    alarm.operation, alarm.workSource, alarm.uid);
                            mInFlight.add(inflight);
                            mBroadcastRefCount++;
                            mTriggeredUids.add(new Integer(alarm.uid));
@@ -1559,9 +1562,11 @@ class AlarmManagerService extends IAlarmManager.Stub {
        public void onSendFinished(PendingIntent pi, Intent intent, int resultCode,
                String resultData, Bundle resultExtras) {
            synchronized (mLock) {
                int uid = 0;
                InFlight inflight = null;
                for (int i=0; i<mInFlight.size(); i++) {
                    if (mInFlight.get(i).mPendingIntent == pi) {
                        uid = mInFlight.get(i).mUid;
                        inflight = mInFlight.remove(i);
                        break;
                    }
@@ -1583,18 +1588,7 @@ class AlarmManagerService extends IAlarmManager.Stub {
                } else {
                    mLog.w("No in-flight alarm for " + pi + " " + intent);
                }
                String pkg = null;
                int uid = 0;
                try {
                    pkg = pi.getTargetPackage();
                    final PackageManager pm = mContext.getPackageManager();
                    ApplicationInfo appInfo =
                        pm.getApplicationInfo(pkg, PackageManager.GET_META_DATA);
                    uid = appInfo.uid;
                mTriggeredUids.remove(new Integer(uid));
                } catch (PackageManager.NameNotFoundException ex) {
                    Slog.w(TAG, "onSendFinished NameNotFoundException Pkg = " + pkg);
                }
                if(mBlockedUids.contains(new Integer(uid))) {
                    mBlockedUids.remove(new Integer(uid));
                } else {
+3 −1
Original line number Diff line number Diff line
@@ -913,11 +913,13 @@ public final class PowerManagerService extends IPowerManager.Stub
            if (DEBUG_SPEW) Slog.v(TAG, "updateBlockedUids: uid = "+uid +"isBlocked = "+isBlocked);
            if(isBlocked) {
                mBlockedUids.add(new Integer(uid));
                for (WakeLock wl : mWakeLocks) {
                for (int index = 0; index < mWakeLocks.size(); index++) {
                    WakeLock wl = mWakeLocks.get(index);
                    if(wl != null) {
                        // release the wakelock for the blocked uid
                        if (wl.mOwnerUid == uid || checkWorkSourceObjectId(uid, wl)) {
                            releaseWakeLockInternal(wl.mLock, wl.mFlags);
                            index--;
                            if (DEBUG_SPEW) Slog.v(TAG, "Internally releasing it");
                        }
                    }