Merge "MainlineModuleVersionPreferenceControllerTest to access intent directly" into main
This commit is contained in:
@@ -41,18 +41,17 @@ import java.util.TimeZone;
|
||||
|
||||
public class MainlineModuleVersionPreferenceController extends BasePreferenceController {
|
||||
|
||||
@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 static final String TAG = "MainlineModuleControl";
|
||||
private static final List<String> VERSION_NAME_DATE_PATTERNS = Arrays.asList("yyyy-MM-dd",
|
||||
"yyyy-MM");
|
||||
@VisibleForTesting
|
||||
static final String MODULE_UPDATE_INTENT_ACTION =
|
||||
"android.settings.MODULE_UPDATE_SETTINGS";
|
||||
@VisibleForTesting
|
||||
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;
|
||||
@@ -60,13 +59,11 @@ 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);
|
||||
MODULE_UPDATE_INTENT.setPackage(packageName);
|
||||
MODULE_UPDATE_V2_INTENT.setPackage(packageName);
|
||||
}
|
||||
initModules();
|
||||
}
|
||||
@@ -96,17 +93,17 @@ public class MainlineModuleVersionPreferenceController extends BasePreferenceCon
|
||||
super.updateState(preference);
|
||||
|
||||
final ResolveInfo resolvedV2 =
|
||||
mPackageManager.resolveActivity(mModuleUpdateV2Intent, 0 /* flags */);
|
||||
mPackageManager.resolveActivity(MODULE_UPDATE_V2_INTENT, 0 /* flags */);
|
||||
if (resolvedV2 != null) {
|
||||
preference.setIntent(mModuleUpdateV2Intent);
|
||||
preference.setIntent(MODULE_UPDATE_V2_INTENT);
|
||||
preference.setSelectable(true);
|
||||
return;
|
||||
}
|
||||
|
||||
final ResolveInfo resolved =
|
||||
mPackageManager.resolveActivity(mModuleUpdateIntent, 0 /* flags */);
|
||||
mPackageManager.resolveActivity(MODULE_UPDATE_INTENT, 0 /* flags */);
|
||||
if (resolved != null) {
|
||||
preference.setIntent(mModuleUpdateIntent);
|
||||
preference.setIntent(MODULE_UPDATE_INTENT);
|
||||
preference.setSelectable(true);
|
||||
} else {
|
||||
Log.d(TAG, "The ResolveInfo of the update intent is null.");
|
||||
|
@@ -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_ACTION;
|
||||
import static com.android.settings.deviceinfo.firmwareversion.MainlineModuleVersionPreferenceController.MODULE_UPDATE_V2_INTENT_ACTION;
|
||||
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;
|
||||
|
||||
@@ -29,7 +29,6 @@ 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;
|
||||
@@ -40,7 +39,6 @@ import android.platform.test.flag.junit.DeviceFlagsValueProvider;
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -53,10 +51,6 @@ import org.robolectric.RuntimeEnvironment;
|
||||
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();
|
||||
@@ -115,7 +109,6 @@ public class MainlineModuleVersionPreferenceControllerTest {
|
||||
assertThat(controller.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
||||
}
|
||||
|
||||
@Ignore("b/313567396")
|
||||
@Test
|
||||
public void updateState_canHandleV2Intent_setIntentToPreference() throws Exception {
|
||||
setupModulePackage("test version 123");
|
||||
@@ -129,7 +122,6 @@ public class MainlineModuleVersionPreferenceControllerTest {
|
||||
assertThat(mPreference.getIntent()).isEqualTo(MODULE_UPDATE_V2_INTENT);
|
||||
}
|
||||
|
||||
@Ignore("b/313567396")
|
||||
@Test
|
||||
public void updateState_canHandleV2Intent_preferenceShouldBeSelectable() throws Exception {
|
||||
setupModulePackage("test version 123");
|
||||
@@ -143,7 +135,6 @@ public class MainlineModuleVersionPreferenceControllerTest {
|
||||
assertThat(mPreference.isSelectable()).isTrue();
|
||||
}
|
||||
|
||||
@Ignore("b/313567396")
|
||||
@RequiresFlagsEnabled(com.android.settings.flags.Flags.FLAG_MAINLINE_MODULE_EXPLICIT_INTENT)
|
||||
@Test
|
||||
public void updateState_canHandleIntent_setIntentToPreference() throws Exception {
|
||||
@@ -159,7 +150,6 @@ public class MainlineModuleVersionPreferenceControllerTest {
|
||||
assertThat(mPreference.getIntent()).isEqualTo(MODULE_UPDATE_INTENT);
|
||||
}
|
||||
|
||||
@Ignore("b/313567396")
|
||||
@RequiresFlagsEnabled(com.android.settings.flags.Flags.FLAG_MAINLINE_MODULE_EXPLICIT_INTENT)
|
||||
@Test
|
||||
public void updateState_canHandleIntent_preferenceShouldBeSelectable() throws Exception {
|
||||
|
Reference in New Issue
Block a user