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