Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5ee17505 authored by Amith Yamasani's avatar Amith Yamasani
Browse files

Changes to deal with restrictions API change

Bug: 8633967
Change-Id: I5d8e843c850ad3eff900409a9006666ddf91b061
parent e11a346f
Loading
Loading
Loading
Loading
+0 −4
Original line number Diff line number Diff line
@@ -134,16 +134,12 @@ public class Settings extends PreferenceActivity
    private Header mLastHeader;
    private boolean mListeningToAccountUpdates;

    private List<RestrictionEntry> mAppRestrictions;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        if (getIntent().hasExtra(EXTRA_UI_OPTIONS)) {
            getWindow().setUiOptions(getIntent().getIntExtra(EXTRA_UI_OPTIONS, 0));
        }

        mAppRestrictions = getApplicationRestrictions();

        mAuthenticatorHelper = new AuthenticatorHelper();
        mAuthenticatorHelper.updateAuthDescriptions(this);
        mAuthenticatorHelper.onAccountsUpdated(this, null);
+12 −9
Original line number Diff line number Diff line
@@ -562,7 +562,8 @@ public class AppRestrictionsFragment extends SettingsPreferenceFragment implemen
                        if (packageName.equals(getActivity().getPackageName())) {
                            RestrictionUtils.setRestrictions(getActivity(), restrictions, mUser);
                        } else {
                            mUserManager.setApplicationRestrictions(packageName, restrictions,
                            mUserManager.setApplicationRestrictions(packageName,
                                    RestrictionUtils.restrictionsToBundle(restrictions),
                                    mUser);
                        }
                        break;
@@ -594,12 +595,11 @@ public class AppRestrictionsFragment extends SettingsPreferenceFragment implemen
                            getActivity(), mUser);
                    onRestrictionsReceived(preference, packageName, restrictions);
                } else {
                    List<RestrictionEntry> oldEntries =
                    Bundle oldEntries =
                            mUserManager.getApplicationRestrictions(packageName, mUser);
                    Intent intent = new Intent(Intent.ACTION_GET_RESTRICTION_ENTRIES);
                    intent.setPackage(packageName);
                    intent.putParcelableArrayListExtra(Intent.EXTRA_RESTRICTIONS,
                            new ArrayList<RestrictionEntry>(oldEntries));
                    intent.putExtra(Intent.EXTRA_RESTRICTIONS_BUNDLE, oldEntries);
                    intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
                    getActivity().sendOrderedBroadcast(intent, null,
                            new RestrictionsResultReceiver(packageName, preference),
@@ -626,14 +626,16 @@ public class AppRestrictionsFragment extends SettingsPreferenceFragment implemen
        public void onReceive(Context context, Intent intent) {
            Bundle results = getResultExtras(true);
            final ArrayList<RestrictionEntry> restrictions = results.getParcelableArrayList(
                    Intent.EXTRA_RESTRICTIONS);
                    Intent.EXTRA_RESTRICTIONS_LIST);
            Intent restrictionsIntent = (Intent) results.getParcelable(CUSTOM_RESTRICTIONS_INTENT);
            if (restrictions != null && restrictionsIntent == null) {
                onRestrictionsReceived(preference, packageName, restrictions);
                mUserManager.setApplicationRestrictions(packageName, restrictions, mUser);
                mUserManager.setApplicationRestrictions(packageName,
                        RestrictionUtils.restrictionsToBundle(restrictions), mUser);
            } else if (restrictionsIntent != null) {
                final Intent customIntent = restrictionsIntent;
                customIntent.putParcelableArrayListExtra(Intent.EXTRA_RESTRICTIONS, restrictions);
                customIntent.putExtra(Intent.EXTRA_RESTRICTIONS_BUNDLE,
                        RestrictionUtils.restrictionsToBundle(restrictions));
                Preference p = new Preference(context);
                p.setTitle(R.string.app_restrictions_custom_label);
                p.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@@ -741,12 +743,13 @@ public class AppRestrictionsFragment extends SettingsPreferenceFragment implemen

        if (resultCode == Activity.RESULT_OK) {
            ArrayList<RestrictionEntry> list =
                    data.getParcelableArrayListExtra(Intent.EXTRA_RESTRICTIONS);
                    data.getParcelableArrayListExtra(Intent.EXTRA_RESTRICTIONS_LIST);
            if (list != null) {
                // If there's a valid result, persist it to the user manager.
                String packageName = pref.getKey().substring(PKG_PREFIX.length());
                pref.setRestrictions(list);
                mUserManager.setApplicationRestrictions(packageName, list, mUser);
                mUserManager.setApplicationRestrictions(packageName,
                        RestrictionUtils.restrictionsToBundle(list), mUser);
            }
            toggleAppPanel(pref);
        }
+14 −0
Original line number Diff line number Diff line
@@ -90,4 +90,18 @@ public class RestrictionUtils {
        }
        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;
    }
}