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; |
Ruben Brunk | 98576cf | 2016-03-07 18:54:28 -0800 | [diff] [blame] | 22 | import android.content.ComponentName; |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 23 | import android.content.pm.FeatureInfo; |
Jeff Sharkey | b92b05b | 2016-01-28 09:50:00 -0700 | [diff] [blame] | 24 | import android.content.pm.PackageManager; |
Jiyong Park | fad9944 | 2018-03-12 10:39:07 +0900 | [diff] [blame] | 25 | import android.os.Build; |
Jeff Sharkey | b92b05b | 2016-01-28 09:50:00 -0700 | [diff] [blame] | 26 | import android.os.Environment; |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 27 | import android.os.Process; |
Jeff Sharkey | b92b05b | 2016-01-28 09:50:00 -0700 | [diff] [blame] | 28 | import android.os.storage.StorageManager; |
Fyodor Kupolov | 964d2eb | 2016-11-09 14:32:27 -0800 | [diff] [blame] | 29 | import android.text.TextUtils; |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 30 | import android.util.ArrayMap; |
| 31 | import android.util.ArraySet; |
| 32 | import android.util.Slog; |
| 33 | import android.util.SparseArray; |
| 34 | import android.util.Xml; |
Jeff Sharkey | 1c4ae80 | 2014-12-19 11:08:55 -0800 | [diff] [blame] | 35 | |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 36 | import com.android.internal.util.XmlUtils; |
Jeff Sharkey | 1c4ae80 | 2014-12-19 11:08:55 -0800 | [diff] [blame] | 37 | |
Jeff Sharkey | b92b05b | 2016-01-28 09:50:00 -0700 | [diff] [blame] | 38 | import libcore.io.IoUtils; |
| 39 | |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 40 | import org.xmlpull.v1.XmlPullParser; |
| 41 | import org.xmlpull.v1.XmlPullParserException; |
| 42 | |
| 43 | import java.io.File; |
| 44 | import java.io.FileNotFoundException; |
| 45 | import java.io.FileReader; |
| 46 | import java.io.IOException; |
Jeff Davidson | 24b9d96 | 2016-07-21 12:35:10 -0700 | [diff] [blame] | 47 | import java.util.ArrayList; |
Svet Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 48 | import java.util.Collections; |
Jeff Davidson | 24b9d96 | 2016-07-21 12:35:10 -0700 | [diff] [blame] | 49 | import java.util.List; |
Svet Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 50 | import java.util.Map; |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 51 | |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 52 | /** |
| 53 | * Loads global system configuration info. |
| 54 | */ |
| 55 | public class SystemConfig { |
| 56 | static final String TAG = "SystemConfig"; |
| 57 | |
| 58 | static SystemConfig sInstance; |
| 59 | |
Hung-ying Tyan | bdc9d58 | 2015-11-20 11:53:39 +0800 | [diff] [blame] | 60 | // permission flag, determines which types of configuration are allowed to be read |
| 61 | private static final int ALLOW_FEATURES = 0x01; |
| 62 | private static final int ALLOW_LIBS = 0x02; |
| 63 | private static final int ALLOW_PERMISSIONS = 0x04; |
| 64 | private static final int ALLOW_APP_CONFIGS = 0x08; |
Jaekyun Seok | e3b6bf1 | 2017-02-16 13:48:30 +0900 | [diff] [blame] | 65 | private static final int ALLOW_PRIVAPP_PERMISSIONS = 0x10; |
Svet Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 66 | private static final int ALLOW_OEM_PERMISSIONS = 0x20; |
Mathew Inwood | 4693a75 | 2018-02-20 16:04:25 +0000 | [diff] [blame] | 67 | private static final int ALLOW_HIDDENAPI_WHITELISTING = 0x40; |
Hung-ying Tyan | bdc9d58 | 2015-11-20 11:53:39 +0800 | [diff] [blame] | 68 | private static final int ALLOW_ALL = ~0; |
| 69 | |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 70 | // Group-ids that are given to all packages as read from etc/permissions/*.xml. |
| 71 | int[] mGlobalGids; |
| 72 | |
| 73 | // These are the built-in uid -> permission mappings that were read from the |
| 74 | // system configuration files. |
Jeff Sharkey | 9f837a9 | 2014-10-24 12:07:24 -0700 | [diff] [blame] | 75 | final SparseArray<ArraySet<String>> mSystemPermissions = new SparseArray<>(); |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 76 | |
| 77 | // These are the built-in shared libraries that were read from the |
| 78 | // system configuration files. Keys are the library names; strings are the |
| 79 | // paths to the libraries. |
Dianne Hackborn | bb8aa5a | 2014-09-17 13:20:38 -0700 | [diff] [blame] | 80 | final ArrayMap<String, String> mSharedLibraries = new ArrayMap<>(); |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 81 | |
| 82 | // These are the features this devices supports that were read from the |
| 83 | // system configuration files. |
Jeff Sharkey | 9f837a9 | 2014-10-24 12:07:24 -0700 | [diff] [blame] | 84 | final ArrayMap<String, FeatureInfo> mAvailableFeatures = new ArrayMap<>(); |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 85 | |
Jeff Sharkey | 1c4ae80 | 2014-12-19 11:08:55 -0800 | [diff] [blame] | 86 | // These are the features which this device doesn't support; the OEM |
| 87 | // partition uses these to opt-out of features from the system image. |
| 88 | final ArraySet<String> mUnavailableFeatures = new ArraySet<>(); |
| 89 | |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 90 | public static final class PermissionEntry { |
| 91 | public final String name; |
| 92 | public int[] gids; |
Jeff Sharkey | 00f3904 | 2015-03-23 16:51:22 -0700 | [diff] [blame] | 93 | public boolean perUser; |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 94 | |
Jeff Sharkey | 00f3904 | 2015-03-23 16:51:22 -0700 | [diff] [blame] | 95 | PermissionEntry(String name, boolean perUser) { |
| 96 | this.name = name; |
| 97 | this.perUser = perUser; |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 98 | } |
| 99 | } |
| 100 | |
| 101 | // These are the permission -> gid mappings that were read from the |
| 102 | // system configuration files. |
Dianne Hackborn | bb8aa5a | 2014-09-17 13:20:38 -0700 | [diff] [blame] | 103 | final ArrayMap<String, PermissionEntry> mPermissions = new ArrayMap<>(); |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 104 | |
| 105 | // 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] | 106 | // background while in power save mode (but not whitelisted from device idle modes), |
| 107 | // as read from the configuration files. |
| 108 | final ArraySet<String> mAllowInPowerSaveExceptIdle = new ArraySet<>(); |
| 109 | |
| 110 | // 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] | 111 | // background while in power save mode, as read from the configuration files. |
Dianne Hackborn | bb8aa5a | 2014-09-17 13:20:38 -0700 | [diff] [blame] | 112 | final ArraySet<String> mAllowInPowerSave = new ArraySet<>(); |
| 113 | |
Felipe Leme | a9505cc | 2016-02-26 10:28:41 -0800 | [diff] [blame] | 114 | // These are the packages that are white-listed to be able to run in the |
| 115 | // background while in data-usage save mode, as read from the configuration files. |
| 116 | final ArraySet<String> mAllowInDataUsageSave = new ArraySet<>(); |
| 117 | |
Soonil Nagarkar | 2b565df | 2017-02-14 13:33:23 -0800 | [diff] [blame] | 118 | // These are the packages that are white-listed to be able to run background location |
| 119 | // without throttling, as read from the configuration files. |
| 120 | final ArraySet<String> mAllowUnthrottledLocation = new ArraySet<>(); |
| 121 | |
Christopher Tate | 42a386b | 2016-11-07 12:21:21 -0800 | [diff] [blame] | 122 | // These are the action strings of broadcasts which are whitelisted to |
| 123 | // be delivered anonymously even to apps which target O+. |
| 124 | final ArraySet<String> mAllowImplicitBroadcasts = new ArraySet<>(); |
| 125 | |
Christopher Tate | 01e1864 | 2015-07-07 18:10:38 -0700 | [diff] [blame] | 126 | // These are the package names of apps which should be in the 'always' |
| 127 | // URL-handling state upon factory reset. |
| 128 | final ArraySet<String> mLinkedApps = new ArraySet<>(); |
| 129 | |
Fyodor Kupolov | 7db5af1 | 2015-07-31 16:50:27 -0700 | [diff] [blame] | 130 | // These are the packages that are whitelisted to be able to run as system user |
| 131 | final ArraySet<String> mSystemUserWhitelistedApps = new ArraySet<>(); |
| 132 | |
| 133 | // These are the packages that should not run under system user |
| 134 | final ArraySet<String> mSystemUserBlacklistedApps = new ArraySet<>(); |
| 135 | |
Ruben Brunk | 98576cf | 2016-03-07 18:54:28 -0800 | [diff] [blame] | 136 | // These are the components that are enabled by default as VR mode listener services. |
| 137 | final ArraySet<ComponentName> mDefaultVrComponents = new ArraySet<>(); |
| 138 | |
Christopher Tate | 494df79 | 2016-05-10 17:05:38 -0700 | [diff] [blame] | 139 | // These are the permitted backup transport service components |
| 140 | final ArraySet<ComponentName> mBackupTransportWhitelist = new ArraySet<>(); |
| 141 | |
Mathew Inwood | 4693a75 | 2018-02-20 16:04:25 +0000 | [diff] [blame] | 142 | // Package names that are exempted from private API blacklisting |
| 143 | final ArraySet<String> mHiddenApiPackageWhitelist = new ArraySet<>(); |
| 144 | |
goneil | 18928e9 | 2018-02-28 15:22:08 -0800 | [diff] [blame] | 145 | // The list of carrier applications which should be disabled until used. |
| 146 | // This function suppresses update notifications for these pre-installed apps. |
| 147 | // In SubscriptionInfoUpdater, the listed applications are disabled until used when all of the |
| 148 | // following conditions are met. |
| 149 | // 1. Not currently carrier-privileged according to the inserted SIM |
| 150 | // 2. Pre-installed |
| 151 | // 3. In the default state (enabled but not explicitly) |
| 152 | // And SubscriptionInfoUpdater undoes this and marks the app enabled when a SIM is inserted |
| 153 | // that marks the app as carrier privileged. It also grants the app default permissions |
| 154 | // for Phone and Location. As such, apps MUST only ever be added to this list if they |
| 155 | // obtain user consent to access their location through other means. |
| 156 | final ArraySet<String> mDisabledUntilUsedPreinstalledCarrierApps = new ArraySet<>(); |
| 157 | |
Jeff Davidson | 24b9d96 | 2016-07-21 12:35:10 -0700 | [diff] [blame] | 158 | // These are the packages of carrier-associated apps which should be disabled until used until |
| 159 | // a SIM is inserted which grants carrier privileges to that carrier app. |
| 160 | final ArrayMap<String, List<String>> mDisabledUntilUsedPreinstalledCarrierAssociatedApps = |
| 161 | new ArrayMap<>(); |
| 162 | |
Fyodor Kupolov | 964d2eb | 2016-11-09 14:32:27 -0800 | [diff] [blame] | 163 | final ArrayMap<String, ArraySet<String>> mPrivAppPermissions = new ArrayMap<>(); |
Todd Kennedy | 74629e3 | 2017-08-15 14:48:07 -0700 | [diff] [blame] | 164 | final ArrayMap<String, ArraySet<String>> mPrivAppDenyPermissions = new ArrayMap<>(); |
Fyodor Kupolov | 964d2eb | 2016-11-09 14:32:27 -0800 | [diff] [blame] | 165 | |
Jiyong Park | 002fdbd | 2017-02-13 20:50:31 +0900 | [diff] [blame] | 166 | final ArrayMap<String, ArraySet<String>> mVendorPrivAppPermissions = new ArrayMap<>(); |
| 167 | final ArrayMap<String, ArraySet<String>> mVendorPrivAppDenyPermissions = new ArrayMap<>(); |
| 168 | |
Jaekyun Seok | 1713d9e | 2018-01-12 21:47:26 +0900 | [diff] [blame] | 169 | final ArrayMap<String, ArraySet<String>> mProductPrivAppPermissions = new ArrayMap<>(); |
| 170 | final ArrayMap<String, ArraySet<String>> mProductPrivAppDenyPermissions = new ArrayMap<>(); |
| 171 | |
Svet Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 172 | final ArrayMap<String, ArrayMap<String, Boolean>> mOemPermissions = new ArrayMap<>(); |
| 173 | |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 174 | public static SystemConfig getInstance() { |
| 175 | synchronized (SystemConfig.class) { |
| 176 | if (sInstance == null) { |
| 177 | sInstance = new SystemConfig(); |
| 178 | } |
| 179 | return sInstance; |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | public int[] getGlobalGids() { |
| 184 | return mGlobalGids; |
| 185 | } |
| 186 | |
Jeff Sharkey | 9f837a9 | 2014-10-24 12:07:24 -0700 | [diff] [blame] | 187 | public SparseArray<ArraySet<String>> getSystemPermissions() { |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 188 | return mSystemPermissions; |
| 189 | } |
| 190 | |
| 191 | public ArrayMap<String, String> getSharedLibraries() { |
| 192 | return mSharedLibraries; |
| 193 | } |
| 194 | |
Jeff Sharkey | 9f837a9 | 2014-10-24 12:07:24 -0700 | [diff] [blame] | 195 | public ArrayMap<String, FeatureInfo> getAvailableFeatures() { |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 196 | return mAvailableFeatures; |
| 197 | } |
| 198 | |
| 199 | public ArrayMap<String, PermissionEntry> getPermissions() { |
| 200 | return mPermissions; |
| 201 | } |
| 202 | |
Christopher Tate | 42a386b | 2016-11-07 12:21:21 -0800 | [diff] [blame] | 203 | public ArraySet<String> getAllowImplicitBroadcasts() { |
| 204 | return mAllowImplicitBroadcasts; |
| 205 | } |
| 206 | |
Dianne Hackborn | 4a503b1 | 2015-08-06 22:19:06 -0700 | [diff] [blame] | 207 | public ArraySet<String> getAllowInPowerSaveExceptIdle() { |
| 208 | return mAllowInPowerSaveExceptIdle; |
| 209 | } |
| 210 | |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 211 | public ArraySet<String> getAllowInPowerSave() { |
| 212 | return mAllowInPowerSave; |
| 213 | } |
| 214 | |
Felipe Leme | a9505cc | 2016-02-26 10:28:41 -0800 | [diff] [blame] | 215 | public ArraySet<String> getAllowInDataUsageSave() { |
| 216 | return mAllowInDataUsageSave; |
| 217 | } |
| 218 | |
Soonil Nagarkar | 2b565df | 2017-02-14 13:33:23 -0800 | [diff] [blame] | 219 | public ArraySet<String> getAllowUnthrottledLocation() { |
| 220 | return mAllowUnthrottledLocation; |
| 221 | } |
| 222 | |
Christopher Tate | 01e1864 | 2015-07-07 18:10:38 -0700 | [diff] [blame] | 223 | public ArraySet<String> getLinkedApps() { |
| 224 | return mLinkedApps; |
| 225 | } |
| 226 | |
Fyodor Kupolov | 7db5af1 | 2015-07-31 16:50:27 -0700 | [diff] [blame] | 227 | public ArraySet<String> getSystemUserWhitelistedApps() { |
| 228 | return mSystemUserWhitelistedApps; |
| 229 | } |
| 230 | |
| 231 | public ArraySet<String> getSystemUserBlacklistedApps() { |
| 232 | return mSystemUserBlacklistedApps; |
| 233 | } |
| 234 | |
Mathew Inwood | 4693a75 | 2018-02-20 16:04:25 +0000 | [diff] [blame] | 235 | public ArraySet<String> getHiddenApiWhitelistedApps() { |
| 236 | return mHiddenApiPackageWhitelist; |
| 237 | } |
| 238 | |
Ruben Brunk | 98576cf | 2016-03-07 18:54:28 -0800 | [diff] [blame] | 239 | public ArraySet<ComponentName> getDefaultVrComponents() { |
| 240 | return mDefaultVrComponents; |
| 241 | } |
| 242 | |
Christopher Tate | 494df79 | 2016-05-10 17:05:38 -0700 | [diff] [blame] | 243 | public ArraySet<ComponentName> getBackupTransportWhitelist() { |
| 244 | return mBackupTransportWhitelist; |
| 245 | } |
| 246 | |
goneil | 18928e9 | 2018-02-28 15:22:08 -0800 | [diff] [blame] | 247 | public ArraySet<String> getDisabledUntilUsedPreinstalledCarrierApps() { |
| 248 | return mDisabledUntilUsedPreinstalledCarrierApps; |
| 249 | } |
| 250 | |
Jeff Davidson | 24b9d96 | 2016-07-21 12:35:10 -0700 | [diff] [blame] | 251 | public ArrayMap<String, List<String>> getDisabledUntilUsedPreinstalledCarrierAssociatedApps() { |
| 252 | return mDisabledUntilUsedPreinstalledCarrierAssociatedApps; |
| 253 | } |
| 254 | |
Fyodor Kupolov | 964d2eb | 2016-11-09 14:32:27 -0800 | [diff] [blame] | 255 | public ArraySet<String> getPrivAppPermissions(String packageName) { |
| 256 | return mPrivAppPermissions.get(packageName); |
| 257 | } |
| 258 | |
Todd Kennedy | 74629e3 | 2017-08-15 14:48:07 -0700 | [diff] [blame] | 259 | public ArraySet<String> getPrivAppDenyPermissions(String packageName) { |
| 260 | return mPrivAppDenyPermissions.get(packageName); |
| 261 | } |
| 262 | |
Jiyong Park | 002fdbd | 2017-02-13 20:50:31 +0900 | [diff] [blame] | 263 | public ArraySet<String> getVendorPrivAppPermissions(String packageName) { |
| 264 | return mVendorPrivAppPermissions.get(packageName); |
| 265 | } |
| 266 | |
| 267 | public ArraySet<String> getVendorPrivAppDenyPermissions(String packageName) { |
| 268 | return mVendorPrivAppDenyPermissions.get(packageName); |
| 269 | } |
| 270 | |
Jaekyun Seok | 1713d9e | 2018-01-12 21:47:26 +0900 | [diff] [blame] | 271 | public ArraySet<String> getProductPrivAppPermissions(String packageName) { |
| 272 | return mProductPrivAppPermissions.get(packageName); |
| 273 | } |
| 274 | |
| 275 | public ArraySet<String> getProductPrivAppDenyPermissions(String packageName) { |
| 276 | return mProductPrivAppDenyPermissions.get(packageName); |
| 277 | } |
| 278 | |
Svet Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 279 | public Map<String, Boolean> getOemPermissions(String packageName) { |
| 280 | final Map<String, Boolean> oemPermissions = mOemPermissions.get(packageName); |
| 281 | if (oemPermissions != null) { |
| 282 | return oemPermissions; |
| 283 | } |
| 284 | return Collections.emptyMap(); |
| 285 | } |
| 286 | |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 287 | SystemConfig() { |
| 288 | // Read configuration from system |
| 289 | readPermissions(Environment.buildPath( |
Hung-ying Tyan | bdc9d58 | 2015-11-20 11:53:39 +0800 | [diff] [blame] | 290 | Environment.getRootDirectory(), "etc", "sysconfig"), ALLOW_ALL); |
Svet Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 291 | |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 292 | // Read configuration from the old permissions dir |
| 293 | readPermissions(Environment.buildPath( |
Hung-ying Tyan | bdc9d58 | 2015-11-20 11:53:39 +0800 | [diff] [blame] | 294 | Environment.getRootDirectory(), "etc", "permissions"), ALLOW_ALL); |
Svet Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 295 | |
Jiyong Park | fad9944 | 2018-03-12 10:39:07 +0900 | [diff] [blame] | 296 | // Vendors are only allowed to customze libs, features and privapp permissions |
| 297 | int vendorPermissionFlag = ALLOW_LIBS | ALLOW_FEATURES | ALLOW_PRIVAPP_PERMISSIONS; |
| 298 | if (Build.VERSION.FIRST_SDK_INT <= Build.VERSION_CODES.O_MR1) { |
| 299 | // For backward compatibility |
| 300 | vendorPermissionFlag |= (ALLOW_PERMISSIONS | ALLOW_APP_CONFIGS); |
| 301 | } |
Jaekyun Seok | e3b6bf1 | 2017-02-16 13:48:30 +0900 | [diff] [blame] | 302 | readPermissions(Environment.buildPath( |
| 303 | Environment.getVendorDirectory(), "etc", "sysconfig"), vendorPermissionFlag); |
| 304 | readPermissions(Environment.buildPath( |
| 305 | Environment.getVendorDirectory(), "etc", "permissions"), vendorPermissionFlag); |
Svet Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 306 | |
Jiyong Park | 090c6b1 | 2017-12-28 12:03:28 +0900 | [diff] [blame] | 307 | // Allow ODM to customize system configs as much as Vendor, because /odm is another |
| 308 | // vendor partition other than /vendor. |
| 309 | int odmPermissionFlag = vendorPermissionFlag; |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 310 | readPermissions(Environment.buildPath( |
Hung-ying Tyan | bdc9d58 | 2015-11-20 11:53:39 +0800 | [diff] [blame] | 311 | Environment.getOdmDirectory(), "etc", "sysconfig"), odmPermissionFlag); |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 312 | readPermissions(Environment.buildPath( |
Hung-ying Tyan | bdc9d58 | 2015-11-20 11:53:39 +0800 | [diff] [blame] | 313 | Environment.getOdmDirectory(), "etc", "permissions"), odmPermissionFlag); |
Svet Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 314 | |
| 315 | // Allow OEM to customize features and OEM permissions |
| 316 | int oemPermissionFlag = ALLOW_FEATURES | ALLOW_OEM_PERMISSIONS; |
Hung-ying Tyan | bdc9d58 | 2015-11-20 11:53:39 +0800 | [diff] [blame] | 317 | readPermissions(Environment.buildPath( |
Svet Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 318 | Environment.getOemDirectory(), "etc", "sysconfig"), oemPermissionFlag); |
Hung-ying Tyan | bdc9d58 | 2015-11-20 11:53:39 +0800 | [diff] [blame] | 319 | readPermissions(Environment.buildPath( |
Svet Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 320 | Environment.getOemDirectory(), "etc", "permissions"), oemPermissionFlag); |
Jaekyun Seok | 1713d9e | 2018-01-12 21:47:26 +0900 | [diff] [blame] | 321 | |
| 322 | // Allow Product to customize system configs around libs, features, permissions and apps |
| 323 | int productPermissionFlag = ALLOW_LIBS | ALLOW_FEATURES | ALLOW_PERMISSIONS | |
| 324 | ALLOW_APP_CONFIGS | ALLOW_PRIVAPP_PERMISSIONS; |
| 325 | readPermissions(Environment.buildPath( |
| 326 | Environment.getProductDirectory(), "etc", "sysconfig"), productPermissionFlag); |
| 327 | readPermissions(Environment.buildPath( |
| 328 | Environment.getProductDirectory(), "etc", "permissions"), productPermissionFlag); |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 329 | } |
| 330 | |
Hung-ying Tyan | bdc9d58 | 2015-11-20 11:53:39 +0800 | [diff] [blame] | 331 | void readPermissions(File libraryDir, int permissionFlag) { |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 332 | // Read permissions from given directory. |
| 333 | if (!libraryDir.exists() || !libraryDir.isDirectory()) { |
Hung-ying Tyan | bdc9d58 | 2015-11-20 11:53:39 +0800 | [diff] [blame] | 334 | if (permissionFlag == ALLOW_ALL) { |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 335 | Slog.w(TAG, "No directory " + libraryDir + ", skipping"); |
| 336 | } |
| 337 | return; |
| 338 | } |
| 339 | if (!libraryDir.canRead()) { |
| 340 | Slog.w(TAG, "Directory " + libraryDir + " cannot be read"); |
| 341 | return; |
| 342 | } |
| 343 | |
| 344 | // Iterate over the files in the directory and scan .xml files |
Jeff Sharkey | 1c4ae80 | 2014-12-19 11:08:55 -0800 | [diff] [blame] | 345 | File platformFile = null; |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 346 | for (File f : libraryDir.listFiles()) { |
| 347 | // We'll read platform.xml last |
| 348 | if (f.getPath().endsWith("etc/permissions/platform.xml")) { |
Jeff Sharkey | 1c4ae80 | 2014-12-19 11:08:55 -0800 | [diff] [blame] | 349 | platformFile = f; |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 350 | continue; |
| 351 | } |
| 352 | |
| 353 | if (!f.getPath().endsWith(".xml")) { |
| 354 | Slog.i(TAG, "Non-xml file " + f + " in " + libraryDir + " directory, ignoring"); |
| 355 | continue; |
| 356 | } |
| 357 | if (!f.canRead()) { |
| 358 | Slog.w(TAG, "Permissions library file " + f + " cannot be read"); |
| 359 | continue; |
| 360 | } |
| 361 | |
Hung-ying Tyan | bdc9d58 | 2015-11-20 11:53:39 +0800 | [diff] [blame] | 362 | readPermissionsFromXml(f, permissionFlag); |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 363 | } |
| 364 | |
Jeff Sharkey | 1c4ae80 | 2014-12-19 11:08:55 -0800 | [diff] [blame] | 365 | // Read platform permissions last so it will take precedence |
| 366 | if (platformFile != null) { |
Hung-ying Tyan | bdc9d58 | 2015-11-20 11:53:39 +0800 | [diff] [blame] | 367 | readPermissionsFromXml(platformFile, permissionFlag); |
Jeff Sharkey | 1c4ae80 | 2014-12-19 11:08:55 -0800 | [diff] [blame] | 368 | } |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 369 | } |
| 370 | |
Hung-ying Tyan | bdc9d58 | 2015-11-20 11:53:39 +0800 | [diff] [blame] | 371 | private void readPermissionsFromXml(File permFile, int permissionFlag) { |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 372 | FileReader permReader = null; |
| 373 | try { |
| 374 | permReader = new FileReader(permFile); |
| 375 | } catch (FileNotFoundException e) { |
| 376 | Slog.w(TAG, "Couldn't find or open permissions file " + permFile); |
| 377 | return; |
| 378 | } |
| 379 | |
Dianne Hackborn | c0e4aaa | 2014-11-14 10:55:50 -0800 | [diff] [blame] | 380 | final boolean lowRam = ActivityManager.isLowRamDeviceStatic(); |
| 381 | |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 382 | try { |
| 383 | XmlPullParser parser = Xml.newPullParser(); |
| 384 | parser.setInput(permReader); |
| 385 | |
| 386 | int type; |
| 387 | while ((type=parser.next()) != parser.START_TAG |
| 388 | && type != parser.END_DOCUMENT) { |
| 389 | ; |
| 390 | } |
| 391 | |
| 392 | if (type != parser.START_TAG) { |
| 393 | throw new XmlPullParserException("No start tag found"); |
| 394 | } |
| 395 | |
| 396 | if (!parser.getName().equals("permissions") && !parser.getName().equals("config")) { |
Dianne Hackborn | b3d4cb3 | 2015-01-09 09:54:06 -0800 | [diff] [blame] | 397 | throw new XmlPullParserException("Unexpected start tag in " + permFile |
| 398 | + ": found " + parser.getName() + ", expected 'permissions' or 'config'"); |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 399 | } |
| 400 | |
Hung-ying Tyan | bdc9d58 | 2015-11-20 11:53:39 +0800 | [diff] [blame] | 401 | boolean allowAll = permissionFlag == ALLOW_ALL; |
| 402 | boolean allowLibs = (permissionFlag & ALLOW_LIBS) != 0; |
| 403 | boolean allowFeatures = (permissionFlag & ALLOW_FEATURES) != 0; |
| 404 | boolean allowPermissions = (permissionFlag & ALLOW_PERMISSIONS) != 0; |
| 405 | boolean allowAppConfigs = (permissionFlag & ALLOW_APP_CONFIGS) != 0; |
Jaekyun Seok | e3b6bf1 | 2017-02-16 13:48:30 +0900 | [diff] [blame] | 406 | boolean allowPrivappPermissions = (permissionFlag & ALLOW_PRIVAPP_PERMISSIONS) != 0; |
Svet Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 407 | boolean allowOemPermissions = (permissionFlag & ALLOW_OEM_PERMISSIONS) != 0; |
Mathew Inwood | 4693a75 | 2018-02-20 16:04:25 +0000 | [diff] [blame] | 408 | boolean allowApiWhitelisting = (permissionFlag & ALLOW_HIDDENAPI_WHITELISTING) != 0; |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 409 | while (true) { |
| 410 | XmlUtils.nextElement(parser); |
| 411 | if (parser.getEventType() == XmlPullParser.END_DOCUMENT) { |
| 412 | break; |
| 413 | } |
| 414 | |
| 415 | String name = parser.getName(); |
Hung-ying Tyan | bdc9d58 | 2015-11-20 11:53:39 +0800 | [diff] [blame] | 416 | if ("group".equals(name) && allowAll) { |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 417 | String gidStr = parser.getAttributeValue(null, "gid"); |
| 418 | if (gidStr != null) { |
| 419 | int gid = android.os.Process.getGidForName(gidStr); |
| 420 | mGlobalGids = appendInt(mGlobalGids, gid); |
| 421 | } else { |
Dianne Hackborn | b3d4cb3 | 2015-01-09 09:54:06 -0800 | [diff] [blame] | 422 | Slog.w(TAG, "<group> without gid in " + permFile + " at " |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 423 | + parser.getPositionDescription()); |
| 424 | } |
| 425 | |
| 426 | XmlUtils.skipCurrentTag(parser); |
| 427 | continue; |
Hung-ying Tyan | bdc9d58 | 2015-11-20 11:53:39 +0800 | [diff] [blame] | 428 | } else if ("permission".equals(name) && allowPermissions) { |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 429 | String perm = parser.getAttributeValue(null, "name"); |
| 430 | if (perm == null) { |
Dianne Hackborn | b3d4cb3 | 2015-01-09 09:54:06 -0800 | [diff] [blame] | 431 | Slog.w(TAG, "<permission> without name in " + permFile + " at " |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 432 | + parser.getPositionDescription()); |
| 433 | XmlUtils.skipCurrentTag(parser); |
| 434 | continue; |
| 435 | } |
| 436 | perm = perm.intern(); |
| 437 | readPermission(parser, perm); |
| 438 | |
Hung-ying Tyan | bdc9d58 | 2015-11-20 11:53:39 +0800 | [diff] [blame] | 439 | } else if ("assign-permission".equals(name) && allowPermissions) { |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 440 | String perm = parser.getAttributeValue(null, "name"); |
| 441 | if (perm == null) { |
Dianne Hackborn | b3d4cb3 | 2015-01-09 09:54:06 -0800 | [diff] [blame] | 442 | Slog.w(TAG, "<assign-permission> without name in " + permFile + " at " |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 443 | + parser.getPositionDescription()); |
| 444 | XmlUtils.skipCurrentTag(parser); |
| 445 | continue; |
| 446 | } |
| 447 | String uidStr = parser.getAttributeValue(null, "uid"); |
| 448 | if (uidStr == null) { |
Dianne Hackborn | b3d4cb3 | 2015-01-09 09:54:06 -0800 | [diff] [blame] | 449 | Slog.w(TAG, "<assign-permission> without uid in " + permFile + " at " |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 450 | + parser.getPositionDescription()); |
| 451 | XmlUtils.skipCurrentTag(parser); |
| 452 | continue; |
| 453 | } |
| 454 | int uid = Process.getUidForName(uidStr); |
| 455 | if (uid < 0) { |
| 456 | Slog.w(TAG, "<assign-permission> with unknown uid \"" |
Dianne Hackborn | b3d4cb3 | 2015-01-09 09:54:06 -0800 | [diff] [blame] | 457 | + uidStr + " in " + permFile + " at " |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 458 | + parser.getPositionDescription()); |
| 459 | XmlUtils.skipCurrentTag(parser); |
| 460 | continue; |
| 461 | } |
| 462 | perm = perm.intern(); |
Jeff Sharkey | 9f837a9 | 2014-10-24 12:07:24 -0700 | [diff] [blame] | 463 | ArraySet<String> perms = mSystemPermissions.get(uid); |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 464 | if (perms == null) { |
Jeff Sharkey | 9f837a9 | 2014-10-24 12:07:24 -0700 | [diff] [blame] | 465 | perms = new ArraySet<String>(); |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 466 | mSystemPermissions.put(uid, perms); |
| 467 | } |
| 468 | perms.add(perm); |
| 469 | XmlUtils.skipCurrentTag(parser); |
| 470 | |
Hung-ying Tyan | bdc9d58 | 2015-11-20 11:53:39 +0800 | [diff] [blame] | 471 | } else if ("library".equals(name) && allowLibs) { |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 472 | String lname = parser.getAttributeValue(null, "name"); |
| 473 | String lfile = parser.getAttributeValue(null, "file"); |
| 474 | if (lname == null) { |
Dianne Hackborn | b3d4cb3 | 2015-01-09 09:54:06 -0800 | [diff] [blame] | 475 | Slog.w(TAG, "<library> without name in " + permFile + " at " |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 476 | + parser.getPositionDescription()); |
| 477 | } else if (lfile == null) { |
Dianne Hackborn | b3d4cb3 | 2015-01-09 09:54:06 -0800 | [diff] [blame] | 478 | Slog.w(TAG, "<library> without file in " + permFile + " at " |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 479 | + parser.getPositionDescription()); |
| 480 | } else { |
| 481 | //Log.i(TAG, "Got library " + lname + " in " + lfile); |
| 482 | mSharedLibraries.put(lname, lfile); |
| 483 | } |
| 484 | XmlUtils.skipCurrentTag(parser); |
| 485 | continue; |
| 486 | |
Hung-ying Tyan | bdc9d58 | 2015-11-20 11:53:39 +0800 | [diff] [blame] | 487 | } else if ("feature".equals(name) && allowFeatures) { |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 488 | String fname = parser.getAttributeValue(null, "name"); |
Arunesh Mishra | 4e0bdf3 | 2016-02-15 23:50:38 -0800 | [diff] [blame] | 489 | int fversion = XmlUtils.readIntAttribute(parser, "version", 0); |
Dianne Hackborn | c0e4aaa | 2014-11-14 10:55:50 -0800 | [diff] [blame] | 490 | boolean allowed; |
| 491 | if (!lowRam) { |
| 492 | allowed = true; |
| 493 | } else { |
| 494 | String notLowRam = parser.getAttributeValue(null, "notLowRam"); |
| 495 | allowed = !"true".equals(notLowRam); |
| 496 | } |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 497 | if (fname == null) { |
Dianne Hackborn | b3d4cb3 | 2015-01-09 09:54:06 -0800 | [diff] [blame] | 498 | Slog.w(TAG, "<feature> without name in " + permFile + " at " |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 499 | + parser.getPositionDescription()); |
Dianne Hackborn | c0e4aaa | 2014-11-14 10:55:50 -0800 | [diff] [blame] | 500 | } else if (allowed) { |
Jeff Sharkey | 115d2c1 | 2016-02-15 17:25:57 -0700 | [diff] [blame] | 501 | addFeature(fname, fversion); |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 502 | } |
| 503 | XmlUtils.skipCurrentTag(parser); |
| 504 | continue; |
| 505 | |
Hung-ying Tyan | bdc9d58 | 2015-11-20 11:53:39 +0800 | [diff] [blame] | 506 | } else if ("unavailable-feature".equals(name) && allowFeatures) { |
Jeff Sharkey | 1c4ae80 | 2014-12-19 11:08:55 -0800 | [diff] [blame] | 507 | String fname = parser.getAttributeValue(null, "name"); |
| 508 | if (fname == null) { |
Dianne Hackborn | b3d4cb3 | 2015-01-09 09:54:06 -0800 | [diff] [blame] | 509 | Slog.w(TAG, "<unavailable-feature> without name in " + permFile + " at " |
Jeff Sharkey | 1c4ae80 | 2014-12-19 11:08:55 -0800 | [diff] [blame] | 510 | + parser.getPositionDescription()); |
| 511 | } else { |
| 512 | mUnavailableFeatures.add(fname); |
| 513 | } |
| 514 | XmlUtils.skipCurrentTag(parser); |
| 515 | continue; |
| 516 | |
Hung-ying Tyan | bdc9d58 | 2015-11-20 11:53:39 +0800 | [diff] [blame] | 517 | } else if ("allow-in-power-save-except-idle".equals(name) && allowAll) { |
Dianne Hackborn | 4a503b1 | 2015-08-06 22:19:06 -0700 | [diff] [blame] | 518 | String pkgname = parser.getAttributeValue(null, "package"); |
| 519 | if (pkgname == null) { |
| 520 | Slog.w(TAG, "<allow-in-power-save-except-idle> without package in " |
| 521 | + permFile + " at " + parser.getPositionDescription()); |
| 522 | } else { |
| 523 | mAllowInPowerSaveExceptIdle.add(pkgname); |
| 524 | } |
| 525 | XmlUtils.skipCurrentTag(parser); |
| 526 | continue; |
| 527 | |
Hung-ying Tyan | bdc9d58 | 2015-11-20 11:53:39 +0800 | [diff] [blame] | 528 | } else if ("allow-in-power-save".equals(name) && allowAll) { |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 529 | String pkgname = parser.getAttributeValue(null, "package"); |
| 530 | if (pkgname == null) { |
Dianne Hackborn | b3d4cb3 | 2015-01-09 09:54:06 -0800 | [diff] [blame] | 531 | Slog.w(TAG, "<allow-in-power-save> without package in " + permFile + " at " |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 532 | + parser.getPositionDescription()); |
| 533 | } else { |
| 534 | mAllowInPowerSave.add(pkgname); |
| 535 | } |
| 536 | XmlUtils.skipCurrentTag(parser); |
| 537 | continue; |
| 538 | |
Felipe Leme | a9505cc | 2016-02-26 10:28:41 -0800 | [diff] [blame] | 539 | } else if ("allow-in-data-usage-save".equals(name) && allowAll) { |
| 540 | String pkgname = parser.getAttributeValue(null, "package"); |
| 541 | if (pkgname == null) { |
| 542 | Slog.w(TAG, "<allow-in-data-usage-save> without package in " + permFile |
| 543 | + " at " + parser.getPositionDescription()); |
| 544 | } else { |
| 545 | mAllowInDataUsageSave.add(pkgname); |
| 546 | } |
| 547 | XmlUtils.skipCurrentTag(parser); |
| 548 | continue; |
| 549 | |
Soonil Nagarkar | 2b565df | 2017-02-14 13:33:23 -0800 | [diff] [blame] | 550 | } else if ("allow-unthrottled-location".equals(name) && allowAll) { |
| 551 | String pkgname = parser.getAttributeValue(null, "package"); |
| 552 | if (pkgname == null) { |
| 553 | Slog.w(TAG, "<allow-unthrottled-location> without package in " |
| 554 | + permFile + " at " + parser.getPositionDescription()); |
| 555 | } else { |
| 556 | mAllowUnthrottledLocation.add(pkgname); |
| 557 | } |
| 558 | XmlUtils.skipCurrentTag(parser); |
| 559 | continue; |
| 560 | |
Christopher Tate | 42a386b | 2016-11-07 12:21:21 -0800 | [diff] [blame] | 561 | } else if ("allow-implicit-broadcast".equals(name) && allowAll) { |
| 562 | String action = parser.getAttributeValue(null, "action"); |
| 563 | if (action == null) { |
| 564 | Slog.w(TAG, "<allow-implicit-broadcast> without action in " + permFile |
| 565 | + " at " + parser.getPositionDescription()); |
| 566 | } else { |
| 567 | mAllowImplicitBroadcasts.add(action); |
| 568 | } |
| 569 | XmlUtils.skipCurrentTag(parser); |
| 570 | continue; |
| 571 | |
Hung-ying Tyan | bdc9d58 | 2015-11-20 11:53:39 +0800 | [diff] [blame] | 572 | } else if ("app-link".equals(name) && allowAppConfigs) { |
Christopher Tate | 01e1864 | 2015-07-07 18:10:38 -0700 | [diff] [blame] | 573 | String pkgname = parser.getAttributeValue(null, "package"); |
| 574 | if (pkgname == null) { |
| 575 | Slog.w(TAG, "<app-link> without package in " + permFile + " at " |
| 576 | + parser.getPositionDescription()); |
| 577 | } else { |
| 578 | mLinkedApps.add(pkgname); |
| 579 | } |
| 580 | XmlUtils.skipCurrentTag(parser); |
Hung-ying Tyan | bdc9d58 | 2015-11-20 11:53:39 +0800 | [diff] [blame] | 581 | } else if ("system-user-whitelisted-app".equals(name) && allowAppConfigs) { |
Fyodor Kupolov | 7db5af1 | 2015-07-31 16:50:27 -0700 | [diff] [blame] | 582 | String pkgname = parser.getAttributeValue(null, "package"); |
| 583 | if (pkgname == null) { |
| 584 | Slog.w(TAG, "<system-user-whitelisted-app> without package in " + permFile |
| 585 | + " at " + parser.getPositionDescription()); |
| 586 | } else { |
| 587 | mSystemUserWhitelistedApps.add(pkgname); |
| 588 | } |
| 589 | XmlUtils.skipCurrentTag(parser); |
Hung-ying Tyan | bdc9d58 | 2015-11-20 11:53:39 +0800 | [diff] [blame] | 590 | } else if ("system-user-blacklisted-app".equals(name) && allowAppConfigs) { |
Fyodor Kupolov | 7db5af1 | 2015-07-31 16:50:27 -0700 | [diff] [blame] | 591 | String pkgname = parser.getAttributeValue(null, "package"); |
| 592 | if (pkgname == null) { |
| 593 | Slog.w(TAG, "<system-user-blacklisted-app without package in " + permFile |
| 594 | + " at " + parser.getPositionDescription()); |
| 595 | } else { |
| 596 | mSystemUserBlacklistedApps.add(pkgname); |
| 597 | } |
| 598 | XmlUtils.skipCurrentTag(parser); |
Ruben Brunk | 98576cf | 2016-03-07 18:54:28 -0800 | [diff] [blame] | 599 | } else if ("default-enabled-vr-app".equals(name) && allowAppConfigs) { |
| 600 | String pkgname = parser.getAttributeValue(null, "package"); |
| 601 | String clsname = parser.getAttributeValue(null, "class"); |
| 602 | if (pkgname == null) { |
| 603 | Slog.w(TAG, "<default-enabled-vr-app without package in " + permFile |
| 604 | + " at " + parser.getPositionDescription()); |
| 605 | } else if (clsname == null) { |
| 606 | Slog.w(TAG, "<default-enabled-vr-app without class in " + permFile |
| 607 | + " at " + parser.getPositionDescription()); |
| 608 | } else { |
| 609 | mDefaultVrComponents.add(new ComponentName(pkgname, clsname)); |
| 610 | } |
| 611 | XmlUtils.skipCurrentTag(parser); |
Christopher Tate | 494df79 | 2016-05-10 17:05:38 -0700 | [diff] [blame] | 612 | } else if ("backup-transport-whitelisted-service".equals(name) && allowFeatures) { |
| 613 | String serviceName = parser.getAttributeValue(null, "service"); |
| 614 | if (serviceName == null) { |
| 615 | Slog.w(TAG, "<backup-transport-whitelisted-service> without service in " |
| 616 | + permFile + " at " + parser.getPositionDescription()); |
| 617 | } else { |
| 618 | ComponentName cn = ComponentName.unflattenFromString(serviceName); |
| 619 | if (cn == null) { |
| 620 | Slog.w(TAG, |
| 621 | "<backup-transport-whitelisted-service> with invalid service name " |
| 622 | + serviceName + " in "+ permFile |
| 623 | + " at " + parser.getPositionDescription()); |
| 624 | } else { |
| 625 | mBackupTransportWhitelist.add(cn); |
| 626 | } |
| 627 | } |
| 628 | XmlUtils.skipCurrentTag(parser); |
Jeff Davidson | 24b9d96 | 2016-07-21 12:35:10 -0700 | [diff] [blame] | 629 | } else if ("disabled-until-used-preinstalled-carrier-associated-app".equals(name) |
| 630 | && allowAppConfigs) { |
| 631 | String pkgname = parser.getAttributeValue(null, "package"); |
| 632 | String carrierPkgname = parser.getAttributeValue(null, "carrierAppPackage"); |
| 633 | if (pkgname == null || carrierPkgname == null) { |
| 634 | Slog.w(TAG, "<disabled-until-used-preinstalled-carrier-associated-app" |
| 635 | + " without package or carrierAppPackage in " + permFile + " at " |
| 636 | + parser.getPositionDescription()); |
| 637 | } else { |
| 638 | List<String> associatedPkgs = |
| 639 | mDisabledUntilUsedPreinstalledCarrierAssociatedApps.get( |
| 640 | carrierPkgname); |
| 641 | if (associatedPkgs == null) { |
| 642 | associatedPkgs = new ArrayList<>(); |
| 643 | mDisabledUntilUsedPreinstalledCarrierAssociatedApps.put( |
| 644 | carrierPkgname, associatedPkgs); |
| 645 | } |
| 646 | associatedPkgs.add(pkgname); |
| 647 | } |
| 648 | XmlUtils.skipCurrentTag(parser); |
goneil | 18928e9 | 2018-02-28 15:22:08 -0800 | [diff] [blame] | 649 | } else if ("disabled-until-used-preinstalled-carrier-app".equals(name) |
| 650 | && allowAppConfigs) { |
| 651 | String pkgname = parser.getAttributeValue(null, "package"); |
| 652 | if (pkgname == null) { |
| 653 | Slog.w(TAG, |
| 654 | "<disabled-until-used-preinstalled-carrier-app> without " |
| 655 | + "package in " + permFile + " at " |
| 656 | + parser.getPositionDescription()); |
| 657 | } else { |
| 658 | mDisabledUntilUsedPreinstalledCarrierApps.add(pkgname); |
| 659 | } |
| 660 | XmlUtils.skipCurrentTag(parser); |
Jaekyun Seok | e3b6bf1 | 2017-02-16 13:48:30 +0900 | [diff] [blame] | 661 | } else if ("privapp-permissions".equals(name) && allowPrivappPermissions) { |
Jaekyun Seok | 1713d9e | 2018-01-12 21:47:26 +0900 | [diff] [blame] | 662 | // privapp permissions from system, vendor and product partitions are stored |
Jiyong Park | 002fdbd | 2017-02-13 20:50:31 +0900 | [diff] [blame] | 663 | // separately. This is to prevent xml files in the vendor partition from |
| 664 | // granting permissions to priv apps in the system partition and vice |
| 665 | // versa. |
| 666 | boolean vendor = permFile.toPath().startsWith( |
Jiyong Park | 090c6b1 | 2017-12-28 12:03:28 +0900 | [diff] [blame] | 667 | Environment.getVendorDirectory().toPath()) |
| 668 | || permFile.toPath().startsWith( |
| 669 | Environment.getOdmDirectory().toPath()); |
Jaekyun Seok | 1713d9e | 2018-01-12 21:47:26 +0900 | [diff] [blame] | 670 | boolean product = permFile.toPath().startsWith( |
| 671 | Environment.getProductDirectory().toPath()); |
Jiyong Park | 002fdbd | 2017-02-13 20:50:31 +0900 | [diff] [blame] | 672 | if (vendor) { |
| 673 | readPrivAppPermissions(parser, mVendorPrivAppPermissions, |
| 674 | mVendorPrivAppDenyPermissions); |
Jaekyun Seok | 1713d9e | 2018-01-12 21:47:26 +0900 | [diff] [blame] | 675 | } else if (product) { |
| 676 | readPrivAppPermissions(parser, mProductPrivAppPermissions, |
| 677 | mProductPrivAppDenyPermissions); |
Jiyong Park | 002fdbd | 2017-02-13 20:50:31 +0900 | [diff] [blame] | 678 | } else { |
| 679 | readPrivAppPermissions(parser, mPrivAppPermissions, |
| 680 | mPrivAppDenyPermissions); |
| 681 | } |
Svet Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 682 | } else if ("oem-permissions".equals(name) && allowOemPermissions) { |
| 683 | readOemPermissions(parser); |
Mathew Inwood | 4693a75 | 2018-02-20 16:04:25 +0000 | [diff] [blame] | 684 | } else if ("hidden-api-whitelisted-app".equals(name) && allowApiWhitelisting) { |
| 685 | String pkgname = parser.getAttributeValue(null, "package"); |
| 686 | if (pkgname == null) { |
| 687 | Slog.w(TAG, "<hidden-api-whitelisted-app> without package in " + permFile |
| 688 | + " at " + parser.getPositionDescription()); |
| 689 | } else { |
| 690 | mHiddenApiPackageWhitelist.add(pkgname); |
| 691 | } |
| 692 | XmlUtils.skipCurrentTag(parser); |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 693 | } else { |
Jiyong Park | fad9944 | 2018-03-12 10:39:07 +0900 | [diff] [blame] | 694 | Slog.w(TAG, "Tag " + name + " is unknown or not allowed in " |
| 695 | + permFile.getParent()); |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 696 | XmlUtils.skipCurrentTag(parser); |
| 697 | continue; |
| 698 | } |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 699 | } |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 700 | } catch (XmlPullParserException e) { |
Jeff Sharkey | 1c4ae80 | 2014-12-19 11:08:55 -0800 | [diff] [blame] | 701 | Slog.w(TAG, "Got exception parsing permissions.", e); |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 702 | } catch (IOException e) { |
Jeff Sharkey | 1c4ae80 | 2014-12-19 11:08:55 -0800 | [diff] [blame] | 703 | Slog.w(TAG, "Got exception parsing permissions.", e); |
| 704 | } finally { |
| 705 | IoUtils.closeQuietly(permReader); |
| 706 | } |
| 707 | |
Jeff Sharkey | b92b05b | 2016-01-28 09:50:00 -0700 | [diff] [blame] | 708 | // Some devices can be field-converted to FBE, so offer to splice in |
| 709 | // those features if not already defined by the static config |
Paul Lawrence | 20be5d6 | 2016-02-26 13:51:17 -0800 | [diff] [blame] | 710 | if (StorageManager.isFileEncryptedNativeOnly()) { |
Jeff Sharkey | 115d2c1 | 2016-02-15 17:25:57 -0700 | [diff] [blame] | 711 | addFeature(PackageManager.FEATURE_FILE_BASED_ENCRYPTION, 0); |
| 712 | addFeature(PackageManager.FEATURE_SECURELY_REMOVES_USERS, 0); |
Jeff Sharkey | b92b05b | 2016-01-28 09:50:00 -0700 | [diff] [blame] | 713 | } |
| 714 | |
Jeff Sharkey | 8eb783b | 2018-01-04 16:46:48 -0700 | [diff] [blame] | 715 | // Help legacy devices that may not have updated their static config |
| 716 | if (StorageManager.hasAdoptable()) { |
| 717 | addFeature(PackageManager.FEATURE_ADOPTABLE_STORAGE, 0); |
| 718 | } |
| 719 | |
Dianne Hackborn | 2a103f1 | 2017-08-08 15:50:31 -0700 | [diff] [blame] | 720 | if (ActivityManager.isLowRamDeviceStatic()) { |
| 721 | addFeature(PackageManager.FEATURE_RAM_LOW, 0); |
| 722 | } else { |
| 723 | addFeature(PackageManager.FEATURE_RAM_NORMAL, 0); |
| 724 | } |
| 725 | |
Jeff Sharkey | b92b05b | 2016-01-28 09:50:00 -0700 | [diff] [blame] | 726 | for (String featureName : mUnavailableFeatures) { |
| 727 | removeFeature(featureName); |
| 728 | } |
| 729 | } |
| 730 | |
Jeff Sharkey | 115d2c1 | 2016-02-15 17:25:57 -0700 | [diff] [blame] | 731 | private void addFeature(String name, int version) { |
| 732 | FeatureInfo fi = mAvailableFeatures.get(name); |
| 733 | if (fi == null) { |
| 734 | fi = new FeatureInfo(); |
| 735 | fi.name = name; |
| 736 | fi.version = version; |
| 737 | mAvailableFeatures.put(name, fi); |
| 738 | } else { |
| 739 | fi.version = Math.max(fi.version, version); |
Jeff Sharkey | b92b05b | 2016-01-28 09:50:00 -0700 | [diff] [blame] | 740 | } |
| 741 | } |
| 742 | |
Jeff Sharkey | 115d2c1 | 2016-02-15 17:25:57 -0700 | [diff] [blame] | 743 | private void removeFeature(String name) { |
| 744 | if (mAvailableFeatures.remove(name) != null) { |
| 745 | Slog.d(TAG, "Removed unavailable feature " + name); |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 746 | } |
| 747 | } |
| 748 | |
| 749 | void readPermission(XmlPullParser parser, String name) |
| 750 | throws IOException, XmlPullParserException { |
Jeff Sharkey | 00f3904 | 2015-03-23 16:51:22 -0700 | [diff] [blame] | 751 | if (mPermissions.containsKey(name)) { |
| 752 | throw new IllegalStateException("Duplicate permission definition for " + name); |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 753 | } |
Jeff Sharkey | 00f3904 | 2015-03-23 16:51:22 -0700 | [diff] [blame] | 754 | |
| 755 | final boolean perUser = XmlUtils.readBooleanAttribute(parser, "perUser", false); |
| 756 | final PermissionEntry perm = new PermissionEntry(name, perUser); |
| 757 | mPermissions.put(name, perm); |
| 758 | |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 759 | int outerDepth = parser.getDepth(); |
| 760 | int type; |
| 761 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 762 | && (type != XmlPullParser.END_TAG |
| 763 | || parser.getDepth() > outerDepth)) { |
| 764 | if (type == XmlPullParser.END_TAG |
| 765 | || type == XmlPullParser.TEXT) { |
| 766 | continue; |
| 767 | } |
| 768 | |
| 769 | String tagName = parser.getName(); |
| 770 | if ("group".equals(tagName)) { |
| 771 | String gidStr = parser.getAttributeValue(null, "gid"); |
| 772 | if (gidStr != null) { |
| 773 | int gid = Process.getGidForName(gidStr); |
| 774 | perm.gids = appendInt(perm.gids, gid); |
| 775 | } else { |
| 776 | Slog.w(TAG, "<group> without gid at " |
| 777 | + parser.getPositionDescription()); |
| 778 | } |
| 779 | } |
| 780 | XmlUtils.skipCurrentTag(parser); |
| 781 | } |
| 782 | } |
Fyodor Kupolov | 964d2eb | 2016-11-09 14:32:27 -0800 | [diff] [blame] | 783 | |
Jiyong Park | 002fdbd | 2017-02-13 20:50:31 +0900 | [diff] [blame] | 784 | private void readPrivAppPermissions(XmlPullParser parser, |
| 785 | ArrayMap<String, ArraySet<String>> grantMap, |
| 786 | ArrayMap<String, ArraySet<String>> denyMap) |
| 787 | throws IOException, XmlPullParserException { |
Fyodor Kupolov | 964d2eb | 2016-11-09 14:32:27 -0800 | [diff] [blame] | 788 | String packageName = parser.getAttributeValue(null, "package"); |
| 789 | if (TextUtils.isEmpty(packageName)) { |
| 790 | Slog.w(TAG, "package is required for <privapp-permissions> in " |
| 791 | + parser.getPositionDescription()); |
| 792 | return; |
| 793 | } |
| 794 | |
Jiyong Park | 002fdbd | 2017-02-13 20:50:31 +0900 | [diff] [blame] | 795 | ArraySet<String> permissions = grantMap.get(packageName); |
Fyodor Kupolov | 964d2eb | 2016-11-09 14:32:27 -0800 | [diff] [blame] | 796 | if (permissions == null) { |
| 797 | permissions = new ArraySet<>(); |
| 798 | } |
Jiyong Park | 002fdbd | 2017-02-13 20:50:31 +0900 | [diff] [blame] | 799 | ArraySet<String> denyPermissions = denyMap.get(packageName); |
Fyodor Kupolov | 964d2eb | 2016-11-09 14:32:27 -0800 | [diff] [blame] | 800 | int depth = parser.getDepth(); |
| 801 | while (XmlUtils.nextElementWithin(parser, depth)) { |
| 802 | String name = parser.getName(); |
| 803 | if ("permission".equals(name)) { |
| 804 | String permName = parser.getAttributeValue(null, "name"); |
| 805 | if (TextUtils.isEmpty(permName)) { |
| 806 | Slog.w(TAG, "name is required for <permission> in " |
| 807 | + parser.getPositionDescription()); |
| 808 | continue; |
| 809 | } |
| 810 | permissions.add(permName); |
Todd Kennedy | 74629e3 | 2017-08-15 14:48:07 -0700 | [diff] [blame] | 811 | } else if ("deny-permission".equals(name)) { |
| 812 | String permName = parser.getAttributeValue(null, "name"); |
| 813 | if (TextUtils.isEmpty(permName)) { |
| 814 | Slog.w(TAG, "name is required for <deny-permission> in " |
| 815 | + parser.getPositionDescription()); |
| 816 | continue; |
| 817 | } |
| 818 | if (denyPermissions == null) { |
| 819 | denyPermissions = new ArraySet<>(); |
| 820 | } |
| 821 | denyPermissions.add(permName); |
Fyodor Kupolov | 964d2eb | 2016-11-09 14:32:27 -0800 | [diff] [blame] | 822 | } |
| 823 | } |
Jiyong Park | 002fdbd | 2017-02-13 20:50:31 +0900 | [diff] [blame] | 824 | grantMap.put(packageName, permissions); |
Todd Kennedy | 74629e3 | 2017-08-15 14:48:07 -0700 | [diff] [blame] | 825 | if (denyPermissions != null) { |
Jiyong Park | 002fdbd | 2017-02-13 20:50:31 +0900 | [diff] [blame] | 826 | denyMap.put(packageName, denyPermissions); |
Todd Kennedy | 74629e3 | 2017-08-15 14:48:07 -0700 | [diff] [blame] | 827 | } |
Fyodor Kupolov | 964d2eb | 2016-11-09 14:32:27 -0800 | [diff] [blame] | 828 | } |
Svet Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 829 | |
| 830 | void readOemPermissions(XmlPullParser parser) throws IOException, XmlPullParserException { |
| 831 | final String packageName = parser.getAttributeValue(null, "package"); |
| 832 | if (TextUtils.isEmpty(packageName)) { |
| 833 | Slog.w(TAG, "package is required for <oem-permissions> in " |
| 834 | + parser.getPositionDescription()); |
| 835 | return; |
| 836 | } |
| 837 | |
| 838 | ArrayMap<String, Boolean> permissions = mOemPermissions.get(packageName); |
| 839 | if (permissions == null) { |
| 840 | permissions = new ArrayMap<>(); |
| 841 | } |
| 842 | final int depth = parser.getDepth(); |
| 843 | while (XmlUtils.nextElementWithin(parser, depth)) { |
| 844 | final String name = parser.getName(); |
| 845 | if ("permission".equals(name)) { |
| 846 | final String permName = parser.getAttributeValue(null, "name"); |
| 847 | if (TextUtils.isEmpty(permName)) { |
| 848 | Slog.w(TAG, "name is required for <permission> in " |
| 849 | + parser.getPositionDescription()); |
| 850 | continue; |
| 851 | } |
| 852 | permissions.put(permName, Boolean.TRUE); |
| 853 | } else if ("deny-permission".equals(name)) { |
| 854 | String permName = parser.getAttributeValue(null, "name"); |
| 855 | if (TextUtils.isEmpty(permName)) { |
| 856 | Slog.w(TAG, "name is required for <deny-permission> in " |
| 857 | + parser.getPositionDescription()); |
| 858 | continue; |
| 859 | } |
| 860 | permissions.put(permName, Boolean.FALSE); |
| 861 | } |
| 862 | } |
| 863 | mOemPermissions.put(packageName, permissions); |
| 864 | } |
Dianne Hackborn | be7c50e | 2014-06-30 14:43:28 -0700 | [diff] [blame] | 865 | } |