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

Commit e5524f86 authored by Aishwarya Mallampati's avatar Aishwarya Mallampati Committed by Android (Google) Code Review
Browse files

Merge "send request immediately to handler" into main

parents d89720db d3034595
Loading
Loading
Loading
Loading
+57 −1
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ import android.util.Log;
import com.android.internal.R;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.os.SomeArgs;
import com.android.internal.telephony.flags.FeatureFlags;

import java.util.ArrayList;
@@ -58,11 +59,14 @@ import java.util.function.Consumer;
/**
 * PointingApp controller to manage interactions with PointingUI app.
 */
public class PointingAppController {
public class PointingAppController extends Handler {
    private static final String TAG = "PointingAppController";
    private static final String ALLOW_MOCK_MODEM_PROPERTY = "persist.radio.allow_mock_modem";
    private static final boolean DEBUG = !"user".equals(Build.TYPE);

    private static final int REQUEST_START_POINTING_UI = 1;
    private static final int REQUEST_REMOVE_LISTENER_FOR_POINTING_UI = 2;

    @NonNull
    private static PointingAppController sInstance;
    @NonNull private final Context mContext;
@@ -125,6 +129,34 @@ public class PointingAppController {
        mPersistentLogger = SatelliteServiceUtils.getPersistentLogger(context);
    }

    @Override
    public void handleMessage(Message msg) {
        switch (msg.what) {
            case REQUEST_START_POINTING_UI: {
                plogd("REQUEST_START_POINTING_UI");
                SomeArgs args = (SomeArgs) msg.obj;
                boolean needFullScreenPointingUI = (boolean) args.arg1;
                boolean isDemoMode = (boolean) args.arg2;
                boolean isEmergency = (boolean) args.arg3;
                try {
                    handleRequestStartPointingUI(needFullScreenPointingUI, isDemoMode, isEmergency);
                } finally {
                    args.recycle();
                }
                break;
            }

            case REQUEST_REMOVE_LISTENER_FOR_POINTING_UI: {
                handleRequestRemoveListenerForPointingUI();
                break;
            }

            default:
                ploge("PointingAppControllerHandler: unexpected message code: " + msg.what);
                break;
        }
    }

    /**
     * Set the flag mStartedSatelliteTransmissionUpdates to true or false based on the state of
     * transmission updates
@@ -390,6 +422,20 @@ public class PointingAppController {
     */
    public void startPointingUI(boolean needFullScreenPointingUI, boolean isDemoMode,
            boolean isEmergency) {
        if (mFeatureFlags.satelliteImproveMultiThreadDesign()) {
            SomeArgs args = SomeArgs.obtain();
            args.arg1 = needFullScreenPointingUI;
            args.arg2 = isDemoMode;
            args.arg3 = isEmergency;
            sendMessage(obtainMessage(REQUEST_START_POINTING_UI, args));
            return;
        }

        handleRequestStartPointingUI(needFullScreenPointingUI, isDemoMode, isEmergency);
    }

    private void handleRequestStartPointingUI(boolean needFullScreenPointingUI, boolean isDemoMode,
            boolean isEmergency) {
        String packageName = getPointingUiPackageName();
        if (TextUtils.isEmpty(packageName)) {
            plogd("startPointingUI: config_pointing_ui_package is not set. Ignore the request");
@@ -437,6 +483,16 @@ public class PointingAppController {
     * Remove the Importance Listener For Pointing UI App once the satellite is disabled
     */
    public void removeListenerForPointingUI() {
        if (mFeatureFlags.satelliteImproveMultiThreadDesign()) {
            sendMessage(obtainMessage(REQUEST_REMOVE_LISTENER_FOR_POINTING_UI));
            return;
        }

        handleRequestRemoveListenerForPointingUI();
    }

    private void handleRequestRemoveListenerForPointingUI() {
        plogd("handleRequestRemoveListenerForPointingUI");
        synchronized (mListenerForPointingUIRegisteredLock) {
            if (mListenerForPointingUIRegistered) {
                mActivityManager.removeOnUidImportanceListener(mUidImportanceListener);
+4 −0
Original line number Diff line number Diff line
@@ -322,6 +322,7 @@ public class PointingAppControllerTest extends TelephonyTest {
    public void testStartPointingUI() throws Exception {
        ArgumentCaptor<Intent> startedIntentCaptor = ArgumentCaptor.forClass(Intent.class);
        mPointingAppController.startPointingUI(true, true, true);
        processAllMessages();
        verify(mContext).startActivityAsUser(startedIntentCaptor.capture(), eq(UserHandle.CURRENT));
        Intent intent = startedIntentCaptor.getValue();
        assertEquals(KEY_POINTING_UI_PACKAGE_NAME, intent.getComponent().getPackageName());
@@ -338,10 +339,12 @@ public class PointingAppControllerTest extends TelephonyTest {
    @Test
    public void testRestartPointingUi() throws Exception {
        mPointingAppController.startPointingUI(true, false, true);
        processAllMessages();
        mInOrderForPointingUi.verify(mContext).startActivityAsUser(any(Intent.class),
                eq(UserHandle.CURRENT));
        testRestartPointingUi(true, false, true);
        mPointingAppController.startPointingUI(false, true, false);
        processAllMessages();
        mInOrderForPointingUi.verify(mContext).startActivityAsUser(any(Intent.class),
                eq(UserHandle.CURRENT));
        testRestartPointingUi(false, true, false);
@@ -353,6 +356,7 @@ public class PointingAppControllerTest extends TelephonyTest {
        doReturn(new String[]{KEY_POINTING_UI_PACKAGE_NAME}).when(mPackageManager)
            .getPackagesForUid(anyInt());
        mPointingAppController.mUidImportanceListener.onUidImportance(1, IMPORTANCE_GONE);
        processAllMessages();
        ArgumentCaptor<Intent> restartedIntentCaptor = ArgumentCaptor.forClass(Intent.class);
        mInOrderForPointingUi.verify(mContext).startActivityAsUser(restartedIntentCaptor.capture(),
                eq(UserHandle.CURRENT));