Merge "DO NOT MERGE - Merge pi-platform-release (PPRL.190205.001) into stage-aosp-master" into stage-aosp-master

This commit is contained in:
Xin Li
2019-02-14 22:11:39 +00:00
committed by Android (Google) Code Review
96 changed files with 1014 additions and 650 deletions

View File

@@ -203,6 +203,33 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
verify(mBluetoothDeviceUpdater).addPreference(mCachedBluetoothDevice);
}
@Test
public void onProfileConnectionStateChanged_hearingAidDeviceConnected_notInCall_addPreference()
{
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedHearingAidDevice()).thenReturn(true);
mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice,
BluetoothProfile.STATE_CONNECTED, BluetoothProfile.HEARING_AID);
verify(mBluetoothDeviceUpdater).addPreference(mCachedBluetoothDevice);
}
@Test
public void onProfileConnectionStateChanged_hearingAidDeviceConnected_inCall_addPreference() {
mShadowAudioManager.setMode(AudioManager.MODE_IN_CALL);
when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedHearingAidDevice()).thenReturn(true);
mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice,
BluetoothProfile.STATE_CONNECTED, BluetoothProfile.HEARING_AID);
verify(mBluetoothDeviceUpdater).addPreference(mCachedBluetoothDevice);
}
@Test
public void onProfileConnectionStateChanged_deviceDisconnected_removePreference() {
mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice,

View File

@@ -204,6 +204,34 @@ public class ConnectedBluetoothDeviceUpdaterTest {
verify(mBluetoothDeviceUpdater).addPreference(mCachedBluetoothDevice);
}
@Test
public void onProfileConnectionStateChanged_hearingAidDeviceConnected_inCall_removePreference()
{
mShadowAudioManager.setMode(AudioManager.MODE_IN_CALL);
when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedHearingAidDevice()).thenReturn(true);
mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice,
BluetoothProfile.STATE_CONNECTED, BluetoothProfile.HEARING_AID);
verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice);
}
@Test
public void onProfileConnectionStateChanged_hearingAidDeviceConnected_notInCall_removePreference
() {
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedHearingAidDevice()).thenReturn(true);
mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice,
BluetoothProfile.STATE_CONNECTED, BluetoothProfile.HEARING_AID);
verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice);
}
@Test
public void onProfileConnectionStateChanged_deviceDisconnected_removePreference() {
mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice,

View File

@@ -16,12 +16,21 @@
package com.android.settings.connecteddevice.usb;
import static android.net.ConnectivityManager.TETHERING_USB;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Matchers.anyLong;
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.verifyZeroInteractions;
import static org.mockito.Mockito.when;
import android.hardware.usb.UsbManager;
import android.net.ConnectivityManager;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.ShadowUtils;
@@ -31,13 +40,17 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.Robolectric;
import org.robolectric.annotation.Config;
import org.robolectric.util.FragmentTestUtil;
@RunWith(SettingsRobolectricTestRunner.class)
public class UsbDefaultFragmentTest {
@Mock
private UsbBackend mUsbBackend;
@Mock
private ConnectivityManager mConnectivityManager;
private UsbDefaultFragment mFragment;
@@ -46,6 +59,7 @@ public class UsbDefaultFragmentTest {
MockitoAnnotations.initMocks(this);
mFragment = new UsbDefaultFragment();
mFragment.mUsbBackend = mUsbBackend;
mFragment.mConnectivityManager = mConnectivityManager;
}
@Test
@@ -101,12 +115,6 @@ public class UsbDefaultFragmentTest {
verify(mUsbBackend).setDefaultUsbFunctions(UsbManager.FUNCTION_PTP);
}
@Test
public void setDefaultKey_isRndis_shouldSetRndis() {
mFragment.setDefaultKey(UsbBackend.usbFunctionsToString(UsbManager.FUNCTION_RNDIS));
verify(mUsbBackend).setDefaultUsbFunctions(UsbManager.FUNCTION_RNDIS);
}
@Test
public void setDefaultKey_isMidi_shouldSetMidi() {
mFragment.setDefaultKey(UsbBackend.usbFunctionsToString(UsbManager.FUNCTION_MIDI));
@@ -118,6 +126,39 @@ public class UsbDefaultFragmentTest {
public void setDefaultKey_isMonkey_shouldDoNothing() {
ShadowUtils.setIsUserAMonkey(true);
mFragment.setDefaultKey(UsbBackend.usbFunctionsToString(UsbManager.FUNCTION_MTP));
verifyZeroInteractions(mUsbBackend);
verify(mUsbBackend, never()).setDefaultUsbFunctions(anyLong());
}
@Test
public void setDefaultKey_functionRndis_startTetheringInvoked() {
doReturn(UsbManager.FUNCTION_MTP).when(mUsbBackend).getCurrentFunctions();
mFragment.setDefaultKey(UsbBackend.usbFunctionsToString(UsbManager.FUNCTION_RNDIS));
verify(mConnectivityManager).startTethering(TETHERING_USB, true,
mFragment.mOnStartTetheringCallback);
assertThat(mFragment.mPreviousFunctions).isEqualTo(
UsbManager.FUNCTION_MTP);
}
@Test
public void setDefaultKey_functionOther_setCurrentFunctionInvoked() {
doReturn(UsbManager.FUNCTION_MTP).when(mUsbBackend).getCurrentFunctions();
mFragment.setDefaultKey(UsbBackend.usbFunctionsToString(UsbManager.FUNCTION_PTP));
verify(mUsbBackend).setDefaultUsbFunctions(UsbManager.FUNCTION_PTP);
assertThat(mFragment.mPreviousFunctions).isEqualTo(
UsbManager.FUNCTION_MTP);
}
@Test
public void onTetheringStarted_setDefaultUsbFunctions() {
mFragment.mPreviousFunctions = UsbManager.FUNCTION_PTP;
mFragment.mOnStartTetheringCallback.onTetheringStarted();
verify(mUsbBackend).setDefaultUsbFunctions(UsbManager.FUNCTION_RNDIS);
}
}

View File

@@ -16,9 +16,14 @@
package com.android.settings.connecteddevice.usb;
import static android.net.ConnectivityManager.TETHERING_USB;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.anyLong;
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;
@@ -26,6 +31,7 @@ import android.app.Activity;
import android.content.Context;
import android.hardware.usb.UsbManager;
import android.hardware.usb.UsbPort;
import android.net.ConnectivityManager;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceManager;
import androidx.preference.PreferenceScreen;
@@ -53,9 +59,10 @@ public class UsbDetailsFunctionsControllerTest {
private UsbDetailsFunctionsController mDetailsFunctionsController;
private Context mContext;
private Lifecycle mLifecycle;
private PreferenceCategory mPreference;
private PreferenceCategory mPreferenceCategory;
private PreferenceManager mPreferenceManager;
private PreferenceScreen mScreen;
private RadioButtonPreference mRadioButtonPreference;
@Mock
private UsbBackend mUsbBackend;
@@ -63,12 +70,14 @@ public class UsbDetailsFunctionsControllerTest {
private UsbDetailsFragment mFragment;
@Mock
private Activity mActivity;
@Mock
private ConnectivityManager mConnectivityManager;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
mContext = spy(RuntimeEnvironment.application);
mLifecycle = new Lifecycle(() -> mLifecycle);
mPreferenceManager = new PreferenceManager(mContext);
mScreen = mPreferenceManager.createPreferenceScreen(mContext);
@@ -78,12 +87,16 @@ public class UsbDetailsFunctionsControllerTest {
when(mFragment.getContext()).thenReturn(mContext);
when(mFragment.getPreferenceManager()).thenReturn(mPreferenceManager);
when(mFragment.getPreferenceScreen()).thenReturn(mScreen);
when(mContext.getSystemService(ConnectivityManager.class)).thenReturn(mConnectivityManager);
mDetailsFunctionsController = new UsbDetailsFunctionsController(mContext, mFragment,
mUsbBackend);
mPreference = new PreferenceCategory(mContext);
mPreference.setKey(mDetailsFunctionsController.getPreferenceKey());
mScreen.addPreference(mPreference);
mPreferenceCategory = new PreferenceCategory(mContext);
mPreferenceCategory.setKey(mDetailsFunctionsController.getPreferenceKey());
mScreen.addPreference(mPreferenceCategory);
mDetailsFunctionsController.displayPreference(mScreen);
mRadioButtonPreference = new RadioButtonPreference(mContext);
}
@Test
@@ -105,10 +118,9 @@ public class UsbDetailsFunctionsControllerTest {
public void displayRefresh_disconnected_shouldDisable() {
when(mUsbBackend.areFunctionsSupported(anyLong())).thenReturn(true);
mDetailsFunctionsController.displayPreference(mScreen);
mDetailsFunctionsController.refresh(false, UsbManager.FUNCTION_NONE,
UsbPort.POWER_ROLE_SINK, UsbPort.DATA_ROLE_DEVICE);
assertThat(mPreference.isEnabled()).isFalse();
assertThat(mPreferenceCategory.isEnabled()).isFalse();
}
@Test
@@ -118,7 +130,6 @@ public class UsbDetailsFunctionsControllerTest {
when(mUsbBackend.areFunctionsSupported(UsbManager.FUNCTION_PTP)).thenReturn(false);
when(mUsbBackend.areFunctionsSupported(UsbManager.FUNCTION_RNDIS)).thenReturn(false);
mDetailsFunctionsController.displayPreference(mScreen);
mDetailsFunctionsController.refresh(true, UsbManager.FUNCTION_NONE, UsbPort.POWER_ROLE_SINK,
UsbPort.DATA_ROLE_DEVICE);
List<RadioButtonPreference> prefs = getRadioPreferences();
@@ -131,7 +142,6 @@ public class UsbDetailsFunctionsControllerTest {
public void displayRefresh_mtpEnabled_shouldCheckSwitches() {
when(mUsbBackend.areFunctionsSupported(anyLong())).thenReturn(true);
mDetailsFunctionsController.displayPreference(mScreen);
mDetailsFunctionsController.refresh(true, UsbManager.FUNCTION_MTP, UsbPort.POWER_ROLE_SINK,
UsbPort.DATA_ROLE_DEVICE);
List<RadioButtonPreference> prefs = getRadioPreferences();
@@ -145,7 +155,6 @@ public class UsbDetailsFunctionsControllerTest {
public void onClickMtp_noneEnabled_shouldEnableMtp() {
when(mUsbBackend.areFunctionsSupported(anyLong())).thenReturn(true);
mDetailsFunctionsController.displayPreference(mScreen);
mDetailsFunctionsController.refresh(true, UsbManager.FUNCTION_NONE, UsbPort.POWER_ROLE_SINK,
UsbPort.DATA_ROLE_DEVICE);
when(mUsbBackend.getCurrentFunctions()).thenReturn(UsbManager.FUNCTION_NONE);
@@ -164,7 +173,6 @@ public class UsbDetailsFunctionsControllerTest {
public void onClickMtp_ptpEnabled_shouldEnableMtp() {
when(mUsbBackend.areFunctionsSupported(anyLong())).thenReturn(true);
mDetailsFunctionsController.displayPreference(mScreen);
mDetailsFunctionsController.refresh(true, UsbManager.FUNCTION_PTP, UsbPort.POWER_ROLE_SINK,
UsbPort.DATA_ROLE_DEVICE);
when(mUsbBackend.getCurrentFunctions()).thenReturn(UsbManager.FUNCTION_PTP);
@@ -186,7 +194,6 @@ public class UsbDetailsFunctionsControllerTest {
public void onClickNone_mtpEnabled_shouldDisableMtp() {
when(mUsbBackend.areFunctionsSupported(anyLong())).thenReturn(true);
mDetailsFunctionsController.displayPreference(mScreen);
mDetailsFunctionsController.refresh(true, UsbManager.FUNCTION_MTP, UsbPort.POWER_ROLE_SINK,
UsbPort.DATA_ROLE_DEVICE);
when(mUsbBackend.getCurrentFunctions()).thenReturn(UsbManager.FUNCTION_MTP);
@@ -210,9 +217,55 @@ public class UsbDetailsFunctionsControllerTest {
private List<RadioButtonPreference> getRadioPreferences() {
ArrayList<RadioButtonPreference> result = new ArrayList<>();
for (int i = 0; i < mPreference.getPreferenceCount(); i++) {
result.add((RadioButtonPreference) mPreference.getPreference(i));
for (int i = 0; i < mPreferenceCategory.getPreferenceCount(); i++) {
result.add((RadioButtonPreference) mPreferenceCategory.getPreference(i));
}
return result;
}
@Test
public void onRadioButtonClicked_functionRndis_startTetheringInvoked() {
mRadioButtonPreference.setKey(UsbBackend.usbFunctionsToString(UsbManager.FUNCTION_RNDIS));
doReturn(UsbManager.FUNCTION_MTP).when(mUsbBackend).getCurrentFunctions();
mDetailsFunctionsController.onRadioButtonClicked(mRadioButtonPreference);
verify(mConnectivityManager).startTethering(TETHERING_USB, true,
mDetailsFunctionsController.mOnStartTetheringCallback);
assertThat(mDetailsFunctionsController.mPreviousFunction).isEqualTo(
UsbManager.FUNCTION_MTP);
}
@Test
public void onRadioButtonClicked_functionOther_setCurrentFunctionInvoked() {
mRadioButtonPreference.setKey(UsbBackend.usbFunctionsToString(UsbManager.FUNCTION_PTP));
doReturn(UsbManager.FUNCTION_MTP).when(mUsbBackend).getCurrentFunctions();
mDetailsFunctionsController.onRadioButtonClicked(mRadioButtonPreference);
verify(mUsbBackend).setCurrentFunctions(UsbManager.FUNCTION_PTP);
assertThat(mDetailsFunctionsController.mPreviousFunction).isEqualTo(
UsbManager.FUNCTION_MTP);
}
@Test
public void onRadioButtonClicked_clickSameButton_doNothing() {
mRadioButtonPreference.setKey(UsbBackend.usbFunctionsToString(UsbManager.FUNCTION_PTP));
doReturn(UsbManager.FUNCTION_PTP).when(mUsbBackend).getCurrentFunctions();
mDetailsFunctionsController.onRadioButtonClicked(mRadioButtonPreference);
verify(mUsbBackend, never()).setCurrentFunctions(UsbManager.FUNCTION_PTP);
verify(mConnectivityManager, never()).startTethering(TETHERING_USB, true,
mDetailsFunctionsController.mOnStartTetheringCallback);
}
@Test
public void onTetheringFailed_resetPreviousFunctions() {
mDetailsFunctionsController.mPreviousFunction = UsbManager.FUNCTION_PTP;
mDetailsFunctionsController.mOnStartTetheringCallback.onTetheringFailed();
verify(mUsbBackend).setCurrentFunctions(UsbManager.FUNCTION_PTP);
}
}

View File

@@ -0,0 +1,71 @@
/*
* Copyright (C) 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.development.qstile;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import android.content.ComponentName;
import android.content.pm.PackageManager;
import android.service.quicksettings.Tile;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settingslib.development.DevelopmentSettingsEnabler;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.Robolectric;
@RunWith(SettingsRobolectricTestRunner.class)
public class DevelopmentTilesTest {
@Mock
private Tile mTile;
@Mock
private PackageManager mPackageManager;
private DevelopmentTiles mService;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mService = spy(Robolectric.setupService(DevelopmentTiles.ShowLayout.class));
doReturn(mTile).when(mService).getQsTile();
}
@Test
public void refresh_devOptionIsDisabled_shouldResetTileValue() {
final ComponentName cn = new ComponentName(
mService.getPackageName(), mService.getClass().getName());
doReturn(mPackageManager).when(mService).getPackageManager();
DevelopmentSettingsEnabler.setDevelopmentSettingsEnabled(mService, false);
mService.setIsEnabled(true);
mService.refresh();
verify(mPackageManager).setComponentEnabledSetting(cn,
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
PackageManager.DONT_KILL_APP);
assertThat(mService.isEnabled()).isFalse();
}
}

View File

@@ -81,6 +81,12 @@ public class BrightnessLevelPreferenceControllerTest {
assertThat(mController.isAvailable()).isTrue();
}
@Test
public void isInVrMode_noVrManager_shouldAlwaysReturnFalse() {
doReturn(null).when(mController).safeGetVrManager();
assertThat(mController.isInVrMode()).isFalse();
}
@Test
public void onStart_shouldRegisterObserver() {
BrightnessLevelPreferenceController controller =