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