Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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.server; |
| 18 | |
Jeff Sharkey | b92b05b | 2016-01-28 09:50:00 -0700 | [diff] [blame] | 19 | import static com.android.internal.util.ArrayUtils.appendInt; |
| 20 | |
Dianne Hackborn | c0e4aaa | 2014-11-14 10:55:50 -0800 | [diff] [blame] | 21 | import android.app.ActivityManager; |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 22 | import android.content.pm.FeatureInfo; |
Jeff Sharkey | b92b05b | 2016-01-28 09:50:00 -0700 | [diff] [blame] | 23 | import android.content.pm.PackageManager; |
| 24 | import android.os.Environment; |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 25 | import android.os.Process; |
Jeff Sharkey | b92b05b | 2016-01-28 09:50:00 -0700 | [diff] [blame] | 26 | import android.os.storage.StorageManager; |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 27 | import android.util.ArrayMap; |
| 28 | import android.util.ArraySet; |
| 29 | import android.util.Slog; |
| 30 | import android.util.SparseArray; |
| 31 | import android.util.Xml; |
Jeff Sharkey | 1c4ae80 | 2014-12-19 11:08:55 -0800 | [diff] [blame] | 32 | |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 33 | import com.android.internal.util.XmlUtils; |
Jeff Sharkey | 1c4ae80 | 2014-12-19 11:08:55 -0800 | [diff] [blame] | 34 | |
Jeff Sharkey | b92b05b | 2016-01-28 09:50:00 -0700 | [diff] [blame] | 35 | import libcore.io.IoUtils; |
| 36 | |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 37 | import org.xmlpull.v1.XmlPullParser; |
| 38 | import org.xmlpull.v1.XmlPullParserException; |
| 39 | |
| 40 | import java.io.File; |
| 41 | import java.io.FileNotFoundException; |
| 42 | import java.io.FileReader; |
| 43 | import java.io.IOException; |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 44 | |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 45 | /** |
| 46 | * Loads global system configuration info. |
| 47 | */ |
| 48 | public class SystemConfig { |
| 49 | static final String TAG = "SystemConfig"; |
| 50 | |
| 51 | static SystemConfig sInstance; |
| 52 | |
Hung-ying Tyan | bdc9d58 | 2015-11-20 11:53:39 +0800 | [diff] [blame] | 53 | // permission flag, determines which types of configuration are allowed to be read |
| 54 | private static final int ALLOW_FEATURES = 0x01; |
| 55 | private static final int ALLOW_LIBS = 0x02; |
| 56 | private static final int ALLOW_PERMISSIONS = 0x04; |
| 57 | private static final int ALLOW_APP_CONFIGS = 0x08; |
| 58 | private static final int ALLOW_ALL = ~0; |
| 59 | |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 60 | // Group-ids that are given to all packages as read from etc/permissions/*.xml. |
| 61 | int[] mGlobalGids; |
| 62 | |
| 63 | // These are the built-in uid -> permission mappings that were read from the |
| 64 | // system configuration files. |
Jeff Sharkey | 9f837a9 | 2014-10-24 12:07:24 -0700 | [diff] [blame] | 65 | final SparseArray<ArraySet<String>> mSystemPermissions = new SparseArray<>(); |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 66 | |
| 67 | // These are the built-in shared libraries that were read from the |
| 68 | // system configuration files. Keys are the library names; strings are the |
| 69 | // paths to the libraries. |
Dianne Hackborn | bb8aa5a | 2014-09-17 13:20:38 -0700 | [diff] [blame] | 70 | final ArrayMap<String, String> mSharedLibraries = new ArrayMap<>(); |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 71 | |
| 72 | // These are the features this devices supports that were read from the |
| 73 | // system configuration files. |
Jeff Sharkey | 9f837a9 | 2014-10-24 12:07:24 -0700 | [diff] [blame] | 74 | final ArrayMap<String, FeatureInfo> mAvailableFeatures = new ArrayMap<>(); |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 75 | |
Jeff Sharkey | 1c4ae80 | 2014-12-19 11:08:55 -0800 | [diff] [blame] | 76 | // These are the features which this device doesn't support; the OEM |
| 77 | // partition uses these to opt-out of features from the system image. |
| 78 | final ArraySet<String> mUnavailableFeatures = new ArraySet<>(); |
| 79 | |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 80 | public static final class PermissionEntry { |
| 81 | public final String name; |
| 82 | public int[] gids; |
Jeff Sharkey | 00f3904 | 2015-03-23 16:51:22 -0700 | [diff] [blame] | 83 | public boolean perUser; |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 84 | |
Jeff Sharkey | 00f3904 | 2015-03-23 16:51:22 -0700 | [diff] [blame] | 85 | PermissionEntry(String name, boolean perUser) { |
| 86 | this.name = name; |
| 87 | this.perUser = perUser; |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 88 | } |
| 89 | } |
| 90 | |
| 91 | // These are the permission -> gid mappings that were read from the |
| 92 | // system configuration files. |
Dianne Hackborn | bb8aa5a | 2014-09-17 13:20:38 -0700 | [diff] [blame] | 93 | final ArrayMap<String, PermissionEntry> mPermissions = new ArrayMap<>(); |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 94 | |
| 95 | // These are the packages that are white-listed to be able to run in the |
Dianne Hackborn | 4a503b1 | 2015-08-06 22:19:06 -0700 | [diff] [blame] | 96 | // background while in power save mode (but not whitelisted from device idle modes), |
| 97 | // as read from the configuration files. |
| 98 | final ArraySet<String> mAllowInPowerSaveExceptIdle = new ArraySet<>(); |
| 99 | |
| 100 | // These are the packages that are white-listed to be able to run in the |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 101 | // background while in power save mode, as read from the configuration files. |
Dianne Hackborn | bb8aa5a | 2014-09-17 13:20:38 -0700 | [diff] [blame] | 102 | final ArraySet<String> mAllowInPowerSave = new ArraySet<>(); |
| 103 | |
| 104 | // These are the app package names that should not allow IME switching. |
| 105 | final ArraySet<String> mFixedImeApps = new ArraySet<>(); |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 106 | |
Christopher Tate | 01e1864 | 2015-07-07 18:10:38 -0700 | [diff] [blame] | 107 | // These are the package names of apps which should be in the 'always' |
| 108 | // URL-handling state upon factory reset. |
| 109 | final ArraySet<String> mLinkedApps = new ArraySet<>(); |
| 110 | |
Fyodor Kupolov | 7db5af1 | 2015-07-31 16:50:27 -0700 | [diff] [blame] | 111 | // These are the packages that are whitelisted to be able to run as system user |
| 112 | final ArraySet<String> mSystemUserWhitelistedApps = new ArraySet<>(); |
| 113 | |
| 114 | // These are the packages that should not run under system user |
| 115 | final ArraySet<String> mSystemUserBlacklistedApps = new ArraySet<>(); |
| 116 | |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 117 | public static SystemConfig getInstance() { |
| 118 | synchronized (SystemConfig.class) { |
| 119 | if (sInstance == null) { |
| 120 | sInstance = new SystemConfig(); |
| 121 | } |
| 122 | return sInstance; |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | public int[] getGlobalGids() { |
| 127 | return mGlobalGids; |
| 128 | } |
| 129 | |
Jeff Sharkey | 9f837a9 | 2014-10-24 12:07:24 -0700 | [diff] [blame] | 130 | public SparseArray<ArraySet<String>> getSystemPermissions() { |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 131 | return mSystemPermissions; |
| 132 | } |
| 133 | |
| 134 | public ArrayMap<String, String> getSharedLibraries() { |
| 135 | return mSharedLibraries; |
| 136 | } |
| 137 | |
Jeff Sharkey | 9f837a9 | 2014-10-24 12:07:24 -0700 | [diff] [blame] | 138 | public ArrayMap<String, FeatureInfo> getAvailableFeatures() { |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 139 | return mAvailableFeatures; |
| 140 | } |
| 141 | |
| 142 | public ArrayMap<String, PermissionEntry> getPermissions() { |
| 143 | return mPermissions; |
| 144 | } |
| 145 | |
Dianne Hackborn | 4a503b1 | 2015-08-06 22:19:06 -0700 | [diff] [blame] | 146 | public ArraySet<String> getAllowInPowerSaveExceptIdle() { |
| 147 | return mAllowInPowerSaveExceptIdle; |
| 148 | } |
| 149 | |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 150 | public ArraySet<String> getAllowInPowerSave() { |
| 151 | return mAllowInPowerSave; |
| 152 | } |
| 153 | |
Dianne Hackborn | bb8aa5a | 2014-09-17 13:20:38 -0700 | [diff] [blame] | 154 | public ArraySet<String> getFixedImeApps() { |
| 155 | return mFixedImeApps; |
| 156 | } |
| 157 | |
Christopher Tate | 01e1864 | 2015-07-07 18:10:38 -0700 | [diff] [blame] | 158 | public ArraySet<String> getLinkedApps() { |
| 159 | return mLinkedApps; |
| 160 | } |
| 161 | |
Fyodor Kupolov | 7db5af1 | 2015-07-31 16:50:27 -0700 | [diff] [blame] | 162 | public ArraySet<String> getSystemUserWhitelistedApps() { |
| 163 | return mSystemUserWhitelistedApps; |
| 164 | } |
| 165 | |
| 166 | public ArraySet<String> getSystemUserBlacklistedApps() { |
| 167 | return mSystemUserBlacklistedApps; |
| 168 | } |
| 169 | |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 170 | SystemConfig() { |
| 171 | // Read configuration from system |
| 172 | readPermissions(Environment.buildPath( |
Hung-ying Tyan | bdc9d58 | 2015-11-20 11:53:39 +0800 | [diff] [blame] | 173 | Environment.getRootDirectory(), "etc", "sysconfig"), ALLOW_ALL); |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 174 | // Read configuration from the old permissions dir |
| 175 | readPermissions(Environment.buildPath( |
Hung-ying Tyan | bdc9d58 | 2015-11-20 11:53:39 +0800 | [diff] [blame] | 176 | Environment.getRootDirectory(), "etc", "permissions"), ALLOW_ALL); |
| 177 | // Allow ODM to customize system configs around libs, features and apps |
| 178 | int odmPermissionFlag = ALLOW_LIBS | ALLOW_FEATURES | ALLOW_APP_CONFIGS; |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 179 | readPermissions(Environment.buildPath( |
Hung-ying Tyan | bdc9d58 | 2015-11-20 11:53:39 +0800 | [diff] [blame] | 180 | Environment.getOdmDirectory(), "etc", "sysconfig"), odmPermissionFlag); |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 181 | readPermissions(Environment.buildPath( |
Hung-ying Tyan | bdc9d58 | 2015-11-20 11:53:39 +0800 | [diff] [blame] | 182 | Environment.getOdmDirectory(), "etc", "permissions"), odmPermissionFlag); |
| 183 | // Only allow OEM to customize features |
| 184 | readPermissions(Environment.buildPath( |
| 185 | Environment.getOemDirectory(), "etc", "sysconfig"), ALLOW_FEATURES); |
| 186 | readPermissions(Environment.buildPath( |
| 187 | Environment.getOemDirectory(), "etc", "permissions"), ALLOW_FEATURES); |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 188 | } |
| 189 | |
Hung-ying Tyan | bdc9d58 | 2015-11-20 11:53:39 +0800 | [diff] [blame] | 190 | void readPermissions(File libraryDir, int permissionFlag) { |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 191 | // Read permissions from given directory. |
| 192 | if (!libraryDir.exists() || !libraryDir.isDirectory()) { |
Hung-ying Tyan | bdc9d58 | 2015-11-20 11:53:39 +0800 | [diff] [blame] | 193 | if (permissionFlag == ALLOW_ALL) { |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 194 | Slog.w(TAG, "No directory " + libraryDir + ", skipping"); |
| 195 | } |
| 196 | return; |
| 197 | } |
| 198 | if (!libraryDir.canRead()) { |
| 199 | Slog.w(TAG, "Directory " + libraryDir + " cannot be read"); |
| 200 | return; |
| 201 | } |
| 202 | |
| 203 | // Iterate over the files in the directory and scan .xml files |
Jeff Sharkey | 1c4ae80 | 2014-12-19 11:08:55 -0800 | [diff] [blame] | 204 | File platformFile = null; |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 205 | for (File f : libraryDir.listFiles()) { |
| 206 | // We'll read platform.xml last |
| 207 | if (f.getPath().endsWith("etc/permissions/platform.xml")) { |
Jeff Sharkey | 1c4ae80 | 2014-12-19 11:08:55 -0800 | [diff] [blame] | 208 | platformFile = f; |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 209 | continue; |
| 210 | } |
| 211 | |
| 212 | if (!f.getPath().endsWith(".xml")) { |
| 213 | Slog.i(TAG, "Non-xml file " + f + " in " + libraryDir + " directory, ignoring"); |
| 214 | continue; |
| 215 | } |
| 216 | if (!f.canRead()) { |
| 217 | Slog.w(TAG, "Permissions library file " + f + " cannot be read"); |
| 218 | continue; |
| 219 | } |
| 220 | |
Hung-ying Tyan | bdc9d58 | 2015-11-20 11:53:39 +0800 | [diff] [blame] | 221 | readPermissionsFromXml(f, permissionFlag); |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 222 | } |
| 223 | |
Jeff Sharkey | 1c4ae80 | 2014-12-19 11:08:55 -0800 | [diff] [blame] | 224 | // Read platform permissions last so it will take precedence |
| 225 | if (platformFile != null) { |
Hung-ying Tyan | bdc9d58 | 2015-11-20 11:53:39 +0800 | [diff] [blame] | 226 | readPermissionsFromXml(platformFile, permissionFlag); |
Jeff Sharkey | 1c4ae80 | 2014-12-19 11:08:55 -0800 | [diff] [blame] | 227 | } |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 228 | } |
| 229 | |
Hung-ying Tyan | bdc9d58 | 2015-11-20 11:53:39 +0800 | [diff] [blame] | 230 | private void readPermissionsFromXml(File permFile, int permissionFlag) { |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 231 | FileReader permReader = null; |
| 232 | try { |
| 233 | permReader = new FileReader(permFile); |
| 234 | } catch (FileNotFoundException e) { |
| 235 | Slog.w(TAG, "Couldn't find or open permissions file " + permFile); |
| 236 | return; |
| 237 | } |
| 238 | |
Dianne Hackborn | c0e4aaa | 2014-11-14 10:55:50 -0800 | [diff] [blame] | 239 | final boolean lowRam = ActivityManager.isLowRamDeviceStatic(); |
| 240 | |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 241 | try { |
| 242 | XmlPullParser parser = Xml.newPullParser(); |
| 243 | parser.setInput(permReader); |
| 244 | |
| 245 | int type; |
| 246 | while ((type=parser.next()) != parser.START_TAG |
| 247 | && type != parser.END_DOCUMENT) { |
| 248 | ; |
| 249 | } |
| 250 | |
| 251 | if (type != parser.START_TAG) { |
| 252 | throw new XmlPullParserException("No start tag found"); |
| 253 | } |
| 254 | |
| 255 | if (!parser.getName().equals("permissions") && !parser.getName().equals("config")) { |
Dianne Hackborn | b3d4cb3 | 2015-01-09 09:54:06 -0800 | [diff] [blame] | 256 | throw new XmlPullParserException("Unexpected start tag in " + permFile |
| 257 | + ": found " + parser.getName() + ", expected 'permissions' or 'config'"); |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 258 | } |
| 259 | |
Hung-ying Tyan | bdc9d58 | 2015-11-20 11:53:39 +0800 | [diff] [blame] | 260 | boolean allowAll = permissionFlag == ALLOW_ALL; |
| 261 | boolean allowLibs = (permissionFlag & ALLOW_LIBS) != 0; |
| 262 | boolean allowFeatures = (permissionFlag & ALLOW_FEATURES) != 0; |
| 263 | boolean allowPermissions = (permissionFlag & ALLOW_PERMISSIONS) != 0; |
| 264 | boolean allowAppConfigs = (permissionFlag & ALLOW_APP_CONFIGS) != 0; |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 265 | while (true) { |
| 266 | XmlUtils.nextElement(parser); |
| 267 | if (parser.getEventType() == XmlPullParser.END_DOCUMENT) { |
| 268 | break; |
| 269 | } |
| 270 | |
| 271 | String name = parser.getName(); |
Hung-ying Tyan | bdc9d58 | 2015-11-20 11:53:39 +0800 | [diff] [blame] | 272 | if ("group".equals(name) && allowAll) { |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 273 | String gidStr = parser.getAttributeValue(null, "gid"); |
| 274 | if (gidStr != null) { |
| 275 | int gid = android.os.Process.getGidForName(gidStr); |
| 276 | mGlobalGids = appendInt(mGlobalGids, gid); |
| 277 | } else { |
Dianne Hackborn | b3d4cb3 | 2015-01-09 09:54:06 -0800 | [diff] [blame] | 278 | Slog.w(TAG, "<group> without gid in " + permFile + " at " |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 279 | + parser.getPositionDescription()); |
| 280 | } |
| 281 | |
| 282 | XmlUtils.skipCurrentTag(parser); |
| 283 | continue; |
Hung-ying Tyan | bdc9d58 | 2015-11-20 11:53:39 +0800 | [diff] [blame] | 284 | } else if ("permission".equals(name) && allowPermissions) { |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 285 | String perm = parser.getAttributeValue(null, "name"); |
| 286 | if (perm == null) { |
Dianne Hackborn | b3d4cb3 | 2015-01-09 09:54:06 -0800 | [diff] [blame] | 287 | Slog.w(TAG, "<permission> without name in " + permFile + " at " |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 288 | + parser.getPositionDescription()); |
| 289 | XmlUtils.skipCurrentTag(parser); |
| 290 | continue; |
| 291 | } |
| 292 | perm = perm.intern(); |
| 293 | readPermission(parser, perm); |
| 294 | |
Hung-ying Tyan | bdc9d58 | 2015-11-20 11:53:39 +0800 | [diff] [blame] | 295 | } else if ("assign-permission".equals(name) && allowPermissions) { |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 296 | String perm = parser.getAttributeValue(null, "name"); |
| 297 | if (perm == null) { |
Dianne Hackborn | b3d4cb3 | 2015-01-09 09:54:06 -0800 | [diff] [blame] | 298 | Slog.w(TAG, "<assign-permission> without name in " + permFile + " at " |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 299 | + parser.getPositionDescription()); |
| 300 | XmlUtils.skipCurrentTag(parser); |
| 301 | continue; |
| 302 | } |
| 303 | String uidStr = parser.getAttributeValue(null, "uid"); |
| 304 | if (uidStr == null) { |
Dianne Hackborn | b3d4cb3 | 2015-01-09 09:54:06 -0800 | [diff] [blame] | 305 | Slog.w(TAG, "<assign-permission> without uid in " + permFile + " at " |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 306 | + parser.getPositionDescription()); |
| 307 | XmlUtils.skipCurrentTag(parser); |
| 308 | continue; |
| 309 | } |
| 310 | int uid = Process.getUidForName(uidStr); |
| 311 | if (uid < 0) { |
| 312 | Slog.w(TAG, "<assign-permission> with unknown uid \"" |
Dianne Hackborn | b3d4cb3 | 2015-01-09 09:54:06 -0800 | [diff] [blame] | 313 | + uidStr + " in " + permFile + " at " |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 314 | + parser.getPositionDescription()); |
| 315 | XmlUtils.skipCurrentTag(parser); |
| 316 | continue; |
| 317 | } |
| 318 | perm = perm.intern(); |
Jeff Sharkey | 9f837a9 | 2014-10-24 12:07:24 -0700 | [diff] [blame] | 319 | ArraySet<String> perms = mSystemPermissions.get(uid); |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 320 | if (perms == null) { |
Jeff Sharkey | 9f837a9 | 2014-10-24 12:07:24 -0700 | [diff] [blame] | 321 | perms = new ArraySet<String>(); |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 322 | mSystemPermissions.put(uid, perms); |
| 323 | } |
| 324 | perms.add(perm); |
| 325 | XmlUtils.skipCurrentTag(parser); |
| 326 | |
Hung-ying Tyan | bdc9d58 | 2015-11-20 11:53:39 +0800 | [diff] [blame] | 327 | } else if ("library".equals(name) && allowLibs) { |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 328 | String lname = parser.getAttributeValue(null, "name"); |
| 329 | String lfile = parser.getAttributeValue(null, "file"); |
| 330 | if (lname == null) { |
Dianne Hackborn | b3d4cb3 | 2015-01-09 09:54:06 -0800 | [diff] [blame] | 331 | Slog.w(TAG, "<library> without name in " + permFile + " at " |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 332 | + parser.getPositionDescription()); |
| 333 | } else if (lfile == null) { |
Dianne Hackborn | b3d4cb3 | 2015-01-09 09:54:06 -0800 | [diff] [blame] | 334 | Slog.w(TAG, "<library> without file in " + permFile + " at " |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 335 | + parser.getPositionDescription()); |
| 336 | } else { |
| 337 | //Log.i(TAG, "Got library " + lname + " in " + lfile); |
| 338 | mSharedLibraries.put(lname, lfile); |
| 339 | } |
| 340 | XmlUtils.skipCurrentTag(parser); |
| 341 | continue; |
| 342 | |
Hung-ying Tyan | bdc9d58 | 2015-11-20 11:53:39 +0800 | [diff] [blame] | 343 | } else if ("feature".equals(name) && allowFeatures) { |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 344 | String fname = parser.getAttributeValue(null, "name"); |
Arunesh Mishra | 4e0bdf3 | 2016-02-15 23:50:38 -0800 | [diff] [blame] | 345 | int fversion = XmlUtils.readIntAttribute(parser, "version", 0); |
Dianne Hackborn | c0e4aaa | 2014-11-14 10:55:50 -0800 | [diff] [blame] | 346 | boolean allowed; |
| 347 | if (!lowRam) { |
| 348 | allowed = true; |
| 349 | } else { |
| 350 | String notLowRam = parser.getAttributeValue(null, "notLowRam"); |
| 351 | allowed = !"true".equals(notLowRam); |
| 352 | } |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 353 | if (fname == null) { |
Dianne Hackborn | b3d4cb3 | 2015-01-09 09:54:06 -0800 | [diff] [blame] | 354 | Slog.w(TAG, "<feature> without name in " + permFile + " at " |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 355 | + parser.getPositionDescription()); |
Dianne Hackborn | c0e4aaa | 2014-11-14 10:55:50 -0800 | [diff] [blame] | 356 | } else if (allowed) { |
Jeff Sharkey | 115d2c1 | 2016-02-15 17:25:57 -0700 | [diff] [blame] | 357 | addFeature(fname, fversion); |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 358 | } |
| 359 | XmlUtils.skipCurrentTag(parser); |
| 360 | continue; |
| 361 | |
Hung-ying Tyan | bdc9d58 | 2015-11-20 11:53:39 +0800 | [diff] [blame] | 362 | } else if ("unavailable-feature".equals(name) && allowFeatures) { |
Jeff Sharkey | 1c4ae80 | 2014-12-19 11:08:55 -0800 | [diff] [blame] | 363 | String fname = parser.getAttributeValue(null, "name"); |
| 364 | if (fname == null) { |
Dianne Hackborn | b3d4cb3 | 2015-01-09 09:54:06 -0800 | [diff] [blame] | 365 | Slog.w(TAG, "<unavailable-feature> without name in " + permFile + " at " |
Jeff Sharkey | 1c4ae80 | 2014-12-19 11:08:55 -0800 | [diff] [blame] | 366 | + parser.getPositionDescription()); |
| 367 | } else { |
| 368 | mUnavailableFeatures.add(fname); |
| 369 | } |
| 370 | XmlUtils.skipCurrentTag(parser); |
| 371 | continue; |
| 372 | |
Hung-ying Tyan | bdc9d58 | 2015-11-20 11:53:39 +0800 | [diff] [blame] | 373 | } else if ("allow-in-power-save-except-idle".equals(name) && allowAll) { |
Dianne Hackborn | 4a503b1 | 2015-08-06 22:19:06 -0700 | [diff] [blame] | 374 | String pkgname = parser.getAttributeValue(null, "package"); |
| 375 | if (pkgname == null) { |
| 376 | Slog.w(TAG, "<allow-in-power-save-except-idle> without package in " |
| 377 | + permFile + " at " + parser.getPositionDescription()); |
| 378 | } else { |
| 379 | mAllowInPowerSaveExceptIdle.add(pkgname); |
| 380 | } |
| 381 | XmlUtils.skipCurrentTag(parser); |
| 382 | continue; |
| 383 | |
Hung-ying Tyan | bdc9d58 | 2015-11-20 11:53:39 +0800 | [diff] [blame] | 384 | } else if ("allow-in-power-save".equals(name) && allowAll) { |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 385 | String pkgname = parser.getAttributeValue(null, "package"); |
| 386 | if (pkgname == null) { |
Dianne Hackborn | b3d4cb3 | 2015-01-09 09:54:06 -0800 | [diff] [blame] | 387 | Slog.w(TAG, "<allow-in-power-save> without package in " + permFile + " at " |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 388 | + parser.getPositionDescription()); |
| 389 | } else { |
| 390 | mAllowInPowerSave.add(pkgname); |
| 391 | } |
| 392 | XmlUtils.skipCurrentTag(parser); |
| 393 | continue; |
| 394 | |
Hung-ying Tyan | bdc9d58 | 2015-11-20 11:53:39 +0800 | [diff] [blame] | 395 | } else if ("fixed-ime-app".equals(name) && allowAll) { |
Dianne Hackborn | bb8aa5a | 2014-09-17 13:20:38 -0700 | [diff] [blame] | 396 | String pkgname = parser.getAttributeValue(null, "package"); |
| 397 | if (pkgname == null) { |
Dianne Hackborn | b3d4cb3 | 2015-01-09 09:54:06 -0800 | [diff] [blame] | 398 | Slog.w(TAG, "<fixed-ime-app> without package in " + permFile + " at " |
Dianne Hackborn | bb8aa5a | 2014-09-17 13:20:38 -0700 | [diff] [blame] | 399 | + parser.getPositionDescription()); |
| 400 | } else { |
| 401 | mFixedImeApps.add(pkgname); |
| 402 | } |
| 403 | XmlUtils.skipCurrentTag(parser); |
| 404 | continue; |
| 405 | |
Hung-ying Tyan | bdc9d58 | 2015-11-20 11:53:39 +0800 | [diff] [blame] | 406 | } else if ("app-link".equals(name) && allowAppConfigs) { |
Christopher Tate | 01e1864 | 2015-07-07 18:10:38 -0700 | [diff] [blame] | 407 | String pkgname = parser.getAttributeValue(null, "package"); |
| 408 | if (pkgname == null) { |
| 409 | Slog.w(TAG, "<app-link> without package in " + permFile + " at " |
| 410 | + parser.getPositionDescription()); |
| 411 | } else { |
| 412 | mLinkedApps.add(pkgname); |
| 413 | } |
| 414 | XmlUtils.skipCurrentTag(parser); |
Hung-ying Tyan | bdc9d58 | 2015-11-20 11:53:39 +0800 | [diff] [blame] | 415 | } else if ("system-user-whitelisted-app".equals(name) && allowAppConfigs) { |
Fyodor Kupolov | 7db5af1 | 2015-07-31 16:50:27 -0700 | [diff] [blame] | 416 | String pkgname = parser.getAttributeValue(null, "package"); |
| 417 | if (pkgname == null) { |
| 418 | Slog.w(TAG, "<system-user-whitelisted-app> without package in " + permFile |
| 419 | + " at " + parser.getPositionDescription()); |
| 420 | } else { |
| 421 | mSystemUserWhitelistedApps.add(pkgname); |
| 422 | } |
| 423 | XmlUtils.skipCurrentTag(parser); |
Hung-ying Tyan | bdc9d58 | 2015-11-20 11:53:39 +0800 | [diff] [blame] | 424 | } else if ("system-user-blacklisted-app".equals(name) && allowAppConfigs) { |
Fyodor Kupolov | 7db5af1 | 2015-07-31 16:50:27 -0700 | [diff] [blame] | 425 | String pkgname = parser.getAttributeValue(null, "package"); |
| 426 | if (pkgname == null) { |
| 427 | Slog.w(TAG, "<system-user-blacklisted-app without package in " + permFile |
| 428 | + " at " + parser.getPositionDescription()); |
| 429 | } else { |
| 430 | mSystemUserBlacklistedApps.add(pkgname); |
| 431 | } |
| 432 | XmlUtils.skipCurrentTag(parser); |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 433 | } else { |
| 434 | XmlUtils.skipCurrentTag(parser); |
| 435 | continue; |
| 436 | } |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 437 | } |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 438 | } catch (XmlPullParserException e) { |
Jeff Sharkey | 1c4ae80 | 2014-12-19 11:08:55 -0800 | [diff] [blame] | 439 | Slog.w(TAG, "Got exception parsing permissions.", e); |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 440 | } catch (IOException e) { |
Jeff Sharkey | 1c4ae80 | 2014-12-19 11:08:55 -0800 | [diff] [blame] | 441 | Slog.w(TAG, "Got exception parsing permissions.", e); |
| 442 | } finally { |
| 443 | IoUtils.closeQuietly(permReader); |
| 444 | } |
| 445 | |
Jeff Sharkey | b92b05b | 2016-01-28 09:50:00 -0700 | [diff] [blame] | 446 | // Some devices can be field-converted to FBE, so offer to splice in |
| 447 | // those features if not already defined by the static config |
| 448 | if (StorageManager.isNativeFileBasedEncryptionEnabled()) { |
Jeff Sharkey | 115d2c1 | 2016-02-15 17:25:57 -0700 | [diff] [blame] | 449 | addFeature(PackageManager.FEATURE_FILE_BASED_ENCRYPTION, 0); |
| 450 | addFeature(PackageManager.FEATURE_SECURELY_REMOVES_USERS, 0); |
Jeff Sharkey | b92b05b | 2016-01-28 09:50:00 -0700 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | for (String featureName : mUnavailableFeatures) { |
| 454 | removeFeature(featureName); |
| 455 | } |
| 456 | } |
| 457 | |
Jeff Sharkey | 115d2c1 | 2016-02-15 17:25:57 -0700 | [diff] [blame] | 458 | private void addFeature(String name, int version) { |
| 459 | FeatureInfo fi = mAvailableFeatures.get(name); |
| 460 | if (fi == null) { |
| 461 | fi = new FeatureInfo(); |
| 462 | fi.name = name; |
| 463 | fi.version = version; |
| 464 | mAvailableFeatures.put(name, fi); |
| 465 | } else { |
| 466 | fi.version = Math.max(fi.version, version); |
Jeff Sharkey | b92b05b | 2016-01-28 09:50:00 -0700 | [diff] [blame] | 467 | } |
| 468 | } |
| 469 | |
Jeff Sharkey | 115d2c1 | 2016-02-15 17:25:57 -0700 | [diff] [blame] | 470 | private void removeFeature(String name) { |
| 471 | if (mAvailableFeatures.remove(name) != null) { |
| 472 | Slog.d(TAG, "Removed unavailable feature " + name); |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 473 | } |
| 474 | } |
| 475 | |
| 476 | void readPermission(XmlPullParser parser, String name) |
| 477 | throws IOException, XmlPullParserException { |
Jeff Sharkey | 00f3904 | 2015-03-23 16:51:22 -0700 | [diff] [blame] | 478 | if (mPermissions.containsKey(name)) { |
| 479 | throw new IllegalStateException("Duplicate permission definition for " + name); |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 480 | } |
Jeff Sharkey | 00f3904 | 2015-03-23 16:51:22 -0700 | [diff] [blame] | 481 | |
| 482 | final boolean perUser = XmlUtils.readBooleanAttribute(parser, "perUser", false); |
| 483 | final PermissionEntry perm = new PermissionEntry(name, perUser); |
| 484 | mPermissions.put(name, perm); |
| 485 | |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 486 | int outerDepth = parser.getDepth(); |
| 487 | int type; |
| 488 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 489 | && (type != XmlPullParser.END_TAG |
| 490 | || parser.getDepth() > outerDepth)) { |
| 491 | if (type == XmlPullParser.END_TAG |
| 492 | || type == XmlPullParser.TEXT) { |
| 493 | continue; |
| 494 | } |
| 495 | |
| 496 | String tagName = parser.getName(); |
| 497 | if ("group".equals(tagName)) { |
| 498 | String gidStr = parser.getAttributeValue(null, "gid"); |
| 499 | if (gidStr != null) { |
| 500 | int gid = Process.getGidForName(gidStr); |
| 501 | perm.gids = appendInt(perm.gids, gid); |
| 502 | } else { |
| 503 | Slog.w(TAG, "<group> without gid at " |
| 504 | + parser.getPositionDescription()); |
| 505 | } |
| 506 | } |
| 507 | XmlUtils.skipCurrentTag(parser); |
| 508 | } |
| 509 | } |
| 510 | } |