Loading aconfig/settings_flag_declarations.aconfig +7 −0 Original line number Diff line number Diff line Loading @@ -6,3 +6,10 @@ flag { description: "This flag controls whether to show a Cancel button when factory reset" bug: "300634367" } flag { name: "mainline_module_explicit_intent" namespace: "android_settings" description: "Enabling will provide an explicit package name for Intent to update mainline modules" bug: "278987474" } res/values/config.xml 100755 → 100644 +3 −0 Original line number Diff line number Diff line Loading @@ -782,4 +782,7 @@ <item>@layout/screen_zoom_preview_1</item> <item>@layout/accessibility_text_reading_preview_mail_content</item> </array> <!-- Package responsible for updating Mainline Modules --> <string name="config_mainline_module_update_package" translatable="false">com.android.vending</string> </resources> src/com/android/settings/deviceinfo/firmwareversion/MainlineModuleVersionPreferenceController.java +19 −9 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ import androidx.annotation.VisibleForTesting; import androidx.preference.Preference; import com.android.settings.core.BasePreferenceController; import com.android.settings.flags.Flags; import java.text.ParseException; import java.text.SimpleDateFormat; Loading @@ -43,14 +44,15 @@ public class MainlineModuleVersionPreferenceController extends BasePreferenceCon private static final String TAG = "MainlineModuleControl"; private static final List<String> VERSION_NAME_DATE_PATTERNS = Arrays.asList("yyyy-MM-dd", "yyyy-MM"); @VisibleForTesting static final Intent MODULE_UPDATE_INTENT = new Intent("android.settings.MODULE_UPDATE_SETTINGS"); static final String MODULE_UPDATE_INTENT_ACTION = "android.settings.MODULE_UPDATE_SETTINGS"; @VisibleForTesting static final Intent MODULE_UPDATE_V2_INTENT = new Intent("android.settings.MODULE_UPDATE_VERSIONS"); static final String MODULE_UPDATE_V2_INTENT_ACTION = "android.settings.MODULE_UPDATE_VERSIONS"; private final Intent mModuleUpdateIntent; private final Intent mModuleUpdateV2Intent; private final PackageManager mPackageManager; private String mModuleVersion; Loading @@ -58,6 +60,14 @@ public class MainlineModuleVersionPreferenceController extends BasePreferenceCon public MainlineModuleVersionPreferenceController(Context context, String key) { super(context, key); mPackageManager = mContext.getPackageManager(); mModuleUpdateIntent = new Intent(MODULE_UPDATE_INTENT_ACTION); mModuleUpdateV2Intent = new Intent(MODULE_UPDATE_V2_INTENT_ACTION); if (Flags.mainlineModuleExplicitIntent()) { String packageName = mContext .getString(com.android.settings.R.string.config_mainline_module_update_package); mModuleUpdateIntent.setPackage(packageName); mModuleUpdateV2Intent.setPackage(packageName); } initModules(); } Loading Loading @@ -86,17 +96,17 @@ public class MainlineModuleVersionPreferenceController extends BasePreferenceCon super.updateState(preference); final ResolveInfo resolvedV2 = mPackageManager.resolveActivity(MODULE_UPDATE_V2_INTENT, 0 /* flags */); mPackageManager.resolveActivity(mModuleUpdateV2Intent, 0 /* flags */); if (resolvedV2 != null) { preference.setIntent(MODULE_UPDATE_V2_INTENT); preference.setIntent(mModuleUpdateV2Intent); preference.setSelectable(true); return; } final ResolveInfo resolved = mPackageManager.resolveActivity(MODULE_UPDATE_INTENT, 0 /* flags */); mPackageManager.resolveActivity(mModuleUpdateIntent, 0 /* flags */); if (resolved != null) { preference.setIntent(MODULE_UPDATE_INTENT); preference.setIntent(mModuleUpdateIntent); preference.setSelectable(true); } else { Log.d(TAG, "The ResolveInfo of the update intent is null."); Loading tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/MainlineModuleVersionPreferenceControllerTest.java +22 −2 Original line number Diff line number Diff line Loading @@ -18,8 +18,8 @@ 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.android.settings.deviceinfo.firmwareversion.MainlineModuleVersionPreferenceController.MODULE_UPDATE_INTENT_ACTION; import static com.android.settings.deviceinfo.firmwareversion.MainlineModuleVersionPreferenceController.MODULE_UPDATE_V2_INTENT_ACTION; import static com.google.common.truth.Truth.assertThat; Loading @@ -29,13 +29,18 @@ import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; import android.content.Context; import android.content.Intent; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.platform.test.annotations.RequiresFlagsEnabled; import android.platform.test.flag.junit.CheckFlagsRule; import android.platform.test.flag.junit.DeviceFlagsValueProvider; import androidx.preference.Preference; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; Loading @@ -46,6 +51,15 @@ import org.robolectric.RuntimeEnvironment; @RunWith(RobolectricTestRunner.class) public class MainlineModuleVersionPreferenceControllerTest { private static final String MODULE_PACKAGE = "com.android.vending"; private static final Intent MODULE_UPDATE_V2_INTENT = new Intent(MODULE_UPDATE_V2_INTENT_ACTION).setPackage(MODULE_PACKAGE); private static final Intent MODULE_UPDATE_INTENT = new Intent(MODULE_UPDATE_INTENT_ACTION).setPackage(MODULE_PACKAGE); @Rule public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule(); @Mock private PackageManager mPackageManager; Loading @@ -58,6 +72,9 @@ public class MainlineModuleVersionPreferenceControllerTest { mContext = spy(RuntimeEnvironment.application); mPreference = new Preference(mContext); when(mContext.getPackageManager()).thenReturn(mPackageManager); when(mContext .getString(com.android.settings.R.string.config_mainline_module_update_package)) .thenReturn(MODULE_PACKAGE); } @Test Loading Loading @@ -123,6 +140,7 @@ public class MainlineModuleVersionPreferenceControllerTest { assertThat(mPreference.isSelectable()).isTrue(); } @RequiresFlagsEnabled(com.android.settings.flags.Flags.FLAG_MAINLINE_MODULE_EXPLICIT_INTENT) @Test public void updateState_canHandleIntent_setIntentToPreference() throws Exception { setupModulePackage("test version 123"); Loading @@ -137,6 +155,7 @@ public class MainlineModuleVersionPreferenceControllerTest { assertThat(mPreference.getIntent()).isEqualTo(MODULE_UPDATE_INTENT); } @RequiresFlagsEnabled(com.android.settings.flags.Flags.FLAG_MAINLINE_MODULE_EXPLICIT_INTENT) @Test public void updateState_canHandleIntent_preferenceShouldBeSelectable() throws Exception { setupModulePackage("test version 123"); Loading @@ -151,6 +170,7 @@ public class MainlineModuleVersionPreferenceControllerTest { assertThat(mPreference.isSelectable()).isTrue(); } @RequiresFlagsEnabled(com.android.settings.flags.Flags.FLAG_MAINLINE_MODULE_EXPLICIT_INTENT) @Test public void updateState_cannotHandleIntent_setNullToPreference() throws Exception { setupModulePackage("test version 123"); Loading Loading
aconfig/settings_flag_declarations.aconfig +7 −0 Original line number Diff line number Diff line Loading @@ -6,3 +6,10 @@ flag { description: "This flag controls whether to show a Cancel button when factory reset" bug: "300634367" } flag { name: "mainline_module_explicit_intent" namespace: "android_settings" description: "Enabling will provide an explicit package name for Intent to update mainline modules" bug: "278987474" }
res/values/config.xml 100755 → 100644 +3 −0 Original line number Diff line number Diff line Loading @@ -782,4 +782,7 @@ <item>@layout/screen_zoom_preview_1</item> <item>@layout/accessibility_text_reading_preview_mail_content</item> </array> <!-- Package responsible for updating Mainline Modules --> <string name="config_mainline_module_update_package" translatable="false">com.android.vending</string> </resources>
src/com/android/settings/deviceinfo/firmwareversion/MainlineModuleVersionPreferenceController.java +19 −9 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ import androidx.annotation.VisibleForTesting; import androidx.preference.Preference; import com.android.settings.core.BasePreferenceController; import com.android.settings.flags.Flags; import java.text.ParseException; import java.text.SimpleDateFormat; Loading @@ -43,14 +44,15 @@ public class MainlineModuleVersionPreferenceController extends BasePreferenceCon private static final String TAG = "MainlineModuleControl"; private static final List<String> VERSION_NAME_DATE_PATTERNS = Arrays.asList("yyyy-MM-dd", "yyyy-MM"); @VisibleForTesting static final Intent MODULE_UPDATE_INTENT = new Intent("android.settings.MODULE_UPDATE_SETTINGS"); static final String MODULE_UPDATE_INTENT_ACTION = "android.settings.MODULE_UPDATE_SETTINGS"; @VisibleForTesting static final Intent MODULE_UPDATE_V2_INTENT = new Intent("android.settings.MODULE_UPDATE_VERSIONS"); static final String MODULE_UPDATE_V2_INTENT_ACTION = "android.settings.MODULE_UPDATE_VERSIONS"; private final Intent mModuleUpdateIntent; private final Intent mModuleUpdateV2Intent; private final PackageManager mPackageManager; private String mModuleVersion; Loading @@ -58,6 +60,14 @@ public class MainlineModuleVersionPreferenceController extends BasePreferenceCon public MainlineModuleVersionPreferenceController(Context context, String key) { super(context, key); mPackageManager = mContext.getPackageManager(); mModuleUpdateIntent = new Intent(MODULE_UPDATE_INTENT_ACTION); mModuleUpdateV2Intent = new Intent(MODULE_UPDATE_V2_INTENT_ACTION); if (Flags.mainlineModuleExplicitIntent()) { String packageName = mContext .getString(com.android.settings.R.string.config_mainline_module_update_package); mModuleUpdateIntent.setPackage(packageName); mModuleUpdateV2Intent.setPackage(packageName); } initModules(); } Loading Loading @@ -86,17 +96,17 @@ public class MainlineModuleVersionPreferenceController extends BasePreferenceCon super.updateState(preference); final ResolveInfo resolvedV2 = mPackageManager.resolveActivity(MODULE_UPDATE_V2_INTENT, 0 /* flags */); mPackageManager.resolveActivity(mModuleUpdateV2Intent, 0 /* flags */); if (resolvedV2 != null) { preference.setIntent(MODULE_UPDATE_V2_INTENT); preference.setIntent(mModuleUpdateV2Intent); preference.setSelectable(true); return; } final ResolveInfo resolved = mPackageManager.resolveActivity(MODULE_UPDATE_INTENT, 0 /* flags */); mPackageManager.resolveActivity(mModuleUpdateIntent, 0 /* flags */); if (resolved != null) { preference.setIntent(MODULE_UPDATE_INTENT); preference.setIntent(mModuleUpdateIntent); preference.setSelectable(true); } else { Log.d(TAG, "The ResolveInfo of the update intent is null."); Loading
tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/MainlineModuleVersionPreferenceControllerTest.java +22 −2 Original line number Diff line number Diff line Loading @@ -18,8 +18,8 @@ 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.android.settings.deviceinfo.firmwareversion.MainlineModuleVersionPreferenceController.MODULE_UPDATE_INTENT_ACTION; import static com.android.settings.deviceinfo.firmwareversion.MainlineModuleVersionPreferenceController.MODULE_UPDATE_V2_INTENT_ACTION; import static com.google.common.truth.Truth.assertThat; Loading @@ -29,13 +29,18 @@ import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; import android.content.Context; import android.content.Intent; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.platform.test.annotations.RequiresFlagsEnabled; import android.platform.test.flag.junit.CheckFlagsRule; import android.platform.test.flag.junit.DeviceFlagsValueProvider; import androidx.preference.Preference; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; Loading @@ -46,6 +51,15 @@ import org.robolectric.RuntimeEnvironment; @RunWith(RobolectricTestRunner.class) public class MainlineModuleVersionPreferenceControllerTest { private static final String MODULE_PACKAGE = "com.android.vending"; private static final Intent MODULE_UPDATE_V2_INTENT = new Intent(MODULE_UPDATE_V2_INTENT_ACTION).setPackage(MODULE_PACKAGE); private static final Intent MODULE_UPDATE_INTENT = new Intent(MODULE_UPDATE_INTENT_ACTION).setPackage(MODULE_PACKAGE); @Rule public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule(); @Mock private PackageManager mPackageManager; Loading @@ -58,6 +72,9 @@ public class MainlineModuleVersionPreferenceControllerTest { mContext = spy(RuntimeEnvironment.application); mPreference = new Preference(mContext); when(mContext.getPackageManager()).thenReturn(mPackageManager); when(mContext .getString(com.android.settings.R.string.config_mainline_module_update_package)) .thenReturn(MODULE_PACKAGE); } @Test Loading Loading @@ -123,6 +140,7 @@ public class MainlineModuleVersionPreferenceControllerTest { assertThat(mPreference.isSelectable()).isTrue(); } @RequiresFlagsEnabled(com.android.settings.flags.Flags.FLAG_MAINLINE_MODULE_EXPLICIT_INTENT) @Test public void updateState_canHandleIntent_setIntentToPreference() throws Exception { setupModulePackage("test version 123"); Loading @@ -137,6 +155,7 @@ public class MainlineModuleVersionPreferenceControllerTest { assertThat(mPreference.getIntent()).isEqualTo(MODULE_UPDATE_INTENT); } @RequiresFlagsEnabled(com.android.settings.flags.Flags.FLAG_MAINLINE_MODULE_EXPLICIT_INTENT) @Test public void updateState_canHandleIntent_preferenceShouldBeSelectable() throws Exception { setupModulePackage("test version 123"); Loading @@ -151,6 +170,7 @@ public class MainlineModuleVersionPreferenceControllerTest { assertThat(mPreference.isSelectable()).isTrue(); } @RequiresFlagsEnabled(com.android.settings.flags.Flags.FLAG_MAINLINE_MODULE_EXPLICIT_INTENT) @Test public void updateState_cannotHandleIntent_setNullToPreference() throws Exception { setupModulePackage("test version 123"); Loading