The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 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 | |
Christopher Tate | 4528186 | 2010-03-05 15:46:30 -0800 | [diff] [blame] | 19 | import android.app.backup.BackupAgent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 20 | import android.content.BroadcastReceiver; |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 21 | import android.content.ComponentCallbacks2; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 22 | import android.content.ComponentName; |
| 23 | import android.content.ContentProvider; |
| 24 | import android.content.Context; |
| 25 | import android.content.IContentProvider; |
| 26 | import android.content.Intent; |
Suchi Amalapurapu | 1ccac75 | 2009-06-12 10:09:58 -0700 | [diff] [blame] | 27 | import android.content.IIntentReceiver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | import android.content.pm.ActivityInfo; |
| 29 | import android.content.pm.ApplicationInfo; |
| 30 | import android.content.pm.IPackageManager; |
| 31 | import android.content.pm.InstrumentationInfo; |
Christopher Tate | 346acb1 | 2012-10-15 19:20:25 -0700 | [diff] [blame] | 32 | import android.content.pm.PackageInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | import android.content.pm.PackageManager; |
Sen Hu | bde7570 | 2010-05-28 01:54:03 -0700 | [diff] [blame] | 34 | import android.content.pm.PackageManager.NameNotFoundException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | import android.content.pm.ProviderInfo; |
| 36 | import android.content.pm.ServiceInfo; |
| 37 | import android.content.res.AssetManager; |
Mitsuru Oshima | ba3ba57 | 2009-07-08 18:49:26 -0700 | [diff] [blame] | 38 | import android.content.res.CompatibilityInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | import android.content.res.Configuration; |
| 40 | import android.content.res.Resources; |
| 41 | import android.database.sqlite.SQLiteDatabase; |
| 42 | import android.database.sqlite.SQLiteDebug; |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 43 | import android.database.sqlite.SQLiteDebug.DbStats; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | import android.graphics.Bitmap; |
| 45 | import android.graphics.Canvas; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 46 | import android.hardware.display.DisplayManagerGlobal; |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 47 | import android.net.IConnectivityManager; |
| 48 | import android.net.Proxy; |
| 49 | import android.net.ProxyProperties; |
Romain Guy | a958265 | 2011-11-10 14:20:10 -0800 | [diff] [blame] | 50 | import android.opengl.GLUtils; |
Joe Onorato | d630f10 | 2011-03-17 18:42:26 -0700 | [diff] [blame] | 51 | import android.os.AsyncTask; |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 52 | import android.os.Binder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 53 | import android.os.Bundle; |
| 54 | import android.os.Debug; |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 55 | import android.os.DropBoxManager; |
Jeff Sharkey | b049e21 | 2012-09-07 23:16:01 -0700 | [diff] [blame] | 56 | import android.os.Environment; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | import android.os.Handler; |
| 58 | import android.os.IBinder; |
| 59 | import android.os.Looper; |
| 60 | import android.os.Message; |
| 61 | import android.os.MessageQueue; |
Dianne Hackborn | 9c8dd55 | 2009-06-23 19:22:52 -0700 | [diff] [blame] | 62 | import android.os.ParcelFileDescriptor; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 63 | import android.os.Process; |
| 64 | import android.os.RemoteException; |
| 65 | import android.os.ServiceManager; |
Brad Fitzpatrick | 438d059 | 2010-06-10 12:19:19 -0700 | [diff] [blame] | 66 | import android.os.StrictMode; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | import android.os.SystemClock; |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 68 | import android.os.SystemProperties; |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 69 | import android.os.Trace; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 70 | import android.os.UserHandle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 71 | import android.util.AndroidRuntimeException; |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 72 | import android.util.ArrayMap; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 73 | import android.util.DisplayMetrics; |
| 74 | import android.util.EventLog; |
| 75 | import android.util.Log; |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 76 | import android.util.LogPrinter; |
Jeff Brown | 6754ba2 | 2011-12-14 20:20:01 -0800 | [diff] [blame] | 77 | import android.util.PrintWriterPrinter; |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 78 | import android.util.Slog; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 79 | import android.view.Display; |
Romain Guy | 5233920 | 2010-09-03 16:04:46 -0700 | [diff] [blame] | 80 | import android.view.HardwareRenderer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 81 | import android.view.View; |
| 82 | import android.view.ViewDebug; |
| 83 | import android.view.ViewManager; |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 84 | import android.view.ViewRootImpl; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 85 | import android.view.Window; |
| 86 | import android.view.WindowManager; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 87 | import android.view.WindowManagerGlobal; |
Jason Sams | a6f338c | 2012-02-24 16:22:16 -0800 | [diff] [blame] | 88 | import android.renderscript.RenderScript; |
Kenny Root | 8b51475 | 2013-02-04 09:35:16 -0800 | [diff] [blame] | 89 | import android.security.AndroidKeyStoreProvider; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 90 | |
| 91 | import com.android.internal.os.BinderInternal; |
| 92 | import com.android.internal.os.RuntimeInit; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 93 | import com.android.internal.os.SamplingProfilerIntegration; |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 94 | import com.android.internal.util.FastPrintWriter; |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 95 | import com.android.internal.util.Objects; |
Kenny Root | 12e7522 | 2013-04-23 22:34:24 -0700 | [diff] [blame] | 96 | import com.android.org.conscrypt.OpenSSLSocketImpl; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 97 | |
| 98 | import java.io.File; |
| 99 | import java.io.FileDescriptor; |
| 100 | import java.io.FileOutputStream; |
Dianne Hackborn | 9c8dd55 | 2009-06-23 19:22:52 -0700 | [diff] [blame] | 101 | import java.io.IOException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 102 | import java.io.PrintWriter; |
| 103 | import java.lang.ref.WeakReference; |
Robert Greenwalt | 03595d0 | 2010-11-02 14:08:23 -0700 | [diff] [blame] | 104 | import java.net.InetAddress; |
Kenny Root | 8b51475 | 2013-02-04 09:35:16 -0800 | [diff] [blame] | 105 | import java.security.Security; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 106 | import java.util.ArrayList; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 107 | import java.util.List; |
| 108 | import java.util.Locale; |
| 109 | import java.util.Map; |
| 110 | import java.util.TimeZone; |
| 111 | import java.util.regex.Pattern; |
| 112 | |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 113 | import libcore.io.DropBox; |
Geremy Condra | 69689a7 | 2012-09-11 16:57:17 -0700 | [diff] [blame] | 114 | import libcore.io.EventLogger; |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 115 | import libcore.io.IoUtils; |
| 116 | |
Brad Fitzpatrick | 4d9e6d2 | 2010-11-15 08:49:51 -0800 | [diff] [blame] | 117 | import dalvik.system.CloseGuard; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 118 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 119 | final class SuperNotCalledException extends AndroidRuntimeException { |
| 120 | public SuperNotCalledException(String msg) { |
| 121 | super(msg); |
| 122 | } |
| 123 | } |
| 124 | |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 125 | final class RemoteServiceException extends AndroidRuntimeException { |
| 126 | public RemoteServiceException(String msg) { |
| 127 | super(msg); |
| 128 | } |
| 129 | } |
| 130 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 131 | /** |
| 132 | * This manages the execution of the main thread in an |
| 133 | * application process, scheduling and executing activities, |
| 134 | * broadcasts, and other operations on it as the activity |
| 135 | * manager requests. |
| 136 | * |
| 137 | * {@hide} |
| 138 | */ |
| 139 | public final class ActivityThread { |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 140 | /** @hide */ |
| 141 | public static final String TAG = "ActivityThread"; |
Jim Miller | 0b2a6d0 | 2010-07-13 18:01:29 -0700 | [diff] [blame] | 142 | private static final android.graphics.Bitmap.Config THUMBNAIL_FORMAT = Bitmap.Config.RGB_565; |
Joe Onorato | 43a1765 | 2011-04-06 19:22:23 -0700 | [diff] [blame] | 143 | static final boolean localLOGV = false; |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 144 | static final boolean DEBUG_MESSAGES = false; |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 145 | /** @hide */ |
| 146 | public static final boolean DEBUG_BROADCAST = false; |
Chris Tate | 8a7dc17 | 2009-03-24 20:11:42 -0700 | [diff] [blame] | 147 | private static final boolean DEBUG_RESULTS = false; |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 148 | private static final boolean DEBUG_BACKUP = false; |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 149 | public static final boolean DEBUG_CONFIGURATION = false; |
Dianne Hackborn | a0c283e | 2012-02-09 10:47:01 -0800 | [diff] [blame] | 150 | private static final boolean DEBUG_SERVICE = false; |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 151 | private static final boolean DEBUG_MEMORY_TRIM = false; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 152 | private static final boolean DEBUG_PROVIDER = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 153 | private static final long MIN_TIME_BETWEEN_GCS = 5*1000; |
| 154 | private static final Pattern PATTERN_SEMICOLON = Pattern.compile(";"); |
| 155 | private static final int SQLITE_MEM_RELEASED_EVENT_LOG_TAG = 75003; |
| 156 | private static final int LOG_ON_PAUSE_CALLED = 30021; |
| 157 | private static final int LOG_ON_RESUME_CALLED = 30022; |
| 158 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 159 | static ContextImpl mSystemContext = null; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 160 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 161 | static IPackageManager sPackageManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 162 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 163 | final ApplicationThread mAppThread = new ApplicationThread(); |
| 164 | final Looper mLooper = Looper.myLooper(); |
| 165 | final H mH = new H(); |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 166 | final ArrayMap<IBinder, ActivityClientRecord> mActivities |
| 167 | = new ArrayMap<IBinder, ActivityClientRecord>(); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 168 | // List of new activities (via ActivityRecord.nextIdle) that should |
| 169 | // be reported when next we idle. |
| 170 | ActivityClientRecord mNewActivities = null; |
| 171 | // Number of activities that are currently visible on-screen. |
| 172 | int mNumVisibleActivities = 0; |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 173 | final ArrayMap<IBinder, Service> mServices |
| 174 | = new ArrayMap<IBinder, Service>(); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 175 | AppBindData mBoundApplication; |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 176 | Profiler mProfiler; |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 177 | int mCurDefaultDisplayDpi; |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 178 | boolean mDensityCompatMode; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 179 | Configuration mConfiguration; |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 180 | Configuration mCompatConfiguration; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 181 | Application mInitialApplication; |
| 182 | final ArrayList<Application> mAllApplications |
| 183 | = new ArrayList<Application>(); |
| 184 | // set of instantiated backup agents, keyed by package name |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 185 | final ArrayMap<String, BackupAgent> mBackupAgents = new ArrayMap<String, BackupAgent>(); |
Jeff Sharkey | 66a017b | 2013-01-17 18:18:22 -0800 | [diff] [blame] | 186 | /** Reference to singleton {@link ActivityThread} */ |
| 187 | private static ActivityThread sCurrentActivityThread; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 188 | Instrumentation mInstrumentation; |
| 189 | String mInstrumentationAppDir = null; |
Brian Carlstrom | d893a89 | 2012-04-01 21:30:26 -0700 | [diff] [blame] | 190 | String mInstrumentationAppLibraryDir = null; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 191 | String mInstrumentationAppPackage = null; |
| 192 | String mInstrumentedAppDir = null; |
Brian Carlstrom | d893a89 | 2012-04-01 21:30:26 -0700 | [diff] [blame] | 193 | String mInstrumentedAppLibraryDir = null; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 194 | boolean mSystemThread = false; |
| 195 | boolean mJitEnabled = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 196 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 197 | // These can be accessed by multiple threads; mPackages is the lock. |
| 198 | // XXX For now we keep around information about all packages we have |
| 199 | // seen, not removing entries from this map. |
Dianne Hackborn | 1fbee79 | 2011-11-30 11:29:58 -0800 | [diff] [blame] | 200 | // NOTE: The activity and window managers need to call in to |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 201 | // ActivityThread to do things like update resource configurations, |
Dianne Hackborn | 1fbee79 | 2011-11-30 11:29:58 -0800 | [diff] [blame] | 202 | // which means this lock gets held while the activity and window managers |
| 203 | // holds their own lock. Thus you MUST NEVER call back into the activity manager |
| 204 | // or window manager or anything that depends on them while holding this lock. |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 205 | final ArrayMap<String, WeakReference<LoadedApk>> mPackages |
| 206 | = new ArrayMap<String, WeakReference<LoadedApk>>(); |
| 207 | final ArrayMap<String, WeakReference<LoadedApk>> mResourcePackages |
| 208 | = new ArrayMap<String, WeakReference<LoadedApk>>(); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 209 | final ArrayList<ActivityClientRecord> mRelaunchingActivities |
| 210 | = new ArrayList<ActivityClientRecord>(); |
| 211 | Configuration mPendingConfiguration = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 212 | |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 213 | private final ResourcesManager mResourcesManager; |
| 214 | |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 215 | private static final class ProviderKey { |
| 216 | final String authority; |
| 217 | final int userId; |
| 218 | |
| 219 | public ProviderKey(String authority, int userId) { |
| 220 | this.authority = authority; |
| 221 | this.userId = userId; |
| 222 | } |
| 223 | |
| 224 | @Override |
| 225 | public boolean equals(Object o) { |
| 226 | if (o instanceof ProviderKey) { |
| 227 | final ProviderKey other = (ProviderKey) o; |
| 228 | return Objects.equal(authority, other.authority) && userId == other.userId; |
| 229 | } |
| 230 | return false; |
| 231 | } |
| 232 | |
| 233 | @Override |
| 234 | public int hashCode() { |
| 235 | return ((authority != null) ? authority.hashCode() : 0) ^ userId; |
| 236 | } |
| 237 | } |
| 238 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 239 | // The lock of mProviderMap protects the following variables. |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 240 | final ArrayMap<ProviderKey, ProviderClientRecord> mProviderMap |
| 241 | = new ArrayMap<ProviderKey, ProviderClientRecord>(); |
| 242 | final ArrayMap<IBinder, ProviderRefCount> mProviderRefCountMap |
| 243 | = new ArrayMap<IBinder, ProviderRefCount>(); |
| 244 | final ArrayMap<IBinder, ProviderClientRecord> mLocalProviders |
| 245 | = new ArrayMap<IBinder, ProviderClientRecord>(); |
| 246 | final ArrayMap<ComponentName, ProviderClientRecord> mLocalProvidersByName |
| 247 | = new ArrayMap<ComponentName, ProviderClientRecord>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 248 | |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 249 | final ArrayMap<Activity, ArrayList<OnActivityPausedListener>> mOnPauseListeners |
| 250 | = new ArrayMap<Activity, ArrayList<OnActivityPausedListener>>(); |
Jeff Hamilton | 52d3203 | 2011-01-08 15:31:26 -0600 | [diff] [blame] | 251 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 252 | final GcIdler mGcIdler = new GcIdler(); |
| 253 | boolean mGcIdlerScheduled = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 254 | |
Brad Fitzpatrick | 333b8cb | 2010-08-26 12:04:57 -0700 | [diff] [blame] | 255 | static Handler sMainThreadHandler; // set once in main() |
| 256 | |
Svetoslav Ganov | 9aa597e | 2011-03-03 18:17:41 -0800 | [diff] [blame] | 257 | Bundle mCoreSettings = null; |
| 258 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 259 | static final class ActivityClientRecord { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 260 | IBinder token; |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 261 | int ident; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 262 | Intent intent; |
| 263 | Bundle state; |
| 264 | Activity activity; |
| 265 | Window window; |
| 266 | Activity parent; |
| 267 | String embeddedID; |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 268 | Activity.NonConfigurationInstances lastNonConfigurationInstances; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 269 | boolean paused; |
| 270 | boolean stopped; |
| 271 | boolean hideForNow; |
| 272 | Configuration newConfig; |
Dianne Hackborn | e88846e | 2009-09-30 21:34:25 -0700 | [diff] [blame] | 273 | Configuration createdConfig; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 274 | ActivityClientRecord nextIdle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 275 | |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 276 | String profileFile; |
| 277 | ParcelFileDescriptor profileFd; |
| 278 | boolean autoStopProfiler; |
| 279 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 280 | ActivityInfo activityInfo; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 281 | CompatibilityInfo compatInfo; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 282 | LoadedApk packageInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 283 | |
| 284 | List<ResultInfo> pendingResults; |
| 285 | List<Intent> pendingIntents; |
| 286 | |
| 287 | boolean startsNotResumed; |
| 288 | boolean isForward; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 289 | int pendingConfigChanges; |
| 290 | boolean onlyLocalRequest; |
| 291 | |
| 292 | View mPendingRemoveWindow; |
| 293 | WindowManager mPendingRemoveWindowManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 294 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 295 | ActivityClientRecord() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 296 | parent = null; |
| 297 | embeddedID = null; |
| 298 | paused = false; |
| 299 | stopped = false; |
| 300 | hideForNow = false; |
| 301 | nextIdle = null; |
| 302 | } |
| 303 | |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 304 | public boolean isPreHoneycomb() { |
| 305 | if (activity != null) { |
| 306 | return activity.getApplicationInfo().targetSdkVersion |
| 307 | < android.os.Build.VERSION_CODES.HONEYCOMB; |
| 308 | } |
| 309 | return false; |
| 310 | } |
| 311 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 312 | public String toString() { |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 313 | ComponentName componentName = intent != null ? intent.getComponent() : null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 314 | return "ActivityRecord{" |
| 315 | + Integer.toHexString(System.identityHashCode(this)) |
| 316 | + " token=" + token + " " + (componentName == null |
| 317 | ? "no component name" : componentName.toShortString()) |
| 318 | + "}"; |
| 319 | } |
| 320 | } |
| 321 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 322 | final class ProviderClientRecord { |
| 323 | final String[] mNames; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 324 | final IContentProvider mProvider; |
| 325 | final ContentProvider mLocalProvider; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 326 | final IActivityManager.ContentProviderHolder mHolder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 327 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 328 | ProviderClientRecord(String[] names, IContentProvider provider, |
| 329 | ContentProvider localProvider, |
| 330 | IActivityManager.ContentProviderHolder holder) { |
| 331 | mNames = names; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 332 | mProvider = provider; |
| 333 | mLocalProvider = localProvider; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 334 | mHolder = holder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 335 | } |
| 336 | } |
| 337 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 338 | static final class NewIntentData { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 339 | List<Intent> intents; |
| 340 | IBinder token; |
| 341 | public String toString() { |
| 342 | return "NewIntentData{intents=" + intents + " token=" + token + "}"; |
| 343 | } |
| 344 | } |
| 345 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 346 | static final class ReceiverData extends BroadcastReceiver.PendingResult { |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 347 | public ReceiverData(Intent intent, int resultCode, String resultData, Bundle resultExtras, |
Dianne Hackborn | 20e8098 | 2012-08-31 19:00:44 -0700 | [diff] [blame] | 348 | boolean ordered, boolean sticky, IBinder token, int sendingUser) { |
| 349 | super(resultCode, resultData, resultExtras, TYPE_COMPONENT, ordered, sticky, |
| 350 | token, sendingUser); |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 351 | this.intent = intent; |
| 352 | } |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 353 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 354 | Intent intent; |
| 355 | ActivityInfo info; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 356 | CompatibilityInfo compatInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 357 | public String toString() { |
| 358 | return "ReceiverData{intent=" + intent + " packageName=" + |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 359 | info.packageName + " resultCode=" + getResultCode() |
| 360 | + " resultData=" + getResultData() + " resultExtras=" |
| 361 | + getResultExtras(false) + "}"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 362 | } |
| 363 | } |
| 364 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 365 | static final class CreateBackupAgentData { |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 366 | ApplicationInfo appInfo; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 367 | CompatibilityInfo compatInfo; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 368 | int backupMode; |
| 369 | public String toString() { |
| 370 | return "CreateBackupAgentData{appInfo=" + appInfo |
| 371 | + " backupAgent=" + appInfo.backupAgentName |
| 372 | + " mode=" + backupMode + "}"; |
| 373 | } |
| 374 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 375 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 376 | static final class CreateServiceData { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 377 | IBinder token; |
| 378 | ServiceInfo info; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 379 | CompatibilityInfo compatInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 380 | Intent intent; |
| 381 | public String toString() { |
| 382 | return "CreateServiceData{token=" + token + " className=" |
| 383 | + info.name + " packageName=" + info.packageName |
| 384 | + " intent=" + intent + "}"; |
| 385 | } |
| 386 | } |
| 387 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 388 | static final class BindServiceData { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 389 | IBinder token; |
| 390 | Intent intent; |
| 391 | boolean rebind; |
| 392 | public String toString() { |
| 393 | return "BindServiceData{token=" + token + " intent=" + intent + "}"; |
| 394 | } |
| 395 | } |
| 396 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 397 | static final class ServiceArgsData { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 398 | IBinder token; |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 399 | boolean taskRemoved; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 400 | int startId; |
Dianne Hackborn | f6f9f2d | 2009-08-21 16:26:03 -0700 | [diff] [blame] | 401 | int flags; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 402 | Intent args; |
| 403 | public String toString() { |
| 404 | return "ServiceArgsData{token=" + token + " startId=" + startId |
| 405 | + " args=" + args + "}"; |
| 406 | } |
| 407 | } |
| 408 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 409 | static final class AppBindData { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 410 | LoadedApk info; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 411 | String processName; |
| 412 | ApplicationInfo appInfo; |
| 413 | List<ProviderInfo> providers; |
| 414 | ComponentName instrumentationName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 415 | Bundle instrumentationArgs; |
| 416 | IInstrumentationWatcher instrumentationWatcher; |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 417 | IUiAutomationConnection instrumentationUiAutomationConnection; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 418 | int debugMode; |
Siva Velusamy | 92a8b22 | 2012-03-09 16:24:04 -0800 | [diff] [blame] | 419 | boolean enableOpenGlTrace; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 420 | boolean restrictedBackupMode; |
Dianne Hackborn | 5d927c2 | 2011-09-02 12:22:18 -0700 | [diff] [blame] | 421 | boolean persistent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 422 | Configuration config; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 423 | CompatibilityInfo compatInfo; |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 424 | |
| 425 | /** Initial values for {@link Profiler}. */ |
| 426 | String initProfileFile; |
| 427 | ParcelFileDescriptor initProfileFd; |
| 428 | boolean initAutoStopProfiler; |
| 429 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 430 | public String toString() { |
| 431 | return "AppBindData{appInfo=" + appInfo + "}"; |
| 432 | } |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | static final class Profiler { |
| 436 | String profileFile; |
| 437 | ParcelFileDescriptor profileFd; |
| 438 | boolean autoStopProfiler; |
| 439 | boolean profiling; |
| 440 | boolean handlingProfiling; |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 441 | public void setProfiler(String file, ParcelFileDescriptor fd) { |
| 442 | if (profiling) { |
| 443 | if (fd != null) { |
| 444 | try { |
| 445 | fd.close(); |
| 446 | } catch (IOException e) { |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 447 | // Ignore |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 448 | } |
| 449 | } |
| 450 | return; |
| 451 | } |
| 452 | if (profileFd != null) { |
| 453 | try { |
| 454 | profileFd.close(); |
| 455 | } catch (IOException e) { |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 456 | // Ignore |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 457 | } |
| 458 | } |
| 459 | profileFile = file; |
| 460 | profileFd = fd; |
| 461 | } |
| 462 | public void startProfiling() { |
| 463 | if (profileFd == null || profiling) { |
| 464 | return; |
| 465 | } |
| 466 | try { |
| 467 | Debug.startMethodTracing(profileFile, profileFd.getFileDescriptor(), |
| 468 | 8 * 1024 * 1024, 0); |
| 469 | profiling = true; |
| 470 | } catch (RuntimeException e) { |
| 471 | Slog.w(TAG, "Profiling failed on path " + profileFile); |
| 472 | try { |
| 473 | profileFd.close(); |
| 474 | profileFd = null; |
| 475 | } catch (IOException e2) { |
| 476 | Slog.w(TAG, "Failure closing profile fd", e2); |
| 477 | } |
| 478 | } |
| 479 | } |
| 480 | public void stopProfiling() { |
| 481 | if (profiling) { |
| 482 | profiling = false; |
| 483 | Debug.stopMethodTracing(); |
| 484 | if (profileFd != null) { |
| 485 | try { |
| 486 | profileFd.close(); |
| 487 | } catch (IOException e) { |
| 488 | } |
| 489 | } |
| 490 | profileFd = null; |
| 491 | profileFile = null; |
| 492 | } |
| 493 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 494 | } |
| 495 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 496 | static final class DumpComponentInfo { |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 497 | ParcelFileDescriptor fd; |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 498 | IBinder token; |
Dianne Hackborn | 30d7189 | 2010-12-11 10:37:55 -0800 | [diff] [blame] | 499 | String prefix; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 500 | String[] args; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 501 | } |
| 502 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 503 | static final class ResultData { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 504 | IBinder token; |
| 505 | List<ResultInfo> results; |
| 506 | public String toString() { |
| 507 | return "ResultData{token=" + token + " results" + results + "}"; |
| 508 | } |
| 509 | } |
| 510 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 511 | static final class ContextCleanupInfo { |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 512 | ContextImpl context; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 513 | String what; |
| 514 | String who; |
| 515 | } |
| 516 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 517 | static final class ProfilerControlData { |
Dianne Hackborn | 9c8dd55 | 2009-06-23 19:22:52 -0700 | [diff] [blame] | 518 | String path; |
| 519 | ParcelFileDescriptor fd; |
| 520 | } |
| 521 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 522 | static final class DumpHeapData { |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 523 | String path; |
| 524 | ParcelFileDescriptor fd; |
| 525 | } |
| 526 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 527 | static final class UpdateCompatibilityData { |
| 528 | String pkg; |
| 529 | CompatibilityInfo info; |
| 530 | } |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 531 | |
| 532 | static final class RequestActivityExtras { |
| 533 | IBinder activityToken; |
| 534 | IBinder requestToken; |
| 535 | int requestType; |
| 536 | } |
Anwar Ghuloum | 3a8ce1b | 2013-04-26 16:18:28 -0700 | [diff] [blame] | 537 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 538 | private native void dumpGraphicsInfo(FileDescriptor fd); |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 539 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 540 | private class ApplicationThread extends ApplicationThreadNative { |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 541 | private static final String HEAP_COLUMN = "%13s %8s %8s %8s %8s %8s %8s %8s %8s %8s"; |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 542 | private static final String ONE_COUNT_COLUMN = "%21s %8d"; |
| 543 | private static final String TWO_COUNT_COLUMNS = "%21s %8d %21s %8d"; |
Vasu Nori | 3c7131f | 2010-09-21 14:36:57 -0700 | [diff] [blame] | 544 | private static final String DB_INFO_FORMAT = " %8s %8s %14s %14s %s"; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 545 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 546 | // Formatting for checkin service - update version if row format changes |
Dianne Hackborn | cfc837f | 2013-06-27 18:32:07 -0700 | [diff] [blame] | 547 | private static final int ACTIVITY_THREAD_CHECKIN_VERSION = 3; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 548 | |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 549 | private int mLastProcessState = -1; |
| 550 | |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 551 | private void updatePendingConfiguration(Configuration config) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 552 | synchronized (mResourcesManager) { |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 553 | if (mPendingConfiguration == null || |
| 554 | mPendingConfiguration.isOtherSeqNewer(config)) { |
| 555 | mPendingConfiguration = config; |
| 556 | } |
| 557 | } |
| 558 | } |
| 559 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 560 | public final void schedulePauseActivity(IBinder token, boolean finished, |
| 561 | boolean userLeaving, int configChanges) { |
| 562 | queueOrSendMessage( |
| 563 | finished ? H.PAUSE_ACTIVITY_FINISHING : H.PAUSE_ACTIVITY, |
| 564 | token, |
| 565 | (userLeaving ? 1 : 0), |
| 566 | configChanges); |
| 567 | } |
| 568 | |
| 569 | public final void scheduleStopActivity(IBinder token, boolean showWindow, |
| 570 | int configChanges) { |
| 571 | queueOrSendMessage( |
| 572 | showWindow ? H.STOP_ACTIVITY_SHOW : H.STOP_ACTIVITY_HIDE, |
| 573 | token, 0, configChanges); |
| 574 | } |
| 575 | |
| 576 | public final void scheduleWindowVisibility(IBinder token, boolean showWindow) { |
| 577 | queueOrSendMessage( |
| 578 | showWindow ? H.SHOW_WINDOW : H.HIDE_WINDOW, |
| 579 | token); |
| 580 | } |
| 581 | |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 582 | public final void scheduleSleeping(IBinder token, boolean sleeping) { |
| 583 | queueOrSendMessage(H.SLEEPING, token, sleeping ? 1 : 0); |
| 584 | } |
| 585 | |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 586 | public final void scheduleResumeActivity(IBinder token, int processState, |
| 587 | boolean isForward) { |
| 588 | updateProcessState(processState, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 589 | queueOrSendMessage(H.RESUME_ACTIVITY, token, isForward ? 1 : 0); |
| 590 | } |
| 591 | |
| 592 | public final void scheduleSendResult(IBinder token, List<ResultInfo> results) { |
| 593 | ResultData res = new ResultData(); |
| 594 | res.token = token; |
| 595 | res.results = results; |
| 596 | queueOrSendMessage(H.SEND_RESULT, res); |
| 597 | } |
| 598 | |
| 599 | // we use token to identify this activity without having to send the |
| 600 | // activity itself back to the activity manager. (matters more with ipc) |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 601 | public final void scheduleLaunchActivity(Intent intent, IBinder token, int ident, |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 602 | ActivityInfo info, Configuration curConfig, CompatibilityInfo compatInfo, |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 603 | int procState, Bundle state, List<ResultInfo> pendingResults, |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 604 | List<Intent> pendingNewIntents, boolean notResumed, boolean isForward, |
| 605 | String profileName, ParcelFileDescriptor profileFd, boolean autoStopProfiler) { |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 606 | |
| 607 | updateProcessState(procState, false); |
| 608 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 609 | ActivityClientRecord r = new ActivityClientRecord(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 610 | |
| 611 | r.token = token; |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 612 | r.ident = ident; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 613 | r.intent = intent; |
| 614 | r.activityInfo = info; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 615 | r.compatInfo = compatInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 616 | r.state = state; |
| 617 | |
| 618 | r.pendingResults = pendingResults; |
| 619 | r.pendingIntents = pendingNewIntents; |
| 620 | |
| 621 | r.startsNotResumed = notResumed; |
| 622 | r.isForward = isForward; |
| 623 | |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 624 | r.profileFile = profileName; |
| 625 | r.profileFd = profileFd; |
| 626 | r.autoStopProfiler = autoStopProfiler; |
| 627 | |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 628 | updatePendingConfiguration(curConfig); |
| 629 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 630 | queueOrSendMessage(H.LAUNCH_ACTIVITY, r); |
| 631 | } |
| 632 | |
| 633 | public final void scheduleRelaunchActivity(IBinder token, |
| 634 | List<ResultInfo> pendingResults, List<Intent> pendingNewIntents, |
Dianne Hackborn | 871ecdc | 2009-12-11 15:24:33 -0800 | [diff] [blame] | 635 | int configChanges, boolean notResumed, Configuration config) { |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 636 | requestRelaunchActivity(token, pendingResults, pendingNewIntents, |
| 637 | configChanges, notResumed, config, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 638 | } |
| 639 | |
| 640 | public final void scheduleNewIntent(List<Intent> intents, IBinder token) { |
| 641 | NewIntentData data = new NewIntentData(); |
| 642 | data.intents = intents; |
| 643 | data.token = token; |
| 644 | |
| 645 | queueOrSendMessage(H.NEW_INTENT, data); |
| 646 | } |
| 647 | |
| 648 | public final void scheduleDestroyActivity(IBinder token, boolean finishing, |
| 649 | int configChanges) { |
| 650 | queueOrSendMessage(H.DESTROY_ACTIVITY, token, finishing ? 1 : 0, |
| 651 | configChanges); |
| 652 | } |
| 653 | |
| 654 | public final void scheduleReceiver(Intent intent, ActivityInfo info, |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 655 | CompatibilityInfo compatInfo, int resultCode, String data, Bundle extras, |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 656 | boolean sync, int sendingUser, int processState) { |
| 657 | updateProcessState(processState, false); |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 658 | ReceiverData r = new ReceiverData(intent, resultCode, data, extras, |
Dianne Hackborn | 20e8098 | 2012-08-31 19:00:44 -0700 | [diff] [blame] | 659 | sync, false, mAppThread.asBinder(), sendingUser); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 660 | r.info = info; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 661 | r.compatInfo = compatInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 662 | queueOrSendMessage(H.RECEIVER, r); |
| 663 | } |
| 664 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 665 | public final void scheduleCreateBackupAgent(ApplicationInfo app, |
| 666 | CompatibilityInfo compatInfo, int backupMode) { |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 667 | CreateBackupAgentData d = new CreateBackupAgentData(); |
| 668 | d.appInfo = app; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 669 | d.compatInfo = compatInfo; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 670 | d.backupMode = backupMode; |
| 671 | |
| 672 | queueOrSendMessage(H.CREATE_BACKUP_AGENT, d); |
| 673 | } |
| 674 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 675 | public final void scheduleDestroyBackupAgent(ApplicationInfo app, |
| 676 | CompatibilityInfo compatInfo) { |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 677 | CreateBackupAgentData d = new CreateBackupAgentData(); |
| 678 | d.appInfo = app; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 679 | d.compatInfo = compatInfo; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 680 | |
| 681 | queueOrSendMessage(H.DESTROY_BACKUP_AGENT, d); |
| 682 | } |
| 683 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 684 | public final void scheduleCreateService(IBinder token, |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 685 | ServiceInfo info, CompatibilityInfo compatInfo, int processState) { |
| 686 | updateProcessState(processState, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 687 | CreateServiceData s = new CreateServiceData(); |
| 688 | s.token = token; |
| 689 | s.info = info; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 690 | s.compatInfo = compatInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 691 | |
| 692 | queueOrSendMessage(H.CREATE_SERVICE, s); |
| 693 | } |
| 694 | |
| 695 | public final void scheduleBindService(IBinder token, Intent intent, |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 696 | boolean rebind, int processState) { |
| 697 | updateProcessState(processState, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 698 | BindServiceData s = new BindServiceData(); |
| 699 | s.token = token; |
| 700 | s.intent = intent; |
| 701 | s.rebind = rebind; |
| 702 | |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 703 | if (DEBUG_SERVICE) |
| 704 | Slog.v(TAG, "scheduleBindService token=" + token + " intent=" + intent + " uid=" |
| 705 | + Binder.getCallingUid() + " pid=" + Binder.getCallingPid()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 706 | queueOrSendMessage(H.BIND_SERVICE, s); |
| 707 | } |
| 708 | |
| 709 | public final void scheduleUnbindService(IBinder token, Intent intent) { |
| 710 | BindServiceData s = new BindServiceData(); |
| 711 | s.token = token; |
| 712 | s.intent = intent; |
| 713 | |
| 714 | queueOrSendMessage(H.UNBIND_SERVICE, s); |
| 715 | } |
| 716 | |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 717 | public final void scheduleServiceArgs(IBinder token, boolean taskRemoved, int startId, |
Dianne Hackborn | f6f9f2d | 2009-08-21 16:26:03 -0700 | [diff] [blame] | 718 | int flags ,Intent args) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 719 | ServiceArgsData s = new ServiceArgsData(); |
| 720 | s.token = token; |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 721 | s.taskRemoved = taskRemoved; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 722 | s.startId = startId; |
Dianne Hackborn | f6f9f2d | 2009-08-21 16:26:03 -0700 | [diff] [blame] | 723 | s.flags = flags; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 724 | s.args = args; |
| 725 | |
| 726 | queueOrSendMessage(H.SERVICE_ARGS, s); |
| 727 | } |
| 728 | |
| 729 | public final void scheduleStopService(IBinder token) { |
| 730 | queueOrSendMessage(H.STOP_SERVICE, token); |
| 731 | } |
| 732 | |
| 733 | public final void bindApplication(String processName, |
| 734 | ApplicationInfo appInfo, List<ProviderInfo> providers, |
| 735 | ComponentName instrumentationName, String profileFile, |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 736 | ParcelFileDescriptor profileFd, boolean autoStopProfiler, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 737 | Bundle instrumentationArgs, IInstrumentationWatcher instrumentationWatcher, |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 738 | IUiAutomationConnection instrumentationUiConnection, int debugMode, |
| 739 | boolean enableOpenGlTrace, boolean isRestrictedBackupMode, boolean persistent, |
| 740 | Configuration config, CompatibilityInfo compatInfo, Map<String, IBinder> services, |
| 741 | Bundle coreSettings) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 742 | |
| 743 | if (services != null) { |
| 744 | // Setup the service cache in the ServiceManager |
| 745 | ServiceManager.initServiceCache(services); |
| 746 | } |
| 747 | |
Svetoslav Ganov | 9aa597e | 2011-03-03 18:17:41 -0800 | [diff] [blame] | 748 | setCoreSettings(coreSettings); |
| 749 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 750 | AppBindData data = new AppBindData(); |
| 751 | data.processName = processName; |
| 752 | data.appInfo = appInfo; |
| 753 | data.providers = providers; |
| 754 | data.instrumentationName = instrumentationName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 755 | data.instrumentationArgs = instrumentationArgs; |
| 756 | data.instrumentationWatcher = instrumentationWatcher; |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 757 | data.instrumentationUiAutomationConnection = instrumentationUiConnection; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 758 | data.debugMode = debugMode; |
Siva Velusamy | 92a8b22 | 2012-03-09 16:24:04 -0800 | [diff] [blame] | 759 | data.enableOpenGlTrace = enableOpenGlTrace; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 760 | data.restrictedBackupMode = isRestrictedBackupMode; |
Dianne Hackborn | 5d927c2 | 2011-09-02 12:22:18 -0700 | [diff] [blame] | 761 | data.persistent = persistent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 762 | data.config = config; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 763 | data.compatInfo = compatInfo; |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 764 | data.initProfileFile = profileFile; |
| 765 | data.initProfileFd = profileFd; |
| 766 | data.initAutoStopProfiler = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 767 | queueOrSendMessage(H.BIND_APPLICATION, data); |
| 768 | } |
| 769 | |
| 770 | public final void scheduleExit() { |
| 771 | queueOrSendMessage(H.EXIT_APPLICATION, null); |
| 772 | } |
| 773 | |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 774 | public final void scheduleSuicide() { |
| 775 | queueOrSendMessage(H.SUICIDE, null); |
| 776 | } |
| 777 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 778 | public void requestThumbnail(IBinder token) { |
| 779 | queueOrSendMessage(H.REQUEST_THUMBNAIL, token); |
| 780 | } |
| 781 | |
| 782 | public void scheduleConfigurationChanged(Configuration config) { |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 783 | updatePendingConfiguration(config); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 784 | queueOrSendMessage(H.CONFIGURATION_CHANGED, config); |
| 785 | } |
| 786 | |
| 787 | public void updateTimeZone() { |
| 788 | TimeZone.setDefault(null); |
| 789 | } |
| 790 | |
Robert Greenwalt | 03595d0 | 2010-11-02 14:08:23 -0700 | [diff] [blame] | 791 | public void clearDnsCache() { |
| 792 | // a non-standard API to get this to libcore |
| 793 | InetAddress.clearDnsCache(); |
| 794 | } |
| 795 | |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 796 | public void setHttpProxy(String host, String port, String exclList) { |
| 797 | Proxy.setHttpProxySystemProperty(host, port, exclList); |
| 798 | } |
| 799 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 800 | public void processInBackground() { |
| 801 | mH.removeMessages(H.GC_WHEN_IDLE); |
| 802 | mH.sendMessage(mH.obtainMessage(H.GC_WHEN_IDLE)); |
| 803 | } |
| 804 | |
| 805 | public void dumpService(FileDescriptor fd, IBinder servicetoken, String[] args) { |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 806 | DumpComponentInfo data = new DumpComponentInfo(); |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 807 | try { |
| 808 | data.fd = ParcelFileDescriptor.dup(fd); |
| 809 | data.token = servicetoken; |
| 810 | data.args = args; |
| 811 | queueOrSendMessage(H.DUMP_SERVICE, data); |
| 812 | } catch (IOException e) { |
| 813 | Slog.w(TAG, "dumpService failed", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 814 | } |
| 815 | } |
| 816 | |
| 817 | // This function exists to make sure all receiver dispatching is |
| 818 | // correctly ordered, since these are one-way calls and the binder driver |
| 819 | // applies transaction ordering per object for such calls. |
| 820 | public void scheduleRegisteredReceiver(IIntentReceiver receiver, Intent intent, |
Dianne Hackborn | 68d881c | 2009-10-05 13:58:17 -0700 | [diff] [blame] | 821 | int resultCode, String dataStr, Bundle extras, boolean ordered, |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 822 | boolean sticky, int sendingUser, int processState) throws RemoteException { |
| 823 | updateProcessState(processState, false); |
Dianne Hackborn | 20e8098 | 2012-08-31 19:00:44 -0700 | [diff] [blame] | 824 | receiver.performReceive(intent, resultCode, dataStr, extras, ordered, |
| 825 | sticky, sendingUser); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 826 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 827 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 828 | public void scheduleLowMemory() { |
| 829 | queueOrSendMessage(H.LOW_MEMORY, null); |
| 830 | } |
| 831 | |
| 832 | public void scheduleActivityConfigurationChanged(IBinder token) { |
| 833 | queueOrSendMessage(H.ACTIVITY_CONFIGURATION_CHANGED, token); |
| 834 | } |
| 835 | |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 836 | public void profilerControl(boolean start, String path, ParcelFileDescriptor fd, |
| 837 | int profileType) { |
Dianne Hackborn | 9c8dd55 | 2009-06-23 19:22:52 -0700 | [diff] [blame] | 838 | ProfilerControlData pcd = new ProfilerControlData(); |
| 839 | pcd.path = path; |
| 840 | pcd.fd = fd; |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 841 | queueOrSendMessage(H.PROFILER_CONTROL, pcd, start ? 1 : 0, profileType); |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 842 | } |
| 843 | |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 844 | public void dumpHeap(boolean managed, String path, ParcelFileDescriptor fd) { |
| 845 | DumpHeapData dhd = new DumpHeapData(); |
| 846 | dhd.path = path; |
| 847 | dhd.fd = fd; |
| 848 | queueOrSendMessage(H.DUMP_HEAP, dhd, managed ? 1 : 0); |
| 849 | } |
| 850 | |
Dianne Hackborn | 06de2ea | 2009-05-21 12:56:43 -0700 | [diff] [blame] | 851 | public void setSchedulingGroup(int group) { |
| 852 | // Note: do this immediately, since going into the foreground |
| 853 | // should happen regardless of what pending work we have to do |
| 854 | // and the activity manager will wait for us to report back that |
| 855 | // we are done before sending us to the background. |
| 856 | try { |
| 857 | Process.setProcessGroup(Process.myPid(), group); |
| 858 | } catch (Exception e) { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 859 | Slog.w(TAG, "Failed setting process group to " + group, e); |
Dianne Hackborn | 06de2ea | 2009-05-21 12:56:43 -0700 | [diff] [blame] | 860 | } |
| 861 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 862 | |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 863 | public void getMemoryInfo(Debug.MemoryInfo outInfo) { |
| 864 | Debug.getMemoryInfo(outInfo); |
| 865 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 866 | |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 867 | public void dispatchPackageBroadcast(int cmd, String[] packages) { |
| 868 | queueOrSendMessage(H.DISPATCH_PACKAGE_BROADCAST, packages, cmd); |
| 869 | } |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 870 | |
| 871 | public void scheduleCrash(String msg) { |
| 872 | queueOrSendMessage(H.SCHEDULE_CRASH, msg); |
| 873 | } |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 874 | |
Dianne Hackborn | 30d7189 | 2010-12-11 10:37:55 -0800 | [diff] [blame] | 875 | public void dumpActivity(FileDescriptor fd, IBinder activitytoken, |
| 876 | String prefix, String[] args) { |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 877 | DumpComponentInfo data = new DumpComponentInfo(); |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 878 | try { |
| 879 | data.fd = ParcelFileDescriptor.dup(fd); |
| 880 | data.token = activitytoken; |
| 881 | data.prefix = prefix; |
| 882 | data.args = args; |
| 883 | queueOrSendMessage(H.DUMP_ACTIVITY, data); |
| 884 | } catch (IOException e) { |
| 885 | Slog.w(TAG, "dumpActivity failed", e); |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 886 | } |
| 887 | } |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 888 | |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 889 | public void dumpProvider(FileDescriptor fd, IBinder providertoken, |
| 890 | String[] args) { |
| 891 | DumpComponentInfo data = new DumpComponentInfo(); |
| 892 | try { |
| 893 | data.fd = ParcelFileDescriptor.dup(fd); |
| 894 | data.token = providertoken; |
| 895 | data.args = args; |
| 896 | queueOrSendMessage(H.DUMP_PROVIDER, data); |
| 897 | } catch (IOException e) { |
| 898 | Slog.w(TAG, "dumpProvider failed", e); |
| 899 | } |
| 900 | } |
| 901 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 902 | @Override |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 903 | public Debug.MemoryInfo dumpMemInfo(FileDescriptor fd, boolean checkin, |
Dianne Hackborn | 64770d1 | 2013-05-23 17:51:19 -0700 | [diff] [blame] | 904 | boolean dumpInfo, boolean dumpDalvik, String[] args) { |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 905 | FileOutputStream fout = new FileOutputStream(fd); |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 906 | PrintWriter pw = new FastPrintWriter(fout); |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 907 | try { |
Dianne Hackborn | 64770d1 | 2013-05-23 17:51:19 -0700 | [diff] [blame] | 908 | return dumpMemInfo(pw, checkin, dumpInfo, dumpDalvik); |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 909 | } finally { |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 910 | pw.flush(); |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 911 | } |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 912 | } |
| 913 | |
Dianne Hackborn | 64770d1 | 2013-05-23 17:51:19 -0700 | [diff] [blame] | 914 | private Debug.MemoryInfo dumpMemInfo(PrintWriter pw, boolean checkin, boolean dumpInfo, |
| 915 | boolean dumpDalvik) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 916 | long nativeMax = Debug.getNativeHeapSize() / 1024; |
| 917 | long nativeAllocated = Debug.getNativeHeapAllocatedSize() / 1024; |
| 918 | long nativeFree = Debug.getNativeHeapFreeSize() / 1024; |
| 919 | |
| 920 | Debug.MemoryInfo memInfo = new Debug.MemoryInfo(); |
| 921 | Debug.getMemoryInfo(memInfo); |
| 922 | |
Dianne Hackborn | 64770d1 | 2013-05-23 17:51:19 -0700 | [diff] [blame] | 923 | if (!dumpInfo) { |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 924 | return memInfo; |
| 925 | } |
| 926 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 927 | Runtime runtime = Runtime.getRuntime(); |
| 928 | |
| 929 | long dalvikMax = runtime.totalMemory() / 1024; |
| 930 | long dalvikFree = runtime.freeMemory() / 1024; |
| 931 | long dalvikAllocated = dalvikMax - dalvikFree; |
| 932 | long viewInstanceCount = ViewDebug.getViewInstanceCount(); |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 933 | long viewRootInstanceCount = ViewDebug.getViewRootImplCount(); |
Brian Carlstrom | c21550a | 2010-10-05 21:34:06 -0700 | [diff] [blame] | 934 | long appContextInstanceCount = Debug.countInstancesOfClass(ContextImpl.class); |
| 935 | long activityInstanceCount = Debug.countInstancesOfClass(Activity.class); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 936 | int globalAssetCount = AssetManager.getGlobalAssetCount(); |
| 937 | int globalAssetManagerCount = AssetManager.getGlobalAssetManagerCount(); |
| 938 | int binderLocalObjectCount = Debug.getBinderLocalObjectCount(); |
| 939 | int binderProxyObjectCount = Debug.getBinderProxyObjectCount(); |
| 940 | int binderDeathObjectCount = Debug.getBinderDeathObjectCount(); |
Brian Carlstrom | c9d5b31 | 2010-10-05 22:23:41 -0700 | [diff] [blame] | 941 | long openSslSocketCount = Debug.countInstancesOfClass(OpenSSLSocketImpl.class); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 942 | SQLiteDebug.PagerStats stats = SQLiteDebug.getDatabaseInfo(); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 943 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 944 | // For checkin, we print one long comma-separated list of values |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 945 | if (checkin) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 946 | // NOTE: if you change anything significant below, also consider changing |
| 947 | // ACTIVITY_THREAD_CHECKIN_VERSION. |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 948 | String processName = (mBoundApplication != null) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 949 | ? mBoundApplication.processName : "unknown"; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 950 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 951 | // Header |
| 952 | pw.print(ACTIVITY_THREAD_CHECKIN_VERSION); pw.print(','); |
| 953 | pw.print(Process.myPid()); pw.print(','); |
| 954 | pw.print(processName); pw.print(','); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 955 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 956 | // Heap info - max |
| 957 | pw.print(nativeMax); pw.print(','); |
| 958 | pw.print(dalvikMax); pw.print(','); |
| 959 | pw.print("N/A,"); |
| 960 | pw.print(nativeMax + dalvikMax); pw.print(','); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 961 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 962 | // Heap info - allocated |
| 963 | pw.print(nativeAllocated); pw.print(','); |
| 964 | pw.print(dalvikAllocated); pw.print(','); |
| 965 | pw.print("N/A,"); |
| 966 | pw.print(nativeAllocated + dalvikAllocated); pw.print(','); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 967 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 968 | // Heap info - free |
| 969 | pw.print(nativeFree); pw.print(','); |
| 970 | pw.print(dalvikFree); pw.print(','); |
| 971 | pw.print("N/A,"); |
| 972 | pw.print(nativeFree + dalvikFree); pw.print(','); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 973 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 974 | // Heap info - proportional set size |
| 975 | pw.print(memInfo.nativePss); pw.print(','); |
| 976 | pw.print(memInfo.dalvikPss); pw.print(','); |
| 977 | pw.print(memInfo.otherPss); pw.print(','); |
Dianne Hackborn | cfc837f | 2013-06-27 18:32:07 -0700 | [diff] [blame] | 978 | pw.print(memInfo.getTotalPss()); pw.print(','); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 979 | |
Dianne Hackborn | cfc837f | 2013-06-27 18:32:07 -0700 | [diff] [blame] | 980 | // Heap info - swappable set size |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 981 | pw.print(memInfo.nativeSwappablePss); pw.print(','); |
| 982 | pw.print(memInfo.dalvikSwappablePss); pw.print(','); |
| 983 | pw.print(memInfo.otherSwappablePss); pw.print(','); |
Dianne Hackborn | cfc837f | 2013-06-27 18:32:07 -0700 | [diff] [blame] | 984 | pw.print(memInfo.getTotalSwappablePss()); pw.print(','); |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 985 | |
Anwar Ghuloum | 3a8ce1b | 2013-04-26 16:18:28 -0700 | [diff] [blame] | 986 | // Heap info - shared dirty |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 987 | pw.print(memInfo.nativeSharedDirty); pw.print(','); |
| 988 | pw.print(memInfo.dalvikSharedDirty); pw.print(','); |
| 989 | pw.print(memInfo.otherSharedDirty); pw.print(','); |
Dianne Hackborn | cfc837f | 2013-06-27 18:32:07 -0700 | [diff] [blame] | 990 | pw.print(memInfo.getTotalSharedDirty()); pw.print(','); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 991 | |
Anwar Ghuloum | 3a8ce1b | 2013-04-26 16:18:28 -0700 | [diff] [blame] | 992 | // Heap info - shared clean |
| 993 | pw.print(memInfo.nativeSharedClean); pw.print(','); |
| 994 | pw.print(memInfo.dalvikSharedClean); pw.print(','); |
| 995 | pw.print(memInfo.otherSharedClean); pw.print(','); |
Dianne Hackborn | cfc837f | 2013-06-27 18:32:07 -0700 | [diff] [blame] | 996 | pw.print(memInfo.getTotalSharedClean()); pw.print(','); |
Anwar Ghuloum | 3a8ce1b | 2013-04-26 16:18:28 -0700 | [diff] [blame] | 997 | |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 998 | // Heap info - private Dirty |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 999 | pw.print(memInfo.nativePrivateDirty); pw.print(','); |
| 1000 | pw.print(memInfo.dalvikPrivateDirty); pw.print(','); |
| 1001 | pw.print(memInfo.otherPrivateDirty); pw.print(','); |
Dianne Hackborn | cfc837f | 2013-06-27 18:32:07 -0700 | [diff] [blame] | 1002 | pw.print(memInfo.getTotalPrivateDirty()); pw.print(','); |
Anwar Ghuloum | 3a8ce1b | 2013-04-26 16:18:28 -0700 | [diff] [blame] | 1003 | |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 1004 | // Heap info - private Clean |
| 1005 | pw.print(memInfo.nativePrivateClean); pw.print(','); |
| 1006 | pw.print(memInfo.dalvikPrivateClean); pw.print(','); |
| 1007 | pw.print(memInfo.otherPrivateClean); pw.print(','); |
Dianne Hackborn | cfc837f | 2013-06-27 18:32:07 -0700 | [diff] [blame] | 1008 | pw.print(memInfo.getTotalPrivateClean()); pw.print(','); |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 1009 | |
Dianne Hackborn | cfc837f | 2013-06-27 18:32:07 -0700 | [diff] [blame] | 1010 | // Heap info - other areas |
| 1011 | for (int i=0; i<Debug.MemoryInfo.NUM_OTHER_STATS; i++) { |
| 1012 | pw.print(Debug.MemoryInfo.getOtherLabel(i)); pw.print(','); |
| 1013 | pw.print(memInfo.getOtherPss(i)); pw.print(','); |
| 1014 | pw.print(memInfo.getOtherSwappablePss(i)); pw.print(','); |
| 1015 | pw.print(memInfo.getOtherSharedDirty(i)); pw.print(','); |
| 1016 | pw.print(memInfo.getOtherSharedClean(i)); pw.print(','); |
| 1017 | pw.print(memInfo.getOtherPrivateDirty(i)); pw.print(','); |
| 1018 | pw.print(memInfo.getOtherPrivateClean(i)); pw.print(','); |
| 1019 | } |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 1020 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1021 | // Object counts |
| 1022 | pw.print(viewInstanceCount); pw.print(','); |
| 1023 | pw.print(viewRootInstanceCount); pw.print(','); |
| 1024 | pw.print(appContextInstanceCount); pw.print(','); |
| 1025 | pw.print(activityInstanceCount); pw.print(','); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1026 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1027 | pw.print(globalAssetCount); pw.print(','); |
| 1028 | pw.print(globalAssetManagerCount); pw.print(','); |
| 1029 | pw.print(binderLocalObjectCount); pw.print(','); |
| 1030 | pw.print(binderProxyObjectCount); pw.print(','); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1031 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1032 | pw.print(binderDeathObjectCount); pw.print(','); |
| 1033 | pw.print(openSslSocketCount); pw.print(','); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1034 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1035 | // SQL |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1036 | pw.print(stats.memoryUsed / 1024); pw.print(','); |
Jeff Brown | 2a293b6 | 2012-01-19 14:02:22 -0800 | [diff] [blame] | 1037 | pw.print(stats.memoryUsed / 1024); pw.print(','); |
| 1038 | pw.print(stats.pageCacheOverflow / 1024); pw.print(','); |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 1039 | pw.print(stats.largestMemAlloc / 1024); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1040 | for (int i = 0; i < stats.dbStats.size(); i++) { |
| 1041 | DbStats dbStats = stats.dbStats.get(i); |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 1042 | pw.print(','); pw.print(dbStats.dbName); |
| 1043 | pw.print(','); pw.print(dbStats.pageSize); |
| 1044 | pw.print(','); pw.print(dbStats.dbSize); |
| 1045 | pw.print(','); pw.print(dbStats.lookaside); |
| 1046 | pw.print(','); pw.print(dbStats.cache); |
| 1047 | pw.print(','); pw.print(dbStats.cache); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1048 | } |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 1049 | pw.println(); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1050 | |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 1051 | return memInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1052 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1053 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1054 | // otherwise, show human-readable format |
Dianne Hackborn | 64770d1 | 2013-05-23 17:51:19 -0700 | [diff] [blame] | 1055 | printRow(pw, HEAP_COLUMN, "", "Pss", "Pss","Shared", "Private", "Shared", "Private", |
| 1056 | "Heap", "Heap", "Heap"); |
| 1057 | printRow(pw, HEAP_COLUMN, "", "Total", "Clean", "Dirty", "Dirty", "Clean", "Clean", |
| 1058 | "Size", "Alloc", "Free"); |
| 1059 | printRow(pw, HEAP_COLUMN, "", "------", "------", "------", "------", "------", |
| 1060 | "------", "------", "------", "------"); |
| 1061 | printRow(pw, HEAP_COLUMN, "Native Heap", memInfo.nativePss, memInfo.nativeSwappablePss, |
| 1062 | memInfo.nativeSharedDirty, |
| 1063 | memInfo.nativePrivateDirty, memInfo.nativeSharedClean, |
| 1064 | memInfo.nativePrivateClean, nativeMax, nativeAllocated, nativeFree); |
| 1065 | printRow(pw, HEAP_COLUMN, "Dalvik Heap", memInfo.dalvikPss, memInfo.dalvikSwappablePss, |
| 1066 | memInfo.dalvikSharedDirty, |
| 1067 | memInfo.dalvikPrivateDirty, memInfo.dalvikSharedClean, |
| 1068 | memInfo.dalvikPrivateClean, dalvikMax, dalvikAllocated, dalvikFree); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1069 | |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 1070 | int otherPss = memInfo.otherPss; |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 1071 | int otherSwappablePss = memInfo.otherSwappablePss; |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 1072 | int otherSharedDirty = memInfo.otherSharedDirty; |
| 1073 | int otherPrivateDirty = memInfo.otherPrivateDirty; |
Anwar Ghuloum | 3a8ce1b | 2013-04-26 16:18:28 -0700 | [diff] [blame] | 1074 | int otherSharedClean = memInfo.otherSharedClean; |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 1075 | int otherPrivateClean = memInfo.otherPrivateClean; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1076 | |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 1077 | for (int i=0; i<Debug.MemoryInfo.NUM_OTHER_STATS; i++) { |
Dianne Hackborn | 64770d1 | 2013-05-23 17:51:19 -0700 | [diff] [blame] | 1078 | final int myPss = memInfo.getOtherPss(i); |
| 1079 | final int mySwappablePss = memInfo.getOtherSwappablePss(i); |
| 1080 | final int mySharedDirty = memInfo.getOtherSharedDirty(i); |
| 1081 | final int myPrivateDirty = memInfo.getOtherPrivateDirty(i); |
| 1082 | final int mySharedClean = memInfo.getOtherSharedClean(i); |
| 1083 | final int myPrivateClean = memInfo.getOtherPrivateClean(i); |
| 1084 | if (myPss != 0 || mySharedDirty != 0 || myPrivateDirty != 0 |
| 1085 | || mySharedClean != 0 || myPrivateClean != 0) { |
| 1086 | printRow(pw, HEAP_COLUMN, Debug.MemoryInfo.getOtherLabel(i), |
| 1087 | myPss, mySwappablePss, mySharedDirty, myPrivateDirty, |
| 1088 | mySharedClean, myPrivateClean, "", "", ""); |
| 1089 | otherPss -= myPss; |
| 1090 | otherSwappablePss -= mySwappablePss; |
| 1091 | otherSharedDirty -= mySharedDirty; |
| 1092 | otherPrivateDirty -= myPrivateDirty; |
| 1093 | otherSharedClean -= mySharedClean; |
| 1094 | otherPrivateClean -= myPrivateClean; |
| 1095 | } |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 1096 | } |
| 1097 | |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 1098 | |
| 1099 | |
| 1100 | printRow(pw, HEAP_COLUMN, "Unknown", otherPss, otherSwappablePss, otherSharedDirty, |
| 1101 | otherPrivateDirty, otherSharedClean, otherPrivateClean,"", "", ""); |
Dianne Hackborn | 64770d1 | 2013-05-23 17:51:19 -0700 | [diff] [blame] | 1102 | printRow(pw, HEAP_COLUMN, "TOTAL", memInfo.getTotalPss(), |
| 1103 | memInfo.getTotalSwappablePss(), |
| 1104 | memInfo.getTotalSharedDirty(), memInfo.getTotalPrivateDirty(), |
| 1105 | memInfo.getTotalSharedClean(), memInfo.getTotalPrivateClean(), |
| 1106 | nativeMax+dalvikMax, |
| 1107 | nativeAllocated+dalvikAllocated, nativeFree+dalvikFree); |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 1108 | |
Dianne Hackborn | 64770d1 | 2013-05-23 17:51:19 -0700 | [diff] [blame] | 1109 | if (dumpDalvik) { |
| 1110 | pw.println(" "); |
| 1111 | pw.println(" Dalvik Details"); |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 1112 | |
Dianne Hackborn | 64770d1 | 2013-05-23 17:51:19 -0700 | [diff] [blame] | 1113 | for (int i=Debug.MemoryInfo.NUM_OTHER_STATS; |
| 1114 | i<Debug.MemoryInfo.NUM_OTHER_STATS + Debug.MemoryInfo.NUM_DVK_STATS; i++) { |
| 1115 | final int myPss = memInfo.getOtherPss(i); |
| 1116 | final int mySwappablePss = memInfo.getOtherSwappablePss(i); |
| 1117 | final int mySharedDirty = memInfo.getOtherSharedDirty(i); |
| 1118 | final int myPrivateDirty = memInfo.getOtherPrivateDirty(i); |
| 1119 | final int mySharedClean = memInfo.getOtherSharedClean(i); |
| 1120 | final int myPrivateClean = memInfo.getOtherPrivateClean(i); |
| 1121 | if (myPss != 0 || mySharedDirty != 0 || myPrivateDirty != 0 |
| 1122 | || mySharedClean != 0 || myPrivateClean != 0) { |
| 1123 | printRow(pw, HEAP_COLUMN, Debug.MemoryInfo.getOtherLabel(i), |
| 1124 | myPss, mySwappablePss, mySharedDirty, myPrivateDirty, |
| 1125 | mySharedClean, myPrivateClean, "", "", ""); |
| 1126 | } |
| 1127 | } |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 1128 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1129 | |
| 1130 | pw.println(" "); |
| 1131 | pw.println(" Objects"); |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1132 | printRow(pw, TWO_COUNT_COLUMNS, "Views:", viewInstanceCount, "ViewRootImpl:", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1133 | viewRootInstanceCount); |
| 1134 | |
| 1135 | printRow(pw, TWO_COUNT_COLUMNS, "AppContexts:", appContextInstanceCount, |
| 1136 | "Activities:", activityInstanceCount); |
| 1137 | |
| 1138 | printRow(pw, TWO_COUNT_COLUMNS, "Assets:", globalAssetCount, |
| 1139 | "AssetManagers:", globalAssetManagerCount); |
| 1140 | |
| 1141 | printRow(pw, TWO_COUNT_COLUMNS, "Local Binders:", binderLocalObjectCount, |
| 1142 | "Proxy Binders:", binderProxyObjectCount); |
| 1143 | printRow(pw, ONE_COUNT_COLUMN, "Death Recipients:", binderDeathObjectCount); |
| 1144 | |
| 1145 | printRow(pw, ONE_COUNT_COLUMN, "OpenSSL Sockets:", openSslSocketCount); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1146 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1147 | // SQLite mem info |
| 1148 | pw.println(" "); |
| 1149 | pw.println(" SQL"); |
Jeff Brown | 2a293b6 | 2012-01-19 14:02:22 -0800 | [diff] [blame] | 1150 | printRow(pw, ONE_COUNT_COLUMN, "MEMORY_USED:", stats.memoryUsed / 1024); |
| 1151 | printRow(pw, TWO_COUNT_COLUMNS, "PAGECACHE_OVERFLOW:", |
| 1152 | stats.pageCacheOverflow / 1024, "MALLOC_SIZE:", stats.largestMemAlloc / 1024); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1153 | pw.println(" "); |
| 1154 | int N = stats.dbStats.size(); |
| 1155 | if (N > 0) { |
| 1156 | pw.println(" DATABASES"); |
Vasu Nori | 3c7131f | 2010-09-21 14:36:57 -0700 | [diff] [blame] | 1157 | printRow(pw, " %8s %8s %14s %14s %s", "pgsz", "dbsz", "Lookaside(b)", "cache", |
| 1158 | "Dbname"); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1159 | for (int i = 0; i < N; i++) { |
| 1160 | DbStats dbStats = stats.dbStats.get(i); |
Vasu Nori | 3c7131f | 2010-09-21 14:36:57 -0700 | [diff] [blame] | 1161 | printRow(pw, DB_INFO_FORMAT, |
| 1162 | (dbStats.pageSize > 0) ? String.valueOf(dbStats.pageSize) : " ", |
| 1163 | (dbStats.dbSize > 0) ? String.valueOf(dbStats.dbSize) : " ", |
| 1164 | (dbStats.lookaside > 0) ? String.valueOf(dbStats.lookaside) : " ", |
| 1165 | dbStats.cache, dbStats.dbName); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1166 | } |
| 1167 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1168 | |
Dianne Hackborn | 82e1ee9 | 2009-08-11 18:56:41 -0700 | [diff] [blame] | 1169 | // Asset details. |
| 1170 | String assetAlloc = AssetManager.getAssetAllocations(); |
| 1171 | if (assetAlloc != null) { |
| 1172 | pw.println(" "); |
| 1173 | pw.println(" Asset Allocations"); |
| 1174 | pw.print(assetAlloc); |
| 1175 | } |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 1176 | |
| 1177 | return memInfo; |
| 1178 | } |
| 1179 | |
| 1180 | @Override |
| 1181 | public void dumpGfxInfo(FileDescriptor fd, String[] args) { |
| 1182 | dumpGraphicsInfo(fd); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1183 | WindowManagerGlobal.getInstance().dumpGfxInfo(fd); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1184 | } |
| 1185 | |
Jeff Brown | 6754ba2 | 2011-12-14 20:20:01 -0800 | [diff] [blame] | 1186 | @Override |
| 1187 | public void dumpDbInfo(FileDescriptor fd, String[] args) { |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 1188 | PrintWriter pw = new FastPrintWriter(new FileOutputStream(fd)); |
Jeff Brown | 6754ba2 | 2011-12-14 20:20:01 -0800 | [diff] [blame] | 1189 | PrintWriterPrinter printer = new PrintWriterPrinter(pw); |
| 1190 | SQLiteDebug.dump(printer, args); |
| 1191 | pw.flush(); |
| 1192 | } |
| 1193 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1194 | @Override |
| 1195 | public void unstableProviderDied(IBinder provider) { |
| 1196 | queueOrSendMessage(H.UNSTABLE_PROVIDER_DIED, provider); |
| 1197 | } |
| 1198 | |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 1199 | @Override |
| 1200 | public void requestActivityExtras(IBinder activityToken, IBinder requestToken, |
| 1201 | int requestType) { |
| 1202 | RequestActivityExtras cmd = new RequestActivityExtras(); |
| 1203 | cmd.activityToken = activityToken; |
| 1204 | cmd.requestToken = requestToken; |
| 1205 | cmd.requestType = requestType; |
| 1206 | queueOrSendMessage(H.REQUEST_ACTIVITY_EXTRAS, cmd); |
| 1207 | } |
| 1208 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1209 | private void printRow(PrintWriter pw, String format, Object...objs) { |
| 1210 | pw.println(String.format(format, objs)); |
| 1211 | } |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1212 | |
Svetoslav Ganov | 9aa597e | 2011-03-03 18:17:41 -0800 | [diff] [blame] | 1213 | public void setCoreSettings(Bundle coreSettings) { |
| 1214 | queueOrSendMessage(H.SET_CORE_SETTINGS, coreSettings); |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1215 | } |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1216 | |
| 1217 | public void updatePackageCompatibilityInfo(String pkg, CompatibilityInfo info) { |
| 1218 | UpdateCompatibilityData ucd = new UpdateCompatibilityData(); |
| 1219 | ucd.pkg = pkg; |
| 1220 | ucd.info = info; |
| 1221 | queueOrSendMessage(H.UPDATE_PACKAGE_COMPATIBILITY_INFO, ucd); |
| 1222 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1223 | |
| 1224 | public void scheduleTrimMemory(int level) { |
Dianne Hackborn | f0754f5b | 2011-07-21 16:02:07 -0700 | [diff] [blame] | 1225 | queueOrSendMessage(H.TRIM_MEMORY, null, level); |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1226 | } |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1227 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1228 | public void scheduleTranslucentConversionComplete(IBinder token, boolean drawComplete) { |
| 1229 | queueOrSendMessage(H.TRANSLUCENT_CONVERSION_COMPLETE, token, drawComplete ? 1 : 0); |
| 1230 | } |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 1231 | |
| 1232 | public void setProcessState(int state) { |
| 1233 | updateProcessState(state, true); |
| 1234 | } |
| 1235 | |
| 1236 | public void updateProcessState(int processState, boolean fromIpc) { |
| 1237 | synchronized (this) { |
| 1238 | if (mLastProcessState != processState) { |
| 1239 | mLastProcessState = processState; |
| 1240 | |
| 1241 | // Update Dalvik state here based on ActivityManager.PROCESS_STATE_* constants. |
| 1242 | if (false) { |
| 1243 | Slog.i(TAG, "******************* PROCESS STATE CHANGED TO: " + processState |
| 1244 | + (fromIpc ? " (from ipc": "")); |
| 1245 | } |
| 1246 | } |
| 1247 | } |
| 1248 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1249 | } |
| 1250 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1251 | private class H extends Handler { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1252 | public static final int LAUNCH_ACTIVITY = 100; |
| 1253 | public static final int PAUSE_ACTIVITY = 101; |
| 1254 | public static final int PAUSE_ACTIVITY_FINISHING= 102; |
| 1255 | public static final int STOP_ACTIVITY_SHOW = 103; |
| 1256 | public static final int STOP_ACTIVITY_HIDE = 104; |
| 1257 | public static final int SHOW_WINDOW = 105; |
| 1258 | public static final int HIDE_WINDOW = 106; |
| 1259 | public static final int RESUME_ACTIVITY = 107; |
| 1260 | public static final int SEND_RESULT = 108; |
Brian Carlstrom | ed7e007 | 2011-03-24 13:27:57 -0700 | [diff] [blame] | 1261 | public static final int DESTROY_ACTIVITY = 109; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1262 | public static final int BIND_APPLICATION = 110; |
| 1263 | public static final int EXIT_APPLICATION = 111; |
| 1264 | public static final int NEW_INTENT = 112; |
| 1265 | public static final int RECEIVER = 113; |
| 1266 | public static final int CREATE_SERVICE = 114; |
| 1267 | public static final int SERVICE_ARGS = 115; |
| 1268 | public static final int STOP_SERVICE = 116; |
| 1269 | public static final int REQUEST_THUMBNAIL = 117; |
| 1270 | public static final int CONFIGURATION_CHANGED = 118; |
| 1271 | public static final int CLEAN_UP_CONTEXT = 119; |
| 1272 | public static final int GC_WHEN_IDLE = 120; |
| 1273 | public static final int BIND_SERVICE = 121; |
| 1274 | public static final int UNBIND_SERVICE = 122; |
| 1275 | public static final int DUMP_SERVICE = 123; |
| 1276 | public static final int LOW_MEMORY = 124; |
| 1277 | public static final int ACTIVITY_CONFIGURATION_CHANGED = 125; |
| 1278 | public static final int RELAUNCH_ACTIVITY = 126; |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 1279 | public static final int PROFILER_CONTROL = 127; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1280 | public static final int CREATE_BACKUP_AGENT = 128; |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 1281 | public static final int DESTROY_BACKUP_AGENT = 129; |
| 1282 | public static final int SUICIDE = 130; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1283 | public static final int REMOVE_PROVIDER = 131; |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 1284 | public static final int ENABLE_JIT = 132; |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1285 | public static final int DISPATCH_PACKAGE_BROADCAST = 133; |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 1286 | public static final int SCHEDULE_CRASH = 134; |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 1287 | public static final int DUMP_HEAP = 135; |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1288 | public static final int DUMP_ACTIVITY = 136; |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1289 | public static final int SLEEPING = 137; |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1290 | public static final int SET_CORE_SETTINGS = 138; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1291 | public static final int UPDATE_PACKAGE_COMPATIBILITY_INFO = 139; |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1292 | public static final int TRIM_MEMORY = 140; |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1293 | public static final int DUMP_PROVIDER = 141; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1294 | public static final int UNSTABLE_PROVIDER_DIED = 142; |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 1295 | public static final int REQUEST_ACTIVITY_EXTRAS = 143; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1296 | public static final int TRANSLUCENT_CONVERSION_COMPLETE = 144; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1297 | String codeToString(int code) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 1298 | if (DEBUG_MESSAGES) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1299 | switch (code) { |
| 1300 | case LAUNCH_ACTIVITY: return "LAUNCH_ACTIVITY"; |
| 1301 | case PAUSE_ACTIVITY: return "PAUSE_ACTIVITY"; |
| 1302 | case PAUSE_ACTIVITY_FINISHING: return "PAUSE_ACTIVITY_FINISHING"; |
| 1303 | case STOP_ACTIVITY_SHOW: return "STOP_ACTIVITY_SHOW"; |
| 1304 | case STOP_ACTIVITY_HIDE: return "STOP_ACTIVITY_HIDE"; |
| 1305 | case SHOW_WINDOW: return "SHOW_WINDOW"; |
| 1306 | case HIDE_WINDOW: return "HIDE_WINDOW"; |
| 1307 | case RESUME_ACTIVITY: return "RESUME_ACTIVITY"; |
| 1308 | case SEND_RESULT: return "SEND_RESULT"; |
| 1309 | case DESTROY_ACTIVITY: return "DESTROY_ACTIVITY"; |
| 1310 | case BIND_APPLICATION: return "BIND_APPLICATION"; |
| 1311 | case EXIT_APPLICATION: return "EXIT_APPLICATION"; |
| 1312 | case NEW_INTENT: return "NEW_INTENT"; |
| 1313 | case RECEIVER: return "RECEIVER"; |
| 1314 | case CREATE_SERVICE: return "CREATE_SERVICE"; |
| 1315 | case SERVICE_ARGS: return "SERVICE_ARGS"; |
| 1316 | case STOP_SERVICE: return "STOP_SERVICE"; |
| 1317 | case REQUEST_THUMBNAIL: return "REQUEST_THUMBNAIL"; |
| 1318 | case CONFIGURATION_CHANGED: return "CONFIGURATION_CHANGED"; |
| 1319 | case CLEAN_UP_CONTEXT: return "CLEAN_UP_CONTEXT"; |
| 1320 | case GC_WHEN_IDLE: return "GC_WHEN_IDLE"; |
| 1321 | case BIND_SERVICE: return "BIND_SERVICE"; |
| 1322 | case UNBIND_SERVICE: return "UNBIND_SERVICE"; |
| 1323 | case DUMP_SERVICE: return "DUMP_SERVICE"; |
| 1324 | case LOW_MEMORY: return "LOW_MEMORY"; |
| 1325 | case ACTIVITY_CONFIGURATION_CHANGED: return "ACTIVITY_CONFIGURATION_CHANGED"; |
| 1326 | case RELAUNCH_ACTIVITY: return "RELAUNCH_ACTIVITY"; |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 1327 | case PROFILER_CONTROL: return "PROFILER_CONTROL"; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1328 | case CREATE_BACKUP_AGENT: return "CREATE_BACKUP_AGENT"; |
| 1329 | case DESTROY_BACKUP_AGENT: return "DESTROY_BACKUP_AGENT"; |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 1330 | case SUICIDE: return "SUICIDE"; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1331 | case REMOVE_PROVIDER: return "REMOVE_PROVIDER"; |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 1332 | case ENABLE_JIT: return "ENABLE_JIT"; |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1333 | case DISPATCH_PACKAGE_BROADCAST: return "DISPATCH_PACKAGE_BROADCAST"; |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 1334 | case SCHEDULE_CRASH: return "SCHEDULE_CRASH"; |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 1335 | case DUMP_HEAP: return "DUMP_HEAP"; |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1336 | case DUMP_ACTIVITY: return "DUMP_ACTIVITY"; |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1337 | case SLEEPING: return "SLEEPING"; |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1338 | case SET_CORE_SETTINGS: return "SET_CORE_SETTINGS"; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1339 | case UPDATE_PACKAGE_COMPATIBILITY_INFO: return "UPDATE_PACKAGE_COMPATIBILITY_INFO"; |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1340 | case TRIM_MEMORY: return "TRIM_MEMORY"; |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1341 | case DUMP_PROVIDER: return "DUMP_PROVIDER"; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1342 | case UNSTABLE_PROVIDER_DIED: return "UNSTABLE_PROVIDER_DIED"; |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 1343 | case REQUEST_ACTIVITY_EXTRAS: return "REQUEST_ACTIVITY_EXTRAS"; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1344 | case TRANSLUCENT_CONVERSION_COMPLETE: return "TRANSLUCENT_CONVERSION_COMPLETE"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1345 | } |
| 1346 | } |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 1347 | return Integer.toString(code); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1348 | } |
| 1349 | public void handleMessage(Message msg) { |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 1350 | if (DEBUG_MESSAGES) Slog.v(TAG, ">>> handling: " + codeToString(msg.what)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1351 | switch (msg.what) { |
| 1352 | case LAUNCH_ACTIVITY: { |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1353 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityStart"); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1354 | ActivityClientRecord r = (ActivityClientRecord)msg.obj; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1355 | |
| 1356 | r.packageInfo = getPackageInfoNoCheck( |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1357 | r.activityInfo.applicationInfo, r.compatInfo); |
Christopher Tate | b70f3df | 2009-04-07 16:07:59 -0700 | [diff] [blame] | 1358 | handleLaunchActivity(r, null); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1359 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1360 | } break; |
| 1361 | case RELAUNCH_ACTIVITY: { |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1362 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityRestart"); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1363 | ActivityClientRecord r = (ActivityClientRecord)msg.obj; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 1364 | handleRelaunchActivity(r); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1365 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1366 | } break; |
| 1367 | case PAUSE_ACTIVITY: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1368 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityPause"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1369 | handlePauseActivity((IBinder)msg.obj, false, msg.arg1 != 0, msg.arg2); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1370 | maybeSnapshot(); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1371 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1372 | break; |
| 1373 | case PAUSE_ACTIVITY_FINISHING: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1374 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityPause"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1375 | handlePauseActivity((IBinder)msg.obj, true, msg.arg1 != 0, msg.arg2); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1376 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1377 | break; |
| 1378 | case STOP_ACTIVITY_SHOW: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1379 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityStop"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1380 | handleStopActivity((IBinder)msg.obj, true, msg.arg2); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1381 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1382 | break; |
| 1383 | case STOP_ACTIVITY_HIDE: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1384 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityStop"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1385 | handleStopActivity((IBinder)msg.obj, false, msg.arg2); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1386 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1387 | break; |
| 1388 | case SHOW_WINDOW: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1389 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityShowWindow"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1390 | handleWindowVisibility((IBinder)msg.obj, true); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1391 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1392 | break; |
| 1393 | case HIDE_WINDOW: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1394 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityHideWindow"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1395 | handleWindowVisibility((IBinder)msg.obj, false); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1396 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1397 | break; |
| 1398 | case RESUME_ACTIVITY: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1399 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityResume"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1400 | handleResumeActivity((IBinder)msg.obj, true, |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 1401 | msg.arg1 != 0, true); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1402 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1403 | break; |
| 1404 | case SEND_RESULT: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1405 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityDeliverResult"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1406 | handleSendResult((ResultData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1407 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1408 | break; |
| 1409 | case DESTROY_ACTIVITY: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1410 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityDestroy"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1411 | handleDestroyActivity((IBinder)msg.obj, msg.arg1 != 0, |
| 1412 | msg.arg2, false); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1413 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1414 | break; |
| 1415 | case BIND_APPLICATION: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1416 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "bindApplication"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1417 | AppBindData data = (AppBindData)msg.obj; |
| 1418 | handleBindApplication(data); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1419 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1420 | break; |
| 1421 | case EXIT_APPLICATION: |
| 1422 | if (mInitialApplication != null) { |
| 1423 | mInitialApplication.onTerminate(); |
| 1424 | } |
| 1425 | Looper.myLooper().quit(); |
| 1426 | break; |
| 1427 | case NEW_INTENT: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1428 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityNewIntent"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1429 | handleNewIntent((NewIntentData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1430 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1431 | break; |
| 1432 | case RECEIVER: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1433 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "broadcastReceiveComp"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1434 | handleReceiver((ReceiverData)msg.obj); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1435 | maybeSnapshot(); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1436 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1437 | break; |
| 1438 | case CREATE_SERVICE: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1439 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "serviceCreate"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1440 | handleCreateService((CreateServiceData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1441 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1442 | break; |
| 1443 | case BIND_SERVICE: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1444 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "serviceBind"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1445 | handleBindService((BindServiceData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1446 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1447 | break; |
| 1448 | case UNBIND_SERVICE: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1449 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "serviceUnbind"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1450 | handleUnbindService((BindServiceData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1451 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1452 | break; |
| 1453 | case SERVICE_ARGS: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1454 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "serviceStart"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1455 | handleServiceArgs((ServiceArgsData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1456 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1457 | break; |
| 1458 | case STOP_SERVICE: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1459 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "serviceStop"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1460 | handleStopService((IBinder)msg.obj); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1461 | maybeSnapshot(); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1462 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1463 | break; |
| 1464 | case REQUEST_THUMBNAIL: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1465 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "requestThumbnail"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1466 | handleRequestThumbnail((IBinder)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1467 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1468 | break; |
| 1469 | case CONFIGURATION_CHANGED: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1470 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "configChanged"); |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 1471 | mCurDefaultDisplayDpi = ((Configuration)msg.obj).densityDpi; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1472 | handleConfigurationChanged((Configuration)msg.obj, null); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1473 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1474 | break; |
| 1475 | case CLEAN_UP_CONTEXT: |
| 1476 | ContextCleanupInfo cci = (ContextCleanupInfo)msg.obj; |
| 1477 | cci.context.performFinalCleanup(cci.who, cci.what); |
| 1478 | break; |
| 1479 | case GC_WHEN_IDLE: |
| 1480 | scheduleGcIdler(); |
| 1481 | break; |
| 1482 | case DUMP_SERVICE: |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1483 | handleDumpService((DumpComponentInfo)msg.obj); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1484 | break; |
| 1485 | case LOW_MEMORY: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1486 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "lowMemory"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1487 | handleLowMemory(); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1488 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1489 | break; |
| 1490 | case ACTIVITY_CONFIGURATION_CHANGED: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1491 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityConfigChanged"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1492 | handleActivityConfigurationChanged((IBinder)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1493 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1494 | break; |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 1495 | case PROFILER_CONTROL: |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 1496 | handleProfilerControl(msg.arg1 != 0, (ProfilerControlData)msg.obj, msg.arg2); |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 1497 | break; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1498 | case CREATE_BACKUP_AGENT: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1499 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "backupCreateAgent"); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1500 | handleCreateBackupAgent((CreateBackupAgentData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1501 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1502 | break; |
| 1503 | case DESTROY_BACKUP_AGENT: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1504 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "backupDestroyAgent"); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1505 | handleDestroyBackupAgent((CreateBackupAgentData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1506 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1507 | break; |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 1508 | case SUICIDE: |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1509 | Process.killProcess(Process.myPid()); |
| 1510 | break; |
| 1511 | case REMOVE_PROVIDER: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1512 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "providerRemove"); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1513 | completeRemoveProvider((ProviderRefCount)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1514 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 1515 | break; |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 1516 | case ENABLE_JIT: |
| 1517 | ensureJitEnabled(); |
| 1518 | break; |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1519 | case DISPATCH_PACKAGE_BROADCAST: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1520 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "broadcastPackage"); |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1521 | handleDispatchPackageBroadcast(msg.arg1, (String[])msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1522 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1523 | break; |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 1524 | case SCHEDULE_CRASH: |
| 1525 | throw new RemoteServiceException((String)msg.obj); |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 1526 | case DUMP_HEAP: |
| 1527 | handleDumpHeap(msg.arg1 != 0, (DumpHeapData)msg.obj); |
| 1528 | break; |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1529 | case DUMP_ACTIVITY: |
| 1530 | handleDumpActivity((DumpComponentInfo)msg.obj); |
| 1531 | break; |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1532 | case DUMP_PROVIDER: |
| 1533 | handleDumpProvider((DumpComponentInfo)msg.obj); |
| 1534 | break; |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1535 | case SLEEPING: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1536 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "sleeping"); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1537 | handleSleeping((IBinder)msg.obj, msg.arg1 != 0); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1538 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1539 | break; |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1540 | case SET_CORE_SETTINGS: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1541 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "setCoreSettings"); |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1542 | handleSetCoreSettings((Bundle) msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1543 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1544 | break; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1545 | case UPDATE_PACKAGE_COMPATIBILITY_INFO: |
| 1546 | handleUpdatePackageCompatibilityInfo((UpdateCompatibilityData)msg.obj); |
Dianne Hackborn | f0754f5b | 2011-07-21 16:02:07 -0700 | [diff] [blame] | 1547 | break; |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1548 | case TRIM_MEMORY: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1549 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "trimMemory"); |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1550 | handleTrimMemory(msg.arg1); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1551 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Dianne Hackborn | f0754f5b | 2011-07-21 16:02:07 -0700 | [diff] [blame] | 1552 | break; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1553 | case UNSTABLE_PROVIDER_DIED: |
| 1554 | handleUnstableProviderDied((IBinder)msg.obj, false); |
| 1555 | break; |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 1556 | case REQUEST_ACTIVITY_EXTRAS: |
| 1557 | handleRequestActivityExtras((RequestActivityExtras)msg.obj); |
| 1558 | break; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1559 | case TRANSLUCENT_CONVERSION_COMPLETE: |
| 1560 | handleTranslucentConversionComplete((IBinder)msg.obj, msg.arg1 == 1); |
| 1561 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1562 | } |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 1563 | if (DEBUG_MESSAGES) Slog.v(TAG, "<<< done: " + codeToString(msg.what)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1564 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1565 | |
Brian Carlstrom | ed7e007 | 2011-03-24 13:27:57 -0700 | [diff] [blame] | 1566 | private void maybeSnapshot() { |
| 1567 | if (mBoundApplication != null && SamplingProfilerIntegration.isEnabled()) { |
Sen Hu | bde7570 | 2010-05-28 01:54:03 -0700 | [diff] [blame] | 1568 | // convert the *private* ActivityThread.PackageInfo to *public* known |
| 1569 | // android.content.pm.PackageInfo |
| 1570 | String packageName = mBoundApplication.info.mPackageName; |
| 1571 | android.content.pm.PackageInfo packageInfo = null; |
| 1572 | try { |
| 1573 | Context context = getSystemContext(); |
| 1574 | if(context == null) { |
| 1575 | Log.e(TAG, "cannot get a valid context"); |
| 1576 | return; |
| 1577 | } |
| 1578 | PackageManager pm = context.getPackageManager(); |
| 1579 | if(pm == null) { |
| 1580 | Log.e(TAG, "cannot get a valid PackageManager"); |
| 1581 | return; |
| 1582 | } |
| 1583 | packageInfo = pm.getPackageInfo( |
| 1584 | packageName, PackageManager.GET_ACTIVITIES); |
| 1585 | } catch (NameNotFoundException e) { |
| 1586 | Log.e(TAG, "cannot get package info for " + packageName, e); |
| 1587 | } |
| 1588 | SamplingProfilerIntegration.writeSnapshot(mBoundApplication.processName, packageInfo); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1589 | } |
| 1590 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1591 | } |
| 1592 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1593 | private class Idler implements MessageQueue.IdleHandler { |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 1594 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1595 | public final boolean queueIdle() { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1596 | ActivityClientRecord a = mNewActivities; |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 1597 | boolean stopProfiling = false; |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 1598 | if (mBoundApplication != null && mProfiler.profileFd != null |
| 1599 | && mProfiler.autoStopProfiler) { |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 1600 | stopProfiling = true; |
| 1601 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1602 | if (a != null) { |
| 1603 | mNewActivities = null; |
| 1604 | IActivityManager am = ActivityManagerNative.getDefault(); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1605 | ActivityClientRecord prev; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1606 | do { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 1607 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1608 | TAG, "Reporting idle of " + a + |
| 1609 | " finished=" + |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1610 | (a.activity != null && a.activity.mFinished)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1611 | if (a.activity != null && !a.activity.mFinished) { |
| 1612 | try { |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 1613 | am.activityIdle(a.token, a.createdConfig, stopProfiling); |
Dianne Hackborn | e88846e | 2009-09-30 21:34:25 -0700 | [diff] [blame] | 1614 | a.createdConfig = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1615 | } catch (RemoteException ex) { |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1616 | // Ignore |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1617 | } |
| 1618 | } |
| 1619 | prev = a; |
| 1620 | a = a.nextIdle; |
| 1621 | prev.nextIdle = null; |
| 1622 | } while (a != null); |
| 1623 | } |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 1624 | if (stopProfiling) { |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 1625 | mProfiler.stopProfiling(); |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 1626 | } |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 1627 | ensureJitEnabled(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1628 | return false; |
| 1629 | } |
| 1630 | } |
| 1631 | |
| 1632 | final class GcIdler implements MessageQueue.IdleHandler { |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 1633 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1634 | public final boolean queueIdle() { |
| 1635 | doGcIfNeeded(); |
| 1636 | return false; |
| 1637 | } |
| 1638 | } |
| 1639 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1640 | public static ActivityThread currentActivityThread() { |
Jeff Sharkey | 66a017b | 2013-01-17 18:18:22 -0800 | [diff] [blame] | 1641 | return sCurrentActivityThread; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1642 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1643 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1644 | public static String currentPackageName() { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1645 | ActivityThread am = currentActivityThread(); |
| 1646 | return (am != null && am.mBoundApplication != null) |
Dianne Hackborn | b57a50b | 2013-04-11 17:29:32 -0700 | [diff] [blame] | 1647 | ? am.mBoundApplication.appInfo.packageName : null; |
| 1648 | } |
| 1649 | |
| 1650 | public static String currentProcessName() { |
| 1651 | ActivityThread am = currentActivityThread(); |
| 1652 | return (am != null && am.mBoundApplication != null) |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1653 | ? am.mBoundApplication.processName : null; |
| 1654 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1655 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1656 | public static Application currentApplication() { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1657 | ActivityThread am = currentActivityThread(); |
| 1658 | return am != null ? am.mInitialApplication : null; |
| 1659 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1660 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1661 | public static IPackageManager getPackageManager() { |
| 1662 | if (sPackageManager != null) { |
| 1663 | //Slog.v("PackageManager", "returning cur default = " + sPackageManager); |
| 1664 | return sPackageManager; |
| 1665 | } |
| 1666 | IBinder b = ServiceManager.getService("package"); |
| 1667 | //Slog.v("PackageManager", "default service binder = " + b); |
| 1668 | sPackageManager = IPackageManager.Stub.asInterface(b); |
| 1669 | //Slog.v("PackageManager", "default service = " + sPackageManager); |
| 1670 | return sPackageManager; |
| 1671 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1672 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1673 | private Configuration mMainThreadConfig = new Configuration(); |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 1674 | Configuration applyConfigCompatMainThread(int displayDensity, Configuration config, |
| 1675 | CompatibilityInfo compat) { |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1676 | if (config == null) { |
| 1677 | return null; |
| 1678 | } |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 1679 | if (!compat.supportsScreen()) { |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1680 | mMainThreadConfig.setTo(config); |
| 1681 | config = mMainThreadConfig; |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 1682 | compat.applyToConfiguration(displayDensity, config); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1683 | } |
| 1684 | return config; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1685 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1686 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1687 | /** |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1688 | * Creates the top level resources for the given package. |
| 1689 | */ |
Jeff Brown | a492c3a | 2012-08-23 19:48:44 -0700 | [diff] [blame] | 1690 | Resources getTopLevelResources(String resDir, |
| 1691 | int displayId, Configuration overrideConfiguration, |
Dianne Hackborn | 756220b | 2012-08-14 16:45:30 -0700 | [diff] [blame] | 1692 | LoadedApk pkgInfo) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 1693 | return mResourcesManager.getTopLevelResources(resDir, displayId, overrideConfiguration, |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 1694 | pkgInfo.getCompatibilityInfo(), null); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1695 | } |
| 1696 | |
| 1697 | final Handler getHandler() { |
| 1698 | return mH; |
| 1699 | } |
| 1700 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1701 | public final LoadedApk getPackageInfo(String packageName, CompatibilityInfo compatInfo, |
| 1702 | int flags) { |
Amith Yamasani | 98edc95 | 2012-09-25 14:09:27 -0700 | [diff] [blame] | 1703 | return getPackageInfo(packageName, compatInfo, flags, UserHandle.myUserId()); |
| 1704 | } |
| 1705 | |
| 1706 | public final LoadedApk getPackageInfo(String packageName, CompatibilityInfo compatInfo, |
| 1707 | int flags, int userId) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 1708 | synchronized (mResourcesManager) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1709 | WeakReference<LoadedApk> ref; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1710 | if ((flags&Context.CONTEXT_INCLUDE_CODE) != 0) { |
| 1711 | ref = mPackages.get(packageName); |
| 1712 | } else { |
| 1713 | ref = mResourcePackages.get(packageName); |
| 1714 | } |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1715 | LoadedApk packageInfo = ref != null ? ref.get() : null; |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 1716 | //Slog.i(TAG, "getPackageInfo " + packageName + ": " + packageInfo); |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1717 | //if (packageInfo != null) Slog.i(TAG, "isUptoDate " + packageInfo.mResDir |
| 1718 | // + ": " + packageInfo.mResources.getAssets().isUpToDate()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1719 | if (packageInfo != null && (packageInfo.mResources == null |
| 1720 | || packageInfo.mResources.getAssets().isUpToDate())) { |
| 1721 | if (packageInfo.isSecurityViolation() |
| 1722 | && (flags&Context.CONTEXT_IGNORE_SECURITY) == 0) { |
| 1723 | throw new SecurityException( |
| 1724 | "Requesting code from " + packageName |
| 1725 | + " to be run in process " |
| 1726 | + mBoundApplication.processName |
| 1727 | + "/" + mBoundApplication.appInfo.uid); |
| 1728 | } |
| 1729 | return packageInfo; |
| 1730 | } |
| 1731 | } |
| 1732 | |
| 1733 | ApplicationInfo ai = null; |
| 1734 | try { |
| 1735 | ai = getPackageManager().getApplicationInfo(packageName, |
Amith Yamasani | 98edc95 | 2012-09-25 14:09:27 -0700 | [diff] [blame] | 1736 | PackageManager.GET_SHARED_LIBRARY_FILES, userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1737 | } catch (RemoteException e) { |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1738 | // Ignore |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1739 | } |
| 1740 | |
| 1741 | if (ai != null) { |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1742 | return getPackageInfo(ai, compatInfo, flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1743 | } |
| 1744 | |
| 1745 | return null; |
| 1746 | } |
| 1747 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1748 | public final LoadedApk getPackageInfo(ApplicationInfo ai, CompatibilityInfo compatInfo, |
| 1749 | int flags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1750 | boolean includeCode = (flags&Context.CONTEXT_INCLUDE_CODE) != 0; |
| 1751 | boolean securityViolation = includeCode && ai.uid != 0 |
| 1752 | && ai.uid != Process.SYSTEM_UID && (mBoundApplication != null |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 1753 | ? !UserHandle.isSameApp(ai.uid, mBoundApplication.appInfo.uid) |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 1754 | : true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1755 | if ((flags&(Context.CONTEXT_INCLUDE_CODE |
| 1756 | |Context.CONTEXT_IGNORE_SECURITY)) |
| 1757 | == Context.CONTEXT_INCLUDE_CODE) { |
| 1758 | if (securityViolation) { |
| 1759 | String msg = "Requesting code from " + ai.packageName |
| 1760 | + " (with uid " + ai.uid + ")"; |
| 1761 | if (mBoundApplication != null) { |
| 1762 | msg = msg + " to be run in process " |
| 1763 | + mBoundApplication.processName + " (with uid " |
| 1764 | + mBoundApplication.appInfo.uid + ")"; |
| 1765 | } |
| 1766 | throw new SecurityException(msg); |
| 1767 | } |
| 1768 | } |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1769 | return getPackageInfo(ai, compatInfo, null, securityViolation, includeCode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1770 | } |
| 1771 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1772 | public final LoadedApk getPackageInfoNoCheck(ApplicationInfo ai, |
| 1773 | CompatibilityInfo compatInfo) { |
| 1774 | return getPackageInfo(ai, compatInfo, null, false, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1775 | } |
| 1776 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1777 | public final LoadedApk peekPackageInfo(String packageName, boolean includeCode) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 1778 | synchronized (mResourcesManager) { |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1779 | WeakReference<LoadedApk> ref; |
| 1780 | if (includeCode) { |
| 1781 | ref = mPackages.get(packageName); |
| 1782 | } else { |
| 1783 | ref = mResourcePackages.get(packageName); |
| 1784 | } |
| 1785 | return ref != null ? ref.get() : null; |
| 1786 | } |
| 1787 | } |
| 1788 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1789 | private LoadedApk getPackageInfo(ApplicationInfo aInfo, CompatibilityInfo compatInfo, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1790 | ClassLoader baseLoader, boolean securityViolation, boolean includeCode) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 1791 | synchronized (mResourcesManager) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1792 | WeakReference<LoadedApk> ref; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1793 | if (includeCode) { |
| 1794 | ref = mPackages.get(aInfo.packageName); |
| 1795 | } else { |
| 1796 | ref = mResourcePackages.get(aInfo.packageName); |
| 1797 | } |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1798 | LoadedApk packageInfo = ref != null ? ref.get() : null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1799 | if (packageInfo == null || (packageInfo.mResources != null |
| 1800 | && !packageInfo.mResources.getAssets().isUpToDate())) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 1801 | if (localLOGV) Slog.v(TAG, (includeCode ? "Loading code package " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1802 | : "Loading resource-only package ") + aInfo.packageName |
| 1803 | + " (in " + (mBoundApplication != null |
| 1804 | ? mBoundApplication.processName : null) |
| 1805 | + ")"); |
| 1806 | packageInfo = |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1807 | new LoadedApk(this, aInfo, compatInfo, this, baseLoader, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1808 | securityViolation, includeCode && |
| 1809 | (aInfo.flags&ApplicationInfo.FLAG_HAS_CODE) != 0); |
| 1810 | if (includeCode) { |
| 1811 | mPackages.put(aInfo.packageName, |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1812 | new WeakReference<LoadedApk>(packageInfo)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1813 | } else { |
| 1814 | mResourcePackages.put(aInfo.packageName, |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1815 | new WeakReference<LoadedApk>(packageInfo)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1816 | } |
| 1817 | } |
| 1818 | return packageInfo; |
| 1819 | } |
| 1820 | } |
| 1821 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1822 | ActivityThread() { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 1823 | mResourcesManager = ResourcesManager.getInstance(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1824 | } |
| 1825 | |
| 1826 | public ApplicationThread getApplicationThread() |
| 1827 | { |
| 1828 | return mAppThread; |
| 1829 | } |
| 1830 | |
| 1831 | public Instrumentation getInstrumentation() |
| 1832 | { |
| 1833 | return mInstrumentation; |
| 1834 | } |
| 1835 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1836 | public boolean isProfiling() { |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 1837 | return mProfiler != null && mProfiler.profileFile != null |
| 1838 | && mProfiler.profileFd == null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1839 | } |
| 1840 | |
| 1841 | public String getProfileFilePath() { |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 1842 | return mProfiler.profileFile; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1843 | } |
| 1844 | |
| 1845 | public Looper getLooper() { |
| 1846 | return mLooper; |
| 1847 | } |
| 1848 | |
| 1849 | public Application getApplication() { |
| 1850 | return mInitialApplication; |
| 1851 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1852 | |
Dianne Hackborn | d97c7ad | 2009-06-19 11:37:35 -0700 | [diff] [blame] | 1853 | public String getProcessName() { |
| 1854 | return mBoundApplication.processName; |
| 1855 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1856 | |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 1857 | public ContextImpl getSystemContext() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1858 | synchronized (this) { |
| 1859 | if (mSystemContext == null) { |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 1860 | ContextImpl context = |
| 1861 | ContextImpl.createSystemContext(this); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1862 | LoadedApk info = new LoadedApk(this, "android", context, null, |
| 1863 | CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1864 | context.init(info, null, this); |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 1865 | context.getResources().updateConfiguration(mResourcesManager.getConfiguration(), |
| 1866 | mResourcesManager.getDisplayMetricsLocked(Display.DEFAULT_DISPLAY)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1867 | mSystemContext = context; |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 1868 | //Slog.i(TAG, "Created system resources " + context.getResources() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1869 | // + ": " + context.getResources().getConfiguration()); |
| 1870 | } |
| 1871 | } |
| 1872 | return mSystemContext; |
| 1873 | } |
| 1874 | |
Mike Cleron | 432b713 | 2009-09-24 15:28:29 -0700 | [diff] [blame] | 1875 | public void installSystemApplicationInfo(ApplicationInfo info) { |
| 1876 | synchronized (this) { |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 1877 | ContextImpl context = getSystemContext(); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1878 | context.init(new LoadedApk(this, "android", context, info, |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 1879 | CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO), null, this); |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 1880 | |
| 1881 | // give ourselves a default profiler |
| 1882 | mProfiler = new Profiler(); |
Mike Cleron | 432b713 | 2009-09-24 15:28:29 -0700 | [diff] [blame] | 1883 | } |
| 1884 | } |
| 1885 | |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 1886 | void ensureJitEnabled() { |
| 1887 | if (!mJitEnabled) { |
| 1888 | mJitEnabled = true; |
| 1889 | dalvik.system.VMRuntime.getRuntime().startJitCompilation(); |
| 1890 | } |
| 1891 | } |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 1892 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1893 | void scheduleGcIdler() { |
| 1894 | if (!mGcIdlerScheduled) { |
| 1895 | mGcIdlerScheduled = true; |
| 1896 | Looper.myQueue().addIdleHandler(mGcIdler); |
| 1897 | } |
| 1898 | mH.removeMessages(H.GC_WHEN_IDLE); |
| 1899 | } |
| 1900 | |
| 1901 | void unscheduleGcIdler() { |
| 1902 | if (mGcIdlerScheduled) { |
| 1903 | mGcIdlerScheduled = false; |
| 1904 | Looper.myQueue().removeIdleHandler(mGcIdler); |
| 1905 | } |
| 1906 | mH.removeMessages(H.GC_WHEN_IDLE); |
| 1907 | } |
| 1908 | |
| 1909 | void doGcIfNeeded() { |
| 1910 | mGcIdlerScheduled = false; |
| 1911 | final long now = SystemClock.uptimeMillis(); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 1912 | //Slog.i(TAG, "**** WE MIGHT WANT TO GC: then=" + Binder.getLastGcTime() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1913 | // + "m now=" + now); |
| 1914 | if ((BinderInternal.getLastGcTime()+MIN_TIME_BETWEEN_GCS) < now) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 1915 | //Slog.i(TAG, "**** WE DO, WE DO WANT TO GC!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1916 | BinderInternal.forceGc("bg"); |
| 1917 | } |
| 1918 | } |
| 1919 | |
Jeff Hamilton | 52d3203 | 2011-01-08 15:31:26 -0600 | [diff] [blame] | 1920 | public void registerOnActivityPausedListener(Activity activity, |
| 1921 | OnActivityPausedListener listener) { |
| 1922 | synchronized (mOnPauseListeners) { |
| 1923 | ArrayList<OnActivityPausedListener> list = mOnPauseListeners.get(activity); |
| 1924 | if (list == null) { |
| 1925 | list = new ArrayList<OnActivityPausedListener>(); |
| 1926 | mOnPauseListeners.put(activity, list); |
| 1927 | } |
| 1928 | list.add(listener); |
| 1929 | } |
| 1930 | } |
| 1931 | |
Jeff Hamilton | ce3224c | 2011-01-17 11:05:03 -0800 | [diff] [blame] | 1932 | public void unregisterOnActivityPausedListener(Activity activity, |
| 1933 | OnActivityPausedListener listener) { |
| 1934 | synchronized (mOnPauseListeners) { |
| 1935 | ArrayList<OnActivityPausedListener> list = mOnPauseListeners.get(activity); |
| 1936 | if (list != null) { |
| 1937 | list.remove(listener); |
| 1938 | } |
| 1939 | } |
| 1940 | } |
| 1941 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1942 | public final ActivityInfo resolveActivityInfo(Intent intent) { |
| 1943 | ActivityInfo aInfo = intent.resolveActivityInfo( |
| 1944 | mInitialApplication.getPackageManager(), PackageManager.GET_SHARED_LIBRARY_FILES); |
| 1945 | if (aInfo == null) { |
| 1946 | // Throw an exception. |
| 1947 | Instrumentation.checkStartActivityResult( |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 1948 | ActivityManager.START_CLASS_NOT_FOUND, intent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1949 | } |
| 1950 | return aInfo; |
| 1951 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1952 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1953 | public final Activity startActivityNow(Activity parent, String id, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1954 | Intent intent, ActivityInfo activityInfo, IBinder token, Bundle state, |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 1955 | Activity.NonConfigurationInstances lastNonConfigurationInstances) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1956 | ActivityClientRecord r = new ActivityClientRecord(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1957 | r.token = token; |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 1958 | r.ident = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1959 | r.intent = intent; |
| 1960 | r.state = state; |
| 1961 | r.parent = parent; |
| 1962 | r.embeddedID = id; |
| 1963 | r.activityInfo = activityInfo; |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 1964 | r.lastNonConfigurationInstances = lastNonConfigurationInstances; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1965 | if (localLOGV) { |
| 1966 | ComponentName compname = intent.getComponent(); |
| 1967 | String name; |
| 1968 | if (compname != null) { |
| 1969 | name = compname.toShortString(); |
| 1970 | } else { |
| 1971 | name = "(Intent " + intent + ").getComponent() returned null"; |
| 1972 | } |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 1973 | Slog.v(TAG, "Performing launch: action=" + intent.getAction() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1974 | + ", comp=" + name |
| 1975 | + ", token=" + token); |
| 1976 | } |
Christopher Tate | b70f3df | 2009-04-07 16:07:59 -0700 | [diff] [blame] | 1977 | return performLaunchActivity(r, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1978 | } |
| 1979 | |
| 1980 | public final Activity getActivity(IBinder token) { |
| 1981 | return mActivities.get(token).activity; |
| 1982 | } |
| 1983 | |
| 1984 | public final void sendActivityResult( |
| 1985 | IBinder token, String id, int requestCode, |
| 1986 | int resultCode, Intent data) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 1987 | if (DEBUG_RESULTS) Slog.v(TAG, "sendActivityResult: id=" + id |
Chris Tate | 8a7dc17 | 2009-03-24 20:11:42 -0700 | [diff] [blame] | 1988 | + " req=" + requestCode + " res=" + resultCode + " data=" + data); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1989 | ArrayList<ResultInfo> list = new ArrayList<ResultInfo>(); |
| 1990 | list.add(new ResultInfo(id, requestCode, resultCode, data)); |
| 1991 | mAppThread.scheduleSendResult(token, list); |
| 1992 | } |
| 1993 | |
| 1994 | // if the thread hasn't started yet, we don't have the handler, so just |
| 1995 | // save the messages until we're ready. |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1996 | private void queueOrSendMessage(int what, Object obj) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1997 | queueOrSendMessage(what, obj, 0, 0); |
| 1998 | } |
| 1999 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 2000 | private void queueOrSendMessage(int what, Object obj, int arg1) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2001 | queueOrSendMessage(what, obj, arg1, 0); |
| 2002 | } |
| 2003 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 2004 | private void queueOrSendMessage(int what, Object obj, int arg1, int arg2) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2005 | synchronized (this) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 2006 | if (DEBUG_MESSAGES) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2007 | TAG, "SCHEDULE " + what + " " + mH.codeToString(what) |
| 2008 | + ": " + arg1 + " / " + obj); |
| 2009 | Message msg = Message.obtain(); |
| 2010 | msg.what = what; |
| 2011 | msg.obj = obj; |
| 2012 | msg.arg1 = arg1; |
| 2013 | msg.arg2 = arg2; |
| 2014 | mH.sendMessage(msg); |
| 2015 | } |
| 2016 | } |
| 2017 | |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 2018 | final void scheduleContextCleanup(ContextImpl context, String who, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2019 | String what) { |
| 2020 | ContextCleanupInfo cci = new ContextCleanupInfo(); |
| 2021 | cci.context = context; |
| 2022 | cci.who = who; |
| 2023 | cci.what = what; |
| 2024 | queueOrSendMessage(H.CLEAN_UP_CONTEXT, cci); |
| 2025 | } |
| 2026 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 2027 | private Activity performLaunchActivity(ActivityClientRecord r, Intent customIntent) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2028 | // System.out.println("##### [" + System.currentTimeMillis() + "] ActivityThread.performLaunchActivity(" + r + ")"); |
| 2029 | |
| 2030 | ActivityInfo aInfo = r.activityInfo; |
| 2031 | if (r.packageInfo == null) { |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2032 | r.packageInfo = getPackageInfo(aInfo.applicationInfo, r.compatInfo, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2033 | Context.CONTEXT_INCLUDE_CODE); |
| 2034 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2035 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2036 | ComponentName component = r.intent.getComponent(); |
| 2037 | if (component == null) { |
| 2038 | component = r.intent.resolveActivity( |
| 2039 | mInitialApplication.getPackageManager()); |
| 2040 | r.intent.setComponent(component); |
| 2041 | } |
| 2042 | |
| 2043 | if (r.activityInfo.targetActivity != null) { |
| 2044 | component = new ComponentName(r.activityInfo.packageName, |
| 2045 | r.activityInfo.targetActivity); |
| 2046 | } |
| 2047 | |
| 2048 | Activity activity = null; |
| 2049 | try { |
| 2050 | java.lang.ClassLoader cl = r.packageInfo.getClassLoader(); |
| 2051 | activity = mInstrumentation.newActivity( |
| 2052 | cl, component.getClassName(), r.intent); |
Brad Fitzpatrick | 5f8b5c1 | 2011-01-20 15:12:08 -0800 | [diff] [blame] | 2053 | StrictMode.incrementExpectedActivityCount(activity.getClass()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2054 | r.intent.setExtrasClassLoader(cl); |
| 2055 | if (r.state != null) { |
| 2056 | r.state.setClassLoader(cl); |
| 2057 | } |
| 2058 | } catch (Exception e) { |
| 2059 | if (!mInstrumentation.onException(activity, e)) { |
| 2060 | throw new RuntimeException( |
| 2061 | "Unable to instantiate activity " + component |
| 2062 | + ": " + e.toString(), e); |
| 2063 | } |
| 2064 | } |
| 2065 | |
| 2066 | try { |
Dianne Hackborn | 0be1f78 | 2009-11-09 12:30:12 -0800 | [diff] [blame] | 2067 | Application app = r.packageInfo.makeApplication(false, mInstrumentation); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2068 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2069 | if (localLOGV) Slog.v(TAG, "Performing launch of " + r); |
| 2070 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2071 | TAG, r + ": app=" + app |
| 2072 | + ", appName=" + app.getPackageName() |
| 2073 | + ", pkg=" + r.packageInfo.getPackageName() |
| 2074 | + ", comp=" + r.intent.getComponent().toShortString() |
| 2075 | + ", dir=" + r.packageInfo.getAppDir()); |
| 2076 | |
| 2077 | if (activity != null) { |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 2078 | Context appContext = createBaseContextForActivity(r, activity); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2079 | CharSequence title = r.activityInfo.loadLabel(appContext.getPackageManager()); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 2080 | Configuration config = new Configuration(mCompatConfiguration); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2081 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Launching activity " |
Dianne Hackborn | dc6b635 | 2009-09-30 14:20:09 -0700 | [diff] [blame] | 2082 | + r.activityInfo.name + " with config " + config); |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 2083 | activity.attach(appContext, this, getInstrumentation(), r.token, |
| 2084 | r.ident, app, r.intent, r.activityInfo, title, r.parent, |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 2085 | r.embeddedID, r.lastNonConfigurationInstances, config); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2086 | |
Christopher Tate | b70f3df | 2009-04-07 16:07:59 -0700 | [diff] [blame] | 2087 | if (customIntent != null) { |
| 2088 | activity.mIntent = customIntent; |
| 2089 | } |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 2090 | r.lastNonConfigurationInstances = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2091 | activity.mStartedActivity = false; |
| 2092 | int theme = r.activityInfo.getThemeResource(); |
| 2093 | if (theme != 0) { |
| 2094 | activity.setTheme(theme); |
| 2095 | } |
| 2096 | |
| 2097 | activity.mCalled = false; |
| 2098 | mInstrumentation.callActivityOnCreate(activity, r.state); |
| 2099 | if (!activity.mCalled) { |
| 2100 | throw new SuperNotCalledException( |
| 2101 | "Activity " + r.intent.getComponent().toShortString() + |
| 2102 | " did not call through to super.onCreate()"); |
| 2103 | } |
| 2104 | r.activity = activity; |
| 2105 | r.stopped = true; |
| 2106 | if (!r.activity.mFinished) { |
| 2107 | activity.performStart(); |
| 2108 | r.stopped = false; |
| 2109 | } |
| 2110 | if (!r.activity.mFinished) { |
| 2111 | if (r.state != null) { |
| 2112 | mInstrumentation.callActivityOnRestoreInstanceState(activity, r.state); |
| 2113 | } |
| 2114 | } |
| 2115 | if (!r.activity.mFinished) { |
| 2116 | activity.mCalled = false; |
| 2117 | mInstrumentation.callActivityOnPostCreate(activity, r.state); |
| 2118 | if (!activity.mCalled) { |
| 2119 | throw new SuperNotCalledException( |
| 2120 | "Activity " + r.intent.getComponent().toShortString() + |
| 2121 | " did not call through to super.onPostCreate()"); |
| 2122 | } |
| 2123 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2124 | } |
| 2125 | r.paused = true; |
| 2126 | |
| 2127 | mActivities.put(r.token, r); |
| 2128 | |
| 2129 | } catch (SuperNotCalledException e) { |
| 2130 | throw e; |
| 2131 | |
| 2132 | } catch (Exception e) { |
| 2133 | if (!mInstrumentation.onException(activity, e)) { |
| 2134 | throw new RuntimeException( |
| 2135 | "Unable to start activity " + component |
| 2136 | + ": " + e.toString(), e); |
| 2137 | } |
| 2138 | } |
| 2139 | |
| 2140 | return activity; |
| 2141 | } |
| 2142 | |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 2143 | private Context createBaseContextForActivity(ActivityClientRecord r, |
| 2144 | final Activity activity) { |
| 2145 | ContextImpl appContext = new ContextImpl(); |
| 2146 | appContext.init(r.packageInfo, r.token, this); |
| 2147 | appContext.setOuterContext(activity); |
| 2148 | |
| 2149 | // For debugging purposes, if the activity's package name contains the value of |
| 2150 | // the "debug.use-second-display" system property as a substring, then show |
| 2151 | // its content on a secondary display if there is one. |
| 2152 | Context baseContext = appContext; |
| 2153 | String pkgName = SystemProperties.get("debug.second-display.pkg"); |
| 2154 | if (pkgName != null && !pkgName.isEmpty() |
| 2155 | && r.packageInfo.mPackageName.contains(pkgName)) { |
| 2156 | DisplayManagerGlobal dm = DisplayManagerGlobal.getInstance(); |
| 2157 | for (int displayId : dm.getDisplayIds()) { |
| 2158 | if (displayId != Display.DEFAULT_DISPLAY) { |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 2159 | Display display = dm.getRealDisplay(displayId, r.token); |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 2160 | baseContext = appContext.createDisplayContext(display); |
| 2161 | break; |
| 2162 | } |
| 2163 | } |
| 2164 | } |
| 2165 | return baseContext; |
| 2166 | } |
| 2167 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 2168 | private void handleLaunchActivity(ActivityClientRecord r, Intent customIntent) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2169 | // If we are getting ready to gc after going to the background, well |
| 2170 | // we are back active so skip it. |
| 2171 | unscheduleGcIdler(); |
| 2172 | |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 2173 | if (r.profileFd != null) { |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 2174 | mProfiler.setProfiler(r.profileFile, r.profileFd); |
| 2175 | mProfiler.startProfiling(); |
| 2176 | mProfiler.autoStopProfiler = r.autoStopProfiler; |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 2177 | } |
| 2178 | |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 2179 | // Make sure we are running with the most recent config. |
| 2180 | handleConfigurationChanged(null, null); |
| 2181 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2182 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2183 | TAG, "Handling launch of " + r); |
Christopher Tate | b70f3df | 2009-04-07 16:07:59 -0700 | [diff] [blame] | 2184 | Activity a = performLaunchActivity(r, customIntent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2185 | |
| 2186 | if (a != null) { |
Dianne Hackborn | 871ecdc | 2009-12-11 15:24:33 -0800 | [diff] [blame] | 2187 | r.createdConfig = new Configuration(mConfiguration); |
Dianne Hackborn | 9e0f5d9 | 2010-02-22 15:05:42 -0800 | [diff] [blame] | 2188 | Bundle oldState = r.state; |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 2189 | handleResumeActivity(r.token, false, r.isForward, |
| 2190 | !r.activity.mFinished && !r.startsNotResumed); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2191 | |
| 2192 | if (!r.activity.mFinished && r.startsNotResumed) { |
| 2193 | // The activity manager actually wants this one to start out |
| 2194 | // paused, because it needs to be visible but isn't in the |
| 2195 | // foreground. We accomplish this by going through the |
| 2196 | // normal startup (because activities expect to go through |
| 2197 | // onResume() the first time they run, before their window |
| 2198 | // is displayed), and then pausing it. However, in this case |
| 2199 | // we do -not- need to do the full pause cycle (of freezing |
| 2200 | // and such) because the activity manager assumes it can just |
| 2201 | // retain the current state it has. |
| 2202 | try { |
| 2203 | r.activity.mCalled = false; |
| 2204 | mInstrumentation.callActivityOnPause(r.activity); |
Dianne Hackborn | 9e0f5d9 | 2010-02-22 15:05:42 -0800 | [diff] [blame] | 2205 | // We need to keep around the original state, in case |
Dianne Hackborn | 03fcc33 | 2012-05-15 12:49:40 -0700 | [diff] [blame] | 2206 | // we need to be created again. But we only do this |
| 2207 | // for pre-Honeycomb apps, which always save their state |
| 2208 | // when pausing, so we can not have them save their state |
| 2209 | // when restarting from a paused state. For HC and later, |
| 2210 | // we want to (and can) let the state be saved as the normal |
| 2211 | // part of stopping the activity. |
| 2212 | if (r.isPreHoneycomb()) { |
| 2213 | r.state = oldState; |
| 2214 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2215 | if (!r.activity.mCalled) { |
| 2216 | throw new SuperNotCalledException( |
| 2217 | "Activity " + r.intent.getComponent().toShortString() + |
| 2218 | " did not call through to super.onPause()"); |
| 2219 | } |
| 2220 | |
| 2221 | } catch (SuperNotCalledException e) { |
| 2222 | throw e; |
| 2223 | |
| 2224 | } catch (Exception e) { |
| 2225 | if (!mInstrumentation.onException(r.activity, e)) { |
| 2226 | throw new RuntimeException( |
| 2227 | "Unable to pause activity " |
| 2228 | + r.intent.getComponent().toShortString() |
| 2229 | + ": " + e.toString(), e); |
| 2230 | } |
| 2231 | } |
| 2232 | r.paused = true; |
| 2233 | } |
| 2234 | } else { |
| 2235 | // If there was an error, for any reason, tell the activity |
| 2236 | // manager to stop us. |
| 2237 | try { |
| 2238 | ActivityManagerNative.getDefault() |
| 2239 | .finishActivity(r.token, Activity.RESULT_CANCELED, null); |
| 2240 | } catch (RemoteException ex) { |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 2241 | // Ignore |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2242 | } |
| 2243 | } |
| 2244 | } |
| 2245 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 2246 | private void deliverNewIntents(ActivityClientRecord r, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2247 | List<Intent> intents) { |
| 2248 | final int N = intents.size(); |
| 2249 | for (int i=0; i<N; i++) { |
| 2250 | Intent intent = intents.get(i); |
| 2251 | intent.setExtrasClassLoader(r.activity.getClassLoader()); |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 2252 | r.activity.mFragments.noteStateNotSaved(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2253 | mInstrumentation.callActivityOnNewIntent(r.activity, intent); |
| 2254 | } |
| 2255 | } |
| 2256 | |
| 2257 | public final void performNewIntents(IBinder token, |
| 2258 | List<Intent> intents) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2259 | ActivityClientRecord r = mActivities.get(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2260 | if (r != null) { |
| 2261 | final boolean resumed = !r.paused; |
| 2262 | if (resumed) { |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 2263 | r.activity.mTemporaryPause = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2264 | mInstrumentation.callActivityOnPause(r.activity); |
| 2265 | } |
| 2266 | deliverNewIntents(r, intents); |
| 2267 | if (resumed) { |
Dianne Hackborn | b46ed76 | 2011-06-02 18:33:15 -0700 | [diff] [blame] | 2268 | r.activity.performResume(); |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 2269 | r.activity.mTemporaryPause = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2270 | } |
| 2271 | } |
| 2272 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2273 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 2274 | private void handleNewIntent(NewIntentData data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2275 | performNewIntents(data.token, data.intents); |
| 2276 | } |
| 2277 | |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 2278 | public void handleRequestActivityExtras(RequestActivityExtras cmd) { |
| 2279 | Bundle data = new Bundle(); |
| 2280 | ActivityClientRecord r = mActivities.get(cmd.activityToken); |
| 2281 | if (r != null) { |
| 2282 | r.activity.getApplication().dispatchOnProvideAssistData(r.activity, data); |
| 2283 | r.activity.onProvideAssistData(data); |
| 2284 | } |
| 2285 | if (data.isEmpty()) { |
| 2286 | data = null; |
| 2287 | } |
| 2288 | IActivityManager mgr = ActivityManagerNative.getDefault(); |
| 2289 | try { |
| 2290 | mgr.reportTopActivityExtras(cmd.requestToken, data); |
| 2291 | } catch (RemoteException e) { |
| 2292 | } |
| 2293 | } |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 2294 | |
| 2295 | public void handleTranslucentConversionComplete(IBinder token, boolean drawComplete) { |
| 2296 | ActivityClientRecord r = mActivities.get(token); |
| 2297 | if (r != null) { |
| 2298 | r.activity.onTranslucentConversionComplete(drawComplete); |
| 2299 | } |
| 2300 | } |
| 2301 | |
Brad Fitzpatrick | bfb1919 | 2010-10-29 15:25:44 -0700 | [diff] [blame] | 2302 | private static final ThreadLocal<Intent> sCurrentBroadcastIntent = new ThreadLocal<Intent>(); |
| 2303 | |
| 2304 | /** |
| 2305 | * Return the Intent that's currently being handled by a |
| 2306 | * BroadcastReceiver on this thread, or null if none. |
| 2307 | * @hide |
| 2308 | */ |
| 2309 | public static Intent getIntentBeingBroadcast() { |
| 2310 | return sCurrentBroadcastIntent.get(); |
| 2311 | } |
| 2312 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 2313 | private void handleReceiver(ReceiverData data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2314 | // If we are getting ready to gc after going to the background, well |
| 2315 | // we are back active so skip it. |
| 2316 | unscheduleGcIdler(); |
| 2317 | |
| 2318 | String component = data.intent.getComponent().getClassName(); |
| 2319 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2320 | LoadedApk packageInfo = getPackageInfoNoCheck( |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2321 | data.info.applicationInfo, data.compatInfo); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2322 | |
| 2323 | IActivityManager mgr = ActivityManagerNative.getDefault(); |
| 2324 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 2325 | BroadcastReceiver receiver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2326 | try { |
| 2327 | java.lang.ClassLoader cl = packageInfo.getClassLoader(); |
| 2328 | data.intent.setExtrasClassLoader(cl); |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 2329 | data.setExtrasClassLoader(cl); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2330 | receiver = (BroadcastReceiver)cl.loadClass(component).newInstance(); |
| 2331 | } catch (Exception e) { |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 2332 | if (DEBUG_BROADCAST) Slog.i(TAG, |
| 2333 | "Finishing failed broadcast to " + data.intent.getComponent()); |
| 2334 | data.sendFinished(mgr); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2335 | throw new RuntimeException( |
| 2336 | "Unable to instantiate receiver " + component |
| 2337 | + ": " + e.toString(), e); |
| 2338 | } |
| 2339 | |
| 2340 | try { |
Dianne Hackborn | 0be1f78 | 2009-11-09 12:30:12 -0800 | [diff] [blame] | 2341 | Application app = packageInfo.makeApplication(false, mInstrumentation); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2342 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2343 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2344 | TAG, "Performing receive of " + data.intent |
| 2345 | + ": app=" + app |
| 2346 | + ", appName=" + app.getPackageName() |
| 2347 | + ", pkg=" + packageInfo.getPackageName() |
| 2348 | + ", comp=" + data.intent.getComponent().toShortString() |
| 2349 | + ", dir=" + packageInfo.getAppDir()); |
| 2350 | |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 2351 | ContextImpl context = (ContextImpl)app.getBaseContext(); |
Brad Fitzpatrick | bfb1919 | 2010-10-29 15:25:44 -0700 | [diff] [blame] | 2352 | sCurrentBroadcastIntent.set(data.intent); |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 2353 | receiver.setPendingResult(data); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2354 | receiver.onReceive(context.getReceiverRestrictedContext(), |
| 2355 | data.intent); |
| 2356 | } catch (Exception e) { |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 2357 | if (DEBUG_BROADCAST) Slog.i(TAG, |
| 2358 | "Finishing failed broadcast to " + data.intent.getComponent()); |
| 2359 | data.sendFinished(mgr); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2360 | if (!mInstrumentation.onException(receiver, e)) { |
| 2361 | throw new RuntimeException( |
| 2362 | "Unable to start receiver " + component |
| 2363 | + ": " + e.toString(), e); |
| 2364 | } |
Brad Fitzpatrick | bfb1919 | 2010-10-29 15:25:44 -0700 | [diff] [blame] | 2365 | } finally { |
| 2366 | sCurrentBroadcastIntent.set(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2367 | } |
| 2368 | |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 2369 | if (receiver.getPendingResult() != null) { |
| 2370 | data.finish(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2371 | } |
| 2372 | } |
| 2373 | |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 2374 | // Instantiate a BackupAgent and tell it that it's alive |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 2375 | private void handleCreateBackupAgent(CreateBackupAgentData data) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2376 | if (DEBUG_BACKUP) Slog.v(TAG, "handleCreateBackupAgent: " + data); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 2377 | |
Christopher Tate | 346acb1 | 2012-10-15 19:20:25 -0700 | [diff] [blame] | 2378 | // Sanity check the requested target package's uid against ours |
| 2379 | try { |
| 2380 | PackageInfo requestedPackage = getPackageManager().getPackageInfo( |
| 2381 | data.appInfo.packageName, 0, UserHandle.myUserId()); |
| 2382 | if (requestedPackage.applicationInfo.uid != Process.myUid()) { |
| 2383 | Slog.w(TAG, "Asked to instantiate non-matching package " |
| 2384 | + data.appInfo.packageName); |
| 2385 | return; |
| 2386 | } |
| 2387 | } catch (RemoteException e) { |
| 2388 | Slog.e(TAG, "Can't reach package manager", e); |
| 2389 | return; |
| 2390 | } |
| 2391 | |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 2392 | // no longer idle; we have backup work to do |
| 2393 | unscheduleGcIdler(); |
| 2394 | |
| 2395 | // instantiate the BackupAgent class named in the manifest |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2396 | LoadedApk packageInfo = getPackageInfoNoCheck(data.appInfo, data.compatInfo); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 2397 | String packageName = packageInfo.mPackageName; |
Christopher Tate | 346acb1 | 2012-10-15 19:20:25 -0700 | [diff] [blame] | 2398 | if (packageName == null) { |
| 2399 | Slog.d(TAG, "Asked to create backup agent for nonexistent package"); |
| 2400 | return; |
| 2401 | } |
| 2402 | |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 2403 | if (mBackupAgents.get(packageName) != null) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2404 | Slog.d(TAG, "BackupAgent " + " for " + packageName |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 2405 | + " already exists"); |
| 2406 | return; |
| 2407 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2408 | |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 2409 | BackupAgent agent = null; |
| 2410 | String classname = data.appInfo.backupAgentName; |
Christopher Tate | 4a627c7 | 2011-04-01 14:43:32 -0700 | [diff] [blame] | 2411 | |
Christopher Tate | 79ec80d | 2011-06-24 14:58:49 -0700 | [diff] [blame] | 2412 | // full backup operation but no app-supplied agent? use the default implementation |
| 2413 | if (classname == null && (data.backupMode == IApplicationThread.BACKUP_MODE_FULL |
| 2414 | || data.backupMode == IApplicationThread.BACKUP_MODE_RESTORE_FULL)) { |
Christopher Tate | 4a627c7 | 2011-04-01 14:43:32 -0700 | [diff] [blame] | 2415 | classname = "android.app.backup.FullBackupAgent"; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 2416 | } |
Christopher Tate | 4a627c7 | 2011-04-01 14:43:32 -0700 | [diff] [blame] | 2417 | |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 2418 | try { |
Christopher Tate | d1475e0 | 2009-07-09 15:36:17 -0700 | [diff] [blame] | 2419 | IBinder binder = null; |
| 2420 | try { |
Christopher Tate | 4a627c7 | 2011-04-01 14:43:32 -0700 | [diff] [blame] | 2421 | if (DEBUG_BACKUP) Slog.v(TAG, "Initializing agent class " + classname); |
| 2422 | |
Christopher Tate | d1475e0 | 2009-07-09 15:36:17 -0700 | [diff] [blame] | 2423 | java.lang.ClassLoader cl = packageInfo.getClassLoader(); |
Christopher Tate | 4a627c7 | 2011-04-01 14:43:32 -0700 | [diff] [blame] | 2424 | agent = (BackupAgent) cl.loadClass(classname).newInstance(); |
Christopher Tate | d1475e0 | 2009-07-09 15:36:17 -0700 | [diff] [blame] | 2425 | |
| 2426 | // set up the agent's context |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 2427 | ContextImpl context = new ContextImpl(); |
Christopher Tate | d1475e0 | 2009-07-09 15:36:17 -0700 | [diff] [blame] | 2428 | context.init(packageInfo, null, this); |
| 2429 | context.setOuterContext(agent); |
| 2430 | agent.attach(context); |
| 2431 | |
| 2432 | agent.onCreate(); |
| 2433 | binder = agent.onBind(); |
| 2434 | mBackupAgents.put(packageName, agent); |
| 2435 | } catch (Exception e) { |
| 2436 | // If this is during restore, fail silently; otherwise go |
| 2437 | // ahead and let the user see the crash. |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 2438 | Slog.e(TAG, "Agent threw during creation: " + e); |
Christopher Tate | 75a9970 | 2011-05-18 16:28:19 -0700 | [diff] [blame] | 2439 | if (data.backupMode != IApplicationThread.BACKUP_MODE_RESTORE |
| 2440 | && data.backupMode != IApplicationThread.BACKUP_MODE_RESTORE_FULL) { |
Christopher Tate | d1475e0 | 2009-07-09 15:36:17 -0700 | [diff] [blame] | 2441 | throw e; |
| 2442 | } |
| 2443 | // falling through with 'binder' still null |
| 2444 | } |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 2445 | |
| 2446 | // tell the OS that we're live now |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 2447 | try { |
| 2448 | ActivityManagerNative.getDefault().backupAgentCreated(packageName, binder); |
| 2449 | } catch (RemoteException e) { |
| 2450 | // nothing to do. |
| 2451 | } |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 2452 | } catch (Exception e) { |
| 2453 | throw new RuntimeException("Unable to create BackupAgent " |
Christopher Tate | 4a627c7 | 2011-04-01 14:43:32 -0700 | [diff] [blame] | 2454 | + classname + ": " + e.toString(), e); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 2455 | } |
| 2456 | } |
| 2457 | |
| 2458 | // Tear down a BackupAgent |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 2459 | private void handleDestroyBackupAgent(CreateBackupAgentData data) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2460 | if (DEBUG_BACKUP) Slog.v(TAG, "handleDestroyBackupAgent: " + data); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2461 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2462 | LoadedApk packageInfo = getPackageInfoNoCheck(data.appInfo, data.compatInfo); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 2463 | String packageName = packageInfo.mPackageName; |
| 2464 | BackupAgent agent = mBackupAgents.get(packageName); |
| 2465 | if (agent != null) { |
| 2466 | try { |
| 2467 | agent.onDestroy(); |
| 2468 | } catch (Exception e) { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 2469 | Slog.w(TAG, "Exception thrown in onDestroy by backup agent of " + data.appInfo); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 2470 | e.printStackTrace(); |
| 2471 | } |
| 2472 | mBackupAgents.remove(packageName); |
| 2473 | } else { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 2474 | Slog.w(TAG, "Attempt to destroy unknown backup agent " + data); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 2475 | } |
| 2476 | } |
| 2477 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 2478 | private void handleCreateService(CreateServiceData data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2479 | // If we are getting ready to gc after going to the background, well |
| 2480 | // we are back active so skip it. |
| 2481 | unscheduleGcIdler(); |
| 2482 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2483 | LoadedApk packageInfo = getPackageInfoNoCheck( |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2484 | data.info.applicationInfo, data.compatInfo); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2485 | Service service = null; |
| 2486 | try { |
| 2487 | java.lang.ClassLoader cl = packageInfo.getClassLoader(); |
| 2488 | service = (Service) cl.loadClass(data.info.name).newInstance(); |
| 2489 | } catch (Exception e) { |
| 2490 | if (!mInstrumentation.onException(service, e)) { |
| 2491 | throw new RuntimeException( |
| 2492 | "Unable to instantiate service " + data.info.name |
| 2493 | + ": " + e.toString(), e); |
| 2494 | } |
| 2495 | } |
| 2496 | |
| 2497 | try { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2498 | if (localLOGV) Slog.v(TAG, "Creating service " + data.info.name); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2499 | |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 2500 | ContextImpl context = new ContextImpl(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2501 | context.init(packageInfo, null, this); |
| 2502 | |
Dianne Hackborn | 0be1f78 | 2009-11-09 12:30:12 -0800 | [diff] [blame] | 2503 | Application app = packageInfo.makeApplication(false, mInstrumentation); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2504 | context.setOuterContext(service); |
| 2505 | service.attach(context, this, data.info.name, data.token, app, |
| 2506 | ActivityManagerNative.getDefault()); |
| 2507 | service.onCreate(); |
| 2508 | mServices.put(data.token, service); |
| 2509 | try { |
Dianne Hackborn | f6f9f2d | 2009-08-21 16:26:03 -0700 | [diff] [blame] | 2510 | ActivityManagerNative.getDefault().serviceDoneExecuting( |
| 2511 | data.token, 0, 0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2512 | } catch (RemoteException e) { |
| 2513 | // nothing to do. |
| 2514 | } |
| 2515 | } catch (Exception e) { |
| 2516 | if (!mInstrumentation.onException(service, e)) { |
| 2517 | throw new RuntimeException( |
| 2518 | "Unable to create service " + data.info.name |
| 2519 | + ": " + e.toString(), e); |
| 2520 | } |
| 2521 | } |
| 2522 | } |
| 2523 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 2524 | private void handleBindService(BindServiceData data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2525 | Service s = mServices.get(data.token); |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 2526 | if (DEBUG_SERVICE) |
| 2527 | Slog.v(TAG, "handleBindService s=" + s + " rebind=" + data.rebind); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2528 | if (s != null) { |
| 2529 | try { |
| 2530 | data.intent.setExtrasClassLoader(s.getClassLoader()); |
| 2531 | try { |
| 2532 | if (!data.rebind) { |
| 2533 | IBinder binder = s.onBind(data.intent); |
| 2534 | ActivityManagerNative.getDefault().publishService( |
| 2535 | data.token, data.intent, binder); |
| 2536 | } else { |
| 2537 | s.onRebind(data.intent); |
| 2538 | ActivityManagerNative.getDefault().serviceDoneExecuting( |
Dianne Hackborn | f6f9f2d | 2009-08-21 16:26:03 -0700 | [diff] [blame] | 2539 | data.token, 0, 0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2540 | } |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 2541 | ensureJitEnabled(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2542 | } catch (RemoteException ex) { |
| 2543 | } |
| 2544 | } catch (Exception e) { |
| 2545 | if (!mInstrumentation.onException(s, e)) { |
| 2546 | throw new RuntimeException( |
| 2547 | "Unable to bind to service " + s |
| 2548 | + " with " + data.intent + ": " + e.toString(), e); |
| 2549 | } |
| 2550 | } |
| 2551 | } |
| 2552 | } |
| 2553 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 2554 | private void handleUnbindService(BindServiceData data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2555 | Service s = mServices.get(data.token); |
| 2556 | if (s != null) { |
| 2557 | try { |
| 2558 | data.intent.setExtrasClassLoader(s.getClassLoader()); |
| 2559 | boolean doRebind = s.onUnbind(data.intent); |
| 2560 | try { |
| 2561 | if (doRebind) { |
| 2562 | ActivityManagerNative.getDefault().unbindFinished( |
| 2563 | data.token, data.intent, doRebind); |
| 2564 | } else { |
| 2565 | ActivityManagerNative.getDefault().serviceDoneExecuting( |
Dianne Hackborn | f6f9f2d | 2009-08-21 16:26:03 -0700 | [diff] [blame] | 2566 | data.token, 0, 0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2567 | } |
| 2568 | } catch (RemoteException ex) { |
| 2569 | } |
| 2570 | } catch (Exception e) { |
| 2571 | if (!mInstrumentation.onException(s, e)) { |
| 2572 | throw new RuntimeException( |
| 2573 | "Unable to unbind to service " + s |
| 2574 | + " with " + data.intent + ": " + e.toString(), e); |
| 2575 | } |
| 2576 | } |
| 2577 | } |
| 2578 | } |
| 2579 | |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 2580 | private void handleDumpService(DumpComponentInfo info) { |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 2581 | final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); |
| 2582 | try { |
| 2583 | Service s = mServices.get(info.token); |
| 2584 | if (s != null) { |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 2585 | PrintWriter pw = new FastPrintWriter(new FileOutputStream( |
| 2586 | info.fd.getFileDescriptor())); |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 2587 | s.dump(info.fd.getFileDescriptor(), pw, info.args); |
| 2588 | pw.flush(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2589 | } |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 2590 | } finally { |
| 2591 | IoUtils.closeQuietly(info.fd); |
| 2592 | StrictMode.setThreadPolicy(oldPolicy); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2593 | } |
| 2594 | } |
| 2595 | |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 2596 | private void handleDumpActivity(DumpComponentInfo info) { |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 2597 | final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); |
| 2598 | try { |
| 2599 | ActivityClientRecord r = mActivities.get(info.token); |
| 2600 | if (r != null && r.activity != null) { |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 2601 | PrintWriter pw = new FastPrintWriter(new FileOutputStream( |
| 2602 | info.fd.getFileDescriptor())); |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 2603 | r.activity.dump(info.prefix, info.fd.getFileDescriptor(), pw, info.args); |
| 2604 | pw.flush(); |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 2605 | } |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 2606 | } finally { |
| 2607 | IoUtils.closeQuietly(info.fd); |
| 2608 | StrictMode.setThreadPolicy(oldPolicy); |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 2609 | } |
| 2610 | } |
| 2611 | |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 2612 | private void handleDumpProvider(DumpComponentInfo info) { |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 2613 | final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); |
| 2614 | try { |
| 2615 | ProviderClientRecord r = mLocalProviders.get(info.token); |
| 2616 | if (r != null && r.mLocalProvider != null) { |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 2617 | PrintWriter pw = new FastPrintWriter(new FileOutputStream( |
| 2618 | info.fd.getFileDescriptor())); |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 2619 | r.mLocalProvider.dump(info.fd.getFileDescriptor(), pw, info.args); |
| 2620 | pw.flush(); |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 2621 | } |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 2622 | } finally { |
| 2623 | IoUtils.closeQuietly(info.fd); |
| 2624 | StrictMode.setThreadPolicy(oldPolicy); |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 2625 | } |
| 2626 | } |
| 2627 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 2628 | private void handleServiceArgs(ServiceArgsData data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2629 | Service s = mServices.get(data.token); |
| 2630 | if (s != null) { |
| 2631 | try { |
| 2632 | if (data.args != null) { |
| 2633 | data.args.setExtrasClassLoader(s.getClassLoader()); |
| 2634 | } |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 2635 | int res; |
| 2636 | if (!data.taskRemoved) { |
| 2637 | res = s.onStartCommand(data.args, data.flags, data.startId); |
| 2638 | } else { |
| 2639 | s.onTaskRemoved(data.args); |
| 2640 | res = Service.START_TASK_REMOVED_COMPLETE; |
| 2641 | } |
Brad Fitzpatrick | 333b8cb | 2010-08-26 12:04:57 -0700 | [diff] [blame] | 2642 | |
| 2643 | QueuedWork.waitToFinish(); |
| 2644 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2645 | try { |
Dianne Hackborn | f6f9f2d | 2009-08-21 16:26:03 -0700 | [diff] [blame] | 2646 | ActivityManagerNative.getDefault().serviceDoneExecuting( |
| 2647 | data.token, 1, data.startId, res); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2648 | } catch (RemoteException e) { |
| 2649 | // nothing to do. |
| 2650 | } |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 2651 | ensureJitEnabled(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2652 | } catch (Exception e) { |
| 2653 | if (!mInstrumentation.onException(s, e)) { |
| 2654 | throw new RuntimeException( |
| 2655 | "Unable to start service " + s |
| 2656 | + " with " + data.args + ": " + e.toString(), e); |
| 2657 | } |
| 2658 | } |
| 2659 | } |
| 2660 | } |
| 2661 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 2662 | private void handleStopService(IBinder token) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2663 | Service s = mServices.remove(token); |
| 2664 | if (s != null) { |
| 2665 | try { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2666 | if (localLOGV) Slog.v(TAG, "Destroying service " + s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2667 | s.onDestroy(); |
| 2668 | Context context = s.getBaseContext(); |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 2669 | if (context instanceof ContextImpl) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2670 | final String who = s.getClassName(); |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 2671 | ((ContextImpl) context).scheduleFinalCleanup(who, "Service"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2672 | } |
Brad Fitzpatrick | 333b8cb | 2010-08-26 12:04:57 -0700 | [diff] [blame] | 2673 | |
| 2674 | QueuedWork.waitToFinish(); |
| 2675 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2676 | try { |
Dianne Hackborn | f6f9f2d | 2009-08-21 16:26:03 -0700 | [diff] [blame] | 2677 | ActivityManagerNative.getDefault().serviceDoneExecuting( |
| 2678 | token, 0, 0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2679 | } catch (RemoteException e) { |
| 2680 | // nothing to do. |
| 2681 | } |
| 2682 | } catch (Exception e) { |
| 2683 | if (!mInstrumentation.onException(s, e)) { |
| 2684 | throw new RuntimeException( |
| 2685 | "Unable to stop service " + s |
| 2686 | + ": " + e.toString(), e); |
| 2687 | } |
| 2688 | } |
| 2689 | } |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2690 | //Slog.i(TAG, "Running services: " + mServices); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2691 | } |
| 2692 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2693 | public final ActivityClientRecord performResumeActivity(IBinder token, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2694 | boolean clearHide) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2695 | ActivityClientRecord r = mActivities.get(token); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2696 | if (localLOGV) Slog.v(TAG, "Performing resume of " + r |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2697 | + " finished=" + r.activity.mFinished); |
| 2698 | if (r != null && !r.activity.mFinished) { |
| 2699 | if (clearHide) { |
| 2700 | r.hideForNow = false; |
| 2701 | r.activity.mStartedActivity = false; |
| 2702 | } |
| 2703 | try { |
Dianne Hackborn | 689586d | 2012-10-01 18:23:04 -0700 | [diff] [blame] | 2704 | r.activity.mFragments.noteStateNotSaved(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2705 | if (r.pendingIntents != null) { |
| 2706 | deliverNewIntents(r, r.pendingIntents); |
| 2707 | r.pendingIntents = null; |
| 2708 | } |
| 2709 | if (r.pendingResults != null) { |
| 2710 | deliverResults(r, r.pendingResults); |
| 2711 | r.pendingResults = null; |
| 2712 | } |
| 2713 | r.activity.performResume(); |
| 2714 | |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2715 | EventLog.writeEvent(LOG_ON_RESUME_CALLED, |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 2716 | UserHandle.myUserId(), r.activity.getComponentName().getClassName()); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2717 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2718 | r.paused = false; |
| 2719 | r.stopped = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2720 | r.state = null; |
| 2721 | } catch (Exception e) { |
| 2722 | if (!mInstrumentation.onException(r.activity, e)) { |
| 2723 | throw new RuntimeException( |
| 2724 | "Unable to resume activity " |
| 2725 | + r.intent.getComponent().toShortString() |
| 2726 | + ": " + e.toString(), e); |
| 2727 | } |
| 2728 | } |
| 2729 | } |
| 2730 | return r; |
| 2731 | } |
| 2732 | |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 2733 | static final void cleanUpPendingRemoveWindows(ActivityClientRecord r) { |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 2734 | if (r.mPendingRemoveWindow != null) { |
| 2735 | r.mPendingRemoveWindowManager.removeViewImmediate(r.mPendingRemoveWindow); |
| 2736 | IBinder wtoken = r.mPendingRemoveWindow.getWindowToken(); |
| 2737 | if (wtoken != null) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2738 | WindowManagerGlobal.getInstance().closeAll(wtoken, |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 2739 | r.activity.getClass().getName(), "Activity"); |
| 2740 | } |
| 2741 | } |
| 2742 | r.mPendingRemoveWindow = null; |
| 2743 | r.mPendingRemoveWindowManager = null; |
| 2744 | } |
| 2745 | |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 2746 | final void handleResumeActivity(IBinder token, boolean clearHide, boolean isForward, |
| 2747 | boolean reallyResume) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2748 | // If we are getting ready to gc after going to the background, well |
| 2749 | // we are back active so skip it. |
| 2750 | unscheduleGcIdler(); |
| 2751 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2752 | ActivityClientRecord r = performResumeActivity(token, clearHide); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2753 | |
| 2754 | if (r != null) { |
| 2755 | final Activity a = r.activity; |
| 2756 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2757 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2758 | TAG, "Resume " + r + " started activity: " + |
| 2759 | a.mStartedActivity + ", hideForNow: " + r.hideForNow |
| 2760 | + ", finished: " + a.mFinished); |
| 2761 | |
| 2762 | final int forwardBit = isForward ? |
| 2763 | WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION : 0; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2764 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2765 | // If the window hasn't yet been added to the window manager, |
| 2766 | // and this guy didn't finish itself or start another activity, |
| 2767 | // then go ahead and add the window. |
Dianne Hackborn | 061d58a | 2010-03-12 15:07:06 -0800 | [diff] [blame] | 2768 | boolean willBeVisible = !a.mStartedActivity; |
| 2769 | if (!willBeVisible) { |
| 2770 | try { |
| 2771 | willBeVisible = ActivityManagerNative.getDefault().willActivityBeVisible( |
| 2772 | a.getActivityToken()); |
| 2773 | } catch (RemoteException e) { |
| 2774 | } |
| 2775 | } |
| 2776 | if (r.window == null && !a.mFinished && willBeVisible) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2777 | r.window = r.activity.getWindow(); |
| 2778 | View decor = r.window.getDecorView(); |
| 2779 | decor.setVisibility(View.INVISIBLE); |
| 2780 | ViewManager wm = a.getWindowManager(); |
| 2781 | WindowManager.LayoutParams l = r.window.getAttributes(); |
| 2782 | a.mDecor = decor; |
| 2783 | l.type = WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
| 2784 | l.softInputMode |= forwardBit; |
| 2785 | if (a.mVisibleFromClient) { |
| 2786 | a.mWindowAdded = true; |
| 2787 | wm.addView(decor, l); |
| 2788 | } |
| 2789 | |
| 2790 | // If the window has already been added, but during resume |
| 2791 | // we started another activity, then don't yet make the |
Dianne Hackborn | 061d58a | 2010-03-12 15:07:06 -0800 | [diff] [blame] | 2792 | // window visible. |
| 2793 | } else if (!willBeVisible) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2794 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2795 | TAG, "Launch " + r + " mStartedActivity set"); |
| 2796 | r.hideForNow = true; |
| 2797 | } |
| 2798 | |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 2799 | // Get rid of anything left hanging around. |
| 2800 | cleanUpPendingRemoveWindows(r); |
| 2801 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2802 | // The window is now visible if it has been added, we are not |
| 2803 | // simply finishing, and we are not starting another activity. |
Dianne Hackborn | 061d58a | 2010-03-12 15:07:06 -0800 | [diff] [blame] | 2804 | if (!r.activity.mFinished && willBeVisible |
Dianne Hackborn | c1e605e | 2009-09-25 17:18:15 -0700 | [diff] [blame] | 2805 | && r.activity.mDecor != null && !r.hideForNow) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2806 | if (r.newConfig != null) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2807 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Resuming activity " |
Dianne Hackborn | dc6b635 | 2009-09-30 14:20:09 -0700 | [diff] [blame] | 2808 | + r.activityInfo.name + " with newConfig " + r.newConfig); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2809 | performConfigurationChanged(r.activity, r.newConfig); |
Fabrice Di Meglio | 30ca5cd | 2012-05-07 17:45:44 -0700 | [diff] [blame] | 2810 | freeTextLayoutCachesIfNeeded(r.activity.mCurrentConfig.diff(r.newConfig)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2811 | r.newConfig = null; |
| 2812 | } |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2813 | if (localLOGV) Slog.v(TAG, "Resuming " + r + " with isForward=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2814 | + isForward); |
| 2815 | WindowManager.LayoutParams l = r.window.getAttributes(); |
| 2816 | if ((l.softInputMode |
| 2817 | & WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) |
| 2818 | != forwardBit) { |
| 2819 | l.softInputMode = (l.softInputMode |
| 2820 | & (~WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION)) |
| 2821 | | forwardBit; |
Dianne Hackborn | c1e605e | 2009-09-25 17:18:15 -0700 | [diff] [blame] | 2822 | if (r.activity.mVisibleFromClient) { |
| 2823 | ViewManager wm = a.getWindowManager(); |
| 2824 | View decor = r.window.getDecorView(); |
| 2825 | wm.updateViewLayout(decor, l); |
| 2826 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2827 | } |
| 2828 | r.activity.mVisibleFromServer = true; |
| 2829 | mNumVisibleActivities++; |
| 2830 | if (r.activity.mVisibleFromClient) { |
| 2831 | r.activity.makeVisible(); |
| 2832 | } |
| 2833 | } |
| 2834 | |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 2835 | if (!r.onlyLocalRequest) { |
| 2836 | r.nextIdle = mNewActivities; |
| 2837 | mNewActivities = r; |
| 2838 | if (localLOGV) Slog.v( |
| 2839 | TAG, "Scheduling idle handler for " + r); |
| 2840 | Looper.myQueue().addIdleHandler(new Idler()); |
| 2841 | } |
| 2842 | r.onlyLocalRequest = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2843 | |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 2844 | // Tell the activity manager we have resumed. |
| 2845 | if (reallyResume) { |
| 2846 | try { |
| 2847 | ActivityManagerNative.getDefault().activityResumed(token); |
| 2848 | } catch (RemoteException ex) { |
| 2849 | } |
| 2850 | } |
| 2851 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2852 | } else { |
| 2853 | // If an exception was thrown when trying to resume, then |
| 2854 | // just end this activity. |
| 2855 | try { |
| 2856 | ActivityManagerNative.getDefault() |
| 2857 | .finishActivity(token, Activity.RESULT_CANCELED, null); |
| 2858 | } catch (RemoteException ex) { |
| 2859 | } |
| 2860 | } |
| 2861 | } |
| 2862 | |
| 2863 | private int mThumbnailWidth = -1; |
| 2864 | private int mThumbnailHeight = -1; |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 2865 | private Bitmap mAvailThumbnailBitmap = null; |
| 2866 | private Canvas mThumbnailCanvas = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2867 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 2868 | private Bitmap createThumbnailBitmap(ActivityClientRecord r) { |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 2869 | Bitmap thumbnail = mAvailThumbnailBitmap; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2870 | try { |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 2871 | if (thumbnail == null) { |
| 2872 | int w = mThumbnailWidth; |
| 2873 | int h; |
| 2874 | if (w < 0) { |
| 2875 | Resources res = r.activity.getResources(); |
| 2876 | mThumbnailHeight = h = |
| 2877 | res.getDimensionPixelSize(com.android.internal.R.dimen.thumbnail_height); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2878 | |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 2879 | mThumbnailWidth = w = |
| 2880 | res.getDimensionPixelSize(com.android.internal.R.dimen.thumbnail_width); |
| 2881 | } else { |
| 2882 | h = mThumbnailHeight; |
| 2883 | } |
| 2884 | |
| 2885 | // On platforms where we don't want thumbnails, set dims to (0,0) |
| 2886 | if ((w > 0) && (h > 0)) { |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 2887 | thumbnail = Bitmap.createBitmap(r.activity.getResources().getDisplayMetrics(), |
| 2888 | w, h, THUMBNAIL_FORMAT); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 2889 | thumbnail.eraseColor(0); |
| 2890 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2891 | } |
| 2892 | |
Dianne Hackborn | fb3806d | 2010-12-09 13:14:12 -0800 | [diff] [blame] | 2893 | if (thumbnail != null) { |
| 2894 | Canvas cv = mThumbnailCanvas; |
| 2895 | if (cv == null) { |
| 2896 | mThumbnailCanvas = cv = new Canvas(); |
| 2897 | } |
| 2898 | |
| 2899 | cv.setBitmap(thumbnail); |
| 2900 | if (!r.activity.onCreateThumbnail(thumbnail, cv)) { |
| 2901 | mAvailThumbnailBitmap = thumbnail; |
| 2902 | thumbnail = null; |
| 2903 | } |
Dianne Hackborn | 6311d0a | 2011-08-02 16:37:58 -0700 | [diff] [blame] | 2904 | cv.setBitmap(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2905 | } |
Jim Miller | 0b2a6d0 | 2010-07-13 18:01:29 -0700 | [diff] [blame] | 2906 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2907 | } catch (Exception e) { |
| 2908 | if (!mInstrumentation.onException(r.activity, e)) { |
| 2909 | throw new RuntimeException( |
| 2910 | "Unable to create thumbnail of " |
| 2911 | + r.intent.getComponent().toShortString() |
| 2912 | + ": " + e.toString(), e); |
| 2913 | } |
| 2914 | thumbnail = null; |
| 2915 | } |
| 2916 | |
| 2917 | return thumbnail; |
| 2918 | } |
| 2919 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 2920 | private void handlePauseActivity(IBinder token, boolean finished, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2921 | boolean userLeaving, int configChanges) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2922 | ActivityClientRecord r = mActivities.get(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2923 | if (r != null) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2924 | //Slog.v(TAG, "userLeaving=" + userLeaving + " handling pause of " + r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2925 | if (userLeaving) { |
| 2926 | performUserLeavingActivity(r); |
| 2927 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2928 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2929 | r.activity.mConfigChangeFlags |= configChanges; |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 2930 | performPauseActivity(token, finished, r.isPreHoneycomb()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2931 | |
Dianne Hackborn | aa93bcd | 2010-10-27 13:57:00 -0700 | [diff] [blame] | 2932 | // Make sure any pending writes are now committed. |
Dianne Hackborn | 5d9d03a | 2011-01-24 13:15:09 -0800 | [diff] [blame] | 2933 | if (r.isPreHoneycomb()) { |
| 2934 | QueuedWork.waitToFinish(); |
| 2935 | } |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 2936 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2937 | // Tell the activity manager we have paused. |
| 2938 | try { |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 2939 | ActivityManagerNative.getDefault().activityPaused(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2940 | } catch (RemoteException ex) { |
| 2941 | } |
| 2942 | } |
| 2943 | } |
| 2944 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2945 | final void performUserLeavingActivity(ActivityClientRecord r) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2946 | mInstrumentation.callActivityOnUserLeaving(r.activity); |
| 2947 | } |
| 2948 | |
| 2949 | final Bundle performPauseActivity(IBinder token, boolean finished, |
| 2950 | boolean saveState) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2951 | ActivityClientRecord r = mActivities.get(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2952 | return r != null ? performPauseActivity(r, finished, saveState) : null; |
| 2953 | } |
| 2954 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2955 | final Bundle performPauseActivity(ActivityClientRecord r, boolean finished, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2956 | boolean saveState) { |
| 2957 | if (r.paused) { |
| 2958 | if (r.activity.mFinished) { |
| 2959 | // If we are finishing, we won't call onResume() in certain cases. |
| 2960 | // So here we likewise don't want to call onPause() if the activity |
| 2961 | // isn't resumed. |
| 2962 | return null; |
| 2963 | } |
| 2964 | RuntimeException e = new RuntimeException( |
| 2965 | "Performing pause of activity that is not resumed: " |
| 2966 | + r.intent.getComponent().toShortString()); |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 2967 | Slog.e(TAG, e.getMessage(), e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2968 | } |
| 2969 | Bundle state = null; |
| 2970 | if (finished) { |
| 2971 | r.activity.mFinished = true; |
| 2972 | } |
| 2973 | try { |
| 2974 | // Next have the activity save its current state and managed dialogs... |
| 2975 | if (!r.activity.mFinished && saveState) { |
| 2976 | state = new Bundle(); |
Dianne Hackborn | 9ecebbf | 2011-09-28 23:19:47 -0400 | [diff] [blame] | 2977 | state.setAllowFds(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2978 | mInstrumentation.callActivityOnSaveInstanceState(r.activity, state); |
| 2979 | r.state = state; |
| 2980 | } |
| 2981 | // Now we are idle. |
| 2982 | r.activity.mCalled = false; |
| 2983 | mInstrumentation.callActivityOnPause(r.activity); |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 2984 | EventLog.writeEvent(LOG_ON_PAUSE_CALLED, UserHandle.myUserId(), |
| 2985 | r.activity.getComponentName().getClassName()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2986 | if (!r.activity.mCalled) { |
| 2987 | throw new SuperNotCalledException( |
| 2988 | "Activity " + r.intent.getComponent().toShortString() + |
| 2989 | " did not call through to super.onPause()"); |
| 2990 | } |
| 2991 | |
| 2992 | } catch (SuperNotCalledException e) { |
| 2993 | throw e; |
| 2994 | |
| 2995 | } catch (Exception e) { |
| 2996 | if (!mInstrumentation.onException(r.activity, e)) { |
| 2997 | throw new RuntimeException( |
| 2998 | "Unable to pause activity " |
| 2999 | + r.intent.getComponent().toShortString() |
| 3000 | + ": " + e.toString(), e); |
| 3001 | } |
| 3002 | } |
| 3003 | r.paused = true; |
Jeff Hamilton | 52d3203 | 2011-01-08 15:31:26 -0600 | [diff] [blame] | 3004 | |
| 3005 | // Notify any outstanding on paused listeners |
| 3006 | ArrayList<OnActivityPausedListener> listeners; |
| 3007 | synchronized (mOnPauseListeners) { |
| 3008 | listeners = mOnPauseListeners.remove(r.activity); |
| 3009 | } |
| 3010 | int size = (listeners != null ? listeners.size() : 0); |
| 3011 | for (int i = 0; i < size; i++) { |
| 3012 | listeners.get(i).onPaused(r.activity); |
| 3013 | } |
| 3014 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3015 | return state; |
| 3016 | } |
| 3017 | |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3018 | final void performStopActivity(IBinder token, boolean saveState) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3019 | ActivityClientRecord r = mActivities.get(token); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3020 | performStopActivityInner(r, null, false, saveState); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3021 | } |
| 3022 | |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 3023 | private static class StopInfo implements Runnable { |
| 3024 | ActivityClientRecord activity; |
| 3025 | Bundle state; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3026 | Bitmap thumbnail; |
| 3027 | CharSequence description; |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 3028 | |
| 3029 | @Override public void run() { |
| 3030 | // Tell activity manager we have been stopped. |
| 3031 | try { |
| 3032 | if (DEBUG_MEMORY_TRIM) Slog.v(TAG, "Reporting activity stopped: " + activity); |
| 3033 | ActivityManagerNative.getDefault().activityStopped( |
| 3034 | activity.token, state, thumbnail, description); |
| 3035 | } catch (RemoteException ex) { |
| 3036 | } |
| 3037 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3038 | } |
| 3039 | |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 3040 | private static final class ProviderRefCount { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 3041 | public final IActivityManager.ContentProviderHolder holder; |
| 3042 | public final ProviderClientRecord client; |
| 3043 | public int stableCount; |
| 3044 | public int unstableCount; |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 3045 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 3046 | // When this is set, the stable and unstable ref counts are 0 and |
| 3047 | // we have a pending operation scheduled to remove the ref count |
| 3048 | // from the activity manager. On the activity manager we are still |
| 3049 | // holding an unstable ref, though it is not reflected in the counts |
| 3050 | // here. |
| 3051 | public boolean removePending; |
| 3052 | |
| 3053 | ProviderRefCount(IActivityManager.ContentProviderHolder inHolder, |
| 3054 | ProviderClientRecord inClient, int sCount, int uCount) { |
| 3055 | holder = inHolder; |
| 3056 | client = inClient; |
| 3057 | stableCount = sCount; |
| 3058 | unstableCount = uCount; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3059 | } |
| 3060 | } |
| 3061 | |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3062 | /** |
| 3063 | * Core implementation of stopping an activity. Note this is a little |
| 3064 | * tricky because the server's meaning of stop is slightly different |
| 3065 | * than our client -- for the server, stop means to save state and give |
| 3066 | * it the result when it is done, but the window may still be visible. |
| 3067 | * For the client, we want to call onStop()/onStart() to indicate when |
| 3068 | * the activity's UI visibillity changes. |
| 3069 | */ |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3070 | private void performStopActivityInner(ActivityClientRecord r, |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3071 | StopInfo info, boolean keepShown, boolean saveState) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3072 | if (localLOGV) Slog.v(TAG, "Performing stop of " + r); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3073 | Bundle state = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3074 | if (r != null) { |
| 3075 | if (!keepShown && r.stopped) { |
| 3076 | if (r.activity.mFinished) { |
| 3077 | // If we are finishing, we won't call onResume() in certain |
| 3078 | // cases. So here we likewise don't want to call onStop() |
| 3079 | // if the activity isn't resumed. |
| 3080 | return; |
| 3081 | } |
| 3082 | RuntimeException e = new RuntimeException( |
| 3083 | "Performing stop of activity that is not resumed: " |
| 3084 | + r.intent.getComponent().toShortString()); |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 3085 | Slog.e(TAG, e.getMessage(), e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3086 | } |
| 3087 | |
| 3088 | if (info != null) { |
| 3089 | try { |
| 3090 | // First create a thumbnail for the activity... |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3091 | // For now, don't create the thumbnail here; we are |
| 3092 | // doing that by doing a screen snapshot. |
| 3093 | info.thumbnail = null; //createThumbnailBitmap(r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3094 | info.description = r.activity.onCreateDescription(); |
| 3095 | } catch (Exception e) { |
| 3096 | if (!mInstrumentation.onException(r.activity, e)) { |
| 3097 | throw new RuntimeException( |
| 3098 | "Unable to save state of activity " |
| 3099 | + r.intent.getComponent().toShortString() |
| 3100 | + ": " + e.toString(), e); |
| 3101 | } |
| 3102 | } |
| 3103 | } |
| 3104 | |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3105 | // Next have the activity save its current state and managed dialogs... |
| 3106 | if (!r.activity.mFinished && saveState) { |
| 3107 | if (r.state == null) { |
| 3108 | state = new Bundle(); |
Dianne Hackborn | 9ecebbf | 2011-09-28 23:19:47 -0400 | [diff] [blame] | 3109 | state.setAllowFds(false); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3110 | mInstrumentation.callActivityOnSaveInstanceState(r.activity, state); |
| 3111 | r.state = state; |
| 3112 | } else { |
| 3113 | state = r.state; |
| 3114 | } |
| 3115 | } |
| 3116 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3117 | if (!keepShown) { |
| 3118 | try { |
| 3119 | // Now we are idle. |
| 3120 | r.activity.performStop(); |
| 3121 | } catch (Exception e) { |
| 3122 | if (!mInstrumentation.onException(r.activity, e)) { |
| 3123 | throw new RuntimeException( |
| 3124 | "Unable to stop activity " |
| 3125 | + r.intent.getComponent().toShortString() |
| 3126 | + ": " + e.toString(), e); |
| 3127 | } |
| 3128 | } |
| 3129 | r.stopped = true; |
| 3130 | } |
| 3131 | |
| 3132 | r.paused = true; |
| 3133 | } |
| 3134 | } |
| 3135 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3136 | private void updateVisibility(ActivityClientRecord r, boolean show) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3137 | View v = r.activity.mDecor; |
| 3138 | if (v != null) { |
| 3139 | if (show) { |
| 3140 | if (!r.activity.mVisibleFromServer) { |
| 3141 | r.activity.mVisibleFromServer = true; |
| 3142 | mNumVisibleActivities++; |
| 3143 | if (r.activity.mVisibleFromClient) { |
| 3144 | r.activity.makeVisible(); |
| 3145 | } |
| 3146 | } |
| 3147 | if (r.newConfig != null) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3148 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Updating activity vis " |
Dianne Hackborn | dc6b635 | 2009-09-30 14:20:09 -0700 | [diff] [blame] | 3149 | + r.activityInfo.name + " with new config " + r.newConfig); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3150 | performConfigurationChanged(r.activity, r.newConfig); |
Fabrice Di Meglio | 30ca5cd | 2012-05-07 17:45:44 -0700 | [diff] [blame] | 3151 | freeTextLayoutCachesIfNeeded(r.activity.mCurrentConfig.diff(r.newConfig)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3152 | r.newConfig = null; |
| 3153 | } |
| 3154 | } else { |
| 3155 | if (r.activity.mVisibleFromServer) { |
| 3156 | r.activity.mVisibleFromServer = false; |
| 3157 | mNumVisibleActivities--; |
| 3158 | v.setVisibility(View.INVISIBLE); |
| 3159 | } |
| 3160 | } |
| 3161 | } |
| 3162 | } |
| 3163 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3164 | private void handleStopActivity(IBinder token, boolean show, int configChanges) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3165 | ActivityClientRecord r = mActivities.get(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3166 | r.activity.mConfigChangeFlags |= configChanges; |
| 3167 | |
| 3168 | StopInfo info = new StopInfo(); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3169 | performStopActivityInner(r, info, show, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3170 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3171 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3172 | TAG, "Finishing stop of " + r + ": show=" + show |
| 3173 | + " win=" + r.window); |
| 3174 | |
| 3175 | updateVisibility(r, show); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3176 | |
Dianne Hackborn | 5d9d03a | 2011-01-24 13:15:09 -0800 | [diff] [blame] | 3177 | // Make sure any pending writes are now committed. |
| 3178 | if (!r.isPreHoneycomb()) { |
| 3179 | QueuedWork.waitToFinish(); |
| 3180 | } |
| 3181 | |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 3182 | // Schedule the call to tell the activity manager we have |
| 3183 | // stopped. We don't do this immediately, because we want to |
| 3184 | // have a chance for any other pending work (in particular memory |
| 3185 | // trim requests) to complete before you tell the activity |
| 3186 | // manager to proceed and allow us to go fully into the background. |
| 3187 | info.activity = r; |
| 3188 | info.state = r.state; |
| 3189 | mH.post(info); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3190 | } |
| 3191 | |
| 3192 | final void performRestartActivity(IBinder token) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3193 | ActivityClientRecord r = mActivities.get(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3194 | if (r.stopped) { |
| 3195 | r.activity.performRestart(); |
| 3196 | r.stopped = false; |
| 3197 | } |
| 3198 | } |
| 3199 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3200 | private void handleWindowVisibility(IBinder token, boolean show) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3201 | ActivityClientRecord r = mActivities.get(token); |
Dianne Hackborn | bfddc0f | 2010-12-14 11:28:01 -0800 | [diff] [blame] | 3202 | |
| 3203 | if (r == null) { |
| 3204 | Log.w(TAG, "handleWindowVisibility: no activity for token " + token); |
| 3205 | return; |
| 3206 | } |
| 3207 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3208 | if (!show && !r.stopped) { |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3209 | performStopActivityInner(r, null, show, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3210 | } else if (show && r.stopped) { |
| 3211 | // If we are getting ready to gc after going to the background, well |
| 3212 | // we are back active so skip it. |
| 3213 | unscheduleGcIdler(); |
| 3214 | |
| 3215 | r.activity.performRestart(); |
| 3216 | r.stopped = false; |
| 3217 | } |
| 3218 | if (r.activity.mDecor != null) { |
Joe Onorato | 43a1765 | 2011-04-06 19:22:23 -0700 | [diff] [blame] | 3219 | if (false) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3220 | TAG, "Handle window " + r + " visibility: " + show); |
| 3221 | updateVisibility(r, show); |
| 3222 | } |
| 3223 | } |
| 3224 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3225 | private void handleSleeping(IBinder token, boolean sleeping) { |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 3226 | ActivityClientRecord r = mActivities.get(token); |
| 3227 | |
| 3228 | if (r == null) { |
Dianne Hackborn | 842e04b | 2011-01-22 13:00:12 -0800 | [diff] [blame] | 3229 | Log.w(TAG, "handleSleeping: no activity for token " + token); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 3230 | return; |
| 3231 | } |
| 3232 | |
| 3233 | if (sleeping) { |
Dianne Hackborn | 842e04b | 2011-01-22 13:00:12 -0800 | [diff] [blame] | 3234 | if (!r.stopped && !r.isPreHoneycomb()) { |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 3235 | try { |
| 3236 | // Now we are idle. |
| 3237 | r.activity.performStop(); |
| 3238 | } catch (Exception e) { |
| 3239 | if (!mInstrumentation.onException(r.activity, e)) { |
| 3240 | throw new RuntimeException( |
| 3241 | "Unable to stop activity " |
| 3242 | + r.intent.getComponent().toShortString() |
| 3243 | + ": " + e.toString(), e); |
| 3244 | } |
| 3245 | } |
| 3246 | r.stopped = true; |
| 3247 | } |
Dianne Hackborn | 5d9d03a | 2011-01-24 13:15:09 -0800 | [diff] [blame] | 3248 | |
| 3249 | // Make sure any pending writes are now committed. |
| 3250 | if (!r.isPreHoneycomb()) { |
| 3251 | QueuedWork.waitToFinish(); |
| 3252 | } |
| 3253 | |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 3254 | // Tell activity manager we slept. |
| 3255 | try { |
| 3256 | ActivityManagerNative.getDefault().activitySlept(r.token); |
| 3257 | } catch (RemoteException ex) { |
| 3258 | } |
| 3259 | } else { |
| 3260 | if (r.stopped && r.activity.mVisibleFromServer) { |
| 3261 | r.activity.performRestart(); |
| 3262 | r.stopped = false; |
| 3263 | } |
| 3264 | } |
| 3265 | } |
| 3266 | |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 3267 | private void handleSetCoreSettings(Bundle coreSettings) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 3268 | synchronized (mResourcesManager) { |
Svetoslav Ganov | 9aa597e | 2011-03-03 18:17:41 -0800 | [diff] [blame] | 3269 | mCoreSettings = coreSettings; |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 3270 | } |
| 3271 | } |
| 3272 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 3273 | private void handleUpdatePackageCompatibilityInfo(UpdateCompatibilityData data) { |
| 3274 | LoadedApk apk = peekPackageInfo(data.pkg, false); |
| 3275 | if (apk != null) { |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 3276 | apk.setCompatibilityInfo(data.info); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 3277 | } |
| 3278 | apk = peekPackageInfo(data.pkg, true); |
| 3279 | if (apk != null) { |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 3280 | apk.setCompatibilityInfo(data.info); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 3281 | } |
| 3282 | handleConfigurationChanged(mConfiguration, data.info); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 3283 | WindowManagerGlobal.getInstance().reportNewConfiguration(mConfiguration); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 3284 | } |
| 3285 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3286 | private void deliverResults(ActivityClientRecord r, List<ResultInfo> results) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3287 | final int N = results.size(); |
| 3288 | for (int i=0; i<N; i++) { |
| 3289 | ResultInfo ri = results.get(i); |
| 3290 | try { |
| 3291 | if (ri.mData != null) { |
| 3292 | ri.mData.setExtrasClassLoader(r.activity.getClassLoader()); |
| 3293 | } |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3294 | if (DEBUG_RESULTS) Slog.v(TAG, |
Chris Tate | 8a7dc17 | 2009-03-24 20:11:42 -0700 | [diff] [blame] | 3295 | "Delivering result to activity " + r + " : " + ri); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3296 | r.activity.dispatchActivityResult(ri.mResultWho, |
| 3297 | ri.mRequestCode, ri.mResultCode, ri.mData); |
| 3298 | } catch (Exception e) { |
| 3299 | if (!mInstrumentation.onException(r.activity, e)) { |
| 3300 | throw new RuntimeException( |
| 3301 | "Failure delivering result " + ri + " to activity " |
| 3302 | + r.intent.getComponent().toShortString() |
| 3303 | + ": " + e.toString(), e); |
| 3304 | } |
| 3305 | } |
| 3306 | } |
| 3307 | } |
| 3308 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3309 | private void handleSendResult(ResultData res) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3310 | ActivityClientRecord r = mActivities.get(res.token); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3311 | if (DEBUG_RESULTS) Slog.v(TAG, "Handling send result to " + r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3312 | if (r != null) { |
| 3313 | final boolean resumed = !r.paused; |
| 3314 | if (!r.activity.mFinished && r.activity.mDecor != null |
| 3315 | && r.hideForNow && resumed) { |
| 3316 | // We had hidden the activity because it started another |
| 3317 | // one... we have gotten a result back and we are not |
| 3318 | // paused, so make sure our window is visible. |
| 3319 | updateVisibility(r, true); |
| 3320 | } |
| 3321 | if (resumed) { |
| 3322 | try { |
| 3323 | // Now we are idle. |
| 3324 | r.activity.mCalled = false; |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 3325 | r.activity.mTemporaryPause = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3326 | mInstrumentation.callActivityOnPause(r.activity); |
| 3327 | if (!r.activity.mCalled) { |
| 3328 | throw new SuperNotCalledException( |
| 3329 | "Activity " + r.intent.getComponent().toShortString() |
| 3330 | + " did not call through to super.onPause()"); |
| 3331 | } |
| 3332 | } catch (SuperNotCalledException e) { |
| 3333 | throw e; |
| 3334 | } catch (Exception e) { |
| 3335 | if (!mInstrumentation.onException(r.activity, e)) { |
| 3336 | throw new RuntimeException( |
| 3337 | "Unable to pause activity " |
| 3338 | + r.intent.getComponent().toShortString() |
| 3339 | + ": " + e.toString(), e); |
| 3340 | } |
| 3341 | } |
| 3342 | } |
| 3343 | deliverResults(r, res.results); |
| 3344 | if (resumed) { |
Dianne Hackborn | b46ed76 | 2011-06-02 18:33:15 -0700 | [diff] [blame] | 3345 | r.activity.performResume(); |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 3346 | r.activity.mTemporaryPause = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3347 | } |
| 3348 | } |
| 3349 | } |
| 3350 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3351 | public final ActivityClientRecord performDestroyActivity(IBinder token, boolean finishing) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3352 | return performDestroyActivity(token, finishing, 0, false); |
| 3353 | } |
| 3354 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3355 | private ActivityClientRecord performDestroyActivity(IBinder token, boolean finishing, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3356 | int configChanges, boolean getNonConfigInstance) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3357 | ActivityClientRecord r = mActivities.get(token); |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 3358 | Class<? extends Activity> activityClass = null; |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3359 | if (localLOGV) Slog.v(TAG, "Performing finish of " + r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3360 | if (r != null) { |
Brad Fitzpatrick | 5f8b5c1 | 2011-01-20 15:12:08 -0800 | [diff] [blame] | 3361 | activityClass = r.activity.getClass(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3362 | r.activity.mConfigChangeFlags |= configChanges; |
| 3363 | if (finishing) { |
| 3364 | r.activity.mFinished = true; |
| 3365 | } |
| 3366 | if (!r.paused) { |
| 3367 | try { |
| 3368 | r.activity.mCalled = false; |
| 3369 | mInstrumentation.callActivityOnPause(r.activity); |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 3370 | EventLog.writeEvent(LOG_ON_PAUSE_CALLED, UserHandle.myUserId(), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3371 | r.activity.getComponentName().getClassName()); |
| 3372 | if (!r.activity.mCalled) { |
| 3373 | throw new SuperNotCalledException( |
Mitsuru Oshima | d9aef73 | 2009-06-16 20:20:50 -0700 | [diff] [blame] | 3374 | "Activity " + safeToComponentShortString(r.intent) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3375 | + " did not call through to super.onPause()"); |
| 3376 | } |
| 3377 | } catch (SuperNotCalledException e) { |
| 3378 | throw e; |
| 3379 | } catch (Exception e) { |
| 3380 | if (!mInstrumentation.onException(r.activity, e)) { |
| 3381 | throw new RuntimeException( |
| 3382 | "Unable to pause activity " |
Mitsuru Oshima | d9aef73 | 2009-06-16 20:20:50 -0700 | [diff] [blame] | 3383 | + safeToComponentShortString(r.intent) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3384 | + ": " + e.toString(), e); |
| 3385 | } |
| 3386 | } |
| 3387 | r.paused = true; |
| 3388 | } |
| 3389 | if (!r.stopped) { |
| 3390 | try { |
| 3391 | r.activity.performStop(); |
| 3392 | } catch (SuperNotCalledException e) { |
| 3393 | throw e; |
| 3394 | } catch (Exception e) { |
| 3395 | if (!mInstrumentation.onException(r.activity, e)) { |
| 3396 | throw new RuntimeException( |
| 3397 | "Unable to stop activity " |
Mitsuru Oshima | d9aef73 | 2009-06-16 20:20:50 -0700 | [diff] [blame] | 3398 | + safeToComponentShortString(r.intent) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3399 | + ": " + e.toString(), e); |
| 3400 | } |
| 3401 | } |
| 3402 | r.stopped = true; |
| 3403 | } |
| 3404 | if (getNonConfigInstance) { |
| 3405 | try { |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 3406 | r.lastNonConfigurationInstances |
| 3407 | = r.activity.retainNonConfigurationInstances(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3408 | } catch (Exception e) { |
| 3409 | if (!mInstrumentation.onException(r.activity, e)) { |
| 3410 | throw new RuntimeException( |
| 3411 | "Unable to retain activity " |
| 3412 | + r.intent.getComponent().toShortString() |
| 3413 | + ": " + e.toString(), e); |
| 3414 | } |
| 3415 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3416 | } |
| 3417 | try { |
| 3418 | r.activity.mCalled = false; |
Dianne Hackborn | 2dedce6 | 2010-04-15 14:45:25 -0700 | [diff] [blame] | 3419 | mInstrumentation.callActivityOnDestroy(r.activity); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3420 | if (!r.activity.mCalled) { |
| 3421 | throw new SuperNotCalledException( |
Mitsuru Oshima | d9aef73 | 2009-06-16 20:20:50 -0700 | [diff] [blame] | 3422 | "Activity " + safeToComponentShortString(r.intent) + |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3423 | " did not call through to super.onDestroy()"); |
| 3424 | } |
| 3425 | if (r.window != null) { |
| 3426 | r.window.closeAllPanels(); |
| 3427 | } |
| 3428 | } catch (SuperNotCalledException e) { |
| 3429 | throw e; |
| 3430 | } catch (Exception e) { |
| 3431 | if (!mInstrumentation.onException(r.activity, e)) { |
| 3432 | throw new RuntimeException( |
Mitsuru Oshima | d9aef73 | 2009-06-16 20:20:50 -0700 | [diff] [blame] | 3433 | "Unable to destroy activity " + safeToComponentShortString(r.intent) |
| 3434 | + ": " + e.toString(), e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3435 | } |
| 3436 | } |
| 3437 | } |
| 3438 | mActivities.remove(token); |
Brad Fitzpatrick | 5f8b5c1 | 2011-01-20 15:12:08 -0800 | [diff] [blame] | 3439 | StrictMode.decrementExpectedActivityCount(activityClass); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3440 | return r; |
| 3441 | } |
| 3442 | |
Mitsuru Oshima | d9aef73 | 2009-06-16 20:20:50 -0700 | [diff] [blame] | 3443 | private static String safeToComponentShortString(Intent intent) { |
| 3444 | ComponentName component = intent.getComponent(); |
| 3445 | return component == null ? "[Unknown]" : component.toShortString(); |
| 3446 | } |
| 3447 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3448 | private void handleDestroyActivity(IBinder token, boolean finishing, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3449 | int configChanges, boolean getNonConfigInstance) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3450 | ActivityClientRecord r = performDestroyActivity(token, finishing, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3451 | configChanges, getNonConfigInstance); |
| 3452 | if (r != null) { |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 3453 | cleanUpPendingRemoveWindows(r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3454 | WindowManager wm = r.activity.getWindowManager(); |
| 3455 | View v = r.activity.mDecor; |
| 3456 | if (v != null) { |
| 3457 | if (r.activity.mVisibleFromServer) { |
| 3458 | mNumVisibleActivities--; |
| 3459 | } |
| 3460 | IBinder wtoken = v.getWindowToken(); |
| 3461 | if (r.activity.mWindowAdded) { |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 3462 | if (r.onlyLocalRequest) { |
| 3463 | // Hold off on removing this until the new activity's |
| 3464 | // window is being added. |
| 3465 | r.mPendingRemoveWindow = v; |
| 3466 | r.mPendingRemoveWindowManager = wm; |
| 3467 | } else { |
| 3468 | wm.removeViewImmediate(v); |
| 3469 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3470 | } |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 3471 | if (wtoken != null && r.mPendingRemoveWindow == null) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 3472 | WindowManagerGlobal.getInstance().closeAll(wtoken, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3473 | r.activity.getClass().getName(), "Activity"); |
| 3474 | } |
| 3475 | r.activity.mDecor = null; |
| 3476 | } |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 3477 | if (r.mPendingRemoveWindow == null) { |
| 3478 | // If we are delaying the removal of the activity window, then |
| 3479 | // we can't clean up all windows here. Note that we can't do |
| 3480 | // so later either, which means any windows that aren't closed |
| 3481 | // by the app will leak. Well we try to warning them a lot |
| 3482 | // about leaking windows, because that is a bug, so if they are |
| 3483 | // using this recreate facility then they get to live with leaks. |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 3484 | WindowManagerGlobal.getInstance().closeAll(token, |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 3485 | r.activity.getClass().getName(), "Activity"); |
| 3486 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3487 | |
| 3488 | // Mocked out contexts won't be participating in the normal |
| 3489 | // process lifecycle, but if we're running with a proper |
| 3490 | // ApplicationContext we need to have it tear down things |
| 3491 | // cleanly. |
| 3492 | Context c = r.activity.getBaseContext(); |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 3493 | if (c instanceof ContextImpl) { |
| 3494 | ((ContextImpl) c).scheduleFinalCleanup( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3495 | r.activity.getClass().getName(), "Activity"); |
| 3496 | } |
| 3497 | } |
| 3498 | if (finishing) { |
| 3499 | try { |
| 3500 | ActivityManagerNative.getDefault().activityDestroyed(token); |
| 3501 | } catch (RemoteException ex) { |
| 3502 | // If the system process has died, it's game over for everyone. |
| 3503 | } |
| 3504 | } |
| 3505 | } |
| 3506 | |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 3507 | public final void requestRelaunchActivity(IBinder token, |
| 3508 | List<ResultInfo> pendingResults, List<Intent> pendingNewIntents, |
| 3509 | int configChanges, boolean notResumed, Configuration config, |
| 3510 | boolean fromServer) { |
| 3511 | ActivityClientRecord target = null; |
| 3512 | |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 3513 | synchronized (mResourcesManager) { |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 3514 | for (int i=0; i<mRelaunchingActivities.size(); i++) { |
| 3515 | ActivityClientRecord r = mRelaunchingActivities.get(i); |
| 3516 | if (r.token == token) { |
| 3517 | target = r; |
| 3518 | if (pendingResults != null) { |
| 3519 | if (r.pendingResults != null) { |
| 3520 | r.pendingResults.addAll(pendingResults); |
| 3521 | } else { |
| 3522 | r.pendingResults = pendingResults; |
| 3523 | } |
| 3524 | } |
| 3525 | if (pendingNewIntents != null) { |
| 3526 | if (r.pendingIntents != null) { |
| 3527 | r.pendingIntents.addAll(pendingNewIntents); |
| 3528 | } else { |
| 3529 | r.pendingIntents = pendingNewIntents; |
| 3530 | } |
| 3531 | } |
| 3532 | break; |
| 3533 | } |
| 3534 | } |
| 3535 | |
| 3536 | if (target == null) { |
| 3537 | target = new ActivityClientRecord(); |
| 3538 | target.token = token; |
| 3539 | target.pendingResults = pendingResults; |
| 3540 | target.pendingIntents = pendingNewIntents; |
| 3541 | if (!fromServer) { |
| 3542 | ActivityClientRecord existing = mActivities.get(token); |
| 3543 | if (existing != null) { |
| 3544 | target.startsNotResumed = existing.paused; |
| 3545 | } |
| 3546 | target.onlyLocalRequest = true; |
| 3547 | } |
| 3548 | mRelaunchingActivities.add(target); |
| 3549 | queueOrSendMessage(H.RELAUNCH_ACTIVITY, target); |
| 3550 | } |
| 3551 | |
| 3552 | if (fromServer) { |
| 3553 | target.startsNotResumed = notResumed; |
| 3554 | target.onlyLocalRequest = false; |
| 3555 | } |
| 3556 | if (config != null) { |
| 3557 | target.createdConfig = config; |
| 3558 | } |
| 3559 | target.pendingConfigChanges |= configChanges; |
| 3560 | } |
| 3561 | } |
| 3562 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3563 | private void handleRelaunchActivity(ActivityClientRecord tmp) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3564 | // If we are getting ready to gc after going to the background, well |
| 3565 | // we are back active so skip it. |
| 3566 | unscheduleGcIdler(); |
| 3567 | |
| 3568 | Configuration changedConfig = null; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 3569 | int configChanges = 0; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3570 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3571 | // First: make sure we have the most recent configuration and most |
| 3572 | // recent version of the activity, or skip it if some previous call |
| 3573 | // had taken a more recent version. |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 3574 | synchronized (mResourcesManager) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3575 | int N = mRelaunchingActivities.size(); |
| 3576 | IBinder token = tmp.token; |
| 3577 | tmp = null; |
| 3578 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3579 | ActivityClientRecord r = mRelaunchingActivities.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3580 | if (r.token == token) { |
| 3581 | tmp = r; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 3582 | configChanges |= tmp.pendingConfigChanges; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3583 | mRelaunchingActivities.remove(i); |
| 3584 | i--; |
| 3585 | N--; |
| 3586 | } |
| 3587 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3588 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3589 | if (tmp == null) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3590 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Abort, activity not relaunching!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3591 | return; |
| 3592 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3593 | |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 3594 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Relaunching activity " |
| 3595 | + tmp.token + " with configChanges=0x" |
| 3596 | + Integer.toHexString(configChanges)); |
| 3597 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3598 | if (mPendingConfiguration != null) { |
| 3599 | changedConfig = mPendingConfiguration; |
| 3600 | mPendingConfiguration = null; |
| 3601 | } |
| 3602 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3603 | |
Dianne Hackborn | 871ecdc | 2009-12-11 15:24:33 -0800 | [diff] [blame] | 3604 | if (tmp.createdConfig != null) { |
| 3605 | // If the activity manager is passing us its current config, |
| 3606 | // assume that is really what we want regardless of what we |
| 3607 | // may have pending. |
| 3608 | if (mConfiguration == null |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3609 | || (tmp.createdConfig.isOtherSeqNewer(mConfiguration) |
| 3610 | && mConfiguration.diff(tmp.createdConfig) != 0)) { |
| 3611 | if (changedConfig == null |
| 3612 | || tmp.createdConfig.isOtherSeqNewer(changedConfig)) { |
| 3613 | changedConfig = tmp.createdConfig; |
| 3614 | } |
Dianne Hackborn | 871ecdc | 2009-12-11 15:24:33 -0800 | [diff] [blame] | 3615 | } |
| 3616 | } |
| 3617 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3618 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Relaunching activity " |
Dianne Hackborn | dc6b635 | 2009-09-30 14:20:09 -0700 | [diff] [blame] | 3619 | + tmp.token + ": changedConfig=" + changedConfig); |
| 3620 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3621 | // If there was a pending configuration change, execute it first. |
| 3622 | if (changedConfig != null) { |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 3623 | mCurDefaultDisplayDpi = changedConfig.densityDpi; |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 3624 | updateDefaultDensity(); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 3625 | handleConfigurationChanged(changedConfig, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3626 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3627 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3628 | ActivityClientRecord r = mActivities.get(tmp.token); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3629 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Handling relaunch of " + r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3630 | if (r == null) { |
| 3631 | return; |
| 3632 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3633 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3634 | r.activity.mConfigChangeFlags |= configChanges; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 3635 | r.onlyLocalRequest = tmp.onlyLocalRequest; |
Christopher Tate | b70f3df | 2009-04-07 16:07:59 -0700 | [diff] [blame] | 3636 | Intent currentIntent = r.activity.mIntent; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3637 | |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3638 | r.activity.mChangingConfigurations = true; |
| 3639 | |
Dianne Hackborn | e2b0480 | 2010-12-09 09:24:55 -0800 | [diff] [blame] | 3640 | // Need to ensure state is saved. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3641 | if (!r.paused) { |
Dianne Hackborn | e2b0480 | 2010-12-09 09:24:55 -0800 | [diff] [blame] | 3642 | performPauseActivity(r.token, false, r.isPreHoneycomb()); |
| 3643 | } |
| 3644 | if (r.state == null && !r.stopped && !r.isPreHoneycomb()) { |
| 3645 | r.state = new Bundle(); |
Dianne Hackborn | 9ecebbf | 2011-09-28 23:19:47 -0400 | [diff] [blame] | 3646 | r.state.setAllowFds(false); |
Dianne Hackborn | e2b0480 | 2010-12-09 09:24:55 -0800 | [diff] [blame] | 3647 | mInstrumentation.callActivityOnSaveInstanceState(r.activity, r.state); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3648 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3649 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3650 | handleDestroyActivity(r.token, false, configChanges, true); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3651 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3652 | r.activity = null; |
| 3653 | r.window = null; |
| 3654 | r.hideForNow = false; |
| 3655 | r.nextIdle = null; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3656 | // Merge any pending results and pending intents; don't just replace them |
| 3657 | if (tmp.pendingResults != null) { |
| 3658 | if (r.pendingResults == null) { |
| 3659 | r.pendingResults = tmp.pendingResults; |
| 3660 | } else { |
| 3661 | r.pendingResults.addAll(tmp.pendingResults); |
| 3662 | } |
| 3663 | } |
| 3664 | if (tmp.pendingIntents != null) { |
| 3665 | if (r.pendingIntents == null) { |
| 3666 | r.pendingIntents = tmp.pendingIntents; |
| 3667 | } else { |
| 3668 | r.pendingIntents.addAll(tmp.pendingIntents); |
| 3669 | } |
| 3670 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3671 | r.startsNotResumed = tmp.startsNotResumed; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3672 | |
Christopher Tate | b70f3df | 2009-04-07 16:07:59 -0700 | [diff] [blame] | 3673 | handleLaunchActivity(r, currentIntent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3674 | } |
| 3675 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3676 | private void handleRequestThumbnail(IBinder token) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3677 | ActivityClientRecord r = mActivities.get(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3678 | Bitmap thumbnail = createThumbnailBitmap(r); |
| 3679 | CharSequence description = null; |
| 3680 | try { |
| 3681 | description = r.activity.onCreateDescription(); |
| 3682 | } catch (Exception e) { |
| 3683 | if (!mInstrumentation.onException(r.activity, e)) { |
| 3684 | throw new RuntimeException( |
| 3685 | "Unable to create description of activity " |
| 3686 | + r.intent.getComponent().toShortString() |
| 3687 | + ": " + e.toString(), e); |
| 3688 | } |
| 3689 | } |
| 3690 | //System.out.println("Reporting top thumbnail " + thumbnail); |
| 3691 | try { |
| 3692 | ActivityManagerNative.getDefault().reportThumbnail( |
| 3693 | token, thumbnail, description); |
| 3694 | } catch (RemoteException ex) { |
| 3695 | } |
| 3696 | } |
| 3697 | |
Dianne Hackborn | 73c1416 | 2012-09-19 15:45:06 -0700 | [diff] [blame] | 3698 | ArrayList<ComponentCallbacks2> collectComponentCallbacks( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3699 | boolean allActivities, Configuration newConfig) { |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 3700 | ArrayList<ComponentCallbacks2> callbacks |
| 3701 | = new ArrayList<ComponentCallbacks2>(); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3702 | |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 3703 | synchronized (mResourcesManager) { |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 3704 | final int NAPP = mAllApplications.size(); |
| 3705 | for (int i=0; i<NAPP; i++) { |
Dianne Hackborn | 73c1416 | 2012-09-19 15:45:06 -0700 | [diff] [blame] | 3706 | callbacks.add(mAllApplications.get(i)); |
| 3707 | } |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 3708 | final int NACT = mActivities.size(); |
| 3709 | for (int i=0; i<NACT; i++) { |
| 3710 | ActivityClientRecord ar = mActivities.valueAt(i); |
| 3711 | Activity a = ar.activity; |
| 3712 | if (a != null) { |
| 3713 | Configuration thisConfig = applyConfigCompatMainThread( |
| 3714 | mCurDefaultDisplayDpi, newConfig, |
| 3715 | ar.packageInfo.getCompatibilityInfo()); |
| 3716 | if (!ar.activity.mFinished && (allActivities || !ar.paused)) { |
| 3717 | // If the activity is currently resumed, its configuration |
| 3718 | // needs to change right now. |
| 3719 | callbacks.add(a); |
| 3720 | } else if (thisConfig != null) { |
| 3721 | // Otherwise, we will tell it about the change |
| 3722 | // the next time it is resumed or shown. Note that |
| 3723 | // the activity manager may, before then, decide the |
| 3724 | // activity needs to be destroyed to handle its new |
| 3725 | // configuration. |
| 3726 | if (DEBUG_CONFIGURATION) { |
| 3727 | Slog.v(TAG, "Setting activity " |
| 3728 | + ar.activityInfo.name + " newConfig=" + thisConfig); |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 3729 | } |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 3730 | ar.newConfig = thisConfig; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3731 | } |
| 3732 | } |
| 3733 | } |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 3734 | final int NSVC = mServices.size(); |
| 3735 | for (int i=0; i<NSVC; i++) { |
| 3736 | callbacks.add(mServices.valueAt(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3737 | } |
| 3738 | } |
| 3739 | synchronized (mProviderMap) { |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 3740 | final int NPRV = mLocalProviders.size(); |
| 3741 | for (int i=0; i<NPRV; i++) { |
| 3742 | callbacks.add(mLocalProviders.valueAt(i).mLocalProvider); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3743 | } |
| 3744 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3745 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3746 | return callbacks; |
| 3747 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3748 | |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 3749 | private static void performConfigurationChanged(ComponentCallbacks2 cb, Configuration config) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3750 | // Only for Activity objects, check that they actually call up to their |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 3751 | // superclass implementation. ComponentCallbacks2 is an interface, so |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3752 | // we check the runtime type and act accordingly. |
| 3753 | Activity activity = (cb instanceof Activity) ? (Activity) cb : null; |
| 3754 | if (activity != null) { |
| 3755 | activity.mCalled = false; |
| 3756 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3757 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3758 | boolean shouldChangeConfig = false; |
| 3759 | if ((activity == null) || (activity.mCurrentConfig == null)) { |
| 3760 | shouldChangeConfig = true; |
| 3761 | } else { |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3762 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3763 | // If the new config is the same as the config this Activity |
| 3764 | // is already running with then don't bother calling |
| 3765 | // onConfigurationChanged |
| 3766 | int diff = activity.mCurrentConfig.diff(config); |
| 3767 | if (diff != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3768 | // If this activity doesn't handle any of the config changes |
| 3769 | // then don't bother calling onConfigurationChanged as we're |
| 3770 | // going to destroy it. |
Dianne Hackborn | e667635 | 2011-06-01 16:51:20 -0700 | [diff] [blame] | 3771 | if ((~activity.mActivityInfo.getRealConfigChanged() & diff) == 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3772 | shouldChangeConfig = true; |
| 3773 | } |
| 3774 | } |
| 3775 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3776 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3777 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Config callback " + cb |
Dianne Hackborn | dc6b635 | 2009-09-30 14:20:09 -0700 | [diff] [blame] | 3778 | + ": shouldChangeConfig=" + shouldChangeConfig); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3779 | if (shouldChangeConfig) { |
| 3780 | cb.onConfigurationChanged(config); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3781 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3782 | if (activity != null) { |
| 3783 | if (!activity.mCalled) { |
| 3784 | throw new SuperNotCalledException( |
| 3785 | "Activity " + activity.getLocalClassName() + |
| 3786 | " did not call through to super.onConfigurationChanged()"); |
| 3787 | } |
| 3788 | activity.mConfigChangeFlags = 0; |
| 3789 | activity.mCurrentConfig = new Configuration(config); |
| 3790 | } |
| 3791 | } |
| 3792 | } |
| 3793 | |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 3794 | public final void applyConfigurationToResources(Configuration config) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 3795 | synchronized (mResourcesManager) { |
| 3796 | mResourcesManager.applyConfigurationToResourcesLocked(config, null); |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 3797 | } |
| 3798 | } |
| 3799 | |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 3800 | final Configuration applyCompatConfiguration(int displayDensity) { |
Dianne Hackborn | 836e262 | 2011-10-04 18:32:39 -0700 | [diff] [blame] | 3801 | Configuration config = mConfiguration; |
| 3802 | if (mCompatConfiguration == null) { |
| 3803 | mCompatConfiguration = new Configuration(); |
| 3804 | } |
| 3805 | mCompatConfiguration.setTo(mConfiguration); |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 3806 | if (mResourcesManager.applyCompatConfiguration(displayDensity, mCompatConfiguration)) { |
Dianne Hackborn | 836e262 | 2011-10-04 18:32:39 -0700 | [diff] [blame] | 3807 | config = mCompatConfiguration; |
| 3808 | } |
| 3809 | return config; |
| 3810 | } |
| 3811 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 3812 | final void handleConfigurationChanged(Configuration config, CompatibilityInfo compat) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3813 | |
Fabrice Di Meglio | 30ca5cd | 2012-05-07 17:45:44 -0700 | [diff] [blame] | 3814 | int configDiff = 0; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3815 | |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 3816 | synchronized (mResourcesManager) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3817 | if (mPendingConfiguration != null) { |
| 3818 | if (!mPendingConfiguration.isOtherSeqNewer(config)) { |
| 3819 | config = mPendingConfiguration; |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 3820 | mCurDefaultDisplayDpi = config.densityDpi; |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 3821 | updateDefaultDensity(); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3822 | } |
| 3823 | mPendingConfiguration = null; |
| 3824 | } |
| 3825 | |
| 3826 | if (config == null) { |
| 3827 | return; |
| 3828 | } |
| 3829 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3830 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Handle configuration changed: " |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3831 | + config); |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 3832 | |
| 3833 | mResourcesManager.applyConfigurationToResourcesLocked(config, compat); |
| 3834 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3835 | if (mConfiguration == null) { |
| 3836 | mConfiguration = new Configuration(); |
| 3837 | } |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 3838 | if (!mConfiguration.isOtherSeqNewer(config) && compat == null) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3839 | return; |
| 3840 | } |
Fabrice Di Meglio | 30ca5cd | 2012-05-07 17:45:44 -0700 | [diff] [blame] | 3841 | configDiff = mConfiguration.diff(config); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3842 | mConfiguration.updateFrom(config); |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 3843 | config = applyCompatConfiguration(mCurDefaultDisplayDpi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3844 | } |
Dianne Hackborn | 73c1416 | 2012-09-19 15:45:06 -0700 | [diff] [blame] | 3845 | |
| 3846 | ArrayList<ComponentCallbacks2> callbacks = collectComponentCallbacks(false, config); |
| 3847 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3848 | // Cleanup hardware accelerated stuff |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 3849 | WindowManagerGlobal.getInstance().trimLocalMemory(); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3850 | |
Fabrice Di Meglio | 30ca5cd | 2012-05-07 17:45:44 -0700 | [diff] [blame] | 3851 | freeTextLayoutCachesIfNeeded(configDiff); |
| 3852 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3853 | if (callbacks != null) { |
| 3854 | final int N = callbacks.size(); |
| 3855 | for (int i=0; i<N; i++) { |
| 3856 | performConfigurationChanged(callbacks.get(i), config); |
| 3857 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3858 | } |
| 3859 | } |
| 3860 | |
Fabrice Di Meglio | 30ca5cd | 2012-05-07 17:45:44 -0700 | [diff] [blame] | 3861 | final void freeTextLayoutCachesIfNeeded(int configDiff) { |
| 3862 | if (configDiff != 0) { |
| 3863 | // Ask text layout engine to free its caches if there is a locale change |
| 3864 | boolean hasLocaleConfigChange = ((configDiff & ActivityInfo.CONFIG_LOCALE) != 0); |
| 3865 | if (hasLocaleConfigChange) { |
| 3866 | Canvas.freeTextLayoutCaches(); |
| 3867 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Cleared TextLayout Caches"); |
| 3868 | } |
| 3869 | } |
| 3870 | } |
| 3871 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3872 | final void handleActivityConfigurationChanged(IBinder token) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3873 | ActivityClientRecord r = mActivities.get(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3874 | if (r == null || r.activity == null) { |
| 3875 | return; |
| 3876 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3877 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3878 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Handle activity config changed: " |
Dianne Hackborn | dc6b635 | 2009-09-30 14:20:09 -0700 | [diff] [blame] | 3879 | + r.activityInfo.name); |
| 3880 | |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 3881 | performConfigurationChanged(r.activity, mCompatConfiguration); |
Fabrice Di Meglio | 30ca5cd | 2012-05-07 17:45:44 -0700 | [diff] [blame] | 3882 | |
| 3883 | freeTextLayoutCachesIfNeeded(r.activity.mCurrentConfig.diff(mCompatConfiguration)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3884 | } |
| 3885 | |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 3886 | final void handleProfilerControl(boolean start, ProfilerControlData pcd, int profileType) { |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 3887 | if (start) { |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 3888 | try { |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 3889 | switch (profileType) { |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 3890 | default: |
| 3891 | mProfiler.setProfiler(pcd.path, pcd.fd); |
| 3892 | mProfiler.autoStopProfiler = false; |
| 3893 | mProfiler.startProfiling(); |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 3894 | break; |
| 3895 | } |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 3896 | } catch (RuntimeException e) { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 3897 | Slog.w(TAG, "Profiling failed on path " + pcd.path |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 3898 | + " -- can the process access this path?"); |
Dianne Hackborn | 9c8dd55 | 2009-06-23 19:22:52 -0700 | [diff] [blame] | 3899 | } finally { |
| 3900 | try { |
| 3901 | pcd.fd.close(); |
| 3902 | } catch (IOException e) { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 3903 | Slog.w(TAG, "Failure closing profile fd", e); |
Dianne Hackborn | 9c8dd55 | 2009-06-23 19:22:52 -0700 | [diff] [blame] | 3904 | } |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 3905 | } |
| 3906 | } else { |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 3907 | switch (profileType) { |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 3908 | default: |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 3909 | mProfiler.stopProfiling(); |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 3910 | break; |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 3911 | } |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 3912 | } |
| 3913 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3914 | |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 3915 | static final void handleDumpHeap(boolean managed, DumpHeapData dhd) { |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 3916 | if (managed) { |
| 3917 | try { |
| 3918 | Debug.dumpHprofData(dhd.path, dhd.fd.getFileDescriptor()); |
| 3919 | } catch (IOException e) { |
| 3920 | Slog.w(TAG, "Managed heap dump failed on path " + dhd.path |
| 3921 | + " -- can the process access this path?"); |
| 3922 | } finally { |
| 3923 | try { |
| 3924 | dhd.fd.close(); |
| 3925 | } catch (IOException e) { |
| 3926 | Slog.w(TAG, "Failure closing profile fd", e); |
| 3927 | } |
| 3928 | } |
| 3929 | } else { |
Andy McFadden | 06a6b55 | 2010-07-13 16:28:09 -0700 | [diff] [blame] | 3930 | Debug.dumpNativeHeap(dhd.fd.getFileDescriptor()); |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 3931 | } |
| 3932 | } |
| 3933 | |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 3934 | final void handleDispatchPackageBroadcast(int cmd, String[] packages) { |
| 3935 | boolean hasPkgInfo = false; |
| 3936 | if (packages != null) { |
| 3937 | for (int i=packages.length-1; i>=0; i--) { |
| 3938 | //Slog.i(TAG, "Cleaning old package: " + packages[i]); |
| 3939 | if (!hasPkgInfo) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3940 | WeakReference<LoadedApk> ref; |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 3941 | ref = mPackages.get(packages[i]); |
| 3942 | if (ref != null && ref.get() != null) { |
| 3943 | hasPkgInfo = true; |
| 3944 | } else { |
| 3945 | ref = mResourcePackages.get(packages[i]); |
| 3946 | if (ref != null && ref.get() != null) { |
| 3947 | hasPkgInfo = true; |
| 3948 | } |
| 3949 | } |
| 3950 | } |
| 3951 | mPackages.remove(packages[i]); |
| 3952 | mResourcePackages.remove(packages[i]); |
| 3953 | } |
| 3954 | } |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 3955 | ApplicationPackageManager.handlePackageBroadcast(cmd, packages, |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 3956 | hasPkgInfo); |
| 3957 | } |
| 3958 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3959 | final void handleLowMemory() { |
Dianne Hackborn | 73c1416 | 2012-09-19 15:45:06 -0700 | [diff] [blame] | 3960 | ArrayList<ComponentCallbacks2> callbacks = collectComponentCallbacks(true, null); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3961 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3962 | final int N = callbacks.size(); |
| 3963 | for (int i=0; i<N; i++) { |
| 3964 | callbacks.get(i).onLowMemory(); |
| 3965 | } |
| 3966 | |
Chris Tate | ce22905 | 2009-03-25 16:44:52 -0700 | [diff] [blame] | 3967 | // Ask SQLite to free up as much memory as it can, mostly from its page caches. |
| 3968 | if (Process.myUid() != Process.SYSTEM_UID) { |
| 3969 | int sqliteReleased = SQLiteDatabase.releaseMemory(); |
| 3970 | EventLog.writeEvent(SQLITE_MEM_RELEASED_EVENT_LOG_TAG, sqliteReleased); |
| 3971 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3972 | |
Mike Reed | caf0df1 | 2009-04-27 14:32:05 -0400 | [diff] [blame] | 3973 | // Ask graphics to free up as much as possible (font/image caches) |
| 3974 | Canvas.freeCaches(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3975 | |
Fabrice Di Meglio | 30ca5cd | 2012-05-07 17:45:44 -0700 | [diff] [blame] | 3976 | // Ask text layout engine to free also as much as possible |
| 3977 | Canvas.freeTextLayoutCaches(); |
| 3978 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3979 | BinderInternal.forceGc("mem"); |
| 3980 | } |
| 3981 | |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3982 | final void handleTrimMemory(int level) { |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 3983 | if (DEBUG_MEMORY_TRIM) Slog.v(TAG, "Trimming memory to level: " + level); |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 3984 | |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 3985 | final WindowManagerGlobal windowManager = WindowManagerGlobal.getInstance(); |
Romain Guy | 19f86e8 | 2012-04-23 15:19:07 -0700 | [diff] [blame] | 3986 | windowManager.startTrimMemory(level); |
| 3987 | |
Dianne Hackborn | 73c1416 | 2012-09-19 15:45:06 -0700 | [diff] [blame] | 3988 | ArrayList<ComponentCallbacks2> callbacks = collectComponentCallbacks(true, null); |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 3989 | |
| 3990 | final int N = callbacks.size(); |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 3991 | for (int i = 0; i < N; i++) { |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 3992 | callbacks.get(i).onTrimMemory(level); |
| 3993 | } |
Romain Guy | 19f86e8 | 2012-04-23 15:19:07 -0700 | [diff] [blame] | 3994 | |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 3995 | windowManager.endTrimMemory(); |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3996 | } |
| 3997 | |
Jeff Sharkey | e1d330a | 2012-05-02 13:46:21 -0700 | [diff] [blame] | 3998 | private void setupGraphicsSupport(LoadedApk info, File cacheDir) { |
Dianne Hackborn | a0c283e | 2012-02-09 10:47:01 -0800 | [diff] [blame] | 3999 | if (Process.isIsolated()) { |
| 4000 | // Isolated processes aren't going to do UI. |
| 4001 | return; |
| 4002 | } |
Romain Guy | a958265 | 2011-11-10 14:20:10 -0800 | [diff] [blame] | 4003 | try { |
| 4004 | int uid = Process.myUid(); |
| 4005 | String[] packages = getPackageManager().getPackagesForUid(uid); |
| 4006 | |
| 4007 | // If there are several packages in this application we won't |
| 4008 | // initialize the graphics disk caches |
Dianne Hackborn | a0c283e | 2012-02-09 10:47:01 -0800 | [diff] [blame] | 4009 | if (packages != null && packages.length == 1) { |
Jeff Sharkey | e1d330a | 2012-05-02 13:46:21 -0700 | [diff] [blame] | 4010 | HardwareRenderer.setupDiskCache(cacheDir); |
| 4011 | RenderScript.setupDiskCache(cacheDir); |
Romain Guy | a958265 | 2011-11-10 14:20:10 -0800 | [diff] [blame] | 4012 | } |
| 4013 | } catch (RemoteException e) { |
| 4014 | // Ignore |
| 4015 | } |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 4016 | } |
| 4017 | |
| 4018 | private void updateDefaultDensity() { |
| 4019 | if (mCurDefaultDisplayDpi != Configuration.DENSITY_DPI_UNDEFINED |
| 4020 | && mCurDefaultDisplayDpi != DisplayMetrics.DENSITY_DEVICE |
| 4021 | && !mDensityCompatMode) { |
| 4022 | Slog.i(TAG, "Switching default density from " |
| 4023 | + DisplayMetrics.DENSITY_DEVICE + " to " |
| 4024 | + mCurDefaultDisplayDpi); |
| 4025 | DisplayMetrics.DENSITY_DEVICE = mCurDefaultDisplayDpi; |
| 4026 | Bitmap.setDefaultDensity(DisplayMetrics.DENSITY_DEFAULT); |
| 4027 | } |
| 4028 | } |
| 4029 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 4030 | private void handleBindApplication(AppBindData data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4031 | mBoundApplication = data; |
| 4032 | mConfiguration = new Configuration(data.config); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 4033 | mCompatConfiguration = new Configuration(data.config); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4034 | |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 4035 | mProfiler = new Profiler(); |
| 4036 | mProfiler.profileFile = data.initProfileFile; |
| 4037 | mProfiler.profileFd = data.initProfileFd; |
| 4038 | mProfiler.autoStopProfiler = data.initAutoStopProfiler; |
| 4039 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4040 | // send up app name; do this *before* waiting for debugger |
Christopher Tate | 8ee038d | 2009-11-06 11:30:20 -0800 | [diff] [blame] | 4041 | Process.setArgV0(data.processName); |
Siva Velusamy | d693dfa | 2012-09-10 14:36:58 -0700 | [diff] [blame] | 4042 | android.ddm.DdmHandleAppName.setAppName(data.processName, |
| 4043 | UserHandle.myUserId()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4044 | |
Dianne Hackborn | 5d927c2 | 2011-09-02 12:22:18 -0700 | [diff] [blame] | 4045 | if (data.persistent) { |
| 4046 | // Persistent processes on low-memory devices do not get to |
| 4047 | // use hardware accelerated drawing, since this can add too much |
| 4048 | // overhead to the process. |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 4049 | if (!ActivityManager.isHighEndGfx()) { |
Dianne Hackborn | 5d927c2 | 2011-09-02 12:22:18 -0700 | [diff] [blame] | 4050 | HardwareRenderer.disable(false); |
| 4051 | } |
| 4052 | } |
Romain Guy | a958265 | 2011-11-10 14:20:10 -0800 | [diff] [blame] | 4053 | |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 4054 | if (mProfiler.profileFd != null) { |
| 4055 | mProfiler.startProfiling(); |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 4056 | } |
| 4057 | |
Joe Onorato | d630f10 | 2011-03-17 18:42:26 -0700 | [diff] [blame] | 4058 | // If the app is Honeycomb MR1 or earlier, switch its AsyncTask |
| 4059 | // implementation to use the pool executor. Normally, we use the |
| 4060 | // serialized executor as the default. This has to happen in the |
| 4061 | // main thread so the main looper is set right. |
Dianne Hackborn | 81e9276 | 2011-10-09 16:00:21 -0700 | [diff] [blame] | 4062 | if (data.appInfo.targetSdkVersion <= android.os.Build.VERSION_CODES.HONEYCOMB_MR1) { |
Joe Onorato | d630f10 | 2011-03-17 18:42:26 -0700 | [diff] [blame] | 4063 | AsyncTask.setDefaultExecutor(AsyncTask.THREAD_POOL_EXECUTOR); |
| 4064 | } |
| 4065 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4066 | /* |
| 4067 | * Before spawning a new process, reset the time zone to be the system time zone. |
| 4068 | * This needs to be done because the system time zone could have changed after the |
| 4069 | * the spawning of this process. Without doing this this process would have the incorrect |
| 4070 | * system time zone. |
| 4071 | */ |
| 4072 | TimeZone.setDefault(null); |
| 4073 | |
| 4074 | /* |
| 4075 | * Initialize the default locale in this process for the reasons we set the time zone. |
| 4076 | */ |
| 4077 | Locale.setDefault(data.config.locale); |
| 4078 | |
Suchi Amalapurapu | c984329 | 2009-06-24 17:02:25 -0700 | [diff] [blame] | 4079 | /* |
| 4080 | * Update the system configuration since its preloaded and might not |
| 4081 | * reflect configuration changes. The configuration object passed |
| 4082 | * in AppBindData can be safely assumed to be up to date |
| 4083 | */ |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4084 | mResourcesManager.applyConfigurationToResourcesLocked(data.config, data.compatInfo); |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 4085 | mCurDefaultDisplayDpi = data.config.densityDpi; |
| 4086 | applyCompatConfiguration(mCurDefaultDisplayDpi); |
Suchi Amalapurapu | c984329 | 2009-06-24 17:02:25 -0700 | [diff] [blame] | 4087 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4088 | data.info = getPackageInfoNoCheck(data.appInfo, data.compatInfo); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4089 | |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 4090 | /** |
| 4091 | * Switch this process to density compatibility mode if needed. |
| 4092 | */ |
| 4093 | if ((data.appInfo.flags&ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES) |
| 4094 | == 0) { |
| 4095 | mDensityCompatMode = true; |
| 4096 | Bitmap.setDefaultDensity(DisplayMetrics.DENSITY_DEFAULT); |
| 4097 | } |
| 4098 | updateDefaultDensity(); |
| 4099 | |
Jeff Sharkey | e1d330a | 2012-05-02 13:46:21 -0700 | [diff] [blame] | 4100 | final ContextImpl appContext = new ContextImpl(); |
| 4101 | appContext.init(data.info, null, this); |
Amith Yamasani | 11de39a | 2012-08-17 18:00:52 -0700 | [diff] [blame] | 4102 | if (!Process.isIsolated()) { |
| 4103 | final File cacheDir = appContext.getCacheDir(); |
Jeff Sharkey | e1d330a | 2012-05-02 13:46:21 -0700 | [diff] [blame] | 4104 | |
Amith Yamasani | 92d5705 | 2012-08-23 10:07:52 -0700 | [diff] [blame] | 4105 | if (cacheDir != null) { |
| 4106 | // Provide a usable directory for temporary files |
| 4107 | System.setProperty("java.io.tmpdir", cacheDir.getAbsolutePath()); |
| 4108 | |
| 4109 | setupGraphicsSupport(data.info, cacheDir); |
| 4110 | } else { |
| 4111 | Log.e(TAG, "Unable to setupGraphicsSupport due to missing cache directory"); |
| 4112 | } |
Amith Yamasani | 11de39a | 2012-08-17 18:00:52 -0700 | [diff] [blame] | 4113 | } |
Dianne Hackborn | 96e240f | 2009-07-26 17:42:30 -0700 | [diff] [blame] | 4114 | /** |
Brad Fitzpatrick | 438d059 | 2010-06-10 12:19:19 -0700 | [diff] [blame] | 4115 | * For system applications on userdebug/eng builds, log stack |
| 4116 | * traces of disk and network access to dropbox for analysis. |
| 4117 | */ |
Brad Fitzpatrick | ad13b98 | 2010-07-14 12:35:53 -0700 | [diff] [blame] | 4118 | if ((data.appInfo.flags & |
| 4119 | (ApplicationInfo.FLAG_SYSTEM | |
Brad Fitzpatrick | 50d66f9 | 2010-09-13 21:29:05 -0700 | [diff] [blame] | 4120 | ApplicationInfo.FLAG_UPDATED_SYSTEM_APP)) != 0) { |
| 4121 | StrictMode.conditionallyEnableDebugLogging(); |
Brad Fitzpatrick | 438d059 | 2010-06-10 12:19:19 -0700 | [diff] [blame] | 4122 | } |
| 4123 | |
| 4124 | /** |
Brad Fitzpatrick | b6e1841 | 2010-10-28 14:50:05 -0700 | [diff] [blame] | 4125 | * For apps targetting SDK Honeycomb or later, we don't allow |
| 4126 | * network usage on the main event loop / UI thread. |
| 4127 | * |
| 4128 | * Note to those grepping: this is what ultimately throws |
| 4129 | * NetworkOnMainThreadException ... |
| 4130 | */ |
| 4131 | if (data.appInfo.targetSdkVersion > 9) { |
| 4132 | StrictMode.enableDeathOnNetwork(); |
| 4133 | } |
| 4134 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4135 | if (data.debugMode != IApplicationThread.DEBUG_OFF) { |
| 4136 | // XXX should have option to change the port. |
| 4137 | Debug.changeDebugPort(8100); |
| 4138 | if (data.debugMode == IApplicationThread.DEBUG_WAIT) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4139 | Slog.w(TAG, "Application " + data.info.getPackageName() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4140 | + " is waiting for the debugger on port 8100..."); |
| 4141 | |
| 4142 | IActivityManager mgr = ActivityManagerNative.getDefault(); |
| 4143 | try { |
| 4144 | mgr.showWaitingForDebugger(mAppThread, true); |
| 4145 | } catch (RemoteException ex) { |
| 4146 | } |
| 4147 | |
| 4148 | Debug.waitForDebugger(); |
| 4149 | |
| 4150 | try { |
| 4151 | mgr.showWaitingForDebugger(mAppThread, false); |
| 4152 | } catch (RemoteException ex) { |
| 4153 | } |
| 4154 | |
| 4155 | } else { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4156 | Slog.w(TAG, "Application " + data.info.getPackageName() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4157 | + " can be debugged on port 8100..."); |
| 4158 | } |
| 4159 | } |
| 4160 | |
Siva Velusamy | 92a8b22 | 2012-03-09 16:24:04 -0800 | [diff] [blame] | 4161 | // Enable OpenGL tracing if required |
| 4162 | if (data.enableOpenGlTrace) { |
Siva Velusamy | 0c1761b | 2012-12-14 17:09:06 -0800 | [diff] [blame] | 4163 | GLUtils.setTracingLevel(1); |
Siva Velusamy | 92a8b22 | 2012-03-09 16:24:04 -0800 | [diff] [blame] | 4164 | } |
| 4165 | |
Jamie Gennis | f9c7d6b | 2013-03-25 14:18:25 -0700 | [diff] [blame] | 4166 | // Allow application-generated systrace messages if we're debuggable. |
| 4167 | boolean appTracingAllowed = (data.appInfo.flags&ApplicationInfo.FLAG_DEBUGGABLE) != 0; |
| 4168 | Trace.setAppTracingAllowed(appTracingAllowed); |
| 4169 | |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 4170 | /** |
| 4171 | * Initialize the default http proxy in this process for the reasons we set the time zone. |
| 4172 | */ |
| 4173 | IBinder b = ServiceManager.getService(Context.CONNECTIVITY_SERVICE); |
Dianne Hackborn | d4d32c5 | 2011-11-08 17:33:59 -0800 | [diff] [blame] | 4174 | if (b != null) { |
| 4175 | // In pre-boot mode (doing initial launch to collect password), not |
| 4176 | // all system is up. This includes the connectivity service, so don't |
| 4177 | // crash if we can't get it. |
| 4178 | IConnectivityManager service = IConnectivityManager.Stub.asInterface(b); |
| 4179 | try { |
| 4180 | ProxyProperties proxyProperties = service.getProxy(); |
| 4181 | Proxy.setHttpProxySystemProperty(proxyProperties); |
| 4182 | } catch (RemoteException e) {} |
| 4183 | } |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 4184 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4185 | if (data.instrumentationName != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4186 | InstrumentationInfo ii = null; |
| 4187 | try { |
| 4188 | ii = appContext.getPackageManager(). |
| 4189 | getInstrumentationInfo(data.instrumentationName, 0); |
| 4190 | } catch (PackageManager.NameNotFoundException e) { |
| 4191 | } |
| 4192 | if (ii == null) { |
| 4193 | throw new RuntimeException( |
| 4194 | "Unable to find instrumentation info for: " |
| 4195 | + data.instrumentationName); |
| 4196 | } |
| 4197 | |
| 4198 | mInstrumentationAppDir = ii.sourceDir; |
Brian Carlstrom | d893a89 | 2012-04-01 21:30:26 -0700 | [diff] [blame] | 4199 | mInstrumentationAppLibraryDir = ii.nativeLibraryDir; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4200 | mInstrumentationAppPackage = ii.packageName; |
| 4201 | mInstrumentedAppDir = data.info.getAppDir(); |
Brian Carlstrom | d893a89 | 2012-04-01 21:30:26 -0700 | [diff] [blame] | 4202 | mInstrumentedAppLibraryDir = data.info.getLibDir(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4203 | |
| 4204 | ApplicationInfo instrApp = new ApplicationInfo(); |
| 4205 | instrApp.packageName = ii.packageName; |
| 4206 | instrApp.sourceDir = ii.sourceDir; |
| 4207 | instrApp.publicSourceDir = ii.publicSourceDir; |
| 4208 | instrApp.dataDir = ii.dataDir; |
Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 4209 | instrApp.nativeLibraryDir = ii.nativeLibraryDir; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4210 | LoadedApk pi = getPackageInfo(instrApp, data.compatInfo, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4211 | appContext.getClassLoader(), false, true); |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 4212 | ContextImpl instrContext = new ContextImpl(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4213 | instrContext.init(pi, null, this); |
| 4214 | |
| 4215 | try { |
| 4216 | java.lang.ClassLoader cl = instrContext.getClassLoader(); |
| 4217 | mInstrumentation = (Instrumentation) |
| 4218 | cl.loadClass(data.instrumentationName.getClassName()).newInstance(); |
| 4219 | } catch (Exception e) { |
| 4220 | throw new RuntimeException( |
| 4221 | "Unable to instantiate instrumentation " |
| 4222 | + data.instrumentationName + ": " + e.toString(), e); |
| 4223 | } |
| 4224 | |
| 4225 | mInstrumentation.init(this, instrContext, appContext, |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 4226 | new ComponentName(ii.packageName, ii.name), data.instrumentationWatcher, |
| 4227 | data.instrumentationUiAutomationConnection); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4228 | |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 4229 | if (mProfiler.profileFile != null && !ii.handleProfiling |
| 4230 | && mProfiler.profileFd == null) { |
| 4231 | mProfiler.handlingProfiling = true; |
| 4232 | File file = new File(mProfiler.profileFile); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4233 | file.getParentFile().mkdirs(); |
| 4234 | Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024); |
| 4235 | } |
| 4236 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4237 | } else { |
| 4238 | mInstrumentation = new Instrumentation(); |
| 4239 | } |
| 4240 | |
Dianne Hackborn | 3b81bc1 | 2011-01-15 11:50:52 -0800 | [diff] [blame] | 4241 | if ((data.appInfo.flags&ApplicationInfo.FLAG_LARGE_HEAP) != 0) { |
Dianne Hackborn | de39851 | 2011-01-18 18:45:21 -0800 | [diff] [blame] | 4242 | dalvik.system.VMRuntime.getRuntime().clearGrowthLimit(); |
Dianne Hackborn | 3b81bc1 | 2011-01-15 11:50:52 -0800 | [diff] [blame] | 4243 | } |
| 4244 | |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 4245 | // Allow disk access during application and provider setup. This could |
Jeff Sharkey | 7c50167 | 2012-02-28 12:08:37 -0800 | [diff] [blame] | 4246 | // block processing ordered broadcasts, but later processing would |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 4247 | // probably end up doing the same disk access. |
Jeff Sharkey | 7c50167 | 2012-02-28 12:08:37 -0800 | [diff] [blame] | 4248 | final StrictMode.ThreadPolicy savedPolicy = StrictMode.allowThreadDiskWrites(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4249 | try { |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 4250 | // If the app is being launched for full backup or restore, bring it up in |
| 4251 | // a restricted environment with the base application class. |
| 4252 | Application app = data.info.makeApplication(data.restrictedBackupMode, null); |
| 4253 | mInitialApplication = app; |
Jeff Sharkey | 7c50167 | 2012-02-28 12:08:37 -0800 | [diff] [blame] | 4254 | |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 4255 | // don't bring up providers in restricted mode; they may depend on the |
| 4256 | // app's custom Application class |
| 4257 | if (!data.restrictedBackupMode) { |
| 4258 | List<ProviderInfo> providers = data.providers; |
| 4259 | if (providers != null) { |
| 4260 | installContentProviders(app, providers); |
| 4261 | // For process that contains content providers, we want to |
| 4262 | // ensure that the JIT is enabled "at some point". |
| 4263 | mH.sendEmptyMessageDelayed(H.ENABLE_JIT, 10*1000); |
| 4264 | } |
| 4265 | } |
| 4266 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 4267 | // Do this after providers, since instrumentation tests generally start their |
| 4268 | // test thread at this point, and we don't want that racing. |
| 4269 | try { |
| 4270 | mInstrumentation.onCreate(data.instrumentationArgs); |
| 4271 | } |
| 4272 | catch (Exception e) { |
| 4273 | throw new RuntimeException( |
| 4274 | "Exception thrown in onCreate() of " |
| 4275 | + data.instrumentationName + ": " + e.toString(), e); |
| 4276 | } |
| 4277 | |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 4278 | try { |
| 4279 | mInstrumentation.callApplicationOnCreate(app); |
| 4280 | } catch (Exception e) { |
| 4281 | if (!mInstrumentation.onException(app, e)) { |
| 4282 | throw new RuntimeException( |
| 4283 | "Unable to create application " + app.getClass().getName() |
| 4284 | + ": " + e.toString(), e); |
| 4285 | } |
| 4286 | } |
| 4287 | } finally { |
| 4288 | StrictMode.setThreadPolicy(savedPolicy); |
| 4289 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4290 | } |
| 4291 | |
| 4292 | /*package*/ final void finishInstrumentation(int resultCode, Bundle results) { |
| 4293 | IActivityManager am = ActivityManagerNative.getDefault(); |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 4294 | if (mProfiler.profileFile != null && mProfiler.handlingProfiling |
| 4295 | && mProfiler.profileFd == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4296 | Debug.stopMethodTracing(); |
| 4297 | } |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4298 | //Slog.i(TAG, "am: " + ActivityManagerNative.getDefault() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4299 | // + ", app thr: " + mAppThread); |
| 4300 | try { |
| 4301 | am.finishInstrumentation(mAppThread, resultCode, results); |
| 4302 | } catch (RemoteException ex) { |
| 4303 | } |
| 4304 | } |
| 4305 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 4306 | private void installContentProviders( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4307 | Context context, List<ProviderInfo> providers) { |
| 4308 | final ArrayList<IActivityManager.ContentProviderHolder> results = |
| 4309 | new ArrayList<IActivityManager.ContentProviderHolder>(); |
| 4310 | |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 4311 | for (ProviderInfo cpi : providers) { |
Dianne Hackborn | 40e9f29 | 2012-11-27 19:12:23 -0800 | [diff] [blame] | 4312 | if (DEBUG_PROVIDER) { |
| 4313 | StringBuilder buf = new StringBuilder(128); |
| 4314 | buf.append("Pub "); |
| 4315 | buf.append(cpi.authority); |
| 4316 | buf.append(": "); |
| 4317 | buf.append(cpi.name); |
| 4318 | Log.i(TAG, buf.toString()); |
| 4319 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 4320 | IActivityManager.ContentProviderHolder cph = installProvider(context, null, cpi, |
| 4321 | false /*noisy*/, true /*noReleaseNeeded*/, true /*stable*/); |
| 4322 | if (cph != null) { |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 4323 | cph.noReleaseNeeded = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4324 | results.add(cph); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4325 | } |
| 4326 | } |
| 4327 | |
| 4328 | try { |
| 4329 | ActivityManagerNative.getDefault().publishContentProviders( |
| 4330 | getApplicationThread(), results); |
| 4331 | } catch (RemoteException ex) { |
| 4332 | } |
| 4333 | } |
| 4334 | |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 4335 | public final IContentProvider acquireProvider( |
| 4336 | Context c, String auth, int userId, boolean stable) { |
| 4337 | final IContentProvider provider = acquireExistingProvider(c, auth, userId, stable); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 4338 | if (provider != null) { |
| 4339 | return provider; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4340 | } |
| 4341 | |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 4342 | // There is a possible race here. Another thread may try to acquire |
| 4343 | // the same provider at the same time. When this happens, we want to ensure |
| 4344 | // that the first one wins. |
| 4345 | // Note that we cannot hold the lock while acquiring and installing the |
| 4346 | // provider since it might take a long time to run and it could also potentially |
| 4347 | // be re-entrant in the case where the provider is in the same process. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4348 | IActivityManager.ContentProviderHolder holder = null; |
| 4349 | try { |
| 4350 | holder = ActivityManagerNative.getDefault().getContentProvider( |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 4351 | getApplicationThread(), auth, userId, stable); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4352 | } catch (RemoteException ex) { |
| 4353 | } |
| 4354 | if (holder == null) { |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 4355 | Slog.e(TAG, "Failed to find provider info for " + auth); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4356 | return null; |
| 4357 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4358 | |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 4359 | // Install provider will increment the reference count for us, and break |
| 4360 | // any ties in the race. |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 4361 | holder = installProvider(c, holder, holder.info, |
| 4362 | true /*noisy*/, holder.noReleaseNeeded, stable); |
| 4363 | return holder.provider; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4364 | } |
| 4365 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 4366 | private final void incProviderRefLocked(ProviderRefCount prc, boolean stable) { |
| 4367 | if (stable) { |
| 4368 | prc.stableCount += 1; |
| 4369 | if (prc.stableCount == 1) { |
| 4370 | // We are acquiring a new stable reference on the provider. |
| 4371 | int unstableDelta; |
| 4372 | if (prc.removePending) { |
| 4373 | // We have a pending remove operation, which is holding the |
| 4374 | // last unstable reference. At this point we are converting |
| 4375 | // that unstable reference to our new stable reference. |
| 4376 | unstableDelta = -1; |
| 4377 | // Cancel the removal of the provider. |
| 4378 | if (DEBUG_PROVIDER) { |
| 4379 | Slog.v(TAG, "incProviderRef: stable " |
| 4380 | + "snatched provider from the jaws of death"); |
| 4381 | } |
| 4382 | prc.removePending = false; |
Guobin Zhang | 9e3e5266 | 2013-03-21 13:57:11 +0800 | [diff] [blame] | 4383 | // There is a race! It fails to remove the message, which |
| 4384 | // will be handled in completeRemoveProvider(). |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 4385 | mH.removeMessages(H.REMOVE_PROVIDER, prc); |
| 4386 | } else { |
| 4387 | unstableDelta = 0; |
| 4388 | } |
| 4389 | try { |
| 4390 | if (DEBUG_PROVIDER) { |
| 4391 | Slog.v(TAG, "incProviderRef Now stable - " |
| 4392 | + prc.holder.info.name + ": unstableDelta=" |
| 4393 | + unstableDelta); |
| 4394 | } |
| 4395 | ActivityManagerNative.getDefault().refContentProvider( |
| 4396 | prc.holder.connection, 1, unstableDelta); |
| 4397 | } catch (RemoteException e) { |
| 4398 | //do nothing content provider object is dead any way |
| 4399 | } |
| 4400 | } |
| 4401 | } else { |
| 4402 | prc.unstableCount += 1; |
| 4403 | if (prc.unstableCount == 1) { |
| 4404 | // We are acquiring a new unstable reference on the provider. |
| 4405 | if (prc.removePending) { |
| 4406 | // Oh look, we actually have a remove pending for the |
| 4407 | // provider, which is still holding the last unstable |
| 4408 | // reference. We just need to cancel that to take new |
| 4409 | // ownership of the reference. |
| 4410 | if (DEBUG_PROVIDER) { |
| 4411 | Slog.v(TAG, "incProviderRef: unstable " |
| 4412 | + "snatched provider from the jaws of death"); |
| 4413 | } |
| 4414 | prc.removePending = false; |
| 4415 | mH.removeMessages(H.REMOVE_PROVIDER, prc); |
| 4416 | } else { |
| 4417 | // First unstable ref, increment our count in the |
| 4418 | // activity manager. |
| 4419 | try { |
| 4420 | if (DEBUG_PROVIDER) { |
| 4421 | Slog.v(TAG, "incProviderRef: Now unstable - " |
| 4422 | + prc.holder.info.name); |
| 4423 | } |
| 4424 | ActivityManagerNative.getDefault().refContentProvider( |
| 4425 | prc.holder.connection, 0, 1); |
| 4426 | } catch (RemoteException e) { |
| 4427 | //do nothing content provider object is dead any way |
| 4428 | } |
| 4429 | } |
| 4430 | } |
| 4431 | } |
| 4432 | } |
| 4433 | |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 4434 | public final IContentProvider acquireExistingProvider( |
| 4435 | Context c, String auth, int userId, boolean stable) { |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 4436 | synchronized (mProviderMap) { |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 4437 | final ProviderKey key = new ProviderKey(auth, userId); |
| 4438 | final ProviderClientRecord pr = mProviderMap.get(key); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 4439 | if (pr == null) { |
| 4440 | return null; |
| 4441 | } |
| 4442 | |
| 4443 | IContentProvider provider = pr.mProvider; |
| 4444 | IBinder jBinder = provider.asBinder(); |
Dianne Hackborn | c428aae | 2012-10-03 16:38:22 -0700 | [diff] [blame] | 4445 | if (!jBinder.isBinderAlive()) { |
| 4446 | // The hosting process of the provider has died; we can't |
| 4447 | // use this one. |
| 4448 | Log.i(TAG, "Acquiring provider " + auth + " for user " + userId |
| 4449 | + ": existing object's process dead"); |
| 4450 | handleUnstableProviderDiedLocked(jBinder, true); |
| 4451 | return null; |
| 4452 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 4453 | |
| 4454 | // Only increment the ref count if we have one. If we don't then the |
| 4455 | // provider is not reference counted and never needs to be released. |
Dianne Hackborn | cca1f0e | 2010-09-26 18:34:53 -0700 | [diff] [blame] | 4456 | ProviderRefCount prc = mProviderRefCountMap.get(jBinder); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 4457 | if (prc != null) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 4458 | incProviderRefLocked(prc, stable); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 4459 | } |
| 4460 | return provider; |
| 4461 | } |
Dianne Hackborn | cca1f0e | 2010-09-26 18:34:53 -0700 | [diff] [blame] | 4462 | } |
| 4463 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 4464 | public final boolean releaseProvider(IContentProvider provider, boolean stable) { |
| 4465 | if (provider == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4466 | return false; |
| 4467 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 4468 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4469 | IBinder jBinder = provider.asBinder(); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 4470 | synchronized (mProviderMap) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4471 | ProviderRefCount prc = mProviderRefCountMap.get(jBinder); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 4472 | if (prc == null) { |
| 4473 | // The provider has no ref count, no release is needed. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4474 | return false; |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 4475 | } |
| 4476 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 4477 | boolean lastRef = false; |
| 4478 | if (stable) { |
| 4479 | if (prc.stableCount == 0) { |
| 4480 | if (DEBUG_PROVIDER) Slog.v(TAG, |
| 4481 | "releaseProvider: stable ref count already 0, how?"); |
| 4482 | return false; |
| 4483 | } |
| 4484 | prc.stableCount -= 1; |
| 4485 | if (prc.stableCount == 0) { |
| 4486 | // What we do at this point depends on whether there are |
| 4487 | // any unstable refs left: if there are, we just tell the |
| 4488 | // activity manager to decrement its stable count; if there |
| 4489 | // aren't, we need to enqueue this provider to be removed, |
| 4490 | // and convert to holding a single unstable ref while |
| 4491 | // doing so. |
| 4492 | lastRef = prc.unstableCount == 0; |
| 4493 | try { |
| 4494 | if (DEBUG_PROVIDER) { |
| 4495 | Slog.v(TAG, "releaseProvider: No longer stable w/lastRef=" |
| 4496 | + lastRef + " - " + prc.holder.info.name); |
| 4497 | } |
| 4498 | ActivityManagerNative.getDefault().refContentProvider( |
| 4499 | prc.holder.connection, -1, lastRef ? 1 : 0); |
| 4500 | } catch (RemoteException e) { |
| 4501 | //do nothing content provider object is dead any way |
| 4502 | } |
| 4503 | } |
| 4504 | } else { |
| 4505 | if (prc.unstableCount == 0) { |
| 4506 | if (DEBUG_PROVIDER) Slog.v(TAG, |
| 4507 | "releaseProvider: unstable ref count already 0, how?"); |
| 4508 | return false; |
| 4509 | } |
| 4510 | prc.unstableCount -= 1; |
| 4511 | if (prc.unstableCount == 0) { |
| 4512 | // If this is the last reference, we need to enqueue |
| 4513 | // this provider to be removed instead of telling the |
| 4514 | // activity manager to remove it at this point. |
| 4515 | lastRef = prc.stableCount == 0; |
| 4516 | if (!lastRef) { |
| 4517 | try { |
| 4518 | if (DEBUG_PROVIDER) { |
| 4519 | Slog.v(TAG, "releaseProvider: No longer unstable - " |
| 4520 | + prc.holder.info.name); |
| 4521 | } |
| 4522 | ActivityManagerNative.getDefault().refContentProvider( |
| 4523 | prc.holder.connection, 0, -1); |
| 4524 | } catch (RemoteException e) { |
| 4525 | //do nothing content provider object is dead any way |
| 4526 | } |
| 4527 | } |
| 4528 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 4529 | } |
| 4530 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 4531 | if (lastRef) { |
| 4532 | if (!prc.removePending) { |
| 4533 | // Schedule the actual remove asynchronously, since we don't know the context |
| 4534 | // this will be called in. |
| 4535 | // TODO: it would be nice to post a delayed message, so |
| 4536 | // if we come back and need the same provider quickly |
| 4537 | // we will still have it available. |
| 4538 | if (DEBUG_PROVIDER) { |
| 4539 | Slog.v(TAG, "releaseProvider: Enqueueing pending removal - " |
| 4540 | + prc.holder.info.name); |
| 4541 | } |
| 4542 | prc.removePending = true; |
| 4543 | Message msg = mH.obtainMessage(H.REMOVE_PROVIDER, prc); |
| 4544 | mH.sendMessage(msg); |
| 4545 | } else { |
| 4546 | Slog.w(TAG, "Duplicate remove pending of provider " + prc.holder.info.name); |
| 4547 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 4548 | } |
| 4549 | return true; |
| 4550 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4551 | } |
| 4552 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 4553 | final void completeRemoveProvider(ProviderRefCount prc) { |
| 4554 | synchronized (mProviderMap) { |
| 4555 | if (!prc.removePending) { |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 4556 | // There was a race! Some other client managed to acquire |
| 4557 | // the provider before the removal was completed. |
| 4558 | // Abort the removal. We will do it later. |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 4559 | if (DEBUG_PROVIDER) Slog.v(TAG, "completeRemoveProvider: lost the race, " |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 4560 | + "provider still in use"); |
| 4561 | return; |
| 4562 | } |
| 4563 | |
Guobin Zhang | 9e3e5266 | 2013-03-21 13:57:11 +0800 | [diff] [blame] | 4564 | // More complicated race!! Some client managed to acquire the |
| 4565 | // provider and release it before the removal was completed. |
| 4566 | // Continue the removal, and abort the next remove message. |
| 4567 | prc.removePending = false; |
| 4568 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 4569 | final IBinder jBinder = prc.holder.provider.asBinder(); |
| 4570 | ProviderRefCount existingPrc = mProviderRefCountMap.get(jBinder); |
| 4571 | if (existingPrc == prc) { |
| 4572 | mProviderRefCountMap.remove(jBinder); |
| 4573 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 4574 | |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 4575 | for (int i=mProviderMap.size()-1; i>=0; i--) { |
| 4576 | ProviderClientRecord pr = mProviderMap.valueAt(i); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 4577 | IBinder myBinder = pr.mProvider.asBinder(); |
| 4578 | if (myBinder == jBinder) { |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 4579 | mProviderMap.removeAt(i); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 4580 | } |
| 4581 | } |
| 4582 | } |
| 4583 | |
| 4584 | try { |
| 4585 | if (DEBUG_PROVIDER) { |
| 4586 | Slog.v(TAG, "removeProvider: Invoking ActivityManagerNative." |
| 4587 | + "removeContentProvider(" + prc.holder.info.name + ")"); |
| 4588 | } |
| 4589 | ActivityManagerNative.getDefault().removeContentProvider( |
| 4590 | prc.holder.connection, false); |
| 4591 | } catch (RemoteException e) { |
| 4592 | //do nothing content provider object is dead any way |
| 4593 | } |
| 4594 | } |
| 4595 | |
| 4596 | final void handleUnstableProviderDied(IBinder provider, boolean fromClient) { |
Dianne Hackborn | c428aae | 2012-10-03 16:38:22 -0700 | [diff] [blame] | 4597 | synchronized (mProviderMap) { |
| 4598 | handleUnstableProviderDiedLocked(provider, fromClient); |
| 4599 | } |
| 4600 | } |
| 4601 | |
| 4602 | final void handleUnstableProviderDiedLocked(IBinder provider, boolean fromClient) { |
| 4603 | ProviderRefCount prc = mProviderRefCountMap.get(provider); |
| 4604 | if (prc != null) { |
| 4605 | if (DEBUG_PROVIDER) Slog.v(TAG, "Cleaning up dead provider " |
| 4606 | + provider + " " + prc.holder.info.name); |
| 4607 | mProviderRefCountMap.remove(provider); |
| 4608 | if (prc.client != null && prc.client.mNames != null) { |
| 4609 | for (String name : prc.client.mNames) { |
| 4610 | ProviderClientRecord pr = mProviderMap.get(name); |
| 4611 | if (pr != null && pr.mProvider.asBinder() == provider) { |
| 4612 | Slog.i(TAG, "Removing dead content provider: " + name); |
| 4613 | mProviderMap.remove(name); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 4614 | } |
| 4615 | } |
Dianne Hackborn | c428aae | 2012-10-03 16:38:22 -0700 | [diff] [blame] | 4616 | } |
| 4617 | if (fromClient) { |
| 4618 | // We found out about this due to execution in our client |
| 4619 | // code. Tell the activity manager about it now, to ensure |
| 4620 | // that the next time we go to do anything with the provider |
| 4621 | // it knows it is dead (so we don't race with its death |
| 4622 | // notification). |
| 4623 | try { |
| 4624 | ActivityManagerNative.getDefault().unstableProviderDied( |
| 4625 | prc.holder.connection); |
| 4626 | } catch (RemoteException e) { |
| 4627 | //do nothing content provider object is dead any way |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 4628 | } |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 4629 | } |
| 4630 | } |
| 4631 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4632 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 4633 | private ProviderClientRecord installProviderAuthoritiesLocked(IContentProvider provider, |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 4634 | ContentProvider localProvider, IActivityManager.ContentProviderHolder holder) { |
| 4635 | final String auths[] = PATTERN_SEMICOLON.split(holder.info.authority); |
| 4636 | final int userId = UserHandle.getUserId(holder.info.applicationInfo.uid); |
| 4637 | |
| 4638 | final ProviderClientRecord pcr = new ProviderClientRecord( |
| 4639 | auths, provider, localProvider, holder); |
| 4640 | for (String auth : auths) { |
| 4641 | final ProviderKey key = new ProviderKey(auth, userId); |
| 4642 | final ProviderClientRecord existing = mProviderMap.get(key); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 4643 | if (existing != null) { |
| 4644 | Slog.w(TAG, "Content provider " + pcr.mHolder.info.name |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 4645 | + " already published as " + auth); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 4646 | } else { |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 4647 | mProviderMap.put(key, pcr); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4648 | } |
| 4649 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 4650 | return pcr; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4651 | } |
| 4652 | |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 4653 | /** |
| 4654 | * Installs the provider. |
| 4655 | * |
| 4656 | * Providers that are local to the process or that come from the system server |
| 4657 | * may be installed permanently which is indicated by setting noReleaseNeeded to true. |
| 4658 | * Other remote providers are reference counted. The initial reference count |
| 4659 | * for all reference counted providers is one. Providers that are not reference |
| 4660 | * counted do not have a reference count (at all). |
| 4661 | * |
| 4662 | * This method detects when a provider has already been installed. When this happens, |
| 4663 | * it increments the reference count of the existing provider (if appropriate) |
| 4664 | * and returns the existing provider. This can happen due to concurrent |
| 4665 | * attempts to acquire the same provider. |
| 4666 | */ |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 4667 | private IActivityManager.ContentProviderHolder installProvider(Context context, |
| 4668 | IActivityManager.ContentProviderHolder holder, ProviderInfo info, |
| 4669 | boolean noisy, boolean noReleaseNeeded, boolean stable) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4670 | ContentProvider localProvider = null; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 4671 | IContentProvider provider; |
Dianne Hackborn | 5f48fca | 2012-05-30 11:06:31 -0700 | [diff] [blame] | 4672 | if (holder == null || holder.provider == null) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 4673 | if (DEBUG_PROVIDER || noisy) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4674 | Slog.d(TAG, "Loading provider " + info.authority + ": " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4675 | + info.name); |
| 4676 | } |
| 4677 | Context c = null; |
| 4678 | ApplicationInfo ai = info.applicationInfo; |
| 4679 | if (context.getPackageName().equals(ai.packageName)) { |
| 4680 | c = context; |
| 4681 | } else if (mInitialApplication != null && |
| 4682 | mInitialApplication.getPackageName().equals(ai.packageName)) { |
| 4683 | c = mInitialApplication; |
| 4684 | } else { |
| 4685 | try { |
| 4686 | c = context.createPackageContext(ai.packageName, |
| 4687 | Context.CONTEXT_INCLUDE_CODE); |
| 4688 | } catch (PackageManager.NameNotFoundException e) { |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 4689 | // Ignore |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4690 | } |
| 4691 | } |
| 4692 | if (c == null) { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 4693 | Slog.w(TAG, "Unable to get context for package " + |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4694 | ai.packageName + |
| 4695 | " while loading content provider " + |
| 4696 | info.name); |
| 4697 | return null; |
| 4698 | } |
| 4699 | try { |
| 4700 | final java.lang.ClassLoader cl = c.getClassLoader(); |
| 4701 | localProvider = (ContentProvider)cl. |
| 4702 | loadClass(info.name).newInstance(); |
| 4703 | provider = localProvider.getIContentProvider(); |
| 4704 | if (provider == null) { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 4705 | Slog.e(TAG, "Failed to instantiate class " + |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4706 | info.name + " from sourceDir " + |
| 4707 | info.applicationInfo.sourceDir); |
| 4708 | return null; |
| 4709 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 4710 | if (DEBUG_PROVIDER) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4711 | TAG, "Instantiating local provider " + info.name); |
| 4712 | // XXX Need to create the correct context for this provider. |
| 4713 | localProvider.attachInfo(c, info); |
| 4714 | } catch (java.lang.Exception e) { |
| 4715 | if (!mInstrumentation.onException(null, e)) { |
| 4716 | throw new RuntimeException( |
| 4717 | "Unable to get provider " + info.name |
| 4718 | + ": " + e.toString(), e); |
| 4719 | } |
| 4720 | return null; |
| 4721 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 4722 | } else { |
| 4723 | provider = holder.provider; |
| 4724 | if (DEBUG_PROVIDER) Slog.v(TAG, "Installing external provider " + info.authority + ": " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4725 | + info.name); |
| 4726 | } |
| 4727 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 4728 | IActivityManager.ContentProviderHolder retHolder; |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 4729 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 4730 | synchronized (mProviderMap) { |
| 4731 | if (DEBUG_PROVIDER) Slog.v(TAG, "Checking to add " + provider |
| 4732 | + " / " + info.name); |
| 4733 | IBinder jBinder = provider.asBinder(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4734 | if (localProvider != null) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 4735 | ComponentName cname = new ComponentName(info.packageName, info.name); |
| 4736 | ProviderClientRecord pr = mLocalProvidersByName.get(cname); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 4737 | if (pr != null) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 4738 | if (DEBUG_PROVIDER) { |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 4739 | Slog.v(TAG, "installProvider: lost the race, " |
| 4740 | + "using existing local provider"); |
| 4741 | } |
| 4742 | provider = pr.mProvider; |
| 4743 | } else { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 4744 | holder = new IActivityManager.ContentProviderHolder(info); |
| 4745 | holder.provider = provider; |
| 4746 | holder.noReleaseNeeded = true; |
| 4747 | pr = installProviderAuthoritiesLocked(provider, localProvider, holder); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 4748 | mLocalProviders.put(jBinder, pr); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 4749 | mLocalProvidersByName.put(cname, pr); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 4750 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 4751 | retHolder = pr.mHolder; |
| 4752 | } else { |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 4753 | ProviderRefCount prc = mProviderRefCountMap.get(jBinder); |
| 4754 | if (prc != null) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 4755 | if (DEBUG_PROVIDER) { |
| 4756 | Slog.v(TAG, "installProvider: lost the race, updating ref count"); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 4757 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 4758 | // We need to transfer our new reference to the existing |
| 4759 | // ref count, releasing the old one... but only if |
| 4760 | // release is needed (that is, it is not running in the |
| 4761 | // system process). |
| 4762 | if (!noReleaseNeeded) { |
| 4763 | incProviderRefLocked(prc, stable); |
| 4764 | try { |
| 4765 | ActivityManagerNative.getDefault().removeContentProvider( |
| 4766 | holder.connection, stable); |
| 4767 | } catch (RemoteException e) { |
| 4768 | //do nothing content provider object is dead any way |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 4769 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 4770 | } |
| 4771 | } else { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 4772 | ProviderClientRecord client = installProviderAuthoritiesLocked( |
| 4773 | provider, localProvider, holder); |
| 4774 | if (noReleaseNeeded) { |
| 4775 | prc = new ProviderRefCount(holder, client, 1000, 1000); |
| 4776 | } else { |
| 4777 | prc = stable |
| 4778 | ? new ProviderRefCount(holder, client, 1, 0) |
| 4779 | : new ProviderRefCount(holder, client, 0, 1); |
| 4780 | } |
| 4781 | mProviderRefCountMap.put(jBinder, prc); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 4782 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 4783 | retHolder = prc.holder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4784 | } |
| 4785 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 4786 | |
| 4787 | return retHolder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4788 | } |
| 4789 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 4790 | private void attach(boolean system) { |
Jeff Sharkey | 66a017b | 2013-01-17 18:18:22 -0800 | [diff] [blame] | 4791 | sCurrentActivityThread = this; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4792 | mSystemThread = system; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4793 | if (!system) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 4794 | ViewRootImpl.addFirstDrawHandler(new Runnable() { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4795 | @Override |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 4796 | public void run() { |
| 4797 | ensureJitEnabled(); |
| 4798 | } |
| 4799 | }); |
Siva Velusamy | d693dfa | 2012-09-10 14:36:58 -0700 | [diff] [blame] | 4800 | android.ddm.DdmHandleAppName.setAppName("<pre-initialized>", |
| 4801 | UserHandle.myUserId()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4802 | RuntimeInit.setApplicationObject(mAppThread.asBinder()); |
| 4803 | IActivityManager mgr = ActivityManagerNative.getDefault(); |
| 4804 | try { |
| 4805 | mgr.attachApplication(mAppThread); |
| 4806 | } catch (RemoteException ex) { |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 4807 | // Ignore |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4808 | } |
| 4809 | } else { |
| 4810 | // Don't set application object here -- if the system crashes, |
| 4811 | // we can't display an alert, we just want to die die die. |
Siva Velusamy | d693dfa | 2012-09-10 14:36:58 -0700 | [diff] [blame] | 4812 | android.ddm.DdmHandleAppName.setAppName("system_process", |
| 4813 | UserHandle.myUserId()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4814 | try { |
| 4815 | mInstrumentation = new Instrumentation(); |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 4816 | ContextImpl context = new ContextImpl(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4817 | context.init(getSystemContext().mPackageInfo, null, this); |
| 4818 | Application app = Instrumentation.newApplication(Application.class, context); |
| 4819 | mAllApplications.add(app); |
| 4820 | mInitialApplication = app; |
| 4821 | app.onCreate(); |
| 4822 | } catch (Exception e) { |
| 4823 | throw new RuntimeException( |
| 4824 | "Unable to instantiate Application():" + e.toString(), e); |
| 4825 | } |
| 4826 | } |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 4827 | |
| 4828 | // add dropbox logging to libcore |
| 4829 | DropBox.setReporter(new DropBoxReporter()); |
| 4830 | |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 4831 | ViewRootImpl.addConfigCallback(new ComponentCallbacks2() { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4832 | @Override |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4833 | public void onConfigurationChanged(Configuration newConfig) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4834 | synchronized (mResourcesManager) { |
Dianne Hackborn | ae07816 | 2010-03-18 11:29:37 -0700 | [diff] [blame] | 4835 | // We need to apply this change to the resources |
| 4836 | // immediately, because upon returning the view |
| 4837 | // hierarchy will be informed about it. |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4838 | if (mResourcesManager.applyConfigurationToResourcesLocked(newConfig, null)) { |
Dianne Hackborn | ae07816 | 2010-03-18 11:29:37 -0700 | [diff] [blame] | 4839 | // This actually changed the resources! Tell |
| 4840 | // everyone about it. |
| 4841 | if (mPendingConfiguration == null || |
| 4842 | mPendingConfiguration.isOtherSeqNewer(newConfig)) { |
| 4843 | mPendingConfiguration = newConfig; |
| 4844 | |
| 4845 | queueOrSendMessage(H.CONFIGURATION_CHANGED, newConfig); |
| 4846 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4847 | } |
| 4848 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4849 | } |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4850 | @Override |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4851 | public void onLowMemory() { |
| 4852 | } |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4853 | @Override |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 4854 | public void onTrimMemory(int level) { |
| 4855 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4856 | }); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4857 | } |
| 4858 | |
Romain Guy | 5e9120d | 2012-01-30 12:17:22 -0800 | [diff] [blame] | 4859 | public static ActivityThread systemMain() { |
Dianne Hackborn | 5d927c2 | 2011-09-02 12:22:18 -0700 | [diff] [blame] | 4860 | HardwareRenderer.disable(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4861 | ActivityThread thread = new ActivityThread(); |
| 4862 | thread.attach(true); |
| 4863 | return thread; |
| 4864 | } |
| 4865 | |
Jeff Brown | 10e8971 | 2011-07-08 18:52:57 -0700 | [diff] [blame] | 4866 | public final void installSystemProviders(List<ProviderInfo> providers) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4867 | if (providers != null) { |
Jeff Brown | 10e8971 | 2011-07-08 18:52:57 -0700 | [diff] [blame] | 4868 | installContentProviders(mInitialApplication, providers); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4869 | } |
| 4870 | } |
| 4871 | |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 4872 | public int getIntCoreSetting(String key, int defaultValue) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4873 | synchronized (mResourcesManager) { |
Svetoslav Ganov | 9aa597e | 2011-03-03 18:17:41 -0800 | [diff] [blame] | 4874 | if (mCoreSettings != null) { |
| 4875 | return mCoreSettings.getInt(key, defaultValue); |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 4876 | } |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4877 | return defaultValue; |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 4878 | } |
| 4879 | } |
| 4880 | |
Geremy Condra | 69689a7 | 2012-09-11 16:57:17 -0700 | [diff] [blame] | 4881 | private static class EventLoggingReporter implements EventLogger.Reporter { |
| 4882 | @Override |
| 4883 | public void report (int code, Object... list) { |
| 4884 | EventLog.writeEvent(code, list); |
| 4885 | } |
| 4886 | } |
| 4887 | |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 4888 | private class DropBoxReporter implements DropBox.Reporter { |
| 4889 | |
| 4890 | private DropBoxManager dropBox; |
| 4891 | |
| 4892 | public DropBoxReporter() { |
| 4893 | dropBox = (DropBoxManager) getSystemContext().getSystemService(Context.DROPBOX_SERVICE); |
| 4894 | } |
| 4895 | |
| 4896 | @Override |
| 4897 | public void addData(String tag, byte[] data, int flags) { |
| 4898 | dropBox.addData(tag, data, flags); |
| 4899 | } |
| 4900 | |
| 4901 | @Override |
| 4902 | public void addText(String tag, String data) { |
| 4903 | dropBox.addText(tag, data); |
| 4904 | } |
| 4905 | } |
| 4906 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 4907 | public static void main(String[] args) { |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4908 | SamplingProfilerIntegration.start(); |
| 4909 | |
Brad Fitzpatrick | 4d9e6d2 | 2010-11-15 08:49:51 -0800 | [diff] [blame] | 4910 | // CloseGuard defaults to true and can be quite spammy. We |
| 4911 | // disable it here, but selectively enable it later (via |
| 4912 | // StrictMode) on debug builds, but using DropBox, not logs. |
| 4913 | CloseGuard.setEnabled(false); |
| 4914 | |
Jeff Sharkey | b049e21 | 2012-09-07 23:16:01 -0700 | [diff] [blame] | 4915 | Environment.initForCurrentUser(); |
| 4916 | |
Geremy Condra | 69689a7 | 2012-09-11 16:57:17 -0700 | [diff] [blame] | 4917 | // Set the reporter for event logging in libcore |
| 4918 | EventLogger.setReporter(new EventLoggingReporter()); |
| 4919 | |
Kenny Root | 8b51475 | 2013-02-04 09:35:16 -0800 | [diff] [blame] | 4920 | Security.addProvider(new AndroidKeyStoreProvider()); |
| 4921 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4922 | Process.setArgV0("<pre-initialized>"); |
| 4923 | |
| 4924 | Looper.prepareMainLooper(); |
| 4925 | |
| 4926 | ActivityThread thread = new ActivityThread(); |
| 4927 | thread.attach(false); |
| 4928 | |
Vairavan Srinivasan | 7335cfd | 2012-08-18 18:36:03 -0700 | [diff] [blame] | 4929 | if (sMainThreadHandler == null) { |
| 4930 | sMainThreadHandler = thread.getHandler(); |
| 4931 | } |
| 4932 | |
Romain Guy | 5e9120d | 2012-01-30 12:17:22 -0800 | [diff] [blame] | 4933 | AsyncTask.init(); |
| 4934 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 4935 | if (false) { |
| 4936 | Looper.myLooper().setMessageLogging(new |
| 4937 | LogPrinter(Log.DEBUG, "ActivityThread")); |
| 4938 | } |
| 4939 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4940 | Looper.loop(); |
| 4941 | |
Jeff Brown | 10e8971 | 2011-07-08 18:52:57 -0700 | [diff] [blame] | 4942 | throw new RuntimeException("Main thread loop unexpectedly exited"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4943 | } |
| 4944 | } |