1 /* 2 * Copyright (C) 2013 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.settings.users; 18 19 import android.content.Context; 20 import android.content.RestrictionEntry; 21 import android.content.res.Resources; 22 import android.os.Bundle; 23 import android.os.UserHandle; 24 import android.os.UserManager; 25 26 import com.android.settings.R; 27 28 import java.util.ArrayList; 29 30 public class RestrictionUtils { 31 32 public static final String [] sRestrictionKeys = { 33 // UserManager.DISALLOW_CONFIG_WIFI, 34 // UserManager.DISALLOW_CONFIG_BLUETOOTH, 35 UserManager.DISALLOW_SHARE_LOCATION, 36 // UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES 37 }; 38 39 public static final int [] sRestrictionTitles = { 40 // R.string.restriction_wifi_config_title, 41 // R.string.restriction_bluetooth_config_title, 42 R.string.restriction_location_enable_title, 43 // R.string.install_applications 44 }; 45 46 public static final int [] sRestrictionDescriptions = { 47 // R.string.restriction_wifi_config_summary, 48 // R.string.restriction_bluetooth_config_summary, 49 R.string.restriction_location_enable_summary, 50 // R.string.install_unknown_applications 51 }; 52 53 /** 54 * Returns the current user restrictions in the form of application 55 * restriction entries. 56 * @return list of RestrictionEntry objects with user-visible text. 57 */ getRestrictions(Context context, UserHandle user)58 public static ArrayList<RestrictionEntry> getRestrictions(Context context, UserHandle user) { 59 Resources res = context.getResources(); 60 ArrayList<RestrictionEntry> entries = new ArrayList<RestrictionEntry>(); 61 UserManager um = UserManager.get(context); 62 Bundle userRestrictions = um.getUserRestrictions(user); 63 64 for (int i = 0; i < sRestrictionKeys.length; i++) { 65 RestrictionEntry entry = new RestrictionEntry( 66 sRestrictionKeys[i], 67 !userRestrictions.getBoolean(sRestrictionKeys[i], false)); 68 entry.setTitle(res.getString(sRestrictionTitles[i])); 69 entry.setDescription(res.getString(sRestrictionDescriptions[i])); 70 entry.setType(RestrictionEntry.TYPE_BOOLEAN); 71 entries.add(entry); 72 } 73 74 return entries; 75 } 76 setRestrictions(Context context, ArrayList<RestrictionEntry> entries, UserHandle user)77 public static void setRestrictions(Context context, ArrayList<RestrictionEntry> entries, 78 UserHandle user) { 79 UserManager um = UserManager.get(context); 80 for (RestrictionEntry entry : entries) { 81 um.setUserRestriction(entry.getKey(), !entry.getSelectedState(), user); 82 } 83 } 84 } 85