Add Wifi Slice
Add a custom Wifi Slice to the Settings Slice Provider. It needs a custom Slice because of the complicated listener logic in the MasterSwitchPreferenceController, which makes it hard to work-in synchronous set/get logic. The one-off Slice requires extra changes, including: - Including it in getDescendants - Handling changes to wifi by the framework This is the first change that uses SettingsLib's broadcast relay, which allows settings to (un)register IntentFilters to a Uri, allowing Settings Slices affected by the framework (quicksettings, connectivity related, volume, etc) to be updated without action on the Slice. Fixes: 70622039 Fixes: 67997332 Test: robotests Change-Id: Ia76738dd6baacd5522d52df2c61ebad86a600282 Merged-In: Ibfe4736beecb833e3f6bb871b2eb5228a5fd3a34
This commit is contained in:
@@ -19,6 +19,7 @@ package com.android.settings.slices;
|
||||
|
||||
import static android.content.ContentResolver.SCHEME_CONTENT;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -31,6 +32,7 @@ import android.net.Uri;
|
||||
import android.os.StrictMode;
|
||||
import android.provider.SettingsSlicesContract;
|
||||
|
||||
import com.android.settings.wifi.WifiSliceBuilder;
|
||||
import com.android.settings.testutils.DatabaseTestUtils;
|
||||
import com.android.settings.testutils.FakeToggleController;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
@@ -45,6 +47,8 @@ import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
import androidx.slice.Slice;
|
||||
|
||||
@@ -70,6 +74,10 @@ public class SettingsSliceProviderTest {
|
||||
private SQLiteDatabase mDb;
|
||||
private SliceManager mManager;
|
||||
|
||||
private static final List<Uri> SPECIAL_CASE_PLATFORM_URIS = Arrays.asList(
|
||||
WifiSliceBuilder.WIFI_URI
|
||||
);
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
@@ -114,7 +122,7 @@ public class SettingsSliceProviderTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadSlice_doesntCacheWithoutPin() {
|
||||
public void testLoadSlice_doesNotCacheWithoutPin() {
|
||||
insertSpecialCase(KEY);
|
||||
Uri uri = SliceBuilderUtils.getUri(INTENT_PATH, false);
|
||||
|
||||
@@ -226,6 +234,7 @@ public class SettingsSliceProviderTest {
|
||||
.build();
|
||||
|
||||
final Collection<Uri> descendants = mProvider.onGetSliceDescendants(uri);
|
||||
descendants.removeAll(SPECIAL_CASE_PLATFORM_URIS);
|
||||
|
||||
assertThat(descendants).isEmpty();
|
||||
}
|
||||
@@ -293,16 +302,18 @@ public class SettingsSliceProviderTest {
|
||||
.authority(SettingsSlicesContract.AUTHORITY)
|
||||
.appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
|
||||
.build();
|
||||
final Uri expectedUri = new Uri.Builder()
|
||||
final Collection<Uri> expectedUris = new HashSet<>();
|
||||
expectedUris.addAll(SPECIAL_CASE_PLATFORM_URIS);
|
||||
expectedUris.add(new Uri.Builder()
|
||||
.scheme(SCHEME_CONTENT)
|
||||
.authority(SettingsSlicesContract.AUTHORITY)
|
||||
.appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
|
||||
.appendPath(key)
|
||||
.build();
|
||||
.build());
|
||||
|
||||
final Collection<Uri> descendants = mProvider.onGetSliceDescendants(uri);
|
||||
|
||||
assertThat(descendants).containsExactly(expectedUri);
|
||||
assertThat(descendants).containsExactlyElementsIn(expectedUris);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -313,16 +324,18 @@ public class SettingsSliceProviderTest {
|
||||
.scheme(SCHEME_CONTENT)
|
||||
.authority(SettingsSlicesContract.AUTHORITY)
|
||||
.build();
|
||||
final Uri expectedUri = new Uri.Builder()
|
||||
final Collection<Uri> expectedUris = new HashSet<>();
|
||||
expectedUris.addAll(SPECIAL_CASE_PLATFORM_URIS);
|
||||
expectedUris.add(new Uri.Builder()
|
||||
.scheme(SCHEME_CONTENT)
|
||||
.authority(SettingsSlicesContract.AUTHORITY)
|
||||
.appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
|
||||
.appendPath(key)
|
||||
.build();
|
||||
.build());
|
||||
|
||||
final Collection<Uri> descendants = mProvider.onGetSliceDescendants(uri);
|
||||
|
||||
assertThat(descendants).containsExactly(expectedUri);
|
||||
assertThat(descendants).containsExactlyElementsIn(expectedUris);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -334,22 +347,31 @@ public class SettingsSliceProviderTest {
|
||||
final Uri uri = new Uri.Builder()
|
||||
.scheme(SCHEME_CONTENT)
|
||||
.build();
|
||||
final Uri expectedPlatformUri = new Uri.Builder()
|
||||
final Collection<Uri> expectedUris = new HashSet<>();
|
||||
expectedUris.addAll(SPECIAL_CASE_PLATFORM_URIS);
|
||||
expectedUris.add(new Uri.Builder()
|
||||
.scheme(SCHEME_CONTENT)
|
||||
.authority(SettingsSlicesContract.AUTHORITY)
|
||||
.appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
|
||||
.appendPath(platformKey)
|
||||
.build();
|
||||
final Uri expectedOemUri = new Uri.Builder()
|
||||
.build());
|
||||
expectedUris.add(new Uri.Builder()
|
||||
.scheme(SCHEME_CONTENT)
|
||||
.authority(SettingsSliceProvider.SLICE_AUTHORITY)
|
||||
.appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
|
||||
.appendPath(oemKey)
|
||||
.build();
|
||||
.build());
|
||||
|
||||
final Collection<Uri> descendants = mProvider.onGetSliceDescendants(uri);
|
||||
|
||||
assertThat(descendants).containsExactly(expectedPlatformUri, expectedOemUri);
|
||||
assertThat(descendants).containsExactlyElementsIn(expectedUris);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bindSlice_wifiSlice_returnsWifiSlice() {
|
||||
final Slice wifiSlice = mProvider.onBindSlice(WifiSliceBuilder.WIFI_URI);
|
||||
|
||||
assertThat(wifiSlice.getUri()).isEqualTo(WifiSliceBuilder.WIFI_URI);
|
||||
}
|
||||
|
||||
private void insertSpecialCase(String key) {
|
||||
|
Reference in New Issue
Block a user