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