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