blob: 4dc46ac6364313c621ae1d99c4eebd00dc4f501b [file] [log] [blame]
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -07001/*
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
17package com.android.server;
18
Dianne Hackbornc0e4aaa2014-11-14 10:55:50 -080019import android.app.ActivityManager;
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -070020import android.content.pm.FeatureInfo;
21import android.os.*;
22import android.os.Process;
23import android.util.ArrayMap;
24import android.util.ArraySet;
25import android.util.Slog;
26import android.util.SparseArray;
27import android.util.Xml;
Jeff Sharkey1c4ae802014-12-19 11:08:55 -080028
29import libcore.io.IoUtils;
30
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -070031import com.android.internal.util.XmlUtils;
Jeff Sharkey1c4ae802014-12-19 11:08:55 -080032
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -070033import org.xmlpull.v1.XmlPullParser;
34import org.xmlpull.v1.XmlPullParserException;
35
36import java.io.File;
37import java.io.FileNotFoundException;
38import java.io.FileReader;
39import java.io.IOException;
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -070040
41import static com.android.internal.util.ArrayUtils.appendInt;
42
43/**
44 * Loads global system configuration info.
45 */
46public class SystemConfig {
47 static final String TAG = "SystemConfig";
48
49 static SystemConfig sInstance;
50
Hung-ying Tyanbdc9d582015-11-20 11:53:39 +080051 // permission flag, determines which types of configuration are allowed to be read
52 private static final int ALLOW_FEATURES = 0x01;
53 private static final int ALLOW_LIBS = 0x02;
54 private static final int ALLOW_PERMISSIONS = 0x04;
55 private static final int ALLOW_APP_CONFIGS = 0x08;
56 private static final int ALLOW_ALL = ~0;
57
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -070058 // Group-ids that are given to all packages as read from etc/permissions/*.xml.
59 int[] mGlobalGids;
60
61 // These are the built-in uid -> permission mappings that were read from the
62 // system configuration files.
Jeff Sharkey9f837a92014-10-24 12:07:24 -070063 final SparseArray<ArraySet<String>> mSystemPermissions = new SparseArray<>();
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -070064
65 // These are the built-in shared libraries that were read from the
66 // system configuration files. Keys are the library names; strings are the
67 // paths to the libraries.
Dianne Hackbornbb8aa5a2014-09-17 13:20:38 -070068 final ArrayMap<String, String> mSharedLibraries = new ArrayMap<>();
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -070069
70 // These are the features this devices supports that were read from the
71 // system configuration files.
Jeff Sharkey9f837a92014-10-24 12:07:24 -070072 final ArrayMap<String, FeatureInfo> mAvailableFeatures = new ArrayMap<>();
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -070073
Jeff Sharkey1c4ae802014-12-19 11:08:55 -080074 // These are the features which this device doesn't support; the OEM
75 // partition uses these to opt-out of features from the system image.
76 final ArraySet<String> mUnavailableFeatures = new ArraySet<>();
77
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -070078 public static final class PermissionEntry {
79 public final String name;
80 public int[] gids;
Jeff Sharkey00f39042015-03-23 16:51:22 -070081 public boolean perUser;
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -070082
Jeff Sharkey00f39042015-03-23 16:51:22 -070083 PermissionEntry(String name, boolean perUser) {
84 this.name = name;
85 this.perUser = perUser;
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -070086 }
87 }
88
89 // These are the permission -> gid mappings that were read from the
90 // system configuration files.
Dianne Hackbornbb8aa5a2014-09-17 13:20:38 -070091 final ArrayMap<String, PermissionEntry> mPermissions = new ArrayMap<>();
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -070092
93 // These are the packages that are white-listed to be able to run in the
Dianne Hackborn4a503b12015-08-06 22:19:06 -070094 // background while in power save mode (but not whitelisted from device idle modes),
95 // as read from the configuration files.
96 final ArraySet<String> mAllowInPowerSaveExceptIdle = new ArraySet<>();
97
98 // These are the packages that are white-listed to be able to run in the
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -070099 // background while in power save mode, as read from the configuration files.
Dianne Hackbornbb8aa5a2014-09-17 13:20:38 -0700100 final ArraySet<String> mAllowInPowerSave = new ArraySet<>();
101
102 // These are the app package names that should not allow IME switching.
103 final ArraySet<String> mFixedImeApps = new ArraySet<>();
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -0700104
Christopher Tate01e18642015-07-07 18:10:38 -0700105 // These are the package names of apps which should be in the 'always'
106 // URL-handling state upon factory reset.
107 final ArraySet<String> mLinkedApps = new ArraySet<>();
108
Fyodor Kupolov7db5af12015-07-31 16:50:27 -0700109 // These are the packages that are whitelisted to be able to run as system user
110 final ArraySet<String> mSystemUserWhitelistedApps = new ArraySet<>();
111
112 // These are the packages that should not run under system user
113 final ArraySet<String> mSystemUserBlacklistedApps = new ArraySet<>();
114
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -0700115 public static SystemConfig getInstance() {
116 synchronized (SystemConfig.class) {
117 if (sInstance == null) {
118 sInstance = new SystemConfig();
119 }
120 return sInstance;
121 }
122 }
123
124 public int[] getGlobalGids() {
125 return mGlobalGids;
126 }
127
Jeff Sharkey9f837a92014-10-24 12:07:24 -0700128 public SparseArray<ArraySet<String>> getSystemPermissions() {
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -0700129 return mSystemPermissions;
130 }
131
132 public ArrayMap<String, String> getSharedLibraries() {
133 return mSharedLibraries;
134 }
135
Jeff Sharkey9f837a92014-10-24 12:07:24 -0700136 public ArrayMap<String, FeatureInfo> getAvailableFeatures() {
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -0700137 return mAvailableFeatures;
138 }
139
140 public ArrayMap<String, PermissionEntry> getPermissions() {
141 return mPermissions;
142 }
143
Dianne Hackborn4a503b12015-08-06 22:19:06 -0700144 public ArraySet<String> getAllowInPowerSaveExceptIdle() {
145 return mAllowInPowerSaveExceptIdle;
146 }
147
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -0700148 public ArraySet<String> getAllowInPowerSave() {
149 return mAllowInPowerSave;
150 }
151
Dianne Hackbornbb8aa5a2014-09-17 13:20:38 -0700152 public ArraySet<String> getFixedImeApps() {
153 return mFixedImeApps;
154 }
155
Christopher Tate01e18642015-07-07 18:10:38 -0700156 public ArraySet<String> getLinkedApps() {
157 return mLinkedApps;
158 }
159
Fyodor Kupolov7db5af12015-07-31 16:50:27 -0700160 public ArraySet<String> getSystemUserWhitelistedApps() {
161 return mSystemUserWhitelistedApps;
162 }
163
164 public ArraySet<String> getSystemUserBlacklistedApps() {
165 return mSystemUserBlacklistedApps;
166 }
167
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -0700168 SystemConfig() {
169 // Read configuration from system
170 readPermissions(Environment.buildPath(
Hung-ying Tyanbdc9d582015-11-20 11:53:39 +0800171 Environment.getRootDirectory(), "etc", "sysconfig"), ALLOW_ALL);
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -0700172 // Read configuration from the old permissions dir
173 readPermissions(Environment.buildPath(
Hung-ying Tyanbdc9d582015-11-20 11:53:39 +0800174 Environment.getRootDirectory(), "etc", "permissions"), ALLOW_ALL);
175 // Allow ODM to customize system configs around libs, features and apps
176 int odmPermissionFlag = ALLOW_LIBS | ALLOW_FEATURES | ALLOW_APP_CONFIGS;
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -0700177 readPermissions(Environment.buildPath(
Hung-ying Tyanbdc9d582015-11-20 11:53:39 +0800178 Environment.getOdmDirectory(), "etc", "sysconfig"), odmPermissionFlag);
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -0700179 readPermissions(Environment.buildPath(
Hung-ying Tyanbdc9d582015-11-20 11:53:39 +0800180 Environment.getOdmDirectory(), "etc", "permissions"), odmPermissionFlag);
181 // Only allow OEM to customize features
182 readPermissions(Environment.buildPath(
183 Environment.getOemDirectory(), "etc", "sysconfig"), ALLOW_FEATURES);
184 readPermissions(Environment.buildPath(
185 Environment.getOemDirectory(), "etc", "permissions"), ALLOW_FEATURES);
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -0700186 }
187
Hung-ying Tyanbdc9d582015-11-20 11:53:39 +0800188 void readPermissions(File libraryDir, int permissionFlag) {
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -0700189 // Read permissions from given directory.
190 if (!libraryDir.exists() || !libraryDir.isDirectory()) {
Hung-ying Tyanbdc9d582015-11-20 11:53:39 +0800191 if (permissionFlag == ALLOW_ALL) {
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -0700192 Slog.w(TAG, "No directory " + libraryDir + ", skipping");
193 }
194 return;
195 }
196 if (!libraryDir.canRead()) {
197 Slog.w(TAG, "Directory " + libraryDir + " cannot be read");
198 return;
199 }
200
201 // Iterate over the files in the directory and scan .xml files
Jeff Sharkey1c4ae802014-12-19 11:08:55 -0800202 File platformFile = null;
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -0700203 for (File f : libraryDir.listFiles()) {
204 // We'll read platform.xml last
205 if (f.getPath().endsWith("etc/permissions/platform.xml")) {
Jeff Sharkey1c4ae802014-12-19 11:08:55 -0800206 platformFile = f;
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -0700207 continue;
208 }
209
210 if (!f.getPath().endsWith(".xml")) {
211 Slog.i(TAG, "Non-xml file " + f + " in " + libraryDir + " directory, ignoring");
212 continue;
213 }
214 if (!f.canRead()) {
215 Slog.w(TAG, "Permissions library file " + f + " cannot be read");
216 continue;
217 }
218
Hung-ying Tyanbdc9d582015-11-20 11:53:39 +0800219 readPermissionsFromXml(f, permissionFlag);
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -0700220 }
221
Jeff Sharkey1c4ae802014-12-19 11:08:55 -0800222 // Read platform permissions last so it will take precedence
223 if (platformFile != null) {
Hung-ying Tyanbdc9d582015-11-20 11:53:39 +0800224 readPermissionsFromXml(platformFile, permissionFlag);
Jeff Sharkey1c4ae802014-12-19 11:08:55 -0800225 }
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -0700226 }
227
Hung-ying Tyanbdc9d582015-11-20 11:53:39 +0800228 private void readPermissionsFromXml(File permFile, int permissionFlag) {
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -0700229 FileReader permReader = null;
230 try {
231 permReader = new FileReader(permFile);
232 } catch (FileNotFoundException e) {
233 Slog.w(TAG, "Couldn't find or open permissions file " + permFile);
234 return;
235 }
236
Dianne Hackbornc0e4aaa2014-11-14 10:55:50 -0800237 final boolean lowRam = ActivityManager.isLowRamDeviceStatic();
238
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -0700239 try {
240 XmlPullParser parser = Xml.newPullParser();
241 parser.setInput(permReader);
242
243 int type;
244 while ((type=parser.next()) != parser.START_TAG
245 && type != parser.END_DOCUMENT) {
246 ;
247 }
248
249 if (type != parser.START_TAG) {
250 throw new XmlPullParserException("No start tag found");
251 }
252
253 if (!parser.getName().equals("permissions") && !parser.getName().equals("config")) {
Dianne Hackbornb3d4cb32015-01-09 09:54:06 -0800254 throw new XmlPullParserException("Unexpected start tag in " + permFile
255 + ": found " + parser.getName() + ", expected 'permissions' or 'config'");
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -0700256 }
257
Hung-ying Tyanbdc9d582015-11-20 11:53:39 +0800258 boolean allowAll = permissionFlag == ALLOW_ALL;
259 boolean allowLibs = (permissionFlag & ALLOW_LIBS) != 0;
260 boolean allowFeatures = (permissionFlag & ALLOW_FEATURES) != 0;
261 boolean allowPermissions = (permissionFlag & ALLOW_PERMISSIONS) != 0;
262 boolean allowAppConfigs = (permissionFlag & ALLOW_APP_CONFIGS) != 0;
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -0700263 while (true) {
264 XmlUtils.nextElement(parser);
265 if (parser.getEventType() == XmlPullParser.END_DOCUMENT) {
266 break;
267 }
268
269 String name = parser.getName();
Hung-ying Tyanbdc9d582015-11-20 11:53:39 +0800270 if ("group".equals(name) && allowAll) {
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -0700271 String gidStr = parser.getAttributeValue(null, "gid");
272 if (gidStr != null) {
273 int gid = android.os.Process.getGidForName(gidStr);
274 mGlobalGids = appendInt(mGlobalGids, gid);
275 } else {
Dianne Hackbornb3d4cb32015-01-09 09:54:06 -0800276 Slog.w(TAG, "<group> without gid in " + permFile + " at "
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -0700277 + parser.getPositionDescription());
278 }
279
280 XmlUtils.skipCurrentTag(parser);
281 continue;
Hung-ying Tyanbdc9d582015-11-20 11:53:39 +0800282 } else if ("permission".equals(name) && allowPermissions) {
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -0700283 String perm = parser.getAttributeValue(null, "name");
284 if (perm == null) {
Dianne Hackbornb3d4cb32015-01-09 09:54:06 -0800285 Slog.w(TAG, "<permission> without name in " + permFile + " at "
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -0700286 + parser.getPositionDescription());
287 XmlUtils.skipCurrentTag(parser);
288 continue;
289 }
290 perm = perm.intern();
291 readPermission(parser, perm);
292
Hung-ying Tyanbdc9d582015-11-20 11:53:39 +0800293 } else if ("assign-permission".equals(name) && allowPermissions) {
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -0700294 String perm = parser.getAttributeValue(null, "name");
295 if (perm == null) {
Dianne Hackbornb3d4cb32015-01-09 09:54:06 -0800296 Slog.w(TAG, "<assign-permission> without name in " + permFile + " at "
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -0700297 + parser.getPositionDescription());
298 XmlUtils.skipCurrentTag(parser);
299 continue;
300 }
301 String uidStr = parser.getAttributeValue(null, "uid");
302 if (uidStr == null) {
Dianne Hackbornb3d4cb32015-01-09 09:54:06 -0800303 Slog.w(TAG, "<assign-permission> without uid in " + permFile + " at "
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -0700304 + parser.getPositionDescription());
305 XmlUtils.skipCurrentTag(parser);
306 continue;
307 }
308 int uid = Process.getUidForName(uidStr);
309 if (uid < 0) {
310 Slog.w(TAG, "<assign-permission> with unknown uid \""
Dianne Hackbornb3d4cb32015-01-09 09:54:06 -0800311 + uidStr + " in " + permFile + " at "
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -0700312 + parser.getPositionDescription());
313 XmlUtils.skipCurrentTag(parser);
314 continue;
315 }
316 perm = perm.intern();
Jeff Sharkey9f837a92014-10-24 12:07:24 -0700317 ArraySet<String> perms = mSystemPermissions.get(uid);
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -0700318 if (perms == null) {
Jeff Sharkey9f837a92014-10-24 12:07:24 -0700319 perms = new ArraySet<String>();
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -0700320 mSystemPermissions.put(uid, perms);
321 }
322 perms.add(perm);
323 XmlUtils.skipCurrentTag(parser);
324
Hung-ying Tyanbdc9d582015-11-20 11:53:39 +0800325 } else if ("library".equals(name) && allowLibs) {
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -0700326 String lname = parser.getAttributeValue(null, "name");
327 String lfile = parser.getAttributeValue(null, "file");
328 if (lname == null) {
Dianne Hackbornb3d4cb32015-01-09 09:54:06 -0800329 Slog.w(TAG, "<library> without name in " + permFile + " at "
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -0700330 + parser.getPositionDescription());
331 } else if (lfile == null) {
Dianne Hackbornb3d4cb32015-01-09 09:54:06 -0800332 Slog.w(TAG, "<library> without file in " + permFile + " at "
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -0700333 + parser.getPositionDescription());
334 } else {
335 //Log.i(TAG, "Got library " + lname + " in " + lfile);
336 mSharedLibraries.put(lname, lfile);
337 }
338 XmlUtils.skipCurrentTag(parser);
339 continue;
340
Hung-ying Tyanbdc9d582015-11-20 11:53:39 +0800341 } else if ("feature".equals(name) && allowFeatures) {
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -0700342 String fname = parser.getAttributeValue(null, "name");
Dianne Hackbornc0e4aaa2014-11-14 10:55:50 -0800343 boolean allowed;
344 if (!lowRam) {
345 allowed = true;
346 } else {
347 String notLowRam = parser.getAttributeValue(null, "notLowRam");
348 allowed = !"true".equals(notLowRam);
349 }
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -0700350 if (fname == null) {
Dianne Hackbornb3d4cb32015-01-09 09:54:06 -0800351 Slog.w(TAG, "<feature> without name in " + permFile + " at "
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -0700352 + parser.getPositionDescription());
Dianne Hackbornc0e4aaa2014-11-14 10:55:50 -0800353 } else if (allowed) {
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -0700354 //Log.i(TAG, "Got feature " + fname);
355 FeatureInfo fi = new FeatureInfo();
356 fi.name = fname;
357 mAvailableFeatures.put(fname, fi);
358 }
359 XmlUtils.skipCurrentTag(parser);
360 continue;
361
Hung-ying Tyanbdc9d582015-11-20 11:53:39 +0800362 } else if ("unavailable-feature".equals(name) && allowFeatures) {
Jeff Sharkey1c4ae802014-12-19 11:08:55 -0800363 String fname = parser.getAttributeValue(null, "name");
364 if (fname == null) {
Dianne Hackbornb3d4cb32015-01-09 09:54:06 -0800365 Slog.w(TAG, "<unavailable-feature> without name in " + permFile + " at "
Jeff Sharkey1c4ae802014-12-19 11:08:55 -0800366 + parser.getPositionDescription());
367 } else {
368 mUnavailableFeatures.add(fname);
369 }
370 XmlUtils.skipCurrentTag(parser);
371 continue;
372
Hung-ying Tyanbdc9d582015-11-20 11:53:39 +0800373 } else if ("allow-in-power-save-except-idle".equals(name) && allowAll) {
Dianne Hackborn4a503b12015-08-06 22:19:06 -0700374 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 Tyanbdc9d582015-11-20 11:53:39 +0800384 } else if ("allow-in-power-save".equals(name) && allowAll) {
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -0700385 String pkgname = parser.getAttributeValue(null, "package");
386 if (pkgname == null) {
Dianne Hackbornb3d4cb32015-01-09 09:54:06 -0800387 Slog.w(TAG, "<allow-in-power-save> without package in " + permFile + " at "
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -0700388 + parser.getPositionDescription());
389 } else {
390 mAllowInPowerSave.add(pkgname);
391 }
392 XmlUtils.skipCurrentTag(parser);
393 continue;
394
Hung-ying Tyanbdc9d582015-11-20 11:53:39 +0800395 } else if ("fixed-ime-app".equals(name) && allowAll) {
Dianne Hackbornbb8aa5a2014-09-17 13:20:38 -0700396 String pkgname = parser.getAttributeValue(null, "package");
397 if (pkgname == null) {
Dianne Hackbornb3d4cb32015-01-09 09:54:06 -0800398 Slog.w(TAG, "<fixed-ime-app> without package in " + permFile + " at "
Dianne Hackbornbb8aa5a2014-09-17 13:20:38 -0700399 + parser.getPositionDescription());
400 } else {
401 mFixedImeApps.add(pkgname);
402 }
403 XmlUtils.skipCurrentTag(parser);
404 continue;
405
Hung-ying Tyanbdc9d582015-11-20 11:53:39 +0800406 } else if ("app-link".equals(name) && allowAppConfigs) {
Christopher Tate01e18642015-07-07 18:10:38 -0700407 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 Tyanbdc9d582015-11-20 11:53:39 +0800415 } else if ("system-user-whitelisted-app".equals(name) && allowAppConfigs) {
Fyodor Kupolov7db5af12015-07-31 16:50:27 -0700416 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 Tyanbdc9d582015-11-20 11:53:39 +0800424 } else if ("system-user-blacklisted-app".equals(name) && allowAppConfigs) {
Fyodor Kupolov7db5af12015-07-31 16:50:27 -0700425 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 Hackbornbe7c50e2014-06-30 14:43:28 -0700433 } else {
434 XmlUtils.skipCurrentTag(parser);
435 continue;
436 }
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -0700437 }
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -0700438 } catch (XmlPullParserException e) {
Jeff Sharkey1c4ae802014-12-19 11:08:55 -0800439 Slog.w(TAG, "Got exception parsing permissions.", e);
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -0700440 } catch (IOException e) {
Jeff Sharkey1c4ae802014-12-19 11:08:55 -0800441 Slog.w(TAG, "Got exception parsing permissions.", e);
442 } finally {
443 IoUtils.closeQuietly(permReader);
444 }
445
446 for (String fname : mUnavailableFeatures) {
447 if (mAvailableFeatures.remove(fname) != null) {
448 Slog.d(TAG, "Removed unavailable feature " + fname);
449 }
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -0700450 }
451 }
452
453 void readPermission(XmlPullParser parser, String name)
454 throws IOException, XmlPullParserException {
Jeff Sharkey00f39042015-03-23 16:51:22 -0700455 if (mPermissions.containsKey(name)) {
456 throw new IllegalStateException("Duplicate permission definition for " + name);
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -0700457 }
Jeff Sharkey00f39042015-03-23 16:51:22 -0700458
459 final boolean perUser = XmlUtils.readBooleanAttribute(parser, "perUser", false);
460 final PermissionEntry perm = new PermissionEntry(name, perUser);
461 mPermissions.put(name, perm);
462
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -0700463 int outerDepth = parser.getDepth();
464 int type;
465 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
466 && (type != XmlPullParser.END_TAG
467 || parser.getDepth() > outerDepth)) {
468 if (type == XmlPullParser.END_TAG
469 || type == XmlPullParser.TEXT) {
470 continue;
471 }
472
473 String tagName = parser.getName();
474 if ("group".equals(tagName)) {
475 String gidStr = parser.getAttributeValue(null, "gid");
476 if (gidStr != null) {
477 int gid = Process.getGidForName(gidStr);
478 perm.gids = appendInt(perm.gids, gid);
479 } else {
480 Slog.w(TAG, "<group> without gid at "
481 + parser.getPositionDescription());
482 }
483 }
484 XmlUtils.skipCurrentTag(parser);
485 }
486 }
487}