DO NOT MERGE - Merge pie-platform-release (PPRL.181205.001) into master

Bug: 120502534
Change-Id: I63bedf30fa0a4629cfab1dbe94359b4d36cf9ac1
This commit is contained in:
Xin Li
2018-12-11 14:19:45 -08:00
97 changed files with 356 additions and 63 deletions

View File

@@ -0,0 +1,66 @@
/*
* Copyright (C) 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.bluetooth;
import static android.bluetooth.BluetoothDevice.PAIRING_VARIANT_CONSENT;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.content.Intent;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.ShadowBluetoothAdapter;
import com.android.settings.testutils.shadow.ShadowBluetoothPan;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(shadows = {ShadowBluetoothPan.class, ShadowBluetoothAdapter.class})
public class BluetoothPairingControllerTest {
@Mock
private BluetoothDevice mBluetoothDevice;
private Context mContext;
private BluetoothPairingController mBluetoothPairingController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
final Intent intent = new Intent();
intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mBluetoothDevice);
mBluetoothPairingController = spy(new BluetoothPairingController(intent, mContext));
}
@Test
public void onDialogPositiveClick_confirmationDialog_setPBAP() {
mBluetoothPairingController.mType = PAIRING_VARIANT_CONSENT;
mBluetoothPairingController.onCheckedChanged(null, true);
mBluetoothPairingController.onDialogPositiveClick(null);
verify(mBluetoothDevice).setPhonebookAccessPermission(BluetoothDevice.ACCESS_ALLOWED);
}
}

View File

@@ -17,6 +17,8 @@
package com.android.settings.development;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.AdditionalMatchers.aryEq;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
@@ -38,6 +40,7 @@ import com.android.settings.wrapper.OverlayManagerWrapper.OverlayInfo;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.AdditionalMatchers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
@@ -46,10 +49,10 @@ import java.util.Arrays;
@RunWith(SettingsRobolectricTestRunner.class)
public class EmulateDisplayCutoutPreferenceControllerTest {
private static final OverlayInfo ONE_DISABLED = createFakeOverlay("emulation.one", false);
private static final OverlayInfo ONE_ENABLED = createFakeOverlay("emulation.one", true);
private static final OverlayInfo TWO_DISABLED = createFakeOverlay("emulation.two", false);
private static final OverlayInfo TWO_ENABLED = createFakeOverlay("emulation.two", true);
private static final OverlayInfo ONE_DISABLED = createFakeOverlay("emulation.one", false, 1);
private static final OverlayInfo ONE_ENABLED = createFakeOverlay("emulation.one", true, 1);
private static final OverlayInfo TWO_DISABLED = createFakeOverlay("emulation.two", false, 2);
private static final OverlayInfo TWO_ENABLED = createFakeOverlay("emulation.two", true, 2);
@Mock
private Context mContext;
@@ -127,6 +130,16 @@ public class EmulateDisplayCutoutPreferenceControllerTest {
verify(mPreference).setValueIndex(0);
}
@Test
public void ordered_by_priority() throws Exception {
mockCurrentOverlays(TWO_DISABLED, ONE_DISABLED);
mController.updateState(null);
verify(mPreference).setEntryValues(
aryEq(new String[]{"", ONE_DISABLED.packageName, TWO_DISABLED.packageName}));
}
@Test
public void onDeveloperOptionsSwitchDisabled() throws Exception {
mockCurrentOverlays(ONE_ENABLED, TWO_DISABLED);
@@ -145,7 +158,8 @@ public class EmulateDisplayCutoutPreferenceControllerTest {
mOverlayManager);
}
private static OverlayInfo createFakeOverlay(String pkg, boolean enabled) {
return new OverlayInfo(pkg, DisplayCutout.EMULATION_OVERLAY_CATEGORY, enabled);
private static OverlayInfo createFakeOverlay(String pkg, boolean enabled, int priority) {
return new OverlayInfo(pkg, DisplayCutout.EMULATION_OVERLAY_CATEGORY, enabled,
priority);
}
}

View File

@@ -17,6 +17,7 @@
package com.android.settings.fuelgauge;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.doNothing;
@@ -89,6 +90,7 @@ public class BackgroundActivityPreferenceControllerTest {
mShadowContext = RuntimeEnvironment.application;
FakeFeatureFactory.setupForTest();
when(mContext.getApplicationContext()).thenReturn(mContext);
when(mContext.getPackageManager()).thenReturn(mPackageManager);
when(mContext.getSystemService(Context.APP_OPS_SERVICE)).thenReturn(mAppOpsManager);
when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
@@ -118,7 +120,7 @@ public class BackgroundActivityPreferenceControllerTest {
@Test
public void testHandlePreferenceTreeClick_restrictApp_showDialog() {
doReturn(AppOpsManager.MODE_ALLOWED).when(mAppOpsManager)
.checkOpNoThrow(anyInt(), anyInt(), anyString());
.checkOpNoThrow(anyInt(), anyInt(), anyString());
mController.handlePreferenceTreeClick(mPreference);
@@ -128,7 +130,7 @@ public class BackgroundActivityPreferenceControllerTest {
@Test
public void testHandlePreferenceTreeClick_unRestrictApp_showDialog() {
doReturn(AppOpsManager.MODE_IGNORED).when(mAppOpsManager)
.checkOpNoThrow(anyInt(), anyInt(), anyString());
.checkOpNoThrow(anyInt(), anyInt(), anyString());
mController.handlePreferenceTreeClick(mPreference);

View File

@@ -159,8 +159,12 @@ public class SliceBroadcastReceiverTest {
assertThat(fakeToggleController.isChecked()).isFalse();
final Uri expectedUri = SliceBuilderUtils.getUri(
SettingsSlicesContract.PATH_SETTING_ACTION + "/" + key, false);
final Uri expectedUri = new Uri.Builder()
.scheme(ContentResolver.SCHEME_CONTENT)
.authority(SettingsSliceProvider.SLICE_AUTHORITY)
.appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
.appendPath(key)
.build();
verify(resolver).notifyChange(eq(expectedUri), eq(null));
}

View File

@@ -0,0 +1,72 @@
/*
* Copyright (C) 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.settings.slices;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.provider.SettingsSlicesContract;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settingslib.SliceBroadcastRelay;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RuntimeEnvironment;
@RunWith(SettingsRobolectricTestRunner.class)
public class SliceRelayReceiverTest {
private Context mContext;
private SliceRelayReceiver mSliceRelayReceiver;
@Before
public void setUp() {
mContext = spy(RuntimeEnvironment.application);
mSliceRelayReceiver = new SliceRelayReceiver();
}
@Test
public void onReceive_extraUri_notifiesChangeOnUri() {
// Monitor the ContentResolver
final ContentResolver resolver = spy(mContext.getContentResolver());
doReturn(resolver).when(mContext).getContentResolver();
final Uri uri = new Uri.Builder()
.scheme(ContentResolver.SCHEME_CONTENT)
.authority(SettingsSlicesContract.AUTHORITY)
.appendPath("path")
.build();
final Intent intent = new Intent();
intent.putExtra(SliceBroadcastRelay.EXTRA_URI, uri.toString());
mSliceRelayReceiver.onReceive(mContext, intent);
verify(resolver).notifyChange(eq(uri), any());
}
}