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 | |
Dianne Hackborn | 69c6adc | 2015-06-02 10:52:59 -0700 | [diff] [blame] | 19 | import android.app.assist.AssistContent; |
| 20 | import android.app.assist.AssistStructure; |
Christopher Tate | 4528186 | 2010-03-05 15:46:30 -0800 | [diff] [blame] | 21 | import android.app.backup.BackupAgent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 22 | import android.content.BroadcastReceiver; |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 23 | import android.content.ComponentCallbacks2; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | import android.content.ComponentName; |
| 25 | import android.content.ContentProvider; |
| 26 | import android.content.Context; |
| 27 | import android.content.IContentProvider; |
| 28 | import android.content.Intent; |
Suchi Amalapurapu | 1ccac75 | 2009-06-12 10:09:58 -0700 | [diff] [blame] | 29 | import android.content.IIntentReceiver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | import android.content.pm.ActivityInfo; |
| 31 | import android.content.pm.ApplicationInfo; |
| 32 | import android.content.pm.IPackageManager; |
| 33 | import android.content.pm.InstrumentationInfo; |
Christopher Tate | 346acb1 | 2012-10-15 19:20:25 -0700 | [diff] [blame] | 34 | import android.content.pm.PackageInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | import android.content.pm.PackageManager; |
Sen Hu | bde7570 | 2010-05-28 01:54:03 -0700 | [diff] [blame] | 36 | import android.content.pm.PackageManager.NameNotFoundException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | import android.content.pm.ProviderInfo; |
| 38 | import android.content.pm.ServiceInfo; |
| 39 | import android.content.res.AssetManager; |
Mitsuru Oshima | ba3ba57 | 2009-07-08 18:49:26 -0700 | [diff] [blame] | 40 | import android.content.res.CompatibilityInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | import android.content.res.Configuration; |
| 42 | import android.content.res.Resources; |
Alan Viverette | e54d245 | 2015-05-06 10:41:43 -0700 | [diff] [blame] | 43 | import android.content.res.Resources.Theme; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | import android.database.sqlite.SQLiteDatabase; |
| 45 | import android.database.sqlite.SQLiteDebug; |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 46 | import android.database.sqlite.SQLiteDebug.DbStats; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | import android.graphics.Bitmap; |
| 48 | import android.graphics.Canvas; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 49 | import android.hardware.display.DisplayManagerGlobal; |
Paul Jensen | e0bef71 | 2014-12-10 15:12:18 -0500 | [diff] [blame] | 50 | import android.net.ConnectivityManager; |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 51 | import android.net.IConnectivityManager; |
Paul Jensen | e0bef71 | 2014-12-10 15:12:18 -0500 | [diff] [blame] | 52 | import android.net.Network; |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 53 | import android.net.Proxy; |
Jason Monk | 207900c | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 54 | import android.net.ProxyInfo; |
Jason Monk | 83520b9 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 55 | import android.net.Uri; |
Romain Guy | a958265 | 2011-11-10 14:20:10 -0800 | [diff] [blame] | 56 | import android.opengl.GLUtils; |
Joe Onorato | d630f10 | 2011-03-17 18:42:26 -0700 | [diff] [blame] | 57 | import android.os.AsyncTask; |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 58 | import android.os.Binder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 59 | import android.os.Bundle; |
| 60 | import android.os.Debug; |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 61 | import android.os.DropBoxManager; |
Jeff Sharkey | b049e21 | 2012-09-07 23:16:01 -0700 | [diff] [blame] | 62 | import android.os.Environment; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 63 | import android.os.Handler; |
| 64 | import android.os.IBinder; |
| 65 | import android.os.Looper; |
| 66 | import android.os.Message; |
| 67 | import android.os.MessageQueue; |
Dianne Hackborn | fabb70b | 2014-11-11 12:22:36 -0800 | [diff] [blame] | 68 | import android.os.Parcel; |
Dianne Hackborn | 9c8dd55 | 2009-06-23 19:22:52 -0700 | [diff] [blame] | 69 | import android.os.ParcelFileDescriptor; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 70 | import android.os.PersistableBundle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 71 | import android.os.Process; |
| 72 | import android.os.RemoteException; |
| 73 | import android.os.ServiceManager; |
Brad Fitzpatrick | 438d059 | 2010-06-10 12:19:19 -0700 | [diff] [blame] | 74 | import android.os.StrictMode; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 75 | import android.os.SystemClock; |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 76 | import android.os.SystemProperties; |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 77 | import android.os.Trace; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 78 | import android.os.UserHandle; |
Narayan Kamath | ccb2a086 | 2013-12-19 14:49:36 +0000 | [diff] [blame] | 79 | import android.provider.Settings; |
Alex Klyubin | f9034cc | 2015-02-12 11:43:09 -0800 | [diff] [blame] | 80 | import android.security.NetworkSecurityPolicy; |
Chad Brubaker | 78d4712 | 2015-11-17 22:26:58 -0800 | [diff] [blame] | 81 | import android.security.net.config.NetworkSecurityConfigProvider; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 82 | import android.util.AndroidRuntimeException; |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 83 | import android.util.ArrayMap; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 84 | import android.util.DisplayMetrics; |
| 85 | import android.util.EventLog; |
| 86 | import android.util.Log; |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 87 | import android.util.LogPrinter; |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 88 | import android.util.Pair; |
Jeff Brown | 6754ba2 | 2011-12-14 20:20:01 -0800 | [diff] [blame] | 89 | import android.util.PrintWriterPrinter; |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 90 | import android.util.Slog; |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 91 | import android.util.SparseIntArray; |
Adam Powell | 1487466 | 2013-07-18 19:42:41 -0700 | [diff] [blame] | 92 | import android.util.SuperNotCalledException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 93 | import android.view.Display; |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 94 | import android.view.ThreadedRenderer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 95 | import android.view.View; |
| 96 | import android.view.ViewDebug; |
| 97 | import android.view.ViewManager; |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 98 | import android.view.ViewRootImpl; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 99 | import android.view.Window; |
| 100 | import android.view.WindowManager; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 101 | import android.view.WindowManagerGlobal; |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 102 | import android.renderscript.RenderScriptCacheDir; |
Alex Klyubin | dcdaf87 | 2015-05-13 15:57:09 -0700 | [diff] [blame] | 103 | import android.security.keystore.AndroidKeyStoreProvider; |
Calin Juravle | 6905239 | 2015-12-17 17:06:49 +0200 | [diff] [blame] | 104 | import android.system.Os; |
| 105 | import android.system.OsConstants; |
| 106 | import android.system.ErrnoException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 107 | |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 108 | import com.android.internal.annotations.GuardedBy; |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 109 | import com.android.internal.app.IVoiceInteractor; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 110 | import com.android.internal.content.ReferrerIntent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 111 | import com.android.internal.os.BinderInternal; |
| 112 | import com.android.internal.os.RuntimeInit; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 113 | import com.android.internal.os.SamplingProfilerIntegration; |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 114 | import com.android.internal.os.SomeArgs; |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 115 | import com.android.internal.util.FastPrintWriter; |
Kenny Root | 12e7522 | 2013-04-23 22:34:24 -0700 | [diff] [blame] | 116 | import com.android.org.conscrypt.OpenSSLSocketImpl; |
Robin Lee | 3d076af | 2014-04-25 14:57:49 +0100 | [diff] [blame] | 117 | import com.android.org.conscrypt.TrustedCertificateStore; |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 118 | import com.google.android.collect.Lists; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 119 | |
| 120 | import java.io.File; |
| 121 | import java.io.FileDescriptor; |
| 122 | import java.io.FileOutputStream; |
Dianne Hackborn | 9c8dd55 | 2009-06-23 19:22:52 -0700 | [diff] [blame] | 123 | import java.io.IOException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 124 | import java.io.PrintWriter; |
| 125 | import java.lang.ref.WeakReference; |
Robert Greenwalt | 03595d0 | 2010-11-02 14:08:23 -0700 | [diff] [blame] | 126 | import java.net.InetAddress; |
Narayan Kamath | ccb2a086 | 2013-12-19 14:49:36 +0000 | [diff] [blame] | 127 | import java.text.DateFormat; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 128 | import java.util.ArrayList; |
Calin Juravle | f19c963 | 2015-12-10 17:32:15 +0000 | [diff] [blame] | 129 | import java.util.Collections; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 130 | import java.util.List; |
| 131 | import java.util.Locale; |
| 132 | import java.util.Map; |
Kenny Root | e6585b3 | 2013-12-13 12:00:26 -0800 | [diff] [blame] | 133 | import java.util.Objects; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 134 | import java.util.TimeZone; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 135 | |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 136 | import libcore.io.DropBox; |
Geremy Condra | 69689a7 | 2012-09-11 16:57:17 -0700 | [diff] [blame] | 137 | import libcore.io.EventLogger; |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 138 | import libcore.io.IoUtils; |
Paul Jensen | e401d17 | 2014-09-12 10:47:39 -0400 | [diff] [blame] | 139 | import libcore.net.event.NetworkEventDispatcher; |
Brad Fitzpatrick | 4d9e6d2 | 2010-11-15 08:49:51 -0800 | [diff] [blame] | 140 | import dalvik.system.CloseGuard; |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 141 | import dalvik.system.VMDebug; |
Mathieu Chartier | 1e37090 | 2013-07-18 10:58:01 -0700 | [diff] [blame] | 142 | import dalvik.system.VMRuntime; |
Man Cao | cfa78b2 | 2015-06-11 20:14:34 -0700 | [diff] [blame] | 143 | import org.apache.harmony.dalvik.ddmc.DdmVmInternal; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 144 | |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 145 | final class RemoteServiceException extends AndroidRuntimeException { |
| 146 | public RemoteServiceException(String msg) { |
| 147 | super(msg); |
| 148 | } |
| 149 | } |
| 150 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 151 | /** |
| 152 | * This manages the execution of the main thread in an |
| 153 | * application process, scheduling and executing activities, |
| 154 | * broadcasts, and other operations on it as the activity |
| 155 | * manager requests. |
| 156 | * |
| 157 | * {@hide} |
| 158 | */ |
| 159 | public final class ActivityThread { |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 160 | /** @hide */ |
| 161 | public static final String TAG = "ActivityThread"; |
Jim Miller | 0b2a6d0 | 2010-07-13 18:01:29 -0700 | [diff] [blame] | 162 | 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] | 163 | static final boolean localLOGV = false; |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 164 | static final boolean DEBUG_MESSAGES = false; |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 165 | /** @hide */ |
| 166 | public static final boolean DEBUG_BROADCAST = false; |
Chris Tate | 8a7dc17 | 2009-03-24 20:11:42 -0700 | [diff] [blame] | 167 | private static final boolean DEBUG_RESULTS = false; |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 168 | private static final boolean DEBUG_BACKUP = false; |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 169 | public static final boolean DEBUG_CONFIGURATION = false; |
Dianne Hackborn | a0c283e | 2012-02-09 10:47:01 -0800 | [diff] [blame] | 170 | private static final boolean DEBUG_SERVICE = false; |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 171 | private static final boolean DEBUG_MEMORY_TRIM = false; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 172 | private static final boolean DEBUG_PROVIDER = false; |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 173 | private static final boolean DEBUG_ORDER = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 174 | private static final long MIN_TIME_BETWEEN_GCS = 5*1000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 175 | private static final int SQLITE_MEM_RELEASED_EVENT_LOG_TAG = 75003; |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 176 | private static final int LOG_AM_ON_PAUSE_CALLED = 30021; |
| 177 | private static final int LOG_AM_ON_RESUME_CALLED = 30022; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 178 | |
Dianne Hackborn | 455625e | 2015-01-21 09:55:13 -0800 | [diff] [blame] | 179 | /** Type for IActivityManager.serviceDoneExecuting: anonymous operation */ |
| 180 | public static final int SERVICE_DONE_EXECUTING_ANON = 0; |
| 181 | /** Type for IActivityManager.serviceDoneExecuting: done with an onStart call */ |
| 182 | public static final int SERVICE_DONE_EXECUTING_START = 1; |
| 183 | /** Type for IActivityManager.serviceDoneExecuting: done stopping (destroying) service */ |
| 184 | public static final int SERVICE_DONE_EXECUTING_STOP = 2; |
| 185 | |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 186 | // Details for pausing activity. |
| 187 | private static final int USER_LEAVING = 1; |
| 188 | private static final int DONT_REPORT = 2; |
| 189 | |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 190 | // Whether to invoke an activity callback after delivering new configuration. |
| 191 | private static final boolean REPORT_TO_ACTIVITY = true; |
| 192 | |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 193 | private ContextImpl mSystemContext; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 194 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 195 | static IPackageManager sPackageManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 196 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 197 | final ApplicationThread mAppThread = new ApplicationThread(); |
| 198 | final Looper mLooper = Looper.myLooper(); |
| 199 | final H mH = new H(); |
Dianne Hackborn | 782d498 | 2015-07-08 17:36:37 -0700 | [diff] [blame] | 200 | final ArrayMap<IBinder, ActivityClientRecord> mActivities = new ArrayMap<>(); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 201 | // List of new activities (via ActivityRecord.nextIdle) that should |
| 202 | // be reported when next we idle. |
| 203 | ActivityClientRecord mNewActivities = null; |
| 204 | // Number of activities that are currently visible on-screen. |
| 205 | int mNumVisibleActivities = 0; |
Dianne Hackborn | 782d498 | 2015-07-08 17:36:37 -0700 | [diff] [blame] | 206 | WeakReference<AssistStructure> mLastAssistStructure; |
| 207 | final ArrayMap<IBinder, Service> mServices = new ArrayMap<>(); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 208 | AppBindData mBoundApplication; |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 209 | Profiler mProfiler; |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 210 | int mCurDefaultDisplayDpi; |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 211 | boolean mDensityCompatMode; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 212 | Configuration mConfiguration; |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 213 | Configuration mCompatConfiguration; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 214 | Application mInitialApplication; |
| 215 | final ArrayList<Application> mAllApplications |
| 216 | = new ArrayList<Application>(); |
| 217 | // set of instantiated backup agents, keyed by package name |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 218 | final ArrayMap<String, BackupAgent> mBackupAgents = new ArrayMap<String, BackupAgent>(); |
Jeff Sharkey | 66a017b | 2013-01-17 18:18:22 -0800 | [diff] [blame] | 219 | /** Reference to singleton {@link ActivityThread} */ |
| 220 | private static ActivityThread sCurrentActivityThread; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 221 | Instrumentation mInstrumentation; |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 222 | String mInstrumentationPackageName = null; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 223 | String mInstrumentationAppDir = null; |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 224 | String[] mInstrumentationSplitAppDirs = null; |
| 225 | String mInstrumentationLibDir = null; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 226 | String mInstrumentedAppDir = null; |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 227 | String[] mInstrumentedSplitAppDirs = null; |
| 228 | String mInstrumentedLibDir = null; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 229 | boolean mSystemThread = false; |
| 230 | boolean mJitEnabled = false; |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 231 | boolean mSomeActivitiesChanged = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 232 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 233 | // These can be accessed by multiple threads; mPackages is the lock. |
| 234 | // XXX For now we keep around information about all packages we have |
| 235 | // seen, not removing entries from this map. |
Dianne Hackborn | 1fbee79 | 2011-11-30 11:29:58 -0800 | [diff] [blame] | 236 | // NOTE: The activity and window managers need to call in to |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 237 | // ActivityThread to do things like update resource configurations, |
Dianne Hackborn | 1fbee79 | 2011-11-30 11:29:58 -0800 | [diff] [blame] | 238 | // which means this lock gets held while the activity and window managers |
| 239 | // holds their own lock. Thus you MUST NEVER call back into the activity manager |
| 240 | // or window manager or anything that depends on them while holding this lock. |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 241 | // These LoadedApk are only valid for the userId that we're running as. |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 242 | final ArrayMap<String, WeakReference<LoadedApk>> mPackages |
| 243 | = new ArrayMap<String, WeakReference<LoadedApk>>(); |
| 244 | final ArrayMap<String, WeakReference<LoadedApk>> mResourcePackages |
| 245 | = new ArrayMap<String, WeakReference<LoadedApk>>(); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 246 | final ArrayList<ActivityClientRecord> mRelaunchingActivities |
| 247 | = new ArrayList<ActivityClientRecord>(); |
| 248 | Configuration mPendingConfiguration = null; |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 249 | // Because we merge activity relaunch operations we can't depend on the ordering provided by |
| 250 | // the handler messages. We need to introduce secondary ordering mechanism, which will allow |
| 251 | // us to drop certain events, if we know that they happened before relaunch we already executed. |
| 252 | // This represents the order of receiving the request from AM. |
| 253 | @GuardedBy("mResourcesManager") |
| 254 | int mLifecycleSeq = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 255 | |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 256 | private final ResourcesManager mResourcesManager; |
| 257 | |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 258 | private static final class ProviderKey { |
| 259 | final String authority; |
| 260 | final int userId; |
| 261 | |
| 262 | public ProviderKey(String authority, int userId) { |
| 263 | this.authority = authority; |
| 264 | this.userId = userId; |
| 265 | } |
| 266 | |
| 267 | @Override |
| 268 | public boolean equals(Object o) { |
| 269 | if (o instanceof ProviderKey) { |
| 270 | final ProviderKey other = (ProviderKey) o; |
Kenny Root | e6585b3 | 2013-12-13 12:00:26 -0800 | [diff] [blame] | 271 | return Objects.equals(authority, other.authority) && userId == other.userId; |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 272 | } |
| 273 | return false; |
| 274 | } |
| 275 | |
| 276 | @Override |
| 277 | public int hashCode() { |
| 278 | return ((authority != null) ? authority.hashCode() : 0) ^ userId; |
| 279 | } |
| 280 | } |
| 281 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 282 | // The lock of mProviderMap protects the following variables. |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 283 | final ArrayMap<ProviderKey, ProviderClientRecord> mProviderMap |
| 284 | = new ArrayMap<ProviderKey, ProviderClientRecord>(); |
| 285 | final ArrayMap<IBinder, ProviderRefCount> mProviderRefCountMap |
| 286 | = new ArrayMap<IBinder, ProviderRefCount>(); |
| 287 | final ArrayMap<IBinder, ProviderClientRecord> mLocalProviders |
| 288 | = new ArrayMap<IBinder, ProviderClientRecord>(); |
| 289 | final ArrayMap<ComponentName, ProviderClientRecord> mLocalProvidersByName |
| 290 | = new ArrayMap<ComponentName, ProviderClientRecord>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 291 | |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 292 | final ArrayMap<Activity, ArrayList<OnActivityPausedListener>> mOnPauseListeners |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 293 | = new ArrayMap<Activity, ArrayList<OnActivityPausedListener>>(); |
Jeff Hamilton | 52d3203 | 2011-01-08 15:31:26 -0600 | [diff] [blame] | 294 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 295 | final GcIdler mGcIdler = new GcIdler(); |
| 296 | boolean mGcIdlerScheduled = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 297 | |
Brad Fitzpatrick | 333b8cb | 2010-08-26 12:04:57 -0700 | [diff] [blame] | 298 | static Handler sMainThreadHandler; // set once in main() |
| 299 | |
Svetoslav Ganov | 9aa597e | 2011-03-03 18:17:41 -0800 | [diff] [blame] | 300 | Bundle mCoreSettings = null; |
| 301 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 302 | static final class ActivityClientRecord { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 303 | IBinder token; |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 304 | int ident; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 305 | Intent intent; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 306 | String referrer; |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 307 | IVoiceInteractor voiceInteractor; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 308 | Bundle state; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 309 | PersistableBundle persistentState; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 310 | Activity activity; |
| 311 | Window window; |
| 312 | Activity parent; |
| 313 | String embeddedID; |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 314 | Activity.NonConfigurationInstances lastNonConfigurationInstances; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 315 | boolean paused; |
| 316 | boolean stopped; |
| 317 | boolean hideForNow; |
| 318 | Configuration newConfig; |
Dianne Hackborn | e88846e | 2009-09-30 21:34:25 -0700 | [diff] [blame] | 319 | Configuration createdConfig; |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 320 | Configuration overrideConfig; |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 321 | // Used for consolidating configs before sending on to Activity. |
| 322 | private Configuration tmpConfig = new Configuration(); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 323 | ActivityClientRecord nextIdle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 324 | |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 325 | ProfilerInfo profilerInfo; |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 326 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 327 | ActivityInfo activityInfo; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 328 | CompatibilityInfo compatInfo; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 329 | LoadedApk packageInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 330 | |
| 331 | List<ResultInfo> pendingResults; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 332 | List<ReferrerIntent> pendingIntents; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 333 | |
| 334 | boolean startsNotResumed; |
| 335 | boolean isForward; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 336 | int pendingConfigChanges; |
| 337 | boolean onlyLocalRequest; |
| 338 | |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 339 | Window mPendingRemoveWindow; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 340 | WindowManager mPendingRemoveWindowManager; |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 341 | boolean mPreserveWindow; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 342 | |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 343 | // Set for relaunch requests, indicates the order number of the relaunch operation, so it |
| 344 | // can be compared with other lifecycle operations. |
| 345 | int relaunchSeq = 0; |
| 346 | |
| 347 | // Can only be accessed from the UI thread. This represents the latest processed message |
| 348 | // that is related to lifecycle events/ |
| 349 | int lastProcessedSeq = 0; |
| 350 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 351 | ActivityClientRecord() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 352 | parent = null; |
| 353 | embeddedID = null; |
| 354 | paused = false; |
| 355 | stopped = false; |
| 356 | hideForNow = false; |
| 357 | nextIdle = null; |
| 358 | } |
| 359 | |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 360 | public boolean isPreHoneycomb() { |
| 361 | if (activity != null) { |
| 362 | return activity.getApplicationInfo().targetSdkVersion |
| 363 | < android.os.Build.VERSION_CODES.HONEYCOMB; |
| 364 | } |
| 365 | return false; |
| 366 | } |
| 367 | |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 368 | public boolean isPersistable() { |
Craig Mautner | 43e52ed | 2014-06-16 17:18:52 -0700 | [diff] [blame] | 369 | return activityInfo.persistableMode == ActivityInfo.PERSIST_ACROSS_REBOOTS; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 370 | } |
| 371 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 372 | public String toString() { |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 373 | ComponentName componentName = intent != null ? intent.getComponent() : null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 374 | return "ActivityRecord{" |
| 375 | + Integer.toHexString(System.identityHashCode(this)) |
| 376 | + " token=" + token + " " + (componentName == null |
| 377 | ? "no component name" : componentName.toShortString()) |
| 378 | + "}"; |
| 379 | } |
| 380 | } |
| 381 | |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 382 | final class ProviderClientRecord { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 383 | final String[] mNames; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 384 | final IContentProvider mProvider; |
| 385 | final ContentProvider mLocalProvider; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 386 | final IActivityManager.ContentProviderHolder mHolder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 387 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 388 | ProviderClientRecord(String[] names, IContentProvider provider, |
| 389 | ContentProvider localProvider, |
| 390 | IActivityManager.ContentProviderHolder holder) { |
| 391 | mNames = names; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 392 | mProvider = provider; |
| 393 | mLocalProvider = localProvider; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 394 | mHolder = holder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 395 | } |
| 396 | } |
| 397 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 398 | static final class NewIntentData { |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 399 | List<ReferrerIntent> intents; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 400 | IBinder token; |
| 401 | public String toString() { |
| 402 | return "NewIntentData{intents=" + intents + " token=" + token + "}"; |
| 403 | } |
| 404 | } |
| 405 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 406 | static final class ReceiverData extends BroadcastReceiver.PendingResult { |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 407 | public ReceiverData(Intent intent, int resultCode, String resultData, Bundle resultExtras, |
Dianne Hackborn | 20e8098 | 2012-08-31 19:00:44 -0700 | [diff] [blame] | 408 | boolean ordered, boolean sticky, IBinder token, int sendingUser) { |
| 409 | super(resultCode, resultData, resultExtras, TYPE_COMPONENT, ordered, sticky, |
riddle_hsu | 1f5ac4d | 2015-01-03 15:38:21 +0800 | [diff] [blame] | 410 | token, sendingUser, intent.getFlags()); |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 411 | this.intent = intent; |
| 412 | } |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 413 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 414 | Intent intent; |
| 415 | ActivityInfo info; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 416 | CompatibilityInfo compatInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 417 | public String toString() { |
| 418 | return "ReceiverData{intent=" + intent + " packageName=" + |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 419 | info.packageName + " resultCode=" + getResultCode() |
| 420 | + " resultData=" + getResultData() + " resultExtras=" |
| 421 | + getResultExtras(false) + "}"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 422 | } |
| 423 | } |
| 424 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 425 | static final class CreateBackupAgentData { |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 426 | ApplicationInfo appInfo; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 427 | CompatibilityInfo compatInfo; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 428 | int backupMode; |
| 429 | public String toString() { |
| 430 | return "CreateBackupAgentData{appInfo=" + appInfo |
| 431 | + " backupAgent=" + appInfo.backupAgentName |
| 432 | + " mode=" + backupMode + "}"; |
| 433 | } |
| 434 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 435 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 436 | static final class CreateServiceData { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 437 | IBinder token; |
| 438 | ServiceInfo info; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 439 | CompatibilityInfo compatInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 440 | Intent intent; |
| 441 | public String toString() { |
| 442 | return "CreateServiceData{token=" + token + " className=" |
| 443 | + info.name + " packageName=" + info.packageName |
| 444 | + " intent=" + intent + "}"; |
| 445 | } |
| 446 | } |
| 447 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 448 | static final class BindServiceData { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 449 | IBinder token; |
| 450 | Intent intent; |
| 451 | boolean rebind; |
| 452 | public String toString() { |
| 453 | return "BindServiceData{token=" + token + " intent=" + intent + "}"; |
| 454 | } |
| 455 | } |
| 456 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 457 | static final class ServiceArgsData { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 458 | IBinder token; |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 459 | boolean taskRemoved; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 460 | int startId; |
Dianne Hackborn | f6f9f2d | 2009-08-21 16:26:03 -0700 | [diff] [blame] | 461 | int flags; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 462 | Intent args; |
| 463 | public String toString() { |
| 464 | return "ServiceArgsData{token=" + token + " startId=" + startId |
| 465 | + " args=" + args + "}"; |
| 466 | } |
| 467 | } |
| 468 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 469 | static final class AppBindData { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 470 | LoadedApk info; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 471 | String processName; |
| 472 | ApplicationInfo appInfo; |
| 473 | List<ProviderInfo> providers; |
| 474 | ComponentName instrumentationName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 475 | Bundle instrumentationArgs; |
| 476 | IInstrumentationWatcher instrumentationWatcher; |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 477 | IUiAutomationConnection instrumentationUiAutomationConnection; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 478 | int debugMode; |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 479 | boolean enableBinderTracking; |
Man Cao | cfa78b2 | 2015-06-11 20:14:34 -0700 | [diff] [blame] | 480 | boolean trackAllocation; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 481 | boolean restrictedBackupMode; |
Dianne Hackborn | 5d927c2 | 2011-09-02 12:22:18 -0700 | [diff] [blame] | 482 | boolean persistent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 483 | Configuration config; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 484 | CompatibilityInfo compatInfo; |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 485 | |
| 486 | /** Initial values for {@link Profiler}. */ |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 487 | ProfilerInfo initProfilerInfo; |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 488 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 489 | public String toString() { |
| 490 | return "AppBindData{appInfo=" + appInfo + "}"; |
| 491 | } |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | static final class Profiler { |
| 495 | String profileFile; |
| 496 | ParcelFileDescriptor profileFd; |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 497 | int samplingInterval; |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 498 | boolean autoStopProfiler; |
| 499 | boolean profiling; |
| 500 | boolean handlingProfiling; |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 501 | public void setProfiler(ProfilerInfo profilerInfo) { |
| 502 | ParcelFileDescriptor fd = profilerInfo.profileFd; |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 503 | if (profiling) { |
| 504 | if (fd != null) { |
| 505 | try { |
| 506 | fd.close(); |
| 507 | } catch (IOException e) { |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 508 | // Ignore |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 509 | } |
| 510 | } |
| 511 | return; |
| 512 | } |
| 513 | if (profileFd != null) { |
| 514 | try { |
| 515 | profileFd.close(); |
| 516 | } catch (IOException e) { |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 517 | // Ignore |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 518 | } |
| 519 | } |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 520 | profileFile = profilerInfo.profileFile; |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 521 | profileFd = fd; |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 522 | samplingInterval = profilerInfo.samplingInterval; |
| 523 | autoStopProfiler = profilerInfo.autoStopProfiler; |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 524 | } |
| 525 | public void startProfiling() { |
| 526 | if (profileFd == null || profiling) { |
| 527 | return; |
| 528 | } |
| 529 | try { |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 530 | VMDebug.startMethodTracing(profileFile, profileFd.getFileDescriptor(), |
| 531 | 8 * 1024 * 1024, 0, samplingInterval != 0, samplingInterval); |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 532 | profiling = true; |
| 533 | } catch (RuntimeException e) { |
| 534 | Slog.w(TAG, "Profiling failed on path " + profileFile); |
| 535 | try { |
| 536 | profileFd.close(); |
| 537 | profileFd = null; |
| 538 | } catch (IOException e2) { |
| 539 | Slog.w(TAG, "Failure closing profile fd", e2); |
| 540 | } |
| 541 | } |
| 542 | } |
| 543 | public void stopProfiling() { |
| 544 | if (profiling) { |
| 545 | profiling = false; |
| 546 | Debug.stopMethodTracing(); |
| 547 | if (profileFd != null) { |
| 548 | try { |
| 549 | profileFd.close(); |
| 550 | } catch (IOException e) { |
| 551 | } |
| 552 | } |
| 553 | profileFd = null; |
| 554 | profileFile = null; |
| 555 | } |
| 556 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 557 | } |
| 558 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 559 | static final class DumpComponentInfo { |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 560 | ParcelFileDescriptor fd; |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 561 | IBinder token; |
Dianne Hackborn | 30d7189 | 2010-12-11 10:37:55 -0800 | [diff] [blame] | 562 | String prefix; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 563 | String[] args; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 564 | } |
| 565 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 566 | static final class ResultData { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 567 | IBinder token; |
| 568 | List<ResultInfo> results; |
| 569 | public String toString() { |
| 570 | return "ResultData{token=" + token + " results" + results + "}"; |
| 571 | } |
| 572 | } |
| 573 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 574 | static final class ContextCleanupInfo { |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 575 | ContextImpl context; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 576 | String what; |
| 577 | String who; |
| 578 | } |
| 579 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 580 | static final class DumpHeapData { |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 581 | String path; |
| 582 | ParcelFileDescriptor fd; |
| 583 | } |
| 584 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 585 | static final class UpdateCompatibilityData { |
| 586 | String pkg; |
| 587 | CompatibilityInfo info; |
| 588 | } |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 589 | |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 590 | static final class RequestAssistContextExtras { |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 591 | IBinder activityToken; |
| 592 | IBinder requestToken; |
| 593 | int requestType; |
| 594 | } |
Anwar Ghuloum | 3a8ce1b | 2013-04-26 16:18:28 -0700 | [diff] [blame] | 595 | |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 596 | static final class ActivityConfigChangeData { |
| 597 | final IBinder activityToken; |
| 598 | final Configuration overrideConfig; |
| 599 | public ActivityConfigChangeData(IBinder token, Configuration config) { |
| 600 | activityToken = token; |
| 601 | overrideConfig = config; |
| 602 | } |
| 603 | } |
| 604 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 605 | private native void dumpGraphicsInfo(FileDescriptor fd); |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 606 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 607 | private class ApplicationThread extends ApplicationThreadNative { |
Vasu Nori | 3c7131f | 2010-09-21 14:36:57 -0700 | [diff] [blame] | 608 | private static final String DB_INFO_FORMAT = " %8s %8s %14s %14s %s"; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 609 | |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 610 | private int mLastProcessState = -1; |
| 611 | |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 612 | private void updatePendingConfiguration(Configuration config) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 613 | synchronized (mResourcesManager) { |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 614 | if (mPendingConfiguration == null || |
| 615 | mPendingConfiguration.isOtherSeqNewer(config)) { |
| 616 | mPendingConfiguration = config; |
| 617 | } |
| 618 | } |
| 619 | } |
| 620 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 621 | public final void schedulePauseActivity(IBinder token, boolean finished, |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 622 | boolean userLeaving, int configChanges, boolean dontReport) { |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 623 | int seq = getLifecycleSeq(); |
| 624 | if (DEBUG_ORDER) Slog.d(TAG, "pauseActivity " + ActivityThread.this |
| 625 | + " operation received seq: " + seq); |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 626 | sendMessage( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 627 | finished ? H.PAUSE_ACTIVITY_FINISHING : H.PAUSE_ACTIVITY, |
| 628 | token, |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 629 | (userLeaving ? USER_LEAVING : 0) | (dontReport ? DONT_REPORT : 0), |
| 630 | configChanges, |
| 631 | seq); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | public final void scheduleStopActivity(IBinder token, boolean showWindow, |
| 635 | int configChanges) { |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 636 | int seq = getLifecycleSeq(); |
| 637 | if (DEBUG_ORDER) Slog.d(TAG, "stopActivity " + ActivityThread.this |
| 638 | + " operation received seq: " + seq); |
| 639 | sendMessage( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 640 | showWindow ? H.STOP_ACTIVITY_SHOW : H.STOP_ACTIVITY_HIDE, |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 641 | token, 0, configChanges, seq); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 642 | } |
| 643 | |
| 644 | public final void scheduleWindowVisibility(IBinder token, boolean showWindow) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 645 | sendMessage( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 646 | showWindow ? H.SHOW_WINDOW : H.HIDE_WINDOW, |
| 647 | token); |
| 648 | } |
| 649 | |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 650 | public final void scheduleSleeping(IBinder token, boolean sleeping) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 651 | sendMessage(H.SLEEPING, token, sleeping ? 1 : 0); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 652 | } |
| 653 | |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 654 | public final void scheduleResumeActivity(IBinder token, int processState, |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 655 | boolean isForward, Bundle resumeArgs) { |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 656 | int seq = getLifecycleSeq(); |
| 657 | if (DEBUG_ORDER) Slog.d(TAG, "resumeActivity " + ActivityThread.this |
| 658 | + " operation received seq: " + seq); |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 659 | updateProcessState(processState, false); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 660 | sendMessage(H.RESUME_ACTIVITY, token, isForward ? 1 : 0, 0, seq); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | public final void scheduleSendResult(IBinder token, List<ResultInfo> results) { |
| 664 | ResultData res = new ResultData(); |
| 665 | res.token = token; |
| 666 | res.results = results; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 667 | sendMessage(H.SEND_RESULT, res); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | // we use token to identify this activity without having to send the |
| 671 | // activity itself back to the activity manager. (matters more with ipc) |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 672 | @Override |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 673 | public final void scheduleLaunchActivity(Intent intent, IBinder token, int ident, |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 674 | ActivityInfo info, Configuration curConfig, Configuration overrideConfig, |
| 675 | CompatibilityInfo compatInfo, String referrer, IVoiceInteractor voiceInteractor, |
| 676 | int procState, Bundle state, PersistableBundle persistentState, |
| 677 | List<ResultInfo> pendingResults, List<ReferrerIntent> pendingNewIntents, |
| 678 | boolean notResumed, boolean isForward, ProfilerInfo profilerInfo) { |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 679 | |
| 680 | updateProcessState(procState, false); |
| 681 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 682 | ActivityClientRecord r = new ActivityClientRecord(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 683 | |
| 684 | r.token = token; |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 685 | r.ident = ident; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 686 | r.intent = intent; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 687 | r.referrer = referrer; |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 688 | r.voiceInteractor = voiceInteractor; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 689 | r.activityInfo = info; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 690 | r.compatInfo = compatInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 691 | r.state = state; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 692 | r.persistentState = persistentState; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 693 | |
| 694 | r.pendingResults = pendingResults; |
| 695 | r.pendingIntents = pendingNewIntents; |
| 696 | |
| 697 | r.startsNotResumed = notResumed; |
| 698 | r.isForward = isForward; |
| 699 | |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 700 | r.profilerInfo = profilerInfo; |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 701 | |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 702 | r.overrideConfig = overrideConfig; |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 703 | updatePendingConfiguration(curConfig); |
| 704 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 705 | sendMessage(H.LAUNCH_ACTIVITY, r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 706 | } |
| 707 | |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 708 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 709 | public final void scheduleRelaunchActivity(IBinder token, |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 710 | List<ResultInfo> pendingResults, List<ReferrerIntent> pendingNewIntents, |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 711 | int configChanges, boolean notResumed, Configuration config, |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 712 | Configuration overrideConfig, boolean preserveWindow) { |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 713 | requestRelaunchActivity(token, pendingResults, pendingNewIntents, |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 714 | configChanges, notResumed, config, overrideConfig, true, preserveWindow); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 715 | } |
| 716 | |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 717 | public final void scheduleNewIntent(List<ReferrerIntent> intents, IBinder token) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 718 | NewIntentData data = new NewIntentData(); |
| 719 | data.intents = intents; |
| 720 | data.token = token; |
| 721 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 722 | sendMessage(H.NEW_INTENT, data); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 723 | } |
| 724 | |
| 725 | public final void scheduleDestroyActivity(IBinder token, boolean finishing, |
| 726 | int configChanges) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 727 | sendMessage(H.DESTROY_ACTIVITY, token, finishing ? 1 : 0, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 728 | configChanges); |
| 729 | } |
| 730 | |
| 731 | public final void scheduleReceiver(Intent intent, ActivityInfo info, |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 732 | CompatibilityInfo compatInfo, int resultCode, String data, Bundle extras, |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 733 | boolean sync, int sendingUser, int processState) { |
| 734 | updateProcessState(processState, false); |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 735 | ReceiverData r = new ReceiverData(intent, resultCode, data, extras, |
Dianne Hackborn | 20e8098 | 2012-08-31 19:00:44 -0700 | [diff] [blame] | 736 | sync, false, mAppThread.asBinder(), sendingUser); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 737 | r.info = info; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 738 | r.compatInfo = compatInfo; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 739 | sendMessage(H.RECEIVER, r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 740 | } |
| 741 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 742 | public final void scheduleCreateBackupAgent(ApplicationInfo app, |
| 743 | CompatibilityInfo compatInfo, int backupMode) { |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 744 | CreateBackupAgentData d = new CreateBackupAgentData(); |
| 745 | d.appInfo = app; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 746 | d.compatInfo = compatInfo; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 747 | d.backupMode = backupMode; |
| 748 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 749 | sendMessage(H.CREATE_BACKUP_AGENT, d); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 750 | } |
| 751 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 752 | public final void scheduleDestroyBackupAgent(ApplicationInfo app, |
| 753 | CompatibilityInfo compatInfo) { |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 754 | CreateBackupAgentData d = new CreateBackupAgentData(); |
| 755 | d.appInfo = app; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 756 | d.compatInfo = compatInfo; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 757 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 758 | sendMessage(H.DESTROY_BACKUP_AGENT, d); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 759 | } |
| 760 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 761 | public final void scheduleCreateService(IBinder token, |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 762 | ServiceInfo info, CompatibilityInfo compatInfo, int processState) { |
| 763 | updateProcessState(processState, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 764 | CreateServiceData s = new CreateServiceData(); |
| 765 | s.token = token; |
| 766 | s.info = info; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 767 | s.compatInfo = compatInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 768 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 769 | sendMessage(H.CREATE_SERVICE, s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 770 | } |
| 771 | |
| 772 | public final void scheduleBindService(IBinder token, Intent intent, |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 773 | boolean rebind, int processState) { |
| 774 | updateProcessState(processState, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 775 | BindServiceData s = new BindServiceData(); |
| 776 | s.token = token; |
| 777 | s.intent = intent; |
| 778 | s.rebind = rebind; |
| 779 | |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 780 | if (DEBUG_SERVICE) |
| 781 | Slog.v(TAG, "scheduleBindService token=" + token + " intent=" + intent + " uid=" |
| 782 | + Binder.getCallingUid() + " pid=" + Binder.getCallingPid()); |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 783 | sendMessage(H.BIND_SERVICE, s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 784 | } |
| 785 | |
| 786 | public final void scheduleUnbindService(IBinder token, Intent intent) { |
| 787 | BindServiceData s = new BindServiceData(); |
| 788 | s.token = token; |
| 789 | s.intent = intent; |
| 790 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 791 | sendMessage(H.UNBIND_SERVICE, s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 792 | } |
| 793 | |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 794 | public final void scheduleServiceArgs(IBinder token, boolean taskRemoved, int startId, |
Dianne Hackborn | f6f9f2d | 2009-08-21 16:26:03 -0700 | [diff] [blame] | 795 | int flags ,Intent args) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 796 | ServiceArgsData s = new ServiceArgsData(); |
| 797 | s.token = token; |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 798 | s.taskRemoved = taskRemoved; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 799 | s.startId = startId; |
Dianne Hackborn | f6f9f2d | 2009-08-21 16:26:03 -0700 | [diff] [blame] | 800 | s.flags = flags; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 801 | s.args = args; |
| 802 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 803 | sendMessage(H.SERVICE_ARGS, s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 804 | } |
| 805 | |
| 806 | public final void scheduleStopService(IBinder token) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 807 | sendMessage(H.STOP_SERVICE, token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 808 | } |
| 809 | |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 810 | public final void bindApplication(String processName, ApplicationInfo appInfo, |
| 811 | List<ProviderInfo> providers, ComponentName instrumentationName, |
| 812 | ProfilerInfo profilerInfo, Bundle instrumentationArgs, |
| 813 | IInstrumentationWatcher instrumentationWatcher, |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 814 | IUiAutomationConnection instrumentationUiConnection, int debugMode, |
Pablo Ceballos | a4d4e82 | 2015-10-05 10:27:52 -0700 | [diff] [blame] | 815 | boolean enableBinderTracking, boolean trackAllocation, |
| 816 | boolean isRestrictedBackupMode, boolean persistent, Configuration config, |
| 817 | CompatibilityInfo compatInfo, Map<String, IBinder> services, Bundle coreSettings) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 818 | |
| 819 | if (services != null) { |
| 820 | // Setup the service cache in the ServiceManager |
| 821 | ServiceManager.initServiceCache(services); |
| 822 | } |
| 823 | |
Svetoslav Ganov | 9aa597e | 2011-03-03 18:17:41 -0800 | [diff] [blame] | 824 | setCoreSettings(coreSettings); |
| 825 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 826 | AppBindData data = new AppBindData(); |
| 827 | data.processName = processName; |
| 828 | data.appInfo = appInfo; |
| 829 | data.providers = providers; |
| 830 | data.instrumentationName = instrumentationName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 831 | data.instrumentationArgs = instrumentationArgs; |
| 832 | data.instrumentationWatcher = instrumentationWatcher; |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 833 | data.instrumentationUiAutomationConnection = instrumentationUiConnection; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 834 | data.debugMode = debugMode; |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 835 | data.enableBinderTracking = enableBinderTracking; |
Man Cao | cfa78b2 | 2015-06-11 20:14:34 -0700 | [diff] [blame] | 836 | data.trackAllocation = trackAllocation; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 837 | data.restrictedBackupMode = isRestrictedBackupMode; |
Dianne Hackborn | 5d927c2 | 2011-09-02 12:22:18 -0700 | [diff] [blame] | 838 | data.persistent = persistent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 839 | data.config = config; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 840 | data.compatInfo = compatInfo; |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 841 | data.initProfilerInfo = profilerInfo; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 842 | sendMessage(H.BIND_APPLICATION, data); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 843 | } |
| 844 | |
| 845 | public final void scheduleExit() { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 846 | sendMessage(H.EXIT_APPLICATION, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 847 | } |
| 848 | |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 849 | public final void scheduleSuicide() { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 850 | sendMessage(H.SUICIDE, null); |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 851 | } |
| 852 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 853 | public void scheduleConfigurationChanged(Configuration config) { |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 854 | updatePendingConfiguration(config); |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 855 | sendMessage(H.CONFIGURATION_CHANGED, config); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 856 | } |
| 857 | |
| 858 | public void updateTimeZone() { |
| 859 | TimeZone.setDefault(null); |
| 860 | } |
| 861 | |
Robert Greenwalt | 03595d0 | 2010-11-02 14:08:23 -0700 | [diff] [blame] | 862 | public void clearDnsCache() { |
| 863 | // a non-standard API to get this to libcore |
| 864 | InetAddress.clearDnsCache(); |
Paul Jensen | e401d17 | 2014-09-12 10:47:39 -0400 | [diff] [blame] | 865 | // Allow libcore to perform the necessary actions as it sees fit upon a network |
| 866 | // configuration change. |
| 867 | NetworkEventDispatcher.getInstance().onNetworkConfigurationChanged(); |
Robert Greenwalt | 03595d0 | 2010-11-02 14:08:23 -0700 | [diff] [blame] | 868 | } |
| 869 | |
Jason Monk | 83520b9 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 870 | public void setHttpProxy(String host, String port, String exclList, Uri pacFileUrl) { |
Paul Jensen | 72db88e | 2015-03-10 10:54:12 -0400 | [diff] [blame] | 871 | final ConnectivityManager cm = ConnectivityManager.from(getSystemContext()); |
| 872 | final Network network = cm.getBoundNetworkForProcess(); |
Paul Jensen | e0bef71 | 2014-12-10 15:12:18 -0500 | [diff] [blame] | 873 | if (network != null) { |
Paul Jensen | 72db88e | 2015-03-10 10:54:12 -0400 | [diff] [blame] | 874 | Proxy.setHttpProxySystemProperty(cm.getDefaultProxy()); |
Paul Jensen | e0bef71 | 2014-12-10 15:12:18 -0500 | [diff] [blame] | 875 | } else { |
| 876 | Proxy.setHttpProxySystemProperty(host, port, exclList, pacFileUrl); |
| 877 | } |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 878 | } |
| 879 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 880 | public void processInBackground() { |
| 881 | mH.removeMessages(H.GC_WHEN_IDLE); |
| 882 | mH.sendMessage(mH.obtainMessage(H.GC_WHEN_IDLE)); |
| 883 | } |
| 884 | |
| 885 | public void dumpService(FileDescriptor fd, IBinder servicetoken, String[] args) { |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 886 | DumpComponentInfo data = new DumpComponentInfo(); |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 887 | try { |
| 888 | data.fd = ParcelFileDescriptor.dup(fd); |
| 889 | data.token = servicetoken; |
| 890 | data.args = args; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 891 | sendMessage(H.DUMP_SERVICE, data, 0, 0, true /*async*/); |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 892 | } catch (IOException e) { |
| 893 | Slog.w(TAG, "dumpService failed", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 894 | } |
| 895 | } |
| 896 | |
| 897 | // This function exists to make sure all receiver dispatching is |
| 898 | // correctly ordered, since these are one-way calls and the binder driver |
| 899 | // applies transaction ordering per object for such calls. |
| 900 | public void scheduleRegisteredReceiver(IIntentReceiver receiver, Intent intent, |
Dianne Hackborn | 68d881c | 2009-10-05 13:58:17 -0700 | [diff] [blame] | 901 | int resultCode, String dataStr, Bundle extras, boolean ordered, |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 902 | boolean sticky, int sendingUser, int processState) throws RemoteException { |
| 903 | updateProcessState(processState, false); |
Dianne Hackborn | 20e8098 | 2012-08-31 19:00:44 -0700 | [diff] [blame] | 904 | receiver.performReceive(intent, resultCode, dataStr, extras, ordered, |
| 905 | sticky, sendingUser); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 906 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 907 | |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 908 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 909 | public void scheduleLowMemory() { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 910 | sendMessage(H.LOW_MEMORY, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 911 | } |
| 912 | |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 913 | @Override |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 914 | public void scheduleActivityConfigurationChanged( |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 915 | IBinder token, Configuration overrideConfig, boolean reportToActivity) { |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 916 | sendMessage(H.ACTIVITY_CONFIGURATION_CHANGED, |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 917 | new ActivityConfigChangeData(token, overrideConfig), reportToActivity ? 1 : 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 918 | } |
| 919 | |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 920 | @Override |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 921 | public void profilerControl(boolean start, ProfilerInfo profilerInfo, int profileType) { |
| 922 | sendMessage(H.PROFILER_CONTROL, profilerInfo, start ? 1 : 0, profileType); |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 923 | } |
| 924 | |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 925 | public void dumpHeap(boolean managed, String path, ParcelFileDescriptor fd) { |
| 926 | DumpHeapData dhd = new DumpHeapData(); |
| 927 | dhd.path = path; |
| 928 | dhd.fd = fd; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 929 | sendMessage(H.DUMP_HEAP, dhd, managed ? 1 : 0, 0, true /*async*/); |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 930 | } |
| 931 | |
Dianne Hackborn | 06de2ea | 2009-05-21 12:56:43 -0700 | [diff] [blame] | 932 | public void setSchedulingGroup(int group) { |
| 933 | // Note: do this immediately, since going into the foreground |
| 934 | // should happen regardless of what pending work we have to do |
| 935 | // and the activity manager will wait for us to report back that |
| 936 | // we are done before sending us to the background. |
| 937 | try { |
| 938 | Process.setProcessGroup(Process.myPid(), group); |
| 939 | } catch (Exception e) { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 940 | Slog.w(TAG, "Failed setting process group to " + group, e); |
Dianne Hackborn | 06de2ea | 2009-05-21 12:56:43 -0700 | [diff] [blame] | 941 | } |
| 942 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 943 | |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 944 | public void dispatchPackageBroadcast(int cmd, String[] packages) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 945 | sendMessage(H.DISPATCH_PACKAGE_BROADCAST, packages, cmd); |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 946 | } |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 947 | |
| 948 | public void scheduleCrash(String msg) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 949 | sendMessage(H.SCHEDULE_CRASH, msg); |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 950 | } |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 951 | |
Dianne Hackborn | 30d7189 | 2010-12-11 10:37:55 -0800 | [diff] [blame] | 952 | public void dumpActivity(FileDescriptor fd, IBinder activitytoken, |
| 953 | String prefix, String[] args) { |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 954 | DumpComponentInfo data = new DumpComponentInfo(); |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 955 | try { |
| 956 | data.fd = ParcelFileDescriptor.dup(fd); |
| 957 | data.token = activitytoken; |
| 958 | data.prefix = prefix; |
| 959 | data.args = args; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 960 | sendMessage(H.DUMP_ACTIVITY, data, 0, 0, true /*async*/); |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 961 | } catch (IOException e) { |
| 962 | Slog.w(TAG, "dumpActivity failed", e); |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 963 | } |
| 964 | } |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 965 | |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 966 | public void dumpProvider(FileDescriptor fd, IBinder providertoken, |
| 967 | String[] args) { |
| 968 | DumpComponentInfo data = new DumpComponentInfo(); |
| 969 | try { |
| 970 | data.fd = ParcelFileDescriptor.dup(fd); |
| 971 | data.token = providertoken; |
| 972 | data.args = args; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 973 | sendMessage(H.DUMP_PROVIDER, data, 0, 0, true /*async*/); |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 974 | } catch (IOException e) { |
| 975 | Slog.w(TAG, "dumpProvider failed", e); |
| 976 | } |
| 977 | } |
| 978 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 979 | @Override |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 980 | public void dumpMemInfo(FileDescriptor fd, Debug.MemoryInfo mem, boolean checkin, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 981 | boolean dumpFullInfo, boolean dumpDalvik, boolean dumpSummaryOnly, String[] args) { |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 982 | FileOutputStream fout = new FileOutputStream(fd); |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 983 | PrintWriter pw = new FastPrintWriter(fout); |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 984 | try { |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 985 | dumpMemInfo(pw, mem, checkin, dumpFullInfo, dumpDalvik, dumpSummaryOnly); |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 986 | } finally { |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 987 | pw.flush(); |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 988 | } |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 989 | } |
| 990 | |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 991 | private void dumpMemInfo(PrintWriter pw, Debug.MemoryInfo memInfo, boolean checkin, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 992 | boolean dumpFullInfo, boolean dumpDalvik, boolean dumpSummaryOnly) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 993 | long nativeMax = Debug.getNativeHeapSize() / 1024; |
| 994 | long nativeAllocated = Debug.getNativeHeapAllocatedSize() / 1024; |
| 995 | long nativeFree = Debug.getNativeHeapFreeSize() / 1024; |
| 996 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 997 | Runtime runtime = Runtime.getRuntime(); |
Mathieu Chartier | d288a26 | 2015-07-10 13:44:42 -0700 | [diff] [blame] | 998 | runtime.gc(); // Do GC since countInstancesOfClass counts unreachable objects. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 999 | long dalvikMax = runtime.totalMemory() / 1024; |
| 1000 | long dalvikFree = runtime.freeMemory() / 1024; |
| 1001 | long dalvikAllocated = dalvikMax - dalvikFree; |
| 1002 | long viewInstanceCount = ViewDebug.getViewInstanceCount(); |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1003 | long viewRootInstanceCount = ViewDebug.getViewRootImplCount(); |
Brian Carlstrom | c21550a | 2010-10-05 21:34:06 -0700 | [diff] [blame] | 1004 | long appContextInstanceCount = Debug.countInstancesOfClass(ContextImpl.class); |
| 1005 | long activityInstanceCount = Debug.countInstancesOfClass(Activity.class); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1006 | int globalAssetCount = AssetManager.getGlobalAssetCount(); |
| 1007 | int globalAssetManagerCount = AssetManager.getGlobalAssetManagerCount(); |
| 1008 | int binderLocalObjectCount = Debug.getBinderLocalObjectCount(); |
| 1009 | int binderProxyObjectCount = Debug.getBinderProxyObjectCount(); |
| 1010 | int binderDeathObjectCount = Debug.getBinderDeathObjectCount(); |
Dianne Hackborn | fabb70b | 2014-11-11 12:22:36 -0800 | [diff] [blame] | 1011 | long parcelSize = Parcel.getGlobalAllocSize(); |
| 1012 | long parcelCount = Parcel.getGlobalAllocCount(); |
Brian Carlstrom | c9d5b31 | 2010-10-05 22:23:41 -0700 | [diff] [blame] | 1013 | long openSslSocketCount = Debug.countInstancesOfClass(OpenSSLSocketImpl.class); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1014 | SQLiteDebug.PagerStats stats = SQLiteDebug.getDatabaseInfo(); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1015 | |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 1016 | dumpMemInfoTable(pw, memInfo, checkin, dumpFullInfo, dumpDalvik, dumpSummaryOnly, |
| 1017 | Process.myPid(), |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 1018 | (mBoundApplication != null) ? mBoundApplication.processName : "unknown", |
| 1019 | nativeMax, nativeAllocated, nativeFree, |
| 1020 | dalvikMax, dalvikAllocated, dalvikFree); |
| 1021 | |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 1022 | if (checkin) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1023 | // NOTE: if you change anything significant below, also consider changing |
| 1024 | // ACTIVITY_THREAD_CHECKIN_VERSION. |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 1025 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1026 | // Object counts |
| 1027 | pw.print(viewInstanceCount); pw.print(','); |
| 1028 | pw.print(viewRootInstanceCount); pw.print(','); |
| 1029 | pw.print(appContextInstanceCount); pw.print(','); |
| 1030 | pw.print(activityInstanceCount); pw.print(','); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1031 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1032 | pw.print(globalAssetCount); pw.print(','); |
| 1033 | pw.print(globalAssetManagerCount); pw.print(','); |
| 1034 | pw.print(binderLocalObjectCount); pw.print(','); |
| 1035 | pw.print(binderProxyObjectCount); pw.print(','); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1036 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1037 | pw.print(binderDeathObjectCount); pw.print(','); |
| 1038 | pw.print(openSslSocketCount); pw.print(','); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1039 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1040 | // SQL |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1041 | pw.print(stats.memoryUsed / 1024); pw.print(','); |
Jeff Brown | 2a293b6 | 2012-01-19 14:02:22 -0800 | [diff] [blame] | 1042 | pw.print(stats.memoryUsed / 1024); pw.print(','); |
| 1043 | pw.print(stats.pageCacheOverflow / 1024); pw.print(','); |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 1044 | pw.print(stats.largestMemAlloc / 1024); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1045 | for (int i = 0; i < stats.dbStats.size(); i++) { |
| 1046 | DbStats dbStats = stats.dbStats.get(i); |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 1047 | pw.print(','); pw.print(dbStats.dbName); |
| 1048 | pw.print(','); pw.print(dbStats.pageSize); |
| 1049 | pw.print(','); pw.print(dbStats.dbSize); |
| 1050 | pw.print(','); pw.print(dbStats.lookaside); |
| 1051 | pw.print(','); pw.print(dbStats.cache); |
| 1052 | pw.print(','); pw.print(dbStats.cache); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1053 | } |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 1054 | pw.println(); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1055 | |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 1056 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1057 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1058 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1059 | pw.println(" "); |
| 1060 | pw.println(" Objects"); |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1061 | printRow(pw, TWO_COUNT_COLUMNS, "Views:", viewInstanceCount, "ViewRootImpl:", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1062 | viewRootInstanceCount); |
| 1063 | |
| 1064 | printRow(pw, TWO_COUNT_COLUMNS, "AppContexts:", appContextInstanceCount, |
| 1065 | "Activities:", activityInstanceCount); |
| 1066 | |
| 1067 | printRow(pw, TWO_COUNT_COLUMNS, "Assets:", globalAssetCount, |
| 1068 | "AssetManagers:", globalAssetManagerCount); |
| 1069 | |
| 1070 | printRow(pw, TWO_COUNT_COLUMNS, "Local Binders:", binderLocalObjectCount, |
| 1071 | "Proxy Binders:", binderProxyObjectCount); |
Dianne Hackborn | fabb70b | 2014-11-11 12:22:36 -0800 | [diff] [blame] | 1072 | printRow(pw, TWO_COUNT_COLUMNS, "Parcel memory:", parcelSize/1024, |
| 1073 | "Parcel count:", parcelCount); |
| 1074 | printRow(pw, TWO_COUNT_COLUMNS, "Death Recipients:", binderDeathObjectCount, |
| 1075 | "OpenSSL Sockets:", openSslSocketCount); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1076 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1077 | // SQLite mem info |
| 1078 | pw.println(" "); |
| 1079 | pw.println(" SQL"); |
Jeff Brown | 2a293b6 | 2012-01-19 14:02:22 -0800 | [diff] [blame] | 1080 | printRow(pw, ONE_COUNT_COLUMN, "MEMORY_USED:", stats.memoryUsed / 1024); |
| 1081 | printRow(pw, TWO_COUNT_COLUMNS, "PAGECACHE_OVERFLOW:", |
| 1082 | stats.pageCacheOverflow / 1024, "MALLOC_SIZE:", stats.largestMemAlloc / 1024); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1083 | pw.println(" "); |
| 1084 | int N = stats.dbStats.size(); |
| 1085 | if (N > 0) { |
| 1086 | pw.println(" DATABASES"); |
Vasu Nori | 3c7131f | 2010-09-21 14:36:57 -0700 | [diff] [blame] | 1087 | printRow(pw, " %8s %8s %14s %14s %s", "pgsz", "dbsz", "Lookaside(b)", "cache", |
| 1088 | "Dbname"); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1089 | for (int i = 0; i < N; i++) { |
| 1090 | DbStats dbStats = stats.dbStats.get(i); |
Vasu Nori | 3c7131f | 2010-09-21 14:36:57 -0700 | [diff] [blame] | 1091 | printRow(pw, DB_INFO_FORMAT, |
| 1092 | (dbStats.pageSize > 0) ? String.valueOf(dbStats.pageSize) : " ", |
| 1093 | (dbStats.dbSize > 0) ? String.valueOf(dbStats.dbSize) : " ", |
| 1094 | (dbStats.lookaside > 0) ? String.valueOf(dbStats.lookaside) : " ", |
| 1095 | dbStats.cache, dbStats.dbName); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1096 | } |
| 1097 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1098 | |
Dianne Hackborn | 82e1ee9 | 2009-08-11 18:56:41 -0700 | [diff] [blame] | 1099 | // Asset details. |
| 1100 | String assetAlloc = AssetManager.getAssetAllocations(); |
| 1101 | if (assetAlloc != null) { |
| 1102 | pw.println(" "); |
| 1103 | pw.println(" Asset Allocations"); |
| 1104 | pw.print(assetAlloc); |
| 1105 | } |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 1106 | } |
| 1107 | |
| 1108 | @Override |
| 1109 | public void dumpGfxInfo(FileDescriptor fd, String[] args) { |
| 1110 | dumpGraphicsInfo(fd); |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 1111 | WindowManagerGlobal.getInstance().dumpGfxInfo(fd, args); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1112 | } |
| 1113 | |
riddle_hsu | 1d6c40a | 2014-07-31 00:18:00 +0800 | [diff] [blame] | 1114 | private void dumpDatabaseInfo(FileDescriptor fd, String[] args) { |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 1115 | PrintWriter pw = new FastPrintWriter(new FileOutputStream(fd)); |
Jeff Brown | 6754ba2 | 2011-12-14 20:20:01 -0800 | [diff] [blame] | 1116 | PrintWriterPrinter printer = new PrintWriterPrinter(pw); |
| 1117 | SQLiteDebug.dump(printer, args); |
| 1118 | pw.flush(); |
| 1119 | } |
| 1120 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1121 | @Override |
riddle_hsu | 1d6c40a | 2014-07-31 00:18:00 +0800 | [diff] [blame] | 1122 | public void dumpDbInfo(final FileDescriptor fd, final String[] args) { |
| 1123 | if (mSystemThread) { |
| 1124 | // Ensure this invocation is asynchronous to prevent |
| 1125 | // writer waiting due to buffer cannot be consumed. |
| 1126 | AsyncTask.THREAD_POOL_EXECUTOR.execute(new Runnable() { |
| 1127 | @Override |
| 1128 | public void run() { |
| 1129 | dumpDatabaseInfo(fd, args); |
| 1130 | } |
| 1131 | }); |
| 1132 | } else { |
| 1133 | dumpDatabaseInfo(fd, args); |
| 1134 | } |
| 1135 | } |
| 1136 | |
| 1137 | @Override |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1138 | public void unstableProviderDied(IBinder provider) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1139 | sendMessage(H.UNSTABLE_PROVIDER_DIED, provider); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1140 | } |
| 1141 | |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 1142 | @Override |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 1143 | public void requestAssistContextExtras(IBinder activityToken, IBinder requestToken, |
Adam Skory | 7140a25 | 2013-09-11 12:04:58 +0100 | [diff] [blame] | 1144 | int requestType) { |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 1145 | RequestAssistContextExtras cmd = new RequestAssistContextExtras(); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 1146 | cmd.activityToken = activityToken; |
| 1147 | cmd.requestToken = requestToken; |
| 1148 | cmd.requestType = requestType; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1149 | sendMessage(H.REQUEST_ASSIST_CONTEXT_EXTRAS, cmd); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 1150 | } |
| 1151 | |
Svetoslav Ganov | 9aa597e | 2011-03-03 18:17:41 -0800 | [diff] [blame] | 1152 | public void setCoreSettings(Bundle coreSettings) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1153 | sendMessage(H.SET_CORE_SETTINGS, coreSettings); |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1154 | } |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1155 | |
| 1156 | public void updatePackageCompatibilityInfo(String pkg, CompatibilityInfo info) { |
| 1157 | UpdateCompatibilityData ucd = new UpdateCompatibilityData(); |
| 1158 | ucd.pkg = pkg; |
| 1159 | ucd.info = info; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1160 | sendMessage(H.UPDATE_PACKAGE_COMPATIBILITY_INFO, ucd); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1161 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1162 | |
| 1163 | public void scheduleTrimMemory(int level) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1164 | sendMessage(H.TRIM_MEMORY, null, level); |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1165 | } |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1166 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1167 | public void scheduleTranslucentConversionComplete(IBinder token, boolean drawComplete) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1168 | sendMessage(H.TRANSLUCENT_CONVERSION_COMPLETE, token, drawComplete ? 1 : 0); |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1169 | } |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 1170 | |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1171 | public void scheduleOnNewActivityOptions(IBinder token, ActivityOptions options) { |
| 1172 | sendMessage(H.ON_NEW_ACTIVITY_OPTIONS, |
| 1173 | new Pair<IBinder, ActivityOptions>(token, options)); |
| 1174 | } |
| 1175 | |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 1176 | public void setProcessState(int state) { |
| 1177 | updateProcessState(state, true); |
| 1178 | } |
| 1179 | |
| 1180 | public void updateProcessState(int processState, boolean fromIpc) { |
| 1181 | synchronized (this) { |
| 1182 | if (mLastProcessState != processState) { |
| 1183 | mLastProcessState = processState; |
Mathieu Chartier | 1e37090 | 2013-07-18 10:58:01 -0700 | [diff] [blame] | 1184 | // Update Dalvik state based on ActivityManager.PROCESS_STATE_* constants. |
| 1185 | final int DALVIK_PROCESS_STATE_JANK_PERCEPTIBLE = 0; |
| 1186 | final int DALVIK_PROCESS_STATE_JANK_IMPERCEPTIBLE = 1; |
| 1187 | int dalvikProcessState = DALVIK_PROCESS_STATE_JANK_IMPERCEPTIBLE; |
| 1188 | // TODO: Tune this since things like gmail sync are important background but not jank perceptible. |
| 1189 | if (processState <= ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND) { |
| 1190 | dalvikProcessState = DALVIK_PROCESS_STATE_JANK_PERCEPTIBLE; |
| 1191 | } |
| 1192 | VMRuntime.getRuntime().updateProcessState(dalvikProcessState); |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 1193 | if (false) { |
| 1194 | Slog.i(TAG, "******************* PROCESS STATE CHANGED TO: " + processState |
| 1195 | + (fromIpc ? " (from ipc": "")); |
| 1196 | } |
| 1197 | } |
| 1198 | } |
| 1199 | } |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 1200 | |
| 1201 | @Override |
| 1202 | public void scheduleInstallProvider(ProviderInfo provider) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1203 | sendMessage(H.INSTALL_PROVIDER, provider); |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 1204 | } |
Narayan Kamath | ccb2a086 | 2013-12-19 14:49:36 +0000 | [diff] [blame] | 1205 | |
| 1206 | @Override |
| 1207 | public final void updateTimePrefs(boolean is24Hour) { |
| 1208 | DateFormat.set24HourTimePref(is24Hour); |
| 1209 | } |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 1210 | |
| 1211 | @Override |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 1212 | public void scheduleCancelVisibleBehind(IBinder token) { |
| 1213 | sendMessage(H.CANCEL_VISIBLE_BEHIND, token); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 1214 | } |
| 1215 | |
| 1216 | @Override |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 1217 | public void scheduleBackgroundVisibleBehindChanged(IBinder token, boolean visible) { |
| 1218 | sendMessage(H.BACKGROUND_VISIBLE_BEHIND_CHANGED, token, visible ? 1 : 0); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 1219 | } |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 1220 | |
Jeff Sharkey | 605eb79 | 2014-11-04 13:34:06 -0800 | [diff] [blame] | 1221 | @Override |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 1222 | public void scheduleEnterAnimationComplete(IBinder token) { |
| 1223 | sendMessage(H.ENTER_ANIMATION_COMPLETE, token); |
| 1224 | } |
Jeff Sharkey | 605eb79 | 2014-11-04 13:34:06 -0800 | [diff] [blame] | 1225 | |
| 1226 | @Override |
| 1227 | public void notifyCleartextNetwork(byte[] firstPacket) { |
| 1228 | if (StrictMode.vmCleartextNetworkEnabled()) { |
| 1229 | StrictMode.onCleartextNetworkDetected(firstPacket); |
| 1230 | } |
| 1231 | } |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 1232 | |
| 1233 | @Override |
| 1234 | public void startBinderTracking() { |
| 1235 | sendMessage(H.START_BINDER_TRACKING, null); |
| 1236 | } |
| 1237 | |
| 1238 | @Override |
| 1239 | public void stopBinderTrackingAndDump(FileDescriptor fd) { |
| 1240 | try { |
| 1241 | sendMessage(H.STOP_BINDER_TRACKING_AND_DUMP, ParcelFileDescriptor.dup(fd)); |
| 1242 | } catch (IOException e) { |
| 1243 | } |
| 1244 | } |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 1245 | |
| 1246 | @Override |
| 1247 | public void scheduleMultiWindowModeChanged(IBinder token, boolean multiWindowMode) |
| 1248 | throws RemoteException { |
| 1249 | sendMessage(H.MULTI_WINDOW_MODE_CHANGED, token, multiWindowMode ? 1 : 0); |
| 1250 | } |
| 1251 | |
| 1252 | @Override |
| 1253 | public void schedulePictureInPictureModeChanged(IBinder token, boolean pipMode) |
| 1254 | throws RemoteException { |
| 1255 | sendMessage(H.PICTURE_IN_PICTURE_MODE_CHANGED, token, pipMode ? 1 : 0); |
| 1256 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1257 | } |
| 1258 | |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1259 | private int getLifecycleSeq() { |
| 1260 | synchronized (mResourcesManager) { |
| 1261 | return mLifecycleSeq++; |
| 1262 | } |
| 1263 | } |
| 1264 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1265 | private class H extends Handler { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1266 | public static final int LAUNCH_ACTIVITY = 100; |
| 1267 | public static final int PAUSE_ACTIVITY = 101; |
| 1268 | public static final int PAUSE_ACTIVITY_FINISHING= 102; |
| 1269 | public static final int STOP_ACTIVITY_SHOW = 103; |
| 1270 | public static final int STOP_ACTIVITY_HIDE = 104; |
| 1271 | public static final int SHOW_WINDOW = 105; |
| 1272 | public static final int HIDE_WINDOW = 106; |
| 1273 | public static final int RESUME_ACTIVITY = 107; |
| 1274 | public static final int SEND_RESULT = 108; |
Brian Carlstrom | ed7e007 | 2011-03-24 13:27:57 -0700 | [diff] [blame] | 1275 | public static final int DESTROY_ACTIVITY = 109; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1276 | public static final int BIND_APPLICATION = 110; |
| 1277 | public static final int EXIT_APPLICATION = 111; |
| 1278 | public static final int NEW_INTENT = 112; |
| 1279 | public static final int RECEIVER = 113; |
| 1280 | public static final int CREATE_SERVICE = 114; |
| 1281 | public static final int SERVICE_ARGS = 115; |
| 1282 | public static final int STOP_SERVICE = 116; |
Dianne Hackborn | 0923328 | 2014-04-30 11:33:59 -0700 | [diff] [blame] | 1283 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1284 | public static final int CONFIGURATION_CHANGED = 118; |
| 1285 | public static final int CLEAN_UP_CONTEXT = 119; |
| 1286 | public static final int GC_WHEN_IDLE = 120; |
| 1287 | public static final int BIND_SERVICE = 121; |
| 1288 | public static final int UNBIND_SERVICE = 122; |
| 1289 | public static final int DUMP_SERVICE = 123; |
| 1290 | public static final int LOW_MEMORY = 124; |
| 1291 | public static final int ACTIVITY_CONFIGURATION_CHANGED = 125; |
| 1292 | public static final int RELAUNCH_ACTIVITY = 126; |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 1293 | public static final int PROFILER_CONTROL = 127; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1294 | public static final int CREATE_BACKUP_AGENT = 128; |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 1295 | public static final int DESTROY_BACKUP_AGENT = 129; |
| 1296 | public static final int SUICIDE = 130; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1297 | public static final int REMOVE_PROVIDER = 131; |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 1298 | public static final int ENABLE_JIT = 132; |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1299 | public static final int DISPATCH_PACKAGE_BROADCAST = 133; |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 1300 | public static final int SCHEDULE_CRASH = 134; |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 1301 | public static final int DUMP_HEAP = 135; |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1302 | public static final int DUMP_ACTIVITY = 136; |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1303 | public static final int SLEEPING = 137; |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1304 | public static final int SET_CORE_SETTINGS = 138; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1305 | public static final int UPDATE_PACKAGE_COMPATIBILITY_INFO = 139; |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1306 | public static final int TRIM_MEMORY = 140; |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1307 | public static final int DUMP_PROVIDER = 141; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1308 | public static final int UNSTABLE_PROVIDER_DIED = 142; |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 1309 | public static final int REQUEST_ASSIST_CONTEXT_EXTRAS = 143; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1310 | public static final int TRANSLUCENT_CONVERSION_COMPLETE = 144; |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 1311 | public static final int INSTALL_PROVIDER = 145; |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1312 | public static final int ON_NEW_ACTIVITY_OPTIONS = 146; |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 1313 | public static final int CANCEL_VISIBLE_BEHIND = 147; |
| 1314 | public static final int BACKGROUND_VISIBLE_BEHIND_CHANGED = 148; |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 1315 | public static final int ENTER_ANIMATION_COMPLETE = 149; |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 1316 | public static final int START_BINDER_TRACKING = 150; |
| 1317 | public static final int STOP_BINDER_TRACKING_AND_DUMP = 151; |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 1318 | public static final int MULTI_WINDOW_MODE_CHANGED = 152; |
| 1319 | public static final int PICTURE_IN_PICTURE_MODE_CHANGED = 153; |
Narayan Kamath | ccb2a086 | 2013-12-19 14:49:36 +0000 | [diff] [blame] | 1320 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1321 | String codeToString(int code) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 1322 | if (DEBUG_MESSAGES) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1323 | switch (code) { |
| 1324 | case LAUNCH_ACTIVITY: return "LAUNCH_ACTIVITY"; |
| 1325 | case PAUSE_ACTIVITY: return "PAUSE_ACTIVITY"; |
| 1326 | case PAUSE_ACTIVITY_FINISHING: return "PAUSE_ACTIVITY_FINISHING"; |
| 1327 | case STOP_ACTIVITY_SHOW: return "STOP_ACTIVITY_SHOW"; |
| 1328 | case STOP_ACTIVITY_HIDE: return "STOP_ACTIVITY_HIDE"; |
| 1329 | case SHOW_WINDOW: return "SHOW_WINDOW"; |
| 1330 | case HIDE_WINDOW: return "HIDE_WINDOW"; |
| 1331 | case RESUME_ACTIVITY: return "RESUME_ACTIVITY"; |
| 1332 | case SEND_RESULT: return "SEND_RESULT"; |
| 1333 | case DESTROY_ACTIVITY: return "DESTROY_ACTIVITY"; |
| 1334 | case BIND_APPLICATION: return "BIND_APPLICATION"; |
| 1335 | case EXIT_APPLICATION: return "EXIT_APPLICATION"; |
| 1336 | case NEW_INTENT: return "NEW_INTENT"; |
| 1337 | case RECEIVER: return "RECEIVER"; |
| 1338 | case CREATE_SERVICE: return "CREATE_SERVICE"; |
| 1339 | case SERVICE_ARGS: return "SERVICE_ARGS"; |
| 1340 | case STOP_SERVICE: return "STOP_SERVICE"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1341 | case CONFIGURATION_CHANGED: return "CONFIGURATION_CHANGED"; |
| 1342 | case CLEAN_UP_CONTEXT: return "CLEAN_UP_CONTEXT"; |
| 1343 | case GC_WHEN_IDLE: return "GC_WHEN_IDLE"; |
| 1344 | case BIND_SERVICE: return "BIND_SERVICE"; |
| 1345 | case UNBIND_SERVICE: return "UNBIND_SERVICE"; |
| 1346 | case DUMP_SERVICE: return "DUMP_SERVICE"; |
| 1347 | case LOW_MEMORY: return "LOW_MEMORY"; |
| 1348 | case ACTIVITY_CONFIGURATION_CHANGED: return "ACTIVITY_CONFIGURATION_CHANGED"; |
| 1349 | case RELAUNCH_ACTIVITY: return "RELAUNCH_ACTIVITY"; |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 1350 | case PROFILER_CONTROL: return "PROFILER_CONTROL"; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1351 | case CREATE_BACKUP_AGENT: return "CREATE_BACKUP_AGENT"; |
| 1352 | case DESTROY_BACKUP_AGENT: return "DESTROY_BACKUP_AGENT"; |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 1353 | case SUICIDE: return "SUICIDE"; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1354 | case REMOVE_PROVIDER: return "REMOVE_PROVIDER"; |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 1355 | case ENABLE_JIT: return "ENABLE_JIT"; |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1356 | case DISPATCH_PACKAGE_BROADCAST: return "DISPATCH_PACKAGE_BROADCAST"; |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 1357 | case SCHEDULE_CRASH: return "SCHEDULE_CRASH"; |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 1358 | case DUMP_HEAP: return "DUMP_HEAP"; |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1359 | case DUMP_ACTIVITY: return "DUMP_ACTIVITY"; |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1360 | case SLEEPING: return "SLEEPING"; |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1361 | case SET_CORE_SETTINGS: return "SET_CORE_SETTINGS"; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1362 | case UPDATE_PACKAGE_COMPATIBILITY_INFO: return "UPDATE_PACKAGE_COMPATIBILITY_INFO"; |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1363 | case TRIM_MEMORY: return "TRIM_MEMORY"; |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1364 | case DUMP_PROVIDER: return "DUMP_PROVIDER"; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1365 | case UNSTABLE_PROVIDER_DIED: return "UNSTABLE_PROVIDER_DIED"; |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 1366 | case REQUEST_ASSIST_CONTEXT_EXTRAS: return "REQUEST_ASSIST_CONTEXT_EXTRAS"; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1367 | case TRANSLUCENT_CONVERSION_COMPLETE: return "TRANSLUCENT_CONVERSION_COMPLETE"; |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 1368 | case INSTALL_PROVIDER: return "INSTALL_PROVIDER"; |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1369 | case ON_NEW_ACTIVITY_OPTIONS: return "ON_NEW_ACTIVITY_OPTIONS"; |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 1370 | case CANCEL_VISIBLE_BEHIND: return "CANCEL_VISIBLE_BEHIND"; |
| 1371 | case BACKGROUND_VISIBLE_BEHIND_CHANGED: return "BACKGROUND_VISIBLE_BEHIND_CHANGED"; |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 1372 | case ENTER_ANIMATION_COMPLETE: return "ENTER_ANIMATION_COMPLETE"; |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 1373 | case MULTI_WINDOW_MODE_CHANGED: return "MULTI_WINDOW_MODE_CHANGED"; |
| 1374 | case PICTURE_IN_PICTURE_MODE_CHANGED: return "PICTURE_IN_PICTURE_MODE_CHANGED"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1375 | } |
| 1376 | } |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 1377 | return Integer.toString(code); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1378 | } |
| 1379 | public void handleMessage(Message msg) { |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 1380 | 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] | 1381 | switch (msg.what) { |
| 1382 | case LAUNCH_ACTIVITY: { |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1383 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityStart"); |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 1384 | final ActivityClientRecord r = (ActivityClientRecord) msg.obj; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1385 | |
| 1386 | r.packageInfo = getPackageInfoNoCheck( |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1387 | r.activityInfo.applicationInfo, r.compatInfo); |
Christopher Tate | b70f3df | 2009-04-07 16:07:59 -0700 | [diff] [blame] | 1388 | handleLaunchActivity(r, null); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1389 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1390 | } break; |
| 1391 | case RELAUNCH_ACTIVITY: { |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1392 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityRestart"); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1393 | ActivityClientRecord r = (ActivityClientRecord)msg.obj; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 1394 | handleRelaunchActivity(r); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1395 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1396 | } break; |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1397 | case PAUSE_ACTIVITY: { |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1398 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityPause"); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1399 | SomeArgs args = (SomeArgs) msg.obj; |
| 1400 | handlePauseActivity((IBinder) args.arg1, false, |
| 1401 | (args.argi1 & USER_LEAVING) != 0, args.argi2, |
| 1402 | (args.argi1 & DONT_REPORT) != 0, args.argi3); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1403 | maybeSnapshot(); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1404 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1405 | } break; |
| 1406 | case PAUSE_ACTIVITY_FINISHING: { |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1407 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityPause"); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1408 | SomeArgs args = (SomeArgs) msg.obj; |
| 1409 | handlePauseActivity((IBinder) args.arg1, true, (args.argi1 & USER_LEAVING) != 0, |
| 1410 | args.argi2, (args.argi1 & DONT_REPORT) != 0, args.argi3); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1411 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1412 | } break; |
| 1413 | case STOP_ACTIVITY_SHOW: { |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1414 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityStop"); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1415 | SomeArgs args = (SomeArgs) msg.obj; |
| 1416 | handleStopActivity((IBinder) args.arg1, true, args.argi2, args.argi3); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1417 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1418 | } break; |
| 1419 | case STOP_ACTIVITY_HIDE: { |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1420 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityStop"); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1421 | SomeArgs args = (SomeArgs) msg.obj; |
| 1422 | handleStopActivity((IBinder) args.arg1, false, args.argi2, args.argi3); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1423 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1424 | } break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1425 | case SHOW_WINDOW: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1426 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityShowWindow"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1427 | handleWindowVisibility((IBinder)msg.obj, true); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1428 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1429 | break; |
| 1430 | case HIDE_WINDOW: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1431 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityHideWindow"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1432 | handleWindowVisibility((IBinder)msg.obj, false); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1433 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1434 | break; |
| 1435 | case RESUME_ACTIVITY: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1436 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityResume"); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1437 | SomeArgs args = (SomeArgs) msg.obj; |
| 1438 | handleResumeActivity((IBinder) args.arg1, true, args.argi1 != 0, true, |
| 1439 | args.argi3); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1440 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1441 | break; |
| 1442 | case SEND_RESULT: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1443 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityDeliverResult"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1444 | handleSendResult((ResultData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1445 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1446 | break; |
| 1447 | case DESTROY_ACTIVITY: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1448 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityDestroy"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1449 | handleDestroyActivity((IBinder)msg.obj, msg.arg1 != 0, |
| 1450 | msg.arg2, false); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1451 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1452 | break; |
| 1453 | case BIND_APPLICATION: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1454 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "bindApplication"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1455 | AppBindData data = (AppBindData)msg.obj; |
| 1456 | handleBindApplication(data); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1457 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1458 | break; |
| 1459 | case EXIT_APPLICATION: |
| 1460 | if (mInitialApplication != null) { |
| 1461 | mInitialApplication.onTerminate(); |
| 1462 | } |
| 1463 | Looper.myLooper().quit(); |
| 1464 | break; |
| 1465 | case NEW_INTENT: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1466 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityNewIntent"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1467 | handleNewIntent((NewIntentData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1468 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1469 | break; |
| 1470 | case RECEIVER: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1471 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "broadcastReceiveComp"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1472 | handleReceiver((ReceiverData)msg.obj); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1473 | maybeSnapshot(); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1474 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1475 | break; |
| 1476 | case CREATE_SERVICE: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1477 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "serviceCreate"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1478 | handleCreateService((CreateServiceData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1479 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1480 | break; |
| 1481 | case BIND_SERVICE: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1482 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "serviceBind"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1483 | handleBindService((BindServiceData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1484 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1485 | break; |
| 1486 | case UNBIND_SERVICE: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1487 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "serviceUnbind"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1488 | handleUnbindService((BindServiceData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1489 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1490 | break; |
| 1491 | case SERVICE_ARGS: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1492 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "serviceStart"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1493 | handleServiceArgs((ServiceArgsData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1494 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1495 | break; |
| 1496 | case STOP_SERVICE: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1497 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "serviceStop"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1498 | handleStopService((IBinder)msg.obj); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1499 | maybeSnapshot(); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1500 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1501 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1502 | case CONFIGURATION_CHANGED: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1503 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "configChanged"); |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 1504 | mCurDefaultDisplayDpi = ((Configuration)msg.obj).densityDpi; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1505 | handleConfigurationChanged((Configuration)msg.obj, null); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1506 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1507 | break; |
| 1508 | case CLEAN_UP_CONTEXT: |
| 1509 | ContextCleanupInfo cci = (ContextCleanupInfo)msg.obj; |
| 1510 | cci.context.performFinalCleanup(cci.who, cci.what); |
| 1511 | break; |
| 1512 | case GC_WHEN_IDLE: |
| 1513 | scheduleGcIdler(); |
| 1514 | break; |
| 1515 | case DUMP_SERVICE: |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1516 | handleDumpService((DumpComponentInfo)msg.obj); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1517 | break; |
| 1518 | case LOW_MEMORY: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1519 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "lowMemory"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1520 | handleLowMemory(); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1521 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1522 | break; |
| 1523 | case ACTIVITY_CONFIGURATION_CHANGED: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1524 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityConfigChanged"); |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 1525 | handleActivityConfigurationChanged((ActivityConfigChangeData) msg.obj, |
| 1526 | msg.arg1 == 1 ? REPORT_TO_ACTIVITY : !REPORT_TO_ACTIVITY); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1527 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1528 | break; |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 1529 | case PROFILER_CONTROL: |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 1530 | handleProfilerControl(msg.arg1 != 0, (ProfilerInfo)msg.obj, msg.arg2); |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 1531 | break; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1532 | case CREATE_BACKUP_AGENT: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1533 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "backupCreateAgent"); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1534 | handleCreateBackupAgent((CreateBackupAgentData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1535 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1536 | break; |
| 1537 | case DESTROY_BACKUP_AGENT: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1538 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "backupDestroyAgent"); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1539 | handleDestroyBackupAgent((CreateBackupAgentData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1540 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1541 | break; |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 1542 | case SUICIDE: |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1543 | Process.killProcess(Process.myPid()); |
| 1544 | break; |
| 1545 | case REMOVE_PROVIDER: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1546 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "providerRemove"); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1547 | completeRemoveProvider((ProviderRefCount)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1548 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 1549 | break; |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 1550 | case ENABLE_JIT: |
| 1551 | ensureJitEnabled(); |
| 1552 | break; |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1553 | case DISPATCH_PACKAGE_BROADCAST: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1554 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "broadcastPackage"); |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1555 | handleDispatchPackageBroadcast(msg.arg1, (String[])msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1556 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1557 | break; |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 1558 | case SCHEDULE_CRASH: |
| 1559 | throw new RemoteServiceException((String)msg.obj); |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 1560 | case DUMP_HEAP: |
| 1561 | handleDumpHeap(msg.arg1 != 0, (DumpHeapData)msg.obj); |
| 1562 | break; |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1563 | case DUMP_ACTIVITY: |
| 1564 | handleDumpActivity((DumpComponentInfo)msg.obj); |
| 1565 | break; |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1566 | case DUMP_PROVIDER: |
| 1567 | handleDumpProvider((DumpComponentInfo)msg.obj); |
| 1568 | break; |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1569 | case SLEEPING: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1570 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "sleeping"); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1571 | handleSleeping((IBinder)msg.obj, msg.arg1 != 0); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1572 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1573 | break; |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1574 | case SET_CORE_SETTINGS: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1575 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "setCoreSettings"); |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1576 | handleSetCoreSettings((Bundle) msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1577 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1578 | break; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1579 | case UPDATE_PACKAGE_COMPATIBILITY_INFO: |
| 1580 | handleUpdatePackageCompatibilityInfo((UpdateCompatibilityData)msg.obj); |
Dianne Hackborn | f0754f5b | 2011-07-21 16:02:07 -0700 | [diff] [blame] | 1581 | break; |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1582 | case TRIM_MEMORY: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1583 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "trimMemory"); |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1584 | handleTrimMemory(msg.arg1); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1585 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Dianne Hackborn | f0754f5b | 2011-07-21 16:02:07 -0700 | [diff] [blame] | 1586 | break; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1587 | case UNSTABLE_PROVIDER_DIED: |
| 1588 | handleUnstableProviderDied((IBinder)msg.obj, false); |
| 1589 | break; |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 1590 | case REQUEST_ASSIST_CONTEXT_EXTRAS: |
| 1591 | handleRequestAssistContextExtras((RequestAssistContextExtras)msg.obj); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 1592 | break; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1593 | case TRANSLUCENT_CONVERSION_COMPLETE: |
| 1594 | handleTranslucentConversionComplete((IBinder)msg.obj, msg.arg1 == 1); |
| 1595 | break; |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 1596 | case INSTALL_PROVIDER: |
| 1597 | handleInstallProvider((ProviderInfo) msg.obj); |
| 1598 | break; |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1599 | case ON_NEW_ACTIVITY_OPTIONS: |
| 1600 | Pair<IBinder, ActivityOptions> pair = (Pair<IBinder, ActivityOptions>) msg.obj; |
| 1601 | onNewActivityOptions(pair.first, pair.second); |
Dake Gu | 7ef70b0 | 2014-07-08 18:37:12 -0700 | [diff] [blame] | 1602 | break; |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 1603 | case CANCEL_VISIBLE_BEHIND: |
| 1604 | handleCancelVisibleBehind((IBinder) msg.obj); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 1605 | break; |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 1606 | case BACKGROUND_VISIBLE_BEHIND_CHANGED: |
| 1607 | handleOnBackgroundVisibleBehindChanged((IBinder) msg.obj, msg.arg1 > 0); |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1608 | break; |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 1609 | case ENTER_ANIMATION_COMPLETE: |
| 1610 | handleEnterAnimationComplete((IBinder) msg.obj); |
| 1611 | break; |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 1612 | case START_BINDER_TRACKING: |
| 1613 | handleStartBinderTracking(); |
| 1614 | break; |
| 1615 | case STOP_BINDER_TRACKING_AND_DUMP: |
| 1616 | handleStopBinderTrackingAndDump((ParcelFileDescriptor) msg.obj); |
| 1617 | break; |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 1618 | case MULTI_WINDOW_MODE_CHANGED: |
| 1619 | handleMultiWindowModeChanged((IBinder) msg.obj, msg.arg1 == 1); |
| 1620 | break; |
| 1621 | case PICTURE_IN_PICTURE_MODE_CHANGED: |
| 1622 | handlePictureInPictureModeChanged((IBinder) msg.obj, msg.arg1 == 1); |
| 1623 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1624 | } |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1625 | Object obj = msg.obj; |
| 1626 | if (obj instanceof SomeArgs) { |
| 1627 | ((SomeArgs) obj).recycle(); |
| 1628 | } |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 1629 | 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] | 1630 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1631 | |
Brian Carlstrom | ed7e007 | 2011-03-24 13:27:57 -0700 | [diff] [blame] | 1632 | private void maybeSnapshot() { |
| 1633 | if (mBoundApplication != null && SamplingProfilerIntegration.isEnabled()) { |
Sen Hu | bde7570 | 2010-05-28 01:54:03 -0700 | [diff] [blame] | 1634 | // convert the *private* ActivityThread.PackageInfo to *public* known |
| 1635 | // android.content.pm.PackageInfo |
| 1636 | String packageName = mBoundApplication.info.mPackageName; |
| 1637 | android.content.pm.PackageInfo packageInfo = null; |
| 1638 | try { |
| 1639 | Context context = getSystemContext(); |
| 1640 | if(context == null) { |
| 1641 | Log.e(TAG, "cannot get a valid context"); |
| 1642 | return; |
| 1643 | } |
| 1644 | PackageManager pm = context.getPackageManager(); |
| 1645 | if(pm == null) { |
| 1646 | Log.e(TAG, "cannot get a valid PackageManager"); |
| 1647 | return; |
| 1648 | } |
| 1649 | packageInfo = pm.getPackageInfo( |
| 1650 | packageName, PackageManager.GET_ACTIVITIES); |
| 1651 | } catch (NameNotFoundException e) { |
| 1652 | Log.e(TAG, "cannot get package info for " + packageName, e); |
| 1653 | } |
| 1654 | SamplingProfilerIntegration.writeSnapshot(mBoundApplication.processName, packageInfo); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1655 | } |
| 1656 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1657 | } |
| 1658 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1659 | private class Idler implements MessageQueue.IdleHandler { |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 1660 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1661 | public final boolean queueIdle() { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1662 | ActivityClientRecord a = mNewActivities; |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 1663 | boolean stopProfiling = false; |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 1664 | if (mBoundApplication != null && mProfiler.profileFd != null |
| 1665 | && mProfiler.autoStopProfiler) { |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 1666 | stopProfiling = true; |
| 1667 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1668 | if (a != null) { |
| 1669 | mNewActivities = null; |
| 1670 | IActivityManager am = ActivityManagerNative.getDefault(); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1671 | ActivityClientRecord prev; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1672 | do { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 1673 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1674 | TAG, "Reporting idle of " + a + |
| 1675 | " finished=" + |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1676 | (a.activity != null && a.activity.mFinished)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1677 | if (a.activity != null && !a.activity.mFinished) { |
| 1678 | try { |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 1679 | am.activityIdle(a.token, a.createdConfig, stopProfiling); |
Dianne Hackborn | e88846e | 2009-09-30 21:34:25 -0700 | [diff] [blame] | 1680 | a.createdConfig = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1681 | } catch (RemoteException ex) { |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1682 | // Ignore |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1683 | } |
| 1684 | } |
| 1685 | prev = a; |
| 1686 | a = a.nextIdle; |
| 1687 | prev.nextIdle = null; |
| 1688 | } while (a != null); |
| 1689 | } |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 1690 | if (stopProfiling) { |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 1691 | mProfiler.stopProfiling(); |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 1692 | } |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 1693 | ensureJitEnabled(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1694 | return false; |
| 1695 | } |
| 1696 | } |
| 1697 | |
| 1698 | final class GcIdler implements MessageQueue.IdleHandler { |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 1699 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1700 | public final boolean queueIdle() { |
| 1701 | doGcIfNeeded(); |
| 1702 | return false; |
| 1703 | } |
| 1704 | } |
| 1705 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1706 | public static ActivityThread currentActivityThread() { |
Jeff Sharkey | 66a017b | 2013-01-17 18:18:22 -0800 | [diff] [blame] | 1707 | return sCurrentActivityThread; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1708 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1709 | |
Wale Ogunwale | 9a6ef1e | 2015-06-02 13:41:00 -0700 | [diff] [blame] | 1710 | public static boolean isSystem() { |
| 1711 | return (sCurrentActivityThread != null) ? sCurrentActivityThread.mSystemThread : false; |
| 1712 | } |
| 1713 | |
Svetoslav | fbf0eca | 2015-05-01 16:52:41 -0700 | [diff] [blame] | 1714 | public static String currentOpPackageName() { |
| 1715 | ActivityThread am = currentActivityThread(); |
| 1716 | return (am != null && am.getApplication() != null) |
| 1717 | ? am.getApplication().getOpPackageName() : null; |
| 1718 | } |
| 1719 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1720 | public static String currentPackageName() { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1721 | ActivityThread am = currentActivityThread(); |
| 1722 | return (am != null && am.mBoundApplication != null) |
Dianne Hackborn | b57a50b | 2013-04-11 17:29:32 -0700 | [diff] [blame] | 1723 | ? am.mBoundApplication.appInfo.packageName : null; |
| 1724 | } |
| 1725 | |
| 1726 | public static String currentProcessName() { |
| 1727 | ActivityThread am = currentActivityThread(); |
| 1728 | return (am != null && am.mBoundApplication != null) |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1729 | ? am.mBoundApplication.processName : null; |
| 1730 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1731 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1732 | public static Application currentApplication() { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1733 | ActivityThread am = currentActivityThread(); |
| 1734 | return am != null ? am.mInitialApplication : null; |
| 1735 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1736 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1737 | public static IPackageManager getPackageManager() { |
| 1738 | if (sPackageManager != null) { |
| 1739 | //Slog.v("PackageManager", "returning cur default = " + sPackageManager); |
| 1740 | return sPackageManager; |
| 1741 | } |
| 1742 | IBinder b = ServiceManager.getService("package"); |
| 1743 | //Slog.v("PackageManager", "default service binder = " + b); |
| 1744 | sPackageManager = IPackageManager.Stub.asInterface(b); |
| 1745 | //Slog.v("PackageManager", "default service = " + sPackageManager); |
| 1746 | return sPackageManager; |
| 1747 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1748 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1749 | private Configuration mMainThreadConfig = new Configuration(); |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 1750 | Configuration applyConfigCompatMainThread(int displayDensity, Configuration config, |
| 1751 | CompatibilityInfo compat) { |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1752 | if (config == null) { |
| 1753 | return null; |
| 1754 | } |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 1755 | if (!compat.supportsScreen()) { |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1756 | mMainThreadConfig.setTo(config); |
| 1757 | config = mMainThreadConfig; |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 1758 | compat.applyToConfiguration(displayDensity, config); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1759 | } |
| 1760 | return config; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1761 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1762 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1763 | /** |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1764 | * Creates the top level resources for the given package. |
| 1765 | */ |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 1766 | Resources getTopLevelResources(String resDir, String[] splitResDirs, String[] overlayDirs, |
| 1767 | String[] libDirs, int displayId, Configuration overrideConfiguration, |
Dianne Hackborn | 756220b | 2012-08-14 16:45:30 -0700 | [diff] [blame] | 1768 | LoadedApk pkgInfo) { |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 1769 | return mResourcesManager.getTopLevelResources(resDir, splitResDirs, overlayDirs, libDirs, |
Alan Viverette | 02fc5fe | 2015-08-27 13:16:09 -0400 | [diff] [blame] | 1770 | displayId, overrideConfiguration, pkgInfo.getCompatibilityInfo(), |
| 1771 | pkgInfo.getClassLoader()); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1772 | } |
| 1773 | |
| 1774 | final Handler getHandler() { |
| 1775 | return mH; |
| 1776 | } |
| 1777 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1778 | public final LoadedApk getPackageInfo(String packageName, CompatibilityInfo compatInfo, |
| 1779 | int flags) { |
Amith Yamasani | 98edc95 | 2012-09-25 14:09:27 -0700 | [diff] [blame] | 1780 | return getPackageInfo(packageName, compatInfo, flags, UserHandle.myUserId()); |
| 1781 | } |
| 1782 | |
| 1783 | public final LoadedApk getPackageInfo(String packageName, CompatibilityInfo compatInfo, |
| 1784 | int flags, int userId) { |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 1785 | final boolean differentUser = (UserHandle.myUserId() != userId); |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 1786 | synchronized (mResourcesManager) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1787 | WeakReference<LoadedApk> ref; |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 1788 | if (differentUser) { |
| 1789 | // Caching not supported across users |
| 1790 | ref = null; |
| 1791 | } else if ((flags & Context.CONTEXT_INCLUDE_CODE) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1792 | ref = mPackages.get(packageName); |
| 1793 | } else { |
| 1794 | ref = mResourcePackages.get(packageName); |
| 1795 | } |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 1796 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1797 | LoadedApk packageInfo = ref != null ? ref.get() : null; |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 1798 | //Slog.i(TAG, "getPackageInfo " + packageName + ": " + packageInfo); |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1799 | //if (packageInfo != null) Slog.i(TAG, "isUptoDate " + packageInfo.mResDir |
| 1800 | // + ": " + packageInfo.mResources.getAssets().isUpToDate()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1801 | if (packageInfo != null && (packageInfo.mResources == null |
| 1802 | || packageInfo.mResources.getAssets().isUpToDate())) { |
| 1803 | if (packageInfo.isSecurityViolation() |
| 1804 | && (flags&Context.CONTEXT_IGNORE_SECURITY) == 0) { |
| 1805 | throw new SecurityException( |
| 1806 | "Requesting code from " + packageName |
| 1807 | + " to be run in process " |
| 1808 | + mBoundApplication.processName |
| 1809 | + "/" + mBoundApplication.appInfo.uid); |
| 1810 | } |
| 1811 | return packageInfo; |
| 1812 | } |
| 1813 | } |
| 1814 | |
| 1815 | ApplicationInfo ai = null; |
| 1816 | try { |
| 1817 | ai = getPackageManager().getApplicationInfo(packageName, |
Jeff Sharkey | c5967e9 | 2016-01-07 18:50:29 -0700 | [diff] [blame] | 1818 | PackageManager.GET_SHARED_LIBRARY_FILES |
| 1819 | | PackageManager.MATCH_DEBUG_TRIAGED_MISSING, |
| 1820 | userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1821 | } catch (RemoteException e) { |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1822 | // Ignore |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1823 | } |
| 1824 | |
| 1825 | if (ai != null) { |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1826 | return getPackageInfo(ai, compatInfo, flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1827 | } |
| 1828 | |
| 1829 | return null; |
| 1830 | } |
| 1831 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1832 | public final LoadedApk getPackageInfo(ApplicationInfo ai, CompatibilityInfo compatInfo, |
| 1833 | int flags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1834 | boolean includeCode = (flags&Context.CONTEXT_INCLUDE_CODE) != 0; |
| 1835 | boolean securityViolation = includeCode && ai.uid != 0 |
| 1836 | && ai.uid != Process.SYSTEM_UID && (mBoundApplication != null |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 1837 | ? !UserHandle.isSameApp(ai.uid, mBoundApplication.appInfo.uid) |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 1838 | : true); |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 1839 | boolean registerPackage = includeCode && (flags&Context.CONTEXT_REGISTER_PACKAGE) != 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1840 | if ((flags&(Context.CONTEXT_INCLUDE_CODE |
| 1841 | |Context.CONTEXT_IGNORE_SECURITY)) |
| 1842 | == Context.CONTEXT_INCLUDE_CODE) { |
| 1843 | if (securityViolation) { |
| 1844 | String msg = "Requesting code from " + ai.packageName |
| 1845 | + " (with uid " + ai.uid + ")"; |
| 1846 | if (mBoundApplication != null) { |
| 1847 | msg = msg + " to be run in process " |
| 1848 | + mBoundApplication.processName + " (with uid " |
| 1849 | + mBoundApplication.appInfo.uid + ")"; |
| 1850 | } |
| 1851 | throw new SecurityException(msg); |
| 1852 | } |
| 1853 | } |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 1854 | return getPackageInfo(ai, compatInfo, null, securityViolation, includeCode, |
| 1855 | registerPackage); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1856 | } |
| 1857 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1858 | public final LoadedApk getPackageInfoNoCheck(ApplicationInfo ai, |
| 1859 | CompatibilityInfo compatInfo) { |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 1860 | return getPackageInfo(ai, compatInfo, null, false, true, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1861 | } |
| 1862 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1863 | public final LoadedApk peekPackageInfo(String packageName, boolean includeCode) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 1864 | synchronized (mResourcesManager) { |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1865 | WeakReference<LoadedApk> ref; |
| 1866 | if (includeCode) { |
| 1867 | ref = mPackages.get(packageName); |
| 1868 | } else { |
| 1869 | ref = mResourcePackages.get(packageName); |
| 1870 | } |
| 1871 | return ref != null ? ref.get() : null; |
| 1872 | } |
| 1873 | } |
| 1874 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1875 | private LoadedApk getPackageInfo(ApplicationInfo aInfo, CompatibilityInfo compatInfo, |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 1876 | ClassLoader baseLoader, boolean securityViolation, boolean includeCode, |
| 1877 | boolean registerPackage) { |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 1878 | final boolean differentUser = (UserHandle.myUserId() != UserHandle.getUserId(aInfo.uid)); |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 1879 | synchronized (mResourcesManager) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1880 | WeakReference<LoadedApk> ref; |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 1881 | if (differentUser) { |
| 1882 | // Caching not supported across users |
| 1883 | ref = null; |
| 1884 | } else if (includeCode) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1885 | ref = mPackages.get(aInfo.packageName); |
| 1886 | } else { |
| 1887 | ref = mResourcePackages.get(aInfo.packageName); |
| 1888 | } |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 1889 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1890 | LoadedApk packageInfo = ref != null ? ref.get() : null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1891 | if (packageInfo == null || (packageInfo.mResources != null |
| 1892 | && !packageInfo.mResources.getAssets().isUpToDate())) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 1893 | if (localLOGV) Slog.v(TAG, (includeCode ? "Loading code package " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1894 | : "Loading resource-only package ") + aInfo.packageName |
| 1895 | + " (in " + (mBoundApplication != null |
| 1896 | ? mBoundApplication.processName : null) |
| 1897 | + ")"); |
| 1898 | packageInfo = |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 1899 | new LoadedApk(this, aInfo, compatInfo, baseLoader, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1900 | securityViolation, includeCode && |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 1901 | (aInfo.flags&ApplicationInfo.FLAG_HAS_CODE) != 0, registerPackage); |
Narayan Kamath | cb38318 | 2014-10-29 17:56:42 +0000 | [diff] [blame] | 1902 | |
| 1903 | if (mSystemThread && "android".equals(aInfo.packageName)) { |
| 1904 | packageInfo.installSystemApplicationInfo(aInfo, |
| 1905 | getSystemContext().mPackageInfo.getClassLoader()); |
| 1906 | } |
| 1907 | |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 1908 | if (differentUser) { |
| 1909 | // Caching not supported across users |
| 1910 | } else if (includeCode) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1911 | mPackages.put(aInfo.packageName, |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1912 | new WeakReference<LoadedApk>(packageInfo)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1913 | } else { |
| 1914 | mResourcePackages.put(aInfo.packageName, |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1915 | new WeakReference<LoadedApk>(packageInfo)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1916 | } |
| 1917 | } |
| 1918 | return packageInfo; |
| 1919 | } |
| 1920 | } |
| 1921 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1922 | ActivityThread() { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 1923 | mResourcesManager = ResourcesManager.getInstance(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1924 | } |
| 1925 | |
| 1926 | public ApplicationThread getApplicationThread() |
| 1927 | { |
| 1928 | return mAppThread; |
| 1929 | } |
| 1930 | |
| 1931 | public Instrumentation getInstrumentation() |
| 1932 | { |
| 1933 | return mInstrumentation; |
| 1934 | } |
| 1935 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1936 | public boolean isProfiling() { |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 1937 | return mProfiler != null && mProfiler.profileFile != null |
| 1938 | && mProfiler.profileFd == null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1939 | } |
| 1940 | |
| 1941 | public String getProfileFilePath() { |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 1942 | return mProfiler.profileFile; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1943 | } |
| 1944 | |
| 1945 | public Looper getLooper() { |
| 1946 | return mLooper; |
| 1947 | } |
| 1948 | |
| 1949 | public Application getApplication() { |
| 1950 | return mInitialApplication; |
| 1951 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1952 | |
Dianne Hackborn | d97c7ad | 2009-06-19 11:37:35 -0700 | [diff] [blame] | 1953 | public String getProcessName() { |
| 1954 | return mBoundApplication.processName; |
| 1955 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1956 | |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 1957 | public ContextImpl getSystemContext() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1958 | synchronized (this) { |
| 1959 | if (mSystemContext == null) { |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 1960 | mSystemContext = ContextImpl.createSystemContext(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1961 | } |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 1962 | return mSystemContext; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1963 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1964 | } |
| 1965 | |
Narayan Kamath | 29564cd | 2014-08-07 10:57:40 +0100 | [diff] [blame] | 1966 | public void installSystemApplicationInfo(ApplicationInfo info, ClassLoader classLoader) { |
Mike Cleron | 432b713 | 2009-09-24 15:28:29 -0700 | [diff] [blame] | 1967 | synchronized (this) { |
Narayan Kamath | 29564cd | 2014-08-07 10:57:40 +0100 | [diff] [blame] | 1968 | getSystemContext().installSystemApplicationInfo(info, classLoader); |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 1969 | |
| 1970 | // give ourselves a default profiler |
| 1971 | mProfiler = new Profiler(); |
Mike Cleron | 432b713 | 2009-09-24 15:28:29 -0700 | [diff] [blame] | 1972 | } |
| 1973 | } |
| 1974 | |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 1975 | void ensureJitEnabled() { |
| 1976 | if (!mJitEnabled) { |
| 1977 | mJitEnabled = true; |
| 1978 | dalvik.system.VMRuntime.getRuntime().startJitCompilation(); |
| 1979 | } |
| 1980 | } |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 1981 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1982 | void scheduleGcIdler() { |
| 1983 | if (!mGcIdlerScheduled) { |
| 1984 | mGcIdlerScheduled = true; |
| 1985 | Looper.myQueue().addIdleHandler(mGcIdler); |
| 1986 | } |
| 1987 | mH.removeMessages(H.GC_WHEN_IDLE); |
| 1988 | } |
| 1989 | |
| 1990 | void unscheduleGcIdler() { |
| 1991 | if (mGcIdlerScheduled) { |
| 1992 | mGcIdlerScheduled = false; |
| 1993 | Looper.myQueue().removeIdleHandler(mGcIdler); |
| 1994 | } |
| 1995 | mH.removeMessages(H.GC_WHEN_IDLE); |
| 1996 | } |
| 1997 | |
| 1998 | void doGcIfNeeded() { |
| 1999 | mGcIdlerScheduled = false; |
| 2000 | final long now = SystemClock.uptimeMillis(); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2001 | //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] | 2002 | // + "m now=" + now); |
| 2003 | if ((BinderInternal.getLastGcTime()+MIN_TIME_BETWEEN_GCS) < now) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2004 | //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] | 2005 | BinderInternal.forceGc("bg"); |
| 2006 | } |
| 2007 | } |
| 2008 | |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2009 | private static final String HEAP_FULL_COLUMN |
| 2010 | = "%13s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s"; |
| 2011 | private static final String HEAP_COLUMN |
| 2012 | = "%13s %8s %8s %8s %8s %8s %8s %8s"; |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2013 | private static final String ONE_COUNT_COLUMN = "%21s %8d"; |
| 2014 | private static final String TWO_COUNT_COLUMNS = "%21s %8d %21s %8d"; |
| 2015 | private static final String ONE_COUNT_COLUMN_HEADER = "%21s %8s"; |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2016 | |
| 2017 | // Formatting for checkin service - update version if row format changes |
Martijn Coenen | 41f94ed | 2015-12-14 15:28:51 +0100 | [diff] [blame] | 2018 | private static final int ACTIVITY_THREAD_CHECKIN_VERSION = 4; |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2019 | |
| 2020 | static void printRow(PrintWriter pw, String format, Object...objs) { |
| 2021 | pw.println(String.format(format, objs)); |
| 2022 | } |
| 2023 | |
| 2024 | public static void dumpMemInfoTable(PrintWriter pw, Debug.MemoryInfo memInfo, boolean checkin, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2025 | boolean dumpFullInfo, boolean dumpDalvik, boolean dumpSummaryOnly, |
| 2026 | int pid, String processName, |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2027 | long nativeMax, long nativeAllocated, long nativeFree, |
| 2028 | long dalvikMax, long dalvikAllocated, long dalvikFree) { |
| 2029 | |
| 2030 | // For checkin, we print one long comma-separated list of values |
| 2031 | if (checkin) { |
| 2032 | // NOTE: if you change anything significant below, also consider changing |
| 2033 | // ACTIVITY_THREAD_CHECKIN_VERSION. |
| 2034 | |
| 2035 | // Header |
| 2036 | pw.print(ACTIVITY_THREAD_CHECKIN_VERSION); pw.print(','); |
| 2037 | pw.print(pid); pw.print(','); |
| 2038 | pw.print(processName); pw.print(','); |
| 2039 | |
| 2040 | // Heap info - max |
| 2041 | pw.print(nativeMax); pw.print(','); |
| 2042 | pw.print(dalvikMax); pw.print(','); |
| 2043 | pw.print("N/A,"); |
| 2044 | pw.print(nativeMax + dalvikMax); pw.print(','); |
| 2045 | |
| 2046 | // Heap info - allocated |
| 2047 | pw.print(nativeAllocated); pw.print(','); |
| 2048 | pw.print(dalvikAllocated); pw.print(','); |
| 2049 | pw.print("N/A,"); |
| 2050 | pw.print(nativeAllocated + dalvikAllocated); pw.print(','); |
| 2051 | |
| 2052 | // Heap info - free |
| 2053 | pw.print(nativeFree); pw.print(','); |
| 2054 | pw.print(dalvikFree); pw.print(','); |
| 2055 | pw.print("N/A,"); |
| 2056 | pw.print(nativeFree + dalvikFree); pw.print(','); |
| 2057 | |
| 2058 | // Heap info - proportional set size |
| 2059 | pw.print(memInfo.nativePss); pw.print(','); |
| 2060 | pw.print(memInfo.dalvikPss); pw.print(','); |
| 2061 | pw.print(memInfo.otherPss); pw.print(','); |
| 2062 | pw.print(memInfo.getTotalPss()); pw.print(','); |
| 2063 | |
| 2064 | // Heap info - swappable set size |
| 2065 | pw.print(memInfo.nativeSwappablePss); pw.print(','); |
| 2066 | pw.print(memInfo.dalvikSwappablePss); pw.print(','); |
| 2067 | pw.print(memInfo.otherSwappablePss); pw.print(','); |
| 2068 | pw.print(memInfo.getTotalSwappablePss()); pw.print(','); |
| 2069 | |
| 2070 | // Heap info - shared dirty |
| 2071 | pw.print(memInfo.nativeSharedDirty); pw.print(','); |
| 2072 | pw.print(memInfo.dalvikSharedDirty); pw.print(','); |
| 2073 | pw.print(memInfo.otherSharedDirty); pw.print(','); |
| 2074 | pw.print(memInfo.getTotalSharedDirty()); pw.print(','); |
| 2075 | |
| 2076 | // Heap info - shared clean |
| 2077 | pw.print(memInfo.nativeSharedClean); pw.print(','); |
| 2078 | pw.print(memInfo.dalvikSharedClean); pw.print(','); |
| 2079 | pw.print(memInfo.otherSharedClean); pw.print(','); |
| 2080 | pw.print(memInfo.getTotalSharedClean()); pw.print(','); |
| 2081 | |
| 2082 | // Heap info - private Dirty |
| 2083 | pw.print(memInfo.nativePrivateDirty); pw.print(','); |
| 2084 | pw.print(memInfo.dalvikPrivateDirty); pw.print(','); |
| 2085 | pw.print(memInfo.otherPrivateDirty); pw.print(','); |
| 2086 | pw.print(memInfo.getTotalPrivateDirty()); pw.print(','); |
| 2087 | |
| 2088 | // Heap info - private Clean |
| 2089 | pw.print(memInfo.nativePrivateClean); pw.print(','); |
| 2090 | pw.print(memInfo.dalvikPrivateClean); pw.print(','); |
| 2091 | pw.print(memInfo.otherPrivateClean); pw.print(','); |
| 2092 | pw.print(memInfo.getTotalPrivateClean()); pw.print(','); |
| 2093 | |
Martijn Coenen | 41f94ed | 2015-12-14 15:28:51 +0100 | [diff] [blame] | 2094 | // Heap info - swapped out |
| 2095 | pw.print(memInfo.nativeSwappedOut); pw.print(','); |
| 2096 | pw.print(memInfo.dalvikSwappedOut); pw.print(','); |
| 2097 | pw.print(memInfo.otherSwappedOut); pw.print(','); |
| 2098 | pw.print(memInfo.getTotalSwappedOut()); pw.print(','); |
| 2099 | |
| 2100 | // Heap info - swapped out pss |
| 2101 | if (memInfo.hasSwappedOutPss) { |
| 2102 | pw.print(memInfo.nativeSwappedOutPss); pw.print(','); |
| 2103 | pw.print(memInfo.dalvikSwappedOutPss); pw.print(','); |
| 2104 | pw.print(memInfo.otherSwappedOutPss); pw.print(','); |
| 2105 | pw.print(memInfo.getTotalSwappedOutPss()); pw.print(','); |
| 2106 | } else { |
| 2107 | pw.print("N/A,"); |
| 2108 | pw.print("N/A,"); |
| 2109 | pw.print("N/A,"); |
| 2110 | pw.print("N/A,"); |
| 2111 | } |
| 2112 | |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2113 | // Heap info - other areas |
| 2114 | for (int i=0; i<Debug.MemoryInfo.NUM_OTHER_STATS; i++) { |
| 2115 | pw.print(Debug.MemoryInfo.getOtherLabel(i)); pw.print(','); |
| 2116 | pw.print(memInfo.getOtherPss(i)); pw.print(','); |
| 2117 | pw.print(memInfo.getOtherSwappablePss(i)); pw.print(','); |
| 2118 | pw.print(memInfo.getOtherSharedDirty(i)); pw.print(','); |
| 2119 | pw.print(memInfo.getOtherSharedClean(i)); pw.print(','); |
| 2120 | pw.print(memInfo.getOtherPrivateDirty(i)); pw.print(','); |
| 2121 | pw.print(memInfo.getOtherPrivateClean(i)); pw.print(','); |
Martijn Coenen | 41f94ed | 2015-12-14 15:28:51 +0100 | [diff] [blame] | 2122 | pw.print(memInfo.getOtherSwappedOut(i)); pw.print(','); |
| 2123 | if (memInfo.hasSwappedOutPss) { |
| 2124 | pw.print(memInfo.getOtherSwappedOutPss(i)); pw.print(','); |
| 2125 | } else { |
| 2126 | pw.print("N/A,"); |
| 2127 | } |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2128 | } |
| 2129 | return; |
| 2130 | } |
| 2131 | |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2132 | if (!dumpSummaryOnly) { |
| 2133 | if (dumpFullInfo) { |
| 2134 | printRow(pw, HEAP_FULL_COLUMN, "", "Pss", "Pss", "Shared", "Private", |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2135 | "Shared", "Private", memInfo.hasSwappedOutPss ? "SwapPss" : "Swap", |
| 2136 | "Heap", "Heap", "Heap"); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2137 | printRow(pw, HEAP_FULL_COLUMN, "", "Total", "Clean", "Dirty", "Dirty", |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2138 | "Clean", "Clean", "Dirty", |
| 2139 | "Size", "Alloc", "Free"); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2140 | printRow(pw, HEAP_FULL_COLUMN, "", "------", "------", "------", "------", |
| 2141 | "------", "------", "------", "------", "------", "------"); |
| 2142 | printRow(pw, HEAP_FULL_COLUMN, "Native Heap", memInfo.nativePss, |
| 2143 | memInfo.nativeSwappablePss, memInfo.nativeSharedDirty, |
| 2144 | memInfo.nativePrivateDirty, memInfo.nativeSharedClean, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2145 | memInfo.nativePrivateClean, memInfo.hasSwappedOutPss ? |
| 2146 | memInfo.nativeSwappedOut : memInfo.nativeSwappedOutPss, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2147 | nativeMax, nativeAllocated, nativeFree); |
| 2148 | printRow(pw, HEAP_FULL_COLUMN, "Dalvik Heap", memInfo.dalvikPss, |
| 2149 | memInfo.dalvikSwappablePss, memInfo.dalvikSharedDirty, |
| 2150 | memInfo.dalvikPrivateDirty, memInfo.dalvikSharedClean, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2151 | memInfo.dalvikPrivateClean, memInfo.hasSwappedOutPss ? |
| 2152 | memInfo.dalvikSwappedOut : memInfo.dalvikSwappedOutPss, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2153 | dalvikMax, dalvikAllocated, dalvikFree); |
| 2154 | } else { |
| 2155 | printRow(pw, HEAP_COLUMN, "", "Pss", "Private", |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2156 | "Private", memInfo.hasSwappedOutPss ? "SwapPss" : "Swap", |
| 2157 | "Heap", "Heap", "Heap"); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2158 | printRow(pw, HEAP_COLUMN, "", "Total", "Dirty", |
| 2159 | "Clean", "Dirty", "Size", "Alloc", "Free"); |
| 2160 | printRow(pw, HEAP_COLUMN, "", "------", "------", "------", |
| 2161 | "------", "------", "------", "------", "------"); |
| 2162 | printRow(pw, HEAP_COLUMN, "Native Heap", memInfo.nativePss, |
| 2163 | memInfo.nativePrivateDirty, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2164 | memInfo.nativePrivateClean, |
| 2165 | memInfo.hasSwappedOutPss ? memInfo.nativeSwappedOutPss : |
| 2166 | memInfo.nativeSwappedOut, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2167 | nativeMax, nativeAllocated, nativeFree); |
| 2168 | printRow(pw, HEAP_COLUMN, "Dalvik Heap", memInfo.dalvikPss, |
| 2169 | memInfo.dalvikPrivateDirty, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2170 | memInfo.dalvikPrivateClean, |
| 2171 | memInfo.hasSwappedOutPss ? memInfo.dalvikSwappedOutPss : |
| 2172 | memInfo.dalvikSwappedOut, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2173 | dalvikMax, dalvikAllocated, dalvikFree); |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2174 | } |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2175 | |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2176 | int otherPss = memInfo.otherPss; |
| 2177 | int otherSwappablePss = memInfo.otherSwappablePss; |
| 2178 | int otherSharedDirty = memInfo.otherSharedDirty; |
| 2179 | int otherPrivateDirty = memInfo.otherPrivateDirty; |
| 2180 | int otherSharedClean = memInfo.otherSharedClean; |
| 2181 | int otherPrivateClean = memInfo.otherPrivateClean; |
| 2182 | int otherSwappedOut = memInfo.otherSwappedOut; |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2183 | int otherSwappedOutPss = memInfo.otherSwappedOutPss; |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2184 | |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2185 | for (int i=0; i<Debug.MemoryInfo.NUM_OTHER_STATS; i++) { |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2186 | final int myPss = memInfo.getOtherPss(i); |
| 2187 | final int mySwappablePss = memInfo.getOtherSwappablePss(i); |
| 2188 | final int mySharedDirty = memInfo.getOtherSharedDirty(i); |
| 2189 | final int myPrivateDirty = memInfo.getOtherPrivateDirty(i); |
| 2190 | final int mySharedClean = memInfo.getOtherSharedClean(i); |
| 2191 | final int myPrivateClean = memInfo.getOtherPrivateClean(i); |
| 2192 | final int mySwappedOut = memInfo.getOtherSwappedOut(i); |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2193 | final int mySwappedOutPss = memInfo.getOtherSwappedOutPss(i); |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2194 | if (myPss != 0 || mySharedDirty != 0 || myPrivateDirty != 0 |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2195 | || mySharedClean != 0 || myPrivateClean != 0 |
| 2196 | || (memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut) != 0) { |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2197 | if (dumpFullInfo) { |
| 2198 | printRow(pw, HEAP_FULL_COLUMN, Debug.MemoryInfo.getOtherLabel(i), |
| 2199 | myPss, mySwappablePss, mySharedDirty, myPrivateDirty, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2200 | mySharedClean, myPrivateClean, |
| 2201 | memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut, |
| 2202 | "", "", ""); |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2203 | } else { |
| 2204 | printRow(pw, HEAP_COLUMN, Debug.MemoryInfo.getOtherLabel(i), |
| 2205 | myPss, myPrivateDirty, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2206 | myPrivateClean, |
| 2207 | memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut, |
| 2208 | "", "", ""); |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2209 | } |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2210 | otherPss -= myPss; |
| 2211 | otherSwappablePss -= mySwappablePss; |
| 2212 | otherSharedDirty -= mySharedDirty; |
| 2213 | otherPrivateDirty -= myPrivateDirty; |
| 2214 | otherSharedClean -= mySharedClean; |
| 2215 | otherPrivateClean -= myPrivateClean; |
| 2216 | otherSwappedOut -= mySwappedOut; |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2217 | otherSwappedOutPss -= mySwappedOutPss; |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2218 | } |
| 2219 | } |
| 2220 | |
| 2221 | if (dumpFullInfo) { |
| 2222 | printRow(pw, HEAP_FULL_COLUMN, "Unknown", otherPss, otherSwappablePss, |
| 2223 | otherSharedDirty, otherPrivateDirty, otherSharedClean, otherPrivateClean, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2224 | memInfo.hasSwappedOutPss ? otherSwappedOutPss : otherSwappedOut, |
| 2225 | "", "", ""); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2226 | printRow(pw, HEAP_FULL_COLUMN, "TOTAL", memInfo.getTotalPss(), |
| 2227 | memInfo.getTotalSwappablePss(), |
| 2228 | memInfo.getTotalSharedDirty(), memInfo.getTotalPrivateDirty(), |
| 2229 | memInfo.getTotalSharedClean(), memInfo.getTotalPrivateClean(), |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2230 | memInfo.hasSwappedOutPss ? memInfo.getTotalSwappedOut() : |
| 2231 | memInfo.getTotalSwappedOutPss(), |
| 2232 | nativeMax+dalvikMax, nativeAllocated+dalvikAllocated, |
| 2233 | nativeFree+dalvikFree); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2234 | } else { |
| 2235 | printRow(pw, HEAP_COLUMN, "Unknown", otherPss, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2236 | otherPrivateDirty, otherPrivateClean, |
| 2237 | memInfo.hasSwappedOutPss ? otherSwappedOutPss : otherSwappedOut, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2238 | "", "", ""); |
| 2239 | printRow(pw, HEAP_COLUMN, "TOTAL", memInfo.getTotalPss(), |
| 2240 | memInfo.getTotalPrivateDirty(), |
| 2241 | memInfo.getTotalPrivateClean(), |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2242 | memInfo.hasSwappedOutPss ? memInfo.getTotalSwappedOutPss() : |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2243 | memInfo.getTotalSwappedOut(), |
| 2244 | nativeMax+dalvikMax, |
| 2245 | nativeAllocated+dalvikAllocated, nativeFree+dalvikFree); |
| 2246 | } |
| 2247 | |
| 2248 | if (dumpDalvik) { |
| 2249 | pw.println(" "); |
| 2250 | pw.println(" Dalvik Details"); |
| 2251 | |
| 2252 | for (int i=Debug.MemoryInfo.NUM_OTHER_STATS; |
| 2253 | i<Debug.MemoryInfo.NUM_OTHER_STATS + Debug.MemoryInfo.NUM_DVK_STATS; i++) { |
| 2254 | final int myPss = memInfo.getOtherPss(i); |
| 2255 | final int mySwappablePss = memInfo.getOtherSwappablePss(i); |
| 2256 | final int mySharedDirty = memInfo.getOtherSharedDirty(i); |
| 2257 | final int myPrivateDirty = memInfo.getOtherPrivateDirty(i); |
| 2258 | final int mySharedClean = memInfo.getOtherSharedClean(i); |
| 2259 | final int myPrivateClean = memInfo.getOtherPrivateClean(i); |
| 2260 | final int mySwappedOut = memInfo.getOtherSwappedOut(i); |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2261 | final int mySwappedOutPss = memInfo.getOtherSwappedOutPss(i); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2262 | if (myPss != 0 || mySharedDirty != 0 || myPrivateDirty != 0 |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2263 | || mySharedClean != 0 || myPrivateClean != 0 |
| 2264 | || (memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut) != 0) { |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2265 | if (dumpFullInfo) { |
| 2266 | printRow(pw, HEAP_FULL_COLUMN, Debug.MemoryInfo.getOtherLabel(i), |
| 2267 | myPss, mySwappablePss, mySharedDirty, myPrivateDirty, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2268 | mySharedClean, myPrivateClean, |
| 2269 | memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut, |
| 2270 | "", "", ""); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2271 | } else { |
| 2272 | printRow(pw, HEAP_COLUMN, Debug.MemoryInfo.getOtherLabel(i), |
| 2273 | myPss, myPrivateDirty, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2274 | myPrivateClean, |
| 2275 | memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut, |
| 2276 | "", "", ""); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2277 | } |
| 2278 | } |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2279 | } |
| 2280 | } |
| 2281 | } |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2282 | |
| 2283 | pw.println(" "); |
| 2284 | pw.println(" App Summary"); |
| 2285 | printRow(pw, ONE_COUNT_COLUMN_HEADER, "", "Pss(KB)"); |
| 2286 | printRow(pw, ONE_COUNT_COLUMN_HEADER, "", "------"); |
| 2287 | printRow(pw, ONE_COUNT_COLUMN, |
| 2288 | "Java Heap:", memInfo.getSummaryJavaHeap()); |
| 2289 | printRow(pw, ONE_COUNT_COLUMN, |
| 2290 | "Native Heap:", memInfo.getSummaryNativeHeap()); |
| 2291 | printRow(pw, ONE_COUNT_COLUMN, |
| 2292 | "Code:", memInfo.getSummaryCode()); |
| 2293 | printRow(pw, ONE_COUNT_COLUMN, |
| 2294 | "Stack:", memInfo.getSummaryStack()); |
| 2295 | printRow(pw, ONE_COUNT_COLUMN, |
| 2296 | "Graphics:", memInfo.getSummaryGraphics()); |
| 2297 | printRow(pw, ONE_COUNT_COLUMN, |
| 2298 | "Private Other:", memInfo.getSummaryPrivateOther()); |
| 2299 | printRow(pw, ONE_COUNT_COLUMN, |
| 2300 | "System:", memInfo.getSummarySystem()); |
| 2301 | pw.println(" "); |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2302 | if (memInfo.hasSwappedOutPss) { |
| 2303 | printRow(pw, TWO_COUNT_COLUMNS, |
| 2304 | "TOTAL:", memInfo.getSummaryTotalPss(), |
| 2305 | "TOTAL SWAP PSS:", memInfo.getSummaryTotalSwapPss()); |
| 2306 | } else { |
| 2307 | printRow(pw, TWO_COUNT_COLUMNS, |
| 2308 | "TOTAL:", memInfo.getSummaryTotalPss(), |
| 2309 | "TOTAL SWAP (KB):", memInfo.getSummaryTotalSwap()); |
| 2310 | } |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2311 | } |
| 2312 | |
Jeff Hamilton | 52d3203 | 2011-01-08 15:31:26 -0600 | [diff] [blame] | 2313 | public void registerOnActivityPausedListener(Activity activity, |
| 2314 | OnActivityPausedListener listener) { |
| 2315 | synchronized (mOnPauseListeners) { |
| 2316 | ArrayList<OnActivityPausedListener> list = mOnPauseListeners.get(activity); |
| 2317 | if (list == null) { |
| 2318 | list = new ArrayList<OnActivityPausedListener>(); |
| 2319 | mOnPauseListeners.put(activity, list); |
| 2320 | } |
| 2321 | list.add(listener); |
| 2322 | } |
| 2323 | } |
| 2324 | |
Jeff Hamilton | ce3224c | 2011-01-17 11:05:03 -0800 | [diff] [blame] | 2325 | public void unregisterOnActivityPausedListener(Activity activity, |
| 2326 | OnActivityPausedListener listener) { |
| 2327 | synchronized (mOnPauseListeners) { |
| 2328 | ArrayList<OnActivityPausedListener> list = mOnPauseListeners.get(activity); |
| 2329 | if (list != null) { |
| 2330 | list.remove(listener); |
| 2331 | } |
| 2332 | } |
| 2333 | } |
| 2334 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2335 | public final ActivityInfo resolveActivityInfo(Intent intent) { |
| 2336 | ActivityInfo aInfo = intent.resolveActivityInfo( |
| 2337 | mInitialApplication.getPackageManager(), PackageManager.GET_SHARED_LIBRARY_FILES); |
| 2338 | if (aInfo == null) { |
| 2339 | // Throw an exception. |
| 2340 | Instrumentation.checkStartActivityResult( |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 2341 | ActivityManager.START_CLASS_NOT_FOUND, intent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2342 | } |
| 2343 | return aInfo; |
| 2344 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2345 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2346 | public final Activity startActivityNow(Activity parent, String id, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2347 | Intent intent, ActivityInfo activityInfo, IBinder token, Bundle state, |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 2348 | Activity.NonConfigurationInstances lastNonConfigurationInstances) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2349 | ActivityClientRecord r = new ActivityClientRecord(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2350 | r.token = token; |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 2351 | r.ident = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2352 | r.intent = intent; |
| 2353 | r.state = state; |
| 2354 | r.parent = parent; |
| 2355 | r.embeddedID = id; |
| 2356 | r.activityInfo = activityInfo; |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 2357 | r.lastNonConfigurationInstances = lastNonConfigurationInstances; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2358 | if (localLOGV) { |
| 2359 | ComponentName compname = intent.getComponent(); |
| 2360 | String name; |
| 2361 | if (compname != null) { |
| 2362 | name = compname.toShortString(); |
| 2363 | } else { |
| 2364 | name = "(Intent " + intent + ").getComponent() returned null"; |
| 2365 | } |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2366 | Slog.v(TAG, "Performing launch: action=" + intent.getAction() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2367 | + ", comp=" + name |
| 2368 | + ", token=" + token); |
| 2369 | } |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 2370 | return performLaunchActivity(r, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2371 | } |
| 2372 | |
| 2373 | public final Activity getActivity(IBinder token) { |
| 2374 | return mActivities.get(token).activity; |
| 2375 | } |
| 2376 | |
| 2377 | public final void sendActivityResult( |
| 2378 | IBinder token, String id, int requestCode, |
| 2379 | int resultCode, Intent data) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2380 | if (DEBUG_RESULTS) Slog.v(TAG, "sendActivityResult: id=" + id |
Chris Tate | 8a7dc17 | 2009-03-24 20:11:42 -0700 | [diff] [blame] | 2381 | + " req=" + requestCode + " res=" + resultCode + " data=" + data); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2382 | ArrayList<ResultInfo> list = new ArrayList<ResultInfo>(); |
| 2383 | list.add(new ResultInfo(id, requestCode, resultCode, data)); |
| 2384 | mAppThread.scheduleSendResult(token, list); |
| 2385 | } |
| 2386 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 2387 | private void sendMessage(int what, Object obj) { |
| 2388 | sendMessage(what, obj, 0, 0, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2389 | } |
| 2390 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 2391 | private void sendMessage(int what, Object obj, int arg1) { |
| 2392 | sendMessage(what, obj, arg1, 0, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2393 | } |
| 2394 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 2395 | private void sendMessage(int what, Object obj, int arg1, int arg2) { |
| 2396 | sendMessage(what, obj, arg1, arg2, false); |
| 2397 | } |
| 2398 | |
| 2399 | private void sendMessage(int what, Object obj, int arg1, int arg2, boolean async) { |
| 2400 | if (DEBUG_MESSAGES) Slog.v( |
| 2401 | TAG, "SCHEDULE " + what + " " + mH.codeToString(what) |
| 2402 | + ": " + arg1 + " / " + obj); |
| 2403 | Message msg = Message.obtain(); |
| 2404 | msg.what = what; |
| 2405 | msg.obj = obj; |
| 2406 | msg.arg1 = arg1; |
| 2407 | msg.arg2 = arg2; |
| 2408 | if (async) { |
| 2409 | msg.setAsynchronous(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2410 | } |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 2411 | mH.sendMessage(msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2412 | } |
| 2413 | |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 2414 | private void sendMessage(int what, Object obj, int arg1, int arg2, int seq) { |
| 2415 | if (DEBUG_MESSAGES) Slog.v( |
| 2416 | TAG, "SCHEDULE " + mH.codeToString(what) + " arg1=" + arg1 + " arg2=" + arg2 + |
| 2417 | "seq= " + seq); |
| 2418 | Message msg = Message.obtain(); |
| 2419 | msg.what = what; |
| 2420 | SomeArgs args = SomeArgs.obtain(); |
| 2421 | args.arg1 = obj; |
| 2422 | args.argi1 = arg1; |
| 2423 | args.argi2 = arg2; |
| 2424 | args.argi3 = seq; |
| 2425 | msg.obj = args; |
| 2426 | mH.sendMessage(msg); |
| 2427 | } |
| 2428 | |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 2429 | final void scheduleContextCleanup(ContextImpl context, String who, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2430 | String what) { |
| 2431 | ContextCleanupInfo cci = new ContextCleanupInfo(); |
| 2432 | cci.context = context; |
| 2433 | cci.who = who; |
| 2434 | cci.what = what; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 2435 | sendMessage(H.CLEAN_UP_CONTEXT, cci); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2436 | } |
| 2437 | |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 2438 | private Activity performLaunchActivity(ActivityClientRecord r, Intent customIntent) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2439 | // System.out.println("##### [" + System.currentTimeMillis() + "] ActivityThread.performLaunchActivity(" + r + ")"); |
| 2440 | |
| 2441 | ActivityInfo aInfo = r.activityInfo; |
| 2442 | if (r.packageInfo == null) { |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2443 | r.packageInfo = getPackageInfo(aInfo.applicationInfo, r.compatInfo, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2444 | Context.CONTEXT_INCLUDE_CODE); |
| 2445 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2446 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2447 | ComponentName component = r.intent.getComponent(); |
| 2448 | if (component == null) { |
| 2449 | component = r.intent.resolveActivity( |
| 2450 | mInitialApplication.getPackageManager()); |
| 2451 | r.intent.setComponent(component); |
| 2452 | } |
| 2453 | |
| 2454 | if (r.activityInfo.targetActivity != null) { |
| 2455 | component = new ComponentName(r.activityInfo.packageName, |
| 2456 | r.activityInfo.targetActivity); |
| 2457 | } |
| 2458 | |
| 2459 | Activity activity = null; |
| 2460 | try { |
| 2461 | java.lang.ClassLoader cl = r.packageInfo.getClassLoader(); |
| 2462 | activity = mInstrumentation.newActivity( |
| 2463 | cl, component.getClassName(), r.intent); |
Brad Fitzpatrick | 5f8b5c1 | 2011-01-20 15:12:08 -0800 | [diff] [blame] | 2464 | StrictMode.incrementExpectedActivityCount(activity.getClass()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2465 | r.intent.setExtrasClassLoader(cl); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 2466 | r.intent.prepareToEnterProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2467 | if (r.state != null) { |
| 2468 | r.state.setClassLoader(cl); |
| 2469 | } |
| 2470 | } catch (Exception e) { |
| 2471 | if (!mInstrumentation.onException(activity, e)) { |
| 2472 | throw new RuntimeException( |
| 2473 | "Unable to instantiate activity " + component |
| 2474 | + ": " + e.toString(), e); |
| 2475 | } |
| 2476 | } |
| 2477 | |
| 2478 | try { |
Dianne Hackborn | 0be1f78 | 2009-11-09 12:30:12 -0800 | [diff] [blame] | 2479 | Application app = r.packageInfo.makeApplication(false, mInstrumentation); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2480 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2481 | if (localLOGV) Slog.v(TAG, "Performing launch of " + r); |
| 2482 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2483 | TAG, r + ": app=" + app |
| 2484 | + ", appName=" + app.getPackageName() |
| 2485 | + ", pkg=" + r.packageInfo.getPackageName() |
| 2486 | + ", comp=" + r.intent.getComponent().toShortString() |
| 2487 | + ", dir=" + r.packageInfo.getAppDir()); |
| 2488 | |
| 2489 | if (activity != null) { |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 2490 | Context appContext = createBaseContextForActivity(r, activity); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2491 | CharSequence title = r.activityInfo.loadLabel(appContext.getPackageManager()); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 2492 | Configuration config = new Configuration(mCompatConfiguration); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2493 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Launching activity " |
Dianne Hackborn | dc6b635 | 2009-09-30 14:20:09 -0700 | [diff] [blame] | 2494 | + r.activityInfo.name + " with config " + config); |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 2495 | Window window = null; |
| 2496 | if (r.mPendingRemoveWindow != null && r.mPreserveWindow) { |
| 2497 | window = r.mPendingRemoveWindow; |
| 2498 | r.mPendingRemoveWindow = null; |
| 2499 | r.mPendingRemoveWindowManager = null; |
| 2500 | } |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 2501 | activity.attach(appContext, this, getInstrumentation(), r.token, |
| 2502 | r.ident, app, r.intent, r.activityInfo, title, r.parent, |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 2503 | r.embeddedID, r.lastNonConfigurationInstances, config, |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 2504 | r.referrer, r.voiceInteractor, window); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2505 | |
Christopher Tate | b70f3df | 2009-04-07 16:07:59 -0700 | [diff] [blame] | 2506 | if (customIntent != null) { |
| 2507 | activity.mIntent = customIntent; |
| 2508 | } |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 2509 | r.lastNonConfigurationInstances = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2510 | activity.mStartedActivity = false; |
| 2511 | int theme = r.activityInfo.getThemeResource(); |
| 2512 | if (theme != 0) { |
| 2513 | activity.setTheme(theme); |
| 2514 | } |
| 2515 | |
| 2516 | activity.mCalled = false; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2517 | if (r.isPersistable()) { |
| 2518 | mInstrumentation.callActivityOnCreate(activity, r.state, r.persistentState); |
| 2519 | } else { |
| 2520 | mInstrumentation.callActivityOnCreate(activity, r.state); |
| 2521 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2522 | if (!activity.mCalled) { |
| 2523 | throw new SuperNotCalledException( |
| 2524 | "Activity " + r.intent.getComponent().toShortString() + |
| 2525 | " did not call through to super.onCreate()"); |
| 2526 | } |
| 2527 | r.activity = activity; |
| 2528 | r.stopped = true; |
| 2529 | if (!r.activity.mFinished) { |
| 2530 | activity.performStart(); |
| 2531 | r.stopped = false; |
| 2532 | } |
| 2533 | if (!r.activity.mFinished) { |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2534 | if (r.isPersistable()) { |
| 2535 | if (r.state != null || r.persistentState != null) { |
| 2536 | mInstrumentation.callActivityOnRestoreInstanceState(activity, r.state, |
| 2537 | r.persistentState); |
| 2538 | } |
| 2539 | } else if (r.state != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2540 | mInstrumentation.callActivityOnRestoreInstanceState(activity, r.state); |
| 2541 | } |
| 2542 | } |
| 2543 | if (!r.activity.mFinished) { |
| 2544 | activity.mCalled = false; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2545 | if (r.isPersistable()) { |
| 2546 | mInstrumentation.callActivityOnPostCreate(activity, r.state, |
| 2547 | r.persistentState); |
| 2548 | } else { |
| 2549 | mInstrumentation.callActivityOnPostCreate(activity, r.state); |
| 2550 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2551 | if (!activity.mCalled) { |
| 2552 | throw new SuperNotCalledException( |
| 2553 | "Activity " + r.intent.getComponent().toShortString() + |
| 2554 | " did not call through to super.onPostCreate()"); |
| 2555 | } |
| 2556 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2557 | } |
| 2558 | r.paused = true; |
| 2559 | |
| 2560 | mActivities.put(r.token, r); |
| 2561 | |
| 2562 | } catch (SuperNotCalledException e) { |
| 2563 | throw e; |
| 2564 | |
| 2565 | } catch (Exception e) { |
| 2566 | if (!mInstrumentation.onException(activity, e)) { |
| 2567 | throw new RuntimeException( |
| 2568 | "Unable to start activity " + component |
| 2569 | + ": " + e.toString(), e); |
| 2570 | } |
| 2571 | } |
| 2572 | |
| 2573 | return activity; |
| 2574 | } |
| 2575 | |
Wale Ogunwale | 7c72668 | 2015-02-06 17:34:28 -0800 | [diff] [blame] | 2576 | private Context createBaseContextForActivity(ActivityClientRecord r, final Activity activity) { |
| 2577 | int displayId = Display.DEFAULT_DISPLAY; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2578 | try { |
Craig Mautner | aa7e3ed | 2015-02-17 10:17:21 -0800 | [diff] [blame] | 2579 | displayId = ActivityManagerNative.getDefault().getActivityDisplayId(r.token); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2580 | } catch (RemoteException e) { |
| 2581 | } |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 2582 | |
Wale Ogunwale | 7c72668 | 2015-02-06 17:34:28 -0800 | [diff] [blame] | 2583 | ContextImpl appContext = ContextImpl.createActivityContext( |
| 2584 | this, r.packageInfo, displayId, r.overrideConfig); |
| 2585 | appContext.setOuterContext(activity); |
| 2586 | Context baseContext = appContext; |
| 2587 | |
| 2588 | final DisplayManagerGlobal dm = DisplayManagerGlobal.getInstance(); |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 2589 | // For debugging purposes, if the activity's package name contains the value of |
| 2590 | // the "debug.use-second-display" system property as a substring, then show |
| 2591 | // its content on a secondary display if there is one. |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 2592 | String pkgName = SystemProperties.get("debug.second-display.pkg"); |
| 2593 | if (pkgName != null && !pkgName.isEmpty() |
| 2594 | && r.packageInfo.mPackageName.contains(pkgName)) { |
Wale Ogunwale | 7c72668 | 2015-02-06 17:34:28 -0800 | [diff] [blame] | 2595 | for (int id : dm.getDisplayIds()) { |
| 2596 | if (id != Display.DEFAULT_DISPLAY) { |
Wale Ogunwale | 2669851 | 2015-06-05 16:55:33 -0700 | [diff] [blame] | 2597 | Display display = |
| 2598 | dm.getCompatibleDisplay(id, appContext.getDisplayAdjustments(id)); |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 2599 | baseContext = appContext.createDisplayContext(display); |
| 2600 | break; |
| 2601 | } |
| 2602 | } |
| 2603 | } |
| 2604 | return baseContext; |
| 2605 | } |
| 2606 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 2607 | private void handleLaunchActivity(ActivityClientRecord r, Intent customIntent) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2608 | // If we are getting ready to gc after going to the background, well |
| 2609 | // we are back active so skip it. |
| 2610 | unscheduleGcIdler(); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 2611 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2612 | |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 2613 | if (r.profilerInfo != null) { |
| 2614 | mProfiler.setProfiler(r.profilerInfo); |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 2615 | mProfiler.startProfiling(); |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 2616 | } |
| 2617 | |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 2618 | // Make sure we are running with the most recent config. |
| 2619 | handleConfigurationChanged(null, null); |
| 2620 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2621 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2622 | TAG, "Handling launch of " + r); |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 2623 | |
Chet Haase | 0d1c27a | 2014-11-03 18:35:16 +0000 | [diff] [blame] | 2624 | // Initialize before creating the activity |
| 2625 | WindowManagerGlobal.initialize(); |
| 2626 | |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 2627 | Activity a = performLaunchActivity(r, customIntent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2628 | |
| 2629 | if (a != null) { |
Dianne Hackborn | 871ecdc | 2009-12-11 15:24:33 -0800 | [diff] [blame] | 2630 | r.createdConfig = new Configuration(mConfiguration); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 2631 | reportSizeConfigurations(r); |
Dianne Hackborn | 9e0f5d9 | 2010-02-22 15:05:42 -0800 | [diff] [blame] | 2632 | Bundle oldState = r.state; |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 2633 | handleResumeActivity(r.token, false, r.isForward, |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 2634 | !r.activity.mFinished && !r.startsNotResumed, r.lastProcessedSeq); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2635 | |
| 2636 | if (!r.activity.mFinished && r.startsNotResumed) { |
| 2637 | // The activity manager actually wants this one to start out |
| 2638 | // paused, because it needs to be visible but isn't in the |
| 2639 | // foreground. We accomplish this by going through the |
| 2640 | // normal startup (because activities expect to go through |
| 2641 | // onResume() the first time they run, before their window |
| 2642 | // is displayed), and then pausing it. However, in this case |
| 2643 | // we do -not- need to do the full pause cycle (of freezing |
| 2644 | // and such) because the activity manager assumes it can just |
| 2645 | // retain the current state it has. |
| 2646 | try { |
| 2647 | r.activity.mCalled = false; |
| 2648 | mInstrumentation.callActivityOnPause(r.activity); |
Dianne Hackborn | 9e0f5d9 | 2010-02-22 15:05:42 -0800 | [diff] [blame] | 2649 | // We need to keep around the original state, in case |
Dianne Hackborn | 03fcc33 | 2012-05-15 12:49:40 -0700 | [diff] [blame] | 2650 | // we need to be created again. But we only do this |
| 2651 | // for pre-Honeycomb apps, which always save their state |
| 2652 | // when pausing, so we can not have them save their state |
| 2653 | // when restarting from a paused state. For HC and later, |
| 2654 | // we want to (and can) let the state be saved as the normal |
| 2655 | // part of stopping the activity. |
| 2656 | if (r.isPreHoneycomb()) { |
| 2657 | r.state = oldState; |
| 2658 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2659 | if (!r.activity.mCalled) { |
| 2660 | throw new SuperNotCalledException( |
| 2661 | "Activity " + r.intent.getComponent().toShortString() + |
| 2662 | " did not call through to super.onPause()"); |
| 2663 | } |
| 2664 | |
| 2665 | } catch (SuperNotCalledException e) { |
| 2666 | throw e; |
| 2667 | |
| 2668 | } catch (Exception e) { |
| 2669 | if (!mInstrumentation.onException(r.activity, e)) { |
| 2670 | throw new RuntimeException( |
| 2671 | "Unable to pause activity " |
| 2672 | + r.intent.getComponent().toShortString() |
| 2673 | + ": " + e.toString(), e); |
| 2674 | } |
| 2675 | } |
| 2676 | r.paused = true; |
| 2677 | } |
| 2678 | } else { |
| 2679 | // If there was an error, for any reason, tell the activity |
| 2680 | // manager to stop us. |
| 2681 | try { |
| 2682 | ActivityManagerNative.getDefault() |
Wale Ogunwale | ba7881c | 2015-08-01 19:28:29 -0700 | [diff] [blame] | 2683 | .finishActivity(r.token, Activity.RESULT_CANCELED, null, |
| 2684 | Activity.DONT_FINISH_TASK_WITH_ACTIVITY); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2685 | } catch (RemoteException ex) { |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 2686 | // Ignore |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2687 | } |
| 2688 | } |
| 2689 | } |
| 2690 | |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 2691 | private void reportSizeConfigurations(ActivityClientRecord r) { |
| 2692 | Configuration[] configurations = r.activity.getResources().getSizeConfigurations(); |
| 2693 | if (configurations == null) { |
| 2694 | return; |
| 2695 | } |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 2696 | SparseIntArray horizontal = new SparseIntArray(); |
| 2697 | SparseIntArray vertical = new SparseIntArray(); |
| 2698 | SparseIntArray smallest = new SparseIntArray(); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 2699 | for (int i = configurations.length - 1; i >= 0; i--) { |
| 2700 | Configuration config = configurations[i]; |
| 2701 | if (config.screenHeightDp != Configuration.SCREEN_HEIGHT_DP_UNDEFINED) { |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 2702 | vertical.put(config.screenHeightDp, 0); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 2703 | } |
| 2704 | if (config.screenWidthDp != Configuration.SCREEN_WIDTH_DP_UNDEFINED) { |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 2705 | horizontal.put(config.screenWidthDp, 0); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 2706 | } |
| 2707 | if (config.smallestScreenWidthDp != Configuration.SMALLEST_SCREEN_WIDTH_DP_UNDEFINED) { |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 2708 | smallest.put(config.smallestScreenWidthDp, 0); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 2709 | } |
| 2710 | } |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 2711 | try { |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 2712 | ActivityManagerNative.getDefault().reportSizeConfigurations(r.token, |
| 2713 | horizontal.copyKeys(), vertical.copyKeys(), smallest.copyKeys()); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 2714 | } catch (RemoteException ex) { |
| 2715 | } |
| 2716 | |
| 2717 | } |
| 2718 | |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 2719 | private void deliverNewIntents(ActivityClientRecord r, List<ReferrerIntent> intents) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2720 | final int N = intents.size(); |
| 2721 | for (int i=0; i<N; i++) { |
Dianne Hackborn | a01a0fa | 2014-12-02 10:33:14 -0800 | [diff] [blame] | 2722 | ReferrerIntent intent = intents.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2723 | intent.setExtrasClassLoader(r.activity.getClassLoader()); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 2724 | intent.prepareToEnterProcess(); |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 2725 | r.activity.mFragments.noteStateNotSaved(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2726 | mInstrumentation.callActivityOnNewIntent(r.activity, intent); |
| 2727 | } |
| 2728 | } |
| 2729 | |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 2730 | public final void performNewIntents(IBinder token, List<ReferrerIntent> intents) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2731 | ActivityClientRecord r = mActivities.get(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2732 | if (r != null) { |
| 2733 | final boolean resumed = !r.paused; |
| 2734 | if (resumed) { |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 2735 | r.activity.mTemporaryPause = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2736 | mInstrumentation.callActivityOnPause(r.activity); |
| 2737 | } |
| 2738 | deliverNewIntents(r, intents); |
| 2739 | if (resumed) { |
Dianne Hackborn | b46ed76 | 2011-06-02 18:33:15 -0700 | [diff] [blame] | 2740 | r.activity.performResume(); |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 2741 | r.activity.mTemporaryPause = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2742 | } |
| 2743 | } |
| 2744 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2745 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 2746 | private void handleNewIntent(NewIntentData data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2747 | performNewIntents(data.token, data.intents); |
| 2748 | } |
| 2749 | |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 2750 | public void handleRequestAssistContextExtras(RequestAssistContextExtras cmd) { |
Dianne Hackborn | 782d498 | 2015-07-08 17:36:37 -0700 | [diff] [blame] | 2751 | if (mLastAssistStructure != null) { |
| 2752 | AssistStructure structure = mLastAssistStructure.get(); |
| 2753 | if (structure != null) { |
| 2754 | structure.clearSendChannel(); |
| 2755 | } |
| 2756 | } |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 2757 | Bundle data = new Bundle(); |
Dianne Hackborn | 09d57fe | 2015-05-27 18:05:52 -0700 | [diff] [blame] | 2758 | AssistStructure structure = null; |
| 2759 | AssistContent content = new AssistContent(); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 2760 | ActivityClientRecord r = mActivities.get(cmd.activityToken); |
Dianne Hackborn | a3acdb3 | 2015-06-08 17:07:40 -0700 | [diff] [blame] | 2761 | Uri referrer = null; |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 2762 | if (r != null) { |
| 2763 | r.activity.getApplication().dispatchOnProvideAssistData(r.activity, data); |
| 2764 | r.activity.onProvideAssistData(data); |
Dianne Hackborn | a3acdb3 | 2015-06-08 17:07:40 -0700 | [diff] [blame] | 2765 | referrer = r.activity.onProvideReferrer(); |
Dianne Hackborn | a83ce1d | 2015-03-11 15:16:13 -0700 | [diff] [blame] | 2766 | if (cmd.requestType == ActivityManager.ASSIST_CONTEXT_FULL) { |
Dianne Hackborn | 09d57fe | 2015-05-27 18:05:52 -0700 | [diff] [blame] | 2767 | structure = new AssistStructure(r.activity); |
Adam Skory | 4aaed14 | 2015-04-22 11:29:31 -0600 | [diff] [blame] | 2768 | Intent activityIntent = r.activity.getIntent(); |
Dianne Hackborn | 09d57fe | 2015-05-27 18:05:52 -0700 | [diff] [blame] | 2769 | if (activityIntent != null && (r.window == null || |
| 2770 | (r.window.getAttributes().flags |
| 2771 | & WindowManager.LayoutParams.FLAG_SECURE) == 0)) { |
Adam Skory | 4aaed14 | 2015-04-22 11:29:31 -0600 | [diff] [blame] | 2772 | Intent intent = new Intent(activityIntent); |
| 2773 | intent.setFlags(intent.getFlags() & ~(Intent.FLAG_GRANT_WRITE_URI_PERMISSION |
| 2774 | | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION)); |
| 2775 | intent.removeUnsafeExtras(); |
Adam Skory | cd70c64 | 2015-06-05 11:41:55 -0600 | [diff] [blame] | 2776 | content.setDefaultIntent(intent); |
Adam Skory | 4aaed14 | 2015-04-22 11:29:31 -0600 | [diff] [blame] | 2777 | } else { |
Adam Skory | cd70c64 | 2015-06-05 11:41:55 -0600 | [diff] [blame] | 2778 | content.setDefaultIntent(new Intent()); |
Adam Skory | 4aaed14 | 2015-04-22 11:29:31 -0600 | [diff] [blame] | 2779 | } |
Dianne Hackborn | a83ce1d | 2015-03-11 15:16:13 -0700 | [diff] [blame] | 2780 | r.activity.onProvideAssistContent(content); |
Dianne Hackborn | a83ce1d | 2015-03-11 15:16:13 -0700 | [diff] [blame] | 2781 | } |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 2782 | } |
Dianne Hackborn | 09d57fe | 2015-05-27 18:05:52 -0700 | [diff] [blame] | 2783 | if (structure == null) { |
| 2784 | structure = new AssistStructure(); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 2785 | } |
Dianne Hackborn | 782d498 | 2015-07-08 17:36:37 -0700 | [diff] [blame] | 2786 | mLastAssistStructure = new WeakReference<>(structure); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 2787 | IActivityManager mgr = ActivityManagerNative.getDefault(); |
| 2788 | try { |
Dianne Hackborn | a3acdb3 | 2015-06-08 17:07:40 -0700 | [diff] [blame] | 2789 | mgr.reportAssistContextExtras(cmd.requestToken, data, structure, content, referrer); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 2790 | } catch (RemoteException e) { |
| 2791 | } |
| 2792 | } |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 2793 | |
| 2794 | public void handleTranslucentConversionComplete(IBinder token, boolean drawComplete) { |
| 2795 | ActivityClientRecord r = mActivities.get(token); |
| 2796 | if (r != null) { |
| 2797 | r.activity.onTranslucentConversionComplete(drawComplete); |
| 2798 | } |
| 2799 | } |
| 2800 | |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 2801 | public void onNewActivityOptions(IBinder token, ActivityOptions options) { |
| 2802 | ActivityClientRecord r = mActivities.get(token); |
| 2803 | if (r != null) { |
| 2804 | r.activity.onNewActivityOptions(options); |
| 2805 | } |
| 2806 | } |
| 2807 | |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 2808 | public void handleCancelVisibleBehind(IBinder token) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 2809 | ActivityClientRecord r = mActivities.get(token); |
| 2810 | if (r != null) { |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 2811 | mSomeActivitiesChanged = true; |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 2812 | final Activity activity = r.activity; |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 2813 | if (activity.mVisibleBehind) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 2814 | activity.mCalled = false; |
Jose Lima | fcf7083 | 2014-08-27 23:09:05 -0700 | [diff] [blame] | 2815 | activity.onVisibleBehindCanceled(); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 2816 | // Tick, tick, tick. The activity has 500 msec to return or it will be destroyed. |
| 2817 | if (!activity.mCalled) { |
| 2818 | throw new SuperNotCalledException("Activity " + activity.getLocalClassName() + |
Jose Lima | fcf7083 | 2014-08-27 23:09:05 -0700 | [diff] [blame] | 2819 | " did not call through to super.onVisibleBehindCanceled()"); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 2820 | } |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 2821 | activity.mVisibleBehind = false; |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 2822 | } |
| 2823 | } |
| 2824 | try { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 2825 | ActivityManagerNative.getDefault().backgroundResourcesReleased(token); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 2826 | } catch (RemoteException e) { |
| 2827 | } |
| 2828 | } |
| 2829 | |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 2830 | public void handleOnBackgroundVisibleBehindChanged(IBinder token, boolean visible) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 2831 | ActivityClientRecord r = mActivities.get(token); |
| 2832 | if (r != null) { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 2833 | r.activity.onBackgroundVisibleBehindChanged(visible); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 2834 | } |
| 2835 | } |
| 2836 | |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 2837 | public void handleInstallProvider(ProviderInfo info) { |
Jeff Sharkey | bb2e2ca | 2014-10-23 11:42:31 -0700 | [diff] [blame] | 2838 | final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); |
| 2839 | try { |
| 2840 | installContentProviders(mInitialApplication, Lists.newArrayList(info)); |
| 2841 | } finally { |
| 2842 | StrictMode.setThreadPolicy(oldPolicy); |
| 2843 | } |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 2844 | } |
| 2845 | |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 2846 | private void handleEnterAnimationComplete(IBinder token) { |
| 2847 | ActivityClientRecord r = mActivities.get(token); |
| 2848 | if (r != null) { |
Filip Gruszczynski | 6eafa90 | 2014-11-14 14:24:37 -0800 | [diff] [blame] | 2849 | r.activity.dispatchEnterAnimationComplete(); |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 2850 | } |
| 2851 | } |
| 2852 | |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 2853 | private void handleStartBinderTracking() { |
| 2854 | Binder.enableTracing(); |
| 2855 | } |
| 2856 | |
| 2857 | private void handleStopBinderTrackingAndDump(ParcelFileDescriptor fd) { |
| 2858 | try { |
| 2859 | Binder.disableTracing(); |
| 2860 | Binder.getTransactionTracker().writeTracesToFile(fd); |
| 2861 | } finally { |
| 2862 | IoUtils.closeQuietly(fd); |
| 2863 | Binder.getTransactionTracker().clearTraces(); |
| 2864 | } |
| 2865 | } |
| 2866 | |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 2867 | private void handleMultiWindowModeChanged(IBinder token, boolean multiWindowMode) { |
| 2868 | final ActivityClientRecord r = mActivities.get(token); |
| 2869 | if (r != null) { |
| 2870 | r.activity.onMultiWindowModeChanged(multiWindowMode); |
| 2871 | } |
| 2872 | } |
| 2873 | |
| 2874 | private void handlePictureInPictureModeChanged(IBinder token, boolean pipMode) { |
| 2875 | final ActivityClientRecord r = mActivities.get(token); |
| 2876 | if (r != null) { |
| 2877 | r.activity.onPictureInPictureModeChanged(pipMode); |
| 2878 | } |
| 2879 | } |
| 2880 | |
Brad Fitzpatrick | bfb1919 | 2010-10-29 15:25:44 -0700 | [diff] [blame] | 2881 | private static final ThreadLocal<Intent> sCurrentBroadcastIntent = new ThreadLocal<Intent>(); |
| 2882 | |
| 2883 | /** |
| 2884 | * Return the Intent that's currently being handled by a |
| 2885 | * BroadcastReceiver on this thread, or null if none. |
| 2886 | * @hide |
| 2887 | */ |
| 2888 | public static Intent getIntentBeingBroadcast() { |
| 2889 | return sCurrentBroadcastIntent.get(); |
| 2890 | } |
| 2891 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 2892 | private void handleReceiver(ReceiverData data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2893 | // If we are getting ready to gc after going to the background, well |
| 2894 | // we are back active so skip it. |
| 2895 | unscheduleGcIdler(); |
| 2896 | |
| 2897 | String component = data.intent.getComponent().getClassName(); |
| 2898 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2899 | LoadedApk packageInfo = getPackageInfoNoCheck( |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2900 | data.info.applicationInfo, data.compatInfo); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2901 | |
| 2902 | IActivityManager mgr = ActivityManagerNative.getDefault(); |
| 2903 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 2904 | BroadcastReceiver receiver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2905 | try { |
| 2906 | java.lang.ClassLoader cl = packageInfo.getClassLoader(); |
| 2907 | data.intent.setExtrasClassLoader(cl); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 2908 | data.intent.prepareToEnterProcess(); |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 2909 | data.setExtrasClassLoader(cl); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2910 | receiver = (BroadcastReceiver)cl.loadClass(component).newInstance(); |
| 2911 | } catch (Exception e) { |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 2912 | if (DEBUG_BROADCAST) Slog.i(TAG, |
| 2913 | "Finishing failed broadcast to " + data.intent.getComponent()); |
| 2914 | data.sendFinished(mgr); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2915 | throw new RuntimeException( |
| 2916 | "Unable to instantiate receiver " + component |
| 2917 | + ": " + e.toString(), e); |
| 2918 | } |
| 2919 | |
| 2920 | try { |
Dianne Hackborn | 0be1f78 | 2009-11-09 12:30:12 -0800 | [diff] [blame] | 2921 | Application app = packageInfo.makeApplication(false, mInstrumentation); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2922 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2923 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2924 | TAG, "Performing receive of " + data.intent |
| 2925 | + ": app=" + app |
| 2926 | + ", appName=" + app.getPackageName() |
| 2927 | + ", pkg=" + packageInfo.getPackageName() |
| 2928 | + ", comp=" + data.intent.getComponent().toShortString() |
| 2929 | + ", dir=" + packageInfo.getAppDir()); |
| 2930 | |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 2931 | ContextImpl context = (ContextImpl)app.getBaseContext(); |
Brad Fitzpatrick | bfb1919 | 2010-10-29 15:25:44 -0700 | [diff] [blame] | 2932 | sCurrentBroadcastIntent.set(data.intent); |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 2933 | receiver.setPendingResult(data); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2934 | receiver.onReceive(context.getReceiverRestrictedContext(), |
| 2935 | data.intent); |
| 2936 | } catch (Exception e) { |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 2937 | if (DEBUG_BROADCAST) Slog.i(TAG, |
| 2938 | "Finishing failed broadcast to " + data.intent.getComponent()); |
| 2939 | data.sendFinished(mgr); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2940 | if (!mInstrumentation.onException(receiver, e)) { |
| 2941 | throw new RuntimeException( |
| 2942 | "Unable to start receiver " + component |
| 2943 | + ": " + e.toString(), e); |
| 2944 | } |
Brad Fitzpatrick | bfb1919 | 2010-10-29 15:25:44 -0700 | [diff] [blame] | 2945 | } finally { |
| 2946 | sCurrentBroadcastIntent.set(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2947 | } |
| 2948 | |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 2949 | if (receiver.getPendingResult() != null) { |
| 2950 | data.finish(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2951 | } |
| 2952 | } |
| 2953 | |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 2954 | // Instantiate a BackupAgent and tell it that it's alive |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 2955 | private void handleCreateBackupAgent(CreateBackupAgentData data) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2956 | if (DEBUG_BACKUP) Slog.v(TAG, "handleCreateBackupAgent: " + data); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 2957 | |
Christopher Tate | 346acb1 | 2012-10-15 19:20:25 -0700 | [diff] [blame] | 2958 | // Sanity check the requested target package's uid against ours |
| 2959 | try { |
| 2960 | PackageInfo requestedPackage = getPackageManager().getPackageInfo( |
| 2961 | data.appInfo.packageName, 0, UserHandle.myUserId()); |
| 2962 | if (requestedPackage.applicationInfo.uid != Process.myUid()) { |
| 2963 | Slog.w(TAG, "Asked to instantiate non-matching package " |
| 2964 | + data.appInfo.packageName); |
| 2965 | return; |
| 2966 | } |
| 2967 | } catch (RemoteException e) { |
| 2968 | Slog.e(TAG, "Can't reach package manager", e); |
| 2969 | return; |
| 2970 | } |
| 2971 | |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 2972 | // no longer idle; we have backup work to do |
| 2973 | unscheduleGcIdler(); |
| 2974 | |
| 2975 | // instantiate the BackupAgent class named in the manifest |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2976 | LoadedApk packageInfo = getPackageInfoNoCheck(data.appInfo, data.compatInfo); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 2977 | String packageName = packageInfo.mPackageName; |
Christopher Tate | 346acb1 | 2012-10-15 19:20:25 -0700 | [diff] [blame] | 2978 | if (packageName == null) { |
| 2979 | Slog.d(TAG, "Asked to create backup agent for nonexistent package"); |
| 2980 | return; |
| 2981 | } |
| 2982 | |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 2983 | String classname = data.appInfo.backupAgentName; |
Christopher Tate | 79ec80d | 2011-06-24 14:58:49 -0700 | [diff] [blame] | 2984 | // full backup operation but no app-supplied agent? use the default implementation |
| 2985 | if (classname == null && (data.backupMode == IApplicationThread.BACKUP_MODE_FULL |
| 2986 | || data.backupMode == IApplicationThread.BACKUP_MODE_RESTORE_FULL)) { |
Christopher Tate | 4a627c7 | 2011-04-01 14:43:32 -0700 | [diff] [blame] | 2987 | classname = "android.app.backup.FullBackupAgent"; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 2988 | } |
Christopher Tate | 4a627c7 | 2011-04-01 14:43:32 -0700 | [diff] [blame] | 2989 | |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 2990 | try { |
Christopher Tate | d1475e0 | 2009-07-09 15:36:17 -0700 | [diff] [blame] | 2991 | IBinder binder = null; |
Christopher Tate | 2e40d11 | 2014-07-15 12:37:38 -0700 | [diff] [blame] | 2992 | BackupAgent agent = mBackupAgents.get(packageName); |
| 2993 | if (agent != null) { |
| 2994 | // reusing the existing instance |
| 2995 | if (DEBUG_BACKUP) { |
| 2996 | Slog.v(TAG, "Reusing existing agent instance"); |
Christopher Tate | d1475e0 | 2009-07-09 15:36:17 -0700 | [diff] [blame] | 2997 | } |
Christopher Tate | 2e40d11 | 2014-07-15 12:37:38 -0700 | [diff] [blame] | 2998 | binder = agent.onBind(); |
| 2999 | } else { |
| 3000 | try { |
| 3001 | if (DEBUG_BACKUP) Slog.v(TAG, "Initializing agent class " + classname); |
| 3002 | |
| 3003 | java.lang.ClassLoader cl = packageInfo.getClassLoader(); |
| 3004 | agent = (BackupAgent) cl.loadClass(classname).newInstance(); |
| 3005 | |
| 3006 | // set up the agent's context |
| 3007 | ContextImpl context = ContextImpl.createAppContext(this, packageInfo); |
| 3008 | context.setOuterContext(agent); |
| 3009 | agent.attach(context); |
| 3010 | |
| 3011 | agent.onCreate(); |
| 3012 | binder = agent.onBind(); |
| 3013 | mBackupAgents.put(packageName, agent); |
| 3014 | } catch (Exception e) { |
| 3015 | // If this is during restore, fail silently; otherwise go |
| 3016 | // ahead and let the user see the crash. |
| 3017 | Slog.e(TAG, "Agent threw during creation: " + e); |
| 3018 | if (data.backupMode != IApplicationThread.BACKUP_MODE_RESTORE |
| 3019 | && data.backupMode != IApplicationThread.BACKUP_MODE_RESTORE_FULL) { |
| 3020 | throw e; |
| 3021 | } |
| 3022 | // falling through with 'binder' still null |
| 3023 | } |
Christopher Tate | d1475e0 | 2009-07-09 15:36:17 -0700 | [diff] [blame] | 3024 | } |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3025 | |
| 3026 | // tell the OS that we're live now |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3027 | try { |
| 3028 | ActivityManagerNative.getDefault().backupAgentCreated(packageName, binder); |
| 3029 | } catch (RemoteException e) { |
| 3030 | // nothing to do. |
| 3031 | } |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3032 | } catch (Exception e) { |
| 3033 | throw new RuntimeException("Unable to create BackupAgent " |
Christopher Tate | 4a627c7 | 2011-04-01 14:43:32 -0700 | [diff] [blame] | 3034 | + classname + ": " + e.toString(), e); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3035 | } |
| 3036 | } |
| 3037 | |
| 3038 | // Tear down a BackupAgent |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3039 | private void handleDestroyBackupAgent(CreateBackupAgentData data) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3040 | if (DEBUG_BACKUP) Slog.v(TAG, "handleDestroyBackupAgent: " + data); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3041 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 3042 | LoadedApk packageInfo = getPackageInfoNoCheck(data.appInfo, data.compatInfo); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3043 | String packageName = packageInfo.mPackageName; |
| 3044 | BackupAgent agent = mBackupAgents.get(packageName); |
| 3045 | if (agent != null) { |
| 3046 | try { |
| 3047 | agent.onDestroy(); |
| 3048 | } catch (Exception e) { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 3049 | 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] | 3050 | e.printStackTrace(); |
| 3051 | } |
| 3052 | mBackupAgents.remove(packageName); |
| 3053 | } else { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 3054 | Slog.w(TAG, "Attempt to destroy unknown backup agent " + data); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3055 | } |
| 3056 | } |
| 3057 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3058 | private void handleCreateService(CreateServiceData data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3059 | // If we are getting ready to gc after going to the background, well |
| 3060 | // we are back active so skip it. |
| 3061 | unscheduleGcIdler(); |
| 3062 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3063 | LoadedApk packageInfo = getPackageInfoNoCheck( |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 3064 | data.info.applicationInfo, data.compatInfo); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3065 | Service service = null; |
| 3066 | try { |
| 3067 | java.lang.ClassLoader cl = packageInfo.getClassLoader(); |
| 3068 | service = (Service) cl.loadClass(data.info.name).newInstance(); |
| 3069 | } catch (Exception e) { |
| 3070 | if (!mInstrumentation.onException(service, e)) { |
| 3071 | throw new RuntimeException( |
| 3072 | "Unable to instantiate service " + data.info.name |
| 3073 | + ": " + e.toString(), e); |
| 3074 | } |
| 3075 | } |
| 3076 | |
| 3077 | try { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3078 | 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] | 3079 | |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 3080 | ContextImpl context = ContextImpl.createAppContext(this, packageInfo); |
| 3081 | context.setOuterContext(service); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3082 | |
Dianne Hackborn | 0be1f78 | 2009-11-09 12:30:12 -0800 | [diff] [blame] | 3083 | Application app = packageInfo.makeApplication(false, mInstrumentation); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3084 | service.attach(context, this, data.info.name, data.token, app, |
| 3085 | ActivityManagerNative.getDefault()); |
| 3086 | service.onCreate(); |
| 3087 | mServices.put(data.token, service); |
| 3088 | try { |
Dianne Hackborn | f6f9f2d | 2009-08-21 16:26:03 -0700 | [diff] [blame] | 3089 | ActivityManagerNative.getDefault().serviceDoneExecuting( |
Dianne Hackborn | 455625e | 2015-01-21 09:55:13 -0800 | [diff] [blame] | 3090 | data.token, SERVICE_DONE_EXECUTING_ANON, 0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3091 | } catch (RemoteException e) { |
| 3092 | // nothing to do. |
| 3093 | } |
| 3094 | } catch (Exception e) { |
| 3095 | if (!mInstrumentation.onException(service, e)) { |
| 3096 | throw new RuntimeException( |
| 3097 | "Unable to create service " + data.info.name |
| 3098 | + ": " + e.toString(), e); |
| 3099 | } |
| 3100 | } |
| 3101 | } |
| 3102 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3103 | private void handleBindService(BindServiceData data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3104 | Service s = mServices.get(data.token); |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 3105 | if (DEBUG_SERVICE) |
| 3106 | Slog.v(TAG, "handleBindService s=" + s + " rebind=" + data.rebind); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3107 | if (s != null) { |
| 3108 | try { |
| 3109 | data.intent.setExtrasClassLoader(s.getClassLoader()); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 3110 | data.intent.prepareToEnterProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3111 | try { |
| 3112 | if (!data.rebind) { |
| 3113 | IBinder binder = s.onBind(data.intent); |
| 3114 | ActivityManagerNative.getDefault().publishService( |
| 3115 | data.token, data.intent, binder); |
| 3116 | } else { |
| 3117 | s.onRebind(data.intent); |
| 3118 | ActivityManagerNative.getDefault().serviceDoneExecuting( |
Dianne Hackborn | 455625e | 2015-01-21 09:55:13 -0800 | [diff] [blame] | 3119 | data.token, SERVICE_DONE_EXECUTING_ANON, 0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3120 | } |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 3121 | ensureJitEnabled(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3122 | } catch (RemoteException ex) { |
| 3123 | } |
| 3124 | } catch (Exception e) { |
| 3125 | if (!mInstrumentation.onException(s, e)) { |
| 3126 | throw new RuntimeException( |
| 3127 | "Unable to bind to service " + s |
| 3128 | + " with " + data.intent + ": " + e.toString(), e); |
| 3129 | } |
| 3130 | } |
| 3131 | } |
| 3132 | } |
| 3133 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3134 | private void handleUnbindService(BindServiceData data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3135 | Service s = mServices.get(data.token); |
| 3136 | if (s != null) { |
| 3137 | try { |
| 3138 | data.intent.setExtrasClassLoader(s.getClassLoader()); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 3139 | data.intent.prepareToEnterProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3140 | boolean doRebind = s.onUnbind(data.intent); |
| 3141 | try { |
| 3142 | if (doRebind) { |
| 3143 | ActivityManagerNative.getDefault().unbindFinished( |
| 3144 | data.token, data.intent, doRebind); |
| 3145 | } else { |
| 3146 | ActivityManagerNative.getDefault().serviceDoneExecuting( |
Dianne Hackborn | 455625e | 2015-01-21 09:55:13 -0800 | [diff] [blame] | 3147 | data.token, SERVICE_DONE_EXECUTING_ANON, 0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3148 | } |
| 3149 | } catch (RemoteException ex) { |
| 3150 | } |
| 3151 | } catch (Exception e) { |
| 3152 | if (!mInstrumentation.onException(s, e)) { |
| 3153 | throw new RuntimeException( |
| 3154 | "Unable to unbind to service " + s |
| 3155 | + " with " + data.intent + ": " + e.toString(), e); |
| 3156 | } |
| 3157 | } |
| 3158 | } |
| 3159 | } |
| 3160 | |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 3161 | private void handleDumpService(DumpComponentInfo info) { |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3162 | final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); |
| 3163 | try { |
| 3164 | Service s = mServices.get(info.token); |
| 3165 | if (s != null) { |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 3166 | PrintWriter pw = new FastPrintWriter(new FileOutputStream( |
| 3167 | info.fd.getFileDescriptor())); |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3168 | s.dump(info.fd.getFileDescriptor(), pw, info.args); |
| 3169 | pw.flush(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3170 | } |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3171 | } finally { |
| 3172 | IoUtils.closeQuietly(info.fd); |
| 3173 | StrictMode.setThreadPolicy(oldPolicy); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3174 | } |
| 3175 | } |
| 3176 | |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 3177 | private void handleDumpActivity(DumpComponentInfo info) { |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3178 | final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); |
| 3179 | try { |
| 3180 | ActivityClientRecord r = mActivities.get(info.token); |
| 3181 | if (r != null && r.activity != null) { |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 3182 | PrintWriter pw = new FastPrintWriter(new FileOutputStream( |
| 3183 | info.fd.getFileDescriptor())); |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3184 | r.activity.dump(info.prefix, info.fd.getFileDescriptor(), pw, info.args); |
| 3185 | pw.flush(); |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 3186 | } |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3187 | } finally { |
| 3188 | IoUtils.closeQuietly(info.fd); |
| 3189 | StrictMode.setThreadPolicy(oldPolicy); |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 3190 | } |
| 3191 | } |
| 3192 | |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 3193 | private void handleDumpProvider(DumpComponentInfo info) { |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3194 | final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); |
| 3195 | try { |
| 3196 | ProviderClientRecord r = mLocalProviders.get(info.token); |
| 3197 | if (r != null && r.mLocalProvider != null) { |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 3198 | PrintWriter pw = new FastPrintWriter(new FileOutputStream( |
| 3199 | info.fd.getFileDescriptor())); |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3200 | r.mLocalProvider.dump(info.fd.getFileDescriptor(), pw, info.args); |
| 3201 | pw.flush(); |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 3202 | } |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3203 | } finally { |
| 3204 | IoUtils.closeQuietly(info.fd); |
| 3205 | StrictMode.setThreadPolicy(oldPolicy); |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 3206 | } |
| 3207 | } |
| 3208 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3209 | private void handleServiceArgs(ServiceArgsData data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3210 | Service s = mServices.get(data.token); |
| 3211 | if (s != null) { |
| 3212 | try { |
| 3213 | if (data.args != null) { |
| 3214 | data.args.setExtrasClassLoader(s.getClassLoader()); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 3215 | data.args.prepareToEnterProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3216 | } |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 3217 | int res; |
| 3218 | if (!data.taskRemoved) { |
| 3219 | res = s.onStartCommand(data.args, data.flags, data.startId); |
| 3220 | } else { |
| 3221 | s.onTaskRemoved(data.args); |
| 3222 | res = Service.START_TASK_REMOVED_COMPLETE; |
| 3223 | } |
Brad Fitzpatrick | 333b8cb | 2010-08-26 12:04:57 -0700 | [diff] [blame] | 3224 | |
| 3225 | QueuedWork.waitToFinish(); |
| 3226 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3227 | try { |
Dianne Hackborn | f6f9f2d | 2009-08-21 16:26:03 -0700 | [diff] [blame] | 3228 | ActivityManagerNative.getDefault().serviceDoneExecuting( |
Dianne Hackborn | 455625e | 2015-01-21 09:55:13 -0800 | [diff] [blame] | 3229 | data.token, SERVICE_DONE_EXECUTING_START, data.startId, res); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3230 | } catch (RemoteException e) { |
| 3231 | // nothing to do. |
| 3232 | } |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 3233 | ensureJitEnabled(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3234 | } catch (Exception e) { |
| 3235 | if (!mInstrumentation.onException(s, e)) { |
| 3236 | throw new RuntimeException( |
| 3237 | "Unable to start service " + s |
| 3238 | + " with " + data.args + ": " + e.toString(), e); |
| 3239 | } |
| 3240 | } |
| 3241 | } |
| 3242 | } |
| 3243 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3244 | private void handleStopService(IBinder token) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3245 | Service s = mServices.remove(token); |
| 3246 | if (s != null) { |
| 3247 | try { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3248 | if (localLOGV) Slog.v(TAG, "Destroying service " + s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3249 | s.onDestroy(); |
| 3250 | Context context = s.getBaseContext(); |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 3251 | if (context instanceof ContextImpl) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3252 | final String who = s.getClassName(); |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 3253 | ((ContextImpl) context).scheduleFinalCleanup(who, "Service"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3254 | } |
Brad Fitzpatrick | 333b8cb | 2010-08-26 12:04:57 -0700 | [diff] [blame] | 3255 | |
| 3256 | QueuedWork.waitToFinish(); |
| 3257 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3258 | try { |
Dianne Hackborn | f6f9f2d | 2009-08-21 16:26:03 -0700 | [diff] [blame] | 3259 | ActivityManagerNative.getDefault().serviceDoneExecuting( |
Dianne Hackborn | 455625e | 2015-01-21 09:55:13 -0800 | [diff] [blame] | 3260 | token, SERVICE_DONE_EXECUTING_STOP, 0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3261 | } catch (RemoteException e) { |
| 3262 | // nothing to do. |
Craig Mautner | 66c4a82 | 2015-01-16 12:48:16 -0800 | [diff] [blame] | 3263 | Slog.i(TAG, "handleStopService: unable to execute serviceDoneExecuting for " |
| 3264 | + token, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3265 | } |
| 3266 | } catch (Exception e) { |
| 3267 | if (!mInstrumentation.onException(s, e)) { |
| 3268 | throw new RuntimeException( |
| 3269 | "Unable to stop service " + s |
| 3270 | + ": " + e.toString(), e); |
| 3271 | } |
Craig Mautner | 66c4a82 | 2015-01-16 12:48:16 -0800 | [diff] [blame] | 3272 | Slog.i(TAG, "handleStopService: exception for " + token, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3273 | } |
Craig Mautner | 9776ad4 | 2015-01-15 14:38:39 -0800 | [diff] [blame] | 3274 | } else { |
| 3275 | Slog.i(TAG, "handleStopService: token=" + token + " not found."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3276 | } |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3277 | //Slog.i(TAG, "Running services: " + mServices); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3278 | } |
| 3279 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3280 | public final ActivityClientRecord performResumeActivity(IBinder token, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3281 | boolean clearHide) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3282 | ActivityClientRecord r = mActivities.get(token); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3283 | if (localLOGV) Slog.v(TAG, "Performing resume of " + r |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3284 | + " finished=" + r.activity.mFinished); |
| 3285 | if (r != null && !r.activity.mFinished) { |
| 3286 | if (clearHide) { |
| 3287 | r.hideForNow = false; |
| 3288 | r.activity.mStartedActivity = false; |
| 3289 | } |
| 3290 | try { |
Dianne Hackborn | 6bdd3a1 | 2015-08-05 15:01:28 -0700 | [diff] [blame] | 3291 | r.activity.onStateNotSaved(); |
Dianne Hackborn | 689586d | 2012-10-01 18:23:04 -0700 | [diff] [blame] | 3292 | r.activity.mFragments.noteStateNotSaved(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3293 | if (r.pendingIntents != null) { |
| 3294 | deliverNewIntents(r, r.pendingIntents); |
| 3295 | r.pendingIntents = null; |
| 3296 | } |
| 3297 | if (r.pendingResults != null) { |
| 3298 | deliverResults(r, r.pendingResults); |
| 3299 | r.pendingResults = null; |
| 3300 | } |
| 3301 | r.activity.performResume(); |
| 3302 | |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 3303 | EventLog.writeEvent(LOG_AM_ON_RESUME_CALLED, |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 3304 | UserHandle.myUserId(), r.activity.getComponentName().getClassName()); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3305 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3306 | r.paused = false; |
| 3307 | r.stopped = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3308 | r.state = null; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3309 | r.persistentState = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3310 | } catch (Exception e) { |
| 3311 | if (!mInstrumentation.onException(r.activity, e)) { |
| 3312 | throw new RuntimeException( |
| 3313 | "Unable to resume activity " |
| 3314 | + r.intent.getComponent().toShortString() |
| 3315 | + ": " + e.toString(), e); |
| 3316 | } |
| 3317 | } |
| 3318 | } |
| 3319 | return r; |
| 3320 | } |
| 3321 | |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 3322 | static final void cleanUpPendingRemoveWindows(ActivityClientRecord r, boolean force) { |
| 3323 | if (r.mPreserveWindow && !force) { |
| 3324 | return; |
| 3325 | } |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 3326 | if (r.mPendingRemoveWindow != null) { |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 3327 | r.mPendingRemoveWindowManager.removeViewImmediate( |
| 3328 | r.mPendingRemoveWindow.getDecorView()); |
| 3329 | IBinder wtoken = r.mPendingRemoveWindow.getDecorView().getWindowToken(); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 3330 | if (wtoken != null) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 3331 | WindowManagerGlobal.getInstance().closeAll(wtoken, |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 3332 | r.activity.getClass().getName(), "Activity"); |
| 3333 | } |
| 3334 | } |
| 3335 | r.mPendingRemoveWindow = null; |
| 3336 | r.mPendingRemoveWindowManager = null; |
| 3337 | } |
| 3338 | |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 3339 | final void handleResumeActivity(IBinder token, |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 3340 | boolean clearHide, boolean isForward, boolean reallyResume, int seq) { |
| 3341 | ActivityClientRecord r = mActivities.get(token); |
| 3342 | if (!checkAndUpdateLifecycleSeq(seq, r, "resumeActivity")) { |
| 3343 | return; |
| 3344 | } |
| 3345 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3346 | // If we are getting ready to gc after going to the background, well |
| 3347 | // we are back active so skip it. |
| 3348 | unscheduleGcIdler(); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3349 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3350 | |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 3351 | // TODO Push resumeArgs into the activity for consideration |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 3352 | r = performResumeActivity(token, clearHide); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3353 | |
| 3354 | if (r != null) { |
| 3355 | final Activity a = r.activity; |
| 3356 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3357 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3358 | TAG, "Resume " + r + " started activity: " + |
| 3359 | a.mStartedActivity + ", hideForNow: " + r.hideForNow |
| 3360 | + ", finished: " + a.mFinished); |
| 3361 | |
| 3362 | final int forwardBit = isForward ? |
| 3363 | WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION : 0; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3364 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3365 | // If the window hasn't yet been added to the window manager, |
| 3366 | // and this guy didn't finish itself or start another activity, |
| 3367 | // then go ahead and add the window. |
Dianne Hackborn | 061d58a | 2010-03-12 15:07:06 -0800 | [diff] [blame] | 3368 | boolean willBeVisible = !a.mStartedActivity; |
| 3369 | if (!willBeVisible) { |
| 3370 | try { |
| 3371 | willBeVisible = ActivityManagerNative.getDefault().willActivityBeVisible( |
| 3372 | a.getActivityToken()); |
| 3373 | } catch (RemoteException e) { |
| 3374 | } |
| 3375 | } |
| 3376 | if (r.window == null && !a.mFinished && willBeVisible) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3377 | r.window = r.activity.getWindow(); |
| 3378 | View decor = r.window.getDecorView(); |
| 3379 | decor.setVisibility(View.INVISIBLE); |
| 3380 | ViewManager wm = a.getWindowManager(); |
| 3381 | WindowManager.LayoutParams l = r.window.getAttributes(); |
| 3382 | a.mDecor = decor; |
| 3383 | l.type = WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
| 3384 | l.softInputMode |= forwardBit; |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 3385 | if (r.mPreserveWindow) { |
| 3386 | a.mWindowAdded = true; |
| 3387 | r.mPreserveWindow = false; |
| 3388 | } |
| 3389 | if (a.mVisibleFromClient && !a.mWindowAdded) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3390 | a.mWindowAdded = true; |
| 3391 | wm.addView(decor, l); |
| 3392 | } |
| 3393 | |
| 3394 | // If the window has already been added, but during resume |
| 3395 | // we started another activity, then don't yet make the |
Dianne Hackborn | 061d58a | 2010-03-12 15:07:06 -0800 | [diff] [blame] | 3396 | // window visible. |
| 3397 | } else if (!willBeVisible) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3398 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3399 | TAG, "Launch " + r + " mStartedActivity set"); |
| 3400 | r.hideForNow = true; |
| 3401 | } |
| 3402 | |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 3403 | // Get rid of anything left hanging around. |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 3404 | cleanUpPendingRemoveWindows(r, false /* force */); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 3405 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3406 | // The window is now visible if it has been added, we are not |
| 3407 | // simply finishing, and we are not starting another activity. |
Dianne Hackborn | 061d58a | 2010-03-12 15:07:06 -0800 | [diff] [blame] | 3408 | if (!r.activity.mFinished && willBeVisible |
Dianne Hackborn | c1e605e | 2009-09-25 17:18:15 -0700 | [diff] [blame] | 3409 | && r.activity.mDecor != null && !r.hideForNow) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3410 | if (r.newConfig != null) { |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 3411 | r.tmpConfig.setTo(r.newConfig); |
| 3412 | if (r.overrideConfig != null) { |
| 3413 | r.tmpConfig.updateFrom(r.overrideConfig); |
| 3414 | } |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3415 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Resuming activity " |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 3416 | + r.activityInfo.name + " with newConfig " + r.tmpConfig); |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 3417 | performConfigurationChanged(r.activity, r.tmpConfig, REPORT_TO_ACTIVITY); |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 3418 | freeTextLayoutCachesIfNeeded(r.activity.mCurrentConfig.diff(r.tmpConfig)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3419 | r.newConfig = null; |
| 3420 | } |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3421 | if (localLOGV) Slog.v(TAG, "Resuming " + r + " with isForward=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3422 | + isForward); |
| 3423 | WindowManager.LayoutParams l = r.window.getAttributes(); |
| 3424 | if ((l.softInputMode |
| 3425 | & WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) |
| 3426 | != forwardBit) { |
| 3427 | l.softInputMode = (l.softInputMode |
| 3428 | & (~WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION)) |
| 3429 | | forwardBit; |
Dianne Hackborn | c1e605e | 2009-09-25 17:18:15 -0700 | [diff] [blame] | 3430 | if (r.activity.mVisibleFromClient) { |
| 3431 | ViewManager wm = a.getWindowManager(); |
| 3432 | View decor = r.window.getDecorView(); |
| 3433 | wm.updateViewLayout(decor, l); |
| 3434 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3435 | } |
| 3436 | r.activity.mVisibleFromServer = true; |
| 3437 | mNumVisibleActivities++; |
| 3438 | if (r.activity.mVisibleFromClient) { |
| 3439 | r.activity.makeVisible(); |
| 3440 | } |
| 3441 | } |
| 3442 | |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 3443 | if (!r.onlyLocalRequest) { |
| 3444 | r.nextIdle = mNewActivities; |
| 3445 | mNewActivities = r; |
| 3446 | if (localLOGV) Slog.v( |
| 3447 | TAG, "Scheduling idle handler for " + r); |
| 3448 | Looper.myQueue().addIdleHandler(new Idler()); |
| 3449 | } |
| 3450 | r.onlyLocalRequest = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3451 | |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 3452 | // Tell the activity manager we have resumed. |
| 3453 | if (reallyResume) { |
| 3454 | try { |
| 3455 | ActivityManagerNative.getDefault().activityResumed(token); |
| 3456 | } catch (RemoteException ex) { |
| 3457 | } |
| 3458 | } |
| 3459 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3460 | } else { |
| 3461 | // If an exception was thrown when trying to resume, then |
| 3462 | // just end this activity. |
| 3463 | try { |
| 3464 | ActivityManagerNative.getDefault() |
Wale Ogunwale | ba7881c | 2015-08-01 19:28:29 -0700 | [diff] [blame] | 3465 | .finishActivity(token, Activity.RESULT_CANCELED, null, |
| 3466 | Activity.DONT_FINISH_TASK_WITH_ACTIVITY); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3467 | } catch (RemoteException ex) { |
| 3468 | } |
| 3469 | } |
| 3470 | } |
| 3471 | |
| 3472 | private int mThumbnailWidth = -1; |
| 3473 | private int mThumbnailHeight = -1; |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3474 | private Bitmap mAvailThumbnailBitmap = null; |
| 3475 | private Canvas mThumbnailCanvas = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3476 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3477 | private Bitmap createThumbnailBitmap(ActivityClientRecord r) { |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3478 | Bitmap thumbnail = mAvailThumbnailBitmap; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3479 | try { |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3480 | if (thumbnail == null) { |
| 3481 | int w = mThumbnailWidth; |
| 3482 | int h; |
| 3483 | if (w < 0) { |
| 3484 | Resources res = r.activity.getResources(); |
Winson Chung | 6784f1c | 2014-05-22 11:22:41 -0700 | [diff] [blame] | 3485 | int wId = com.android.internal.R.dimen.thumbnail_width; |
| 3486 | int hId = com.android.internal.R.dimen.thumbnail_height; |
Winson Chung | fd08622 | 2014-05-13 15:49:42 -0700 | [diff] [blame] | 3487 | mThumbnailWidth = w = res.getDimensionPixelSize(wId); |
| 3488 | mThumbnailHeight = h = res.getDimensionPixelSize(hId); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3489 | } else { |
| 3490 | h = mThumbnailHeight; |
| 3491 | } |
| 3492 | |
| 3493 | // On platforms where we don't want thumbnails, set dims to (0,0) |
| 3494 | if ((w > 0) && (h > 0)) { |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 3495 | thumbnail = Bitmap.createBitmap(r.activity.getResources().getDisplayMetrics(), |
| 3496 | w, h, THUMBNAIL_FORMAT); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3497 | thumbnail.eraseColor(0); |
| 3498 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3499 | } |
| 3500 | |
Dianne Hackborn | fb3806d | 2010-12-09 13:14:12 -0800 | [diff] [blame] | 3501 | if (thumbnail != null) { |
| 3502 | Canvas cv = mThumbnailCanvas; |
| 3503 | if (cv == null) { |
| 3504 | mThumbnailCanvas = cv = new Canvas(); |
| 3505 | } |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 3506 | |
Dianne Hackborn | fb3806d | 2010-12-09 13:14:12 -0800 | [diff] [blame] | 3507 | cv.setBitmap(thumbnail); |
| 3508 | if (!r.activity.onCreateThumbnail(thumbnail, cv)) { |
| 3509 | mAvailThumbnailBitmap = thumbnail; |
| 3510 | thumbnail = null; |
| 3511 | } |
Dianne Hackborn | 6311d0a | 2011-08-02 16:37:58 -0700 | [diff] [blame] | 3512 | cv.setBitmap(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3513 | } |
Jim Miller | 0b2a6d0 | 2010-07-13 18:01:29 -0700 | [diff] [blame] | 3514 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3515 | } catch (Exception e) { |
| 3516 | if (!mInstrumentation.onException(r.activity, e)) { |
| 3517 | throw new RuntimeException( |
| 3518 | "Unable to create thumbnail of " |
| 3519 | + r.intent.getComponent().toShortString() |
| 3520 | + ": " + e.toString(), e); |
| 3521 | } |
| 3522 | thumbnail = null; |
| 3523 | } |
| 3524 | |
| 3525 | return thumbnail; |
| 3526 | } |
| 3527 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3528 | private void handlePauseActivity(IBinder token, boolean finished, |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 3529 | boolean userLeaving, int configChanges, boolean dontReport, int seq) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3530 | ActivityClientRecord r = mActivities.get(token); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 3531 | if (!checkAndUpdateLifecycleSeq(seq, r, "pauseActivity")) { |
| 3532 | return; |
| 3533 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3534 | if (r != null) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3535 | //Slog.v(TAG, "userLeaving=" + userLeaving + " handling pause of " + r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3536 | if (userLeaving) { |
| 3537 | performUserLeavingActivity(r); |
| 3538 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3539 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3540 | r.activity.mConfigChangeFlags |= configChanges; |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3541 | performPauseActivity(token, finished, r.isPreHoneycomb()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3542 | |
Dianne Hackborn | aa93bcd | 2010-10-27 13:57:00 -0700 | [diff] [blame] | 3543 | // Make sure any pending writes are now committed. |
Dianne Hackborn | 5d9d03a | 2011-01-24 13:15:09 -0800 | [diff] [blame] | 3544 | if (r.isPreHoneycomb()) { |
| 3545 | QueuedWork.waitToFinish(); |
| 3546 | } |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 3547 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3548 | // Tell the activity manager we have paused. |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 3549 | if (!dontReport) { |
| 3550 | try { |
| 3551 | ActivityManagerNative.getDefault().activityPaused(token); |
| 3552 | } catch (RemoteException ex) { |
| 3553 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3554 | } |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3555 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3556 | } |
| 3557 | } |
| 3558 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3559 | final void performUserLeavingActivity(ActivityClientRecord r) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3560 | mInstrumentation.callActivityOnUserLeaving(r.activity); |
| 3561 | } |
| 3562 | |
| 3563 | final Bundle performPauseActivity(IBinder token, boolean finished, |
| 3564 | boolean saveState) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3565 | ActivityClientRecord r = mActivities.get(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3566 | return r != null ? performPauseActivity(r, finished, saveState) : null; |
| 3567 | } |
| 3568 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3569 | final Bundle performPauseActivity(ActivityClientRecord r, boolean finished, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3570 | boolean saveState) { |
| 3571 | if (r.paused) { |
| 3572 | if (r.activity.mFinished) { |
| 3573 | // If we are finishing, we won't call onResume() in certain cases. |
| 3574 | // So here we likewise don't want to call onPause() if the activity |
| 3575 | // isn't resumed. |
| 3576 | return null; |
| 3577 | } |
| 3578 | RuntimeException e = new RuntimeException( |
| 3579 | "Performing pause of activity that is not resumed: " |
| 3580 | + r.intent.getComponent().toShortString()); |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 3581 | Slog.e(TAG, e.getMessage(), e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3582 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3583 | if (finished) { |
| 3584 | r.activity.mFinished = true; |
| 3585 | } |
| 3586 | try { |
| 3587 | // Next have the activity save its current state and managed dialogs... |
| 3588 | if (!r.activity.mFinished && saveState) { |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3589 | callCallActivityOnSaveInstanceState(r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3590 | } |
| 3591 | // Now we are idle. |
| 3592 | r.activity.mCalled = false; |
| 3593 | mInstrumentation.callActivityOnPause(r.activity); |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 3594 | EventLog.writeEvent(LOG_AM_ON_PAUSE_CALLED, UserHandle.myUserId(), |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 3595 | r.activity.getComponentName().getClassName()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3596 | if (!r.activity.mCalled) { |
| 3597 | throw new SuperNotCalledException( |
| 3598 | "Activity " + r.intent.getComponent().toShortString() + |
| 3599 | " did not call through to super.onPause()"); |
| 3600 | } |
| 3601 | |
| 3602 | } catch (SuperNotCalledException e) { |
| 3603 | throw e; |
| 3604 | |
| 3605 | } catch (Exception e) { |
| 3606 | if (!mInstrumentation.onException(r.activity, e)) { |
| 3607 | throw new RuntimeException( |
| 3608 | "Unable to pause activity " |
| 3609 | + r.intent.getComponent().toShortString() |
| 3610 | + ": " + e.toString(), e); |
| 3611 | } |
| 3612 | } |
| 3613 | r.paused = true; |
Jeff Hamilton | 52d3203 | 2011-01-08 15:31:26 -0600 | [diff] [blame] | 3614 | |
| 3615 | // Notify any outstanding on paused listeners |
| 3616 | ArrayList<OnActivityPausedListener> listeners; |
| 3617 | synchronized (mOnPauseListeners) { |
| 3618 | listeners = mOnPauseListeners.remove(r.activity); |
| 3619 | } |
| 3620 | int size = (listeners != null ? listeners.size() : 0); |
| 3621 | for (int i = 0; i < size; i++) { |
| 3622 | listeners.get(i).onPaused(r.activity); |
| 3623 | } |
| 3624 | |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3625 | return !r.activity.mFinished && saveState ? r.state : null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3626 | } |
| 3627 | |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3628 | final void performStopActivity(IBinder token, boolean saveState) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3629 | ActivityClientRecord r = mActivities.get(token); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3630 | performStopActivityInner(r, null, false, saveState); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3631 | } |
| 3632 | |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 3633 | private static class StopInfo implements Runnable { |
| 3634 | ActivityClientRecord activity; |
| 3635 | Bundle state; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3636 | PersistableBundle persistentState; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3637 | CharSequence description; |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 3638 | |
| 3639 | @Override public void run() { |
| 3640 | // Tell activity manager we have been stopped. |
| 3641 | try { |
| 3642 | if (DEBUG_MEMORY_TRIM) Slog.v(TAG, "Reporting activity stopped: " + activity); |
| 3643 | ActivityManagerNative.getDefault().activityStopped( |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3644 | activity.token, state, persistentState, description); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 3645 | } catch (RemoteException ex) { |
| 3646 | } |
| 3647 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3648 | } |
| 3649 | |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 3650 | private static final class ProviderRefCount { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 3651 | public final IActivityManager.ContentProviderHolder holder; |
| 3652 | public final ProviderClientRecord client; |
| 3653 | public int stableCount; |
| 3654 | public int unstableCount; |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 3655 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 3656 | // When this is set, the stable and unstable ref counts are 0 and |
| 3657 | // we have a pending operation scheduled to remove the ref count |
| 3658 | // from the activity manager. On the activity manager we are still |
| 3659 | // holding an unstable ref, though it is not reflected in the counts |
| 3660 | // here. |
| 3661 | public boolean removePending; |
| 3662 | |
| 3663 | ProviderRefCount(IActivityManager.ContentProviderHolder inHolder, |
| 3664 | ProviderClientRecord inClient, int sCount, int uCount) { |
| 3665 | holder = inHolder; |
| 3666 | client = inClient; |
| 3667 | stableCount = sCount; |
| 3668 | unstableCount = uCount; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3669 | } |
| 3670 | } |
| 3671 | |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3672 | /** |
| 3673 | * Core implementation of stopping an activity. Note this is a little |
| 3674 | * tricky because the server's meaning of stop is slightly different |
| 3675 | * than our client -- for the server, stop means to save state and give |
| 3676 | * it the result when it is done, but the window may still be visible. |
| 3677 | * For the client, we want to call onStop()/onStart() to indicate when |
| 3678 | * the activity's UI visibillity changes. |
| 3679 | */ |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3680 | private void performStopActivityInner(ActivityClientRecord r, |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3681 | StopInfo info, boolean keepShown, boolean saveState) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3682 | if (localLOGV) Slog.v(TAG, "Performing stop of " + r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3683 | if (r != null) { |
| 3684 | if (!keepShown && r.stopped) { |
| 3685 | if (r.activity.mFinished) { |
| 3686 | // If we are finishing, we won't call onResume() in certain |
| 3687 | // cases. So here we likewise don't want to call onStop() |
| 3688 | // if the activity isn't resumed. |
| 3689 | return; |
| 3690 | } |
| 3691 | RuntimeException e = new RuntimeException( |
| 3692 | "Performing stop of activity that is not resumed: " |
| 3693 | + r.intent.getComponent().toShortString()); |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 3694 | Slog.e(TAG, e.getMessage(), e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3695 | } |
| 3696 | |
| 3697 | if (info != null) { |
| 3698 | try { |
| 3699 | // First create a thumbnail for the activity... |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3700 | // For now, don't create the thumbnail here; we are |
| 3701 | // doing that by doing a screen snapshot. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3702 | info.description = r.activity.onCreateDescription(); |
| 3703 | } catch (Exception e) { |
| 3704 | if (!mInstrumentation.onException(r.activity, e)) { |
| 3705 | throw new RuntimeException( |
| 3706 | "Unable to save state of activity " |
| 3707 | + r.intent.getComponent().toShortString() |
| 3708 | + ": " + e.toString(), e); |
| 3709 | } |
| 3710 | } |
| 3711 | } |
| 3712 | |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3713 | // Next have the activity save its current state and managed dialogs... |
| 3714 | if (!r.activity.mFinished && saveState) { |
| 3715 | if (r.state == null) { |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3716 | callCallActivityOnSaveInstanceState(r); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3717 | } |
| 3718 | } |
| 3719 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3720 | if (!keepShown) { |
| 3721 | try { |
| 3722 | // Now we are idle. |
| 3723 | r.activity.performStop(); |
| 3724 | } catch (Exception e) { |
| 3725 | if (!mInstrumentation.onException(r.activity, e)) { |
| 3726 | throw new RuntimeException( |
| 3727 | "Unable to stop activity " |
| 3728 | + r.intent.getComponent().toShortString() |
| 3729 | + ": " + e.toString(), e); |
| 3730 | } |
| 3731 | } |
| 3732 | r.stopped = true; |
| 3733 | } |
| 3734 | |
| 3735 | r.paused = true; |
| 3736 | } |
| 3737 | } |
| 3738 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3739 | private void updateVisibility(ActivityClientRecord r, boolean show) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3740 | View v = r.activity.mDecor; |
| 3741 | if (v != null) { |
| 3742 | if (show) { |
| 3743 | if (!r.activity.mVisibleFromServer) { |
| 3744 | r.activity.mVisibleFromServer = true; |
| 3745 | mNumVisibleActivities++; |
| 3746 | if (r.activity.mVisibleFromClient) { |
| 3747 | r.activity.makeVisible(); |
| 3748 | } |
| 3749 | } |
| 3750 | if (r.newConfig != null) { |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 3751 | r.tmpConfig.setTo(r.newConfig); |
| 3752 | if (r.overrideConfig != null) { |
| 3753 | r.tmpConfig.updateFrom(r.overrideConfig); |
| 3754 | } |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3755 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Updating activity vis " |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 3756 | + r.activityInfo.name + " with new config " + r.tmpConfig); |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 3757 | performConfigurationChanged(r.activity, r.tmpConfig, REPORT_TO_ACTIVITY); |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 3758 | freeTextLayoutCachesIfNeeded(r.activity.mCurrentConfig.diff(r.tmpConfig)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3759 | r.newConfig = null; |
| 3760 | } |
| 3761 | } else { |
| 3762 | if (r.activity.mVisibleFromServer) { |
| 3763 | r.activity.mVisibleFromServer = false; |
| 3764 | mNumVisibleActivities--; |
| 3765 | v.setVisibility(View.INVISIBLE); |
| 3766 | } |
| 3767 | } |
| 3768 | } |
| 3769 | } |
| 3770 | |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 3771 | private void handleStopActivity(IBinder token, boolean show, int configChanges, int seq) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3772 | ActivityClientRecord r = mActivities.get(token); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 3773 | if (!checkAndUpdateLifecycleSeq(seq, r, "stopActivity")) { |
| 3774 | return; |
| 3775 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3776 | r.activity.mConfigChangeFlags |= configChanges; |
| 3777 | |
| 3778 | StopInfo info = new StopInfo(); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3779 | performStopActivityInner(r, info, show, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3780 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3781 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3782 | TAG, "Finishing stop of " + r + ": show=" + show |
| 3783 | + " win=" + r.window); |
| 3784 | |
| 3785 | updateVisibility(r, show); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3786 | |
Dianne Hackborn | 5d9d03a | 2011-01-24 13:15:09 -0800 | [diff] [blame] | 3787 | // Make sure any pending writes are now committed. |
| 3788 | if (!r.isPreHoneycomb()) { |
| 3789 | QueuedWork.waitToFinish(); |
| 3790 | } |
| 3791 | |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 3792 | // Schedule the call to tell the activity manager we have |
| 3793 | // stopped. We don't do this immediately, because we want to |
| 3794 | // have a chance for any other pending work (in particular memory |
| 3795 | // trim requests) to complete before you tell the activity |
| 3796 | // manager to proceed and allow us to go fully into the background. |
| 3797 | info.activity = r; |
| 3798 | info.state = r.state; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3799 | info.persistentState = r.persistentState; |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 3800 | mH.post(info); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3801 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3802 | } |
| 3803 | |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 3804 | private static boolean checkAndUpdateLifecycleSeq(int seq, ActivityClientRecord r, |
| 3805 | String action) { |
| 3806 | if (r == null) { |
| 3807 | return true; |
| 3808 | } |
| 3809 | if (seq < r.lastProcessedSeq) { |
| 3810 | if (DEBUG_ORDER) Slog.d(TAG, action + " for " + r + " ignored, because seq=" + seq |
| 3811 | + " < mCurrentLifecycleSeq=" + r.lastProcessedSeq); |
| 3812 | return false; |
| 3813 | } |
| 3814 | r.lastProcessedSeq = seq; |
| 3815 | return true; |
| 3816 | } |
| 3817 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3818 | final void performRestartActivity(IBinder token) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3819 | ActivityClientRecord r = mActivities.get(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3820 | if (r.stopped) { |
| 3821 | r.activity.performRestart(); |
| 3822 | r.stopped = false; |
| 3823 | } |
| 3824 | } |
| 3825 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3826 | private void handleWindowVisibility(IBinder token, boolean show) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3827 | ActivityClientRecord r = mActivities.get(token); |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 3828 | |
Dianne Hackborn | bfddc0f | 2010-12-14 11:28:01 -0800 | [diff] [blame] | 3829 | if (r == null) { |
| 3830 | Log.w(TAG, "handleWindowVisibility: no activity for token " + token); |
| 3831 | return; |
| 3832 | } |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 3833 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3834 | if (!show && !r.stopped) { |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3835 | performStopActivityInner(r, null, show, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3836 | } else if (show && r.stopped) { |
| 3837 | // If we are getting ready to gc after going to the background, well |
| 3838 | // we are back active so skip it. |
| 3839 | unscheduleGcIdler(); |
| 3840 | |
| 3841 | r.activity.performRestart(); |
| 3842 | r.stopped = false; |
| 3843 | } |
| 3844 | if (r.activity.mDecor != null) { |
Joe Onorato | 43a1765 | 2011-04-06 19:22:23 -0700 | [diff] [blame] | 3845 | if (false) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3846 | TAG, "Handle window " + r + " visibility: " + show); |
| 3847 | updateVisibility(r, show); |
| 3848 | } |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3849 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3850 | } |
| 3851 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3852 | private void handleSleeping(IBinder token, boolean sleeping) { |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 3853 | ActivityClientRecord r = mActivities.get(token); |
| 3854 | |
| 3855 | if (r == null) { |
Dianne Hackborn | 842e04b | 2011-01-22 13:00:12 -0800 | [diff] [blame] | 3856 | Log.w(TAG, "handleSleeping: no activity for token " + token); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 3857 | return; |
| 3858 | } |
| 3859 | |
| 3860 | if (sleeping) { |
Dianne Hackborn | 842e04b | 2011-01-22 13:00:12 -0800 | [diff] [blame] | 3861 | if (!r.stopped && !r.isPreHoneycomb()) { |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 3862 | try { |
| 3863 | // Now we are idle. |
| 3864 | r.activity.performStop(); |
| 3865 | } catch (Exception e) { |
| 3866 | if (!mInstrumentation.onException(r.activity, e)) { |
| 3867 | throw new RuntimeException( |
| 3868 | "Unable to stop activity " |
| 3869 | + r.intent.getComponent().toShortString() |
| 3870 | + ": " + e.toString(), e); |
| 3871 | } |
| 3872 | } |
| 3873 | r.stopped = true; |
| 3874 | } |
Dianne Hackborn | 5d9d03a | 2011-01-24 13:15:09 -0800 | [diff] [blame] | 3875 | |
| 3876 | // Make sure any pending writes are now committed. |
| 3877 | if (!r.isPreHoneycomb()) { |
| 3878 | QueuedWork.waitToFinish(); |
| 3879 | } |
| 3880 | |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 3881 | // Tell activity manager we slept. |
| 3882 | try { |
| 3883 | ActivityManagerNative.getDefault().activitySlept(r.token); |
| 3884 | } catch (RemoteException ex) { |
| 3885 | } |
| 3886 | } else { |
| 3887 | if (r.stopped && r.activity.mVisibleFromServer) { |
| 3888 | r.activity.performRestart(); |
| 3889 | r.stopped = false; |
| 3890 | } |
| 3891 | } |
| 3892 | } |
| 3893 | |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 3894 | private void handleSetCoreSettings(Bundle coreSettings) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 3895 | synchronized (mResourcesManager) { |
Svetoslav Ganov | 9aa597e | 2011-03-03 18:17:41 -0800 | [diff] [blame] | 3896 | mCoreSettings = coreSettings; |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 3897 | } |
Jon Miranda | 836c0a8 | 2014-08-11 12:32:26 -0700 | [diff] [blame] | 3898 | onCoreSettingsChange(); |
| 3899 | } |
| 3900 | |
| 3901 | private void onCoreSettingsChange() { |
| 3902 | boolean debugViewAttributes = |
| 3903 | mCoreSettings.getInt(Settings.Global.DEBUG_VIEW_ATTRIBUTES, 0) != 0; |
| 3904 | if (debugViewAttributes != View.mDebugViewAttributes) { |
| 3905 | View.mDebugViewAttributes = debugViewAttributes; |
| 3906 | |
| 3907 | // request all activities to relaunch for the changes to take place |
| 3908 | for (Map.Entry<IBinder, ActivityClientRecord> entry : mActivities.entrySet()) { |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 3909 | requestRelaunchActivity(entry.getKey(), null, null, 0, false, null, null, false, |
| 3910 | false /* preserveWindow */); |
Jon Miranda | 836c0a8 | 2014-08-11 12:32:26 -0700 | [diff] [blame] | 3911 | } |
| 3912 | } |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 3913 | } |
| 3914 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 3915 | private void handleUpdatePackageCompatibilityInfo(UpdateCompatibilityData data) { |
| 3916 | LoadedApk apk = peekPackageInfo(data.pkg, false); |
| 3917 | if (apk != null) { |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 3918 | apk.setCompatibilityInfo(data.info); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 3919 | } |
| 3920 | apk = peekPackageInfo(data.pkg, true); |
| 3921 | if (apk != null) { |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 3922 | apk.setCompatibilityInfo(data.info); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 3923 | } |
| 3924 | handleConfigurationChanged(mConfiguration, data.info); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 3925 | WindowManagerGlobal.getInstance().reportNewConfiguration(mConfiguration); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 3926 | } |
| 3927 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3928 | private void deliverResults(ActivityClientRecord r, List<ResultInfo> results) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3929 | final int N = results.size(); |
| 3930 | for (int i=0; i<N; i++) { |
| 3931 | ResultInfo ri = results.get(i); |
| 3932 | try { |
| 3933 | if (ri.mData != null) { |
| 3934 | ri.mData.setExtrasClassLoader(r.activity.getClassLoader()); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 3935 | ri.mData.prepareToEnterProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3936 | } |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3937 | if (DEBUG_RESULTS) Slog.v(TAG, |
Chris Tate | 8a7dc17 | 2009-03-24 20:11:42 -0700 | [diff] [blame] | 3938 | "Delivering result to activity " + r + " : " + ri); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3939 | r.activity.dispatchActivityResult(ri.mResultWho, |
| 3940 | ri.mRequestCode, ri.mResultCode, ri.mData); |
| 3941 | } catch (Exception e) { |
| 3942 | if (!mInstrumentation.onException(r.activity, e)) { |
| 3943 | throw new RuntimeException( |
| 3944 | "Failure delivering result " + ri + " to activity " |
| 3945 | + r.intent.getComponent().toShortString() |
| 3946 | + ": " + e.toString(), e); |
| 3947 | } |
| 3948 | } |
| 3949 | } |
| 3950 | } |
| 3951 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3952 | private void handleSendResult(ResultData res) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3953 | ActivityClientRecord r = mActivities.get(res.token); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3954 | 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] | 3955 | if (r != null) { |
| 3956 | final boolean resumed = !r.paused; |
| 3957 | if (!r.activity.mFinished && r.activity.mDecor != null |
| 3958 | && r.hideForNow && resumed) { |
| 3959 | // We had hidden the activity because it started another |
| 3960 | // one... we have gotten a result back and we are not |
| 3961 | // paused, so make sure our window is visible. |
| 3962 | updateVisibility(r, true); |
| 3963 | } |
| 3964 | if (resumed) { |
| 3965 | try { |
| 3966 | // Now we are idle. |
| 3967 | r.activity.mCalled = false; |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 3968 | r.activity.mTemporaryPause = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3969 | mInstrumentation.callActivityOnPause(r.activity); |
| 3970 | if (!r.activity.mCalled) { |
| 3971 | throw new SuperNotCalledException( |
| 3972 | "Activity " + r.intent.getComponent().toShortString() |
| 3973 | + " did not call through to super.onPause()"); |
| 3974 | } |
| 3975 | } catch (SuperNotCalledException e) { |
| 3976 | throw e; |
| 3977 | } catch (Exception e) { |
| 3978 | if (!mInstrumentation.onException(r.activity, e)) { |
| 3979 | throw new RuntimeException( |
| 3980 | "Unable to pause activity " |
| 3981 | + r.intent.getComponent().toShortString() |
| 3982 | + ": " + e.toString(), e); |
| 3983 | } |
| 3984 | } |
| 3985 | } |
| 3986 | deliverResults(r, res.results); |
| 3987 | if (resumed) { |
Dianne Hackborn | b46ed76 | 2011-06-02 18:33:15 -0700 | [diff] [blame] | 3988 | r.activity.performResume(); |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 3989 | r.activity.mTemporaryPause = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3990 | } |
| 3991 | } |
| 3992 | } |
| 3993 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3994 | public final ActivityClientRecord performDestroyActivity(IBinder token, boolean finishing) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3995 | return performDestroyActivity(token, finishing, 0, false); |
| 3996 | } |
| 3997 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3998 | private ActivityClientRecord performDestroyActivity(IBinder token, boolean finishing, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3999 | int configChanges, boolean getNonConfigInstance) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4000 | ActivityClientRecord r = mActivities.get(token); |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4001 | Class<? extends Activity> activityClass = null; |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4002 | if (localLOGV) Slog.v(TAG, "Performing finish of " + r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4003 | if (r != null) { |
Brad Fitzpatrick | 5f8b5c1 | 2011-01-20 15:12:08 -0800 | [diff] [blame] | 4004 | activityClass = r.activity.getClass(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4005 | r.activity.mConfigChangeFlags |= configChanges; |
| 4006 | if (finishing) { |
| 4007 | r.activity.mFinished = true; |
| 4008 | } |
| 4009 | if (!r.paused) { |
| 4010 | try { |
| 4011 | r.activity.mCalled = false; |
| 4012 | mInstrumentation.callActivityOnPause(r.activity); |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 4013 | EventLog.writeEvent(LOG_AM_ON_PAUSE_CALLED, UserHandle.myUserId(), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4014 | r.activity.getComponentName().getClassName()); |
| 4015 | if (!r.activity.mCalled) { |
| 4016 | throw new SuperNotCalledException( |
Mitsuru Oshima | d9aef73 | 2009-06-16 20:20:50 -0700 | [diff] [blame] | 4017 | "Activity " + safeToComponentShortString(r.intent) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4018 | + " did not call through to super.onPause()"); |
| 4019 | } |
| 4020 | } catch (SuperNotCalledException e) { |
| 4021 | throw e; |
| 4022 | } catch (Exception e) { |
| 4023 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4024 | throw new RuntimeException( |
| 4025 | "Unable to pause activity " |
Mitsuru Oshima | d9aef73 | 2009-06-16 20:20:50 -0700 | [diff] [blame] | 4026 | + safeToComponentShortString(r.intent) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4027 | + ": " + e.toString(), e); |
| 4028 | } |
| 4029 | } |
| 4030 | r.paused = true; |
| 4031 | } |
| 4032 | if (!r.stopped) { |
| 4033 | try { |
| 4034 | r.activity.performStop(); |
| 4035 | } catch (SuperNotCalledException e) { |
| 4036 | throw e; |
| 4037 | } catch (Exception e) { |
| 4038 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4039 | throw new RuntimeException( |
| 4040 | "Unable to stop activity " |
Mitsuru Oshima | d9aef73 | 2009-06-16 20:20:50 -0700 | [diff] [blame] | 4041 | + safeToComponentShortString(r.intent) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4042 | + ": " + e.toString(), e); |
| 4043 | } |
| 4044 | } |
| 4045 | r.stopped = true; |
| 4046 | } |
| 4047 | if (getNonConfigInstance) { |
| 4048 | try { |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 4049 | r.lastNonConfigurationInstances |
| 4050 | = r.activity.retainNonConfigurationInstances(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4051 | } catch (Exception e) { |
| 4052 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4053 | throw new RuntimeException( |
| 4054 | "Unable to retain activity " |
| 4055 | + r.intent.getComponent().toShortString() |
| 4056 | + ": " + e.toString(), e); |
| 4057 | } |
| 4058 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4059 | } |
| 4060 | try { |
| 4061 | r.activity.mCalled = false; |
Dianne Hackborn | 2dedce6 | 2010-04-15 14:45:25 -0700 | [diff] [blame] | 4062 | mInstrumentation.callActivityOnDestroy(r.activity); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4063 | if (!r.activity.mCalled) { |
| 4064 | throw new SuperNotCalledException( |
Mitsuru Oshima | d9aef73 | 2009-06-16 20:20:50 -0700 | [diff] [blame] | 4065 | "Activity " + safeToComponentShortString(r.intent) + |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4066 | " did not call through to super.onDestroy()"); |
| 4067 | } |
| 4068 | if (r.window != null) { |
| 4069 | r.window.closeAllPanels(); |
| 4070 | } |
| 4071 | } catch (SuperNotCalledException e) { |
| 4072 | throw e; |
| 4073 | } catch (Exception e) { |
| 4074 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4075 | throw new RuntimeException( |
Mitsuru Oshima | d9aef73 | 2009-06-16 20:20:50 -0700 | [diff] [blame] | 4076 | "Unable to destroy activity " + safeToComponentShortString(r.intent) |
| 4077 | + ": " + e.toString(), e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4078 | } |
| 4079 | } |
| 4080 | } |
| 4081 | mActivities.remove(token); |
Brad Fitzpatrick | 5f8b5c1 | 2011-01-20 15:12:08 -0800 | [diff] [blame] | 4082 | StrictMode.decrementExpectedActivityCount(activityClass); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4083 | return r; |
| 4084 | } |
| 4085 | |
Mitsuru Oshima | d9aef73 | 2009-06-16 20:20:50 -0700 | [diff] [blame] | 4086 | private static String safeToComponentShortString(Intent intent) { |
| 4087 | ComponentName component = intent.getComponent(); |
| 4088 | return component == null ? "[Unknown]" : component.toShortString(); |
| 4089 | } |
| 4090 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 4091 | private void handleDestroyActivity(IBinder token, boolean finishing, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4092 | int configChanges, boolean getNonConfigInstance) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4093 | ActivityClientRecord r = performDestroyActivity(token, finishing, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4094 | configChanges, getNonConfigInstance); |
| 4095 | if (r != null) { |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4096 | cleanUpPendingRemoveWindows(r, finishing); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4097 | WindowManager wm = r.activity.getWindowManager(); |
| 4098 | View v = r.activity.mDecor; |
| 4099 | if (v != null) { |
| 4100 | if (r.activity.mVisibleFromServer) { |
| 4101 | mNumVisibleActivities--; |
| 4102 | } |
| 4103 | IBinder wtoken = v.getWindowToken(); |
| 4104 | if (r.activity.mWindowAdded) { |
Filip Gruszczynski | 14418da | 2015-10-04 16:43:48 -0700 | [diff] [blame] | 4105 | if (r.onlyLocalRequest || r.mPreserveWindow) { |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4106 | // Hold off on removing this until the new activity's |
| 4107 | // window is being added. |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4108 | r.mPendingRemoveWindow = r.window; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4109 | r.mPendingRemoveWindowManager = wm; |
Filip Gruszczynski | 14418da | 2015-10-04 16:43:48 -0700 | [diff] [blame] | 4110 | if (r.mPreserveWindow) { |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4111 | // We can only keep the part of the view hierarchy that we control, |
| 4112 | // everything else must be removed, because it might not be able to |
| 4113 | // behave properly when activity is relaunching. |
| 4114 | r.window.clearContentView(); |
| 4115 | } |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4116 | } else { |
| 4117 | wm.removeViewImmediate(v); |
| 4118 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4119 | } |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4120 | if (wtoken != null && r.mPendingRemoveWindow == null) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 4121 | WindowManagerGlobal.getInstance().closeAll(wtoken, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4122 | r.activity.getClass().getName(), "Activity"); |
| 4123 | } |
| 4124 | r.activity.mDecor = null; |
| 4125 | } |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4126 | if (r.mPendingRemoveWindow == null) { |
| 4127 | // If we are delaying the removal of the activity window, then |
| 4128 | // we can't clean up all windows here. Note that we can't do |
| 4129 | // so later either, which means any windows that aren't closed |
| 4130 | // by the app will leak. Well we try to warning them a lot |
| 4131 | // about leaking windows, because that is a bug, so if they are |
| 4132 | // using this recreate facility then they get to live with leaks. |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 4133 | WindowManagerGlobal.getInstance().closeAll(token, |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4134 | r.activity.getClass().getName(), "Activity"); |
| 4135 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4136 | |
| 4137 | // Mocked out contexts won't be participating in the normal |
| 4138 | // process lifecycle, but if we're running with a proper |
| 4139 | // ApplicationContext we need to have it tear down things |
| 4140 | // cleanly. |
| 4141 | Context c = r.activity.getBaseContext(); |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 4142 | if (c instanceof ContextImpl) { |
| 4143 | ((ContextImpl) c).scheduleFinalCleanup( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4144 | r.activity.getClass().getName(), "Activity"); |
| 4145 | } |
| 4146 | } |
| 4147 | if (finishing) { |
| 4148 | try { |
| 4149 | ActivityManagerNative.getDefault().activityDestroyed(token); |
| 4150 | } catch (RemoteException ex) { |
| 4151 | // If the system process has died, it's game over for everyone. |
| 4152 | } |
| 4153 | } |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4154 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4155 | } |
| 4156 | |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4157 | /** |
| 4158 | * @param preserveWindow Whether the activity should try to reuse the window it created, |
| 4159 | * including the decor view after the relaunch. |
| 4160 | */ |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4161 | public final void requestRelaunchActivity(IBinder token, |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 4162 | List<ResultInfo> pendingResults, List<ReferrerIntent> pendingNewIntents, |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4163 | int configChanges, boolean notResumed, Configuration config, |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4164 | Configuration overrideConfig, boolean fromServer, boolean preserveWindow) { |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4165 | ActivityClientRecord target = null; |
| 4166 | |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4167 | synchronized (mResourcesManager) { |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4168 | for (int i=0; i<mRelaunchingActivities.size(); i++) { |
| 4169 | ActivityClientRecord r = mRelaunchingActivities.get(i); |
| 4170 | if (r.token == token) { |
| 4171 | target = r; |
| 4172 | if (pendingResults != null) { |
| 4173 | if (r.pendingResults != null) { |
| 4174 | r.pendingResults.addAll(pendingResults); |
| 4175 | } else { |
| 4176 | r.pendingResults = pendingResults; |
| 4177 | } |
| 4178 | } |
| 4179 | if (pendingNewIntents != null) { |
| 4180 | if (r.pendingIntents != null) { |
| 4181 | r.pendingIntents.addAll(pendingNewIntents); |
| 4182 | } else { |
| 4183 | r.pendingIntents = pendingNewIntents; |
| 4184 | } |
| 4185 | } |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4186 | |
| 4187 | // For each relaunch request, activity manager expects an answer |
| 4188 | if (!r.onlyLocalRequest && fromServer) { |
| 4189 | try { |
| 4190 | ActivityManagerNative.getDefault().activityRelaunched(token); |
| 4191 | } catch (RemoteException e) { |
| 4192 | e.printStackTrace(); |
| 4193 | } |
| 4194 | } |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4195 | break; |
| 4196 | } |
| 4197 | } |
| 4198 | |
| 4199 | if (target == null) { |
| 4200 | target = new ActivityClientRecord(); |
| 4201 | target.token = token; |
| 4202 | target.pendingResults = pendingResults; |
| 4203 | target.pendingIntents = pendingNewIntents; |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4204 | target.mPreserveWindow = preserveWindow; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4205 | if (!fromServer) { |
| 4206 | ActivityClientRecord existing = mActivities.get(token); |
| 4207 | if (existing != null) { |
| 4208 | target.startsNotResumed = existing.paused; |
Wale Ogunwale | 93f543c | 2015-02-17 16:55:03 -0800 | [diff] [blame] | 4209 | target.overrideConfig = existing.overrideConfig; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4210 | } |
| 4211 | target.onlyLocalRequest = true; |
| 4212 | } |
| 4213 | mRelaunchingActivities.add(target); |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 4214 | sendMessage(H.RELAUNCH_ACTIVITY, target); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4215 | } |
| 4216 | |
| 4217 | if (fromServer) { |
| 4218 | target.startsNotResumed = notResumed; |
| 4219 | target.onlyLocalRequest = false; |
| 4220 | } |
| 4221 | if (config != null) { |
| 4222 | target.createdConfig = config; |
| 4223 | } |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 4224 | if (overrideConfig != null) { |
| 4225 | target.overrideConfig = overrideConfig; |
| 4226 | } |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4227 | target.pendingConfigChanges |= configChanges; |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 4228 | target.relaunchSeq = getLifecycleSeq(); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4229 | } |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 4230 | if (DEBUG_ORDER) Slog.d(TAG, "relaunchActivity " + ActivityThread.this |
| 4231 | + " operation received seq: " + target.relaunchSeq); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4232 | } |
| 4233 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 4234 | private void handleRelaunchActivity(ActivityClientRecord tmp) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4235 | // If we are getting ready to gc after going to the background, well |
| 4236 | // we are back active so skip it. |
| 4237 | unscheduleGcIdler(); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4238 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4239 | |
| 4240 | Configuration changedConfig = null; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4241 | int configChanges = 0; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4242 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4243 | // First: make sure we have the most recent configuration and most |
| 4244 | // recent version of the activity, or skip it if some previous call |
| 4245 | // had taken a more recent version. |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4246 | synchronized (mResourcesManager) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4247 | int N = mRelaunchingActivities.size(); |
| 4248 | IBinder token = tmp.token; |
| 4249 | tmp = null; |
| 4250 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4251 | ActivityClientRecord r = mRelaunchingActivities.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4252 | if (r.token == token) { |
| 4253 | tmp = r; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4254 | configChanges |= tmp.pendingConfigChanges; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4255 | mRelaunchingActivities.remove(i); |
| 4256 | i--; |
| 4257 | N--; |
| 4258 | } |
| 4259 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4260 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4261 | if (tmp == null) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4262 | 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] | 4263 | return; |
| 4264 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4265 | |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4266 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Relaunching activity " |
| 4267 | + tmp.token + " with configChanges=0x" |
| 4268 | + Integer.toHexString(configChanges)); |
| 4269 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4270 | if (mPendingConfiguration != null) { |
| 4271 | changedConfig = mPendingConfiguration; |
| 4272 | mPendingConfiguration = null; |
| 4273 | } |
| 4274 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4275 | |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 4276 | if (tmp.lastProcessedSeq > tmp.relaunchSeq) { |
| 4277 | Slog.wtf(TAG, "For some reason target: " + tmp + " has lower sequence: " |
| 4278 | + tmp.relaunchSeq + " than current sequence: " + tmp.lastProcessedSeq); |
| 4279 | } else { |
| 4280 | tmp.lastProcessedSeq = tmp.relaunchSeq; |
| 4281 | } |
Dianne Hackborn | 871ecdc | 2009-12-11 15:24:33 -0800 | [diff] [blame] | 4282 | if (tmp.createdConfig != null) { |
| 4283 | // If the activity manager is passing us its current config, |
| 4284 | // assume that is really what we want regardless of what we |
| 4285 | // may have pending. |
| 4286 | if (mConfiguration == null |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4287 | || (tmp.createdConfig.isOtherSeqNewer(mConfiguration) |
| 4288 | && mConfiguration.diff(tmp.createdConfig) != 0)) { |
| 4289 | if (changedConfig == null |
| 4290 | || tmp.createdConfig.isOtherSeqNewer(changedConfig)) { |
| 4291 | changedConfig = tmp.createdConfig; |
| 4292 | } |
Dianne Hackborn | 871ecdc | 2009-12-11 15:24:33 -0800 | [diff] [blame] | 4293 | } |
| 4294 | } |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 4295 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4296 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Relaunching activity " |
Dianne Hackborn | dc6b635 | 2009-09-30 14:20:09 -0700 | [diff] [blame] | 4297 | + tmp.token + ": changedConfig=" + changedConfig); |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 4298 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4299 | // If there was a pending configuration change, execute it first. |
| 4300 | if (changedConfig != null) { |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 4301 | mCurDefaultDisplayDpi = changedConfig.densityDpi; |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 4302 | updateDefaultDensity(); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4303 | handleConfigurationChanged(changedConfig, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4304 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4305 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4306 | ActivityClientRecord r = mActivities.get(tmp.token); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4307 | 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] | 4308 | if (r == null) { |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4309 | if (!tmp.onlyLocalRequest) { |
| 4310 | try { |
| 4311 | ActivityManagerNative.getDefault().activityRelaunched(tmp.token); |
| 4312 | } catch (RemoteException e) { |
| 4313 | // If the system process has died, it's game over for everyone. |
| 4314 | } |
| 4315 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4316 | return; |
| 4317 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4318 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4319 | r.activity.mConfigChangeFlags |= configChanges; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4320 | r.onlyLocalRequest = tmp.onlyLocalRequest; |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4321 | r.mPreserveWindow = tmp.mPreserveWindow; |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 4322 | r.lastProcessedSeq = tmp.lastProcessedSeq; |
| 4323 | r.relaunchSeq = tmp.relaunchSeq; |
Christopher Tate | b70f3df | 2009-04-07 16:07:59 -0700 | [diff] [blame] | 4324 | Intent currentIntent = r.activity.mIntent; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4325 | |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4326 | r.activity.mChangingConfigurations = true; |
| 4327 | |
Dianne Hackborn | e2b0480 | 2010-12-09 09:24:55 -0800 | [diff] [blame] | 4328 | // Need to ensure state is saved. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4329 | if (!r.paused) { |
Dianne Hackborn | e2b0480 | 2010-12-09 09:24:55 -0800 | [diff] [blame] | 4330 | performPauseActivity(r.token, false, r.isPreHoneycomb()); |
| 4331 | } |
| 4332 | if (r.state == null && !r.stopped && !r.isPreHoneycomb()) { |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 4333 | callCallActivityOnSaveInstanceState(r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4334 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4335 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4336 | handleDestroyActivity(r.token, false, configChanges, true); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4337 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4338 | r.activity = null; |
| 4339 | r.window = null; |
| 4340 | r.hideForNow = false; |
| 4341 | r.nextIdle = null; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4342 | // Merge any pending results and pending intents; don't just replace them |
| 4343 | if (tmp.pendingResults != null) { |
| 4344 | if (r.pendingResults == null) { |
| 4345 | r.pendingResults = tmp.pendingResults; |
| 4346 | } else { |
| 4347 | r.pendingResults.addAll(tmp.pendingResults); |
| 4348 | } |
| 4349 | } |
| 4350 | if (tmp.pendingIntents != null) { |
| 4351 | if (r.pendingIntents == null) { |
| 4352 | r.pendingIntents = tmp.pendingIntents; |
| 4353 | } else { |
| 4354 | r.pendingIntents.addAll(tmp.pendingIntents); |
| 4355 | } |
| 4356 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4357 | r.startsNotResumed = tmp.startsNotResumed; |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 4358 | r.overrideConfig = tmp.overrideConfig; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4359 | |
Christopher Tate | b70f3df | 2009-04-07 16:07:59 -0700 | [diff] [blame] | 4360 | handleLaunchActivity(r, currentIntent); |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4361 | |
| 4362 | if (!tmp.onlyLocalRequest) { |
| 4363 | try { |
| 4364 | ActivityManagerNative.getDefault().activityRelaunched(r.token); |
| 4365 | } catch (RemoteException e) { |
| 4366 | // If the system process has died, it's game over for everyone. |
| 4367 | } |
| 4368 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4369 | } |
| 4370 | |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 4371 | private void callCallActivityOnSaveInstanceState(ActivityClientRecord r) { |
| 4372 | r.state = new Bundle(); |
| 4373 | r.state.setAllowFds(false); |
| 4374 | if (r.isPersistable()) { |
| 4375 | r.persistentState = new PersistableBundle(); |
| 4376 | mInstrumentation.callActivityOnSaveInstanceState(r.activity, r.state, |
| 4377 | r.persistentState); |
| 4378 | } else { |
| 4379 | mInstrumentation.callActivityOnSaveInstanceState(r.activity, r.state); |
| 4380 | } |
| 4381 | } |
| 4382 | |
Dianne Hackborn | 73c1416 | 2012-09-19 15:45:06 -0700 | [diff] [blame] | 4383 | ArrayList<ComponentCallbacks2> collectComponentCallbacks( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4384 | boolean allActivities, Configuration newConfig) { |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 4385 | ArrayList<ComponentCallbacks2> callbacks |
| 4386 | = new ArrayList<ComponentCallbacks2>(); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4387 | |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4388 | synchronized (mResourcesManager) { |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 4389 | final int NAPP = mAllApplications.size(); |
| 4390 | for (int i=0; i<NAPP; i++) { |
Dianne Hackborn | 73c1416 | 2012-09-19 15:45:06 -0700 | [diff] [blame] | 4391 | callbacks.add(mAllApplications.get(i)); |
| 4392 | } |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 4393 | final int NACT = mActivities.size(); |
| 4394 | for (int i=0; i<NACT; i++) { |
| 4395 | ActivityClientRecord ar = mActivities.valueAt(i); |
| 4396 | Activity a = ar.activity; |
| 4397 | if (a != null) { |
| 4398 | Configuration thisConfig = applyConfigCompatMainThread( |
| 4399 | mCurDefaultDisplayDpi, newConfig, |
| 4400 | ar.packageInfo.getCompatibilityInfo()); |
| 4401 | if (!ar.activity.mFinished && (allActivities || !ar.paused)) { |
| 4402 | // If the activity is currently resumed, its configuration |
| 4403 | // needs to change right now. |
| 4404 | callbacks.add(a); |
| 4405 | } else if (thisConfig != null) { |
| 4406 | // Otherwise, we will tell it about the change |
| 4407 | // the next time it is resumed or shown. Note that |
| 4408 | // the activity manager may, before then, decide the |
| 4409 | // activity needs to be destroyed to handle its new |
| 4410 | // configuration. |
| 4411 | if (DEBUG_CONFIGURATION) { |
| 4412 | Slog.v(TAG, "Setting activity " |
| 4413 | + ar.activityInfo.name + " newConfig=" + thisConfig); |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 4414 | } |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 4415 | ar.newConfig = thisConfig; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4416 | } |
| 4417 | } |
| 4418 | } |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 4419 | final int NSVC = mServices.size(); |
| 4420 | for (int i=0; i<NSVC; i++) { |
| 4421 | callbacks.add(mServices.valueAt(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4422 | } |
| 4423 | } |
| 4424 | synchronized (mProviderMap) { |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 4425 | final int NPRV = mLocalProviders.size(); |
| 4426 | for (int i=0; i<NPRV; i++) { |
| 4427 | callbacks.add(mLocalProviders.valueAt(i).mLocalProvider); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4428 | } |
| 4429 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4430 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4431 | return callbacks; |
| 4432 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4433 | |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 4434 | private static void performConfigurationChanged(ComponentCallbacks2 cb, Configuration config, |
| 4435 | boolean reportToActivity) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4436 | // Only for Activity objects, check that they actually call up to their |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 4437 | // superclass implementation. ComponentCallbacks2 is an interface, so |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4438 | // we check the runtime type and act accordingly. |
| 4439 | Activity activity = (cb instanceof Activity) ? (Activity) cb : null; |
| 4440 | if (activity != null) { |
| 4441 | activity.mCalled = false; |
| 4442 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4443 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4444 | boolean shouldChangeConfig = false; |
| 4445 | if ((activity == null) || (activity.mCurrentConfig == null)) { |
| 4446 | shouldChangeConfig = true; |
| 4447 | } else { |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4448 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4449 | // If the new config is the same as the config this Activity |
| 4450 | // is already running with then don't bother calling |
| 4451 | // onConfigurationChanged |
| 4452 | int diff = activity.mCurrentConfig.diff(config); |
| 4453 | if (diff != 0) { |
Wale Ogunwale | 14e811f | 2015-12-14 15:04:22 -0800 | [diff] [blame] | 4454 | // If this activity doesn't handle any of the config changes then don't bother |
| 4455 | // calling onConfigurationChanged as we're going to destroy it. |
| 4456 | // Except in the case where the configuration changed on the activity manager side, |
| 4457 | // but wasn't big enough to cause a resource change so the activity wasn't destroyed. |
| 4458 | // In this case we still want to change the configuration of the activity but not |
| 4459 | // report it to the app. |
| 4460 | if ((~activity.mActivityInfo.getRealConfigChanged() & diff) == 0 |
| 4461 | || !reportToActivity) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4462 | shouldChangeConfig = true; |
| 4463 | } |
| 4464 | } |
| 4465 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4466 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4467 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Config callback " + cb |
Dianne Hackborn | dc6b635 | 2009-09-30 14:20:09 -0700 | [diff] [blame] | 4468 | + ": shouldChangeConfig=" + shouldChangeConfig); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4469 | if (shouldChangeConfig) { |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 4470 | if (reportToActivity) { |
| 4471 | cb.onConfigurationChanged(config); |
| 4472 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4473 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4474 | if (activity != null) { |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 4475 | if (reportToActivity && !activity.mCalled) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4476 | throw new SuperNotCalledException( |
| 4477 | "Activity " + activity.getLocalClassName() + |
| 4478 | " did not call through to super.onConfigurationChanged()"); |
| 4479 | } |
| 4480 | activity.mConfigChangeFlags = 0; |
| 4481 | activity.mCurrentConfig = new Configuration(config); |
| 4482 | } |
| 4483 | } |
| 4484 | } |
| 4485 | |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 4486 | public final void applyConfigurationToResources(Configuration config) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4487 | synchronized (mResourcesManager) { |
| 4488 | mResourcesManager.applyConfigurationToResourcesLocked(config, null); |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 4489 | } |
| 4490 | } |
| 4491 | |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 4492 | final Configuration applyCompatConfiguration(int displayDensity) { |
Dianne Hackborn | 836e262 | 2011-10-04 18:32:39 -0700 | [diff] [blame] | 4493 | Configuration config = mConfiguration; |
| 4494 | if (mCompatConfiguration == null) { |
| 4495 | mCompatConfiguration = new Configuration(); |
| 4496 | } |
| 4497 | mCompatConfiguration.setTo(mConfiguration); |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4498 | if (mResourcesManager.applyCompatConfiguration(displayDensity, mCompatConfiguration)) { |
Dianne Hackborn | 836e262 | 2011-10-04 18:32:39 -0700 | [diff] [blame] | 4499 | config = mCompatConfiguration; |
| 4500 | } |
| 4501 | return config; |
| 4502 | } |
| 4503 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4504 | final void handleConfigurationChanged(Configuration config, CompatibilityInfo compat) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4505 | |
Fabrice Di Meglio | 30ca5cd | 2012-05-07 17:45:44 -0700 | [diff] [blame] | 4506 | int configDiff = 0; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4507 | |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4508 | synchronized (mResourcesManager) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4509 | if (mPendingConfiguration != null) { |
| 4510 | if (!mPendingConfiguration.isOtherSeqNewer(config)) { |
| 4511 | config = mPendingConfiguration; |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 4512 | mCurDefaultDisplayDpi = config.densityDpi; |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 4513 | updateDefaultDensity(); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4514 | } |
| 4515 | mPendingConfiguration = null; |
| 4516 | } |
| 4517 | |
| 4518 | if (config == null) { |
| 4519 | return; |
| 4520 | } |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 4521 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4522 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Handle configuration changed: " |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4523 | + config); |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4524 | |
| 4525 | mResourcesManager.applyConfigurationToResourcesLocked(config, compat); |
| 4526 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4527 | if (mConfiguration == null) { |
| 4528 | mConfiguration = new Configuration(); |
| 4529 | } |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4530 | if (!mConfiguration.isOtherSeqNewer(config) && compat == null) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4531 | return; |
| 4532 | } |
Alan Viverette | e54d245 | 2015-05-06 10:41:43 -0700 | [diff] [blame] | 4533 | |
| 4534 | configDiff = mConfiguration.updateFrom(config); |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 4535 | config = applyCompatConfiguration(mCurDefaultDisplayDpi); |
Alan Viverette | 395cd01 | 2015-08-11 17:27:04 -0400 | [diff] [blame] | 4536 | |
| 4537 | final Theme systemTheme = getSystemContext().getTheme(); |
| 4538 | if ((systemTheme.getChangingConfigurations() & configDiff) != 0) { |
| 4539 | systemTheme.rebase(); |
| 4540 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4541 | } |
Dianne Hackborn | 73c1416 | 2012-09-19 15:45:06 -0700 | [diff] [blame] | 4542 | |
| 4543 | ArrayList<ComponentCallbacks2> callbacks = collectComponentCallbacks(false, config); |
| 4544 | |
Fabrice Di Meglio | 30ca5cd | 2012-05-07 17:45:44 -0700 | [diff] [blame] | 4545 | freeTextLayoutCachesIfNeeded(configDiff); |
| 4546 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4547 | if (callbacks != null) { |
| 4548 | final int N = callbacks.size(); |
| 4549 | for (int i=0; i<N; i++) { |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 4550 | performConfigurationChanged(callbacks.get(i), config, REPORT_TO_ACTIVITY); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4551 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4552 | } |
| 4553 | } |
| 4554 | |
Romain Guy | 46bfc48 | 2013-08-16 18:38:29 -0700 | [diff] [blame] | 4555 | static void freeTextLayoutCachesIfNeeded(int configDiff) { |
Fabrice Di Meglio | 30ca5cd | 2012-05-07 17:45:44 -0700 | [diff] [blame] | 4556 | if (configDiff != 0) { |
| 4557 | // Ask text layout engine to free its caches if there is a locale change |
| 4558 | boolean hasLocaleConfigChange = ((configDiff & ActivityInfo.CONFIG_LOCALE) != 0); |
| 4559 | if (hasLocaleConfigChange) { |
| 4560 | Canvas.freeTextLayoutCaches(); |
| 4561 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Cleared TextLayout Caches"); |
| 4562 | } |
| 4563 | } |
| 4564 | } |
| 4565 | |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 4566 | final void handleActivityConfigurationChanged(ActivityConfigChangeData data, |
| 4567 | boolean reportToActivity) { |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 4568 | ActivityClientRecord r = mActivities.get(data.activityToken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4569 | if (r == null || r.activity == null) { |
| 4570 | return; |
| 4571 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4572 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4573 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Handle activity config changed: " |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 4574 | + r.activityInfo.name + ", with callback=" + reportToActivity); |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 4575 | |
| 4576 | r.tmpConfig.setTo(mCompatConfiguration); |
| 4577 | if (data.overrideConfig != null) { |
| 4578 | r.overrideConfig = data.overrideConfig; |
| 4579 | r.tmpConfig.updateFrom(data.overrideConfig); |
| 4580 | } |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 4581 | performConfigurationChanged(r.activity, r.tmpConfig, reportToActivity); |
Fabrice Di Meglio | 30ca5cd | 2012-05-07 17:45:44 -0700 | [diff] [blame] | 4582 | |
| 4583 | freeTextLayoutCachesIfNeeded(r.activity.mCurrentConfig.diff(mCompatConfiguration)); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4584 | |
| 4585 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4586 | } |
| 4587 | |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 4588 | final void handleProfilerControl(boolean start, ProfilerInfo profilerInfo, int profileType) { |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 4589 | if (start) { |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 4590 | try { |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 4591 | switch (profileType) { |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 4592 | default: |
| 4593 | mProfiler.setProfiler(profilerInfo); |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 4594 | mProfiler.startProfiling(); |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 4595 | break; |
| 4596 | } |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 4597 | } catch (RuntimeException e) { |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 4598 | Slog.w(TAG, "Profiling failed on path " + profilerInfo.profileFile |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 4599 | + " -- can the process access this path?"); |
Dianne Hackborn | 9c8dd55 | 2009-06-23 19:22:52 -0700 | [diff] [blame] | 4600 | } finally { |
| 4601 | try { |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 4602 | profilerInfo.profileFd.close(); |
Dianne Hackborn | 9c8dd55 | 2009-06-23 19:22:52 -0700 | [diff] [blame] | 4603 | } catch (IOException e) { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 4604 | Slog.w(TAG, "Failure closing profile fd", e); |
Dianne Hackborn | 9c8dd55 | 2009-06-23 19:22:52 -0700 | [diff] [blame] | 4605 | } |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 4606 | } |
| 4607 | } else { |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 4608 | switch (profileType) { |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 4609 | default: |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 4610 | mProfiler.stopProfiling(); |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 4611 | break; |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 4612 | } |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 4613 | } |
| 4614 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4615 | |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 4616 | static final void handleDumpHeap(boolean managed, DumpHeapData dhd) { |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 4617 | if (managed) { |
| 4618 | try { |
| 4619 | Debug.dumpHprofData(dhd.path, dhd.fd.getFileDescriptor()); |
| 4620 | } catch (IOException e) { |
| 4621 | Slog.w(TAG, "Managed heap dump failed on path " + dhd.path |
| 4622 | + " -- can the process access this path?"); |
| 4623 | } finally { |
| 4624 | try { |
| 4625 | dhd.fd.close(); |
| 4626 | } catch (IOException e) { |
| 4627 | Slog.w(TAG, "Failure closing profile fd", e); |
| 4628 | } |
| 4629 | } |
| 4630 | } else { |
Andy McFadden | 06a6b55 | 2010-07-13 16:28:09 -0700 | [diff] [blame] | 4631 | Debug.dumpNativeHeap(dhd.fd.getFileDescriptor()); |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 4632 | } |
Dianne Hackborn | b9a5e4a | 2015-03-03 17:04:12 -0800 | [diff] [blame] | 4633 | try { |
| 4634 | ActivityManagerNative.getDefault().dumpHeapFinished(dhd.path); |
| 4635 | } catch (RemoteException e) { |
| 4636 | } |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 4637 | } |
| 4638 | |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 4639 | final void handleDispatchPackageBroadcast(int cmd, String[] packages) { |
| 4640 | boolean hasPkgInfo = false; |
| 4641 | if (packages != null) { |
mark_chen | 89764e3 | 2014-12-12 15:38:48 +0800 | [diff] [blame] | 4642 | synchronized (mResourcesManager) { |
| 4643 | for (int i=packages.length-1; i>=0; i--) { |
| 4644 | //Slog.i(TAG, "Cleaning old package: " + packages[i]); |
| 4645 | if (!hasPkgInfo) { |
| 4646 | WeakReference<LoadedApk> ref; |
| 4647 | ref = mPackages.get(packages[i]); |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 4648 | if (ref != null && ref.get() != null) { |
| 4649 | hasPkgInfo = true; |
mark_chen | 89764e3 | 2014-12-12 15:38:48 +0800 | [diff] [blame] | 4650 | } else { |
| 4651 | ref = mResourcePackages.get(packages[i]); |
| 4652 | if (ref != null && ref.get() != null) { |
| 4653 | hasPkgInfo = true; |
| 4654 | } |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 4655 | } |
| 4656 | } |
mark_chen | 89764e3 | 2014-12-12 15:38:48 +0800 | [diff] [blame] | 4657 | mPackages.remove(packages[i]); |
| 4658 | mResourcePackages.remove(packages[i]); |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 4659 | } |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 4660 | } |
| 4661 | } |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 4662 | ApplicationPackageManager.handlePackageBroadcast(cmd, packages, |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 4663 | hasPkgInfo); |
| 4664 | } |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 4665 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4666 | final void handleLowMemory() { |
Dianne Hackborn | 73c1416 | 2012-09-19 15:45:06 -0700 | [diff] [blame] | 4667 | ArrayList<ComponentCallbacks2> callbacks = collectComponentCallbacks(true, null); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4668 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4669 | final int N = callbacks.size(); |
| 4670 | for (int i=0; i<N; i++) { |
| 4671 | callbacks.get(i).onLowMemory(); |
| 4672 | } |
| 4673 | |
Chris Tate | ce22905 | 2009-03-25 16:44:52 -0700 | [diff] [blame] | 4674 | // Ask SQLite to free up as much memory as it can, mostly from its page caches. |
| 4675 | if (Process.myUid() != Process.SYSTEM_UID) { |
| 4676 | int sqliteReleased = SQLiteDatabase.releaseMemory(); |
| 4677 | EventLog.writeEvent(SQLITE_MEM_RELEASED_EVENT_LOG_TAG, sqliteReleased); |
| 4678 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4679 | |
Mike Reed | caf0df1 | 2009-04-27 14:32:05 -0400 | [diff] [blame] | 4680 | // Ask graphics to free up as much as possible (font/image caches) |
| 4681 | Canvas.freeCaches(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4682 | |
Fabrice Di Meglio | 30ca5cd | 2012-05-07 17:45:44 -0700 | [diff] [blame] | 4683 | // Ask text layout engine to free also as much as possible |
| 4684 | Canvas.freeTextLayoutCaches(); |
| 4685 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4686 | BinderInternal.forceGc("mem"); |
| 4687 | } |
| 4688 | |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 4689 | final void handleTrimMemory(int level) { |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 4690 | if (DEBUG_MEMORY_TRIM) Slog.v(TAG, "Trimming memory to level: " + level); |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 4691 | |
Dianne Hackborn | 73c1416 | 2012-09-19 15:45:06 -0700 | [diff] [blame] | 4692 | ArrayList<ComponentCallbacks2> callbacks = collectComponentCallbacks(true, null); |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 4693 | |
| 4694 | final int N = callbacks.size(); |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 4695 | for (int i = 0; i < N; i++) { |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 4696 | callbacks.get(i).onTrimMemory(level); |
| 4697 | } |
Romain Guy | 19f86e8 | 2012-04-23 15:19:07 -0700 | [diff] [blame] | 4698 | |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 4699 | WindowManagerGlobal.getInstance().trimMemory(level); |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 4700 | } |
| 4701 | |
Jeff Sharkey | e1d330a | 2012-05-02 13:46:21 -0700 | [diff] [blame] | 4702 | private void setupGraphicsSupport(LoadedApk info, File cacheDir) { |
Dianne Hackborn | a0c283e | 2012-02-09 10:47:01 -0800 | [diff] [blame] | 4703 | if (Process.isIsolated()) { |
| 4704 | // Isolated processes aren't going to do UI. |
| 4705 | return; |
| 4706 | } |
Romain Guy | a958265 | 2011-11-10 14:20:10 -0800 | [diff] [blame] | 4707 | try { |
| 4708 | int uid = Process.myUid(); |
| 4709 | String[] packages = getPackageManager().getPackagesForUid(uid); |
| 4710 | |
| 4711 | // If there are several packages in this application we won't |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 4712 | // initialize the graphics disk caches |
Dianne Hackborn | a0c283e | 2012-02-09 10:47:01 -0800 | [diff] [blame] | 4713 | if (packages != null && packages.length == 1) { |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 4714 | ThreadedRenderer.setupDiskCache(cacheDir); |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 4715 | RenderScriptCacheDir.setupDiskCache(cacheDir); |
Romain Guy | a958265 | 2011-11-10 14:20:10 -0800 | [diff] [blame] | 4716 | } |
| 4717 | } catch (RemoteException e) { |
| 4718 | // Ignore |
| 4719 | } |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 4720 | } |
| 4721 | |
Calin Juravle | 6905239 | 2015-12-17 17:06:49 +0200 | [diff] [blame] | 4722 | private static void setupJitProfileSupport(LoadedApk loadedApk, File cacheDir) { |
Calin Juravle | db4a79a | 2015-12-23 18:55:08 +0200 | [diff] [blame^] | 4723 | if (!SystemProperties.getBoolean("dalvik.vm.usejitprofiles", false)) { |
| 4724 | return; |
| 4725 | } |
Calin Juravle | 6905239 | 2015-12-17 17:06:49 +0200 | [diff] [blame] | 4726 | final ApplicationInfo appInfo = loadedApk.getApplicationInfo(); |
| 4727 | if (isSharingRuntime(appInfo)) { |
| 4728 | // If sharing is enabled we do not have a unique application |
| 4729 | // in a process and therefore cannot rely on the package |
| 4730 | // name inside the runtime. |
| 4731 | return; |
| 4732 | } |
| 4733 | final List<String> codePaths = new ArrayList<>(); |
| 4734 | if ((appInfo.flags & ApplicationInfo.FLAG_HAS_CODE) != 0) { |
| 4735 | codePaths.add(appInfo.sourceDir); |
| 4736 | } |
| 4737 | if (appInfo.splitSourceDirs != null) { |
| 4738 | Collections.addAll(codePaths, appInfo.splitSourceDirs); |
| 4739 | } |
| 4740 | |
| 4741 | if (codePaths.isEmpty()) { |
| 4742 | // If there are no code paths there's no need to setup a profile file and register with |
| 4743 | // the runtime, |
| 4744 | return; |
| 4745 | } |
| 4746 | |
| 4747 | // Add an extension to the file name to better reveal its intended use. |
| 4748 | // Keep in sync with BackgroundDexOptService. |
| 4749 | final String profileExtension = ".prof"; |
| 4750 | final File profileFile = new File(cacheDir, loadedApk.mPackageName + profileExtension); |
| 4751 | if (!profileFile.exists()) { |
| 4752 | FileDescriptor fd = null; |
| 4753 | try { |
| 4754 | final int permissions = 0600; // read-write for user. |
| 4755 | fd = Os.open(profileFile.getAbsolutePath(), OsConstants.O_CREAT, permissions); |
| 4756 | Os.fchmod(fd, permissions); |
| 4757 | Os.fchown(fd, appInfo.uid, appInfo.uid); |
| 4758 | } catch (ErrnoException e) { |
| 4759 | Log.w(TAG, "Unable to create jit profile file " + profileFile, e); |
| 4760 | try { |
| 4761 | Os.unlink(profileFile.getAbsolutePath()); |
| 4762 | } catch (ErrnoException unlinkErr) { |
| 4763 | Log.v(TAG, "Unable to unlink jit profile file " + profileFile, unlinkErr); |
| 4764 | } |
| 4765 | return; |
| 4766 | } finally { |
| 4767 | IoUtils.closeQuietly(fd); |
| 4768 | } |
| 4769 | } |
| 4770 | |
| 4771 | VMRuntime.registerAppInfo(profileFile.getAbsolutePath(), appInfo.dataDir, |
| 4772 | codePaths.toArray(new String[codePaths.size()])); |
| 4773 | } |
| 4774 | |
| 4775 | /* |
| 4776 | * Two possible indications that this package could be |
| 4777 | * sharing its runtime with other packages: |
| 4778 | * |
| 4779 | * 1) the sharedUserId attribute is set in the manifest, |
| 4780 | * indicating a request to share a VM with other |
| 4781 | * packages with the same sharedUserId. |
| 4782 | * |
| 4783 | * 2) the application element of the manifest has an |
| 4784 | * attribute specifying a non-default process name, |
| 4785 | * indicating the desire to run in another packages VM. |
| 4786 | */ |
| 4787 | private static boolean isSharingRuntime(ApplicationInfo appInfo) { |
| 4788 | IPackageManager pm = getPackageManager(); |
| 4789 | android.content.pm.PackageInfo pi = null; |
| 4790 | try { |
| 4791 | pi = pm.getPackageInfo(appInfo.packageName, 0, UserHandle.myUserId()); |
| 4792 | } catch (RemoteException e) { |
| 4793 | } |
| 4794 | if (pi != null) { |
| 4795 | boolean sharedUserIdSet = (pi.sharedUserId != null); |
| 4796 | boolean processNameNotDefault = (pi.applicationInfo != null) && |
| 4797 | !appInfo.packageName.equals(pi.applicationInfo.processName); |
| 4798 | boolean sharable = sharedUserIdSet || processNameNotDefault; |
| 4799 | return sharable; |
| 4800 | } |
| 4801 | // We couldn't get information for the package. Be pessimistic and assume |
| 4802 | // it's sharing the runtime. |
| 4803 | return true; |
| 4804 | } |
| 4805 | |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 4806 | private void updateDefaultDensity() { |
| 4807 | if (mCurDefaultDisplayDpi != Configuration.DENSITY_DPI_UNDEFINED |
| 4808 | && mCurDefaultDisplayDpi != DisplayMetrics.DENSITY_DEVICE |
| 4809 | && !mDensityCompatMode) { |
| 4810 | Slog.i(TAG, "Switching default density from " |
| 4811 | + DisplayMetrics.DENSITY_DEVICE + " to " |
| 4812 | + mCurDefaultDisplayDpi); |
| 4813 | DisplayMetrics.DENSITY_DEVICE = mCurDefaultDisplayDpi; |
| 4814 | Bitmap.setDefaultDensity(DisplayMetrics.DENSITY_DEFAULT); |
| 4815 | } |
| 4816 | } |
| 4817 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 4818 | private void handleBindApplication(AppBindData data) { |
Man Cao | cfa78b2 | 2015-06-11 20:14:34 -0700 | [diff] [blame] | 4819 | if (data.trackAllocation) { |
| 4820 | DdmVmInternal.enableRecentAllocations(true); |
| 4821 | } |
| 4822 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4823 | mBoundApplication = data; |
| 4824 | mConfiguration = new Configuration(data.config); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 4825 | mCompatConfiguration = new Configuration(data.config); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4826 | |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 4827 | mProfiler = new Profiler(); |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 4828 | if (data.initProfilerInfo != null) { |
| 4829 | mProfiler.profileFile = data.initProfilerInfo.profileFile; |
| 4830 | mProfiler.profileFd = data.initProfilerInfo.profileFd; |
| 4831 | mProfiler.samplingInterval = data.initProfilerInfo.samplingInterval; |
| 4832 | mProfiler.autoStopProfiler = data.initProfilerInfo.autoStopProfiler; |
| 4833 | } |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 4834 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4835 | // send up app name; do this *before* waiting for debugger |
Christopher Tate | 8ee038d | 2009-11-06 11:30:20 -0800 | [diff] [blame] | 4836 | Process.setArgV0(data.processName); |
Siva Velusamy | d693dfa | 2012-09-10 14:36:58 -0700 | [diff] [blame] | 4837 | android.ddm.DdmHandleAppName.setAppName(data.processName, |
| 4838 | UserHandle.myUserId()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4839 | |
Dianne Hackborn | 5d927c2 | 2011-09-02 12:22:18 -0700 | [diff] [blame] | 4840 | if (data.persistent) { |
| 4841 | // Persistent processes on low-memory devices do not get to |
| 4842 | // use hardware accelerated drawing, since this can add too much |
| 4843 | // overhead to the process. |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 4844 | if (!ActivityManager.isHighEndGfx()) { |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 4845 | ThreadedRenderer.disable(false); |
Dianne Hackborn | 5d927c2 | 2011-09-02 12:22:18 -0700 | [diff] [blame] | 4846 | } |
| 4847 | } |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 4848 | |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 4849 | if (mProfiler.profileFd != null) { |
| 4850 | mProfiler.startProfiling(); |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 4851 | } |
| 4852 | |
Joe Onorato | d630f10 | 2011-03-17 18:42:26 -0700 | [diff] [blame] | 4853 | // If the app is Honeycomb MR1 or earlier, switch its AsyncTask |
| 4854 | // implementation to use the pool executor. Normally, we use the |
| 4855 | // serialized executor as the default. This has to happen in the |
| 4856 | // main thread so the main looper is set right. |
Dianne Hackborn | 81e9276 | 2011-10-09 16:00:21 -0700 | [diff] [blame] | 4857 | if (data.appInfo.targetSdkVersion <= android.os.Build.VERSION_CODES.HONEYCOMB_MR1) { |
Joe Onorato | d630f10 | 2011-03-17 18:42:26 -0700 | [diff] [blame] | 4858 | AsyncTask.setDefaultExecutor(AsyncTask.THREAD_POOL_EXECUTOR); |
| 4859 | } |
| 4860 | |
Dianne Hackborn | 7895bc2 | 2014-09-05 15:09:03 -0700 | [diff] [blame] | 4861 | Message.updateCheckRecycle(data.appInfo.targetSdkVersion); |
| 4862 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4863 | /* |
| 4864 | * Before spawning a new process, reset the time zone to be the system time zone. |
| 4865 | * This needs to be done because the system time zone could have changed after the |
| 4866 | * the spawning of this process. Without doing this this process would have the incorrect |
| 4867 | * system time zone. |
| 4868 | */ |
| 4869 | TimeZone.setDefault(null); |
| 4870 | |
| 4871 | /* |
| 4872 | * Initialize the default locale in this process for the reasons we set the time zone. |
| 4873 | */ |
| 4874 | Locale.setDefault(data.config.locale); |
| 4875 | |
Suchi Amalapurapu | c984329 | 2009-06-24 17:02:25 -0700 | [diff] [blame] | 4876 | /* |
| 4877 | * Update the system configuration since its preloaded and might not |
| 4878 | * reflect configuration changes. The configuration object passed |
| 4879 | * in AppBindData can be safely assumed to be up to date |
| 4880 | */ |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4881 | mResourcesManager.applyConfigurationToResourcesLocked(data.config, data.compatInfo); |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 4882 | mCurDefaultDisplayDpi = data.config.densityDpi; |
| 4883 | applyCompatConfiguration(mCurDefaultDisplayDpi); |
Suchi Amalapurapu | c984329 | 2009-06-24 17:02:25 -0700 | [diff] [blame] | 4884 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4885 | data.info = getPackageInfoNoCheck(data.appInfo, data.compatInfo); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4886 | |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 4887 | /** |
| 4888 | * Switch this process to density compatibility mode if needed. |
| 4889 | */ |
| 4890 | if ((data.appInfo.flags&ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES) |
| 4891 | == 0) { |
| 4892 | mDensityCompatMode = true; |
| 4893 | Bitmap.setDefaultDensity(DisplayMetrics.DENSITY_DEFAULT); |
| 4894 | } |
| 4895 | updateDefaultDensity(); |
| 4896 | |
Narayan Kamath | ccb2a086 | 2013-12-19 14:49:36 +0000 | [diff] [blame] | 4897 | final boolean is24Hr = "24".equals(mCoreSettings.getString(Settings.System.TIME_12_24)); |
| 4898 | DateFormat.set24HourTimePref(is24Hr); |
| 4899 | |
Jon Miranda | 836c0a8 | 2014-08-11 12:32:26 -0700 | [diff] [blame] | 4900 | View.mDebugViewAttributes = |
| 4901 | mCoreSettings.getInt(Settings.Global.DEBUG_VIEW_ATTRIBUTES, 0) != 0; |
| 4902 | |
Dianne Hackborn | 96e240f | 2009-07-26 17:42:30 -0700 | [diff] [blame] | 4903 | /** |
Brad Fitzpatrick | 438d059 | 2010-06-10 12:19:19 -0700 | [diff] [blame] | 4904 | * For system applications on userdebug/eng builds, log stack |
| 4905 | * traces of disk and network access to dropbox for analysis. |
| 4906 | */ |
Brad Fitzpatrick | ad13b98 | 2010-07-14 12:35:53 -0700 | [diff] [blame] | 4907 | if ((data.appInfo.flags & |
| 4908 | (ApplicationInfo.FLAG_SYSTEM | |
Brad Fitzpatrick | 50d66f9 | 2010-09-13 21:29:05 -0700 | [diff] [blame] | 4909 | ApplicationInfo.FLAG_UPDATED_SYSTEM_APP)) != 0) { |
| 4910 | StrictMode.conditionallyEnableDebugLogging(); |
Brad Fitzpatrick | 438d059 | 2010-06-10 12:19:19 -0700 | [diff] [blame] | 4911 | } |
| 4912 | |
| 4913 | /** |
Brad Fitzpatrick | b6e1841 | 2010-10-28 14:50:05 -0700 | [diff] [blame] | 4914 | * For apps targetting SDK Honeycomb or later, we don't allow |
| 4915 | * network usage on the main event loop / UI thread. |
| 4916 | * |
| 4917 | * Note to those grepping: this is what ultimately throws |
| 4918 | * NetworkOnMainThreadException ... |
| 4919 | */ |
| 4920 | if (data.appInfo.targetSdkVersion > 9) { |
| 4921 | StrictMode.enableDeathOnNetwork(); |
| 4922 | } |
| 4923 | |
Alex Klyubin | f9034cc | 2015-02-12 11:43:09 -0800 | [diff] [blame] | 4924 | NetworkSecurityPolicy.getInstance().setCleartextTrafficPermitted( |
| 4925 | (data.appInfo.flags & ApplicationInfo.FLAG_USES_CLEARTEXT_TRAFFIC) != 0); |
| 4926 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4927 | if (data.debugMode != IApplicationThread.DEBUG_OFF) { |
| 4928 | // XXX should have option to change the port. |
| 4929 | Debug.changeDebugPort(8100); |
| 4930 | if (data.debugMode == IApplicationThread.DEBUG_WAIT) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4931 | Slog.w(TAG, "Application " + data.info.getPackageName() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4932 | + " is waiting for the debugger on port 8100..."); |
| 4933 | |
| 4934 | IActivityManager mgr = ActivityManagerNative.getDefault(); |
| 4935 | try { |
| 4936 | mgr.showWaitingForDebugger(mAppThread, true); |
| 4937 | } catch (RemoteException ex) { |
| 4938 | } |
| 4939 | |
| 4940 | Debug.waitForDebugger(); |
| 4941 | |
| 4942 | try { |
| 4943 | mgr.showWaitingForDebugger(mAppThread, false); |
| 4944 | } catch (RemoteException ex) { |
| 4945 | } |
| 4946 | |
| 4947 | } else { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4948 | Slog.w(TAG, "Application " + data.info.getPackageName() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4949 | + " can be debugged on port 8100..."); |
| 4950 | } |
| 4951 | } |
| 4952 | |
Jamie Gennis | f9c7d6b | 2013-03-25 14:18:25 -0700 | [diff] [blame] | 4953 | // Allow application-generated systrace messages if we're debuggable. |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 4954 | boolean isAppDebuggable = (data.appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0; |
| 4955 | Trace.setAppTracingAllowed(isAppDebuggable); |
| 4956 | if (isAppDebuggable && data.enableBinderTracking) { |
| 4957 | Binder.enableTracing(); |
| 4958 | } |
Jamie Gennis | f9c7d6b | 2013-03-25 14:18:25 -0700 | [diff] [blame] | 4959 | |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 4960 | /** |
| 4961 | * Initialize the default http proxy in this process for the reasons we set the time zone. |
| 4962 | */ |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 4963 | final IBinder b = ServiceManager.getService(Context.CONNECTIVITY_SERVICE); |
Dianne Hackborn | d4d32c5 | 2011-11-08 17:33:59 -0800 | [diff] [blame] | 4964 | if (b != null) { |
| 4965 | // In pre-boot mode (doing initial launch to collect password), not |
| 4966 | // all system is up. This includes the connectivity service, so don't |
| 4967 | // crash if we can't get it. |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 4968 | final IConnectivityManager service = IConnectivityManager.Stub.asInterface(b); |
Dianne Hackborn | d4d32c5 | 2011-11-08 17:33:59 -0800 | [diff] [blame] | 4969 | try { |
Paul Jensen | cee9b51 | 2015-05-06 07:32:40 -0400 | [diff] [blame] | 4970 | final ProxyInfo proxyInfo = service.getProxyForNetwork(null); |
Jason Monk | 207900c | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 4971 | Proxy.setHttpProxySystemProperty(proxyInfo); |
Dianne Hackborn | d4d32c5 | 2011-11-08 17:33:59 -0800 | [diff] [blame] | 4972 | } catch (RemoteException e) {} |
| 4973 | } |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 4974 | |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 4975 | // Instrumentation info affects the class loader, so load it before |
| 4976 | // setting up the app context. |
| 4977 | final InstrumentationInfo ii; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4978 | if (data.instrumentationName != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4979 | try { |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 4980 | ii = new ApplicationPackageManager(null, getPackageManager()) |
| 4981 | .getInstrumentationInfo(data.instrumentationName, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4982 | } catch (PackageManager.NameNotFoundException e) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4983 | throw new RuntimeException( |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 4984 | "Unable to find instrumentation info for: " + data.instrumentationName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4985 | } |
| 4986 | |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 4987 | mInstrumentationPackageName = ii.packageName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4988 | mInstrumentationAppDir = ii.sourceDir; |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 4989 | mInstrumentationSplitAppDirs = ii.splitSourceDirs; |
| 4990 | mInstrumentationLibDir = ii.nativeLibraryDir; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4991 | mInstrumentedAppDir = data.info.getAppDir(); |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 4992 | mInstrumentedSplitAppDirs = data.info.getSplitAppDirs(); |
| 4993 | mInstrumentedLibDir = data.info.getLibDir(); |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 4994 | } else { |
| 4995 | ii = null; |
| 4996 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4997 | |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 4998 | final ContextImpl appContext = ContextImpl.createAppContext(this, data.info); |
| 4999 | if (!Process.isIsolated()) { |
| 5000 | final File cacheDir = appContext.getCacheDir(); |
| 5001 | if (cacheDir != null) { |
| 5002 | // Provide a usable directory for temporary files |
| 5003 | System.setProperty("java.io.tmpdir", cacheDir.getAbsolutePath()); |
| 5004 | } else { |
| 5005 | Log.v(TAG, "Unable to initialize \"java.io.tmpdir\" property " |
| 5006 | + "due to missing cache directory"); |
| 5007 | } |
Alan Viverette | 346296b | 2015-09-01 13:08:05 -0400 | [diff] [blame] | 5008 | |
Calin Juravle | c74d338 | 2016-01-07 12:15:36 +0000 | [diff] [blame] | 5009 | // Use codeCacheDir to store generated/compiled graphics code and jit profiling data. |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 5010 | final File codeCacheDir = appContext.getCodeCacheDir(); |
| 5011 | if (codeCacheDir != null) { |
| 5012 | setupGraphicsSupport(data.info, codeCacheDir); |
Calin Juravle | c74d338 | 2016-01-07 12:15:36 +0000 | [diff] [blame] | 5013 | setupJitProfileSupport(data.info, codeCacheDir); |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 5014 | } else { |
Calin Juravle | c74d338 | 2016-01-07 12:15:36 +0000 | [diff] [blame] | 5015 | Log.e(TAG, "Unable to setupGraphicsSupport and setupJitProfileSupport " + |
| 5016 | "due to missing code-cache directory"); |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 5017 | } |
| 5018 | } |
| 5019 | |
Chad Brubaker | 78d4712 | 2015-11-17 22:26:58 -0800 | [diff] [blame] | 5020 | // Install the Network Security Config Provider. This must happen before the application |
| 5021 | // code is loaded to prevent issues with instances of TLS objects being created before |
| 5022 | // the provider is installed. |
| 5023 | NetworkSecurityConfigProvider.install(appContext); |
| 5024 | |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 5025 | // Continue loading instrumentation. |
| 5026 | if (ii != null) { |
Alan Viverette | 346296b | 2015-09-01 13:08:05 -0400 | [diff] [blame] | 5027 | final ApplicationInfo instrApp = new ApplicationInfo(); |
Jeff Sharkey | 1544779 | 2015-11-05 16:18:51 -0800 | [diff] [blame] | 5028 | ii.copyTo(instrApp); |
Fyodor Kupolov | af38b8e | 2015-12-02 16:16:07 -0800 | [diff] [blame] | 5029 | instrApp.initForUser(UserHandle.myUserId()); |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 5030 | final LoadedApk pi = getPackageInfo(instrApp, data.compatInfo, |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 5031 | appContext.getClassLoader(), false, true, false); |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 5032 | final ContextImpl instrContext = ContextImpl.createAppContext(this, pi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5033 | |
| 5034 | try { |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 5035 | final ClassLoader cl = instrContext.getClassLoader(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5036 | mInstrumentation = (Instrumentation) |
| 5037 | cl.loadClass(data.instrumentationName.getClassName()).newInstance(); |
| 5038 | } catch (Exception e) { |
| 5039 | throw new RuntimeException( |
| 5040 | "Unable to instantiate instrumentation " |
| 5041 | + data.instrumentationName + ": " + e.toString(), e); |
| 5042 | } |
| 5043 | |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 5044 | final ComponentName component = new ComponentName(ii.packageName, ii.name); |
| 5045 | mInstrumentation.init(this, instrContext, appContext, component, |
| 5046 | data.instrumentationWatcher, data.instrumentationUiAutomationConnection); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5047 | |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 5048 | if (mProfiler.profileFile != null && !ii.handleProfiling |
| 5049 | && mProfiler.profileFd == null) { |
| 5050 | mProfiler.handlingProfiling = true; |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 5051 | final File file = new File(mProfiler.profileFile); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5052 | file.getParentFile().mkdirs(); |
| 5053 | Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024); |
| 5054 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5055 | } else { |
| 5056 | mInstrumentation = new Instrumentation(); |
| 5057 | } |
| 5058 | |
Dianne Hackborn | 3b81bc1 | 2011-01-15 11:50:52 -0800 | [diff] [blame] | 5059 | if ((data.appInfo.flags&ApplicationInfo.FLAG_LARGE_HEAP) != 0) { |
Dianne Hackborn | de39851 | 2011-01-18 18:45:21 -0800 | [diff] [blame] | 5060 | dalvik.system.VMRuntime.getRuntime().clearGrowthLimit(); |
Mathieu Chartier | 24cee07 | 2015-01-08 14:42:20 -0800 | [diff] [blame] | 5061 | } else { |
| 5062 | // Small heap, clamp to the current growth limit and let the heap release |
| 5063 | // pages after the growth limit to the non growth limit capacity. b/18387825 |
| 5064 | dalvik.system.VMRuntime.getRuntime().clampGrowthLimit(); |
Dianne Hackborn | 3b81bc1 | 2011-01-15 11:50:52 -0800 | [diff] [blame] | 5065 | } |
| 5066 | |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 5067 | // Allow disk access during application and provider setup. This could |
Jeff Sharkey | 7c50167 | 2012-02-28 12:08:37 -0800 | [diff] [blame] | 5068 | // block processing ordered broadcasts, but later processing would |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 5069 | // probably end up doing the same disk access. |
Jeff Sharkey | 7c50167 | 2012-02-28 12:08:37 -0800 | [diff] [blame] | 5070 | final StrictMode.ThreadPolicy savedPolicy = StrictMode.allowThreadDiskWrites(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5071 | try { |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 5072 | // If the app is being launched for full backup or restore, bring it up in |
| 5073 | // a restricted environment with the base application class. |
| 5074 | Application app = data.info.makeApplication(data.restrictedBackupMode, null); |
| 5075 | mInitialApplication = app; |
Jeff Sharkey | 7c50167 | 2012-02-28 12:08:37 -0800 | [diff] [blame] | 5076 | |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 5077 | // don't bring up providers in restricted mode; they may depend on the |
| 5078 | // app's custom Application class |
| 5079 | if (!data.restrictedBackupMode) { |
| 5080 | List<ProviderInfo> providers = data.providers; |
| 5081 | if (providers != null) { |
| 5082 | installContentProviders(app, providers); |
| 5083 | // For process that contains content providers, we want to |
| 5084 | // ensure that the JIT is enabled "at some point". |
| 5085 | mH.sendEmptyMessageDelayed(H.ENABLE_JIT, 10*1000); |
| 5086 | } |
| 5087 | } |
| 5088 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5089 | // Do this after providers, since instrumentation tests generally start their |
| 5090 | // test thread at this point, and we don't want that racing. |
| 5091 | try { |
| 5092 | mInstrumentation.onCreate(data.instrumentationArgs); |
| 5093 | } |
| 5094 | catch (Exception e) { |
| 5095 | throw new RuntimeException( |
| 5096 | "Exception thrown in onCreate() of " |
| 5097 | + data.instrumentationName + ": " + e.toString(), e); |
| 5098 | } |
| 5099 | |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 5100 | try { |
| 5101 | mInstrumentation.callApplicationOnCreate(app); |
| 5102 | } catch (Exception e) { |
| 5103 | if (!mInstrumentation.onException(app, e)) { |
| 5104 | throw new RuntimeException( |
| 5105 | "Unable to create application " + app.getClass().getName() |
| 5106 | + ": " + e.toString(), e); |
| 5107 | } |
| 5108 | } |
| 5109 | } finally { |
| 5110 | StrictMode.setThreadPolicy(savedPolicy); |
| 5111 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5112 | } |
| 5113 | |
| 5114 | /*package*/ final void finishInstrumentation(int resultCode, Bundle results) { |
| 5115 | IActivityManager am = ActivityManagerNative.getDefault(); |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 5116 | if (mProfiler.profileFile != null && mProfiler.handlingProfiling |
| 5117 | && mProfiler.profileFd == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5118 | Debug.stopMethodTracing(); |
| 5119 | } |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 5120 | //Slog.i(TAG, "am: " + ActivityManagerNative.getDefault() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5121 | // + ", app thr: " + mAppThread); |
| 5122 | try { |
| 5123 | am.finishInstrumentation(mAppThread, resultCode, results); |
| 5124 | } catch (RemoteException ex) { |
| 5125 | } |
| 5126 | } |
| 5127 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 5128 | private void installContentProviders( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5129 | Context context, List<ProviderInfo> providers) { |
| 5130 | final ArrayList<IActivityManager.ContentProviderHolder> results = |
| 5131 | new ArrayList<IActivityManager.ContentProviderHolder>(); |
| 5132 | |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 5133 | for (ProviderInfo cpi : providers) { |
Dianne Hackborn | 40e9f29 | 2012-11-27 19:12:23 -0800 | [diff] [blame] | 5134 | if (DEBUG_PROVIDER) { |
| 5135 | StringBuilder buf = new StringBuilder(128); |
| 5136 | buf.append("Pub "); |
| 5137 | buf.append(cpi.authority); |
| 5138 | buf.append(": "); |
| 5139 | buf.append(cpi.name); |
| 5140 | Log.i(TAG, buf.toString()); |
| 5141 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5142 | IActivityManager.ContentProviderHolder cph = installProvider(context, null, cpi, |
| 5143 | false /*noisy*/, true /*noReleaseNeeded*/, true /*stable*/); |
| 5144 | if (cph != null) { |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5145 | cph.noReleaseNeeded = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5146 | results.add(cph); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5147 | } |
| 5148 | } |
| 5149 | |
| 5150 | try { |
| 5151 | ActivityManagerNative.getDefault().publishContentProviders( |
| 5152 | getApplicationThread(), results); |
| 5153 | } catch (RemoteException ex) { |
| 5154 | } |
| 5155 | } |
| 5156 | |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 5157 | public final IContentProvider acquireProvider( |
| 5158 | Context c, String auth, int userId, boolean stable) { |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 5159 | final IContentProvider provider = acquireExistingProvider(c, auth, userId, stable); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5160 | if (provider != null) { |
| 5161 | return provider; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5162 | } |
| 5163 | |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 5164 | // There is a possible race here. Another thread may try to acquire |
| 5165 | // the same provider at the same time. When this happens, we want to ensure |
| 5166 | // that the first one wins. |
| 5167 | // Note that we cannot hold the lock while acquiring and installing the |
| 5168 | // provider since it might take a long time to run and it could also potentially |
| 5169 | // 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] | 5170 | IActivityManager.ContentProviderHolder holder = null; |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 5171 | try { |
| 5172 | holder = ActivityManagerNative.getDefault().getContentProvider( |
| 5173 | getApplicationThread(), auth, userId, stable); |
| 5174 | } catch (RemoteException ex) { |
Wale Ogunwale | 67fe0a4 | 2015-04-24 14:44:54 -0700 | [diff] [blame] | 5175 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5176 | if (holder == null) { |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 5177 | Slog.e(TAG, "Failed to find provider info for " + auth); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5178 | return null; |
| 5179 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5180 | |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5181 | // Install provider will increment the reference count for us, and break |
| 5182 | // any ties in the race. |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5183 | holder = installProvider(c, holder, holder.info, |
| 5184 | true /*noisy*/, holder.noReleaseNeeded, stable); |
| 5185 | return holder.provider; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5186 | } |
| 5187 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5188 | private final void incProviderRefLocked(ProviderRefCount prc, boolean stable) { |
| 5189 | if (stable) { |
| 5190 | prc.stableCount += 1; |
| 5191 | if (prc.stableCount == 1) { |
| 5192 | // We are acquiring a new stable reference on the provider. |
| 5193 | int unstableDelta; |
| 5194 | if (prc.removePending) { |
| 5195 | // We have a pending remove operation, which is holding the |
| 5196 | // last unstable reference. At this point we are converting |
| 5197 | // that unstable reference to our new stable reference. |
| 5198 | unstableDelta = -1; |
| 5199 | // Cancel the removal of the provider. |
| 5200 | if (DEBUG_PROVIDER) { |
| 5201 | Slog.v(TAG, "incProviderRef: stable " |
| 5202 | + "snatched provider from the jaws of death"); |
| 5203 | } |
| 5204 | prc.removePending = false; |
Guobin Zhang | 9e3e5266 | 2013-03-21 13:57:11 +0800 | [diff] [blame] | 5205 | // There is a race! It fails to remove the message, which |
| 5206 | // will be handled in completeRemoveProvider(). |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5207 | mH.removeMessages(H.REMOVE_PROVIDER, prc); |
| 5208 | } else { |
| 5209 | unstableDelta = 0; |
| 5210 | } |
| 5211 | try { |
| 5212 | if (DEBUG_PROVIDER) { |
| 5213 | Slog.v(TAG, "incProviderRef Now stable - " |
| 5214 | + prc.holder.info.name + ": unstableDelta=" |
| 5215 | + unstableDelta); |
| 5216 | } |
| 5217 | ActivityManagerNative.getDefault().refContentProvider( |
| 5218 | prc.holder.connection, 1, unstableDelta); |
| 5219 | } catch (RemoteException e) { |
| 5220 | //do nothing content provider object is dead any way |
| 5221 | } |
| 5222 | } |
| 5223 | } else { |
| 5224 | prc.unstableCount += 1; |
| 5225 | if (prc.unstableCount == 1) { |
| 5226 | // We are acquiring a new unstable reference on the provider. |
| 5227 | if (prc.removePending) { |
| 5228 | // Oh look, we actually have a remove pending for the |
| 5229 | // provider, which is still holding the last unstable |
| 5230 | // reference. We just need to cancel that to take new |
| 5231 | // ownership of the reference. |
| 5232 | if (DEBUG_PROVIDER) { |
| 5233 | Slog.v(TAG, "incProviderRef: unstable " |
| 5234 | + "snatched provider from the jaws of death"); |
| 5235 | } |
| 5236 | prc.removePending = false; |
| 5237 | mH.removeMessages(H.REMOVE_PROVIDER, prc); |
| 5238 | } else { |
| 5239 | // First unstable ref, increment our count in the |
| 5240 | // activity manager. |
| 5241 | try { |
| 5242 | if (DEBUG_PROVIDER) { |
| 5243 | Slog.v(TAG, "incProviderRef: Now unstable - " |
| 5244 | + prc.holder.info.name); |
| 5245 | } |
| 5246 | ActivityManagerNative.getDefault().refContentProvider( |
| 5247 | prc.holder.connection, 0, 1); |
| 5248 | } catch (RemoteException e) { |
| 5249 | //do nothing content provider object is dead any way |
| 5250 | } |
| 5251 | } |
| 5252 | } |
| 5253 | } |
| 5254 | } |
| 5255 | |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 5256 | public final IContentProvider acquireExistingProvider( |
| 5257 | Context c, String auth, int userId, boolean stable) { |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5258 | synchronized (mProviderMap) { |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 5259 | final ProviderKey key = new ProviderKey(auth, userId); |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 5260 | final ProviderClientRecord pr = mProviderMap.get(key); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5261 | if (pr == null) { |
| 5262 | return null; |
| 5263 | } |
| 5264 | |
| 5265 | IContentProvider provider = pr.mProvider; |
| 5266 | IBinder jBinder = provider.asBinder(); |
Dianne Hackborn | c428aae | 2012-10-03 16:38:22 -0700 | [diff] [blame] | 5267 | if (!jBinder.isBinderAlive()) { |
| 5268 | // The hosting process of the provider has died; we can't |
| 5269 | // use this one. |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 5270 | Log.i(TAG, "Acquiring provider " + auth + " for user " + userId |
Dianne Hackborn | c428aae | 2012-10-03 16:38:22 -0700 | [diff] [blame] | 5271 | + ": existing object's process dead"); |
| 5272 | handleUnstableProviderDiedLocked(jBinder, true); |
| 5273 | return null; |
| 5274 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5275 | |
| 5276 | // Only increment the ref count if we have one. If we don't then the |
| 5277 | // provider is not reference counted and never needs to be released. |
Dianne Hackborn | cca1f0e | 2010-09-26 18:34:53 -0700 | [diff] [blame] | 5278 | ProviderRefCount prc = mProviderRefCountMap.get(jBinder); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5279 | if (prc != null) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5280 | incProviderRefLocked(prc, stable); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5281 | } |
| 5282 | return provider; |
| 5283 | } |
Dianne Hackborn | cca1f0e | 2010-09-26 18:34:53 -0700 | [diff] [blame] | 5284 | } |
| 5285 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5286 | public final boolean releaseProvider(IContentProvider provider, boolean stable) { |
| 5287 | if (provider == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5288 | return false; |
| 5289 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5290 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5291 | IBinder jBinder = provider.asBinder(); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5292 | synchronized (mProviderMap) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5293 | ProviderRefCount prc = mProviderRefCountMap.get(jBinder); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5294 | if (prc == null) { |
| 5295 | // 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] | 5296 | return false; |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5297 | } |
| 5298 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5299 | boolean lastRef = false; |
| 5300 | if (stable) { |
| 5301 | if (prc.stableCount == 0) { |
| 5302 | if (DEBUG_PROVIDER) Slog.v(TAG, |
| 5303 | "releaseProvider: stable ref count already 0, how?"); |
| 5304 | return false; |
| 5305 | } |
| 5306 | prc.stableCount -= 1; |
| 5307 | if (prc.stableCount == 0) { |
| 5308 | // What we do at this point depends on whether there are |
| 5309 | // any unstable refs left: if there are, we just tell the |
| 5310 | // activity manager to decrement its stable count; if there |
| 5311 | // aren't, we need to enqueue this provider to be removed, |
| 5312 | // and convert to holding a single unstable ref while |
| 5313 | // doing so. |
| 5314 | lastRef = prc.unstableCount == 0; |
| 5315 | try { |
| 5316 | if (DEBUG_PROVIDER) { |
| 5317 | Slog.v(TAG, "releaseProvider: No longer stable w/lastRef=" |
| 5318 | + lastRef + " - " + prc.holder.info.name); |
| 5319 | } |
| 5320 | ActivityManagerNative.getDefault().refContentProvider( |
| 5321 | prc.holder.connection, -1, lastRef ? 1 : 0); |
| 5322 | } catch (RemoteException e) { |
| 5323 | //do nothing content provider object is dead any way |
| 5324 | } |
| 5325 | } |
| 5326 | } else { |
| 5327 | if (prc.unstableCount == 0) { |
| 5328 | if (DEBUG_PROVIDER) Slog.v(TAG, |
| 5329 | "releaseProvider: unstable ref count already 0, how?"); |
| 5330 | return false; |
| 5331 | } |
| 5332 | prc.unstableCount -= 1; |
| 5333 | if (prc.unstableCount == 0) { |
| 5334 | // If this is the last reference, we need to enqueue |
| 5335 | // this provider to be removed instead of telling the |
| 5336 | // activity manager to remove it at this point. |
| 5337 | lastRef = prc.stableCount == 0; |
| 5338 | if (!lastRef) { |
| 5339 | try { |
| 5340 | if (DEBUG_PROVIDER) { |
| 5341 | Slog.v(TAG, "releaseProvider: No longer unstable - " |
| 5342 | + prc.holder.info.name); |
| 5343 | } |
| 5344 | ActivityManagerNative.getDefault().refContentProvider( |
| 5345 | prc.holder.connection, 0, -1); |
| 5346 | } catch (RemoteException e) { |
| 5347 | //do nothing content provider object is dead any way |
| 5348 | } |
| 5349 | } |
| 5350 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5351 | } |
| 5352 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5353 | if (lastRef) { |
| 5354 | if (!prc.removePending) { |
| 5355 | // Schedule the actual remove asynchronously, since we don't know the context |
| 5356 | // this will be called in. |
| 5357 | // TODO: it would be nice to post a delayed message, so |
| 5358 | // if we come back and need the same provider quickly |
| 5359 | // we will still have it available. |
| 5360 | if (DEBUG_PROVIDER) { |
| 5361 | Slog.v(TAG, "releaseProvider: Enqueueing pending removal - " |
| 5362 | + prc.holder.info.name); |
| 5363 | } |
| 5364 | prc.removePending = true; |
| 5365 | Message msg = mH.obtainMessage(H.REMOVE_PROVIDER, prc); |
| 5366 | mH.sendMessage(msg); |
| 5367 | } else { |
| 5368 | Slog.w(TAG, "Duplicate remove pending of provider " + prc.holder.info.name); |
| 5369 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5370 | } |
| 5371 | return true; |
| 5372 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5373 | } |
| 5374 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5375 | final void completeRemoveProvider(ProviderRefCount prc) { |
| 5376 | synchronized (mProviderMap) { |
| 5377 | if (!prc.removePending) { |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5378 | // There was a race! Some other client managed to acquire |
| 5379 | // the provider before the removal was completed. |
| 5380 | // Abort the removal. We will do it later. |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5381 | if (DEBUG_PROVIDER) Slog.v(TAG, "completeRemoveProvider: lost the race, " |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5382 | + "provider still in use"); |
| 5383 | return; |
| 5384 | } |
| 5385 | |
Guobin Zhang | 9e3e5266 | 2013-03-21 13:57:11 +0800 | [diff] [blame] | 5386 | // More complicated race!! Some client managed to acquire the |
| 5387 | // provider and release it before the removal was completed. |
| 5388 | // Continue the removal, and abort the next remove message. |
| 5389 | prc.removePending = false; |
| 5390 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5391 | final IBinder jBinder = prc.holder.provider.asBinder(); |
| 5392 | ProviderRefCount existingPrc = mProviderRefCountMap.get(jBinder); |
| 5393 | if (existingPrc == prc) { |
| 5394 | mProviderRefCountMap.remove(jBinder); |
| 5395 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5396 | |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 5397 | for (int i=mProviderMap.size()-1; i>=0; i--) { |
| 5398 | ProviderClientRecord pr = mProviderMap.valueAt(i); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5399 | IBinder myBinder = pr.mProvider.asBinder(); |
| 5400 | if (myBinder == jBinder) { |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 5401 | mProviderMap.removeAt(i); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5402 | } |
| 5403 | } |
| 5404 | } |
| 5405 | |
| 5406 | try { |
| 5407 | if (DEBUG_PROVIDER) { |
| 5408 | Slog.v(TAG, "removeProvider: Invoking ActivityManagerNative." |
| 5409 | + "removeContentProvider(" + prc.holder.info.name + ")"); |
| 5410 | } |
| 5411 | ActivityManagerNative.getDefault().removeContentProvider( |
| 5412 | prc.holder.connection, false); |
| 5413 | } catch (RemoteException e) { |
| 5414 | //do nothing content provider object is dead any way |
| 5415 | } |
| 5416 | } |
| 5417 | |
| 5418 | final void handleUnstableProviderDied(IBinder provider, boolean fromClient) { |
Dianne Hackborn | c428aae | 2012-10-03 16:38:22 -0700 | [diff] [blame] | 5419 | synchronized (mProviderMap) { |
| 5420 | handleUnstableProviderDiedLocked(provider, fromClient); |
| 5421 | } |
| 5422 | } |
| 5423 | |
| 5424 | final void handleUnstableProviderDiedLocked(IBinder provider, boolean fromClient) { |
| 5425 | ProviderRefCount prc = mProviderRefCountMap.get(provider); |
| 5426 | if (prc != null) { |
| 5427 | if (DEBUG_PROVIDER) Slog.v(TAG, "Cleaning up dead provider " |
| 5428 | + provider + " " + prc.holder.info.name); |
| 5429 | mProviderRefCountMap.remove(provider); |
You Kim | bc74de6 | 2013-10-01 00:13:26 +0900 | [diff] [blame] | 5430 | for (int i=mProviderMap.size()-1; i>=0; i--) { |
| 5431 | ProviderClientRecord pr = mProviderMap.valueAt(i); |
| 5432 | if (pr != null && pr.mProvider.asBinder() == provider) { |
| 5433 | Slog.i(TAG, "Removing dead content provider:" + pr.mProvider.toString()); |
| 5434 | mProviderMap.removeAt(i); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5435 | } |
Dianne Hackborn | c428aae | 2012-10-03 16:38:22 -0700 | [diff] [blame] | 5436 | } |
You Kim | bc74de6 | 2013-10-01 00:13:26 +0900 | [diff] [blame] | 5437 | |
Dianne Hackborn | c428aae | 2012-10-03 16:38:22 -0700 | [diff] [blame] | 5438 | if (fromClient) { |
| 5439 | // We found out about this due to execution in our client |
| 5440 | // code. Tell the activity manager about it now, to ensure |
| 5441 | // that the next time we go to do anything with the provider |
| 5442 | // it knows it is dead (so we don't race with its death |
| 5443 | // notification). |
| 5444 | try { |
| 5445 | ActivityManagerNative.getDefault().unstableProviderDied( |
| 5446 | prc.holder.connection); |
| 5447 | } catch (RemoteException e) { |
| 5448 | //do nothing content provider object is dead any way |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5449 | } |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 5450 | } |
| 5451 | } |
| 5452 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5453 | |
Jeff Sharkey | 7aa7601 | 2013-09-30 14:26:27 -0700 | [diff] [blame] | 5454 | final void appNotRespondingViaProvider(IBinder provider) { |
| 5455 | synchronized (mProviderMap) { |
| 5456 | ProviderRefCount prc = mProviderRefCountMap.get(provider); |
| 5457 | if (prc != null) { |
| 5458 | try { |
| 5459 | ActivityManagerNative.getDefault() |
| 5460 | .appNotRespondingViaProvider(prc.holder.connection); |
| 5461 | } catch (RemoteException e) { |
| 5462 | } |
| 5463 | } |
| 5464 | } |
| 5465 | } |
| 5466 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5467 | private ProviderClientRecord installProviderAuthoritiesLocked(IContentProvider provider, |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 5468 | ContentProvider localProvider, IActivityManager.ContentProviderHolder holder) { |
Andreas Gampe | 18e99c1 | 2015-03-06 15:29:06 -0800 | [diff] [blame] | 5469 | final String auths[] = holder.info.authority.split(";"); |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 5470 | final int userId = UserHandle.getUserId(holder.info.applicationInfo.uid); |
| 5471 | |
| 5472 | final ProviderClientRecord pcr = new ProviderClientRecord( |
| 5473 | auths, provider, localProvider, holder); |
| 5474 | for (String auth : auths) { |
| 5475 | final ProviderKey key = new ProviderKey(auth, userId); |
| 5476 | final ProviderClientRecord existing = mProviderMap.get(key); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5477 | if (existing != null) { |
| 5478 | Slog.w(TAG, "Content provider " + pcr.mHolder.info.name |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 5479 | + " already published as " + auth); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5480 | } else { |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 5481 | mProviderMap.put(key, pcr); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5482 | } |
| 5483 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5484 | return pcr; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5485 | } |
| 5486 | |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5487 | /** |
| 5488 | * Installs the provider. |
| 5489 | * |
| 5490 | * Providers that are local to the process or that come from the system server |
| 5491 | * may be installed permanently which is indicated by setting noReleaseNeeded to true. |
| 5492 | * Other remote providers are reference counted. The initial reference count |
| 5493 | * for all reference counted providers is one. Providers that are not reference |
| 5494 | * counted do not have a reference count (at all). |
| 5495 | * |
| 5496 | * This method detects when a provider has already been installed. When this happens, |
| 5497 | * it increments the reference count of the existing provider (if appropriate) |
| 5498 | * and returns the existing provider. This can happen due to concurrent |
| 5499 | * attempts to acquire the same provider. |
| 5500 | */ |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5501 | private IActivityManager.ContentProviderHolder installProvider(Context context, |
| 5502 | IActivityManager.ContentProviderHolder holder, ProviderInfo info, |
| 5503 | boolean noisy, boolean noReleaseNeeded, boolean stable) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5504 | ContentProvider localProvider = null; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5505 | IContentProvider provider; |
Dianne Hackborn | 5f48fca | 2012-05-30 11:06:31 -0700 | [diff] [blame] | 5506 | if (holder == null || holder.provider == null) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5507 | if (DEBUG_PROVIDER || noisy) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 5508 | Slog.d(TAG, "Loading provider " + info.authority + ": " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5509 | + info.name); |
| 5510 | } |
| 5511 | Context c = null; |
| 5512 | ApplicationInfo ai = info.applicationInfo; |
| 5513 | if (context.getPackageName().equals(ai.packageName)) { |
| 5514 | c = context; |
| 5515 | } else if (mInitialApplication != null && |
| 5516 | mInitialApplication.getPackageName().equals(ai.packageName)) { |
| 5517 | c = mInitialApplication; |
| 5518 | } else { |
| 5519 | try { |
| 5520 | c = context.createPackageContext(ai.packageName, |
| 5521 | Context.CONTEXT_INCLUDE_CODE); |
| 5522 | } catch (PackageManager.NameNotFoundException e) { |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 5523 | // Ignore |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5524 | } |
| 5525 | } |
| 5526 | if (c == null) { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 5527 | Slog.w(TAG, "Unable to get context for package " + |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5528 | ai.packageName + |
| 5529 | " while loading content provider " + |
| 5530 | info.name); |
| 5531 | return null; |
| 5532 | } |
| 5533 | try { |
| 5534 | final java.lang.ClassLoader cl = c.getClassLoader(); |
| 5535 | localProvider = (ContentProvider)cl. |
| 5536 | loadClass(info.name).newInstance(); |
| 5537 | provider = localProvider.getIContentProvider(); |
| 5538 | if (provider == null) { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 5539 | Slog.e(TAG, "Failed to instantiate class " + |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5540 | info.name + " from sourceDir " + |
| 5541 | info.applicationInfo.sourceDir); |
| 5542 | return null; |
| 5543 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5544 | if (DEBUG_PROVIDER) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5545 | TAG, "Instantiating local provider " + info.name); |
| 5546 | // XXX Need to create the correct context for this provider. |
| 5547 | localProvider.attachInfo(c, info); |
| 5548 | } catch (java.lang.Exception e) { |
| 5549 | if (!mInstrumentation.onException(null, e)) { |
| 5550 | throw new RuntimeException( |
| 5551 | "Unable to get provider " + info.name |
| 5552 | + ": " + e.toString(), e); |
| 5553 | } |
| 5554 | return null; |
| 5555 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5556 | } else { |
| 5557 | provider = holder.provider; |
| 5558 | 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] | 5559 | + info.name); |
| 5560 | } |
| 5561 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5562 | IActivityManager.ContentProviderHolder retHolder; |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5563 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5564 | synchronized (mProviderMap) { |
| 5565 | if (DEBUG_PROVIDER) Slog.v(TAG, "Checking to add " + provider |
| 5566 | + " / " + info.name); |
| 5567 | IBinder jBinder = provider.asBinder(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5568 | if (localProvider != null) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5569 | ComponentName cname = new ComponentName(info.packageName, info.name); |
| 5570 | ProviderClientRecord pr = mLocalProvidersByName.get(cname); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5571 | if (pr != null) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5572 | if (DEBUG_PROVIDER) { |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5573 | Slog.v(TAG, "installProvider: lost the race, " |
| 5574 | + "using existing local provider"); |
| 5575 | } |
| 5576 | provider = pr.mProvider; |
| 5577 | } else { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5578 | holder = new IActivityManager.ContentProviderHolder(info); |
| 5579 | holder.provider = provider; |
| 5580 | holder.noReleaseNeeded = true; |
| 5581 | pr = installProviderAuthoritiesLocked(provider, localProvider, holder); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5582 | mLocalProviders.put(jBinder, pr); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5583 | mLocalProvidersByName.put(cname, pr); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5584 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5585 | retHolder = pr.mHolder; |
| 5586 | } else { |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5587 | ProviderRefCount prc = mProviderRefCountMap.get(jBinder); |
| 5588 | if (prc != null) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5589 | if (DEBUG_PROVIDER) { |
| 5590 | Slog.v(TAG, "installProvider: lost the race, updating ref count"); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5591 | } |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 5592 | // We need to transfer our new reference to the existing |
| 5593 | // ref count, releasing the old one... but only if |
| 5594 | // release is needed (that is, it is not running in the |
| 5595 | // system process). |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5596 | if (!noReleaseNeeded) { |
| 5597 | incProviderRefLocked(prc, stable); |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 5598 | try { |
| 5599 | ActivityManagerNative.getDefault().removeContentProvider( |
| 5600 | holder.connection, stable); |
| 5601 | } catch (RemoteException e) { |
| 5602 | //do nothing content provider object is dead any way |
| 5603 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5604 | } |
| 5605 | } else { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5606 | ProviderClientRecord client = installProviderAuthoritiesLocked( |
| 5607 | provider, localProvider, holder); |
| 5608 | if (noReleaseNeeded) { |
| 5609 | prc = new ProviderRefCount(holder, client, 1000, 1000); |
| 5610 | } else { |
| 5611 | prc = stable |
| 5612 | ? new ProviderRefCount(holder, client, 1, 0) |
| 5613 | : new ProviderRefCount(holder, client, 0, 1); |
| 5614 | } |
| 5615 | mProviderRefCountMap.put(jBinder, prc); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5616 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5617 | retHolder = prc.holder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5618 | } |
| 5619 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5620 | |
| 5621 | return retHolder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5622 | } |
| 5623 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 5624 | private void attach(boolean system) { |
Jeff Sharkey | 66a017b | 2013-01-17 18:18:22 -0800 | [diff] [blame] | 5625 | sCurrentActivityThread = this; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5626 | mSystemThread = system; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5627 | if (!system) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 5628 | ViewRootImpl.addFirstDrawHandler(new Runnable() { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 5629 | @Override |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 5630 | public void run() { |
| 5631 | ensureJitEnabled(); |
| 5632 | } |
| 5633 | }); |
Siva Velusamy | d693dfa | 2012-09-10 14:36:58 -0700 | [diff] [blame] | 5634 | android.ddm.DdmHandleAppName.setAppName("<pre-initialized>", |
| 5635 | UserHandle.myUserId()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5636 | RuntimeInit.setApplicationObject(mAppThread.asBinder()); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 5637 | final IActivityManager mgr = ActivityManagerNative.getDefault(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5638 | try { |
| 5639 | mgr.attachApplication(mAppThread); |
| 5640 | } catch (RemoteException ex) { |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 5641 | // Ignore |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5642 | } |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 5643 | // Watch for getting close to heap limit. |
| 5644 | BinderInternal.addGcWatcher(new Runnable() { |
| 5645 | @Override public void run() { |
| 5646 | if (!mSomeActivitiesChanged) { |
| 5647 | return; |
| 5648 | } |
| 5649 | Runtime runtime = Runtime.getRuntime(); |
| 5650 | long dalvikMax = runtime.maxMemory(); |
| 5651 | long dalvikUsed = runtime.totalMemory() - runtime.freeMemory(); |
| 5652 | if (dalvikUsed > ((3*dalvikMax)/4)) { |
| 5653 | if (DEBUG_MEMORY_TRIM) Slog.d(TAG, "Dalvik max=" + (dalvikMax/1024) |
| 5654 | + " total=" + (runtime.totalMemory()/1024) |
| 5655 | + " used=" + (dalvikUsed/1024)); |
| 5656 | mSomeActivitiesChanged = false; |
| 5657 | try { |
| 5658 | mgr.releaseSomeActivities(mAppThread); |
| 5659 | } catch (RemoteException e) { |
| 5660 | } |
| 5661 | } |
| 5662 | } |
| 5663 | }); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5664 | } else { |
| 5665 | // Don't set application object here -- if the system crashes, |
| 5666 | // we can't display an alert, we just want to die die die. |
Siva Velusamy | d693dfa | 2012-09-10 14:36:58 -0700 | [diff] [blame] | 5667 | android.ddm.DdmHandleAppName.setAppName("system_process", |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 5668 | UserHandle.myUserId()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5669 | try { |
| 5670 | mInstrumentation = new Instrumentation(); |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 5671 | ContextImpl context = ContextImpl.createAppContext( |
| 5672 | this, getSystemContext().mPackageInfo); |
Jeff Brown | 7fc8e35 | 2014-09-16 18:06:47 -0700 | [diff] [blame] | 5673 | mInitialApplication = context.mPackageInfo.makeApplication(true, null); |
| 5674 | mInitialApplication.onCreate(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5675 | } catch (Exception e) { |
| 5676 | throw new RuntimeException( |
| 5677 | "Unable to instantiate Application():" + e.toString(), e); |
| 5678 | } |
| 5679 | } |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 5680 | |
| 5681 | // add dropbox logging to libcore |
| 5682 | DropBox.setReporter(new DropBoxReporter()); |
| 5683 | |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 5684 | ViewRootImpl.addConfigCallback(new ComponentCallbacks2() { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 5685 | @Override |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5686 | public void onConfigurationChanged(Configuration newConfig) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 5687 | synchronized (mResourcesManager) { |
Dianne Hackborn | ae07816 | 2010-03-18 11:29:37 -0700 | [diff] [blame] | 5688 | // We need to apply this change to the resources |
| 5689 | // immediately, because upon returning the view |
| 5690 | // hierarchy will be informed about it. |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 5691 | if (mResourcesManager.applyConfigurationToResourcesLocked(newConfig, null)) { |
Dianne Hackborn | ae07816 | 2010-03-18 11:29:37 -0700 | [diff] [blame] | 5692 | // This actually changed the resources! Tell |
| 5693 | // everyone about it. |
| 5694 | if (mPendingConfiguration == null || |
| 5695 | mPendingConfiguration.isOtherSeqNewer(newConfig)) { |
| 5696 | mPendingConfiguration = newConfig; |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 5697 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 5698 | sendMessage(H.CONFIGURATION_CHANGED, newConfig); |
Dianne Hackborn | ae07816 | 2010-03-18 11:29:37 -0700 | [diff] [blame] | 5699 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5700 | } |
| 5701 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5702 | } |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 5703 | @Override |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5704 | public void onLowMemory() { |
| 5705 | } |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 5706 | @Override |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 5707 | public void onTrimMemory(int level) { |
| 5708 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5709 | }); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5710 | } |
| 5711 | |
Romain Guy | 5e9120d | 2012-01-30 12:17:22 -0800 | [diff] [blame] | 5712 | public static ActivityThread systemMain() { |
Alan Viverette | 5e1565e | 2014-07-29 16:14:25 -0700 | [diff] [blame] | 5713 | // The system process on low-memory devices do not get to use hardware |
| 5714 | // accelerated drawing, since this can add too much overhead to the |
| 5715 | // process. |
| 5716 | if (!ActivityManager.isHighEndGfx()) { |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 5717 | ThreadedRenderer.disable(true); |
John Reck | 73840ea | 2014-09-22 07:39:18 -0700 | [diff] [blame] | 5718 | } else { |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 5719 | ThreadedRenderer.enableForegroundTrimming(); |
Alan Viverette | 5e1565e | 2014-07-29 16:14:25 -0700 | [diff] [blame] | 5720 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5721 | ActivityThread thread = new ActivityThread(); |
| 5722 | thread.attach(true); |
| 5723 | return thread; |
| 5724 | } |
| 5725 | |
Jeff Brown | 10e8971 | 2011-07-08 18:52:57 -0700 | [diff] [blame] | 5726 | public final void installSystemProviders(List<ProviderInfo> providers) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5727 | if (providers != null) { |
Jeff Brown | 10e8971 | 2011-07-08 18:52:57 -0700 | [diff] [blame] | 5728 | installContentProviders(mInitialApplication, providers); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5729 | } |
| 5730 | } |
| 5731 | |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 5732 | public int getIntCoreSetting(String key, int defaultValue) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 5733 | synchronized (mResourcesManager) { |
Svetoslav Ganov | 9aa597e | 2011-03-03 18:17:41 -0800 | [diff] [blame] | 5734 | if (mCoreSettings != null) { |
| 5735 | return mCoreSettings.getInt(key, defaultValue); |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 5736 | } |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 5737 | return defaultValue; |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 5738 | } |
| 5739 | } |
| 5740 | |
Geremy Condra | 69689a7 | 2012-09-11 16:57:17 -0700 | [diff] [blame] | 5741 | private static class EventLoggingReporter implements EventLogger.Reporter { |
| 5742 | @Override |
| 5743 | public void report (int code, Object... list) { |
| 5744 | EventLog.writeEvent(code, list); |
| 5745 | } |
| 5746 | } |
| 5747 | |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 5748 | private class DropBoxReporter implements DropBox.Reporter { |
| 5749 | |
| 5750 | private DropBoxManager dropBox; |
| 5751 | |
Narayan Kamath | 7f06224 | 2015-04-08 13:24:13 +0100 | [diff] [blame] | 5752 | public DropBoxReporter() {} |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 5753 | |
| 5754 | @Override |
| 5755 | public void addData(String tag, byte[] data, int flags) { |
Narayan Kamath | 7f06224 | 2015-04-08 13:24:13 +0100 | [diff] [blame] | 5756 | ensureInitialized(); |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 5757 | dropBox.addData(tag, data, flags); |
| 5758 | } |
| 5759 | |
| 5760 | @Override |
| 5761 | public void addText(String tag, String data) { |
Narayan Kamath | 7f06224 | 2015-04-08 13:24:13 +0100 | [diff] [blame] | 5762 | ensureInitialized(); |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 5763 | dropBox.addText(tag, data); |
| 5764 | } |
Narayan Kamath | 7f06224 | 2015-04-08 13:24:13 +0100 | [diff] [blame] | 5765 | |
| 5766 | private synchronized void ensureInitialized() { |
| 5767 | if (dropBox == null) { |
| 5768 | dropBox = (DropBoxManager) getSystemContext().getSystemService(Context.DROPBOX_SERVICE); |
| 5769 | } |
| 5770 | } |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 5771 | } |
| 5772 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 5773 | public static void main(String[] args) { |
Narayan Kamath | fbb32f6 | 2015-06-12 15:34:35 +0100 | [diff] [blame] | 5774 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "ActivityThreadMain"); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 5775 | SamplingProfilerIntegration.start(); |
| 5776 | |
Brad Fitzpatrick | 4d9e6d2 | 2010-11-15 08:49:51 -0800 | [diff] [blame] | 5777 | // CloseGuard defaults to true and can be quite spammy. We |
| 5778 | // disable it here, but selectively enable it later (via |
| 5779 | // StrictMode) on debug builds, but using DropBox, not logs. |
| 5780 | CloseGuard.setEnabled(false); |
| 5781 | |
Jeff Sharkey | b049e21 | 2012-09-07 23:16:01 -0700 | [diff] [blame] | 5782 | Environment.initForCurrentUser(); |
| 5783 | |
Geremy Condra | 69689a7 | 2012-09-11 16:57:17 -0700 | [diff] [blame] | 5784 | // Set the reporter for event logging in libcore |
| 5785 | EventLogger.setReporter(new EventLoggingReporter()); |
| 5786 | |
Alex Klyubin | 4812563 | 2015-04-29 13:16:30 -0700 | [diff] [blame] | 5787 | AndroidKeyStoreProvider.install(); |
Kenny Root | 8b51475 | 2013-02-04 09:35:16 -0800 | [diff] [blame] | 5788 | |
Robin Lee | 3d076af | 2014-04-25 14:57:49 +0100 | [diff] [blame] | 5789 | // Make sure TrustedCertificateStore looks in the right place for CA certificates |
| 5790 | final File configDir = Environment.getUserConfigDirectory(UserHandle.myUserId()); |
| 5791 | TrustedCertificateStore.setDefaultUserDirectory(configDir); |
| 5792 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5793 | Process.setArgV0("<pre-initialized>"); |
| 5794 | |
| 5795 | Looper.prepareMainLooper(); |
| 5796 | |
| 5797 | ActivityThread thread = new ActivityThread(); |
| 5798 | thread.attach(false); |
| 5799 | |
Vairavan Srinivasan | 7335cfd | 2012-08-18 18:36:03 -0700 | [diff] [blame] | 5800 | if (sMainThreadHandler == null) { |
| 5801 | sMainThreadHandler = thread.getHandler(); |
| 5802 | } |
| 5803 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 5804 | if (false) { |
| 5805 | Looper.myLooper().setMessageLogging(new |
| 5806 | LogPrinter(Log.DEBUG, "ActivityThread")); |
| 5807 | } |
| 5808 | |
Narayan Kamath | fbb32f6 | 2015-06-12 15:34:35 +0100 | [diff] [blame] | 5809 | // End of event ActivityThreadMain. |
| 5810 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5811 | Looper.loop(); |
| 5812 | |
Jeff Brown | 10e8971 | 2011-07-08 18:52:57 -0700 | [diff] [blame] | 5813 | throw new RuntimeException("Main thread loop unexpectedly exited"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5814 | } |
| 5815 | } |