android.content.RestrictionEntry Java Examples

The following examples show how to use android.content.RestrictionEntry. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AppRestrictionSchemaFragment.java    From enterprise-samples with Apache License 2.0 6 votes vote down vote up
private void resolveRestrictions() {
    RestrictionsManager manager =
            (RestrictionsManager) getActivity().getSystemService(Context.RESTRICTIONS_SERVICE);
    Bundle restrictions = manager.getApplicationRestrictions();
    List<RestrictionEntry> entries = manager.getManifestRestrictions(
            getActivity().getApplicationContext().getPackageName());
    for (RestrictionEntry entry : entries) {
        String key = entry.getKey();
        Log.d(TAG, "key: " + key);
        if (key.equals(KEY_CAN_SAY_HELLO)) {
            updateCanSayHello(entry, restrictions);
        } else if (key.equals(KEY_MESSAGE)) {
            updateMessage(entry, restrictions);
        } else if (key.equals(KEY_NUMBER)) {
            updateNumber(entry, restrictions);
        } else if (key.equals(KEY_RANK)) {
            updateRank(entry, restrictions);
        } else if (key.equals(KEY_APPROVALS)) {
            updateApprovals(entry, restrictions);
        } else if (key.equals(KEY_ITEMS)) {
            updateItems(restrictions);
        }
    }
}
 
Example #2
Source File: ManagedConfigurationsFragment.java    From android-testdpc with Apache License 2.0 6 votes vote down vote up
private int getRestrictionTypeFromDialogType(int typeIndex) {
    switch (typeIndex) {
        case KeyValuePairDialogFragment.DialogType.BOOL_TYPE:
            return RestrictionEntry.TYPE_BOOLEAN;
        case KeyValuePairDialogFragment.DialogType.INT_TYPE:
            return RestrictionEntry.TYPE_INTEGER;
        case KeyValuePairDialogFragment.DialogType.STRING_TYPE:
            return RestrictionEntry.TYPE_STRING;
        case KeyValuePairDialogFragment.DialogType.STRING_ARRAY_TYPE:
            return RestrictionEntry.TYPE_MULTI_SELECT;
        case KeyValuePairDialogFragment.DialogType.BUNDLE_TYPE:
            return RestrictionEntry.TYPE_BUNDLE;
        case KeyValuePairDialogFragment.DialogType.BUNDLE_ARRAY_TYPE:
            return RestrictionEntry.TYPE_BUNDLE_ARRAY;
        default:
            throw new AssertionError("Unknown type index");
    }
}
 
Example #3
Source File: ManagedConfigurationsFragment.java    From android-testdpc with Apache License 2.0 6 votes vote down vote up
private int getTypeIndexFromRestrictionType(int restrictionType) {
    switch (restrictionType) {
        case RestrictionEntry.TYPE_BOOLEAN:
            return KeyValuePairDialogFragment.DialogType.BOOL_TYPE;
        case RestrictionEntry.TYPE_INTEGER:
            return KeyValuePairDialogFragment.DialogType.INT_TYPE;
        case RestrictionEntry.TYPE_STRING:
            return KeyValuePairDialogFragment.DialogType.STRING_TYPE;
        case RestrictionEntry.TYPE_MULTI_SELECT:
            return KeyValuePairDialogFragment.DialogType.STRING_ARRAY_TYPE;
        case RestrictionEntry.TYPE_BUNDLE:
            return KeyValuePairDialogFragment.DialogType.BUNDLE_TYPE;
        case RestrictionEntry.TYPE_BUNDLE_ARRAY:
            return KeyValuePairDialogFragment.DialogType.BUNDLE_ARRAY_TYPE;
        default:
            throw new AssertionError("Unknown restriction type");
    }
}
 
Example #4
Source File: RestrictionManagerCompat.java    From android-testdpc with Apache License 2.0 6 votes vote down vote up
@TargetApi(VERSION_CODES.M)
private static void addBundleArrayRestrictionToBundle(Bundle bundle, RestrictionEntry entry) {
    if (Util.SDK_INT >= VERSION_CODES.M) {
        RestrictionEntry[] bundleRestrictionArray = entry.getRestrictions();
        Bundle[] bundleArray = new Bundle[bundleRestrictionArray.length];
        for (int i = 0; i < bundleRestrictionArray.length; i++) {
            RestrictionEntry[] bundleRestrictions =
                    bundleRestrictionArray[i].getRestrictions();
            if (bundleRestrictions == null) {
                // Non-bundle entry found in bundle array.
                Log.w(TAG, "addRestrictionToBundle: " +
                        "Non-bundle entry found in bundle array");
                bundleArray[i] = new Bundle();
            } else {
                bundleArray[i] = convertRestrictionsToBundle(Arrays.asList(
                        bundleRestrictions));
            }
        }
        bundle.putParcelableArray(entry.getKey(), bundleArray);
    } else {
        Log.w(TAG, "addBundleArrayRestrictionToBundle is called in pre-M");
    }
}
 
Example #5
Source File: AppRestrictionSchemaFragment.java    From android-AppRestrictionSchema with Apache License 2.0 6 votes vote down vote up
private void resolveRestrictions() {
    RestrictionsManager manager =
            (RestrictionsManager) getActivity().getSystemService(Context.RESTRICTIONS_SERVICE);
    Bundle restrictions = manager.getApplicationRestrictions();
    List<RestrictionEntry> entries = manager.getManifestRestrictions(
            getActivity().getApplicationContext().getPackageName());
    for (RestrictionEntry entry : entries) {
        String key = entry.getKey();
        Log.d(TAG, "key: " + key);
        if (key.equals(KEY_CAN_SAY_HELLO)) {
            updateCanSayHello(entry, restrictions);
        } else if (key.equals(KEY_MESSAGE)) {
            updateMessage(entry, restrictions);
        } else if (key.equals(KEY_NUMBER)) {
            updateNumber(entry, restrictions);
        } else if (key.equals(KEY_RANK)) {
            updateRank(entry, restrictions);
        } else if (key.equals(KEY_APPROVALS)) {
            updateApprovals(entry, restrictions);
        } else if (key.equals(KEY_ITEMS)) {
            updateItems(restrictions);
        }
    }
}
 
Example #6
Source File: ManagedConfigurationsFragment.java    From android-testdpc with Apache License 2.0 6 votes vote down vote up
protected RestrictionEntry[] convertBundleToRestrictions(Bundle restrictionBundle) {
    List<RestrictionEntry> restrictionEntries = new ArrayList<>();
    Set<String> keys = restrictionBundle.keySet();
    for (String key : keys) {
        Object value = restrictionBundle.get(key);
        if (value instanceof Boolean) {
            restrictionEntries.add(new RestrictionEntry(key, (boolean) value));
        } else if (value instanceof Integer) {
            restrictionEntries.add(new RestrictionEntry(key, (int) value));
        } else if (value instanceof String) {
            RestrictionEntry entry = new RestrictionEntry(RestrictionEntry.TYPE_STRING, key);
            entry.setSelectedString((String) value);
            restrictionEntries.add(entry);
        } else if (value instanceof String[]) {
            restrictionEntries.add(new RestrictionEntry(key, (String[]) value));
        } else if (value instanceof Bundle) {
            addBundleEntryToRestrictions(restrictionEntries, key, (Bundle) value);
        } else if (value instanceof Parcelable[]) {
            addBundleArrayToRestrictions(restrictionEntries, key, (Parcelable[]) value);
        }
    }
    return restrictionEntries.toArray(new RestrictionEntry[0]);
}
 
Example #7
Source File: GetRestrictionsReceiver.java    From enterprise-samples with Apache License 2.0 6 votes vote down vote up
private ArrayList<RestrictionEntry> initRestrictions(Context context) {
    ArrayList<RestrictionEntry> newRestrictions = new ArrayList<>();
    Resources res = context.getResources();

    RestrictionEntry reBoolean = new RestrictionEntry(KEY_BOOLEAN, false);
    populateBooleanEntry(res, reBoolean);
    newRestrictions.add(reBoolean);

    RestrictionEntry reSingleChoice = new RestrictionEntry(KEY_CHOICE, (String) null);
    populateChoiceEntry(res, reSingleChoice);
    newRestrictions.add(reSingleChoice);

    RestrictionEntry reMultiSelect = new RestrictionEntry(KEY_MULTI_SELECT, (String[]) null);
    populateMultiEntry(res, reMultiSelect);
    newRestrictions.add(reMultiSelect);

    return newRestrictions;
}
 
Example #8
Source File: GetRestrictionsReceiver.java    From android-AppRestrictions with Apache License 2.0 6 votes vote down vote up
private ArrayList<RestrictionEntry> initRestrictions(Context context) {
    ArrayList<RestrictionEntry> newRestrictions = new ArrayList<>();
    Resources res = context.getResources();

    RestrictionEntry reBoolean = new RestrictionEntry(KEY_BOOLEAN, false);
    populateBooleanEntry(res, reBoolean);
    newRestrictions.add(reBoolean);

    RestrictionEntry reSingleChoice = new RestrictionEntry(KEY_CHOICE, (String) null);
    populateChoiceEntry(res, reSingleChoice);
    newRestrictions.add(reSingleChoice);

    RestrictionEntry reMultiSelect = new RestrictionEntry(KEY_MULTI_SELECT, (String[]) null);
    populateMultiEntry(res, reMultiSelect);
    newRestrictions.add(reMultiSelect);

    return newRestrictions;
}
 
Example #9
Source File: GetRestrictionReceiver.java    From bitmask_android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onReceive(final Context context, Intent intent) {
    final PendingResult result = goAsync();

    new Thread() {
        @Override
        public void run() {
            final Bundle extras = new Bundle();

            ArrayList<RestrictionEntry> restrictionEntries = initRestrictions(context);

            extras.putParcelableArrayList(Intent.EXTRA_RESTRICTIONS_LIST, restrictionEntries);
            result.setResult(Activity.RESULT_OK,null,extras);
            result.finish();
        }
    }.run();
}
 
Example #10
Source File: AppRestrictionEnforcerFragment.java    From android-AppRestrictionEnforcer with Apache License 2.0 5 votes vote down vote up
/**
 * Loads the restrictions for the AppRestrictionSchema sample.
 *
 * @param activity The activity
 */
private void loadRestrictions(Activity activity) {
    RestrictionsManager manager =
            (RestrictionsManager) activity.getSystemService(Context.RESTRICTIONS_SERVICE);
    List<RestrictionEntry> restrictions =
            manager.getManifestRestrictions(Constants.PACKAGE_NAME_APP_RESTRICTION_SCHEMA);
    SharedPreferences prefs = activity.getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE);
    for (RestrictionEntry restriction : restrictions) {
        String key = restriction.getKey();
        if (RESTRICTION_KEY_SAY_HELLO.equals(key)) {
            updateCanSayHello(prefs.getBoolean(RESTRICTION_KEY_SAY_HELLO,
                    restriction.getSelectedState()));
        } else if (RESTRICTION_KEY_MESSAGE.equals(key)) {
            updateMessage(prefs.getString(RESTRICTION_KEY_MESSAGE,
                    restriction.getSelectedString()));
        } else if (RESTRICTION_KEY_NUMBER.equals(key)) {
            updateNumber(prefs.getInt(RESTRICTION_KEY_NUMBER,
                    restriction.getIntValue()));
        } else if (RESTRICTION_KEY_RANK.equals(key)) {
            updateRank(activity, restriction.getChoiceValues(),
                    prefs.getString(RESTRICTION_KEY_RANK, restriction.getSelectedString()));
        } else if (RESTRICTION_KEY_APPROVALS.equals(key)) {
            updateApprovals(activity, restriction.getChoiceValues(),
                    TextUtils.split(prefs.getString(RESTRICTION_KEY_APPROVALS,
                                    TextUtils.join(DELIMETER,
                                            restriction.getAllSelectedStrings())),
                            DELIMETER));
        } else if (BUNDLE_SUPPORTED && RESTRICTION_KEY_ITEMS.equals(key)) {
            String itemsString = prefs.getString(RESTRICTION_KEY_ITEMS, "");
            HashMap<String, String> items = new HashMap<>();
            for (String itemString : TextUtils.split(itemsString, DELIMETER)) {
                String[] strings = itemString.split(SEPARATOR, 2);
                items.put(strings[0], strings[1]);
            }
            updateItems(activity, items);
        }
    }
}
 
Example #11
Source File: AppRestrictionSchemaFragment.java    From android-AppRestrictionSchema with Apache License 2.0 5 votes vote down vote up
private void updateApprovals(RestrictionEntry entry, Bundle restrictions) {
    String[] approvals;
    if (restrictions == null || !restrictions.containsKey(KEY_APPROVALS)) {
        approvals = entry.getAllSelectedStrings();
    } else {
        approvals = restrictions.getStringArray(KEY_APPROVALS);
    }
    String text;
    if (approvals == null || approvals.length == 0) {
        text = getString(R.string.none);
    } else {
        text = TextUtils.join(", ", approvals);
    }
    mTextApprovals.setText(getString(R.string.approvals_you_have, text));
}
 
Example #12
Source File: AppRestrictionSchemaFragment.java    From android-AppRestrictionSchema with Apache License 2.0 5 votes vote down vote up
private void updateRank(RestrictionEntry entry, Bundle restrictions) {
    String rank;
    if (restrictions == null || !restrictions.containsKey(KEY_RANK)) {
        rank = entry.getSelectedString();
    } else {
        rank = restrictions.getString(KEY_RANK);
    }
    mTextRank.setText(getString(R.string.your_rank, rank));
}
 
Example #13
Source File: GetRestrictionsReceiver.java    From android-AppRestrictions with Apache License 2.0 5 votes vote down vote up
public static void populateChoiceEntry(Resources res, RestrictionEntry reSingleChoice) {
    String[] choiceEntries = res.getStringArray(R.array.choice_entry_entries);
    String[] choiceValues = res.getStringArray(R.array.choice_entry_values);
    if (reSingleChoice.getSelectedString() == null) {
        reSingleChoice.setSelectedString(choiceValues[0]);
    }
    reSingleChoice.setTitle(res.getString(R.string.choice_entry_title));
    reSingleChoice.setChoiceEntries(choiceEntries);
    reSingleChoice.setChoiceValues(choiceValues);
    reSingleChoice.setType(RestrictionEntry.TYPE_CHOICE);
}
 
Example #14
Source File: AppRestrictionSchemaFragment.java    From android-AppRestrictionSchema with Apache License 2.0 5 votes vote down vote up
private void updateNumber(RestrictionEntry entry, Bundle restrictions) {
    int number;
    if (restrictions == null || !restrictions.containsKey(KEY_NUMBER)) {
        number = entry.getIntValue();
    } else {
        number = restrictions.getInt(KEY_NUMBER);
    }
    mTextNumber.setText(getString(R.string.your_number, number));
}
 
Example #15
Source File: GetRestrictionsReceiver.java    From android-AppRestrictions with Apache License 2.0 5 votes vote down vote up
public static void populateMultiEntry(Resources res, RestrictionEntry reMultiSelect) {
    String[] multiEntries = res.getStringArray(R.array.multi_entry_entries);
    String[] multiValues = res.getStringArray(R.array.multi_entry_values);
    if (reMultiSelect.getAllSelectedStrings() == null) {
        reMultiSelect.setAllSelectedStrings(new String[0]);
    }
    reMultiSelect.setTitle(res.getString(R.string.multi_entry_title));
    reMultiSelect.setChoiceEntries(multiEntries);
    reMultiSelect.setChoiceValues(multiValues);
    reMultiSelect.setType(RestrictionEntry.TYPE_MULTI_SELECT);
}
 
Example #16
Source File: AppRestrictionSchemaFragment.java    From android-AppRestrictionSchema with Apache License 2.0 5 votes vote down vote up
private void updateMessage(RestrictionEntry entry, Bundle restrictions) {
    if (restrictions == null || !restrictions.containsKey(KEY_MESSAGE)) {
        mMessage = entry.getSelectedString();
    } else {
        mMessage = restrictions.getString(KEY_MESSAGE);
    }
}
 
Example #17
Source File: AppRestrictionSchemaFragment.java    From android-AppRestrictionSchema with Apache License 2.0 5 votes vote down vote up
private void updateCanSayHello(RestrictionEntry entry, Bundle restrictions) {
    boolean canSayHello;
    if (restrictions == null || !restrictions.containsKey(KEY_CAN_SAY_HELLO)) {
        canSayHello = entry.getSelectedState();
    } else {
        canSayHello = restrictions.getBoolean(KEY_CAN_SAY_HELLO);
    }
    mTextSayHello.setText(canSayHello ?
            R.string.explanation_can_say_hello_true :
            R.string.explanation_can_say_hello_false);
    mButtonSayHello.setEnabled(canSayHello);
}
 
Example #18
Source File: AppRestrictionEnforcerFragment.java    From enterprise-samples with Apache License 2.0 5 votes vote down vote up
/**
 * Loads the restrictions for the AppRestrictionSchema sample.
 *
 * @param activity The activity
 */
private void loadRestrictions(Activity activity) {
    RestrictionsManager manager =
            (RestrictionsManager) activity.getSystemService(Context.RESTRICTIONS_SERVICE);
    List<RestrictionEntry> restrictions =
            manager.getManifestRestrictions(Constants.PACKAGE_NAME_APP_RESTRICTION_SCHEMA);
    SharedPreferences prefs = activity.getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE);
    for (RestrictionEntry restriction : restrictions) {
        String key = restriction.getKey();
        if (RESTRICTION_KEY_SAY_HELLO.equals(key)) {
            updateCanSayHello(prefs.getBoolean(RESTRICTION_KEY_SAY_HELLO,
                    restriction.getSelectedState()));
        } else if (RESTRICTION_KEY_MESSAGE.equals(key)) {
            updateMessage(prefs.getString(RESTRICTION_KEY_MESSAGE,
                    restriction.getSelectedString()));
        } else if (RESTRICTION_KEY_NUMBER.equals(key)) {
            updateNumber(prefs.getInt(RESTRICTION_KEY_NUMBER,
                    restriction.getIntValue()));
        } else if (RESTRICTION_KEY_RANK.equals(key)) {
            updateRank(activity, restriction.getChoiceValues(),
                    prefs.getString(RESTRICTION_KEY_RANK, restriction.getSelectedString()));
        } else if (RESTRICTION_KEY_APPROVALS.equals(key)) {
            updateApprovals(activity, restriction.getChoiceValues(),
                    TextUtils.split(prefs.getString(RESTRICTION_KEY_APPROVALS,
                                    TextUtils.join(DELIMETER,
                                            restriction.getAllSelectedStrings())),
                            DELIMETER));
        } else if (BUNDLE_SUPPORTED && RESTRICTION_KEY_ITEMS.equals(key)) {
            String itemsString = prefs.getString(RESTRICTION_KEY_ITEMS, "");
            HashMap<String, String> items = new HashMap<>();
            for (String itemString : TextUtils.split(itemsString, DELIMETER)) {
                String[] strings = itemString.split(SEPARATOR, 2);
                items.put(strings[0], strings[1]);
            }
            updateItems(activity, items);
        }
    }
}
 
Example #19
Source File: RestrictionManagerCompat.java    From android-testdpc with Apache License 2.0 5 votes vote down vote up
@TargetApi(VERSION_CODES.M)
private static void addBundleRestrictionToBundle(Bundle bundle, RestrictionEntry entry) {
    if (Util.SDK_INT >= VERSION_CODES.M) {
        RestrictionEntry[] restrictions = entry.getRestrictions();
        Bundle childBundle = convertRestrictionsToBundle(Arrays.asList(restrictions));
        bundle.putBundle(entry.getKey(), childBundle);
    } else {
        Log.w(TAG, "addBundleRestrictionToBundle is called in pre-M");
    }
}
 
Example #20
Source File: GetRestrictionReceiver.java    From bitmask_android with GNU General Public License v3.0 5 votes vote down vote up
private ArrayList<RestrictionEntry> initRestrictions(Context context) {
    ArrayList<RestrictionEntry> restrictions = new ArrayList<RestrictionEntry>();
    RestrictionEntry allowChanges = new RestrictionEntry("allow_changes",false);
    allowChanges.setTitle(context.getString(R.string.allow_vpn_changes));
    restrictions.add(allowChanges);

    return restrictions;
}
 
Example #21
Source File: RestrictionManagerCompat.java    From android-testdpc with Apache License 2.0 5 votes vote down vote up
private static Bundle addRestrictionToBundle(Bundle bundle, RestrictionEntry entry) {
    switch (entry.getType()) {
        case RestrictionEntry.TYPE_BOOLEAN:
            bundle.putBoolean(entry.getKey(), entry.getSelectedState());
            break;
        case RestrictionEntry.TYPE_CHOICE:
        case RestrictionEntry.TYPE_MULTI_SELECT:
            bundle.putStringArray(entry.getKey(), entry.getAllSelectedStrings());
            break;
        case RestrictionEntry.TYPE_INTEGER:
            bundle.putInt(entry.getKey(), entry.getIntValue());
            break;
        case RestrictionEntry.TYPE_STRING:
        case RestrictionEntry.TYPE_NULL:
            bundle.putString(entry.getKey(), entry.getSelectedString());
            break;
        case RestrictionEntry.TYPE_BUNDLE:
            addBundleRestrictionToBundle(bundle, entry);
            break;
        case RestrictionEntry.TYPE_BUNDLE_ARRAY:
            addBundleArrayRestrictionToBundle(bundle, entry);
            break;
        default:
            throw new IllegalArgumentException(
                    "Unsupported restrictionEntry type: " + entry.getType());
    }
    return bundle;
}
 
Example #22
Source File: AppRestrictionSchemaFragment.java    From enterprise-samples with Apache License 2.0 5 votes vote down vote up
private void updateCanSayHello(RestrictionEntry entry, Bundle restrictions) {
    boolean canSayHello;
    if (restrictions == null || !restrictions.containsKey(KEY_CAN_SAY_HELLO)) {
        canSayHello = entry.getSelectedState();
    } else {
        canSayHello = restrictions.getBoolean(KEY_CAN_SAY_HELLO);
    }
    mTextSayHello.setText(canSayHello ?
            R.string.explanation_can_say_hello_true :
            R.string.explanation_can_say_hello_false);
    mButtonSayHello.setEnabled(canSayHello);
}
 
Example #23
Source File: AppRestrictionSchemaFragment.java    From enterprise-samples with Apache License 2.0 5 votes vote down vote up
private void updateMessage(RestrictionEntry entry, Bundle restrictions) {
    if (restrictions == null || !restrictions.containsKey(KEY_MESSAGE)) {
        mMessage = entry.getSelectedString();
    } else {
        mMessage = restrictions.getString(KEY_MESSAGE);
    }
}
 
Example #24
Source File: AppRestrictionSchemaFragment.java    From enterprise-samples with Apache License 2.0 5 votes vote down vote up
private void updateNumber(RestrictionEntry entry, Bundle restrictions) {
    int number;
    if (restrictions == null || !restrictions.containsKey(KEY_NUMBER)) {
        number = entry.getIntValue();
    } else {
        number = restrictions.getInt(KEY_NUMBER);
    }
    mTextNumber.setText(getString(R.string.your_number, number));
}
 
Example #25
Source File: AppRestrictionSchemaFragment.java    From enterprise-samples with Apache License 2.0 5 votes vote down vote up
private void updateRank(RestrictionEntry entry, Bundle restrictions) {
    String rank;
    if (restrictions == null || !restrictions.containsKey(KEY_RANK)) {
        rank = entry.getSelectedString();
    } else {
        rank = restrictions.getString(KEY_RANK);
    }
    mTextRank.setText(getString(R.string.your_rank, rank));
}
 
Example #26
Source File: ManagedConfigurationsFragment.java    From android-testdpc with Apache License 2.0 5 votes vote down vote up
private void loadManifestAppRestrictions(String pkgName) {
    if (!TextUtils.isEmpty(pkgName)) {
        List<RestrictionEntry> manifestRestrictions = null;
        try {
            manifestRestrictions = mRestrictionsManager.getManifestRestrictions(pkgName);
            convertTypeChoiceAndNullToString(manifestRestrictions);
        } catch (NullPointerException e) {
            // This means no default restrictions.
        }
        if (manifestRestrictions != null) {
            loadAppRestrictionsList(manifestRestrictions.toArray(new RestrictionEntry[0]));
        }
    }
}
 
Example #27
Source File: ManagedConfigurationsFragment.java    From android-testdpc with Apache License 2.0 5 votes vote down vote up
@TargetApi(VERSION_CODES.M)
private void updateRestrictionEntryFromResultIntent(RestrictionEntry restrictionEntry,
        Intent intent) {
    switch (restrictionEntry.getType()) {
        case RestrictionEntry.TYPE_BOOLEAN:
            restrictionEntry.setSelectedState(intent.getBooleanExtra(RESULT_VALUE, false));
            break;
        case RestrictionEntry.TYPE_INTEGER:
            restrictionEntry.setIntValue(intent.getIntExtra(RESULT_VALUE, 0));
            break;
        case RestrictionEntry.TYPE_STRING:
            restrictionEntry.setSelectedString(intent.getStringExtra(RESULT_VALUE));
            break;
        case RestrictionEntry.TYPE_MULTI_SELECT:
            restrictionEntry.setAllSelectedStrings(intent.getStringArrayExtra(RESULT_VALUE));
            break;
        case RestrictionEntry.TYPE_BUNDLE: {
            Bundle bundle = intent.getBundleExtra(RESULT_VALUE);
            restrictionEntry.setRestrictions(convertBundleToRestrictions(bundle));
            break;
        }
        case RestrictionEntry.TYPE_BUNDLE_ARRAY: {
            Parcelable[] bundleArray = intent.getParcelableArrayExtra(RESULT_VALUE);
            RestrictionEntry[] restrictionEntryArray = new RestrictionEntry[bundleArray.length];
            for (int i = 0; i< bundleArray.length; i++) {
                restrictionEntryArray[i] = RestrictionEntry.createBundleEntry(String.valueOf(i),
                        convertBundleToRestrictions((Bundle) bundleArray[i]));
            }
            restrictionEntry.setRestrictions(restrictionEntryArray);
            break;
        }
    }
}
 
Example #28
Source File: AppRestrictionSchemaFragment.java    From enterprise-samples with Apache License 2.0 5 votes vote down vote up
private void updateApprovals(RestrictionEntry entry, Bundle restrictions) {
    String[] approvals;
    if (restrictions == null || !restrictions.containsKey(KEY_APPROVALS)) {
        approvals = entry.getAllSelectedStrings();
    } else {
        approvals = restrictions.getStringArray(KEY_APPROVALS);
    }
    String text;
    if (approvals == null || approvals.length == 0) {
        text = getString(R.string.none);
    } else {
        text = TextUtils.join(", ", approvals);
    }
    mTextApprovals.setText(getString(R.string.approvals_you_have, text));
}
 
Example #29
Source File: ManagedConfigurationsFragment.java    From android-testdpc with Apache License 2.0 5 votes vote down vote up
@TargetApi(VERSION_CODES.M)
private void addBundleArrayToRestrictions(List<RestrictionEntry> restrictionEntries,
        String key, Parcelable[] value) {
    int length = value.length;
    RestrictionEntry[] entriesArray = new RestrictionEntry[length];
    for (int i = 0; i < entriesArray.length; ++i) {
        entriesArray[i] = RestrictionEntry.createBundleEntry(key,
                convertBundleToRestrictions((Bundle) value[i]));
    }
    restrictionEntries.add(RestrictionEntry.createBundleArrayEntry(key, entriesArray));
}
 
Example #30
Source File: ManagedConfigurationsFragment.java    From android-testdpc with Apache License 2.0 5 votes vote down vote up
/**
 * TODO (b/23378519): Remove this method and add support for type choice and null.
 */
private void convertTypeChoiceAndNullToString(List<RestrictionEntry> restrictionEntries) {
    for (RestrictionEntry entry : restrictionEntries) {
        if (entry.getType() == RestrictionEntry.TYPE_CHOICE ||
                entry.getType() == RestrictionEntry.TYPE_NULL) {
            entry.setType(RestrictionEntry.TYPE_STRING);
        }
    }
}