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