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