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

@@ -16,11 +16,14 @@
package com.android.settings.development;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -33,8 +36,10 @@ import android.support.v7.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.ShadowUtils;
import com.android.settingslib.core.lifecycle.Lifecycle;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -44,7 +49,9 @@ import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
@Config(manifest = TestConfig.MANIFEST_PATH,
sdk = TestConfig.SDK_VERSION,
shadows = {ShadowUtils.class})
public class SelectUsbConfigPreferenceControllerTest {
@Mock
@@ -85,6 +92,11 @@ public class SelectUsbConfigPreferenceControllerTest {
}
@After
public void teardown() {
ShadowUtils.reset();
}
@Test
public void onPreferenceChange_setCharging_shouldEnableCharging() {
when(mUsbManager.isFunctionEnabled(mValues[0])).thenReturn(true);
@@ -103,6 +115,18 @@ public class SelectUsbConfigPreferenceControllerTest {
verify(mController).setCurrentFunction(mValues[1], true /* usb data unlock */);
}
@Test
public void onPreferenceChange_monkeyUser_shouldReturnFalse() {
when(mUsbManager.isFunctionEnabled(mValues[1])).thenReturn(true);
ShadowUtils.setIsUserAMonkey(true);
doNothing().when(mController).setCurrentFunction(anyString(), anyBoolean());
final boolean isHandled = mController.onPreferenceChange(mPreference, mValues[1]);
assertThat(isHandled).isFalse();
verify(mController, never()).setCurrentFunction(any(), anyBoolean());
}
@Test
public void updateState_chargingEnabled_shouldSetPreferenceToCharging() {
when(mUsbManager.isFunctionEnabled(mValues[0])).thenReturn(true);