Changes to deal with restrictions API change
Bug: 8633967 Change-Id: I5d8e843c850ad3eff900409a9006666ddf91b061
This commit is contained in:
@@ -134,16 +134,12 @@ public class Settings extends PreferenceActivity
|
|||||||
private Header mLastHeader;
|
private Header mLastHeader;
|
||||||
private boolean mListeningToAccountUpdates;
|
private boolean mListeningToAccountUpdates;
|
||||||
|
|
||||||
private List<RestrictionEntry> mAppRestrictions;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
if (getIntent().hasExtra(EXTRA_UI_OPTIONS)) {
|
if (getIntent().hasExtra(EXTRA_UI_OPTIONS)) {
|
||||||
getWindow().setUiOptions(getIntent().getIntExtra(EXTRA_UI_OPTIONS, 0));
|
getWindow().setUiOptions(getIntent().getIntExtra(EXTRA_UI_OPTIONS, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
mAppRestrictions = getApplicationRestrictions();
|
|
||||||
|
|
||||||
mAuthenticatorHelper = new AuthenticatorHelper();
|
mAuthenticatorHelper = new AuthenticatorHelper();
|
||||||
mAuthenticatorHelper.updateAuthDescriptions(this);
|
mAuthenticatorHelper.updateAuthDescriptions(this);
|
||||||
mAuthenticatorHelper.onAccountsUpdated(this, null);
|
mAuthenticatorHelper.onAccountsUpdated(this, null);
|
||||||
|
@@ -562,7 +562,8 @@ public class AppRestrictionsFragment extends SettingsPreferenceFragment implemen
|
|||||||
if (packageName.equals(getActivity().getPackageName())) {
|
if (packageName.equals(getActivity().getPackageName())) {
|
||||||
RestrictionUtils.setRestrictions(getActivity(), restrictions, mUser);
|
RestrictionUtils.setRestrictions(getActivity(), restrictions, mUser);
|
||||||
} else {
|
} else {
|
||||||
mUserManager.setApplicationRestrictions(packageName, restrictions,
|
mUserManager.setApplicationRestrictions(packageName,
|
||||||
|
RestrictionUtils.restrictionsToBundle(restrictions),
|
||||||
mUser);
|
mUser);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -594,12 +595,11 @@ public class AppRestrictionsFragment extends SettingsPreferenceFragment implemen
|
|||||||
getActivity(), mUser);
|
getActivity(), mUser);
|
||||||
onRestrictionsReceived(preference, packageName, restrictions);
|
onRestrictionsReceived(preference, packageName, restrictions);
|
||||||
} else {
|
} else {
|
||||||
List<RestrictionEntry> oldEntries =
|
Bundle oldEntries =
|
||||||
mUserManager.getApplicationRestrictions(packageName, mUser);
|
mUserManager.getApplicationRestrictions(packageName, mUser);
|
||||||
Intent intent = new Intent(Intent.ACTION_GET_RESTRICTION_ENTRIES);
|
Intent intent = new Intent(Intent.ACTION_GET_RESTRICTION_ENTRIES);
|
||||||
intent.setPackage(packageName);
|
intent.setPackage(packageName);
|
||||||
intent.putParcelableArrayListExtra(Intent.EXTRA_RESTRICTIONS,
|
intent.putExtra(Intent.EXTRA_RESTRICTIONS_BUNDLE, oldEntries);
|
||||||
new ArrayList<RestrictionEntry>(oldEntries));
|
|
||||||
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
|
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
|
||||||
getActivity().sendOrderedBroadcast(intent, null,
|
getActivity().sendOrderedBroadcast(intent, null,
|
||||||
new RestrictionsResultReceiver(packageName, preference),
|
new RestrictionsResultReceiver(packageName, preference),
|
||||||
@@ -626,14 +626,16 @@ public class AppRestrictionsFragment extends SettingsPreferenceFragment implemen
|
|||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
Bundle results = getResultExtras(true);
|
Bundle results = getResultExtras(true);
|
||||||
final ArrayList<RestrictionEntry> restrictions = results.getParcelableArrayList(
|
final ArrayList<RestrictionEntry> restrictions = results.getParcelableArrayList(
|
||||||
Intent.EXTRA_RESTRICTIONS);
|
Intent.EXTRA_RESTRICTIONS_LIST);
|
||||||
Intent restrictionsIntent = (Intent) results.getParcelable(CUSTOM_RESTRICTIONS_INTENT);
|
Intent restrictionsIntent = (Intent) results.getParcelable(CUSTOM_RESTRICTIONS_INTENT);
|
||||||
if (restrictions != null && restrictionsIntent == null) {
|
if (restrictions != null && restrictionsIntent == null) {
|
||||||
onRestrictionsReceived(preference, packageName, restrictions);
|
onRestrictionsReceived(preference, packageName, restrictions);
|
||||||
mUserManager.setApplicationRestrictions(packageName, restrictions, mUser);
|
mUserManager.setApplicationRestrictions(packageName,
|
||||||
|
RestrictionUtils.restrictionsToBundle(restrictions), mUser);
|
||||||
} else if (restrictionsIntent != null) {
|
} else if (restrictionsIntent != null) {
|
||||||
final Intent customIntent = restrictionsIntent;
|
final Intent customIntent = restrictionsIntent;
|
||||||
customIntent.putParcelableArrayListExtra(Intent.EXTRA_RESTRICTIONS, restrictions);
|
customIntent.putExtra(Intent.EXTRA_RESTRICTIONS_BUNDLE,
|
||||||
|
RestrictionUtils.restrictionsToBundle(restrictions));
|
||||||
Preference p = new Preference(context);
|
Preference p = new Preference(context);
|
||||||
p.setTitle(R.string.app_restrictions_custom_label);
|
p.setTitle(R.string.app_restrictions_custom_label);
|
||||||
p.setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
p.setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
||||||
@@ -741,12 +743,13 @@ public class AppRestrictionsFragment extends SettingsPreferenceFragment implemen
|
|||||||
|
|
||||||
if (resultCode == Activity.RESULT_OK) {
|
if (resultCode == Activity.RESULT_OK) {
|
||||||
ArrayList<RestrictionEntry> list =
|
ArrayList<RestrictionEntry> list =
|
||||||
data.getParcelableArrayListExtra(Intent.EXTRA_RESTRICTIONS);
|
data.getParcelableArrayListExtra(Intent.EXTRA_RESTRICTIONS_LIST);
|
||||||
if (list != null) {
|
if (list != null) {
|
||||||
// If there's a valid result, persist it to the user manager.
|
// If there's a valid result, persist it to the user manager.
|
||||||
String packageName = pref.getKey().substring(PKG_PREFIX.length());
|
String packageName = pref.getKey().substring(PKG_PREFIX.length());
|
||||||
pref.setRestrictions(list);
|
pref.setRestrictions(list);
|
||||||
mUserManager.setApplicationRestrictions(packageName, list, mUser);
|
mUserManager.setApplicationRestrictions(packageName,
|
||||||
|
RestrictionUtils.restrictionsToBundle(list), mUser);
|
||||||
}
|
}
|
||||||
toggleAppPanel(pref);
|
toggleAppPanel(pref);
|
||||||
}
|
}
|
||||||
|
@@ -90,4 +90,18 @@ public class RestrictionUtils {
|
|||||||
}
|
}
|
||||||
um.setUserRestrictions(userRestrictions, user);
|
um.setUserRestrictions(userRestrictions, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Bundle restrictionsToBundle(ArrayList<RestrictionEntry> entries) {
|
||||||
|
final Bundle bundle = new Bundle();
|
||||||
|
for (RestrictionEntry entry : entries) {
|
||||||
|
if (entry.getType() == RestrictionEntry.TYPE_BOOLEAN) {
|
||||||
|
bundle.putBoolean(entry.getKey(), entry.getSelectedState());
|
||||||
|
} else if (entry.getType() == RestrictionEntry.TYPE_MULTI_SELECT) {
|
||||||
|
bundle.putStringArray(entry.getKey(), entry.getAllSelectedStrings());
|
||||||
|
} else {
|
||||||
|
bundle.putString(entry.getKey(), entry.getSelectedString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return bundle;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user