SettingsPreferenceServiceClient


public class SettingsPreferenceServiceClient
extends Object implements AutoCloseable

java.lang.Object
   ↳ android.service.settings.preferences.SettingsPreferenceServiceClient


Client class responsible for binding to and interacting with an instance of SettingsPreferenceService.

This is a convenience class to handle the lifecycle of the service connection.

This client will only interact with one instance at a time, so if the caller requires multiple instances (multiple applications that provide settings), then the caller must create multiple client classes, one for each instance required. To find all available services, a caller may query PackageManager for applications that provide the intent action SettingsPreferenceService.ACTION_PREFERENCE_SERVICE that are also system applications (ApplicationInfo.FLAG_SYSTEM).

Note: Each instance of this client will open a binding to an application. This can be resource intensive and affect the health of the system. It is essential that each client instance is only used when needed and the number of calls made are minimal.

Summary

Public constructors

SettingsPreferenceServiceClient(Context context, String packageName, Executor callbackExecutor, OutcomeReceiver<SettingsPreferenceServiceClientException> clientReadyCallback)

Construct a client for binding to a SettingsPreferenceService provided by the application corresponding to the provided package name.

Public methods

void close()

This client handles a resource, thus is it important to appropriately close that resource when it is no longer needed.

void getAllPreferenceMetadata(MetadataRequest request, Executor executor, OutcomeReceiver<MetadataResultException> receiver)

Retrieve the metadata for all exposed settings preferences within the application.

void getPreferenceValue(GetValueRequest request, Executor executor, OutcomeReceiver<GetValueResultException> receiver)

Retrieve the current value of the requested settings preference.

void setPreferenceValue(SetValueRequest request, Executor executor, OutcomeReceiver<SetValueResultException> receiver)

Set the value on the target settings preference.

Inherited methods

Object clone()

Creates and returns a copy of this object.

boolean equals(Object obj)

Indicates whether some other object is "equal to" this one.

void finalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

final Class<?> getClass()

Returns the runtime class of this Object.

int hashCode()

Returns a hash code value for the object.

final void notify()

Wakes up a single thread that is waiting on this object's monitor.

final void notifyAll()

Wakes up all threads that are waiting on this object's monitor.

String toString()

Returns a string representation of the object.

final void wait(long timeoutMillis, int nanos)

Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

final void wait(long timeoutMillis)

Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

final void wait()

Causes the current thread to wait until it is awakened, typically by being notified or interrupted.

abstract void close()

Closes this resource, relinquishing any underlying resources.

Public constructors

SettingsPreferenceServiceClient

public SettingsPreferenceServiceClient (Context context, 
                String packageName, 
                Executor callbackExecutor, 
                OutcomeReceiver<SettingsPreferenceServiceClientException> clientReadyCallback)

Construct a client for binding to a SettingsPreferenceService provided by the application corresponding to the provided package name.

Parameters
context Context: Application context

packageName String: package name for which this client will initiate a service binding

callbackExecutor Executor: executor on which to invoke clientReadyCallback Callback and listener events are dispatched through this Executor, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use Context.getMainExecutor(). Otherwise, provide an Executor that dispatches to an appropriate thread.

clientReadyCallback OutcomeReceiver: callback invoked once the client is ready, error otherwise

Public methods

close

public void close ()

This client handles a resource, thus is it important to appropriately close that resource when it is no longer needed.

This method is provided by AutoCloseable and calling it will unbind any service binding.

getAllPreferenceMetadata

public void getAllPreferenceMetadata (MetadataRequest request, 
                Executor executor, 
                OutcomeReceiver<MetadataResultException> receiver)

Retrieve the metadata for all exposed settings preferences within the application.

Parameters
request MetadataRequest: object to specify request parameters

executor Executor: Executor on which to invoke the receiver Callback and listener events are dispatched through this Executor, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use Context.getMainExecutor(). Otherwise, provide an Executor that dispatches to an appropriate thread.

receiver OutcomeReceiver: callback to receive the result or failure

getPreferenceValue

public void getPreferenceValue (GetValueRequest request, 
                Executor executor, 
                OutcomeReceiver<GetValueResultException> receiver)

Retrieve the current value of the requested settings preference.

Parameters
request GetValueRequest: object to specify request parameters

executor Executor: Executor on which to invoke the receiver Callback and listener events are dispatched through this Executor, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use Context.getMainExecutor(). Otherwise, provide an Executor that dispatches to an appropriate thread.

receiver OutcomeReceiver: callback to receive the result or failure

setPreferenceValue

public void setPreferenceValue (SetValueRequest request, 
                Executor executor, 
                OutcomeReceiver<SetValueResultException> receiver)

Set the value on the target settings preference.

Parameters
request SetValueRequest: object to specify request parameters

executor Executor: Executor on which to invoke the receiver Callback and listener events are dispatched through this Executor, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use Context.getMainExecutor(). Otherwise, provide an Executor that dispatches to an appropriate thread.

receiver OutcomeReceiver: callback to receive the result or failure