SettingsPreferenceService


abstract class SettingsPreferenceService : Service
kotlin.Any
   ↳ android.content.Context
   ↳ android.content.ContextWrapper
   ↳ android.app.Service
   ↳ android.service.settings.preferences.SettingsPreferenceService

Base class for a service that exposes its settings preferences to external access.

This class is to be implemented by apps that contribute to the Android Settings surface. Access to this service is permission guarded by android.permission.READ_SYSTEM_PREFERENCES for binding and reading, and guarded by both android.permission.READ_SYSTEM_PREFERENCES and android.permission.WRITE_SYSTEM_PREFERENCES for writing. An additional checks for access control are the responsibility of the implementing class.

This implementation must correspond to an exported service declaration in the host app AndroidManifest.xml as follows

<service
      android:permission="android.permission.READ_SYSTEM_PREFERENCES"
      android:exported="true">
      <intent-filter>
          <action android:name="android.service.settings.preferences.action.PREFERENCE_SERVICE" />
      </intent-filter>
  </service>
  
  • It is recommended to expose the metadata for most, if not all, preferences within a settings app, thus implementing onGetAllPreferenceMetadata.
  • Exposing preferences for read access of their values is up to the implementer, but any exposed must be a subset of the preferences exposed in onGetAllPreferenceMetadata. To expose a preference for read access, the implementation will contain onGetPreferenceValue.
  • Exposing a preference for write access of their values is up to the implementer, but should be done so with extra care and consideration, both for security and privacy. These must also be a subset of those exposed in onGetAllPreferenceMetadata. To expose a preference for write access, the implementation will contain onSetPreferenceValue.

Summary

Constants
static String

Intent Action corresponding to a SettingsPreferenceService.

Inherited constants
Public constructors

Public methods
abstract Unit

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

abstract Unit

Retrieve the current value of the requested settings preference.

abstract Unit

Set the value within the request to the target settings preference.

Inherited functions

Constants

ACTION_PREFERENCE_SERVICE

static val ACTION_PREFERENCE_SERVICE: String

Intent Action corresponding to a SettingsPreferenceService. Note that any checks for such services must be accompanied by a check to ensure the host is a system application. Given an android.content.pm.ApplicationInfo you can check for android.content.pm.ApplicationInfo#FLAG_SYSTEM, or when querying android.content.pm.PackageManager#queryIntentServices you can provide the flag PackageManager.MATCH_SYSTEM_ONLY.

Value: "android.service.settings.preferences.action.PREFERENCE_SERVICE"

Public constructors

SettingsPreferenceService

SettingsPreferenceService()

Public methods

onGetAllPreferenceMetadata

abstract fun onGetAllPreferenceMetadata(
    request: MetadataRequest,
    callback: OutcomeReceiver<MetadataResult!, Exception!>
): Unit

Retrieve the metadata for all exposed settings preferences within this application. This data should be a snapshot of their state at the time of this method being called.

Parameters
request MetadataRequest: object to specify request parameters
callback OutcomeReceiver<MetadataResult!, Exception!>: object to receive result or failure of request

onGetPreferenceValue

abstract fun onGetPreferenceValue(
    request: GetValueRequest,
    callback: OutcomeReceiver<GetValueResult!, Exception!>
): Unit

Retrieve the current value of the requested settings preference. If this value is not exposed or cannot be obtained for some reason, the corresponding result code will be set on the result object.

Parameters
request GetValueRequest: object to specify request parameters
callback OutcomeReceiver<GetValueResult!, Exception!>: object to receive result or failure of request

onSetPreferenceValue

abstract fun onSetPreferenceValue(
    request: SetValueRequest,
    callback: OutcomeReceiver<SetValueResult!, Exception!>
): Unit

Set the value within the request to the target settings preference. If this value cannot be written for some reason, the corresponding result code will be set on the result object.

Parameters
request SetValueRequest: object to specify request parameters
callback OutcomeReceiver<SetValueResult!, Exception!>: object to receive result or failure of request