SliceManager

abstract class SliceManager
kotlin.Any
   ↳ androidx.slice.SliceManager

Class to handle interactions with Slices.

The SliceManager manages permissions and pinned state for slices.

Summary

Nested classes
abstract

Class that listens to changes in Slices.

Public methods
abstract MutableSet<SliceSpec!>

Get the current set of specs for a pinned slice.

abstract Unit
revokeSlicePermission(toPackage: String, uri: Uri)

Remove permissions to access a particular content provider Uri that were previously added with #grantSlicePermission for a specific target package.

abstract Uri?

Turns a slice intent into a slice uri.

abstract Slice?
bindSlice(uri: Uri)

Turns a slice Uri into slice content.

abstract Slice?
bindSlice(intent: Intent)

Turns a slice intent into slice content.

abstract MutableList<Uri!>

Get the list of currently pinned slices for this app.

abstract MutableCollection<Uri!>

Obtains a list of slices that are descendants of the specified Uri.

abstract Unit

Adds a callback to a specific slice uri.

abstract Unit

Adds a callback to a specific slice uri.

abstract Unit

Remove a pin for a slice.

abstract Unit

Removes a callback for a specific slice uri.

abstract Unit
pinSlice(uri: Uri)

Ensures that a slice is in a pinned state.

abstract Int
checkSlicePermission(uri: Uri, pid: Int, uid: Int)

Determine whether a particular process and user ID has been granted permission to access a specific slice URI.

abstract Unit
grantSlicePermission(toPackage: String, uri: Uri)

Grant permission to access a specific slice Uri to another package.

open static SliceManager
getInstance(context: Context)

Get a SliceManager.

Public methods

getPinnedSpecs

abstract fun getPinnedSpecs(uri: Uri): MutableSet<SliceSpec!>

Get the current set of specs for a pinned slice.

This is the set of specs supported for a specific pinned slice. It will take into account all clients and returns only specs supported by all.

See Also

  • SliceSpec

revokeSlicePermission

abstract fun revokeSlicePermission(toPackage: String, uri: Uri): Unit

Remove permissions to access a particular content provider Uri that were previously added with #grantSlicePermission for a specific target package. The given Uri will match all previously granted Uris that are the same or a sub-path of the given Uri. That is, revoking "content://foo/target" will revoke both "content://foo/target" and "content://foo/target/sub", but not "content://foo". It will not remove any prefix grants that exist at a higher level.

Parameters
toPackage String: The package you would like to allow to access the Uri.
uri String: The Uri you would like to revoke access to.

mapIntentToUri

abstract fun mapIntentToUri(intent: Intent): Uri?

Turns a slice intent into a slice uri. Expects an explicit intent.

This goes through a several stage resolution process to determine if any slice can represent this intent.

  1. If the intent contains data that android.content.ContentResolver#getType is android.app.slice.SliceProvider#SLICE_TYPE then the data will be returned.
  2. If the intent explicitly points at an activity, and that activity has meta-data for key android.app.slice.SliceManager#SLICE_METADATA_KEY, then the Uri specified there will be returned.
  3. Lastly, if the intent with android.app.slice.SliceManager#CATEGORY_SLICE added resolves to a provider, then the provider will be asked to SliceProvider#onMapIntentToUri and that result will be returned.
  4. If no slice is found, then null is returned.
Parameters
intent Intent: The intent associated with a slice.
Return
Uri?: The Slice Uri provided by the app or null if none exists.

bindSlice

abstract fun bindSlice(uri: Uri): Slice?

Turns a slice Uri into slice content.

Parameters
uri Uri: The URI to a slice provider
Return
Slice?: The Slice provided by the app or null if none is given.

See Also

bindSlice

abstract fun bindSlice(intent: Intent): Slice?

Turns a slice intent into slice content. Is a shortcut to perform the action of both #mapIntentToUri(Intent) and #bindSlice(Uri) at once.

Parameters
intent Intent: The intent associated with a slice.
Return
Slice?: The Slice provided by the app or null if none is given.

getPinnedSlices

abstract fun getPinnedSlices(): MutableList<Uri!>

Get the list of currently pinned slices for this app.

getSliceDescendants

abstract fun getSliceDescendants(uri: Uri): MutableCollection<Uri!>

Obtains a list of slices that are descendants of the specified Uri.

Not all slice providers will implement this functionality, in which case, an empty collection will be returned.

Parameters
uri Uri: The uri to look for descendants under.
Return
MutableCollection<Uri!>: All slices within the space.

registerSliceCallback

abstract fun registerSliceCallback(uri: Uri, callback: SliceManager.SliceCallback): Unit

Adds a callback to a specific slice uri.

This is a convenience that performs a few slice actions at once. It will put the slice in a pinned state since there is a callback attached. It will also listen for content changes, when a content change observes, the android system will bind the new slice and provide it to all registered SliceCallbacks.

Parameters
uri Uri: The uri of the slice being listened to.
callback Uri: The listener that should receive the callbacks.

registerSliceCallback

abstract fun registerSliceCallback(uri: Uri, executor: Executor, callback: SliceManager.SliceCallback): Unit

Adds a callback to a specific slice uri.

This is a convenience that performs a few slice actions at once. It will put the slice in a pinned state since there is a callback attached. It will also listen for content changes, when a content change observes, the android system will bind the new slice and provide it to all registered SliceCallbacks.

Parameters
uri Uri: The uri of the slice being listened to.
callback Uri: The listener that should receive the callbacks.

unpinSlice

abstract fun unpinSlice(uri: Uri): Unit

Remove a pin for a slice.

If the slice has no other pins/callbacks then the slice will be unpinned.

Parameters
uri Uri: The uri of the slice being unpinned.

unregisterSliceCallback

abstract fun unregisterSliceCallback(uri: Uri, callback: SliceManager.SliceCallback): Unit

Removes a callback for a specific slice uri.

Removes the app from the pinned state (if there are no other apps/callbacks pinning it) in addition to removing the callback.

Parameters
uri Uri: The uri of the slice being listened to
callback Uri: The listener that should no longer receive callbacks.

pinSlice

abstract fun pinSlice(uri: Uri): Unit

Ensures that a slice is in a pinned state.

Pinned state is not persisted across reboots, so apps are expected to re-pin any slices they still care about after a reboot.

Parameters
uri Uri: The uri of the slice being pinned.

checkSlicePermission

abstract fun checkSlicePermission(uri: Uri, pid: Int, uid: Int): Int

Determine whether a particular process and user ID has been granted permission to access a specific slice URI.

Parameters
uri Uri: The uri that is being checked.
pid Uri: The process ID being checked against. Must be > 0.
uid Uri: The user ID being checked against. A uid of 0 is the root user, which will pass every permission check.
Return
Int: PackageManager#PERMISSION_GRANTED if the given pid/uid is allowed to access that uri, or PackageManager#PERMISSION_DENIED if it is not.

grantSlicePermission

abstract fun grantSlicePermission(toPackage: String, uri: Uri): Unit

Grant permission to access a specific slice Uri to another package.

Parameters
toPackage String: The package you would like to allow to access the Uri.
uri String: The Uri you would like to grant access to.

getInstance

open static fun getInstance(context: Context): SliceManager

Get a SliceManager.