项目:buildAPKsSamples
文件:GetRestrictionsReceiver.java
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;
}
项目:mc_backup
文件:RestrictionProvider.java
@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();
}
项目:android-testdpc
文件:ManageAppRestrictionsFragment.java
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,(Parcelable[]) value);
}
}
return restrictionEntries.toArray(new RestrictionEntry[0]);
}
项目:android-testdpc
文件:ManageAppRestrictionsFragment.java
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");
}
}
项目:android-testdpc
文件:ManageAppRestrictionsFragment.java
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");
}
}
项目:android-testdpc
文件:RestrictionManagerCompat.java
@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");
}
}
@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,extras);
result.finish();
}
}.run();
}
@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,extras);
result.finish();
}
}.start();
}
项目:ics-openconnect
文件:GetRestrictionReceiver.java
@Override
public void onReceive(final Context context,extras);
result.finish();
}
}.run();
}
项目:buildAPKsSamples
文件:GetRestrictionsReceiver.java
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);
}
项目:buildAPKsSamples
文件:GetRestrictionsReceiver.java
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);
}
项目:mc_backup
文件:RestrictionProvider.java
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;
}
项目:android-testdpc
文件:ManageAppRestrictionsFragment.java
@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));
}
项目:android-testdpc
文件:ManageAppRestrictionsFragment.java
@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;
}
}
}
项目:android-testdpc
文件:ManageAppRestrictionsFragment.java
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]));
}
}
}
项目:android-testdpc
文件:ManageAppRestrictionsFragment.java
/**
* 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);
}
}
}
项目:android-testdpc
文件:RestrictionManagerCompat.java
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;
}
项目:android-testdpc
文件:RestrictionManagerCompat.java
@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");
}
}
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;
}
项目:ics-openconnect
文件:GetRestrictionReceiver.java
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;
}
项目:buildAPKsSamples
文件:GetRestrictionsReceiver.java
public static void populateBooleanEntry(Resources res,RestrictionEntry entry) {
entry.setType(RestrictionEntry.TYPE_BOOLEAN);
entry.setTitle(res.getString(R.string.boolean_entry_title));
}
项目:android-testdpc
文件:ManageAppRestrictionsFragment.java
protected void loadAppRestrictionsList(RestrictionEntry[] restrictionEntries) {
if (restrictionEntries != null) {
mAppRestrictionsArrayAdapter.clear();
mAppRestrictionsArrayAdapter.addAll(Arrays.asList(restrictionEntries));
}
}
项目:android-testdpc
文件:ManageAppRestrictionsFragment.java
@TargetApi(Build.VERSION_CODES.M)
private void addBundleEntryToRestrictions(List<RestrictionEntry> restrictionEntries,Bundle value) {
restrictionEntries.add(RestrictionEntry.createBundleEntry(
key,convertBundletoRestrictions(value)));
}
项目:android-testdpc
文件:ManageAppRestrictionsFragment.java
@Override
public void onEditButtonClick(RestrictionEntry restrictionEntry) {
showEditDialog(restrictionEntry);
}
项目:android-testdpc
文件:ManageAppRestrictionsFragment.java
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,value,supportType,getCurrentAppName());
dialogFragment.setTargetFragment(this,RESULT_CODE_EDIT_DIALOG);
dialogFragment.show(getFragmentManager(),"dialog");
}
项目:android-testdpc
文件:ManageAppRestrictionsFragment.java
@TargetApi(Build.VERSION_CODES.M)
private RestrictionEntry[] getRestrictionEntries(RestrictionEntry restrictionEntry) {
return restrictionEntry.getRestrictions();
}
项目:android-testdpc
文件:ManageAppRestrictionsFragment.java
public RestrictionEntryEditDeleteArrayAdapter(Context context,List<RestrictionEntry> entries,OnEditButtonClickListener onEditButtonClickListener,OnDeleteButtonClickListener onDeleteButtonClickListener) {
super(context,entries,onEditButtonClickListener,onDeleteButtonClickListener);
}
项目:android-testdpc
文件:ManageAppRestrictionsFragment.java
@Override
protected String getdisplayName(RestrictionEntry entry) {
return entry.getKey();
}
项目:mc_backup
文件:RestrictionProvider.java
private RestrictionEntry createRestrictionEntryWithDefaultValue(Context context,Restriction restriction,boolean defaultValue) {
RestrictionEntry entry = new RestrictionEntry(restriction.name,defaultValue);
entry.setTitle(restriction.getTitle(context));
return entry;
}
项目:android-testdpc
文件:RestrictionManagerCompat.java
/**
* 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;
}