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