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

Commit 4afb1946 authored by Sudheer Shanka's avatar Sudheer Shanka Committed by Automerger Merge Worker
Browse files

Merge "Handle uid state changes on the handler thread." into udc-qpr-dev am: ae3fcf13

parents b8bf6be8 ae3fcf13
Loading
Loading
Loading
Loading
+18 −9
Original line number Original line Diff line number Diff line
@@ -249,6 +249,7 @@ class BroadcastQueueModernImpl extends BroadcastQueue {
    private static final int MSG_CHECK_HEALTH = 5;
    private static final int MSG_CHECK_HEALTH = 5;
    private static final int MSG_CHECK_PENDING_COLD_START_VALIDITY = 6;
    private static final int MSG_CHECK_PENDING_COLD_START_VALIDITY = 6;
    private static final int MSG_PROCESS_FREEZABLE_CHANGED = 7;
    private static final int MSG_PROCESS_FREEZABLE_CHANGED = 7;
    private static final int MSG_UID_STATE_CHANGED = 8;


    private void enqueueUpdateRunningList() {
    private void enqueueUpdateRunningList() {
        mLocalHandler.removeMessages(MSG_UPDATE_RUNNING_LIST);
        mLocalHandler.removeMessages(MSG_UPDATE_RUNNING_LIST);
@@ -295,6 +296,19 @@ class BroadcastQueueModernImpl extends BroadcastQueue {
                }
                }
                return true;
                return true;
            }
            }
            case MSG_UID_STATE_CHANGED: {
                final int uid = (int) msg.obj;
                final int procState = msg.arg1;
                synchronized (mService) {
                    if (procState == ActivityManager.PROCESS_STATE_TOP) {
                        mUidForeground.put(uid, true);
                    } else {
                        mUidForeground.delete(uid);
                    }
                    refreshProcessQueuesLocked(uid);
                }
                return true;
            }
        }
        }
        return false;
        return false;
    };
    };
@@ -672,7 +686,7 @@ class BroadcastQueueModernImpl extends BroadcastQueue {
    @Override
    @Override
    public void onProcessFreezableChangedLocked(@NonNull ProcessRecord app) {
    public void onProcessFreezableChangedLocked(@NonNull ProcessRecord app) {
        mLocalHandler.removeMessages(MSG_PROCESS_FREEZABLE_CHANGED, app);
        mLocalHandler.removeMessages(MSG_PROCESS_FREEZABLE_CHANGED, app);
        mLocalHandler.sendMessage(mHandler.obtainMessage(MSG_PROCESS_FREEZABLE_CHANGED, app));
        mLocalHandler.obtainMessage(MSG_PROCESS_FREEZABLE_CHANGED, app).sendToTarget();
    }
    }


    @Override
    @Override
@@ -1601,14 +1615,9 @@ class BroadcastQueueModernImpl extends BroadcastQueue {
            @Override
            @Override
            public void onUidStateChanged(int uid, int procState, long procStateSeq,
            public void onUidStateChanged(int uid, int procState, long procStateSeq,
                    int capability) {
                    int capability) {
                synchronized (mService) {
                mLocalHandler.removeMessages(MSG_UID_STATE_CHANGED, uid);
                    if (procState == ActivityManager.PROCESS_STATE_TOP) {
                mLocalHandler.obtainMessage(MSG_UID_STATE_CHANGED, procState, 0, uid)
                        mUidForeground.put(uid, true);
                        .sendToTarget();
                    } else {
                        mUidForeground.delete(uid);
                    }
                    refreshProcessQueuesLocked(uid);
                }
            }
            }
        }, ActivityManager.UID_OBSERVER_PROCSTATE,
        }, ActivityManager.UID_OBSERVER_PROCSTATE,
                ActivityManager.PROCESS_STATE_TOP, "android");
                ActivityManager.PROCESS_STATE_TOP, "android");
+6 −0
Original line number Original line Diff line number Diff line
@@ -125,6 +125,7 @@ import java.util.List;
import java.util.Map;
import java.util.Map;
import java.util.Objects;
import java.util.Objects;
import java.util.Set;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.UnaryOperator;
import java.util.function.UnaryOperator;
@@ -707,6 +708,9 @@ public class BroadcastQueueTest {
    private void waitForIdle() throws Exception {
    private void waitForIdle() throws Exception {
        mLooper.release();
        mLooper.release();
        mQueue.waitForIdle(LOG_WRITER_INFO);
        mQueue.waitForIdle(LOG_WRITER_INFO);
        final CountDownLatch latch = new CountDownLatch(1);
        mHandlerThread.getThreadHandler().post(latch::countDown);
        latch.await();
        mLooper = Objects.requireNonNull(InstrumentationRegistry.getInstrumentation()
        mLooper = Objects.requireNonNull(InstrumentationRegistry.getInstrumentation()
                .acquireLooperManager(mHandlerThread.getLooper()));
                .acquireLooperManager(mHandlerThread.getLooper()));
    }
    }
@@ -2342,6 +2346,7 @@ public class BroadcastQueueTest {


        mUidObserver.onUidStateChanged(receiverGreenApp.info.uid,
        mUidObserver.onUidStateChanged(receiverGreenApp.info.uid,
                ActivityManager.PROCESS_STATE_TOP, 0, ActivityManager.PROCESS_CAPABILITY_NONE);
                ActivityManager.PROCESS_STATE_TOP, 0, ActivityManager.PROCESS_CAPABILITY_NONE);
        waitForIdle();


        final Intent airplane = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
        final Intent airplane = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
        final Intent timeTick = new Intent(Intent.ACTION_TIME_TICK);
        final Intent timeTick = new Intent(Intent.ACTION_TIME_TICK);
@@ -2375,6 +2380,7 @@ public class BroadcastQueueTest {


        mUidObserver.onUidStateChanged(receiverGreenApp.info.uid,
        mUidObserver.onUidStateChanged(receiverGreenApp.info.uid,
                ActivityManager.PROCESS_STATE_TOP, 0, ActivityManager.PROCESS_CAPABILITY_NONE);
                ActivityManager.PROCESS_STATE_TOP, 0, ActivityManager.PROCESS_CAPABILITY_NONE);
        waitForIdle();


        final Intent timeTick = new Intent(Intent.ACTION_TIME_TICK);
        final Intent timeTick = new Intent(Intent.ACTION_TIME_TICK);