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 | |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 19 | import static android.view.Display.INVALID_DISPLAY; |
| 20 | |
Adam Lesinski | c1b0ebf | 2016-06-09 11:17:10 -0700 | [diff] [blame] | 21 | import android.annotation.NonNull; |
| 22 | import android.annotation.Nullable; |
Dianne Hackborn | 69c6adc | 2015-06-02 10:52:59 -0700 | [diff] [blame] | 23 | import android.app.assist.AssistContent; |
| 24 | import android.app.assist.AssistStructure; |
Christopher Tate | 4528186 | 2010-03-05 15:46:30 -0800 | [diff] [blame] | 25 | import android.app.backup.BackupAgent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 26 | import android.content.BroadcastReceiver; |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 27 | import android.content.ComponentCallbacks2; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | import android.content.ComponentName; |
| 29 | import android.content.ContentProvider; |
| 30 | import android.content.Context; |
| 31 | import android.content.IContentProvider; |
Suchi Amalapurapu | 1ccac75 | 2009-06-12 10:09:58 -0700 | [diff] [blame] | 32 | import android.content.IIntentReceiver; |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 33 | import android.content.Intent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | import android.content.pm.ActivityInfo; |
| 35 | import android.content.pm.ApplicationInfo; |
| 36 | import android.content.pm.IPackageManager; |
| 37 | import android.content.pm.InstrumentationInfo; |
Christopher Tate | 346acb1 | 2012-10-15 19:20:25 -0700 | [diff] [blame] | 38 | import android.content.pm.PackageInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | import android.content.pm.PackageManager; |
Sen Hu | bde7570 | 2010-05-28 01:54:03 -0700 | [diff] [blame] | 40 | import android.content.pm.PackageManager.NameNotFoundException; |
Dianne Hackborn | 3f7c9f2 | 2017-04-04 15:36:33 -0700 | [diff] [blame] | 41 | import android.content.pm.ParceledListSlice; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | import android.content.pm.ProviderInfo; |
| 43 | import android.content.pm.ServiceInfo; |
| 44 | import android.content.res.AssetManager; |
Mitsuru Oshima | ba3ba57 | 2009-07-08 18:49:26 -0700 | [diff] [blame] | 45 | import android.content.res.CompatibilityInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 | import android.content.res.Configuration; |
| 47 | import android.content.res.Resources; |
Alan Viverette | e54d245 | 2015-05-06 10:41:43 -0700 | [diff] [blame] | 48 | import android.content.res.Resources.Theme; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | import android.database.sqlite.SQLiteDatabase; |
| 50 | import android.database.sqlite.SQLiteDebug; |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 51 | import android.database.sqlite.SQLiteDebug.DbStats; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | import android.graphics.Bitmap; |
| 53 | import android.graphics.Canvas; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 54 | import android.hardware.display.DisplayManagerGlobal; |
Paul Jensen | e0bef71 | 2014-12-10 15:12:18 -0500 | [diff] [blame] | 55 | import android.net.ConnectivityManager; |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 56 | import android.net.IConnectivityManager; |
Paul Jensen | e0bef71 | 2014-12-10 15:12:18 -0500 | [diff] [blame] | 57 | import android.net.Network; |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 58 | import android.net.Proxy; |
Jason Monk | 207900c | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 59 | import android.net.ProxyInfo; |
Jason Monk | 83520b9 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 60 | import android.net.Uri; |
Joe Onorato | d630f10 | 2011-03-17 18:42:26 -0700 | [diff] [blame] | 61 | import android.os.AsyncTask; |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 62 | import android.os.Binder; |
Jeff Sharkey | 344744b | 2016-01-28 19:03:30 -0700 | [diff] [blame] | 63 | import android.os.Build; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 64 | import android.os.Bundle; |
| 65 | import android.os.Debug; |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 66 | import android.os.DropBoxManager; |
Jeff Sharkey | b049e21 | 2012-09-07 23:16:01 -0700 | [diff] [blame] | 67 | import android.os.Environment; |
Jesse Hall | b12249b | 2016-12-12 12:53:02 -0800 | [diff] [blame] | 68 | import android.os.GraphicsEnvironment; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | import android.os.Handler; |
| 70 | import android.os.IBinder; |
Adam Lesinski | b61e405 | 2016-05-19 18:23:05 -0700 | [diff] [blame] | 71 | import android.os.LocaleList; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 72 | import android.os.Looper; |
| 73 | import android.os.Message; |
| 74 | import android.os.MessageQueue; |
Dianne Hackborn | fabb70b | 2014-11-11 12:22:36 -0800 | [diff] [blame] | 75 | import android.os.Parcel; |
Dianne Hackborn | 9c8dd55 | 2009-06-23 19:22:52 -0700 | [diff] [blame] | 76 | import android.os.ParcelFileDescriptor; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 77 | import android.os.PersistableBundle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 78 | import android.os.Process; |
| 79 | import android.os.RemoteException; |
| 80 | import android.os.ServiceManager; |
Brad Fitzpatrick | 438d059 | 2010-06-10 12:19:19 -0700 | [diff] [blame] | 81 | import android.os.StrictMode; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 82 | import android.os.SystemClock; |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 83 | import android.os.SystemProperties; |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 84 | import android.os.Trace; |
Jeff Sharkey | 369f509 | 2016-02-29 11:16:21 -0700 | [diff] [blame] | 85 | import android.os.TransactionTooLargeException; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 86 | import android.os.UserHandle; |
Jeff Sharkey | 0a17db1 | 2016-11-04 11:23:46 -0600 | [diff] [blame] | 87 | import android.provider.BlockedNumberContract; |
| 88 | import android.provider.CalendarContract; |
| 89 | import android.provider.CallLog; |
| 90 | import android.provider.ContactsContract; |
| 91 | import android.provider.Downloads; |
Seigo Nonaka | 54084b6 | 2017-04-24 14:46:23 -0700 | [diff] [blame] | 92 | import android.provider.FontsContract; |
Narayan Kamath | ccb2a086 | 2013-12-19 14:49:36 +0000 | [diff] [blame] | 93 | import android.provider.Settings; |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 94 | import android.renderscript.RenderScriptCacheDir; |
Chad Brubaker | c72875b | 2016-04-27 16:35:11 -0700 | [diff] [blame] | 95 | import android.security.NetworkSecurityPolicy; |
Chad Brubaker | 78d4712 | 2015-11-17 22:26:58 -0800 | [diff] [blame] | 96 | import android.security.net.config.NetworkSecurityConfigProvider; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 97 | import android.util.AndroidRuntimeException; |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 98 | import android.util.ArrayMap; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 99 | import android.util.DisplayMetrics; |
| 100 | import android.util.EventLog; |
| 101 | import android.util.Log; |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 102 | import android.util.LogPrinter; |
Jeff Sharkey | a6bfeae | 2017-07-05 16:50:24 -0600 | [diff] [blame] | 103 | import android.util.LogWriter; |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 104 | import android.util.Pair; |
Jeff Brown | 6754ba2 | 2011-12-14 20:20:01 -0800 | [diff] [blame] | 105 | import android.util.PrintWriterPrinter; |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 106 | import android.util.Slog; |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 107 | import android.util.SparseIntArray; |
Adam Powell | 1487466 | 2013-07-18 19:42:41 -0700 | [diff] [blame] | 108 | import android.util.SuperNotCalledException; |
Adam Lesinski | 3ad1b48 | 2016-04-01 16:41:41 -0700 | [diff] [blame] | 109 | import android.view.ContextThemeWrapper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 110 | import android.view.Display; |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 111 | import android.view.ThreadedRenderer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 112 | import android.view.View; |
| 113 | import android.view.ViewDebug; |
| 114 | import android.view.ViewManager; |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 115 | import android.view.ViewRootImpl; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 116 | import android.view.Window; |
| 117 | import android.view.WindowManager; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 118 | import android.view.WindowManagerGlobal; |
Richard Uhler | 2c03619 | 2016-09-14 09:48:31 +0100 | [diff] [blame] | 119 | import android.webkit.WebView; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 120 | |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 121 | import com.android.internal.annotations.GuardedBy; |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 122 | import com.android.internal.app.IVoiceInteractor; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 123 | import com.android.internal.content.ReferrerIntent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 124 | import com.android.internal.os.BinderInternal; |
| 125 | import com.android.internal.os.RuntimeInit; |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 126 | import com.android.internal.os.SomeArgs; |
Jeff Sharkey | 3e19589 | 2016-03-05 19:48:59 -0700 | [diff] [blame] | 127 | import com.android.internal.util.ArrayUtils; |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 128 | import com.android.internal.util.FastPrintWriter; |
Jeff Sharkey | a6bfeae | 2017-07-05 16:50:24 -0600 | [diff] [blame] | 129 | import com.android.internal.util.IndentingPrintWriter; |
Kenny Root | 12e7522 | 2013-04-23 22:34:24 -0700 | [diff] [blame] | 130 | import com.android.org.conscrypt.OpenSSLSocketImpl; |
Robin Lee | 3d076af | 2014-04-25 14:57:49 +0100 | [diff] [blame] | 131 | import com.android.org.conscrypt.TrustedCertificateStore; |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 132 | |
| 133 | import dalvik.system.BaseDexClassLoader; |
| 134 | import dalvik.system.CloseGuard; |
| 135 | import dalvik.system.VMDebug; |
| 136 | import dalvik.system.VMRuntime; |
| 137 | |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 138 | import libcore.io.DropBox; |
| 139 | import libcore.io.EventLogger; |
| 140 | import libcore.io.IoUtils; |
| 141 | import libcore.net.event.NetworkEventDispatcher; |
| 142 | |
| 143 | import org.apache.harmony.dalvik.ddmc.DdmVmInternal; |
| 144 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 145 | import java.io.File; |
| 146 | import java.io.FileDescriptor; |
| 147 | import java.io.FileOutputStream; |
Dianne Hackborn | 9c8dd55 | 2009-06-23 19:22:52 -0700 | [diff] [blame] | 148 | import java.io.IOException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 149 | import java.io.PrintWriter; |
| 150 | import java.lang.ref.WeakReference; |
Svet Ganov | 37e4327 | 2016-09-09 16:01:32 -0700 | [diff] [blame] | 151 | import java.lang.reflect.Field; |
Robert Greenwalt | 03595d0 | 2010-11-02 14:08:23 -0700 | [diff] [blame] | 152 | import java.net.InetAddress; |
Narayan Kamath | ccb2a086 | 2013-12-19 14:49:36 +0000 | [diff] [blame] | 153 | import java.text.DateFormat; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 154 | import java.util.ArrayList; |
Jeff Sharkey | a6bfeae | 2017-07-05 16:50:24 -0600 | [diff] [blame] | 155 | import java.util.Arrays; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 156 | import java.util.List; |
Adam Lesinski | b61e405 | 2016-05-19 18:23:05 -0700 | [diff] [blame] | 157 | import java.util.Locale; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 158 | import java.util.Map; |
Kenny Root | e6585b3 | 2013-12-13 12:00:26 -0800 | [diff] [blame] | 159 | import java.util.Objects; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 160 | import java.util.TimeZone; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 161 | |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 162 | final class RemoteServiceException extends AndroidRuntimeException { |
| 163 | public RemoteServiceException(String msg) { |
| 164 | super(msg); |
| 165 | } |
| 166 | } |
| 167 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 168 | /** |
| 169 | * This manages the execution of the main thread in an |
| 170 | * application process, scheduling and executing activities, |
| 171 | * broadcasts, and other operations on it as the activity |
| 172 | * manager requests. |
| 173 | * |
| 174 | * {@hide} |
| 175 | */ |
| 176 | public final class ActivityThread { |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 177 | /** @hide */ |
| 178 | public static final String TAG = "ActivityThread"; |
Jim Miller | 0b2a6d0 | 2010-07-13 18:01:29 -0700 | [diff] [blame] | 179 | 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] | 180 | static final boolean localLOGV = false; |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 181 | static final boolean DEBUG_MESSAGES = false; |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 182 | /** @hide */ |
| 183 | public static final boolean DEBUG_BROADCAST = false; |
Chris Tate | 8a7dc17 | 2009-03-24 20:11:42 -0700 | [diff] [blame] | 184 | private static final boolean DEBUG_RESULTS = false; |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 185 | private static final boolean DEBUG_BACKUP = false; |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 186 | public static final boolean DEBUG_CONFIGURATION = false; |
Dianne Hackborn | a0c283e | 2012-02-09 10:47:01 -0800 | [diff] [blame] | 187 | private static final boolean DEBUG_SERVICE = false; |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 188 | private static final boolean DEBUG_MEMORY_TRIM = false; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 189 | private static final boolean DEBUG_PROVIDER = false; |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 190 | private static final boolean DEBUG_ORDER = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 191 | 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] | 192 | private static final int SQLITE_MEM_RELEASED_EVENT_LOG_TAG = 75003; |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 193 | private static final int LOG_AM_ON_PAUSE_CALLED = 30021; |
| 194 | private static final int LOG_AM_ON_RESUME_CALLED = 30022; |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 195 | private static final int LOG_AM_ON_STOP_CALLED = 30049; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 196 | |
Dianne Hackborn | 455625e | 2015-01-21 09:55:13 -0800 | [diff] [blame] | 197 | /** Type for IActivityManager.serviceDoneExecuting: anonymous operation */ |
| 198 | public static final int SERVICE_DONE_EXECUTING_ANON = 0; |
| 199 | /** Type for IActivityManager.serviceDoneExecuting: done with an onStart call */ |
| 200 | public static final int SERVICE_DONE_EXECUTING_START = 1; |
| 201 | /** Type for IActivityManager.serviceDoneExecuting: done stopping (destroying) service */ |
| 202 | public static final int SERVICE_DONE_EXECUTING_STOP = 2; |
| 203 | |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 204 | // Details for pausing activity. |
| 205 | private static final int USER_LEAVING = 1; |
| 206 | private static final int DONT_REPORT = 2; |
| 207 | |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 208 | // Whether to invoke an activity callback after delivering new configuration. |
| 209 | private static final boolean REPORT_TO_ACTIVITY = true; |
| 210 | |
Sudheer Shanka | 84a4895 | 2017-03-08 18:19:01 -0800 | [diff] [blame] | 211 | /** |
| 212 | * Denotes an invalid sequence number corresponding to a process state change. |
| 213 | */ |
| 214 | public static final long INVALID_PROC_STATE_SEQ = -1; |
| 215 | |
| 216 | private final Object mNetworkPolicyLock = new Object(); |
| 217 | |
| 218 | /** |
| 219 | * Denotes the sequence number of the process state change for which the main thread needs |
| 220 | * to block until the network rules are updated for it. |
| 221 | * |
| 222 | * Value of {@link #INVALID_PROC_STATE_SEQ} indicates there is no need for blocking. |
| 223 | */ |
| 224 | @GuardedBy("mNetworkPolicyLock") |
| 225 | private long mNetworkBlockSeq = INVALID_PROC_STATE_SEQ; |
| 226 | |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 227 | private ContextImpl mSystemContext; |
Adam Lesinski | a82b626 | 2017-03-21 16:56:17 -0700 | [diff] [blame] | 228 | private ContextImpl mSystemUiContext; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 229 | |
Jeff Sharkey | d589663 | 2016-03-04 16:16:00 -0700 | [diff] [blame] | 230 | static volatile IPackageManager sPackageManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 231 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 232 | final ApplicationThread mAppThread = new ApplicationThread(); |
| 233 | final Looper mLooper = Looper.myLooper(); |
| 234 | final H mH = new H(); |
Dianne Hackborn | 782d498 | 2015-07-08 17:36:37 -0700 | [diff] [blame] | 235 | final ArrayMap<IBinder, ActivityClientRecord> mActivities = new ArrayMap<>(); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 236 | // List of new activities (via ActivityRecord.nextIdle) that should |
| 237 | // be reported when next we idle. |
| 238 | ActivityClientRecord mNewActivities = null; |
| 239 | // Number of activities that are currently visible on-screen. |
| 240 | int mNumVisibleActivities = 0; |
Amith Yamasani | 4f128e4 | 2016-05-10 11:44:12 -0700 | [diff] [blame] | 241 | ArrayList<WeakReference<AssistStructure>> mLastAssistStructures = new ArrayList<>(); |
| 242 | private int mLastSessionId; |
Dianne Hackborn | 782d498 | 2015-07-08 17:36:37 -0700 | [diff] [blame] | 243 | final ArrayMap<IBinder, Service> mServices = new ArrayMap<>(); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 244 | AppBindData mBoundApplication; |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 245 | Profiler mProfiler; |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 246 | int mCurDefaultDisplayDpi; |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 247 | boolean mDensityCompatMode; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 248 | Configuration mConfiguration; |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 249 | Configuration mCompatConfiguration; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 250 | Application mInitialApplication; |
| 251 | final ArrayList<Application> mAllApplications |
| 252 | = new ArrayList<Application>(); |
| 253 | // set of instantiated backup agents, keyed by package name |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 254 | final ArrayMap<String, BackupAgent> mBackupAgents = new ArrayMap<String, BackupAgent>(); |
Jeff Sharkey | 66a017b | 2013-01-17 18:18:22 -0800 | [diff] [blame] | 255 | /** Reference to singleton {@link ActivityThread} */ |
Jeff Sharkey | d589663 | 2016-03-04 16:16:00 -0700 | [diff] [blame] | 256 | private static volatile ActivityThread sCurrentActivityThread; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 257 | Instrumentation mInstrumentation; |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 258 | String mInstrumentationPackageName = null; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 259 | String mInstrumentationAppDir = null; |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 260 | String[] mInstrumentationSplitAppDirs = null; |
| 261 | String mInstrumentationLibDir = null; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 262 | String mInstrumentedAppDir = null; |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 263 | String[] mInstrumentedSplitAppDirs = null; |
| 264 | String mInstrumentedLibDir = null; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 265 | boolean mSystemThread = false; |
| 266 | boolean mJitEnabled = false; |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 267 | boolean mSomeActivitiesChanged = false; |
Chong Zhang | 4951f9d | 2016-06-23 13:15:08 -0700 | [diff] [blame] | 268 | boolean mUpdatingSystemConfig = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 269 | |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 270 | // These can be accessed by multiple threads; mResourcesManager is the lock. |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 271 | // XXX For now we keep around information about all packages we have |
| 272 | // seen, not removing entries from this map. |
Dianne Hackborn | 1fbee79 | 2011-11-30 11:29:58 -0800 | [diff] [blame] | 273 | // NOTE: The activity and window managers need to call in to |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 274 | // ActivityThread to do things like update resource configurations, |
Dianne Hackborn | 1fbee79 | 2011-11-30 11:29:58 -0800 | [diff] [blame] | 275 | // which means this lock gets held while the activity and window managers |
| 276 | // holds their own lock. Thus you MUST NEVER call back into the activity manager |
| 277 | // 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] | 278 | // These LoadedApk are only valid for the userId that we're running as. |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 279 | @GuardedBy("mResourcesManager") |
| 280 | final ArrayMap<String, WeakReference<LoadedApk>> mPackages = new ArrayMap<>(); |
| 281 | @GuardedBy("mResourcesManager") |
| 282 | final ArrayMap<String, WeakReference<LoadedApk>> mResourcePackages = new ArrayMap<>(); |
| 283 | @GuardedBy("mResourcesManager") |
| 284 | final ArrayList<ActivityClientRecord> mRelaunchingActivities = new ArrayList<>(); |
| 285 | @GuardedBy("mResourcesManager") |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 286 | Configuration mPendingConfiguration = null; |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 287 | // Because we merge activity relaunch operations we can't depend on the ordering provided by |
| 288 | // the handler messages. We need to introduce secondary ordering mechanism, which will allow |
| 289 | // us to drop certain events, if we know that they happened before relaunch we already executed. |
| 290 | // This represents the order of receiving the request from AM. |
| 291 | @GuardedBy("mResourcesManager") |
| 292 | int mLifecycleSeq = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 293 | |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 294 | private final ResourcesManager mResourcesManager; |
| 295 | |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 296 | private static final class ProviderKey { |
| 297 | final String authority; |
| 298 | final int userId; |
| 299 | |
| 300 | public ProviderKey(String authority, int userId) { |
| 301 | this.authority = authority; |
| 302 | this.userId = userId; |
| 303 | } |
| 304 | |
| 305 | @Override |
| 306 | public boolean equals(Object o) { |
| 307 | if (o instanceof ProviderKey) { |
| 308 | final ProviderKey other = (ProviderKey) o; |
Kenny Root | e6585b3 | 2013-12-13 12:00:26 -0800 | [diff] [blame] | 309 | return Objects.equals(authority, other.authority) && userId == other.userId; |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 310 | } |
| 311 | return false; |
| 312 | } |
| 313 | |
| 314 | @Override |
| 315 | public int hashCode() { |
| 316 | return ((authority != null) ? authority.hashCode() : 0) ^ userId; |
| 317 | } |
| 318 | } |
| 319 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 320 | // The lock of mProviderMap protects the following variables. |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 321 | final ArrayMap<ProviderKey, ProviderClientRecord> mProviderMap |
| 322 | = new ArrayMap<ProviderKey, ProviderClientRecord>(); |
| 323 | final ArrayMap<IBinder, ProviderRefCount> mProviderRefCountMap |
| 324 | = new ArrayMap<IBinder, ProviderRefCount>(); |
| 325 | final ArrayMap<IBinder, ProviderClientRecord> mLocalProviders |
| 326 | = new ArrayMap<IBinder, ProviderClientRecord>(); |
| 327 | final ArrayMap<ComponentName, ProviderClientRecord> mLocalProvidersByName |
| 328 | = new ArrayMap<ComponentName, ProviderClientRecord>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 329 | |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 330 | final ArrayMap<Activity, ArrayList<OnActivityPausedListener>> mOnPauseListeners |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 331 | = new ArrayMap<Activity, ArrayList<OnActivityPausedListener>>(); |
Jeff Hamilton | 52d3203 | 2011-01-08 15:31:26 -0600 | [diff] [blame] | 332 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 333 | final GcIdler mGcIdler = new GcIdler(); |
| 334 | boolean mGcIdlerScheduled = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 335 | |
Jeff Sharkey | d589663 | 2016-03-04 16:16:00 -0700 | [diff] [blame] | 336 | static volatile Handler sMainThreadHandler; // set once in main() |
Brad Fitzpatrick | 333b8cb | 2010-08-26 12:04:57 -0700 | [diff] [blame] | 337 | |
Svetoslav Ganov | 9aa597e | 2011-03-03 18:17:41 -0800 | [diff] [blame] | 338 | Bundle mCoreSettings = null; |
| 339 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 340 | static final class ActivityClientRecord { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 341 | IBinder token; |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 342 | int ident; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 343 | Intent intent; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 344 | String referrer; |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 345 | IVoiceInteractor voiceInteractor; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 346 | Bundle state; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 347 | PersistableBundle persistentState; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 348 | Activity activity; |
| 349 | Window window; |
| 350 | Activity parent; |
| 351 | String embeddedID; |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 352 | Activity.NonConfigurationInstances lastNonConfigurationInstances; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 353 | boolean paused; |
| 354 | boolean stopped; |
| 355 | boolean hideForNow; |
| 356 | Configuration newConfig; |
Dianne Hackborn | e88846e | 2009-09-30 21:34:25 -0700 | [diff] [blame] | 357 | Configuration createdConfig; |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 358 | Configuration overrideConfig; |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 359 | // Used for consolidating configs before sending on to Activity. |
| 360 | private Configuration tmpConfig = new Configuration(); |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 361 | // Callback used for updating activity override config. |
| 362 | ViewRootImpl.ActivityConfigCallback configCallback; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 363 | ActivityClientRecord nextIdle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 364 | |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 365 | ProfilerInfo profilerInfo; |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 366 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 367 | ActivityInfo activityInfo; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 368 | CompatibilityInfo compatInfo; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 369 | LoadedApk packageInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 370 | |
| 371 | List<ResultInfo> pendingResults; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 372 | List<ReferrerIntent> pendingIntents; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 373 | |
| 374 | boolean startsNotResumed; |
| 375 | boolean isForward; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 376 | int pendingConfigChanges; |
| 377 | boolean onlyLocalRequest; |
| 378 | |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 379 | Window mPendingRemoveWindow; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 380 | WindowManager mPendingRemoveWindowManager; |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 381 | boolean mPreserveWindow; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 382 | |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 383 | // Set for relaunch requests, indicates the order number of the relaunch operation, so it |
| 384 | // can be compared with other lifecycle operations. |
| 385 | int relaunchSeq = 0; |
| 386 | |
| 387 | // Can only be accessed from the UI thread. This represents the latest processed message |
| 388 | // that is related to lifecycle events/ |
| 389 | int lastProcessedSeq = 0; |
| 390 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 391 | ActivityClientRecord() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 392 | parent = null; |
| 393 | embeddedID = null; |
| 394 | paused = false; |
| 395 | stopped = false; |
| 396 | hideForNow = false; |
| 397 | nextIdle = null; |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 398 | configCallback = (Configuration overrideConfig, int newDisplayId) -> { |
| 399 | if (activity == null) { |
| 400 | throw new IllegalStateException( |
| 401 | "Received config update for non-existing activity"); |
| 402 | } |
| 403 | activity.mMainThread.handleActivityConfigurationChanged( |
| 404 | new ActivityConfigChangeData(token, overrideConfig), newDisplayId); |
| 405 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 406 | } |
| 407 | |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 408 | public boolean isPreHoneycomb() { |
| 409 | if (activity != null) { |
| 410 | return activity.getApplicationInfo().targetSdkVersion |
| 411 | < android.os.Build.VERSION_CODES.HONEYCOMB; |
| 412 | } |
| 413 | return false; |
| 414 | } |
| 415 | |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 416 | public boolean isPersistable() { |
Craig Mautner | 43e52ed | 2014-06-16 17:18:52 -0700 | [diff] [blame] | 417 | return activityInfo.persistableMode == ActivityInfo.PERSIST_ACROSS_REBOOTS; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 418 | } |
| 419 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 420 | public String toString() { |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 421 | ComponentName componentName = intent != null ? intent.getComponent() : null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 422 | return "ActivityRecord{" |
| 423 | + Integer.toHexString(System.identityHashCode(this)) |
| 424 | + " token=" + token + " " + (componentName == null |
| 425 | ? "no component name" : componentName.toShortString()) |
| 426 | + "}"; |
| 427 | } |
Andrii Kulian | 58178f2 | 2016-03-16 13:44:56 -0700 | [diff] [blame] | 428 | |
| 429 | public String getStateString() { |
| 430 | StringBuilder sb = new StringBuilder(); |
| 431 | sb.append("ActivityClientRecord{"); |
| 432 | sb.append("paused=").append(paused); |
| 433 | sb.append(", stopped=").append(stopped); |
| 434 | sb.append(", hideForNow=").append(hideForNow); |
| 435 | sb.append(", startsNotResumed=").append(startsNotResumed); |
| 436 | sb.append(", isForward=").append(isForward); |
| 437 | sb.append(", pendingConfigChanges=").append(pendingConfigChanges); |
| 438 | sb.append(", onlyLocalRequest=").append(onlyLocalRequest); |
| 439 | sb.append(", preserveWindow=").append(mPreserveWindow); |
| 440 | if (activity != null) { |
| 441 | sb.append(", Activity{"); |
| 442 | sb.append("resumed=").append(activity.mResumed); |
| 443 | sb.append(", stopped=").append(activity.mStopped); |
| 444 | sb.append(", finished=").append(activity.isFinishing()); |
| 445 | sb.append(", destroyed=").append(activity.isDestroyed()); |
| 446 | sb.append(", startedActivity=").append(activity.mStartedActivity); |
| 447 | sb.append(", temporaryPause=").append(activity.mTemporaryPause); |
| 448 | sb.append(", changingConfigurations=").append(activity.mChangingConfigurations); |
Andrii Kulian | 58178f2 | 2016-03-16 13:44:56 -0700 | [diff] [blame] | 449 | sb.append("}"); |
| 450 | } |
| 451 | sb.append("}"); |
| 452 | return sb.toString(); |
| 453 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 454 | } |
| 455 | |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 456 | final class ProviderClientRecord { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 457 | final String[] mNames; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 458 | final IContentProvider mProvider; |
| 459 | final ContentProvider mLocalProvider; |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 460 | final ContentProviderHolder mHolder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 461 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 462 | ProviderClientRecord(String[] names, IContentProvider provider, |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 463 | ContentProvider localProvider, ContentProviderHolder holder) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 464 | mNames = names; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 465 | mProvider = provider; |
| 466 | mLocalProvider = localProvider; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 467 | mHolder = holder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 468 | } |
| 469 | } |
| 470 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 471 | static final class NewIntentData { |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 472 | List<ReferrerIntent> intents; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 473 | IBinder token; |
Wale Ogunwale | 826c706 | 2016-09-13 08:25:54 -0700 | [diff] [blame] | 474 | boolean andPause; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 475 | public String toString() { |
Wale Ogunwale | 826c706 | 2016-09-13 08:25:54 -0700 | [diff] [blame] | 476 | return "NewIntentData{intents=" + intents + " token=" + token |
| 477 | + " andPause=" + andPause +"}"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 478 | } |
| 479 | } |
| 480 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 481 | static final class ReceiverData extends BroadcastReceiver.PendingResult { |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 482 | public ReceiverData(Intent intent, int resultCode, String resultData, Bundle resultExtras, |
Dianne Hackborn | 20e8098 | 2012-08-31 19:00:44 -0700 | [diff] [blame] | 483 | boolean ordered, boolean sticky, IBinder token, int sendingUser) { |
| 484 | super(resultCode, resultData, resultExtras, TYPE_COMPONENT, ordered, sticky, |
riddle_hsu | 1f5ac4d | 2015-01-03 15:38:21 +0800 | [diff] [blame] | 485 | token, sendingUser, intent.getFlags()); |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 486 | this.intent = intent; |
| 487 | } |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 488 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 489 | Intent intent; |
| 490 | ActivityInfo info; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 491 | CompatibilityInfo compatInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 492 | public String toString() { |
| 493 | return "ReceiverData{intent=" + intent + " packageName=" + |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 494 | info.packageName + " resultCode=" + getResultCode() |
| 495 | + " resultData=" + getResultData() + " resultExtras=" |
| 496 | + getResultExtras(false) + "}"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 497 | } |
| 498 | } |
| 499 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 500 | static final class CreateBackupAgentData { |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 501 | ApplicationInfo appInfo; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 502 | CompatibilityInfo compatInfo; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 503 | int backupMode; |
| 504 | public String toString() { |
| 505 | return "CreateBackupAgentData{appInfo=" + appInfo |
| 506 | + " backupAgent=" + appInfo.backupAgentName |
| 507 | + " mode=" + backupMode + "}"; |
| 508 | } |
| 509 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 510 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 511 | static final class CreateServiceData { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 512 | IBinder token; |
| 513 | ServiceInfo info; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 514 | CompatibilityInfo compatInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 515 | Intent intent; |
| 516 | public String toString() { |
| 517 | return "CreateServiceData{token=" + token + " className=" |
| 518 | + info.name + " packageName=" + info.packageName |
| 519 | + " intent=" + intent + "}"; |
| 520 | } |
| 521 | } |
| 522 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 523 | static final class BindServiceData { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 524 | IBinder token; |
| 525 | Intent intent; |
| 526 | boolean rebind; |
| 527 | public String toString() { |
| 528 | return "BindServiceData{token=" + token + " intent=" + intent + "}"; |
| 529 | } |
| 530 | } |
| 531 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 532 | static final class ServiceArgsData { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 533 | IBinder token; |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 534 | boolean taskRemoved; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 535 | int startId; |
Dianne Hackborn | f6f9f2d | 2009-08-21 16:26:03 -0700 | [diff] [blame] | 536 | int flags; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 537 | Intent args; |
| 538 | public String toString() { |
| 539 | return "ServiceArgsData{token=" + token + " startId=" + startId |
| 540 | + " args=" + args + "}"; |
| 541 | } |
| 542 | } |
| 543 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 544 | static final class AppBindData { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 545 | LoadedApk info; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 546 | String processName; |
| 547 | ApplicationInfo appInfo; |
| 548 | List<ProviderInfo> providers; |
| 549 | ComponentName instrumentationName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 550 | Bundle instrumentationArgs; |
| 551 | IInstrumentationWatcher instrumentationWatcher; |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 552 | IUiAutomationConnection instrumentationUiAutomationConnection; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 553 | int debugMode; |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 554 | boolean enableBinderTracking; |
Man Cao | cfa78b2 | 2015-06-11 20:14:34 -0700 | [diff] [blame] | 555 | boolean trackAllocation; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 556 | boolean restrictedBackupMode; |
Dianne Hackborn | 5d927c2 | 2011-09-02 12:22:18 -0700 | [diff] [blame] | 557 | boolean persistent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 558 | Configuration config; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 559 | CompatibilityInfo compatInfo; |
Svet Ganov | 37e4327 | 2016-09-09 16:01:32 -0700 | [diff] [blame] | 560 | String buildSerial; |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 561 | |
| 562 | /** Initial values for {@link Profiler}. */ |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 563 | ProfilerInfo initProfilerInfo; |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 564 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 565 | public String toString() { |
| 566 | return "AppBindData{appInfo=" + appInfo + "}"; |
| 567 | } |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 568 | } |
| 569 | |
| 570 | static final class Profiler { |
| 571 | String profileFile; |
| 572 | ParcelFileDescriptor profileFd; |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 573 | int samplingInterval; |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 574 | boolean autoStopProfiler; |
Shukang Zhou | 6ffd4f9 | 2017-01-25 16:07:57 -0800 | [diff] [blame] | 575 | boolean streamingOutput; |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 576 | boolean profiling; |
| 577 | boolean handlingProfiling; |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 578 | public void setProfiler(ProfilerInfo profilerInfo) { |
| 579 | ParcelFileDescriptor fd = profilerInfo.profileFd; |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 580 | if (profiling) { |
| 581 | if (fd != null) { |
| 582 | try { |
| 583 | fd.close(); |
| 584 | } catch (IOException e) { |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 585 | // Ignore |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 586 | } |
| 587 | } |
| 588 | return; |
| 589 | } |
| 590 | if (profileFd != null) { |
| 591 | try { |
| 592 | profileFd.close(); |
| 593 | } catch (IOException e) { |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 594 | // Ignore |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 595 | } |
| 596 | } |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 597 | profileFile = profilerInfo.profileFile; |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 598 | profileFd = fd; |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 599 | samplingInterval = profilerInfo.samplingInterval; |
| 600 | autoStopProfiler = profilerInfo.autoStopProfiler; |
Shukang Zhou | 6ffd4f9 | 2017-01-25 16:07:57 -0800 | [diff] [blame] | 601 | streamingOutput = profilerInfo.streamingOutput; |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 602 | } |
| 603 | public void startProfiling() { |
| 604 | if (profileFd == null || profiling) { |
| 605 | return; |
| 606 | } |
| 607 | try { |
Andreas Gampe | eff0639 | 2016-05-10 12:51:45 -0700 | [diff] [blame] | 608 | int bufferSize = SystemProperties.getInt("debug.traceview-buffer-size-mb", 8); |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 609 | VMDebug.startMethodTracing(profileFile, profileFd.getFileDescriptor(), |
Shukang Zhou | 6ffd4f9 | 2017-01-25 16:07:57 -0800 | [diff] [blame] | 610 | bufferSize * 1024 * 1024, 0, samplingInterval != 0, samplingInterval, |
| 611 | streamingOutput); |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 612 | profiling = true; |
| 613 | } catch (RuntimeException e) { |
| 614 | Slog.w(TAG, "Profiling failed on path " + profileFile); |
| 615 | try { |
| 616 | profileFd.close(); |
| 617 | profileFd = null; |
| 618 | } catch (IOException e2) { |
| 619 | Slog.w(TAG, "Failure closing profile fd", e2); |
| 620 | } |
| 621 | } |
| 622 | } |
| 623 | public void stopProfiling() { |
| 624 | if (profiling) { |
| 625 | profiling = false; |
| 626 | Debug.stopMethodTracing(); |
| 627 | if (profileFd != null) { |
| 628 | try { |
| 629 | profileFd.close(); |
| 630 | } catch (IOException e) { |
| 631 | } |
| 632 | } |
| 633 | profileFd = null; |
| 634 | profileFile = null; |
| 635 | } |
| 636 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 637 | } |
| 638 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 639 | static final class DumpComponentInfo { |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 640 | ParcelFileDescriptor fd; |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 641 | IBinder token; |
Dianne Hackborn | 30d7189 | 2010-12-11 10:37:55 -0800 | [diff] [blame] | 642 | String prefix; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 643 | String[] args; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 644 | } |
| 645 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 646 | static final class ResultData { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 647 | IBinder token; |
| 648 | List<ResultInfo> results; |
| 649 | public String toString() { |
| 650 | return "ResultData{token=" + token + " results" + results + "}"; |
| 651 | } |
| 652 | } |
| 653 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 654 | static final class ContextCleanupInfo { |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 655 | ContextImpl context; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 656 | String what; |
| 657 | String who; |
| 658 | } |
| 659 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 660 | static final class DumpHeapData { |
Christopher Ferris | 8d652f8 | 2017-04-11 16:29:18 -0700 | [diff] [blame] | 661 | public boolean managed; |
| 662 | public boolean mallocInfo; |
Makoto Onuki | 4556b7b | 2017-07-07 14:58:58 -0700 | [diff] [blame] | 663 | public boolean runGc; |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 664 | String path; |
| 665 | ParcelFileDescriptor fd; |
| 666 | } |
| 667 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 668 | static final class UpdateCompatibilityData { |
| 669 | String pkg; |
| 670 | CompatibilityInfo info; |
| 671 | } |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 672 | |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 673 | static final class RequestAssistContextExtras { |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 674 | IBinder activityToken; |
| 675 | IBinder requestToken; |
| 676 | int requestType; |
Amith Yamasani | 4f128e4 | 2016-05-10 11:44:12 -0700 | [diff] [blame] | 677 | int sessionId; |
Svet Ganov | fd31f85 | 2017-04-26 15:54:27 -0700 | [diff] [blame] | 678 | int flags; |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 679 | } |
Anwar Ghuloum | 3a8ce1b | 2013-04-26 16:18:28 -0700 | [diff] [blame] | 680 | |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 681 | static final class ActivityConfigChangeData { |
| 682 | final IBinder activityToken; |
| 683 | final Configuration overrideConfig; |
| 684 | public ActivityConfigChangeData(IBinder token, Configuration config) { |
| 685 | activityToken = token; |
| 686 | overrideConfig = config; |
| 687 | } |
| 688 | } |
| 689 | |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 690 | private class ApplicationThread extends IApplicationThread.Stub { |
Vasu Nori | 3c7131f | 2010-09-21 14:36:57 -0700 | [diff] [blame] | 691 | private static final String DB_INFO_FORMAT = " %8s %8s %14s %14s %s"; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 692 | |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 693 | private int mLastProcessState = -1; |
| 694 | |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 695 | private void updatePendingConfiguration(Configuration config) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 696 | synchronized (mResourcesManager) { |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 697 | if (mPendingConfiguration == null || |
| 698 | mPendingConfiguration.isOtherSeqNewer(config)) { |
| 699 | mPendingConfiguration = config; |
| 700 | } |
| 701 | } |
| 702 | } |
| 703 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 704 | public final void schedulePauseActivity(IBinder token, boolean finished, |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 705 | boolean userLeaving, int configChanges, boolean dontReport) { |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 706 | int seq = getLifecycleSeq(); |
| 707 | if (DEBUG_ORDER) Slog.d(TAG, "pauseActivity " + ActivityThread.this |
| 708 | + " operation received seq: " + seq); |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 709 | sendMessage( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 710 | finished ? H.PAUSE_ACTIVITY_FINISHING : H.PAUSE_ACTIVITY, |
| 711 | token, |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 712 | (userLeaving ? USER_LEAVING : 0) | (dontReport ? DONT_REPORT : 0), |
| 713 | configChanges, |
| 714 | seq); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 715 | } |
| 716 | |
| 717 | public final void scheduleStopActivity(IBinder token, boolean showWindow, |
| 718 | int configChanges) { |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 719 | int seq = getLifecycleSeq(); |
| 720 | if (DEBUG_ORDER) Slog.d(TAG, "stopActivity " + ActivityThread.this |
| 721 | + " operation received seq: " + seq); |
| 722 | sendMessage( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 723 | showWindow ? H.STOP_ACTIVITY_SHOW : H.STOP_ACTIVITY_HIDE, |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 724 | token, 0, configChanges, seq); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 725 | } |
| 726 | |
| 727 | public final void scheduleWindowVisibility(IBinder token, boolean showWindow) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 728 | sendMessage( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 729 | showWindow ? H.SHOW_WINDOW : H.HIDE_WINDOW, |
| 730 | token); |
| 731 | } |
| 732 | |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 733 | public final void scheduleSleeping(IBinder token, boolean sleeping) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 734 | sendMessage(H.SLEEPING, token, sleeping ? 1 : 0); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 735 | } |
| 736 | |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 737 | public final void scheduleResumeActivity(IBinder token, int processState, |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 738 | boolean isForward, Bundle resumeArgs) { |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 739 | int seq = getLifecycleSeq(); |
| 740 | if (DEBUG_ORDER) Slog.d(TAG, "resumeActivity " + ActivityThread.this |
| 741 | + " operation received seq: " + seq); |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 742 | updateProcessState(processState, false); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 743 | 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] | 744 | } |
| 745 | |
| 746 | public final void scheduleSendResult(IBinder token, List<ResultInfo> results) { |
| 747 | ResultData res = new ResultData(); |
| 748 | res.token = token; |
| 749 | res.results = results; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 750 | sendMessage(H.SEND_RESULT, res); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 751 | } |
| 752 | |
| 753 | // we use token to identify this activity without having to send the |
| 754 | // activity itself back to the activity manager. (matters more with ipc) |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 755 | @Override |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 756 | public final void scheduleLaunchActivity(Intent intent, IBinder token, int ident, |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 757 | ActivityInfo info, Configuration curConfig, Configuration overrideConfig, |
| 758 | CompatibilityInfo compatInfo, String referrer, IVoiceInteractor voiceInteractor, |
| 759 | int procState, Bundle state, PersistableBundle persistentState, |
| 760 | List<ResultInfo> pendingResults, List<ReferrerIntent> pendingNewIntents, |
| 761 | boolean notResumed, boolean isForward, ProfilerInfo profilerInfo) { |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 762 | |
| 763 | updateProcessState(procState, false); |
| 764 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 765 | ActivityClientRecord r = new ActivityClientRecord(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 766 | |
| 767 | r.token = token; |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 768 | r.ident = ident; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 769 | r.intent = intent; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 770 | r.referrer = referrer; |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 771 | r.voiceInteractor = voiceInteractor; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 772 | r.activityInfo = info; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 773 | r.compatInfo = compatInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 774 | r.state = state; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 775 | r.persistentState = persistentState; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 776 | |
| 777 | r.pendingResults = pendingResults; |
| 778 | r.pendingIntents = pendingNewIntents; |
| 779 | |
| 780 | r.startsNotResumed = notResumed; |
| 781 | r.isForward = isForward; |
| 782 | |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 783 | r.profilerInfo = profilerInfo; |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 784 | |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 785 | r.overrideConfig = overrideConfig; |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 786 | updatePendingConfiguration(curConfig); |
| 787 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 788 | sendMessage(H.LAUNCH_ACTIVITY, r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 789 | } |
| 790 | |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 791 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 792 | public final void scheduleRelaunchActivity(IBinder token, |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 793 | List<ResultInfo> pendingResults, List<ReferrerIntent> pendingNewIntents, |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 794 | int configChanges, boolean notResumed, Configuration config, |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 795 | Configuration overrideConfig, boolean preserveWindow) { |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 796 | requestRelaunchActivity(token, pendingResults, pendingNewIntents, |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 797 | configChanges, notResumed, config, overrideConfig, true, preserveWindow); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 798 | } |
| 799 | |
Wale Ogunwale | 826c706 | 2016-09-13 08:25:54 -0700 | [diff] [blame] | 800 | public final void scheduleNewIntent( |
| 801 | List<ReferrerIntent> intents, IBinder token, boolean andPause) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 802 | NewIntentData data = new NewIntentData(); |
| 803 | data.intents = intents; |
| 804 | data.token = token; |
Wale Ogunwale | 826c706 | 2016-09-13 08:25:54 -0700 | [diff] [blame] | 805 | data.andPause = andPause; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 806 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 807 | sendMessage(H.NEW_INTENT, data); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 808 | } |
| 809 | |
| 810 | public final void scheduleDestroyActivity(IBinder token, boolean finishing, |
| 811 | int configChanges) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 812 | sendMessage(H.DESTROY_ACTIVITY, token, finishing ? 1 : 0, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 813 | configChanges); |
| 814 | } |
| 815 | |
| 816 | public final void scheduleReceiver(Intent intent, ActivityInfo info, |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 817 | CompatibilityInfo compatInfo, int resultCode, String data, Bundle extras, |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 818 | boolean sync, int sendingUser, int processState) { |
| 819 | updateProcessState(processState, false); |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 820 | ReceiverData r = new ReceiverData(intent, resultCode, data, extras, |
Dianne Hackborn | 20e8098 | 2012-08-31 19:00:44 -0700 | [diff] [blame] | 821 | sync, false, mAppThread.asBinder(), sendingUser); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 822 | r.info = info; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 823 | r.compatInfo = compatInfo; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 824 | sendMessage(H.RECEIVER, r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 825 | } |
| 826 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 827 | public final void scheduleCreateBackupAgent(ApplicationInfo app, |
| 828 | CompatibilityInfo compatInfo, int backupMode) { |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 829 | CreateBackupAgentData d = new CreateBackupAgentData(); |
| 830 | d.appInfo = app; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 831 | d.compatInfo = compatInfo; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 832 | d.backupMode = backupMode; |
| 833 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 834 | sendMessage(H.CREATE_BACKUP_AGENT, d); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 835 | } |
| 836 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 837 | public final void scheduleDestroyBackupAgent(ApplicationInfo app, |
| 838 | CompatibilityInfo compatInfo) { |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 839 | CreateBackupAgentData d = new CreateBackupAgentData(); |
| 840 | d.appInfo = app; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 841 | d.compatInfo = compatInfo; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 842 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 843 | sendMessage(H.DESTROY_BACKUP_AGENT, d); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 844 | } |
| 845 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 846 | public final void scheduleCreateService(IBinder token, |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 847 | ServiceInfo info, CompatibilityInfo compatInfo, int processState) { |
| 848 | updateProcessState(processState, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 849 | CreateServiceData s = new CreateServiceData(); |
| 850 | s.token = token; |
| 851 | s.info = info; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 852 | s.compatInfo = compatInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 853 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 854 | sendMessage(H.CREATE_SERVICE, s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 855 | } |
| 856 | |
| 857 | public final void scheduleBindService(IBinder token, Intent intent, |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 858 | boolean rebind, int processState) { |
| 859 | updateProcessState(processState, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 860 | BindServiceData s = new BindServiceData(); |
| 861 | s.token = token; |
| 862 | s.intent = intent; |
| 863 | s.rebind = rebind; |
| 864 | |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 865 | if (DEBUG_SERVICE) |
| 866 | Slog.v(TAG, "scheduleBindService token=" + token + " intent=" + intent + " uid=" |
| 867 | + Binder.getCallingUid() + " pid=" + Binder.getCallingPid()); |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 868 | sendMessage(H.BIND_SERVICE, s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 869 | } |
| 870 | |
| 871 | public final void scheduleUnbindService(IBinder token, Intent intent) { |
| 872 | BindServiceData s = new BindServiceData(); |
| 873 | s.token = token; |
| 874 | s.intent = intent; |
| 875 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 876 | sendMessage(H.UNBIND_SERVICE, s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 877 | } |
| 878 | |
Dianne Hackborn | 3f7c9f2 | 2017-04-04 15:36:33 -0700 | [diff] [blame] | 879 | public final void scheduleServiceArgs(IBinder token, ParceledListSlice args) { |
| 880 | List<ServiceStartArgs> list = args.getList(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 881 | |
Dianne Hackborn | 3f7c9f2 | 2017-04-04 15:36:33 -0700 | [diff] [blame] | 882 | for (int i = 0; i < list.size(); i++) { |
| 883 | ServiceStartArgs ssa = list.get(i); |
| 884 | ServiceArgsData s = new ServiceArgsData(); |
| 885 | s.token = token; |
| 886 | s.taskRemoved = ssa.taskRemoved; |
| 887 | s.startId = ssa.startId; |
| 888 | s.flags = ssa.flags; |
| 889 | s.args = ssa.args; |
| 890 | |
| 891 | sendMessage(H.SERVICE_ARGS, s); |
| 892 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 893 | } |
| 894 | |
| 895 | public final void scheduleStopService(IBinder token) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 896 | sendMessage(H.STOP_SERVICE, token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 897 | } |
| 898 | |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 899 | public final void bindApplication(String processName, ApplicationInfo appInfo, |
| 900 | List<ProviderInfo> providers, ComponentName instrumentationName, |
| 901 | ProfilerInfo profilerInfo, Bundle instrumentationArgs, |
| 902 | IInstrumentationWatcher instrumentationWatcher, |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 903 | IUiAutomationConnection instrumentationUiConnection, int debugMode, |
Pablo Ceballos | a4d4e82 | 2015-10-05 10:27:52 -0700 | [diff] [blame] | 904 | boolean enableBinderTracking, boolean trackAllocation, |
| 905 | boolean isRestrictedBackupMode, boolean persistent, Configuration config, |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 906 | CompatibilityInfo compatInfo, Map services, Bundle coreSettings, |
Svet Ganov | 37e4327 | 2016-09-09 16:01:32 -0700 | [diff] [blame] | 907 | String buildSerial) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 908 | |
| 909 | if (services != null) { |
| 910 | // Setup the service cache in the ServiceManager |
| 911 | ServiceManager.initServiceCache(services); |
| 912 | } |
| 913 | |
Svetoslav Ganov | 9aa597e | 2011-03-03 18:17:41 -0800 | [diff] [blame] | 914 | setCoreSettings(coreSettings); |
| 915 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 916 | AppBindData data = new AppBindData(); |
| 917 | data.processName = processName; |
| 918 | data.appInfo = appInfo; |
| 919 | data.providers = providers; |
| 920 | data.instrumentationName = instrumentationName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 921 | data.instrumentationArgs = instrumentationArgs; |
| 922 | data.instrumentationWatcher = instrumentationWatcher; |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 923 | data.instrumentationUiAutomationConnection = instrumentationUiConnection; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 924 | data.debugMode = debugMode; |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 925 | data.enableBinderTracking = enableBinderTracking; |
Man Cao | cfa78b2 | 2015-06-11 20:14:34 -0700 | [diff] [blame] | 926 | data.trackAllocation = trackAllocation; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 927 | data.restrictedBackupMode = isRestrictedBackupMode; |
Dianne Hackborn | 5d927c2 | 2011-09-02 12:22:18 -0700 | [diff] [blame] | 928 | data.persistent = persistent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 929 | data.config = config; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 930 | data.compatInfo = compatInfo; |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 931 | data.initProfilerInfo = profilerInfo; |
Svet Ganov | 37e4327 | 2016-09-09 16:01:32 -0700 | [diff] [blame] | 932 | data.buildSerial = buildSerial; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 933 | sendMessage(H.BIND_APPLICATION, data); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 934 | } |
| 935 | |
| 936 | public final void scheduleExit() { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 937 | sendMessage(H.EXIT_APPLICATION, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 938 | } |
| 939 | |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 940 | public final void scheduleSuicide() { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 941 | sendMessage(H.SUICIDE, null); |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 942 | } |
| 943 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 944 | public void scheduleConfigurationChanged(Configuration config) { |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 945 | updatePendingConfiguration(config); |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 946 | sendMessage(H.CONFIGURATION_CHANGED, config); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 947 | } |
| 948 | |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 949 | public void scheduleApplicationInfoChanged(ApplicationInfo ai) { |
| 950 | sendMessage(H.APPLICATION_INFO_CHANGED, ai); |
| 951 | } |
| 952 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 953 | public void updateTimeZone() { |
| 954 | TimeZone.setDefault(null); |
| 955 | } |
| 956 | |
Robert Greenwalt | 03595d0 | 2010-11-02 14:08:23 -0700 | [diff] [blame] | 957 | public void clearDnsCache() { |
| 958 | // a non-standard API to get this to libcore |
| 959 | InetAddress.clearDnsCache(); |
Paul Jensen | e401d17 | 2014-09-12 10:47:39 -0400 | [diff] [blame] | 960 | // Allow libcore to perform the necessary actions as it sees fit upon a network |
| 961 | // configuration change. |
| 962 | NetworkEventDispatcher.getInstance().onNetworkConfigurationChanged(); |
Robert Greenwalt | 03595d0 | 2010-11-02 14:08:23 -0700 | [diff] [blame] | 963 | } |
| 964 | |
Jason Monk | 83520b9 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 965 | public void setHttpProxy(String host, String port, String exclList, Uri pacFileUrl) { |
Paul Jensen | 72db88e | 2015-03-10 10:54:12 -0400 | [diff] [blame] | 966 | final ConnectivityManager cm = ConnectivityManager.from(getSystemContext()); |
| 967 | final Network network = cm.getBoundNetworkForProcess(); |
Paul Jensen | e0bef71 | 2014-12-10 15:12:18 -0500 | [diff] [blame] | 968 | if (network != null) { |
Paul Jensen | 72db88e | 2015-03-10 10:54:12 -0400 | [diff] [blame] | 969 | Proxy.setHttpProxySystemProperty(cm.getDefaultProxy()); |
Paul Jensen | e0bef71 | 2014-12-10 15:12:18 -0500 | [diff] [blame] | 970 | } else { |
| 971 | Proxy.setHttpProxySystemProperty(host, port, exclList, pacFileUrl); |
| 972 | } |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 973 | } |
| 974 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 975 | public void processInBackground() { |
| 976 | mH.removeMessages(H.GC_WHEN_IDLE); |
| 977 | mH.sendMessage(mH.obtainMessage(H.GC_WHEN_IDLE)); |
| 978 | } |
| 979 | |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 980 | public void dumpService(ParcelFileDescriptor pfd, IBinder servicetoken, String[] args) { |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 981 | DumpComponentInfo data = new DumpComponentInfo(); |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 982 | try { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 983 | data.fd = pfd.dup(); |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 984 | data.token = servicetoken; |
| 985 | data.args = args; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 986 | sendMessage(H.DUMP_SERVICE, data, 0, 0, true /*async*/); |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 987 | } catch (IOException e) { |
| 988 | Slog.w(TAG, "dumpService failed", e); |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 989 | } finally { |
| 990 | IoUtils.closeQuietly(pfd); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 991 | } |
| 992 | } |
| 993 | |
| 994 | // This function exists to make sure all receiver dispatching is |
| 995 | // correctly ordered, since these are one-way calls and the binder driver |
| 996 | // applies transaction ordering per object for such calls. |
| 997 | public void scheduleRegisteredReceiver(IIntentReceiver receiver, Intent intent, |
Dianne Hackborn | 68d881c | 2009-10-05 13:58:17 -0700 | [diff] [blame] | 998 | int resultCode, String dataStr, Bundle extras, boolean ordered, |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 999 | boolean sticky, int sendingUser, int processState) throws RemoteException { |
| 1000 | updateProcessState(processState, false); |
Dianne Hackborn | 20e8098 | 2012-08-31 19:00:44 -0700 | [diff] [blame] | 1001 | receiver.performReceive(intent, resultCode, dataStr, extras, ordered, |
| 1002 | sticky, sendingUser); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1003 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1004 | |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 1005 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1006 | public void scheduleLowMemory() { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1007 | sendMessage(H.LOW_MEMORY, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1008 | } |
| 1009 | |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 1010 | @Override |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 1011 | public void scheduleActivityConfigurationChanged( |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 1012 | IBinder token, Configuration overrideConfig) { |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 1013 | sendMessage(H.ACTIVITY_CONFIGURATION_CHANGED, |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 1014 | new ActivityConfigChangeData(token, overrideConfig)); |
| 1015 | } |
| 1016 | |
| 1017 | @Override |
| 1018 | public void scheduleActivityMovedToDisplay(IBinder token, int displayId, |
| 1019 | Configuration overrideConfig) { |
| 1020 | sendMessage(H.ACTIVITY_MOVED_TO_DISPLAY, |
| 1021 | new ActivityConfigChangeData(token, overrideConfig), displayId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1022 | } |
| 1023 | |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 1024 | @Override |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 1025 | public void profilerControl(boolean start, ProfilerInfo profilerInfo, int profileType) { |
| 1026 | sendMessage(H.PROFILER_CONTROL, profilerInfo, start ? 1 : 0, profileType); |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 1027 | } |
| 1028 | |
Makoto Onuki | 4556b7b | 2017-07-07 14:58:58 -0700 | [diff] [blame] | 1029 | @Override |
Christopher Ferris | 8d652f8 | 2017-04-11 16:29:18 -0700 | [diff] [blame] | 1030 | public void dumpHeap(boolean managed, boolean mallocInfo, boolean runGc, String path, |
| 1031 | ParcelFileDescriptor fd) { |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 1032 | DumpHeapData dhd = new DumpHeapData(); |
Christopher Ferris | 8d652f8 | 2017-04-11 16:29:18 -0700 | [diff] [blame] | 1033 | dhd.managed = managed; |
| 1034 | dhd.mallocInfo = mallocInfo; |
Makoto Onuki | 4556b7b | 2017-07-07 14:58:58 -0700 | [diff] [blame] | 1035 | dhd.runGc = runGc; |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 1036 | dhd.path = path; |
| 1037 | dhd.fd = fd; |
Christopher Ferris | 8d652f8 | 2017-04-11 16:29:18 -0700 | [diff] [blame] | 1038 | sendMessage(H.DUMP_HEAP, dhd, 0, 0, true /*async*/); |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 1039 | } |
| 1040 | |
Leonard Mosescu | f3409ce | 2016-10-06 17:32:05 -0700 | [diff] [blame] | 1041 | public void attachAgent(String agent) { |
| 1042 | sendMessage(H.ATTACH_AGENT, agent); |
| 1043 | } |
| 1044 | |
Dianne Hackborn | 06de2ea | 2009-05-21 12:56:43 -0700 | [diff] [blame] | 1045 | public void setSchedulingGroup(int group) { |
| 1046 | // Note: do this immediately, since going into the foreground |
| 1047 | // should happen regardless of what pending work we have to do |
| 1048 | // and the activity manager will wait for us to report back that |
| 1049 | // we are done before sending us to the background. |
| 1050 | try { |
| 1051 | Process.setProcessGroup(Process.myPid(), group); |
| 1052 | } catch (Exception e) { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 1053 | Slog.w(TAG, "Failed setting process group to " + group, e); |
Dianne Hackborn | 06de2ea | 2009-05-21 12:56:43 -0700 | [diff] [blame] | 1054 | } |
| 1055 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1056 | |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1057 | public void dispatchPackageBroadcast(int cmd, String[] packages) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1058 | sendMessage(H.DISPATCH_PACKAGE_BROADCAST, packages, cmd); |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1059 | } |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 1060 | |
| 1061 | public void scheduleCrash(String msg) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1062 | sendMessage(H.SCHEDULE_CRASH, msg); |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 1063 | } |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1064 | |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1065 | public void dumpActivity(ParcelFileDescriptor pfd, IBinder activitytoken, |
Dianne Hackborn | 30d7189 | 2010-12-11 10:37:55 -0800 | [diff] [blame] | 1066 | String prefix, String[] args) { |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1067 | DumpComponentInfo data = new DumpComponentInfo(); |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 1068 | try { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1069 | data.fd = pfd.dup(); |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 1070 | data.token = activitytoken; |
| 1071 | data.prefix = prefix; |
| 1072 | data.args = args; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1073 | sendMessage(H.DUMP_ACTIVITY, data, 0, 0, true /*async*/); |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 1074 | } catch (IOException e) { |
| 1075 | Slog.w(TAG, "dumpActivity failed", e); |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1076 | } finally { |
| 1077 | IoUtils.closeQuietly(pfd); |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1078 | } |
| 1079 | } |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 1080 | |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1081 | public void dumpProvider(ParcelFileDescriptor pfd, IBinder providertoken, |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1082 | String[] args) { |
| 1083 | DumpComponentInfo data = new DumpComponentInfo(); |
| 1084 | try { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1085 | data.fd = pfd.dup(); |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1086 | data.token = providertoken; |
| 1087 | data.args = args; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1088 | sendMessage(H.DUMP_PROVIDER, data, 0, 0, true /*async*/); |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1089 | } catch (IOException e) { |
| 1090 | Slog.w(TAG, "dumpProvider failed", e); |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1091 | } finally { |
| 1092 | IoUtils.closeQuietly(pfd); |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1093 | } |
| 1094 | } |
| 1095 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1096 | @Override |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1097 | public void dumpMemInfo(ParcelFileDescriptor pfd, Debug.MemoryInfo mem, boolean checkin, |
Colin Cross | c4fb5f9 | 2016-02-02 16:51:15 -0800 | [diff] [blame] | 1098 | boolean dumpFullInfo, boolean dumpDalvik, boolean dumpSummaryOnly, |
| 1099 | boolean dumpUnreachable, String[] args) { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1100 | FileOutputStream fout = new FileOutputStream(pfd.getFileDescriptor()); |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 1101 | PrintWriter pw = new FastPrintWriter(fout); |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 1102 | try { |
Colin Cross | c4fb5f9 | 2016-02-02 16:51:15 -0800 | [diff] [blame] | 1103 | dumpMemInfo(pw, mem, checkin, dumpFullInfo, dumpDalvik, dumpSummaryOnly, dumpUnreachable); |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 1104 | } finally { |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 1105 | pw.flush(); |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1106 | IoUtils.closeQuietly(pfd); |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 1107 | } |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 1108 | } |
| 1109 | |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 1110 | private void dumpMemInfo(PrintWriter pw, Debug.MemoryInfo memInfo, boolean checkin, |
Colin Cross | c4fb5f9 | 2016-02-02 16:51:15 -0800 | [diff] [blame] | 1111 | boolean dumpFullInfo, boolean dumpDalvik, boolean dumpSummaryOnly, boolean dumpUnreachable) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1112 | long nativeMax = Debug.getNativeHeapSize() / 1024; |
| 1113 | long nativeAllocated = Debug.getNativeHeapAllocatedSize() / 1024; |
| 1114 | long nativeFree = Debug.getNativeHeapFreeSize() / 1024; |
| 1115 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1116 | Runtime runtime = Runtime.getRuntime(); |
Mathieu Chartier | d288a26 | 2015-07-10 13:44:42 -0700 | [diff] [blame] | 1117 | runtime.gc(); // Do GC since countInstancesOfClass counts unreachable objects. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1118 | long dalvikMax = runtime.totalMemory() / 1024; |
| 1119 | long dalvikFree = runtime.freeMemory() / 1024; |
| 1120 | long dalvikAllocated = dalvikMax - dalvikFree; |
Richard Uhler | 2c03619 | 2016-09-14 09:48:31 +0100 | [diff] [blame] | 1121 | |
| 1122 | Class[] classesToCount = new Class[] { |
| 1123 | ContextImpl.class, |
| 1124 | Activity.class, |
| 1125 | WebView.class, |
| 1126 | OpenSSLSocketImpl.class |
| 1127 | }; |
| 1128 | long[] instanceCounts = VMDebug.countInstancesOfClasses(classesToCount, true); |
| 1129 | long appContextInstanceCount = instanceCounts[0]; |
| 1130 | long activityInstanceCount = instanceCounts[1]; |
| 1131 | long webviewInstanceCount = instanceCounts[2]; |
| 1132 | long openSslSocketCount = instanceCounts[3]; |
| 1133 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1134 | long viewInstanceCount = ViewDebug.getViewInstanceCount(); |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1135 | long viewRootInstanceCount = ViewDebug.getViewRootImplCount(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1136 | int globalAssetCount = AssetManager.getGlobalAssetCount(); |
| 1137 | int globalAssetManagerCount = AssetManager.getGlobalAssetManagerCount(); |
| 1138 | int binderLocalObjectCount = Debug.getBinderLocalObjectCount(); |
| 1139 | int binderProxyObjectCount = Debug.getBinderProxyObjectCount(); |
| 1140 | int binderDeathObjectCount = Debug.getBinderDeathObjectCount(); |
Dianne Hackborn | fabb70b | 2014-11-11 12:22:36 -0800 | [diff] [blame] | 1141 | long parcelSize = Parcel.getGlobalAllocSize(); |
| 1142 | long parcelCount = Parcel.getGlobalAllocCount(); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1143 | SQLiteDebug.PagerStats stats = SQLiteDebug.getDatabaseInfo(); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1144 | |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 1145 | dumpMemInfoTable(pw, memInfo, checkin, dumpFullInfo, dumpDalvik, dumpSummaryOnly, |
| 1146 | Process.myPid(), |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 1147 | (mBoundApplication != null) ? mBoundApplication.processName : "unknown", |
| 1148 | nativeMax, nativeAllocated, nativeFree, |
| 1149 | dalvikMax, dalvikAllocated, dalvikFree); |
| 1150 | |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 1151 | if (checkin) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1152 | // NOTE: if you change anything significant below, also consider changing |
| 1153 | // ACTIVITY_THREAD_CHECKIN_VERSION. |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 1154 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1155 | // Object counts |
| 1156 | pw.print(viewInstanceCount); pw.print(','); |
| 1157 | pw.print(viewRootInstanceCount); pw.print(','); |
| 1158 | pw.print(appContextInstanceCount); pw.print(','); |
| 1159 | pw.print(activityInstanceCount); pw.print(','); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1160 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1161 | pw.print(globalAssetCount); pw.print(','); |
| 1162 | pw.print(globalAssetManagerCount); pw.print(','); |
| 1163 | pw.print(binderLocalObjectCount); pw.print(','); |
| 1164 | pw.print(binderProxyObjectCount); pw.print(','); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1165 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1166 | pw.print(binderDeathObjectCount); pw.print(','); |
| 1167 | pw.print(openSslSocketCount); pw.print(','); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1168 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1169 | // SQL |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1170 | pw.print(stats.memoryUsed / 1024); pw.print(','); |
Jeff Brown | 2a293b6 | 2012-01-19 14:02:22 -0800 | [diff] [blame] | 1171 | pw.print(stats.memoryUsed / 1024); pw.print(','); |
| 1172 | pw.print(stats.pageCacheOverflow / 1024); pw.print(','); |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 1173 | pw.print(stats.largestMemAlloc / 1024); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1174 | for (int i = 0; i < stats.dbStats.size(); i++) { |
| 1175 | DbStats dbStats = stats.dbStats.get(i); |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 1176 | pw.print(','); pw.print(dbStats.dbName); |
| 1177 | pw.print(','); pw.print(dbStats.pageSize); |
| 1178 | pw.print(','); pw.print(dbStats.dbSize); |
| 1179 | pw.print(','); pw.print(dbStats.lookaside); |
| 1180 | pw.print(','); pw.print(dbStats.cache); |
| 1181 | pw.print(','); pw.print(dbStats.cache); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1182 | } |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 1183 | pw.println(); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1184 | |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 1185 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1186 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1187 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1188 | pw.println(" "); |
| 1189 | pw.println(" Objects"); |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1190 | printRow(pw, TWO_COUNT_COLUMNS, "Views:", viewInstanceCount, "ViewRootImpl:", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1191 | viewRootInstanceCount); |
| 1192 | |
| 1193 | printRow(pw, TWO_COUNT_COLUMNS, "AppContexts:", appContextInstanceCount, |
| 1194 | "Activities:", activityInstanceCount); |
| 1195 | |
| 1196 | printRow(pw, TWO_COUNT_COLUMNS, "Assets:", globalAssetCount, |
| 1197 | "AssetManagers:", globalAssetManagerCount); |
| 1198 | |
| 1199 | printRow(pw, TWO_COUNT_COLUMNS, "Local Binders:", binderLocalObjectCount, |
| 1200 | "Proxy Binders:", binderProxyObjectCount); |
Dianne Hackborn | fabb70b | 2014-11-11 12:22:36 -0800 | [diff] [blame] | 1201 | printRow(pw, TWO_COUNT_COLUMNS, "Parcel memory:", parcelSize/1024, |
| 1202 | "Parcel count:", parcelCount); |
| 1203 | printRow(pw, TWO_COUNT_COLUMNS, "Death Recipients:", binderDeathObjectCount, |
| 1204 | "OpenSSL Sockets:", openSslSocketCount); |
Richard Uhler | 2c03619 | 2016-09-14 09:48:31 +0100 | [diff] [blame] | 1205 | printRow(pw, ONE_COUNT_COLUMN, "WebViews:", webviewInstanceCount); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1206 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1207 | // SQLite mem info |
| 1208 | pw.println(" "); |
| 1209 | pw.println(" SQL"); |
Jeff Brown | 2a293b6 | 2012-01-19 14:02:22 -0800 | [diff] [blame] | 1210 | printRow(pw, ONE_COUNT_COLUMN, "MEMORY_USED:", stats.memoryUsed / 1024); |
| 1211 | printRow(pw, TWO_COUNT_COLUMNS, "PAGECACHE_OVERFLOW:", |
| 1212 | stats.pageCacheOverflow / 1024, "MALLOC_SIZE:", stats.largestMemAlloc / 1024); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1213 | pw.println(" "); |
| 1214 | int N = stats.dbStats.size(); |
| 1215 | if (N > 0) { |
| 1216 | pw.println(" DATABASES"); |
Vasu Nori | 3c7131f | 2010-09-21 14:36:57 -0700 | [diff] [blame] | 1217 | printRow(pw, " %8s %8s %14s %14s %s", "pgsz", "dbsz", "Lookaside(b)", "cache", |
| 1218 | "Dbname"); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1219 | for (int i = 0; i < N; i++) { |
| 1220 | DbStats dbStats = stats.dbStats.get(i); |
Vasu Nori | 3c7131f | 2010-09-21 14:36:57 -0700 | [diff] [blame] | 1221 | printRow(pw, DB_INFO_FORMAT, |
| 1222 | (dbStats.pageSize > 0) ? String.valueOf(dbStats.pageSize) : " ", |
| 1223 | (dbStats.dbSize > 0) ? String.valueOf(dbStats.dbSize) : " ", |
| 1224 | (dbStats.lookaside > 0) ? String.valueOf(dbStats.lookaside) : " ", |
| 1225 | dbStats.cache, dbStats.dbName); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1226 | } |
| 1227 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1228 | |
Dianne Hackborn | 82e1ee9 | 2009-08-11 18:56:41 -0700 | [diff] [blame] | 1229 | // Asset details. |
| 1230 | String assetAlloc = AssetManager.getAssetAllocations(); |
| 1231 | if (assetAlloc != null) { |
| 1232 | pw.println(" "); |
| 1233 | pw.println(" Asset Allocations"); |
| 1234 | pw.print(assetAlloc); |
| 1235 | } |
Colin Cross | c4fb5f9 | 2016-02-02 16:51:15 -0800 | [diff] [blame] | 1236 | |
| 1237 | // Unreachable native memory |
| 1238 | if (dumpUnreachable) { |
| 1239 | boolean showContents = ((mBoundApplication != null) |
| 1240 | && ((mBoundApplication.appInfo.flags&ApplicationInfo.FLAG_DEBUGGABLE) != 0)) |
| 1241 | || android.os.Build.IS_DEBUGGABLE; |
| 1242 | pw.println(" "); |
| 1243 | pw.println(" Unreachable memory"); |
| 1244 | pw.print(Debug.getUnreachableMemory(100, showContents)); |
| 1245 | } |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 1246 | } |
| 1247 | |
| 1248 | @Override |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1249 | public void dumpGfxInfo(ParcelFileDescriptor pfd, String[] args) { |
Chris Craik | fc29424 | 2016-12-13 18:10:46 -0800 | [diff] [blame] | 1250 | nDumpGraphicsInfo(pfd.getFileDescriptor()); |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1251 | WindowManagerGlobal.getInstance().dumpGfxInfo(pfd.getFileDescriptor(), args); |
| 1252 | IoUtils.closeQuietly(pfd); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1253 | } |
| 1254 | |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1255 | private void dumpDatabaseInfo(ParcelFileDescriptor pfd, String[] args) { |
| 1256 | PrintWriter pw = new FastPrintWriter( |
| 1257 | new FileOutputStream(pfd.getFileDescriptor())); |
Jeff Brown | 6754ba2 | 2011-12-14 20:20:01 -0800 | [diff] [blame] | 1258 | PrintWriterPrinter printer = new PrintWriterPrinter(pw); |
| 1259 | SQLiteDebug.dump(printer, args); |
| 1260 | pw.flush(); |
| 1261 | } |
| 1262 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1263 | @Override |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1264 | public void dumpDbInfo(final ParcelFileDescriptor pfd, final String[] args) { |
riddle_hsu | 1d6c40a | 2014-07-31 00:18:00 +0800 | [diff] [blame] | 1265 | if (mSystemThread) { |
Felipe Leme | 29de492 | 2016-06-07 16:14:07 -0700 | [diff] [blame] | 1266 | // Ensure this invocation is asynchronous to prevent writer waiting if buffer cannot |
| 1267 | // be consumed. But it must duplicate the file descriptor first, since caller might |
| 1268 | // be closing it. |
| 1269 | final ParcelFileDescriptor dup; |
| 1270 | try { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1271 | dup = pfd.dup(); |
Felipe Leme | 29de492 | 2016-06-07 16:14:07 -0700 | [diff] [blame] | 1272 | } catch (IOException e) { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1273 | Log.w(TAG, "Could not dup FD " + pfd.getFileDescriptor().getInt$()); |
Felipe Leme | 29de492 | 2016-06-07 16:14:07 -0700 | [diff] [blame] | 1274 | return; |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1275 | } finally { |
| 1276 | IoUtils.closeQuietly(pfd); |
Felipe Leme | 29de492 | 2016-06-07 16:14:07 -0700 | [diff] [blame] | 1277 | } |
| 1278 | |
riddle_hsu | 1d6c40a | 2014-07-31 00:18:00 +0800 | [diff] [blame] | 1279 | AsyncTask.THREAD_POOL_EXECUTOR.execute(new Runnable() { |
| 1280 | @Override |
| 1281 | public void run() { |
Felipe Leme | c74972f | 2016-06-08 09:12:37 -0700 | [diff] [blame] | 1282 | try { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1283 | dumpDatabaseInfo(dup, args); |
Felipe Leme | c74972f | 2016-06-08 09:12:37 -0700 | [diff] [blame] | 1284 | } finally { |
| 1285 | IoUtils.closeQuietly(dup); |
| 1286 | } |
riddle_hsu | 1d6c40a | 2014-07-31 00:18:00 +0800 | [diff] [blame] | 1287 | } |
| 1288 | }); |
| 1289 | } else { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1290 | dumpDatabaseInfo(pfd, args); |
| 1291 | IoUtils.closeQuietly(pfd); |
riddle_hsu | 1d6c40a | 2014-07-31 00:18:00 +0800 | [diff] [blame] | 1292 | } |
| 1293 | } |
| 1294 | |
| 1295 | @Override |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1296 | public void unstableProviderDied(IBinder provider) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1297 | sendMessage(H.UNSTABLE_PROVIDER_DIED, provider); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1298 | } |
| 1299 | |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 1300 | @Override |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 1301 | public void requestAssistContextExtras(IBinder activityToken, IBinder requestToken, |
Svet Ganov | fd31f85 | 2017-04-26 15:54:27 -0700 | [diff] [blame] | 1302 | int requestType, int sessionId, int flags) { |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 1303 | RequestAssistContextExtras cmd = new RequestAssistContextExtras(); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 1304 | cmd.activityToken = activityToken; |
| 1305 | cmd.requestToken = requestToken; |
| 1306 | cmd.requestType = requestType; |
Amith Yamasani | 4f128e4 | 2016-05-10 11:44:12 -0700 | [diff] [blame] | 1307 | cmd.sessionId = sessionId; |
Svet Ganov | fd31f85 | 2017-04-26 15:54:27 -0700 | [diff] [blame] | 1308 | cmd.flags = flags; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1309 | sendMessage(H.REQUEST_ASSIST_CONTEXT_EXTRAS, cmd); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 1310 | } |
| 1311 | |
Svetoslav Ganov | 9aa597e | 2011-03-03 18:17:41 -0800 | [diff] [blame] | 1312 | public void setCoreSettings(Bundle coreSettings) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1313 | sendMessage(H.SET_CORE_SETTINGS, coreSettings); |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1314 | } |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1315 | |
| 1316 | public void updatePackageCompatibilityInfo(String pkg, CompatibilityInfo info) { |
| 1317 | UpdateCompatibilityData ucd = new UpdateCompatibilityData(); |
| 1318 | ucd.pkg = pkg; |
| 1319 | ucd.info = info; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1320 | sendMessage(H.UPDATE_PACKAGE_COMPATIBILITY_INFO, ucd); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1321 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1322 | |
| 1323 | public void scheduleTrimMemory(int level) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1324 | sendMessage(H.TRIM_MEMORY, null, level); |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1325 | } |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1326 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1327 | public void scheduleTranslucentConversionComplete(IBinder token, boolean drawComplete) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1328 | sendMessage(H.TRANSLUCENT_CONVERSION_COMPLETE, token, drawComplete ? 1 : 0); |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1329 | } |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 1330 | |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1331 | public void scheduleOnNewActivityOptions(IBinder token, Bundle options) { |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1332 | sendMessage(H.ON_NEW_ACTIVITY_OPTIONS, |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1333 | new Pair<IBinder, ActivityOptions>(token, ActivityOptions.fromBundle(options))); |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1334 | } |
| 1335 | |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 1336 | public void setProcessState(int state) { |
| 1337 | updateProcessState(state, true); |
| 1338 | } |
| 1339 | |
| 1340 | public void updateProcessState(int processState, boolean fromIpc) { |
| 1341 | synchronized (this) { |
| 1342 | if (mLastProcessState != processState) { |
| 1343 | mLastProcessState = processState; |
Mathieu Chartier | 1e37090 | 2013-07-18 10:58:01 -0700 | [diff] [blame] | 1344 | // Update Dalvik state based on ActivityManager.PROCESS_STATE_* constants. |
| 1345 | final int DALVIK_PROCESS_STATE_JANK_PERCEPTIBLE = 0; |
| 1346 | final int DALVIK_PROCESS_STATE_JANK_IMPERCEPTIBLE = 1; |
| 1347 | int dalvikProcessState = DALVIK_PROCESS_STATE_JANK_IMPERCEPTIBLE; |
| 1348 | // TODO: Tune this since things like gmail sync are important background but not jank perceptible. |
| 1349 | if (processState <= ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND) { |
| 1350 | dalvikProcessState = DALVIK_PROCESS_STATE_JANK_PERCEPTIBLE; |
| 1351 | } |
| 1352 | VMRuntime.getRuntime().updateProcessState(dalvikProcessState); |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 1353 | if (false) { |
| 1354 | Slog.i(TAG, "******************* PROCESS STATE CHANGED TO: " + processState |
| 1355 | + (fromIpc ? " (from ipc": "")); |
| 1356 | } |
| 1357 | } |
| 1358 | } |
| 1359 | } |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 1360 | |
Sudheer Shanka | 84a4895 | 2017-03-08 18:19:01 -0800 | [diff] [blame] | 1361 | /** |
| 1362 | * Updates {@link #mNetworkBlockSeq}. This is used by ActivityManagerService to inform |
| 1363 | * the main thread that it needs to wait for the network rules to get updated before |
| 1364 | * launching an activity. |
| 1365 | */ |
| 1366 | @Override |
| 1367 | public void setNetworkBlockSeq(long procStateSeq) { |
| 1368 | synchronized (mNetworkPolicyLock) { |
| 1369 | mNetworkBlockSeq = procStateSeq; |
| 1370 | } |
| 1371 | } |
| 1372 | |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 1373 | @Override |
| 1374 | public void scheduleInstallProvider(ProviderInfo provider) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1375 | sendMessage(H.INSTALL_PROVIDER, provider); |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 1376 | } |
Narayan Kamath | ccb2a086 | 2013-12-19 14:49:36 +0000 | [diff] [blame] | 1377 | |
| 1378 | @Override |
Neil Fuller | b7146fe | 2016-11-15 16:52:15 +0000 | [diff] [blame] | 1379 | public final void updateTimePrefs(int timeFormatPreference) { |
| 1380 | final Boolean timeFormatPreferenceBool; |
| 1381 | // For convenience we are using the Intent extra values. |
| 1382 | if (timeFormatPreference == Intent.EXTRA_TIME_PREF_VALUE_USE_12_HOUR) { |
| 1383 | timeFormatPreferenceBool = Boolean.FALSE; |
| 1384 | } else if (timeFormatPreference == Intent.EXTRA_TIME_PREF_VALUE_USE_24_HOUR) { |
| 1385 | timeFormatPreferenceBool = Boolean.TRUE; |
| 1386 | } else { |
| 1387 | // timeFormatPreference == Intent.EXTRA_TIME_PREF_VALUE_USE_LOCALE_DEFAULT |
| 1388 | // (or unknown). |
| 1389 | timeFormatPreferenceBool = null; |
| 1390 | } |
| 1391 | DateFormat.set24HourTimePref(timeFormatPreferenceBool); |
Narayan Kamath | ccb2a086 | 2013-12-19 14:49:36 +0000 | [diff] [blame] | 1392 | } |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 1393 | |
| 1394 | @Override |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 1395 | public void scheduleEnterAnimationComplete(IBinder token) { |
| 1396 | sendMessage(H.ENTER_ANIMATION_COMPLETE, token); |
| 1397 | } |
Jeff Sharkey | 605eb79 | 2014-11-04 13:34:06 -0800 | [diff] [blame] | 1398 | |
| 1399 | @Override |
| 1400 | public void notifyCleartextNetwork(byte[] firstPacket) { |
| 1401 | if (StrictMode.vmCleartextNetworkEnabled()) { |
| 1402 | StrictMode.onCleartextNetworkDetected(firstPacket); |
| 1403 | } |
| 1404 | } |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 1405 | |
| 1406 | @Override |
| 1407 | public void startBinderTracking() { |
| 1408 | sendMessage(H.START_BINDER_TRACKING, null); |
| 1409 | } |
| 1410 | |
| 1411 | @Override |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1412 | public void stopBinderTrackingAndDump(ParcelFileDescriptor pfd) { |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 1413 | try { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1414 | sendMessage(H.STOP_BINDER_TRACKING_AND_DUMP, pfd.dup()); |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 1415 | } catch (IOException e) { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1416 | } finally { |
| 1417 | IoUtils.closeQuietly(pfd); |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 1418 | } |
| 1419 | } |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 1420 | |
| 1421 | @Override |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 1422 | public void scheduleMultiWindowModeChanged(IBinder token, boolean isInMultiWindowMode, |
| 1423 | Configuration overrideConfig) throws RemoteException { |
| 1424 | SomeArgs args = SomeArgs.obtain(); |
| 1425 | args.arg1 = token; |
| 1426 | args.arg2 = overrideConfig; |
| 1427 | args.argi1 = isInMultiWindowMode ? 1 : 0; |
| 1428 | sendMessage(H.MULTI_WINDOW_MODE_CHANGED, args); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 1429 | } |
| 1430 | |
| 1431 | @Override |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 1432 | public void schedulePictureInPictureModeChanged(IBinder token, boolean isInPipMode, |
| 1433 | Configuration overrideConfig) throws RemoteException { |
| 1434 | SomeArgs args = SomeArgs.obtain(); |
| 1435 | args.arg1 = token; |
| 1436 | args.arg2 = overrideConfig; |
| 1437 | args.argi1 = isInPipMode ? 1 : 0; |
| 1438 | sendMessage(H.PICTURE_IN_PICTURE_MODE_CHANGED, args); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 1439 | } |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1440 | |
| 1441 | @Override |
| 1442 | public void scheduleLocalVoiceInteractionStarted(IBinder token, |
| 1443 | IVoiceInteractor voiceInteractor) throws RemoteException { |
| 1444 | SomeArgs args = SomeArgs.obtain(); |
| 1445 | args.arg1 = token; |
| 1446 | args.arg2 = voiceInteractor; |
| 1447 | sendMessage(H.LOCAL_VOICE_INTERACTION_STARTED, args); |
| 1448 | } |
Chad Brubaker | c72875b | 2016-04-27 16:35:11 -0700 | [diff] [blame] | 1449 | |
| 1450 | @Override |
| 1451 | public void handleTrustStorageUpdate() { |
| 1452 | NetworkSecurityPolicy.getInstance().handleTrustStorageUpdate(); |
| 1453 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1454 | } |
| 1455 | |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1456 | private int getLifecycleSeq() { |
| 1457 | synchronized (mResourcesManager) { |
| 1458 | return mLifecycleSeq++; |
| 1459 | } |
| 1460 | } |
| 1461 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1462 | private class H extends Handler { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1463 | public static final int LAUNCH_ACTIVITY = 100; |
| 1464 | public static final int PAUSE_ACTIVITY = 101; |
| 1465 | public static final int PAUSE_ACTIVITY_FINISHING= 102; |
| 1466 | public static final int STOP_ACTIVITY_SHOW = 103; |
| 1467 | public static final int STOP_ACTIVITY_HIDE = 104; |
| 1468 | public static final int SHOW_WINDOW = 105; |
| 1469 | public static final int HIDE_WINDOW = 106; |
| 1470 | public static final int RESUME_ACTIVITY = 107; |
| 1471 | public static final int SEND_RESULT = 108; |
Brian Carlstrom | ed7e007 | 2011-03-24 13:27:57 -0700 | [diff] [blame] | 1472 | public static final int DESTROY_ACTIVITY = 109; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1473 | public static final int BIND_APPLICATION = 110; |
| 1474 | public static final int EXIT_APPLICATION = 111; |
| 1475 | public static final int NEW_INTENT = 112; |
| 1476 | public static final int RECEIVER = 113; |
| 1477 | public static final int CREATE_SERVICE = 114; |
| 1478 | public static final int SERVICE_ARGS = 115; |
| 1479 | public static final int STOP_SERVICE = 116; |
Dianne Hackborn | 0923328 | 2014-04-30 11:33:59 -0700 | [diff] [blame] | 1480 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1481 | public static final int CONFIGURATION_CHANGED = 118; |
| 1482 | public static final int CLEAN_UP_CONTEXT = 119; |
| 1483 | public static final int GC_WHEN_IDLE = 120; |
| 1484 | public static final int BIND_SERVICE = 121; |
| 1485 | public static final int UNBIND_SERVICE = 122; |
| 1486 | public static final int DUMP_SERVICE = 123; |
| 1487 | public static final int LOW_MEMORY = 124; |
| 1488 | public static final int ACTIVITY_CONFIGURATION_CHANGED = 125; |
| 1489 | public static final int RELAUNCH_ACTIVITY = 126; |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 1490 | public static final int PROFILER_CONTROL = 127; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1491 | public static final int CREATE_BACKUP_AGENT = 128; |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 1492 | public static final int DESTROY_BACKUP_AGENT = 129; |
| 1493 | public static final int SUICIDE = 130; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1494 | public static final int REMOVE_PROVIDER = 131; |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 1495 | public static final int ENABLE_JIT = 132; |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1496 | public static final int DISPATCH_PACKAGE_BROADCAST = 133; |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 1497 | public static final int SCHEDULE_CRASH = 134; |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 1498 | public static final int DUMP_HEAP = 135; |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1499 | public static final int DUMP_ACTIVITY = 136; |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1500 | public static final int SLEEPING = 137; |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1501 | public static final int SET_CORE_SETTINGS = 138; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1502 | public static final int UPDATE_PACKAGE_COMPATIBILITY_INFO = 139; |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1503 | public static final int TRIM_MEMORY = 140; |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1504 | public static final int DUMP_PROVIDER = 141; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1505 | public static final int UNSTABLE_PROVIDER_DIED = 142; |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 1506 | public static final int REQUEST_ASSIST_CONTEXT_EXTRAS = 143; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1507 | public static final int TRANSLUCENT_CONVERSION_COMPLETE = 144; |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 1508 | public static final int INSTALL_PROVIDER = 145; |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1509 | public static final int ON_NEW_ACTIVITY_OPTIONS = 146; |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 1510 | public static final int ENTER_ANIMATION_COMPLETE = 149; |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 1511 | public static final int START_BINDER_TRACKING = 150; |
| 1512 | public static final int STOP_BINDER_TRACKING_AND_DUMP = 151; |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 1513 | public static final int MULTI_WINDOW_MODE_CHANGED = 152; |
| 1514 | public static final int PICTURE_IN_PICTURE_MODE_CHANGED = 153; |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1515 | public static final int LOCAL_VOICE_INTERACTION_STARTED = 154; |
Leonard Mosescu | f3409ce | 2016-10-06 17:32:05 -0700 | [diff] [blame] | 1516 | public static final int ATTACH_AGENT = 155; |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 1517 | public static final int APPLICATION_INFO_CHANGED = 156; |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 1518 | public static final int ACTIVITY_MOVED_TO_DISPLAY = 157; |
Narayan Kamath | ccb2a086 | 2013-12-19 14:49:36 +0000 | [diff] [blame] | 1519 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1520 | String codeToString(int code) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 1521 | if (DEBUG_MESSAGES) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1522 | switch (code) { |
| 1523 | case LAUNCH_ACTIVITY: return "LAUNCH_ACTIVITY"; |
| 1524 | case PAUSE_ACTIVITY: return "PAUSE_ACTIVITY"; |
| 1525 | case PAUSE_ACTIVITY_FINISHING: return "PAUSE_ACTIVITY_FINISHING"; |
| 1526 | case STOP_ACTIVITY_SHOW: return "STOP_ACTIVITY_SHOW"; |
| 1527 | case STOP_ACTIVITY_HIDE: return "STOP_ACTIVITY_HIDE"; |
| 1528 | case SHOW_WINDOW: return "SHOW_WINDOW"; |
| 1529 | case HIDE_WINDOW: return "HIDE_WINDOW"; |
| 1530 | case RESUME_ACTIVITY: return "RESUME_ACTIVITY"; |
| 1531 | case SEND_RESULT: return "SEND_RESULT"; |
| 1532 | case DESTROY_ACTIVITY: return "DESTROY_ACTIVITY"; |
| 1533 | case BIND_APPLICATION: return "BIND_APPLICATION"; |
| 1534 | case EXIT_APPLICATION: return "EXIT_APPLICATION"; |
| 1535 | case NEW_INTENT: return "NEW_INTENT"; |
| 1536 | case RECEIVER: return "RECEIVER"; |
| 1537 | case CREATE_SERVICE: return "CREATE_SERVICE"; |
| 1538 | case SERVICE_ARGS: return "SERVICE_ARGS"; |
| 1539 | case STOP_SERVICE: return "STOP_SERVICE"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1540 | case CONFIGURATION_CHANGED: return "CONFIGURATION_CHANGED"; |
| 1541 | case CLEAN_UP_CONTEXT: return "CLEAN_UP_CONTEXT"; |
| 1542 | case GC_WHEN_IDLE: return "GC_WHEN_IDLE"; |
| 1543 | case BIND_SERVICE: return "BIND_SERVICE"; |
| 1544 | case UNBIND_SERVICE: return "UNBIND_SERVICE"; |
| 1545 | case DUMP_SERVICE: return "DUMP_SERVICE"; |
| 1546 | case LOW_MEMORY: return "LOW_MEMORY"; |
| 1547 | case ACTIVITY_CONFIGURATION_CHANGED: return "ACTIVITY_CONFIGURATION_CHANGED"; |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 1548 | case ACTIVITY_MOVED_TO_DISPLAY: return "ACTIVITY_MOVED_TO_DISPLAY"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1549 | case RELAUNCH_ACTIVITY: return "RELAUNCH_ACTIVITY"; |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 1550 | case PROFILER_CONTROL: return "PROFILER_CONTROL"; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1551 | case CREATE_BACKUP_AGENT: return "CREATE_BACKUP_AGENT"; |
| 1552 | case DESTROY_BACKUP_AGENT: return "DESTROY_BACKUP_AGENT"; |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 1553 | case SUICIDE: return "SUICIDE"; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1554 | case REMOVE_PROVIDER: return "REMOVE_PROVIDER"; |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 1555 | case ENABLE_JIT: return "ENABLE_JIT"; |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1556 | case DISPATCH_PACKAGE_BROADCAST: return "DISPATCH_PACKAGE_BROADCAST"; |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 1557 | case SCHEDULE_CRASH: return "SCHEDULE_CRASH"; |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 1558 | case DUMP_HEAP: return "DUMP_HEAP"; |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1559 | case DUMP_ACTIVITY: return "DUMP_ACTIVITY"; |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1560 | case SLEEPING: return "SLEEPING"; |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1561 | case SET_CORE_SETTINGS: return "SET_CORE_SETTINGS"; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1562 | case UPDATE_PACKAGE_COMPATIBILITY_INFO: return "UPDATE_PACKAGE_COMPATIBILITY_INFO"; |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1563 | case TRIM_MEMORY: return "TRIM_MEMORY"; |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1564 | case DUMP_PROVIDER: return "DUMP_PROVIDER"; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1565 | case UNSTABLE_PROVIDER_DIED: return "UNSTABLE_PROVIDER_DIED"; |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 1566 | case REQUEST_ASSIST_CONTEXT_EXTRAS: return "REQUEST_ASSIST_CONTEXT_EXTRAS"; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1567 | case TRANSLUCENT_CONVERSION_COMPLETE: return "TRANSLUCENT_CONVERSION_COMPLETE"; |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 1568 | case INSTALL_PROVIDER: return "INSTALL_PROVIDER"; |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1569 | case ON_NEW_ACTIVITY_OPTIONS: return "ON_NEW_ACTIVITY_OPTIONS"; |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 1570 | case ENTER_ANIMATION_COMPLETE: return "ENTER_ANIMATION_COMPLETE"; |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 1571 | case MULTI_WINDOW_MODE_CHANGED: return "MULTI_WINDOW_MODE_CHANGED"; |
| 1572 | case PICTURE_IN_PICTURE_MODE_CHANGED: return "PICTURE_IN_PICTURE_MODE_CHANGED"; |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1573 | case LOCAL_VOICE_INTERACTION_STARTED: return "LOCAL_VOICE_INTERACTION_STARTED"; |
Leonard Mosescu | f3409ce | 2016-10-06 17:32:05 -0700 | [diff] [blame] | 1574 | case ATTACH_AGENT: return "ATTACH_AGENT"; |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 1575 | case APPLICATION_INFO_CHANGED: return "APPLICATION_INFO_CHANGED"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1576 | } |
| 1577 | } |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 1578 | return Integer.toString(code); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1579 | } |
| 1580 | public void handleMessage(Message msg) { |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 1581 | 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] | 1582 | switch (msg.what) { |
| 1583 | case LAUNCH_ACTIVITY: { |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1584 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityStart"); |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 1585 | final ActivityClientRecord r = (ActivityClientRecord) msg.obj; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1586 | |
| 1587 | r.packageInfo = getPackageInfoNoCheck( |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1588 | r.activityInfo.applicationInfo, r.compatInfo); |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 1589 | handleLaunchActivity(r, null, "LAUNCH_ACTIVITY"); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1590 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1591 | } break; |
| 1592 | case RELAUNCH_ACTIVITY: { |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1593 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityRestart"); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1594 | ActivityClientRecord r = (ActivityClientRecord)msg.obj; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 1595 | handleRelaunchActivity(r); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1596 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1597 | } break; |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1598 | case PAUSE_ACTIVITY: { |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1599 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityPause"); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1600 | SomeArgs args = (SomeArgs) msg.obj; |
| 1601 | handlePauseActivity((IBinder) args.arg1, false, |
| 1602 | (args.argi1 & USER_LEAVING) != 0, args.argi2, |
| 1603 | (args.argi1 & DONT_REPORT) != 0, args.argi3); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1604 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1605 | } break; |
| 1606 | case PAUSE_ACTIVITY_FINISHING: { |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1607 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityPause"); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1608 | SomeArgs args = (SomeArgs) msg.obj; |
| 1609 | handlePauseActivity((IBinder) args.arg1, true, (args.argi1 & USER_LEAVING) != 0, |
| 1610 | args.argi2, (args.argi1 & DONT_REPORT) != 0, args.argi3); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1611 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1612 | } break; |
| 1613 | case STOP_ACTIVITY_SHOW: { |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1614 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityStop"); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1615 | SomeArgs args = (SomeArgs) msg.obj; |
| 1616 | handleStopActivity((IBinder) args.arg1, true, args.argi2, args.argi3); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1617 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1618 | } break; |
| 1619 | case STOP_ACTIVITY_HIDE: { |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1620 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityStop"); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1621 | SomeArgs args = (SomeArgs) msg.obj; |
| 1622 | handleStopActivity((IBinder) args.arg1, false, args.argi2, args.argi3); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1623 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1624 | } break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1625 | case SHOW_WINDOW: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1626 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityShowWindow"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1627 | handleWindowVisibility((IBinder)msg.obj, true); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1628 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1629 | break; |
| 1630 | case HIDE_WINDOW: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1631 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityHideWindow"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1632 | handleWindowVisibility((IBinder)msg.obj, false); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1633 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1634 | break; |
| 1635 | case RESUME_ACTIVITY: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1636 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityResume"); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1637 | SomeArgs args = (SomeArgs) msg.obj; |
| 1638 | handleResumeActivity((IBinder) args.arg1, true, args.argi1 != 0, true, |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 1639 | args.argi3, "RESUME_ACTIVITY"); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1640 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1641 | break; |
| 1642 | case SEND_RESULT: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1643 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityDeliverResult"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1644 | handleSendResult((ResultData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1645 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1646 | break; |
| 1647 | case DESTROY_ACTIVITY: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1648 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityDestroy"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1649 | handleDestroyActivity((IBinder)msg.obj, msg.arg1 != 0, |
| 1650 | msg.arg2, false); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1651 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1652 | break; |
| 1653 | case BIND_APPLICATION: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1654 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "bindApplication"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1655 | AppBindData data = (AppBindData)msg.obj; |
| 1656 | handleBindApplication(data); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1657 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1658 | break; |
| 1659 | case EXIT_APPLICATION: |
| 1660 | if (mInitialApplication != null) { |
| 1661 | mInitialApplication.onTerminate(); |
| 1662 | } |
| 1663 | Looper.myLooper().quit(); |
| 1664 | break; |
| 1665 | case NEW_INTENT: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1666 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityNewIntent"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1667 | handleNewIntent((NewIntentData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1668 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1669 | break; |
| 1670 | case RECEIVER: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1671 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "broadcastReceiveComp"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1672 | handleReceiver((ReceiverData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1673 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1674 | break; |
| 1675 | case CREATE_SERVICE: |
Tim Murray | b6f5a42 | 2016-04-07 15:25:22 -0700 | [diff] [blame] | 1676 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, ("serviceCreate: " + String.valueOf(msg.obj))); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1677 | handleCreateService((CreateServiceData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1678 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1679 | break; |
| 1680 | case BIND_SERVICE: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1681 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "serviceBind"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1682 | handleBindService((BindServiceData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1683 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1684 | break; |
| 1685 | case UNBIND_SERVICE: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1686 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "serviceUnbind"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1687 | handleUnbindService((BindServiceData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1688 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1689 | break; |
| 1690 | case SERVICE_ARGS: |
Tim Murray | b6f5a42 | 2016-04-07 15:25:22 -0700 | [diff] [blame] | 1691 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, ("serviceStart: " + String.valueOf(msg.obj))); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1692 | handleServiceArgs((ServiceArgsData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1693 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1694 | break; |
| 1695 | case STOP_SERVICE: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1696 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "serviceStop"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1697 | handleStopService((IBinder)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1698 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1699 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1700 | case CONFIGURATION_CHANGED: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1701 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "configChanged"); |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 1702 | mCurDefaultDisplayDpi = ((Configuration)msg.obj).densityDpi; |
Chong Zhang | 4951f9d | 2016-06-23 13:15:08 -0700 | [diff] [blame] | 1703 | mUpdatingSystemConfig = true; |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 1704 | try { |
| 1705 | handleConfigurationChanged((Configuration) msg.obj, null); |
| 1706 | } finally { |
| 1707 | mUpdatingSystemConfig = false; |
| 1708 | } |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1709 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1710 | break; |
| 1711 | case CLEAN_UP_CONTEXT: |
| 1712 | ContextCleanupInfo cci = (ContextCleanupInfo)msg.obj; |
| 1713 | cci.context.performFinalCleanup(cci.who, cci.what); |
| 1714 | break; |
| 1715 | case GC_WHEN_IDLE: |
| 1716 | scheduleGcIdler(); |
| 1717 | break; |
| 1718 | case DUMP_SERVICE: |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1719 | handleDumpService((DumpComponentInfo)msg.obj); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1720 | break; |
| 1721 | case LOW_MEMORY: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1722 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "lowMemory"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1723 | handleLowMemory(); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1724 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1725 | break; |
| 1726 | case ACTIVITY_CONFIGURATION_CHANGED: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1727 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityConfigChanged"); |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 1728 | handleActivityConfigurationChanged((ActivityConfigChangeData) msg.obj, |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 1729 | INVALID_DISPLAY); |
| 1730 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
| 1731 | break; |
| 1732 | case ACTIVITY_MOVED_TO_DISPLAY: |
| 1733 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityMovedToDisplay"); |
| 1734 | handleActivityConfigurationChanged((ActivityConfigChangeData) msg.obj, |
| 1735 | msg.arg1 /* displayId */); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1736 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1737 | break; |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 1738 | case PROFILER_CONTROL: |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 1739 | handleProfilerControl(msg.arg1 != 0, (ProfilerInfo)msg.obj, msg.arg2); |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 1740 | break; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1741 | case CREATE_BACKUP_AGENT: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1742 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "backupCreateAgent"); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1743 | handleCreateBackupAgent((CreateBackupAgentData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1744 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1745 | break; |
| 1746 | case DESTROY_BACKUP_AGENT: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1747 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "backupDestroyAgent"); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1748 | handleDestroyBackupAgent((CreateBackupAgentData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1749 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1750 | break; |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 1751 | case SUICIDE: |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1752 | Process.killProcess(Process.myPid()); |
| 1753 | break; |
| 1754 | case REMOVE_PROVIDER: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1755 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "providerRemove"); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1756 | completeRemoveProvider((ProviderRefCount)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1757 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 1758 | break; |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 1759 | case ENABLE_JIT: |
| 1760 | ensureJitEnabled(); |
| 1761 | break; |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1762 | case DISPATCH_PACKAGE_BROADCAST: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1763 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "broadcastPackage"); |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1764 | handleDispatchPackageBroadcast(msg.arg1, (String[])msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1765 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1766 | break; |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 1767 | case SCHEDULE_CRASH: |
| 1768 | throw new RemoteServiceException((String)msg.obj); |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 1769 | case DUMP_HEAP: |
Christopher Ferris | 8d652f8 | 2017-04-11 16:29:18 -0700 | [diff] [blame] | 1770 | handleDumpHeap((DumpHeapData) msg.obj); |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 1771 | break; |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1772 | case DUMP_ACTIVITY: |
| 1773 | handleDumpActivity((DumpComponentInfo)msg.obj); |
| 1774 | break; |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1775 | case DUMP_PROVIDER: |
| 1776 | handleDumpProvider((DumpComponentInfo)msg.obj); |
| 1777 | break; |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1778 | case SLEEPING: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1779 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "sleeping"); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1780 | handleSleeping((IBinder)msg.obj, msg.arg1 != 0); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1781 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1782 | break; |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1783 | case SET_CORE_SETTINGS: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1784 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "setCoreSettings"); |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1785 | handleSetCoreSettings((Bundle) msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1786 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1787 | break; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1788 | case UPDATE_PACKAGE_COMPATIBILITY_INFO: |
| 1789 | handleUpdatePackageCompatibilityInfo((UpdateCompatibilityData)msg.obj); |
Dianne Hackborn | f0754f5b | 2011-07-21 16:02:07 -0700 | [diff] [blame] | 1790 | break; |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1791 | case TRIM_MEMORY: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1792 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "trimMemory"); |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1793 | handleTrimMemory(msg.arg1); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1794 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Dianne Hackborn | f0754f5b | 2011-07-21 16:02:07 -0700 | [diff] [blame] | 1795 | break; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1796 | case UNSTABLE_PROVIDER_DIED: |
| 1797 | handleUnstableProviderDied((IBinder)msg.obj, false); |
| 1798 | break; |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 1799 | case REQUEST_ASSIST_CONTEXT_EXTRAS: |
| 1800 | handleRequestAssistContextExtras((RequestAssistContextExtras)msg.obj); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 1801 | break; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1802 | case TRANSLUCENT_CONVERSION_COMPLETE: |
| 1803 | handleTranslucentConversionComplete((IBinder)msg.obj, msg.arg1 == 1); |
| 1804 | break; |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 1805 | case INSTALL_PROVIDER: |
| 1806 | handleInstallProvider((ProviderInfo) msg.obj); |
| 1807 | break; |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1808 | case ON_NEW_ACTIVITY_OPTIONS: |
| 1809 | Pair<IBinder, ActivityOptions> pair = (Pair<IBinder, ActivityOptions>) msg.obj; |
| 1810 | onNewActivityOptions(pair.first, pair.second); |
Dake Gu | 7ef70b0 | 2014-07-08 18:37:12 -0700 | [diff] [blame] | 1811 | break; |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 1812 | case ENTER_ANIMATION_COMPLETE: |
| 1813 | handleEnterAnimationComplete((IBinder) msg.obj); |
| 1814 | break; |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 1815 | case START_BINDER_TRACKING: |
| 1816 | handleStartBinderTracking(); |
| 1817 | break; |
| 1818 | case STOP_BINDER_TRACKING_AND_DUMP: |
| 1819 | handleStopBinderTrackingAndDump((ParcelFileDescriptor) msg.obj); |
| 1820 | break; |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 1821 | case MULTI_WINDOW_MODE_CHANGED: |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 1822 | handleMultiWindowModeChanged((IBinder) ((SomeArgs) msg.obj).arg1, |
| 1823 | ((SomeArgs) msg.obj).argi1 == 1, |
| 1824 | (Configuration) ((SomeArgs) msg.obj).arg2); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 1825 | break; |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 1826 | case PICTURE_IN_PICTURE_MODE_CHANGED: |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 1827 | handlePictureInPictureModeChanged((IBinder) ((SomeArgs) msg.obj).arg1, |
| 1828 | ((SomeArgs) msg.obj).argi1 == 1, |
| 1829 | (Configuration) ((SomeArgs) msg.obj).arg2); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 1830 | break; |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1831 | case LOCAL_VOICE_INTERACTION_STARTED: |
| 1832 | handleLocalVoiceInteractionStarted((IBinder) ((SomeArgs) msg.obj).arg1, |
| 1833 | (IVoiceInteractor) ((SomeArgs) msg.obj).arg2); |
Amith Yamasani | 6101911 | 2017-01-10 15:05:00 -0800 | [diff] [blame] | 1834 | break; |
Leonard Mosescu | f3409ce | 2016-10-06 17:32:05 -0700 | [diff] [blame] | 1835 | case ATTACH_AGENT: |
| 1836 | handleAttachAgent((String) msg.obj); |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1837 | break; |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 1838 | case APPLICATION_INFO_CHANGED: |
| 1839 | mUpdatingSystemConfig = true; |
| 1840 | try { |
| 1841 | handleApplicationInfoChanged((ApplicationInfo) msg.obj); |
| 1842 | } finally { |
| 1843 | mUpdatingSystemConfig = false; |
| 1844 | } |
| 1845 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1846 | } |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1847 | Object obj = msg.obj; |
| 1848 | if (obj instanceof SomeArgs) { |
| 1849 | ((SomeArgs) obj).recycle(); |
| 1850 | } |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 1851 | 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] | 1852 | } |
| 1853 | } |
| 1854 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1855 | private class Idler implements MessageQueue.IdleHandler { |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 1856 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1857 | public final boolean queueIdle() { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1858 | ActivityClientRecord a = mNewActivities; |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 1859 | boolean stopProfiling = false; |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 1860 | if (mBoundApplication != null && mProfiler.profileFd != null |
| 1861 | && mProfiler.autoStopProfiler) { |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 1862 | stopProfiling = true; |
| 1863 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1864 | if (a != null) { |
| 1865 | mNewActivities = null; |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 1866 | IActivityManager am = ActivityManager.getService(); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1867 | ActivityClientRecord prev; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1868 | do { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 1869 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1870 | TAG, "Reporting idle of " + a + |
| 1871 | " finished=" + |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1872 | (a.activity != null && a.activity.mFinished)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1873 | if (a.activity != null && !a.activity.mFinished) { |
| 1874 | try { |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 1875 | am.activityIdle(a.token, a.createdConfig, stopProfiling); |
Dianne Hackborn | e88846e | 2009-09-30 21:34:25 -0700 | [diff] [blame] | 1876 | a.createdConfig = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1877 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1878 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1879 | } |
| 1880 | } |
| 1881 | prev = a; |
| 1882 | a = a.nextIdle; |
| 1883 | prev.nextIdle = null; |
| 1884 | } while (a != null); |
| 1885 | } |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 1886 | if (stopProfiling) { |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 1887 | mProfiler.stopProfiling(); |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 1888 | } |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 1889 | ensureJitEnabled(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1890 | return false; |
| 1891 | } |
| 1892 | } |
| 1893 | |
| 1894 | final class GcIdler implements MessageQueue.IdleHandler { |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 1895 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1896 | public final boolean queueIdle() { |
| 1897 | doGcIfNeeded(); |
| 1898 | return false; |
| 1899 | } |
| 1900 | } |
| 1901 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1902 | public static ActivityThread currentActivityThread() { |
Jeff Sharkey | 66a017b | 2013-01-17 18:18:22 -0800 | [diff] [blame] | 1903 | return sCurrentActivityThread; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1904 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1905 | |
Wale Ogunwale | 9a6ef1e | 2015-06-02 13:41:00 -0700 | [diff] [blame] | 1906 | public static boolean isSystem() { |
| 1907 | return (sCurrentActivityThread != null) ? sCurrentActivityThread.mSystemThread : false; |
| 1908 | } |
| 1909 | |
Svetoslav | fbf0eca | 2015-05-01 16:52:41 -0700 | [diff] [blame] | 1910 | public static String currentOpPackageName() { |
| 1911 | ActivityThread am = currentActivityThread(); |
| 1912 | return (am != null && am.getApplication() != null) |
| 1913 | ? am.getApplication().getOpPackageName() : null; |
| 1914 | } |
| 1915 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1916 | public static String currentPackageName() { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1917 | ActivityThread am = currentActivityThread(); |
| 1918 | return (am != null && am.mBoundApplication != null) |
Dianne Hackborn | b57a50b | 2013-04-11 17:29:32 -0700 | [diff] [blame] | 1919 | ? am.mBoundApplication.appInfo.packageName : null; |
| 1920 | } |
| 1921 | |
| 1922 | public static String currentProcessName() { |
| 1923 | ActivityThread am = currentActivityThread(); |
| 1924 | return (am != null && am.mBoundApplication != null) |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1925 | ? am.mBoundApplication.processName : null; |
| 1926 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1927 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1928 | public static Application currentApplication() { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1929 | ActivityThread am = currentActivityThread(); |
| 1930 | return am != null ? am.mInitialApplication : null; |
| 1931 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1932 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1933 | public static IPackageManager getPackageManager() { |
| 1934 | if (sPackageManager != null) { |
| 1935 | //Slog.v("PackageManager", "returning cur default = " + sPackageManager); |
| 1936 | return sPackageManager; |
| 1937 | } |
| 1938 | IBinder b = ServiceManager.getService("package"); |
| 1939 | //Slog.v("PackageManager", "default service binder = " + b); |
| 1940 | sPackageManager = IPackageManager.Stub.asInterface(b); |
| 1941 | //Slog.v("PackageManager", "default service = " + sPackageManager); |
| 1942 | return sPackageManager; |
| 1943 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1944 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1945 | private Configuration mMainThreadConfig = new Configuration(); |
Amith Yamasani | 4f128e4 | 2016-05-10 11:44:12 -0700 | [diff] [blame] | 1946 | |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 1947 | Configuration applyConfigCompatMainThread(int displayDensity, Configuration config, |
| 1948 | CompatibilityInfo compat) { |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1949 | if (config == null) { |
| 1950 | return null; |
| 1951 | } |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 1952 | if (!compat.supportsScreen()) { |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1953 | mMainThreadConfig.setTo(config); |
| 1954 | config = mMainThreadConfig; |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 1955 | compat.applyToConfiguration(displayDensity, config); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1956 | } |
| 1957 | return config; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1958 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1959 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1960 | /** |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 1961 | * Creates the top level resources for the given package. Will return an existing |
| 1962 | * Resources if one has already been created. |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1963 | */ |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 1964 | Resources getTopLevelResources(String resDir, String[] splitResDirs, String[] overlayDirs, |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 1965 | String[] libDirs, int displayId, LoadedApk pkgInfo) { |
| 1966 | return mResourcesManager.getResources(null, resDir, splitResDirs, overlayDirs, libDirs, |
| 1967 | displayId, null, pkgInfo.getCompatibilityInfo(), pkgInfo.getClassLoader()); |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 1968 | } |
| 1969 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1970 | final Handler getHandler() { |
| 1971 | return mH; |
| 1972 | } |
| 1973 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1974 | public final LoadedApk getPackageInfo(String packageName, CompatibilityInfo compatInfo, |
| 1975 | int flags) { |
Amith Yamasani | 98edc95 | 2012-09-25 14:09:27 -0700 | [diff] [blame] | 1976 | return getPackageInfo(packageName, compatInfo, flags, UserHandle.myUserId()); |
| 1977 | } |
| 1978 | |
| 1979 | public final LoadedApk getPackageInfo(String packageName, CompatibilityInfo compatInfo, |
| 1980 | int flags, int userId) { |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 1981 | final boolean differentUser = (UserHandle.myUserId() != userId); |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 1982 | synchronized (mResourcesManager) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1983 | WeakReference<LoadedApk> ref; |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 1984 | if (differentUser) { |
| 1985 | // Caching not supported across users |
| 1986 | ref = null; |
| 1987 | } else if ((flags & Context.CONTEXT_INCLUDE_CODE) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1988 | ref = mPackages.get(packageName); |
| 1989 | } else { |
| 1990 | ref = mResourcePackages.get(packageName); |
| 1991 | } |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 1992 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1993 | LoadedApk packageInfo = ref != null ? ref.get() : null; |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 1994 | //Slog.i(TAG, "getPackageInfo " + packageName + ": " + packageInfo); |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1995 | //if (packageInfo != null) Slog.i(TAG, "isUptoDate " + packageInfo.mResDir |
| 1996 | // + ": " + packageInfo.mResources.getAssets().isUpToDate()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1997 | if (packageInfo != null && (packageInfo.mResources == null |
| 1998 | || packageInfo.mResources.getAssets().isUpToDate())) { |
| 1999 | if (packageInfo.isSecurityViolation() |
| 2000 | && (flags&Context.CONTEXT_IGNORE_SECURITY) == 0) { |
| 2001 | throw new SecurityException( |
| 2002 | "Requesting code from " + packageName |
| 2003 | + " to be run in process " |
| 2004 | + mBoundApplication.processName |
| 2005 | + "/" + mBoundApplication.appInfo.uid); |
| 2006 | } |
| 2007 | return packageInfo; |
| 2008 | } |
| 2009 | } |
| 2010 | |
| 2011 | ApplicationInfo ai = null; |
| 2012 | try { |
| 2013 | ai = getPackageManager().getApplicationInfo(packageName, |
Jeff Sharkey | c5967e9 | 2016-01-07 18:50:29 -0700 | [diff] [blame] | 2014 | PackageManager.GET_SHARED_LIBRARY_FILES |
| 2015 | | PackageManager.MATCH_DEBUG_TRIAGED_MISSING, |
| 2016 | userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2017 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2018 | throw e.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2019 | } |
| 2020 | |
| 2021 | if (ai != null) { |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2022 | return getPackageInfo(ai, compatInfo, flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2023 | } |
| 2024 | |
| 2025 | return null; |
| 2026 | } |
| 2027 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2028 | public final LoadedApk getPackageInfo(ApplicationInfo ai, CompatibilityInfo compatInfo, |
| 2029 | int flags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2030 | boolean includeCode = (flags&Context.CONTEXT_INCLUDE_CODE) != 0; |
| 2031 | boolean securityViolation = includeCode && ai.uid != 0 |
| 2032 | && ai.uid != Process.SYSTEM_UID && (mBoundApplication != null |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 2033 | ? !UserHandle.isSameApp(ai.uid, mBoundApplication.appInfo.uid) |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 2034 | : true); |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 2035 | boolean registerPackage = includeCode && (flags&Context.CONTEXT_REGISTER_PACKAGE) != 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2036 | if ((flags&(Context.CONTEXT_INCLUDE_CODE |
| 2037 | |Context.CONTEXT_IGNORE_SECURITY)) |
| 2038 | == Context.CONTEXT_INCLUDE_CODE) { |
| 2039 | if (securityViolation) { |
| 2040 | String msg = "Requesting code from " + ai.packageName |
| 2041 | + " (with uid " + ai.uid + ")"; |
| 2042 | if (mBoundApplication != null) { |
| 2043 | msg = msg + " to be run in process " |
| 2044 | + mBoundApplication.processName + " (with uid " |
| 2045 | + mBoundApplication.appInfo.uid + ")"; |
| 2046 | } |
| 2047 | throw new SecurityException(msg); |
| 2048 | } |
| 2049 | } |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 2050 | return getPackageInfo(ai, compatInfo, null, securityViolation, includeCode, |
| 2051 | registerPackage); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2052 | } |
| 2053 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2054 | public final LoadedApk getPackageInfoNoCheck(ApplicationInfo ai, |
| 2055 | CompatibilityInfo compatInfo) { |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 2056 | return getPackageInfo(ai, compatInfo, null, false, true, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2057 | } |
| 2058 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2059 | public final LoadedApk peekPackageInfo(String packageName, boolean includeCode) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 2060 | synchronized (mResourcesManager) { |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2061 | WeakReference<LoadedApk> ref; |
| 2062 | if (includeCode) { |
| 2063 | ref = mPackages.get(packageName); |
| 2064 | } else { |
| 2065 | ref = mResourcePackages.get(packageName); |
| 2066 | } |
| 2067 | return ref != null ? ref.get() : null; |
| 2068 | } |
| 2069 | } |
| 2070 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 2071 | private LoadedApk getPackageInfo(ApplicationInfo aInfo, CompatibilityInfo compatInfo, |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 2072 | ClassLoader baseLoader, boolean securityViolation, boolean includeCode, |
| 2073 | boolean registerPackage) { |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 2074 | final boolean differentUser = (UserHandle.myUserId() != UserHandle.getUserId(aInfo.uid)); |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 2075 | synchronized (mResourcesManager) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2076 | WeakReference<LoadedApk> ref; |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 2077 | if (differentUser) { |
| 2078 | // Caching not supported across users |
| 2079 | ref = null; |
| 2080 | } else if (includeCode) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2081 | ref = mPackages.get(aInfo.packageName); |
| 2082 | } else { |
| 2083 | ref = mResourcePackages.get(aInfo.packageName); |
| 2084 | } |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 2085 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2086 | LoadedApk packageInfo = ref != null ? ref.get() : null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2087 | if (packageInfo == null || (packageInfo.mResources != null |
| 2088 | && !packageInfo.mResources.getAssets().isUpToDate())) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2089 | if (localLOGV) Slog.v(TAG, (includeCode ? "Loading code package " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2090 | : "Loading resource-only package ") + aInfo.packageName |
| 2091 | + " (in " + (mBoundApplication != null |
| 2092 | ? mBoundApplication.processName : null) |
| 2093 | + ")"); |
| 2094 | packageInfo = |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 2095 | new LoadedApk(this, aInfo, compatInfo, baseLoader, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2096 | securityViolation, includeCode && |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 2097 | (aInfo.flags&ApplicationInfo.FLAG_HAS_CODE) != 0, registerPackage); |
Narayan Kamath | cb38318 | 2014-10-29 17:56:42 +0000 | [diff] [blame] | 2098 | |
| 2099 | if (mSystemThread && "android".equals(aInfo.packageName)) { |
| 2100 | packageInfo.installSystemApplicationInfo(aInfo, |
| 2101 | getSystemContext().mPackageInfo.getClassLoader()); |
| 2102 | } |
| 2103 | |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 2104 | if (differentUser) { |
| 2105 | // Caching not supported across users |
| 2106 | } else if (includeCode) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2107 | mPackages.put(aInfo.packageName, |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2108 | new WeakReference<LoadedApk>(packageInfo)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2109 | } else { |
| 2110 | mResourcePackages.put(aInfo.packageName, |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2111 | new WeakReference<LoadedApk>(packageInfo)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2112 | } |
| 2113 | } |
| 2114 | return packageInfo; |
| 2115 | } |
| 2116 | } |
| 2117 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2118 | ActivityThread() { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 2119 | mResourcesManager = ResourcesManager.getInstance(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2120 | } |
| 2121 | |
| 2122 | public ApplicationThread getApplicationThread() |
| 2123 | { |
| 2124 | return mAppThread; |
| 2125 | } |
| 2126 | |
| 2127 | public Instrumentation getInstrumentation() |
| 2128 | { |
| 2129 | return mInstrumentation; |
| 2130 | } |
| 2131 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2132 | public boolean isProfiling() { |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 2133 | return mProfiler != null && mProfiler.profileFile != null |
| 2134 | && mProfiler.profileFd == null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2135 | } |
| 2136 | |
| 2137 | public String getProfileFilePath() { |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 2138 | return mProfiler.profileFile; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2139 | } |
| 2140 | |
| 2141 | public Looper getLooper() { |
| 2142 | return mLooper; |
| 2143 | } |
| 2144 | |
| 2145 | public Application getApplication() { |
| 2146 | return mInitialApplication; |
| 2147 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2148 | |
Dianne Hackborn | d97c7ad | 2009-06-19 11:37:35 -0700 | [diff] [blame] | 2149 | public String getProcessName() { |
| 2150 | return mBoundApplication.processName; |
| 2151 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2152 | |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 2153 | public ContextImpl getSystemContext() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2154 | synchronized (this) { |
| 2155 | if (mSystemContext == null) { |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 2156 | mSystemContext = ContextImpl.createSystemContext(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2157 | } |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 2158 | return mSystemContext; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2159 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2160 | } |
| 2161 | |
Adam Lesinski | a82b626 | 2017-03-21 16:56:17 -0700 | [diff] [blame] | 2162 | public ContextImpl getSystemUiContext() { |
| 2163 | synchronized (this) { |
| 2164 | if (mSystemUiContext == null) { |
Adam Lesinski | 6f1a917 | 2017-04-10 16:35:19 -0700 | [diff] [blame] | 2165 | mSystemUiContext = ContextImpl.createSystemUiContext(getSystemContext()); |
Adam Lesinski | a82b626 | 2017-03-21 16:56:17 -0700 | [diff] [blame] | 2166 | } |
| 2167 | return mSystemUiContext; |
| 2168 | } |
| 2169 | } |
| 2170 | |
Narayan Kamath | 29564cd | 2014-08-07 10:57:40 +0100 | [diff] [blame] | 2171 | public void installSystemApplicationInfo(ApplicationInfo info, ClassLoader classLoader) { |
Mike Cleron | 432b713 | 2009-09-24 15:28:29 -0700 | [diff] [blame] | 2172 | synchronized (this) { |
Narayan Kamath | 29564cd | 2014-08-07 10:57:40 +0100 | [diff] [blame] | 2173 | getSystemContext().installSystemApplicationInfo(info, classLoader); |
Adam Lesinski | a82b626 | 2017-03-21 16:56:17 -0700 | [diff] [blame] | 2174 | getSystemUiContext().installSystemApplicationInfo(info, classLoader); |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 2175 | |
| 2176 | // give ourselves a default profiler |
| 2177 | mProfiler = new Profiler(); |
Mike Cleron | 432b713 | 2009-09-24 15:28:29 -0700 | [diff] [blame] | 2178 | } |
| 2179 | } |
| 2180 | |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 2181 | void ensureJitEnabled() { |
| 2182 | if (!mJitEnabled) { |
| 2183 | mJitEnabled = true; |
| 2184 | dalvik.system.VMRuntime.getRuntime().startJitCompilation(); |
| 2185 | } |
| 2186 | } |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 2187 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2188 | void scheduleGcIdler() { |
| 2189 | if (!mGcIdlerScheduled) { |
| 2190 | mGcIdlerScheduled = true; |
| 2191 | Looper.myQueue().addIdleHandler(mGcIdler); |
| 2192 | } |
| 2193 | mH.removeMessages(H.GC_WHEN_IDLE); |
| 2194 | } |
| 2195 | |
| 2196 | void unscheduleGcIdler() { |
| 2197 | if (mGcIdlerScheduled) { |
| 2198 | mGcIdlerScheduled = false; |
| 2199 | Looper.myQueue().removeIdleHandler(mGcIdler); |
| 2200 | } |
| 2201 | mH.removeMessages(H.GC_WHEN_IDLE); |
| 2202 | } |
| 2203 | |
| 2204 | void doGcIfNeeded() { |
| 2205 | mGcIdlerScheduled = false; |
| 2206 | final long now = SystemClock.uptimeMillis(); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2207 | //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] | 2208 | // + "m now=" + now); |
| 2209 | if ((BinderInternal.getLastGcTime()+MIN_TIME_BETWEEN_GCS) < now) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2210 | //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] | 2211 | BinderInternal.forceGc("bg"); |
| 2212 | } |
| 2213 | } |
| 2214 | |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2215 | private static final String HEAP_FULL_COLUMN |
| 2216 | = "%13s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s"; |
| 2217 | private static final String HEAP_COLUMN |
| 2218 | = "%13s %8s %8s %8s %8s %8s %8s %8s"; |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2219 | private static final String ONE_COUNT_COLUMN = "%21s %8d"; |
| 2220 | private static final String TWO_COUNT_COLUMNS = "%21s %8d %21s %8d"; |
| 2221 | private static final String ONE_COUNT_COLUMN_HEADER = "%21s %8s"; |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2222 | |
| 2223 | // Formatting for checkin service - update version if row format changes |
Martijn Coenen | 41f94ed | 2015-12-14 15:28:51 +0100 | [diff] [blame] | 2224 | private static final int ACTIVITY_THREAD_CHECKIN_VERSION = 4; |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2225 | |
| 2226 | static void printRow(PrintWriter pw, String format, Object...objs) { |
| 2227 | pw.println(String.format(format, objs)); |
| 2228 | } |
| 2229 | |
| 2230 | public static void dumpMemInfoTable(PrintWriter pw, Debug.MemoryInfo memInfo, boolean checkin, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2231 | boolean dumpFullInfo, boolean dumpDalvik, boolean dumpSummaryOnly, |
| 2232 | int pid, String processName, |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2233 | long nativeMax, long nativeAllocated, long nativeFree, |
| 2234 | long dalvikMax, long dalvikAllocated, long dalvikFree) { |
| 2235 | |
| 2236 | // For checkin, we print one long comma-separated list of values |
| 2237 | if (checkin) { |
| 2238 | // NOTE: if you change anything significant below, also consider changing |
| 2239 | // ACTIVITY_THREAD_CHECKIN_VERSION. |
| 2240 | |
| 2241 | // Header |
| 2242 | pw.print(ACTIVITY_THREAD_CHECKIN_VERSION); pw.print(','); |
| 2243 | pw.print(pid); pw.print(','); |
| 2244 | pw.print(processName); pw.print(','); |
| 2245 | |
| 2246 | // Heap info - max |
| 2247 | pw.print(nativeMax); pw.print(','); |
| 2248 | pw.print(dalvikMax); pw.print(','); |
| 2249 | pw.print("N/A,"); |
| 2250 | pw.print(nativeMax + dalvikMax); pw.print(','); |
| 2251 | |
| 2252 | // Heap info - allocated |
| 2253 | pw.print(nativeAllocated); pw.print(','); |
| 2254 | pw.print(dalvikAllocated); pw.print(','); |
| 2255 | pw.print("N/A,"); |
| 2256 | pw.print(nativeAllocated + dalvikAllocated); pw.print(','); |
| 2257 | |
| 2258 | // Heap info - free |
| 2259 | pw.print(nativeFree); pw.print(','); |
| 2260 | pw.print(dalvikFree); pw.print(','); |
| 2261 | pw.print("N/A,"); |
| 2262 | pw.print(nativeFree + dalvikFree); pw.print(','); |
| 2263 | |
| 2264 | // Heap info - proportional set size |
| 2265 | pw.print(memInfo.nativePss); pw.print(','); |
| 2266 | pw.print(memInfo.dalvikPss); pw.print(','); |
| 2267 | pw.print(memInfo.otherPss); pw.print(','); |
| 2268 | pw.print(memInfo.getTotalPss()); pw.print(','); |
| 2269 | |
| 2270 | // Heap info - swappable set size |
| 2271 | pw.print(memInfo.nativeSwappablePss); pw.print(','); |
| 2272 | pw.print(memInfo.dalvikSwappablePss); pw.print(','); |
| 2273 | pw.print(memInfo.otherSwappablePss); pw.print(','); |
| 2274 | pw.print(memInfo.getTotalSwappablePss()); pw.print(','); |
| 2275 | |
| 2276 | // Heap info - shared dirty |
| 2277 | pw.print(memInfo.nativeSharedDirty); pw.print(','); |
| 2278 | pw.print(memInfo.dalvikSharedDirty); pw.print(','); |
| 2279 | pw.print(memInfo.otherSharedDirty); pw.print(','); |
| 2280 | pw.print(memInfo.getTotalSharedDirty()); pw.print(','); |
| 2281 | |
| 2282 | // Heap info - shared clean |
| 2283 | pw.print(memInfo.nativeSharedClean); pw.print(','); |
| 2284 | pw.print(memInfo.dalvikSharedClean); pw.print(','); |
| 2285 | pw.print(memInfo.otherSharedClean); pw.print(','); |
| 2286 | pw.print(memInfo.getTotalSharedClean()); pw.print(','); |
| 2287 | |
| 2288 | // Heap info - private Dirty |
| 2289 | pw.print(memInfo.nativePrivateDirty); pw.print(','); |
| 2290 | pw.print(memInfo.dalvikPrivateDirty); pw.print(','); |
| 2291 | pw.print(memInfo.otherPrivateDirty); pw.print(','); |
| 2292 | pw.print(memInfo.getTotalPrivateDirty()); pw.print(','); |
| 2293 | |
| 2294 | // Heap info - private Clean |
| 2295 | pw.print(memInfo.nativePrivateClean); pw.print(','); |
| 2296 | pw.print(memInfo.dalvikPrivateClean); pw.print(','); |
| 2297 | pw.print(memInfo.otherPrivateClean); pw.print(','); |
| 2298 | pw.print(memInfo.getTotalPrivateClean()); pw.print(','); |
| 2299 | |
Martijn Coenen | 41f94ed | 2015-12-14 15:28:51 +0100 | [diff] [blame] | 2300 | // Heap info - swapped out |
| 2301 | pw.print(memInfo.nativeSwappedOut); pw.print(','); |
| 2302 | pw.print(memInfo.dalvikSwappedOut); pw.print(','); |
| 2303 | pw.print(memInfo.otherSwappedOut); pw.print(','); |
| 2304 | pw.print(memInfo.getTotalSwappedOut()); pw.print(','); |
| 2305 | |
| 2306 | // Heap info - swapped out pss |
| 2307 | if (memInfo.hasSwappedOutPss) { |
| 2308 | pw.print(memInfo.nativeSwappedOutPss); pw.print(','); |
| 2309 | pw.print(memInfo.dalvikSwappedOutPss); pw.print(','); |
| 2310 | pw.print(memInfo.otherSwappedOutPss); pw.print(','); |
| 2311 | pw.print(memInfo.getTotalSwappedOutPss()); pw.print(','); |
| 2312 | } else { |
| 2313 | pw.print("N/A,"); |
| 2314 | pw.print("N/A,"); |
| 2315 | pw.print("N/A,"); |
| 2316 | pw.print("N/A,"); |
| 2317 | } |
| 2318 | |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2319 | // Heap info - other areas |
| 2320 | for (int i=0; i<Debug.MemoryInfo.NUM_OTHER_STATS; i++) { |
| 2321 | pw.print(Debug.MemoryInfo.getOtherLabel(i)); pw.print(','); |
| 2322 | pw.print(memInfo.getOtherPss(i)); pw.print(','); |
| 2323 | pw.print(memInfo.getOtherSwappablePss(i)); pw.print(','); |
| 2324 | pw.print(memInfo.getOtherSharedDirty(i)); pw.print(','); |
| 2325 | pw.print(memInfo.getOtherSharedClean(i)); pw.print(','); |
| 2326 | pw.print(memInfo.getOtherPrivateDirty(i)); pw.print(','); |
| 2327 | pw.print(memInfo.getOtherPrivateClean(i)); pw.print(','); |
Martijn Coenen | 41f94ed | 2015-12-14 15:28:51 +0100 | [diff] [blame] | 2328 | pw.print(memInfo.getOtherSwappedOut(i)); pw.print(','); |
| 2329 | if (memInfo.hasSwappedOutPss) { |
| 2330 | pw.print(memInfo.getOtherSwappedOutPss(i)); pw.print(','); |
| 2331 | } else { |
| 2332 | pw.print("N/A,"); |
| 2333 | } |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2334 | } |
| 2335 | return; |
| 2336 | } |
| 2337 | |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2338 | if (!dumpSummaryOnly) { |
| 2339 | if (dumpFullInfo) { |
| 2340 | printRow(pw, HEAP_FULL_COLUMN, "", "Pss", "Pss", "Shared", "Private", |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2341 | "Shared", "Private", memInfo.hasSwappedOutPss ? "SwapPss" : "Swap", |
| 2342 | "Heap", "Heap", "Heap"); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2343 | printRow(pw, HEAP_FULL_COLUMN, "", "Total", "Clean", "Dirty", "Dirty", |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2344 | "Clean", "Clean", "Dirty", |
| 2345 | "Size", "Alloc", "Free"); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2346 | printRow(pw, HEAP_FULL_COLUMN, "", "------", "------", "------", "------", |
| 2347 | "------", "------", "------", "------", "------", "------"); |
| 2348 | printRow(pw, HEAP_FULL_COLUMN, "Native Heap", memInfo.nativePss, |
| 2349 | memInfo.nativeSwappablePss, memInfo.nativeSharedDirty, |
| 2350 | memInfo.nativePrivateDirty, memInfo.nativeSharedClean, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2351 | memInfo.nativePrivateClean, memInfo.hasSwappedOutPss ? |
Richard Uhler | 91702eb3 | 2017-06-23 16:54:25 +0100 | [diff] [blame] | 2352 | memInfo.nativeSwappedOutPss : memInfo.nativeSwappedOut, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2353 | nativeMax, nativeAllocated, nativeFree); |
| 2354 | printRow(pw, HEAP_FULL_COLUMN, "Dalvik Heap", memInfo.dalvikPss, |
| 2355 | memInfo.dalvikSwappablePss, memInfo.dalvikSharedDirty, |
| 2356 | memInfo.dalvikPrivateDirty, memInfo.dalvikSharedClean, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2357 | memInfo.dalvikPrivateClean, memInfo.hasSwappedOutPss ? |
Richard Uhler | 91702eb3 | 2017-06-23 16:54:25 +0100 | [diff] [blame] | 2358 | memInfo.dalvikSwappedOutPss : memInfo.dalvikSwappedOut, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2359 | dalvikMax, dalvikAllocated, dalvikFree); |
| 2360 | } else { |
| 2361 | printRow(pw, HEAP_COLUMN, "", "Pss", "Private", |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2362 | "Private", memInfo.hasSwappedOutPss ? "SwapPss" : "Swap", |
| 2363 | "Heap", "Heap", "Heap"); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2364 | printRow(pw, HEAP_COLUMN, "", "Total", "Dirty", |
| 2365 | "Clean", "Dirty", "Size", "Alloc", "Free"); |
| 2366 | printRow(pw, HEAP_COLUMN, "", "------", "------", "------", |
| 2367 | "------", "------", "------", "------", "------"); |
| 2368 | printRow(pw, HEAP_COLUMN, "Native Heap", memInfo.nativePss, |
| 2369 | memInfo.nativePrivateDirty, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2370 | memInfo.nativePrivateClean, |
| 2371 | memInfo.hasSwappedOutPss ? memInfo.nativeSwappedOutPss : |
| 2372 | memInfo.nativeSwappedOut, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2373 | nativeMax, nativeAllocated, nativeFree); |
| 2374 | printRow(pw, HEAP_COLUMN, "Dalvik Heap", memInfo.dalvikPss, |
| 2375 | memInfo.dalvikPrivateDirty, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2376 | memInfo.dalvikPrivateClean, |
| 2377 | memInfo.hasSwappedOutPss ? memInfo.dalvikSwappedOutPss : |
| 2378 | memInfo.dalvikSwappedOut, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2379 | dalvikMax, dalvikAllocated, dalvikFree); |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2380 | } |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2381 | |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2382 | int otherPss = memInfo.otherPss; |
| 2383 | int otherSwappablePss = memInfo.otherSwappablePss; |
| 2384 | int otherSharedDirty = memInfo.otherSharedDirty; |
| 2385 | int otherPrivateDirty = memInfo.otherPrivateDirty; |
| 2386 | int otherSharedClean = memInfo.otherSharedClean; |
| 2387 | int otherPrivateClean = memInfo.otherPrivateClean; |
| 2388 | int otherSwappedOut = memInfo.otherSwappedOut; |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2389 | int otherSwappedOutPss = memInfo.otherSwappedOutPss; |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2390 | |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2391 | for (int i=0; i<Debug.MemoryInfo.NUM_OTHER_STATS; i++) { |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2392 | final int myPss = memInfo.getOtherPss(i); |
| 2393 | final int mySwappablePss = memInfo.getOtherSwappablePss(i); |
| 2394 | final int mySharedDirty = memInfo.getOtherSharedDirty(i); |
| 2395 | final int myPrivateDirty = memInfo.getOtherPrivateDirty(i); |
| 2396 | final int mySharedClean = memInfo.getOtherSharedClean(i); |
| 2397 | final int myPrivateClean = memInfo.getOtherPrivateClean(i); |
| 2398 | final int mySwappedOut = memInfo.getOtherSwappedOut(i); |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2399 | final int mySwappedOutPss = memInfo.getOtherSwappedOutPss(i); |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2400 | if (myPss != 0 || mySharedDirty != 0 || myPrivateDirty != 0 |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2401 | || mySharedClean != 0 || myPrivateClean != 0 |
| 2402 | || (memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut) != 0) { |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2403 | if (dumpFullInfo) { |
| 2404 | printRow(pw, HEAP_FULL_COLUMN, Debug.MemoryInfo.getOtherLabel(i), |
| 2405 | myPss, mySwappablePss, mySharedDirty, myPrivateDirty, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2406 | mySharedClean, myPrivateClean, |
| 2407 | memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut, |
| 2408 | "", "", ""); |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2409 | } else { |
| 2410 | printRow(pw, HEAP_COLUMN, Debug.MemoryInfo.getOtherLabel(i), |
| 2411 | myPss, myPrivateDirty, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2412 | myPrivateClean, |
| 2413 | memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut, |
| 2414 | "", "", ""); |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2415 | } |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2416 | otherPss -= myPss; |
| 2417 | otherSwappablePss -= mySwappablePss; |
| 2418 | otherSharedDirty -= mySharedDirty; |
| 2419 | otherPrivateDirty -= myPrivateDirty; |
| 2420 | otherSharedClean -= mySharedClean; |
| 2421 | otherPrivateClean -= myPrivateClean; |
| 2422 | otherSwappedOut -= mySwappedOut; |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2423 | otherSwappedOutPss -= mySwappedOutPss; |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2424 | } |
| 2425 | } |
| 2426 | |
| 2427 | if (dumpFullInfo) { |
| 2428 | printRow(pw, HEAP_FULL_COLUMN, "Unknown", otherPss, otherSwappablePss, |
| 2429 | otherSharedDirty, otherPrivateDirty, otherSharedClean, otherPrivateClean, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2430 | memInfo.hasSwappedOutPss ? otherSwappedOutPss : otherSwappedOut, |
| 2431 | "", "", ""); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2432 | printRow(pw, HEAP_FULL_COLUMN, "TOTAL", memInfo.getTotalPss(), |
| 2433 | memInfo.getTotalSwappablePss(), |
| 2434 | memInfo.getTotalSharedDirty(), memInfo.getTotalPrivateDirty(), |
| 2435 | memInfo.getTotalSharedClean(), memInfo.getTotalPrivateClean(), |
Thierry Strudel | 9b51160 | 2016-02-25 17:46:38 -0800 | [diff] [blame] | 2436 | memInfo.hasSwappedOutPss ? memInfo.getTotalSwappedOutPss() : |
| 2437 | memInfo.getTotalSwappedOut(), |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2438 | nativeMax+dalvikMax, nativeAllocated+dalvikAllocated, |
| 2439 | nativeFree+dalvikFree); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2440 | } else { |
| 2441 | printRow(pw, HEAP_COLUMN, "Unknown", otherPss, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2442 | otherPrivateDirty, otherPrivateClean, |
| 2443 | memInfo.hasSwappedOutPss ? otherSwappedOutPss : otherSwappedOut, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2444 | "", "", ""); |
| 2445 | printRow(pw, HEAP_COLUMN, "TOTAL", memInfo.getTotalPss(), |
| 2446 | memInfo.getTotalPrivateDirty(), |
| 2447 | memInfo.getTotalPrivateClean(), |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2448 | memInfo.hasSwappedOutPss ? memInfo.getTotalSwappedOutPss() : |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2449 | memInfo.getTotalSwappedOut(), |
| 2450 | nativeMax+dalvikMax, |
| 2451 | nativeAllocated+dalvikAllocated, nativeFree+dalvikFree); |
| 2452 | } |
| 2453 | |
| 2454 | if (dumpDalvik) { |
| 2455 | pw.println(" "); |
| 2456 | pw.println(" Dalvik Details"); |
| 2457 | |
| 2458 | for (int i=Debug.MemoryInfo.NUM_OTHER_STATS; |
| 2459 | i<Debug.MemoryInfo.NUM_OTHER_STATS + Debug.MemoryInfo.NUM_DVK_STATS; i++) { |
| 2460 | final int myPss = memInfo.getOtherPss(i); |
| 2461 | final int mySwappablePss = memInfo.getOtherSwappablePss(i); |
| 2462 | final int mySharedDirty = memInfo.getOtherSharedDirty(i); |
| 2463 | final int myPrivateDirty = memInfo.getOtherPrivateDirty(i); |
| 2464 | final int mySharedClean = memInfo.getOtherSharedClean(i); |
| 2465 | final int myPrivateClean = memInfo.getOtherPrivateClean(i); |
| 2466 | final int mySwappedOut = memInfo.getOtherSwappedOut(i); |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2467 | final int mySwappedOutPss = memInfo.getOtherSwappedOutPss(i); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2468 | if (myPss != 0 || mySharedDirty != 0 || myPrivateDirty != 0 |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2469 | || mySharedClean != 0 || myPrivateClean != 0 |
| 2470 | || (memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut) != 0) { |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2471 | if (dumpFullInfo) { |
| 2472 | printRow(pw, HEAP_FULL_COLUMN, Debug.MemoryInfo.getOtherLabel(i), |
| 2473 | myPss, mySwappablePss, mySharedDirty, myPrivateDirty, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2474 | mySharedClean, myPrivateClean, |
| 2475 | memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut, |
| 2476 | "", "", ""); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2477 | } else { |
| 2478 | printRow(pw, HEAP_COLUMN, Debug.MemoryInfo.getOtherLabel(i), |
| 2479 | myPss, myPrivateDirty, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2480 | myPrivateClean, |
| 2481 | memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut, |
| 2482 | "", "", ""); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2483 | } |
| 2484 | } |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2485 | } |
| 2486 | } |
| 2487 | } |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2488 | |
| 2489 | pw.println(" "); |
| 2490 | pw.println(" App Summary"); |
| 2491 | printRow(pw, ONE_COUNT_COLUMN_HEADER, "", "Pss(KB)"); |
| 2492 | printRow(pw, ONE_COUNT_COLUMN_HEADER, "", "------"); |
| 2493 | printRow(pw, ONE_COUNT_COLUMN, |
| 2494 | "Java Heap:", memInfo.getSummaryJavaHeap()); |
| 2495 | printRow(pw, ONE_COUNT_COLUMN, |
| 2496 | "Native Heap:", memInfo.getSummaryNativeHeap()); |
| 2497 | printRow(pw, ONE_COUNT_COLUMN, |
| 2498 | "Code:", memInfo.getSummaryCode()); |
| 2499 | printRow(pw, ONE_COUNT_COLUMN, |
| 2500 | "Stack:", memInfo.getSummaryStack()); |
| 2501 | printRow(pw, ONE_COUNT_COLUMN, |
| 2502 | "Graphics:", memInfo.getSummaryGraphics()); |
| 2503 | printRow(pw, ONE_COUNT_COLUMN, |
| 2504 | "Private Other:", memInfo.getSummaryPrivateOther()); |
| 2505 | printRow(pw, ONE_COUNT_COLUMN, |
| 2506 | "System:", memInfo.getSummarySystem()); |
| 2507 | pw.println(" "); |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2508 | if (memInfo.hasSwappedOutPss) { |
| 2509 | printRow(pw, TWO_COUNT_COLUMNS, |
| 2510 | "TOTAL:", memInfo.getSummaryTotalPss(), |
| 2511 | "TOTAL SWAP PSS:", memInfo.getSummaryTotalSwapPss()); |
| 2512 | } else { |
| 2513 | printRow(pw, TWO_COUNT_COLUMNS, |
| 2514 | "TOTAL:", memInfo.getSummaryTotalPss(), |
| 2515 | "TOTAL SWAP (KB):", memInfo.getSummaryTotalSwap()); |
| 2516 | } |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2517 | } |
| 2518 | |
Jeff Hamilton | 52d3203 | 2011-01-08 15:31:26 -0600 | [diff] [blame] | 2519 | public void registerOnActivityPausedListener(Activity activity, |
| 2520 | OnActivityPausedListener listener) { |
| 2521 | synchronized (mOnPauseListeners) { |
| 2522 | ArrayList<OnActivityPausedListener> list = mOnPauseListeners.get(activity); |
| 2523 | if (list == null) { |
| 2524 | list = new ArrayList<OnActivityPausedListener>(); |
| 2525 | mOnPauseListeners.put(activity, list); |
| 2526 | } |
| 2527 | list.add(listener); |
| 2528 | } |
| 2529 | } |
| 2530 | |
Jeff Hamilton | ce3224c | 2011-01-17 11:05:03 -0800 | [diff] [blame] | 2531 | public void unregisterOnActivityPausedListener(Activity activity, |
| 2532 | OnActivityPausedListener listener) { |
| 2533 | synchronized (mOnPauseListeners) { |
| 2534 | ArrayList<OnActivityPausedListener> list = mOnPauseListeners.get(activity); |
| 2535 | if (list != null) { |
| 2536 | list.remove(listener); |
| 2537 | } |
| 2538 | } |
| 2539 | } |
| 2540 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2541 | public final ActivityInfo resolveActivityInfo(Intent intent) { |
| 2542 | ActivityInfo aInfo = intent.resolveActivityInfo( |
| 2543 | mInitialApplication.getPackageManager(), PackageManager.GET_SHARED_LIBRARY_FILES); |
| 2544 | if (aInfo == null) { |
| 2545 | // Throw an exception. |
| 2546 | Instrumentation.checkStartActivityResult( |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 2547 | ActivityManager.START_CLASS_NOT_FOUND, intent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2548 | } |
| 2549 | return aInfo; |
| 2550 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2551 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2552 | public final Activity startActivityNow(Activity parent, String id, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2553 | Intent intent, ActivityInfo activityInfo, IBinder token, Bundle state, |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 2554 | Activity.NonConfigurationInstances lastNonConfigurationInstances) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2555 | ActivityClientRecord r = new ActivityClientRecord(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2556 | r.token = token; |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 2557 | r.ident = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2558 | r.intent = intent; |
| 2559 | r.state = state; |
| 2560 | r.parent = parent; |
| 2561 | r.embeddedID = id; |
| 2562 | r.activityInfo = activityInfo; |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 2563 | r.lastNonConfigurationInstances = lastNonConfigurationInstances; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2564 | if (localLOGV) { |
| 2565 | ComponentName compname = intent.getComponent(); |
| 2566 | String name; |
| 2567 | if (compname != null) { |
| 2568 | name = compname.toShortString(); |
| 2569 | } else { |
| 2570 | name = "(Intent " + intent + ").getComponent() returned null"; |
| 2571 | } |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2572 | Slog.v(TAG, "Performing launch: action=" + intent.getAction() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2573 | + ", comp=" + name |
| 2574 | + ", token=" + token); |
| 2575 | } |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 2576 | return performLaunchActivity(r, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2577 | } |
| 2578 | |
| 2579 | public final Activity getActivity(IBinder token) { |
| 2580 | return mActivities.get(token).activity; |
| 2581 | } |
| 2582 | |
| 2583 | public final void sendActivityResult( |
| 2584 | IBinder token, String id, int requestCode, |
| 2585 | int resultCode, Intent data) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2586 | if (DEBUG_RESULTS) Slog.v(TAG, "sendActivityResult: id=" + id |
Chris Tate | 8a7dc17 | 2009-03-24 20:11:42 -0700 | [diff] [blame] | 2587 | + " req=" + requestCode + " res=" + resultCode + " data=" + data); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2588 | ArrayList<ResultInfo> list = new ArrayList<ResultInfo>(); |
| 2589 | list.add(new ResultInfo(id, requestCode, resultCode, data)); |
| 2590 | mAppThread.scheduleSendResult(token, list); |
| 2591 | } |
| 2592 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 2593 | private void sendMessage(int what, Object obj) { |
| 2594 | sendMessage(what, obj, 0, 0, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2595 | } |
| 2596 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 2597 | private void sendMessage(int what, Object obj, int arg1) { |
| 2598 | sendMessage(what, obj, arg1, 0, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2599 | } |
| 2600 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 2601 | private void sendMessage(int what, Object obj, int arg1, int arg2) { |
| 2602 | sendMessage(what, obj, arg1, arg2, false); |
| 2603 | } |
| 2604 | |
| 2605 | private void sendMessage(int what, Object obj, int arg1, int arg2, boolean async) { |
| 2606 | if (DEBUG_MESSAGES) Slog.v( |
| 2607 | TAG, "SCHEDULE " + what + " " + mH.codeToString(what) |
| 2608 | + ": " + arg1 + " / " + obj); |
| 2609 | Message msg = Message.obtain(); |
| 2610 | msg.what = what; |
| 2611 | msg.obj = obj; |
| 2612 | msg.arg1 = arg1; |
| 2613 | msg.arg2 = arg2; |
| 2614 | if (async) { |
| 2615 | msg.setAsynchronous(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2616 | } |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 2617 | mH.sendMessage(msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2618 | } |
| 2619 | |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 2620 | private void sendMessage(int what, Object obj, int arg1, int arg2, int seq) { |
| 2621 | if (DEBUG_MESSAGES) Slog.v( |
| 2622 | TAG, "SCHEDULE " + mH.codeToString(what) + " arg1=" + arg1 + " arg2=" + arg2 + |
| 2623 | "seq= " + seq); |
| 2624 | Message msg = Message.obtain(); |
| 2625 | msg.what = what; |
| 2626 | SomeArgs args = SomeArgs.obtain(); |
| 2627 | args.arg1 = obj; |
| 2628 | args.argi1 = arg1; |
| 2629 | args.argi2 = arg2; |
| 2630 | args.argi3 = seq; |
| 2631 | msg.obj = args; |
| 2632 | mH.sendMessage(msg); |
| 2633 | } |
| 2634 | |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 2635 | final void scheduleContextCleanup(ContextImpl context, String who, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2636 | String what) { |
| 2637 | ContextCleanupInfo cci = new ContextCleanupInfo(); |
| 2638 | cci.context = context; |
| 2639 | cci.who = who; |
| 2640 | cci.what = what; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 2641 | sendMessage(H.CLEAN_UP_CONTEXT, cci); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2642 | } |
| 2643 | |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 2644 | private Activity performLaunchActivity(ActivityClientRecord r, Intent customIntent) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2645 | // System.out.println("##### [" + System.currentTimeMillis() + "] ActivityThread.performLaunchActivity(" + r + ")"); |
| 2646 | |
| 2647 | ActivityInfo aInfo = r.activityInfo; |
| 2648 | if (r.packageInfo == null) { |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2649 | r.packageInfo = getPackageInfo(aInfo.applicationInfo, r.compatInfo, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2650 | Context.CONTEXT_INCLUDE_CODE); |
| 2651 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2652 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2653 | ComponentName component = r.intent.getComponent(); |
| 2654 | if (component == null) { |
| 2655 | component = r.intent.resolveActivity( |
| 2656 | mInitialApplication.getPackageManager()); |
| 2657 | r.intent.setComponent(component); |
| 2658 | } |
| 2659 | |
| 2660 | if (r.activityInfo.targetActivity != null) { |
| 2661 | component = new ComponentName(r.activityInfo.packageName, |
| 2662 | r.activityInfo.targetActivity); |
| 2663 | } |
| 2664 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 2665 | ContextImpl appContext = createBaseContextForActivity(r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2666 | Activity activity = null; |
| 2667 | try { |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 2668 | java.lang.ClassLoader cl = appContext.getClassLoader(); |
Jason Monk | 6945710 | 2017-06-06 18:01:31 -0400 | [diff] [blame] | 2669 | if (appContext.getApplicationContext() instanceof Application) { |
| 2670 | activity = ((Application) appContext.getApplicationContext()) |
| 2671 | .instantiateActivity(cl, component.getClassName(), r.intent); |
| 2672 | } |
| 2673 | if (activity == null) { |
| 2674 | activity = mInstrumentation.newActivity( |
| 2675 | cl, component.getClassName(), r.intent); |
| 2676 | } |
Brad Fitzpatrick | 5f8b5c1 | 2011-01-20 15:12:08 -0800 | [diff] [blame] | 2677 | StrictMode.incrementExpectedActivityCount(activity.getClass()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2678 | r.intent.setExtrasClassLoader(cl); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 2679 | r.intent.prepareToEnterProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2680 | if (r.state != null) { |
| 2681 | r.state.setClassLoader(cl); |
| 2682 | } |
| 2683 | } catch (Exception e) { |
| 2684 | if (!mInstrumentation.onException(activity, e)) { |
| 2685 | throw new RuntimeException( |
| 2686 | "Unable to instantiate activity " + component |
| 2687 | + ": " + e.toString(), e); |
| 2688 | } |
| 2689 | } |
| 2690 | |
| 2691 | try { |
Dianne Hackborn | 0be1f78 | 2009-11-09 12:30:12 -0800 | [diff] [blame] | 2692 | Application app = r.packageInfo.makeApplication(false, mInstrumentation); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2693 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2694 | if (localLOGV) Slog.v(TAG, "Performing launch of " + r); |
| 2695 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2696 | TAG, r + ": app=" + app |
| 2697 | + ", appName=" + app.getPackageName() |
| 2698 | + ", pkg=" + r.packageInfo.getPackageName() |
| 2699 | + ", comp=" + r.intent.getComponent().toShortString() |
| 2700 | + ", dir=" + r.packageInfo.getAppDir()); |
| 2701 | |
| 2702 | if (activity != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2703 | CharSequence title = r.activityInfo.loadLabel(appContext.getPackageManager()); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 2704 | Configuration config = new Configuration(mCompatConfiguration); |
Andrii Kulian | d0ad938 | 2016-04-18 20:54:20 -0700 | [diff] [blame] | 2705 | if (r.overrideConfig != null) { |
| 2706 | config.updateFrom(r.overrideConfig); |
| 2707 | } |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2708 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Launching activity " |
Dianne Hackborn | dc6b635 | 2009-09-30 14:20:09 -0700 | [diff] [blame] | 2709 | + r.activityInfo.name + " with config " + config); |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 2710 | Window window = null; |
| 2711 | if (r.mPendingRemoveWindow != null && r.mPreserveWindow) { |
| 2712 | window = r.mPendingRemoveWindow; |
| 2713 | r.mPendingRemoveWindow = null; |
| 2714 | r.mPendingRemoveWindowManager = null; |
| 2715 | } |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 2716 | appContext.setOuterContext(activity); |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 2717 | activity.attach(appContext, this, getInstrumentation(), r.token, |
| 2718 | r.ident, app, r.intent, r.activityInfo, title, r.parent, |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 2719 | r.embeddedID, r.lastNonConfigurationInstances, config, |
Andrii Kulian | 51c1b67 | 2017-04-07 18:39:32 -0700 | [diff] [blame] | 2720 | r.referrer, r.voiceInteractor, window, r.configCallback); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2721 | |
Christopher Tate | b70f3df | 2009-04-07 16:07:59 -0700 | [diff] [blame] | 2722 | if (customIntent != null) { |
| 2723 | activity.mIntent = customIntent; |
| 2724 | } |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 2725 | r.lastNonConfigurationInstances = null; |
Sudheer Shanka | 84a4895 | 2017-03-08 18:19:01 -0800 | [diff] [blame] | 2726 | checkAndBlockForNetworkAccess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2727 | activity.mStartedActivity = false; |
| 2728 | int theme = r.activityInfo.getThemeResource(); |
| 2729 | if (theme != 0) { |
| 2730 | activity.setTheme(theme); |
| 2731 | } |
| 2732 | |
| 2733 | activity.mCalled = false; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2734 | if (r.isPersistable()) { |
| 2735 | mInstrumentation.callActivityOnCreate(activity, r.state, r.persistentState); |
| 2736 | } else { |
| 2737 | mInstrumentation.callActivityOnCreate(activity, r.state); |
| 2738 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2739 | if (!activity.mCalled) { |
| 2740 | throw new SuperNotCalledException( |
| 2741 | "Activity " + r.intent.getComponent().toShortString() + |
| 2742 | " did not call through to super.onCreate()"); |
| 2743 | } |
| 2744 | r.activity = activity; |
| 2745 | r.stopped = true; |
| 2746 | if (!r.activity.mFinished) { |
| 2747 | activity.performStart(); |
| 2748 | r.stopped = false; |
| 2749 | } |
| 2750 | if (!r.activity.mFinished) { |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2751 | if (r.isPersistable()) { |
| 2752 | if (r.state != null || r.persistentState != null) { |
| 2753 | mInstrumentation.callActivityOnRestoreInstanceState(activity, r.state, |
| 2754 | r.persistentState); |
| 2755 | } |
| 2756 | } else if (r.state != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2757 | mInstrumentation.callActivityOnRestoreInstanceState(activity, r.state); |
| 2758 | } |
| 2759 | } |
| 2760 | if (!r.activity.mFinished) { |
| 2761 | activity.mCalled = false; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2762 | if (r.isPersistable()) { |
| 2763 | mInstrumentation.callActivityOnPostCreate(activity, r.state, |
| 2764 | r.persistentState); |
| 2765 | } else { |
| 2766 | mInstrumentation.callActivityOnPostCreate(activity, r.state); |
| 2767 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2768 | if (!activity.mCalled) { |
| 2769 | throw new SuperNotCalledException( |
| 2770 | "Activity " + r.intent.getComponent().toShortString() + |
| 2771 | " did not call through to super.onPostCreate()"); |
| 2772 | } |
| 2773 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2774 | } |
| 2775 | r.paused = true; |
| 2776 | |
| 2777 | mActivities.put(r.token, r); |
| 2778 | |
| 2779 | } catch (SuperNotCalledException e) { |
| 2780 | throw e; |
| 2781 | |
| 2782 | } catch (Exception e) { |
| 2783 | if (!mInstrumentation.onException(activity, e)) { |
| 2784 | throw new RuntimeException( |
| 2785 | "Unable to start activity " + component |
| 2786 | + ": " + e.toString(), e); |
| 2787 | } |
| 2788 | } |
| 2789 | |
| 2790 | return activity; |
| 2791 | } |
| 2792 | |
Sudheer Shanka | 84a4895 | 2017-03-08 18:19:01 -0800 | [diff] [blame] | 2793 | /** |
| 2794 | * Checks if {@link #mNetworkBlockSeq} is {@link #INVALID_PROC_STATE_SEQ} and if so, returns |
| 2795 | * immediately. Otherwise, makes a blocking call to ActivityManagerService to wait for the |
| 2796 | * network rules to get updated. |
| 2797 | */ |
| 2798 | private void checkAndBlockForNetworkAccess() { |
| 2799 | synchronized (mNetworkPolicyLock) { |
| 2800 | if (mNetworkBlockSeq != INVALID_PROC_STATE_SEQ) { |
| 2801 | try { |
| 2802 | ActivityManager.getService().waitForNetworkStateUpdate(mNetworkBlockSeq); |
| 2803 | mNetworkBlockSeq = INVALID_PROC_STATE_SEQ; |
| 2804 | } catch (RemoteException ignored) {} |
| 2805 | } |
| 2806 | } |
| 2807 | } |
| 2808 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 2809 | private ContextImpl createBaseContextForActivity(ActivityClientRecord r) { |
| 2810 | final int displayId; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2811 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 2812 | displayId = ActivityManager.getService().getActivityDisplayId(r.token); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2813 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2814 | throw e.rethrowFromSystemServer(); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2815 | } |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 2816 | |
Wale Ogunwale | 7c72668 | 2015-02-06 17:34:28 -0800 | [diff] [blame] | 2817 | ContextImpl appContext = ContextImpl.createActivityContext( |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 2818 | this, r.packageInfo, r.activityInfo, r.token, displayId, r.overrideConfig); |
Wale Ogunwale | 7c72668 | 2015-02-06 17:34:28 -0800 | [diff] [blame] | 2819 | |
| 2820 | final DisplayManagerGlobal dm = DisplayManagerGlobal.getInstance(); |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 2821 | // For debugging purposes, if the activity's package name contains the value of |
| 2822 | // the "debug.use-second-display" system property as a substring, then show |
| 2823 | // its content on a secondary display if there is one. |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 2824 | String pkgName = SystemProperties.get("debug.second-display.pkg"); |
| 2825 | if (pkgName != null && !pkgName.isEmpty() |
| 2826 | && r.packageInfo.mPackageName.contains(pkgName)) { |
Wale Ogunwale | 7c72668 | 2015-02-06 17:34:28 -0800 | [diff] [blame] | 2827 | for (int id : dm.getDisplayIds()) { |
| 2828 | if (id != Display.DEFAULT_DISPLAY) { |
Wale Ogunwale | 2669851 | 2015-06-05 16:55:33 -0700 | [diff] [blame] | 2829 | Display display = |
Bryce Lee | 609bf65 | 2017-02-09 16:50:13 -0800 | [diff] [blame] | 2830 | dm.getCompatibleDisplay(id, appContext.getResources()); |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 2831 | appContext = (ContextImpl) appContext.createDisplayContext(display); |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 2832 | break; |
| 2833 | } |
| 2834 | } |
| 2835 | } |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 2836 | return appContext; |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 2837 | } |
| 2838 | |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 2839 | private void handleLaunchActivity(ActivityClientRecord r, Intent customIntent, String reason) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2840 | // If we are getting ready to gc after going to the background, well |
| 2841 | // we are back active so skip it. |
| 2842 | unscheduleGcIdler(); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 2843 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2844 | |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 2845 | if (r.profilerInfo != null) { |
| 2846 | mProfiler.setProfiler(r.profilerInfo); |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 2847 | mProfiler.startProfiling(); |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 2848 | } |
| 2849 | |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 2850 | // Make sure we are running with the most recent config. |
| 2851 | handleConfigurationChanged(null, null); |
| 2852 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2853 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2854 | TAG, "Handling launch of " + r); |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 2855 | |
Chet Haase | 0d1c27a | 2014-11-03 18:35:16 +0000 | [diff] [blame] | 2856 | // Initialize before creating the activity |
Jesse Hall | c37984f | 2017-05-23 16:55:08 -0700 | [diff] [blame] | 2857 | if (!ThreadedRenderer.sRendererDisabled) { |
| 2858 | GraphicsEnvironment.earlyInitEGL(); |
| 2859 | } |
Chet Haase | 0d1c27a | 2014-11-03 18:35:16 +0000 | [diff] [blame] | 2860 | WindowManagerGlobal.initialize(); |
| 2861 | |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 2862 | Activity a = performLaunchActivity(r, customIntent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2863 | |
| 2864 | if (a != null) { |
Dianne Hackborn | 871ecdc | 2009-12-11 15:24:33 -0800 | [diff] [blame] | 2865 | r.createdConfig = new Configuration(mConfiguration); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 2866 | reportSizeConfigurations(r); |
Dianne Hackborn | 9e0f5d9 | 2010-02-22 15:05:42 -0800 | [diff] [blame] | 2867 | Bundle oldState = r.state; |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 2868 | handleResumeActivity(r.token, false, r.isForward, |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 2869 | !r.activity.mFinished && !r.startsNotResumed, r.lastProcessedSeq, reason); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2870 | |
| 2871 | if (!r.activity.mFinished && r.startsNotResumed) { |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 2872 | // The activity manager actually wants this one to start out paused, because it |
| 2873 | // needs to be visible but isn't in the foreground. We accomplish this by going |
| 2874 | // through the normal startup (because activities expect to go through onResume() |
| 2875 | // the first time they run, before their window is displayed), and then pausing it. |
| 2876 | // However, in this case we do -not- need to do the full pause cycle (of freezing |
| 2877 | // and such) because the activity manager assumes it can just retain the current |
| 2878 | // state it has. |
| 2879 | performPauseActivityIfNeeded(r, reason); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2880 | |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 2881 | // We need to keep around the original state, in case we need to be created again. |
| 2882 | // But we only do this for pre-Honeycomb apps, which always save their state when |
| 2883 | // pausing, so we can not have them save their state when restarting from a paused |
| 2884 | // state. For HC and later, we want to (and can) let the state be saved as the |
| 2885 | // normal part of stopping the activity. |
| 2886 | if (r.isPreHoneycomb()) { |
| 2887 | r.state = oldState; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2888 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2889 | } |
| 2890 | } else { |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 2891 | // If there was an error, for any reason, tell the activity manager to stop us. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2892 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 2893 | ActivityManager.getService() |
Wale Ogunwale | ba7881c | 2015-08-01 19:28:29 -0700 | [diff] [blame] | 2894 | .finishActivity(r.token, Activity.RESULT_CANCELED, null, |
| 2895 | Activity.DONT_FINISH_TASK_WITH_ACTIVITY); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2896 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2897 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2898 | } |
| 2899 | } |
| 2900 | } |
| 2901 | |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 2902 | private void reportSizeConfigurations(ActivityClientRecord r) { |
| 2903 | Configuration[] configurations = r.activity.getResources().getSizeConfigurations(); |
| 2904 | if (configurations == null) { |
| 2905 | return; |
| 2906 | } |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 2907 | SparseIntArray horizontal = new SparseIntArray(); |
| 2908 | SparseIntArray vertical = new SparseIntArray(); |
| 2909 | SparseIntArray smallest = new SparseIntArray(); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 2910 | for (int i = configurations.length - 1; i >= 0; i--) { |
| 2911 | Configuration config = configurations[i]; |
| 2912 | if (config.screenHeightDp != Configuration.SCREEN_HEIGHT_DP_UNDEFINED) { |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 2913 | vertical.put(config.screenHeightDp, 0); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 2914 | } |
| 2915 | if (config.screenWidthDp != Configuration.SCREEN_WIDTH_DP_UNDEFINED) { |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 2916 | horizontal.put(config.screenWidthDp, 0); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 2917 | } |
| 2918 | if (config.smallestScreenWidthDp != Configuration.SMALLEST_SCREEN_WIDTH_DP_UNDEFINED) { |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 2919 | smallest.put(config.smallestScreenWidthDp, 0); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 2920 | } |
| 2921 | } |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 2922 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 2923 | ActivityManager.getService().reportSizeConfigurations(r.token, |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 2924 | horizontal.copyKeys(), vertical.copyKeys(), smallest.copyKeys()); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 2925 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2926 | throw ex.rethrowFromSystemServer(); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 2927 | } |
| 2928 | |
| 2929 | } |
| 2930 | |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 2931 | private void deliverNewIntents(ActivityClientRecord r, List<ReferrerIntent> intents) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2932 | final int N = intents.size(); |
| 2933 | for (int i=0; i<N; i++) { |
Dianne Hackborn | a01a0fa | 2014-12-02 10:33:14 -0800 | [diff] [blame] | 2934 | ReferrerIntent intent = intents.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2935 | intent.setExtrasClassLoader(r.activity.getClassLoader()); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 2936 | intent.prepareToEnterProcess(); |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 2937 | r.activity.mFragments.noteStateNotSaved(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2938 | mInstrumentation.callActivityOnNewIntent(r.activity, intent); |
| 2939 | } |
| 2940 | } |
| 2941 | |
Wale Ogunwale | 826c706 | 2016-09-13 08:25:54 -0700 | [diff] [blame] | 2942 | void performNewIntents(IBinder token, List<ReferrerIntent> intents, boolean andPause) { |
| 2943 | final ActivityClientRecord r = mActivities.get(token); |
| 2944 | if (r == null) { |
| 2945 | return; |
| 2946 | } |
| 2947 | |
| 2948 | final boolean resumed = !r.paused; |
| 2949 | if (resumed) { |
| 2950 | r.activity.mTemporaryPause = true; |
| 2951 | mInstrumentation.callActivityOnPause(r.activity); |
| 2952 | } |
Sudheer Shanka | 43b5ea4 | 2017-06-21 11:24:53 -0700 | [diff] [blame] | 2953 | checkAndBlockForNetworkAccess(); |
Wale Ogunwale | 826c706 | 2016-09-13 08:25:54 -0700 | [diff] [blame] | 2954 | deliverNewIntents(r, intents); |
| 2955 | if (resumed) { |
| 2956 | r.activity.performResume(); |
| 2957 | r.activity.mTemporaryPause = false; |
| 2958 | } |
| 2959 | |
| 2960 | if (r.paused && andPause) { |
| 2961 | // In this case the activity was in the paused state when we delivered the intent, |
| 2962 | // to guarantee onResume gets called after onNewIntent we temporarily resume the |
| 2963 | // activity and pause again as the caller wanted. |
| 2964 | performResumeActivity(token, false, "performNewIntents"); |
| 2965 | performPauseActivityIfNeeded(r, "performNewIntents"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2966 | } |
| 2967 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2968 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 2969 | private void handleNewIntent(NewIntentData data) { |
Wale Ogunwale | 826c706 | 2016-09-13 08:25:54 -0700 | [diff] [blame] | 2970 | performNewIntents(data.token, data.intents, data.andPause); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2971 | } |
| 2972 | |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 2973 | public void handleRequestAssistContextExtras(RequestAssistContextExtras cmd) { |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 2974 | // Filling for autofill has a few differences: |
Felipe Leme | 1ca634a | 2016-11-28 17:21:21 -0800 | [diff] [blame] | 2975 | // - it does not need an AssistContent |
| 2976 | // - it does not call onProvideAssistData() |
| 2977 | // - it needs an IAutoFillCallback |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 2978 | boolean forAutofill = cmd.requestType == ActivityManager.ASSIST_CONTEXT_AUTOFILL; |
Felipe Leme | 1ca634a | 2016-11-28 17:21:21 -0800 | [diff] [blame] | 2979 | |
Felipe Leme | 85d1c2d | 2017-04-21 08:56:04 -0700 | [diff] [blame] | 2980 | // TODO: decide if lastSessionId logic applies to autofill sessions |
Amith Yamasani | 4f128e4 | 2016-05-10 11:44:12 -0700 | [diff] [blame] | 2981 | if (mLastSessionId != cmd.sessionId) { |
| 2982 | // Clear the existing structures |
| 2983 | mLastSessionId = cmd.sessionId; |
| 2984 | for (int i = mLastAssistStructures.size() - 1; i >= 0; i--) { |
| 2985 | AssistStructure structure = mLastAssistStructures.get(i).get(); |
| 2986 | if (structure != null) { |
| 2987 | structure.clearSendChannel(); |
| 2988 | } |
| 2989 | mLastAssistStructures.remove(i); |
Dianne Hackborn | 782d498 | 2015-07-08 17:36:37 -0700 | [diff] [blame] | 2990 | } |
| 2991 | } |
Felipe Leme | 29a5b0d | 2016-10-25 14:57:11 -0700 | [diff] [blame] | 2992 | |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 2993 | Bundle data = new Bundle(); |
Dianne Hackborn | 09d57fe | 2015-05-27 18:05:52 -0700 | [diff] [blame] | 2994 | AssistStructure structure = null; |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 2995 | AssistContent content = forAutofill ? null : new AssistContent(); |
Amith Yamasani | 858f98d | 2017-02-22 12:59:53 -0800 | [diff] [blame] | 2996 | final long startTime = SystemClock.uptimeMillis(); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 2997 | ActivityClientRecord r = mActivities.get(cmd.activityToken); |
Dianne Hackborn | a3acdb3 | 2015-06-08 17:07:40 -0700 | [diff] [blame] | 2998 | Uri referrer = null; |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 2999 | if (r != null) { |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 3000 | if (!forAutofill) { |
Felipe Leme | 1ca634a | 2016-11-28 17:21:21 -0800 | [diff] [blame] | 3001 | r.activity.getApplication().dispatchOnProvideAssistData(r.activity, data); |
Felipe Leme | 29a5b0d | 2016-10-25 14:57:11 -0700 | [diff] [blame] | 3002 | r.activity.onProvideAssistData(data); |
Felipe Leme | 6d55387 | 2016-12-08 17:13:25 -0800 | [diff] [blame] | 3003 | referrer = r.activity.onProvideReferrer(); |
Felipe Leme | 29a5b0d | 2016-10-25 14:57:11 -0700 | [diff] [blame] | 3004 | } |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 3005 | if (cmd.requestType == ActivityManager.ASSIST_CONTEXT_FULL || forAutofill) { |
Svet Ganov | fd31f85 | 2017-04-26 15:54:27 -0700 | [diff] [blame] | 3006 | structure = new AssistStructure(r.activity, forAutofill, cmd.flags); |
Adam Skory | 4aaed14 | 2015-04-22 11:29:31 -0600 | [diff] [blame] | 3007 | Intent activityIntent = r.activity.getIntent(); |
Felipe Leme | 6d55387 | 2016-12-08 17:13:25 -0800 | [diff] [blame] | 3008 | boolean notSecure = r.window == null || |
Dianne Hackborn | 09d57fe | 2015-05-27 18:05:52 -0700 | [diff] [blame] | 3009 | (r.window.getAttributes().flags |
Felipe Leme | 6d55387 | 2016-12-08 17:13:25 -0800 | [diff] [blame] | 3010 | & WindowManager.LayoutParams.FLAG_SECURE) == 0; |
| 3011 | if (activityIntent != null && notSecure) { |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 3012 | if (!forAutofill) { |
Felipe Leme | 1ca634a | 2016-11-28 17:21:21 -0800 | [diff] [blame] | 3013 | Intent intent = new Intent(activityIntent); |
| 3014 | intent.setFlags(intent.getFlags() & ~(Intent.FLAG_GRANT_WRITE_URI_PERMISSION |
| 3015 | | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION)); |
| 3016 | intent.removeUnsafeExtras(); |
Felipe Leme | 29a5b0d | 2016-10-25 14:57:11 -0700 | [diff] [blame] | 3017 | content.setDefaultIntent(intent); |
| 3018 | } |
Adam Skory | 4aaed14 | 2015-04-22 11:29:31 -0600 | [diff] [blame] | 3019 | } else { |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 3020 | if (!forAutofill) { |
Felipe Leme | 29a5b0d | 2016-10-25 14:57:11 -0700 | [diff] [blame] | 3021 | content.setDefaultIntent(new Intent()); |
| 3022 | } |
Adam Skory | 4aaed14 | 2015-04-22 11:29:31 -0600 | [diff] [blame] | 3023 | } |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 3024 | if (!forAutofill) { |
Felipe Leme | 29a5b0d | 2016-10-25 14:57:11 -0700 | [diff] [blame] | 3025 | r.activity.onProvideAssistContent(content); |
| 3026 | } |
Dianne Hackborn | a83ce1d | 2015-03-11 15:16:13 -0700 | [diff] [blame] | 3027 | } |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 3028 | } |
Dianne Hackborn | 09d57fe | 2015-05-27 18:05:52 -0700 | [diff] [blame] | 3029 | if (structure == null) { |
| 3030 | structure = new AssistStructure(); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 3031 | } |
Felipe Leme | 0200d9e | 2017-01-24 15:10:26 -0800 | [diff] [blame] | 3032 | |
Felipe Leme | 85d1c2d | 2017-04-21 08:56:04 -0700 | [diff] [blame] | 3033 | // TODO: decide if lastSessionId logic applies to autofill sessions |
Amith Yamasani | 858f98d | 2017-02-22 12:59:53 -0800 | [diff] [blame] | 3034 | |
| 3035 | structure.setAcquisitionStartTime(startTime); |
| 3036 | structure.setAcquisitionEndTime(SystemClock.uptimeMillis()); |
| 3037 | |
Amith Yamasani | 4f128e4 | 2016-05-10 11:44:12 -0700 | [diff] [blame] | 3038 | mLastAssistStructures.add(new WeakReference<>(structure)); |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3039 | IActivityManager mgr = ActivityManager.getService(); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 3040 | try { |
Dianne Hackborn | a3acdb3 | 2015-06-08 17:07:40 -0700 | [diff] [blame] | 3041 | mgr.reportAssistContextExtras(cmd.requestToken, data, structure, content, referrer); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 3042 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3043 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 3044 | } |
| 3045 | } |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 3046 | |
| 3047 | public void handleTranslucentConversionComplete(IBinder token, boolean drawComplete) { |
| 3048 | ActivityClientRecord r = mActivities.get(token); |
| 3049 | if (r != null) { |
| 3050 | r.activity.onTranslucentConversionComplete(drawComplete); |
| 3051 | } |
| 3052 | } |
| 3053 | |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 3054 | public void onNewActivityOptions(IBinder token, ActivityOptions options) { |
| 3055 | ActivityClientRecord r = mActivities.get(token); |
| 3056 | if (r != null) { |
| 3057 | r.activity.onNewActivityOptions(options); |
| 3058 | } |
| 3059 | } |
| 3060 | |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 3061 | public void handleInstallProvider(ProviderInfo info) { |
Jeff Sharkey | bb2e2ca | 2014-10-23 11:42:31 -0700 | [diff] [blame] | 3062 | final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); |
| 3063 | try { |
Jeff Sharkey | a6bfeae | 2017-07-05 16:50:24 -0600 | [diff] [blame] | 3064 | installContentProviders(mInitialApplication, Arrays.asList(info)); |
Jeff Sharkey | bb2e2ca | 2014-10-23 11:42:31 -0700 | [diff] [blame] | 3065 | } finally { |
| 3066 | StrictMode.setThreadPolicy(oldPolicy); |
| 3067 | } |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 3068 | } |
| 3069 | |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 3070 | private void handleEnterAnimationComplete(IBinder token) { |
| 3071 | ActivityClientRecord r = mActivities.get(token); |
| 3072 | if (r != null) { |
Filip Gruszczynski | 6eafa90 | 2014-11-14 14:24:37 -0800 | [diff] [blame] | 3073 | r.activity.dispatchEnterAnimationComplete(); |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 3074 | } |
| 3075 | } |
| 3076 | |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 3077 | private void handleStartBinderTracking() { |
| 3078 | Binder.enableTracing(); |
| 3079 | } |
| 3080 | |
| 3081 | private void handleStopBinderTrackingAndDump(ParcelFileDescriptor fd) { |
| 3082 | try { |
| 3083 | Binder.disableTracing(); |
| 3084 | Binder.getTransactionTracker().writeTracesToFile(fd); |
| 3085 | } finally { |
| 3086 | IoUtils.closeQuietly(fd); |
| 3087 | Binder.getTransactionTracker().clearTraces(); |
| 3088 | } |
| 3089 | } |
| 3090 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 3091 | private void handleMultiWindowModeChanged(IBinder token, boolean isInMultiWindowMode, |
| 3092 | Configuration overrideConfig) { |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 3093 | final ActivityClientRecord r = mActivities.get(token); |
| 3094 | if (r != null) { |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 3095 | final Configuration newConfig = new Configuration(mConfiguration); |
| 3096 | if (overrideConfig != null) { |
| 3097 | newConfig.updateFrom(overrideConfig); |
| 3098 | } |
| 3099 | r.activity.dispatchMultiWindowModeChanged(isInMultiWindowMode, newConfig); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 3100 | } |
| 3101 | } |
| 3102 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 3103 | private void handlePictureInPictureModeChanged(IBinder token, boolean isInPipMode, |
| 3104 | Configuration overrideConfig) { |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 3105 | final ActivityClientRecord r = mActivities.get(token); |
| 3106 | if (r != null) { |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 3107 | final Configuration newConfig = new Configuration(mConfiguration); |
| 3108 | if (overrideConfig != null) { |
| 3109 | newConfig.updateFrom(overrideConfig); |
| 3110 | } |
| 3111 | r.activity.dispatchPictureInPictureModeChanged(isInPipMode, newConfig); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 3112 | } |
| 3113 | } |
| 3114 | |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 3115 | private void handleLocalVoiceInteractionStarted(IBinder token, IVoiceInteractor interactor) { |
| 3116 | final ActivityClientRecord r = mActivities.get(token); |
| 3117 | if (r != null) { |
| 3118 | r.voiceInteractor = interactor; |
| 3119 | r.activity.setVoiceInteractor(interactor); |
| 3120 | if (interactor == null) { |
| 3121 | r.activity.onLocalVoiceInteractionStopped(); |
| 3122 | } else { |
| 3123 | r.activity.onLocalVoiceInteractionStarted(); |
| 3124 | } |
| 3125 | } |
| 3126 | } |
| 3127 | |
Leonard Mosescu | f3409ce | 2016-10-06 17:32:05 -0700 | [diff] [blame] | 3128 | static final void handleAttachAgent(String agent) { |
| 3129 | try { |
| 3130 | VMDebug.attachAgent(agent); |
| 3131 | } catch (IOException e) { |
| 3132 | Slog.e(TAG, "Attaching agent failed: " + agent); |
| 3133 | } |
| 3134 | } |
| 3135 | |
Brad Fitzpatrick | bfb1919 | 2010-10-29 15:25:44 -0700 | [diff] [blame] | 3136 | private static final ThreadLocal<Intent> sCurrentBroadcastIntent = new ThreadLocal<Intent>(); |
| 3137 | |
| 3138 | /** |
| 3139 | * Return the Intent that's currently being handled by a |
| 3140 | * BroadcastReceiver on this thread, or null if none. |
| 3141 | * @hide |
| 3142 | */ |
| 3143 | public static Intent getIntentBeingBroadcast() { |
| 3144 | return sCurrentBroadcastIntent.get(); |
| 3145 | } |
| 3146 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3147 | private void handleReceiver(ReceiverData data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3148 | // If we are getting ready to gc after going to the background, well |
| 3149 | // we are back active so skip it. |
| 3150 | unscheduleGcIdler(); |
| 3151 | |
| 3152 | String component = data.intent.getComponent().getClassName(); |
| 3153 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3154 | LoadedApk packageInfo = getPackageInfoNoCheck( |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 3155 | data.info.applicationInfo, data.compatInfo); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3156 | |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3157 | IActivityManager mgr = ActivityManager.getService(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3158 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 3159 | Application app; |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3160 | BroadcastReceiver receiver; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 3161 | ContextImpl context; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3162 | try { |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 3163 | app = packageInfo.makeApplication(false, mInstrumentation); |
| 3164 | context = (ContextImpl) app.getBaseContext(); |
| 3165 | if (data.info.splitName != null) { |
| 3166 | context = (ContextImpl) context.createContextForSplit(data.info.splitName); |
| 3167 | } |
| 3168 | java.lang.ClassLoader cl = context.getClassLoader(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3169 | data.intent.setExtrasClassLoader(cl); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 3170 | data.intent.prepareToEnterProcess(); |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 3171 | data.setExtrasClassLoader(cl); |
Jason Monk | 6945710 | 2017-06-06 18:01:31 -0400 | [diff] [blame] | 3172 | receiver = instantiate(cl, component, data.intent, app, |
| 3173 | Application::instantiateReceiver); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3174 | } catch (Exception e) { |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 3175 | if (DEBUG_BROADCAST) Slog.i(TAG, |
| 3176 | "Finishing failed broadcast to " + data.intent.getComponent()); |
| 3177 | data.sendFinished(mgr); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3178 | throw new RuntimeException( |
| 3179 | "Unable to instantiate receiver " + component |
| 3180 | + ": " + e.toString(), e); |
| 3181 | } |
| 3182 | |
| 3183 | try { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3184 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3185 | TAG, "Performing receive of " + data.intent |
| 3186 | + ": app=" + app |
| 3187 | + ", appName=" + app.getPackageName() |
| 3188 | + ", pkg=" + packageInfo.getPackageName() |
| 3189 | + ", comp=" + data.intent.getComponent().toShortString() |
| 3190 | + ", dir=" + packageInfo.getAppDir()); |
| 3191 | |
Brad Fitzpatrick | bfb1919 | 2010-10-29 15:25:44 -0700 | [diff] [blame] | 3192 | sCurrentBroadcastIntent.set(data.intent); |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 3193 | receiver.setPendingResult(data); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3194 | receiver.onReceive(context.getReceiverRestrictedContext(), |
| 3195 | data.intent); |
| 3196 | } catch (Exception e) { |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 3197 | if (DEBUG_BROADCAST) Slog.i(TAG, |
| 3198 | "Finishing failed broadcast to " + data.intent.getComponent()); |
| 3199 | data.sendFinished(mgr); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3200 | if (!mInstrumentation.onException(receiver, e)) { |
| 3201 | throw new RuntimeException( |
| 3202 | "Unable to start receiver " + component |
| 3203 | + ": " + e.toString(), e); |
| 3204 | } |
Brad Fitzpatrick | bfb1919 | 2010-10-29 15:25:44 -0700 | [diff] [blame] | 3205 | } finally { |
| 3206 | sCurrentBroadcastIntent.set(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3207 | } |
| 3208 | |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 3209 | if (receiver.getPendingResult() != null) { |
| 3210 | data.finish(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3211 | } |
| 3212 | } |
| 3213 | |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3214 | // Instantiate a BackupAgent and tell it that it's alive |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3215 | private void handleCreateBackupAgent(CreateBackupAgentData data) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3216 | if (DEBUG_BACKUP) Slog.v(TAG, "handleCreateBackupAgent: " + data); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3217 | |
Christopher Tate | 346acb1 | 2012-10-15 19:20:25 -0700 | [diff] [blame] | 3218 | // Sanity check the requested target package's uid against ours |
| 3219 | try { |
| 3220 | PackageInfo requestedPackage = getPackageManager().getPackageInfo( |
| 3221 | data.appInfo.packageName, 0, UserHandle.myUserId()); |
| 3222 | if (requestedPackage.applicationInfo.uid != Process.myUid()) { |
| 3223 | Slog.w(TAG, "Asked to instantiate non-matching package " |
| 3224 | + data.appInfo.packageName); |
| 3225 | return; |
| 3226 | } |
| 3227 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3228 | throw e.rethrowFromSystemServer(); |
Christopher Tate | 346acb1 | 2012-10-15 19:20:25 -0700 | [diff] [blame] | 3229 | } |
| 3230 | |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3231 | // no longer idle; we have backup work to do |
| 3232 | unscheduleGcIdler(); |
| 3233 | |
| 3234 | // instantiate the BackupAgent class named in the manifest |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 3235 | LoadedApk packageInfo = getPackageInfoNoCheck(data.appInfo, data.compatInfo); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3236 | String packageName = packageInfo.mPackageName; |
Christopher Tate | 346acb1 | 2012-10-15 19:20:25 -0700 | [diff] [blame] | 3237 | if (packageName == null) { |
| 3238 | Slog.d(TAG, "Asked to create backup agent for nonexistent package"); |
| 3239 | return; |
| 3240 | } |
| 3241 | |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3242 | String classname = data.appInfo.backupAgentName; |
Christopher Tate | 79ec80d | 2011-06-24 14:58:49 -0700 | [diff] [blame] | 3243 | // full backup operation but no app-supplied agent? use the default implementation |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 3244 | if (classname == null && (data.backupMode == ApplicationThreadConstants.BACKUP_MODE_FULL |
| 3245 | || data.backupMode == ApplicationThreadConstants.BACKUP_MODE_RESTORE_FULL)) { |
Christopher Tate | 4a627c7 | 2011-04-01 14:43:32 -0700 | [diff] [blame] | 3246 | classname = "android.app.backup.FullBackupAgent"; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3247 | } |
Christopher Tate | 4a627c7 | 2011-04-01 14:43:32 -0700 | [diff] [blame] | 3248 | |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3249 | try { |
Christopher Tate | d1475e0 | 2009-07-09 15:36:17 -0700 | [diff] [blame] | 3250 | IBinder binder = null; |
Christopher Tate | 2e40d11 | 2014-07-15 12:37:38 -0700 | [diff] [blame] | 3251 | BackupAgent agent = mBackupAgents.get(packageName); |
| 3252 | if (agent != null) { |
| 3253 | // reusing the existing instance |
| 3254 | if (DEBUG_BACKUP) { |
| 3255 | Slog.v(TAG, "Reusing existing agent instance"); |
Christopher Tate | d1475e0 | 2009-07-09 15:36:17 -0700 | [diff] [blame] | 3256 | } |
Christopher Tate | 2e40d11 | 2014-07-15 12:37:38 -0700 | [diff] [blame] | 3257 | binder = agent.onBind(); |
| 3258 | } else { |
| 3259 | try { |
| 3260 | if (DEBUG_BACKUP) Slog.v(TAG, "Initializing agent class " + classname); |
Jason Monk | 6945710 | 2017-06-06 18:01:31 -0400 | [diff] [blame] | 3261 | ContextImpl context = ContextImpl.createAppContext(this, packageInfo); |
Christopher Tate | 2e40d11 | 2014-07-15 12:37:38 -0700 | [diff] [blame] | 3262 | |
| 3263 | java.lang.ClassLoader cl = packageInfo.getClassLoader(); |
Jason Monk | 6945710 | 2017-06-06 18:01:31 -0400 | [diff] [blame] | 3264 | agent = instantiate(cl, classname, context, |
| 3265 | Application::instantiateBackupAgent); |
Christopher Tate | 2e40d11 | 2014-07-15 12:37:38 -0700 | [diff] [blame] | 3266 | |
| 3267 | // set up the agent's context |
Christopher Tate | 2e40d11 | 2014-07-15 12:37:38 -0700 | [diff] [blame] | 3268 | context.setOuterContext(agent); |
| 3269 | agent.attach(context); |
| 3270 | |
| 3271 | agent.onCreate(); |
| 3272 | binder = agent.onBind(); |
| 3273 | mBackupAgents.put(packageName, agent); |
| 3274 | } catch (Exception e) { |
| 3275 | // If this is during restore, fail silently; otherwise go |
| 3276 | // ahead and let the user see the crash. |
| 3277 | Slog.e(TAG, "Agent threw during creation: " + e); |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 3278 | if (data.backupMode != ApplicationThreadConstants.BACKUP_MODE_RESTORE |
| 3279 | && data.backupMode != |
| 3280 | ApplicationThreadConstants.BACKUP_MODE_RESTORE_FULL) { |
Christopher Tate | 2e40d11 | 2014-07-15 12:37:38 -0700 | [diff] [blame] | 3281 | throw e; |
| 3282 | } |
| 3283 | // falling through with 'binder' still null |
| 3284 | } |
Christopher Tate | d1475e0 | 2009-07-09 15:36:17 -0700 | [diff] [blame] | 3285 | } |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3286 | |
| 3287 | // tell the OS that we're live now |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3288 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3289 | ActivityManager.getService().backupAgentCreated(packageName, binder); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3290 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3291 | throw e.rethrowFromSystemServer(); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3292 | } |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3293 | } catch (Exception e) { |
| 3294 | throw new RuntimeException("Unable to create BackupAgent " |
Christopher Tate | 4a627c7 | 2011-04-01 14:43:32 -0700 | [diff] [blame] | 3295 | + classname + ": " + e.toString(), e); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3296 | } |
| 3297 | } |
| 3298 | |
| 3299 | // Tear down a BackupAgent |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3300 | private void handleDestroyBackupAgent(CreateBackupAgentData data) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3301 | if (DEBUG_BACKUP) Slog.v(TAG, "handleDestroyBackupAgent: " + data); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3302 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 3303 | LoadedApk packageInfo = getPackageInfoNoCheck(data.appInfo, data.compatInfo); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3304 | String packageName = packageInfo.mPackageName; |
| 3305 | BackupAgent agent = mBackupAgents.get(packageName); |
| 3306 | if (agent != null) { |
| 3307 | try { |
| 3308 | agent.onDestroy(); |
| 3309 | } catch (Exception e) { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 3310 | 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] | 3311 | e.printStackTrace(); |
| 3312 | } |
| 3313 | mBackupAgents.remove(packageName); |
| 3314 | } else { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 3315 | Slog.w(TAG, "Attempt to destroy unknown backup agent " + data); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3316 | } |
| 3317 | } |
| 3318 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3319 | private void handleCreateService(CreateServiceData data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3320 | // If we are getting ready to gc after going to the background, well |
| 3321 | // we are back active so skip it. |
| 3322 | unscheduleGcIdler(); |
| 3323 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3324 | LoadedApk packageInfo = getPackageInfoNoCheck( |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 3325 | data.info.applicationInfo, data.compatInfo); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3326 | Service service = null; |
Jason Monk | 6945710 | 2017-06-06 18:01:31 -0400 | [diff] [blame] | 3327 | Application app = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3328 | try { |
Jason Monk | 6945710 | 2017-06-06 18:01:31 -0400 | [diff] [blame] | 3329 | app = packageInfo.makeApplication(false, mInstrumentation); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3330 | java.lang.ClassLoader cl = packageInfo.getClassLoader(); |
Jason Monk | 6945710 | 2017-06-06 18:01:31 -0400 | [diff] [blame] | 3331 | service = instantiate(cl, data.info.name, data.intent, app, |
| 3332 | Application::instantiateService); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3333 | } catch (Exception e) { |
| 3334 | if (!mInstrumentation.onException(service, e)) { |
| 3335 | throw new RuntimeException( |
| 3336 | "Unable to instantiate service " + data.info.name |
| 3337 | + ": " + e.toString(), e); |
| 3338 | } |
| 3339 | } |
| 3340 | |
| 3341 | try { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3342 | 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] | 3343 | |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 3344 | ContextImpl context = ContextImpl.createAppContext(this, packageInfo); |
| 3345 | context.setOuterContext(service); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3346 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3347 | service.attach(context, this, data.info.name, data.token, app, |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3348 | ActivityManager.getService()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3349 | service.onCreate(); |
| 3350 | mServices.put(data.token, service); |
| 3351 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3352 | ActivityManager.getService().serviceDoneExecuting( |
Dianne Hackborn | 455625e | 2015-01-21 09:55:13 -0800 | [diff] [blame] | 3353 | data.token, SERVICE_DONE_EXECUTING_ANON, 0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3354 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3355 | throw e.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3356 | } |
| 3357 | } catch (Exception e) { |
| 3358 | if (!mInstrumentation.onException(service, e)) { |
| 3359 | throw new RuntimeException( |
| 3360 | "Unable to create service " + data.info.name |
| 3361 | + ": " + e.toString(), e); |
| 3362 | } |
| 3363 | } |
| 3364 | } |
| 3365 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3366 | private void handleBindService(BindServiceData data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3367 | Service s = mServices.get(data.token); |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 3368 | if (DEBUG_SERVICE) |
| 3369 | Slog.v(TAG, "handleBindService s=" + s + " rebind=" + data.rebind); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3370 | if (s != null) { |
| 3371 | try { |
| 3372 | data.intent.setExtrasClassLoader(s.getClassLoader()); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 3373 | data.intent.prepareToEnterProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3374 | try { |
| 3375 | if (!data.rebind) { |
| 3376 | IBinder binder = s.onBind(data.intent); |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3377 | ActivityManager.getService().publishService( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3378 | data.token, data.intent, binder); |
| 3379 | } else { |
| 3380 | s.onRebind(data.intent); |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3381 | ActivityManager.getService().serviceDoneExecuting( |
Dianne Hackborn | 455625e | 2015-01-21 09:55:13 -0800 | [diff] [blame] | 3382 | data.token, SERVICE_DONE_EXECUTING_ANON, 0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3383 | } |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 3384 | ensureJitEnabled(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3385 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3386 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3387 | } |
| 3388 | } catch (Exception e) { |
| 3389 | if (!mInstrumentation.onException(s, e)) { |
| 3390 | throw new RuntimeException( |
| 3391 | "Unable to bind to service " + s |
| 3392 | + " with " + data.intent + ": " + e.toString(), e); |
| 3393 | } |
| 3394 | } |
| 3395 | } |
| 3396 | } |
| 3397 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3398 | private void handleUnbindService(BindServiceData data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3399 | Service s = mServices.get(data.token); |
| 3400 | if (s != null) { |
| 3401 | try { |
| 3402 | data.intent.setExtrasClassLoader(s.getClassLoader()); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 3403 | data.intent.prepareToEnterProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3404 | boolean doRebind = s.onUnbind(data.intent); |
| 3405 | try { |
| 3406 | if (doRebind) { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3407 | ActivityManager.getService().unbindFinished( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3408 | data.token, data.intent, doRebind); |
| 3409 | } else { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3410 | ActivityManager.getService().serviceDoneExecuting( |
Dianne Hackborn | 455625e | 2015-01-21 09:55:13 -0800 | [diff] [blame] | 3411 | data.token, SERVICE_DONE_EXECUTING_ANON, 0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3412 | } |
| 3413 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3414 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3415 | } |
| 3416 | } catch (Exception e) { |
| 3417 | if (!mInstrumentation.onException(s, e)) { |
| 3418 | throw new RuntimeException( |
| 3419 | "Unable to unbind to service " + s |
| 3420 | + " with " + data.intent + ": " + e.toString(), e); |
| 3421 | } |
| 3422 | } |
| 3423 | } |
| 3424 | } |
| 3425 | |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 3426 | private void handleDumpService(DumpComponentInfo info) { |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3427 | final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); |
| 3428 | try { |
| 3429 | Service s = mServices.get(info.token); |
| 3430 | if (s != null) { |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 3431 | PrintWriter pw = new FastPrintWriter(new FileOutputStream( |
| 3432 | info.fd.getFileDescriptor())); |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3433 | s.dump(info.fd.getFileDescriptor(), pw, info.args); |
| 3434 | pw.flush(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3435 | } |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3436 | } finally { |
| 3437 | IoUtils.closeQuietly(info.fd); |
| 3438 | StrictMode.setThreadPolicy(oldPolicy); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3439 | } |
| 3440 | } |
| 3441 | |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 3442 | private void handleDumpActivity(DumpComponentInfo info) { |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3443 | final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); |
| 3444 | try { |
| 3445 | ActivityClientRecord r = mActivities.get(info.token); |
| 3446 | if (r != null && r.activity != null) { |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 3447 | PrintWriter pw = new FastPrintWriter(new FileOutputStream( |
| 3448 | info.fd.getFileDescriptor())); |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3449 | r.activity.dump(info.prefix, info.fd.getFileDescriptor(), pw, info.args); |
| 3450 | pw.flush(); |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 3451 | } |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3452 | } finally { |
| 3453 | IoUtils.closeQuietly(info.fd); |
| 3454 | StrictMode.setThreadPolicy(oldPolicy); |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 3455 | } |
| 3456 | } |
| 3457 | |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 3458 | private void handleDumpProvider(DumpComponentInfo info) { |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3459 | final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); |
| 3460 | try { |
| 3461 | ProviderClientRecord r = mLocalProviders.get(info.token); |
| 3462 | if (r != null && r.mLocalProvider != null) { |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 3463 | PrintWriter pw = new FastPrintWriter(new FileOutputStream( |
| 3464 | info.fd.getFileDescriptor())); |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3465 | r.mLocalProvider.dump(info.fd.getFileDescriptor(), pw, info.args); |
| 3466 | pw.flush(); |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 3467 | } |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3468 | } finally { |
| 3469 | IoUtils.closeQuietly(info.fd); |
| 3470 | StrictMode.setThreadPolicy(oldPolicy); |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 3471 | } |
| 3472 | } |
| 3473 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3474 | private void handleServiceArgs(ServiceArgsData data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3475 | Service s = mServices.get(data.token); |
| 3476 | if (s != null) { |
| 3477 | try { |
| 3478 | if (data.args != null) { |
| 3479 | data.args.setExtrasClassLoader(s.getClassLoader()); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 3480 | data.args.prepareToEnterProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3481 | } |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 3482 | int res; |
| 3483 | if (!data.taskRemoved) { |
| 3484 | res = s.onStartCommand(data.args, data.flags, data.startId); |
| 3485 | } else { |
| 3486 | s.onTaskRemoved(data.args); |
| 3487 | res = Service.START_TASK_REMOVED_COMPLETE; |
| 3488 | } |
Brad Fitzpatrick | 333b8cb | 2010-08-26 12:04:57 -0700 | [diff] [blame] | 3489 | |
| 3490 | QueuedWork.waitToFinish(); |
| 3491 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3492 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3493 | ActivityManager.getService().serviceDoneExecuting( |
Dianne Hackborn | 455625e | 2015-01-21 09:55:13 -0800 | [diff] [blame] | 3494 | data.token, SERVICE_DONE_EXECUTING_START, data.startId, res); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3495 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3496 | throw e.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3497 | } |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 3498 | ensureJitEnabled(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3499 | } catch (Exception e) { |
| 3500 | if (!mInstrumentation.onException(s, e)) { |
| 3501 | throw new RuntimeException( |
| 3502 | "Unable to start service " + s |
| 3503 | + " with " + data.args + ": " + e.toString(), e); |
| 3504 | } |
| 3505 | } |
| 3506 | } |
| 3507 | } |
| 3508 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3509 | private void handleStopService(IBinder token) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3510 | Service s = mServices.remove(token); |
| 3511 | if (s != null) { |
| 3512 | try { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3513 | if (localLOGV) Slog.v(TAG, "Destroying service " + s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3514 | s.onDestroy(); |
Amith Yamasani | 7592825 | 2017-05-22 15:10:47 -0700 | [diff] [blame] | 3515 | s.detachAndCleanUp(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3516 | Context context = s.getBaseContext(); |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 3517 | if (context instanceof ContextImpl) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3518 | final String who = s.getClassName(); |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 3519 | ((ContextImpl) context).scheduleFinalCleanup(who, "Service"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3520 | } |
Brad Fitzpatrick | 333b8cb | 2010-08-26 12:04:57 -0700 | [diff] [blame] | 3521 | |
| 3522 | QueuedWork.waitToFinish(); |
| 3523 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3524 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3525 | ActivityManager.getService().serviceDoneExecuting( |
Dianne Hackborn | 455625e | 2015-01-21 09:55:13 -0800 | [diff] [blame] | 3526 | token, SERVICE_DONE_EXECUTING_STOP, 0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3527 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3528 | throw e.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3529 | } |
| 3530 | } catch (Exception e) { |
| 3531 | if (!mInstrumentation.onException(s, e)) { |
| 3532 | throw new RuntimeException( |
| 3533 | "Unable to stop service " + s |
| 3534 | + ": " + e.toString(), e); |
| 3535 | } |
Craig Mautner | 66c4a82 | 2015-01-16 12:48:16 -0800 | [diff] [blame] | 3536 | Slog.i(TAG, "handleStopService: exception for " + token, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3537 | } |
Craig Mautner | 9776ad4 | 2015-01-15 14:38:39 -0800 | [diff] [blame] | 3538 | } else { |
| 3539 | Slog.i(TAG, "handleStopService: token=" + token + " not found."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3540 | } |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3541 | //Slog.i(TAG, "Running services: " + mServices); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3542 | } |
| 3543 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3544 | public final ActivityClientRecord performResumeActivity(IBinder token, |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 3545 | boolean clearHide, String reason) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3546 | ActivityClientRecord r = mActivities.get(token); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3547 | if (localLOGV) Slog.v(TAG, "Performing resume of " + r |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3548 | + " finished=" + r.activity.mFinished); |
| 3549 | if (r != null && !r.activity.mFinished) { |
| 3550 | if (clearHide) { |
| 3551 | r.hideForNow = false; |
| 3552 | r.activity.mStartedActivity = false; |
| 3553 | } |
| 3554 | try { |
Dianne Hackborn | 6bdd3a1 | 2015-08-05 15:01:28 -0700 | [diff] [blame] | 3555 | r.activity.onStateNotSaved(); |
Dianne Hackborn | 689586d | 2012-10-01 18:23:04 -0700 | [diff] [blame] | 3556 | r.activity.mFragments.noteStateNotSaved(); |
Sudheer Shanka | 43b5ea4 | 2017-06-21 11:24:53 -0700 | [diff] [blame] | 3557 | checkAndBlockForNetworkAccess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3558 | if (r.pendingIntents != null) { |
| 3559 | deliverNewIntents(r, r.pendingIntents); |
| 3560 | r.pendingIntents = null; |
| 3561 | } |
| 3562 | if (r.pendingResults != null) { |
| 3563 | deliverResults(r, r.pendingResults); |
| 3564 | r.pendingResults = null; |
| 3565 | } |
| 3566 | r.activity.performResume(); |
| 3567 | |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 3568 | synchronized (mResourcesManager) { |
| 3569 | // If there is a pending local relaunch that was requested when the activity was |
| 3570 | // paused, it will put the activity into paused state when it finally happens. |
| 3571 | // Since the activity resumed before being relaunched, we don't want that to |
| 3572 | // happen, so we need to clear the request to relaunch paused. |
| 3573 | for (int i = mRelaunchingActivities.size() - 1; i >= 0; i--) { |
| 3574 | final ActivityClientRecord relaunching = mRelaunchingActivities.get(i); |
| 3575 | if (relaunching.token == r.token |
| 3576 | && relaunching.onlyLocalRequest && relaunching.startsNotResumed) { |
| 3577 | relaunching.startsNotResumed = false; |
| 3578 | } |
Filip Gruszczynski | c3b6179 | 2016-01-22 16:43:48 -0800 | [diff] [blame] | 3579 | } |
| 3580 | } |
| 3581 | |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 3582 | EventLog.writeEvent(LOG_AM_ON_RESUME_CALLED, UserHandle.myUserId(), |
| 3583 | r.activity.getComponentName().getClassName(), reason); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3584 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3585 | r.paused = false; |
| 3586 | r.stopped = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3587 | r.state = null; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3588 | r.persistentState = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3589 | } catch (Exception e) { |
| 3590 | if (!mInstrumentation.onException(r.activity, e)) { |
| 3591 | throw new RuntimeException( |
| 3592 | "Unable to resume activity " |
| 3593 | + r.intent.getComponent().toShortString() |
| 3594 | + ": " + e.toString(), e); |
| 3595 | } |
| 3596 | } |
| 3597 | } |
| 3598 | return r; |
| 3599 | } |
| 3600 | |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 3601 | static final void cleanUpPendingRemoveWindows(ActivityClientRecord r, boolean force) { |
| 3602 | if (r.mPreserveWindow && !force) { |
| 3603 | return; |
| 3604 | } |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 3605 | if (r.mPendingRemoveWindow != null) { |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 3606 | r.mPendingRemoveWindowManager.removeViewImmediate( |
| 3607 | r.mPendingRemoveWindow.getDecorView()); |
| 3608 | IBinder wtoken = r.mPendingRemoveWindow.getDecorView().getWindowToken(); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 3609 | if (wtoken != null) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 3610 | WindowManagerGlobal.getInstance().closeAll(wtoken, |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 3611 | r.activity.getClass().getName(), "Activity"); |
| 3612 | } |
| 3613 | } |
| 3614 | r.mPendingRemoveWindow = null; |
| 3615 | r.mPendingRemoveWindowManager = null; |
| 3616 | } |
| 3617 | |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 3618 | final void handleResumeActivity(IBinder token, |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 3619 | boolean clearHide, boolean isForward, boolean reallyResume, int seq, String reason) { |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 3620 | ActivityClientRecord r = mActivities.get(token); |
| 3621 | if (!checkAndUpdateLifecycleSeq(seq, r, "resumeActivity")) { |
| 3622 | return; |
| 3623 | } |
| 3624 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3625 | // If we are getting ready to gc after going to the background, well |
| 3626 | // we are back active so skip it. |
| 3627 | unscheduleGcIdler(); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3628 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3629 | |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 3630 | // TODO Push resumeArgs into the activity for consideration |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 3631 | r = performResumeActivity(token, clearHide, reason); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3632 | |
| 3633 | if (r != null) { |
| 3634 | final Activity a = r.activity; |
| 3635 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3636 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3637 | TAG, "Resume " + r + " started activity: " + |
| 3638 | a.mStartedActivity + ", hideForNow: " + r.hideForNow |
| 3639 | + ", finished: " + a.mFinished); |
| 3640 | |
| 3641 | final int forwardBit = isForward ? |
| 3642 | WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION : 0; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3643 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3644 | // If the window hasn't yet been added to the window manager, |
| 3645 | // and this guy didn't finish itself or start another activity, |
| 3646 | // then go ahead and add the window. |
Dianne Hackborn | 061d58a | 2010-03-12 15:07:06 -0800 | [diff] [blame] | 3647 | boolean willBeVisible = !a.mStartedActivity; |
| 3648 | if (!willBeVisible) { |
| 3649 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3650 | willBeVisible = ActivityManager.getService().willActivityBeVisible( |
Dianne Hackborn | 061d58a | 2010-03-12 15:07:06 -0800 | [diff] [blame] | 3651 | a.getActivityToken()); |
| 3652 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3653 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 061d58a | 2010-03-12 15:07:06 -0800 | [diff] [blame] | 3654 | } |
| 3655 | } |
| 3656 | if (r.window == null && !a.mFinished && willBeVisible) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3657 | r.window = r.activity.getWindow(); |
| 3658 | View decor = r.window.getDecorView(); |
| 3659 | decor.setVisibility(View.INVISIBLE); |
| 3660 | ViewManager wm = a.getWindowManager(); |
| 3661 | WindowManager.LayoutParams l = r.window.getAttributes(); |
| 3662 | a.mDecor = decor; |
| 3663 | l.type = WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
| 3664 | l.softInputMode |= forwardBit; |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 3665 | if (r.mPreserveWindow) { |
| 3666 | a.mWindowAdded = true; |
| 3667 | r.mPreserveWindow = false; |
Robert Carr | b259485 | 2016-04-25 16:21:13 -0700 | [diff] [blame] | 3668 | // Normally the ViewRoot sets up callbacks with the Activity |
| 3669 | // in addView->ViewRootImpl#setView. If we are instead reusing |
| 3670 | // the decor view we have to notify the view root that the |
| 3671 | // callbacks may have changed. |
| 3672 | ViewRootImpl impl = decor.getViewRootImpl(); |
Robert Carr | 311ecba | 2016-04-27 12:59:45 -0700 | [diff] [blame] | 3673 | if (impl != null) { |
| 3674 | impl.notifyChildRebuilt(); |
| 3675 | } |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 3676 | } |
Bryce Lee | 4b51b32 | 2017-04-07 10:27:19 -0700 | [diff] [blame] | 3677 | if (a.mVisibleFromClient) { |
| 3678 | if (!a.mWindowAdded) { |
| 3679 | a.mWindowAdded = true; |
| 3680 | wm.addView(decor, l); |
| 3681 | } else { |
| 3682 | // The activity will get a callback for this {@link LayoutParams} change |
| 3683 | // earlier. However, at that time the decor will not be set (this is set |
| 3684 | // in this method), so no action will be taken. This call ensures the |
| 3685 | // callback occurs with the decor set. |
| 3686 | a.onWindowAttributesChanged(l); |
| 3687 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3688 | } |
| 3689 | |
| 3690 | // If the window has already been added, but during resume |
| 3691 | // we started another activity, then don't yet make the |
Dianne Hackborn | 061d58a | 2010-03-12 15:07:06 -0800 | [diff] [blame] | 3692 | // window visible. |
| 3693 | } else if (!willBeVisible) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3694 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3695 | TAG, "Launch " + r + " mStartedActivity set"); |
| 3696 | r.hideForNow = true; |
| 3697 | } |
| 3698 | |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 3699 | // Get rid of anything left hanging around. |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 3700 | cleanUpPendingRemoveWindows(r, false /* force */); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 3701 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3702 | // The window is now visible if it has been added, we are not |
| 3703 | // simply finishing, and we are not starting another activity. |
Dianne Hackborn | 061d58a | 2010-03-12 15:07:06 -0800 | [diff] [blame] | 3704 | if (!r.activity.mFinished && willBeVisible |
Dianne Hackborn | c1e605e | 2009-09-25 17:18:15 -0700 | [diff] [blame] | 3705 | && r.activity.mDecor != null && !r.hideForNow) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3706 | if (r.newConfig != null) { |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 3707 | performConfigurationChangedForActivity(r, r.newConfig); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3708 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Resuming activity " |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 3709 | + r.activityInfo.name + " with newConfig " + r.activity.mCurrentConfig); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3710 | r.newConfig = null; |
| 3711 | } |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3712 | if (localLOGV) Slog.v(TAG, "Resuming " + r + " with isForward=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3713 | + isForward); |
| 3714 | WindowManager.LayoutParams l = r.window.getAttributes(); |
| 3715 | if ((l.softInputMode |
| 3716 | & WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) |
| 3717 | != forwardBit) { |
| 3718 | l.softInputMode = (l.softInputMode |
| 3719 | & (~WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION)) |
| 3720 | | forwardBit; |
Dianne Hackborn | c1e605e | 2009-09-25 17:18:15 -0700 | [diff] [blame] | 3721 | if (r.activity.mVisibleFromClient) { |
| 3722 | ViewManager wm = a.getWindowManager(); |
| 3723 | View decor = r.window.getDecorView(); |
| 3724 | wm.updateViewLayout(decor, l); |
| 3725 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3726 | } |
Bryce Lee | 4b51b32 | 2017-04-07 10:27:19 -0700 | [diff] [blame] | 3727 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3728 | r.activity.mVisibleFromServer = true; |
| 3729 | mNumVisibleActivities++; |
| 3730 | if (r.activity.mVisibleFromClient) { |
| 3731 | r.activity.makeVisible(); |
| 3732 | } |
| 3733 | } |
| 3734 | |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 3735 | if (!r.onlyLocalRequest) { |
| 3736 | r.nextIdle = mNewActivities; |
| 3737 | mNewActivities = r; |
| 3738 | if (localLOGV) Slog.v( |
| 3739 | TAG, "Scheduling idle handler for " + r); |
| 3740 | Looper.myQueue().addIdleHandler(new Idler()); |
| 3741 | } |
| 3742 | r.onlyLocalRequest = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3743 | |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 3744 | // Tell the activity manager we have resumed. |
| 3745 | if (reallyResume) { |
| 3746 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3747 | ActivityManager.getService().activityResumed(token); |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 3748 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3749 | throw ex.rethrowFromSystemServer(); |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 3750 | } |
| 3751 | } |
| 3752 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3753 | } else { |
| 3754 | // If an exception was thrown when trying to resume, then |
| 3755 | // just end this activity. |
| 3756 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3757 | ActivityManager.getService() |
Wale Ogunwale | ba7881c | 2015-08-01 19:28:29 -0700 | [diff] [blame] | 3758 | .finishActivity(token, Activity.RESULT_CANCELED, null, |
| 3759 | Activity.DONT_FINISH_TASK_WITH_ACTIVITY); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3760 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3761 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3762 | } |
| 3763 | } |
| 3764 | } |
| 3765 | |
| 3766 | private int mThumbnailWidth = -1; |
| 3767 | private int mThumbnailHeight = -1; |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3768 | private Bitmap mAvailThumbnailBitmap = null; |
| 3769 | private Canvas mThumbnailCanvas = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3770 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3771 | private Bitmap createThumbnailBitmap(ActivityClientRecord r) { |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3772 | Bitmap thumbnail = mAvailThumbnailBitmap; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3773 | try { |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3774 | if (thumbnail == null) { |
| 3775 | int w = mThumbnailWidth; |
| 3776 | int h; |
| 3777 | if (w < 0) { |
| 3778 | Resources res = r.activity.getResources(); |
Winson Chung | 6784f1c | 2014-05-22 11:22:41 -0700 | [diff] [blame] | 3779 | int wId = com.android.internal.R.dimen.thumbnail_width; |
| 3780 | int hId = com.android.internal.R.dimen.thumbnail_height; |
Winson Chung | fd08622 | 2014-05-13 15:49:42 -0700 | [diff] [blame] | 3781 | mThumbnailWidth = w = res.getDimensionPixelSize(wId); |
| 3782 | mThumbnailHeight = h = res.getDimensionPixelSize(hId); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3783 | } else { |
| 3784 | h = mThumbnailHeight; |
| 3785 | } |
| 3786 | |
| 3787 | // On platforms where we don't want thumbnails, set dims to (0,0) |
| 3788 | if ((w > 0) && (h > 0)) { |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 3789 | thumbnail = Bitmap.createBitmap(r.activity.getResources().getDisplayMetrics(), |
| 3790 | w, h, THUMBNAIL_FORMAT); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3791 | thumbnail.eraseColor(0); |
| 3792 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3793 | } |
| 3794 | |
Dianne Hackborn | fb3806d | 2010-12-09 13:14:12 -0800 | [diff] [blame] | 3795 | if (thumbnail != null) { |
| 3796 | Canvas cv = mThumbnailCanvas; |
| 3797 | if (cv == null) { |
| 3798 | mThumbnailCanvas = cv = new Canvas(); |
| 3799 | } |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 3800 | |
Dianne Hackborn | fb3806d | 2010-12-09 13:14:12 -0800 | [diff] [blame] | 3801 | cv.setBitmap(thumbnail); |
| 3802 | if (!r.activity.onCreateThumbnail(thumbnail, cv)) { |
| 3803 | mAvailThumbnailBitmap = thumbnail; |
| 3804 | thumbnail = null; |
| 3805 | } |
Dianne Hackborn | 6311d0a | 2011-08-02 16:37:58 -0700 | [diff] [blame] | 3806 | cv.setBitmap(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3807 | } |
Jim Miller | 0b2a6d0 | 2010-07-13 18:01:29 -0700 | [diff] [blame] | 3808 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3809 | } catch (Exception e) { |
| 3810 | if (!mInstrumentation.onException(r.activity, e)) { |
| 3811 | throw new RuntimeException( |
| 3812 | "Unable to create thumbnail of " |
| 3813 | + r.intent.getComponent().toShortString() |
| 3814 | + ": " + e.toString(), e); |
| 3815 | } |
| 3816 | thumbnail = null; |
| 3817 | } |
| 3818 | |
| 3819 | return thumbnail; |
| 3820 | } |
| 3821 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3822 | private void handlePauseActivity(IBinder token, boolean finished, |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 3823 | boolean userLeaving, int configChanges, boolean dontReport, int seq) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3824 | ActivityClientRecord r = mActivities.get(token); |
Filip Gruszczynski | c3b6179 | 2016-01-22 16:43:48 -0800 | [diff] [blame] | 3825 | if (DEBUG_ORDER) Slog.d(TAG, "handlePauseActivity " + r + ", seq: " + seq); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 3826 | if (!checkAndUpdateLifecycleSeq(seq, r, "pauseActivity")) { |
| 3827 | return; |
| 3828 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3829 | if (r != null) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3830 | //Slog.v(TAG, "userLeaving=" + userLeaving + " handling pause of " + r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3831 | if (userLeaving) { |
| 3832 | performUserLeavingActivity(r); |
| 3833 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3834 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3835 | r.activity.mConfigChangeFlags |= configChanges; |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 3836 | performPauseActivity(token, finished, r.isPreHoneycomb(), "handlePauseActivity"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3837 | |
Dianne Hackborn | aa93bcd | 2010-10-27 13:57:00 -0700 | [diff] [blame] | 3838 | // Make sure any pending writes are now committed. |
Dianne Hackborn | 5d9d03a | 2011-01-24 13:15:09 -0800 | [diff] [blame] | 3839 | if (r.isPreHoneycomb()) { |
| 3840 | QueuedWork.waitToFinish(); |
| 3841 | } |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 3842 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3843 | // Tell the activity manager we have paused. |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 3844 | if (!dontReport) { |
| 3845 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3846 | ActivityManager.getService().activityPaused(token); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 3847 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3848 | throw ex.rethrowFromSystemServer(); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 3849 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3850 | } |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3851 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3852 | } |
| 3853 | } |
| 3854 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3855 | final void performUserLeavingActivity(ActivityClientRecord r) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3856 | mInstrumentation.callActivityOnUserLeaving(r.activity); |
| 3857 | } |
| 3858 | |
| 3859 | final Bundle performPauseActivity(IBinder token, boolean finished, |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 3860 | boolean saveState, String reason) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3861 | ActivityClientRecord r = mActivities.get(token); |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 3862 | return r != null ? performPauseActivity(r, finished, saveState, reason) : null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3863 | } |
| 3864 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3865 | final Bundle performPauseActivity(ActivityClientRecord r, boolean finished, |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 3866 | boolean saveState, String reason) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3867 | if (r.paused) { |
| 3868 | if (r.activity.mFinished) { |
| 3869 | // If we are finishing, we won't call onResume() in certain cases. |
| 3870 | // So here we likewise don't want to call onPause() if the activity |
| 3871 | // isn't resumed. |
| 3872 | return null; |
| 3873 | } |
| 3874 | RuntimeException e = new RuntimeException( |
| 3875 | "Performing pause of activity that is not resumed: " |
| 3876 | + r.intent.getComponent().toShortString()); |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 3877 | Slog.e(TAG, e.getMessage(), e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3878 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3879 | if (finished) { |
| 3880 | r.activity.mFinished = true; |
| 3881 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3882 | |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 3883 | // Next have the activity save its current state and managed dialogs... |
| 3884 | if (!r.activity.mFinished && saveState) { |
| 3885 | callCallActivityOnSaveInstanceState(r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3886 | } |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 3887 | |
| 3888 | performPauseActivityIfNeeded(r, reason); |
Jeff Hamilton | 52d3203 | 2011-01-08 15:31:26 -0600 | [diff] [blame] | 3889 | |
| 3890 | // Notify any outstanding on paused listeners |
| 3891 | ArrayList<OnActivityPausedListener> listeners; |
| 3892 | synchronized (mOnPauseListeners) { |
| 3893 | listeners = mOnPauseListeners.remove(r.activity); |
| 3894 | } |
| 3895 | int size = (listeners != null ? listeners.size() : 0); |
| 3896 | for (int i = 0; i < size; i++) { |
| 3897 | listeners.get(i).onPaused(r.activity); |
| 3898 | } |
| 3899 | |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3900 | return !r.activity.mFinished && saveState ? r.state : null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3901 | } |
| 3902 | |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 3903 | private void performPauseActivityIfNeeded(ActivityClientRecord r, String reason) { |
| 3904 | if (r.paused) { |
| 3905 | // You are already paused silly... |
| 3906 | return; |
| 3907 | } |
| 3908 | |
| 3909 | try { |
| 3910 | r.activity.mCalled = false; |
| 3911 | mInstrumentation.callActivityOnPause(r.activity); |
| 3912 | EventLog.writeEvent(LOG_AM_ON_PAUSE_CALLED, UserHandle.myUserId(), |
| 3913 | r.activity.getComponentName().getClassName(), reason); |
| 3914 | if (!r.activity.mCalled) { |
| 3915 | throw new SuperNotCalledException("Activity " + safeToComponentShortString(r.intent) |
| 3916 | + " did not call through to super.onPause()"); |
| 3917 | } |
| 3918 | } catch (SuperNotCalledException e) { |
| 3919 | throw e; |
| 3920 | } catch (Exception e) { |
| 3921 | if (!mInstrumentation.onException(r.activity, e)) { |
| 3922 | throw new RuntimeException("Unable to pause activity " |
| 3923 | + safeToComponentShortString(r.intent) + ": " + e.toString(), e); |
| 3924 | } |
| 3925 | } |
| 3926 | r.paused = true; |
| 3927 | } |
| 3928 | |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 3929 | final void performStopActivity(IBinder token, boolean saveState, String reason) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3930 | ActivityClientRecord r = mActivities.get(token); |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 3931 | performStopActivityInner(r, null, false, saveState, reason); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3932 | } |
| 3933 | |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 3934 | private static class StopInfo implements Runnable { |
| 3935 | ActivityClientRecord activity; |
| 3936 | Bundle state; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3937 | PersistableBundle persistentState; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3938 | CharSequence description; |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 3939 | |
| 3940 | @Override public void run() { |
| 3941 | // Tell activity manager we have been stopped. |
| 3942 | try { |
| 3943 | if (DEBUG_MEMORY_TRIM) Slog.v(TAG, "Reporting activity stopped: " + activity); |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3944 | ActivityManager.getService().activityStopped( |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3945 | activity.token, state, persistentState, description); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 3946 | } catch (RemoteException ex) { |
Jeff Sharkey | a6bfeae | 2017-07-05 16:50:24 -0600 | [diff] [blame] | 3947 | // Dump statistics about bundle to help developers debug |
| 3948 | final LogWriter writer = new LogWriter(Log.WARN, TAG); |
| 3949 | final IndentingPrintWriter pw = new IndentingPrintWriter(writer, " "); |
| 3950 | pw.println("Bundle stats:"); |
| 3951 | Bundle.dumpStats(pw, state); |
| 3952 | pw.println("PersistableBundle stats:"); |
| 3953 | Bundle.dumpStats(pw, persistentState); |
| 3954 | |
Jeff Sharkey | 369f509 | 2016-02-29 11:16:21 -0700 | [diff] [blame] | 3955 | if (ex instanceof TransactionTooLargeException |
Jeff Sharkey | 9ad8613 | 2016-03-01 11:22:59 -0700 | [diff] [blame] | 3956 | && activity.packageInfo.getTargetSdkVersion() < Build.VERSION_CODES.N) { |
Jeff Sharkey | b8e8a91 | 2016-03-09 16:27:40 -0700 | [diff] [blame] | 3957 | Log.e(TAG, "App sent too much data in instance state, so it was ignored", ex); |
Jeff Sharkey | 369f509 | 2016-02-29 11:16:21 -0700 | [diff] [blame] | 3958 | return; |
| 3959 | } |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3960 | throw ex.rethrowFromSystemServer(); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 3961 | } |
| 3962 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3963 | } |
| 3964 | |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 3965 | private static final class ProviderRefCount { |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 3966 | public final ContentProviderHolder holder; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 3967 | public final ProviderClientRecord client; |
| 3968 | public int stableCount; |
| 3969 | public int unstableCount; |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 3970 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 3971 | // When this is set, the stable and unstable ref counts are 0 and |
| 3972 | // we have a pending operation scheduled to remove the ref count |
| 3973 | // from the activity manager. On the activity manager we are still |
| 3974 | // holding an unstable ref, though it is not reflected in the counts |
| 3975 | // here. |
| 3976 | public boolean removePending; |
| 3977 | |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 3978 | ProviderRefCount(ContentProviderHolder inHolder, |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 3979 | ProviderClientRecord inClient, int sCount, int uCount) { |
| 3980 | holder = inHolder; |
| 3981 | client = inClient; |
| 3982 | stableCount = sCount; |
| 3983 | unstableCount = uCount; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3984 | } |
| 3985 | } |
| 3986 | |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3987 | /** |
| 3988 | * Core implementation of stopping an activity. Note this is a little |
| 3989 | * tricky because the server's meaning of stop is slightly different |
| 3990 | * than our client -- for the server, stop means to save state and give |
| 3991 | * it the result when it is done, but the window may still be visible. |
| 3992 | * For the client, we want to call onStop()/onStart() to indicate when |
Wale Ogunwale | b5066fe | 2016-09-21 07:33:43 -0700 | [diff] [blame] | 3993 | * the activity's UI visibility changes. |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3994 | */ |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3995 | private void performStopActivityInner(ActivityClientRecord r, |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 3996 | StopInfo info, boolean keepShown, boolean saveState, String reason) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3997 | if (localLOGV) Slog.v(TAG, "Performing stop of " + r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3998 | if (r != null) { |
| 3999 | if (!keepShown && r.stopped) { |
| 4000 | if (r.activity.mFinished) { |
| 4001 | // If we are finishing, we won't call onResume() in certain |
| 4002 | // cases. So here we likewise don't want to call onStop() |
| 4003 | // if the activity isn't resumed. |
| 4004 | return; |
| 4005 | } |
| 4006 | RuntimeException e = new RuntimeException( |
Andrii Kulian | 58178f2 | 2016-03-16 13:44:56 -0700 | [diff] [blame] | 4007 | "Performing stop of activity that is already stopped: " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4008 | + r.intent.getComponent().toShortString()); |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 4009 | Slog.e(TAG, e.getMessage(), e); |
Andrii Kulian | 58178f2 | 2016-03-16 13:44:56 -0700 | [diff] [blame] | 4010 | Slog.e(TAG, r.getStateString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4011 | } |
| 4012 | |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 4013 | // One must first be paused before stopped... |
| 4014 | performPauseActivityIfNeeded(r, reason); |
| 4015 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4016 | if (info != null) { |
| 4017 | try { |
| 4018 | // First create a thumbnail for the activity... |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4019 | // For now, don't create the thumbnail here; we are |
| 4020 | // doing that by doing a screen snapshot. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4021 | info.description = r.activity.onCreateDescription(); |
| 4022 | } catch (Exception e) { |
| 4023 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4024 | throw new RuntimeException( |
| 4025 | "Unable to save state of activity " |
| 4026 | + r.intent.getComponent().toShortString() |
| 4027 | + ": " + e.toString(), e); |
| 4028 | } |
| 4029 | } |
| 4030 | } |
| 4031 | |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4032 | // Next have the activity save its current state and managed dialogs... |
| 4033 | if (!r.activity.mFinished && saveState) { |
| 4034 | if (r.state == null) { |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 4035 | callCallActivityOnSaveInstanceState(r); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4036 | } |
| 4037 | } |
| 4038 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4039 | if (!keepShown) { |
| 4040 | try { |
| 4041 | // Now we are idle. |
Chong Zhang | 7687f25 | 2016-02-26 12:03:33 -0800 | [diff] [blame] | 4042 | r.activity.performStop(false /*preserveWindow*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4043 | } catch (Exception e) { |
| 4044 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4045 | throw new RuntimeException( |
| 4046 | "Unable to stop activity " |
| 4047 | + r.intent.getComponent().toShortString() |
| 4048 | + ": " + e.toString(), e); |
| 4049 | } |
| 4050 | } |
| 4051 | r.stopped = true; |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 4052 | EventLog.writeEvent(LOG_AM_ON_STOP_CALLED, UserHandle.myUserId(), |
| 4053 | r.activity.getComponentName().getClassName(), reason); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4054 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4055 | } |
| 4056 | } |
| 4057 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 4058 | private void updateVisibility(ActivityClientRecord r, boolean show) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4059 | View v = r.activity.mDecor; |
| 4060 | if (v != null) { |
| 4061 | if (show) { |
| 4062 | if (!r.activity.mVisibleFromServer) { |
| 4063 | r.activity.mVisibleFromServer = true; |
| 4064 | mNumVisibleActivities++; |
| 4065 | if (r.activity.mVisibleFromClient) { |
| 4066 | r.activity.makeVisible(); |
| 4067 | } |
| 4068 | } |
| 4069 | if (r.newConfig != null) { |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4070 | performConfigurationChangedForActivity(r, r.newConfig); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4071 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Updating activity vis " |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 4072 | + r.activityInfo.name + " with new config " |
| 4073 | + r.activity.mCurrentConfig); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4074 | r.newConfig = null; |
| 4075 | } |
| 4076 | } else { |
| 4077 | if (r.activity.mVisibleFromServer) { |
| 4078 | r.activity.mVisibleFromServer = false; |
| 4079 | mNumVisibleActivities--; |
| 4080 | v.setVisibility(View.INVISIBLE); |
| 4081 | } |
| 4082 | } |
| 4083 | } |
| 4084 | } |
| 4085 | |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 4086 | private void handleStopActivity(IBinder token, boolean show, int configChanges, int seq) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4087 | ActivityClientRecord r = mActivities.get(token); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 4088 | if (!checkAndUpdateLifecycleSeq(seq, r, "stopActivity")) { |
| 4089 | return; |
| 4090 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4091 | r.activity.mConfigChangeFlags |= configChanges; |
| 4092 | |
| 4093 | StopInfo info = new StopInfo(); |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 4094 | performStopActivityInner(r, info, show, true, "handleStopActivity"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4095 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4096 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4097 | TAG, "Finishing stop of " + r + ": show=" + show |
| 4098 | + " win=" + r.window); |
| 4099 | |
| 4100 | updateVisibility(r, show); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4101 | |
Dianne Hackborn | 5d9d03a | 2011-01-24 13:15:09 -0800 | [diff] [blame] | 4102 | // Make sure any pending writes are now committed. |
| 4103 | if (!r.isPreHoneycomb()) { |
| 4104 | QueuedWork.waitToFinish(); |
| 4105 | } |
| 4106 | |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 4107 | // Schedule the call to tell the activity manager we have |
| 4108 | // stopped. We don't do this immediately, because we want to |
| 4109 | // have a chance for any other pending work (in particular memory |
| 4110 | // trim requests) to complete before you tell the activity |
| 4111 | // manager to proceed and allow us to go fully into the background. |
| 4112 | info.activity = r; |
| 4113 | info.state = r.state; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 4114 | info.persistentState = r.persistentState; |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 4115 | mH.post(info); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4116 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4117 | } |
| 4118 | |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 4119 | private static boolean checkAndUpdateLifecycleSeq(int seq, ActivityClientRecord r, |
| 4120 | String action) { |
| 4121 | if (r == null) { |
| 4122 | return true; |
| 4123 | } |
| 4124 | if (seq < r.lastProcessedSeq) { |
| 4125 | if (DEBUG_ORDER) Slog.d(TAG, action + " for " + r + " ignored, because seq=" + seq |
| 4126 | + " < mCurrentLifecycleSeq=" + r.lastProcessedSeq); |
| 4127 | return false; |
| 4128 | } |
| 4129 | r.lastProcessedSeq = seq; |
| 4130 | return true; |
| 4131 | } |
| 4132 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4133 | final void performRestartActivity(IBinder token) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4134 | ActivityClientRecord r = mActivities.get(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4135 | if (r.stopped) { |
| 4136 | r.activity.performRestart(); |
| 4137 | r.stopped = false; |
| 4138 | } |
| 4139 | } |
| 4140 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 4141 | private void handleWindowVisibility(IBinder token, boolean show) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4142 | ActivityClientRecord r = mActivities.get(token); |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 4143 | |
Dianne Hackborn | bfddc0f | 2010-12-14 11:28:01 -0800 | [diff] [blame] | 4144 | if (r == null) { |
| 4145 | Log.w(TAG, "handleWindowVisibility: no activity for token " + token); |
| 4146 | return; |
| 4147 | } |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 4148 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4149 | if (!show && !r.stopped) { |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 4150 | performStopActivityInner(r, null, show, false, "handleWindowVisibility"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4151 | } else if (show && r.stopped) { |
| 4152 | // If we are getting ready to gc after going to the background, well |
| 4153 | // we are back active so skip it. |
| 4154 | unscheduleGcIdler(); |
| 4155 | |
| 4156 | r.activity.performRestart(); |
| 4157 | r.stopped = false; |
| 4158 | } |
| 4159 | if (r.activity.mDecor != null) { |
Joe Onorato | 43a1765 | 2011-04-06 19:22:23 -0700 | [diff] [blame] | 4160 | if (false) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4161 | TAG, "Handle window " + r + " visibility: " + show); |
| 4162 | updateVisibility(r, show); |
| 4163 | } |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4164 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4165 | } |
| 4166 | |
Wale Ogunwale | b5066fe | 2016-09-21 07:33:43 -0700 | [diff] [blame] | 4167 | // TODO: This method should be changed to use {@link #performStopActivityInner} to perform to |
| 4168 | // stop operation on the activity to reduce code duplication and the chance of fixing a bug in |
| 4169 | // one place and missing the other. |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 4170 | private void handleSleeping(IBinder token, boolean sleeping) { |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 4171 | ActivityClientRecord r = mActivities.get(token); |
| 4172 | |
| 4173 | if (r == null) { |
Dianne Hackborn | 842e04b | 2011-01-22 13:00:12 -0800 | [diff] [blame] | 4174 | Log.w(TAG, "handleSleeping: no activity for token " + token); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 4175 | return; |
| 4176 | } |
| 4177 | |
| 4178 | if (sleeping) { |
Dianne Hackborn | 842e04b | 2011-01-22 13:00:12 -0800 | [diff] [blame] | 4179 | if (!r.stopped && !r.isPreHoneycomb()) { |
Wale Ogunwale | b5066fe | 2016-09-21 07:33:43 -0700 | [diff] [blame] | 4180 | if (!r.activity.mFinished && r.state == null) { |
| 4181 | callCallActivityOnSaveInstanceState(r); |
| 4182 | } |
| 4183 | |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 4184 | try { |
| 4185 | // Now we are idle. |
Chong Zhang | 7687f25 | 2016-02-26 12:03:33 -0800 | [diff] [blame] | 4186 | r.activity.performStop(false /*preserveWindow*/); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 4187 | } catch (Exception e) { |
| 4188 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4189 | throw new RuntimeException( |
| 4190 | "Unable to stop activity " |
| 4191 | + r.intent.getComponent().toShortString() |
| 4192 | + ": " + e.toString(), e); |
| 4193 | } |
| 4194 | } |
| 4195 | r.stopped = true; |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 4196 | EventLog.writeEvent(LOG_AM_ON_STOP_CALLED, UserHandle.myUserId(), |
| 4197 | r.activity.getComponentName().getClassName(), "sleeping"); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 4198 | } |
Dianne Hackborn | 5d9d03a | 2011-01-24 13:15:09 -0800 | [diff] [blame] | 4199 | |
| 4200 | // Make sure any pending writes are now committed. |
| 4201 | if (!r.isPreHoneycomb()) { |
| 4202 | QueuedWork.waitToFinish(); |
| 4203 | } |
| 4204 | |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 4205 | // Tell activity manager we slept. |
| 4206 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 4207 | ActivityManager.getService().activitySlept(r.token); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 4208 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4209 | throw ex.rethrowFromSystemServer(); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 4210 | } |
| 4211 | } else { |
| 4212 | if (r.stopped && r.activity.mVisibleFromServer) { |
| 4213 | r.activity.performRestart(); |
| 4214 | r.stopped = false; |
| 4215 | } |
| 4216 | } |
| 4217 | } |
| 4218 | |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 4219 | private void handleSetCoreSettings(Bundle coreSettings) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4220 | synchronized (mResourcesManager) { |
Svetoslav Ganov | 9aa597e | 2011-03-03 18:17:41 -0800 | [diff] [blame] | 4221 | mCoreSettings = coreSettings; |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 4222 | } |
Jon Miranda | 836c0a8 | 2014-08-11 12:32:26 -0700 | [diff] [blame] | 4223 | onCoreSettingsChange(); |
| 4224 | } |
| 4225 | |
| 4226 | private void onCoreSettingsChange() { |
| 4227 | boolean debugViewAttributes = |
| 4228 | mCoreSettings.getInt(Settings.Global.DEBUG_VIEW_ATTRIBUTES, 0) != 0; |
| 4229 | if (debugViewAttributes != View.mDebugViewAttributes) { |
| 4230 | View.mDebugViewAttributes = debugViewAttributes; |
| 4231 | |
| 4232 | // request all activities to relaunch for the changes to take place |
Fyodor Kupolov | cb93d6f | 2017-05-04 17:27:16 -0700 | [diff] [blame] | 4233 | requestRelaunchAllActivities(); |
| 4234 | } |
| 4235 | } |
| 4236 | |
| 4237 | private void requestRelaunchAllActivities() { |
| 4238 | for (Map.Entry<IBinder, ActivityClientRecord> entry : mActivities.entrySet()) { |
| 4239 | final Activity activity = entry.getValue().activity; |
| 4240 | if (!activity.mFinished) { |
| 4241 | try { |
| 4242 | ActivityManager.getService().requestActivityRelaunch(entry.getKey()); |
| 4243 | } catch (RemoteException e) { |
| 4244 | throw e.rethrowFromSystemServer(); |
| 4245 | } |
Jon Miranda | 836c0a8 | 2014-08-11 12:32:26 -0700 | [diff] [blame] | 4246 | } |
| 4247 | } |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 4248 | } |
| 4249 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4250 | private void handleUpdatePackageCompatibilityInfo(UpdateCompatibilityData data) { |
| 4251 | LoadedApk apk = peekPackageInfo(data.pkg, false); |
| 4252 | if (apk != null) { |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 4253 | apk.setCompatibilityInfo(data.info); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4254 | } |
| 4255 | apk = peekPackageInfo(data.pkg, true); |
| 4256 | if (apk != null) { |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 4257 | apk.setCompatibilityInfo(data.info); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4258 | } |
| 4259 | handleConfigurationChanged(mConfiguration, data.info); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 4260 | WindowManagerGlobal.getInstance().reportNewConfiguration(mConfiguration); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4261 | } |
| 4262 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 4263 | private void deliverResults(ActivityClientRecord r, List<ResultInfo> results) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4264 | final int N = results.size(); |
| 4265 | for (int i=0; i<N; i++) { |
| 4266 | ResultInfo ri = results.get(i); |
| 4267 | try { |
| 4268 | if (ri.mData != null) { |
| 4269 | ri.mData.setExtrasClassLoader(r.activity.getClassLoader()); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 4270 | ri.mData.prepareToEnterProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4271 | } |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4272 | if (DEBUG_RESULTS) Slog.v(TAG, |
Chris Tate | 8a7dc17 | 2009-03-24 20:11:42 -0700 | [diff] [blame] | 4273 | "Delivering result to activity " + r + " : " + ri); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4274 | r.activity.dispatchActivityResult(ri.mResultWho, |
| 4275 | ri.mRequestCode, ri.mResultCode, ri.mData); |
| 4276 | } catch (Exception e) { |
| 4277 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4278 | throw new RuntimeException( |
| 4279 | "Failure delivering result " + ri + " to activity " |
| 4280 | + r.intent.getComponent().toShortString() |
| 4281 | + ": " + e.toString(), e); |
| 4282 | } |
| 4283 | } |
| 4284 | } |
| 4285 | } |
| 4286 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 4287 | private void handleSendResult(ResultData res) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4288 | ActivityClientRecord r = mActivities.get(res.token); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4289 | 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] | 4290 | if (r != null) { |
| 4291 | final boolean resumed = !r.paused; |
| 4292 | if (!r.activity.mFinished && r.activity.mDecor != null |
| 4293 | && r.hideForNow && resumed) { |
| 4294 | // We had hidden the activity because it started another |
| 4295 | // one... we have gotten a result back and we are not |
| 4296 | // paused, so make sure our window is visible. |
| 4297 | updateVisibility(r, true); |
| 4298 | } |
| 4299 | if (resumed) { |
| 4300 | try { |
| 4301 | // Now we are idle. |
| 4302 | r.activity.mCalled = false; |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 4303 | r.activity.mTemporaryPause = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4304 | mInstrumentation.callActivityOnPause(r.activity); |
| 4305 | if (!r.activity.mCalled) { |
| 4306 | throw new SuperNotCalledException( |
| 4307 | "Activity " + r.intent.getComponent().toShortString() |
| 4308 | + " did not call through to super.onPause()"); |
| 4309 | } |
| 4310 | } catch (SuperNotCalledException e) { |
| 4311 | throw e; |
| 4312 | } catch (Exception e) { |
| 4313 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4314 | throw new RuntimeException( |
| 4315 | "Unable to pause activity " |
| 4316 | + r.intent.getComponent().toShortString() |
| 4317 | + ": " + e.toString(), e); |
| 4318 | } |
| 4319 | } |
| 4320 | } |
Sudheer Shanka | 43b5ea4 | 2017-06-21 11:24:53 -0700 | [diff] [blame] | 4321 | checkAndBlockForNetworkAccess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4322 | deliverResults(r, res.results); |
| 4323 | if (resumed) { |
Dianne Hackborn | b46ed76 | 2011-06-02 18:33:15 -0700 | [diff] [blame] | 4324 | r.activity.performResume(); |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 4325 | r.activity.mTemporaryPause = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4326 | } |
| 4327 | } |
| 4328 | } |
| 4329 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4330 | public final ActivityClientRecord performDestroyActivity(IBinder token, boolean finishing) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4331 | return performDestroyActivity(token, finishing, 0, false); |
| 4332 | } |
| 4333 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 4334 | private ActivityClientRecord performDestroyActivity(IBinder token, boolean finishing, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4335 | int configChanges, boolean getNonConfigInstance) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4336 | ActivityClientRecord r = mActivities.get(token); |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4337 | Class<? extends Activity> activityClass = null; |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4338 | if (localLOGV) Slog.v(TAG, "Performing finish of " + r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4339 | if (r != null) { |
Brad Fitzpatrick | 5f8b5c1 | 2011-01-20 15:12:08 -0800 | [diff] [blame] | 4340 | activityClass = r.activity.getClass(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4341 | r.activity.mConfigChangeFlags |= configChanges; |
| 4342 | if (finishing) { |
| 4343 | r.activity.mFinished = true; |
| 4344 | } |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 4345 | |
| 4346 | performPauseActivityIfNeeded(r, "destroy"); |
| 4347 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4348 | if (!r.stopped) { |
| 4349 | try { |
Chong Zhang | 7687f25 | 2016-02-26 12:03:33 -0800 | [diff] [blame] | 4350 | r.activity.performStop(r.mPreserveWindow); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4351 | } catch (SuperNotCalledException e) { |
| 4352 | throw e; |
| 4353 | } catch (Exception e) { |
| 4354 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4355 | throw new RuntimeException( |
| 4356 | "Unable to stop activity " |
Mitsuru Oshima | d9aef73 | 2009-06-16 20:20:50 -0700 | [diff] [blame] | 4357 | + safeToComponentShortString(r.intent) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4358 | + ": " + e.toString(), e); |
| 4359 | } |
| 4360 | } |
| 4361 | r.stopped = true; |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 4362 | EventLog.writeEvent(LOG_AM_ON_STOP_CALLED, UserHandle.myUserId(), |
| 4363 | r.activity.getComponentName().getClassName(), "destroy"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4364 | } |
| 4365 | if (getNonConfigInstance) { |
| 4366 | try { |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 4367 | r.lastNonConfigurationInstances |
| 4368 | = r.activity.retainNonConfigurationInstances(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4369 | } catch (Exception e) { |
| 4370 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4371 | throw new RuntimeException( |
| 4372 | "Unable to retain activity " |
| 4373 | + r.intent.getComponent().toShortString() |
| 4374 | + ": " + e.toString(), e); |
| 4375 | } |
| 4376 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4377 | } |
| 4378 | try { |
| 4379 | r.activity.mCalled = false; |
Dianne Hackborn | 2dedce6 | 2010-04-15 14:45:25 -0700 | [diff] [blame] | 4380 | mInstrumentation.callActivityOnDestroy(r.activity); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4381 | if (!r.activity.mCalled) { |
| 4382 | throw new SuperNotCalledException( |
Mitsuru Oshima | d9aef73 | 2009-06-16 20:20:50 -0700 | [diff] [blame] | 4383 | "Activity " + safeToComponentShortString(r.intent) + |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4384 | " did not call through to super.onDestroy()"); |
| 4385 | } |
| 4386 | if (r.window != null) { |
| 4387 | r.window.closeAllPanels(); |
| 4388 | } |
| 4389 | } catch (SuperNotCalledException e) { |
| 4390 | throw e; |
| 4391 | } catch (Exception e) { |
| 4392 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4393 | throw new RuntimeException( |
Mitsuru Oshima | d9aef73 | 2009-06-16 20:20:50 -0700 | [diff] [blame] | 4394 | "Unable to destroy activity " + safeToComponentShortString(r.intent) |
| 4395 | + ": " + e.toString(), e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4396 | } |
| 4397 | } |
| 4398 | } |
| 4399 | mActivities.remove(token); |
Brad Fitzpatrick | 5f8b5c1 | 2011-01-20 15:12:08 -0800 | [diff] [blame] | 4400 | StrictMode.decrementExpectedActivityCount(activityClass); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4401 | return r; |
| 4402 | } |
| 4403 | |
Mitsuru Oshima | d9aef73 | 2009-06-16 20:20:50 -0700 | [diff] [blame] | 4404 | private static String safeToComponentShortString(Intent intent) { |
| 4405 | ComponentName component = intent.getComponent(); |
| 4406 | return component == null ? "[Unknown]" : component.toShortString(); |
| 4407 | } |
| 4408 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 4409 | private void handleDestroyActivity(IBinder token, boolean finishing, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4410 | int configChanges, boolean getNonConfigInstance) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4411 | ActivityClientRecord r = performDestroyActivity(token, finishing, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4412 | configChanges, getNonConfigInstance); |
| 4413 | if (r != null) { |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4414 | cleanUpPendingRemoveWindows(r, finishing); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4415 | WindowManager wm = r.activity.getWindowManager(); |
| 4416 | View v = r.activity.mDecor; |
| 4417 | if (v != null) { |
| 4418 | if (r.activity.mVisibleFromServer) { |
| 4419 | mNumVisibleActivities--; |
| 4420 | } |
| 4421 | IBinder wtoken = v.getWindowToken(); |
| 4422 | if (r.activity.mWindowAdded) { |
Robert Carr | 77bdfb5 | 2016-05-02 18:18:31 -0700 | [diff] [blame] | 4423 | if (r.mPreserveWindow) { |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4424 | // Hold off on removing this until the new activity's |
| 4425 | // window is being added. |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4426 | r.mPendingRemoveWindow = r.window; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4427 | r.mPendingRemoveWindowManager = wm; |
Andrii Kulian | eac0ea5 | 2016-05-11 15:50:24 -0700 | [diff] [blame] | 4428 | // We can only keep the part of the view hierarchy that we control, |
| 4429 | // everything else must be removed, because it might not be able to |
| 4430 | // behave properly when activity is relaunching. |
| 4431 | r.window.clearContentView(); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4432 | } else { |
| 4433 | wm.removeViewImmediate(v); |
| 4434 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4435 | } |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4436 | if (wtoken != null && r.mPendingRemoveWindow == null) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 4437 | WindowManagerGlobal.getInstance().closeAll(wtoken, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4438 | r.activity.getClass().getName(), "Activity"); |
Andrii Kulian | eac0ea5 | 2016-05-11 15:50:24 -0700 | [diff] [blame] | 4439 | } else if (r.mPendingRemoveWindow != null) { |
| 4440 | // We're preserving only one window, others should be closed so app views |
| 4441 | // will be detached before the final tear down. It should be done now because |
| 4442 | // some components (e.g. WebView) rely on detach callbacks to perform receiver |
| 4443 | // unregister and other cleanup. |
| 4444 | WindowManagerGlobal.getInstance().closeAllExceptView(token, v, |
| 4445 | r.activity.getClass().getName(), "Activity"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4446 | } |
| 4447 | r.activity.mDecor = null; |
| 4448 | } |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4449 | if (r.mPendingRemoveWindow == null) { |
| 4450 | // If we are delaying the removal of the activity window, then |
| 4451 | // we can't clean up all windows here. Note that we can't do |
| 4452 | // so later either, which means any windows that aren't closed |
| 4453 | // by the app will leak. Well we try to warning them a lot |
| 4454 | // about leaking windows, because that is a bug, so if they are |
| 4455 | // using this recreate facility then they get to live with leaks. |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 4456 | WindowManagerGlobal.getInstance().closeAll(token, |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4457 | r.activity.getClass().getName(), "Activity"); |
| 4458 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4459 | |
| 4460 | // Mocked out contexts won't be participating in the normal |
| 4461 | // process lifecycle, but if we're running with a proper |
| 4462 | // ApplicationContext we need to have it tear down things |
| 4463 | // cleanly. |
| 4464 | Context c = r.activity.getBaseContext(); |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 4465 | if (c instanceof ContextImpl) { |
| 4466 | ((ContextImpl) c).scheduleFinalCleanup( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4467 | r.activity.getClass().getName(), "Activity"); |
| 4468 | } |
| 4469 | } |
| 4470 | if (finishing) { |
| 4471 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 4472 | ActivityManager.getService().activityDestroyed(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4473 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4474 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4475 | } |
| 4476 | } |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4477 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4478 | } |
| 4479 | |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4480 | /** |
| 4481 | * @param preserveWindow Whether the activity should try to reuse the window it created, |
| 4482 | * including the decor view after the relaunch. |
| 4483 | */ |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4484 | public final void requestRelaunchActivity(IBinder token, |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 4485 | List<ResultInfo> pendingResults, List<ReferrerIntent> pendingNewIntents, |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4486 | int configChanges, boolean notResumed, Configuration config, |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4487 | Configuration overrideConfig, boolean fromServer, boolean preserveWindow) { |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4488 | ActivityClientRecord target = null; |
| 4489 | |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4490 | synchronized (mResourcesManager) { |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4491 | for (int i=0; i<mRelaunchingActivities.size(); i++) { |
| 4492 | ActivityClientRecord r = mRelaunchingActivities.get(i); |
Filip Gruszczynski | c3b6179 | 2016-01-22 16:43:48 -0800 | [diff] [blame] | 4493 | if (DEBUG_ORDER) Slog.d(TAG, "requestRelaunchActivity: " + this + ", trying: " + r); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4494 | if (r.token == token) { |
| 4495 | target = r; |
| 4496 | if (pendingResults != null) { |
| 4497 | if (r.pendingResults != null) { |
| 4498 | r.pendingResults.addAll(pendingResults); |
| 4499 | } else { |
| 4500 | r.pendingResults = pendingResults; |
| 4501 | } |
| 4502 | } |
| 4503 | if (pendingNewIntents != null) { |
| 4504 | if (r.pendingIntents != null) { |
| 4505 | r.pendingIntents.addAll(pendingNewIntents); |
| 4506 | } else { |
| 4507 | r.pendingIntents = pendingNewIntents; |
| 4508 | } |
| 4509 | } |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4510 | |
| 4511 | // For each relaunch request, activity manager expects an answer |
| 4512 | if (!r.onlyLocalRequest && fromServer) { |
| 4513 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 4514 | ActivityManager.getService().activityRelaunched(token); |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4515 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4516 | throw e.rethrowFromSystemServer(); |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4517 | } |
| 4518 | } |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4519 | break; |
| 4520 | } |
| 4521 | } |
| 4522 | |
| 4523 | if (target == null) { |
Filip Gruszczynski | c3b6179 | 2016-01-22 16:43:48 -0800 | [diff] [blame] | 4524 | if (DEBUG_ORDER) Slog.d(TAG, "requestRelaunchActivity: target is null, fromServer:" |
| 4525 | + fromServer); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4526 | target = new ActivityClientRecord(); |
| 4527 | target.token = token; |
| 4528 | target.pendingResults = pendingResults; |
| 4529 | target.pendingIntents = pendingNewIntents; |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4530 | target.mPreserveWindow = preserveWindow; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4531 | if (!fromServer) { |
Filip Gruszczynski | c3b6179 | 2016-01-22 16:43:48 -0800 | [diff] [blame] | 4532 | final ActivityClientRecord existing = mActivities.get(token); |
| 4533 | if (DEBUG_ORDER) Slog.d(TAG, "requestRelaunchActivity: " + existing); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4534 | if (existing != null) { |
Filip Gruszczynski | c3b6179 | 2016-01-22 16:43:48 -0800 | [diff] [blame] | 4535 | if (DEBUG_ORDER) Slog.d(TAG, "requestRelaunchActivity: paused= " |
| 4536 | + existing.paused);; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4537 | target.startsNotResumed = existing.paused; |
Wale Ogunwale | 93f543c | 2015-02-17 16:55:03 -0800 | [diff] [blame] | 4538 | target.overrideConfig = existing.overrideConfig; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4539 | } |
| 4540 | target.onlyLocalRequest = true; |
| 4541 | } |
| 4542 | mRelaunchingActivities.add(target); |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 4543 | sendMessage(H.RELAUNCH_ACTIVITY, target); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4544 | } |
| 4545 | |
| 4546 | if (fromServer) { |
| 4547 | target.startsNotResumed = notResumed; |
| 4548 | target.onlyLocalRequest = false; |
| 4549 | } |
| 4550 | if (config != null) { |
| 4551 | target.createdConfig = config; |
| 4552 | } |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 4553 | if (overrideConfig != null) { |
| 4554 | target.overrideConfig = overrideConfig; |
| 4555 | } |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4556 | target.pendingConfigChanges |= configChanges; |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 4557 | target.relaunchSeq = getLifecycleSeq(); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4558 | } |
Filip Gruszczynski | c3b6179 | 2016-01-22 16:43:48 -0800 | [diff] [blame] | 4559 | if (DEBUG_ORDER) Slog.d(TAG, "relaunchActivity " + ActivityThread.this + ", target " |
| 4560 | + target + " operation received seq: " + target.relaunchSeq); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4561 | } |
| 4562 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 4563 | private void handleRelaunchActivity(ActivityClientRecord tmp) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4564 | // If we are getting ready to gc after going to the background, well |
| 4565 | // we are back active so skip it. |
| 4566 | unscheduleGcIdler(); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4567 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4568 | |
| 4569 | Configuration changedConfig = null; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4570 | int configChanges = 0; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4571 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4572 | // First: make sure we have the most recent configuration and most |
| 4573 | // recent version of the activity, or skip it if some previous call |
| 4574 | // had taken a more recent version. |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4575 | synchronized (mResourcesManager) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4576 | int N = mRelaunchingActivities.size(); |
| 4577 | IBinder token = tmp.token; |
| 4578 | tmp = null; |
| 4579 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4580 | ActivityClientRecord r = mRelaunchingActivities.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4581 | if (r.token == token) { |
| 4582 | tmp = r; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4583 | configChanges |= tmp.pendingConfigChanges; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4584 | mRelaunchingActivities.remove(i); |
| 4585 | i--; |
| 4586 | N--; |
| 4587 | } |
| 4588 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4589 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4590 | if (tmp == null) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4591 | 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] | 4592 | return; |
| 4593 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4594 | |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4595 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Relaunching activity " |
| 4596 | + tmp.token + " with configChanges=0x" |
| 4597 | + Integer.toHexString(configChanges)); |
| 4598 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4599 | if (mPendingConfiguration != null) { |
| 4600 | changedConfig = mPendingConfiguration; |
| 4601 | mPendingConfiguration = null; |
| 4602 | } |
| 4603 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4604 | |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 4605 | if (tmp.lastProcessedSeq > tmp.relaunchSeq) { |
| 4606 | Slog.wtf(TAG, "For some reason target: " + tmp + " has lower sequence: " |
| 4607 | + tmp.relaunchSeq + " than current sequence: " + tmp.lastProcessedSeq); |
| 4608 | } else { |
| 4609 | tmp.lastProcessedSeq = tmp.relaunchSeq; |
| 4610 | } |
Dianne Hackborn | 871ecdc | 2009-12-11 15:24:33 -0800 | [diff] [blame] | 4611 | if (tmp.createdConfig != null) { |
| 4612 | // If the activity manager is passing us its current config, |
| 4613 | // assume that is really what we want regardless of what we |
| 4614 | // may have pending. |
| 4615 | if (mConfiguration == null |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4616 | || (tmp.createdConfig.isOtherSeqNewer(mConfiguration) |
| 4617 | && mConfiguration.diff(tmp.createdConfig) != 0)) { |
| 4618 | if (changedConfig == null |
| 4619 | || tmp.createdConfig.isOtherSeqNewer(changedConfig)) { |
| 4620 | changedConfig = tmp.createdConfig; |
| 4621 | } |
Dianne Hackborn | 871ecdc | 2009-12-11 15:24:33 -0800 | [diff] [blame] | 4622 | } |
| 4623 | } |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 4624 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4625 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Relaunching activity " |
Dianne Hackborn | dc6b635 | 2009-09-30 14:20:09 -0700 | [diff] [blame] | 4626 | + tmp.token + ": changedConfig=" + changedConfig); |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 4627 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4628 | // If there was a pending configuration change, execute it first. |
| 4629 | if (changedConfig != null) { |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 4630 | mCurDefaultDisplayDpi = changedConfig.densityDpi; |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 4631 | updateDefaultDensity(); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4632 | handleConfigurationChanged(changedConfig, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4633 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4634 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4635 | ActivityClientRecord r = mActivities.get(tmp.token); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4636 | 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] | 4637 | if (r == null) { |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4638 | if (!tmp.onlyLocalRequest) { |
| 4639 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 4640 | ActivityManager.getService().activityRelaunched(tmp.token); |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4641 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4642 | throw e.rethrowFromSystemServer(); |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4643 | } |
| 4644 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4645 | return; |
| 4646 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4647 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4648 | r.activity.mConfigChangeFlags |= configChanges; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4649 | r.onlyLocalRequest = tmp.onlyLocalRequest; |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4650 | r.mPreserveWindow = tmp.mPreserveWindow; |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 4651 | r.lastProcessedSeq = tmp.lastProcessedSeq; |
| 4652 | r.relaunchSeq = tmp.relaunchSeq; |
Christopher Tate | b70f3df | 2009-04-07 16:07:59 -0700 | [diff] [blame] | 4653 | Intent currentIntent = r.activity.mIntent; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4654 | |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4655 | r.activity.mChangingConfigurations = true; |
| 4656 | |
Robert Carr | 23fa16b | 2016-01-13 13:19:58 -0800 | [diff] [blame] | 4657 | // If we are preserving the main window across relaunches we would also like to preserve |
| 4658 | // the children. However the client side view system does not support preserving |
| 4659 | // the child views so we notify the window manager to expect these windows to |
| 4660 | // be replaced and defer requests to destroy or hide them. This way we can achieve |
| 4661 | // visual continuity. It's important that we do this here prior to pause and destroy |
| 4662 | // as that is when we may hide or remove the child views. |
Robert Carr | 77bdfb5 | 2016-05-02 18:18:31 -0700 | [diff] [blame] | 4663 | // |
| 4664 | // There is another scenario, if we have decided locally to relaunch the app from a |
| 4665 | // call to recreate, then none of the windows will be prepared for replacement or |
| 4666 | // preserved by the server, so we want to notify it that we are preparing to replace |
| 4667 | // everything |
Robert Carr | 23fa16b | 2016-01-13 13:19:58 -0800 | [diff] [blame] | 4668 | try { |
Robert Carr | 77bdfb5 | 2016-05-02 18:18:31 -0700 | [diff] [blame] | 4669 | if (r.mPreserveWindow || r.onlyLocalRequest) { |
| 4670 | WindowManagerGlobal.getWindowSession().prepareToReplaceWindows( |
| 4671 | r.token, !r.onlyLocalRequest); |
Robert Carr | 23fa16b | 2016-01-13 13:19:58 -0800 | [diff] [blame] | 4672 | } |
| 4673 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4674 | throw e.rethrowFromSystemServer(); |
Robert Carr | 23fa16b | 2016-01-13 13:19:58 -0800 | [diff] [blame] | 4675 | } |
| 4676 | |
Dianne Hackborn | e2b0480 | 2010-12-09 09:24:55 -0800 | [diff] [blame] | 4677 | // Need to ensure state is saved. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4678 | if (!r.paused) { |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 4679 | performPauseActivity(r.token, false, r.isPreHoneycomb(), "handleRelaunchActivity"); |
Dianne Hackborn | e2b0480 | 2010-12-09 09:24:55 -0800 | [diff] [blame] | 4680 | } |
| 4681 | if (r.state == null && !r.stopped && !r.isPreHoneycomb()) { |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 4682 | callCallActivityOnSaveInstanceState(r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4683 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4684 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4685 | handleDestroyActivity(r.token, false, configChanges, true); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4686 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4687 | r.activity = null; |
| 4688 | r.window = null; |
| 4689 | r.hideForNow = false; |
| 4690 | r.nextIdle = null; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4691 | // Merge any pending results and pending intents; don't just replace them |
| 4692 | if (tmp.pendingResults != null) { |
| 4693 | if (r.pendingResults == null) { |
| 4694 | r.pendingResults = tmp.pendingResults; |
| 4695 | } else { |
| 4696 | r.pendingResults.addAll(tmp.pendingResults); |
| 4697 | } |
| 4698 | } |
| 4699 | if (tmp.pendingIntents != null) { |
| 4700 | if (r.pendingIntents == null) { |
| 4701 | r.pendingIntents = tmp.pendingIntents; |
| 4702 | } else { |
| 4703 | r.pendingIntents.addAll(tmp.pendingIntents); |
| 4704 | } |
| 4705 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4706 | r.startsNotResumed = tmp.startsNotResumed; |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 4707 | r.overrideConfig = tmp.overrideConfig; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4708 | |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 4709 | handleLaunchActivity(r, currentIntent, "handleRelaunchActivity"); |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4710 | |
| 4711 | if (!tmp.onlyLocalRequest) { |
| 4712 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 4713 | ActivityManager.getService().activityRelaunched(r.token); |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 4714 | if (r.window != null) { |
| 4715 | r.window.reportActivityRelaunched(); |
| 4716 | } |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4717 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4718 | throw e.rethrowFromSystemServer(); |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4719 | } |
| 4720 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4721 | } |
| 4722 | |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 4723 | private void callCallActivityOnSaveInstanceState(ActivityClientRecord r) { |
| 4724 | r.state = new Bundle(); |
| 4725 | r.state.setAllowFds(false); |
| 4726 | if (r.isPersistable()) { |
| 4727 | r.persistentState = new PersistableBundle(); |
| 4728 | mInstrumentation.callActivityOnSaveInstanceState(r.activity, r.state, |
| 4729 | r.persistentState); |
| 4730 | } else { |
| 4731 | mInstrumentation.callActivityOnSaveInstanceState(r.activity, r.state); |
| 4732 | } |
| 4733 | } |
| 4734 | |
Dianne Hackborn | 73c1416 | 2012-09-19 15:45:06 -0700 | [diff] [blame] | 4735 | ArrayList<ComponentCallbacks2> collectComponentCallbacks( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4736 | boolean allActivities, Configuration newConfig) { |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 4737 | ArrayList<ComponentCallbacks2> callbacks |
| 4738 | = new ArrayList<ComponentCallbacks2>(); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4739 | |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4740 | synchronized (mResourcesManager) { |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 4741 | final int NAPP = mAllApplications.size(); |
| 4742 | for (int i=0; i<NAPP; i++) { |
Dianne Hackborn | 73c1416 | 2012-09-19 15:45:06 -0700 | [diff] [blame] | 4743 | callbacks.add(mAllApplications.get(i)); |
| 4744 | } |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 4745 | final int NACT = mActivities.size(); |
| 4746 | for (int i=0; i<NACT; i++) { |
| 4747 | ActivityClientRecord ar = mActivities.valueAt(i); |
| 4748 | Activity a = ar.activity; |
| 4749 | if (a != null) { |
| 4750 | Configuration thisConfig = applyConfigCompatMainThread( |
| 4751 | mCurDefaultDisplayDpi, newConfig, |
| 4752 | ar.packageInfo.getCompatibilityInfo()); |
| 4753 | if (!ar.activity.mFinished && (allActivities || !ar.paused)) { |
| 4754 | // If the activity is currently resumed, its configuration |
| 4755 | // needs to change right now. |
| 4756 | callbacks.add(a); |
| 4757 | } else if (thisConfig != null) { |
| 4758 | // Otherwise, we will tell it about the change |
| 4759 | // the next time it is resumed or shown. Note that |
| 4760 | // the activity manager may, before then, decide the |
| 4761 | // activity needs to be destroyed to handle its new |
| 4762 | // configuration. |
| 4763 | if (DEBUG_CONFIGURATION) { |
| 4764 | Slog.v(TAG, "Setting activity " |
| 4765 | + ar.activityInfo.name + " newConfig=" + thisConfig); |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 4766 | } |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 4767 | ar.newConfig = thisConfig; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4768 | } |
| 4769 | } |
| 4770 | } |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 4771 | final int NSVC = mServices.size(); |
| 4772 | for (int i=0; i<NSVC; i++) { |
| 4773 | callbacks.add(mServices.valueAt(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4774 | } |
| 4775 | } |
| 4776 | synchronized (mProviderMap) { |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 4777 | final int NPRV = mLocalProviders.size(); |
| 4778 | for (int i=0; i<NPRV; i++) { |
| 4779 | callbacks.add(mLocalProviders.valueAt(i).mLocalProvider); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4780 | } |
| 4781 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4782 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4783 | return callbacks; |
| 4784 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4785 | |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 4786 | /** |
| 4787 | * Updates the configuration for an Activity. The ActivityClientRecord's |
| 4788 | * {@link ActivityClientRecord#overrideConfig} is used to compute the final Configuration for |
| 4789 | * that Activity. {@link ActivityClientRecord#tmpConfig} is used as a temporary for delivering |
| 4790 | * the updated Configuration. |
| 4791 | * @param r ActivityClientRecord representing the Activity. |
| 4792 | * @param newBaseConfig The new configuration to use. This may be augmented with |
| 4793 | * {@link ActivityClientRecord#overrideConfig}. |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 4794 | */ |
| 4795 | private void performConfigurationChangedForActivity(ActivityClientRecord r, |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4796 | Configuration newBaseConfig) { |
| 4797 | performConfigurationChangedForActivity(r, newBaseConfig, |
| 4798 | r.activity.getDisplay().getDisplayId(), false /* movedToDifferentDisplay */); |
| 4799 | } |
| 4800 | |
| 4801 | /** |
| 4802 | * Updates the configuration for an Activity. The ActivityClientRecord's |
| 4803 | * {@link ActivityClientRecord#overrideConfig} is used to compute the final Configuration for |
| 4804 | * that Activity. {@link ActivityClientRecord#tmpConfig} is used as a temporary for delivering |
| 4805 | * the updated Configuration. |
| 4806 | * @param r ActivityClientRecord representing the Activity. |
| 4807 | * @param newBaseConfig The new configuration to use. This may be augmented with |
| 4808 | * {@link ActivityClientRecord#overrideConfig}. |
| 4809 | * @param displayId The id of the display where the Activity currently resides. |
| 4810 | * @param movedToDifferentDisplay Indicates if the activity was moved to different display. |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 4811 | * @return {@link Configuration} instance sent to client, null if not sent. |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4812 | */ |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 4813 | private Configuration performConfigurationChangedForActivity(ActivityClientRecord r, |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4814 | Configuration newBaseConfig, int displayId, boolean movedToDifferentDisplay) { |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 4815 | r.tmpConfig.setTo(newBaseConfig); |
| 4816 | if (r.overrideConfig != null) { |
| 4817 | r.tmpConfig.updateFrom(r.overrideConfig); |
| 4818 | } |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 4819 | final Configuration reportedConfig = performActivityConfigurationChanged(r.activity, |
| 4820 | r.tmpConfig, r.overrideConfig, displayId, movedToDifferentDisplay); |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 4821 | freeTextLayoutCachesIfNeeded(r.activity.mCurrentConfig.diff(r.tmpConfig)); |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 4822 | return reportedConfig; |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 4823 | } |
| 4824 | |
| 4825 | /** |
Adam Lesinski | c1b0ebf | 2016-06-09 11:17:10 -0700 | [diff] [blame] | 4826 | * Creates a new Configuration only if override would modify base. Otherwise returns base. |
| 4827 | * @param base The base configuration. |
| 4828 | * @param override The update to apply to the base configuration. Can be null. |
| 4829 | * @return A Configuration representing base with override applied. |
| 4830 | */ |
| 4831 | private static Configuration createNewConfigAndUpdateIfNotNull(@NonNull Configuration base, |
| 4832 | @Nullable Configuration override) { |
| 4833 | if (override == null) { |
| 4834 | return base; |
| 4835 | } |
| 4836 | Configuration newConfig = new Configuration(base); |
| 4837 | newConfig.updateFrom(override); |
| 4838 | return newConfig; |
| 4839 | } |
| 4840 | |
| 4841 | /** |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4842 | * Decides whether to update a component's configuration and whether to inform it. |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 4843 | * @param cb The component callback to notify of configuration change. |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4844 | * @param newConfig The new configuration. |
| 4845 | */ |
| 4846 | private void performConfigurationChanged(ComponentCallbacks2 cb, Configuration newConfig) { |
| 4847 | if (!REPORT_TO_ACTIVITY) { |
| 4848 | return; |
| 4849 | } |
| 4850 | |
| 4851 | // ContextThemeWrappers may override the configuration for that context. We must check and |
| 4852 | // apply any overrides defined. |
| 4853 | Configuration contextThemeWrapperOverrideConfig = null; |
| 4854 | if (cb instanceof ContextThemeWrapper) { |
| 4855 | final ContextThemeWrapper contextThemeWrapper = (ContextThemeWrapper) cb; |
| 4856 | contextThemeWrapperOverrideConfig = contextThemeWrapper.getOverrideConfiguration(); |
| 4857 | } |
| 4858 | |
| 4859 | // Apply the ContextThemeWrapper override if necessary. |
| 4860 | // NOTE: Make sure the configurations are not modified, as they are treated as immutable |
| 4861 | // in many places. |
| 4862 | final Configuration configToReport = createNewConfigAndUpdateIfNotNull( |
| 4863 | newConfig, contextThemeWrapperOverrideConfig); |
| 4864 | cb.onConfigurationChanged(configToReport); |
| 4865 | } |
| 4866 | |
| 4867 | /** |
| 4868 | * Decides whether to update an Activity's configuration and whether to inform it. |
| 4869 | * @param activity The activity to notify of configuration change. |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 4870 | * @param newConfig The new configuration. |
Adam Lesinski | c1b0ebf | 2016-06-09 11:17:10 -0700 | [diff] [blame] | 4871 | * @param amOverrideConfig The override config that differentiates the Activity's configuration |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4872 | * from the base global configuration. This is supplied by |
| 4873 | * ActivityManager. |
| 4874 | * @param displayId Id of the display where activity currently resides. |
| 4875 | * @param movedToDifferentDisplay Indicates if the activity was moved to different display. |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 4876 | * @return Configuration sent to client, null if no changes and not moved to different display. |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 4877 | */ |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 4878 | private Configuration performActivityConfigurationChanged(Activity activity, |
| 4879 | Configuration newConfig, Configuration amOverrideConfig, int displayId, |
| 4880 | boolean movedToDifferentDisplay) { |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4881 | if (activity == null) { |
| 4882 | throw new IllegalArgumentException("No activity provided."); |
| 4883 | } |
| 4884 | final IBinder activityToken = activity.getActivityToken(); |
| 4885 | if (activityToken == null) { |
| 4886 | throw new IllegalArgumentException("Activity token not set. Is the activity attached?"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4887 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4888 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4889 | boolean shouldChangeConfig = false; |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4890 | if (activity.mCurrentConfig == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4891 | shouldChangeConfig = true; |
| 4892 | } else { |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4893 | // If the new config is the same as the config this Activity is already running with and |
| 4894 | // the override config also didn't change, then don't bother calling |
| 4895 | // onConfigurationChanged. |
Bryce Lee | 658d984 | 2017-07-28 08:33:36 -0700 | [diff] [blame] | 4896 | final int diff = activity.mCurrentConfig.diffPublicOnly(newConfig); |
| 4897 | |
Andrii Kulian | 3b3c914 | 2016-07-18 19:15:56 -0700 | [diff] [blame] | 4898 | if (diff != 0 || !mResourcesManager.isSameResourcesOverrideConfig(activityToken, |
| 4899 | amOverrideConfig)) { |
Chong Zhang | 4951f9d | 2016-06-23 13:15:08 -0700 | [diff] [blame] | 4900 | // Always send the task-level config changes. For system-level configuration, if |
| 4901 | // this activity doesn't handle any of the config changes, then don't bother |
| 4902 | // calling onConfigurationChanged as we're going to destroy it. |
| 4903 | if (!mUpdatingSystemConfig |
| 4904 | || (~activity.mActivityInfo.getRealConfigChanged() & diff) == 0 |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4905 | || !REPORT_TO_ACTIVITY) { |
Chong Zhang | 4951f9d | 2016-06-23 13:15:08 -0700 | [diff] [blame] | 4906 | shouldChangeConfig = true; |
| 4907 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4908 | } |
| 4909 | } |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4910 | if (!shouldChangeConfig && !movedToDifferentDisplay) { |
| 4911 | // Nothing significant, don't proceed with updating and reporting. |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 4912 | return null; |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4913 | } |
| 4914 | |
| 4915 | // Propagate the configuration change to ResourcesManager and Activity. |
| 4916 | |
| 4917 | // ContextThemeWrappers may override the configuration for that context. We must check and |
| 4918 | // apply any overrides defined. |
| 4919 | Configuration contextThemeWrapperOverrideConfig = activity.getOverrideConfiguration(); |
| 4920 | |
| 4921 | // We only update an Activity's configuration if this is not a global configuration change. |
| 4922 | // This must also be done before the callback, or else we violate the contract that the new |
| 4923 | // resources are available in ComponentCallbacks2#onConfigurationChanged(Configuration). |
| 4924 | // Also apply the ContextThemeWrapper override if necessary. |
| 4925 | // NOTE: Make sure the configurations are not modified, as they are treated as immutable in |
| 4926 | // many places. |
| 4927 | final Configuration finalOverrideConfig = createNewConfigAndUpdateIfNotNull( |
| 4928 | amOverrideConfig, contextThemeWrapperOverrideConfig); |
| 4929 | mResourcesManager.updateResourcesForActivity(activityToken, finalOverrideConfig, |
| 4930 | displayId, movedToDifferentDisplay); |
| 4931 | |
| 4932 | activity.mConfigChangeFlags = 0; |
| 4933 | activity.mCurrentConfig = new Configuration(newConfig); |
| 4934 | |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 4935 | // Apply the ContextThemeWrapper override if necessary. |
| 4936 | // NOTE: Make sure the configurations are not modified, as they are treated as immutable |
| 4937 | // in many places. |
| 4938 | final Configuration configToReport = createNewConfigAndUpdateIfNotNull(newConfig, |
| 4939 | contextThemeWrapperOverrideConfig); |
| 4940 | |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4941 | if (!REPORT_TO_ACTIVITY) { |
| 4942 | // Not configured to report to activity. |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 4943 | return configToReport; |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4944 | } |
| 4945 | |
| 4946 | if (movedToDifferentDisplay) { |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 4947 | activity.dispatchMovedToDisplay(displayId, configToReport); |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4948 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4949 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4950 | if (shouldChangeConfig) { |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4951 | activity.mCalled = false; |
| 4952 | activity.onConfigurationChanged(configToReport); |
| 4953 | if (!activity.mCalled) { |
| 4954 | throw new SuperNotCalledException("Activity " + activity.getLocalClassName() + |
| 4955 | " did not call through to super.onConfigurationChanged()"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4956 | } |
| 4957 | } |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 4958 | |
| 4959 | return configToReport; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4960 | } |
| 4961 | |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 4962 | public final void applyConfigurationToResources(Configuration config) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4963 | synchronized (mResourcesManager) { |
| 4964 | mResourcesManager.applyConfigurationToResourcesLocked(config, null); |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 4965 | } |
| 4966 | } |
| 4967 | |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 4968 | final Configuration applyCompatConfiguration(int displayDensity) { |
Dianne Hackborn | 836e262 | 2011-10-04 18:32:39 -0700 | [diff] [blame] | 4969 | Configuration config = mConfiguration; |
| 4970 | if (mCompatConfiguration == null) { |
| 4971 | mCompatConfiguration = new Configuration(); |
| 4972 | } |
| 4973 | mCompatConfiguration.setTo(mConfiguration); |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 4974 | if (mResourcesManager.applyCompatConfigurationLocked(displayDensity, |
| 4975 | mCompatConfiguration)) { |
Dianne Hackborn | 836e262 | 2011-10-04 18:32:39 -0700 | [diff] [blame] | 4976 | config = mCompatConfiguration; |
| 4977 | } |
| 4978 | return config; |
| 4979 | } |
| 4980 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4981 | final void handleConfigurationChanged(Configuration config, CompatibilityInfo compat) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4982 | |
Fabrice Di Meglio | 30ca5cd | 2012-05-07 17:45:44 -0700 | [diff] [blame] | 4983 | int configDiff = 0; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4984 | |
Bryce Lee | 658d984 | 2017-07-28 08:33:36 -0700 | [diff] [blame] | 4985 | // This flag tracks whether the new configuration is fundamentally equivalent to the |
| 4986 | // existing configuration. This is necessary to determine whether non-activity |
| 4987 | // callbacks should receive notice when the only changes are related to non-public fields. |
| 4988 | // We do not gate calling {@link #performActivityConfigurationChanged} based on this flag |
| 4989 | // as that method uses the same check on the activity config override as well. |
| 4990 | final boolean equivalent = config != null && mConfiguration != null |
| 4991 | && (0 == mConfiguration.diffPublicOnly(config)); |
| 4992 | |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4993 | synchronized (mResourcesManager) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4994 | if (mPendingConfiguration != null) { |
| 4995 | if (!mPendingConfiguration.isOtherSeqNewer(config)) { |
| 4996 | config = mPendingConfiguration; |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 4997 | mCurDefaultDisplayDpi = config.densityDpi; |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 4998 | updateDefaultDensity(); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4999 | } |
| 5000 | mPendingConfiguration = null; |
| 5001 | } |
| 5002 | |
| 5003 | if (config == null) { |
| 5004 | return; |
| 5005 | } |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 5006 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 5007 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Handle configuration changed: " |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5008 | + config); |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 5009 | |
| 5010 | mResourcesManager.applyConfigurationToResourcesLocked(config, compat); |
Adam Lesinski | b61e405 | 2016-05-19 18:23:05 -0700 | [diff] [blame] | 5011 | updateLocaleListFromAppContext(mInitialApplication.getApplicationContext(), |
| 5012 | mResourcesManager.getConfiguration().getLocales()); |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 5013 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5014 | if (mConfiguration == null) { |
| 5015 | mConfiguration = new Configuration(); |
| 5016 | } |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 5017 | if (!mConfiguration.isOtherSeqNewer(config) && compat == null) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5018 | return; |
| 5019 | } |
Alan Viverette | e54d245 | 2015-05-06 10:41:43 -0700 | [diff] [blame] | 5020 | |
| 5021 | configDiff = mConfiguration.updateFrom(config); |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 5022 | config = applyCompatConfiguration(mCurDefaultDisplayDpi); |
Alan Viverette | 395cd01 | 2015-08-11 17:27:04 -0400 | [diff] [blame] | 5023 | |
| 5024 | final Theme systemTheme = getSystemContext().getTheme(); |
| 5025 | if ((systemTheme.getChangingConfigurations() & configDiff) != 0) { |
| 5026 | systemTheme.rebase(); |
| 5027 | } |
Adam Lesinski | a82b626 | 2017-03-21 16:56:17 -0700 | [diff] [blame] | 5028 | |
| 5029 | final Theme systemUiTheme = getSystemUiContext().getTheme(); |
| 5030 | if ((systemUiTheme.getChangingConfigurations() & configDiff) != 0) { |
| 5031 | systemUiTheme.rebase(); |
| 5032 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5033 | } |
Dianne Hackborn | 73c1416 | 2012-09-19 15:45:06 -0700 | [diff] [blame] | 5034 | |
| 5035 | ArrayList<ComponentCallbacks2> callbacks = collectComponentCallbacks(false, config); |
| 5036 | |
Fabrice Di Meglio | 30ca5cd | 2012-05-07 17:45:44 -0700 | [diff] [blame] | 5037 | freeTextLayoutCachesIfNeeded(configDiff); |
| 5038 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5039 | if (callbacks != null) { |
| 5040 | final int N = callbacks.size(); |
| 5041 | for (int i=0; i<N; i++) { |
Andrii Kulian | 701214b | 2016-04-07 09:36:33 -0700 | [diff] [blame] | 5042 | ComponentCallbacks2 cb = callbacks.get(i); |
| 5043 | if (cb instanceof Activity) { |
| 5044 | // If callback is an Activity - call corresponding method to consider override |
| 5045 | // config and avoid onConfigurationChanged if it hasn't changed. |
| 5046 | Activity a = (Activity) cb; |
| 5047 | performConfigurationChangedForActivity(mActivities.get(a.getActivityToken()), |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5048 | config); |
Bryce Lee | 658d984 | 2017-07-28 08:33:36 -0700 | [diff] [blame] | 5049 | } else if (!equivalent) { |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5050 | performConfigurationChanged(cb, config); |
Andrii Kulian | 701214b | 2016-04-07 09:36:33 -0700 | [diff] [blame] | 5051 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5052 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5053 | } |
| 5054 | } |
| 5055 | |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 5056 | void handleApplicationInfoChanged(@NonNull final ApplicationInfo ai) { |
Adam Lesinski | d33ef56 | 2017-01-19 14:49:59 -0800 | [diff] [blame] | 5057 | // Updates triggered by package installation go through a package update |
| 5058 | // receiver. Here we try to capture ApplicationInfo changes that are |
| 5059 | // caused by other sources, such as overlays. That means we want to be as conservative |
| 5060 | // about code changes as possible. Take the diff of the old ApplicationInfo and the new |
| 5061 | // to see if anything needs to change. |
Fyodor Kupolov | b7865ce | 2017-05-05 15:08:03 -0700 | [diff] [blame] | 5062 | LoadedApk apk; |
| 5063 | LoadedApk resApk; |
| 5064 | // Update all affected loaded packages with new package information |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 5065 | synchronized (mResourcesManager) { |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 5066 | WeakReference<LoadedApk> ref = mPackages.get(ai.packageName); |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 5067 | apk = ref != null ? ref.get() : null; |
Fyodor Kupolov | b7865ce | 2017-05-05 15:08:03 -0700 | [diff] [blame] | 5068 | ref = mResourcePackages.get(ai.packageName); |
| 5069 | resApk = ref != null ? ref.get() : null; |
| 5070 | } |
| 5071 | if (apk != null) { |
| 5072 | final ArrayList<String> oldPaths = new ArrayList<>(); |
| 5073 | LoadedApk.makePaths(this, apk.getApplicationInfo(), oldPaths); |
| 5074 | apk.updateApplicationInfo(ai, oldPaths); |
| 5075 | } |
| 5076 | if (resApk != null) { |
| 5077 | final ArrayList<String> oldPaths = new ArrayList<>(); |
| 5078 | LoadedApk.makePaths(this, resApk.getApplicationInfo(), oldPaths); |
| 5079 | resApk.updateApplicationInfo(ai, oldPaths); |
| 5080 | } |
| 5081 | synchronized (mResourcesManager) { |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 5082 | // Update all affected Resources objects to use new ResourcesImpl |
| 5083 | mResourcesManager.applyNewResourceDirsLocked(ai.sourceDir, ai.resourceDirs); |
| 5084 | } |
| 5085 | |
| 5086 | ApplicationPackageManager.configurationChanged(); |
| 5087 | |
| 5088 | // Trigger a regular Configuration change event, only with a different assetsSeq number |
| 5089 | // so that we actually call through to all components. |
Adam Lesinski | a82b626 | 2017-03-21 16:56:17 -0700 | [diff] [blame] | 5090 | // TODO(adamlesinski): Change this to make use of ActivityManager's upcoming ability to |
| 5091 | // store configurations per-process. |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 5092 | Configuration newConfig = new Configuration(); |
Adam Lesinski | a82b626 | 2017-03-21 16:56:17 -0700 | [diff] [blame] | 5093 | newConfig.assetsSeq = (mConfiguration != null ? mConfiguration.assetsSeq : 0) + 1; |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 5094 | handleConfigurationChanged(newConfig, null); |
| 5095 | |
Fyodor Kupolov | cb93d6f | 2017-05-04 17:27:16 -0700 | [diff] [blame] | 5096 | requestRelaunchAllActivities(); |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 5097 | } |
| 5098 | |
Romain Guy | 46bfc48 | 2013-08-16 18:38:29 -0700 | [diff] [blame] | 5099 | static void freeTextLayoutCachesIfNeeded(int configDiff) { |
Fabrice Di Meglio | 30ca5cd | 2012-05-07 17:45:44 -0700 | [diff] [blame] | 5100 | if (configDiff != 0) { |
| 5101 | // Ask text layout engine to free its caches if there is a locale change |
| 5102 | boolean hasLocaleConfigChange = ((configDiff & ActivityInfo.CONFIG_LOCALE) != 0); |
| 5103 | if (hasLocaleConfigChange) { |
| 5104 | Canvas.freeTextLayoutCaches(); |
| 5105 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Cleared TextLayout Caches"); |
| 5106 | } |
| 5107 | } |
| 5108 | } |
| 5109 | |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5110 | /** |
| 5111 | * Handle new activity configuration and/or move to a different display. |
| 5112 | * @param data Configuration update data. |
| 5113 | * @param displayId Id of the display where activity was moved to, -1 if there was no move and |
| 5114 | * value didn't change. |
| 5115 | */ |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 5116 | void handleActivityConfigurationChanged(ActivityConfigChangeData data, int displayId) { |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 5117 | ActivityClientRecord r = mActivities.get(data.activityToken); |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5118 | // Check input params. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5119 | if (r == null || r.activity == null) { |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5120 | if (DEBUG_CONFIGURATION) Slog.w(TAG, "Not found target activity to report to: " + r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5121 | return; |
| 5122 | } |
Andrii Kulian | 51c1b67 | 2017-04-07 18:39:32 -0700 | [diff] [blame] | 5123 | final boolean movedToDifferentDisplay = displayId != INVALID_DISPLAY |
| 5124 | && displayId != r.activity.getDisplay().getDisplayId(); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 5125 | |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5126 | // Perform updates. |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 5127 | r.overrideConfig = data.overrideConfig; |
Stephen Kiazyk | f903b73 | 2017-03-20 16:23:45 -0700 | [diff] [blame] | 5128 | final ViewRootImpl viewRoot = r.activity.mDecor != null |
| 5129 | ? r.activity.mDecor.getViewRootImpl() : null; |
| 5130 | |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5131 | if (movedToDifferentDisplay) { |
| 5132 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Handle activity moved to display, activity:" |
| 5133 | + r.activityInfo.name + ", displayId=" + displayId |
| 5134 | + ", config=" + data.overrideConfig); |
| 5135 | |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 5136 | final Configuration reportedConfig = performConfigurationChangedForActivity(r, |
| 5137 | mCompatConfiguration, displayId, true /* movedToDifferentDisplay */); |
Andrii Kulian | ce1ecf1 | 2017-03-17 14:58:36 -0700 | [diff] [blame] | 5138 | if (viewRoot != null) { |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 5139 | viewRoot.onMovedToDisplay(displayId, reportedConfig); |
Andrii Kulian | ce1ecf1 | 2017-03-17 14:58:36 -0700 | [diff] [blame] | 5140 | } |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5141 | } else { |
| 5142 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Handle activity config changed: " |
| 5143 | + r.activityInfo.name + ", config=" + data.overrideConfig); |
| 5144 | performConfigurationChangedForActivity(r, mCompatConfiguration); |
| 5145 | } |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 5146 | // Notify the ViewRootImpl instance about configuration changes. It may have initiated this |
| 5147 | // update to make sure that resources are updated before updating itself. |
Andrii Kulian | ce1ecf1 | 2017-03-17 14:58:36 -0700 | [diff] [blame] | 5148 | if (viewRoot != null) { |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 5149 | viewRoot.updateConfiguration(displayId); |
Andrii Kulian | ce1ecf1 | 2017-03-17 14:58:36 -0700 | [diff] [blame] | 5150 | } |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 5151 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5152 | } |
| 5153 | |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 5154 | final void handleProfilerControl(boolean start, ProfilerInfo profilerInfo, int profileType) { |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 5155 | if (start) { |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 5156 | try { |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 5157 | switch (profileType) { |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 5158 | default: |
| 5159 | mProfiler.setProfiler(profilerInfo); |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 5160 | mProfiler.startProfiling(); |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 5161 | break; |
| 5162 | } |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 5163 | } catch (RuntimeException e) { |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 5164 | Slog.w(TAG, "Profiling failed on path " + profilerInfo.profileFile |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 5165 | + " -- can the process access this path?"); |
Dianne Hackborn | 9c8dd55 | 2009-06-23 19:22:52 -0700 | [diff] [blame] | 5166 | } finally { |
Andreas Gampe | 2b073a0 | 2017-06-22 17:28:57 -0700 | [diff] [blame] | 5167 | profilerInfo.closeFd(); |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 5168 | } |
| 5169 | } else { |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 5170 | switch (profileType) { |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 5171 | default: |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 5172 | mProfiler.stopProfiling(); |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 5173 | break; |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 5174 | } |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 5175 | } |
| 5176 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 5177 | |
Andreas Gampe | 4c79fea | 2016-01-28 20:11:41 -0800 | [diff] [blame] | 5178 | /** |
| 5179 | * Public entrypoint to stop profiling. This is required to end profiling when the app crashes, |
| 5180 | * so that profiler data won't be lost. |
| 5181 | * |
| 5182 | * @hide |
| 5183 | */ |
| 5184 | public void stopProfiling() { |
Amith Yamasani | b168443 | 2017-01-26 14:57:20 -0800 | [diff] [blame] | 5185 | if (mProfiler != null) { |
| 5186 | mProfiler.stopProfiling(); |
| 5187 | } |
Andreas Gampe | 4c79fea | 2016-01-28 20:11:41 -0800 | [diff] [blame] | 5188 | } |
| 5189 | |
Christopher Ferris | 8d652f8 | 2017-04-11 16:29:18 -0700 | [diff] [blame] | 5190 | static void handleDumpHeap(DumpHeapData dhd) { |
Makoto Onuki | 4556b7b | 2017-07-07 14:58:58 -0700 | [diff] [blame] | 5191 | if (dhd.runGc) { |
| 5192 | System.gc(); |
| 5193 | System.runFinalization(); |
| 5194 | System.gc(); |
| 5195 | } |
Christopher Ferris | 8d652f8 | 2017-04-11 16:29:18 -0700 | [diff] [blame] | 5196 | if (dhd.managed) { |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 5197 | try { |
| 5198 | Debug.dumpHprofData(dhd.path, dhd.fd.getFileDescriptor()); |
| 5199 | } catch (IOException e) { |
| 5200 | Slog.w(TAG, "Managed heap dump failed on path " + dhd.path |
| 5201 | + " -- can the process access this path?"); |
| 5202 | } finally { |
| 5203 | try { |
| 5204 | dhd.fd.close(); |
| 5205 | } catch (IOException e) { |
| 5206 | Slog.w(TAG, "Failure closing profile fd", e); |
| 5207 | } |
| 5208 | } |
Christopher Ferris | 8d652f8 | 2017-04-11 16:29:18 -0700 | [diff] [blame] | 5209 | } else if (dhd.mallocInfo) { |
| 5210 | Debug.dumpNativeMallocInfo(dhd.fd.getFileDescriptor()); |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 5211 | } else { |
Andy McFadden | 06a6b55 | 2010-07-13 16:28:09 -0700 | [diff] [blame] | 5212 | Debug.dumpNativeHeap(dhd.fd.getFileDescriptor()); |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 5213 | } |
Dianne Hackborn | b9a5e4a | 2015-03-03 17:04:12 -0800 | [diff] [blame] | 5214 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5215 | ActivityManager.getService().dumpHeapFinished(dhd.path); |
Dianne Hackborn | b9a5e4a | 2015-03-03 17:04:12 -0800 | [diff] [blame] | 5216 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5217 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | b9a5e4a | 2015-03-03 17:04:12 -0800 | [diff] [blame] | 5218 | } |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 5219 | } |
| 5220 | |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 5221 | final void handleDispatchPackageBroadcast(int cmd, String[] packages) { |
| 5222 | boolean hasPkgInfo = false; |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5223 | switch (cmd) { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 5224 | case ApplicationThreadConstants.PACKAGE_REMOVED: |
| 5225 | case ApplicationThreadConstants.PACKAGE_REMOVED_DONT_KILL: |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5226 | { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 5227 | final boolean killApp = cmd == ApplicationThreadConstants.PACKAGE_REMOVED; |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5228 | if (packages == null) { |
| 5229 | break; |
| 5230 | } |
| 5231 | synchronized (mResourcesManager) { |
| 5232 | for (int i = packages.length - 1; i >= 0; i--) { |
| 5233 | if (!hasPkgInfo) { |
| 5234 | WeakReference<LoadedApk> ref = mPackages.get(packages[i]); |
| 5235 | if (ref != null && ref.get() != null) { |
| 5236 | hasPkgInfo = true; |
| 5237 | } else { |
| 5238 | ref = mResourcePackages.get(packages[i]); |
| 5239 | if (ref != null && ref.get() != null) { |
| 5240 | hasPkgInfo = true; |
| 5241 | } |
| 5242 | } |
| 5243 | } |
| 5244 | if (killApp) { |
| 5245 | mPackages.remove(packages[i]); |
| 5246 | mResourcePackages.remove(packages[i]); |
| 5247 | } |
| 5248 | } |
| 5249 | } |
| 5250 | break; |
| 5251 | } |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 5252 | case ApplicationThreadConstants.PACKAGE_REPLACED: |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5253 | { |
| 5254 | if (packages == null) { |
| 5255 | break; |
| 5256 | } |
| 5257 | synchronized (mResourcesManager) { |
| 5258 | for (int i = packages.length - 1; i >= 0; i--) { |
| 5259 | WeakReference<LoadedApk> ref = mPackages.get(packages[i]); |
| 5260 | LoadedApk pkgInfo = ref != null ? ref.get() : null; |
| 5261 | if (pkgInfo != null) { |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 5262 | hasPkgInfo = true; |
mark_chen | 89764e3 | 2014-12-12 15:38:48 +0800 | [diff] [blame] | 5263 | } else { |
| 5264 | ref = mResourcePackages.get(packages[i]); |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5265 | pkgInfo = ref != null ? ref.get() : null; |
| 5266 | if (pkgInfo != null) { |
mark_chen | 89764e3 | 2014-12-12 15:38:48 +0800 | [diff] [blame] | 5267 | hasPkgInfo = true; |
| 5268 | } |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 5269 | } |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5270 | // If the package is being replaced, yet it still has a valid |
| 5271 | // LoadedApk object, the package was updated with _DONT_KILL. |
| 5272 | // Adjust it's internal references to the application info and |
| 5273 | // resources. |
| 5274 | if (pkgInfo != null) { |
| 5275 | try { |
| 5276 | final String packageName = packages[i]; |
| 5277 | final ApplicationInfo aInfo = |
| 5278 | sPackageManager.getApplicationInfo( |
| 5279 | packageName, |
| 5280 | 0 /*flags*/, |
| 5281 | UserHandle.myUserId()); |
| 5282 | |
| 5283 | if (mActivities.size() > 0) { |
| 5284 | for (ActivityClientRecord ar : mActivities.values()) { |
| 5285 | if (ar.activityInfo.applicationInfo.packageName |
| 5286 | .equals(packageName)) { |
| 5287 | ar.activityInfo.applicationInfo = aInfo; |
| 5288 | ar.packageInfo = pkgInfo; |
| 5289 | } |
| 5290 | } |
| 5291 | } |
| 5292 | final List<String> oldPaths = |
| 5293 | sPackageManager.getPreviousCodePaths(packageName); |
| 5294 | pkgInfo.updateApplicationInfo(aInfo, oldPaths); |
| 5295 | } catch (RemoteException e) { |
| 5296 | } |
| 5297 | } |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 5298 | } |
| 5299 | } |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5300 | break; |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 5301 | } |
| 5302 | } |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5303 | ApplicationPackageManager.handlePackageBroadcast(cmd, packages, hasPkgInfo); |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 5304 | } |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 5305 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5306 | final void handleLowMemory() { |
Dianne Hackborn | 73c1416 | 2012-09-19 15:45:06 -0700 | [diff] [blame] | 5307 | ArrayList<ComponentCallbacks2> callbacks = collectComponentCallbacks(true, null); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 5308 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5309 | final int N = callbacks.size(); |
| 5310 | for (int i=0; i<N; i++) { |
| 5311 | callbacks.get(i).onLowMemory(); |
| 5312 | } |
| 5313 | |
Chris Tate | ce22905 | 2009-03-25 16:44:52 -0700 | [diff] [blame] | 5314 | // Ask SQLite to free up as much memory as it can, mostly from its page caches. |
| 5315 | if (Process.myUid() != Process.SYSTEM_UID) { |
| 5316 | int sqliteReleased = SQLiteDatabase.releaseMemory(); |
| 5317 | EventLog.writeEvent(SQLITE_MEM_RELEASED_EVENT_LOG_TAG, sqliteReleased); |
| 5318 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 5319 | |
Mike Reed | caf0df1 | 2009-04-27 14:32:05 -0400 | [diff] [blame] | 5320 | // Ask graphics to free up as much as possible (font/image caches) |
| 5321 | Canvas.freeCaches(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5322 | |
Fabrice Di Meglio | 30ca5cd | 2012-05-07 17:45:44 -0700 | [diff] [blame] | 5323 | // Ask text layout engine to free also as much as possible |
| 5324 | Canvas.freeTextLayoutCaches(); |
| 5325 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5326 | BinderInternal.forceGc("mem"); |
| 5327 | } |
| 5328 | |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 5329 | final void handleTrimMemory(int level) { |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 5330 | if (DEBUG_MEMORY_TRIM) Slog.v(TAG, "Trimming memory to level: " + level); |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 5331 | |
Dianne Hackborn | 73c1416 | 2012-09-19 15:45:06 -0700 | [diff] [blame] | 5332 | ArrayList<ComponentCallbacks2> callbacks = collectComponentCallbacks(true, null); |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 5333 | |
| 5334 | final int N = callbacks.size(); |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 5335 | for (int i = 0; i < N; i++) { |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 5336 | callbacks.get(i).onTrimMemory(level); |
| 5337 | } |
Romain Guy | 19f86e8 | 2012-04-23 15:19:07 -0700 | [diff] [blame] | 5338 | |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 5339 | WindowManagerGlobal.getInstance().trimMemory(level); |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 5340 | } |
| 5341 | |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 5342 | private void setupGraphicsSupport(Context context) { |
Andreas Gampe | 4c8e542 | 2016-05-18 11:58:47 -0700 | [diff] [blame] | 5343 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "setupGraphicsSupport"); |
Romain Guy | a958265 | 2011-11-10 14:20:10 -0800 | [diff] [blame] | 5344 | |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 5345 | // The system package doesn't have real data directories, so don't set up cache paths. |
| 5346 | if (!"android".equals(context.getPackageName())) { |
| 5347 | // This cache location probably points at credential-encrypted |
| 5348 | // storage which may not be accessible yet; assign it anyway instead |
| 5349 | // of pointing at device-encrypted storage. |
| 5350 | final File cacheDir = context.getCacheDir(); |
| 5351 | if (cacheDir != null) { |
| 5352 | // Provide a usable directory for temporary files |
| 5353 | System.setProperty("java.io.tmpdir", cacheDir.getAbsolutePath()); |
| 5354 | } else { |
| 5355 | Log.v(TAG, "Unable to initialize \"java.io.tmpdir\" property " |
| 5356 | + "due to missing cache directory"); |
Romain Guy | a958265 | 2011-11-10 14:20:10 -0800 | [diff] [blame] | 5357 | } |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 5358 | |
| 5359 | // Setup a location to store generated/compiled graphics code. |
| 5360 | final Context deviceContext = context.createDeviceProtectedStorageContext(); |
| 5361 | final File codeCacheDir = deviceContext.getCodeCacheDir(); |
| 5362 | if (codeCacheDir != null) { |
| 5363 | try { |
| 5364 | int uid = Process.myUid(); |
| 5365 | String[] packages = getPackageManager().getPackagesForUid(uid); |
| 5366 | if (packages != null) { |
Romain Guy | cecbe07 | 2017-07-18 15:42:06 -0700 | [diff] [blame] | 5367 | ThreadedRenderer.setupDiskCache(codeCacheDir); |
| 5368 | RenderScriptCacheDir.setupDiskCache(codeCacheDir); |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 5369 | } |
| 5370 | } catch (RemoteException e) { |
| 5371 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
| 5372 | throw e.rethrowFromSystemServer(); |
| 5373 | } |
| 5374 | } else { |
| 5375 | Log.w(TAG, "Unable to use shader/script cache: missing code-cache directory"); |
| 5376 | } |
Romain Guy | a958265 | 2011-11-10 14:20:10 -0800 | [diff] [blame] | 5377 | } |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 5378 | |
Jesse Hall | c37984f | 2017-05-23 16:55:08 -0700 | [diff] [blame] | 5379 | GraphicsEnvironment.chooseDriver(context); |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 5380 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 5381 | } |
| 5382 | |
| 5383 | private void updateDefaultDensity() { |
Alan Viverette | 2ac46f1 | 2016-02-04 16:58:14 -0500 | [diff] [blame] | 5384 | final int densityDpi = mCurDefaultDisplayDpi; |
| 5385 | if (!mDensityCompatMode |
| 5386 | && densityDpi != Configuration.DENSITY_DPI_UNDEFINED |
| 5387 | && densityDpi != DisplayMetrics.DENSITY_DEVICE) { |
| 5388 | DisplayMetrics.DENSITY_DEVICE = densityDpi; |
| 5389 | Bitmap.setDefaultDensity(densityDpi); |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 5390 | } |
| 5391 | } |
| 5392 | |
Todd Kennedy | e713efc | 2016-05-10 13:45:40 -0700 | [diff] [blame] | 5393 | /** |
| 5394 | * Returns the correct library directory for the current ABI. |
| 5395 | * <p> |
| 5396 | * If we're dealing with a multi-arch application that has both 32 and 64 bit shared |
| 5397 | * libraries, we might need to choose the secondary depending on what the current |
| 5398 | * runtime's instruction set is. |
| 5399 | */ |
| 5400 | private String getInstrumentationLibrary(ApplicationInfo appInfo, InstrumentationInfo insInfo) { |
| 5401 | if (appInfo.primaryCpuAbi != null && appInfo.secondaryCpuAbi != null) { |
| 5402 | // Get the instruction set supported by the secondary ABI. In the presence |
| 5403 | // of a native bridge this might be different than the one secondary ABI used. |
| 5404 | String secondaryIsa = |
| 5405 | VMRuntime.getInstructionSet(appInfo.secondaryCpuAbi); |
| 5406 | final String secondaryDexCodeIsa = |
| 5407 | SystemProperties.get("ro.dalvik.vm.isa." + secondaryIsa); |
| 5408 | secondaryIsa = secondaryDexCodeIsa.isEmpty() ? secondaryIsa : secondaryDexCodeIsa; |
| 5409 | |
| 5410 | final String runtimeIsa = VMRuntime.getRuntime().vmInstructionSet(); |
| 5411 | if (runtimeIsa.equals(secondaryIsa)) { |
| 5412 | return insInfo.secondaryNativeLibraryDir; |
| 5413 | } |
| 5414 | } |
| 5415 | return insInfo.nativeLibraryDir; |
| 5416 | } |
| 5417 | |
Adam Lesinski | b61e405 | 2016-05-19 18:23:05 -0700 | [diff] [blame] | 5418 | /** |
| 5419 | * The LocaleList set for the app's resources may have been shuffled so that the preferred |
| 5420 | * Locale is at position 0. We must find the index of this preferred Locale in the |
| 5421 | * original LocaleList. |
| 5422 | */ |
| 5423 | private void updateLocaleListFromAppContext(Context context, LocaleList newLocaleList) { |
| 5424 | final Locale bestLocale = context.getResources().getConfiguration().getLocales().get(0); |
| 5425 | final int newLocaleListSize = newLocaleList.size(); |
| 5426 | for (int i = 0; i < newLocaleListSize; i++) { |
| 5427 | if (bestLocale.equals(newLocaleList.get(i))) { |
| 5428 | LocaleList.setDefault(newLocaleList, i); |
| 5429 | return; |
| 5430 | } |
| 5431 | } |
Adam Lesinski | 27d3016 | 2016-05-25 16:45:14 -0700 | [diff] [blame] | 5432 | |
| 5433 | // The app may have overridden the LocaleList with its own Locale |
| 5434 | // (not present in the available list). Push the chosen Locale |
| 5435 | // to the front of the list. |
| 5436 | LocaleList.setDefault(new LocaleList(bestLocale, newLocaleList)); |
Adam Lesinski | b61e405 | 2016-05-19 18:23:05 -0700 | [diff] [blame] | 5437 | } |
| 5438 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 5439 | private void handleBindApplication(AppBindData data) { |
Calin Juravle | 8f5770d | 2016-04-12 14:12:04 +0100 | [diff] [blame] | 5440 | // Register the UI Thread as a sensitive thread to the runtime. |
| 5441 | VMRuntime.registerSensitiveThread(); |
Man Cao | cfa78b2 | 2015-06-11 20:14:34 -0700 | [diff] [blame] | 5442 | if (data.trackAllocation) { |
| 5443 | DdmVmInternal.enableRecentAllocations(true); |
| 5444 | } |
| 5445 | |
Dianne Hackborn | d98885c | 2016-03-01 17:13:03 -0800 | [diff] [blame] | 5446 | // Note when this process has started. |
| 5447 | Process.setStartTimes(SystemClock.elapsedRealtime(), SystemClock.uptimeMillis()); |
| 5448 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5449 | mBoundApplication = data; |
| 5450 | mConfiguration = new Configuration(data.config); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 5451 | mCompatConfiguration = new Configuration(data.config); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5452 | |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 5453 | mProfiler = new Profiler(); |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 5454 | if (data.initProfilerInfo != null) { |
| 5455 | mProfiler.profileFile = data.initProfilerInfo.profileFile; |
| 5456 | mProfiler.profileFd = data.initProfilerInfo.profileFd; |
| 5457 | mProfiler.samplingInterval = data.initProfilerInfo.samplingInterval; |
| 5458 | mProfiler.autoStopProfiler = data.initProfilerInfo.autoStopProfiler; |
Shukang Zhou | 6ffd4f9 | 2017-01-25 16:07:57 -0800 | [diff] [blame] | 5459 | mProfiler.streamingOutput = data.initProfilerInfo.streamingOutput; |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 5460 | } |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 5461 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5462 | // send up app name; do this *before* waiting for debugger |
Christopher Tate | 8ee038d | 2009-11-06 11:30:20 -0800 | [diff] [blame] | 5463 | Process.setArgV0(data.processName); |
Siva Velusamy | d693dfa | 2012-09-10 14:36:58 -0700 | [diff] [blame] | 5464 | android.ddm.DdmHandleAppName.setAppName(data.processName, |
| 5465 | UserHandle.myUserId()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5466 | |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 5467 | if (mProfiler.profileFd != null) { |
| 5468 | mProfiler.startProfiling(); |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 5469 | } |
| 5470 | |
Joe Onorato | d630f10 | 2011-03-17 18:42:26 -0700 | [diff] [blame] | 5471 | // If the app is Honeycomb MR1 or earlier, switch its AsyncTask |
| 5472 | // implementation to use the pool executor. Normally, we use the |
| 5473 | // serialized executor as the default. This has to happen in the |
| 5474 | // main thread so the main looper is set right. |
Dianne Hackborn | 81e9276 | 2011-10-09 16:00:21 -0700 | [diff] [blame] | 5475 | if (data.appInfo.targetSdkVersion <= android.os.Build.VERSION_CODES.HONEYCOMB_MR1) { |
Joe Onorato | d630f10 | 2011-03-17 18:42:26 -0700 | [diff] [blame] | 5476 | AsyncTask.setDefaultExecutor(AsyncTask.THREAD_POOL_EXECUTOR); |
| 5477 | } |
| 5478 | |
Dianne Hackborn | 7895bc2 | 2014-09-05 15:09:03 -0700 | [diff] [blame] | 5479 | Message.updateCheckRecycle(data.appInfo.targetSdkVersion); |
| 5480 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5481 | /* |
| 5482 | * Before spawning a new process, reset the time zone to be the system time zone. |
| 5483 | * This needs to be done because the system time zone could have changed after the |
| 5484 | * the spawning of this process. Without doing this this process would have the incorrect |
| 5485 | * system time zone. |
| 5486 | */ |
| 5487 | TimeZone.setDefault(null); |
| 5488 | |
Adam Lesinski | b61e405 | 2016-05-19 18:23:05 -0700 | [diff] [blame] | 5489 | /* |
| 5490 | * Set the LocaleList. This may change once we create the App Context. |
| 5491 | */ |
| 5492 | LocaleList.setDefault(data.config.getLocales()); |
| 5493 | |
| 5494 | synchronized (mResourcesManager) { |
| 5495 | /* |
| 5496 | * Update the system configuration since its preloaded and might not |
| 5497 | * reflect configuration changes. The configuration object passed |
| 5498 | * in AppBindData can be safely assumed to be up to date |
| 5499 | */ |
| 5500 | mResourcesManager.applyConfigurationToResourcesLocked(data.config, data.compatInfo); |
| 5501 | mCurDefaultDisplayDpi = data.config.densityDpi; |
| 5502 | |
| 5503 | // This calls mResourcesManager so keep it within the synchronized block. |
| 5504 | applyCompatConfiguration(mCurDefaultDisplayDpi); |
| 5505 | } |
| 5506 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 5507 | data.info = getPackageInfoNoCheck(data.appInfo, data.compatInfo); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5508 | |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 5509 | /** |
| 5510 | * Switch this process to density compatibility mode if needed. |
| 5511 | */ |
| 5512 | if ((data.appInfo.flags&ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES) |
| 5513 | == 0) { |
| 5514 | mDensityCompatMode = true; |
| 5515 | Bitmap.setDefaultDensity(DisplayMetrics.DENSITY_DEFAULT); |
| 5516 | } |
| 5517 | updateDefaultDensity(); |
| 5518 | |
Neil Fuller | c66ec40 | 2016-11-14 16:06:42 +0000 | [diff] [blame] | 5519 | final String use24HourSetting = mCoreSettings.getString(Settings.System.TIME_12_24); |
| 5520 | Boolean is24Hr = null; |
| 5521 | if (use24HourSetting != null) { |
| 5522 | is24Hr = "24".equals(use24HourSetting) ? Boolean.TRUE : Boolean.FALSE; |
| 5523 | } |
| 5524 | // null : use locale default for 12/24 hour formatting, |
| 5525 | // false : use 12 hour format, |
| 5526 | // true : use 24 hour format. |
Narayan Kamath | ccb2a086 | 2013-12-19 14:49:36 +0000 | [diff] [blame] | 5527 | DateFormat.set24HourTimePref(is24Hr); |
| 5528 | |
Jon Miranda | 836c0a8 | 2014-08-11 12:32:26 -0700 | [diff] [blame] | 5529 | View.mDebugViewAttributes = |
| 5530 | mCoreSettings.getInt(Settings.Global.DEBUG_VIEW_ATTRIBUTES, 0) != 0; |
| 5531 | |
Dianne Hackborn | 96e240f | 2009-07-26 17:42:30 -0700 | [diff] [blame] | 5532 | /** |
Brad Fitzpatrick | 438d059 | 2010-06-10 12:19:19 -0700 | [diff] [blame] | 5533 | * For system applications on userdebug/eng builds, log stack |
| 5534 | * traces of disk and network access to dropbox for analysis. |
| 5535 | */ |
Brad Fitzpatrick | ad13b98 | 2010-07-14 12:35:53 -0700 | [diff] [blame] | 5536 | if ((data.appInfo.flags & |
| 5537 | (ApplicationInfo.FLAG_SYSTEM | |
Brad Fitzpatrick | 50d66f9 | 2010-09-13 21:29:05 -0700 | [diff] [blame] | 5538 | ApplicationInfo.FLAG_UPDATED_SYSTEM_APP)) != 0) { |
| 5539 | StrictMode.conditionallyEnableDebugLogging(); |
Brad Fitzpatrick | 438d059 | 2010-06-10 12:19:19 -0700 | [diff] [blame] | 5540 | } |
| 5541 | |
| 5542 | /** |
Jeff Sharkey | 344744b | 2016-01-28 19:03:30 -0700 | [diff] [blame] | 5543 | * For apps targetting Honeycomb or later, we don't allow network usage |
| 5544 | * on the main event loop / UI thread. This is what ultimately throws |
| 5545 | * {@link NetworkOnMainThreadException}. |
Brad Fitzpatrick | b6e1841 | 2010-10-28 14:50:05 -0700 | [diff] [blame] | 5546 | */ |
Jeff Sharkey | 344744b | 2016-01-28 19:03:30 -0700 | [diff] [blame] | 5547 | if (data.appInfo.targetSdkVersion >= Build.VERSION_CODES.HONEYCOMB) { |
Brad Fitzpatrick | b6e1841 | 2010-10-28 14:50:05 -0700 | [diff] [blame] | 5548 | StrictMode.enableDeathOnNetwork(); |
| 5549 | } |
| 5550 | |
Jeff Sharkey | 344744b | 2016-01-28 19:03:30 -0700 | [diff] [blame] | 5551 | /** |
| 5552 | * For apps targetting N or later, we don't allow file:// Uri exposure. |
| 5553 | * This is what ultimately throws {@link FileUriExposedException}. |
| 5554 | */ |
| 5555 | if (data.appInfo.targetSdkVersion >= Build.VERSION_CODES.N) { |
Thierry Strudel | e60b28d | 2016-02-25 02:14:16 +0000 | [diff] [blame] | 5556 | StrictMode.enableDeathOnFileUriExposure(); |
Jeff Sharkey | 344744b | 2016-01-28 19:03:30 -0700 | [diff] [blame] | 5557 | } |
| 5558 | |
Svet Ganov | 37e4327 | 2016-09-09 16:01:32 -0700 | [diff] [blame] | 5559 | // We deprecated Build.SERIAL and only apps that target pre NMR1 |
| 5560 | // SDK can see it. Since access to the serial is now behind a |
| 5561 | // permission we push down the value and here we fix it up |
| 5562 | // before any app code has been loaded. |
| 5563 | try { |
| 5564 | Field field = Build.class.getDeclaredField("SERIAL"); |
| 5565 | field.setAccessible(true); |
| 5566 | field.set(Build.class, data.buildSerial); |
| 5567 | } catch (NoSuchFieldException | IllegalAccessException e) { |
| 5568 | /* ignore */ |
| 5569 | } |
| 5570 | |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 5571 | if (data.debugMode != ApplicationThreadConstants.DEBUG_OFF) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5572 | // XXX should have option to change the port. |
| 5573 | Debug.changeDebugPort(8100); |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 5574 | if (data.debugMode == ApplicationThreadConstants.DEBUG_WAIT) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 5575 | Slog.w(TAG, "Application " + data.info.getPackageName() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5576 | + " is waiting for the debugger on port 8100..."); |
| 5577 | |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5578 | IActivityManager mgr = ActivityManager.getService(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5579 | try { |
| 5580 | mgr.showWaitingForDebugger(mAppThread, true); |
| 5581 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5582 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5583 | } |
| 5584 | |
| 5585 | Debug.waitForDebugger(); |
| 5586 | |
| 5587 | try { |
| 5588 | mgr.showWaitingForDebugger(mAppThread, false); |
| 5589 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5590 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5591 | } |
| 5592 | |
| 5593 | } else { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 5594 | Slog.w(TAG, "Application " + data.info.getPackageName() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5595 | + " can be debugged on port 8100..."); |
| 5596 | } |
| 5597 | } |
| 5598 | |
Jamie Gennis | f9c7d6b | 2013-03-25 14:18:25 -0700 | [diff] [blame] | 5599 | // Allow application-generated systrace messages if we're debuggable. |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 5600 | boolean isAppDebuggable = (data.appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0; |
| 5601 | Trace.setAppTracingAllowed(isAppDebuggable); |
| 5602 | if (isAppDebuggable && data.enableBinderTracking) { |
| 5603 | Binder.enableTracing(); |
| 5604 | } |
Jamie Gennis | f9c7d6b | 2013-03-25 14:18:25 -0700 | [diff] [blame] | 5605 | |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 5606 | /** |
| 5607 | * Initialize the default http proxy in this process for the reasons we set the time zone. |
| 5608 | */ |
Andreas Gampe | 4c8e542 | 2016-05-18 11:58:47 -0700 | [diff] [blame] | 5609 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "Setup proxies"); |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 5610 | final IBinder b = ServiceManager.getService(Context.CONNECTIVITY_SERVICE); |
Dianne Hackborn | d4d32c5 | 2011-11-08 17:33:59 -0800 | [diff] [blame] | 5611 | if (b != null) { |
| 5612 | // In pre-boot mode (doing initial launch to collect password), not |
| 5613 | // all system is up. This includes the connectivity service, so don't |
| 5614 | // crash if we can't get it. |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 5615 | final IConnectivityManager service = IConnectivityManager.Stub.asInterface(b); |
Dianne Hackborn | d4d32c5 | 2011-11-08 17:33:59 -0800 | [diff] [blame] | 5616 | try { |
Paul Jensen | cee9b51 | 2015-05-06 07:32:40 -0400 | [diff] [blame] | 5617 | final ProxyInfo proxyInfo = service.getProxyForNetwork(null); |
Jason Monk | 207900c | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 5618 | Proxy.setHttpProxySystemProperty(proxyInfo); |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5619 | } catch (RemoteException e) { |
Andreas Gampe | 4c8e542 | 2016-05-18 11:58:47 -0700 | [diff] [blame] | 5620 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5621 | throw e.rethrowFromSystemServer(); |
| 5622 | } |
Dianne Hackborn | d4d32c5 | 2011-11-08 17:33:59 -0800 | [diff] [blame] | 5623 | } |
Andreas Gampe | 4c8e542 | 2016-05-18 11:58:47 -0700 | [diff] [blame] | 5624 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 5625 | |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 5626 | // Instrumentation info affects the class loader, so load it before |
| 5627 | // setting up the app context. |
| 5628 | final InstrumentationInfo ii; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5629 | if (data.instrumentationName != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5630 | try { |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 5631 | ii = new ApplicationPackageManager(null, getPackageManager()) |
| 5632 | .getInstrumentationInfo(data.instrumentationName, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5633 | } catch (PackageManager.NameNotFoundException e) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5634 | throw new RuntimeException( |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 5635 | "Unable to find instrumentation info for: " + data.instrumentationName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5636 | } |
| 5637 | |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 5638 | mInstrumentationPackageName = ii.packageName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5639 | mInstrumentationAppDir = ii.sourceDir; |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 5640 | mInstrumentationSplitAppDirs = ii.splitSourceDirs; |
Todd Kennedy | e713efc | 2016-05-10 13:45:40 -0700 | [diff] [blame] | 5641 | mInstrumentationLibDir = getInstrumentationLibrary(data.appInfo, ii); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5642 | mInstrumentedAppDir = data.info.getAppDir(); |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 5643 | mInstrumentedSplitAppDirs = data.info.getSplitAppDirs(); |
| 5644 | mInstrumentedLibDir = data.info.getLibDir(); |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 5645 | } else { |
| 5646 | ii = null; |
| 5647 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5648 | |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 5649 | final ContextImpl appContext = ContextImpl.createAppContext(this, data.info); |
Adam Lesinski | b61e405 | 2016-05-19 18:23:05 -0700 | [diff] [blame] | 5650 | updateLocaleListFromAppContext(appContext, |
| 5651 | mResourcesManager.getConfiguration().getLocales()); |
Seigo Nonaka | c14dd78 | 2016-03-30 23:09:16 +0900 | [diff] [blame] | 5652 | |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 5653 | if (!Process.isIsolated()) { |
| 5654 | setupGraphicsSupport(appContext); |
Michael Lentine | 2ba303f | 2016-02-01 20:44:34 -0600 | [diff] [blame] | 5655 | } |
Michael Lentine | 03d8f768 | 2016-01-31 15:37:11 -0600 | [diff] [blame] | 5656 | |
Calin Juravle | 37dfc8e | 2017-03-13 19:02:32 -0700 | [diff] [blame] | 5657 | // If we use profiles, setup the dex reporter to notify package manager |
| 5658 | // of any relevant dex loads. The idle maintenance job will use the information |
| 5659 | // reported to optimize the loaded dex files. |
| 5660 | // Note that we only need one global reporter per app. |
| 5661 | // Make sure we do this before calling onCreate so that we can capture the |
| 5662 | // complete application startup. |
| 5663 | if (SystemProperties.getBoolean("dalvik.vm.usejitprofiles", false)) { |
Calin Juravle | f5a7bfc | 2017-03-13 23:30:30 -0700 | [diff] [blame] | 5664 | BaseDexClassLoader.setReporter(DexLoadReporter.getInstance()); |
Calin Juravle | 37dfc8e | 2017-03-13 19:02:32 -0700 | [diff] [blame] | 5665 | } |
| 5666 | |
Chad Brubaker | 78d4712 | 2015-11-17 22:26:58 -0800 | [diff] [blame] | 5667 | // Install the Network Security Config Provider. This must happen before the application |
| 5668 | // code is loaded to prevent issues with instances of TLS objects being created before |
| 5669 | // the provider is installed. |
Andreas Gampe | 4c8e542 | 2016-05-18 11:58:47 -0700 | [diff] [blame] | 5670 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "NetworkSecurityConfigProvider.install"); |
Chad Brubaker | 276ee96 | 2016-06-08 12:57:46 -0700 | [diff] [blame] | 5671 | NetworkSecurityConfigProvider.install(appContext); |
Andreas Gampe | 4c8e542 | 2016-05-18 11:58:47 -0700 | [diff] [blame] | 5672 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Chad Brubaker | 78d4712 | 2015-11-17 22:26:58 -0800 | [diff] [blame] | 5673 | |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 5674 | // Continue loading instrumentation. |
| 5675 | if (ii != null) { |
Alan Viverette | 346296b | 2015-09-01 13:08:05 -0400 | [diff] [blame] | 5676 | final ApplicationInfo instrApp = new ApplicationInfo(); |
Jeff Sharkey | 1544779 | 2015-11-05 16:18:51 -0800 | [diff] [blame] | 5677 | ii.copyTo(instrApp); |
Fyodor Kupolov | af38b8e | 2015-12-02 16:16:07 -0800 | [diff] [blame] | 5678 | instrApp.initForUser(UserHandle.myUserId()); |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 5679 | final LoadedApk pi = getPackageInfo(instrApp, data.compatInfo, |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 5680 | appContext.getClassLoader(), false, true, false); |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 5681 | final ContextImpl instrContext = ContextImpl.createAppContext(this, pi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5682 | |
| 5683 | try { |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 5684 | final ClassLoader cl = instrContext.getClassLoader(); |
Jason Monk | 6945710 | 2017-06-06 18:01:31 -0400 | [diff] [blame] | 5685 | mInstrumentation = instantiate(cl, data.instrumentationName.getClassName(), |
| 5686 | instrContext, Application::instantiateInstrumentation); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5687 | } catch (Exception e) { |
| 5688 | throw new RuntimeException( |
| 5689 | "Unable to instantiate instrumentation " |
| 5690 | + data.instrumentationName + ": " + e.toString(), e); |
| 5691 | } |
| 5692 | |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 5693 | final ComponentName component = new ComponentName(ii.packageName, ii.name); |
| 5694 | mInstrumentation.init(this, instrContext, appContext, component, |
| 5695 | data.instrumentationWatcher, data.instrumentationUiAutomationConnection); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5696 | |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 5697 | if (mProfiler.profileFile != null && !ii.handleProfiling |
| 5698 | && mProfiler.profileFd == null) { |
| 5699 | mProfiler.handlingProfiling = true; |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 5700 | final File file = new File(mProfiler.profileFile); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5701 | file.getParentFile().mkdirs(); |
| 5702 | Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024); |
| 5703 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5704 | } else { |
| 5705 | mInstrumentation = new Instrumentation(); |
| 5706 | } |
| 5707 | |
Dianne Hackborn | 3b81bc1 | 2011-01-15 11:50:52 -0800 | [diff] [blame] | 5708 | if ((data.appInfo.flags&ApplicationInfo.FLAG_LARGE_HEAP) != 0) { |
Dianne Hackborn | de39851 | 2011-01-18 18:45:21 -0800 | [diff] [blame] | 5709 | dalvik.system.VMRuntime.getRuntime().clearGrowthLimit(); |
Mathieu Chartier | 24cee07 | 2015-01-08 14:42:20 -0800 | [diff] [blame] | 5710 | } else { |
| 5711 | // Small heap, clamp to the current growth limit and let the heap release |
| 5712 | // pages after the growth limit to the non growth limit capacity. b/18387825 |
| 5713 | dalvik.system.VMRuntime.getRuntime().clampGrowthLimit(); |
Dianne Hackborn | 3b81bc1 | 2011-01-15 11:50:52 -0800 | [diff] [blame] | 5714 | } |
| 5715 | |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 5716 | // Allow disk access during application and provider setup. This could |
Jeff Sharkey | 7c50167 | 2012-02-28 12:08:37 -0800 | [diff] [blame] | 5717 | // block processing ordered broadcasts, but later processing would |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 5718 | // probably end up doing the same disk access. |
Kurt Nelson | 5e15436 | 2017-06-29 17:20:56 -0700 | [diff] [blame] | 5719 | Application app; |
Jeff Sharkey | 7c50167 | 2012-02-28 12:08:37 -0800 | [diff] [blame] | 5720 | final StrictMode.ThreadPolicy savedPolicy = StrictMode.allowThreadDiskWrites(); |
Kurt Nelson | 571c3f6 | 2017-07-10 11:09:04 -0700 | [diff] [blame] | 5721 | final StrictMode.ThreadPolicy writesAllowedPolicy = StrictMode.getThreadPolicy(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5722 | try { |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 5723 | // If the app is being launched for full backup or restore, bring it up in |
| 5724 | // a restricted environment with the base application class. |
Kurt Nelson | 5e15436 | 2017-06-29 17:20:56 -0700 | [diff] [blame] | 5725 | app = data.info.makeApplication(data.restrictedBackupMode, null); |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 5726 | mInitialApplication = app; |
Jeff Sharkey | 7c50167 | 2012-02-28 12:08:37 -0800 | [diff] [blame] | 5727 | |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 5728 | // don't bring up providers in restricted mode; they may depend on the |
| 5729 | // app's custom Application class |
| 5730 | if (!data.restrictedBackupMode) { |
Jeff Sharkey | 3e19589 | 2016-03-05 19:48:59 -0700 | [diff] [blame] | 5731 | if (!ArrayUtils.isEmpty(data.providers)) { |
| 5732 | installContentProviders(app, data.providers); |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 5733 | // For process that contains content providers, we want to |
| 5734 | // ensure that the JIT is enabled "at some point". |
| 5735 | mH.sendEmptyMessageDelayed(H.ENABLE_JIT, 10*1000); |
| 5736 | } |
| 5737 | } |
| 5738 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5739 | // Do this after providers, since instrumentation tests generally start their |
| 5740 | // test thread at this point, and we don't want that racing. |
| 5741 | try { |
| 5742 | mInstrumentation.onCreate(data.instrumentationArgs); |
| 5743 | } |
| 5744 | catch (Exception e) { |
| 5745 | throw new RuntimeException( |
| 5746 | "Exception thrown in onCreate() of " |
| 5747 | + data.instrumentationName + ": " + e.toString(), e); |
| 5748 | } |
Kurt Nelson | 571c3f6 | 2017-07-10 11:09:04 -0700 | [diff] [blame] | 5749 | try { |
| 5750 | mInstrumentation.callApplicationOnCreate(app); |
| 5751 | } catch (Exception e) { |
| 5752 | if (!mInstrumentation.onException(app, e)) { |
| 5753 | throw new RuntimeException( |
| 5754 | "Unable to create application " + app.getClass().getName() |
| 5755 | + ": " + e.toString(), e); |
| 5756 | } |
| 5757 | } |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 5758 | } finally { |
Kurt Nelson | 571c3f6 | 2017-07-10 11:09:04 -0700 | [diff] [blame] | 5759 | // If the app targets < O-MR1, or doesn't change the thread policy |
| 5760 | // during startup, clobber the policy to maintain behavior of b/36951662 |
| 5761 | if (data.appInfo.targetSdkVersion <= Build.VERSION_CODES.O |
| 5762 | || StrictMode.getThreadPolicy().equals(writesAllowedPolicy)) { |
| 5763 | StrictMode.setThreadPolicy(savedPolicy); |
Kurt Nelson | 5e15436 | 2017-06-29 17:20:56 -0700 | [diff] [blame] | 5764 | } |
| 5765 | } |
| 5766 | |
Clara Bayarri | 4b5a4d2 | 2017-01-27 20:15:45 +0000 | [diff] [blame] | 5767 | // Preload fonts resources |
Seigo Nonaka | 54084b6 | 2017-04-24 14:46:23 -0700 | [diff] [blame] | 5768 | FontsContract.setApplicationContextForResources(appContext); |
Clara Bayarri | 4b5a4d2 | 2017-01-27 20:15:45 +0000 | [diff] [blame] | 5769 | try { |
| 5770 | final ApplicationInfo info = |
Amith Yamasani | 336d29d | 2017-02-14 15:14:09 -0800 | [diff] [blame] | 5771 | getPackageManager().getApplicationInfo( |
Clara Bayarri | 4b5a4d2 | 2017-01-27 20:15:45 +0000 | [diff] [blame] | 5772 | data.appInfo.packageName, |
| 5773 | PackageManager.GET_META_DATA /*flags*/, |
| 5774 | UserHandle.myUserId()); |
| 5775 | if (info.metaData != null) { |
| 5776 | final int preloadedFontsResource = info.metaData.getInt( |
| 5777 | ApplicationInfo.METADATA_PRELOADED_FONTS, 0); |
| 5778 | if (preloadedFontsResource != 0) { |
| 5779 | data.info.mResources.preloadFonts(preloadedFontsResource); |
| 5780 | } |
| 5781 | } |
| 5782 | } catch (RemoteException e) { |
| 5783 | throw e.rethrowFromSystemServer(); |
| 5784 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5785 | } |
| 5786 | |
| 5787 | /*package*/ final void finishInstrumentation(int resultCode, Bundle results) { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5788 | IActivityManager am = ActivityManager.getService(); |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 5789 | if (mProfiler.profileFile != null && mProfiler.handlingProfiling |
| 5790 | && mProfiler.profileFd == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5791 | Debug.stopMethodTracing(); |
| 5792 | } |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5793 | //Slog.i(TAG, "am: " + ActivityManager.getService() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5794 | // + ", app thr: " + mAppThread); |
| 5795 | try { |
| 5796 | am.finishInstrumentation(mAppThread, resultCode, results); |
| 5797 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5798 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5799 | } |
| 5800 | } |
| 5801 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 5802 | private void installContentProviders( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5803 | Context context, List<ProviderInfo> providers) { |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 5804 | final ArrayList<ContentProviderHolder> results = new ArrayList<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5805 | |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 5806 | for (ProviderInfo cpi : providers) { |
Dianne Hackborn | 40e9f29 | 2012-11-27 19:12:23 -0800 | [diff] [blame] | 5807 | if (DEBUG_PROVIDER) { |
| 5808 | StringBuilder buf = new StringBuilder(128); |
| 5809 | buf.append("Pub "); |
| 5810 | buf.append(cpi.authority); |
| 5811 | buf.append(": "); |
| 5812 | buf.append(cpi.name); |
| 5813 | Log.i(TAG, buf.toString()); |
| 5814 | } |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 5815 | ContentProviderHolder cph = installProvider(context, null, cpi, |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5816 | false /*noisy*/, true /*noReleaseNeeded*/, true /*stable*/); |
| 5817 | if (cph != null) { |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5818 | cph.noReleaseNeeded = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5819 | results.add(cph); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5820 | } |
| 5821 | } |
| 5822 | |
| 5823 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5824 | ActivityManager.getService().publishContentProviders( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5825 | getApplicationThread(), results); |
| 5826 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5827 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5828 | } |
| 5829 | } |
| 5830 | |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 5831 | public final IContentProvider acquireProvider( |
| 5832 | Context c, String auth, int userId, boolean stable) { |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 5833 | final IContentProvider provider = acquireExistingProvider(c, auth, userId, stable); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5834 | if (provider != null) { |
| 5835 | return provider; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5836 | } |
| 5837 | |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 5838 | // There is a possible race here. Another thread may try to acquire |
| 5839 | // the same provider at the same time. When this happens, we want to ensure |
| 5840 | // that the first one wins. |
| 5841 | // Note that we cannot hold the lock while acquiring and installing the |
| 5842 | // provider since it might take a long time to run and it could also potentially |
| 5843 | // be re-entrant in the case where the provider is in the same process. |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 5844 | ContentProviderHolder holder = null; |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 5845 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5846 | holder = ActivityManager.getService().getContentProvider( |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 5847 | getApplicationThread(), auth, userId, stable); |
| 5848 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5849 | throw ex.rethrowFromSystemServer(); |
Wale Ogunwale | 67fe0a4 | 2015-04-24 14:44:54 -0700 | [diff] [blame] | 5850 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5851 | if (holder == null) { |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 5852 | 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] | 5853 | return null; |
| 5854 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5855 | |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5856 | // Install provider will increment the reference count for us, and break |
| 5857 | // any ties in the race. |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5858 | holder = installProvider(c, holder, holder.info, |
| 5859 | true /*noisy*/, holder.noReleaseNeeded, stable); |
| 5860 | return holder.provider; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5861 | } |
| 5862 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5863 | private final void incProviderRefLocked(ProviderRefCount prc, boolean stable) { |
| 5864 | if (stable) { |
| 5865 | prc.stableCount += 1; |
| 5866 | if (prc.stableCount == 1) { |
| 5867 | // We are acquiring a new stable reference on the provider. |
| 5868 | int unstableDelta; |
| 5869 | if (prc.removePending) { |
| 5870 | // We have a pending remove operation, which is holding the |
| 5871 | // last unstable reference. At this point we are converting |
| 5872 | // that unstable reference to our new stable reference. |
| 5873 | unstableDelta = -1; |
| 5874 | // Cancel the removal of the provider. |
| 5875 | if (DEBUG_PROVIDER) { |
| 5876 | Slog.v(TAG, "incProviderRef: stable " |
| 5877 | + "snatched provider from the jaws of death"); |
| 5878 | } |
| 5879 | prc.removePending = false; |
Guobin Zhang | 9e3e5266 | 2013-03-21 13:57:11 +0800 | [diff] [blame] | 5880 | // There is a race! It fails to remove the message, which |
| 5881 | // will be handled in completeRemoveProvider(). |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5882 | mH.removeMessages(H.REMOVE_PROVIDER, prc); |
| 5883 | } else { |
| 5884 | unstableDelta = 0; |
| 5885 | } |
| 5886 | try { |
| 5887 | if (DEBUG_PROVIDER) { |
| 5888 | Slog.v(TAG, "incProviderRef Now stable - " |
| 5889 | + prc.holder.info.name + ": unstableDelta=" |
| 5890 | + unstableDelta); |
| 5891 | } |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5892 | ActivityManager.getService().refContentProvider( |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5893 | prc.holder.connection, 1, unstableDelta); |
| 5894 | } catch (RemoteException e) { |
| 5895 | //do nothing content provider object is dead any way |
| 5896 | } |
| 5897 | } |
| 5898 | } else { |
| 5899 | prc.unstableCount += 1; |
| 5900 | if (prc.unstableCount == 1) { |
| 5901 | // We are acquiring a new unstable reference on the provider. |
| 5902 | if (prc.removePending) { |
| 5903 | // Oh look, we actually have a remove pending for the |
| 5904 | // provider, which is still holding the last unstable |
| 5905 | // reference. We just need to cancel that to take new |
| 5906 | // ownership of the reference. |
| 5907 | if (DEBUG_PROVIDER) { |
| 5908 | Slog.v(TAG, "incProviderRef: unstable " |
| 5909 | + "snatched provider from the jaws of death"); |
| 5910 | } |
| 5911 | prc.removePending = false; |
| 5912 | mH.removeMessages(H.REMOVE_PROVIDER, prc); |
| 5913 | } else { |
| 5914 | // First unstable ref, increment our count in the |
| 5915 | // activity manager. |
| 5916 | try { |
| 5917 | if (DEBUG_PROVIDER) { |
| 5918 | Slog.v(TAG, "incProviderRef: Now unstable - " |
| 5919 | + prc.holder.info.name); |
| 5920 | } |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5921 | ActivityManager.getService().refContentProvider( |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5922 | prc.holder.connection, 0, 1); |
| 5923 | } catch (RemoteException e) { |
| 5924 | //do nothing content provider object is dead any way |
| 5925 | } |
| 5926 | } |
| 5927 | } |
| 5928 | } |
| 5929 | } |
| 5930 | |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 5931 | public final IContentProvider acquireExistingProvider( |
| 5932 | Context c, String auth, int userId, boolean stable) { |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5933 | synchronized (mProviderMap) { |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 5934 | final ProviderKey key = new ProviderKey(auth, userId); |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 5935 | final ProviderClientRecord pr = mProviderMap.get(key); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5936 | if (pr == null) { |
| 5937 | return null; |
| 5938 | } |
| 5939 | |
| 5940 | IContentProvider provider = pr.mProvider; |
| 5941 | IBinder jBinder = provider.asBinder(); |
Dianne Hackborn | c428aae | 2012-10-03 16:38:22 -0700 | [diff] [blame] | 5942 | if (!jBinder.isBinderAlive()) { |
| 5943 | // The hosting process of the provider has died; we can't |
| 5944 | // use this one. |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 5945 | Log.i(TAG, "Acquiring provider " + auth + " for user " + userId |
Dianne Hackborn | c428aae | 2012-10-03 16:38:22 -0700 | [diff] [blame] | 5946 | + ": existing object's process dead"); |
| 5947 | handleUnstableProviderDiedLocked(jBinder, true); |
| 5948 | return null; |
| 5949 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5950 | |
| 5951 | // Only increment the ref count if we have one. If we don't then the |
| 5952 | // provider is not reference counted and never needs to be released. |
Dianne Hackborn | cca1f0e | 2010-09-26 18:34:53 -0700 | [diff] [blame] | 5953 | ProviderRefCount prc = mProviderRefCountMap.get(jBinder); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5954 | if (prc != null) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5955 | incProviderRefLocked(prc, stable); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5956 | } |
| 5957 | return provider; |
| 5958 | } |
Dianne Hackborn | cca1f0e | 2010-09-26 18:34:53 -0700 | [diff] [blame] | 5959 | } |
| 5960 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5961 | public final boolean releaseProvider(IContentProvider provider, boolean stable) { |
| 5962 | if (provider == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5963 | return false; |
| 5964 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5965 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5966 | IBinder jBinder = provider.asBinder(); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5967 | synchronized (mProviderMap) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5968 | ProviderRefCount prc = mProviderRefCountMap.get(jBinder); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5969 | if (prc == null) { |
| 5970 | // 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] | 5971 | return false; |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5972 | } |
| 5973 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5974 | boolean lastRef = false; |
| 5975 | if (stable) { |
| 5976 | if (prc.stableCount == 0) { |
| 5977 | if (DEBUG_PROVIDER) Slog.v(TAG, |
| 5978 | "releaseProvider: stable ref count already 0, how?"); |
| 5979 | return false; |
| 5980 | } |
| 5981 | prc.stableCount -= 1; |
| 5982 | if (prc.stableCount == 0) { |
| 5983 | // What we do at this point depends on whether there are |
| 5984 | // any unstable refs left: if there are, we just tell the |
| 5985 | // activity manager to decrement its stable count; if there |
| 5986 | // aren't, we need to enqueue this provider to be removed, |
| 5987 | // and convert to holding a single unstable ref while |
| 5988 | // doing so. |
| 5989 | lastRef = prc.unstableCount == 0; |
| 5990 | try { |
| 5991 | if (DEBUG_PROVIDER) { |
| 5992 | Slog.v(TAG, "releaseProvider: No longer stable w/lastRef=" |
| 5993 | + lastRef + " - " + prc.holder.info.name); |
| 5994 | } |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5995 | ActivityManager.getService().refContentProvider( |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5996 | prc.holder.connection, -1, lastRef ? 1 : 0); |
| 5997 | } catch (RemoteException e) { |
| 5998 | //do nothing content provider object is dead any way |
| 5999 | } |
| 6000 | } |
| 6001 | } else { |
| 6002 | if (prc.unstableCount == 0) { |
| 6003 | if (DEBUG_PROVIDER) Slog.v(TAG, |
| 6004 | "releaseProvider: unstable ref count already 0, how?"); |
| 6005 | return false; |
| 6006 | } |
| 6007 | prc.unstableCount -= 1; |
| 6008 | if (prc.unstableCount == 0) { |
| 6009 | // If this is the last reference, we need to enqueue |
| 6010 | // this provider to be removed instead of telling the |
| 6011 | // activity manager to remove it at this point. |
| 6012 | lastRef = prc.stableCount == 0; |
| 6013 | if (!lastRef) { |
| 6014 | try { |
| 6015 | if (DEBUG_PROVIDER) { |
| 6016 | Slog.v(TAG, "releaseProvider: No longer unstable - " |
| 6017 | + prc.holder.info.name); |
| 6018 | } |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6019 | ActivityManager.getService().refContentProvider( |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6020 | prc.holder.connection, 0, -1); |
| 6021 | } catch (RemoteException e) { |
| 6022 | //do nothing content provider object is dead any way |
| 6023 | } |
| 6024 | } |
| 6025 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6026 | } |
| 6027 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6028 | if (lastRef) { |
| 6029 | if (!prc.removePending) { |
| 6030 | // Schedule the actual remove asynchronously, since we don't know the context |
| 6031 | // this will be called in. |
| 6032 | // TODO: it would be nice to post a delayed message, so |
| 6033 | // if we come back and need the same provider quickly |
| 6034 | // we will still have it available. |
| 6035 | if (DEBUG_PROVIDER) { |
| 6036 | Slog.v(TAG, "releaseProvider: Enqueueing pending removal - " |
| 6037 | + prc.holder.info.name); |
| 6038 | } |
| 6039 | prc.removePending = true; |
| 6040 | Message msg = mH.obtainMessage(H.REMOVE_PROVIDER, prc); |
| 6041 | mH.sendMessage(msg); |
| 6042 | } else { |
| 6043 | Slog.w(TAG, "Duplicate remove pending of provider " + prc.holder.info.name); |
| 6044 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6045 | } |
| 6046 | return true; |
| 6047 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6048 | } |
| 6049 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6050 | final void completeRemoveProvider(ProviderRefCount prc) { |
| 6051 | synchronized (mProviderMap) { |
| 6052 | if (!prc.removePending) { |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6053 | // There was a race! Some other client managed to acquire |
| 6054 | // the provider before the removal was completed. |
| 6055 | // Abort the removal. We will do it later. |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6056 | if (DEBUG_PROVIDER) Slog.v(TAG, "completeRemoveProvider: lost the race, " |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6057 | + "provider still in use"); |
| 6058 | return; |
| 6059 | } |
| 6060 | |
Guobin Zhang | 9e3e5266 | 2013-03-21 13:57:11 +0800 | [diff] [blame] | 6061 | // More complicated race!! Some client managed to acquire the |
| 6062 | // provider and release it before the removal was completed. |
| 6063 | // Continue the removal, and abort the next remove message. |
| 6064 | prc.removePending = false; |
| 6065 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6066 | final IBinder jBinder = prc.holder.provider.asBinder(); |
| 6067 | ProviderRefCount existingPrc = mProviderRefCountMap.get(jBinder); |
| 6068 | if (existingPrc == prc) { |
| 6069 | mProviderRefCountMap.remove(jBinder); |
| 6070 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6071 | |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 6072 | for (int i=mProviderMap.size()-1; i>=0; i--) { |
| 6073 | ProviderClientRecord pr = mProviderMap.valueAt(i); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6074 | IBinder myBinder = pr.mProvider.asBinder(); |
| 6075 | if (myBinder == jBinder) { |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 6076 | mProviderMap.removeAt(i); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6077 | } |
| 6078 | } |
| 6079 | } |
| 6080 | |
| 6081 | try { |
| 6082 | if (DEBUG_PROVIDER) { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6083 | Slog.v(TAG, "removeProvider: Invoking ActivityManagerService." |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6084 | + "removeContentProvider(" + prc.holder.info.name + ")"); |
| 6085 | } |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6086 | ActivityManager.getService().removeContentProvider( |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6087 | prc.holder.connection, false); |
| 6088 | } catch (RemoteException e) { |
| 6089 | //do nothing content provider object is dead any way |
| 6090 | } |
| 6091 | } |
| 6092 | |
| 6093 | final void handleUnstableProviderDied(IBinder provider, boolean fromClient) { |
Dianne Hackborn | c428aae | 2012-10-03 16:38:22 -0700 | [diff] [blame] | 6094 | synchronized (mProviderMap) { |
| 6095 | handleUnstableProviderDiedLocked(provider, fromClient); |
| 6096 | } |
| 6097 | } |
| 6098 | |
| 6099 | final void handleUnstableProviderDiedLocked(IBinder provider, boolean fromClient) { |
| 6100 | ProviderRefCount prc = mProviderRefCountMap.get(provider); |
| 6101 | if (prc != null) { |
| 6102 | if (DEBUG_PROVIDER) Slog.v(TAG, "Cleaning up dead provider " |
| 6103 | + provider + " " + prc.holder.info.name); |
| 6104 | mProviderRefCountMap.remove(provider); |
You Kim | bc74de6 | 2013-10-01 00:13:26 +0900 | [diff] [blame] | 6105 | for (int i=mProviderMap.size()-1; i>=0; i--) { |
| 6106 | ProviderClientRecord pr = mProviderMap.valueAt(i); |
| 6107 | if (pr != null && pr.mProvider.asBinder() == provider) { |
| 6108 | Slog.i(TAG, "Removing dead content provider:" + pr.mProvider.toString()); |
| 6109 | mProviderMap.removeAt(i); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6110 | } |
Dianne Hackborn | c428aae | 2012-10-03 16:38:22 -0700 | [diff] [blame] | 6111 | } |
You Kim | bc74de6 | 2013-10-01 00:13:26 +0900 | [diff] [blame] | 6112 | |
Dianne Hackborn | c428aae | 2012-10-03 16:38:22 -0700 | [diff] [blame] | 6113 | if (fromClient) { |
| 6114 | // We found out about this due to execution in our client |
| 6115 | // code. Tell the activity manager about it now, to ensure |
| 6116 | // that the next time we go to do anything with the provider |
| 6117 | // it knows it is dead (so we don't race with its death |
| 6118 | // notification). |
| 6119 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6120 | ActivityManager.getService().unstableProviderDied( |
Dianne Hackborn | c428aae | 2012-10-03 16:38:22 -0700 | [diff] [blame] | 6121 | prc.holder.connection); |
| 6122 | } catch (RemoteException e) { |
| 6123 | //do nothing content provider object is dead any way |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6124 | } |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 6125 | } |
| 6126 | } |
| 6127 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6128 | |
Jeff Sharkey | 7aa7601 | 2013-09-30 14:26:27 -0700 | [diff] [blame] | 6129 | final void appNotRespondingViaProvider(IBinder provider) { |
| 6130 | synchronized (mProviderMap) { |
| 6131 | ProviderRefCount prc = mProviderRefCountMap.get(provider); |
| 6132 | if (prc != null) { |
| 6133 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6134 | ActivityManager.getService() |
Jeff Sharkey | 7aa7601 | 2013-09-30 14:26:27 -0700 | [diff] [blame] | 6135 | .appNotRespondingViaProvider(prc.holder.connection); |
| 6136 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 6137 | throw e.rethrowFromSystemServer(); |
Jeff Sharkey | 7aa7601 | 2013-09-30 14:26:27 -0700 | [diff] [blame] | 6138 | } |
| 6139 | } |
| 6140 | } |
| 6141 | } |
| 6142 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6143 | private ProviderClientRecord installProviderAuthoritiesLocked(IContentProvider provider, |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 6144 | ContentProvider localProvider, ContentProviderHolder holder) { |
Andreas Gampe | 18e99c1 | 2015-03-06 15:29:06 -0800 | [diff] [blame] | 6145 | final String auths[] = holder.info.authority.split(";"); |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 6146 | final int userId = UserHandle.getUserId(holder.info.applicationInfo.uid); |
| 6147 | |
Jeff Sharkey | 0a17db1 | 2016-11-04 11:23:46 -0600 | [diff] [blame] | 6148 | if (provider != null) { |
| 6149 | // If this provider is hosted by the core OS and cannot be upgraded, |
| 6150 | // then I guess we're okay doing blocking calls to it. |
| 6151 | for (String auth : auths) { |
| 6152 | switch (auth) { |
| 6153 | case ContactsContract.AUTHORITY: |
| 6154 | case CallLog.AUTHORITY: |
| 6155 | case CallLog.SHADOW_AUTHORITY: |
| 6156 | case BlockedNumberContract.AUTHORITY: |
| 6157 | case CalendarContract.AUTHORITY: |
| 6158 | case Downloads.Impl.AUTHORITY: |
Jeff Sharkey | cb62162 | 2016-11-11 14:04:32 -0700 | [diff] [blame] | 6159 | case "telephony": |
Jeff Sharkey | 0a17db1 | 2016-11-04 11:23:46 -0600 | [diff] [blame] | 6160 | Binder.allowBlocking(provider.asBinder()); |
| 6161 | } |
| 6162 | } |
| 6163 | } |
| 6164 | |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 6165 | final ProviderClientRecord pcr = new ProviderClientRecord( |
| 6166 | auths, provider, localProvider, holder); |
| 6167 | for (String auth : auths) { |
| 6168 | final ProviderKey key = new ProviderKey(auth, userId); |
| 6169 | final ProviderClientRecord existing = mProviderMap.get(key); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6170 | if (existing != null) { |
| 6171 | Slog.w(TAG, "Content provider " + pcr.mHolder.info.name |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 6172 | + " already published as " + auth); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6173 | } else { |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 6174 | mProviderMap.put(key, pcr); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6175 | } |
| 6176 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6177 | return pcr; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6178 | } |
| 6179 | |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6180 | /** |
| 6181 | * Installs the provider. |
| 6182 | * |
| 6183 | * Providers that are local to the process or that come from the system server |
| 6184 | * may be installed permanently which is indicated by setting noReleaseNeeded to true. |
| 6185 | * Other remote providers are reference counted. The initial reference count |
| 6186 | * for all reference counted providers is one. Providers that are not reference |
| 6187 | * counted do not have a reference count (at all). |
| 6188 | * |
| 6189 | * This method detects when a provider has already been installed. When this happens, |
| 6190 | * it increments the reference count of the existing provider (if appropriate) |
| 6191 | * and returns the existing provider. This can happen due to concurrent |
| 6192 | * attempts to acquire the same provider. |
| 6193 | */ |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 6194 | private ContentProviderHolder installProvider(Context context, |
| 6195 | ContentProviderHolder holder, ProviderInfo info, |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6196 | boolean noisy, boolean noReleaseNeeded, boolean stable) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6197 | ContentProvider localProvider = null; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6198 | IContentProvider provider; |
Dianne Hackborn | 5f48fca | 2012-05-30 11:06:31 -0700 | [diff] [blame] | 6199 | if (holder == null || holder.provider == null) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6200 | if (DEBUG_PROVIDER || noisy) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 6201 | Slog.d(TAG, "Loading provider " + info.authority + ": " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6202 | + info.name); |
| 6203 | } |
| 6204 | Context c = null; |
| 6205 | ApplicationInfo ai = info.applicationInfo; |
| 6206 | if (context.getPackageName().equals(ai.packageName)) { |
| 6207 | c = context; |
| 6208 | } else if (mInitialApplication != null && |
| 6209 | mInitialApplication.getPackageName().equals(ai.packageName)) { |
| 6210 | c = mInitialApplication; |
| 6211 | } else { |
| 6212 | try { |
| 6213 | c = context.createPackageContext(ai.packageName, |
| 6214 | Context.CONTEXT_INCLUDE_CODE); |
| 6215 | } catch (PackageManager.NameNotFoundException e) { |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 6216 | // Ignore |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6217 | } |
| 6218 | } |
| 6219 | if (c == null) { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 6220 | Slog.w(TAG, "Unable to get context for package " + |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6221 | ai.packageName + |
| 6222 | " while loading content provider " + |
| 6223 | info.name); |
| 6224 | return null; |
| 6225 | } |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 6226 | |
| 6227 | if (info.splitName != null) { |
| 6228 | try { |
| 6229 | c = c.createContextForSplit(info.splitName); |
| 6230 | } catch (NameNotFoundException e) { |
| 6231 | throw new RuntimeException(e); |
| 6232 | } |
| 6233 | } |
| 6234 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6235 | try { |
| 6236 | final java.lang.ClassLoader cl = c.getClassLoader(); |
Jason Monk | 6945710 | 2017-06-06 18:01:31 -0400 | [diff] [blame] | 6237 | localProvider = instantiate(cl, info.name, context, |
| 6238 | Application::instantiateProvider); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6239 | provider = localProvider.getIContentProvider(); |
| 6240 | if (provider == null) { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 6241 | Slog.e(TAG, "Failed to instantiate class " + |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6242 | info.name + " from sourceDir " + |
| 6243 | info.applicationInfo.sourceDir); |
| 6244 | return null; |
| 6245 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6246 | if (DEBUG_PROVIDER) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6247 | TAG, "Instantiating local provider " + info.name); |
| 6248 | // XXX Need to create the correct context for this provider. |
| 6249 | localProvider.attachInfo(c, info); |
| 6250 | } catch (java.lang.Exception e) { |
| 6251 | if (!mInstrumentation.onException(null, e)) { |
| 6252 | throw new RuntimeException( |
| 6253 | "Unable to get provider " + info.name |
| 6254 | + ": " + e.toString(), e); |
| 6255 | } |
| 6256 | return null; |
| 6257 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6258 | } else { |
| 6259 | provider = holder.provider; |
| 6260 | 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] | 6261 | + info.name); |
| 6262 | } |
| 6263 | |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 6264 | ContentProviderHolder retHolder; |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6265 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6266 | synchronized (mProviderMap) { |
| 6267 | if (DEBUG_PROVIDER) Slog.v(TAG, "Checking to add " + provider |
| 6268 | + " / " + info.name); |
| 6269 | IBinder jBinder = provider.asBinder(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6270 | if (localProvider != null) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6271 | ComponentName cname = new ComponentName(info.packageName, info.name); |
| 6272 | ProviderClientRecord pr = mLocalProvidersByName.get(cname); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6273 | if (pr != null) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6274 | if (DEBUG_PROVIDER) { |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6275 | Slog.v(TAG, "installProvider: lost the race, " |
| 6276 | + "using existing local provider"); |
| 6277 | } |
| 6278 | provider = pr.mProvider; |
| 6279 | } else { |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 6280 | holder = new ContentProviderHolder(info); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6281 | holder.provider = provider; |
| 6282 | holder.noReleaseNeeded = true; |
| 6283 | pr = installProviderAuthoritiesLocked(provider, localProvider, holder); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6284 | mLocalProviders.put(jBinder, pr); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6285 | mLocalProvidersByName.put(cname, pr); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6286 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6287 | retHolder = pr.mHolder; |
| 6288 | } else { |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6289 | ProviderRefCount prc = mProviderRefCountMap.get(jBinder); |
| 6290 | if (prc != null) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6291 | if (DEBUG_PROVIDER) { |
| 6292 | Slog.v(TAG, "installProvider: lost the race, updating ref count"); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6293 | } |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 6294 | // We need to transfer our new reference to the existing |
| 6295 | // ref count, releasing the old one... but only if |
| 6296 | // release is needed (that is, it is not running in the |
| 6297 | // system process). |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6298 | if (!noReleaseNeeded) { |
| 6299 | incProviderRefLocked(prc, stable); |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 6300 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6301 | ActivityManager.getService().removeContentProvider( |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 6302 | holder.connection, stable); |
| 6303 | } catch (RemoteException e) { |
| 6304 | //do nothing content provider object is dead any way |
| 6305 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6306 | } |
| 6307 | } else { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6308 | ProviderClientRecord client = installProviderAuthoritiesLocked( |
| 6309 | provider, localProvider, holder); |
| 6310 | if (noReleaseNeeded) { |
| 6311 | prc = new ProviderRefCount(holder, client, 1000, 1000); |
| 6312 | } else { |
| 6313 | prc = stable |
| 6314 | ? new ProviderRefCount(holder, client, 1, 0) |
| 6315 | : new ProviderRefCount(holder, client, 0, 1); |
| 6316 | } |
| 6317 | mProviderRefCountMap.put(jBinder, prc); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6318 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6319 | retHolder = prc.holder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6320 | } |
| 6321 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6322 | return retHolder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6323 | } |
| 6324 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 6325 | private void attach(boolean system) { |
Jeff Sharkey | 66a017b | 2013-01-17 18:18:22 -0800 | [diff] [blame] | 6326 | sCurrentActivityThread = this; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6327 | mSystemThread = system; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6328 | if (!system) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 6329 | ViewRootImpl.addFirstDrawHandler(new Runnable() { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 6330 | @Override |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 6331 | public void run() { |
| 6332 | ensureJitEnabled(); |
| 6333 | } |
| 6334 | }); |
Siva Velusamy | d693dfa | 2012-09-10 14:36:58 -0700 | [diff] [blame] | 6335 | android.ddm.DdmHandleAppName.setAppName("<pre-initialized>", |
| 6336 | UserHandle.myUserId()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6337 | RuntimeInit.setApplicationObject(mAppThread.asBinder()); |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6338 | final IActivityManager mgr = ActivityManager.getService(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6339 | try { |
| 6340 | mgr.attachApplication(mAppThread); |
| 6341 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 6342 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6343 | } |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 6344 | // Watch for getting close to heap limit. |
| 6345 | BinderInternal.addGcWatcher(new Runnable() { |
| 6346 | @Override public void run() { |
| 6347 | if (!mSomeActivitiesChanged) { |
| 6348 | return; |
| 6349 | } |
| 6350 | Runtime runtime = Runtime.getRuntime(); |
| 6351 | long dalvikMax = runtime.maxMemory(); |
| 6352 | long dalvikUsed = runtime.totalMemory() - runtime.freeMemory(); |
| 6353 | if (dalvikUsed > ((3*dalvikMax)/4)) { |
| 6354 | if (DEBUG_MEMORY_TRIM) Slog.d(TAG, "Dalvik max=" + (dalvikMax/1024) |
| 6355 | + " total=" + (runtime.totalMemory()/1024) |
| 6356 | + " used=" + (dalvikUsed/1024)); |
| 6357 | mSomeActivitiesChanged = false; |
| 6358 | try { |
| 6359 | mgr.releaseSomeActivities(mAppThread); |
| 6360 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 6361 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 6362 | } |
| 6363 | } |
| 6364 | } |
| 6365 | }); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6366 | } else { |
| 6367 | // Don't set application object here -- if the system crashes, |
| 6368 | // 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] | 6369 | android.ddm.DdmHandleAppName.setAppName("system_process", |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 6370 | UserHandle.myUserId()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6371 | try { |
| 6372 | mInstrumentation = new Instrumentation(); |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 6373 | ContextImpl context = ContextImpl.createAppContext( |
| 6374 | this, getSystemContext().mPackageInfo); |
Jeff Brown | 7fc8e35 | 2014-09-16 18:06:47 -0700 | [diff] [blame] | 6375 | mInitialApplication = context.mPackageInfo.makeApplication(true, null); |
| 6376 | mInitialApplication.onCreate(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6377 | } catch (Exception e) { |
| 6378 | throw new RuntimeException( |
| 6379 | "Unable to instantiate Application():" + e.toString(), e); |
| 6380 | } |
| 6381 | } |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 6382 | |
| 6383 | // add dropbox logging to libcore |
| 6384 | DropBox.setReporter(new DropBoxReporter()); |
| 6385 | |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 6386 | ViewRootImpl.ConfigChangedCallback configChangedCallback |
| 6387 | = (Configuration globalConfig) -> { |
| 6388 | synchronized (mResourcesManager) { |
| 6389 | // We need to apply this change to the resources immediately, because upon returning |
| 6390 | // the view hierarchy will be informed about it. |
| 6391 | if (mResourcesManager.applyConfigurationToResourcesLocked(globalConfig, |
| 6392 | null /* compat */)) { |
| 6393 | updateLocaleListFromAppContext(mInitialApplication.getApplicationContext(), |
| 6394 | mResourcesManager.getConfiguration().getLocales()); |
Adam Lesinski | b61e405 | 2016-05-19 18:23:05 -0700 | [diff] [blame] | 6395 | |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 6396 | // This actually changed the resources! Tell everyone about it. |
| 6397 | if (mPendingConfiguration == null |
| 6398 | || mPendingConfiguration.isOtherSeqNewer(globalConfig)) { |
| 6399 | mPendingConfiguration = globalConfig; |
| 6400 | sendMessage(H.CONFIGURATION_CHANGED, globalConfig); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6401 | } |
| 6402 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6403 | } |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 6404 | }; |
| 6405 | ViewRootImpl.addConfigCallback(configChangedCallback); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6406 | } |
| 6407 | |
Romain Guy | 5e9120d | 2012-01-30 12:17:22 -0800 | [diff] [blame] | 6408 | public static ActivityThread systemMain() { |
Alan Viverette | 5e1565e | 2014-07-29 16:14:25 -0700 | [diff] [blame] | 6409 | // The system process on low-memory devices do not get to use hardware |
| 6410 | // accelerated drawing, since this can add too much overhead to the |
| 6411 | // process. |
| 6412 | if (!ActivityManager.isHighEndGfx()) { |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 6413 | ThreadedRenderer.disable(true); |
John Reck | 73840ea | 2014-09-22 07:39:18 -0700 | [diff] [blame] | 6414 | } else { |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 6415 | ThreadedRenderer.enableForegroundTrimming(); |
Alan Viverette | 5e1565e | 2014-07-29 16:14:25 -0700 | [diff] [blame] | 6416 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6417 | ActivityThread thread = new ActivityThread(); |
| 6418 | thread.attach(true); |
| 6419 | return thread; |
| 6420 | } |
| 6421 | |
Jeff Brown | 10e8971 | 2011-07-08 18:52:57 -0700 | [diff] [blame] | 6422 | public final void installSystemProviders(List<ProviderInfo> providers) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6423 | if (providers != null) { |
Jeff Brown | 10e8971 | 2011-07-08 18:52:57 -0700 | [diff] [blame] | 6424 | installContentProviders(mInitialApplication, providers); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6425 | } |
| 6426 | } |
| 6427 | |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 6428 | public int getIntCoreSetting(String key, int defaultValue) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 6429 | synchronized (mResourcesManager) { |
Svetoslav Ganov | 9aa597e | 2011-03-03 18:17:41 -0800 | [diff] [blame] | 6430 | if (mCoreSettings != null) { |
| 6431 | return mCoreSettings.getInt(key, defaultValue); |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 6432 | } |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 6433 | return defaultValue; |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 6434 | } |
| 6435 | } |
| 6436 | |
Jason Monk | 6945710 | 2017-06-06 18:01:31 -0400 | [diff] [blame] | 6437 | private <T> T instantiate(ClassLoader cl, String className, Context c, |
| 6438 | Instantiator<T> instantiator) |
| 6439 | throws ClassNotFoundException, IllegalAccessException, InstantiationException { |
Jason Monk | 0b06d4e | 2017-07-14 10:22:36 -0400 | [diff] [blame] | 6440 | Application app = getApp(c); |
| 6441 | if (app != null) { |
| 6442 | T a = instantiator.instantiate(app, cl, className); |
Jason Monk | 6945710 | 2017-06-06 18:01:31 -0400 | [diff] [blame] | 6443 | if (a != null) return a; |
| 6444 | } |
| 6445 | return (T) cl.loadClass(className).newInstance(); |
| 6446 | } |
| 6447 | |
| 6448 | private <T> T instantiate(ClassLoader cl, String className, Intent intent, Context c, |
| 6449 | IntentInstantiator<T> instantiator) |
| 6450 | throws ClassNotFoundException, IllegalAccessException, InstantiationException { |
Jason Monk | 0b06d4e | 2017-07-14 10:22:36 -0400 | [diff] [blame] | 6451 | Application app = getApp(c); |
| 6452 | if (app != null) { |
| 6453 | T a = instantiator.instantiate(app, cl, className, intent); |
Jason Monk | 6945710 | 2017-06-06 18:01:31 -0400 | [diff] [blame] | 6454 | if (a != null) return a; |
| 6455 | } |
| 6456 | return (T) cl.loadClass(className).newInstance(); |
| 6457 | } |
| 6458 | |
Jason Monk | 0b06d4e | 2017-07-14 10:22:36 -0400 | [diff] [blame] | 6459 | private Application getApp(Context c) { |
| 6460 | // We need this shortcut to avoid actually calling getApplicationContext() on an Application |
| 6461 | // because the Application may not return itself for getApplicationContext() because the |
| 6462 | // API doesn't enforce it. |
| 6463 | if (c instanceof Application) return (Application) c; |
| 6464 | if (c.getApplicationContext() instanceof Application) { |
| 6465 | return (Application) c.getApplicationContext(); |
| 6466 | } |
| 6467 | return null; |
| 6468 | } |
| 6469 | |
Jason Monk | 6945710 | 2017-06-06 18:01:31 -0400 | [diff] [blame] | 6470 | private interface Instantiator<T> { |
| 6471 | T instantiate(Application app, ClassLoader cl, String className) |
| 6472 | throws ClassNotFoundException, IllegalAccessException, InstantiationException; |
| 6473 | } |
| 6474 | |
| 6475 | private interface IntentInstantiator<T> { |
| 6476 | T instantiate(Application app, ClassLoader cl, String className, Intent intent) |
| 6477 | throws ClassNotFoundException, IllegalAccessException, InstantiationException; |
| 6478 | } |
| 6479 | |
Geremy Condra | 69689a7 | 2012-09-11 16:57:17 -0700 | [diff] [blame] | 6480 | private static class EventLoggingReporter implements EventLogger.Reporter { |
| 6481 | @Override |
| 6482 | public void report (int code, Object... list) { |
| 6483 | EventLog.writeEvent(code, list); |
| 6484 | } |
| 6485 | } |
| 6486 | |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 6487 | private class DropBoxReporter implements DropBox.Reporter { |
| 6488 | |
| 6489 | private DropBoxManager dropBox; |
| 6490 | |
Narayan Kamath | 7f06224 | 2015-04-08 13:24:13 +0100 | [diff] [blame] | 6491 | public DropBoxReporter() {} |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 6492 | |
| 6493 | @Override |
| 6494 | public void addData(String tag, byte[] data, int flags) { |
Narayan Kamath | 7f06224 | 2015-04-08 13:24:13 +0100 | [diff] [blame] | 6495 | ensureInitialized(); |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 6496 | dropBox.addData(tag, data, flags); |
| 6497 | } |
| 6498 | |
| 6499 | @Override |
| 6500 | public void addText(String tag, String data) { |
Narayan Kamath | 7f06224 | 2015-04-08 13:24:13 +0100 | [diff] [blame] | 6501 | ensureInitialized(); |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 6502 | dropBox.addText(tag, data); |
| 6503 | } |
Narayan Kamath | 7f06224 | 2015-04-08 13:24:13 +0100 | [diff] [blame] | 6504 | |
| 6505 | private synchronized void ensureInitialized() { |
| 6506 | if (dropBox == null) { |
| 6507 | dropBox = (DropBoxManager) getSystemContext().getSystemService(Context.DROPBOX_SERVICE); |
| 6508 | } |
| 6509 | } |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 6510 | } |
| 6511 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 6512 | public static void main(String[] args) { |
Narayan Kamath | fbb32f6 | 2015-06-12 15:34:35 +0100 | [diff] [blame] | 6513 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "ActivityThreadMain"); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 6514 | |
Brad Fitzpatrick | 4d9e6d2 | 2010-11-15 08:49:51 -0800 | [diff] [blame] | 6515 | // CloseGuard defaults to true and can be quite spammy. We |
| 6516 | // disable it here, but selectively enable it later (via |
| 6517 | // StrictMode) on debug builds, but using DropBox, not logs. |
| 6518 | CloseGuard.setEnabled(false); |
| 6519 | |
Andreas Gampe | d281b42 | 2016-07-08 03:50:27 +0000 | [diff] [blame] | 6520 | Environment.initForCurrentUser(); |
Jeff Sharkey | b049e21 | 2012-09-07 23:16:01 -0700 | [diff] [blame] | 6521 | |
Geremy Condra | 69689a7 | 2012-09-11 16:57:17 -0700 | [diff] [blame] | 6522 | // Set the reporter for event logging in libcore |
| 6523 | EventLogger.setReporter(new EventLoggingReporter()); |
| 6524 | |
Robin Lee | 3d076af | 2014-04-25 14:57:49 +0100 | [diff] [blame] | 6525 | // Make sure TrustedCertificateStore looks in the right place for CA certificates |
| 6526 | final File configDir = Environment.getUserConfigDirectory(UserHandle.myUserId()); |
| 6527 | TrustedCertificateStore.setDefaultUserDirectory(configDir); |
| 6528 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6529 | Process.setArgV0("<pre-initialized>"); |
| 6530 | |
| 6531 | Looper.prepareMainLooper(); |
| 6532 | |
| 6533 | ActivityThread thread = new ActivityThread(); |
| 6534 | thread.attach(false); |
| 6535 | |
Vairavan Srinivasan | 7335cfd | 2012-08-18 18:36:03 -0700 | [diff] [blame] | 6536 | if (sMainThreadHandler == null) { |
| 6537 | sMainThreadHandler = thread.getHandler(); |
| 6538 | } |
| 6539 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6540 | if (false) { |
| 6541 | Looper.myLooper().setMessageLogging(new |
| 6542 | LogPrinter(Log.DEBUG, "ActivityThread")); |
| 6543 | } |
| 6544 | |
Narayan Kamath | fbb32f6 | 2015-06-12 15:34:35 +0100 | [diff] [blame] | 6545 | // End of event ActivityThreadMain. |
| 6546 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6547 | Looper.loop(); |
| 6548 | |
Jeff Brown | 10e8971 | 2011-07-08 18:52:57 -0700 | [diff] [blame] | 6549 | throw new RuntimeException("Main thread loop unexpectedly exited"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6550 | } |
Chris Craik | fc29424 | 2016-12-13 18:10:46 -0800 | [diff] [blame] | 6551 | |
| 6552 | // ------------------ Regular JNI ------------------------ |
| 6553 | |
| 6554 | private native void nDumpGraphicsInfo(FileDescriptor fd); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6555 | } |