Add permission hint, update permission slice structure
Test: atest cts/tests/tests/slices
Bug: 75500766
Change-Id: Ic26dbaa121a3745174a6e21171f35abad69c61de
diff --git a/api/current.txt b/api/current.txt
index 85f238c..7251e8f 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -7213,6 +7213,7 @@
field public static final java.lang.String HINT_LIST_ITEM = "list_item";
field public static final java.lang.String HINT_NO_TINT = "no_tint";
field public static final java.lang.String HINT_PARTIAL = "partial";
+ field public static final java.lang.String HINT_PERMISSION_REQUEST = "permission_request";
field public static final java.lang.String HINT_SEE_MORE = "see_more";
field public static final java.lang.String HINT_SELECTED = "selected";
field public static final java.lang.String HINT_SHORTCUT = "shortcut";
diff --git a/core/java/android/app/slice/Slice.java b/core/java/android/app/slice/Slice.java
index 95bb1f6..fc3b38d 100644
--- a/core/java/android/app/slice/Slice.java
+++ b/core/java/android/app/slice/Slice.java
@@ -70,6 +70,7 @@
HINT_ERROR,
HINT_TTL,
HINT_LAST_UPDATED,
+ HINT_PERMISSION_REQUEST,
})
@Retention(RetentionPolicy.SOURCE)
public @interface SliceHint {}
@@ -184,6 +185,11 @@
*/
public static final String HINT_LAST_UPDATED = "last_updated";
/**
+ * A hint to indicate that this slice represents a permission request for showing
+ * slices.
+ */
+ public static final String HINT_PERMISSION_REQUEST = "permission_request";
+ /**
* Key to retrieve an extra added to an intent when a control is changed.
*/
public static final String EXTRA_TOGGLE_STATE = "android.app.slice.extra.TOGGLE_STATE";
diff --git a/core/java/android/app/slice/SliceProvider.java b/core/java/android/app/slice/SliceProvider.java
index bf856b7..bbeb3849 100644
--- a/core/java/android/app/slice/SliceProvider.java
+++ b/core/java/android/app/slice/SliceProvider.java
@@ -428,15 +428,17 @@
} finally {
Handler.getMain().removeCallbacks(mAnr);
}
- return new Slice.Builder(sliceUri)
- .addAction(action,
- new Slice.Builder(sliceUri.buildUpon().appendPath("permission").build())
- .addText(getPermissionString(context, callingPackage), null,
- Collections.emptyList())
- .build(),
- null)
- .addHints(Arrays.asList(Slice.HINT_LIST_ITEM))
- .build();
+ Slice.Builder parent = new Slice.Builder(sliceUri);
+ Slice.Builder childAction = new Slice.Builder(parent)
+ .addHints(Arrays.asList(Slice.HINT_TITLE, Slice.HINT_SHORTCUT))
+ .addAction(action, new Slice.Builder(parent).build(), null);
+
+ parent.addSubSlice(new Slice.Builder(sliceUri.buildUpon().appendPath("permission").build())
+ .addText(getPermissionString(context, callingPackage), null,
+ Collections.emptyList())
+ .addSubSlice(childAction.build(), null)
+ .build(), null);
+ return parent.addHints(Arrays.asList(Slice.HINT_PERMISSION_REQUEST)).build();
}
/**