RestrictionsReceiver
abstract class RestrictionsReceiver : BroadcastReceiver
Abstract implementation of a Restrictions Provider BroadcastReceiver. To implement a Restrictions Provider, extend from this class and implement the abstract methods. Export this receiver in the manifest. A profile owner device admin can then register this component as a Restrictions Provider using android.app.admin.DevicePolicyManager#setRestrictionsProvider(ComponentName,ComponentName).
The function of a Restrictions Provider is to transport permission requests from apps on this device to an administrator (most likely on a remote device or computer) and deliver back responses. The response should be sent back to the app via RestrictionsManager#notifyPermissionResponse(String, PersistableBundle)
.
Summary
Public methods |
open Unit |
Intercept standard Restrictions Provider broadcasts.
|
abstract Unit |
An asynchronous permission request made by an application for an operation that requires authorization by a local or remote administrator other than the user.
|
Inherited functions |
From class BroadcastReceiver
Unit |
abortBroadcast()
Sets the flag indicating that this receiver should abort the current broadcast; only works with broadcasts sent through Context.sendOrderedBroadcast . This will prevent any other broadcast receivers from receiving the broadcast. It will still call onReceive of the BroadcastReceiver that the caller of Context.sendOrderedBroadcast passed in.
This method does not work with non-ordered broadcasts such as those sent with Context.sendBroadcast
|
Unit |
clearAbortBroadcast()
Clears the flag indicating that this receiver should abort the current broadcast.
|
Boolean |
getAbortBroadcast()
Returns the flag indicating whether or not this receiver should abort the current broadcast.
|
Boolean |
getDebugUnregister()
Return the last value given to setDebugUnregister .
|
Int |
getResultCode()
Retrieve the current result code, as set by the previous receiver.
|
String! |
getResultData()
Retrieve the current result data, as set by the previous receiver. Often this is null.
|
Bundle! |
getResultExtras(makeMap: Boolean)
Retrieve the current result extra data, as set by the previous receiver. Any changes you make to the returned Map will be propagated to the next receiver.
|
String? |
getSentFromPackage()
Returns the package name of the app that initially sent this broadcast.
|
Int |
getSentFromUid()
Returns the uid of the app that initially sent this broadcast.
|
BroadcastReceiver.PendingResult! |
goAsync()
This can be called by an application in onReceive to allow it to keep the broadcast active after returning from that function. This does not change the expectation of being relatively responsive to the broadcast, but does allow the implementation to move work related to it over to another thread to avoid glitching the main UI thread due to disk IO.
As a general rule, broadcast receivers are allowed to run for up to 10 seconds before the system will consider them non-responsive and ANR the app. Since these usually execute on the app's main thread, they are already bound by the ~5 second time limit of various operations that can happen there (not to mention just avoiding UI jank), so the receive limit is generally not of concern. However, once you use goAsync , though able to be off the main thread, the broadcast execution limit still applies, and that includes the time spent between calling this method and ultimately PendingResult.finish() .
If you are taking advantage of this method to have more time to execute, it is useful to know that the available time can be longer in certain situations. In particular, if the broadcast you are receiving is not a foreground broadcast (that is, the sender has not used Intent#FLAG_RECEIVER_FOREGROUND ), then more time is allowed for the receivers to run, allowing them to execute for 30 seconds or even a bit more. This is something that receivers should rarely take advantage of (long work should be punted to another system facility such as android.app.job.JobScheduler , android.app.Service , or see especially androidx.core.app.JobIntentService), but can be useful in certain rare cases where it is necessary to do some work as soon as the broadcast is delivered. Keep in mind that the work you do here will block further broadcasts until it completes, so taking advantage of this at all excessively can be counter-productive and cause later events to be received more slowly.
|
Boolean |
isInitialStickyBroadcast()
Returns true if the receiver is currently processing the initial value of a sticky broadcast -- that is, the value that was last broadcast and is currently held in the sticky cache, so this is not directly the result of a broadcast right now.
|
Boolean |
isOrderedBroadcast()
Returns true if the receiver is currently processing an ordered broadcast.
|
IBinder! |
peekService(myContext: Context!, service: Intent!)
Provide a binder to an already-bound service. This method is synchronous and will not start the target service if it is not present, so it is safe to call from onReceive . For peekService() to return a non null android.os.IBinder interface the service must have published it before. In other words some component must have called android.content.Context#bindService(Intent, ServiceConnection, int) on it.
|
Unit |
setDebugUnregister(debug: Boolean)
Control inclusion of debugging help for mismatched calls to Context.registerReceiver() . If called with true, before given to registerReceiver(), then the callstack of the following Context.unregisterReceiver() call is retained, to be printed if a later incorrect unregister call is made. Note that doing this requires retaining information about the BroadcastReceiver for the lifetime of the app, resulting in a leak -- this should only be used for debugging.
|
Unit |
setOrderedHint(isOrdered: Boolean)
For internal use, sets the hint about whether this BroadcastReceiver is running in ordered mode.
|
Unit |
setResult(code: Int, data: String!, extras: Bundle!)
Change all of the result data returned from this broadcasts; only works with broadcasts sent through Context.sendOrderedBroadcast . All current result data is replaced by the value given to this method.
This method does not work with non-ordered broadcasts such as those sent with Context.sendBroadcast
|
Unit |
setResultCode(code: Int)
Change the current result code of this broadcast; only works with broadcasts sent through Context.sendOrderedBroadcast . Often uses the Activity android.app.Activity#RESULT_CANCELED and android.app.Activity#RESULT_OK constants, though the actual meaning of this value is ultimately up to the broadcaster.
This method does not work with non-ordered broadcasts such as those sent with Context.sendBroadcast
|
Unit |
setResultData(data: String!)
Change the current result data of this broadcast; only works with broadcasts sent through Context.sendOrderedBroadcast . This is an arbitrary string whose interpretation is up to the broadcaster.
This method does not work with non-ordered broadcasts such as those sent with Context.sendBroadcast
|
Unit |
setResultExtras(extras: Bundle!)
Change the current result extras of this broadcast; only works with broadcasts sent through Context.sendOrderedBroadcast . This is a Bundle holding arbitrary data, whose interpretation is up to the broadcaster. Can be set to null. Calling this method completely replaces the current map (if any).
This method does not work with non-ordered broadcasts such as those sent with Context.sendBroadcast
|
|
Public constructors
RestrictionsReceiver
RestrictionsReceiver()
Public methods
onReceive
open fun onReceive(
context: Context!,
intent: Intent!
): Unit
Intercept standard Restrictions Provider broadcasts. Implementations should not override this method; it is better to implement the convenience callbacks for each action.
Parameters |
context |
Context!: The Context in which the receiver is running. |
intent |
Intent!: The Intent being received. |
onRequestPermission
abstract fun onRequestPermission(
context: Context!,
packageName: String!,
requestType: String!,
requestId: String!,
request: PersistableBundle!
): Unit
An asynchronous permission request made by an application for an operation that requires authorization by a local or remote administrator other than the user. The Restrictions Provider should transfer the request to the administrator and deliver back a response, when available. The calling application is aware that the response could take an indefinite amount of time.
If the request bundle contains the key RestrictionsManager#REQUEST_KEY_NEW_REQUEST
, then a new request must be sent. Otherwise the provider can look up any previous response to the same requestId and return the cached response.
Parameters |
packageName |
String!: the application requesting permission. |
requestType |
String!: the type of request, which determines the content and presentation of the request data. |
request |
PersistableBundle!: the request data bundle containing at a minimum a request id. |