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