Revert "Revert "Prevent monkey from changing usb settings""

This reverts commit da3f0d9e56.

Change-Id: I6d63305e18c2b95676feb60f2526dcade951cd3f
This commit is contained in:
Jeffrey Huang
2017-11-20 18:55:26 +00:00
committed by jeffreyhuang
parent 2575d3fd45
commit 5a280667ba
4 changed files with 51 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));