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