blob: b409f2fa84c3770325896f9d39c732b10b1b8eda [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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
17package android.app;
18
Christopher Tate45281862010-03-05 15:46:30 -080019import android.app.backup.BackupAgent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080020import android.content.BroadcastReceiver;
21import android.content.ComponentCallbacks;
22import android.content.ComponentName;
23import android.content.ContentProvider;
24import android.content.Context;
25import android.content.IContentProvider;
26import android.content.Intent;
Suchi Amalapurapu1ccac752009-06-12 10:09:58 -070027import android.content.IIntentReceiver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028import android.content.pm.ActivityInfo;
29import android.content.pm.ApplicationInfo;
30import android.content.pm.IPackageManager;
31import android.content.pm.InstrumentationInfo;
32import android.content.pm.PackageManager;
Sen Hubde75702010-05-28 01:54:03 -070033import android.content.pm.PackageManager.NameNotFoundException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080034import android.content.pm.ProviderInfo;
35import android.content.pm.ServiceInfo;
36import android.content.res.AssetManager;
Mitsuru Oshimaba3ba572009-07-08 18:49:26 -070037import android.content.res.CompatibilityInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080038import android.content.res.Configuration;
39import android.content.res.Resources;
40import android.database.sqlite.SQLiteDatabase;
41import android.database.sqlite.SQLiteDebug;
Vasu Noric3849202010-03-09 10:47:25 -080042import android.database.sqlite.SQLiteDebug.DbStats;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043import android.graphics.Bitmap;
44import android.graphics.Canvas;
Robert Greenwalt434203a2010-10-11 16:00:27 -070045import android.net.IConnectivityManager;
46import android.net.Proxy;
47import android.net.ProxyProperties;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080048import android.os.Bundle;
49import android.os.Debug;
50import android.os.Handler;
51import android.os.IBinder;
52import android.os.Looper;
53import android.os.Message;
54import android.os.MessageQueue;
Dianne Hackborn9c8dd552009-06-23 19:22:52 -070055import android.os.ParcelFileDescriptor;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056import android.os.Process;
57import android.os.RemoteException;
58import android.os.ServiceManager;
Brad Fitzpatrick438d0592010-06-10 12:19:19 -070059import android.os.StrictMode;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060import android.os.SystemClock;
61import android.util.AndroidRuntimeException;
62import android.util.Config;
63import android.util.DisplayMetrics;
64import android.util.EventLog;
65import android.util.Log;
Dianne Hackborn287952c2010-09-22 22:34:31 -070066import android.util.LogPrinter;
Dianne Hackbornc9421ba2010-03-11 22:23:46 -080067import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080068import android.view.Display;
Romain Guy52339202010-09-03 16:04:46 -070069import android.view.HardwareRenderer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080070import android.view.View;
71import android.view.ViewDebug;
72import android.view.ViewManager;
Dianne Hackborn2a9094d2010-02-03 19:20:09 -080073import android.view.ViewRoot;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080074import android.view.Window;
75import android.view.WindowManager;
76import android.view.WindowManagerImpl;
77
78import com.android.internal.os.BinderInternal;
79import com.android.internal.os.RuntimeInit;
Bob Leee5408332009-09-04 18:31:17 -070080import com.android.internal.os.SamplingProfilerIntegration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080081
82import org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl;
83
84import java.io.File;
85import java.io.FileDescriptor;
86import java.io.FileOutputStream;
Dianne Hackborn9c8dd552009-06-23 19:22:52 -070087import java.io.IOException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080088import java.io.PrintWriter;
89import java.lang.ref.WeakReference;
Robert Greenwalt03595d02010-11-02 14:08:23 -070090import java.net.InetAddress;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080091import java.util.ArrayList;
92import java.util.HashMap;
93import java.util.Iterator;
94import java.util.List;
95import java.util.Locale;
96import java.util.Map;
97import java.util.TimeZone;
98import java.util.regex.Pattern;
99
Brad Fitzpatrick4d9e6d22010-11-15 08:49:51 -0800100import dalvik.system.CloseGuard;
Bob Leee5408332009-09-04 18:31:17 -0700101
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800102final class SuperNotCalledException extends AndroidRuntimeException {
103 public SuperNotCalledException(String msg) {
104 super(msg);
105 }
106}
107
Dianne Hackborn9d39d0c2010-06-24 15:57:42 -0700108final class RemoteServiceException extends AndroidRuntimeException {
109 public RemoteServiceException(String msg) {
110 super(msg);
111 }
112}
113
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800114/**
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 */
122public final class ActivityThread {
Dianne Hackborne829fef2010-10-26 17:44:01 -0700123 /** @hide */
124 public static final String TAG = "ActivityThread";
Jim Miller0b2a6d02010-07-13 18:01:29 -0700125 private static final android.graphics.Bitmap.Config THUMBNAIL_FORMAT = Bitmap.Config.RGB_565;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800126 private static final boolean DEBUG = false;
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700127 static final boolean localLOGV = DEBUG ? Config.LOGD : Config.LOGV;
Dianne Hackborn287952c2010-09-22 22:34:31 -0700128 static final boolean DEBUG_MESSAGES = false;
Dianne Hackborne829fef2010-10-26 17:44:01 -0700129 /** @hide */
130 public static final boolean DEBUG_BROADCAST = false;
Chris Tate8a7dc172009-03-24 20:11:42 -0700131 private static final boolean DEBUG_RESULTS = false;
Christopher Tate436344a2009-09-30 16:17:37 -0700132 private static final boolean DEBUG_BACKUP = false;
Dianne Hackborndc6b6352009-09-30 14:20:09 -0700133 private static final boolean DEBUG_CONFIGURATION = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800134 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 Hackborn01e4cfc2010-06-24 15:07:24 -0700140 static ContextImpl mSystemContext = null;
Bob Leee5408332009-09-04 18:31:17 -0700141
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700142 static IPackageManager sPackageManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800143
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700144 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;
158 Configuration mResConfiguration;
159 Application mInitialApplication;
160 final ArrayList<Application> mAllApplications
161 = new ArrayList<Application>();
162 // set of instantiated backup agents, keyed by package name
163 final HashMap<String, BackupAgent> mBackupAgents = new HashMap<String, BackupAgent>();
Brad Fitzpatrick333b8cb2010-08-26 12:04:57 -0700164 static final ThreadLocal<ActivityThread> sThreadLocal = new ThreadLocal();
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700165 Instrumentation mInstrumentation;
166 String mInstrumentationAppDir = null;
167 String mInstrumentationAppPackage = null;
168 String mInstrumentedAppDir = null;
169 boolean mSystemThread = false;
170 boolean mJitEnabled = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800171
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700172 // These can be accessed by multiple threads; mPackages is the lock.
173 // XXX For now we keep around information about all packages we have
174 // seen, not removing entries from this map.
175 final HashMap<String, WeakReference<LoadedApk>> mPackages
176 = new HashMap<String, WeakReference<LoadedApk>>();
177 final HashMap<String, WeakReference<LoadedApk>> mResourcePackages
178 = new HashMap<String, WeakReference<LoadedApk>>();
179 Display mDisplay = null;
180 DisplayMetrics mDisplayMetrics = null;
181 final HashMap<ResourcesKey, WeakReference<Resources> > mActiveResources
182 = new HashMap<ResourcesKey, WeakReference<Resources> >();
183 final ArrayList<ActivityClientRecord> mRelaunchingActivities
184 = new ArrayList<ActivityClientRecord>();
185 Configuration mPendingConfiguration = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800186
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700187 // The lock of mProviderMap protects the following variables.
188 final HashMap<String, ProviderClientRecord> mProviderMap
189 = new HashMap<String, ProviderClientRecord>();
190 final HashMap<IBinder, ProviderRefCount> mProviderRefCountMap
191 = new HashMap<IBinder, ProviderRefCount>();
192 final HashMap<IBinder, ProviderClientRecord> mLocalProviders
193 = new HashMap<IBinder, ProviderClientRecord>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800194
Jeff Hamilton52d32032011-01-08 15:31:26 -0600195 final HashMap<Activity, ArrayList<OnActivityPausedListener>> mOnPauseListeners
196 = new HashMap<Activity, ArrayList<OnActivityPausedListener>>();
197
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700198 final GcIdler mGcIdler = new GcIdler();
199 boolean mGcIdlerScheduled = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800200
Brad Fitzpatrick333b8cb2010-08-26 12:04:57 -0700201 static Handler sMainThreadHandler; // set once in main()
202
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700203 private static final class ActivityClientRecord {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800204 IBinder token;
Dianne Hackbornb06ea702009-07-13 13:07:51 -0700205 int ident;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800206 Intent intent;
207 Bundle state;
208 Activity activity;
209 Window window;
210 Activity parent;
211 String embeddedID;
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700212 Activity.NonConfigurationInstances lastNonConfigurationInstances;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800213 boolean paused;
214 boolean stopped;
215 boolean hideForNow;
216 Configuration newConfig;
Dianne Hackborne88846e2009-09-30 21:34:25 -0700217 Configuration createdConfig;
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700218 ActivityClientRecord nextIdle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800219
220 ActivityInfo activityInfo;
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700221 LoadedApk packageInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800222
223 List<ResultInfo> pendingResults;
224 List<Intent> pendingIntents;
225
226 boolean startsNotResumed;
227 boolean isForward;
Dianne Hackborn30c9bd82010-12-01 16:07:40 -0800228 int pendingConfigChanges;
229 boolean onlyLocalRequest;
230
231 View mPendingRemoveWindow;
232 WindowManager mPendingRemoveWindowManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800233
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700234 ActivityClientRecord() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800235 parent = null;
236 embeddedID = null;
237 paused = false;
238 stopped = false;
239 hideForNow = false;
240 nextIdle = null;
241 }
242
Dianne Hackborn0aae2d42010-12-07 23:51:29 -0800243 public boolean isPreHoneycomb() {
244 if (activity != null) {
245 return activity.getApplicationInfo().targetSdkVersion
246 < android.os.Build.VERSION_CODES.HONEYCOMB;
247 }
248 return false;
249 }
250
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800251 public String toString() {
252 ComponentName componentName = intent.getComponent();
253 return "ActivityRecord{"
254 + Integer.toHexString(System.identityHashCode(this))
255 + " token=" + token + " " + (componentName == null
256 ? "no component name" : componentName.toShortString())
257 + "}";
258 }
259 }
260
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700261 private final class ProviderClientRecord implements IBinder.DeathRecipient {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800262 final String mName;
263 final IContentProvider mProvider;
264 final ContentProvider mLocalProvider;
265
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700266 ProviderClientRecord(String name, IContentProvider provider,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800267 ContentProvider localProvider) {
268 mName = name;
269 mProvider = provider;
270 mLocalProvider = localProvider;
271 }
272
273 public void binderDied() {
274 removeDeadProvider(mName, mProvider);
275 }
276 }
277
278 private static final class NewIntentData {
279 List<Intent> intents;
280 IBinder token;
281 public String toString() {
282 return "NewIntentData{intents=" + intents + " token=" + token + "}";
283 }
284 }
285
Dianne Hackborne829fef2010-10-26 17:44:01 -0700286 private static final class ReceiverData extends BroadcastReceiver.PendingResult {
287 public ReceiverData(Intent intent, int resultCode, String resultData, Bundle resultExtras,
288 boolean ordered, boolean sticky, IBinder token) {
289 super(resultCode, resultData, resultExtras, TYPE_COMPONENT, ordered, sticky, token);
290 this.intent = intent;
291 }
Robert Greenwalt434203a2010-10-11 16:00:27 -0700292
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800293 Intent intent;
294 ActivityInfo info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800295 public String toString() {
296 return "ReceiverData{intent=" + intent + " packageName=" +
Dianne Hackborne829fef2010-10-26 17:44:01 -0700297 info.packageName + " resultCode=" + getResultCode()
298 + " resultData=" + getResultData() + " resultExtras="
299 + getResultExtras(false) + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800300 }
301 }
302
Christopher Tate181fafa2009-05-14 11:12:14 -0700303 private static final class CreateBackupAgentData {
304 ApplicationInfo appInfo;
305 int backupMode;
306 public String toString() {
307 return "CreateBackupAgentData{appInfo=" + appInfo
308 + " backupAgent=" + appInfo.backupAgentName
309 + " mode=" + backupMode + "}";
310 }
311 }
Bob Leee5408332009-09-04 18:31:17 -0700312
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800313 private static final class CreateServiceData {
314 IBinder token;
315 ServiceInfo info;
316 Intent intent;
317 public String toString() {
318 return "CreateServiceData{token=" + token + " className="
319 + info.name + " packageName=" + info.packageName
320 + " intent=" + intent + "}";
321 }
322 }
323
324 private static final class BindServiceData {
325 IBinder token;
326 Intent intent;
327 boolean rebind;
328 public String toString() {
329 return "BindServiceData{token=" + token + " intent=" + intent + "}";
330 }
331 }
332
333 private static final class ServiceArgsData {
334 IBinder token;
335 int startId;
Dianne Hackbornf6f9f2d2009-08-21 16:26:03 -0700336 int flags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800337 Intent args;
338 public String toString() {
339 return "ServiceArgsData{token=" + token + " startId=" + startId
340 + " args=" + args + "}";
341 }
342 }
343
344 private static final class AppBindData {
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700345 LoadedApk info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800346 String processName;
347 ApplicationInfo appInfo;
348 List<ProviderInfo> providers;
349 ComponentName instrumentationName;
350 String profileFile;
351 Bundle instrumentationArgs;
352 IInstrumentationWatcher instrumentationWatcher;
353 int debugMode;
Christopher Tate181fafa2009-05-14 11:12:14 -0700354 boolean restrictedBackupMode;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800355 Configuration config;
356 boolean handlingProfiling;
Svetoslav Ganov54d068e2011-03-02 12:58:40 -0800357 Bundle coreSettings;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800358 public String toString() {
359 return "AppBindData{appInfo=" + appInfo + "}";
360 }
361 }
362
Dianne Hackborn625ac272010-09-17 18:29:22 -0700363 private static final class DumpComponentInfo {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800364 FileDescriptor fd;
Dianne Hackborn625ac272010-09-17 18:29:22 -0700365 IBinder token;
Dianne Hackborn30d71892010-12-11 10:37:55 -0800366 String prefix;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800367 String[] args;
368 boolean dumped;
369 }
370
371 private static final class ResultData {
372 IBinder token;
373 List<ResultInfo> results;
374 public String toString() {
375 return "ResultData{token=" + token + " results" + results + "}";
376 }
377 }
378
379 private static final class ContextCleanupInfo {
Dianne Hackborn21556372010-02-04 16:34:40 -0800380 ContextImpl context;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800381 String what;
382 String who;
383 }
384
Dianne Hackborn9c8dd552009-06-23 19:22:52 -0700385 private static final class ProfilerControlData {
386 String path;
387 ParcelFileDescriptor fd;
388 }
389
Andy McFadden824c5102010-07-09 16:26:57 -0700390 private static final class DumpHeapData {
391 String path;
392 ParcelFileDescriptor fd;
393 }
394
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800395 private final class ApplicationThread extends ApplicationThreadNative {
396 private static final String HEAP_COLUMN = "%17s %8s %8s %8s %8s";
397 private static final String ONE_COUNT_COLUMN = "%17s %8d";
398 private static final String TWO_COUNT_COLUMNS = "%17s %8d %17s %8d";
Vasu Nori3c7131f2010-09-21 14:36:57 -0700399 private static final String TWO_COUNT_COLUMNS_DB = "%20s %8d %20s %8d";
400 private static final String DB_INFO_FORMAT = " %8s %8s %14s %14s %s";
Bob Leee5408332009-09-04 18:31:17 -0700401
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800402 // Formatting for checkin service - update version if row format changes
403 private static final int ACTIVITY_THREAD_CHECKIN_VERSION = 1;
Bob Leee5408332009-09-04 18:31:17 -0700404
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800405 public final void schedulePauseActivity(IBinder token, boolean finished,
406 boolean userLeaving, int configChanges) {
407 queueOrSendMessage(
408 finished ? H.PAUSE_ACTIVITY_FINISHING : H.PAUSE_ACTIVITY,
409 token,
410 (userLeaving ? 1 : 0),
411 configChanges);
412 }
413
414 public final void scheduleStopActivity(IBinder token, boolean showWindow,
415 int configChanges) {
416 queueOrSendMessage(
417 showWindow ? H.STOP_ACTIVITY_SHOW : H.STOP_ACTIVITY_HIDE,
418 token, 0, configChanges);
419 }
420
421 public final void scheduleWindowVisibility(IBinder token, boolean showWindow) {
422 queueOrSendMessage(
423 showWindow ? H.SHOW_WINDOW : H.HIDE_WINDOW,
424 token);
425 }
426
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800427 public final void scheduleSleeping(IBinder token, boolean sleeping) {
428 queueOrSendMessage(H.SLEEPING, token, sleeping ? 1 : 0);
429 }
430
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800431 public final void scheduleResumeActivity(IBinder token, boolean isForward) {
432 queueOrSendMessage(H.RESUME_ACTIVITY, token, isForward ? 1 : 0);
433 }
434
435 public final void scheduleSendResult(IBinder token, List<ResultInfo> results) {
436 ResultData res = new ResultData();
437 res.token = token;
438 res.results = results;
439 queueOrSendMessage(H.SEND_RESULT, res);
440 }
441
442 // we use token to identify this activity without having to send the
443 // activity itself back to the activity manager. (matters more with ipc)
Dianne Hackbornb06ea702009-07-13 13:07:51 -0700444 public final void scheduleLaunchActivity(Intent intent, IBinder token, int ident,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800445 ActivityInfo info, Bundle state, List<ResultInfo> pendingResults,
446 List<Intent> pendingNewIntents, boolean notResumed, boolean isForward) {
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700447 ActivityClientRecord r = new ActivityClientRecord();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800448
449 r.token = token;
Dianne Hackbornb06ea702009-07-13 13:07:51 -0700450 r.ident = ident;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800451 r.intent = intent;
452 r.activityInfo = info;
453 r.state = state;
454
455 r.pendingResults = pendingResults;
456 r.pendingIntents = pendingNewIntents;
457
458 r.startsNotResumed = notResumed;
459 r.isForward = isForward;
460
461 queueOrSendMessage(H.LAUNCH_ACTIVITY, r);
462 }
463
464 public final void scheduleRelaunchActivity(IBinder token,
465 List<ResultInfo> pendingResults, List<Intent> pendingNewIntents,
Dianne Hackborn871ecdc2009-12-11 15:24:33 -0800466 int configChanges, boolean notResumed, Configuration config) {
Dianne Hackborn30c9bd82010-12-01 16:07:40 -0800467 requestRelaunchActivity(token, pendingResults, pendingNewIntents,
468 configChanges, notResumed, config, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800469 }
470
471 public final void scheduleNewIntent(List<Intent> intents, IBinder token) {
472 NewIntentData data = new NewIntentData();
473 data.intents = intents;
474 data.token = token;
475
476 queueOrSendMessage(H.NEW_INTENT, data);
477 }
478
479 public final void scheduleDestroyActivity(IBinder token, boolean finishing,
480 int configChanges) {
481 queueOrSendMessage(H.DESTROY_ACTIVITY, token, finishing ? 1 : 0,
482 configChanges);
483 }
484
485 public final void scheduleReceiver(Intent intent, ActivityInfo info,
486 int resultCode, String data, Bundle extras, boolean sync) {
Dianne Hackborne829fef2010-10-26 17:44:01 -0700487 ReceiverData r = new ReceiverData(intent, resultCode, data, extras,
488 sync, false, mAppThread.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800489 r.info = info;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800490 queueOrSendMessage(H.RECEIVER, r);
491 }
492
Christopher Tate181fafa2009-05-14 11:12:14 -0700493 public final void scheduleCreateBackupAgent(ApplicationInfo app, int backupMode) {
494 CreateBackupAgentData d = new CreateBackupAgentData();
495 d.appInfo = app;
496 d.backupMode = backupMode;
497
498 queueOrSendMessage(H.CREATE_BACKUP_AGENT, d);
499 }
500
501 public final void scheduleDestroyBackupAgent(ApplicationInfo app) {
502 CreateBackupAgentData d = new CreateBackupAgentData();
503 d.appInfo = app;
504
505 queueOrSendMessage(H.DESTROY_BACKUP_AGENT, d);
506 }
507
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800508 public final void scheduleCreateService(IBinder token,
509 ServiceInfo info) {
510 CreateServiceData s = new CreateServiceData();
511 s.token = token;
512 s.info = info;
513
514 queueOrSendMessage(H.CREATE_SERVICE, s);
515 }
516
517 public final void scheduleBindService(IBinder token, Intent intent,
518 boolean rebind) {
519 BindServiceData s = new BindServiceData();
520 s.token = token;
521 s.intent = intent;
522 s.rebind = rebind;
523
524 queueOrSendMessage(H.BIND_SERVICE, s);
525 }
526
527 public final void scheduleUnbindService(IBinder token, Intent intent) {
528 BindServiceData s = new BindServiceData();
529 s.token = token;
530 s.intent = intent;
531
532 queueOrSendMessage(H.UNBIND_SERVICE, s);
533 }
534
535 public final void scheduleServiceArgs(IBinder token, int startId,
Dianne Hackbornf6f9f2d2009-08-21 16:26:03 -0700536 int flags ,Intent args) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800537 ServiceArgsData s = new ServiceArgsData();
538 s.token = token;
539 s.startId = startId;
Dianne Hackbornf6f9f2d2009-08-21 16:26:03 -0700540 s.flags = flags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800541 s.args = args;
542
543 queueOrSendMessage(H.SERVICE_ARGS, s);
544 }
545
546 public final void scheduleStopService(IBinder token) {
547 queueOrSendMessage(H.STOP_SERVICE, token);
548 }
549
550 public final void bindApplication(String processName,
551 ApplicationInfo appInfo, List<ProviderInfo> providers,
552 ComponentName instrumentationName, String profileFile,
553 Bundle instrumentationArgs, IInstrumentationWatcher instrumentationWatcher,
Christopher Tate181fafa2009-05-14 11:12:14 -0700554 int debugMode, boolean isRestrictedBackupMode, Configuration config,
Svetoslav Ganov54d068e2011-03-02 12:58:40 -0800555 Map<String, IBinder> services, Bundle coreSettings) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800556
557 if (services != null) {
558 // Setup the service cache in the ServiceManager
559 ServiceManager.initServiceCache(services);
560 }
561
562 AppBindData data = new AppBindData();
563 data.processName = processName;
564 data.appInfo = appInfo;
565 data.providers = providers;
566 data.instrumentationName = instrumentationName;
567 data.profileFile = profileFile;
568 data.instrumentationArgs = instrumentationArgs;
569 data.instrumentationWatcher = instrumentationWatcher;
570 data.debugMode = debugMode;
Christopher Tate181fafa2009-05-14 11:12:14 -0700571 data.restrictedBackupMode = isRestrictedBackupMode;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800572 data.config = config;
Svetoslav Ganov54d068e2011-03-02 12:58:40 -0800573 data.coreSettings = coreSettings;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800574 queueOrSendMessage(H.BIND_APPLICATION, data);
575 }
576
577 public final void scheduleExit() {
578 queueOrSendMessage(H.EXIT_APPLICATION, null);
579 }
580
Christopher Tate5e1ab332009-09-01 20:32:49 -0700581 public final void scheduleSuicide() {
582 queueOrSendMessage(H.SUICIDE, null);
583 }
584
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800585 public void requestThumbnail(IBinder token) {
586 queueOrSendMessage(H.REQUEST_THUMBNAIL, token);
587 }
588
589 public void scheduleConfigurationChanged(Configuration config) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800590 synchronized (mPackages) {
591 if (mPendingConfiguration == null ||
592 mPendingConfiguration.isOtherSeqNewer(config)) {
593 mPendingConfiguration = config;
594 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800595 }
596 queueOrSendMessage(H.CONFIGURATION_CHANGED, config);
597 }
598
599 public void updateTimeZone() {
600 TimeZone.setDefault(null);
601 }
602
Robert Greenwalt03595d02010-11-02 14:08:23 -0700603 public void clearDnsCache() {
604 // a non-standard API to get this to libcore
605 InetAddress.clearDnsCache();
606 }
607
Robert Greenwalt434203a2010-10-11 16:00:27 -0700608 public void setHttpProxy(String host, String port, String exclList) {
609 Proxy.setHttpProxySystemProperty(host, port, exclList);
610 }
611
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800612 public void processInBackground() {
613 mH.removeMessages(H.GC_WHEN_IDLE);
614 mH.sendMessage(mH.obtainMessage(H.GC_WHEN_IDLE));
615 }
616
617 public void dumpService(FileDescriptor fd, IBinder servicetoken, String[] args) {
Dianne Hackborn625ac272010-09-17 18:29:22 -0700618 DumpComponentInfo data = new DumpComponentInfo();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800619 data.fd = fd;
Dianne Hackborn625ac272010-09-17 18:29:22 -0700620 data.token = servicetoken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800621 data.args = args;
622 data.dumped = false;
623 queueOrSendMessage(H.DUMP_SERVICE, data);
624 synchronized (data) {
625 while (!data.dumped) {
626 try {
627 data.wait();
628 } catch (InterruptedException e) {
629 // no need to do anything here, we will keep waiting until
630 // dumped is set
631 }
632 }
633 }
634 }
635
636 // This function exists to make sure all receiver dispatching is
637 // correctly ordered, since these are one-way calls and the binder driver
638 // applies transaction ordering per object for such calls.
639 public void scheduleRegisteredReceiver(IIntentReceiver receiver, Intent intent,
Dianne Hackborn68d881c2009-10-05 13:58:17 -0700640 int resultCode, String dataStr, Bundle extras, boolean ordered,
641 boolean sticky) throws RemoteException {
642 receiver.performReceive(intent, resultCode, dataStr, extras, ordered, sticky);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800643 }
Bob Leee5408332009-09-04 18:31:17 -0700644
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800645 public void scheduleLowMemory() {
646 queueOrSendMessage(H.LOW_MEMORY, null);
647 }
648
649 public void scheduleActivityConfigurationChanged(IBinder token) {
650 queueOrSendMessage(H.ACTIVITY_CONFIGURATION_CHANGED, token);
651 }
652
Dianne Hackborn9c8dd552009-06-23 19:22:52 -0700653 public void profilerControl(boolean start, String path, ParcelFileDescriptor fd) {
654 ProfilerControlData pcd = new ProfilerControlData();
655 pcd.path = path;
656 pcd.fd = fd;
657 queueOrSendMessage(H.PROFILER_CONTROL, pcd, start ? 1 : 0);
The Android Open Source Projectf5b4b982009-03-05 20:00:43 -0800658 }
659
Andy McFadden824c5102010-07-09 16:26:57 -0700660 public void dumpHeap(boolean managed, String path, ParcelFileDescriptor fd) {
661 DumpHeapData dhd = new DumpHeapData();
662 dhd.path = path;
663 dhd.fd = fd;
664 queueOrSendMessage(H.DUMP_HEAP, dhd, managed ? 1 : 0);
665 }
666
Dianne Hackborn06de2ea2009-05-21 12:56:43 -0700667 public void setSchedulingGroup(int group) {
668 // Note: do this immediately, since going into the foreground
669 // should happen regardless of what pending work we have to do
670 // and the activity manager will wait for us to report back that
671 // we are done before sending us to the background.
672 try {
673 Process.setProcessGroup(Process.myPid(), group);
674 } catch (Exception e) {
Dianne Hackbornc9421ba2010-03-11 22:23:46 -0800675 Slog.w(TAG, "Failed setting process group to " + group, e);
Dianne Hackborn06de2ea2009-05-21 12:56:43 -0700676 }
677 }
Bob Leee5408332009-09-04 18:31:17 -0700678
Dianne Hackborn3025ef32009-08-31 21:31:47 -0700679 public void getMemoryInfo(Debug.MemoryInfo outInfo) {
680 Debug.getMemoryInfo(outInfo);
681 }
Bob Leee5408332009-09-04 18:31:17 -0700682
Dianne Hackborn4416c3d2010-05-04 17:22:49 -0700683 public void dispatchPackageBroadcast(int cmd, String[] packages) {
684 queueOrSendMessage(H.DISPATCH_PACKAGE_BROADCAST, packages, cmd);
685 }
Dianne Hackborn9d39d0c2010-06-24 15:57:42 -0700686
687 public void scheduleCrash(String msg) {
688 queueOrSendMessage(H.SCHEDULE_CRASH, msg);
689 }
Dianne Hackborn625ac272010-09-17 18:29:22 -0700690
Dianne Hackborn30d71892010-12-11 10:37:55 -0800691 public void dumpActivity(FileDescriptor fd, IBinder activitytoken,
692 String prefix, String[] args) {
Dianne Hackborn625ac272010-09-17 18:29:22 -0700693 DumpComponentInfo data = new DumpComponentInfo();
694 data.fd = fd;
695 data.token = activitytoken;
Dianne Hackborn30d71892010-12-11 10:37:55 -0800696 data.prefix = prefix;
Dianne Hackborn625ac272010-09-17 18:29:22 -0700697 data.args = args;
698 data.dumped = false;
699 queueOrSendMessage(H.DUMP_ACTIVITY, data);
700 synchronized (data) {
701 while (!data.dumped) {
702 try {
703 data.wait();
704 } catch (InterruptedException e) {
705 // no need to do anything here, we will keep waiting until
706 // dumped is set
707 }
708 }
709 }
710 }
Dianne Hackborn4416c3d2010-05-04 17:22:49 -0700711
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800712 @Override
713 protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
714 long nativeMax = Debug.getNativeHeapSize() / 1024;
715 long nativeAllocated = Debug.getNativeHeapAllocatedSize() / 1024;
716 long nativeFree = Debug.getNativeHeapFreeSize() / 1024;
717
718 Debug.MemoryInfo memInfo = new Debug.MemoryInfo();
719 Debug.getMemoryInfo(memInfo);
720
721 final int nativeShared = memInfo.nativeSharedDirty;
722 final int dalvikShared = memInfo.dalvikSharedDirty;
723 final int otherShared = memInfo.otherSharedDirty;
724
725 final int nativePrivate = memInfo.nativePrivateDirty;
726 final int dalvikPrivate = memInfo.dalvikPrivateDirty;
727 final int otherPrivate = memInfo.otherPrivateDirty;
728
729 Runtime runtime = Runtime.getRuntime();
730
731 long dalvikMax = runtime.totalMemory() / 1024;
732 long dalvikFree = runtime.freeMemory() / 1024;
733 long dalvikAllocated = dalvikMax - dalvikFree;
734 long viewInstanceCount = ViewDebug.getViewInstanceCount();
735 long viewRootInstanceCount = ViewDebug.getViewRootInstanceCount();
Brian Carlstromc21550a2010-10-05 21:34:06 -0700736 long appContextInstanceCount = Debug.countInstancesOfClass(ContextImpl.class);
737 long activityInstanceCount = Debug.countInstancesOfClass(Activity.class);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800738 int globalAssetCount = AssetManager.getGlobalAssetCount();
739 int globalAssetManagerCount = AssetManager.getGlobalAssetManagerCount();
740 int binderLocalObjectCount = Debug.getBinderLocalObjectCount();
741 int binderProxyObjectCount = Debug.getBinderProxyObjectCount();
742 int binderDeathObjectCount = Debug.getBinderDeathObjectCount();
Brian Carlstromc9d5b312010-10-05 22:23:41 -0700743 long openSslSocketCount = Debug.countInstancesOfClass(OpenSSLSocketImpl.class);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800744 long sqliteAllocated = SQLiteDebug.getHeapAllocatedSize() / 1024;
Vasu Noric3849202010-03-09 10:47:25 -0800745 SQLiteDebug.PagerStats stats = SQLiteDebug.getDatabaseInfo();
Bob Leee5408332009-09-04 18:31:17 -0700746
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800747 // Check to see if we were called by checkin server. If so, print terse format.
748 boolean doCheckinFormat = false;
749 if (args != null) {
750 for (String arg : args) {
751 if ("-c".equals(arg)) doCheckinFormat = true;
752 }
753 }
Bob Leee5408332009-09-04 18:31:17 -0700754
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800755 // For checkin, we print one long comma-separated list of values
756 if (doCheckinFormat) {
757 // NOTE: if you change anything significant below, also consider changing
758 // ACTIVITY_THREAD_CHECKIN_VERSION.
Bob Leee5408332009-09-04 18:31:17 -0700759 String processName = (mBoundApplication != null)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800760 ? mBoundApplication.processName : "unknown";
Bob Leee5408332009-09-04 18:31:17 -0700761
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800762 // Header
763 pw.print(ACTIVITY_THREAD_CHECKIN_VERSION); pw.print(',');
764 pw.print(Process.myPid()); pw.print(',');
765 pw.print(processName); pw.print(',');
Bob Leee5408332009-09-04 18:31:17 -0700766
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800767 // Heap info - max
768 pw.print(nativeMax); pw.print(',');
769 pw.print(dalvikMax); pw.print(',');
770 pw.print("N/A,");
771 pw.print(nativeMax + dalvikMax); pw.print(',');
Bob Leee5408332009-09-04 18:31:17 -0700772
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800773 // Heap info - allocated
774 pw.print(nativeAllocated); pw.print(',');
775 pw.print(dalvikAllocated); pw.print(',');
776 pw.print("N/A,");
777 pw.print(nativeAllocated + dalvikAllocated); pw.print(',');
Bob Leee5408332009-09-04 18:31:17 -0700778
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800779 // Heap info - free
780 pw.print(nativeFree); pw.print(',');
781 pw.print(dalvikFree); pw.print(',');
782 pw.print("N/A,");
783 pw.print(nativeFree + dalvikFree); pw.print(',');
Bob Leee5408332009-09-04 18:31:17 -0700784
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800785 // Heap info - proportional set size
786 pw.print(memInfo.nativePss); pw.print(',');
787 pw.print(memInfo.dalvikPss); pw.print(',');
788 pw.print(memInfo.otherPss); pw.print(',');
789 pw.print(memInfo.nativePss + memInfo.dalvikPss + memInfo.otherPss); pw.print(',');
Bob Leee5408332009-09-04 18:31:17 -0700790
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800791 // Heap info - shared
Bob Leee5408332009-09-04 18:31:17 -0700792 pw.print(nativeShared); pw.print(',');
793 pw.print(dalvikShared); pw.print(',');
794 pw.print(otherShared); pw.print(',');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800795 pw.print(nativeShared + dalvikShared + otherShared); pw.print(',');
Bob Leee5408332009-09-04 18:31:17 -0700796
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800797 // Heap info - private
Bob Leee5408332009-09-04 18:31:17 -0700798 pw.print(nativePrivate); pw.print(',');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800799 pw.print(dalvikPrivate); pw.print(',');
800 pw.print(otherPrivate); pw.print(',');
801 pw.print(nativePrivate + dalvikPrivate + otherPrivate); pw.print(',');
Bob Leee5408332009-09-04 18:31:17 -0700802
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800803 // Object counts
804 pw.print(viewInstanceCount); pw.print(',');
805 pw.print(viewRootInstanceCount); pw.print(',');
806 pw.print(appContextInstanceCount); pw.print(',');
807 pw.print(activityInstanceCount); pw.print(',');
Bob Leee5408332009-09-04 18:31:17 -0700808
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800809 pw.print(globalAssetCount); pw.print(',');
810 pw.print(globalAssetManagerCount); pw.print(',');
811 pw.print(binderLocalObjectCount); pw.print(',');
812 pw.print(binderProxyObjectCount); pw.print(',');
Bob Leee5408332009-09-04 18:31:17 -0700813
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800814 pw.print(binderDeathObjectCount); pw.print(',');
815 pw.print(openSslSocketCount); pw.print(',');
Bob Leee5408332009-09-04 18:31:17 -0700816
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800817 // SQL
818 pw.print(sqliteAllocated); pw.print(',');
Vasu Noric3849202010-03-09 10:47:25 -0800819 pw.print(stats.memoryUsed / 1024); pw.print(',');
820 pw.print(stats.pageCacheOverflo / 1024); pw.print(',');
821 pw.print(stats.largestMemAlloc / 1024); pw.print(',');
822 for (int i = 0; i < stats.dbStats.size(); i++) {
823 DbStats dbStats = stats.dbStats.get(i);
824 printRow(pw, DB_INFO_FORMAT, dbStats.pageSize, dbStats.dbSize,
Vasu Nori90a367262010-04-12 12:49:09 -0700825 dbStats.lookaside, dbStats.cache, dbStats.dbName);
Vasu Noric3849202010-03-09 10:47:25 -0800826 pw.print(',');
827 }
Bob Leee5408332009-09-04 18:31:17 -0700828
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800829 return;
830 }
Bob Leee5408332009-09-04 18:31:17 -0700831
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800832 // otherwise, show human-readable format
833 printRow(pw, HEAP_COLUMN, "", "native", "dalvik", "other", "total");
834 printRow(pw, HEAP_COLUMN, "size:", nativeMax, dalvikMax, "N/A", nativeMax + dalvikMax);
835 printRow(pw, HEAP_COLUMN, "allocated:", nativeAllocated, dalvikAllocated, "N/A",
836 nativeAllocated + dalvikAllocated);
837 printRow(pw, HEAP_COLUMN, "free:", nativeFree, dalvikFree, "N/A",
838 nativeFree + dalvikFree);
839
840 printRow(pw, HEAP_COLUMN, "(Pss):", memInfo.nativePss, memInfo.dalvikPss,
841 memInfo.otherPss, memInfo.nativePss + memInfo.dalvikPss + memInfo.otherPss);
842
843 printRow(pw, HEAP_COLUMN, "(shared dirty):", nativeShared, dalvikShared, otherShared,
844 nativeShared + dalvikShared + otherShared);
845 printRow(pw, HEAP_COLUMN, "(priv dirty):", nativePrivate, dalvikPrivate, otherPrivate,
846 nativePrivate + dalvikPrivate + otherPrivate);
847
848 pw.println(" ");
849 pw.println(" Objects");
850 printRow(pw, TWO_COUNT_COLUMNS, "Views:", viewInstanceCount, "ViewRoots:",
851 viewRootInstanceCount);
852
853 printRow(pw, TWO_COUNT_COLUMNS, "AppContexts:", appContextInstanceCount,
854 "Activities:", activityInstanceCount);
855
856 printRow(pw, TWO_COUNT_COLUMNS, "Assets:", globalAssetCount,
857 "AssetManagers:", globalAssetManagerCount);
858
859 printRow(pw, TWO_COUNT_COLUMNS, "Local Binders:", binderLocalObjectCount,
860 "Proxy Binders:", binderProxyObjectCount);
861 printRow(pw, ONE_COUNT_COLUMN, "Death Recipients:", binderDeathObjectCount);
862
863 printRow(pw, ONE_COUNT_COLUMN, "OpenSSL Sockets:", openSslSocketCount);
Bob Leee5408332009-09-04 18:31:17 -0700864
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800865 // SQLite mem info
866 pw.println(" ");
867 pw.println(" SQL");
Vasu Nori3c7131f2010-09-21 14:36:57 -0700868 printRow(pw, TWO_COUNT_COLUMNS_DB, "heap:", sqliteAllocated, "MEMORY_USED:",
Vasu Noric3849202010-03-09 10:47:25 -0800869 stats.memoryUsed / 1024);
Vasu Nori3c7131f2010-09-21 14:36:57 -0700870 printRow(pw, TWO_COUNT_COLUMNS_DB, "PAGECACHE_OVERFLOW:",
871 stats.pageCacheOverflo / 1024, "MALLOC_SIZE:", stats.largestMemAlloc / 1024);
Vasu Noric3849202010-03-09 10:47:25 -0800872 pw.println(" ");
873 int N = stats.dbStats.size();
874 if (N > 0) {
875 pw.println(" DATABASES");
Vasu Nori3c7131f2010-09-21 14:36:57 -0700876 printRow(pw, " %8s %8s %14s %14s %s", "pgsz", "dbsz", "Lookaside(b)", "cache",
877 "Dbname");
Vasu Noric3849202010-03-09 10:47:25 -0800878 for (int i = 0; i < N; i++) {
879 DbStats dbStats = stats.dbStats.get(i);
Vasu Nori3c7131f2010-09-21 14:36:57 -0700880 printRow(pw, DB_INFO_FORMAT,
881 (dbStats.pageSize > 0) ? String.valueOf(dbStats.pageSize) : " ",
882 (dbStats.dbSize > 0) ? String.valueOf(dbStats.dbSize) : " ",
883 (dbStats.lookaside > 0) ? String.valueOf(dbStats.lookaside) : " ",
884 dbStats.cache, dbStats.dbName);
Vasu Noric3849202010-03-09 10:47:25 -0800885 }
886 }
Bob Leee5408332009-09-04 18:31:17 -0700887
Dianne Hackborn82e1ee92009-08-11 18:56:41 -0700888 // Asset details.
889 String assetAlloc = AssetManager.getAssetAllocations();
890 if (assetAlloc != null) {
891 pw.println(" ");
892 pw.println(" Asset Allocations");
893 pw.print(assetAlloc);
894 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800895 }
896
897 private void printRow(PrintWriter pw, String format, Object...objs) {
898 pw.println(String.format(format, objs));
899 }
Svetoslav Ganov54d068e2011-03-02 12:58:40 -0800900
901 public void setCoreSettings(Bundle settings) {
902 queueOrSendMessage(H.SET_CORE_SETTINGS, settings);
903 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800904 }
905
906 private final class H extends Handler {
907 public static final int LAUNCH_ACTIVITY = 100;
908 public static final int PAUSE_ACTIVITY = 101;
909 public static final int PAUSE_ACTIVITY_FINISHING= 102;
910 public static final int STOP_ACTIVITY_SHOW = 103;
911 public static final int STOP_ACTIVITY_HIDE = 104;
912 public static final int SHOW_WINDOW = 105;
913 public static final int HIDE_WINDOW = 106;
914 public static final int RESUME_ACTIVITY = 107;
915 public static final int SEND_RESULT = 108;
916 public static final int DESTROY_ACTIVITY = 109;
917 public static final int BIND_APPLICATION = 110;
918 public static final int EXIT_APPLICATION = 111;
919 public static final int NEW_INTENT = 112;
920 public static final int RECEIVER = 113;
921 public static final int CREATE_SERVICE = 114;
922 public static final int SERVICE_ARGS = 115;
923 public static final int STOP_SERVICE = 116;
924 public static final int REQUEST_THUMBNAIL = 117;
925 public static final int CONFIGURATION_CHANGED = 118;
926 public static final int CLEAN_UP_CONTEXT = 119;
927 public static final int GC_WHEN_IDLE = 120;
928 public static final int BIND_SERVICE = 121;
929 public static final int UNBIND_SERVICE = 122;
930 public static final int DUMP_SERVICE = 123;
931 public static final int LOW_MEMORY = 124;
932 public static final int ACTIVITY_CONFIGURATION_CHANGED = 125;
933 public static final int RELAUNCH_ACTIVITY = 126;
The Android Open Source Projectf5b4b982009-03-05 20:00:43 -0800934 public static final int PROFILER_CONTROL = 127;
Christopher Tate181fafa2009-05-14 11:12:14 -0700935 public static final int CREATE_BACKUP_AGENT = 128;
Christopher Tate5e1ab332009-09-01 20:32:49 -0700936 public static final int DESTROY_BACKUP_AGENT = 129;
937 public static final int SUICIDE = 130;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700938 public static final int REMOVE_PROVIDER = 131;
Dianne Hackborn2a9094d2010-02-03 19:20:09 -0800939 public static final int ENABLE_JIT = 132;
Dianne Hackborn4416c3d2010-05-04 17:22:49 -0700940 public static final int DISPATCH_PACKAGE_BROADCAST = 133;
Dianne Hackborn9d39d0c2010-06-24 15:57:42 -0700941 public static final int SCHEDULE_CRASH = 134;
Andy McFadden824c5102010-07-09 16:26:57 -0700942 public static final int DUMP_HEAP = 135;
Dianne Hackborn625ac272010-09-17 18:29:22 -0700943 public static final int DUMP_ACTIVITY = 136;
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800944 public static final int SLEEPING = 137;
Svetoslav Ganov54d068e2011-03-02 12:58:40 -0800945 public static final int SET_CORE_SETTINGS = 138;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800946 String codeToString(int code) {
Dianne Hackborn287952c2010-09-22 22:34:31 -0700947 if (DEBUG_MESSAGES) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800948 switch (code) {
949 case LAUNCH_ACTIVITY: return "LAUNCH_ACTIVITY";
950 case PAUSE_ACTIVITY: return "PAUSE_ACTIVITY";
951 case PAUSE_ACTIVITY_FINISHING: return "PAUSE_ACTIVITY_FINISHING";
952 case STOP_ACTIVITY_SHOW: return "STOP_ACTIVITY_SHOW";
953 case STOP_ACTIVITY_HIDE: return "STOP_ACTIVITY_HIDE";
954 case SHOW_WINDOW: return "SHOW_WINDOW";
955 case HIDE_WINDOW: return "HIDE_WINDOW";
956 case RESUME_ACTIVITY: return "RESUME_ACTIVITY";
957 case SEND_RESULT: return "SEND_RESULT";
958 case DESTROY_ACTIVITY: return "DESTROY_ACTIVITY";
959 case BIND_APPLICATION: return "BIND_APPLICATION";
960 case EXIT_APPLICATION: return "EXIT_APPLICATION";
961 case NEW_INTENT: return "NEW_INTENT";
962 case RECEIVER: return "RECEIVER";
963 case CREATE_SERVICE: return "CREATE_SERVICE";
964 case SERVICE_ARGS: return "SERVICE_ARGS";
965 case STOP_SERVICE: return "STOP_SERVICE";
966 case REQUEST_THUMBNAIL: return "REQUEST_THUMBNAIL";
967 case CONFIGURATION_CHANGED: return "CONFIGURATION_CHANGED";
968 case CLEAN_UP_CONTEXT: return "CLEAN_UP_CONTEXT";
969 case GC_WHEN_IDLE: return "GC_WHEN_IDLE";
970 case BIND_SERVICE: return "BIND_SERVICE";
971 case UNBIND_SERVICE: return "UNBIND_SERVICE";
972 case DUMP_SERVICE: return "DUMP_SERVICE";
973 case LOW_MEMORY: return "LOW_MEMORY";
974 case ACTIVITY_CONFIGURATION_CHANGED: return "ACTIVITY_CONFIGURATION_CHANGED";
975 case RELAUNCH_ACTIVITY: return "RELAUNCH_ACTIVITY";
The Android Open Source Projectf5b4b982009-03-05 20:00:43 -0800976 case PROFILER_CONTROL: return "PROFILER_CONTROL";
Christopher Tate181fafa2009-05-14 11:12:14 -0700977 case CREATE_BACKUP_AGENT: return "CREATE_BACKUP_AGENT";
978 case DESTROY_BACKUP_AGENT: return "DESTROY_BACKUP_AGENT";
Christopher Tate5e1ab332009-09-01 20:32:49 -0700979 case SUICIDE: return "SUICIDE";
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700980 case REMOVE_PROVIDER: return "REMOVE_PROVIDER";
Dianne Hackborn2a9094d2010-02-03 19:20:09 -0800981 case ENABLE_JIT: return "ENABLE_JIT";
Dianne Hackborn4416c3d2010-05-04 17:22:49 -0700982 case DISPATCH_PACKAGE_BROADCAST: return "DISPATCH_PACKAGE_BROADCAST";
Dianne Hackborn9d39d0c2010-06-24 15:57:42 -0700983 case SCHEDULE_CRASH: return "SCHEDULE_CRASH";
Andy McFadden824c5102010-07-09 16:26:57 -0700984 case DUMP_HEAP: return "DUMP_HEAP";
Dianne Hackborn625ac272010-09-17 18:29:22 -0700985 case DUMP_ACTIVITY: return "DUMP_ACTIVITY";
Dianne Hackborn4eba96b2011-01-21 13:34:36 -0800986 case SLEEPING: return "SLEEPING";
Svetoslav Ganov54d068e2011-03-02 12:58:40 -0800987 case SET_CORE_SETTINGS: return "SET_CORE_SETTINGS";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800988 }
989 }
990 return "(unknown)";
991 }
992 public void handleMessage(Message msg) {
Dianne Hackborn287952c2010-09-22 22:34:31 -0700993 if (DEBUG_MESSAGES) Slog.v(TAG, ">>> handling: " + msg.what);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800994 switch (msg.what) {
995 case LAUNCH_ACTIVITY: {
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -0700996 ActivityClientRecord r = (ActivityClientRecord)msg.obj;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800997
998 r.packageInfo = getPackageInfoNoCheck(
999 r.activityInfo.applicationInfo);
Christopher Tateb70f3df2009-04-07 16:07:59 -07001000 handleLaunchActivity(r, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001001 } break;
1002 case RELAUNCH_ACTIVITY: {
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07001003 ActivityClientRecord r = (ActivityClientRecord)msg.obj;
Dianne Hackborn30c9bd82010-12-01 16:07:40 -08001004 handleRelaunchActivity(r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001005 } break;
1006 case PAUSE_ACTIVITY:
1007 handlePauseActivity((IBinder)msg.obj, false, msg.arg1 != 0, msg.arg2);
Bob Leee5408332009-09-04 18:31:17 -07001008 maybeSnapshot();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001009 break;
1010 case PAUSE_ACTIVITY_FINISHING:
1011 handlePauseActivity((IBinder)msg.obj, true, msg.arg1 != 0, msg.arg2);
1012 break;
1013 case STOP_ACTIVITY_SHOW:
1014 handleStopActivity((IBinder)msg.obj, true, msg.arg2);
1015 break;
1016 case STOP_ACTIVITY_HIDE:
1017 handleStopActivity((IBinder)msg.obj, false, msg.arg2);
1018 break;
1019 case SHOW_WINDOW:
1020 handleWindowVisibility((IBinder)msg.obj, true);
1021 break;
1022 case HIDE_WINDOW:
1023 handleWindowVisibility((IBinder)msg.obj, false);
1024 break;
1025 case RESUME_ACTIVITY:
1026 handleResumeActivity((IBinder)msg.obj, true,
1027 msg.arg1 != 0);
1028 break;
1029 case SEND_RESULT:
1030 handleSendResult((ResultData)msg.obj);
1031 break;
1032 case DESTROY_ACTIVITY:
1033 handleDestroyActivity((IBinder)msg.obj, msg.arg1 != 0,
1034 msg.arg2, false);
1035 break;
1036 case BIND_APPLICATION:
1037 AppBindData data = (AppBindData)msg.obj;
1038 handleBindApplication(data);
1039 break;
1040 case EXIT_APPLICATION:
1041 if (mInitialApplication != null) {
1042 mInitialApplication.onTerminate();
1043 }
1044 Looper.myLooper().quit();
1045 break;
1046 case NEW_INTENT:
1047 handleNewIntent((NewIntentData)msg.obj);
1048 break;
1049 case RECEIVER:
1050 handleReceiver((ReceiverData)msg.obj);
Bob Leee5408332009-09-04 18:31:17 -07001051 maybeSnapshot();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001052 break;
1053 case CREATE_SERVICE:
1054 handleCreateService((CreateServiceData)msg.obj);
1055 break;
1056 case BIND_SERVICE:
1057 handleBindService((BindServiceData)msg.obj);
1058 break;
1059 case UNBIND_SERVICE:
1060 handleUnbindService((BindServiceData)msg.obj);
1061 break;
1062 case SERVICE_ARGS:
1063 handleServiceArgs((ServiceArgsData)msg.obj);
1064 break;
1065 case STOP_SERVICE:
1066 handleStopService((IBinder)msg.obj);
Bob Leee5408332009-09-04 18:31:17 -07001067 maybeSnapshot();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001068 break;
1069 case REQUEST_THUMBNAIL:
1070 handleRequestThumbnail((IBinder)msg.obj);
1071 break;
1072 case CONFIGURATION_CHANGED:
1073 handleConfigurationChanged((Configuration)msg.obj);
1074 break;
1075 case CLEAN_UP_CONTEXT:
1076 ContextCleanupInfo cci = (ContextCleanupInfo)msg.obj;
1077 cci.context.performFinalCleanup(cci.who, cci.what);
1078 break;
1079 case GC_WHEN_IDLE:
1080 scheduleGcIdler();
1081 break;
1082 case DUMP_SERVICE:
Dianne Hackborn625ac272010-09-17 18:29:22 -07001083 handleDumpService((DumpComponentInfo)msg.obj);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001084 break;
1085 case LOW_MEMORY:
1086 handleLowMemory();
1087 break;
1088 case ACTIVITY_CONFIGURATION_CHANGED:
1089 handleActivityConfigurationChanged((IBinder)msg.obj);
1090 break;
The Android Open Source Projectf5b4b982009-03-05 20:00:43 -08001091 case PROFILER_CONTROL:
Dianne Hackborn9c8dd552009-06-23 19:22:52 -07001092 handleProfilerControl(msg.arg1 != 0, (ProfilerControlData)msg.obj);
The Android Open Source Projectf5b4b982009-03-05 20:00:43 -08001093 break;
Christopher Tate181fafa2009-05-14 11:12:14 -07001094 case CREATE_BACKUP_AGENT:
1095 handleCreateBackupAgent((CreateBackupAgentData)msg.obj);
1096 break;
1097 case DESTROY_BACKUP_AGENT:
1098 handleDestroyBackupAgent((CreateBackupAgentData)msg.obj);
1099 break;
Christopher Tate5e1ab332009-09-01 20:32:49 -07001100 case SUICIDE:
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001101 Process.killProcess(Process.myPid());
1102 break;
1103 case REMOVE_PROVIDER:
1104 completeRemoveProvider((IContentProvider)msg.obj);
Christopher Tate5e1ab332009-09-01 20:32:49 -07001105 break;
Dianne Hackborn2a9094d2010-02-03 19:20:09 -08001106 case ENABLE_JIT:
1107 ensureJitEnabled();
1108 break;
Dianne Hackborn4416c3d2010-05-04 17:22:49 -07001109 case DISPATCH_PACKAGE_BROADCAST:
1110 handleDispatchPackageBroadcast(msg.arg1, (String[])msg.obj);
1111 break;
Dianne Hackborn9d39d0c2010-06-24 15:57:42 -07001112 case SCHEDULE_CRASH:
1113 throw new RemoteServiceException((String)msg.obj);
Andy McFadden824c5102010-07-09 16:26:57 -07001114 case DUMP_HEAP:
1115 handleDumpHeap(msg.arg1 != 0, (DumpHeapData)msg.obj);
1116 break;
Dianne Hackborn625ac272010-09-17 18:29:22 -07001117 case DUMP_ACTIVITY:
1118 handleDumpActivity((DumpComponentInfo)msg.obj);
1119 break;
Dianne Hackborn4eba96b2011-01-21 13:34:36 -08001120 case SLEEPING:
1121 handleSleeping((IBinder)msg.obj, msg.arg1 != 0);
1122 break;
Svetoslav Ganov54d068e2011-03-02 12:58:40 -08001123 case SET_CORE_SETTINGS:
1124 handleSetCoreSettings((Bundle) msg.obj);
1125 break;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001126 }
Dianne Hackborn287952c2010-09-22 22:34:31 -07001127 if (DEBUG_MESSAGES) Slog.v(TAG, "<<< done: " + msg.what);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001128 }
Bob Leee5408332009-09-04 18:31:17 -07001129
1130 void maybeSnapshot() {
1131 if (mBoundApplication != null) {
Sen Hubde75702010-05-28 01:54:03 -07001132 // convert the *private* ActivityThread.PackageInfo to *public* known
1133 // android.content.pm.PackageInfo
1134 String packageName = mBoundApplication.info.mPackageName;
1135 android.content.pm.PackageInfo packageInfo = null;
1136 try {
1137 Context context = getSystemContext();
1138 if(context == null) {
1139 Log.e(TAG, "cannot get a valid context");
1140 return;
1141 }
1142 PackageManager pm = context.getPackageManager();
1143 if(pm == null) {
1144 Log.e(TAG, "cannot get a valid PackageManager");
1145 return;
1146 }
1147 packageInfo = pm.getPackageInfo(
1148 packageName, PackageManager.GET_ACTIVITIES);
1149 } catch (NameNotFoundException e) {
1150 Log.e(TAG, "cannot get package info for " + packageName, e);
1151 }
1152 SamplingProfilerIntegration.writeSnapshot(mBoundApplication.processName, packageInfo);
Bob Leee5408332009-09-04 18:31:17 -07001153 }
1154 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001155 }
1156
1157 private final class Idler implements MessageQueue.IdleHandler {
1158 public final boolean queueIdle() {
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07001159 ActivityClientRecord a = mNewActivities;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001160 if (a != null) {
1161 mNewActivities = null;
1162 IActivityManager am = ActivityManagerNative.getDefault();
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07001163 ActivityClientRecord prev;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001164 do {
Dianne Hackborn399cccb2010-04-13 22:57:49 -07001165 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001166 TAG, "Reporting idle of " + a +
1167 " finished=" +
1168 (a.activity != null ? a.activity.mFinished : false));
1169 if (a.activity != null && !a.activity.mFinished) {
1170 try {
Dianne Hackborne88846e2009-09-30 21:34:25 -07001171 am.activityIdle(a.token, a.createdConfig);
1172 a.createdConfig = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001173 } catch (RemoteException ex) {
1174 }
1175 }
1176 prev = a;
1177 a = a.nextIdle;
1178 prev.nextIdle = null;
1179 } while (a != null);
1180 }
Dianne Hackborn2a9094d2010-02-03 19:20:09 -08001181 ensureJitEnabled();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001182 return false;
1183 }
1184 }
1185
1186 final class GcIdler implements MessageQueue.IdleHandler {
1187 public final boolean queueIdle() {
1188 doGcIfNeeded();
1189 return false;
1190 }
1191 }
1192
Mitsuru Oshimaba3ba572009-07-08 18:49:26 -07001193 private final static class ResourcesKey {
1194 final private String mResDir;
1195 final private float mScale;
1196 final private int mHash;
Bob Leee5408332009-09-04 18:31:17 -07001197
Mitsuru Oshimaba3ba572009-07-08 18:49:26 -07001198 ResourcesKey(String resDir, float scale) {
1199 mResDir = resDir;
1200 mScale = scale;
1201 mHash = mResDir.hashCode() << 2 + (int) (mScale * 2);
1202 }
Bob Leee5408332009-09-04 18:31:17 -07001203
Mitsuru Oshimaba3ba572009-07-08 18:49:26 -07001204 @Override
1205 public int hashCode() {
1206 return mHash;
1207 }
1208
1209 @Override
1210 public boolean equals(Object obj) {
1211 if (!(obj instanceof ResourcesKey)) {
1212 return false;
1213 }
1214 ResourcesKey peer = (ResourcesKey) obj;
1215 return mResDir.equals(peer.mResDir) && mScale == peer.mScale;
1216 }
1217 }
1218
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07001219 public static final ActivityThread currentActivityThread() {
Brad Fitzpatrick333b8cb2010-08-26 12:04:57 -07001220 return sThreadLocal.get();
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07001221 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001222
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07001223 public static final String currentPackageName() {
1224 ActivityThread am = currentActivityThread();
1225 return (am != null && am.mBoundApplication != null)
1226 ? am.mBoundApplication.processName : null;
1227 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001228
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07001229 public static final Application currentApplication() {
1230 ActivityThread am = currentActivityThread();
1231 return am != null ? am.mInitialApplication : null;
1232 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001233
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07001234 public static IPackageManager getPackageManager() {
1235 if (sPackageManager != null) {
1236 //Slog.v("PackageManager", "returning cur default = " + sPackageManager);
1237 return sPackageManager;
1238 }
1239 IBinder b = ServiceManager.getService("package");
1240 //Slog.v("PackageManager", "default service binder = " + b);
1241 sPackageManager = IPackageManager.Stub.asInterface(b);
1242 //Slog.v("PackageManager", "default service = " + sPackageManager);
1243 return sPackageManager;
1244 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001245
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07001246 DisplayMetrics getDisplayMetricsLocked(boolean forceUpdate) {
1247 if (mDisplayMetrics != null && !forceUpdate) {
1248 return mDisplayMetrics;
1249 }
1250 if (mDisplay == null) {
1251 WindowManager wm = WindowManagerImpl.getDefault();
1252 mDisplay = wm.getDefaultDisplay();
1253 }
1254 DisplayMetrics metrics = mDisplayMetrics = new DisplayMetrics();
1255 mDisplay.getMetrics(metrics);
1256 //Slog.i("foo", "New metrics: w=" + metrics.widthPixels + " h="
1257 // + metrics.heightPixels + " den=" + metrics.density
1258 // + " xdpi=" + metrics.xdpi + " ydpi=" + metrics.ydpi);
1259 return metrics;
1260 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001261
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07001262 /**
1263 * Creates the top level Resources for applications with the given compatibility info.
1264 *
1265 * @param resDir the resource directory.
1266 * @param compInfo the compability info. It will use the default compatibility info when it's
1267 * null.
1268 */
1269 Resources getTopLevelResources(String resDir, CompatibilityInfo compInfo) {
1270 ResourcesKey key = new ResourcesKey(resDir, compInfo.applicationScale);
1271 Resources r;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001272 synchronized (mPackages) {
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07001273 // Resources is app scale dependent.
1274 if (false) {
1275 Slog.w(TAG, "getTopLevelResources: " + resDir + " / "
1276 + compInfo.applicationScale);
1277 }
1278 WeakReference<Resources> wr = mActiveResources.get(key);
1279 r = wr != null ? wr.get() : null;
1280 //if (r != null) Slog.i(TAG, "isUpToDate " + resDir + ": " + r.getAssets().isUpToDate());
1281 if (r != null && r.getAssets().isUpToDate()) {
1282 if (false) {
1283 Slog.w(TAG, "Returning cached resources " + r + " " + resDir
1284 + ": appScale=" + r.getCompatibilityInfo().applicationScale);
1285 }
1286 return r;
1287 }
1288 }
1289
1290 //if (r != null) {
1291 // Slog.w(TAG, "Throwing away out-of-date resources!!!! "
1292 // + r + " " + resDir);
1293 //}
1294
1295 AssetManager assets = new AssetManager();
1296 if (assets.addAssetPath(resDir) == 0) {
1297 return null;
1298 }
1299
1300 //Slog.i(TAG, "Resource: key=" + key + ", display metrics=" + metrics);
1301 DisplayMetrics metrics = getDisplayMetricsLocked(false);
1302 r = new Resources(assets, metrics, getConfiguration(), compInfo);
1303 if (false) {
1304 Slog.i(TAG, "Created app resources " + resDir + " " + r + ": "
1305 + r.getConfiguration() + " appScale="
1306 + r.getCompatibilityInfo().applicationScale);
1307 }
1308
1309 synchronized (mPackages) {
1310 WeakReference<Resources> wr = mActiveResources.get(key);
1311 Resources existing = wr != null ? wr.get() : null;
1312 if (existing != null && existing.getAssets().isUpToDate()) {
1313 // Someone else already created the resources while we were
1314 // unlocked; go ahead and use theirs.
1315 r.getAssets().close();
1316 return existing;
1317 }
1318
1319 // XXX need to remove entries when weak references go away
1320 mActiveResources.put(key, new WeakReference<Resources>(r));
1321 return r;
1322 }
1323 }
1324
1325 /**
1326 * Creates the top level resources for the given package.
1327 */
1328 Resources getTopLevelResources(String resDir, LoadedApk pkgInfo) {
1329 return getTopLevelResources(resDir, pkgInfo.mCompatibilityInfo);
1330 }
1331
1332 final Handler getHandler() {
1333 return mH;
1334 }
1335
1336 public final LoadedApk getPackageInfo(String packageName, int flags) {
1337 synchronized (mPackages) {
1338 WeakReference<LoadedApk> ref;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001339 if ((flags&Context.CONTEXT_INCLUDE_CODE) != 0) {
1340 ref = mPackages.get(packageName);
1341 } else {
1342 ref = mResourcePackages.get(packageName);
1343 }
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07001344 LoadedApk packageInfo = ref != null ? ref.get() : null;
Dianne Hackborn399cccb2010-04-13 22:57:49 -07001345 //Slog.i(TAG, "getPackageInfo " + packageName + ": " + packageInfo);
Dianne Hackborn4416c3d2010-05-04 17:22:49 -07001346 //if (packageInfo != null) Slog.i(TAG, "isUptoDate " + packageInfo.mResDir
1347 // + ": " + packageInfo.mResources.getAssets().isUpToDate());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001348 if (packageInfo != null && (packageInfo.mResources == null
1349 || packageInfo.mResources.getAssets().isUpToDate())) {
1350 if (packageInfo.isSecurityViolation()
1351 && (flags&Context.CONTEXT_IGNORE_SECURITY) == 0) {
1352 throw new SecurityException(
1353 "Requesting code from " + packageName
1354 + " to be run in process "
1355 + mBoundApplication.processName
1356 + "/" + mBoundApplication.appInfo.uid);
1357 }
1358 return packageInfo;
1359 }
1360 }
1361
1362 ApplicationInfo ai = null;
1363 try {
1364 ai = getPackageManager().getApplicationInfo(packageName,
1365 PackageManager.GET_SHARED_LIBRARY_FILES);
1366 } catch (RemoteException e) {
1367 }
1368
1369 if (ai != null) {
1370 return getPackageInfo(ai, flags);
1371 }
1372
1373 return null;
1374 }
1375
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07001376 public final LoadedApk getPackageInfo(ApplicationInfo ai, int flags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001377 boolean includeCode = (flags&Context.CONTEXT_INCLUDE_CODE) != 0;
1378 boolean securityViolation = includeCode && ai.uid != 0
1379 && ai.uid != Process.SYSTEM_UID && (mBoundApplication != null
1380 ? ai.uid != mBoundApplication.appInfo.uid : true);
1381 if ((flags&(Context.CONTEXT_INCLUDE_CODE
1382 |Context.CONTEXT_IGNORE_SECURITY))
1383 == Context.CONTEXT_INCLUDE_CODE) {
1384 if (securityViolation) {
1385 String msg = "Requesting code from " + ai.packageName
1386 + " (with uid " + ai.uid + ")";
1387 if (mBoundApplication != null) {
1388 msg = msg + " to be run in process "
1389 + mBoundApplication.processName + " (with uid "
1390 + mBoundApplication.appInfo.uid + ")";
1391 }
1392 throw new SecurityException(msg);
1393 }
1394 }
1395 return getPackageInfo(ai, null, securityViolation, includeCode);
1396 }
1397
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07001398 public final LoadedApk getPackageInfoNoCheck(ApplicationInfo ai) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001399 return getPackageInfo(ai, null, false, true);
1400 }
1401
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07001402 private final LoadedApk getPackageInfo(ApplicationInfo aInfo,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001403 ClassLoader baseLoader, boolean securityViolation, boolean includeCode) {
1404 synchronized (mPackages) {
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07001405 WeakReference<LoadedApk> ref;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001406 if (includeCode) {
1407 ref = mPackages.get(aInfo.packageName);
1408 } else {
1409 ref = mResourcePackages.get(aInfo.packageName);
1410 }
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07001411 LoadedApk packageInfo = ref != null ? ref.get() : null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001412 if (packageInfo == null || (packageInfo.mResources != null
1413 && !packageInfo.mResources.getAssets().isUpToDate())) {
Dianne Hackborn399cccb2010-04-13 22:57:49 -07001414 if (localLOGV) Slog.v(TAG, (includeCode ? "Loading code package "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001415 : "Loading resource-only package ") + aInfo.packageName
1416 + " (in " + (mBoundApplication != null
1417 ? mBoundApplication.processName : null)
1418 + ")");
1419 packageInfo =
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07001420 new LoadedApk(this, aInfo, this, baseLoader,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001421 securityViolation, includeCode &&
1422 (aInfo.flags&ApplicationInfo.FLAG_HAS_CODE) != 0);
1423 if (includeCode) {
1424 mPackages.put(aInfo.packageName,
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07001425 new WeakReference<LoadedApk>(packageInfo));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001426 } else {
1427 mResourcePackages.put(aInfo.packageName,
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07001428 new WeakReference<LoadedApk>(packageInfo));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001429 }
1430 }
1431 return packageInfo;
1432 }
1433 }
1434
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001435 ActivityThread() {
1436 }
1437
1438 public ApplicationThread getApplicationThread()
1439 {
1440 return mAppThread;
1441 }
1442
1443 public Instrumentation getInstrumentation()
1444 {
1445 return mInstrumentation;
1446 }
1447
1448 public Configuration getConfiguration() {
1449 return mConfiguration;
1450 }
1451
1452 public boolean isProfiling() {
1453 return mBoundApplication != null && mBoundApplication.profileFile != null;
1454 }
1455
1456 public String getProfileFilePath() {
1457 return mBoundApplication.profileFile;
1458 }
1459
1460 public Looper getLooper() {
1461 return mLooper;
1462 }
1463
1464 public Application getApplication() {
1465 return mInitialApplication;
1466 }
Bob Leee5408332009-09-04 18:31:17 -07001467
Dianne Hackbornd97c7ad2009-06-19 11:37:35 -07001468 public String getProcessName() {
1469 return mBoundApplication.processName;
1470 }
Bob Leee5408332009-09-04 18:31:17 -07001471
Dianne Hackborn21556372010-02-04 16:34:40 -08001472 public ContextImpl getSystemContext() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001473 synchronized (this) {
1474 if (mSystemContext == null) {
Dianne Hackborn21556372010-02-04 16:34:40 -08001475 ContextImpl context =
1476 ContextImpl.createSystemContext(this);
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07001477 LoadedApk info = new LoadedApk(this, "android", context, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001478 context.init(info, null, this);
1479 context.getResources().updateConfiguration(
1480 getConfiguration(), getDisplayMetricsLocked(false));
1481 mSystemContext = context;
Dianne Hackborn399cccb2010-04-13 22:57:49 -07001482 //Slog.i(TAG, "Created system resources " + context.getResources()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001483 // + ": " + context.getResources().getConfiguration());
1484 }
1485 }
1486 return mSystemContext;
1487 }
1488
Mike Cleron432b7132009-09-24 15:28:29 -07001489 public void installSystemApplicationInfo(ApplicationInfo info) {
1490 synchronized (this) {
Dianne Hackborn21556372010-02-04 16:34:40 -08001491 ContextImpl context = getSystemContext();
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07001492 context.init(new LoadedApk(this, "android", context, info), null, this);
Mike Cleron432b7132009-09-24 15:28:29 -07001493 }
1494 }
1495
Dianne Hackborn2a9094d2010-02-03 19:20:09 -08001496 void ensureJitEnabled() {
1497 if (!mJitEnabled) {
1498 mJitEnabled = true;
1499 dalvik.system.VMRuntime.getRuntime().startJitCompilation();
1500 }
1501 }
1502
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001503 void scheduleGcIdler() {
1504 if (!mGcIdlerScheduled) {
1505 mGcIdlerScheduled = true;
1506 Looper.myQueue().addIdleHandler(mGcIdler);
1507 }
1508 mH.removeMessages(H.GC_WHEN_IDLE);
1509 }
1510
1511 void unscheduleGcIdler() {
1512 if (mGcIdlerScheduled) {
1513 mGcIdlerScheduled = false;
1514 Looper.myQueue().removeIdleHandler(mGcIdler);
1515 }
1516 mH.removeMessages(H.GC_WHEN_IDLE);
1517 }
1518
1519 void doGcIfNeeded() {
1520 mGcIdlerScheduled = false;
1521 final long now = SystemClock.uptimeMillis();
Dianne Hackborn399cccb2010-04-13 22:57:49 -07001522 //Slog.i(TAG, "**** WE MIGHT WANT TO GC: then=" + Binder.getLastGcTime()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001523 // + "m now=" + now);
1524 if ((BinderInternal.getLastGcTime()+MIN_TIME_BETWEEN_GCS) < now) {
Dianne Hackborn399cccb2010-04-13 22:57:49 -07001525 //Slog.i(TAG, "**** WE DO, WE DO WANT TO GC!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001526 BinderInternal.forceGc("bg");
1527 }
1528 }
1529
Jeff Hamilton52d32032011-01-08 15:31:26 -06001530 public void registerOnActivityPausedListener(Activity activity,
1531 OnActivityPausedListener listener) {
1532 synchronized (mOnPauseListeners) {
1533 ArrayList<OnActivityPausedListener> list = mOnPauseListeners.get(activity);
1534 if (list == null) {
1535 list = new ArrayList<OnActivityPausedListener>();
1536 mOnPauseListeners.put(activity, list);
1537 }
1538 list.add(listener);
1539 }
1540 }
1541
Jeff Hamiltonce3224c2011-01-17 11:05:03 -08001542 public void unregisterOnActivityPausedListener(Activity activity,
1543 OnActivityPausedListener listener) {
1544 synchronized (mOnPauseListeners) {
1545 ArrayList<OnActivityPausedListener> list = mOnPauseListeners.get(activity);
1546 if (list != null) {
1547 list.remove(listener);
1548 }
1549 }
1550 }
1551
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001552 public final ActivityInfo resolveActivityInfo(Intent intent) {
1553 ActivityInfo aInfo = intent.resolveActivityInfo(
1554 mInitialApplication.getPackageManager(), PackageManager.GET_SHARED_LIBRARY_FILES);
1555 if (aInfo == null) {
1556 // Throw an exception.
1557 Instrumentation.checkStartActivityResult(
1558 IActivityManager.START_CLASS_NOT_FOUND, intent);
1559 }
1560 return aInfo;
1561 }
Bob Leee5408332009-09-04 18:31:17 -07001562
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001563 public final Activity startActivityNow(Activity parent, String id,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001564 Intent intent, ActivityInfo activityInfo, IBinder token, Bundle state,
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -07001565 Activity.NonConfigurationInstances lastNonConfigurationInstances) {
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07001566 ActivityClientRecord r = new ActivityClientRecord();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001567 r.token = token;
Dianne Hackbornb06ea702009-07-13 13:07:51 -07001568 r.ident = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001569 r.intent = intent;
1570 r.state = state;
1571 r.parent = parent;
1572 r.embeddedID = id;
1573 r.activityInfo = activityInfo;
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -07001574 r.lastNonConfigurationInstances = lastNonConfigurationInstances;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001575 if (localLOGV) {
1576 ComponentName compname = intent.getComponent();
1577 String name;
1578 if (compname != null) {
1579 name = compname.toShortString();
1580 } else {
1581 name = "(Intent " + intent + ").getComponent() returned null";
1582 }
Dianne Hackborn399cccb2010-04-13 22:57:49 -07001583 Slog.v(TAG, "Performing launch: action=" + intent.getAction()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001584 + ", comp=" + name
1585 + ", token=" + token);
1586 }
Christopher Tateb70f3df2009-04-07 16:07:59 -07001587 return performLaunchActivity(r, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001588 }
1589
1590 public final Activity getActivity(IBinder token) {
1591 return mActivities.get(token).activity;
1592 }
1593
1594 public final void sendActivityResult(
1595 IBinder token, String id, int requestCode,
1596 int resultCode, Intent data) {
Dianne Hackborn399cccb2010-04-13 22:57:49 -07001597 if (DEBUG_RESULTS) Slog.v(TAG, "sendActivityResult: id=" + id
Chris Tate8a7dc172009-03-24 20:11:42 -07001598 + " req=" + requestCode + " res=" + resultCode + " data=" + data);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001599 ArrayList<ResultInfo> list = new ArrayList<ResultInfo>();
1600 list.add(new ResultInfo(id, requestCode, resultCode, data));
1601 mAppThread.scheduleSendResult(token, list);
1602 }
1603
1604 // if the thread hasn't started yet, we don't have the handler, so just
1605 // save the messages until we're ready.
1606 private final void queueOrSendMessage(int what, Object obj) {
1607 queueOrSendMessage(what, obj, 0, 0);
1608 }
1609
1610 private final void queueOrSendMessage(int what, Object obj, int arg1) {
1611 queueOrSendMessage(what, obj, arg1, 0);
1612 }
1613
1614 private final void queueOrSendMessage(int what, Object obj, int arg1, int arg2) {
1615 synchronized (this) {
Dianne Hackborn287952c2010-09-22 22:34:31 -07001616 if (DEBUG_MESSAGES) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001617 TAG, "SCHEDULE " + what + " " + mH.codeToString(what)
1618 + ": " + arg1 + " / " + obj);
1619 Message msg = Message.obtain();
1620 msg.what = what;
1621 msg.obj = obj;
1622 msg.arg1 = arg1;
1623 msg.arg2 = arg2;
1624 mH.sendMessage(msg);
1625 }
1626 }
1627
Dianne Hackborn21556372010-02-04 16:34:40 -08001628 final void scheduleContextCleanup(ContextImpl context, String who,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001629 String what) {
1630 ContextCleanupInfo cci = new ContextCleanupInfo();
1631 cci.context = context;
1632 cci.who = who;
1633 cci.what = what;
1634 queueOrSendMessage(H.CLEAN_UP_CONTEXT, cci);
1635 }
1636
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07001637 private final Activity performLaunchActivity(ActivityClientRecord r, Intent customIntent) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001638 // System.out.println("##### [" + System.currentTimeMillis() + "] ActivityThread.performLaunchActivity(" + r + ")");
1639
1640 ActivityInfo aInfo = r.activityInfo;
1641 if (r.packageInfo == null) {
1642 r.packageInfo = getPackageInfo(aInfo.applicationInfo,
1643 Context.CONTEXT_INCLUDE_CODE);
1644 }
Bob Leee5408332009-09-04 18:31:17 -07001645
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001646 ComponentName component = r.intent.getComponent();
1647 if (component == null) {
1648 component = r.intent.resolveActivity(
1649 mInitialApplication.getPackageManager());
1650 r.intent.setComponent(component);
1651 }
1652
1653 if (r.activityInfo.targetActivity != null) {
1654 component = new ComponentName(r.activityInfo.packageName,
1655 r.activityInfo.targetActivity);
1656 }
1657
1658 Activity activity = null;
1659 try {
1660 java.lang.ClassLoader cl = r.packageInfo.getClassLoader();
1661 activity = mInstrumentation.newActivity(
1662 cl, component.getClassName(), r.intent);
Brad Fitzpatrick5f8b5c12011-01-20 15:12:08 -08001663 StrictMode.incrementExpectedActivityCount(activity.getClass());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001664 r.intent.setExtrasClassLoader(cl);
1665 if (r.state != null) {
1666 r.state.setClassLoader(cl);
1667 }
1668 } catch (Exception e) {
1669 if (!mInstrumentation.onException(activity, e)) {
1670 throw new RuntimeException(
1671 "Unable to instantiate activity " + component
1672 + ": " + e.toString(), e);
1673 }
1674 }
1675
1676 try {
Dianne Hackborn0be1f782009-11-09 12:30:12 -08001677 Application app = r.packageInfo.makeApplication(false, mInstrumentation);
Bob Leee5408332009-09-04 18:31:17 -07001678
Dianne Hackborn399cccb2010-04-13 22:57:49 -07001679 if (localLOGV) Slog.v(TAG, "Performing launch of " + r);
1680 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001681 TAG, r + ": app=" + app
1682 + ", appName=" + app.getPackageName()
1683 + ", pkg=" + r.packageInfo.getPackageName()
1684 + ", comp=" + r.intent.getComponent().toShortString()
1685 + ", dir=" + r.packageInfo.getAppDir());
1686
1687 if (activity != null) {
Dianne Hackborn21556372010-02-04 16:34:40 -08001688 ContextImpl appContext = new ContextImpl();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001689 appContext.init(r.packageInfo, r.token, this);
1690 appContext.setOuterContext(activity);
1691 CharSequence title = r.activityInfo.loadLabel(appContext.getPackageManager());
1692 Configuration config = new Configuration(mConfiguration);
Dianne Hackborn399cccb2010-04-13 22:57:49 -07001693 if (DEBUG_CONFIGURATION) Slog.v(TAG, "Launching activity "
Dianne Hackborndc6b6352009-09-30 14:20:09 -07001694 + r.activityInfo.name + " with config " + config);
Dianne Hackbornb06ea702009-07-13 13:07:51 -07001695 activity.attach(appContext, this, getInstrumentation(), r.token,
1696 r.ident, app, r.intent, r.activityInfo, title, r.parent,
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -07001697 r.embeddedID, r.lastNonConfigurationInstances, config);
Bob Leee5408332009-09-04 18:31:17 -07001698
Christopher Tateb70f3df2009-04-07 16:07:59 -07001699 if (customIntent != null) {
1700 activity.mIntent = customIntent;
1701 }
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -07001702 r.lastNonConfigurationInstances = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001703 activity.mStartedActivity = false;
1704 int theme = r.activityInfo.getThemeResource();
1705 if (theme != 0) {
1706 activity.setTheme(theme);
1707 }
1708
1709 activity.mCalled = false;
1710 mInstrumentation.callActivityOnCreate(activity, r.state);
1711 if (!activity.mCalled) {
1712 throw new SuperNotCalledException(
1713 "Activity " + r.intent.getComponent().toShortString() +
1714 " did not call through to super.onCreate()");
1715 }
1716 r.activity = activity;
1717 r.stopped = true;
1718 if (!r.activity.mFinished) {
1719 activity.performStart();
1720 r.stopped = false;
1721 }
1722 if (!r.activity.mFinished) {
1723 if (r.state != null) {
1724 mInstrumentation.callActivityOnRestoreInstanceState(activity, r.state);
1725 }
1726 }
1727 if (!r.activity.mFinished) {
1728 activity.mCalled = false;
1729 mInstrumentation.callActivityOnPostCreate(activity, r.state);
1730 if (!activity.mCalled) {
1731 throw new SuperNotCalledException(
1732 "Activity " + r.intent.getComponent().toShortString() +
1733 " did not call through to super.onPostCreate()");
1734 }
1735 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001736 }
1737 r.paused = true;
1738
1739 mActivities.put(r.token, r);
1740
1741 } catch (SuperNotCalledException e) {
1742 throw e;
1743
1744 } catch (Exception e) {
1745 if (!mInstrumentation.onException(activity, e)) {
1746 throw new RuntimeException(
1747 "Unable to start activity " + component
1748 + ": " + e.toString(), e);
1749 }
1750 }
1751
1752 return activity;
1753 }
1754
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07001755 private final void handleLaunchActivity(ActivityClientRecord r, Intent customIntent) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001756 // If we are getting ready to gc after going to the background, well
1757 // we are back active so skip it.
1758 unscheduleGcIdler();
1759
Dianne Hackborn399cccb2010-04-13 22:57:49 -07001760 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001761 TAG, "Handling launch of " + r);
Christopher Tateb70f3df2009-04-07 16:07:59 -07001762 Activity a = performLaunchActivity(r, customIntent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001763
1764 if (a != null) {
Dianne Hackborn871ecdc2009-12-11 15:24:33 -08001765 r.createdConfig = new Configuration(mConfiguration);
Dianne Hackborn9e0f5d92010-02-22 15:05:42 -08001766 Bundle oldState = r.state;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001767 handleResumeActivity(r.token, false, r.isForward);
1768
1769 if (!r.activity.mFinished && r.startsNotResumed) {
1770 // The activity manager actually wants this one to start out
1771 // paused, because it needs to be visible but isn't in the
1772 // foreground. We accomplish this by going through the
1773 // normal startup (because activities expect to go through
1774 // onResume() the first time they run, before their window
1775 // is displayed), and then pausing it. However, in this case
1776 // we do -not- need to do the full pause cycle (of freezing
1777 // and such) because the activity manager assumes it can just
1778 // retain the current state it has.
1779 try {
1780 r.activity.mCalled = false;
1781 mInstrumentation.callActivityOnPause(r.activity);
Dianne Hackborn9e0f5d92010-02-22 15:05:42 -08001782 // We need to keep around the original state, in case
1783 // we need to be created again.
1784 r.state = oldState;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001785 if (!r.activity.mCalled) {
1786 throw new SuperNotCalledException(
1787 "Activity " + r.intent.getComponent().toShortString() +
1788 " did not call through to super.onPause()");
1789 }
1790
1791 } catch (SuperNotCalledException e) {
1792 throw e;
1793
1794 } catch (Exception e) {
1795 if (!mInstrumentation.onException(r.activity, e)) {
1796 throw new RuntimeException(
1797 "Unable to pause activity "
1798 + r.intent.getComponent().toShortString()
1799 + ": " + e.toString(), e);
1800 }
1801 }
1802 r.paused = true;
1803 }
1804 } else {
1805 // If there was an error, for any reason, tell the activity
1806 // manager to stop us.
1807 try {
1808 ActivityManagerNative.getDefault()
1809 .finishActivity(r.token, Activity.RESULT_CANCELED, null);
1810 } catch (RemoteException ex) {
1811 }
1812 }
1813 }
1814
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07001815 private final void deliverNewIntents(ActivityClientRecord r,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001816 List<Intent> intents) {
1817 final int N = intents.size();
1818 for (int i=0; i<N; i++) {
1819 Intent intent = intents.get(i);
1820 intent.setExtrasClassLoader(r.activity.getClassLoader());
Dianne Hackbornfb3cffe2010-10-25 17:08:56 -07001821 r.activity.mFragments.noteStateNotSaved();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001822 mInstrumentation.callActivityOnNewIntent(r.activity, intent);
1823 }
1824 }
1825
1826 public final void performNewIntents(IBinder token,
1827 List<Intent> intents) {
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07001828 ActivityClientRecord r = mActivities.get(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001829 if (r != null) {
1830 final boolean resumed = !r.paused;
1831 if (resumed) {
Dianne Hackbornfb3cffe2010-10-25 17:08:56 -07001832 r.activity.mTemporaryPause = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001833 mInstrumentation.callActivityOnPause(r.activity);
1834 }
1835 deliverNewIntents(r, intents);
1836 if (resumed) {
1837 mInstrumentation.callActivityOnResume(r.activity);
Dianne Hackbornfb3cffe2010-10-25 17:08:56 -07001838 r.activity.mTemporaryPause = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001839 }
1840 }
1841 }
Bob Leee5408332009-09-04 18:31:17 -07001842
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001843 private final void handleNewIntent(NewIntentData data) {
1844 performNewIntents(data.token, data.intents);
1845 }
1846
Brad Fitzpatrickbfb19192010-10-29 15:25:44 -07001847 private static final ThreadLocal<Intent> sCurrentBroadcastIntent = new ThreadLocal<Intent>();
1848
1849 /**
1850 * Return the Intent that's currently being handled by a
1851 * BroadcastReceiver on this thread, or null if none.
1852 * @hide
1853 */
1854 public static Intent getIntentBeingBroadcast() {
1855 return sCurrentBroadcastIntent.get();
1856 }
1857
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001858 private final void handleReceiver(ReceiverData data) {
1859 // If we are getting ready to gc after going to the background, well
1860 // we are back active so skip it.
1861 unscheduleGcIdler();
1862
1863 String component = data.intent.getComponent().getClassName();
1864
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07001865 LoadedApk packageInfo = getPackageInfoNoCheck(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001866 data.info.applicationInfo);
1867
1868 IActivityManager mgr = ActivityManagerNative.getDefault();
1869
1870 BroadcastReceiver receiver = null;
1871 try {
1872 java.lang.ClassLoader cl = packageInfo.getClassLoader();
1873 data.intent.setExtrasClassLoader(cl);
Dianne Hackborne829fef2010-10-26 17:44:01 -07001874 data.setExtrasClassLoader(cl);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001875 receiver = (BroadcastReceiver)cl.loadClass(component).newInstance();
1876 } catch (Exception e) {
Dianne Hackborne829fef2010-10-26 17:44:01 -07001877 if (DEBUG_BROADCAST) Slog.i(TAG,
1878 "Finishing failed broadcast to " + data.intent.getComponent());
1879 data.sendFinished(mgr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001880 throw new RuntimeException(
1881 "Unable to instantiate receiver " + component
1882 + ": " + e.toString(), e);
1883 }
1884
1885 try {
Dianne Hackborn0be1f782009-11-09 12:30:12 -08001886 Application app = packageInfo.makeApplication(false, mInstrumentation);
Bob Leee5408332009-09-04 18:31:17 -07001887
Dianne Hackborn399cccb2010-04-13 22:57:49 -07001888 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001889 TAG, "Performing receive of " + data.intent
1890 + ": app=" + app
1891 + ", appName=" + app.getPackageName()
1892 + ", pkg=" + packageInfo.getPackageName()
1893 + ", comp=" + data.intent.getComponent().toShortString()
1894 + ", dir=" + packageInfo.getAppDir());
1895
Dianne Hackborn21556372010-02-04 16:34:40 -08001896 ContextImpl context = (ContextImpl)app.getBaseContext();
Brad Fitzpatrickbfb19192010-10-29 15:25:44 -07001897 sCurrentBroadcastIntent.set(data.intent);
Dianne Hackborne829fef2010-10-26 17:44:01 -07001898 receiver.setPendingResult(data);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001899 receiver.onReceive(context.getReceiverRestrictedContext(),
1900 data.intent);
1901 } catch (Exception e) {
Dianne Hackborne829fef2010-10-26 17:44:01 -07001902 if (DEBUG_BROADCAST) Slog.i(TAG,
1903 "Finishing failed broadcast to " + data.intent.getComponent());
1904 data.sendFinished(mgr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001905 if (!mInstrumentation.onException(receiver, e)) {
1906 throw new RuntimeException(
1907 "Unable to start receiver " + component
1908 + ": " + e.toString(), e);
1909 }
Brad Fitzpatrickbfb19192010-10-29 15:25:44 -07001910 } finally {
1911 sCurrentBroadcastIntent.set(null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001912 }
1913
Dianne Hackborne829fef2010-10-26 17:44:01 -07001914 if (receiver.getPendingResult() != null) {
1915 data.finish();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001916 }
1917 }
1918
Christopher Tate181fafa2009-05-14 11:12:14 -07001919 // Instantiate a BackupAgent and tell it that it's alive
1920 private final void handleCreateBackupAgent(CreateBackupAgentData data) {
Dianne Hackborn399cccb2010-04-13 22:57:49 -07001921 if (DEBUG_BACKUP) Slog.v(TAG, "handleCreateBackupAgent: " + data);
Christopher Tate181fafa2009-05-14 11:12:14 -07001922
1923 // no longer idle; we have backup work to do
1924 unscheduleGcIdler();
1925
1926 // instantiate the BackupAgent class named in the manifest
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07001927 LoadedApk packageInfo = getPackageInfoNoCheck(data.appInfo);
Christopher Tate181fafa2009-05-14 11:12:14 -07001928 String packageName = packageInfo.mPackageName;
1929 if (mBackupAgents.get(packageName) != null) {
Dianne Hackborn399cccb2010-04-13 22:57:49 -07001930 Slog.d(TAG, "BackupAgent " + " for " + packageName
Christopher Tate181fafa2009-05-14 11:12:14 -07001931 + " already exists");
1932 return;
1933 }
Bob Leee5408332009-09-04 18:31:17 -07001934
Christopher Tate181fafa2009-05-14 11:12:14 -07001935 BackupAgent agent = null;
1936 String classname = data.appInfo.backupAgentName;
1937 if (classname == null) {
1938 if (data.backupMode == IApplicationThread.BACKUP_MODE_INCREMENTAL) {
Dianne Hackbornc9421ba2010-03-11 22:23:46 -08001939 Slog.e(TAG, "Attempted incremental backup but no defined agent for "
Christopher Tate181fafa2009-05-14 11:12:14 -07001940 + packageName);
1941 return;
1942 }
1943 classname = "android.app.FullBackupAgent";
1944 }
1945 try {
Christopher Tated1475e02009-07-09 15:36:17 -07001946 IBinder binder = null;
1947 try {
1948 java.lang.ClassLoader cl = packageInfo.getClassLoader();
1949 agent = (BackupAgent) cl.loadClass(data.appInfo.backupAgentName).newInstance();
1950
1951 // set up the agent's context
Dianne Hackborn399cccb2010-04-13 22:57:49 -07001952 if (DEBUG_BACKUP) Slog.v(TAG, "Initializing BackupAgent "
Christopher Tated1475e02009-07-09 15:36:17 -07001953 + data.appInfo.backupAgentName);
1954
Dianne Hackborn21556372010-02-04 16:34:40 -08001955 ContextImpl context = new ContextImpl();
Christopher Tated1475e02009-07-09 15:36:17 -07001956 context.init(packageInfo, null, this);
1957 context.setOuterContext(agent);
1958 agent.attach(context);
1959
1960 agent.onCreate();
1961 binder = agent.onBind();
1962 mBackupAgents.put(packageName, agent);
1963 } catch (Exception e) {
1964 // If this is during restore, fail silently; otherwise go
1965 // ahead and let the user see the crash.
Dianne Hackbornc9421ba2010-03-11 22:23:46 -08001966 Slog.e(TAG, "Agent threw during creation: " + e);
Christopher Tated1475e02009-07-09 15:36:17 -07001967 if (data.backupMode != IApplicationThread.BACKUP_MODE_RESTORE) {
1968 throw e;
1969 }
1970 // falling through with 'binder' still null
1971 }
Christopher Tate181fafa2009-05-14 11:12:14 -07001972
1973 // tell the OS that we're live now
Christopher Tate181fafa2009-05-14 11:12:14 -07001974 try {
1975 ActivityManagerNative.getDefault().backupAgentCreated(packageName, binder);
1976 } catch (RemoteException e) {
1977 // nothing to do.
1978 }
Christopher Tate181fafa2009-05-14 11:12:14 -07001979 } catch (Exception e) {
1980 throw new RuntimeException("Unable to create BackupAgent "
1981 + data.appInfo.backupAgentName + ": " + e.toString(), e);
1982 }
1983 }
1984
1985 // Tear down a BackupAgent
1986 private final void handleDestroyBackupAgent(CreateBackupAgentData data) {
Dianne Hackborn399cccb2010-04-13 22:57:49 -07001987 if (DEBUG_BACKUP) Slog.v(TAG, "handleDestroyBackupAgent: " + data);
Bob Leee5408332009-09-04 18:31:17 -07001988
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07001989 LoadedApk packageInfo = getPackageInfoNoCheck(data.appInfo);
Christopher Tate181fafa2009-05-14 11:12:14 -07001990 String packageName = packageInfo.mPackageName;
1991 BackupAgent agent = mBackupAgents.get(packageName);
1992 if (agent != null) {
1993 try {
1994 agent.onDestroy();
1995 } catch (Exception e) {
Dianne Hackbornc9421ba2010-03-11 22:23:46 -08001996 Slog.w(TAG, "Exception thrown in onDestroy by backup agent of " + data.appInfo);
Christopher Tate181fafa2009-05-14 11:12:14 -07001997 e.printStackTrace();
1998 }
1999 mBackupAgents.remove(packageName);
2000 } else {
Dianne Hackbornc9421ba2010-03-11 22:23:46 -08002001 Slog.w(TAG, "Attempt to destroy unknown backup agent " + data);
Christopher Tate181fafa2009-05-14 11:12:14 -07002002 }
2003 }
2004
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002005 private final void handleCreateService(CreateServiceData data) {
2006 // If we are getting ready to gc after going to the background, well
2007 // we are back active so skip it.
2008 unscheduleGcIdler();
2009
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07002010 LoadedApk packageInfo = getPackageInfoNoCheck(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002011 data.info.applicationInfo);
2012 Service service = null;
2013 try {
2014 java.lang.ClassLoader cl = packageInfo.getClassLoader();
2015 service = (Service) cl.loadClass(data.info.name).newInstance();
2016 } catch (Exception e) {
2017 if (!mInstrumentation.onException(service, e)) {
2018 throw new RuntimeException(
2019 "Unable to instantiate service " + data.info.name
2020 + ": " + e.toString(), e);
2021 }
2022 }
2023
2024 try {
Dianne Hackborn399cccb2010-04-13 22:57:49 -07002025 if (localLOGV) Slog.v(TAG, "Creating service " + data.info.name);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002026
Dianne Hackborn21556372010-02-04 16:34:40 -08002027 ContextImpl context = new ContextImpl();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002028 context.init(packageInfo, null, this);
2029
Dianne Hackborn0be1f782009-11-09 12:30:12 -08002030 Application app = packageInfo.makeApplication(false, mInstrumentation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002031 context.setOuterContext(service);
2032 service.attach(context, this, data.info.name, data.token, app,
2033 ActivityManagerNative.getDefault());
2034 service.onCreate();
2035 mServices.put(data.token, service);
2036 try {
Dianne Hackbornf6f9f2d2009-08-21 16:26:03 -07002037 ActivityManagerNative.getDefault().serviceDoneExecuting(
2038 data.token, 0, 0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002039 } catch (RemoteException e) {
2040 // nothing to do.
2041 }
2042 } catch (Exception e) {
2043 if (!mInstrumentation.onException(service, e)) {
2044 throw new RuntimeException(
2045 "Unable to create service " + data.info.name
2046 + ": " + e.toString(), e);
2047 }
2048 }
2049 }
2050
2051 private final void handleBindService(BindServiceData data) {
2052 Service s = mServices.get(data.token);
2053 if (s != null) {
2054 try {
2055 data.intent.setExtrasClassLoader(s.getClassLoader());
2056 try {
2057 if (!data.rebind) {
2058 IBinder binder = s.onBind(data.intent);
2059 ActivityManagerNative.getDefault().publishService(
2060 data.token, data.intent, binder);
2061 } else {
2062 s.onRebind(data.intent);
2063 ActivityManagerNative.getDefault().serviceDoneExecuting(
Dianne Hackbornf6f9f2d2009-08-21 16:26:03 -07002064 data.token, 0, 0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002065 }
Dianne Hackborn2a9094d2010-02-03 19:20:09 -08002066 ensureJitEnabled();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002067 } catch (RemoteException ex) {
2068 }
2069 } catch (Exception e) {
2070 if (!mInstrumentation.onException(s, e)) {
2071 throw new RuntimeException(
2072 "Unable to bind to service " + s
2073 + " with " + data.intent + ": " + e.toString(), e);
2074 }
2075 }
2076 }
2077 }
2078
2079 private final void handleUnbindService(BindServiceData data) {
2080 Service s = mServices.get(data.token);
2081 if (s != null) {
2082 try {
2083 data.intent.setExtrasClassLoader(s.getClassLoader());
2084 boolean doRebind = s.onUnbind(data.intent);
2085 try {
2086 if (doRebind) {
2087 ActivityManagerNative.getDefault().unbindFinished(
2088 data.token, data.intent, doRebind);
2089 } else {
2090 ActivityManagerNative.getDefault().serviceDoneExecuting(
Dianne Hackbornf6f9f2d2009-08-21 16:26:03 -07002091 data.token, 0, 0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002092 }
2093 } catch (RemoteException ex) {
2094 }
2095 } catch (Exception e) {
2096 if (!mInstrumentation.onException(s, e)) {
2097 throw new RuntimeException(
2098 "Unable to unbind to service " + s
2099 + " with " + data.intent + ": " + e.toString(), e);
2100 }
2101 }
2102 }
2103 }
2104
Dianne Hackborn625ac272010-09-17 18:29:22 -07002105 private void handleDumpService(DumpComponentInfo info) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002106 try {
Dianne Hackborn625ac272010-09-17 18:29:22 -07002107 Service s = mServices.get(info.token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002108 if (s != null) {
2109 PrintWriter pw = new PrintWriter(new FileOutputStream(info.fd));
2110 s.dump(info.fd, pw, info.args);
2111 pw.close();
2112 }
2113 } finally {
2114 synchronized (info) {
2115 info.dumped = true;
2116 info.notifyAll();
2117 }
2118 }
2119 }
2120
Dianne Hackborn625ac272010-09-17 18:29:22 -07002121 private void handleDumpActivity(DumpComponentInfo info) {
2122 try {
2123 ActivityClientRecord r = mActivities.get(info.token);
2124 if (r != null && r.activity != null) {
2125 PrintWriter pw = new PrintWriter(new FileOutputStream(info.fd));
Dianne Hackborn30d71892010-12-11 10:37:55 -08002126 r.activity.dump(info.prefix, info.fd, pw, info.args);
Dianne Hackborn625ac272010-09-17 18:29:22 -07002127 pw.close();
2128 }
2129 } finally {
2130 synchronized (info) {
2131 info.dumped = true;
2132 info.notifyAll();
2133 }
2134 }
2135 }
2136
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002137 private final void handleServiceArgs(ServiceArgsData data) {
2138 Service s = mServices.get(data.token);
2139 if (s != null) {
2140 try {
2141 if (data.args != null) {
2142 data.args.setExtrasClassLoader(s.getClassLoader());
2143 }
Dianne Hackbornf6f9f2d2009-08-21 16:26:03 -07002144 int res = s.onStartCommand(data.args, data.flags, data.startId);
Brad Fitzpatrick333b8cb2010-08-26 12:04:57 -07002145
2146 QueuedWork.waitToFinish();
2147
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002148 try {
Dianne Hackbornf6f9f2d2009-08-21 16:26:03 -07002149 ActivityManagerNative.getDefault().serviceDoneExecuting(
2150 data.token, 1, data.startId, res);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002151 } catch (RemoteException e) {
2152 // nothing to do.
2153 }
Dianne Hackborn2a9094d2010-02-03 19:20:09 -08002154 ensureJitEnabled();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002155 } catch (Exception e) {
2156 if (!mInstrumentation.onException(s, e)) {
2157 throw new RuntimeException(
2158 "Unable to start service " + s
2159 + " with " + data.args + ": " + e.toString(), e);
2160 }
2161 }
2162 }
2163 }
2164
2165 private final void handleStopService(IBinder token) {
2166 Service s = mServices.remove(token);
2167 if (s != null) {
2168 try {
Dianne Hackborn399cccb2010-04-13 22:57:49 -07002169 if (localLOGV) Slog.v(TAG, "Destroying service " + s);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002170 s.onDestroy();
2171 Context context = s.getBaseContext();
Dianne Hackborn21556372010-02-04 16:34:40 -08002172 if (context instanceof ContextImpl) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002173 final String who = s.getClassName();
Dianne Hackborn21556372010-02-04 16:34:40 -08002174 ((ContextImpl) context).scheduleFinalCleanup(who, "Service");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002175 }
Brad Fitzpatrick333b8cb2010-08-26 12:04:57 -07002176
2177 QueuedWork.waitToFinish();
2178
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002179 try {
Dianne Hackbornf6f9f2d2009-08-21 16:26:03 -07002180 ActivityManagerNative.getDefault().serviceDoneExecuting(
2181 token, 0, 0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002182 } catch (RemoteException e) {
2183 // nothing to do.
2184 }
2185 } catch (Exception e) {
2186 if (!mInstrumentation.onException(s, e)) {
2187 throw new RuntimeException(
2188 "Unable to stop service " + s
2189 + ": " + e.toString(), e);
2190 }
2191 }
2192 }
Dianne Hackborn399cccb2010-04-13 22:57:49 -07002193 //Slog.i(TAG, "Running services: " + mServices);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002194 }
2195
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07002196 public final ActivityClientRecord performResumeActivity(IBinder token,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002197 boolean clearHide) {
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07002198 ActivityClientRecord r = mActivities.get(token);
Dianne Hackborn399cccb2010-04-13 22:57:49 -07002199 if (localLOGV) Slog.v(TAG, "Performing resume of " + r
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002200 + " finished=" + r.activity.mFinished);
2201 if (r != null && !r.activity.mFinished) {
2202 if (clearHide) {
2203 r.hideForNow = false;
2204 r.activity.mStartedActivity = false;
2205 }
2206 try {
2207 if (r.pendingIntents != null) {
2208 deliverNewIntents(r, r.pendingIntents);
2209 r.pendingIntents = null;
2210 }
2211 if (r.pendingResults != null) {
2212 deliverResults(r, r.pendingResults);
2213 r.pendingResults = null;
2214 }
2215 r.activity.performResume();
2216
Bob Leee5408332009-09-04 18:31:17 -07002217 EventLog.writeEvent(LOG_ON_RESUME_CALLED,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002218 r.activity.getComponentName().getClassName());
Bob Leee5408332009-09-04 18:31:17 -07002219
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002220 r.paused = false;
2221 r.stopped = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002222 r.state = null;
2223 } catch (Exception e) {
2224 if (!mInstrumentation.onException(r.activity, e)) {
2225 throw new RuntimeException(
2226 "Unable to resume activity "
2227 + r.intent.getComponent().toShortString()
2228 + ": " + e.toString(), e);
2229 }
2230 }
2231 }
2232 return r;
2233 }
2234
Dianne Hackborn30c9bd82010-12-01 16:07:40 -08002235 final void cleanUpPendingRemoveWindows(ActivityClientRecord r) {
2236 if (r.mPendingRemoveWindow != null) {
2237 r.mPendingRemoveWindowManager.removeViewImmediate(r.mPendingRemoveWindow);
2238 IBinder wtoken = r.mPendingRemoveWindow.getWindowToken();
2239 if (wtoken != null) {
2240 WindowManagerImpl.getDefault().closeAll(wtoken,
2241 r.activity.getClass().getName(), "Activity");
2242 }
2243 }
2244 r.mPendingRemoveWindow = null;
2245 r.mPendingRemoveWindowManager = null;
2246 }
2247
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002248 final void handleResumeActivity(IBinder token, boolean clearHide, boolean isForward) {
2249 // If we are getting ready to gc after going to the background, well
2250 // we are back active so skip it.
2251 unscheduleGcIdler();
2252
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07002253 ActivityClientRecord r = performResumeActivity(token, clearHide);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002254
2255 if (r != null) {
2256 final Activity a = r.activity;
2257
Dianne Hackborn399cccb2010-04-13 22:57:49 -07002258 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002259 TAG, "Resume " + r + " started activity: " +
2260 a.mStartedActivity + ", hideForNow: " + r.hideForNow
2261 + ", finished: " + a.mFinished);
2262
2263 final int forwardBit = isForward ?
2264 WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION : 0;
Bob Leee5408332009-09-04 18:31:17 -07002265
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002266 // If the window hasn't yet been added to the window manager,
2267 // and this guy didn't finish itself or start another activity,
2268 // then go ahead and add the window.
Dianne Hackborn061d58a2010-03-12 15:07:06 -08002269 boolean willBeVisible = !a.mStartedActivity;
2270 if (!willBeVisible) {
2271 try {
2272 willBeVisible = ActivityManagerNative.getDefault().willActivityBeVisible(
2273 a.getActivityToken());
2274 } catch (RemoteException e) {
2275 }
2276 }
2277 if (r.window == null && !a.mFinished && willBeVisible) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002278 r.window = r.activity.getWindow();
2279 View decor = r.window.getDecorView();
2280 decor.setVisibility(View.INVISIBLE);
2281 ViewManager wm = a.getWindowManager();
2282 WindowManager.LayoutParams l = r.window.getAttributes();
2283 a.mDecor = decor;
2284 l.type = WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
2285 l.softInputMode |= forwardBit;
2286 if (a.mVisibleFromClient) {
2287 a.mWindowAdded = true;
2288 wm.addView(decor, l);
2289 }
2290
2291 // If the window has already been added, but during resume
2292 // we started another activity, then don't yet make the
Dianne Hackborn061d58a2010-03-12 15:07:06 -08002293 // window visible.
2294 } else if (!willBeVisible) {
Dianne Hackborn399cccb2010-04-13 22:57:49 -07002295 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002296 TAG, "Launch " + r + " mStartedActivity set");
2297 r.hideForNow = true;
2298 }
2299
Dianne Hackborn30c9bd82010-12-01 16:07:40 -08002300 // Get rid of anything left hanging around.
2301 cleanUpPendingRemoveWindows(r);
2302
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002303 // The window is now visible if it has been added, we are not
2304 // simply finishing, and we are not starting another activity.
Dianne Hackborn061d58a2010-03-12 15:07:06 -08002305 if (!r.activity.mFinished && willBeVisible
Dianne Hackbornc1e605e2009-09-25 17:18:15 -07002306 && r.activity.mDecor != null && !r.hideForNow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002307 if (r.newConfig != null) {
Dianne Hackborn399cccb2010-04-13 22:57:49 -07002308 if (DEBUG_CONFIGURATION) Slog.v(TAG, "Resuming activity "
Dianne Hackborndc6b6352009-09-30 14:20:09 -07002309 + r.activityInfo.name + " with newConfig " + r.newConfig);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002310 performConfigurationChanged(r.activity, r.newConfig);
2311 r.newConfig = null;
2312 }
Dianne Hackborn399cccb2010-04-13 22:57:49 -07002313 if (localLOGV) Slog.v(TAG, "Resuming " + r + " with isForward="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002314 + isForward);
2315 WindowManager.LayoutParams l = r.window.getAttributes();
2316 if ((l.softInputMode
2317 & WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION)
2318 != forwardBit) {
2319 l.softInputMode = (l.softInputMode
2320 & (~WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION))
2321 | forwardBit;
Dianne Hackbornc1e605e2009-09-25 17:18:15 -07002322 if (r.activity.mVisibleFromClient) {
2323 ViewManager wm = a.getWindowManager();
2324 View decor = r.window.getDecorView();
2325 wm.updateViewLayout(decor, l);
2326 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002327 }
2328 r.activity.mVisibleFromServer = true;
2329 mNumVisibleActivities++;
2330 if (r.activity.mVisibleFromClient) {
2331 r.activity.makeVisible();
2332 }
2333 }
2334
Dianne Hackborn30c9bd82010-12-01 16:07:40 -08002335 if (!r.onlyLocalRequest) {
2336 r.nextIdle = mNewActivities;
2337 mNewActivities = r;
2338 if (localLOGV) Slog.v(
2339 TAG, "Scheduling idle handler for " + r);
2340 Looper.myQueue().addIdleHandler(new Idler());
2341 }
2342 r.onlyLocalRequest = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002343
2344 } else {
2345 // If an exception was thrown when trying to resume, then
2346 // just end this activity.
2347 try {
2348 ActivityManagerNative.getDefault()
2349 .finishActivity(token, Activity.RESULT_CANCELED, null);
2350 } catch (RemoteException ex) {
2351 }
2352 }
2353 }
2354
2355 private int mThumbnailWidth = -1;
2356 private int mThumbnailHeight = -1;
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08002357 private Bitmap mAvailThumbnailBitmap = null;
2358 private Canvas mThumbnailCanvas = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002359
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07002360 private final Bitmap createThumbnailBitmap(ActivityClientRecord r) {
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08002361 Bitmap thumbnail = mAvailThumbnailBitmap;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002362 try {
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08002363 if (thumbnail == null) {
2364 int w = mThumbnailWidth;
2365 int h;
2366 if (w < 0) {
2367 Resources res = r.activity.getResources();
2368 mThumbnailHeight = h =
2369 res.getDimensionPixelSize(com.android.internal.R.dimen.thumbnail_height);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002370
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08002371 mThumbnailWidth = w =
2372 res.getDimensionPixelSize(com.android.internal.R.dimen.thumbnail_width);
2373 } else {
2374 h = mThumbnailHeight;
2375 }
2376
2377 // On platforms where we don't want thumbnails, set dims to (0,0)
2378 if ((w > 0) && (h > 0)) {
2379 thumbnail = Bitmap.createBitmap(w, h, THUMBNAIL_FORMAT);
2380 thumbnail.eraseColor(0);
2381 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002382 }
2383
Dianne Hackbornfb3806d2010-12-09 13:14:12 -08002384 if (thumbnail != null) {
2385 Canvas cv = mThumbnailCanvas;
2386 if (cv == null) {
2387 mThumbnailCanvas = cv = new Canvas();
2388 }
2389
2390 cv.setBitmap(thumbnail);
2391 if (!r.activity.onCreateThumbnail(thumbnail, cv)) {
2392 mAvailThumbnailBitmap = thumbnail;
2393 thumbnail = null;
2394 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002395 }
Jim Miller0b2a6d02010-07-13 18:01:29 -07002396
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002397 } catch (Exception e) {
2398 if (!mInstrumentation.onException(r.activity, e)) {
2399 throw new RuntimeException(
2400 "Unable to create thumbnail of "
2401 + r.intent.getComponent().toShortString()
2402 + ": " + e.toString(), e);
2403 }
2404 thumbnail = null;
2405 }
2406
2407 return thumbnail;
2408 }
2409
2410 private final void handlePauseActivity(IBinder token, boolean finished,
2411 boolean userLeaving, int configChanges) {
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07002412 ActivityClientRecord r = mActivities.get(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002413 if (r != null) {
Dianne Hackborn399cccb2010-04-13 22:57:49 -07002414 //Slog.v(TAG, "userLeaving=" + userLeaving + " handling pause of " + r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002415 if (userLeaving) {
2416 performUserLeavingActivity(r);
2417 }
Bob Leee5408332009-09-04 18:31:17 -07002418
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002419 r.activity.mConfigChangeFlags |= configChanges;
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08002420 performPauseActivity(token, finished, r.isPreHoneycomb());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002421
Dianne Hackbornaa93bcd2010-10-27 13:57:00 -07002422 // Make sure any pending writes are now committed.
Dianne Hackborn5d9d03a2011-01-24 13:15:09 -08002423 if (r.isPreHoneycomb()) {
2424 QueuedWork.waitToFinish();
2425 }
Dianne Hackbornaa93bcd2010-10-27 13:57:00 -07002426
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002427 // Tell the activity manager we have paused.
2428 try {
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08002429 ActivityManagerNative.getDefault().activityPaused(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002430 } catch (RemoteException ex) {
2431 }
2432 }
2433 }
2434
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07002435 final void performUserLeavingActivity(ActivityClientRecord r) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002436 mInstrumentation.callActivityOnUserLeaving(r.activity);
2437 }
2438
2439 final Bundle performPauseActivity(IBinder token, boolean finished,
2440 boolean saveState) {
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07002441 ActivityClientRecord r = mActivities.get(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002442 return r != null ? performPauseActivity(r, finished, saveState) : null;
2443 }
2444
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07002445 final Bundle performPauseActivity(ActivityClientRecord r, boolean finished,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002446 boolean saveState) {
2447 if (r.paused) {
2448 if (r.activity.mFinished) {
2449 // If we are finishing, we won't call onResume() in certain cases.
2450 // So here we likewise don't want to call onPause() if the activity
2451 // isn't resumed.
2452 return null;
2453 }
2454 RuntimeException e = new RuntimeException(
2455 "Performing pause of activity that is not resumed: "
2456 + r.intent.getComponent().toShortString());
Dianne Hackbornc9421ba2010-03-11 22:23:46 -08002457 Slog.e(TAG, e.getMessage(), e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002458 }
2459 Bundle state = null;
2460 if (finished) {
2461 r.activity.mFinished = true;
2462 }
2463 try {
2464 // Next have the activity save its current state and managed dialogs...
2465 if (!r.activity.mFinished && saveState) {
2466 state = new Bundle();
2467 mInstrumentation.callActivityOnSaveInstanceState(r.activity, state);
2468 r.state = state;
2469 }
2470 // Now we are idle.
2471 r.activity.mCalled = false;
2472 mInstrumentation.callActivityOnPause(r.activity);
2473 EventLog.writeEvent(LOG_ON_PAUSE_CALLED, r.activity.getComponentName().getClassName());
2474 if (!r.activity.mCalled) {
2475 throw new SuperNotCalledException(
2476 "Activity " + r.intent.getComponent().toShortString() +
2477 " did not call through to super.onPause()");
2478 }
2479
2480 } catch (SuperNotCalledException e) {
2481 throw e;
2482
2483 } catch (Exception e) {
2484 if (!mInstrumentation.onException(r.activity, e)) {
2485 throw new RuntimeException(
2486 "Unable to pause activity "
2487 + r.intent.getComponent().toShortString()
2488 + ": " + e.toString(), e);
2489 }
2490 }
2491 r.paused = true;
Jeff Hamilton52d32032011-01-08 15:31:26 -06002492
2493 // Notify any outstanding on paused listeners
2494 ArrayList<OnActivityPausedListener> listeners;
2495 synchronized (mOnPauseListeners) {
2496 listeners = mOnPauseListeners.remove(r.activity);
2497 }
2498 int size = (listeners != null ? listeners.size() : 0);
2499 for (int i = 0; i < size; i++) {
2500 listeners.get(i).onPaused(r.activity);
2501 }
2502
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002503 return state;
2504 }
2505
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08002506 final void performStopActivity(IBinder token, boolean saveState) {
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07002507 ActivityClientRecord r = mActivities.get(token);
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08002508 performStopActivityInner(r, null, false, saveState);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002509 }
2510
2511 private static class StopInfo {
2512 Bitmap thumbnail;
2513 CharSequence description;
2514 }
2515
2516 private final class ProviderRefCount {
2517 public int count;
2518 ProviderRefCount(int pCount) {
2519 count = pCount;
2520 }
2521 }
2522
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08002523 /**
2524 * Core implementation of stopping an activity. Note this is a little
2525 * tricky because the server's meaning of stop is slightly different
2526 * than our client -- for the server, stop means to save state and give
2527 * it the result when it is done, but the window may still be visible.
2528 * For the client, we want to call onStop()/onStart() to indicate when
2529 * the activity's UI visibillity changes.
2530 */
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07002531 private final void performStopActivityInner(ActivityClientRecord r,
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08002532 StopInfo info, boolean keepShown, boolean saveState) {
Dianne Hackborn399cccb2010-04-13 22:57:49 -07002533 if (localLOGV) Slog.v(TAG, "Performing stop of " + r);
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08002534 Bundle state = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002535 if (r != null) {
2536 if (!keepShown && r.stopped) {
2537 if (r.activity.mFinished) {
2538 // If we are finishing, we won't call onResume() in certain
2539 // cases. So here we likewise don't want to call onStop()
2540 // if the activity isn't resumed.
2541 return;
2542 }
2543 RuntimeException e = new RuntimeException(
2544 "Performing stop of activity that is not resumed: "
2545 + r.intent.getComponent().toShortString());
Dianne Hackbornc9421ba2010-03-11 22:23:46 -08002546 Slog.e(TAG, e.getMessage(), e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002547 }
2548
2549 if (info != null) {
2550 try {
2551 // First create a thumbnail for the activity...
Jim Miller0b2a6d02010-07-13 18:01:29 -07002552 info.thumbnail = createThumbnailBitmap(r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002553 info.description = r.activity.onCreateDescription();
2554 } catch (Exception e) {
2555 if (!mInstrumentation.onException(r.activity, e)) {
2556 throw new RuntimeException(
2557 "Unable to save state of activity "
2558 + r.intent.getComponent().toShortString()
2559 + ": " + e.toString(), e);
2560 }
2561 }
2562 }
2563
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08002564 // Next have the activity save its current state and managed dialogs...
2565 if (!r.activity.mFinished && saveState) {
2566 if (r.state == null) {
2567 state = new Bundle();
2568 mInstrumentation.callActivityOnSaveInstanceState(r.activity, state);
2569 r.state = state;
2570 } else {
2571 state = r.state;
2572 }
2573 }
2574
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002575 if (!keepShown) {
2576 try {
2577 // Now we are idle.
2578 r.activity.performStop();
2579 } catch (Exception e) {
2580 if (!mInstrumentation.onException(r.activity, e)) {
2581 throw new RuntimeException(
2582 "Unable to stop activity "
2583 + r.intent.getComponent().toShortString()
2584 + ": " + e.toString(), e);
2585 }
2586 }
2587 r.stopped = true;
2588 }
2589
2590 r.paused = true;
2591 }
2592 }
2593
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07002594 private final void updateVisibility(ActivityClientRecord r, boolean show) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002595 View v = r.activity.mDecor;
2596 if (v != null) {
2597 if (show) {
2598 if (!r.activity.mVisibleFromServer) {
2599 r.activity.mVisibleFromServer = true;
2600 mNumVisibleActivities++;
2601 if (r.activity.mVisibleFromClient) {
2602 r.activity.makeVisible();
2603 }
2604 }
2605 if (r.newConfig != null) {
Dianne Hackborn399cccb2010-04-13 22:57:49 -07002606 if (DEBUG_CONFIGURATION) Slog.v(TAG, "Updating activity vis "
Dianne Hackborndc6b6352009-09-30 14:20:09 -07002607 + r.activityInfo.name + " with new config " + r.newConfig);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002608 performConfigurationChanged(r.activity, r.newConfig);
2609 r.newConfig = null;
2610 }
2611 } else {
2612 if (r.activity.mVisibleFromServer) {
2613 r.activity.mVisibleFromServer = false;
2614 mNumVisibleActivities--;
2615 v.setVisibility(View.INVISIBLE);
2616 }
2617 }
2618 }
2619 }
2620
2621 private final void handleStopActivity(IBinder token, boolean show, int configChanges) {
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07002622 ActivityClientRecord r = mActivities.get(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002623 r.activity.mConfigChangeFlags |= configChanges;
2624
2625 StopInfo info = new StopInfo();
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08002626 performStopActivityInner(r, info, show, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002627
Dianne Hackborn399cccb2010-04-13 22:57:49 -07002628 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002629 TAG, "Finishing stop of " + r + ": show=" + show
2630 + " win=" + r.window);
2631
2632 updateVisibility(r, show);
Bob Leee5408332009-09-04 18:31:17 -07002633
Dianne Hackborn5d9d03a2011-01-24 13:15:09 -08002634 // Make sure any pending writes are now committed.
2635 if (!r.isPreHoneycomb()) {
2636 QueuedWork.waitToFinish();
2637 }
2638
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002639 // Tell activity manager we have been stopped.
2640 try {
2641 ActivityManagerNative.getDefault().activityStopped(
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08002642 r.token, r.state, info.thumbnail, info.description);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002643 } catch (RemoteException ex) {
2644 }
2645 }
2646
2647 final void performRestartActivity(IBinder token) {
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07002648 ActivityClientRecord r = mActivities.get(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002649 if (r.stopped) {
2650 r.activity.performRestart();
2651 r.stopped = false;
2652 }
2653 }
2654
2655 private final void handleWindowVisibility(IBinder token, boolean show) {
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07002656 ActivityClientRecord r = mActivities.get(token);
Dianne Hackbornbfddc0f2010-12-14 11:28:01 -08002657
2658 if (r == null) {
2659 Log.w(TAG, "handleWindowVisibility: no activity for token " + token);
2660 return;
2661 }
2662
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002663 if (!show && !r.stopped) {
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08002664 performStopActivityInner(r, null, show, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002665 } else if (show && r.stopped) {
2666 // If we are getting ready to gc after going to the background, well
2667 // we are back active so skip it.
2668 unscheduleGcIdler();
2669
2670 r.activity.performRestart();
2671 r.stopped = false;
2672 }
2673 if (r.activity.mDecor != null) {
Dianne Hackborn399cccb2010-04-13 22:57:49 -07002674 if (Config.LOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002675 TAG, "Handle window " + r + " visibility: " + show);
2676 updateVisibility(r, show);
2677 }
2678 }
2679
Dianne Hackborn4eba96b2011-01-21 13:34:36 -08002680 private final void handleSleeping(IBinder token, boolean sleeping) {
2681 ActivityClientRecord r = mActivities.get(token);
2682
2683 if (r == null) {
Dianne Hackborn842e04b2011-01-22 13:00:12 -08002684 Log.w(TAG, "handleSleeping: no activity for token " + token);
Dianne Hackborn4eba96b2011-01-21 13:34:36 -08002685 return;
2686 }
2687
2688 if (sleeping) {
Dianne Hackborn842e04b2011-01-22 13:00:12 -08002689 if (!r.stopped && !r.isPreHoneycomb()) {
Dianne Hackborn4eba96b2011-01-21 13:34:36 -08002690 try {
2691 // Now we are idle.
2692 r.activity.performStop();
2693 } catch (Exception e) {
2694 if (!mInstrumentation.onException(r.activity, e)) {
2695 throw new RuntimeException(
2696 "Unable to stop activity "
2697 + r.intent.getComponent().toShortString()
2698 + ": " + e.toString(), e);
2699 }
2700 }
2701 r.stopped = true;
2702 }
Dianne Hackborn5d9d03a2011-01-24 13:15:09 -08002703
2704 // Make sure any pending writes are now committed.
2705 if (!r.isPreHoneycomb()) {
2706 QueuedWork.waitToFinish();
2707 }
2708
Dianne Hackborn4eba96b2011-01-21 13:34:36 -08002709 // Tell activity manager we slept.
2710 try {
2711 ActivityManagerNative.getDefault().activitySlept(r.token);
2712 } catch (RemoteException ex) {
2713 }
2714 } else {
2715 if (r.stopped && r.activity.mVisibleFromServer) {
2716 r.activity.performRestart();
2717 r.stopped = false;
2718 }
2719 }
2720 }
2721
Svetoslav Ganov54d068e2011-03-02 12:58:40 -08002722 private void handleSetCoreSettings(Bundle coreSettings) {
2723 if (mBoundApplication != null) {
2724 synchronized (mBoundApplication) {
2725 mBoundApplication.coreSettings = coreSettings;
2726 }
2727 }
2728 }
2729
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07002730 private final void deliverResults(ActivityClientRecord r, List<ResultInfo> results) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002731 final int N = results.size();
2732 for (int i=0; i<N; i++) {
2733 ResultInfo ri = results.get(i);
2734 try {
2735 if (ri.mData != null) {
2736 ri.mData.setExtrasClassLoader(r.activity.getClassLoader());
2737 }
Dianne Hackborn399cccb2010-04-13 22:57:49 -07002738 if (DEBUG_RESULTS) Slog.v(TAG,
Chris Tate8a7dc172009-03-24 20:11:42 -07002739 "Delivering result to activity " + r + " : " + ri);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002740 r.activity.dispatchActivityResult(ri.mResultWho,
2741 ri.mRequestCode, ri.mResultCode, ri.mData);
2742 } catch (Exception e) {
2743 if (!mInstrumentation.onException(r.activity, e)) {
2744 throw new RuntimeException(
2745 "Failure delivering result " + ri + " to activity "
2746 + r.intent.getComponent().toShortString()
2747 + ": " + e.toString(), e);
2748 }
2749 }
2750 }
2751 }
2752
2753 private final void handleSendResult(ResultData res) {
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07002754 ActivityClientRecord r = mActivities.get(res.token);
Dianne Hackborn399cccb2010-04-13 22:57:49 -07002755 if (DEBUG_RESULTS) Slog.v(TAG, "Handling send result to " + r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002756 if (r != null) {
2757 final boolean resumed = !r.paused;
2758 if (!r.activity.mFinished && r.activity.mDecor != null
2759 && r.hideForNow && resumed) {
2760 // We had hidden the activity because it started another
2761 // one... we have gotten a result back and we are not
2762 // paused, so make sure our window is visible.
2763 updateVisibility(r, true);
2764 }
2765 if (resumed) {
2766 try {
2767 // Now we are idle.
2768 r.activity.mCalled = false;
Dianne Hackbornfb3cffe2010-10-25 17:08:56 -07002769 r.activity.mTemporaryPause = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002770 mInstrumentation.callActivityOnPause(r.activity);
2771 if (!r.activity.mCalled) {
2772 throw new SuperNotCalledException(
2773 "Activity " + r.intent.getComponent().toShortString()
2774 + " did not call through to super.onPause()");
2775 }
2776 } catch (SuperNotCalledException e) {
2777 throw e;
2778 } catch (Exception e) {
2779 if (!mInstrumentation.onException(r.activity, e)) {
2780 throw new RuntimeException(
2781 "Unable to pause activity "
2782 + r.intent.getComponent().toShortString()
2783 + ": " + e.toString(), e);
2784 }
2785 }
2786 }
2787 deliverResults(r, res.results);
2788 if (resumed) {
2789 mInstrumentation.callActivityOnResume(r.activity);
Dianne Hackbornfb3cffe2010-10-25 17:08:56 -07002790 r.activity.mTemporaryPause = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002791 }
2792 }
2793 }
2794
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07002795 public final ActivityClientRecord performDestroyActivity(IBinder token, boolean finishing) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002796 return performDestroyActivity(token, finishing, 0, false);
2797 }
2798
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07002799 private final ActivityClientRecord performDestroyActivity(IBinder token, boolean finishing,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002800 int configChanges, boolean getNonConfigInstance) {
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07002801 ActivityClientRecord r = mActivities.get(token);
Brad Fitzpatrick5f8b5c12011-01-20 15:12:08 -08002802 Class activityClass = null;
Dianne Hackborn399cccb2010-04-13 22:57:49 -07002803 if (localLOGV) Slog.v(TAG, "Performing finish of " + r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002804 if (r != null) {
Brad Fitzpatrick5f8b5c12011-01-20 15:12:08 -08002805 activityClass = r.activity.getClass();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002806 r.activity.mConfigChangeFlags |= configChanges;
2807 if (finishing) {
2808 r.activity.mFinished = true;
2809 }
2810 if (!r.paused) {
2811 try {
2812 r.activity.mCalled = false;
2813 mInstrumentation.callActivityOnPause(r.activity);
Bob Leee5408332009-09-04 18:31:17 -07002814 EventLog.writeEvent(LOG_ON_PAUSE_CALLED,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002815 r.activity.getComponentName().getClassName());
2816 if (!r.activity.mCalled) {
2817 throw new SuperNotCalledException(
Mitsuru Oshimad9aef732009-06-16 20:20:50 -07002818 "Activity " + safeToComponentShortString(r.intent)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002819 + " did not call through to super.onPause()");
2820 }
2821 } catch (SuperNotCalledException e) {
2822 throw e;
2823 } catch (Exception e) {
2824 if (!mInstrumentation.onException(r.activity, e)) {
2825 throw new RuntimeException(
2826 "Unable to pause activity "
Mitsuru Oshimad9aef732009-06-16 20:20:50 -07002827 + safeToComponentShortString(r.intent)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002828 + ": " + e.toString(), e);
2829 }
2830 }
2831 r.paused = true;
2832 }
2833 if (!r.stopped) {
2834 try {
2835 r.activity.performStop();
2836 } catch (SuperNotCalledException e) {
2837 throw e;
2838 } catch (Exception e) {
2839 if (!mInstrumentation.onException(r.activity, e)) {
2840 throw new RuntimeException(
2841 "Unable to stop activity "
Mitsuru Oshimad9aef732009-06-16 20:20:50 -07002842 + safeToComponentShortString(r.intent)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002843 + ": " + e.toString(), e);
2844 }
2845 }
2846 r.stopped = true;
2847 }
2848 if (getNonConfigInstance) {
2849 try {
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -07002850 r.lastNonConfigurationInstances
2851 = r.activity.retainNonConfigurationInstances();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002852 } catch (Exception e) {
2853 if (!mInstrumentation.onException(r.activity, e)) {
2854 throw new RuntimeException(
2855 "Unable to retain activity "
2856 + r.intent.getComponent().toShortString()
2857 + ": " + e.toString(), e);
2858 }
2859 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002860 }
2861 try {
2862 r.activity.mCalled = false;
Dianne Hackborn2dedce62010-04-15 14:45:25 -07002863 mInstrumentation.callActivityOnDestroy(r.activity);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002864 if (!r.activity.mCalled) {
2865 throw new SuperNotCalledException(
Mitsuru Oshimad9aef732009-06-16 20:20:50 -07002866 "Activity " + safeToComponentShortString(r.intent) +
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002867 " did not call through to super.onDestroy()");
2868 }
2869 if (r.window != null) {
2870 r.window.closeAllPanels();
2871 }
2872 } catch (SuperNotCalledException e) {
2873 throw e;
2874 } catch (Exception e) {
2875 if (!mInstrumentation.onException(r.activity, e)) {
2876 throw new RuntimeException(
Mitsuru Oshimad9aef732009-06-16 20:20:50 -07002877 "Unable to destroy activity " + safeToComponentShortString(r.intent)
2878 + ": " + e.toString(), e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002879 }
2880 }
2881 }
2882 mActivities.remove(token);
Brad Fitzpatrick5f8b5c12011-01-20 15:12:08 -08002883 StrictMode.decrementExpectedActivityCount(activityClass);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002884 return r;
2885 }
2886
Mitsuru Oshimad9aef732009-06-16 20:20:50 -07002887 private static String safeToComponentShortString(Intent intent) {
2888 ComponentName component = intent.getComponent();
2889 return component == null ? "[Unknown]" : component.toShortString();
2890 }
2891
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002892 private final void handleDestroyActivity(IBinder token, boolean finishing,
2893 int configChanges, boolean getNonConfigInstance) {
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07002894 ActivityClientRecord r = performDestroyActivity(token, finishing,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002895 configChanges, getNonConfigInstance);
2896 if (r != null) {
Dianne Hackborn30c9bd82010-12-01 16:07:40 -08002897 cleanUpPendingRemoveWindows(r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002898 WindowManager wm = r.activity.getWindowManager();
2899 View v = r.activity.mDecor;
2900 if (v != null) {
2901 if (r.activity.mVisibleFromServer) {
2902 mNumVisibleActivities--;
2903 }
2904 IBinder wtoken = v.getWindowToken();
2905 if (r.activity.mWindowAdded) {
Dianne Hackborn30c9bd82010-12-01 16:07:40 -08002906 if (r.onlyLocalRequest) {
2907 // Hold off on removing this until the new activity's
2908 // window is being added.
2909 r.mPendingRemoveWindow = v;
2910 r.mPendingRemoveWindowManager = wm;
2911 } else {
2912 wm.removeViewImmediate(v);
2913 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002914 }
Dianne Hackborn30c9bd82010-12-01 16:07:40 -08002915 if (wtoken != null && r.mPendingRemoveWindow == null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002916 WindowManagerImpl.getDefault().closeAll(wtoken,
2917 r.activity.getClass().getName(), "Activity");
2918 }
2919 r.activity.mDecor = null;
2920 }
Dianne Hackborn30c9bd82010-12-01 16:07:40 -08002921 if (r.mPendingRemoveWindow == null) {
2922 // If we are delaying the removal of the activity window, then
2923 // we can't clean up all windows here. Note that we can't do
2924 // so later either, which means any windows that aren't closed
2925 // by the app will leak. Well we try to warning them a lot
2926 // about leaking windows, because that is a bug, so if they are
2927 // using this recreate facility then they get to live with leaks.
2928 WindowManagerImpl.getDefault().closeAll(token,
2929 r.activity.getClass().getName(), "Activity");
2930 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002931
2932 // Mocked out contexts won't be participating in the normal
2933 // process lifecycle, but if we're running with a proper
2934 // ApplicationContext we need to have it tear down things
2935 // cleanly.
2936 Context c = r.activity.getBaseContext();
Dianne Hackborn21556372010-02-04 16:34:40 -08002937 if (c instanceof ContextImpl) {
2938 ((ContextImpl) c).scheduleFinalCleanup(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002939 r.activity.getClass().getName(), "Activity");
2940 }
2941 }
2942 if (finishing) {
2943 try {
2944 ActivityManagerNative.getDefault().activityDestroyed(token);
2945 } catch (RemoteException ex) {
2946 // If the system process has died, it's game over for everyone.
2947 }
2948 }
2949 }
2950
Dianne Hackborn30c9bd82010-12-01 16:07:40 -08002951 public final void requestRelaunchActivity(IBinder token,
2952 List<ResultInfo> pendingResults, List<Intent> pendingNewIntents,
2953 int configChanges, boolean notResumed, Configuration config,
2954 boolean fromServer) {
2955 ActivityClientRecord target = null;
2956
2957 synchronized (mPackages) {
2958 for (int i=0; i<mRelaunchingActivities.size(); i++) {
2959 ActivityClientRecord r = mRelaunchingActivities.get(i);
2960 if (r.token == token) {
2961 target = r;
2962 if (pendingResults != null) {
2963 if (r.pendingResults != null) {
2964 r.pendingResults.addAll(pendingResults);
2965 } else {
2966 r.pendingResults = pendingResults;
2967 }
2968 }
2969 if (pendingNewIntents != null) {
2970 if (r.pendingIntents != null) {
2971 r.pendingIntents.addAll(pendingNewIntents);
2972 } else {
2973 r.pendingIntents = pendingNewIntents;
2974 }
2975 }
2976 break;
2977 }
2978 }
2979
2980 if (target == null) {
2981 target = new ActivityClientRecord();
2982 target.token = token;
2983 target.pendingResults = pendingResults;
2984 target.pendingIntents = pendingNewIntents;
2985 if (!fromServer) {
2986 ActivityClientRecord existing = mActivities.get(token);
2987 if (existing != null) {
2988 target.startsNotResumed = existing.paused;
2989 }
2990 target.onlyLocalRequest = true;
2991 }
2992 mRelaunchingActivities.add(target);
2993 queueOrSendMessage(H.RELAUNCH_ACTIVITY, target);
2994 }
2995
2996 if (fromServer) {
2997 target.startsNotResumed = notResumed;
2998 target.onlyLocalRequest = false;
2999 }
3000 if (config != null) {
3001 target.createdConfig = config;
3002 }
3003 target.pendingConfigChanges |= configChanges;
3004 }
3005 }
3006
3007 private final void handleRelaunchActivity(ActivityClientRecord tmp) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003008 // If we are getting ready to gc after going to the background, well
3009 // we are back active so skip it.
3010 unscheduleGcIdler();
3011
3012 Configuration changedConfig = null;
Dianne Hackborn30c9bd82010-12-01 16:07:40 -08003013 int configChanges = 0;
Bob Leee5408332009-09-04 18:31:17 -07003014
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003015 // First: make sure we have the most recent configuration and most
3016 // recent version of the activity, or skip it if some previous call
3017 // had taken a more recent version.
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003018 synchronized (mPackages) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003019 int N = mRelaunchingActivities.size();
3020 IBinder token = tmp.token;
3021 tmp = null;
3022 for (int i=0; i<N; i++) {
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07003023 ActivityClientRecord r = mRelaunchingActivities.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003024 if (r.token == token) {
3025 tmp = r;
Dianne Hackborn30c9bd82010-12-01 16:07:40 -08003026 configChanges |= tmp.pendingConfigChanges;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003027 mRelaunchingActivities.remove(i);
3028 i--;
3029 N--;
3030 }
3031 }
Bob Leee5408332009-09-04 18:31:17 -07003032
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003033 if (tmp == null) {
Dianne Hackborn399cccb2010-04-13 22:57:49 -07003034 if (DEBUG_CONFIGURATION) Slog.v(TAG, "Abort, activity not relaunching!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003035 return;
3036 }
Bob Leee5408332009-09-04 18:31:17 -07003037
Dianne Hackborn30c9bd82010-12-01 16:07:40 -08003038 if (DEBUG_CONFIGURATION) Slog.v(TAG, "Relaunching activity "
3039 + tmp.token + " with configChanges=0x"
3040 + Integer.toHexString(configChanges));
3041
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003042 if (mPendingConfiguration != null) {
3043 changedConfig = mPendingConfiguration;
3044 mPendingConfiguration = null;
3045 }
3046 }
Bob Leee5408332009-09-04 18:31:17 -07003047
Dianne Hackborn871ecdc2009-12-11 15:24:33 -08003048 if (tmp.createdConfig != null) {
3049 // If the activity manager is passing us its current config,
3050 // assume that is really what we want regardless of what we
3051 // may have pending.
3052 if (mConfiguration == null
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003053 || (tmp.createdConfig.isOtherSeqNewer(mConfiguration)
3054 && mConfiguration.diff(tmp.createdConfig) != 0)) {
3055 if (changedConfig == null
3056 || tmp.createdConfig.isOtherSeqNewer(changedConfig)) {
3057 changedConfig = tmp.createdConfig;
3058 }
Dianne Hackborn871ecdc2009-12-11 15:24:33 -08003059 }
3060 }
3061
Dianne Hackborn399cccb2010-04-13 22:57:49 -07003062 if (DEBUG_CONFIGURATION) Slog.v(TAG, "Relaunching activity "
Dianne Hackborndc6b6352009-09-30 14:20:09 -07003063 + tmp.token + ": changedConfig=" + changedConfig);
3064
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003065 // If there was a pending configuration change, execute it first.
3066 if (changedConfig != null) {
3067 handleConfigurationChanged(changedConfig);
3068 }
Bob Leee5408332009-09-04 18:31:17 -07003069
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07003070 ActivityClientRecord r = mActivities.get(tmp.token);
Dianne Hackborn399cccb2010-04-13 22:57:49 -07003071 if (DEBUG_CONFIGURATION) Slog.v(TAG, "Handling relaunch of " + r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003072 if (r == null) {
3073 return;
3074 }
Bob Leee5408332009-09-04 18:31:17 -07003075
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003076 r.activity.mConfigChangeFlags |= configChanges;
Dianne Hackborn30c9bd82010-12-01 16:07:40 -08003077 r.onlyLocalRequest = tmp.onlyLocalRequest;
Christopher Tateb70f3df2009-04-07 16:07:59 -07003078 Intent currentIntent = r.activity.mIntent;
Bob Leee5408332009-09-04 18:31:17 -07003079
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08003080 r.activity.mChangingConfigurations = true;
3081
Dianne Hackborne2b04802010-12-09 09:24:55 -08003082 // Need to ensure state is saved.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003083 if (!r.paused) {
Dianne Hackborne2b04802010-12-09 09:24:55 -08003084 performPauseActivity(r.token, false, r.isPreHoneycomb());
3085 }
3086 if (r.state == null && !r.stopped && !r.isPreHoneycomb()) {
3087 r.state = new Bundle();
3088 mInstrumentation.callActivityOnSaveInstanceState(r.activity, r.state);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003089 }
Bob Leee5408332009-09-04 18:31:17 -07003090
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003091 handleDestroyActivity(r.token, false, configChanges, true);
Bob Leee5408332009-09-04 18:31:17 -07003092
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003093 r.activity = null;
3094 r.window = null;
3095 r.hideForNow = false;
3096 r.nextIdle = null;
The Android Open Source Project10592532009-03-18 17:39:46 -07003097 // Merge any pending results and pending intents; don't just replace them
3098 if (tmp.pendingResults != null) {
3099 if (r.pendingResults == null) {
3100 r.pendingResults = tmp.pendingResults;
3101 } else {
3102 r.pendingResults.addAll(tmp.pendingResults);
3103 }
3104 }
3105 if (tmp.pendingIntents != null) {
3106 if (r.pendingIntents == null) {
3107 r.pendingIntents = tmp.pendingIntents;
3108 } else {
3109 r.pendingIntents.addAll(tmp.pendingIntents);
3110 }
3111 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003112 r.startsNotResumed = tmp.startsNotResumed;
Bob Leee5408332009-09-04 18:31:17 -07003113
Christopher Tateb70f3df2009-04-07 16:07:59 -07003114 handleLaunchActivity(r, currentIntent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003115 }
3116
3117 private final void handleRequestThumbnail(IBinder token) {
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07003118 ActivityClientRecord r = mActivities.get(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003119 Bitmap thumbnail = createThumbnailBitmap(r);
3120 CharSequence description = null;
3121 try {
3122 description = r.activity.onCreateDescription();
3123 } catch (Exception e) {
3124 if (!mInstrumentation.onException(r.activity, e)) {
3125 throw new RuntimeException(
3126 "Unable to create description of activity "
3127 + r.intent.getComponent().toShortString()
3128 + ": " + e.toString(), e);
3129 }
3130 }
3131 //System.out.println("Reporting top thumbnail " + thumbnail);
3132 try {
3133 ActivityManagerNative.getDefault().reportThumbnail(
3134 token, thumbnail, description);
3135 } catch (RemoteException ex) {
3136 }
3137 }
3138
3139 ArrayList<ComponentCallbacks> collectComponentCallbacksLocked(
3140 boolean allActivities, Configuration newConfig) {
3141 ArrayList<ComponentCallbacks> callbacks
3142 = new ArrayList<ComponentCallbacks>();
Bob Leee5408332009-09-04 18:31:17 -07003143
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003144 if (mActivities.size() > 0) {
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07003145 Iterator<ActivityClientRecord> it = mActivities.values().iterator();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003146 while (it.hasNext()) {
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07003147 ActivityClientRecord ar = it.next();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003148 Activity a = ar.activity;
3149 if (a != null) {
3150 if (!ar.activity.mFinished && (allActivities ||
3151 (a != null && !ar.paused))) {
3152 // If the activity is currently resumed, its configuration
3153 // needs to change right now.
3154 callbacks.add(a);
3155 } else if (newConfig != null) {
3156 // Otherwise, we will tell it about the change
3157 // the next time it is resumed or shown. Note that
3158 // the activity manager may, before then, decide the
3159 // activity needs to be destroyed to handle its new
3160 // configuration.
Dianne Hackborn399cccb2010-04-13 22:57:49 -07003161 if (DEBUG_CONFIGURATION) Slog.v(TAG, "Setting activity "
Dianne Hackborndc6b6352009-09-30 14:20:09 -07003162 + ar.activityInfo.name + " newConfig=" + newConfig);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003163 ar.newConfig = newConfig;
3164 }
3165 }
3166 }
3167 }
3168 if (mServices.size() > 0) {
3169 Iterator<Service> it = mServices.values().iterator();
3170 while (it.hasNext()) {
3171 callbacks.add(it.next());
3172 }
3173 }
3174 synchronized (mProviderMap) {
3175 if (mLocalProviders.size() > 0) {
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07003176 Iterator<ProviderClientRecord> it = mLocalProviders.values().iterator();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003177 while (it.hasNext()) {
3178 callbacks.add(it.next().mLocalProvider);
3179 }
3180 }
3181 }
3182 final int N = mAllApplications.size();
3183 for (int i=0; i<N; i++) {
3184 callbacks.add(mAllApplications.get(i));
3185 }
Bob Leee5408332009-09-04 18:31:17 -07003186
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003187 return callbacks;
3188 }
Bob Leee5408332009-09-04 18:31:17 -07003189
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003190 private final void performConfigurationChanged(
3191 ComponentCallbacks cb, Configuration config) {
3192 // Only for Activity objects, check that they actually call up to their
3193 // superclass implementation. ComponentCallbacks is an interface, so
3194 // we check the runtime type and act accordingly.
3195 Activity activity = (cb instanceof Activity) ? (Activity) cb : null;
3196 if (activity != null) {
3197 activity.mCalled = false;
3198 }
Bob Leee5408332009-09-04 18:31:17 -07003199
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003200 boolean shouldChangeConfig = false;
3201 if ((activity == null) || (activity.mCurrentConfig == null)) {
3202 shouldChangeConfig = true;
3203 } else {
Bob Leee5408332009-09-04 18:31:17 -07003204
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003205 // If the new config is the same as the config this Activity
3206 // is already running with then don't bother calling
3207 // onConfigurationChanged
3208 int diff = activity.mCurrentConfig.diff(config);
3209 if (diff != 0) {
Bob Leee5408332009-09-04 18:31:17 -07003210
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003211 // If this activity doesn't handle any of the config changes
3212 // then don't bother calling onConfigurationChanged as we're
3213 // going to destroy it.
3214 if ((~activity.mActivityInfo.configChanges & diff) == 0) {
3215 shouldChangeConfig = true;
3216 }
3217 }
3218 }
Bob Leee5408332009-09-04 18:31:17 -07003219
Dianne Hackborn399cccb2010-04-13 22:57:49 -07003220 if (DEBUG_CONFIGURATION) Slog.v(TAG, "Config callback " + cb
Dianne Hackborndc6b6352009-09-30 14:20:09 -07003221 + ": shouldChangeConfig=" + shouldChangeConfig);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003222 if (shouldChangeConfig) {
3223 cb.onConfigurationChanged(config);
Bob Leee5408332009-09-04 18:31:17 -07003224
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003225 if (activity != null) {
3226 if (!activity.mCalled) {
3227 throw new SuperNotCalledException(
3228 "Activity " + activity.getLocalClassName() +
3229 " did not call through to super.onConfigurationChanged()");
3230 }
3231 activity.mConfigChangeFlags = 0;
3232 activity.mCurrentConfig = new Configuration(config);
3233 }
3234 }
3235 }
3236
Dianne Hackbornae078162010-03-18 11:29:37 -07003237 final boolean applyConfigurationToResourcesLocked(Configuration config) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003238 if (mResConfiguration == null) {
3239 mResConfiguration = new Configuration();
3240 }
3241 if (!mResConfiguration.isOtherSeqNewer(config)) {
Dianne Hackborn399cccb2010-04-13 22:57:49 -07003242 if (DEBUG_CONFIGURATION) Slog.v(TAG, "Skipping new config: curSeq="
Dianne Hackborn694f79b2010-03-17 19:44:59 -07003243 + mResConfiguration.seq + ", newSeq=" + config.seq);
Dianne Hackbornae078162010-03-18 11:29:37 -07003244 return false;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003245 }
Dianne Hackbornae078162010-03-18 11:29:37 -07003246 int changes = mResConfiguration.updateFrom(config);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003247 DisplayMetrics dm = getDisplayMetricsLocked(true);
Bob Leee5408332009-09-04 18:31:17 -07003248
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003249 // set it for java, this also affects newly created Resources
3250 if (config.locale != null) {
3251 Locale.setDefault(config.locale);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003252 }
Bob Leee5408332009-09-04 18:31:17 -07003253
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003254 Resources.updateSystemConfiguration(config, dm);
Bob Leee5408332009-09-04 18:31:17 -07003255
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08003256 ApplicationPackageManager.configurationChanged();
Dianne Hackborn399cccb2010-04-13 22:57:49 -07003257 //Slog.i(TAG, "Configuration changed in " + currentPackageName());
Dianne Hackborndc6b6352009-09-30 14:20:09 -07003258
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003259 Iterator<WeakReference<Resources>> it =
3260 mActiveResources.values().iterator();
3261 //Iterator<Map.Entry<String, WeakReference<Resources>>> it =
3262 // mActiveResources.entrySet().iterator();
3263 while (it.hasNext()) {
3264 WeakReference<Resources> v = it.next();
3265 Resources r = v.get();
3266 if (r != null) {
Dianne Hackborn399cccb2010-04-13 22:57:49 -07003267 if (DEBUG_CONFIGURATION) Slog.v(TAG, "Changing resources "
Dianne Hackborn694f79b2010-03-17 19:44:59 -07003268 + r + " config to: " + config);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003269 r.updateConfiguration(config, dm);
Dianne Hackborn399cccb2010-04-13 22:57:49 -07003270 //Slog.i(TAG, "Updated app resources " + v.getKey()
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003271 // + " " + r + ": " + r.getConfiguration());
3272 } else {
Dianne Hackborn399cccb2010-04-13 22:57:49 -07003273 //Slog.i(TAG, "Removing old resources " + v.getKey());
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003274 it.remove();
3275 }
3276 }
Dianne Hackbornae078162010-03-18 11:29:37 -07003277
3278 return changes != 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003279 }
3280
3281 final void handleConfigurationChanged(Configuration config) {
3282
3283 ArrayList<ComponentCallbacks> callbacks = null;
3284
3285 synchronized (mPackages) {
3286 if (mPendingConfiguration != null) {
3287 if (!mPendingConfiguration.isOtherSeqNewer(config)) {
3288 config = mPendingConfiguration;
3289 }
3290 mPendingConfiguration = null;
3291 }
3292
3293 if (config == null) {
3294 return;
3295 }
3296
Dianne Hackborn399cccb2010-04-13 22:57:49 -07003297 if (DEBUG_CONFIGURATION) Slog.v(TAG, "Handle configuration changed: "
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003298 + config);
3299
3300 applyConfigurationToResourcesLocked(config);
3301
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003302 if (mConfiguration == null) {
3303 mConfiguration = new Configuration();
3304 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003305 if (!mConfiguration.isOtherSeqNewer(config)) {
3306 return;
3307 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003308 mConfiguration.updateFrom(config);
Bob Leee5408332009-09-04 18:31:17 -07003309
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003310 callbacks = collectComponentCallbacksLocked(false, config);
3311 }
Bob Leee5408332009-09-04 18:31:17 -07003312
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003313 if (callbacks != null) {
3314 final int N = callbacks.size();
3315 for (int i=0; i<N; i++) {
3316 performConfigurationChanged(callbacks.get(i), config);
3317 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003318 }
3319 }
3320
3321 final void handleActivityConfigurationChanged(IBinder token) {
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07003322 ActivityClientRecord r = mActivities.get(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003323 if (r == null || r.activity == null) {
3324 return;
3325 }
Bob Leee5408332009-09-04 18:31:17 -07003326
Dianne Hackborn399cccb2010-04-13 22:57:49 -07003327 if (DEBUG_CONFIGURATION) Slog.v(TAG, "Handle activity config changed: "
Dianne Hackborndc6b6352009-09-30 14:20:09 -07003328 + r.activityInfo.name);
3329
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003330 performConfigurationChanged(r.activity, mConfiguration);
3331 }
3332
Dianne Hackborn9c8dd552009-06-23 19:22:52 -07003333 final void handleProfilerControl(boolean start, ProfilerControlData pcd) {
The Android Open Source Projectf5b4b982009-03-05 20:00:43 -08003334 if (start) {
The Android Open Source Projectf5b4b982009-03-05 20:00:43 -08003335 try {
Dianne Hackborn9c8dd552009-06-23 19:22:52 -07003336 Debug.startMethodTracing(pcd.path, pcd.fd.getFileDescriptor(),
3337 8 * 1024 * 1024, 0);
The Android Open Source Projectf5b4b982009-03-05 20:00:43 -08003338 } catch (RuntimeException e) {
Dianne Hackbornc9421ba2010-03-11 22:23:46 -08003339 Slog.w(TAG, "Profiling failed on path " + pcd.path
The Android Open Source Projectf5b4b982009-03-05 20:00:43 -08003340 + " -- can the process access this path?");
Dianne Hackborn9c8dd552009-06-23 19:22:52 -07003341 } finally {
3342 try {
3343 pcd.fd.close();
3344 } catch (IOException e) {
Dianne Hackbornc9421ba2010-03-11 22:23:46 -08003345 Slog.w(TAG, "Failure closing profile fd", e);
Dianne Hackborn9c8dd552009-06-23 19:22:52 -07003346 }
The Android Open Source Projectf5b4b982009-03-05 20:00:43 -08003347 }
3348 } else {
3349 Debug.stopMethodTracing();
3350 }
3351 }
Bob Leee5408332009-09-04 18:31:17 -07003352
Andy McFadden824c5102010-07-09 16:26:57 -07003353 final void handleDumpHeap(boolean managed, DumpHeapData dhd) {
3354 if (managed) {
3355 try {
3356 Debug.dumpHprofData(dhd.path, dhd.fd.getFileDescriptor());
3357 } catch (IOException e) {
3358 Slog.w(TAG, "Managed heap dump failed on path " + dhd.path
3359 + " -- can the process access this path?");
3360 } finally {
3361 try {
3362 dhd.fd.close();
3363 } catch (IOException e) {
3364 Slog.w(TAG, "Failure closing profile fd", e);
3365 }
3366 }
3367 } else {
Andy McFadden06a6b552010-07-13 16:28:09 -07003368 Debug.dumpNativeHeap(dhd.fd.getFileDescriptor());
Andy McFadden824c5102010-07-09 16:26:57 -07003369 }
3370 }
3371
Dianne Hackborn4416c3d2010-05-04 17:22:49 -07003372 final void handleDispatchPackageBroadcast(int cmd, String[] packages) {
3373 boolean hasPkgInfo = false;
3374 if (packages != null) {
3375 for (int i=packages.length-1; i>=0; i--) {
3376 //Slog.i(TAG, "Cleaning old package: " + packages[i]);
3377 if (!hasPkgInfo) {
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07003378 WeakReference<LoadedApk> ref;
Dianne Hackborn4416c3d2010-05-04 17:22:49 -07003379 ref = mPackages.get(packages[i]);
3380 if (ref != null && ref.get() != null) {
3381 hasPkgInfo = true;
3382 } else {
3383 ref = mResourcePackages.get(packages[i]);
3384 if (ref != null && ref.get() != null) {
3385 hasPkgInfo = true;
3386 }
3387 }
3388 }
3389 mPackages.remove(packages[i]);
3390 mResourcePackages.remove(packages[i]);
3391 }
3392 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08003393 ApplicationPackageManager.handlePackageBroadcast(cmd, packages,
Dianne Hackborn4416c3d2010-05-04 17:22:49 -07003394 hasPkgInfo);
3395 }
3396
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003397 final void handleLowMemory() {
3398 ArrayList<ComponentCallbacks> callbacks
3399 = new ArrayList<ComponentCallbacks>();
3400
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003401 synchronized (mPackages) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003402 callbacks = collectComponentCallbacksLocked(true, null);
3403 }
Bob Leee5408332009-09-04 18:31:17 -07003404
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003405 final int N = callbacks.size();
3406 for (int i=0; i<N; i++) {
3407 callbacks.get(i).onLowMemory();
3408 }
3409
Chris Tatece229052009-03-25 16:44:52 -07003410 // Ask SQLite to free up as much memory as it can, mostly from its page caches.
3411 if (Process.myUid() != Process.SYSTEM_UID) {
3412 int sqliteReleased = SQLiteDatabase.releaseMemory();
3413 EventLog.writeEvent(SQLITE_MEM_RELEASED_EVENT_LOG_TAG, sqliteReleased);
3414 }
Bob Leee5408332009-09-04 18:31:17 -07003415
Mike Reedcaf0df12009-04-27 14:32:05 -04003416 // Ask graphics to free up as much as possible (font/image caches)
3417 Canvas.freeCaches();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003418
3419 BinderInternal.forceGc("mem");
3420 }
3421
3422 private final void handleBindApplication(AppBindData data) {
3423 mBoundApplication = data;
3424 mConfiguration = new Configuration(data.config);
3425
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003426 // send up app name; do this *before* waiting for debugger
Christopher Tate8ee038d2009-11-06 11:30:20 -08003427 Process.setArgV0(data.processName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003428 android.ddm.DdmHandleAppName.setAppName(data.processName);
3429
3430 /*
3431 * Before spawning a new process, reset the time zone to be the system time zone.
3432 * This needs to be done because the system time zone could have changed after the
3433 * the spawning of this process. Without doing this this process would have the incorrect
3434 * system time zone.
3435 */
3436 TimeZone.setDefault(null);
3437
3438 /*
3439 * Initialize the default locale in this process for the reasons we set the time zone.
3440 */
3441 Locale.setDefault(data.config.locale);
3442
Suchi Amalapurapuc9843292009-06-24 17:02:25 -07003443 /*
3444 * Update the system configuration since its preloaded and might not
3445 * reflect configuration changes. The configuration object passed
3446 * in AppBindData can be safely assumed to be up to date
3447 */
3448 Resources.getSystem().updateConfiguration(mConfiguration, null);
3449
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003450 data.info = getPackageInfoNoCheck(data.appInfo);
3451
Dianne Hackborn96e240f2009-07-26 17:42:30 -07003452 /**
Brad Fitzpatrick438d0592010-06-10 12:19:19 -07003453 * For system applications on userdebug/eng builds, log stack
3454 * traces of disk and network access to dropbox for analysis.
3455 */
Brad Fitzpatrickad13b982010-07-14 12:35:53 -07003456 if ((data.appInfo.flags &
3457 (ApplicationInfo.FLAG_SYSTEM |
Brad Fitzpatrick50d66f92010-09-13 21:29:05 -07003458 ApplicationInfo.FLAG_UPDATED_SYSTEM_APP)) != 0) {
3459 StrictMode.conditionallyEnableDebugLogging();
Brad Fitzpatrick438d0592010-06-10 12:19:19 -07003460 }
3461
3462 /**
Brad Fitzpatrickb6e18412010-10-28 14:50:05 -07003463 * For apps targetting SDK Honeycomb or later, we don't allow
3464 * network usage on the main event loop / UI thread.
3465 *
3466 * Note to those grepping: this is what ultimately throws
3467 * NetworkOnMainThreadException ...
3468 */
3469 if (data.appInfo.targetSdkVersion > 9) {
3470 StrictMode.enableDeathOnNetwork();
3471 }
3472
3473 /**
Dianne Hackborn96e240f2009-07-26 17:42:30 -07003474 * Switch this process to density compatibility mode if needed.
3475 */
3476 if ((data.appInfo.flags&ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES)
3477 == 0) {
3478 Bitmap.setDefaultDensity(DisplayMetrics.DENSITY_DEFAULT);
3479 }
Bob Leee5408332009-09-04 18:31:17 -07003480
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003481 if (data.debugMode != IApplicationThread.DEBUG_OFF) {
3482 // XXX should have option to change the port.
3483 Debug.changeDebugPort(8100);
3484 if (data.debugMode == IApplicationThread.DEBUG_WAIT) {
Dianne Hackborn399cccb2010-04-13 22:57:49 -07003485 Slog.w(TAG, "Application " + data.info.getPackageName()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003486 + " is waiting for the debugger on port 8100...");
3487
3488 IActivityManager mgr = ActivityManagerNative.getDefault();
3489 try {
3490 mgr.showWaitingForDebugger(mAppThread, true);
3491 } catch (RemoteException ex) {
3492 }
3493
3494 Debug.waitForDebugger();
3495
3496 try {
3497 mgr.showWaitingForDebugger(mAppThread, false);
3498 } catch (RemoteException ex) {
3499 }
3500
3501 } else {
Dianne Hackborn399cccb2010-04-13 22:57:49 -07003502 Slog.w(TAG, "Application " + data.info.getPackageName()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003503 + " can be debugged on port 8100...");
3504 }
3505 }
3506
Robert Greenwalt434203a2010-10-11 16:00:27 -07003507 /**
3508 * Initialize the default http proxy in this process for the reasons we set the time zone.
3509 */
3510 IBinder b = ServiceManager.getService(Context.CONNECTIVITY_SERVICE);
3511 IConnectivityManager service = IConnectivityManager.Stub.asInterface(b);
3512 try {
3513 ProxyProperties proxyProperties = service.getProxy();
3514 Proxy.setHttpProxySystemProperty(proxyProperties);
3515 } catch (RemoteException e) {}
3516
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003517 if (data.instrumentationName != null) {
Dianne Hackborn21556372010-02-04 16:34:40 -08003518 ContextImpl appContext = new ContextImpl();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003519 appContext.init(data.info, null, this);
3520 InstrumentationInfo ii = null;
3521 try {
3522 ii = appContext.getPackageManager().
3523 getInstrumentationInfo(data.instrumentationName, 0);
3524 } catch (PackageManager.NameNotFoundException e) {
3525 }
3526 if (ii == null) {
3527 throw new RuntimeException(
3528 "Unable to find instrumentation info for: "
3529 + data.instrumentationName);
3530 }
3531
3532 mInstrumentationAppDir = ii.sourceDir;
3533 mInstrumentationAppPackage = ii.packageName;
3534 mInstrumentedAppDir = data.info.getAppDir();
3535
3536 ApplicationInfo instrApp = new ApplicationInfo();
3537 instrApp.packageName = ii.packageName;
3538 instrApp.sourceDir = ii.sourceDir;
3539 instrApp.publicSourceDir = ii.publicSourceDir;
3540 instrApp.dataDir = ii.dataDir;
Kenny Root85387d72010-08-26 10:13:11 -07003541 instrApp.nativeLibraryDir = ii.nativeLibraryDir;
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07003542 LoadedApk pi = getPackageInfo(instrApp,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003543 appContext.getClassLoader(), false, true);
Dianne Hackborn21556372010-02-04 16:34:40 -08003544 ContextImpl instrContext = new ContextImpl();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003545 instrContext.init(pi, null, this);
3546
3547 try {
3548 java.lang.ClassLoader cl = instrContext.getClassLoader();
3549 mInstrumentation = (Instrumentation)
3550 cl.loadClass(data.instrumentationName.getClassName()).newInstance();
3551 } catch (Exception e) {
3552 throw new RuntimeException(
3553 "Unable to instantiate instrumentation "
3554 + data.instrumentationName + ": " + e.toString(), e);
3555 }
3556
3557 mInstrumentation.init(this, instrContext, appContext,
3558 new ComponentName(ii.packageName, ii.name), data.instrumentationWatcher);
3559
3560 if (data.profileFile != null && !ii.handleProfiling) {
3561 data.handlingProfiling = true;
3562 File file = new File(data.profileFile);
3563 file.getParentFile().mkdirs();
3564 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
3565 }
3566
3567 try {
3568 mInstrumentation.onCreate(data.instrumentationArgs);
3569 }
3570 catch (Exception e) {
3571 throw new RuntimeException(
3572 "Exception thrown in onCreate() of "
3573 + data.instrumentationName + ": " + e.toString(), e);
3574 }
3575
3576 } else {
3577 mInstrumentation = new Instrumentation();
3578 }
3579
Dianne Hackborn3b81bc12011-01-15 11:50:52 -08003580 if ((data.appInfo.flags&ApplicationInfo.FLAG_LARGE_HEAP) != 0) {
Dianne Hackbornde398512011-01-18 18:45:21 -08003581 dalvik.system.VMRuntime.getRuntime().clearGrowthLimit();
Dianne Hackborn3b81bc12011-01-15 11:50:52 -08003582 }
3583
Christopher Tate181fafa2009-05-14 11:12:14 -07003584 // If the app is being launched for full backup or restore, bring it up in
3585 // a restricted environment with the base application class.
Dianne Hackborn0be1f782009-11-09 12:30:12 -08003586 Application app = data.info.makeApplication(data.restrictedBackupMode, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003587 mInitialApplication = app;
3588
3589 List<ProviderInfo> providers = data.providers;
3590 if (providers != null) {
3591 installContentProviders(app, providers);
Dianne Hackborn3b81bc12011-01-15 11:50:52 -08003592 // For process that contains content providers, we want to
Dianne Hackborn2a9094d2010-02-03 19:20:09 -08003593 // ensure that the JIT is enabled "at some point".
3594 mH.sendEmptyMessageDelayed(H.ENABLE_JIT, 10*1000);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003595 }
3596
3597 try {
3598 mInstrumentation.callApplicationOnCreate(app);
3599 } catch (Exception e) {
3600 if (!mInstrumentation.onException(app, e)) {
3601 throw new RuntimeException(
3602 "Unable to create application " + app.getClass().getName()
3603 + ": " + e.toString(), e);
3604 }
3605 }
3606 }
3607
3608 /*package*/ final void finishInstrumentation(int resultCode, Bundle results) {
3609 IActivityManager am = ActivityManagerNative.getDefault();
3610 if (mBoundApplication.profileFile != null && mBoundApplication.handlingProfiling) {
3611 Debug.stopMethodTracing();
3612 }
Dianne Hackborn399cccb2010-04-13 22:57:49 -07003613 //Slog.i(TAG, "am: " + ActivityManagerNative.getDefault()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003614 // + ", app thr: " + mAppThread);
3615 try {
3616 am.finishInstrumentation(mAppThread, resultCode, results);
3617 } catch (RemoteException ex) {
3618 }
3619 }
3620
3621 private final void installContentProviders(
3622 Context context, List<ProviderInfo> providers) {
3623 final ArrayList<IActivityManager.ContentProviderHolder> results =
3624 new ArrayList<IActivityManager.ContentProviderHolder>();
3625
3626 Iterator<ProviderInfo> i = providers.iterator();
3627 while (i.hasNext()) {
3628 ProviderInfo cpi = i.next();
3629 StringBuilder buf = new StringBuilder(128);
Dianne Hackborncef65ee2010-09-30 18:27:22 -07003630 buf.append("Pub ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003631 buf.append(cpi.authority);
3632 buf.append(": ");
3633 buf.append(cpi.name);
3634 Log.i(TAG, buf.toString());
3635 IContentProvider cp = installProvider(context, null, cpi, false);
3636 if (cp != null) {
3637 IActivityManager.ContentProviderHolder cph =
3638 new IActivityManager.ContentProviderHolder(cpi);
3639 cph.provider = cp;
3640 results.add(cph);
3641 // Don't ever unload this provider from the process.
3642 synchronized(mProviderMap) {
3643 mProviderRefCountMap.put(cp.asBinder(), new ProviderRefCount(10000));
3644 }
3645 }
3646 }
3647
3648 try {
3649 ActivityManagerNative.getDefault().publishContentProviders(
3650 getApplicationThread(), results);
3651 } catch (RemoteException ex) {
3652 }
3653 }
3654
Dianne Hackborncca1f0e2010-09-26 18:34:53 -07003655 private final IContentProvider getExistingProvider(Context context, String name) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003656 synchronized(mProviderMap) {
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07003657 final ProviderClientRecord pr = mProviderMap.get(name);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003658 if (pr != null) {
3659 return pr.mProvider;
3660 }
Dianne Hackborncca1f0e2010-09-26 18:34:53 -07003661 return null;
3662 }
3663 }
3664
3665 private final IContentProvider getProvider(Context context, String name) {
3666 IContentProvider existing = getExistingProvider(context, name);
3667 if (existing != null) {
3668 return existing;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003669 }
3670
3671 IActivityManager.ContentProviderHolder holder = null;
3672 try {
3673 holder = ActivityManagerNative.getDefault().getContentProvider(
3674 getApplicationThread(), name);
3675 } catch (RemoteException ex) {
3676 }
3677 if (holder == null) {
Dianne Hackbornc9421ba2010-03-11 22:23:46 -08003678 Slog.e(TAG, "Failed to find provider info for " + name);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003679 return null;
3680 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003681
3682 IContentProvider prov = installProvider(context, holder.provider,
3683 holder.info, true);
Dianne Hackborn399cccb2010-04-13 22:57:49 -07003684 //Slog.i(TAG, "noReleaseNeeded=" + holder.noReleaseNeeded);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003685 if (holder.noReleaseNeeded || holder.provider == null) {
3686 // We are not going to release the provider if it is an external
3687 // provider that doesn't care about being released, or if it is
3688 // a local provider running in this process.
Dianne Hackborn399cccb2010-04-13 22:57:49 -07003689 //Slog.i(TAG, "*** NO RELEASE NEEDED");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003690 synchronized(mProviderMap) {
3691 mProviderRefCountMap.put(prov.asBinder(), new ProviderRefCount(10000));
3692 }
3693 }
3694 return prov;
3695 }
3696
3697 public final IContentProvider acquireProvider(Context c, String name) {
3698 IContentProvider provider = getProvider(c, name);
3699 if(provider == null)
3700 return null;
3701 IBinder jBinder = provider.asBinder();
3702 synchronized(mProviderMap) {
3703 ProviderRefCount prc = mProviderRefCountMap.get(jBinder);
3704 if(prc == null) {
3705 mProviderRefCountMap.put(jBinder, new ProviderRefCount(1));
3706 } else {
3707 prc.count++;
3708 } //end else
3709 } //end synchronized
3710 return provider;
3711 }
3712
Dianne Hackborncca1f0e2010-09-26 18:34:53 -07003713 public final IContentProvider acquireExistingProvider(Context c, String name) {
3714 IContentProvider provider = getExistingProvider(c, name);
3715 if(provider == null)
3716 return null;
3717 IBinder jBinder = provider.asBinder();
3718 synchronized(mProviderMap) {
3719 ProviderRefCount prc = mProviderRefCountMap.get(jBinder);
3720 if(prc == null) {
3721 mProviderRefCountMap.put(jBinder, new ProviderRefCount(1));
3722 } else {
3723 prc.count++;
3724 } //end else
3725 } //end synchronized
3726 return provider;
3727 }
3728
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003729 public final boolean releaseProvider(IContentProvider provider) {
3730 if(provider == null) {
3731 return false;
3732 }
3733 IBinder jBinder = provider.asBinder();
3734 synchronized(mProviderMap) {
3735 ProviderRefCount prc = mProviderRefCountMap.get(jBinder);
3736 if(prc == null) {
Dianne Hackborncca1f0e2010-09-26 18:34:53 -07003737 if(localLOGV) Slog.v(TAG, "releaseProvider::Weird shouldn't be here");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003738 return false;
3739 } else {
3740 prc.count--;
3741 if(prc.count == 0) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003742 // Schedule the actual remove asynchronously, since we
3743 // don't know the context this will be called in.
Dianne Hackborn0c3154d2009-10-06 17:18:05 -07003744 // TODO: it would be nice to post a delayed message, so
3745 // if we come back and need the same provider quickly
3746 // we will still have it available.
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003747 Message msg = mH.obtainMessage(H.REMOVE_PROVIDER, provider);
3748 mH.sendMessage(msg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003749 } //end if
3750 } //end else
3751 } //end synchronized
3752 return true;
3753 }
3754
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003755 final void completeRemoveProvider(IContentProvider provider) {
3756 IBinder jBinder = provider.asBinder();
Dianne Hackborn0c3154d2009-10-06 17:18:05 -07003757 String name = null;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003758 synchronized(mProviderMap) {
3759 ProviderRefCount prc = mProviderRefCountMap.get(jBinder);
3760 if(prc != null && prc.count == 0) {
3761 mProviderRefCountMap.remove(jBinder);
3762 //invoke removeProvider to dereference provider
Dianne Hackborn0c3154d2009-10-06 17:18:05 -07003763 name = removeProviderLocked(provider);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003764 }
3765 }
Dianne Hackborn0c3154d2009-10-06 17:18:05 -07003766
3767 if (name != null) {
3768 try {
Dianne Hackborn399cccb2010-04-13 22:57:49 -07003769 if(localLOGV) Slog.v(TAG, "removeProvider::Invoking " +
Dianne Hackborn0c3154d2009-10-06 17:18:05 -07003770 "ActivityManagerNative.removeContentProvider(" + name);
3771 ActivityManagerNative.getDefault().removeContentProvider(
3772 getApplicationThread(), name);
3773 } catch (RemoteException e) {
3774 //do nothing content provider object is dead any way
3775 } //end catch
3776 }
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003777 }
3778
Dianne Hackborn0c3154d2009-10-06 17:18:05 -07003779 public final String removeProviderLocked(IContentProvider provider) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003780 if (provider == null) {
Dianne Hackborn0c3154d2009-10-06 17:18:05 -07003781 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003782 }
3783 IBinder providerBinder = provider.asBinder();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003784
Dianne Hackborn0c3154d2009-10-06 17:18:05 -07003785 String name = null;
3786
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003787 // remove the provider from mProviderMap
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07003788 Iterator<ProviderClientRecord> iter = mProviderMap.values().iterator();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003789 while (iter.hasNext()) {
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07003790 ProviderClientRecord pr = iter.next();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003791 IBinder myBinder = pr.mProvider.asBinder();
3792 if (myBinder == providerBinder) {
3793 //find if its published by this process itself
3794 if(pr.mLocalProvider != null) {
Dianne Hackborn399cccb2010-04-13 22:57:49 -07003795 if(localLOGV) Slog.i(TAG, "removeProvider::found local provider returning");
Dianne Hackborn0c3154d2009-10-06 17:18:05 -07003796 return name;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003797 }
Dianne Hackborn399cccb2010-04-13 22:57:49 -07003798 if(localLOGV) Slog.v(TAG, "removeProvider::Not local provider Unlinking " +
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003799 "death recipient");
3800 //content provider is in another process
3801 myBinder.unlinkToDeath(pr, 0);
3802 iter.remove();
3803 //invoke remove only once for the very first name seen
Dianne Hackborn0c3154d2009-10-06 17:18:05 -07003804 if(name == null) {
3805 name = pr.mName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003806 }
3807 } //end if myBinder
3808 } //end while iter
Dianne Hackborn0c3154d2009-10-06 17:18:05 -07003809
3810 return name;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003811 }
3812
3813 final void removeDeadProvider(String name, IContentProvider provider) {
3814 synchronized(mProviderMap) {
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07003815 ProviderClientRecord pr = mProviderMap.get(name);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003816 if (pr.mProvider.asBinder() == provider.asBinder()) {
Dianne Hackborn399cccb2010-04-13 22:57:49 -07003817 Slog.i(TAG, "Removing dead content provider: " + name);
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07003818 ProviderClientRecord removed = mProviderMap.remove(name);
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07003819 if (removed != null) {
3820 removed.mProvider.asBinder().unlinkToDeath(removed, 0);
3821 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003822 }
3823 }
3824 }
3825
3826 final void removeDeadProviderLocked(String name, IContentProvider provider) {
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07003827 ProviderClientRecord pr = mProviderMap.get(name);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003828 if (pr.mProvider.asBinder() == provider.asBinder()) {
Dianne Hackborn399cccb2010-04-13 22:57:49 -07003829 Slog.i(TAG, "Removing dead content provider: " + name);
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07003830 ProviderClientRecord removed = mProviderMap.remove(name);
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07003831 if (removed != null) {
3832 removed.mProvider.asBinder().unlinkToDeath(removed, 0);
3833 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003834 }
3835 }
3836
3837 private final IContentProvider installProvider(Context context,
3838 IContentProvider provider, ProviderInfo info, boolean noisy) {
3839 ContentProvider localProvider = null;
3840 if (provider == null) {
3841 if (noisy) {
Dianne Hackborn399cccb2010-04-13 22:57:49 -07003842 Slog.d(TAG, "Loading provider " + info.authority + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003843 + info.name);
3844 }
3845 Context c = null;
3846 ApplicationInfo ai = info.applicationInfo;
3847 if (context.getPackageName().equals(ai.packageName)) {
3848 c = context;
3849 } else if (mInitialApplication != null &&
3850 mInitialApplication.getPackageName().equals(ai.packageName)) {
3851 c = mInitialApplication;
3852 } else {
3853 try {
3854 c = context.createPackageContext(ai.packageName,
3855 Context.CONTEXT_INCLUDE_CODE);
3856 } catch (PackageManager.NameNotFoundException e) {
3857 }
3858 }
3859 if (c == null) {
Dianne Hackbornc9421ba2010-03-11 22:23:46 -08003860 Slog.w(TAG, "Unable to get context for package " +
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003861 ai.packageName +
3862 " while loading content provider " +
3863 info.name);
3864 return null;
3865 }
3866 try {
3867 final java.lang.ClassLoader cl = c.getClassLoader();
3868 localProvider = (ContentProvider)cl.
3869 loadClass(info.name).newInstance();
3870 provider = localProvider.getIContentProvider();
3871 if (provider == null) {
Dianne Hackbornc9421ba2010-03-11 22:23:46 -08003872 Slog.e(TAG, "Failed to instantiate class " +
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003873 info.name + " from sourceDir " +
3874 info.applicationInfo.sourceDir);
3875 return null;
3876 }
Dianne Hackborn399cccb2010-04-13 22:57:49 -07003877 if (Config.LOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003878 TAG, "Instantiating local provider " + info.name);
3879 // XXX Need to create the correct context for this provider.
3880 localProvider.attachInfo(c, info);
3881 } catch (java.lang.Exception e) {
3882 if (!mInstrumentation.onException(null, e)) {
3883 throw new RuntimeException(
3884 "Unable to get provider " + info.name
3885 + ": " + e.toString(), e);
3886 }
3887 return null;
3888 }
3889 } else if (localLOGV) {
Dianne Hackborn399cccb2010-04-13 22:57:49 -07003890 Slog.v(TAG, "Installing external provider " + info.authority + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003891 + info.name);
3892 }
3893
3894 synchronized (mProviderMap) {
3895 // Cache the pointer for the remote provider.
3896 String names[] = PATTERN_SEMICOLON.split(info.authority);
3897 for (int i=0; i<names.length; i++) {
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07003898 ProviderClientRecord pr = new ProviderClientRecord(names[i], provider,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003899 localProvider);
3900 try {
3901 provider.asBinder().linkToDeath(pr, 0);
3902 mProviderMap.put(names[i], pr);
3903 } catch (RemoteException e) {
3904 return null;
3905 }
3906 }
3907 if (localProvider != null) {
3908 mLocalProviders.put(provider.asBinder(),
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07003909 new ProviderClientRecord(null, provider, localProvider));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003910 }
3911 }
3912
3913 return provider;
3914 }
3915
3916 private final void attach(boolean system) {
3917 sThreadLocal.set(this);
3918 mSystemThread = system;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003919 if (!system) {
Dianne Hackborn2a9094d2010-02-03 19:20:09 -08003920 ViewRoot.addFirstDrawHandler(new Runnable() {
3921 public void run() {
3922 ensureJitEnabled();
3923 }
3924 });
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003925 android.ddm.DdmHandleAppName.setAppName("<pre-initialized>");
3926 RuntimeInit.setApplicationObject(mAppThread.asBinder());
3927 IActivityManager mgr = ActivityManagerNative.getDefault();
3928 try {
3929 mgr.attachApplication(mAppThread);
3930 } catch (RemoteException ex) {
3931 }
3932 } else {
3933 // Don't set application object here -- if the system crashes,
3934 // we can't display an alert, we just want to die die die.
3935 android.ddm.DdmHandleAppName.setAppName("system_process");
3936 try {
3937 mInstrumentation = new Instrumentation();
Dianne Hackborn21556372010-02-04 16:34:40 -08003938 ContextImpl context = new ContextImpl();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003939 context.init(getSystemContext().mPackageInfo, null, this);
3940 Application app = Instrumentation.newApplication(Application.class, context);
3941 mAllApplications.add(app);
3942 mInitialApplication = app;
3943 app.onCreate();
3944 } catch (Exception e) {
3945 throw new RuntimeException(
3946 "Unable to instantiate Application():" + e.toString(), e);
3947 }
3948 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003949
3950 ViewRoot.addConfigCallback(new ComponentCallbacks() {
3951 public void onConfigurationChanged(Configuration newConfig) {
3952 synchronized (mPackages) {
Dianne Hackbornae078162010-03-18 11:29:37 -07003953 // We need to apply this change to the resources
3954 // immediately, because upon returning the view
3955 // hierarchy will be informed about it.
3956 if (applyConfigurationToResourcesLocked(newConfig)) {
3957 // This actually changed the resources! Tell
3958 // everyone about it.
3959 if (mPendingConfiguration == null ||
3960 mPendingConfiguration.isOtherSeqNewer(newConfig)) {
3961 mPendingConfiguration = newConfig;
3962
3963 queueOrSendMessage(H.CONFIGURATION_CHANGED, newConfig);
3964 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003965 }
3966 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003967 }
3968 public void onLowMemory() {
3969 }
3970 });
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003971 }
3972
3973 private final void detach()
3974 {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003975 sThreadLocal.set(null);
3976 }
3977
3978 public static final ActivityThread systemMain() {
Romain Guy52339202010-09-03 16:04:46 -07003979 HardwareRenderer.disable();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003980 ActivityThread thread = new ActivityThread();
3981 thread.attach(true);
3982 return thread;
3983 }
3984
3985 public final void installSystemProviders(List providers) {
3986 if (providers != null) {
3987 installContentProviders(mInitialApplication,
3988 (List<ProviderInfo>)providers);
3989 }
3990 }
3991
Svetoslav Ganov54d068e2011-03-02 12:58:40 -08003992 public int getIntCoreSetting(String key, int defaultValue) {
3993 if (mBoundApplication == null) {
3994 return defaultValue;
3995 }
3996 synchronized (mBoundApplication) {
3997 Bundle coreSettings = mBoundApplication.coreSettings;
3998 if (coreSettings != null) {
3999 return coreSettings.getInt(key, defaultValue);
4000 } else {
4001 return defaultValue;
4002 }
4003 }
4004 }
4005
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004006 public static final void main(String[] args) {
Bob Leee5408332009-09-04 18:31:17 -07004007 SamplingProfilerIntegration.start();
4008
Brad Fitzpatrick4d9e6d22010-11-15 08:49:51 -08004009 // CloseGuard defaults to true and can be quite spammy. We
4010 // disable it here, but selectively enable it later (via
4011 // StrictMode) on debug builds, but using DropBox, not logs.
4012 CloseGuard.setEnabled(false);
4013
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004014 Process.setArgV0("<pre-initialized>");
4015
4016 Looper.prepareMainLooper();
Brad Fitzpatrick333b8cb2010-08-26 12:04:57 -07004017 if (sMainThreadHandler == null) {
4018 sMainThreadHandler = new Handler();
4019 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004020
4021 ActivityThread thread = new ActivityThread();
4022 thread.attach(false);
4023
Dianne Hackborn287952c2010-09-22 22:34:31 -07004024 if (false) {
4025 Looper.myLooper().setMessageLogging(new
4026 LogPrinter(Log.DEBUG, "ActivityThread"));
4027 }
4028
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004029 Looper.loop();
4030
4031 if (Process.supportsProcesses()) {
4032 throw new RuntimeException("Main thread loop unexpectedly exited");
4033 }
4034
4035 thread.detach();
Bob Leeeec2f412009-09-10 11:01:24 +02004036 String name = (thread.mInitialApplication != null)
4037 ? thread.mInitialApplication.getPackageName()
4038 : "<unknown>";
Dianne Hackborn399cccb2010-04-13 22:57:49 -07004039 Slog.i(TAG, "Main thread of " + name + " is now exiting");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004040 }
4041}