Prevent monkey from changing usb settings

- Prevent monkey from revoking usb debugging authorizations
 - Prevent monkey from changing usb configurations

Bug: 68707778
Test: make RunSettingsRoboTests -j40
Change-Id: Idce99d60f0fbce5a9d93aceb0c2a07d27482de10
This commit is contained in:
jeffreyhuang
2017-11-06 16:51:27 -08:00
parent d723394569
commit 7b17780134
4 changed files with 52 additions and 3 deletions

View File

@@ -38,6 +38,7 @@ import android.support.v7.preference.PreferenceScreen;
import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.SettingsShadowSystemProperties;
import com.android.settings.testutils.shadow.ShadowUtils;
import org.junit.After;
import org.junit.Before;
@@ -54,7 +55,7 @@ import org.robolectric.util.ReflectionHelpers;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH,
sdk = TestConfig.SDK_VERSION,
shadows = {SettingsShadowSystemProperties.class})
shadows = {SettingsShadowSystemProperties.class, ShadowUtils.class})
public class ClearAdbKeysPreferenceControllerTest {
@Mock
@@ -83,6 +84,7 @@ public class ClearAdbKeysPreferenceControllerTest {
public void tearDown() {
ShadowClearAdbKeysWarningDialog.resetDialog();
SettingsShadowSystemProperties.clear();
ShadowUtils.reset();
}
@Test
@@ -136,6 +138,20 @@ public class ClearAdbKeysPreferenceControllerTest {
assertThat(isHandled).isFalse();
}
@Test
public void handlePreferenceTreeClick_monkeyUser_shouldReturnFalse() {
SystemProperties.set(RO_ADB_SECURE_PROPERTY_KEY, Boolean.toString(true));
doReturn(true).when(mController).isAdminUser();
ShadowUtils.setIsUserAMonkey(true);
mController.displayPreference(mScreen);
final String preferenceKey = mController.getPreferenceKey();
when(mPreference.getKey()).thenReturn(preferenceKey);
final boolean isHandled = mController.handlePreferenceTreeClick(mPreference);
assertThat(isHandled).isFalse();
}
@Test
public void onDeveloperOptionsSwitchEnabled_isAdminUser_shouldEnablePreference() {
SystemProperties.set(RO_ADB_SECURE_PROPERTY_KEY, Boolean.toString(true));