Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.server.pm; |
| 18 | |
| 19 | import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DEFAULT; |
| 20 | import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DISABLED; |
| 21 | import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_ENABLED; |
Christopher Tate | e9fd1fa | 2015-09-15 16:43:07 -0700 | [diff] [blame] | 22 | import static android.content.pm.PackageManager.FLAG_PERMISSION_REVOKE_ON_UPGRADE; |
Philip P. Moltmann | 17f65af | 2018-10-18 15:32:29 -0700 | [diff] [blame] | 23 | import static android.content.pm.PackageManager.FLAG_PERMISSION_REVOKE_WHEN_REQUESTED; |
Jeff Sharkey | 2271ba3 | 2016-02-01 17:57:08 -0700 | [diff] [blame] | 24 | import static android.content.pm.PackageManager.FLAG_PERMISSION_USER_FIXED; |
| 25 | import static android.content.pm.PackageManager.FLAG_PERMISSION_USER_SET; |
Todd Kennedy | 13715d5 | 2016-08-01 13:38:57 -0700 | [diff] [blame] | 26 | import static android.content.pm.PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 27 | import static android.content.pm.PackageManager.INSTALL_FAILED_SHARED_USER_INCOMPATIBLE; |
Fabrice Di Meglio | 0788595 | 2015-04-06 19:41:28 -0700 | [diff] [blame] | 28 | 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] | 29 | import static android.content.pm.PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_UNDEFINED; |
Jeff Sharkey | 2a90f673 | 2016-01-06 12:26:11 -0700 | [diff] [blame] | 30 | import static android.content.pm.PackageManager.MATCH_DEFAULT_ONLY; |
Jeff Sharkey | 184a010 | 2013-07-10 16:19:52 -0700 | [diff] [blame] | 31 | import static android.os.Process.PACKAGE_INFO_GID; |
Jeff Sharkey | 2a90f673 | 2016-01-06 12:26:11 -0700 | [diff] [blame] | 32 | import static android.os.Process.SYSTEM_UID; |
Jeff Sharkey | 2271ba3 | 2016-02-01 17:57:08 -0700 | [diff] [blame] | 33 | |
Christopher Tate | 72c10a2 | 2015-06-12 18:31:24 -0700 | [diff] [blame] | 34 | import static com.android.server.pm.PackageManagerService.DEBUG_DOMAIN_VERIFICATION; |
Suprabh Shukla | 021b57a | 2018-03-08 18:21:50 -0800 | [diff] [blame] | 35 | import static com.android.server.pm.PackageManagerService.PLATFORM_PACKAGE_NAME; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 36 | |
Xiaohui Chen | 594f208 | 2015-08-18 11:04:20 -0700 | [diff] [blame] | 37 | import android.annotation.NonNull; |
Todd Kennedy | 13715d5 | 2016-08-01 13:38:57 -0700 | [diff] [blame] | 38 | import android.annotation.Nullable; |
Jeff Sharkey | 2a90f673 | 2016-01-06 12:26:11 -0700 | [diff] [blame] | 39 | import android.content.ComponentName; |
| 40 | import android.content.Intent; |
Dianne Hackborn | 8a2ed1d | 2013-01-29 15:18:29 -0800 | [diff] [blame] | 41 | import android.content.IntentFilter; |
| 42 | import android.content.pm.ActivityInfo; |
Jeff Sharkey | 2a90f673 | 2016-01-06 12:26:11 -0700 | [diff] [blame] | 43 | import android.content.pm.ApplicationInfo; |
| 44 | import android.content.pm.ComponentInfo; |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 45 | import android.content.pm.IntentFilterVerificationInfo; |
Jeff Sharkey | 2a90f673 | 2016-01-06 12:26:11 -0700 | [diff] [blame] | 46 | import android.content.pm.PackageManager; |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 47 | import android.content.pm.PackageManagerInternal; |
Jeff Sharkey | 2a90f673 | 2016-01-06 12:26:11 -0700 | [diff] [blame] | 48 | import android.content.pm.PackageParser; |
| 49 | import android.content.pm.PackageUserState; |
| 50 | import android.content.pm.PermissionInfo; |
Dianne Hackborn | 8a2ed1d | 2013-01-29 15:18:29 -0800 | [diff] [blame] | 51 | import android.content.pm.ResolveInfo; |
Jeff Sharkey | 2a90f673 | 2016-01-06 12:26:11 -0700 | [diff] [blame] | 52 | import android.content.pm.Signature; |
Suprabh Shukla | 389cb6f | 2018-10-01 18:20:39 -0700 | [diff] [blame] | 53 | import android.content.pm.SuspendDialogInfo; |
Jeff Sharkey | 2a90f673 | 2016-01-06 12:26:11 -0700 | [diff] [blame] | 54 | import android.content.pm.UserInfo; |
| 55 | import android.content.pm.VerifierDeviceIdentity; |
Dianne Hackborn | 8a2ed1d | 2013-01-29 15:18:29 -0800 | [diff] [blame] | 56 | import android.net.Uri; |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 57 | import android.os.Binder; |
Jeff Sharkey | 4ed745d | 2014-07-15 20:39:15 -0700 | [diff] [blame] | 58 | import android.os.Build; |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 59 | import android.os.Environment; |
| 60 | import android.os.FileUtils; |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 61 | import android.os.Handler; |
| 62 | import android.os.Message; |
Dianne Hackborn | 8a2ed1d | 2013-01-29 15:18:29 -0800 | [diff] [blame] | 63 | import android.os.PatternMatcher; |
Suprabh Shukla | 021b57a | 2018-03-08 18:21:50 -0800 | [diff] [blame] | 64 | import android.os.PersistableBundle; |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 65 | import android.os.Process; |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 66 | import android.os.SystemClock; |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 67 | import android.os.UserHandle; |
Amith Yamasani | 26f9ea3 | 2014-09-11 10:56:51 -0700 | [diff] [blame] | 68 | import android.os.UserManager; |
Paul Crowley | bcf48ed | 2015-04-22 13:36:59 +0100 | [diff] [blame] | 69 | import android.os.storage.StorageManager; |
Netta P | 426cbef | 2017-02-10 14:38:39 -0800 | [diff] [blame] | 70 | import android.service.pm.PackageServiceDumpProto; |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 71 | import android.text.TextUtils; |
Jeff Sharkey | 2a90f673 | 2016-01-06 12:26:11 -0700 | [diff] [blame] | 72 | import android.util.ArrayMap; |
| 73 | import android.util.ArraySet; |
| 74 | import android.util.AtomicFile; |
| 75 | import android.util.Log; |
Dianne Hackborn | 8a2ed1d | 2013-01-29 15:18:29 -0800 | [diff] [blame] | 76 | import android.util.LogPrinter; |
Jeff Sharkey | 2a90f673 | 2016-01-06 12:26:11 -0700 | [diff] [blame] | 77 | import android.util.Slog; |
| 78 | import android.util.SparseArray; |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 79 | import android.util.SparseBooleanArray; |
Jeff Sharkey | 2a90f673 | 2016-01-06 12:26:11 -0700 | [diff] [blame] | 80 | import android.util.SparseIntArray; |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 81 | import android.util.SparseLongArray; |
Jeff Sharkey | 2a90f673 | 2016-01-06 12:26:11 -0700 | [diff] [blame] | 82 | import android.util.Xml; |
Netta P | 426cbef | 2017-02-10 14:38:39 -0800 | [diff] [blame] | 83 | import android.util.proto.ProtoOutputStream; |
Christopher Tate | e012a23 | 2015-04-01 17:18:50 -0700 | [diff] [blame] | 84 | |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 85 | import com.android.internal.annotations.GuardedBy; |
| 86 | import com.android.internal.os.BackgroundThread; |
| 87 | import com.android.internal.util.ArrayUtils; |
Makoto Onuki | 0a06858 | 2018-06-13 10:57:34 -0700 | [diff] [blame] | 88 | import com.android.internal.util.CollectionUtils; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 89 | import com.android.internal.util.FastXmlSerializer; |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 90 | import com.android.internal.util.IndentingPrintWriter; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 91 | import com.android.internal.util.JournaledFile; |
| 92 | import com.android.internal.util.XmlUtils; |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 93 | import com.android.server.LocalServices; |
Jeff Sharkey | 740f523 | 2016-12-09 14:31:26 -0700 | [diff] [blame] | 94 | import com.android.server.pm.Installer.InstallerException; |
Todd Kennedy | 91a39d1 | 2017-09-27 12:37:04 -0700 | [diff] [blame] | 95 | import com.android.server.pm.permission.BasePermission; |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 96 | import com.android.server.pm.permission.PermissionSettings; |
Todd Kennedy | 82b0842 | 2017-09-28 13:32:05 -0700 | [diff] [blame] | 97 | import com.android.server.pm.permission.PermissionsState; |
| 98 | import com.android.server.pm.permission.PermissionsState.PermissionState; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 99 | |
Jeff Sharkey | 2a90f673 | 2016-01-06 12:26:11 -0700 | [diff] [blame] | 100 | import libcore.io.IoUtils; |
Alexandra Gherghina | 6e2ae25 | 2014-06-12 16:03:58 +0100 | [diff] [blame] | 101 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 102 | import org.xmlpull.v1.XmlPullParser; |
| 103 | import org.xmlpull.v1.XmlPullParserException; |
| 104 | import org.xmlpull.v1.XmlSerializer; |
| 105 | |
Jeff Sharkey | 2a90f673 | 2016-01-06 12:26:11 -0700 | [diff] [blame] | 106 | import java.io.BufferedInputStream; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 107 | import java.io.BufferedOutputStream; |
Jeff Sharkey | 2a90f673 | 2016-01-06 12:26:11 -0700 | [diff] [blame] | 108 | import java.io.BufferedWriter; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 109 | import java.io.File; |
| 110 | import java.io.FileInputStream; |
Jeff Sharkey | 2a90f673 | 2016-01-06 12:26:11 -0700 | [diff] [blame] | 111 | import java.io.FileNotFoundException; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 112 | import java.io.FileOutputStream; |
| 113 | import java.io.IOException; |
Jeff Sharkey | 2a90f673 | 2016-01-06 12:26:11 -0700 | [diff] [blame] | 114 | import java.io.InputStream; |
| 115 | import java.io.OutputStreamWriter; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 116 | import java.io.PrintWriter; |
Jeff Sharkey | 2a90f673 | 2016-01-06 12:26:11 -0700 | [diff] [blame] | 117 | import java.nio.charset.Charset; |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 118 | import java.nio.charset.StandardCharsets; |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 119 | import java.text.SimpleDateFormat; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 120 | import java.util.ArrayList; |
| 121 | import java.util.Arrays; |
Jeff Sharkey | 2a90f673 | 2016-01-06 12:26:11 -0700 | [diff] [blame] | 122 | import java.util.Collection; |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 123 | import java.util.Collections; |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 124 | import java.util.Date; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 125 | import java.util.Iterator; |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 126 | import java.util.List; |
Andy McFadden | 2f36229 | 2012-01-20 14:43:38 -0800 | [diff] [blame] | 127 | import java.util.Map; |
Jeff Sharkey | 2a90f673 | 2016-01-06 12:26:11 -0700 | [diff] [blame] | 128 | import java.util.Map.Entry; |
Jeff Sharkey | 84f1294 | 2014-07-10 17:48:11 -0700 | [diff] [blame] | 129 | import java.util.Objects; |
Dianne Hackborn | 6309271 | 2012-10-07 14:45:35 -0700 | [diff] [blame] | 130 | import java.util.Set; |
Kenny Root | 62539e9 | 2011-11-10 09:35:38 -0800 | [diff] [blame] | 131 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 132 | /** |
| 133 | * Holds information about dynamic settings. |
| 134 | */ |
Todd Kennedy | 91a39d1 | 2017-09-27 12:37:04 -0700 | [diff] [blame] | 135 | public final class Settings { |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 136 | private static final String TAG = "PackageSettings"; |
| 137 | |
Kenny Root | c1c0d3c | 2014-04-24 13:36:40 -0700 | [diff] [blame] | 138 | /** |
| 139 | * Current version of the package database. Set it to the latest version in |
| 140 | * the {@link DatabaseVersion} class below to ensure the database upgrade |
| 141 | * doesn't happen repeatedly. |
| 142 | * <p> |
| 143 | * Note that care should be taken to make sure all database upgrades are |
| 144 | * idempotent. |
| 145 | */ |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 146 | public static final int CURRENT_DATABASE_VERSION = DatabaseVersion.SIGNATURE_MALFORMED_RECOVER; |
Kenny Root | c1c0d3c | 2014-04-24 13:36:40 -0700 | [diff] [blame] | 147 | |
| 148 | /** |
| 149 | * This class contains constants that can be referred to from upgrade code. |
| 150 | * Insert constant values here that describe the upgrade reason. The version |
| 151 | * code must be monotonically increasing. |
| 152 | */ |
| 153 | public static class DatabaseVersion { |
| 154 | /** |
| 155 | * The initial version of the database. |
| 156 | */ |
| 157 | public static final int FIRST_VERSION = 1; |
Kenny Root | a8e65fd | 2014-04-24 11:44:47 -0700 | [diff] [blame] | 158 | |
| 159 | /** |
| 160 | * Migrating the Signature array from the entire certificate chain to |
| 161 | * just the signing certificate. |
| 162 | */ |
| 163 | public static final int SIGNATURE_END_ENTITY = 2; |
Jeff Sharkey | d68b87c | 2014-11-12 12:18:11 -0800 | [diff] [blame] | 164 | |
| 165 | /** |
| 166 | * There was a window of time in |
| 167 | * {@link android.os.Build.VERSION_CODES#LOLLIPOP} where we persisted |
| 168 | * certificates after potentially mutating them. To switch back to the |
| 169 | * original untouched certificates, we need to force a collection pass. |
| 170 | */ |
| 171 | public static final int SIGNATURE_MALFORMED_RECOVER = 3; |
Kenny Root | c1c0d3c | 2014-04-24 13:36:40 -0700 | [diff] [blame] | 172 | } |
| 173 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 174 | private static final boolean DEBUG_STOPPED = false; |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 175 | private static final boolean DEBUG_MU = false; |
Jeff Sharkey | 2271ba3 | 2016-02-01 17:57:08 -0700 | [diff] [blame] | 176 | private static final boolean DEBUG_KERNEL = false; |
Todd Kennedy | 788c842 | 2016-08-10 10:52:34 -0700 | [diff] [blame] | 177 | private static final boolean DEBUG_PARSER = false; |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 178 | |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 179 | private static final String RUNTIME_PERMISSIONS_FILE_NAME = "runtime-permissions.xml"; |
| 180 | |
Jeff Sharkey | edc84ee8 | 2012-03-19 16:52:26 -0700 | [diff] [blame] | 181 | private static final String TAG_READ_EXTERNAL_STORAGE = "read-external-storage"; |
| 182 | private static final String ATTR_ENFORCEMENT = "enforcement"; |
| 183 | |
Todd Kennedy | 91a39d1 | 2017-09-27 12:37:04 -0700 | [diff] [blame] | 184 | public static final String TAG_ITEM = "item"; |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 185 | private static final String TAG_DISABLED_COMPONENTS = "disabled-components"; |
| 186 | private static final String TAG_ENABLED_COMPONENTS = "enabled-components"; |
| 187 | private static final String TAG_PACKAGE_RESTRICTIONS = "package-restrictions"; |
| 188 | private static final String TAG_PACKAGE = "pkg"; |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 189 | private static final String TAG_SHARED_USER = "shared-user"; |
| 190 | private static final String TAG_RUNTIME_PERMISSIONS = "runtime-permissions"; |
| 191 | private static final String TAG_PERMISSIONS = "perms"; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 192 | private static final String TAG_CHILD_PACKAGE = "child-package"; |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 193 | private static final String TAG_USES_STATIC_LIB = "uses-static-lib"; |
Vladislav Kuzkokov | 253984e | 2016-10-24 09:27:16 +0200 | [diff] [blame] | 194 | private static final String TAG_BLOCK_UNINSTALL_PACKAGES = "block-uninstall-packages"; |
| 195 | private static final String TAG_BLOCK_UNINSTALL = "block-uninstall"; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 196 | |
Sander Alewijnse | af59762 | 2014-03-20 18:44:57 +0000 | [diff] [blame] | 197 | private static final String TAG_PERSISTENT_PREFERRED_ACTIVITIES = |
| 198 | "persistent-preferred-activities"; |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 199 | static final String TAG_CROSS_PROFILE_INTENT_FILTERS = |
| 200 | "crossProfile-intent-filters"; |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 201 | private static final String TAG_DOMAIN_VERIFICATION = "domain-verification"; |
| 202 | private static final String TAG_DEFAULT_APPS = "default-apps"; |
| 203 | private static final String TAG_ALL_INTENT_FILTER_VERIFICATION = |
Christopher Tate | 6038d15 | 2015-06-17 13:07:46 -0700 | [diff] [blame] | 204 | "all-intent-filter-verifications"; |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 205 | private static final String TAG_DEFAULT_BROWSER = "default-browser"; |
Robin Lee | 0dc591b | 2016-05-04 13:01:46 +0100 | [diff] [blame] | 206 | private static final String TAG_DEFAULT_DIALER = "default-dialer"; |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 207 | private static final String TAG_VERSION = "version"; |
Suprabh Shukla | 389cb6f | 2018-10-01 18:20:39 -0700 | [diff] [blame] | 208 | private static final String TAG_SUSPENDED_DIALOG_INFO = "suspended-dialog-info"; |
Suprabh Shukla | 021b57a | 2018-03-08 18:21:50 -0800 | [diff] [blame] | 209 | private static final String TAG_SUSPENDED_APP_EXTRAS = "suspended-app-extras"; |
| 210 | private static final String TAG_SUSPENDED_LAUNCHER_EXTRAS = "suspended-launcher-extras"; |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 211 | |
Todd Kennedy | 91a39d1 | 2017-09-27 12:37:04 -0700 | [diff] [blame] | 212 | public static final String ATTR_NAME = "name"; |
| 213 | public static final String ATTR_PACKAGE = "package"; |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 214 | private static final String ATTR_GRANTED = "granted"; |
| 215 | private static final String ATTR_FLAGS = "flags"; |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 216 | private static final String ATTR_VERSION = "version"; |
Jeff Sharkey | 4288419 | 2016-04-09 16:12:01 -0600 | [diff] [blame] | 217 | |
| 218 | private static final String ATTR_CE_DATA_INODE = "ceDataInode"; |
| 219 | private static final String ATTR_INSTALLED = "inst"; |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 220 | private static final String ATTR_STOPPED = "stopped"; |
Jeff Sharkey | 4288419 | 2016-04-09 16:12:01 -0600 | [diff] [blame] | 221 | private static final String ATTR_NOT_LAUNCHED = "nl"; |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 222 | // Legacy, here for reading older versions of the package-restrictions. |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 223 | private static final String ATTR_BLOCKED = "blocked"; |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 224 | // New name for the above attribute. |
| 225 | private static final String ATTR_HIDDEN = "hidden"; |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 226 | private static final String ATTR_SUSPENDED = "suspended"; |
Suprabh Shukla | 021b57a | 2018-03-08 18:21:50 -0800 | [diff] [blame] | 227 | private static final String ATTR_SUSPENDING_PACKAGE = "suspending-package"; |
Suprabh Shukla | 389cb6f | 2018-10-01 18:20:39 -0700 | [diff] [blame] | 228 | /** |
| 229 | * @deprecated Legacy attribute, kept only for upgrading from P builds. |
| 230 | */ |
| 231 | @Deprecated |
Suprabh Shukla | 3c3af14 | 2018-03-30 00:28:37 -0700 | [diff] [blame] | 232 | private static final String ATTR_SUSPEND_DIALOG_MESSAGE = "suspend_dialog_message"; |
Vladislav Kuzkokov | 253984e | 2016-10-24 09:27:16 +0200 | [diff] [blame] | 233 | // Legacy, uninstall blocks are stored separately. |
| 234 | @Deprecated |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 235 | private static final String ATTR_BLOCK_UNINSTALL = "blockUninstall"; |
Jeff Sharkey | 4288419 | 2016-04-09 16:12:01 -0600 | [diff] [blame] | 236 | private static final String ATTR_ENABLED = "enabled"; |
| 237 | private static final String ATTR_ENABLED_CALLER = "enabledCaller"; |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 238 | private static final String ATTR_DOMAIN_VERIFICATON_STATE = "domainVerificationStatus"; |
Jeff Sharkey | 4288419 | 2016-04-09 16:12:01 -0600 | [diff] [blame] | 239 | private static final String ATTR_APP_LINK_GENERATION = "app-link-generation"; |
Bartosz Fabianowski | a34f53f | 2017-01-11 18:08:47 +0100 | [diff] [blame] | 240 | private static final String ATTR_INSTALL_REASON = "install-reason"; |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 241 | private static final String ATTR_INSTANT_APP = "instant-app"; |
Todd Kennedy | 5eb5a7d | 2017-08-01 07:42:47 -0700 | [diff] [blame] | 242 | private static final String ATTR_VIRTUAL_PRELOAD = "virtual-preload"; |
Ben Gruver | 1ab3d6e | 2017-12-07 13:45:08 -0800 | [diff] [blame] | 243 | private static final String ATTR_HARMFUL_APP_WARNING = "harmful-app-warning"; |
Jeff Sharkey | 4288419 | 2016-04-09 16:12:01 -0600 | [diff] [blame] | 244 | |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 245 | private static final String ATTR_PACKAGE_NAME = "packageName"; |
Svet Ganov | ba3ba81 | 2015-06-26 10:54:06 -0700 | [diff] [blame] | 246 | private static final String ATTR_FINGERPRINT = "fingerprint"; |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 247 | private static final String ATTR_VOLUME_UUID = "volumeUuid"; |
| 248 | private static final String ATTR_SDK_VERSION = "sdkVersion"; |
| 249 | private static final String ATTR_DATABASE_VERSION = "databaseVersion"; |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 250 | |
Christopher Tate | e9fd1fa | 2015-09-15 16:43:07 -0700 | [diff] [blame] | 251 | // Bookkeeping for restored permission grants |
| 252 | private static final String TAG_RESTORED_RUNTIME_PERMISSIONS = "restored-perms"; |
| 253 | // package name: ATTR_PACKAGE_NAME |
| 254 | private static final String TAG_PERMISSION_ENTRY = "perm"; |
| 255 | // permission name: ATTR_NAME |
| 256 | // permission granted (boolean): ATTR_GRANTED |
| 257 | private static final String ATTR_USER_SET = "set"; |
| 258 | private static final String ATTR_USER_FIXED = "fixed"; |
| 259 | private static final String ATTR_REVOKE_ON_UPGRADE = "rou"; |
Philip P. Moltmann | 17f65af | 2018-10-18 15:32:29 -0700 | [diff] [blame] | 260 | private static final String ATTR_REVOKE_WHEN_REQUESTED = "rwr"; |
Christopher Tate | e9fd1fa | 2015-09-15 16:43:07 -0700 | [diff] [blame] | 261 | |
| 262 | // Flag mask of restored permission grants that are applied at install time |
| 263 | private static final int USER_RUNTIME_GRANT_MASK = |
| 264 | FLAG_PERMISSION_USER_SET |
| 265 | | FLAG_PERMISSION_USER_FIXED |
| 266 | | FLAG_PERMISSION_REVOKE_ON_UPGRADE; |
| 267 | |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 268 | private final Object mLock; |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 269 | |
| 270 | private final RuntimePermissionPersistence mRuntimePermissionsPersistence; |
| 271 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 272 | private final File mSettingsFilename; |
| 273 | private final File mBackupSettingsFilename; |
| 274 | private final File mPackageListFilename; |
| 275 | private final File mStoppedPackagesFilename; |
| 276 | private final File mBackupStoppedPackagesFilename; |
Amith Yamasani | 23ab7f5 | 2017-01-22 17:43:24 -0800 | [diff] [blame] | 277 | /** 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] | 278 | private final File mKernelMappingFilename; |
Jeff Sharkey | 184a010 | 2013-07-10 16:19:52 -0700 | [diff] [blame] | 279 | |
Jeff Sharkey | 2271ba3 | 2016-02-01 17:57:08 -0700 | [diff] [blame] | 280 | /** Map from package name to settings */ |
| 281 | final ArrayMap<String, PackageSetting> mPackages = new ArrayMap<>(); |
| 282 | |
Sudheer Shanka | 2928337 | 2016-04-04 20:56:27 -0700 | [diff] [blame] | 283 | /** List of packages that installed other packages */ |
| 284 | final ArraySet<String> mInstallerPackages = new ArraySet<>(); |
| 285 | |
Amith Yamasani | 23ab7f5 | 2017-01-22 17:43:24 -0800 | [diff] [blame] | 286 | /** Map from package name to appId and excluded userids */ |
| 287 | private final ArrayMap<String, KernelPackageState> mKernelMapping = new ArrayMap<>(); |
Christopher Tate | 6038d15 | 2015-06-17 13:07:46 -0700 | [diff] [blame] | 288 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 289 | // List of replaced system applications |
Jeff Sharkey | 9f837a9 | 2014-10-24 12:07:24 -0700 | [diff] [blame] | 290 | private final ArrayMap<String, PackageSetting> mDisabledSysPackages = |
| 291 | new ArrayMap<String, PackageSetting>(); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 292 | |
Vladislav Kuzkokov | 253984e | 2016-10-24 09:27:16 +0200 | [diff] [blame] | 293 | /** List of packages that are blocked for uninstall for specific users */ |
| 294 | private final SparseArray<ArraySet<String>> mBlockUninstallPackages = new SparseArray<>(); |
| 295 | |
Christopher Tate | 6038d15 | 2015-06-17 13:07:46 -0700 | [diff] [blame] | 296 | // Set of restored intent-filter verification states |
| 297 | private final ArrayMap<String, IntentFilterVerificationInfo> mRestoredIntentFilterVerifications = |
| 298 | new ArrayMap<String, IntentFilterVerificationInfo>(); |
| 299 | |
Amith Yamasani | 23ab7f5 | 2017-01-22 17:43:24 -0800 | [diff] [blame] | 300 | private static final class KernelPackageState { |
| 301 | int appId; |
| 302 | int[] excludedUserIds; |
| 303 | } |
| 304 | |
Christopher Tate | e9fd1fa | 2015-09-15 16:43:07 -0700 | [diff] [blame] | 305 | // Bookkeeping for restored user permission grants |
| 306 | final class RestoredPermissionGrant { |
| 307 | String permissionName; |
| 308 | boolean granted; |
| 309 | int grantBits; |
| 310 | |
| 311 | RestoredPermissionGrant(String name, boolean isGranted, int theGrantBits) { |
| 312 | permissionName = name; |
| 313 | granted = isGranted; |
| 314 | grantBits = theGrantBits; |
| 315 | } |
| 316 | } |
| 317 | |
| 318 | // This would be more compact as a flat array of restored grants or something, but we |
| 319 | // may have quite a few, especially during early device lifetime, and avoiding all those |
| 320 | // linear lookups will be important. |
| 321 | private final SparseArray<ArrayMap<String, ArraySet<RestoredPermissionGrant>>> |
| 322 | mRestoredUserGrants = |
| 323 | new SparseArray<ArrayMap<String, ArraySet<RestoredPermissionGrant>>>(); |
| 324 | |
Geremy Condra | 12c1838 | 2013-03-06 16:49:06 -0800 | [diff] [blame] | 325 | private static int mFirstAvailableUid = 0; |
| 326 | |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 327 | /** Map from volume UUID to {@link VersionInfo} */ |
| 328 | private ArrayMap<String, VersionInfo> mVersion = new ArrayMap<>(); |
Kenny Root | 0aaa0d9 | 2011-09-12 16:42:55 -0700 | [diff] [blame] | 329 | |
Kenny Root | c1c0d3c | 2014-04-24 13:36:40 -0700 | [diff] [blame] | 330 | /** |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 331 | * Version details for a storage volume that may hold apps. |
Kenny Root | c1c0d3c | 2014-04-24 13:36:40 -0700 | [diff] [blame] | 332 | */ |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 333 | public static class VersionInfo { |
| 334 | /** |
| 335 | * These are the last platform API version we were using for the apps |
| 336 | * installed on internal and external storage. It is used to grant newer |
| 337 | * permissions one time during a system upgrade. |
| 338 | */ |
| 339 | int sdkVersion; |
Kenny Root | c1c0d3c | 2014-04-24 13:36:40 -0700 | [diff] [blame] | 340 | |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 341 | /** |
| 342 | * The current database version for apps on internal storage. This is |
| 343 | * used to upgrade the format of the packages.xml database not |
| 344 | * necessarily tied to an SDK version. |
| 345 | */ |
| 346 | int databaseVersion; |
| 347 | |
| 348 | /** |
| 349 | * Last known value of {@link Build#FINGERPRINT}. Used to determine when |
| 350 | * an system update has occurred, meaning we need to clear code caches. |
| 351 | */ |
| 352 | String fingerprint; |
| 353 | |
| 354 | /** |
| 355 | * Force all version information to match current system values, |
| 356 | * typically after resolving any required upgrade steps. |
| 357 | */ |
| 358 | public void forceCurrent() { |
| 359 | sdkVersion = Build.VERSION.SDK_INT; |
| 360 | databaseVersion = CURRENT_DATABASE_VERSION; |
| 361 | fingerprint = Build.FINGERPRINT; |
| 362 | } |
| 363 | } |
Jeff Sharkey | 4ed745d | 2014-07-15 20:39:15 -0700 | [diff] [blame] | 364 | |
Jeff Sharkey | f538577 | 2012-05-11 14:04:41 -0700 | [diff] [blame] | 365 | Boolean mReadExternalStorageEnforced; |
Jeff Sharkey | edc84ee8 | 2012-03-19 16:52:26 -0700 | [diff] [blame] | 366 | |
Kenny Root | 0aaa0d9 | 2011-09-12 16:42:55 -0700 | [diff] [blame] | 367 | /** Device identity for the purpose of package verification. */ |
| 368 | private VerifierDeviceIdentity mVerifierDeviceIdentity; |
| 369 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 370 | // The user's preferred activities associated with particular intent |
| 371 | // filters. |
Dianne Hackborn | 6309271 | 2012-10-07 14:45:35 -0700 | [diff] [blame] | 372 | final SparseArray<PreferredIntentResolver> mPreferredActivities = |
| 373 | new SparseArray<PreferredIntentResolver>(); |
| 374 | |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 375 | // The persistent preferred activities of the user's profile/device owner |
| 376 | // associated with particular intent filters. |
| 377 | final SparseArray<PersistentPreferredIntentResolver> mPersistentPreferredActivities = |
| 378 | new SparseArray<PersistentPreferredIntentResolver>(); |
| 379 | |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 380 | // 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] | 381 | final SparseArray<CrossProfileIntentResolver> mCrossProfileIntentResolvers = |
| 382 | new SparseArray<CrossProfileIntentResolver>(); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 383 | |
Jeff Sharkey | 9f837a9 | 2014-10-24 12:07:24 -0700 | [diff] [blame] | 384 | final ArrayMap<String, SharedUserSetting> mSharedUsers = |
| 385 | new ArrayMap<String, SharedUserSetting>(); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 386 | private final ArrayList<Object> mUserIds = new ArrayList<Object>(); |
| 387 | private final SparseArray<Object> mOtherUserIds = |
| 388 | new SparseArray<Object>(); |
| 389 | |
| 390 | // For reading/writing settings file. |
| 391 | private final ArrayList<Signature> mPastSignatures = |
| 392 | new ArrayList<Signature>(); |
dcashman | 8c04fac | 2015-03-23 11:39:42 -0700 | [diff] [blame] | 393 | private final ArrayMap<Long, Integer> mKeySetRefs = |
| 394 | new ArrayMap<Long, Integer>(); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 395 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 396 | // Packages that have been renamed since they were first installed. |
| 397 | // Keys are the new names of the packages, values are the original |
Todd Kennedy | 13715d5 | 2016-08-01 13:38:57 -0700 | [diff] [blame] | 398 | // names. The packages appear everywhere else under their original |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 399 | // names. |
Todd Kennedy | 13715d5 | 2016-08-01 13:38:57 -0700 | [diff] [blame] | 400 | private final ArrayMap<String, String> mRenamedPackages = new ArrayMap<String, String>(); |
Fabrice Di Meglio | 6227172 | 2015-04-10 17:24:02 -0700 | [diff] [blame] | 401 | |
| 402 | // For every user, it is used to find the package name of the default Browser App. |
| 403 | final SparseArray<String> mDefaultBrowserApp = new SparseArray<String>(); |
| 404 | |
Robin Lee | 0dc591b | 2016-05-04 13:01:46 +0100 | [diff] [blame] | 405 | // For every user, a record of the package name of the default Dialer App. |
| 406 | final SparseArray<String> mDefaultDialerApp = new SparseArray<String>(); |
| 407 | |
Christopher Tate | f0d6cb3 | 2015-07-10 17:44:53 -0700 | [diff] [blame] | 408 | // App-link priority tracking, per-user |
| 409 | final SparseIntArray mNextAppLinkGeneration = new SparseIntArray(); |
| 410 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 411 | final StringBuilder mReadMessages = new StringBuilder(); |
| 412 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 413 | /** |
| 414 | * Used to track packages that have a shared user ID that hasn't been read |
| 415 | * in yet. |
| 416 | * <p> |
| 417 | * TODO: make this just a local variable that is passed in during package |
| 418 | * scanning to make it less confusing. |
| 419 | */ |
Todd Kennedy | 788c842 | 2016-08-10 10:52:34 -0700 | [diff] [blame] | 420 | private final ArrayList<PackageSetting> mPendingPackages = new ArrayList<>(); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 421 | |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 422 | private final File mSystemDir; |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 423 | |
dcashman | 55b1078 | 2014-04-09 14:20:38 -0700 | [diff] [blame] | 424 | public final KeySetManagerService mKeySetManagerService = new KeySetManagerService(mPackages); |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 425 | /** Settings and other information about permissions */ |
Todd Kennedy | c842393 | 2017-10-05 08:58:36 -0700 | [diff] [blame] | 426 | final PermissionSettings mPermissions; |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 427 | |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 428 | Settings(File dataDir, PermissionSettings permission, |
| 429 | Object lock) { |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 430 | mLock = lock; |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 431 | mPermissions = permission; |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 432 | mRuntimePermissionsPersistence = new RuntimePermissionPersistence(mLock); |
| 433 | |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 434 | mSystemDir = new File(dataDir, "system"); |
| 435 | mSystemDir.mkdirs(); |
| 436 | FileUtils.setPermissions(mSystemDir.toString(), |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 437 | FileUtils.S_IRWXU|FileUtils.S_IRWXG |
| 438 | |FileUtils.S_IROTH|FileUtils.S_IXOTH, |
| 439 | -1, -1); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 440 | mSettingsFilename = new File(mSystemDir, "packages.xml"); |
| 441 | mBackupSettingsFilename = new File(mSystemDir, "packages-backup.xml"); |
| 442 | mPackageListFilename = new File(mSystemDir, "packages.list"); |
Jeff Sharkey | aebb65c | 2014-11-24 15:00:13 -0800 | [diff] [blame] | 443 | FileUtils.setPermissions(mPackageListFilename, 0640, SYSTEM_UID, PACKAGE_INFO_GID); |
Jeff Sharkey | 184a010 | 2013-07-10 16:19:52 -0700 | [diff] [blame] | 444 | |
Jeff Sharkey | 2271ba3 | 2016-02-01 17:57:08 -0700 | [diff] [blame] | 445 | final File kernelDir = new File("/config/sdcardfs"); |
| 446 | mKernelMappingFilename = kernelDir.exists() ? kernelDir : null; |
| 447 | |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 448 | // Deprecated: Needed for migration |
| 449 | mStoppedPackagesFilename = new File(mSystemDir, "packages-stopped.xml"); |
| 450 | mBackupStoppedPackagesFilename = new File(mSystemDir, "packages-stopped-backup.xml"); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 451 | } |
| 452 | |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 453 | PackageSetting getPackageLPr(String pkgName) { |
Todd Kennedy | 13715d5 | 2016-08-01 13:38:57 -0700 | [diff] [blame] | 454 | return mPackages.get(pkgName); |
| 455 | } |
| 456 | |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 457 | String getRenamedPackageLPr(String pkgName) { |
Todd Kennedy | 13715d5 | 2016-08-01 13:38:57 -0700 | [diff] [blame] | 458 | return mRenamedPackages.get(pkgName); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 459 | } |
| 460 | |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 461 | String addRenamedPackageLPw(String pkgName, String origPkgName) { |
| 462 | return mRenamedPackages.put(pkgName, origPkgName); |
| 463 | } |
| 464 | |
Christopher Tate | e9fd1fa | 2015-09-15 16:43:07 -0700 | [diff] [blame] | 465 | void applyPendingPermissionGrantsLPw(String packageName, int userId) { |
| 466 | ArrayMap<String, ArraySet<RestoredPermissionGrant>> grantsByPackage = |
| 467 | mRestoredUserGrants.get(userId); |
| 468 | if (grantsByPackage == null || grantsByPackage.size() == 0) { |
| 469 | return; |
| 470 | } |
| 471 | |
| 472 | ArraySet<RestoredPermissionGrant> grants = grantsByPackage.get(packageName); |
| 473 | if (grants == null || grants.size() == 0) { |
| 474 | return; |
| 475 | } |
| 476 | |
| 477 | final PackageSetting ps = mPackages.get(packageName); |
| 478 | if (ps == null) { |
| 479 | Slog.e(TAG, "Can't find supposedly installed package " + packageName); |
| 480 | return; |
| 481 | } |
| 482 | final PermissionsState perms = ps.getPermissionsState(); |
| 483 | |
| 484 | for (RestoredPermissionGrant grant : grants) { |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 485 | BasePermission bp = mPermissions.getPermission(grant.permissionName); |
Christopher Tate | e9fd1fa | 2015-09-15 16:43:07 -0700 | [diff] [blame] | 486 | if (bp != null) { |
| 487 | if (grant.granted) { |
| 488 | perms.grantRuntimePermission(bp, userId); |
| 489 | } |
| 490 | perms.updatePermissionFlags(bp, userId, USER_RUNTIME_GRANT_MASK, grant.grantBits); |
| 491 | } |
| 492 | } |
| 493 | |
| 494 | // And remove it from the pending-grant bookkeeping |
| 495 | grantsByPackage.remove(packageName); |
| 496 | if (grantsByPackage.size() < 1) { |
| 497 | mRestoredUserGrants.remove(userId); |
| 498 | } |
| 499 | writeRuntimePermissionsForUserLPr(userId, false); |
| 500 | } |
| 501 | |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 502 | public boolean canPropagatePermissionToInstantApp(String permName) { |
| 503 | return mPermissions.canPropagatePermissionToInstantApp(permName); |
| 504 | } |
| 505 | |
Jeff Sharkey | b2b9ab8 | 2015-04-05 21:10:42 -0700 | [diff] [blame] | 506 | void setInstallerPackageName(String pkgName, String installerPkgName) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 507 | PackageSetting p = mPackages.get(pkgName); |
Jeff Sharkey | b2b9ab8 | 2015-04-05 21:10:42 -0700 | [diff] [blame] | 508 | if (p != null) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 509 | p.setInstallerPackageName(installerPkgName); |
Sudheer Shanka | 2928337 | 2016-04-04 20:56:27 -0700 | [diff] [blame] | 510 | if (installerPkgName != null) { |
| 511 | mInstallerPackages.add(installerPkgName); |
| 512 | } |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 513 | } |
| 514 | } |
| 515 | |
Todd Kennedy | 13715d5 | 2016-08-01 13:38:57 -0700 | [diff] [blame] | 516 | /** Gets and optionally creates a new shared user id. */ |
Todd Kennedy | ff35e66 | 2016-09-20 12:53:52 -0700 | [diff] [blame] | 517 | SharedUserSetting getSharedUserLPw(String name, int pkgFlags, int pkgPrivateFlags, |
| 518 | boolean create) throws PackageManagerException { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 519 | SharedUserSetting s = mSharedUsers.get(name); |
Todd Kennedy | ff35e66 | 2016-09-20 12:53:52 -0700 | [diff] [blame] | 520 | if (s == null && create) { |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 521 | s = new SharedUserSetting(name, pkgFlags, pkgPrivateFlags); |
Dianne Hackborn | 21fbd1f | 2012-02-10 10:38:10 -0800 | [diff] [blame] | 522 | s.userId = newUserIdLPw(s); |
Todd Kennedy | ff35e66 | 2016-09-20 12:53:52 -0700 | [diff] [blame] | 523 | if (s.userId < 0) { |
| 524 | // < 0 means we couldn't assign a userid; throw exception |
| 525 | throw new PackageManagerException(INSTALL_FAILED_INSUFFICIENT_STORAGE, |
| 526 | "Creating shared user " + name + " failed"); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 527 | } |
Todd Kennedy | ff35e66 | 2016-09-20 12:53:52 -0700 | [diff] [blame] | 528 | Log.i(PackageManagerService.TAG, "New shared user " + name + ": id=" + s.userId); |
| 529 | mSharedUsers.put(name, s); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 530 | } |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 531 | return s; |
| 532 | } |
| 533 | |
Narayan Kamath | df6d6dc | 2014-04-28 14:18:34 +0100 | [diff] [blame] | 534 | Collection<SharedUserSetting> getAllSharedUsersLPw() { |
| 535 | return mSharedUsers.values(); |
| 536 | } |
| 537 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 538 | boolean disableSystemPackageLPw(String name, boolean replaced) { |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 539 | final PackageSetting p = mPackages.get(name); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 540 | if(p == null) { |
Jeff Sharkey | e06b4d1 | 2016-01-06 14:51:50 -0700 | [diff] [blame] | 541 | Log.w(PackageManagerService.TAG, "Package " + name + " is not an installed package"); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 542 | return false; |
| 543 | } |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 544 | final PackageSetting dp = mDisabledSysPackages.get(name); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 545 | // always make sure the system package code and resource paths dont change |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 546 | if (dp == null && p.pkg != null && p.pkg.isSystem() && !p.pkg.isUpdatedSystemApp()) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 547 | if((p.pkg != null) && (p.pkg.applicationInfo != null)) { |
| 548 | p.pkg.applicationInfo.flags |= ApplicationInfo.FLAG_UPDATED_SYSTEM_APP; |
| 549 | } |
Patrick | 4ccae94 | 2018-07-17 09:15:55 -0700 | [diff] [blame] | 550 | final PackageSetting disabled; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 551 | if (replaced) { |
| 552 | // a little trick... when we install the new package, we don't |
| 553 | // want to modify the existing PackageSetting for the built-in |
Patrick | 4ccae94 | 2018-07-17 09:15:55 -0700 | [diff] [blame] | 554 | // version. so at this point we make a copy to place into the |
| 555 | // disabled set. |
| 556 | disabled = new PackageSetting(p); |
| 557 | } else { |
| 558 | disabled = p; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 559 | } |
Patrick | 4ccae94 | 2018-07-17 09:15:55 -0700 | [diff] [blame] | 560 | mDisabledSysPackages.put(name, disabled); |
| 561 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 562 | return true; |
| 563 | } |
| 564 | return false; |
| 565 | } |
| 566 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 567 | PackageSetting enableSystemPackageLPw(String name) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 568 | PackageSetting p = mDisabledSysPackages.get(name); |
| 569 | if(p == null) { |
Jeff Sharkey | e06b4d1 | 2016-01-06 14:51:50 -0700 | [diff] [blame] | 570 | Log.w(PackageManagerService.TAG, "Package " + name + " is not disabled"); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 571 | return null; |
| 572 | } |
| 573 | // Reset flag in ApplicationInfo object |
| 574 | if((p.pkg != null) && (p.pkg.applicationInfo != null)) { |
| 575 | p.pkg.applicationInfo.flags &= ~ApplicationInfo.FLAG_UPDATED_SYSTEM_APP; |
| 576 | } |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 577 | PackageSetting ret = addPackageLPw(name, p.realName, p.codePath, p.resourcePath, |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 578 | p.legacyNativeLibraryPathString, p.primaryCpuAbiString, |
Selim Gurun | 5c8acb4 | 2016-04-07 16:34:02 -0700 | [diff] [blame] | 579 | p.secondaryCpuAbiString, p.cpuAbiOverrideString, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 580 | p.appId, p.versionCode, p.pkgFlags, p.pkgPrivateFlags, |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 581 | p.parentPackageName, p.childPackageNames, p.usesStaticLibraries, |
| 582 | p.usesStaticLibrariesVersions); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 583 | mDisabledSysPackages.remove(name); |
| 584 | return ret; |
| 585 | } |
| 586 | |
Kenny Root | c52d6fd | 2012-05-07 23:04:52 -0700 | [diff] [blame] | 587 | boolean isDisabledSystemPackageLPr(String name) { |
| 588 | return mDisabledSysPackages.containsKey(name); |
| 589 | } |
| 590 | |
| 591 | void removeDisabledSystemPackageLPw(String name) { |
| 592 | mDisabledSysPackages.remove(name); |
| 593 | } |
| 594 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 595 | PackageSetting addPackageLPw(String name, String realName, File codePath, File resourcePath, |
Svet Ganov | f4ff39c | 2016-02-04 14:27:05 -0800 | [diff] [blame] | 596 | String legacyNativeLibraryPathString, String primaryCpuAbiString, |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 597 | String secondaryCpuAbiString, String cpuAbiOverrideString, int uid, long vc, int |
Svet Ganov | f4ff39c | 2016-02-04 14:27:05 -0800 | [diff] [blame] | 598 | pkgFlags, int pkgPrivateFlags, String parentPackageName, |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 599 | List<String> childPackageNames, String[] usesStaticLibraries, |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 600 | long[] usesStaticLibraryNames) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 601 | PackageSetting p = mPackages.get(name); |
| 602 | if (p != null) { |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 603 | if (p.appId == uid) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 604 | return p; |
| 605 | } |
| 606 | PackageManagerService.reportSettingsProblem(Log.ERROR, |
| 607 | "Adding duplicate package, keeping first: " + name); |
| 608 | return null; |
| 609 | } |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 610 | p = new PackageSetting(name, realName, codePath, resourcePath, |
Narayan Kamath | 4903f64 | 2014-08-11 13:33:45 +0100 | [diff] [blame] | 611 | legacyNativeLibraryPathString, primaryCpuAbiString, secondaryCpuAbiString, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 612 | cpuAbiOverrideString, vc, pkgFlags, pkgPrivateFlags, parentPackageName, |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 613 | childPackageNames, 0 /*userId*/, usesStaticLibraries, usesStaticLibraryNames); |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 614 | p.appId = uid; |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 615 | if (addUserIdLPw(uid, p, name)) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 616 | mPackages.put(name, p); |
| 617 | return p; |
| 618 | } |
| 619 | return null; |
| 620 | } |
| 621 | |
Todd Kennedy | c842393 | 2017-10-05 08:58:36 -0700 | [diff] [blame] | 622 | void addAppOpPackage(String permName, String packageName) { |
| 623 | mPermissions.addAppOpPackage(permName, packageName); |
| 624 | } |
| 625 | |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 626 | SharedUserSetting addSharedUserLPw(String name, int uid, int pkgFlags, int pkgPrivateFlags) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 627 | SharedUserSetting s = mSharedUsers.get(name); |
| 628 | if (s != null) { |
| 629 | if (s.userId == uid) { |
| 630 | return s; |
| 631 | } |
| 632 | PackageManagerService.reportSettingsProblem(Log.ERROR, |
| 633 | "Adding duplicate shared user, keeping first: " + name); |
| 634 | return null; |
| 635 | } |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 636 | s = new SharedUserSetting(name, pkgFlags, pkgPrivateFlags); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 637 | s.userId = uid; |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 638 | if (addUserIdLPw(uid, s, name)) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 639 | mSharedUsers.put(name, s); |
| 640 | return s; |
| 641 | } |
| 642 | return null; |
| 643 | } |
| 644 | |
Christopher Tate | 86b391c | 2013-09-13 16:58:36 -0700 | [diff] [blame] | 645 | void pruneSharedUsersLPw() { |
| 646 | ArrayList<String> removeStage = new ArrayList<String>(); |
| 647 | for (Map.Entry<String,SharedUserSetting> entry : mSharedUsers.entrySet()) { |
| 648 | final SharedUserSetting sus = entry.getValue(); |
Todd Kennedy | 68f6715 | 2015-10-21 13:09:10 -0700 | [diff] [blame] | 649 | if (sus == null) { |
| 650 | removeStage.add(entry.getKey()); |
| 651 | continue; |
| 652 | } |
| 653 | // remove packages that are no longer installed |
| 654 | for (Iterator<PackageSetting> iter = sus.packages.iterator(); iter.hasNext();) { |
| 655 | PackageSetting ps = iter.next(); |
| 656 | if (mPackages.get(ps.name) == null) { |
| 657 | iter.remove(); |
| 658 | } |
| 659 | } |
| 660 | if (sus.packages.size() == 0) { |
Christopher Tate | 86b391c | 2013-09-13 16:58:36 -0700 | [diff] [blame] | 661 | removeStage.add(entry.getKey()); |
| 662 | } |
| 663 | } |
| 664 | for (int i = 0; i < removeStage.size(); i++) { |
| 665 | mSharedUsers.remove(removeStage.get(i)); |
| 666 | } |
| 667 | } |
| 668 | |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 669 | /** |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 670 | * Creates a new {@code PackageSetting} object. |
| 671 | * Use this method instead of the constructor to ensure a settings object is created |
| 672 | * with the correct base. |
Todd Kennedy | 13715d5 | 2016-08-01 13:38:57 -0700 | [diff] [blame] | 673 | */ |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 674 | static @NonNull PackageSetting createNewSetting(String pkgName, PackageSetting originalPkg, |
| 675 | PackageSetting disabledPkg, String realPkgName, SharedUserSetting sharedUser, |
| 676 | File codePath, File resourcePath, String legacyNativeLibraryPath, String primaryCpuAbi, |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 677 | String secondaryCpuAbi, long versionCode, int pkgFlags, int pkgPrivateFlags, |
Todd Kennedy | 5eb5a7d | 2017-08-01 07:42:47 -0700 | [diff] [blame] | 678 | UserHandle installUser, boolean allowInstall, boolean instantApp, |
| 679 | boolean virtualPreload, String parentPkgName, List<String> childPkgNames, |
| 680 | UserManagerService userManager, |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 681 | String[] usesStaticLibraries, long[] usesStaticLibrariesVersions) { |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 682 | final PackageSetting pkgSetting; |
| 683 | if (originalPkg != null) { |
| 684 | if (PackageManagerService.DEBUG_UPGRADE) Log.v(PackageManagerService.TAG, "Package " |
| 685 | + pkgName + " is adopting original package " + originalPkg.name); |
| 686 | pkgSetting = new PackageSetting(originalPkg, pkgName /*realPkgName*/); |
| 687 | pkgSetting.childPackageNames = |
| 688 | (childPkgNames != null) ? new ArrayList<>(childPkgNames) : null; |
| 689 | pkgSetting.codePath = codePath; |
| 690 | pkgSetting.legacyNativeLibraryPathString = legacyNativeLibraryPath; |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 691 | pkgSetting.parentPackageName = parentPkgName; |
| 692 | pkgSetting.pkgFlags = pkgFlags; |
| 693 | pkgSetting.pkgPrivateFlags = pkgPrivateFlags; |
Todd Kennedy | 13715d5 | 2016-08-01 13:38:57 -0700 | [diff] [blame] | 694 | pkgSetting.primaryCpuAbiString = primaryCpuAbi; |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 695 | pkgSetting.resourcePath = resourcePath; |
Todd Kennedy | 13715d5 | 2016-08-01 13:38:57 -0700 | [diff] [blame] | 696 | pkgSetting.secondaryCpuAbiString = secondaryCpuAbi; |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 697 | // NOTE: Create a deeper copy of the package signatures so we don't |
| 698 | // overwrite the signatures in the original package setting. |
| 699 | pkgSetting.signatures = new PackageSignatures(); |
| 700 | pkgSetting.versionCode = versionCode; |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 701 | pkgSetting.usesStaticLibraries = usesStaticLibraries; |
| 702 | pkgSetting.usesStaticLibrariesVersions = usesStaticLibrariesVersions; |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 703 | // Update new package state. |
| 704 | pkgSetting.setTimeStamp(codePath.lastModified()); |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 705 | } else { |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 706 | pkgSetting = new PackageSetting(pkgName, realPkgName, codePath, resourcePath, |
| 707 | legacyNativeLibraryPath, primaryCpuAbi, secondaryCpuAbi, |
| 708 | null /*cpuAbiOverrideString*/, versionCode, pkgFlags, pkgPrivateFlags, |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 709 | parentPkgName, childPkgNames, 0 /*sharedUserId*/, usesStaticLibraries, |
| 710 | usesStaticLibrariesVersions); |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 711 | pkgSetting.setTimeStamp(codePath.lastModified()); |
| 712 | pkgSetting.sharedUser = sharedUser; |
| 713 | // If this is not a system app, it starts out stopped. |
| 714 | if ((pkgFlags&ApplicationInfo.FLAG_SYSTEM) == 0) { |
| 715 | if (DEBUG_STOPPED) { |
| 716 | RuntimeException e = new RuntimeException("here"); |
| 717 | e.fillInStackTrace(); |
| 718 | Slog.i(PackageManagerService.TAG, "Stopping package " + pkgName, e); |
| 719 | } |
Todd Kennedy | 13715d5 | 2016-08-01 13:38:57 -0700 | [diff] [blame] | 720 | List<UserInfo> users = getAllUsers(userManager); |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 721 | final int installUserId = installUser != null ? installUser.getIdentifier() : 0; |
| 722 | if (users != null && allowInstall) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 723 | for (UserInfo user : users) { |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 724 | // By default we consider this app to be installed |
| 725 | // for the user if no user has been specified (which |
| 726 | // means to leave it at its original value, and the |
| 727 | // original default value is true), or we are being |
| 728 | // asked to install for all users, or this is the |
| 729 | // user we are installing for. |
| 730 | final boolean installed = installUser == null |
| 731 | || (installUserId == UserHandle.USER_ALL |
Amith Yamasani | 8cd28b5 | 2014-06-08 17:54:27 -0700 | [diff] [blame] | 732 | && !isAdbInstallDisallowed(userManager, user.id)) |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 733 | || installUserId == user.id; |
| 734 | pkgSetting.setUserState(user.id, 0, COMPONENT_ENABLED_STATE_DEFAULT, |
| 735 | installed, |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 736 | true /*stopped*/, |
| 737 | true /*notLaunched*/, |
| 738 | false /*hidden*/, |
| 739 | false /*suspended*/, |
Suprabh Shukla | 151b21b | 2018-04-27 19:30:30 -0700 | [diff] [blame] | 740 | null /*suspendingPackage*/, |
Suprabh Shukla | 389cb6f | 2018-10-01 18:20:39 -0700 | [diff] [blame] | 741 | null /*dialogInfo*/, |
Suprabh Shukla | 151b21b | 2018-04-27 19:30:30 -0700 | [diff] [blame] | 742 | null /*suspendedAppExtras*/, |
| 743 | null /*suspendedLauncherExtras*/, |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 744 | instantApp, |
Todd Kennedy | 5eb5a7d | 2017-08-01 07:42:47 -0700 | [diff] [blame] | 745 | virtualPreload, |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 746 | null /*lastDisableAppCaller*/, |
| 747 | null /*enabledComponents*/, |
| 748 | null /*disabledComponents*/, |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 749 | INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_UNDEFINED, |
Ben Gruver | 1ab3d6e | 2017-12-07 13:45:08 -0800 | [diff] [blame] | 750 | 0, PackageManager.INSTALL_REASON_UNKNOWN, |
| 751 | null /*harmfulAppWarning*/); |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 752 | } |
| 753 | } |
| 754 | } |
| 755 | if (sharedUser != null) { |
| 756 | pkgSetting.appId = sharedUser.userId; |
| 757 | } else { |
| 758 | // Clone the setting here for disabled system packages |
| 759 | if (disabledPkg != null) { |
| 760 | // For disabled packages a new setting is created |
| 761 | // from the existing user id. This still has to be |
| 762 | // added to list of user id's |
| 763 | // Copy signatures from previous setting |
| 764 | pkgSetting.signatures = new PackageSignatures(disabledPkg.signatures); |
| 765 | pkgSetting.appId = disabledPkg.appId; |
| 766 | // Clone permissions |
| 767 | pkgSetting.getPermissionsState().copyFrom(disabledPkg.getPermissionsState()); |
| 768 | // Clone component info |
| 769 | List<UserInfo> users = getAllUsers(userManager); |
| 770 | if (users != null) { |
| 771 | for (UserInfo user : users) { |
| 772 | final int userId = user.id; |
| 773 | pkgSetting.setDisabledComponentsCopy( |
| 774 | disabledPkg.getDisabledComponents(userId), userId); |
| 775 | pkgSetting.setEnabledComponentsCopy( |
| 776 | disabledPkg.getEnabledComponents(userId), userId); |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 777 | } |
| 778 | } |
| 779 | } |
| 780 | } |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 781 | } |
Todd Kennedy | 13715d5 | 2016-08-01 13:38:57 -0700 | [diff] [blame] | 782 | return pkgSetting; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 783 | } |
| 784 | |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 785 | /** |
| 786 | * Updates the given package setting using the provided information. |
| 787 | * <p> |
| 788 | * WARNING: The provided PackageSetting object may be mutated. |
| 789 | */ |
| 790 | static void updatePackageSetting(@NonNull PackageSetting pkgSetting, |
| 791 | @Nullable PackageSetting disabledPkg, @Nullable SharedUserSetting sharedUser, |
Todd Kennedy | 30a23a5 | 2018-01-04 13:27:49 -0800 | [diff] [blame] | 792 | @NonNull File codePath, File resourcePath, |
| 793 | @Nullable String legacyNativeLibraryPath, @Nullable String primaryCpuAbi, |
| 794 | @Nullable String secondaryCpuAbi, int pkgFlags, int pkgPrivateFlags, |
| 795 | @Nullable List<String> childPkgNames, @NonNull UserManagerService userManager, |
| 796 | @Nullable String[] usesStaticLibraries, @Nullable long[] usesStaticLibrariesVersions) |
| 797 | throws PackageManagerException { |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 798 | final String pkgName = pkgSetting.name; |
| 799 | if (pkgSetting.sharedUser != sharedUser) { |
| 800 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 801 | "Package " + pkgName + " shared user changed from " |
| 802 | + (pkgSetting.sharedUser != null ? pkgSetting.sharedUser.name : "<nothing>") |
| 803 | + " to " + (sharedUser != null ? sharedUser.name : "<nothing>")); |
| 804 | throw new PackageManagerException(INSTALL_FAILED_SHARED_USER_INCOMPATIBLE, |
| 805 | "Updating application package " + pkgName + " failed"); |
| 806 | } |
| 807 | |
| 808 | if (!pkgSetting.codePath.equals(codePath)) { |
Todd Kennedy | 30a23a5 | 2018-01-04 13:27:49 -0800 | [diff] [blame] | 809 | final boolean isSystem = pkgSetting.isSystem(); |
| 810 | Slog.i(PackageManagerService.TAG, |
| 811 | "Update" + (isSystem ? " system" : "") |
| 812 | + " package " + pkgName |
| 813 | + " code path from " + pkgSetting.codePathString |
| 814 | + " to " + codePath.toString() |
| 815 | + "; Retain data and using new"); |
| 816 | if (!isSystem) { |
| 817 | // The package isn't considered as installed if the application was |
| 818 | // first installed by another user. Update the installed flag when the |
| 819 | // application ever becomes part of the system. |
| 820 | if ((pkgFlags & ApplicationInfo.FLAG_SYSTEM) != 0 && disabledPkg == null) { |
| 821 | final List<UserInfo> allUserInfos = getAllUsers(userManager); |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 822 | if (allUserInfos != null) { |
| 823 | for (UserInfo userInfo : allUserInfos) { |
| 824 | pkgSetting.setInstalled(true, userInfo.id); |
| 825 | } |
| 826 | } |
| 827 | } |
| 828 | |
Todd Kennedy | 30a23a5 | 2018-01-04 13:27:49 -0800 | [diff] [blame] | 829 | // Since we've changed paths, prefer the new native library path over |
| 830 | // the one stored in the package settings since we might have moved from |
| 831 | // internal to external storage or vice versa. |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 832 | pkgSetting.legacyNativeLibraryPathString = legacyNativeLibraryPath; |
| 833 | } |
Todd Kennedy | 30a23a5 | 2018-01-04 13:27:49 -0800 | [diff] [blame] | 834 | pkgSetting.codePath = codePath; |
| 835 | pkgSetting.codePathString = codePath.toString(); |
| 836 | } |
| 837 | if (!pkgSetting.resourcePath.equals(resourcePath)) { |
| 838 | final boolean isSystem = pkgSetting.isSystem(); |
| 839 | Slog.i(PackageManagerService.TAG, |
| 840 | "Update" + (isSystem ? " system" : "") |
| 841 | + " package " + pkgName |
| 842 | + " resource path from " + pkgSetting.resourcePathString |
| 843 | + " to " + resourcePath.toString() |
| 844 | + "; Retain data and using new"); |
| 845 | pkgSetting.resourcePath = resourcePath; |
| 846 | pkgSetting.resourcePathString = resourcePath.toString(); |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 847 | } |
| 848 | // If what we are scanning is a system (and possibly privileged) package, |
| 849 | // then make it so, regardless of whether it was previously installed only |
Patrick Baumann | a639d14 | 2018-05-02 15:00:59 -0700 | [diff] [blame] | 850 | // in the data partition. Reset first. |
| 851 | pkgSetting.pkgFlags &= ~ApplicationInfo.FLAG_SYSTEM; |
| 852 | pkgSetting.pkgPrivateFlags &= ~(ApplicationInfo.PRIVATE_FLAG_PRIVILEGED |
| 853 | | ApplicationInfo.PRIVATE_FLAG_OEM |
| 854 | | ApplicationInfo.PRIVATE_FLAG_VENDOR |
Dario Freni | 2bef176 | 2018-06-01 14:02:08 +0100 | [diff] [blame] | 855 | | ApplicationInfo.PRIVATE_FLAG_PRODUCT |
| 856 | | ApplicationInfo.PRIVATE_FLAG_PRODUCT_SERVICES); |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 857 | pkgSetting.pkgFlags |= pkgFlags & ApplicationInfo.FLAG_SYSTEM; |
| 858 | pkgSetting.pkgPrivateFlags |= |
| 859 | pkgPrivateFlags & ApplicationInfo.PRIVATE_FLAG_PRIVILEGED; |
Svet Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 860 | pkgSetting.pkgPrivateFlags |= |
| 861 | pkgPrivateFlags & ApplicationInfo.PRIVATE_FLAG_OEM; |
Jiyong Park | 002fdbd | 2017-02-13 20:50:31 +0900 | [diff] [blame] | 862 | pkgSetting.pkgPrivateFlags |= |
| 863 | pkgPrivateFlags & ApplicationInfo.PRIVATE_FLAG_VENDOR; |
Jaekyun Seok | 1713d9e | 2018-01-12 21:47:26 +0900 | [diff] [blame] | 864 | pkgSetting.pkgPrivateFlags |= |
| 865 | pkgPrivateFlags & ApplicationInfo.PRIVATE_FLAG_PRODUCT; |
Dario Freni | 2bef176 | 2018-06-01 14:02:08 +0100 | [diff] [blame] | 866 | pkgSetting.pkgPrivateFlags |= |
| 867 | pkgPrivateFlags & ApplicationInfo.PRIVATE_FLAG_PRODUCT_SERVICES; |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 868 | pkgSetting.primaryCpuAbiString = primaryCpuAbi; |
| 869 | pkgSetting.secondaryCpuAbiString = secondaryCpuAbi; |
| 870 | if (childPkgNames != null) { |
| 871 | pkgSetting.childPackageNames = new ArrayList<>(childPkgNames); |
| 872 | } |
Todd Kennedy | 30a23a5 | 2018-01-04 13:27:49 -0800 | [diff] [blame] | 873 | // Update static shared library dependencies if needed |
| 874 | if (usesStaticLibraries != null && usesStaticLibrariesVersions != null |
| 875 | && usesStaticLibraries.length == usesStaticLibrariesVersions.length) { |
| 876 | pkgSetting.usesStaticLibraries = usesStaticLibraries; |
| 877 | pkgSetting.usesStaticLibrariesVersions = usesStaticLibrariesVersions; |
| 878 | } else { |
| 879 | pkgSetting.usesStaticLibraries = null; |
| 880 | pkgSetting.usesStaticLibrariesVersions = null; |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 881 | } |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 882 | } |
| 883 | |
| 884 | /** |
| 885 | * Registers a user ID with the system. Potentially allocates a new user ID. |
| 886 | * @throws PackageManagerException If a user ID could not be allocated. |
| 887 | */ |
| 888 | void addUserToSettingLPw(PackageSetting p) throws PackageManagerException { |
| 889 | if (p.appId == 0) { |
| 890 | // Assign new user ID |
| 891 | p.appId = newUserIdLPw(p); |
| 892 | } else { |
| 893 | // Add new setting to list of user IDs |
| 894 | addUserIdLPw(p.appId, p, p.name); |
| 895 | } |
| 896 | if (p.appId < 0) { |
| 897 | PackageManagerService.reportSettingsProblem(Log.WARN, |
Jeff Sharkey | f60d8ab | 2017-02-24 11:06:49 -0700 | [diff] [blame] | 898 | "Package " + p.name + " could not be assigned a valid UID"); |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 899 | throw new PackageManagerException(INSTALL_FAILED_INSUFFICIENT_STORAGE, |
Jeff Sharkey | f60d8ab | 2017-02-24 11:06:49 -0700 | [diff] [blame] | 900 | "Package " + p.name + " could not be assigned a valid UID"); |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 901 | } |
| 902 | } |
| 903 | |
| 904 | /** |
| 905 | * Writes per-user package restrictions if the user state has changed. If the user |
| 906 | * state has not changed, this does nothing. |
| 907 | */ |
Todd Kennedy | ff35e66 | 2016-09-20 12:53:52 -0700 | [diff] [blame] | 908 | void writeUserRestrictionsLPw(PackageSetting newPackage, PackageSetting oldPackage) { |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 909 | // package doesn't exist; do nothing |
Todd Kennedy | 8cad623 | 2016-10-06 11:27:07 -0700 | [diff] [blame] | 910 | if (getPackageLPr(newPackage.name) == null) { |
Todd Kennedy | 3cd658e | 2016-08-16 15:00:31 -0700 | [diff] [blame] | 911 | return; |
| 912 | } |
| 913 | // no users defined; do nothing |
| 914 | final List<UserInfo> allUsers = getAllUsers(UserManagerService.getInstance()); |
| 915 | if (allUsers == null) { |
| 916 | return; |
| 917 | } |
| 918 | for (UserInfo user : allUsers) { |
| 919 | final PackageUserState oldUserState = oldPackage == null |
| 920 | ? PackageSettingBase.DEFAULT_USER_STATE |
| 921 | : oldPackage.readUserState(user.id); |
| 922 | if (!oldUserState.equals(newPackage.readUserState(user.id))) { |
| 923 | writePackageRestrictionsLPr(user.id); |
| 924 | } |
| 925 | } |
| 926 | } |
| 927 | |
Todd Kennedy | 13715d5 | 2016-08-01 13:38:57 -0700 | [diff] [blame] | 928 | static boolean isAdbInstallDisallowed(UserManagerService userManager, int userId) { |
Amith Yamasani | 8cd28b5 | 2014-06-08 17:54:27 -0700 | [diff] [blame] | 929 | return userManager.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES, |
| 930 | userId); |
| 931 | } |
| 932 | |
Todd Kennedy | 30a23a5 | 2018-01-04 13:27:49 -0800 | [diff] [blame] | 933 | // TODO: Move to scanPackageOnlyLI() after verifying signatures are setup correctly |
| 934 | // by that time. |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 935 | void insertPackageSettingLPw(PackageSetting p, PackageParser.Package pkg) { |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 936 | // Update signatures if needed. |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 937 | if (p.signatures.mSigningDetails.signatures == null) { |
| 938 | p.signatures.mSigningDetails = pkg.mSigningDetails; |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 939 | } |
| 940 | // If this app defines a shared user id initialize |
| 941 | // the shared user signatures as well. |
Daniel Cashman | 77029c5 | 2018-01-18 16:19:29 -0800 | [diff] [blame] | 942 | if (p.sharedUser != null && p.sharedUser.signatures.mSigningDetails.signatures == null) { |
| 943 | p.sharedUser.signatures.mSigningDetails = pkg.mSigningDetails; |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 944 | } |
Todd Kennedy | 788c842 | 2016-08-10 10:52:34 -0700 | [diff] [blame] | 945 | addPackageSettingLPw(p, p.sharedUser); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 946 | } |
| 947 | |
| 948 | // Utility method that adds a PackageSetting to mPackages and |
Christopher Tate | 6038d15 | 2015-06-17 13:07:46 -0700 | [diff] [blame] | 949 | // completes updating the shared user attributes and any restored |
| 950 | // app link verification state |
Todd Kennedy | 788c842 | 2016-08-10 10:52:34 -0700 | [diff] [blame] | 951 | private void addPackageSettingLPw(PackageSetting p, SharedUserSetting sharedUser) { |
| 952 | mPackages.put(p.name, p); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 953 | if (sharedUser != null) { |
| 954 | if (p.sharedUser != null && p.sharedUser != sharedUser) { |
| 955 | PackageManagerService.reportSettingsProblem(Log.ERROR, |
| 956 | "Package " + p.name + " was user " |
| 957 | + p.sharedUser + " but is now " + sharedUser |
| 958 | + "; I am not changing its files so it will probably fail!"); |
Ben Gruver | dd72c9e | 2013-08-06 12:34:17 -0700 | [diff] [blame] | 959 | p.sharedUser.removePackage(p); |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 960 | } else if (p.appId != sharedUser.userId) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 961 | PackageManagerService.reportSettingsProblem(Log.ERROR, |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 962 | "Package " + p.name + " was user id " + p.appId |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 963 | + " but is now user " + sharedUser |
| 964 | + " with id " + sharedUser.userId |
| 965 | + "; I am not changing its files so it will probably fail!"); |
| 966 | } |
| 967 | |
Ben Gruver | dd72c9e | 2013-08-06 12:34:17 -0700 | [diff] [blame] | 968 | sharedUser.addPackage(p); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 969 | p.sharedUser = sharedUser; |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 970 | p.appId = sharedUser.userId; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 971 | } |
Svet Ganov | e7af194 | 2015-08-04 11:13:44 -0700 | [diff] [blame] | 972 | |
| 973 | // If the we know about this user id, we have to update it as it |
| 974 | // has to point to the same PackageSetting instance as the package. |
| 975 | Object userIdPs = getUserIdLPr(p.appId); |
| 976 | if (sharedUser == null) { |
| 977 | if (userIdPs != null && userIdPs != p) { |
| 978 | replaceUserIdLPw(p.appId, p); |
| 979 | } |
| 980 | } else { |
| 981 | if (userIdPs != null && userIdPs != sharedUser) { |
| 982 | replaceUserIdLPw(p.appId, sharedUser); |
| 983 | } |
| 984 | } |
| 985 | |
Todd Kennedy | 788c842 | 2016-08-10 10:52:34 -0700 | [diff] [blame] | 986 | IntentFilterVerificationInfo ivi = mRestoredIntentFilterVerifications.get(p.name); |
Christopher Tate | 6038d15 | 2015-06-17 13:07:46 -0700 | [diff] [blame] | 987 | if (ivi != null) { |
| 988 | if (DEBUG_DOMAIN_VERIFICATION) { |
Todd Kennedy | 788c842 | 2016-08-10 10:52:34 -0700 | [diff] [blame] | 989 | Slog.i(TAG, "Applying restored IVI for " + p.name + " : " + ivi.getStatusString()); |
Christopher Tate | 6038d15 | 2015-06-17 13:07:46 -0700 | [diff] [blame] | 990 | } |
Todd Kennedy | 788c842 | 2016-08-10 10:52:34 -0700 | [diff] [blame] | 991 | mRestoredIntentFilterVerifications.remove(p.name); |
Christopher Tate | 6038d15 | 2015-06-17 13:07:46 -0700 | [diff] [blame] | 992 | p.setIntentFilterVerificationInfo(ivi); |
| 993 | } |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 994 | } |
| 995 | |
| 996 | /* |
| 997 | * Update the shared user setting when a package using |
| 998 | * specifying the shared user id is removed. The gids |
| 999 | * associated with each permission of the deleted package |
| 1000 | * are removed from the shared user's gid list only if its |
| 1001 | * not in use by other permissions of packages in the |
| 1002 | * shared user setting. |
| 1003 | */ |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 1004 | int updateSharedUserPermsLPw(PackageSetting deletedPs, int userId) { |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 1005 | if ((deletedPs == null) || (deletedPs.pkg == null)) { |
| 1006 | Slog.i(PackageManagerService.TAG, |
| 1007 | "Trying to update info for null package. Just ignoring"); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 1008 | return UserHandle.USER_NULL; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1009 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 1010 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1011 | // No sharedUserId |
| 1012 | if (deletedPs.sharedUser == null) { |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 1013 | return UserHandle.USER_NULL; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1014 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 1015 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1016 | SharedUserSetting sus = deletedPs.sharedUser; |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 1017 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1018 | // Update permissions |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 1019 | for (String eachPerm : deletedPs.pkg.requestedPermissions) { |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 1020 | BasePermission bp = mPermissions.getPermission(eachPerm); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 1021 | if (bp == null) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1022 | continue; |
| 1023 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 1024 | |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 1025 | // Check if another package in the shared user needs the permission. |
Svetoslav | 4a5f4a2 | 2015-07-07 18:18:15 -0700 | [diff] [blame] | 1026 | boolean used = false; |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 1027 | for (PackageSetting pkg : sus.packages) { |
| 1028 | if (pkg.pkg != null |
| 1029 | && !pkg.pkg.packageName.equals(deletedPs.pkg.packageName) |
| 1030 | && pkg.pkg.requestedPermissions.contains(eachPerm)) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1031 | used = true; |
| 1032 | break; |
| 1033 | } |
| 1034 | } |
Svetoslav | 4a5f4a2 | 2015-07-07 18:18:15 -0700 | [diff] [blame] | 1035 | if (used) { |
| 1036 | continue; |
| 1037 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 1038 | |
Svetoslav | 4a5f4a2 | 2015-07-07 18:18:15 -0700 | [diff] [blame] | 1039 | PermissionsState permissionsState = sus.getPermissionsState(); |
| 1040 | PackageSetting disabledPs = getDisabledSystemPkgLPr(deletedPs.pkg.packageName); |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 1041 | |
Svetoslav | 4a5f4a2 | 2015-07-07 18:18:15 -0700 | [diff] [blame] | 1042 | // If the package is shadowing is a disabled system package, |
| 1043 | // do not drop permissions that the shadowed package requests. |
| 1044 | if (disabledPs != null) { |
| 1045 | boolean reqByDisabledSysPkg = false; |
| 1046 | for (String permission : disabledPs.pkg.requestedPermissions) { |
| 1047 | if (permission.equals(eachPerm)) { |
| 1048 | reqByDisabledSysPkg = true; |
| 1049 | break; |
| 1050 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 1051 | } |
Svetoslav | 4a5f4a2 | 2015-07-07 18:18:15 -0700 | [diff] [blame] | 1052 | if (reqByDisabledSysPkg) { |
| 1053 | continue; |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 1054 | } |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1055 | } |
Svetoslav | 4a5f4a2 | 2015-07-07 18:18:15 -0700 | [diff] [blame] | 1056 | |
| 1057 | // Try to revoke as an install permission which is for all users. |
| 1058 | // The package is gone - no need to keep flags for applying policy. |
| 1059 | permissionsState.updatePermissionFlags(bp, userId, |
| 1060 | PackageManager.MASK_PERMISSION_FLAGS, 0); |
| 1061 | |
| 1062 | if (permissionsState.revokeInstallPermission(bp) == |
| 1063 | PermissionsState.PERMISSION_OPERATION_SUCCESS_GIDS_CHANGED) { |
| 1064 | return UserHandle.USER_ALL; |
| 1065 | } |
| 1066 | |
| 1067 | // Try to revoke as an install permission which is per user. |
| 1068 | if (permissionsState.revokeRuntimePermission(bp, userId) == |
| 1069 | PermissionsState.PERMISSION_OPERATION_SUCCESS_GIDS_CHANGED) { |
| 1070 | return userId; |
| 1071 | } |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1072 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 1073 | |
| 1074 | return UserHandle.USER_NULL; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1075 | } |
| 1076 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 1077 | int removePackageLPw(String name) { |
| 1078 | final PackageSetting p = mPackages.get(name); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1079 | if (p != null) { |
| 1080 | mPackages.remove(name); |
Sudheer Shanka | 2928337 | 2016-04-04 20:56:27 -0700 | [diff] [blame] | 1081 | removeInstallerPackageStatus(name); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1082 | if (p.sharedUser != null) { |
Ben Gruver | dd72c9e | 2013-08-06 12:34:17 -0700 | [diff] [blame] | 1083 | p.sharedUser.removePackage(p); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1084 | if (p.sharedUser.packages.size() == 0) { |
| 1085 | mSharedUsers.remove(p.sharedUser.name); |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 1086 | removeUserIdLPw(p.sharedUser.userId); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1087 | return p.sharedUser.userId; |
| 1088 | } |
| 1089 | } else { |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 1090 | removeUserIdLPw(p.appId); |
| 1091 | return p.appId; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1092 | } |
| 1093 | } |
| 1094 | return -1; |
| 1095 | } |
| 1096 | |
Sudheer Shanka | 2928337 | 2016-04-04 20:56:27 -0700 | [diff] [blame] | 1097 | /** |
| 1098 | * Checks if {@param packageName} is an installer package and if so, clear the installer |
| 1099 | * package name of the packages that are installed by this. |
| 1100 | */ |
| 1101 | private void removeInstallerPackageStatus(String packageName) { |
| 1102 | // Check if the package to be removed is an installer package. |
| 1103 | if (!mInstallerPackages.contains(packageName)) { |
| 1104 | return; |
| 1105 | } |
| 1106 | for (int i = 0; i < mPackages.size(); i++) { |
| 1107 | final PackageSetting ps = mPackages.valueAt(i); |
| 1108 | final String installerPackageName = ps.getInstallerPackageName(); |
| 1109 | if (installerPackageName != null |
| 1110 | && installerPackageName.equals(packageName)) { |
| 1111 | ps.setInstallerPackageName(null); |
Sudheer Shanka | 8c57aea | 2016-04-20 16:47:50 -0700 | [diff] [blame] | 1112 | ps.isOrphaned = true; |
Sudheer Shanka | 2928337 | 2016-04-04 20:56:27 -0700 | [diff] [blame] | 1113 | } |
| 1114 | } |
| 1115 | mInstallerPackages.remove(packageName); |
| 1116 | } |
| 1117 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 1118 | private boolean addUserIdLPw(int uid, Object obj, Object name) { |
Dianne Hackborn | 21fbd1f | 2012-02-10 10:38:10 -0800 | [diff] [blame] | 1119 | if (uid > Process.LAST_APPLICATION_UID) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1120 | return false; |
| 1121 | } |
| 1122 | |
Dianne Hackborn | 21fbd1f | 2012-02-10 10:38:10 -0800 | [diff] [blame] | 1123 | if (uid >= Process.FIRST_APPLICATION_UID) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1124 | int N = mUserIds.size(); |
Dianne Hackborn | 21fbd1f | 2012-02-10 10:38:10 -0800 | [diff] [blame] | 1125 | final int index = uid - Process.FIRST_APPLICATION_UID; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1126 | while (index >= N) { |
| 1127 | mUserIds.add(null); |
| 1128 | N++; |
| 1129 | } |
| 1130 | if (mUserIds.get(index) != null) { |
| 1131 | PackageManagerService.reportSettingsProblem(Log.ERROR, |
| 1132 | "Adding duplicate user id: " + uid |
| 1133 | + " name=" + name); |
| 1134 | return false; |
| 1135 | } |
| 1136 | mUserIds.set(index, obj); |
| 1137 | } else { |
| 1138 | if (mOtherUserIds.get(uid) != null) { |
| 1139 | PackageManagerService.reportSettingsProblem(Log.ERROR, |
| 1140 | "Adding duplicate shared id: " + uid |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1141 | + " name=" + name); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1142 | return false; |
| 1143 | } |
| 1144 | mOtherUserIds.put(uid, obj); |
| 1145 | } |
| 1146 | return true; |
| 1147 | } |
| 1148 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 1149 | public Object getUserIdLPr(int uid) { |
Dianne Hackborn | 21fbd1f | 2012-02-10 10:38:10 -0800 | [diff] [blame] | 1150 | if (uid >= Process.FIRST_APPLICATION_UID) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1151 | final int N = mUserIds.size(); |
Dianne Hackborn | 21fbd1f | 2012-02-10 10:38:10 -0800 | [diff] [blame] | 1152 | final int index = uid - Process.FIRST_APPLICATION_UID; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1153 | return index < N ? mUserIds.get(index) : null; |
| 1154 | } else { |
| 1155 | return mOtherUserIds.get(uid); |
| 1156 | } |
| 1157 | } |
| 1158 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 1159 | private void removeUserIdLPw(int uid) { |
Dianne Hackborn | 21fbd1f | 2012-02-10 10:38:10 -0800 | [diff] [blame] | 1160 | if (uid >= Process.FIRST_APPLICATION_UID) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1161 | final int N = mUserIds.size(); |
Dianne Hackborn | 21fbd1f | 2012-02-10 10:38:10 -0800 | [diff] [blame] | 1162 | final int index = uid - Process.FIRST_APPLICATION_UID; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1163 | if (index < N) mUserIds.set(index, null); |
| 1164 | } else { |
| 1165 | mOtherUserIds.remove(uid); |
| 1166 | } |
Geremy Condra | 12c1838 | 2013-03-06 16:49:06 -0800 | [diff] [blame] | 1167 | setFirstAvailableUid(uid+1); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1168 | } |
| 1169 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 1170 | private void replaceUserIdLPw(int uid, Object obj) { |
Dianne Hackborn | 21fbd1f | 2012-02-10 10:38:10 -0800 | [diff] [blame] | 1171 | if (uid >= Process.FIRST_APPLICATION_UID) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1172 | final int N = mUserIds.size(); |
Dianne Hackborn | 21fbd1f | 2012-02-10 10:38:10 -0800 | [diff] [blame] | 1173 | final int index = uid - Process.FIRST_APPLICATION_UID; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1174 | if (index < N) mUserIds.set(index, obj); |
| 1175 | } else { |
| 1176 | mOtherUserIds.put(uid, obj); |
| 1177 | } |
| 1178 | } |
| 1179 | |
Dianne Hackborn | 6309271 | 2012-10-07 14:45:35 -0700 | [diff] [blame] | 1180 | PreferredIntentResolver editPreferredActivitiesLPw(int userId) { |
| 1181 | PreferredIntentResolver pir = mPreferredActivities.get(userId); |
| 1182 | if (pir == null) { |
| 1183 | pir = new PreferredIntentResolver(); |
| 1184 | mPreferredActivities.put(userId, pir); |
| 1185 | } |
| 1186 | return pir; |
| 1187 | } |
| 1188 | |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 1189 | PersistentPreferredIntentResolver editPersistentPreferredActivitiesLPw(int userId) { |
| 1190 | PersistentPreferredIntentResolver ppir = mPersistentPreferredActivities.get(userId); |
| 1191 | if (ppir == null) { |
| 1192 | ppir = new PersistentPreferredIntentResolver(); |
| 1193 | mPersistentPreferredActivities.put(userId, ppir); |
| 1194 | } |
| 1195 | return ppir; |
| 1196 | } |
| 1197 | |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 1198 | CrossProfileIntentResolver editCrossProfileIntentResolverLPw(int userId) { |
| 1199 | CrossProfileIntentResolver cpir = mCrossProfileIntentResolvers.get(userId); |
| 1200 | if (cpir == null) { |
| 1201 | cpir = new CrossProfileIntentResolver(); |
| 1202 | mCrossProfileIntentResolvers.put(userId, cpir); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1203 | } |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 1204 | return cpir; |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1205 | } |
| 1206 | |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1207 | /** |
| 1208 | * The following functions suppose that you have a lock for managing access to the |
| 1209 | * mIntentFiltersVerifications map. |
| 1210 | */ |
| 1211 | |
| 1212 | /* package protected */ |
| 1213 | IntentFilterVerificationInfo getIntentFilterVerificationLPr(String packageName) { |
| 1214 | PackageSetting ps = mPackages.get(packageName); |
| 1215 | if (ps == null) { |
Christopher Tate | 72c10a2 | 2015-06-12 18:31:24 -0700 | [diff] [blame] | 1216 | if (DEBUG_DOMAIN_VERIFICATION) { |
| 1217 | Slog.w(PackageManagerService.TAG, "No package known: " + packageName); |
| 1218 | } |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1219 | return null; |
| 1220 | } |
| 1221 | return ps.getIntentFilterVerificationInfo(); |
| 1222 | } |
| 1223 | |
| 1224 | /* package protected */ |
Fabrice Di Meglio | 7d014ce | 2015-04-08 16:17:46 -0700 | [diff] [blame] | 1225 | IntentFilterVerificationInfo createIntentFilterVerificationIfNeededLPw(String packageName, |
Todd Kennedy | 788c842 | 2016-08-10 10:52:34 -0700 | [diff] [blame] | 1226 | ArraySet<String> domains) { |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1227 | PackageSetting ps = mPackages.get(packageName); |
| 1228 | if (ps == null) { |
Christopher Tate | 72c10a2 | 2015-06-12 18:31:24 -0700 | [diff] [blame] | 1229 | if (DEBUG_DOMAIN_VERIFICATION) { |
| 1230 | Slog.w(PackageManagerService.TAG, "No package known: " + packageName); |
| 1231 | } |
Fabrice Di Meglio | 7d014ce | 2015-04-08 16:17:46 -0700 | [diff] [blame] | 1232 | return null; |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1233 | } |
Fabrice Di Meglio | 7d014ce | 2015-04-08 16:17:46 -0700 | [diff] [blame] | 1234 | IntentFilterVerificationInfo ivi = ps.getIntentFilterVerificationInfo(); |
| 1235 | if (ivi == null) { |
| 1236 | ivi = new IntentFilterVerificationInfo(packageName, domains); |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1237 | ps.setIntentFilterVerificationInfo(ivi); |
Christopher Tate | 72c10a2 | 2015-06-12 18:31:24 -0700 | [diff] [blame] | 1238 | if (DEBUG_DOMAIN_VERIFICATION) { |
| 1239 | Slog.d(PackageManagerService.TAG, |
| 1240 | "Creating new IntentFilterVerificationInfo for pkg: " + packageName); |
| 1241 | } |
Fabrice Di Meglio | 1de3f0d | 2015-04-29 19:42:41 -0700 | [diff] [blame] | 1242 | } else { |
| 1243 | ivi.setDomains(domains); |
Christopher Tate | 72c10a2 | 2015-06-12 18:31:24 -0700 | [diff] [blame] | 1244 | if (DEBUG_DOMAIN_VERIFICATION) { |
| 1245 | Slog.d(PackageManagerService.TAG, |
| 1246 | "Setting domains to existing IntentFilterVerificationInfo for pkg: " + |
| 1247 | packageName + " and with domains: " + ivi.getDomainsString()); |
| 1248 | } |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1249 | } |
Fabrice Di Meglio | 7d014ce | 2015-04-08 16:17:46 -0700 | [diff] [blame] | 1250 | return ivi; |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1251 | } |
| 1252 | |
| 1253 | int getIntentFilterVerificationStatusLPr(String packageName, int userId) { |
| 1254 | PackageSetting ps = mPackages.get(packageName); |
| 1255 | if (ps == null) { |
Christopher Tate | 72c10a2 | 2015-06-12 18:31:24 -0700 | [diff] [blame] | 1256 | if (DEBUG_DOMAIN_VERIFICATION) { |
| 1257 | Slog.w(PackageManagerService.TAG, "No package known: " + packageName); |
| 1258 | } |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1259 | return INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_UNDEFINED; |
| 1260 | } |
Christopher Tate | d85a664 | 2015-07-17 15:39:08 -0700 | [diff] [blame] | 1261 | return (int)(ps.getDomainVerificationStatusForUser(userId) >> 32); |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1262 | } |
| 1263 | |
Christopher Tate | f0d6cb3 | 2015-07-10 17:44:53 -0700 | [diff] [blame] | 1264 | boolean updateIntentFilterVerificationStatusLPw(String packageName, final int status, int userId) { |
Fabrice Di Meglio | 0788595 | 2015-04-06 19:41:28 -0700 | [diff] [blame] | 1265 | // Update the status for the current package |
| 1266 | PackageSetting current = mPackages.get(packageName); |
| 1267 | if (current == null) { |
Christopher Tate | 72c10a2 | 2015-06-12 18:31:24 -0700 | [diff] [blame] | 1268 | if (DEBUG_DOMAIN_VERIFICATION) { |
| 1269 | Slog.w(PackageManagerService.TAG, "No package known: " + packageName); |
| 1270 | } |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1271 | return false; |
| 1272 | } |
Christopher Tate | 050aee2 | 2015-07-01 16:50:43 -0700 | [diff] [blame] | 1273 | |
Christopher Tate | f0d6cb3 | 2015-07-10 17:44:53 -0700 | [diff] [blame] | 1274 | final int alwaysGeneration; |
| 1275 | if (status == INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ALWAYS) { |
| 1276 | alwaysGeneration = mNextAppLinkGeneration.get(userId) + 1; |
| 1277 | mNextAppLinkGeneration.put(userId, alwaysGeneration); |
| 1278 | } else { |
| 1279 | alwaysGeneration = 0; |
| 1280 | } |
| 1281 | |
| 1282 | current.setDomainVerificationStatusForUser(status, alwaysGeneration, userId); |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1283 | return true; |
| 1284 | } |
| 1285 | |
| 1286 | /** |
Fabrice Di Meglio | 0788595 | 2015-04-06 19:41:28 -0700 | [diff] [blame] | 1287 | * Used for Settings App and PackageManagerService dump. Should be read only. |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1288 | */ |
| 1289 | List<IntentFilterVerificationInfo> getIntentFilterVerificationsLPr( |
| 1290 | String packageName) { |
| 1291 | if (packageName == null) { |
| 1292 | return Collections.<IntentFilterVerificationInfo>emptyList(); |
| 1293 | } |
| 1294 | ArrayList<IntentFilterVerificationInfo> result = new ArrayList<>(); |
| 1295 | for (PackageSetting ps : mPackages.values()) { |
| 1296 | IntentFilterVerificationInfo ivi = ps.getIntentFilterVerificationInfo(); |
| 1297 | if (ivi == null || TextUtils.isEmpty(ivi.getPackageName()) || |
| 1298 | !ivi.getPackageName().equalsIgnoreCase(packageName)) { |
| 1299 | continue; |
| 1300 | } |
| 1301 | result.add(ivi); |
| 1302 | } |
| 1303 | return result; |
| 1304 | } |
| 1305 | |
Fabrice Di Meglio | 1f09b8c | 2015-05-06 18:51:21 -0700 | [diff] [blame] | 1306 | boolean removeIntentFilterVerificationLPw(String packageName, int userId) { |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1307 | PackageSetting ps = mPackages.get(packageName); |
| 1308 | if (ps == null) { |
Christopher Tate | 72c10a2 | 2015-06-12 18:31:24 -0700 | [diff] [blame] | 1309 | if (DEBUG_DOMAIN_VERIFICATION) { |
| 1310 | Slog.w(PackageManagerService.TAG, "No package known: " + packageName); |
| 1311 | } |
Fabrice Di Meglio | 1f09b8c | 2015-05-06 18:51:21 -0700 | [diff] [blame] | 1312 | return false; |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1313 | } |
| 1314 | ps.clearDomainVerificationStatusForUser(userId); |
Fabrice Di Meglio | 1f09b8c | 2015-05-06 18:51:21 -0700 | [diff] [blame] | 1315 | return true; |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1316 | } |
| 1317 | |
Fabrice Di Meglio | 1f09b8c | 2015-05-06 18:51:21 -0700 | [diff] [blame] | 1318 | boolean removeIntentFilterVerificationLPw(String packageName, int[] userIds) { |
| 1319 | boolean result = false; |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1320 | for (int userId : userIds) { |
Fabrice Di Meglio | 1f09b8c | 2015-05-06 18:51:21 -0700 | [diff] [blame] | 1321 | result |= removeIntentFilterVerificationLPw(packageName, userId); |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1322 | } |
Fabrice Di Meglio | 1f09b8c | 2015-05-06 18:51:21 -0700 | [diff] [blame] | 1323 | return result; |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1324 | } |
| 1325 | |
Christopher Tate | db3fe81 | 2015-06-24 16:15:48 -0700 | [diff] [blame] | 1326 | boolean setDefaultBrowserPackageNameLPw(String packageName, int userId) { |
Fabrice Di Meglio | 6227172 | 2015-04-10 17:24:02 -0700 | [diff] [blame] | 1327 | if (userId == UserHandle.USER_ALL) { |
| 1328 | return false; |
| 1329 | } |
Christopher Tate | 53d52c8 | 2017-04-24 15:55:33 -0700 | [diff] [blame] | 1330 | if (packageName != null) { |
| 1331 | mDefaultBrowserApp.put(userId, packageName); |
| 1332 | } else { |
| 1333 | mDefaultBrowserApp.remove(userId); |
| 1334 | } |
Fabrice Di Meglio | 6227172 | 2015-04-10 17:24:02 -0700 | [diff] [blame] | 1335 | writePackageRestrictionsLPr(userId); |
| 1336 | return true; |
| 1337 | } |
| 1338 | |
| 1339 | String getDefaultBrowserPackageNameLPw(int userId) { |
| 1340 | return (userId == UserHandle.USER_ALL) ? null : mDefaultBrowserApp.get(userId); |
| 1341 | } |
| 1342 | |
Robin Lee | 0dc591b | 2016-05-04 13:01:46 +0100 | [diff] [blame] | 1343 | boolean setDefaultDialerPackageNameLPw(String packageName, int userId) { |
| 1344 | if (userId == UserHandle.USER_ALL) { |
| 1345 | return false; |
| 1346 | } |
| 1347 | mDefaultDialerApp.put(userId, packageName); |
| 1348 | writePackageRestrictionsLPr(userId); |
| 1349 | return true; |
| 1350 | } |
| 1351 | |
| 1352 | String getDefaultDialerPackageNameLPw(int userId) { |
| 1353 | return (userId == UserHandle.USER_ALL) ? null : mDefaultDialerApp.get(userId); |
| 1354 | } |
| 1355 | |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1356 | private File getUserPackagesStateFile(int userId) { |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 1357 | // TODO: Implement a cleaner solution when adding tests. |
| 1358 | // This instead of Environment.getUserSystemDirectory(userId) to support testing. |
| 1359 | File userDir = new File(new File(mSystemDir, "users"), Integer.toString(userId)); |
| 1360 | return new File(userDir, "package-restrictions.xml"); |
| 1361 | } |
| 1362 | |
| 1363 | private File getUserRuntimePermissionsFile(int userId) { |
| 1364 | // TODO: Implement a cleaner solution when adding tests. |
| 1365 | // This instead of Environment.getUserSystemDirectory(userId) to support testing. |
| 1366 | File userDir = new File(new File(mSystemDir, "users"), Integer.toString(userId)); |
| 1367 | return new File(userDir, RUNTIME_PERMISSIONS_FILE_NAME); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1368 | } |
| 1369 | |
| 1370 | private File getUserPackagesStateBackupFile(int userId) { |
Amith Yamasani | 61f5737 | 2012-08-31 12:12:28 -0700 | [diff] [blame] | 1371 | return new File(Environment.getUserSystemDirectory(userId), |
| 1372 | "package-restrictions-backup.xml"); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1373 | } |
| 1374 | |
| 1375 | void writeAllUsersPackageRestrictionsLPr() { |
Todd Kennedy | 13715d5 | 2016-08-01 13:38:57 -0700 | [diff] [blame] | 1376 | List<UserInfo> users = getAllUsers(UserManagerService.getInstance()); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1377 | if (users == null) return; |
| 1378 | |
| 1379 | for (UserInfo user : users) { |
| 1380 | writePackageRestrictionsLPr(user.id); |
| 1381 | } |
| 1382 | } |
| 1383 | |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 1384 | void writeAllRuntimePermissionsLPr() { |
| 1385 | for (int userId : UserManagerService.getInstance().getUserIds()) { |
| 1386 | mRuntimePermissionsPersistence.writePermissionsForUserAsyncLPr(userId); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1387 | } |
| 1388 | } |
| 1389 | |
Svet Ganov | ba3ba81 | 2015-06-26 10:54:06 -0700 | [diff] [blame] | 1390 | boolean areDefaultRuntimePermissionsGrantedLPr(int userId) { |
| 1391 | return mRuntimePermissionsPersistence |
| 1392 | .areDefaultRuntimPermissionsGrantedLPr(userId); |
| 1393 | } |
| 1394 | |
| 1395 | void onDefaultRuntimePermissionsGrantedLPr(int userId) { |
| 1396 | mRuntimePermissionsPersistence |
| 1397 | .onDefaultRuntimePermissionsGrantedLPr(userId); |
| 1398 | } |
| 1399 | |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 1400 | public VersionInfo findOrCreateVersion(String volumeUuid) { |
| 1401 | VersionInfo ver = mVersion.get(volumeUuid); |
| 1402 | if (ver == null) { |
| 1403 | ver = new VersionInfo(); |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 1404 | mVersion.put(volumeUuid, ver); |
| 1405 | } |
| 1406 | return ver; |
Kenny Root | c1c0d3c | 2014-04-24 13:36:40 -0700 | [diff] [blame] | 1407 | } |
| 1408 | |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 1409 | public VersionInfo getInternalVersion() { |
| 1410 | return mVersion.get(StorageManager.UUID_PRIVATE_INTERNAL); |
Kenny Root | c1c0d3c | 2014-04-24 13:36:40 -0700 | [diff] [blame] | 1411 | } |
| 1412 | |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 1413 | public VersionInfo getExternalVersion() { |
| 1414 | return mVersion.get(StorageManager.UUID_PRIMARY_PHYSICAL); |
Kenny Root | c1c0d3c | 2014-04-24 13:36:40 -0700 | [diff] [blame] | 1415 | } |
| 1416 | |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 1417 | public void onVolumeForgotten(String fsUuid) { |
| 1418 | mVersion.remove(fsUuid); |
Kenny Root | c1c0d3c | 2014-04-24 13:36:40 -0700 | [diff] [blame] | 1419 | } |
| 1420 | |
Christopher Tate | e012a23 | 2015-04-01 17:18:50 -0700 | [diff] [blame] | 1421 | /** |
| 1422 | * Applies the preferred activity state described by the given XML. This code |
| 1423 | * also supports the restore-from-backup code path. |
| 1424 | * |
| 1425 | * @see PreferredActivityBackupHelper |
| 1426 | */ |
| 1427 | void readPreferredActivitiesLPw(XmlPullParser parser, int userId) |
Dianne Hackborn | 6309271 | 2012-10-07 14:45:35 -0700 | [diff] [blame] | 1428 | throws XmlPullParserException, IOException { |
| 1429 | int outerDepth = parser.getDepth(); |
| 1430 | int type; |
| 1431 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 1432 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 1433 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 1434 | continue; |
| 1435 | } |
| 1436 | |
| 1437 | String tagName = parser.getName(); |
| 1438 | if (tagName.equals(TAG_ITEM)) { |
| 1439 | PreferredActivity pa = new PreferredActivity(parser); |
| 1440 | if (pa.mPref.getParseError() == null) { |
| 1441 | editPreferredActivitiesLPw(userId).addFilter(pa); |
| 1442 | } else { |
| 1443 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 1444 | "Error in package manager settings: <preferred-activity> " |
| 1445 | + pa.mPref.getParseError() + " at " |
| 1446 | + parser.getPositionDescription()); |
| 1447 | } |
| 1448 | } else { |
| 1449 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 1450 | "Unknown element under <preferred-activities>: " + parser.getName()); |
| 1451 | XmlUtils.skipCurrentTag(parser); |
| 1452 | } |
| 1453 | } |
| 1454 | } |
| 1455 | |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 1456 | private void readPersistentPreferredActivitiesLPw(XmlPullParser parser, int userId) |
| 1457 | throws XmlPullParserException, IOException { |
| 1458 | int outerDepth = parser.getDepth(); |
| 1459 | int type; |
| 1460 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 1461 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 1462 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 1463 | continue; |
| 1464 | } |
| 1465 | String tagName = parser.getName(); |
| 1466 | if (tagName.equals(TAG_ITEM)) { |
| 1467 | PersistentPreferredActivity ppa = new PersistentPreferredActivity(parser); |
| 1468 | editPersistentPreferredActivitiesLPw(userId).addFilter(ppa); |
| 1469 | } else { |
| 1470 | PackageManagerService.reportSettingsProblem(Log.WARN, |
Sander Alewijnse | af59762 | 2014-03-20 18:44:57 +0000 | [diff] [blame] | 1471 | "Unknown element under <" + TAG_PERSISTENT_PREFERRED_ACTIVITIES + ">: " |
| 1472 | + parser.getName()); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 1473 | XmlUtils.skipCurrentTag(parser); |
| 1474 | } |
| 1475 | } |
| 1476 | } |
| 1477 | |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 1478 | private void readCrossProfileIntentFiltersLPw(XmlPullParser parser, int userId) |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1479 | throws XmlPullParserException, IOException { |
| 1480 | int outerDepth = parser.getDepth(); |
| 1481 | int type; |
| 1482 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 1483 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 1484 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 1485 | continue; |
| 1486 | } |
Christopher Tate | 6038d15 | 2015-06-17 13:07:46 -0700 | [diff] [blame] | 1487 | final String tagName = parser.getName(); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1488 | if (tagName.equals(TAG_ITEM)) { |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 1489 | CrossProfileIntentFilter cpif = new CrossProfileIntentFilter(parser); |
| 1490 | editCrossProfileIntentResolverLPw(userId).addFilter(cpif); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1491 | } else { |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 1492 | String msg = "Unknown element under " + TAG_CROSS_PROFILE_INTENT_FILTERS + ": " + |
Christopher Tate | 6038d15 | 2015-06-17 13:07:46 -0700 | [diff] [blame] | 1493 | tagName; |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1494 | PackageManagerService.reportSettingsProblem(Log.WARN, msg); |
| 1495 | XmlUtils.skipCurrentTag(parser); |
| 1496 | } |
| 1497 | } |
| 1498 | } |
| 1499 | |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1500 | private void readDomainVerificationLPw(XmlPullParser parser, PackageSettingBase packageSetting) |
| 1501 | throws XmlPullParserException, IOException { |
| 1502 | IntentFilterVerificationInfo ivi = new IntentFilterVerificationInfo(parser); |
| 1503 | packageSetting.setIntentFilterVerificationInfo(ivi); |
Todd Kennedy | 788c842 | 2016-08-10 10:52:34 -0700 | [diff] [blame] | 1504 | if (DEBUG_PARSER) { |
| 1505 | Log.d(TAG, "Read domain verification for package: " + ivi.getPackageName()); |
| 1506 | } |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1507 | } |
| 1508 | |
Christopher Tate | 6038d15 | 2015-06-17 13:07:46 -0700 | [diff] [blame] | 1509 | private void readRestoredIntentFilterVerifications(XmlPullParser parser) |
| 1510 | throws XmlPullParserException, IOException { |
| 1511 | int outerDepth = parser.getDepth(); |
| 1512 | int type; |
| 1513 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 1514 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 1515 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 1516 | continue; |
| 1517 | } |
| 1518 | final String tagName = parser.getName(); |
| 1519 | if (tagName.equals(TAG_DOMAIN_VERIFICATION)) { |
| 1520 | IntentFilterVerificationInfo ivi = new IntentFilterVerificationInfo(parser); |
| 1521 | if (DEBUG_DOMAIN_VERIFICATION) { |
| 1522 | Slog.i(TAG, "Restored IVI for " + ivi.getPackageName() |
| 1523 | + " status=" + ivi.getStatusString()); |
| 1524 | } |
| 1525 | mRestoredIntentFilterVerifications.put(ivi.getPackageName(), ivi); |
| 1526 | } else { |
| 1527 | Slog.w(TAG, "Unknown element: " + tagName); |
| 1528 | XmlUtils.skipCurrentTag(parser); |
| 1529 | } |
| 1530 | } |
| 1531 | } |
| 1532 | |
| 1533 | void readDefaultAppsLPw(XmlPullParser parser, int userId) |
Fabrice Di Meglio | 6227172 | 2015-04-10 17:24:02 -0700 | [diff] [blame] | 1534 | throws XmlPullParserException, IOException { |
| 1535 | int outerDepth = parser.getDepth(); |
| 1536 | int type; |
| 1537 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 1538 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 1539 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 1540 | continue; |
| 1541 | } |
| 1542 | String tagName = parser.getName(); |
| 1543 | if (tagName.equals(TAG_DEFAULT_BROWSER)) { |
| 1544 | String packageName = parser.getAttributeValue(null, ATTR_PACKAGE_NAME); |
| 1545 | mDefaultBrowserApp.put(userId, packageName); |
Robin Lee | 0dc591b | 2016-05-04 13:01:46 +0100 | [diff] [blame] | 1546 | } else if (tagName.equals(TAG_DEFAULT_DIALER)) { |
| 1547 | String packageName = parser.getAttributeValue(null, ATTR_PACKAGE_NAME); |
| 1548 | mDefaultDialerApp.put(userId, packageName); |
Fabrice Di Meglio | 6227172 | 2015-04-10 17:24:02 -0700 | [diff] [blame] | 1549 | } else { |
| 1550 | String msg = "Unknown element under " + TAG_DEFAULT_APPS + ": " + |
| 1551 | parser.getName(); |
| 1552 | PackageManagerService.reportSettingsProblem(Log.WARN, msg); |
| 1553 | XmlUtils.skipCurrentTag(parser); |
| 1554 | } |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1555 | } |
| 1556 | } |
| 1557 | |
Vladislav Kuzkokov | 253984e | 2016-10-24 09:27:16 +0200 | [diff] [blame] | 1558 | void readBlockUninstallPackagesLPw(XmlPullParser parser, int userId) |
| 1559 | throws XmlPullParserException, IOException { |
| 1560 | int outerDepth = parser.getDepth(); |
| 1561 | int type; |
| 1562 | ArraySet<String> packages = new ArraySet<>(); |
| 1563 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 1564 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 1565 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 1566 | continue; |
| 1567 | } |
| 1568 | String tagName = parser.getName(); |
| 1569 | if (tagName.equals(TAG_BLOCK_UNINSTALL)) { |
| 1570 | String packageName = parser.getAttributeValue(null, ATTR_PACKAGE_NAME); |
| 1571 | packages.add(packageName); |
| 1572 | } else { |
| 1573 | String msg = "Unknown element under " + TAG_BLOCK_UNINSTALL_PACKAGES + ": " + |
| 1574 | parser.getName(); |
| 1575 | PackageManagerService.reportSettingsProblem(Log.WARN, msg); |
| 1576 | XmlUtils.skipCurrentTag(parser); |
| 1577 | } |
| 1578 | } |
| 1579 | if (packages.isEmpty()) { |
| 1580 | mBlockUninstallPackages.remove(userId); |
| 1581 | } else { |
| 1582 | mBlockUninstallPackages.put(userId, packages); |
| 1583 | } |
| 1584 | } |
| 1585 | |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1586 | void readPackageRestrictionsLPr(int userId) { |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1587 | if (DEBUG_MU) { |
| 1588 | Log.i(TAG, "Reading package restrictions for user=" + userId); |
| 1589 | } |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1590 | FileInputStream str = null; |
| 1591 | File userPackagesStateFile = getUserPackagesStateFile(userId); |
| 1592 | File backupFile = getUserPackagesStateBackupFile(userId); |
| 1593 | if (backupFile.exists()) { |
| 1594 | try { |
| 1595 | str = new FileInputStream(backupFile); |
| 1596 | mReadMessages.append("Reading from backup stopped packages file\n"); |
| 1597 | PackageManagerService.reportSettingsProblem(Log.INFO, |
| 1598 | "Need to read from backup stopped packages file"); |
| 1599 | if (userPackagesStateFile.exists()) { |
| 1600 | // If both the backup and normal file exist, we |
| 1601 | // ignore the normal one since it might have been |
| 1602 | // corrupted. |
| 1603 | Slog.w(PackageManagerService.TAG, "Cleaning up stopped packages file " |
| 1604 | + userPackagesStateFile); |
| 1605 | userPackagesStateFile.delete(); |
| 1606 | } |
| 1607 | } catch (java.io.IOException e) { |
| 1608 | // We'll try for the normal settings file. |
| 1609 | } |
| 1610 | } |
| 1611 | |
| 1612 | try { |
| 1613 | if (str == null) { |
| 1614 | if (!userPackagesStateFile.exists()) { |
| 1615 | mReadMessages.append("No stopped packages file found\n"); |
| 1616 | PackageManagerService.reportSettingsProblem(Log.INFO, |
| 1617 | "No stopped packages file; " |
| 1618 | + "assuming all started"); |
| 1619 | // At first boot, make sure no packages are stopped. |
| 1620 | // We usually want to have third party apps initialize |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 1621 | // in the stopped state, but not at first boot. Also |
| 1622 | // consider all applications to be installed. |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1623 | for (PackageSetting pkg : mPackages.values()) { |
Jeff Sharkey | 4288419 | 2016-04-09 16:12:01 -0600 | [diff] [blame] | 1624 | pkg.setUserState(userId, 0, COMPONENT_ENABLED_STATE_DEFAULT, |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 1625 | true /*installed*/, |
| 1626 | false /*stopped*/, |
| 1627 | false /*notLaunched*/, |
| 1628 | false /*hidden*/, |
| 1629 | false /*suspended*/, |
Suprabh Shukla | 151b21b | 2018-04-27 19:30:30 -0700 | [diff] [blame] | 1630 | null /*suspendingPackage*/, |
Suprabh Shukla | 389cb6f | 2018-10-01 18:20:39 -0700 | [diff] [blame] | 1631 | null /*dialogInfo*/, |
Suprabh Shukla | 151b21b | 2018-04-27 19:30:30 -0700 | [diff] [blame] | 1632 | null /*suspendedAppExtras*/, |
| 1633 | null /*suspendedLauncherExtras*/, |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 1634 | false /*instantApp*/, |
Todd Kennedy | 5eb5a7d | 2017-08-01 07:42:47 -0700 | [diff] [blame] | 1635 | false /*virtualPreload*/, |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 1636 | null /*lastDisableAppCaller*/, |
| 1637 | null /*enabledComponents*/, |
| 1638 | null /*disabledComponents*/, |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 1639 | INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_UNDEFINED, |
Ben Gruver | 1ab3d6e | 2017-12-07 13:45:08 -0800 | [diff] [blame] | 1640 | 0, PackageManager.INSTALL_REASON_UNKNOWN, |
| 1641 | null /*harmfulAppWarning*/); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1642 | } |
| 1643 | return; |
| 1644 | } |
| 1645 | str = new FileInputStream(userPackagesStateFile); |
| 1646 | } |
| 1647 | final XmlPullParser parser = Xml.newPullParser(); |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 1648 | parser.setInput(str, StandardCharsets.UTF_8.name()); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1649 | |
| 1650 | int type; |
| 1651 | while ((type=parser.next()) != XmlPullParser.START_TAG |
| 1652 | && type != XmlPullParser.END_DOCUMENT) { |
| 1653 | ; |
| 1654 | } |
| 1655 | |
| 1656 | if (type != XmlPullParser.START_TAG) { |
| 1657 | mReadMessages.append("No start tag found in package restrictions file\n"); |
| 1658 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 1659 | "No start tag found in package manager stopped packages"); |
| 1660 | return; |
| 1661 | } |
| 1662 | |
Christopher Tate | f0d6cb3 | 2015-07-10 17:44:53 -0700 | [diff] [blame] | 1663 | int maxAppLinkGeneration = 0; |
| 1664 | |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1665 | int outerDepth = parser.getDepth(); |
| 1666 | PackageSetting ps = null; |
| 1667 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 1668 | && (type != XmlPullParser.END_TAG |
| 1669 | || parser.getDepth() > outerDepth)) { |
| 1670 | if (type == XmlPullParser.END_TAG |
| 1671 | || type == XmlPullParser.TEXT) { |
| 1672 | continue; |
| 1673 | } |
| 1674 | |
| 1675 | String tagName = parser.getName(); |
| 1676 | if (tagName.equals(TAG_PACKAGE)) { |
| 1677 | String name = parser.getAttributeValue(null, ATTR_NAME); |
| 1678 | ps = mPackages.get(name); |
| 1679 | if (ps == null) { |
Jeff Sharkey | e06b4d1 | 2016-01-06 14:51:50 -0700 | [diff] [blame] | 1680 | Slog.w(PackageManagerService.TAG, "No package known for stopped package " |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1681 | + name); |
| 1682 | XmlUtils.skipCurrentTag(parser); |
| 1683 | continue; |
| 1684 | } |
Jeff Sharkey | 4288419 | 2016-04-09 16:12:01 -0600 | [diff] [blame] | 1685 | |
| 1686 | final long ceDataInode = XmlUtils.readLongAttribute(parser, ATTR_CE_DATA_INODE, |
| 1687 | 0); |
| 1688 | final boolean installed = XmlUtils.readBooleanAttribute(parser, ATTR_INSTALLED, |
| 1689 | true); |
| 1690 | final boolean stopped = XmlUtils.readBooleanAttribute(parser, ATTR_STOPPED, |
| 1691 | false); |
| 1692 | final boolean notLaunched = XmlUtils.readBooleanAttribute(parser, |
| 1693 | ATTR_NOT_LAUNCHED, false); |
| 1694 | |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 1695 | // For backwards compatibility with the previous name of "blocked", which |
| 1696 | // now means hidden, read the old attribute as well. |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 1697 | final String blockedStr = parser.getAttributeValue(null, ATTR_BLOCKED); |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 1698 | boolean hidden = blockedStr == null |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 1699 | ? false : Boolean.parseBoolean(blockedStr); |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 1700 | final String hiddenStr = parser.getAttributeValue(null, ATTR_HIDDEN); |
| 1701 | hidden = hiddenStr == null |
| 1702 | ? hidden : Boolean.parseBoolean(hiddenStr); |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 1703 | |
Jeff Sharkey | 4288419 | 2016-04-09 16:12:01 -0600 | [diff] [blame] | 1704 | final boolean suspended = XmlUtils.readBooleanAttribute(parser, ATTR_SUSPENDED, |
| 1705 | false); |
Suprabh Shukla | 021b57a | 2018-03-08 18:21:50 -0800 | [diff] [blame] | 1706 | String suspendingPackage = parser.getAttributeValue(null, |
| 1707 | ATTR_SUSPENDING_PACKAGE); |
Suprabh Shukla | 3c3af14 | 2018-03-30 00:28:37 -0700 | [diff] [blame] | 1708 | final String dialogMessage = parser.getAttributeValue(null, |
| 1709 | ATTR_SUSPEND_DIALOG_MESSAGE); |
Suprabh Shukla | 021b57a | 2018-03-08 18:21:50 -0800 | [diff] [blame] | 1710 | if (suspended && suspendingPackage == null) { |
| 1711 | suspendingPackage = PLATFORM_PACKAGE_NAME; |
| 1712 | } |
| 1713 | |
Jeff Sharkey | 4288419 | 2016-04-09 16:12:01 -0600 | [diff] [blame] | 1714 | final boolean blockUninstall = XmlUtils.readBooleanAttribute(parser, |
| 1715 | ATTR_BLOCK_UNINSTALL, false); |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 1716 | final boolean instantApp = XmlUtils.readBooleanAttribute(parser, |
| 1717 | ATTR_INSTANT_APP, false); |
Todd Kennedy | 5eb5a7d | 2017-08-01 07:42:47 -0700 | [diff] [blame] | 1718 | final boolean virtualPreload = XmlUtils.readBooleanAttribute(parser, |
| 1719 | ATTR_VIRTUAL_PRELOAD, false); |
Jeff Sharkey | 4288419 | 2016-04-09 16:12:01 -0600 | [diff] [blame] | 1720 | final int enabled = XmlUtils.readIntAttribute(parser, ATTR_ENABLED, |
| 1721 | COMPONENT_ENABLED_STATE_DEFAULT); |
| 1722 | final String enabledCaller = parser.getAttributeValue(null, |
| 1723 | ATTR_ENABLED_CALLER); |
Ben Gruver | 1ab3d6e | 2017-12-07 13:45:08 -0800 | [diff] [blame] | 1724 | final String harmfulAppWarning = |
| 1725 | parser.getAttributeValue(null, ATTR_HARMFUL_APP_WARNING); |
Jeff Sharkey | 4288419 | 2016-04-09 16:12:01 -0600 | [diff] [blame] | 1726 | final int verifState = XmlUtils.readIntAttribute(parser, |
| 1727 | ATTR_DOMAIN_VERIFICATON_STATE, |
| 1728 | PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_UNDEFINED); |
| 1729 | final int linkGeneration = XmlUtils.readIntAttribute(parser, |
| 1730 | ATTR_APP_LINK_GENERATION, 0); |
Christopher Tate | f0d6cb3 | 2015-07-10 17:44:53 -0700 | [diff] [blame] | 1731 | if (linkGeneration > maxAppLinkGeneration) { |
| 1732 | maxAppLinkGeneration = linkGeneration; |
| 1733 | } |
Bartosz Fabianowski | a34f53f | 2017-01-11 18:08:47 +0100 | [diff] [blame] | 1734 | final int installReason = XmlUtils.readIntAttribute(parser, |
| 1735 | ATTR_INSTALL_REASON, PackageManager.INSTALL_REASON_UNKNOWN); |
Christopher Tate | f0d6cb3 | 2015-07-10 17:44:53 -0700 | [diff] [blame] | 1736 | |
Jeff Sharkey | 9f837a9 | 2014-10-24 12:07:24 -0700 | [diff] [blame] | 1737 | ArraySet<String> enabledComponents = null; |
| 1738 | ArraySet<String> disabledComponents = null; |
Suprabh Shukla | 021b57a | 2018-03-08 18:21:50 -0800 | [diff] [blame] | 1739 | PersistableBundle suspendedAppExtras = null; |
| 1740 | PersistableBundle suspendedLauncherExtras = null; |
Suprabh Shukla | 389cb6f | 2018-10-01 18:20:39 -0700 | [diff] [blame] | 1741 | SuspendDialogInfo suspendDialogInfo = null; |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1742 | |
| 1743 | int packageDepth = parser.getDepth(); |
| 1744 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 1745 | && (type != XmlPullParser.END_TAG |
| 1746 | || parser.getDepth() > packageDepth)) { |
| 1747 | if (type == XmlPullParser.END_TAG |
| 1748 | || type == XmlPullParser.TEXT) { |
| 1749 | continue; |
| 1750 | } |
Suprabh Shukla | 021b57a | 2018-03-08 18:21:50 -0800 | [diff] [blame] | 1751 | switch (parser.getName()) { |
| 1752 | case TAG_ENABLED_COMPONENTS: |
| 1753 | enabledComponents = readComponentsLPr(parser); |
| 1754 | break; |
| 1755 | case TAG_DISABLED_COMPONENTS: |
| 1756 | disabledComponents = readComponentsLPr(parser); |
| 1757 | break; |
| 1758 | case TAG_SUSPENDED_APP_EXTRAS: |
| 1759 | suspendedAppExtras = PersistableBundle.restoreFromXml(parser); |
| 1760 | break; |
| 1761 | case TAG_SUSPENDED_LAUNCHER_EXTRAS: |
| 1762 | suspendedLauncherExtras = PersistableBundle.restoreFromXml(parser); |
| 1763 | break; |
Suprabh Shukla | 389cb6f | 2018-10-01 18:20:39 -0700 | [diff] [blame] | 1764 | case TAG_SUSPENDED_DIALOG_INFO: |
| 1765 | suspendDialogInfo = SuspendDialogInfo.restoreFromXml(parser); |
| 1766 | break; |
Suprabh Shukla | 021b57a | 2018-03-08 18:21:50 -0800 | [diff] [blame] | 1767 | default: |
| 1768 | Slog.wtf(TAG, "Unknown tag " + parser.getName() + " under tag " |
| 1769 | + TAG_PACKAGE); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1770 | } |
| 1771 | } |
Suprabh Shukla | 389cb6f | 2018-10-01 18:20:39 -0700 | [diff] [blame] | 1772 | if (suspendDialogInfo == null && !TextUtils.isEmpty(dialogMessage)) { |
| 1773 | suspendDialogInfo = new SuspendDialogInfo.Builder() |
| 1774 | .setMessage(dialogMessage) |
| 1775 | .build(); |
| 1776 | } |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 1777 | |
Vladislav Kuzkokov | 253984e | 2016-10-24 09:27:16 +0200 | [diff] [blame] | 1778 | if (blockUninstall) { |
| 1779 | setBlockUninstallLPw(userId, name, true); |
| 1780 | } |
Jeff Sharkey | 4288419 | 2016-04-09 16:12:01 -0600 | [diff] [blame] | 1781 | ps.setUserState(userId, ceDataInode, enabled, installed, stopped, notLaunched, |
Suprabh Shukla | 389cb6f | 2018-10-01 18:20:39 -0700 | [diff] [blame] | 1782 | hidden, suspended, suspendingPackage, suspendDialogInfo, |
| 1783 | suspendedAppExtras, suspendedLauncherExtras, instantApp, virtualPreload, |
| 1784 | enabledCaller, enabledComponents, disabledComponents, verifState, |
| 1785 | linkGeneration, installReason, harmfulAppWarning); |
Dianne Hackborn | 6309271 | 2012-10-07 14:45:35 -0700 | [diff] [blame] | 1786 | } else if (tagName.equals("preferred-activities")) { |
| 1787 | readPreferredActivitiesLPw(parser, userId); |
Sander Alewijnse | af59762 | 2014-03-20 18:44:57 +0000 | [diff] [blame] | 1788 | } else if (tagName.equals(TAG_PERSISTENT_PREFERRED_ACTIVITIES)) { |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 1789 | readPersistentPreferredActivitiesLPw(parser, userId); |
Nicolas Prevot | 29762c3 | 2014-07-29 18:51:32 +0100 | [diff] [blame] | 1790 | } else if (tagName.equals(TAG_CROSS_PROFILE_INTENT_FILTERS)) { |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 1791 | readCrossProfileIntentFiltersLPw(parser, userId); |
Fabrice Di Meglio | 6227172 | 2015-04-10 17:24:02 -0700 | [diff] [blame] | 1792 | } else if (tagName.equals(TAG_DEFAULT_APPS)) { |
| 1793 | readDefaultAppsLPw(parser, userId); |
Vladislav Kuzkokov | 253984e | 2016-10-24 09:27:16 +0200 | [diff] [blame] | 1794 | } else if (tagName.equals(TAG_BLOCK_UNINSTALL_PACKAGES)) { |
| 1795 | readBlockUninstallPackagesLPw(parser, userId); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1796 | } else { |
| 1797 | Slog.w(PackageManagerService.TAG, "Unknown element under <stopped-packages>: " |
| 1798 | + parser.getName()); |
| 1799 | XmlUtils.skipCurrentTag(parser); |
| 1800 | } |
| 1801 | } |
| 1802 | |
| 1803 | str.close(); |
| 1804 | |
Christopher Tate | f0d6cb3 | 2015-07-10 17:44:53 -0700 | [diff] [blame] | 1805 | mNextAppLinkGeneration.put(userId, maxAppLinkGeneration + 1); |
| 1806 | |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1807 | } catch (XmlPullParserException e) { |
| 1808 | mReadMessages.append("Error reading: " + e.toString()); |
| 1809 | PackageManagerService.reportSettingsProblem(Log.ERROR, |
| 1810 | "Error reading stopped packages: " + e); |
Dianne Hackborn | 8d05172 | 2014-10-01 14:59:58 -0700 | [diff] [blame] | 1811 | Slog.wtf(PackageManagerService.TAG, "Error reading package manager stopped packages", |
| 1812 | e); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1813 | |
| 1814 | } catch (java.io.IOException e) { |
| 1815 | mReadMessages.append("Error reading: " + e.toString()); |
| 1816 | PackageManagerService.reportSettingsProblem(Log.ERROR, "Error reading settings: " + e); |
Dianne Hackborn | 8d05172 | 2014-10-01 14:59:58 -0700 | [diff] [blame] | 1817 | Slog.wtf(PackageManagerService.TAG, "Error reading package manager stopped packages", |
| 1818 | e); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1819 | } |
| 1820 | } |
| 1821 | |
Vladislav Kuzkokov | 253984e | 2016-10-24 09:27:16 +0200 | [diff] [blame] | 1822 | void setBlockUninstallLPw(int userId, String packageName, boolean blockUninstall) { |
| 1823 | ArraySet<String> packages = mBlockUninstallPackages.get(userId); |
| 1824 | if (blockUninstall) { |
| 1825 | if (packages == null) { |
| 1826 | packages = new ArraySet<String>(); |
| 1827 | mBlockUninstallPackages.put(userId, packages); |
| 1828 | } |
| 1829 | packages.add(packageName); |
| 1830 | } else if (packages != null) { |
| 1831 | packages.remove(packageName); |
| 1832 | if (packages.isEmpty()) { |
| 1833 | mBlockUninstallPackages.remove(userId); |
| 1834 | } |
| 1835 | } |
| 1836 | } |
| 1837 | |
| 1838 | boolean getBlockUninstallLPr(int userId, String packageName) { |
| 1839 | ArraySet<String> packages = mBlockUninstallPackages.get(userId); |
| 1840 | if (packages == null) { |
| 1841 | return false; |
| 1842 | } |
| 1843 | return packages.contains(packageName); |
| 1844 | } |
| 1845 | |
Jeff Sharkey | 9f837a9 | 2014-10-24 12:07:24 -0700 | [diff] [blame] | 1846 | private ArraySet<String> readComponentsLPr(XmlPullParser parser) |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1847 | throws IOException, XmlPullParserException { |
Jeff Sharkey | 9f837a9 | 2014-10-24 12:07:24 -0700 | [diff] [blame] | 1848 | ArraySet<String> components = null; |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1849 | int type; |
| 1850 | int outerDepth = parser.getDepth(); |
| 1851 | String tagName; |
| 1852 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 1853 | && (type != XmlPullParser.END_TAG |
| 1854 | || parser.getDepth() > outerDepth)) { |
| 1855 | if (type == XmlPullParser.END_TAG |
| 1856 | || type == XmlPullParser.TEXT) { |
| 1857 | continue; |
| 1858 | } |
| 1859 | tagName = parser.getName(); |
| 1860 | if (tagName.equals(TAG_ITEM)) { |
| 1861 | String componentName = parser.getAttributeValue(null, ATTR_NAME); |
| 1862 | if (componentName != null) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 1863 | if (components == null) { |
Jeff Sharkey | 9f837a9 | 2014-10-24 12:07:24 -0700 | [diff] [blame] | 1864 | components = new ArraySet<String>(); |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 1865 | } |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1866 | components.add(componentName); |
| 1867 | } |
| 1868 | } |
| 1869 | } |
| 1870 | return components; |
| 1871 | } |
| 1872 | |
Christopher Tate | e012a23 | 2015-04-01 17:18:50 -0700 | [diff] [blame] | 1873 | /** |
| 1874 | * Record the state of preferred activity configuration into XML. This is used both |
| 1875 | * for recording packages.xml internally and for supporting backup/restore of the |
| 1876 | * preferred activity configuration. |
| 1877 | */ |
Dianne Hackborn | 8a2ed1d | 2013-01-29 15:18:29 -0800 | [diff] [blame] | 1878 | void writePreferredActivitiesLPr(XmlSerializer serializer, int userId, boolean full) |
Dianne Hackborn | 6309271 | 2012-10-07 14:45:35 -0700 | [diff] [blame] | 1879 | throws IllegalArgumentException, IllegalStateException, IOException { |
| 1880 | serializer.startTag(null, "preferred-activities"); |
| 1881 | PreferredIntentResolver pir = mPreferredActivities.get(userId); |
| 1882 | if (pir != null) { |
| 1883 | for (final PreferredActivity pa : pir.filterSet()) { |
| 1884 | serializer.startTag(null, TAG_ITEM); |
Dianne Hackborn | 8a2ed1d | 2013-01-29 15:18:29 -0800 | [diff] [blame] | 1885 | pa.writeToXml(serializer, full); |
Dianne Hackborn | 6309271 | 2012-10-07 14:45:35 -0700 | [diff] [blame] | 1886 | serializer.endTag(null, TAG_ITEM); |
| 1887 | } |
| 1888 | } |
| 1889 | serializer.endTag(null, "preferred-activities"); |
| 1890 | } |
| 1891 | |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 1892 | void writePersistentPreferredActivitiesLPr(XmlSerializer serializer, int userId) |
| 1893 | throws IllegalArgumentException, IllegalStateException, IOException { |
Sander Alewijnse | af59762 | 2014-03-20 18:44:57 +0000 | [diff] [blame] | 1894 | serializer.startTag(null, TAG_PERSISTENT_PREFERRED_ACTIVITIES); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 1895 | PersistentPreferredIntentResolver ppir = mPersistentPreferredActivities.get(userId); |
| 1896 | if (ppir != null) { |
| 1897 | for (final PersistentPreferredActivity ppa : ppir.filterSet()) { |
| 1898 | serializer.startTag(null, TAG_ITEM); |
| 1899 | ppa.writeToXml(serializer); |
| 1900 | serializer.endTag(null, TAG_ITEM); |
| 1901 | } |
| 1902 | } |
Sander Alewijnse | af59762 | 2014-03-20 18:44:57 +0000 | [diff] [blame] | 1903 | serializer.endTag(null, TAG_PERSISTENT_PREFERRED_ACTIVITIES); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 1904 | } |
| 1905 | |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 1906 | void writeCrossProfileIntentFiltersLPr(XmlSerializer serializer, int userId) |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1907 | throws IllegalArgumentException, IllegalStateException, IOException { |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 1908 | serializer.startTag(null, TAG_CROSS_PROFILE_INTENT_FILTERS); |
| 1909 | CrossProfileIntentResolver cpir = mCrossProfileIntentResolvers.get(userId); |
| 1910 | if (cpir != null) { |
| 1911 | for (final CrossProfileIntentFilter cpif : cpir.filterSet()) { |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1912 | serializer.startTag(null, TAG_ITEM); |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 1913 | cpif.writeToXml(serializer); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1914 | serializer.endTag(null, TAG_ITEM); |
| 1915 | } |
| 1916 | } |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 1917 | serializer.endTag(null, TAG_CROSS_PROFILE_INTENT_FILTERS); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 1918 | } |
| 1919 | |
Fabrice Di Meglio | 6227172 | 2015-04-10 17:24:02 -0700 | [diff] [blame] | 1920 | void writeDomainVerificationsLPr(XmlSerializer serializer, |
| 1921 | IntentFilterVerificationInfo verificationInfo) |
| 1922 | throws IllegalArgumentException, IllegalStateException, IOException { |
| 1923 | if (verificationInfo != null && verificationInfo.getPackageName() != null) { |
| 1924 | serializer.startTag(null, TAG_DOMAIN_VERIFICATION); |
| 1925 | verificationInfo.writeToXml(serializer); |
Christopher Tate | 72c10a2 | 2015-06-12 18:31:24 -0700 | [diff] [blame] | 1926 | if (DEBUG_DOMAIN_VERIFICATION) { |
| 1927 | Slog.d(TAG, "Wrote domain verification for package: " |
| 1928 | + verificationInfo.getPackageName()); |
| 1929 | } |
Fabrice Di Meglio | 6227172 | 2015-04-10 17:24:02 -0700 | [diff] [blame] | 1930 | serializer.endTag(null, TAG_DOMAIN_VERIFICATION); |
| 1931 | } |
| 1932 | } |
| 1933 | |
Christopher Tate | 6038d15 | 2015-06-17 13:07:46 -0700 | [diff] [blame] | 1934 | // Specifically for backup/restore |
| 1935 | void writeAllDomainVerificationsLPr(XmlSerializer serializer, int userId) |
| 1936 | throws IllegalArgumentException, IllegalStateException, IOException { |
| 1937 | serializer.startTag(null, TAG_ALL_INTENT_FILTER_VERIFICATION); |
| 1938 | final int N = mPackages.size(); |
| 1939 | for (int i = 0; i < N; i++) { |
| 1940 | PackageSetting ps = mPackages.valueAt(i); |
| 1941 | IntentFilterVerificationInfo ivi = ps.getIntentFilterVerificationInfo(); |
| 1942 | if (ivi != null) { |
| 1943 | writeDomainVerificationsLPr(serializer, ivi); |
| 1944 | } |
| 1945 | } |
| 1946 | serializer.endTag(null, TAG_ALL_INTENT_FILTER_VERIFICATION); |
| 1947 | } |
| 1948 | |
| 1949 | // Specifically for backup/restore |
| 1950 | void readAllDomainVerificationsLPr(XmlPullParser parser, int userId) |
| 1951 | throws XmlPullParserException, IOException { |
| 1952 | mRestoredIntentFilterVerifications.clear(); |
| 1953 | |
| 1954 | int outerDepth = parser.getDepth(); |
| 1955 | int type; |
| 1956 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 1957 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 1958 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 1959 | continue; |
| 1960 | } |
| 1961 | |
| 1962 | String tagName = parser.getName(); |
| 1963 | if (tagName.equals(TAG_DOMAIN_VERIFICATION)) { |
| 1964 | IntentFilterVerificationInfo ivi = new IntentFilterVerificationInfo(parser); |
| 1965 | final String pkgName = ivi.getPackageName(); |
| 1966 | final PackageSetting ps = mPackages.get(pkgName); |
| 1967 | if (ps != null) { |
| 1968 | // known/existing package; update in place |
| 1969 | ps.setIntentFilterVerificationInfo(ivi); |
| 1970 | if (DEBUG_DOMAIN_VERIFICATION) { |
| 1971 | Slog.d(TAG, "Restored IVI for existing app " + pkgName |
| 1972 | + " status=" + ivi.getStatusString()); |
| 1973 | } |
| 1974 | } else { |
| 1975 | mRestoredIntentFilterVerifications.put(pkgName, ivi); |
| 1976 | if (DEBUG_DOMAIN_VERIFICATION) { |
| 1977 | Slog.d(TAG, "Restored IVI for pending app " + pkgName |
| 1978 | + " status=" + ivi.getStatusString()); |
| 1979 | } |
| 1980 | } |
| 1981 | } else { |
| 1982 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 1983 | "Unknown element under <all-intent-filter-verification>: " |
| 1984 | + parser.getName()); |
| 1985 | XmlUtils.skipCurrentTag(parser); |
| 1986 | } |
| 1987 | } |
| 1988 | } |
| 1989 | |
Christopher Tate | e9fd1fa | 2015-09-15 16:43:07 -0700 | [diff] [blame] | 1990 | // Specifically for backup/restore |
| 1991 | public void processRestoredPermissionGrantLPr(String pkgName, String permission, |
Todd Kennedy | 91a39d1 | 2017-09-27 12:37:04 -0700 | [diff] [blame] | 1992 | boolean isGranted, int restoredFlagSet, int userId) { |
Christopher Tate | e9fd1fa | 2015-09-15 16:43:07 -0700 | [diff] [blame] | 1993 | mRuntimePermissionsPersistence.rememberRestoredUserGrantLPr( |
| 1994 | pkgName, permission, isGranted, restoredFlagSet, userId); |
| 1995 | } |
| 1996 | |
Fabrice Di Meglio | 6227172 | 2015-04-10 17:24:02 -0700 | [diff] [blame] | 1997 | void writeDefaultAppsLPr(XmlSerializer serializer, int userId) |
| 1998 | throws IllegalArgumentException, IllegalStateException, IOException { |
| 1999 | serializer.startTag(null, TAG_DEFAULT_APPS); |
Robin Lee | 0dc591b | 2016-05-04 13:01:46 +0100 | [diff] [blame] | 2000 | String defaultBrowser = mDefaultBrowserApp.get(userId); |
| 2001 | if (!TextUtils.isEmpty(defaultBrowser)) { |
Fabrice Di Meglio | 6227172 | 2015-04-10 17:24:02 -0700 | [diff] [blame] | 2002 | serializer.startTag(null, TAG_DEFAULT_BROWSER); |
Robin Lee | 0dc591b | 2016-05-04 13:01:46 +0100 | [diff] [blame] | 2003 | serializer.attribute(null, ATTR_PACKAGE_NAME, defaultBrowser); |
Fabrice Di Meglio | 6227172 | 2015-04-10 17:24:02 -0700 | [diff] [blame] | 2004 | serializer.endTag(null, TAG_DEFAULT_BROWSER); |
| 2005 | } |
Robin Lee | 0dc591b | 2016-05-04 13:01:46 +0100 | [diff] [blame] | 2006 | String defaultDialer = mDefaultDialerApp.get(userId); |
| 2007 | if (!TextUtils.isEmpty(defaultDialer)) { |
| 2008 | serializer.startTag(null, TAG_DEFAULT_DIALER); |
| 2009 | serializer.attribute(null, ATTR_PACKAGE_NAME, defaultDialer); |
| 2010 | serializer.endTag(null, TAG_DEFAULT_DIALER); |
| 2011 | } |
Fabrice Di Meglio | 6227172 | 2015-04-10 17:24:02 -0700 | [diff] [blame] | 2012 | serializer.endTag(null, TAG_DEFAULT_APPS); |
| 2013 | } |
| 2014 | |
Vladislav Kuzkokov | 253984e | 2016-10-24 09:27:16 +0200 | [diff] [blame] | 2015 | void writeBlockUninstallPackagesLPr(XmlSerializer serializer, int userId) |
| 2016 | throws IOException { |
| 2017 | ArraySet<String> packages = mBlockUninstallPackages.get(userId); |
| 2018 | if (packages != null) { |
| 2019 | serializer.startTag(null, TAG_BLOCK_UNINSTALL_PACKAGES); |
| 2020 | for (int i = 0; i < packages.size(); i++) { |
| 2021 | serializer.startTag(null, TAG_BLOCK_UNINSTALL); |
| 2022 | serializer.attribute(null, ATTR_PACKAGE_NAME, packages.valueAt(i)); |
| 2023 | serializer.endTag(null, TAG_BLOCK_UNINSTALL); |
| 2024 | } |
| 2025 | serializer.endTag(null, TAG_BLOCK_UNINSTALL_PACKAGES); |
| 2026 | } |
| 2027 | } |
| 2028 | |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2029 | void writePackageRestrictionsLPr(int userId) { |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 2030 | if (DEBUG_MU) { |
| 2031 | Log.i(TAG, "Writing package restrictions for user=" + userId); |
| 2032 | } |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 2033 | final long startTime = SystemClock.uptimeMillis(); |
| 2034 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2035 | // Keep the old stopped packages around until we know the new ones have |
| 2036 | // been successfully written. |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2037 | File userPackagesStateFile = getUserPackagesStateFile(userId); |
| 2038 | File backupFile = getUserPackagesStateBackupFile(userId); |
| 2039 | new File(userPackagesStateFile.getParent()).mkdirs(); |
| 2040 | if (userPackagesStateFile.exists()) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2041 | // Presence of backup settings file indicates that we failed |
| 2042 | // to persist packages earlier. So preserve the older |
| 2043 | // backup for future reference since the current packages |
| 2044 | // might have been corrupted. |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2045 | if (!backupFile.exists()) { |
| 2046 | if (!userPackagesStateFile.renameTo(backupFile)) { |
Dianne Hackborn | 8d05172 | 2014-10-01 14:59:58 -0700 | [diff] [blame] | 2047 | Slog.wtf(PackageManagerService.TAG, |
| 2048 | "Unable to backup user packages state file, " |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2049 | + "current changes will be lost at reboot"); |
| 2050 | return; |
| 2051 | } |
| 2052 | } else { |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2053 | userPackagesStateFile.delete(); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2054 | Slog.w(PackageManagerService.TAG, "Preserving older stopped packages backup"); |
| 2055 | } |
| 2056 | } |
| 2057 | |
| 2058 | try { |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2059 | final FileOutputStream fstr = new FileOutputStream(userPackagesStateFile); |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 2060 | final BufferedOutputStream str = new BufferedOutputStream(fstr); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2061 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 2062 | final XmlSerializer serializer = new FastXmlSerializer(); |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 2063 | serializer.setOutput(str, StandardCharsets.UTF_8.name()); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2064 | serializer.startDocument(null, true); |
| 2065 | serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true); |
| 2066 | |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2067 | serializer.startTag(null, TAG_PACKAGE_RESTRICTIONS); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2068 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 2069 | for (final PackageSetting pkg : mPackages.values()) { |
Jeff Sharkey | 4288419 | 2016-04-09 16:12:01 -0600 | [diff] [blame] | 2070 | final PackageUserState ustate = pkg.readUserState(userId); |
| 2071 | if (DEBUG_MU) Log.i(TAG, " pkg=" + pkg.name + ", state=" + ustate.enabled); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2072 | |
Jeff Sharkey | 4288419 | 2016-04-09 16:12:01 -0600 | [diff] [blame] | 2073 | serializer.startTag(null, TAG_PACKAGE); |
| 2074 | serializer.attribute(null, ATTR_NAME, pkg.name); |
| 2075 | if (ustate.ceDataInode != 0) { |
| 2076 | XmlUtils.writeLongAttribute(serializer, ATTR_CE_DATA_INODE, ustate.ceDataInode); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2077 | } |
Jeff Sharkey | 4288419 | 2016-04-09 16:12:01 -0600 | [diff] [blame] | 2078 | if (!ustate.installed) { |
| 2079 | serializer.attribute(null, ATTR_INSTALLED, "false"); |
| 2080 | } |
| 2081 | if (ustate.stopped) { |
| 2082 | serializer.attribute(null, ATTR_STOPPED, "true"); |
| 2083 | } |
| 2084 | if (ustate.notLaunched) { |
| 2085 | serializer.attribute(null, ATTR_NOT_LAUNCHED, "true"); |
| 2086 | } |
| 2087 | if (ustate.hidden) { |
| 2088 | serializer.attribute(null, ATTR_HIDDEN, "true"); |
| 2089 | } |
| 2090 | if (ustate.suspended) { |
| 2091 | serializer.attribute(null, ATTR_SUSPENDED, "true"); |
Suprabh Shukla | 3c3af14 | 2018-03-30 00:28:37 -0700 | [diff] [blame] | 2092 | if (ustate.suspendingPackage != null) { |
| 2093 | serializer.attribute(null, ATTR_SUSPENDING_PACKAGE, |
| 2094 | ustate.suspendingPackage); |
| 2095 | } |
Suprabh Shukla | 389cb6f | 2018-10-01 18:20:39 -0700 | [diff] [blame] | 2096 | if (ustate.dialogInfo != null) { |
| 2097 | serializer.startTag(null, TAG_SUSPENDED_DIALOG_INFO); |
| 2098 | ustate.dialogInfo.saveToXml(serializer); |
| 2099 | serializer.endTag(null, TAG_SUSPENDED_DIALOG_INFO); |
Suprabh Shukla | 3c3af14 | 2018-03-30 00:28:37 -0700 | [diff] [blame] | 2100 | } |
Suprabh Shukla | 021b57a | 2018-03-08 18:21:50 -0800 | [diff] [blame] | 2101 | if (ustate.suspendedAppExtras != null) { |
| 2102 | serializer.startTag(null, TAG_SUSPENDED_APP_EXTRAS); |
| 2103 | try { |
| 2104 | ustate.suspendedAppExtras.saveToXml(serializer); |
| 2105 | } catch (XmlPullParserException xmle) { |
| 2106 | Slog.wtf(TAG, "Exception while trying to write suspendedAppExtras for " |
| 2107 | + pkg + ". Will be lost on reboot", xmle); |
| 2108 | } |
| 2109 | serializer.endTag(null, TAG_SUSPENDED_APP_EXTRAS); |
| 2110 | } |
| 2111 | if (ustate.suspendedLauncherExtras != null) { |
| 2112 | serializer.startTag(null, TAG_SUSPENDED_LAUNCHER_EXTRAS); |
| 2113 | try { |
| 2114 | ustate.suspendedLauncherExtras.saveToXml(serializer); |
| 2115 | } catch (XmlPullParserException xmle) { |
| 2116 | Slog.wtf(TAG, "Exception while trying to write suspendedLauncherExtras" |
| 2117 | + " for " + pkg + ". Will be lost on reboot", xmle); |
| 2118 | } |
| 2119 | serializer.endTag(null, TAG_SUSPENDED_LAUNCHER_EXTRAS); |
| 2120 | } |
Jeff Sharkey | 4288419 | 2016-04-09 16:12:01 -0600 | [diff] [blame] | 2121 | } |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 2122 | if (ustate.instantApp) { |
| 2123 | serializer.attribute(null, ATTR_INSTANT_APP, "true"); |
| 2124 | } |
Todd Kennedy | 5eb5a7d | 2017-08-01 07:42:47 -0700 | [diff] [blame] | 2125 | if (ustate.virtualPreload) { |
| 2126 | serializer.attribute(null, ATTR_VIRTUAL_PRELOAD, "true"); |
| 2127 | } |
Jeff Sharkey | 4288419 | 2016-04-09 16:12:01 -0600 | [diff] [blame] | 2128 | if (ustate.enabled != COMPONENT_ENABLED_STATE_DEFAULT) { |
| 2129 | serializer.attribute(null, ATTR_ENABLED, |
| 2130 | Integer.toString(ustate.enabled)); |
| 2131 | if (ustate.lastDisableAppCaller != null) { |
| 2132 | serializer.attribute(null, ATTR_ENABLED_CALLER, |
| 2133 | ustate.lastDisableAppCaller); |
| 2134 | } |
| 2135 | } |
| 2136 | if (ustate.domainVerificationStatus != |
| 2137 | PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_UNDEFINED) { |
| 2138 | XmlUtils.writeIntAttribute(serializer, ATTR_DOMAIN_VERIFICATON_STATE, |
| 2139 | ustate.domainVerificationStatus); |
| 2140 | } |
| 2141 | if (ustate.appLinkGeneration != 0) { |
| 2142 | XmlUtils.writeIntAttribute(serializer, ATTR_APP_LINK_GENERATION, |
| 2143 | ustate.appLinkGeneration); |
| 2144 | } |
Bartosz Fabianowski | a34f53f | 2017-01-11 18:08:47 +0100 | [diff] [blame] | 2145 | if (ustate.installReason != PackageManager.INSTALL_REASON_UNKNOWN) { |
| 2146 | serializer.attribute(null, ATTR_INSTALL_REASON, |
| 2147 | Integer.toString(ustate.installReason)); |
| 2148 | } |
Ben Gruver | 1ab3d6e | 2017-12-07 13:45:08 -0800 | [diff] [blame] | 2149 | if (ustate.harmfulAppWarning != null) { |
| 2150 | serializer.attribute(null, ATTR_HARMFUL_APP_WARNING, |
| 2151 | ustate.harmfulAppWarning); |
| 2152 | } |
Jeff Sharkey | 4288419 | 2016-04-09 16:12:01 -0600 | [diff] [blame] | 2153 | if (!ArrayUtils.isEmpty(ustate.enabledComponents)) { |
| 2154 | serializer.startTag(null, TAG_ENABLED_COMPONENTS); |
| 2155 | for (final String name : ustate.enabledComponents) { |
| 2156 | serializer.startTag(null, TAG_ITEM); |
| 2157 | serializer.attribute(null, ATTR_NAME, name); |
| 2158 | serializer.endTag(null, TAG_ITEM); |
| 2159 | } |
| 2160 | serializer.endTag(null, TAG_ENABLED_COMPONENTS); |
| 2161 | } |
| 2162 | if (!ArrayUtils.isEmpty(ustate.disabledComponents)) { |
| 2163 | serializer.startTag(null, TAG_DISABLED_COMPONENTS); |
| 2164 | for (final String name : ustate.disabledComponents) { |
| 2165 | serializer.startTag(null, TAG_ITEM); |
| 2166 | serializer.attribute(null, ATTR_NAME, name); |
| 2167 | serializer.endTag(null, TAG_ITEM); |
| 2168 | } |
| 2169 | serializer.endTag(null, TAG_DISABLED_COMPONENTS); |
| 2170 | } |
| 2171 | |
| 2172 | serializer.endTag(null, TAG_PACKAGE); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2173 | } |
| 2174 | |
Dianne Hackborn | 8a2ed1d | 2013-01-29 15:18:29 -0800 | [diff] [blame] | 2175 | writePreferredActivitiesLPr(serializer, userId, true); |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 2176 | writePersistentPreferredActivitiesLPr(serializer, userId); |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 2177 | writeCrossProfileIntentFiltersLPr(serializer, userId); |
Fabrice Di Meglio | 6227172 | 2015-04-10 17:24:02 -0700 | [diff] [blame] | 2178 | writeDefaultAppsLPr(serializer, userId); |
Vladislav Kuzkokov | 253984e | 2016-10-24 09:27:16 +0200 | [diff] [blame] | 2179 | writeBlockUninstallPackagesLPr(serializer, userId); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 2180 | |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2181 | serializer.endTag(null, TAG_PACKAGE_RESTRICTIONS); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2182 | |
| 2183 | serializer.endDocument(); |
| 2184 | |
| 2185 | str.flush(); |
| 2186 | FileUtils.sync(fstr); |
| 2187 | str.close(); |
| 2188 | |
| 2189 | // New settings successfully written, old ones are no longer |
| 2190 | // needed. |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2191 | backupFile.delete(); |
| 2192 | FileUtils.setPermissions(userPackagesStateFile.toString(), |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2193 | FileUtils.S_IRUSR|FileUtils.S_IWUSR |
Nick Kralevich | 70522ad | 2012-01-06 13:58:01 -0800 | [diff] [blame] | 2194 | |FileUtils.S_IRGRP|FileUtils.S_IWGRP, |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2195 | -1, -1); |
| 2196 | |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 2197 | com.android.internal.logging.EventLogTags.writeCommitSysConfigFile( |
| 2198 | "package-user-" + userId, SystemClock.uptimeMillis() - startTime); |
| 2199 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2200 | // Done, all is good! |
| 2201 | return; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2202 | } catch(java.io.IOException e) { |
Dianne Hackborn | 8d05172 | 2014-10-01 14:59:58 -0700 | [diff] [blame] | 2203 | Slog.wtf(PackageManagerService.TAG, |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2204 | "Unable to write package manager user packages state, " |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2205 | + " current changes will be lost at reboot", e); |
| 2206 | } |
| 2207 | |
| 2208 | // Clean up partially written files |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2209 | if (userPackagesStateFile.exists()) { |
| 2210 | if (!userPackagesStateFile.delete()) { |
| 2211 | Log.i(PackageManagerService.TAG, "Failed to clean up mangled file: " |
| 2212 | + mStoppedPackagesFilename); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2213 | } |
| 2214 | } |
| 2215 | } |
| 2216 | |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 2217 | void readInstallPermissionsLPr(XmlPullParser parser, |
| 2218 | PermissionsState permissionsState) throws IOException, XmlPullParserException { |
| 2219 | int outerDepth = parser.getDepth(); |
| 2220 | int type; |
| 2221 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 2222 | && (type != XmlPullParser.END_TAG |
| 2223 | || parser.getDepth() > outerDepth)) { |
| 2224 | if (type == XmlPullParser.END_TAG |
| 2225 | || type == XmlPullParser.TEXT) { |
| 2226 | continue; |
| 2227 | } |
| 2228 | String tagName = parser.getName(); |
| 2229 | if (tagName.equals(TAG_ITEM)) { |
| 2230 | String name = parser.getAttributeValue(null, ATTR_NAME); |
| 2231 | |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 2232 | BasePermission bp = mPermissions.getPermission(name); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 2233 | if (bp == null) { |
| 2234 | Slog.w(PackageManagerService.TAG, "Unknown permission: " + name); |
| 2235 | XmlUtils.skipCurrentTag(parser); |
| 2236 | continue; |
| 2237 | } |
| 2238 | |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 2239 | String grantedStr = parser.getAttributeValue(null, ATTR_GRANTED); |
| 2240 | final boolean granted = grantedStr == null |
| 2241 | || Boolean.parseBoolean(grantedStr); |
| 2242 | |
| 2243 | String flagsStr = parser.getAttributeValue(null, ATTR_FLAGS); |
| 2244 | final int flags = (flagsStr != null) |
| 2245 | ? Integer.parseInt(flagsStr, 16) : 0; |
| 2246 | |
| 2247 | if (granted) { |
| 2248 | if (permissionsState.grantInstallPermission(bp) == |
| 2249 | PermissionsState.PERMISSION_OPERATION_FAILURE) { |
| 2250 | Slog.w(PackageManagerService.TAG, "Permission already added: " + name); |
| 2251 | XmlUtils.skipCurrentTag(parser); |
| 2252 | } else { |
| 2253 | permissionsState.updatePermissionFlags(bp, UserHandle.USER_ALL, |
| 2254 | PackageManager.MASK_PERMISSION_FLAGS, flags); |
| 2255 | } |
| 2256 | } else { |
| 2257 | if (permissionsState.revokeInstallPermission(bp) == |
| 2258 | PermissionsState.PERMISSION_OPERATION_FAILURE) { |
| 2259 | Slog.w(PackageManagerService.TAG, "Permission already added: " + name); |
| 2260 | XmlUtils.skipCurrentTag(parser); |
| 2261 | } else { |
| 2262 | permissionsState.updatePermissionFlags(bp, UserHandle.USER_ALL, |
| 2263 | PackageManager.MASK_PERMISSION_FLAGS, flags); |
| 2264 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 2265 | } |
| 2266 | } else { |
| 2267 | Slog.w(PackageManagerService.TAG, "Unknown element under <permissions>: " |
| 2268 | + parser.getName()); |
| 2269 | XmlUtils.skipCurrentTag(parser); |
| 2270 | } |
| 2271 | } |
| 2272 | } |
| 2273 | |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 2274 | void writePermissionsLPr(XmlSerializer serializer, List<PermissionState> permissionStates) |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 2275 | throws IOException { |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 2276 | if (permissionStates.isEmpty()) { |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 2277 | return; |
| 2278 | } |
| 2279 | |
| 2280 | serializer.startTag(null, TAG_PERMISSIONS); |
| 2281 | |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 2282 | for (PermissionState permissionState : permissionStates) { |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 2283 | serializer.startTag(null, TAG_ITEM); |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 2284 | serializer.attribute(null, ATTR_NAME, permissionState.getName()); |
| 2285 | serializer.attribute(null, ATTR_GRANTED, String.valueOf(permissionState.isGranted())); |
| 2286 | serializer.attribute(null, ATTR_FLAGS, Integer.toHexString(permissionState.getFlags())); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 2287 | serializer.endTag(null, TAG_ITEM); |
| 2288 | } |
| 2289 | |
| 2290 | serializer.endTag(null, TAG_PERMISSIONS); |
| 2291 | } |
| 2292 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2293 | void writeChildPackagesLPw(XmlSerializer serializer, List<String> childPackageNames) |
| 2294 | throws IOException { |
| 2295 | if (childPackageNames == null) { |
| 2296 | return; |
| 2297 | } |
| 2298 | final int childCount = childPackageNames.size(); |
| 2299 | for (int i = 0; i < childCount; i++) { |
| 2300 | String childPackageName = childPackageNames.get(i); |
| 2301 | serializer.startTag(null, TAG_CHILD_PACKAGE); |
| 2302 | serializer.attribute(null, ATTR_NAME, childPackageName); |
| 2303 | serializer.endTag(null, TAG_CHILD_PACKAGE); |
| 2304 | } |
| 2305 | } |
| 2306 | |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 2307 | void readUsesStaticLibLPw(XmlPullParser parser, PackageSetting outPs) |
| 2308 | throws IOException, XmlPullParserException { |
| 2309 | int outerDepth = parser.getDepth(); |
| 2310 | int type; |
| 2311 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 2312 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 2313 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 2314 | continue; |
| 2315 | } |
| 2316 | String libName = parser.getAttributeValue(null, ATTR_NAME); |
| 2317 | String libVersionStr = parser.getAttributeValue(null, ATTR_VERSION); |
| 2318 | |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 2319 | long libVersion = -1; |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 2320 | try { |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 2321 | libVersion = Long.parseLong(libVersionStr); |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 2322 | } catch (NumberFormatException e) { |
| 2323 | // ignore |
| 2324 | } |
| 2325 | |
| 2326 | if (libName != null && libVersion >= 0) { |
| 2327 | outPs.usesStaticLibraries = ArrayUtils.appendElement(String.class, |
| 2328 | outPs.usesStaticLibraries, libName); |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 2329 | outPs.usesStaticLibrariesVersions = ArrayUtils.appendLong( |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 2330 | outPs.usesStaticLibrariesVersions, libVersion); |
| 2331 | } |
| 2332 | |
| 2333 | XmlUtils.skipCurrentTag(parser); |
| 2334 | } |
| 2335 | } |
| 2336 | |
| 2337 | void writeUsesStaticLibLPw(XmlSerializer serializer, String[] usesStaticLibraries, |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 2338 | long[] usesStaticLibraryVersions) throws IOException { |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 2339 | if (ArrayUtils.isEmpty(usesStaticLibraries) || ArrayUtils.isEmpty(usesStaticLibraryVersions) |
| 2340 | || usesStaticLibraries.length != usesStaticLibraryVersions.length) { |
| 2341 | return; |
| 2342 | } |
| 2343 | final int libCount = usesStaticLibraries.length; |
| 2344 | for (int i = 0; i < libCount; i++) { |
| 2345 | final String libName = usesStaticLibraries[i]; |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 2346 | final long libVersion = usesStaticLibraryVersions[i]; |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 2347 | serializer.startTag(null, TAG_USES_STATIC_LIB); |
| 2348 | serializer.attribute(null, ATTR_NAME, libName); |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 2349 | serializer.attribute(null, ATTR_VERSION, Long.toString(libVersion)); |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 2350 | serializer.endTag(null, TAG_USES_STATIC_LIB); |
| 2351 | } |
| 2352 | } |
| 2353 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2354 | // Note: assumed "stopped" field is already cleared in all packages. |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2355 | // 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] | 2356 | void readStoppedLPw() { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2357 | FileInputStream str = null; |
| 2358 | if (mBackupStoppedPackagesFilename.exists()) { |
| 2359 | try { |
| 2360 | str = new FileInputStream(mBackupStoppedPackagesFilename); |
| 2361 | mReadMessages.append("Reading from backup stopped packages file\n"); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2362 | PackageManagerService.reportSettingsProblem(Log.INFO, |
| 2363 | "Need to read from backup stopped packages file"); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2364 | if (mSettingsFilename.exists()) { |
| 2365 | // If both the backup and normal file exist, we |
| 2366 | // ignore the normal one since it might have been |
| 2367 | // corrupted. |
| 2368 | Slog.w(PackageManagerService.TAG, "Cleaning up stopped packages file " |
| 2369 | + mStoppedPackagesFilename); |
| 2370 | mStoppedPackagesFilename.delete(); |
| 2371 | } |
| 2372 | } catch (java.io.IOException e) { |
| 2373 | // We'll try for the normal settings file. |
| 2374 | } |
| 2375 | } |
| 2376 | |
| 2377 | try { |
| 2378 | if (str == null) { |
| 2379 | if (!mStoppedPackagesFilename.exists()) { |
| 2380 | mReadMessages.append("No stopped packages file found\n"); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2381 | PackageManagerService.reportSettingsProblem(Log.INFO, |
| 2382 | "No stopped packages file file; assuming all started"); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2383 | // At first boot, make sure no packages are stopped. |
| 2384 | // We usually want to have third party apps initialize |
| 2385 | // in the stopped state, but not at first boot. |
| 2386 | for (PackageSetting pkg : mPackages.values()) { |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2387 | pkg.setStopped(false, 0); |
| 2388 | pkg.setNotLaunched(false, 0); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2389 | } |
| 2390 | return; |
| 2391 | } |
| 2392 | str = new FileInputStream(mStoppedPackagesFilename); |
| 2393 | } |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 2394 | final XmlPullParser parser = Xml.newPullParser(); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2395 | parser.setInput(str, null); |
| 2396 | |
| 2397 | int type; |
| 2398 | while ((type=parser.next()) != XmlPullParser.START_TAG |
| 2399 | && type != XmlPullParser.END_DOCUMENT) { |
| 2400 | ; |
| 2401 | } |
| 2402 | |
| 2403 | if (type != XmlPullParser.START_TAG) { |
| 2404 | mReadMessages.append("No start tag found in stopped packages file\n"); |
| 2405 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 2406 | "No start tag found in package manager stopped packages"); |
| 2407 | return; |
| 2408 | } |
| 2409 | |
| 2410 | int outerDepth = parser.getDepth(); |
| 2411 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 2412 | && (type != XmlPullParser.END_TAG |
| 2413 | || parser.getDepth() > outerDepth)) { |
| 2414 | if (type == XmlPullParser.END_TAG |
| 2415 | || type == XmlPullParser.TEXT) { |
| 2416 | continue; |
| 2417 | } |
| 2418 | |
| 2419 | String tagName = parser.getName(); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2420 | if (tagName.equals(TAG_PACKAGE)) { |
| 2421 | String name = parser.getAttributeValue(null, ATTR_NAME); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2422 | PackageSetting ps = mPackages.get(name); |
| 2423 | if (ps != null) { |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2424 | ps.setStopped(true, 0); |
| 2425 | if ("1".equals(parser.getAttributeValue(null, ATTR_NOT_LAUNCHED))) { |
| 2426 | ps.setNotLaunched(true, 0); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2427 | } |
| 2428 | } else { |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2429 | Slog.w(PackageManagerService.TAG, |
Jeff Sharkey | e06b4d1 | 2016-01-06 14:51:50 -0700 | [diff] [blame] | 2430 | "No package known for stopped package " + name); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2431 | } |
| 2432 | XmlUtils.skipCurrentTag(parser); |
| 2433 | } else { |
| 2434 | Slog.w(PackageManagerService.TAG, "Unknown element under <stopped-packages>: " |
| 2435 | + parser.getName()); |
| 2436 | XmlUtils.skipCurrentTag(parser); |
| 2437 | } |
| 2438 | } |
| 2439 | |
| 2440 | str.close(); |
| 2441 | |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2442 | } catch (XmlPullParserException e) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2443 | mReadMessages.append("Error reading: " + e.toString()); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2444 | PackageManagerService.reportSettingsProblem(Log.ERROR, |
| 2445 | "Error reading stopped packages: " + e); |
Dianne Hackborn | 8d05172 | 2014-10-01 14:59:58 -0700 | [diff] [blame] | 2446 | Slog.wtf(PackageManagerService.TAG, "Error reading package manager stopped packages", |
| 2447 | e); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2448 | |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2449 | } catch (java.io.IOException e) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2450 | mReadMessages.append("Error reading: " + e.toString()); |
| 2451 | PackageManagerService.reportSettingsProblem(Log.ERROR, "Error reading settings: " + e); |
Dianne Hackborn | 8d05172 | 2014-10-01 14:59:58 -0700 | [diff] [blame] | 2452 | Slog.wtf(PackageManagerService.TAG, "Error reading package manager stopped packages", |
| 2453 | e); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2454 | |
| 2455 | } |
| 2456 | } |
| 2457 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 2458 | void writeLPr() { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2459 | //Debug.startMethodTracing("/data/system/packageprof", 8 * 1024 * 1024); |
| 2460 | |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 2461 | final long startTime = SystemClock.uptimeMillis(); |
| 2462 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2463 | // Keep the old settings around until we know the new ones have |
| 2464 | // been successfully written. |
| 2465 | if (mSettingsFilename.exists()) { |
| 2466 | // Presence of backup settings file indicates that we failed |
| 2467 | // to persist settings earlier. So preserve the older |
| 2468 | // backup for future reference since the current settings |
| 2469 | // might have been corrupted. |
| 2470 | if (!mBackupSettingsFilename.exists()) { |
| 2471 | if (!mSettingsFilename.renameTo(mBackupSettingsFilename)) { |
Dianne Hackborn | 8d05172 | 2014-10-01 14:59:58 -0700 | [diff] [blame] | 2472 | Slog.wtf(PackageManagerService.TAG, |
| 2473 | "Unable to backup package manager settings, " |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2474 | + " current changes will be lost at reboot"); |
| 2475 | return; |
| 2476 | } |
| 2477 | } else { |
| 2478 | mSettingsFilename.delete(); |
| 2479 | Slog.w(PackageManagerService.TAG, "Preserving older settings backup"); |
| 2480 | } |
| 2481 | } |
| 2482 | |
| 2483 | mPastSignatures.clear(); |
| 2484 | |
| 2485 | try { |
| 2486 | FileOutputStream fstr = new FileOutputStream(mSettingsFilename); |
| 2487 | BufferedOutputStream str = new BufferedOutputStream(fstr); |
| 2488 | |
| 2489 | //XmlSerializer serializer = XmlUtils.serializerInstance(); |
| 2490 | XmlSerializer serializer = new FastXmlSerializer(); |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 2491 | serializer.setOutput(str, StandardCharsets.UTF_8.name()); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2492 | serializer.startDocument(null, true); |
| 2493 | serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true); |
| 2494 | |
| 2495 | serializer.startTag(null, "packages"); |
| 2496 | |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 2497 | for (int i = 0; i < mVersion.size(); i++) { |
| 2498 | final String volumeUuid = mVersion.keyAt(i); |
| 2499 | final VersionInfo ver = mVersion.valueAt(i); |
Jeff Sharkey | edc84ee8 | 2012-03-19 16:52:26 -0700 | [diff] [blame] | 2500 | |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 2501 | serializer.startTag(null, TAG_VERSION); |
| 2502 | XmlUtils.writeStringAttribute(serializer, ATTR_VOLUME_UUID, volumeUuid); |
| 2503 | XmlUtils.writeIntAttribute(serializer, ATTR_SDK_VERSION, ver.sdkVersion); |
| 2504 | XmlUtils.writeIntAttribute(serializer, ATTR_DATABASE_VERSION, ver.databaseVersion); |
| 2505 | XmlUtils.writeStringAttribute(serializer, ATTR_FINGERPRINT, ver.fingerprint); |
| 2506 | serializer.endTag(null, TAG_VERSION); |
| 2507 | } |
Kenny Root | c1c0d3c | 2014-04-24 13:36:40 -0700 | [diff] [blame] | 2508 | |
Kenny Root | 0aaa0d9 | 2011-09-12 16:42:55 -0700 | [diff] [blame] | 2509 | if (mVerifierDeviceIdentity != null) { |
| 2510 | serializer.startTag(null, "verifier"); |
| 2511 | serializer.attribute(null, "device", mVerifierDeviceIdentity.toString()); |
| 2512 | serializer.endTag(null, "verifier"); |
| 2513 | } |
| 2514 | |
Jeff Sharkey | f538577 | 2012-05-11 14:04:41 -0700 | [diff] [blame] | 2515 | if (mReadExternalStorageEnforced != null) { |
Jeff Sharkey | edc84ee8 | 2012-03-19 16:52:26 -0700 | [diff] [blame] | 2516 | serializer.startTag(null, TAG_READ_EXTERNAL_STORAGE); |
| 2517 | serializer.attribute( |
Jeff Sharkey | 5d32e77 | 2012-04-12 15:59:23 -0700 | [diff] [blame] | 2518 | null, ATTR_ENFORCEMENT, mReadExternalStorageEnforced ? "1" : "0"); |
Jeff Sharkey | edc84ee8 | 2012-03-19 16:52:26 -0700 | [diff] [blame] | 2519 | serializer.endTag(null, TAG_READ_EXTERNAL_STORAGE); |
| 2520 | } |
| 2521 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2522 | serializer.startTag(null, "permission-trees"); |
Todd Kennedy | c842393 | 2017-10-05 08:58:36 -0700 | [diff] [blame] | 2523 | mPermissions.writePermissionTrees(serializer); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2524 | serializer.endTag(null, "permission-trees"); |
| 2525 | |
| 2526 | serializer.startTag(null, "permissions"); |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 2527 | mPermissions.writePermissions(serializer); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2528 | serializer.endTag(null, "permissions"); |
| 2529 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 2530 | for (final PackageSetting pkg : mPackages.values()) { |
| 2531 | writePackageLPr(serializer, pkg); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2532 | } |
| 2533 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 2534 | for (final PackageSetting pkg : mDisabledSysPackages.values()) { |
| 2535 | writeDisabledSysPackageLPr(serializer, pkg); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2536 | } |
| 2537 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 2538 | for (final SharedUserSetting usr : mSharedUsers.values()) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2539 | serializer.startTag(null, "shared-user"); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2540 | serializer.attribute(null, ATTR_NAME, usr.name); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2541 | serializer.attribute(null, "userId", |
| 2542 | Integer.toString(usr.userId)); |
| 2543 | usr.signatures.writeXml(serializer, "sigs", mPastSignatures); |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 2544 | writePermissionsLPr(serializer, usr.getPermissionsState() |
| 2545 | .getInstallPermissionStates()); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2546 | serializer.endTag(null, "shared-user"); |
| 2547 | } |
| 2548 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2549 | if (mRenamedPackages.size() > 0) { |
Andy McFadden | 2f36229 | 2012-01-20 14:43:38 -0800 | [diff] [blame] | 2550 | for (Map.Entry<String, String> e : mRenamedPackages.entrySet()) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2551 | serializer.startTag(null, "renamed-package"); |
| 2552 | serializer.attribute(null, "new", e.getKey()); |
| 2553 | serializer.attribute(null, "old", e.getValue()); |
| 2554 | serializer.endTag(null, "renamed-package"); |
| 2555 | } |
| 2556 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 2557 | |
Christopher Tate | 6038d15 | 2015-06-17 13:07:46 -0700 | [diff] [blame] | 2558 | final int numIVIs = mRestoredIntentFilterVerifications.size(); |
| 2559 | if (numIVIs > 0) { |
| 2560 | if (DEBUG_DOMAIN_VERIFICATION) { |
| 2561 | Slog.i(TAG, "Writing restored-ivi entries to packages.xml"); |
| 2562 | } |
| 2563 | serializer.startTag(null, "restored-ivi"); |
| 2564 | for (int i = 0; i < numIVIs; i++) { |
| 2565 | IntentFilterVerificationInfo ivi = mRestoredIntentFilterVerifications.valueAt(i); |
| 2566 | writeDomainVerificationsLPr(serializer, ivi); |
| 2567 | } |
| 2568 | serializer.endTag(null, "restored-ivi"); |
| 2569 | } else { |
| 2570 | if (DEBUG_DOMAIN_VERIFICATION) { |
| 2571 | Slog.i(TAG, " no restored IVI entries to write"); |
| 2572 | } |
| 2573 | } |
| 2574 | |
dcashman | 55b1078 | 2014-04-09 14:20:38 -0700 | [diff] [blame] | 2575 | mKeySetManagerService.writeKeySetManagerServiceLPr(serializer); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2576 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2577 | serializer.endTag(null, "packages"); |
| 2578 | |
| 2579 | serializer.endDocument(); |
| 2580 | |
| 2581 | str.flush(); |
| 2582 | FileUtils.sync(fstr); |
| 2583 | str.close(); |
| 2584 | |
| 2585 | // New settings successfully written, old ones are no longer |
| 2586 | // needed. |
| 2587 | mBackupSettingsFilename.delete(); |
| 2588 | FileUtils.setPermissions(mSettingsFilename.toString(), |
| 2589 | FileUtils.S_IRUSR|FileUtils.S_IWUSR |
Nick Kralevich | 70522ad | 2012-01-06 13:58:01 -0800 | [diff] [blame] | 2590 | |FileUtils.S_IRGRP|FileUtils.S_IWGRP, |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2591 | -1, -1); |
| 2592 | |
Jeff Sharkey | 2271ba3 | 2016-02-01 17:57:08 -0700 | [diff] [blame] | 2593 | writeKernelMappingLPr(); |
Jeff Sharkey | 91edde2 | 2015-05-20 12:04:42 -0700 | [diff] [blame] | 2594 | writePackageListLPr(); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2595 | writeAllUsersPackageRestrictionsLPr(); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 2596 | writeAllRuntimePermissionsLPr(); |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 2597 | com.android.internal.logging.EventLogTags.writeCommitSysConfigFile( |
| 2598 | "package", SystemClock.uptimeMillis() - startTime); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2599 | return; |
| 2600 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2601 | } catch(java.io.IOException e) { |
Dianne Hackborn | 8d05172 | 2014-10-01 14:59:58 -0700 | [diff] [blame] | 2602 | Slog.wtf(PackageManagerService.TAG, "Unable to write package manager settings, " |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2603 | + "current changes will be lost at reboot", e); |
| 2604 | } |
| 2605 | // Clean up partially written files |
| 2606 | if (mSettingsFilename.exists()) { |
| 2607 | if (!mSettingsFilename.delete()) { |
Dianne Hackborn | 8d05172 | 2014-10-01 14:59:58 -0700 | [diff] [blame] | 2608 | Slog.wtf(PackageManagerService.TAG, "Failed to clean up mangled file: " |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2609 | + mSettingsFilename); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2610 | } |
| 2611 | } |
| 2612 | //Debug.stopMethodTracing(); |
| 2613 | } |
| 2614 | |
Amith Yamasani | 23ab7f5 | 2017-01-22 17:43:24 -0800 | [diff] [blame] | 2615 | private void writeKernelRemoveUserLPr(int userId) { |
| 2616 | if (mKernelMappingFilename == null) return; |
| 2617 | |
| 2618 | File removeUserIdFile = new File(mKernelMappingFilename, "remove_userid"); |
| 2619 | if (DEBUG_KERNEL) Slog.d(TAG, "Writing " + userId + " to " + removeUserIdFile |
| 2620 | .getAbsolutePath()); |
| 2621 | writeIntToFile(removeUserIdFile, userId); |
| 2622 | } |
| 2623 | |
Jeff Sharkey | 2271ba3 | 2016-02-01 17:57:08 -0700 | [diff] [blame] | 2624 | void writeKernelMappingLPr() { |
| 2625 | if (mKernelMappingFilename == null) return; |
| 2626 | |
| 2627 | final String[] known = mKernelMappingFilename.list(); |
| 2628 | final ArraySet<String> knownSet = new ArraySet<>(known.length); |
| 2629 | for (String name : known) { |
| 2630 | knownSet.add(name); |
| 2631 | } |
| 2632 | |
| 2633 | for (final PackageSetting ps : mPackages.values()) { |
| 2634 | // Package is actively claimed |
| 2635 | knownSet.remove(ps.name); |
| 2636 | writeKernelMappingLPr(ps); |
| 2637 | } |
| 2638 | |
Sudheer Shanka | 12783cb | 2018-10-18 08:53:02 -0700 | [diff] [blame] | 2639 | for (final SharedUserSetting sus : mSharedUsers.values()) { |
Sudheer Shanka | d68bd60 | 2018-11-13 17:43:39 -0800 | [diff] [blame] | 2640 | knownSet.remove(sus.getStorageSandboxName()); |
Sudheer Shanka | 12783cb | 2018-10-18 08:53:02 -0700 | [diff] [blame] | 2641 | } |
| 2642 | |
Jeff Sharkey | 2271ba3 | 2016-02-01 17:57:08 -0700 | [diff] [blame] | 2643 | // Remove any unclaimed mappings |
| 2644 | for (int i = 0; i < knownSet.size(); i++) { |
| 2645 | final String name = knownSet.valueAt(i); |
| 2646 | if (DEBUG_KERNEL) Slog.d(TAG, "Dropping mapping " + name); |
| 2647 | |
| 2648 | mKernelMapping.remove(name); |
Jeff Sharkey | 800efcc | 2016-02-25 17:08:11 -0700 | [diff] [blame] | 2649 | new File(mKernelMappingFilename, name).delete(); |
Jeff Sharkey | 2271ba3 | 2016-02-01 17:57:08 -0700 | [diff] [blame] | 2650 | } |
| 2651 | } |
| 2652 | |
Sudheer Shanka | 12783cb | 2018-10-18 08:53:02 -0700 | [diff] [blame] | 2653 | void writeKernelMappingLPr(SharedUserSetting sus) { |
| 2654 | if (mKernelMappingFilename == null || sus == null || sus.name == null) return; |
| 2655 | |
Sudheer Shanka | d68bd60 | 2018-11-13 17:43:39 -0800 | [diff] [blame] | 2656 | writeKernelMappingLPr(sus.getStorageSandboxName(), |
| 2657 | sus.userId, sus.getNotInstalledUserIds()); |
Sudheer Shanka | 12783cb | 2018-10-18 08:53:02 -0700 | [diff] [blame] | 2658 | } |
| 2659 | |
Jeff Sharkey | 2271ba3 | 2016-02-01 17:57:08 -0700 | [diff] [blame] | 2660 | void writeKernelMappingLPr(PackageSetting ps) { |
Amith Yamasani | 23ab7f5 | 2017-01-22 17:43:24 -0800 | [diff] [blame] | 2661 | if (mKernelMappingFilename == null || ps == null || ps.name == null) return; |
Jeff Sharkey | 2271ba3 | 2016-02-01 17:57:08 -0700 | [diff] [blame] | 2662 | |
Sudheer Shanka | 12783cb | 2018-10-18 08:53:02 -0700 | [diff] [blame] | 2663 | writeKernelMappingLPr(ps.name, ps.appId, ps.getNotInstalledUserIds()); |
| 2664 | if (ps.sharedUser != null) { |
| 2665 | writeKernelMappingLPr(ps.sharedUser); |
| 2666 | } |
| 2667 | } |
| 2668 | |
| 2669 | void writeKernelMappingLPr(String name, int appId, int[] excludedUserIds) { |
| 2670 | KernelPackageState cur = mKernelMapping.get(name); |
Amith Yamasani | 23ab7f5 | 2017-01-22 17:43:24 -0800 | [diff] [blame] | 2671 | final boolean firstTime = cur == null; |
Amith Yamasani | 23ab7f5 | 2017-01-22 17:43:24 -0800 | [diff] [blame] | 2672 | final boolean userIdsChanged = firstTime |
| 2673 | || !Arrays.equals(excludedUserIds, cur.excludedUserIds); |
| 2674 | |
| 2675 | // Package directory |
Sudheer Shanka | 12783cb | 2018-10-18 08:53:02 -0700 | [diff] [blame] | 2676 | final File dir = new File(mKernelMappingFilename, name); |
Amith Yamasani | 23ab7f5 | 2017-01-22 17:43:24 -0800 | [diff] [blame] | 2677 | |
| 2678 | if (firstTime) { |
| 2679 | dir.mkdir(); |
| 2680 | // Create a new mapping state |
| 2681 | cur = new KernelPackageState(); |
Sudheer Shanka | 12783cb | 2018-10-18 08:53:02 -0700 | [diff] [blame] | 2682 | mKernelMapping.put(name, cur); |
Jeff Sharkey | 2271ba3 | 2016-02-01 17:57:08 -0700 | [diff] [blame] | 2683 | } |
| 2684 | |
Amith Yamasani | 23ab7f5 | 2017-01-22 17:43:24 -0800 | [diff] [blame] | 2685 | // If mapping is incorrect or non-existent, write the appid file |
Sudheer Shanka | 12783cb | 2018-10-18 08:53:02 -0700 | [diff] [blame] | 2686 | if (cur.appId != appId) { |
Amith Yamasani | 23ab7f5 | 2017-01-22 17:43:24 -0800 | [diff] [blame] | 2687 | final File appIdFile = new File(dir, "appid"); |
Sudheer Shanka | 12783cb | 2018-10-18 08:53:02 -0700 | [diff] [blame] | 2688 | writeIntToFile(appIdFile, appId); |
| 2689 | if (DEBUG_KERNEL) Slog.d(TAG, "Mapping " + name + " to " + appId); |
Amith Yamasani | 23ab7f5 | 2017-01-22 17:43:24 -0800 | [diff] [blame] | 2690 | } |
Jeff Sharkey | 2271ba3 | 2016-02-01 17:57:08 -0700 | [diff] [blame] | 2691 | |
Amith Yamasani | 23ab7f5 | 2017-01-22 17:43:24 -0800 | [diff] [blame] | 2692 | if (userIdsChanged) { |
| 2693 | // Build the exclusion list -- the ids to add to the exclusion list |
| 2694 | for (int i = 0; i < excludedUserIds.length; i++) { |
| 2695 | if (cur.excludedUserIds == null || !ArrayUtils.contains(cur.excludedUserIds, |
| 2696 | excludedUserIds[i])) { |
| 2697 | writeIntToFile(new File(dir, "excluded_userids"), excludedUserIds[i]); |
| 2698 | if (DEBUG_KERNEL) Slog.d(TAG, "Writing " + excludedUserIds[i] + " to " |
Sudheer Shanka | 12783cb | 2018-10-18 08:53:02 -0700 | [diff] [blame] | 2699 | + name + "/excluded_userids"); |
Amith Yamasani | 23ab7f5 | 2017-01-22 17:43:24 -0800 | [diff] [blame] | 2700 | } |
| 2701 | } |
| 2702 | // Build the inclusion list -- the ids to remove from the exclusion list |
| 2703 | if (cur.excludedUserIds != null) { |
| 2704 | for (int i = 0; i < cur.excludedUserIds.length; i++) { |
| 2705 | if (!ArrayUtils.contains(excludedUserIds, cur.excludedUserIds[i])) { |
| 2706 | writeIntToFile(new File(dir, "clear_userid"), |
| 2707 | cur.excludedUserIds[i]); |
| 2708 | if (DEBUG_KERNEL) Slog.d(TAG, "Writing " + cur.excludedUserIds[i] + " to " |
Sudheer Shanka | 12783cb | 2018-10-18 08:53:02 -0700 | [diff] [blame] | 2709 | + name + "/clear_userid"); |
Jeff Sharkey | 2271ba3 | 2016-02-01 17:57:08 -0700 | [diff] [blame] | 2710 | |
Amith Yamasani | 23ab7f5 | 2017-01-22 17:43:24 -0800 | [diff] [blame] | 2711 | } |
| 2712 | } |
| 2713 | } |
| 2714 | cur.excludedUserIds = excludedUserIds; |
| 2715 | } |
| 2716 | } |
| 2717 | |
| 2718 | private void writeIntToFile(File file, int value) { |
Jeff Sharkey | 2271ba3 | 2016-02-01 17:57:08 -0700 | [diff] [blame] | 2719 | try { |
Narayan Kamath | 6d051fc | 2016-11-22 20:20:00 +0000 | [diff] [blame] | 2720 | FileUtils.bytesToFile(file.getAbsolutePath(), |
Amith Yamasani | 23ab7f5 | 2017-01-22 17:43:24 -0800 | [diff] [blame] | 2721 | Integer.toString(value).getBytes(StandardCharsets.US_ASCII)); |
Jeff Sharkey | 2271ba3 | 2016-02-01 17:57:08 -0700 | [diff] [blame] | 2722 | } catch (IOException ignored) { |
Amith Yamasani | 23ab7f5 | 2017-01-22 17:43:24 -0800 | [diff] [blame] | 2723 | Slog.w(TAG, "Couldn't write " + value + " to " + file.getAbsolutePath()); |
Jeff Sharkey | 2271ba3 | 2016-02-01 17:57:08 -0700 | [diff] [blame] | 2724 | } |
| 2725 | } |
| 2726 | |
Jeff Sharkey | 91edde2 | 2015-05-20 12:04:42 -0700 | [diff] [blame] | 2727 | void writePackageListLPr() { |
| 2728 | writePackageListLPr(-1); |
| 2729 | } |
| 2730 | |
| 2731 | void writePackageListLPr(int creatingUserId) { |
| 2732 | // Only derive GIDs for active users (not dying) |
| 2733 | final List<UserInfo> users = UserManagerService.getInstance().getUsers(true); |
| 2734 | int[] userIds = new int[users.size()]; |
| 2735 | for (int i = 0; i < userIds.length; i++) { |
| 2736 | userIds[i] = users.get(i).id; |
| 2737 | } |
| 2738 | if (creatingUserId != -1) { |
| 2739 | userIds = ArrayUtils.appendInt(userIds, creatingUserId); |
| 2740 | } |
| 2741 | |
| 2742 | // Write package list file now, use a JournaledFile. |
| 2743 | File tempFile = new File(mPackageListFilename.getAbsolutePath() + ".tmp"); |
| 2744 | JournaledFile journal = new JournaledFile(mPackageListFilename, tempFile); |
| 2745 | |
| 2746 | final File writeTarget = journal.chooseForWrite(); |
Fyodor Kupolov | b69056b | 2015-12-18 15:20:00 -0800 | [diff] [blame] | 2747 | FileOutputStream fstr; |
| 2748 | BufferedWriter writer = null; |
Jeff Sharkey | 91edde2 | 2015-05-20 12:04:42 -0700 | [diff] [blame] | 2749 | try { |
| 2750 | fstr = new FileOutputStream(writeTarget); |
Fyodor Kupolov | b69056b | 2015-12-18 15:20:00 -0800 | [diff] [blame] | 2751 | writer = new BufferedWriter(new OutputStreamWriter(fstr, Charset.defaultCharset())); |
Jeff Sharkey | 91edde2 | 2015-05-20 12:04:42 -0700 | [diff] [blame] | 2752 | FileUtils.setPermissions(fstr.getFD(), 0640, SYSTEM_UID, PACKAGE_INFO_GID); |
| 2753 | |
| 2754 | StringBuilder sb = new StringBuilder(); |
| 2755 | for (final PackageSetting pkg : mPackages.values()) { |
Jeff Sharkey | e17ac15 | 2015-11-06 22:40:29 -0800 | [diff] [blame] | 2756 | if (pkg.pkg == null || pkg.pkg.applicationInfo == null |
| 2757 | || pkg.pkg.applicationInfo.dataDir == null) { |
Jeff Sharkey | 2271ba3 | 2016-02-01 17:57:08 -0700 | [diff] [blame] | 2758 | if (!"android".equals(pkg.name)) { |
| 2759 | Slog.w(TAG, "Skipping " + pkg + " due to missing metadata"); |
| 2760 | } |
Jeff Sharkey | 91edde2 | 2015-05-20 12:04:42 -0700 | [diff] [blame] | 2761 | continue; |
| 2762 | } |
| 2763 | |
| 2764 | final ApplicationInfo ai = pkg.pkg.applicationInfo; |
Jeff Sharkey | e84bdd3 | 2016-02-08 12:16:00 -0700 | [diff] [blame] | 2765 | final String dataPath = ai.dataDir; |
Jeff Sharkey | 91edde2 | 2015-05-20 12:04:42 -0700 | [diff] [blame] | 2766 | final boolean isDebug = (ai.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0; |
| 2767 | final int[] gids = pkg.getPermissionsState().computeGids(userIds); |
| 2768 | |
| 2769 | // Avoid any application that has a space in its path. |
Fyodor Kupolov | b69056b | 2015-12-18 15:20:00 -0800 | [diff] [blame] | 2770 | if (dataPath.indexOf(' ') >= 0) |
Jeff Sharkey | 91edde2 | 2015-05-20 12:04:42 -0700 | [diff] [blame] | 2771 | continue; |
| 2772 | |
| 2773 | // we store on each line the following information for now: |
| 2774 | // |
| 2775 | // pkgName - package name |
| 2776 | // userId - application-specific user id |
| 2777 | // debugFlag - 0 or 1 if the package is debuggable. |
| 2778 | // dataPath - path to package's data path |
| 2779 | // seinfo - seinfo label for the app (assigned at install time) |
| 2780 | // gids - supplementary gids this app launches with |
| 2781 | // |
| 2782 | // NOTE: We prefer not to expose all ApplicationInfo flags for now. |
| 2783 | // |
| 2784 | // DO NOT MODIFY THIS FORMAT UNLESS YOU CAN ALSO MODIFY ITS USERS |
| 2785 | // FROM NATIVE CODE. AT THE MOMENT, LOOK AT THE FOLLOWING SOURCES: |
Yabin Cui | 1d5ca70 | 2018-11-12 23:42:51 +0000 | [diff] [blame] | 2786 | // frameworks/base/libs/packagelistparser |
| 2787 | // system/core/run-as/run-as.c |
Jeff Sharkey | 91edde2 | 2015-05-20 12:04:42 -0700 | [diff] [blame] | 2788 | // |
| 2789 | sb.setLength(0); |
| 2790 | sb.append(ai.packageName); |
| 2791 | sb.append(" "); |
Fyodor Kupolov | b69056b | 2015-12-18 15:20:00 -0800 | [diff] [blame] | 2792 | sb.append(ai.uid); |
Jeff Sharkey | 91edde2 | 2015-05-20 12:04:42 -0700 | [diff] [blame] | 2793 | sb.append(isDebug ? " 1 " : " 0 "); |
| 2794 | sb.append(dataPath); |
| 2795 | sb.append(" "); |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 2796 | sb.append(ai.seInfo); |
Jeff Sharkey | 91edde2 | 2015-05-20 12:04:42 -0700 | [diff] [blame] | 2797 | sb.append(" "); |
| 2798 | if (gids != null && gids.length > 0) { |
| 2799 | sb.append(gids[0]); |
| 2800 | for (int i = 1; i < gids.length; i++) { |
| 2801 | sb.append(","); |
| 2802 | sb.append(gids[i]); |
| 2803 | } |
| 2804 | } else { |
| 2805 | sb.append("none"); |
| 2806 | } |
| 2807 | sb.append("\n"); |
Fyodor Kupolov | b69056b | 2015-12-18 15:20:00 -0800 | [diff] [blame] | 2808 | writer.append(sb); |
Jeff Sharkey | 91edde2 | 2015-05-20 12:04:42 -0700 | [diff] [blame] | 2809 | } |
Fyodor Kupolov | b69056b | 2015-12-18 15:20:00 -0800 | [diff] [blame] | 2810 | writer.flush(); |
Jeff Sharkey | 91edde2 | 2015-05-20 12:04:42 -0700 | [diff] [blame] | 2811 | FileUtils.sync(fstr); |
Fyodor Kupolov | b69056b | 2015-12-18 15:20:00 -0800 | [diff] [blame] | 2812 | writer.close(); |
Jeff Sharkey | 91edde2 | 2015-05-20 12:04:42 -0700 | [diff] [blame] | 2813 | journal.commit(); |
| 2814 | } catch (Exception e) { |
| 2815 | Slog.wtf(TAG, "Failed to write packages.list", e); |
Fyodor Kupolov | b69056b | 2015-12-18 15:20:00 -0800 | [diff] [blame] | 2816 | IoUtils.closeQuietly(writer); |
Jeff Sharkey | 91edde2 | 2015-05-20 12:04:42 -0700 | [diff] [blame] | 2817 | journal.rollback(); |
| 2818 | } |
| 2819 | } |
| 2820 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 2821 | void writeDisabledSysPackageLPr(XmlSerializer serializer, final PackageSetting pkg) |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2822 | throws java.io.IOException { |
| 2823 | serializer.startTag(null, "updated-package"); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2824 | serializer.attribute(null, ATTR_NAME, pkg.name); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2825 | if (pkg.realName != null) { |
| 2826 | serializer.attribute(null, "realName", pkg.realName); |
| 2827 | } |
| 2828 | serializer.attribute(null, "codePath", pkg.codePathString); |
| 2829 | serializer.attribute(null, "ft", Long.toHexString(pkg.timeStamp)); |
| 2830 | serializer.attribute(null, "it", Long.toHexString(pkg.firstInstallTime)); |
| 2831 | serializer.attribute(null, "ut", Long.toHexString(pkg.lastUpdateTime)); |
| 2832 | serializer.attribute(null, "version", String.valueOf(pkg.versionCode)); |
| 2833 | if (!pkg.resourcePathString.equals(pkg.codePathString)) { |
| 2834 | serializer.attribute(null, "resourcePath", pkg.resourcePathString); |
| 2835 | } |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 2836 | if (pkg.legacyNativeLibraryPathString != null) { |
| 2837 | serializer.attribute(null, "nativeLibraryPath", pkg.legacyNativeLibraryPathString); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2838 | } |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 2839 | if (pkg.primaryCpuAbiString != null) { |
| 2840 | serializer.attribute(null, "primaryCpuAbi", pkg.primaryCpuAbiString); |
Narayan Kamath | 9e289d7 | 2014-04-10 09:26:59 +0000 | [diff] [blame] | 2841 | } |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 2842 | if (pkg.secondaryCpuAbiString != null) { |
| 2843 | serializer.attribute(null, "secondaryCpuAbi", pkg.secondaryCpuAbiString); |
| 2844 | } |
Narayan Kamath | 4903f64 | 2014-08-11 13:33:45 +0100 | [diff] [blame] | 2845 | if (pkg.cpuAbiOverrideString != null) { |
| 2846 | serializer.attribute(null, "cpuAbiOverride", pkg.cpuAbiOverrideString); |
| 2847 | } |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 2848 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2849 | if (pkg.sharedUser == null) { |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 2850 | serializer.attribute(null, "userId", Integer.toString(pkg.appId)); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2851 | } else { |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 2852 | serializer.attribute(null, "sharedUserId", Integer.toString(pkg.appId)); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2853 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 2854 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2855 | if (pkg.parentPackageName != null) { |
| 2856 | serializer.attribute(null, "parentPackageName", pkg.parentPackageName); |
| 2857 | } |
| 2858 | |
| 2859 | writeChildPackagesLPw(serializer, pkg.childPackageNames); |
| 2860 | |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 2861 | writeUsesStaticLibLPw(serializer, pkg.usesStaticLibraries, pkg.usesStaticLibrariesVersions); |
| 2862 | |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 2863 | // If this is a shared user, the permissions will be written there. |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2864 | if (pkg.sharedUser == null) { |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 2865 | writePermissionsLPr(serializer, pkg.getPermissionsState() |
| 2866 | .getInstallPermissionStates()); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2867 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 2868 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2869 | serializer.endTag(null, "updated-package"); |
| 2870 | } |
| 2871 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 2872 | void writePackageLPr(XmlSerializer serializer, final PackageSetting pkg) |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2873 | throws java.io.IOException { |
| 2874 | serializer.startTag(null, "package"); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2875 | serializer.attribute(null, ATTR_NAME, pkg.name); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2876 | if (pkg.realName != null) { |
| 2877 | serializer.attribute(null, "realName", pkg.realName); |
| 2878 | } |
| 2879 | serializer.attribute(null, "codePath", pkg.codePathString); |
| 2880 | if (!pkg.resourcePathString.equals(pkg.codePathString)) { |
| 2881 | serializer.attribute(null, "resourcePath", pkg.resourcePathString); |
| 2882 | } |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 2883 | |
| 2884 | if (pkg.legacyNativeLibraryPathString != null) { |
| 2885 | serializer.attribute(null, "nativeLibraryPath", pkg.legacyNativeLibraryPathString); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2886 | } |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 2887 | if (pkg.primaryCpuAbiString != null) { |
| 2888 | serializer.attribute(null, "primaryCpuAbi", pkg.primaryCpuAbiString); |
Narayan Kamath | 9e289d7 | 2014-04-10 09:26:59 +0000 | [diff] [blame] | 2889 | } |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 2890 | if (pkg.secondaryCpuAbiString != null) { |
| 2891 | serializer.attribute(null, "secondaryCpuAbi", pkg.secondaryCpuAbiString); |
| 2892 | } |
Narayan Kamath | 4903f64 | 2014-08-11 13:33:45 +0100 | [diff] [blame] | 2893 | if (pkg.cpuAbiOverrideString != null) { |
| 2894 | serializer.attribute(null, "cpuAbiOverride", pkg.cpuAbiOverrideString); |
| 2895 | } |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 2896 | |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 2897 | serializer.attribute(null, "publicFlags", Integer.toString(pkg.pkgFlags)); |
| 2898 | serializer.attribute(null, "privateFlags", Integer.toString(pkg.pkgPrivateFlags)); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2899 | serializer.attribute(null, "ft", Long.toHexString(pkg.timeStamp)); |
| 2900 | serializer.attribute(null, "it", Long.toHexString(pkg.firstInstallTime)); |
| 2901 | serializer.attribute(null, "ut", Long.toHexString(pkg.lastUpdateTime)); |
| 2902 | serializer.attribute(null, "version", String.valueOf(pkg.versionCode)); |
| 2903 | if (pkg.sharedUser == null) { |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 2904 | serializer.attribute(null, "userId", Integer.toString(pkg.appId)); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2905 | } else { |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 2906 | serializer.attribute(null, "sharedUserId", Integer.toString(pkg.appId)); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2907 | } |
| 2908 | if (pkg.uidError) { |
| 2909 | serializer.attribute(null, "uidError", "true"); |
| 2910 | } |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2911 | if (pkg.installerPackageName != null) { |
| 2912 | serializer.attribute(null, "installer", pkg.installerPackageName); |
| 2913 | } |
Sudheer Shanka | 8c57aea | 2016-04-20 16:47:50 -0700 | [diff] [blame] | 2914 | if (pkg.isOrphaned) { |
| 2915 | serializer.attribute(null, "isOrphaned", "true"); |
| 2916 | } |
Jeff Sharkey | b2b9ab8 | 2015-04-05 21:10:42 -0700 | [diff] [blame] | 2917 | if (pkg.volumeUuid != null) { |
| 2918 | serializer.attribute(null, "volumeUuid", pkg.volumeUuid); |
| 2919 | } |
Jeff Sharkey | 9bc89af | 2017-01-11 11:25:50 -0700 | [diff] [blame] | 2920 | if (pkg.categoryHint != ApplicationInfo.CATEGORY_UNDEFINED) { |
| 2921 | serializer.attribute(null, "categoryHint", |
| 2922 | Integer.toString(pkg.categoryHint)); |
| 2923 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2924 | if (pkg.parentPackageName != null) { |
| 2925 | serializer.attribute(null, "parentPackageName", pkg.parentPackageName); |
| 2926 | } |
Todd Kennedy | ab53289 | 2017-03-08 14:19:49 -0800 | [diff] [blame] | 2927 | if (pkg.updateAvailable) { |
| 2928 | serializer.attribute(null, "updateAvailable", "true"); |
| 2929 | } |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 2930 | |
| 2931 | writeChildPackagesLPw(serializer, pkg.childPackageNames); |
| 2932 | |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 2933 | writeUsesStaticLibLPw(serializer, pkg.usesStaticLibraries, pkg.usesStaticLibrariesVersions); |
| 2934 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2935 | pkg.signatures.writeXml(serializer, "sigs", mPastSignatures); |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 2936 | |
| 2937 | writePermissionsLPr(serializer, pkg.getPermissionsState() |
| 2938 | .getInstallPermissionStates()); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2939 | |
dcashman | 8c04fac | 2015-03-23 11:39:42 -0700 | [diff] [blame] | 2940 | writeSigningKeySetLPr(serializer, pkg.keySetData); |
dcashman | 55b1078 | 2014-04-09 14:20:38 -0700 | [diff] [blame] | 2941 | writeUpgradeKeySetsLPr(serializer, pkg.keySetData); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2942 | writeKeySetAliasesLPr(serializer, pkg.keySetData); |
Fabrice Di Meglio | 6227172 | 2015-04-10 17:24:02 -0700 | [diff] [blame] | 2943 | writeDomainVerificationsLPr(serializer, pkg.verificationInfo); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2944 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2945 | serializer.endTag(null, "package"); |
| 2946 | } |
| 2947 | |
dcashman | 8c04fac | 2015-03-23 11:39:42 -0700 | [diff] [blame] | 2948 | void writeSigningKeySetLPr(XmlSerializer serializer, |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2949 | PackageKeySetData data) throws IOException { |
dcashman | 8c04fac | 2015-03-23 11:39:42 -0700 | [diff] [blame] | 2950 | serializer.startTag(null, "proper-signing-keyset"); |
| 2951 | serializer.attribute(null, "identifier", |
| 2952 | Long.toString(data.getProperSigningKeySet())); |
| 2953 | serializer.endTag(null, "proper-signing-keyset"); |
dcashman | 55b1078 | 2014-04-09 14:20:38 -0700 | [diff] [blame] | 2954 | } |
| 2955 | |
| 2956 | void writeUpgradeKeySetsLPr(XmlSerializer serializer, |
| 2957 | PackageKeySetData data) throws IOException { |
| 2958 | if (data.isUsingUpgradeKeySets()) { |
| 2959 | for (long id : data.getUpgradeKeySets()) { |
| 2960 | serializer.startTag(null, "upgrade-keyset"); |
| 2961 | serializer.attribute(null, "identifier", Long.toString(id)); |
| 2962 | serializer.endTag(null, "upgrade-keyset"); |
| 2963 | } |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 2964 | } |
| 2965 | } |
| 2966 | |
| 2967 | void writeKeySetAliasesLPr(XmlSerializer serializer, |
| 2968 | PackageKeySetData data) throws IOException { |
| 2969 | for (Map.Entry<String, Long> e: data.getAliases().entrySet()) { |
| 2970 | serializer.startTag(null, "defined-keyset"); |
| 2971 | serializer.attribute(null, "alias", e.getKey()); |
| 2972 | serializer.attribute(null, "identifier", Long.toString(e.getValue())); |
| 2973 | serializer.endTag(null, "defined-keyset"); |
| 2974 | } |
| 2975 | } |
| 2976 | |
Todd Kennedy | 91a39d1 | 2017-09-27 12:37:04 -0700 | [diff] [blame] | 2977 | void writePermissionLPr(XmlSerializer serializer, BasePermission bp) throws IOException { |
| 2978 | bp.writeLPr(serializer); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2979 | } |
| 2980 | |
Xiaohui Chen | 594f208 | 2015-08-18 11:04:20 -0700 | [diff] [blame] | 2981 | boolean readLPw(@NonNull List<UserInfo> users) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 2982 | FileInputStream str = null; |
| 2983 | if (mBackupSettingsFilename.exists()) { |
| 2984 | try { |
| 2985 | str = new FileInputStream(mBackupSettingsFilename); |
| 2986 | mReadMessages.append("Reading from backup settings file\n"); |
| 2987 | PackageManagerService.reportSettingsProblem(Log.INFO, |
| 2988 | "Need to read from backup settings file"); |
| 2989 | if (mSettingsFilename.exists()) { |
| 2990 | // If both the backup and settings file exist, we |
| 2991 | // ignore the settings since it might have been |
| 2992 | // corrupted. |
| 2993 | Slog.w(PackageManagerService.TAG, "Cleaning up settings file " |
| 2994 | + mSettingsFilename); |
| 2995 | mSettingsFilename.delete(); |
| 2996 | } |
| 2997 | } catch (java.io.IOException e) { |
| 2998 | // We'll try for the normal settings file. |
| 2999 | } |
| 3000 | } |
| 3001 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 3002 | mPendingPackages.clear(); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3003 | mPastSignatures.clear(); |
dcashman | 8c04fac | 2015-03-23 11:39:42 -0700 | [diff] [blame] | 3004 | mKeySetRefs.clear(); |
Sudheer Shanka | 2928337 | 2016-04-04 20:56:27 -0700 | [diff] [blame] | 3005 | mInstallerPackages.clear(); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3006 | |
| 3007 | try { |
| 3008 | if (str == null) { |
| 3009 | if (!mSettingsFilename.exists()) { |
| 3010 | mReadMessages.append("No settings file found\n"); |
| 3011 | PackageManagerService.reportSettingsProblem(Log.INFO, |
| 3012 | "No settings file; creating initial state"); |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 3013 | // It's enough to just touch version details to create them |
| 3014 | // with default values |
longhai | bc62b21 | 2016-01-29 14:22:22 +0800 | [diff] [blame] | 3015 | findOrCreateVersion(StorageManager.UUID_PRIVATE_INTERNAL).forceCurrent(); |
| 3016 | findOrCreateVersion(StorageManager.UUID_PRIMARY_PHYSICAL).forceCurrent(); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3017 | return false; |
| 3018 | } |
| 3019 | str = new FileInputStream(mSettingsFilename); |
| 3020 | } |
| 3021 | XmlPullParser parser = Xml.newPullParser(); |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 3022 | parser.setInput(str, StandardCharsets.UTF_8.name()); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3023 | |
| 3024 | int type; |
| 3025 | while ((type = parser.next()) != XmlPullParser.START_TAG |
| 3026 | && type != XmlPullParser.END_DOCUMENT) { |
| 3027 | ; |
| 3028 | } |
| 3029 | |
| 3030 | if (type != XmlPullParser.START_TAG) { |
| 3031 | mReadMessages.append("No start tag found in settings file\n"); |
| 3032 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 3033 | "No start tag found in package manager settings"); |
Dianne Hackborn | 8d05172 | 2014-10-01 14:59:58 -0700 | [diff] [blame] | 3034 | Slog.wtf(PackageManagerService.TAG, |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 3035 | "No start tag found in package manager settings"); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3036 | return false; |
| 3037 | } |
| 3038 | |
| 3039 | int outerDepth = parser.getDepth(); |
| 3040 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 3041 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 3042 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 3043 | continue; |
| 3044 | } |
| 3045 | |
| 3046 | String tagName = parser.getName(); |
| 3047 | if (tagName.equals("package")) { |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 3048 | readPackageLPw(parser); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3049 | } else if (tagName.equals("permissions")) { |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 3050 | mPermissions.readPermissions(parser); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3051 | } else if (tagName.equals("permission-trees")) { |
Todd Kennedy | c842393 | 2017-10-05 08:58:36 -0700 | [diff] [blame] | 3052 | mPermissions.readPermissionTrees(parser); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3053 | } else if (tagName.equals("shared-user")) { |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 3054 | readSharedUserLPw(parser); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3055 | } else if (tagName.equals("preferred-packages")) { |
| 3056 | // no longer used. |
| 3057 | } else if (tagName.equals("preferred-activities")) { |
Dianne Hackborn | 6309271 | 2012-10-07 14:45:35 -0700 | [diff] [blame] | 3058 | // Upgrading from old single-user implementation; |
| 3059 | // these are the preferred activities for user 0. |
| 3060 | readPreferredActivitiesLPw(parser, 0); |
Sander Alewijnse | af59762 | 2014-03-20 18:44:57 +0000 | [diff] [blame] | 3061 | } else if (tagName.equals(TAG_PERSISTENT_PREFERRED_ACTIVITIES)) { |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 3062 | // TODO: check whether this is okay! as it is very |
| 3063 | // similar to how preferred-activities are treated |
| 3064 | readPersistentPreferredActivitiesLPw(parser, 0); |
Nicolas Prevot | 29762c3 | 2014-07-29 18:51:32 +0100 | [diff] [blame] | 3065 | } else if (tagName.equals(TAG_CROSS_PROFILE_INTENT_FILTERS)) { |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 3066 | // TODO: check whether this is okay! as it is very |
| 3067 | // similar to how preferred-activities are treated |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 3068 | readCrossProfileIntentFiltersLPw(parser, 0); |
Fabrice Di Meglio | 6227172 | 2015-04-10 17:24:02 -0700 | [diff] [blame] | 3069 | } else if (tagName.equals(TAG_DEFAULT_BROWSER)) { |
| 3070 | readDefaultAppsLPw(parser, 0); |
| 3071 | } else if (tagName.equals("updated-package")) { |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 3072 | readDisabledSysPackageLPw(parser); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3073 | } else if (tagName.equals("renamed-package")) { |
| 3074 | String nname = parser.getAttributeValue(null, "new"); |
| 3075 | String oname = parser.getAttributeValue(null, "old"); |
| 3076 | if (nname != null && oname != null) { |
| 3077 | mRenamedPackages.put(nname, oname); |
| 3078 | } |
Christopher Tate | 6038d15 | 2015-06-17 13:07:46 -0700 | [diff] [blame] | 3079 | } else if (tagName.equals("restored-ivi")) { |
| 3080 | readRestoredIntentFilterVerifications(parser); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3081 | } else if (tagName.equals("last-platform-version")) { |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 3082 | // Upgrade from older XML schema |
| 3083 | final VersionInfo internal = findOrCreateVersion( |
| 3084 | StorageManager.UUID_PRIVATE_INTERNAL); |
| 3085 | final VersionInfo external = findOrCreateVersion( |
| 3086 | StorageManager.UUID_PRIMARY_PHYSICAL); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 3087 | |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 3088 | internal.sdkVersion = XmlUtils.readIntAttribute(parser, "internal", 0); |
| 3089 | external.sdkVersion = XmlUtils.readIntAttribute(parser, "external", 0); |
| 3090 | internal.fingerprint = external.fingerprint = |
| 3091 | XmlUtils.readStringAttribute(parser, "fingerprint"); |
| 3092 | |
Kenny Root | c1c0d3c | 2014-04-24 13:36:40 -0700 | [diff] [blame] | 3093 | } else if (tagName.equals("database-version")) { |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 3094 | // Upgrade from older XML schema |
| 3095 | final VersionInfo internal = findOrCreateVersion( |
| 3096 | StorageManager.UUID_PRIVATE_INTERNAL); |
| 3097 | final VersionInfo external = findOrCreateVersion( |
| 3098 | StorageManager.UUID_PRIMARY_PHYSICAL); |
| 3099 | |
| 3100 | internal.databaseVersion = XmlUtils.readIntAttribute(parser, "internal", 0); |
| 3101 | external.databaseVersion = XmlUtils.readIntAttribute(parser, "external", 0); |
| 3102 | |
Kenny Root | 0aaa0d9 | 2011-09-12 16:42:55 -0700 | [diff] [blame] | 3103 | } else if (tagName.equals("verifier")) { |
| 3104 | final String deviceIdentity = parser.getAttributeValue(null, "device"); |
| 3105 | try { |
| 3106 | mVerifierDeviceIdentity = VerifierDeviceIdentity.parse(deviceIdentity); |
| 3107 | } catch (IllegalArgumentException e) { |
| 3108 | Slog.w(PackageManagerService.TAG, "Discard invalid verifier device id: " |
| 3109 | + e.getMessage()); |
| 3110 | } |
Jeff Sharkey | edc84ee8 | 2012-03-19 16:52:26 -0700 | [diff] [blame] | 3111 | } else if (TAG_READ_EXTERNAL_STORAGE.equals(tagName)) { |
| 3112 | final String enforcement = parser.getAttributeValue(null, ATTR_ENFORCEMENT); |
Todd Kennedy | 91a39d1 | 2017-09-27 12:37:04 -0700 | [diff] [blame] | 3113 | mReadExternalStorageEnforced = |
| 3114 | "1".equals(enforcement) ? Boolean.TRUE : Boolean.FALSE; |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 3115 | } else if (tagName.equals("keyset-settings")) { |
dcashman | 8c04fac | 2015-03-23 11:39:42 -0700 | [diff] [blame] | 3116 | mKeySetManagerService.readKeySetsLPw(parser, mKeySetRefs); |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 3117 | } else if (TAG_VERSION.equals(tagName)) { |
| 3118 | final String volumeUuid = XmlUtils.readStringAttribute(parser, |
| 3119 | ATTR_VOLUME_UUID); |
| 3120 | final VersionInfo ver = findOrCreateVersion(volumeUuid); |
| 3121 | ver.sdkVersion = XmlUtils.readIntAttribute(parser, ATTR_SDK_VERSION); |
khmel | 80bdce0 | 2018-01-02 16:39:05 -0800 | [diff] [blame] | 3122 | ver.databaseVersion = XmlUtils.readIntAttribute(parser, ATTR_DATABASE_VERSION); |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 3123 | ver.fingerprint = XmlUtils.readStringAttribute(parser, ATTR_FINGERPRINT); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3124 | } else { |
| 3125 | Slog.w(PackageManagerService.TAG, "Unknown element under <packages>: " |
| 3126 | + parser.getName()); |
| 3127 | XmlUtils.skipCurrentTag(parser); |
| 3128 | } |
| 3129 | } |
| 3130 | |
| 3131 | str.close(); |
| 3132 | |
| 3133 | } catch (XmlPullParserException e) { |
| 3134 | mReadMessages.append("Error reading: " + e.toString()); |
| 3135 | PackageManagerService.reportSettingsProblem(Log.ERROR, "Error reading settings: " + e); |
Dianne Hackborn | 8d05172 | 2014-10-01 14:59:58 -0700 | [diff] [blame] | 3136 | Slog.wtf(PackageManagerService.TAG, "Error reading package manager settings", e); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3137 | |
| 3138 | } catch (java.io.IOException e) { |
| 3139 | mReadMessages.append("Error reading: " + e.toString()); |
| 3140 | PackageManagerService.reportSettingsProblem(Log.ERROR, "Error reading settings: " + e); |
Dianne Hackborn | 8d05172 | 2014-10-01 14:59:58 -0700 | [diff] [blame] | 3141 | Slog.wtf(PackageManagerService.TAG, "Error reading package manager settings", e); |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 3142 | } |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3143 | |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 3144 | // If the build is setup to drop runtime permissions |
| 3145 | // on update drop the files before loading them. |
| 3146 | if (PackageManagerService.CLEAR_RUNTIME_PERMISSIONS_ON_UPGRADE) { |
| 3147 | final VersionInfo internal = getInternalVersion(); |
| 3148 | if (!Build.FINGERPRINT.equals(internal.fingerprint)) { |
Xiaohui Chen | 594f208 | 2015-08-18 11:04:20 -0700 | [diff] [blame] | 3149 | for (UserInfo user : users) { |
| 3150 | mRuntimePermissionsPersistence.deleteUserRuntimePermissionsFile(user.id); |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 3151 | } |
| 3152 | } |
| 3153 | } |
| 3154 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3155 | final int N = mPendingPackages.size(); |
dcashman | 8c04fac | 2015-03-23 11:39:42 -0700 | [diff] [blame] | 3156 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3157 | for (int i = 0; i < N; i++) { |
Todd Kennedy | 788c842 | 2016-08-10 10:52:34 -0700 | [diff] [blame] | 3158 | final PackageSetting p = mPendingPackages.get(i); |
| 3159 | final int sharedUserId = p.getSharedUserId(); |
| 3160 | final Object idObj = getUserIdLPr(sharedUserId); |
| 3161 | if (idObj instanceof SharedUserSetting) { |
| 3162 | final SharedUserSetting sharedUser = (SharedUserSetting) idObj; |
| 3163 | p.sharedUser = sharedUser; |
| 3164 | p.appId = sharedUser.userId; |
| 3165 | addPackageSettingLPw(p, sharedUser); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3166 | } else if (idObj != null) { |
Todd Kennedy | 788c842 | 2016-08-10 10:52:34 -0700 | [diff] [blame] | 3167 | String msg = "Bad package setting: package " + p.name + " has shared uid " |
| 3168 | + sharedUserId + " that is not a shared uid\n"; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3169 | mReadMessages.append(msg); |
| 3170 | PackageManagerService.reportSettingsProblem(Log.ERROR, msg); |
| 3171 | } else { |
Todd Kennedy | 788c842 | 2016-08-10 10:52:34 -0700 | [diff] [blame] | 3172 | String msg = "Bad package setting: package " + p.name + " has shared uid " |
| 3173 | + sharedUserId + " that is not defined\n"; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3174 | mReadMessages.append(msg); |
| 3175 | PackageManagerService.reportSettingsProblem(Log.ERROR, msg); |
| 3176 | } |
| 3177 | } |
| 3178 | mPendingPackages.clear(); |
| 3179 | |
Amith Yamasani | f031f23 | 2012-10-26 15:35:21 -0700 | [diff] [blame] | 3180 | if (mBackupStoppedPackagesFilename.exists() |
| 3181 | || mStoppedPackagesFilename.exists()) { |
| 3182 | // Read old file |
| 3183 | readStoppedLPw(); |
| 3184 | mBackupStoppedPackagesFilename.delete(); |
| 3185 | mStoppedPackagesFilename.delete(); |
| 3186 | // Migrate to new file format |
Xiaohui Chen | 594f208 | 2015-08-18 11:04:20 -0700 | [diff] [blame] | 3187 | writePackageRestrictionsLPr(UserHandle.USER_SYSTEM); |
Amith Yamasani | f031f23 | 2012-10-26 15:35:21 -0700 | [diff] [blame] | 3188 | } else { |
Xiaohui Chen | 594f208 | 2015-08-18 11:04:20 -0700 | [diff] [blame] | 3189 | for (UserInfo user : users) { |
| 3190 | readPackageRestrictionsLPr(user.id); |
Amith Yamasani | f031f23 | 2012-10-26 15:35:21 -0700 | [diff] [blame] | 3191 | } |
| 3192 | } |
| 3193 | |
Xiaohui Chen | 594f208 | 2015-08-18 11:04:20 -0700 | [diff] [blame] | 3194 | for (UserInfo user : users) { |
| 3195 | mRuntimePermissionsPersistence.readStateForUserSyncLPr(user.id); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 3196 | } |
| 3197 | |
Kenny Root | 1d1b489 | 2011-04-08 14:25:24 -0700 | [diff] [blame] | 3198 | /* |
| 3199 | * Make sure all the updated system packages have their shared users |
| 3200 | * associated with them. |
| 3201 | */ |
| 3202 | final Iterator<PackageSetting> disabledIt = mDisabledSysPackages.values().iterator(); |
| 3203 | while (disabledIt.hasNext()) { |
| 3204 | final PackageSetting disabledPs = disabledIt.next(); |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 3205 | final Object id = getUserIdLPr(disabledPs.appId); |
Kenny Root | 1d1b489 | 2011-04-08 14:25:24 -0700 | [diff] [blame] | 3206 | if (id != null && id instanceof SharedUserSetting) { |
| 3207 | disabledPs.sharedUser = (SharedUserSetting) id; |
| 3208 | } |
| 3209 | } |
| 3210 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3211 | mReadMessages.append("Read completed successfully: " + mPackages.size() + " packages, " |
| 3212 | + mSharedUsers.size() + " shared uids\n"); |
| 3213 | |
Jeff Sharkey | 2271ba3 | 2016-02-01 17:57:08 -0700 | [diff] [blame] | 3214 | writeKernelMappingLPr(); |
| 3215 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3216 | return true; |
| 3217 | } |
| 3218 | |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 3219 | void applyDefaultPreferredAppsLPw(int userId) { |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3220 | // First pull data from any pre-installed apps. |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 3221 | final PackageManagerInternal pmInternal = |
| 3222 | LocalServices.getService(PackageManagerInternal.class); |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3223 | for (PackageSetting ps : mPackages.values()) { |
| 3224 | if ((ps.pkgFlags&ApplicationInfo.FLAG_SYSTEM) != 0 && ps.pkg != null |
| 3225 | && ps.pkg.preferredActivityFilters != null) { |
| 3226 | ArrayList<PackageParser.ActivityIntentInfo> intents |
| 3227 | = ps.pkg.preferredActivityFilters; |
| 3228 | for (int i=0; i<intents.size(); i++) { |
| 3229 | PackageParser.ActivityIntentInfo aii = intents.get(i); |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 3230 | applyDefaultPreferredActivityLPw(pmInternal, aii, new ComponentName( |
| 3231 | ps.name, aii.activity.className), userId); |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3232 | } |
| 3233 | } |
| 3234 | } |
| 3235 | |
Dianne Hackborn | fc8b7fe | 2012-06-18 15:38:12 -0700 | [diff] [blame] | 3236 | // Read preferred apps from .../etc/preferred-apps directory. |
| 3237 | File preferredDir = new File(Environment.getRootDirectory(), "etc/preferred-apps"); |
| 3238 | if (!preferredDir.exists() || !preferredDir.isDirectory()) { |
| 3239 | return; |
| 3240 | } |
| 3241 | if (!preferredDir.canRead()) { |
| 3242 | Slog.w(TAG, "Directory " + preferredDir + " cannot be read"); |
| 3243 | return; |
| 3244 | } |
| 3245 | |
| 3246 | // Iterate over the files in the directory and scan .xml files |
| 3247 | for (File f : preferredDir.listFiles()) { |
| 3248 | if (!f.getPath().endsWith(".xml")) { |
| 3249 | Slog.i(TAG, "Non-xml file " + f + " in " + preferredDir + " directory, ignoring"); |
| 3250 | continue; |
| 3251 | } |
| 3252 | if (!f.canRead()) { |
| 3253 | Slog.w(TAG, "Preferred apps file " + f + " cannot be read"); |
| 3254 | continue; |
| 3255 | } |
| 3256 | |
Dianne Hackborn | 8a2ed1d | 2013-01-29 15:18:29 -0800 | [diff] [blame] | 3257 | if (PackageManagerService.DEBUG_PREFERRED) Log.d(TAG, "Reading default preferred " + f); |
Fyodor Kupolov | b35b34c | 2015-12-17 14:16:51 -0800 | [diff] [blame] | 3258 | InputStream str = null; |
Dianne Hackborn | fc8b7fe | 2012-06-18 15:38:12 -0700 | [diff] [blame] | 3259 | try { |
Fyodor Kupolov | b35b34c | 2015-12-17 14:16:51 -0800 | [diff] [blame] | 3260 | str = new BufferedInputStream(new FileInputStream(f)); |
Dianne Hackborn | fc8b7fe | 2012-06-18 15:38:12 -0700 | [diff] [blame] | 3261 | XmlPullParser parser = Xml.newPullParser(); |
| 3262 | parser.setInput(str, null); |
| 3263 | |
| 3264 | int type; |
| 3265 | while ((type = parser.next()) != XmlPullParser.START_TAG |
| 3266 | && type != XmlPullParser.END_DOCUMENT) { |
| 3267 | ; |
| 3268 | } |
| 3269 | |
| 3270 | if (type != XmlPullParser.START_TAG) { |
| 3271 | Slog.w(TAG, "Preferred apps file " + f + " does not have start tag"); |
| 3272 | continue; |
| 3273 | } |
| 3274 | if (!"preferred-activities".equals(parser.getName())) { |
| 3275 | Slog.w(TAG, "Preferred apps file " + f |
| 3276 | + " does not start with 'preferred-activities'"); |
| 3277 | continue; |
| 3278 | } |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 3279 | readDefaultPreferredActivitiesLPw(parser, userId); |
Dianne Hackborn | fc8b7fe | 2012-06-18 15:38:12 -0700 | [diff] [blame] | 3280 | } catch (XmlPullParserException e) { |
| 3281 | Slog.w(TAG, "Error reading apps file " + f, e); |
| 3282 | } catch (IOException e) { |
| 3283 | Slog.w(TAG, "Error reading apps file " + f, e); |
| 3284 | } finally { |
| 3285 | if (str != null) { |
| 3286 | try { |
| 3287 | str.close(); |
| 3288 | } catch (IOException e) { |
| 3289 | } |
| 3290 | } |
| 3291 | } |
| 3292 | } |
| 3293 | } |
| 3294 | |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 3295 | private void applyDefaultPreferredActivityLPw( |
| 3296 | PackageManagerInternal pmInternal, IntentFilter tmpPa, ComponentName cn, int userId) { |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3297 | // The initial preferences only specify the target activity |
| 3298 | // component and intent-filter, not the set of matches. So we |
| 3299 | // now need to query for the matches to build the correct |
| 3300 | // preferred activity entry. |
| 3301 | if (PackageManagerService.DEBUG_PREFERRED) { |
| 3302 | Log.d(TAG, "Processing preferred:"); |
| 3303 | tmpPa.dump(new LogPrinter(Log.DEBUG, TAG), " "); |
| 3304 | } |
| 3305 | Intent intent = new Intent(); |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 3306 | int flags = PackageManager.MATCH_DIRECT_BOOT_AWARE |
| 3307 | | PackageManager.MATCH_DIRECT_BOOT_UNAWARE; |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3308 | intent.setAction(tmpPa.getAction(0)); |
| 3309 | for (int i=0; i<tmpPa.countCategories(); i++) { |
| 3310 | String cat = tmpPa.getCategory(i); |
| 3311 | if (cat.equals(Intent.CATEGORY_DEFAULT)) { |
Jeff Sharkey | 2a90f673 | 2016-01-06 12:26:11 -0700 | [diff] [blame] | 3312 | flags |= MATCH_DEFAULT_ONLY; |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3313 | } else { |
| 3314 | intent.addCategory(cat); |
| 3315 | } |
| 3316 | } |
| 3317 | |
| 3318 | boolean doNonData = true; |
Christopher Tate | 2298ef2 | 2013-11-04 17:02:10 -0800 | [diff] [blame] | 3319 | boolean hasSchemes = false; |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3320 | |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 3321 | final int dataSchemesCount = tmpPa.countDataSchemes(); |
| 3322 | for (int ischeme = 0; ischeme < dataSchemesCount; ischeme++) { |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3323 | boolean doScheme = true; |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 3324 | final String scheme = tmpPa.getDataScheme(ischeme); |
Christopher Tate | 2298ef2 | 2013-11-04 17:02:10 -0800 | [diff] [blame] | 3325 | if (scheme != null && !scheme.isEmpty()) { |
| 3326 | hasSchemes = true; |
| 3327 | } |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 3328 | final int dataSchemeSpecificPartsCount = tmpPa.countDataSchemeSpecificParts(); |
| 3329 | for (int issp = 0; issp < dataSchemeSpecificPartsCount; issp++) { |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3330 | Uri.Builder builder = new Uri.Builder(); |
| 3331 | builder.scheme(scheme); |
| 3332 | PatternMatcher ssp = tmpPa.getDataSchemeSpecificPart(issp); |
| 3333 | builder.opaquePart(ssp.getPath()); |
| 3334 | Intent finalIntent = new Intent(intent); |
| 3335 | finalIntent.setData(builder.build()); |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 3336 | applyDefaultPreferredActivityLPw(pmInternal, finalIntent, flags, cn, |
Dianne Hackborn | eeb2c7e | 2014-09-23 16:45:39 -0700 | [diff] [blame] | 3337 | scheme, ssp, null, null, userId); |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3338 | doScheme = false; |
| 3339 | } |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 3340 | final int dataAuthoritiesCount = tmpPa.countDataAuthorities(); |
| 3341 | for (int iauth = 0; iauth < dataAuthoritiesCount; iauth++) { |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3342 | boolean doAuth = true; |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 3343 | final IntentFilter.AuthorityEntry auth = tmpPa.getDataAuthority(iauth); |
| 3344 | final int dataPathsCount = tmpPa.countDataPaths(); |
| 3345 | for (int ipath = 0; ipath < dataPathsCount; ipath++) { |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3346 | Uri.Builder builder = new Uri.Builder(); |
| 3347 | builder.scheme(scheme); |
| 3348 | if (auth.getHost() != null) { |
| 3349 | builder.authority(auth.getHost()); |
| 3350 | } |
| 3351 | PatternMatcher path = tmpPa.getDataPath(ipath); |
| 3352 | builder.path(path.getPath()); |
| 3353 | Intent finalIntent = new Intent(intent); |
| 3354 | finalIntent.setData(builder.build()); |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 3355 | applyDefaultPreferredActivityLPw(pmInternal, finalIntent, flags, cn, |
Dianne Hackborn | eeb2c7e | 2014-09-23 16:45:39 -0700 | [diff] [blame] | 3356 | scheme, null, auth, path, userId); |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3357 | doAuth = doScheme = false; |
| 3358 | } |
| 3359 | if (doAuth) { |
| 3360 | Uri.Builder builder = new Uri.Builder(); |
| 3361 | builder.scheme(scheme); |
| 3362 | if (auth.getHost() != null) { |
| 3363 | builder.authority(auth.getHost()); |
| 3364 | } |
| 3365 | Intent finalIntent = new Intent(intent); |
| 3366 | finalIntent.setData(builder.build()); |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 3367 | applyDefaultPreferredActivityLPw(pmInternal, finalIntent, flags, cn, |
Dianne Hackborn | eeb2c7e | 2014-09-23 16:45:39 -0700 | [diff] [blame] | 3368 | scheme, null, auth, null, userId); |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3369 | doScheme = false; |
| 3370 | } |
| 3371 | } |
| 3372 | if (doScheme) { |
| 3373 | Uri.Builder builder = new Uri.Builder(); |
| 3374 | builder.scheme(scheme); |
| 3375 | Intent finalIntent = new Intent(intent); |
| 3376 | finalIntent.setData(builder.build()); |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 3377 | applyDefaultPreferredActivityLPw(pmInternal, finalIntent, flags, cn, |
Dianne Hackborn | eeb2c7e | 2014-09-23 16:45:39 -0700 | [diff] [blame] | 3378 | scheme, null, null, null, userId); |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3379 | } |
| 3380 | doNonData = false; |
| 3381 | } |
| 3382 | |
| 3383 | for (int idata=0; idata<tmpPa.countDataTypes(); idata++) { |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3384 | String mimeType = tmpPa.getDataType(idata); |
Christopher Tate | 2298ef2 | 2013-11-04 17:02:10 -0800 | [diff] [blame] | 3385 | if (hasSchemes) { |
| 3386 | Uri.Builder builder = new Uri.Builder(); |
| 3387 | for (int ischeme=0; ischeme<tmpPa.countDataSchemes(); ischeme++) { |
| 3388 | String scheme = tmpPa.getDataScheme(ischeme); |
| 3389 | if (scheme != null && !scheme.isEmpty()) { |
| 3390 | Intent finalIntent = new Intent(intent); |
| 3391 | builder.scheme(scheme); |
| 3392 | finalIntent.setDataAndType(builder.build(), mimeType); |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 3393 | applyDefaultPreferredActivityLPw(pmInternal, finalIntent, flags, cn, |
Dianne Hackborn | eeb2c7e | 2014-09-23 16:45:39 -0700 | [diff] [blame] | 3394 | scheme, null, null, null, userId); |
Christopher Tate | 2298ef2 | 2013-11-04 17:02:10 -0800 | [diff] [blame] | 3395 | } |
| 3396 | } |
| 3397 | } else { |
| 3398 | Intent finalIntent = new Intent(intent); |
| 3399 | finalIntent.setType(mimeType); |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 3400 | applyDefaultPreferredActivityLPw(pmInternal, finalIntent, flags, cn, |
Dianne Hackborn | eeb2c7e | 2014-09-23 16:45:39 -0700 | [diff] [blame] | 3401 | null, null, null, null, userId); |
Christopher Tate | 2298ef2 | 2013-11-04 17:02:10 -0800 | [diff] [blame] | 3402 | } |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3403 | doNonData = false; |
| 3404 | } |
| 3405 | |
| 3406 | if (doNonData) { |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 3407 | applyDefaultPreferredActivityLPw(pmInternal, intent, flags, cn, |
Dianne Hackborn | eeb2c7e | 2014-09-23 16:45:39 -0700 | [diff] [blame] | 3408 | null, null, null, null, userId); |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3409 | } |
| 3410 | } |
| 3411 | |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 3412 | private void applyDefaultPreferredActivityLPw(PackageManagerInternal pmInternal, Intent intent, |
| 3413 | int flags, ComponentName cn, String scheme, PatternMatcher ssp, |
Dianne Hackborn | eeb2c7e | 2014-09-23 16:45:39 -0700 | [diff] [blame] | 3414 | IntentFilter.AuthorityEntry auth, PatternMatcher path, int userId) { |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 3415 | final List<ResolveInfo> ri = |
| 3416 | pmInternal.queryIntentActivities(intent, flags, Binder.getCallingUid(), 0); |
| 3417 | if (PackageManagerService.DEBUG_PREFERRED) { |
| 3418 | Log.d(TAG, "Queried " + intent + " results: " + ri); |
| 3419 | } |
Dianne Hackborn | f85e7af | 2014-10-14 10:43:43 -0700 | [diff] [blame] | 3420 | int systemMatch = 0; |
| 3421 | int thirdPartyMatch = 0; |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 3422 | final int numMatches = (ri == null ? 0 : ri.size()); |
| 3423 | if (numMatches <= 1) { |
| 3424 | Slog.w(TAG, "No potential matches found for " + intent |
| 3425 | + " while setting preferred " + cn.flattenToShortString()); |
| 3426 | return; |
| 3427 | } |
| 3428 | boolean haveAct = false; |
| 3429 | ComponentName haveNonSys = null; |
| 3430 | ComponentName[] set = new ComponentName[ri.size()]; |
| 3431 | for (int i = 0; i < numMatches; i++) { |
| 3432 | final ActivityInfo ai = ri.get(i).activityInfo; |
| 3433 | set[i] = new ComponentName(ai.packageName, ai.name); |
| 3434 | if ((ai.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) { |
| 3435 | if (ri.get(i).match >= thirdPartyMatch) { |
| 3436 | // Keep track of the best match we find of all third |
| 3437 | // party apps, for use later to determine if we actually |
| 3438 | // want to set a preferred app for this intent. |
| 3439 | if (PackageManagerService.DEBUG_PREFERRED) { |
| 3440 | Log.d(TAG, "Result " + ai.packageName + "/" + ai.name + ": non-system!"); |
Dianne Hackborn | eeb2c7e | 2014-09-23 16:45:39 -0700 | [diff] [blame] | 3441 | } |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 3442 | haveNonSys = set[i]; |
| 3443 | break; |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3444 | } |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 3445 | } else if (cn.getPackageName().equals(ai.packageName) |
| 3446 | && cn.getClassName().equals(ai.name)) { |
| 3447 | if (PackageManagerService.DEBUG_PREFERRED) { |
| 3448 | Log.d(TAG, "Result " + ai.packageName + "/" + ai.name + ": default!"); |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3449 | } |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 3450 | haveAct = true; |
| 3451 | systemMatch = ri.get(i).match; |
Dianne Hackborn | eeb2c7e | 2014-09-23 16:45:39 -0700 | [diff] [blame] | 3452 | } else { |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 3453 | if (PackageManagerService.DEBUG_PREFERRED) { |
| 3454 | Log.d(TAG, "Result " + ai.packageName + "/" + ai.name + ": skipped"); |
| 3455 | } |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3456 | } |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 3457 | } |
| 3458 | if (haveNonSys != null && thirdPartyMatch < systemMatch) { |
| 3459 | // If we have a matching third party app, but its match is not as |
| 3460 | // good as the built-in system app, then we don't want to actually |
| 3461 | // consider it a match because presumably the built-in app is still |
| 3462 | // the thing we want users to see by default. |
| 3463 | haveNonSys = null; |
| 3464 | } |
| 3465 | if (haveAct && haveNonSys == null) { |
| 3466 | IntentFilter filter = new IntentFilter(); |
| 3467 | if (intent.getAction() != null) { |
| 3468 | filter.addAction(intent.getAction()); |
| 3469 | } |
| 3470 | if (intent.getCategories() != null) { |
| 3471 | for (String cat : intent.getCategories()) { |
| 3472 | filter.addCategory(cat); |
| 3473 | } |
| 3474 | } |
| 3475 | if ((flags & MATCH_DEFAULT_ONLY) != 0) { |
| 3476 | filter.addCategory(Intent.CATEGORY_DEFAULT); |
| 3477 | } |
| 3478 | if (scheme != null) { |
| 3479 | filter.addDataScheme(scheme); |
| 3480 | } |
| 3481 | if (ssp != null) { |
| 3482 | filter.addDataSchemeSpecificPart(ssp.getPath(), ssp.getType()); |
| 3483 | } |
| 3484 | if (auth != null) { |
| 3485 | filter.addDataAuthority(auth); |
| 3486 | } |
| 3487 | if (path != null) { |
| 3488 | filter.addDataPath(path); |
| 3489 | } |
| 3490 | if (intent.getType() != null) { |
| 3491 | try { |
| 3492 | filter.addDataType(intent.getType()); |
| 3493 | } catch (IntentFilter.MalformedMimeTypeException ex) { |
| 3494 | Slog.w(TAG, "Malformed mimetype " + intent.getType() + " for " + cn); |
| 3495 | } |
| 3496 | } |
| 3497 | PreferredActivity pa = new PreferredActivity(filter, systemMatch, set, cn, true); |
| 3498 | editPreferredActivitiesLPw(userId).addFilter(pa); |
| 3499 | } else if (haveNonSys == null) { |
| 3500 | StringBuilder sb = new StringBuilder(); |
| 3501 | sb.append("No component "); |
| 3502 | sb.append(cn.flattenToShortString()); |
| 3503 | sb.append(" found setting preferred "); |
| 3504 | sb.append(intent); |
| 3505 | sb.append("; possible matches are "); |
| 3506 | for (int i = 0; i < set.length; i++) { |
| 3507 | if (i > 0) sb.append(", "); |
| 3508 | sb.append(set[i].flattenToShortString()); |
| 3509 | } |
| 3510 | Slog.w(TAG, sb.toString()); |
Dianne Hackborn | eeb2c7e | 2014-09-23 16:45:39 -0700 | [diff] [blame] | 3511 | } else { |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 3512 | Slog.i(TAG, "Not setting preferred " + intent + "; found third party match " |
| 3513 | + haveNonSys.flattenToShortString()); |
Dianne Hackborn | b09491f | 2013-07-22 15:30:11 -0700 | [diff] [blame] | 3514 | } |
| 3515 | } |
| 3516 | |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 3517 | private void readDefaultPreferredActivitiesLPw(XmlPullParser parser, int userId) |
Dianne Hackborn | 8a2ed1d | 2013-01-29 15:18:29 -0800 | [diff] [blame] | 3518 | throws XmlPullParserException, IOException { |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 3519 | final PackageManagerInternal pmInternal = |
| 3520 | LocalServices.getService(PackageManagerInternal.class); |
Dianne Hackborn | 8a2ed1d | 2013-01-29 15:18:29 -0800 | [diff] [blame] | 3521 | int outerDepth = parser.getDepth(); |
| 3522 | int type; |
| 3523 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 3524 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 3525 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 3526 | continue; |
| 3527 | } |
| 3528 | |
| 3529 | String tagName = parser.getName(); |
| 3530 | if (tagName.equals(TAG_ITEM)) { |
| 3531 | PreferredActivity tmpPa = new PreferredActivity(parser); |
| 3532 | if (tmpPa.mPref.getParseError() == null) { |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 3533 | applyDefaultPreferredActivityLPw( |
| 3534 | pmInternal, tmpPa, tmpPa.mPref.mComponent, userId); |
Dianne Hackborn | 8a2ed1d | 2013-01-29 15:18:29 -0800 | [diff] [blame] | 3535 | } else { |
| 3536 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 3537 | "Error in package manager settings: <preferred-activity> " |
| 3538 | + tmpPa.mPref.getParseError() + " at " |
| 3539 | + parser.getPositionDescription()); |
| 3540 | } |
| 3541 | } else { |
| 3542 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 3543 | "Unknown element under <preferred-activities>: " + parser.getName()); |
| 3544 | XmlUtils.skipCurrentTag(parser); |
| 3545 | } |
| 3546 | } |
| 3547 | } |
| 3548 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 3549 | private void readDisabledSysPackageLPw(XmlPullParser parser) throws XmlPullParserException, |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3550 | IOException { |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 3551 | String name = parser.getAttributeValue(null, ATTR_NAME); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3552 | String realName = parser.getAttributeValue(null, "realName"); |
| 3553 | String codePathStr = parser.getAttributeValue(null, "codePath"); |
| 3554 | String resourcePathStr = parser.getAttributeValue(null, "resourcePath"); |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 3555 | |
| 3556 | String legacyCpuAbiStr = parser.getAttributeValue(null, "requiredCpuAbi"); |
| 3557 | String legacyNativeLibraryPathStr = parser.getAttributeValue(null, "nativeLibraryPath"); |
| 3558 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3559 | String parentPackageName = parser.getAttributeValue(null, "parentPackageName"); |
| 3560 | |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 3561 | String primaryCpuAbiStr = parser.getAttributeValue(null, "primaryCpuAbi"); |
| 3562 | String secondaryCpuAbiStr = parser.getAttributeValue(null, "secondaryCpuAbi"); |
Narayan Kamath | 4903f64 | 2014-08-11 13:33:45 +0100 | [diff] [blame] | 3563 | String cpuAbiOverrideStr = parser.getAttributeValue(null, "cpuAbiOverride"); |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 3564 | |
| 3565 | if (primaryCpuAbiStr == null && legacyCpuAbiStr != null) { |
| 3566 | primaryCpuAbiStr = legacyCpuAbiStr; |
| 3567 | } |
Narayan Kamath | 9e289d7 | 2014-04-10 09:26:59 +0000 | [diff] [blame] | 3568 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3569 | if (resourcePathStr == null) { |
| 3570 | resourcePathStr = codePathStr; |
| 3571 | } |
| 3572 | String version = parser.getAttributeValue(null, "version"); |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 3573 | long versionCode = 0; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3574 | if (version != null) { |
| 3575 | try { |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 3576 | versionCode = Long.parseLong(version); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3577 | } catch (NumberFormatException e) { |
| 3578 | } |
| 3579 | } |
| 3580 | |
| 3581 | int pkgFlags = 0; |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 3582 | int pkgPrivateFlags = 0; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3583 | pkgFlags |= ApplicationInfo.FLAG_SYSTEM; |
Todd Kennedy | ddaaf4c | 2017-11-07 10:01:25 -0800 | [diff] [blame] | 3584 | if (PackageManagerService.locationIsPrivileged(codePathStr)) { |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 3585 | pkgPrivateFlags |= ApplicationInfo.PRIVATE_FLAG_PRIVILEGED; |
Christopher Tate | 628946a | 2013-10-18 18:11:05 -0700 | [diff] [blame] | 3586 | } |
Todd Kennedy | ddaaf4c | 2017-11-07 10:01:25 -0800 | [diff] [blame] | 3587 | PackageSetting ps = new PackageSetting(name, realName, new File(codePathStr), |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 3588 | new File(resourcePathStr), legacyNativeLibraryPathStr, primaryCpuAbiStr, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3589 | secondaryCpuAbiStr, cpuAbiOverrideStr, versionCode, pkgFlags, pkgPrivateFlags, |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 3590 | parentPackageName, null /*childPackageNames*/, 0 /*sharedUserId*/, null, null); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3591 | String timeStampStr = parser.getAttributeValue(null, "ft"); |
| 3592 | if (timeStampStr != null) { |
| 3593 | try { |
| 3594 | long timeStamp = Long.parseLong(timeStampStr, 16); |
| 3595 | ps.setTimeStamp(timeStamp); |
| 3596 | } catch (NumberFormatException e) { |
| 3597 | } |
| 3598 | } else { |
| 3599 | timeStampStr = parser.getAttributeValue(null, "ts"); |
| 3600 | if (timeStampStr != null) { |
| 3601 | try { |
| 3602 | long timeStamp = Long.parseLong(timeStampStr); |
| 3603 | ps.setTimeStamp(timeStamp); |
| 3604 | } catch (NumberFormatException e) { |
| 3605 | } |
| 3606 | } |
| 3607 | } |
| 3608 | timeStampStr = parser.getAttributeValue(null, "it"); |
| 3609 | if (timeStampStr != null) { |
| 3610 | try { |
| 3611 | ps.firstInstallTime = Long.parseLong(timeStampStr, 16); |
| 3612 | } catch (NumberFormatException e) { |
| 3613 | } |
| 3614 | } |
| 3615 | timeStampStr = parser.getAttributeValue(null, "ut"); |
| 3616 | if (timeStampStr != null) { |
| 3617 | try { |
| 3618 | ps.lastUpdateTime = Long.parseLong(timeStampStr, 16); |
| 3619 | } catch (NumberFormatException e) { |
| 3620 | } |
| 3621 | } |
| 3622 | String idStr = parser.getAttributeValue(null, "userId"); |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 3623 | ps.appId = idStr != null ? Integer.parseInt(idStr) : 0; |
| 3624 | if (ps.appId <= 0) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3625 | String sharedIdStr = parser.getAttributeValue(null, "sharedUserId"); |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 3626 | ps.appId = sharedIdStr != null ? Integer.parseInt(sharedIdStr) : 0; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3627 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 3628 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3629 | int outerDepth = parser.getDepth(); |
| 3630 | int type; |
| 3631 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 3632 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 3633 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 3634 | continue; |
| 3635 | } |
| 3636 | |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 3637 | if (parser.getName().equals(TAG_PERMISSIONS)) { |
| 3638 | readInstallPermissionsLPr(parser, ps.getPermissionsState()); |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3639 | } else if (parser.getName().equals(TAG_CHILD_PACKAGE)) { |
| 3640 | String childPackageName = parser.getAttributeValue(null, ATTR_NAME); |
| 3641 | if (ps.childPackageNames == null) { |
| 3642 | ps.childPackageNames = new ArrayList<>(); |
| 3643 | } |
| 3644 | ps.childPackageNames.add(childPackageName); |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 3645 | } else if (parser.getName().equals(TAG_USES_STATIC_LIB)) { |
| 3646 | readUsesStaticLibLPw(parser, ps); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3647 | } else { |
| 3648 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 3649 | "Unknown element under <updated-package>: " + parser.getName()); |
| 3650 | XmlUtils.skipCurrentTag(parser); |
| 3651 | } |
| 3652 | } |
Christopher Tate | 628946a | 2013-10-18 18:11:05 -0700 | [diff] [blame] | 3653 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3654 | mDisabledSysPackages.put(name, ps); |
| 3655 | } |
| 3656 | |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 3657 | private static int PRE_M_APP_INFO_FLAG_HIDDEN = 1<<27; |
| 3658 | private static int PRE_M_APP_INFO_FLAG_CANT_SAVE_STATE = 1<<28; |
| 3659 | private static int PRE_M_APP_INFO_FLAG_FORWARD_LOCK = 1<<29; |
| 3660 | private static int PRE_M_APP_INFO_FLAG_PRIVILEGED = 1<<30; |
| 3661 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 3662 | private void readPackageLPw(XmlPullParser parser) throws XmlPullParserException, IOException { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3663 | String name = null; |
| 3664 | String realName = null; |
| 3665 | String idStr = null; |
| 3666 | String sharedIdStr = null; |
| 3667 | String codePathStr = null; |
| 3668 | String resourcePathStr = null; |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 3669 | String legacyCpuAbiString = null; |
| 3670 | String legacyNativeLibraryPathStr = null; |
| 3671 | String primaryCpuAbiString = null; |
| 3672 | String secondaryCpuAbiString = null; |
Narayan Kamath | 4903f64 | 2014-08-11 13:33:45 +0100 | [diff] [blame] | 3673 | String cpuAbiOverrideString = null; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3674 | String systemStr = null; |
| 3675 | String installerPackageName = null; |
Sudheer Shanka | 8c57aea | 2016-04-20 16:47:50 -0700 | [diff] [blame] | 3676 | String isOrphaned = null; |
Jeff Sharkey | b2b9ab8 | 2015-04-05 21:10:42 -0700 | [diff] [blame] | 3677 | String volumeUuid = null; |
Jeff Sharkey | 9bc89af | 2017-01-11 11:25:50 -0700 | [diff] [blame] | 3678 | String categoryHintString = null; |
Todd Kennedy | ab53289 | 2017-03-08 14:19:49 -0800 | [diff] [blame] | 3679 | String updateAvailable = null; |
Jeff Sharkey | 9bc89af | 2017-01-11 11:25:50 -0700 | [diff] [blame] | 3680 | int categoryHint = ApplicationInfo.CATEGORY_UNDEFINED; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3681 | String uidError = null; |
| 3682 | int pkgFlags = 0; |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 3683 | int pkgPrivateFlags = 0; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3684 | long timeStamp = 0; |
| 3685 | long firstInstallTime = 0; |
| 3686 | long lastUpdateTime = 0; |
Todd Kennedy | 788c842 | 2016-08-10 10:52:34 -0700 | [diff] [blame] | 3687 | PackageSetting packageSetting = null; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3688 | String version = null; |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 3689 | long versionCode = 0; |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3690 | String parentPackageName; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3691 | try { |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 3692 | name = parser.getAttributeValue(null, ATTR_NAME); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3693 | realName = parser.getAttributeValue(null, "realName"); |
| 3694 | idStr = parser.getAttributeValue(null, "userId"); |
| 3695 | uidError = parser.getAttributeValue(null, "uidError"); |
| 3696 | sharedIdStr = parser.getAttributeValue(null, "sharedUserId"); |
| 3697 | codePathStr = parser.getAttributeValue(null, "codePath"); |
| 3698 | resourcePathStr = parser.getAttributeValue(null, "resourcePath"); |
Narayan Kamath | 9e289d7 | 2014-04-10 09:26:59 +0000 | [diff] [blame] | 3699 | |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 3700 | legacyCpuAbiString = parser.getAttributeValue(null, "requiredCpuAbi"); |
| 3701 | |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3702 | parentPackageName = parser.getAttributeValue(null, "parentPackageName"); |
| 3703 | |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 3704 | legacyNativeLibraryPathStr = parser.getAttributeValue(null, "nativeLibraryPath"); |
| 3705 | primaryCpuAbiString = parser.getAttributeValue(null, "primaryCpuAbi"); |
| 3706 | secondaryCpuAbiString = parser.getAttributeValue(null, "secondaryCpuAbi"); |
Narayan Kamath | 4903f64 | 2014-08-11 13:33:45 +0100 | [diff] [blame] | 3707 | cpuAbiOverrideString = parser.getAttributeValue(null, "cpuAbiOverride"); |
Todd Kennedy | ab53289 | 2017-03-08 14:19:49 -0800 | [diff] [blame] | 3708 | updateAvailable = parser.getAttributeValue(null, "updateAvailable"); |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 3709 | |
| 3710 | if (primaryCpuAbiString == null && legacyCpuAbiString != null) { |
| 3711 | primaryCpuAbiString = legacyCpuAbiString; |
| 3712 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 3713 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3714 | version = parser.getAttributeValue(null, "version"); |
| 3715 | if (version != null) { |
| 3716 | try { |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 3717 | versionCode = Long.parseLong(version); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3718 | } catch (NumberFormatException e) { |
| 3719 | } |
| 3720 | } |
| 3721 | installerPackageName = parser.getAttributeValue(null, "installer"); |
Sudheer Shanka | 8c57aea | 2016-04-20 16:47:50 -0700 | [diff] [blame] | 3722 | isOrphaned = parser.getAttributeValue(null, "isOrphaned"); |
Jeff Sharkey | b2b9ab8 | 2015-04-05 21:10:42 -0700 | [diff] [blame] | 3723 | volumeUuid = parser.getAttributeValue(null, "volumeUuid"); |
Jeff Sharkey | 9bc89af | 2017-01-11 11:25:50 -0700 | [diff] [blame] | 3724 | categoryHintString = parser.getAttributeValue(null, "categoryHint"); |
| 3725 | if (categoryHintString != null) { |
| 3726 | try { |
| 3727 | categoryHint = Integer.parseInt(categoryHintString); |
| 3728 | } catch (NumberFormatException e) { |
| 3729 | } |
| 3730 | } |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3731 | |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 3732 | systemStr = parser.getAttributeValue(null, "publicFlags"); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3733 | if (systemStr != null) { |
| 3734 | try { |
| 3735 | pkgFlags = Integer.parseInt(systemStr); |
| 3736 | } catch (NumberFormatException e) { |
| 3737 | } |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 3738 | systemStr = parser.getAttributeValue(null, "privateFlags"); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3739 | if (systemStr != null) { |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 3740 | try { |
| 3741 | pkgPrivateFlags = Integer.parseInt(systemStr); |
| 3742 | } catch (NumberFormatException e) { |
| 3743 | } |
| 3744 | } |
| 3745 | } else { |
| 3746 | // Pre-M -- both public and private flags were stored in one "flags" field. |
| 3747 | systemStr = parser.getAttributeValue(null, "flags"); |
| 3748 | if (systemStr != null) { |
| 3749 | try { |
| 3750 | pkgFlags = Integer.parseInt(systemStr); |
| 3751 | } catch (NumberFormatException e) { |
| 3752 | } |
| 3753 | if ((pkgFlags & PRE_M_APP_INFO_FLAG_HIDDEN) != 0) { |
| 3754 | pkgPrivateFlags |= ApplicationInfo.PRIVATE_FLAG_HIDDEN; |
| 3755 | } |
| 3756 | if ((pkgFlags & PRE_M_APP_INFO_FLAG_CANT_SAVE_STATE) != 0) { |
| 3757 | pkgPrivateFlags |= ApplicationInfo.PRIVATE_FLAG_CANT_SAVE_STATE; |
| 3758 | } |
| 3759 | if ((pkgFlags & PRE_M_APP_INFO_FLAG_FORWARD_LOCK) != 0) { |
| 3760 | pkgPrivateFlags |= ApplicationInfo.PRIVATE_FLAG_FORWARD_LOCK; |
| 3761 | } |
| 3762 | if ((pkgFlags & PRE_M_APP_INFO_FLAG_PRIVILEGED) != 0) { |
| 3763 | pkgPrivateFlags |= ApplicationInfo.PRIVATE_FLAG_PRIVILEGED; |
| 3764 | } |
| 3765 | pkgFlags &= ~(PRE_M_APP_INFO_FLAG_HIDDEN |
| 3766 | | PRE_M_APP_INFO_FLAG_CANT_SAVE_STATE |
| 3767 | | PRE_M_APP_INFO_FLAG_FORWARD_LOCK |
| 3768 | | PRE_M_APP_INFO_FLAG_PRIVILEGED); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3769 | } else { |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 3770 | // For backward compatibility |
| 3771 | systemStr = parser.getAttributeValue(null, "system"); |
| 3772 | if (systemStr != null) { |
| 3773 | pkgFlags |= ("true".equalsIgnoreCase(systemStr)) ? ApplicationInfo.FLAG_SYSTEM |
| 3774 | : 0; |
| 3775 | } else { |
| 3776 | // Old settings that don't specify system... just treat |
| 3777 | // them as system, good enough. |
| 3778 | pkgFlags |= ApplicationInfo.FLAG_SYSTEM; |
| 3779 | } |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3780 | } |
| 3781 | } |
| 3782 | String timeStampStr = parser.getAttributeValue(null, "ft"); |
| 3783 | if (timeStampStr != null) { |
| 3784 | try { |
| 3785 | timeStamp = Long.parseLong(timeStampStr, 16); |
| 3786 | } catch (NumberFormatException e) { |
| 3787 | } |
| 3788 | } else { |
| 3789 | timeStampStr = parser.getAttributeValue(null, "ts"); |
| 3790 | if (timeStampStr != null) { |
| 3791 | try { |
| 3792 | timeStamp = Long.parseLong(timeStampStr); |
| 3793 | } catch (NumberFormatException e) { |
| 3794 | } |
| 3795 | } |
| 3796 | } |
| 3797 | timeStampStr = parser.getAttributeValue(null, "it"); |
| 3798 | if (timeStampStr != null) { |
| 3799 | try { |
| 3800 | firstInstallTime = Long.parseLong(timeStampStr, 16); |
| 3801 | } catch (NumberFormatException e) { |
| 3802 | } |
| 3803 | } |
| 3804 | timeStampStr = parser.getAttributeValue(null, "ut"); |
| 3805 | if (timeStampStr != null) { |
| 3806 | try { |
| 3807 | lastUpdateTime = Long.parseLong(timeStampStr, 16); |
| 3808 | } catch (NumberFormatException e) { |
| 3809 | } |
| 3810 | } |
| 3811 | if (PackageManagerService.DEBUG_SETTINGS) |
| 3812 | Log.v(PackageManagerService.TAG, "Reading package: " + name + " userId=" + idStr |
| 3813 | + " sharedUserId=" + sharedIdStr); |
Todd Kennedy | 788c842 | 2016-08-10 10:52:34 -0700 | [diff] [blame] | 3814 | final int userId = idStr != null ? Integer.parseInt(idStr) : 0; |
| 3815 | final int sharedUserId = sharedIdStr != null ? Integer.parseInt(sharedIdStr) : 0; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3816 | if (resourcePathStr == null) { |
| 3817 | resourcePathStr = codePathStr; |
| 3818 | } |
| 3819 | if (realName != null) { |
| 3820 | realName = realName.intern(); |
| 3821 | } |
| 3822 | if (name == null) { |
| 3823 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 3824 | "Error in package manager settings: <package> has no name at " |
| 3825 | + parser.getPositionDescription()); |
| 3826 | } else if (codePathStr == null) { |
| 3827 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 3828 | "Error in package manager settings: <package> has no codePath at " |
| 3829 | + parser.getPositionDescription()); |
| 3830 | } else if (userId > 0) { |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 3831 | packageSetting = addPackageLPw(name.intern(), realName, new File(codePathStr), |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 3832 | new File(resourcePathStr), legacyNativeLibraryPathStr, primaryCpuAbiString, |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 3833 | secondaryCpuAbiString, cpuAbiOverrideString, userId, versionCode, pkgFlags, |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 3834 | pkgPrivateFlags, parentPackageName, null /*childPackageNames*/, |
| 3835 | null /*usesStaticLibraries*/, null /*usesStaticLibraryVersions*/); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3836 | if (PackageManagerService.DEBUG_SETTINGS) |
| 3837 | Log.i(PackageManagerService.TAG, "Reading package " + name + ": userId=" |
| 3838 | + userId + " pkg=" + packageSetting); |
| 3839 | if (packageSetting == null) { |
| 3840 | PackageManagerService.reportSettingsProblem(Log.ERROR, "Failure adding uid " |
| 3841 | + userId + " while parsing settings at " |
| 3842 | + parser.getPositionDescription()); |
| 3843 | } else { |
| 3844 | packageSetting.setTimeStamp(timeStamp); |
| 3845 | packageSetting.firstInstallTime = firstInstallTime; |
| 3846 | packageSetting.lastUpdateTime = lastUpdateTime; |
| 3847 | } |
| 3848 | } else if (sharedIdStr != null) { |
Todd Kennedy | 788c842 | 2016-08-10 10:52:34 -0700 | [diff] [blame] | 3849 | if (sharedUserId > 0) { |
| 3850 | packageSetting = new PackageSetting(name.intern(), realName, new File( |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 3851 | codePathStr), new File(resourcePathStr), legacyNativeLibraryPathStr, |
Narayan Kamath | 4903f64 | 2014-08-11 13:33:45 +0100 | [diff] [blame] | 3852 | primaryCpuAbiString, secondaryCpuAbiString, cpuAbiOverrideString, |
Todd Kennedy | 788c842 | 2016-08-10 10:52:34 -0700 | [diff] [blame] | 3853 | versionCode, pkgFlags, pkgPrivateFlags, parentPackageName, |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 3854 | null /*childPackageNames*/, sharedUserId, |
| 3855 | null /*usesStaticLibraries*/, null /*usesStaticLibraryVersions*/); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3856 | packageSetting.setTimeStamp(timeStamp); |
| 3857 | packageSetting.firstInstallTime = firstInstallTime; |
| 3858 | packageSetting.lastUpdateTime = lastUpdateTime; |
Todd Kennedy | 788c842 | 2016-08-10 10:52:34 -0700 | [diff] [blame] | 3859 | mPendingPackages.add(packageSetting); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3860 | if (PackageManagerService.DEBUG_SETTINGS) |
| 3861 | Log.i(PackageManagerService.TAG, "Reading package " + name |
Todd Kennedy | 788c842 | 2016-08-10 10:52:34 -0700 | [diff] [blame] | 3862 | + ": sharedUserId=" + sharedUserId + " pkg=" + packageSetting); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3863 | } else { |
| 3864 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 3865 | "Error in package manager settings: package " + name |
| 3866 | + " has bad sharedId " + sharedIdStr + " at " |
| 3867 | + parser.getPositionDescription()); |
| 3868 | } |
| 3869 | } else { |
| 3870 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 3871 | "Error in package manager settings: package " + name + " has bad userId " |
| 3872 | + idStr + " at " + parser.getPositionDescription()); |
| 3873 | } |
| 3874 | } catch (NumberFormatException e) { |
| 3875 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 3876 | "Error in package manager settings: package " + name + " has bad userId " |
| 3877 | + idStr + " at " + parser.getPositionDescription()); |
| 3878 | } |
| 3879 | if (packageSetting != null) { |
| 3880 | packageSetting.uidError = "true".equals(uidError); |
| 3881 | packageSetting.installerPackageName = installerPackageName; |
Sudheer Shanka | 8c57aea | 2016-04-20 16:47:50 -0700 | [diff] [blame] | 3882 | packageSetting.isOrphaned = "true".equals(isOrphaned); |
Jeff Sharkey | b2b9ab8 | 2015-04-05 21:10:42 -0700 | [diff] [blame] | 3883 | packageSetting.volumeUuid = volumeUuid; |
Jeff Sharkey | 9bc89af | 2017-01-11 11:25:50 -0700 | [diff] [blame] | 3884 | packageSetting.categoryHint = categoryHint; |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 3885 | packageSetting.legacyNativeLibraryPathString = legacyNativeLibraryPathStr; |
| 3886 | packageSetting.primaryCpuAbiString = primaryCpuAbiString; |
| 3887 | packageSetting.secondaryCpuAbiString = secondaryCpuAbiString; |
Todd Kennedy | ab53289 | 2017-03-08 14:19:49 -0800 | [diff] [blame] | 3888 | packageSetting.updateAvailable = "true".equals(updateAvailable); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 3889 | // Handle legacy string here for single-user mode |
| 3890 | final String enabledStr = parser.getAttributeValue(null, ATTR_ENABLED); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3891 | if (enabledStr != null) { |
Dianne Hackborn | b8f4000 | 2011-07-19 15:17:43 -0700 | [diff] [blame] | 3892 | try { |
Dianne Hackborn | 3fa3c28a | 2013-03-26 16:15:41 -0700 | [diff] [blame] | 3893 | packageSetting.setEnabled(Integer.parseInt(enabledStr), 0 /* userId */, null); |
Dianne Hackborn | b8f4000 | 2011-07-19 15:17:43 -0700 | [diff] [blame] | 3894 | } catch (NumberFormatException e) { |
| 3895 | if (enabledStr.equalsIgnoreCase("true")) { |
Dianne Hackborn | 3fa3c28a | 2013-03-26 16:15:41 -0700 | [diff] [blame] | 3896 | packageSetting.setEnabled(COMPONENT_ENABLED_STATE_ENABLED, 0, null); |
Dianne Hackborn | b8f4000 | 2011-07-19 15:17:43 -0700 | [diff] [blame] | 3897 | } else if (enabledStr.equalsIgnoreCase("false")) { |
Dianne Hackborn | 3fa3c28a | 2013-03-26 16:15:41 -0700 | [diff] [blame] | 3898 | packageSetting.setEnabled(COMPONENT_ENABLED_STATE_DISABLED, 0, null); |
Dianne Hackborn | b8f4000 | 2011-07-19 15:17:43 -0700 | [diff] [blame] | 3899 | } else if (enabledStr.equalsIgnoreCase("default")) { |
Dianne Hackborn | 3fa3c28a | 2013-03-26 16:15:41 -0700 | [diff] [blame] | 3900 | packageSetting.setEnabled(COMPONENT_ENABLED_STATE_DEFAULT, 0, null); |
Dianne Hackborn | b8f4000 | 2011-07-19 15:17:43 -0700 | [diff] [blame] | 3901 | } else { |
| 3902 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 3903 | "Error in package manager settings: package " + name |
| 3904 | + " has bad enabled value: " + idStr + " at " |
| 3905 | + parser.getPositionDescription()); |
| 3906 | } |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3907 | } |
| 3908 | } else { |
Dianne Hackborn | 3fa3c28a | 2013-03-26 16:15:41 -0700 | [diff] [blame] | 3909 | packageSetting.setEnabled(COMPONENT_ENABLED_STATE_DEFAULT, 0, null); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3910 | } |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 3911 | |
Sudheer Shanka | 2928337 | 2016-04-04 20:56:27 -0700 | [diff] [blame] | 3912 | if (installerPackageName != null) { |
| 3913 | mInstallerPackages.add(installerPackageName); |
| 3914 | } |
| 3915 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3916 | int outerDepth = parser.getDepth(); |
| 3917 | int type; |
| 3918 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 3919 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 3920 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 3921 | continue; |
| 3922 | } |
| 3923 | |
| 3924 | String tagName = parser.getName(); |
Selim Gurun | 5c8acb4 | 2016-04-07 16:34:02 -0700 | [diff] [blame] | 3925 | // Legacy |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 3926 | if (tagName.equals(TAG_DISABLED_COMPONENTS)) { |
| 3927 | readDisabledComponentsLPw(packageSetting, parser, 0); |
| 3928 | } else if (tagName.equals(TAG_ENABLED_COMPONENTS)) { |
| 3929 | readEnabledComponentsLPw(packageSetting, parser, 0); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3930 | } else if (tagName.equals("sigs")) { |
| 3931 | packageSetting.signatures.readXml(parser, mPastSignatures); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 3932 | } else if (tagName.equals(TAG_PERMISSIONS)) { |
| 3933 | readInstallPermissionsLPr(parser, |
| 3934 | packageSetting.getPermissionsState()); |
Svetoslav | cf959f6 | 2015-03-26 20:53:34 -0700 | [diff] [blame] | 3935 | packageSetting.installPermissionsFixed = true; |
dcashman | 3a0dbfb | 2014-07-07 13:53:36 -0700 | [diff] [blame] | 3936 | } else if (tagName.equals("proper-signing-keyset")) { |
| 3937 | long id = Long.parseLong(parser.getAttributeValue(null, "identifier")); |
dcashman | 8c04fac | 2015-03-23 11:39:42 -0700 | [diff] [blame] | 3938 | Integer refCt = mKeySetRefs.get(id); |
| 3939 | if (refCt != null) { |
| 3940 | mKeySetRefs.put(id, refCt + 1); |
| 3941 | } else { |
| 3942 | mKeySetRefs.put(id, 1); |
| 3943 | } |
dcashman | 3a0dbfb | 2014-07-07 13:53:36 -0700 | [diff] [blame] | 3944 | packageSetting.keySetData.setProperSigningKeySet(id); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 3945 | } else if (tagName.equals("signing-keyset")) { |
dcashman | 8c04fac | 2015-03-23 11:39:42 -0700 | [diff] [blame] | 3946 | // from v1 of keysetmanagerservice - no longer used |
dcashman | 55b1078 | 2014-04-09 14:20:38 -0700 | [diff] [blame] | 3947 | } else if (tagName.equals("upgrade-keyset")) { |
| 3948 | long id = Long.parseLong(parser.getAttributeValue(null, "identifier")); |
| 3949 | packageSetting.keySetData.addUpgradeKeySetById(id); |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 3950 | } else if (tagName.equals("defined-keyset")) { |
| 3951 | long id = Long.parseLong(parser.getAttributeValue(null, "identifier")); |
| 3952 | String alias = parser.getAttributeValue(null, "alias"); |
dcashman | 8c04fac | 2015-03-23 11:39:42 -0700 | [diff] [blame] | 3953 | Integer refCt = mKeySetRefs.get(id); |
| 3954 | if (refCt != null) { |
| 3955 | mKeySetRefs.put(id, refCt + 1); |
| 3956 | } else { |
| 3957 | mKeySetRefs.put(id, 1); |
| 3958 | } |
Geremy Condra | f1bcca8 | 2013-01-07 22:35:24 -0800 | [diff] [blame] | 3959 | packageSetting.keySetData.addDefinedKeySet(id, alias); |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 3960 | } else if (tagName.equals(TAG_DOMAIN_VERIFICATION)) { |
| 3961 | readDomainVerificationLPw(parser, packageSetting); |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 3962 | } else if (tagName.equals(TAG_CHILD_PACKAGE)) { |
| 3963 | String childPackageName = parser.getAttributeValue(null, ATTR_NAME); |
| 3964 | if (packageSetting.childPackageNames == null) { |
| 3965 | packageSetting.childPackageNames = new ArrayList<>(); |
| 3966 | } |
| 3967 | packageSetting.childPackageNames.add(childPackageName); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3968 | } else { |
| 3969 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 3970 | "Unknown element under <package>: " + parser.getName()); |
| 3971 | XmlUtils.skipCurrentTag(parser); |
| 3972 | } |
| 3973 | } |
| 3974 | } else { |
| 3975 | XmlUtils.skipCurrentTag(parser); |
| 3976 | } |
| 3977 | } |
| 3978 | |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 3979 | private void readDisabledComponentsLPw(PackageSettingBase packageSetting, XmlPullParser parser, |
| 3980 | int userId) throws IOException, XmlPullParserException { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3981 | int outerDepth = parser.getDepth(); |
| 3982 | int type; |
| 3983 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 3984 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 3985 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 3986 | continue; |
| 3987 | } |
| 3988 | |
| 3989 | String tagName = parser.getName(); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 3990 | if (tagName.equals(TAG_ITEM)) { |
| 3991 | String name = parser.getAttributeValue(null, ATTR_NAME); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3992 | if (name != null) { |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 3993 | packageSetting.addDisabledComponent(name.intern(), userId); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 3994 | } else { |
| 3995 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 3996 | "Error in package manager settings: <disabled-components> has" |
| 3997 | + " no name at " + parser.getPositionDescription()); |
| 3998 | } |
| 3999 | } else { |
| 4000 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 4001 | "Unknown element under <disabled-components>: " + parser.getName()); |
| 4002 | } |
| 4003 | XmlUtils.skipCurrentTag(parser); |
| 4004 | } |
| 4005 | } |
| 4006 | |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 4007 | private void readEnabledComponentsLPw(PackageSettingBase packageSetting, XmlPullParser parser, |
| 4008 | int userId) throws IOException, XmlPullParserException { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 4009 | int outerDepth = parser.getDepth(); |
| 4010 | int type; |
| 4011 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 4012 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 4013 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 4014 | continue; |
| 4015 | } |
| 4016 | |
| 4017 | String tagName = parser.getName(); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 4018 | if (tagName.equals(TAG_ITEM)) { |
| 4019 | String name = parser.getAttributeValue(null, ATTR_NAME); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 4020 | if (name != null) { |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 4021 | packageSetting.addEnabledComponent(name.intern(), userId); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 4022 | } else { |
| 4023 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 4024 | "Error in package manager settings: <enabled-components> has" |
| 4025 | + " no name at " + parser.getPositionDescription()); |
| 4026 | } |
| 4027 | } else { |
| 4028 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 4029 | "Unknown element under <enabled-components>: " + parser.getName()); |
| 4030 | } |
| 4031 | XmlUtils.skipCurrentTag(parser); |
| 4032 | } |
| 4033 | } |
| 4034 | |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 4035 | private void readSharedUserLPw(XmlPullParser parser) throws XmlPullParserException,IOException { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 4036 | String name = null; |
| 4037 | String idStr = null; |
| 4038 | int pkgFlags = 0; |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 4039 | int pkgPrivateFlags = 0; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 4040 | SharedUserSetting su = null; |
| 4041 | try { |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 4042 | name = parser.getAttributeValue(null, ATTR_NAME); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 4043 | idStr = parser.getAttributeValue(null, "userId"); |
| 4044 | int userId = idStr != null ? Integer.parseInt(idStr) : 0; |
| 4045 | if ("true".equals(parser.getAttributeValue(null, "system"))) { |
| 4046 | pkgFlags |= ApplicationInfo.FLAG_SYSTEM; |
| 4047 | } |
| 4048 | if (name == null) { |
| 4049 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 4050 | "Error in package manager settings: <shared-user> has no name at " |
| 4051 | + parser.getPositionDescription()); |
| 4052 | } else if (userId == 0) { |
| 4053 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 4054 | "Error in package manager settings: shared-user " + name |
| 4055 | + " has bad userId " + idStr + " at " |
| 4056 | + parser.getPositionDescription()); |
| 4057 | } else { |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 4058 | if ((su = addSharedUserLPw(name.intern(), userId, pkgFlags, pkgPrivateFlags)) |
| 4059 | == null) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 4060 | PackageManagerService |
| 4061 | .reportSettingsProblem(Log.ERROR, "Occurred while parsing settings at " |
| 4062 | + parser.getPositionDescription()); |
| 4063 | } |
| 4064 | } |
| 4065 | } catch (NumberFormatException e) { |
| 4066 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 4067 | "Error in package manager settings: package " + name + " has bad userId " |
| 4068 | + idStr + " at " + parser.getPositionDescription()); |
| 4069 | } |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 4070 | |
| 4071 | if (su != null) { |
| 4072 | int outerDepth = parser.getDepth(); |
| 4073 | int type; |
| 4074 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 4075 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 4076 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 4077 | continue; |
| 4078 | } |
| 4079 | |
| 4080 | String tagName = parser.getName(); |
| 4081 | if (tagName.equals("sigs")) { |
| 4082 | su.signatures.readXml(parser, mPastSignatures); |
| 4083 | } else if (tagName.equals("perms")) { |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4084 | readInstallPermissionsLPr(parser, su.getPermissionsState()); |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 4085 | } else { |
| 4086 | PackageManagerService.reportSettingsProblem(Log.WARN, |
| 4087 | "Unknown element under <shared-user>: " + parser.getName()); |
| 4088 | XmlUtils.skipCurrentTag(parser); |
| 4089 | } |
| 4090 | } |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 4091 | } else { |
| 4092 | XmlUtils.skipCurrentTag(parser); |
| 4093 | } |
| 4094 | } |
| 4095 | |
Fyodor Kupolov | d8327bd | 2015-11-30 17:42:43 -0800 | [diff] [blame] | 4096 | void createNewUserLI(@NonNull PackageManagerService service, @NonNull Installer installer, |
Sudheer Shanka | 7cb54a3 | 2016-09-16 12:59:05 -0700 | [diff] [blame] | 4097 | int userHandle, String[] disallowedPackages) { |
Fyodor Kupolov | d8327bd | 2015-11-30 17:42:43 -0800 | [diff] [blame] | 4098 | String[] volumeUuids; |
| 4099 | String[] names; |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 4100 | int[] appIds; |
Fyodor Kupolov | d8327bd | 2015-11-30 17:42:43 -0800 | [diff] [blame] | 4101 | String[] seinfos; |
Janis Danisevskis | f340974 | 2016-01-12 14:46:33 +0000 | [diff] [blame] | 4102 | int[] targetSdkVersions; |
Fyodor Kupolov | d8327bd | 2015-11-30 17:42:43 -0800 | [diff] [blame] | 4103 | int packagesCount; |
| 4104 | synchronized (mPackages) { |
| 4105 | Collection<PackageSetting> packages = mPackages.values(); |
| 4106 | packagesCount = packages.size(); |
| 4107 | volumeUuids = new String[packagesCount]; |
| 4108 | names = new String[packagesCount]; |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 4109 | appIds = new int[packagesCount]; |
Fyodor Kupolov | d8327bd | 2015-11-30 17:42:43 -0800 | [diff] [blame] | 4110 | seinfos = new String[packagesCount]; |
Janis Danisevskis | f340974 | 2016-01-12 14:46:33 +0000 | [diff] [blame] | 4111 | targetSdkVersions = new int[packagesCount]; |
Fyodor Kupolov | d8327bd | 2015-11-30 17:42:43 -0800 | [diff] [blame] | 4112 | Iterator<PackageSetting> packagesIterator = packages.iterator(); |
| 4113 | for (int i = 0; i < packagesCount; i++) { |
| 4114 | PackageSetting ps = packagesIterator.next(); |
| 4115 | if (ps.pkg == null || ps.pkg.applicationInfo == null) { |
| 4116 | continue; |
| 4117 | } |
Sudheer Shanka | 7cb54a3 | 2016-09-16 12:59:05 -0700 | [diff] [blame] | 4118 | final boolean shouldInstall = ps.isSystem() && |
Rhed Jao | cd47c26 | 2018-06-13 11:16:16 +0800 | [diff] [blame] | 4119 | !ArrayUtils.contains(disallowedPackages, ps.name) && |
| 4120 | !ps.pkg.applicationInfo.hiddenUntilInstalled; |
Fyodor Kupolov | d8327bd | 2015-11-30 17:42:43 -0800 | [diff] [blame] | 4121 | // Only system apps are initially installed. |
Sudheer Shanka | 7cb54a3 | 2016-09-16 12:59:05 -0700 | [diff] [blame] | 4122 | ps.setInstalled(shouldInstall, userHandle); |
Amith Yamasani | 23ab7f5 | 2017-01-22 17:43:24 -0800 | [diff] [blame] | 4123 | if (!shouldInstall) { |
| 4124 | writeKernelMappingLPr(ps); |
| 4125 | } |
Fyodor Kupolov | d8327bd | 2015-11-30 17:42:43 -0800 | [diff] [blame] | 4126 | // Need to create a data directory for all apps under this user. Accumulate all |
| 4127 | // required args and call the installer after mPackages lock has been released |
| 4128 | volumeUuids[i] = ps.volumeUuid; |
| 4129 | names[i] = ps.name; |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 4130 | appIds[i] = ps.appId; |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 4131 | seinfos[i] = ps.pkg.applicationInfo.seInfo; |
Janis Danisevskis | f340974 | 2016-01-12 14:46:33 +0000 | [diff] [blame] | 4132 | targetSdkVersions[i] = ps.pkg.applicationInfo.targetSdkVersion; |
Fyodor Kupolov | d8327bd | 2015-11-30 17:42:43 -0800 | [diff] [blame] | 4133 | } |
| 4134 | } |
| 4135 | for (int i = 0; i < packagesCount; i++) { |
| 4136 | if (names[i] == null) { |
Amith Yamasani | 41cd577 | 2014-07-10 15:26:00 -0700 | [diff] [blame] | 4137 | continue; |
| 4138 | } |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 4139 | // TODO: triage flags! |
Jeff Sharkey | 47f7108 | 2016-02-01 17:03:54 -0700 | [diff] [blame] | 4140 | final int flags = StorageManager.FLAG_STORAGE_CE | StorageManager.FLAG_STORAGE_DE; |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 4141 | try { |
| 4142 | installer.createAppData(volumeUuids[i], names[i], userHandle, flags, appIds[i], |
Janis Danisevskis | f340974 | 2016-01-12 14:46:33 +0000 | [diff] [blame] | 4143 | seinfos[i], targetSdkVersions[i]); |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 4144 | } catch (InstallerException e) { |
| 4145 | Slog.w(TAG, "Failed to prepare app data", e); |
| 4146 | } |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 4147 | } |
Fyodor Kupolov | d8327bd | 2015-11-30 17:42:43 -0800 | [diff] [blame] | 4148 | synchronized (mPackages) { |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 4149 | applyDefaultPreferredAppsLPw(userHandle); |
Fyodor Kupolov | d8327bd | 2015-11-30 17:42:43 -0800 | [diff] [blame] | 4150 | } |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 4151 | } |
| 4152 | |
Alexandra Gherghina | 539a7ef | 2014-07-07 12:27:54 +0100 | [diff] [blame] | 4153 | void removeUserLPw(int userId) { |
Dianne Hackborn | 6309271 | 2012-10-07 14:45:35 -0700 | [diff] [blame] | 4154 | Set<Entry<String, PackageSetting>> entries = mPackages.entrySet(); |
| 4155 | for (Entry<String, PackageSetting> entry : entries) { |
| 4156 | entry.getValue().removeUser(userId); |
| 4157 | } |
| 4158 | mPreferredActivities.remove(userId); |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 4159 | File file = getUserPackagesStateFile(userId); |
| 4160 | file.delete(); |
| 4161 | file = getUserPackagesStateBackupFile(userId); |
| 4162 | file.delete(); |
Nicolas Prevot | e702404 | 2014-07-08 15:47:17 +0100 | [diff] [blame] | 4163 | removeCrossProfileIntentFiltersLPw(userId); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4164 | |
Fyodor Kupolov | 6954259 | 2016-05-23 14:22:38 -0700 | [diff] [blame] | 4165 | mRuntimePermissionsPersistence.onUserRemovedLPw(userId); |
Jeff Sharkey | 91edde2 | 2015-05-20 12:04:42 -0700 | [diff] [blame] | 4166 | |
| 4167 | writePackageListLPr(); |
Amith Yamasani | 23ab7f5 | 2017-01-22 17:43:24 -0800 | [diff] [blame] | 4168 | |
| 4169 | // Inform kernel that the user was removed, so that packages are marked uninstalled |
| 4170 | // for sdcardfs |
| 4171 | writeKernelRemoveUserLPr(userId); |
Nicolas Prevot | a0f4885 | 2014-05-27 11:21:11 +0100 | [diff] [blame] | 4172 | } |
| 4173 | |
Nicolas Prevot | e702404 | 2014-07-08 15:47:17 +0100 | [diff] [blame] | 4174 | void removeCrossProfileIntentFiltersLPw(int userId) { |
| 4175 | synchronized (mCrossProfileIntentResolvers) { |
| 4176 | // userId is the source user |
| 4177 | if (mCrossProfileIntentResolvers.get(userId) != null) { |
| 4178 | mCrossProfileIntentResolvers.remove(userId); |
| 4179 | writePackageRestrictionsLPr(userId); |
Nicolas Prevot | a0f4885 | 2014-05-27 11:21:11 +0100 | [diff] [blame] | 4180 | } |
Nicolas Prevot | e702404 | 2014-07-08 15:47:17 +0100 | [diff] [blame] | 4181 | // userId is the target user |
| 4182 | int count = mCrossProfileIntentResolvers.size(); |
| 4183 | for (int i = 0; i < count; i++) { |
| 4184 | int sourceUserId = mCrossProfileIntentResolvers.keyAt(i); |
| 4185 | CrossProfileIntentResolver cpir = mCrossProfileIntentResolvers.get(sourceUserId); |
| 4186 | boolean needsWriting = false; |
Jeff Sharkey | 9f837a9 | 2014-10-24 12:07:24 -0700 | [diff] [blame] | 4187 | ArraySet<CrossProfileIntentFilter> cpifs = |
| 4188 | new ArraySet<CrossProfileIntentFilter>(cpir.filterSet()); |
Nicolas Prevot | e702404 | 2014-07-08 15:47:17 +0100 | [diff] [blame] | 4189 | for (CrossProfileIntentFilter cpif : cpifs) { |
| 4190 | if (cpif.getTargetUserId() == userId) { |
| 4191 | needsWriting = true; |
| 4192 | cpir.removeFilter(cpif); |
| 4193 | } |
| 4194 | } |
| 4195 | if (needsWriting) { |
| 4196 | writePackageRestrictionsLPr(sourceUserId); |
| 4197 | } |
Nicolas Prevot | a0f4885 | 2014-05-27 11:21:11 +0100 | [diff] [blame] | 4198 | } |
| 4199 | } |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 4200 | } |
| 4201 | |
Geremy Condra | 12c1838 | 2013-03-06 16:49:06 -0800 | [diff] [blame] | 4202 | // This should be called (at least) whenever an application is removed |
| 4203 | private void setFirstAvailableUid(int uid) { |
| 4204 | if (uid > mFirstAvailableUid) { |
| 4205 | mFirstAvailableUid = uid; |
| 4206 | } |
| 4207 | } |
| 4208 | |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 4209 | // Returns -1 if we could not find an available UserId to assign |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4210 | private int newUserIdLPw(Object obj) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 4211 | // Let's be stupidly inefficient for now... |
| 4212 | final int N = mUserIds.size(); |
Geremy Condra | 12c1838 | 2013-03-06 16:49:06 -0800 | [diff] [blame] | 4213 | for (int i = mFirstAvailableUid; i < N; i++) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 4214 | if (mUserIds.get(i) == null) { |
| 4215 | mUserIds.set(i, obj); |
Dianne Hackborn | 21fbd1f | 2012-02-10 10:38:10 -0800 | [diff] [blame] | 4216 | return Process.FIRST_APPLICATION_UID + i; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 4217 | } |
| 4218 | } |
| 4219 | |
| 4220 | // None left? |
Dianne Hackborn | 21fbd1f | 2012-02-10 10:38:10 -0800 | [diff] [blame] | 4221 | if (N > (Process.LAST_APPLICATION_UID-Process.FIRST_APPLICATION_UID)) { |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 4222 | return -1; |
| 4223 | } |
| 4224 | |
| 4225 | mUserIds.add(obj); |
Dianne Hackborn | 21fbd1f | 2012-02-10 10:38:10 -0800 | [diff] [blame] | 4226 | return Process.FIRST_APPLICATION_UID + N; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 4227 | } |
| 4228 | |
Kenny Root | 0aaa0d9 | 2011-09-12 16:42:55 -0700 | [diff] [blame] | 4229 | public VerifierDeviceIdentity getVerifierDeviceIdentityLPw() { |
| 4230 | if (mVerifierDeviceIdentity == null) { |
| 4231 | mVerifierDeviceIdentity = VerifierDeviceIdentity.generate(); |
| 4232 | |
| 4233 | writeLPr(); |
| 4234 | } |
| 4235 | |
| 4236 | return mVerifierDeviceIdentity; |
| 4237 | } |
| 4238 | |
Todd Kennedy | ff35e66 | 2016-09-20 12:53:52 -0700 | [diff] [blame] | 4239 | boolean hasOtherDisabledSystemPkgWithChildLPr(String parentPackageName, |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4240 | String childPackageName) { |
| 4241 | final int packageCount = mDisabledSysPackages.size(); |
| 4242 | for (int i = 0; i < packageCount; i++) { |
| 4243 | PackageSetting disabledPs = mDisabledSysPackages.valueAt(i); |
| 4244 | if (disabledPs.childPackageNames == null || disabledPs.childPackageNames.isEmpty()) { |
| 4245 | continue; |
| 4246 | } |
| 4247 | if (disabledPs.name.equals(parentPackageName)) { |
| 4248 | continue; |
| 4249 | } |
| 4250 | final int childCount = disabledPs.childPackageNames.size(); |
| 4251 | for (int j = 0; j < childCount; j++) { |
| 4252 | String currChildPackageName = disabledPs.childPackageNames.get(j); |
| 4253 | if (currChildPackageName.equals(childPackageName)) { |
| 4254 | return true; |
| 4255 | } |
| 4256 | } |
| 4257 | } |
| 4258 | return false; |
| 4259 | } |
| 4260 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4261 | public PackageSetting getDisabledSystemPkgLPr(String name) { |
| 4262 | PackageSetting ps = mDisabledSysPackages.get(name); |
| 4263 | return ps; |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 4264 | } |
| 4265 | |
Jeff Sharkey | 5217cac | 2015-12-20 15:34:01 -0700 | [diff] [blame] | 4266 | boolean isEnabledAndMatchLPr(ComponentInfo componentInfo, int flags, int userId) { |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 4267 | final PackageSetting ps = mPackages.get(componentInfo.packageName); |
| 4268 | if (ps == null) return false; |
Jeff Sharkey | e17ac15 | 2015-11-06 22:40:29 -0800 | [diff] [blame] | 4269 | |
Jeff Sharkey | 2bd31db | 2016-01-09 16:58:14 -0700 | [diff] [blame] | 4270 | final PackageUserState userState = ps.readUserState(userId); |
| 4271 | return userState.isMatch(componentInfo, flags); |
Jeff Sharkey | e17ac15 | 2015-11-06 22:40:29 -0800 | [diff] [blame] | 4272 | } |
| 4273 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4274 | String getInstallerPackageNameLPr(String packageName) { |
| 4275 | final PackageSetting pkg = mPackages.get(packageName); |
| 4276 | if (pkg == null) { |
| 4277 | throw new IllegalArgumentException("Unknown package: " + packageName); |
| 4278 | } |
| 4279 | return pkg.installerPackageName; |
| 4280 | } |
| 4281 | |
Sudheer Shanka | 8c57aea | 2016-04-20 16:47:50 -0700 | [diff] [blame] | 4282 | boolean isOrphaned(String packageName) { |
| 4283 | final PackageSetting pkg = mPackages.get(packageName); |
| 4284 | if (pkg == null) { |
| 4285 | throw new IllegalArgumentException("Unknown package: " + packageName); |
| 4286 | } |
| 4287 | return pkg.isOrphaned; |
| 4288 | } |
| 4289 | |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 4290 | int getApplicationEnabledSettingLPr(String packageName, int userId) { |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4291 | final PackageSetting pkg = mPackages.get(packageName); |
| 4292 | if (pkg == null) { |
| 4293 | throw new IllegalArgumentException("Unknown package: " + packageName); |
| 4294 | } |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 4295 | return pkg.getEnabled(userId); |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4296 | } |
| 4297 | |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 4298 | int getComponentEnabledSettingLPr(ComponentName componentName, int userId) { |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4299 | final String packageName = componentName.getPackageName(); |
| 4300 | final PackageSetting pkg = mPackages.get(packageName); |
| 4301 | if (pkg == null) { |
| 4302 | throw new IllegalArgumentException("Unknown component: " + componentName); |
| 4303 | } |
| 4304 | final String classNameStr = componentName.getClassName(); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 4305 | return pkg.getCurrentEnabledStateLPr(classNameStr, userId); |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4306 | } |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 4307 | |
Svet Ganov | 973edd19 | 2016-09-08 20:15:55 -0700 | [diff] [blame] | 4308 | boolean wasPackageEverLaunchedLPr(String packageName, int userId) { |
| 4309 | final PackageSetting pkgSetting = mPackages.get(packageName); |
| 4310 | if (pkgSetting == null) { |
| 4311 | throw new IllegalArgumentException("Unknown package: " + packageName); |
| 4312 | } |
| 4313 | return !pkgSetting.getNotLaunched(userId); |
| 4314 | } |
| 4315 | |
Christopher Tate | 5cf5578 | 2016-04-25 17:08:56 -0700 | [diff] [blame] | 4316 | boolean setPackageStoppedStateLPw(PackageManagerService pm, String packageName, |
Jeff Sharkey | bd0e9e4 | 2015-04-30 16:04:50 -0700 | [diff] [blame] | 4317 | boolean stopped, boolean allowedByPermission, int uid, int userId) { |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 4318 | int appId = UserHandle.getAppId(uid); |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4319 | final PackageSetting pkgSetting = mPackages.get(packageName); |
| 4320 | if (pkgSetting == null) { |
| 4321 | throw new IllegalArgumentException("Unknown package: " + packageName); |
| 4322 | } |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 4323 | if (!allowedByPermission && (appId != pkgSetting.appId)) { |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4324 | throw new SecurityException( |
| 4325 | "Permission Denial: attempt to change stopped state from pid=" |
| 4326 | + Binder.getCallingPid() |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 4327 | + ", uid=" + uid + ", package uid=" + pkgSetting.appId); |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4328 | } |
| 4329 | if (DEBUG_STOPPED) { |
| 4330 | if (stopped) { |
| 4331 | RuntimeException e = new RuntimeException("here"); |
| 4332 | e.fillInStackTrace(); |
| 4333 | Slog.i(TAG, "Stopping package " + packageName, e); |
| 4334 | } |
| 4335 | } |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 4336 | if (pkgSetting.getStopped(userId) != stopped) { |
| 4337 | pkgSetting.setStopped(stopped, userId); |
| 4338 | // pkgSetting.pkg.mSetStopped = stopped; |
| 4339 | if (pkgSetting.getNotLaunched(userId)) { |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4340 | if (pkgSetting.installerPackageName != null) { |
Christopher Tate | 5cf5578 | 2016-04-25 17:08:56 -0700 | [diff] [blame] | 4341 | pm.notifyFirstLaunch(pkgSetting.name, pkgSetting.installerPackageName, userId); |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4342 | } |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 4343 | pkgSetting.setNotLaunched(false, userId); |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4344 | } |
| 4345 | return true; |
| 4346 | } |
| 4347 | return false; |
| 4348 | } |
| 4349 | |
Ben Gruver | 1ab3d6e | 2017-12-07 13:45:08 -0800 | [diff] [blame] | 4350 | void setHarmfulAppWarningLPw(String packageName, CharSequence warning, int userId) { |
| 4351 | final PackageSetting pkgSetting = mPackages.get(packageName); |
| 4352 | if (pkgSetting == null) { |
| 4353 | throw new IllegalArgumentException("Unknown package: " + packageName); |
| 4354 | } |
| 4355 | pkgSetting.setHarmfulAppWarning(userId, warning == null ? null : warning.toString()); |
| 4356 | } |
| 4357 | |
| 4358 | String getHarmfulAppWarningLPr(String packageName, int userId) { |
| 4359 | final PackageSetting pkgSetting = mPackages.get(packageName); |
| 4360 | if (pkgSetting == null) { |
| 4361 | throw new IllegalArgumentException("Unknown package: " + packageName); |
| 4362 | } |
| 4363 | return pkgSetting.getHarmfulAppWarning(userId); |
| 4364 | } |
| 4365 | |
Todd Kennedy | 13715d5 | 2016-08-01 13:38:57 -0700 | [diff] [blame] | 4366 | private static List<UserInfo> getAllUsers(UserManagerService userManager) { |
Amith Yamasani | 7ea3e7d | 2012-04-20 15:19:35 -0700 | [diff] [blame] | 4367 | long id = Binder.clearCallingIdentity(); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 4368 | try { |
Todd Kennedy | 13715d5 | 2016-08-01 13:38:57 -0700 | [diff] [blame] | 4369 | return userManager.getUsers(false); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 4370 | } catch (NullPointerException npe) { |
| 4371 | // packagemanager not yet initialized |
Amith Yamasani | 7ea3e7d | 2012-04-20 15:19:35 -0700 | [diff] [blame] | 4372 | } finally { |
| 4373 | Binder.restoreCallingIdentity(id); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 4374 | } |
| 4375 | return null; |
| 4376 | } |
| 4377 | |
Jeff Sharkey | b2b9ab8 | 2015-04-05 21:10:42 -0700 | [diff] [blame] | 4378 | /** |
| 4379 | * Return all {@link PackageSetting} that are actively installed on the |
| 4380 | * given {@link VolumeInfo#fsUuid}. |
| 4381 | */ |
| 4382 | List<PackageSetting> getVolumePackagesLPr(String volumeUuid) { |
Jeff Sharkey | b2b9ab8 | 2015-04-05 21:10:42 -0700 | [diff] [blame] | 4383 | ArrayList<PackageSetting> res = new ArrayList<>(); |
| 4384 | for (int i = 0; i < mPackages.size(); i++) { |
| 4385 | final PackageSetting setting = mPackages.valueAt(i); |
| 4386 | if (Objects.equals(volumeUuid, setting.volumeUuid)) { |
| 4387 | res.add(setting); |
| 4388 | } |
| 4389 | } |
| 4390 | return res; |
| 4391 | } |
| 4392 | |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4393 | static void printFlags(PrintWriter pw, int val, Object[] spec) { |
Joe Onorato | 20963df | 2012-01-04 18:13:24 -0800 | [diff] [blame] | 4394 | pw.print("[ "); |
| 4395 | for (int i=0; i<spec.length; i+=2) { |
| 4396 | int mask = (Integer)spec[i]; |
| 4397 | if ((val & mask) != 0) { |
| 4398 | pw.print(spec[i+1]); |
| 4399 | pw.print(" "); |
| 4400 | } |
| 4401 | } |
| 4402 | pw.print("]"); |
| 4403 | } |
| 4404 | |
| 4405 | static final Object[] FLAG_DUMP_SPEC = new Object[] { |
| 4406 | ApplicationInfo.FLAG_SYSTEM, "SYSTEM", |
| 4407 | ApplicationInfo.FLAG_DEBUGGABLE, "DEBUGGABLE", |
| 4408 | ApplicationInfo.FLAG_HAS_CODE, "HAS_CODE", |
| 4409 | ApplicationInfo.FLAG_PERSISTENT, "PERSISTENT", |
| 4410 | ApplicationInfo.FLAG_FACTORY_TEST, "FACTORY_TEST", |
| 4411 | ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING, "ALLOW_TASK_REPARENTING", |
| 4412 | ApplicationInfo.FLAG_ALLOW_CLEAR_USER_DATA, "ALLOW_CLEAR_USER_DATA", |
| 4413 | ApplicationInfo.FLAG_UPDATED_SYSTEM_APP, "UPDATED_SYSTEM_APP", |
| 4414 | ApplicationInfo.FLAG_TEST_ONLY, "TEST_ONLY", |
| 4415 | ApplicationInfo.FLAG_VM_SAFE_MODE, "VM_SAFE_MODE", |
| 4416 | ApplicationInfo.FLAG_ALLOW_BACKUP, "ALLOW_BACKUP", |
| 4417 | ApplicationInfo.FLAG_KILL_AFTER_RESTORE, "KILL_AFTER_RESTORE", |
| 4418 | ApplicationInfo.FLAG_RESTORE_ANY_VERSION, "RESTORE_ANY_VERSION", |
| 4419 | ApplicationInfo.FLAG_EXTERNAL_STORAGE, "EXTERNAL_STORAGE", |
| 4420 | ApplicationInfo.FLAG_LARGE_HEAP, "LARGE_HEAP", |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 4421 | }; |
| 4422 | |
Wale Ogunwale | 72a73e3 | 2016-10-13 12:16:39 -0700 | [diff] [blame] | 4423 | private static final Object[] PRIVATE_FLAG_DUMP_SPEC = new Object[] { |
Svet Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 4424 | ApplicationInfo.PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_RESIZEABLE, "PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_RESIZEABLE", |
| 4425 | ApplicationInfo.PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION, "PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION", |
| 4426 | ApplicationInfo.PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_UNRESIZEABLE, "PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_UNRESIZEABLE", |
| 4427 | ApplicationInfo.PRIVATE_FLAG_BACKUP_IN_FOREGROUND, "BACKUP_IN_FOREGROUND", |
| 4428 | ApplicationInfo.PRIVATE_FLAG_CANT_SAVE_STATE, "CANT_SAVE_STATE", |
| 4429 | ApplicationInfo.PRIVATE_FLAG_DEFAULT_TO_DEVICE_PROTECTED_STORAGE, "DEFAULT_TO_DEVICE_PROTECTED_STORAGE", |
| 4430 | ApplicationInfo.PRIVATE_FLAG_DIRECT_BOOT_AWARE, "DIRECT_BOOT_AWARE", |
| 4431 | ApplicationInfo.PRIVATE_FLAG_FORWARD_LOCK, "FORWARD_LOCK", |
| 4432 | ApplicationInfo.PRIVATE_FLAG_HAS_DOMAIN_URLS, "HAS_DOMAIN_URLS", |
| 4433 | ApplicationInfo.PRIVATE_FLAG_HIDDEN, "HIDDEN", |
| 4434 | ApplicationInfo.PRIVATE_FLAG_INSTANT, "EPHEMERAL", |
| 4435 | ApplicationInfo.PRIVATE_FLAG_ISOLATED_SPLIT_LOADING, "ISOLATED_SPLIT_LOADING", |
| 4436 | ApplicationInfo.PRIVATE_FLAG_OEM, "OEM", |
| 4437 | ApplicationInfo.PRIVATE_FLAG_PARTIALLY_DIRECT_BOOT_AWARE, "PARTIALLY_DIRECT_BOOT_AWARE", |
| 4438 | ApplicationInfo.PRIVATE_FLAG_PRIVILEGED, "PRIVILEGED", |
| 4439 | ApplicationInfo.PRIVATE_FLAG_REQUIRED_FOR_SYSTEM_USER, "REQUIRED_FOR_SYSTEM_USER", |
| 4440 | ApplicationInfo.PRIVATE_FLAG_STATIC_SHARED_LIBRARY, "STATIC_SHARED_LIBRARY", |
Jiyong Park | 002fdbd | 2017-02-13 20:50:31 +0900 | [diff] [blame] | 4441 | ApplicationInfo.PRIVATE_FLAG_VENDOR, "VENDOR", |
Jaekyun Seok | 1713d9e | 2018-01-12 21:47:26 +0900 | [diff] [blame] | 4442 | ApplicationInfo.PRIVATE_FLAG_PRODUCT, "PRODUCT", |
Dario Freni | 2bef176 | 2018-06-01 14:02:08 +0100 | [diff] [blame] | 4443 | ApplicationInfo.PRIVATE_FLAG_PRODUCT_SERVICES, "PRODUCT_SERVICES", |
Svet Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 4444 | ApplicationInfo.PRIVATE_FLAG_VIRTUAL_PRELOAD, "VIRTUAL_PRELOAD", |
Joe Onorato | 20963df | 2012-01-04 18:13:24 -0800 | [diff] [blame] | 4445 | }; |
| 4446 | |
Jeff Sharkey | f80b52b | 2015-07-17 14:56:34 -0700 | [diff] [blame] | 4447 | void dumpVersionLPr(IndentingPrintWriter pw) { |
| 4448 | pw.increaseIndent(); |
| 4449 | for (int i= 0; i < mVersion.size(); i++) { |
| 4450 | final String volumeUuid = mVersion.keyAt(i); |
| 4451 | final VersionInfo ver = mVersion.valueAt(i); |
| 4452 | if (Objects.equals(StorageManager.UUID_PRIVATE_INTERNAL, volumeUuid)) { |
| 4453 | pw.println("Internal:"); |
| 4454 | } else if (Objects.equals(StorageManager.UUID_PRIMARY_PHYSICAL, volumeUuid)) { |
| 4455 | pw.println("External:"); |
| 4456 | } else { |
| 4457 | pw.println("UUID " + volumeUuid + ":"); |
| 4458 | } |
| 4459 | pw.increaseIndent(); |
| 4460 | pw.printPair("sdkVersion", ver.sdkVersion); |
| 4461 | pw.printPair("databaseVersion", ver.databaseVersion); |
| 4462 | pw.println(); |
| 4463 | pw.printPair("fingerprint", ver.fingerprint); |
| 4464 | pw.println(); |
| 4465 | pw.decreaseIndent(); |
| 4466 | } |
| 4467 | pw.decreaseIndent(); |
| 4468 | } |
| 4469 | |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 4470 | void dumpPackageLPr(PrintWriter pw, String prefix, String checkinTag, |
| 4471 | ArraySet<String> permissionNames, PackageSetting ps, SimpleDateFormat sdf, |
Makoto Onuki | 0a06858 | 2018-06-13 10:57:34 -0700 | [diff] [blame] | 4472 | Date date, List<UserInfo> users, boolean dumpAll, boolean dumpAllComponents) { |
Dianne Hackborn | 60dc0d9 | 2014-01-17 13:29:21 -0800 | [diff] [blame] | 4473 | if (checkinTag != null) { |
| 4474 | pw.print(checkinTag); |
| 4475 | pw.print(","); |
| 4476 | pw.print(ps.realName != null ? ps.realName : ps.name); |
| 4477 | pw.print(","); |
| 4478 | pw.print(ps.appId); |
| 4479 | pw.print(","); |
| 4480 | pw.print(ps.versionCode); |
| 4481 | pw.print(","); |
| 4482 | pw.print(ps.firstInstallTime); |
| 4483 | pw.print(","); |
| 4484 | pw.print(ps.lastUpdateTime); |
| 4485 | pw.print(","); |
| 4486 | pw.print(ps.installerPackageName != null ? ps.installerPackageName : "?"); |
| 4487 | pw.println(); |
Jeff Sharkey | c4d05fc | 2014-12-01 16:24:01 -0800 | [diff] [blame] | 4488 | if (ps.pkg != null) { |
| 4489 | pw.print(checkinTag); pw.print("-"); pw.print("splt,"); |
| 4490 | pw.print("base,"); |
| 4491 | pw.println(ps.pkg.baseRevisionCode); |
| 4492 | if (ps.pkg.splitNames != null) { |
| 4493 | for (int i = 0; i < ps.pkg.splitNames.length; i++) { |
| 4494 | pw.print(checkinTag); pw.print("-"); pw.print("splt,"); |
| 4495 | pw.print(ps.pkg.splitNames[i]); pw.print(","); |
| 4496 | pw.println(ps.pkg.splitRevisionCodes[i]); |
| 4497 | } |
| 4498 | } |
| 4499 | } |
Dianne Hackborn | 60dc0d9 | 2014-01-17 13:29:21 -0800 | [diff] [blame] | 4500 | for (UserInfo user : users) { |
| 4501 | pw.print(checkinTag); |
| 4502 | pw.print("-"); |
| 4503 | pw.print("usr"); |
| 4504 | pw.print(","); |
| 4505 | pw.print(user.id); |
| 4506 | pw.print(","); |
| 4507 | pw.print(ps.getInstalled(user.id) ? "I" : "i"); |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 4508 | pw.print(ps.getHidden(user.id) ? "B" : "b"); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4509 | pw.print(ps.getSuspended(user.id) ? "SU" : "su"); |
Dianne Hackborn | 60dc0d9 | 2014-01-17 13:29:21 -0800 | [diff] [blame] | 4510 | pw.print(ps.getStopped(user.id) ? "S" : "s"); |
| 4511 | pw.print(ps.getNotLaunched(user.id) ? "l" : "L"); |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 4512 | pw.print(ps.getInstantApp(user.id) ? "IA" : "ia"); |
Todd Kennedy | 5eb5a7d | 2017-08-01 07:42:47 -0700 | [diff] [blame] | 4513 | pw.print(ps.getVirtulalPreload(user.id) ? "VPI" : "vpi"); |
Ben Gruver | 1ab3d6e | 2017-12-07 13:45:08 -0800 | [diff] [blame] | 4514 | String harmfulAppWarning = ps.getHarmfulAppWarning(user.id); |
| 4515 | pw.print(harmfulAppWarning != null ? "HA" : "ha"); |
Dianne Hackborn | 60dc0d9 | 2014-01-17 13:29:21 -0800 | [diff] [blame] | 4516 | pw.print(","); |
| 4517 | pw.print(ps.getEnabled(user.id)); |
| 4518 | String lastDisabledAppCaller = ps.getLastDisabledAppCaller(user.id); |
| 4519 | pw.print(","); |
| 4520 | pw.print(lastDisabledAppCaller != null ? lastDisabledAppCaller : "?"); |
Ben Gruver | 1ab3d6e | 2017-12-07 13:45:08 -0800 | [diff] [blame] | 4521 | pw.print(","); |
Dianne Hackborn | 60dc0d9 | 2014-01-17 13:29:21 -0800 | [diff] [blame] | 4522 | pw.println(); |
| 4523 | } |
| 4524 | return; |
| 4525 | } |
| 4526 | |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 4527 | pw.print(prefix); pw.print("Package ["); |
| 4528 | pw.print(ps.realName != null ? ps.realName : ps.name); |
| 4529 | pw.print("] ("); |
| 4530 | pw.print(Integer.toHexString(System.identityHashCode(ps))); |
| 4531 | pw.println("):"); |
| 4532 | |
| 4533 | if (ps.realName != null) { |
| 4534 | pw.print(prefix); pw.print(" compat name="); |
| 4535 | pw.println(ps.name); |
| 4536 | } |
| 4537 | |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4538 | pw.print(prefix); pw.print(" userId="); pw.println(ps.appId); |
| 4539 | |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 4540 | if (ps.sharedUser != null) { |
| 4541 | pw.print(prefix); pw.print(" sharedUser="); pw.println(ps.sharedUser); |
| 4542 | } |
| 4543 | pw.print(prefix); pw.print(" pkg="); pw.println(ps.pkg); |
| 4544 | pw.print(prefix); pw.print(" codePath="); pw.println(ps.codePathString); |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 4545 | if (permissionNames == null) { |
| 4546 | pw.print(prefix); pw.print(" resourcePath="); pw.println(ps.resourcePathString); |
| 4547 | pw.print(prefix); pw.print(" legacyNativeLibraryDir="); |
| 4548 | pw.println(ps.legacyNativeLibraryPathString); |
| 4549 | pw.print(prefix); pw.print(" primaryCpuAbi="); pw.println(ps.primaryCpuAbiString); |
| 4550 | pw.print(prefix); pw.print(" secondaryCpuAbi="); pw.println(ps.secondaryCpuAbiString); |
| 4551 | } |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 4552 | pw.print(prefix); pw.print(" versionCode="); pw.print(ps.versionCode); |
| 4553 | if (ps.pkg != null) { |
Todd Kennedy | 89d6018 | 2016-03-11 11:18:32 -0800 | [diff] [blame] | 4554 | pw.print(" minSdk="); pw.print(ps.pkg.applicationInfo.minSdkVersion); |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 4555 | pw.print(" targetSdk="); pw.print(ps.pkg.applicationInfo.targetSdkVersion); |
| 4556 | } |
| 4557 | pw.println(); |
| 4558 | if (ps.pkg != null) { |
Svet Ganov | 354cd3c | 2015-12-17 11:35:04 -0800 | [diff] [blame] | 4559 | if (ps.pkg.parentPackage != null) { |
| 4560 | PackageParser.Package parentPkg = ps.pkg.parentPackage; |
| 4561 | PackageSetting pps = mPackages.get(parentPkg.packageName); |
| 4562 | if (pps == null || !pps.codePathString.equals(parentPkg.codePath)) { |
| 4563 | pps = mDisabledSysPackages.get(parentPkg.packageName); |
| 4564 | } |
| 4565 | if (pps != null) { |
| 4566 | pw.print(prefix); pw.print(" parentPackage="); |
| 4567 | pw.println(pps.realName != null ? pps.realName : pps.name); |
| 4568 | } |
| 4569 | } else if (ps.pkg.childPackages != null) { |
| 4570 | pw.print(prefix); pw.print(" childPackages=["); |
| 4571 | final int childCount = ps.pkg.childPackages.size(); |
| 4572 | for (int i = 0; i < childCount; i++) { |
| 4573 | PackageParser.Package childPkg = ps.pkg.childPackages.get(i); |
| 4574 | PackageSetting cps = mPackages.get(childPkg.packageName); |
| 4575 | if (cps == null || !cps.codePathString.equals(childPkg.codePath)) { |
| 4576 | cps = mDisabledSysPackages.get(childPkg.packageName); |
| 4577 | } |
| 4578 | if (cps != null) { |
| 4579 | if (i > 0) { |
| 4580 | pw.print(", "); |
| 4581 | } |
| 4582 | pw.print(cps.realName != null ? cps.realName : cps.name); |
| 4583 | } |
| 4584 | } |
| 4585 | pw.println("]"); |
| 4586 | } |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 4587 | pw.print(prefix); pw.print(" versionName="); pw.println(ps.pkg.mVersionName); |
Jeff Sharkey | c4d05fc | 2014-12-01 16:24:01 -0800 | [diff] [blame] | 4588 | pw.print(prefix); pw.print(" splits="); dumpSplitNames(pw, ps.pkg); pw.println(); |
Patrick Baumann | 420d58a | 2017-12-19 10:17:21 -0800 | [diff] [blame] | 4589 | final int apkSigningVersion = ps.pkg.mSigningDetails.signatureSchemeVersion; |
| 4590 | pw.print(prefix); pw.print(" apkSigningVersion="); pw.println(apkSigningVersion); |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 4591 | pw.print(prefix); pw.print(" applicationInfo="); |
| 4592 | pw.println(ps.pkg.applicationInfo.toString()); |
| 4593 | pw.print(prefix); pw.print(" flags="); printFlags(pw, ps.pkg.applicationInfo.flags, |
| 4594 | FLAG_DUMP_SPEC); pw.println(); |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 4595 | if (ps.pkg.applicationInfo.privateFlags != 0) { |
| 4596 | pw.print(prefix); pw.print(" privateFlags="); printFlags(pw, |
| 4597 | ps.pkg.applicationInfo.privateFlags, PRIVATE_FLAG_DUMP_SPEC); pw.println(); |
| 4598 | } |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 4599 | pw.print(prefix); pw.print(" dataDir="); pw.println(ps.pkg.applicationInfo.dataDir); |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 4600 | pw.print(prefix); pw.print(" supportsScreens=["); |
| 4601 | boolean first = true; |
| 4602 | if ((ps.pkg.applicationInfo.flags & ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS) != 0) { |
| 4603 | if (!first) |
| 4604 | pw.print(", "); |
| 4605 | first = false; |
| 4606 | pw.print("small"); |
| 4607 | } |
| 4608 | if ((ps.pkg.applicationInfo.flags & ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS) != 0) { |
| 4609 | if (!first) |
| 4610 | pw.print(", "); |
| 4611 | first = false; |
| 4612 | pw.print("medium"); |
| 4613 | } |
| 4614 | if ((ps.pkg.applicationInfo.flags & ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS) != 0) { |
| 4615 | if (!first) |
| 4616 | pw.print(", "); |
| 4617 | first = false; |
| 4618 | pw.print("large"); |
| 4619 | } |
| 4620 | if ((ps.pkg.applicationInfo.flags & ApplicationInfo.FLAG_SUPPORTS_XLARGE_SCREENS) != 0) { |
| 4621 | if (!first) |
| 4622 | pw.print(", "); |
| 4623 | first = false; |
| 4624 | pw.print("xlarge"); |
| 4625 | } |
| 4626 | if ((ps.pkg.applicationInfo.flags & ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS) != 0) { |
| 4627 | if (!first) |
| 4628 | pw.print(", "); |
| 4629 | first = false; |
| 4630 | pw.print("resizeable"); |
| 4631 | } |
| 4632 | if ((ps.pkg.applicationInfo.flags & ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES) != 0) { |
| 4633 | if (!first) |
| 4634 | pw.print(", "); |
| 4635 | first = false; |
| 4636 | pw.print("anyDensity"); |
| 4637 | } |
| 4638 | pw.println("]"); |
| 4639 | if (ps.pkg.libraryNames != null && ps.pkg.libraryNames.size() > 0) { |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 4640 | pw.print(prefix); pw.println(" dynamic libraries:"); |
| 4641 | for (int i = 0; i<ps.pkg.libraryNames.size(); i++) { |
| 4642 | pw.print(prefix); pw.print(" "); |
| 4643 | pw.println(ps.pkg.libraryNames.get(i)); |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 4644 | } |
| 4645 | } |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 4646 | if (ps.pkg.staticSharedLibName != null) { |
| 4647 | pw.print(prefix); pw.println(" static library:"); |
| 4648 | pw.print(prefix); pw.print(" "); |
| 4649 | pw.print("name:"); pw.print(ps.pkg.staticSharedLibName); |
| 4650 | pw.print(" version:"); pw.println(ps.pkg.staticSharedLibVersion); |
| 4651 | } |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 4652 | if (ps.pkg.usesLibraries != null && ps.pkg.usesLibraries.size() > 0) { |
| 4653 | pw.print(prefix); pw.println(" usesLibraries:"); |
| 4654 | for (int i=0; i<ps.pkg.usesLibraries.size(); i++) { |
| 4655 | pw.print(prefix); pw.print(" "); pw.println(ps.pkg.usesLibraries.get(i)); |
| 4656 | } |
| 4657 | } |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 4658 | if (ps.pkg.usesStaticLibraries != null |
| 4659 | && ps.pkg.usesStaticLibraries.size() > 0) { |
| 4660 | pw.print(prefix); pw.println(" usesStaticLibraries:"); |
| 4661 | for (int i=0; i<ps.pkg.usesStaticLibraries.size(); i++) { |
| 4662 | pw.print(prefix); pw.print(" "); |
| 4663 | pw.print(ps.pkg.usesStaticLibraries.get(i)); pw.print(" version:"); |
| 4664 | pw.println(ps.pkg.usesStaticLibrariesVersions[i]); |
| 4665 | } |
| 4666 | } |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 4667 | if (ps.pkg.usesOptionalLibraries != null |
| 4668 | && ps.pkg.usesOptionalLibraries.size() > 0) { |
| 4669 | pw.print(prefix); pw.println(" usesOptionalLibraries:"); |
| 4670 | for (int i=0; i<ps.pkg.usesOptionalLibraries.size(); i++) { |
| 4671 | pw.print(prefix); pw.print(" "); |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 4672 | pw.println(ps.pkg.usesOptionalLibraries.get(i)); |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 4673 | } |
| 4674 | } |
| 4675 | if (ps.pkg.usesLibraryFiles != null |
| 4676 | && ps.pkg.usesLibraryFiles.length > 0) { |
| 4677 | pw.print(prefix); pw.println(" usesLibraryFiles:"); |
| 4678 | for (int i=0; i<ps.pkg.usesLibraryFiles.length; i++) { |
| 4679 | pw.print(prefix); pw.print(" "); pw.println(ps.pkg.usesLibraryFiles[i]); |
| 4680 | } |
| 4681 | } |
| 4682 | } |
| 4683 | pw.print(prefix); pw.print(" timeStamp="); |
| 4684 | date.setTime(ps.timeStamp); |
| 4685 | pw.println(sdf.format(date)); |
| 4686 | pw.print(prefix); pw.print(" firstInstallTime="); |
| 4687 | date.setTime(ps.firstInstallTime); |
| 4688 | pw.println(sdf.format(date)); |
| 4689 | pw.print(prefix); pw.print(" lastUpdateTime="); |
| 4690 | date.setTime(ps.lastUpdateTime); |
| 4691 | pw.println(sdf.format(date)); |
| 4692 | if (ps.installerPackageName != null) { |
| 4693 | pw.print(prefix); pw.print(" installerPackageName="); |
| 4694 | pw.println(ps.installerPackageName); |
| 4695 | } |
Jeff Sharkey | b2b9ab8 | 2015-04-05 21:10:42 -0700 | [diff] [blame] | 4696 | if (ps.volumeUuid != null) { |
| 4697 | pw.print(prefix); pw.print(" volumeUuid="); |
| 4698 | pw.println(ps.volumeUuid); |
| 4699 | } |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 4700 | pw.print(prefix); pw.print(" signatures="); pw.println(ps.signatures); |
Svetoslav | cf959f6 | 2015-03-26 20:53:34 -0700 | [diff] [blame] | 4701 | pw.print(prefix); pw.print(" installPermissionsFixed="); |
| 4702 | pw.print(ps.installPermissionsFixed); |
Todd Kennedy | af6f195 | 2018-02-13 11:09:50 -0800 | [diff] [blame] | 4703 | pw.println(); |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 4704 | pw.print(prefix); pw.print(" pkgFlags="); printFlags(pw, ps.pkgFlags, FLAG_DUMP_SPEC); |
| 4705 | pw.println(); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4706 | |
Patrick Baumann | 7438dcb | 2018-05-08 14:31:45 -0700 | [diff] [blame] | 4707 | if (ps.pkg != null && ps.pkg.mOverlayTarget != null) { |
Adrian Roos | c84df77 | 2018-01-19 21:20:22 +0100 | [diff] [blame] | 4708 | pw.print(prefix); pw.print(" overlayTarget="); pw.println(ps.pkg.mOverlayTarget); |
| 4709 | pw.print(prefix); pw.print(" overlayCategory="); pw.println(ps.pkg.mOverlayCategory); |
| 4710 | } |
| 4711 | |
Dianne Hackborn | cfbfafe | 2015-07-21 16:57:51 -0700 | [diff] [blame] | 4712 | if (ps.pkg != null && ps.pkg.permissions != null && ps.pkg.permissions.size() > 0) { |
| 4713 | final ArrayList<PackageParser.Permission> perms = ps.pkg.permissions; |
| 4714 | pw.print(prefix); pw.println(" declared permissions:"); |
| 4715 | for (int i=0; i<perms.size(); i++) { |
| 4716 | PackageParser.Permission perm = perms.get(i); |
| 4717 | if (permissionNames != null |
| 4718 | && !permissionNames.contains(perm.info.name)) { |
| 4719 | continue; |
| 4720 | } |
| 4721 | pw.print(prefix); pw.print(" "); pw.print(perm.info.name); |
| 4722 | pw.print(": prot="); |
| 4723 | pw.print(PermissionInfo.protectionToString(perm.info.protectionLevel)); |
| 4724 | if ((perm.info.flags&PermissionInfo.FLAG_COSTS_MONEY) != 0) { |
| 4725 | pw.print(", COSTS_MONEY"); |
| 4726 | } |
Svet Ganov | 2a1376d | 2016-02-22 17:20:35 -0800 | [diff] [blame] | 4727 | if ((perm.info.flags&PermissionInfo.FLAG_REMOVED) != 0) { |
Svet Ganov | 52153f4 | 2015-08-11 08:59:12 -0700 | [diff] [blame] | 4728 | pw.print(", HIDDEN"); |
Svet Ganov | 3e0be74 | 2015-08-07 23:06:00 -0700 | [diff] [blame] | 4729 | } |
Dianne Hackborn | cfbfafe | 2015-07-21 16:57:51 -0700 | [diff] [blame] | 4730 | if ((perm.info.flags&PermissionInfo.FLAG_INSTALLED) != 0) { |
| 4731 | pw.print(", INSTALLED"); |
| 4732 | } |
| 4733 | pw.println(); |
| 4734 | } |
| 4735 | } |
| 4736 | |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 4737 | if ((permissionNames != null || dumpAll) && ps.pkg != null |
| 4738 | && ps.pkg.requestedPermissions != null |
Dianne Hackborn | 9f5b0a2 | 2015-08-13 18:25:20 -0700 | [diff] [blame] | 4739 | && ps.pkg.requestedPermissions.size() > 0) { |
| 4740 | final ArrayList<String> perms = ps.pkg.requestedPermissions; |
| 4741 | pw.print(prefix); pw.println(" requested permissions:"); |
| 4742 | for (int i=0; i<perms.size(); i++) { |
| 4743 | String perm = perms.get(i); |
| 4744 | if (permissionNames != null |
| 4745 | && !permissionNames.contains(perm)) { |
| 4746 | continue; |
| 4747 | } |
| 4748 | pw.print(prefix); pw.print(" "); pw.println(perm); |
| 4749 | } |
| 4750 | } |
| 4751 | |
| 4752 | if (ps.sharedUser == null || permissionNames != null || dumpAll) { |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4753 | PermissionsState permissionsState = ps.getPermissionsState(); |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 4754 | dumpInstallPermissionsLPr(pw, prefix + " ", permissionNames, permissionsState); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4755 | } |
| 4756 | |
Makoto Onuki | 0a06858 | 2018-06-13 10:57:34 -0700 | [diff] [blame] | 4757 | if (dumpAllComponents) { |
| 4758 | dumpComponents(pw, prefix + " ", ps); |
| 4759 | } |
| 4760 | |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 4761 | for (UserInfo user : users) { |
| 4762 | pw.print(prefix); pw.print(" User "); pw.print(user.id); pw.print(": "); |
Jeff Sharkey | 4288419 | 2016-04-09 16:12:01 -0600 | [diff] [blame] | 4763 | pw.print("ceDataInode="); |
| 4764 | pw.print(ps.getCeDataInode(user.id)); |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 4765 | pw.print(" installed="); |
| 4766 | pw.print(ps.getInstalled(user.id)); |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 4767 | pw.print(" hidden="); |
| 4768 | pw.print(ps.getHidden(user.id)); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 4769 | pw.print(" suspended="); |
| 4770 | pw.print(ps.getSuspended(user.id)); |
Suprabh Shukla | 021b57a | 2018-03-08 18:21:50 -0800 | [diff] [blame] | 4771 | if (ps.getSuspended(user.id)) { |
Suprabh Shukla | 3c3af14 | 2018-03-30 00:28:37 -0700 | [diff] [blame] | 4772 | final PackageUserState pus = ps.readUserState(user.id); |
Suprabh Shukla | 021b57a | 2018-03-08 18:21:50 -0800 | [diff] [blame] | 4773 | pw.print(" suspendingPackage="); |
Suprabh Shukla | 3c3af14 | 2018-03-30 00:28:37 -0700 | [diff] [blame] | 4774 | pw.print(pus.suspendingPackage); |
Suprabh Shukla | 389cb6f | 2018-10-01 18:20:39 -0700 | [diff] [blame] | 4775 | pw.print(" dialogInfo="); |
| 4776 | pw.print(pus.dialogInfo); |
Suprabh Shukla | 021b57a | 2018-03-08 18:21:50 -0800 | [diff] [blame] | 4777 | } |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 4778 | pw.print(" stopped="); |
| 4779 | pw.print(ps.getStopped(user.id)); |
| 4780 | pw.print(" notLaunched="); |
| 4781 | pw.print(ps.getNotLaunched(user.id)); |
| 4782 | pw.print(" enabled="); |
Fyodor Kupolov | 09546ff | 2017-04-03 17:45:50 -0700 | [diff] [blame] | 4783 | pw.print(ps.getEnabled(user.id)); |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 4784 | pw.print(" instant="); |
Dianne Hackborn | c50a108 | 2017-08-15 14:10:39 -0700 | [diff] [blame] | 4785 | pw.print(ps.getInstantApp(user.id)); |
Todd Kennedy | 5eb5a7d | 2017-08-01 07:42:47 -0700 | [diff] [blame] | 4786 | pw.print(" virtual="); |
| 4787 | pw.println(ps.getVirtulalPreload(user.id)); |
Todd Kennedy | b274947 | 2017-06-13 08:24:32 -0700 | [diff] [blame] | 4788 | |
| 4789 | String[] overlayPaths = ps.getOverlayPaths(user.id); |
| 4790 | if (overlayPaths != null && overlayPaths.length > 0) { |
Todd Kennedy | 560830c | 2017-06-16 13:55:13 -0700 | [diff] [blame] | 4791 | pw.print(prefix); pw.println(" overlay paths:"); |
Todd Kennedy | b274947 | 2017-06-13 08:24:32 -0700 | [diff] [blame] | 4792 | for (String path : overlayPaths) { |
Todd Kennedy | 560830c | 2017-06-16 13:55:13 -0700 | [diff] [blame] | 4793 | pw.print(prefix); pw.print(" "); pw.println(path); |
Todd Kennedy | b274947 | 2017-06-13 08:24:32 -0700 | [diff] [blame] | 4794 | } |
| 4795 | } |
| 4796 | |
Dianne Hackborn | 3fa3c28a | 2013-03-26 16:15:41 -0700 | [diff] [blame] | 4797 | String lastDisabledAppCaller = ps.getLastDisabledAppCaller(user.id); |
| 4798 | if (lastDisabledAppCaller != null) { |
| 4799 | pw.print(prefix); pw.print(" lastDisabledCaller: "); |
| 4800 | pw.println(lastDisabledAppCaller); |
| 4801 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4802 | |
| 4803 | if (ps.sharedUser == null) { |
| 4804 | PermissionsState permissionsState = ps.getPermissionsState(); |
| 4805 | dumpGidsLPr(pw, prefix + " ", permissionsState.computeGids(user.id)); |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 4806 | dumpRuntimePermissionsLPr(pw, prefix + " ", permissionNames, permissionsState |
Dianne Hackborn | 9f5b0a2 | 2015-08-13 18:25:20 -0700 | [diff] [blame] | 4807 | .getRuntimePermissionStates(user.id), dumpAll); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4808 | } |
| 4809 | |
Ben Gruver | 1ab3d6e | 2017-12-07 13:45:08 -0800 | [diff] [blame] | 4810 | String harmfulAppWarning = ps.getHarmfulAppWarning(user.id); |
| 4811 | if (harmfulAppWarning != null) { |
| 4812 | pw.print(prefix); pw.print(" harmfulAppWarning: "); |
| 4813 | pw.println(harmfulAppWarning); |
| 4814 | } |
| 4815 | |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 4816 | if (permissionNames == null) { |
| 4817 | ArraySet<String> cmp = ps.getDisabledComponents(user.id); |
| 4818 | if (cmp != null && cmp.size() > 0) { |
| 4819 | pw.print(prefix); pw.println(" disabledComponents:"); |
| 4820 | for (String s : cmp) { |
Dianne Hackborn | cfbfafe | 2015-07-21 16:57:51 -0700 | [diff] [blame] | 4821 | pw.print(prefix); pw.print(" "); pw.println(s); |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 4822 | } |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 4823 | } |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 4824 | cmp = ps.getEnabledComponents(user.id); |
| 4825 | if (cmp != null && cmp.size() > 0) { |
| 4826 | pw.print(prefix); pw.println(" enabledComponents:"); |
| 4827 | for (String s : cmp) { |
Dianne Hackborn | cfbfafe | 2015-07-21 16:57:51 -0700 | [diff] [blame] | 4828 | pw.print(prefix); pw.print(" "); pw.println(s); |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 4829 | } |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 4830 | } |
| 4831 | } |
| 4832 | } |
Dianne Hackborn | c895be7 | 2013-03-11 17:48:43 -0700 | [diff] [blame] | 4833 | } |
| 4834 | |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 4835 | void dumpPackagesLPr(PrintWriter pw, String packageName, ArraySet<String> permissionNames, |
| 4836 | DumpState dumpState, boolean checkin) { |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4837 | final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| 4838 | final Date date = new Date(); |
| 4839 | boolean printedSomething = false; |
Makoto Onuki | 0a06858 | 2018-06-13 10:57:34 -0700 | [diff] [blame] | 4840 | final boolean dumpAllComponents = |
| 4841 | dumpState.isOptionEnabled(DumpState.OPTION_DUMP_ALL_COMPONENTS); |
Todd Kennedy | 13715d5 | 2016-08-01 13:38:57 -0700 | [diff] [blame] | 4842 | List<UserInfo> users = getAllUsers(UserManagerService.getInstance()); |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4843 | for (final PackageSetting ps : mPackages.values()) { |
| 4844 | if (packageName != null && !packageName.equals(ps.realName) |
| 4845 | && !packageName.equals(ps.name)) { |
| 4846 | continue; |
| 4847 | } |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 4848 | if (permissionNames != null |
| 4849 | && !ps.getPermissionsState().hasRequestedPermission(permissionNames)) { |
| 4850 | continue; |
| 4851 | } |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4852 | |
Dianne Hackborn | 60dc0d9 | 2014-01-17 13:29:21 -0800 | [diff] [blame] | 4853 | if (!checkin && packageName != null) { |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4854 | dumpState.setSharedUser(ps.sharedUser); |
| 4855 | } |
| 4856 | |
Dianne Hackborn | 60dc0d9 | 2014-01-17 13:29:21 -0800 | [diff] [blame] | 4857 | if (!checkin && !printedSomething) { |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4858 | if (dumpState.onTitlePrinted()) |
Dianne Hackborn | cbfd23e | 2013-06-11 14:26:53 -0700 | [diff] [blame] | 4859 | pw.println(); |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4860 | pw.println("Packages:"); |
| 4861 | printedSomething = true; |
| 4862 | } |
Dianne Hackborn | 9f5b0a2 | 2015-08-13 18:25:20 -0700 | [diff] [blame] | 4863 | dumpPackageLPr(pw, " ", checkin ? "pkg" : null, permissionNames, ps, sdf, date, users, |
Makoto Onuki | 0a06858 | 2018-06-13 10:57:34 -0700 | [diff] [blame] | 4864 | packageName != null, dumpAllComponents); |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4865 | } |
| 4866 | |
| 4867 | printedSomething = false; |
Dianne Hackborn | 9f5b0a2 | 2015-08-13 18:25:20 -0700 | [diff] [blame] | 4868 | if (mRenamedPackages.size() > 0 && permissionNames == null) { |
Andy McFadden | 2f36229 | 2012-01-20 14:43:38 -0800 | [diff] [blame] | 4869 | for (final Map.Entry<String, String> e : mRenamedPackages.entrySet()) { |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4870 | if (packageName != null && !packageName.equals(e.getKey()) |
| 4871 | && !packageName.equals(e.getValue())) { |
| 4872 | continue; |
| 4873 | } |
Dianne Hackborn | 60dc0d9 | 2014-01-17 13:29:21 -0800 | [diff] [blame] | 4874 | if (!checkin) { |
| 4875 | if (!printedSomething) { |
| 4876 | if (dumpState.onTitlePrinted()) |
| 4877 | pw.println(); |
| 4878 | pw.println("Renamed packages:"); |
| 4879 | printedSomething = true; |
| 4880 | } |
| 4881 | pw.print(" "); |
| 4882 | } else { |
| 4883 | pw.print("ren,"); |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4884 | } |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4885 | pw.print(e.getKey()); |
Dianne Hackborn | 60dc0d9 | 2014-01-17 13:29:21 -0800 | [diff] [blame] | 4886 | pw.print(checkin ? " -> " : ","); |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4887 | pw.println(e.getValue()); |
| 4888 | } |
| 4889 | } |
| 4890 | |
| 4891 | printedSomething = false; |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 4892 | if (mDisabledSysPackages.size() > 0 && permissionNames == null) { |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4893 | for (final PackageSetting ps : mDisabledSysPackages.values()) { |
| 4894 | if (packageName != null && !packageName.equals(ps.realName) |
| 4895 | && !packageName.equals(ps.name)) { |
| 4896 | continue; |
| 4897 | } |
Dianne Hackborn | 60dc0d9 | 2014-01-17 13:29:21 -0800 | [diff] [blame] | 4898 | if (!checkin && !printedSomething) { |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4899 | if (dumpState.onTitlePrinted()) |
Dianne Hackborn | cbfd23e | 2013-06-11 14:26:53 -0700 | [diff] [blame] | 4900 | pw.println(); |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4901 | pw.println("Hidden system packages:"); |
| 4902 | printedSomething = true; |
| 4903 | } |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 4904 | dumpPackageLPr(pw, " ", checkin ? "dis" : null, permissionNames, ps, sdf, date, |
Makoto Onuki | 0a06858 | 2018-06-13 10:57:34 -0700 | [diff] [blame] | 4905 | users, packageName != null, dumpAllComponents); |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4906 | } |
| 4907 | } |
| 4908 | } |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 4909 | |
Netta P | 426cbef | 2017-02-10 14:38:39 -0800 | [diff] [blame] | 4910 | void dumpPackagesProto(ProtoOutputStream proto) { |
| 4911 | List<UserInfo> users = getAllUsers(UserManagerService.getInstance()); |
| 4912 | |
| 4913 | final int count = mPackages.size(); |
| 4914 | for (int i = 0; i < count; i++) { |
| 4915 | final PackageSetting ps = mPackages.valueAt(i); |
| 4916 | ps.writeToProto(proto, PackageServiceDumpProto.PACKAGES, users); |
| 4917 | } |
| 4918 | } |
| 4919 | |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 4920 | void dumpPermissionsLPr(PrintWriter pw, String packageName, ArraySet<String> permissionNames, |
| 4921 | DumpState dumpState) { |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 4922 | mPermissions.dumpPermissions(pw, packageName, permissionNames, |
| 4923 | (mReadExternalStorageEnforced == Boolean.TRUE), dumpState); |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4924 | } |
Jeff Sharkey | 1c27576a | 2012-04-11 19:07:08 -0700 | [diff] [blame] | 4925 | |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 4926 | void dumpSharedUsersLPr(PrintWriter pw, String packageName, ArraySet<String> permissionNames, |
| 4927 | DumpState dumpState, boolean checkin) { |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4928 | boolean printedSomething = false; |
| 4929 | for (SharedUserSetting su : mSharedUsers.values()) { |
| 4930 | if (packageName != null && su != dumpState.getSharedUser()) { |
| 4931 | continue; |
| 4932 | } |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 4933 | if (permissionNames != null |
| 4934 | && !su.getPermissionsState().hasRequestedPermission(permissionNames)) { |
| 4935 | continue; |
| 4936 | } |
Dianne Hackborn | d052a94 | 2014-11-21 15:23:13 -0800 | [diff] [blame] | 4937 | if (!checkin) { |
| 4938 | if (!printedSomething) { |
| 4939 | if (dumpState.onTitlePrinted()) |
| 4940 | pw.println(); |
| 4941 | pw.println("Shared users:"); |
| 4942 | printedSomething = true; |
| 4943 | } |
| 4944 | pw.print(" SharedUser ["); |
| 4945 | pw.print(su.name); |
| 4946 | pw.print("] ("); |
| 4947 | pw.print(Integer.toHexString(System.identityHashCode(su))); |
| 4948 | pw.println("):"); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4949 | |
| 4950 | String prefix = " "; |
| 4951 | pw.print(prefix); pw.print("userId="); pw.println(su.userId); |
| 4952 | |
| 4953 | PermissionsState permissionsState = su.getPermissionsState(); |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 4954 | dumpInstallPermissionsLPr(pw, prefix, permissionNames, permissionsState); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4955 | |
| 4956 | for (int userId : UserManagerService.getInstance().getUserIds()) { |
| 4957 | final int[] gids = permissionsState.computeGids(userId); |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 4958 | List<PermissionState> permissions = permissionsState |
| 4959 | .getRuntimePermissionStates(userId); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4960 | if (!ArrayUtils.isEmpty(gids) || !permissions.isEmpty()) { |
| 4961 | pw.print(prefix); pw.print("User "); pw.print(userId); pw.println(": "); |
| 4962 | dumpGidsLPr(pw, prefix + " ", gids); |
Dianne Hackborn | 9f5b0a2 | 2015-08-13 18:25:20 -0700 | [diff] [blame] | 4963 | dumpRuntimePermissionsLPr(pw, prefix + " ", permissionNames, permissions, |
| 4964 | packageName != null); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 4965 | } |
Dianne Hackborn | d052a94 | 2014-11-21 15:23:13 -0800 | [diff] [blame] | 4966 | } |
| 4967 | } else { |
| 4968 | 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] | 4969 | } |
| 4970 | } |
| 4971 | } |
| 4972 | |
Netta P | 426cbef | 2017-02-10 14:38:39 -0800 | [diff] [blame] | 4973 | void dumpSharedUsersProto(ProtoOutputStream proto) { |
| 4974 | final int count = mSharedUsers.size(); |
| 4975 | for (int i = 0; i < count; i++) { |
Yi Jin | d6759d4 | 2017-10-12 15:08:49 -0700 | [diff] [blame] | 4976 | mSharedUsers.valueAt(i).writeToProto(proto, PackageServiceDumpProto.SHARED_USERS); |
Netta P | 426cbef | 2017-02-10 14:38:39 -0800 | [diff] [blame] | 4977 | } |
| 4978 | } |
| 4979 | |
Kenny Root | 447106f | 2011-03-23 11:00:15 -0700 | [diff] [blame] | 4980 | void dumpReadMessagesLPr(PrintWriter pw, DumpState dumpState) { |
| 4981 | pw.println("Settings parse messages:"); |
| 4982 | pw.print(mReadMessages.toString()); |
| 4983 | } |
Jeff Sharkey | c4d05fc | 2014-12-01 16:24:01 -0800 | [diff] [blame] | 4984 | |
Christopher Tate | e9fd1fa | 2015-09-15 16:43:07 -0700 | [diff] [blame] | 4985 | void dumpRestoredPermissionGrantsLPr(PrintWriter pw, DumpState dumpState) { |
| 4986 | if (mRestoredUserGrants.size() > 0) { |
| 4987 | pw.println(); |
| 4988 | pw.println("Restored (pending) permission grants:"); |
| 4989 | for (int userIndex = 0; userIndex < mRestoredUserGrants.size(); userIndex++) { |
| 4990 | ArrayMap<String, ArraySet<RestoredPermissionGrant>> grantsByPackage = |
| 4991 | mRestoredUserGrants.valueAt(userIndex); |
| 4992 | if (grantsByPackage != null && grantsByPackage.size() > 0) { |
| 4993 | final int userId = mRestoredUserGrants.keyAt(userIndex); |
| 4994 | pw.print(" User "); pw.println(userId); |
| 4995 | |
| 4996 | for (int pkgIndex = 0; pkgIndex < grantsByPackage.size(); pkgIndex++) { |
| 4997 | ArraySet<RestoredPermissionGrant> grants = grantsByPackage.valueAt(pkgIndex); |
| 4998 | if (grants != null && grants.size() > 0) { |
| 4999 | final String pkgName = grantsByPackage.keyAt(pkgIndex); |
| 5000 | pw.print(" "); pw.print(pkgName); pw.println(" :"); |
| 5001 | |
| 5002 | for (RestoredPermissionGrant g : grants) { |
| 5003 | pw.print(" "); |
| 5004 | pw.print(g.permissionName); |
| 5005 | if (g.granted) { |
| 5006 | pw.print(" GRANTED"); |
| 5007 | } |
| 5008 | if ((g.grantBits&FLAG_PERMISSION_USER_SET) != 0) { |
| 5009 | pw.print(" user_set"); |
| 5010 | } |
| 5011 | if ((g.grantBits&FLAG_PERMISSION_USER_FIXED) != 0) { |
| 5012 | pw.print(" user_fixed"); |
| 5013 | } |
| 5014 | if ((g.grantBits&FLAG_PERMISSION_REVOKE_ON_UPGRADE) != 0) { |
| 5015 | pw.print(" revoke_on_upgrade"); |
| 5016 | } |
Philip P. Moltmann | 17f65af | 2018-10-18 15:32:29 -0700 | [diff] [blame] | 5017 | if ((g.grantBits & FLAG_PERMISSION_REVOKE_WHEN_REQUESTED) != 0) { |
| 5018 | pw.print(" revoke_when_requested"); |
| 5019 | } |
Christopher Tate | e9fd1fa | 2015-09-15 16:43:07 -0700 | [diff] [blame] | 5020 | pw.println(); |
| 5021 | } |
| 5022 | } |
| 5023 | } |
| 5024 | } |
| 5025 | } |
| 5026 | pw.println(); |
| 5027 | } |
| 5028 | } |
| 5029 | |
Jeff Sharkey | c4d05fc | 2014-12-01 16:24:01 -0800 | [diff] [blame] | 5030 | private static void dumpSplitNames(PrintWriter pw, PackageParser.Package pkg) { |
| 5031 | if (pkg == null) { |
| 5032 | pw.print("unknown"); |
| 5033 | } else { |
| 5034 | // [base:10, config.mdpi, config.xhdpi:12] |
| 5035 | pw.print("["); |
| 5036 | pw.print("base"); |
| 5037 | if (pkg.baseRevisionCode != 0) { |
| 5038 | pw.print(":"); pw.print(pkg.baseRevisionCode); |
| 5039 | } |
| 5040 | if (pkg.splitNames != null) { |
| 5041 | for (int i = 0; i < pkg.splitNames.length; i++) { |
| 5042 | pw.print(", "); |
| 5043 | pw.print(pkg.splitNames[i]); |
| 5044 | if (pkg.splitRevisionCodes[i] != 0) { |
| 5045 | pw.print(":"); pw.print(pkg.splitRevisionCodes[i]); |
| 5046 | } |
| 5047 | } |
| 5048 | } |
| 5049 | pw.print("]"); |
| 5050 | } |
| 5051 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5052 | |
| 5053 | void dumpGidsLPr(PrintWriter pw, String prefix, int[] gids) { |
| 5054 | if (!ArrayUtils.isEmpty(gids)) { |
Fabrice Di Meglio | 6227172 | 2015-04-10 17:24:02 -0700 | [diff] [blame] | 5055 | pw.print(prefix); |
| 5056 | pw.print("gids="); pw.println( |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5057 | PackageManagerService.arrayToString(gids)); |
| 5058 | } |
| 5059 | } |
| 5060 | |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 5061 | void dumpRuntimePermissionsLPr(PrintWriter pw, String prefix, ArraySet<String> permissionNames, |
Dianne Hackborn | 9f5b0a2 | 2015-08-13 18:25:20 -0700 | [diff] [blame] | 5062 | List<PermissionState> permissionStates, boolean dumpAll) { |
| 5063 | if (!permissionStates.isEmpty() || dumpAll) { |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5064 | pw.print(prefix); pw.println("runtime permissions:"); |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5065 | for (PermissionState permissionState : permissionStates) { |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 5066 | if (permissionNames != null |
| 5067 | && !permissionNames.contains(permissionState.getName())) { |
| 5068 | continue; |
| 5069 | } |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5070 | pw.print(prefix); pw.print(" "); pw.print(permissionState.getName()); |
Dianne Hackborn | cfbfafe | 2015-07-21 16:57:51 -0700 | [diff] [blame] | 5071 | pw.print(": granted="); pw.print(permissionState.isGranted()); |
| 5072 | pw.println(permissionFlagsToString(", flags=", |
| 5073 | permissionState.getFlags())); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5074 | } |
| 5075 | } |
| 5076 | } |
| 5077 | |
Dianne Hackborn | cfbfafe | 2015-07-21 16:57:51 -0700 | [diff] [blame] | 5078 | private static String permissionFlagsToString(String prefix, int flags) { |
| 5079 | StringBuilder flagsString = null; |
Svet Ganov | 77ab6a8 | 2015-07-03 12:03:02 -0700 | [diff] [blame] | 5080 | while (flags != 0) { |
Dianne Hackborn | cfbfafe | 2015-07-21 16:57:51 -0700 | [diff] [blame] | 5081 | if (flagsString == null) { |
| 5082 | flagsString = new StringBuilder(); |
| 5083 | flagsString.append(prefix); |
| 5084 | flagsString.append("[ "); |
| 5085 | } |
Svet Ganov | 77ab6a8 | 2015-07-03 12:03:02 -0700 | [diff] [blame] | 5086 | final int flag = 1 << Integer.numberOfTrailingZeros(flags); |
| 5087 | flags &= ~flag; |
| 5088 | flagsString.append(PackageManager.permissionFlagToString(flag)); |
| 5089 | flagsString.append(' '); |
| 5090 | } |
Dianne Hackborn | cfbfafe | 2015-07-21 16:57:51 -0700 | [diff] [blame] | 5091 | if (flagsString != null) { |
| 5092 | flagsString.append(']'); |
| 5093 | return flagsString.toString(); |
| 5094 | } else { |
| 5095 | return ""; |
| 5096 | } |
Svet Ganov | 77ab6a8 | 2015-07-03 12:03:02 -0700 | [diff] [blame] | 5097 | } |
| 5098 | |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 5099 | void dumpInstallPermissionsLPr(PrintWriter pw, String prefix, ArraySet<String> permissionNames, |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5100 | PermissionsState permissionsState) { |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5101 | List<PermissionState> permissionStates = permissionsState.getInstallPermissionStates(); |
| 5102 | if (!permissionStates.isEmpty()) { |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5103 | pw.print(prefix); pw.println("install permissions:"); |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5104 | for (PermissionState permissionState : permissionStates) { |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 5105 | if (permissionNames != null |
| 5106 | && !permissionNames.contains(permissionState.getName())) { |
| 5107 | continue; |
| 5108 | } |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5109 | pw.print(prefix); pw.print(" "); pw.print(permissionState.getName()); |
Dianne Hackborn | cfbfafe | 2015-07-21 16:57:51 -0700 | [diff] [blame] | 5110 | pw.print(": granted="); pw.print(permissionState.isGranted()); |
| 5111 | pw.println(permissionFlagsToString(", flags=", |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5112 | permissionState.getFlags())); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5113 | } |
| 5114 | } |
| 5115 | } |
| 5116 | |
Makoto Onuki | 0a06858 | 2018-06-13 10:57:34 -0700 | [diff] [blame] | 5117 | void dumpComponents(PrintWriter pw, String prefix, PackageSetting ps) { |
| 5118 | dumpComponents(pw, prefix, ps, "activities:", ps.pkg.activities); |
| 5119 | dumpComponents(pw, prefix, ps, "services:", ps.pkg.services); |
| 5120 | dumpComponents(pw, prefix, ps, "receivers:", ps.pkg.receivers); |
| 5121 | dumpComponents(pw, prefix, ps, "providers:", ps.pkg.providers); |
| 5122 | dumpComponents(pw, prefix, ps, "instrumentations:", ps.pkg.instrumentation); |
| 5123 | } |
| 5124 | |
| 5125 | void dumpComponents(PrintWriter pw, String prefix, PackageSetting ps, |
| 5126 | String label, List<? extends PackageParser.Component<?>> list) { |
| 5127 | final int size = CollectionUtils.size(list); |
| 5128 | if (size == 0) { |
| 5129 | return; |
| 5130 | } |
| 5131 | pw.print(prefix);pw.println(label); |
| 5132 | for (int i = 0; i < size; i++) { |
| 5133 | final PackageParser.Component<?> component = list.get(i); |
| 5134 | pw.print(prefix);pw.print(" "); |
| 5135 | pw.println(component.getComponentName().flattenToShortString()); |
| 5136 | } |
| 5137 | } |
| 5138 | |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5139 | public void writeRuntimePermissionsForUserLPr(int userId, boolean sync) { |
| 5140 | if (sync) { |
| 5141 | mRuntimePermissionsPersistence.writePermissionsForUserSyncLPr(userId); |
| 5142 | } else { |
| 5143 | mRuntimePermissionsPersistence.writePermissionsForUserAsyncLPr(userId); |
| 5144 | } |
| 5145 | } |
| 5146 | |
| 5147 | private final class RuntimePermissionPersistence { |
| 5148 | private static final long WRITE_PERMISSIONS_DELAY_MILLIS = 200; |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5149 | private static final long MAX_WRITE_PERMISSIONS_DELAY_MILLIS = 2000; |
| 5150 | |
| 5151 | private final Handler mHandler = new MyHandler(); |
| 5152 | |
Todd Kennedy | 91a39d1 | 2017-09-27 12:37:04 -0700 | [diff] [blame] | 5153 | private final Object mPersistenceLock; |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5154 | |
| 5155 | @GuardedBy("mLock") |
Svet Ganov | ba3ba81 | 2015-06-26 10:54:06 -0700 | [diff] [blame] | 5156 | private final SparseBooleanArray mWriteScheduled = new SparseBooleanArray(); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5157 | |
| 5158 | @GuardedBy("mLock") |
Svet Ganov | ba3ba81 | 2015-06-26 10:54:06 -0700 | [diff] [blame] | 5159 | // The mapping keys are user ids. |
| 5160 | private final SparseLongArray mLastNotWrittenMutationTimesMillis = new SparseLongArray(); |
| 5161 | |
| 5162 | @GuardedBy("mLock") |
| 5163 | // The mapping keys are user ids. |
| 5164 | private final SparseArray<String> mFingerprints = new SparseArray<>(); |
| 5165 | |
| 5166 | @GuardedBy("mLock") |
| 5167 | // The mapping keys are user ids. |
| 5168 | private final SparseBooleanArray mDefaultPermissionsGranted = new SparseBooleanArray(); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5169 | |
Todd Kennedy | 91a39d1 | 2017-09-27 12:37:04 -0700 | [diff] [blame] | 5170 | public RuntimePermissionPersistence(Object persistenceLock) { |
| 5171 | mPersistenceLock = persistenceLock; |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5172 | } |
| 5173 | |
Andreas Gampe | 2e8c767 | 2018-07-20 13:01:08 -0700 | [diff] [blame] | 5174 | @GuardedBy("Settings.this.mLock") |
Svet Ganov | ba3ba81 | 2015-06-26 10:54:06 -0700 | [diff] [blame] | 5175 | public boolean areDefaultRuntimPermissionsGrantedLPr(int userId) { |
| 5176 | return mDefaultPermissionsGranted.get(userId); |
| 5177 | } |
| 5178 | |
Andreas Gampe | 2e8c767 | 2018-07-20 13:01:08 -0700 | [diff] [blame] | 5179 | @GuardedBy("Settings.this.mLock") |
Svet Ganov | ba3ba81 | 2015-06-26 10:54:06 -0700 | [diff] [blame] | 5180 | public void onDefaultRuntimePermissionsGrantedLPr(int userId) { |
| 5181 | mFingerprints.put(userId, Build.FINGERPRINT); |
| 5182 | writePermissionsForUserAsyncLPr(userId); |
| 5183 | } |
| 5184 | |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5185 | public void writePermissionsForUserSyncLPr(int userId) { |
| 5186 | mHandler.removeMessages(userId); |
| 5187 | writePermissionsSync(userId); |
| 5188 | } |
| 5189 | |
Andreas Gampe | 2e8c767 | 2018-07-20 13:01:08 -0700 | [diff] [blame] | 5190 | @GuardedBy("Settings.this.mLock") |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5191 | public void writePermissionsForUserAsyncLPr(int userId) { |
| 5192 | final long currentTimeMillis = SystemClock.uptimeMillis(); |
| 5193 | |
| 5194 | if (mWriteScheduled.get(userId)) { |
| 5195 | mHandler.removeMessages(userId); |
| 5196 | |
| 5197 | // If enough time passed, write without holding off anymore. |
| 5198 | final long lastNotWrittenMutationTimeMillis = mLastNotWrittenMutationTimesMillis |
| 5199 | .get(userId); |
| 5200 | final long timeSinceLastNotWrittenMutationMillis = currentTimeMillis |
| 5201 | - lastNotWrittenMutationTimeMillis; |
| 5202 | if (timeSinceLastNotWrittenMutationMillis >= MAX_WRITE_PERMISSIONS_DELAY_MILLIS) { |
| 5203 | mHandler.obtainMessage(userId).sendToTarget(); |
| 5204 | return; |
| 5205 | } |
| 5206 | |
| 5207 | // Hold off a bit more as settings are frequently changing. |
| 5208 | final long maxDelayMillis = Math.max(lastNotWrittenMutationTimeMillis |
| 5209 | + MAX_WRITE_PERMISSIONS_DELAY_MILLIS - currentTimeMillis, 0); |
| 5210 | final long writeDelayMillis = Math.min(WRITE_PERMISSIONS_DELAY_MILLIS, |
| 5211 | maxDelayMillis); |
| 5212 | |
| 5213 | Message message = mHandler.obtainMessage(userId); |
| 5214 | mHandler.sendMessageDelayed(message, writeDelayMillis); |
| 5215 | } else { |
| 5216 | mLastNotWrittenMutationTimesMillis.put(userId, currentTimeMillis); |
| 5217 | Message message = mHandler.obtainMessage(userId); |
| 5218 | mHandler.sendMessageDelayed(message, WRITE_PERMISSIONS_DELAY_MILLIS); |
| 5219 | mWriteScheduled.put(userId, true); |
| 5220 | } |
| 5221 | } |
| 5222 | |
| 5223 | private void writePermissionsSync(int userId) { |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 5224 | AtomicFile destination = new AtomicFile(getUserRuntimePermissionsFile(userId), |
| 5225 | "package-perms-" + userId); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5226 | |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5227 | ArrayMap<String, List<PermissionState>> permissionsForPackage = new ArrayMap<>(); |
| 5228 | ArrayMap<String, List<PermissionState>> permissionsForSharedUser = new ArrayMap<>(); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5229 | |
Todd Kennedy | 91a39d1 | 2017-09-27 12:37:04 -0700 | [diff] [blame] | 5230 | synchronized (mPersistenceLock) { |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5231 | mWriteScheduled.delete(userId); |
| 5232 | |
| 5233 | final int packageCount = mPackages.size(); |
| 5234 | for (int i = 0; i < packageCount; i++) { |
| 5235 | String packageName = mPackages.keyAt(i); |
| 5236 | PackageSetting packageSetting = mPackages.valueAt(i); |
| 5237 | if (packageSetting.sharedUser == null) { |
| 5238 | PermissionsState permissionsState = packageSetting.getPermissionsState(); |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5239 | List<PermissionState> permissionsStates = permissionsState |
| 5240 | .getRuntimePermissionStates(userId); |
| 5241 | if (!permissionsStates.isEmpty()) { |
| 5242 | permissionsForPackage.put(packageName, permissionsStates); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5243 | } |
| 5244 | } |
| 5245 | } |
| 5246 | |
| 5247 | final int sharedUserCount = mSharedUsers.size(); |
| 5248 | for (int i = 0; i < sharedUserCount; i++) { |
| 5249 | String sharedUserName = mSharedUsers.keyAt(i); |
| 5250 | SharedUserSetting sharedUser = mSharedUsers.valueAt(i); |
| 5251 | PermissionsState permissionsState = sharedUser.getPermissionsState(); |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5252 | List<PermissionState> permissionsStates = permissionsState |
| 5253 | .getRuntimePermissionStates(userId); |
| 5254 | if (!permissionsStates.isEmpty()) { |
| 5255 | permissionsForSharedUser.put(sharedUserName, permissionsStates); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5256 | } |
| 5257 | } |
| 5258 | } |
| 5259 | |
| 5260 | FileOutputStream out = null; |
| 5261 | try { |
| 5262 | out = destination.startWrite(); |
| 5263 | |
| 5264 | XmlSerializer serializer = Xml.newSerializer(); |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 5265 | serializer.setOutput(out, StandardCharsets.UTF_8.name()); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5266 | serializer.setFeature( |
| 5267 | "http://xmlpull.org/v1/doc/features.html#indent-output", true); |
| 5268 | serializer.startDocument(null, true); |
Christopher Tate | e9fd1fa | 2015-09-15 16:43:07 -0700 | [diff] [blame] | 5269 | |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5270 | serializer.startTag(null, TAG_RUNTIME_PERMISSIONS); |
| 5271 | |
Svet Ganov | ba3ba81 | 2015-06-26 10:54:06 -0700 | [diff] [blame] | 5272 | String fingerprint = mFingerprints.get(userId); |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 5273 | if (fingerprint != null) { |
| 5274 | serializer.attribute(null, ATTR_FINGERPRINT, fingerprint); |
| 5275 | } |
Svet Ganov | ba3ba81 | 2015-06-26 10:54:06 -0700 | [diff] [blame] | 5276 | |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5277 | final int packageCount = permissionsForPackage.size(); |
| 5278 | for (int i = 0; i < packageCount; i++) { |
| 5279 | String packageName = permissionsForPackage.keyAt(i); |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5280 | List<PermissionState> permissionStates = permissionsForPackage.valueAt(i); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5281 | serializer.startTag(null, TAG_PACKAGE); |
| 5282 | serializer.attribute(null, ATTR_NAME, packageName); |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5283 | writePermissions(serializer, permissionStates); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5284 | serializer.endTag(null, TAG_PACKAGE); |
| 5285 | } |
| 5286 | |
| 5287 | final int sharedUserCount = permissionsForSharedUser.size(); |
| 5288 | for (int i = 0; i < sharedUserCount; i++) { |
| 5289 | String packageName = permissionsForSharedUser.keyAt(i); |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5290 | List<PermissionState> permissionStates = permissionsForSharedUser.valueAt(i); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5291 | serializer.startTag(null, TAG_SHARED_USER); |
| 5292 | serializer.attribute(null, ATTR_NAME, packageName); |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5293 | writePermissions(serializer, permissionStates); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5294 | serializer.endTag(null, TAG_SHARED_USER); |
| 5295 | } |
| 5296 | |
| 5297 | serializer.endTag(null, TAG_RUNTIME_PERMISSIONS); |
Christopher Tate | e9fd1fa | 2015-09-15 16:43:07 -0700 | [diff] [blame] | 5298 | |
| 5299 | // Now any restored permission grants that are waiting for the apps |
| 5300 | // in question to be installed. These are stored as per-package |
| 5301 | // TAG_RESTORED_RUNTIME_PERMISSIONS blocks, each containing some |
| 5302 | // number of individual permission grant entities. |
| 5303 | if (mRestoredUserGrants.get(userId) != null) { |
| 5304 | ArrayMap<String, ArraySet<RestoredPermissionGrant>> restoredGrants = |
| 5305 | mRestoredUserGrants.get(userId); |
| 5306 | if (restoredGrants != null) { |
| 5307 | final int pkgCount = restoredGrants.size(); |
| 5308 | for (int i = 0; i < pkgCount; i++) { |
| 5309 | final ArraySet<RestoredPermissionGrant> pkgGrants = |
| 5310 | restoredGrants.valueAt(i); |
| 5311 | if (pkgGrants != null && pkgGrants.size() > 0) { |
| 5312 | final String pkgName = restoredGrants.keyAt(i); |
| 5313 | serializer.startTag(null, TAG_RESTORED_RUNTIME_PERMISSIONS); |
| 5314 | serializer.attribute(null, ATTR_PACKAGE_NAME, pkgName); |
| 5315 | |
| 5316 | final int N = pkgGrants.size(); |
| 5317 | for (int z = 0; z < N; z++) { |
| 5318 | RestoredPermissionGrant g = pkgGrants.valueAt(z); |
| 5319 | serializer.startTag(null, TAG_PERMISSION_ENTRY); |
| 5320 | serializer.attribute(null, ATTR_NAME, g.permissionName); |
| 5321 | |
| 5322 | if (g.granted) { |
| 5323 | serializer.attribute(null, ATTR_GRANTED, "true"); |
| 5324 | } |
| 5325 | |
| 5326 | if ((g.grantBits&FLAG_PERMISSION_USER_SET) != 0) { |
| 5327 | serializer.attribute(null, ATTR_USER_SET, "true"); |
| 5328 | } |
| 5329 | if ((g.grantBits&FLAG_PERMISSION_USER_FIXED) != 0) { |
| 5330 | serializer.attribute(null, ATTR_USER_FIXED, "true"); |
| 5331 | } |
| 5332 | if ((g.grantBits&FLAG_PERMISSION_REVOKE_ON_UPGRADE) != 0) { |
| 5333 | serializer.attribute(null, ATTR_REVOKE_ON_UPGRADE, "true"); |
| 5334 | } |
Philip P. Moltmann | 17f65af | 2018-10-18 15:32:29 -0700 | [diff] [blame] | 5335 | if ((g.grantBits & FLAG_PERMISSION_REVOKE_WHEN_REQUESTED) |
| 5336 | != 0) { |
| 5337 | serializer.attribute(null, ATTR_REVOKE_WHEN_REQUESTED, |
| 5338 | "true"); |
| 5339 | } |
Christopher Tate | e9fd1fa | 2015-09-15 16:43:07 -0700 | [diff] [blame] | 5340 | serializer.endTag(null, TAG_PERMISSION_ENTRY); |
| 5341 | } |
| 5342 | serializer.endTag(null, TAG_RESTORED_RUNTIME_PERMISSIONS); |
| 5343 | } |
| 5344 | } |
| 5345 | } |
| 5346 | } |
| 5347 | |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5348 | serializer.endDocument(); |
| 5349 | destination.finishWrite(out); |
Svet Ganov | ba0821e | 2015-04-22 13:34:31 -0700 | [diff] [blame] | 5350 | |
Svet Ganov | ba3ba81 | 2015-06-26 10:54:06 -0700 | [diff] [blame] | 5351 | if (Build.FINGERPRINT.equals(fingerprint)) { |
| 5352 | mDefaultPermissionsGranted.put(userId, true); |
| 5353 | } |
| 5354 | // Any error while writing is fatal. |
Svet Ganov | ba0821e | 2015-04-22 13:34:31 -0700 | [diff] [blame] | 5355 | } catch (Throwable t) { |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5356 | Slog.wtf(PackageManagerService.TAG, |
Svet Ganov | ba0821e | 2015-04-22 13:34:31 -0700 | [diff] [blame] | 5357 | "Failed to write settings, restoring backup", t); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5358 | destination.failWrite(out); |
| 5359 | } finally { |
| 5360 | IoUtils.closeQuietly(out); |
| 5361 | } |
| 5362 | } |
| 5363 | |
Andreas Gampe | 2e8c767 | 2018-07-20 13:01:08 -0700 | [diff] [blame] | 5364 | @GuardedBy("Settings.this.mLock") |
Fyodor Kupolov | 6954259 | 2016-05-23 14:22:38 -0700 | [diff] [blame] | 5365 | private void onUserRemovedLPw(int userId) { |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5366 | // Make sure we do not |
| 5367 | mHandler.removeMessages(userId); |
| 5368 | |
| 5369 | for (SettingBase sb : mPackages.values()) { |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5370 | revokeRuntimePermissionsAndClearFlags(sb, userId); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5371 | } |
| 5372 | |
| 5373 | for (SettingBase sb : mSharedUsers.values()) { |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5374 | revokeRuntimePermissionsAndClearFlags(sb, userId); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5375 | } |
Fyodor Kupolov | 6954259 | 2016-05-23 14:22:38 -0700 | [diff] [blame] | 5376 | |
| 5377 | mDefaultPermissionsGranted.delete(userId); |
| 5378 | mFingerprints.remove(userId); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5379 | } |
| 5380 | |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5381 | private void revokeRuntimePermissionsAndClearFlags(SettingBase sb, int userId) { |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5382 | PermissionsState permissionsState = sb.getPermissionsState(); |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5383 | for (PermissionState permissionState |
| 5384 | : permissionsState.getRuntimePermissionStates(userId)) { |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 5385 | BasePermission bp = mPermissions.getPermission(permissionState.getName()); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5386 | if (bp != null) { |
| 5387 | permissionsState.revokeRuntimePermission(bp, userId); |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5388 | permissionsState.updatePermissionFlags(bp, userId, |
| 5389 | PackageManager.MASK_PERMISSION_FLAGS, 0); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5390 | } |
| 5391 | } |
| 5392 | } |
| 5393 | |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 5394 | public void deleteUserRuntimePermissionsFile(int userId) { |
| 5395 | getUserRuntimePermissionsFile(userId).delete(); |
| 5396 | } |
| 5397 | |
Andreas Gampe | 2e8c767 | 2018-07-20 13:01:08 -0700 | [diff] [blame] | 5398 | @GuardedBy("Settings.this.mLock") |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5399 | public void readStateForUserSyncLPr(int userId) { |
| 5400 | File permissionsFile = getUserRuntimePermissionsFile(userId); |
| 5401 | if (!permissionsFile.exists()) { |
| 5402 | return; |
| 5403 | } |
| 5404 | |
| 5405 | FileInputStream in; |
| 5406 | try { |
Svetoslav | 3dcdd37 | 2015-05-29 13:00:32 -0700 | [diff] [blame] | 5407 | in = new AtomicFile(permissionsFile).openRead(); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5408 | } catch (FileNotFoundException fnfe) { |
| 5409 | Slog.i(PackageManagerService.TAG, "No permissions state"); |
| 5410 | return; |
| 5411 | } |
| 5412 | |
| 5413 | try { |
| 5414 | XmlPullParser parser = Xml.newPullParser(); |
| 5415 | parser.setInput(in, null); |
| 5416 | parseRuntimePermissionsLPr(parser, userId); |
Svet Ganov | ba0821e | 2015-04-22 13:34:31 -0700 | [diff] [blame] | 5417 | |
Svet Ganov | e723e54 | 2015-04-23 11:58:26 -0700 | [diff] [blame] | 5418 | } catch (XmlPullParserException | IOException e) { |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5419 | throw new IllegalStateException("Failed parsing permissions file: " |
Svet Ganov | e723e54 | 2015-04-23 11:58:26 -0700 | [diff] [blame] | 5420 | + permissionsFile , e); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5421 | } finally { |
| 5422 | IoUtils.closeQuietly(in); |
| 5423 | } |
| 5424 | } |
| 5425 | |
Christopher Tate | e9fd1fa | 2015-09-15 16:43:07 -0700 | [diff] [blame] | 5426 | // Backup/restore support |
| 5427 | |
| 5428 | public void rememberRestoredUserGrantLPr(String pkgName, String permission, |
| 5429 | boolean isGranted, int restoredFlagSet, int userId) { |
| 5430 | // This change will be remembered at write-settings time |
| 5431 | ArrayMap<String, ArraySet<RestoredPermissionGrant>> grantsByPackage = |
| 5432 | mRestoredUserGrants.get(userId); |
| 5433 | if (grantsByPackage == null) { |
| 5434 | grantsByPackage = new ArrayMap<String, ArraySet<RestoredPermissionGrant>>(); |
| 5435 | mRestoredUserGrants.put(userId, grantsByPackage); |
| 5436 | } |
| 5437 | |
| 5438 | ArraySet<RestoredPermissionGrant> grants = grantsByPackage.get(pkgName); |
| 5439 | if (grants == null) { |
| 5440 | grants = new ArraySet<RestoredPermissionGrant>(); |
| 5441 | grantsByPackage.put(pkgName, grants); |
| 5442 | } |
| 5443 | |
| 5444 | RestoredPermissionGrant grant = new RestoredPermissionGrant(permission, |
| 5445 | isGranted, restoredFlagSet); |
| 5446 | grants.add(grant); |
| 5447 | } |
| 5448 | |
| 5449 | // Private internals |
| 5450 | |
Andreas Gampe | 2e8c767 | 2018-07-20 13:01:08 -0700 | [diff] [blame] | 5451 | @GuardedBy("Settings.this.mLock") |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5452 | private void parseRuntimePermissionsLPr(XmlPullParser parser, int userId) |
| 5453 | throws IOException, XmlPullParserException { |
Svet Ganov | 12a692a | 2015-03-28 19:34:15 -0700 | [diff] [blame] | 5454 | final int outerDepth = parser.getDepth(); |
| 5455 | int type; |
| 5456 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 5457 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 5458 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 5459 | continue; |
| 5460 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5461 | |
Svet Ganov | 12a692a | 2015-03-28 19:34:15 -0700 | [diff] [blame] | 5462 | switch (parser.getName()) { |
Svet Ganov | ba3ba81 | 2015-06-26 10:54:06 -0700 | [diff] [blame] | 5463 | case TAG_RUNTIME_PERMISSIONS: { |
| 5464 | String fingerprint = parser.getAttributeValue(null, ATTR_FINGERPRINT); |
| 5465 | mFingerprints.put(userId, fingerprint); |
| 5466 | final boolean defaultsGranted = Build.FINGERPRINT.equals(fingerprint); |
| 5467 | mDefaultPermissionsGranted.put(userId, defaultsGranted); |
| 5468 | } break; |
| 5469 | |
Svet Ganov | 12a692a | 2015-03-28 19:34:15 -0700 | [diff] [blame] | 5470 | case TAG_PACKAGE: { |
| 5471 | String name = parser.getAttributeValue(null, ATTR_NAME); |
| 5472 | PackageSetting ps = mPackages.get(name); |
| 5473 | if (ps == null) { |
| 5474 | Slog.w(PackageManagerService.TAG, "Unknown package:" + name); |
| 5475 | XmlUtils.skipCurrentTag(parser); |
| 5476 | continue; |
| 5477 | } |
| 5478 | parsePermissionsLPr(parser, ps.getPermissionsState(), userId); |
| 5479 | } break; |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5480 | |
Svet Ganov | 12a692a | 2015-03-28 19:34:15 -0700 | [diff] [blame] | 5481 | case TAG_SHARED_USER: { |
| 5482 | String name = parser.getAttributeValue(null, ATTR_NAME); |
| 5483 | SharedUserSetting sus = mSharedUsers.get(name); |
| 5484 | if (sus == null) { |
| 5485 | Slog.w(PackageManagerService.TAG, "Unknown shared user:" + name); |
| 5486 | XmlUtils.skipCurrentTag(parser); |
| 5487 | continue; |
| 5488 | } |
| 5489 | parsePermissionsLPr(parser, sus.getPermissionsState(), userId); |
| 5490 | } break; |
Christopher Tate | e9fd1fa | 2015-09-15 16:43:07 -0700 | [diff] [blame] | 5491 | |
| 5492 | case TAG_RESTORED_RUNTIME_PERMISSIONS: { |
| 5493 | final String pkgName = parser.getAttributeValue(null, ATTR_PACKAGE_NAME); |
| 5494 | parseRestoredRuntimePermissionsLPr(parser, pkgName, userId); |
| 5495 | } break; |
| 5496 | } |
| 5497 | } |
| 5498 | } |
| 5499 | |
| 5500 | private void parseRestoredRuntimePermissionsLPr(XmlPullParser parser, |
| 5501 | final String pkgName, final int userId) throws IOException, XmlPullParserException { |
| 5502 | final int outerDepth = parser.getDepth(); |
| 5503 | int type; |
| 5504 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 5505 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 5506 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 5507 | continue; |
| 5508 | } |
| 5509 | |
| 5510 | switch (parser.getName()) { |
| 5511 | case TAG_PERMISSION_ENTRY: { |
| 5512 | final String permName = parser.getAttributeValue(null, ATTR_NAME); |
| 5513 | final boolean isGranted = "true".equals( |
| 5514 | parser.getAttributeValue(null, ATTR_GRANTED)); |
| 5515 | |
| 5516 | int permBits = 0; |
| 5517 | if ("true".equals(parser.getAttributeValue(null, ATTR_USER_SET))) { |
| 5518 | permBits |= FLAG_PERMISSION_USER_SET; |
| 5519 | } |
| 5520 | if ("true".equals(parser.getAttributeValue(null, ATTR_USER_FIXED))) { |
| 5521 | permBits |= FLAG_PERMISSION_USER_FIXED; |
| 5522 | } |
| 5523 | if ("true".equals(parser.getAttributeValue(null, ATTR_REVOKE_ON_UPGRADE))) { |
| 5524 | permBits |= FLAG_PERMISSION_REVOKE_ON_UPGRADE; |
| 5525 | } |
Philip P. Moltmann | 17f65af | 2018-10-18 15:32:29 -0700 | [diff] [blame] | 5526 | if ("true".equals(parser.getAttributeValue(null, |
| 5527 | ATTR_REVOKE_WHEN_REQUESTED))) { |
| 5528 | permBits |= FLAG_PERMISSION_REVOKE_WHEN_REQUESTED; |
| 5529 | } |
Christopher Tate | e9fd1fa | 2015-09-15 16:43:07 -0700 | [diff] [blame] | 5530 | |
| 5531 | if (isGranted || permBits != 0) { |
| 5532 | rememberRestoredUserGrantLPr(pkgName, permName, isGranted, permBits, userId); |
| 5533 | } |
| 5534 | } break; |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5535 | } |
| 5536 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5537 | } |
| 5538 | |
Svet Ganov | 12a692a | 2015-03-28 19:34:15 -0700 | [diff] [blame] | 5539 | private void parsePermissionsLPr(XmlPullParser parser, PermissionsState permissionsState, |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5540 | int userId) throws IOException, XmlPullParserException { |
Svet Ganov | 12a692a | 2015-03-28 19:34:15 -0700 | [diff] [blame] | 5541 | final int outerDepth = parser.getDepth(); |
| 5542 | int type; |
| 5543 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 5544 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 5545 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 5546 | continue; |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5547 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5548 | |
Svet Ganov | 12a692a | 2015-03-28 19:34:15 -0700 | [diff] [blame] | 5549 | switch (parser.getName()) { |
| 5550 | case TAG_ITEM: { |
| 5551 | String name = parser.getAttributeValue(null, ATTR_NAME); |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 5552 | BasePermission bp = mPermissions.getPermission(name); |
Svet Ganov | 12a692a | 2015-03-28 19:34:15 -0700 | [diff] [blame] | 5553 | if (bp == null) { |
| 5554 | Slog.w(PackageManagerService.TAG, "Unknown permission:" + name); |
| 5555 | XmlUtils.skipCurrentTag(parser); |
| 5556 | continue; |
| 5557 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5558 | |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5559 | String grantedStr = parser.getAttributeValue(null, ATTR_GRANTED); |
| 5560 | final boolean granted = grantedStr == null |
| 5561 | || Boolean.parseBoolean(grantedStr); |
| 5562 | |
| 5563 | String flagsStr = parser.getAttributeValue(null, ATTR_FLAGS); |
| 5564 | final int flags = (flagsStr != null) |
| 5565 | ? Integer.parseInt(flagsStr, 16) : 0; |
| 5566 | |
| 5567 | if (granted) { |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 5568 | permissionsState.grantRuntimePermission(bp, userId); |
| 5569 | permissionsState.updatePermissionFlags(bp, userId, |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5570 | PackageManager.MASK_PERMISSION_FLAGS, flags); |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5571 | } else { |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 5572 | permissionsState.updatePermissionFlags(bp, userId, |
| 5573 | PackageManager.MASK_PERMISSION_FLAGS, flags); |
Svet Ganov | 12a692a | 2015-03-28 19:34:15 -0700 | [diff] [blame] | 5574 | } |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5575 | |
Svet Ganov | 12a692a | 2015-03-28 19:34:15 -0700 | [diff] [blame] | 5576 | } break; |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5577 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5578 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5579 | } |
| 5580 | |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5581 | private void writePermissions(XmlSerializer serializer, |
| 5582 | List<PermissionState> permissionStates) throws IOException { |
| 5583 | for (PermissionState permissionState : permissionStates) { |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5584 | serializer.startTag(null, TAG_ITEM); |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 5585 | serializer.attribute(null, ATTR_NAME,permissionState.getName()); |
| 5586 | serializer.attribute(null, ATTR_GRANTED, |
| 5587 | String.valueOf(permissionState.isGranted())); |
| 5588 | serializer.attribute(null, ATTR_FLAGS, |
| 5589 | Integer.toHexString(permissionState.getFlags())); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 5590 | serializer.endTag(null, TAG_ITEM); |
| 5591 | } |
| 5592 | } |
| 5593 | |
| 5594 | private final class MyHandler extends Handler { |
| 5595 | public MyHandler() { |
| 5596 | super(BackgroundThread.getHandler().getLooper()); |
| 5597 | } |
| 5598 | |
| 5599 | @Override |
| 5600 | public void handleMessage(Message message) { |
| 5601 | final int userId = message.what; |
| 5602 | Runnable callback = (Runnable) message.obj; |
| 5603 | writePermissionsSync(userId); |
| 5604 | if (callback != null) { |
| 5605 | callback.run(); |
| 5606 | } |
| 5607 | } |
| 5608 | } |
| 5609 | } |
Andy McFadden | 2f36229 | 2012-01-20 14:43:38 -0800 | [diff] [blame] | 5610 | } |