Modify restrictions bundle per api council recommendations
Use a Bundle for persisting and passing to the application, but use a list to return data back from an application that's exposing restrictions. Changed the xml reading/writing code to store the value type in the Bundle so that it can be reproduced when reading. Earlier we were assuming only String and String[]. Bug: 8633967 Change-Id: I523d5553728edcf28a1e9d432f490b4956f34215
This commit is contained in:
@@ -134,11 +134,6 @@ public class Application extends ContextWrapper implements ComponentCallbacks2 {
|
||||
}
|
||||
}
|
||||
|
||||
public List<RestrictionEntry> getApplicationRestrictions() {
|
||||
return ((UserManager) getSystemService(USER_SERVICE))
|
||||
.getApplicationRestrictions(getPackageName(), android.os.Process.myUserHandle());
|
||||
}
|
||||
|
||||
public void registerComponentCallbacks(ComponentCallbacks callback) {
|
||||
synchronized (mComponentCallbacks) {
|
||||
mComponentCallbacks.add(callback);
|
||||
|
||||
@@ -292,15 +292,6 @@ public abstract class Context {
|
||||
*/
|
||||
public abstract Context getApplicationContext();
|
||||
|
||||
/**
|
||||
* Returns the list of restrictions for the application, or null if there are no
|
||||
* restrictions.
|
||||
* @return
|
||||
*/
|
||||
public List<RestrictionEntry> getApplicationRestrictions() {
|
||||
return getApplicationContext().getApplicationRestrictions();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new {@link ComponentCallbacks} to the base application of the
|
||||
* Context, which will be called at the same times as the ComponentCallbacks
|
||||
|
||||
@@ -2417,11 +2417,16 @@ public class Intent implements Parcelable, Cloneable {
|
||||
|
||||
/**
|
||||
* Broadcast to a specific application to query any supported restrictions to impose
|
||||
* on restricted users. The response should contain an extra {@link #EXTRA_RESTRICTIONS},
|
||||
* on restricted users. The broadcast intent contains an extra
|
||||
* {@link #EXTRA_RESTRICTIONS_BUNDLE} with the currently persisted
|
||||
* restrictions as a Bundle of key/value pairs. The value types can be Boolean, String or
|
||||
* String[] depending on the restriction type.<p/>
|
||||
* The response should contain an extra {@link #EXTRA_RESTRICTIONS_LIST},
|
||||
* which is of type <code>ArrayList<RestrictionEntry></code>. It can also
|
||||
* contain an extra {@link #EXTRA_RESTRICTIONS_INTENT}, which is of type <code>Intent</code>.
|
||||
* The activity specified by that intent will be launched for a result which must contain
|
||||
* the extra {@link #EXTRA_RESTRICTIONS}. The returned restrictions will be persisted.
|
||||
* the extra {@link #EXTRA_RESTRICTIONS_LIST}. The keys and values of the returned restrictions
|
||||
* will be persisted.
|
||||
* @see RestrictionEntry
|
||||
*/
|
||||
public static final String ACTION_GET_RESTRICTION_ENTRIES =
|
||||
@@ -3160,7 +3165,8 @@ public class Intent implements Parcelable, Cloneable {
|
||||
"android.intent.extra.ALLOW_MULTIPLE";
|
||||
|
||||
/**
|
||||
* The userHandle carried with broadcast intents related to addition, removal and switching of users
|
||||
* The userHandle carried with broadcast intents related to addition, removal and switching of
|
||||
* users
|
||||
* - {@link #ACTION_USER_ADDED}, {@link #ACTION_USER_REMOVED} and {@link #ACTION_USER_SWITCHED}.
|
||||
* @hide
|
||||
*/
|
||||
@@ -3169,9 +3175,18 @@ public class Intent implements Parcelable, Cloneable {
|
||||
|
||||
/**
|
||||
* Extra used in the response from a BroadcastReceiver that handles
|
||||
* {@link #ACTION_GET_RESTRICTION_ENTRIES}.
|
||||
* {@link #ACTION_GET_RESTRICTION_ENTRIES}. The type of the extra is
|
||||
* <code>ArrayList<RestrictionEntry></code>.
|
||||
*/
|
||||
public static final String EXTRA_RESTRICTIONS = "android.intent.extra.restrictions";
|
||||
public static final String EXTRA_RESTRICTIONS_LIST = "android.intent.extra.restrictions_list";
|
||||
|
||||
/**
|
||||
* Extra sent in the intent to the BroadcastReceiver that handles
|
||||
* {@link #ACTION_GET_RESTRICTION_ENTRIES}. The type of the extra is a Bundle containing
|
||||
* the restrictions as key/value pairs.
|
||||
*/
|
||||
public static final String EXTRA_RESTRICTIONS_BUNDLE =
|
||||
"android.intent.extra.restrictions_bundle";
|
||||
|
||||
/**
|
||||
* Extra used in the response from a BroadcastReceiver that handles
|
||||
|
||||
@@ -42,7 +42,8 @@ interface IUserManager {
|
||||
int getUserHandle(int userSerialNumber);
|
||||
Bundle getUserRestrictions(int userHandle);
|
||||
void setUserRestrictions(in Bundle restrictions, int userHandle);
|
||||
void setApplicationRestrictions(in String packageName, in List<RestrictionEntry> entries,
|
||||
void setApplicationRestrictions(in String packageName, in Bundle restrictions,
|
||||
int userHandle);
|
||||
List<RestrictionEntry> getApplicationRestrictions(in String packageName, int userHandle);
|
||||
Bundle getApplicationRestrictions(in String packageName);
|
||||
Bundle getApplicationRestrictionsForUser(in String packageName, int userHandle);
|
||||
}
|
||||
|
||||
@@ -142,6 +142,7 @@ public class UserManager {
|
||||
|
||||
private static UserManager sInstance = null;
|
||||
|
||||
/** @hide */
|
||||
public synchronized static UserManager get(Context context) {
|
||||
if (sInstance == null) {
|
||||
sInstance = (UserManager) context.getSystemService(Context.USER_SERVICE);
|
||||
@@ -578,13 +579,29 @@ public class UserManager {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Bundle containing any saved application restrictions for this user, for the
|
||||
* given package name. Only an application with this package name can call this method.
|
||||
* @param packageName the package name of the calling application
|
||||
* @return a Bundle with the restrictions as key/value pairs, or null if there are no
|
||||
* saved restrictions. The values can be of type Boolean, String or String[], depending
|
||||
* on the restriction type, as defined by the application.
|
||||
*/
|
||||
public Bundle getApplicationRestrictions(String packageName) {
|
||||
try {
|
||||
return mService.getApplicationRestrictions(packageName);
|
||||
} catch (RemoteException re) {
|
||||
Log.w(TAG, "Could not get application restrictions for package " + packageName);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
public List<RestrictionEntry> getApplicationRestrictions(String packageName, UserHandle user) {
|
||||
public Bundle getApplicationRestrictions(String packageName, UserHandle user) {
|
||||
try {
|
||||
return mService.getApplicationRestrictions(packageName, user.getIdentifier());
|
||||
return mService.getApplicationRestrictionsForUser(packageName, user.getIdentifier());
|
||||
} catch (RemoteException re) {
|
||||
Log.w(TAG, "Could not get application restrictions for user " + user.getIdentifier());
|
||||
}
|
||||
@@ -594,10 +611,10 @@ public class UserManager {
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
public void setApplicationRestrictions(String packageName, List<RestrictionEntry> entries,
|
||||
public void setApplicationRestrictions(String packageName, Bundle restrictions,
|
||||
UserHandle user) {
|
||||
try {
|
||||
mService.setApplicationRestrictions(packageName, entries, user.getIdentifier());
|
||||
mService.setApplicationRestrictions(packageName, restrictions, user.getIdentifier());
|
||||
} catch (RemoteException re) {
|
||||
Log.w(TAG, "Could not set application restrictions for user " + user.getIdentifier());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user