/* * Copyright (C) 2015 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.server.pm; import com.google.android.collect.Sets; import com.android.internal.util.Preconditions; import android.os.Bundle; import android.os.UserManager; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlSerializer; import java.io.IOException; import java.io.PrintWriter; import java.util.Set; public class UserRestrictionsUtils { private UserRestrictionsUtils() { } public static final String[] USER_RESTRICTIONS = { UserManager.DISALLOW_CONFIG_WIFI, UserManager.DISALLOW_MODIFY_ACCOUNTS, UserManager.DISALLOW_INSTALL_APPS, UserManager.DISALLOW_UNINSTALL_APPS, UserManager.DISALLOW_SHARE_LOCATION, UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES, UserManager.DISALLOW_CONFIG_BLUETOOTH, UserManager.DISALLOW_USB_FILE_TRANSFER, UserManager.DISALLOW_CONFIG_CREDENTIALS, UserManager.DISALLOW_REMOVE_USER, UserManager.DISALLOW_DEBUGGING_FEATURES, UserManager.DISALLOW_CONFIG_VPN, UserManager.DISALLOW_CONFIG_TETHERING, UserManager.DISALLOW_NETWORK_RESET, UserManager.DISALLOW_FACTORY_RESET, UserManager.DISALLOW_ADD_USER, UserManager.ENSURE_VERIFY_APPS, UserManager.DISALLOW_CONFIG_CELL_BROADCASTS, UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS, UserManager.DISALLOW_APPS_CONTROL, UserManager.DISALLOW_MOUNT_PHYSICAL_MEDIA, UserManager.DISALLOW_UNMUTE_MICROPHONE, UserManager.DISALLOW_ADJUST_VOLUME, UserManager.DISALLOW_OUTGOING_CALLS, UserManager.DISALLOW_SMS, UserManager.DISALLOW_FUN, UserManager.DISALLOW_CREATE_WINDOWS, UserManager.DISALLOW_CROSS_PROFILE_COPY_PASTE, UserManager.DISALLOW_OUTGOING_BEAM, UserManager.DISALLOW_WALLPAPER, UserManager.DISALLOW_SAFE_BOOT, UserManager.ALLOW_PARENT_PROFILE_APP_LINKING, UserManager.DISALLOW_RECORD_AUDIO, }; /** * Set of user restrictions, which can only be enforced by the system. */ public static final Set SYSTEM_CONTROLLED_USER_RESTRICTIONS = Sets.newArraySet( UserManager.DISALLOW_RECORD_AUDIO); /** * Set of user restriction which we don't want to persist. */ public static final Set NON_PERSIST_USER_RESTRICTIONS = Sets.newArraySet( UserManager.DISALLOW_RECORD_AUDIO); public static void writeRestrictions(XmlSerializer serializer, Bundle restrictions, String tag) throws IOException { serializer.startTag(null, tag); for (String key : USER_RESTRICTIONS) { if (restrictions.getBoolean(key) && !NON_PERSIST_USER_RESTRICTIONS.contains(key)) { serializer.attribute(null, key, "true"); } } serializer.endTag(null, tag); } public static void readRestrictions(XmlPullParser parser, Bundle restrictions) throws IOException { for (String key : USER_RESTRICTIONS) { final String value = parser.getAttributeValue(null, key); if (value != null) { restrictions.putBoolean(key, Boolean.parseBoolean(value)); } } } public static void merge(Bundle dest, Bundle in) { if (in == null) { return; } for (String key : in.keySet()) { if (in.getBoolean(key, false)) { dest.putBoolean(key, true); } } } public static void dumpRestrictions(PrintWriter pw, String prefix, Bundle restrictions) { boolean noneSet = true; if (restrictions != null) { for (String key : restrictions.keySet()) { if (restrictions.getBoolean(key, false)) { pw.println(prefix + key); noneSet = false; } } if (noneSet) { pw.println(prefix + "none"); } } else { pw.println(prefix + "null"); } } }