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