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