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