Fields Summary |
---|
private static final String | TAG |
public static final String | ACTION_PERMISSION_RESPONSE_RECEIVEDBroadcast intent delivered when a response is received for a permission request. The
application should not interrupt the user by coming to the foreground if it isn't
currently in the foreground. It can either post a notification informing
the user of the response or wait until the next time the user launches the app.
For instance, if the user requested permission to make an in-app purchase,
the app can post a notification that the request had been approved or denied.
The broadcast Intent carries the following extra:
{@link #EXTRA_RESPONSE_BUNDLE}. |
public static final String | ACTION_REQUEST_PERMISSIONBroadcast intent sent to the Restrictions Provider to handle a permission request from
an app. It will have the following extras: {@link #EXTRA_PACKAGE_NAME},
{@link #EXTRA_REQUEST_TYPE}, {@link #EXTRA_REQUEST_ID} and {@link #EXTRA_REQUEST_BUNDLE}.
The Restrictions Provider will handle the request and respond back to the
RestrictionsManager, when a response is available, by calling
{@link #notifyPermissionResponse}.
The BroadcastReceiver must require the {@link android.Manifest.permission#BIND_DEVICE_ADMIN}
permission to ensure that only the system can send the broadcast. |
public static final String | ACTION_REQUEST_LOCAL_APPROVALActivity intent that is optionally implemented by the Restrictions Provider package
to challenge for an administrator PIN or password locally on the device. Apps will
call this intent using {@link Activity#startActivityForResult}. On a successful
response, {@link Activity#onActivityResult} will return a resultCode of
{@link Activity#RESULT_OK}.
The intent must contain {@link #EXTRA_REQUEST_BUNDLE} as an extra and the bundle must
contain at least {@link #REQUEST_KEY_MESSAGE} for the activity to display.
|
public static final String | EXTRA_PACKAGE_NAMEThe package name of the application making the request.
Type: String |
public static final String | EXTRA_REQUEST_TYPEThe request type passed in the {@link #ACTION_REQUEST_PERMISSION} broadcast.
Type: String |
public static final String | EXTRA_REQUEST_IDThe request ID passed in the {@link #ACTION_REQUEST_PERMISSION} broadcast.
Type: String |
public static final String | EXTRA_REQUEST_BUNDLEThe request bundle passed in the {@link #ACTION_REQUEST_PERMISSION} broadcast.
Type: {@link PersistableBundle} |
public static final String | EXTRA_RESPONSE_BUNDLEContains a response from the administrator for specific request.
The bundle contains the following information, at least:
- {@link #REQUEST_KEY_ID}: The request ID.
- {@link #RESPONSE_KEY_RESULT}: The response result.
Type: {@link PersistableBundle} |
public static final String | REQUEST_TYPE_APPROVALRequest type for a simple question, with a possible title and icon.
Required keys are: {@link #REQUEST_KEY_MESSAGE}
Optional keys are
{@link #REQUEST_KEY_DATA}, {@link #REQUEST_KEY_ICON}, {@link #REQUEST_KEY_TITLE},
{@link #REQUEST_KEY_APPROVE_LABEL} and {@link #REQUEST_KEY_DENY_LABEL}. |
public static final String | REQUEST_KEY_IDKey for request ID contained in the request bundle.
App-generated request ID to identify the specific request when receiving
a response. This value is returned in the {@link #EXTRA_RESPONSE_BUNDLE}.
Type: String |
public static final String | REQUEST_KEY_DATAKey for request data contained in the request bundle.
Optional, typically used to identify the specific data that is being referred to,
such as the unique identifier for a movie or book. This is not used for display
purposes and is more like a cookie. This value is returned in the
{@link #EXTRA_RESPONSE_BUNDLE}.
Type: String |
public static final String | REQUEST_KEY_TITLEKey for request title contained in the request bundle.
Optional, typically used as the title of any notification or dialog presented
to the administrator who approves the request.
Type: String |
public static final String | REQUEST_KEY_MESSAGEKey for request message contained in the request bundle.
Required, shown as the actual message in a notification or dialog presented
to the administrator who approves the request.
Type: String |
public static final String | REQUEST_KEY_ICONKey for request icon contained in the request bundle.
Optional, shown alongside the request message presented to the administrator
who approves the request. The content must be a compressed image such as a
PNG or JPEG, as a byte array.
Type: byte[] |
public static final String | REQUEST_KEY_APPROVE_LABELKey for request approval button label contained in the request bundle.
Optional, may be shown as a label on the positive button in a dialog or
notification presented to the administrator who approves the request.
Type: String |
public static final String | REQUEST_KEY_DENY_LABELKey for request rejection button label contained in the request bundle.
Optional, may be shown as a label on the negative button in a dialog or
notification presented to the administrator who approves the request.
Type: String |
public static final String | REQUEST_KEY_NEW_REQUESTKey for issuing a new request, contained in the request bundle. If this is set to true,
the Restrictions Provider must make a new request. If it is false or not specified, then
the Restrictions Provider can return a cached response that has the same requestId, if
available. If there's no cached response, it will issue a new one to the administrator.
Type: boolean |
public static final String | RESPONSE_KEY_RESULTKey for the response result in the response bundle sent to the application, for a permission
request. It indicates the status of the request. In some cases an additional message might
be available in {@link #RESPONSE_KEY_MESSAGE}, to be displayed to the user.
Type: int
Possible values: {@link #RESULT_APPROVED}, {@link #RESULT_DENIED},
{@link #RESULT_NO_RESPONSE}, {@link #RESULT_UNKNOWN_REQUEST} or
{@link #RESULT_ERROR}. |
public static final int | RESULT_APPROVEDResponse result value indicating that the request was approved. |
public static final int | RESULT_DENIEDResponse result value indicating that the request was denied. |
public static final int | RESULT_NO_RESPONSEResponse result value indicating that the request has not received a response yet. |
public static final int | RESULT_UNKNOWN_REQUESTResponse result value indicating that the request is unknown, when it's not a new
request. |
public static final int | RESULT_ERRORResponse result value indicating an error condition. Additional error code might be available
in the response bundle, for the key {@link #RESPONSE_KEY_ERROR_CODE}. There might also be
an associated error message in the response bundle, for the key
{@link #RESPONSE_KEY_MESSAGE}. |
public static final int | RESULT_ERROR_BAD_REQUESTError code indicating that there was a problem with the request.
Stored in {@link #RESPONSE_KEY_ERROR_CODE} field in the response bundle. |
public static final int | RESULT_ERROR_NETWORKError code indicating that there was a problem with the network.
Stored in {@link #RESPONSE_KEY_ERROR_CODE} field in the response bundle. |
public static final int | RESULT_ERROR_INTERNALError code indicating that there was an internal error.
Stored in {@link #RESPONSE_KEY_ERROR_CODE} field in the response bundle. |
public static final String | RESPONSE_KEY_ERROR_CODEKey for the optional error code in the response bundle sent to the application.
Type: int
Possible values: {@link #RESULT_ERROR_BAD_REQUEST}, {@link #RESULT_ERROR_NETWORK} or
{@link #RESULT_ERROR_INTERNAL}. |
public static final String | RESPONSE_KEY_MESSAGEKey for the optional message in the response bundle sent to the application.
Type: String |
public static final String | RESPONSE_KEY_RESPONSE_TIMESTAMPKey for the optional timestamp of when the administrator responded to the permission
request. It is an represented in milliseconds since January 1, 1970 00:00:00.0 UTC.
Type: long |
public static final String | META_DATA_APP_RESTRICTIONSName of the meta-data entry in the manifest that points to the XML file containing the
application's available restrictions. |
private static final String | TAG_RESTRICTION |
private final Context | mContext |
private final IRestrictionsManager | mService |
Methods Summary |
---|
public Intent | createLocalApprovalIntent()
try {
if (mService != null) {
return mService.createLocalApprovalIntent();
}
} catch (RemoteException re) {
Log.w(TAG, "Couldn't reach service");
}
return null;
|
public android.os.Bundle | getApplicationRestrictions()Returns any available set of application-specific restrictions applicable
to this application.
try {
if (mService != null) {
return mService.getApplicationRestrictions(mContext.getPackageName());
}
} catch (RemoteException re) {
Log.w(TAG, "Couldn't reach service");
}
return null;
|
public java.util.List | getManifestRestrictions(java.lang.String packageName)Parse and return the list of restrictions defined in the manifest for the specified
package, if any.
ApplicationInfo appInfo = null;
try {
appInfo = mContext.getPackageManager().getApplicationInfo(packageName,
PackageManager.GET_META_DATA);
} catch (NameNotFoundException pnfe) {
throw new IllegalArgumentException("No such package " + packageName);
}
if (appInfo == null || !appInfo.metaData.containsKey(META_DATA_APP_RESTRICTIONS)) {
return null;
}
XmlResourceParser xml =
appInfo.loadXmlMetaData(mContext.getPackageManager(), META_DATA_APP_RESTRICTIONS);
List<RestrictionEntry> restrictions = loadManifestRestrictions(packageName, xml);
return restrictions;
|
public boolean | hasRestrictionsProvider()Called by an application to check if there is an active Restrictions Provider. If
there isn't, {@link #requestPermission(String, String, PersistableBundle)} is not available.
try {
if (mService != null) {
return mService.hasRestrictionsProvider();
}
} catch (RemoteException re) {
Log.w(TAG, "Couldn't reach service");
}
return false;
|
private java.util.List | loadManifestRestrictions(java.lang.String packageName, android.content.res.XmlResourceParser xml)
Context appContext;
try {
appContext = mContext.createPackageContext(packageName, 0 /* flags */);
} catch (NameNotFoundException nnfe) {
return null;
}
ArrayList<RestrictionEntry> restrictions = new ArrayList<RestrictionEntry>();
RestrictionEntry restriction;
try {
int tagType = xml.next();
while (tagType != XmlPullParser.END_DOCUMENT) {
if (tagType == XmlPullParser.START_TAG) {
if (xml.getName().equals(TAG_RESTRICTION)) {
AttributeSet attrSet = Xml.asAttributeSet(xml);
if (attrSet != null) {
TypedArray a = appContext.obtainStyledAttributes(attrSet,
com.android.internal.R.styleable.RestrictionEntry);
restriction = loadRestriction(appContext, a);
if (restriction != null) {
restrictions.add(restriction);
}
}
}
}
tagType = xml.next();
}
} catch (XmlPullParserException e) {
Log.w(TAG, "Reading restriction metadata for " + packageName, e);
return null;
} catch (IOException e) {
Log.w(TAG, "Reading restriction metadata for " + packageName, e);
return null;
}
return restrictions;
|
private RestrictionEntry | loadRestriction(Context appContext, android.content.res.TypedArray a)
String key = a.getString(R.styleable.RestrictionEntry_key);
int restrictionType = a.getInt(
R.styleable.RestrictionEntry_restrictionType, -1);
String title = a.getString(R.styleable.RestrictionEntry_title);
String description = a.getString(R.styleable.RestrictionEntry_description);
int entries = a.getResourceId(R.styleable.RestrictionEntry_entries, 0);
int entryValues = a.getResourceId(R.styleable.RestrictionEntry_entryValues, 0);
if (restrictionType == -1) {
Log.w(TAG, "restrictionType cannot be omitted");
return null;
}
if (key == null) {
Log.w(TAG, "key cannot be omitted");
return null;
}
RestrictionEntry restriction = new RestrictionEntry(restrictionType, key);
restriction.setTitle(title);
restriction.setDescription(description);
if (entries != 0) {
restriction.setChoiceEntries(appContext, entries);
}
if (entryValues != 0) {
restriction.setChoiceValues(appContext, entryValues);
}
// Extract the default value based on the type
switch (restrictionType) {
case RestrictionEntry.TYPE_NULL: // hidden
case RestrictionEntry.TYPE_STRING:
case RestrictionEntry.TYPE_CHOICE:
restriction.setSelectedString(
a.getString(R.styleable.RestrictionEntry_defaultValue));
break;
case RestrictionEntry.TYPE_INTEGER:
restriction.setIntValue(
a.getInt(R.styleable.RestrictionEntry_defaultValue, 0));
break;
case RestrictionEntry.TYPE_MULTI_SELECT:
int resId = a.getResourceId(R.styleable.RestrictionEntry_defaultValue, 0);
if (resId != 0) {
restriction.setAllSelectedStrings(
appContext.getResources().getStringArray(resId));
}
break;
case RestrictionEntry.TYPE_BOOLEAN:
restriction.setSelectedState(
a.getBoolean(R.styleable.RestrictionEntry_defaultValue, false));
break;
default:
Log.w(TAG, "Unknown restriction type " + restrictionType);
}
return restriction;
|
public void | notifyPermissionResponse(java.lang.String packageName, android.os.PersistableBundle response)Called by the Restrictions Provider to deliver a response to an application.
if (packageName == null) {
throw new NullPointerException("packageName cannot be null");
}
if (response == null) {
throw new NullPointerException("request cannot be null");
}
if (!response.containsKey(REQUEST_KEY_ID)) {
throw new IllegalArgumentException("REQUEST_KEY_ID must be specified");
}
if (!response.containsKey(RESPONSE_KEY_RESULT)) {
throw new IllegalArgumentException("RESPONSE_KEY_RESULT must be specified");
}
try {
if (mService != null) {
mService.notifyPermissionResponse(packageName, response);
}
} catch (RemoteException re) {
Log.w(TAG, "Couldn't reach service");
}
|
public void | requestPermission(java.lang.String requestType, java.lang.String requestId, android.os.PersistableBundle request)Called by an application to request permission for an operation. The contents of the
request are passed in a Bundle that contains several pieces of data depending on the
chosen request type.
if (requestType == null) {
throw new NullPointerException("requestType cannot be null");
}
if (requestId == null) {
throw new NullPointerException("requestId cannot be null");
}
if (request == null) {
throw new NullPointerException("request cannot be null");
}
try {
if (mService != null) {
mService.requestPermission(mContext.getPackageName(), requestType, requestId,
request);
}
} catch (RemoteException re) {
Log.w(TAG, "Couldn't reach service");
}
|