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; |
Todd Kennedy | 13715d5 | 2016-08-01 13:38:57 -0700 | [diff] [blame] | 22 | import static android.content.pm.PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 23 | import static android.content.pm.PackageManager.INSTALL_FAILED_SHARED_USER_INCOMPATIBLE; |
Fabrice Di Meglio | 0788595 | 2015-04-06 19:41:28 -0700 | [diff] [blame] | 24 | 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] | 25 | import static android.content.pm.PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_UNDEFINED; |
Jeff Sharkey | 2a90f673 | 2016-01-06 12:26:11 -0700 | [diff] [blame] | 26 | import static android.content.pm.PackageManager.MATCH_DEFAULT_ONLY; |
Jeff Sharkey | 184a010 | 2013-07-10 16:19:52 -0700 | [diff] [blame] | 27 | import static android.os.Process.PACKAGE_INFO_GID; |
Jeff Sharkey | 2a90f673 | 2016-01-06 12:26:11 -0700 | [diff] [blame] | 28 | import static android.os.Process.SYSTEM_UID; |
Jeff Sharkey | 2271ba3 | 2016-02-01 17:57:08 -0700 | [diff] [blame] | 29 | |
Christopher Tate | 72c10a2 | 2015-06-12 18:31:24 -0700 | [diff] [blame] | 30 | import static com.android.server.pm.PackageManagerService.DEBUG_DOMAIN_VERIFICATION; |
Suprabh Shukla | 021b57a | 2018-03-08 18:21:50 -0800 | [diff] [blame] | 31 | import static com.android.server.pm.PackageManagerService.PLATFORM_PACKAGE_NAME; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 32 | |
Xiaohui Chen | 594f208 | 2015-08-18 11:04:20 -0700 | [diff] [blame] | 33 | import android.annotation.NonNull; |
Todd Kennedy | 13715d5 | 2016-08-01 13:38:57 -0700 | [diff] [blame] | 34 | import android.annotation.Nullable; |
Anton Hansson | e870d022 | 2019-03-26 14:35:58 +0000 | [diff] [blame] | 35 | import android.annotation.UserIdInt; |
Jeff Sharkey | 2a90f673 | 2016-01-06 12:26:11 -0700 | [diff] [blame] | 36 | import android.content.ComponentName; |
| 37 | import android.content.Intent; |
Dianne Hackborn | 8a2ed1d | 2013-01-29 15:18:29 -0800 | [diff] [blame] | 38 | import android.content.IntentFilter; |
| 39 | import android.content.pm.ActivityInfo; |
Jeff Sharkey | 2a90f673 | 2016-01-06 12:26:11 -0700 | [diff] [blame] | 40 | import android.content.pm.ApplicationInfo; |
| 41 | import android.content.pm.ComponentInfo; |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 42 | import android.content.pm.IntentFilterVerificationInfo; |
Jeff Sharkey | 2a90f673 | 2016-01-06 12:26:11 -0700 | [diff] [blame] | 43 | import android.content.pm.PackageManager; |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 44 | import android.content.pm.PackageManagerInternal; |
Jeff Sharkey | 2a90f673 | 2016-01-06 12:26:11 -0700 | [diff] [blame] | 45 | import android.content.pm.PackageParser; |
| 46 | import android.content.pm.PackageUserState; |
| 47 | import android.content.pm.PermissionInfo; |
Dianne Hackborn | 8a2ed1d | 2013-01-29 15:18:29 -0800 | [diff] [blame] | 48 | import android.content.pm.ResolveInfo; |
Jeff Sharkey | 2a90f673 | 2016-01-06 12:26:11 -0700 | [diff] [blame] | 49 | import android.content.pm.Signature; |
Suprabh Shukla | 389cb6f | 2018-10-01 18:20:39 -0700 | [diff] [blame] | 50 | import android.content.pm.SuspendDialogInfo; |
Jeff Sharkey | 2a90f673 | 2016-01-06 12:26:11 -0700 | [diff] [blame] | 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; |
Suprabh Shukla | 021b57a | 2018-03-08 18:21:50 -0800 | [diff] [blame] | 61 | import android.os.PersistableBundle; |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 62 | import android.os.Process; |
Florian Mayer | d4db997 | 2019-03-21 13:57:42 +0000 | [diff] [blame] | 63 | import android.os.SELinux; |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 64 | import android.os.SystemClock; |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 65 | import android.os.UserHandle; |
Amith Yamasani | 26f9ea3 | 2014-09-11 10:56:51 -0700 | [diff] [blame] | 66 | import android.os.UserManager; |
Paul Crowley | bcf48ed | 2015-04-22 13:36:59 +0100 | [diff] [blame] | 67 | import android.os.storage.StorageManager; |
Netta P | 426cbef | 2017-02-10 14:38:39 -0800 | [diff] [blame] | 68 | import android.service.pm.PackageServiceDumpProto; |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 69 | import android.text.TextUtils; |
Jeff Sharkey | 2a90f673 | 2016-01-06 12:26:11 -0700 | [diff] [blame] | 70 | import android.util.ArrayMap; |
| 71 | import android.util.ArraySet; |
| 72 | import android.util.AtomicFile; |
| 73 | import android.util.Log; |
Dianne Hackborn | 8a2ed1d | 2013-01-29 15:18:29 -0800 | [diff] [blame] | 74 | import android.util.LogPrinter; |
Jeff Sharkey | 2a90f673 | 2016-01-06 12:26:11 -0700 | [diff] [blame] | 75 | import android.util.Slog; |
| 76 | import android.util.SparseArray; |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 77 | import android.util.SparseBooleanArray; |
Jeff Sharkey | 2a90f673 | 2016-01-06 12:26:11 -0700 | [diff] [blame] | 78 | import android.util.SparseIntArray; |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 79 | import android.util.SparseLongArray; |
Jeff Sharkey | 2a90f673 | 2016-01-06 12:26:11 -0700 | [diff] [blame] | 80 | import android.util.Xml; |
Netta P | 426cbef | 2017-02-10 14:38:39 -0800 | [diff] [blame] | 81 | import android.util.proto.ProtoOutputStream; |
Christopher Tate | e012a23 | 2015-04-01 17:18:50 -0700 | [diff] [blame] | 82 | |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 83 | import com.android.internal.annotations.GuardedBy; |
| 84 | import com.android.internal.os.BackgroundThread; |
| 85 | import com.android.internal.util.ArrayUtils; |
Makoto Onuki | 0a06858 | 2018-06-13 10:57:34 -0700 | [diff] [blame] | 86 | import com.android.internal.util.CollectionUtils; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 87 | import com.android.internal.util.FastXmlSerializer; |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 88 | import com.android.internal.util.IndentingPrintWriter; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 89 | import com.android.internal.util.JournaledFile; |
| 90 | import com.android.internal.util.XmlUtils; |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 91 | import com.android.server.LocalServices; |
Jeff Sharkey | 740f523 | 2016-12-09 14:31:26 -0700 | [diff] [blame] | 92 | import com.android.server.pm.Installer.InstallerException; |
Todd Kennedy | 91a39d1 | 2017-09-27 12:37:04 -0700 | [diff] [blame] | 93 | import com.android.server.pm.permission.BasePermission; |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 94 | import com.android.server.pm.permission.PermissionSettings; |
Todd Kennedy | 82b0842 | 2017-09-28 13:32:05 -0700 | [diff] [blame] | 95 | import com.android.server.pm.permission.PermissionsState; |
| 96 | import com.android.server.pm.permission.PermissionsState.PermissionState; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 97 | |
Jeff Sharkey | 2a90f673 | 2016-01-06 12:26:11 -0700 | [diff] [blame] | 98 | import libcore.io.IoUtils; |
Alexandra Gherghina | 6e2ae25 | 2014-06-12 16:03:58 +0100 | [diff] [blame] | 99 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 100 | import org.xmlpull.v1.XmlPullParser; |
| 101 | import org.xmlpull.v1.XmlPullParserException; |
| 102 | import org.xmlpull.v1.XmlSerializer; |
| 103 | |
Jeff Sharkey | 2a90f673 | 2016-01-06 12:26:11 -0700 | [diff] [blame] | 104 | import java.io.BufferedInputStream; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 105 | import java.io.BufferedOutputStream; |
Jeff Sharkey | 2a90f673 | 2016-01-06 12:26:11 -0700 | [diff] [blame] | 106 | import java.io.BufferedWriter; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 107 | import java.io.File; |
| 108 | import java.io.FileInputStream; |
Jeff Sharkey | 2a90f673 | 2016-01-06 12:26:11 -0700 | [diff] [blame] | 109 | import java.io.FileNotFoundException; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 110 | import java.io.FileOutputStream; |
| 111 | import java.io.IOException; |
Jeff Sharkey | 2a90f673 | 2016-01-06 12:26:11 -0700 | [diff] [blame] | 112 | import java.io.InputStream; |
| 113 | import java.io.OutputStreamWriter; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 114 | import java.io.PrintWriter; |
Jeff Sharkey | 2a90f673 | 2016-01-06 12:26:11 -0700 | [diff] [blame] | 115 | import java.nio.charset.Charset; |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 116 | import java.nio.charset.StandardCharsets; |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 117 | import java.text.SimpleDateFormat; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 118 | import java.util.ArrayList; |
| 119 | import java.util.Arrays; |
Jeff Sharkey | 2a90f673 | 2016-01-06 12:26:11 -0700 | [diff] [blame] | 120 | import java.util.Collection; |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 121 | import java.util.Collections; |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 122 | import java.util.Date; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 123 | import java.util.Iterator; |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 124 | import java.util.List; |
Andy McFadden | 2f36229 | 2012-01-20 14:43:38 -0800 | [diff] [blame] | 125 | import java.util.Map; |
Jeff Sharkey | 2a90f673 | 2016-01-06 12:26:11 -0700 | [diff] [blame] | 126 | import java.util.Map.Entry; |
Jeff Sharkey | 84f1294 | 2014-07-10 17:48:11 -0700 | [diff] [blame] | 127 | import java.util.Objects; |
Dianne Hackborn | 6309271 | 2012-10-07 14:45:35 -0700 | [diff] [blame] | 128 | import java.util.Set; |
Kenny Root | 62539e9 | 2011-11-10 09:35:38 -0800 | [diff] [blame] | 129 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 130 | /** |
| 131 | * Holds information about dynamic settings. |
| 132 | */ |
Todd Kennedy | 91a39d1 | 2017-09-27 12:37:04 -0700 | [diff] [blame] | 133 | public final class Settings { |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 134 | private static final String TAG = "PackageSettings"; |
| 135 | |
Kenny Root | c1c0d3c | 2014-04-24 13:36:40 -0700 | [diff] [blame] | 136 | /** |
| 137 | * Current version of the package database. Set it to the latest version in |
| 138 | * the {@link DatabaseVersion} class below to ensure the database upgrade |
| 139 | * doesn't happen repeatedly. |
| 140 | * <p> |
| 141 | * Note that care should be taken to make sure all database upgrades are |
| 142 | * idempotent. |
| 143 | */ |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 144 | public static final int CURRENT_DATABASE_VERSION = DatabaseVersion.SIGNATURE_MALFORMED_RECOVER; |
Kenny Root | c1c0d3c | 2014-04-24 13:36:40 -0700 | [diff] [blame] | 145 | |
| 146 | /** |
| 147 | * This class contains constants that can be referred to from upgrade code. |
| 148 | * Insert constant values here that describe the upgrade reason. The version |
| 149 | * code must be monotonically increasing. |
| 150 | */ |
| 151 | public static class DatabaseVersion { |
| 152 | /** |
| 153 | * The initial version of the database. |
| 154 | */ |
| 155 | public static final int FIRST_VERSION = 1; |
Kenny Root | a8e65fd | 2014-04-24 11:44:47 -0700 | [diff] [blame] | 156 | |
| 157 | /** |
| 158 | * Migrating the Signature array from the entire certificate chain to |
| 159 | * just the signing certificate. |
| 160 | */ |
| 161 | public static final int SIGNATURE_END_ENTITY = 2; |
Jeff Sharkey | d68b87c | 2014-11-12 12:18:11 -0800 | [diff] [blame] | 162 | |
| 163 | /** |
| 164 | * There was a window of time in |
| 165 | * {@link android.os.Build.VERSION_CODES#LOLLIPOP} where we persisted |
| 166 | * certificates after potentially mutating them. To switch back to the |
| 167 | * original untouched certificates, we need to force a collection pass. |
| 168 | */ |
| 169 | public static final int SIGNATURE_MALFORMED_RECOVER = 3; |
Kenny Root | c1c0d3c | 2014-04-24 13:36:40 -0700 | [diff] [blame] | 170 | } |
| 171 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 172 | private static final boolean DEBUG_STOPPED = false; |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 173 | private static final boolean DEBUG_MU = false; |
Jeff Sharkey | 2271ba3 | 2016-02-01 17:57:08 -0700 | [diff] [blame] | 174 | private static final boolean DEBUG_KERNEL = false; |
Todd Kennedy | 788c842 | 2016-08-10 10:52:34 -0700 | [diff] [blame] | 175 | private static final boolean DEBUG_PARSER = false; |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 176 | |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 177 | private static final String RUNTIME_PERMISSIONS_FILE_NAME = "runtime-permissions.xml"; |
| 178 | |
Jeff Sharkey | edc84ee8 | 2012-03-19 16:52:26 -0700 | [diff] [blame] | 179 | private static final String TAG_READ_EXTERNAL_STORAGE = "read-external-storage"; |
| 180 | private static final String ATTR_ENFORCEMENT = "enforcement"; |
| 181 | |
Todd Kennedy | 91a39d1 | 2017-09-27 12:37:04 -0700 | [diff] [blame] | 182 | public static final String TAG_ITEM = "item"; |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 183 | private static final String TAG_DISABLED_COMPONENTS = "disabled-components"; |
| 184 | private static final String TAG_ENABLED_COMPONENTS = "enabled-components"; |
| 185 | private static final String TAG_PACKAGE_RESTRICTIONS = "package-restrictions"; |
| 186 | private static final String TAG_PACKAGE = "pkg"; |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 187 | private static final String TAG_SHARED_USER = "shared-user"; |
| 188 | private static final String TAG_RUNTIME_PERMISSIONS = "runtime-permissions"; |
| 189 | private static final String TAG_PERMISSIONS = "perms"; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 190 | private static final String TAG_CHILD_PACKAGE = "child-package"; |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 191 | private static final String TAG_USES_STATIC_LIB = "uses-static-lib"; |
Vladislav Kuzkokov | 253984e | 2016-10-24 09:27:16 +0200 | [diff] [blame] | 192 | private static final String TAG_BLOCK_UNINSTALL_PACKAGES = "block-uninstall-packages"; |
| 193 | private static final String TAG_BLOCK_UNINSTALL = "block-uninstall"; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 194 | |
Sander Alewijnse | af59762 | 2014-03-20 18:44:57 +0000 | [diff] [blame] | 195 | private static final String TAG_PERSISTENT_PREFERRED_ACTIVITIES = |
| 196 | "persistent-preferred-activities"; |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 197 | static final String TAG_CROSS_PROFILE_INTENT_FILTERS = |
| 198 | "crossProfile-intent-filters"; |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 199 | private static final String TAG_DOMAIN_VERIFICATION = "domain-verification"; |
| 200 | private static final String TAG_DEFAULT_APPS = "default-apps"; |
| 201 | private static final String TAG_ALL_INTENT_FILTER_VERIFICATION = |
Christopher Tate | 6038d15 | 2015-06-17 13:07:46 -0700 | [diff] [blame] | 202 | "all-intent-filter-verifications"; |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 203 | private static final String TAG_DEFAULT_BROWSER = "default-browser"; |
Robin Lee | 0dc591b | 2016-05-04 13:01:46 +0100 | [diff] [blame] | 204 | private static final String TAG_DEFAULT_DIALER = "default-dialer"; |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 205 | private static final String TAG_VERSION = "version"; |
Suprabh Shukla | 389cb6f | 2018-10-01 18:20:39 -0700 | [diff] [blame] | 206 | private static final String TAG_SUSPENDED_DIALOG_INFO = "suspended-dialog-info"; |
Suprabh Shukla | 021b57a | 2018-03-08 18:21:50 -0800 | [diff] [blame] | 207 | private static final String TAG_SUSPENDED_APP_EXTRAS = "suspended-app-extras"; |
| 208 | private static final String TAG_SUSPENDED_LAUNCHER_EXTRAS = "suspended-launcher-extras"; |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 209 | |
Todd Kennedy | 91a39d1 | 2017-09-27 12:37:04 -0700 | [diff] [blame] | 210 | public static final String ATTR_NAME = "name"; |
| 211 | public static final String ATTR_PACKAGE = "package"; |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 212 | private static final String ATTR_GRANTED = "granted"; |
| 213 | private static final String ATTR_FLAGS = "flags"; |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 214 | private static final String ATTR_VERSION = "version"; |
Jeff Sharkey | 4288419 | 2016-04-09 16:12:01 -0600 | [diff] [blame] | 215 | |
| 216 | private static final String ATTR_CE_DATA_INODE = "ceDataInode"; |
| 217 | private static final String ATTR_INSTALLED = "inst"; |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 218 | private static final String ATTR_STOPPED = "stopped"; |
Jeff Sharkey | 4288419 | 2016-04-09 16:12:01 -0600 | [diff] [blame] | 219 | private static final String ATTR_NOT_LAUNCHED = "nl"; |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 220 | // Legacy, here for reading older versions of the package-restrictions. |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 221 | private static final String ATTR_BLOCKED = "blocked"; |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 222 | // New name for the above attribute. |
| 223 | private static final String ATTR_HIDDEN = "hidden"; |
Suprabh Shukla | 7900049 | 2018-12-24 17:03:02 -0800 | [diff] [blame] | 224 | private static final String ATTR_DISTRACTION_FLAGS = "distraction_flags"; |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 225 | private static final String ATTR_SUSPENDED = "suspended"; |
Suprabh Shukla | 021b57a | 2018-03-08 18:21:50 -0800 | [diff] [blame] | 226 | private static final String ATTR_SUSPENDING_PACKAGE = "suspending-package"; |
Suprabh Shukla | 389cb6f | 2018-10-01 18:20:39 -0700 | [diff] [blame] | 227 | /** |
| 228 | * @deprecated Legacy attribute, kept only for upgrading from P builds. |
| 229 | */ |
| 230 | @Deprecated |
Suprabh Shukla | 3c3af14 | 2018-03-30 00:28:37 -0700 | [diff] [blame] | 231 | private static final String ATTR_SUSPEND_DIALOG_MESSAGE = "suspend_dialog_message"; |
Vladislav Kuzkokov | 253984e | 2016-10-24 09:27:16 +0200 | [diff] [blame] | 232 | // Legacy, uninstall blocks are stored separately. |
| 233 | @Deprecated |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 234 | private static final String ATTR_BLOCK_UNINSTALL = "blockUninstall"; |
Jeff Sharkey | 4288419 | 2016-04-09 16:12:01 -0600 | [diff] [blame] | 235 | private static final String ATTR_ENABLED = "enabled"; |
| 236 | private static final String ATTR_ENABLED_CALLER = "enabledCaller"; |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 237 | private static final String ATTR_DOMAIN_VERIFICATON_STATE = "domainVerificationStatus"; |
Jeff Sharkey | 4288419 | 2016-04-09 16:12:01 -0600 | [diff] [blame] | 238 | private static final String ATTR_APP_LINK_GENERATION = "app-link-generation"; |
Bartosz Fabianowski | a34f53f | 2017-01-11 18:08:47 +0100 | [diff] [blame] | 239 | private static final String ATTR_INSTALL_REASON = "install-reason"; |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 240 | private static final String ATTR_INSTANT_APP = "instant-app"; |
Todd Kennedy | 5eb5a7d | 2017-08-01 07:42:47 -0700 | [diff] [blame] | 241 | private static final String ATTR_VIRTUAL_PRELOAD = "virtual-preload"; |
Ben Gruver | 1ab3d6e | 2017-12-07 13:45:08 -0800 | [diff] [blame] | 242 | private static final String ATTR_HARMFUL_APP_WARNING = "harmful-app-warning"; |
Jeff Sharkey | 4288419 | 2016-04-09 16:12:01 -0600 | [diff] [blame] | 243 | |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 244 | private static final String ATTR_PACKAGE_NAME = "packageName"; |
Svet Ganov | ba3ba81 | 2015-06-26 10:54:06 -0700 | [diff] [blame] | 245 | private static final String ATTR_FINGERPRINT = "fingerprint"; |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 246 | private static final String ATTR_VOLUME_UUID = "volumeUuid"; |
| 247 | private static final String ATTR_SDK_VERSION = "sdkVersion"; |
| 248 | private static final String ATTR_DATABASE_VERSION = "databaseVersion"; |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 249 | |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 250 | private final Object mLock; |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 251 | |
| 252 | private final RuntimePermissionPersistence mRuntimePermissionsPersistence; |
| 253 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 254 | private final File mSettingsFilename; |
| 255 | private final File mBackupSettingsFilename; |
| 256 | private final File mPackageListFilename; |
| 257 | private final File mStoppedPackagesFilename; |
| 258 | private final File mBackupStoppedPackagesFilename; |
Amith Yamasani | 23ab7f5 | 2017-01-22 17:43:24 -0800 | [diff] [blame] | 259 | /** 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] | 260 | private final File mKernelMappingFilename; |
Jeff Sharkey | 184a010 | 2013-07-10 16:19:52 -0700 | [diff] [blame] | 261 | |
Jeff Sharkey | 2271ba3 | 2016-02-01 17:57:08 -0700 | [diff] [blame] | 262 | /** Map from package name to settings */ |
| 263 | final ArrayMap<String, PackageSetting> mPackages = new ArrayMap<>(); |
| 264 | |
Sudheer Shanka | 2928337 | 2016-04-04 20:56:27 -0700 | [diff] [blame] | 265 | /** List of packages that installed other packages */ |
| 266 | final ArraySet<String> mInstallerPackages = new ArraySet<>(); |
| 267 | |
Amith Yamasani | 23ab7f5 | 2017-01-22 17:43:24 -0800 | [diff] [blame] | 268 | /** Map from package name to appId and excluded userids */ |
| 269 | private final ArrayMap<String, KernelPackageState> mKernelMapping = new ArrayMap<>(); |
Christopher Tate | 6038d15 | 2015-06-17 13:07:46 -0700 | [diff] [blame] | 270 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 271 | // List of replaced system applications |
Jeff Sharkey | 9f837a9 | 2014-10-24 12:07:24 -0700 | [diff] [blame] | 272 | private final ArrayMap<String, PackageSetting> mDisabledSysPackages = |
| 273 | new ArrayMap<String, PackageSetting>(); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 274 | |
Vladislav Kuzkokov | 253984e | 2016-10-24 09:27:16 +0200 | [diff] [blame] | 275 | /** List of packages that are blocked for uninstall for specific users */ |
| 276 | private final SparseArray<ArraySet<String>> mBlockUninstallPackages = new SparseArray<>(); |
| 277 | |
Christopher Tate | 6038d15 | 2015-06-17 13:07:46 -0700 | [diff] [blame] | 278 | // Set of restored intent-filter verification states |
| 279 | private final ArrayMap<String, IntentFilterVerificationInfo> mRestoredIntentFilterVerifications = |
| 280 | new ArrayMap<String, IntentFilterVerificationInfo>(); |
| 281 | |
Amith Yamasani | 23ab7f5 | 2017-01-22 17:43:24 -0800 | [diff] [blame] | 282 | private static final class KernelPackageState { |
| 283 | int appId; |
| 284 | int[] excludedUserIds; |
| 285 | } |
| 286 | |
Geremy Condra | 12c1838 | 2013-03-06 16:49:06 -0800 | [diff] [blame] | 287 | private static int mFirstAvailableUid = 0; |
| 288 | |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 289 | /** Map from volume UUID to {@link VersionInfo} */ |
| 290 | private ArrayMap<String, VersionInfo> mVersion = new ArrayMap<>(); |
Kenny Root | 0aaa0d9 | 2011-09-12 16:42:55 -0700 | [diff] [blame] | 291 | |
Kenny Root | c1c0d3c | 2014-04-24 13:36:40 -0700 | [diff] [blame] | 292 | /** |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 293 | * Version details for a storage volume that may hold apps. |
Kenny Root | c1c0d3c | 2014-04-24 13:36:40 -0700 | [diff] [blame] | 294 | */ |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 295 | public static class VersionInfo { |
| 296 | /** |
| 297 | * These are the last platform API version we were using for the apps |
| 298 | * installed on internal and external storage. It is used to grant newer |
| 299 | * permissions one time during a system upgrade. |
| 300 | */ |
| 301 | int sdkVersion; |
Kenny Root | c1c0d3c | 2014-04-24 13:36:40 -0700 | [diff] [blame] | 302 | |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 303 | /** |
| 304 | * The current database version for apps on internal storage. This is |
| 305 | * used to upgrade the format of the packages.xml database not |
| 306 | * necessarily tied to an SDK version. |
| 307 | */ |
| 308 | int databaseVersion; |
| 309 | |
| 310 | /** |
| 311 | * Last known value of {@link Build#FINGERPRINT}. Used to determine when |
| 312 | * an system update has occurred, meaning we need to clear code caches. |
| 313 | */ |
| 314 | String fingerprint; |
| 315 | |
| 316 | /** |
| 317 | * Force all version information to match current system values, |
| 318 | * typically after resolving any required upgrade steps. |
| 319 | */ |
| 320 | public void forceCurrent() { |
| 321 | sdkVersion = Build.VERSION.SDK_INT; |
| 322 | databaseVersion = CURRENT_DATABASE_VERSION; |
| 323 | fingerprint = Build.FINGERPRINT; |
| 324 | } |
| 325 | } |
Jeff Sharkey | 4ed745d | 2014-07-15 20:39:15 -0700 | [diff] [blame] | 326 | |
Jeff Sharkey | f538577 | 2012-05-11 14:04:41 -0700 | [diff] [blame] | 327 | Boolean mReadExternalStorageEnforced; |
Jeff Sharkey | edc84ee8 | 2012-03-19 16:52:26 -0700 | [diff] [blame] | 328 | |
Kenny Root | 0aaa0d9 | 2011-09-12 16:42:55 -0700 | [diff] [blame] | 329 | /** Device identity for the purpose of package verification. */ |
| 330 | private VerifierDeviceIdentity mVerifierDeviceIdentity; |
| 331 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 332 | // The user's preferred activities associated with particular intent |
| 333 | // filters. |
Dianne Hackborn | 6309271 | 2012-10-07 14:45:35 -0700 | [diff] [blame] | 334 | final SparseArray<PreferredIntentResolver> mPreferredActivities = |
| 335 | new SparseArray<PreferredIntentResolver>(); |
| 336 | |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 337 | // The persistent preferred activities of the user's profile/device owner |
| 338 | // associated with particular intent filters. |
| 339 | final SparseArray<PersistentPreferredIntentResolver> mPersistentPreferredActivities = |
| 340 | new SparseArray<PersistentPreferredIntentResolver>(); |
| 341 | |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 342 | // 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] | 343 | final SparseArray<CrossProfileIntentResolver> mCrossProfileIntentResolvers = |
| 344 | new SparseArray<CrossProfileIntentResolver>(); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 345 | |
Patrick Baumann | 649a857 | 2018-11-20 11:16:58 -0800 | [diff] [blame] | 346 | final ArrayMap<String, SharedUserSetting> mSharedUsers = new ArrayMap<>(); |
| 347 | private final ArrayList<SettingBase> mAppIds = new ArrayList<>(); |
| 348 | private final SparseArray<SettingBase> mOtherAppIds = new SparseArray<>(); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 349 | |
| 350 | // For reading/writing settings file. |
| 351 | private final ArrayList<Signature> mPastSignatures = |
| 352 | new ArrayList<Signature>(); |
dcashman | 8c04fac | 2015-03-23 11:39:42 -0700 | [diff] [blame] | 353 | private final ArrayMap<Long, Integer> mKeySetRefs = |
| 354 | new ArrayMap<Long, Integer>(); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 355 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 356 | // Packages that have been renamed since they were first installed. |
| 357 | // Keys are the new names of the packages, values are the original |
Todd Kennedy | 13715d5 | 2016-08-01 13:38:57 -0700 | [diff] [blame] | 358 | // names. The packages appear everywhere else under their original |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 359 | // names. |
Todd Kennedy | 13715d5 | 2016-08-01 13:38:57 -0700 | [diff] [blame] | 360 | private final ArrayMap<String, String> mRenamedPackages = new ArrayMap<String, String>(); |
Fabrice Di Meglio | 6227172 | 2015-04-10 17:24:02 -0700 | [diff] [blame] | 361 | |
| 362 | // For every user, it is used to find the package name of the default Browser App. |
| 363 | final SparseArray<String> mDefaultBrowserApp = new SparseArray<String>(); |
| 364 | |
Christopher Tate | f0d6cb3 | 2015-07-10 17:44:53 -0700 | [diff] [blame] | 365 | // App-link priority tracking, per-user |
| 366 | final SparseIntArray mNextAppLinkGeneration = new SparseIntArray(); |
| 367 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 368 | final StringBuilder mReadMessages = new StringBuilder(); |
| 369 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 370 | /** |
| 371 | * Used to track packages that have a shared user ID that hasn't been read |
| 372 | * in yet. |
| 373 | * <p> |
| 374 | * TODO: make this just a local variable that is passed in during package |
| 375 | * scanning to make it less confusing. |
| 376 | */ |
Todd Kennedy | 788c842 | 2016-08-10 10:52:34 -0700 | [diff] [blame] | 377 | private final ArrayList<PackageSetting> mPendingPackages = new ArrayList<>(); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 378 | |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 379 | private final File mSystemDir; |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 380 | |
dcashman | 55b1078 | 2014-04-09 14:20:38 -0700 | [diff] [blame] | 381 | public final KeySetManagerService mKeySetManagerService = new KeySetManagerService(mPackages); |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 382 | /** Settings and other information about permissions */ |
Todd Kennedy | c842393 | 2017-10-05 08:58:36 -0700 | [diff] [blame] | 383 | final PermissionSettings mPermissions; |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 384 | |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 385 | Settings(File dataDir, PermissionSettings permission, |
| 386 | Object lock) { |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 387 | mLock = lock; |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 388 | mPermissions = permission; |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 389 | mRuntimePermissionsPersistence = new RuntimePermissionPersistence(mLock); |
| 390 | |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 391 | mSystemDir = new File(dataDir, "system"); |
| 392 | mSystemDir.mkdirs(); |
| 393 | FileUtils.setPermissions(mSystemDir.toString(), |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 394 | FileUtils.S_IRWXU|FileUtils.S_IRWXG |
| 395 | |FileUtils.S_IROTH|FileUtils.S_IXOTH, |
| 396 | -1, -1); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 397 | mSettingsFilename = new File(mSystemDir, "packages.xml"); |
| 398 | mBackupSettingsFilename = new File(mSystemDir, "packages-backup.xml"); |
| 399 | mPackageListFilename = new File(mSystemDir, "packages.list"); |
Jeff Sharkey | aebb65c | 2014-11-24 15:00:13 -0800 | [diff] [blame] | 400 | FileUtils.setPermissions(mPackageListFilename, 0640, SYSTEM_UID, PACKAGE_INFO_GID); |
Jeff Sharkey | 184a010 | 2013-07-10 16:19:52 -0700 | [diff] [blame] | 401 | |
Jeff Sharkey | 2271ba3 | 2016-02-01 17:57:08 -0700 | [diff] [blame] | 402 | final File kernelDir = new File("/config/sdcardfs"); |
| 403 | mKernelMappingFilename = kernelDir.exists() ? kernelDir : null; |
| 404 | |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 405 | // Deprecated: Needed for migration |
| 406 | mStoppedPackagesFilename = new File(mSystemDir, "packages-stopped.xml"); |
| 407 | mBackupStoppedPackagesFilename = new File(mSystemDir, "packages-stopped-backup.xml"); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 408 | } |
| 409 | |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 410 | PackageSetting getPackageLPr(String pkgName) { |
Todd Kennedy | 13715d5 | 2016-08-01 13:38:57 -0700 | [diff] [blame] | 411 | return mPackages.get(pkgName); |
| 412 | } |
| 413 | |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 414 | String getRenamedPackageLPr(String pkgName) { |
Todd Kennedy | 13715d5 | 2016-08-01 13:38:57 -0700 | [diff] [blame] | 415 | return mRenamedPackages.get(pkgName); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 416 | } |
| 417 | |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 418 | String addRenamedPackageLPw(String pkgName, String origPkgName) { |
| 419 | return mRenamedPackages.put(pkgName, origPkgName); |
| 420 | } |
| 421 | |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 422 | public boolean canPropagatePermissionToInstantApp(String permName) { |
| 423 | return mPermissions.canPropagatePermissionToInstantApp(permName); |
| 424 | } |
| 425 | |
Jeff Sharkey | b2b9ab8 | 2015-04-05 21:10:42 -0700 | [diff] [blame] | 426 | void setInstallerPackageName(String pkgName, String installerPkgName) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 427 | PackageSetting p = mPackages.get(pkgName); |
Jeff Sharkey | b2b9ab8 | 2015-04-05 21:10:42 -0700 | [diff] [blame] | 428 | if (p != null) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 429 | p.setInstallerPackageName(installerPkgName); |
Sudheer Shanka | 2928337 | 2016-04-04 20:56:27 -0700 | [diff] [blame] | 430 | if (installerPkgName != null) { |
| 431 | mInstallerPackages.add(installerPkgName); |
| 432 | } |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 433 | } |
| 434 | } |
| 435 | |
Todd Kennedy | 13715d5 | 2016-08-01 13:38:57 -0700 | [diff] [blame] | 436 | /** Gets and optionally creates a new shared user id. */ |
Todd Kennedy | ff35e66 | 2016-09-20 12:53:52 -0700 | [diff] [blame] | 437 | SharedUserSetting getSharedUserLPw(String name, int pkgFlags, int pkgPrivateFlags, |
| 438 | boolean create) throws PackageManagerException { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 439 | SharedUserSetting s = mSharedUsers.get(name); |
Todd Kennedy | ff35e66 | 2016-09-20 12:53:52 -0700 | [diff] [blame] | 440 | if (s == null && create) { |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 441 | s = new SharedUserSetting(name, pkgFlags, pkgPrivateFlags); |
Patrick Baumann | 649a857 | 2018-11-20 11:16:58 -0800 | [diff] [blame] | 442 | s.userId = acquireAndRegisterNewAppIdLPw(s); |
Todd Kennedy | ff35e66 | 2016-09-20 12:53:52 -0700 | [diff] [blame] | 443 | if (s.userId < 0) { |
| 444 | // < 0 means we couldn't assign a userid; throw exception |
| 445 | throw new PackageManagerException(INSTALL_FAILED_INSUFFICIENT_STORAGE, |
| 446 | "Creating shared user " + name + " failed"); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 447 | } |
Todd Kennedy | ff35e66 | 2016-09-20 12:53:52 -0700 | [diff] [blame] | 448 | Log.i(PackageManagerService.TAG, "New shared user " + name + ": id=" + s.userId); |
| 449 | mSharedUsers.put(name, s); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 450 | } |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 451 | return s; |
| 452 | } |
| 453 | |
Narayan Kamath | df6d6dc | 2014-04-28 14:18:34 +0100 | [diff] [blame] | 454 | Collection<SharedUserSetting> getAllSharedUsersLPw() { |
| 455 | return mSharedUsers.values(); |
| 456 | } |
| 457 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 458 | boolean disableSystemPackageLPw(String name, boolean replaced) { |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 459 | final PackageSetting p = mPackages.get(name); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 460 | if(p == null) { |
Jeff Sharkey | e06b4d1 | 2016-01-06 14:51:50 -0700 | [diff] [blame] | 461 | Log.w(PackageManagerService.TAG, "Package " + name + " is not an installed package"); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 462 | return false; |
| 463 | } |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 464 | final PackageSetting dp = mDisabledSysPackages.get(name); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 465 | // always make sure the system package code and resource paths dont change |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 466 | if (dp == null && p.pkg != null && p.pkg.isSystem() && !p.pkg.isUpdatedSystemApp()) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 467 | if((p.pkg != null) && (p.pkg.applicationInfo != null)) { |
| 468 | p.pkg.applicationInfo.flags |= ApplicationInfo.FLAG_UPDATED_SYSTEM_APP; |
| 469 | } |
Patrick | 4ccae94 | 2018-07-17 09:15:55 -0700 | [diff] [blame] | 470 | final PackageSetting disabled; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 471 | if (replaced) { |
| 472 | // a little trick... when we install the new package, we don't |
| 473 | // want to modify the existing PackageSetting for the built-in |
Patrick | 4ccae94 | 2018-07-17 09:15:55 -0700 | [diff] [blame] | 474 | // version. so at this point we make a copy to place into the |
| 475 | // disabled set. |
| 476 | disabled = new PackageSetting(p); |
| 477 | } else { |
| 478 | disabled = p; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 479 | } |
Patrick | 4ccae94 | 2018-07-17 09:15:55 -0700 | [diff] [blame] | 480 | mDisabledSysPackages.put(name, disabled); |
| 481 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 482 | return true; |
| 483 | } |
| 484 | return false; |
| 485 | } |
| 486 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 487 | PackageSetting enableSystemPackageLPw(String name) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 488 | PackageSetting p = mDisabledSysPackages.get(name); |
| 489 | if(p == null) { |
Jeff Sharkey | e06b4d1 | 2016-01-06 14:51:50 -0700 | [diff] [blame] | 490 | Log.w(PackageManagerService.TAG, "Package " + name + " is not disabled"); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 491 | return null; |
| 492 | } |
| 493 | // Reset flag in ApplicationInfo object |
| 494 | if((p.pkg != null) && (p.pkg.applicationInfo != null)) { |
| 495 | p.pkg.applicationInfo.flags &= ~ApplicationInfo.FLAG_UPDATED_SYSTEM_APP; |
| 496 | } |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 497 | PackageSetting ret = addPackageLPw(name, p.realName, p.codePath, p.resourcePath, |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 498 | p.legacyNativeLibraryPathString, p.primaryCpuAbiString, |
Selim Gurun | 5c8acb4 | 2016-04-07 16:34:02 -0700 | [diff] [blame] | 499 | p.secondaryCpuAbiString, p.cpuAbiOverrideString, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 500 | p.appId, p.versionCode, p.pkgFlags, p.pkgPrivateFlags, |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 501 | p.parentPackageName, p.childPackageNames, p.usesStaticLibraries, |
| 502 | p.usesStaticLibrariesVersions); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 503 | mDisabledSysPackages.remove(name); |
| 504 | return ret; |
| 505 | } |
| 506 | |
Kenny Root | c52d6fd | 2012-05-07 23:04:52 -0700 | [diff] [blame] | 507 | boolean isDisabledSystemPackageLPr(String name) { |
| 508 | return mDisabledSysPackages.containsKey(name); |
| 509 | } |
| 510 | |
| 511 | void removeDisabledSystemPackageLPw(String name) { |
| 512 | mDisabledSysPackages.remove(name); |
| 513 | } |
| 514 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 515 | PackageSetting addPackageLPw(String name, String realName, File codePath, File resourcePath, |
Svet Ganov | f4ff39c | 2016-02-04 14:27:05 -0800 | [diff] [blame] | 516 | String legacyNativeLibraryPathString, String primaryCpuAbiString, |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 517 | String secondaryCpuAbiString, String cpuAbiOverrideString, int uid, long vc, int |
Svet Ganov | f4ff39c | 2016-02-04 14:27:05 -0800 | [diff] [blame] | 518 | pkgFlags, int pkgPrivateFlags, String parentPackageName, |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 519 | List<String> childPackageNames, String[] usesStaticLibraries, |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 520 | long[] usesStaticLibraryNames) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 521 | PackageSetting p = mPackages.get(name); |
| 522 | if (p != null) { |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 523 | if (p.appId == uid) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 524 | return p; |
| 525 | } |
| 526 | PackageManagerService.reportSettingsProblem(Log.ERROR, |
| 527 | "Adding duplicate package, keeping first: " + name); |
| 528 | return null; |
| 529 | } |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 530 | p = new PackageSetting(name, realName, codePath, resourcePath, |
Narayan Kamath | 4903f64 | 2014-08-11 13:33:45 +0100 | [diff] [blame] | 531 | legacyNativeLibraryPathString, primaryCpuAbiString, secondaryCpuAbiString, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 532 | cpuAbiOverrideString, vc, pkgFlags, pkgPrivateFlags, parentPackageName, |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 533 | childPackageNames, 0 /*userId*/, usesStaticLibraries, usesStaticLibraryNames); |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 534 | p.appId = uid; |
Patrick Baumann | 649a857 | 2018-11-20 11:16:58 -0800 | [diff] [blame] | 535 | if (registerExistingAppIdLPw(uid, p, name)) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 536 | mPackages.put(name, p); |
| 537 | return p; |
| 538 | } |
| 539 | return null; |
| 540 | } |
| 541 | |
Todd Kennedy | c842393 | 2017-10-05 08:58:36 -0700 | [diff] [blame] | 542 | void addAppOpPackage(String permName, String packageName) { |
| 543 | mPermissions.addAppOpPackage(permName, packageName); |
| 544 | } |
| 545 | |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 546 | SharedUserSetting addSharedUserLPw(String name, int uid, int pkgFlags, int pkgPrivateFlags) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 547 | SharedUserSetting s = mSharedUsers.get(name); |
| 548 | if (s != null) { |
| 549 | if (s.userId == uid) { |
| 550 | return s; |
| 551 | } |
| 552 | PackageManagerService.reportSettingsProblem(Log.ERROR, |
| 553 | "Adding duplicate shared user, keeping first: " + name); |
| 554 | return null; |
| 555 | } |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 556 | s = new SharedUserSetting(name, pkgFlags, pkgPrivateFlags); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 557 | s.userId = uid; |
Patrick Baumann | 649a857 | 2018-11-20 11:16:58 -0800 | [diff] [blame] | 558 | if (registerExistingAppIdLPw(uid, s, name)) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 559 | mSharedUsers.put(name, s); |
| 560 | return s; |
| 561 | } |
| 562 | return null; |
| 563 | } |
| 564 | |
Christopher Tate | 86b391c | 2013-09-13 16:58:36 -0700 | [diff] [blame] | 565 | void pruneSharedUsersLPw() { |
| 566 | ArrayList<String> removeStage = new ArrayList<String>(); |
| 567 | for (Map.Entry<String,SharedUserSetting> entry : mSharedUsers.entrySet()) { |
| 568 | final SharedUserSetting sus = entry.getValue(); |
Todd Kennedy | 68f6715 | 2015-10-21 13:09:10 -0700 | [diff] [blame] | 569 | if (sus == null) { |
| 570 | removeStage.add(entry.getKey()); |
| 571 | continue; |
| 572 | } |
| 573 | // remove packages that are no longer installed |
| 574 | for (Iterator<PackageSetting> iter = sus.packages.iterator(); iter.hasNext();) { |
| 575 | PackageSetting ps = iter.next(); |
| 576 | if (mPackages.get(ps.name) == null) { |
| 577 | iter.remove(); |
| 578 | } |
| 579 | } |
| 580 | if (sus.packages.size() == 0) { |
Christopher Tate | 86b391c | 2013-09-13 16:58:36 -0700 | [diff] [blame] | 581 | removeStage.add(entry.getKey()); |
| 582 | } |
| 583 | } |
| 584 | for (int i = 0; i < removeStage.size(); i++) { |
| 585 | mSharedUsers.remove(removeStage.get(i)); |
| 586 | } |
| 587 | } |
| 588 | |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 589 | /** |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 590 | * Creates a new {@code PackageSetting} object. |
| 591 | * Use this method instead of the constructor to ensure a settings object is created |
| 592 | * with the correct base. |
Todd Kennedy | 13715d5 | 2016-08-01 13:38:57 -0700 | [diff] [blame] | 593 | */ |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 594 | static @NonNull PackageSetting createNewSetting(String pkgName, PackageSetting originalPkg, |
| 595 | PackageSetting disabledPkg, String realPkgName, SharedUserSetting sharedUser, |
| 596 | File codePath, File resourcePath, String legacyNativeLibraryPath, String primaryCpuAbi, |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 597 | String secondaryCpuAbi, long versionCode, int pkgFlags, int pkgPrivateFlags, |
Todd Kennedy | 5eb5a7d | 2017-08-01 07:42:47 -0700 | [diff] [blame] | 598 | UserHandle installUser, boolean allowInstall, boolean instantApp, |
| 599 | boolean virtualPreload, String parentPkgName, List<String> childPkgNames, |
| 600 | UserManagerService userManager, |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 601 | String[] usesStaticLibraries, long[] usesStaticLibrariesVersions) { |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 602 | final PackageSetting pkgSetting; |
| 603 | if (originalPkg != null) { |
| 604 | if (PackageManagerService.DEBUG_UPGRADE) Log.v(PackageManagerService.TAG, "Package " |
| 605 | + pkgName + " is adopting original package " + originalPkg.name); |
| 606 | pkgSetting = new PackageSetting(originalPkg, pkgName /*realPkgName*/); |
| 607 | pkgSetting.childPackageNames = |
| 608 | (childPkgNames != null) ? new ArrayList<>(childPkgNames) : null; |
| 609 | pkgSetting.codePath = codePath; |
| 610 | pkgSetting.legacyNativeLibraryPathString = legacyNativeLibraryPath; |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 611 | pkgSetting.parentPackageName = parentPkgName; |
| 612 | pkgSetting.pkgFlags = pkgFlags; |
| 613 | pkgSetting.pkgPrivateFlags = pkgPrivateFlags; |
Todd Kennedy | 13715d5 | 2016-08-01 13:38:57 -0700 | [diff] [blame] | 614 | pkgSetting.primaryCpuAbiString = primaryCpuAbi; |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 615 | pkgSetting.resourcePath = resourcePath; |
Todd Kennedy | 13715d5 | 2016-08-01 13:38:57 -0700 | [diff] [blame] | 616 | pkgSetting.secondaryCpuAbiString = secondaryCpuAbi; |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 617 | // NOTE: Create a deeper copy of the package signatures so we don't |
| 618 | // overwrite the signatures in the original package setting. |
| 619 | pkgSetting.signatures = new PackageSignatures(); |
| 620 | pkgSetting.versionCode = versionCode; |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 621 | pkgSetting.usesStaticLibraries = usesStaticLibraries; |
| 622 | pkgSetting.usesStaticLibrariesVersions = usesStaticLibrariesVersions; |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 623 | // Update new package state. |
| 624 | pkgSetting.setTimeStamp(codePath.lastModified()); |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 625 | } else { |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 626 | pkgSetting = new PackageSetting(pkgName, realPkgName, codePath, resourcePath, |
| 627 | legacyNativeLibraryPath, primaryCpuAbi, secondaryCpuAbi, |
| 628 | null /*cpuAbiOverrideString*/, versionCode, pkgFlags, pkgPrivateFlags, |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 629 | parentPkgName, childPkgNames, 0 /*sharedUserId*/, usesStaticLibraries, |
| 630 | usesStaticLibrariesVersions); |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 631 | pkgSetting.setTimeStamp(codePath.lastModified()); |
| 632 | pkgSetting.sharedUser = sharedUser; |
| 633 | // If this is not a system app, it starts out stopped. |
| 634 | if ((pkgFlags&ApplicationInfo.FLAG_SYSTEM) == 0) { |
| 635 | if (DEBUG_STOPPED) { |
| 636 | RuntimeException e = new RuntimeException("here"); |
| 637 | e.fillInStackTrace(); |
| 638 | Slog.i(PackageManagerService.TAG, "Stopping package " + pkgName, e); |
| 639 | } |
Todd Kennedy | 13715d5 | 2016-08-01 13:38:57 -0700 | [diff] [blame] | 640 | List<UserInfo> users = getAllUsers(userManager); |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 641 | final int installUserId = installUser != null ? installUser.getIdentifier() : 0; |
| 642 | if (users != null && allowInstall) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 643 | for (UserInfo user : users) { |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 644 | // By default we consider this app to be installed |
| 645 | // for the user if no user has been specified (which |
| 646 | // means to leave it at its original value, and the |
| 647 | // original default value is true), or we are being |
| 648 | // asked to install for all users, or this is the |
| 649 | // user we are installing for. |
| 650 | final boolean installed = installUser == null |
| 651 | || (installUserId == UserHandle.USER_ALL |
Amith Yamasani | 8cd28b5 | 2014-06-08 17:54:27 -0700 | [diff] [blame] | 652 | && !isAdbInstallDisallowed(userManager, user.id)) |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 653 | || installUserId == user.id; |
| 654 | pkgSetting.setUserState(user.id, 0, COMPONENT_ENABLED_STATE_DEFAULT, |
| 655 | installed, |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 656 | true /*stopped*/, |
| 657 | true /*notLaunched*/, |
| 658 | false /*hidden*/, |
Suprabh Shukla | 7900049 | 2018-12-24 17:03:02 -0800 | [diff] [blame] | 659 | 0 /*distractionFlags*/, |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 660 | false /*suspended*/, |
Suprabh Shukla | 151b21b | 2018-04-27 19:30:30 -0700 | [diff] [blame] | 661 | null /*suspendingPackage*/, |
Suprabh Shukla | 389cb6f | 2018-10-01 18:20:39 -0700 | [diff] [blame] | 662 | null /*dialogInfo*/, |
Suprabh Shukla | 151b21b | 2018-04-27 19:30:30 -0700 | [diff] [blame] | 663 | null /*suspendedAppExtras*/, |
| 664 | null /*suspendedLauncherExtras*/, |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 665 | instantApp, |
Todd Kennedy | 5eb5a7d | 2017-08-01 07:42:47 -0700 | [diff] [blame] | 666 | virtualPreload, |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 667 | null /*lastDisableAppCaller*/, |
| 668 | null /*enabledComponents*/, |
| 669 | null /*disabledComponents*/, |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 670 | INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_UNDEFINED, |
Ben Gruver | 1ab3d6e | 2017-12-07 13:45:08 -0800 | [diff] [blame] | 671 | 0, PackageManager.INSTALL_REASON_UNKNOWN, |
| 672 | null /*harmfulAppWarning*/); |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 673 | } |
| 674 | } |
| 675 | } |
| 676 | if (sharedUser != null) { |
| 677 | pkgSetting.appId = sharedUser.userId; |
| 678 | } else { |
| 679 | // Clone the setting here for disabled system packages |
| 680 | if (disabledPkg != null) { |
| 681 | // For disabled packages a new setting is created |
| 682 | // from the existing user id. This still has to be |
| 683 | // added to list of user id's |
| 684 | // Copy signatures from previous setting |
| 685 | pkgSetting.signatures = new PackageSignatures(disabledPkg.signatures); |
| 686 | pkgSetting.appId = disabledPkg.appId; |
| 687 | // Clone permissions |
| 688 | pkgSetting.getPermissionsState().copyFrom(disabledPkg.getPermissionsState()); |
| 689 | // Clone component info |
| 690 | List<UserInfo> users = getAllUsers(userManager); |
| 691 | if (users != null) { |
| 692 | for (UserInfo user : users) { |
| 693 | final int userId = user.id; |
| 694 | pkgSetting.setDisabledComponentsCopy( |
| 695 | disabledPkg.getDisabledComponents(userId), userId); |
| 696 | pkgSetting.setEnabledComponentsCopy( |
| 697 | disabledPkg.getEnabledComponents(userId), userId); |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 698 | } |
| 699 | } |
| 700 | } |
| 701 | } |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 702 | } |
Todd Kennedy | 13715d5 | 2016-08-01 13:38:57 -0700 | [diff] [blame] | 703 | return pkgSetting; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 704 | } |
| 705 | |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 706 | /** |
| 707 | * Updates the given package setting using the provided information. |
| 708 | * <p> |
| 709 | * WARNING: The provided PackageSetting object may be mutated. |
| 710 | */ |
| 711 | static void updatePackageSetting(@NonNull PackageSetting pkgSetting, |
| 712 | @Nullable PackageSetting disabledPkg, @Nullable SharedUserSetting sharedUser, |
Todd Kennedy | 30a23a5 | 2018-01-04 13:27:49 -0800 | [diff] [blame] | 713 | @NonNull File codePath, File resourcePath, |
| 714 | @Nullable String legacyNativeLibraryPath, @Nullable String primaryCpuAbi, |
| 715 | @Nullable String secondaryCpuAbi, int pkgFlags, int pkgPrivateFlags, |
| 716 | @Nullable List<String> childPkgNames, @NonNull UserManagerService userManager, |
| 717 | @Nullable String[] usesStaticLibraries, @Nullable long[] usesStaticLibrariesVersions) |
| 718 | throws PackageManagerException { |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 719 | final String pkgName = pkgSetting.name; |
| 720 | if (pkgSetting.sharedUser != sharedUser) { |
| 721 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 722 | "Package " + pkgName + " shared user changed from " |
| 723 | + (pkgSetting.sharedUser != null ? pkgSetting.sharedUser.name : "<nothing>") |
| 724 | + " to " + (sharedUser != null ? sharedUser.name : "<nothing>")); |
| 725 | throw new PackageManagerException(INSTALL_FAILED_SHARED_USER_INCOMPATIBLE, |
| 726 | "Updating application package " + pkgName + " failed"); |
| 727 | } |
| 728 | |
| 729 | if (!pkgSetting.codePath.equals(codePath)) { |
Todd Kennedy | 30a23a5 | 2018-01-04 13:27:49 -0800 | [diff] [blame] | 730 | final boolean isSystem = pkgSetting.isSystem(); |
| 731 | Slog.i(PackageManagerService.TAG, |
| 732 | "Update" + (isSystem ? " system" : "") |
| 733 | + " package " + pkgName |
| 734 | + " code path from " + pkgSetting.codePathString |
| 735 | + " to " + codePath.toString() |
| 736 | + "; Retain data and using new"); |
| 737 | if (!isSystem) { |
| 738 | // The package isn't considered as installed if the application was |
| 739 | // first installed by another user. Update the installed flag when the |
| 740 | // application ever becomes part of the system. |
| 741 | if ((pkgFlags & ApplicationInfo.FLAG_SYSTEM) != 0 && disabledPkg == null) { |
| 742 | final List<UserInfo> allUserInfos = getAllUsers(userManager); |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 743 | if (allUserInfos != null) { |
| 744 | for (UserInfo userInfo : allUserInfos) { |
| 745 | pkgSetting.setInstalled(true, userInfo.id); |
| 746 | } |
| 747 | } |
| 748 | } |
| 749 | |
Todd Kennedy | 30a23a5 | 2018-01-04 13:27:49 -0800 | [diff] [blame] | 750 | // Since we've changed paths, prefer the new native library path over |
| 751 | // the one stored in the package settings since we might have moved from |
| 752 | // internal to external storage or vice versa. |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 753 | pkgSetting.legacyNativeLibraryPathString = legacyNativeLibraryPath; |
| 754 | } |
Todd Kennedy | 30a23a5 | 2018-01-04 13:27:49 -0800 | [diff] [blame] | 755 | pkgSetting.codePath = codePath; |
| 756 | pkgSetting.codePathString = codePath.toString(); |
| 757 | } |
| 758 | if (!pkgSetting.resourcePath.equals(resourcePath)) { |
| 759 | final boolean isSystem = pkgSetting.isSystem(); |
| 760 | Slog.i(PackageManagerService.TAG, |
| 761 | "Update" + (isSystem ? " system" : "") |
| 762 | + " package " + pkgName |
| 763 | + " resource path from " + pkgSetting.resourcePathString |
| 764 | + " to " + resourcePath.toString() |
| 765 | + "; Retain data and using new"); |
| 766 | pkgSetting.resourcePath = resourcePath; |
| 767 | pkgSetting.resourcePathString = resourcePath.toString(); |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 768 | } |
| 769 | // If what we are scanning is a system (and possibly privileged) package, |
| 770 | // then make it so, regardless of whether it was previously installed only |
Patrick Baumann | a639d14 | 2018-05-02 15:00:59 -0700 | [diff] [blame] | 771 | // in the data partition. Reset first. |
| 772 | pkgSetting.pkgFlags &= ~ApplicationInfo.FLAG_SYSTEM; |
| 773 | pkgSetting.pkgPrivateFlags &= ~(ApplicationInfo.PRIVATE_FLAG_PRIVILEGED |
| 774 | | ApplicationInfo.PRIVATE_FLAG_OEM |
| 775 | | ApplicationInfo.PRIVATE_FLAG_VENDOR |
Dario Freni | 2bef176 | 2018-06-01 14:02:08 +0100 | [diff] [blame] | 776 | | ApplicationInfo.PRIVATE_FLAG_PRODUCT |
Jeongik Cha | f662983 | 2019-07-04 21:12:06 +0900 | [diff] [blame] | 777 | | ApplicationInfo.PRIVATE_FLAG_SYSTEM_EXT |
MÃ¥rten Kongstad | 48c24cf | 2019-02-25 10:54:09 +0100 | [diff] [blame] | 778 | | ApplicationInfo.PRIVATE_FLAG_ODM); |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 779 | pkgSetting.pkgFlags |= pkgFlags & ApplicationInfo.FLAG_SYSTEM; |
| 780 | pkgSetting.pkgPrivateFlags |= |
| 781 | pkgPrivateFlags & ApplicationInfo.PRIVATE_FLAG_PRIVILEGED; |
Svet Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 782 | pkgSetting.pkgPrivateFlags |= |
| 783 | pkgPrivateFlags & ApplicationInfo.PRIVATE_FLAG_OEM; |
Jiyong Park | 002fdbd | 2017-02-13 20:50:31 +0900 | [diff] [blame] | 784 | pkgSetting.pkgPrivateFlags |= |
| 785 | pkgPrivateFlags & ApplicationInfo.PRIVATE_FLAG_VENDOR; |
Jaekyun Seok | 1713d9e | 2018-01-12 21:47:26 +0900 | [diff] [blame] | 786 | pkgSetting.pkgPrivateFlags |= |
| 787 | pkgPrivateFlags & ApplicationInfo.PRIVATE_FLAG_PRODUCT; |
Dario Freni | 2bef176 | 2018-06-01 14:02:08 +0100 | [diff] [blame] | 788 | pkgSetting.pkgPrivateFlags |= |
Jeongik Cha | f662983 | 2019-07-04 21:12:06 +0900 | [diff] [blame] | 789 | pkgPrivateFlags & ApplicationInfo.PRIVATE_FLAG_SYSTEM_EXT; |
MÃ¥rten Kongstad | 48c24cf | 2019-02-25 10:54:09 +0100 | [diff] [blame] | 790 | pkgSetting.pkgPrivateFlags |= |
| 791 | pkgPrivateFlags & ApplicationInfo.PRIVATE_FLAG_ODM; |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 792 | pkgSetting.primaryCpuAbiString = primaryCpuAbi; |
| 793 | pkgSetting.secondaryCpuAbiString = secondaryCpuAbi; |
| 794 | if (childPkgNames != null) { |
| 795 | pkgSetting.childPackageNames = new ArrayList<>(childPkgNames); |
| 796 | } |
Todd Kennedy | 30a23a5 | 2018-01-04 13:27:49 -0800 | [diff] [blame] | 797 | // Update static shared library dependencies if needed |
| 798 | if (usesStaticLibraries != null && usesStaticLibrariesVersions != null |
| 799 | && usesStaticLibraries.length == usesStaticLibrariesVersions.length) { |
| 800 | pkgSetting.usesStaticLibraries = usesStaticLibraries; |
| 801 | pkgSetting.usesStaticLibrariesVersions = usesStaticLibrariesVersions; |
| 802 | } else { |
| 803 | pkgSetting.usesStaticLibraries = null; |
| 804 | pkgSetting.usesStaticLibrariesVersions = null; |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 805 | } |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 806 | } |
| 807 | |
| 808 | /** |
| 809 | * Registers a user ID with the system. Potentially allocates a new user ID. |
Patrick Baumann | b22e916 | 2019-04-12 10:35:29 -0700 | [diff] [blame] | 810 | * @return {@code true} if a new app ID was created in the process. {@code false} can be |
| 811 | * returned in the case that a shared user ID already exists or the explicit app ID is |
| 812 | * already registered. |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 813 | * @throws PackageManagerException If a user ID could not be allocated. |
| 814 | */ |
Patrick Baumann | b22e916 | 2019-04-12 10:35:29 -0700 | [diff] [blame] | 815 | boolean registerAppIdLPw(PackageSetting p) throws PackageManagerException { |
| 816 | final boolean createdNew; |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 817 | if (p.appId == 0) { |
| 818 | // Assign new user ID |
Patrick Baumann | 649a857 | 2018-11-20 11:16:58 -0800 | [diff] [blame] | 819 | p.appId = acquireAndRegisterNewAppIdLPw(p); |
Patrick Baumann | b22e916 | 2019-04-12 10:35:29 -0700 | [diff] [blame] | 820 | createdNew = true; |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 821 | } else { |
| 822 | // Add new setting to list of user IDs |
Patrick Baumann | b22e916 | 2019-04-12 10:35:29 -0700 | [diff] [blame] | 823 | createdNew = registerExistingAppIdLPw(p.appId, p, p.name); |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 824 | } |
| 825 | if (p.appId < 0) { |
| 826 | PackageManagerService.reportSettingsProblem(Log.WARN, |
Jeff Sharkey | f60d8ab | 2017-02-24 11:06:49 -0700 | [diff] [blame] | 827 | "Package " + p.name + " could not be assigned a valid UID"); |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 828 | throw new PackageManagerException(INSTALL_FAILED_INSUFFICIENT_STORAGE, |
Jeff Sharkey | f60d8ab | 2017-02-24 11:06:49 -0700 | [diff] [blame] | 829 | "Package " + p.name + " could not be assigned a valid UID"); |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 830 | } |
Patrick Baumann | b22e916 | 2019-04-12 10:35:29 -0700 | [diff] [blame] | 831 | return createdNew; |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 832 | } |
| 833 | |
| 834 | /** |
| 835 | * Writes per-user package restrictions if the user state has changed. If the user |
| 836 | * state has not changed, this does nothing. |
| 837 | */ |
Todd Kennedy | ff35e66 | 2016-09-20 12:53:52 -0700 | [diff] [blame] | 838 | void writeUserRestrictionsLPw(PackageSetting newPackage, PackageSetting oldPackage) { |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 839 | // package doesn't exist; do nothing |
Todd Kennedy | 8cad623 | 2016-10-06 11:27:07 -0700 | [diff] [blame] | 840 | if (getPackageLPr(newPackage.name) == null) { |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 841 | return; |
| 842 | } |
| 843 | // no users defined; do nothing |
| 844 | final List<UserInfo> allUsers = getAllUsers(UserManagerService.getInstance()); |
| 845 | if (allUsers == null) { |
| 846 | return; |
| 847 | } |
| 848 | for (UserInfo user : allUsers) { |
| 849 | final PackageUserState oldUserState = oldPackage == null |
| 850 | ? PackageSettingBase.DEFAULT_USER_STATE |
| 851 | : oldPackage.readUserState(user.id); |
| 852 | if (!oldUserState.equals(newPackage.readUserState(user.id))) { |
| 853 | writePackageRestrictionsLPr(user.id); |
| 854 | } |
| 855 | } |
| 856 | } |
| 857 | |
Todd Kennedy | 13715d5 | 2016-08-01 13:38:57 -0700 | [diff] [blame] | 858 | static boolean isAdbInstallDisallowed(UserManagerService userManager, int userId) { |
Amith Yamasani | 8cd28b5 | 2014-06-08 17:54:27 -0700 | [diff] [blame] | 859 | return userManager.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES, |
| 860 | userId); |
| 861 | } |
| 862 | |
Todd Kennedy | 30a23a5 | 2018-01-04 13:27:49 -0800 | [diff] [blame] | 863 | // TODO: Move to scanPackageOnlyLI() after verifying signatures are setup correctly |
| 864 | // by that time. |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 865 | void insertPackageSettingLPw(PackageSetting p, PackageParser.Package pkg) { |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 866 | // Update signatures if needed. |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 867 | if (p.signatures.mSigningDetails.signatures == null) { |
| 868 | p.signatures.mSigningDetails = pkg.mSigningDetails; |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 869 | } |
| 870 | // If this app defines a shared user id initialize |
| 871 | // the shared user signatures as well. |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 872 | if (p.sharedUser != null && p.sharedUser.signatures.mSigningDetails.signatures == null) { |
| 873 | p.sharedUser.signatures.mSigningDetails = pkg.mSigningDetails; |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 874 | } |
Todd Kennedy | 788c842 | 2016-08-10 10:52:34 -0700 | [diff] [blame] | 875 | addPackageSettingLPw(p, p.sharedUser); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 876 | } |
| 877 | |
| 878 | // Utility method that adds a PackageSetting to mPackages and |
Christopher Tate | 6038d15 | 2015-06-17 13:07:46 -0700 | [diff] [blame] | 879 | // completes updating the shared user attributes and any restored |
| 880 | // app link verification state |
Todd Kennedy | 788c842 | 2016-08-10 10:52:34 -0700 | [diff] [blame] | 881 | private void addPackageSettingLPw(PackageSetting p, SharedUserSetting sharedUser) { |
| 882 | mPackages.put(p.name, p); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 883 | if (sharedUser != null) { |
| 884 | if (p.sharedUser != null && p.sharedUser != sharedUser) { |
| 885 | PackageManagerService.reportSettingsProblem(Log.ERROR, |
| 886 | "Package " + p.name + " was user " |
| 887 | + p.sharedUser + " but is now " + sharedUser |
| 888 | + "; I am not changing its files so it will probably fail!"); |
Ben Gruver | dd72c9e | 2013-08-06 12:34:17 -0700 | [diff] [blame] | 889 | p.sharedUser.removePackage(p); |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 890 | } else if (p.appId != sharedUser.userId) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 891 | PackageManagerService.reportSettingsProblem(Log.ERROR, |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 892 | "Package " + p.name + " was user id " + p.appId |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 893 | + " but is now user " + sharedUser |
| 894 | + " with id " + sharedUser.userId |
| 895 | + "; I am not changing its files so it will probably fail!"); |
| 896 | } |
| 897 | |
Ben Gruver | dd72c9e | 2013-08-06 12:34:17 -0700 | [diff] [blame] | 898 | sharedUser.addPackage(p); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 899 | p.sharedUser = sharedUser; |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 900 | p.appId = sharedUser.userId; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 901 | } |
Svet Ganov | e7af194 | 2015-08-04 11:13:44 -0700 | [diff] [blame] | 902 | |
| 903 | // If the we know about this user id, we have to update it as it |
| 904 | // has to point to the same PackageSetting instance as the package. |
Patrick Baumann | 649a857 | 2018-11-20 11:16:58 -0800 | [diff] [blame] | 905 | Object userIdPs = getSettingLPr(p.appId); |
Svet Ganov | e7af194 | 2015-08-04 11:13:44 -0700 | [diff] [blame] | 906 | if (sharedUser == null) { |
| 907 | if (userIdPs != null && userIdPs != p) { |
Patrick Baumann | 649a857 | 2018-11-20 11:16:58 -0800 | [diff] [blame] | 908 | replaceAppIdLPw(p.appId, p); |
Svet Ganov | e7af194 | 2015-08-04 11:13:44 -0700 | [diff] [blame] | 909 | } |
| 910 | } else { |
| 911 | if (userIdPs != null && userIdPs != sharedUser) { |
Patrick Baumann | 649a857 | 2018-11-20 11:16:58 -0800 | [diff] [blame] | 912 | replaceAppIdLPw(p.appId, sharedUser); |
Svet Ganov | e7af194 | 2015-08-04 11:13:44 -0700 | [diff] [blame] | 913 | } |
| 914 | } |
| 915 | |
Todd Kennedy | 788c842 | 2016-08-10 10:52:34 -0700 | [diff] [blame] | 916 | IntentFilterVerificationInfo ivi = mRestoredIntentFilterVerifications.get(p.name); |
Christopher Tate | 6038d15 | 2015-06-17 13:07:46 -0700 | [diff] [blame] | 917 | if (ivi != null) { |
| 918 | if (DEBUG_DOMAIN_VERIFICATION) { |
Todd Kennedy | 788c842 | 2016-08-10 10:52:34 -0700 | [diff] [blame] | 919 | Slog.i(TAG, "Applying restored IVI for " + p.name + " : " + ivi.getStatusString()); |
Christopher Tate | 6038d15 | 2015-06-17 13:07:46 -0700 | [diff] [blame] | 920 | } |
Todd Kennedy | 788c842 | 2016-08-10 10:52:34 -0700 | [diff] [blame] | 921 | mRestoredIntentFilterVerifications.remove(p.name); |
Christopher Tate | 6038d15 | 2015-06-17 13:07:46 -0700 | [diff] [blame] | 922 | p.setIntentFilterVerificationInfo(ivi); |
| 923 | } |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 924 | } |
| 925 | |
| 926 | /* |
Anton Hansson | e870d022 | 2019-03-26 14:35:58 +0000 | [diff] [blame] | 927 | * Update the shared user setting when a package with a shared user id is removed. The gids |
| 928 | * associated with each permission of the deleted package are removed from the shared user' |
| 929 | * gid list only if its not in use by other permissions of packages in the shared user setting. |
| 930 | * |
| 931 | * @return the affected user id |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 932 | */ |
Anton Hansson | e870d022 | 2019-03-26 14:35:58 +0000 | [diff] [blame] | 933 | @UserIdInt |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 934 | int updateSharedUserPermsLPw(PackageSetting deletedPs, int userId) { |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 935 | if ((deletedPs == null) || (deletedPs.pkg == null)) { |
| 936 | Slog.i(PackageManagerService.TAG, |
| 937 | "Trying to update info for null package. Just ignoring"); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 938 | return UserHandle.USER_NULL; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 939 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 940 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 941 | // No sharedUserId |
| 942 | if (deletedPs.sharedUser == null) { |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 943 | return UserHandle.USER_NULL; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 944 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 945 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 946 | SharedUserSetting sus = deletedPs.sharedUser; |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 947 | |
Anton Hansson | e870d022 | 2019-03-26 14:35:58 +0000 | [diff] [blame] | 948 | int affectedUserId = UserHandle.USER_NULL; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 949 | // Update permissions |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 950 | for (String eachPerm : deletedPs.pkg.requestedPermissions) { |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 951 | BasePermission bp = mPermissions.getPermission(eachPerm); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 952 | if (bp == null) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 953 | continue; |
| 954 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 955 | |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 956 | // Check if another package in the shared user needs the permission. |
Svetoslav | 4a5f4a2 | 2015-07-07 18:18:15 -0700 | [diff] [blame] | 957 | boolean used = false; |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 958 | for (PackageSetting pkg : sus.packages) { |
| 959 | if (pkg.pkg != null |
| 960 | && !pkg.pkg.packageName.equals(deletedPs.pkg.packageName) |
| 961 | && pkg.pkg.requestedPermissions.contains(eachPerm)) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 962 | used = true; |
| 963 | break; |
| 964 | } |
| 965 | } |
Svetoslav | 4a5f4a2 | 2015-07-07 18:18:15 -0700 | [diff] [blame] | 966 | if (used) { |
| 967 | continue; |
| 968 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 969 | |
Svetoslav | 4a5f4a2 | 2015-07-07 18:18:15 -0700 | [diff] [blame] | 970 | PermissionsState permissionsState = sus.getPermissionsState(); |
| 971 | PackageSetting disabledPs = getDisabledSystemPkgLPr(deletedPs.pkg.packageName); |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 972 | |
Svetoslav | 4a5f4a2 | 2015-07-07 18:18:15 -0700 | [diff] [blame] | 973 | // If the package is shadowing is a disabled system package, |
| 974 | // do not drop permissions that the shadowed package requests. |
| 975 | if (disabledPs != null) { |
| 976 | boolean reqByDisabledSysPkg = false; |
| 977 | for (String permission : disabledPs.pkg.requestedPermissions) { |
| 978 | if (permission.equals(eachPerm)) { |
| 979 | reqByDisabledSysPkg = true; |
| 980 | break; |
| 981 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 982 | } |
Svetoslav | 4a5f4a2 | 2015-07-07 18:18:15 -0700 | [diff] [blame] | 983 | if (reqByDisabledSysPkg) { |
| 984 | continue; |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 985 | } |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 986 | } |
Svetoslav | 4a5f4a2 | 2015-07-07 18:18:15 -0700 | [diff] [blame] | 987 | |
| 988 | // Try to revoke as an install permission which is for all users. |
| 989 | // The package is gone - no need to keep flags for applying policy. |
| 990 | permissionsState.updatePermissionFlags(bp, userId, |
Philip P. Moltmann | 7659769 | 2019-03-02 13:18:41 -0800 | [diff] [blame] | 991 | PackageManager.MASK_PERMISSION_FLAGS_ALL, 0); |
Svetoslav | 4a5f4a2 | 2015-07-07 18:18:15 -0700 | [diff] [blame] | 992 | |
| 993 | if (permissionsState.revokeInstallPermission(bp) == |
| 994 | PermissionsState.PERMISSION_OPERATION_SUCCESS_GIDS_CHANGED) { |
Anton Hansson | e870d022 | 2019-03-26 14:35:58 +0000 | [diff] [blame] | 995 | affectedUserId = UserHandle.USER_ALL; |
Svetoslav | 4a5f4a2 | 2015-07-07 18:18:15 -0700 | [diff] [blame] | 996 | } |
| 997 | |
| 998 | // Try to revoke as an install permission which is per user. |
| 999 | if (permissionsState.revokeRuntimePermission(bp, userId) == |
| 1000 | PermissionsState.PERMISSION_OPERATION_SUCCESS_GIDS_CHANGED) { |
Anton Hansson | e870d022 | 2019-03-26 14:35:58 +0000 | [diff] [blame] | 1001 | if (affectedUserId == UserHandle.USER_NULL) { |
| 1002 | affectedUserId = userId; |
| 1003 | } else if (affectedUserId != userId) { |
| 1004 | // Multiple users affected. |
| 1005 | affectedUserId = UserHandle.USER_ALL; |
| 1006 | } |
Svetoslav | 4a5f4a2 | 2015-07-07 18:18:15 -0700 | [diff] [blame] | 1007 | } |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1008 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 1009 | |
Anton Hansson | e870d022 | 2019-03-26 14:35:58 +0000 | [diff] [blame] | 1010 | return affectedUserId; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1011 | } |
| 1012 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 1013 | int removePackageLPw(String name) { |
| 1014 | final PackageSetting p = mPackages.get(name); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1015 | if (p != null) { |
| 1016 | mPackages.remove(name); |
Sudheer Shanka | 2928337 | 2016-04-04 20:56:27 -0700 | [diff] [blame] | 1017 | removeInstallerPackageStatus(name); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1018 | if (p.sharedUser != null) { |
Ben Gruver | dd72c9e | 2013-08-06 12:34:17 -0700 | [diff] [blame] | 1019 | p.sharedUser.removePackage(p); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1020 | if (p.sharedUser.packages.size() == 0) { |
| 1021 | mSharedUsers.remove(p.sharedUser.name); |
Patrick Baumann | 649a857 | 2018-11-20 11:16:58 -0800 | [diff] [blame] | 1022 | removeAppIdLPw(p.sharedUser.userId); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1023 | return p.sharedUser.userId; |
| 1024 | } |
| 1025 | } else { |
Patrick Baumann | 649a857 | 2018-11-20 11:16:58 -0800 | [diff] [blame] | 1026 | removeAppIdLPw(p.appId); |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 1027 | return p.appId; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1028 | } |
| 1029 | } |
| 1030 | return -1; |
| 1031 | } |
| 1032 | |
Sudheer Shanka | 2928337 | 2016-04-04 20:56:27 -0700 | [diff] [blame] | 1033 | /** |
| 1034 | * Checks if {@param packageName} is an installer package and if so, clear the installer |
| 1035 | * package name of the packages that are installed by this. |
| 1036 | */ |
| 1037 | private void removeInstallerPackageStatus(String packageName) { |
| 1038 | // Check if the package to be removed is an installer package. |
| 1039 | if (!mInstallerPackages.contains(packageName)) { |
| 1040 | return; |
| 1041 | } |
| 1042 | for (int i = 0; i < mPackages.size(); i++) { |
| 1043 | final PackageSetting ps = mPackages.valueAt(i); |
| 1044 | final String installerPackageName = ps.getInstallerPackageName(); |
| 1045 | if (installerPackageName != null |
| 1046 | && installerPackageName.equals(packageName)) { |
| 1047 | ps.setInstallerPackageName(null); |
Sudheer Shanka | 8c57aea | 2016-04-20 16:47:50 -0700 | [diff] [blame] | 1048 | ps.isOrphaned = true; |
Sudheer Shanka | 2928337 | 2016-04-04 20:56:27 -0700 | [diff] [blame] | 1049 | } |
| 1050 | } |
| 1051 | mInstallerPackages.remove(packageName); |
| 1052 | } |
| 1053 | |
Patrick Baumann | 649a857 | 2018-11-20 11:16:58 -0800 | [diff] [blame] | 1054 | /** Returns true if the requested AppID was valid and not already registered. */ |
| 1055 | private boolean registerExistingAppIdLPw(int appId, SettingBase obj, Object name) { |
| 1056 | if (appId > Process.LAST_APPLICATION_UID) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1057 | return false; |
| 1058 | } |
| 1059 | |
Patrick Baumann | 649a857 | 2018-11-20 11:16:58 -0800 | [diff] [blame] | 1060 | if (appId >= Process.FIRST_APPLICATION_UID) { |
| 1061 | int size = mAppIds.size(); |
| 1062 | final int index = appId - Process.FIRST_APPLICATION_UID; |
| 1063 | // fill the array until our index becomes valid |
| 1064 | while (index >= size) { |
| 1065 | mAppIds.add(null); |
| 1066 | size++; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1067 | } |
Patrick Baumann | 649a857 | 2018-11-20 11:16:58 -0800 | [diff] [blame] | 1068 | if (mAppIds.get(index) != null) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1069 | PackageManagerService.reportSettingsProblem(Log.ERROR, |
Patrick Baumann | 649a857 | 2018-11-20 11:16:58 -0800 | [diff] [blame] | 1070 | "Adding duplicate app id: " + appId |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1071 | + " name=" + name); |
| 1072 | return false; |
| 1073 | } |
Patrick Baumann | 649a857 | 2018-11-20 11:16:58 -0800 | [diff] [blame] | 1074 | mAppIds.set(index, obj); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1075 | } else { |
Patrick Baumann | 649a857 | 2018-11-20 11:16:58 -0800 | [diff] [blame] | 1076 | if (mOtherAppIds.get(appId) != null) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1077 | PackageManagerService.reportSettingsProblem(Log.ERROR, |
Patrick Baumann | 649a857 | 2018-11-20 11:16:58 -0800 | [diff] [blame] | 1078 | "Adding duplicate shared id: " + appId |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1079 | + " name=" + name); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1080 | return false; |
| 1081 | } |
Patrick Baumann | 649a857 | 2018-11-20 11:16:58 -0800 | [diff] [blame] | 1082 | mOtherAppIds.put(appId, obj); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1083 | } |
| 1084 | return true; |
| 1085 | } |
| 1086 | |
Patrick Baumann | 649a857 | 2018-11-20 11:16:58 -0800 | [diff] [blame] | 1087 | /** Gets the setting associated with the provided App ID */ |
| 1088 | public SettingBase getSettingLPr(int appId) { |
| 1089 | if (appId >= Process.FIRST_APPLICATION_UID) { |
| 1090 | final int size = mAppIds.size(); |
| 1091 | final int index = appId - Process.FIRST_APPLICATION_UID; |
| 1092 | return index < size ? mAppIds.get(index) : null; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1093 | } else { |
Patrick Baumann | 649a857 | 2018-11-20 11:16:58 -0800 | [diff] [blame] | 1094 | return mOtherAppIds.get(appId); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1095 | } |
| 1096 | } |
| 1097 | |
Patrick Baumann | 649a857 | 2018-11-20 11:16:58 -0800 | [diff] [blame] | 1098 | /** Unregisters the provided app ID. */ |
| 1099 | void removeAppIdLPw(int appId) { |
| 1100 | if (appId >= Process.FIRST_APPLICATION_UID) { |
| 1101 | final int size = mAppIds.size(); |
| 1102 | final int index = appId - Process.FIRST_APPLICATION_UID; |
| 1103 | if (index < size) mAppIds.set(index, null); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1104 | } else { |
Patrick Baumann | 649a857 | 2018-11-20 11:16:58 -0800 | [diff] [blame] | 1105 | mOtherAppIds.remove(appId); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1106 | } |
Patrick Baumann | 649a857 | 2018-11-20 11:16:58 -0800 | [diff] [blame] | 1107 | setFirstAvailableUid(appId + 1); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1108 | } |
| 1109 | |
Patrick Baumann | 649a857 | 2018-11-20 11:16:58 -0800 | [diff] [blame] | 1110 | private void replaceAppIdLPw(int appId, SettingBase obj) { |
| 1111 | if (appId >= Process.FIRST_APPLICATION_UID) { |
| 1112 | final int size = mAppIds.size(); |
| 1113 | final int index = appId - Process.FIRST_APPLICATION_UID; |
| 1114 | if (index < size) mAppIds.set(index, obj); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1115 | } else { |
Patrick Baumann | 649a857 | 2018-11-20 11:16:58 -0800 | [diff] [blame] | 1116 | mOtherAppIds.put(appId, obj); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1117 | } |
| 1118 | } |
| 1119 | |
Dianne Hackborn | 6309271 | 2012-10-07 14:45:35 -0700 | [diff] [blame] | 1120 | PreferredIntentResolver editPreferredActivitiesLPw(int userId) { |
| 1121 | PreferredIntentResolver pir = mPreferredActivities.get(userId); |
| 1122 | if (pir == null) { |
| 1123 | pir = new PreferredIntentResolver(); |
| 1124 | mPreferredActivities.put(userId, pir); |
| 1125 | } |
| 1126 | return pir; |
| 1127 | } |
| 1128 | |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 1129 | PersistentPreferredIntentResolver editPersistentPreferredActivitiesLPw(int userId) { |
| 1130 | PersistentPreferredIntentResolver ppir = mPersistentPreferredActivities.get(userId); |
| 1131 | if (ppir == null) { |
| 1132 | ppir = new PersistentPreferredIntentResolver(); |
| 1133 | mPersistentPreferredActivities.put(userId, ppir); |
| 1134 | } |
| 1135 | return ppir; |
| 1136 | } |
| 1137 | |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 1138 | CrossProfileIntentResolver editCrossProfileIntentResolverLPw(int userId) { |
| 1139 | CrossProfileIntentResolver cpir = mCrossProfileIntentResolvers.get(userId); |
| 1140 | if (cpir == null) { |
| 1141 | cpir = new CrossProfileIntentResolver(); |
| 1142 | mCrossProfileIntentResolvers.put(userId, cpir); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1143 | } |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 1144 | return cpir; |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1145 | } |
| 1146 | |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1147 | /** |
| 1148 | * The following functions suppose that you have a lock for managing access to the |
| 1149 | * mIntentFiltersVerifications map. |
| 1150 | */ |
| 1151 | |
| 1152 | /* package protected */ |
| 1153 | IntentFilterVerificationInfo getIntentFilterVerificationLPr(String packageName) { |
| 1154 | PackageSetting ps = mPackages.get(packageName); |
| 1155 | if (ps == null) { |
Christopher Tate | 72c10a2 | 2015-06-12 18:31:24 -0700 | [diff] [blame] | 1156 | if (DEBUG_DOMAIN_VERIFICATION) { |
| 1157 | Slog.w(PackageManagerService.TAG, "No package known: " + packageName); |
| 1158 | } |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1159 | return null; |
| 1160 | } |
| 1161 | return ps.getIntentFilterVerificationInfo(); |
| 1162 | } |
| 1163 | |
| 1164 | /* package protected */ |
Fabrice Di Meglio | 7d014ce | 2015-04-08 16:17:46 -0700 | [diff] [blame] | 1165 | IntentFilterVerificationInfo createIntentFilterVerificationIfNeededLPw(String packageName, |
Todd Kennedy | 788c842 | 2016-08-10 10:52:34 -0700 | [diff] [blame] | 1166 | ArraySet<String> domains) { |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1167 | PackageSetting ps = mPackages.get(packageName); |
| 1168 | if (ps == null) { |
Christopher Tate | 72c10a2 | 2015-06-12 18:31:24 -0700 | [diff] [blame] | 1169 | if (DEBUG_DOMAIN_VERIFICATION) { |
| 1170 | Slog.w(PackageManagerService.TAG, "No package known: " + packageName); |
| 1171 | } |
Fabrice Di Meglio | 7d014ce | 2015-04-08 16:17:46 -0700 | [diff] [blame] | 1172 | return null; |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1173 | } |
Fabrice Di Meglio | 7d014ce | 2015-04-08 16:17:46 -0700 | [diff] [blame] | 1174 | IntentFilterVerificationInfo ivi = ps.getIntentFilterVerificationInfo(); |
| 1175 | if (ivi == null) { |
| 1176 | ivi = new IntentFilterVerificationInfo(packageName, domains); |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1177 | ps.setIntentFilterVerificationInfo(ivi); |
Christopher Tate | 72c10a2 | 2015-06-12 18:31:24 -0700 | [diff] [blame] | 1178 | if (DEBUG_DOMAIN_VERIFICATION) { |
| 1179 | Slog.d(PackageManagerService.TAG, |
| 1180 | "Creating new IntentFilterVerificationInfo for pkg: " + packageName); |
| 1181 | } |
Fabrice Di Meglio | 1de3f0d | 2015-04-29 19:42:41 -0700 | [diff] [blame] | 1182 | } else { |
| 1183 | ivi.setDomains(domains); |
Christopher Tate | 72c10a2 | 2015-06-12 18:31:24 -0700 | [diff] [blame] | 1184 | if (DEBUG_DOMAIN_VERIFICATION) { |
| 1185 | Slog.d(PackageManagerService.TAG, |
| 1186 | "Setting domains to existing IntentFilterVerificationInfo for pkg: " + |
| 1187 | packageName + " and with domains: " + ivi.getDomainsString()); |
| 1188 | } |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1189 | } |
Fabrice Di Meglio | 7d014ce | 2015-04-08 16:17:46 -0700 | [diff] [blame] | 1190 | return ivi; |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1191 | } |
| 1192 | |
| 1193 | int getIntentFilterVerificationStatusLPr(String packageName, int userId) { |
| 1194 | PackageSetting ps = mPackages.get(packageName); |
| 1195 | if (ps == null) { |
Christopher Tate | 72c10a2 | 2015-06-12 18:31:24 -0700 | [diff] [blame] | 1196 | if (DEBUG_DOMAIN_VERIFICATION) { |
| 1197 | Slog.w(PackageManagerService.TAG, "No package known: " + packageName); |
| 1198 | } |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1199 | return INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_UNDEFINED; |
| 1200 | } |
Christopher Tate | d85a664 | 2015-07-17 15:39:08 -0700 | [diff] [blame] | 1201 | return (int)(ps.getDomainVerificationStatusForUser(userId) >> 32); |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1202 | } |
| 1203 | |
Christopher Tate | f0d6cb3 | 2015-07-10 17:44:53 -0700 | [diff] [blame] | 1204 | boolean updateIntentFilterVerificationStatusLPw(String packageName, final int status, int userId) { |
Fabrice Di Meglio | 0788595 | 2015-04-06 19:41:28 -0700 | [diff] [blame] | 1205 | // Update the status for the current package |
| 1206 | PackageSetting current = mPackages.get(packageName); |
| 1207 | if (current == null) { |
Christopher Tate | 72c10a2 | 2015-06-12 18:31:24 -0700 | [diff] [blame] | 1208 | if (DEBUG_DOMAIN_VERIFICATION) { |
| 1209 | Slog.w(PackageManagerService.TAG, "No package known: " + packageName); |
| 1210 | } |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1211 | return false; |
| 1212 | } |
Christopher Tate | 050aee2 | 2015-07-01 16:50:43 -0700 | [diff] [blame] | 1213 | |
Christopher Tate | f0d6cb3 | 2015-07-10 17:44:53 -0700 | [diff] [blame] | 1214 | final int alwaysGeneration; |
| 1215 | if (status == INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ALWAYS) { |
| 1216 | alwaysGeneration = mNextAppLinkGeneration.get(userId) + 1; |
| 1217 | mNextAppLinkGeneration.put(userId, alwaysGeneration); |
| 1218 | } else { |
| 1219 | alwaysGeneration = 0; |
| 1220 | } |
| 1221 | |
| 1222 | current.setDomainVerificationStatusForUser(status, alwaysGeneration, userId); |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1223 | return true; |
| 1224 | } |
| 1225 | |
| 1226 | /** |
Fabrice Di Meglio | 0788595 | 2015-04-06 19:41:28 -0700 | [diff] [blame] | 1227 | * Used for Settings App and PackageManagerService dump. Should be read only. |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1228 | */ |
| 1229 | List<IntentFilterVerificationInfo> getIntentFilterVerificationsLPr( |
| 1230 | String packageName) { |
| 1231 | if (packageName == null) { |
| 1232 | return Collections.<IntentFilterVerificationInfo>emptyList(); |
| 1233 | } |
| 1234 | ArrayList<IntentFilterVerificationInfo> result = new ArrayList<>(); |
| 1235 | for (PackageSetting ps : mPackages.values()) { |
| 1236 | IntentFilterVerificationInfo ivi = ps.getIntentFilterVerificationInfo(); |
| 1237 | if (ivi == null || TextUtils.isEmpty(ivi.getPackageName()) || |
| 1238 | !ivi.getPackageName().equalsIgnoreCase(packageName)) { |
| 1239 | continue; |
| 1240 | } |
| 1241 | result.add(ivi); |
| 1242 | } |
| 1243 | return result; |
| 1244 | } |
| 1245 | |
Fabrice Di Meglio | 1f09b8c | 2015-05-06 18:51:21 -0700 | [diff] [blame] | 1246 | boolean removeIntentFilterVerificationLPw(String packageName, int userId) { |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1247 | PackageSetting ps = mPackages.get(packageName); |
| 1248 | if (ps == null) { |
Christopher Tate | 72c10a2 | 2015-06-12 18:31:24 -0700 | [diff] [blame] | 1249 | if (DEBUG_DOMAIN_VERIFICATION) { |
| 1250 | Slog.w(PackageManagerService.TAG, "No package known: " + packageName); |
| 1251 | } |
Fabrice Di Meglio | 1f09b8c | 2015-05-06 18:51:21 -0700 | [diff] [blame] | 1252 | return false; |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1253 | } |
| 1254 | ps.clearDomainVerificationStatusForUser(userId); |
Fabrice Di Meglio | 1f09b8c | 2015-05-06 18:51:21 -0700 | [diff] [blame] | 1255 | return true; |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1256 | } |
| 1257 | |
Fabrice Di Meglio | 1f09b8c | 2015-05-06 18:51:21 -0700 | [diff] [blame] | 1258 | boolean removeIntentFilterVerificationLPw(String packageName, int[] userIds) { |
| 1259 | boolean result = false; |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1260 | for (int userId : userIds) { |
Fabrice Di Meglio | 1f09b8c | 2015-05-06 18:51:21 -0700 | [diff] [blame] | 1261 | result |= removeIntentFilterVerificationLPw(packageName, userId); |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1262 | } |
Fabrice Di Meglio | 1f09b8c | 2015-05-06 18:51:21 -0700 | [diff] [blame] | 1263 | return result; |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1264 | } |
| 1265 | |
Hai Zhang | a22cd83 | 2019-01-30 13:38:43 -0800 | [diff] [blame] | 1266 | String removeDefaultBrowserPackageNameLPw(int userId) { |
| 1267 | return (userId == UserHandle.USER_ALL) ? null : mDefaultBrowserApp.removeReturnOld(userId); |
Fabrice Di Meglio | 6227172 | 2015-04-10 17:24:02 -0700 | [diff] [blame] | 1268 | } |
| 1269 | |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1270 | private File getUserPackagesStateFile(int userId) { |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 1271 | // TODO: Implement a cleaner solution when adding tests. |
| 1272 | // This instead of Environment.getUserSystemDirectory(userId) to support testing. |
| 1273 | File userDir = new File(new File(mSystemDir, "users"), Integer.toString(userId)); |
| 1274 | return new File(userDir, "package-restrictions.xml"); |
| 1275 | } |
| 1276 | |
| 1277 | private File getUserRuntimePermissionsFile(int userId) { |
| 1278 | // TODO: Implement a cleaner solution when adding tests. |
| 1279 | // This instead of Environment.getUserSystemDirectory(userId) to support testing. |
| 1280 | File userDir = new File(new File(mSystemDir, "users"), Integer.toString(userId)); |
| 1281 | return new File(userDir, RUNTIME_PERMISSIONS_FILE_NAME); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1282 | } |
| 1283 | |
| 1284 | private File getUserPackagesStateBackupFile(int userId) { |
Amith Yamasani | 61f5737 | 2012-08-31 12:12:28 -0700 | [diff] [blame] | 1285 | return new File(Environment.getUserSystemDirectory(userId), |
| 1286 | "package-restrictions-backup.xml"); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1287 | } |
| 1288 | |
| 1289 | void writeAllUsersPackageRestrictionsLPr() { |
Todd Kennedy | 13715d5 | 2016-08-01 13:38:57 -0700 | [diff] [blame] | 1290 | List<UserInfo> users = getAllUsers(UserManagerService.getInstance()); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1291 | if (users == null) return; |
| 1292 | |
| 1293 | for (UserInfo user : users) { |
| 1294 | writePackageRestrictionsLPr(user.id); |
| 1295 | } |
| 1296 | } |
| 1297 | |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 1298 | void writeAllRuntimePermissionsLPr() { |
| 1299 | for (int userId : UserManagerService.getInstance().getUserIds()) { |
| 1300 | mRuntimePermissionsPersistence.writePermissionsForUserAsyncLPr(userId); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1301 | } |
| 1302 | } |
| 1303 | |
Svet Ganov | ba3ba81 | 2015-06-26 10:54:06 -0700 | [diff] [blame] | 1304 | boolean areDefaultRuntimePermissionsGrantedLPr(int userId) { |
| 1305 | return mRuntimePermissionsPersistence |
Svet Ganov | d8eb8b2 | 2019-04-05 18:52:08 -0700 | [diff] [blame] | 1306 | .areDefaultRuntimePermissionsGrantedLPr(userId); |
Svet Ganov | ba3ba81 | 2015-06-26 10:54:06 -0700 | [diff] [blame] | 1307 | } |
| 1308 | |
Philip P. Moltmann | 5f5783e | 2019-05-22 14:57:18 -0700 | [diff] [blame] | 1309 | void setRuntimePermissionsFingerPrintLPr(@NonNull String fingerPrint, @UserIdInt int userId) { |
| 1310 | mRuntimePermissionsPersistence.setRuntimePermissionsFingerPrintLPr(fingerPrint, userId); |
Svet Ganov | ba3ba81 | 2015-06-26 10:54:06 -0700 | [diff] [blame] | 1311 | } |
| 1312 | |
Svet Ganov | d8eb8b2 | 2019-04-05 18:52:08 -0700 | [diff] [blame] | 1313 | int getDefaultRuntimePermissionsVersionLPr(int userId) { |
| 1314 | return mRuntimePermissionsPersistence.getVersionLPr(userId); |
| 1315 | } |
| 1316 | |
| 1317 | void setDefaultRuntimePermissionsVersionLPr(int version, int userId) { |
| 1318 | mRuntimePermissionsPersistence.setVersionLPr(version, userId); |
| 1319 | } |
| 1320 | |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 1321 | public VersionInfo findOrCreateVersion(String volumeUuid) { |
| 1322 | VersionInfo ver = mVersion.get(volumeUuid); |
| 1323 | if (ver == null) { |
| 1324 | ver = new VersionInfo(); |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 1325 | mVersion.put(volumeUuid, ver); |
| 1326 | } |
| 1327 | return ver; |
Kenny Root | c1c0d3c | 2014-04-24 13:36:40 -0700 | [diff] [blame] | 1328 | } |
| 1329 | |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 1330 | public VersionInfo getInternalVersion() { |
| 1331 | return mVersion.get(StorageManager.UUID_PRIVATE_INTERNAL); |
Kenny Root | c1c0d3c | 2014-04-24 13:36:40 -0700 | [diff] [blame] | 1332 | } |
| 1333 | |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 1334 | public VersionInfo getExternalVersion() { |
| 1335 | return mVersion.get(StorageManager.UUID_PRIMARY_PHYSICAL); |
Kenny Root | c1c0d3c | 2014-04-24 13:36:40 -0700 | [diff] [blame] | 1336 | } |
| 1337 | |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 1338 | public void onVolumeForgotten(String fsUuid) { |
| 1339 | mVersion.remove(fsUuid); |
Kenny Root | c1c0d3c | 2014-04-24 13:36:40 -0700 | [diff] [blame] | 1340 | } |
| 1341 | |
Christopher Tate | e012a23 | 2015-04-01 17:18:50 -0700 | [diff] [blame] | 1342 | /** |
| 1343 | * Applies the preferred activity state described by the given XML. This code |
| 1344 | * also supports the restore-from-backup code path. |
| 1345 | * |
| 1346 | * @see PreferredActivityBackupHelper |
| 1347 | */ |
| 1348 | void readPreferredActivitiesLPw(XmlPullParser parser, int userId) |
Dianne Hackborn | 6309271 | 2012-10-07 14:45:35 -0700 | [diff] [blame] | 1349 | throws XmlPullParserException, IOException { |
| 1350 | int outerDepth = parser.getDepth(); |
| 1351 | int type; |
| 1352 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 1353 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 1354 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 1355 | continue; |
| 1356 | } |
| 1357 | |
| 1358 | String tagName = parser.getName(); |
| 1359 | if (tagName.equals(TAG_ITEM)) { |
| 1360 | PreferredActivity pa = new PreferredActivity(parser); |
| 1361 | if (pa.mPref.getParseError() == null) { |
| 1362 | editPreferredActivitiesLPw(userId).addFilter(pa); |
| 1363 | } else { |
| 1364 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 1365 | "Error in package manager settings: <preferred-activity> " |
| 1366 | + pa.mPref.getParseError() + " at " |
| 1367 | + parser.getPositionDescription()); |
| 1368 | } |
| 1369 | } else { |
| 1370 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 1371 | "Unknown element under <preferred-activities>: " + parser.getName()); |
| 1372 | XmlUtils.skipCurrentTag(parser); |
| 1373 | } |
| 1374 | } |
| 1375 | } |
| 1376 | |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 1377 | private void readPersistentPreferredActivitiesLPw(XmlPullParser parser, int userId) |
| 1378 | throws XmlPullParserException, IOException { |
| 1379 | int outerDepth = parser.getDepth(); |
| 1380 | int type; |
| 1381 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 1382 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 1383 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 1384 | continue; |
| 1385 | } |
| 1386 | String tagName = parser.getName(); |
| 1387 | if (tagName.equals(TAG_ITEM)) { |
| 1388 | PersistentPreferredActivity ppa = new PersistentPreferredActivity(parser); |
| 1389 | editPersistentPreferredActivitiesLPw(userId).addFilter(ppa); |
| 1390 | } else { |
| 1391 | PackageManagerService.reportSettingsProblem(Log.WARN, |
Sander Alewijnse | af59762 | 2014-03-20 18:44:57 +0000 | [diff] [blame] | 1392 | "Unknown element under <" + TAG_PERSISTENT_PREFERRED_ACTIVITIES + ">: " |
| 1393 | + parser.getName()); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 1394 | XmlUtils.skipCurrentTag(parser); |
| 1395 | } |
| 1396 | } |
| 1397 | } |
| 1398 | |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 1399 | private void readCrossProfileIntentFiltersLPw(XmlPullParser parser, int userId) |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1400 | throws XmlPullParserException, IOException { |
| 1401 | int outerDepth = parser.getDepth(); |
| 1402 | int type; |
| 1403 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 1404 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 1405 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 1406 | continue; |
| 1407 | } |
Christopher Tate | 6038d15 | 2015-06-17 13:07:46 -0700 | [diff] [blame] | 1408 | final String tagName = parser.getName(); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1409 | if (tagName.equals(TAG_ITEM)) { |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 1410 | CrossProfileIntentFilter cpif = new CrossProfileIntentFilter(parser); |
| 1411 | editCrossProfileIntentResolverLPw(userId).addFilter(cpif); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1412 | } else { |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 1413 | String msg = "Unknown element under " + TAG_CROSS_PROFILE_INTENT_FILTERS + ": " + |
Christopher Tate | 6038d15 | 2015-06-17 13:07:46 -0700 | [diff] [blame] | 1414 | tagName; |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1415 | PackageManagerService.reportSettingsProblem(Log.WARN, msg); |
| 1416 | XmlUtils.skipCurrentTag(parser); |
| 1417 | } |
| 1418 | } |
| 1419 | } |
| 1420 | |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1421 | private void readDomainVerificationLPw(XmlPullParser parser, PackageSettingBase packageSetting) |
| 1422 | throws XmlPullParserException, IOException { |
| 1423 | IntentFilterVerificationInfo ivi = new IntentFilterVerificationInfo(parser); |
| 1424 | packageSetting.setIntentFilterVerificationInfo(ivi); |
Todd Kennedy | 788c842 | 2016-08-10 10:52:34 -0700 | [diff] [blame] | 1425 | if (DEBUG_PARSER) { |
| 1426 | Log.d(TAG, "Read domain verification for package: " + ivi.getPackageName()); |
| 1427 | } |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1428 | } |
| 1429 | |
Christopher Tate | 6038d15 | 2015-06-17 13:07:46 -0700 | [diff] [blame] | 1430 | private void readRestoredIntentFilterVerifications(XmlPullParser parser) |
| 1431 | throws XmlPullParserException, IOException { |
| 1432 | int outerDepth = parser.getDepth(); |
| 1433 | int type; |
| 1434 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 1435 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 1436 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 1437 | continue; |
| 1438 | } |
| 1439 | final String tagName = parser.getName(); |
| 1440 | if (tagName.equals(TAG_DOMAIN_VERIFICATION)) { |
| 1441 | IntentFilterVerificationInfo ivi = new IntentFilterVerificationInfo(parser); |
| 1442 | if (DEBUG_DOMAIN_VERIFICATION) { |
| 1443 | Slog.i(TAG, "Restored IVI for " + ivi.getPackageName() |
| 1444 | + " status=" + ivi.getStatusString()); |
| 1445 | } |
| 1446 | mRestoredIntentFilterVerifications.put(ivi.getPackageName(), ivi); |
| 1447 | } else { |
| 1448 | Slog.w(TAG, "Unknown element: " + tagName); |
| 1449 | XmlUtils.skipCurrentTag(parser); |
| 1450 | } |
| 1451 | } |
| 1452 | } |
| 1453 | |
| 1454 | void readDefaultAppsLPw(XmlPullParser parser, int userId) |
Fabrice Di Meglio | 6227172 | 2015-04-10 17:24:02 -0700 | [diff] [blame] | 1455 | throws XmlPullParserException, IOException { |
| 1456 | int outerDepth = parser.getDepth(); |
| 1457 | int type; |
| 1458 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 1459 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 1460 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 1461 | continue; |
| 1462 | } |
| 1463 | String tagName = parser.getName(); |
| 1464 | if (tagName.equals(TAG_DEFAULT_BROWSER)) { |
| 1465 | String packageName = parser.getAttributeValue(null, ATTR_PACKAGE_NAME); |
| 1466 | mDefaultBrowserApp.put(userId, packageName); |
Robin Lee | 0dc591b | 2016-05-04 13:01:46 +0100 | [diff] [blame] | 1467 | } else if (tagName.equals(TAG_DEFAULT_DIALER)) { |
Hai Zhang | c139927 | 2019-05-07 15:50:58 -0700 | [diff] [blame] | 1468 | // Ignored. |
Fabrice Di Meglio | 6227172 | 2015-04-10 17:24:02 -0700 | [diff] [blame] | 1469 | } else { |
| 1470 | String msg = "Unknown element under " + TAG_DEFAULT_APPS + ": " + |
| 1471 | parser.getName(); |
| 1472 | PackageManagerService.reportSettingsProblem(Log.WARN, msg); |
| 1473 | XmlUtils.skipCurrentTag(parser); |
| 1474 | } |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1475 | } |
| 1476 | } |
| 1477 | |
Vladislav Kuzkokov | 253984e | 2016-10-24 09:27:16 +0200 | [diff] [blame] | 1478 | void readBlockUninstallPackagesLPw(XmlPullParser parser, int userId) |
| 1479 | throws XmlPullParserException, IOException { |
| 1480 | int outerDepth = parser.getDepth(); |
| 1481 | int type; |
| 1482 | ArraySet<String> packages = new ArraySet<>(); |
| 1483 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 1484 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 1485 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 1486 | continue; |
| 1487 | } |
| 1488 | String tagName = parser.getName(); |
| 1489 | if (tagName.equals(TAG_BLOCK_UNINSTALL)) { |
| 1490 | String packageName = parser.getAttributeValue(null, ATTR_PACKAGE_NAME); |
| 1491 | packages.add(packageName); |
| 1492 | } else { |
| 1493 | String msg = "Unknown element under " + TAG_BLOCK_UNINSTALL_PACKAGES + ": " + |
| 1494 | parser.getName(); |
| 1495 | PackageManagerService.reportSettingsProblem(Log.WARN, msg); |
| 1496 | XmlUtils.skipCurrentTag(parser); |
| 1497 | } |
| 1498 | } |
| 1499 | if (packages.isEmpty()) { |
| 1500 | mBlockUninstallPackages.remove(userId); |
| 1501 | } else { |
| 1502 | mBlockUninstallPackages.put(userId, packages); |
| 1503 | } |
| 1504 | } |
| 1505 | |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1506 | void readPackageRestrictionsLPr(int userId) { |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1507 | if (DEBUG_MU) { |
| 1508 | Log.i(TAG, "Reading package restrictions for user=" + userId); |
| 1509 | } |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1510 | FileInputStream str = null; |
| 1511 | File userPackagesStateFile = getUserPackagesStateFile(userId); |
| 1512 | File backupFile = getUserPackagesStateBackupFile(userId); |
| 1513 | if (backupFile.exists()) { |
| 1514 | try { |
| 1515 | str = new FileInputStream(backupFile); |
| 1516 | mReadMessages.append("Reading from backup stopped packages file\n"); |
| 1517 | PackageManagerService.reportSettingsProblem(Log.INFO, |
| 1518 | "Need to read from backup stopped packages file"); |
| 1519 | if (userPackagesStateFile.exists()) { |
| 1520 | // If both the backup and normal file exist, we |
| 1521 | // ignore the normal one since it might have been |
| 1522 | // corrupted. |
| 1523 | Slog.w(PackageManagerService.TAG, "Cleaning up stopped packages file " |
| 1524 | + userPackagesStateFile); |
| 1525 | userPackagesStateFile.delete(); |
| 1526 | } |
| 1527 | } catch (java.io.IOException e) { |
| 1528 | // We'll try for the normal settings file. |
| 1529 | } |
| 1530 | } |
| 1531 | |
| 1532 | try { |
| 1533 | if (str == null) { |
| 1534 | if (!userPackagesStateFile.exists()) { |
| 1535 | mReadMessages.append("No stopped packages file found\n"); |
| 1536 | PackageManagerService.reportSettingsProblem(Log.INFO, |
| 1537 | "No stopped packages file; " |
| 1538 | + "assuming all started"); |
| 1539 | // At first boot, make sure no packages are stopped. |
| 1540 | // We usually want to have third party apps initialize |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 1541 | // in the stopped state, but not at first boot. Also |
| 1542 | // consider all applications to be installed. |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1543 | for (PackageSetting pkg : mPackages.values()) { |
Jeff Sharkey | 4288419 | 2016-04-09 16:12:01 -0600 | [diff] [blame] | 1544 | pkg.setUserState(userId, 0, COMPONENT_ENABLED_STATE_DEFAULT, |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 1545 | true /*installed*/, |
| 1546 | false /*stopped*/, |
| 1547 | false /*notLaunched*/, |
| 1548 | false /*hidden*/, |
Suprabh Shukla | 7900049 | 2018-12-24 17:03:02 -0800 | [diff] [blame] | 1549 | 0 /*distractionFlags*/, |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 1550 | false /*suspended*/, |
Suprabh Shukla | 151b21b | 2018-04-27 19:30:30 -0700 | [diff] [blame] | 1551 | null /*suspendingPackage*/, |
Suprabh Shukla | 389cb6f | 2018-10-01 18:20:39 -0700 | [diff] [blame] | 1552 | null /*dialogInfo*/, |
Suprabh Shukla | 151b21b | 2018-04-27 19:30:30 -0700 | [diff] [blame] | 1553 | null /*suspendedAppExtras*/, |
| 1554 | null /*suspendedLauncherExtras*/, |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 1555 | false /*instantApp*/, |
Todd Kennedy | 5eb5a7d | 2017-08-01 07:42:47 -0700 | [diff] [blame] | 1556 | false /*virtualPreload*/, |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 1557 | null /*lastDisableAppCaller*/, |
| 1558 | null /*enabledComponents*/, |
| 1559 | null /*disabledComponents*/, |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 1560 | INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_UNDEFINED, |
Ben Gruver | 1ab3d6e | 2017-12-07 13:45:08 -0800 | [diff] [blame] | 1561 | 0, PackageManager.INSTALL_REASON_UNKNOWN, |
| 1562 | null /*harmfulAppWarning*/); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1563 | } |
| 1564 | return; |
| 1565 | } |
| 1566 | str = new FileInputStream(userPackagesStateFile); |
| 1567 | } |
| 1568 | final XmlPullParser parser = Xml.newPullParser(); |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 1569 | parser.setInput(str, StandardCharsets.UTF_8.name()); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1570 | |
| 1571 | int type; |
| 1572 | while ((type=parser.next()) != XmlPullParser.START_TAG |
| 1573 | && type != XmlPullParser.END_DOCUMENT) { |
| 1574 | ; |
| 1575 | } |
| 1576 | |
| 1577 | if (type != XmlPullParser.START_TAG) { |
| 1578 | mReadMessages.append("No start tag found in package restrictions file\n"); |
| 1579 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 1580 | "No start tag found in package manager stopped packages"); |
| 1581 | return; |
| 1582 | } |
| 1583 | |
Christopher Tate | f0d6cb3 | 2015-07-10 17:44:53 -0700 | [diff] [blame] | 1584 | int maxAppLinkGeneration = 0; |
| 1585 | |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1586 | int outerDepth = parser.getDepth(); |
| 1587 | PackageSetting ps = null; |
| 1588 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 1589 | && (type != XmlPullParser.END_TAG |
| 1590 | || parser.getDepth() > outerDepth)) { |
| 1591 | if (type == XmlPullParser.END_TAG |
| 1592 | || type == XmlPullParser.TEXT) { |
| 1593 | continue; |
| 1594 | } |
| 1595 | |
| 1596 | String tagName = parser.getName(); |
| 1597 | if (tagName.equals(TAG_PACKAGE)) { |
| 1598 | String name = parser.getAttributeValue(null, ATTR_NAME); |
| 1599 | ps = mPackages.get(name); |
| 1600 | if (ps == null) { |
Jeff Sharkey | e06b4d1 | 2016-01-06 14:51:50 -0700 | [diff] [blame] | 1601 | Slog.w(PackageManagerService.TAG, "No package known for stopped package " |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1602 | + name); |
| 1603 | XmlUtils.skipCurrentTag(parser); |
| 1604 | continue; |
| 1605 | } |
Jeff Sharkey | 4288419 | 2016-04-09 16:12:01 -0600 | [diff] [blame] | 1606 | |
| 1607 | final long ceDataInode = XmlUtils.readLongAttribute(parser, ATTR_CE_DATA_INODE, |
| 1608 | 0); |
| 1609 | final boolean installed = XmlUtils.readBooleanAttribute(parser, ATTR_INSTALLED, |
| 1610 | true); |
| 1611 | final boolean stopped = XmlUtils.readBooleanAttribute(parser, ATTR_STOPPED, |
| 1612 | false); |
| 1613 | final boolean notLaunched = XmlUtils.readBooleanAttribute(parser, |
| 1614 | ATTR_NOT_LAUNCHED, false); |
| 1615 | |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 1616 | // For backwards compatibility with the previous name of "blocked", which |
| 1617 | // now means hidden, read the old attribute as well. |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 1618 | final String blockedStr = parser.getAttributeValue(null, ATTR_BLOCKED); |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 1619 | boolean hidden = blockedStr == null |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 1620 | ? false : Boolean.parseBoolean(blockedStr); |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 1621 | final String hiddenStr = parser.getAttributeValue(null, ATTR_HIDDEN); |
| 1622 | hidden = hiddenStr == null |
| 1623 | ? hidden : Boolean.parseBoolean(hiddenStr); |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 1624 | |
Suprabh Shukla | 7900049 | 2018-12-24 17:03:02 -0800 | [diff] [blame] | 1625 | final int distractionFlags = XmlUtils.readIntAttribute(parser, |
| 1626 | ATTR_DISTRACTION_FLAGS, 0); |
Jeff Sharkey | 4288419 | 2016-04-09 16:12:01 -0600 | [diff] [blame] | 1627 | final boolean suspended = XmlUtils.readBooleanAttribute(parser, ATTR_SUSPENDED, |
| 1628 | false); |
Suprabh Shukla | 021b57a | 2018-03-08 18:21:50 -0800 | [diff] [blame] | 1629 | String suspendingPackage = parser.getAttributeValue(null, |
| 1630 | ATTR_SUSPENDING_PACKAGE); |
Suprabh Shukla | 3c3af14 | 2018-03-30 00:28:37 -0700 | [diff] [blame] | 1631 | final String dialogMessage = parser.getAttributeValue(null, |
| 1632 | ATTR_SUSPEND_DIALOG_MESSAGE); |
Suprabh Shukla | 021b57a | 2018-03-08 18:21:50 -0800 | [diff] [blame] | 1633 | if (suspended && suspendingPackage == null) { |
| 1634 | suspendingPackage = PLATFORM_PACKAGE_NAME; |
| 1635 | } |
| 1636 | |
Jeff Sharkey | 4288419 | 2016-04-09 16:12:01 -0600 | [diff] [blame] | 1637 | final boolean blockUninstall = XmlUtils.readBooleanAttribute(parser, |
| 1638 | ATTR_BLOCK_UNINSTALL, false); |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 1639 | final boolean instantApp = XmlUtils.readBooleanAttribute(parser, |
| 1640 | ATTR_INSTANT_APP, false); |
Todd Kennedy | 5eb5a7d | 2017-08-01 07:42:47 -0700 | [diff] [blame] | 1641 | final boolean virtualPreload = XmlUtils.readBooleanAttribute(parser, |
| 1642 | ATTR_VIRTUAL_PRELOAD, false); |
Jeff Sharkey | 4288419 | 2016-04-09 16:12:01 -0600 | [diff] [blame] | 1643 | final int enabled = XmlUtils.readIntAttribute(parser, ATTR_ENABLED, |
| 1644 | COMPONENT_ENABLED_STATE_DEFAULT); |
| 1645 | final String enabledCaller = parser.getAttributeValue(null, |
| 1646 | ATTR_ENABLED_CALLER); |
Ben Gruver | 1ab3d6e | 2017-12-07 13:45:08 -0800 | [diff] [blame] | 1647 | final String harmfulAppWarning = |
| 1648 | parser.getAttributeValue(null, ATTR_HARMFUL_APP_WARNING); |
Jeff Sharkey | 4288419 | 2016-04-09 16:12:01 -0600 | [diff] [blame] | 1649 | final int verifState = XmlUtils.readIntAttribute(parser, |
| 1650 | ATTR_DOMAIN_VERIFICATON_STATE, |
| 1651 | PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_UNDEFINED); |
| 1652 | final int linkGeneration = XmlUtils.readIntAttribute(parser, |
| 1653 | ATTR_APP_LINK_GENERATION, 0); |
Christopher Tate | f0d6cb3 | 2015-07-10 17:44:53 -0700 | [diff] [blame] | 1654 | if (linkGeneration > maxAppLinkGeneration) { |
| 1655 | maxAppLinkGeneration = linkGeneration; |
| 1656 | } |
Bartosz Fabianowski | a34f53f | 2017-01-11 18:08:47 +0100 | [diff] [blame] | 1657 | final int installReason = XmlUtils.readIntAttribute(parser, |
| 1658 | ATTR_INSTALL_REASON, PackageManager.INSTALL_REASON_UNKNOWN); |
Christopher Tate | f0d6cb3 | 2015-07-10 17:44:53 -0700 | [diff] [blame] | 1659 | |
Jeff Sharkey | 9f837a9 | 2014-10-24 12:07:24 -0700 | [diff] [blame] | 1660 | ArraySet<String> enabledComponents = null; |
| 1661 | ArraySet<String> disabledComponents = null; |
Suprabh Shukla | 021b57a | 2018-03-08 18:21:50 -0800 | [diff] [blame] | 1662 | PersistableBundle suspendedAppExtras = null; |
| 1663 | PersistableBundle suspendedLauncherExtras = null; |
Suprabh Shukla | 389cb6f | 2018-10-01 18:20:39 -0700 | [diff] [blame] | 1664 | SuspendDialogInfo suspendDialogInfo = null; |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1665 | |
| 1666 | int packageDepth = parser.getDepth(); |
| 1667 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 1668 | && (type != XmlPullParser.END_TAG |
| 1669 | || parser.getDepth() > packageDepth)) { |
| 1670 | if (type == XmlPullParser.END_TAG |
| 1671 | || type == XmlPullParser.TEXT) { |
| 1672 | continue; |
| 1673 | } |
Suprabh Shukla | 021b57a | 2018-03-08 18:21:50 -0800 | [diff] [blame] | 1674 | switch (parser.getName()) { |
| 1675 | case TAG_ENABLED_COMPONENTS: |
| 1676 | enabledComponents = readComponentsLPr(parser); |
| 1677 | break; |
| 1678 | case TAG_DISABLED_COMPONENTS: |
| 1679 | disabledComponents = readComponentsLPr(parser); |
| 1680 | break; |
| 1681 | case TAG_SUSPENDED_APP_EXTRAS: |
| 1682 | suspendedAppExtras = PersistableBundle.restoreFromXml(parser); |
| 1683 | break; |
| 1684 | case TAG_SUSPENDED_LAUNCHER_EXTRAS: |
| 1685 | suspendedLauncherExtras = PersistableBundle.restoreFromXml(parser); |
| 1686 | break; |
Suprabh Shukla | 389cb6f | 2018-10-01 18:20:39 -0700 | [diff] [blame] | 1687 | case TAG_SUSPENDED_DIALOG_INFO: |
| 1688 | suspendDialogInfo = SuspendDialogInfo.restoreFromXml(parser); |
| 1689 | break; |
Suprabh Shukla | 021b57a | 2018-03-08 18:21:50 -0800 | [diff] [blame] | 1690 | default: |
| 1691 | Slog.wtf(TAG, "Unknown tag " + parser.getName() + " under tag " |
| 1692 | + TAG_PACKAGE); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1693 | } |
| 1694 | } |
Suprabh Shukla | 389cb6f | 2018-10-01 18:20:39 -0700 | [diff] [blame] | 1695 | if (suspendDialogInfo == null && !TextUtils.isEmpty(dialogMessage)) { |
| 1696 | suspendDialogInfo = new SuspendDialogInfo.Builder() |
| 1697 | .setMessage(dialogMessage) |
| 1698 | .build(); |
| 1699 | } |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 1700 | |
Vladislav Kuzkokov | 253984e | 2016-10-24 09:27:16 +0200 | [diff] [blame] | 1701 | if (blockUninstall) { |
| 1702 | setBlockUninstallLPw(userId, name, true); |
| 1703 | } |
Jeff Sharkey | 4288419 | 2016-04-09 16:12:01 -0600 | [diff] [blame] | 1704 | ps.setUserState(userId, ceDataInode, enabled, installed, stopped, notLaunched, |
Suprabh Shukla | 7900049 | 2018-12-24 17:03:02 -0800 | [diff] [blame] | 1705 | hidden, distractionFlags, suspended, suspendingPackage, |
| 1706 | suspendDialogInfo, |
Suprabh Shukla | 389cb6f | 2018-10-01 18:20:39 -0700 | [diff] [blame] | 1707 | suspendedAppExtras, suspendedLauncherExtras, instantApp, virtualPreload, |
| 1708 | enabledCaller, enabledComponents, disabledComponents, verifState, |
| 1709 | linkGeneration, installReason, harmfulAppWarning); |
Dianne Hackborn | 6309271 | 2012-10-07 14:45:35 -0700 | [diff] [blame] | 1710 | } else if (tagName.equals("preferred-activities")) { |
| 1711 | readPreferredActivitiesLPw(parser, userId); |
Sander Alewijnse | af59762 | 2014-03-20 18:44:57 +0000 | [diff] [blame] | 1712 | } else if (tagName.equals(TAG_PERSISTENT_PREFERRED_ACTIVITIES)) { |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 1713 | readPersistentPreferredActivitiesLPw(parser, userId); |
Nicolas Prevot | 29762c3 | 2014-07-29 18:51:32 +0100 | [diff] [blame] | 1714 | } else if (tagName.equals(TAG_CROSS_PROFILE_INTENT_FILTERS)) { |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 1715 | readCrossProfileIntentFiltersLPw(parser, userId); |
Fabrice Di Meglio | 6227172 | 2015-04-10 17:24:02 -0700 | [diff] [blame] | 1716 | } else if (tagName.equals(TAG_DEFAULT_APPS)) { |
| 1717 | readDefaultAppsLPw(parser, userId); |
Vladislav Kuzkokov | 253984e | 2016-10-24 09:27:16 +0200 | [diff] [blame] | 1718 | } else if (tagName.equals(TAG_BLOCK_UNINSTALL_PACKAGES)) { |
| 1719 | readBlockUninstallPackagesLPw(parser, userId); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1720 | } else { |
| 1721 | Slog.w(PackageManagerService.TAG, "Unknown element under <stopped-packages>: " |
| 1722 | + parser.getName()); |
| 1723 | XmlUtils.skipCurrentTag(parser); |
| 1724 | } |
| 1725 | } |
| 1726 | |
| 1727 | str.close(); |
| 1728 | |
Christopher Tate | f0d6cb3 | 2015-07-10 17:44:53 -0700 | [diff] [blame] | 1729 | mNextAppLinkGeneration.put(userId, maxAppLinkGeneration + 1); |
| 1730 | |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1731 | } catch (XmlPullParserException e) { |
| 1732 | mReadMessages.append("Error reading: " + e.toString()); |
| 1733 | PackageManagerService.reportSettingsProblem(Log.ERROR, |
| 1734 | "Error reading stopped packages: " + e); |
Dianne Hackborn | 8d05172 | 2014-10-01 14:59:58 -0700 | [diff] [blame] | 1735 | Slog.wtf(PackageManagerService.TAG, "Error reading package manager stopped packages", |
| 1736 | e); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1737 | |
| 1738 | } catch (java.io.IOException e) { |
| 1739 | mReadMessages.append("Error reading: " + e.toString()); |
| 1740 | PackageManagerService.reportSettingsProblem(Log.ERROR, "Error reading settings: " + e); |
Dianne Hackborn | 8d05172 | 2014-10-01 14:59:58 -0700 | [diff] [blame] | 1741 | Slog.wtf(PackageManagerService.TAG, "Error reading package manager stopped packages", |
| 1742 | e); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1743 | } |
| 1744 | } |
| 1745 | |
Vladislav Kuzkokov | 253984e | 2016-10-24 09:27:16 +0200 | [diff] [blame] | 1746 | void setBlockUninstallLPw(int userId, String packageName, boolean blockUninstall) { |
| 1747 | ArraySet<String> packages = mBlockUninstallPackages.get(userId); |
| 1748 | if (blockUninstall) { |
| 1749 | if (packages == null) { |
| 1750 | packages = new ArraySet<String>(); |
| 1751 | mBlockUninstallPackages.put(userId, packages); |
| 1752 | } |
| 1753 | packages.add(packageName); |
| 1754 | } else if (packages != null) { |
| 1755 | packages.remove(packageName); |
| 1756 | if (packages.isEmpty()) { |
| 1757 | mBlockUninstallPackages.remove(userId); |
| 1758 | } |
| 1759 | } |
| 1760 | } |
| 1761 | |
| 1762 | boolean getBlockUninstallLPr(int userId, String packageName) { |
| 1763 | ArraySet<String> packages = mBlockUninstallPackages.get(userId); |
| 1764 | if (packages == null) { |
| 1765 | return false; |
| 1766 | } |
| 1767 | return packages.contains(packageName); |
| 1768 | } |
| 1769 | |
Jeff Sharkey | 9f837a9 | 2014-10-24 12:07:24 -0700 | [diff] [blame] | 1770 | private ArraySet<String> readComponentsLPr(XmlPullParser parser) |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1771 | throws IOException, XmlPullParserException { |
Jeff Sharkey | 9f837a9 | 2014-10-24 12:07:24 -0700 | [diff] [blame] | 1772 | ArraySet<String> components = null; |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1773 | int type; |
| 1774 | int outerDepth = parser.getDepth(); |
| 1775 | String tagName; |
| 1776 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 1777 | && (type != XmlPullParser.END_TAG |
| 1778 | || parser.getDepth() > outerDepth)) { |
| 1779 | if (type == XmlPullParser.END_TAG |
| 1780 | || type == XmlPullParser.TEXT) { |
| 1781 | continue; |
| 1782 | } |
| 1783 | tagName = parser.getName(); |
| 1784 | if (tagName.equals(TAG_ITEM)) { |
| 1785 | String componentName = parser.getAttributeValue(null, ATTR_NAME); |
| 1786 | if (componentName != null) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 1787 | if (components == null) { |
Jeff Sharkey | 9f837a9 | 2014-10-24 12:07:24 -0700 | [diff] [blame] | 1788 | components = new ArraySet<String>(); |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 1789 | } |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1790 | components.add(componentName); |
| 1791 | } |
| 1792 | } |
| 1793 | } |
| 1794 | return components; |
| 1795 | } |
| 1796 | |
Christopher Tate | e012a23 | 2015-04-01 17:18:50 -0700 | [diff] [blame] | 1797 | /** |
| 1798 | * Record the state of preferred activity configuration into XML. This is used both |
| 1799 | * for recording packages.xml internally and for supporting backup/restore of the |
| 1800 | * preferred activity configuration. |
| 1801 | */ |
Dianne Hackborn | 8a2ed1d | 2013-01-29 15:18:29 -0800 | [diff] [blame] | 1802 | void writePreferredActivitiesLPr(XmlSerializer serializer, int userId, boolean full) |
Dianne Hackborn | 6309271 | 2012-10-07 14:45:35 -0700 | [diff] [blame] | 1803 | throws IllegalArgumentException, IllegalStateException, IOException { |
| 1804 | serializer.startTag(null, "preferred-activities"); |
| 1805 | PreferredIntentResolver pir = mPreferredActivities.get(userId); |
| 1806 | if (pir != null) { |
| 1807 | for (final PreferredActivity pa : pir.filterSet()) { |
| 1808 | serializer.startTag(null, TAG_ITEM); |
Dianne Hackborn | 8a2ed1d | 2013-01-29 15:18:29 -0800 | [diff] [blame] | 1809 | pa.writeToXml(serializer, full); |
Dianne Hackborn | 6309271 | 2012-10-07 14:45:35 -0700 | [diff] [blame] | 1810 | serializer.endTag(null, TAG_ITEM); |
| 1811 | } |
| 1812 | } |
| 1813 | serializer.endTag(null, "preferred-activities"); |
| 1814 | } |
| 1815 | |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 1816 | void writePersistentPreferredActivitiesLPr(XmlSerializer serializer, int userId) |
| 1817 | throws IllegalArgumentException, IllegalStateException, IOException { |
Sander Alewijnse | af59762 | 2014-03-20 18:44:57 +0000 | [diff] [blame] | 1818 | serializer.startTag(null, TAG_PERSISTENT_PREFERRED_ACTIVITIES); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 1819 | PersistentPreferredIntentResolver ppir = mPersistentPreferredActivities.get(userId); |
| 1820 | if (ppir != null) { |
| 1821 | for (final PersistentPreferredActivity ppa : ppir.filterSet()) { |
| 1822 | serializer.startTag(null, TAG_ITEM); |
| 1823 | ppa.writeToXml(serializer); |
| 1824 | serializer.endTag(null, TAG_ITEM); |
| 1825 | } |
| 1826 | } |
Sander Alewijnse | af59762 | 2014-03-20 18:44:57 +0000 | [diff] [blame] | 1827 | serializer.endTag(null, TAG_PERSISTENT_PREFERRED_ACTIVITIES); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 1828 | } |
| 1829 | |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 1830 | void writeCrossProfileIntentFiltersLPr(XmlSerializer serializer, int userId) |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1831 | throws IllegalArgumentException, IllegalStateException, IOException { |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 1832 | serializer.startTag(null, TAG_CROSS_PROFILE_INTENT_FILTERS); |
| 1833 | CrossProfileIntentResolver cpir = mCrossProfileIntentResolvers.get(userId); |
| 1834 | if (cpir != null) { |
| 1835 | for (final CrossProfileIntentFilter cpif : cpir.filterSet()) { |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1836 | serializer.startTag(null, TAG_ITEM); |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 1837 | cpif.writeToXml(serializer); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1838 | serializer.endTag(null, TAG_ITEM); |
| 1839 | } |
| 1840 | } |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 1841 | serializer.endTag(null, TAG_CROSS_PROFILE_INTENT_FILTERS); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1842 | } |
| 1843 | |
Fabrice Di Meglio | 6227172 | 2015-04-10 17:24:02 -0700 | [diff] [blame] | 1844 | void writeDomainVerificationsLPr(XmlSerializer serializer, |
| 1845 | IntentFilterVerificationInfo verificationInfo) |
| 1846 | throws IllegalArgumentException, IllegalStateException, IOException { |
| 1847 | if (verificationInfo != null && verificationInfo.getPackageName() != null) { |
| 1848 | serializer.startTag(null, TAG_DOMAIN_VERIFICATION); |
| 1849 | verificationInfo.writeToXml(serializer); |
Christopher Tate | 72c10a2 | 2015-06-12 18:31:24 -0700 | [diff] [blame] | 1850 | if (DEBUG_DOMAIN_VERIFICATION) { |
| 1851 | Slog.d(TAG, "Wrote domain verification for package: " |
| 1852 | + verificationInfo.getPackageName()); |
| 1853 | } |
Fabrice Di Meglio | 6227172 | 2015-04-10 17:24:02 -0700 | [diff] [blame] | 1854 | serializer.endTag(null, TAG_DOMAIN_VERIFICATION); |
| 1855 | } |
| 1856 | } |
| 1857 | |
Christopher Tate | 6038d15 | 2015-06-17 13:07:46 -0700 | [diff] [blame] | 1858 | // Specifically for backup/restore |
| 1859 | void writeAllDomainVerificationsLPr(XmlSerializer serializer, int userId) |
| 1860 | throws IllegalArgumentException, IllegalStateException, IOException { |
| 1861 | serializer.startTag(null, TAG_ALL_INTENT_FILTER_VERIFICATION); |
| 1862 | final int N = mPackages.size(); |
| 1863 | for (int i = 0; i < N; i++) { |
| 1864 | PackageSetting ps = mPackages.valueAt(i); |
| 1865 | IntentFilterVerificationInfo ivi = ps.getIntentFilterVerificationInfo(); |
| 1866 | if (ivi != null) { |
| 1867 | writeDomainVerificationsLPr(serializer, ivi); |
| 1868 | } |
| 1869 | } |
| 1870 | serializer.endTag(null, TAG_ALL_INTENT_FILTER_VERIFICATION); |
| 1871 | } |
| 1872 | |
| 1873 | // Specifically for backup/restore |
| 1874 | void readAllDomainVerificationsLPr(XmlPullParser parser, int userId) |
| 1875 | throws XmlPullParserException, IOException { |
| 1876 | mRestoredIntentFilterVerifications.clear(); |
| 1877 | |
| 1878 | int outerDepth = parser.getDepth(); |
| 1879 | int type; |
| 1880 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 1881 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 1882 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 1883 | continue; |
| 1884 | } |
| 1885 | |
| 1886 | String tagName = parser.getName(); |
| 1887 | if (tagName.equals(TAG_DOMAIN_VERIFICATION)) { |
| 1888 | IntentFilterVerificationInfo ivi = new IntentFilterVerificationInfo(parser); |
| 1889 | final String pkgName = ivi.getPackageName(); |
| 1890 | final PackageSetting ps = mPackages.get(pkgName); |
| 1891 | if (ps != null) { |
| 1892 | // known/existing package; update in place |
| 1893 | ps.setIntentFilterVerificationInfo(ivi); |
| 1894 | if (DEBUG_DOMAIN_VERIFICATION) { |
| 1895 | Slog.d(TAG, "Restored IVI for existing app " + pkgName |
| 1896 | + " status=" + ivi.getStatusString()); |
| 1897 | } |
| 1898 | } else { |
| 1899 | mRestoredIntentFilterVerifications.put(pkgName, ivi); |
| 1900 | if (DEBUG_DOMAIN_VERIFICATION) { |
| 1901 | Slog.d(TAG, "Restored IVI for pending app " + pkgName |
| 1902 | + " status=" + ivi.getStatusString()); |
| 1903 | } |
| 1904 | } |
| 1905 | } else { |
| 1906 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 1907 | "Unknown element under <all-intent-filter-verification>: " |
| 1908 | + parser.getName()); |
| 1909 | XmlUtils.skipCurrentTag(parser); |
| 1910 | } |
| 1911 | } |
| 1912 | } |
| 1913 | |
Fabrice Di Meglio | 6227172 | 2015-04-10 17:24:02 -0700 | [diff] [blame] | 1914 | void writeDefaultAppsLPr(XmlSerializer serializer, int userId) |
| 1915 | throws IllegalArgumentException, IllegalStateException, IOException { |
| 1916 | serializer.startTag(null, TAG_DEFAULT_APPS); |
Robin Lee | 0dc591b | 2016-05-04 13:01:46 +0100 | [diff] [blame] | 1917 | String defaultBrowser = mDefaultBrowserApp.get(userId); |
| 1918 | if (!TextUtils.isEmpty(defaultBrowser)) { |
Fabrice Di Meglio | 6227172 | 2015-04-10 17:24:02 -0700 | [diff] [blame] | 1919 | serializer.startTag(null, TAG_DEFAULT_BROWSER); |
Robin Lee | 0dc591b | 2016-05-04 13:01:46 +0100 | [diff] [blame] | 1920 | serializer.attribute(null, ATTR_PACKAGE_NAME, defaultBrowser); |
Fabrice Di Meglio | 6227172 | 2015-04-10 17:24:02 -0700 | [diff] [blame] | 1921 | serializer.endTag(null, TAG_DEFAULT_BROWSER); |
| 1922 | } |
| 1923 | serializer.endTag(null, TAG_DEFAULT_APPS); |
| 1924 | } |
| 1925 | |
Vladislav Kuzkokov | 253984e | 2016-10-24 09:27:16 +0200 | [diff] [blame] | 1926 | void writeBlockUninstallPackagesLPr(XmlSerializer serializer, int userId) |
| 1927 | throws IOException { |
| 1928 | ArraySet<String> packages = mBlockUninstallPackages.get(userId); |
| 1929 | if (packages != null) { |
| 1930 | serializer.startTag(null, TAG_BLOCK_UNINSTALL_PACKAGES); |
| 1931 | for (int i = 0; i < packages.size(); i++) { |
| 1932 | serializer.startTag(null, TAG_BLOCK_UNINSTALL); |
| 1933 | serializer.attribute(null, ATTR_PACKAGE_NAME, packages.valueAt(i)); |
| 1934 | serializer.endTag(null, TAG_BLOCK_UNINSTALL); |
| 1935 | } |
| 1936 | serializer.endTag(null, TAG_BLOCK_UNINSTALL_PACKAGES); |
| 1937 | } |
| 1938 | } |
| 1939 | |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1940 | void writePackageRestrictionsLPr(int userId) { |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1941 | if (DEBUG_MU) { |
| 1942 | Log.i(TAG, "Writing package restrictions for user=" + userId); |
| 1943 | } |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 1944 | final long startTime = SystemClock.uptimeMillis(); |
| 1945 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1946 | // Keep the old stopped packages around until we know the new ones have |
| 1947 | // been successfully written. |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1948 | File userPackagesStateFile = getUserPackagesStateFile(userId); |
| 1949 | File backupFile = getUserPackagesStateBackupFile(userId); |
| 1950 | new File(userPackagesStateFile.getParent()).mkdirs(); |
| 1951 | if (userPackagesStateFile.exists()) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1952 | // Presence of backup settings file indicates that we failed |
| 1953 | // to persist packages earlier. So preserve the older |
| 1954 | // backup for future reference since the current packages |
| 1955 | // might have been corrupted. |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1956 | if (!backupFile.exists()) { |
| 1957 | if (!userPackagesStateFile.renameTo(backupFile)) { |
Dianne Hackborn | 8d05172 | 2014-10-01 14:59:58 -0700 | [diff] [blame] | 1958 | Slog.wtf(PackageManagerService.TAG, |
| 1959 | "Unable to backup user packages state file, " |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1960 | + "current changes will be lost at reboot"); |
| 1961 | return; |
| 1962 | } |
| 1963 | } else { |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1964 | userPackagesStateFile.delete(); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1965 | Slog.w(PackageManagerService.TAG, "Preserving older stopped packages backup"); |
| 1966 | } |
| 1967 | } |
| 1968 | |
| 1969 | try { |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1970 | final FileOutputStream fstr = new FileOutputStream(userPackagesStateFile); |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 1971 | final BufferedOutputStream str = new BufferedOutputStream(fstr); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1972 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 1973 | final XmlSerializer serializer = new FastXmlSerializer(); |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 1974 | serializer.setOutput(str, StandardCharsets.UTF_8.name()); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1975 | serializer.startDocument(null, true); |
| 1976 | serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true); |
| 1977 | |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1978 | serializer.startTag(null, TAG_PACKAGE_RESTRICTIONS); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1979 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 1980 | for (final PackageSetting pkg : mPackages.values()) { |
Jeff Sharkey | 4288419 | 2016-04-09 16:12:01 -0600 | [diff] [blame] | 1981 | final PackageUserState ustate = pkg.readUserState(userId); |
| 1982 | if (DEBUG_MU) Log.i(TAG, " pkg=" + pkg.name + ", state=" + ustate.enabled); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1983 | |
Jeff Sharkey | 4288419 | 2016-04-09 16:12:01 -0600 | [diff] [blame] | 1984 | serializer.startTag(null, TAG_PACKAGE); |
| 1985 | serializer.attribute(null, ATTR_NAME, pkg.name); |
| 1986 | if (ustate.ceDataInode != 0) { |
| 1987 | XmlUtils.writeLongAttribute(serializer, ATTR_CE_DATA_INODE, ustate.ceDataInode); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1988 | } |
Jeff Sharkey | 4288419 | 2016-04-09 16:12:01 -0600 | [diff] [blame] | 1989 | if (!ustate.installed) { |
| 1990 | serializer.attribute(null, ATTR_INSTALLED, "false"); |
| 1991 | } |
| 1992 | if (ustate.stopped) { |
| 1993 | serializer.attribute(null, ATTR_STOPPED, "true"); |
| 1994 | } |
| 1995 | if (ustate.notLaunched) { |
| 1996 | serializer.attribute(null, ATTR_NOT_LAUNCHED, "true"); |
| 1997 | } |
| 1998 | if (ustate.hidden) { |
| 1999 | serializer.attribute(null, ATTR_HIDDEN, "true"); |
| 2000 | } |
Suprabh Shukla | 7900049 | 2018-12-24 17:03:02 -0800 | [diff] [blame] | 2001 | if (ustate.distractionFlags != 0) { |
| 2002 | serializer.attribute(null, ATTR_DISTRACTION_FLAGS, |
| 2003 | Integer.toString(ustate.distractionFlags)); |
| 2004 | } |
Jeff Sharkey | 4288419 | 2016-04-09 16:12:01 -0600 | [diff] [blame] | 2005 | if (ustate.suspended) { |
| 2006 | serializer.attribute(null, ATTR_SUSPENDED, "true"); |
Suprabh Shukla | 3c3af14 | 2018-03-30 00:28:37 -0700 | [diff] [blame] | 2007 | if (ustate.suspendingPackage != null) { |
| 2008 | serializer.attribute(null, ATTR_SUSPENDING_PACKAGE, |
| 2009 | ustate.suspendingPackage); |
| 2010 | } |
Suprabh Shukla | 389cb6f | 2018-10-01 18:20:39 -0700 | [diff] [blame] | 2011 | if (ustate.dialogInfo != null) { |
| 2012 | serializer.startTag(null, TAG_SUSPENDED_DIALOG_INFO); |
| 2013 | ustate.dialogInfo.saveToXml(serializer); |
| 2014 | serializer.endTag(null, TAG_SUSPENDED_DIALOG_INFO); |
Suprabh Shukla | 3c3af14 | 2018-03-30 00:28:37 -0700 | [diff] [blame] | 2015 | } |
Suprabh Shukla | 021b57a | 2018-03-08 18:21:50 -0800 | [diff] [blame] | 2016 | if (ustate.suspendedAppExtras != null) { |
| 2017 | serializer.startTag(null, TAG_SUSPENDED_APP_EXTRAS); |
| 2018 | try { |
| 2019 | ustate.suspendedAppExtras.saveToXml(serializer); |
| 2020 | } catch (XmlPullParserException xmle) { |
| 2021 | Slog.wtf(TAG, "Exception while trying to write suspendedAppExtras for " |
| 2022 | + pkg + ". Will be lost on reboot", xmle); |
| 2023 | } |
| 2024 | serializer.endTag(null, TAG_SUSPENDED_APP_EXTRAS); |
| 2025 | } |
| 2026 | if (ustate.suspendedLauncherExtras != null) { |
| 2027 | serializer.startTag(null, TAG_SUSPENDED_LAUNCHER_EXTRAS); |
| 2028 | try { |
| 2029 | ustate.suspendedLauncherExtras.saveToXml(serializer); |
| 2030 | } catch (XmlPullParserException xmle) { |
| 2031 | Slog.wtf(TAG, "Exception while trying to write suspendedLauncherExtras" |
| 2032 | + " for " + pkg + ". Will be lost on reboot", xmle); |
| 2033 | } |
| 2034 | serializer.endTag(null, TAG_SUSPENDED_LAUNCHER_EXTRAS); |
| 2035 | } |
Jeff Sharkey | 4288419 | 2016-04-09 16:12:01 -0600 | [diff] [blame] | 2036 | } |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 2037 | if (ustate.instantApp) { |
| 2038 | serializer.attribute(null, ATTR_INSTANT_APP, "true"); |
| 2039 | } |
Todd Kennedy | 5eb5a7d | 2017-08-01 07:42:47 -0700 | [diff] [blame] | 2040 | if (ustate.virtualPreload) { |
| 2041 | serializer.attribute(null, ATTR_VIRTUAL_PRELOAD, "true"); |
| 2042 | } |
Jeff Sharkey | 4288419 | 2016-04-09 16:12:01 -0600 | [diff] [blame] | 2043 | if (ustate.enabled != COMPONENT_ENABLED_STATE_DEFAULT) { |
| 2044 | serializer.attribute(null, ATTR_ENABLED, |
| 2045 | Integer.toString(ustate.enabled)); |
| 2046 | if (ustate.lastDisableAppCaller != null) { |
| 2047 | serializer.attribute(null, ATTR_ENABLED_CALLER, |
| 2048 | ustate.lastDisableAppCaller); |
| 2049 | } |
| 2050 | } |
| 2051 | if (ustate.domainVerificationStatus != |
| 2052 | PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_UNDEFINED) { |
| 2053 | XmlUtils.writeIntAttribute(serializer, ATTR_DOMAIN_VERIFICATON_STATE, |
| 2054 | ustate.domainVerificationStatus); |
| 2055 | } |
| 2056 | if (ustate.appLinkGeneration != 0) { |
| 2057 | XmlUtils.writeIntAttribute(serializer, ATTR_APP_LINK_GENERATION, |
| 2058 | ustate.appLinkGeneration); |
| 2059 | } |
Bartosz Fabianowski | a34f53f | 2017-01-11 18:08:47 +0100 | [diff] [blame] | 2060 | if (ustate.installReason != PackageManager.INSTALL_REASON_UNKNOWN) { |
| 2061 | serializer.attribute(null, ATTR_INSTALL_REASON, |
| 2062 | Integer.toString(ustate.installReason)); |
| 2063 | } |
Ben Gruver | 1ab3d6e | 2017-12-07 13:45:08 -0800 | [diff] [blame] | 2064 | if (ustate.harmfulAppWarning != null) { |
| 2065 | serializer.attribute(null, ATTR_HARMFUL_APP_WARNING, |
| 2066 | ustate.harmfulAppWarning); |
| 2067 | } |
Jeff Sharkey | 4288419 | 2016-04-09 16:12:01 -0600 | [diff] [blame] | 2068 | if (!ArrayUtils.isEmpty(ustate.enabledComponents)) { |
| 2069 | serializer.startTag(null, TAG_ENABLED_COMPONENTS); |
| 2070 | for (final String name : ustate.enabledComponents) { |
| 2071 | serializer.startTag(null, TAG_ITEM); |
| 2072 | serializer.attribute(null, ATTR_NAME, name); |
| 2073 | serializer.endTag(null, TAG_ITEM); |
| 2074 | } |
| 2075 | serializer.endTag(null, TAG_ENABLED_COMPONENTS); |
| 2076 | } |
| 2077 | if (!ArrayUtils.isEmpty(ustate.disabledComponents)) { |
| 2078 | serializer.startTag(null, TAG_DISABLED_COMPONENTS); |
| 2079 | for (final String name : ustate.disabledComponents) { |
| 2080 | serializer.startTag(null, TAG_ITEM); |
| 2081 | serializer.attribute(null, ATTR_NAME, name); |
| 2082 | serializer.endTag(null, TAG_ITEM); |
| 2083 | } |
| 2084 | serializer.endTag(null, TAG_DISABLED_COMPONENTS); |
| 2085 | } |
| 2086 | |
| 2087 | serializer.endTag(null, TAG_PACKAGE); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2088 | } |
| 2089 | |
Dianne Hackborn | 8a2ed1d | 2013-01-29 15:18:29 -0800 | [diff] [blame] | 2090 | writePreferredActivitiesLPr(serializer, userId, true); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 2091 | writePersistentPreferredActivitiesLPr(serializer, userId); |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 2092 | writeCrossProfileIntentFiltersLPr(serializer, userId); |
Fabrice Di Meglio | 6227172 | 2015-04-10 17:24:02 -0700 | [diff] [blame] | 2093 | writeDefaultAppsLPr(serializer, userId); |
Vladislav Kuzkokov | 253984e | 2016-10-24 09:27:16 +0200 | [diff] [blame] | 2094 | writeBlockUninstallPackagesLPr(serializer, userId); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 2095 | |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2096 | serializer.endTag(null, TAG_PACKAGE_RESTRICTIONS); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2097 | |
| 2098 | serializer.endDocument(); |
| 2099 | |
| 2100 | str.flush(); |
| 2101 | FileUtils.sync(fstr); |
| 2102 | str.close(); |
| 2103 | |
| 2104 | // New settings successfully written, old ones are no longer |
| 2105 | // needed. |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2106 | backupFile.delete(); |
| 2107 | FileUtils.setPermissions(userPackagesStateFile.toString(), |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2108 | FileUtils.S_IRUSR|FileUtils.S_IWUSR |
Nick Kralevich | 70522ad | 2012-01-06 13:58:01 -0800 | [diff] [blame] | 2109 | |FileUtils.S_IRGRP|FileUtils.S_IWGRP, |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2110 | -1, -1); |
| 2111 | |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 2112 | com.android.internal.logging.EventLogTags.writeCommitSysConfigFile( |
| 2113 | "package-user-" + userId, SystemClock.uptimeMillis() - startTime); |
| 2114 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2115 | // Done, all is good! |
| 2116 | return; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2117 | } catch(java.io.IOException e) { |
Dianne Hackborn | 8d05172 | 2014-10-01 14:59:58 -0700 | [diff] [blame] | 2118 | Slog.wtf(PackageManagerService.TAG, |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2119 | "Unable to write package manager user packages state, " |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2120 | + " current changes will be lost at reboot", e); |
| 2121 | } |
| 2122 | |
| 2123 | // Clean up partially written files |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2124 | if (userPackagesStateFile.exists()) { |
| 2125 | if (!userPackagesStateFile.delete()) { |
| 2126 | Log.i(PackageManagerService.TAG, "Failed to clean up mangled file: " |
| 2127 | + mStoppedPackagesFilename); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2128 | } |
| 2129 | } |
| 2130 | } |
| 2131 | |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 2132 | void readInstallPermissionsLPr(XmlPullParser parser, |
| 2133 | PermissionsState permissionsState) throws IOException, XmlPullParserException { |
| 2134 | int outerDepth = parser.getDepth(); |
| 2135 | int type; |
| 2136 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 2137 | && (type != XmlPullParser.END_TAG |
| 2138 | || parser.getDepth() > outerDepth)) { |
| 2139 | if (type == XmlPullParser.END_TAG |
| 2140 | || type == XmlPullParser.TEXT) { |
| 2141 | continue; |
| 2142 | } |
| 2143 | String tagName = parser.getName(); |
| 2144 | if (tagName.equals(TAG_ITEM)) { |
| 2145 | String name = parser.getAttributeValue(null, ATTR_NAME); |
| 2146 | |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 2147 | BasePermission bp = mPermissions.getPermission(name); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 2148 | if (bp == null) { |
| 2149 | Slog.w(PackageManagerService.TAG, "Unknown permission: " + name); |
| 2150 | XmlUtils.skipCurrentTag(parser); |
| 2151 | continue; |
| 2152 | } |
| 2153 | |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 2154 | String grantedStr = parser.getAttributeValue(null, ATTR_GRANTED); |
| 2155 | final boolean granted = grantedStr == null |
| 2156 | || Boolean.parseBoolean(grantedStr); |
| 2157 | |
| 2158 | String flagsStr = parser.getAttributeValue(null, ATTR_FLAGS); |
| 2159 | final int flags = (flagsStr != null) |
| 2160 | ? Integer.parseInt(flagsStr, 16) : 0; |
| 2161 | |
| 2162 | if (granted) { |
| 2163 | if (permissionsState.grantInstallPermission(bp) == |
| 2164 | PermissionsState.PERMISSION_OPERATION_FAILURE) { |
| 2165 | Slog.w(PackageManagerService.TAG, "Permission already added: " + name); |
| 2166 | XmlUtils.skipCurrentTag(parser); |
| 2167 | } else { |
| 2168 | permissionsState.updatePermissionFlags(bp, UserHandle.USER_ALL, |
Philip P. Moltmann | 7659769 | 2019-03-02 13:18:41 -0800 | [diff] [blame] | 2169 | PackageManager.MASK_PERMISSION_FLAGS_ALL, flags); |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 2170 | } |
| 2171 | } else { |
| 2172 | if (permissionsState.revokeInstallPermission(bp) == |
| 2173 | PermissionsState.PERMISSION_OPERATION_FAILURE) { |
| 2174 | Slog.w(PackageManagerService.TAG, "Permission already added: " + name); |
| 2175 | XmlUtils.skipCurrentTag(parser); |
| 2176 | } else { |
| 2177 | permissionsState.updatePermissionFlags(bp, UserHandle.USER_ALL, |
Philip P. Moltmann | 7659769 | 2019-03-02 13:18:41 -0800 | [diff] [blame] | 2178 | PackageManager.MASK_PERMISSION_FLAGS_ALL, flags); |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 2179 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 2180 | } |
| 2181 | } else { |
| 2182 | Slog.w(PackageManagerService.TAG, "Unknown element under <permissions>: " |
| 2183 | + parser.getName()); |
| 2184 | XmlUtils.skipCurrentTag(parser); |
| 2185 | } |
| 2186 | } |
| 2187 | } |
| 2188 | |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 2189 | void writePermissionsLPr(XmlSerializer serializer, List<PermissionState> permissionStates) |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 2190 | throws IOException { |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 2191 | if (permissionStates.isEmpty()) { |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 2192 | return; |
| 2193 | } |
| 2194 | |
| 2195 | serializer.startTag(null, TAG_PERMISSIONS); |
| 2196 | |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 2197 | for (PermissionState permissionState : permissionStates) { |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 2198 | serializer.startTag(null, TAG_ITEM); |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 2199 | serializer.attribute(null, ATTR_NAME, permissionState.getName()); |
| 2200 | serializer.attribute(null, ATTR_GRANTED, String.valueOf(permissionState.isGranted())); |
| 2201 | serializer.attribute(null, ATTR_FLAGS, Integer.toHexString(permissionState.getFlags())); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 2202 | serializer.endTag(null, TAG_ITEM); |
| 2203 | } |
| 2204 | |
| 2205 | serializer.endTag(null, TAG_PERMISSIONS); |
| 2206 | } |
| 2207 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2208 | void writeChildPackagesLPw(XmlSerializer serializer, List<String> childPackageNames) |
| 2209 | throws IOException { |
| 2210 | if (childPackageNames == null) { |
| 2211 | return; |
| 2212 | } |
| 2213 | final int childCount = childPackageNames.size(); |
| 2214 | for (int i = 0; i < childCount; i++) { |
| 2215 | String childPackageName = childPackageNames.get(i); |
| 2216 | serializer.startTag(null, TAG_CHILD_PACKAGE); |
| 2217 | serializer.attribute(null, ATTR_NAME, childPackageName); |
| 2218 | serializer.endTag(null, TAG_CHILD_PACKAGE); |
| 2219 | } |
| 2220 | } |
| 2221 | |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 2222 | void readUsesStaticLibLPw(XmlPullParser parser, PackageSetting outPs) |
| 2223 | throws IOException, XmlPullParserException { |
| 2224 | int outerDepth = parser.getDepth(); |
| 2225 | int type; |
| 2226 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 2227 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 2228 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 2229 | continue; |
| 2230 | } |
| 2231 | String libName = parser.getAttributeValue(null, ATTR_NAME); |
| 2232 | String libVersionStr = parser.getAttributeValue(null, ATTR_VERSION); |
| 2233 | |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 2234 | long libVersion = -1; |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 2235 | try { |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 2236 | libVersion = Long.parseLong(libVersionStr); |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 2237 | } catch (NumberFormatException e) { |
| 2238 | // ignore |
| 2239 | } |
| 2240 | |
| 2241 | if (libName != null && libVersion >= 0) { |
| 2242 | outPs.usesStaticLibraries = ArrayUtils.appendElement(String.class, |
| 2243 | outPs.usesStaticLibraries, libName); |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 2244 | outPs.usesStaticLibrariesVersions = ArrayUtils.appendLong( |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 2245 | outPs.usesStaticLibrariesVersions, libVersion); |
| 2246 | } |
| 2247 | |
| 2248 | XmlUtils.skipCurrentTag(parser); |
| 2249 | } |
| 2250 | } |
| 2251 | |
| 2252 | void writeUsesStaticLibLPw(XmlSerializer serializer, String[] usesStaticLibraries, |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 2253 | long[] usesStaticLibraryVersions) throws IOException { |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 2254 | if (ArrayUtils.isEmpty(usesStaticLibraries) || ArrayUtils.isEmpty(usesStaticLibraryVersions) |
| 2255 | || usesStaticLibraries.length != usesStaticLibraryVersions.length) { |
| 2256 | return; |
| 2257 | } |
| 2258 | final int libCount = usesStaticLibraries.length; |
| 2259 | for (int i = 0; i < libCount; i++) { |
| 2260 | final String libName = usesStaticLibraries[i]; |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 2261 | final long libVersion = usesStaticLibraryVersions[i]; |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 2262 | serializer.startTag(null, TAG_USES_STATIC_LIB); |
| 2263 | serializer.attribute(null, ATTR_NAME, libName); |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 2264 | serializer.attribute(null, ATTR_VERSION, Long.toString(libVersion)); |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 2265 | serializer.endTag(null, TAG_USES_STATIC_LIB); |
| 2266 | } |
| 2267 | } |
| 2268 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2269 | // Note: assumed "stopped" field is already cleared in all packages. |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2270 | // 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] | 2271 | void readStoppedLPw() { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2272 | FileInputStream str = null; |
| 2273 | if (mBackupStoppedPackagesFilename.exists()) { |
| 2274 | try { |
| 2275 | str = new FileInputStream(mBackupStoppedPackagesFilename); |
| 2276 | mReadMessages.append("Reading from backup stopped packages file\n"); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2277 | PackageManagerService.reportSettingsProblem(Log.INFO, |
| 2278 | "Need to read from backup stopped packages file"); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2279 | if (mSettingsFilename.exists()) { |
| 2280 | // If both the backup and normal file exist, we |
| 2281 | // ignore the normal one since it might have been |
| 2282 | // corrupted. |
| 2283 | Slog.w(PackageManagerService.TAG, "Cleaning up stopped packages file " |
| 2284 | + mStoppedPackagesFilename); |
| 2285 | mStoppedPackagesFilename.delete(); |
| 2286 | } |
| 2287 | } catch (java.io.IOException e) { |
| 2288 | // We'll try for the normal settings file. |
| 2289 | } |
| 2290 | } |
| 2291 | |
| 2292 | try { |
| 2293 | if (str == null) { |
| 2294 | if (!mStoppedPackagesFilename.exists()) { |
| 2295 | mReadMessages.append("No stopped packages file found\n"); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2296 | PackageManagerService.reportSettingsProblem(Log.INFO, |
| 2297 | "No stopped packages file file; assuming all started"); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2298 | // At first boot, make sure no packages are stopped. |
| 2299 | // We usually want to have third party apps initialize |
| 2300 | // in the stopped state, but not at first boot. |
| 2301 | for (PackageSetting pkg : mPackages.values()) { |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2302 | pkg.setStopped(false, 0); |
| 2303 | pkg.setNotLaunched(false, 0); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2304 | } |
| 2305 | return; |
| 2306 | } |
| 2307 | str = new FileInputStream(mStoppedPackagesFilename); |
| 2308 | } |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 2309 | final XmlPullParser parser = Xml.newPullParser(); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2310 | parser.setInput(str, null); |
| 2311 | |
| 2312 | int type; |
| 2313 | while ((type=parser.next()) != XmlPullParser.START_TAG |
| 2314 | && type != XmlPullParser.END_DOCUMENT) { |
| 2315 | ; |
| 2316 | } |
| 2317 | |
| 2318 | if (type != XmlPullParser.START_TAG) { |
| 2319 | mReadMessages.append("No start tag found in stopped packages file\n"); |
| 2320 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 2321 | "No start tag found in package manager stopped packages"); |
| 2322 | return; |
| 2323 | } |
| 2324 | |
| 2325 | int outerDepth = parser.getDepth(); |
| 2326 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 2327 | && (type != XmlPullParser.END_TAG |
| 2328 | || parser.getDepth() > outerDepth)) { |
| 2329 | if (type == XmlPullParser.END_TAG |
| 2330 | || type == XmlPullParser.TEXT) { |
| 2331 | continue; |
| 2332 | } |
| 2333 | |
| 2334 | String tagName = parser.getName(); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2335 | if (tagName.equals(TAG_PACKAGE)) { |
| 2336 | String name = parser.getAttributeValue(null, ATTR_NAME); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2337 | PackageSetting ps = mPackages.get(name); |
| 2338 | if (ps != null) { |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2339 | ps.setStopped(true, 0); |
| 2340 | if ("1".equals(parser.getAttributeValue(null, ATTR_NOT_LAUNCHED))) { |
| 2341 | ps.setNotLaunched(true, 0); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2342 | } |
| 2343 | } else { |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2344 | Slog.w(PackageManagerService.TAG, |
Jeff Sharkey | e06b4d1 | 2016-01-06 14:51:50 -0700 | [diff] [blame] | 2345 | "No package known for stopped package " + name); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2346 | } |
| 2347 | XmlUtils.skipCurrentTag(parser); |
| 2348 | } else { |
| 2349 | Slog.w(PackageManagerService.TAG, "Unknown element under <stopped-packages>: " |
| 2350 | + parser.getName()); |
| 2351 | XmlUtils.skipCurrentTag(parser); |
| 2352 | } |
| 2353 | } |
| 2354 | |
| 2355 | str.close(); |
| 2356 | |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2357 | } catch (XmlPullParserException e) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2358 | mReadMessages.append("Error reading: " + e.toString()); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2359 | PackageManagerService.reportSettingsProblem(Log.ERROR, |
| 2360 | "Error reading stopped packages: " + e); |
Dianne Hackborn | 8d05172 | 2014-10-01 14:59:58 -0700 | [diff] [blame] | 2361 | Slog.wtf(PackageManagerService.TAG, "Error reading package manager stopped packages", |
| 2362 | e); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2363 | |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2364 | } catch (java.io.IOException e) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2365 | mReadMessages.append("Error reading: " + e.toString()); |
| 2366 | PackageManagerService.reportSettingsProblem(Log.ERROR, "Error reading settings: " + e); |
Dianne Hackborn | 8d05172 | 2014-10-01 14:59:58 -0700 | [diff] [blame] | 2367 | Slog.wtf(PackageManagerService.TAG, "Error reading package manager stopped packages", |
| 2368 | e); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2369 | |
| 2370 | } |
| 2371 | } |
| 2372 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 2373 | void writeLPr() { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2374 | //Debug.startMethodTracing("/data/system/packageprof", 8 * 1024 * 1024); |
| 2375 | |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 2376 | final long startTime = SystemClock.uptimeMillis(); |
| 2377 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2378 | // Keep the old settings around until we know the new ones have |
| 2379 | // been successfully written. |
| 2380 | if (mSettingsFilename.exists()) { |
| 2381 | // Presence of backup settings file indicates that we failed |
| 2382 | // to persist settings earlier. So preserve the older |
| 2383 | // backup for future reference since the current settings |
| 2384 | // might have been corrupted. |
| 2385 | if (!mBackupSettingsFilename.exists()) { |
| 2386 | if (!mSettingsFilename.renameTo(mBackupSettingsFilename)) { |
Dianne Hackborn | 8d05172 | 2014-10-01 14:59:58 -0700 | [diff] [blame] | 2387 | Slog.wtf(PackageManagerService.TAG, |
| 2388 | "Unable to backup package manager settings, " |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2389 | + " current changes will be lost at reboot"); |
| 2390 | return; |
| 2391 | } |
| 2392 | } else { |
| 2393 | mSettingsFilename.delete(); |
| 2394 | Slog.w(PackageManagerService.TAG, "Preserving older settings backup"); |
| 2395 | } |
| 2396 | } |
| 2397 | |
| 2398 | mPastSignatures.clear(); |
| 2399 | |
| 2400 | try { |
| 2401 | FileOutputStream fstr = new FileOutputStream(mSettingsFilename); |
| 2402 | BufferedOutputStream str = new BufferedOutputStream(fstr); |
| 2403 | |
| 2404 | //XmlSerializer serializer = XmlUtils.serializerInstance(); |
| 2405 | XmlSerializer serializer = new FastXmlSerializer(); |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 2406 | serializer.setOutput(str, StandardCharsets.UTF_8.name()); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2407 | serializer.startDocument(null, true); |
| 2408 | serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true); |
| 2409 | |
| 2410 | serializer.startTag(null, "packages"); |
| 2411 | |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 2412 | for (int i = 0; i < mVersion.size(); i++) { |
| 2413 | final String volumeUuid = mVersion.keyAt(i); |
| 2414 | final VersionInfo ver = mVersion.valueAt(i); |
Jeff Sharkey | edc84ee8 | 2012-03-19 16:52:26 -0700 | [diff] [blame] | 2415 | |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 2416 | serializer.startTag(null, TAG_VERSION); |
| 2417 | XmlUtils.writeStringAttribute(serializer, ATTR_VOLUME_UUID, volumeUuid); |
| 2418 | XmlUtils.writeIntAttribute(serializer, ATTR_SDK_VERSION, ver.sdkVersion); |
| 2419 | XmlUtils.writeIntAttribute(serializer, ATTR_DATABASE_VERSION, ver.databaseVersion); |
| 2420 | XmlUtils.writeStringAttribute(serializer, ATTR_FINGERPRINT, ver.fingerprint); |
| 2421 | serializer.endTag(null, TAG_VERSION); |
| 2422 | } |
Kenny Root | c1c0d3c | 2014-04-24 13:36:40 -0700 | [diff] [blame] | 2423 | |
Kenny Root | 0aaa0d9 | 2011-09-12 16:42:55 -0700 | [diff] [blame] | 2424 | if (mVerifierDeviceIdentity != null) { |
| 2425 | serializer.startTag(null, "verifier"); |
| 2426 | serializer.attribute(null, "device", mVerifierDeviceIdentity.toString()); |
| 2427 | serializer.endTag(null, "verifier"); |
| 2428 | } |
| 2429 | |
Jeff Sharkey | f538577 | 2012-05-11 14:04:41 -0700 | [diff] [blame] | 2430 | if (mReadExternalStorageEnforced != null) { |
Jeff Sharkey | edc84ee8 | 2012-03-19 16:52:26 -0700 | [diff] [blame] | 2431 | serializer.startTag(null, TAG_READ_EXTERNAL_STORAGE); |
| 2432 | serializer.attribute( |
Jeff Sharkey | 5d32e77 | 2012-04-12 15:59:23 -0700 | [diff] [blame] | 2433 | null, ATTR_ENFORCEMENT, mReadExternalStorageEnforced ? "1" : "0"); |
Jeff Sharkey | edc84ee8 | 2012-03-19 16:52:26 -0700 | [diff] [blame] | 2434 | serializer.endTag(null, TAG_READ_EXTERNAL_STORAGE); |
| 2435 | } |
| 2436 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2437 | serializer.startTag(null, "permission-trees"); |
Todd Kennedy | c842393 | 2017-10-05 08:58:36 -0700 | [diff] [blame] | 2438 | mPermissions.writePermissionTrees(serializer); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2439 | serializer.endTag(null, "permission-trees"); |
| 2440 | |
| 2441 | serializer.startTag(null, "permissions"); |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 2442 | mPermissions.writePermissions(serializer); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2443 | serializer.endTag(null, "permissions"); |
| 2444 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 2445 | for (final PackageSetting pkg : mPackages.values()) { |
| 2446 | writePackageLPr(serializer, pkg); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2447 | } |
| 2448 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 2449 | for (final PackageSetting pkg : mDisabledSysPackages.values()) { |
| 2450 | writeDisabledSysPackageLPr(serializer, pkg); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2451 | } |
| 2452 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 2453 | for (final SharedUserSetting usr : mSharedUsers.values()) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2454 | serializer.startTag(null, "shared-user"); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2455 | serializer.attribute(null, ATTR_NAME, usr.name); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2456 | serializer.attribute(null, "userId", |
| 2457 | Integer.toString(usr.userId)); |
| 2458 | usr.signatures.writeXml(serializer, "sigs", mPastSignatures); |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 2459 | writePermissionsLPr(serializer, usr.getPermissionsState() |
| 2460 | .getInstallPermissionStates()); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2461 | serializer.endTag(null, "shared-user"); |
| 2462 | } |
| 2463 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2464 | if (mRenamedPackages.size() > 0) { |
Andy McFadden | 2f36229 | 2012-01-20 14:43:38 -0800 | [diff] [blame] | 2465 | for (Map.Entry<String, String> e : mRenamedPackages.entrySet()) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2466 | serializer.startTag(null, "renamed-package"); |
| 2467 | serializer.attribute(null, "new", e.getKey()); |
| 2468 | serializer.attribute(null, "old", e.getValue()); |
| 2469 | serializer.endTag(null, "renamed-package"); |
| 2470 | } |
| 2471 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 2472 | |
Christopher Tate | 6038d15 | 2015-06-17 13:07:46 -0700 | [diff] [blame] | 2473 | final int numIVIs = mRestoredIntentFilterVerifications.size(); |
| 2474 | if (numIVIs > 0) { |
| 2475 | if (DEBUG_DOMAIN_VERIFICATION) { |
| 2476 | Slog.i(TAG, "Writing restored-ivi entries to packages.xml"); |
| 2477 | } |
| 2478 | serializer.startTag(null, "restored-ivi"); |
| 2479 | for (int i = 0; i < numIVIs; i++) { |
| 2480 | IntentFilterVerificationInfo ivi = mRestoredIntentFilterVerifications.valueAt(i); |
| 2481 | writeDomainVerificationsLPr(serializer, ivi); |
| 2482 | } |
| 2483 | serializer.endTag(null, "restored-ivi"); |
| 2484 | } else { |
| 2485 | if (DEBUG_DOMAIN_VERIFICATION) { |
| 2486 | Slog.i(TAG, " no restored IVI entries to write"); |
| 2487 | } |
| 2488 | } |
| 2489 | |
dcashman | 55b1078 | 2014-04-09 14:20:38 -0700 | [diff] [blame] | 2490 | mKeySetManagerService.writeKeySetManagerServiceLPr(serializer); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2491 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2492 | serializer.endTag(null, "packages"); |
| 2493 | |
| 2494 | serializer.endDocument(); |
| 2495 | |
| 2496 | str.flush(); |
| 2497 | FileUtils.sync(fstr); |
| 2498 | str.close(); |
| 2499 | |
| 2500 | // New settings successfully written, old ones are no longer |
| 2501 | // needed. |
| 2502 | mBackupSettingsFilename.delete(); |
| 2503 | FileUtils.setPermissions(mSettingsFilename.toString(), |
| 2504 | FileUtils.S_IRUSR|FileUtils.S_IWUSR |
Nick Kralevich | 70522ad | 2012-01-06 13:58:01 -0800 | [diff] [blame] | 2505 | |FileUtils.S_IRGRP|FileUtils.S_IWGRP, |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2506 | -1, -1); |
| 2507 | |
Jeff Sharkey | 2271ba3 | 2016-02-01 17:57:08 -0700 | [diff] [blame] | 2508 | writeKernelMappingLPr(); |
Jeff Sharkey | 91edde2 | 2015-05-20 12:04:42 -0700 | [diff] [blame] | 2509 | writePackageListLPr(); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2510 | writeAllUsersPackageRestrictionsLPr(); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 2511 | writeAllRuntimePermissionsLPr(); |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 2512 | com.android.internal.logging.EventLogTags.writeCommitSysConfigFile( |
| 2513 | "package", SystemClock.uptimeMillis() - startTime); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2514 | return; |
| 2515 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2516 | } catch(java.io.IOException e) { |
Dianne Hackborn | 8d05172 | 2014-10-01 14:59:58 -0700 | [diff] [blame] | 2517 | Slog.wtf(PackageManagerService.TAG, "Unable to write package manager settings, " |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2518 | + "current changes will be lost at reboot", e); |
| 2519 | } |
| 2520 | // Clean up partially written files |
| 2521 | if (mSettingsFilename.exists()) { |
| 2522 | if (!mSettingsFilename.delete()) { |
Dianne Hackborn | 8d05172 | 2014-10-01 14:59:58 -0700 | [diff] [blame] | 2523 | Slog.wtf(PackageManagerService.TAG, "Failed to clean up mangled file: " |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2524 | + mSettingsFilename); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2525 | } |
| 2526 | } |
| 2527 | //Debug.stopMethodTracing(); |
| 2528 | } |
| 2529 | |
Amith Yamasani | 23ab7f5 | 2017-01-22 17:43:24 -0800 | [diff] [blame] | 2530 | private void writeKernelRemoveUserLPr(int userId) { |
| 2531 | if (mKernelMappingFilename == null) return; |
| 2532 | |
| 2533 | File removeUserIdFile = new File(mKernelMappingFilename, "remove_userid"); |
| 2534 | if (DEBUG_KERNEL) Slog.d(TAG, "Writing " + userId + " to " + removeUserIdFile |
| 2535 | .getAbsolutePath()); |
| 2536 | writeIntToFile(removeUserIdFile, userId); |
| 2537 | } |
| 2538 | |
Jeff Sharkey | 2271ba3 | 2016-02-01 17:57:08 -0700 | [diff] [blame] | 2539 | void writeKernelMappingLPr() { |
| 2540 | if (mKernelMappingFilename == null) return; |
| 2541 | |
| 2542 | final String[] known = mKernelMappingFilename.list(); |
| 2543 | final ArraySet<String> knownSet = new ArraySet<>(known.length); |
| 2544 | for (String name : known) { |
| 2545 | knownSet.add(name); |
| 2546 | } |
| 2547 | |
| 2548 | for (final PackageSetting ps : mPackages.values()) { |
| 2549 | // Package is actively claimed |
| 2550 | knownSet.remove(ps.name); |
| 2551 | writeKernelMappingLPr(ps); |
| 2552 | } |
| 2553 | |
| 2554 | // Remove any unclaimed mappings |
| 2555 | for (int i = 0; i < knownSet.size(); i++) { |
| 2556 | final String name = knownSet.valueAt(i); |
| 2557 | if (DEBUG_KERNEL) Slog.d(TAG, "Dropping mapping " + name); |
| 2558 | |
| 2559 | mKernelMapping.remove(name); |
Jeff Sharkey | 800efcc | 2016-02-25 17:08:11 -0700 | [diff] [blame] | 2560 | new File(mKernelMappingFilename, name).delete(); |
Jeff Sharkey | 2271ba3 | 2016-02-01 17:57:08 -0700 | [diff] [blame] | 2561 | } |
| 2562 | } |
| 2563 | |
| 2564 | void writeKernelMappingLPr(PackageSetting ps) { |
Amith Yamasani | 23ab7f5 | 2017-01-22 17:43:24 -0800 | [diff] [blame] | 2565 | if (mKernelMappingFilename == null || ps == null || ps.name == null) return; |
Jeff Sharkey | 2271ba3 | 2016-02-01 17:57:08 -0700 | [diff] [blame] | 2566 | |
Sudheer Shanka | 12783cb | 2018-10-18 08:53:02 -0700 | [diff] [blame] | 2567 | writeKernelMappingLPr(ps.name, ps.appId, ps.getNotInstalledUserIds()); |
Sudheer Shanka | 12783cb | 2018-10-18 08:53:02 -0700 | [diff] [blame] | 2568 | } |
| 2569 | |
| 2570 | void writeKernelMappingLPr(String name, int appId, int[] excludedUserIds) { |
| 2571 | KernelPackageState cur = mKernelMapping.get(name); |
Amith Yamasani | 23ab7f5 | 2017-01-22 17:43:24 -0800 | [diff] [blame] | 2572 | final boolean firstTime = cur == null; |
Amith Yamasani | 23ab7f5 | 2017-01-22 17:43:24 -0800 | [diff] [blame] | 2573 | final boolean userIdsChanged = firstTime |
| 2574 | || !Arrays.equals(excludedUserIds, cur.excludedUserIds); |
| 2575 | |
| 2576 | // Package directory |
Sudheer Shanka | 12783cb | 2018-10-18 08:53:02 -0700 | [diff] [blame] | 2577 | final File dir = new File(mKernelMappingFilename, name); |
Amith Yamasani | 23ab7f5 | 2017-01-22 17:43:24 -0800 | [diff] [blame] | 2578 | |
| 2579 | if (firstTime) { |
| 2580 | dir.mkdir(); |
| 2581 | // Create a new mapping state |
| 2582 | cur = new KernelPackageState(); |
Sudheer Shanka | 12783cb | 2018-10-18 08:53:02 -0700 | [diff] [blame] | 2583 | mKernelMapping.put(name, cur); |
Jeff Sharkey | 2271ba3 | 2016-02-01 17:57:08 -0700 | [diff] [blame] | 2584 | } |
| 2585 | |
Amith Yamasani | 23ab7f5 | 2017-01-22 17:43:24 -0800 | [diff] [blame] | 2586 | // If mapping is incorrect or non-existent, write the appid file |
Sudheer Shanka | 12783cb | 2018-10-18 08:53:02 -0700 | [diff] [blame] | 2587 | if (cur.appId != appId) { |
Amith Yamasani | 23ab7f5 | 2017-01-22 17:43:24 -0800 | [diff] [blame] | 2588 | final File appIdFile = new File(dir, "appid"); |
Sudheer Shanka | 12783cb | 2018-10-18 08:53:02 -0700 | [diff] [blame] | 2589 | writeIntToFile(appIdFile, appId); |
| 2590 | if (DEBUG_KERNEL) Slog.d(TAG, "Mapping " + name + " to " + appId); |
Amith Yamasani | 23ab7f5 | 2017-01-22 17:43:24 -0800 | [diff] [blame] | 2591 | } |
Jeff Sharkey | 2271ba3 | 2016-02-01 17:57:08 -0700 | [diff] [blame] | 2592 | |
Amith Yamasani | 23ab7f5 | 2017-01-22 17:43:24 -0800 | [diff] [blame] | 2593 | if (userIdsChanged) { |
| 2594 | // Build the exclusion list -- the ids to add to the exclusion list |
| 2595 | for (int i = 0; i < excludedUserIds.length; i++) { |
| 2596 | if (cur.excludedUserIds == null || !ArrayUtils.contains(cur.excludedUserIds, |
| 2597 | excludedUserIds[i])) { |
| 2598 | writeIntToFile(new File(dir, "excluded_userids"), excludedUserIds[i]); |
| 2599 | if (DEBUG_KERNEL) Slog.d(TAG, "Writing " + excludedUserIds[i] + " to " |
Sudheer Shanka | 12783cb | 2018-10-18 08:53:02 -0700 | [diff] [blame] | 2600 | + name + "/excluded_userids"); |
Amith Yamasani | 23ab7f5 | 2017-01-22 17:43:24 -0800 | [diff] [blame] | 2601 | } |
| 2602 | } |
| 2603 | // Build the inclusion list -- the ids to remove from the exclusion list |
| 2604 | if (cur.excludedUserIds != null) { |
| 2605 | for (int i = 0; i < cur.excludedUserIds.length; i++) { |
| 2606 | if (!ArrayUtils.contains(excludedUserIds, cur.excludedUserIds[i])) { |
| 2607 | writeIntToFile(new File(dir, "clear_userid"), |
| 2608 | cur.excludedUserIds[i]); |
| 2609 | if (DEBUG_KERNEL) Slog.d(TAG, "Writing " + cur.excludedUserIds[i] + " to " |
Sudheer Shanka | 12783cb | 2018-10-18 08:53:02 -0700 | [diff] [blame] | 2610 | + name + "/clear_userid"); |
Jeff Sharkey | 2271ba3 | 2016-02-01 17:57:08 -0700 | [diff] [blame] | 2611 | |
Amith Yamasani | 23ab7f5 | 2017-01-22 17:43:24 -0800 | [diff] [blame] | 2612 | } |
| 2613 | } |
| 2614 | } |
| 2615 | cur.excludedUserIds = excludedUserIds; |
| 2616 | } |
| 2617 | } |
| 2618 | |
| 2619 | private void writeIntToFile(File file, int value) { |
Jeff Sharkey | 2271ba3 | 2016-02-01 17:57:08 -0700 | [diff] [blame] | 2620 | try { |
Narayan Kamath | 6d051fc | 2016-11-22 20:20:00 +0000 | [diff] [blame] | 2621 | FileUtils.bytesToFile(file.getAbsolutePath(), |
Amith Yamasani | 23ab7f5 | 2017-01-22 17:43:24 -0800 | [diff] [blame] | 2622 | Integer.toString(value).getBytes(StandardCharsets.US_ASCII)); |
Jeff Sharkey | 2271ba3 | 2016-02-01 17:57:08 -0700 | [diff] [blame] | 2623 | } catch (IOException ignored) { |
Amith Yamasani | 23ab7f5 | 2017-01-22 17:43:24 -0800 | [diff] [blame] | 2624 | Slog.w(TAG, "Couldn't write " + value + " to " + file.getAbsolutePath()); |
Jeff Sharkey | 2271ba3 | 2016-02-01 17:57:08 -0700 | [diff] [blame] | 2625 | } |
| 2626 | } |
| 2627 | |
Jeff Sharkey | 91edde2 | 2015-05-20 12:04:42 -0700 | [diff] [blame] | 2628 | void writePackageListLPr() { |
| 2629 | writePackageListLPr(-1); |
| 2630 | } |
| 2631 | |
| 2632 | void writePackageListLPr(int creatingUserId) { |
Florian Mayer | d4db997 | 2019-03-21 13:57:42 +0000 | [diff] [blame] | 2633 | String filename = mPackageListFilename.getAbsolutePath(); |
| 2634 | String ctx = SELinux.fileSelabelLookup(filename); |
| 2635 | if (ctx == null) { |
| 2636 | Slog.wtf(TAG, "Failed to get SELinux context for " + |
| 2637 | mPackageListFilename.getAbsolutePath()); |
| 2638 | } |
| 2639 | |
| 2640 | if (!SELinux.setFSCreateContext(ctx)) { |
| 2641 | Slog.wtf(TAG, "Failed to set packages.list SELinux context"); |
| 2642 | } |
| 2643 | try { |
| 2644 | writePackageListLPrInternal(creatingUserId); |
| 2645 | } finally { |
| 2646 | SELinux.setFSCreateContext(null); |
| 2647 | } |
| 2648 | } |
| 2649 | |
| 2650 | private void writePackageListLPrInternal(int creatingUserId) { |
Jeff Sharkey | 91edde2 | 2015-05-20 12:04:42 -0700 | [diff] [blame] | 2651 | // Only derive GIDs for active users (not dying) |
Amith Yamasani | e744669 | 2019-04-19 13:39:51 -0700 | [diff] [blame] | 2652 | final List<UserInfo> users = getUsers(UserManagerService.getInstance(), true); |
Jeff Sharkey | 91edde2 | 2015-05-20 12:04:42 -0700 | [diff] [blame] | 2653 | int[] userIds = new int[users.size()]; |
| 2654 | for (int i = 0; i < userIds.length; i++) { |
| 2655 | userIds[i] = users.get(i).id; |
| 2656 | } |
| 2657 | if (creatingUserId != -1) { |
| 2658 | userIds = ArrayUtils.appendInt(userIds, creatingUserId); |
| 2659 | } |
| 2660 | |
| 2661 | // Write package list file now, use a JournaledFile. |
| 2662 | File tempFile = new File(mPackageListFilename.getAbsolutePath() + ".tmp"); |
| 2663 | JournaledFile journal = new JournaledFile(mPackageListFilename, tempFile); |
| 2664 | |
| 2665 | final File writeTarget = journal.chooseForWrite(); |
Fyodor Kupolov | b69056b | 2015-12-18 15:20:00 -0800 | [diff] [blame] | 2666 | FileOutputStream fstr; |
| 2667 | BufferedWriter writer = null; |
Jeff Sharkey | 91edde2 | 2015-05-20 12:04:42 -0700 | [diff] [blame] | 2668 | try { |
| 2669 | fstr = new FileOutputStream(writeTarget); |
Fyodor Kupolov | b69056b | 2015-12-18 15:20:00 -0800 | [diff] [blame] | 2670 | writer = new BufferedWriter(new OutputStreamWriter(fstr, Charset.defaultCharset())); |
Jeff Sharkey | 91edde2 | 2015-05-20 12:04:42 -0700 | [diff] [blame] | 2671 | FileUtils.setPermissions(fstr.getFD(), 0640, SYSTEM_UID, PACKAGE_INFO_GID); |
| 2672 | |
| 2673 | StringBuilder sb = new StringBuilder(); |
| 2674 | for (final PackageSetting pkg : mPackages.values()) { |
Jeff Sharkey | e17ac15 | 2015-11-06 22:40:29 -0800 | [diff] [blame] | 2675 | if (pkg.pkg == null || pkg.pkg.applicationInfo == null |
| 2676 | || pkg.pkg.applicationInfo.dataDir == null) { |
Jeff Sharkey | 2271ba3 | 2016-02-01 17:57:08 -0700 | [diff] [blame] | 2677 | if (!"android".equals(pkg.name)) { |
| 2678 | Slog.w(TAG, "Skipping " + pkg + " due to missing metadata"); |
| 2679 | } |
Jeff Sharkey | 91edde2 | 2015-05-20 12:04:42 -0700 | [diff] [blame] | 2680 | continue; |
| 2681 | } |
| 2682 | |
| 2683 | final ApplicationInfo ai = pkg.pkg.applicationInfo; |
Jeff Sharkey | e84bdd3 | 2016-02-08 12:16:00 -0700 | [diff] [blame] | 2684 | final String dataPath = ai.dataDir; |
Jeff Sharkey | 91edde2 | 2015-05-20 12:04:42 -0700 | [diff] [blame] | 2685 | final boolean isDebug = (ai.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0; |
| 2686 | final int[] gids = pkg.getPermissionsState().computeGids(userIds); |
| 2687 | |
| 2688 | // Avoid any application that has a space in its path. |
Fyodor Kupolov | b69056b | 2015-12-18 15:20:00 -0800 | [diff] [blame] | 2689 | if (dataPath.indexOf(' ') >= 0) |
Jeff Sharkey | 91edde2 | 2015-05-20 12:04:42 -0700 | [diff] [blame] | 2690 | continue; |
| 2691 | |
| 2692 | // we store on each line the following information for now: |
| 2693 | // |
| 2694 | // pkgName - package name |
| 2695 | // userId - application-specific user id |
| 2696 | // debugFlag - 0 or 1 if the package is debuggable. |
| 2697 | // dataPath - path to package's data path |
| 2698 | // seinfo - seinfo label for the app (assigned at install time) |
| 2699 | // gids - supplementary gids this app launches with |
Yabin Cui | 1ced4ce | 2019-01-10 23:23:00 +0000 | [diff] [blame] | 2700 | // profileableFromShellFlag - 0 or 1 if the package is profileable from shell. |
Florian Mayer | aedbca8 | 2019-01-28 14:40:34 +0000 | [diff] [blame] | 2701 | // longVersionCode - integer version of the package. |
Jeff Sharkey | 91edde2 | 2015-05-20 12:04:42 -0700 | [diff] [blame] | 2702 | // |
| 2703 | // NOTE: We prefer not to expose all ApplicationInfo flags for now. |
| 2704 | // |
| 2705 | // DO NOT MODIFY THIS FORMAT UNLESS YOU CAN ALSO MODIFY ITS USERS |
| 2706 | // FROM NATIVE CODE. AT THE MOMENT, LOOK AT THE FOLLOWING SOURCES: |
Yabin Cui | 1ced4ce | 2019-01-10 23:23:00 +0000 | [diff] [blame] | 2707 | // system/core/libpackagelistparser |
Jeff Sharkey | 91edde2 | 2015-05-20 12:04:42 -0700 | [diff] [blame] | 2708 | // |
| 2709 | sb.setLength(0); |
| 2710 | sb.append(ai.packageName); |
| 2711 | sb.append(" "); |
Fyodor Kupolov | b69056b | 2015-12-18 15:20:00 -0800 | [diff] [blame] | 2712 | sb.append(ai.uid); |
Jeff Sharkey | 91edde2 | 2015-05-20 12:04:42 -0700 | [diff] [blame] | 2713 | sb.append(isDebug ? " 1 " : " 0 "); |
| 2714 | sb.append(dataPath); |
| 2715 | sb.append(" "); |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 2716 | sb.append(ai.seInfo); |
Jeff Sharkey | 91edde2 | 2015-05-20 12:04:42 -0700 | [diff] [blame] | 2717 | sb.append(" "); |
| 2718 | if (gids != null && gids.length > 0) { |
| 2719 | sb.append(gids[0]); |
| 2720 | for (int i = 1; i < gids.length; i++) { |
| 2721 | sb.append(","); |
| 2722 | sb.append(gids[i]); |
| 2723 | } |
| 2724 | } else { |
| 2725 | sb.append("none"); |
| 2726 | } |
Yabin Cui | 1ced4ce | 2019-01-10 23:23:00 +0000 | [diff] [blame] | 2727 | sb.append(" "); |
| 2728 | sb.append(ai.isProfileableByShell() ? "1" : "0"); |
Florian Mayer | aedbca8 | 2019-01-28 14:40:34 +0000 | [diff] [blame] | 2729 | sb.append(" "); |
| 2730 | sb.append(String.valueOf(ai.longVersionCode)); |
Jeff Sharkey | 91edde2 | 2015-05-20 12:04:42 -0700 | [diff] [blame] | 2731 | sb.append("\n"); |
Fyodor Kupolov | b69056b | 2015-12-18 15:20:00 -0800 | [diff] [blame] | 2732 | writer.append(sb); |
Jeff Sharkey | 91edde2 | 2015-05-20 12:04:42 -0700 | [diff] [blame] | 2733 | } |
Fyodor Kupolov | b69056b | 2015-12-18 15:20:00 -0800 | [diff] [blame] | 2734 | writer.flush(); |
Jeff Sharkey | 91edde2 | 2015-05-20 12:04:42 -0700 | [diff] [blame] | 2735 | FileUtils.sync(fstr); |
Fyodor Kupolov | b69056b | 2015-12-18 15:20:00 -0800 | [diff] [blame] | 2736 | writer.close(); |
Jeff Sharkey | 91edde2 | 2015-05-20 12:04:42 -0700 | [diff] [blame] | 2737 | journal.commit(); |
| 2738 | } catch (Exception e) { |
| 2739 | Slog.wtf(TAG, "Failed to write packages.list", e); |
Fyodor Kupolov | b69056b | 2015-12-18 15:20:00 -0800 | [diff] [blame] | 2740 | IoUtils.closeQuietly(writer); |
Jeff Sharkey | 91edde2 | 2015-05-20 12:04:42 -0700 | [diff] [blame] | 2741 | journal.rollback(); |
| 2742 | } |
| 2743 | } |
| 2744 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 2745 | void writeDisabledSysPackageLPr(XmlSerializer serializer, final PackageSetting pkg) |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2746 | throws java.io.IOException { |
| 2747 | serializer.startTag(null, "updated-package"); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2748 | serializer.attribute(null, ATTR_NAME, pkg.name); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2749 | if (pkg.realName != null) { |
| 2750 | serializer.attribute(null, "realName", pkg.realName); |
| 2751 | } |
| 2752 | serializer.attribute(null, "codePath", pkg.codePathString); |
| 2753 | serializer.attribute(null, "ft", Long.toHexString(pkg.timeStamp)); |
| 2754 | serializer.attribute(null, "it", Long.toHexString(pkg.firstInstallTime)); |
| 2755 | serializer.attribute(null, "ut", Long.toHexString(pkg.lastUpdateTime)); |
| 2756 | serializer.attribute(null, "version", String.valueOf(pkg.versionCode)); |
| 2757 | if (!pkg.resourcePathString.equals(pkg.codePathString)) { |
| 2758 | serializer.attribute(null, "resourcePath", pkg.resourcePathString); |
| 2759 | } |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 2760 | if (pkg.legacyNativeLibraryPathString != null) { |
| 2761 | serializer.attribute(null, "nativeLibraryPath", pkg.legacyNativeLibraryPathString); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2762 | } |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 2763 | if (pkg.primaryCpuAbiString != null) { |
| 2764 | serializer.attribute(null, "primaryCpuAbi", pkg.primaryCpuAbiString); |
Narayan Kamath | 9e289d7 | 2014-04-10 09:26:59 +0000 | [diff] [blame] | 2765 | } |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 2766 | if (pkg.secondaryCpuAbiString != null) { |
| 2767 | serializer.attribute(null, "secondaryCpuAbi", pkg.secondaryCpuAbiString); |
| 2768 | } |
Narayan Kamath | 4903f64 | 2014-08-11 13:33:45 +0100 | [diff] [blame] | 2769 | if (pkg.cpuAbiOverrideString != null) { |
| 2770 | serializer.attribute(null, "cpuAbiOverride", pkg.cpuAbiOverrideString); |
| 2771 | } |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 2772 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2773 | if (pkg.sharedUser == null) { |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 2774 | serializer.attribute(null, "userId", Integer.toString(pkg.appId)); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2775 | } else { |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 2776 | serializer.attribute(null, "sharedUserId", Integer.toString(pkg.appId)); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2777 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 2778 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2779 | if (pkg.parentPackageName != null) { |
| 2780 | serializer.attribute(null, "parentPackageName", pkg.parentPackageName); |
| 2781 | } |
| 2782 | |
| 2783 | writeChildPackagesLPw(serializer, pkg.childPackageNames); |
| 2784 | |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 2785 | writeUsesStaticLibLPw(serializer, pkg.usesStaticLibraries, pkg.usesStaticLibrariesVersions); |
| 2786 | |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 2787 | // If this is a shared user, the permissions will be written there. |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2788 | if (pkg.sharedUser == null) { |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 2789 | writePermissionsLPr(serializer, pkg.getPermissionsState() |
| 2790 | .getInstallPermissionStates()); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2791 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 2792 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2793 | serializer.endTag(null, "updated-package"); |
| 2794 | } |
| 2795 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 2796 | void writePackageLPr(XmlSerializer serializer, final PackageSetting pkg) |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2797 | throws java.io.IOException { |
| 2798 | serializer.startTag(null, "package"); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2799 | serializer.attribute(null, ATTR_NAME, pkg.name); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2800 | if (pkg.realName != null) { |
| 2801 | serializer.attribute(null, "realName", pkg.realName); |
| 2802 | } |
| 2803 | serializer.attribute(null, "codePath", pkg.codePathString); |
| 2804 | if (!pkg.resourcePathString.equals(pkg.codePathString)) { |
| 2805 | serializer.attribute(null, "resourcePath", pkg.resourcePathString); |
| 2806 | } |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 2807 | |
| 2808 | if (pkg.legacyNativeLibraryPathString != null) { |
| 2809 | serializer.attribute(null, "nativeLibraryPath", pkg.legacyNativeLibraryPathString); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2810 | } |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 2811 | if (pkg.primaryCpuAbiString != null) { |
| 2812 | serializer.attribute(null, "primaryCpuAbi", pkg.primaryCpuAbiString); |
Narayan Kamath | 9e289d7 | 2014-04-10 09:26:59 +0000 | [diff] [blame] | 2813 | } |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 2814 | if (pkg.secondaryCpuAbiString != null) { |
| 2815 | serializer.attribute(null, "secondaryCpuAbi", pkg.secondaryCpuAbiString); |
| 2816 | } |
Narayan Kamath | 4903f64 | 2014-08-11 13:33:45 +0100 | [diff] [blame] | 2817 | if (pkg.cpuAbiOverrideString != null) { |
| 2818 | serializer.attribute(null, "cpuAbiOverride", pkg.cpuAbiOverrideString); |
| 2819 | } |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 2820 | |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 2821 | serializer.attribute(null, "publicFlags", Integer.toString(pkg.pkgFlags)); |
| 2822 | serializer.attribute(null, "privateFlags", Integer.toString(pkg.pkgPrivateFlags)); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2823 | serializer.attribute(null, "ft", Long.toHexString(pkg.timeStamp)); |
| 2824 | serializer.attribute(null, "it", Long.toHexString(pkg.firstInstallTime)); |
| 2825 | serializer.attribute(null, "ut", Long.toHexString(pkg.lastUpdateTime)); |
| 2826 | serializer.attribute(null, "version", String.valueOf(pkg.versionCode)); |
| 2827 | if (pkg.sharedUser == null) { |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 2828 | serializer.attribute(null, "userId", Integer.toString(pkg.appId)); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2829 | } else { |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 2830 | serializer.attribute(null, "sharedUserId", Integer.toString(pkg.appId)); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2831 | } |
| 2832 | if (pkg.uidError) { |
| 2833 | serializer.attribute(null, "uidError", "true"); |
| 2834 | } |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2835 | if (pkg.installerPackageName != null) { |
| 2836 | serializer.attribute(null, "installer", pkg.installerPackageName); |
| 2837 | } |
Sudheer Shanka | 8c57aea | 2016-04-20 16:47:50 -0700 | [diff] [blame] | 2838 | if (pkg.isOrphaned) { |
| 2839 | serializer.attribute(null, "isOrphaned", "true"); |
| 2840 | } |
Jeff Sharkey | b2b9ab8 | 2015-04-05 21:10:42 -0700 | [diff] [blame] | 2841 | if (pkg.volumeUuid != null) { |
| 2842 | serializer.attribute(null, "volumeUuid", pkg.volumeUuid); |
| 2843 | } |
Jeff Sharkey | 9bc89af | 2017-01-11 11:25:50 -0700 | [diff] [blame] | 2844 | if (pkg.categoryHint != ApplicationInfo.CATEGORY_UNDEFINED) { |
| 2845 | serializer.attribute(null, "categoryHint", |
| 2846 | Integer.toString(pkg.categoryHint)); |
| 2847 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2848 | if (pkg.parentPackageName != null) { |
| 2849 | serializer.attribute(null, "parentPackageName", pkg.parentPackageName); |
| 2850 | } |
Todd Kennedy | ab53289 | 2017-03-08 14:19:49 -0800 | [diff] [blame] | 2851 | if (pkg.updateAvailable) { |
| 2852 | serializer.attribute(null, "updateAvailable", "true"); |
| 2853 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2854 | |
| 2855 | writeChildPackagesLPw(serializer, pkg.childPackageNames); |
| 2856 | |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 2857 | writeUsesStaticLibLPw(serializer, pkg.usesStaticLibraries, pkg.usesStaticLibrariesVersions); |
| 2858 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2859 | pkg.signatures.writeXml(serializer, "sigs", mPastSignatures); |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 2860 | |
| 2861 | writePermissionsLPr(serializer, pkg.getPermissionsState() |
| 2862 | .getInstallPermissionStates()); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2863 | |
dcashman | 8c04fac | 2015-03-23 11:39:42 -0700 | [diff] [blame] | 2864 | writeSigningKeySetLPr(serializer, pkg.keySetData); |
dcashman | 55b1078 | 2014-04-09 14:20:38 -0700 | [diff] [blame] | 2865 | writeUpgradeKeySetsLPr(serializer, pkg.keySetData); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2866 | writeKeySetAliasesLPr(serializer, pkg.keySetData); |
Fabrice Di Meglio | 6227172 | 2015-04-10 17:24:02 -0700 | [diff] [blame] | 2867 | writeDomainVerificationsLPr(serializer, pkg.verificationInfo); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2868 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2869 | serializer.endTag(null, "package"); |
| 2870 | } |
| 2871 | |
dcashman | 8c04fac | 2015-03-23 11:39:42 -0700 | [diff] [blame] | 2872 | void writeSigningKeySetLPr(XmlSerializer serializer, |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2873 | PackageKeySetData data) throws IOException { |
dcashman | 8c04fac | 2015-03-23 11:39:42 -0700 | [diff] [blame] | 2874 | serializer.startTag(null, "proper-signing-keyset"); |
| 2875 | serializer.attribute(null, "identifier", |
| 2876 | Long.toString(data.getProperSigningKeySet())); |
| 2877 | serializer.endTag(null, "proper-signing-keyset"); |
dcashman | 55b1078 | 2014-04-09 14:20:38 -0700 | [diff] [blame] | 2878 | } |
| 2879 | |
| 2880 | void writeUpgradeKeySetsLPr(XmlSerializer serializer, |
| 2881 | PackageKeySetData data) throws IOException { |
| 2882 | if (data.isUsingUpgradeKeySets()) { |
| 2883 | for (long id : data.getUpgradeKeySets()) { |
| 2884 | serializer.startTag(null, "upgrade-keyset"); |
| 2885 | serializer.attribute(null, "identifier", Long.toString(id)); |
| 2886 | serializer.endTag(null, "upgrade-keyset"); |
| 2887 | } |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2888 | } |
| 2889 | } |
| 2890 | |
| 2891 | void writeKeySetAliasesLPr(XmlSerializer serializer, |
| 2892 | PackageKeySetData data) throws IOException { |
| 2893 | for (Map.Entry<String, Long> e: data.getAliases().entrySet()) { |
| 2894 | serializer.startTag(null, "defined-keyset"); |
| 2895 | serializer.attribute(null, "alias", e.getKey()); |
| 2896 | serializer.attribute(null, "identifier", Long.toString(e.getValue())); |
| 2897 | serializer.endTag(null, "defined-keyset"); |
| 2898 | } |
| 2899 | } |
| 2900 | |
Todd Kennedy | 91a39d1 | 2017-09-27 12:37:04 -0700 | [diff] [blame] | 2901 | void writePermissionLPr(XmlSerializer serializer, BasePermission bp) throws IOException { |
| 2902 | bp.writeLPr(serializer); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2903 | } |
| 2904 | |
Xiaohui Chen | 594f208 | 2015-08-18 11:04:20 -0700 | [diff] [blame] | 2905 | boolean readLPw(@NonNull List<UserInfo> users) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2906 | FileInputStream str = null; |
| 2907 | if (mBackupSettingsFilename.exists()) { |
| 2908 | try { |
| 2909 | str = new FileInputStream(mBackupSettingsFilename); |
| 2910 | mReadMessages.append("Reading from backup settings file\n"); |
| 2911 | PackageManagerService.reportSettingsProblem(Log.INFO, |
| 2912 | "Need to read from backup settings file"); |
| 2913 | if (mSettingsFilename.exists()) { |
| 2914 | // If both the backup and settings file exist, we |
| 2915 | // ignore the settings since it might have been |
| 2916 | // corrupted. |
| 2917 | Slog.w(PackageManagerService.TAG, "Cleaning up settings file " |
| 2918 | + mSettingsFilename); |
| 2919 | mSettingsFilename.delete(); |
| 2920 | } |
| 2921 | } catch (java.io.IOException e) { |
| 2922 | // We'll try for the normal settings file. |
| 2923 | } |
| 2924 | } |
| 2925 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 2926 | mPendingPackages.clear(); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2927 | mPastSignatures.clear(); |
dcashman | 8c04fac | 2015-03-23 11:39:42 -0700 | [diff] [blame] | 2928 | mKeySetRefs.clear(); |
Sudheer Shanka | 2928337 | 2016-04-04 20:56:27 -0700 | [diff] [blame] | 2929 | mInstallerPackages.clear(); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2930 | |
| 2931 | try { |
| 2932 | if (str == null) { |
| 2933 | if (!mSettingsFilename.exists()) { |
| 2934 | mReadMessages.append("No settings file found\n"); |
| 2935 | PackageManagerService.reportSettingsProblem(Log.INFO, |
| 2936 | "No settings file; creating initial state"); |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 2937 | // It's enough to just touch version details to create them |
| 2938 | // with default values |
longhai | bc62b21 | 2016-01-29 14:22:22 +0800 | [diff] [blame] | 2939 | findOrCreateVersion(StorageManager.UUID_PRIVATE_INTERNAL).forceCurrent(); |
| 2940 | findOrCreateVersion(StorageManager.UUID_PRIMARY_PHYSICAL).forceCurrent(); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2941 | return false; |
| 2942 | } |
| 2943 | str = new FileInputStream(mSettingsFilename); |
| 2944 | } |
| 2945 | XmlPullParser parser = Xml.newPullParser(); |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 2946 | parser.setInput(str, StandardCharsets.UTF_8.name()); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2947 | |
| 2948 | int type; |
| 2949 | while ((type = parser.next()) != XmlPullParser.START_TAG |
| 2950 | && type != XmlPullParser.END_DOCUMENT) { |
| 2951 | ; |
| 2952 | } |
| 2953 | |
| 2954 | if (type != XmlPullParser.START_TAG) { |
| 2955 | mReadMessages.append("No start tag found in settings file\n"); |
| 2956 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 2957 | "No start tag found in package manager settings"); |
Dianne Hackborn | 8d05172 | 2014-10-01 14:59:58 -0700 | [diff] [blame] | 2958 | Slog.wtf(PackageManagerService.TAG, |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 2959 | "No start tag found in package manager settings"); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2960 | return false; |
| 2961 | } |
| 2962 | |
| 2963 | int outerDepth = parser.getDepth(); |
| 2964 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 2965 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 2966 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 2967 | continue; |
| 2968 | } |
| 2969 | |
| 2970 | String tagName = parser.getName(); |
| 2971 | if (tagName.equals("package")) { |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 2972 | readPackageLPw(parser); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2973 | } else if (tagName.equals("permissions")) { |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 2974 | mPermissions.readPermissions(parser); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2975 | } else if (tagName.equals("permission-trees")) { |
Todd Kennedy | c842393 | 2017-10-05 08:58:36 -0700 | [diff] [blame] | 2976 | mPermissions.readPermissionTrees(parser); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2977 | } else if (tagName.equals("shared-user")) { |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 2978 | readSharedUserLPw(parser); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2979 | } else if (tagName.equals("preferred-packages")) { |
| 2980 | // no longer used. |
| 2981 | } else if (tagName.equals("preferred-activities")) { |
Dianne Hackborn | 6309271 | 2012-10-07 14:45:35 -0700 | [diff] [blame] | 2982 | // Upgrading from old single-user implementation; |
| 2983 | // these are the preferred activities for user 0. |
| 2984 | readPreferredActivitiesLPw(parser, 0); |
Sander Alewijnse | af59762 | 2014-03-20 18:44:57 +0000 | [diff] [blame] | 2985 | } else if (tagName.equals(TAG_PERSISTENT_PREFERRED_ACTIVITIES)) { |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 2986 | // TODO: check whether this is okay! as it is very |
| 2987 | // similar to how preferred-activities are treated |
| 2988 | readPersistentPreferredActivitiesLPw(parser, 0); |
Nicolas Prevot | 29762c3 | 2014-07-29 18:51:32 +0100 | [diff] [blame] | 2989 | } else if (tagName.equals(TAG_CROSS_PROFILE_INTENT_FILTERS)) { |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 2990 | // TODO: check whether this is okay! as it is very |
| 2991 | // similar to how preferred-activities are treated |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 2992 | readCrossProfileIntentFiltersLPw(parser, 0); |
Fabrice Di Meglio | 6227172 | 2015-04-10 17:24:02 -0700 | [diff] [blame] | 2993 | } else if (tagName.equals(TAG_DEFAULT_BROWSER)) { |
| 2994 | readDefaultAppsLPw(parser, 0); |
| 2995 | } else if (tagName.equals("updated-package")) { |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 2996 | readDisabledSysPackageLPw(parser); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2997 | } else if (tagName.equals("renamed-package")) { |
| 2998 | String nname = parser.getAttributeValue(null, "new"); |
| 2999 | String oname = parser.getAttributeValue(null, "old"); |
| 3000 | if (nname != null && oname != null) { |
| 3001 | mRenamedPackages.put(nname, oname); |
| 3002 | } |
Christopher Tate | 6038d15 | 2015-06-17 13:07:46 -0700 | [diff] [blame] | 3003 | } else if (tagName.equals("restored-ivi")) { |
| 3004 | readRestoredIntentFilterVerifications(parser); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3005 | } else if (tagName.equals("last-platform-version")) { |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 3006 | // Upgrade from older XML schema |
| 3007 | final VersionInfo internal = findOrCreateVersion( |
| 3008 | StorageManager.UUID_PRIVATE_INTERNAL); |
| 3009 | final VersionInfo external = findOrCreateVersion( |
| 3010 | StorageManager.UUID_PRIMARY_PHYSICAL); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 3011 | |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 3012 | internal.sdkVersion = XmlUtils.readIntAttribute(parser, "internal", 0); |
| 3013 | external.sdkVersion = XmlUtils.readIntAttribute(parser, "external", 0); |
| 3014 | internal.fingerprint = external.fingerprint = |
| 3015 | XmlUtils.readStringAttribute(parser, "fingerprint"); |
| 3016 | |
Kenny Root | c1c0d3c | 2014-04-24 13:36:40 -0700 | [diff] [blame] | 3017 | } else if (tagName.equals("database-version")) { |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 3018 | // Upgrade from older XML schema |
| 3019 | final VersionInfo internal = findOrCreateVersion( |
| 3020 | StorageManager.UUID_PRIVATE_INTERNAL); |
| 3021 | final VersionInfo external = findOrCreateVersion( |
| 3022 | StorageManager.UUID_PRIMARY_PHYSICAL); |
| 3023 | |
| 3024 | internal.databaseVersion = XmlUtils.readIntAttribute(parser, "internal", 0); |
| 3025 | external.databaseVersion = XmlUtils.readIntAttribute(parser, "external", 0); |
| 3026 | |
Kenny Root | 0aaa0d9 | 2011-09-12 16:42:55 -0700 | [diff] [blame] | 3027 | } else if (tagName.equals("verifier")) { |
| 3028 | final String deviceIdentity = parser.getAttributeValue(null, "device"); |
| 3029 | try { |
| 3030 | mVerifierDeviceIdentity = VerifierDeviceIdentity.parse(deviceIdentity); |
| 3031 | } catch (IllegalArgumentException e) { |
| 3032 | Slog.w(PackageManagerService.TAG, "Discard invalid verifier device id: " |
| 3033 | + e.getMessage()); |
| 3034 | } |
Jeff Sharkey | edc84ee8 | 2012-03-19 16:52:26 -0700 | [diff] [blame] | 3035 | } else if (TAG_READ_EXTERNAL_STORAGE.equals(tagName)) { |
| 3036 | final String enforcement = parser.getAttributeValue(null, ATTR_ENFORCEMENT); |
Todd Kennedy | 91a39d1 | 2017-09-27 12:37:04 -0700 | [diff] [blame] | 3037 | mReadExternalStorageEnforced = |
| 3038 | "1".equals(enforcement) ? Boolean.TRUE : Boolean.FALSE; |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 3039 | } else if (tagName.equals("keyset-settings")) { |
dcashman | 8c04fac | 2015-03-23 11:39:42 -0700 | [diff] [blame] | 3040 | mKeySetManagerService.readKeySetsLPw(parser, mKeySetRefs); |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 3041 | } else if (TAG_VERSION.equals(tagName)) { |
| 3042 | final String volumeUuid = XmlUtils.readStringAttribute(parser, |
| 3043 | ATTR_VOLUME_UUID); |
| 3044 | final VersionInfo ver = findOrCreateVersion(volumeUuid); |
| 3045 | ver.sdkVersion = XmlUtils.readIntAttribute(parser, ATTR_SDK_VERSION); |
khmel | 80bdce0 | 2018-01-02 16:39:05 -0800 | [diff] [blame] | 3046 | ver.databaseVersion = XmlUtils.readIntAttribute(parser, ATTR_DATABASE_VERSION); |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 3047 | ver.fingerprint = XmlUtils.readStringAttribute(parser, ATTR_FINGERPRINT); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3048 | } else { |
| 3049 | Slog.w(PackageManagerService.TAG, "Unknown element under <packages>: " |
| 3050 | + parser.getName()); |
| 3051 | XmlUtils.skipCurrentTag(parser); |
| 3052 | } |
| 3053 | } |
| 3054 | |
| 3055 | str.close(); |
| 3056 | |
| 3057 | } catch (XmlPullParserException e) { |
| 3058 | mReadMessages.append("Error reading: " + e.toString()); |
| 3059 | PackageManagerService.reportSettingsProblem(Log.ERROR, "Error reading settings: " + e); |
Dianne Hackborn | 8d05172 | 2014-10-01 14:59:58 -0700 | [diff] [blame] | 3060 | Slog.wtf(PackageManagerService.TAG, "Error reading package manager settings", e); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3061 | |
| 3062 | } catch (java.io.IOException e) { |
| 3063 | mReadMessages.append("Error reading: " + e.toString()); |
| 3064 | PackageManagerService.reportSettingsProblem(Log.ERROR, "Error reading settings: " + e); |
Dianne Hackborn | 8d05172 | 2014-10-01 14:59:58 -0700 | [diff] [blame] | 3065 | Slog.wtf(PackageManagerService.TAG, "Error reading package manager settings", e); |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 3066 | } |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3067 | |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 3068 | // If the build is setup to drop runtime permissions |
| 3069 | // on update drop the files before loading them. |
| 3070 | if (PackageManagerService.CLEAR_RUNTIME_PERMISSIONS_ON_UPGRADE) { |
| 3071 | final VersionInfo internal = getInternalVersion(); |
| 3072 | if (!Build.FINGERPRINT.equals(internal.fingerprint)) { |
Xiaohui Chen | 594f208 | 2015-08-18 11:04:20 -0700 | [diff] [blame] | 3073 | for (UserInfo user : users) { |
| 3074 | mRuntimePermissionsPersistence.deleteUserRuntimePermissionsFile(user.id); |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 3075 | } |
| 3076 | } |
| 3077 | } |
| 3078 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3079 | final int N = mPendingPackages.size(); |
dcashman | 8c04fac | 2015-03-23 11:39:42 -0700 | [diff] [blame] | 3080 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3081 | for (int i = 0; i < N; i++) { |
Todd Kennedy | 788c842 | 2016-08-10 10:52:34 -0700 | [diff] [blame] | 3082 | final PackageSetting p = mPendingPackages.get(i); |
| 3083 | final int sharedUserId = p.getSharedUserId(); |
Patrick Baumann | 649a857 | 2018-11-20 11:16:58 -0800 | [diff] [blame] | 3084 | final Object idObj = getSettingLPr(sharedUserId); |
Todd Kennedy | 788c842 | 2016-08-10 10:52:34 -0700 | [diff] [blame] | 3085 | if (idObj instanceof SharedUserSetting) { |
| 3086 | final SharedUserSetting sharedUser = (SharedUserSetting) idObj; |
| 3087 | p.sharedUser = sharedUser; |
| 3088 | p.appId = sharedUser.userId; |
| 3089 | addPackageSettingLPw(p, sharedUser); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3090 | } else if (idObj != null) { |
Todd Kennedy | 788c842 | 2016-08-10 10:52:34 -0700 | [diff] [blame] | 3091 | String msg = "Bad package setting: package " + p.name + " has shared uid " |
| 3092 | + sharedUserId + " that is not a shared uid\n"; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3093 | mReadMessages.append(msg); |
| 3094 | PackageManagerService.reportSettingsProblem(Log.ERROR, msg); |
| 3095 | } else { |
Todd Kennedy | 788c842 | 2016-08-10 10:52:34 -0700 | [diff] [blame] | 3096 | String msg = "Bad package setting: package " + p.name + " has shared uid " |
| 3097 | + sharedUserId + " that is not defined\n"; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3098 | mReadMessages.append(msg); |
| 3099 | PackageManagerService.reportSettingsProblem(Log.ERROR, msg); |
| 3100 | } |
| 3101 | } |
| 3102 | mPendingPackages.clear(); |
| 3103 | |
Amith Yamasani | f031f23 | 2012-10-26 15:35:21 -0700 | [diff] [blame] | 3104 | if (mBackupStoppedPackagesFilename.exists() |
| 3105 | || mStoppedPackagesFilename.exists()) { |
| 3106 | // Read old file |
| 3107 | readStoppedLPw(); |
| 3108 | mBackupStoppedPackagesFilename.delete(); |
| 3109 | mStoppedPackagesFilename.delete(); |
| 3110 | // Migrate to new file format |
Xiaohui Chen | 594f208 | 2015-08-18 11:04:20 -0700 | [diff] [blame] | 3111 | writePackageRestrictionsLPr(UserHandle.USER_SYSTEM); |
Amith Yamasani | f031f23 | 2012-10-26 15:35:21 -0700 | [diff] [blame] | 3112 | } else { |
Xiaohui Chen | 594f208 | 2015-08-18 11:04:20 -0700 | [diff] [blame] | 3113 | for (UserInfo user : users) { |
| 3114 | readPackageRestrictionsLPr(user.id); |
Amith Yamasani | f031f23 | 2012-10-26 15:35:21 -0700 | [diff] [blame] | 3115 | } |
| 3116 | } |
| 3117 | |
Xiaohui Chen | 594f208 | 2015-08-18 11:04:20 -0700 | [diff] [blame] | 3118 | for (UserInfo user : users) { |
| 3119 | mRuntimePermissionsPersistence.readStateForUserSyncLPr(user.id); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 3120 | } |
| 3121 | |
Kenny Root | 1d1b489 | 2011-04-08 14:25:24 -0700 | [diff] [blame] | 3122 | /* |
| 3123 | * Make sure all the updated system packages have their shared users |
| 3124 | * associated with them. |
| 3125 | */ |
| 3126 | final Iterator<PackageSetting> disabledIt = mDisabledSysPackages.values().iterator(); |
| 3127 | while (disabledIt.hasNext()) { |
| 3128 | final PackageSetting disabledPs = disabledIt.next(); |
Patrick Baumann | 649a857 | 2018-11-20 11:16:58 -0800 | [diff] [blame] | 3129 | final Object id = getSettingLPr(disabledPs.appId); |
Kenny Root | 1d1b489 | 2011-04-08 14:25:24 -0700 | [diff] [blame] | 3130 | if (id != null && id instanceof SharedUserSetting) { |
| 3131 | disabledPs.sharedUser = (SharedUserSetting) id; |
| 3132 | } |
| 3133 | } |
| 3134 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3135 | mReadMessages.append("Read completed successfully: " + mPackages.size() + " packages, " |
| 3136 | + mSharedUsers.size() + " shared uids\n"); |
| 3137 | |
Jeff Sharkey | 2271ba3 | 2016-02-01 17:57:08 -0700 | [diff] [blame] | 3138 | writeKernelMappingLPr(); |
| 3139 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3140 | return true; |
| 3141 | } |
| 3142 | |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 3143 | void applyDefaultPreferredAppsLPw(int userId) { |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3144 | // First pull data from any pre-installed apps. |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 3145 | final PackageManagerInternal pmInternal = |
| 3146 | LocalServices.getService(PackageManagerInternal.class); |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3147 | for (PackageSetting ps : mPackages.values()) { |
| 3148 | if ((ps.pkgFlags&ApplicationInfo.FLAG_SYSTEM) != 0 && ps.pkg != null |
| 3149 | && ps.pkg.preferredActivityFilters != null) { |
| 3150 | ArrayList<PackageParser.ActivityIntentInfo> intents |
| 3151 | = ps.pkg.preferredActivityFilters; |
| 3152 | for (int i=0; i<intents.size(); i++) { |
| 3153 | PackageParser.ActivityIntentInfo aii = intents.get(i); |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 3154 | applyDefaultPreferredActivityLPw(pmInternal, aii, new ComponentName( |
| 3155 | ps.name, aii.activity.className), userId); |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3156 | } |
| 3157 | } |
| 3158 | } |
| 3159 | |
Dianne Hackborn | fc8b7fe | 2012-06-18 15:38:12 -0700 | [diff] [blame] | 3160 | // Read preferred apps from .../etc/preferred-apps directory. |
| 3161 | File preferredDir = new File(Environment.getRootDirectory(), "etc/preferred-apps"); |
| 3162 | if (!preferredDir.exists() || !preferredDir.isDirectory()) { |
| 3163 | return; |
| 3164 | } |
| 3165 | if (!preferredDir.canRead()) { |
| 3166 | Slog.w(TAG, "Directory " + preferredDir + " cannot be read"); |
| 3167 | return; |
| 3168 | } |
| 3169 | |
| 3170 | // Iterate over the files in the directory and scan .xml files |
| 3171 | for (File f : preferredDir.listFiles()) { |
| 3172 | if (!f.getPath().endsWith(".xml")) { |
| 3173 | Slog.i(TAG, "Non-xml file " + f + " in " + preferredDir + " directory, ignoring"); |
| 3174 | continue; |
| 3175 | } |
| 3176 | if (!f.canRead()) { |
| 3177 | Slog.w(TAG, "Preferred apps file " + f + " cannot be read"); |
| 3178 | continue; |
| 3179 | } |
| 3180 | |
Dianne Hackborn | 8a2ed1d | 2013-01-29 15:18:29 -0800 | [diff] [blame] | 3181 | if (PackageManagerService.DEBUG_PREFERRED) Log.d(TAG, "Reading default preferred " + f); |
Fyodor Kupolov | b35b34c | 2015-12-17 14:16:51 -0800 | [diff] [blame] | 3182 | InputStream str = null; |
Dianne Hackborn | fc8b7fe | 2012-06-18 15:38:12 -0700 | [diff] [blame] | 3183 | try { |
Fyodor Kupolov | b35b34c | 2015-12-17 14:16:51 -0800 | [diff] [blame] | 3184 | str = new BufferedInputStream(new FileInputStream(f)); |
Dianne Hackborn | fc8b7fe | 2012-06-18 15:38:12 -0700 | [diff] [blame] | 3185 | XmlPullParser parser = Xml.newPullParser(); |
| 3186 | parser.setInput(str, null); |
| 3187 | |
| 3188 | int type; |
| 3189 | while ((type = parser.next()) != XmlPullParser.START_TAG |
| 3190 | && type != XmlPullParser.END_DOCUMENT) { |
| 3191 | ; |
| 3192 | } |
| 3193 | |
| 3194 | if (type != XmlPullParser.START_TAG) { |
| 3195 | Slog.w(TAG, "Preferred apps file " + f + " does not have start tag"); |
| 3196 | continue; |
| 3197 | } |
| 3198 | if (!"preferred-activities".equals(parser.getName())) { |
| 3199 | Slog.w(TAG, "Preferred apps file " + f |
| 3200 | + " does not start with 'preferred-activities'"); |
| 3201 | continue; |
| 3202 | } |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 3203 | readDefaultPreferredActivitiesLPw(parser, userId); |
Dianne Hackborn | fc8b7fe | 2012-06-18 15:38:12 -0700 | [diff] [blame] | 3204 | } catch (XmlPullParserException e) { |
| 3205 | Slog.w(TAG, "Error reading apps file " + f, e); |
| 3206 | } catch (IOException e) { |
| 3207 | Slog.w(TAG, "Error reading apps file " + f, e); |
| 3208 | } finally { |
| 3209 | if (str != null) { |
| 3210 | try { |
| 3211 | str.close(); |
| 3212 | } catch (IOException e) { |
| 3213 | } |
| 3214 | } |
| 3215 | } |
| 3216 | } |
| 3217 | } |
| 3218 | |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 3219 | private void applyDefaultPreferredActivityLPw( |
| 3220 | PackageManagerInternal pmInternal, IntentFilter tmpPa, ComponentName cn, int userId) { |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3221 | // The initial preferences only specify the target activity |
| 3222 | // component and intent-filter, not the set of matches. So we |
| 3223 | // now need to query for the matches to build the correct |
| 3224 | // preferred activity entry. |
| 3225 | if (PackageManagerService.DEBUG_PREFERRED) { |
| 3226 | Log.d(TAG, "Processing preferred:"); |
| 3227 | tmpPa.dump(new LogPrinter(Log.DEBUG, TAG), " "); |
| 3228 | } |
| 3229 | Intent intent = new Intent(); |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 3230 | int flags = PackageManager.MATCH_DIRECT_BOOT_AWARE |
| 3231 | | PackageManager.MATCH_DIRECT_BOOT_UNAWARE; |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3232 | intent.setAction(tmpPa.getAction(0)); |
| 3233 | for (int i=0; i<tmpPa.countCategories(); i++) { |
| 3234 | String cat = tmpPa.getCategory(i); |
| 3235 | if (cat.equals(Intent.CATEGORY_DEFAULT)) { |
Jeff Sharkey | 2a90f673 | 2016-01-06 12:26:11 -0700 | [diff] [blame] | 3236 | flags |= MATCH_DEFAULT_ONLY; |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3237 | } else { |
| 3238 | intent.addCategory(cat); |
| 3239 | } |
| 3240 | } |
| 3241 | |
| 3242 | boolean doNonData = true; |
Christopher Tate | 2298ef2 | 2013-11-04 17:02:10 -0800 | [diff] [blame] | 3243 | boolean hasSchemes = false; |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3244 | |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 3245 | final int dataSchemesCount = tmpPa.countDataSchemes(); |
| 3246 | for (int ischeme = 0; ischeme < dataSchemesCount; ischeme++) { |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3247 | boolean doScheme = true; |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 3248 | final String scheme = tmpPa.getDataScheme(ischeme); |
Christopher Tate | 2298ef2 | 2013-11-04 17:02:10 -0800 | [diff] [blame] | 3249 | if (scheme != null && !scheme.isEmpty()) { |
| 3250 | hasSchemes = true; |
| 3251 | } |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 3252 | final int dataSchemeSpecificPartsCount = tmpPa.countDataSchemeSpecificParts(); |
| 3253 | for (int issp = 0; issp < dataSchemeSpecificPartsCount; issp++) { |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3254 | Uri.Builder builder = new Uri.Builder(); |
| 3255 | builder.scheme(scheme); |
| 3256 | PatternMatcher ssp = tmpPa.getDataSchemeSpecificPart(issp); |
| 3257 | builder.opaquePart(ssp.getPath()); |
| 3258 | Intent finalIntent = new Intent(intent); |
| 3259 | finalIntent.setData(builder.build()); |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 3260 | applyDefaultPreferredActivityLPw(pmInternal, finalIntent, flags, cn, |
Dianne Hackborn | eeb2c7e | 2014-09-23 16:45:39 -0700 | [diff] [blame] | 3261 | scheme, ssp, null, null, userId); |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3262 | doScheme = false; |
| 3263 | } |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 3264 | final int dataAuthoritiesCount = tmpPa.countDataAuthorities(); |
| 3265 | for (int iauth = 0; iauth < dataAuthoritiesCount; iauth++) { |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3266 | boolean doAuth = true; |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 3267 | final IntentFilter.AuthorityEntry auth = tmpPa.getDataAuthority(iauth); |
| 3268 | final int dataPathsCount = tmpPa.countDataPaths(); |
| 3269 | for (int ipath = 0; ipath < dataPathsCount; ipath++) { |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3270 | Uri.Builder builder = new Uri.Builder(); |
| 3271 | builder.scheme(scheme); |
| 3272 | if (auth.getHost() != null) { |
| 3273 | builder.authority(auth.getHost()); |
| 3274 | } |
| 3275 | PatternMatcher path = tmpPa.getDataPath(ipath); |
| 3276 | builder.path(path.getPath()); |
| 3277 | Intent finalIntent = new Intent(intent); |
| 3278 | finalIntent.setData(builder.build()); |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 3279 | applyDefaultPreferredActivityLPw(pmInternal, finalIntent, flags, cn, |
Dianne Hackborn | eeb2c7e | 2014-09-23 16:45:39 -0700 | [diff] [blame] | 3280 | scheme, null, auth, path, userId); |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3281 | doAuth = doScheme = false; |
| 3282 | } |
| 3283 | if (doAuth) { |
| 3284 | Uri.Builder builder = new Uri.Builder(); |
| 3285 | builder.scheme(scheme); |
| 3286 | if (auth.getHost() != null) { |
| 3287 | builder.authority(auth.getHost()); |
| 3288 | } |
| 3289 | Intent finalIntent = new Intent(intent); |
| 3290 | finalIntent.setData(builder.build()); |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 3291 | applyDefaultPreferredActivityLPw(pmInternal, finalIntent, flags, cn, |
Dianne Hackborn | eeb2c7e | 2014-09-23 16:45:39 -0700 | [diff] [blame] | 3292 | scheme, null, auth, null, userId); |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3293 | doScheme = false; |
| 3294 | } |
| 3295 | } |
| 3296 | if (doScheme) { |
| 3297 | Uri.Builder builder = new Uri.Builder(); |
| 3298 | builder.scheme(scheme); |
| 3299 | Intent finalIntent = new Intent(intent); |
| 3300 | finalIntent.setData(builder.build()); |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 3301 | applyDefaultPreferredActivityLPw(pmInternal, finalIntent, flags, cn, |
Dianne Hackborn | eeb2c7e | 2014-09-23 16:45:39 -0700 | [diff] [blame] | 3302 | scheme, null, null, null, userId); |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3303 | } |
| 3304 | doNonData = false; |
| 3305 | } |
| 3306 | |
| 3307 | for (int idata=0; idata<tmpPa.countDataTypes(); idata++) { |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3308 | String mimeType = tmpPa.getDataType(idata); |
Christopher Tate | 2298ef2 | 2013-11-04 17:02:10 -0800 | [diff] [blame] | 3309 | if (hasSchemes) { |
| 3310 | Uri.Builder builder = new Uri.Builder(); |
| 3311 | for (int ischeme=0; ischeme<tmpPa.countDataSchemes(); ischeme++) { |
| 3312 | String scheme = tmpPa.getDataScheme(ischeme); |
| 3313 | if (scheme != null && !scheme.isEmpty()) { |
| 3314 | Intent finalIntent = new Intent(intent); |
| 3315 | builder.scheme(scheme); |
| 3316 | finalIntent.setDataAndType(builder.build(), mimeType); |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 3317 | applyDefaultPreferredActivityLPw(pmInternal, finalIntent, flags, cn, |
Dianne Hackborn | eeb2c7e | 2014-09-23 16:45:39 -0700 | [diff] [blame] | 3318 | scheme, null, null, null, userId); |
Christopher Tate | 2298ef2 | 2013-11-04 17:02:10 -0800 | [diff] [blame] | 3319 | } |
| 3320 | } |
| 3321 | } else { |
| 3322 | Intent finalIntent = new Intent(intent); |
| 3323 | finalIntent.setType(mimeType); |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 3324 | applyDefaultPreferredActivityLPw(pmInternal, finalIntent, flags, cn, |
Dianne Hackborn | eeb2c7e | 2014-09-23 16:45:39 -0700 | [diff] [blame] | 3325 | null, null, null, null, userId); |
Christopher Tate | 2298ef2 | 2013-11-04 17:02:10 -0800 | [diff] [blame] | 3326 | } |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3327 | doNonData = false; |
| 3328 | } |
| 3329 | |
| 3330 | if (doNonData) { |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 3331 | applyDefaultPreferredActivityLPw(pmInternal, intent, flags, cn, |
Dianne Hackborn | eeb2c7e | 2014-09-23 16:45:39 -0700 | [diff] [blame] | 3332 | null, null, null, null, userId); |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3333 | } |
| 3334 | } |
| 3335 | |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 3336 | private void applyDefaultPreferredActivityLPw(PackageManagerInternal pmInternal, Intent intent, |
| 3337 | int flags, ComponentName cn, String scheme, PatternMatcher ssp, |
Dianne Hackborn | eeb2c7e | 2014-09-23 16:45:39 -0700 | [diff] [blame] | 3338 | IntentFilter.AuthorityEntry auth, PatternMatcher path, int userId) { |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 3339 | final List<ResolveInfo> ri = |
Patrick Baumann | 3fa8853 | 2019-11-18 13:43:11 -0800 | [diff] [blame] | 3340 | pmInternal.queryIntentActivities( |
| 3341 | intent, intent.getType(), flags, Binder.getCallingUid(), 0); |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 3342 | if (PackageManagerService.DEBUG_PREFERRED) { |
| 3343 | Log.d(TAG, "Queried " + intent + " results: " + ri); |
| 3344 | } |
Dianne Hackborn | f85e7af | 2014-10-14 10:43:43 -0700 | [diff] [blame] | 3345 | int systemMatch = 0; |
| 3346 | int thirdPartyMatch = 0; |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 3347 | final int numMatches = (ri == null ? 0 : ri.size()); |
| 3348 | if (numMatches <= 1) { |
| 3349 | Slog.w(TAG, "No potential matches found for " + intent |
| 3350 | + " while setting preferred " + cn.flattenToShortString()); |
| 3351 | return; |
| 3352 | } |
| 3353 | boolean haveAct = false; |
| 3354 | ComponentName haveNonSys = null; |
| 3355 | ComponentName[] set = new ComponentName[ri.size()]; |
| 3356 | for (int i = 0; i < numMatches; i++) { |
| 3357 | final ActivityInfo ai = ri.get(i).activityInfo; |
| 3358 | set[i] = new ComponentName(ai.packageName, ai.name); |
| 3359 | if ((ai.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) { |
| 3360 | if (ri.get(i).match >= thirdPartyMatch) { |
| 3361 | // Keep track of the best match we find of all third |
| 3362 | // party apps, for use later to determine if we actually |
| 3363 | // want to set a preferred app for this intent. |
| 3364 | if (PackageManagerService.DEBUG_PREFERRED) { |
| 3365 | Log.d(TAG, "Result " + ai.packageName + "/" + ai.name + ": non-system!"); |
Dianne Hackborn | eeb2c7e | 2014-09-23 16:45:39 -0700 | [diff] [blame] | 3366 | } |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 3367 | haveNonSys = set[i]; |
| 3368 | break; |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3369 | } |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 3370 | } else if (cn.getPackageName().equals(ai.packageName) |
| 3371 | && cn.getClassName().equals(ai.name)) { |
| 3372 | if (PackageManagerService.DEBUG_PREFERRED) { |
| 3373 | Log.d(TAG, "Result " + ai.packageName + "/" + ai.name + ": default!"); |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3374 | } |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 3375 | haveAct = true; |
| 3376 | systemMatch = ri.get(i).match; |
Dianne Hackborn | eeb2c7e | 2014-09-23 16:45:39 -0700 | [diff] [blame] | 3377 | } else { |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 3378 | if (PackageManagerService.DEBUG_PREFERRED) { |
| 3379 | Log.d(TAG, "Result " + ai.packageName + "/" + ai.name + ": skipped"); |
| 3380 | } |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3381 | } |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 3382 | } |
| 3383 | if (haveNonSys != null && thirdPartyMatch < systemMatch) { |
| 3384 | // If we have a matching third party app, but its match is not as |
| 3385 | // good as the built-in system app, then we don't want to actually |
| 3386 | // consider it a match because presumably the built-in app is still |
| 3387 | // the thing we want users to see by default. |
| 3388 | haveNonSys = null; |
| 3389 | } |
| 3390 | if (haveAct && haveNonSys == null) { |
| 3391 | IntentFilter filter = new IntentFilter(); |
| 3392 | if (intent.getAction() != null) { |
| 3393 | filter.addAction(intent.getAction()); |
| 3394 | } |
| 3395 | if (intent.getCategories() != null) { |
| 3396 | for (String cat : intent.getCategories()) { |
| 3397 | filter.addCategory(cat); |
| 3398 | } |
| 3399 | } |
| 3400 | if ((flags & MATCH_DEFAULT_ONLY) != 0) { |
| 3401 | filter.addCategory(Intent.CATEGORY_DEFAULT); |
| 3402 | } |
| 3403 | if (scheme != null) { |
| 3404 | filter.addDataScheme(scheme); |
| 3405 | } |
| 3406 | if (ssp != null) { |
| 3407 | filter.addDataSchemeSpecificPart(ssp.getPath(), ssp.getType()); |
| 3408 | } |
| 3409 | if (auth != null) { |
| 3410 | filter.addDataAuthority(auth); |
| 3411 | } |
| 3412 | if (path != null) { |
| 3413 | filter.addDataPath(path); |
| 3414 | } |
| 3415 | if (intent.getType() != null) { |
| 3416 | try { |
| 3417 | filter.addDataType(intent.getType()); |
| 3418 | } catch (IntentFilter.MalformedMimeTypeException ex) { |
| 3419 | Slog.w(TAG, "Malformed mimetype " + intent.getType() + " for " + cn); |
| 3420 | } |
| 3421 | } |
| 3422 | PreferredActivity pa = new PreferredActivity(filter, systemMatch, set, cn, true); |
| 3423 | editPreferredActivitiesLPw(userId).addFilter(pa); |
| 3424 | } else if (haveNonSys == null) { |
| 3425 | StringBuilder sb = new StringBuilder(); |
| 3426 | sb.append("No component "); |
| 3427 | sb.append(cn.flattenToShortString()); |
| 3428 | sb.append(" found setting preferred "); |
| 3429 | sb.append(intent); |
| 3430 | sb.append("; possible matches are "); |
| 3431 | for (int i = 0; i < set.length; i++) { |
| 3432 | if (i > 0) sb.append(", "); |
| 3433 | sb.append(set[i].flattenToShortString()); |
| 3434 | } |
| 3435 | Slog.w(TAG, sb.toString()); |
Dianne Hackborn | eeb2c7e | 2014-09-23 16:45:39 -0700 | [diff] [blame] | 3436 | } else { |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 3437 | Slog.i(TAG, "Not setting preferred " + intent + "; found third party match " |
| 3438 | + haveNonSys.flattenToShortString()); |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3439 | } |
| 3440 | } |
| 3441 | |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 3442 | private void readDefaultPreferredActivitiesLPw(XmlPullParser parser, int userId) |
Dianne Hackborn | 8a2ed1d | 2013-01-29 15:18:29 -0800 | [diff] [blame] | 3443 | throws XmlPullParserException, IOException { |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 3444 | final PackageManagerInternal pmInternal = |
| 3445 | LocalServices.getService(PackageManagerInternal.class); |
Dianne Hackborn | 8a2ed1d | 2013-01-29 15:18:29 -0800 | [diff] [blame] | 3446 | int outerDepth = parser.getDepth(); |
| 3447 | int type; |
| 3448 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 3449 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 3450 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 3451 | continue; |
| 3452 | } |
| 3453 | |
| 3454 | String tagName = parser.getName(); |
| 3455 | if (tagName.equals(TAG_ITEM)) { |
| 3456 | PreferredActivity tmpPa = new PreferredActivity(parser); |
| 3457 | if (tmpPa.mPref.getParseError() == null) { |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 3458 | applyDefaultPreferredActivityLPw( |
| 3459 | pmInternal, tmpPa, tmpPa.mPref.mComponent, userId); |
Dianne Hackborn | 8a2ed1d | 2013-01-29 15:18:29 -0800 | [diff] [blame] | 3460 | } else { |
| 3461 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 3462 | "Error in package manager settings: <preferred-activity> " |
| 3463 | + tmpPa.mPref.getParseError() + " at " |
| 3464 | + parser.getPositionDescription()); |
| 3465 | } |
| 3466 | } else { |
| 3467 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 3468 | "Unknown element under <preferred-activities>: " + parser.getName()); |
| 3469 | XmlUtils.skipCurrentTag(parser); |
| 3470 | } |
| 3471 | } |
| 3472 | } |
| 3473 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 3474 | private void readDisabledSysPackageLPw(XmlPullParser parser) throws XmlPullParserException, |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3475 | IOException { |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 3476 | String name = parser.getAttributeValue(null, ATTR_NAME); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3477 | String realName = parser.getAttributeValue(null, "realName"); |
| 3478 | String codePathStr = parser.getAttributeValue(null, "codePath"); |
| 3479 | String resourcePathStr = parser.getAttributeValue(null, "resourcePath"); |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 3480 | |
| 3481 | String legacyCpuAbiStr = parser.getAttributeValue(null, "requiredCpuAbi"); |
| 3482 | String legacyNativeLibraryPathStr = parser.getAttributeValue(null, "nativeLibraryPath"); |
| 3483 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3484 | String parentPackageName = parser.getAttributeValue(null, "parentPackageName"); |
| 3485 | |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 3486 | String primaryCpuAbiStr = parser.getAttributeValue(null, "primaryCpuAbi"); |
| 3487 | String secondaryCpuAbiStr = parser.getAttributeValue(null, "secondaryCpuAbi"); |
Narayan Kamath | 4903f64 | 2014-08-11 13:33:45 +0100 | [diff] [blame] | 3488 | String cpuAbiOverrideStr = parser.getAttributeValue(null, "cpuAbiOverride"); |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 3489 | |
| 3490 | if (primaryCpuAbiStr == null && legacyCpuAbiStr != null) { |
| 3491 | primaryCpuAbiStr = legacyCpuAbiStr; |
| 3492 | } |
Narayan Kamath | 9e289d7 | 2014-04-10 09:26:59 +0000 | [diff] [blame] | 3493 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3494 | if (resourcePathStr == null) { |
| 3495 | resourcePathStr = codePathStr; |
| 3496 | } |
| 3497 | String version = parser.getAttributeValue(null, "version"); |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 3498 | long versionCode = 0; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3499 | if (version != null) { |
| 3500 | try { |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 3501 | versionCode = Long.parseLong(version); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3502 | } catch (NumberFormatException e) { |
| 3503 | } |
| 3504 | } |
| 3505 | |
| 3506 | int pkgFlags = 0; |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 3507 | int pkgPrivateFlags = 0; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3508 | pkgFlags |= ApplicationInfo.FLAG_SYSTEM; |
Dario Freni | 787471a | 2019-10-22 14:14:00 +0100 | [diff] [blame] | 3509 | if (codePathStr.contains("/priv-app/")) { |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 3510 | pkgPrivateFlags |= ApplicationInfo.PRIVATE_FLAG_PRIVILEGED; |
Christopher Tate | 628946a | 2013-10-18 18:11:05 -0700 | [diff] [blame] | 3511 | } |
Todd Kennedy | ddaaf4c | 2017-11-07 10:01:25 -0800 | [diff] [blame] | 3512 | PackageSetting ps = new PackageSetting(name, realName, new File(codePathStr), |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 3513 | new File(resourcePathStr), legacyNativeLibraryPathStr, primaryCpuAbiStr, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3514 | secondaryCpuAbiStr, cpuAbiOverrideStr, versionCode, pkgFlags, pkgPrivateFlags, |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 3515 | parentPackageName, null /*childPackageNames*/, 0 /*sharedUserId*/, null, null); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3516 | String timeStampStr = parser.getAttributeValue(null, "ft"); |
| 3517 | if (timeStampStr != null) { |
| 3518 | try { |
| 3519 | long timeStamp = Long.parseLong(timeStampStr, 16); |
| 3520 | ps.setTimeStamp(timeStamp); |
| 3521 | } catch (NumberFormatException e) { |
| 3522 | } |
| 3523 | } else { |
| 3524 | timeStampStr = parser.getAttributeValue(null, "ts"); |
| 3525 | if (timeStampStr != null) { |
| 3526 | try { |
| 3527 | long timeStamp = Long.parseLong(timeStampStr); |
| 3528 | ps.setTimeStamp(timeStamp); |
| 3529 | } catch (NumberFormatException e) { |
| 3530 | } |
| 3531 | } |
| 3532 | } |
| 3533 | timeStampStr = parser.getAttributeValue(null, "it"); |
| 3534 | if (timeStampStr != null) { |
| 3535 | try { |
| 3536 | ps.firstInstallTime = Long.parseLong(timeStampStr, 16); |
| 3537 | } catch (NumberFormatException e) { |
| 3538 | } |
| 3539 | } |
| 3540 | timeStampStr = parser.getAttributeValue(null, "ut"); |
| 3541 | if (timeStampStr != null) { |
| 3542 | try { |
| 3543 | ps.lastUpdateTime = Long.parseLong(timeStampStr, 16); |
| 3544 | } catch (NumberFormatException e) { |
| 3545 | } |
| 3546 | } |
| 3547 | String idStr = parser.getAttributeValue(null, "userId"); |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 3548 | ps.appId = idStr != null ? Integer.parseInt(idStr) : 0; |
| 3549 | if (ps.appId <= 0) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3550 | String sharedIdStr = parser.getAttributeValue(null, "sharedUserId"); |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 3551 | ps.appId = sharedIdStr != null ? Integer.parseInt(sharedIdStr) : 0; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3552 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 3553 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3554 | int outerDepth = parser.getDepth(); |
| 3555 | int type; |
| 3556 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 3557 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 3558 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 3559 | continue; |
| 3560 | } |
| 3561 | |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 3562 | if (parser.getName().equals(TAG_PERMISSIONS)) { |
| 3563 | readInstallPermissionsLPr(parser, ps.getPermissionsState()); |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3564 | } else if (parser.getName().equals(TAG_CHILD_PACKAGE)) { |
| 3565 | String childPackageName = parser.getAttributeValue(null, ATTR_NAME); |
| 3566 | if (ps.childPackageNames == null) { |
| 3567 | ps.childPackageNames = new ArrayList<>(); |
| 3568 | } |
| 3569 | ps.childPackageNames.add(childPackageName); |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 3570 | } else if (parser.getName().equals(TAG_USES_STATIC_LIB)) { |
| 3571 | readUsesStaticLibLPw(parser, ps); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3572 | } else { |
| 3573 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 3574 | "Unknown element under <updated-package>: " + parser.getName()); |
| 3575 | XmlUtils.skipCurrentTag(parser); |
| 3576 | } |
| 3577 | } |
Christopher Tate | 628946a | 2013-10-18 18:11:05 -0700 | [diff] [blame] | 3578 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3579 | mDisabledSysPackages.put(name, ps); |
| 3580 | } |
| 3581 | |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 3582 | private static int PRE_M_APP_INFO_FLAG_HIDDEN = 1<<27; |
| 3583 | private static int PRE_M_APP_INFO_FLAG_CANT_SAVE_STATE = 1<<28; |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 3584 | private static int PRE_M_APP_INFO_FLAG_PRIVILEGED = 1<<30; |
| 3585 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 3586 | private void readPackageLPw(XmlPullParser parser) throws XmlPullParserException, IOException { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3587 | String name = null; |
| 3588 | String realName = null; |
| 3589 | String idStr = null; |
| 3590 | String sharedIdStr = null; |
| 3591 | String codePathStr = null; |
| 3592 | String resourcePathStr = null; |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 3593 | String legacyCpuAbiString = null; |
| 3594 | String legacyNativeLibraryPathStr = null; |
| 3595 | String primaryCpuAbiString = null; |
| 3596 | String secondaryCpuAbiString = null; |
Narayan Kamath | 4903f64 | 2014-08-11 13:33:45 +0100 | [diff] [blame] | 3597 | String cpuAbiOverrideString = null; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3598 | String systemStr = null; |
| 3599 | String installerPackageName = null; |
Sudheer Shanka | 8c57aea | 2016-04-20 16:47:50 -0700 | [diff] [blame] | 3600 | String isOrphaned = null; |
Jeff Sharkey | b2b9ab8 | 2015-04-05 21:10:42 -0700 | [diff] [blame] | 3601 | String volumeUuid = null; |
Jeff Sharkey | 9bc89af | 2017-01-11 11:25:50 -0700 | [diff] [blame] | 3602 | String categoryHintString = null; |
Todd Kennedy | ab53289 | 2017-03-08 14:19:49 -0800 | [diff] [blame] | 3603 | String updateAvailable = null; |
Jeff Sharkey | 9bc89af | 2017-01-11 11:25:50 -0700 | [diff] [blame] | 3604 | int categoryHint = ApplicationInfo.CATEGORY_UNDEFINED; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3605 | String uidError = null; |
| 3606 | int pkgFlags = 0; |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 3607 | int pkgPrivateFlags = 0; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3608 | long timeStamp = 0; |
| 3609 | long firstInstallTime = 0; |
| 3610 | long lastUpdateTime = 0; |
Todd Kennedy | 788c842 | 2016-08-10 10:52:34 -0700 | [diff] [blame] | 3611 | PackageSetting packageSetting = null; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3612 | String version = null; |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 3613 | long versionCode = 0; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3614 | String parentPackageName; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3615 | try { |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 3616 | name = parser.getAttributeValue(null, ATTR_NAME); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3617 | realName = parser.getAttributeValue(null, "realName"); |
| 3618 | idStr = parser.getAttributeValue(null, "userId"); |
| 3619 | uidError = parser.getAttributeValue(null, "uidError"); |
| 3620 | sharedIdStr = parser.getAttributeValue(null, "sharedUserId"); |
| 3621 | codePathStr = parser.getAttributeValue(null, "codePath"); |
| 3622 | resourcePathStr = parser.getAttributeValue(null, "resourcePath"); |
Narayan Kamath | 9e289d7 | 2014-04-10 09:26:59 +0000 | [diff] [blame] | 3623 | |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 3624 | legacyCpuAbiString = parser.getAttributeValue(null, "requiredCpuAbi"); |
| 3625 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3626 | parentPackageName = parser.getAttributeValue(null, "parentPackageName"); |
| 3627 | |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 3628 | legacyNativeLibraryPathStr = parser.getAttributeValue(null, "nativeLibraryPath"); |
| 3629 | primaryCpuAbiString = parser.getAttributeValue(null, "primaryCpuAbi"); |
| 3630 | secondaryCpuAbiString = parser.getAttributeValue(null, "secondaryCpuAbi"); |
Narayan Kamath | 4903f64 | 2014-08-11 13:33:45 +0100 | [diff] [blame] | 3631 | cpuAbiOverrideString = parser.getAttributeValue(null, "cpuAbiOverride"); |
Todd Kennedy | ab53289 | 2017-03-08 14:19:49 -0800 | [diff] [blame] | 3632 | updateAvailable = parser.getAttributeValue(null, "updateAvailable"); |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 3633 | |
| 3634 | if (primaryCpuAbiString == null && legacyCpuAbiString != null) { |
| 3635 | primaryCpuAbiString = legacyCpuAbiString; |
| 3636 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 3637 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3638 | version = parser.getAttributeValue(null, "version"); |
| 3639 | if (version != null) { |
| 3640 | try { |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 3641 | versionCode = Long.parseLong(version); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3642 | } catch (NumberFormatException e) { |
| 3643 | } |
| 3644 | } |
| 3645 | installerPackageName = parser.getAttributeValue(null, "installer"); |
Sudheer Shanka | 8c57aea | 2016-04-20 16:47:50 -0700 | [diff] [blame] | 3646 | isOrphaned = parser.getAttributeValue(null, "isOrphaned"); |
Jeff Sharkey | b2b9ab8 | 2015-04-05 21:10:42 -0700 | [diff] [blame] | 3647 | volumeUuid = parser.getAttributeValue(null, "volumeUuid"); |
Jeff Sharkey | 9bc89af | 2017-01-11 11:25:50 -0700 | [diff] [blame] | 3648 | categoryHintString = parser.getAttributeValue(null, "categoryHint"); |
| 3649 | if (categoryHintString != null) { |
| 3650 | try { |
| 3651 | categoryHint = Integer.parseInt(categoryHintString); |
| 3652 | } catch (NumberFormatException e) { |
| 3653 | } |
| 3654 | } |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3655 | |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 3656 | systemStr = parser.getAttributeValue(null, "publicFlags"); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3657 | if (systemStr != null) { |
| 3658 | try { |
| 3659 | pkgFlags = Integer.parseInt(systemStr); |
| 3660 | } catch (NumberFormatException e) { |
| 3661 | } |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 3662 | systemStr = parser.getAttributeValue(null, "privateFlags"); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3663 | if (systemStr != null) { |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 3664 | try { |
| 3665 | pkgPrivateFlags = Integer.parseInt(systemStr); |
| 3666 | } catch (NumberFormatException e) { |
| 3667 | } |
| 3668 | } |
| 3669 | } else { |
| 3670 | // Pre-M -- both public and private flags were stored in one "flags" field. |
| 3671 | systemStr = parser.getAttributeValue(null, "flags"); |
| 3672 | if (systemStr != null) { |
| 3673 | try { |
| 3674 | pkgFlags = Integer.parseInt(systemStr); |
| 3675 | } catch (NumberFormatException e) { |
| 3676 | } |
| 3677 | if ((pkgFlags & PRE_M_APP_INFO_FLAG_HIDDEN) != 0) { |
| 3678 | pkgPrivateFlags |= ApplicationInfo.PRIVATE_FLAG_HIDDEN; |
| 3679 | } |
| 3680 | if ((pkgFlags & PRE_M_APP_INFO_FLAG_CANT_SAVE_STATE) != 0) { |
| 3681 | pkgPrivateFlags |= ApplicationInfo.PRIVATE_FLAG_CANT_SAVE_STATE; |
| 3682 | } |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 3683 | if ((pkgFlags & PRE_M_APP_INFO_FLAG_PRIVILEGED) != 0) { |
| 3684 | pkgPrivateFlags |= ApplicationInfo.PRIVATE_FLAG_PRIVILEGED; |
| 3685 | } |
| 3686 | pkgFlags &= ~(PRE_M_APP_INFO_FLAG_HIDDEN |
| 3687 | | PRE_M_APP_INFO_FLAG_CANT_SAVE_STATE |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 3688 | | PRE_M_APP_INFO_FLAG_PRIVILEGED); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3689 | } else { |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 3690 | // For backward compatibility |
| 3691 | systemStr = parser.getAttributeValue(null, "system"); |
| 3692 | if (systemStr != null) { |
| 3693 | pkgFlags |= ("true".equalsIgnoreCase(systemStr)) ? ApplicationInfo.FLAG_SYSTEM |
| 3694 | : 0; |
| 3695 | } else { |
| 3696 | // Old settings that don't specify system... just treat |
| 3697 | // them as system, good enough. |
| 3698 | pkgFlags |= ApplicationInfo.FLAG_SYSTEM; |
| 3699 | } |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3700 | } |
| 3701 | } |
| 3702 | String timeStampStr = parser.getAttributeValue(null, "ft"); |
| 3703 | if (timeStampStr != null) { |
| 3704 | try { |
| 3705 | timeStamp = Long.parseLong(timeStampStr, 16); |
| 3706 | } catch (NumberFormatException e) { |
| 3707 | } |
| 3708 | } else { |
| 3709 | timeStampStr = parser.getAttributeValue(null, "ts"); |
| 3710 | if (timeStampStr != null) { |
| 3711 | try { |
| 3712 | timeStamp = Long.parseLong(timeStampStr); |
| 3713 | } catch (NumberFormatException e) { |
| 3714 | } |
| 3715 | } |
| 3716 | } |
| 3717 | timeStampStr = parser.getAttributeValue(null, "it"); |
| 3718 | if (timeStampStr != null) { |
| 3719 | try { |
| 3720 | firstInstallTime = Long.parseLong(timeStampStr, 16); |
| 3721 | } catch (NumberFormatException e) { |
| 3722 | } |
| 3723 | } |
| 3724 | timeStampStr = parser.getAttributeValue(null, "ut"); |
| 3725 | if (timeStampStr != null) { |
| 3726 | try { |
| 3727 | lastUpdateTime = Long.parseLong(timeStampStr, 16); |
| 3728 | } catch (NumberFormatException e) { |
| 3729 | } |
| 3730 | } |
| 3731 | if (PackageManagerService.DEBUG_SETTINGS) |
| 3732 | Log.v(PackageManagerService.TAG, "Reading package: " + name + " userId=" + idStr |
| 3733 | + " sharedUserId=" + sharedIdStr); |
Todd Kennedy | 788c842 | 2016-08-10 10:52:34 -0700 | [diff] [blame] | 3734 | final int userId = idStr != null ? Integer.parseInt(idStr) : 0; |
| 3735 | final int sharedUserId = sharedIdStr != null ? Integer.parseInt(sharedIdStr) : 0; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3736 | if (resourcePathStr == null) { |
| 3737 | resourcePathStr = codePathStr; |
| 3738 | } |
| 3739 | if (realName != null) { |
| 3740 | realName = realName.intern(); |
| 3741 | } |
| 3742 | if (name == null) { |
| 3743 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 3744 | "Error in package manager settings: <package> has no name at " |
| 3745 | + parser.getPositionDescription()); |
| 3746 | } else if (codePathStr == null) { |
| 3747 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 3748 | "Error in package manager settings: <package> has no codePath at " |
| 3749 | + parser.getPositionDescription()); |
| 3750 | } else if (userId > 0) { |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 3751 | packageSetting = addPackageLPw(name.intern(), realName, new File(codePathStr), |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 3752 | new File(resourcePathStr), legacyNativeLibraryPathStr, primaryCpuAbiString, |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 3753 | secondaryCpuAbiString, cpuAbiOverrideString, userId, versionCode, pkgFlags, |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 3754 | pkgPrivateFlags, parentPackageName, null /*childPackageNames*/, |
| 3755 | null /*usesStaticLibraries*/, null /*usesStaticLibraryVersions*/); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3756 | if (PackageManagerService.DEBUG_SETTINGS) |
| 3757 | Log.i(PackageManagerService.TAG, "Reading package " + name + ": userId=" |
| 3758 | + userId + " pkg=" + packageSetting); |
| 3759 | if (packageSetting == null) { |
| 3760 | PackageManagerService.reportSettingsProblem(Log.ERROR, "Failure adding uid " |
| 3761 | + userId + " while parsing settings at " |
| 3762 | + parser.getPositionDescription()); |
| 3763 | } else { |
| 3764 | packageSetting.setTimeStamp(timeStamp); |
| 3765 | packageSetting.firstInstallTime = firstInstallTime; |
| 3766 | packageSetting.lastUpdateTime = lastUpdateTime; |
| 3767 | } |
| 3768 | } else if (sharedIdStr != null) { |
Todd Kennedy | 788c842 | 2016-08-10 10:52:34 -0700 | [diff] [blame] | 3769 | if (sharedUserId > 0) { |
| 3770 | packageSetting = new PackageSetting(name.intern(), realName, new File( |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 3771 | codePathStr), new File(resourcePathStr), legacyNativeLibraryPathStr, |
Narayan Kamath | 4903f64 | 2014-08-11 13:33:45 +0100 | [diff] [blame] | 3772 | primaryCpuAbiString, secondaryCpuAbiString, cpuAbiOverrideString, |
Todd Kennedy | 788c842 | 2016-08-10 10:52:34 -0700 | [diff] [blame] | 3773 | versionCode, pkgFlags, pkgPrivateFlags, parentPackageName, |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 3774 | null /*childPackageNames*/, sharedUserId, |
| 3775 | null /*usesStaticLibraries*/, null /*usesStaticLibraryVersions*/); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3776 | packageSetting.setTimeStamp(timeStamp); |
| 3777 | packageSetting.firstInstallTime = firstInstallTime; |
| 3778 | packageSetting.lastUpdateTime = lastUpdateTime; |
Todd Kennedy | 788c842 | 2016-08-10 10:52:34 -0700 | [diff] [blame] | 3779 | mPendingPackages.add(packageSetting); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3780 | if (PackageManagerService.DEBUG_SETTINGS) |
| 3781 | Log.i(PackageManagerService.TAG, "Reading package " + name |
Todd Kennedy | 788c842 | 2016-08-10 10:52:34 -0700 | [diff] [blame] | 3782 | + ": sharedUserId=" + sharedUserId + " pkg=" + packageSetting); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3783 | } else { |
| 3784 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 3785 | "Error in package manager settings: package " + name |
| 3786 | + " has bad sharedId " + sharedIdStr + " at " |
| 3787 | + parser.getPositionDescription()); |
| 3788 | } |
| 3789 | } else { |
| 3790 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 3791 | "Error in package manager settings: package " + name + " has bad userId " |
| 3792 | + idStr + " at " + parser.getPositionDescription()); |
| 3793 | } |
| 3794 | } catch (NumberFormatException e) { |
| 3795 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 3796 | "Error in package manager settings: package " + name + " has bad userId " |
| 3797 | + idStr + " at " + parser.getPositionDescription()); |
| 3798 | } |
| 3799 | if (packageSetting != null) { |
| 3800 | packageSetting.uidError = "true".equals(uidError); |
| 3801 | packageSetting.installerPackageName = installerPackageName; |
Sudheer Shanka | 8c57aea | 2016-04-20 16:47:50 -0700 | [diff] [blame] | 3802 | packageSetting.isOrphaned = "true".equals(isOrphaned); |
Jeff Sharkey | b2b9ab8 | 2015-04-05 21:10:42 -0700 | [diff] [blame] | 3803 | packageSetting.volumeUuid = volumeUuid; |
Jeff Sharkey | 9bc89af | 2017-01-11 11:25:50 -0700 | [diff] [blame] | 3804 | packageSetting.categoryHint = categoryHint; |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 3805 | packageSetting.legacyNativeLibraryPathString = legacyNativeLibraryPathStr; |
| 3806 | packageSetting.primaryCpuAbiString = primaryCpuAbiString; |
| 3807 | packageSetting.secondaryCpuAbiString = secondaryCpuAbiString; |
Todd Kennedy | ab53289 | 2017-03-08 14:19:49 -0800 | [diff] [blame] | 3808 | packageSetting.updateAvailable = "true".equals(updateAvailable); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 3809 | // Handle legacy string here for single-user mode |
| 3810 | final String enabledStr = parser.getAttributeValue(null, ATTR_ENABLED); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3811 | if (enabledStr != null) { |
Dianne Hackborn | b8f4000 | 2011-07-19 15:17:43 -0700 | [diff] [blame] | 3812 | try { |
Dianne Hackborn | 3fa3c28a | 2013-03-26 16:15:41 -0700 | [diff] [blame] | 3813 | packageSetting.setEnabled(Integer.parseInt(enabledStr), 0 /* userId */, null); |
Dianne Hackborn | b8f4000 | 2011-07-19 15:17:43 -0700 | [diff] [blame] | 3814 | } catch (NumberFormatException e) { |
| 3815 | if (enabledStr.equalsIgnoreCase("true")) { |
Dianne Hackborn | 3fa3c28a | 2013-03-26 16:15:41 -0700 | [diff] [blame] | 3816 | packageSetting.setEnabled(COMPONENT_ENABLED_STATE_ENABLED, 0, null); |
Dianne Hackborn | b8f4000 | 2011-07-19 15:17:43 -0700 | [diff] [blame] | 3817 | } else if (enabledStr.equalsIgnoreCase("false")) { |
Dianne Hackborn | 3fa3c28a | 2013-03-26 16:15:41 -0700 | [diff] [blame] | 3818 | packageSetting.setEnabled(COMPONENT_ENABLED_STATE_DISABLED, 0, null); |
Dianne Hackborn | b8f4000 | 2011-07-19 15:17:43 -0700 | [diff] [blame] | 3819 | } else if (enabledStr.equalsIgnoreCase("default")) { |
Dianne Hackborn | 3fa3c28a | 2013-03-26 16:15:41 -0700 | [diff] [blame] | 3820 | packageSetting.setEnabled(COMPONENT_ENABLED_STATE_DEFAULT, 0, null); |
Dianne Hackborn | b8f4000 | 2011-07-19 15:17:43 -0700 | [diff] [blame] | 3821 | } else { |
| 3822 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 3823 | "Error in package manager settings: package " + name |
| 3824 | + " has bad enabled value: " + idStr + " at " |
| 3825 | + parser.getPositionDescription()); |
| 3826 | } |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3827 | } |
| 3828 | } else { |
Dianne Hackborn | 3fa3c28a | 2013-03-26 16:15:41 -0700 | [diff] [blame] | 3829 | packageSetting.setEnabled(COMPONENT_ENABLED_STATE_DEFAULT, 0, null); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3830 | } |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 3831 | |
Sudheer Shanka | 2928337 | 2016-04-04 20:56:27 -0700 | [diff] [blame] | 3832 | if (installerPackageName != null) { |
| 3833 | mInstallerPackages.add(installerPackageName); |
| 3834 | } |
| 3835 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3836 | int outerDepth = parser.getDepth(); |
| 3837 | int type; |
| 3838 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 3839 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 3840 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 3841 | continue; |
| 3842 | } |
| 3843 | |
| 3844 | String tagName = parser.getName(); |
Selim Gurun | 5c8acb4 | 2016-04-07 16:34:02 -0700 | [diff] [blame] | 3845 | // Legacy |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 3846 | if (tagName.equals(TAG_DISABLED_COMPONENTS)) { |
| 3847 | readDisabledComponentsLPw(packageSetting, parser, 0); |
| 3848 | } else if (tagName.equals(TAG_ENABLED_COMPONENTS)) { |
| 3849 | readEnabledComponentsLPw(packageSetting, parser, 0); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3850 | } else if (tagName.equals("sigs")) { |
| 3851 | packageSetting.signatures.readXml(parser, mPastSignatures); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 3852 | } else if (tagName.equals(TAG_PERMISSIONS)) { |
| 3853 | readInstallPermissionsLPr(parser, |
| 3854 | packageSetting.getPermissionsState()); |
Svetoslav | cf959f6 | 2015-03-26 20:53:34 -0700 | [diff] [blame] | 3855 | packageSetting.installPermissionsFixed = true; |
dcashman | 3a0dbfb | 2014-07-07 13:53:36 -0700 | [diff] [blame] | 3856 | } else if (tagName.equals("proper-signing-keyset")) { |
| 3857 | long id = Long.parseLong(parser.getAttributeValue(null, "identifier")); |
dcashman | 8c04fac | 2015-03-23 11:39:42 -0700 | [diff] [blame] | 3858 | Integer refCt = mKeySetRefs.get(id); |
| 3859 | if (refCt != null) { |
| 3860 | mKeySetRefs.put(id, refCt + 1); |
| 3861 | } else { |
| 3862 | mKeySetRefs.put(id, 1); |
| 3863 | } |
dcashman | 3a0dbfb | 2014-07-07 13:53:36 -0700 | [diff] [blame] | 3864 | packageSetting.keySetData.setProperSigningKeySet(id); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 3865 | } else if (tagName.equals("signing-keyset")) { |
dcashman | 8c04fac | 2015-03-23 11:39:42 -0700 | [diff] [blame] | 3866 | // from v1 of keysetmanagerservice - no longer used |
dcashman | 55b1078 | 2014-04-09 14:20:38 -0700 | [diff] [blame] | 3867 | } else if (tagName.equals("upgrade-keyset")) { |
| 3868 | long id = Long.parseLong(parser.getAttributeValue(null, "identifier")); |
| 3869 | packageSetting.keySetData.addUpgradeKeySetById(id); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 3870 | } else if (tagName.equals("defined-keyset")) { |
| 3871 | long id = Long.parseLong(parser.getAttributeValue(null, "identifier")); |
| 3872 | String alias = parser.getAttributeValue(null, "alias"); |
dcashman | 8c04fac | 2015-03-23 11:39:42 -0700 | [diff] [blame] | 3873 | Integer refCt = mKeySetRefs.get(id); |
| 3874 | if (refCt != null) { |
| 3875 | mKeySetRefs.put(id, refCt + 1); |
| 3876 | } else { |
| 3877 | mKeySetRefs.put(id, 1); |
| 3878 | } |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 3879 | packageSetting.keySetData.addDefinedKeySet(id, alias); |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 3880 | } else if (tagName.equals(TAG_DOMAIN_VERIFICATION)) { |
| 3881 | readDomainVerificationLPw(parser, packageSetting); |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3882 | } else if (tagName.equals(TAG_CHILD_PACKAGE)) { |
| 3883 | String childPackageName = parser.getAttributeValue(null, ATTR_NAME); |
| 3884 | if (packageSetting.childPackageNames == null) { |
| 3885 | packageSetting.childPackageNames = new ArrayList<>(); |
| 3886 | } |
| 3887 | packageSetting.childPackageNames.add(childPackageName); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3888 | } else { |
| 3889 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 3890 | "Unknown element under <package>: " + parser.getName()); |
| 3891 | XmlUtils.skipCurrentTag(parser); |
| 3892 | } |
| 3893 | } |
| 3894 | } else { |
| 3895 | XmlUtils.skipCurrentTag(parser); |
| 3896 | } |
| 3897 | } |
| 3898 | |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 3899 | private void readDisabledComponentsLPw(PackageSettingBase packageSetting, XmlPullParser parser, |
| 3900 | int userId) throws IOException, XmlPullParserException { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3901 | int outerDepth = parser.getDepth(); |
| 3902 | int type; |
| 3903 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 3904 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 3905 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 3906 | continue; |
| 3907 | } |
| 3908 | |
| 3909 | String tagName = parser.getName(); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 3910 | if (tagName.equals(TAG_ITEM)) { |
| 3911 | String name = parser.getAttributeValue(null, ATTR_NAME); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3912 | if (name != null) { |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 3913 | packageSetting.addDisabledComponent(name.intern(), userId); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3914 | } else { |
| 3915 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 3916 | "Error in package manager settings: <disabled-components> has" |
| 3917 | + " no name at " + parser.getPositionDescription()); |
| 3918 | } |
| 3919 | } else { |
| 3920 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 3921 | "Unknown element under <disabled-components>: " + parser.getName()); |
| 3922 | } |
| 3923 | XmlUtils.skipCurrentTag(parser); |
| 3924 | } |
| 3925 | } |
| 3926 | |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 3927 | private void readEnabledComponentsLPw(PackageSettingBase packageSetting, XmlPullParser parser, |
| 3928 | int userId) throws IOException, XmlPullParserException { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3929 | int outerDepth = parser.getDepth(); |
| 3930 | int type; |
| 3931 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 3932 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 3933 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 3934 | continue; |
| 3935 | } |
| 3936 | |
| 3937 | String tagName = parser.getName(); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 3938 | if (tagName.equals(TAG_ITEM)) { |
| 3939 | String name = parser.getAttributeValue(null, ATTR_NAME); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3940 | if (name != null) { |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 3941 | packageSetting.addEnabledComponent(name.intern(), userId); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3942 | } else { |
| 3943 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 3944 | "Error in package manager settings: <enabled-components> has" |
| 3945 | + " no name at " + parser.getPositionDescription()); |
| 3946 | } |
| 3947 | } else { |
| 3948 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 3949 | "Unknown element under <enabled-components>: " + parser.getName()); |
| 3950 | } |
| 3951 | XmlUtils.skipCurrentTag(parser); |
| 3952 | } |
| 3953 | } |
| 3954 | |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 3955 | private void readSharedUserLPw(XmlPullParser parser) throws XmlPullParserException,IOException { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3956 | String name = null; |
| 3957 | String idStr = null; |
| 3958 | int pkgFlags = 0; |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 3959 | int pkgPrivateFlags = 0; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3960 | SharedUserSetting su = null; |
| 3961 | try { |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 3962 | name = parser.getAttributeValue(null, ATTR_NAME); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3963 | idStr = parser.getAttributeValue(null, "userId"); |
| 3964 | int userId = idStr != null ? Integer.parseInt(idStr) : 0; |
| 3965 | if ("true".equals(parser.getAttributeValue(null, "system"))) { |
| 3966 | pkgFlags |= ApplicationInfo.FLAG_SYSTEM; |
| 3967 | } |
| 3968 | if (name == null) { |
| 3969 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 3970 | "Error in package manager settings: <shared-user> has no name at " |
| 3971 | + parser.getPositionDescription()); |
| 3972 | } else if (userId == 0) { |
| 3973 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 3974 | "Error in package manager settings: shared-user " + name |
| 3975 | + " has bad userId " + idStr + " at " |
| 3976 | + parser.getPositionDescription()); |
| 3977 | } else { |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 3978 | if ((su = addSharedUserLPw(name.intern(), userId, pkgFlags, pkgPrivateFlags)) |
| 3979 | == null) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3980 | PackageManagerService |
| 3981 | .reportSettingsProblem(Log.ERROR, "Occurred while parsing settings at " |
| 3982 | + parser.getPositionDescription()); |
| 3983 | } |
| 3984 | } |
| 3985 | } catch (NumberFormatException e) { |
| 3986 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 3987 | "Error in package manager settings: package " + name + " has bad userId " |
| 3988 | + idStr + " at " + parser.getPositionDescription()); |
| 3989 | } |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3990 | |
| 3991 | if (su != null) { |
| 3992 | int outerDepth = parser.getDepth(); |
| 3993 | int type; |
| 3994 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 3995 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 3996 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 3997 | continue; |
| 3998 | } |
| 3999 | |
| 4000 | String tagName = parser.getName(); |
| 4001 | if (tagName.equals("sigs")) { |
| 4002 | su.signatures.readXml(parser, mPastSignatures); |
| 4003 | } else if (tagName.equals("perms")) { |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4004 | readInstallPermissionsLPr(parser, su.getPermissionsState()); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 4005 | } else { |
| 4006 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 4007 | "Unknown element under <shared-user>: " + parser.getName()); |
| 4008 | XmlUtils.skipCurrentTag(parser); |
| 4009 | } |
| 4010 | } |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 4011 | } else { |
| 4012 | XmlUtils.skipCurrentTag(parser); |
| 4013 | } |
| 4014 | } |
| 4015 | |
Fyodor Kupolov | d8327bd | 2015-11-30 17:42:43 -0800 | [diff] [blame] | 4016 | void createNewUserLI(@NonNull PackageManagerService service, @NonNull Installer installer, |
Sudheer Shanka | 7cb54a3 | 2016-09-16 12:59:05 -0700 | [diff] [blame] | 4017 | int userHandle, String[] disallowedPackages) { |
Fyodor Kupolov | d8327bd | 2015-11-30 17:42:43 -0800 | [diff] [blame] | 4018 | String[] volumeUuids; |
| 4019 | String[] names; |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 4020 | int[] appIds; |
Fyodor Kupolov | d8327bd | 2015-11-30 17:42:43 -0800 | [diff] [blame] | 4021 | String[] seinfos; |
Janis Danisevskis | f340974 | 2016-01-12 14:46:33 +0000 | [diff] [blame] | 4022 | int[] targetSdkVersions; |
Fyodor Kupolov | d8327bd | 2015-11-30 17:42:43 -0800 | [diff] [blame] | 4023 | int packagesCount; |
| 4024 | synchronized (mPackages) { |
| 4025 | Collection<PackageSetting> packages = mPackages.values(); |
| 4026 | packagesCount = packages.size(); |
| 4027 | volumeUuids = new String[packagesCount]; |
| 4028 | names = new String[packagesCount]; |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 4029 | appIds = new int[packagesCount]; |
Fyodor Kupolov | d8327bd | 2015-11-30 17:42:43 -0800 | [diff] [blame] | 4030 | seinfos = new String[packagesCount]; |
Janis Danisevskis | f340974 | 2016-01-12 14:46:33 +0000 | [diff] [blame] | 4031 | targetSdkVersions = new int[packagesCount]; |
Fyodor Kupolov | d8327bd | 2015-11-30 17:42:43 -0800 | [diff] [blame] | 4032 | Iterator<PackageSetting> packagesIterator = packages.iterator(); |
| 4033 | for (int i = 0; i < packagesCount; i++) { |
| 4034 | PackageSetting ps = packagesIterator.next(); |
| 4035 | if (ps.pkg == null || ps.pkg.applicationInfo == null) { |
| 4036 | continue; |
| 4037 | } |
Sudheer Shanka | 7cb54a3 | 2016-09-16 12:59:05 -0700 | [diff] [blame] | 4038 | final boolean shouldInstall = ps.isSystem() && |
Rhed Jao | cd47c26 | 2018-06-13 11:16:16 +0800 | [diff] [blame] | 4039 | !ArrayUtils.contains(disallowedPackages, ps.name) && |
| 4040 | !ps.pkg.applicationInfo.hiddenUntilInstalled; |
Fyodor Kupolov | d8327bd | 2015-11-30 17:42:43 -0800 | [diff] [blame] | 4041 | // Only system apps are initially installed. |
Sudheer Shanka | 7cb54a3 | 2016-09-16 12:59:05 -0700 | [diff] [blame] | 4042 | ps.setInstalled(shouldInstall, userHandle); |
Amith Yamasani | 23ab7f5 | 2017-01-22 17:43:24 -0800 | [diff] [blame] | 4043 | if (!shouldInstall) { |
| 4044 | writeKernelMappingLPr(ps); |
| 4045 | } |
Fyodor Kupolov | d8327bd | 2015-11-30 17:42:43 -0800 | [diff] [blame] | 4046 | // Need to create a data directory for all apps under this user. Accumulate all |
| 4047 | // required args and call the installer after mPackages lock has been released |
| 4048 | volumeUuids[i] = ps.volumeUuid; |
| 4049 | names[i] = ps.name; |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 4050 | appIds[i] = ps.appId; |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 4051 | seinfos[i] = ps.pkg.applicationInfo.seInfo; |
Janis Danisevskis | f340974 | 2016-01-12 14:46:33 +0000 | [diff] [blame] | 4052 | targetSdkVersions[i] = ps.pkg.applicationInfo.targetSdkVersion; |
Fyodor Kupolov | d8327bd | 2015-11-30 17:42:43 -0800 | [diff] [blame] | 4053 | } |
| 4054 | } |
| 4055 | for (int i = 0; i < packagesCount; i++) { |
| 4056 | if (names[i] == null) { |
Amith Yamasani | 41cd577 | 2014-07-10 15:26:00 -0700 | [diff] [blame] | 4057 | continue; |
| 4058 | } |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 4059 | // TODO: triage flags! |
Jeff Sharkey | 47f7108 | 2016-02-01 17:03:54 -0700 | [diff] [blame] | 4060 | final int flags = StorageManager.FLAG_STORAGE_CE | StorageManager.FLAG_STORAGE_DE; |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 4061 | try { |
| 4062 | installer.createAppData(volumeUuids[i], names[i], userHandle, flags, appIds[i], |
Janis Danisevskis | f340974 | 2016-01-12 14:46:33 +0000 | [diff] [blame] | 4063 | seinfos[i], targetSdkVersions[i]); |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 4064 | } catch (InstallerException e) { |
| 4065 | Slog.w(TAG, "Failed to prepare app data", e); |
| 4066 | } |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 4067 | } |
Fyodor Kupolov | d8327bd | 2015-11-30 17:42:43 -0800 | [diff] [blame] | 4068 | synchronized (mPackages) { |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 4069 | applyDefaultPreferredAppsLPw(userHandle); |
Fyodor Kupolov | d8327bd | 2015-11-30 17:42:43 -0800 | [diff] [blame] | 4070 | } |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 4071 | } |
| 4072 | |
Alexandra Gherghina | 539a7ef | 2014-07-07 12:27:54 +0100 | [diff] [blame] | 4073 | void removeUserLPw(int userId) { |
Dianne Hackborn | 6309271 | 2012-10-07 14:45:35 -0700 | [diff] [blame] | 4074 | Set<Entry<String, PackageSetting>> entries = mPackages.entrySet(); |
| 4075 | for (Entry<String, PackageSetting> entry : entries) { |
| 4076 | entry.getValue().removeUser(userId); |
| 4077 | } |
| 4078 | mPreferredActivities.remove(userId); |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 4079 | File file = getUserPackagesStateFile(userId); |
| 4080 | file.delete(); |
| 4081 | file = getUserPackagesStateBackupFile(userId); |
| 4082 | file.delete(); |
Nicolas Prevot | e702404 | 2014-07-08 15:47:17 +0100 | [diff] [blame] | 4083 | removeCrossProfileIntentFiltersLPw(userId); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4084 | |
Fyodor Kupolov | 6954259 | 2016-05-23 14:22:38 -0700 | [diff] [blame] | 4085 | mRuntimePermissionsPersistence.onUserRemovedLPw(userId); |
Jeff Sharkey | 91edde2 | 2015-05-20 12:04:42 -0700 | [diff] [blame] | 4086 | |
| 4087 | writePackageListLPr(); |
Amith Yamasani | 23ab7f5 | 2017-01-22 17:43:24 -0800 | [diff] [blame] | 4088 | |
| 4089 | // Inform kernel that the user was removed, so that packages are marked uninstalled |
| 4090 | // for sdcardfs |
| 4091 | writeKernelRemoveUserLPr(userId); |
Nicolas Prevot | a0f4885 | 2014-05-27 11:21:11 +0100 | [diff] [blame] | 4092 | } |
| 4093 | |
Nicolas Prevot | e702404 | 2014-07-08 15:47:17 +0100 | [diff] [blame] | 4094 | void removeCrossProfileIntentFiltersLPw(int userId) { |
| 4095 | synchronized (mCrossProfileIntentResolvers) { |
| 4096 | // userId is the source user |
| 4097 | if (mCrossProfileIntentResolvers.get(userId) != null) { |
| 4098 | mCrossProfileIntentResolvers.remove(userId); |
| 4099 | writePackageRestrictionsLPr(userId); |
Nicolas Prevot | a0f4885 | 2014-05-27 11:21:11 +0100 | [diff] [blame] | 4100 | } |
Nicolas Prevot | e702404 | 2014-07-08 15:47:17 +0100 | [diff] [blame] | 4101 | // userId is the target user |
| 4102 | int count = mCrossProfileIntentResolvers.size(); |
| 4103 | for (int i = 0; i < count; i++) { |
| 4104 | int sourceUserId = mCrossProfileIntentResolvers.keyAt(i); |
| 4105 | CrossProfileIntentResolver cpir = mCrossProfileIntentResolvers.get(sourceUserId); |
| 4106 | boolean needsWriting = false; |
Jeff Sharkey | 9f837a9 | 2014-10-24 12:07:24 -0700 | [diff] [blame] | 4107 | ArraySet<CrossProfileIntentFilter> cpifs = |
| 4108 | new ArraySet<CrossProfileIntentFilter>(cpir.filterSet()); |
Nicolas Prevot | e702404 | 2014-07-08 15:47:17 +0100 | [diff] [blame] | 4109 | for (CrossProfileIntentFilter cpif : cpifs) { |
| 4110 | if (cpif.getTargetUserId() == userId) { |
| 4111 | needsWriting = true; |
| 4112 | cpir.removeFilter(cpif); |
| 4113 | } |
| 4114 | } |
| 4115 | if (needsWriting) { |
| 4116 | writePackageRestrictionsLPr(sourceUserId); |
| 4117 | } |
Nicolas Prevot | a0f4885 | 2014-05-27 11:21:11 +0100 | [diff] [blame] | 4118 | } |
| 4119 | } |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 4120 | } |
| 4121 | |
Geremy Condra | 12c1838 | 2013-03-06 16:49:06 -0800 | [diff] [blame] | 4122 | // This should be called (at least) whenever an application is removed |
| 4123 | private void setFirstAvailableUid(int uid) { |
| 4124 | if (uid > mFirstAvailableUid) { |
| 4125 | mFirstAvailableUid = uid; |
| 4126 | } |
| 4127 | } |
| 4128 | |
Patrick Baumann | 649a857 | 2018-11-20 11:16:58 -0800 | [diff] [blame] | 4129 | /** Returns a new AppID or -1 if we could not find an available AppID to assign */ |
| 4130 | private int acquireAndRegisterNewAppIdLPw(SettingBase obj) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 4131 | // Let's be stupidly inefficient for now... |
Patrick Baumann | 649a857 | 2018-11-20 11:16:58 -0800 | [diff] [blame] | 4132 | final int size = mAppIds.size(); |
| 4133 | for (int i = mFirstAvailableUid; i < size; i++) { |
| 4134 | if (mAppIds.get(i) == null) { |
| 4135 | mAppIds.set(i, obj); |
Dianne Hackborn | 21fbd1f | 2012-02-10 10:38:10 -0800 | [diff] [blame] | 4136 | return Process.FIRST_APPLICATION_UID + i; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 4137 | } |
| 4138 | } |
| 4139 | |
| 4140 | // None left? |
Patrick Baumann | 649a857 | 2018-11-20 11:16:58 -0800 | [diff] [blame] | 4141 | if (size > (Process.LAST_APPLICATION_UID - Process.FIRST_APPLICATION_UID)) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 4142 | return -1; |
| 4143 | } |
| 4144 | |
Patrick Baumann | 649a857 | 2018-11-20 11:16:58 -0800 | [diff] [blame] | 4145 | mAppIds.add(obj); |
| 4146 | return Process.FIRST_APPLICATION_UID + size; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 4147 | } |
| 4148 | |
Kenny Root | 0aaa0d9 | 2011-09-12 16:42:55 -0700 | [diff] [blame] | 4149 | public VerifierDeviceIdentity getVerifierDeviceIdentityLPw() { |
| 4150 | if (mVerifierDeviceIdentity == null) { |
| 4151 | mVerifierDeviceIdentity = VerifierDeviceIdentity.generate(); |
| 4152 | |
| 4153 | writeLPr(); |
| 4154 | } |
| 4155 | |
| 4156 | return mVerifierDeviceIdentity; |
| 4157 | } |
| 4158 | |
Todd Kennedy | ff35e66 | 2016-09-20 12:53:52 -0700 | [diff] [blame] | 4159 | boolean hasOtherDisabledSystemPkgWithChildLPr(String parentPackageName, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4160 | String childPackageName) { |
| 4161 | final int packageCount = mDisabledSysPackages.size(); |
| 4162 | for (int i = 0; i < packageCount; i++) { |
| 4163 | PackageSetting disabledPs = mDisabledSysPackages.valueAt(i); |
| 4164 | if (disabledPs.childPackageNames == null || disabledPs.childPackageNames.isEmpty()) { |
| 4165 | continue; |
| 4166 | } |
| 4167 | if (disabledPs.name.equals(parentPackageName)) { |
| 4168 | continue; |
| 4169 | } |
| 4170 | final int childCount = disabledPs.childPackageNames.size(); |
| 4171 | for (int j = 0; j < childCount; j++) { |
| 4172 | String currChildPackageName = disabledPs.childPackageNames.get(j); |
| 4173 | if (currChildPackageName.equals(childPackageName)) { |
| 4174 | return true; |
| 4175 | } |
| 4176 | } |
| 4177 | } |
| 4178 | return false; |
| 4179 | } |
| 4180 | |
Patrick Baumann | 4140783 | 2018-11-09 15:02:38 -0800 | [diff] [blame] | 4181 | /** |
| 4182 | * Returns the disabled {@link PackageSetting} for the provided package name if one exists, |
| 4183 | * {@code null} otherwise. |
| 4184 | */ |
| 4185 | @Nullable |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4186 | public PackageSetting getDisabledSystemPkgLPr(String name) { |
| 4187 | PackageSetting ps = mDisabledSysPackages.get(name); |
| 4188 | return ps; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 4189 | } |
| 4190 | |
Patrick Baumann | 4140783 | 2018-11-09 15:02:38 -0800 | [diff] [blame] | 4191 | /** |
| 4192 | * Returns the disabled {@link PackageSetting} for the provided enabled {@link PackageSetting} |
| 4193 | * if one exists, {@code null} otherwise. |
| 4194 | */ |
| 4195 | @Nullable |
| 4196 | public PackageSetting getDisabledSystemPkgLPr(PackageSetting enabledPackageSetting) { |
| 4197 | if (enabledPackageSetting == null) { |
| 4198 | return null; |
| 4199 | } |
| 4200 | return getDisabledSystemPkgLPr(enabledPackageSetting.name); |
| 4201 | } |
| 4202 | |
| 4203 | /** |
| 4204 | * Fetches an array of the child {@link PackageSetting}s for all child package names referenced |
| 4205 | * by the provided parent {@link PackageSetting} or {@code null} if no children are referenced. |
| 4206 | * |
| 4207 | * Note: Any child packages not found will be null in the returned array. |
| 4208 | */ |
| 4209 | @Nullable |
| 4210 | public PackageSetting[] getChildSettingsLPr(PackageSetting parentPackageSetting) { |
| 4211 | if (parentPackageSetting == null || !parentPackageSetting.hasChildPackages()) { |
| 4212 | return null; |
| 4213 | } |
| 4214 | final int childCount = parentPackageSetting.childPackageNames.size(); |
| 4215 | PackageSetting[] children = |
| 4216 | new PackageSetting[childCount]; |
| 4217 | for (int i = 0; i < childCount; i++) { |
| 4218 | children[i] = mPackages.get(parentPackageSetting.childPackageNames.get(i)); |
| 4219 | } |
| 4220 | return children; |
| 4221 | } |
| 4222 | |
Jeff Sharkey | 5217cac | 2015-12-20 15:34:01 -0700 | [diff] [blame] | 4223 | boolean isEnabledAndMatchLPr(ComponentInfo componentInfo, int flags, int userId) { |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 4224 | final PackageSetting ps = mPackages.get(componentInfo.packageName); |
| 4225 | if (ps == null) return false; |
Jeff Sharkey | e17ac15 | 2015-11-06 22:40:29 -0800 | [diff] [blame] | 4226 | |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 4227 | final PackageUserState userState = ps.readUserState(userId); |
| 4228 | return userState.isMatch(componentInfo, flags); |
Jeff Sharkey | e17ac15 | 2015-11-06 22:40:29 -0800 | [diff] [blame] | 4229 | } |
| 4230 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4231 | String getInstallerPackageNameLPr(String packageName) { |
| 4232 | final PackageSetting pkg = mPackages.get(packageName); |
| 4233 | if (pkg == null) { |
| 4234 | throw new IllegalArgumentException("Unknown package: " + packageName); |
| 4235 | } |
| 4236 | return pkg.installerPackageName; |
| 4237 | } |
| 4238 | |
Sudheer Shanka | 8c57aea | 2016-04-20 16:47:50 -0700 | [diff] [blame] | 4239 | boolean isOrphaned(String packageName) { |
| 4240 | final PackageSetting pkg = mPackages.get(packageName); |
| 4241 | if (pkg == null) { |
| 4242 | throw new IllegalArgumentException("Unknown package: " + packageName); |
| 4243 | } |
| 4244 | return pkg.isOrphaned; |
| 4245 | } |
| 4246 | |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 4247 | int getApplicationEnabledSettingLPr(String packageName, int userId) { |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4248 | final PackageSetting pkg = mPackages.get(packageName); |
| 4249 | if (pkg == null) { |
| 4250 | throw new IllegalArgumentException("Unknown package: " + packageName); |
| 4251 | } |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 4252 | return pkg.getEnabled(userId); |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4253 | } |
| 4254 | |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 4255 | int getComponentEnabledSettingLPr(ComponentName componentName, int userId) { |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4256 | final String packageName = componentName.getPackageName(); |
| 4257 | final PackageSetting pkg = mPackages.get(packageName); |
| 4258 | if (pkg == null) { |
| 4259 | throw new IllegalArgumentException("Unknown component: " + componentName); |
| 4260 | } |
| 4261 | final String classNameStr = componentName.getClassName(); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 4262 | return pkg.getCurrentEnabledStateLPr(classNameStr, userId); |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4263 | } |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 4264 | |
Svet Ganov | 973edd19 | 2016-09-08 20:15:55 -0700 | [diff] [blame] | 4265 | boolean wasPackageEverLaunchedLPr(String packageName, int userId) { |
| 4266 | final PackageSetting pkgSetting = mPackages.get(packageName); |
| 4267 | if (pkgSetting == null) { |
| 4268 | throw new IllegalArgumentException("Unknown package: " + packageName); |
| 4269 | } |
| 4270 | return !pkgSetting.getNotLaunched(userId); |
| 4271 | } |
| 4272 | |
Christopher Tate | 5cf5578 | 2016-04-25 17:08:56 -0700 | [diff] [blame] | 4273 | boolean setPackageStoppedStateLPw(PackageManagerService pm, String packageName, |
Jeff Sharkey | bd0e9e4 | 2015-04-30 16:04:50 -0700 | [diff] [blame] | 4274 | boolean stopped, boolean allowedByPermission, int uid, int userId) { |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 4275 | int appId = UserHandle.getAppId(uid); |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4276 | final PackageSetting pkgSetting = mPackages.get(packageName); |
| 4277 | if (pkgSetting == null) { |
| 4278 | throw new IllegalArgumentException("Unknown package: " + packageName); |
| 4279 | } |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 4280 | if (!allowedByPermission && (appId != pkgSetting.appId)) { |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4281 | throw new SecurityException( |
| 4282 | "Permission Denial: attempt to change stopped state from pid=" |
| 4283 | + Binder.getCallingPid() |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 4284 | + ", uid=" + uid + ", package uid=" + pkgSetting.appId); |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4285 | } |
| 4286 | if (DEBUG_STOPPED) { |
| 4287 | if (stopped) { |
| 4288 | RuntimeException e = new RuntimeException("here"); |
| 4289 | e.fillInStackTrace(); |
| 4290 | Slog.i(TAG, "Stopping package " + packageName, e); |
| 4291 | } |
| 4292 | } |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 4293 | if (pkgSetting.getStopped(userId) != stopped) { |
| 4294 | pkgSetting.setStopped(stopped, userId); |
| 4295 | // pkgSetting.pkg.mSetStopped = stopped; |
| 4296 | if (pkgSetting.getNotLaunched(userId)) { |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4297 | if (pkgSetting.installerPackageName != null) { |
Christopher Tate | 5cf5578 | 2016-04-25 17:08:56 -0700 | [diff] [blame] | 4298 | pm.notifyFirstLaunch(pkgSetting.name, pkgSetting.installerPackageName, userId); |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4299 | } |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 4300 | pkgSetting.setNotLaunched(false, userId); |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4301 | } |
| 4302 | return true; |
| 4303 | } |
| 4304 | return false; |
| 4305 | } |
| 4306 | |
Ben Gruver | 1ab3d6e | 2017-12-07 13:45:08 -0800 | [diff] [blame] | 4307 | void setHarmfulAppWarningLPw(String packageName, CharSequence warning, int userId) { |
| 4308 | final PackageSetting pkgSetting = mPackages.get(packageName); |
| 4309 | if (pkgSetting == null) { |
| 4310 | throw new IllegalArgumentException("Unknown package: " + packageName); |
| 4311 | } |
| 4312 | pkgSetting.setHarmfulAppWarning(userId, warning == null ? null : warning.toString()); |
| 4313 | } |
| 4314 | |
| 4315 | String getHarmfulAppWarningLPr(String packageName, int userId) { |
| 4316 | final PackageSetting pkgSetting = mPackages.get(packageName); |
| 4317 | if (pkgSetting == null) { |
| 4318 | throw new IllegalArgumentException("Unknown package: " + packageName); |
| 4319 | } |
| 4320 | return pkgSetting.getHarmfulAppWarning(userId); |
| 4321 | } |
| 4322 | |
Amith Yamasani | e744669 | 2019-04-19 13:39:51 -0700 | [diff] [blame] | 4323 | /** |
| 4324 | * Return all users on the device, including partial or dying users. |
| 4325 | * @param userManager UserManagerService instance |
| 4326 | * @return the list of users |
| 4327 | */ |
Todd Kennedy | 13715d5 | 2016-08-01 13:38:57 -0700 | [diff] [blame] | 4328 | private static List<UserInfo> getAllUsers(UserManagerService userManager) { |
Amith Yamasani | e744669 | 2019-04-19 13:39:51 -0700 | [diff] [blame] | 4329 | return getUsers(userManager, false); |
| 4330 | } |
| 4331 | |
| 4332 | /** |
| 4333 | * Return the list of users on the device. Clear the calling identity before calling into |
| 4334 | * UserManagerService. |
| 4335 | * @param userManager UserManagerService instance |
| 4336 | * @param excludeDying Indicates whether to exclude any users marked for deletion. |
| 4337 | * @return the list of users |
| 4338 | */ |
| 4339 | private static List<UserInfo> getUsers(UserManagerService userManager, boolean excludeDying) { |
Amith Yamasani | 7ea3e7d | 2012-04-20 15:19:35 -0700 | [diff] [blame] | 4340 | long id = Binder.clearCallingIdentity(); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 4341 | try { |
Amith Yamasani | e744669 | 2019-04-19 13:39:51 -0700 | [diff] [blame] | 4342 | return userManager.getUsers(excludeDying); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 4343 | } catch (NullPointerException npe) { |
| 4344 | // packagemanager not yet initialized |
Amith Yamasani | 7ea3e7d | 2012-04-20 15:19:35 -0700 | [diff] [blame] | 4345 | } finally { |
| 4346 | Binder.restoreCallingIdentity(id); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 4347 | } |
| 4348 | return null; |
| 4349 | } |
| 4350 | |
Jeff Sharkey | b2b9ab8 | 2015-04-05 21:10:42 -0700 | [diff] [blame] | 4351 | /** |
| 4352 | * Return all {@link PackageSetting} that are actively installed on the |
| 4353 | * given {@link VolumeInfo#fsUuid}. |
| 4354 | */ |
| 4355 | List<PackageSetting> getVolumePackagesLPr(String volumeUuid) { |
Jeff Sharkey | b2b9ab8 | 2015-04-05 21:10:42 -0700 | [diff] [blame] | 4356 | ArrayList<PackageSetting> res = new ArrayList<>(); |
| 4357 | for (int i = 0; i < mPackages.size(); i++) { |
| 4358 | final PackageSetting setting = mPackages.valueAt(i); |
| 4359 | if (Objects.equals(volumeUuid, setting.volumeUuid)) { |
| 4360 | res.add(setting); |
| 4361 | } |
| 4362 | } |
| 4363 | return res; |
| 4364 | } |
| 4365 | |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4366 | static void printFlags(PrintWriter pw, int val, Object[] spec) { |
Joe Onorato | 20963df | 2012-01-04 18:13:24 -0800 | [diff] [blame] | 4367 | pw.print("[ "); |
| 4368 | for (int i=0; i<spec.length; i+=2) { |
| 4369 | int mask = (Integer)spec[i]; |
| 4370 | if ((val & mask) != 0) { |
| 4371 | pw.print(spec[i+1]); |
| 4372 | pw.print(" "); |
| 4373 | } |
| 4374 | } |
| 4375 | pw.print("]"); |
| 4376 | } |
| 4377 | |
| 4378 | static final Object[] FLAG_DUMP_SPEC = new Object[] { |
| 4379 | ApplicationInfo.FLAG_SYSTEM, "SYSTEM", |
| 4380 | ApplicationInfo.FLAG_DEBUGGABLE, "DEBUGGABLE", |
| 4381 | ApplicationInfo.FLAG_HAS_CODE, "HAS_CODE", |
| 4382 | ApplicationInfo.FLAG_PERSISTENT, "PERSISTENT", |
| 4383 | ApplicationInfo.FLAG_FACTORY_TEST, "FACTORY_TEST", |
| 4384 | ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING, "ALLOW_TASK_REPARENTING", |
| 4385 | ApplicationInfo.FLAG_ALLOW_CLEAR_USER_DATA, "ALLOW_CLEAR_USER_DATA", |
| 4386 | ApplicationInfo.FLAG_UPDATED_SYSTEM_APP, "UPDATED_SYSTEM_APP", |
| 4387 | ApplicationInfo.FLAG_TEST_ONLY, "TEST_ONLY", |
| 4388 | ApplicationInfo.FLAG_VM_SAFE_MODE, "VM_SAFE_MODE", |
| 4389 | ApplicationInfo.FLAG_ALLOW_BACKUP, "ALLOW_BACKUP", |
| 4390 | ApplicationInfo.FLAG_KILL_AFTER_RESTORE, "KILL_AFTER_RESTORE", |
| 4391 | ApplicationInfo.FLAG_RESTORE_ANY_VERSION, "RESTORE_ANY_VERSION", |
| 4392 | ApplicationInfo.FLAG_EXTERNAL_STORAGE, "EXTERNAL_STORAGE", |
| 4393 | ApplicationInfo.FLAG_LARGE_HEAP, "LARGE_HEAP", |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 4394 | }; |
| 4395 | |
Wale Ogunwale | 72a73e3 | 2016-10-13 12:16:39 -0700 | [diff] [blame] | 4396 | private static final Object[] PRIVATE_FLAG_DUMP_SPEC = new Object[] { |
Svet Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 4397 | ApplicationInfo.PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_RESIZEABLE, "PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_RESIZEABLE", |
| 4398 | ApplicationInfo.PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION, "PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION", |
| 4399 | ApplicationInfo.PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_UNRESIZEABLE, "PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_UNRESIZEABLE", |
Kevin Rocard | f91d50b | 2019-02-21 14:32:46 -0800 | [diff] [blame] | 4400 | ApplicationInfo.PRIVATE_FLAG_ALLOW_AUDIO_PLAYBACK_CAPTURE, "ALLOW_AUDIO_PLAYBACK_CAPTURE", |
Svet Ganov | d563e93 | 2019-04-14 13:07:41 -0700 | [diff] [blame] | 4401 | ApplicationInfo.PRIVATE_FLAG_REQUEST_LEGACY_EXTERNAL_STORAGE, "PRIVATE_FLAG_REQUEST_LEGACY_EXTERNAL_STORAGE", |
Svet Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 4402 | ApplicationInfo.PRIVATE_FLAG_BACKUP_IN_FOREGROUND, "BACKUP_IN_FOREGROUND", |
| 4403 | ApplicationInfo.PRIVATE_FLAG_CANT_SAVE_STATE, "CANT_SAVE_STATE", |
| 4404 | ApplicationInfo.PRIVATE_FLAG_DEFAULT_TO_DEVICE_PROTECTED_STORAGE, "DEFAULT_TO_DEVICE_PROTECTED_STORAGE", |
| 4405 | ApplicationInfo.PRIVATE_FLAG_DIRECT_BOOT_AWARE, "DIRECT_BOOT_AWARE", |
Svet Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 4406 | ApplicationInfo.PRIVATE_FLAG_HAS_DOMAIN_URLS, "HAS_DOMAIN_URLS", |
| 4407 | ApplicationInfo.PRIVATE_FLAG_HIDDEN, "HIDDEN", |
| 4408 | ApplicationInfo.PRIVATE_FLAG_INSTANT, "EPHEMERAL", |
| 4409 | ApplicationInfo.PRIVATE_FLAG_ISOLATED_SPLIT_LOADING, "ISOLATED_SPLIT_LOADING", |
| 4410 | ApplicationInfo.PRIVATE_FLAG_OEM, "OEM", |
| 4411 | ApplicationInfo.PRIVATE_FLAG_PARTIALLY_DIRECT_BOOT_AWARE, "PARTIALLY_DIRECT_BOOT_AWARE", |
| 4412 | ApplicationInfo.PRIVATE_FLAG_PRIVILEGED, "PRIVILEGED", |
| 4413 | ApplicationInfo.PRIVATE_FLAG_REQUIRED_FOR_SYSTEM_USER, "REQUIRED_FOR_SYSTEM_USER", |
| 4414 | ApplicationInfo.PRIVATE_FLAG_STATIC_SHARED_LIBRARY, "STATIC_SHARED_LIBRARY", |
Jiyong Park | 002fdbd | 2017-02-13 20:50:31 +0900 | [diff] [blame] | 4415 | ApplicationInfo.PRIVATE_FLAG_VENDOR, "VENDOR", |
Jaekyun Seok | 1713d9e | 2018-01-12 21:47:26 +0900 | [diff] [blame] | 4416 | ApplicationInfo.PRIVATE_FLAG_PRODUCT, "PRODUCT", |
Jeongik Cha | f662983 | 2019-07-04 21:12:06 +0900 | [diff] [blame] | 4417 | ApplicationInfo.PRIVATE_FLAG_SYSTEM_EXT, "SYSTEM_EXT", |
Svet Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 4418 | ApplicationInfo.PRIVATE_FLAG_VIRTUAL_PRELOAD, "VIRTUAL_PRELOAD", |
MÃ¥rten Kongstad | 48c24cf | 2019-02-25 10:54:09 +0100 | [diff] [blame] | 4419 | ApplicationInfo.PRIVATE_FLAG_ODM, "ODM", |
Joe Onorato | 20963df | 2012-01-04 18:13:24 -0800 | [diff] [blame] | 4420 | }; |
| 4421 | |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 4422 | void dumpVersionLPr(IndentingPrintWriter pw) { |
| 4423 | pw.increaseIndent(); |
| 4424 | for (int i= 0; i < mVersion.size(); i++) { |
| 4425 | final String volumeUuid = mVersion.keyAt(i); |
| 4426 | final VersionInfo ver = mVersion.valueAt(i); |
| 4427 | if (Objects.equals(StorageManager.UUID_PRIVATE_INTERNAL, volumeUuid)) { |
| 4428 | pw.println("Internal:"); |
| 4429 | } else if (Objects.equals(StorageManager.UUID_PRIMARY_PHYSICAL, volumeUuid)) { |
| 4430 | pw.println("External:"); |
| 4431 | } else { |
| 4432 | pw.println("UUID " + volumeUuid + ":"); |
| 4433 | } |
| 4434 | pw.increaseIndent(); |
| 4435 | pw.printPair("sdkVersion", ver.sdkVersion); |
| 4436 | pw.printPair("databaseVersion", ver.databaseVersion); |
| 4437 | pw.println(); |
| 4438 | pw.printPair("fingerprint", ver.fingerprint); |
| 4439 | pw.println(); |
| 4440 | pw.decreaseIndent(); |
| 4441 | } |
| 4442 | pw.decreaseIndent(); |
| 4443 | } |
| 4444 | |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 4445 | void dumpPackageLPr(PrintWriter pw, String prefix, String checkinTag, |
| 4446 | ArraySet<String> permissionNames, PackageSetting ps, SimpleDateFormat sdf, |
Makoto Onuki | 0a06858 | 2018-06-13 10:57:34 -0700 | [diff] [blame] | 4447 | Date date, List<UserInfo> users, boolean dumpAll, boolean dumpAllComponents) { |
Dianne Hackborn | 60dc0d9 | 2014-01-17 13:29:21 -0800 | [diff] [blame] | 4448 | if (checkinTag != null) { |
| 4449 | pw.print(checkinTag); |
| 4450 | pw.print(","); |
| 4451 | pw.print(ps.realName != null ? ps.realName : ps.name); |
| 4452 | pw.print(","); |
| 4453 | pw.print(ps.appId); |
| 4454 | pw.print(","); |
| 4455 | pw.print(ps.versionCode); |
| 4456 | pw.print(","); |
| 4457 | pw.print(ps.firstInstallTime); |
| 4458 | pw.print(","); |
| 4459 | pw.print(ps.lastUpdateTime); |
| 4460 | pw.print(","); |
| 4461 | pw.print(ps.installerPackageName != null ? ps.installerPackageName : "?"); |
| 4462 | pw.println(); |
Jeff Sharkey | c4d05fc | 2014-12-01 16:24:01 -0800 | [diff] [blame] | 4463 | if (ps.pkg != null) { |
| 4464 | pw.print(checkinTag); pw.print("-"); pw.print("splt,"); |
| 4465 | pw.print("base,"); |
| 4466 | pw.println(ps.pkg.baseRevisionCode); |
| 4467 | if (ps.pkg.splitNames != null) { |
| 4468 | for (int i = 0; i < ps.pkg.splitNames.length; i++) { |
| 4469 | pw.print(checkinTag); pw.print("-"); pw.print("splt,"); |
| 4470 | pw.print(ps.pkg.splitNames[i]); pw.print(","); |
| 4471 | pw.println(ps.pkg.splitRevisionCodes[i]); |
| 4472 | } |
| 4473 | } |
| 4474 | } |
Dianne Hackborn | 60dc0d9 | 2014-01-17 13:29:21 -0800 | [diff] [blame] | 4475 | for (UserInfo user : users) { |
| 4476 | pw.print(checkinTag); |
| 4477 | pw.print("-"); |
| 4478 | pw.print("usr"); |
| 4479 | pw.print(","); |
| 4480 | pw.print(user.id); |
| 4481 | pw.print(","); |
| 4482 | pw.print(ps.getInstalled(user.id) ? "I" : "i"); |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 4483 | pw.print(ps.getHidden(user.id) ? "B" : "b"); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4484 | pw.print(ps.getSuspended(user.id) ? "SU" : "su"); |
Dianne Hackborn | 60dc0d9 | 2014-01-17 13:29:21 -0800 | [diff] [blame] | 4485 | pw.print(ps.getStopped(user.id) ? "S" : "s"); |
| 4486 | pw.print(ps.getNotLaunched(user.id) ? "l" : "L"); |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 4487 | pw.print(ps.getInstantApp(user.id) ? "IA" : "ia"); |
Todd Kennedy | 5eb5a7d | 2017-08-01 07:42:47 -0700 | [diff] [blame] | 4488 | pw.print(ps.getVirtulalPreload(user.id) ? "VPI" : "vpi"); |
Ben Gruver | 1ab3d6e | 2017-12-07 13:45:08 -0800 | [diff] [blame] | 4489 | String harmfulAppWarning = ps.getHarmfulAppWarning(user.id); |
| 4490 | pw.print(harmfulAppWarning != null ? "HA" : "ha"); |
Dianne Hackborn | 60dc0d9 | 2014-01-17 13:29:21 -0800 | [diff] [blame] | 4491 | pw.print(","); |
| 4492 | pw.print(ps.getEnabled(user.id)); |
| 4493 | String lastDisabledAppCaller = ps.getLastDisabledAppCaller(user.id); |
| 4494 | pw.print(","); |
| 4495 | pw.print(lastDisabledAppCaller != null ? lastDisabledAppCaller : "?"); |
Ben Gruver | 1ab3d6e | 2017-12-07 13:45:08 -0800 | [diff] [blame] | 4496 | pw.print(","); |
Dianne Hackborn | 60dc0d9 | 2014-01-17 13:29:21 -0800 | [diff] [blame] | 4497 | pw.println(); |
| 4498 | } |
| 4499 | return; |
| 4500 | } |
| 4501 | |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 4502 | pw.print(prefix); pw.print("Package ["); |
| 4503 | pw.print(ps.realName != null ? ps.realName : ps.name); |
| 4504 | pw.print("] ("); |
| 4505 | pw.print(Integer.toHexString(System.identityHashCode(ps))); |
| 4506 | pw.println("):"); |
| 4507 | |
| 4508 | if (ps.realName != null) { |
| 4509 | pw.print(prefix); pw.print(" compat name="); |
| 4510 | pw.println(ps.name); |
| 4511 | } |
| 4512 | |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4513 | pw.print(prefix); pw.print(" userId="); pw.println(ps.appId); |
| 4514 | |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 4515 | if (ps.sharedUser != null) { |
| 4516 | pw.print(prefix); pw.print(" sharedUser="); pw.println(ps.sharedUser); |
| 4517 | } |
| 4518 | pw.print(prefix); pw.print(" pkg="); pw.println(ps.pkg); |
| 4519 | pw.print(prefix); pw.print(" codePath="); pw.println(ps.codePathString); |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 4520 | if (permissionNames == null) { |
| 4521 | pw.print(prefix); pw.print(" resourcePath="); pw.println(ps.resourcePathString); |
| 4522 | pw.print(prefix); pw.print(" legacyNativeLibraryDir="); |
| 4523 | pw.println(ps.legacyNativeLibraryPathString); |
| 4524 | pw.print(prefix); pw.print(" primaryCpuAbi="); pw.println(ps.primaryCpuAbiString); |
| 4525 | pw.print(prefix); pw.print(" secondaryCpuAbi="); pw.println(ps.secondaryCpuAbiString); |
| 4526 | } |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 4527 | pw.print(prefix); pw.print(" versionCode="); pw.print(ps.versionCode); |
| 4528 | if (ps.pkg != null) { |
Todd Kennedy | 89d6018 | 2016-03-11 11:18:32 -0800 | [diff] [blame] | 4529 | pw.print(" minSdk="); pw.print(ps.pkg.applicationInfo.minSdkVersion); |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 4530 | pw.print(" targetSdk="); pw.print(ps.pkg.applicationInfo.targetSdkVersion); |
| 4531 | } |
| 4532 | pw.println(); |
| 4533 | if (ps.pkg != null) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4534 | if (ps.pkg.parentPackage != null) { |
| 4535 | PackageParser.Package parentPkg = ps.pkg.parentPackage; |
| 4536 | PackageSetting pps = mPackages.get(parentPkg.packageName); |
| 4537 | if (pps == null || !pps.codePathString.equals(parentPkg.codePath)) { |
| 4538 | pps = mDisabledSysPackages.get(parentPkg.packageName); |
| 4539 | } |
| 4540 | if (pps != null) { |
| 4541 | pw.print(prefix); pw.print(" parentPackage="); |
| 4542 | pw.println(pps.realName != null ? pps.realName : pps.name); |
| 4543 | } |
| 4544 | } else if (ps.pkg.childPackages != null) { |
| 4545 | pw.print(prefix); pw.print(" childPackages=["); |
| 4546 | final int childCount = ps.pkg.childPackages.size(); |
| 4547 | for (int i = 0; i < childCount; i++) { |
| 4548 | PackageParser.Package childPkg = ps.pkg.childPackages.get(i); |
| 4549 | PackageSetting cps = mPackages.get(childPkg.packageName); |
| 4550 | if (cps == null || !cps.codePathString.equals(childPkg.codePath)) { |
| 4551 | cps = mDisabledSysPackages.get(childPkg.packageName); |
| 4552 | } |
| 4553 | if (cps != null) { |
| 4554 | if (i > 0) { |
| 4555 | pw.print(", "); |
| 4556 | } |
| 4557 | pw.print(cps.realName != null ? cps.realName : cps.name); |
| 4558 | } |
| 4559 | } |
| 4560 | pw.println("]"); |
| 4561 | } |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 4562 | pw.print(prefix); pw.print(" versionName="); pw.println(ps.pkg.mVersionName); |
Jeff Sharkey | c4d05fc | 2014-12-01 16:24:01 -0800 | [diff] [blame] | 4563 | pw.print(prefix); pw.print(" splits="); dumpSplitNames(pw, ps.pkg); pw.println(); |
Patrick Baumann | 420d58a | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 4564 | final int apkSigningVersion = ps.pkg.mSigningDetails.signatureSchemeVersion; |
| 4565 | pw.print(prefix); pw.print(" apkSigningVersion="); pw.println(apkSigningVersion); |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 4566 | pw.print(prefix); pw.print(" applicationInfo="); |
| 4567 | pw.println(ps.pkg.applicationInfo.toString()); |
| 4568 | pw.print(prefix); pw.print(" flags="); printFlags(pw, ps.pkg.applicationInfo.flags, |
| 4569 | FLAG_DUMP_SPEC); pw.println(); |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 4570 | if (ps.pkg.applicationInfo.privateFlags != 0) { |
| 4571 | pw.print(prefix); pw.print(" privateFlags="); printFlags(pw, |
| 4572 | ps.pkg.applicationInfo.privateFlags, PRIVATE_FLAG_DUMP_SPEC); pw.println(); |
| 4573 | } |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 4574 | pw.print(prefix); pw.print(" dataDir="); pw.println(ps.pkg.applicationInfo.dataDir); |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 4575 | pw.print(prefix); pw.print(" supportsScreens=["); |
| 4576 | boolean first = true; |
| 4577 | if ((ps.pkg.applicationInfo.flags & ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS) != 0) { |
| 4578 | if (!first) |
| 4579 | pw.print(", "); |
| 4580 | first = false; |
| 4581 | pw.print("small"); |
| 4582 | } |
| 4583 | if ((ps.pkg.applicationInfo.flags & ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS) != 0) { |
| 4584 | if (!first) |
| 4585 | pw.print(", "); |
| 4586 | first = false; |
| 4587 | pw.print("medium"); |
| 4588 | } |
| 4589 | if ((ps.pkg.applicationInfo.flags & ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS) != 0) { |
| 4590 | if (!first) |
| 4591 | pw.print(", "); |
| 4592 | first = false; |
| 4593 | pw.print("large"); |
| 4594 | } |
| 4595 | if ((ps.pkg.applicationInfo.flags & ApplicationInfo.FLAG_SUPPORTS_XLARGE_SCREENS) != 0) { |
| 4596 | if (!first) |
| 4597 | pw.print(", "); |
| 4598 | first = false; |
| 4599 | pw.print("xlarge"); |
| 4600 | } |
| 4601 | if ((ps.pkg.applicationInfo.flags & ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS) != 0) { |
| 4602 | if (!first) |
| 4603 | pw.print(", "); |
| 4604 | first = false; |
| 4605 | pw.print("resizeable"); |
| 4606 | } |
| 4607 | if ((ps.pkg.applicationInfo.flags & ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES) != 0) { |
| 4608 | if (!first) |
| 4609 | pw.print(", "); |
| 4610 | first = false; |
| 4611 | pw.print("anyDensity"); |
| 4612 | } |
| 4613 | pw.println("]"); |
| 4614 | if (ps.pkg.libraryNames != null && ps.pkg.libraryNames.size() > 0) { |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 4615 | pw.print(prefix); pw.println(" dynamic libraries:"); |
| 4616 | for (int i = 0; i<ps.pkg.libraryNames.size(); i++) { |
| 4617 | pw.print(prefix); pw.print(" "); |
| 4618 | pw.println(ps.pkg.libraryNames.get(i)); |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 4619 | } |
| 4620 | } |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 4621 | if (ps.pkg.staticSharedLibName != null) { |
| 4622 | pw.print(prefix); pw.println(" static library:"); |
| 4623 | pw.print(prefix); pw.print(" "); |
| 4624 | pw.print("name:"); pw.print(ps.pkg.staticSharedLibName); |
| 4625 | pw.print(" version:"); pw.println(ps.pkg.staticSharedLibVersion); |
| 4626 | } |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 4627 | if (ps.pkg.usesLibraries != null && ps.pkg.usesLibraries.size() > 0) { |
| 4628 | pw.print(prefix); pw.println(" usesLibraries:"); |
| 4629 | for (int i=0; i<ps.pkg.usesLibraries.size(); i++) { |
| 4630 | pw.print(prefix); pw.print(" "); pw.println(ps.pkg.usesLibraries.get(i)); |
| 4631 | } |
| 4632 | } |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 4633 | if (ps.pkg.usesStaticLibraries != null |
| 4634 | && ps.pkg.usesStaticLibraries.size() > 0) { |
| 4635 | pw.print(prefix); pw.println(" usesStaticLibraries:"); |
| 4636 | for (int i=0; i<ps.pkg.usesStaticLibraries.size(); i++) { |
| 4637 | pw.print(prefix); pw.print(" "); |
| 4638 | pw.print(ps.pkg.usesStaticLibraries.get(i)); pw.print(" version:"); |
| 4639 | pw.println(ps.pkg.usesStaticLibrariesVersions[i]); |
| 4640 | } |
| 4641 | } |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 4642 | if (ps.pkg.usesOptionalLibraries != null |
| 4643 | && ps.pkg.usesOptionalLibraries.size() > 0) { |
| 4644 | pw.print(prefix); pw.println(" usesOptionalLibraries:"); |
| 4645 | for (int i=0; i<ps.pkg.usesOptionalLibraries.size(); i++) { |
| 4646 | pw.print(prefix); pw.print(" "); |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 4647 | pw.println(ps.pkg.usesOptionalLibraries.get(i)); |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 4648 | } |
| 4649 | } |
| 4650 | if (ps.pkg.usesLibraryFiles != null |
| 4651 | && ps.pkg.usesLibraryFiles.length > 0) { |
| 4652 | pw.print(prefix); pw.println(" usesLibraryFiles:"); |
| 4653 | for (int i=0; i<ps.pkg.usesLibraryFiles.length; i++) { |
| 4654 | pw.print(prefix); pw.print(" "); pw.println(ps.pkg.usesLibraryFiles[i]); |
| 4655 | } |
| 4656 | } |
| 4657 | } |
| 4658 | pw.print(prefix); pw.print(" timeStamp="); |
| 4659 | date.setTime(ps.timeStamp); |
| 4660 | pw.println(sdf.format(date)); |
| 4661 | pw.print(prefix); pw.print(" firstInstallTime="); |
| 4662 | date.setTime(ps.firstInstallTime); |
| 4663 | pw.println(sdf.format(date)); |
| 4664 | pw.print(prefix); pw.print(" lastUpdateTime="); |
| 4665 | date.setTime(ps.lastUpdateTime); |
| 4666 | pw.println(sdf.format(date)); |
| 4667 | if (ps.installerPackageName != null) { |
| 4668 | pw.print(prefix); pw.print(" installerPackageName="); |
| 4669 | pw.println(ps.installerPackageName); |
| 4670 | } |
Jeff Sharkey | b2b9ab8 | 2015-04-05 21:10:42 -0700 | [diff] [blame] | 4671 | if (ps.volumeUuid != null) { |
| 4672 | pw.print(prefix); pw.print(" volumeUuid="); |
| 4673 | pw.println(ps.volumeUuid); |
| 4674 | } |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 4675 | pw.print(prefix); pw.print(" signatures="); pw.println(ps.signatures); |
Svetoslav | cf959f6 | 2015-03-26 20:53:34 -0700 | [diff] [blame] | 4676 | pw.print(prefix); pw.print(" installPermissionsFixed="); |
| 4677 | pw.print(ps.installPermissionsFixed); |
Todd Kennedy | af6f195 | 2018-02-13 11:09:50 -0800 | [diff] [blame] | 4678 | pw.println(); |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 4679 | pw.print(prefix); pw.print(" pkgFlags="); printFlags(pw, ps.pkgFlags, FLAG_DUMP_SPEC); |
| 4680 | pw.println(); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4681 | |
Patrick Baumann | 7438dcb | 2018-05-08 14:31:45 -0700 | [diff] [blame] | 4682 | if (ps.pkg != null && ps.pkg.mOverlayTarget != null) { |
Adrian Roos | c84df77 | 2018-01-19 21:20:22 +0100 | [diff] [blame] | 4683 | pw.print(prefix); pw.print(" overlayTarget="); pw.println(ps.pkg.mOverlayTarget); |
| 4684 | pw.print(prefix); pw.print(" overlayCategory="); pw.println(ps.pkg.mOverlayCategory); |
| 4685 | } |
| 4686 | |
Dianne Hackborn | cfbfafe | 2015-07-21 16:57:51 -0700 | [diff] [blame] | 4687 | if (ps.pkg != null && ps.pkg.permissions != null && ps.pkg.permissions.size() > 0) { |
| 4688 | final ArrayList<PackageParser.Permission> perms = ps.pkg.permissions; |
| 4689 | pw.print(prefix); pw.println(" declared permissions:"); |
| 4690 | for (int i=0; i<perms.size(); i++) { |
| 4691 | PackageParser.Permission perm = perms.get(i); |
| 4692 | if (permissionNames != null |
| 4693 | && !permissionNames.contains(perm.info.name)) { |
| 4694 | continue; |
| 4695 | } |
| 4696 | pw.print(prefix); pw.print(" "); pw.print(perm.info.name); |
| 4697 | pw.print(": prot="); |
| 4698 | pw.print(PermissionInfo.protectionToString(perm.info.protectionLevel)); |
| 4699 | if ((perm.info.flags&PermissionInfo.FLAG_COSTS_MONEY) != 0) { |
| 4700 | pw.print(", COSTS_MONEY"); |
| 4701 | } |
Svet Ganov | 2a1376d | 2016-02-22 17:20:35 -0800 | [diff] [blame] | 4702 | if ((perm.info.flags&PermissionInfo.FLAG_REMOVED) != 0) { |
Svet Ganov | 52153f4 | 2015-08-11 08:59:12 -0700 | [diff] [blame] | 4703 | pw.print(", HIDDEN"); |
Svet Ganov | 3e0be74 | 2015-08-07 23:06:00 -0700 | [diff] [blame] | 4704 | } |
Dianne Hackborn | cfbfafe | 2015-07-21 16:57:51 -0700 | [diff] [blame] | 4705 | if ((perm.info.flags&PermissionInfo.FLAG_INSTALLED) != 0) { |
| 4706 | pw.print(", INSTALLED"); |
| 4707 | } |
| 4708 | pw.println(); |
| 4709 | } |
| 4710 | } |
| 4711 | |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 4712 | if ((permissionNames != null || dumpAll) && ps.pkg != null |
| 4713 | && ps.pkg.requestedPermissions != null |
Dianne Hackborn | 9f5b0a2 | 2015-08-13 18:25:20 -0700 | [diff] [blame] | 4714 | && ps.pkg.requestedPermissions.size() > 0) { |
| 4715 | final ArrayList<String> perms = ps.pkg.requestedPermissions; |
| 4716 | pw.print(prefix); pw.println(" requested permissions:"); |
| 4717 | for (int i=0; i<perms.size(); i++) { |
| 4718 | String perm = perms.get(i); |
| 4719 | if (permissionNames != null |
| 4720 | && !permissionNames.contains(perm)) { |
| 4721 | continue; |
| 4722 | } |
Svet Ganov | d8eb8b2 | 2019-04-05 18:52:08 -0700 | [diff] [blame] | 4723 | pw.print(prefix); pw.print(" "); pw.print(perm); |
| 4724 | final BasePermission bp = mPermissions.getPermission(perm); |
Svet Ganov | d563e93 | 2019-04-14 13:07:41 -0700 | [diff] [blame] | 4725 | if (bp != null && bp.isHardOrSoftRestricted()) { |
Svet Ganov | d8eb8b2 | 2019-04-05 18:52:08 -0700 | [diff] [blame] | 4726 | pw.println(": restricted=true"); |
| 4727 | } else { |
| 4728 | pw.println(); |
| 4729 | } |
Dianne Hackborn | 9f5b0a2 | 2015-08-13 18:25:20 -0700 | [diff] [blame] | 4730 | } |
| 4731 | } |
| 4732 | |
| 4733 | if (ps.sharedUser == null || permissionNames != null || dumpAll) { |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4734 | PermissionsState permissionsState = ps.getPermissionsState(); |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 4735 | dumpInstallPermissionsLPr(pw, prefix + " ", permissionNames, permissionsState); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4736 | } |
| 4737 | |
Makoto Onuki | 0a06858 | 2018-06-13 10:57:34 -0700 | [diff] [blame] | 4738 | if (dumpAllComponents) { |
| 4739 | dumpComponents(pw, prefix + " ", ps); |
| 4740 | } |
| 4741 | |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 4742 | for (UserInfo user : users) { |
| 4743 | pw.print(prefix); pw.print(" User "); pw.print(user.id); pw.print(": "); |
Jeff Sharkey | 4288419 | 2016-04-09 16:12:01 -0600 | [diff] [blame] | 4744 | pw.print("ceDataInode="); |
| 4745 | pw.print(ps.getCeDataInode(user.id)); |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 4746 | pw.print(" installed="); |
| 4747 | pw.print(ps.getInstalled(user.id)); |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 4748 | pw.print(" hidden="); |
| 4749 | pw.print(ps.getHidden(user.id)); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4750 | pw.print(" suspended="); |
| 4751 | pw.print(ps.getSuspended(user.id)); |
Suprabh Shukla | 021b57a | 2018-03-08 18:21:50 -0800 | [diff] [blame] | 4752 | if (ps.getSuspended(user.id)) { |
Suprabh Shukla | 3c3af14 | 2018-03-30 00:28:37 -0700 | [diff] [blame] | 4753 | final PackageUserState pus = ps.readUserState(user.id); |
Suprabh Shukla | 021b57a | 2018-03-08 18:21:50 -0800 | [diff] [blame] | 4754 | pw.print(" suspendingPackage="); |
Suprabh Shukla | 3c3af14 | 2018-03-30 00:28:37 -0700 | [diff] [blame] | 4755 | pw.print(pus.suspendingPackage); |
Suprabh Shukla | 389cb6f | 2018-10-01 18:20:39 -0700 | [diff] [blame] | 4756 | pw.print(" dialogInfo="); |
| 4757 | pw.print(pus.dialogInfo); |
Suprabh Shukla | 021b57a | 2018-03-08 18:21:50 -0800 | [diff] [blame] | 4758 | } |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 4759 | pw.print(" stopped="); |
| 4760 | pw.print(ps.getStopped(user.id)); |
| 4761 | pw.print(" notLaunched="); |
| 4762 | pw.print(ps.getNotLaunched(user.id)); |
| 4763 | pw.print(" enabled="); |
Fyodor Kupolov | 09546ff | 2017-04-03 17:45:50 -0700 | [diff] [blame] | 4764 | pw.print(ps.getEnabled(user.id)); |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 4765 | pw.print(" instant="); |
Dianne Hackborn | c50a108 | 2017-08-15 14:10:39 -0700 | [diff] [blame] | 4766 | pw.print(ps.getInstantApp(user.id)); |
Todd Kennedy | 5eb5a7d | 2017-08-01 07:42:47 -0700 | [diff] [blame] | 4767 | pw.print(" virtual="); |
| 4768 | pw.println(ps.getVirtulalPreload(user.id)); |
Todd Kennedy | b274947 | 2017-06-13 08:24:32 -0700 | [diff] [blame] | 4769 | |
| 4770 | String[] overlayPaths = ps.getOverlayPaths(user.id); |
| 4771 | if (overlayPaths != null && overlayPaths.length > 0) { |
Todd Kennedy | 560830c | 2017-06-16 13:55:13 -0700 | [diff] [blame] | 4772 | pw.print(prefix); pw.println(" overlay paths:"); |
Todd Kennedy | b274947 | 2017-06-13 08:24:32 -0700 | [diff] [blame] | 4773 | for (String path : overlayPaths) { |
Todd Kennedy | 560830c | 2017-06-16 13:55:13 -0700 | [diff] [blame] | 4774 | pw.print(prefix); pw.print(" "); pw.println(path); |
Todd Kennedy | b274947 | 2017-06-13 08:24:32 -0700 | [diff] [blame] | 4775 | } |
| 4776 | } |
| 4777 | |
Dianne Hackborn | 3fa3c28a | 2013-03-26 16:15:41 -0700 | [diff] [blame] | 4778 | String lastDisabledAppCaller = ps.getLastDisabledAppCaller(user.id); |
| 4779 | if (lastDisabledAppCaller != null) { |
| 4780 | pw.print(prefix); pw.print(" lastDisabledCaller: "); |
| 4781 | pw.println(lastDisabledAppCaller); |
| 4782 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4783 | |
| 4784 | if (ps.sharedUser == null) { |
| 4785 | PermissionsState permissionsState = ps.getPermissionsState(); |
| 4786 | dumpGidsLPr(pw, prefix + " ", permissionsState.computeGids(user.id)); |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 4787 | dumpRuntimePermissionsLPr(pw, prefix + " ", permissionNames, permissionsState |
Dianne Hackborn | 9f5b0a2 | 2015-08-13 18:25:20 -0700 | [diff] [blame] | 4788 | .getRuntimePermissionStates(user.id), dumpAll); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4789 | } |
| 4790 | |
Ben Gruver | 1ab3d6e | 2017-12-07 13:45:08 -0800 | [diff] [blame] | 4791 | String harmfulAppWarning = ps.getHarmfulAppWarning(user.id); |
| 4792 | if (harmfulAppWarning != null) { |
| 4793 | pw.print(prefix); pw.print(" harmfulAppWarning: "); |
| 4794 | pw.println(harmfulAppWarning); |
| 4795 | } |
| 4796 | |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 4797 | if (permissionNames == null) { |
| 4798 | ArraySet<String> cmp = ps.getDisabledComponents(user.id); |
| 4799 | if (cmp != null && cmp.size() > 0) { |
| 4800 | pw.print(prefix); pw.println(" disabledComponents:"); |
| 4801 | for (String s : cmp) { |
Dianne Hackborn | cfbfafe | 2015-07-21 16:57:51 -0700 | [diff] [blame] | 4802 | pw.print(prefix); pw.print(" "); pw.println(s); |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 4803 | } |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 4804 | } |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 4805 | cmp = ps.getEnabledComponents(user.id); |
| 4806 | if (cmp != null && cmp.size() > 0) { |
| 4807 | pw.print(prefix); pw.println(" enabledComponents:"); |
| 4808 | for (String s : cmp) { |
Dianne Hackborn | cfbfafe | 2015-07-21 16:57:51 -0700 | [diff] [blame] | 4809 | pw.print(prefix); pw.print(" "); pw.println(s); |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 4810 | } |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 4811 | } |
| 4812 | } |
| 4813 | } |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 4814 | } |
| 4815 | |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 4816 | void dumpPackagesLPr(PrintWriter pw, String packageName, ArraySet<String> permissionNames, |
| 4817 | DumpState dumpState, boolean checkin) { |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4818 | final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| 4819 | final Date date = new Date(); |
| 4820 | boolean printedSomething = false; |
Makoto Onuki | 0a06858 | 2018-06-13 10:57:34 -0700 | [diff] [blame] | 4821 | final boolean dumpAllComponents = |
| 4822 | dumpState.isOptionEnabled(DumpState.OPTION_DUMP_ALL_COMPONENTS); |
Todd Kennedy | 13715d5 | 2016-08-01 13:38:57 -0700 | [diff] [blame] | 4823 | List<UserInfo> users = getAllUsers(UserManagerService.getInstance()); |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4824 | for (final PackageSetting ps : mPackages.values()) { |
| 4825 | if (packageName != null && !packageName.equals(ps.realName) |
| 4826 | && !packageName.equals(ps.name)) { |
| 4827 | continue; |
| 4828 | } |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 4829 | if (permissionNames != null |
| 4830 | && !ps.getPermissionsState().hasRequestedPermission(permissionNames)) { |
| 4831 | continue; |
| 4832 | } |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4833 | |
Dianne Hackborn | 60dc0d9 | 2014-01-17 13:29:21 -0800 | [diff] [blame] | 4834 | if (!checkin && packageName != null) { |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4835 | dumpState.setSharedUser(ps.sharedUser); |
| 4836 | } |
| 4837 | |
Dianne Hackborn | 60dc0d9 | 2014-01-17 13:29:21 -0800 | [diff] [blame] | 4838 | if (!checkin && !printedSomething) { |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4839 | if (dumpState.onTitlePrinted()) |
Dianne Hackborn | cbfd23e | 2013-06-11 14:26:53 -0700 | [diff] [blame] | 4840 | pw.println(); |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4841 | pw.println("Packages:"); |
| 4842 | printedSomething = true; |
| 4843 | } |
Dianne Hackborn | 9f5b0a2 | 2015-08-13 18:25:20 -0700 | [diff] [blame] | 4844 | dumpPackageLPr(pw, " ", checkin ? "pkg" : null, permissionNames, ps, sdf, date, users, |
Makoto Onuki | 0a06858 | 2018-06-13 10:57:34 -0700 | [diff] [blame] | 4845 | packageName != null, dumpAllComponents); |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4846 | } |
| 4847 | |
| 4848 | printedSomething = false; |
Dianne Hackborn | 9f5b0a2 | 2015-08-13 18:25:20 -0700 | [diff] [blame] | 4849 | if (mRenamedPackages.size() > 0 && permissionNames == null) { |
Andy McFadden | 2f36229 | 2012-01-20 14:43:38 -0800 | [diff] [blame] | 4850 | for (final Map.Entry<String, String> e : mRenamedPackages.entrySet()) { |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4851 | if (packageName != null && !packageName.equals(e.getKey()) |
| 4852 | && !packageName.equals(e.getValue())) { |
| 4853 | continue; |
| 4854 | } |
Dianne Hackborn | 60dc0d9 | 2014-01-17 13:29:21 -0800 | [diff] [blame] | 4855 | if (!checkin) { |
| 4856 | if (!printedSomething) { |
| 4857 | if (dumpState.onTitlePrinted()) |
| 4858 | pw.println(); |
| 4859 | pw.println("Renamed packages:"); |
| 4860 | printedSomething = true; |
| 4861 | } |
| 4862 | pw.print(" "); |
| 4863 | } else { |
| 4864 | pw.print("ren,"); |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4865 | } |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4866 | pw.print(e.getKey()); |
Dianne Hackborn | 60dc0d9 | 2014-01-17 13:29:21 -0800 | [diff] [blame] | 4867 | pw.print(checkin ? " -> " : ","); |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4868 | pw.println(e.getValue()); |
| 4869 | } |
| 4870 | } |
| 4871 | |
| 4872 | printedSomething = false; |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 4873 | if (mDisabledSysPackages.size() > 0 && permissionNames == null) { |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4874 | for (final PackageSetting ps : mDisabledSysPackages.values()) { |
| 4875 | if (packageName != null && !packageName.equals(ps.realName) |
| 4876 | && !packageName.equals(ps.name)) { |
| 4877 | continue; |
| 4878 | } |
Dianne Hackborn | 60dc0d9 | 2014-01-17 13:29:21 -0800 | [diff] [blame] | 4879 | if (!checkin && !printedSomething) { |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4880 | if (dumpState.onTitlePrinted()) |
Dianne Hackborn | cbfd23e | 2013-06-11 14:26:53 -0700 | [diff] [blame] | 4881 | pw.println(); |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4882 | pw.println("Hidden system packages:"); |
| 4883 | printedSomething = true; |
| 4884 | } |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 4885 | dumpPackageLPr(pw, " ", checkin ? "dis" : null, permissionNames, ps, sdf, date, |
Makoto Onuki | 0a06858 | 2018-06-13 10:57:34 -0700 | [diff] [blame] | 4886 | users, packageName != null, dumpAllComponents); |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4887 | } |
| 4888 | } |
| 4889 | } |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 4890 | |
Netta P | 426cbef | 2017-02-10 14:38:39 -0800 | [diff] [blame] | 4891 | void dumpPackagesProto(ProtoOutputStream proto) { |
| 4892 | List<UserInfo> users = getAllUsers(UserManagerService.getInstance()); |
| 4893 | |
| 4894 | final int count = mPackages.size(); |
| 4895 | for (int i = 0; i < count; i++) { |
| 4896 | final PackageSetting ps = mPackages.valueAt(i); |
| 4897 | ps.writeToProto(proto, PackageServiceDumpProto.PACKAGES, users); |
| 4898 | } |
| 4899 | } |
| 4900 | |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 4901 | void dumpPermissionsLPr(PrintWriter pw, String packageName, ArraySet<String> permissionNames, |
| 4902 | DumpState dumpState) { |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 4903 | mPermissions.dumpPermissions(pw, packageName, permissionNames, |
| 4904 | (mReadExternalStorageEnforced == Boolean.TRUE), dumpState); |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4905 | } |
Jeff Sharkey | 1c27576a | 2012-04-11 19:07:08 -0700 | [diff] [blame] | 4906 | |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 4907 | void dumpSharedUsersLPr(PrintWriter pw, String packageName, ArraySet<String> permissionNames, |
| 4908 | DumpState dumpState, boolean checkin) { |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4909 | boolean printedSomething = false; |
| 4910 | for (SharedUserSetting su : mSharedUsers.values()) { |
| 4911 | if (packageName != null && su != dumpState.getSharedUser()) { |
| 4912 | continue; |
| 4913 | } |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 4914 | if (permissionNames != null |
| 4915 | && !su.getPermissionsState().hasRequestedPermission(permissionNames)) { |
| 4916 | continue; |
| 4917 | } |
Dianne Hackborn | d052a94 | 2014-11-21 15:23:13 -0800 | [diff] [blame] | 4918 | if (!checkin) { |
| 4919 | if (!printedSomething) { |
| 4920 | if (dumpState.onTitlePrinted()) |
| 4921 | pw.println(); |
| 4922 | pw.println("Shared users:"); |
| 4923 | printedSomething = true; |
| 4924 | } |
Todd Kennedy | 0d80c41 | 2019-05-10 08:23:06 -0700 | [diff] [blame] | 4925 | |
Dianne Hackborn | d052a94 | 2014-11-21 15:23:13 -0800 | [diff] [blame] | 4926 | pw.print(" SharedUser ["); |
| 4927 | pw.print(su.name); |
| 4928 | pw.print("] ("); |
| 4929 | pw.print(Integer.toHexString(System.identityHashCode(su))); |
Todd Kennedy | 0d80c41 | 2019-05-10 08:23:06 -0700 | [diff] [blame] | 4930 | pw.println("):"); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4931 | |
| 4932 | String prefix = " "; |
| 4933 | pw.print(prefix); pw.print("userId="); pw.println(su.userId); |
| 4934 | |
Todd Kennedy | 0d80c41 | 2019-05-10 08:23:06 -0700 | [diff] [blame] | 4935 | pw.print(prefix); pw.println("Packages"); |
| 4936 | final int numPackages = su.packages.size(); |
| 4937 | for (int i = 0; i < numPackages; i++) { |
| 4938 | final PackageSetting ps = su.packages.valueAt(i); |
| 4939 | if (ps != null) { |
| 4940 | pw.print(prefix + " "); pw.println(ps.toString()); |
| 4941 | } else { |
| 4942 | pw.print(prefix + " "); pw.println("NULL?!"); |
| 4943 | } |
| 4944 | } |
| 4945 | |
| 4946 | if (dumpState.isOptionEnabled(DumpState.OPTION_SKIP_PERMISSIONS)) { |
| 4947 | continue; |
| 4948 | } |
| 4949 | |
| 4950 | final PermissionsState permissionsState = su.getPermissionsState(); |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 4951 | dumpInstallPermissionsLPr(pw, prefix, permissionNames, permissionsState); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4952 | |
| 4953 | for (int userId : UserManagerService.getInstance().getUserIds()) { |
| 4954 | final int[] gids = permissionsState.computeGids(userId); |
Todd Kennedy | 0d80c41 | 2019-05-10 08:23:06 -0700 | [diff] [blame] | 4955 | final List<PermissionState> permissions = |
| 4956 | permissionsState.getRuntimePermissionStates(userId); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4957 | if (!ArrayUtils.isEmpty(gids) || !permissions.isEmpty()) { |
| 4958 | pw.print(prefix); pw.print("User "); pw.print(userId); pw.println(": "); |
| 4959 | dumpGidsLPr(pw, prefix + " ", gids); |
Todd Kennedy | 0d80c41 | 2019-05-10 08:23:06 -0700 | [diff] [blame] | 4960 | dumpRuntimePermissionsLPr(pw, prefix + " ", permissionNames, |
| 4961 | permissions, packageName != null); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4962 | } |
Dianne Hackborn | d052a94 | 2014-11-21 15:23:13 -0800 | [diff] [blame] | 4963 | } |
| 4964 | } else { |
| 4965 | 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] | 4966 | } |
| 4967 | } |
| 4968 | } |
| 4969 | |
Netta P | 426cbef | 2017-02-10 14:38:39 -0800 | [diff] [blame] | 4970 | void dumpSharedUsersProto(ProtoOutputStream proto) { |
| 4971 | final int count = mSharedUsers.size(); |
| 4972 | for (int i = 0; i < count; i++) { |
Yi Jin | d6759d4 | 2017-10-12 15:08:49 -0700 | [diff] [blame] | 4973 | mSharedUsers.valueAt(i).writeToProto(proto, PackageServiceDumpProto.SHARED_USERS); |
Netta P | 426cbef | 2017-02-10 14:38:39 -0800 | [diff] [blame] | 4974 | } |
| 4975 | } |
| 4976 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4977 | void dumpReadMessagesLPr(PrintWriter pw, DumpState dumpState) { |
| 4978 | pw.println("Settings parse messages:"); |
| 4979 | pw.print(mReadMessages.toString()); |
| 4980 | } |
Jeff Sharkey | c4d05fc | 2014-12-01 16:24:01 -0800 | [diff] [blame] | 4981 | |
| 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)); |
Svet Ganov | d8eb8b2 | 2019-04-05 18:52:08 -0700 | [diff] [blame] | 5041 | if (flags != 0) { |
| 5042 | flagsString.append('|'); |
| 5043 | } |
| 5044 | |
Svet Ganov | 77ab6a8 | 2015-07-03 12:03:02 -0700 | [diff] [blame] | 5045 | } |
Dianne Hackborn | cfbfafe | 2015-07-21 16:57:51 -0700 | [diff] [blame] | 5046 | if (flagsString != null) { |
| 5047 | flagsString.append(']'); |
| 5048 | return flagsString.toString(); |
| 5049 | } else { |
| 5050 | return ""; |
| 5051 | } |
Svet Ganov | 77ab6a8 | 2015-07-03 12:03:02 -0700 | [diff] [blame] | 5052 | } |
| 5053 | |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 5054 | void dumpInstallPermissionsLPr(PrintWriter pw, String prefix, ArraySet<String> permissionNames, |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5055 | PermissionsState permissionsState) { |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5056 | List<PermissionState> permissionStates = permissionsState.getInstallPermissionStates(); |
| 5057 | if (!permissionStates.isEmpty()) { |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5058 | pw.print(prefix); pw.println("install permissions:"); |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5059 | for (PermissionState permissionState : permissionStates) { |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 5060 | if (permissionNames != null |
| 5061 | && !permissionNames.contains(permissionState.getName())) { |
| 5062 | continue; |
| 5063 | } |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5064 | pw.print(prefix); pw.print(" "); pw.print(permissionState.getName()); |
Dianne Hackborn | cfbfafe | 2015-07-21 16:57:51 -0700 | [diff] [blame] | 5065 | pw.print(": granted="); pw.print(permissionState.isGranted()); |
| 5066 | pw.println(permissionFlagsToString(", flags=", |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5067 | permissionState.getFlags())); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5068 | } |
| 5069 | } |
| 5070 | } |
| 5071 | |
Makoto Onuki | 0a06858 | 2018-06-13 10:57:34 -0700 | [diff] [blame] | 5072 | void dumpComponents(PrintWriter pw, String prefix, PackageSetting ps) { |
| 5073 | dumpComponents(pw, prefix, ps, "activities:", ps.pkg.activities); |
| 5074 | dumpComponents(pw, prefix, ps, "services:", ps.pkg.services); |
| 5075 | dumpComponents(pw, prefix, ps, "receivers:", ps.pkg.receivers); |
| 5076 | dumpComponents(pw, prefix, ps, "providers:", ps.pkg.providers); |
| 5077 | dumpComponents(pw, prefix, ps, "instrumentations:", ps.pkg.instrumentation); |
| 5078 | } |
| 5079 | |
| 5080 | void dumpComponents(PrintWriter pw, String prefix, PackageSetting ps, |
| 5081 | String label, List<? extends PackageParser.Component<?>> list) { |
| 5082 | final int size = CollectionUtils.size(list); |
| 5083 | if (size == 0) { |
| 5084 | return; |
| 5085 | } |
| 5086 | pw.print(prefix);pw.println(label); |
| 5087 | for (int i = 0; i < size; i++) { |
| 5088 | final PackageParser.Component<?> component = list.get(i); |
| 5089 | pw.print(prefix);pw.print(" "); |
| 5090 | pw.println(component.getComponentName().flattenToShortString()); |
| 5091 | } |
| 5092 | } |
| 5093 | |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5094 | public void writeRuntimePermissionsForUserLPr(int userId, boolean sync) { |
| 5095 | if (sync) { |
| 5096 | mRuntimePermissionsPersistence.writePermissionsForUserSyncLPr(userId); |
| 5097 | } else { |
| 5098 | mRuntimePermissionsPersistence.writePermissionsForUserAsyncLPr(userId); |
| 5099 | } |
| 5100 | } |
| 5101 | |
| 5102 | private final class RuntimePermissionPersistence { |
| 5103 | private static final long WRITE_PERMISSIONS_DELAY_MILLIS = 200; |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5104 | private static final long MAX_WRITE_PERMISSIONS_DELAY_MILLIS = 2000; |
| 5105 | |
Philip P. Moltmann | 1ae81a5 | 2019-05-21 15:31:36 -0700 | [diff] [blame] | 5106 | private static final int UPGRADE_VERSION = -1; |
Svet Ganov | d8eb8b2 | 2019-04-05 18:52:08 -0700 | [diff] [blame] | 5107 | private static final int INITIAL_VERSION = 0; |
| 5108 | |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5109 | private final Handler mHandler = new MyHandler(); |
| 5110 | |
Todd Kennedy | 91a39d1 | 2017-09-27 12:37:04 -0700 | [diff] [blame] | 5111 | private final Object mPersistenceLock; |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5112 | |
| 5113 | @GuardedBy("mLock") |
Svet Ganov | ba3ba81 | 2015-06-26 10:54:06 -0700 | [diff] [blame] | 5114 | private final SparseBooleanArray mWriteScheduled = new SparseBooleanArray(); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5115 | |
| 5116 | @GuardedBy("mLock") |
Svet Ganov | ba3ba81 | 2015-06-26 10:54:06 -0700 | [diff] [blame] | 5117 | // The mapping keys are user ids. |
| 5118 | private final SparseLongArray mLastNotWrittenMutationTimesMillis = new SparseLongArray(); |
| 5119 | |
| 5120 | @GuardedBy("mLock") |
| 5121 | // The mapping keys are user ids. |
Svet Ganov | d8eb8b2 | 2019-04-05 18:52:08 -0700 | [diff] [blame] | 5122 | private final SparseIntArray mVersions = new SparseIntArray(); |
| 5123 | |
| 5124 | @GuardedBy("mLock") |
| 5125 | // The mapping keys are user ids. |
Svet Ganov | ba3ba81 | 2015-06-26 10:54:06 -0700 | [diff] [blame] | 5126 | private final SparseArray<String> mFingerprints = new SparseArray<>(); |
| 5127 | |
| 5128 | @GuardedBy("mLock") |
| 5129 | // The mapping keys are user ids. |
| 5130 | private final SparseBooleanArray mDefaultPermissionsGranted = new SparseBooleanArray(); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5131 | |
Todd Kennedy | 91a39d1 | 2017-09-27 12:37:04 -0700 | [diff] [blame] | 5132 | public RuntimePermissionPersistence(Object persistenceLock) { |
| 5133 | mPersistenceLock = persistenceLock; |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5134 | } |
| 5135 | |
Andreas Gampe | 2e8c767 | 2018-07-20 13:01:08 -0700 | [diff] [blame] | 5136 | @GuardedBy("Settings.this.mLock") |
Svet Ganov | d8eb8b2 | 2019-04-05 18:52:08 -0700 | [diff] [blame] | 5137 | int getVersionLPr(int userId) { |
Philip P. Moltmann | 1ae81a5 | 2019-05-21 15:31:36 -0700 | [diff] [blame] | 5138 | return mVersions.get(userId, INITIAL_VERSION); |
Svet Ganov | d8eb8b2 | 2019-04-05 18:52:08 -0700 | [diff] [blame] | 5139 | } |
| 5140 | |
| 5141 | @GuardedBy("Settings.this.mLock") |
| 5142 | void setVersionLPr(int version, int userId) { |
| 5143 | mVersions.put(userId, version); |
| 5144 | writePermissionsForUserAsyncLPr(userId); |
| 5145 | } |
| 5146 | |
| 5147 | @GuardedBy("Settings.this.mLock") |
| 5148 | public boolean areDefaultRuntimePermissionsGrantedLPr(int userId) { |
Svet Ganov | ba3ba81 | 2015-06-26 10:54:06 -0700 | [diff] [blame] | 5149 | return mDefaultPermissionsGranted.get(userId); |
| 5150 | } |
| 5151 | |
Andreas Gampe | 2e8c767 | 2018-07-20 13:01:08 -0700 | [diff] [blame] | 5152 | @GuardedBy("Settings.this.mLock") |
Philip P. Moltmann | 5f5783e | 2019-05-22 14:57:18 -0700 | [diff] [blame] | 5153 | public void setRuntimePermissionsFingerPrintLPr(@NonNull String fingerPrint, |
| 5154 | @UserIdInt int userId) { |
| 5155 | mFingerprints.put(userId, fingerPrint); |
Svet Ganov | ba3ba81 | 2015-06-26 10:54:06 -0700 | [diff] [blame] | 5156 | writePermissionsForUserAsyncLPr(userId); |
| 5157 | } |
| 5158 | |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5159 | public void writePermissionsForUserSyncLPr(int userId) { |
| 5160 | mHandler.removeMessages(userId); |
| 5161 | writePermissionsSync(userId); |
| 5162 | } |
| 5163 | |
Andreas Gampe | 2e8c767 | 2018-07-20 13:01:08 -0700 | [diff] [blame] | 5164 | @GuardedBy("Settings.this.mLock") |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5165 | public void writePermissionsForUserAsyncLPr(int userId) { |
| 5166 | final long currentTimeMillis = SystemClock.uptimeMillis(); |
| 5167 | |
| 5168 | if (mWriteScheduled.get(userId)) { |
| 5169 | mHandler.removeMessages(userId); |
| 5170 | |
| 5171 | // If enough time passed, write without holding off anymore. |
| 5172 | final long lastNotWrittenMutationTimeMillis = mLastNotWrittenMutationTimesMillis |
| 5173 | .get(userId); |
| 5174 | final long timeSinceLastNotWrittenMutationMillis = currentTimeMillis |
| 5175 | - lastNotWrittenMutationTimeMillis; |
| 5176 | if (timeSinceLastNotWrittenMutationMillis >= MAX_WRITE_PERMISSIONS_DELAY_MILLIS) { |
| 5177 | mHandler.obtainMessage(userId).sendToTarget(); |
| 5178 | return; |
| 5179 | } |
| 5180 | |
| 5181 | // Hold off a bit more as settings are frequently changing. |
| 5182 | final long maxDelayMillis = Math.max(lastNotWrittenMutationTimeMillis |
| 5183 | + MAX_WRITE_PERMISSIONS_DELAY_MILLIS - currentTimeMillis, 0); |
| 5184 | final long writeDelayMillis = Math.min(WRITE_PERMISSIONS_DELAY_MILLIS, |
| 5185 | maxDelayMillis); |
| 5186 | |
| 5187 | Message message = mHandler.obtainMessage(userId); |
| 5188 | mHandler.sendMessageDelayed(message, writeDelayMillis); |
| 5189 | } else { |
| 5190 | mLastNotWrittenMutationTimesMillis.put(userId, currentTimeMillis); |
| 5191 | Message message = mHandler.obtainMessage(userId); |
| 5192 | mHandler.sendMessageDelayed(message, WRITE_PERMISSIONS_DELAY_MILLIS); |
| 5193 | mWriteScheduled.put(userId, true); |
| 5194 | } |
| 5195 | } |
| 5196 | |
| 5197 | private void writePermissionsSync(int userId) { |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 5198 | AtomicFile destination = new AtomicFile(getUserRuntimePermissionsFile(userId), |
| 5199 | "package-perms-" + userId); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5200 | |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5201 | ArrayMap<String, List<PermissionState>> permissionsForPackage = new ArrayMap<>(); |
| 5202 | ArrayMap<String, List<PermissionState>> permissionsForSharedUser = new ArrayMap<>(); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5203 | |
Todd Kennedy | 91a39d1 | 2017-09-27 12:37:04 -0700 | [diff] [blame] | 5204 | synchronized (mPersistenceLock) { |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5205 | mWriteScheduled.delete(userId); |
| 5206 | |
| 5207 | final int packageCount = mPackages.size(); |
| 5208 | for (int i = 0; i < packageCount; i++) { |
| 5209 | String packageName = mPackages.keyAt(i); |
| 5210 | PackageSetting packageSetting = mPackages.valueAt(i); |
| 5211 | if (packageSetting.sharedUser == null) { |
| 5212 | PermissionsState permissionsState = packageSetting.getPermissionsState(); |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5213 | List<PermissionState> permissionsStates = permissionsState |
| 5214 | .getRuntimePermissionStates(userId); |
| 5215 | if (!permissionsStates.isEmpty()) { |
| 5216 | permissionsForPackage.put(packageName, permissionsStates); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5217 | } |
| 5218 | } |
| 5219 | } |
| 5220 | |
| 5221 | final int sharedUserCount = mSharedUsers.size(); |
| 5222 | for (int i = 0; i < sharedUserCount; i++) { |
| 5223 | String sharedUserName = mSharedUsers.keyAt(i); |
| 5224 | SharedUserSetting sharedUser = mSharedUsers.valueAt(i); |
| 5225 | PermissionsState permissionsState = sharedUser.getPermissionsState(); |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5226 | List<PermissionState> permissionsStates = permissionsState |
| 5227 | .getRuntimePermissionStates(userId); |
| 5228 | if (!permissionsStates.isEmpty()) { |
| 5229 | permissionsForSharedUser.put(sharedUserName, permissionsStates); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5230 | } |
| 5231 | } |
| 5232 | } |
| 5233 | |
| 5234 | FileOutputStream out = null; |
| 5235 | try { |
| 5236 | out = destination.startWrite(); |
| 5237 | |
| 5238 | XmlSerializer serializer = Xml.newSerializer(); |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 5239 | serializer.setOutput(out, StandardCharsets.UTF_8.name()); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5240 | serializer.setFeature( |
| 5241 | "http://xmlpull.org/v1/doc/features.html#indent-output", true); |
| 5242 | serializer.startDocument(null, true); |
Christopher Tate | e9fd1fa | 2015-09-15 16:43:07 -0700 | [diff] [blame] | 5243 | |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5244 | serializer.startTag(null, TAG_RUNTIME_PERMISSIONS); |
| 5245 | |
Svet Ganov | d8eb8b2 | 2019-04-05 18:52:08 -0700 | [diff] [blame] | 5246 | final int version = mVersions.get(userId, INITIAL_VERSION); |
| 5247 | serializer.attribute(null, ATTR_VERSION, Integer.toString(version)); |
| 5248 | |
Svet Ganov | ba3ba81 | 2015-06-26 10:54:06 -0700 | [diff] [blame] | 5249 | String fingerprint = mFingerprints.get(userId); |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 5250 | if (fingerprint != null) { |
| 5251 | serializer.attribute(null, ATTR_FINGERPRINT, fingerprint); |
| 5252 | } |
Svet Ganov | ba3ba81 | 2015-06-26 10:54:06 -0700 | [diff] [blame] | 5253 | |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5254 | final int packageCount = permissionsForPackage.size(); |
| 5255 | for (int i = 0; i < packageCount; i++) { |
| 5256 | String packageName = permissionsForPackage.keyAt(i); |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5257 | List<PermissionState> permissionStates = permissionsForPackage.valueAt(i); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5258 | serializer.startTag(null, TAG_PACKAGE); |
| 5259 | serializer.attribute(null, ATTR_NAME, packageName); |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5260 | writePermissions(serializer, permissionStates); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5261 | serializer.endTag(null, TAG_PACKAGE); |
| 5262 | } |
| 5263 | |
| 5264 | final int sharedUserCount = permissionsForSharedUser.size(); |
| 5265 | for (int i = 0; i < sharedUserCount; i++) { |
| 5266 | String packageName = permissionsForSharedUser.keyAt(i); |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5267 | List<PermissionState> permissionStates = permissionsForSharedUser.valueAt(i); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5268 | serializer.startTag(null, TAG_SHARED_USER); |
| 5269 | serializer.attribute(null, ATTR_NAME, packageName); |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5270 | writePermissions(serializer, permissionStates); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5271 | serializer.endTag(null, TAG_SHARED_USER); |
| 5272 | } |
| 5273 | |
| 5274 | serializer.endTag(null, TAG_RUNTIME_PERMISSIONS); |
Christopher Tate | e9fd1fa | 2015-09-15 16:43:07 -0700 | [diff] [blame] | 5275 | |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5276 | serializer.endDocument(); |
| 5277 | destination.finishWrite(out); |
Svet Ganov | ba0821e | 2015-04-22 13:34:31 -0700 | [diff] [blame] | 5278 | |
Svet Ganov | ba3ba81 | 2015-06-26 10:54:06 -0700 | [diff] [blame] | 5279 | if (Build.FINGERPRINT.equals(fingerprint)) { |
| 5280 | mDefaultPermissionsGranted.put(userId, true); |
| 5281 | } |
| 5282 | // Any error while writing is fatal. |
Svet Ganov | ba0821e | 2015-04-22 13:34:31 -0700 | [diff] [blame] | 5283 | } catch (Throwable t) { |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5284 | Slog.wtf(PackageManagerService.TAG, |
Svet Ganov | ba0821e | 2015-04-22 13:34:31 -0700 | [diff] [blame] | 5285 | "Failed to write settings, restoring backup", t); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5286 | destination.failWrite(out); |
| 5287 | } finally { |
| 5288 | IoUtils.closeQuietly(out); |
| 5289 | } |
| 5290 | } |
| 5291 | |
Andreas Gampe | 2e8c767 | 2018-07-20 13:01:08 -0700 | [diff] [blame] | 5292 | @GuardedBy("Settings.this.mLock") |
Fyodor Kupolov | 6954259 | 2016-05-23 14:22:38 -0700 | [diff] [blame] | 5293 | private void onUserRemovedLPw(int userId) { |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5294 | // Make sure we do not |
| 5295 | mHandler.removeMessages(userId); |
| 5296 | |
| 5297 | for (SettingBase sb : mPackages.values()) { |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5298 | revokeRuntimePermissionsAndClearFlags(sb, userId); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5299 | } |
| 5300 | |
| 5301 | for (SettingBase sb : mSharedUsers.values()) { |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5302 | revokeRuntimePermissionsAndClearFlags(sb, userId); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5303 | } |
Fyodor Kupolov | 6954259 | 2016-05-23 14:22:38 -0700 | [diff] [blame] | 5304 | |
| 5305 | mDefaultPermissionsGranted.delete(userId); |
Svet Ganov | d8eb8b2 | 2019-04-05 18:52:08 -0700 | [diff] [blame] | 5306 | mVersions.delete(userId); |
Fyodor Kupolov | 6954259 | 2016-05-23 14:22:38 -0700 | [diff] [blame] | 5307 | mFingerprints.remove(userId); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5308 | } |
| 5309 | |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5310 | private void revokeRuntimePermissionsAndClearFlags(SettingBase sb, int userId) { |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5311 | PermissionsState permissionsState = sb.getPermissionsState(); |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5312 | for (PermissionState permissionState |
| 5313 | : permissionsState.getRuntimePermissionStates(userId)) { |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 5314 | BasePermission bp = mPermissions.getPermission(permissionState.getName()); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5315 | if (bp != null) { |
| 5316 | permissionsState.revokeRuntimePermission(bp, userId); |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5317 | permissionsState.updatePermissionFlags(bp, userId, |
Philip P. Moltmann | 7659769 | 2019-03-02 13:18:41 -0800 | [diff] [blame] | 5318 | PackageManager.MASK_PERMISSION_FLAGS_ALL, 0); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5319 | } |
| 5320 | } |
| 5321 | } |
| 5322 | |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 5323 | public void deleteUserRuntimePermissionsFile(int userId) { |
| 5324 | getUserRuntimePermissionsFile(userId).delete(); |
| 5325 | } |
| 5326 | |
Andreas Gampe | 2e8c767 | 2018-07-20 13:01:08 -0700 | [diff] [blame] | 5327 | @GuardedBy("Settings.this.mLock") |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5328 | public void readStateForUserSyncLPr(int userId) { |
| 5329 | File permissionsFile = getUserRuntimePermissionsFile(userId); |
| 5330 | if (!permissionsFile.exists()) { |
| 5331 | return; |
| 5332 | } |
| 5333 | |
| 5334 | FileInputStream in; |
| 5335 | try { |
Svetoslav | 3dcdd37 | 2015-05-29 13:00:32 -0700 | [diff] [blame] | 5336 | in = new AtomicFile(permissionsFile).openRead(); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5337 | } catch (FileNotFoundException fnfe) { |
| 5338 | Slog.i(PackageManagerService.TAG, "No permissions state"); |
| 5339 | return; |
| 5340 | } |
| 5341 | |
| 5342 | try { |
| 5343 | XmlPullParser parser = Xml.newPullParser(); |
| 5344 | parser.setInput(in, null); |
| 5345 | parseRuntimePermissionsLPr(parser, userId); |
Svet Ganov | ba0821e | 2015-04-22 13:34:31 -0700 | [diff] [blame] | 5346 | |
Svet Ganov | e723e54 | 2015-04-23 11:58:26 -0700 | [diff] [blame] | 5347 | } catch (XmlPullParserException | IOException e) { |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5348 | throw new IllegalStateException("Failed parsing permissions file: " |
Svet Ganov | e723e54 | 2015-04-23 11:58:26 -0700 | [diff] [blame] | 5349 | + permissionsFile , e); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5350 | } finally { |
| 5351 | IoUtils.closeQuietly(in); |
| 5352 | } |
| 5353 | } |
| 5354 | |
Christopher Tate | e9fd1fa | 2015-09-15 16:43:07 -0700 | [diff] [blame] | 5355 | // Private internals |
| 5356 | |
Andreas Gampe | 2e8c767 | 2018-07-20 13:01:08 -0700 | [diff] [blame] | 5357 | @GuardedBy("Settings.this.mLock") |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5358 | private void parseRuntimePermissionsLPr(XmlPullParser parser, int userId) |
| 5359 | throws IOException, XmlPullParserException { |
Svet Ganov | 12a692a | 2015-03-28 19:34:15 -0700 | [diff] [blame] | 5360 | final int outerDepth = parser.getDepth(); |
| 5361 | int type; |
| 5362 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 5363 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 5364 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 5365 | continue; |
| 5366 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5367 | |
Svet Ganov | 12a692a | 2015-03-28 19:34:15 -0700 | [diff] [blame] | 5368 | switch (parser.getName()) { |
Svet Ganov | ba3ba81 | 2015-06-26 10:54:06 -0700 | [diff] [blame] | 5369 | case TAG_RUNTIME_PERMISSIONS: { |
Philip P. Moltmann | 1ae81a5 | 2019-05-21 15:31:36 -0700 | [diff] [blame] | 5370 | // If the permisions settings file exists but the version is not set this is |
| 5371 | // an upgrade from P->Q. Hence mark it with the special UPGRADE_VERSION |
Svet Ganov | d8eb8b2 | 2019-04-05 18:52:08 -0700 | [diff] [blame] | 5372 | int version = XmlUtils.readIntAttribute(parser, ATTR_VERSION, |
Philip P. Moltmann | 1ae81a5 | 2019-05-21 15:31:36 -0700 | [diff] [blame] | 5373 | UPGRADE_VERSION); |
Svet Ganov | d8eb8b2 | 2019-04-05 18:52:08 -0700 | [diff] [blame] | 5374 | mVersions.put(userId, version); |
Svet Ganov | ba3ba81 | 2015-06-26 10:54:06 -0700 | [diff] [blame] | 5375 | String fingerprint = parser.getAttributeValue(null, ATTR_FINGERPRINT); |
| 5376 | mFingerprints.put(userId, fingerprint); |
| 5377 | final boolean defaultsGranted = Build.FINGERPRINT.equals(fingerprint); |
| 5378 | mDefaultPermissionsGranted.put(userId, defaultsGranted); |
| 5379 | } break; |
| 5380 | |
Svet Ganov | 12a692a | 2015-03-28 19:34:15 -0700 | [diff] [blame] | 5381 | case TAG_PACKAGE: { |
| 5382 | String name = parser.getAttributeValue(null, ATTR_NAME); |
| 5383 | PackageSetting ps = mPackages.get(name); |
| 5384 | if (ps == null) { |
| 5385 | Slog.w(PackageManagerService.TAG, "Unknown package:" + name); |
| 5386 | XmlUtils.skipCurrentTag(parser); |
| 5387 | continue; |
| 5388 | } |
| 5389 | parsePermissionsLPr(parser, ps.getPermissionsState(), userId); |
| 5390 | } break; |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5391 | |
Svet Ganov | 12a692a | 2015-03-28 19:34:15 -0700 | [diff] [blame] | 5392 | case TAG_SHARED_USER: { |
| 5393 | String name = parser.getAttributeValue(null, ATTR_NAME); |
| 5394 | SharedUserSetting sus = mSharedUsers.get(name); |
| 5395 | if (sus == null) { |
| 5396 | Slog.w(PackageManagerService.TAG, "Unknown shared user:" + name); |
| 5397 | XmlUtils.skipCurrentTag(parser); |
| 5398 | continue; |
| 5399 | } |
| 5400 | parsePermissionsLPr(parser, sus.getPermissionsState(), userId); |
| 5401 | } break; |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5402 | } |
| 5403 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5404 | } |
| 5405 | |
Svet Ganov | 12a692a | 2015-03-28 19:34:15 -0700 | [diff] [blame] | 5406 | private void parsePermissionsLPr(XmlPullParser parser, PermissionsState permissionsState, |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5407 | int userId) throws IOException, XmlPullParserException { |
Svet Ganov | 12a692a | 2015-03-28 19:34:15 -0700 | [diff] [blame] | 5408 | final int outerDepth = parser.getDepth(); |
| 5409 | int type; |
| 5410 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 5411 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 5412 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 5413 | continue; |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5414 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5415 | |
Svet Ganov | 12a692a | 2015-03-28 19:34:15 -0700 | [diff] [blame] | 5416 | switch (parser.getName()) { |
| 5417 | case TAG_ITEM: { |
| 5418 | String name = parser.getAttributeValue(null, ATTR_NAME); |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 5419 | BasePermission bp = mPermissions.getPermission(name); |
Svet Ganov | 12a692a | 2015-03-28 19:34:15 -0700 | [diff] [blame] | 5420 | if (bp == null) { |
| 5421 | Slog.w(PackageManagerService.TAG, "Unknown permission:" + name); |
| 5422 | XmlUtils.skipCurrentTag(parser); |
| 5423 | continue; |
| 5424 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5425 | |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5426 | String grantedStr = parser.getAttributeValue(null, ATTR_GRANTED); |
| 5427 | final boolean granted = grantedStr == null |
| 5428 | || Boolean.parseBoolean(grantedStr); |
| 5429 | |
| 5430 | String flagsStr = parser.getAttributeValue(null, ATTR_FLAGS); |
| 5431 | final int flags = (flagsStr != null) |
| 5432 | ? Integer.parseInt(flagsStr, 16) : 0; |
| 5433 | |
| 5434 | if (granted) { |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 5435 | permissionsState.grantRuntimePermission(bp, userId); |
| 5436 | permissionsState.updatePermissionFlags(bp, userId, |
Philip P. Moltmann | 7659769 | 2019-03-02 13:18:41 -0800 | [diff] [blame] | 5437 | PackageManager.MASK_PERMISSION_FLAGS_ALL, flags); |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5438 | } else { |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 5439 | permissionsState.updatePermissionFlags(bp, userId, |
Philip P. Moltmann | 7659769 | 2019-03-02 13:18:41 -0800 | [diff] [blame] | 5440 | PackageManager.MASK_PERMISSION_FLAGS_ALL, flags); |
Svet Ganov | 12a692a | 2015-03-28 19:34:15 -0700 | [diff] [blame] | 5441 | } |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5442 | |
Svet Ganov | 12a692a | 2015-03-28 19:34:15 -0700 | [diff] [blame] | 5443 | } break; |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5444 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5445 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5446 | } |
| 5447 | |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5448 | private void writePermissions(XmlSerializer serializer, |
| 5449 | List<PermissionState> permissionStates) throws IOException { |
| 5450 | for (PermissionState permissionState : permissionStates) { |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5451 | serializer.startTag(null, TAG_ITEM); |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5452 | serializer.attribute(null, ATTR_NAME,permissionState.getName()); |
| 5453 | serializer.attribute(null, ATTR_GRANTED, |
| 5454 | String.valueOf(permissionState.isGranted())); |
| 5455 | serializer.attribute(null, ATTR_FLAGS, |
| 5456 | Integer.toHexString(permissionState.getFlags())); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5457 | serializer.endTag(null, TAG_ITEM); |
| 5458 | } |
| 5459 | } |
| 5460 | |
| 5461 | private final class MyHandler extends Handler { |
| 5462 | public MyHandler() { |
| 5463 | super(BackgroundThread.getHandler().getLooper()); |
| 5464 | } |
| 5465 | |
| 5466 | @Override |
| 5467 | public void handleMessage(Message message) { |
| 5468 | final int userId = message.what; |
| 5469 | Runnable callback = (Runnable) message.obj; |
| 5470 | writePermissionsSync(userId); |
| 5471 | if (callback != null) { |
| 5472 | callback.run(); |
| 5473 | } |
| 5474 | } |
| 5475 | } |
| 5476 | } |
Andy McFadden | 2f36229 | 2012-01-20 14:43:38 -0800 | [diff] [blame] | 5477 | } |