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