diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 2f910e4e313..17f83035463 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -3313,10 +3313,15 @@ - - - + android:name=".slices.SliceBroadcastReceiver" + android:exported="false"> + + + + - Simulate a display with a cutout + Display cutout display cutout, notch - - None + + Device default Special app access diff --git a/res/xml/my_device_info.xml b/res/xml/my_device_info.xml index 3dac8b879f2..3d499ab4600 100644 --- a/res/xml/my_device_info.xml +++ b/res/xml/my_device_info.xml @@ -71,10 +71,18 @@ + + + + + - - - - - - \ No newline at end of file + diff --git a/src/com/android/settings/bluetooth/BluetoothPairingController.java b/src/com/android/settings/bluetooth/BluetoothPairingController.java index 5120cc0ff9b..c39f1d9feb0 100644 --- a/src/com/android/settings/bluetooth/BluetoothPairingController.java +++ b/src/com/android/settings/bluetooth/BluetoothPairingController.java @@ -23,10 +23,14 @@ import android.text.Editable; import android.util.Log; import android.widget.CompoundButton; import android.widget.CompoundButton.OnCheckedChangeListener; + +import androidx.annotation.VisibleForTesting; + import com.android.settings.R; import com.android.settings.bluetooth.BluetoothPairingDialogFragment.BluetoothPairingDialogListener; import com.android.settingslib.bluetooth.LocalBluetoothManager; import com.android.settingslib.bluetooth.LocalBluetoothProfile; + import java.util.Locale; /** @@ -50,8 +54,10 @@ public class BluetoothPairingController implements OnCheckedChangeListener, // Bluetooth dependencies for the connection we are trying to establish private LocalBluetoothManager mBluetoothManager; - private BluetoothDevice mDevice; - private int mType; + @VisibleForTesting + BluetoothDevice mDevice; + @VisibleForTesting + int mType; private String mUserInput; private String mPasskeyFormatted; private int mPasskey; @@ -82,7 +88,6 @@ public class BluetoothPairingController implements OnCheckedChangeListener, mDeviceName = mBluetoothManager.getCachedDeviceManager().getName(mDevice); mPbapClientProfile = mBluetoothManager.getProfileManager().getPbapClientProfile(); mPasskeyFormatted = formatKey(mPasskey); - } @Override @@ -96,12 +101,13 @@ public class BluetoothPairingController implements OnCheckedChangeListener, @Override public void onDialogPositiveClick(BluetoothPairingDialogFragment dialog) { + if (mPbapAllowed) { + mDevice.setPhonebookAccessPermission(BluetoothDevice.ACCESS_ALLOWED); + } else { + mDevice.setPhonebookAccessPermission(BluetoothDevice.ACCESS_REJECTED); + } + if (getDialogType() == USER_ENTRY_DIALOG) { - if (mPbapAllowed) { - mDevice.setPhonebookAccessPermission(BluetoothDevice.ACCESS_ALLOWED); - } else { - mDevice.setPhonebookAccessPermission(BluetoothDevice.ACCESS_REJECTED); - } onPair(mUserInput); } else { onPair(null); diff --git a/src/com/android/settings/development/EmulateDisplayCutoutPreferenceController.java b/src/com/android/settings/development/EmulateDisplayCutoutPreferenceController.java index 3d551cdefaf..c9bb9b76bd2 100644 --- a/src/com/android/settings/development/EmulateDisplayCutoutPreferenceController.java +++ b/src/com/android/settings/development/EmulateDisplayCutoutPreferenceController.java @@ -33,6 +33,7 @@ import com.android.settings.wrapper.OverlayManagerWrapper; import com.android.settings.wrapper.OverlayManagerWrapper.OverlayInfo; import com.android.settingslib.development.DeveloperOptionsPreferenceController; +import java.util.Comparator; import java.util.List; public class EmulateDisplayCutoutPreferenceController extends @@ -40,6 +41,8 @@ public class EmulateDisplayCutoutPreferenceController extends PreferenceControllerMixin { private static final String KEY = "display_cutout_emulation"; + private static final Comparator OVERLAY_INFO_COMPARATOR = + Comparator.comparingInt(a -> a.priority); private final OverlayManagerWrapper mOverlayManager; private final boolean mAvailable; @@ -120,7 +123,7 @@ public class EmulateDisplayCutoutPreferenceController extends int current = 0; pkgs[0] = ""; - labels[0] = mContext.getString(R.string.display_cutout_emulation_none); + labels[0] = mContext.getString(R.string.display_cutout_emulation_device_default); for (int i = 0; i < overlays.length; i++) { OverlayInfo o = overlays[i]; @@ -153,6 +156,7 @@ public class EmulateDisplayCutoutPreferenceController extends overlayInfos.remove(i); } } + overlayInfos.sort(OVERLAY_INFO_COMPARATOR); return overlayInfos.toArray(new OverlayInfo[overlayInfos.size()]); } diff --git a/src/com/android/settings/fuelgauge/BatteryUtils.java b/src/com/android/settings/fuelgauge/BatteryUtils.java index 4a3e6d42e88..8540f0fd69b 100644 --- a/src/com/android/settings/fuelgauge/BatteryUtils.java +++ b/src/com/android/settings/fuelgauge/BatteryUtils.java @@ -24,8 +24,8 @@ import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.os.BatteryStats; -import android.os.Bundle; import android.os.Build; +import android.os.Bundle; import android.os.Process; import android.os.SystemClock; import android.os.UserHandle; @@ -35,7 +35,6 @@ import androidx.annotation.Nullable; import androidx.annotation.StringRes; import androidx.annotation.VisibleForTesting; import androidx.annotation.WorkerThread; -import android.text.TextUtils; import android.text.format.DateUtils; import android.util.Log; import android.util.SparseLongArray; @@ -48,7 +47,6 @@ import com.android.settings.fuelgauge.anomaly.Anomaly; import com.android.settings.fuelgauge.batterytip.AnomalyInfo; import com.android.settings.fuelgauge.batterytip.StatsManagerConfig; import com.android.settings.overlay.FeatureFactory; - import com.android.settingslib.fuelgauge.PowerWhitelistBackend; import com.android.settingslib.utils.PowerUtil; @@ -93,14 +91,14 @@ public class BatteryUtils { public static BatteryUtils getInstance(Context context) { if (sInstance == null || sInstance.isDataCorrupted()) { - sInstance = new BatteryUtils(context); + sInstance = new BatteryUtils(context.getApplicationContext()); } return sInstance; } @VisibleForTesting BatteryUtils(Context context) { - mContext = context.getApplicationContext(); + mContext = context; mPackageManager = context.getPackageManager(); mAppOpsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE); mPowerUsageFeatureProvider = FeatureFactory.getFactory( diff --git a/src/com/android/settings/overlay/FeatureFactoryImpl.java b/src/com/android/settings/overlay/FeatureFactoryImpl.java index 89e1eb8eda4..72714d563cd 100644 --- a/src/com/android/settings/overlay/FeatureFactoryImpl.java +++ b/src/com/android/settings/overlay/FeatureFactoryImpl.java @@ -94,7 +94,8 @@ public class FeatureFactoryImpl extends FeatureFactory { @Override public PowerUsageFeatureProvider getPowerUsageFeatureProvider(Context context) { if (mPowerUsageFeatureProvider == null) { - mPowerUsageFeatureProvider = new PowerUsageFeatureProviderImpl(context); + mPowerUsageFeatureProvider = new PowerUsageFeatureProviderImpl( + context.getApplicationContext()); } return mPowerUsageFeatureProvider; } @@ -102,7 +103,8 @@ public class FeatureFactoryImpl extends FeatureFactory { @Override public DashboardFeatureProvider getDashboardFeatureProvider(Context context) { if (mDashboardFeatureProvider == null) { - mDashboardFeatureProvider = new DashboardFeatureProviderImpl(context); + mDashboardFeatureProvider = new DashboardFeatureProviderImpl( + context.getApplicationContext()); } return mDashboardFeatureProvider; } @@ -118,10 +120,11 @@ public class FeatureFactoryImpl extends FeatureFactory { @Override public ApplicationFeatureProvider getApplicationFeatureProvider(Context context) { if (mApplicationFeatureProvider == null) { - mApplicationFeatureProvider = new ApplicationFeatureProviderImpl(context, - new PackageManagerWrapper(context.getPackageManager()), + final Context appContext = context.getApplicationContext(); + mApplicationFeatureProvider = new ApplicationFeatureProviderImpl(appContext, + new PackageManagerWrapper(appContext.getPackageManager()), AppGlobals.getPackageManager(), - (DevicePolicyManager) context + (DevicePolicyManager) appContext .getSystemService(Context.DEVICE_POLICY_SERVICE)); } return mApplicationFeatureProvider; @@ -138,12 +141,14 @@ public class FeatureFactoryImpl extends FeatureFactory { @Override public EnterprisePrivacyFeatureProvider getEnterprisePrivacyFeatureProvider(Context context) { if (mEnterprisePrivacyFeatureProvider == null) { - mEnterprisePrivacyFeatureProvider = new EnterprisePrivacyFeatureProviderImpl(context, - (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE), - new PackageManagerWrapper(context.getPackageManager()), - UserManager.get(context), - (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE), - context.getResources()); + final Context appContext = context.getApplicationContext(); + mEnterprisePrivacyFeatureProvider = new EnterprisePrivacyFeatureProviderImpl(appContext, + (DevicePolicyManager) appContext + .getSystemService(Context.DEVICE_POLICY_SERVICE), + new PackageManagerWrapper(appContext.getPackageManager()), + UserManager.get(appContext), + (ConnectivityManager) appContext.getSystemService(Context.CONNECTIVITY_SERVICE), + appContext.getResources()); } return mEnterprisePrivacyFeatureProvider; } @@ -172,7 +177,8 @@ public class FeatureFactoryImpl extends FeatureFactory { @Override public SuggestionFeatureProvider getSuggestionFeatureProvider(Context context) { if (mSuggestionFeatureProvider == null) { - mSuggestionFeatureProvider = new SuggestionFeatureProviderImpl(context); + mSuggestionFeatureProvider = new SuggestionFeatureProviderImpl( + context.getApplicationContext()); } return mSuggestionFeatureProvider; } @@ -180,7 +186,7 @@ public class FeatureFactoryImpl extends FeatureFactory { @Override public UserFeatureProvider getUserFeatureProvider(Context context) { if (mUserFeatureProvider == null) { - mUserFeatureProvider = new UserFeatureProviderImpl(context); + mUserFeatureProvider = new UserFeatureProviderImpl(context.getApplicationContext()); } return mUserFeatureProvider; } diff --git a/src/com/android/settings/slices/SettingsSliceProvider.java b/src/com/android/settings/slices/SettingsSliceProvider.java index 4b9a7eced95..b327f029712 100644 --- a/src/com/android/settings/slices/SettingsSliceProvider.java +++ b/src/com/android/settings/slices/SettingsSliceProvider.java @@ -382,7 +382,7 @@ public class SettingsSliceProvider extends SliceProvider { void registerIntentToUri(IntentFilter intentFilter, Uri sliceUri) { Log.d(TAG, "Registering Uri for broadcast relay: " + sliceUri); mRegisteredUris.add(sliceUri); - SliceBroadcastRelay.registerReceiver(getContext(), sliceUri, SliceBroadcastReceiver.class, + SliceBroadcastRelay.registerReceiver(getContext(), sliceUri, SliceRelayReceiver.class, intentFilter); } diff --git a/src/com/android/settings/slices/SliceBroadcastReceiver.java b/src/com/android/settings/slices/SliceBroadcastReceiver.java index d81734a974d..53fa4be8e38 100644 --- a/src/com/android/settings/slices/SliceBroadcastReceiver.java +++ b/src/com/android/settings/slices/SliceBroadcastReceiver.java @@ -44,7 +44,6 @@ import com.android.settings.core.TogglePreferenceController; import com.android.settings.notification.ZenModeSliceBuilder; import com.android.settings.overlay.FeatureFactory; import com.android.settings.wifi.WifiSliceBuilder; -import com.android.settingslib.SliceBroadcastRelay; /** * Responds to actions performed on slices and notifies slices of updates in state changes. @@ -84,12 +83,6 @@ public class SliceBroadcastReceiver extends BroadcastReceiver { case ACTION_ZEN_MODE_SLICE_CHANGED: ZenModeSliceBuilder.handleUriChange(context, intent); break; - default: - final String uriString = intent.getStringExtra(SliceBroadcastRelay.EXTRA_URI); - if (!TextUtils.isEmpty(uriString)) { - final Uri uri = Uri.parse(uriString); - context.getContentResolver().notifyChange(uri, null /* observer */); - } } } diff --git a/src/com/android/settings/slices/SliceRelayReceiver.java b/src/com/android/settings/slices/SliceRelayReceiver.java new file mode 100644 index 00000000000..c8ec12eae85 --- /dev/null +++ b/src/com/android/settings/slices/SliceRelayReceiver.java @@ -0,0 +1,39 @@ +/* + * 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 android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.net.Uri; +import android.text.TextUtils; +import com.android.settingslib.SliceBroadcastRelay; + +/** + * Receives broadcasts to notify that Settings Slices are potentially stale. + */ +public class SliceRelayReceiver extends BroadcastReceiver { + + @Override + public void onReceive(Context context, Intent intent) { + final String uriString = intent.getStringExtra(SliceBroadcastRelay.EXTRA_URI); + if (!TextUtils.isEmpty(uriString)) { + final Uri uri = Uri.parse(uriString); + context.getContentResolver().notifyChange(uri, null /* observer */); + } + } +} \ No newline at end of file diff --git a/src/com/android/settings/wrapper/OverlayManagerWrapper.java b/src/com/android/settings/wrapper/OverlayManagerWrapper.java index 6e3c2348857..371504ff551 100644 --- a/src/com/android/settings/wrapper/OverlayManagerWrapper.java +++ b/src/com/android/settings/wrapper/OverlayManagerWrapper.java @@ -81,18 +81,21 @@ public class OverlayManagerWrapper { public static final String CATEGORY_THEME = android.content.om.OverlayInfo.CATEGORY_THEME; public final String packageName; public final String category; + public final int priority; private final boolean mEnabled; - public OverlayInfo(String packageName, String category, boolean enabled) { + public OverlayInfo(String packageName, String category, boolean enabled, int priority) { this.packageName = packageName; this.category = category; mEnabled = enabled; + this.priority = priority; } public OverlayInfo(android.content.om.OverlayInfo info) { mEnabled = info.isEnabled(); category = info.category; packageName = info.packageName; + priority = info.priority; } public boolean isEnabled() { diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothPairingControllerTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothPairingControllerTest.java new file mode 100644 index 00000000000..b28a8b2b825 --- /dev/null +++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothPairingControllerTest.java @@ -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); + } +} diff --git a/tests/robotests/src/com/android/settings/development/EmulateDisplayCutoutPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/EmulateDisplayCutoutPreferenceControllerTest.java index 34a0581e582..68a0ffdd853 100644 --- a/tests/robotests/src/com/android/settings/development/EmulateDisplayCutoutPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/development/EmulateDisplayCutoutPreferenceControllerTest.java @@ -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); } } \ No newline at end of file diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BackgroundActivityPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BackgroundActivityPreferenceControllerTest.java index d5f3e2b58a7..9ca61a43d7d 100644 --- a/tests/robotests/src/com/android/settings/fuelgauge/BackgroundActivityPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/fuelgauge/BackgroundActivityPreferenceControllerTest.java @@ -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); diff --git a/tests/robotests/src/com/android/settings/slices/SliceBroadcastReceiverTest.java b/tests/robotests/src/com/android/settings/slices/SliceBroadcastReceiverTest.java index 25f0d0cb163..f8172e88f0c 100644 --- a/tests/robotests/src/com/android/settings/slices/SliceBroadcastReceiverTest.java +++ b/tests/robotests/src/com/android/settings/slices/SliceBroadcastReceiverTest.java @@ -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)); } diff --git a/tests/robotests/src/com/android/settings/slices/SliceRelayReceiverTest.java b/tests/robotests/src/com/android/settings/slices/SliceRelayReceiverTest.java new file mode 100644 index 00000000000..3388a16f33f --- /dev/null +++ b/tests/robotests/src/com/android/settings/slices/SliceRelayReceiverTest.java @@ -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()); + + } +}