Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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 android.app; |
| 18 | |
Adam Lesinski | d33ef56 | 2017-01-19 14:49:59 -0800 | [diff] [blame] | 19 | import android.annotation.NonNull; |
| 20 | import android.annotation.Nullable; |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 21 | import android.annotation.UnsupportedAppUsage; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 22 | import android.content.BroadcastReceiver; |
| 23 | import android.content.ComponentName; |
| 24 | import android.content.Context; |
| 25 | import android.content.IIntentReceiver; |
| 26 | import android.content.Intent; |
| 27 | import android.content.ServiceConnection; |
| 28 | import android.content.pm.ApplicationInfo; |
| 29 | import android.content.pm.IPackageManager; |
| 30 | import android.content.pm.PackageManager; |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 31 | import android.content.pm.PackageManager.NameNotFoundException; |
Calin Juravle | 6ae39fc | 2018-01-19 20:32:47 -0800 | [diff] [blame] | 32 | import android.content.pm.dex.ArtManager; |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 33 | import android.content.pm.split.SplitDependencyLoader; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 34 | import android.content.res.AssetManager; |
| 35 | import android.content.res.CompatibilityInfo; |
| 36 | import android.content.res.Resources; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 37 | import android.os.Build; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 38 | import android.os.Bundle; |
Jeff Sharkey | 1544779 | 2015-11-05 16:18:51 -0800 | [diff] [blame] | 39 | import android.os.FileUtils; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 40 | import android.os.Handler; |
| 41 | import android.os.IBinder; |
| 42 | import android.os.Process; |
| 43 | import android.os.RemoteException; |
Brad Fitzpatrick | 624d50f | 2010-11-09 14:25:12 -0800 | [diff] [blame] | 44 | import android.os.StrictMode; |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 45 | import android.os.SystemProperties; |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 46 | import android.os.Trace; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 47 | import android.os.UserHandle; |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 48 | import android.text.TextUtils; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 49 | import android.util.AndroidRuntimeException; |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 50 | import android.util.ArrayMap; |
Adam Lesinski | 2cb761e | 2014-08-15 13:59:02 -0700 | [diff] [blame] | 51 | import android.util.Log; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 52 | import android.util.Slog; |
Adam Lesinski | de898ff | 2014-01-29 18:20:45 -0800 | [diff] [blame] | 53 | import android.util.SparseArray; |
Jeff Brown | a492c3a | 2012-08-23 19:48:44 -0700 | [diff] [blame] | 54 | import android.view.Display; |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 55 | import android.view.DisplayAdjustments; |
Calin Juravle | 6ae39fc | 2018-01-19 20:32:47 -0800 | [diff] [blame] | 56 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 57 | import com.android.internal.util.ArrayUtils; |
Calin Juravle | 6ae39fc | 2018-01-19 20:32:47 -0800 | [diff] [blame] | 58 | |
Narayan Kamath | 7dba6eb | 2014-07-16 08:53:30 +0100 | [diff] [blame] | 59 | import dalvik.system.VMRuntime; |
Calin Juravle | 6ae39fc | 2018-01-19 20:32:47 -0800 | [diff] [blame] | 60 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 61 | import java.io.File; |
| 62 | import java.io.IOException; |
| 63 | import java.io.InputStream; |
| 64 | import java.lang.ref.WeakReference; |
Adam Lesinski | 1e466385 | 2014-08-15 14:47:28 -0700 | [diff] [blame] | 65 | import java.lang.reflect.InvocationTargetException; |
| 66 | import java.lang.reflect.Method; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 67 | import java.net.URL; |
Jiyong Park | 29d9eba | 2018-05-04 12:44:38 +0900 | [diff] [blame] | 68 | import java.nio.file.Paths; |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 69 | import java.util.ArrayList; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 70 | import java.util.Arrays; |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 71 | import java.util.Collections; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 72 | import java.util.Enumeration; |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 73 | import java.util.List; |
Narayan Kamath | 2053168 | 2014-07-14 13:18:43 +0100 | [diff] [blame] | 74 | import java.util.Objects; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 75 | |
| 76 | final class IntentReceiverLeaked extends AndroidRuntimeException { |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 77 | @UnsupportedAppUsage |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 78 | public IntentReceiverLeaked(String msg) { |
| 79 | super(msg); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | final class ServiceConnectionLeaked extends AndroidRuntimeException { |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 84 | @UnsupportedAppUsage |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 85 | public ServiceConnectionLeaked(String msg) { |
| 86 | super(msg); |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Local state maintained about a currently loaded .apk. |
| 92 | * @hide |
| 93 | */ |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 94 | public final class LoadedApk { |
Dianne Hackborn | 9484603 | 2017-03-31 17:55:23 -0700 | [diff] [blame] | 95 | static final String TAG = "LoadedApk"; |
| 96 | static final boolean DEBUG = false; |
Patrick Baumann | 1bea237 | 2018-03-13 14:26:58 -0700 | [diff] [blame] | 97 | private static final String PROPERTY_NAME_APPEND_NATIVE = "pi.append_native_lib_paths"; |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 98 | |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 99 | @UnsupportedAppUsage |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 100 | private final ActivityThread mActivityThread; |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 101 | @UnsupportedAppUsage |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 102 | final String mPackageName; |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 103 | @UnsupportedAppUsage |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 104 | private ApplicationInfo mApplicationInfo; |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 105 | @UnsupportedAppUsage |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 106 | private String mAppDir; |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 107 | @UnsupportedAppUsage |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 108 | private String mResDir; |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 109 | private String[] mOverlayDirs; |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 110 | @UnsupportedAppUsage |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 111 | private String mDataDir; |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 112 | @UnsupportedAppUsage |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 113 | private String mLibDir; |
Mathew Inwood | 45d2c25 | 2018-09-14 12:35:36 +0100 | [diff] [blame] | 114 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 115 | private File mDataDirFile; |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 116 | private File mDeviceProtectedDataDirFile; |
| 117 | private File mCredentialProtectedDataDirFile; |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 118 | @UnsupportedAppUsage |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 119 | private final ClassLoader mBaseClassLoader; |
| 120 | private final boolean mSecurityViolation; |
| 121 | private final boolean mIncludeCode; |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 122 | private final boolean mRegisterPackage; |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 123 | @UnsupportedAppUsage |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 124 | private final DisplayAdjustments mDisplayAdjustments = new DisplayAdjustments(); |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 125 | /** WARNING: This may change. Don't hold external references to it. */ |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 126 | @UnsupportedAppUsage |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 127 | Resources mResources; |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 128 | @UnsupportedAppUsage |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 129 | private ClassLoader mClassLoader; |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 130 | @UnsupportedAppUsage |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 131 | private Application mApplication; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 132 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 133 | private String[] mSplitNames; |
| 134 | private String[] mSplitAppDirs; |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 135 | @UnsupportedAppUsage |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 136 | private String[] mSplitResDirs; |
Narayan Kamath | f9419f0 | 2017-06-15 11:35:38 +0100 | [diff] [blame] | 137 | private String[] mSplitClassLoaderNames; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 138 | |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 139 | @UnsupportedAppUsage |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 140 | private final ArrayMap<Context, ArrayMap<BroadcastReceiver, ReceiverDispatcher>> mReceivers |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 141 | = new ArrayMap<>(); |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 142 | private final ArrayMap<Context, ArrayMap<BroadcastReceiver, LoadedApk.ReceiverDispatcher>> mUnregisteredReceivers |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 143 | = new ArrayMap<>(); |
Mathew Inwood | 45d2c25 | 2018-09-14 12:35:36 +0100 | [diff] [blame] | 144 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 145 | private final ArrayMap<Context, ArrayMap<ServiceConnection, LoadedApk.ServiceDispatcher>> mServices |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 146 | = new ArrayMap<>(); |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 147 | private final ArrayMap<Context, ArrayMap<ServiceConnection, LoadedApk.ServiceDispatcher>> mUnboundServices |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 148 | = new ArrayMap<>(); |
Jason Monk | a80bfb5 | 2017-11-16 17:15:37 -0500 | [diff] [blame] | 149 | private AppComponentFactory mAppComponentFactory; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 150 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 151 | Application getApplication() { |
| 152 | return mApplication; |
| 153 | } |
| 154 | |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 155 | /** |
| 156 | * Create information about a new .apk |
| 157 | * |
| 158 | * NOTE: This constructor is called with ActivityThread's lock held, |
| 159 | * so MUST NOT call back out to the activity manager. |
| 160 | */ |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 161 | public LoadedApk(ActivityThread activityThread, ApplicationInfo aInfo, |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 162 | CompatibilityInfo compatInfo, ClassLoader baseLoader, |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 163 | boolean securityViolation, boolean includeCode, boolean registerPackage) { |
Narayan Kamath | 7dba6eb | 2014-07-16 08:53:30 +0100 | [diff] [blame] | 164 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 165 | mActivityThread = activityThread; |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 166 | setApplicationInfo(aInfo); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 167 | mPackageName = aInfo.packageName; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 168 | mBaseClassLoader = baseLoader; |
| 169 | mSecurityViolation = securityViolation; |
| 170 | mIncludeCode = includeCode; |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 171 | mRegisterPackage = registerPackage; |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 172 | mDisplayAdjustments.setCompatibilityInfo(compatInfo); |
Jason Monk | a80bfb5 | 2017-11-16 17:15:37 -0500 | [diff] [blame] | 173 | mAppComponentFactory = createAppFactory(mApplicationInfo, mBaseClassLoader); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 174 | } |
| 175 | |
Narayan Kamath | 7dba6eb | 2014-07-16 08:53:30 +0100 | [diff] [blame] | 176 | private static ApplicationInfo adjustNativeLibraryPaths(ApplicationInfo info) { |
| 177 | // If we're dealing with a multi-arch application that has both |
| 178 | // 32 and 64 bit shared libraries, we might need to choose the secondary |
| 179 | // depending on what the current runtime's instruction set is. |
| 180 | if (info.primaryCpuAbi != null && info.secondaryCpuAbi != null) { |
| 181 | final String runtimeIsa = VMRuntime.getRuntime().vmInstructionSet(); |
jgu21 | 4741cd9 | 2014-12-17 17:23:29 -0500 | [diff] [blame] | 182 | |
| 183 | // Get the instruction set that the libraries of secondary Abi is supported. |
| 184 | // In presence of a native bridge this might be different than the one secondary Abi used. |
| 185 | String secondaryIsa = VMRuntime.getInstructionSet(info.secondaryCpuAbi); |
| 186 | final String secondaryDexCodeIsa = SystemProperties.get("ro.dalvik.vm.isa." + secondaryIsa); |
| 187 | secondaryIsa = secondaryDexCodeIsa.isEmpty() ? secondaryIsa : secondaryDexCodeIsa; |
Narayan Kamath | 7dba6eb | 2014-07-16 08:53:30 +0100 | [diff] [blame] | 188 | |
| 189 | // If the runtimeIsa is the same as the primary isa, then we do nothing. |
| 190 | // Everything will be set up correctly because info.nativeLibraryDir will |
| 191 | // correspond to the right ISA. |
| 192 | if (runtimeIsa.equals(secondaryIsa)) { |
| 193 | final ApplicationInfo modified = new ApplicationInfo(info); |
| 194 | modified.nativeLibraryDir = modified.secondaryNativeLibraryDir; |
Dmitriy Ivanov | e56b3f6 | 2015-06-05 22:00:13 -0700 | [diff] [blame] | 195 | modified.primaryCpuAbi = modified.secondaryCpuAbi; |
Narayan Kamath | 7dba6eb | 2014-07-16 08:53:30 +0100 | [diff] [blame] | 196 | return modified; |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | return info; |
| 201 | } |
| 202 | |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 203 | /** |
| 204 | * Create information about the system package. |
| 205 | * Must call {@link #installSystemApplicationInfo} later. |
| 206 | */ |
| 207 | LoadedApk(ActivityThread activityThread) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 208 | mActivityThread = activityThread; |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 209 | mApplicationInfo = new ApplicationInfo(); |
| 210 | mApplicationInfo.packageName = "android"; |
| 211 | mPackageName = "android"; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 212 | mAppDir = null; |
| 213 | mResDir = null; |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 214 | mSplitAppDirs = null; |
| 215 | mSplitResDirs = null; |
Narayan Kamath | f9419f0 | 2017-06-15 11:35:38 +0100 | [diff] [blame] | 216 | mSplitClassLoaderNames = null; |
MÃ¥rten Kongstad | 48d2232 | 2014-01-31 14:43:27 +0100 | [diff] [blame] | 217 | mOverlayDirs = null; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 218 | mDataDir = null; |
| 219 | mDataDirFile = null; |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 220 | mDeviceProtectedDataDirFile = null; |
| 221 | mCredentialProtectedDataDirFile = null; |
Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 222 | mLibDir = null; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 223 | mBaseClassLoader = null; |
| 224 | mSecurityViolation = false; |
| 225 | mIncludeCode = true; |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 226 | mRegisterPackage = false; |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 227 | mClassLoader = ClassLoader.getSystemClassLoader(); |
| 228 | mResources = Resources.getSystem(); |
Jason Monk | a80bfb5 | 2017-11-16 17:15:37 -0500 | [diff] [blame] | 229 | mAppComponentFactory = createAppFactory(mApplicationInfo, mClassLoader); |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | /** |
| 233 | * Sets application info about the system package. |
| 234 | */ |
Narayan Kamath | 29564cd | 2014-08-07 10:57:40 +0100 | [diff] [blame] | 235 | void installSystemApplicationInfo(ApplicationInfo info, ClassLoader classLoader) { |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 236 | assert info.packageName.equals("android"); |
| 237 | mApplicationInfo = info; |
Narayan Kamath | 29564cd | 2014-08-07 10:57:40 +0100 | [diff] [blame] | 238 | mClassLoader = classLoader; |
Jason Monk | a80bfb5 | 2017-11-16 17:15:37 -0500 | [diff] [blame] | 239 | mAppComponentFactory = createAppFactory(info, classLoader); |
| 240 | } |
| 241 | |
| 242 | private AppComponentFactory createAppFactory(ApplicationInfo appInfo, ClassLoader cl) { |
Jason Monk | 6ee51bb | 2018-03-02 11:20:31 -0500 | [diff] [blame] | 243 | if (appInfo.appComponentFactory != null && cl != null) { |
Jason Monk | a80bfb5 | 2017-11-16 17:15:37 -0500 | [diff] [blame] | 244 | try { |
| 245 | return (AppComponentFactory) cl.loadClass(appInfo.appComponentFactory) |
| 246 | .newInstance(); |
| 247 | } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) { |
| 248 | Slog.e(TAG, "Unable to instantiate appComponentFactory", e); |
| 249 | } |
| 250 | } |
| 251 | return AppComponentFactory.DEFAULT; |
| 252 | } |
| 253 | |
| 254 | public AppComponentFactory getAppFactory() { |
| 255 | return mAppComponentFactory; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 256 | } |
| 257 | |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 258 | @UnsupportedAppUsage |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 259 | public String getPackageName() { |
| 260 | return mPackageName; |
| 261 | } |
| 262 | |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 263 | @UnsupportedAppUsage |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 264 | public ApplicationInfo getApplicationInfo() { |
| 265 | return mApplicationInfo; |
| 266 | } |
| 267 | |
Jeff Sharkey | 369f509 | 2016-02-29 11:16:21 -0700 | [diff] [blame] | 268 | public int getTargetSdkVersion() { |
| 269 | return mApplicationInfo.targetSdkVersion; |
| 270 | } |
| 271 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 272 | public boolean isSecurityViolation() { |
| 273 | return mSecurityViolation; |
| 274 | } |
| 275 | |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 276 | @UnsupportedAppUsage |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 277 | public CompatibilityInfo getCompatibilityInfo() { |
| 278 | return mDisplayAdjustments.getCompatibilityInfo(); |
| 279 | } |
| 280 | |
| 281 | public void setCompatibilityInfo(CompatibilityInfo compatInfo) { |
| 282 | mDisplayAdjustments.setCompatibilityInfo(compatInfo); |
| 283 | } |
| 284 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 285 | /** |
| 286 | * Gets the array of shared libraries that are listed as |
| 287 | * used by the given package. |
| 288 | * |
| 289 | * @param packageName the name of the package (note: not its |
| 290 | * file name) |
| 291 | * @return null-ok; the array of shared libraries, each one |
| 292 | * a fully-qualified path |
| 293 | */ |
| 294 | private static String[] getLibrariesFor(String packageName) { |
| 295 | ApplicationInfo ai = null; |
| 296 | try { |
| 297 | ai = ActivityThread.getPackageManager().getApplicationInfo(packageName, |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 298 | PackageManager.GET_SHARED_LIBRARY_FILES, UserHandle.myUserId()); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 299 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 300 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | if (ai == null) { |
| 304 | return null; |
| 305 | } |
| 306 | |
| 307 | return ai.sharedLibraryFiles; |
| 308 | } |
| 309 | |
Adam Lesinski | d33ef56 | 2017-01-19 14:49:59 -0800 | [diff] [blame] | 310 | /** |
| 311 | * Update the ApplicationInfo for an app. If oldPaths is null, all the paths are considered |
| 312 | * new. |
| 313 | * @param aInfo The new ApplicationInfo to use for this LoadedApk |
| 314 | * @param oldPaths The code paths for the old ApplicationInfo object. null means no paths can |
| 315 | * be reused. |
| 316 | */ |
| 317 | public void updateApplicationInfo(@NonNull ApplicationInfo aInfo, |
| 318 | @Nullable List<String> oldPaths) { |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 319 | setApplicationInfo(aInfo); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 320 | |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 321 | final List<String> newPaths = new ArrayList<>(); |
Dimitry Ivanov | 638d810 | 2017-02-22 15:39:42 -0800 | [diff] [blame] | 322 | makePaths(mActivityThread, aInfo, newPaths); |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 323 | final List<String> addedPaths = new ArrayList<>(newPaths.size()); |
| 324 | |
| 325 | if (oldPaths != null) { |
| 326 | for (String path : newPaths) { |
| 327 | final String apkName = path.substring(path.lastIndexOf(File.separator)); |
| 328 | boolean match = false; |
| 329 | for (String oldPath : oldPaths) { |
Adam Lesinski | a5ca624 | 2017-03-01 15:45:12 -0800 | [diff] [blame] | 330 | final String oldApkName = oldPath.substring(oldPath.lastIndexOf(File.separator)); |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 331 | if (apkName.equals(oldApkName)) { |
| 332 | match = true; |
| 333 | break; |
| 334 | } |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 335 | } |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 336 | if (!match) { |
| 337 | addedPaths.add(path); |
| 338 | } |
| 339 | } |
| 340 | } else { |
| 341 | addedPaths.addAll(newPaths); |
| 342 | } |
| 343 | synchronized (this) { |
Dimitry Ivanov | 43b28b1 | 2016-03-14 17:15:38 -0700 | [diff] [blame] | 344 | createOrUpdateClassLoaderLocked(addedPaths); |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 345 | if (mResources != null) { |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 346 | final String[] splitPaths; |
| 347 | try { |
| 348 | splitPaths = getSplitPaths(null); |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 349 | } catch (NameNotFoundException e) { |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 350 | // This should NEVER fail. |
| 351 | throw new AssertionError("null split not found"); |
| 352 | } |
| 353 | |
| 354 | mResources = ResourcesManager.getInstance().getResources(null, mResDir, |
Adam Lesinski | 0e61883 | 2017-02-07 11:40:12 -0800 | [diff] [blame] | 355 | splitPaths, mOverlayDirs, mApplicationInfo.sharedLibraryFiles, |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 356 | Display.DEFAULT_DISPLAY, null, getCompatibilityInfo(), |
| 357 | getClassLoader()); |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 358 | } |
| 359 | } |
Jason Monk | a80bfb5 | 2017-11-16 17:15:37 -0500 | [diff] [blame] | 360 | mAppComponentFactory = createAppFactory(aInfo, mClassLoader); |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | private void setApplicationInfo(ApplicationInfo aInfo) { |
| 364 | final int myUid = Process.myUid(); |
| 365 | aInfo = adjustNativeLibraryPaths(aInfo); |
| 366 | mApplicationInfo = aInfo; |
| 367 | mAppDir = aInfo.sourceDir; |
| 368 | mResDir = aInfo.uid == myUid ? aInfo.sourceDir : aInfo.publicSourceDir; |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 369 | mOverlayDirs = aInfo.resourceDirs; |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 370 | mDataDir = aInfo.dataDir; |
| 371 | mLibDir = aInfo.nativeLibraryDir; |
| 372 | mDataDirFile = FileUtils.newFileOrNull(aInfo.dataDir); |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 373 | mDeviceProtectedDataDirFile = FileUtils.newFileOrNull(aInfo.deviceProtectedDataDir); |
| 374 | mCredentialProtectedDataDirFile = FileUtils.newFileOrNull(aInfo.credentialProtectedDataDir); |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 375 | |
| 376 | mSplitNames = aInfo.splitNames; |
| 377 | mSplitAppDirs = aInfo.splitSourceDirs; |
| 378 | mSplitResDirs = aInfo.uid == myUid ? aInfo.splitSourceDirs : aInfo.splitPublicSourceDirs; |
Narayan Kamath | f9419f0 | 2017-06-15 11:35:38 +0100 | [diff] [blame] | 379 | mSplitClassLoaderNames = aInfo.splitClassLoaderNames; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 380 | |
| 381 | if (aInfo.requestsIsolatedSplitLoading() && !ArrayUtils.isEmpty(mSplitNames)) { |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 382 | mSplitLoader = new SplitDependencyLoaderImpl(aInfo.splitDependencies); |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 383 | } |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 384 | } |
| 385 | |
Dimitry Ivanov | 638d810 | 2017-02-22 15:39:42 -0800 | [diff] [blame] | 386 | public static void makePaths(ActivityThread activityThread, |
| 387 | ApplicationInfo aInfo, |
| 388 | List<String> outZipPaths) { |
| 389 | makePaths(activityThread, false, aInfo, outZipPaths, null); |
| 390 | } |
| 391 | |
| 392 | public static void makePaths(ActivityThread activityThread, |
| 393 | boolean isBundledApp, |
| 394 | ApplicationInfo aInfo, |
| 395 | List<String> outZipPaths, |
| 396 | List<String> outLibPaths) { |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 397 | final String appDir = aInfo.sourceDir; |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 398 | final String libDir = aInfo.nativeLibraryDir; |
| 399 | final String[] sharedLibraries = aInfo.sharedLibraryFiles; |
| 400 | |
| 401 | outZipPaths.clear(); |
| 402 | outZipPaths.add(appDir); |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 403 | |
| 404 | // Do not load all available splits if the app requested isolated split loading. |
| 405 | if (aInfo.splitSourceDirs != null && !aInfo.requestsIsolatedSplitLoading()) { |
| 406 | Collections.addAll(outZipPaths, aInfo.splitSourceDirs); |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | if (outLibPaths != null) { |
| 410 | outLibPaths.clear(); |
| 411 | } |
| 412 | |
| 413 | /* |
| 414 | * The following is a bit of a hack to inject |
| 415 | * instrumentation into the system: If the app |
| 416 | * being started matches one of the instrumentation names, |
| 417 | * then we combine both the "instrumentation" and |
| 418 | * "instrumented" app into the path, along with the |
| 419 | * concatenation of both apps' shared library lists. |
| 420 | */ |
| 421 | |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 422 | String[] instrumentationLibs = null; |
Torne (Richard Coles) | 3b6ca99 | 2016-10-10 15:11:36 +0100 | [diff] [blame] | 423 | // activityThread will be null when called from the WebView zygote; just assume |
| 424 | // no instrumentation applies in this case. |
| 425 | if (activityThread != null) { |
| 426 | String instrumentationPackageName = activityThread.mInstrumentationPackageName; |
| 427 | String instrumentationAppDir = activityThread.mInstrumentationAppDir; |
| 428 | String[] instrumentationSplitAppDirs = activityThread.mInstrumentationSplitAppDirs; |
| 429 | String instrumentationLibDir = activityThread.mInstrumentationLibDir; |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 430 | |
Torne (Richard Coles) | 3b6ca99 | 2016-10-10 15:11:36 +0100 | [diff] [blame] | 431 | String instrumentedAppDir = activityThread.mInstrumentedAppDir; |
| 432 | String[] instrumentedSplitAppDirs = activityThread.mInstrumentedSplitAppDirs; |
| 433 | String instrumentedLibDir = activityThread.mInstrumentedLibDir; |
| 434 | |
| 435 | if (appDir.equals(instrumentationAppDir) |
| 436 | || appDir.equals(instrumentedAppDir)) { |
| 437 | outZipPaths.clear(); |
| 438 | outZipPaths.add(instrumentationAppDir); |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 439 | |
| 440 | // Only add splits if the app did not request isolated split loading. |
| 441 | if (!aInfo.requestsIsolatedSplitLoading()) { |
| 442 | if (instrumentationSplitAppDirs != null) { |
| 443 | Collections.addAll(outZipPaths, instrumentationSplitAppDirs); |
| 444 | } |
| 445 | |
| 446 | if (!instrumentationAppDir.equals(instrumentedAppDir)) { |
| 447 | outZipPaths.add(instrumentedAppDir); |
| 448 | if (instrumentedSplitAppDirs != null) { |
| 449 | Collections.addAll(outZipPaths, instrumentedSplitAppDirs); |
| 450 | } |
Torne (Richard Coles) | 3b6ca99 | 2016-10-10 15:11:36 +0100 | [diff] [blame] | 451 | } |
Jeff Hao | c7b9482 | 2016-03-16 15:56:07 -0700 | [diff] [blame] | 452 | } |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 453 | |
Torne (Richard Coles) | 3b6ca99 | 2016-10-10 15:11:36 +0100 | [diff] [blame] | 454 | if (outLibPaths != null) { |
| 455 | outLibPaths.add(instrumentationLibDir); |
| 456 | if (!instrumentationLibDir.equals(instrumentedLibDir)) { |
| 457 | outLibPaths.add(instrumentedLibDir); |
| 458 | } |
| 459 | } |
| 460 | |
| 461 | if (!instrumentedAppDir.equals(instrumentationAppDir)) { |
| 462 | instrumentationLibs = getLibrariesFor(instrumentationPackageName); |
| 463 | } |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 464 | } |
| 465 | } |
| 466 | |
| 467 | if (outLibPaths != null) { |
| 468 | if (outLibPaths.isEmpty()) { |
| 469 | outLibPaths.add(libDir); |
| 470 | } |
| 471 | |
| 472 | // Add path to libraries in apk for current abi. Do this now because more entries |
| 473 | // will be added to zipPaths that shouldn't be part of the library path. |
| 474 | if (aInfo.primaryCpuAbi != null) { |
Alex Light | 20ed24f | 2016-04-20 14:07:43 -0700 | [diff] [blame] | 475 | // Add fake libs into the library search path if we target prior to N. |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 476 | if (aInfo.targetSdkVersion < Build.VERSION_CODES.N) { |
Alex Light | 20ed24f | 2016-04-20 14:07:43 -0700 | [diff] [blame] | 477 | outLibPaths.add("/system/fake-libs" + |
| 478 | (VMRuntime.is64BitAbi(aInfo.primaryCpuAbi) ? "64" : "")); |
| 479 | } |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 480 | for (String apk : outZipPaths) { |
| 481 | outLibPaths.add(apk + "!/lib/" + aInfo.primaryCpuAbi); |
| 482 | } |
| 483 | } |
| 484 | |
Dimitry Ivanov | 638d810 | 2017-02-22 15:39:42 -0800 | [diff] [blame] | 485 | if (isBundledApp) { |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 486 | // Add path to system libraries to libPaths; |
| 487 | // Access to system libs should be limited |
| 488 | // to bundled applications; this is why updated |
| 489 | // system apps are not included. |
| 490 | outLibPaths.add(System.getProperty("java.library.path")); |
| 491 | } |
| 492 | } |
| 493 | |
Jeff Hao | 090892f | 2017-04-24 17:37:31 -0700 | [diff] [blame] | 494 | // Prepend the shared libraries, maintaining their original order where possible. |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 495 | if (sharedLibraries != null) { |
Jeff Hao | 090892f | 2017-04-24 17:37:31 -0700 | [diff] [blame] | 496 | int index = 0; |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 497 | for (String lib : sharedLibraries) { |
| 498 | if (!outZipPaths.contains(lib)) { |
Jeff Hao | 090892f | 2017-04-24 17:37:31 -0700 | [diff] [blame] | 499 | outZipPaths.add(index, lib); |
| 500 | index++; |
Svetoslav Ganov | 40610e3 | 2017-06-20 19:35:51 -0700 | [diff] [blame] | 501 | appendApkLibPathIfNeeded(lib, aInfo, outLibPaths); |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 502 | } |
| 503 | } |
| 504 | } |
| 505 | |
| 506 | if (instrumentationLibs != null) { |
| 507 | for (String lib : instrumentationLibs) { |
| 508 | if (!outZipPaths.contains(lib)) { |
| 509 | outZipPaths.add(0, lib); |
Svetoslav Ganov | 40610e3 | 2017-06-20 19:35:51 -0700 | [diff] [blame] | 510 | appendApkLibPathIfNeeded(lib, aInfo, outLibPaths); |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 511 | } |
| 512 | } |
| 513 | } |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 514 | } |
| 515 | |
Svetoslav Ganov | 40610e3 | 2017-06-20 19:35:51 -0700 | [diff] [blame] | 516 | /** |
| 517 | * This method appends a path to the appropriate native library folder of a |
| 518 | * library if this library is hosted in an APK. This allows support for native |
| 519 | * shared libraries. The library API is determined based on the application |
| 520 | * ABI. |
| 521 | * |
| 522 | * @param path Path to the library. |
| 523 | * @param applicationInfo The application depending on the library. |
| 524 | * @param outLibPaths List to which to add the native lib path if needed. |
| 525 | */ |
| 526 | private static void appendApkLibPathIfNeeded(@NonNull String path, |
| 527 | @NonNull ApplicationInfo applicationInfo, @Nullable List<String> outLibPaths) { |
| 528 | // Looking at the suffix is a little hacky but a safe and simple solution. |
| 529 | // We will be revisiting code in the next release and clean this up. |
| 530 | if (outLibPaths != null && applicationInfo.primaryCpuAbi != null && path.endsWith(".apk")) { |
| 531 | if (applicationInfo.targetSdkVersion >= Build.VERSION_CODES.O) { |
| 532 | outLibPaths.add(path + "!/lib/" + applicationInfo.primaryCpuAbi); |
| 533 | } |
| 534 | } |
| 535 | } |
| 536 | |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 537 | /* |
| 538 | * All indices received by the super class should be shifted by 1 when accessing mSplitNames, |
| 539 | * etc. The super class assumes the base APK is index 0, while the PackageManager APIs don't |
| 540 | * include the base APK in the list of splits. |
| 541 | */ |
| 542 | private class SplitDependencyLoaderImpl extends SplitDependencyLoader<NameNotFoundException> { |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 543 | private final String[][] mCachedResourcePaths; |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 544 | private final ClassLoader[] mCachedClassLoaders; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 545 | |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 546 | SplitDependencyLoaderImpl(@NonNull SparseArray<int[]> dependencies) { |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 547 | super(dependencies); |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 548 | mCachedResourcePaths = new String[mSplitNames.length + 1][]; |
| 549 | mCachedClassLoaders = new ClassLoader[mSplitNames.length + 1]; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 550 | } |
| 551 | |
| 552 | @Override |
| 553 | protected boolean isSplitCached(int splitIdx) { |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 554 | return mCachedClassLoaders[splitIdx] != null; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 555 | } |
| 556 | |
| 557 | @Override |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 558 | protected void constructSplit(int splitIdx, @NonNull int[] configSplitIndices, |
| 559 | int parentSplitIdx) throws NameNotFoundException { |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 560 | final ArrayList<String> splitPaths = new ArrayList<>(); |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 561 | if (splitIdx == 0) { |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 562 | createOrUpdateClassLoaderLocked(null); |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 563 | mCachedClassLoaders[0] = mClassLoader; |
| 564 | |
| 565 | // Never add the base resources here, they always get added no matter what. |
| 566 | for (int configSplitIdx : configSplitIndices) { |
| 567 | splitPaths.add(mSplitResDirs[configSplitIdx - 1]); |
| 568 | } |
| 569 | mCachedResourcePaths[0] = splitPaths.toArray(new String[splitPaths.size()]); |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 570 | return; |
| 571 | } |
| 572 | |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 573 | // Since we handled the special base case above, parentSplitIdx is always valid. |
| 574 | final ClassLoader parent = mCachedClassLoaders[parentSplitIdx]; |
| 575 | mCachedClassLoaders[splitIdx] = ApplicationLoaders.getDefault().getClassLoader( |
Narayan Kamath | f9419f0 | 2017-06-15 11:35:38 +0100 | [diff] [blame] | 576 | mSplitAppDirs[splitIdx - 1], getTargetSdkVersion(), false, null, null, parent, |
| 577 | mSplitClassLoaderNames[splitIdx - 1]); |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 578 | |
| 579 | Collections.addAll(splitPaths, mCachedResourcePaths[parentSplitIdx]); |
| 580 | splitPaths.add(mSplitResDirs[splitIdx - 1]); |
| 581 | for (int configSplitIdx : configSplitIndices) { |
| 582 | splitPaths.add(mSplitResDirs[configSplitIdx - 1]); |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 583 | } |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 584 | mCachedResourcePaths[splitIdx] = splitPaths.toArray(new String[splitPaths.size()]); |
| 585 | } |
| 586 | |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 587 | private int ensureSplitLoaded(String splitName) throws NameNotFoundException { |
| 588 | int idx = 0; |
| 589 | if (splitName != null) { |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 590 | idx = Arrays.binarySearch(mSplitNames, splitName); |
| 591 | if (idx < 0) { |
| 592 | throw new PackageManager.NameNotFoundException( |
| 593 | "Split name '" + splitName + "' is not installed"); |
| 594 | } |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 595 | idx += 1; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 596 | } |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 597 | loadDependenciesForSplit(idx); |
| 598 | return idx; |
| 599 | } |
| 600 | |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 601 | ClassLoader getClassLoaderForSplit(String splitName) throws NameNotFoundException { |
| 602 | return mCachedClassLoaders[ensureSplitLoaded(splitName)]; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 603 | } |
| 604 | |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 605 | String[] getSplitPathsForSplit(String splitName) throws NameNotFoundException { |
| 606 | return mCachedResourcePaths[ensureSplitLoaded(splitName)]; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 607 | } |
| 608 | } |
| 609 | |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 610 | private SplitDependencyLoaderImpl mSplitLoader; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 611 | |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 612 | ClassLoader getSplitClassLoader(String splitName) throws NameNotFoundException { |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 613 | if (mSplitLoader == null) { |
| 614 | return mClassLoader; |
| 615 | } |
| 616 | return mSplitLoader.getClassLoaderForSplit(splitName); |
| 617 | } |
| 618 | |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 619 | String[] getSplitPaths(String splitName) throws NameNotFoundException { |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 620 | if (mSplitLoader == null) { |
| 621 | return mSplitResDirs; |
| 622 | } |
| 623 | return mSplitLoader.getSplitPathsForSplit(splitName); |
| 624 | } |
| 625 | |
Dimitry Ivanov | 43b28b1 | 2016-03-14 17:15:38 -0700 | [diff] [blame] | 626 | private void createOrUpdateClassLoaderLocked(List<String> addedPaths) { |
| 627 | if (mPackageName.equals("android")) { |
Calin Juravle | 430ef45 | 2016-04-22 17:43:07 +0100 | [diff] [blame] | 628 | // Note: This branch is taken for system server and we don't need to setup |
| 629 | // jit profiling support. |
Dimitry Ivanov | 43b28b1 | 2016-03-14 17:15:38 -0700 | [diff] [blame] | 630 | if (mClassLoader != null) { |
| 631 | // nothing to update |
| 632 | return; |
Dimitry Ivanov | b9c9026 | 2016-02-19 14:09:20 -0800 | [diff] [blame] | 633 | } |
| 634 | |
Dimitry Ivanov | 43b28b1 | 2016-03-14 17:15:38 -0700 | [diff] [blame] | 635 | if (mBaseClassLoader != null) { |
| 636 | mClassLoader = mBaseClassLoader; |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 637 | } else { |
Dimitry Ivanov | 43b28b1 | 2016-03-14 17:15:38 -0700 | [diff] [blame] | 638 | mClassLoader = ClassLoader.getSystemClassLoader(); |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 639 | } |
Jason Monk | 6ee51bb | 2018-03-02 11:20:31 -0500 | [diff] [blame] | 640 | mAppComponentFactory = createAppFactory(mApplicationInfo, mClassLoader); |
Dimitry Ivanov | 43b28b1 | 2016-03-14 17:15:38 -0700 | [diff] [blame] | 641 | |
| 642 | return; |
| 643 | } |
| 644 | |
| 645 | // Avoid the binder call when the package is the current application package. |
| 646 | // The activity manager will perform ensure that dexopt is performed before |
| 647 | // spinning up the process. |
Narayan Kamath | bf07e2a | 2017-03-15 11:37:32 +0000 | [diff] [blame] | 648 | if (!Objects.equals(mPackageName, ActivityThread.currentPackageName()) && mIncludeCode) { |
Dimitry Ivanov | 43b28b1 | 2016-03-14 17:15:38 -0700 | [diff] [blame] | 649 | try { |
Brian Carlstrom | ca82e61 | 2016-04-19 23:16:08 -0700 | [diff] [blame] | 650 | ActivityThread.getPackageManager().notifyPackageUse(mPackageName, |
| 651 | PackageManager.NOTIFY_PACKAGE_USE_CROSS_PACKAGE); |
Dimitry Ivanov | 43b28b1 | 2016-03-14 17:15:38 -0700 | [diff] [blame] | 652 | } catch (RemoteException re) { |
| 653 | throw re.rethrowFromSystemServer(); |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 654 | } |
| 655 | } |
Dimitry Ivanov | 43b28b1 | 2016-03-14 17:15:38 -0700 | [diff] [blame] | 656 | |
Dimitry Ivanov | 43b28b1 | 2016-03-14 17:15:38 -0700 | [diff] [blame] | 657 | if (mRegisterPackage) { |
| 658 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 659 | ActivityManager.getService().addPackageDependency(mPackageName); |
Dimitry Ivanov | 43b28b1 | 2016-03-14 17:15:38 -0700 | [diff] [blame] | 660 | } catch (RemoteException e) { |
| 661 | throw e.rethrowFromSystemServer(); |
| 662 | } |
| 663 | } |
| 664 | |
Andreas Gampe | a8a58ff | 2016-05-18 11:58:39 -0700 | [diff] [blame] | 665 | // Lists for the elements of zip/code and native libraries. |
| 666 | // |
| 667 | // Both lists are usually not empty. We expect on average one APK for the zip component, |
| 668 | // but shared libraries and splits are not uncommon. We expect at least three elements |
| 669 | // for native libraries (app-based, system, vendor). As such, give both some breathing |
| 670 | // space and initialize to a small value (instead of incurring growth code). |
| 671 | final List<String> zipPaths = new ArrayList<>(10); |
| 672 | final List<String> libPaths = new ArrayList<>(10); |
Narayan Kamath | 8995b00 | 2016-05-11 20:31:09 +0100 | [diff] [blame] | 673 | |
Jiyong Park | fcad696 | 2017-08-22 10:24:28 +0900 | [diff] [blame] | 674 | boolean isBundledApp = mApplicationInfo.isSystemApp() |
Dimitry Ivanov | 43b28b1 | 2016-03-14 17:15:38 -0700 | [diff] [blame] | 675 | && !mApplicationInfo.isUpdatedSystemApp(); |
Dimitry Ivanov | bf3b5f7 | 2016-05-03 11:34:58 -0700 | [diff] [blame] | 676 | |
Jiyong Park | fcad696 | 2017-08-22 10:24:28 +0900 | [diff] [blame] | 677 | // Vendor apks are treated as bundled only when /vendor/lib is in the default search |
| 678 | // paths. If not, they are treated as unbundled; access to system libs is limited. |
| 679 | // Having /vendor/lib in the default search paths means that all system processes |
| 680 | // are allowed to use any vendor library, which in turn means that system is dependent |
| 681 | // on vendor partition. In the contrary, not having /vendor/lib in the default search |
| 682 | // paths mean that the two partitions are separated and thus we can treat vendor apks |
| 683 | // as unbundled. |
| 684 | final String defaultSearchPaths = System.getProperty("java.library.path"); |
| 685 | final boolean treatVendorApkAsUnbundled = !defaultSearchPaths.contains("/vendor/lib"); |
Jiyong Park | 63495c2 | 2017-09-15 07:48:06 +0900 | [diff] [blame] | 686 | if (mApplicationInfo.getCodePath() != null |
Jiyong Park | 002fdbd | 2017-02-13 20:50:31 +0900 | [diff] [blame] | 687 | && mApplicationInfo.isVendor() && treatVendorApkAsUnbundled) { |
Jiyong Park | fcad696 | 2017-08-22 10:24:28 +0900 | [diff] [blame] | 688 | isBundledApp = false; |
| 689 | } |
| 690 | |
Dimitry Ivanov | 638d810 | 2017-02-22 15:39:42 -0800 | [diff] [blame] | 691 | makePaths(mActivityThread, isBundledApp, mApplicationInfo, zipPaths, libPaths); |
| 692 | |
Dimitry Ivanov | eb96b00 | 2016-05-10 10:51:40 -0700 | [diff] [blame] | 693 | String libraryPermittedPath = mDataDir; |
Jiyong Park | 29d9eba | 2018-05-04 12:44:38 +0900 | [diff] [blame] | 694 | |
Dimitry Ivanov | 43b28b1 | 2016-03-14 17:15:38 -0700 | [diff] [blame] | 695 | if (isBundledApp) { |
Jiyong Park | 29d9eba | 2018-05-04 12:44:38 +0900 | [diff] [blame] | 696 | // For bundled apps, add the base directory of the app (e.g., |
| 697 | // /system/app/Foo/) to the permitted paths so that it can load libraries |
| 698 | // embedded in module apks under the directory. For now, GmsCore is relying |
| 699 | // on this, but this isn't specific to the app. Also note that, we don't |
| 700 | // need to do this for unbundled apps as entire /data is already set to |
| 701 | // the permitted paths for them. |
| 702 | libraryPermittedPath += File.pathSeparator |
| 703 | + Paths.get(getAppDir()).getParent().toString(); |
| 704 | |
Dimitry Ivanov | 43b28b1 | 2016-03-14 17:15:38 -0700 | [diff] [blame] | 705 | // This is necessary to grant bundled apps access to |
| 706 | // libraries located in subdirectories of /system/lib |
Jiyong Park | fcad696 | 2017-08-22 10:24:28 +0900 | [diff] [blame] | 707 | libraryPermittedPath += File.pathSeparator + defaultSearchPaths; |
Dimitry Ivanov | 43b28b1 | 2016-03-14 17:15:38 -0700 | [diff] [blame] | 708 | } |
Dimitry Ivanov | 43b28b1 | 2016-03-14 17:15:38 -0700 | [diff] [blame] | 709 | |
| 710 | final String librarySearchPath = TextUtils.join(File.pathSeparator, libPaths); |
| 711 | |
Narayan Kamath | 8995b00 | 2016-05-11 20:31:09 +0100 | [diff] [blame] | 712 | // If we're not asked to include code, we construct a classloader that has |
| 713 | // no code path included. We still need to set up the library search paths |
| 714 | // and permitted path because NativeActivity relies on it (it attempts to |
| 715 | // call System.loadLibrary() on a classloader from a LoadedApk with |
| 716 | // mIncludeCode == false). |
| 717 | if (!mIncludeCode) { |
| 718 | if (mClassLoader == null) { |
| 719 | StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); |
| 720 | mClassLoader = ApplicationLoaders.getDefault().getClassLoader( |
Narayan Kamath | f9419f0 | 2017-06-15 11:35:38 +0100 | [diff] [blame] | 721 | "" /* codePath */, mApplicationInfo.targetSdkVersion, isBundledApp, |
| 722 | librarySearchPath, libraryPermittedPath, mBaseClassLoader, |
| 723 | null /* classLoaderName */); |
Narayan Kamath | 8995b00 | 2016-05-11 20:31:09 +0100 | [diff] [blame] | 724 | StrictMode.setThreadPolicy(oldPolicy); |
Jason Monk | 2544c69 | 2018-05-15 11:30:09 -0400 | [diff] [blame] | 725 | mAppComponentFactory = AppComponentFactory.DEFAULT; |
Narayan Kamath | 8995b00 | 2016-05-11 20:31:09 +0100 | [diff] [blame] | 726 | } |
| 727 | |
| 728 | return; |
| 729 | } |
| 730 | |
Dimitry Ivanov | 43b28b1 | 2016-03-14 17:15:38 -0700 | [diff] [blame] | 731 | /* |
Narayan Kamath | 8995b00 | 2016-05-11 20:31:09 +0100 | [diff] [blame] | 732 | * With all the combination done (if necessary, actually create the java class |
| 733 | * loader and set up JIT profiling support if necessary. |
Andreas Gampe | a8a58ff | 2016-05-18 11:58:39 -0700 | [diff] [blame] | 734 | * |
| 735 | * In many cases this is a single APK, so try to avoid the StringBuilder in TextUtils. |
Dimitry Ivanov | 43b28b1 | 2016-03-14 17:15:38 -0700 | [diff] [blame] | 736 | */ |
Andreas Gampe | a8a58ff | 2016-05-18 11:58:39 -0700 | [diff] [blame] | 737 | final String zip = (zipPaths.size() == 1) ? zipPaths.get(0) : |
| 738 | TextUtils.join(File.pathSeparator, zipPaths); |
Dimitry Ivanov | 43b28b1 | 2016-03-14 17:15:38 -0700 | [diff] [blame] | 739 | |
Dianne Hackborn | 9484603 | 2017-03-31 17:55:23 -0700 | [diff] [blame] | 740 | if (DEBUG) Slog.v(ActivityThread.TAG, "Class path: " + zip + |
Dimitry Ivanov | 43b28b1 | 2016-03-14 17:15:38 -0700 | [diff] [blame] | 741 | ", JNI path: " + librarySearchPath); |
| 742 | |
Calin Juravle | 430ef45 | 2016-04-22 17:43:07 +0100 | [diff] [blame] | 743 | boolean needToSetupJitProfiles = false; |
Dimitry Ivanov | 43b28b1 | 2016-03-14 17:15:38 -0700 | [diff] [blame] | 744 | if (mClassLoader == null) { |
| 745 | // Temporarily disable logging of disk reads on the Looper thread |
| 746 | // as this is early and necessary. |
| 747 | StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); |
| 748 | |
| 749 | mClassLoader = ApplicationLoaders.getDefault().getClassLoader(zip, |
| 750 | mApplicationInfo.targetSdkVersion, isBundledApp, librarySearchPath, |
Narayan Kamath | f9419f0 | 2017-06-15 11:35:38 +0100 | [diff] [blame] | 751 | libraryPermittedPath, mBaseClassLoader, |
| 752 | mApplicationInfo.classLoaderName); |
Jason Monk | 6ee51bb | 2018-03-02 11:20:31 -0500 | [diff] [blame] | 753 | mAppComponentFactory = createAppFactory(mApplicationInfo, mClassLoader); |
Dimitry Ivanov | 43b28b1 | 2016-03-14 17:15:38 -0700 | [diff] [blame] | 754 | |
| 755 | StrictMode.setThreadPolicy(oldPolicy); |
Calin Juravle | 430ef45 | 2016-04-22 17:43:07 +0100 | [diff] [blame] | 756 | // Setup the class loader paths for profiling. |
| 757 | needToSetupJitProfiles = true; |
Dimitry Ivanov | 43b28b1 | 2016-03-14 17:15:38 -0700 | [diff] [blame] | 758 | } |
| 759 | |
Patrick Baumann | 1bea237 | 2018-03-13 14:26:58 -0700 | [diff] [blame] | 760 | if (!libPaths.isEmpty() && SystemProperties.getBoolean(PROPERTY_NAME_APPEND_NATIVE, true)) { |
Patrick Baumann | 5c5daa4 | 2018-05-09 11:12:49 -0700 | [diff] [blame] | 761 | // Temporarily disable logging of disk reads on the Looper thread as this is necessary |
| 762 | StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); |
| 763 | try { |
| 764 | ApplicationLoaders.getDefault().addNative(mClassLoader, libPaths); |
| 765 | } finally { |
| 766 | StrictMode.setThreadPolicy(oldPolicy); |
| 767 | } |
Patrick Baumann | 1bea237 | 2018-03-13 14:26:58 -0700 | [diff] [blame] | 768 | } |
| 769 | |
Jiyong Park | cfe38cd | 2018-06-04 15:05:29 +0900 | [diff] [blame] | 770 | // /vendor/lib, /odm/lib and /product/lib are added to the native lib search |
| 771 | // paths of the classloader. Note that this is done AFTER the classloader is |
| 772 | // created by ApplicationLoaders.getDefault().getClassLoader(...). The |
| 773 | // reason is because if we have added the paths when creating the classloader |
| 774 | // above, the paths are also added to the search path of the linker namespace |
| 775 | // 'classloader-namespace', which will allow ALL libs in the paths to apps. |
| 776 | // Since only the libs listed in <partition>/etc/public.libraries.txt can be |
| 777 | // available to apps, we shouldn't add the paths then. |
| 778 | // |
| 779 | // However, we need to add the paths to the classloader (Java) though. This |
| 780 | // is because when a native lib is requested via System.loadLibrary(), the |
| 781 | // classloader first tries to find the requested lib in its own native libs |
| 782 | // search paths. If a lib is not found in one of the paths, dlopen() is not |
| 783 | // called at all. This can cause a problem that a vendor public native lib |
| 784 | // is accessible when directly opened via dlopen(), but inaccesible via |
| 785 | // System.loadLibrary(). In order to prevent the problem, we explicitly |
| 786 | // add the paths only to the classloader, and not to the native loader |
| 787 | // (linker namespace). |
| 788 | List<String> extraLibPaths = new ArrayList<>(3); |
| 789 | String abiSuffix = VMRuntime.getRuntime().is64Bit() ? "64" : ""; |
| 790 | if (!defaultSearchPaths.contains("/vendor/lib")) { |
| 791 | extraLibPaths.add("/vendor/lib" + abiSuffix); |
| 792 | } |
| 793 | if (!defaultSearchPaths.contains("/odm/lib")) { |
| 794 | extraLibPaths.add("/odm/lib" + abiSuffix); |
| 795 | } |
| 796 | if (!defaultSearchPaths.contains("/product/lib")) { |
| 797 | extraLibPaths.add("/product/lib" + abiSuffix); |
| 798 | } |
| 799 | if (!extraLibPaths.isEmpty()) { |
| 800 | StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); |
| 801 | try { |
| 802 | ApplicationLoaders.getDefault().addNative(mClassLoader, extraLibPaths); |
| 803 | } finally { |
| 804 | StrictMode.setThreadPolicy(oldPolicy); |
| 805 | } |
| 806 | } |
| 807 | |
Dimitry Ivanov | 43b28b1 | 2016-03-14 17:15:38 -0700 | [diff] [blame] | 808 | if (addedPaths != null && addedPaths.size() > 0) { |
| 809 | final String add = TextUtils.join(File.pathSeparator, addedPaths); |
| 810 | ApplicationLoaders.getDefault().addPath(mClassLoader, add); |
Calin Juravle | 430ef45 | 2016-04-22 17:43:07 +0100 | [diff] [blame] | 811 | // Setup the new code paths for profiling. |
| 812 | needToSetupJitProfiles = true; |
Dimitry Ivanov | 43b28b1 | 2016-03-14 17:15:38 -0700 | [diff] [blame] | 813 | } |
Calin Juravle | 2a727d7 | 2016-04-15 19:33:46 +0100 | [diff] [blame] | 814 | |
| 815 | // Setup jit profile support. |
Narayan Kamath | 2d4a222 | 2016-04-25 19:16:56 +0100 | [diff] [blame] | 816 | // |
Calin Juravle | 2a727d7 | 2016-04-15 19:33:46 +0100 | [diff] [blame] | 817 | // It is ok to call this multiple times if the application gets updated with new splits. |
| 818 | // The runtime only keeps track of unique code paths and can handle re-registration of |
| 819 | // the same code path. There's no need to pass `addedPaths` since any new code paths |
| 820 | // are already in `mApplicationInfo`. |
Narayan Kamath | 2d4a222 | 2016-04-25 19:16:56 +0100 | [diff] [blame] | 821 | // |
| 822 | // It is NOT ok to call this function from the system_server (for any of the packages it |
| 823 | // loads code from) so we explicitly disallow it there. |
| 824 | if (needToSetupJitProfiles && !ActivityThread.isSystem()) { |
Calin Juravle | 430ef45 | 2016-04-22 17:43:07 +0100 | [diff] [blame] | 825 | setupJitProfileSupport(); |
Calin Juravle | 430ef45 | 2016-04-22 17:43:07 +0100 | [diff] [blame] | 826 | } |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 827 | } |
| 828 | |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 829 | @UnsupportedAppUsage |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 830 | public ClassLoader getClassLoader() { |
| 831 | synchronized (this) { |
| 832 | if (mClassLoader == null) { |
Dimitry Ivanov | 43b28b1 | 2016-03-14 17:15:38 -0700 | [diff] [blame] | 833 | createOrUpdateClassLoaderLocked(null /*addedPaths*/); |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 834 | } |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 835 | return mClassLoader; |
| 836 | } |
| 837 | } |
| 838 | |
Calin Juravle | 2a727d7 | 2016-04-15 19:33:46 +0100 | [diff] [blame] | 839 | private void setupJitProfileSupport() { |
| 840 | if (!SystemProperties.getBoolean("dalvik.vm.usejitprofiles", false)) { |
| 841 | return; |
| 842 | } |
Calin Juravle | 126f780 | 2016-05-24 15:23:47 +0100 | [diff] [blame] | 843 | // Only set up profile support if the loaded apk has the same uid as the |
| 844 | // current process. |
| 845 | // Currently, we do not support profiling across different apps. |
| 846 | // (e.g. application's uid might be different when the code is |
| 847 | // loaded by another app via createApplicationContext) |
| 848 | if (mApplicationInfo.uid != Process.myUid()) { |
| 849 | return; |
| 850 | } |
| 851 | |
Calin Juravle | 2a727d7 | 2016-04-15 19:33:46 +0100 | [diff] [blame] | 852 | final List<String> codePaths = new ArrayList<>(); |
| 853 | if ((mApplicationInfo.flags & ApplicationInfo.FLAG_HAS_CODE) != 0) { |
| 854 | codePaths.add(mApplicationInfo.sourceDir); |
| 855 | } |
| 856 | if (mApplicationInfo.splitSourceDirs != null) { |
| 857 | Collections.addAll(codePaths, mApplicationInfo.splitSourceDirs); |
| 858 | } |
| 859 | |
| 860 | if (codePaths.isEmpty()) { |
| 861 | // If there are no code paths there's no need to setup a profile file and register with |
| 862 | // the runtime, |
| 863 | return; |
| 864 | } |
| 865 | |
Calin Juravle | 6ae39fc | 2018-01-19 20:32:47 -0800 | [diff] [blame] | 866 | for (int i = codePaths.size() - 1; i >= 0; i--) { |
| 867 | String splitName = i == 0 ? null : mApplicationInfo.splitNames[i - 1]; |
| 868 | String profileFile = ArtManager.getCurrentProfilePath( |
| 869 | mPackageName, UserHandle.myUserId(), splitName); |
| 870 | VMRuntime.registerAppInfo(profileFile, new String[] {codePaths.get(i)}); |
| 871 | } |
Calin Juravle | f5a7bfc | 2017-03-13 23:30:30 -0700 | [diff] [blame] | 872 | |
| 873 | // Register the app data directory with the reporter. It will |
| 874 | // help deciding whether or not a dex file is the primary apk or a |
| 875 | // secondary dex. |
| 876 | DexLoadReporter.getInstance().registerAppDataDir(mPackageName, mDataDir); |
Calin Juravle | 2a727d7 | 2016-04-15 19:33:46 +0100 | [diff] [blame] | 877 | } |
| 878 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 879 | /** |
| 880 | * Setup value for Thread.getContextClassLoader(). If the |
| 881 | * package will not run in in a VM with other packages, we set |
| 882 | * the Java context ClassLoader to the |
| 883 | * PackageInfo.getClassLoader value. However, if this VM can |
| 884 | * contain multiple packages, we intead set the Java context |
| 885 | * ClassLoader to a proxy that will warn about the use of Java |
| 886 | * context ClassLoaders and then fall through to use the |
| 887 | * system ClassLoader. |
| 888 | * |
| 889 | * <p> Note that this is similar to but not the same as the |
| 890 | * android.content.Context.getClassLoader(). While both |
| 891 | * context class loaders are typically set to the |
| 892 | * PathClassLoader used to load the package archive in the |
| 893 | * single application per VM case, a single Android process |
| 894 | * may contain several Contexts executing on one thread with |
| 895 | * their own logical ClassLoaders while the Java context |
| 896 | * ClassLoader is a thread local. This is why in the case when |
| 897 | * we have multiple packages per VM we do not set the Java |
| 898 | * context ClassLoader to an arbitrary but instead warn the |
| 899 | * user to set their own if we detect that they are using a |
| 900 | * Java library that expects it to be set. |
| 901 | */ |
| 902 | private void initializeJavaContextClassLoader() { |
| 903 | IPackageManager pm = ActivityThread.getPackageManager(); |
| 904 | android.content.pm.PackageInfo pi; |
| 905 | try { |
Jeff Sharkey | c7bacab | 2016-02-09 15:56:11 -0700 | [diff] [blame] | 906 | pi = pm.getPackageInfo(mPackageName, PackageManager.MATCH_DEBUG_TRIAGED_MISSING, |
| 907 | UserHandle.myUserId()); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 908 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 909 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 208d937 | 2013-02-25 13:17:54 -0800 | [diff] [blame] | 910 | } |
| 911 | if (pi == null) { |
| 912 | throw new IllegalStateException("Unable to get package info for " |
| 913 | + mPackageName + "; is package not installed?"); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 914 | } |
| 915 | /* |
| 916 | * Two possible indications that this package could be |
| 917 | * sharing its virtual machine with other packages: |
| 918 | * |
| 919 | * 1.) the sharedUserId attribute is set in the manifest, |
| 920 | * indicating a request to share a VM with other |
| 921 | * packages with the same sharedUserId. |
| 922 | * |
| 923 | * 2.) the application element of the manifest has an |
| 924 | * attribute specifying a non-default process name, |
| 925 | * indicating the desire to run in another packages VM. |
| 926 | */ |
| 927 | boolean sharedUserIdSet = (pi.sharedUserId != null); |
| 928 | boolean processNameNotDefault = |
| 929 | (pi.applicationInfo != null && |
| 930 | !mPackageName.equals(pi.applicationInfo.processName)); |
| 931 | boolean sharable = (sharedUserIdSet || processNameNotDefault); |
| 932 | ClassLoader contextClassLoader = |
| 933 | (sharable) |
| 934 | ? new WarningContextClassLoader() |
| 935 | : mClassLoader; |
| 936 | Thread.currentThread().setContextClassLoader(contextClassLoader); |
| 937 | } |
| 938 | |
| 939 | private static class WarningContextClassLoader extends ClassLoader { |
| 940 | |
| 941 | private static boolean warned = false; |
| 942 | |
| 943 | private void warn(String methodName) { |
| 944 | if (warned) { |
| 945 | return; |
| 946 | } |
| 947 | warned = true; |
| 948 | Thread.currentThread().setContextClassLoader(getParent()); |
| 949 | Slog.w(ActivityThread.TAG, "ClassLoader." + methodName + ": " + |
| 950 | "The class loader returned by " + |
| 951 | "Thread.getContextClassLoader() may fail for processes " + |
| 952 | "that host multiple applications. You should explicitly " + |
| 953 | "specify a context class loader. For example: " + |
| 954 | "Thread.setContextClassLoader(getClass().getClassLoader());"); |
| 955 | } |
| 956 | |
| 957 | @Override public URL getResource(String resName) { |
| 958 | warn("getResource"); |
| 959 | return getParent().getResource(resName); |
| 960 | } |
| 961 | |
| 962 | @Override public Enumeration<URL> getResources(String resName) throws IOException { |
| 963 | warn("getResources"); |
| 964 | return getParent().getResources(resName); |
| 965 | } |
| 966 | |
| 967 | @Override public InputStream getResourceAsStream(String resName) { |
| 968 | warn("getResourceAsStream"); |
| 969 | return getParent().getResourceAsStream(resName); |
| 970 | } |
| 971 | |
| 972 | @Override public Class<?> loadClass(String className) throws ClassNotFoundException { |
| 973 | warn("loadClass"); |
| 974 | return getParent().loadClass(className); |
| 975 | } |
| 976 | |
| 977 | @Override public void setClassAssertionStatus(String cname, boolean enable) { |
| 978 | warn("setClassAssertionStatus"); |
| 979 | getParent().setClassAssertionStatus(cname, enable); |
| 980 | } |
| 981 | |
| 982 | @Override public void setPackageAssertionStatus(String pname, boolean enable) { |
| 983 | warn("setPackageAssertionStatus"); |
| 984 | getParent().setPackageAssertionStatus(pname, enable); |
| 985 | } |
| 986 | |
| 987 | @Override public void setDefaultAssertionStatus(boolean enable) { |
| 988 | warn("setDefaultAssertionStatus"); |
| 989 | getParent().setDefaultAssertionStatus(enable); |
| 990 | } |
| 991 | |
| 992 | @Override public void clearAssertionStatus() { |
| 993 | warn("clearAssertionStatus"); |
| 994 | getParent().clearAssertionStatus(); |
| 995 | } |
| 996 | } |
| 997 | |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 998 | @UnsupportedAppUsage |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 999 | public String getAppDir() { |
| 1000 | return mAppDir; |
| 1001 | } |
| 1002 | |
Brian Carlstrom | d893a89 | 2012-04-01 21:30:26 -0700 | [diff] [blame] | 1003 | public String getLibDir() { |
| 1004 | return mLibDir; |
| 1005 | } |
| 1006 | |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 1007 | @UnsupportedAppUsage |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1008 | public String getResDir() { |
| 1009 | return mResDir; |
| 1010 | } |
| 1011 | |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 1012 | public String[] getSplitAppDirs() { |
| 1013 | return mSplitAppDirs; |
| 1014 | } |
| 1015 | |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 1016 | @UnsupportedAppUsage |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 1017 | public String[] getSplitResDirs() { |
| 1018 | return mSplitResDirs; |
| 1019 | } |
| 1020 | |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 1021 | @UnsupportedAppUsage |
MÃ¥rten Kongstad | 48d2232 | 2014-01-31 14:43:27 +0100 | [diff] [blame] | 1022 | public String[] getOverlayDirs() { |
| 1023 | return mOverlayDirs; |
| 1024 | } |
| 1025 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1026 | public String getDataDir() { |
| 1027 | return mDataDir; |
| 1028 | } |
| 1029 | |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 1030 | @UnsupportedAppUsage |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1031 | public File getDataDirFile() { |
| 1032 | return mDataDirFile; |
| 1033 | } |
| 1034 | |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 1035 | public File getDeviceProtectedDataDirFile() { |
| 1036 | return mDeviceProtectedDataDirFile; |
Jeff Sharkey | 1544779 | 2015-11-05 16:18:51 -0800 | [diff] [blame] | 1037 | } |
| 1038 | |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 1039 | public File getCredentialProtectedDataDirFile() { |
| 1040 | return mCredentialProtectedDataDirFile; |
Jeff Sharkey | 1544779 | 2015-11-05 16:18:51 -0800 | [diff] [blame] | 1041 | } |
| 1042 | |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 1043 | @UnsupportedAppUsage |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1044 | public AssetManager getAssets() { |
| 1045 | return getResources().getAssets(); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1046 | } |
| 1047 | |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 1048 | @UnsupportedAppUsage |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1049 | public Resources getResources() { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1050 | if (mResources == null) { |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1051 | final String[] splitPaths; |
| 1052 | try { |
| 1053 | splitPaths = getSplitPaths(null); |
Adam Lesinski | 1665d0f | 2017-03-10 14:46:57 -0800 | [diff] [blame] | 1054 | } catch (NameNotFoundException e) { |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1055 | // This should never fail. |
| 1056 | throw new AssertionError("null split not found"); |
| 1057 | } |
| 1058 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 1059 | mResources = ResourcesManager.getInstance().getResources(null, mResDir, |
| 1060 | splitPaths, mOverlayDirs, mApplicationInfo.sharedLibraryFiles, |
| 1061 | Display.DEFAULT_DISPLAY, null, getCompatibilityInfo(), |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1062 | getClassLoader()); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1063 | } |
| 1064 | return mResources; |
| 1065 | } |
| 1066 | |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 1067 | @UnsupportedAppUsage |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1068 | public Application makeApplication(boolean forceDefaultAppClass, |
| 1069 | Instrumentation instrumentation) { |
| 1070 | if (mApplication != null) { |
| 1071 | return mApplication; |
| 1072 | } |
| 1073 | |
Andreas Gampe | 4c8e542 | 2016-05-18 11:58:47 -0700 | [diff] [blame] | 1074 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "makeApplication"); |
| 1075 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1076 | Application app = null; |
| 1077 | |
| 1078 | String appClass = mApplicationInfo.className; |
| 1079 | if (forceDefaultAppClass || (appClass == null)) { |
| 1080 | appClass = "android.app.Application"; |
| 1081 | } |
| 1082 | |
| 1083 | try { |
| 1084 | java.lang.ClassLoader cl = getClassLoader(); |
Narayan Kamath | 8091edb | 2014-10-15 11:38:44 +0100 | [diff] [blame] | 1085 | if (!mPackageName.equals("android")) { |
Andreas Gampe | 4c8e542 | 2016-05-18 11:58:47 -0700 | [diff] [blame] | 1086 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, |
| 1087 | "initializeJavaContextClassLoader"); |
Narayan Kamath | 8091edb | 2014-10-15 11:38:44 +0100 | [diff] [blame] | 1088 | initializeJavaContextClassLoader(); |
Andreas Gampe | 4c8e542 | 2016-05-18 11:58:47 -0700 | [diff] [blame] | 1089 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Narayan Kamath | 8091edb | 2014-10-15 11:38:44 +0100 | [diff] [blame] | 1090 | } |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 1091 | ContextImpl appContext = ContextImpl.createAppContext(mActivityThread, this); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1092 | app = mActivityThread.mInstrumentation.newApplication( |
| 1093 | cl, appClass, appContext); |
| 1094 | appContext.setOuterContext(app); |
| 1095 | } catch (Exception e) { |
| 1096 | if (!mActivityThread.mInstrumentation.onException(app, e)) { |
Andreas Gampe | 4c8e542 | 2016-05-18 11:58:47 -0700 | [diff] [blame] | 1097 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1098 | throw new RuntimeException( |
| 1099 | "Unable to instantiate application " + appClass |
| 1100 | + ": " + e.toString(), e); |
| 1101 | } |
| 1102 | } |
| 1103 | mActivityThread.mAllApplications.add(app); |
| 1104 | mApplication = app; |
| 1105 | |
| 1106 | if (instrumentation != null) { |
| 1107 | try { |
| 1108 | instrumentation.callApplicationOnCreate(app); |
| 1109 | } catch (Exception e) { |
| 1110 | if (!instrumentation.onException(app, e)) { |
Andreas Gampe | 4c8e542 | 2016-05-18 11:58:47 -0700 | [diff] [blame] | 1111 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1112 | throw new RuntimeException( |
| 1113 | "Unable to create application " + app.getClass().getName() |
| 1114 | + ": " + e.toString(), e); |
| 1115 | } |
| 1116 | } |
| 1117 | } |
Adam Lesinski | de898ff | 2014-01-29 18:20:45 -0800 | [diff] [blame] | 1118 | |
| 1119 | // Rewrite the R 'constants' for all library apks. |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 1120 | SparseArray<String> packageIdentifiers = getAssets().getAssignedPackageIdentifiers(); |
Adam Lesinski | de898ff | 2014-01-29 18:20:45 -0800 | [diff] [blame] | 1121 | final int N = packageIdentifiers.size(); |
| 1122 | for (int i = 0; i < N; i++) { |
| 1123 | final int id = packageIdentifiers.keyAt(i); |
| 1124 | if (id == 0x01 || id == 0x7f) { |
| 1125 | continue; |
| 1126 | } |
| 1127 | |
| 1128 | rewriteRValues(getClassLoader(), packageIdentifiers.valueAt(i), id); |
| 1129 | } |
| 1130 | |
Andreas Gampe | 4c8e542 | 2016-05-18 11:58:47 -0700 | [diff] [blame] | 1131 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
| 1132 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1133 | return app; |
| 1134 | } |
| 1135 | |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 1136 | @UnsupportedAppUsage |
Adam Lesinski | de898ff | 2014-01-29 18:20:45 -0800 | [diff] [blame] | 1137 | private void rewriteRValues(ClassLoader cl, String packageName, int id) { |
Adam Lesinski | 2cb761e | 2014-08-15 13:59:02 -0700 | [diff] [blame] | 1138 | final Class<?> rClazz; |
Adam Lesinski | de898ff | 2014-01-29 18:20:45 -0800 | [diff] [blame] | 1139 | try { |
Adam Lesinski | 2cb761e | 2014-08-15 13:59:02 -0700 | [diff] [blame] | 1140 | rClazz = cl.loadClass(packageName + ".R"); |
| 1141 | } catch (ClassNotFoundException e) { |
| 1142 | // This is not necessarily an error, as some packages do not ship with resources |
| 1143 | // (or they do not need rewriting). |
Adam Lesinski | 1e466385 | 2014-08-15 14:47:28 -0700 | [diff] [blame] | 1144 | Log.i(TAG, "No resource references to update in package " + packageName); |
Adam Lesinski | 2cb761e | 2014-08-15 13:59:02 -0700 | [diff] [blame] | 1145 | return; |
| 1146 | } |
| 1147 | |
Adam Lesinski | 1e466385 | 2014-08-15 14:47:28 -0700 | [diff] [blame] | 1148 | final Method callback; |
Adam Lesinski | 2cb761e | 2014-08-15 13:59:02 -0700 | [diff] [blame] | 1149 | try { |
Adam Lesinski | 1e466385 | 2014-08-15 14:47:28 -0700 | [diff] [blame] | 1150 | callback = rClazz.getMethod("onResourcesLoaded", int.class); |
| 1151 | } catch (NoSuchMethodException e) { |
| 1152 | // No rewriting to be done. |
| 1153 | return; |
Adam Lesinski | de898ff | 2014-01-29 18:20:45 -0800 | [diff] [blame] | 1154 | } |
Adam Lesinski | 1e466385 | 2014-08-15 14:47:28 -0700 | [diff] [blame] | 1155 | |
| 1156 | Throwable cause; |
| 1157 | try { |
| 1158 | callback.invoke(null, id); |
| 1159 | return; |
| 1160 | } catch (IllegalAccessException e) { |
| 1161 | cause = e; |
| 1162 | } catch (InvocationTargetException e) { |
| 1163 | cause = e.getCause(); |
| 1164 | } |
| 1165 | |
| 1166 | throw new RuntimeException("Failed to rewrite resource references for " + packageName, |
| 1167 | cause); |
Adam Lesinski | de898ff | 2014-01-29 18:20:45 -0800 | [diff] [blame] | 1168 | } |
| 1169 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1170 | public void removeContextRegistrations(Context context, |
| 1171 | String who, String what) { |
Jeff Sharkey | d7026f1 | 2012-03-01 20:50:32 -0800 | [diff] [blame] | 1172 | final boolean reportRegistrationLeaks = StrictMode.vmRegistrationLeaksEnabled(); |
Adam Lesinski | 23d40c4 | 2014-11-20 11:58:21 -0800 | [diff] [blame] | 1173 | synchronized (mReceivers) { |
| 1174 | ArrayMap<BroadcastReceiver, LoadedApk.ReceiverDispatcher> rmap = |
| 1175 | mReceivers.remove(context); |
| 1176 | if (rmap != null) { |
| 1177 | for (int i = 0; i < rmap.size(); i++) { |
| 1178 | LoadedApk.ReceiverDispatcher rd = rmap.valueAt(i); |
| 1179 | IntentReceiverLeaked leak = new IntentReceiverLeaked( |
| 1180 | what + " " + who + " has leaked IntentReceiver " |
| 1181 | + rd.getIntentReceiver() + " that was " + |
| 1182 | "originally registered here. Are you missing a " + |
| 1183 | "call to unregisterReceiver()?"); |
| 1184 | leak.setStackTrace(rd.getLocation().getStackTrace()); |
| 1185 | Slog.e(ActivityThread.TAG, leak.getMessage(), leak); |
| 1186 | if (reportRegistrationLeaks) { |
| 1187 | StrictMode.onIntentReceiverLeaked(leak); |
| 1188 | } |
| 1189 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 1190 | ActivityManager.getService().unregisterReceiver( |
Adam Lesinski | 23d40c4 | 2014-11-20 11:58:21 -0800 | [diff] [blame] | 1191 | rd.getIIntentReceiver()); |
| 1192 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1193 | throw e.rethrowFromSystemServer(); |
Adam Lesinski | 23d40c4 | 2014-11-20 11:58:21 -0800 | [diff] [blame] | 1194 | } |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1195 | } |
| 1196 | } |
Adam Lesinski | 23d40c4 | 2014-11-20 11:58:21 -0800 | [diff] [blame] | 1197 | mUnregisteredReceivers.remove(context); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1198 | } |
Adam Lesinski | 23d40c4 | 2014-11-20 11:58:21 -0800 | [diff] [blame] | 1199 | |
| 1200 | synchronized (mServices) { |
| 1201 | //Slog.i(TAG, "Receiver registrations: " + mReceivers); |
| 1202 | ArrayMap<ServiceConnection, LoadedApk.ServiceDispatcher> smap = |
| 1203 | mServices.remove(context); |
| 1204 | if (smap != null) { |
| 1205 | for (int i = 0; i < smap.size(); i++) { |
| 1206 | LoadedApk.ServiceDispatcher sd = smap.valueAt(i); |
| 1207 | ServiceConnectionLeaked leak = new ServiceConnectionLeaked( |
| 1208 | what + " " + who + " has leaked ServiceConnection " |
| 1209 | + sd.getServiceConnection() + " that was originally bound here"); |
| 1210 | leak.setStackTrace(sd.getLocation().getStackTrace()); |
| 1211 | Slog.e(ActivityThread.TAG, leak.getMessage(), leak); |
| 1212 | if (reportRegistrationLeaks) { |
| 1213 | StrictMode.onServiceConnectionLeaked(leak); |
| 1214 | } |
| 1215 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 1216 | ActivityManager.getService().unbindService( |
Adam Lesinski | 23d40c4 | 2014-11-20 11:58:21 -0800 | [diff] [blame] | 1217 | sd.getIServiceConnection()); |
| 1218 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1219 | throw e.rethrowFromSystemServer(); |
Adam Lesinski | 23d40c4 | 2014-11-20 11:58:21 -0800 | [diff] [blame] | 1220 | } |
| 1221 | sd.doForget(); |
Jeff Sharkey | d7026f1 | 2012-03-01 20:50:32 -0800 | [diff] [blame] | 1222 | } |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1223 | } |
Adam Lesinski | 23d40c4 | 2014-11-20 11:58:21 -0800 | [diff] [blame] | 1224 | mUnboundServices.remove(context); |
| 1225 | //Slog.i(TAG, "Service registrations: " + mServices); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1226 | } |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1227 | } |
| 1228 | |
| 1229 | public IIntentReceiver getReceiverDispatcher(BroadcastReceiver r, |
| 1230 | Context context, Handler handler, |
| 1231 | Instrumentation instrumentation, boolean registered) { |
| 1232 | synchronized (mReceivers) { |
| 1233 | LoadedApk.ReceiverDispatcher rd = null; |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 1234 | ArrayMap<BroadcastReceiver, LoadedApk.ReceiverDispatcher> map = null; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1235 | if (registered) { |
| 1236 | map = mReceivers.get(context); |
| 1237 | if (map != null) { |
| 1238 | rd = map.get(r); |
| 1239 | } |
| 1240 | } |
| 1241 | if (rd == null) { |
| 1242 | rd = new ReceiverDispatcher(r, context, handler, |
| 1243 | instrumentation, registered); |
| 1244 | if (registered) { |
| 1245 | if (map == null) { |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 1246 | map = new ArrayMap<BroadcastReceiver, LoadedApk.ReceiverDispatcher>(); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1247 | mReceivers.put(context, map); |
| 1248 | } |
| 1249 | map.put(r, rd); |
| 1250 | } |
| 1251 | } else { |
| 1252 | rd.validate(context, handler); |
| 1253 | } |
Dianne Hackborn | c2d9c8e | 2011-01-24 21:59:21 -0800 | [diff] [blame] | 1254 | rd.mForgotten = false; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1255 | return rd.getIIntentReceiver(); |
| 1256 | } |
| 1257 | } |
| 1258 | |
| 1259 | public IIntentReceiver forgetReceiverDispatcher(Context context, |
| 1260 | BroadcastReceiver r) { |
| 1261 | synchronized (mReceivers) { |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 1262 | ArrayMap<BroadcastReceiver, LoadedApk.ReceiverDispatcher> map = mReceivers.get(context); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1263 | LoadedApk.ReceiverDispatcher rd = null; |
| 1264 | if (map != null) { |
| 1265 | rd = map.get(r); |
| 1266 | if (rd != null) { |
| 1267 | map.remove(r); |
| 1268 | if (map.size() == 0) { |
| 1269 | mReceivers.remove(context); |
| 1270 | } |
| 1271 | if (r.getDebugUnregister()) { |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 1272 | ArrayMap<BroadcastReceiver, LoadedApk.ReceiverDispatcher> holder |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1273 | = mUnregisteredReceivers.get(context); |
| 1274 | if (holder == null) { |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 1275 | holder = new ArrayMap<BroadcastReceiver, LoadedApk.ReceiverDispatcher>(); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1276 | mUnregisteredReceivers.put(context, holder); |
| 1277 | } |
| 1278 | RuntimeException ex = new IllegalArgumentException( |
| 1279 | "Originally unregistered here:"); |
| 1280 | ex.fillInStackTrace(); |
| 1281 | rd.setUnregisterLocation(ex); |
| 1282 | holder.put(r, rd); |
| 1283 | } |
Dianne Hackborn | c2d9c8e | 2011-01-24 21:59:21 -0800 | [diff] [blame] | 1284 | rd.mForgotten = true; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1285 | return rd.getIIntentReceiver(); |
| 1286 | } |
| 1287 | } |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 1288 | ArrayMap<BroadcastReceiver, LoadedApk.ReceiverDispatcher> holder |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1289 | = mUnregisteredReceivers.get(context); |
| 1290 | if (holder != null) { |
| 1291 | rd = holder.get(r); |
| 1292 | if (rd != null) { |
| 1293 | RuntimeException ex = rd.getUnregisterLocation(); |
| 1294 | throw new IllegalArgumentException( |
| 1295 | "Unregistering Receiver " + r |
| 1296 | + " that was already unregistered", ex); |
| 1297 | } |
| 1298 | } |
| 1299 | if (context == null) { |
| 1300 | throw new IllegalStateException("Unbinding Receiver " + r |
| 1301 | + " from Context that is no longer in use: " + context); |
| 1302 | } else { |
| 1303 | throw new IllegalArgumentException("Receiver not registered: " + r); |
| 1304 | } |
| 1305 | |
| 1306 | } |
| 1307 | } |
| 1308 | |
| 1309 | static final class ReceiverDispatcher { |
| 1310 | |
| 1311 | final static class InnerReceiver extends IIntentReceiver.Stub { |
| 1312 | final WeakReference<LoadedApk.ReceiverDispatcher> mDispatcher; |
| 1313 | final LoadedApk.ReceiverDispatcher mStrongRef; |
| 1314 | |
| 1315 | InnerReceiver(LoadedApk.ReceiverDispatcher rd, boolean strong) { |
| 1316 | mDispatcher = new WeakReference<LoadedApk.ReceiverDispatcher>(rd); |
| 1317 | mStrongRef = strong ? rd : null; |
| 1318 | } |
Jeff Sharkey | d136e51 | 2016-03-09 22:30:56 -0700 | [diff] [blame] | 1319 | |
| 1320 | @Override |
Dianne Hackborn | 20e8098 | 2012-08-31 19:00:44 -0700 | [diff] [blame] | 1321 | public void performReceive(Intent intent, int resultCode, String data, |
| 1322 | Bundle extras, boolean ordered, boolean sticky, int sendingUser) { |
Dianne Hackborn | 2675616 | 2016-05-17 13:40:44 -0700 | [diff] [blame] | 1323 | final LoadedApk.ReceiverDispatcher rd; |
| 1324 | if (intent == null) { |
| 1325 | Log.wtf(TAG, "Null intent received"); |
| 1326 | rd = null; |
| 1327 | } else { |
| 1328 | rd = mDispatcher.get(); |
| 1329 | } |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1330 | if (ActivityThread.DEBUG_BROADCAST) { |
| 1331 | int seq = intent.getIntExtra("seq", -1); |
Dianne Hackborn | 2675616 | 2016-05-17 13:40:44 -0700 | [diff] [blame] | 1332 | Slog.i(ActivityThread.TAG, "Receiving broadcast " + intent.getAction() |
| 1333 | + " seq=" + seq + " to " + (rd != null ? rd.mReceiver : null)); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1334 | } |
| 1335 | if (rd != null) { |
| 1336 | rd.performReceive(intent, resultCode, data, extras, |
Dianne Hackborn | 20e8098 | 2012-08-31 19:00:44 -0700 | [diff] [blame] | 1337 | ordered, sticky, sendingUser); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1338 | } else { |
| 1339 | // The activity manager dispatched a broadcast to a registered |
| 1340 | // receiver in this process, but before it could be delivered the |
| 1341 | // receiver was unregistered. Acknowledge the broadcast on its |
| 1342 | // behalf so that the system's broadcast sequence can continue. |
| 1343 | if (ActivityThread.DEBUG_BROADCAST) Slog.i(ActivityThread.TAG, |
| 1344 | "Finishing broadcast to unregistered receiver"); |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 1345 | IActivityManager mgr = ActivityManager.getService(); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1346 | try { |
Dianne Hackborn | 9ecebbf | 2011-09-28 23:19:47 -0400 | [diff] [blame] | 1347 | if (extras != null) { |
| 1348 | extras.setAllowFds(false); |
| 1349 | } |
riddle_hsu | 1f5ac4d | 2015-01-03 15:38:21 +0800 | [diff] [blame] | 1350 | mgr.finishReceiver(this, resultCode, data, extras, false, intent.getFlags()); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1351 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1352 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1353 | } |
| 1354 | } |
| 1355 | } |
| 1356 | } |
| 1357 | |
| 1358 | final IIntentReceiver.Stub mIIntentReceiver; |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 1359 | @UnsupportedAppUsage |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1360 | final BroadcastReceiver mReceiver; |
Mathew Inwood | 45d2c25 | 2018-09-14 12:35:36 +0100 | [diff] [blame] | 1361 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1362 | final Context mContext; |
| 1363 | final Handler mActivityThread; |
| 1364 | final Instrumentation mInstrumentation; |
| 1365 | final boolean mRegistered; |
| 1366 | final IntentReceiverLeaked mLocation; |
| 1367 | RuntimeException mUnregisterLocation; |
Dianne Hackborn | c2d9c8e | 2011-01-24 21:59:21 -0800 | [diff] [blame] | 1368 | boolean mForgotten; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1369 | |
Makoto Onuki | 08408b9 | 2017-05-09 13:48:53 -0700 | [diff] [blame] | 1370 | final class Args extends BroadcastReceiver.PendingResult { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1371 | private Intent mCurIntent; |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 1372 | private final boolean mOrdered; |
Dianne Hackborn | 17c7753 | 2016-06-22 16:49:14 -0700 | [diff] [blame] | 1373 | private boolean mDispatched; |
Makoto Onuki | f3bb6f3 | 2017-05-02 12:02:23 -0700 | [diff] [blame] | 1374 | private Throwable mPreviousRunStacktrace; // To investigate b/37809561. STOPSHIP remove. |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1375 | |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 1376 | public Args(Intent intent, int resultCode, String resultData, Bundle resultExtras, |
Dianne Hackborn | 20e8098 | 2012-08-31 19:00:44 -0700 | [diff] [blame] | 1377 | boolean ordered, boolean sticky, int sendingUser) { |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 1378 | super(resultCode, resultData, resultExtras, |
riddle_hsu | 1f5ac4d | 2015-01-03 15:38:21 +0800 | [diff] [blame] | 1379 | mRegistered ? TYPE_REGISTERED : TYPE_UNREGISTERED, ordered, |
| 1380 | sticky, mIIntentReceiver.asBinder(), sendingUser, intent.getFlags()); |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 1381 | mCurIntent = intent; |
| 1382 | mOrdered = ordered; |
| 1383 | } |
Dianne Hackborn | 17c7753 | 2016-06-22 16:49:14 -0700 | [diff] [blame] | 1384 | |
Makoto Onuki | 08408b9 | 2017-05-09 13:48:53 -0700 | [diff] [blame] | 1385 | public final Runnable getRunnable() { |
| 1386 | return () -> { |
| 1387 | final BroadcastReceiver receiver = mReceiver; |
| 1388 | final boolean ordered = mOrdered; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1389 | |
Makoto Onuki | 08408b9 | 2017-05-09 13:48:53 -0700 | [diff] [blame] | 1390 | if (ActivityThread.DEBUG_BROADCAST) { |
| 1391 | int seq = mCurIntent.getIntExtra("seq", -1); |
| 1392 | Slog.i(ActivityThread.TAG, "Dispatching broadcast " + mCurIntent.getAction() |
| 1393 | + " seq=" + seq + " to " + mReceiver); |
| 1394 | Slog.i(ActivityThread.TAG, " mRegistered=" + mRegistered |
| 1395 | + " mOrderedHint=" + ordered); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1396 | } |
Makoto Onuki | 08408b9 | 2017-05-09 13:48:53 -0700 | [diff] [blame] | 1397 | |
| 1398 | final IActivityManager mgr = ActivityManager.getService(); |
| 1399 | final Intent intent = mCurIntent; |
| 1400 | if (intent == null) { |
| 1401 | Log.wtf(TAG, "Null intent being dispatched, mDispatched=" + mDispatched |
| 1402 | + ": run() previously called at " |
| 1403 | + Log.getStackTraceString(mPreviousRunStacktrace)); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1404 | } |
Makoto Onuki | 08408b9 | 2017-05-09 13:48:53 -0700 | [diff] [blame] | 1405 | |
| 1406 | mCurIntent = null; |
| 1407 | mDispatched = true; |
| 1408 | mPreviousRunStacktrace = new Throwable("Previous stacktrace"); |
| 1409 | if (receiver == null || intent == null || mForgotten) { |
| 1410 | if (mRegistered && ordered) { |
| 1411 | if (ActivityThread.DEBUG_BROADCAST) Slog.i(ActivityThread.TAG, |
| 1412 | "Finishing null broadcast to " + mReceiver); |
| 1413 | sendFinished(mgr); |
| 1414 | } |
| 1415 | return; |
| 1416 | } |
| 1417 | |
| 1418 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "broadcastReceiveReg"); |
| 1419 | try { |
| 1420 | ClassLoader cl = mReceiver.getClass().getClassLoader(); |
| 1421 | intent.setExtrasClassLoader(cl); |
| 1422 | intent.prepareToEnterProcess(); |
| 1423 | setExtrasClassLoader(cl); |
| 1424 | receiver.setPendingResult(this); |
| 1425 | receiver.onReceive(mContext, intent); |
| 1426 | } catch (Exception e) { |
| 1427 | if (mRegistered && ordered) { |
| 1428 | if (ActivityThread.DEBUG_BROADCAST) Slog.i(ActivityThread.TAG, |
| 1429 | "Finishing failed broadcast to " + mReceiver); |
| 1430 | sendFinished(mgr); |
| 1431 | } |
| 1432 | if (mInstrumentation == null || |
| 1433 | !mInstrumentation.onException(mReceiver, e)) { |
| 1434 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
| 1435 | throw new RuntimeException( |
| 1436 | "Error receiving broadcast " + intent |
| 1437 | + " in " + mReceiver, e); |
| 1438 | } |
| 1439 | } |
| 1440 | |
| 1441 | if (receiver.getPendingResult() != null) { |
| 1442 | finish(); |
| 1443 | } |
| 1444 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
| 1445 | }; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1446 | } |
| 1447 | } |
| 1448 | |
| 1449 | ReceiverDispatcher(BroadcastReceiver receiver, Context context, |
| 1450 | Handler activityThread, Instrumentation instrumentation, |
| 1451 | boolean registered) { |
| 1452 | if (activityThread == null) { |
| 1453 | throw new NullPointerException("Handler must not be null"); |
| 1454 | } |
| 1455 | |
| 1456 | mIIntentReceiver = new InnerReceiver(this, !registered); |
| 1457 | mReceiver = receiver; |
| 1458 | mContext = context; |
| 1459 | mActivityThread = activityThread; |
| 1460 | mInstrumentation = instrumentation; |
| 1461 | mRegistered = registered; |
| 1462 | mLocation = new IntentReceiverLeaked(null); |
| 1463 | mLocation.fillInStackTrace(); |
| 1464 | } |
| 1465 | |
| 1466 | void validate(Context context, Handler activityThread) { |
| 1467 | if (mContext != context) { |
| 1468 | throw new IllegalStateException( |
| 1469 | "Receiver " + mReceiver + |
| 1470 | " registered with differing Context (was " + |
| 1471 | mContext + " now " + context + ")"); |
| 1472 | } |
| 1473 | if (mActivityThread != activityThread) { |
| 1474 | throw new IllegalStateException( |
| 1475 | "Receiver " + mReceiver + |
| 1476 | " registered with differing handler (was " + |
| 1477 | mActivityThread + " now " + activityThread + ")"); |
| 1478 | } |
| 1479 | } |
| 1480 | |
| 1481 | IntentReceiverLeaked getLocation() { |
| 1482 | return mLocation; |
| 1483 | } |
| 1484 | |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 1485 | @UnsupportedAppUsage |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1486 | BroadcastReceiver getIntentReceiver() { |
| 1487 | return mReceiver; |
| 1488 | } |
| 1489 | |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 1490 | @UnsupportedAppUsage |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1491 | IIntentReceiver getIIntentReceiver() { |
| 1492 | return mIIntentReceiver; |
| 1493 | } |
| 1494 | |
| 1495 | void setUnregisterLocation(RuntimeException ex) { |
| 1496 | mUnregisterLocation = ex; |
| 1497 | } |
| 1498 | |
| 1499 | RuntimeException getUnregisterLocation() { |
| 1500 | return mUnregisterLocation; |
| 1501 | } |
| 1502 | |
Dianne Hackborn | 20e8098 | 2012-08-31 19:00:44 -0700 | [diff] [blame] | 1503 | public void performReceive(Intent intent, int resultCode, String data, |
| 1504 | Bundle extras, boolean ordered, boolean sticky, int sendingUser) { |
Dianne Hackborn | 41bfaf8 | 2016-06-08 16:33:29 -0700 | [diff] [blame] | 1505 | final Args args = new Args(intent, resultCode, data, extras, ordered, |
Dianne Hackborn | 20e8098 | 2012-08-31 19:00:44 -0700 | [diff] [blame] | 1506 | sticky, sendingUser); |
Dianne Hackborn | 41bfaf8 | 2016-06-08 16:33:29 -0700 | [diff] [blame] | 1507 | if (intent == null) { |
| 1508 | Log.wtf(TAG, "Null intent received"); |
| 1509 | } else { |
| 1510 | if (ActivityThread.DEBUG_BROADCAST) { |
| 1511 | int seq = intent.getIntExtra("seq", -1); |
| 1512 | Slog.i(ActivityThread.TAG, "Enqueueing broadcast " + intent.getAction() |
| 1513 | + " seq=" + seq + " to " + mReceiver); |
| 1514 | } |
| 1515 | } |
Makoto Onuki | 08408b9 | 2017-05-09 13:48:53 -0700 | [diff] [blame] | 1516 | if (intent == null || !mActivityThread.post(args.getRunnable())) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1517 | if (mRegistered && ordered) { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 1518 | IActivityManager mgr = ActivityManager.getService(); |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 1519 | if (ActivityThread.DEBUG_BROADCAST) Slog.i(ActivityThread.TAG, |
| 1520 | "Finishing sync broadcast to " + mReceiver); |
| 1521 | args.sendFinished(mgr); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1522 | } |
| 1523 | } |
| 1524 | } |
| 1525 | |
| 1526 | } |
| 1527 | |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 1528 | @UnsupportedAppUsage |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1529 | public final IServiceConnection getServiceDispatcher(ServiceConnection c, |
| 1530 | Context context, Handler handler, int flags) { |
| 1531 | synchronized (mServices) { |
| 1532 | LoadedApk.ServiceDispatcher sd = null; |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 1533 | ArrayMap<ServiceConnection, LoadedApk.ServiceDispatcher> map = mServices.get(context); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1534 | if (map != null) { |
Dianne Hackborn | 9484603 | 2017-03-31 17:55:23 -0700 | [diff] [blame] | 1535 | if (DEBUG) Slog.d(TAG, "Returning existing dispatcher " + sd + " for conn " + c); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1536 | sd = map.get(c); |
| 1537 | } |
| 1538 | if (sd == null) { |
| 1539 | sd = new ServiceDispatcher(c, context, handler, flags); |
Dianne Hackborn | 9484603 | 2017-03-31 17:55:23 -0700 | [diff] [blame] | 1540 | if (DEBUG) Slog.d(TAG, "Creating new dispatcher " + sd + " for conn " + c); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1541 | if (map == null) { |
Dianne Hackborn | 9484603 | 2017-03-31 17:55:23 -0700 | [diff] [blame] | 1542 | map = new ArrayMap<>(); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1543 | mServices.put(context, map); |
| 1544 | } |
| 1545 | map.put(c, sd); |
| 1546 | } else { |
| 1547 | sd.validate(context, handler); |
| 1548 | } |
| 1549 | return sd.getIServiceConnection(); |
| 1550 | } |
| 1551 | } |
| 1552 | |
| 1553 | public final IServiceConnection forgetServiceDispatcher(Context context, |
| 1554 | ServiceConnection c) { |
| 1555 | synchronized (mServices) { |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 1556 | ArrayMap<ServiceConnection, LoadedApk.ServiceDispatcher> map |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1557 | = mServices.get(context); |
| 1558 | LoadedApk.ServiceDispatcher sd = null; |
| 1559 | if (map != null) { |
| 1560 | sd = map.get(c); |
| 1561 | if (sd != null) { |
Dianne Hackborn | 9484603 | 2017-03-31 17:55:23 -0700 | [diff] [blame] | 1562 | if (DEBUG) Slog.d(TAG, "Removing dispatcher " + sd + " for conn " + c); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1563 | map.remove(c); |
| 1564 | sd.doForget(); |
| 1565 | if (map.size() == 0) { |
| 1566 | mServices.remove(context); |
| 1567 | } |
| 1568 | if ((sd.getFlags()&Context.BIND_DEBUG_UNBIND) != 0) { |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 1569 | ArrayMap<ServiceConnection, LoadedApk.ServiceDispatcher> holder |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1570 | = mUnboundServices.get(context); |
| 1571 | if (holder == null) { |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 1572 | holder = new ArrayMap<ServiceConnection, LoadedApk.ServiceDispatcher>(); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1573 | mUnboundServices.put(context, holder); |
| 1574 | } |
| 1575 | RuntimeException ex = new IllegalArgumentException( |
| 1576 | "Originally unbound here:"); |
| 1577 | ex.fillInStackTrace(); |
| 1578 | sd.setUnbindLocation(ex); |
| 1579 | holder.put(c, sd); |
| 1580 | } |
| 1581 | return sd.getIServiceConnection(); |
| 1582 | } |
| 1583 | } |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 1584 | ArrayMap<ServiceConnection, LoadedApk.ServiceDispatcher> holder |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1585 | = mUnboundServices.get(context); |
| 1586 | if (holder != null) { |
| 1587 | sd = holder.get(c); |
| 1588 | if (sd != null) { |
| 1589 | RuntimeException ex = sd.getUnbindLocation(); |
| 1590 | throw new IllegalArgumentException( |
| 1591 | "Unbinding Service " + c |
| 1592 | + " that was already unbound", ex); |
| 1593 | } |
| 1594 | } |
| 1595 | if (context == null) { |
| 1596 | throw new IllegalStateException("Unbinding Service " + c |
| 1597 | + " from Context that is no longer in use: " + context); |
| 1598 | } else { |
| 1599 | throw new IllegalArgumentException("Service not registered: " + c); |
| 1600 | } |
| 1601 | } |
| 1602 | } |
| 1603 | |
| 1604 | static final class ServiceDispatcher { |
| 1605 | private final ServiceDispatcher.InnerConnection mIServiceConnection; |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 1606 | @UnsupportedAppUsage |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1607 | private final ServiceConnection mConnection; |
Mathew Inwood | 45d2c25 | 2018-09-14 12:35:36 +0100 | [diff] [blame] | 1608 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1609 | private final Context mContext; |
| 1610 | private final Handler mActivityThread; |
| 1611 | private final ServiceConnectionLeaked mLocation; |
| 1612 | private final int mFlags; |
| 1613 | |
| 1614 | private RuntimeException mUnbindLocation; |
| 1615 | |
Dianne Hackborn | 5a6ef73 | 2011-11-11 12:31:52 -0800 | [diff] [blame] | 1616 | private boolean mForgotten; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1617 | |
| 1618 | private static class ConnectionInfo { |
| 1619 | IBinder binder; |
| 1620 | IBinder.DeathRecipient deathMonitor; |
| 1621 | } |
| 1622 | |
| 1623 | private static class InnerConnection extends IServiceConnection.Stub { |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 1624 | @UnsupportedAppUsage |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1625 | final WeakReference<LoadedApk.ServiceDispatcher> mDispatcher; |
| 1626 | |
| 1627 | InnerConnection(LoadedApk.ServiceDispatcher sd) { |
| 1628 | mDispatcher = new WeakReference<LoadedApk.ServiceDispatcher>(sd); |
| 1629 | } |
| 1630 | |
Dianne Hackborn | 9484603 | 2017-03-31 17:55:23 -0700 | [diff] [blame] | 1631 | public void connected(ComponentName name, IBinder service, boolean dead) |
| 1632 | throws RemoteException { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1633 | LoadedApk.ServiceDispatcher sd = mDispatcher.get(); |
| 1634 | if (sd != null) { |
Dianne Hackborn | 9484603 | 2017-03-31 17:55:23 -0700 | [diff] [blame] | 1635 | sd.connected(name, service, dead); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1636 | } |
| 1637 | } |
| 1638 | } |
| 1639 | |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 1640 | private final ArrayMap<ComponentName, ServiceDispatcher.ConnectionInfo> mActiveConnections |
| 1641 | = new ArrayMap<ComponentName, ServiceDispatcher.ConnectionInfo>(); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1642 | |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 1643 | @UnsupportedAppUsage |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1644 | ServiceDispatcher(ServiceConnection conn, |
| 1645 | Context context, Handler activityThread, int flags) { |
| 1646 | mIServiceConnection = new InnerConnection(this); |
| 1647 | mConnection = conn; |
| 1648 | mContext = context; |
| 1649 | mActivityThread = activityThread; |
| 1650 | mLocation = new ServiceConnectionLeaked(null); |
| 1651 | mLocation.fillInStackTrace(); |
| 1652 | mFlags = flags; |
| 1653 | } |
| 1654 | |
| 1655 | void validate(Context context, Handler activityThread) { |
| 1656 | if (mContext != context) { |
| 1657 | throw new RuntimeException( |
| 1658 | "ServiceConnection " + mConnection + |
| 1659 | " registered with differing Context (was " + |
| 1660 | mContext + " now " + context + ")"); |
| 1661 | } |
| 1662 | if (mActivityThread != activityThread) { |
| 1663 | throw new RuntimeException( |
| 1664 | "ServiceConnection " + mConnection + |
| 1665 | " registered with differing handler (was " + |
| 1666 | mActivityThread + " now " + activityThread + ")"); |
| 1667 | } |
| 1668 | } |
| 1669 | |
| 1670 | void doForget() { |
| 1671 | synchronized(this) { |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 1672 | for (int i=0; i<mActiveConnections.size(); i++) { |
| 1673 | ServiceDispatcher.ConnectionInfo ci = mActiveConnections.valueAt(i); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1674 | ci.binder.unlinkToDeath(ci.deathMonitor, 0); |
| 1675 | } |
| 1676 | mActiveConnections.clear(); |
Dianne Hackborn | 5a6ef73 | 2011-11-11 12:31:52 -0800 | [diff] [blame] | 1677 | mForgotten = true; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1678 | } |
| 1679 | } |
| 1680 | |
| 1681 | ServiceConnectionLeaked getLocation() { |
| 1682 | return mLocation; |
| 1683 | } |
| 1684 | |
| 1685 | ServiceConnection getServiceConnection() { |
| 1686 | return mConnection; |
| 1687 | } |
| 1688 | |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 1689 | @UnsupportedAppUsage |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1690 | IServiceConnection getIServiceConnection() { |
| 1691 | return mIServiceConnection; |
| 1692 | } |
| 1693 | |
| 1694 | int getFlags() { |
| 1695 | return mFlags; |
| 1696 | } |
| 1697 | |
| 1698 | void setUnbindLocation(RuntimeException ex) { |
| 1699 | mUnbindLocation = ex; |
| 1700 | } |
| 1701 | |
| 1702 | RuntimeException getUnbindLocation() { |
| 1703 | return mUnbindLocation; |
| 1704 | } |
| 1705 | |
Dianne Hackborn | 9484603 | 2017-03-31 17:55:23 -0700 | [diff] [blame] | 1706 | public void connected(ComponentName name, IBinder service, boolean dead) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1707 | if (mActivityThread != null) { |
Dianne Hackborn | 9484603 | 2017-03-31 17:55:23 -0700 | [diff] [blame] | 1708 | mActivityThread.post(new RunConnection(name, service, 0, dead)); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1709 | } else { |
Dianne Hackborn | 9484603 | 2017-03-31 17:55:23 -0700 | [diff] [blame] | 1710 | doConnected(name, service, dead); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1711 | } |
| 1712 | } |
| 1713 | |
| 1714 | public void death(ComponentName name, IBinder service) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1715 | if (mActivityThread != null) { |
Dianne Hackborn | 9484603 | 2017-03-31 17:55:23 -0700 | [diff] [blame] | 1716 | mActivityThread.post(new RunConnection(name, service, 1, false)); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1717 | } else { |
| 1718 | doDeath(name, service); |
| 1719 | } |
| 1720 | } |
| 1721 | |
Dianne Hackborn | 9484603 | 2017-03-31 17:55:23 -0700 | [diff] [blame] | 1722 | public void doConnected(ComponentName name, IBinder service, boolean dead) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1723 | ServiceDispatcher.ConnectionInfo old; |
| 1724 | ServiceDispatcher.ConnectionInfo info; |
| 1725 | |
| 1726 | synchronized (this) { |
Dianne Hackborn | 5a6ef73 | 2011-11-11 12:31:52 -0800 | [diff] [blame] | 1727 | if (mForgotten) { |
| 1728 | // We unbound before receiving the connection; ignore |
| 1729 | // any connection received. |
| 1730 | return; |
| 1731 | } |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1732 | old = mActiveConnections.get(name); |
| 1733 | if (old != null && old.binder == service) { |
| 1734 | // Huh, already have this one. Oh well! |
| 1735 | return; |
| 1736 | } |
| 1737 | |
| 1738 | if (service != null) { |
| 1739 | // A new service is being connected... set it all up. |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1740 | info = new ConnectionInfo(); |
| 1741 | info.binder = service; |
| 1742 | info.deathMonitor = new DeathMonitor(name, service); |
| 1743 | try { |
| 1744 | service.linkToDeath(info.deathMonitor, 0); |
| 1745 | mActiveConnections.put(name, info); |
| 1746 | } catch (RemoteException e) { |
| 1747 | // This service was dead before we got it... just |
| 1748 | // don't do anything with it. |
| 1749 | mActiveConnections.remove(name); |
| 1750 | return; |
| 1751 | } |
| 1752 | |
| 1753 | } else { |
| 1754 | // The named service is being disconnected... clean up. |
| 1755 | mActiveConnections.remove(name); |
| 1756 | } |
| 1757 | |
| 1758 | if (old != null) { |
| 1759 | old.binder.unlinkToDeath(old.deathMonitor, 0); |
| 1760 | } |
| 1761 | } |
| 1762 | |
Adrian Roos | a9b4318 | 2016-07-21 13:20:38 -0700 | [diff] [blame] | 1763 | // If there was an old service, it is now disconnected. |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1764 | if (old != null) { |
| 1765 | mConnection.onServiceDisconnected(name); |
| 1766 | } |
Dianne Hackborn | 9484603 | 2017-03-31 17:55:23 -0700 | [diff] [blame] | 1767 | if (dead) { |
Dianne Hackborn | ac26534 | 2017-04-19 14:53:18 -0700 | [diff] [blame] | 1768 | mConnection.onBindingDied(name); |
Dianne Hackborn | 9484603 | 2017-03-31 17:55:23 -0700 | [diff] [blame] | 1769 | } |
Christopher Tate | 5d73b6d | 2017-10-06 16:15:34 -0700 | [diff] [blame] | 1770 | // If there is a new viable service, it is now connected. |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1771 | if (service != null) { |
| 1772 | mConnection.onServiceConnected(name, service); |
Christopher Tate | 5d73b6d | 2017-10-06 16:15:34 -0700 | [diff] [blame] | 1773 | } else { |
| 1774 | // The binding machinery worked, but the remote returned null from onBind(). |
| 1775 | mConnection.onNullBinding(name); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1776 | } |
| 1777 | } |
| 1778 | |
| 1779 | public void doDeath(ComponentName name, IBinder service) { |
Adrian Roos | a9b4318 | 2016-07-21 13:20:38 -0700 | [diff] [blame] | 1780 | synchronized (this) { |
| 1781 | ConnectionInfo old = mActiveConnections.get(name); |
| 1782 | if (old == null || old.binder != service) { |
| 1783 | // Death for someone different than who we last |
| 1784 | // reported... just ignore it. |
| 1785 | return; |
| 1786 | } |
| 1787 | mActiveConnections.remove(name); |
| 1788 | old.binder.unlinkToDeath(old.deathMonitor, 0); |
| 1789 | } |
| 1790 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1791 | mConnection.onServiceDisconnected(name); |
| 1792 | } |
| 1793 | |
| 1794 | private final class RunConnection implements Runnable { |
Dianne Hackborn | 9484603 | 2017-03-31 17:55:23 -0700 | [diff] [blame] | 1795 | RunConnection(ComponentName name, IBinder service, int command, boolean dead) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1796 | mName = name; |
| 1797 | mService = service; |
| 1798 | mCommand = command; |
Dianne Hackborn | 9484603 | 2017-03-31 17:55:23 -0700 | [diff] [blame] | 1799 | mDead = dead; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1800 | } |
| 1801 | |
| 1802 | public void run() { |
| 1803 | if (mCommand == 0) { |
Dianne Hackborn | 9484603 | 2017-03-31 17:55:23 -0700 | [diff] [blame] | 1804 | doConnected(mName, mService, mDead); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1805 | } else if (mCommand == 1) { |
| 1806 | doDeath(mName, mService); |
| 1807 | } |
| 1808 | } |
| 1809 | |
| 1810 | final ComponentName mName; |
| 1811 | final IBinder mService; |
| 1812 | final int mCommand; |
Dianne Hackborn | 9484603 | 2017-03-31 17:55:23 -0700 | [diff] [blame] | 1813 | final boolean mDead; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1814 | } |
| 1815 | |
| 1816 | private final class DeathMonitor implements IBinder.DeathRecipient |
| 1817 | { |
| 1818 | DeathMonitor(ComponentName name, IBinder service) { |
| 1819 | mName = name; |
| 1820 | mService = service; |
| 1821 | } |
| 1822 | |
| 1823 | public void binderDied() { |
| 1824 | death(mName, mService); |
| 1825 | } |
| 1826 | |
| 1827 | final ComponentName mName; |
| 1828 | final IBinder mService; |
| 1829 | } |
| 1830 | } |
| 1831 | } |