belongs to Maven artifact androidx.slice:slice-view:1.0.0-alpha1

SliceManager

public abstract class SliceManager
extends Object

java.lang.Object
   ↳ androidx.slice.SliceManager


Class to handle interactions with Slices.

The SliceManager manages permissions and pinned state for slices.

Summary

Nested classes

interface SliceManager.SliceCallback

Class that listens to changes in Slices. 

Public methods

abstract Slice bindSlice(Intent intent)

Turns a slice intent into slice content.

abstract Slice bindSlice(Uri uri)

Turns a slice Uri into slice content.

abstract int checkSlicePermission(Uri uri, int pid, int uid)

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

static SliceManager getInstance(Context context)

Get a SliceManager.

abstract List<Uri> getPinnedSlices()

Get the list of currently pinned slices for this app.

abstract Set<SliceSpec> getPinnedSpecs(Uri uri)

Get the current set of specs for a pinned slice.

abstract Collection<Uri> getSliceDescendants(Uri uri)

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

abstract void grantSlicePermission(String toPackage, Uri uri)

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

abstract Uri mapIntentToUri(Intent intent)

Turns a slice intent into a slice uri.

abstract void pinSlice(Uri uri)

Ensures that a slice is in a pinned state.

abstract void registerSliceCallback(Uri uri, Executor executor, SliceManager.SliceCallback callback)

Adds a callback to a specific slice uri.

abstract void registerSliceCallback(Uri uri, SliceManager.SliceCallback callback)

Adds a callback to a specific slice uri.

abstract void revokeSlicePermission(String toPackage, Uri uri)

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

abstract void unpinSlice(Uri uri)

Remove a pin for a slice.

abstract void unregisterSliceCallback(Uri uri, SliceManager.SliceCallback callback)

Removes a callback for a specific slice uri.

Inherited methods

Public methods

bindSlice

Slice bindSlice (Intent intent)

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.

Returns
Slice The Slice provided by the app or null if none is given.

bindSlice

Slice bindSlice (Uri uri)

Turns a slice Uri into slice content.

Parameters
uri Uri: The URI to a slice provider

Returns
Slice The Slice provided by the app or null if none is given.

See also:

checkSlicePermission

int checkSlicePermission (Uri uri, 
                int pid, 
                int uid)

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 int: The process ID being checked against. Must be > 0.

uid int: The user ID being checked against. A uid of 0 is the root user, which will pass every permission check.

Returns
int PackageManager.PERMISSION_GRANTED if the given pid/uid is allowed to access that uri, or PackageManager.PERMISSION_DENIED if it is not.

getInstance

SliceManager getInstance (Context context)

Get a SliceManager.

Parameters
context Context

Returns
SliceManager

getPinnedSlices

List<Uri> getPinnedSlices ()

Get the list of currently pinned slices for this app.

Returns
List<Uri>

getPinnedSpecs

Set<SliceSpec> getPinnedSpecs (Uri uri)

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.

Parameters
uri Uri

Returns
Set<SliceSpec>

See also:

  • SliceSpec

getSliceDescendants

Collection<Uri> getSliceDescendants (Uri 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.

Returns
Collection<Uri> All slices within the space.

grantSlicePermission

void grantSlicePermission (String toPackage, 
                Uri uri)

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 Uri: The Uri you would like to grant access to.

mapIntentToUri

Uri mapIntentToUri (Intent intent)

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 ContentResolver.getType(Uri) is 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 SliceManager.SLICE_METADATA_KEY, then the Uri specified there will be returned.
  3. Lastly, if the intent with SliceManager.CATEGORY_SLICE added resolves to a provider, then the provider will be asked to SliceProvider.onMapIntentToUri(Intent) 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.

Returns
Uri The Slice Uri provided by the app or null if none exists.

pinSlice

void pinSlice (Uri uri)

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.

registerSliceCallback

void registerSliceCallback (Uri uri, 
                Executor executor, 
                SliceManager.SliceCallback callback)

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 SliceManager.SliceCallbacks.

Parameters
uri Uri: The uri of the slice being listened to.

executor Executor

callback SliceManager.SliceCallback: The listener that should receive the callbacks.

registerSliceCallback

void registerSliceCallback (Uri uri, 
                SliceManager.SliceCallback callback)

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 SliceManager.SliceCallbacks.

Parameters
uri Uri: The uri of the slice being listened to.

callback SliceManager.SliceCallback: The listener that should receive the callbacks.

revokeSlicePermission

void revokeSlicePermission (String toPackage, 
                Uri uri)

Remove permissions to access a particular content provider Uri that were previously added with grantSlicePermission(String, Uri) 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 Uri: The Uri you would like to revoke access to.

unpinSlice

void unpinSlice (Uri uri)

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

void unregisterSliceCallback (Uri uri, 
                SliceManager.SliceCallback callback)

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 SliceManager.SliceCallback: The listener that should no longer receive callbacks.