Merge rvc-qpr-dev-plus-aosp-without-vendor@6881855

Bug: 172690556
Merged-In: Iafcefc2aa64cf3c50b1d139ec0204a315be29da7
Change-Id: I5d4e70fe723d890b5694c3490d6ec841b1ac596e
This commit is contained in:
Xin Li
2020-12-02 00:29:15 -08:00
393 changed files with 32291 additions and 47011 deletions

View File

@@ -18,6 +18,8 @@ package com.android.settings;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
@@ -25,20 +27,27 @@ import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.bluetooth.BluetoothAdapter;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.net.wifi.WifiManager;
import android.os.UserHandle;
import android.os.UserManager;
import android.util.FeatureFlagUtils;
import androidx.fragment.app.FragmentActivity;
import androidx.preference.Preference;
import androidx.preference.SwitchPreference;
import com.android.settings.core.FeatureFlags;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
@@ -160,6 +169,80 @@ public class TetherSettingsTest {
verify(mockPreference).setTitle(R.string.tethering_footer_info_sta_ap_concurrency);
}
@Test
public void testBluetoothState_updateBluetoothState_bluetoothTetheringStateOn() {
final TetherSettings spyTetherSettings = spy(new TetherSettings());
when(spyTetherSettings.getContext()).thenReturn(mContext);
final SwitchPreference mockSwitchPreference = mock(SwitchPreference.class);
when(spyTetherSettings.findPreference(TetherSettings.KEY_ENABLE_BLUETOOTH_TETHERING))
.thenReturn(mockSwitchPreference);
final FragmentActivity mockActivity = mock(FragmentActivity.class);
when(spyTetherSettings.getActivity()).thenReturn(mockActivity);
final ArgumentCaptor<BroadcastReceiver> captor =
ArgumentCaptor.forClass(BroadcastReceiver.class);
when(mockActivity.registerReceiver(captor.capture(), any(IntentFilter.class)))
.thenReturn(null);
// Bluetooth tethering state is on
when(spyTetherSettings.getBluetoothState()).thenReturn(BluetoothAdapter.STATE_ON);
when(spyTetherSettings.isBluetoothTetheringOn()).thenReturn(true);
spyTetherSettings.setupTetherPreference();
spyTetherSettings.registerReceiver();
updateOnlyBluetoothState(spyTetherSettings);
// Simulate Bluetooth tethering state changed
final BroadcastReceiver receiver = captor.getValue();
final Intent bluetoothTetheringChanged =
new Intent(TetherSettings.BLUETOOTH_TETHERING_STATE_CHANGED);
receiver.onReceive(mockActivity, bluetoothTetheringChanged);
verify(mockSwitchPreference).setEnabled(true);
verify(mockSwitchPreference).setChecked(true);
}
@Test
public void testBluetoothState_updateBluetoothState_bluetoothTetheringStateOff() {
final TetherSettings spyTetherSettings = spy(new TetherSettings());
when(spyTetherSettings.getContext()).thenReturn(mContext);
final SwitchPreference mockSwitchPreference = mock(SwitchPreference.class);
when(spyTetherSettings.findPreference(TetherSettings.KEY_ENABLE_BLUETOOTH_TETHERING))
.thenReturn(mockSwitchPreference);
final FragmentActivity mockActivity = mock(FragmentActivity.class);
when(spyTetherSettings.getActivity()).thenReturn(mockActivity);
final ArgumentCaptor<BroadcastReceiver> captor =
ArgumentCaptor.forClass(BroadcastReceiver.class);
when(mockActivity.registerReceiver(captor.capture(), any(IntentFilter.class)))
.thenReturn(null);
// Bluetooth tethering state is off
when(spyTetherSettings.getBluetoothState()).thenReturn(BluetoothAdapter.STATE_ON);
when(spyTetherSettings.isBluetoothTetheringOn()).thenReturn(false);
spyTetherSettings.setupTetherPreference();
spyTetherSettings.registerReceiver();
updateOnlyBluetoothState(spyTetherSettings);
// Simulate Bluetooth tethering state changed
final BroadcastReceiver receiver = captor.getValue();
final Intent bluetoothTetheringChanged =
new Intent(TetherSettings.BLUETOOTH_TETHERING_STATE_CHANGED);
receiver.onReceive(mockActivity, bluetoothTetheringChanged);
verify(mockSwitchPreference).setEnabled(true);
verify(mockSwitchPreference).setChecked(false);
}
private void updateOnlyBluetoothState(TetherSettings tetherSettings) {
doReturn(mConnectivityManager).when(tetherSettings)
.getSystemService(Context.CONNECTIVITY_SERVICE);
when(mConnectivityManager.getTetherableIfaces()).thenReturn(new String[0]);
when(mConnectivityManager.getTetheredIfaces()).thenReturn(new String[0]);
when(mConnectivityManager.getTetheringErroredIfaces()).thenReturn(new String[0]);
doNothing().when(tetherSettings).updateUsbState(any(String[].class), any(String[].class),
any(String[].class));
doNothing().when(tetherSettings).updateEthernetState(any(String[].class),
any(String[].class));
}
private void setupIsTetherAvailable(boolean returnValue) {
when(mConnectivityManager.isTetheringSupported()).thenReturn(true);

View File

@@ -40,6 +40,8 @@ import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.VectorDrawable;
import android.media.MediaRoute2Info;
import android.media.MediaRouter2Manager;
import android.net.ConnectivityManager;
import android.net.LinkAddress;
import android.net.LinkProperties;
@@ -299,4 +301,33 @@ public class UtilsTest {
assertThat(Utils.isSettingsIntelligence(mContext)).isFalse();
}
@Test
public void isMediaOutputDisabled_infosSizeEqual1_returnsTrue() {
final MediaRouter2Manager router2Manager = mock(MediaRouter2Manager.class);
final MediaRoute2Info info = mock(MediaRoute2Info.class);
final List<MediaRoute2Info> infos = new ArrayList<>();
infos.add(info);
when(router2Manager.getAvailableRoutes(anyString())).thenReturn(infos);
when(info.getType()).thenReturn(0);
assertThat(Utils.isMediaOutputDisabled(router2Manager, "test")).isTrue();
}
@Test
public void isMediaOutputDisabled_infosSizeOverThan1_returnsFalse() {
final MediaRouter2Manager router2Manager = mock(MediaRouter2Manager.class);
final MediaRoute2Info info = mock(MediaRoute2Info.class);
final MediaRoute2Info info2 = mock(MediaRoute2Info.class);
final List<MediaRoute2Info> infos = new ArrayList<>();
infos.add(info);
infos.add(info2);
when(router2Manager.getAvailableRoutes(anyString())).thenReturn(infos);
when(info.getType()).thenReturn(0);
when(info2.getType()).thenReturn(0);
assertThat(Utils.isMediaOutputDisabled(router2Manager, "test")).isFalse();
}
}

View File

@@ -570,12 +570,14 @@ public class ManageApplicationsTest {
mFragment.createHeader();
assertThat(mFragment.mFilterAdapter.getCount()).isEqualTo(3);
assertThat(mFragment.mFilterAdapter.getCount()).isEqualTo(4);
assertThat(mFragment.mFilterAdapter.getItem(0)).isEqualTo(
mContext.getString(R.string.sort_order_recent_notification));
assertThat(mFragment.mFilterAdapter.getItem(1)).isEqualTo(
mContext.getString(R.string.sort_order_frequent_notification));
assertThat(mFragment.mFilterAdapter.getItem(2)).isEqualTo(
mContext.getString(R.string.filter_all_apps));
assertThat(mFragment.mFilterAdapter.getItem(3)).isEqualTo(
mContext.getString(R.string.filter_notif_blocked_apps));
}

View File

@@ -62,12 +62,6 @@ public class ZenAccessControllerTest {
assertThat(mController.isAvailable()).isTrue();
}
@Test
public void isAvailable_lowMemory_false() {
mActivityManager.setIsLowRamDevice(true);
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void logSpecialPermissionChange() {
ZenAccessController.logSpecialPermissionChange(true, "app", mContext);

View File

@@ -65,27 +65,13 @@ public class ZenAccessSettingObserverMixinTest {
}
@Test
public void onStart_lowMemory_shouldNotRegisterListener() {
public void onStart_shouldRegisterListener() {
final ShadowActivityManager sam = Shadow.extract(
mContext.getSystemService(ActivityManager.class));
sam.setIsLowRamDevice(true);
mLifecycle.handleLifecycleEvent(ON_START);
mContext.getContentResolver().notifyChange(Settings.Secure.getUriFor(
Settings.Secure.ENABLED_NOTIFICATION_POLICY_ACCESS_PACKAGES), null);
verify(mListener, never()).onZenAccessPolicyChanged();
}
@Test
public void onStart_highMemory_shouldRegisterListener() {
final ShadowActivityManager sam = Shadow.extract(
mContext.getSystemService(ActivityManager.class));
sam.setIsLowRamDevice(false);
mLifecycle.handleLifecycleEvent(ON_START);
mContext.getContentResolver().notifyChange(Settings.Secure.getUriFor(
Settings.Secure.ENABLED_NOTIFICATION_POLICY_ACCESS_PACKAGES), null);
@@ -94,10 +80,6 @@ public class ZenAccessSettingObserverMixinTest {
@Test
public void onStop_shouldUnregisterListener() {
final ShadowActivityManager sam = Shadow.extract(
mContext.getSystemService(ActivityManager.class));
sam.setIsLowRamDevice(false);
mLifecycle.handleLifecycleEvent(ON_START);
mLifecycle.handleLifecycleEvent(ON_STOP);

View File

@@ -17,10 +17,12 @@ package com.android.settings.bluetooth;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -35,7 +37,6 @@ import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.shadow.ShadowAlertDialogCompat;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
import com.android.settingslib.testutils.DrawableTestHelper;
import org.junit.Before;
import org.junit.Test;
@@ -261,4 +262,19 @@ public class BluetoothDevicePreferenceTest {
assertThat(mPreferenceList.get(2).getCachedDevice().getAddress())
.isEqualTo(preference3.getCachedDevice().getAddress());
}
@Test
public void onAttached_callbackNotRemoved_doNotRegisterCallback() {
mPreference.onAttached();
verify(mCachedBluetoothDevice, never()).unregisterCallback(any());
}
@Test
public void onAttached_callbackRemoved_registerCallback() {
mPreference.onPrepareForRemoval();
mPreference.onAttached();
verify(mCachedBluetoothDevice, times(2)).registerCallback(any());
}
}

View File

@@ -144,6 +144,15 @@ public class SavedBluetoothDeviceUpdaterTest {
verify(mCachedBluetoothDevice).connect();
}
@Test
public void onClick_Preference_connected_setActive() {
when(mCachedBluetoothDevice.isConnected()).thenReturn(true);
mBluetoothDeviceUpdater.onPreferenceClick(mPreference);
verify(mCachedBluetoothDevice).setActive();
}
@Test
public void forceUpdate_findCachedBluetoothDeviceIsMatched_addPreference() {
final List<BluetoothDevice> bluetoothDevices = new ArrayList<>();

View File

@@ -0,0 +1,57 @@
/*
* Copyright 2020 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.connecteddevice;
import static com.google.common.truth.Truth.assertThat;
import android.bluetooth.BluetoothAdapter;
import com.android.settings.testutils.shadow.ShadowBluetoothAdapter;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import org.robolectric.shadow.api.Shadow;
@RunWith(RobolectricTestRunner.class)
@Config(shadows = ShadowBluetoothAdapter.class)
public class PreviouslyConnectedDeviceDashboardFragmentTest {
private ShadowBluetoothAdapter mShadowBluetoothAdapter;
private PreviouslyConnectedDeviceDashboardFragment mFragment;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mShadowBluetoothAdapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter());
mFragment = new PreviouslyConnectedDeviceDashboardFragment();
mFragment.mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
}
@Test
public void onStart_bluetoothIsDisable_enableBluetooth() {
mShadowBluetoothAdapter.setEnabled(false);
assertThat(mFragment.mBluetoothAdapter.isEnabled()).isFalse();
mFragment.enableBluetoothIfNecessary();
assertThat(mFragment.mBluetoothAdapter.isEnabled()).isTrue();
}
}

View File

@@ -23,7 +23,10 @@ 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 static org.mockito.Mockito.when;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.content.pm.PackageManager;
@@ -32,9 +35,14 @@ import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceGroup;
import androidx.preference.PreferenceManager;
import com.android.settings.R;
import com.android.settings.bluetooth.BluetoothDevicePreference;
import com.android.settings.bluetooth.BluetoothDeviceUpdater;
import com.android.settings.connecteddevice.dock.DockUpdater;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.testutils.shadow.ShadowBluetoothAdapter;
import com.android.settings.widget.SingleTargetGearPreference;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import org.junit.Before;
import org.junit.Test;
@@ -43,11 +51,21 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.shadow.api.Shadow;
import java.util.ArrayList;
import java.util.List;
@RunWith(RobolectricTestRunner.class)
@Config(shadows = ShadowBluetoothAdapter.class)
public class PreviouslyConnectedDevicePreferenceControllerTest {
private final String KEY = "test_key";
private static final String KEY = "test_key";
private static final String FAKE_ADDRESS_1 = "AA:AA:AA:AA:AA:01";
private static final String FAKE_ADDRESS_2 = "AA:AA:AA:AA:AA:02";
private static final String FAKE_ADDRESS_3 = "AA:AA:AA:AA:AA:03";
private static final String FAKE_ADDRESS_4 = "AA:AA:AA:AA:AA:04";
@Mock
private DashboardFragment mDashboardFragment;
@@ -59,10 +77,29 @@ public class PreviouslyConnectedDevicePreferenceControllerTest {
private PackageManager mPackageManager;
@Mock
private PreferenceManager mPreferenceManager;
@Mock
private Preference mSeeAllPreference;
@Mock
private CachedBluetoothDevice mCachedDevice1;
@Mock
private CachedBluetoothDevice mCachedDevice2;
@Mock
private CachedBluetoothDevice mCachedDevice3;
@Mock
private CachedBluetoothDevice mCachedDevice4;
@Mock
private BluetoothDevice mBluetoothDevice1;
@Mock
private BluetoothDevice mBluetoothDevice2;
@Mock
private BluetoothDevice mBluetoothDevice3;
@Mock
private BluetoothDevice mBluetoothDevice4;
private Context mContext;
private PreviouslyConnectedDevicePreferenceController mPreConnectedDeviceController;
private PreferenceGroup mPreferenceGroup;
private ShadowBluetoothAdapter mShadowBluetoothAdapter;
@Before
public void setUp() {
@@ -74,11 +111,29 @@ public class PreviouslyConnectedDevicePreferenceControllerTest {
new PreviouslyConnectedDevicePreferenceController(mContext, KEY);
mPreConnectedDeviceController.setBluetoothDeviceUpdater(mBluetoothDeviceUpdater);
mPreConnectedDeviceController.setSavedDockUpdater(mDockUpdater);
mShadowBluetoothAdapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter());
when(mCachedDevice1.getDevice()).thenReturn(mBluetoothDevice1);
when(mCachedDevice1.getAddress()).thenReturn(FAKE_ADDRESS_1);
when(mCachedDevice2.getDevice()).thenReturn(mBluetoothDevice2);
when(mCachedDevice2.getAddress()).thenReturn(FAKE_ADDRESS_2);
when(mCachedDevice3.getDevice()).thenReturn(mBluetoothDevice3);
when(mCachedDevice3.getAddress()).thenReturn(FAKE_ADDRESS_3);
when(mCachedDevice4.getDevice()).thenReturn(mBluetoothDevice4);
when(mCachedDevice4.getAddress()).thenReturn(FAKE_ADDRESS_4);
final List<BluetoothDevice> mMostRecentlyConnectedDevices = new ArrayList<>();
mMostRecentlyConnectedDevices.add(mBluetoothDevice1);
mMostRecentlyConnectedDevices.add(mBluetoothDevice2);
mMostRecentlyConnectedDevices.add(mBluetoothDevice4);
mMostRecentlyConnectedDevices.add(mBluetoothDevice3);
mShadowBluetoothAdapter.setMostRecentlyConnectedDevices(mMostRecentlyConnectedDevices);
mPreferenceGroup = spy(new PreferenceCategory(mContext));
doReturn(mPreferenceManager).when(mPreferenceGroup).getPreferenceManager();
mPreferenceGroup.setVisible(false);
mPreConnectedDeviceController.setPreferenceGroup(mPreferenceGroup);
mPreConnectedDeviceController.mSeeAllPreference = mSeeAllPreference;
}
@Test
@@ -87,11 +142,14 @@ public class PreviouslyConnectedDevicePreferenceControllerTest {
mPreConnectedDeviceController.onStart();
verify(mBluetoothDeviceUpdater).registerCallback();
verify(mDockUpdater).registerCallback();
verify(mContext).registerReceiver(mPreConnectedDeviceController.mReceiver,
mPreConnectedDeviceController.mIntentFilter);
// unregister the callback in onStop()
mPreConnectedDeviceController.onStop();
verify(mBluetoothDeviceUpdater).unregisterCallback();
verify(mDockUpdater).unregisterCallback();
verify(mContext).unregisterReceiver(mPreConnectedDeviceController.mReceiver);
}
@Test
@@ -122,32 +180,76 @@ public class PreviouslyConnectedDevicePreferenceControllerTest {
@Test
public void onDeviceAdded_addDevicePreference_displayIt() {
mPreConnectedDeviceController.onDeviceAdded(new Preference(mContext));
final BluetoothDevicePreference preference1 = new BluetoothDevicePreference(
mContext, mCachedDevice1, true, BluetoothDevicePreference.SortType.TYPE_NO_SORT);
assertThat(mPreferenceGroup.isVisible()).isTrue();
assertThat(mPreferenceGroup.getPreferenceCount()).isEqualTo(1);
mPreConnectedDeviceController.onDeviceAdded(preference1);
assertThat(mPreferenceGroup.getPreferenceCount()).isEqualTo(2);
}
@Test
public void onDeviceAdded_addDockDevicePreference_displayIt() {
final SingleTargetGearPreference dockPreference = new SingleTargetGearPreference(
mContext, null /* AttributeSet */);
mPreConnectedDeviceController.onDeviceAdded(dockPreference);
assertThat(mPreferenceGroup.getPreferenceCount()).isEqualTo(2);
}
@Test
public void onDeviceAdded_addFourDevicePreference_onlyDisplayThree() {
mPreConnectedDeviceController.onDeviceAdded(new Preference(mContext));
mPreConnectedDeviceController.onDeviceAdded(new Preference(mContext));
mPreConnectedDeviceController.onDeviceAdded(new Preference(mContext));
mPreConnectedDeviceController.onDeviceAdded(new Preference(mContext));
final BluetoothDevicePreference preference1 = new BluetoothDevicePreference(
mContext, mCachedDevice1, true, BluetoothDevicePreference.SortType.TYPE_NO_SORT);
final BluetoothDevicePreference preference2 = new BluetoothDevicePreference(
mContext, mCachedDevice2, true, BluetoothDevicePreference.SortType.TYPE_NO_SORT);
final BluetoothDevicePreference preference3 = new BluetoothDevicePreference(
mContext, mCachedDevice3, true, BluetoothDevicePreference.SortType.TYPE_NO_SORT);
final BluetoothDevicePreference preference4 = new BluetoothDevicePreference(
mContext, mCachedDevice4, true, BluetoothDevicePreference.SortType.TYPE_NO_SORT);
final SingleTargetGearPreference dockPreference = new SingleTargetGearPreference(
mContext, null /* AttributeSet */);
assertThat(mPreferenceGroup.isVisible()).isTrue();
assertThat(mPreferenceGroup.getPreferenceCount()).isEqualTo(3);
mPreConnectedDeviceController.onDeviceAdded(preference1);
mPreConnectedDeviceController.onDeviceAdded(preference2);
mPreConnectedDeviceController.onDeviceAdded(preference3);
mPreConnectedDeviceController.onDeviceAdded(preference4);
mPreConnectedDeviceController.onDeviceAdded(dockPreference);
// 3 BluetoothDevicePreference and 1 see all preference
assertThat(mPreferenceGroup.getPreferenceCount()).isEqualTo(4);
}
@Test
public void onDeviceRemoved_removeLastDevice_setInvisible() {
final Preference preference = new Preference(mContext);
mPreferenceGroup.addPreference(preference);
mPreferenceGroup.setVisible(true);
public void onDeviceRemoved_removeLastDevice_showSeeAllPreference() {
final BluetoothDevicePreference preference1 = new BluetoothDevicePreference(
mContext, mCachedDevice1, true, BluetoothDevicePreference.SortType.TYPE_NO_SORT);
final SingleTargetGearPreference dockPreference = new SingleTargetGearPreference(
mContext, null /* AttributeSet */);
mPreferenceGroup.addPreference(preference1);
mPreferenceGroup.addPreference(dockPreference);
mPreConnectedDeviceController.onDeviceRemoved(preference);
mPreConnectedDeviceController.onDeviceRemoved(preference1);
mPreConnectedDeviceController.onDeviceRemoved(dockPreference);
assertThat(mPreferenceGroup.isVisible()).isFalse();
assertThat(mPreferenceGroup.getPreferenceCount()).isEqualTo(0);
assertThat(mPreferenceGroup.getPreferenceCount()).isEqualTo(1);
}
@Test
public void updatePreferenceVisibility_bluetoothIsEnable_shouldShowCorrectText() {
mShadowBluetoothAdapter.setEnabled(true);
mPreConnectedDeviceController.updatePreferenceVisibility();
verify(mSeeAllPreference).setSummary("");
}
@Test
public void updatePreferenceVisibility_bluetoothIsDisable_shouldShowCorrectText() {
mShadowBluetoothAdapter.setEnabled(false);
mPreConnectedDeviceController.updatePreferenceVisibility();
verify(mSeeAllPreference).setSummary(
mContext.getString(R.string.connected_device_see_all_summary));
}
}

View File

@@ -18,8 +18,8 @@ package com.android.settings.development.graphicsdriver;
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
import static com.android.settings.development.graphicsdriver.GraphicsDriverEnableForAllAppsPreferenceController.GAME_DRIVER_DEFAULT;
import static com.android.settings.development.graphicsdriver.GraphicsDriverEnableForAllAppsPreferenceController.GAME_DRIVER_OFF;
import static com.android.settings.development.graphicsdriver.GraphicsDriverEnableForAllAppsPreferenceController.UPDATABLE_DRIVER_DEFAULT;
import static com.android.settings.development.graphicsdriver.GraphicsDriverEnableForAllAppsPreferenceController.UPDATABLE_DRIVER_OFF;
import static com.android.settings.testutils.ApplicationTestUtils.buildInfo;
import static com.google.common.truth.Truth.assertThat;
@@ -57,7 +57,7 @@ public class GraphicsDriverAppPreferenceControllerTest {
private static final int DEFAULT = 0;
private static final int PRERELEASE_DRIVER = 1;
private static final int GAME_DRIVER = 2;
private static final int PRODUCTION_DRIVER = 2;
private static final int SYSTEM = 3;
private static final String TEST_APP_NAME = "testApp";
private static final String TEST_PKG_NAME = "testPkg";
@@ -99,11 +99,11 @@ public class GraphicsDriverAppPreferenceControllerTest {
}
@Test
public void getAvailability_developmentSettingsEnabledAndGameDriverOn_available() {
public void getAvailability_developmentSettingsEnabledAndProductionDriverOn_available() {
loadDefaultConfig();
Settings.Global.putInt(mResolver, Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
Settings.Global.putInt(
mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT);
mResolver, Settings.Global.UPDATABLE_DRIVER_ALL_APPS, UPDATABLE_DRIVER_DEFAULT);
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
}
@@ -119,7 +119,8 @@ public class GraphicsDriverAppPreferenceControllerTest {
@Test
public void getAvailability_graphicsDriverOff_conditionallyUnavailable() {
loadDefaultConfig();
Settings.Global.putInt(mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_OFF);
Settings.Global.putInt(mResolver, Settings.Global.UPDATABLE_DRIVER_ALL_APPS,
UPDATABLE_DRIVER_OFF);
assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
}
@@ -157,7 +158,7 @@ public class GraphicsDriverAppPreferenceControllerTest {
public void updateState_available_visible() {
Settings.Global.putInt(mResolver, Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
Settings.Global.putInt(
mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT);
mResolver, Settings.Global.UPDATABLE_DRIVER_ALL_APPS, UPDATABLE_DRIVER_DEFAULT);
loadDefaultConfig();
assertThat(mGroup.isVisible()).isTrue();
@@ -165,7 +166,8 @@ public class GraphicsDriverAppPreferenceControllerTest {
@Test
public void updateState_graphicsDriverOff_notVisible() {
Settings.Global.putInt(mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_OFF);
Settings.Global.putInt(mResolver, Settings.Global.UPDATABLE_DRIVER_ALL_APPS,
UPDATABLE_DRIVER_OFF);
loadDefaultConfig();
assertThat(mGroup.isVisible()).isFalse();
@@ -188,7 +190,7 @@ public class GraphicsDriverAppPreferenceControllerTest {
}
@Test
public void createPreference_configGAME_DRIVER_shouldSetGameDriverAttributes() {
public void createPreference_configProduction_DRIVER_shouldSetProductionDriverAttributes() {
loadConfig(TEST_PKG_NAME, "", "");
final ListPreference preference =
mController.createListPreference(mContext, TEST_PKG_NAME, TEST_APP_NAME);
@@ -198,9 +200,9 @@ public class GraphicsDriverAppPreferenceControllerTest {
assertThat(preference.getDialogTitle()).isEqualTo(mDialogTitle);
assertThat(preference.getEntries()).isEqualTo(mValueList);
assertThat(preference.getEntryValues()).isEqualTo(mValueList);
assertThat(preference.getEntry()).isEqualTo(mValueList[GAME_DRIVER]);
assertThat(preference.getValue()).isEqualTo(mValueList[GAME_DRIVER]);
assertThat(preference.getSummary()).isEqualTo(mValueList[GAME_DRIVER]);
assertThat(preference.getEntry()).isEqualTo(mValueList[PRODUCTION_DRIVER]);
assertThat(preference.getValue()).isEqualTo(mValueList[PRODUCTION_DRIVER]);
assertThat(preference.getSummary()).isEqualTo(mValueList[PRODUCTION_DRIVER]);
}
@Test
@@ -245,9 +247,11 @@ public class GraphicsDriverAppPreferenceControllerTest {
assertThat(preference.getEntry()).isEqualTo(mValueList[DEFAULT]);
assertThat(preference.getValue()).isEqualTo(mValueList[DEFAULT]);
assertThat(preference.getSummary()).isEqualTo(mValueList[DEFAULT]);
assertThat(Settings.Global.getString(mResolver, Settings.Global.GAME_DRIVER_OPT_IN_APPS))
assertThat(Settings.Global.getString(mResolver,
Settings.Global.UPDATABLE_DRIVER_PRODUCTION_OPT_IN_APPS))
.isEqualTo("");
assertThat(Settings.Global.getString(mResolver, Settings.Global.GAME_DRIVER_OPT_OUT_APPS))
assertThat(Settings.Global.getString(mResolver,
Settings.Global.UPDATABLE_DRIVER_PRODUCTION_OPT_OUT_APPS))
.isEqualTo("");
}
@@ -262,25 +266,28 @@ public class GraphicsDriverAppPreferenceControllerTest {
assertThat(preference.getValue()).isEqualTo(mValueList[PRERELEASE_DRIVER]);
assertThat(preference.getSummary()).isEqualTo(mValueList[PRERELEASE_DRIVER]);
assertThat(Settings.Global.getString(mResolver,
Settings.Global.GAME_DRIVER_PRERELEASE_OPT_IN_APPS))
Settings.Global.UPDATABLE_DRIVER_PRERELEASE_OPT_IN_APPS))
.isEqualTo(TEST_PKG_NAME);
assertThat(Settings.Global.getString(mResolver, Settings.Global.GAME_DRIVER_OPT_OUT_APPS))
assertThat(Settings.Global.getString(mResolver,
Settings.Global.UPDATABLE_DRIVER_PRODUCTION_OPT_OUT_APPS))
.isEqualTo("");
}
@Test
public void onPreferenceChange_selectGAME_DRIVER_shouldUpdateAttributesAndSettingsGlobal() {
public void onPreferenceChange_selectPRODUCTION_DRIVER_shouldUpdateAttrAndSettingsGlobal() {
loadDefaultConfig();
final ListPreference preference =
mController.createListPreference(mContext, TEST_PKG_NAME, TEST_APP_NAME);
mController.onPreferenceChange(preference, mValueList[GAME_DRIVER]);
mController.onPreferenceChange(preference, mValueList[PRODUCTION_DRIVER]);
assertThat(preference.getEntry()).isEqualTo(mValueList[GAME_DRIVER]);
assertThat(preference.getValue()).isEqualTo(mValueList[GAME_DRIVER]);
assertThat(preference.getSummary()).isEqualTo(mValueList[GAME_DRIVER]);
assertThat(Settings.Global.getString(mResolver, Settings.Global.GAME_DRIVER_OPT_IN_APPS))
assertThat(preference.getEntry()).isEqualTo(mValueList[PRODUCTION_DRIVER]);
assertThat(preference.getValue()).isEqualTo(mValueList[PRODUCTION_DRIVER]);
assertThat(preference.getSummary()).isEqualTo(mValueList[PRODUCTION_DRIVER]);
assertThat(Settings.Global.getString(mResolver,
Settings.Global.UPDATABLE_DRIVER_PRODUCTION_OPT_IN_APPS))
.isEqualTo(TEST_PKG_NAME);
assertThat(Settings.Global.getString(mResolver, Settings.Global.GAME_DRIVER_OPT_OUT_APPS))
assertThat(Settings.Global.getString(mResolver,
Settings.Global.UPDATABLE_DRIVER_PRODUCTION_OPT_OUT_APPS))
.isEqualTo("");
}
@@ -294,9 +301,11 @@ public class GraphicsDriverAppPreferenceControllerTest {
assertThat(preference.getEntry()).isEqualTo(mValueList[SYSTEM]);
assertThat(preference.getValue()).isEqualTo(mValueList[SYSTEM]);
assertThat(preference.getSummary()).isEqualTo(mValueList[SYSTEM]);
assertThat(Settings.Global.getString(mResolver, Settings.Global.GAME_DRIVER_OPT_IN_APPS))
assertThat(Settings.Global.getString(mResolver,
Settings.Global.UPDATABLE_DRIVER_PRODUCTION_OPT_IN_APPS))
.isEqualTo("");
assertThat(Settings.Global.getString(mResolver, Settings.Global.GAME_DRIVER_OPT_OUT_APPS))
assertThat(Settings.Global.getString(mResolver,
Settings.Global.UPDATABLE_DRIVER_PRODUCTION_OPT_OUT_APPS))
.isEqualTo(TEST_PKG_NAME);
}
@@ -320,10 +329,13 @@ public class GraphicsDriverAppPreferenceControllerTest {
}
private void loadConfig(String optIn, String prereleaseOptIn, String optOut) {
Settings.Global.putString(mResolver, Settings.Global.GAME_DRIVER_OPT_IN_APPS, optIn);
Settings.Global.putString(mResolver,
Settings.Global.UPDATABLE_DRIVER_PRODUCTION_OPT_IN_APPS, optIn);
Settings.Global.putString(
mResolver, Settings.Global.GAME_DRIVER_PRERELEASE_OPT_IN_APPS, prereleaseOptIn);
Settings.Global.putString(mResolver, Settings.Global.GAME_DRIVER_OPT_OUT_APPS, optOut);
mResolver, Settings.Global.UPDATABLE_DRIVER_PRERELEASE_OPT_IN_APPS,
prereleaseOptIn);
Settings.Global.putString(
mResolver, Settings.Global.UPDATABLE_DRIVER_PRODUCTION_OPT_OUT_APPS, optOut);
mController = new GraphicsDriverAppPreferenceController(mContext, "testKey");
mController.mEntryList = mContext.getResources().getStringArray(

View File

@@ -58,7 +58,7 @@ public class GraphicsDriverContentObserverTest {
mGraphicsDriverContentObserver.register(mResolver);
verify(mResolver).registerContentObserver(
Settings.Global.getUriFor(Settings.Global.GAME_DRIVER_ALL_APPS), false,
Settings.Global.getUriFor(Settings.Global.UPDATABLE_DRIVER_ALL_APPS), false,
mGraphicsDriverContentObserver);
}

View File

@@ -45,7 +45,7 @@ public class GraphicsDriverDashboardTest {
@Test
public void getMetricesCategory_shouldReturnGraphicsDriverDashboard() {
assertThat(mDashboard.getMetricsCategory())
.isEqualTo(SettingsEnums.SETTINGS_GAME_DRIVER_DASHBOARD);
.isEqualTo(SettingsEnums.SETTINGS_GRAPHICS_DRIVER_DASHBOARD);
}
@Test

View File

@@ -18,10 +18,10 @@ package com.android.settings.development.graphicsdriver;
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
import static com.android.settings.development.graphicsdriver.GraphicsDriverEnableForAllAppsPreferenceController.GAME_DRIVER_ALL_APPS;
import static com.android.settings.development.graphicsdriver.GraphicsDriverEnableForAllAppsPreferenceController.GAME_DRIVER_DEFAULT;
import static com.android.settings.development.graphicsdriver.GraphicsDriverEnableForAllAppsPreferenceController.GAME_DRIVER_OFF;
import static com.android.settings.development.graphicsdriver.GraphicsDriverEnableForAllAppsPreferenceController.GAME_DRIVER_PRERELEASE_ALL_APPS;
import static com.android.settings.development.graphicsdriver.GraphicsDriverEnableForAllAppsPreferenceController.UPDATABLE_DRIVER_DEFAULT;
import static com.android.settings.development.graphicsdriver.GraphicsDriverEnableForAllAppsPreferenceController.UPDATABLE_DRIVER_OFF;
import static com.android.settings.development.graphicsdriver.GraphicsDriverEnableForAllAppsPreferenceController.UPDATABLE_DRIVER_PRERELEASE_ALL_APPS;
import static com.android.settings.development.graphicsdriver.GraphicsDriverEnableForAllAppsPreferenceController.UPDATABLE_DRIVER_PRODUCTION_ALL_APPS;
import static com.google.common.truth.Truth.assertThat;
@@ -61,7 +61,7 @@ public class GraphicsDriverEnableForAllAppsPreferenceControllerTest {
private ContentResolver mResolver;
private GraphicsDriverEnableForAllAppsPreferenceController mController;
private String mPreferenceDefault;
private String mPreferenceGameDriver;
private String mPreferenceProductionDriver;
private String mPreferencePrereleaseDriver;
@Before
@@ -72,14 +72,14 @@ public class GraphicsDriverEnableForAllAppsPreferenceControllerTest {
final Resources resources = mContext.getResources();
mPreferenceDefault = resources.getString(R.string.graphics_driver_app_preference_default);
mPreferenceGameDriver =
resources.getString(R.string.graphics_driver_app_preference_game_driver);
mPreferenceProductionDriver =
resources.getString(R.string.graphics_driver_app_preference_production_driver);
mPreferencePrereleaseDriver =
resources.getString(R.string.graphics_driver_app_preference_prerelease_driver);
Settings.Global.putInt(mResolver, Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
Settings.Global.putInt(
mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT);
mResolver, Settings.Global.UPDATABLE_DRIVER_ALL_APPS, UPDATABLE_DRIVER_DEFAULT);
mController = new GraphicsDriverEnableForAllAppsPreferenceController(mContext, "testKey");
mController.mEntryList = mContext.getResources().getStringArray(
@@ -89,9 +89,9 @@ public class GraphicsDriverEnableForAllAppsPreferenceControllerTest {
}
@Test
public void getAvailability_developmentSettingsEnabledAndGameDriverSettingsOn_available() {
public void getAvailability_developmentSettingsEnabledAndUpdatableDriverSettingsOn_available() {
Settings.Global.putInt(
mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT);
mResolver, Settings.Global.UPDATABLE_DRIVER_ALL_APPS, UPDATABLE_DRIVER_DEFAULT);
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
}
@@ -104,8 +104,9 @@ public class GraphicsDriverEnableForAllAppsPreferenceControllerTest {
}
@Test
public void getAvailability_gameDriverOff_conditionallyUnavailable() {
Settings.Global.putInt(mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_OFF);
public void getAvailability_updatableDriverOff_conditionallyUnavailable() {
Settings.Global.putInt(mResolver, Settings.Global.UPDATABLE_DRIVER_ALL_APPS,
UPDATABLE_DRIVER_OFF);
assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
}
@@ -113,7 +114,7 @@ public class GraphicsDriverEnableForAllAppsPreferenceControllerTest {
@Test
public void displayPreference_shouldAddListPreference() {
Settings.Global.putInt(
mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT);
mResolver, Settings.Global.UPDATABLE_DRIVER_ALL_APPS, UPDATABLE_DRIVER_DEFAULT);
mController.updateState(mPreference);
verify(mPreference).setValue(mPreferenceDefault);
@@ -139,7 +140,7 @@ public class GraphicsDriverEnableForAllAppsPreferenceControllerTest {
@Test
public void updateState_availableAndDefault_visibleAndDefault() {
Settings.Global.putInt(
mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT);
mResolver, Settings.Global.UPDATABLE_DRIVER_ALL_APPS, UPDATABLE_DRIVER_DEFAULT);
mController.updateState(mPreference);
verify(mPreference, atLeastOnce()).setVisible(true);
@@ -148,20 +149,22 @@ public class GraphicsDriverEnableForAllAppsPreferenceControllerTest {
}
@Test
public void updateState_availableAndGameDriver_visibleAndGameDriver() {
public void updateState_availableAndProductionDriver_visibleAndProductionDriver() {
Settings.Global.putInt(
mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_ALL_APPS);
mResolver, Settings.Global.UPDATABLE_DRIVER_ALL_APPS,
UPDATABLE_DRIVER_PRODUCTION_ALL_APPS);
mController.updateState(mPreference);
verify(mPreference, atLeastOnce()).setVisible(true);
verify(mPreference).setValue(mPreferenceGameDriver);
verify(mPreference).setSummary(mPreferenceGameDriver);
verify(mPreference).setValue(mPreferenceProductionDriver);
verify(mPreference).setSummary(mPreferenceProductionDriver);
}
@Test
public void updateState_availableAndPrereleaseDriver_visibleAndPrereleaseDriver() {
Settings.Global.putInt(
mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_PRERELEASE_ALL_APPS);
mResolver, Settings.Global.UPDATABLE_DRIVER_ALL_APPS,
UPDATABLE_DRIVER_PRERELEASE_ALL_APPS);
mController.updateState(mPreference);
verify(mPreference, atLeastOnce()).setVisible(true);
@@ -170,8 +173,9 @@ public class GraphicsDriverEnableForAllAppsPreferenceControllerTest {
}
@Test
public void updateState_gameDriverOff_notVisibleAndSystemDriver() {
Settings.Global.putInt(mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_OFF);
public void updateState_updatableDriverOff_notVisibleAndSystemDriver() {
Settings.Global.putInt(mResolver, Settings.Global.UPDATABLE_DRIVER_ALL_APPS,
UPDATABLE_DRIVER_OFF);
mController.updateState(mPreference);
verify(mPreference).setVisible(false);
@@ -182,33 +186,35 @@ public class GraphicsDriverEnableForAllAppsPreferenceControllerTest {
@Test
public void onPreferenceChange_default_shouldUpdateSettingsGlobal() {
Settings.Global.putInt(
mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_ALL_APPS);
mResolver, Settings.Global.UPDATABLE_DRIVER_ALL_APPS,
UPDATABLE_DRIVER_PRODUCTION_ALL_APPS);
mController.onPreferenceChange(mPreference, mPreferenceDefault);
assertThat(Settings.Global.getInt(
mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT))
.isEqualTo(GAME_DRIVER_DEFAULT);
mResolver, Settings.Global.UPDATABLE_DRIVER_ALL_APPS,
UPDATABLE_DRIVER_DEFAULT))
.isEqualTo(UPDATABLE_DRIVER_DEFAULT);
}
@Test
public void onPreferenceChange_gameDriver_shouldUpdateSettingsGlobal() {
public void onPreferenceChange_updatableDriver_shouldUpdateSettingsGlobal() {
Settings.Global.putInt(
mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT);
mController.onPreferenceChange(mPreference, mPreferenceGameDriver);
mResolver, Settings.Global.UPDATABLE_DRIVER_ALL_APPS, UPDATABLE_DRIVER_DEFAULT);
mController.onPreferenceChange(mPreference, mPreferenceProductionDriver);
assertThat(Settings.Global.getInt(
mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT))
.isEqualTo(GAME_DRIVER_ALL_APPS);
mResolver, Settings.Global.UPDATABLE_DRIVER_ALL_APPS, UPDATABLE_DRIVER_DEFAULT))
.isEqualTo(UPDATABLE_DRIVER_PRODUCTION_ALL_APPS);
}
@Test
public void onPreferenceChange_prereleaseDriver_shouldUpdateSettingsGlobal() {
Settings.Global.putInt(
mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT);
mResolver, Settings.Global.UPDATABLE_DRIVER_ALL_APPS, UPDATABLE_DRIVER_DEFAULT);
mController.onPreferenceChange(mPreference, mPreferencePrereleaseDriver);
assertThat(Settings.Global.getInt(
mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT))
.isEqualTo(GAME_DRIVER_PRERELEASE_ALL_APPS);
mResolver, Settings.Global.UPDATABLE_DRIVER_ALL_APPS, UPDATABLE_DRIVER_DEFAULT))
.isEqualTo(UPDATABLE_DRIVER_PRERELEASE_ALL_APPS);
}
}

View File

@@ -18,9 +18,9 @@ package com.android.settings.development.graphicsdriver;
import static com.android.settings.core.BasePreferenceController.AVAILABLE_UNSEARCHABLE;
import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
import static com.android.settings.development.graphicsdriver.GraphicsDriverEnableForAllAppsPreferenceController.GAME_DRIVER_ALL_APPS;
import static com.android.settings.development.graphicsdriver.GraphicsDriverEnableForAllAppsPreferenceController.GAME_DRIVER_DEFAULT;
import static com.android.settings.development.graphicsdriver.GraphicsDriverEnableForAllAppsPreferenceController.GAME_DRIVER_OFF;
import static com.android.settings.development.graphicsdriver.GraphicsDriverEnableForAllAppsPreferenceController.UPDATABLE_DRIVER_DEFAULT;
import static com.android.settings.development.graphicsdriver.GraphicsDriverEnableForAllAppsPreferenceController.UPDATABLE_DRIVER_OFF;
import static com.android.settings.development.graphicsdriver.GraphicsDriverEnableForAllAppsPreferenceController.UPDATABLE_DRIVER_PRODUCTION_ALL_APPS;
import static com.google.common.truth.Truth.assertThat;
@@ -68,24 +68,26 @@ public class GraphicsDriverFooterPreferenceControllerTest {
}
@Test
public void getAvailabilityStatus_gameDriverOff_availableUnsearchable() {
Settings.Global.putInt(mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_OFF);
public void getAvailabilityStatus_updatableDriverOff_availableUnsearchable() {
Settings.Global.putInt(mResolver, Settings.Global.UPDATABLE_DRIVER_ALL_APPS,
UPDATABLE_DRIVER_OFF);
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE_UNSEARCHABLE);
}
@Test
public void getAvailabilityStatus_gameDriverDefault_conditionallyUnavailable() {
public void getAvailabilityStatus_updatableDriverDefault_conditionallyUnavailable() {
Settings.Global.putInt(
mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT);
mResolver, Settings.Global.UPDATABLE_DRIVER_ALL_APPS, UPDATABLE_DRIVER_DEFAULT);
assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
}
@Test
public void getAvailabilityStatus_gameDriverAllApps_conditionallyUnavailable() {
public void getAvailabilityStatus_updatableProductionDriverAllApps_conditionallyUnavailable() {
Settings.Global.putInt(
mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_ALL_APPS);
mResolver, Settings.Global.UPDATABLE_DRIVER_ALL_APPS,
UPDATABLE_DRIVER_PRODUCTION_ALL_APPS);
assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
}

View File

@@ -16,8 +16,8 @@
package com.android.settings.development.graphicsdriver;
import static com.android.settings.development.graphicsdriver.GraphicsDriverEnableForAllAppsPreferenceController.GAME_DRIVER_DEFAULT;
import static com.android.settings.development.graphicsdriver.GraphicsDriverEnableForAllAppsPreferenceController.GAME_DRIVER_OFF;
import static com.android.settings.development.graphicsdriver.GraphicsDriverEnableForAllAppsPreferenceController.UPDATABLE_DRIVER_DEFAULT;
import static com.android.settings.development.graphicsdriver.GraphicsDriverEnableForAllAppsPreferenceController.UPDATABLE_DRIVER_OFF;
import static com.google.common.truth.Truth.assertThat;
@@ -61,9 +61,9 @@ public class GraphicsDriverGlobalSwitchBarControllerTest {
}
@Test
public void constructor_gameDriverOn_shouldCheckSwitchBar() {
public void constructor_updatableDriverOn_shouldCheckSwitchBar() {
Settings.Global.putInt(
mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT);
mResolver, Settings.Global.UPDATABLE_DRIVER_ALL_APPS, UPDATABLE_DRIVER_DEFAULT);
mController = new GraphicsDriverGlobalSwitchBarController(
mContext, new SwitchBarController(mSwitchBar));
@@ -71,8 +71,9 @@ public class GraphicsDriverGlobalSwitchBarControllerTest {
}
@Test
public void constructor_gameDriverOff_shouldUncheckSwitchBar() {
Settings.Global.putInt(mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_OFF);
public void constructor_updatableDriverOff_shouldUncheckSwitchBar() {
Settings.Global.putInt(mResolver, Settings.Global.UPDATABLE_DRIVER_ALL_APPS,
UPDATABLE_DRIVER_OFF);
mController = new GraphicsDriverGlobalSwitchBarController(
mContext, new SwitchBarController(mSwitchBar));
@@ -122,27 +123,30 @@ public class GraphicsDriverGlobalSwitchBarControllerTest {
}
@Test
public void onSwitchToggled_checked_shouldTurnOnGameDriver() {
Settings.Global.putInt(mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_OFF);
public void onSwitchToggled_checked_shouldTurnOnUpdatableDriver() {
Settings.Global.putInt(mResolver, Settings.Global.UPDATABLE_DRIVER_ALL_APPS,
UPDATABLE_DRIVER_OFF);
mController = new GraphicsDriverGlobalSwitchBarController(
mContext, new SwitchBarController(mSwitchBar));
mController.onSwitchToggled(true);
assertThat(Settings.Global.getInt(
mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT))
.isEqualTo(GAME_DRIVER_DEFAULT);
mResolver, Settings.Global.UPDATABLE_DRIVER_ALL_APPS,
UPDATABLE_DRIVER_DEFAULT))
.isEqualTo(UPDATABLE_DRIVER_DEFAULT);
}
@Test
public void onSwitchToggled_unchecked_shouldTurnOffGameDriver() {
public void onSwitchToggled_unchecked_shouldTurnOffUpdatableDriver() {
Settings.Global.putInt(
mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT);
mResolver, Settings.Global.UPDATABLE_DRIVER_ALL_APPS, UPDATABLE_DRIVER_DEFAULT);
mController = new GraphicsDriverGlobalSwitchBarController(
mContext, new SwitchBarController(mSwitchBar));
mController.onSwitchToggled(false);
assertThat(Settings.Global.getInt(
mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT))
.isEqualTo(GAME_DRIVER_OFF);
mResolver, Settings.Global.UPDATABLE_DRIVER_ALL_APPS,
UPDATABLE_DRIVER_DEFAULT))
.isEqualTo(UPDATABLE_DRIVER_OFF);
}
}

View File

@@ -71,25 +71,25 @@ public class ContextualCardLoaderTest {
}
@Test
public void getDisplayableCards_twoEligibleCards_shouldShowAll() {
public void getDisplayableCards_twoEligibleCards_notExceedDefaultCardCount() {
final List<ContextualCard> cards = getContextualCardList().stream().limit(2)
.collect(Collectors.toList());
doReturn(cards).when(mContextualCardLoader).filterEligibleCards(anyList());
final List<ContextualCard> result = mContextualCardLoader.getDisplayableCards(cards);
assertThat(result).hasSize(cards.size());
assertThat(result).hasSize(Math.min(cards.size(), DEFAULT_CARD_COUNT));
}
@Test
public void getDisplayableCards_fourEligibleCards_shouldShowDefaultCardCount() {
public void getDisplayableCards_fourEligibleCards_notExceedDefaultCardCount() {
final List<ContextualCard> cards = getContextualCardList().stream().limit(4)
.collect(Collectors.toList());
doReturn(cards).when(mContextualCardLoader).filterEligibleCards(anyList());
final List<ContextualCard> result = mContextualCardLoader.getDisplayableCards(cards);
assertThat(result).hasSize(DEFAULT_CARD_COUNT);
assertThat(result).hasSize(Math.min(cards.size(), DEFAULT_CARD_COUNT));
}
@Test
@@ -139,7 +139,7 @@ public class ContextualCardLoaderTest {
@Test
public void getCardCount_noConfiguredCardCount_returnDefaultCardCount() {
assertThat(mContextualCardLoader.getCardCount()).isEqualTo(DEFAULT_CARD_COUNT);
assertThat(mContextualCardLoader.getCardCount(mContext)).isEqualTo(DEFAULT_CARD_COUNT);
}
@Test
@@ -148,7 +148,7 @@ public class ContextualCardLoaderTest {
Settings.Global.putLong(mContext.getContentResolver(),
ContextualCardLoader.CONTEXTUAL_CARD_COUNT, configCount);
assertThat(mContextualCardLoader.getCardCount()).isEqualTo(configCount);
assertThat(mContextualCardLoader.getCardCount(mContext)).isEqualTo(configCount);
}
private List<ContextualCard> getContextualCardList() {

View File

@@ -16,6 +16,7 @@
package com.android.settings.homepage.contextualcards;
import static com.android.settings.homepage.contextualcards.ContextualCardLoader.CONTEXTUAL_CARD_COUNT;
import static com.android.settings.homepage.contextualcards.ContextualCardManager.KEY_CONTEXTUAL_CARDS;
import static com.android.settings.homepage.contextualcards.slices.SliceContextualCardRenderer.VIEW_TYPE_FULL_WIDTH;
import static com.android.settings.homepage.contextualcards.slices.SliceContextualCardRenderer.VIEW_TYPE_HALF_WIDTH;
@@ -307,7 +308,7 @@ public class ContextualCardManagerTest {
}
@Test
public void onFinishCardLoading_fastLoad_shouldCallOnContextualCardUpdated() {
public void onFinishCardLoading_fastLoad_shouldUpdateContextualCard() {
mManager.mStartTime = System.currentTimeMillis();
final ContextualCardManager manager = spy(mManager);
doNothing().when(manager).onContextualCardUpdated(anyMap());
@@ -318,7 +319,7 @@ public class ContextualCardManagerTest {
}
@Test
public void onFinishCardLoading_slowLoad_shouldSkipOnContextualCardUpdated() {
public void onFinishCardLoading_slowLoadAndNoCard_shouldNotUpdateContextualCard() {
mManager.mStartTime = 0;
final ContextualCardManager manager = spy(mManager);
doNothing().when(manager).onContextualCardUpdated(anyMap());
@@ -328,6 +329,30 @@ public class ContextualCardManagerTest {
verify(manager, never()).onContextualCardUpdated(anyMap());
}
@Test
public void onFinishCardLoading_slowLoadAndNotPreAllocateSpace_shouldNotUpdateContextualCard() {
mManager.mStartTime = 0;
Settings.Global.putInt(mContext.getContentResolver(), CONTEXTUAL_CARD_COUNT, 3);
final ContextualCardManager manager = spy(mManager);
doNothing().when(manager).onContextualCardUpdated(anyMap());
manager.onFinishCardLoading(Arrays.asList(buildContextualCard(TEST_SLICE_URI)));
verify(manager, never()).onContextualCardUpdated(anyMap());
}
@Test
public void onFinishCardLoading_slowLoadAndPreAllocateSpace_shouldUpdateContextualCard() {
mManager.mStartTime = 0;
Settings.Global.putInt(mContext.getContentResolver(), CONTEXTUAL_CARD_COUNT, 1);
final ContextualCardManager manager = spy(mManager);
doNothing().when(manager).onContextualCardUpdated(anyMap());
manager.onFinishCardLoading(Arrays.asList(buildContextualCard(TEST_SLICE_URI)));
verify(manager).onContextualCardUpdated(anyMap());
}
@Test
public void onFinishCardLoading_newLaunch_twoLoadedCards_shouldShowTwoCards() {
mManager.mStartTime = System.currentTimeMillis();

View File

@@ -32,6 +32,7 @@ import static org.mockito.Mockito.when;
import android.content.Context;
import android.content.Intent;
import android.media.MediaRouter2Manager;
import android.media.RoutingSessionInfo;
import android.net.Uri;
@@ -87,6 +88,7 @@ public class RemoteMediaSliceTest {
SliceProvider.setSpecs(SliceLiveData.SUPPORTED_SPECS);
mRemoteMediaSlice = new RemoteMediaSlice(mContext);
mRemoteMediaSlice.mRouterManager = mock(MediaRouter2Manager.class);
sMediaDeviceUpdateWorker = spy(new MediaDeviceUpdateWorker(mContext,
REMOTE_MEDIA_SLICE_URI));
sMediaDeviceUpdateWorker.mLocalMediaManager = mLocalMediaManager;

View File

@@ -0,0 +1,88 @@
/*
* Copyright (C) 2020 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.network;
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.when;
import android.content.Context;
import android.content.res.Resources;
import android.provider.Settings;
import com.android.settings.R;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
@RunWith(RobolectricTestRunner.class)
public class AdaptiveConnectivityPreferenceControllerTest {
private static final String PREF_KEY = "adaptive_connectivity";
private Context mContext;
@Mock private Resources mResources;
private AdaptiveConnectivityPreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
doReturn(mResources).when(mContext).getResources();
mController = new AdaptiveConnectivityPreferenceController(mContext, PREF_KEY);
}
@Test
public void isAvailable_supportAdaptiveConnectivity_shouldReturnTrue() {
when(mResources.getBoolean(R.bool.config_show_adaptive_connectivity))
.thenReturn(true);
assertThat(mController.isAvailable()).isTrue();
}
@Test
public void isAvailable_notSupportAdaptiveConnectivity_shouldReturnFalse() {
when(mResources.getBoolean(R.bool.config_show_adaptive_connectivity))
.thenReturn(false);
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void getSummary_adaptiveConnectivityEnabled_shouldShowOn() {
Settings.Secure.putInt(mContext.getContentResolver(),
Settings.Secure.ADAPTIVE_CONNECTIVITY_ENABLED, 1);
assertThat(mController.getSummary()).isEqualTo(mContext.getString(R.string.switch_on_text));
}
@Test
public void getSummary_adaptiveConnectivityEnabled_shouldShowOff() {
Settings.Secure.putInt(mContext.getContentResolver(),
Settings.Secure.ADAPTIVE_CONNECTIVITY_ENABLED, 0);
assertThat(mController.getSummary())
.isEqualTo(mContext.getString(R.string.switch_off_text));
}
}

View File

@@ -0,0 +1,77 @@
/*
* Copyright (C) 2020 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.network;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Answers.RETURNS_DEEP_STUBS;
import android.content.Context;
import android.provider.Settings;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
@RunWith(RobolectricTestRunner.class)
public class AdaptiveConnectivityTogglePreferenceControllerTest {
private static final String PREF_KEY = "adaptive_connectivity";
@Mock(answer = RETURNS_DEEP_STUBS)
private Context mContext;
private AdaptiveConnectivityTogglePreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mController = new AdaptiveConnectivityTogglePreferenceController(mContext, PREF_KEY);
}
@Test
public void isAvailable_shouldReturnTrue() {
assertThat(mController.isAvailable()).isTrue();
}
@Test
public void setChecked_withTrue_shouldUpdateSetting() {
Settings.Secure.putInt(mContext.getContentResolver(),
Settings.Secure.ADAPTIVE_CONNECTIVITY_ENABLED, 0);
mController.setChecked(true);
assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.ADAPTIVE_CONNECTIVITY_ENABLED, 1))
.isEqualTo(1);
}
@Test
public void setChecked_withFalse_shouldUpdateSetting() {
Settings.Secure.putInt(mContext.getContentResolver(),
Settings.Secure.ADAPTIVE_CONNECTIVITY_ENABLED, 1);
mController.setChecked(false);
assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.ADAPTIVE_CONNECTIVITY_ENABLED, 1))
.isEqualTo(0);
}
}

View File

@@ -29,15 +29,12 @@ import static org.mockito.Mockito.when;
import android.content.Context;
import androidx.lifecycle.LifecycleOwner;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceScreen;
import com.android.settings.wifi.WifiConnectionPreferenceController;
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.wifi.WifiEntryPreference;
import com.android.wifitrackerlib.WifiEntry;
import com.android.wifitrackerlib.WifiPickerTracker;
import com.android.settingslib.wifi.AccessPoint;
import com.android.settingslib.wifi.AccessPointPreference;
import com.android.settingslib.wifi.WifiTracker;
import com.android.settingslib.wifi.WifiTrackerFactory;
import org.junit.Before;
import org.junit.Test;
@@ -48,12 +45,19 @@ import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import java.util.ArrayList;
import java.util.Arrays;
import androidx.lifecycle.LifecycleOwner;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceScreen;
@RunWith(RobolectricTestRunner.class)
public class WifiConnectionPreferenceControllerTest {
private static final String KEY = "wifi_connection";
@Mock
WifiPickerTracker mWifiPickerTracker;
WifiTracker mWifiTracker;
@Mock
PreferenceScreen mScreen;
@Mock
@@ -70,6 +74,7 @@ public class WifiConnectionPreferenceControllerTest {
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
WifiTrackerFactory.setTestingWifiTracker(mWifiTracker);
mLifecycleOwner = () -> mLifecycle;
mLifecycle = new Lifecycle(mLifecycleOwner);
when(mScreen.findPreference(eq(KEY))).thenReturn(mPreferenceCategory);
@@ -78,51 +83,49 @@ public class WifiConnectionPreferenceControllerTest {
mController = new WifiConnectionPreferenceController(mContext, mLifecycle, mUpdateListener,
KEY, 0, 0);
mController.mWifiPickerTracker = mWifiPickerTracker;
}
@Test
public void isAvailable_noConnectedWifiEntry_availableIsFalse() {
when(mWifiPickerTracker.getConnectedWifiEntry()).thenReturn(null);
public void isAvailable_noWiFiConnection_availableIsFalse() {
when(mWifiTracker.isConnected()).thenReturn(false);
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void displayPreference_noConnectedWifiEntry_noPreferenceAdded() {
when(mWifiPickerTracker.getConnectedWifiEntry()).thenReturn(null);
public void displayPreference_noWiFiConnection_noPreferenceAdded() {
when(mWifiTracker.isConnected()).thenReturn(false);
when(mWifiTracker.getAccessPoints()).thenReturn(new ArrayList<>());
mController.displayPreference(mScreen);
verify(mPreferenceCategory, never()).addPreference(any());
}
@Test
public void displayPreference_hasConnectedWifiEntry_preferenceAdded() {
final WifiEntry wifiEntry = mock(WifiEntry.class);
when(mWifiPickerTracker.getConnectedWifiEntry()).thenReturn(wifiEntry);
public void displayPreference_hasWiFiConnection_preferenceAdded() {
when(mWifiTracker.isConnected()).thenReturn(true);
final AccessPoint accessPoint = mock(AccessPoint.class);
when(accessPoint.isActive()).thenReturn(true);
when(mWifiTracker.getAccessPoints()).thenReturn(Arrays.asList(accessPoint));
mController.displayPreference(mScreen);
verify(mPreferenceCategory).addPreference(any(WifiEntryPreference.class));
verify(mPreferenceCategory).addPreference(any(AccessPointPreference.class));
}
@Test
public void onConnectedChanged_wifiBecameDisconnected_preferenceRemoved() {
final WifiEntry wifiEntry = mock(WifiEntry.class);
when(mWifiPickerTracker.getConnectedWifiEntry()).thenReturn(wifiEntry);
when(mWifiTracker.isConnected()).thenReturn(true);
final AccessPoint accessPoint = mock(AccessPoint.class);
when(accessPoint.isActive()).thenReturn(true);
when(mWifiTracker.getAccessPoints()).thenReturn(Arrays.asList(accessPoint));
mController.displayPreference(mScreen);
final ArgumentCaptor<WifiEntryPreference> captor = ArgumentCaptor.forClass(
WifiEntryPreference.class);
final ArgumentCaptor<AccessPointPreference> captor = ArgumentCaptor.forClass(
AccessPointPreference.class);
verify(mPreferenceCategory).addPreference(captor.capture());
final WifiEntryPreference pref = captor.getValue();
final AccessPointPreference pref = captor.getValue();
// Become disconnected.
when(mWifiPickerTracker.getConnectedWifiEntry()).thenReturn(null);
when(mWifiTracker.isConnected()).thenReturn(false);
when(mWifiTracker.getAccessPoints()).thenReturn(new ArrayList<>());
final int onUpdatedCountBefore = mOnChildUpdatedCount;
mController.onWifiStateChanged();
mController.onConnectedChanged();
verify(mPreferenceCategory).removePreference(pref);
assertThat(mOnChildUpdatedCount).isEqualTo(onUpdatedCountBefore + 1);
}
@@ -130,24 +133,28 @@ public class WifiConnectionPreferenceControllerTest {
@Test
public void onAccessPointsChanged_wifiBecameConnectedToDifferentAP_preferenceReplaced() {
final WifiEntry wifiEntry1 = mock(WifiEntry.class);
when(wifiEntry1.getKey()).thenReturn("KEY_1");
when(mWifiPickerTracker.getConnectedWifiEntry()).thenReturn(wifiEntry1);
mController.displayPreference(mScreen);
final ArgumentCaptor<WifiEntryPreference> captor = ArgumentCaptor.forClass(
WifiEntryPreference.class);
when(mWifiTracker.isConnected()).thenReturn(true);
final AccessPoint accessPoint1 = mock(AccessPoint.class);
final WifiEntry wifiEntry2 = mock(WifiEntry.class);
when(wifiEntry1.getKey()).thenReturn("KEY_2");
when(mWifiPickerTracker.getConnectedWifiEntry()).thenReturn(wifiEntry2);
when(accessPoint1.isActive()).thenReturn(true);
when(mWifiTracker.getAccessPoints()).thenReturn(Arrays.asList(accessPoint1));
mController.displayPreference(mScreen);
final ArgumentCaptor<AccessPointPreference> captor = ArgumentCaptor.forClass(
AccessPointPreference.class);
final AccessPoint accessPoint2 = mock(AccessPoint.class);
when(accessPoint1.isActive()).thenReturn(false);
when(accessPoint2.isActive()).thenReturn(true);
when(mWifiTracker.getAccessPoints()).thenReturn(Arrays.asList(accessPoint1, accessPoint2));
final int onUpdatedCountBefore = mOnChildUpdatedCount;
mController.onWifiEntriesChanged();
mController.onAccessPointsChanged();
verify(mPreferenceCategory, times(2)).addPreference(captor.capture());
final WifiEntryPreference pref1 = captor.getAllValues().get(0);
final WifiEntryPreference pref2 = captor.getAllValues().get(1);
assertThat(pref1.getWifiEntry()).isEqualTo(wifiEntry1);
assertThat(pref2.getWifiEntry()).isEqualTo(wifiEntry2);
final AccessPointPreference pref1 = captor.getAllValues().get(0);
final AccessPointPreference pref2 = captor.getAllValues().get(1);
assertThat(pref1.getAccessPoint()).isEqualTo(accessPoint1);
assertThat(pref2.getAccessPoint()).isEqualTo(accessPoint2);
verify(mPreferenceCategory).removePreference(eq(pref1));
assertThat(mOnChildUpdatedCount).isEqualTo(onUpdatedCountBefore + 1);
}

View File

@@ -19,6 +19,7 @@ package com.android.settings.notification;
import static android.provider.Settings.Global.NOTIFICATION_BUBBLES;
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
import static com.android.settings.notification.BadgingNotificationPreferenceController.OFF;
import static com.android.settings.notification.BadgingNotificationPreferenceController.ON;
@@ -29,6 +30,7 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.app.ActivityManager;
import android.content.Context;
import android.provider.Settings;
@@ -44,6 +46,8 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.shadow.api.Shadow;
import org.robolectric.shadows.ShadowActivityManager;
@RunWith(RobolectricTestRunner.class)
public class BubbleNotificationPreferenceControllerTest {
@@ -69,7 +73,18 @@ public class BubbleNotificationPreferenceControllerTest {
}
@Test
public void getAvilabilityStatus_returnsAvailable() {
public void isAvailable_lowRam_returnsUnsupported() {
final ShadowActivityManager activityManager =
Shadow.extract(mContext.getSystemService(ActivityManager.class));
activityManager.setIsLowRamDevice(true);
assertEquals(UNSUPPORTED_ON_DEVICE, mController.getAvailabilityStatus());
}
@Test
public void isAvailable_notLowRam_returnsAvailable() {
final ShadowActivityManager activityManager =
Shadow.extract(mContext.getSystemService(ActivityManager.class));
activityManager.setIsLowRamDevice(false);
assertEquals(AVAILABLE, mController.getAvailabilityStatus());
}

View File

@@ -18,11 +18,14 @@ package com.android.settings.notification;
import static android.provider.Settings.Global.NOTIFICATION_BUBBLES;
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
import static com.android.settings.notification.BadgingNotificationPreferenceController.OFF;
import static com.android.settings.notification.BadgingNotificationPreferenceController.ON;
import static com.google.common.truth.Truth.assertThat;
import android.app.ActivityManager;
import android.content.Context;
import android.provider.Settings;
@@ -35,6 +38,8 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.shadow.api.Shadow;
import org.robolectric.shadows.ShadowActivityManager;
@RunWith(RobolectricTestRunner.class)
public class BubbleSummaryNotificationPreferenceControllerTest {
@@ -68,4 +73,20 @@ public class BubbleSummaryNotificationPreferenceControllerTest {
String onString = mContext.getString(R.string.notifications_bubble_setting_on_summary);
assertThat(mController.getSummary()).isEqualTo(onString);
}
@Test
public void isAvailable_lowRam_returnsUnsupported() {
final ShadowActivityManager activityManager =
Shadow.extract(mContext.getSystemService(ActivityManager.class));
activityManager.setIsLowRamDevice(true);
assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
}
@Test
public void isAvailable_notLowRam_returnsAvailable() {
final ShadowActivityManager activityManager =
Shadow.extract(mContext.getSystemService(ActivityManager.class));
activityManager.setIsLowRamDevice(false);
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
}
}

View File

@@ -30,6 +30,7 @@ import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageStats;
import android.media.MediaRouter2Manager;
import android.media.RoutingSessionInfo;
import androidx.preference.Preference;
@@ -94,6 +95,7 @@ public class RemoteVolumeGroupControllerTest {
mContext = RuntimeEnvironment.application;
mController = new RemoteVolumeGroupController(mContext, KEY_REMOTE_VOLUME_GROUP);
mController.mLocalMediaManager = mLocalMediaManager;
mController.mRouterManager = mock(MediaRouter2Manager.class);
mPreferenceCategory = spy(new PreferenceCategory(mContext));
mPreferenceCategory.setKey(mController.getPreferenceKey());

View File

@@ -368,6 +368,7 @@ public class BlockPreferenceControllerTest {
public void testOnSwitchChanged_channel_nonDefault() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("a", "a", IMPORTANCE_HIGH);
channel.setOriginalImportance(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null, null, null);
mController.updateState(mPreference);
@@ -375,7 +376,7 @@ public class BlockPreferenceControllerTest {
assertEquals(IMPORTANCE_NONE, channel.getImportance());
mController.onSwitchChanged(null, true);
assertEquals(IMPORTANCE_DEFAULT, channel.getImportance());
assertEquals(IMPORTANCE_HIGH, channel.getImportance());
verify(mBackend, times(2)).updateChannel(any(), anyInt(), any());
}

View File

@@ -42,6 +42,7 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.app.ActivityManager;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
@@ -67,7 +68,9 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.shadow.api.Shadow;
import org.robolectric.shadows.ShadowApplication;
import org.robolectric.shadows.ShadowActivityManager;
import java.util.ArrayList;
import java.util.List;
@@ -137,7 +140,7 @@ public class BubblePreferenceControllerTest {
}
@Test
public void isAvailable_channel_yesIfAppOff() {
public void isAvailable_channel_notIfAppOff() {
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.bubblePreference = BUBBLE_PREFERENCE_NONE;
@@ -145,7 +148,7 @@ public class BubblePreferenceControllerTest {
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null, null, null);
assertTrue(mController.isAvailable());
assertFalse(mController.isAvailable());
}
@Test
@@ -158,6 +161,18 @@ public class BubblePreferenceControllerTest {
assertFalse(mController.isAvailable());
}
@Test
public void isNotAvailable_ifLowRam() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
mController.onResume(appRow, null, null, null, null, null);
final ShadowActivityManager activityManager =
Shadow.extract(mContext.getSystemService(ActivityManager.class));
activityManager.setIsLowRamDevice(true);
assertFalse(mController.isAvailable());
}
@Test
public void isAvailable_notIfOffGlobally_channel() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
@@ -170,6 +185,18 @@ public class BubblePreferenceControllerTest {
assertFalse(mController.isAvailable());
}
@Test
public void isAvailable_ifNotLowRam() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
mController.onResume(appRow, null, null, null, null, null);
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
final ShadowActivityManager activityManager =
Shadow.extract(mContext.getSystemService(ActivityManager.class));
activityManager.setIsLowRamDevice(false);
assertTrue(mController.isAvailable());
}
@Test
public void isAvailable_app_evenIfOffGlobally() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();

View File

@@ -23,6 +23,8 @@ import static android.app.NotificationManager.BUBBLE_PREFERENCE_SELECTED;
import static android.app.NotificationManager.IMPORTANCE_HIGH;
import static android.provider.Settings.Global.NOTIFICATION_BUBBLES;
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
import static com.android.settings.notification.app.BubblePreferenceController.SYSTEM_WIDE_OFF;
import static com.android.settings.notification.app.BubblePreferenceController.SYSTEM_WIDE_ON;
@@ -37,6 +39,7 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import android.app.ActivityManager;
import android.app.NotificationChannel;
import android.content.Context;
import android.provider.Settings;
@@ -53,6 +56,8 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.shadow.api.Shadow;
import org.robolectric.shadows.ShadowActivityManager;
import org.robolectric.shadows.ShadowApplication;
@RunWith(RobolectricTestRunner.class)
@@ -139,6 +144,28 @@ public class BubbleSummaryPreferenceControllerTest {
assertTrue(mController.isAvailable());
}
@Test
public void isAvailable_lowRam_shouldReturnFalse() {
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
mController.onResume(mAppRow, null, null, null, null, null);
final ShadowActivityManager activityManager =
Shadow.extract(mContext.getSystemService(ActivityManager.class));
activityManager.setIsLowRamDevice(true);
assertFalse(mController.isAvailable());
}
@Test
public void isAvailable_notLowRam_shouldReturnTrue() {
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
mController.onResume(mAppRow, null, null, null, null, null);
final ShadowActivityManager activityManager =
Shadow.extract(mContext.getSystemService(ActivityManager.class));
activityManager.setIsLowRamDevice(false);
assertTrue(mController.isAvailable());
}
@Test
public void updateState_setsIntent() {
mAppRow.bubblePreference = BUBBLE_PREFERENCE_ALL;

View File

@@ -68,10 +68,6 @@ public class ConversationPriorityPreferenceTest {
final LayoutInflater inflater = LayoutInflater.from(mContext);
PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(
inflater.inflate(preference.getLayoutResource(), null));
Drawable unselected = mock(Drawable.class);
Drawable selected = mock(Drawable.class);
preference.selectedBackground = selected;
preference.unselectedBackground = unselected;
preference.setConfigurable(false);
preference.setImportance(IMPORTANCE_DEFAULT);
@@ -81,35 +77,6 @@ public class ConversationPriorityPreferenceTest {
assertThat(holder.itemView.findViewById(R.id.silence).isEnabled()).isFalse();
assertThat(holder.itemView.findViewById(R.id.priority_group).isEnabled()).isFalse();
assertThat(holder.itemView.findViewById(R.id.alert).isEnabled()).isFalse();
assertThat(holder.itemView.findViewById(R.id.priority_group).getBackground())
.isEqualTo(selected);
assertThat(holder.itemView.findViewById(R.id.alert).getBackground()).isEqualTo(unselected);
assertThat(holder.itemView.findViewById(R.id.silence).getBackground())
.isEqualTo(unselected);
// other button
preference.setPriorityConversation(false);
holder = PreferenceViewHolder.createInstanceForTests(
inflater.inflate(preference.getLayoutResource(), null));
preference.onBindViewHolder(holder);
assertThat(holder.itemView.findViewById(R.id.alert).getBackground()).isEqualTo(selected);
assertThat(holder.itemView.findViewById(R.id.silence).getBackground())
.isEqualTo(unselected);
assertThat(holder.itemView.findViewById(R.id.priority_group).getBackground())
.isEqualTo(unselected);
// other other button
preference.setImportance(IMPORTANCE_LOW);
holder = PreferenceViewHolder.createInstanceForTests(
inflater.inflate(preference.getLayoutResource(), null));
preference.onBindViewHolder(holder);
assertThat(holder.itemView.findViewById(R.id.priority_group).getBackground())
.isEqualTo(unselected);
assertThat(holder.itemView.findViewById(R.id.alert).getBackground()).isEqualTo(unselected);
assertThat(holder.itemView.findViewById(R.id.silence).getBackground()).isEqualTo(selected);
}
@Test
@@ -119,10 +86,6 @@ public class ConversationPriorityPreferenceTest {
final LayoutInflater inflater = LayoutInflater.from(mContext);
final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(
inflater.inflate(preference.getLayoutResource(), null));
Drawable unselected = mock(Drawable.class);
Drawable selected = mock(Drawable.class);
preference.selectedBackground = selected;
preference.unselectedBackground = unselected;
preference.setConfigurable(true);
preference.setImportance(IMPORTANCE_LOW);
@@ -130,12 +93,8 @@ public class ConversationPriorityPreferenceTest {
preference.onBindViewHolder(holder);
assertThat(holder.itemView.findViewById(R.id.priority_group).getBackground())
.isEqualTo(unselected);
assertThat(holder.itemView.findViewById(R.id.alert).getBackground()).isEqualTo(unselected);
assertThat(holder.itemView.findViewById(R.id.silence).getBackground())
.isEqualTo(selected);
assertThat(holder.itemView.findViewById(R.id.silence_summary).getVisibility())
assertThat(holder.itemView.findViewById(R.id.silence)
.findViewById(R.id.summary).getVisibility())
.isEqualTo(View.VISIBLE);
}
@@ -146,10 +105,6 @@ public class ConversationPriorityPreferenceTest {
final LayoutInflater inflater = LayoutInflater.from(mContext);
final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(
inflater.inflate(preference.getLayoutResource(), null));
Drawable unselected = mock(Drawable.class);
Drawable selected = mock(Drawable.class);
preference.selectedBackground = selected;
preference.unselectedBackground = unselected;
preference.setConfigurable(true);
preference.setImportance(IMPORTANCE_DEFAULT);
@@ -161,12 +116,6 @@ public class ConversationPriorityPreferenceTest {
silenceButton.callOnClick();
assertThat(holder.itemView.findViewById(R.id.alert).getBackground()).isEqualTo(unselected);
assertThat(holder.itemView.findViewById(R.id.priority_group).getBackground())
.isEqualTo(unselected);
assertThat(holder.itemView.findViewById(R.id.silence).getBackground())
.isEqualTo(selected);
verify(preference, times(1)).callChangeListener(new Pair(IMPORTANCE_LOW, false));
}
}

View File

@@ -317,4 +317,20 @@ public class MediaOutputPanelTest {
public void getViewType_checkType() {
assertThat(mPanel.getViewType()).isEqualTo(PanelContent.VIEW_TYPE_SLIDER_LARGE_ICON);
}
@Test
public void getIcon_mediaControllerIsNull_returnNull() {
mMediaControllers.clear();
mPanel.onStart();
assertThat(mPanel.getIcon()).isNull();
}
@Test
public void getIcon_mediaMetadataIsNull_returnNull() {
mPanel.onStart();
when(mMediaController.getMetadata()).thenReturn(null);
assertThat(mPanel.getIcon()).isNull();
}
}

View File

@@ -26,6 +26,7 @@ import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -36,6 +37,9 @@ import android.os.Build;
import android.view.Window;
import android.view.WindowManager;
import androidx.fragment.app.FragmentManager;
import com.android.settings.R;
import com.android.settings.core.HideNonSystemOverlayMixin;
import com.android.settings.testutils.FakeFeatureFactory;
@@ -43,6 +47,7 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
@@ -56,6 +61,10 @@ public class SettingsPanelActivityTest {
private FakeSettingsPanelActivity mSettingsPanelActivity;
private PanelFeatureProvider mPanelFeatureProvider;
private FakePanelContent mFakePanelContent;
@Mock
private PanelFragment mPanelFragment;
@Mock
private FragmentManager mFragmentManager;
@Before
public void setUp() {
@@ -67,6 +76,10 @@ public class SettingsPanelActivityTest {
mFakeFeatureFactory.panelFeatureProvider = mPanelFeatureProvider;
mFakePanelContent = new FakePanelContent();
doReturn(mFakePanelContent).when(mPanelFeatureProvider).getPanel(any(), any());
mSettingsPanelActivity.mPanelFragment = mPanelFragment;
when(mFragmentManager.findFragmentById(R.id.main_content)).thenReturn(mPanelFragment);
when(mSettingsPanelActivity.getSupportFragmentManager()).thenReturn(mFragmentManager);
}
@Test
@@ -141,11 +154,62 @@ public class SettingsPanelActivityTest {
& SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS).isEqualTo(0);
}
@Test
public void onStop_panelIsNotCreating_shouldForceUpdate() {
mSettingsPanelActivity.mForceCreation = false;
when(mPanelFragment.isPanelCreating()).thenReturn(false);
mSettingsPanelActivity.mPanelFragment = mPanelFragment;
mSettingsPanelActivity.onStop();
assertThat(mSettingsPanelActivity.mForceCreation).isTrue();
}
@Test
public void onStop_panelIsCreating_shouldNotForceUpdate() {
mSettingsPanelActivity.mForceCreation = false;
when(mPanelFragment.isPanelCreating()).thenReturn(true);
mSettingsPanelActivity.mPanelFragment = mPanelFragment;
mSettingsPanelActivity.onStop();
assertThat(mSettingsPanelActivity.mForceCreation).isFalse();
}
@Test
public void onConfigurationChanged_shouldForceUpdate() {
mSettingsPanelActivity.mForceCreation = false;
mSettingsPanelActivity.onConfigurationChanged(new Configuration());
assertThat(mSettingsPanelActivity.mForceCreation).isTrue();
}
@Test
public void onNewIntent_panelIsNotCreating_shouldUpdatePanel() {
when(mPanelFragment.isPanelCreating()).thenReturn(false);
mSettingsPanelActivity.onNewIntent(mSettingsPanelActivity.getIntent());
verify(mPanelFragment).updatePanelWithAnimation();
}
@Test
public void onNewIntent_panelIsCreating_shouldNotUpdatePanel() {
when(mPanelFragment.isPanelCreating()).thenReturn(true);
mSettingsPanelActivity.onNewIntent(mSettingsPanelActivity.getIntent());
verify(mPanelFragment, never()).updatePanelWithAnimation();
}
@Test
public void onNewIntent_panelIsShowingTheSameAction_shouldNotUpdatePanel() {
when(mPanelFragment.isPanelCreating()).thenReturn(false);
when(mPanelFragment.getArguments()).thenReturn(mSettingsPanelActivity.mBundle);
mSettingsPanelActivity.onNewIntent(mSettingsPanelActivity.getIntent());
verify(mPanelFragment, never()).updatePanelWithAnimation();
}
}

View File

@@ -0,0 +1,260 @@
/*
* Copyright (C) 2020 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.slices;
import static com.android.settings.slices.CustomSliceRegistry.VOLUME_SLICES_URI;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.media.AudioManager;
import android.net.Uri;
import com.android.settings.notification.MediaVolumePreferenceController;
import com.android.settings.notification.RingVolumePreferenceController;
import com.android.settings.notification.VolumeSeekBarPreferenceController;
import com.android.settingslib.SliceBroadcastRelay;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
import org.robolectric.annotation.Resetter;
@RunWith(RobolectricTestRunner.class)
@Config(shadows = VolumeSliceHelperTest.ShadowSliceBroadcastRelay.class)
public class VolumeSliceHelperTest {
@Mock
private ContentResolver mResolver;
private Context mContext;
private Intent mIntent;
private VolumeSeekBarPreferenceController mMediaController;
private VolumeSeekBarPreferenceController mRingController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
when(mContext.getContentResolver()).thenReturn(mResolver);
mMediaController = new MediaVolumePreferenceController(mContext);
mRingController = new RingVolumePreferenceController(mContext);
mIntent = createIntent(AudioManager.VOLUME_CHANGED_ACTION)
.putExtra(AudioManager.EXTRA_VOLUME_STREAM_VALUE, 1)
.putExtra(AudioManager.EXTRA_PREV_VOLUME_STREAM_VALUE, 2)
.putExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE, mMediaController.getAudioStream());
}
@After
public void cleanUp() {
ShadowSliceBroadcastRelay.reset();
VolumeSliceHelper.sRegisteredUri.clear();
VolumeSliceHelper.sIntentFilter = null;
}
@Test
public void registerIntentToUri_volumeController_shouldRegisterReceiver() {
registerIntentToUri(mMediaController);
assertThat(ShadowSliceBroadcastRelay.getRegisteredCount()).isEqualTo(1);
assertThat(VolumeSliceHelper.sRegisteredUri)
.containsKey((mMediaController.getSliceUri()));
}
@Test
public void registerIntentToUri_doubleVolumeControllers_shouldRegisterReceiverOnce() {
registerIntentToUri(mMediaController);
registerIntentToUri(mRingController);
assertThat(ShadowSliceBroadcastRelay.getRegisteredCount()).isEqualTo(1);
assertThat(VolumeSliceHelper.sRegisteredUri)
.containsKey((mRingController.getSliceUri()));
}
@Test
public void unregisterUri_notFinalUri_shouldNotUnregisterReceiver() {
registerIntentToUri(mMediaController);
registerIntentToUri(mRingController);
VolumeSliceHelper.unregisterUri(mContext, mMediaController.getSliceUri());
assertThat(ShadowSliceBroadcastRelay.getRegisteredCount()).isEqualTo(1);
assertThat(VolumeSliceHelper.sRegisteredUri)
.doesNotContainKey((mMediaController.getSliceUri()));
}
@Test
public void unregisterUri_finalUri_shouldUnregisterReceiver() {
registerIntentToUri(mMediaController);
VolumeSliceHelper.unregisterUri(mContext, mMediaController.getSliceUri());
assertThat(ShadowSliceBroadcastRelay.getRegisteredCount()).isEqualTo(0);
assertThat(VolumeSliceHelper.sRegisteredUri)
.doesNotContainKey((mMediaController.getSliceUri()));
}
@Test
public void unregisterUri_unregisterTwice_shouldUnregisterReceiverOnce() {
registerIntentToUri(mMediaController);
VolumeSliceHelper.unregisterUri(mContext, mMediaController.getSliceUri());
VolumeSliceHelper.unregisterUri(mContext, mMediaController.getSliceUri());
assertThat(ShadowSliceBroadcastRelay.getRegisteredCount()).isEqualTo(0);
}
@Test
public void unregisterUri_notRegistered_shouldNotUnregisterReceiver() {
registerIntentToUri(mMediaController);
VolumeSliceHelper.unregisterUri(mContext, mRingController.getSliceUri());
assertThat(ShadowSliceBroadcastRelay.getRegisteredCount()).isEqualTo(1);
assertThat(VolumeSliceHelper.sRegisteredUri)
.containsKey((mMediaController.getSliceUri()));
}
@Test
public void onReceive_audioStreamRegistered_shouldNotifyChange() {
registerIntentToUri(mMediaController);
VolumeSliceHelper.onReceive(mContext, mIntent);
verify(mResolver).notifyChange(mMediaController.getSliceUri(), null);
}
@Test
public void onReceive_audioStreamNotRegistered_shouldNotNotifyChange() {
VolumeSliceHelper.onReceive(mContext, mIntent);
verify(mResolver, never()).notifyChange(mMediaController.getSliceUri(), null);
}
@Test
public void onReceive_audioStreamNotMatched_shouldNotNotifyChange() {
registerIntentToUri(mMediaController);
mIntent.putExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE, AudioManager.STREAM_DTMF);
VolumeSliceHelper.onReceive(mContext, mIntent);
verify(mResolver, never()).notifyChange(mMediaController.getSliceUri(), null);
}
@Test
public void onReceive_mediaVolumeNotChanged_shouldNotNotifyChange() {
mIntent.putExtra(AudioManager.EXTRA_VOLUME_STREAM_VALUE, 1)
.putExtra(AudioManager.EXTRA_PREV_VOLUME_STREAM_VALUE, 1);
registerIntentToUri(mMediaController);
VolumeSliceHelper.onReceive(mContext, mIntent);
verify(mResolver, never()).notifyChange(mMediaController.getSliceUri(), null);
}
@Test
public void onReceive_streamVolumeMuted_shouldNotifyChange() {
final Intent intent = createIntent(AudioManager.STREAM_MUTE_CHANGED_ACTION)
.putExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE, mMediaController.getAudioStream());
registerIntentToUri(mMediaController);
registerIntentToUri(mRingController);
VolumeSliceHelper.onReceive(mContext, intent);
verify(mResolver).notifyChange(mMediaController.getSliceUri(), null);
}
@Test
public void onReceive_streamDevicesChanged_shouldNotifyChange() {
final Intent intent = createIntent(AudioManager.STREAM_DEVICES_CHANGED_ACTION)
.putExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE, mRingController.getAudioStream());
registerIntentToUri(mMediaController);
registerIntentToUri(mRingController);
VolumeSliceHelper.onReceive(mContext, intent);
verify(mResolver).notifyChange(mRingController.getSliceUri(), null);
}
@Test
public void onReceive_primaryMutedChanged_shouldNotifyChangeAll() {
final Intent intent = createIntent(AudioManager.MASTER_MUTE_CHANGED_ACTION);
registerIntentToUri(mMediaController);
registerIntentToUri(mRingController);
VolumeSliceHelper.onReceive(mContext, intent);
verify(mResolver).notifyChange(mMediaController.getSliceUri(), null);
verify(mResolver).notifyChange(mRingController.getSliceUri(), null);
}
private void registerIntentToUri(VolumeSeekBarPreferenceController controller) {
VolumeSliceHelper.registerIntentToUri(mContext, controller.getIntentFilter(),
controller.getSliceUri(), controller.getAudioStream());
}
private Intent createIntent(String action) {
return new Intent(action)
.putExtra(SliceBroadcastRelay.EXTRA_URI, VOLUME_SLICES_URI.toString());
}
@Implements(SliceBroadcastRelay.class)
public static class ShadowSliceBroadcastRelay {
private static int sRegisteredCount;
@Implementation
public static void registerReceiver(Context context, Uri sliceUri,
Class<? extends BroadcastReceiver> receiver, IntentFilter filter) {
sRegisteredCount++;
}
@Implementation
public static void unregisterReceivers(Context context, Uri sliceUri) {
sRegisteredCount--;
}
@Resetter
static void reset() {
sRegisteredCount = 0;
}
static int getRegisteredCount() {
return sRegisteredCount;
}
}
}

View File

@@ -69,27 +69,27 @@ public class MediaControlsPreferenceControllerTest {
}
@Test
public void setChecked_enable_shouldTurnOff() {
public void setChecked_enable_shouldTurnOn() {
Settings.Global.putInt(mContentResolver, Settings.Global.SHOW_MEDIA_ON_QUICK_SETTINGS, 1);
Settings.Secure.putInt(mContentResolver, Settings.Secure.MEDIA_CONTROLS_RESUME, 1);
assertThat(mController.isChecked()).isFalse();
mController.setChecked(true);
assertThat(Settings.Secure.getInt(mContentResolver,
Settings.Secure.MEDIA_CONTROLS_RESUME, -1)).isEqualTo(0);
}
@Test
public void setChecked_disable_shouldTurnOn() {
Settings.Global.putInt(mContentResolver, Settings.Global.SHOW_MEDIA_ON_QUICK_SETTINGS, 1);
Settings.Secure.putInt(mContentResolver, Settings.Secure.MEDIA_CONTROLS_RESUME, 0);
assertThat(mController.isChecked()).isTrue();
mController.setChecked(false);
assertThat(Settings.Secure.getInt(mContentResolver,
Settings.Secure.MEDIA_CONTROLS_RESUME, -1)).isEqualTo(0);
}
@Test
public void setChecked_disable_shouldTurnOff() {
Settings.Global.putInt(mContentResolver, Settings.Global.SHOW_MEDIA_ON_QUICK_SETTINGS, 1);
Settings.Secure.putInt(mContentResolver, Settings.Secure.MEDIA_CONTROLS_RESUME, 0);
assertThat(mController.isChecked()).isFalse();
mController.setChecked(true);
assertThat(Settings.Secure.getInt(mContentResolver,
Settings.Secure.MEDIA_CONTROLS_RESUME, -1)).isEqualTo(1);
}

View File

@@ -29,6 +29,7 @@ import com.android.settings.bluetooth.BluetoothFeatureProvider;
import com.android.settings.dashboard.DashboardFeatureProvider;
import com.android.settings.dashboard.suggestions.SuggestionFeatureProvider;
import com.android.settings.enterprise.EnterprisePrivacyFeatureProvider;
import com.android.settings.fuelgauge.BatteryStatusFeatureProvider;
import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
import com.android.settings.gestures.AssistGestureFeatureProvider;
import com.android.settings.homepage.contextualcards.ContextualCardFeatureProvider;
@@ -54,6 +55,7 @@ public class FakeFeatureFactory extends FeatureFactory {
public final SupportFeatureProvider supportFeatureProvider;
public final MetricsFeatureProvider metricsFeatureProvider;
public final BatteryStatusFeatureProvider batteryStatusFeatureProvider;
public final PowerUsageFeatureProvider powerUsageFeatureProvider;
public final DashboardFeatureProvider dashboardFeatureProvider;
public final DockUpdaterFeatureProvider dockUpdaterFeatureProvider;
@@ -98,6 +100,7 @@ public class FakeFeatureFactory extends FeatureFactory {
public FakeFeatureFactory() {
supportFeatureProvider = mock(SupportFeatureProvider.class);
metricsFeatureProvider = mock(MetricsFeatureProvider.class);
batteryStatusFeatureProvider = mock(BatteryStatusFeatureProvider.class);
powerUsageFeatureProvider = mock(PowerUsageFeatureProvider.class);
dashboardFeatureProvider = mock(DashboardFeatureProvider.class);
dockUpdaterFeatureProvider = mock(DockUpdaterFeatureProvider.class);
@@ -134,6 +137,11 @@ public class FakeFeatureFactory extends FeatureFactory {
return metricsFeatureProvider;
}
@Override
public BatteryStatusFeatureProvider getBatteryStatusFeatureProvider(Context context) {
return batteryStatusFeatureProvider;
}
@Override
public PowerUsageFeatureProvider getPowerUsageFeatureProvider(Context context) {
return powerUsageFeatureProvider;

View File

@@ -17,6 +17,7 @@
package com.android.settings.testutils.shadow;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
@@ -29,6 +30,7 @@ public class ShadowBluetoothAdapter extends org.robolectric.shadows.ShadowBlueto
private int mState;
private List<Integer> mSupportedProfiles = new ArrayList<>();
private List<BluetoothDevice> mMostRecentlyConnectedDevices = new ArrayList<>();
@Implementation
protected List<Integer> getSupportedProfiles() {
@@ -56,4 +58,13 @@ public class ShadowBluetoothAdapter extends org.robolectric.shadows.ShadowBlueto
protected boolean factoryReset() {
return true;
}
@Implementation
protected List<BluetoothDevice> getMostRecentlyConnectedDevices() {
return mMostRecentlyConnectedDevices;
}
public void setMostRecentlyConnectedDevices(List<BluetoothDevice> list) {
mMostRecentlyConnectedDevices = list;
}
}

View File

@@ -21,6 +21,7 @@ import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.robolectric.Shadows.shadowOf;
import android.content.Context;
import android.content.res.Resources;
@@ -32,6 +33,9 @@ import android.net.wifi.WifiEnterpriseConfig.Phase2;
import android.net.wifi.WifiManager;
import android.os.ServiceSpecificException;
import android.security.KeyStore;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
@@ -56,6 +60,9 @@ import org.robolectric.RuntimeEnvironment;
import org.robolectric.Shadows;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowInputMethodManager;
import org.robolectric.shadows.ShadowSubscriptionManager;
import java.util.Arrays;
@RunWith(RobolectricTestRunner.class)
@Config(shadows = ShadowConnectivityManager.class)
@@ -71,6 +78,7 @@ public class WifiConfigController2Test {
private KeyStore mKeyStore;
private View mView;
private Spinner mHiddenSettingsSpinner;
private ShadowSubscriptionManager mShadowSubscriptionManager;
public WifiConfigController2 mController;
private static final String HEX_PSK = "01234567012345670123456701234567012345670123456701234567"
@@ -101,6 +109,7 @@ public class WifiConfigController2Test {
final Spinner ipSettingsSpinner = mView.findViewById(R.id.ip_settings);
mHiddenSettingsSpinner = mView.findViewById(R.id.hidden_settings);
ipSettingsSpinner.setSelection(DHCP);
mShadowSubscriptionManager = shadowOf(mContext.getSystemService(SubscriptionManager.class));
mController = new TestWifiConfigController2(mConfigUiBase, mView, mWifiEntry,
WifiConfigUiBase2.MODE_CONNECT);
@@ -224,6 +233,35 @@ public class WifiConfigController2Test {
assertThat(mController.isSubmittable()).isTrue();
}
@Test
public void isSubmittable_caCertWithoutDomain_shouldReturnFalse() {
when(mWifiEntry.getSecurity()).thenReturn(WifiEntry.SECURITY_EAP);
mController = new TestWifiConfigController2(mConfigUiBase, mView, mWifiEntry,
WifiConfigUiBase2.MODE_CONNECT);
mView.findViewById(R.id.l_ca_cert).setVisibility(View.VISIBLE);
final Spinner eapCaCertSpinner = mView.findViewById(R.id.ca_cert);
eapCaCertSpinner.setAdapter(mController.getSpinnerAdapter(new String[]{"certificate"}));
eapCaCertSpinner.setSelection(0);
mView.findViewById(R.id.l_domain).setVisibility(View.VISIBLE);
assertThat(mController.isSubmittable()).isFalse();
}
@Test
public void isSubmittable_caCertWithDomain_shouldReturnTrue() {
when(mWifiEntry.getSecurity()).thenReturn(WifiEntry.SECURITY_EAP);
mController = new TestWifiConfigController2(mConfigUiBase, mView, mWifiEntry,
WifiConfigUiBase2.MODE_CONNECT);
mView.findViewById(R.id.l_ca_cert).setVisibility(View.VISIBLE);
final Spinner eapCaCertSpinner = mView.findViewById(R.id.ca_cert);
eapCaCertSpinner.setAdapter(mController.getSpinnerAdapter(new String[]{"certificate"}));
eapCaCertSpinner.setSelection(0);
mView.findViewById(R.id.l_domain).setVisibility(View.VISIBLE);
((TextView) mView.findViewById(R.id.domain)).setText("fakeDomain");
assertThat(mController.isSubmittable()).isTrue();
}
@Test
public void getSignalString_notReachable_shouldHaveNoSignalString() {
when(mWifiEntry.getLevel()).thenReturn(WifiEntry.WIFI_LEVEL_UNREACHABLE);
@@ -760,4 +798,41 @@ public class WifiConfigController2Test {
mController = new TestWifiConfigController2(mConfigUiBase, mView, mWifiEntry,
WifiConfigUiBase2.MODE_MODIFY);
}
@Test
public void loadSims_noSim_simSpinnerDefaultNoSim() {
when(mWifiEntry.getSecurity()).thenReturn(WifiEntry.SECURITY_EAP);
mController = new TestWifiConfigController2(mConfigUiBase, mView, mWifiEntry,
WifiConfigUiBase2.MODE_CONNECT);
final Spinner eapMethodSpinner = mock(Spinner.class);
when(eapMethodSpinner.getSelectedItemPosition()).thenReturn(
WifiConfigController2.WIFI_EAP_METHOD_SIM);
mController.mEapMethodSpinner = eapMethodSpinner;
mController.loadSims();
final WifiConfiguration wifiConfiguration = mController.getConfig();
assertThat(wifiConfiguration.carrierId).isEqualTo(TelephonyManager.UNKNOWN_CARRIER_ID);
}
@Test
public void loadSims_oneSim_simSpinnerDefaultSubscription() {
when(mWifiEntry.getSecurity()).thenReturn(WifiEntry.SECURITY_EAP);
final SubscriptionInfo subscriptionInfo = mock(SubscriptionInfo.class);
final int carrierId = 6;
when(subscriptionInfo.getCarrierId()).thenReturn(carrierId);
when(subscriptionInfo.getCarrierName()).thenReturn("FAKE-CARRIER");
mShadowSubscriptionManager.setActiveSubscriptionInfoList(Arrays.asList(subscriptionInfo));
mController = new TestWifiConfigController2(mConfigUiBase, mView, mWifiEntry,
WifiConfigUiBase2.MODE_CONNECT);
final Spinner eapMethodSpinner = mock(Spinner.class);
when(eapMethodSpinner.getSelectedItemPosition()).thenReturn(
WifiConfigController2.WIFI_EAP_METHOD_SIM);
mController.mEapMethodSpinner = eapMethodSpinner;
mController.loadSims();
final WifiConfiguration wifiConfiguration = mController.getConfig();
assertThat(wifiConfiguration.carrierId).isEqualTo(carrierId);
}
}

View File

@@ -21,6 +21,7 @@ import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.robolectric.Shadows.shadowOf;
import android.content.Context;
import android.content.res.Resources;
@@ -32,6 +33,9 @@ import android.net.wifi.WifiEnterpriseConfig.Phase2;
import android.net.wifi.WifiManager;
import android.os.ServiceSpecificException;
import android.security.KeyStore;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
@@ -56,6 +60,9 @@ import org.robolectric.RuntimeEnvironment;
import org.robolectric.Shadows;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowInputMethodManager;
import org.robolectric.shadows.ShadowSubscriptionManager;
import java.util.Arrays;
@RunWith(RobolectricTestRunner.class)
@Config(shadows = ShadowConnectivityManager.class)
@@ -71,6 +78,7 @@ public class WifiConfigControllerTest {
private KeyStore mKeyStore;
private View mView;
private Spinner mHiddenSettingsSpinner;
private ShadowSubscriptionManager mShadowSubscriptionManager;
public WifiConfigController mController;
private static final String HEX_PSK = "01234567012345670123456701234567012345670123456701234567"
@@ -95,6 +103,7 @@ public class WifiConfigControllerTest {
final Spinner ipSettingsSpinner = mView.findViewById(R.id.ip_settings);
mHiddenSettingsSpinner = mView.findViewById(R.id.hidden_settings);
ipSettingsSpinner.setSelection(DHCP);
mShadowSubscriptionManager = shadowOf(mContext.getSystemService(SubscriptionManager.class));
mController = new TestWifiConfigController(mConfigUiBase, mView, mAccessPoint,
WifiConfigUiBase.MODE_CONNECT);
@@ -218,6 +227,35 @@ public class WifiConfigControllerTest {
assertThat(mController.isSubmittable()).isTrue();
}
@Test
public void isSubmittable_caCertWithoutDomain_shouldReturnFalse() {
when(mAccessPoint.getSecurity()).thenReturn(AccessPoint.SECURITY_EAP);
mController = new TestWifiConfigController(mConfigUiBase, mView, mAccessPoint,
WifiConfigUiBase.MODE_CONNECT);
mView.findViewById(R.id.l_ca_cert).setVisibility(View.VISIBLE);
final Spinner eapCaCertSpinner = mView.findViewById(R.id.ca_cert);
eapCaCertSpinner.setAdapter(mController.getSpinnerAdapter(new String[]{"certificate"}));
eapCaCertSpinner.setSelection(0);
mView.findViewById(R.id.l_domain).setVisibility(View.VISIBLE);
assertThat(mController.isSubmittable()).isFalse();
}
@Test
public void isSubmittable_caCertWithDomain_shouldReturnTrue() {
when(mAccessPoint.getSecurity()).thenReturn(AccessPoint.SECURITY_EAP);
mController = new TestWifiConfigController(mConfigUiBase, mView, mAccessPoint,
WifiConfigUiBase.MODE_CONNECT);
mView.findViewById(R.id.l_ca_cert).setVisibility(View.VISIBLE);
final Spinner eapCaCertSpinner = mView.findViewById(R.id.ca_cert);
eapCaCertSpinner.setAdapter(mController.getSpinnerAdapter(new String[]{"certificate"}));
eapCaCertSpinner.setSelection(0);
mView.findViewById(R.id.l_domain).setVisibility(View.VISIBLE);
((TextView) mView.findViewById(R.id.domain)).setText("fakeDomain");
assertThat(mController.isSubmittable()).isTrue();
}
@Test
public void getSignalString_notReachable_shouldHaveNoSignalString() {
when(mAccessPoint.isReachable()).thenReturn(false);
@@ -575,4 +613,41 @@ public class WifiConfigControllerTest {
assertThat(advButton.getVisibility()).isEqualTo(View.GONE);
}
@Test
public void loadSims_noSim_simSpinnerDefaultNoSim() {
when(mAccessPoint.getSecurity()).thenReturn(AccessPoint.SECURITY_EAP);
mController = new TestWifiConfigController(mConfigUiBase, mView, mAccessPoint,
WifiConfigUiBase.MODE_CONNECT);
final Spinner eapMethodSpinner = mock(Spinner.class);
when(eapMethodSpinner.getSelectedItemPosition()).thenReturn(
WifiConfigController2.WIFI_EAP_METHOD_SIM);
mController.mEapMethodSpinner = eapMethodSpinner;
mController.loadSims();
final WifiConfiguration wifiConfiguration = mController.getConfig();
assertThat(wifiConfiguration.carrierId).isEqualTo(TelephonyManager.UNKNOWN_CARRIER_ID);
}
@Test
public void loadSims_oneSim_simSpinnerDefaultSubscription() {
when(mAccessPoint.getSecurity()).thenReturn(AccessPoint.SECURITY_EAP);
final SubscriptionInfo subscriptionInfo = mock(SubscriptionInfo.class);
final int carrierId = 6;
when(subscriptionInfo.getCarrierId()).thenReturn(carrierId);
when(subscriptionInfo.getCarrierName()).thenReturn("FAKE-CARRIER");
mShadowSubscriptionManager.setActiveSubscriptionInfoList(Arrays.asList(subscriptionInfo));
mController = new TestWifiConfigController(mConfigUiBase, mView, mAccessPoint,
WifiConfigUiBase.MODE_CONNECT);
final Spinner eapMethodSpinner = mock(Spinner.class);
when(eapMethodSpinner.getSelectedItemPosition()).thenReturn(
WifiConfigController2.WIFI_EAP_METHOD_SIM);
mController.mEapMethodSpinner = eapMethodSpinner;
mController.loadSims();
final WifiConfiguration wifiConfiguration = mController.getConfig();
assertThat(wifiConfiguration.carrierId).isEqualTo(carrierId);
}
}

View File

@@ -18,10 +18,6 @@ package com.android.settings.wifi;
import static com.google.common.truth.Truth.assertThat;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import static org.mockito.Mockito.spy;
import android.content.Context;
@@ -30,6 +26,9 @@ import android.os.Bundle;
import com.android.settingslib.wifi.AccessPoint;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
@RunWith(RobolectricTestRunner.class)
@@ -48,11 +47,12 @@ public class WifiUtilsTest {
public void testPassword() {
final String longPassword = "123456789012345678901234567890"
+ "1234567890123456789012345678901234567890";
assertThat(WifiUtils.isHotspotPasswordValid("123")).isFalse();
assertThat(WifiUtils.isHotspotPasswordValid("12345678")).isTrue();
assertThat(WifiUtils.isHotspotPasswordValid("1234567890")).isTrue();
assertThat(WifiUtils.isHotspotPasswordValid(longPassword)).isFalse();
assertThat(WifiUtils.isHotspotPasswordValid("")).isFalse();
assertThat(WifiUtils.isHotspotWpa2PasswordValid("123")).isFalse();
assertThat(WifiUtils.isHotspotWpa2PasswordValid("12345678")).isTrue();
assertThat(WifiUtils.isHotspotWpa2PasswordValid("1234567890")).isTrue();
assertThat(WifiUtils.isHotspotWpa2PasswordValid(longPassword)).isFalse();
assertThat(WifiUtils.isHotspotWpa2PasswordValid("")).isFalse();
assertThat(WifiUtils.isHotspotWpa2PasswordValid("€¥£")).isFalse();
}
@Test
@@ -73,4 +73,4 @@ public class WifiUtilsTest {
public void getWifiConfigWithNullInput_ThrowIllegalArgumentException() {
WifiConfiguration config = WifiUtils.getWifiConfig(null, null, null);
}
}
}

View File

@@ -53,10 +53,12 @@ import android.net.NetworkRequest;
import android.net.RouteInfo;
import android.net.Uri;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiEnterpriseConfig;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Handler;
import android.provider.Settings;
import android.telephony.TelephonyManager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
@@ -175,6 +177,8 @@ public class WifiDetailPreferenceController2Test {
@Mock
private Preference mMockSsidPref;
@Mock
private Preference mMockEapSimSubscriptionPref;
@Mock
private Preference mMockMacAddressPref;
@Mock
private Preference mMockIpAddressPref;
@@ -295,7 +299,7 @@ public class WifiDetailPreferenceController2Test {
.thenReturn(mMockHeaderController);
when(mMockHeaderController.setSecondSummary(nullable(String.class)))
.thenReturn(mMockHeaderController);
when(mMockIconInjector.getIcon(anyInt())).thenReturn(new ColorDrawable());
when(mMockIconInjector.getIcon(anyBoolean(), anyInt())).thenReturn(new ColorDrawable());
setupMockedPreferenceScreen();
}
@@ -374,6 +378,8 @@ public class WifiDetailPreferenceController2Test {
.thenReturn(mMockSecurityPref);
when(mMockScreen.findPreference(WifiDetailPreferenceController2.KEY_SSID_PREF))
.thenReturn(mMockSsidPref);
when(mMockScreen.findPreference(WifiDetailPreferenceController2
.KEY_EAP_SIM_SUBSCRIPTION_PREF)).thenReturn(mMockEapSimSubscriptionPref);
when(mMockScreen.findPreference(WifiDetailPreferenceController2.KEY_MAC_ADDRESS_PREF))
.thenReturn(mMockMacAddressPref);
when(mMockScreen.findPreference(WifiDetailPreferenceController2.KEY_IP_ADDRESS_PREF))
@@ -494,7 +500,7 @@ public class WifiDetailPreferenceController2Test {
public void entityHeader_shouldHaveIconSetForConnectedNetwork() {
setUpForConnectedNetwork();
setUpSpyController();
Drawable expectedIcon = mMockIconInjector.getIcon(LEVEL);
Drawable expectedIcon = mMockIconInjector.getIcon(false /* showX */, LEVEL);
displayAndResume();
@@ -504,7 +510,7 @@ public class WifiDetailPreferenceController2Test {
@Test
public void entityHeader_shouldHaveIconSetForDisconnectedNetwork() {
setUpForDisconnectedNetwork();
Drawable expectedIcon = mMockIconInjector.getIcon(LEVEL);
Drawable expectedIcon = mMockIconInjector.getIcon(false /* showX */, LEVEL);
displayAndResume();
@@ -609,6 +615,7 @@ public class WifiDetailPreferenceController2Test {
displayAndResume();
assertThat(mController.mShowX).isFalse();
verify(mMockSignalStrengthPref).setIcon(any(Drawable.class));
}
@@ -618,6 +625,7 @@ public class WifiDetailPreferenceController2Test {
displayAndResume();
assertThat(mController.mShowX).isFalse();
verify(mMockSignalStrengthPref).setIcon(any(Drawable.class));
}
@@ -627,6 +635,7 @@ public class WifiDetailPreferenceController2Test {
displayAndResume();
assertThat(mController.mShowX).isFalse();
verify(mMockSignalStrengthPref, never()).setIcon(any(Drawable.class));
}
@@ -639,6 +648,7 @@ public class WifiDetailPreferenceController2Test {
displayAndResume();
assertThat(mController.mShowX).isFalse();
verify(mMockSignalStrengthPref).setSummary(expectedStrength);
}
@@ -650,6 +660,7 @@ public class WifiDetailPreferenceController2Test {
displayAndResume();
assertThat(mController.mShowX).isFalse();
verify(mMockSignalStrengthPref).setSummary(expectedStrength);
}
@@ -659,9 +670,24 @@ public class WifiDetailPreferenceController2Test {
displayAndResume();
assertThat(mController.mShowX).isFalse();
verify(mMockSignalStrengthPref, never()).setSummary(any(String.class));
}
@Test
public void signalStrengthPref_shouldShowXLevelIcon_showXTrue() {
setUpForConnectedNetwork();
setUpSpyController();
final String expectedStrength =
mContext.getResources().getStringArray(R.array.wifi_signal)[LEVEL];
when(mMockWifiEntry.shouldShowXLevelIcon()).thenReturn(true);
displayAndResume();
assertThat(mController.mShowX).isTrue();
verify(mMockSignalStrengthPref).setSummary(expectedStrength);
}
@Test
public void linkSpeedPref_shouldNotShowIfNotSet() {
setUpForConnectedNetwork();
@@ -1523,7 +1549,7 @@ public class WifiDetailPreferenceController2Test {
ArgumentCaptor<BitmapDrawable> drawableCaptor =
ArgumentCaptor.forClass(BitmapDrawable.class);
Drawable original = mContext.getDrawable(Utils.getWifiIconResource(LEVEL)).mutate();
when(mMockIconInjector.getIcon(anyInt())).thenReturn(original);
when(mMockIconInjector.getIcon(anyBoolean(), anyInt())).thenReturn(original);
displayAndResume();
@@ -1542,7 +1568,7 @@ public class WifiDetailPreferenceController2Test {
ArgumentCaptor<BitmapDrawable> drawableCaptor =
ArgumentCaptor.forClass(BitmapDrawable.class);
Drawable original = mContext.getDrawable(Utils.getWifiIconResource(LEVEL)).mutate();
when(mMockIconInjector.getIcon(anyInt())).thenReturn(original);
when(mMockIconInjector.getIcon(anyBoolean(), anyInt())).thenReturn(original);
displayAndResume();
@@ -1582,6 +1608,82 @@ public class WifiDetailPreferenceController2Test {
verify(mMockHeaderController).setSummary(expired);
}
@Test
public void refreshEapSimSubscription_nonEapSecurity_invisibleEapSimSubscriptionPref() {
setUpForDisconnectedNetwork();
when(mMockWifiEntry.getSecurity()).thenReturn(WifiEntry.SECURITY_NONE);
displayAndResume();
verify(mMockEapSimSubscriptionPref, times(1)).setVisible(false);
when(mMockWifiEntry.getSecurity()).thenReturn(WifiEntry.SECURITY_OWE);
displayAndResume();
verify(mMockEapSimSubscriptionPref, times(2)).setVisible(false);
when(mMockWifiEntry.getSecurity()).thenReturn(WifiEntry.SECURITY_PSK);
displayAndResume();
verify(mMockEapSimSubscriptionPref, times(3)).setVisible(false);
when(mMockWifiEntry.getSecurity()).thenReturn(WifiEntry.SECURITY_SAE);
displayAndResume();
verify(mMockEapSimSubscriptionPref, times(4)).setVisible(false);
verify(mMockEapSimSubscriptionPref, never()).setVisible(true);
}
@Test
public void refreshEapSimSubscription_nonSimEapMethod_invisibleEapSimSubscriptionPref() {
setUpForDisconnectedNetwork();
when(mMockWifiEntry.getSecurity()).thenReturn(WifiEntry.SECURITY_EAP);
final WifiConfiguration mockWifiConfiguration = mock(WifiConfiguration.class);
final WifiEnterpriseConfig mockWifiEnterpriseConfig = mock(WifiEnterpriseConfig.class);
when(mockWifiEnterpriseConfig.isAuthenticationSimBased()).thenReturn(false);
mockWifiConfiguration.enterpriseConfig = mockWifiEnterpriseConfig;
when(mMockWifiEntry.getWifiConfiguration()).thenReturn(mockWifiConfiguration);
displayAndResume();
verify(mMockEapSimSubscriptionPref, times(1)).setVisible(false);
}
@Test
public void refreshEapSimSubscription_simEapMethod_visibleEapSimSubscriptionPref() {
setUpForDisconnectedNetwork();
when(mMockWifiEntry.getSecurity()).thenReturn(WifiEntry.SECURITY_EAP);
final WifiConfiguration mockWifiConfiguration = mock(WifiConfiguration.class);
final WifiEnterpriseConfig mockWifiEnterpriseConfig = mock(WifiEnterpriseConfig.class);
when(mockWifiEnterpriseConfig.isAuthenticationSimBased()).thenReturn(true);
mockWifiConfiguration.enterpriseConfig = mockWifiEnterpriseConfig;
when(mMockWifiEntry.getWifiConfiguration()).thenReturn(mockWifiConfiguration);
displayAndResume();
verify(mMockEapSimSubscriptionPref).setVisible(true);
}
@Test
public void refreshEapSimSubscription_unknownCarrierId_noSimEapSimSubscriptionPref() {
setUpForDisconnectedNetwork();
when(mMockWifiEntry.getSecurity()).thenReturn(WifiEntry.SECURITY_EAP);
final WifiConfiguration mockWifiConfiguration = mock(WifiConfiguration.class);
mockWifiConfiguration.carrierId = TelephonyManager.UNKNOWN_CARRIER_ID;
final WifiEnterpriseConfig mockWifiEnterpriseConfig = mock(WifiEnterpriseConfig.class);
when(mockWifiEnterpriseConfig.isAuthenticationSimBased()).thenReturn(true);
mockWifiConfiguration.enterpriseConfig = mockWifiEnterpriseConfig;
when(mMockWifiEntry.getWifiConfiguration()).thenReturn(mockWifiConfiguration);
displayAndResume();
verify(mMockEapSimSubscriptionPref).setVisible(true);
verify(mMockEapSimSubscriptionPref).setSummary(R.string.wifi_no_related_sim_card);
}
private ActionButtonsPreference createMock() {
final ActionButtonsPreference pref = mock(ActionButtonsPreference.class);
when(pref.setButton1Text(anyInt())).thenReturn(pref);

View File

@@ -30,6 +30,7 @@ import android.content.Context;
import android.net.NetworkCapabilities;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;
import android.provider.Settings;
import androidx.core.graphics.drawable.IconCompat;
import androidx.slice.Slice;
@@ -77,6 +78,9 @@ public class ContextualWifiSliceTest {
SliceProvider.setSpecs(SliceLiveData.SUPPORTED_SPECS);
mWifiManager.setWifiEnabled(true);
// Set WifiSlice expandable
Settings.Global.putInt(mContext.getContentResolver(),
ContextualWifiSlice.CONTEXTUAL_WIFI_EXPANDABLE, 1);
mWifiSlice = new ContextualWifiSlice(mContext);
}
@@ -126,6 +130,18 @@ public class ContextualWifiSliceTest {
assertThat(ContextualWifiSlice.getApRowCount()).isEqualTo(COLLAPSED_ROW_COUNT);
}
@Test
public void getWifiSlice_notExpandable_shouldCollapseSlice() {
Settings.Global.putInt(mContext.getContentResolver(),
ContextualWifiSlice.CONTEXTUAL_WIFI_EXPANDABLE, 0);
mWifiSlice.sApRowCollapsed = false;
final Slice wifiSlice = mWifiSlice.getSlice();
assertWifiHeader(wifiSlice);
assertThat(ContextualWifiSlice.getApRowCount()).isEqualTo(COLLAPSED_ROW_COUNT);
}
@Test
public void getWifiSlice_contextualWifiSlice_shouldReturnContextualWifiSliceUri() {
mWifiSlice.sActiveUiSession = mFeatureFactory.slicesFeatureProvider.getUiSessionToken();