Merge "Fix talkback speak wrong item"
diff --git a/res/values/config.xml b/res/values/config.xml
index 4a02b97..35cc420 100755
--- a/res/values/config.xml
+++ b/res/values/config.xml
@@ -425,4 +425,7 @@
<string-array name="config_panel_keep_observe_uri" translatable="false">
<item>content://com.android.settings.slices/intent/media_output_indicator</item>
</string-array>
+
+ <!-- Uri to query non-public Slice Uris. -->
+ <string name="config_non_public_slice_query_uri" translatable="false"></string>
</resources>
diff --git a/src/com/android/settings/search/SettingsSearchIndexablesProvider.java b/src/com/android/settings/search/SettingsSearchIndexablesProvider.java
index d504d9b..237e58f 100644
--- a/src/com/android/settings/search/SettingsSearchIndexablesProvider.java
+++ b/src/com/android/settings/search/SettingsSearchIndexablesProvider.java
@@ -61,10 +61,12 @@
import androidx.annotation.Nullable;
import androidx.slice.SliceViewManager;
+import com.android.settings.R;
import com.android.settings.SettingsActivity;
import com.android.settings.dashboard.DashboardFeatureProvider;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.slices.SettingsSliceProvider;
+import com.android.settingslib.drawer.ActivityTile;
import com.android.settingslib.drawer.DashboardCategory;
import com.android.settingslib.drawer.Tile;
import com.android.settingslib.search.Indexable;
@@ -215,11 +217,13 @@
public Cursor querySliceUriPairs() {
final SliceViewManager manager = SliceViewManager.getInstance(getContext());
final MatrixCursor cursor = new MatrixCursor(SLICE_URI_PAIRS_COLUMNS);
- final Uri baseUri =
- new Uri.Builder()
+ final String queryUri = getContext().getString(R.string.config_non_public_slice_query_uri);
+ final Uri baseUri = !TextUtils.isEmpty(queryUri) ? Uri.parse(queryUri)
+ : new Uri.Builder()
.scheme(ContentResolver.SCHEME_CONTENT)
.authority(SettingsSliceProvider.SLICE_AUTHORITY)
.build();
+
final Uri platformBaseUri =
new Uri.Builder()
.scheme(ContentResolver.SCHEME_CONTENT)
@@ -375,13 +379,19 @@
final String currentPackageName = context.getPackageName();
for (DashboardCategory category : dashboardFeatureProvider.getAllCategories()) {
for (Tile tile : category.getTiles()) {
- if (currentPackageName.equals(tile.getPackageName())) {
+ if (currentPackageName.equals(tile.getPackageName())
+ && tile instanceof ActivityTile) {
+ // Skip Settings injected items because they should be indexed in the sub-pages.
continue;
}
final SearchIndexableRaw raw = new SearchIndexableRaw(context);
+ final CharSequence title = tile.getTitle(context);
+ raw.title = TextUtils.isEmpty(title) ? null : title.toString();
+ if (TextUtils.isEmpty(raw.title)) {
+ continue;
+ }
raw.key = dashboardFeatureProvider.getDashboardKeyForTile(tile);
- raw.title = tile.getTitle(context).toString();
- CharSequence summary = tile.getSummary(context);
+ final CharSequence summary = tile.getSummary(context);
raw.summaryOn = TextUtils.isEmpty(summary) ? null : summary.toString();
raw.summaryOff = raw.summaryOn;
raw.className = CATEGORY_KEY_TO_PARENT_MAP.get(tile.getCategory());
diff --git a/src/com/android/settings/slices/SettingsSliceProvider.java b/src/com/android/settings/slices/SettingsSliceProvider.java
index 8a6496f..d908881 100644
--- a/src/com/android/settings/slices/SettingsSliceProvider.java
+++ b/src/com/android/settings/slices/SettingsSliceProvider.java
@@ -20,10 +20,13 @@
import android.app.PendingIntent;
import android.app.slice.SliceManager;
+import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
+import android.content.pm.PackageManager;
import android.net.Uri;
+import android.os.Binder;
import android.os.StrictMode;
import android.provider.Settings;
import android.provider.SettingsSlicesContract;
@@ -265,16 +268,29 @@
@Override
public Collection<Uri> onGetSliceDescendants(Uri uri) {
final List<Uri> descendants = new ArrayList<>();
- final Pair<Boolean, String> pathData = SliceBuilderUtils.getPathData(uri);
+ Uri finalUri = uri;
+
+ if (isPrivateSlicesNeeded(finalUri)) {
+ descendants.addAll(
+ mSlicesDatabaseAccessor.getSliceUris(finalUri.getAuthority(),
+ false /* isPublicSlice */));
+ Log.d(TAG, "provide " + descendants.size() + " non-public slices");
+ finalUri = new Uri.Builder()
+ .scheme(ContentResolver.SCHEME_CONTENT)
+ .authority(finalUri.getAuthority())
+ .build();
+ }
+
+ final Pair<Boolean, String> pathData = SliceBuilderUtils.getPathData(finalUri);
if (pathData != null) {
// Uri has a full path and will not have any descendants.
- descendants.add(uri);
+ descendants.add(finalUri);
return descendants;
}
- final String authority = uri.getAuthority();
- final String path = uri.getPath();
+ final String authority = finalUri.getAuthority();
+ final String path = finalUri.getPath();
final boolean isPathEmpty = path.isEmpty();
// Path is anything but empty, "action", or "intent". Return empty list.
@@ -286,7 +302,7 @@
}
// Add all descendants from db with matching authority.
- descendants.addAll(mSlicesDatabaseAccessor.getSliceUris(authority));
+ descendants.addAll(mSlicesDatabaseAccessor.getSliceUris(authority, true /*isPublicSlice*/));
if (isPathEmpty && TextUtils.isEmpty(authority)) {
// No path nor authority. Return all possible Uris by adding all special slice uri
@@ -404,6 +420,24 @@
return set;
}
+ @VisibleForTesting
+ boolean isPrivateSlicesNeeded(Uri uri) {
+ final String queryUri = getContext().getString(R.string.config_non_public_slice_query_uri);
+
+ if (!TextUtils.isEmpty(queryUri) && TextUtils.equals(uri.toString(), queryUri)) {
+ // check if the calling package is eligible for private slices
+ final int callingUid = Binder.getCallingUid();
+ final boolean hasPermission = getContext().checkPermission(
+ android.Manifest.permission.READ_SEARCH_INDEXABLES, Binder.getCallingPid(),
+ callingUid) == PackageManager.PERMISSION_GRANTED;
+ final String callingPackage = getContext().getPackageManager()
+ .getPackagesForUid(callingUid)[0];
+ return hasPermission && TextUtils.equals(callingPackage,
+ getContext().getString(R.string.config_settingsintelligence_package_name));
+ }
+ return false;
+ }
+
private void startBackgroundWorker(Sliceable sliceable, Uri uri) {
final Class workerClass = sliceable.getBackgroundWorkerClass();
if (workerClass == null) {
diff --git a/src/com/android/settings/slices/SlicesDatabaseAccessor.java b/src/com/android/settings/slices/SlicesDatabaseAccessor.java
index 4ae9a4c..e31715d 100644
--- a/src/com/android/settings/slices/SlicesDatabaseAccessor.java
+++ b/src/com/android/settings/slices/SlicesDatabaseAccessor.java
@@ -88,16 +88,18 @@
}
/**
- * @return a list of Slice {@link Uri}s matching {@param authority}.
+ * @return a list of Slice {@link Uri}s based on their visibility {@param isPublicSlice } and
+ * {@param authority}.
*/
- public List<Uri> getSliceUris(String authority) {
+ public List<Uri> getSliceUris(String authority, boolean isPublicSlice) {
verifyIndexing();
final List<Uri> uris = new ArrayList<>();
+ final String whereClause = IndexColumns.PUBLIC_SLICE + (isPublicSlice ? "=1" : "=0");
final SQLiteDatabase database = mHelper.getReadableDatabase();
final String[] columns = new String[]{IndexColumns.SLICE_URI};
- try (final Cursor resultCursor = database.query(TABLE_SLICES_INDEX, columns,
- null /* where */, null /* selection */, null /* groupBy */, null /* having */,
- null /* orderBy */)) {
+ try (Cursor resultCursor = database.query(TABLE_SLICES_INDEX, columns,
+ whereClause /* where */, null /* selection */, null /* groupBy */,
+ null /* having */, null /* orderBy */)) {
if (!resultCursor.moveToFirst()) {
return uris;
}
diff --git a/tests/robotests/res/values-mcc999/config.xml b/tests/robotests/res/values-mcc999/config.xml
index 679062b..dc638a5 100644
--- a/tests/robotests/res/values-mcc999/config.xml
+++ b/tests/robotests/res/values-mcc999/config.xml
@@ -94,4 +94,7 @@
<item>injected_tile_key</item>
<item>injected_tile_key2</item>
</string-array>
+
+ <!-- Uri to query non-public Slice Uris. -->
+ <string name="config_non_public_slice_query_uri" translatable="false">content://com.android.settings.slices/test</string>
</resources>
diff --git a/tests/robotests/src/com/android/settings/slices/SettingsSliceProviderTest.java b/tests/robotests/src/com/android/settings/slices/SettingsSliceProviderTest.java
index ab4ece2..a969420 100644
--- a/tests/robotests/src/com/android/settings/slices/SettingsSliceProviderTest.java
+++ b/tests/robotests/src/com/android/settings/slices/SettingsSliceProviderTest.java
@@ -18,10 +18,13 @@
package com.android.settings.slices;
import static android.content.ContentResolver.SCHEME_CONTENT;
+import static android.content.pm.PackageManager.PERMISSION_DENIED;
+import static android.content.pm.PackageManager.PERMISSION_GRANTED;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
@@ -66,12 +69,15 @@
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
+import org.robolectric.Shadows;
import org.robolectric.annotation.Config;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
import org.robolectric.annotation.Resetter;
import org.robolectric.shadow.api.Shadow;
import org.robolectric.shadows.ShadowAccessibilityManager;
+import org.robolectric.shadows.ShadowBinder;
+import org.robolectric.shadows.ShadowPackageManager;
import java.util.ArrayList;
import java.util.Arrays;
@@ -110,6 +116,7 @@
private Context mContext;
private SettingsSliceProvider mProvider;
+ private ShadowPackageManager mPackageManager;
@Mock
private SliceManager mManager;
@@ -146,6 +153,8 @@
doReturn(mManager).when(mContext).getSystemService(SliceManager.class);
when(mManager.getPinnedSlices()).thenReturn(Collections.emptyList());
+ mPackageManager = Shadows.shadowOf(mContext.getPackageManager());
+
SliceProvider.setSpecs(SliceLiveData.SUPPORTED_SPECS);
}
@@ -284,7 +293,8 @@
@Test
public void getDescendantUris_invalidPath_returnsEmpty() {
final String key = "platform_key";
- SliceTestUtils.insertSliceToDb(mContext, key, true /* isPlatformSlice */);
+ SliceTestUtils.insertSliceToDb(mContext, key, true /* isPlatformSlice */,
+ null /* customizedUnavailableSliceSubtitle */, true /* isPublicSlice */);
final Uri uri = new Uri.Builder()
.scheme(SCHEME_CONTENT)
.authority(SettingsSlicesContract.AUTHORITY)
@@ -299,7 +309,8 @@
@Test
public void getDescendantUris_platformSlice_doesNotReturnOEMSlice() {
- SliceTestUtils.insertSliceToDb(mContext, "oem_key", false /* isPlatformSlice */);
+ SliceTestUtils.insertSliceToDb(mContext, "oem_key", false /* isPlatformSlice */,
+ null /* customizedUnavailableSliceSubtitle */, true /* isPublicSlice */);
final Uri uri = new Uri.Builder()
.scheme(SCHEME_CONTENT)
.authority(SettingsSlicesContract.AUTHORITY)
@@ -313,7 +324,8 @@
@Test
public void getDescendantUris_oemSlice_doesNotReturnPlatformSlice() {
- SliceTestUtils.insertSliceToDb(mContext, "platform_key", true /* isPlatformSlice */);
+ SliceTestUtils.insertSliceToDb(mContext, "platform_key", true /* isPlatformSlice */,
+ null /* customizedUnavailableSliceSubtitle */, true /* isPublicSlice */);
final Uri uri = new Uri.Builder()
.scheme(SCHEME_CONTENT)
.authority(SettingsSliceProvider.SLICE_AUTHORITY)
@@ -328,7 +340,8 @@
@Test
public void getDescendantUris_oemSlice_returnsOEMUriDescendant() {
final String key = "oem_key";
- SliceTestUtils.insertSliceToDb(mContext, key, false /* isPlatformSlice */);
+ SliceTestUtils.insertSliceToDb(mContext, key, false /* isPlatformSlice */,
+ null /* customizedUnavailableSliceSubtitle */, true /* isPublicSlice */);
final Uri uri = new Uri.Builder()
.scheme(SCHEME_CONTENT)
.authority(SettingsSliceProvider.SLICE_AUTHORITY)
@@ -351,7 +364,8 @@
@Test
public void getDescendantUris_oemSliceNoPath_returnsOEMUriDescendant() {
final String key = "oem_key";
- SliceTestUtils.insertSliceToDb(mContext, key, false /* isPlatformSlice */);
+ SliceTestUtils.insertSliceToDb(mContext, key, false /* isPlatformSlice */,
+ null /* customizedUnavailableSliceSubtitle */, true /* isPublicSlice */);
final Uri uri = new Uri.Builder()
.scheme(SCHEME_CONTENT)
.authority(SettingsSliceProvider.SLICE_AUTHORITY)
@@ -371,9 +385,31 @@
}
@Test
+ public void getDescendantUris_oemSliceNoPath_notContainPrivateUri() {
+ final String key = "oem_key";
+ SliceTestUtils.insertSliceToDb(mContext, key, false /* isPlatformSlice */,
+ null /* customizedUnavailableSliceSubtitle */, false /* isPublicSlice */);
+ final Uri uri = new Uri.Builder()
+ .scheme(SCHEME_CONTENT)
+ .authority(SettingsSliceProvider.SLICE_AUTHORITY)
+ .build();
+ final Uri expectedUri = new Uri.Builder()
+ .scheme(SCHEME_CONTENT)
+ .authority(SettingsSliceProvider.SLICE_AUTHORITY)
+ .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
+ .appendPath(key)
+ .build();
+
+ final Collection<Uri> descendants = mProvider.onGetSliceDescendants(uri);
+
+ assertThat(descendants).doesNotContain(expectedUri);
+ }
+
+ @Test
public void getDescendantUris_platformSlice_returnsPlatformUriDescendant() {
final String key = "platform_key";
- SliceTestUtils.insertSliceToDb(mContext, key, true /* isPlatformSlice */);
+ SliceTestUtils.insertSliceToDb(mContext, key, true /* isPlatformSlice */,
+ null /* customizedUnavailableSliceSubtitle */, true /* isPublicSlice */);
final Uri uri = new Uri.Builder()
.scheme(SCHEME_CONTENT)
.authority(SettingsSlicesContract.AUTHORITY)
@@ -396,7 +432,8 @@
@Test
public void getDescendantUris_platformSliceNoPath_returnsPlatformUriDescendant() {
final String key = "platform_key";
- SliceTestUtils.insertSliceToDb(mContext, key, true /* isPlatformSlice */);
+ SliceTestUtils.insertSliceToDb(mContext, key, true /* isPlatformSlice */,
+ null /* customizedUnavailableSliceSubtitle */, true /* isPublicSlice */);
final Uri uri = new Uri.Builder()
.scheme(SCHEME_CONTENT)
.authority(SettingsSlicesContract.AUTHORITY)
@@ -419,8 +456,10 @@
public void getDescendantUris_noAuthorityNorPath_returnsAllUris() {
final String platformKey = "platform_key";
final String oemKey = "oemKey";
- SliceTestUtils.insertSliceToDb(mContext, platformKey, true /* isPlatformSlice */);
- SliceTestUtils.insertSliceToDb(mContext, oemKey, false /* isPlatformSlice */);
+ SliceTestUtils.insertSliceToDb(mContext, platformKey, true /* isPlatformSlice */,
+ null /* customizedUnavailableSliceSubtitle */, true /* isPublicSlice */);
+ SliceTestUtils.insertSliceToDb(mContext, oemKey, false /* isPlatformSlice */,
+ null /* customizedUnavailableSliceSubtitle */, true /* isPublicSlice */);
final Uri uri = new Uri.Builder()
.scheme(SCHEME_CONTENT)
.build();
@@ -446,6 +485,48 @@
}
@Test
+ @Config(qualifiers = "mcc999")
+ public void getDescendantUris_privateSlicesNeeded_containsPrivateSliceUri() {
+ final String privateKey = "test_private";
+ final Uri specialUri = Uri.parse("content://com.android.settings.slices/test");
+ doReturn(true).when(mProvider).isPrivateSlicesNeeded(specialUri);
+ SliceTestUtils.insertSliceToDb(mContext, privateKey /* key */, false /* isPlatformSlice */,
+ null /* customizedUnavailableSliceSubtitle */, false /* isPublicSlice */);
+ final Collection<Uri> expectedUris = new HashSet<>();
+ expectedUris.addAll(SPECIAL_CASE_OEM_URIS);
+ expectedUris.add(new Uri.Builder()
+ .scheme(SCHEME_CONTENT)
+ .authority(SettingsSliceProvider.SLICE_AUTHORITY)
+ .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
+ .appendPath(privateKey)
+ .build());
+
+ final Collection<Uri> descendants = mProvider.onGetSliceDescendants(specialUri);
+
+ assertThat(descendants).containsExactlyElementsIn(expectedUris);
+ }
+
+ @Test
+ @Config(qualifiers = "mcc999")
+ public void getDescendantUris_privateSlicesNotNeeded_notContainPrivateSliceUri() {
+ final Uri specialUri = Uri.parse("content://com.android.settings.slices/test");
+ doReturn(false).when(mProvider).isPrivateSlicesNeeded(specialUri);
+ SliceTestUtils.insertSliceToDb(mContext,
+ "test_private" /* key */, false /* isPlatformSlice */,
+ null /* customizedUnavailableSliceSubtitle */, false /* isPublicSlice */);
+ final Uri expectedUri = new Uri.Builder()
+ .scheme(SCHEME_CONTENT)
+ .authority(SettingsSliceProvider.SLICE_AUTHORITY)
+ .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
+ .appendPath("test_private")
+ .build();
+
+ final Collection<Uri> descendants = mProvider.onGetSliceDescendants(specialUri);
+
+ assertThat(descendants).doesNotContain(expectedUri);
+ }
+
+ @Test
public void onCreatePermissionRequest_returnsSettingIntent() {
final PendingIntent pendingIntent = mProvider.onCreatePermissionRequest(
CustomSliceRegistry.FLASHLIGHT_SLICE_URI, "com.android.whaaaat");
@@ -531,6 +612,56 @@
.grantSlicePermission("com.android.settings.slice_whitelist_package", uris.get(0));
}
+ @Test
+ @Config(qualifiers = "mcc999")
+ public void isPrivateSlicesNeeded_incorrectUri_returnFalse() {
+ final Uri uri = Uri.parse("content://com.android.settings.slices/test123");
+
+ assertThat(mProvider.isPrivateSlicesNeeded(uri)).isFalse();
+ }
+
+ @Test
+ public void isPrivateSlicesNeeded_noUri_returnFalse() {
+ final Uri uri = Uri.parse("content://com.android.settings.slices/test");
+
+ assertThat(mProvider.isPrivateSlicesNeeded(uri)).isFalse();
+ }
+
+ @Test
+ @Config(qualifiers = "mcc999")
+ public void isPrivateSlicesNeeded_correctUriWithPermissionAndIsSI_returnTrue() {
+ final Uri uri = Uri.parse("content://com.android.settings.slices/test");
+ ShadowBinder.setCallingUid(123);
+ doReturn(PERMISSION_GRANTED)
+ .when(mContext).checkPermission(anyString(), anyInt(), anyInt());
+ mPackageManager.setPackagesForUid(123, new String[]{"com.android.settings.intelligence"});
+
+ assertThat(mProvider.isPrivateSlicesNeeded(uri)).isTrue();
+ }
+
+ @Test
+ @Config(qualifiers = "mcc999")
+ public void isPrivateSlicesNeeded_correctUriWithPermissionNotSI_returnFalse() {
+ final Uri uri = Uri.parse("content://com.android.settings.slices/test");
+ ShadowBinder.setCallingUid(123);
+ doReturn(PERMISSION_GRANTED)
+ .when(mContext).checkPermission(anyString(), anyInt(), anyInt());
+ mPackageManager.setPackagesForUid(123, new String[]{"com.android.settings.test"});
+
+ assertThat(mProvider.isPrivateSlicesNeeded(uri)).isFalse();
+ }
+
+ @Test
+ @Config(qualifiers = "mcc999")
+ public void isPrivateSlicesNeeded_correctUriNoPermission_returnFalse() {
+ final Uri uri = Uri.parse("content://com.android.settings.slices/test");
+ ShadowBinder.setCallingUid(123);
+ doReturn(PERMISSION_DENIED).when(mContext).checkPermission(anyString(), anyInt(), anyInt());
+ mPackageManager.setPackagesForUid(123, new String[]{"com.android.settings.intelligence"});
+
+ assertThat(mProvider.isPrivateSlicesNeeded(uri)).isFalse();
+ }
+
private static SliceData getDummyData() {
return new SliceData.Builder()
.setKey(KEY)
diff --git a/tests/robotests/src/com/android/settings/slices/SliceTestUtils.java b/tests/robotests/src/com/android/settings/slices/SliceTestUtils.java
index 4f5b3a1..1c9164a 100644
--- a/tests/robotests/src/com/android/settings/slices/SliceTestUtils.java
+++ b/tests/robotests/src/com/android/settings/slices/SliceTestUtils.java
@@ -47,6 +47,11 @@
public static void insertSliceToDb(Context context, String key, boolean isPlatformSlice,
String customizedUnavailableSliceSubtitle) {
+ insertSliceToDb(context, key, isPlatformSlice, customizedUnavailableSliceSubtitle, false);
+ }
+
+ public static void insertSliceToDb(Context context, String key, boolean isPlatformSlice,
+ String customizedUnavailableSliceSubtitle, boolean isPublicSlice) {
final SQLiteDatabase db = SlicesDatabaseHelper.getInstance(context).getWritableDatabase();
ContentValues values = new ContentValues();
values.put(SlicesDatabaseHelper.IndexColumns.KEY, key);
@@ -69,6 +74,7 @@
values.put(SlicesDatabaseHelper.IndexColumns.SLICE_TYPE, SliceData.SliceType.INTENT);
values.put(SlicesDatabaseHelper.IndexColumns.UNAVAILABLE_SLICE_SUBTITLE,
customizedUnavailableSliceSubtitle);
+ values.put(SlicesDatabaseHelper.IndexColumns.PUBLIC_SLICE, isPublicSlice);
db.replaceOrThrow(SlicesDatabaseHelper.Tables.TABLE_SLICES_INDEX, null, values);
db.close();
diff --git a/tests/robotests/src/com/android/settings/slices/SlicesDatabaseAccessorTest.java b/tests/robotests/src/com/android/settings/slices/SlicesDatabaseAccessorTest.java
index a28dba8..b4385d8 100644
--- a/tests/robotests/src/com/android/settings/slices/SlicesDatabaseAccessorTest.java
+++ b/tests/robotests/src/com/android/settings/slices/SlicesDatabaseAccessorTest.java
@@ -17,6 +17,8 @@
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.spy;
@@ -168,8 +170,10 @@
@Test
public void getDescendantUris_platformSlice_doesNotReturnOEMSlice() {
final String key = "oem_key";
- SliceTestUtils.insertSliceToDb(mContext, key, false /* isPlatformSlice */);
- final List<Uri> keys = mAccessor.getSliceUris(SettingsSlicesContract.AUTHORITY);
+ SliceTestUtils.insertSliceToDb(mContext, key, false /* isPlatformSlice */,
+ null /* customizedUnavailableSliceSubtitle */, true /* isPublicSlice */);
+ final List<Uri> keys = mAccessor.getSliceUris(SettingsSlicesContract.AUTHORITY,
+ true /* isPublicSlice */);
assertThat(keys).isEmpty();
}
@@ -177,8 +181,10 @@
@Test
public void getDescendantUris_oemSlice_doesNotReturnPlatformSlice() {
final String key = "platform_key";
- SliceTestUtils.insertSliceToDb(mContext, key, true /* isPlatformSlice */);
- final List<Uri> keys = mAccessor.getSliceUris(SettingsSliceProvider.SLICE_AUTHORITY);
+ SliceTestUtils.insertSliceToDb(mContext, key, true /* isPlatformSlice */,
+ null /* customizedUnavailableSliceSubtitle */, true /* isPublicSlice */);
+ final List<Uri> keys = mAccessor.getSliceUris(SettingsSliceProvider.SLICE_AUTHORITY,
+ true /* isPublicSlice */);
assertThat(keys).isEmpty();
}
@@ -186,8 +192,10 @@
@Test
public void getDescendantUris_oemSlice_returnsOEMUriDescendant() {
final String key = "oem_key";
- SliceTestUtils.insertSliceToDb(mContext, key, false /* isPlatformSlice */);
- final List<Uri> keys = mAccessor.getSliceUris(SettingsSliceProvider.SLICE_AUTHORITY);
+ SliceTestUtils.insertSliceToDb(mContext, key, false /* isPlatformSlice */,
+ null /* customizedUnavailableSliceSubtitle */, true /* isPublicSlice */);
+ final List<Uri> keys = mAccessor.getSliceUris(SettingsSliceProvider.SLICE_AUTHORITY,
+ true /* isPublicSlice */);
assertThat(keys).containsExactly(
Uri.parse("content://com.android.settings.slices/action/oem_key"));
@@ -196,14 +204,52 @@
@Test
public void getDescendantUris_platformSlice_returnsPlatformUriDescendant() {
final String key = "platform_key";
- SliceTestUtils.insertSliceToDb(mContext, key, true /* isPlatformSlice */);
- final List<Uri> keys = mAccessor.getSliceUris(SettingsSlicesContract.AUTHORITY);
+ SliceTestUtils.insertSliceToDb(mContext, key, true /* isPlatformSlice */,
+ null /* customizedUnavailableSliceSubtitle */, true /* isPublicSlice */);
+ final List<Uri> keys = mAccessor.getSliceUris(SettingsSlicesContract.AUTHORITY,
+ true /* isPublicSlice */);
assertThat(keys).containsExactly(
Uri.parse("content://android.settings.slices/action/platform_key"));
}
@Test
+ public void getSliceUris_publicSlice_returnPublicUri() {
+ SliceTestUtils.insertSliceToDb(mContext, "test_public", false /* isPlatformSlice */,
+ null /* customizedUnavailableSliceSubtitle */, true /* isPublicSlice */);
+ SliceTestUtils.insertSliceToDb(mContext, "test_private", false /* isPlatformSlice */,
+ null /* customizedUnavailableSliceSubtitle */, false /* isPublicSlice */);
+ final Uri expectedUri = new Uri.Builder()
+ .scheme(SCHEME_CONTENT)
+ .authority(SettingsSliceProvider.SLICE_AUTHORITY)
+ .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
+ .appendPath("test_public")
+ .build();
+
+ final List<Uri> uri = mAccessor.getSliceUris(SettingsSliceProvider.SLICE_AUTHORITY, true);
+
+ assertThat(uri).containsExactly(expectedUri);
+ }
+
+ @Test
+ public void getSliceUris_nonPublicSlice_returnNonPublicUri() {
+ SliceTestUtils.insertSliceToDb(mContext, "test_public", false /* isPlatformSlice */,
+ null /* customizedUnavailableSliceSubtitle */, true /* isPublicSlice */);
+ SliceTestUtils.insertSliceToDb(mContext, "test_private", false /* isPlatformSlice */,
+ null /* customizedUnavailableSliceSubtitle */, false /* isPublicSlice */);
+ final Uri expectedUri = new Uri.Builder()
+ .scheme(SCHEME_CONTENT)
+ .authority(SettingsSliceProvider.SLICE_AUTHORITY)
+ .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
+ .appendPath("test_private")
+ .build();
+
+ final List<Uri> uri = mAccessor.getSliceUris(SettingsSliceProvider.SLICE_AUTHORITY, false);
+
+ assertThat(uri).containsExactly(expectedUri);
+ }
+
+ @Test
@Config(qualifiers = "mcc999")
public void getSliceKeys_indexesDatabase() {
// Force new indexing
@@ -220,7 +266,8 @@
FakeIndexProvider.SEARCH_INDEX_DATA_PROVIDER));
final SlicesDatabaseAccessor accessor = new SlicesDatabaseAccessor(mContext);
- final List<Uri> keys = accessor.getSliceUris(SettingsSliceProvider.SLICE_AUTHORITY);
+ final List<Uri> keys = accessor.getSliceUris(SettingsSliceProvider.SLICE_AUTHORITY,
+ true /* isPublicSlice */);
assertThat(keys).isNotEmpty();
}