Merge "Revert "Display "Android Auto" in Connected Devices summary text."" into rvc-dev

This commit is contained in:
Yi-Ling Chuang
2020-05-06 10:49:53 +00:00
committed by Android (Google) Code Review
3 changed files with 19 additions and 141 deletions

View File

@@ -23,9 +23,6 @@ import static org.mockito.Mockito.spy;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.ResolveInfo;
import android.nfc.NfcAdapter;
import android.provider.Settings;
@@ -41,7 +38,6 @@ import org.robolectric.RuntimeEnvironment;
import org.robolectric.Shadows;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowNfcAdapter;
import org.robolectric.shadows.ShadowPackageManager;
import org.robolectric.util.ReflectionHelpers;
@RunWith(RobolectricTestRunner.class)
@@ -51,13 +47,11 @@ public class AdvancedConnectedDeviceControllerTest {
private static final String KEY = "test_key";
private static final String DRIVING_MODE_SETTINGS_ENABLED =
"gearhead:driving_mode_settings_enabled";
private static final String ANDROID_AUTO_PACKAGE = "com.google.android.projection.gearhead";
private Context mContext;
private NfcPreferenceController mNfcController;
private ShadowNfcAdapter mShadowNfcAdapter;
private ContentResolver mContentResolver;
private ShadowPackageManager mShadowPackageManager;
@Before
public void setUp() {
@@ -68,7 +62,6 @@ public class AdvancedConnectedDeviceControllerTest {
mNfcController = new NfcPreferenceController(mContext,
NfcPreferenceController.KEY_TOGGLE_NFC);
mShadowNfcAdapter = Shadows.shadowOf(NfcAdapter.getNfcAdapter(mContext));
mShadowPackageManager = Shadows.shadowOf(mContext.getPackageManager());
}
@Test
@@ -83,41 +76,14 @@ public class AdvancedConnectedDeviceControllerTest {
public void isDrivingModeAvailable_returnTrue() {
Settings.System.putInt(mContentResolver, DRIVING_MODE_SETTINGS_ENABLED, 1);
assertThat(
AdvancedConnectedDeviceController.isDrivingModeAvailable(mContext)).isTrue();
assertThat(AdvancedConnectedDeviceController.isDrivingModeAvailable(mContext)).isTrue();
}
@Test
public void isDrivingModeAvailable_returnFalse() {
Settings.System.putInt(mContentResolver, DRIVING_MODE_SETTINGS_ENABLED, 0);
assertThat(
AdvancedConnectedDeviceController.isDrivingModeAvailable(mContext)).isFalse();
}
@Test
public void isAndroidAutoSettingAvailable_returnTrue() {
final ActivityInfo activityInfo = new ActivityInfo();
activityInfo.packageName = ANDROID_AUTO_PACKAGE;
final ResolveInfo resolveInfo = new ResolveInfo();
resolveInfo.activityInfo = activityInfo;
mShadowPackageManager.addResolveInfoForIntent(
buildAndroidAutoSettingsIntent(),
resolveInfo);
assertThat(
AdvancedConnectedDeviceController.isAndroidAutoSettingAvailable(mContext)).isTrue();
}
@Test
public void isAndroidAutoSettingAvailable_returnFalse() {
ResolveInfo resolveInfo = null; // Needed to disambiguate method
mShadowPackageManager.addResolveInfoForIntent(
buildAndroidAutoSettingsIntent(),
resolveInfo);
assertThat(
AdvancedConnectedDeviceController.isAndroidAutoSettingAvailable(mContext)).isFalse();
assertThat(AdvancedConnectedDeviceController.isDrivingModeAvailable(mContext)).isFalse();
}
@Test
@@ -125,7 +91,7 @@ public class AdvancedConnectedDeviceControllerTest {
// NFC available, driving mode available
mShadowNfcAdapter.setEnabled(true);
assertThat(AdvancedConnectedDeviceController
.getConnectedDevicesSummaryResourceId(mNfcController, true, false))
.getConnectedDevicesSummaryResourceId(mNfcController, true))
.isEqualTo(R.string.connected_devices_dashboard_summary);
}
@@ -134,7 +100,7 @@ public class AdvancedConnectedDeviceControllerTest {
// NFC is available, driving mode not available
mShadowNfcAdapter.setEnabled(true);
assertThat(AdvancedConnectedDeviceController
.getConnectedDevicesSummaryResourceId(mNfcController, false, false))
.getConnectedDevicesSummaryResourceId(mNfcController, false))
.isEqualTo(R.string.connected_devices_dashboard_no_driving_mode_summary);
}
@@ -143,7 +109,7 @@ public class AdvancedConnectedDeviceControllerTest {
// NFC not available, driving mode available
ReflectionHelpers.setField(mNfcController, "mNfcAdapter", null);
assertThat(AdvancedConnectedDeviceController
.getConnectedDevicesSummaryResourceId(mNfcController, true, false))
.getConnectedDevicesSummaryResourceId(mNfcController, true))
.isEqualTo(R.string.connected_devices_dashboard_no_nfc_summary);
}
@@ -152,52 +118,7 @@ public class AdvancedConnectedDeviceControllerTest {
// NFC not available, driving mode not available
ReflectionHelpers.setField(mNfcController, "mNfcAdapter", null);
assertThat(AdvancedConnectedDeviceController
.getConnectedDevicesSummaryResourceId(mNfcController, false, false))
.getConnectedDevicesSummaryResourceId(mNfcController, false))
.isEqualTo(R.string.connected_devices_dashboard_no_driving_mode_no_nfc_summary);
}
@Test
public void getConnectedDevicesSummaryResourceId_Auto_NFC_DrivingMode_Available() {
// NFC available, driving mode available
mShadowNfcAdapter.setEnabled(true);
assertThat(AdvancedConnectedDeviceController
.getConnectedDevicesSummaryResourceId(mNfcController, true, true))
.isEqualTo(R.string.connected_devices_dashboard_android_auto_summary);
}
@Test
public void getConnectedDevicesSummaryResourceId_Auto_NFC_Available() {
// NFC is available, driving mode not available
mShadowNfcAdapter.setEnabled(true);
assertThat(AdvancedConnectedDeviceController
.getConnectedDevicesSummaryResourceId(mNfcController, false, true))
.isEqualTo(
R.string.connected_devices_dashboard_android_auto_no_driving_mode_summary);
}
@Test
public void getConnectedDevicesSummaryResourceId_Auto_DrivingMode_Available() {
// NFC not available, driving mode available
ReflectionHelpers.setField(mNfcController, "mNfcAdapter", null);
assertThat(AdvancedConnectedDeviceController
.getConnectedDevicesSummaryResourceId(mNfcController, true, true))
.isEqualTo(R.string.connected_devices_dashboard_android_auto_no_nfc_summary);
}
@Test
public void getConnectedDevicesSummaryResourceId_Auto_Available() {
// NFC not available, driving mode not available
ReflectionHelpers.setField(mNfcController, "mNfcAdapter", null);
assertThat(AdvancedConnectedDeviceController
.getConnectedDevicesSummaryResourceId(mNfcController, false, true))
.isEqualTo(
R.string.connected_devices_dashboard_android_auto_no_nfc_no_driving_mode);
}
private Intent buildAndroidAutoSettingsIntent() {
final Intent intent = new Intent("com.android.settings.action.IA_SETTINGS");
intent.setPackage(ANDROID_AUTO_PACKAGE);
return intent;
}
}