Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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.pm; |
| 18 | |
| 19 | import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DEFAULT; |
| 20 | import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DISABLED; |
| 21 | import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_ENABLED; |
Christopher Tate | e9fd1fa | 2015-09-15 16:43:07 -0700 | [diff] [blame] | 22 | import static android.content.pm.PackageManager.FLAG_PERMISSION_REVOKE_ON_UPGRADE; |
Jeff Sharkey | 2271ba3 | 2016-02-01 17:57:08 -0700 | [diff] [blame] | 23 | import static android.content.pm.PackageManager.FLAG_PERMISSION_USER_FIXED; |
| 24 | import static android.content.pm.PackageManager.FLAG_PERMISSION_USER_SET; |
Todd Kennedy | 13715d5 | 2016-08-01 13:38:57 -0700 | [diff] [blame] | 25 | import static android.content.pm.PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 26 | import static android.content.pm.PackageManager.INSTALL_FAILED_SHARED_USER_INCOMPATIBLE; |
Fabrice Di Meglio | 0788595 | 2015-04-06 19:41:28 -0700 | [diff] [blame] | 27 | import static android.content.pm.PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ALWAYS; |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 28 | import static android.content.pm.PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_UNDEFINED; |
Jeff Sharkey | 2a90f673 | 2016-01-06 12:26:11 -0700 | [diff] [blame] | 29 | import static android.content.pm.PackageManager.MATCH_DEFAULT_ONLY; |
Jeff Sharkey | 184a010 | 2013-07-10 16:19:52 -0700 | [diff] [blame] | 30 | import static android.os.Process.PACKAGE_INFO_GID; |
Jeff Sharkey | 2a90f673 | 2016-01-06 12:26:11 -0700 | [diff] [blame] | 31 | import static android.os.Process.SYSTEM_UID; |
Jeff Sharkey | 2271ba3 | 2016-02-01 17:57:08 -0700 | [diff] [blame] | 32 | |
Christopher Tate | 72c10a2 | 2015-06-12 18:31:24 -0700 | [diff] [blame] | 33 | import static com.android.server.pm.PackageManagerService.DEBUG_DOMAIN_VERIFICATION; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 34 | |
Xiaohui Chen | 594f208 | 2015-08-18 11:04:20 -0700 | [diff] [blame] | 35 | import android.annotation.NonNull; |
Todd Kennedy | 13715d5 | 2016-08-01 13:38:57 -0700 | [diff] [blame] | 36 | import android.annotation.Nullable; |
Jeff Sharkey | 2a90f673 | 2016-01-06 12:26:11 -0700 | [diff] [blame] | 37 | import android.content.ComponentName; |
| 38 | import android.content.Intent; |
Dianne Hackborn | 8a2ed1d | 2013-01-29 15:18:29 -0800 | [diff] [blame] | 39 | import android.content.IntentFilter; |
| 40 | import android.content.pm.ActivityInfo; |
Jeff Sharkey | 2a90f673 | 2016-01-06 12:26:11 -0700 | [diff] [blame] | 41 | import android.content.pm.ApplicationInfo; |
| 42 | import android.content.pm.ComponentInfo; |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 43 | import android.content.pm.IntentFilterVerificationInfo; |
Jeff Sharkey | 2a90f673 | 2016-01-06 12:26:11 -0700 | [diff] [blame] | 44 | import android.content.pm.PackageCleanItem; |
| 45 | import android.content.pm.PackageManager; |
| 46 | import android.content.pm.PackageParser; |
| 47 | import android.content.pm.PackageUserState; |
| 48 | import android.content.pm.PermissionInfo; |
Dianne Hackborn | 8a2ed1d | 2013-01-29 15:18:29 -0800 | [diff] [blame] | 49 | import android.content.pm.ResolveInfo; |
Jeff Sharkey | 2a90f673 | 2016-01-06 12:26:11 -0700 | [diff] [blame] | 50 | import android.content.pm.Signature; |
| 51 | import android.content.pm.UserInfo; |
| 52 | import android.content.pm.VerifierDeviceIdentity; |
Dianne Hackborn | 8a2ed1d | 2013-01-29 15:18:29 -0800 | [diff] [blame] | 53 | import android.net.Uri; |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 54 | import android.os.Binder; |
Jeff Sharkey | 4ed745d | 2014-07-15 20:39:15 -0700 | [diff] [blame] | 55 | import android.os.Build; |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 56 | import android.os.Environment; |
| 57 | import android.os.FileUtils; |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 58 | import android.os.Handler; |
| 59 | import android.os.Message; |
Dianne Hackborn | 8a2ed1d | 2013-01-29 15:18:29 -0800 | [diff] [blame] | 60 | import android.os.PatternMatcher; |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 61 | import android.os.Process; |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 62 | import android.os.SystemClock; |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 63 | import android.os.UserHandle; |
Amith Yamasani | 26f9ea3 | 2014-09-11 10:56:51 -0700 | [diff] [blame] | 64 | import android.os.UserManager; |
Paul Crowley | bcf48ed | 2015-04-22 13:36:59 +0100 | [diff] [blame] | 65 | import android.os.storage.StorageManager; |
Netta P | 426cbef | 2017-02-10 14:38:39 -0800 | [diff] [blame] | 66 | import android.service.pm.PackageServiceDumpProto; |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 67 | import android.text.TextUtils; |
Jeff Sharkey | 2a90f673 | 2016-01-06 12:26:11 -0700 | [diff] [blame] | 68 | import android.util.ArrayMap; |
| 69 | import android.util.ArraySet; |
| 70 | import android.util.AtomicFile; |
| 71 | import android.util.Log; |
Dianne Hackborn | 8a2ed1d | 2013-01-29 15:18:29 -0800 | [diff] [blame] | 72 | import android.util.LogPrinter; |
Jeff Sharkey | 2a90f673 | 2016-01-06 12:26:11 -0700 | [diff] [blame] | 73 | import android.util.Slog; |
| 74 | import android.util.SparseArray; |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 75 | import android.util.SparseBooleanArray; |
Jeff Sharkey | 2a90f673 | 2016-01-06 12:26:11 -0700 | [diff] [blame] | 76 | import android.util.SparseIntArray; |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 77 | import android.util.SparseLongArray; |
Jeff Sharkey | 2a90f673 | 2016-01-06 12:26:11 -0700 | [diff] [blame] | 78 | import android.util.Xml; |
Netta P | 426cbef | 2017-02-10 14:38:39 -0800 | [diff] [blame] | 79 | import android.util.proto.ProtoOutputStream; |
Christopher Tate | e012a23 | 2015-04-01 17:18:50 -0700 | [diff] [blame] | 80 | |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 81 | import com.android.internal.annotations.GuardedBy; |
| 82 | import com.android.internal.os.BackgroundThread; |
| 83 | import com.android.internal.util.ArrayUtils; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 84 | import com.android.internal.util.FastXmlSerializer; |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 85 | import com.android.internal.util.IndentingPrintWriter; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 86 | import com.android.internal.util.JournaledFile; |
| 87 | import com.android.internal.util.XmlUtils; |
Jeff Sharkey | 740f523 | 2016-12-09 14:31:26 -0700 | [diff] [blame] | 88 | import com.android.server.pm.Installer.InstallerException; |
Todd Kennedy | 91a39d1 | 2017-09-27 12:37:04 -0700 | [diff] [blame] | 89 | import com.android.server.pm.permission.BasePermission; |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 90 | import com.android.server.pm.permission.PermissionSettings; |
Todd Kennedy | 82b0842 | 2017-09-28 13:32:05 -0700 | [diff] [blame] | 91 | import com.android.server.pm.permission.PermissionsState; |
| 92 | import com.android.server.pm.permission.PermissionsState.PermissionState; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 93 | |
Jeff Sharkey | 2a90f673 | 2016-01-06 12:26:11 -0700 | [diff] [blame] | 94 | import libcore.io.IoUtils; |
Alexandra Gherghina | 6e2ae25 | 2014-06-12 16:03:58 +0100 | [diff] [blame] | 95 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 96 | import org.xmlpull.v1.XmlPullParser; |
| 97 | import org.xmlpull.v1.XmlPullParserException; |
| 98 | import org.xmlpull.v1.XmlSerializer; |
| 99 | |
Jeff Sharkey | 2a90f673 | 2016-01-06 12:26:11 -0700 | [diff] [blame] | 100 | import java.io.BufferedInputStream; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 101 | import java.io.BufferedOutputStream; |
Jeff Sharkey | 2a90f673 | 2016-01-06 12:26:11 -0700 | [diff] [blame] | 102 | import java.io.BufferedWriter; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 103 | import java.io.File; |
| 104 | import java.io.FileInputStream; |
Jeff Sharkey | 2a90f673 | 2016-01-06 12:26:11 -0700 | [diff] [blame] | 105 | import java.io.FileNotFoundException; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 106 | import java.io.FileOutputStream; |
| 107 | import java.io.IOException; |
Jeff Sharkey | 2a90f673 | 2016-01-06 12:26:11 -0700 | [diff] [blame] | 108 | import java.io.InputStream; |
| 109 | import java.io.OutputStreamWriter; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 110 | import java.io.PrintWriter; |
Jeff Sharkey | 2a90f673 | 2016-01-06 12:26:11 -0700 | [diff] [blame] | 111 | import java.nio.charset.Charset; |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 112 | import java.nio.charset.StandardCharsets; |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 113 | import java.text.SimpleDateFormat; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 114 | import java.util.ArrayList; |
| 115 | import java.util.Arrays; |
Jeff Sharkey | 2a90f673 | 2016-01-06 12:26:11 -0700 | [diff] [blame] | 116 | import java.util.Collection; |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 117 | import java.util.Collections; |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 118 | import java.util.Date; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 119 | import java.util.Iterator; |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 120 | import java.util.List; |
Andy McFadden | 2f36229 | 2012-01-20 14:43:38 -0800 | [diff] [blame] | 121 | import java.util.Map; |
Jeff Sharkey | 2a90f673 | 2016-01-06 12:26:11 -0700 | [diff] [blame] | 122 | import java.util.Map.Entry; |
Jeff Sharkey | 84f1294 | 2014-07-10 17:48:11 -0700 | [diff] [blame] | 123 | import java.util.Objects; |
Dianne Hackborn | 6309271 | 2012-10-07 14:45:35 -0700 | [diff] [blame] | 124 | import java.util.Set; |
Kenny Root | 62539e9 | 2011-11-10 09:35:38 -0800 | [diff] [blame] | 125 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 126 | /** |
| 127 | * Holds information about dynamic settings. |
| 128 | */ |
Todd Kennedy | 91a39d1 | 2017-09-27 12:37:04 -0700 | [diff] [blame] | 129 | public final class Settings { |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 130 | private static final String TAG = "PackageSettings"; |
| 131 | |
Kenny Root | c1c0d3c | 2014-04-24 13:36:40 -0700 | [diff] [blame] | 132 | /** |
| 133 | * Current version of the package database. Set it to the latest version in |
| 134 | * the {@link DatabaseVersion} class below to ensure the database upgrade |
| 135 | * doesn't happen repeatedly. |
| 136 | * <p> |
| 137 | * Note that care should be taken to make sure all database upgrades are |
| 138 | * idempotent. |
| 139 | */ |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 140 | public static final int CURRENT_DATABASE_VERSION = DatabaseVersion.SIGNATURE_MALFORMED_RECOVER; |
Kenny Root | c1c0d3c | 2014-04-24 13:36:40 -0700 | [diff] [blame] | 141 | |
| 142 | /** |
| 143 | * This class contains constants that can be referred to from upgrade code. |
| 144 | * Insert constant values here that describe the upgrade reason. The version |
| 145 | * code must be monotonically increasing. |
| 146 | */ |
| 147 | public static class DatabaseVersion { |
| 148 | /** |
| 149 | * The initial version of the database. |
| 150 | */ |
| 151 | public static final int FIRST_VERSION = 1; |
Kenny Root | a8e65fd | 2014-04-24 11:44:47 -0700 | [diff] [blame] | 152 | |
| 153 | /** |
| 154 | * Migrating the Signature array from the entire certificate chain to |
| 155 | * just the signing certificate. |
| 156 | */ |
| 157 | public static final int SIGNATURE_END_ENTITY = 2; |
Jeff Sharkey | d68b87c | 2014-11-12 12:18:11 -0800 | [diff] [blame] | 158 | |
| 159 | /** |
| 160 | * There was a window of time in |
| 161 | * {@link android.os.Build.VERSION_CODES#LOLLIPOP} where we persisted |
| 162 | * certificates after potentially mutating them. To switch back to the |
| 163 | * original untouched certificates, we need to force a collection pass. |
| 164 | */ |
| 165 | public static final int SIGNATURE_MALFORMED_RECOVER = 3; |
Kenny Root | c1c0d3c | 2014-04-24 13:36:40 -0700 | [diff] [blame] | 166 | } |
| 167 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 168 | private static final boolean DEBUG_STOPPED = false; |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 169 | private static final boolean DEBUG_MU = false; |
Jeff Sharkey | 2271ba3 | 2016-02-01 17:57:08 -0700 | [diff] [blame] | 170 | private static final boolean DEBUG_KERNEL = false; |
Todd Kennedy | 788c842 | 2016-08-10 10:52:34 -0700 | [diff] [blame] | 171 | private static final boolean DEBUG_PARSER = false; |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 172 | |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 173 | private static final String RUNTIME_PERMISSIONS_FILE_NAME = "runtime-permissions.xml"; |
| 174 | |
Jeff Sharkey | edc84ee8 | 2012-03-19 16:52:26 -0700 | [diff] [blame] | 175 | private static final String TAG_READ_EXTERNAL_STORAGE = "read-external-storage"; |
| 176 | private static final String ATTR_ENFORCEMENT = "enforcement"; |
| 177 | |
Todd Kennedy | 91a39d1 | 2017-09-27 12:37:04 -0700 | [diff] [blame] | 178 | public static final String TAG_ITEM = "item"; |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 179 | private static final String TAG_DISABLED_COMPONENTS = "disabled-components"; |
| 180 | private static final String TAG_ENABLED_COMPONENTS = "enabled-components"; |
| 181 | private static final String TAG_PACKAGE_RESTRICTIONS = "package-restrictions"; |
| 182 | private static final String TAG_PACKAGE = "pkg"; |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 183 | private static final String TAG_SHARED_USER = "shared-user"; |
| 184 | private static final String TAG_RUNTIME_PERMISSIONS = "runtime-permissions"; |
| 185 | private static final String TAG_PERMISSIONS = "perms"; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 186 | private static final String TAG_CHILD_PACKAGE = "child-package"; |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 187 | private static final String TAG_USES_STATIC_LIB = "uses-static-lib"; |
Vladislav Kuzkokov | 253984e | 2016-10-24 09:27:16 +0200 | [diff] [blame] | 188 | private static final String TAG_BLOCK_UNINSTALL_PACKAGES = "block-uninstall-packages"; |
| 189 | private static final String TAG_BLOCK_UNINSTALL = "block-uninstall"; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 190 | |
Sander Alewijnse | af59762 | 2014-03-20 18:44:57 +0000 | [diff] [blame] | 191 | private static final String TAG_PERSISTENT_PREFERRED_ACTIVITIES = |
| 192 | "persistent-preferred-activities"; |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 193 | static final String TAG_CROSS_PROFILE_INTENT_FILTERS = |
| 194 | "crossProfile-intent-filters"; |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 195 | private static final String TAG_DOMAIN_VERIFICATION = "domain-verification"; |
| 196 | private static final String TAG_DEFAULT_APPS = "default-apps"; |
| 197 | private static final String TAG_ALL_INTENT_FILTER_VERIFICATION = |
Christopher Tate | 6038d15 | 2015-06-17 13:07:46 -0700 | [diff] [blame] | 198 | "all-intent-filter-verifications"; |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 199 | private static final String TAG_DEFAULT_BROWSER = "default-browser"; |
Robin Lee | 0dc591b | 2016-05-04 13:01:46 +0100 | [diff] [blame] | 200 | private static final String TAG_DEFAULT_DIALER = "default-dialer"; |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 201 | private static final String TAG_VERSION = "version"; |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 202 | |
Todd Kennedy | 91a39d1 | 2017-09-27 12:37:04 -0700 | [diff] [blame] | 203 | public static final String ATTR_NAME = "name"; |
| 204 | public static final String ATTR_PACKAGE = "package"; |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 205 | private static final String ATTR_USER = "user"; |
| 206 | private static final String ATTR_CODE = "code"; |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 207 | private static final String ATTR_GRANTED = "granted"; |
| 208 | private static final String ATTR_FLAGS = "flags"; |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 209 | private static final String ATTR_VERSION = "version"; |
Jeff Sharkey | 4288419 | 2016-04-09 16:12:01 -0600 | [diff] [blame] | 210 | |
| 211 | private static final String ATTR_CE_DATA_INODE = "ceDataInode"; |
| 212 | private static final String ATTR_INSTALLED = "inst"; |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 213 | private static final String ATTR_STOPPED = "stopped"; |
Jeff Sharkey | 4288419 | 2016-04-09 16:12:01 -0600 | [diff] [blame] | 214 | private static final String ATTR_NOT_LAUNCHED = "nl"; |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 215 | // Legacy, here for reading older versions of the package-restrictions. |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 216 | private static final String ATTR_BLOCKED = "blocked"; |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 217 | // New name for the above attribute. |
| 218 | private static final String ATTR_HIDDEN = "hidden"; |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 219 | private static final String ATTR_SUSPENDED = "suspended"; |
Vladislav Kuzkokov | 253984e | 2016-10-24 09:27:16 +0200 | [diff] [blame] | 220 | // Legacy, uninstall blocks are stored separately. |
| 221 | @Deprecated |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 222 | private static final String ATTR_BLOCK_UNINSTALL = "blockUninstall"; |
Jeff Sharkey | 4288419 | 2016-04-09 16:12:01 -0600 | [diff] [blame] | 223 | private static final String ATTR_ENABLED = "enabled"; |
| 224 | private static final String ATTR_ENABLED_CALLER = "enabledCaller"; |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 225 | private static final String ATTR_DOMAIN_VERIFICATON_STATE = "domainVerificationStatus"; |
Jeff Sharkey | 4288419 | 2016-04-09 16:12:01 -0600 | [diff] [blame] | 226 | private static final String ATTR_APP_LINK_GENERATION = "app-link-generation"; |
Bartosz Fabianowski | a34f53f | 2017-01-11 18:08:47 +0100 | [diff] [blame] | 227 | private static final String ATTR_INSTALL_REASON = "install-reason"; |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 228 | private static final String ATTR_INSTANT_APP = "instant-app"; |
Todd Kennedy | 5eb5a7d | 2017-08-01 07:42:47 -0700 | [diff] [blame] | 229 | private static final String ATTR_VIRTUAL_PRELOAD = "virtual-preload"; |
Jeff Sharkey | 4288419 | 2016-04-09 16:12:01 -0600 | [diff] [blame] | 230 | |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 231 | private static final String ATTR_PACKAGE_NAME = "packageName"; |
Svet Ganov | ba3ba81 | 2015-06-26 10:54:06 -0700 | [diff] [blame] | 232 | private static final String ATTR_FINGERPRINT = "fingerprint"; |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 233 | private static final String ATTR_VOLUME_UUID = "volumeUuid"; |
| 234 | private static final String ATTR_SDK_VERSION = "sdkVersion"; |
| 235 | private static final String ATTR_DATABASE_VERSION = "databaseVersion"; |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 236 | |
Christopher Tate | e9fd1fa | 2015-09-15 16:43:07 -0700 | [diff] [blame] | 237 | // Bookkeeping for restored permission grants |
| 238 | private static final String TAG_RESTORED_RUNTIME_PERMISSIONS = "restored-perms"; |
| 239 | // package name: ATTR_PACKAGE_NAME |
| 240 | private static final String TAG_PERMISSION_ENTRY = "perm"; |
| 241 | // permission name: ATTR_NAME |
| 242 | // permission granted (boolean): ATTR_GRANTED |
| 243 | private static final String ATTR_USER_SET = "set"; |
| 244 | private static final String ATTR_USER_FIXED = "fixed"; |
| 245 | private static final String ATTR_REVOKE_ON_UPGRADE = "rou"; |
| 246 | |
| 247 | // Flag mask of restored permission grants that are applied at install time |
| 248 | private static final int USER_RUNTIME_GRANT_MASK = |
| 249 | FLAG_PERMISSION_USER_SET |
| 250 | | FLAG_PERMISSION_USER_FIXED |
| 251 | | FLAG_PERMISSION_REVOKE_ON_UPGRADE; |
| 252 | |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 253 | private final Object mLock; |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 254 | |
| 255 | private final RuntimePermissionPersistence mRuntimePermissionsPersistence; |
| 256 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 257 | private final File mSettingsFilename; |
| 258 | private final File mBackupSettingsFilename; |
| 259 | private final File mPackageListFilename; |
| 260 | private final File mStoppedPackagesFilename; |
| 261 | private final File mBackupStoppedPackagesFilename; |
Amith Yamasani | 23ab7f5 | 2017-01-22 17:43:24 -0800 | [diff] [blame] | 262 | /** The top level directory in configfs for sdcardfs to push the package->uid,userId mappings */ |
Jeff Sharkey | 2271ba3 | 2016-02-01 17:57:08 -0700 | [diff] [blame] | 263 | private final File mKernelMappingFilename; |
Jeff Sharkey | 184a010 | 2013-07-10 16:19:52 -0700 | [diff] [blame] | 264 | |
Jeff Sharkey | 2271ba3 | 2016-02-01 17:57:08 -0700 | [diff] [blame] | 265 | /** Map from package name to settings */ |
| 266 | final ArrayMap<String, PackageSetting> mPackages = new ArrayMap<>(); |
| 267 | |
Sudheer Shanka | 2928337 | 2016-04-04 20:56:27 -0700 | [diff] [blame] | 268 | /** List of packages that installed other packages */ |
| 269 | final ArraySet<String> mInstallerPackages = new ArraySet<>(); |
| 270 | |
Amith Yamasani | 23ab7f5 | 2017-01-22 17:43:24 -0800 | [diff] [blame] | 271 | /** Map from package name to appId and excluded userids */ |
| 272 | private final ArrayMap<String, KernelPackageState> mKernelMapping = new ArrayMap<>(); |
Christopher Tate | 6038d15 | 2015-06-17 13:07:46 -0700 | [diff] [blame] | 273 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 274 | // List of replaced system applications |
Jeff Sharkey | 9f837a9 | 2014-10-24 12:07:24 -0700 | [diff] [blame] | 275 | private final ArrayMap<String, PackageSetting> mDisabledSysPackages = |
| 276 | new ArrayMap<String, PackageSetting>(); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 277 | |
Vladislav Kuzkokov | 253984e | 2016-10-24 09:27:16 +0200 | [diff] [blame] | 278 | /** List of packages that are blocked for uninstall for specific users */ |
| 279 | private final SparseArray<ArraySet<String>> mBlockUninstallPackages = new SparseArray<>(); |
| 280 | |
Christopher Tate | 6038d15 | 2015-06-17 13:07:46 -0700 | [diff] [blame] | 281 | // Set of restored intent-filter verification states |
| 282 | private final ArrayMap<String, IntentFilterVerificationInfo> mRestoredIntentFilterVerifications = |
| 283 | new ArrayMap<String, IntentFilterVerificationInfo>(); |
| 284 | |
Amith Yamasani | 23ab7f5 | 2017-01-22 17:43:24 -0800 | [diff] [blame] | 285 | private static final class KernelPackageState { |
| 286 | int appId; |
| 287 | int[] excludedUserIds; |
| 288 | } |
| 289 | |
Christopher Tate | e9fd1fa | 2015-09-15 16:43:07 -0700 | [diff] [blame] | 290 | // Bookkeeping for restored user permission grants |
| 291 | final class RestoredPermissionGrant { |
| 292 | String permissionName; |
| 293 | boolean granted; |
| 294 | int grantBits; |
| 295 | |
| 296 | RestoredPermissionGrant(String name, boolean isGranted, int theGrantBits) { |
| 297 | permissionName = name; |
| 298 | granted = isGranted; |
| 299 | grantBits = theGrantBits; |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | // This would be more compact as a flat array of restored grants or something, but we |
| 304 | // may have quite a few, especially during early device lifetime, and avoiding all those |
| 305 | // linear lookups will be important. |
| 306 | private final SparseArray<ArrayMap<String, ArraySet<RestoredPermissionGrant>>> |
| 307 | mRestoredUserGrants = |
| 308 | new SparseArray<ArrayMap<String, ArraySet<RestoredPermissionGrant>>>(); |
| 309 | |
Geremy Condra | 12c1838 | 2013-03-06 16:49:06 -0800 | [diff] [blame] | 310 | private static int mFirstAvailableUid = 0; |
| 311 | |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 312 | /** Map from volume UUID to {@link VersionInfo} */ |
| 313 | private ArrayMap<String, VersionInfo> mVersion = new ArrayMap<>(); |
Kenny Root | 0aaa0d9 | 2011-09-12 16:42:55 -0700 | [diff] [blame] | 314 | |
Kenny Root | c1c0d3c | 2014-04-24 13:36:40 -0700 | [diff] [blame] | 315 | /** |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 316 | * Version details for a storage volume that may hold apps. |
Kenny Root | c1c0d3c | 2014-04-24 13:36:40 -0700 | [diff] [blame] | 317 | */ |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 318 | public static class VersionInfo { |
| 319 | /** |
| 320 | * These are the last platform API version we were using for the apps |
| 321 | * installed on internal and external storage. It is used to grant newer |
| 322 | * permissions one time during a system upgrade. |
| 323 | */ |
| 324 | int sdkVersion; |
Kenny Root | c1c0d3c | 2014-04-24 13:36:40 -0700 | [diff] [blame] | 325 | |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 326 | /** |
| 327 | * The current database version for apps on internal storage. This is |
| 328 | * used to upgrade the format of the packages.xml database not |
| 329 | * necessarily tied to an SDK version. |
| 330 | */ |
| 331 | int databaseVersion; |
| 332 | |
| 333 | /** |
| 334 | * Last known value of {@link Build#FINGERPRINT}. Used to determine when |
| 335 | * an system update has occurred, meaning we need to clear code caches. |
| 336 | */ |
| 337 | String fingerprint; |
| 338 | |
| 339 | /** |
| 340 | * Force all version information to match current system values, |
| 341 | * typically after resolving any required upgrade steps. |
| 342 | */ |
| 343 | public void forceCurrent() { |
| 344 | sdkVersion = Build.VERSION.SDK_INT; |
| 345 | databaseVersion = CURRENT_DATABASE_VERSION; |
| 346 | fingerprint = Build.FINGERPRINT; |
| 347 | } |
| 348 | } |
Jeff Sharkey | 4ed745d | 2014-07-15 20:39:15 -0700 | [diff] [blame] | 349 | |
Jeff Sharkey | f538577 | 2012-05-11 14:04:41 -0700 | [diff] [blame] | 350 | Boolean mReadExternalStorageEnforced; |
Jeff Sharkey | edc84ee8 | 2012-03-19 16:52:26 -0700 | [diff] [blame] | 351 | |
Kenny Root | 0aaa0d9 | 2011-09-12 16:42:55 -0700 | [diff] [blame] | 352 | /** Device identity for the purpose of package verification. */ |
| 353 | private VerifierDeviceIdentity mVerifierDeviceIdentity; |
| 354 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 355 | // The user's preferred activities associated with particular intent |
| 356 | // filters. |
Dianne Hackborn | 6309271 | 2012-10-07 14:45:35 -0700 | [diff] [blame] | 357 | final SparseArray<PreferredIntentResolver> mPreferredActivities = |
| 358 | new SparseArray<PreferredIntentResolver>(); |
| 359 | |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 360 | // The persistent preferred activities of the user's profile/device owner |
| 361 | // associated with particular intent filters. |
| 362 | final SparseArray<PersistentPreferredIntentResolver> mPersistentPreferredActivities = |
| 363 | new SparseArray<PersistentPreferredIntentResolver>(); |
| 364 | |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 365 | // For every user, it is used to find to which other users the intent can be forwarded. |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 366 | final SparseArray<CrossProfileIntentResolver> mCrossProfileIntentResolvers = |
| 367 | new SparseArray<CrossProfileIntentResolver>(); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 368 | |
Jeff Sharkey | 9f837a9 | 2014-10-24 12:07:24 -0700 | [diff] [blame] | 369 | final ArrayMap<String, SharedUserSetting> mSharedUsers = |
| 370 | new ArrayMap<String, SharedUserSetting>(); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 371 | private final ArrayList<Object> mUserIds = new ArrayList<Object>(); |
| 372 | private final SparseArray<Object> mOtherUserIds = |
| 373 | new SparseArray<Object>(); |
| 374 | |
| 375 | // For reading/writing settings file. |
| 376 | private final ArrayList<Signature> mPastSignatures = |
| 377 | new ArrayList<Signature>(); |
dcashman | 8c04fac | 2015-03-23 11:39:42 -0700 | [diff] [blame] | 378 | private final ArrayMap<Long, Integer> mKeySetRefs = |
| 379 | new ArrayMap<Long, Integer>(); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 380 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 381 | // Packages that have been uninstalled and still need their external |
| 382 | // storage data deleted. |
Jeff Sharkey | 752cd92 | 2012-09-23 16:25:12 -0700 | [diff] [blame] | 383 | final ArrayList<PackageCleanItem> mPackagesToBeCleaned = new ArrayList<PackageCleanItem>(); |
Selim Gurun | 5c8acb4 | 2016-04-07 16:34:02 -0700 | [diff] [blame] | 384 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 385 | // Packages that have been renamed since they were first installed. |
| 386 | // Keys are the new names of the packages, values are the original |
Todd Kennedy | 13715d5 | 2016-08-01 13:38:57 -0700 | [diff] [blame] | 387 | // names. The packages appear everywhere else under their original |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 388 | // names. |
Todd Kennedy | 13715d5 | 2016-08-01 13:38:57 -0700 | [diff] [blame] | 389 | private final ArrayMap<String, String> mRenamedPackages = new ArrayMap<String, String>(); |
Fabrice Di Meglio | 6227172 | 2015-04-10 17:24:02 -0700 | [diff] [blame] | 390 | |
| 391 | // For every user, it is used to find the package name of the default Browser App. |
| 392 | final SparseArray<String> mDefaultBrowserApp = new SparseArray<String>(); |
| 393 | |
Robin Lee | 0dc591b | 2016-05-04 13:01:46 +0100 | [diff] [blame] | 394 | // For every user, a record of the package name of the default Dialer App. |
| 395 | final SparseArray<String> mDefaultDialerApp = new SparseArray<String>(); |
| 396 | |
Christopher Tate | f0d6cb3 | 2015-07-10 17:44:53 -0700 | [diff] [blame] | 397 | // App-link priority tracking, per-user |
| 398 | final SparseIntArray mNextAppLinkGeneration = new SparseIntArray(); |
| 399 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 400 | final StringBuilder mReadMessages = new StringBuilder(); |
| 401 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 402 | /** |
| 403 | * Used to track packages that have a shared user ID that hasn't been read |
| 404 | * in yet. |
| 405 | * <p> |
| 406 | * TODO: make this just a local variable that is passed in during package |
| 407 | * scanning to make it less confusing. |
| 408 | */ |
Todd Kennedy | 788c842 | 2016-08-10 10:52:34 -0700 | [diff] [blame] | 409 | private final ArrayList<PackageSetting> mPendingPackages = new ArrayList<>(); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 410 | |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 411 | private final File mSystemDir; |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 412 | |
dcashman | 55b1078 | 2014-04-09 14:20:38 -0700 | [diff] [blame] | 413 | public final KeySetManagerService mKeySetManagerService = new KeySetManagerService(mPackages); |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 414 | /** Settings and other information about permissions */ |
Todd Kennedy | c842393 | 2017-10-05 08:58:36 -0700 | [diff] [blame] | 415 | final PermissionSettings mPermissions; |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 416 | |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 417 | Settings(PermissionSettings permissions, Object lock) { |
| 418 | this(Environment.getDataDirectory(), permissions, lock); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 419 | } |
| 420 | |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 421 | Settings(File dataDir, PermissionSettings permission, Object lock) { |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 422 | mLock = lock; |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 423 | mPermissions = permission; |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 424 | mRuntimePermissionsPersistence = new RuntimePermissionPersistence(mLock); |
| 425 | |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 426 | mSystemDir = new File(dataDir, "system"); |
| 427 | mSystemDir.mkdirs(); |
| 428 | FileUtils.setPermissions(mSystemDir.toString(), |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 429 | FileUtils.S_IRWXU|FileUtils.S_IRWXG |
| 430 | |FileUtils.S_IROTH|FileUtils.S_IXOTH, |
| 431 | -1, -1); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 432 | mSettingsFilename = new File(mSystemDir, "packages.xml"); |
| 433 | mBackupSettingsFilename = new File(mSystemDir, "packages-backup.xml"); |
| 434 | mPackageListFilename = new File(mSystemDir, "packages.list"); |
Jeff Sharkey | aebb65c | 2014-11-24 15:00:13 -0800 | [diff] [blame] | 435 | FileUtils.setPermissions(mPackageListFilename, 0640, SYSTEM_UID, PACKAGE_INFO_GID); |
Jeff Sharkey | 184a010 | 2013-07-10 16:19:52 -0700 | [diff] [blame] | 436 | |
Jeff Sharkey | 2271ba3 | 2016-02-01 17:57:08 -0700 | [diff] [blame] | 437 | final File kernelDir = new File("/config/sdcardfs"); |
| 438 | mKernelMappingFilename = kernelDir.exists() ? kernelDir : null; |
| 439 | |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 440 | // Deprecated: Needed for migration |
| 441 | mStoppedPackagesFilename = new File(mSystemDir, "packages-stopped.xml"); |
| 442 | mBackupStoppedPackagesFilename = new File(mSystemDir, "packages-stopped-backup.xml"); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 443 | } |
| 444 | |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 445 | PackageSetting getPackageLPr(String pkgName) { |
Todd Kennedy | 13715d5 | 2016-08-01 13:38:57 -0700 | [diff] [blame] | 446 | return mPackages.get(pkgName); |
| 447 | } |
| 448 | |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 449 | String getRenamedPackageLPr(String pkgName) { |
Todd Kennedy | 13715d5 | 2016-08-01 13:38:57 -0700 | [diff] [blame] | 450 | return mRenamedPackages.get(pkgName); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 451 | } |
| 452 | |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 453 | String addRenamedPackageLPw(String pkgName, String origPkgName) { |
| 454 | return mRenamedPackages.put(pkgName, origPkgName); |
| 455 | } |
| 456 | |
Christopher Tate | e9fd1fa | 2015-09-15 16:43:07 -0700 | [diff] [blame] | 457 | void setInstallStatus(String pkgName, final int status) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 458 | PackageSetting p = mPackages.get(pkgName); |
| 459 | if(p != null) { |
| 460 | if(p.getInstallStatus() != status) { |
| 461 | p.setInstallStatus(status); |
| 462 | } |
| 463 | } |
| 464 | } |
| 465 | |
Christopher Tate | e9fd1fa | 2015-09-15 16:43:07 -0700 | [diff] [blame] | 466 | void applyPendingPermissionGrantsLPw(String packageName, int userId) { |
| 467 | ArrayMap<String, ArraySet<RestoredPermissionGrant>> grantsByPackage = |
| 468 | mRestoredUserGrants.get(userId); |
| 469 | if (grantsByPackage == null || grantsByPackage.size() == 0) { |
| 470 | return; |
| 471 | } |
| 472 | |
| 473 | ArraySet<RestoredPermissionGrant> grants = grantsByPackage.get(packageName); |
| 474 | if (grants == null || grants.size() == 0) { |
| 475 | return; |
| 476 | } |
| 477 | |
| 478 | final PackageSetting ps = mPackages.get(packageName); |
| 479 | if (ps == null) { |
| 480 | Slog.e(TAG, "Can't find supposedly installed package " + packageName); |
| 481 | return; |
| 482 | } |
| 483 | final PermissionsState perms = ps.getPermissionsState(); |
| 484 | |
| 485 | for (RestoredPermissionGrant grant : grants) { |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 486 | BasePermission bp = mPermissions.getPermission(grant.permissionName); |
Christopher Tate | e9fd1fa | 2015-09-15 16:43:07 -0700 | [diff] [blame] | 487 | if (bp != null) { |
| 488 | if (grant.granted) { |
| 489 | perms.grantRuntimePermission(bp, userId); |
| 490 | } |
| 491 | perms.updatePermissionFlags(bp, userId, USER_RUNTIME_GRANT_MASK, grant.grantBits); |
| 492 | } |
| 493 | } |
| 494 | |
| 495 | // And remove it from the pending-grant bookkeeping |
| 496 | grantsByPackage.remove(packageName); |
| 497 | if (grantsByPackage.size() < 1) { |
| 498 | mRestoredUserGrants.remove(userId); |
| 499 | } |
| 500 | writeRuntimePermissionsForUserLPr(userId, false); |
| 501 | } |
| 502 | |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 503 | public boolean canPropagatePermissionToInstantApp(String permName) { |
| 504 | return mPermissions.canPropagatePermissionToInstantApp(permName); |
| 505 | } |
| 506 | |
Jeff Sharkey | b2b9ab8 | 2015-04-05 21:10:42 -0700 | [diff] [blame] | 507 | void setInstallerPackageName(String pkgName, String installerPkgName) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 508 | PackageSetting p = mPackages.get(pkgName); |
Jeff Sharkey | b2b9ab8 | 2015-04-05 21:10:42 -0700 | [diff] [blame] | 509 | if (p != null) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 510 | p.setInstallerPackageName(installerPkgName); |
Sudheer Shanka | 2928337 | 2016-04-04 20:56:27 -0700 | [diff] [blame] | 511 | if (installerPkgName != null) { |
| 512 | mInstallerPackages.add(installerPkgName); |
| 513 | } |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 514 | } |
| 515 | } |
| 516 | |
Todd Kennedy | 13715d5 | 2016-08-01 13:38:57 -0700 | [diff] [blame] | 517 | /** Gets and optionally creates a new shared user id. */ |
Todd Kennedy | ff35e66 | 2016-09-20 12:53:52 -0700 | [diff] [blame] | 518 | SharedUserSetting getSharedUserLPw(String name, int pkgFlags, int pkgPrivateFlags, |
| 519 | boolean create) throws PackageManagerException { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 520 | SharedUserSetting s = mSharedUsers.get(name); |
Todd Kennedy | ff35e66 | 2016-09-20 12:53:52 -0700 | [diff] [blame] | 521 | if (s == null && create) { |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 522 | s = new SharedUserSetting(name, pkgFlags, pkgPrivateFlags); |
Dianne Hackborn | 21fbd1f | 2012-02-10 10:38:10 -0800 | [diff] [blame] | 523 | s.userId = newUserIdLPw(s); |
Todd Kennedy | ff35e66 | 2016-09-20 12:53:52 -0700 | [diff] [blame] | 524 | if (s.userId < 0) { |
| 525 | // < 0 means we couldn't assign a userid; throw exception |
| 526 | throw new PackageManagerException(INSTALL_FAILED_INSUFFICIENT_STORAGE, |
| 527 | "Creating shared user " + name + " failed"); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 528 | } |
Todd Kennedy | ff35e66 | 2016-09-20 12:53:52 -0700 | [diff] [blame] | 529 | Log.i(PackageManagerService.TAG, "New shared user " + name + ": id=" + s.userId); |
| 530 | mSharedUsers.put(name, s); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 531 | } |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 532 | return s; |
| 533 | } |
| 534 | |
Narayan Kamath | df6d6dc | 2014-04-28 14:18:34 +0100 | [diff] [blame] | 535 | Collection<SharedUserSetting> getAllSharedUsersLPw() { |
| 536 | return mSharedUsers.values(); |
| 537 | } |
| 538 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 539 | boolean disableSystemPackageLPw(String name, boolean replaced) { |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 540 | final PackageSetting p = mPackages.get(name); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 541 | if(p == null) { |
Jeff Sharkey | e06b4d1 | 2016-01-06 14:51:50 -0700 | [diff] [blame] | 542 | Log.w(PackageManagerService.TAG, "Package " + name + " is not an installed package"); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 543 | return false; |
| 544 | } |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 545 | final PackageSetting dp = mDisabledSysPackages.get(name); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 546 | // always make sure the system package code and resource paths dont change |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 547 | if (dp == null && p.pkg != null && p.pkg.isSystem() && !p.pkg.isUpdatedSystemApp()) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 548 | if((p.pkg != null) && (p.pkg.applicationInfo != null)) { |
| 549 | p.pkg.applicationInfo.flags |= ApplicationInfo.FLAG_UPDATED_SYSTEM_APP; |
| 550 | } |
| 551 | mDisabledSysPackages.put(name, p); |
| 552 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 553 | if (replaced) { |
| 554 | // a little trick... when we install the new package, we don't |
| 555 | // want to modify the existing PackageSetting for the built-in |
| 556 | // version. so at this point we need a new PackageSetting that |
| 557 | // is okay to muck with. |
| 558 | PackageSetting newp = new PackageSetting(p); |
| 559 | replacePackageLPw(name, newp); |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 560 | } |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 561 | return true; |
| 562 | } |
| 563 | return false; |
| 564 | } |
| 565 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 566 | PackageSetting enableSystemPackageLPw(String name) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 567 | PackageSetting p = mDisabledSysPackages.get(name); |
| 568 | if(p == null) { |
Jeff Sharkey | e06b4d1 | 2016-01-06 14:51:50 -0700 | [diff] [blame] | 569 | Log.w(PackageManagerService.TAG, "Package " + name + " is not disabled"); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 570 | return null; |
| 571 | } |
| 572 | // Reset flag in ApplicationInfo object |
| 573 | if((p.pkg != null) && (p.pkg.applicationInfo != null)) { |
| 574 | p.pkg.applicationInfo.flags &= ~ApplicationInfo.FLAG_UPDATED_SYSTEM_APP; |
| 575 | } |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 576 | PackageSetting ret = addPackageLPw(name, p.realName, p.codePath, p.resourcePath, |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 577 | p.legacyNativeLibraryPathString, p.primaryCpuAbiString, |
Selim Gurun | 5c8acb4 | 2016-04-07 16:34:02 -0700 | [diff] [blame] | 578 | p.secondaryCpuAbiString, p.cpuAbiOverrideString, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 579 | p.appId, p.versionCode, p.pkgFlags, p.pkgPrivateFlags, |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 580 | p.parentPackageName, p.childPackageNames, p.usesStaticLibraries, |
| 581 | p.usesStaticLibrariesVersions); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 582 | mDisabledSysPackages.remove(name); |
| 583 | return ret; |
| 584 | } |
| 585 | |
Kenny Root | c52d6fd | 2012-05-07 23:04:52 -0700 | [diff] [blame] | 586 | boolean isDisabledSystemPackageLPr(String name) { |
| 587 | return mDisabledSysPackages.containsKey(name); |
| 588 | } |
| 589 | |
| 590 | void removeDisabledSystemPackageLPw(String name) { |
| 591 | mDisabledSysPackages.remove(name); |
| 592 | } |
| 593 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 594 | PackageSetting addPackageLPw(String name, String realName, File codePath, File resourcePath, |
Svet Ganov | f4ff39c | 2016-02-04 14:27:05 -0800 | [diff] [blame] | 595 | String legacyNativeLibraryPathString, String primaryCpuAbiString, |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 596 | String secondaryCpuAbiString, String cpuAbiOverrideString, int uid, long vc, int |
Svet Ganov | f4ff39c | 2016-02-04 14:27:05 -0800 | [diff] [blame] | 597 | pkgFlags, int pkgPrivateFlags, String parentPackageName, |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 598 | List<String> childPackageNames, String[] usesStaticLibraries, |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 599 | long[] usesStaticLibraryNames) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 600 | PackageSetting p = mPackages.get(name); |
| 601 | if (p != null) { |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 602 | if (p.appId == uid) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 603 | return p; |
| 604 | } |
| 605 | PackageManagerService.reportSettingsProblem(Log.ERROR, |
| 606 | "Adding duplicate package, keeping first: " + name); |
| 607 | return null; |
| 608 | } |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 609 | p = new PackageSetting(name, realName, codePath, resourcePath, |
Narayan Kamath | 4903f64 | 2014-08-11 13:33:45 +0100 | [diff] [blame] | 610 | legacyNativeLibraryPathString, primaryCpuAbiString, secondaryCpuAbiString, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 611 | cpuAbiOverrideString, vc, pkgFlags, pkgPrivateFlags, parentPackageName, |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 612 | childPackageNames, 0 /*userId*/, usesStaticLibraries, usesStaticLibraryNames); |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 613 | p.appId = uid; |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 614 | if (addUserIdLPw(uid, p, name)) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 615 | mPackages.put(name, p); |
| 616 | return p; |
| 617 | } |
| 618 | return null; |
| 619 | } |
| 620 | |
Todd Kennedy | c842393 | 2017-10-05 08:58:36 -0700 | [diff] [blame] | 621 | void addAppOpPackage(String permName, String packageName) { |
| 622 | mPermissions.addAppOpPackage(permName, packageName); |
| 623 | } |
| 624 | |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 625 | SharedUserSetting addSharedUserLPw(String name, int uid, int pkgFlags, int pkgPrivateFlags) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 626 | SharedUserSetting s = mSharedUsers.get(name); |
| 627 | if (s != null) { |
| 628 | if (s.userId == uid) { |
| 629 | return s; |
| 630 | } |
| 631 | PackageManagerService.reportSettingsProblem(Log.ERROR, |
| 632 | "Adding duplicate shared user, keeping first: " + name); |
| 633 | return null; |
| 634 | } |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 635 | s = new SharedUserSetting(name, pkgFlags, pkgPrivateFlags); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 636 | s.userId = uid; |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 637 | if (addUserIdLPw(uid, s, name)) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 638 | mSharedUsers.put(name, s); |
| 639 | return s; |
| 640 | } |
| 641 | return null; |
| 642 | } |
| 643 | |
Christopher Tate | 86b391c | 2013-09-13 16:58:36 -0700 | [diff] [blame] | 644 | void pruneSharedUsersLPw() { |
| 645 | ArrayList<String> removeStage = new ArrayList<String>(); |
| 646 | for (Map.Entry<String,SharedUserSetting> entry : mSharedUsers.entrySet()) { |
| 647 | final SharedUserSetting sus = entry.getValue(); |
Todd Kennedy | 68f6715 | 2015-10-21 13:09:10 -0700 | [diff] [blame] | 648 | if (sus == null) { |
| 649 | removeStage.add(entry.getKey()); |
| 650 | continue; |
| 651 | } |
| 652 | // remove packages that are no longer installed |
| 653 | for (Iterator<PackageSetting> iter = sus.packages.iterator(); iter.hasNext();) { |
| 654 | PackageSetting ps = iter.next(); |
| 655 | if (mPackages.get(ps.name) == null) { |
| 656 | iter.remove(); |
| 657 | } |
| 658 | } |
| 659 | if (sus.packages.size() == 0) { |
Christopher Tate | 86b391c | 2013-09-13 16:58:36 -0700 | [diff] [blame] | 660 | removeStage.add(entry.getKey()); |
| 661 | } |
| 662 | } |
| 663 | for (int i = 0; i < removeStage.size(); i++) { |
| 664 | mSharedUsers.remove(removeStage.get(i)); |
| 665 | } |
| 666 | } |
| 667 | |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 668 | /** |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 669 | * Creates a new {@code PackageSetting} object. |
| 670 | * Use this method instead of the constructor to ensure a settings object is created |
| 671 | * with the correct base. |
Todd Kennedy | 13715d5 | 2016-08-01 13:38:57 -0700 | [diff] [blame] | 672 | */ |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 673 | static @NonNull PackageSetting createNewSetting(String pkgName, PackageSetting originalPkg, |
| 674 | PackageSetting disabledPkg, String realPkgName, SharedUserSetting sharedUser, |
| 675 | File codePath, File resourcePath, String legacyNativeLibraryPath, String primaryCpuAbi, |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 676 | String secondaryCpuAbi, long versionCode, int pkgFlags, int pkgPrivateFlags, |
Todd Kennedy | 5eb5a7d | 2017-08-01 07:42:47 -0700 | [diff] [blame] | 677 | UserHandle installUser, boolean allowInstall, boolean instantApp, |
| 678 | boolean virtualPreload, String parentPkgName, List<String> childPkgNames, |
| 679 | UserManagerService userManager, |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 680 | String[] usesStaticLibraries, long[] usesStaticLibrariesVersions) { |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 681 | final PackageSetting pkgSetting; |
| 682 | if (originalPkg != null) { |
| 683 | if (PackageManagerService.DEBUG_UPGRADE) Log.v(PackageManagerService.TAG, "Package " |
| 684 | + pkgName + " is adopting original package " + originalPkg.name); |
| 685 | pkgSetting = new PackageSetting(originalPkg, pkgName /*realPkgName*/); |
| 686 | pkgSetting.childPackageNames = |
| 687 | (childPkgNames != null) ? new ArrayList<>(childPkgNames) : null; |
| 688 | pkgSetting.codePath = codePath; |
| 689 | pkgSetting.legacyNativeLibraryPathString = legacyNativeLibraryPath; |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 690 | pkgSetting.parentPackageName = parentPkgName; |
| 691 | pkgSetting.pkgFlags = pkgFlags; |
| 692 | pkgSetting.pkgPrivateFlags = pkgPrivateFlags; |
Todd Kennedy | 13715d5 | 2016-08-01 13:38:57 -0700 | [diff] [blame] | 693 | pkgSetting.primaryCpuAbiString = primaryCpuAbi; |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 694 | pkgSetting.resourcePath = resourcePath; |
Todd Kennedy | 13715d5 | 2016-08-01 13:38:57 -0700 | [diff] [blame] | 695 | pkgSetting.secondaryCpuAbiString = secondaryCpuAbi; |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 696 | // NOTE: Create a deeper copy of the package signatures so we don't |
| 697 | // overwrite the signatures in the original package setting. |
| 698 | pkgSetting.signatures = new PackageSignatures(); |
| 699 | pkgSetting.versionCode = versionCode; |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 700 | pkgSetting.usesStaticLibraries = usesStaticLibraries; |
| 701 | pkgSetting.usesStaticLibrariesVersions = usesStaticLibrariesVersions; |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 702 | // Update new package state. |
| 703 | pkgSetting.setTimeStamp(codePath.lastModified()); |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 704 | } else { |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 705 | pkgSetting = new PackageSetting(pkgName, realPkgName, codePath, resourcePath, |
| 706 | legacyNativeLibraryPath, primaryCpuAbi, secondaryCpuAbi, |
| 707 | null /*cpuAbiOverrideString*/, versionCode, pkgFlags, pkgPrivateFlags, |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 708 | parentPkgName, childPkgNames, 0 /*sharedUserId*/, usesStaticLibraries, |
| 709 | usesStaticLibrariesVersions); |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 710 | pkgSetting.setTimeStamp(codePath.lastModified()); |
| 711 | pkgSetting.sharedUser = sharedUser; |
| 712 | // If this is not a system app, it starts out stopped. |
| 713 | if ((pkgFlags&ApplicationInfo.FLAG_SYSTEM) == 0) { |
| 714 | if (DEBUG_STOPPED) { |
| 715 | RuntimeException e = new RuntimeException("here"); |
| 716 | e.fillInStackTrace(); |
| 717 | Slog.i(PackageManagerService.TAG, "Stopping package " + pkgName, e); |
| 718 | } |
Todd Kennedy | 13715d5 | 2016-08-01 13:38:57 -0700 | [diff] [blame] | 719 | List<UserInfo> users = getAllUsers(userManager); |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 720 | final int installUserId = installUser != null ? installUser.getIdentifier() : 0; |
| 721 | if (users != null && allowInstall) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 722 | for (UserInfo user : users) { |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 723 | // By default we consider this app to be installed |
| 724 | // for the user if no user has been specified (which |
| 725 | // means to leave it at its original value, and the |
| 726 | // original default value is true), or we are being |
| 727 | // asked to install for all users, or this is the |
| 728 | // user we are installing for. |
| 729 | final boolean installed = installUser == null |
| 730 | || (installUserId == UserHandle.USER_ALL |
Amith Yamasani | 8cd28b5 | 2014-06-08 17:54:27 -0700 | [diff] [blame] | 731 | && !isAdbInstallDisallowed(userManager, user.id)) |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 732 | || installUserId == user.id; |
| 733 | pkgSetting.setUserState(user.id, 0, COMPONENT_ENABLED_STATE_DEFAULT, |
| 734 | installed, |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 735 | true /*stopped*/, |
| 736 | true /*notLaunched*/, |
| 737 | false /*hidden*/, |
| 738 | false /*suspended*/, |
| 739 | instantApp, |
Todd Kennedy | 5eb5a7d | 2017-08-01 07:42:47 -0700 | [diff] [blame] | 740 | virtualPreload, |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 741 | null /*lastDisableAppCaller*/, |
| 742 | null /*enabledComponents*/, |
| 743 | null /*disabledComponents*/, |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 744 | INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_UNDEFINED, |
| 745 | 0, PackageManager.INSTALL_REASON_UNKNOWN); |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 746 | } |
| 747 | } |
| 748 | } |
| 749 | if (sharedUser != null) { |
| 750 | pkgSetting.appId = sharedUser.userId; |
| 751 | } else { |
| 752 | // Clone the setting here for disabled system packages |
| 753 | if (disabledPkg != null) { |
| 754 | // For disabled packages a new setting is created |
| 755 | // from the existing user id. This still has to be |
| 756 | // added to list of user id's |
| 757 | // Copy signatures from previous setting |
| 758 | pkgSetting.signatures = new PackageSignatures(disabledPkg.signatures); |
| 759 | pkgSetting.appId = disabledPkg.appId; |
| 760 | // Clone permissions |
| 761 | pkgSetting.getPermissionsState().copyFrom(disabledPkg.getPermissionsState()); |
| 762 | // Clone component info |
| 763 | List<UserInfo> users = getAllUsers(userManager); |
| 764 | if (users != null) { |
| 765 | for (UserInfo user : users) { |
| 766 | final int userId = user.id; |
| 767 | pkgSetting.setDisabledComponentsCopy( |
| 768 | disabledPkg.getDisabledComponents(userId), userId); |
| 769 | pkgSetting.setEnabledComponentsCopy( |
| 770 | disabledPkg.getEnabledComponents(userId), userId); |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 771 | } |
| 772 | } |
| 773 | } |
| 774 | } |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 775 | } |
Todd Kennedy | 13715d5 | 2016-08-01 13:38:57 -0700 | [diff] [blame] | 776 | return pkgSetting; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 777 | } |
| 778 | |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 779 | /** |
| 780 | * Updates the given package setting using the provided information. |
| 781 | * <p> |
| 782 | * WARNING: The provided PackageSetting object may be mutated. |
| 783 | */ |
| 784 | static void updatePackageSetting(@NonNull PackageSetting pkgSetting, |
| 785 | @Nullable PackageSetting disabledPkg, @Nullable SharedUserSetting sharedUser, |
| 786 | @NonNull File codePath, @Nullable String legacyNativeLibraryPath, |
| 787 | @Nullable String primaryCpuAbi, @Nullable String secondaryCpuAbi, |
| 788 | int pkgFlags, int pkgPrivateFlags, @Nullable List<String> childPkgNames, |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 789 | @NonNull UserManagerService userManager, @Nullable String[] usesStaticLibraries, |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 790 | @Nullable long[] usesStaticLibrariesVersions) throws PackageManagerException { |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 791 | final String pkgName = pkgSetting.name; |
| 792 | if (pkgSetting.sharedUser != sharedUser) { |
| 793 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 794 | "Package " + pkgName + " shared user changed from " |
| 795 | + (pkgSetting.sharedUser != null ? pkgSetting.sharedUser.name : "<nothing>") |
| 796 | + " to " + (sharedUser != null ? sharedUser.name : "<nothing>")); |
| 797 | throw new PackageManagerException(INSTALL_FAILED_SHARED_USER_INCOMPATIBLE, |
| 798 | "Updating application package " + pkgName + " failed"); |
| 799 | } |
| 800 | |
| 801 | if (!pkgSetting.codePath.equals(codePath)) { |
| 802 | // Check to see if its a disabled system app |
| 803 | if ((pkgSetting.pkgFlags & ApplicationInfo.FLAG_SYSTEM) != 0) { |
| 804 | // This is an updated system app with versions in both system |
| 805 | // and data partition. Just let the most recent version |
| 806 | // take precedence. |
| 807 | Slog.w(PackageManagerService.TAG, |
| 808 | "Trying to update system app code path from " |
| 809 | + pkgSetting.codePathString + " to " + codePath.toString()); |
| 810 | } else { |
| 811 | // Just a change in the code path is not an issue, but |
| 812 | // let's log a message about it. |
| 813 | Slog.i(PackageManagerService.TAG, |
| 814 | "Package " + pkgName + " codePath changed from " |
| 815 | + pkgSetting.codePath + " to " + codePath |
| 816 | + "; Retaining data and using new"); |
| 817 | |
| 818 | // The owner user's installed flag is set false |
| 819 | // when the application was installed by other user |
| 820 | // and the installed flag is not updated |
| 821 | // when the application is appended as system app later. |
| 822 | if ((pkgFlags & ApplicationInfo.FLAG_SYSTEM) != 0 |
| 823 | && disabledPkg == null) { |
| 824 | List<UserInfo> allUserInfos = getAllUsers(userManager); |
| 825 | if (allUserInfos != null) { |
| 826 | for (UserInfo userInfo : allUserInfos) { |
| 827 | pkgSetting.setInstalled(true, userInfo.id); |
| 828 | } |
| 829 | } |
| 830 | } |
| 831 | |
| 832 | /* |
| 833 | * Since we've changed paths, we need to prefer the new |
| 834 | * native library path over the one stored in the |
| 835 | * package settings since we might have moved from |
| 836 | * internal to external storage or vice versa. |
| 837 | */ |
| 838 | pkgSetting.legacyNativeLibraryPathString = legacyNativeLibraryPath; |
| 839 | } |
| 840 | } |
| 841 | // If what we are scanning is a system (and possibly privileged) package, |
| 842 | // then make it so, regardless of whether it was previously installed only |
| 843 | // in the data partition. |
| 844 | pkgSetting.pkgFlags |= pkgFlags & ApplicationInfo.FLAG_SYSTEM; |
| 845 | pkgSetting.pkgPrivateFlags |= |
| 846 | pkgPrivateFlags & ApplicationInfo.PRIVATE_FLAG_PRIVILEGED; |
Svet Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 847 | pkgSetting.pkgPrivateFlags |= |
| 848 | pkgPrivateFlags & ApplicationInfo.PRIVATE_FLAG_OEM; |
Jiyong Park | 002fdbd | 2017-02-13 20:50:31 +0900 | [diff] [blame] | 849 | pkgSetting.pkgPrivateFlags |= |
| 850 | pkgPrivateFlags & ApplicationInfo.PRIVATE_FLAG_VENDOR; |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 851 | pkgSetting.primaryCpuAbiString = primaryCpuAbi; |
| 852 | pkgSetting.secondaryCpuAbiString = secondaryCpuAbi; |
| 853 | if (childPkgNames != null) { |
| 854 | pkgSetting.childPackageNames = new ArrayList<>(childPkgNames); |
| 855 | } |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 856 | if (usesStaticLibraries != null) { |
| 857 | pkgSetting.usesStaticLibraries = Arrays.copyOf(usesStaticLibraries, |
| 858 | usesStaticLibraries.length); |
| 859 | } |
| 860 | if (usesStaticLibrariesVersions != null) { |
| 861 | pkgSetting.usesStaticLibrariesVersions = Arrays.copyOf(usesStaticLibrariesVersions, |
| 862 | usesStaticLibrariesVersions.length); |
| 863 | } |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 864 | } |
| 865 | |
| 866 | /** |
| 867 | * Registers a user ID with the system. Potentially allocates a new user ID. |
| 868 | * @throws PackageManagerException If a user ID could not be allocated. |
| 869 | */ |
| 870 | void addUserToSettingLPw(PackageSetting p) throws PackageManagerException { |
| 871 | if (p.appId == 0) { |
| 872 | // Assign new user ID |
| 873 | p.appId = newUserIdLPw(p); |
| 874 | } else { |
| 875 | // Add new setting to list of user IDs |
| 876 | addUserIdLPw(p.appId, p, p.name); |
| 877 | } |
| 878 | if (p.appId < 0) { |
| 879 | PackageManagerService.reportSettingsProblem(Log.WARN, |
Jeff Sharkey | f60d8ab | 2017-02-24 11:06:49 -0700 | [diff] [blame] | 880 | "Package " + p.name + " could not be assigned a valid UID"); |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 881 | throw new PackageManagerException(INSTALL_FAILED_INSUFFICIENT_STORAGE, |
Jeff Sharkey | f60d8ab | 2017-02-24 11:06:49 -0700 | [diff] [blame] | 882 | "Package " + p.name + " could not be assigned a valid UID"); |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 883 | } |
| 884 | } |
| 885 | |
| 886 | /** |
| 887 | * Writes per-user package restrictions if the user state has changed. If the user |
| 888 | * state has not changed, this does nothing. |
| 889 | */ |
Todd Kennedy | ff35e66 | 2016-09-20 12:53:52 -0700 | [diff] [blame] | 890 | void writeUserRestrictionsLPw(PackageSetting newPackage, PackageSetting oldPackage) { |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 891 | // package doesn't exist; do nothing |
Todd Kennedy | 8cad623 | 2016-10-06 11:27:07 -0700 | [diff] [blame] | 892 | if (getPackageLPr(newPackage.name) == null) { |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 893 | return; |
| 894 | } |
| 895 | // no users defined; do nothing |
| 896 | final List<UserInfo> allUsers = getAllUsers(UserManagerService.getInstance()); |
| 897 | if (allUsers == null) { |
| 898 | return; |
| 899 | } |
| 900 | for (UserInfo user : allUsers) { |
| 901 | final PackageUserState oldUserState = oldPackage == null |
| 902 | ? PackageSettingBase.DEFAULT_USER_STATE |
| 903 | : oldPackage.readUserState(user.id); |
| 904 | if (!oldUserState.equals(newPackage.readUserState(user.id))) { |
| 905 | writePackageRestrictionsLPr(user.id); |
| 906 | } |
| 907 | } |
| 908 | } |
| 909 | |
Todd Kennedy | 13715d5 | 2016-08-01 13:38:57 -0700 | [diff] [blame] | 910 | static boolean isAdbInstallDisallowed(UserManagerService userManager, int userId) { |
Amith Yamasani | 8cd28b5 | 2014-06-08 17:54:27 -0700 | [diff] [blame] | 911 | return userManager.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES, |
| 912 | userId); |
| 913 | } |
| 914 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 915 | void insertPackageSettingLPw(PackageSetting p, PackageParser.Package pkg) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 916 | p.pkg = pkg; |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 917 | // pkg.mSetEnabled = p.getEnabled(userId); |
| 918 | // pkg.mSetStopped = p.getStopped(userId); |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 919 | final String volumeUuid = pkg.applicationInfo.volumeUuid; |
Jeff Sharkey | d746057 | 2014-07-06 20:44:55 -0700 | [diff] [blame] | 920 | final String codePath = pkg.applicationInfo.getCodePath(); |
| 921 | final String resourcePath = pkg.applicationInfo.getResourcePath(); |
Jeff Sharkey | 84f1294 | 2014-07-10 17:48:11 -0700 | [diff] [blame] | 922 | final String legacyNativeLibraryPath = pkg.applicationInfo.nativeLibraryRootDir; |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 923 | // Update volume if needed |
| 924 | if (!Objects.equals(volumeUuid, p.volumeUuid)) { |
| 925 | Slog.w(PackageManagerService.TAG, "Volume for " + p.pkg.packageName + |
| 926 | " changing from " + p.volumeUuid + " to " + volumeUuid); |
| 927 | p.volumeUuid = volumeUuid; |
| 928 | } |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 929 | // Update code path if needed |
Jeff Sharkey | 84f1294 | 2014-07-10 17:48:11 -0700 | [diff] [blame] | 930 | if (!Objects.equals(codePath, p.codePathString)) { |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 931 | Slog.w(PackageManagerService.TAG, "Code path for " + p.pkg.packageName + |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 932 | " changing from " + p.codePathString + " to " + codePath); |
| 933 | p.codePath = new File(codePath); |
| 934 | p.codePathString = codePath; |
| 935 | } |
| 936 | //Update resource path if needed |
Jeff Sharkey | 84f1294 | 2014-07-10 17:48:11 -0700 | [diff] [blame] | 937 | if (!Objects.equals(resourcePath, p.resourcePathString)) { |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 938 | Slog.w(PackageManagerService.TAG, "Resource path for " + p.pkg.packageName + |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 939 | " changing from " + p.resourcePathString + " to " + resourcePath); |
| 940 | p.resourcePath = new File(resourcePath); |
| 941 | p.resourcePathString = resourcePath; |
| 942 | } |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 943 | // Update the native library paths if needed |
Jeff Sharkey | 84f1294 | 2014-07-10 17:48:11 -0700 | [diff] [blame] | 944 | if (!Objects.equals(legacyNativeLibraryPath, p.legacyNativeLibraryPathString)) { |
| 945 | p.legacyNativeLibraryPathString = legacyNativeLibraryPath; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 946 | } |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 947 | |
Narayan Kamath | 9e289d7 | 2014-04-10 09:26:59 +0000 | [diff] [blame] | 948 | // Update the required Cpu Abi |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 949 | p.primaryCpuAbiString = pkg.applicationInfo.primaryCpuAbi; |
| 950 | p.secondaryCpuAbiString = pkg.applicationInfo.secondaryCpuAbi; |
Narayan Kamath | 4903f64 | 2014-08-11 13:33:45 +0100 | [diff] [blame] | 951 | p.cpuAbiOverrideString = pkg.cpuAbiOverride; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 952 | // Update version code if needed |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 953 | if (pkg.getLongVersionCode() != p.versionCode) { |
| 954 | p.versionCode = pkg.getLongVersionCode(); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 955 | } |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 956 | // Update signatures if needed. |
| 957 | if (p.signatures.mSignatures == null) { |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 958 | p.signatures.assignSignatures(pkg.mSigningDetails.signatures); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 959 | } |
Kenny Root | 5455f68 | 2012-09-09 14:52:10 -0700 | [diff] [blame] | 960 | // Update flags if needed. |
| 961 | if (pkg.applicationInfo.flags != p.pkgFlags) { |
| 962 | p.pkgFlags = pkg.applicationInfo.flags; |
| 963 | } |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 964 | // If this app defines a shared user id initialize |
| 965 | // the shared user signatures as well. |
| 966 | if (p.sharedUser != null && p.sharedUser.signatures.mSignatures == null) { |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 967 | p.sharedUser.signatures.assignSignatures(pkg.mSigningDetails.signatures); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 968 | } |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 969 | // Update static shared library dependencies if needed |
| 970 | if (pkg.usesStaticLibraries != null && pkg.usesStaticLibrariesVersions != null |
| 971 | && pkg.usesStaticLibraries.size() == pkg.usesStaticLibrariesVersions.length) { |
Sudheer Shanka | b6f0681 | 2017-05-16 14:37:42 -0700 | [diff] [blame] | 972 | p.usesStaticLibraries = new String[pkg.usesStaticLibraries.size()]; |
| 973 | pkg.usesStaticLibraries.toArray(p.usesStaticLibraries); |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 974 | p.usesStaticLibrariesVersions = pkg.usesStaticLibrariesVersions; |
| 975 | } else { |
Sudheer Shanka | b6f0681 | 2017-05-16 14:37:42 -0700 | [diff] [blame] | 976 | p.usesStaticLibraries = null; |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 977 | p.usesStaticLibrariesVersions = null; |
| 978 | } |
Todd Kennedy | 788c842 | 2016-08-10 10:52:34 -0700 | [diff] [blame] | 979 | addPackageSettingLPw(p, p.sharedUser); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 980 | } |
| 981 | |
| 982 | // Utility method that adds a PackageSetting to mPackages and |
Christopher Tate | 6038d15 | 2015-06-17 13:07:46 -0700 | [diff] [blame] | 983 | // completes updating the shared user attributes and any restored |
| 984 | // app link verification state |
Todd Kennedy | 788c842 | 2016-08-10 10:52:34 -0700 | [diff] [blame] | 985 | private void addPackageSettingLPw(PackageSetting p, SharedUserSetting sharedUser) { |
| 986 | mPackages.put(p.name, p); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 987 | if (sharedUser != null) { |
| 988 | if (p.sharedUser != null && p.sharedUser != sharedUser) { |
| 989 | PackageManagerService.reportSettingsProblem(Log.ERROR, |
| 990 | "Package " + p.name + " was user " |
| 991 | + p.sharedUser + " but is now " + sharedUser |
| 992 | + "; I am not changing its files so it will probably fail!"); |
Ben Gruver | dd72c9e | 2013-08-06 12:34:17 -0700 | [diff] [blame] | 993 | p.sharedUser.removePackage(p); |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 994 | } else if (p.appId != sharedUser.userId) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 995 | PackageManagerService.reportSettingsProblem(Log.ERROR, |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 996 | "Package " + p.name + " was user id " + p.appId |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 997 | + " but is now user " + sharedUser |
| 998 | + " with id " + sharedUser.userId |
| 999 | + "; I am not changing its files so it will probably fail!"); |
| 1000 | } |
| 1001 | |
Ben Gruver | dd72c9e | 2013-08-06 12:34:17 -0700 | [diff] [blame] | 1002 | sharedUser.addPackage(p); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1003 | p.sharedUser = sharedUser; |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 1004 | p.appId = sharedUser.userId; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1005 | } |
Svet Ganov | e7af194 | 2015-08-04 11:13:44 -0700 | [diff] [blame] | 1006 | |
| 1007 | // If the we know about this user id, we have to update it as it |
| 1008 | // has to point to the same PackageSetting instance as the package. |
| 1009 | Object userIdPs = getUserIdLPr(p.appId); |
| 1010 | if (sharedUser == null) { |
| 1011 | if (userIdPs != null && userIdPs != p) { |
| 1012 | replaceUserIdLPw(p.appId, p); |
| 1013 | } |
| 1014 | } else { |
| 1015 | if (userIdPs != null && userIdPs != sharedUser) { |
| 1016 | replaceUserIdLPw(p.appId, sharedUser); |
| 1017 | } |
| 1018 | } |
| 1019 | |
Todd Kennedy | 788c842 | 2016-08-10 10:52:34 -0700 | [diff] [blame] | 1020 | IntentFilterVerificationInfo ivi = mRestoredIntentFilterVerifications.get(p.name); |
Christopher Tate | 6038d15 | 2015-06-17 13:07:46 -0700 | [diff] [blame] | 1021 | if (ivi != null) { |
| 1022 | if (DEBUG_DOMAIN_VERIFICATION) { |
Todd Kennedy | 788c842 | 2016-08-10 10:52:34 -0700 | [diff] [blame] | 1023 | Slog.i(TAG, "Applying restored IVI for " + p.name + " : " + ivi.getStatusString()); |
Christopher Tate | 6038d15 | 2015-06-17 13:07:46 -0700 | [diff] [blame] | 1024 | } |
Todd Kennedy | 788c842 | 2016-08-10 10:52:34 -0700 | [diff] [blame] | 1025 | mRestoredIntentFilterVerifications.remove(p.name); |
Christopher Tate | 6038d15 | 2015-06-17 13:07:46 -0700 | [diff] [blame] | 1026 | p.setIntentFilterVerificationInfo(ivi); |
| 1027 | } |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1028 | } |
| 1029 | |
| 1030 | /* |
| 1031 | * Update the shared user setting when a package using |
| 1032 | * specifying the shared user id is removed. The gids |
| 1033 | * associated with each permission of the deleted package |
| 1034 | * are removed from the shared user's gid list only if its |
| 1035 | * not in use by other permissions of packages in the |
| 1036 | * shared user setting. |
| 1037 | */ |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 1038 | int updateSharedUserPermsLPw(PackageSetting deletedPs, int userId) { |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 1039 | if ((deletedPs == null) || (deletedPs.pkg == null)) { |
| 1040 | Slog.i(PackageManagerService.TAG, |
| 1041 | "Trying to update info for null package. Just ignoring"); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 1042 | return UserHandle.USER_NULL; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1043 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 1044 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1045 | // No sharedUserId |
| 1046 | if (deletedPs.sharedUser == null) { |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 1047 | return UserHandle.USER_NULL; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1048 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 1049 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1050 | SharedUserSetting sus = deletedPs.sharedUser; |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 1051 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1052 | // Update permissions |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 1053 | for (String eachPerm : deletedPs.pkg.requestedPermissions) { |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 1054 | BasePermission bp = mPermissions.getPermission(eachPerm); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 1055 | if (bp == null) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1056 | continue; |
| 1057 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 1058 | |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 1059 | // Check if another package in the shared user needs the permission. |
Svetoslav | 4a5f4a2 | 2015-07-07 18:18:15 -0700 | [diff] [blame] | 1060 | boolean used = false; |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 1061 | for (PackageSetting pkg : sus.packages) { |
| 1062 | if (pkg.pkg != null |
| 1063 | && !pkg.pkg.packageName.equals(deletedPs.pkg.packageName) |
| 1064 | && pkg.pkg.requestedPermissions.contains(eachPerm)) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1065 | used = true; |
| 1066 | break; |
| 1067 | } |
| 1068 | } |
Svetoslav | 4a5f4a2 | 2015-07-07 18:18:15 -0700 | [diff] [blame] | 1069 | if (used) { |
| 1070 | continue; |
| 1071 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 1072 | |
Svetoslav | 4a5f4a2 | 2015-07-07 18:18:15 -0700 | [diff] [blame] | 1073 | PermissionsState permissionsState = sus.getPermissionsState(); |
| 1074 | PackageSetting disabledPs = getDisabledSystemPkgLPr(deletedPs.pkg.packageName); |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 1075 | |
Svetoslav | 4a5f4a2 | 2015-07-07 18:18:15 -0700 | [diff] [blame] | 1076 | // If the package is shadowing is a disabled system package, |
| 1077 | // do not drop permissions that the shadowed package requests. |
| 1078 | if (disabledPs != null) { |
| 1079 | boolean reqByDisabledSysPkg = false; |
| 1080 | for (String permission : disabledPs.pkg.requestedPermissions) { |
| 1081 | if (permission.equals(eachPerm)) { |
| 1082 | reqByDisabledSysPkg = true; |
| 1083 | break; |
| 1084 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 1085 | } |
Svetoslav | 4a5f4a2 | 2015-07-07 18:18:15 -0700 | [diff] [blame] | 1086 | if (reqByDisabledSysPkg) { |
| 1087 | continue; |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 1088 | } |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1089 | } |
Svetoslav | 4a5f4a2 | 2015-07-07 18:18:15 -0700 | [diff] [blame] | 1090 | |
| 1091 | // Try to revoke as an install permission which is for all users. |
| 1092 | // The package is gone - no need to keep flags for applying policy. |
| 1093 | permissionsState.updatePermissionFlags(bp, userId, |
| 1094 | PackageManager.MASK_PERMISSION_FLAGS, 0); |
| 1095 | |
| 1096 | if (permissionsState.revokeInstallPermission(bp) == |
| 1097 | PermissionsState.PERMISSION_OPERATION_SUCCESS_GIDS_CHANGED) { |
| 1098 | return UserHandle.USER_ALL; |
| 1099 | } |
| 1100 | |
| 1101 | // Try to revoke as an install permission which is per user. |
| 1102 | if (permissionsState.revokeRuntimePermission(bp, userId) == |
| 1103 | PermissionsState.PERMISSION_OPERATION_SUCCESS_GIDS_CHANGED) { |
| 1104 | return userId; |
| 1105 | } |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1106 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 1107 | |
| 1108 | return UserHandle.USER_NULL; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1109 | } |
| 1110 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 1111 | int removePackageLPw(String name) { |
| 1112 | final PackageSetting p = mPackages.get(name); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1113 | if (p != null) { |
| 1114 | mPackages.remove(name); |
Sudheer Shanka | 2928337 | 2016-04-04 20:56:27 -0700 | [diff] [blame] | 1115 | removeInstallerPackageStatus(name); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1116 | if (p.sharedUser != null) { |
Ben Gruver | dd72c9e | 2013-08-06 12:34:17 -0700 | [diff] [blame] | 1117 | p.sharedUser.removePackage(p); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1118 | if (p.sharedUser.packages.size() == 0) { |
| 1119 | mSharedUsers.remove(p.sharedUser.name); |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 1120 | removeUserIdLPw(p.sharedUser.userId); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1121 | return p.sharedUser.userId; |
| 1122 | } |
| 1123 | } else { |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 1124 | removeUserIdLPw(p.appId); |
| 1125 | return p.appId; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1126 | } |
| 1127 | } |
| 1128 | return -1; |
| 1129 | } |
| 1130 | |
Sudheer Shanka | 2928337 | 2016-04-04 20:56:27 -0700 | [diff] [blame] | 1131 | /** |
| 1132 | * Checks if {@param packageName} is an installer package and if so, clear the installer |
| 1133 | * package name of the packages that are installed by this. |
| 1134 | */ |
| 1135 | private void removeInstallerPackageStatus(String packageName) { |
| 1136 | // Check if the package to be removed is an installer package. |
| 1137 | if (!mInstallerPackages.contains(packageName)) { |
| 1138 | return; |
| 1139 | } |
| 1140 | for (int i = 0; i < mPackages.size(); i++) { |
| 1141 | final PackageSetting ps = mPackages.valueAt(i); |
| 1142 | final String installerPackageName = ps.getInstallerPackageName(); |
| 1143 | if (installerPackageName != null |
| 1144 | && installerPackageName.equals(packageName)) { |
| 1145 | ps.setInstallerPackageName(null); |
Sudheer Shanka | 8c57aea | 2016-04-20 16:47:50 -0700 | [diff] [blame] | 1146 | ps.isOrphaned = true; |
Sudheer Shanka | 2928337 | 2016-04-04 20:56:27 -0700 | [diff] [blame] | 1147 | } |
| 1148 | } |
| 1149 | mInstallerPackages.remove(packageName); |
| 1150 | } |
| 1151 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 1152 | private void replacePackageLPw(String name, PackageSetting newp) { |
| 1153 | final PackageSetting p = mPackages.get(name); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1154 | if (p != null) { |
| 1155 | if (p.sharedUser != null) { |
Ben Gruver | dd72c9e | 2013-08-06 12:34:17 -0700 | [diff] [blame] | 1156 | p.sharedUser.removePackage(p); |
| 1157 | p.sharedUser.addPackage(newp); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1158 | } else { |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 1159 | replaceUserIdLPw(p.appId, newp); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1160 | } |
| 1161 | } |
| 1162 | mPackages.put(name, newp); |
| 1163 | } |
| 1164 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 1165 | private boolean addUserIdLPw(int uid, Object obj, Object name) { |
Dianne Hackborn | 21fbd1f | 2012-02-10 10:38:10 -0800 | [diff] [blame] | 1166 | if (uid > Process.LAST_APPLICATION_UID) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1167 | return false; |
| 1168 | } |
| 1169 | |
Dianne Hackborn | 21fbd1f | 2012-02-10 10:38:10 -0800 | [diff] [blame] | 1170 | if (uid >= Process.FIRST_APPLICATION_UID) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1171 | int N = mUserIds.size(); |
Dianne Hackborn | 21fbd1f | 2012-02-10 10:38:10 -0800 | [diff] [blame] | 1172 | final int index = uid - Process.FIRST_APPLICATION_UID; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1173 | while (index >= N) { |
| 1174 | mUserIds.add(null); |
| 1175 | N++; |
| 1176 | } |
| 1177 | if (mUserIds.get(index) != null) { |
| 1178 | PackageManagerService.reportSettingsProblem(Log.ERROR, |
| 1179 | "Adding duplicate user id: " + uid |
| 1180 | + " name=" + name); |
| 1181 | return false; |
| 1182 | } |
| 1183 | mUserIds.set(index, obj); |
| 1184 | } else { |
| 1185 | if (mOtherUserIds.get(uid) != null) { |
| 1186 | PackageManagerService.reportSettingsProblem(Log.ERROR, |
| 1187 | "Adding duplicate shared id: " + uid |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1188 | + " name=" + name); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1189 | return false; |
| 1190 | } |
| 1191 | mOtherUserIds.put(uid, obj); |
| 1192 | } |
| 1193 | return true; |
| 1194 | } |
| 1195 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 1196 | public Object getUserIdLPr(int uid) { |
Dianne Hackborn | 21fbd1f | 2012-02-10 10:38:10 -0800 | [diff] [blame] | 1197 | if (uid >= Process.FIRST_APPLICATION_UID) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1198 | final int N = mUserIds.size(); |
Dianne Hackborn | 21fbd1f | 2012-02-10 10:38:10 -0800 | [diff] [blame] | 1199 | final int index = uid - Process.FIRST_APPLICATION_UID; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1200 | return index < N ? mUserIds.get(index) : null; |
| 1201 | } else { |
| 1202 | return mOtherUserIds.get(uid); |
| 1203 | } |
| 1204 | } |
| 1205 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 1206 | private void removeUserIdLPw(int uid) { |
Dianne Hackborn | 21fbd1f | 2012-02-10 10:38:10 -0800 | [diff] [blame] | 1207 | if (uid >= Process.FIRST_APPLICATION_UID) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1208 | final int N = mUserIds.size(); |
Dianne Hackborn | 21fbd1f | 2012-02-10 10:38:10 -0800 | [diff] [blame] | 1209 | final int index = uid - Process.FIRST_APPLICATION_UID; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1210 | if (index < N) mUserIds.set(index, null); |
| 1211 | } else { |
| 1212 | mOtherUserIds.remove(uid); |
| 1213 | } |
Geremy Condra | 12c1838 | 2013-03-06 16:49:06 -0800 | [diff] [blame] | 1214 | setFirstAvailableUid(uid+1); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1215 | } |
| 1216 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 1217 | private void replaceUserIdLPw(int uid, Object obj) { |
Dianne Hackborn | 21fbd1f | 2012-02-10 10:38:10 -0800 | [diff] [blame] | 1218 | if (uid >= Process.FIRST_APPLICATION_UID) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1219 | final int N = mUserIds.size(); |
Dianne Hackborn | 21fbd1f | 2012-02-10 10:38:10 -0800 | [diff] [blame] | 1220 | final int index = uid - Process.FIRST_APPLICATION_UID; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1221 | if (index < N) mUserIds.set(index, obj); |
| 1222 | } else { |
| 1223 | mOtherUserIds.put(uid, obj); |
| 1224 | } |
| 1225 | } |
| 1226 | |
Dianne Hackborn | 6309271 | 2012-10-07 14:45:35 -0700 | [diff] [blame] | 1227 | PreferredIntentResolver editPreferredActivitiesLPw(int userId) { |
| 1228 | PreferredIntentResolver pir = mPreferredActivities.get(userId); |
| 1229 | if (pir == null) { |
| 1230 | pir = new PreferredIntentResolver(); |
| 1231 | mPreferredActivities.put(userId, pir); |
| 1232 | } |
| 1233 | return pir; |
| 1234 | } |
| 1235 | |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 1236 | PersistentPreferredIntentResolver editPersistentPreferredActivitiesLPw(int userId) { |
| 1237 | PersistentPreferredIntentResolver ppir = mPersistentPreferredActivities.get(userId); |
| 1238 | if (ppir == null) { |
| 1239 | ppir = new PersistentPreferredIntentResolver(); |
| 1240 | mPersistentPreferredActivities.put(userId, ppir); |
| 1241 | } |
| 1242 | return ppir; |
| 1243 | } |
| 1244 | |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 1245 | CrossProfileIntentResolver editCrossProfileIntentResolverLPw(int userId) { |
| 1246 | CrossProfileIntentResolver cpir = mCrossProfileIntentResolvers.get(userId); |
| 1247 | if (cpir == null) { |
| 1248 | cpir = new CrossProfileIntentResolver(); |
| 1249 | mCrossProfileIntentResolvers.put(userId, cpir); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1250 | } |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 1251 | return cpir; |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1252 | } |
| 1253 | |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1254 | /** |
| 1255 | * The following functions suppose that you have a lock for managing access to the |
| 1256 | * mIntentFiltersVerifications map. |
| 1257 | */ |
| 1258 | |
| 1259 | /* package protected */ |
| 1260 | IntentFilterVerificationInfo getIntentFilterVerificationLPr(String packageName) { |
| 1261 | PackageSetting ps = mPackages.get(packageName); |
| 1262 | if (ps == null) { |
Christopher Tate | 72c10a2 | 2015-06-12 18:31:24 -0700 | [diff] [blame] | 1263 | if (DEBUG_DOMAIN_VERIFICATION) { |
| 1264 | Slog.w(PackageManagerService.TAG, "No package known: " + packageName); |
| 1265 | } |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1266 | return null; |
| 1267 | } |
| 1268 | return ps.getIntentFilterVerificationInfo(); |
| 1269 | } |
| 1270 | |
| 1271 | /* package protected */ |
Fabrice Di Meglio | 7d014ce | 2015-04-08 16:17:46 -0700 | [diff] [blame] | 1272 | IntentFilterVerificationInfo createIntentFilterVerificationIfNeededLPw(String packageName, |
Todd Kennedy | 788c842 | 2016-08-10 10:52:34 -0700 | [diff] [blame] | 1273 | ArraySet<String> domains) { |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1274 | PackageSetting ps = mPackages.get(packageName); |
| 1275 | if (ps == null) { |
Christopher Tate | 72c10a2 | 2015-06-12 18:31:24 -0700 | [diff] [blame] | 1276 | if (DEBUG_DOMAIN_VERIFICATION) { |
| 1277 | Slog.w(PackageManagerService.TAG, "No package known: " + packageName); |
| 1278 | } |
Fabrice Di Meglio | 7d014ce | 2015-04-08 16:17:46 -0700 | [diff] [blame] | 1279 | return null; |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1280 | } |
Fabrice Di Meglio | 7d014ce | 2015-04-08 16:17:46 -0700 | [diff] [blame] | 1281 | IntentFilterVerificationInfo ivi = ps.getIntentFilterVerificationInfo(); |
| 1282 | if (ivi == null) { |
| 1283 | ivi = new IntentFilterVerificationInfo(packageName, domains); |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1284 | ps.setIntentFilterVerificationInfo(ivi); |
Christopher Tate | 72c10a2 | 2015-06-12 18:31:24 -0700 | [diff] [blame] | 1285 | if (DEBUG_DOMAIN_VERIFICATION) { |
| 1286 | Slog.d(PackageManagerService.TAG, |
| 1287 | "Creating new IntentFilterVerificationInfo for pkg: " + packageName); |
| 1288 | } |
Fabrice Di Meglio | 1de3f0d | 2015-04-29 19:42:41 -0700 | [diff] [blame] | 1289 | } else { |
| 1290 | ivi.setDomains(domains); |
Christopher Tate | 72c10a2 | 2015-06-12 18:31:24 -0700 | [diff] [blame] | 1291 | if (DEBUG_DOMAIN_VERIFICATION) { |
| 1292 | Slog.d(PackageManagerService.TAG, |
| 1293 | "Setting domains to existing IntentFilterVerificationInfo for pkg: " + |
| 1294 | packageName + " and with domains: " + ivi.getDomainsString()); |
| 1295 | } |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1296 | } |
Fabrice Di Meglio | 7d014ce | 2015-04-08 16:17:46 -0700 | [diff] [blame] | 1297 | return ivi; |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1298 | } |
| 1299 | |
| 1300 | int getIntentFilterVerificationStatusLPr(String packageName, int userId) { |
| 1301 | PackageSetting ps = mPackages.get(packageName); |
| 1302 | if (ps == null) { |
Christopher Tate | 72c10a2 | 2015-06-12 18:31:24 -0700 | [diff] [blame] | 1303 | if (DEBUG_DOMAIN_VERIFICATION) { |
| 1304 | Slog.w(PackageManagerService.TAG, "No package known: " + packageName); |
| 1305 | } |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1306 | return INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_UNDEFINED; |
| 1307 | } |
Christopher Tate | d85a664 | 2015-07-17 15:39:08 -0700 | [diff] [blame] | 1308 | return (int)(ps.getDomainVerificationStatusForUser(userId) >> 32); |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1309 | } |
| 1310 | |
Christopher Tate | f0d6cb3 | 2015-07-10 17:44:53 -0700 | [diff] [blame] | 1311 | boolean updateIntentFilterVerificationStatusLPw(String packageName, final int status, int userId) { |
Fabrice Di Meglio | 0788595 | 2015-04-06 19:41:28 -0700 | [diff] [blame] | 1312 | // Update the status for the current package |
| 1313 | PackageSetting current = mPackages.get(packageName); |
| 1314 | if (current == null) { |
Christopher Tate | 72c10a2 | 2015-06-12 18:31:24 -0700 | [diff] [blame] | 1315 | if (DEBUG_DOMAIN_VERIFICATION) { |
| 1316 | Slog.w(PackageManagerService.TAG, "No package known: " + packageName); |
| 1317 | } |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1318 | return false; |
| 1319 | } |
Christopher Tate | 050aee2 | 2015-07-01 16:50:43 -0700 | [diff] [blame] | 1320 | |
Christopher Tate | f0d6cb3 | 2015-07-10 17:44:53 -0700 | [diff] [blame] | 1321 | final int alwaysGeneration; |
| 1322 | if (status == INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ALWAYS) { |
| 1323 | alwaysGeneration = mNextAppLinkGeneration.get(userId) + 1; |
| 1324 | mNextAppLinkGeneration.put(userId, alwaysGeneration); |
| 1325 | } else { |
| 1326 | alwaysGeneration = 0; |
| 1327 | } |
| 1328 | |
| 1329 | current.setDomainVerificationStatusForUser(status, alwaysGeneration, userId); |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1330 | return true; |
| 1331 | } |
| 1332 | |
| 1333 | /** |
Fabrice Di Meglio | 0788595 | 2015-04-06 19:41:28 -0700 | [diff] [blame] | 1334 | * Used for Settings App and PackageManagerService dump. Should be read only. |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1335 | */ |
| 1336 | List<IntentFilterVerificationInfo> getIntentFilterVerificationsLPr( |
| 1337 | String packageName) { |
| 1338 | if (packageName == null) { |
| 1339 | return Collections.<IntentFilterVerificationInfo>emptyList(); |
| 1340 | } |
| 1341 | ArrayList<IntentFilterVerificationInfo> result = new ArrayList<>(); |
| 1342 | for (PackageSetting ps : mPackages.values()) { |
| 1343 | IntentFilterVerificationInfo ivi = ps.getIntentFilterVerificationInfo(); |
| 1344 | if (ivi == null || TextUtils.isEmpty(ivi.getPackageName()) || |
| 1345 | !ivi.getPackageName().equalsIgnoreCase(packageName)) { |
| 1346 | continue; |
| 1347 | } |
| 1348 | result.add(ivi); |
| 1349 | } |
| 1350 | return result; |
| 1351 | } |
| 1352 | |
Fabrice Di Meglio | 1f09b8c | 2015-05-06 18:51:21 -0700 | [diff] [blame] | 1353 | boolean removeIntentFilterVerificationLPw(String packageName, int userId) { |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1354 | PackageSetting ps = mPackages.get(packageName); |
| 1355 | if (ps == null) { |
Christopher Tate | 72c10a2 | 2015-06-12 18:31:24 -0700 | [diff] [blame] | 1356 | if (DEBUG_DOMAIN_VERIFICATION) { |
| 1357 | Slog.w(PackageManagerService.TAG, "No package known: " + packageName); |
| 1358 | } |
Fabrice Di Meglio | 1f09b8c | 2015-05-06 18:51:21 -0700 | [diff] [blame] | 1359 | return false; |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1360 | } |
| 1361 | ps.clearDomainVerificationStatusForUser(userId); |
Fabrice Di Meglio | 1f09b8c | 2015-05-06 18:51:21 -0700 | [diff] [blame] | 1362 | return true; |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1363 | } |
| 1364 | |
Fabrice Di Meglio | 1f09b8c | 2015-05-06 18:51:21 -0700 | [diff] [blame] | 1365 | boolean removeIntentFilterVerificationLPw(String packageName, int[] userIds) { |
| 1366 | boolean result = false; |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1367 | for (int userId : userIds) { |
Fabrice Di Meglio | 1f09b8c | 2015-05-06 18:51:21 -0700 | [diff] [blame] | 1368 | result |= removeIntentFilterVerificationLPw(packageName, userId); |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1369 | } |
Fabrice Di Meglio | 1f09b8c | 2015-05-06 18:51:21 -0700 | [diff] [blame] | 1370 | return result; |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1371 | } |
| 1372 | |
Christopher Tate | db3fe81 | 2015-06-24 16:15:48 -0700 | [diff] [blame] | 1373 | boolean setDefaultBrowserPackageNameLPw(String packageName, int userId) { |
Fabrice Di Meglio | 6227172 | 2015-04-10 17:24:02 -0700 | [diff] [blame] | 1374 | if (userId == UserHandle.USER_ALL) { |
| 1375 | return false; |
| 1376 | } |
Christopher Tate | 53d52c8 | 2017-04-24 15:55:33 -0700 | [diff] [blame] | 1377 | if (packageName != null) { |
| 1378 | mDefaultBrowserApp.put(userId, packageName); |
| 1379 | } else { |
| 1380 | mDefaultBrowserApp.remove(userId); |
| 1381 | } |
Fabrice Di Meglio | 6227172 | 2015-04-10 17:24:02 -0700 | [diff] [blame] | 1382 | writePackageRestrictionsLPr(userId); |
| 1383 | return true; |
| 1384 | } |
| 1385 | |
| 1386 | String getDefaultBrowserPackageNameLPw(int userId) { |
| 1387 | return (userId == UserHandle.USER_ALL) ? null : mDefaultBrowserApp.get(userId); |
| 1388 | } |
| 1389 | |
Robin Lee | 0dc591b | 2016-05-04 13:01:46 +0100 | [diff] [blame] | 1390 | boolean setDefaultDialerPackageNameLPw(String packageName, int userId) { |
| 1391 | if (userId == UserHandle.USER_ALL) { |
| 1392 | return false; |
| 1393 | } |
| 1394 | mDefaultDialerApp.put(userId, packageName); |
| 1395 | writePackageRestrictionsLPr(userId); |
| 1396 | return true; |
| 1397 | } |
| 1398 | |
| 1399 | String getDefaultDialerPackageNameLPw(int userId) { |
| 1400 | return (userId == UserHandle.USER_ALL) ? null : mDefaultDialerApp.get(userId); |
| 1401 | } |
| 1402 | |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1403 | private File getUserPackagesStateFile(int userId) { |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 1404 | // TODO: Implement a cleaner solution when adding tests. |
| 1405 | // This instead of Environment.getUserSystemDirectory(userId) to support testing. |
| 1406 | File userDir = new File(new File(mSystemDir, "users"), Integer.toString(userId)); |
| 1407 | return new File(userDir, "package-restrictions.xml"); |
| 1408 | } |
| 1409 | |
| 1410 | private File getUserRuntimePermissionsFile(int userId) { |
| 1411 | // TODO: Implement a cleaner solution when adding tests. |
| 1412 | // This instead of Environment.getUserSystemDirectory(userId) to support testing. |
| 1413 | File userDir = new File(new File(mSystemDir, "users"), Integer.toString(userId)); |
| 1414 | return new File(userDir, RUNTIME_PERMISSIONS_FILE_NAME); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1415 | } |
| 1416 | |
| 1417 | private File getUserPackagesStateBackupFile(int userId) { |
Amith Yamasani | 61f5737 | 2012-08-31 12:12:28 -0700 | [diff] [blame] | 1418 | return new File(Environment.getUserSystemDirectory(userId), |
| 1419 | "package-restrictions-backup.xml"); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1420 | } |
| 1421 | |
| 1422 | void writeAllUsersPackageRestrictionsLPr() { |
Todd Kennedy | 13715d5 | 2016-08-01 13:38:57 -0700 | [diff] [blame] | 1423 | List<UserInfo> users = getAllUsers(UserManagerService.getInstance()); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1424 | if (users == null) return; |
| 1425 | |
| 1426 | for (UserInfo user : users) { |
| 1427 | writePackageRestrictionsLPr(user.id); |
| 1428 | } |
| 1429 | } |
| 1430 | |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 1431 | void writeAllRuntimePermissionsLPr() { |
| 1432 | for (int userId : UserManagerService.getInstance().getUserIds()) { |
| 1433 | mRuntimePermissionsPersistence.writePermissionsForUserAsyncLPr(userId); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1434 | } |
| 1435 | } |
| 1436 | |
Svet Ganov | ba3ba81 | 2015-06-26 10:54:06 -0700 | [diff] [blame] | 1437 | boolean areDefaultRuntimePermissionsGrantedLPr(int userId) { |
| 1438 | return mRuntimePermissionsPersistence |
| 1439 | .areDefaultRuntimPermissionsGrantedLPr(userId); |
| 1440 | } |
| 1441 | |
| 1442 | void onDefaultRuntimePermissionsGrantedLPr(int userId) { |
| 1443 | mRuntimePermissionsPersistence |
| 1444 | .onDefaultRuntimePermissionsGrantedLPr(userId); |
| 1445 | } |
| 1446 | |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 1447 | public VersionInfo findOrCreateVersion(String volumeUuid) { |
| 1448 | VersionInfo ver = mVersion.get(volumeUuid); |
| 1449 | if (ver == null) { |
| 1450 | ver = new VersionInfo(); |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 1451 | mVersion.put(volumeUuid, ver); |
| 1452 | } |
| 1453 | return ver; |
Kenny Root | c1c0d3c | 2014-04-24 13:36:40 -0700 | [diff] [blame] | 1454 | } |
| 1455 | |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 1456 | public VersionInfo getInternalVersion() { |
| 1457 | return mVersion.get(StorageManager.UUID_PRIVATE_INTERNAL); |
Kenny Root | c1c0d3c | 2014-04-24 13:36:40 -0700 | [diff] [blame] | 1458 | } |
| 1459 | |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 1460 | public VersionInfo getExternalVersion() { |
| 1461 | return mVersion.get(StorageManager.UUID_PRIMARY_PHYSICAL); |
Kenny Root | c1c0d3c | 2014-04-24 13:36:40 -0700 | [diff] [blame] | 1462 | } |
| 1463 | |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 1464 | public void onVolumeForgotten(String fsUuid) { |
| 1465 | mVersion.remove(fsUuid); |
Kenny Root | c1c0d3c | 2014-04-24 13:36:40 -0700 | [diff] [blame] | 1466 | } |
| 1467 | |
Christopher Tate | e012a23 | 2015-04-01 17:18:50 -0700 | [diff] [blame] | 1468 | /** |
| 1469 | * Applies the preferred activity state described by the given XML. This code |
| 1470 | * also supports the restore-from-backup code path. |
| 1471 | * |
| 1472 | * @see PreferredActivityBackupHelper |
| 1473 | */ |
| 1474 | void readPreferredActivitiesLPw(XmlPullParser parser, int userId) |
Dianne Hackborn | 6309271 | 2012-10-07 14:45:35 -0700 | [diff] [blame] | 1475 | throws XmlPullParserException, IOException { |
| 1476 | int outerDepth = parser.getDepth(); |
| 1477 | int type; |
| 1478 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 1479 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 1480 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 1481 | continue; |
| 1482 | } |
| 1483 | |
| 1484 | String tagName = parser.getName(); |
| 1485 | if (tagName.equals(TAG_ITEM)) { |
| 1486 | PreferredActivity pa = new PreferredActivity(parser); |
| 1487 | if (pa.mPref.getParseError() == null) { |
| 1488 | editPreferredActivitiesLPw(userId).addFilter(pa); |
| 1489 | } else { |
| 1490 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 1491 | "Error in package manager settings: <preferred-activity> " |
| 1492 | + pa.mPref.getParseError() + " at " |
| 1493 | + parser.getPositionDescription()); |
| 1494 | } |
| 1495 | } else { |
| 1496 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 1497 | "Unknown element under <preferred-activities>: " + parser.getName()); |
| 1498 | XmlUtils.skipCurrentTag(parser); |
| 1499 | } |
| 1500 | } |
| 1501 | } |
| 1502 | |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 1503 | private void readPersistentPreferredActivitiesLPw(XmlPullParser parser, int userId) |
| 1504 | throws XmlPullParserException, IOException { |
| 1505 | int outerDepth = parser.getDepth(); |
| 1506 | int type; |
| 1507 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 1508 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 1509 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 1510 | continue; |
| 1511 | } |
| 1512 | String tagName = parser.getName(); |
| 1513 | if (tagName.equals(TAG_ITEM)) { |
| 1514 | PersistentPreferredActivity ppa = new PersistentPreferredActivity(parser); |
| 1515 | editPersistentPreferredActivitiesLPw(userId).addFilter(ppa); |
| 1516 | } else { |
| 1517 | PackageManagerService.reportSettingsProblem(Log.WARN, |
Sander Alewijnse | af59762 | 2014-03-20 18:44:57 +0000 | [diff] [blame] | 1518 | "Unknown element under <" + TAG_PERSISTENT_PREFERRED_ACTIVITIES + ">: " |
| 1519 | + parser.getName()); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 1520 | XmlUtils.skipCurrentTag(parser); |
| 1521 | } |
| 1522 | } |
| 1523 | } |
| 1524 | |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 1525 | private void readCrossProfileIntentFiltersLPw(XmlPullParser parser, int userId) |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1526 | throws XmlPullParserException, IOException { |
| 1527 | int outerDepth = parser.getDepth(); |
| 1528 | int type; |
| 1529 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 1530 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 1531 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 1532 | continue; |
| 1533 | } |
Christopher Tate | 6038d15 | 2015-06-17 13:07:46 -0700 | [diff] [blame] | 1534 | final String tagName = parser.getName(); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1535 | if (tagName.equals(TAG_ITEM)) { |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 1536 | CrossProfileIntentFilter cpif = new CrossProfileIntentFilter(parser); |
| 1537 | editCrossProfileIntentResolverLPw(userId).addFilter(cpif); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1538 | } else { |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 1539 | String msg = "Unknown element under " + TAG_CROSS_PROFILE_INTENT_FILTERS + ": " + |
Christopher Tate | 6038d15 | 2015-06-17 13:07:46 -0700 | [diff] [blame] | 1540 | tagName; |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1541 | PackageManagerService.reportSettingsProblem(Log.WARN, msg); |
| 1542 | XmlUtils.skipCurrentTag(parser); |
| 1543 | } |
| 1544 | } |
| 1545 | } |
| 1546 | |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1547 | private void readDomainVerificationLPw(XmlPullParser parser, PackageSettingBase packageSetting) |
| 1548 | throws XmlPullParserException, IOException { |
| 1549 | IntentFilterVerificationInfo ivi = new IntentFilterVerificationInfo(parser); |
| 1550 | packageSetting.setIntentFilterVerificationInfo(ivi); |
Todd Kennedy | 788c842 | 2016-08-10 10:52:34 -0700 | [diff] [blame] | 1551 | if (DEBUG_PARSER) { |
| 1552 | Log.d(TAG, "Read domain verification for package: " + ivi.getPackageName()); |
| 1553 | } |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1554 | } |
| 1555 | |
Christopher Tate | 6038d15 | 2015-06-17 13:07:46 -0700 | [diff] [blame] | 1556 | private void readRestoredIntentFilterVerifications(XmlPullParser parser) |
| 1557 | throws XmlPullParserException, IOException { |
| 1558 | int outerDepth = parser.getDepth(); |
| 1559 | int type; |
| 1560 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 1561 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 1562 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 1563 | continue; |
| 1564 | } |
| 1565 | final String tagName = parser.getName(); |
| 1566 | if (tagName.equals(TAG_DOMAIN_VERIFICATION)) { |
| 1567 | IntentFilterVerificationInfo ivi = new IntentFilterVerificationInfo(parser); |
| 1568 | if (DEBUG_DOMAIN_VERIFICATION) { |
| 1569 | Slog.i(TAG, "Restored IVI for " + ivi.getPackageName() |
| 1570 | + " status=" + ivi.getStatusString()); |
| 1571 | } |
| 1572 | mRestoredIntentFilterVerifications.put(ivi.getPackageName(), ivi); |
| 1573 | } else { |
| 1574 | Slog.w(TAG, "Unknown element: " + tagName); |
| 1575 | XmlUtils.skipCurrentTag(parser); |
| 1576 | } |
| 1577 | } |
| 1578 | } |
| 1579 | |
| 1580 | void readDefaultAppsLPw(XmlPullParser parser, int userId) |
Fabrice Di Meglio | 6227172 | 2015-04-10 17:24:02 -0700 | [diff] [blame] | 1581 | throws XmlPullParserException, IOException { |
| 1582 | int outerDepth = parser.getDepth(); |
| 1583 | int type; |
| 1584 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 1585 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 1586 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 1587 | continue; |
| 1588 | } |
| 1589 | String tagName = parser.getName(); |
| 1590 | if (tagName.equals(TAG_DEFAULT_BROWSER)) { |
| 1591 | String packageName = parser.getAttributeValue(null, ATTR_PACKAGE_NAME); |
| 1592 | mDefaultBrowserApp.put(userId, packageName); |
Robin Lee | 0dc591b | 2016-05-04 13:01:46 +0100 | [diff] [blame] | 1593 | } else if (tagName.equals(TAG_DEFAULT_DIALER)) { |
| 1594 | String packageName = parser.getAttributeValue(null, ATTR_PACKAGE_NAME); |
| 1595 | mDefaultDialerApp.put(userId, packageName); |
Fabrice Di Meglio | 6227172 | 2015-04-10 17:24:02 -0700 | [diff] [blame] | 1596 | } else { |
| 1597 | String msg = "Unknown element under " + TAG_DEFAULT_APPS + ": " + |
| 1598 | parser.getName(); |
| 1599 | PackageManagerService.reportSettingsProblem(Log.WARN, msg); |
| 1600 | XmlUtils.skipCurrentTag(parser); |
| 1601 | } |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1602 | } |
| 1603 | } |
| 1604 | |
Vladislav Kuzkokov | 253984e | 2016-10-24 09:27:16 +0200 | [diff] [blame] | 1605 | void readBlockUninstallPackagesLPw(XmlPullParser parser, int userId) |
| 1606 | throws XmlPullParserException, IOException { |
| 1607 | int outerDepth = parser.getDepth(); |
| 1608 | int type; |
| 1609 | ArraySet<String> packages = new ArraySet<>(); |
| 1610 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 1611 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 1612 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 1613 | continue; |
| 1614 | } |
| 1615 | String tagName = parser.getName(); |
| 1616 | if (tagName.equals(TAG_BLOCK_UNINSTALL)) { |
| 1617 | String packageName = parser.getAttributeValue(null, ATTR_PACKAGE_NAME); |
| 1618 | packages.add(packageName); |
| 1619 | } else { |
| 1620 | String msg = "Unknown element under " + TAG_BLOCK_UNINSTALL_PACKAGES + ": " + |
| 1621 | parser.getName(); |
| 1622 | PackageManagerService.reportSettingsProblem(Log.WARN, msg); |
| 1623 | XmlUtils.skipCurrentTag(parser); |
| 1624 | } |
| 1625 | } |
| 1626 | if (packages.isEmpty()) { |
| 1627 | mBlockUninstallPackages.remove(userId); |
| 1628 | } else { |
| 1629 | mBlockUninstallPackages.put(userId, packages); |
| 1630 | } |
| 1631 | } |
| 1632 | |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1633 | void readPackageRestrictionsLPr(int userId) { |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1634 | if (DEBUG_MU) { |
| 1635 | Log.i(TAG, "Reading package restrictions for user=" + userId); |
| 1636 | } |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1637 | FileInputStream str = null; |
| 1638 | File userPackagesStateFile = getUserPackagesStateFile(userId); |
| 1639 | File backupFile = getUserPackagesStateBackupFile(userId); |
| 1640 | if (backupFile.exists()) { |
| 1641 | try { |
| 1642 | str = new FileInputStream(backupFile); |
| 1643 | mReadMessages.append("Reading from backup stopped packages file\n"); |
| 1644 | PackageManagerService.reportSettingsProblem(Log.INFO, |
| 1645 | "Need to read from backup stopped packages file"); |
| 1646 | if (userPackagesStateFile.exists()) { |
| 1647 | // If both the backup and normal file exist, we |
| 1648 | // ignore the normal one since it might have been |
| 1649 | // corrupted. |
| 1650 | Slog.w(PackageManagerService.TAG, "Cleaning up stopped packages file " |
| 1651 | + userPackagesStateFile); |
| 1652 | userPackagesStateFile.delete(); |
| 1653 | } |
| 1654 | } catch (java.io.IOException e) { |
| 1655 | // We'll try for the normal settings file. |
| 1656 | } |
| 1657 | } |
| 1658 | |
| 1659 | try { |
| 1660 | if (str == null) { |
| 1661 | if (!userPackagesStateFile.exists()) { |
| 1662 | mReadMessages.append("No stopped packages file found\n"); |
| 1663 | PackageManagerService.reportSettingsProblem(Log.INFO, |
| 1664 | "No stopped packages file; " |
| 1665 | + "assuming all started"); |
| 1666 | // At first boot, make sure no packages are stopped. |
| 1667 | // We usually want to have third party apps initialize |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 1668 | // in the stopped state, but not at first boot. Also |
| 1669 | // consider all applications to be installed. |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1670 | for (PackageSetting pkg : mPackages.values()) { |
Jeff Sharkey | 4288419 | 2016-04-09 16:12:01 -0600 | [diff] [blame] | 1671 | pkg.setUserState(userId, 0, COMPONENT_ENABLED_STATE_DEFAULT, |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 1672 | true /*installed*/, |
| 1673 | false /*stopped*/, |
| 1674 | false /*notLaunched*/, |
| 1675 | false /*hidden*/, |
| 1676 | false /*suspended*/, |
| 1677 | false /*instantApp*/, |
Todd Kennedy | 5eb5a7d | 2017-08-01 07:42:47 -0700 | [diff] [blame] | 1678 | false /*virtualPreload*/, |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 1679 | null /*lastDisableAppCaller*/, |
| 1680 | null /*enabledComponents*/, |
| 1681 | null /*disabledComponents*/, |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 1682 | INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_UNDEFINED, |
| 1683 | 0, PackageManager.INSTALL_REASON_UNKNOWN); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1684 | } |
| 1685 | return; |
| 1686 | } |
| 1687 | str = new FileInputStream(userPackagesStateFile); |
| 1688 | } |
| 1689 | final XmlPullParser parser = Xml.newPullParser(); |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 1690 | parser.setInput(str, StandardCharsets.UTF_8.name()); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1691 | |
| 1692 | int type; |
| 1693 | while ((type=parser.next()) != XmlPullParser.START_TAG |
| 1694 | && type != XmlPullParser.END_DOCUMENT) { |
| 1695 | ; |
| 1696 | } |
| 1697 | |
| 1698 | if (type != XmlPullParser.START_TAG) { |
| 1699 | mReadMessages.append("No start tag found in package restrictions file\n"); |
| 1700 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 1701 | "No start tag found in package manager stopped packages"); |
| 1702 | return; |
| 1703 | } |
| 1704 | |
Christopher Tate | f0d6cb3 | 2015-07-10 17:44:53 -0700 | [diff] [blame] | 1705 | int maxAppLinkGeneration = 0; |
| 1706 | |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1707 | int outerDepth = parser.getDepth(); |
| 1708 | PackageSetting ps = null; |
| 1709 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 1710 | && (type != XmlPullParser.END_TAG |
| 1711 | || parser.getDepth() > outerDepth)) { |
| 1712 | if (type == XmlPullParser.END_TAG |
| 1713 | || type == XmlPullParser.TEXT) { |
| 1714 | continue; |
| 1715 | } |
| 1716 | |
| 1717 | String tagName = parser.getName(); |
| 1718 | if (tagName.equals(TAG_PACKAGE)) { |
| 1719 | String name = parser.getAttributeValue(null, ATTR_NAME); |
| 1720 | ps = mPackages.get(name); |
| 1721 | if (ps == null) { |
Jeff Sharkey | e06b4d1 | 2016-01-06 14:51:50 -0700 | [diff] [blame] | 1722 | Slog.w(PackageManagerService.TAG, "No package known for stopped package " |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1723 | + name); |
| 1724 | XmlUtils.skipCurrentTag(parser); |
| 1725 | continue; |
| 1726 | } |
Jeff Sharkey | 4288419 | 2016-04-09 16:12:01 -0600 | [diff] [blame] | 1727 | |
| 1728 | final long ceDataInode = XmlUtils.readLongAttribute(parser, ATTR_CE_DATA_INODE, |
| 1729 | 0); |
| 1730 | final boolean installed = XmlUtils.readBooleanAttribute(parser, ATTR_INSTALLED, |
| 1731 | true); |
| 1732 | final boolean stopped = XmlUtils.readBooleanAttribute(parser, ATTR_STOPPED, |
| 1733 | false); |
| 1734 | final boolean notLaunched = XmlUtils.readBooleanAttribute(parser, |
| 1735 | ATTR_NOT_LAUNCHED, false); |
| 1736 | |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 1737 | // For backwards compatibility with the previous name of "blocked", which |
| 1738 | // now means hidden, read the old attribute as well. |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 1739 | final String blockedStr = parser.getAttributeValue(null, ATTR_BLOCKED); |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 1740 | boolean hidden = blockedStr == null |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 1741 | ? false : Boolean.parseBoolean(blockedStr); |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 1742 | final String hiddenStr = parser.getAttributeValue(null, ATTR_HIDDEN); |
| 1743 | hidden = hiddenStr == null |
| 1744 | ? hidden : Boolean.parseBoolean(hiddenStr); |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 1745 | |
Jeff Sharkey | 4288419 | 2016-04-09 16:12:01 -0600 | [diff] [blame] | 1746 | final boolean suspended = XmlUtils.readBooleanAttribute(parser, ATTR_SUSPENDED, |
| 1747 | false); |
| 1748 | final boolean blockUninstall = XmlUtils.readBooleanAttribute(parser, |
| 1749 | ATTR_BLOCK_UNINSTALL, false); |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 1750 | final boolean instantApp = XmlUtils.readBooleanAttribute(parser, |
| 1751 | ATTR_INSTANT_APP, false); |
Todd Kennedy | 5eb5a7d | 2017-08-01 07:42:47 -0700 | [diff] [blame] | 1752 | final boolean virtualPreload = XmlUtils.readBooleanAttribute(parser, |
| 1753 | ATTR_VIRTUAL_PRELOAD, false); |
Jeff Sharkey | 4288419 | 2016-04-09 16:12:01 -0600 | [diff] [blame] | 1754 | final int enabled = XmlUtils.readIntAttribute(parser, ATTR_ENABLED, |
| 1755 | COMPONENT_ENABLED_STATE_DEFAULT); |
| 1756 | final String enabledCaller = parser.getAttributeValue(null, |
| 1757 | ATTR_ENABLED_CALLER); |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1758 | |
Jeff Sharkey | 4288419 | 2016-04-09 16:12:01 -0600 | [diff] [blame] | 1759 | final int verifState = XmlUtils.readIntAttribute(parser, |
| 1760 | ATTR_DOMAIN_VERIFICATON_STATE, |
| 1761 | PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_UNDEFINED); |
| 1762 | final int linkGeneration = XmlUtils.readIntAttribute(parser, |
| 1763 | ATTR_APP_LINK_GENERATION, 0); |
Christopher Tate | f0d6cb3 | 2015-07-10 17:44:53 -0700 | [diff] [blame] | 1764 | if (linkGeneration > maxAppLinkGeneration) { |
| 1765 | maxAppLinkGeneration = linkGeneration; |
| 1766 | } |
Bartosz Fabianowski | a34f53f | 2017-01-11 18:08:47 +0100 | [diff] [blame] | 1767 | final int installReason = XmlUtils.readIntAttribute(parser, |
| 1768 | ATTR_INSTALL_REASON, PackageManager.INSTALL_REASON_UNKNOWN); |
Christopher Tate | f0d6cb3 | 2015-07-10 17:44:53 -0700 | [diff] [blame] | 1769 | |
Jeff Sharkey | 9f837a9 | 2014-10-24 12:07:24 -0700 | [diff] [blame] | 1770 | ArraySet<String> enabledComponents = null; |
| 1771 | ArraySet<String> disabledComponents = null; |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1772 | |
| 1773 | int packageDepth = parser.getDepth(); |
| 1774 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 1775 | && (type != XmlPullParser.END_TAG |
| 1776 | || parser.getDepth() > packageDepth)) { |
| 1777 | if (type == XmlPullParser.END_TAG |
| 1778 | || type == XmlPullParser.TEXT) { |
| 1779 | continue; |
| 1780 | } |
| 1781 | tagName = parser.getName(); |
| 1782 | if (tagName.equals(TAG_ENABLED_COMPONENTS)) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 1783 | enabledComponents = readComponentsLPr(parser); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1784 | } else if (tagName.equals(TAG_DISABLED_COMPONENTS)) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 1785 | disabledComponents = readComponentsLPr(parser); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1786 | } |
| 1787 | } |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 1788 | |
Vladislav Kuzkokov | 253984e | 2016-10-24 09:27:16 +0200 | [diff] [blame] | 1789 | if (blockUninstall) { |
| 1790 | setBlockUninstallLPw(userId, name, true); |
| 1791 | } |
Jeff Sharkey | 4288419 | 2016-04-09 16:12:01 -0600 | [diff] [blame] | 1792 | ps.setUserState(userId, ceDataInode, enabled, installed, stopped, notLaunched, |
Todd Kennedy | 5eb5a7d | 2017-08-01 07:42:47 -0700 | [diff] [blame] | 1793 | hidden, suspended, instantApp, virtualPreload, enabledCaller, |
| 1794 | enabledComponents, disabledComponents, verifState, linkGeneration, |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 1795 | installReason); |
Dianne Hackborn | 6309271 | 2012-10-07 14:45:35 -0700 | [diff] [blame] | 1796 | } else if (tagName.equals("preferred-activities")) { |
| 1797 | readPreferredActivitiesLPw(parser, userId); |
Sander Alewijnse | af59762 | 2014-03-20 18:44:57 +0000 | [diff] [blame] | 1798 | } else if (tagName.equals(TAG_PERSISTENT_PREFERRED_ACTIVITIES)) { |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 1799 | readPersistentPreferredActivitiesLPw(parser, userId); |
Nicolas Prevot | 29762c3 | 2014-07-29 18:51:32 +0100 | [diff] [blame] | 1800 | } else if (tagName.equals(TAG_CROSS_PROFILE_INTENT_FILTERS)) { |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 1801 | readCrossProfileIntentFiltersLPw(parser, userId); |
Fabrice Di Meglio | 6227172 | 2015-04-10 17:24:02 -0700 | [diff] [blame] | 1802 | } else if (tagName.equals(TAG_DEFAULT_APPS)) { |
| 1803 | readDefaultAppsLPw(parser, userId); |
Vladislav Kuzkokov | 253984e | 2016-10-24 09:27:16 +0200 | [diff] [blame] | 1804 | } else if (tagName.equals(TAG_BLOCK_UNINSTALL_PACKAGES)) { |
| 1805 | readBlockUninstallPackagesLPw(parser, userId); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1806 | } else { |
| 1807 | Slog.w(PackageManagerService.TAG, "Unknown element under <stopped-packages>: " |
| 1808 | + parser.getName()); |
| 1809 | XmlUtils.skipCurrentTag(parser); |
| 1810 | } |
| 1811 | } |
| 1812 | |
| 1813 | str.close(); |
| 1814 | |
Christopher Tate | f0d6cb3 | 2015-07-10 17:44:53 -0700 | [diff] [blame] | 1815 | mNextAppLinkGeneration.put(userId, maxAppLinkGeneration + 1); |
| 1816 | |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1817 | } catch (XmlPullParserException e) { |
| 1818 | mReadMessages.append("Error reading: " + e.toString()); |
| 1819 | PackageManagerService.reportSettingsProblem(Log.ERROR, |
| 1820 | "Error reading stopped packages: " + e); |
Dianne Hackborn | 8d05172 | 2014-10-01 14:59:58 -0700 | [diff] [blame] | 1821 | Slog.wtf(PackageManagerService.TAG, "Error reading package manager stopped packages", |
| 1822 | e); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1823 | |
| 1824 | } catch (java.io.IOException e) { |
| 1825 | mReadMessages.append("Error reading: " + e.toString()); |
| 1826 | PackageManagerService.reportSettingsProblem(Log.ERROR, "Error reading settings: " + e); |
Dianne Hackborn | 8d05172 | 2014-10-01 14:59:58 -0700 | [diff] [blame] | 1827 | Slog.wtf(PackageManagerService.TAG, "Error reading package manager stopped packages", |
| 1828 | e); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1829 | } |
| 1830 | } |
| 1831 | |
Vladislav Kuzkokov | 253984e | 2016-10-24 09:27:16 +0200 | [diff] [blame] | 1832 | void setBlockUninstallLPw(int userId, String packageName, boolean blockUninstall) { |
| 1833 | ArraySet<String> packages = mBlockUninstallPackages.get(userId); |
| 1834 | if (blockUninstall) { |
| 1835 | if (packages == null) { |
| 1836 | packages = new ArraySet<String>(); |
| 1837 | mBlockUninstallPackages.put(userId, packages); |
| 1838 | } |
| 1839 | packages.add(packageName); |
| 1840 | } else if (packages != null) { |
| 1841 | packages.remove(packageName); |
| 1842 | if (packages.isEmpty()) { |
| 1843 | mBlockUninstallPackages.remove(userId); |
| 1844 | } |
| 1845 | } |
| 1846 | } |
| 1847 | |
| 1848 | boolean getBlockUninstallLPr(int userId, String packageName) { |
| 1849 | ArraySet<String> packages = mBlockUninstallPackages.get(userId); |
| 1850 | if (packages == null) { |
| 1851 | return false; |
| 1852 | } |
| 1853 | return packages.contains(packageName); |
| 1854 | } |
| 1855 | |
Jeff Sharkey | 9f837a9 | 2014-10-24 12:07:24 -0700 | [diff] [blame] | 1856 | private ArraySet<String> readComponentsLPr(XmlPullParser parser) |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1857 | throws IOException, XmlPullParserException { |
Jeff Sharkey | 9f837a9 | 2014-10-24 12:07:24 -0700 | [diff] [blame] | 1858 | ArraySet<String> components = null; |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1859 | int type; |
| 1860 | int outerDepth = parser.getDepth(); |
| 1861 | String tagName; |
| 1862 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 1863 | && (type != XmlPullParser.END_TAG |
| 1864 | || parser.getDepth() > outerDepth)) { |
| 1865 | if (type == XmlPullParser.END_TAG |
| 1866 | || type == XmlPullParser.TEXT) { |
| 1867 | continue; |
| 1868 | } |
| 1869 | tagName = parser.getName(); |
| 1870 | if (tagName.equals(TAG_ITEM)) { |
| 1871 | String componentName = parser.getAttributeValue(null, ATTR_NAME); |
| 1872 | if (componentName != null) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 1873 | if (components == null) { |
Jeff Sharkey | 9f837a9 | 2014-10-24 12:07:24 -0700 | [diff] [blame] | 1874 | components = new ArraySet<String>(); |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 1875 | } |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1876 | components.add(componentName); |
| 1877 | } |
| 1878 | } |
| 1879 | } |
| 1880 | return components; |
| 1881 | } |
| 1882 | |
Christopher Tate | e012a23 | 2015-04-01 17:18:50 -0700 | [diff] [blame] | 1883 | /** |
| 1884 | * Record the state of preferred activity configuration into XML. This is used both |
| 1885 | * for recording packages.xml internally and for supporting backup/restore of the |
| 1886 | * preferred activity configuration. |
| 1887 | */ |
Dianne Hackborn | 8a2ed1d | 2013-01-29 15:18:29 -0800 | [diff] [blame] | 1888 | void writePreferredActivitiesLPr(XmlSerializer serializer, int userId, boolean full) |
Dianne Hackborn | 6309271 | 2012-10-07 14:45:35 -0700 | [diff] [blame] | 1889 | throws IllegalArgumentException, IllegalStateException, IOException { |
| 1890 | serializer.startTag(null, "preferred-activities"); |
| 1891 | PreferredIntentResolver pir = mPreferredActivities.get(userId); |
| 1892 | if (pir != null) { |
| 1893 | for (final PreferredActivity pa : pir.filterSet()) { |
| 1894 | serializer.startTag(null, TAG_ITEM); |
Dianne Hackborn | 8a2ed1d | 2013-01-29 15:18:29 -0800 | [diff] [blame] | 1895 | pa.writeToXml(serializer, full); |
Dianne Hackborn | 6309271 | 2012-10-07 14:45:35 -0700 | [diff] [blame] | 1896 | serializer.endTag(null, TAG_ITEM); |
| 1897 | } |
| 1898 | } |
| 1899 | serializer.endTag(null, "preferred-activities"); |
| 1900 | } |
| 1901 | |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 1902 | void writePersistentPreferredActivitiesLPr(XmlSerializer serializer, int userId) |
| 1903 | throws IllegalArgumentException, IllegalStateException, IOException { |
Sander Alewijnse | af59762 | 2014-03-20 18:44:57 +0000 | [diff] [blame] | 1904 | serializer.startTag(null, TAG_PERSISTENT_PREFERRED_ACTIVITIES); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 1905 | PersistentPreferredIntentResolver ppir = mPersistentPreferredActivities.get(userId); |
| 1906 | if (ppir != null) { |
| 1907 | for (final PersistentPreferredActivity ppa : ppir.filterSet()) { |
| 1908 | serializer.startTag(null, TAG_ITEM); |
| 1909 | ppa.writeToXml(serializer); |
| 1910 | serializer.endTag(null, TAG_ITEM); |
| 1911 | } |
| 1912 | } |
Sander Alewijnse | af59762 | 2014-03-20 18:44:57 +0000 | [diff] [blame] | 1913 | serializer.endTag(null, TAG_PERSISTENT_PREFERRED_ACTIVITIES); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 1914 | } |
| 1915 | |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 1916 | void writeCrossProfileIntentFiltersLPr(XmlSerializer serializer, int userId) |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1917 | throws IllegalArgumentException, IllegalStateException, IOException { |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 1918 | serializer.startTag(null, TAG_CROSS_PROFILE_INTENT_FILTERS); |
| 1919 | CrossProfileIntentResolver cpir = mCrossProfileIntentResolvers.get(userId); |
| 1920 | if (cpir != null) { |
| 1921 | for (final CrossProfileIntentFilter cpif : cpir.filterSet()) { |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1922 | serializer.startTag(null, TAG_ITEM); |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 1923 | cpif.writeToXml(serializer); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1924 | serializer.endTag(null, TAG_ITEM); |
| 1925 | } |
| 1926 | } |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 1927 | serializer.endTag(null, TAG_CROSS_PROFILE_INTENT_FILTERS); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1928 | } |
| 1929 | |
Fabrice Di Meglio | 6227172 | 2015-04-10 17:24:02 -0700 | [diff] [blame] | 1930 | void writeDomainVerificationsLPr(XmlSerializer serializer, |
| 1931 | IntentFilterVerificationInfo verificationInfo) |
| 1932 | throws IllegalArgumentException, IllegalStateException, IOException { |
| 1933 | if (verificationInfo != null && verificationInfo.getPackageName() != null) { |
| 1934 | serializer.startTag(null, TAG_DOMAIN_VERIFICATION); |
| 1935 | verificationInfo.writeToXml(serializer); |
Christopher Tate | 72c10a2 | 2015-06-12 18:31:24 -0700 | [diff] [blame] | 1936 | if (DEBUG_DOMAIN_VERIFICATION) { |
| 1937 | Slog.d(TAG, "Wrote domain verification for package: " |
| 1938 | + verificationInfo.getPackageName()); |
| 1939 | } |
Fabrice Di Meglio | 6227172 | 2015-04-10 17:24:02 -0700 | [diff] [blame] | 1940 | serializer.endTag(null, TAG_DOMAIN_VERIFICATION); |
| 1941 | } |
| 1942 | } |
| 1943 | |
Christopher Tate | 6038d15 | 2015-06-17 13:07:46 -0700 | [diff] [blame] | 1944 | // Specifically for backup/restore |
| 1945 | void writeAllDomainVerificationsLPr(XmlSerializer serializer, int userId) |
| 1946 | throws IllegalArgumentException, IllegalStateException, IOException { |
| 1947 | serializer.startTag(null, TAG_ALL_INTENT_FILTER_VERIFICATION); |
| 1948 | final int N = mPackages.size(); |
| 1949 | for (int i = 0; i < N; i++) { |
| 1950 | PackageSetting ps = mPackages.valueAt(i); |
| 1951 | IntentFilterVerificationInfo ivi = ps.getIntentFilterVerificationInfo(); |
| 1952 | if (ivi != null) { |
| 1953 | writeDomainVerificationsLPr(serializer, ivi); |
| 1954 | } |
| 1955 | } |
| 1956 | serializer.endTag(null, TAG_ALL_INTENT_FILTER_VERIFICATION); |
| 1957 | } |
| 1958 | |
| 1959 | // Specifically for backup/restore |
| 1960 | void readAllDomainVerificationsLPr(XmlPullParser parser, int userId) |
| 1961 | throws XmlPullParserException, IOException { |
| 1962 | mRestoredIntentFilterVerifications.clear(); |
| 1963 | |
| 1964 | int outerDepth = parser.getDepth(); |
| 1965 | int type; |
| 1966 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 1967 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 1968 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 1969 | continue; |
| 1970 | } |
| 1971 | |
| 1972 | String tagName = parser.getName(); |
| 1973 | if (tagName.equals(TAG_DOMAIN_VERIFICATION)) { |
| 1974 | IntentFilterVerificationInfo ivi = new IntentFilterVerificationInfo(parser); |
| 1975 | final String pkgName = ivi.getPackageName(); |
| 1976 | final PackageSetting ps = mPackages.get(pkgName); |
| 1977 | if (ps != null) { |
| 1978 | // known/existing package; update in place |
| 1979 | ps.setIntentFilterVerificationInfo(ivi); |
| 1980 | if (DEBUG_DOMAIN_VERIFICATION) { |
| 1981 | Slog.d(TAG, "Restored IVI for existing app " + pkgName |
| 1982 | + " status=" + ivi.getStatusString()); |
| 1983 | } |
| 1984 | } else { |
| 1985 | mRestoredIntentFilterVerifications.put(pkgName, ivi); |
| 1986 | if (DEBUG_DOMAIN_VERIFICATION) { |
| 1987 | Slog.d(TAG, "Restored IVI for pending app " + pkgName |
| 1988 | + " status=" + ivi.getStatusString()); |
| 1989 | } |
| 1990 | } |
| 1991 | } else { |
| 1992 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 1993 | "Unknown element under <all-intent-filter-verification>: " |
| 1994 | + parser.getName()); |
| 1995 | XmlUtils.skipCurrentTag(parser); |
| 1996 | } |
| 1997 | } |
| 1998 | } |
| 1999 | |
Christopher Tate | e9fd1fa | 2015-09-15 16:43:07 -0700 | [diff] [blame] | 2000 | // Specifically for backup/restore |
| 2001 | public void processRestoredPermissionGrantLPr(String pkgName, String permission, |
Todd Kennedy | 91a39d1 | 2017-09-27 12:37:04 -0700 | [diff] [blame] | 2002 | boolean isGranted, int restoredFlagSet, int userId) { |
Christopher Tate | e9fd1fa | 2015-09-15 16:43:07 -0700 | [diff] [blame] | 2003 | mRuntimePermissionsPersistence.rememberRestoredUserGrantLPr( |
| 2004 | pkgName, permission, isGranted, restoredFlagSet, userId); |
| 2005 | } |
| 2006 | |
Fabrice Di Meglio | 6227172 | 2015-04-10 17:24:02 -0700 | [diff] [blame] | 2007 | void writeDefaultAppsLPr(XmlSerializer serializer, int userId) |
| 2008 | throws IllegalArgumentException, IllegalStateException, IOException { |
| 2009 | serializer.startTag(null, TAG_DEFAULT_APPS); |
Robin Lee | 0dc591b | 2016-05-04 13:01:46 +0100 | [diff] [blame] | 2010 | String defaultBrowser = mDefaultBrowserApp.get(userId); |
| 2011 | if (!TextUtils.isEmpty(defaultBrowser)) { |
Fabrice Di Meglio | 6227172 | 2015-04-10 17:24:02 -0700 | [diff] [blame] | 2012 | serializer.startTag(null, TAG_DEFAULT_BROWSER); |
Robin Lee | 0dc591b | 2016-05-04 13:01:46 +0100 | [diff] [blame] | 2013 | serializer.attribute(null, ATTR_PACKAGE_NAME, defaultBrowser); |
Fabrice Di Meglio | 6227172 | 2015-04-10 17:24:02 -0700 | [diff] [blame] | 2014 | serializer.endTag(null, TAG_DEFAULT_BROWSER); |
| 2015 | } |
Robin Lee | 0dc591b | 2016-05-04 13:01:46 +0100 | [diff] [blame] | 2016 | String defaultDialer = mDefaultDialerApp.get(userId); |
| 2017 | if (!TextUtils.isEmpty(defaultDialer)) { |
| 2018 | serializer.startTag(null, TAG_DEFAULT_DIALER); |
| 2019 | serializer.attribute(null, ATTR_PACKAGE_NAME, defaultDialer); |
| 2020 | serializer.endTag(null, TAG_DEFAULT_DIALER); |
| 2021 | } |
Fabrice Di Meglio | 6227172 | 2015-04-10 17:24:02 -0700 | [diff] [blame] | 2022 | serializer.endTag(null, TAG_DEFAULT_APPS); |
| 2023 | } |
| 2024 | |
Vladislav Kuzkokov | 253984e | 2016-10-24 09:27:16 +0200 | [diff] [blame] | 2025 | void writeBlockUninstallPackagesLPr(XmlSerializer serializer, int userId) |
| 2026 | throws IOException { |
| 2027 | ArraySet<String> packages = mBlockUninstallPackages.get(userId); |
| 2028 | if (packages != null) { |
| 2029 | serializer.startTag(null, TAG_BLOCK_UNINSTALL_PACKAGES); |
| 2030 | for (int i = 0; i < packages.size(); i++) { |
| 2031 | serializer.startTag(null, TAG_BLOCK_UNINSTALL); |
| 2032 | serializer.attribute(null, ATTR_PACKAGE_NAME, packages.valueAt(i)); |
| 2033 | serializer.endTag(null, TAG_BLOCK_UNINSTALL); |
| 2034 | } |
| 2035 | serializer.endTag(null, TAG_BLOCK_UNINSTALL_PACKAGES); |
| 2036 | } |
| 2037 | } |
| 2038 | |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2039 | void writePackageRestrictionsLPr(int userId) { |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 2040 | if (DEBUG_MU) { |
| 2041 | Log.i(TAG, "Writing package restrictions for user=" + userId); |
| 2042 | } |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2043 | // Keep the old stopped packages around until we know the new ones have |
| 2044 | // been successfully written. |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2045 | File userPackagesStateFile = getUserPackagesStateFile(userId); |
| 2046 | File backupFile = getUserPackagesStateBackupFile(userId); |
| 2047 | new File(userPackagesStateFile.getParent()).mkdirs(); |
| 2048 | if (userPackagesStateFile.exists()) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2049 | // Presence of backup settings file indicates that we failed |
| 2050 | // to persist packages earlier. So preserve the older |
| 2051 | // backup for future reference since the current packages |
| 2052 | // might have been corrupted. |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2053 | if (!backupFile.exists()) { |
| 2054 | if (!userPackagesStateFile.renameTo(backupFile)) { |
Dianne Hackborn | 8d05172 | 2014-10-01 14:59:58 -0700 | [diff] [blame] | 2055 | Slog.wtf(PackageManagerService.TAG, |
| 2056 | "Unable to backup user packages state file, " |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2057 | + "current changes will be lost at reboot"); |
| 2058 | return; |
| 2059 | } |
| 2060 | } else { |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2061 | userPackagesStateFile.delete(); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2062 | Slog.w(PackageManagerService.TAG, "Preserving older stopped packages backup"); |
| 2063 | } |
| 2064 | } |
| 2065 | |
| 2066 | try { |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2067 | final FileOutputStream fstr = new FileOutputStream(userPackagesStateFile); |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 2068 | final BufferedOutputStream str = new BufferedOutputStream(fstr); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2069 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 2070 | final XmlSerializer serializer = new FastXmlSerializer(); |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 2071 | serializer.setOutput(str, StandardCharsets.UTF_8.name()); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2072 | serializer.startDocument(null, true); |
| 2073 | serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true); |
| 2074 | |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2075 | serializer.startTag(null, TAG_PACKAGE_RESTRICTIONS); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2076 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 2077 | for (final PackageSetting pkg : mPackages.values()) { |
Jeff Sharkey | 4288419 | 2016-04-09 16:12:01 -0600 | [diff] [blame] | 2078 | final PackageUserState ustate = pkg.readUserState(userId); |
| 2079 | if (DEBUG_MU) Log.i(TAG, " pkg=" + pkg.name + ", state=" + ustate.enabled); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2080 | |
Jeff Sharkey | 4288419 | 2016-04-09 16:12:01 -0600 | [diff] [blame] | 2081 | serializer.startTag(null, TAG_PACKAGE); |
| 2082 | serializer.attribute(null, ATTR_NAME, pkg.name); |
| 2083 | if (ustate.ceDataInode != 0) { |
| 2084 | XmlUtils.writeLongAttribute(serializer, ATTR_CE_DATA_INODE, ustate.ceDataInode); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2085 | } |
Jeff Sharkey | 4288419 | 2016-04-09 16:12:01 -0600 | [diff] [blame] | 2086 | if (!ustate.installed) { |
| 2087 | serializer.attribute(null, ATTR_INSTALLED, "false"); |
| 2088 | } |
| 2089 | if (ustate.stopped) { |
| 2090 | serializer.attribute(null, ATTR_STOPPED, "true"); |
| 2091 | } |
| 2092 | if (ustate.notLaunched) { |
| 2093 | serializer.attribute(null, ATTR_NOT_LAUNCHED, "true"); |
| 2094 | } |
| 2095 | if (ustate.hidden) { |
| 2096 | serializer.attribute(null, ATTR_HIDDEN, "true"); |
| 2097 | } |
| 2098 | if (ustate.suspended) { |
| 2099 | serializer.attribute(null, ATTR_SUSPENDED, "true"); |
| 2100 | } |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 2101 | if (ustate.instantApp) { |
| 2102 | serializer.attribute(null, ATTR_INSTANT_APP, "true"); |
| 2103 | } |
Todd Kennedy | 5eb5a7d | 2017-08-01 07:42:47 -0700 | [diff] [blame] | 2104 | if (ustate.virtualPreload) { |
| 2105 | serializer.attribute(null, ATTR_VIRTUAL_PRELOAD, "true"); |
| 2106 | } |
Jeff Sharkey | 4288419 | 2016-04-09 16:12:01 -0600 | [diff] [blame] | 2107 | if (ustate.enabled != COMPONENT_ENABLED_STATE_DEFAULT) { |
| 2108 | serializer.attribute(null, ATTR_ENABLED, |
| 2109 | Integer.toString(ustate.enabled)); |
| 2110 | if (ustate.lastDisableAppCaller != null) { |
| 2111 | serializer.attribute(null, ATTR_ENABLED_CALLER, |
| 2112 | ustate.lastDisableAppCaller); |
| 2113 | } |
| 2114 | } |
| 2115 | if (ustate.domainVerificationStatus != |
| 2116 | PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_UNDEFINED) { |
| 2117 | XmlUtils.writeIntAttribute(serializer, ATTR_DOMAIN_VERIFICATON_STATE, |
| 2118 | ustate.domainVerificationStatus); |
| 2119 | } |
| 2120 | if (ustate.appLinkGeneration != 0) { |
| 2121 | XmlUtils.writeIntAttribute(serializer, ATTR_APP_LINK_GENERATION, |
| 2122 | ustate.appLinkGeneration); |
| 2123 | } |
Bartosz Fabianowski | a34f53f | 2017-01-11 18:08:47 +0100 | [diff] [blame] | 2124 | if (ustate.installReason != PackageManager.INSTALL_REASON_UNKNOWN) { |
| 2125 | serializer.attribute(null, ATTR_INSTALL_REASON, |
| 2126 | Integer.toString(ustate.installReason)); |
| 2127 | } |
Jeff Sharkey | 4288419 | 2016-04-09 16:12:01 -0600 | [diff] [blame] | 2128 | if (!ArrayUtils.isEmpty(ustate.enabledComponents)) { |
| 2129 | serializer.startTag(null, TAG_ENABLED_COMPONENTS); |
| 2130 | for (final String name : ustate.enabledComponents) { |
| 2131 | serializer.startTag(null, TAG_ITEM); |
| 2132 | serializer.attribute(null, ATTR_NAME, name); |
| 2133 | serializer.endTag(null, TAG_ITEM); |
| 2134 | } |
| 2135 | serializer.endTag(null, TAG_ENABLED_COMPONENTS); |
| 2136 | } |
| 2137 | if (!ArrayUtils.isEmpty(ustate.disabledComponents)) { |
| 2138 | serializer.startTag(null, TAG_DISABLED_COMPONENTS); |
| 2139 | for (final String name : ustate.disabledComponents) { |
| 2140 | serializer.startTag(null, TAG_ITEM); |
| 2141 | serializer.attribute(null, ATTR_NAME, name); |
| 2142 | serializer.endTag(null, TAG_ITEM); |
| 2143 | } |
| 2144 | serializer.endTag(null, TAG_DISABLED_COMPONENTS); |
| 2145 | } |
| 2146 | |
| 2147 | serializer.endTag(null, TAG_PACKAGE); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2148 | } |
| 2149 | |
Dianne Hackborn | 8a2ed1d | 2013-01-29 15:18:29 -0800 | [diff] [blame] | 2150 | writePreferredActivitiesLPr(serializer, userId, true); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 2151 | writePersistentPreferredActivitiesLPr(serializer, userId); |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 2152 | writeCrossProfileIntentFiltersLPr(serializer, userId); |
Fabrice Di Meglio | 6227172 | 2015-04-10 17:24:02 -0700 | [diff] [blame] | 2153 | writeDefaultAppsLPr(serializer, userId); |
Vladislav Kuzkokov | 253984e | 2016-10-24 09:27:16 +0200 | [diff] [blame] | 2154 | writeBlockUninstallPackagesLPr(serializer, userId); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 2155 | |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2156 | serializer.endTag(null, TAG_PACKAGE_RESTRICTIONS); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2157 | |
| 2158 | serializer.endDocument(); |
| 2159 | |
| 2160 | str.flush(); |
| 2161 | FileUtils.sync(fstr); |
| 2162 | str.close(); |
| 2163 | |
| 2164 | // New settings successfully written, old ones are no longer |
| 2165 | // needed. |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2166 | backupFile.delete(); |
| 2167 | FileUtils.setPermissions(userPackagesStateFile.toString(), |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2168 | FileUtils.S_IRUSR|FileUtils.S_IWUSR |
Nick Kralevich | 70522ad | 2012-01-06 13:58:01 -0800 | [diff] [blame] | 2169 | |FileUtils.S_IRGRP|FileUtils.S_IWGRP, |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2170 | -1, -1); |
| 2171 | |
| 2172 | // Done, all is good! |
| 2173 | return; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2174 | } catch(java.io.IOException e) { |
Dianne Hackborn | 8d05172 | 2014-10-01 14:59:58 -0700 | [diff] [blame] | 2175 | Slog.wtf(PackageManagerService.TAG, |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2176 | "Unable to write package manager user packages state, " |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2177 | + " current changes will be lost at reboot", e); |
| 2178 | } |
| 2179 | |
| 2180 | // Clean up partially written files |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2181 | if (userPackagesStateFile.exists()) { |
| 2182 | if (!userPackagesStateFile.delete()) { |
| 2183 | Log.i(PackageManagerService.TAG, "Failed to clean up mangled file: " |
| 2184 | + mStoppedPackagesFilename); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2185 | } |
| 2186 | } |
| 2187 | } |
| 2188 | |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 2189 | void readInstallPermissionsLPr(XmlPullParser parser, |
| 2190 | PermissionsState permissionsState) throws IOException, XmlPullParserException { |
| 2191 | int outerDepth = parser.getDepth(); |
| 2192 | int type; |
| 2193 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 2194 | && (type != XmlPullParser.END_TAG |
| 2195 | || parser.getDepth() > outerDepth)) { |
| 2196 | if (type == XmlPullParser.END_TAG |
| 2197 | || type == XmlPullParser.TEXT) { |
| 2198 | continue; |
| 2199 | } |
| 2200 | String tagName = parser.getName(); |
| 2201 | if (tagName.equals(TAG_ITEM)) { |
| 2202 | String name = parser.getAttributeValue(null, ATTR_NAME); |
| 2203 | |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 2204 | BasePermission bp = mPermissions.getPermission(name); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 2205 | if (bp == null) { |
| 2206 | Slog.w(PackageManagerService.TAG, "Unknown permission: " + name); |
| 2207 | XmlUtils.skipCurrentTag(parser); |
| 2208 | continue; |
| 2209 | } |
| 2210 | |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 2211 | String grantedStr = parser.getAttributeValue(null, ATTR_GRANTED); |
| 2212 | final boolean granted = grantedStr == null |
| 2213 | || Boolean.parseBoolean(grantedStr); |
| 2214 | |
| 2215 | String flagsStr = parser.getAttributeValue(null, ATTR_FLAGS); |
| 2216 | final int flags = (flagsStr != null) |
| 2217 | ? Integer.parseInt(flagsStr, 16) : 0; |
| 2218 | |
| 2219 | if (granted) { |
| 2220 | if (permissionsState.grantInstallPermission(bp) == |
| 2221 | PermissionsState.PERMISSION_OPERATION_FAILURE) { |
| 2222 | Slog.w(PackageManagerService.TAG, "Permission already added: " + name); |
| 2223 | XmlUtils.skipCurrentTag(parser); |
| 2224 | } else { |
| 2225 | permissionsState.updatePermissionFlags(bp, UserHandle.USER_ALL, |
| 2226 | PackageManager.MASK_PERMISSION_FLAGS, flags); |
| 2227 | } |
| 2228 | } else { |
| 2229 | if (permissionsState.revokeInstallPermission(bp) == |
| 2230 | PermissionsState.PERMISSION_OPERATION_FAILURE) { |
| 2231 | Slog.w(PackageManagerService.TAG, "Permission already added: " + name); |
| 2232 | XmlUtils.skipCurrentTag(parser); |
| 2233 | } else { |
| 2234 | permissionsState.updatePermissionFlags(bp, UserHandle.USER_ALL, |
| 2235 | PackageManager.MASK_PERMISSION_FLAGS, flags); |
| 2236 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 2237 | } |
| 2238 | } else { |
| 2239 | Slog.w(PackageManagerService.TAG, "Unknown element under <permissions>: " |
| 2240 | + parser.getName()); |
| 2241 | XmlUtils.skipCurrentTag(parser); |
| 2242 | } |
| 2243 | } |
| 2244 | } |
| 2245 | |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 2246 | void writePermissionsLPr(XmlSerializer serializer, List<PermissionState> permissionStates) |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 2247 | throws IOException { |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 2248 | if (permissionStates.isEmpty()) { |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 2249 | return; |
| 2250 | } |
| 2251 | |
| 2252 | serializer.startTag(null, TAG_PERMISSIONS); |
| 2253 | |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 2254 | for (PermissionState permissionState : permissionStates) { |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 2255 | serializer.startTag(null, TAG_ITEM); |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 2256 | serializer.attribute(null, ATTR_NAME, permissionState.getName()); |
| 2257 | serializer.attribute(null, ATTR_GRANTED, String.valueOf(permissionState.isGranted())); |
| 2258 | serializer.attribute(null, ATTR_FLAGS, Integer.toHexString(permissionState.getFlags())); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 2259 | serializer.endTag(null, TAG_ITEM); |
| 2260 | } |
| 2261 | |
| 2262 | serializer.endTag(null, TAG_PERMISSIONS); |
| 2263 | } |
| 2264 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2265 | void writeChildPackagesLPw(XmlSerializer serializer, List<String> childPackageNames) |
| 2266 | throws IOException { |
| 2267 | if (childPackageNames == null) { |
| 2268 | return; |
| 2269 | } |
| 2270 | final int childCount = childPackageNames.size(); |
| 2271 | for (int i = 0; i < childCount; i++) { |
| 2272 | String childPackageName = childPackageNames.get(i); |
| 2273 | serializer.startTag(null, TAG_CHILD_PACKAGE); |
| 2274 | serializer.attribute(null, ATTR_NAME, childPackageName); |
| 2275 | serializer.endTag(null, TAG_CHILD_PACKAGE); |
| 2276 | } |
| 2277 | } |
| 2278 | |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 2279 | void readUsesStaticLibLPw(XmlPullParser parser, PackageSetting outPs) |
| 2280 | throws IOException, XmlPullParserException { |
| 2281 | int outerDepth = parser.getDepth(); |
| 2282 | int type; |
| 2283 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 2284 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 2285 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 2286 | continue; |
| 2287 | } |
| 2288 | String libName = parser.getAttributeValue(null, ATTR_NAME); |
| 2289 | String libVersionStr = parser.getAttributeValue(null, ATTR_VERSION); |
| 2290 | |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 2291 | long libVersion = -1; |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 2292 | try { |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 2293 | libVersion = Long.parseLong(libVersionStr); |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 2294 | } catch (NumberFormatException e) { |
| 2295 | // ignore |
| 2296 | } |
| 2297 | |
| 2298 | if (libName != null && libVersion >= 0) { |
| 2299 | outPs.usesStaticLibraries = ArrayUtils.appendElement(String.class, |
| 2300 | outPs.usesStaticLibraries, libName); |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 2301 | outPs.usesStaticLibrariesVersions = ArrayUtils.appendLong( |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 2302 | outPs.usesStaticLibrariesVersions, libVersion); |
| 2303 | } |
| 2304 | |
| 2305 | XmlUtils.skipCurrentTag(parser); |
| 2306 | } |
| 2307 | } |
| 2308 | |
| 2309 | void writeUsesStaticLibLPw(XmlSerializer serializer, String[] usesStaticLibraries, |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 2310 | long[] usesStaticLibraryVersions) throws IOException { |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 2311 | if (ArrayUtils.isEmpty(usesStaticLibraries) || ArrayUtils.isEmpty(usesStaticLibraryVersions) |
| 2312 | || usesStaticLibraries.length != usesStaticLibraryVersions.length) { |
| 2313 | return; |
| 2314 | } |
| 2315 | final int libCount = usesStaticLibraries.length; |
| 2316 | for (int i = 0; i < libCount; i++) { |
| 2317 | final String libName = usesStaticLibraries[i]; |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 2318 | final long libVersion = usesStaticLibraryVersions[i]; |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 2319 | serializer.startTag(null, TAG_USES_STATIC_LIB); |
| 2320 | serializer.attribute(null, ATTR_NAME, libName); |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 2321 | serializer.attribute(null, ATTR_VERSION, Long.toString(libVersion)); |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 2322 | serializer.endTag(null, TAG_USES_STATIC_LIB); |
| 2323 | } |
| 2324 | } |
| 2325 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2326 | // Note: assumed "stopped" field is already cleared in all packages. |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2327 | // Legacy reader, used to read in the old file format after an upgrade. Not used after that. |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 2328 | void readStoppedLPw() { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2329 | FileInputStream str = null; |
| 2330 | if (mBackupStoppedPackagesFilename.exists()) { |
| 2331 | try { |
| 2332 | str = new FileInputStream(mBackupStoppedPackagesFilename); |
| 2333 | mReadMessages.append("Reading from backup stopped packages file\n"); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2334 | PackageManagerService.reportSettingsProblem(Log.INFO, |
| 2335 | "Need to read from backup stopped packages file"); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2336 | if (mSettingsFilename.exists()) { |
| 2337 | // If both the backup and normal file exist, we |
| 2338 | // ignore the normal one since it might have been |
| 2339 | // corrupted. |
| 2340 | Slog.w(PackageManagerService.TAG, "Cleaning up stopped packages file " |
| 2341 | + mStoppedPackagesFilename); |
| 2342 | mStoppedPackagesFilename.delete(); |
| 2343 | } |
| 2344 | } catch (java.io.IOException e) { |
| 2345 | // We'll try for the normal settings file. |
| 2346 | } |
| 2347 | } |
| 2348 | |
| 2349 | try { |
| 2350 | if (str == null) { |
| 2351 | if (!mStoppedPackagesFilename.exists()) { |
| 2352 | mReadMessages.append("No stopped packages file found\n"); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2353 | PackageManagerService.reportSettingsProblem(Log.INFO, |
| 2354 | "No stopped packages file file; assuming all started"); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2355 | // At first boot, make sure no packages are stopped. |
| 2356 | // We usually want to have third party apps initialize |
| 2357 | // in the stopped state, but not at first boot. |
| 2358 | for (PackageSetting pkg : mPackages.values()) { |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2359 | pkg.setStopped(false, 0); |
| 2360 | pkg.setNotLaunched(false, 0); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2361 | } |
| 2362 | return; |
| 2363 | } |
| 2364 | str = new FileInputStream(mStoppedPackagesFilename); |
| 2365 | } |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 2366 | final XmlPullParser parser = Xml.newPullParser(); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2367 | parser.setInput(str, null); |
| 2368 | |
| 2369 | int type; |
| 2370 | while ((type=parser.next()) != XmlPullParser.START_TAG |
| 2371 | && type != XmlPullParser.END_DOCUMENT) { |
| 2372 | ; |
| 2373 | } |
| 2374 | |
| 2375 | if (type != XmlPullParser.START_TAG) { |
| 2376 | mReadMessages.append("No start tag found in stopped packages file\n"); |
| 2377 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 2378 | "No start tag found in package manager stopped packages"); |
| 2379 | return; |
| 2380 | } |
| 2381 | |
| 2382 | int outerDepth = parser.getDepth(); |
| 2383 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 2384 | && (type != XmlPullParser.END_TAG |
| 2385 | || parser.getDepth() > outerDepth)) { |
| 2386 | if (type == XmlPullParser.END_TAG |
| 2387 | || type == XmlPullParser.TEXT) { |
| 2388 | continue; |
| 2389 | } |
| 2390 | |
| 2391 | String tagName = parser.getName(); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2392 | if (tagName.equals(TAG_PACKAGE)) { |
| 2393 | String name = parser.getAttributeValue(null, ATTR_NAME); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2394 | PackageSetting ps = mPackages.get(name); |
| 2395 | if (ps != null) { |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2396 | ps.setStopped(true, 0); |
| 2397 | if ("1".equals(parser.getAttributeValue(null, ATTR_NOT_LAUNCHED))) { |
| 2398 | ps.setNotLaunched(true, 0); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2399 | } |
| 2400 | } else { |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2401 | Slog.w(PackageManagerService.TAG, |
Jeff Sharkey | e06b4d1 | 2016-01-06 14:51:50 -0700 | [diff] [blame] | 2402 | "No package known for stopped package " + name); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2403 | } |
| 2404 | XmlUtils.skipCurrentTag(parser); |
| 2405 | } else { |
| 2406 | Slog.w(PackageManagerService.TAG, "Unknown element under <stopped-packages>: " |
| 2407 | + parser.getName()); |
| 2408 | XmlUtils.skipCurrentTag(parser); |
| 2409 | } |
| 2410 | } |
| 2411 | |
| 2412 | str.close(); |
| 2413 | |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2414 | } catch (XmlPullParserException e) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2415 | mReadMessages.append("Error reading: " + e.toString()); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2416 | PackageManagerService.reportSettingsProblem(Log.ERROR, |
| 2417 | "Error reading stopped packages: " + e); |
Dianne Hackborn | 8d05172 | 2014-10-01 14:59:58 -0700 | [diff] [blame] | 2418 | Slog.wtf(PackageManagerService.TAG, "Error reading package manager stopped packages", |
| 2419 | e); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2420 | |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2421 | } catch (java.io.IOException e) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2422 | mReadMessages.append("Error reading: " + e.toString()); |
| 2423 | PackageManagerService.reportSettingsProblem(Log.ERROR, "Error reading settings: " + e); |
Dianne Hackborn | 8d05172 | 2014-10-01 14:59:58 -0700 | [diff] [blame] | 2424 | Slog.wtf(PackageManagerService.TAG, "Error reading package manager stopped packages", |
| 2425 | e); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2426 | |
| 2427 | } |
| 2428 | } |
| 2429 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 2430 | void writeLPr() { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2431 | //Debug.startMethodTracing("/data/system/packageprof", 8 * 1024 * 1024); |
| 2432 | |
| 2433 | // Keep the old settings around until we know the new ones have |
| 2434 | // been successfully written. |
| 2435 | if (mSettingsFilename.exists()) { |
| 2436 | // Presence of backup settings file indicates that we failed |
| 2437 | // to persist settings earlier. So preserve the older |
| 2438 | // backup for future reference since the current settings |
| 2439 | // might have been corrupted. |
| 2440 | if (!mBackupSettingsFilename.exists()) { |
| 2441 | if (!mSettingsFilename.renameTo(mBackupSettingsFilename)) { |
Dianne Hackborn | 8d05172 | 2014-10-01 14:59:58 -0700 | [diff] [blame] | 2442 | Slog.wtf(PackageManagerService.TAG, |
| 2443 | "Unable to backup package manager settings, " |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2444 | + " current changes will be lost at reboot"); |
| 2445 | return; |
| 2446 | } |
| 2447 | } else { |
| 2448 | mSettingsFilename.delete(); |
| 2449 | Slog.w(PackageManagerService.TAG, "Preserving older settings backup"); |
| 2450 | } |
| 2451 | } |
| 2452 | |
| 2453 | mPastSignatures.clear(); |
| 2454 | |
| 2455 | try { |
| 2456 | FileOutputStream fstr = new FileOutputStream(mSettingsFilename); |
| 2457 | BufferedOutputStream str = new BufferedOutputStream(fstr); |
| 2458 | |
| 2459 | //XmlSerializer serializer = XmlUtils.serializerInstance(); |
| 2460 | XmlSerializer serializer = new FastXmlSerializer(); |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 2461 | serializer.setOutput(str, StandardCharsets.UTF_8.name()); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2462 | serializer.startDocument(null, true); |
| 2463 | serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true); |
| 2464 | |
| 2465 | serializer.startTag(null, "packages"); |
| 2466 | |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 2467 | for (int i = 0; i < mVersion.size(); i++) { |
| 2468 | final String volumeUuid = mVersion.keyAt(i); |
| 2469 | final VersionInfo ver = mVersion.valueAt(i); |
Jeff Sharkey | edc84ee8 | 2012-03-19 16:52:26 -0700 | [diff] [blame] | 2470 | |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 2471 | serializer.startTag(null, TAG_VERSION); |
| 2472 | XmlUtils.writeStringAttribute(serializer, ATTR_VOLUME_UUID, volumeUuid); |
| 2473 | XmlUtils.writeIntAttribute(serializer, ATTR_SDK_VERSION, ver.sdkVersion); |
| 2474 | XmlUtils.writeIntAttribute(serializer, ATTR_DATABASE_VERSION, ver.databaseVersion); |
| 2475 | XmlUtils.writeStringAttribute(serializer, ATTR_FINGERPRINT, ver.fingerprint); |
| 2476 | serializer.endTag(null, TAG_VERSION); |
| 2477 | } |
Kenny Root | c1c0d3c | 2014-04-24 13:36:40 -0700 | [diff] [blame] | 2478 | |
Kenny Root | 0aaa0d9 | 2011-09-12 16:42:55 -0700 | [diff] [blame] | 2479 | if (mVerifierDeviceIdentity != null) { |
| 2480 | serializer.startTag(null, "verifier"); |
| 2481 | serializer.attribute(null, "device", mVerifierDeviceIdentity.toString()); |
| 2482 | serializer.endTag(null, "verifier"); |
| 2483 | } |
| 2484 | |
Jeff Sharkey | f538577 | 2012-05-11 14:04:41 -0700 | [diff] [blame] | 2485 | if (mReadExternalStorageEnforced != null) { |
Jeff Sharkey | edc84ee8 | 2012-03-19 16:52:26 -0700 | [diff] [blame] | 2486 | serializer.startTag(null, TAG_READ_EXTERNAL_STORAGE); |
| 2487 | serializer.attribute( |
Jeff Sharkey | 5d32e77 | 2012-04-12 15:59:23 -0700 | [diff] [blame] | 2488 | null, ATTR_ENFORCEMENT, mReadExternalStorageEnforced ? "1" : "0"); |
Jeff Sharkey | edc84ee8 | 2012-03-19 16:52:26 -0700 | [diff] [blame] | 2489 | serializer.endTag(null, TAG_READ_EXTERNAL_STORAGE); |
| 2490 | } |
| 2491 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2492 | serializer.startTag(null, "permission-trees"); |
Todd Kennedy | c842393 | 2017-10-05 08:58:36 -0700 | [diff] [blame] | 2493 | mPermissions.writePermissionTrees(serializer); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2494 | serializer.endTag(null, "permission-trees"); |
| 2495 | |
| 2496 | serializer.startTag(null, "permissions"); |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 2497 | mPermissions.writePermissions(serializer); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2498 | serializer.endTag(null, "permissions"); |
| 2499 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 2500 | for (final PackageSetting pkg : mPackages.values()) { |
| 2501 | writePackageLPr(serializer, pkg); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2502 | } |
| 2503 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 2504 | for (final PackageSetting pkg : mDisabledSysPackages.values()) { |
| 2505 | writeDisabledSysPackageLPr(serializer, pkg); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2506 | } |
| 2507 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 2508 | for (final SharedUserSetting usr : mSharedUsers.values()) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2509 | serializer.startTag(null, "shared-user"); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2510 | serializer.attribute(null, ATTR_NAME, usr.name); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2511 | serializer.attribute(null, "userId", |
| 2512 | Integer.toString(usr.userId)); |
| 2513 | usr.signatures.writeXml(serializer, "sigs", mPastSignatures); |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 2514 | writePermissionsLPr(serializer, usr.getPermissionsState() |
| 2515 | .getInstallPermissionStates()); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2516 | serializer.endTag(null, "shared-user"); |
| 2517 | } |
| 2518 | |
| 2519 | if (mPackagesToBeCleaned.size() > 0) { |
Jeff Sharkey | 752cd92 | 2012-09-23 16:25:12 -0700 | [diff] [blame] | 2520 | for (PackageCleanItem item : mPackagesToBeCleaned) { |
| 2521 | final String userStr = Integer.toString(item.userId); |
| 2522 | serializer.startTag(null, "cleaning-package"); |
| 2523 | serializer.attribute(null, ATTR_NAME, item.packageName); |
| 2524 | serializer.attribute(null, ATTR_CODE, item.andCode ? "true" : "false"); |
| 2525 | serializer.attribute(null, ATTR_USER, userStr); |
| 2526 | serializer.endTag(null, "cleaning-package"); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2527 | } |
| 2528 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 2529 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2530 | if (mRenamedPackages.size() > 0) { |
Andy McFadden | 2f36229 | 2012-01-20 14:43:38 -0800 | [diff] [blame] | 2531 | for (Map.Entry<String, String> e : mRenamedPackages.entrySet()) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2532 | serializer.startTag(null, "renamed-package"); |
| 2533 | serializer.attribute(null, "new", e.getKey()); |
| 2534 | serializer.attribute(null, "old", e.getValue()); |
| 2535 | serializer.endTag(null, "renamed-package"); |
| 2536 | } |
| 2537 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 2538 | |
Christopher Tate | 6038d15 | 2015-06-17 13:07:46 -0700 | [diff] [blame] | 2539 | final int numIVIs = mRestoredIntentFilterVerifications.size(); |
| 2540 | if (numIVIs > 0) { |
| 2541 | if (DEBUG_DOMAIN_VERIFICATION) { |
| 2542 | Slog.i(TAG, "Writing restored-ivi entries to packages.xml"); |
| 2543 | } |
| 2544 | serializer.startTag(null, "restored-ivi"); |
| 2545 | for (int i = 0; i < numIVIs; i++) { |
| 2546 | IntentFilterVerificationInfo ivi = mRestoredIntentFilterVerifications.valueAt(i); |
| 2547 | writeDomainVerificationsLPr(serializer, ivi); |
| 2548 | } |
| 2549 | serializer.endTag(null, "restored-ivi"); |
| 2550 | } else { |
| 2551 | if (DEBUG_DOMAIN_VERIFICATION) { |
| 2552 | Slog.i(TAG, " no restored IVI entries to write"); |
| 2553 | } |
| 2554 | } |
| 2555 | |
dcashman | 55b1078 | 2014-04-09 14:20:38 -0700 | [diff] [blame] | 2556 | mKeySetManagerService.writeKeySetManagerServiceLPr(serializer); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2557 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2558 | serializer.endTag(null, "packages"); |
| 2559 | |
| 2560 | serializer.endDocument(); |
| 2561 | |
| 2562 | str.flush(); |
| 2563 | FileUtils.sync(fstr); |
| 2564 | str.close(); |
| 2565 | |
| 2566 | // New settings successfully written, old ones are no longer |
| 2567 | // needed. |
| 2568 | mBackupSettingsFilename.delete(); |
| 2569 | FileUtils.setPermissions(mSettingsFilename.toString(), |
| 2570 | FileUtils.S_IRUSR|FileUtils.S_IWUSR |
Nick Kralevich | 70522ad | 2012-01-06 13:58:01 -0800 | [diff] [blame] | 2571 | |FileUtils.S_IRGRP|FileUtils.S_IWGRP, |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2572 | -1, -1); |
| 2573 | |
Jeff Sharkey | 2271ba3 | 2016-02-01 17:57:08 -0700 | [diff] [blame] | 2574 | writeKernelMappingLPr(); |
Jeff Sharkey | 91edde2 | 2015-05-20 12:04:42 -0700 | [diff] [blame] | 2575 | writePackageListLPr(); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2576 | writeAllUsersPackageRestrictionsLPr(); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 2577 | writeAllRuntimePermissionsLPr(); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2578 | return; |
| 2579 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2580 | } catch(java.io.IOException e) { |
Dianne Hackborn | 8d05172 | 2014-10-01 14:59:58 -0700 | [diff] [blame] | 2581 | Slog.wtf(PackageManagerService.TAG, "Unable to write package manager settings, " |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2582 | + "current changes will be lost at reboot", e); |
| 2583 | } |
| 2584 | // Clean up partially written files |
| 2585 | if (mSettingsFilename.exists()) { |
| 2586 | if (!mSettingsFilename.delete()) { |
Dianne Hackborn | 8d05172 | 2014-10-01 14:59:58 -0700 | [diff] [blame] | 2587 | Slog.wtf(PackageManagerService.TAG, "Failed to clean up mangled file: " |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2588 | + mSettingsFilename); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2589 | } |
| 2590 | } |
| 2591 | //Debug.stopMethodTracing(); |
| 2592 | } |
| 2593 | |
Amith Yamasani | 23ab7f5 | 2017-01-22 17:43:24 -0800 | [diff] [blame] | 2594 | private void writeKernelRemoveUserLPr(int userId) { |
| 2595 | if (mKernelMappingFilename == null) return; |
| 2596 | |
| 2597 | File removeUserIdFile = new File(mKernelMappingFilename, "remove_userid"); |
| 2598 | if (DEBUG_KERNEL) Slog.d(TAG, "Writing " + userId + " to " + removeUserIdFile |
| 2599 | .getAbsolutePath()); |
| 2600 | writeIntToFile(removeUserIdFile, userId); |
| 2601 | } |
| 2602 | |
Jeff Sharkey | 2271ba3 | 2016-02-01 17:57:08 -0700 | [diff] [blame] | 2603 | void writeKernelMappingLPr() { |
| 2604 | if (mKernelMappingFilename == null) return; |
| 2605 | |
| 2606 | final String[] known = mKernelMappingFilename.list(); |
| 2607 | final ArraySet<String> knownSet = new ArraySet<>(known.length); |
| 2608 | for (String name : known) { |
| 2609 | knownSet.add(name); |
| 2610 | } |
| 2611 | |
| 2612 | for (final PackageSetting ps : mPackages.values()) { |
| 2613 | // Package is actively claimed |
| 2614 | knownSet.remove(ps.name); |
| 2615 | writeKernelMappingLPr(ps); |
| 2616 | } |
| 2617 | |
| 2618 | // Remove any unclaimed mappings |
| 2619 | for (int i = 0; i < knownSet.size(); i++) { |
| 2620 | final String name = knownSet.valueAt(i); |
| 2621 | if (DEBUG_KERNEL) Slog.d(TAG, "Dropping mapping " + name); |
| 2622 | |
| 2623 | mKernelMapping.remove(name); |
Jeff Sharkey | 800efcc | 2016-02-25 17:08:11 -0700 | [diff] [blame] | 2624 | new File(mKernelMappingFilename, name).delete(); |
Jeff Sharkey | 2271ba3 | 2016-02-01 17:57:08 -0700 | [diff] [blame] | 2625 | } |
| 2626 | } |
| 2627 | |
| 2628 | void writeKernelMappingLPr(PackageSetting ps) { |
Amith Yamasani | 23ab7f5 | 2017-01-22 17:43:24 -0800 | [diff] [blame] | 2629 | if (mKernelMappingFilename == null || ps == null || ps.name == null) return; |
Jeff Sharkey | 2271ba3 | 2016-02-01 17:57:08 -0700 | [diff] [blame] | 2630 | |
Amith Yamasani | 23ab7f5 | 2017-01-22 17:43:24 -0800 | [diff] [blame] | 2631 | KernelPackageState cur = mKernelMapping.get(ps.name); |
| 2632 | final boolean firstTime = cur == null; |
| 2633 | int[] excludedUserIds = ps.getNotInstalledUserIds(); |
| 2634 | final boolean userIdsChanged = firstTime |
| 2635 | || !Arrays.equals(excludedUserIds, cur.excludedUserIds); |
| 2636 | |
| 2637 | // Package directory |
| 2638 | final File dir = new File(mKernelMappingFilename, ps.name); |
| 2639 | |
| 2640 | if (firstTime) { |
| 2641 | dir.mkdir(); |
| 2642 | // Create a new mapping state |
| 2643 | cur = new KernelPackageState(); |
| 2644 | mKernelMapping.put(ps.name, cur); |
Jeff Sharkey | 2271ba3 | 2016-02-01 17:57:08 -0700 | [diff] [blame] | 2645 | } |
| 2646 | |
Amith Yamasani | 23ab7f5 | 2017-01-22 17:43:24 -0800 | [diff] [blame] | 2647 | // If mapping is incorrect or non-existent, write the appid file |
| 2648 | if (cur.appId != ps.appId) { |
| 2649 | final File appIdFile = new File(dir, "appid"); |
| 2650 | writeIntToFile(appIdFile, ps.appId); |
| 2651 | if (DEBUG_KERNEL) Slog.d(TAG, "Mapping " + ps.name + " to " + ps.appId); |
| 2652 | } |
Jeff Sharkey | 2271ba3 | 2016-02-01 17:57:08 -0700 | [diff] [blame] | 2653 | |
Amith Yamasani | 23ab7f5 | 2017-01-22 17:43:24 -0800 | [diff] [blame] | 2654 | if (userIdsChanged) { |
| 2655 | // Build the exclusion list -- the ids to add to the exclusion list |
| 2656 | for (int i = 0; i < excludedUserIds.length; i++) { |
| 2657 | if (cur.excludedUserIds == null || !ArrayUtils.contains(cur.excludedUserIds, |
| 2658 | excludedUserIds[i])) { |
| 2659 | writeIntToFile(new File(dir, "excluded_userids"), excludedUserIds[i]); |
| 2660 | if (DEBUG_KERNEL) Slog.d(TAG, "Writing " + excludedUserIds[i] + " to " |
| 2661 | + ps.name + "/excluded_userids"); |
| 2662 | } |
| 2663 | } |
| 2664 | // Build the inclusion list -- the ids to remove from the exclusion list |
| 2665 | if (cur.excludedUserIds != null) { |
| 2666 | for (int i = 0; i < cur.excludedUserIds.length; i++) { |
| 2667 | if (!ArrayUtils.contains(excludedUserIds, cur.excludedUserIds[i])) { |
| 2668 | writeIntToFile(new File(dir, "clear_userid"), |
| 2669 | cur.excludedUserIds[i]); |
| 2670 | if (DEBUG_KERNEL) Slog.d(TAG, "Writing " + cur.excludedUserIds[i] + " to " |
| 2671 | + ps.name + "/clear_userid"); |
Jeff Sharkey | 2271ba3 | 2016-02-01 17:57:08 -0700 | [diff] [blame] | 2672 | |
Amith Yamasani | 23ab7f5 | 2017-01-22 17:43:24 -0800 | [diff] [blame] | 2673 | } |
| 2674 | } |
| 2675 | } |
| 2676 | cur.excludedUserIds = excludedUserIds; |
| 2677 | } |
| 2678 | } |
| 2679 | |
| 2680 | private void writeIntToFile(File file, int value) { |
Jeff Sharkey | 2271ba3 | 2016-02-01 17:57:08 -0700 | [diff] [blame] | 2681 | try { |
Narayan Kamath | 6d051fc | 2016-11-22 20:20:00 +0000 | [diff] [blame] | 2682 | FileUtils.bytesToFile(file.getAbsolutePath(), |
Amith Yamasani | 23ab7f5 | 2017-01-22 17:43:24 -0800 | [diff] [blame] | 2683 | Integer.toString(value).getBytes(StandardCharsets.US_ASCII)); |
Jeff Sharkey | 2271ba3 | 2016-02-01 17:57:08 -0700 | [diff] [blame] | 2684 | } catch (IOException ignored) { |
Amith Yamasani | 23ab7f5 | 2017-01-22 17:43:24 -0800 | [diff] [blame] | 2685 | Slog.w(TAG, "Couldn't write " + value + " to " + file.getAbsolutePath()); |
Jeff Sharkey | 2271ba3 | 2016-02-01 17:57:08 -0700 | [diff] [blame] | 2686 | } |
| 2687 | } |
| 2688 | |
Jeff Sharkey | 91edde2 | 2015-05-20 12:04:42 -0700 | [diff] [blame] | 2689 | void writePackageListLPr() { |
| 2690 | writePackageListLPr(-1); |
| 2691 | } |
| 2692 | |
| 2693 | void writePackageListLPr(int creatingUserId) { |
| 2694 | // Only derive GIDs for active users (not dying) |
| 2695 | final List<UserInfo> users = UserManagerService.getInstance().getUsers(true); |
| 2696 | int[] userIds = new int[users.size()]; |
| 2697 | for (int i = 0; i < userIds.length; i++) { |
| 2698 | userIds[i] = users.get(i).id; |
| 2699 | } |
| 2700 | if (creatingUserId != -1) { |
| 2701 | userIds = ArrayUtils.appendInt(userIds, creatingUserId); |
| 2702 | } |
| 2703 | |
| 2704 | // Write package list file now, use a JournaledFile. |
| 2705 | File tempFile = new File(mPackageListFilename.getAbsolutePath() + ".tmp"); |
| 2706 | JournaledFile journal = new JournaledFile(mPackageListFilename, tempFile); |
| 2707 | |
| 2708 | final File writeTarget = journal.chooseForWrite(); |
Fyodor Kupolov | b69056b | 2015-12-18 15:20:00 -0800 | [diff] [blame] | 2709 | FileOutputStream fstr; |
| 2710 | BufferedWriter writer = null; |
Jeff Sharkey | 91edde2 | 2015-05-20 12:04:42 -0700 | [diff] [blame] | 2711 | try { |
| 2712 | fstr = new FileOutputStream(writeTarget); |
Fyodor Kupolov | b69056b | 2015-12-18 15:20:00 -0800 | [diff] [blame] | 2713 | writer = new BufferedWriter(new OutputStreamWriter(fstr, Charset.defaultCharset())); |
Jeff Sharkey | 91edde2 | 2015-05-20 12:04:42 -0700 | [diff] [blame] | 2714 | FileUtils.setPermissions(fstr.getFD(), 0640, SYSTEM_UID, PACKAGE_INFO_GID); |
| 2715 | |
| 2716 | StringBuilder sb = new StringBuilder(); |
| 2717 | for (final PackageSetting pkg : mPackages.values()) { |
Jeff Sharkey | e17ac15 | 2015-11-06 22:40:29 -0800 | [diff] [blame] | 2718 | if (pkg.pkg == null || pkg.pkg.applicationInfo == null |
| 2719 | || pkg.pkg.applicationInfo.dataDir == null) { |
Jeff Sharkey | 2271ba3 | 2016-02-01 17:57:08 -0700 | [diff] [blame] | 2720 | if (!"android".equals(pkg.name)) { |
| 2721 | Slog.w(TAG, "Skipping " + pkg + " due to missing metadata"); |
| 2722 | } |
Jeff Sharkey | 91edde2 | 2015-05-20 12:04:42 -0700 | [diff] [blame] | 2723 | continue; |
| 2724 | } |
| 2725 | |
| 2726 | final ApplicationInfo ai = pkg.pkg.applicationInfo; |
Jeff Sharkey | e84bdd3 | 2016-02-08 12:16:00 -0700 | [diff] [blame] | 2727 | final String dataPath = ai.dataDir; |
Jeff Sharkey | 91edde2 | 2015-05-20 12:04:42 -0700 | [diff] [blame] | 2728 | final boolean isDebug = (ai.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0; |
| 2729 | final int[] gids = pkg.getPermissionsState().computeGids(userIds); |
| 2730 | |
| 2731 | // Avoid any application that has a space in its path. |
Fyodor Kupolov | b69056b | 2015-12-18 15:20:00 -0800 | [diff] [blame] | 2732 | if (dataPath.indexOf(' ') >= 0) |
Jeff Sharkey | 91edde2 | 2015-05-20 12:04:42 -0700 | [diff] [blame] | 2733 | continue; |
| 2734 | |
| 2735 | // we store on each line the following information for now: |
| 2736 | // |
| 2737 | // pkgName - package name |
| 2738 | // userId - application-specific user id |
| 2739 | // debugFlag - 0 or 1 if the package is debuggable. |
| 2740 | // dataPath - path to package's data path |
| 2741 | // seinfo - seinfo label for the app (assigned at install time) |
| 2742 | // gids - supplementary gids this app launches with |
| 2743 | // |
| 2744 | // NOTE: We prefer not to expose all ApplicationInfo flags for now. |
| 2745 | // |
| 2746 | // DO NOT MODIFY THIS FORMAT UNLESS YOU CAN ALSO MODIFY ITS USERS |
| 2747 | // FROM NATIVE CODE. AT THE MOMENT, LOOK AT THE FOLLOWING SOURCES: |
William Roberts | dc06bb0 | 2015-07-24 10:05:06 -0700 | [diff] [blame] | 2748 | // frameworks/base/libs/packagelistparser |
Jeff Sharkey | 91edde2 | 2015-05-20 12:04:42 -0700 | [diff] [blame] | 2749 | // system/core/run-as/run-as.c |
Jeff Sharkey | 91edde2 | 2015-05-20 12:04:42 -0700 | [diff] [blame] | 2750 | // |
| 2751 | sb.setLength(0); |
| 2752 | sb.append(ai.packageName); |
| 2753 | sb.append(" "); |
Fyodor Kupolov | b69056b | 2015-12-18 15:20:00 -0800 | [diff] [blame] | 2754 | sb.append(ai.uid); |
Jeff Sharkey | 91edde2 | 2015-05-20 12:04:42 -0700 | [diff] [blame] | 2755 | sb.append(isDebug ? " 1 " : " 0 "); |
| 2756 | sb.append(dataPath); |
| 2757 | sb.append(" "); |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 2758 | sb.append(ai.seInfo); |
Jeff Sharkey | 91edde2 | 2015-05-20 12:04:42 -0700 | [diff] [blame] | 2759 | sb.append(" "); |
| 2760 | if (gids != null && gids.length > 0) { |
| 2761 | sb.append(gids[0]); |
| 2762 | for (int i = 1; i < gids.length; i++) { |
| 2763 | sb.append(","); |
| 2764 | sb.append(gids[i]); |
| 2765 | } |
| 2766 | } else { |
| 2767 | sb.append("none"); |
| 2768 | } |
| 2769 | sb.append("\n"); |
Fyodor Kupolov | b69056b | 2015-12-18 15:20:00 -0800 | [diff] [blame] | 2770 | writer.append(sb); |
Jeff Sharkey | 91edde2 | 2015-05-20 12:04:42 -0700 | [diff] [blame] | 2771 | } |
Fyodor Kupolov | b69056b | 2015-12-18 15:20:00 -0800 | [diff] [blame] | 2772 | writer.flush(); |
Jeff Sharkey | 91edde2 | 2015-05-20 12:04:42 -0700 | [diff] [blame] | 2773 | FileUtils.sync(fstr); |
Fyodor Kupolov | b69056b | 2015-12-18 15:20:00 -0800 | [diff] [blame] | 2774 | writer.close(); |
Jeff Sharkey | 91edde2 | 2015-05-20 12:04:42 -0700 | [diff] [blame] | 2775 | journal.commit(); |
| 2776 | } catch (Exception e) { |
| 2777 | Slog.wtf(TAG, "Failed to write packages.list", e); |
Fyodor Kupolov | b69056b | 2015-12-18 15:20:00 -0800 | [diff] [blame] | 2778 | IoUtils.closeQuietly(writer); |
Jeff Sharkey | 91edde2 | 2015-05-20 12:04:42 -0700 | [diff] [blame] | 2779 | journal.rollback(); |
| 2780 | } |
| 2781 | } |
| 2782 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 2783 | void writeDisabledSysPackageLPr(XmlSerializer serializer, final PackageSetting pkg) |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2784 | throws java.io.IOException { |
| 2785 | serializer.startTag(null, "updated-package"); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2786 | serializer.attribute(null, ATTR_NAME, pkg.name); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2787 | if (pkg.realName != null) { |
| 2788 | serializer.attribute(null, "realName", pkg.realName); |
| 2789 | } |
| 2790 | serializer.attribute(null, "codePath", pkg.codePathString); |
| 2791 | serializer.attribute(null, "ft", Long.toHexString(pkg.timeStamp)); |
| 2792 | serializer.attribute(null, "it", Long.toHexString(pkg.firstInstallTime)); |
| 2793 | serializer.attribute(null, "ut", Long.toHexString(pkg.lastUpdateTime)); |
| 2794 | serializer.attribute(null, "version", String.valueOf(pkg.versionCode)); |
| 2795 | if (!pkg.resourcePathString.equals(pkg.codePathString)) { |
| 2796 | serializer.attribute(null, "resourcePath", pkg.resourcePathString); |
| 2797 | } |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 2798 | if (pkg.legacyNativeLibraryPathString != null) { |
| 2799 | serializer.attribute(null, "nativeLibraryPath", pkg.legacyNativeLibraryPathString); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2800 | } |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 2801 | if (pkg.primaryCpuAbiString != null) { |
| 2802 | serializer.attribute(null, "primaryCpuAbi", pkg.primaryCpuAbiString); |
Narayan Kamath | 9e289d7 | 2014-04-10 09:26:59 +0000 | [diff] [blame] | 2803 | } |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 2804 | if (pkg.secondaryCpuAbiString != null) { |
| 2805 | serializer.attribute(null, "secondaryCpuAbi", pkg.secondaryCpuAbiString); |
| 2806 | } |
Narayan Kamath | 4903f64 | 2014-08-11 13:33:45 +0100 | [diff] [blame] | 2807 | if (pkg.cpuAbiOverrideString != null) { |
| 2808 | serializer.attribute(null, "cpuAbiOverride", pkg.cpuAbiOverrideString); |
| 2809 | } |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 2810 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2811 | if (pkg.sharedUser == null) { |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 2812 | serializer.attribute(null, "userId", Integer.toString(pkg.appId)); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2813 | } else { |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 2814 | serializer.attribute(null, "sharedUserId", Integer.toString(pkg.appId)); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2815 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 2816 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2817 | if (pkg.parentPackageName != null) { |
| 2818 | serializer.attribute(null, "parentPackageName", pkg.parentPackageName); |
| 2819 | } |
| 2820 | |
| 2821 | writeChildPackagesLPw(serializer, pkg.childPackageNames); |
| 2822 | |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 2823 | writeUsesStaticLibLPw(serializer, pkg.usesStaticLibraries, pkg.usesStaticLibrariesVersions); |
| 2824 | |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 2825 | // If this is a shared user, the permissions will be written there. |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2826 | if (pkg.sharedUser == null) { |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 2827 | writePermissionsLPr(serializer, pkg.getPermissionsState() |
| 2828 | .getInstallPermissionStates()); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2829 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 2830 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2831 | serializer.endTag(null, "updated-package"); |
| 2832 | } |
| 2833 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 2834 | void writePackageLPr(XmlSerializer serializer, final PackageSetting pkg) |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2835 | throws java.io.IOException { |
| 2836 | serializer.startTag(null, "package"); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2837 | serializer.attribute(null, ATTR_NAME, pkg.name); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2838 | if (pkg.realName != null) { |
| 2839 | serializer.attribute(null, "realName", pkg.realName); |
| 2840 | } |
| 2841 | serializer.attribute(null, "codePath", pkg.codePathString); |
| 2842 | if (!pkg.resourcePathString.equals(pkg.codePathString)) { |
| 2843 | serializer.attribute(null, "resourcePath", pkg.resourcePathString); |
| 2844 | } |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 2845 | |
| 2846 | if (pkg.legacyNativeLibraryPathString != null) { |
| 2847 | serializer.attribute(null, "nativeLibraryPath", pkg.legacyNativeLibraryPathString); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2848 | } |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 2849 | if (pkg.primaryCpuAbiString != null) { |
| 2850 | serializer.attribute(null, "primaryCpuAbi", pkg.primaryCpuAbiString); |
Narayan Kamath | 9e289d7 | 2014-04-10 09:26:59 +0000 | [diff] [blame] | 2851 | } |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 2852 | if (pkg.secondaryCpuAbiString != null) { |
| 2853 | serializer.attribute(null, "secondaryCpuAbi", pkg.secondaryCpuAbiString); |
| 2854 | } |
Narayan Kamath | 4903f64 | 2014-08-11 13:33:45 +0100 | [diff] [blame] | 2855 | if (pkg.cpuAbiOverrideString != null) { |
| 2856 | serializer.attribute(null, "cpuAbiOverride", pkg.cpuAbiOverrideString); |
| 2857 | } |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 2858 | |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 2859 | serializer.attribute(null, "publicFlags", Integer.toString(pkg.pkgFlags)); |
| 2860 | serializer.attribute(null, "privateFlags", Integer.toString(pkg.pkgPrivateFlags)); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2861 | serializer.attribute(null, "ft", Long.toHexString(pkg.timeStamp)); |
| 2862 | serializer.attribute(null, "it", Long.toHexString(pkg.firstInstallTime)); |
| 2863 | serializer.attribute(null, "ut", Long.toHexString(pkg.lastUpdateTime)); |
| 2864 | serializer.attribute(null, "version", String.valueOf(pkg.versionCode)); |
| 2865 | if (pkg.sharedUser == null) { |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 2866 | serializer.attribute(null, "userId", Integer.toString(pkg.appId)); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2867 | } else { |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 2868 | serializer.attribute(null, "sharedUserId", Integer.toString(pkg.appId)); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2869 | } |
| 2870 | if (pkg.uidError) { |
| 2871 | serializer.attribute(null, "uidError", "true"); |
| 2872 | } |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2873 | if (pkg.installStatus == PackageSettingBase.PKG_INSTALL_INCOMPLETE) { |
| 2874 | serializer.attribute(null, "installStatus", "false"); |
| 2875 | } |
| 2876 | if (pkg.installerPackageName != null) { |
| 2877 | serializer.attribute(null, "installer", pkg.installerPackageName); |
| 2878 | } |
Sudheer Shanka | 8c57aea | 2016-04-20 16:47:50 -0700 | [diff] [blame] | 2879 | if (pkg.isOrphaned) { |
| 2880 | serializer.attribute(null, "isOrphaned", "true"); |
| 2881 | } |
Jeff Sharkey | b2b9ab8 | 2015-04-05 21:10:42 -0700 | [diff] [blame] | 2882 | if (pkg.volumeUuid != null) { |
| 2883 | serializer.attribute(null, "volumeUuid", pkg.volumeUuid); |
| 2884 | } |
Jeff Sharkey | 9bc89af | 2017-01-11 11:25:50 -0700 | [diff] [blame] | 2885 | if (pkg.categoryHint != ApplicationInfo.CATEGORY_UNDEFINED) { |
| 2886 | serializer.attribute(null, "categoryHint", |
| 2887 | Integer.toString(pkg.categoryHint)); |
| 2888 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2889 | if (pkg.parentPackageName != null) { |
| 2890 | serializer.attribute(null, "parentPackageName", pkg.parentPackageName); |
| 2891 | } |
Todd Kennedy | ab53289 | 2017-03-08 14:19:49 -0800 | [diff] [blame] | 2892 | if (pkg.updateAvailable) { |
| 2893 | serializer.attribute(null, "updateAvailable", "true"); |
| 2894 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2895 | |
| 2896 | writeChildPackagesLPw(serializer, pkg.childPackageNames); |
| 2897 | |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 2898 | writeUsesStaticLibLPw(serializer, pkg.usesStaticLibraries, pkg.usesStaticLibrariesVersions); |
| 2899 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2900 | pkg.signatures.writeXml(serializer, "sigs", mPastSignatures); |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 2901 | |
| 2902 | writePermissionsLPr(serializer, pkg.getPermissionsState() |
| 2903 | .getInstallPermissionStates()); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2904 | |
dcashman | 8c04fac | 2015-03-23 11:39:42 -0700 | [diff] [blame] | 2905 | writeSigningKeySetLPr(serializer, pkg.keySetData); |
dcashman | 55b1078 | 2014-04-09 14:20:38 -0700 | [diff] [blame] | 2906 | writeUpgradeKeySetsLPr(serializer, pkg.keySetData); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2907 | writeKeySetAliasesLPr(serializer, pkg.keySetData); |
Fabrice Di Meglio | 6227172 | 2015-04-10 17:24:02 -0700 | [diff] [blame] | 2908 | writeDomainVerificationsLPr(serializer, pkg.verificationInfo); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2909 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2910 | serializer.endTag(null, "package"); |
| 2911 | } |
| 2912 | |
dcashman | 8c04fac | 2015-03-23 11:39:42 -0700 | [diff] [blame] | 2913 | void writeSigningKeySetLPr(XmlSerializer serializer, |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2914 | PackageKeySetData data) throws IOException { |
dcashman | 8c04fac | 2015-03-23 11:39:42 -0700 | [diff] [blame] | 2915 | serializer.startTag(null, "proper-signing-keyset"); |
| 2916 | serializer.attribute(null, "identifier", |
| 2917 | Long.toString(data.getProperSigningKeySet())); |
| 2918 | serializer.endTag(null, "proper-signing-keyset"); |
dcashman | 55b1078 | 2014-04-09 14:20:38 -0700 | [diff] [blame] | 2919 | } |
| 2920 | |
| 2921 | void writeUpgradeKeySetsLPr(XmlSerializer serializer, |
| 2922 | PackageKeySetData data) throws IOException { |
| 2923 | if (data.isUsingUpgradeKeySets()) { |
| 2924 | for (long id : data.getUpgradeKeySets()) { |
| 2925 | serializer.startTag(null, "upgrade-keyset"); |
| 2926 | serializer.attribute(null, "identifier", Long.toString(id)); |
| 2927 | serializer.endTag(null, "upgrade-keyset"); |
| 2928 | } |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2929 | } |
| 2930 | } |
| 2931 | |
| 2932 | void writeKeySetAliasesLPr(XmlSerializer serializer, |
| 2933 | PackageKeySetData data) throws IOException { |
| 2934 | for (Map.Entry<String, Long> e: data.getAliases().entrySet()) { |
| 2935 | serializer.startTag(null, "defined-keyset"); |
| 2936 | serializer.attribute(null, "alias", e.getKey()); |
| 2937 | serializer.attribute(null, "identifier", Long.toString(e.getValue())); |
| 2938 | serializer.endTag(null, "defined-keyset"); |
| 2939 | } |
| 2940 | } |
| 2941 | |
Todd Kennedy | 91a39d1 | 2017-09-27 12:37:04 -0700 | [diff] [blame] | 2942 | void writePermissionLPr(XmlSerializer serializer, BasePermission bp) throws IOException { |
| 2943 | bp.writeLPr(serializer); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2944 | } |
| 2945 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 2946 | ArrayList<PackageSetting> getListOfIncompleteInstallPackagesLPr() { |
Jeff Sharkey | 9f837a9 | 2014-10-24 12:07:24 -0700 | [diff] [blame] | 2947 | final ArraySet<String> kList = new ArraySet<String>(mPackages.keySet()); |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 2948 | final Iterator<String> its = kList.iterator(); |
| 2949 | final ArrayList<PackageSetting> ret = new ArrayList<PackageSetting>(); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2950 | while (its.hasNext()) { |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 2951 | final String key = its.next(); |
| 2952 | final PackageSetting ps = mPackages.get(key); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2953 | if (ps.getInstallStatus() == PackageSettingBase.PKG_INSTALL_INCOMPLETE) { |
| 2954 | ret.add(ps); |
| 2955 | } |
| 2956 | } |
| 2957 | return ret; |
| 2958 | } |
| 2959 | |
Jeff Sharkey | 752cd92 | 2012-09-23 16:25:12 -0700 | [diff] [blame] | 2960 | void addPackageToCleanLPw(PackageCleanItem pkg) { |
| 2961 | if (!mPackagesToBeCleaned.contains(pkg)) { |
| 2962 | mPackagesToBeCleaned.add(pkg); |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 2963 | } |
| 2964 | } |
| 2965 | |
Xiaohui Chen | 594f208 | 2015-08-18 11:04:20 -0700 | [diff] [blame] | 2966 | boolean readLPw(@NonNull List<UserInfo> users) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2967 | FileInputStream str = null; |
| 2968 | if (mBackupSettingsFilename.exists()) { |
| 2969 | try { |
| 2970 | str = new FileInputStream(mBackupSettingsFilename); |
| 2971 | mReadMessages.append("Reading from backup settings file\n"); |
| 2972 | PackageManagerService.reportSettingsProblem(Log.INFO, |
| 2973 | "Need to read from backup settings file"); |
| 2974 | if (mSettingsFilename.exists()) { |
| 2975 | // If both the backup and settings file exist, we |
| 2976 | // ignore the settings since it might have been |
| 2977 | // corrupted. |
| 2978 | Slog.w(PackageManagerService.TAG, "Cleaning up settings file " |
| 2979 | + mSettingsFilename); |
| 2980 | mSettingsFilename.delete(); |
| 2981 | } |
| 2982 | } catch (java.io.IOException e) { |
| 2983 | // We'll try for the normal settings file. |
| 2984 | } |
| 2985 | } |
| 2986 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 2987 | mPendingPackages.clear(); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2988 | mPastSignatures.clear(); |
dcashman | 8c04fac | 2015-03-23 11:39:42 -0700 | [diff] [blame] | 2989 | mKeySetRefs.clear(); |
Sudheer Shanka | 2928337 | 2016-04-04 20:56:27 -0700 | [diff] [blame] | 2990 | mInstallerPackages.clear(); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2991 | |
| 2992 | try { |
| 2993 | if (str == null) { |
| 2994 | if (!mSettingsFilename.exists()) { |
| 2995 | mReadMessages.append("No settings file found\n"); |
| 2996 | PackageManagerService.reportSettingsProblem(Log.INFO, |
| 2997 | "No settings file; creating initial state"); |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 2998 | // It's enough to just touch version details to create them |
| 2999 | // with default values |
longhai | bc62b21 | 2016-01-29 14:22:22 +0800 | [diff] [blame] | 3000 | findOrCreateVersion(StorageManager.UUID_PRIVATE_INTERNAL).forceCurrent(); |
| 3001 | findOrCreateVersion(StorageManager.UUID_PRIMARY_PHYSICAL).forceCurrent(); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3002 | return false; |
| 3003 | } |
| 3004 | str = new FileInputStream(mSettingsFilename); |
| 3005 | } |
| 3006 | XmlPullParser parser = Xml.newPullParser(); |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 3007 | parser.setInput(str, StandardCharsets.UTF_8.name()); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3008 | |
| 3009 | int type; |
| 3010 | while ((type = parser.next()) != XmlPullParser.START_TAG |
| 3011 | && type != XmlPullParser.END_DOCUMENT) { |
| 3012 | ; |
| 3013 | } |
| 3014 | |
| 3015 | if (type != XmlPullParser.START_TAG) { |
| 3016 | mReadMessages.append("No start tag found in settings file\n"); |
| 3017 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 3018 | "No start tag found in package manager settings"); |
Dianne Hackborn | 8d05172 | 2014-10-01 14:59:58 -0700 | [diff] [blame] | 3019 | Slog.wtf(PackageManagerService.TAG, |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 3020 | "No start tag found in package manager settings"); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3021 | return false; |
| 3022 | } |
| 3023 | |
| 3024 | int outerDepth = parser.getDepth(); |
| 3025 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 3026 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 3027 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 3028 | continue; |
| 3029 | } |
| 3030 | |
| 3031 | String tagName = parser.getName(); |
| 3032 | if (tagName.equals("package")) { |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 3033 | readPackageLPw(parser); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3034 | } else if (tagName.equals("permissions")) { |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 3035 | mPermissions.readPermissions(parser); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3036 | } else if (tagName.equals("permission-trees")) { |
Todd Kennedy | c842393 | 2017-10-05 08:58:36 -0700 | [diff] [blame] | 3037 | mPermissions.readPermissionTrees(parser); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3038 | } else if (tagName.equals("shared-user")) { |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 3039 | readSharedUserLPw(parser); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3040 | } else if (tagName.equals("preferred-packages")) { |
| 3041 | // no longer used. |
| 3042 | } else if (tagName.equals("preferred-activities")) { |
Dianne Hackborn | 6309271 | 2012-10-07 14:45:35 -0700 | [diff] [blame] | 3043 | // Upgrading from old single-user implementation; |
| 3044 | // these are the preferred activities for user 0. |
| 3045 | readPreferredActivitiesLPw(parser, 0); |
Sander Alewijnse | af59762 | 2014-03-20 18:44:57 +0000 | [diff] [blame] | 3046 | } else if (tagName.equals(TAG_PERSISTENT_PREFERRED_ACTIVITIES)) { |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 3047 | // TODO: check whether this is okay! as it is very |
| 3048 | // similar to how preferred-activities are treated |
| 3049 | readPersistentPreferredActivitiesLPw(parser, 0); |
Nicolas Prevot | 29762c3 | 2014-07-29 18:51:32 +0100 | [diff] [blame] | 3050 | } else if (tagName.equals(TAG_CROSS_PROFILE_INTENT_FILTERS)) { |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 3051 | // TODO: check whether this is okay! as it is very |
| 3052 | // similar to how preferred-activities are treated |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 3053 | readCrossProfileIntentFiltersLPw(parser, 0); |
Fabrice Di Meglio | 6227172 | 2015-04-10 17:24:02 -0700 | [diff] [blame] | 3054 | } else if (tagName.equals(TAG_DEFAULT_BROWSER)) { |
| 3055 | readDefaultAppsLPw(parser, 0); |
| 3056 | } else if (tagName.equals("updated-package")) { |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 3057 | readDisabledSysPackageLPw(parser); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3058 | } else if (tagName.equals("cleaning-package")) { |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 3059 | String name = parser.getAttributeValue(null, ATTR_NAME); |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 3060 | String userStr = parser.getAttributeValue(null, ATTR_USER); |
| 3061 | String codeStr = parser.getAttributeValue(null, ATTR_CODE); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3062 | if (name != null) { |
Xiaohui Chen | 594f208 | 2015-08-18 11:04:20 -0700 | [diff] [blame] | 3063 | int userId = UserHandle.USER_SYSTEM; |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 3064 | boolean andCode = true; |
| 3065 | try { |
| 3066 | if (userStr != null) { |
Jeff Sharkey | 752cd92 | 2012-09-23 16:25:12 -0700 | [diff] [blame] | 3067 | userId = Integer.parseInt(userStr); |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 3068 | } |
| 3069 | } catch (NumberFormatException e) { |
| 3070 | } |
| 3071 | if (codeStr != null) { |
| 3072 | andCode = Boolean.parseBoolean(codeStr); |
| 3073 | } |
Jeff Sharkey | 752cd92 | 2012-09-23 16:25:12 -0700 | [diff] [blame] | 3074 | addPackageToCleanLPw(new PackageCleanItem(userId, name, andCode)); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3075 | } |
| 3076 | } else if (tagName.equals("renamed-package")) { |
| 3077 | String nname = parser.getAttributeValue(null, "new"); |
| 3078 | String oname = parser.getAttributeValue(null, "old"); |
| 3079 | if (nname != null && oname != null) { |
| 3080 | mRenamedPackages.put(nname, oname); |
| 3081 | } |
Christopher Tate | 6038d15 | 2015-06-17 13:07:46 -0700 | [diff] [blame] | 3082 | } else if (tagName.equals("restored-ivi")) { |
| 3083 | readRestoredIntentFilterVerifications(parser); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3084 | } else if (tagName.equals("last-platform-version")) { |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 3085 | // Upgrade from older XML schema |
| 3086 | final VersionInfo internal = findOrCreateVersion( |
| 3087 | StorageManager.UUID_PRIVATE_INTERNAL); |
| 3088 | final VersionInfo external = findOrCreateVersion( |
| 3089 | StorageManager.UUID_PRIMARY_PHYSICAL); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 3090 | |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 3091 | internal.sdkVersion = XmlUtils.readIntAttribute(parser, "internal", 0); |
| 3092 | external.sdkVersion = XmlUtils.readIntAttribute(parser, "external", 0); |
| 3093 | internal.fingerprint = external.fingerprint = |
| 3094 | XmlUtils.readStringAttribute(parser, "fingerprint"); |
| 3095 | |
Kenny Root | c1c0d3c | 2014-04-24 13:36:40 -0700 | [diff] [blame] | 3096 | } else if (tagName.equals("database-version")) { |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 3097 | // Upgrade from older XML schema |
| 3098 | final VersionInfo internal = findOrCreateVersion( |
| 3099 | StorageManager.UUID_PRIVATE_INTERNAL); |
| 3100 | final VersionInfo external = findOrCreateVersion( |
| 3101 | StorageManager.UUID_PRIMARY_PHYSICAL); |
| 3102 | |
| 3103 | internal.databaseVersion = XmlUtils.readIntAttribute(parser, "internal", 0); |
| 3104 | external.databaseVersion = XmlUtils.readIntAttribute(parser, "external", 0); |
| 3105 | |
Kenny Root | 0aaa0d9 | 2011-09-12 16:42:55 -0700 | [diff] [blame] | 3106 | } else if (tagName.equals("verifier")) { |
| 3107 | final String deviceIdentity = parser.getAttributeValue(null, "device"); |
| 3108 | try { |
| 3109 | mVerifierDeviceIdentity = VerifierDeviceIdentity.parse(deviceIdentity); |
| 3110 | } catch (IllegalArgumentException e) { |
| 3111 | Slog.w(PackageManagerService.TAG, "Discard invalid verifier device id: " |
| 3112 | + e.getMessage()); |
| 3113 | } |
Jeff Sharkey | edc84ee8 | 2012-03-19 16:52:26 -0700 | [diff] [blame] | 3114 | } else if (TAG_READ_EXTERNAL_STORAGE.equals(tagName)) { |
| 3115 | final String enforcement = parser.getAttributeValue(null, ATTR_ENFORCEMENT); |
Todd Kennedy | 91a39d1 | 2017-09-27 12:37:04 -0700 | [diff] [blame] | 3116 | mReadExternalStorageEnforced = |
| 3117 | "1".equals(enforcement) ? Boolean.TRUE : Boolean.FALSE; |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 3118 | } else if (tagName.equals("keyset-settings")) { |
dcashman | 8c04fac | 2015-03-23 11:39:42 -0700 | [diff] [blame] | 3119 | mKeySetManagerService.readKeySetsLPw(parser, mKeySetRefs); |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 3120 | } else if (TAG_VERSION.equals(tagName)) { |
| 3121 | final String volumeUuid = XmlUtils.readStringAttribute(parser, |
| 3122 | ATTR_VOLUME_UUID); |
| 3123 | final VersionInfo ver = findOrCreateVersion(volumeUuid); |
| 3124 | ver.sdkVersion = XmlUtils.readIntAttribute(parser, ATTR_SDK_VERSION); |
khmel | 80bdce0 | 2018-01-02 16:39:05 -0800 | [diff] [blame] | 3125 | ver.databaseVersion = XmlUtils.readIntAttribute(parser, ATTR_DATABASE_VERSION); |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 3126 | ver.fingerprint = XmlUtils.readStringAttribute(parser, ATTR_FINGERPRINT); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3127 | } else { |
| 3128 | Slog.w(PackageManagerService.TAG, "Unknown element under <packages>: " |
| 3129 | + parser.getName()); |
| 3130 | XmlUtils.skipCurrentTag(parser); |
| 3131 | } |
| 3132 | } |
| 3133 | |
| 3134 | str.close(); |
| 3135 | |
| 3136 | } catch (XmlPullParserException e) { |
| 3137 | mReadMessages.append("Error reading: " + e.toString()); |
| 3138 | PackageManagerService.reportSettingsProblem(Log.ERROR, "Error reading settings: " + e); |
Dianne Hackborn | 8d05172 | 2014-10-01 14:59:58 -0700 | [diff] [blame] | 3139 | Slog.wtf(PackageManagerService.TAG, "Error reading package manager settings", e); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3140 | |
| 3141 | } catch (java.io.IOException e) { |
| 3142 | mReadMessages.append("Error reading: " + e.toString()); |
| 3143 | PackageManagerService.reportSettingsProblem(Log.ERROR, "Error reading settings: " + e); |
Dianne Hackborn | 8d05172 | 2014-10-01 14:59:58 -0700 | [diff] [blame] | 3144 | Slog.wtf(PackageManagerService.TAG, "Error reading package manager settings", e); |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 3145 | } |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3146 | |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 3147 | // If the build is setup to drop runtime permissions |
| 3148 | // on update drop the files before loading them. |
| 3149 | if (PackageManagerService.CLEAR_RUNTIME_PERMISSIONS_ON_UPGRADE) { |
| 3150 | final VersionInfo internal = getInternalVersion(); |
| 3151 | if (!Build.FINGERPRINT.equals(internal.fingerprint)) { |
Xiaohui Chen | 594f208 | 2015-08-18 11:04:20 -0700 | [diff] [blame] | 3152 | for (UserInfo user : users) { |
| 3153 | mRuntimePermissionsPersistence.deleteUserRuntimePermissionsFile(user.id); |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 3154 | } |
| 3155 | } |
| 3156 | } |
| 3157 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3158 | final int N = mPendingPackages.size(); |
dcashman | 8c04fac | 2015-03-23 11:39:42 -0700 | [diff] [blame] | 3159 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3160 | for (int i = 0; i < N; i++) { |
Todd Kennedy | 788c842 | 2016-08-10 10:52:34 -0700 | [diff] [blame] | 3161 | final PackageSetting p = mPendingPackages.get(i); |
| 3162 | final int sharedUserId = p.getSharedUserId(); |
| 3163 | final Object idObj = getUserIdLPr(sharedUserId); |
| 3164 | if (idObj instanceof SharedUserSetting) { |
| 3165 | final SharedUserSetting sharedUser = (SharedUserSetting) idObj; |
| 3166 | p.sharedUser = sharedUser; |
| 3167 | p.appId = sharedUser.userId; |
| 3168 | addPackageSettingLPw(p, sharedUser); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3169 | } else if (idObj != null) { |
Todd Kennedy | 788c842 | 2016-08-10 10:52:34 -0700 | [diff] [blame] | 3170 | String msg = "Bad package setting: package " + p.name + " has shared uid " |
| 3171 | + sharedUserId + " that is not a shared uid\n"; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3172 | mReadMessages.append(msg); |
| 3173 | PackageManagerService.reportSettingsProblem(Log.ERROR, msg); |
| 3174 | } else { |
Todd Kennedy | 788c842 | 2016-08-10 10:52:34 -0700 | [diff] [blame] | 3175 | String msg = "Bad package setting: package " + p.name + " has shared uid " |
| 3176 | + sharedUserId + " that is not defined\n"; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3177 | mReadMessages.append(msg); |
| 3178 | PackageManagerService.reportSettingsProblem(Log.ERROR, msg); |
| 3179 | } |
| 3180 | } |
| 3181 | mPendingPackages.clear(); |
| 3182 | |
Amith Yamasani | f031f23 | 2012-10-26 15:35:21 -0700 | [diff] [blame] | 3183 | if (mBackupStoppedPackagesFilename.exists() |
| 3184 | || mStoppedPackagesFilename.exists()) { |
| 3185 | // Read old file |
| 3186 | readStoppedLPw(); |
| 3187 | mBackupStoppedPackagesFilename.delete(); |
| 3188 | mStoppedPackagesFilename.delete(); |
| 3189 | // Migrate to new file format |
Xiaohui Chen | 594f208 | 2015-08-18 11:04:20 -0700 | [diff] [blame] | 3190 | writePackageRestrictionsLPr(UserHandle.USER_SYSTEM); |
Amith Yamasani | f031f23 | 2012-10-26 15:35:21 -0700 | [diff] [blame] | 3191 | } else { |
Xiaohui Chen | 594f208 | 2015-08-18 11:04:20 -0700 | [diff] [blame] | 3192 | for (UserInfo user : users) { |
| 3193 | readPackageRestrictionsLPr(user.id); |
Amith Yamasani | f031f23 | 2012-10-26 15:35:21 -0700 | [diff] [blame] | 3194 | } |
| 3195 | } |
| 3196 | |
Xiaohui Chen | 594f208 | 2015-08-18 11:04:20 -0700 | [diff] [blame] | 3197 | for (UserInfo user : users) { |
| 3198 | mRuntimePermissionsPersistence.readStateForUserSyncLPr(user.id); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 3199 | } |
| 3200 | |
Kenny Root | 1d1b489 | 2011-04-08 14:25:24 -0700 | [diff] [blame] | 3201 | /* |
| 3202 | * Make sure all the updated system packages have their shared users |
| 3203 | * associated with them. |
| 3204 | */ |
| 3205 | final Iterator<PackageSetting> disabledIt = mDisabledSysPackages.values().iterator(); |
| 3206 | while (disabledIt.hasNext()) { |
| 3207 | final PackageSetting disabledPs = disabledIt.next(); |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 3208 | final Object id = getUserIdLPr(disabledPs.appId); |
Kenny Root | 1d1b489 | 2011-04-08 14:25:24 -0700 | [diff] [blame] | 3209 | if (id != null && id instanceof SharedUserSetting) { |
| 3210 | disabledPs.sharedUser = (SharedUserSetting) id; |
| 3211 | } |
| 3212 | } |
| 3213 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3214 | mReadMessages.append("Read completed successfully: " + mPackages.size() + " packages, " |
| 3215 | + mSharedUsers.size() + " shared uids\n"); |
| 3216 | |
Jeff Sharkey | 2271ba3 | 2016-02-01 17:57:08 -0700 | [diff] [blame] | 3217 | writeKernelMappingLPr(); |
| 3218 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3219 | return true; |
| 3220 | } |
| 3221 | |
Christopher Tate | db3fe81 | 2015-06-24 16:15:48 -0700 | [diff] [blame] | 3222 | void applyDefaultPreferredAppsLPw(PackageManagerService service, int userId) { |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3223 | // First pull data from any pre-installed apps. |
| 3224 | for (PackageSetting ps : mPackages.values()) { |
| 3225 | if ((ps.pkgFlags&ApplicationInfo.FLAG_SYSTEM) != 0 && ps.pkg != null |
| 3226 | && ps.pkg.preferredActivityFilters != null) { |
| 3227 | ArrayList<PackageParser.ActivityIntentInfo> intents |
| 3228 | = ps.pkg.preferredActivityFilters; |
| 3229 | for (int i=0; i<intents.size(); i++) { |
| 3230 | PackageParser.ActivityIntentInfo aii = intents.get(i); |
| 3231 | applyDefaultPreferredActivityLPw(service, aii, new ComponentName( |
| 3232 | ps.name, aii.activity.className), userId); |
| 3233 | } |
| 3234 | } |
| 3235 | } |
| 3236 | |
Dianne Hackborn | fc8b7fe | 2012-06-18 15:38:12 -0700 | [diff] [blame] | 3237 | // Read preferred apps from .../etc/preferred-apps directory. |
| 3238 | File preferredDir = new File(Environment.getRootDirectory(), "etc/preferred-apps"); |
| 3239 | if (!preferredDir.exists() || !preferredDir.isDirectory()) { |
| 3240 | return; |
| 3241 | } |
| 3242 | if (!preferredDir.canRead()) { |
| 3243 | Slog.w(TAG, "Directory " + preferredDir + " cannot be read"); |
| 3244 | return; |
| 3245 | } |
| 3246 | |
| 3247 | // Iterate over the files in the directory and scan .xml files |
| 3248 | for (File f : preferredDir.listFiles()) { |
| 3249 | if (!f.getPath().endsWith(".xml")) { |
| 3250 | Slog.i(TAG, "Non-xml file " + f + " in " + preferredDir + " directory, ignoring"); |
| 3251 | continue; |
| 3252 | } |
| 3253 | if (!f.canRead()) { |
| 3254 | Slog.w(TAG, "Preferred apps file " + f + " cannot be read"); |
| 3255 | continue; |
| 3256 | } |
| 3257 | |
Dianne Hackborn | 8a2ed1d | 2013-01-29 15:18:29 -0800 | [diff] [blame] | 3258 | if (PackageManagerService.DEBUG_PREFERRED) Log.d(TAG, "Reading default preferred " + f); |
Fyodor Kupolov | b35b34c | 2015-12-17 14:16:51 -0800 | [diff] [blame] | 3259 | InputStream str = null; |
Dianne Hackborn | fc8b7fe | 2012-06-18 15:38:12 -0700 | [diff] [blame] | 3260 | try { |
Fyodor Kupolov | b35b34c | 2015-12-17 14:16:51 -0800 | [diff] [blame] | 3261 | str = new BufferedInputStream(new FileInputStream(f)); |
Dianne Hackborn | fc8b7fe | 2012-06-18 15:38:12 -0700 | [diff] [blame] | 3262 | XmlPullParser parser = Xml.newPullParser(); |
| 3263 | parser.setInput(str, null); |
| 3264 | |
| 3265 | int type; |
| 3266 | while ((type = parser.next()) != XmlPullParser.START_TAG |
| 3267 | && type != XmlPullParser.END_DOCUMENT) { |
| 3268 | ; |
| 3269 | } |
| 3270 | |
| 3271 | if (type != XmlPullParser.START_TAG) { |
| 3272 | Slog.w(TAG, "Preferred apps file " + f + " does not have start tag"); |
| 3273 | continue; |
| 3274 | } |
| 3275 | if (!"preferred-activities".equals(parser.getName())) { |
| 3276 | Slog.w(TAG, "Preferred apps file " + f |
| 3277 | + " does not start with 'preferred-activities'"); |
| 3278 | continue; |
| 3279 | } |
Dianne Hackborn | 8a2ed1d | 2013-01-29 15:18:29 -0800 | [diff] [blame] | 3280 | readDefaultPreferredActivitiesLPw(service, parser, userId); |
Dianne Hackborn | fc8b7fe | 2012-06-18 15:38:12 -0700 | [diff] [blame] | 3281 | } catch (XmlPullParserException e) { |
| 3282 | Slog.w(TAG, "Error reading apps file " + f, e); |
| 3283 | } catch (IOException e) { |
| 3284 | Slog.w(TAG, "Error reading apps file " + f, e); |
| 3285 | } finally { |
| 3286 | if (str != null) { |
| 3287 | try { |
| 3288 | str.close(); |
| 3289 | } catch (IOException e) { |
| 3290 | } |
| 3291 | } |
| 3292 | } |
| 3293 | } |
| 3294 | } |
| 3295 | |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3296 | private void applyDefaultPreferredActivityLPw(PackageManagerService service, |
| 3297 | IntentFilter tmpPa, ComponentName cn, int userId) { |
| 3298 | // The initial preferences only specify the target activity |
| 3299 | // component and intent-filter, not the set of matches. So we |
| 3300 | // now need to query for the matches to build the correct |
| 3301 | // preferred activity entry. |
| 3302 | if (PackageManagerService.DEBUG_PREFERRED) { |
| 3303 | Log.d(TAG, "Processing preferred:"); |
| 3304 | tmpPa.dump(new LogPrinter(Log.DEBUG, TAG), " "); |
| 3305 | } |
| 3306 | Intent intent = new Intent(); |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 3307 | int flags = PackageManager.MATCH_DIRECT_BOOT_AWARE |
| 3308 | | PackageManager.MATCH_DIRECT_BOOT_UNAWARE; |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3309 | intent.setAction(tmpPa.getAction(0)); |
| 3310 | for (int i=0; i<tmpPa.countCategories(); i++) { |
| 3311 | String cat = tmpPa.getCategory(i); |
| 3312 | if (cat.equals(Intent.CATEGORY_DEFAULT)) { |
Jeff Sharkey | 2a90f673 | 2016-01-06 12:26:11 -0700 | [diff] [blame] | 3313 | flags |= MATCH_DEFAULT_ONLY; |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3314 | } else { |
| 3315 | intent.addCategory(cat); |
| 3316 | } |
| 3317 | } |
| 3318 | |
| 3319 | boolean doNonData = true; |
Christopher Tate | 2298ef2 | 2013-11-04 17:02:10 -0800 | [diff] [blame] | 3320 | boolean hasSchemes = false; |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3321 | |
| 3322 | for (int ischeme=0; ischeme<tmpPa.countDataSchemes(); ischeme++) { |
| 3323 | boolean doScheme = true; |
| 3324 | String scheme = tmpPa.getDataScheme(ischeme); |
Christopher Tate | 2298ef2 | 2013-11-04 17:02:10 -0800 | [diff] [blame] | 3325 | if (scheme != null && !scheme.isEmpty()) { |
| 3326 | hasSchemes = true; |
| 3327 | } |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3328 | for (int issp=0; issp<tmpPa.countDataSchemeSpecificParts(); issp++) { |
| 3329 | Uri.Builder builder = new Uri.Builder(); |
| 3330 | builder.scheme(scheme); |
| 3331 | PatternMatcher ssp = tmpPa.getDataSchemeSpecificPart(issp); |
| 3332 | builder.opaquePart(ssp.getPath()); |
| 3333 | Intent finalIntent = new Intent(intent); |
| 3334 | finalIntent.setData(builder.build()); |
| 3335 | applyDefaultPreferredActivityLPw(service, finalIntent, flags, cn, |
Dianne Hackborn | eeb2c7e | 2014-09-23 16:45:39 -0700 | [diff] [blame] | 3336 | scheme, ssp, null, null, userId); |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3337 | doScheme = false; |
| 3338 | } |
| 3339 | for (int iauth=0; iauth<tmpPa.countDataAuthorities(); iauth++) { |
| 3340 | boolean doAuth = true; |
| 3341 | IntentFilter.AuthorityEntry auth = tmpPa.getDataAuthority(iauth); |
| 3342 | for (int ipath=0; ipath<tmpPa.countDataPaths(); ipath++) { |
| 3343 | Uri.Builder builder = new Uri.Builder(); |
| 3344 | builder.scheme(scheme); |
| 3345 | if (auth.getHost() != null) { |
| 3346 | builder.authority(auth.getHost()); |
| 3347 | } |
| 3348 | PatternMatcher path = tmpPa.getDataPath(ipath); |
| 3349 | builder.path(path.getPath()); |
| 3350 | Intent finalIntent = new Intent(intent); |
| 3351 | finalIntent.setData(builder.build()); |
| 3352 | applyDefaultPreferredActivityLPw(service, finalIntent, flags, cn, |
Dianne Hackborn | eeb2c7e | 2014-09-23 16:45:39 -0700 | [diff] [blame] | 3353 | scheme, null, auth, path, userId); |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3354 | doAuth = doScheme = false; |
| 3355 | } |
| 3356 | if (doAuth) { |
| 3357 | Uri.Builder builder = new Uri.Builder(); |
| 3358 | builder.scheme(scheme); |
| 3359 | if (auth.getHost() != null) { |
| 3360 | builder.authority(auth.getHost()); |
| 3361 | } |
| 3362 | Intent finalIntent = new Intent(intent); |
| 3363 | finalIntent.setData(builder.build()); |
| 3364 | applyDefaultPreferredActivityLPw(service, finalIntent, flags, cn, |
Dianne Hackborn | eeb2c7e | 2014-09-23 16:45:39 -0700 | [diff] [blame] | 3365 | scheme, null, auth, null, userId); |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3366 | doScheme = false; |
| 3367 | } |
| 3368 | } |
| 3369 | if (doScheme) { |
| 3370 | Uri.Builder builder = new Uri.Builder(); |
| 3371 | builder.scheme(scheme); |
| 3372 | Intent finalIntent = new Intent(intent); |
| 3373 | finalIntent.setData(builder.build()); |
| 3374 | applyDefaultPreferredActivityLPw(service, finalIntent, flags, cn, |
Dianne Hackborn | eeb2c7e | 2014-09-23 16:45:39 -0700 | [diff] [blame] | 3375 | scheme, null, null, null, userId); |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3376 | } |
| 3377 | doNonData = false; |
| 3378 | } |
| 3379 | |
| 3380 | for (int idata=0; idata<tmpPa.countDataTypes(); idata++) { |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3381 | String mimeType = tmpPa.getDataType(idata); |
Christopher Tate | 2298ef2 | 2013-11-04 17:02:10 -0800 | [diff] [blame] | 3382 | if (hasSchemes) { |
| 3383 | Uri.Builder builder = new Uri.Builder(); |
| 3384 | for (int ischeme=0; ischeme<tmpPa.countDataSchemes(); ischeme++) { |
| 3385 | String scheme = tmpPa.getDataScheme(ischeme); |
| 3386 | if (scheme != null && !scheme.isEmpty()) { |
| 3387 | Intent finalIntent = new Intent(intent); |
| 3388 | builder.scheme(scheme); |
| 3389 | finalIntent.setDataAndType(builder.build(), mimeType); |
| 3390 | applyDefaultPreferredActivityLPw(service, finalIntent, flags, cn, |
Dianne Hackborn | eeb2c7e | 2014-09-23 16:45:39 -0700 | [diff] [blame] | 3391 | scheme, null, null, null, userId); |
Christopher Tate | 2298ef2 | 2013-11-04 17:02:10 -0800 | [diff] [blame] | 3392 | } |
| 3393 | } |
| 3394 | } else { |
| 3395 | Intent finalIntent = new Intent(intent); |
| 3396 | finalIntent.setType(mimeType); |
| 3397 | applyDefaultPreferredActivityLPw(service, finalIntent, flags, cn, |
Dianne Hackborn | eeb2c7e | 2014-09-23 16:45:39 -0700 | [diff] [blame] | 3398 | null, null, null, null, userId); |
Christopher Tate | 2298ef2 | 2013-11-04 17:02:10 -0800 | [diff] [blame] | 3399 | } |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3400 | doNonData = false; |
| 3401 | } |
| 3402 | |
| 3403 | if (doNonData) { |
| 3404 | applyDefaultPreferredActivityLPw(service, intent, flags, cn, |
Dianne Hackborn | eeb2c7e | 2014-09-23 16:45:39 -0700 | [diff] [blame] | 3405 | null, null, null, null, userId); |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3406 | } |
| 3407 | } |
| 3408 | |
| 3409 | private void applyDefaultPreferredActivityLPw(PackageManagerService service, |
| 3410 | Intent intent, int flags, ComponentName cn, String scheme, PatternMatcher ssp, |
Dianne Hackborn | eeb2c7e | 2014-09-23 16:45:39 -0700 | [diff] [blame] | 3411 | IntentFilter.AuthorityEntry auth, PatternMatcher path, int userId) { |
Todd Kennedy | 51b3aac | 2017-03-30 17:50:42 -0700 | [diff] [blame] | 3412 | flags = service.updateFlagsForResolve(flags, userId, intent, Binder.getCallingUid(), false); |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3413 | List<ResolveInfo> ri = service.mActivities.queryIntent(intent, |
| 3414 | intent.getType(), flags, 0); |
| 3415 | if (PackageManagerService.DEBUG_PREFERRED) Log.d(TAG, "Queried " + intent |
| 3416 | + " results: " + ri); |
Dianne Hackborn | f85e7af | 2014-10-14 10:43:43 -0700 | [diff] [blame] | 3417 | int systemMatch = 0; |
| 3418 | int thirdPartyMatch = 0; |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3419 | if (ri != null && ri.size() > 1) { |
| 3420 | boolean haveAct = false; |
Dianne Hackborn | eeb2c7e | 2014-09-23 16:45:39 -0700 | [diff] [blame] | 3421 | ComponentName haveNonSys = null; |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3422 | ComponentName[] set = new ComponentName[ri.size()]; |
| 3423 | for (int i=0; i<ri.size(); i++) { |
| 3424 | ActivityInfo ai = ri.get(i).activityInfo; |
| 3425 | set[i] = new ComponentName(ai.packageName, ai.name); |
| 3426 | if ((ai.applicationInfo.flags&ApplicationInfo.FLAG_SYSTEM) == 0) { |
Dianne Hackborn | f85e7af | 2014-10-14 10:43:43 -0700 | [diff] [blame] | 3427 | if (ri.get(i).match >= thirdPartyMatch) { |
| 3428 | // Keep track of the best match we find of all third |
| 3429 | // party apps, for use later to determine if we actually |
| 3430 | // want to set a preferred app for this intent. |
Dianne Hackborn | eeb2c7e | 2014-09-23 16:45:39 -0700 | [diff] [blame] | 3431 | if (PackageManagerService.DEBUG_PREFERRED) Log.d(TAG, "Result " |
| 3432 | + ai.packageName + "/" + ai.name + ": non-system!"); |
| 3433 | haveNonSys = set[i]; |
| 3434 | break; |
| 3435 | } |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3436 | } else if (cn.getPackageName().equals(ai.packageName) |
| 3437 | && cn.getClassName().equals(ai.name)) { |
| 3438 | if (PackageManagerService.DEBUG_PREFERRED) Log.d(TAG, "Result " |
| 3439 | + ai.packageName + "/" + ai.name + ": default!"); |
| 3440 | haveAct = true; |
Dianne Hackborn | f85e7af | 2014-10-14 10:43:43 -0700 | [diff] [blame] | 3441 | systemMatch = ri.get(i).match; |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3442 | } else { |
| 3443 | if (PackageManagerService.DEBUG_PREFERRED) Log.d(TAG, "Result " |
| 3444 | + ai.packageName + "/" + ai.name + ": skipped"); |
| 3445 | } |
| 3446 | } |
Dianne Hackborn | f85e7af | 2014-10-14 10:43:43 -0700 | [diff] [blame] | 3447 | if (haveNonSys != null && thirdPartyMatch < systemMatch) { |
| 3448 | // If we have a matching third party app, but its match is not as |
| 3449 | // good as the built-in system app, then we don't want to actually |
| 3450 | // consider it a match because presumably the built-in app is still |
| 3451 | // the thing we want users to see by default. |
| 3452 | haveNonSys = null; |
| 3453 | } |
Dianne Hackborn | eeb2c7e | 2014-09-23 16:45:39 -0700 | [diff] [blame] | 3454 | if (haveAct && haveNonSys == null) { |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3455 | IntentFilter filter = new IntentFilter(); |
| 3456 | if (intent.getAction() != null) { |
| 3457 | filter.addAction(intent.getAction()); |
| 3458 | } |
Erin Dahlgren | 707a59d | 2013-10-24 15:13:39 -0700 | [diff] [blame] | 3459 | if (intent.getCategories() != null) { |
| 3460 | for (String cat : intent.getCategories()) { |
| 3461 | filter.addCategory(cat); |
| 3462 | } |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3463 | } |
Jeff Sharkey | 2a90f673 | 2016-01-06 12:26:11 -0700 | [diff] [blame] | 3464 | if ((flags & MATCH_DEFAULT_ONLY) != 0) { |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3465 | filter.addCategory(Intent.CATEGORY_DEFAULT); |
| 3466 | } |
| 3467 | if (scheme != null) { |
| 3468 | filter.addDataScheme(scheme); |
| 3469 | } |
| 3470 | if (ssp != null) { |
| 3471 | filter.addDataSchemeSpecificPart(ssp.getPath(), ssp.getType()); |
| 3472 | } |
| 3473 | if (auth != null) { |
| 3474 | filter.addDataAuthority(auth); |
| 3475 | } |
| 3476 | if (path != null) { |
| 3477 | filter.addDataPath(path); |
| 3478 | } |
Erin Dahlgren | 707a59d | 2013-10-24 15:13:39 -0700 | [diff] [blame] | 3479 | if (intent.getType() != null) { |
| 3480 | try { |
| 3481 | filter.addDataType(intent.getType()); |
| 3482 | } catch (IntentFilter.MalformedMimeTypeException ex) { |
| 3483 | Slog.w(TAG, "Malformed mimetype " + intent.getType() + " for " + cn); |
| 3484 | } |
| 3485 | } |
Dianne Hackborn | f85e7af | 2014-10-14 10:43:43 -0700 | [diff] [blame] | 3486 | PreferredActivity pa = new PreferredActivity(filter, systemMatch, set, cn, true); |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3487 | editPreferredActivitiesLPw(userId).addFilter(pa); |
Dianne Hackborn | eeb2c7e | 2014-09-23 16:45:39 -0700 | [diff] [blame] | 3488 | } else if (haveNonSys == null) { |
| 3489 | StringBuilder sb = new StringBuilder(); |
| 3490 | sb.append("No component "); |
| 3491 | sb.append(cn.flattenToShortString()); |
| 3492 | sb.append(" found setting preferred "); |
| 3493 | sb.append(intent); |
| 3494 | sb.append("; possible matches are "); |
| 3495 | for (int i=0; i<set.length; i++) { |
| 3496 | if (i > 0) sb.append(", "); |
| 3497 | sb.append(set[i].flattenToShortString()); |
| 3498 | } |
| 3499 | Slog.w(TAG, sb.toString()); |
| 3500 | } else { |
| 3501 | Slog.i(TAG, "Not setting preferred " + intent + "; found third party match " |
| 3502 | + haveNonSys.flattenToShortString()); |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3503 | } |
Dianne Hackborn | eeb2c7e | 2014-09-23 16:45:39 -0700 | [diff] [blame] | 3504 | } else { |
| 3505 | Slog.w(TAG, "No potential matches found for " + intent + " while setting preferred " |
| 3506 | + cn.flattenToShortString()); |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3507 | } |
| 3508 | } |
| 3509 | |
Dianne Hackborn | 8a2ed1d | 2013-01-29 15:18:29 -0800 | [diff] [blame] | 3510 | private void readDefaultPreferredActivitiesLPw(PackageManagerService service, |
| 3511 | XmlPullParser parser, int userId) |
| 3512 | throws XmlPullParserException, IOException { |
| 3513 | int outerDepth = parser.getDepth(); |
| 3514 | int type; |
| 3515 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 3516 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 3517 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 3518 | continue; |
| 3519 | } |
| 3520 | |
| 3521 | String tagName = parser.getName(); |
| 3522 | if (tagName.equals(TAG_ITEM)) { |
| 3523 | PreferredActivity tmpPa = new PreferredActivity(parser); |
| 3524 | if (tmpPa.mPref.getParseError() == null) { |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3525 | applyDefaultPreferredActivityLPw(service, tmpPa, tmpPa.mPref.mComponent, |
| 3526 | userId); |
Dianne Hackborn | 8a2ed1d | 2013-01-29 15:18:29 -0800 | [diff] [blame] | 3527 | } else { |
| 3528 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 3529 | "Error in package manager settings: <preferred-activity> " |
| 3530 | + tmpPa.mPref.getParseError() + " at " |
| 3531 | + parser.getPositionDescription()); |
| 3532 | } |
| 3533 | } else { |
| 3534 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 3535 | "Unknown element under <preferred-activities>: " + parser.getName()); |
| 3536 | XmlUtils.skipCurrentTag(parser); |
| 3537 | } |
| 3538 | } |
| 3539 | } |
| 3540 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 3541 | private void readDisabledSysPackageLPw(XmlPullParser parser) throws XmlPullParserException, |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3542 | IOException { |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 3543 | String name = parser.getAttributeValue(null, ATTR_NAME); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3544 | String realName = parser.getAttributeValue(null, "realName"); |
| 3545 | String codePathStr = parser.getAttributeValue(null, "codePath"); |
| 3546 | String resourcePathStr = parser.getAttributeValue(null, "resourcePath"); |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 3547 | |
| 3548 | String legacyCpuAbiStr = parser.getAttributeValue(null, "requiredCpuAbi"); |
| 3549 | String legacyNativeLibraryPathStr = parser.getAttributeValue(null, "nativeLibraryPath"); |
| 3550 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3551 | String parentPackageName = parser.getAttributeValue(null, "parentPackageName"); |
| 3552 | |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 3553 | String primaryCpuAbiStr = parser.getAttributeValue(null, "primaryCpuAbi"); |
| 3554 | String secondaryCpuAbiStr = parser.getAttributeValue(null, "secondaryCpuAbi"); |
Narayan Kamath | 4903f64 | 2014-08-11 13:33:45 +0100 | [diff] [blame] | 3555 | String cpuAbiOverrideStr = parser.getAttributeValue(null, "cpuAbiOverride"); |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 3556 | |
| 3557 | if (primaryCpuAbiStr == null && legacyCpuAbiStr != null) { |
| 3558 | primaryCpuAbiStr = legacyCpuAbiStr; |
| 3559 | } |
Narayan Kamath | 9e289d7 | 2014-04-10 09:26:59 +0000 | [diff] [blame] | 3560 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3561 | if (resourcePathStr == null) { |
| 3562 | resourcePathStr = codePathStr; |
| 3563 | } |
| 3564 | String version = parser.getAttributeValue(null, "version"); |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 3565 | long versionCode = 0; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3566 | if (version != null) { |
| 3567 | try { |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 3568 | versionCode = Long.parseLong(version); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3569 | } catch (NumberFormatException e) { |
| 3570 | } |
| 3571 | } |
| 3572 | |
| 3573 | int pkgFlags = 0; |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 3574 | int pkgPrivateFlags = 0; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3575 | pkgFlags |= ApplicationInfo.FLAG_SYSTEM; |
Todd Kennedy | ddaaf4c | 2017-11-07 10:01:25 -0800 | [diff] [blame] | 3576 | if (PackageManagerService.locationIsPrivileged(codePathStr)) { |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 3577 | pkgPrivateFlags |= ApplicationInfo.PRIVATE_FLAG_PRIVILEGED; |
Christopher Tate | 628946a | 2013-10-18 18:11:05 -0700 | [diff] [blame] | 3578 | } |
Todd Kennedy | ddaaf4c | 2017-11-07 10:01:25 -0800 | [diff] [blame] | 3579 | PackageSetting ps = new PackageSetting(name, realName, new File(codePathStr), |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 3580 | new File(resourcePathStr), legacyNativeLibraryPathStr, primaryCpuAbiStr, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3581 | secondaryCpuAbiStr, cpuAbiOverrideStr, versionCode, pkgFlags, pkgPrivateFlags, |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 3582 | parentPackageName, null /*childPackageNames*/, 0 /*sharedUserId*/, null, null); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3583 | String timeStampStr = parser.getAttributeValue(null, "ft"); |
| 3584 | if (timeStampStr != null) { |
| 3585 | try { |
| 3586 | long timeStamp = Long.parseLong(timeStampStr, 16); |
| 3587 | ps.setTimeStamp(timeStamp); |
| 3588 | } catch (NumberFormatException e) { |
| 3589 | } |
| 3590 | } else { |
| 3591 | timeStampStr = parser.getAttributeValue(null, "ts"); |
| 3592 | if (timeStampStr != null) { |
| 3593 | try { |
| 3594 | long timeStamp = Long.parseLong(timeStampStr); |
| 3595 | ps.setTimeStamp(timeStamp); |
| 3596 | } catch (NumberFormatException e) { |
| 3597 | } |
| 3598 | } |
| 3599 | } |
| 3600 | timeStampStr = parser.getAttributeValue(null, "it"); |
| 3601 | if (timeStampStr != null) { |
| 3602 | try { |
| 3603 | ps.firstInstallTime = Long.parseLong(timeStampStr, 16); |
| 3604 | } catch (NumberFormatException e) { |
| 3605 | } |
| 3606 | } |
| 3607 | timeStampStr = parser.getAttributeValue(null, "ut"); |
| 3608 | if (timeStampStr != null) { |
| 3609 | try { |
| 3610 | ps.lastUpdateTime = Long.parseLong(timeStampStr, 16); |
| 3611 | } catch (NumberFormatException e) { |
| 3612 | } |
| 3613 | } |
| 3614 | String idStr = parser.getAttributeValue(null, "userId"); |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 3615 | ps.appId = idStr != null ? Integer.parseInt(idStr) : 0; |
| 3616 | if (ps.appId <= 0) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3617 | String sharedIdStr = parser.getAttributeValue(null, "sharedUserId"); |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 3618 | ps.appId = sharedIdStr != null ? Integer.parseInt(sharedIdStr) : 0; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3619 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 3620 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3621 | int outerDepth = parser.getDepth(); |
| 3622 | int type; |
| 3623 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 3624 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 3625 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 3626 | continue; |
| 3627 | } |
| 3628 | |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 3629 | if (parser.getName().equals(TAG_PERMISSIONS)) { |
| 3630 | readInstallPermissionsLPr(parser, ps.getPermissionsState()); |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3631 | } else if (parser.getName().equals(TAG_CHILD_PACKAGE)) { |
| 3632 | String childPackageName = parser.getAttributeValue(null, ATTR_NAME); |
| 3633 | if (ps.childPackageNames == null) { |
| 3634 | ps.childPackageNames = new ArrayList<>(); |
| 3635 | } |
| 3636 | ps.childPackageNames.add(childPackageName); |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 3637 | } else if (parser.getName().equals(TAG_USES_STATIC_LIB)) { |
| 3638 | readUsesStaticLibLPw(parser, ps); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3639 | } else { |
| 3640 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 3641 | "Unknown element under <updated-package>: " + parser.getName()); |
| 3642 | XmlUtils.skipCurrentTag(parser); |
| 3643 | } |
| 3644 | } |
Christopher Tate | 628946a | 2013-10-18 18:11:05 -0700 | [diff] [blame] | 3645 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3646 | mDisabledSysPackages.put(name, ps); |
| 3647 | } |
| 3648 | |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 3649 | private static int PRE_M_APP_INFO_FLAG_HIDDEN = 1<<27; |
| 3650 | private static int PRE_M_APP_INFO_FLAG_CANT_SAVE_STATE = 1<<28; |
| 3651 | private static int PRE_M_APP_INFO_FLAG_FORWARD_LOCK = 1<<29; |
| 3652 | private static int PRE_M_APP_INFO_FLAG_PRIVILEGED = 1<<30; |
| 3653 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 3654 | private void readPackageLPw(XmlPullParser parser) throws XmlPullParserException, IOException { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3655 | String name = null; |
| 3656 | String realName = null; |
| 3657 | String idStr = null; |
| 3658 | String sharedIdStr = null; |
| 3659 | String codePathStr = null; |
| 3660 | String resourcePathStr = null; |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 3661 | String legacyCpuAbiString = null; |
| 3662 | String legacyNativeLibraryPathStr = null; |
| 3663 | String primaryCpuAbiString = null; |
| 3664 | String secondaryCpuAbiString = null; |
Narayan Kamath | 4903f64 | 2014-08-11 13:33:45 +0100 | [diff] [blame] | 3665 | String cpuAbiOverrideString = null; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3666 | String systemStr = null; |
| 3667 | String installerPackageName = null; |
Sudheer Shanka | 8c57aea | 2016-04-20 16:47:50 -0700 | [diff] [blame] | 3668 | String isOrphaned = null; |
Jeff Sharkey | b2b9ab8 | 2015-04-05 21:10:42 -0700 | [diff] [blame] | 3669 | String volumeUuid = null; |
Jeff Sharkey | 9bc89af | 2017-01-11 11:25:50 -0700 | [diff] [blame] | 3670 | String categoryHintString = null; |
Todd Kennedy | ab53289 | 2017-03-08 14:19:49 -0800 | [diff] [blame] | 3671 | String updateAvailable = null; |
Jeff Sharkey | 9bc89af | 2017-01-11 11:25:50 -0700 | [diff] [blame] | 3672 | int categoryHint = ApplicationInfo.CATEGORY_UNDEFINED; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3673 | String uidError = null; |
| 3674 | int pkgFlags = 0; |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 3675 | int pkgPrivateFlags = 0; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3676 | long timeStamp = 0; |
| 3677 | long firstInstallTime = 0; |
| 3678 | long lastUpdateTime = 0; |
Todd Kennedy | 788c842 | 2016-08-10 10:52:34 -0700 | [diff] [blame] | 3679 | PackageSetting packageSetting = null; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3680 | String version = null; |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 3681 | long versionCode = 0; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3682 | String parentPackageName; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3683 | try { |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 3684 | name = parser.getAttributeValue(null, ATTR_NAME); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3685 | realName = parser.getAttributeValue(null, "realName"); |
| 3686 | idStr = parser.getAttributeValue(null, "userId"); |
| 3687 | uidError = parser.getAttributeValue(null, "uidError"); |
| 3688 | sharedIdStr = parser.getAttributeValue(null, "sharedUserId"); |
| 3689 | codePathStr = parser.getAttributeValue(null, "codePath"); |
| 3690 | resourcePathStr = parser.getAttributeValue(null, "resourcePath"); |
Narayan Kamath | 9e289d7 | 2014-04-10 09:26:59 +0000 | [diff] [blame] | 3691 | |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 3692 | legacyCpuAbiString = parser.getAttributeValue(null, "requiredCpuAbi"); |
| 3693 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3694 | parentPackageName = parser.getAttributeValue(null, "parentPackageName"); |
| 3695 | |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 3696 | legacyNativeLibraryPathStr = parser.getAttributeValue(null, "nativeLibraryPath"); |
| 3697 | primaryCpuAbiString = parser.getAttributeValue(null, "primaryCpuAbi"); |
| 3698 | secondaryCpuAbiString = parser.getAttributeValue(null, "secondaryCpuAbi"); |
Narayan Kamath | 4903f64 | 2014-08-11 13:33:45 +0100 | [diff] [blame] | 3699 | cpuAbiOverrideString = parser.getAttributeValue(null, "cpuAbiOverride"); |
Todd Kennedy | ab53289 | 2017-03-08 14:19:49 -0800 | [diff] [blame] | 3700 | updateAvailable = parser.getAttributeValue(null, "updateAvailable"); |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 3701 | |
| 3702 | if (primaryCpuAbiString == null && legacyCpuAbiString != null) { |
| 3703 | primaryCpuAbiString = legacyCpuAbiString; |
| 3704 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 3705 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3706 | version = parser.getAttributeValue(null, "version"); |
| 3707 | if (version != null) { |
| 3708 | try { |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 3709 | versionCode = Long.parseLong(version); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3710 | } catch (NumberFormatException e) { |
| 3711 | } |
| 3712 | } |
| 3713 | installerPackageName = parser.getAttributeValue(null, "installer"); |
Sudheer Shanka | 8c57aea | 2016-04-20 16:47:50 -0700 | [diff] [blame] | 3714 | isOrphaned = parser.getAttributeValue(null, "isOrphaned"); |
Jeff Sharkey | b2b9ab8 | 2015-04-05 21:10:42 -0700 | [diff] [blame] | 3715 | volumeUuid = parser.getAttributeValue(null, "volumeUuid"); |
Jeff Sharkey | 9bc89af | 2017-01-11 11:25:50 -0700 | [diff] [blame] | 3716 | categoryHintString = parser.getAttributeValue(null, "categoryHint"); |
| 3717 | if (categoryHintString != null) { |
| 3718 | try { |
| 3719 | categoryHint = Integer.parseInt(categoryHintString); |
| 3720 | } catch (NumberFormatException e) { |
| 3721 | } |
| 3722 | } |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3723 | |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 3724 | systemStr = parser.getAttributeValue(null, "publicFlags"); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3725 | if (systemStr != null) { |
| 3726 | try { |
| 3727 | pkgFlags = Integer.parseInt(systemStr); |
| 3728 | } catch (NumberFormatException e) { |
| 3729 | } |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 3730 | systemStr = parser.getAttributeValue(null, "privateFlags"); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3731 | if (systemStr != null) { |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 3732 | try { |
| 3733 | pkgPrivateFlags = Integer.parseInt(systemStr); |
| 3734 | } catch (NumberFormatException e) { |
| 3735 | } |
| 3736 | } |
| 3737 | } else { |
| 3738 | // Pre-M -- both public and private flags were stored in one "flags" field. |
| 3739 | systemStr = parser.getAttributeValue(null, "flags"); |
| 3740 | if (systemStr != null) { |
| 3741 | try { |
| 3742 | pkgFlags = Integer.parseInt(systemStr); |
| 3743 | } catch (NumberFormatException e) { |
| 3744 | } |
| 3745 | if ((pkgFlags & PRE_M_APP_INFO_FLAG_HIDDEN) != 0) { |
| 3746 | pkgPrivateFlags |= ApplicationInfo.PRIVATE_FLAG_HIDDEN; |
| 3747 | } |
| 3748 | if ((pkgFlags & PRE_M_APP_INFO_FLAG_CANT_SAVE_STATE) != 0) { |
| 3749 | pkgPrivateFlags |= ApplicationInfo.PRIVATE_FLAG_CANT_SAVE_STATE; |
| 3750 | } |
| 3751 | if ((pkgFlags & PRE_M_APP_INFO_FLAG_FORWARD_LOCK) != 0) { |
| 3752 | pkgPrivateFlags |= ApplicationInfo.PRIVATE_FLAG_FORWARD_LOCK; |
| 3753 | } |
| 3754 | if ((pkgFlags & PRE_M_APP_INFO_FLAG_PRIVILEGED) != 0) { |
| 3755 | pkgPrivateFlags |= ApplicationInfo.PRIVATE_FLAG_PRIVILEGED; |
| 3756 | } |
| 3757 | pkgFlags &= ~(PRE_M_APP_INFO_FLAG_HIDDEN |
| 3758 | | PRE_M_APP_INFO_FLAG_CANT_SAVE_STATE |
| 3759 | | PRE_M_APP_INFO_FLAG_FORWARD_LOCK |
| 3760 | | PRE_M_APP_INFO_FLAG_PRIVILEGED); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3761 | } else { |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 3762 | // For backward compatibility |
| 3763 | systemStr = parser.getAttributeValue(null, "system"); |
| 3764 | if (systemStr != null) { |
| 3765 | pkgFlags |= ("true".equalsIgnoreCase(systemStr)) ? ApplicationInfo.FLAG_SYSTEM |
| 3766 | : 0; |
| 3767 | } else { |
| 3768 | // Old settings that don't specify system... just treat |
| 3769 | // them as system, good enough. |
| 3770 | pkgFlags |= ApplicationInfo.FLAG_SYSTEM; |
| 3771 | } |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3772 | } |
| 3773 | } |
| 3774 | String timeStampStr = parser.getAttributeValue(null, "ft"); |
| 3775 | if (timeStampStr != null) { |
| 3776 | try { |
| 3777 | timeStamp = Long.parseLong(timeStampStr, 16); |
| 3778 | } catch (NumberFormatException e) { |
| 3779 | } |
| 3780 | } else { |
| 3781 | timeStampStr = parser.getAttributeValue(null, "ts"); |
| 3782 | if (timeStampStr != null) { |
| 3783 | try { |
| 3784 | timeStamp = Long.parseLong(timeStampStr); |
| 3785 | } catch (NumberFormatException e) { |
| 3786 | } |
| 3787 | } |
| 3788 | } |
| 3789 | timeStampStr = parser.getAttributeValue(null, "it"); |
| 3790 | if (timeStampStr != null) { |
| 3791 | try { |
| 3792 | firstInstallTime = Long.parseLong(timeStampStr, 16); |
| 3793 | } catch (NumberFormatException e) { |
| 3794 | } |
| 3795 | } |
| 3796 | timeStampStr = parser.getAttributeValue(null, "ut"); |
| 3797 | if (timeStampStr != null) { |
| 3798 | try { |
| 3799 | lastUpdateTime = Long.parseLong(timeStampStr, 16); |
| 3800 | } catch (NumberFormatException e) { |
| 3801 | } |
| 3802 | } |
| 3803 | if (PackageManagerService.DEBUG_SETTINGS) |
| 3804 | Log.v(PackageManagerService.TAG, "Reading package: " + name + " userId=" + idStr |
| 3805 | + " sharedUserId=" + sharedIdStr); |
Todd Kennedy | 788c842 | 2016-08-10 10:52:34 -0700 | [diff] [blame] | 3806 | final int userId = idStr != null ? Integer.parseInt(idStr) : 0; |
| 3807 | final int sharedUserId = sharedIdStr != null ? Integer.parseInt(sharedIdStr) : 0; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3808 | if (resourcePathStr == null) { |
| 3809 | resourcePathStr = codePathStr; |
| 3810 | } |
| 3811 | if (realName != null) { |
| 3812 | realName = realName.intern(); |
| 3813 | } |
| 3814 | if (name == null) { |
| 3815 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 3816 | "Error in package manager settings: <package> has no name at " |
| 3817 | + parser.getPositionDescription()); |
| 3818 | } else if (codePathStr == null) { |
| 3819 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 3820 | "Error in package manager settings: <package> has no codePath at " |
| 3821 | + parser.getPositionDescription()); |
| 3822 | } else if (userId > 0) { |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 3823 | packageSetting = addPackageLPw(name.intern(), realName, new File(codePathStr), |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 3824 | new File(resourcePathStr), legacyNativeLibraryPathStr, primaryCpuAbiString, |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 3825 | secondaryCpuAbiString, cpuAbiOverrideString, userId, versionCode, pkgFlags, |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 3826 | pkgPrivateFlags, parentPackageName, null /*childPackageNames*/, |
| 3827 | null /*usesStaticLibraries*/, null /*usesStaticLibraryVersions*/); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3828 | if (PackageManagerService.DEBUG_SETTINGS) |
| 3829 | Log.i(PackageManagerService.TAG, "Reading package " + name + ": userId=" |
| 3830 | + userId + " pkg=" + packageSetting); |
| 3831 | if (packageSetting == null) { |
| 3832 | PackageManagerService.reportSettingsProblem(Log.ERROR, "Failure adding uid " |
| 3833 | + userId + " while parsing settings at " |
| 3834 | + parser.getPositionDescription()); |
| 3835 | } else { |
| 3836 | packageSetting.setTimeStamp(timeStamp); |
| 3837 | packageSetting.firstInstallTime = firstInstallTime; |
| 3838 | packageSetting.lastUpdateTime = lastUpdateTime; |
| 3839 | } |
| 3840 | } else if (sharedIdStr != null) { |
Todd Kennedy | 788c842 | 2016-08-10 10:52:34 -0700 | [diff] [blame] | 3841 | if (sharedUserId > 0) { |
| 3842 | packageSetting = new PackageSetting(name.intern(), realName, new File( |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 3843 | codePathStr), new File(resourcePathStr), legacyNativeLibraryPathStr, |
Narayan Kamath | 4903f64 | 2014-08-11 13:33:45 +0100 | [diff] [blame] | 3844 | primaryCpuAbiString, secondaryCpuAbiString, cpuAbiOverrideString, |
Todd Kennedy | 788c842 | 2016-08-10 10:52:34 -0700 | [diff] [blame] | 3845 | versionCode, pkgFlags, pkgPrivateFlags, parentPackageName, |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 3846 | null /*childPackageNames*/, sharedUserId, |
| 3847 | null /*usesStaticLibraries*/, null /*usesStaticLibraryVersions*/); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3848 | packageSetting.setTimeStamp(timeStamp); |
| 3849 | packageSetting.firstInstallTime = firstInstallTime; |
| 3850 | packageSetting.lastUpdateTime = lastUpdateTime; |
Todd Kennedy | 788c842 | 2016-08-10 10:52:34 -0700 | [diff] [blame] | 3851 | mPendingPackages.add(packageSetting); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3852 | if (PackageManagerService.DEBUG_SETTINGS) |
| 3853 | Log.i(PackageManagerService.TAG, "Reading package " + name |
Todd Kennedy | 788c842 | 2016-08-10 10:52:34 -0700 | [diff] [blame] | 3854 | + ": sharedUserId=" + sharedUserId + " pkg=" + packageSetting); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3855 | } else { |
| 3856 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 3857 | "Error in package manager settings: package " + name |
| 3858 | + " has bad sharedId " + sharedIdStr + " at " |
| 3859 | + parser.getPositionDescription()); |
| 3860 | } |
| 3861 | } else { |
| 3862 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 3863 | "Error in package manager settings: package " + name + " has bad userId " |
| 3864 | + idStr + " at " + parser.getPositionDescription()); |
| 3865 | } |
| 3866 | } catch (NumberFormatException e) { |
| 3867 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 3868 | "Error in package manager settings: package " + name + " has bad userId " |
| 3869 | + idStr + " at " + parser.getPositionDescription()); |
| 3870 | } |
| 3871 | if (packageSetting != null) { |
| 3872 | packageSetting.uidError = "true".equals(uidError); |
| 3873 | packageSetting.installerPackageName = installerPackageName; |
Sudheer Shanka | 8c57aea | 2016-04-20 16:47:50 -0700 | [diff] [blame] | 3874 | packageSetting.isOrphaned = "true".equals(isOrphaned); |
Jeff Sharkey | b2b9ab8 | 2015-04-05 21:10:42 -0700 | [diff] [blame] | 3875 | packageSetting.volumeUuid = volumeUuid; |
Jeff Sharkey | 9bc89af | 2017-01-11 11:25:50 -0700 | [diff] [blame] | 3876 | packageSetting.categoryHint = categoryHint; |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 3877 | packageSetting.legacyNativeLibraryPathString = legacyNativeLibraryPathStr; |
| 3878 | packageSetting.primaryCpuAbiString = primaryCpuAbiString; |
| 3879 | packageSetting.secondaryCpuAbiString = secondaryCpuAbiString; |
Todd Kennedy | ab53289 | 2017-03-08 14:19:49 -0800 | [diff] [blame] | 3880 | packageSetting.updateAvailable = "true".equals(updateAvailable); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 3881 | // Handle legacy string here for single-user mode |
| 3882 | final String enabledStr = parser.getAttributeValue(null, ATTR_ENABLED); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3883 | if (enabledStr != null) { |
Dianne Hackborn | b8f4000 | 2011-07-19 15:17:43 -0700 | [diff] [blame] | 3884 | try { |
Dianne Hackborn | 3fa3c28a | 2013-03-26 16:15:41 -0700 | [diff] [blame] | 3885 | packageSetting.setEnabled(Integer.parseInt(enabledStr), 0 /* userId */, null); |
Dianne Hackborn | b8f4000 | 2011-07-19 15:17:43 -0700 | [diff] [blame] | 3886 | } catch (NumberFormatException e) { |
| 3887 | if (enabledStr.equalsIgnoreCase("true")) { |
Dianne Hackborn | 3fa3c28a | 2013-03-26 16:15:41 -0700 | [diff] [blame] | 3888 | packageSetting.setEnabled(COMPONENT_ENABLED_STATE_ENABLED, 0, null); |
Dianne Hackborn | b8f4000 | 2011-07-19 15:17:43 -0700 | [diff] [blame] | 3889 | } else if (enabledStr.equalsIgnoreCase("false")) { |
Dianne Hackborn | 3fa3c28a | 2013-03-26 16:15:41 -0700 | [diff] [blame] | 3890 | packageSetting.setEnabled(COMPONENT_ENABLED_STATE_DISABLED, 0, null); |
Dianne Hackborn | b8f4000 | 2011-07-19 15:17:43 -0700 | [diff] [blame] | 3891 | } else if (enabledStr.equalsIgnoreCase("default")) { |
Dianne Hackborn | 3fa3c28a | 2013-03-26 16:15:41 -0700 | [diff] [blame] | 3892 | packageSetting.setEnabled(COMPONENT_ENABLED_STATE_DEFAULT, 0, null); |
Dianne Hackborn | b8f4000 | 2011-07-19 15:17:43 -0700 | [diff] [blame] | 3893 | } else { |
| 3894 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 3895 | "Error in package manager settings: package " + name |
| 3896 | + " has bad enabled value: " + idStr + " at " |
| 3897 | + parser.getPositionDescription()); |
| 3898 | } |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3899 | } |
| 3900 | } else { |
Dianne Hackborn | 3fa3c28a | 2013-03-26 16:15:41 -0700 | [diff] [blame] | 3901 | packageSetting.setEnabled(COMPONENT_ENABLED_STATE_DEFAULT, 0, null); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3902 | } |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 3903 | |
Sudheer Shanka | 2928337 | 2016-04-04 20:56:27 -0700 | [diff] [blame] | 3904 | if (installerPackageName != null) { |
| 3905 | mInstallerPackages.add(installerPackageName); |
| 3906 | } |
| 3907 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3908 | final String installStatusStr = parser.getAttributeValue(null, "installStatus"); |
| 3909 | if (installStatusStr != null) { |
| 3910 | if (installStatusStr.equalsIgnoreCase("false")) { |
| 3911 | packageSetting.installStatus = PackageSettingBase.PKG_INSTALL_INCOMPLETE; |
| 3912 | } else { |
| 3913 | packageSetting.installStatus = PackageSettingBase.PKG_INSTALL_COMPLETE; |
| 3914 | } |
| 3915 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3916 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3917 | int outerDepth = parser.getDepth(); |
| 3918 | int type; |
| 3919 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 3920 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 3921 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 3922 | continue; |
| 3923 | } |
| 3924 | |
| 3925 | String tagName = parser.getName(); |
Selim Gurun | 5c8acb4 | 2016-04-07 16:34:02 -0700 | [diff] [blame] | 3926 | // Legacy |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 3927 | if (tagName.equals(TAG_DISABLED_COMPONENTS)) { |
| 3928 | readDisabledComponentsLPw(packageSetting, parser, 0); |
| 3929 | } else if (tagName.equals(TAG_ENABLED_COMPONENTS)) { |
| 3930 | readEnabledComponentsLPw(packageSetting, parser, 0); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3931 | } else if (tagName.equals("sigs")) { |
| 3932 | packageSetting.signatures.readXml(parser, mPastSignatures); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 3933 | } else if (tagName.equals(TAG_PERMISSIONS)) { |
| 3934 | readInstallPermissionsLPr(parser, |
| 3935 | packageSetting.getPermissionsState()); |
Svetoslav | cf959f6 | 2015-03-26 20:53:34 -0700 | [diff] [blame] | 3936 | packageSetting.installPermissionsFixed = true; |
dcashman | 3a0dbfb | 2014-07-07 13:53:36 -0700 | [diff] [blame] | 3937 | } else if (tagName.equals("proper-signing-keyset")) { |
| 3938 | long id = Long.parseLong(parser.getAttributeValue(null, "identifier")); |
dcashman | 8c04fac | 2015-03-23 11:39:42 -0700 | [diff] [blame] | 3939 | Integer refCt = mKeySetRefs.get(id); |
| 3940 | if (refCt != null) { |
| 3941 | mKeySetRefs.put(id, refCt + 1); |
| 3942 | } else { |
| 3943 | mKeySetRefs.put(id, 1); |
| 3944 | } |
dcashman | 3a0dbfb | 2014-07-07 13:53:36 -0700 | [diff] [blame] | 3945 | packageSetting.keySetData.setProperSigningKeySet(id); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 3946 | } else if (tagName.equals("signing-keyset")) { |
dcashman | 8c04fac | 2015-03-23 11:39:42 -0700 | [diff] [blame] | 3947 | // from v1 of keysetmanagerservice - no longer used |
dcashman | 55b1078 | 2014-04-09 14:20:38 -0700 | [diff] [blame] | 3948 | } else if (tagName.equals("upgrade-keyset")) { |
| 3949 | long id = Long.parseLong(parser.getAttributeValue(null, "identifier")); |
| 3950 | packageSetting.keySetData.addUpgradeKeySetById(id); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 3951 | } else if (tagName.equals("defined-keyset")) { |
| 3952 | long id = Long.parseLong(parser.getAttributeValue(null, "identifier")); |
| 3953 | String alias = parser.getAttributeValue(null, "alias"); |
dcashman | 8c04fac | 2015-03-23 11:39:42 -0700 | [diff] [blame] | 3954 | Integer refCt = mKeySetRefs.get(id); |
| 3955 | if (refCt != null) { |
| 3956 | mKeySetRefs.put(id, refCt + 1); |
| 3957 | } else { |
| 3958 | mKeySetRefs.put(id, 1); |
| 3959 | } |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 3960 | packageSetting.keySetData.addDefinedKeySet(id, alias); |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 3961 | } else if (tagName.equals(TAG_DOMAIN_VERIFICATION)) { |
| 3962 | readDomainVerificationLPw(parser, packageSetting); |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3963 | } else if (tagName.equals(TAG_CHILD_PACKAGE)) { |
| 3964 | String childPackageName = parser.getAttributeValue(null, ATTR_NAME); |
| 3965 | if (packageSetting.childPackageNames == null) { |
| 3966 | packageSetting.childPackageNames = new ArrayList<>(); |
| 3967 | } |
| 3968 | packageSetting.childPackageNames.add(childPackageName); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3969 | } else { |
| 3970 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 3971 | "Unknown element under <package>: " + parser.getName()); |
| 3972 | XmlUtils.skipCurrentTag(parser); |
| 3973 | } |
| 3974 | } |
| 3975 | } else { |
| 3976 | XmlUtils.skipCurrentTag(parser); |
| 3977 | } |
| 3978 | } |
| 3979 | |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 3980 | private void readDisabledComponentsLPw(PackageSettingBase packageSetting, XmlPullParser parser, |
| 3981 | int userId) throws IOException, XmlPullParserException { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3982 | int outerDepth = parser.getDepth(); |
| 3983 | int type; |
| 3984 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 3985 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 3986 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 3987 | continue; |
| 3988 | } |
| 3989 | |
| 3990 | String tagName = parser.getName(); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 3991 | if (tagName.equals(TAG_ITEM)) { |
| 3992 | String name = parser.getAttributeValue(null, ATTR_NAME); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3993 | if (name != null) { |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 3994 | packageSetting.addDisabledComponent(name.intern(), userId); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3995 | } else { |
| 3996 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 3997 | "Error in package manager settings: <disabled-components> has" |
| 3998 | + " no name at " + parser.getPositionDescription()); |
| 3999 | } |
| 4000 | } else { |
| 4001 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 4002 | "Unknown element under <disabled-components>: " + parser.getName()); |
| 4003 | } |
| 4004 | XmlUtils.skipCurrentTag(parser); |
| 4005 | } |
| 4006 | } |
| 4007 | |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 4008 | private void readEnabledComponentsLPw(PackageSettingBase packageSetting, XmlPullParser parser, |
| 4009 | int userId) throws IOException, XmlPullParserException { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 4010 | int outerDepth = parser.getDepth(); |
| 4011 | int type; |
| 4012 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 4013 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 4014 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 4015 | continue; |
| 4016 | } |
| 4017 | |
| 4018 | String tagName = parser.getName(); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 4019 | if (tagName.equals(TAG_ITEM)) { |
| 4020 | String name = parser.getAttributeValue(null, ATTR_NAME); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 4021 | if (name != null) { |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 4022 | packageSetting.addEnabledComponent(name.intern(), userId); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 4023 | } else { |
| 4024 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 4025 | "Error in package manager settings: <enabled-components> has" |
| 4026 | + " no name at " + parser.getPositionDescription()); |
| 4027 | } |
| 4028 | } else { |
| 4029 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 4030 | "Unknown element under <enabled-components>: " + parser.getName()); |
| 4031 | } |
| 4032 | XmlUtils.skipCurrentTag(parser); |
| 4033 | } |
| 4034 | } |
| 4035 | |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 4036 | private void readSharedUserLPw(XmlPullParser parser) throws XmlPullParserException,IOException { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 4037 | String name = null; |
| 4038 | String idStr = null; |
| 4039 | int pkgFlags = 0; |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 4040 | int pkgPrivateFlags = 0; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 4041 | SharedUserSetting su = null; |
| 4042 | try { |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 4043 | name = parser.getAttributeValue(null, ATTR_NAME); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 4044 | idStr = parser.getAttributeValue(null, "userId"); |
| 4045 | int userId = idStr != null ? Integer.parseInt(idStr) : 0; |
| 4046 | if ("true".equals(parser.getAttributeValue(null, "system"))) { |
| 4047 | pkgFlags |= ApplicationInfo.FLAG_SYSTEM; |
| 4048 | } |
| 4049 | if (name == null) { |
| 4050 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 4051 | "Error in package manager settings: <shared-user> has no name at " |
| 4052 | + parser.getPositionDescription()); |
| 4053 | } else if (userId == 0) { |
| 4054 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 4055 | "Error in package manager settings: shared-user " + name |
| 4056 | + " has bad userId " + idStr + " at " |
| 4057 | + parser.getPositionDescription()); |
| 4058 | } else { |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 4059 | if ((su = addSharedUserLPw(name.intern(), userId, pkgFlags, pkgPrivateFlags)) |
| 4060 | == null) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 4061 | PackageManagerService |
| 4062 | .reportSettingsProblem(Log.ERROR, "Occurred while parsing settings at " |
| 4063 | + parser.getPositionDescription()); |
| 4064 | } |
| 4065 | } |
| 4066 | } catch (NumberFormatException e) { |
| 4067 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 4068 | "Error in package manager settings: package " + name + " has bad userId " |
| 4069 | + idStr + " at " + parser.getPositionDescription()); |
| 4070 | } |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 4071 | |
| 4072 | if (su != null) { |
| 4073 | int outerDepth = parser.getDepth(); |
| 4074 | int type; |
| 4075 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 4076 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 4077 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 4078 | continue; |
| 4079 | } |
| 4080 | |
| 4081 | String tagName = parser.getName(); |
| 4082 | if (tagName.equals("sigs")) { |
| 4083 | su.signatures.readXml(parser, mPastSignatures); |
| 4084 | } else if (tagName.equals("perms")) { |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4085 | readInstallPermissionsLPr(parser, su.getPermissionsState()); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 4086 | } else { |
| 4087 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 4088 | "Unknown element under <shared-user>: " + parser.getName()); |
| 4089 | XmlUtils.skipCurrentTag(parser); |
| 4090 | } |
| 4091 | } |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 4092 | } else { |
| 4093 | XmlUtils.skipCurrentTag(parser); |
| 4094 | } |
| 4095 | } |
| 4096 | |
Fyodor Kupolov | d8327bd | 2015-11-30 17:42:43 -0800 | [diff] [blame] | 4097 | void createNewUserLI(@NonNull PackageManagerService service, @NonNull Installer installer, |
Sudheer Shanka | 7cb54a3 | 2016-09-16 12:59:05 -0700 | [diff] [blame] | 4098 | int userHandle, String[] disallowedPackages) { |
Fyodor Kupolov | d8327bd | 2015-11-30 17:42:43 -0800 | [diff] [blame] | 4099 | String[] volumeUuids; |
| 4100 | String[] names; |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 4101 | int[] appIds; |
Fyodor Kupolov | d8327bd | 2015-11-30 17:42:43 -0800 | [diff] [blame] | 4102 | String[] seinfos; |
Janis Danisevskis | f340974 | 2016-01-12 14:46:33 +0000 | [diff] [blame] | 4103 | int[] targetSdkVersions; |
Fyodor Kupolov | d8327bd | 2015-11-30 17:42:43 -0800 | [diff] [blame] | 4104 | int packagesCount; |
| 4105 | synchronized (mPackages) { |
| 4106 | Collection<PackageSetting> packages = mPackages.values(); |
| 4107 | packagesCount = packages.size(); |
| 4108 | volumeUuids = new String[packagesCount]; |
| 4109 | names = new String[packagesCount]; |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 4110 | appIds = new int[packagesCount]; |
Fyodor Kupolov | d8327bd | 2015-11-30 17:42:43 -0800 | [diff] [blame] | 4111 | seinfos = new String[packagesCount]; |
Janis Danisevskis | f340974 | 2016-01-12 14:46:33 +0000 | [diff] [blame] | 4112 | targetSdkVersions = new int[packagesCount]; |
Fyodor Kupolov | d8327bd | 2015-11-30 17:42:43 -0800 | [diff] [blame] | 4113 | Iterator<PackageSetting> packagesIterator = packages.iterator(); |
| 4114 | for (int i = 0; i < packagesCount; i++) { |
| 4115 | PackageSetting ps = packagesIterator.next(); |
| 4116 | if (ps.pkg == null || ps.pkg.applicationInfo == null) { |
| 4117 | continue; |
| 4118 | } |
Sudheer Shanka | 7cb54a3 | 2016-09-16 12:59:05 -0700 | [diff] [blame] | 4119 | final boolean shouldInstall = ps.isSystem() && |
| 4120 | !ArrayUtils.contains(disallowedPackages, ps.name); |
Fyodor Kupolov | d8327bd | 2015-11-30 17:42:43 -0800 | [diff] [blame] | 4121 | // Only system apps are initially installed. |
Sudheer Shanka | 7cb54a3 | 2016-09-16 12:59:05 -0700 | [diff] [blame] | 4122 | ps.setInstalled(shouldInstall, userHandle); |
Amith Yamasani | 23ab7f5 | 2017-01-22 17:43:24 -0800 | [diff] [blame] | 4123 | if (!shouldInstall) { |
| 4124 | writeKernelMappingLPr(ps); |
| 4125 | } |
Fyodor Kupolov | d8327bd | 2015-11-30 17:42:43 -0800 | [diff] [blame] | 4126 | // Need to create a data directory for all apps under this user. Accumulate all |
| 4127 | // required args and call the installer after mPackages lock has been released |
| 4128 | volumeUuids[i] = ps.volumeUuid; |
| 4129 | names[i] = ps.name; |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 4130 | appIds[i] = ps.appId; |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 4131 | seinfos[i] = ps.pkg.applicationInfo.seInfo; |
Janis Danisevskis | f340974 | 2016-01-12 14:46:33 +0000 | [diff] [blame] | 4132 | targetSdkVersions[i] = ps.pkg.applicationInfo.targetSdkVersion; |
Fyodor Kupolov | d8327bd | 2015-11-30 17:42:43 -0800 | [diff] [blame] | 4133 | } |
| 4134 | } |
| 4135 | for (int i = 0; i < packagesCount; i++) { |
| 4136 | if (names[i] == null) { |
Amith Yamasani | 41cd577 | 2014-07-10 15:26:00 -0700 | [diff] [blame] | 4137 | continue; |
| 4138 | } |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 4139 | // TODO: triage flags! |
Jeff Sharkey | 47f7108 | 2016-02-01 17:03:54 -0700 | [diff] [blame] | 4140 | final int flags = StorageManager.FLAG_STORAGE_CE | StorageManager.FLAG_STORAGE_DE; |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 4141 | try { |
| 4142 | installer.createAppData(volumeUuids[i], names[i], userHandle, flags, appIds[i], |
Janis Danisevskis | f340974 | 2016-01-12 14:46:33 +0000 | [diff] [blame] | 4143 | seinfos[i], targetSdkVersions[i]); |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 4144 | } catch (InstallerException e) { |
| 4145 | Slog.w(TAG, "Failed to prepare app data", e); |
| 4146 | } |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 4147 | } |
Fyodor Kupolov | d8327bd | 2015-11-30 17:42:43 -0800 | [diff] [blame] | 4148 | synchronized (mPackages) { |
| 4149 | applyDefaultPreferredAppsLPw(service, userHandle); |
Fyodor Kupolov | d8327bd | 2015-11-30 17:42:43 -0800 | [diff] [blame] | 4150 | } |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 4151 | } |
| 4152 | |
Alexandra Gherghina | 539a7ef | 2014-07-07 12:27:54 +0100 | [diff] [blame] | 4153 | void removeUserLPw(int userId) { |
Dianne Hackborn | 6309271 | 2012-10-07 14:45:35 -0700 | [diff] [blame] | 4154 | Set<Entry<String, PackageSetting>> entries = mPackages.entrySet(); |
| 4155 | for (Entry<String, PackageSetting> entry : entries) { |
| 4156 | entry.getValue().removeUser(userId); |
| 4157 | } |
| 4158 | mPreferredActivities.remove(userId); |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 4159 | File file = getUserPackagesStateFile(userId); |
| 4160 | file.delete(); |
| 4161 | file = getUserPackagesStateBackupFile(userId); |
| 4162 | file.delete(); |
Nicolas Prevot | e702404 | 2014-07-08 15:47:17 +0100 | [diff] [blame] | 4163 | removeCrossProfileIntentFiltersLPw(userId); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4164 | |
Fyodor Kupolov | 6954259 | 2016-05-23 14:22:38 -0700 | [diff] [blame] | 4165 | mRuntimePermissionsPersistence.onUserRemovedLPw(userId); |
Jeff Sharkey | 91edde2 | 2015-05-20 12:04:42 -0700 | [diff] [blame] | 4166 | |
| 4167 | writePackageListLPr(); |
Amith Yamasani | 23ab7f5 | 2017-01-22 17:43:24 -0800 | [diff] [blame] | 4168 | |
| 4169 | // Inform kernel that the user was removed, so that packages are marked uninstalled |
| 4170 | // for sdcardfs |
| 4171 | writeKernelRemoveUserLPr(userId); |
Nicolas Prevot | a0f4885 | 2014-05-27 11:21:11 +0100 | [diff] [blame] | 4172 | } |
| 4173 | |
Nicolas Prevot | e702404 | 2014-07-08 15:47:17 +0100 | [diff] [blame] | 4174 | void removeCrossProfileIntentFiltersLPw(int userId) { |
| 4175 | synchronized (mCrossProfileIntentResolvers) { |
| 4176 | // userId is the source user |
| 4177 | if (mCrossProfileIntentResolvers.get(userId) != null) { |
| 4178 | mCrossProfileIntentResolvers.remove(userId); |
| 4179 | writePackageRestrictionsLPr(userId); |
Nicolas Prevot | a0f4885 | 2014-05-27 11:21:11 +0100 | [diff] [blame] | 4180 | } |
Nicolas Prevot | e702404 | 2014-07-08 15:47:17 +0100 | [diff] [blame] | 4181 | // userId is the target user |
| 4182 | int count = mCrossProfileIntentResolvers.size(); |
| 4183 | for (int i = 0; i < count; i++) { |
| 4184 | int sourceUserId = mCrossProfileIntentResolvers.keyAt(i); |
| 4185 | CrossProfileIntentResolver cpir = mCrossProfileIntentResolvers.get(sourceUserId); |
| 4186 | boolean needsWriting = false; |
Jeff Sharkey | 9f837a9 | 2014-10-24 12:07:24 -0700 | [diff] [blame] | 4187 | ArraySet<CrossProfileIntentFilter> cpifs = |
| 4188 | new ArraySet<CrossProfileIntentFilter>(cpir.filterSet()); |
Nicolas Prevot | e702404 | 2014-07-08 15:47:17 +0100 | [diff] [blame] | 4189 | for (CrossProfileIntentFilter cpif : cpifs) { |
| 4190 | if (cpif.getTargetUserId() == userId) { |
| 4191 | needsWriting = true; |
| 4192 | cpir.removeFilter(cpif); |
| 4193 | } |
| 4194 | } |
| 4195 | if (needsWriting) { |
| 4196 | writePackageRestrictionsLPr(sourceUserId); |
| 4197 | } |
Nicolas Prevot | a0f4885 | 2014-05-27 11:21:11 +0100 | [diff] [blame] | 4198 | } |
| 4199 | } |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 4200 | } |
| 4201 | |
Geremy Condra | 12c1838 | 2013-03-06 16:49:06 -0800 | [diff] [blame] | 4202 | // This should be called (at least) whenever an application is removed |
| 4203 | private void setFirstAvailableUid(int uid) { |
| 4204 | if (uid > mFirstAvailableUid) { |
| 4205 | mFirstAvailableUid = uid; |
| 4206 | } |
| 4207 | } |
| 4208 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 4209 | // Returns -1 if we could not find an available UserId to assign |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4210 | private int newUserIdLPw(Object obj) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 4211 | // Let's be stupidly inefficient for now... |
| 4212 | final int N = mUserIds.size(); |
Geremy Condra | 12c1838 | 2013-03-06 16:49:06 -0800 | [diff] [blame] | 4213 | for (int i = mFirstAvailableUid; i < N; i++) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 4214 | if (mUserIds.get(i) == null) { |
| 4215 | mUserIds.set(i, obj); |
Dianne Hackborn | 21fbd1f | 2012-02-10 10:38:10 -0800 | [diff] [blame] | 4216 | return Process.FIRST_APPLICATION_UID + i; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 4217 | } |
| 4218 | } |
| 4219 | |
| 4220 | // None left? |
Dianne Hackborn | 21fbd1f | 2012-02-10 10:38:10 -0800 | [diff] [blame] | 4221 | if (N > (Process.LAST_APPLICATION_UID-Process.FIRST_APPLICATION_UID)) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 4222 | return -1; |
| 4223 | } |
| 4224 | |
| 4225 | mUserIds.add(obj); |
Dianne Hackborn | 21fbd1f | 2012-02-10 10:38:10 -0800 | [diff] [blame] | 4226 | return Process.FIRST_APPLICATION_UID + N; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 4227 | } |
| 4228 | |
Kenny Root | 0aaa0d9 | 2011-09-12 16:42:55 -0700 | [diff] [blame] | 4229 | public VerifierDeviceIdentity getVerifierDeviceIdentityLPw() { |
| 4230 | if (mVerifierDeviceIdentity == null) { |
| 4231 | mVerifierDeviceIdentity = VerifierDeviceIdentity.generate(); |
| 4232 | |
| 4233 | writeLPr(); |
| 4234 | } |
| 4235 | |
| 4236 | return mVerifierDeviceIdentity; |
| 4237 | } |
| 4238 | |
Todd Kennedy | ff35e66 | 2016-09-20 12:53:52 -0700 | [diff] [blame] | 4239 | boolean hasOtherDisabledSystemPkgWithChildLPr(String parentPackageName, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4240 | String childPackageName) { |
| 4241 | final int packageCount = mDisabledSysPackages.size(); |
| 4242 | for (int i = 0; i < packageCount; i++) { |
| 4243 | PackageSetting disabledPs = mDisabledSysPackages.valueAt(i); |
| 4244 | if (disabledPs.childPackageNames == null || disabledPs.childPackageNames.isEmpty()) { |
| 4245 | continue; |
| 4246 | } |
| 4247 | if (disabledPs.name.equals(parentPackageName)) { |
| 4248 | continue; |
| 4249 | } |
| 4250 | final int childCount = disabledPs.childPackageNames.size(); |
| 4251 | for (int j = 0; j < childCount; j++) { |
| 4252 | String currChildPackageName = disabledPs.childPackageNames.get(j); |
| 4253 | if (currChildPackageName.equals(childPackageName)) { |
| 4254 | return true; |
| 4255 | } |
| 4256 | } |
| 4257 | } |
| 4258 | return false; |
| 4259 | } |
| 4260 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4261 | public PackageSetting getDisabledSystemPkgLPr(String name) { |
| 4262 | PackageSetting ps = mDisabledSysPackages.get(name); |
| 4263 | return ps; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 4264 | } |
| 4265 | |
Jeff Sharkey | 5217cac | 2015-12-20 15:34:01 -0700 | [diff] [blame] | 4266 | boolean isEnabledAndMatchLPr(ComponentInfo componentInfo, int flags, int userId) { |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 4267 | final PackageSetting ps = mPackages.get(componentInfo.packageName); |
| 4268 | if (ps == null) return false; |
Jeff Sharkey | e17ac15 | 2015-11-06 22:40:29 -0800 | [diff] [blame] | 4269 | |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 4270 | final PackageUserState userState = ps.readUserState(userId); |
| 4271 | return userState.isMatch(componentInfo, flags); |
Jeff Sharkey | e17ac15 | 2015-11-06 22:40:29 -0800 | [diff] [blame] | 4272 | } |
| 4273 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4274 | String getInstallerPackageNameLPr(String packageName) { |
| 4275 | final PackageSetting pkg = mPackages.get(packageName); |
| 4276 | if (pkg == null) { |
| 4277 | throw new IllegalArgumentException("Unknown package: " + packageName); |
| 4278 | } |
| 4279 | return pkg.installerPackageName; |
| 4280 | } |
| 4281 | |
Sudheer Shanka | 8c57aea | 2016-04-20 16:47:50 -0700 | [diff] [blame] | 4282 | boolean isOrphaned(String packageName) { |
| 4283 | final PackageSetting pkg = mPackages.get(packageName); |
| 4284 | if (pkg == null) { |
| 4285 | throw new IllegalArgumentException("Unknown package: " + packageName); |
| 4286 | } |
| 4287 | return pkg.isOrphaned; |
| 4288 | } |
| 4289 | |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 4290 | int getApplicationEnabledSettingLPr(String packageName, int userId) { |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4291 | final PackageSetting pkg = mPackages.get(packageName); |
| 4292 | if (pkg == null) { |
| 4293 | throw new IllegalArgumentException("Unknown package: " + packageName); |
| 4294 | } |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 4295 | return pkg.getEnabled(userId); |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4296 | } |
| 4297 | |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 4298 | int getComponentEnabledSettingLPr(ComponentName componentName, int userId) { |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4299 | final String packageName = componentName.getPackageName(); |
| 4300 | final PackageSetting pkg = mPackages.get(packageName); |
| 4301 | if (pkg == null) { |
| 4302 | throw new IllegalArgumentException("Unknown component: " + componentName); |
| 4303 | } |
| 4304 | final String classNameStr = componentName.getClassName(); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 4305 | return pkg.getCurrentEnabledStateLPr(classNameStr, userId); |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4306 | } |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 4307 | |
Svet Ganov | 973edd19 | 2016-09-08 20:15:55 -0700 | [diff] [blame] | 4308 | boolean wasPackageEverLaunchedLPr(String packageName, int userId) { |
| 4309 | final PackageSetting pkgSetting = mPackages.get(packageName); |
| 4310 | if (pkgSetting == null) { |
| 4311 | throw new IllegalArgumentException("Unknown package: " + packageName); |
| 4312 | } |
| 4313 | return !pkgSetting.getNotLaunched(userId); |
| 4314 | } |
| 4315 | |
Christopher Tate | 5cf5578 | 2016-04-25 17:08:56 -0700 | [diff] [blame] | 4316 | boolean setPackageStoppedStateLPw(PackageManagerService pm, String packageName, |
Jeff Sharkey | bd0e9e4 | 2015-04-30 16:04:50 -0700 | [diff] [blame] | 4317 | boolean stopped, boolean allowedByPermission, int uid, int userId) { |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 4318 | int appId = UserHandle.getAppId(uid); |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4319 | final PackageSetting pkgSetting = mPackages.get(packageName); |
| 4320 | if (pkgSetting == null) { |
| 4321 | throw new IllegalArgumentException("Unknown package: " + packageName); |
| 4322 | } |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 4323 | if (!allowedByPermission && (appId != pkgSetting.appId)) { |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4324 | throw new SecurityException( |
| 4325 | "Permission Denial: attempt to change stopped state from pid=" |
| 4326 | + Binder.getCallingPid() |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 4327 | + ", uid=" + uid + ", package uid=" + pkgSetting.appId); |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4328 | } |
| 4329 | if (DEBUG_STOPPED) { |
| 4330 | if (stopped) { |
| 4331 | RuntimeException e = new RuntimeException("here"); |
| 4332 | e.fillInStackTrace(); |
| 4333 | Slog.i(TAG, "Stopping package " + packageName, e); |
| 4334 | } |
| 4335 | } |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 4336 | if (pkgSetting.getStopped(userId) != stopped) { |
| 4337 | pkgSetting.setStopped(stopped, userId); |
| 4338 | // pkgSetting.pkg.mSetStopped = stopped; |
| 4339 | if (pkgSetting.getNotLaunched(userId)) { |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4340 | if (pkgSetting.installerPackageName != null) { |
Christopher Tate | 5cf5578 | 2016-04-25 17:08:56 -0700 | [diff] [blame] | 4341 | pm.notifyFirstLaunch(pkgSetting.name, pkgSetting.installerPackageName, userId); |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4342 | } |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 4343 | pkgSetting.setNotLaunched(false, userId); |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4344 | } |
| 4345 | return true; |
| 4346 | } |
| 4347 | return false; |
| 4348 | } |
| 4349 | |
Todd Kennedy | 13715d5 | 2016-08-01 13:38:57 -0700 | [diff] [blame] | 4350 | private static List<UserInfo> getAllUsers(UserManagerService userManager) { |
Amith Yamasani | 7ea3e7d | 2012-04-20 15:19:35 -0700 | [diff] [blame] | 4351 | long id = Binder.clearCallingIdentity(); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 4352 | try { |
Todd Kennedy | 13715d5 | 2016-08-01 13:38:57 -0700 | [diff] [blame] | 4353 | return userManager.getUsers(false); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 4354 | } catch (NullPointerException npe) { |
| 4355 | // packagemanager not yet initialized |
Amith Yamasani | 7ea3e7d | 2012-04-20 15:19:35 -0700 | [diff] [blame] | 4356 | } finally { |
| 4357 | Binder.restoreCallingIdentity(id); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 4358 | } |
| 4359 | return null; |
| 4360 | } |
| 4361 | |
Jeff Sharkey | b2b9ab8 | 2015-04-05 21:10:42 -0700 | [diff] [blame] | 4362 | /** |
| 4363 | * Return all {@link PackageSetting} that are actively installed on the |
| 4364 | * given {@link VolumeInfo#fsUuid}. |
| 4365 | */ |
| 4366 | List<PackageSetting> getVolumePackagesLPr(String volumeUuid) { |
Jeff Sharkey | b2b9ab8 | 2015-04-05 21:10:42 -0700 | [diff] [blame] | 4367 | ArrayList<PackageSetting> res = new ArrayList<>(); |
| 4368 | for (int i = 0; i < mPackages.size(); i++) { |
| 4369 | final PackageSetting setting = mPackages.valueAt(i); |
| 4370 | if (Objects.equals(volumeUuid, setting.volumeUuid)) { |
| 4371 | res.add(setting); |
| 4372 | } |
| 4373 | } |
| 4374 | return res; |
| 4375 | } |
| 4376 | |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4377 | static void printFlags(PrintWriter pw, int val, Object[] spec) { |
Joe Onorato | 20963df | 2012-01-04 18:13:24 -0800 | [diff] [blame] | 4378 | pw.print("[ "); |
| 4379 | for (int i=0; i<spec.length; i+=2) { |
| 4380 | int mask = (Integer)spec[i]; |
| 4381 | if ((val & mask) != 0) { |
| 4382 | pw.print(spec[i+1]); |
| 4383 | pw.print(" "); |
| 4384 | } |
| 4385 | } |
| 4386 | pw.print("]"); |
| 4387 | } |
| 4388 | |
| 4389 | static final Object[] FLAG_DUMP_SPEC = new Object[] { |
| 4390 | ApplicationInfo.FLAG_SYSTEM, "SYSTEM", |
| 4391 | ApplicationInfo.FLAG_DEBUGGABLE, "DEBUGGABLE", |
| 4392 | ApplicationInfo.FLAG_HAS_CODE, "HAS_CODE", |
| 4393 | ApplicationInfo.FLAG_PERSISTENT, "PERSISTENT", |
| 4394 | ApplicationInfo.FLAG_FACTORY_TEST, "FACTORY_TEST", |
| 4395 | ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING, "ALLOW_TASK_REPARENTING", |
| 4396 | ApplicationInfo.FLAG_ALLOW_CLEAR_USER_DATA, "ALLOW_CLEAR_USER_DATA", |
| 4397 | ApplicationInfo.FLAG_UPDATED_SYSTEM_APP, "UPDATED_SYSTEM_APP", |
| 4398 | ApplicationInfo.FLAG_TEST_ONLY, "TEST_ONLY", |
| 4399 | ApplicationInfo.FLAG_VM_SAFE_MODE, "VM_SAFE_MODE", |
| 4400 | ApplicationInfo.FLAG_ALLOW_BACKUP, "ALLOW_BACKUP", |
| 4401 | ApplicationInfo.FLAG_KILL_AFTER_RESTORE, "KILL_AFTER_RESTORE", |
| 4402 | ApplicationInfo.FLAG_RESTORE_ANY_VERSION, "RESTORE_ANY_VERSION", |
| 4403 | ApplicationInfo.FLAG_EXTERNAL_STORAGE, "EXTERNAL_STORAGE", |
| 4404 | ApplicationInfo.FLAG_LARGE_HEAP, "LARGE_HEAP", |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 4405 | }; |
| 4406 | |
Wale Ogunwale | 72a73e3 | 2016-10-13 12:16:39 -0700 | [diff] [blame] | 4407 | private static final Object[] PRIVATE_FLAG_DUMP_SPEC = new Object[] { |
Svet Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 4408 | ApplicationInfo.PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_RESIZEABLE, "PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_RESIZEABLE", |
| 4409 | ApplicationInfo.PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION, "PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION", |
| 4410 | ApplicationInfo.PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_UNRESIZEABLE, "PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_UNRESIZEABLE", |
| 4411 | ApplicationInfo.PRIVATE_FLAG_BACKUP_IN_FOREGROUND, "BACKUP_IN_FOREGROUND", |
| 4412 | ApplicationInfo.PRIVATE_FLAG_CANT_SAVE_STATE, "CANT_SAVE_STATE", |
| 4413 | ApplicationInfo.PRIVATE_FLAG_DEFAULT_TO_DEVICE_PROTECTED_STORAGE, "DEFAULT_TO_DEVICE_PROTECTED_STORAGE", |
| 4414 | ApplicationInfo.PRIVATE_FLAG_DIRECT_BOOT_AWARE, "DIRECT_BOOT_AWARE", |
| 4415 | ApplicationInfo.PRIVATE_FLAG_FORWARD_LOCK, "FORWARD_LOCK", |
| 4416 | ApplicationInfo.PRIVATE_FLAG_HAS_DOMAIN_URLS, "HAS_DOMAIN_URLS", |
| 4417 | ApplicationInfo.PRIVATE_FLAG_HIDDEN, "HIDDEN", |
| 4418 | ApplicationInfo.PRIVATE_FLAG_INSTANT, "EPHEMERAL", |
| 4419 | ApplicationInfo.PRIVATE_FLAG_ISOLATED_SPLIT_LOADING, "ISOLATED_SPLIT_LOADING", |
| 4420 | ApplicationInfo.PRIVATE_FLAG_OEM, "OEM", |
| 4421 | ApplicationInfo.PRIVATE_FLAG_PARTIALLY_DIRECT_BOOT_AWARE, "PARTIALLY_DIRECT_BOOT_AWARE", |
| 4422 | ApplicationInfo.PRIVATE_FLAG_PRIVILEGED, "PRIVILEGED", |
| 4423 | ApplicationInfo.PRIVATE_FLAG_REQUIRED_FOR_SYSTEM_USER, "REQUIRED_FOR_SYSTEM_USER", |
| 4424 | ApplicationInfo.PRIVATE_FLAG_STATIC_SHARED_LIBRARY, "STATIC_SHARED_LIBRARY", |
Jiyong Park | 002fdbd | 2017-02-13 20:50:31 +0900 | [diff] [blame] | 4425 | ApplicationInfo.PRIVATE_FLAG_VENDOR, "VENDOR", |
Svet Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 4426 | ApplicationInfo.PRIVATE_FLAG_VIRTUAL_PRELOAD, "VIRTUAL_PRELOAD", |
Joe Onorato | 20963df | 2012-01-04 18:13:24 -0800 | [diff] [blame] | 4427 | }; |
| 4428 | |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 4429 | void dumpVersionLPr(IndentingPrintWriter pw) { |
| 4430 | pw.increaseIndent(); |
| 4431 | for (int i= 0; i < mVersion.size(); i++) { |
| 4432 | final String volumeUuid = mVersion.keyAt(i); |
| 4433 | final VersionInfo ver = mVersion.valueAt(i); |
| 4434 | if (Objects.equals(StorageManager.UUID_PRIVATE_INTERNAL, volumeUuid)) { |
| 4435 | pw.println("Internal:"); |
| 4436 | } else if (Objects.equals(StorageManager.UUID_PRIMARY_PHYSICAL, volumeUuid)) { |
| 4437 | pw.println("External:"); |
| 4438 | } else { |
| 4439 | pw.println("UUID " + volumeUuid + ":"); |
| 4440 | } |
| 4441 | pw.increaseIndent(); |
| 4442 | pw.printPair("sdkVersion", ver.sdkVersion); |
| 4443 | pw.printPair("databaseVersion", ver.databaseVersion); |
| 4444 | pw.println(); |
| 4445 | pw.printPair("fingerprint", ver.fingerprint); |
| 4446 | pw.println(); |
| 4447 | pw.decreaseIndent(); |
| 4448 | } |
| 4449 | pw.decreaseIndent(); |
| 4450 | } |
| 4451 | |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 4452 | void dumpPackageLPr(PrintWriter pw, String prefix, String checkinTag, |
| 4453 | ArraySet<String> permissionNames, PackageSetting ps, SimpleDateFormat sdf, |
Dianne Hackborn | 9f5b0a2 | 2015-08-13 18:25:20 -0700 | [diff] [blame] | 4454 | Date date, List<UserInfo> users, boolean dumpAll) { |
Dianne Hackborn | 60dc0d9 | 2014-01-17 13:29:21 -0800 | [diff] [blame] | 4455 | if (checkinTag != null) { |
| 4456 | pw.print(checkinTag); |
| 4457 | pw.print(","); |
| 4458 | pw.print(ps.realName != null ? ps.realName : ps.name); |
| 4459 | pw.print(","); |
| 4460 | pw.print(ps.appId); |
| 4461 | pw.print(","); |
| 4462 | pw.print(ps.versionCode); |
| 4463 | pw.print(","); |
| 4464 | pw.print(ps.firstInstallTime); |
| 4465 | pw.print(","); |
| 4466 | pw.print(ps.lastUpdateTime); |
| 4467 | pw.print(","); |
| 4468 | pw.print(ps.installerPackageName != null ? ps.installerPackageName : "?"); |
| 4469 | pw.println(); |
Jeff Sharkey | c4d05fc | 2014-12-01 16:24:01 -0800 | [diff] [blame] | 4470 | if (ps.pkg != null) { |
| 4471 | pw.print(checkinTag); pw.print("-"); pw.print("splt,"); |
| 4472 | pw.print("base,"); |
| 4473 | pw.println(ps.pkg.baseRevisionCode); |
| 4474 | if (ps.pkg.splitNames != null) { |
| 4475 | for (int i = 0; i < ps.pkg.splitNames.length; i++) { |
| 4476 | pw.print(checkinTag); pw.print("-"); pw.print("splt,"); |
| 4477 | pw.print(ps.pkg.splitNames[i]); pw.print(","); |
| 4478 | pw.println(ps.pkg.splitRevisionCodes[i]); |
| 4479 | } |
| 4480 | } |
| 4481 | } |
Dianne Hackborn | 60dc0d9 | 2014-01-17 13:29:21 -0800 | [diff] [blame] | 4482 | for (UserInfo user : users) { |
| 4483 | pw.print(checkinTag); |
| 4484 | pw.print("-"); |
| 4485 | pw.print("usr"); |
| 4486 | pw.print(","); |
| 4487 | pw.print(user.id); |
| 4488 | pw.print(","); |
| 4489 | pw.print(ps.getInstalled(user.id) ? "I" : "i"); |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 4490 | pw.print(ps.getHidden(user.id) ? "B" : "b"); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4491 | pw.print(ps.getSuspended(user.id) ? "SU" : "su"); |
Dianne Hackborn | 60dc0d9 | 2014-01-17 13:29:21 -0800 | [diff] [blame] | 4492 | pw.print(ps.getStopped(user.id) ? "S" : "s"); |
| 4493 | pw.print(ps.getNotLaunched(user.id) ? "l" : "L"); |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 4494 | pw.print(ps.getInstantApp(user.id) ? "IA" : "ia"); |
Todd Kennedy | 5eb5a7d | 2017-08-01 07:42:47 -0700 | [diff] [blame] | 4495 | pw.print(ps.getVirtulalPreload(user.id) ? "VPI" : "vpi"); |
Dianne Hackborn | 60dc0d9 | 2014-01-17 13:29:21 -0800 | [diff] [blame] | 4496 | pw.print(","); |
| 4497 | pw.print(ps.getEnabled(user.id)); |
| 4498 | String lastDisabledAppCaller = ps.getLastDisabledAppCaller(user.id); |
| 4499 | pw.print(","); |
| 4500 | pw.print(lastDisabledAppCaller != null ? lastDisabledAppCaller : "?"); |
| 4501 | pw.println(); |
| 4502 | } |
| 4503 | return; |
| 4504 | } |
| 4505 | |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 4506 | pw.print(prefix); pw.print("Package ["); |
| 4507 | pw.print(ps.realName != null ? ps.realName : ps.name); |
| 4508 | pw.print("] ("); |
| 4509 | pw.print(Integer.toHexString(System.identityHashCode(ps))); |
| 4510 | pw.println("):"); |
| 4511 | |
| 4512 | if (ps.realName != null) { |
| 4513 | pw.print(prefix); pw.print(" compat name="); |
| 4514 | pw.println(ps.name); |
| 4515 | } |
| 4516 | |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4517 | pw.print(prefix); pw.print(" userId="); pw.println(ps.appId); |
| 4518 | |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 4519 | if (ps.sharedUser != null) { |
| 4520 | pw.print(prefix); pw.print(" sharedUser="); pw.println(ps.sharedUser); |
| 4521 | } |
| 4522 | pw.print(prefix); pw.print(" pkg="); pw.println(ps.pkg); |
| 4523 | pw.print(prefix); pw.print(" codePath="); pw.println(ps.codePathString); |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 4524 | if (permissionNames == null) { |
| 4525 | pw.print(prefix); pw.print(" resourcePath="); pw.println(ps.resourcePathString); |
| 4526 | pw.print(prefix); pw.print(" legacyNativeLibraryDir="); |
| 4527 | pw.println(ps.legacyNativeLibraryPathString); |
| 4528 | pw.print(prefix); pw.print(" primaryCpuAbi="); pw.println(ps.primaryCpuAbiString); |
| 4529 | pw.print(prefix); pw.print(" secondaryCpuAbi="); pw.println(ps.secondaryCpuAbiString); |
| 4530 | } |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 4531 | pw.print(prefix); pw.print(" versionCode="); pw.print(ps.versionCode); |
| 4532 | if (ps.pkg != null) { |
Todd Kennedy | 89d6018 | 2016-03-11 11:18:32 -0800 | [diff] [blame] | 4533 | pw.print(" minSdk="); pw.print(ps.pkg.applicationInfo.minSdkVersion); |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 4534 | pw.print(" targetSdk="); pw.print(ps.pkg.applicationInfo.targetSdkVersion); |
| 4535 | } |
| 4536 | pw.println(); |
| 4537 | if (ps.pkg != null) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4538 | if (ps.pkg.parentPackage != null) { |
| 4539 | PackageParser.Package parentPkg = ps.pkg.parentPackage; |
| 4540 | PackageSetting pps = mPackages.get(parentPkg.packageName); |
| 4541 | if (pps == null || !pps.codePathString.equals(parentPkg.codePath)) { |
| 4542 | pps = mDisabledSysPackages.get(parentPkg.packageName); |
| 4543 | } |
| 4544 | if (pps != null) { |
| 4545 | pw.print(prefix); pw.print(" parentPackage="); |
| 4546 | pw.println(pps.realName != null ? pps.realName : pps.name); |
| 4547 | } |
| 4548 | } else if (ps.pkg.childPackages != null) { |
| 4549 | pw.print(prefix); pw.print(" childPackages=["); |
| 4550 | final int childCount = ps.pkg.childPackages.size(); |
| 4551 | for (int i = 0; i < childCount; i++) { |
| 4552 | PackageParser.Package childPkg = ps.pkg.childPackages.get(i); |
| 4553 | PackageSetting cps = mPackages.get(childPkg.packageName); |
| 4554 | if (cps == null || !cps.codePathString.equals(childPkg.codePath)) { |
| 4555 | cps = mDisabledSysPackages.get(childPkg.packageName); |
| 4556 | } |
| 4557 | if (cps != null) { |
| 4558 | if (i > 0) { |
| 4559 | pw.print(", "); |
| 4560 | } |
| 4561 | pw.print(cps.realName != null ? cps.realName : cps.name); |
| 4562 | } |
| 4563 | } |
| 4564 | pw.println("]"); |
| 4565 | } |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 4566 | pw.print(prefix); pw.print(" versionName="); pw.println(ps.pkg.mVersionName); |
Jeff Sharkey | c4d05fc | 2014-12-01 16:24:01 -0800 | [diff] [blame] | 4567 | pw.print(prefix); pw.print(" splits="); dumpSplitNames(pw, ps.pkg); pw.println(); |
Patrick Baumann | 47117fc | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 4568 | final int apkSigningVersion = ps.pkg.mSigningDetails.signatureSchemeVersion; |
| 4569 | pw.print(prefix); pw.print(" apkSigningVersion="); pw.println(apkSigningVersion); |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 4570 | pw.print(prefix); pw.print(" applicationInfo="); |
| 4571 | pw.println(ps.pkg.applicationInfo.toString()); |
| 4572 | pw.print(prefix); pw.print(" flags="); printFlags(pw, ps.pkg.applicationInfo.flags, |
| 4573 | FLAG_DUMP_SPEC); pw.println(); |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 4574 | if (ps.pkg.applicationInfo.privateFlags != 0) { |
| 4575 | pw.print(prefix); pw.print(" privateFlags="); printFlags(pw, |
| 4576 | ps.pkg.applicationInfo.privateFlags, PRIVATE_FLAG_DUMP_SPEC); pw.println(); |
| 4577 | } |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 4578 | pw.print(prefix); pw.print(" dataDir="); pw.println(ps.pkg.applicationInfo.dataDir); |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 4579 | pw.print(prefix); pw.print(" supportsScreens=["); |
| 4580 | boolean first = true; |
| 4581 | if ((ps.pkg.applicationInfo.flags & ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS) != 0) { |
| 4582 | if (!first) |
| 4583 | pw.print(", "); |
| 4584 | first = false; |
| 4585 | pw.print("small"); |
| 4586 | } |
| 4587 | if ((ps.pkg.applicationInfo.flags & ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS) != 0) { |
| 4588 | if (!first) |
| 4589 | pw.print(", "); |
| 4590 | first = false; |
| 4591 | pw.print("medium"); |
| 4592 | } |
| 4593 | if ((ps.pkg.applicationInfo.flags & ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS) != 0) { |
| 4594 | if (!first) |
| 4595 | pw.print(", "); |
| 4596 | first = false; |
| 4597 | pw.print("large"); |
| 4598 | } |
| 4599 | if ((ps.pkg.applicationInfo.flags & ApplicationInfo.FLAG_SUPPORTS_XLARGE_SCREENS) != 0) { |
| 4600 | if (!first) |
| 4601 | pw.print(", "); |
| 4602 | first = false; |
| 4603 | pw.print("xlarge"); |
| 4604 | } |
| 4605 | if ((ps.pkg.applicationInfo.flags & ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS) != 0) { |
| 4606 | if (!first) |
| 4607 | pw.print(", "); |
| 4608 | first = false; |
| 4609 | pw.print("resizeable"); |
| 4610 | } |
| 4611 | if ((ps.pkg.applicationInfo.flags & ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES) != 0) { |
| 4612 | if (!first) |
| 4613 | pw.print(", "); |
| 4614 | first = false; |
| 4615 | pw.print("anyDensity"); |
| 4616 | } |
| 4617 | pw.println("]"); |
| 4618 | if (ps.pkg.libraryNames != null && ps.pkg.libraryNames.size() > 0) { |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 4619 | pw.print(prefix); pw.println(" dynamic libraries:"); |
| 4620 | for (int i = 0; i<ps.pkg.libraryNames.size(); i++) { |
| 4621 | pw.print(prefix); pw.print(" "); |
| 4622 | pw.println(ps.pkg.libraryNames.get(i)); |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 4623 | } |
| 4624 | } |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 4625 | if (ps.pkg.staticSharedLibName != null) { |
| 4626 | pw.print(prefix); pw.println(" static library:"); |
| 4627 | pw.print(prefix); pw.print(" "); |
| 4628 | pw.print("name:"); pw.print(ps.pkg.staticSharedLibName); |
| 4629 | pw.print(" version:"); pw.println(ps.pkg.staticSharedLibVersion); |
| 4630 | } |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 4631 | if (ps.pkg.usesLibraries != null && ps.pkg.usesLibraries.size() > 0) { |
| 4632 | pw.print(prefix); pw.println(" usesLibraries:"); |
| 4633 | for (int i=0; i<ps.pkg.usesLibraries.size(); i++) { |
| 4634 | pw.print(prefix); pw.print(" "); pw.println(ps.pkg.usesLibraries.get(i)); |
| 4635 | } |
| 4636 | } |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 4637 | if (ps.pkg.usesStaticLibraries != null |
| 4638 | && ps.pkg.usesStaticLibraries.size() > 0) { |
| 4639 | pw.print(prefix); pw.println(" usesStaticLibraries:"); |
| 4640 | for (int i=0; i<ps.pkg.usesStaticLibraries.size(); i++) { |
| 4641 | pw.print(prefix); pw.print(" "); |
| 4642 | pw.print(ps.pkg.usesStaticLibraries.get(i)); pw.print(" version:"); |
| 4643 | pw.println(ps.pkg.usesStaticLibrariesVersions[i]); |
| 4644 | } |
| 4645 | } |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 4646 | if (ps.pkg.usesOptionalLibraries != null |
| 4647 | && ps.pkg.usesOptionalLibraries.size() > 0) { |
| 4648 | pw.print(prefix); pw.println(" usesOptionalLibraries:"); |
| 4649 | for (int i=0; i<ps.pkg.usesOptionalLibraries.size(); i++) { |
| 4650 | pw.print(prefix); pw.print(" "); |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 4651 | pw.println(ps.pkg.usesOptionalLibraries.get(i)); |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 4652 | } |
| 4653 | } |
| 4654 | if (ps.pkg.usesLibraryFiles != null |
| 4655 | && ps.pkg.usesLibraryFiles.length > 0) { |
| 4656 | pw.print(prefix); pw.println(" usesLibraryFiles:"); |
| 4657 | for (int i=0; i<ps.pkg.usesLibraryFiles.length; i++) { |
| 4658 | pw.print(prefix); pw.print(" "); pw.println(ps.pkg.usesLibraryFiles[i]); |
| 4659 | } |
| 4660 | } |
| 4661 | } |
| 4662 | pw.print(prefix); pw.print(" timeStamp="); |
| 4663 | date.setTime(ps.timeStamp); |
| 4664 | pw.println(sdf.format(date)); |
| 4665 | pw.print(prefix); pw.print(" firstInstallTime="); |
| 4666 | date.setTime(ps.firstInstallTime); |
| 4667 | pw.println(sdf.format(date)); |
| 4668 | pw.print(prefix); pw.print(" lastUpdateTime="); |
| 4669 | date.setTime(ps.lastUpdateTime); |
| 4670 | pw.println(sdf.format(date)); |
| 4671 | if (ps.installerPackageName != null) { |
| 4672 | pw.print(prefix); pw.print(" installerPackageName="); |
| 4673 | pw.println(ps.installerPackageName); |
| 4674 | } |
Jeff Sharkey | b2b9ab8 | 2015-04-05 21:10:42 -0700 | [diff] [blame] | 4675 | if (ps.volumeUuid != null) { |
| 4676 | pw.print(prefix); pw.print(" volumeUuid="); |
| 4677 | pw.println(ps.volumeUuid); |
| 4678 | } |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 4679 | pw.print(prefix); pw.print(" signatures="); pw.println(ps.signatures); |
Svetoslav | cf959f6 | 2015-03-26 20:53:34 -0700 | [diff] [blame] | 4680 | pw.print(prefix); pw.print(" installPermissionsFixed="); |
| 4681 | pw.print(ps.installPermissionsFixed); |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 4682 | pw.print(" installStatus="); pw.println(ps.installStatus); |
| 4683 | pw.print(prefix); pw.print(" pkgFlags="); printFlags(pw, ps.pkgFlags, FLAG_DUMP_SPEC); |
| 4684 | pw.println(); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4685 | |
Dianne Hackborn | cfbfafe | 2015-07-21 16:57:51 -0700 | [diff] [blame] | 4686 | if (ps.pkg != null && ps.pkg.permissions != null && ps.pkg.permissions.size() > 0) { |
| 4687 | final ArrayList<PackageParser.Permission> perms = ps.pkg.permissions; |
| 4688 | pw.print(prefix); pw.println(" declared permissions:"); |
| 4689 | for (int i=0; i<perms.size(); i++) { |
| 4690 | PackageParser.Permission perm = perms.get(i); |
| 4691 | if (permissionNames != null |
| 4692 | && !permissionNames.contains(perm.info.name)) { |
| 4693 | continue; |
| 4694 | } |
| 4695 | pw.print(prefix); pw.print(" "); pw.print(perm.info.name); |
| 4696 | pw.print(": prot="); |
| 4697 | pw.print(PermissionInfo.protectionToString(perm.info.protectionLevel)); |
| 4698 | if ((perm.info.flags&PermissionInfo.FLAG_COSTS_MONEY) != 0) { |
| 4699 | pw.print(", COSTS_MONEY"); |
| 4700 | } |
Svet Ganov | 2a1376d | 2016-02-22 17:20:35 -0800 | [diff] [blame] | 4701 | if ((perm.info.flags&PermissionInfo.FLAG_REMOVED) != 0) { |
Svet Ganov | 52153f4 | 2015-08-11 08:59:12 -0700 | [diff] [blame] | 4702 | pw.print(", HIDDEN"); |
Svet Ganov | 3e0be74 | 2015-08-07 23:06:00 -0700 | [diff] [blame] | 4703 | } |
Dianne Hackborn | cfbfafe | 2015-07-21 16:57:51 -0700 | [diff] [blame] | 4704 | if ((perm.info.flags&PermissionInfo.FLAG_INSTALLED) != 0) { |
| 4705 | pw.print(", INSTALLED"); |
| 4706 | } |
| 4707 | pw.println(); |
| 4708 | } |
| 4709 | } |
| 4710 | |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 4711 | if ((permissionNames != null || dumpAll) && ps.pkg != null |
| 4712 | && ps.pkg.requestedPermissions != null |
Dianne Hackborn | 9f5b0a2 | 2015-08-13 18:25:20 -0700 | [diff] [blame] | 4713 | && ps.pkg.requestedPermissions.size() > 0) { |
| 4714 | final ArrayList<String> perms = ps.pkg.requestedPermissions; |
| 4715 | pw.print(prefix); pw.println(" requested permissions:"); |
| 4716 | for (int i=0; i<perms.size(); i++) { |
| 4717 | String perm = perms.get(i); |
| 4718 | if (permissionNames != null |
| 4719 | && !permissionNames.contains(perm)) { |
| 4720 | continue; |
| 4721 | } |
| 4722 | pw.print(prefix); pw.print(" "); pw.println(perm); |
| 4723 | } |
| 4724 | } |
| 4725 | |
| 4726 | if (ps.sharedUser == null || permissionNames != null || dumpAll) { |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4727 | PermissionsState permissionsState = ps.getPermissionsState(); |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 4728 | dumpInstallPermissionsLPr(pw, prefix + " ", permissionNames, permissionsState); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4729 | } |
| 4730 | |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 4731 | for (UserInfo user : users) { |
| 4732 | pw.print(prefix); pw.print(" User "); pw.print(user.id); pw.print(": "); |
Jeff Sharkey | 4288419 | 2016-04-09 16:12:01 -0600 | [diff] [blame] | 4733 | pw.print("ceDataInode="); |
| 4734 | pw.print(ps.getCeDataInode(user.id)); |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 4735 | pw.print(" installed="); |
| 4736 | pw.print(ps.getInstalled(user.id)); |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 4737 | pw.print(" hidden="); |
| 4738 | pw.print(ps.getHidden(user.id)); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4739 | pw.print(" suspended="); |
| 4740 | pw.print(ps.getSuspended(user.id)); |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 4741 | pw.print(" stopped="); |
| 4742 | pw.print(ps.getStopped(user.id)); |
| 4743 | pw.print(" notLaunched="); |
| 4744 | pw.print(ps.getNotLaunched(user.id)); |
| 4745 | pw.print(" enabled="); |
Fyodor Kupolov | 09546ff | 2017-04-03 17:45:50 -0700 | [diff] [blame] | 4746 | pw.print(ps.getEnabled(user.id)); |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 4747 | pw.print(" instant="); |
Dianne Hackborn | c50a108 | 2017-08-15 14:10:39 -0700 | [diff] [blame] | 4748 | pw.print(ps.getInstantApp(user.id)); |
Todd Kennedy | 5eb5a7d | 2017-08-01 07:42:47 -0700 | [diff] [blame] | 4749 | pw.print(" virtual="); |
| 4750 | pw.println(ps.getVirtulalPreload(user.id)); |
Todd Kennedy | b274947 | 2017-06-13 08:24:32 -0700 | [diff] [blame] | 4751 | |
| 4752 | String[] overlayPaths = ps.getOverlayPaths(user.id); |
| 4753 | if (overlayPaths != null && overlayPaths.length > 0) { |
Todd Kennedy | 560830c | 2017-06-16 13:55:13 -0700 | [diff] [blame] | 4754 | pw.print(prefix); pw.println(" overlay paths:"); |
Todd Kennedy | b274947 | 2017-06-13 08:24:32 -0700 | [diff] [blame] | 4755 | for (String path : overlayPaths) { |
Todd Kennedy | 560830c | 2017-06-16 13:55:13 -0700 | [diff] [blame] | 4756 | pw.print(prefix); pw.print(" "); pw.println(path); |
Todd Kennedy | b274947 | 2017-06-13 08:24:32 -0700 | [diff] [blame] | 4757 | } |
| 4758 | } |
| 4759 | |
Dianne Hackborn | 3fa3c28a | 2013-03-26 16:15:41 -0700 | [diff] [blame] | 4760 | String lastDisabledAppCaller = ps.getLastDisabledAppCaller(user.id); |
| 4761 | if (lastDisabledAppCaller != null) { |
| 4762 | pw.print(prefix); pw.print(" lastDisabledCaller: "); |
| 4763 | pw.println(lastDisabledAppCaller); |
| 4764 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4765 | |
| 4766 | if (ps.sharedUser == null) { |
| 4767 | PermissionsState permissionsState = ps.getPermissionsState(); |
| 4768 | dumpGidsLPr(pw, prefix + " ", permissionsState.computeGids(user.id)); |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 4769 | dumpRuntimePermissionsLPr(pw, prefix + " ", permissionNames, permissionsState |
Dianne Hackborn | 9f5b0a2 | 2015-08-13 18:25:20 -0700 | [diff] [blame] | 4770 | .getRuntimePermissionStates(user.id), dumpAll); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4771 | } |
| 4772 | |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 4773 | if (permissionNames == null) { |
| 4774 | ArraySet<String> cmp = ps.getDisabledComponents(user.id); |
| 4775 | if (cmp != null && cmp.size() > 0) { |
| 4776 | pw.print(prefix); pw.println(" disabledComponents:"); |
| 4777 | for (String s : cmp) { |
Dianne Hackborn | cfbfafe | 2015-07-21 16:57:51 -0700 | [diff] [blame] | 4778 | pw.print(prefix); pw.print(" "); pw.println(s); |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 4779 | } |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 4780 | } |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 4781 | cmp = ps.getEnabledComponents(user.id); |
| 4782 | if (cmp != null && cmp.size() > 0) { |
| 4783 | pw.print(prefix); pw.println(" enabledComponents:"); |
| 4784 | for (String s : cmp) { |
Dianne Hackborn | cfbfafe | 2015-07-21 16:57:51 -0700 | [diff] [blame] | 4785 | pw.print(prefix); pw.print(" "); pw.println(s); |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 4786 | } |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 4787 | } |
| 4788 | } |
| 4789 | } |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 4790 | } |
| 4791 | |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 4792 | void dumpPackagesLPr(PrintWriter pw, String packageName, ArraySet<String> permissionNames, |
| 4793 | DumpState dumpState, boolean checkin) { |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4794 | final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| 4795 | final Date date = new Date(); |
| 4796 | boolean printedSomething = false; |
Todd Kennedy | 13715d5 | 2016-08-01 13:38:57 -0700 | [diff] [blame] | 4797 | List<UserInfo> users = getAllUsers(UserManagerService.getInstance()); |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4798 | for (final PackageSetting ps : mPackages.values()) { |
| 4799 | if (packageName != null && !packageName.equals(ps.realName) |
| 4800 | && !packageName.equals(ps.name)) { |
| 4801 | continue; |
| 4802 | } |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 4803 | if (permissionNames != null |
| 4804 | && !ps.getPermissionsState().hasRequestedPermission(permissionNames)) { |
| 4805 | continue; |
| 4806 | } |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4807 | |
Dianne Hackborn | 60dc0d9 | 2014-01-17 13:29:21 -0800 | [diff] [blame] | 4808 | if (!checkin && packageName != null) { |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4809 | dumpState.setSharedUser(ps.sharedUser); |
| 4810 | } |
| 4811 | |
Dianne Hackborn | 60dc0d9 | 2014-01-17 13:29:21 -0800 | [diff] [blame] | 4812 | if (!checkin && !printedSomething) { |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4813 | if (dumpState.onTitlePrinted()) |
Dianne Hackborn | cbfd23e | 2013-06-11 14:26:53 -0700 | [diff] [blame] | 4814 | pw.println(); |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4815 | pw.println("Packages:"); |
| 4816 | printedSomething = true; |
| 4817 | } |
Dianne Hackborn | 9f5b0a2 | 2015-08-13 18:25:20 -0700 | [diff] [blame] | 4818 | dumpPackageLPr(pw, " ", checkin ? "pkg" : null, permissionNames, ps, sdf, date, users, |
| 4819 | packageName != null); |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4820 | } |
| 4821 | |
| 4822 | printedSomething = false; |
Dianne Hackborn | 9f5b0a2 | 2015-08-13 18:25:20 -0700 | [diff] [blame] | 4823 | if (mRenamedPackages.size() > 0 && permissionNames == null) { |
Andy McFadden | 2f36229 | 2012-01-20 14:43:38 -0800 | [diff] [blame] | 4824 | for (final Map.Entry<String, String> e : mRenamedPackages.entrySet()) { |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4825 | if (packageName != null && !packageName.equals(e.getKey()) |
| 4826 | && !packageName.equals(e.getValue())) { |
| 4827 | continue; |
| 4828 | } |
Dianne Hackborn | 60dc0d9 | 2014-01-17 13:29:21 -0800 | [diff] [blame] | 4829 | if (!checkin) { |
| 4830 | if (!printedSomething) { |
| 4831 | if (dumpState.onTitlePrinted()) |
| 4832 | pw.println(); |
| 4833 | pw.println("Renamed packages:"); |
| 4834 | printedSomething = true; |
| 4835 | } |
| 4836 | pw.print(" "); |
| 4837 | } else { |
| 4838 | pw.print("ren,"); |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4839 | } |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4840 | pw.print(e.getKey()); |
Dianne Hackborn | 60dc0d9 | 2014-01-17 13:29:21 -0800 | [diff] [blame] | 4841 | pw.print(checkin ? " -> " : ","); |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4842 | pw.println(e.getValue()); |
| 4843 | } |
| 4844 | } |
| 4845 | |
| 4846 | printedSomething = false; |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 4847 | if (mDisabledSysPackages.size() > 0 && permissionNames == null) { |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4848 | for (final PackageSetting ps : mDisabledSysPackages.values()) { |
| 4849 | if (packageName != null && !packageName.equals(ps.realName) |
| 4850 | && !packageName.equals(ps.name)) { |
| 4851 | continue; |
| 4852 | } |
Dianne Hackborn | 60dc0d9 | 2014-01-17 13:29:21 -0800 | [diff] [blame] | 4853 | if (!checkin && !printedSomething) { |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4854 | if (dumpState.onTitlePrinted()) |
Dianne Hackborn | cbfd23e | 2013-06-11 14:26:53 -0700 | [diff] [blame] | 4855 | pw.println(); |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4856 | pw.println("Hidden system packages:"); |
| 4857 | printedSomething = true; |
| 4858 | } |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 4859 | dumpPackageLPr(pw, " ", checkin ? "dis" : null, permissionNames, ps, sdf, date, |
Dianne Hackborn | 9f5b0a2 | 2015-08-13 18:25:20 -0700 | [diff] [blame] | 4860 | users, packageName != null); |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4861 | } |
| 4862 | } |
| 4863 | } |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 4864 | |
Netta P | 426cbef | 2017-02-10 14:38:39 -0800 | [diff] [blame] | 4865 | void dumpPackagesProto(ProtoOutputStream proto) { |
| 4866 | List<UserInfo> users = getAllUsers(UserManagerService.getInstance()); |
| 4867 | |
| 4868 | final int count = mPackages.size(); |
| 4869 | for (int i = 0; i < count; i++) { |
| 4870 | final PackageSetting ps = mPackages.valueAt(i); |
| 4871 | ps.writeToProto(proto, PackageServiceDumpProto.PACKAGES, users); |
| 4872 | } |
| 4873 | } |
| 4874 | |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 4875 | void dumpPermissionsLPr(PrintWriter pw, String packageName, ArraySet<String> permissionNames, |
| 4876 | DumpState dumpState) { |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 4877 | mPermissions.dumpPermissions(pw, packageName, permissionNames, |
| 4878 | (mReadExternalStorageEnforced == Boolean.TRUE), dumpState); |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4879 | } |
Jeff Sharkey | 1c27576a | 2012-04-11 19:07:08 -0700 | [diff] [blame] | 4880 | |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 4881 | void dumpSharedUsersLPr(PrintWriter pw, String packageName, ArraySet<String> permissionNames, |
| 4882 | DumpState dumpState, boolean checkin) { |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4883 | boolean printedSomething = false; |
| 4884 | for (SharedUserSetting su : mSharedUsers.values()) { |
| 4885 | if (packageName != null && su != dumpState.getSharedUser()) { |
| 4886 | continue; |
| 4887 | } |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 4888 | if (permissionNames != null |
| 4889 | && !su.getPermissionsState().hasRequestedPermission(permissionNames)) { |
| 4890 | continue; |
| 4891 | } |
Dianne Hackborn | d052a94 | 2014-11-21 15:23:13 -0800 | [diff] [blame] | 4892 | if (!checkin) { |
| 4893 | if (!printedSomething) { |
| 4894 | if (dumpState.onTitlePrinted()) |
| 4895 | pw.println(); |
| 4896 | pw.println("Shared users:"); |
| 4897 | printedSomething = true; |
| 4898 | } |
| 4899 | pw.print(" SharedUser ["); |
| 4900 | pw.print(su.name); |
| 4901 | pw.print("] ("); |
| 4902 | pw.print(Integer.toHexString(System.identityHashCode(su))); |
| 4903 | pw.println("):"); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4904 | |
| 4905 | String prefix = " "; |
| 4906 | pw.print(prefix); pw.print("userId="); pw.println(su.userId); |
| 4907 | |
| 4908 | PermissionsState permissionsState = su.getPermissionsState(); |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 4909 | dumpInstallPermissionsLPr(pw, prefix, permissionNames, permissionsState); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4910 | |
| 4911 | for (int userId : UserManagerService.getInstance().getUserIds()) { |
| 4912 | final int[] gids = permissionsState.computeGids(userId); |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 4913 | List<PermissionState> permissions = permissionsState |
| 4914 | .getRuntimePermissionStates(userId); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4915 | if (!ArrayUtils.isEmpty(gids) || !permissions.isEmpty()) { |
| 4916 | pw.print(prefix); pw.print("User "); pw.print(userId); pw.println(": "); |
| 4917 | dumpGidsLPr(pw, prefix + " ", gids); |
Dianne Hackborn | 9f5b0a2 | 2015-08-13 18:25:20 -0700 | [diff] [blame] | 4918 | dumpRuntimePermissionsLPr(pw, prefix + " ", permissionNames, permissions, |
| 4919 | packageName != null); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4920 | } |
Dianne Hackborn | d052a94 | 2014-11-21 15:23:13 -0800 | [diff] [blame] | 4921 | } |
| 4922 | } else { |
| 4923 | pw.print("suid,"); pw.print(su.userId); pw.print(","); pw.println(su.name); |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4924 | } |
| 4925 | } |
| 4926 | } |
| 4927 | |
Netta P | 426cbef | 2017-02-10 14:38:39 -0800 | [diff] [blame] | 4928 | void dumpSharedUsersProto(ProtoOutputStream proto) { |
| 4929 | final int count = mSharedUsers.size(); |
| 4930 | for (int i = 0; i < count; i++) { |
Yi Jin | d6759d4 | 2017-10-12 15:08:49 -0700 | [diff] [blame] | 4931 | mSharedUsers.valueAt(i).writeToProto(proto, PackageServiceDumpProto.SHARED_USERS); |
Netta P | 426cbef | 2017-02-10 14:38:39 -0800 | [diff] [blame] | 4932 | } |
| 4933 | } |
| 4934 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4935 | void dumpReadMessagesLPr(PrintWriter pw, DumpState dumpState) { |
| 4936 | pw.println("Settings parse messages:"); |
| 4937 | pw.print(mReadMessages.toString()); |
| 4938 | } |
Jeff Sharkey | c4d05fc | 2014-12-01 16:24:01 -0800 | [diff] [blame] | 4939 | |
Christopher Tate | e9fd1fa | 2015-09-15 16:43:07 -0700 | [diff] [blame] | 4940 | void dumpRestoredPermissionGrantsLPr(PrintWriter pw, DumpState dumpState) { |
| 4941 | if (mRestoredUserGrants.size() > 0) { |
| 4942 | pw.println(); |
| 4943 | pw.println("Restored (pending) permission grants:"); |
| 4944 | for (int userIndex = 0; userIndex < mRestoredUserGrants.size(); userIndex++) { |
| 4945 | ArrayMap<String, ArraySet<RestoredPermissionGrant>> grantsByPackage = |
| 4946 | mRestoredUserGrants.valueAt(userIndex); |
| 4947 | if (grantsByPackage != null && grantsByPackage.size() > 0) { |
| 4948 | final int userId = mRestoredUserGrants.keyAt(userIndex); |
| 4949 | pw.print(" User "); pw.println(userId); |
| 4950 | |
| 4951 | for (int pkgIndex = 0; pkgIndex < grantsByPackage.size(); pkgIndex++) { |
| 4952 | ArraySet<RestoredPermissionGrant> grants = grantsByPackage.valueAt(pkgIndex); |
| 4953 | if (grants != null && grants.size() > 0) { |
| 4954 | final String pkgName = grantsByPackage.keyAt(pkgIndex); |
| 4955 | pw.print(" "); pw.print(pkgName); pw.println(" :"); |
| 4956 | |
| 4957 | for (RestoredPermissionGrant g : grants) { |
| 4958 | pw.print(" "); |
| 4959 | pw.print(g.permissionName); |
| 4960 | if (g.granted) { |
| 4961 | pw.print(" GRANTED"); |
| 4962 | } |
| 4963 | if ((g.grantBits&FLAG_PERMISSION_USER_SET) != 0) { |
| 4964 | pw.print(" user_set"); |
| 4965 | } |
| 4966 | if ((g.grantBits&FLAG_PERMISSION_USER_FIXED) != 0) { |
| 4967 | pw.print(" user_fixed"); |
| 4968 | } |
| 4969 | if ((g.grantBits&FLAG_PERMISSION_REVOKE_ON_UPGRADE) != 0) { |
| 4970 | pw.print(" revoke_on_upgrade"); |
| 4971 | } |
| 4972 | pw.println(); |
| 4973 | } |
| 4974 | } |
| 4975 | } |
| 4976 | } |
| 4977 | } |
| 4978 | pw.println(); |
| 4979 | } |
| 4980 | } |
| 4981 | |
Jeff Sharkey | c4d05fc | 2014-12-01 16:24:01 -0800 | [diff] [blame] | 4982 | private static void dumpSplitNames(PrintWriter pw, PackageParser.Package pkg) { |
| 4983 | if (pkg == null) { |
| 4984 | pw.print("unknown"); |
| 4985 | } else { |
| 4986 | // [base:10, config.mdpi, config.xhdpi:12] |
| 4987 | pw.print("["); |
| 4988 | pw.print("base"); |
| 4989 | if (pkg.baseRevisionCode != 0) { |
| 4990 | pw.print(":"); pw.print(pkg.baseRevisionCode); |
| 4991 | } |
| 4992 | if (pkg.splitNames != null) { |
| 4993 | for (int i = 0; i < pkg.splitNames.length; i++) { |
| 4994 | pw.print(", "); |
| 4995 | pw.print(pkg.splitNames[i]); |
| 4996 | if (pkg.splitRevisionCodes[i] != 0) { |
| 4997 | pw.print(":"); pw.print(pkg.splitRevisionCodes[i]); |
| 4998 | } |
| 4999 | } |
| 5000 | } |
| 5001 | pw.print("]"); |
| 5002 | } |
| 5003 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5004 | |
| 5005 | void dumpGidsLPr(PrintWriter pw, String prefix, int[] gids) { |
| 5006 | if (!ArrayUtils.isEmpty(gids)) { |
Fabrice Di Meglio | 6227172 | 2015-04-10 17:24:02 -0700 | [diff] [blame] | 5007 | pw.print(prefix); |
| 5008 | pw.print("gids="); pw.println( |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5009 | PackageManagerService.arrayToString(gids)); |
| 5010 | } |
| 5011 | } |
| 5012 | |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 5013 | void dumpRuntimePermissionsLPr(PrintWriter pw, String prefix, ArraySet<String> permissionNames, |
Dianne Hackborn | 9f5b0a2 | 2015-08-13 18:25:20 -0700 | [diff] [blame] | 5014 | List<PermissionState> permissionStates, boolean dumpAll) { |
| 5015 | if (!permissionStates.isEmpty() || dumpAll) { |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5016 | pw.print(prefix); pw.println("runtime permissions:"); |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5017 | for (PermissionState permissionState : permissionStates) { |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 5018 | if (permissionNames != null |
| 5019 | && !permissionNames.contains(permissionState.getName())) { |
| 5020 | continue; |
| 5021 | } |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5022 | pw.print(prefix); pw.print(" "); pw.print(permissionState.getName()); |
Dianne Hackborn | cfbfafe | 2015-07-21 16:57:51 -0700 | [diff] [blame] | 5023 | pw.print(": granted="); pw.print(permissionState.isGranted()); |
| 5024 | pw.println(permissionFlagsToString(", flags=", |
| 5025 | permissionState.getFlags())); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5026 | } |
| 5027 | } |
| 5028 | } |
| 5029 | |
Dianne Hackborn | cfbfafe | 2015-07-21 16:57:51 -0700 | [diff] [blame] | 5030 | private static String permissionFlagsToString(String prefix, int flags) { |
| 5031 | StringBuilder flagsString = null; |
Svet Ganov | 77ab6a8 | 2015-07-03 12:03:02 -0700 | [diff] [blame] | 5032 | while (flags != 0) { |
Dianne Hackborn | cfbfafe | 2015-07-21 16:57:51 -0700 | [diff] [blame] | 5033 | if (flagsString == null) { |
| 5034 | flagsString = new StringBuilder(); |
| 5035 | flagsString.append(prefix); |
| 5036 | flagsString.append("[ "); |
| 5037 | } |
Svet Ganov | 77ab6a8 | 2015-07-03 12:03:02 -0700 | [diff] [blame] | 5038 | final int flag = 1 << Integer.numberOfTrailingZeros(flags); |
| 5039 | flags &= ~flag; |
| 5040 | flagsString.append(PackageManager.permissionFlagToString(flag)); |
| 5041 | flagsString.append(' '); |
| 5042 | } |
Dianne Hackborn | cfbfafe | 2015-07-21 16:57:51 -0700 | [diff] [blame] | 5043 | if (flagsString != null) { |
| 5044 | flagsString.append(']'); |
| 5045 | return flagsString.toString(); |
| 5046 | } else { |
| 5047 | return ""; |
| 5048 | } |
Svet Ganov | 77ab6a8 | 2015-07-03 12:03:02 -0700 | [diff] [blame] | 5049 | } |
| 5050 | |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 5051 | void dumpInstallPermissionsLPr(PrintWriter pw, String prefix, ArraySet<String> permissionNames, |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5052 | PermissionsState permissionsState) { |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5053 | List<PermissionState> permissionStates = permissionsState.getInstallPermissionStates(); |
| 5054 | if (!permissionStates.isEmpty()) { |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5055 | pw.print(prefix); pw.println("install permissions:"); |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5056 | for (PermissionState permissionState : permissionStates) { |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 5057 | if (permissionNames != null |
| 5058 | && !permissionNames.contains(permissionState.getName())) { |
| 5059 | continue; |
| 5060 | } |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5061 | pw.print(prefix); pw.print(" "); pw.print(permissionState.getName()); |
Dianne Hackborn | cfbfafe | 2015-07-21 16:57:51 -0700 | [diff] [blame] | 5062 | pw.print(": granted="); pw.print(permissionState.isGranted()); |
| 5063 | pw.println(permissionFlagsToString(", flags=", |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5064 | permissionState.getFlags())); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5065 | } |
| 5066 | } |
| 5067 | } |
| 5068 | |
| 5069 | public void writeRuntimePermissionsForUserLPr(int userId, boolean sync) { |
| 5070 | if (sync) { |
| 5071 | mRuntimePermissionsPersistence.writePermissionsForUserSyncLPr(userId); |
| 5072 | } else { |
| 5073 | mRuntimePermissionsPersistence.writePermissionsForUserAsyncLPr(userId); |
| 5074 | } |
| 5075 | } |
| 5076 | |
| 5077 | private final class RuntimePermissionPersistence { |
| 5078 | private static final long WRITE_PERMISSIONS_DELAY_MILLIS = 200; |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5079 | private static final long MAX_WRITE_PERMISSIONS_DELAY_MILLIS = 2000; |
| 5080 | |
| 5081 | private final Handler mHandler = new MyHandler(); |
| 5082 | |
Todd Kennedy | 91a39d1 | 2017-09-27 12:37:04 -0700 | [diff] [blame] | 5083 | private final Object mPersistenceLock; |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5084 | |
| 5085 | @GuardedBy("mLock") |
Svet Ganov | ba3ba81 | 2015-06-26 10:54:06 -0700 | [diff] [blame] | 5086 | private final SparseBooleanArray mWriteScheduled = new SparseBooleanArray(); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5087 | |
| 5088 | @GuardedBy("mLock") |
Svet Ganov | ba3ba81 | 2015-06-26 10:54:06 -0700 | [diff] [blame] | 5089 | // The mapping keys are user ids. |
| 5090 | private final SparseLongArray mLastNotWrittenMutationTimesMillis = new SparseLongArray(); |
| 5091 | |
| 5092 | @GuardedBy("mLock") |
| 5093 | // The mapping keys are user ids. |
| 5094 | private final SparseArray<String> mFingerprints = new SparseArray<>(); |
| 5095 | |
| 5096 | @GuardedBy("mLock") |
| 5097 | // The mapping keys are user ids. |
| 5098 | private final SparseBooleanArray mDefaultPermissionsGranted = new SparseBooleanArray(); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5099 | |
Todd Kennedy | 91a39d1 | 2017-09-27 12:37:04 -0700 | [diff] [blame] | 5100 | public RuntimePermissionPersistence(Object persistenceLock) { |
| 5101 | mPersistenceLock = persistenceLock; |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5102 | } |
| 5103 | |
Svet Ganov | ba3ba81 | 2015-06-26 10:54:06 -0700 | [diff] [blame] | 5104 | public boolean areDefaultRuntimPermissionsGrantedLPr(int userId) { |
| 5105 | return mDefaultPermissionsGranted.get(userId); |
| 5106 | } |
| 5107 | |
| 5108 | public void onDefaultRuntimePermissionsGrantedLPr(int userId) { |
| 5109 | mFingerprints.put(userId, Build.FINGERPRINT); |
| 5110 | writePermissionsForUserAsyncLPr(userId); |
| 5111 | } |
| 5112 | |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5113 | public void writePermissionsForUserSyncLPr(int userId) { |
| 5114 | mHandler.removeMessages(userId); |
| 5115 | writePermissionsSync(userId); |
| 5116 | } |
| 5117 | |
| 5118 | public void writePermissionsForUserAsyncLPr(int userId) { |
| 5119 | final long currentTimeMillis = SystemClock.uptimeMillis(); |
| 5120 | |
| 5121 | if (mWriteScheduled.get(userId)) { |
| 5122 | mHandler.removeMessages(userId); |
| 5123 | |
| 5124 | // If enough time passed, write without holding off anymore. |
| 5125 | final long lastNotWrittenMutationTimeMillis = mLastNotWrittenMutationTimesMillis |
| 5126 | .get(userId); |
| 5127 | final long timeSinceLastNotWrittenMutationMillis = currentTimeMillis |
| 5128 | - lastNotWrittenMutationTimeMillis; |
| 5129 | if (timeSinceLastNotWrittenMutationMillis >= MAX_WRITE_PERMISSIONS_DELAY_MILLIS) { |
| 5130 | mHandler.obtainMessage(userId).sendToTarget(); |
| 5131 | return; |
| 5132 | } |
| 5133 | |
| 5134 | // Hold off a bit more as settings are frequently changing. |
| 5135 | final long maxDelayMillis = Math.max(lastNotWrittenMutationTimeMillis |
| 5136 | + MAX_WRITE_PERMISSIONS_DELAY_MILLIS - currentTimeMillis, 0); |
| 5137 | final long writeDelayMillis = Math.min(WRITE_PERMISSIONS_DELAY_MILLIS, |
| 5138 | maxDelayMillis); |
| 5139 | |
| 5140 | Message message = mHandler.obtainMessage(userId); |
| 5141 | mHandler.sendMessageDelayed(message, writeDelayMillis); |
| 5142 | } else { |
| 5143 | mLastNotWrittenMutationTimesMillis.put(userId, currentTimeMillis); |
| 5144 | Message message = mHandler.obtainMessage(userId); |
| 5145 | mHandler.sendMessageDelayed(message, WRITE_PERMISSIONS_DELAY_MILLIS); |
| 5146 | mWriteScheduled.put(userId, true); |
| 5147 | } |
| 5148 | } |
| 5149 | |
| 5150 | private void writePermissionsSync(int userId) { |
| 5151 | AtomicFile destination = new AtomicFile(getUserRuntimePermissionsFile(userId)); |
| 5152 | |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5153 | ArrayMap<String, List<PermissionState>> permissionsForPackage = new ArrayMap<>(); |
| 5154 | ArrayMap<String, List<PermissionState>> permissionsForSharedUser = new ArrayMap<>(); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5155 | |
Todd Kennedy | 91a39d1 | 2017-09-27 12:37:04 -0700 | [diff] [blame] | 5156 | synchronized (mPersistenceLock) { |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5157 | mWriteScheduled.delete(userId); |
| 5158 | |
| 5159 | final int packageCount = mPackages.size(); |
| 5160 | for (int i = 0; i < packageCount; i++) { |
| 5161 | String packageName = mPackages.keyAt(i); |
| 5162 | PackageSetting packageSetting = mPackages.valueAt(i); |
| 5163 | if (packageSetting.sharedUser == null) { |
| 5164 | PermissionsState permissionsState = packageSetting.getPermissionsState(); |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5165 | List<PermissionState> permissionsStates = permissionsState |
| 5166 | .getRuntimePermissionStates(userId); |
| 5167 | if (!permissionsStates.isEmpty()) { |
| 5168 | permissionsForPackage.put(packageName, permissionsStates); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5169 | } |
| 5170 | } |
| 5171 | } |
| 5172 | |
| 5173 | final int sharedUserCount = mSharedUsers.size(); |
| 5174 | for (int i = 0; i < sharedUserCount; i++) { |
| 5175 | String sharedUserName = mSharedUsers.keyAt(i); |
| 5176 | SharedUserSetting sharedUser = mSharedUsers.valueAt(i); |
| 5177 | PermissionsState permissionsState = sharedUser.getPermissionsState(); |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5178 | List<PermissionState> permissionsStates = permissionsState |
| 5179 | .getRuntimePermissionStates(userId); |
| 5180 | if (!permissionsStates.isEmpty()) { |
| 5181 | permissionsForSharedUser.put(sharedUserName, permissionsStates); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5182 | } |
| 5183 | } |
| 5184 | } |
| 5185 | |
| 5186 | FileOutputStream out = null; |
| 5187 | try { |
| 5188 | out = destination.startWrite(); |
| 5189 | |
| 5190 | XmlSerializer serializer = Xml.newSerializer(); |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 5191 | serializer.setOutput(out, StandardCharsets.UTF_8.name()); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5192 | serializer.setFeature( |
| 5193 | "http://xmlpull.org/v1/doc/features.html#indent-output", true); |
| 5194 | serializer.startDocument(null, true); |
Christopher Tate | e9fd1fa | 2015-09-15 16:43:07 -0700 | [diff] [blame] | 5195 | |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5196 | serializer.startTag(null, TAG_RUNTIME_PERMISSIONS); |
| 5197 | |
Svet Ganov | ba3ba81 | 2015-06-26 10:54:06 -0700 | [diff] [blame] | 5198 | String fingerprint = mFingerprints.get(userId); |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 5199 | if (fingerprint != null) { |
| 5200 | serializer.attribute(null, ATTR_FINGERPRINT, fingerprint); |
| 5201 | } |
Svet Ganov | ba3ba81 | 2015-06-26 10:54:06 -0700 | [diff] [blame] | 5202 | |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5203 | final int packageCount = permissionsForPackage.size(); |
| 5204 | for (int i = 0; i < packageCount; i++) { |
| 5205 | String packageName = permissionsForPackage.keyAt(i); |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5206 | List<PermissionState> permissionStates = permissionsForPackage.valueAt(i); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5207 | serializer.startTag(null, TAG_PACKAGE); |
| 5208 | serializer.attribute(null, ATTR_NAME, packageName); |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5209 | writePermissions(serializer, permissionStates); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5210 | serializer.endTag(null, TAG_PACKAGE); |
| 5211 | } |
| 5212 | |
| 5213 | final int sharedUserCount = permissionsForSharedUser.size(); |
| 5214 | for (int i = 0; i < sharedUserCount; i++) { |
| 5215 | String packageName = permissionsForSharedUser.keyAt(i); |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5216 | List<PermissionState> permissionStates = permissionsForSharedUser.valueAt(i); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5217 | serializer.startTag(null, TAG_SHARED_USER); |
| 5218 | serializer.attribute(null, ATTR_NAME, packageName); |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5219 | writePermissions(serializer, permissionStates); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5220 | serializer.endTag(null, TAG_SHARED_USER); |
| 5221 | } |
| 5222 | |
| 5223 | serializer.endTag(null, TAG_RUNTIME_PERMISSIONS); |
Christopher Tate | e9fd1fa | 2015-09-15 16:43:07 -0700 | [diff] [blame] | 5224 | |
| 5225 | // Now any restored permission grants that are waiting for the apps |
| 5226 | // in question to be installed. These are stored as per-package |
| 5227 | // TAG_RESTORED_RUNTIME_PERMISSIONS blocks, each containing some |
| 5228 | // number of individual permission grant entities. |
| 5229 | if (mRestoredUserGrants.get(userId) != null) { |
| 5230 | ArrayMap<String, ArraySet<RestoredPermissionGrant>> restoredGrants = |
| 5231 | mRestoredUserGrants.get(userId); |
| 5232 | if (restoredGrants != null) { |
| 5233 | final int pkgCount = restoredGrants.size(); |
| 5234 | for (int i = 0; i < pkgCount; i++) { |
| 5235 | final ArraySet<RestoredPermissionGrant> pkgGrants = |
| 5236 | restoredGrants.valueAt(i); |
| 5237 | if (pkgGrants != null && pkgGrants.size() > 0) { |
| 5238 | final String pkgName = restoredGrants.keyAt(i); |
| 5239 | serializer.startTag(null, TAG_RESTORED_RUNTIME_PERMISSIONS); |
| 5240 | serializer.attribute(null, ATTR_PACKAGE_NAME, pkgName); |
| 5241 | |
| 5242 | final int N = pkgGrants.size(); |
| 5243 | for (int z = 0; z < N; z++) { |
| 5244 | RestoredPermissionGrant g = pkgGrants.valueAt(z); |
| 5245 | serializer.startTag(null, TAG_PERMISSION_ENTRY); |
| 5246 | serializer.attribute(null, ATTR_NAME, g.permissionName); |
| 5247 | |
| 5248 | if (g.granted) { |
| 5249 | serializer.attribute(null, ATTR_GRANTED, "true"); |
| 5250 | } |
| 5251 | |
| 5252 | if ((g.grantBits&FLAG_PERMISSION_USER_SET) != 0) { |
| 5253 | serializer.attribute(null, ATTR_USER_SET, "true"); |
| 5254 | } |
| 5255 | if ((g.grantBits&FLAG_PERMISSION_USER_FIXED) != 0) { |
| 5256 | serializer.attribute(null, ATTR_USER_FIXED, "true"); |
| 5257 | } |
| 5258 | if ((g.grantBits&FLAG_PERMISSION_REVOKE_ON_UPGRADE) != 0) { |
| 5259 | serializer.attribute(null, ATTR_REVOKE_ON_UPGRADE, "true"); |
| 5260 | } |
| 5261 | serializer.endTag(null, TAG_PERMISSION_ENTRY); |
| 5262 | } |
| 5263 | serializer.endTag(null, TAG_RESTORED_RUNTIME_PERMISSIONS); |
| 5264 | } |
| 5265 | } |
| 5266 | } |
| 5267 | } |
| 5268 | |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5269 | serializer.endDocument(); |
| 5270 | destination.finishWrite(out); |
Svet Ganov | ba0821e | 2015-04-22 13:34:31 -0700 | [diff] [blame] | 5271 | |
Svet Ganov | ba3ba81 | 2015-06-26 10:54:06 -0700 | [diff] [blame] | 5272 | if (Build.FINGERPRINT.equals(fingerprint)) { |
| 5273 | mDefaultPermissionsGranted.put(userId, true); |
| 5274 | } |
| 5275 | // Any error while writing is fatal. |
Svet Ganov | ba0821e | 2015-04-22 13:34:31 -0700 | [diff] [blame] | 5276 | } catch (Throwable t) { |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5277 | Slog.wtf(PackageManagerService.TAG, |
Svet Ganov | ba0821e | 2015-04-22 13:34:31 -0700 | [diff] [blame] | 5278 | "Failed to write settings, restoring backup", t); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5279 | destination.failWrite(out); |
| 5280 | } finally { |
| 5281 | IoUtils.closeQuietly(out); |
| 5282 | } |
| 5283 | } |
| 5284 | |
Fyodor Kupolov | 6954259 | 2016-05-23 14:22:38 -0700 | [diff] [blame] | 5285 | private void onUserRemovedLPw(int userId) { |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5286 | // Make sure we do not |
| 5287 | mHandler.removeMessages(userId); |
| 5288 | |
| 5289 | for (SettingBase sb : mPackages.values()) { |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5290 | revokeRuntimePermissionsAndClearFlags(sb, userId); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5291 | } |
| 5292 | |
| 5293 | for (SettingBase sb : mSharedUsers.values()) { |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5294 | revokeRuntimePermissionsAndClearFlags(sb, userId); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5295 | } |
Fyodor Kupolov | 6954259 | 2016-05-23 14:22:38 -0700 | [diff] [blame] | 5296 | |
| 5297 | mDefaultPermissionsGranted.delete(userId); |
| 5298 | mFingerprints.remove(userId); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5299 | } |
| 5300 | |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5301 | private void revokeRuntimePermissionsAndClearFlags(SettingBase sb, int userId) { |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5302 | PermissionsState permissionsState = sb.getPermissionsState(); |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5303 | for (PermissionState permissionState |
| 5304 | : permissionsState.getRuntimePermissionStates(userId)) { |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 5305 | BasePermission bp = mPermissions.getPermission(permissionState.getName()); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5306 | if (bp != null) { |
| 5307 | permissionsState.revokeRuntimePermission(bp, userId); |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5308 | permissionsState.updatePermissionFlags(bp, userId, |
| 5309 | PackageManager.MASK_PERMISSION_FLAGS, 0); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5310 | } |
| 5311 | } |
| 5312 | } |
| 5313 | |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 5314 | public void deleteUserRuntimePermissionsFile(int userId) { |
| 5315 | getUserRuntimePermissionsFile(userId).delete(); |
| 5316 | } |
| 5317 | |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5318 | public void readStateForUserSyncLPr(int userId) { |
| 5319 | File permissionsFile = getUserRuntimePermissionsFile(userId); |
| 5320 | if (!permissionsFile.exists()) { |
| 5321 | return; |
| 5322 | } |
| 5323 | |
| 5324 | FileInputStream in; |
| 5325 | try { |
Svetoslav | 3dcdd37 | 2015-05-29 13:00:32 -0700 | [diff] [blame] | 5326 | in = new AtomicFile(permissionsFile).openRead(); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5327 | } catch (FileNotFoundException fnfe) { |
| 5328 | Slog.i(PackageManagerService.TAG, "No permissions state"); |
| 5329 | return; |
| 5330 | } |
| 5331 | |
| 5332 | try { |
| 5333 | XmlPullParser parser = Xml.newPullParser(); |
| 5334 | parser.setInput(in, null); |
| 5335 | parseRuntimePermissionsLPr(parser, userId); |
Svet Ganov | ba0821e | 2015-04-22 13:34:31 -0700 | [diff] [blame] | 5336 | |
Svet Ganov | e723e54 | 2015-04-23 11:58:26 -0700 | [diff] [blame] | 5337 | } catch (XmlPullParserException | IOException e) { |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5338 | throw new IllegalStateException("Failed parsing permissions file: " |
Svet Ganov | e723e54 | 2015-04-23 11:58:26 -0700 | [diff] [blame] | 5339 | + permissionsFile , e); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5340 | } finally { |
| 5341 | IoUtils.closeQuietly(in); |
| 5342 | } |
| 5343 | } |
| 5344 | |
Christopher Tate | e9fd1fa | 2015-09-15 16:43:07 -0700 | [diff] [blame] | 5345 | // Backup/restore support |
| 5346 | |
| 5347 | public void rememberRestoredUserGrantLPr(String pkgName, String permission, |
| 5348 | boolean isGranted, int restoredFlagSet, int userId) { |
| 5349 | // This change will be remembered at write-settings time |
| 5350 | ArrayMap<String, ArraySet<RestoredPermissionGrant>> grantsByPackage = |
| 5351 | mRestoredUserGrants.get(userId); |
| 5352 | if (grantsByPackage == null) { |
| 5353 | grantsByPackage = new ArrayMap<String, ArraySet<RestoredPermissionGrant>>(); |
| 5354 | mRestoredUserGrants.put(userId, grantsByPackage); |
| 5355 | } |
| 5356 | |
| 5357 | ArraySet<RestoredPermissionGrant> grants = grantsByPackage.get(pkgName); |
| 5358 | if (grants == null) { |
| 5359 | grants = new ArraySet<RestoredPermissionGrant>(); |
| 5360 | grantsByPackage.put(pkgName, grants); |
| 5361 | } |
| 5362 | |
| 5363 | RestoredPermissionGrant grant = new RestoredPermissionGrant(permission, |
| 5364 | isGranted, restoredFlagSet); |
| 5365 | grants.add(grant); |
| 5366 | } |
| 5367 | |
| 5368 | // Private internals |
| 5369 | |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5370 | private void parseRuntimePermissionsLPr(XmlPullParser parser, int userId) |
| 5371 | throws IOException, XmlPullParserException { |
Svet Ganov | 12a692a | 2015-03-28 19:34:15 -0700 | [diff] [blame] | 5372 | final int outerDepth = parser.getDepth(); |
| 5373 | int type; |
| 5374 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 5375 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 5376 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 5377 | continue; |
| 5378 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5379 | |
Svet Ganov | 12a692a | 2015-03-28 19:34:15 -0700 | [diff] [blame] | 5380 | switch (parser.getName()) { |
Svet Ganov | ba3ba81 | 2015-06-26 10:54:06 -0700 | [diff] [blame] | 5381 | case TAG_RUNTIME_PERMISSIONS: { |
| 5382 | String fingerprint = parser.getAttributeValue(null, ATTR_FINGERPRINT); |
| 5383 | mFingerprints.put(userId, fingerprint); |
| 5384 | final boolean defaultsGranted = Build.FINGERPRINT.equals(fingerprint); |
| 5385 | mDefaultPermissionsGranted.put(userId, defaultsGranted); |
| 5386 | } break; |
| 5387 | |
Svet Ganov | 12a692a | 2015-03-28 19:34:15 -0700 | [diff] [blame] | 5388 | case TAG_PACKAGE: { |
| 5389 | String name = parser.getAttributeValue(null, ATTR_NAME); |
| 5390 | PackageSetting ps = mPackages.get(name); |
| 5391 | if (ps == null) { |
| 5392 | Slog.w(PackageManagerService.TAG, "Unknown package:" + name); |
| 5393 | XmlUtils.skipCurrentTag(parser); |
| 5394 | continue; |
| 5395 | } |
| 5396 | parsePermissionsLPr(parser, ps.getPermissionsState(), userId); |
| 5397 | } break; |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5398 | |
Svet Ganov | 12a692a | 2015-03-28 19:34:15 -0700 | [diff] [blame] | 5399 | case TAG_SHARED_USER: { |
| 5400 | String name = parser.getAttributeValue(null, ATTR_NAME); |
| 5401 | SharedUserSetting sus = mSharedUsers.get(name); |
| 5402 | if (sus == null) { |
| 5403 | Slog.w(PackageManagerService.TAG, "Unknown shared user:" + name); |
| 5404 | XmlUtils.skipCurrentTag(parser); |
| 5405 | continue; |
| 5406 | } |
| 5407 | parsePermissionsLPr(parser, sus.getPermissionsState(), userId); |
| 5408 | } break; |
Christopher Tate | e9fd1fa | 2015-09-15 16:43:07 -0700 | [diff] [blame] | 5409 | |
| 5410 | case TAG_RESTORED_RUNTIME_PERMISSIONS: { |
| 5411 | final String pkgName = parser.getAttributeValue(null, ATTR_PACKAGE_NAME); |
| 5412 | parseRestoredRuntimePermissionsLPr(parser, pkgName, userId); |
| 5413 | } break; |
| 5414 | } |
| 5415 | } |
| 5416 | } |
| 5417 | |
| 5418 | private void parseRestoredRuntimePermissionsLPr(XmlPullParser parser, |
| 5419 | final String pkgName, final int userId) throws IOException, XmlPullParserException { |
| 5420 | final int outerDepth = parser.getDepth(); |
| 5421 | int type; |
| 5422 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 5423 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 5424 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 5425 | continue; |
| 5426 | } |
| 5427 | |
| 5428 | switch (parser.getName()) { |
| 5429 | case TAG_PERMISSION_ENTRY: { |
| 5430 | final String permName = parser.getAttributeValue(null, ATTR_NAME); |
| 5431 | final boolean isGranted = "true".equals( |
| 5432 | parser.getAttributeValue(null, ATTR_GRANTED)); |
| 5433 | |
| 5434 | int permBits = 0; |
| 5435 | if ("true".equals(parser.getAttributeValue(null, ATTR_USER_SET))) { |
| 5436 | permBits |= FLAG_PERMISSION_USER_SET; |
| 5437 | } |
| 5438 | if ("true".equals(parser.getAttributeValue(null, ATTR_USER_FIXED))) { |
| 5439 | permBits |= FLAG_PERMISSION_USER_FIXED; |
| 5440 | } |
| 5441 | if ("true".equals(parser.getAttributeValue(null, ATTR_REVOKE_ON_UPGRADE))) { |
| 5442 | permBits |= FLAG_PERMISSION_REVOKE_ON_UPGRADE; |
| 5443 | } |
| 5444 | |
| 5445 | if (isGranted || permBits != 0) { |
| 5446 | rememberRestoredUserGrantLPr(pkgName, permName, isGranted, permBits, userId); |
| 5447 | } |
| 5448 | } break; |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5449 | } |
| 5450 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5451 | } |
| 5452 | |
Svet Ganov | 12a692a | 2015-03-28 19:34:15 -0700 | [diff] [blame] | 5453 | private void parsePermissionsLPr(XmlPullParser parser, PermissionsState permissionsState, |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5454 | int userId) throws IOException, XmlPullParserException { |
Svet Ganov | 12a692a | 2015-03-28 19:34:15 -0700 | [diff] [blame] | 5455 | final int outerDepth = parser.getDepth(); |
| 5456 | int type; |
| 5457 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 5458 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 5459 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 5460 | continue; |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5461 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5462 | |
Svet Ganov | 12a692a | 2015-03-28 19:34:15 -0700 | [diff] [blame] | 5463 | switch (parser.getName()) { |
| 5464 | case TAG_ITEM: { |
| 5465 | String name = parser.getAttributeValue(null, ATTR_NAME); |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 5466 | BasePermission bp = mPermissions.getPermission(name); |
Svet Ganov | 12a692a | 2015-03-28 19:34:15 -0700 | [diff] [blame] | 5467 | if (bp == null) { |
| 5468 | Slog.w(PackageManagerService.TAG, "Unknown permission:" + name); |
| 5469 | XmlUtils.skipCurrentTag(parser); |
| 5470 | continue; |
| 5471 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5472 | |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5473 | String grantedStr = parser.getAttributeValue(null, ATTR_GRANTED); |
| 5474 | final boolean granted = grantedStr == null |
| 5475 | || Boolean.parseBoolean(grantedStr); |
| 5476 | |
| 5477 | String flagsStr = parser.getAttributeValue(null, ATTR_FLAGS); |
| 5478 | final int flags = (flagsStr != null) |
| 5479 | ? Integer.parseInt(flagsStr, 16) : 0; |
| 5480 | |
| 5481 | if (granted) { |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 5482 | permissionsState.grantRuntimePermission(bp, userId); |
| 5483 | permissionsState.updatePermissionFlags(bp, userId, |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5484 | PackageManager.MASK_PERMISSION_FLAGS, flags); |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5485 | } else { |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 5486 | permissionsState.updatePermissionFlags(bp, userId, |
| 5487 | PackageManager.MASK_PERMISSION_FLAGS, flags); |
Svet Ganov | 12a692a | 2015-03-28 19:34:15 -0700 | [diff] [blame] | 5488 | } |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5489 | |
Svet Ganov | 12a692a | 2015-03-28 19:34:15 -0700 | [diff] [blame] | 5490 | } break; |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5491 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5492 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5493 | } |
| 5494 | |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5495 | private void writePermissions(XmlSerializer serializer, |
| 5496 | List<PermissionState> permissionStates) throws IOException { |
| 5497 | for (PermissionState permissionState : permissionStates) { |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5498 | serializer.startTag(null, TAG_ITEM); |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5499 | serializer.attribute(null, ATTR_NAME,permissionState.getName()); |
| 5500 | serializer.attribute(null, ATTR_GRANTED, |
| 5501 | String.valueOf(permissionState.isGranted())); |
| 5502 | serializer.attribute(null, ATTR_FLAGS, |
| 5503 | Integer.toHexString(permissionState.getFlags())); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5504 | serializer.endTag(null, TAG_ITEM); |
| 5505 | } |
| 5506 | } |
| 5507 | |
| 5508 | private final class MyHandler extends Handler { |
| 5509 | public MyHandler() { |
| 5510 | super(BackgroundThread.getHandler().getLooper()); |
| 5511 | } |
| 5512 | |
| 5513 | @Override |
| 5514 | public void handleMessage(Message message) { |
| 5515 | final int userId = message.what; |
| 5516 | Runnable callback = (Runnable) message.obj; |
| 5517 | writePermissionsSync(userId); |
| 5518 | if (callback != null) { |
| 5519 | callback.run(); |
| 5520 | } |
| 5521 | } |
| 5522 | } |
| 5523 | } |
Andy McFadden | 2f36229 | 2012-01-20 14:43:38 -0800 | [diff] [blame] | 5524 | } |