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

Commit 54150c99 authored by Tsung-Mao Fang's avatar Tsung-Mao Fang
Browse files

Support another new intent for mainline module intent

Mainline module team would like to create a new intent to support v2 UX.
In Settings side, if we found system supports this intent,
then we should navigate user to new place.

Test: Run robo test
Fix: 151189987
Change-Id: If4b437236b70c83a1f29a5c3d9e322178c8a6ec6
parent 79a38a73
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
@@ -47,6 +47,10 @@ public class MainlineModuleVersionPreferenceController extends BasePreferenceCon
    @VisibleForTesting
    static final Intent MODULE_UPDATE_INTENT =
            new Intent("android.settings.MODULE_UPDATE_SETTINGS");
    @VisibleForTesting
    static final Intent MODULE_UPDATE_V2_INTENT =
            new Intent("android.settings.MODULE_UPDATE_VERSIONS");

    private final PackageManager mPackageManager;

    private String mModuleVersion;
@@ -81,7 +85,14 @@ public class MainlineModuleVersionPreferenceController extends BasePreferenceCon
    public void updateState(Preference preference) {
        super.updateState(preference);

        // Confirm MODULE_UPDATE_INTENT is handleable, and set it to Preference.
        final ResolveInfo resolvedV2 =
                mPackageManager.resolveActivity(MODULE_UPDATE_V2_INTENT, 0 /* flags */);
        if (resolvedV2 != null) {
            preference.setIntent(MODULE_UPDATE_V2_INTENT);
            preference.setSelectable(true);
            return;
        }

        final ResolveInfo resolved =
                mPackageManager.resolveActivity(MODULE_UPDATE_INTENT, 0 /* flags */);
        if (resolved != null) {
+32 −3
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.settings.deviceinfo.firmwareversion;
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
import static com.android.settings.deviceinfo.firmwareversion.MainlineModuleVersionPreferenceController.MODULE_UPDATE_INTENT;
import static com.android.settings.deviceinfo.firmwareversion.MainlineModuleVersionPreferenceController.MODULE_UPDATE_V2_INTENT;

import static com.google.common.truth.Truth.assertThat;

@@ -97,7 +98,33 @@ public class MainlineModuleVersionPreferenceControllerTest {
    }

    @Test
    public void updateStates_canHandleIntent_setIntentToPreference() throws Exception {
    public void updateState_canHandleV2Intent_setIntentToPreference() throws Exception {
        setupModulePackage("test version 123");
        when(mPackageManager.resolveActivity(MODULE_UPDATE_V2_INTENT, 0))
                .thenReturn(new ResolveInfo());
        final MainlineModuleVersionPreferenceController controller =
                new MainlineModuleVersionPreferenceController(mContext, "key");

        controller.updateState(mPreference);

        assertThat(mPreference.getIntent()).isEqualTo(MODULE_UPDATE_V2_INTENT);
    }

    @Test
    public void updateState_canHandleV2Intent_preferenceShouldBeSelectable() throws Exception {
        setupModulePackage("test version 123");
        when(mPackageManager.resolveActivity(MODULE_UPDATE_V2_INTENT, 0))
                .thenReturn(new ResolveInfo());
        final MainlineModuleVersionPreferenceController controller =
                new MainlineModuleVersionPreferenceController(mContext, "key");

        controller.updateState(mPreference);

        assertThat(mPreference.isSelectable()).isTrue();
    }

    @Test
    public void updateState_canHandleIntent_setIntentToPreference() throws Exception {
        setupModulePackage("test version 123");
        when(mPackageManager.resolveActivity(MODULE_UPDATE_INTENT, 0))
                .thenReturn(new ResolveInfo());
@@ -111,7 +138,7 @@ public class MainlineModuleVersionPreferenceControllerTest {
    }

    @Test
    public void updateStates_canHandleIntent_preferenceShouldBeSelectable() throws Exception {
    public void updateState_canHandleIntent_preferenceShouldBeSelectable() throws Exception {
        setupModulePackage("test version 123");
        when(mPackageManager.resolveActivity(MODULE_UPDATE_INTENT, 0))
                .thenReturn(new ResolveInfo());
@@ -125,10 +152,12 @@ public class MainlineModuleVersionPreferenceControllerTest {
    }

    @Test
    public void updateStates_cannotHandleIntent_setNullToPreference() throws Exception {
    public void updateState_cannotHandleIntent_setNullToPreference() throws Exception {
        setupModulePackage("test version 123");
        when(mPackageManager.resolveActivity(MODULE_UPDATE_INTENT, 0))
                .thenReturn(null);
        when(mPackageManager.resolveActivity(MODULE_UPDATE_V2_INTENT, 0))
                .thenReturn(null);

        final MainlineModuleVersionPreferenceController controller =
                new MainlineModuleVersionPreferenceController(mContext, "key");