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