Java Code Examples for android.content.RestrictionEntry

The following are top voted examples for showing how to use android.content.RestrictionEntry. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: buildAPKsSamples   File: GetRestrictionsReceiver.java   View source code 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 2
Project: mc_backup   File: RestrictionProvider.java   View source code 6 votes vote down vote up
@Override
public void onReceive(final Context context, final Intent intent) {
    if (AppConstants.Versions.preJBMR2) {
        // This broadcast does not make any sense prior to Jelly Bean MR2.
        return;
    }

    final PendingResult result = goAsync();

    new Thread() {
        @Override
        public void run() {
            final Bundle oldRestrictions = intent.getBundleExtra(Intent.EXTRA_RESTRICTIONS_BUNDLE);
            final Bundle extras = new Bundle();

            ArrayList<RestrictionEntry> entries = initRestrictions(context, oldRestrictions);
            extras.putParcelableArrayList(Intent.EXTRA_RESTRICTIONS_LIST, entries);

            result.setResult(Activity.RESULT_OK, null, extras);
            result.finish();
        }
    }.start();
}
 
Example 3
Project: android-testdpc   File: ManageAppRestrictionsFragment.java   View source code 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 4
Project: android-testdpc   File: ManageAppRestrictionsFragment.java   View source code 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 5
Project: android-testdpc   File: ManageAppRestrictionsFragment.java   View source code 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 6
Project: android-testdpc   File: RestrictionManagerCompat.java   View source code 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.M)
private static void addBundleArrayRestrictionToBundle(Bundle bundle, RestrictionEntry entry) {
    if (Build.VERSION.SDK_INT >= Build.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 7
Project: disconnect-mobile-android   File: GetRestrictionReceiver.java   View source code 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 8
Project: Podcatcher-Deluxe-Android-Studio   File: GetRestrictionsReceiver.java   View source code 6 votes vote down vote up
@Override
public void onReceive(final Context context, Intent intent) {
    final PendingResult result = goAsync();

    new Thread() {
        public void run() {
            Process.setThreadPriority(THREAD_PRIORITY_BACKGROUND);
            final Bundle extras = new Bundle();

            // Create the restriction
            final RestrictionEntry hideExplicit = new RestrictionEntry(
                    BLOCK_EXPLICIT_RESTRICTION_KEY, true);
            hideExplicit.setTitle(context.getString(R.string.podcast_block_explicit));

            // Put everything together and send it back
            final ArrayList<RestrictionEntry> list = new ArrayList<>();
            list.add(hideExplicit);

            extras.putParcelableArrayList(Intent.EXTRA_RESTRICTIONS_LIST, list);
            result.setResult(Activity.RESULT_OK, null, extras);
            result.finish();
        }
    }.start();
}
 
Example 9
Project: ics-openconnect   File: GetRestrictionReceiver.java   View source code 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
Project: buildAPKsSamples   File: GetRestrictionsReceiver.java   View source code 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 11
Project: buildAPKsSamples   File: GetRestrictionsReceiver.java   View source code 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 12
Project: mc_backup   File: RestrictionProvider.java   View source code 5 votes vote down vote up
private ArrayList<RestrictionEntry> initRestrictions(Context context, Bundle oldRestrictions) {
    ArrayList<RestrictionEntry> entries = new ArrayList<RestrictionEntry>();

    for (Restriction restriction : RestrictedProfileConfiguration.DEFAULT_RESTRICTIONS) {
        RestrictionEntry entry = createRestrictionEntryWithDefaultValue(context, restriction,
                oldRestrictions.getBoolean(restriction.name, true));
        entries.add(entry);
    }

    return entries;
}
 
Example 13
Project: android-testdpc   File: ManageAppRestrictionsFragment.java   View source code 5 votes vote down vote up
@TargetApi(Build.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 14
Project: android-testdpc   File: ManageAppRestrictionsFragment.java   View source code 5 votes vote down vote up
@TargetApi(Build.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 15
Project: android-testdpc   File: ManageAppRestrictionsFragment.java   View source code 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 16
Project: android-testdpc   File: ManageAppRestrictionsFragment.java   View source code 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);
        }
    }
}
 
Example 17
Project: android-testdpc   File: RestrictionManagerCompat.java   View source code 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 18
Project: android-testdpc   File: RestrictionManagerCompat.java   View source code 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.M)
private static void addBundleRestrictionToBundle(Bundle bundle, RestrictionEntry entry) {
    if (Build.VERSION.SDK_INT >= Build.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 19
Project: disconnect-mobile-android   File: GetRestrictionReceiver.java   View source code 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 20
Project: ics-openconnect   File: GetRestrictionReceiver.java   View source code 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
Project: buildAPKsSamples   File: GetRestrictionsReceiver.java   View source code 4 votes vote down vote up
public static void populateBooleanEntry(Resources res, RestrictionEntry entry) {
    entry.setType(RestrictionEntry.TYPE_BOOLEAN);
    entry.setTitle(res.getString(R.string.boolean_entry_title));
}
 
Example 22
Project: android-testdpc   File: ManageAppRestrictionsFragment.java   View source code 4 votes vote down vote up
protected void loadAppRestrictionsList(RestrictionEntry[] restrictionEntries) {
    if (restrictionEntries != null) {
        mAppRestrictionsArrayAdapter.clear();
        mAppRestrictionsArrayAdapter.addAll(Arrays.asList(restrictionEntries));
    }
}
 
Example 23
Project: android-testdpc   File: ManageAppRestrictionsFragment.java   View source code 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.M)
private void addBundleEntryToRestrictions(List<RestrictionEntry> restrictionEntries,
        String key, Bundle value) {
    restrictionEntries.add(RestrictionEntry.createBundleEntry(
            key, convertBundleToRestrictions(value)));
}
 
Example 24
Project: android-testdpc   File: ManageAppRestrictionsFragment.java   View source code 4 votes vote down vote up
@Override
public void onEditButtonClick(RestrictionEntry restrictionEntry) {
    showEditDialog(restrictionEntry);
}
 
Example 25
Project: android-testdpc   File: ManageAppRestrictionsFragment.java   View source code 4 votes vote down vote up
private void showEditDialog(final RestrictionEntry restrictionEntry) {
    mEditingRestrictionEntry = restrictionEntry;
    int type = KeyValuePairDialogFragment.DialogType.BOOL_TYPE;
    Object value = null;
    String key = "";
    if (restrictionEntry != null) {
        key = restrictionEntry.getKey();
        type = getTypeIndexFromRestrictionType(restrictionEntry.getType());
        switch (restrictionEntry.getType()) {
            case RestrictionEntry.TYPE_BOOLEAN:
                value = restrictionEntry.getSelectedState();
                break;
            case RestrictionEntry.TYPE_INTEGER:
                value = restrictionEntry.getIntValue();
                break;
            case RestrictionEntry.TYPE_STRING:
                value = restrictionEntry.getSelectedString();
                break;
            case RestrictionEntry.TYPE_MULTI_SELECT:
                value = restrictionEntry.getAllSelectedStrings();
                break;
            case RestrictionEntry.TYPE_BUNDLE:
                value = RestrictionManagerCompat.convertRestrictionsToBundle(Arrays.asList(
                        getRestrictionEntries(restrictionEntry)));
                break;
            case RestrictionEntry.TYPE_BUNDLE_ARRAY:
                RestrictionEntry[] restrictionEntries = getRestrictionEntries(restrictionEntry);
                Bundle[] bundles = new Bundle[restrictionEntries.length];
                for (int i = 0; i < restrictionEntries.length; i++) {
                    bundles[i] =
                            RestrictionManagerCompat.convertRestrictionsToBundle(Arrays.asList(
                                    getRestrictionEntries(restrictionEntries[i])));
                }
                value = bundles;
                break;
        }
    }
    int[] supportType = (Build.VERSION.SDK_INT < Build.VERSION_CODES.M)
            ? SUPPORTED_TYPES_PRE_M
            : SUPPORTED_TYPES;
    KeyValuePairDialogFragment dialogFragment =
            KeyValuePairDialogFragment.newInstance(type, true, key, value, supportType,
                    getCurrentAppName());
    dialogFragment.setTargetFragment(this, RESULT_CODE_EDIT_DIALOG);
    dialogFragment.show(getFragmentManager(), "dialog");
}
 
Example 26
Project: android-testdpc   File: ManageAppRestrictionsFragment.java   View source code 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.M)
private RestrictionEntry[] getRestrictionEntries(RestrictionEntry restrictionEntry) {
    return restrictionEntry.getRestrictions();
}
 
Example 27
Project: android-testdpc   File: ManageAppRestrictionsFragment.java   View source code 4 votes vote down vote up
public RestrictionEntryEditDeleteArrayAdapter(Context context,
        List<RestrictionEntry> entries,
        OnEditButtonClickListener onEditButtonClickListener,
        OnDeleteButtonClickListener onDeleteButtonClickListener) {
    super(context, entries, onEditButtonClickListener, onDeleteButtonClickListener);
}
 
Example 28
Project: android-testdpc   File: ManageAppRestrictionsFragment.java   View source code 4 votes vote down vote up
@Override
protected String getDisplayName(RestrictionEntry entry) {
    return entry.getKey();
}
 
Example 29
Project: mc_backup   File: RestrictionProvider.java   View source code 3 votes vote down vote up
private RestrictionEntry createRestrictionEntryWithDefaultValue(Context context, Restriction restriction, boolean defaultValue) {
    RestrictionEntry entry = new RestrictionEntry(restriction.name, defaultValue);

    entry.setTitle(restriction.getTitle(context));

    return entry;
}
 
Example 30
Project: android-testdpc   File: RestrictionManagerCompat.java   View source code 3 votes vote down vote up
/**
 * Converts a list of restrictions to the corresponding bundle, using the following mapping:
 * <table>
 *     <tr><th>RestrictionEntry</th><th>Bundle</th></tr>
 *     <tr><td>{@link RestrictionEntry#TYPE_BOOLEAN}</td><td>{@link Bundle#putBoolean}</td></tr>
 *     <tr><td>{@link RestrictionEntry#TYPE_CHOICE},
 *     {@link RestrictionEntry#TYPE_MULTI_SELECT}</td>
 *     <td>{@link Bundle#putStringArray}</td></tr>
 *     <tr><td>{@link RestrictionEntry#TYPE_INTEGER}</td><td>{@link Bundle#putInt}</td></tr>
 *     <tr><td>{@link RestrictionEntry#TYPE_STRING}</td><td>{@link Bundle#putString}</td></tr>
 *     <tr><td>{@link RestrictionEntry#TYPE_BUNDLE}</td><td>{@link Bundle#putBundle}</td></tr>
 *     <tr><td>{@link RestrictionEntry#TYPE_BUNDLE_ARRAY}</td>
 *     <td>{@link Bundle#putParcelableArray}</td></tr>
 * </table>
 * TYPE_BUNDLE and TYPE_BUNDLE_ARRAY are supported from api level 23 onwards.
 * @param entries list of restrictions
 */
public static Bundle convertRestrictionsToBundle(List<RestrictionEntry> entries) {
    final Bundle bundle = new Bundle();
    for (RestrictionEntry entry : entries) {
        addRestrictionToBundle(bundle, entry);
    }
    return bundle;
}