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 | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 19 | import static android.app.servertransaction.ActivityLifecycleItem.ON_CREATE; |
| 20 | import static android.app.servertransaction.ActivityLifecycleItem.ON_DESTROY; |
| 21 | import static android.app.servertransaction.ActivityLifecycleItem.ON_PAUSE; |
| 22 | import static android.app.servertransaction.ActivityLifecycleItem.ON_RESUME; |
| 23 | import static android.app.servertransaction.ActivityLifecycleItem.ON_START; |
| 24 | import static android.app.servertransaction.ActivityLifecycleItem.ON_STOP; |
| 25 | import static android.app.servertransaction.ActivityLifecycleItem.PRE_ON_CREATE; |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 26 | import static android.view.Display.INVALID_DISPLAY; |
| 27 | |
Adam Lesinski | c1b0ebf | 2016-06-09 11:17:10 -0700 | [diff] [blame] | 28 | import android.annotation.NonNull; |
| 29 | import android.annotation.Nullable; |
Dianne Hackborn | 69c6adc | 2015-06-02 10:52:59 -0700 | [diff] [blame] | 30 | import android.app.assist.AssistContent; |
| 31 | import android.app.assist.AssistStructure; |
Christopher Tate | 4528186 | 2010-03-05 15:46:30 -0800 | [diff] [blame] | 32 | import android.app.backup.BackupAgent; |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 33 | import android.app.servertransaction.ActivityLifecycleItem.LifecycleState; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 34 | import android.app.servertransaction.ActivityResultItem; |
| 35 | import android.app.servertransaction.ClientTransaction; |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 36 | import android.app.servertransaction.PendingTransactionActions; |
| 37 | import android.app.servertransaction.PendingTransactionActions.StopInfo; |
| 38 | import android.app.servertransaction.TransactionExecutor; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | import android.content.BroadcastReceiver; |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 40 | import android.content.ComponentCallbacks2; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | import android.content.ComponentName; |
| 42 | import android.content.ContentProvider; |
| 43 | import android.content.Context; |
| 44 | import android.content.IContentProvider; |
Suchi Amalapurapu | 1ccac75 | 2009-06-12 10:09:58 -0700 | [diff] [blame] | 45 | import android.content.IIntentReceiver; |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 46 | import android.content.Intent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | import android.content.pm.ActivityInfo; |
| 48 | import android.content.pm.ApplicationInfo; |
| 49 | import android.content.pm.IPackageManager; |
| 50 | import android.content.pm.InstrumentationInfo; |
Christopher Tate | 346acb1 | 2012-10-15 19:20:25 -0700 | [diff] [blame] | 51 | import android.content.pm.PackageInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | import android.content.pm.PackageManager; |
Sen Hu | bde7570 | 2010-05-28 01:54:03 -0700 | [diff] [blame] | 53 | import android.content.pm.PackageManager.NameNotFoundException; |
Dianne Hackborn | 3f7c9f2 | 2017-04-04 15:36:33 -0700 | [diff] [blame] | 54 | import android.content.pm.ParceledListSlice; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | import android.content.pm.ProviderInfo; |
| 56 | import android.content.pm.ServiceInfo; |
| 57 | import android.content.res.AssetManager; |
Mitsuru Oshima | ba3ba57 | 2009-07-08 18:49:26 -0700 | [diff] [blame] | 58 | import android.content.res.CompatibilityInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 59 | import android.content.res.Configuration; |
| 60 | import android.content.res.Resources; |
Alan Viverette | e54d245 | 2015-05-06 10:41:43 -0700 | [diff] [blame] | 61 | import android.content.res.Resources.Theme; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | import android.database.sqlite.SQLiteDatabase; |
| 63 | import android.database.sqlite.SQLiteDebug; |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 64 | import android.database.sqlite.SQLiteDebug.DbStats; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 65 | import android.graphics.Bitmap; |
| 66 | import android.graphics.Canvas; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 67 | import android.hardware.display.DisplayManagerGlobal; |
Paul Jensen | e0bef71 | 2014-12-10 15:12:18 -0500 | [diff] [blame] | 68 | import android.net.ConnectivityManager; |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 69 | import android.net.IConnectivityManager; |
Paul Jensen | e0bef71 | 2014-12-10 15:12:18 -0500 | [diff] [blame] | 70 | import android.net.Network; |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 71 | import android.net.Proxy; |
Jason Monk | 207900c | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 72 | import android.net.ProxyInfo; |
Jason Monk | 83520b9 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 73 | import android.net.Uri; |
Joe Onorato | d630f10 | 2011-03-17 18:42:26 -0700 | [diff] [blame] | 74 | import android.os.AsyncTask; |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 75 | import android.os.Binder; |
Jeff Sharkey | 344744b | 2016-01-28 19:03:30 -0700 | [diff] [blame] | 76 | import android.os.Build; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 77 | import android.os.Bundle; |
| 78 | import android.os.Debug; |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 79 | import android.os.DropBoxManager; |
Jeff Sharkey | b049e21 | 2012-09-07 23:16:01 -0700 | [diff] [blame] | 80 | import android.os.Environment; |
Jesse Hall | b12249b | 2016-12-12 12:53:02 -0800 | [diff] [blame] | 81 | import android.os.GraphicsEnvironment; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 82 | import android.os.Handler; |
Jeff Sharkey | 8439ac0 | 2017-12-12 17:26:23 -0700 | [diff] [blame] | 83 | import android.os.HandlerExecutor; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 84 | import android.os.IBinder; |
Adam Lesinski | b61e405 | 2016-05-19 18:23:05 -0700 | [diff] [blame] | 85 | import android.os.LocaleList; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 86 | import android.os.Looper; |
| 87 | import android.os.Message; |
| 88 | import android.os.MessageQueue; |
Dianne Hackborn | fabb70b | 2014-11-11 12:22:36 -0800 | [diff] [blame] | 89 | import android.os.Parcel; |
Dianne Hackborn | 9c8dd55 | 2009-06-23 19:22:52 -0700 | [diff] [blame] | 90 | import android.os.ParcelFileDescriptor; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 91 | import android.os.PersistableBundle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 92 | import android.os.Process; |
| 93 | import android.os.RemoteException; |
| 94 | import android.os.ServiceManager; |
Brad Fitzpatrick | 438d059 | 2010-06-10 12:19:19 -0700 | [diff] [blame] | 95 | import android.os.StrictMode; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 96 | import android.os.SystemClock; |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 97 | import android.os.SystemProperties; |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 98 | import android.os.Trace; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 99 | import android.os.UserHandle; |
Jeff Sharkey | 0a17db1 | 2016-11-04 11:23:46 -0600 | [diff] [blame] | 100 | import android.provider.BlockedNumberContract; |
| 101 | import android.provider.CalendarContract; |
| 102 | import android.provider.CallLog; |
| 103 | import android.provider.ContactsContract; |
| 104 | import android.provider.Downloads; |
Seigo Nonaka | 54084b6 | 2017-04-24 14:46:23 -0700 | [diff] [blame] | 105 | import android.provider.FontsContract; |
Narayan Kamath | ccb2a086 | 2013-12-19 14:49:36 +0000 | [diff] [blame] | 106 | import android.provider.Settings; |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 107 | import android.renderscript.RenderScriptCacheDir; |
Chad Brubaker | c72875b | 2016-04-27 16:35:11 -0700 | [diff] [blame] | 108 | import android.security.NetworkSecurityPolicy; |
Chad Brubaker | 78d4712 | 2015-11-17 22:26:58 -0800 | [diff] [blame] | 109 | import android.security.net.config.NetworkSecurityConfigProvider; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 110 | import android.util.AndroidRuntimeException; |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 111 | import android.util.ArrayMap; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 112 | import android.util.DisplayMetrics; |
| 113 | import android.util.EventLog; |
| 114 | import android.util.Log; |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 115 | import android.util.LogPrinter; |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 116 | import android.util.MergedConfiguration; |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 117 | import android.util.Pair; |
Jeff Brown | 6754ba2 | 2011-12-14 20:20:01 -0800 | [diff] [blame] | 118 | import android.util.PrintWriterPrinter; |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 119 | import android.util.Slog; |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 120 | import android.util.SparseIntArray; |
Adam Powell | 1487466 | 2013-07-18 19:42:41 -0700 | [diff] [blame] | 121 | import android.util.SuperNotCalledException; |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 122 | import android.util.proto.ProtoOutputStream; |
Adam Lesinski | 3ad1b48 | 2016-04-01 16:41:41 -0700 | [diff] [blame] | 123 | import android.view.ContextThemeWrapper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 124 | import android.view.Display; |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 125 | import android.view.ThreadedRenderer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 126 | import android.view.View; |
| 127 | import android.view.ViewDebug; |
| 128 | import android.view.ViewManager; |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 129 | import android.view.ViewRootImpl; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 130 | import android.view.Window; |
| 131 | import android.view.WindowManager; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 132 | import android.view.WindowManagerGlobal; |
Richard Uhler | 2c03619 | 2016-09-14 09:48:31 +0100 | [diff] [blame] | 133 | import android.webkit.WebView; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 134 | |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 135 | import com.android.internal.annotations.GuardedBy; |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 136 | import com.android.internal.annotations.VisibleForTesting; |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 137 | import com.android.internal.app.IVoiceInteractor; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 138 | import com.android.internal.content.ReferrerIntent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 139 | import com.android.internal.os.BinderInternal; |
| 140 | import com.android.internal.os.RuntimeInit; |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 141 | import com.android.internal.os.SomeArgs; |
Jeff Sharkey | 3e19589 | 2016-03-05 19:48:59 -0700 | [diff] [blame] | 142 | import com.android.internal.util.ArrayUtils; |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 143 | import com.android.internal.util.FastPrintWriter; |
Kenny Root | 12e7522 | 2013-04-23 22:34:24 -0700 | [diff] [blame] | 144 | import com.android.org.conscrypt.OpenSSLSocketImpl; |
Robin Lee | 3d076af | 2014-04-25 14:57:49 +0100 | [diff] [blame] | 145 | import com.android.org.conscrypt.TrustedCertificateStore; |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 146 | import com.android.server.am.proto.MemInfoProto; |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 147 | |
| 148 | import dalvik.system.BaseDexClassLoader; |
| 149 | import dalvik.system.CloseGuard; |
| 150 | import dalvik.system.VMDebug; |
| 151 | import dalvik.system.VMRuntime; |
| 152 | |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 153 | import libcore.io.DropBox; |
| 154 | import libcore.io.EventLogger; |
| 155 | import libcore.io.IoUtils; |
| 156 | import libcore.net.event.NetworkEventDispatcher; |
| 157 | |
| 158 | import org.apache.harmony.dalvik.ddmc.DdmVmInternal; |
| 159 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 160 | import java.io.File; |
| 161 | import java.io.FileDescriptor; |
| 162 | import java.io.FileOutputStream; |
Dianne Hackborn | 9c8dd55 | 2009-06-23 19:22:52 -0700 | [diff] [blame] | 163 | import java.io.IOException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 164 | import java.io.PrintWriter; |
| 165 | import java.lang.ref.WeakReference; |
Svet Ganov | 37e4327 | 2016-09-09 16:01:32 -0700 | [diff] [blame] | 166 | import java.lang.reflect.Field; |
Torne (Richard Coles) | 466cbe4 | 2017-05-31 14:09:14 -0400 | [diff] [blame] | 167 | import java.lang.reflect.Method; |
Robert Greenwalt | 03595d0 | 2010-11-02 14:08:23 -0700 | [diff] [blame] | 168 | import java.net.InetAddress; |
Narayan Kamath | ccb2a086 | 2013-12-19 14:49:36 +0000 | [diff] [blame] | 169 | import java.text.DateFormat; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 170 | import java.util.ArrayList; |
Jeff Sharkey | a6bfeae | 2017-07-05 16:50:24 -0600 | [diff] [blame] | 171 | import java.util.Arrays; |
Bryce Lee | a33c13d | 2018-02-08 14:37:06 -0800 | [diff] [blame] | 172 | import java.util.Iterator; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 173 | import java.util.List; |
Adam Lesinski | b61e405 | 2016-05-19 18:23:05 -0700 | [diff] [blame] | 174 | import java.util.Locale; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 175 | import java.util.Map; |
Kenny Root | e6585b3 | 2013-12-13 12:00:26 -0800 | [diff] [blame] | 176 | import java.util.Objects; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 177 | import java.util.TimeZone; |
Jeff Sharkey | 8439ac0 | 2017-12-12 17:26:23 -0700 | [diff] [blame] | 178 | import java.util.concurrent.Executor; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 179 | |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 180 | final class RemoteServiceException extends AndroidRuntimeException { |
| 181 | public RemoteServiceException(String msg) { |
| 182 | super(msg); |
| 183 | } |
| 184 | } |
| 185 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 186 | /** |
| 187 | * This manages the execution of the main thread in an |
| 188 | * application process, scheduling and executing activities, |
| 189 | * broadcasts, and other operations on it as the activity |
| 190 | * manager requests. |
| 191 | * |
| 192 | * {@hide} |
| 193 | */ |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 194 | public final class ActivityThread extends ClientTransactionHandler { |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 195 | /** @hide */ |
| 196 | public static final String TAG = "ActivityThread"; |
Jim Miller | 0b2a6d0 | 2010-07-13 18:01:29 -0700 | [diff] [blame] | 197 | 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] | 198 | static final boolean localLOGV = false; |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 199 | static final boolean DEBUG_MESSAGES = false; |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 200 | /** @hide */ |
| 201 | public static final boolean DEBUG_BROADCAST = false; |
Chris Tate | 8a7dc17 | 2009-03-24 20:11:42 -0700 | [diff] [blame] | 202 | private static final boolean DEBUG_RESULTS = false; |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 203 | private static final boolean DEBUG_BACKUP = false; |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 204 | public static final boolean DEBUG_CONFIGURATION = false; |
Dianne Hackborn | a0c283e | 2012-02-09 10:47:01 -0800 | [diff] [blame] | 205 | private static final boolean DEBUG_SERVICE = false; |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 206 | public static final boolean DEBUG_MEMORY_TRIM = false; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 207 | private static final boolean DEBUG_PROVIDER = false; |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 208 | public static final boolean DEBUG_ORDER = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 209 | 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] | 210 | private static final int SQLITE_MEM_RELEASED_EVENT_LOG_TAG = 75003; |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 211 | private static final int LOG_AM_ON_PAUSE_CALLED = 30021; |
| 212 | private static final int LOG_AM_ON_RESUME_CALLED = 30022; |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 213 | 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] | 214 | |
Dianne Hackborn | 455625e | 2015-01-21 09:55:13 -0800 | [diff] [blame] | 215 | /** Type for IActivityManager.serviceDoneExecuting: anonymous operation */ |
| 216 | public static final int SERVICE_DONE_EXECUTING_ANON = 0; |
| 217 | /** Type for IActivityManager.serviceDoneExecuting: done with an onStart call */ |
| 218 | public static final int SERVICE_DONE_EXECUTING_START = 1; |
| 219 | /** Type for IActivityManager.serviceDoneExecuting: done stopping (destroying) service */ |
| 220 | public static final int SERVICE_DONE_EXECUTING_STOP = 2; |
| 221 | |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 222 | // Whether to invoke an activity callback after delivering new configuration. |
| 223 | private static final boolean REPORT_TO_ACTIVITY = true; |
| 224 | |
Bryce Lee | d946f86 | 2018-01-16 15:59:47 -0800 | [diff] [blame] | 225 | // Maximum number of recent tokens to maintain for debugging purposes |
Bryce Lee | a33c13d | 2018-02-08 14:37:06 -0800 | [diff] [blame] | 226 | private static final int MAX_DESTROYED_ACTIVITIES = 10; |
Bryce Lee | d946f86 | 2018-01-16 15:59:47 -0800 | [diff] [blame] | 227 | |
Sudheer Shanka | 84a4895 | 2017-03-08 18:19:01 -0800 | [diff] [blame] | 228 | /** |
| 229 | * Denotes an invalid sequence number corresponding to a process state change. |
| 230 | */ |
| 231 | public static final long INVALID_PROC_STATE_SEQ = -1; |
| 232 | |
Sudheer Shanka | f669010 | 2017-10-16 10:20:32 -0700 | [diff] [blame] | 233 | /** |
| 234 | * Identifier for the sequence no. associated with this process start. It will be provided |
| 235 | * as one of the arguments when the process starts. |
| 236 | */ |
| 237 | public static final String PROC_START_SEQ_IDENT = "seq="; |
| 238 | |
Sudheer Shanka | 84a4895 | 2017-03-08 18:19:01 -0800 | [diff] [blame] | 239 | private final Object mNetworkPolicyLock = new Object(); |
| 240 | |
| 241 | /** |
| 242 | * Denotes the sequence number of the process state change for which the main thread needs |
| 243 | * to block until the network rules are updated for it. |
| 244 | * |
| 245 | * Value of {@link #INVALID_PROC_STATE_SEQ} indicates there is no need for blocking. |
| 246 | */ |
| 247 | @GuardedBy("mNetworkPolicyLock") |
| 248 | private long mNetworkBlockSeq = INVALID_PROC_STATE_SEQ; |
| 249 | |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 250 | private ContextImpl mSystemContext; |
Adam Lesinski | a82b626 | 2017-03-21 16:56:17 -0700 | [diff] [blame] | 251 | private ContextImpl mSystemUiContext; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 252 | |
Jeff Sharkey | d589663 | 2016-03-04 16:16:00 -0700 | [diff] [blame] | 253 | static volatile IPackageManager sPackageManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 254 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 255 | final ApplicationThread mAppThread = new ApplicationThread(); |
| 256 | final Looper mLooper = Looper.myLooper(); |
| 257 | final H mH = new H(); |
Jeff Sharkey | 8439ac0 | 2017-12-12 17:26:23 -0700 | [diff] [blame] | 258 | final Executor mExecutor = new HandlerExecutor(mH); |
Dianne Hackborn | 782d498 | 2015-07-08 17:36:37 -0700 | [diff] [blame] | 259 | final ArrayMap<IBinder, ActivityClientRecord> mActivities = new ArrayMap<>(); |
Bryce Lee | a33c13d | 2018-02-08 14:37:06 -0800 | [diff] [blame] | 260 | final ArrayList<DestroyedActivityInfo> mRecentDestroyedActivities = new ArrayList<>(); |
Bryce Lee | d946f86 | 2018-01-16 15:59:47 -0800 | [diff] [blame] | 261 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 262 | // List of new activities (via ActivityRecord.nextIdle) that should |
| 263 | // be reported when next we idle. |
| 264 | ActivityClientRecord mNewActivities = null; |
| 265 | // Number of activities that are currently visible on-screen. |
| 266 | int mNumVisibleActivities = 0; |
Amith Yamasani | 4f128e4 | 2016-05-10 11:44:12 -0700 | [diff] [blame] | 267 | ArrayList<WeakReference<AssistStructure>> mLastAssistStructures = new ArrayList<>(); |
| 268 | private int mLastSessionId; |
Dianne Hackborn | 782d498 | 2015-07-08 17:36:37 -0700 | [diff] [blame] | 269 | final ArrayMap<IBinder, Service> mServices = new ArrayMap<>(); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 270 | AppBindData mBoundApplication; |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 271 | Profiler mProfiler; |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 272 | int mCurDefaultDisplayDpi; |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 273 | boolean mDensityCompatMode; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 274 | Configuration mConfiguration; |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 275 | Configuration mCompatConfiguration; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 276 | Application mInitialApplication; |
| 277 | final ArrayList<Application> mAllApplications |
| 278 | = new ArrayList<Application>(); |
| 279 | // set of instantiated backup agents, keyed by package name |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 280 | final ArrayMap<String, BackupAgent> mBackupAgents = new ArrayMap<String, BackupAgent>(); |
Jeff Sharkey | 66a017b | 2013-01-17 18:18:22 -0800 | [diff] [blame] | 281 | /** Reference to singleton {@link ActivityThread} */ |
Jeff Sharkey | d589663 | 2016-03-04 16:16:00 -0700 | [diff] [blame] | 282 | private static volatile ActivityThread sCurrentActivityThread; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 283 | Instrumentation mInstrumentation; |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 284 | String mInstrumentationPackageName = null; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 285 | String mInstrumentationAppDir = null; |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 286 | String[] mInstrumentationSplitAppDirs = null; |
| 287 | String mInstrumentationLibDir = null; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 288 | String mInstrumentedAppDir = null; |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 289 | String[] mInstrumentedSplitAppDirs = null; |
| 290 | String mInstrumentedLibDir = null; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 291 | boolean mSystemThread = false; |
| 292 | boolean mJitEnabled = false; |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 293 | boolean mSomeActivitiesChanged = false; |
Chong Zhang | 4951f9d | 2016-06-23 13:15:08 -0700 | [diff] [blame] | 294 | boolean mUpdatingSystemConfig = false; |
David Brazdil | d960cc4 | 2018-01-31 07:59:17 +0000 | [diff] [blame] | 295 | /* package */ boolean mHiddenApiWarningShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 296 | |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 297 | // These can be accessed by multiple threads; mResourcesManager is the lock. |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 298 | // XXX For now we keep around information about all packages we have |
| 299 | // seen, not removing entries from this map. |
Dianne Hackborn | 1fbee79 | 2011-11-30 11:29:58 -0800 | [diff] [blame] | 300 | // NOTE: The activity and window managers need to call in to |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 301 | // ActivityThread to do things like update resource configurations, |
Dianne Hackborn | 1fbee79 | 2011-11-30 11:29:58 -0800 | [diff] [blame] | 302 | // which means this lock gets held while the activity and window managers |
| 303 | // holds their own lock. Thus you MUST NEVER call back into the activity manager |
| 304 | // 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] | 305 | // 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] | 306 | @GuardedBy("mResourcesManager") |
| 307 | final ArrayMap<String, WeakReference<LoadedApk>> mPackages = new ArrayMap<>(); |
| 308 | @GuardedBy("mResourcesManager") |
| 309 | final ArrayMap<String, WeakReference<LoadedApk>> mResourcePackages = new ArrayMap<>(); |
| 310 | @GuardedBy("mResourcesManager") |
| 311 | final ArrayList<ActivityClientRecord> mRelaunchingActivities = new ArrayList<>(); |
| 312 | @GuardedBy("mResourcesManager") |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 313 | Configuration mPendingConfiguration = null; |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 314 | // An executor that performs multi-step transactions. |
| 315 | private final TransactionExecutor mTransactionExecutor = new TransactionExecutor(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 316 | |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 317 | private final ResourcesManager mResourcesManager; |
| 318 | |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 319 | private static final class ProviderKey { |
| 320 | final String authority; |
| 321 | final int userId; |
| 322 | |
| 323 | public ProviderKey(String authority, int userId) { |
| 324 | this.authority = authority; |
| 325 | this.userId = userId; |
| 326 | } |
| 327 | |
| 328 | @Override |
| 329 | public boolean equals(Object o) { |
| 330 | if (o instanceof ProviderKey) { |
| 331 | final ProviderKey other = (ProviderKey) o; |
Kenny Root | e6585b3 | 2013-12-13 12:00:26 -0800 | [diff] [blame] | 332 | return Objects.equals(authority, other.authority) && userId == other.userId; |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 333 | } |
| 334 | return false; |
| 335 | } |
| 336 | |
| 337 | @Override |
| 338 | public int hashCode() { |
| 339 | return ((authority != null) ? authority.hashCode() : 0) ^ userId; |
| 340 | } |
| 341 | } |
| 342 | |
Bryce Lee | a33c13d | 2018-02-08 14:37:06 -0800 | [diff] [blame] | 343 | /** |
| 344 | * TODO(b/71506345): Remove this once bug is resolved. |
| 345 | */ |
| 346 | private static final class DestroyedActivityInfo { |
| 347 | private final Integer mToken; |
| 348 | private final String mReason; |
| 349 | private final long mTime; |
| 350 | |
| 351 | DestroyedActivityInfo(Integer token, String reason) { |
| 352 | mToken = token; |
| 353 | mReason = reason; |
| 354 | mTime = System.currentTimeMillis(); |
| 355 | } |
| 356 | |
| 357 | void dump(PrintWriter pw, String prefix) { |
| 358 | pw.println(prefix + "[token:" + mToken + " | time:" + mTime + " | reason:" + mReason |
| 359 | + "]"); |
| 360 | } |
| 361 | } |
| 362 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 363 | // The lock of mProviderMap protects the following variables. |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 364 | final ArrayMap<ProviderKey, ProviderClientRecord> mProviderMap |
| 365 | = new ArrayMap<ProviderKey, ProviderClientRecord>(); |
| 366 | final ArrayMap<IBinder, ProviderRefCount> mProviderRefCountMap |
| 367 | = new ArrayMap<IBinder, ProviderRefCount>(); |
| 368 | final ArrayMap<IBinder, ProviderClientRecord> mLocalProviders |
| 369 | = new ArrayMap<IBinder, ProviderClientRecord>(); |
| 370 | final ArrayMap<ComponentName, ProviderClientRecord> mLocalProvidersByName |
| 371 | = new ArrayMap<ComponentName, ProviderClientRecord>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 372 | |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 373 | final ArrayMap<Activity, ArrayList<OnActivityPausedListener>> mOnPauseListeners |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 374 | = new ArrayMap<Activity, ArrayList<OnActivityPausedListener>>(); |
Jeff Hamilton | 52d3203 | 2011-01-08 15:31:26 -0600 | [diff] [blame] | 375 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 376 | final GcIdler mGcIdler = new GcIdler(); |
| 377 | boolean mGcIdlerScheduled = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 378 | |
Jeff Sharkey | d589663 | 2016-03-04 16:16:00 -0700 | [diff] [blame] | 379 | static volatile Handler sMainThreadHandler; // set once in main() |
Brad Fitzpatrick | 333b8cb | 2010-08-26 12:04:57 -0700 | [diff] [blame] | 380 | |
Svetoslav Ganov | 9aa597e | 2011-03-03 18:17:41 -0800 | [diff] [blame] | 381 | Bundle mCoreSettings = null; |
| 382 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 383 | /** Activity client record, used for bookkeeping for the real {@link Activity} instance. */ |
| 384 | public static final class ActivityClientRecord { |
| 385 | public IBinder token; |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 386 | int ident; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 387 | Intent intent; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 388 | String referrer; |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 389 | IVoiceInteractor voiceInteractor; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 390 | Bundle state; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 391 | PersistableBundle persistentState; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 392 | Activity activity; |
| 393 | Window window; |
| 394 | Activity parent; |
| 395 | String embeddedID; |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 396 | Activity.NonConfigurationInstances lastNonConfigurationInstances; |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 397 | // TODO(lifecycler): Use mLifecycleState instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 398 | boolean paused; |
| 399 | boolean stopped; |
| 400 | boolean hideForNow; |
| 401 | Configuration newConfig; |
Dianne Hackborn | e88846e | 2009-09-30 21:34:25 -0700 | [diff] [blame] | 402 | Configuration createdConfig; |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 403 | Configuration overrideConfig; |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 404 | // Used for consolidating configs before sending on to Activity. |
| 405 | private Configuration tmpConfig = new Configuration(); |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 406 | // Callback used for updating activity override config. |
| 407 | ViewRootImpl.ActivityConfigCallback configCallback; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 408 | ActivityClientRecord nextIdle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 409 | |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 410 | ProfilerInfo profilerInfo; |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 411 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 412 | ActivityInfo activityInfo; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 413 | CompatibilityInfo compatInfo; |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 414 | public LoadedApk packageInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 415 | |
| 416 | List<ResultInfo> pendingResults; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 417 | List<ReferrerIntent> pendingIntents; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 418 | |
| 419 | boolean startsNotResumed; |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 420 | public final boolean isForward; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 421 | int pendingConfigChanges; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 422 | |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 423 | Window mPendingRemoveWindow; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 424 | WindowManager mPendingRemoveWindowManager; |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 425 | boolean mPreserveWindow; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 426 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 427 | @LifecycleState |
| 428 | private int mLifecycleState = PRE_ON_CREATE; |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 429 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 430 | @VisibleForTesting |
| 431 | public ActivityClientRecord() { |
| 432 | this.isForward = false; |
| 433 | init(); |
| 434 | } |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 435 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 436 | public ActivityClientRecord(IBinder token, Intent intent, int ident, |
| 437 | ActivityInfo info, Configuration overrideConfig, CompatibilityInfo compatInfo, |
| 438 | String referrer, IVoiceInteractor voiceInteractor, Bundle state, |
| 439 | PersistableBundle persistentState, List<ResultInfo> pendingResults, |
| 440 | List<ReferrerIntent> pendingNewIntents, boolean isForward, |
| 441 | ProfilerInfo profilerInfo, ClientTransactionHandler client) { |
| 442 | this.token = token; |
| 443 | this.ident = ident; |
| 444 | this.intent = intent; |
| 445 | this.referrer = referrer; |
| 446 | this.voiceInteractor = voiceInteractor; |
| 447 | this.activityInfo = info; |
| 448 | this.compatInfo = compatInfo; |
| 449 | this.state = state; |
| 450 | this.persistentState = persistentState; |
| 451 | this.pendingResults = pendingResults; |
| 452 | this.pendingIntents = pendingNewIntents; |
| 453 | this.isForward = isForward; |
| 454 | this.profilerInfo = profilerInfo; |
| 455 | this.overrideConfig = overrideConfig; |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 456 | this.packageInfo = client.getPackageInfoNoCheck(activityInfo.applicationInfo, |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 457 | compatInfo); |
| 458 | init(); |
| 459 | } |
| 460 | |
| 461 | /** Common initializer for all constructors. */ |
| 462 | private void init() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 463 | parent = null; |
| 464 | embeddedID = null; |
| 465 | paused = false; |
| 466 | stopped = false; |
| 467 | hideForNow = false; |
| 468 | nextIdle = null; |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 469 | configCallback = (Configuration overrideConfig, int newDisplayId) -> { |
| 470 | if (activity == null) { |
| 471 | throw new IllegalStateException( |
| 472 | "Received config update for non-existing activity"); |
| 473 | } |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 474 | activity.mMainThread.handleActivityConfigurationChanged(token, overrideConfig, |
| 475 | newDisplayId); |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 476 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 477 | } |
| 478 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 479 | /** Get the current lifecycle state. */ |
| 480 | public int getLifecycleState() { |
| 481 | return mLifecycleState; |
| 482 | } |
| 483 | |
| 484 | /** Update the current lifecycle state for internal bookkeeping. */ |
| 485 | public void setState(@LifecycleState int newLifecycleState) { |
| 486 | mLifecycleState = newLifecycleState; |
| 487 | switch (mLifecycleState) { |
| 488 | case ON_CREATE: |
| 489 | paused = true; |
| 490 | stopped = true; |
| 491 | break; |
| 492 | case ON_START: |
| 493 | paused = true; |
| 494 | stopped = false; |
| 495 | break; |
| 496 | case ON_RESUME: |
| 497 | paused = false; |
| 498 | stopped = false; |
| 499 | break; |
| 500 | case ON_PAUSE: |
| 501 | paused = true; |
| 502 | stopped = false; |
| 503 | break; |
| 504 | case ON_STOP: |
| 505 | paused = true; |
| 506 | stopped = true; |
| 507 | break; |
| 508 | } |
| 509 | } |
| 510 | |
Andrii Kulian | 391161f | 2018-01-29 10:50:02 -0800 | [diff] [blame] | 511 | private boolean isPreHoneycomb() { |
| 512 | return activity != null && activity.getApplicationInfo().targetSdkVersion |
| 513 | < android.os.Build.VERSION_CODES.HONEYCOMB; |
| 514 | } |
| 515 | |
| 516 | private boolean isPreP() { |
| 517 | return activity != null && activity.getApplicationInfo().targetSdkVersion |
| 518 | < android.os.Build.VERSION_CODES.P; |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 519 | } |
| 520 | |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 521 | public boolean isPersistable() { |
Craig Mautner | 43e52ed | 2014-06-16 17:18:52 -0700 | [diff] [blame] | 522 | return activityInfo.persistableMode == ActivityInfo.PERSIST_ACROSS_REBOOTS; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 523 | } |
| 524 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 525 | public String toString() { |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 526 | ComponentName componentName = intent != null ? intent.getComponent() : null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 527 | return "ActivityRecord{" |
| 528 | + Integer.toHexString(System.identityHashCode(this)) |
| 529 | + " token=" + token + " " + (componentName == null |
| 530 | ? "no component name" : componentName.toShortString()) |
| 531 | + "}"; |
| 532 | } |
Andrii Kulian | 58178f2 | 2016-03-16 13:44:56 -0700 | [diff] [blame] | 533 | |
| 534 | public String getStateString() { |
| 535 | StringBuilder sb = new StringBuilder(); |
| 536 | sb.append("ActivityClientRecord{"); |
| 537 | sb.append("paused=").append(paused); |
| 538 | sb.append(", stopped=").append(stopped); |
| 539 | sb.append(", hideForNow=").append(hideForNow); |
| 540 | sb.append(", startsNotResumed=").append(startsNotResumed); |
| 541 | sb.append(", isForward=").append(isForward); |
| 542 | sb.append(", pendingConfigChanges=").append(pendingConfigChanges); |
Andrii Kulian | 58178f2 | 2016-03-16 13:44:56 -0700 | [diff] [blame] | 543 | sb.append(", preserveWindow=").append(mPreserveWindow); |
| 544 | if (activity != null) { |
| 545 | sb.append(", Activity{"); |
| 546 | sb.append("resumed=").append(activity.mResumed); |
| 547 | sb.append(", stopped=").append(activity.mStopped); |
| 548 | sb.append(", finished=").append(activity.isFinishing()); |
| 549 | sb.append(", destroyed=").append(activity.isDestroyed()); |
| 550 | sb.append(", startedActivity=").append(activity.mStartedActivity); |
| 551 | sb.append(", temporaryPause=").append(activity.mTemporaryPause); |
| 552 | sb.append(", changingConfigurations=").append(activity.mChangingConfigurations); |
Andrii Kulian | 58178f2 | 2016-03-16 13:44:56 -0700 | [diff] [blame] | 553 | sb.append("}"); |
| 554 | } |
| 555 | sb.append("}"); |
| 556 | return sb.toString(); |
| 557 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 558 | } |
| 559 | |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 560 | final class ProviderClientRecord { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 561 | final String[] mNames; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 562 | final IContentProvider mProvider; |
| 563 | final ContentProvider mLocalProvider; |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 564 | final ContentProviderHolder mHolder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 565 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 566 | ProviderClientRecord(String[] names, IContentProvider provider, |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 567 | ContentProvider localProvider, ContentProviderHolder holder) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 568 | mNames = names; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 569 | mProvider = provider; |
| 570 | mLocalProvider = localProvider; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 571 | mHolder = holder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 572 | } |
| 573 | } |
| 574 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 575 | static final class ReceiverData extends BroadcastReceiver.PendingResult { |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 576 | public ReceiverData(Intent intent, int resultCode, String resultData, Bundle resultExtras, |
Dianne Hackborn | 20e8098 | 2012-08-31 19:00:44 -0700 | [diff] [blame] | 577 | boolean ordered, boolean sticky, IBinder token, int sendingUser) { |
| 578 | super(resultCode, resultData, resultExtras, TYPE_COMPONENT, ordered, sticky, |
riddle_hsu | 1f5ac4d | 2015-01-03 15:38:21 +0800 | [diff] [blame] | 579 | token, sendingUser, intent.getFlags()); |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 580 | this.intent = intent; |
| 581 | } |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 582 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 583 | Intent intent; |
| 584 | ActivityInfo info; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 585 | CompatibilityInfo compatInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 586 | public String toString() { |
| 587 | return "ReceiverData{intent=" + intent + " packageName=" + |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 588 | info.packageName + " resultCode=" + getResultCode() |
| 589 | + " resultData=" + getResultData() + " resultExtras=" |
| 590 | + getResultExtras(false) + "}"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 591 | } |
| 592 | } |
| 593 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 594 | static final class CreateBackupAgentData { |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 595 | ApplicationInfo appInfo; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 596 | CompatibilityInfo compatInfo; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 597 | int backupMode; |
| 598 | public String toString() { |
| 599 | return "CreateBackupAgentData{appInfo=" + appInfo |
| 600 | + " backupAgent=" + appInfo.backupAgentName |
| 601 | + " mode=" + backupMode + "}"; |
| 602 | } |
| 603 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 604 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 605 | static final class CreateServiceData { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 606 | IBinder token; |
| 607 | ServiceInfo info; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 608 | CompatibilityInfo compatInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 609 | Intent intent; |
| 610 | public String toString() { |
| 611 | return "CreateServiceData{token=" + token + " className=" |
| 612 | + info.name + " packageName=" + info.packageName |
| 613 | + " intent=" + intent + "}"; |
| 614 | } |
| 615 | } |
| 616 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 617 | static final class BindServiceData { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 618 | IBinder token; |
| 619 | Intent intent; |
| 620 | boolean rebind; |
| 621 | public String toString() { |
| 622 | return "BindServiceData{token=" + token + " intent=" + intent + "}"; |
| 623 | } |
| 624 | } |
| 625 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 626 | static final class ServiceArgsData { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 627 | IBinder token; |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 628 | boolean taskRemoved; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 629 | int startId; |
Dianne Hackborn | f6f9f2d | 2009-08-21 16:26:03 -0700 | [diff] [blame] | 630 | int flags; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 631 | Intent args; |
| 632 | public String toString() { |
| 633 | return "ServiceArgsData{token=" + token + " startId=" + startId |
| 634 | + " args=" + args + "}"; |
| 635 | } |
| 636 | } |
| 637 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 638 | static final class AppBindData { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 639 | LoadedApk info; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 640 | String processName; |
| 641 | ApplicationInfo appInfo; |
| 642 | List<ProviderInfo> providers; |
| 643 | ComponentName instrumentationName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 644 | Bundle instrumentationArgs; |
| 645 | IInstrumentationWatcher instrumentationWatcher; |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 646 | IUiAutomationConnection instrumentationUiAutomationConnection; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 647 | int debugMode; |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 648 | boolean enableBinderTracking; |
Man Cao | cfa78b2 | 2015-06-11 20:14:34 -0700 | [diff] [blame] | 649 | boolean trackAllocation; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 650 | boolean restrictedBackupMode; |
Dianne Hackborn | 5d927c2 | 2011-09-02 12:22:18 -0700 | [diff] [blame] | 651 | boolean persistent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 652 | Configuration config; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 653 | CompatibilityInfo compatInfo; |
Svet Ganov | 37e4327 | 2016-09-09 16:01:32 -0700 | [diff] [blame] | 654 | String buildSerial; |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 655 | |
| 656 | /** Initial values for {@link Profiler}. */ |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 657 | ProfilerInfo initProfilerInfo; |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 658 | |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 659 | boolean autofillCompatibilityEnabled; |
| 660 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 661 | public String toString() { |
| 662 | return "AppBindData{appInfo=" + appInfo + "}"; |
| 663 | } |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 664 | } |
| 665 | |
| 666 | static final class Profiler { |
| 667 | String profileFile; |
| 668 | ParcelFileDescriptor profileFd; |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 669 | int samplingInterval; |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 670 | boolean autoStopProfiler; |
Shukang Zhou | 6ffd4f9 | 2017-01-25 16:07:57 -0800 | [diff] [blame] | 671 | boolean streamingOutput; |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 672 | boolean profiling; |
| 673 | boolean handlingProfiling; |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 674 | public void setProfiler(ProfilerInfo profilerInfo) { |
| 675 | ParcelFileDescriptor fd = profilerInfo.profileFd; |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 676 | if (profiling) { |
| 677 | if (fd != null) { |
| 678 | try { |
| 679 | fd.close(); |
| 680 | } catch (IOException e) { |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 681 | // Ignore |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 682 | } |
| 683 | } |
| 684 | return; |
| 685 | } |
| 686 | if (profileFd != null) { |
| 687 | try { |
| 688 | profileFd.close(); |
| 689 | } catch (IOException e) { |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 690 | // Ignore |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 691 | } |
| 692 | } |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 693 | profileFile = profilerInfo.profileFile; |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 694 | profileFd = fd; |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 695 | samplingInterval = profilerInfo.samplingInterval; |
| 696 | autoStopProfiler = profilerInfo.autoStopProfiler; |
Shukang Zhou | 6ffd4f9 | 2017-01-25 16:07:57 -0800 | [diff] [blame] | 697 | streamingOutput = profilerInfo.streamingOutput; |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 698 | } |
| 699 | public void startProfiling() { |
| 700 | if (profileFd == null || profiling) { |
| 701 | return; |
| 702 | } |
| 703 | try { |
Andreas Gampe | eff0639 | 2016-05-10 12:51:45 -0700 | [diff] [blame] | 704 | int bufferSize = SystemProperties.getInt("debug.traceview-buffer-size-mb", 8); |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 705 | VMDebug.startMethodTracing(profileFile, profileFd.getFileDescriptor(), |
Shukang Zhou | 6ffd4f9 | 2017-01-25 16:07:57 -0800 | [diff] [blame] | 706 | bufferSize * 1024 * 1024, 0, samplingInterval != 0, samplingInterval, |
| 707 | streamingOutput); |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 708 | profiling = true; |
| 709 | } catch (RuntimeException e) { |
| 710 | Slog.w(TAG, "Profiling failed on path " + profileFile); |
| 711 | try { |
| 712 | profileFd.close(); |
| 713 | profileFd = null; |
| 714 | } catch (IOException e2) { |
| 715 | Slog.w(TAG, "Failure closing profile fd", e2); |
| 716 | } |
| 717 | } |
| 718 | } |
| 719 | public void stopProfiling() { |
| 720 | if (profiling) { |
| 721 | profiling = false; |
| 722 | Debug.stopMethodTracing(); |
| 723 | if (profileFd != null) { |
| 724 | try { |
| 725 | profileFd.close(); |
| 726 | } catch (IOException e) { |
| 727 | } |
| 728 | } |
| 729 | profileFd = null; |
| 730 | profileFile = null; |
| 731 | } |
| 732 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 733 | } |
| 734 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 735 | static final class DumpComponentInfo { |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 736 | ParcelFileDescriptor fd; |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 737 | IBinder token; |
Dianne Hackborn | 30d7189 | 2010-12-11 10:37:55 -0800 | [diff] [blame] | 738 | String prefix; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 739 | String[] args; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 740 | } |
| 741 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 742 | static final class ContextCleanupInfo { |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 743 | ContextImpl context; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 744 | String what; |
| 745 | String who; |
| 746 | } |
| 747 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 748 | static final class DumpHeapData { |
Christopher Ferris | 8d652f8 | 2017-04-11 16:29:18 -0700 | [diff] [blame] | 749 | public boolean managed; |
| 750 | public boolean mallocInfo; |
Makoto Onuki | 4556b7b | 2017-07-07 14:58:58 -0700 | [diff] [blame] | 751 | public boolean runGc; |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 752 | String path; |
| 753 | ParcelFileDescriptor fd; |
| 754 | } |
| 755 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 756 | static final class UpdateCompatibilityData { |
| 757 | String pkg; |
| 758 | CompatibilityInfo info; |
| 759 | } |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 760 | |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 761 | static final class RequestAssistContextExtras { |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 762 | IBinder activityToken; |
| 763 | IBinder requestToken; |
| 764 | int requestType; |
Amith Yamasani | 4f128e4 | 2016-05-10 11:44:12 -0700 | [diff] [blame] | 765 | int sessionId; |
Svet Ganov | fd31f85 | 2017-04-26 15:54:27 -0700 | [diff] [blame] | 766 | int flags; |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 767 | } |
Anwar Ghuloum | 3a8ce1b | 2013-04-26 16:18:28 -0700 | [diff] [blame] | 768 | |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 769 | private class ApplicationThread extends IApplicationThread.Stub { |
Vasu Nori | 3c7131f | 2010-09-21 14:36:57 -0700 | [diff] [blame] | 770 | private static final String DB_INFO_FORMAT = " %8s %8s %14s %14s %s"; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 771 | |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 772 | private int mLastProcessState = -1; |
| 773 | |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 774 | private void updatePendingConfiguration(Configuration config) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 775 | synchronized (mResourcesManager) { |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 776 | if (mPendingConfiguration == null || |
| 777 | mPendingConfiguration.isOtherSeqNewer(config)) { |
| 778 | mPendingConfiguration = config; |
| 779 | } |
| 780 | } |
| 781 | } |
| 782 | |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 783 | public final void scheduleSleeping(IBinder token, boolean sleeping) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 784 | sendMessage(H.SLEEPING, token, sleeping ? 1 : 0); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 785 | } |
| 786 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 787 | public final void scheduleReceiver(Intent intent, ActivityInfo info, |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 788 | CompatibilityInfo compatInfo, int resultCode, String data, Bundle extras, |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 789 | boolean sync, int sendingUser, int processState) { |
| 790 | updateProcessState(processState, false); |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 791 | ReceiverData r = new ReceiverData(intent, resultCode, data, extras, |
Dianne Hackborn | 20e8098 | 2012-08-31 19:00:44 -0700 | [diff] [blame] | 792 | sync, false, mAppThread.asBinder(), sendingUser); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 793 | r.info = info; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 794 | r.compatInfo = compatInfo; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 795 | sendMessage(H.RECEIVER, r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 796 | } |
| 797 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 798 | public final void scheduleCreateBackupAgent(ApplicationInfo app, |
| 799 | CompatibilityInfo compatInfo, int backupMode) { |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 800 | CreateBackupAgentData d = new CreateBackupAgentData(); |
| 801 | d.appInfo = app; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 802 | d.compatInfo = compatInfo; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 803 | d.backupMode = backupMode; |
| 804 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 805 | sendMessage(H.CREATE_BACKUP_AGENT, d); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 806 | } |
| 807 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 808 | public final void scheduleDestroyBackupAgent(ApplicationInfo app, |
| 809 | CompatibilityInfo compatInfo) { |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 810 | CreateBackupAgentData d = new CreateBackupAgentData(); |
| 811 | d.appInfo = app; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 812 | d.compatInfo = compatInfo; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 813 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 814 | sendMessage(H.DESTROY_BACKUP_AGENT, d); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 815 | } |
| 816 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 817 | public final void scheduleCreateService(IBinder token, |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 818 | ServiceInfo info, CompatibilityInfo compatInfo, int processState) { |
| 819 | updateProcessState(processState, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 820 | CreateServiceData s = new CreateServiceData(); |
| 821 | s.token = token; |
| 822 | s.info = info; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 823 | s.compatInfo = compatInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 824 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 825 | sendMessage(H.CREATE_SERVICE, s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 826 | } |
| 827 | |
| 828 | public final void scheduleBindService(IBinder token, Intent intent, |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 829 | boolean rebind, int processState) { |
| 830 | updateProcessState(processState, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 831 | BindServiceData s = new BindServiceData(); |
| 832 | s.token = token; |
| 833 | s.intent = intent; |
| 834 | s.rebind = rebind; |
| 835 | |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 836 | if (DEBUG_SERVICE) |
| 837 | Slog.v(TAG, "scheduleBindService token=" + token + " intent=" + intent + " uid=" |
| 838 | + Binder.getCallingUid() + " pid=" + Binder.getCallingPid()); |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 839 | sendMessage(H.BIND_SERVICE, s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 840 | } |
| 841 | |
| 842 | public final void scheduleUnbindService(IBinder token, Intent intent) { |
| 843 | BindServiceData s = new BindServiceData(); |
| 844 | s.token = token; |
| 845 | s.intent = intent; |
| 846 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 847 | sendMessage(H.UNBIND_SERVICE, s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 848 | } |
| 849 | |
Dianne Hackborn | 3f7c9f2 | 2017-04-04 15:36:33 -0700 | [diff] [blame] | 850 | public final void scheduleServiceArgs(IBinder token, ParceledListSlice args) { |
| 851 | List<ServiceStartArgs> list = args.getList(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 852 | |
Dianne Hackborn | 3f7c9f2 | 2017-04-04 15:36:33 -0700 | [diff] [blame] | 853 | for (int i = 0; i < list.size(); i++) { |
| 854 | ServiceStartArgs ssa = list.get(i); |
| 855 | ServiceArgsData s = new ServiceArgsData(); |
| 856 | s.token = token; |
| 857 | s.taskRemoved = ssa.taskRemoved; |
| 858 | s.startId = ssa.startId; |
| 859 | s.flags = ssa.flags; |
| 860 | s.args = ssa.args; |
| 861 | |
| 862 | sendMessage(H.SERVICE_ARGS, s); |
| 863 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 864 | } |
| 865 | |
| 866 | public final void scheduleStopService(IBinder token) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 867 | sendMessage(H.STOP_SERVICE, token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 868 | } |
| 869 | |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 870 | public final void bindApplication(String processName, ApplicationInfo appInfo, |
| 871 | List<ProviderInfo> providers, ComponentName instrumentationName, |
| 872 | ProfilerInfo profilerInfo, Bundle instrumentationArgs, |
| 873 | IInstrumentationWatcher instrumentationWatcher, |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 874 | IUiAutomationConnection instrumentationUiConnection, int debugMode, |
Pablo Ceballos | a4d4e82 | 2015-10-05 10:27:52 -0700 | [diff] [blame] | 875 | boolean enableBinderTracking, boolean trackAllocation, |
| 876 | boolean isRestrictedBackupMode, boolean persistent, Configuration config, |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 877 | CompatibilityInfo compatInfo, Map services, Bundle coreSettings, |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 878 | String buildSerial, boolean autofillCompatibilityEnabled) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 879 | |
| 880 | if (services != null) { |
| 881 | // Setup the service cache in the ServiceManager |
| 882 | ServiceManager.initServiceCache(services); |
| 883 | } |
| 884 | |
Svetoslav Ganov | 9aa597e | 2011-03-03 18:17:41 -0800 | [diff] [blame] | 885 | setCoreSettings(coreSettings); |
| 886 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 887 | AppBindData data = new AppBindData(); |
| 888 | data.processName = processName; |
| 889 | data.appInfo = appInfo; |
| 890 | data.providers = providers; |
| 891 | data.instrumentationName = instrumentationName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 892 | data.instrumentationArgs = instrumentationArgs; |
| 893 | data.instrumentationWatcher = instrumentationWatcher; |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 894 | data.instrumentationUiAutomationConnection = instrumentationUiConnection; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 895 | data.debugMode = debugMode; |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 896 | data.enableBinderTracking = enableBinderTracking; |
Man Cao | cfa78b2 | 2015-06-11 20:14:34 -0700 | [diff] [blame] | 897 | data.trackAllocation = trackAllocation; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 898 | data.restrictedBackupMode = isRestrictedBackupMode; |
Dianne Hackborn | 5d927c2 | 2011-09-02 12:22:18 -0700 | [diff] [blame] | 899 | data.persistent = persistent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 900 | data.config = config; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 901 | data.compatInfo = compatInfo; |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 902 | data.initProfilerInfo = profilerInfo; |
Svet Ganov | 37e4327 | 2016-09-09 16:01:32 -0700 | [diff] [blame] | 903 | data.buildSerial = buildSerial; |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 904 | data.autofillCompatibilityEnabled = autofillCompatibilityEnabled; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 905 | sendMessage(H.BIND_APPLICATION, data); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 906 | } |
| 907 | |
Torne (Richard Coles) | 466cbe4 | 2017-05-31 14:09:14 -0400 | [diff] [blame] | 908 | public final void runIsolatedEntryPoint(String entryPoint, String[] entryPointArgs) { |
| 909 | SomeArgs args = SomeArgs.obtain(); |
| 910 | args.arg1 = entryPoint; |
| 911 | args.arg2 = entryPointArgs; |
| 912 | sendMessage(H.RUN_ISOLATED_ENTRY_POINT, args); |
| 913 | } |
| 914 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 915 | public final void scheduleExit() { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 916 | sendMessage(H.EXIT_APPLICATION, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 917 | } |
| 918 | |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 919 | public final void scheduleSuicide() { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 920 | sendMessage(H.SUICIDE, null); |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 921 | } |
| 922 | |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 923 | public void scheduleApplicationInfoChanged(ApplicationInfo ai) { |
| 924 | sendMessage(H.APPLICATION_INFO_CHANGED, ai); |
| 925 | } |
| 926 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 927 | public void updateTimeZone() { |
| 928 | TimeZone.setDefault(null); |
| 929 | } |
| 930 | |
Robert Greenwalt | 03595d0 | 2010-11-02 14:08:23 -0700 | [diff] [blame] | 931 | public void clearDnsCache() { |
| 932 | // a non-standard API to get this to libcore |
| 933 | InetAddress.clearDnsCache(); |
Paul Jensen | e401d17 | 2014-09-12 10:47:39 -0400 | [diff] [blame] | 934 | // Allow libcore to perform the necessary actions as it sees fit upon a network |
| 935 | // configuration change. |
| 936 | NetworkEventDispatcher.getInstance().onNetworkConfigurationChanged(); |
Robert Greenwalt | 03595d0 | 2010-11-02 14:08:23 -0700 | [diff] [blame] | 937 | } |
| 938 | |
Jason Monk | 83520b9 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 939 | public void setHttpProxy(String host, String port, String exclList, Uri pacFileUrl) { |
Paul Jensen | 72db88e | 2015-03-10 10:54:12 -0400 | [diff] [blame] | 940 | final ConnectivityManager cm = ConnectivityManager.from(getSystemContext()); |
| 941 | final Network network = cm.getBoundNetworkForProcess(); |
Paul Jensen | e0bef71 | 2014-12-10 15:12:18 -0500 | [diff] [blame] | 942 | if (network != null) { |
Paul Jensen | 72db88e | 2015-03-10 10:54:12 -0400 | [diff] [blame] | 943 | Proxy.setHttpProxySystemProperty(cm.getDefaultProxy()); |
Paul Jensen | e0bef71 | 2014-12-10 15:12:18 -0500 | [diff] [blame] | 944 | } else { |
| 945 | Proxy.setHttpProxySystemProperty(host, port, exclList, pacFileUrl); |
| 946 | } |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 947 | } |
| 948 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 949 | public void processInBackground() { |
| 950 | mH.removeMessages(H.GC_WHEN_IDLE); |
| 951 | mH.sendMessage(mH.obtainMessage(H.GC_WHEN_IDLE)); |
| 952 | } |
| 953 | |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 954 | public void dumpService(ParcelFileDescriptor pfd, IBinder servicetoken, String[] args) { |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 955 | DumpComponentInfo data = new DumpComponentInfo(); |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 956 | try { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 957 | data.fd = pfd.dup(); |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 958 | data.token = servicetoken; |
| 959 | data.args = args; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 960 | sendMessage(H.DUMP_SERVICE, data, 0, 0, true /*async*/); |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 961 | } catch (IOException e) { |
| 962 | Slog.w(TAG, "dumpService failed", e); |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 963 | } finally { |
| 964 | IoUtils.closeQuietly(pfd); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 965 | } |
| 966 | } |
| 967 | |
| 968 | // This function exists to make sure all receiver dispatching is |
| 969 | // correctly ordered, since these are one-way calls and the binder driver |
| 970 | // applies transaction ordering per object for such calls. |
| 971 | public void scheduleRegisteredReceiver(IIntentReceiver receiver, Intent intent, |
Dianne Hackborn | 68d881c | 2009-10-05 13:58:17 -0700 | [diff] [blame] | 972 | int resultCode, String dataStr, Bundle extras, boolean ordered, |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 973 | boolean sticky, int sendingUser, int processState) throws RemoteException { |
| 974 | updateProcessState(processState, false); |
Dianne Hackborn | 20e8098 | 2012-08-31 19:00:44 -0700 | [diff] [blame] | 975 | receiver.performReceive(intent, resultCode, dataStr, extras, ordered, |
| 976 | sticky, sendingUser); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 977 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 978 | |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 979 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 980 | public void scheduleLowMemory() { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 981 | sendMessage(H.LOW_MEMORY, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 982 | } |
| 983 | |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 984 | @Override |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 985 | public void profilerControl(boolean start, ProfilerInfo profilerInfo, int profileType) { |
| 986 | sendMessage(H.PROFILER_CONTROL, profilerInfo, start ? 1 : 0, profileType); |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 987 | } |
| 988 | |
Makoto Onuki | 4556b7b | 2017-07-07 14:58:58 -0700 | [diff] [blame] | 989 | @Override |
Christopher Ferris | 8d652f8 | 2017-04-11 16:29:18 -0700 | [diff] [blame] | 990 | public void dumpHeap(boolean managed, boolean mallocInfo, boolean runGc, String path, |
| 991 | ParcelFileDescriptor fd) { |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 992 | DumpHeapData dhd = new DumpHeapData(); |
Christopher Ferris | 8d652f8 | 2017-04-11 16:29:18 -0700 | [diff] [blame] | 993 | dhd.managed = managed; |
| 994 | dhd.mallocInfo = mallocInfo; |
Makoto Onuki | 4556b7b | 2017-07-07 14:58:58 -0700 | [diff] [blame] | 995 | dhd.runGc = runGc; |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 996 | dhd.path = path; |
| 997 | dhd.fd = fd; |
Christopher Ferris | 8d652f8 | 2017-04-11 16:29:18 -0700 | [diff] [blame] | 998 | sendMessage(H.DUMP_HEAP, dhd, 0, 0, true /*async*/); |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 999 | } |
| 1000 | |
Leonard Mosescu | f3409ce | 2016-10-06 17:32:05 -0700 | [diff] [blame] | 1001 | public void attachAgent(String agent) { |
| 1002 | sendMessage(H.ATTACH_AGENT, agent); |
| 1003 | } |
| 1004 | |
Dianne Hackborn | 06de2ea | 2009-05-21 12:56:43 -0700 | [diff] [blame] | 1005 | public void setSchedulingGroup(int group) { |
| 1006 | // Note: do this immediately, since going into the foreground |
| 1007 | // should happen regardless of what pending work we have to do |
| 1008 | // and the activity manager will wait for us to report back that |
| 1009 | // we are done before sending us to the background. |
| 1010 | try { |
| 1011 | Process.setProcessGroup(Process.myPid(), group); |
| 1012 | } catch (Exception e) { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 1013 | Slog.w(TAG, "Failed setting process group to " + group, e); |
Dianne Hackborn | 06de2ea | 2009-05-21 12:56:43 -0700 | [diff] [blame] | 1014 | } |
| 1015 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1016 | |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1017 | public void dispatchPackageBroadcast(int cmd, String[] packages) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1018 | sendMessage(H.DISPATCH_PACKAGE_BROADCAST, packages, cmd); |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1019 | } |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 1020 | |
| 1021 | public void scheduleCrash(String msg) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1022 | sendMessage(H.SCHEDULE_CRASH, msg); |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 1023 | } |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1024 | |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1025 | public void dumpActivity(ParcelFileDescriptor pfd, IBinder activitytoken, |
Dianne Hackborn | 30d7189 | 2010-12-11 10:37:55 -0800 | [diff] [blame] | 1026 | String prefix, String[] args) { |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1027 | DumpComponentInfo data = new DumpComponentInfo(); |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 1028 | try { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1029 | data.fd = pfd.dup(); |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 1030 | data.token = activitytoken; |
| 1031 | data.prefix = prefix; |
| 1032 | data.args = args; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1033 | sendMessage(H.DUMP_ACTIVITY, data, 0, 0, true /*async*/); |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 1034 | } catch (IOException e) { |
| 1035 | Slog.w(TAG, "dumpActivity failed", e); |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1036 | } finally { |
| 1037 | IoUtils.closeQuietly(pfd); |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1038 | } |
| 1039 | } |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 1040 | |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1041 | public void dumpProvider(ParcelFileDescriptor pfd, IBinder providertoken, |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1042 | String[] args) { |
| 1043 | DumpComponentInfo data = new DumpComponentInfo(); |
| 1044 | try { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1045 | data.fd = pfd.dup(); |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1046 | data.token = providertoken; |
| 1047 | data.args = args; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1048 | sendMessage(H.DUMP_PROVIDER, data, 0, 0, true /*async*/); |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1049 | } catch (IOException e) { |
| 1050 | Slog.w(TAG, "dumpProvider failed", e); |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1051 | } finally { |
| 1052 | IoUtils.closeQuietly(pfd); |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1053 | } |
| 1054 | } |
| 1055 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1056 | @Override |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1057 | public void dumpMemInfo(ParcelFileDescriptor pfd, Debug.MemoryInfo mem, boolean checkin, |
Colin Cross | c4fb5f9 | 2016-02-02 16:51:15 -0800 | [diff] [blame] | 1058 | boolean dumpFullInfo, boolean dumpDalvik, boolean dumpSummaryOnly, |
| 1059 | boolean dumpUnreachable, String[] args) { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1060 | FileOutputStream fout = new FileOutputStream(pfd.getFileDescriptor()); |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 1061 | PrintWriter pw = new FastPrintWriter(fout); |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 1062 | try { |
Colin Cross | c4fb5f9 | 2016-02-02 16:51:15 -0800 | [diff] [blame] | 1063 | dumpMemInfo(pw, mem, checkin, dumpFullInfo, dumpDalvik, dumpSummaryOnly, dumpUnreachable); |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 1064 | } finally { |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 1065 | pw.flush(); |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1066 | IoUtils.closeQuietly(pfd); |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 1067 | } |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 1068 | } |
| 1069 | |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 1070 | private void dumpMemInfo(PrintWriter pw, Debug.MemoryInfo memInfo, boolean checkin, |
Colin Cross | c4fb5f9 | 2016-02-02 16:51:15 -0800 | [diff] [blame] | 1071 | boolean dumpFullInfo, boolean dumpDalvik, boolean dumpSummaryOnly, boolean dumpUnreachable) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1072 | long nativeMax = Debug.getNativeHeapSize() / 1024; |
| 1073 | long nativeAllocated = Debug.getNativeHeapAllocatedSize() / 1024; |
| 1074 | long nativeFree = Debug.getNativeHeapFreeSize() / 1024; |
| 1075 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1076 | Runtime runtime = Runtime.getRuntime(); |
Mathieu Chartier | d288a26 | 2015-07-10 13:44:42 -0700 | [diff] [blame] | 1077 | runtime.gc(); // Do GC since countInstancesOfClass counts unreachable objects. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1078 | long dalvikMax = runtime.totalMemory() / 1024; |
| 1079 | long dalvikFree = runtime.freeMemory() / 1024; |
| 1080 | long dalvikAllocated = dalvikMax - dalvikFree; |
Richard Uhler | 2c03619 | 2016-09-14 09:48:31 +0100 | [diff] [blame] | 1081 | |
| 1082 | Class[] classesToCount = new Class[] { |
| 1083 | ContextImpl.class, |
| 1084 | Activity.class, |
| 1085 | WebView.class, |
| 1086 | OpenSSLSocketImpl.class |
| 1087 | }; |
| 1088 | long[] instanceCounts = VMDebug.countInstancesOfClasses(classesToCount, true); |
| 1089 | long appContextInstanceCount = instanceCounts[0]; |
| 1090 | long activityInstanceCount = instanceCounts[1]; |
| 1091 | long webviewInstanceCount = instanceCounts[2]; |
| 1092 | long openSslSocketCount = instanceCounts[3]; |
| 1093 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1094 | long viewInstanceCount = ViewDebug.getViewInstanceCount(); |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1095 | long viewRootInstanceCount = ViewDebug.getViewRootImplCount(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1096 | int globalAssetCount = AssetManager.getGlobalAssetCount(); |
| 1097 | int globalAssetManagerCount = AssetManager.getGlobalAssetManagerCount(); |
| 1098 | int binderLocalObjectCount = Debug.getBinderLocalObjectCount(); |
| 1099 | int binderProxyObjectCount = Debug.getBinderProxyObjectCount(); |
| 1100 | int binderDeathObjectCount = Debug.getBinderDeathObjectCount(); |
Dianne Hackborn | fabb70b | 2014-11-11 12:22:36 -0800 | [diff] [blame] | 1101 | long parcelSize = Parcel.getGlobalAllocSize(); |
| 1102 | long parcelCount = Parcel.getGlobalAllocCount(); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1103 | SQLiteDebug.PagerStats stats = SQLiteDebug.getDatabaseInfo(); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1104 | |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 1105 | dumpMemInfoTable(pw, memInfo, checkin, dumpFullInfo, dumpDalvik, dumpSummaryOnly, |
| 1106 | Process.myPid(), |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 1107 | (mBoundApplication != null) ? mBoundApplication.processName : "unknown", |
| 1108 | nativeMax, nativeAllocated, nativeFree, |
| 1109 | dalvikMax, dalvikAllocated, dalvikFree); |
| 1110 | |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 1111 | if (checkin) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1112 | // NOTE: if you change anything significant below, also consider changing |
| 1113 | // ACTIVITY_THREAD_CHECKIN_VERSION. |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 1114 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1115 | // Object counts |
| 1116 | pw.print(viewInstanceCount); pw.print(','); |
| 1117 | pw.print(viewRootInstanceCount); pw.print(','); |
| 1118 | pw.print(appContextInstanceCount); pw.print(','); |
| 1119 | pw.print(activityInstanceCount); pw.print(','); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1120 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1121 | pw.print(globalAssetCount); pw.print(','); |
| 1122 | pw.print(globalAssetManagerCount); pw.print(','); |
| 1123 | pw.print(binderLocalObjectCount); pw.print(','); |
| 1124 | pw.print(binderProxyObjectCount); pw.print(','); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1125 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1126 | pw.print(binderDeathObjectCount); pw.print(','); |
| 1127 | pw.print(openSslSocketCount); pw.print(','); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1128 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1129 | // SQL |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1130 | pw.print(stats.memoryUsed / 1024); pw.print(','); |
Jeff Brown | 2a293b6 | 2012-01-19 14:02:22 -0800 | [diff] [blame] | 1131 | pw.print(stats.memoryUsed / 1024); pw.print(','); |
| 1132 | pw.print(stats.pageCacheOverflow / 1024); pw.print(','); |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 1133 | pw.print(stats.largestMemAlloc / 1024); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1134 | for (int i = 0; i < stats.dbStats.size(); i++) { |
| 1135 | DbStats dbStats = stats.dbStats.get(i); |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 1136 | pw.print(','); pw.print(dbStats.dbName); |
| 1137 | pw.print(','); pw.print(dbStats.pageSize); |
| 1138 | pw.print(','); pw.print(dbStats.dbSize); |
| 1139 | pw.print(','); pw.print(dbStats.lookaside); |
| 1140 | pw.print(','); pw.print(dbStats.cache); |
| 1141 | pw.print(','); pw.print(dbStats.cache); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1142 | } |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 1143 | pw.println(); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1144 | |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 1145 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1146 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1147 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1148 | pw.println(" "); |
| 1149 | pw.println(" Objects"); |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1150 | printRow(pw, TWO_COUNT_COLUMNS, "Views:", viewInstanceCount, "ViewRootImpl:", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1151 | viewRootInstanceCount); |
| 1152 | |
| 1153 | printRow(pw, TWO_COUNT_COLUMNS, "AppContexts:", appContextInstanceCount, |
| 1154 | "Activities:", activityInstanceCount); |
| 1155 | |
| 1156 | printRow(pw, TWO_COUNT_COLUMNS, "Assets:", globalAssetCount, |
| 1157 | "AssetManagers:", globalAssetManagerCount); |
| 1158 | |
| 1159 | printRow(pw, TWO_COUNT_COLUMNS, "Local Binders:", binderLocalObjectCount, |
| 1160 | "Proxy Binders:", binderProxyObjectCount); |
Dianne Hackborn | fabb70b | 2014-11-11 12:22:36 -0800 | [diff] [blame] | 1161 | printRow(pw, TWO_COUNT_COLUMNS, "Parcel memory:", parcelSize/1024, |
| 1162 | "Parcel count:", parcelCount); |
| 1163 | printRow(pw, TWO_COUNT_COLUMNS, "Death Recipients:", binderDeathObjectCount, |
| 1164 | "OpenSSL Sockets:", openSslSocketCount); |
Richard Uhler | 2c03619 | 2016-09-14 09:48:31 +0100 | [diff] [blame] | 1165 | printRow(pw, ONE_COUNT_COLUMN, "WebViews:", webviewInstanceCount); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1166 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1167 | // SQLite mem info |
| 1168 | pw.println(" "); |
| 1169 | pw.println(" SQL"); |
Jeff Brown | 2a293b6 | 2012-01-19 14:02:22 -0800 | [diff] [blame] | 1170 | printRow(pw, ONE_COUNT_COLUMN, "MEMORY_USED:", stats.memoryUsed / 1024); |
| 1171 | printRow(pw, TWO_COUNT_COLUMNS, "PAGECACHE_OVERFLOW:", |
| 1172 | stats.pageCacheOverflow / 1024, "MALLOC_SIZE:", stats.largestMemAlloc / 1024); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1173 | pw.println(" "); |
| 1174 | int N = stats.dbStats.size(); |
| 1175 | if (N > 0) { |
| 1176 | pw.println(" DATABASES"); |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 1177 | printRow(pw, DB_INFO_FORMAT, "pgsz", "dbsz", "Lookaside(b)", "cache", |
Vasu Nori | 3c7131f | 2010-09-21 14:36:57 -0700 | [diff] [blame] | 1178 | "Dbname"); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1179 | for (int i = 0; i < N; i++) { |
| 1180 | DbStats dbStats = stats.dbStats.get(i); |
Vasu Nori | 3c7131f | 2010-09-21 14:36:57 -0700 | [diff] [blame] | 1181 | printRow(pw, DB_INFO_FORMAT, |
| 1182 | (dbStats.pageSize > 0) ? String.valueOf(dbStats.pageSize) : " ", |
| 1183 | (dbStats.dbSize > 0) ? String.valueOf(dbStats.dbSize) : " ", |
| 1184 | (dbStats.lookaside > 0) ? String.valueOf(dbStats.lookaside) : " ", |
| 1185 | dbStats.cache, dbStats.dbName); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1186 | } |
| 1187 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1188 | |
Dianne Hackborn | 82e1ee9 | 2009-08-11 18:56:41 -0700 | [diff] [blame] | 1189 | // Asset details. |
| 1190 | String assetAlloc = AssetManager.getAssetAllocations(); |
| 1191 | if (assetAlloc != null) { |
| 1192 | pw.println(" "); |
| 1193 | pw.println(" Asset Allocations"); |
| 1194 | pw.print(assetAlloc); |
| 1195 | } |
Colin Cross | c4fb5f9 | 2016-02-02 16:51:15 -0800 | [diff] [blame] | 1196 | |
| 1197 | // Unreachable native memory |
| 1198 | if (dumpUnreachable) { |
| 1199 | boolean showContents = ((mBoundApplication != null) |
| 1200 | && ((mBoundApplication.appInfo.flags&ApplicationInfo.FLAG_DEBUGGABLE) != 0)) |
| 1201 | || android.os.Build.IS_DEBUGGABLE; |
| 1202 | pw.println(" "); |
| 1203 | pw.println(" Unreachable memory"); |
| 1204 | pw.print(Debug.getUnreachableMemory(100, showContents)); |
| 1205 | } |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 1206 | } |
| 1207 | |
| 1208 | @Override |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 1209 | public void dumpMemInfoProto(ParcelFileDescriptor pfd, Debug.MemoryInfo mem, |
| 1210 | boolean dumpFullInfo, boolean dumpDalvik, boolean dumpSummaryOnly, |
| 1211 | boolean dumpUnreachable, String[] args) { |
| 1212 | ProtoOutputStream proto = new ProtoOutputStream(pfd.getFileDescriptor()); |
| 1213 | try { |
| 1214 | dumpMemInfo(proto, mem, dumpFullInfo, dumpDalvik, dumpSummaryOnly, dumpUnreachable); |
| 1215 | } finally { |
| 1216 | proto.flush(); |
| 1217 | IoUtils.closeQuietly(pfd); |
| 1218 | } |
| 1219 | } |
| 1220 | |
| 1221 | private void dumpMemInfo(ProtoOutputStream proto, Debug.MemoryInfo memInfo, |
| 1222 | boolean dumpFullInfo, boolean dumpDalvik, |
| 1223 | boolean dumpSummaryOnly, boolean dumpUnreachable) { |
| 1224 | long nativeMax = Debug.getNativeHeapSize() / 1024; |
| 1225 | long nativeAllocated = Debug.getNativeHeapAllocatedSize() / 1024; |
| 1226 | long nativeFree = Debug.getNativeHeapFreeSize() / 1024; |
| 1227 | |
| 1228 | Runtime runtime = Runtime.getRuntime(); |
| 1229 | runtime.gc(); // Do GC since countInstancesOfClass counts unreachable objects. |
| 1230 | long dalvikMax = runtime.totalMemory() / 1024; |
| 1231 | long dalvikFree = runtime.freeMemory() / 1024; |
| 1232 | long dalvikAllocated = dalvikMax - dalvikFree; |
| 1233 | |
| 1234 | Class[] classesToCount = new Class[] { |
| 1235 | ContextImpl.class, |
| 1236 | Activity.class, |
| 1237 | WebView.class, |
| 1238 | OpenSSLSocketImpl.class |
| 1239 | }; |
| 1240 | long[] instanceCounts = VMDebug.countInstancesOfClasses(classesToCount, true); |
| 1241 | long appContextInstanceCount = instanceCounts[0]; |
| 1242 | long activityInstanceCount = instanceCounts[1]; |
| 1243 | long webviewInstanceCount = instanceCounts[2]; |
| 1244 | long openSslSocketCount = instanceCounts[3]; |
| 1245 | |
| 1246 | long viewInstanceCount = ViewDebug.getViewInstanceCount(); |
| 1247 | long viewRootInstanceCount = ViewDebug.getViewRootImplCount(); |
| 1248 | int globalAssetCount = AssetManager.getGlobalAssetCount(); |
| 1249 | int globalAssetManagerCount = AssetManager.getGlobalAssetManagerCount(); |
| 1250 | int binderLocalObjectCount = Debug.getBinderLocalObjectCount(); |
| 1251 | int binderProxyObjectCount = Debug.getBinderProxyObjectCount(); |
| 1252 | int binderDeathObjectCount = Debug.getBinderDeathObjectCount(); |
| 1253 | long parcelSize = Parcel.getGlobalAllocSize(); |
| 1254 | long parcelCount = Parcel.getGlobalAllocCount(); |
| 1255 | SQLiteDebug.PagerStats stats = SQLiteDebug.getDatabaseInfo(); |
| 1256 | |
| 1257 | final long mToken = proto.start(MemInfoProto.AppData.PROCESS_MEMORY); |
| 1258 | proto.write(MemInfoProto.ProcessMemory.PID, Process.myPid()); |
| 1259 | proto.write(MemInfoProto.ProcessMemory.PROCESS_NAME, |
| 1260 | (mBoundApplication != null) ? mBoundApplication.processName : "unknown"); |
| 1261 | dumpMemInfoTable(proto, memInfo, dumpDalvik, dumpSummaryOnly, |
| 1262 | nativeMax, nativeAllocated, nativeFree, |
| 1263 | dalvikMax, dalvikAllocated, dalvikFree); |
| 1264 | proto.end(mToken); |
| 1265 | |
| 1266 | final long oToken = proto.start(MemInfoProto.AppData.OBJECTS); |
| 1267 | proto.write(MemInfoProto.AppData.ObjectStats.VIEW_INSTANCE_COUNT, viewInstanceCount); |
| 1268 | proto.write(MemInfoProto.AppData.ObjectStats.VIEW_ROOT_INSTANCE_COUNT, |
| 1269 | viewRootInstanceCount); |
| 1270 | proto.write(MemInfoProto.AppData.ObjectStats.APP_CONTEXT_INSTANCE_COUNT, |
| 1271 | appContextInstanceCount); |
| 1272 | proto.write(MemInfoProto.AppData.ObjectStats.ACTIVITY_INSTANCE_COUNT, |
| 1273 | activityInstanceCount); |
| 1274 | proto.write(MemInfoProto.AppData.ObjectStats.GLOBAL_ASSET_COUNT, globalAssetCount); |
| 1275 | proto.write(MemInfoProto.AppData.ObjectStats.GLOBAL_ASSET_MANAGER_COUNT, |
| 1276 | globalAssetManagerCount); |
| 1277 | proto.write(MemInfoProto.AppData.ObjectStats.LOCAL_BINDER_OBJECT_COUNT, |
| 1278 | binderLocalObjectCount); |
| 1279 | proto.write(MemInfoProto.AppData.ObjectStats.PROXY_BINDER_OBJECT_COUNT, |
| 1280 | binderProxyObjectCount); |
| 1281 | proto.write(MemInfoProto.AppData.ObjectStats.PARCEL_MEMORY_KB, parcelSize / 1024); |
| 1282 | proto.write(MemInfoProto.AppData.ObjectStats.PARCEL_COUNT, parcelCount); |
| 1283 | proto.write(MemInfoProto.AppData.ObjectStats.BINDER_OBJECT_DEATH_COUNT, |
| 1284 | binderDeathObjectCount); |
| 1285 | proto.write(MemInfoProto.AppData.ObjectStats.OPEN_SSL_SOCKET_COUNT, openSslSocketCount); |
| 1286 | proto.write(MemInfoProto.AppData.ObjectStats.WEBVIEW_INSTANCE_COUNT, |
| 1287 | webviewInstanceCount); |
| 1288 | proto.end(oToken); |
| 1289 | |
| 1290 | // SQLite mem info |
| 1291 | final long sToken = proto.start(MemInfoProto.AppData.SQL); |
| 1292 | proto.write(MemInfoProto.AppData.SqlStats.MEMORY_USED_KB, stats.memoryUsed / 1024); |
| 1293 | proto.write(MemInfoProto.AppData.SqlStats.PAGECACHE_OVERFLOW_KB, |
| 1294 | stats.pageCacheOverflow / 1024); |
| 1295 | proto.write(MemInfoProto.AppData.SqlStats.MALLOC_SIZE_KB, stats.largestMemAlloc / 1024); |
| 1296 | int n = stats.dbStats.size(); |
| 1297 | for (int i = 0; i < n; i++) { |
| 1298 | DbStats dbStats = stats.dbStats.get(i); |
| 1299 | |
| 1300 | final long dToken = proto.start(MemInfoProto.AppData.SqlStats.DATABASES); |
| 1301 | proto.write(MemInfoProto.AppData.SqlStats.Database.NAME, dbStats.dbName); |
| 1302 | proto.write(MemInfoProto.AppData.SqlStats.Database.PAGE_SIZE, dbStats.pageSize); |
| 1303 | proto.write(MemInfoProto.AppData.SqlStats.Database.DB_SIZE, dbStats.dbSize); |
| 1304 | proto.write(MemInfoProto.AppData.SqlStats.Database.LOOKASIDE_B, dbStats.lookaside); |
| 1305 | proto.write(MemInfoProto.AppData.SqlStats.Database.CACHE, dbStats.cache); |
| 1306 | proto.end(dToken); |
| 1307 | } |
| 1308 | proto.end(sToken); |
| 1309 | |
| 1310 | // Asset details. |
| 1311 | String assetAlloc = AssetManager.getAssetAllocations(); |
| 1312 | if (assetAlloc != null) { |
| 1313 | proto.write(MemInfoProto.AppData.ASSET_ALLOCATIONS, assetAlloc); |
| 1314 | } |
| 1315 | |
| 1316 | // Unreachable native memory |
| 1317 | if (dumpUnreachable) { |
| 1318 | int flags = mBoundApplication == null ? 0 : mBoundApplication.appInfo.flags; |
| 1319 | boolean showContents = (flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0 |
| 1320 | || android.os.Build.IS_DEBUGGABLE; |
| 1321 | proto.write(MemInfoProto.AppData.UNREACHABLE_MEMORY, |
| 1322 | Debug.getUnreachableMemory(100, showContents)); |
| 1323 | } |
| 1324 | } |
| 1325 | |
| 1326 | @Override |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1327 | public void dumpGfxInfo(ParcelFileDescriptor pfd, String[] args) { |
Chris Craik | fc29424 | 2016-12-13 18:10:46 -0800 | [diff] [blame] | 1328 | nDumpGraphicsInfo(pfd.getFileDescriptor()); |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1329 | WindowManagerGlobal.getInstance().dumpGfxInfo(pfd.getFileDescriptor(), args); |
| 1330 | IoUtils.closeQuietly(pfd); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1331 | } |
| 1332 | |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1333 | private void dumpDatabaseInfo(ParcelFileDescriptor pfd, String[] args) { |
| 1334 | PrintWriter pw = new FastPrintWriter( |
| 1335 | new FileOutputStream(pfd.getFileDescriptor())); |
Jeff Brown | 6754ba2 | 2011-12-14 20:20:01 -0800 | [diff] [blame] | 1336 | PrintWriterPrinter printer = new PrintWriterPrinter(pw); |
| 1337 | SQLiteDebug.dump(printer, args); |
| 1338 | pw.flush(); |
| 1339 | } |
| 1340 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1341 | @Override |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1342 | public void dumpDbInfo(final ParcelFileDescriptor pfd, final String[] args) { |
riddle_hsu | 1d6c40a | 2014-07-31 00:18:00 +0800 | [diff] [blame] | 1343 | if (mSystemThread) { |
Felipe Leme | 29de492 | 2016-06-07 16:14:07 -0700 | [diff] [blame] | 1344 | // Ensure this invocation is asynchronous to prevent writer waiting if buffer cannot |
| 1345 | // be consumed. But it must duplicate the file descriptor first, since caller might |
| 1346 | // be closing it. |
| 1347 | final ParcelFileDescriptor dup; |
| 1348 | try { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1349 | dup = pfd.dup(); |
Felipe Leme | 29de492 | 2016-06-07 16:14:07 -0700 | [diff] [blame] | 1350 | } catch (IOException e) { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1351 | Log.w(TAG, "Could not dup FD " + pfd.getFileDescriptor().getInt$()); |
Felipe Leme | 29de492 | 2016-06-07 16:14:07 -0700 | [diff] [blame] | 1352 | return; |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1353 | } finally { |
| 1354 | IoUtils.closeQuietly(pfd); |
Felipe Leme | 29de492 | 2016-06-07 16:14:07 -0700 | [diff] [blame] | 1355 | } |
| 1356 | |
riddle_hsu | 1d6c40a | 2014-07-31 00:18:00 +0800 | [diff] [blame] | 1357 | AsyncTask.THREAD_POOL_EXECUTOR.execute(new Runnable() { |
| 1358 | @Override |
| 1359 | public void run() { |
Felipe Leme | c74972f | 2016-06-08 09:12:37 -0700 | [diff] [blame] | 1360 | try { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1361 | dumpDatabaseInfo(dup, args); |
Felipe Leme | c74972f | 2016-06-08 09:12:37 -0700 | [diff] [blame] | 1362 | } finally { |
| 1363 | IoUtils.closeQuietly(dup); |
| 1364 | } |
riddle_hsu | 1d6c40a | 2014-07-31 00:18:00 +0800 | [diff] [blame] | 1365 | } |
| 1366 | }); |
| 1367 | } else { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1368 | dumpDatabaseInfo(pfd, args); |
| 1369 | IoUtils.closeQuietly(pfd); |
riddle_hsu | 1d6c40a | 2014-07-31 00:18:00 +0800 | [diff] [blame] | 1370 | } |
| 1371 | } |
| 1372 | |
| 1373 | @Override |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1374 | public void unstableProviderDied(IBinder provider) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1375 | sendMessage(H.UNSTABLE_PROVIDER_DIED, provider); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1376 | } |
| 1377 | |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 1378 | @Override |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 1379 | public void requestAssistContextExtras(IBinder activityToken, IBinder requestToken, |
Svet Ganov | fd31f85 | 2017-04-26 15:54:27 -0700 | [diff] [blame] | 1380 | int requestType, int sessionId, int flags) { |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 1381 | RequestAssistContextExtras cmd = new RequestAssistContextExtras(); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 1382 | cmd.activityToken = activityToken; |
| 1383 | cmd.requestToken = requestToken; |
| 1384 | cmd.requestType = requestType; |
Amith Yamasani | 4f128e4 | 2016-05-10 11:44:12 -0700 | [diff] [blame] | 1385 | cmd.sessionId = sessionId; |
Svet Ganov | fd31f85 | 2017-04-26 15:54:27 -0700 | [diff] [blame] | 1386 | cmd.flags = flags; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1387 | sendMessage(H.REQUEST_ASSIST_CONTEXT_EXTRAS, cmd); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 1388 | } |
| 1389 | |
Svetoslav Ganov | 9aa597e | 2011-03-03 18:17:41 -0800 | [diff] [blame] | 1390 | public void setCoreSettings(Bundle coreSettings) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1391 | sendMessage(H.SET_CORE_SETTINGS, coreSettings); |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1392 | } |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1393 | |
| 1394 | public void updatePackageCompatibilityInfo(String pkg, CompatibilityInfo info) { |
| 1395 | UpdateCompatibilityData ucd = new UpdateCompatibilityData(); |
| 1396 | ucd.pkg = pkg; |
| 1397 | ucd.info = info; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1398 | sendMessage(H.UPDATE_PACKAGE_COMPATIBILITY_INFO, ucd); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1399 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1400 | |
| 1401 | public void scheduleTrimMemory(int level) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1402 | sendMessage(H.TRIM_MEMORY, null, level); |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1403 | } |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1404 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1405 | public void scheduleTranslucentConversionComplete(IBinder token, boolean drawComplete) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1406 | sendMessage(H.TRANSLUCENT_CONVERSION_COMPLETE, token, drawComplete ? 1 : 0); |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1407 | } |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 1408 | |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1409 | public void scheduleOnNewActivityOptions(IBinder token, Bundle options) { |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1410 | sendMessage(H.ON_NEW_ACTIVITY_OPTIONS, |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1411 | new Pair<IBinder, ActivityOptions>(token, ActivityOptions.fromBundle(options))); |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1412 | } |
| 1413 | |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 1414 | public void setProcessState(int state) { |
| 1415 | updateProcessState(state, true); |
| 1416 | } |
| 1417 | |
| 1418 | public void updateProcessState(int processState, boolean fromIpc) { |
| 1419 | synchronized (this) { |
| 1420 | if (mLastProcessState != processState) { |
| 1421 | mLastProcessState = processState; |
Mathieu Chartier | 1e37090 | 2013-07-18 10:58:01 -0700 | [diff] [blame] | 1422 | // Update Dalvik state based on ActivityManager.PROCESS_STATE_* constants. |
| 1423 | final int DALVIK_PROCESS_STATE_JANK_PERCEPTIBLE = 0; |
| 1424 | final int DALVIK_PROCESS_STATE_JANK_IMPERCEPTIBLE = 1; |
| 1425 | int dalvikProcessState = DALVIK_PROCESS_STATE_JANK_IMPERCEPTIBLE; |
| 1426 | // TODO: Tune this since things like gmail sync are important background but not jank perceptible. |
| 1427 | if (processState <= ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND) { |
| 1428 | dalvikProcessState = DALVIK_PROCESS_STATE_JANK_PERCEPTIBLE; |
| 1429 | } |
| 1430 | VMRuntime.getRuntime().updateProcessState(dalvikProcessState); |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 1431 | if (false) { |
| 1432 | Slog.i(TAG, "******************* PROCESS STATE CHANGED TO: " + processState |
| 1433 | + (fromIpc ? " (from ipc": "")); |
| 1434 | } |
| 1435 | } |
| 1436 | } |
| 1437 | } |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 1438 | |
Sudheer Shanka | 84a4895 | 2017-03-08 18:19:01 -0800 | [diff] [blame] | 1439 | /** |
| 1440 | * Updates {@link #mNetworkBlockSeq}. This is used by ActivityManagerService to inform |
| 1441 | * the main thread that it needs to wait for the network rules to get updated before |
| 1442 | * launching an activity. |
| 1443 | */ |
| 1444 | @Override |
| 1445 | public void setNetworkBlockSeq(long procStateSeq) { |
| 1446 | synchronized (mNetworkPolicyLock) { |
| 1447 | mNetworkBlockSeq = procStateSeq; |
| 1448 | } |
| 1449 | } |
| 1450 | |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 1451 | @Override |
| 1452 | public void scheduleInstallProvider(ProviderInfo provider) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1453 | sendMessage(H.INSTALL_PROVIDER, provider); |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 1454 | } |
Narayan Kamath | ccb2a086 | 2013-12-19 14:49:36 +0000 | [diff] [blame] | 1455 | |
| 1456 | @Override |
Neil Fuller | b7146fe | 2016-11-15 16:52:15 +0000 | [diff] [blame] | 1457 | public final void updateTimePrefs(int timeFormatPreference) { |
| 1458 | final Boolean timeFormatPreferenceBool; |
| 1459 | // For convenience we are using the Intent extra values. |
| 1460 | if (timeFormatPreference == Intent.EXTRA_TIME_PREF_VALUE_USE_12_HOUR) { |
| 1461 | timeFormatPreferenceBool = Boolean.FALSE; |
| 1462 | } else if (timeFormatPreference == Intent.EXTRA_TIME_PREF_VALUE_USE_24_HOUR) { |
| 1463 | timeFormatPreferenceBool = Boolean.TRUE; |
| 1464 | } else { |
| 1465 | // timeFormatPreference == Intent.EXTRA_TIME_PREF_VALUE_USE_LOCALE_DEFAULT |
| 1466 | // (or unknown). |
| 1467 | timeFormatPreferenceBool = null; |
| 1468 | } |
| 1469 | DateFormat.set24HourTimePref(timeFormatPreferenceBool); |
Narayan Kamath | ccb2a086 | 2013-12-19 14:49:36 +0000 | [diff] [blame] | 1470 | } |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 1471 | |
| 1472 | @Override |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 1473 | public void scheduleEnterAnimationComplete(IBinder token) { |
| 1474 | sendMessage(H.ENTER_ANIMATION_COMPLETE, token); |
| 1475 | } |
Jeff Sharkey | 605eb79 | 2014-11-04 13:34:06 -0800 | [diff] [blame] | 1476 | |
| 1477 | @Override |
| 1478 | public void notifyCleartextNetwork(byte[] firstPacket) { |
| 1479 | if (StrictMode.vmCleartextNetworkEnabled()) { |
| 1480 | StrictMode.onCleartextNetworkDetected(firstPacket); |
| 1481 | } |
| 1482 | } |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 1483 | |
| 1484 | @Override |
| 1485 | public void startBinderTracking() { |
| 1486 | sendMessage(H.START_BINDER_TRACKING, null); |
| 1487 | } |
| 1488 | |
| 1489 | @Override |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1490 | public void stopBinderTrackingAndDump(ParcelFileDescriptor pfd) { |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 1491 | try { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1492 | sendMessage(H.STOP_BINDER_TRACKING_AND_DUMP, pfd.dup()); |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 1493 | } catch (IOException e) { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1494 | } finally { |
| 1495 | IoUtils.closeQuietly(pfd); |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 1496 | } |
| 1497 | } |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 1498 | |
| 1499 | @Override |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1500 | public void scheduleLocalVoiceInteractionStarted(IBinder token, |
| 1501 | IVoiceInteractor voiceInteractor) throws RemoteException { |
| 1502 | SomeArgs args = SomeArgs.obtain(); |
| 1503 | args.arg1 = token; |
| 1504 | args.arg2 = voiceInteractor; |
| 1505 | sendMessage(H.LOCAL_VOICE_INTERACTION_STARTED, args); |
| 1506 | } |
Chad Brubaker | c72875b | 2016-04-27 16:35:11 -0700 | [diff] [blame] | 1507 | |
| 1508 | @Override |
| 1509 | public void handleTrustStorageUpdate() { |
| 1510 | NetworkSecurityPolicy.getInstance().handleTrustStorageUpdate(); |
| 1511 | } |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 1512 | |
| 1513 | @Override |
| 1514 | public void scheduleTransaction(ClientTransaction transaction) throws RemoteException { |
| 1515 | ActivityThread.this.scheduleTransaction(transaction); |
| 1516 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1517 | } |
| 1518 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 1519 | @Override |
| 1520 | public void updatePendingConfiguration(Configuration config) { |
| 1521 | mAppThread.updatePendingConfiguration(config); |
| 1522 | } |
| 1523 | |
| 1524 | @Override |
| 1525 | public void updateProcessState(int processState, boolean fromIpc) { |
| 1526 | mAppThread.updateProcessState(processState, fromIpc); |
| 1527 | } |
| 1528 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 1529 | class H extends Handler { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1530 | public static final int BIND_APPLICATION = 110; |
| 1531 | public static final int EXIT_APPLICATION = 111; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1532 | public static final int RECEIVER = 113; |
| 1533 | public static final int CREATE_SERVICE = 114; |
| 1534 | public static final int SERVICE_ARGS = 115; |
| 1535 | public static final int STOP_SERVICE = 116; |
Dianne Hackborn | 0923328 | 2014-04-30 11:33:59 -0700 | [diff] [blame] | 1536 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1537 | public static final int CONFIGURATION_CHANGED = 118; |
| 1538 | public static final int CLEAN_UP_CONTEXT = 119; |
| 1539 | public static final int GC_WHEN_IDLE = 120; |
| 1540 | public static final int BIND_SERVICE = 121; |
| 1541 | public static final int UNBIND_SERVICE = 122; |
| 1542 | public static final int DUMP_SERVICE = 123; |
| 1543 | public static final int LOW_MEMORY = 124; |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 1544 | public static final int PROFILER_CONTROL = 127; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1545 | public static final int CREATE_BACKUP_AGENT = 128; |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 1546 | public static final int DESTROY_BACKUP_AGENT = 129; |
| 1547 | public static final int SUICIDE = 130; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1548 | public static final int REMOVE_PROVIDER = 131; |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 1549 | public static final int ENABLE_JIT = 132; |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1550 | public static final int DISPATCH_PACKAGE_BROADCAST = 133; |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 1551 | public static final int SCHEDULE_CRASH = 134; |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 1552 | public static final int DUMP_HEAP = 135; |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1553 | public static final int DUMP_ACTIVITY = 136; |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1554 | public static final int SLEEPING = 137; |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1555 | public static final int SET_CORE_SETTINGS = 138; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1556 | public static final int UPDATE_PACKAGE_COMPATIBILITY_INFO = 139; |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1557 | public static final int TRIM_MEMORY = 140; |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1558 | public static final int DUMP_PROVIDER = 141; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1559 | public static final int UNSTABLE_PROVIDER_DIED = 142; |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 1560 | public static final int REQUEST_ASSIST_CONTEXT_EXTRAS = 143; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1561 | public static final int TRANSLUCENT_CONVERSION_COMPLETE = 144; |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 1562 | public static final int INSTALL_PROVIDER = 145; |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1563 | public static final int ON_NEW_ACTIVITY_OPTIONS = 146; |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 1564 | public static final int ENTER_ANIMATION_COMPLETE = 149; |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 1565 | public static final int START_BINDER_TRACKING = 150; |
| 1566 | public static final int STOP_BINDER_TRACKING_AND_DUMP = 151; |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1567 | public static final int LOCAL_VOICE_INTERACTION_STARTED = 154; |
Leonard Mosescu | f3409ce | 2016-10-06 17:32:05 -0700 | [diff] [blame] | 1568 | public static final int ATTACH_AGENT = 155; |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 1569 | public static final int APPLICATION_INFO_CHANGED = 156; |
Torne (Richard Coles) | 466cbe4 | 2017-05-31 14:09:14 -0400 | [diff] [blame] | 1570 | public static final int RUN_ISOLATED_ENTRY_POINT = 158; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 1571 | public static final int EXECUTE_TRANSACTION = 159; |
Narayan Kamath | ccb2a086 | 2013-12-19 14:49:36 +0000 | [diff] [blame] | 1572 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1573 | String codeToString(int code) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 1574 | if (DEBUG_MESSAGES) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1575 | switch (code) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1576 | case BIND_APPLICATION: return "BIND_APPLICATION"; |
| 1577 | case EXIT_APPLICATION: return "EXIT_APPLICATION"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1578 | case RECEIVER: return "RECEIVER"; |
| 1579 | case CREATE_SERVICE: return "CREATE_SERVICE"; |
| 1580 | case SERVICE_ARGS: return "SERVICE_ARGS"; |
| 1581 | case STOP_SERVICE: return "STOP_SERVICE"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1582 | case CONFIGURATION_CHANGED: return "CONFIGURATION_CHANGED"; |
| 1583 | case CLEAN_UP_CONTEXT: return "CLEAN_UP_CONTEXT"; |
| 1584 | case GC_WHEN_IDLE: return "GC_WHEN_IDLE"; |
| 1585 | case BIND_SERVICE: return "BIND_SERVICE"; |
| 1586 | case UNBIND_SERVICE: return "UNBIND_SERVICE"; |
| 1587 | case DUMP_SERVICE: return "DUMP_SERVICE"; |
| 1588 | case LOW_MEMORY: return "LOW_MEMORY"; |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 1589 | case PROFILER_CONTROL: return "PROFILER_CONTROL"; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1590 | case CREATE_BACKUP_AGENT: return "CREATE_BACKUP_AGENT"; |
| 1591 | case DESTROY_BACKUP_AGENT: return "DESTROY_BACKUP_AGENT"; |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 1592 | case SUICIDE: return "SUICIDE"; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1593 | case REMOVE_PROVIDER: return "REMOVE_PROVIDER"; |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 1594 | case ENABLE_JIT: return "ENABLE_JIT"; |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1595 | case DISPATCH_PACKAGE_BROADCAST: return "DISPATCH_PACKAGE_BROADCAST"; |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 1596 | case SCHEDULE_CRASH: return "SCHEDULE_CRASH"; |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 1597 | case DUMP_HEAP: return "DUMP_HEAP"; |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1598 | case DUMP_ACTIVITY: return "DUMP_ACTIVITY"; |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1599 | case SLEEPING: return "SLEEPING"; |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1600 | case SET_CORE_SETTINGS: return "SET_CORE_SETTINGS"; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1601 | case UPDATE_PACKAGE_COMPATIBILITY_INFO: return "UPDATE_PACKAGE_COMPATIBILITY_INFO"; |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1602 | case TRIM_MEMORY: return "TRIM_MEMORY"; |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1603 | case DUMP_PROVIDER: return "DUMP_PROVIDER"; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1604 | case UNSTABLE_PROVIDER_DIED: return "UNSTABLE_PROVIDER_DIED"; |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 1605 | case REQUEST_ASSIST_CONTEXT_EXTRAS: return "REQUEST_ASSIST_CONTEXT_EXTRAS"; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1606 | case TRANSLUCENT_CONVERSION_COMPLETE: return "TRANSLUCENT_CONVERSION_COMPLETE"; |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 1607 | case INSTALL_PROVIDER: return "INSTALL_PROVIDER"; |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1608 | case ON_NEW_ACTIVITY_OPTIONS: return "ON_NEW_ACTIVITY_OPTIONS"; |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 1609 | case ENTER_ANIMATION_COMPLETE: return "ENTER_ANIMATION_COMPLETE"; |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1610 | case LOCAL_VOICE_INTERACTION_STARTED: return "LOCAL_VOICE_INTERACTION_STARTED"; |
Leonard Mosescu | f3409ce | 2016-10-06 17:32:05 -0700 | [diff] [blame] | 1611 | case ATTACH_AGENT: return "ATTACH_AGENT"; |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 1612 | case APPLICATION_INFO_CHANGED: return "APPLICATION_INFO_CHANGED"; |
Torne (Richard Coles) | 466cbe4 | 2017-05-31 14:09:14 -0400 | [diff] [blame] | 1613 | case RUN_ISOLATED_ENTRY_POINT: return "RUN_ISOLATED_ENTRY_POINT"; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 1614 | case EXECUTE_TRANSACTION: return "EXECUTE_TRANSACTION"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1615 | } |
| 1616 | } |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 1617 | return Integer.toString(code); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1618 | } |
| 1619 | public void handleMessage(Message msg) { |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 1620 | 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] | 1621 | switch (msg.what) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1622 | case BIND_APPLICATION: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1623 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "bindApplication"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1624 | AppBindData data = (AppBindData)msg.obj; |
| 1625 | handleBindApplication(data); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1626 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1627 | break; |
| 1628 | case EXIT_APPLICATION: |
| 1629 | if (mInitialApplication != null) { |
| 1630 | mInitialApplication.onTerminate(); |
| 1631 | } |
| 1632 | Looper.myLooper().quit(); |
| 1633 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1634 | case RECEIVER: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1635 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "broadcastReceiveComp"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1636 | handleReceiver((ReceiverData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1637 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1638 | break; |
| 1639 | case CREATE_SERVICE: |
Tim Murray | b6f5a42 | 2016-04-07 15:25:22 -0700 | [diff] [blame] | 1640 | 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] | 1641 | handleCreateService((CreateServiceData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1642 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1643 | break; |
| 1644 | case BIND_SERVICE: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1645 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "serviceBind"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1646 | handleBindService((BindServiceData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1647 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1648 | break; |
| 1649 | case UNBIND_SERVICE: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1650 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "serviceUnbind"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1651 | handleUnbindService((BindServiceData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1652 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1653 | break; |
| 1654 | case SERVICE_ARGS: |
Tim Murray | b6f5a42 | 2016-04-07 15:25:22 -0700 | [diff] [blame] | 1655 | 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] | 1656 | handleServiceArgs((ServiceArgsData)msg.obj); |
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 STOP_SERVICE: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1660 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "serviceStop"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1661 | handleStopService((IBinder)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1662 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1663 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1664 | case CONFIGURATION_CHANGED: |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 1665 | handleConfigurationChanged((Configuration) msg.obj); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1666 | break; |
| 1667 | case CLEAN_UP_CONTEXT: |
| 1668 | ContextCleanupInfo cci = (ContextCleanupInfo)msg.obj; |
| 1669 | cci.context.performFinalCleanup(cci.who, cci.what); |
| 1670 | break; |
| 1671 | case GC_WHEN_IDLE: |
| 1672 | scheduleGcIdler(); |
| 1673 | break; |
| 1674 | case DUMP_SERVICE: |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1675 | handleDumpService((DumpComponentInfo)msg.obj); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1676 | break; |
| 1677 | case LOW_MEMORY: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1678 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "lowMemory"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1679 | handleLowMemory(); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1680 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1681 | break; |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 1682 | case PROFILER_CONTROL: |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 1683 | handleProfilerControl(msg.arg1 != 0, (ProfilerInfo)msg.obj, msg.arg2); |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 1684 | break; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1685 | case CREATE_BACKUP_AGENT: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1686 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "backupCreateAgent"); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1687 | handleCreateBackupAgent((CreateBackupAgentData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1688 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1689 | break; |
| 1690 | case DESTROY_BACKUP_AGENT: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1691 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "backupDestroyAgent"); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1692 | handleDestroyBackupAgent((CreateBackupAgentData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1693 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1694 | break; |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 1695 | case SUICIDE: |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1696 | Process.killProcess(Process.myPid()); |
| 1697 | break; |
| 1698 | case REMOVE_PROVIDER: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1699 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "providerRemove"); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1700 | completeRemoveProvider((ProviderRefCount)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1701 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 1702 | break; |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 1703 | case ENABLE_JIT: |
| 1704 | ensureJitEnabled(); |
| 1705 | break; |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1706 | case DISPATCH_PACKAGE_BROADCAST: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1707 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "broadcastPackage"); |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1708 | handleDispatchPackageBroadcast(msg.arg1, (String[])msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1709 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1710 | break; |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 1711 | case SCHEDULE_CRASH: |
| 1712 | throw new RemoteServiceException((String)msg.obj); |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 1713 | case DUMP_HEAP: |
Christopher Ferris | 8d652f8 | 2017-04-11 16:29:18 -0700 | [diff] [blame] | 1714 | handleDumpHeap((DumpHeapData) msg.obj); |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 1715 | break; |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1716 | case DUMP_ACTIVITY: |
| 1717 | handleDumpActivity((DumpComponentInfo)msg.obj); |
| 1718 | break; |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1719 | case DUMP_PROVIDER: |
| 1720 | handleDumpProvider((DumpComponentInfo)msg.obj); |
| 1721 | break; |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1722 | case SLEEPING: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1723 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "sleeping"); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1724 | handleSleeping((IBinder)msg.obj, msg.arg1 != 0); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1725 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1726 | break; |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1727 | case SET_CORE_SETTINGS: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1728 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "setCoreSettings"); |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1729 | handleSetCoreSettings((Bundle) msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1730 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1731 | break; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1732 | case UPDATE_PACKAGE_COMPATIBILITY_INFO: |
| 1733 | handleUpdatePackageCompatibilityInfo((UpdateCompatibilityData)msg.obj); |
Dianne Hackborn | f0754f5b | 2011-07-21 16:02:07 -0700 | [diff] [blame] | 1734 | break; |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1735 | case TRIM_MEMORY: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1736 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "trimMemory"); |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1737 | handleTrimMemory(msg.arg1); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1738 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Dianne Hackborn | f0754f5b | 2011-07-21 16:02:07 -0700 | [diff] [blame] | 1739 | break; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1740 | case UNSTABLE_PROVIDER_DIED: |
| 1741 | handleUnstableProviderDied((IBinder)msg.obj, false); |
| 1742 | break; |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 1743 | case REQUEST_ASSIST_CONTEXT_EXTRAS: |
| 1744 | handleRequestAssistContextExtras((RequestAssistContextExtras)msg.obj); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 1745 | break; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1746 | case TRANSLUCENT_CONVERSION_COMPLETE: |
| 1747 | handleTranslucentConversionComplete((IBinder)msg.obj, msg.arg1 == 1); |
| 1748 | break; |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 1749 | case INSTALL_PROVIDER: |
| 1750 | handleInstallProvider((ProviderInfo) msg.obj); |
| 1751 | break; |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1752 | case ON_NEW_ACTIVITY_OPTIONS: |
| 1753 | Pair<IBinder, ActivityOptions> pair = (Pair<IBinder, ActivityOptions>) msg.obj; |
| 1754 | onNewActivityOptions(pair.first, pair.second); |
Dake Gu | 7ef70b0 | 2014-07-08 18:37:12 -0700 | [diff] [blame] | 1755 | break; |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 1756 | case ENTER_ANIMATION_COMPLETE: |
| 1757 | handleEnterAnimationComplete((IBinder) msg.obj); |
| 1758 | break; |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 1759 | case START_BINDER_TRACKING: |
| 1760 | handleStartBinderTracking(); |
| 1761 | break; |
| 1762 | case STOP_BINDER_TRACKING_AND_DUMP: |
| 1763 | handleStopBinderTrackingAndDump((ParcelFileDescriptor) msg.obj); |
| 1764 | break; |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1765 | case LOCAL_VOICE_INTERACTION_STARTED: |
| 1766 | handleLocalVoiceInteractionStarted((IBinder) ((SomeArgs) msg.obj).arg1, |
| 1767 | (IVoiceInteractor) ((SomeArgs) msg.obj).arg2); |
Amith Yamasani | 6101911 | 2017-01-10 15:05:00 -0800 | [diff] [blame] | 1768 | break; |
Andreas Gampe | ab8a63b | 2018-01-05 13:55:15 -0800 | [diff] [blame] | 1769 | case ATTACH_AGENT: { |
| 1770 | Application app = getApplication(); |
| 1771 | handleAttachAgent((String) msg.obj, app != null ? app.mLoadedApk : null); |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1772 | break; |
Andreas Gampe | ab8a63b | 2018-01-05 13:55:15 -0800 | [diff] [blame] | 1773 | } |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 1774 | case APPLICATION_INFO_CHANGED: |
| 1775 | mUpdatingSystemConfig = true; |
| 1776 | try { |
| 1777 | handleApplicationInfoChanged((ApplicationInfo) msg.obj); |
| 1778 | } finally { |
| 1779 | mUpdatingSystemConfig = false; |
| 1780 | } |
| 1781 | break; |
Torne (Richard Coles) | 466cbe4 | 2017-05-31 14:09:14 -0400 | [diff] [blame] | 1782 | case RUN_ISOLATED_ENTRY_POINT: |
| 1783 | handleRunIsolatedEntryPoint((String) ((SomeArgs) msg.obj).arg1, |
| 1784 | (String[]) ((SomeArgs) msg.obj).arg2); |
| 1785 | break; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 1786 | case EXECUTE_TRANSACTION: |
Andrii Kulian | 0447068 | 2018-01-10 15:32:31 -0800 | [diff] [blame] | 1787 | final ClientTransaction transaction = (ClientTransaction) msg.obj; |
| 1788 | mTransactionExecutor.execute(transaction); |
| 1789 | if (isSystem()) { |
| 1790 | // Client transactions inside system process are recycled on the client side |
| 1791 | // instead of ClientLifecycleManager to avoid being cleared before this |
| 1792 | // message is handled. |
| 1793 | transaction.recycle(); |
| 1794 | } |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 1795 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1796 | } |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1797 | Object obj = msg.obj; |
| 1798 | if (obj instanceof SomeArgs) { |
| 1799 | ((SomeArgs) obj).recycle(); |
| 1800 | } |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 1801 | 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] | 1802 | } |
| 1803 | } |
| 1804 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1805 | private class Idler implements MessageQueue.IdleHandler { |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 1806 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1807 | public final boolean queueIdle() { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1808 | ActivityClientRecord a = mNewActivities; |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 1809 | boolean stopProfiling = false; |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 1810 | if (mBoundApplication != null && mProfiler.profileFd != null |
| 1811 | && mProfiler.autoStopProfiler) { |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 1812 | stopProfiling = true; |
| 1813 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1814 | if (a != null) { |
| 1815 | mNewActivities = null; |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 1816 | IActivityManager am = ActivityManager.getService(); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1817 | ActivityClientRecord prev; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1818 | do { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 1819 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1820 | TAG, "Reporting idle of " + a + |
| 1821 | " finished=" + |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1822 | (a.activity != null && a.activity.mFinished)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1823 | if (a.activity != null && !a.activity.mFinished) { |
| 1824 | try { |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 1825 | am.activityIdle(a.token, a.createdConfig, stopProfiling); |
Dianne Hackborn | e88846e | 2009-09-30 21:34:25 -0700 | [diff] [blame] | 1826 | a.createdConfig = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1827 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1828 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1829 | } |
| 1830 | } |
| 1831 | prev = a; |
| 1832 | a = a.nextIdle; |
| 1833 | prev.nextIdle = null; |
| 1834 | } while (a != null); |
| 1835 | } |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 1836 | if (stopProfiling) { |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 1837 | mProfiler.stopProfiling(); |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 1838 | } |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 1839 | ensureJitEnabled(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1840 | return false; |
| 1841 | } |
| 1842 | } |
| 1843 | |
| 1844 | final class GcIdler implements MessageQueue.IdleHandler { |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 1845 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1846 | public final boolean queueIdle() { |
| 1847 | doGcIfNeeded(); |
| 1848 | return false; |
| 1849 | } |
| 1850 | } |
| 1851 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1852 | public static ActivityThread currentActivityThread() { |
Jeff Sharkey | 66a017b | 2013-01-17 18:18:22 -0800 | [diff] [blame] | 1853 | return sCurrentActivityThread; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1854 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1855 | |
Wale Ogunwale | 9a6ef1e | 2015-06-02 13:41:00 -0700 | [diff] [blame] | 1856 | public static boolean isSystem() { |
| 1857 | return (sCurrentActivityThread != null) ? sCurrentActivityThread.mSystemThread : false; |
| 1858 | } |
| 1859 | |
Svetoslav | fbf0eca | 2015-05-01 16:52:41 -0700 | [diff] [blame] | 1860 | public static String currentOpPackageName() { |
| 1861 | ActivityThread am = currentActivityThread(); |
| 1862 | return (am != null && am.getApplication() != null) |
| 1863 | ? am.getApplication().getOpPackageName() : null; |
| 1864 | } |
| 1865 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1866 | public static String currentPackageName() { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1867 | ActivityThread am = currentActivityThread(); |
| 1868 | return (am != null && am.mBoundApplication != null) |
Dianne Hackborn | b57a50b | 2013-04-11 17:29:32 -0700 | [diff] [blame] | 1869 | ? am.mBoundApplication.appInfo.packageName : null; |
| 1870 | } |
| 1871 | |
| 1872 | public static String currentProcessName() { |
| 1873 | ActivityThread am = currentActivityThread(); |
| 1874 | return (am != null && am.mBoundApplication != null) |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1875 | ? am.mBoundApplication.processName : null; |
| 1876 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1877 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1878 | public static Application currentApplication() { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1879 | ActivityThread am = currentActivityThread(); |
| 1880 | return am != null ? am.mInitialApplication : null; |
| 1881 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1882 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1883 | public static IPackageManager getPackageManager() { |
| 1884 | if (sPackageManager != null) { |
| 1885 | //Slog.v("PackageManager", "returning cur default = " + sPackageManager); |
| 1886 | return sPackageManager; |
| 1887 | } |
| 1888 | IBinder b = ServiceManager.getService("package"); |
| 1889 | //Slog.v("PackageManager", "default service binder = " + b); |
| 1890 | sPackageManager = IPackageManager.Stub.asInterface(b); |
| 1891 | //Slog.v("PackageManager", "default service = " + sPackageManager); |
| 1892 | return sPackageManager; |
| 1893 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1894 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1895 | private Configuration mMainThreadConfig = new Configuration(); |
Amith Yamasani | 4f128e4 | 2016-05-10 11:44:12 -0700 | [diff] [blame] | 1896 | |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 1897 | Configuration applyConfigCompatMainThread(int displayDensity, Configuration config, |
| 1898 | CompatibilityInfo compat) { |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1899 | if (config == null) { |
| 1900 | return null; |
| 1901 | } |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 1902 | if (!compat.supportsScreen()) { |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1903 | mMainThreadConfig.setTo(config); |
| 1904 | config = mMainThreadConfig; |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 1905 | compat.applyToConfiguration(displayDensity, config); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1906 | } |
| 1907 | return config; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1908 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1909 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1910 | /** |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 1911 | * Creates the top level resources for the given package. Will return an existing |
| 1912 | * Resources if one has already been created. |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1913 | */ |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 1914 | Resources getTopLevelResources(String resDir, String[] splitResDirs, String[] overlayDirs, |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 1915 | String[] libDirs, int displayId, LoadedApk pkgInfo) { |
| 1916 | return mResourcesManager.getResources(null, resDir, splitResDirs, overlayDirs, libDirs, |
| 1917 | displayId, null, pkgInfo.getCompatibilityInfo(), pkgInfo.getClassLoader()); |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 1918 | } |
| 1919 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1920 | final Handler getHandler() { |
| 1921 | return mH; |
| 1922 | } |
| 1923 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 1924 | public final LoadedApk getPackageInfo(String packageName, CompatibilityInfo compatInfo, |
| 1925 | int flags) { |
| 1926 | return getPackageInfo(packageName, compatInfo, flags, UserHandle.myUserId()); |
Amith Yamasani | 98edc95 | 2012-09-25 14:09:27 -0700 | [diff] [blame] | 1927 | } |
| 1928 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 1929 | public final LoadedApk getPackageInfo(String packageName, CompatibilityInfo compatInfo, |
| 1930 | int flags, int userId) { |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 1931 | final boolean differentUser = (UserHandle.myUserId() != userId); |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 1932 | synchronized (mResourcesManager) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1933 | WeakReference<LoadedApk> ref; |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 1934 | if (differentUser) { |
| 1935 | // Caching not supported across users |
| 1936 | ref = null; |
| 1937 | } else if ((flags & Context.CONTEXT_INCLUDE_CODE) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1938 | ref = mPackages.get(packageName); |
| 1939 | } else { |
| 1940 | ref = mResourcePackages.get(packageName); |
| 1941 | } |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 1942 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 1943 | LoadedApk packageInfo = ref != null ? ref.get() : null; |
| 1944 | //Slog.i(TAG, "getPackageInfo " + packageName + ": " + packageInfo); |
| 1945 | //if (packageInfo != null) Slog.i(TAG, "isUptoDate " + packageInfo.mResDir |
| 1946 | // + ": " + packageInfo.mResources.getAssets().isUpToDate()); |
| 1947 | if (packageInfo != null && (packageInfo.mResources == null |
| 1948 | || packageInfo.mResources.getAssets().isUpToDate())) { |
| 1949 | if (packageInfo.isSecurityViolation() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1950 | && (flags&Context.CONTEXT_IGNORE_SECURITY) == 0) { |
| 1951 | throw new SecurityException( |
| 1952 | "Requesting code from " + packageName |
| 1953 | + " to be run in process " |
| 1954 | + mBoundApplication.processName |
| 1955 | + "/" + mBoundApplication.appInfo.uid); |
| 1956 | } |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 1957 | return packageInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1958 | } |
| 1959 | } |
| 1960 | |
| 1961 | ApplicationInfo ai = null; |
| 1962 | try { |
| 1963 | ai = getPackageManager().getApplicationInfo(packageName, |
Jeff Sharkey | c5967e9 | 2016-01-07 18:50:29 -0700 | [diff] [blame] | 1964 | PackageManager.GET_SHARED_LIBRARY_FILES |
| 1965 | | PackageManager.MATCH_DEBUG_TRIAGED_MISSING, |
| 1966 | userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1967 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1968 | throw e.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1969 | } |
| 1970 | |
| 1971 | if (ai != null) { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 1972 | return getPackageInfo(ai, compatInfo, flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1973 | } |
| 1974 | |
| 1975 | return null; |
| 1976 | } |
| 1977 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 1978 | public final LoadedApk getPackageInfo(ApplicationInfo ai, CompatibilityInfo compatInfo, |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1979 | int flags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1980 | boolean includeCode = (flags&Context.CONTEXT_INCLUDE_CODE) != 0; |
| 1981 | boolean securityViolation = includeCode && ai.uid != 0 |
| 1982 | && ai.uid != Process.SYSTEM_UID && (mBoundApplication != null |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 1983 | ? !UserHandle.isSameApp(ai.uid, mBoundApplication.appInfo.uid) |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 1984 | : true); |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 1985 | boolean registerPackage = includeCode && (flags&Context.CONTEXT_REGISTER_PACKAGE) != 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1986 | if ((flags&(Context.CONTEXT_INCLUDE_CODE |
| 1987 | |Context.CONTEXT_IGNORE_SECURITY)) |
| 1988 | == Context.CONTEXT_INCLUDE_CODE) { |
| 1989 | if (securityViolation) { |
| 1990 | String msg = "Requesting code from " + ai.packageName |
| 1991 | + " (with uid " + ai.uid + ")"; |
| 1992 | if (mBoundApplication != null) { |
| 1993 | msg = msg + " to be run in process " |
| 1994 | + mBoundApplication.processName + " (with uid " |
| 1995 | + mBoundApplication.appInfo.uid + ")"; |
| 1996 | } |
| 1997 | throw new SecurityException(msg); |
| 1998 | } |
| 1999 | } |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2000 | return getPackageInfo(ai, compatInfo, null, securityViolation, includeCode, |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 2001 | registerPackage); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2002 | } |
| 2003 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 2004 | @Override |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2005 | public final LoadedApk getPackageInfoNoCheck(ApplicationInfo ai, |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2006 | CompatibilityInfo compatInfo) { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2007 | return getPackageInfo(ai, compatInfo, null, false, true, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2008 | } |
| 2009 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2010 | public final LoadedApk peekPackageInfo(String packageName, boolean includeCode) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 2011 | synchronized (mResourcesManager) { |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2012 | WeakReference<LoadedApk> ref; |
| 2013 | if (includeCode) { |
| 2014 | ref = mPackages.get(packageName); |
| 2015 | } else { |
| 2016 | ref = mResourcePackages.get(packageName); |
| 2017 | } |
| 2018 | return ref != null ? ref.get() : null; |
| 2019 | } |
| 2020 | } |
| 2021 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2022 | private LoadedApk getPackageInfo(ApplicationInfo aInfo, CompatibilityInfo compatInfo, |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 2023 | ClassLoader baseLoader, boolean securityViolation, boolean includeCode, |
| 2024 | boolean registerPackage) { |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 2025 | final boolean differentUser = (UserHandle.myUserId() != UserHandle.getUserId(aInfo.uid)); |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 2026 | synchronized (mResourcesManager) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2027 | WeakReference<LoadedApk> ref; |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 2028 | if (differentUser) { |
| 2029 | // Caching not supported across users |
| 2030 | ref = null; |
| 2031 | } else if (includeCode) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2032 | ref = mPackages.get(aInfo.packageName); |
| 2033 | } else { |
| 2034 | ref = mResourcePackages.get(aInfo.packageName); |
| 2035 | } |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 2036 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2037 | LoadedApk packageInfo = ref != null ? ref.get() : null; |
| 2038 | if (packageInfo == null || (packageInfo.mResources != null |
| 2039 | && !packageInfo.mResources.getAssets().isUpToDate())) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2040 | if (localLOGV) Slog.v(TAG, (includeCode ? "Loading code package " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2041 | : "Loading resource-only package ") + aInfo.packageName |
| 2042 | + " (in " + (mBoundApplication != null |
| 2043 | ? mBoundApplication.processName : null) |
| 2044 | + ")"); |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2045 | packageInfo = |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 2046 | new LoadedApk(this, aInfo, compatInfo, baseLoader, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2047 | securityViolation, includeCode && |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 2048 | (aInfo.flags&ApplicationInfo.FLAG_HAS_CODE) != 0, registerPackage); |
Narayan Kamath | cb38318 | 2014-10-29 17:56:42 +0000 | [diff] [blame] | 2049 | |
| 2050 | if (mSystemThread && "android".equals(aInfo.packageName)) { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2051 | packageInfo.installSystemApplicationInfo(aInfo, |
| 2052 | getSystemContext().mPackageInfo.getClassLoader()); |
Narayan Kamath | cb38318 | 2014-10-29 17:56:42 +0000 | [diff] [blame] | 2053 | } |
| 2054 | |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 2055 | if (differentUser) { |
| 2056 | // Caching not supported across users |
| 2057 | } else if (includeCode) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2058 | mPackages.put(aInfo.packageName, |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2059 | new WeakReference<LoadedApk>(packageInfo)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2060 | } else { |
| 2061 | mResourcePackages.put(aInfo.packageName, |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2062 | new WeakReference<LoadedApk>(packageInfo)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2063 | } |
| 2064 | } |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2065 | return packageInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2066 | } |
| 2067 | } |
| 2068 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2069 | ActivityThread() { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 2070 | mResourcesManager = ResourcesManager.getInstance(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2071 | } |
| 2072 | |
| 2073 | public ApplicationThread getApplicationThread() |
| 2074 | { |
| 2075 | return mAppThread; |
| 2076 | } |
| 2077 | |
| 2078 | public Instrumentation getInstrumentation() |
| 2079 | { |
| 2080 | return mInstrumentation; |
| 2081 | } |
| 2082 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2083 | public boolean isProfiling() { |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 2084 | return mProfiler != null && mProfiler.profileFile != null |
| 2085 | && mProfiler.profileFd == null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2086 | } |
| 2087 | |
| 2088 | public String getProfileFilePath() { |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 2089 | return mProfiler.profileFile; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2090 | } |
| 2091 | |
| 2092 | public Looper getLooper() { |
| 2093 | return mLooper; |
| 2094 | } |
| 2095 | |
Jeff Sharkey | 8439ac0 | 2017-12-12 17:26:23 -0700 | [diff] [blame] | 2096 | public Executor getExecutor() { |
| 2097 | return mExecutor; |
| 2098 | } |
| 2099 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2100 | public Application getApplication() { |
| 2101 | return mInitialApplication; |
| 2102 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2103 | |
Dianne Hackborn | d97c7ad | 2009-06-19 11:37:35 -0700 | [diff] [blame] | 2104 | public String getProcessName() { |
| 2105 | return mBoundApplication.processName; |
| 2106 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2107 | |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 2108 | public ContextImpl getSystemContext() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2109 | synchronized (this) { |
| 2110 | if (mSystemContext == null) { |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 2111 | mSystemContext = ContextImpl.createSystemContext(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2112 | } |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 2113 | return mSystemContext; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2114 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2115 | } |
| 2116 | |
Adam Lesinski | a82b626 | 2017-03-21 16:56:17 -0700 | [diff] [blame] | 2117 | public ContextImpl getSystemUiContext() { |
| 2118 | synchronized (this) { |
| 2119 | if (mSystemUiContext == null) { |
Adam Lesinski | 6f1a917 | 2017-04-10 16:35:19 -0700 | [diff] [blame] | 2120 | mSystemUiContext = ContextImpl.createSystemUiContext(getSystemContext()); |
Adam Lesinski | a82b626 | 2017-03-21 16:56:17 -0700 | [diff] [blame] | 2121 | } |
| 2122 | return mSystemUiContext; |
| 2123 | } |
| 2124 | } |
| 2125 | |
Narayan Kamath | 29564cd | 2014-08-07 10:57:40 +0100 | [diff] [blame] | 2126 | public void installSystemApplicationInfo(ApplicationInfo info, ClassLoader classLoader) { |
Mike Cleron | 432b713 | 2009-09-24 15:28:29 -0700 | [diff] [blame] | 2127 | synchronized (this) { |
Narayan Kamath | 29564cd | 2014-08-07 10:57:40 +0100 | [diff] [blame] | 2128 | getSystemContext().installSystemApplicationInfo(info, classLoader); |
Adam Lesinski | a82b626 | 2017-03-21 16:56:17 -0700 | [diff] [blame] | 2129 | getSystemUiContext().installSystemApplicationInfo(info, classLoader); |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 2130 | |
| 2131 | // give ourselves a default profiler |
| 2132 | mProfiler = new Profiler(); |
Mike Cleron | 432b713 | 2009-09-24 15:28:29 -0700 | [diff] [blame] | 2133 | } |
| 2134 | } |
| 2135 | |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 2136 | void ensureJitEnabled() { |
| 2137 | if (!mJitEnabled) { |
| 2138 | mJitEnabled = true; |
| 2139 | dalvik.system.VMRuntime.getRuntime().startJitCompilation(); |
| 2140 | } |
| 2141 | } |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 2142 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2143 | void scheduleGcIdler() { |
| 2144 | if (!mGcIdlerScheduled) { |
| 2145 | mGcIdlerScheduled = true; |
| 2146 | Looper.myQueue().addIdleHandler(mGcIdler); |
| 2147 | } |
| 2148 | mH.removeMessages(H.GC_WHEN_IDLE); |
| 2149 | } |
| 2150 | |
| 2151 | void unscheduleGcIdler() { |
| 2152 | if (mGcIdlerScheduled) { |
| 2153 | mGcIdlerScheduled = false; |
| 2154 | Looper.myQueue().removeIdleHandler(mGcIdler); |
| 2155 | } |
| 2156 | mH.removeMessages(H.GC_WHEN_IDLE); |
| 2157 | } |
| 2158 | |
| 2159 | void doGcIfNeeded() { |
| 2160 | mGcIdlerScheduled = false; |
| 2161 | final long now = SystemClock.uptimeMillis(); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2162 | //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] | 2163 | // + "m now=" + now); |
| 2164 | if ((BinderInternal.getLastGcTime()+MIN_TIME_BETWEEN_GCS) < now) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2165 | //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] | 2166 | BinderInternal.forceGc("bg"); |
| 2167 | } |
| 2168 | } |
| 2169 | |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2170 | private static final String HEAP_FULL_COLUMN |
| 2171 | = "%13s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s"; |
| 2172 | private static final String HEAP_COLUMN |
| 2173 | = "%13s %8s %8s %8s %8s %8s %8s %8s"; |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2174 | private static final String ONE_COUNT_COLUMN = "%21s %8d"; |
| 2175 | private static final String TWO_COUNT_COLUMNS = "%21s %8d %21s %8d"; |
| 2176 | private static final String ONE_COUNT_COLUMN_HEADER = "%21s %8s"; |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2177 | |
| 2178 | // Formatting for checkin service - update version if row format changes |
Martijn Coenen | 41f94ed | 2015-12-14 15:28:51 +0100 | [diff] [blame] | 2179 | private static final int ACTIVITY_THREAD_CHECKIN_VERSION = 4; |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2180 | |
| 2181 | static void printRow(PrintWriter pw, String format, Object...objs) { |
| 2182 | pw.println(String.format(format, objs)); |
| 2183 | } |
| 2184 | |
Bryce Lee | d946f86 | 2018-01-16 15:59:47 -0800 | [diff] [blame] | 2185 | @Override |
| 2186 | public void dump(PrintWriter pw, String prefix) { |
Bryce Lee | a33c13d | 2018-02-08 14:37:06 -0800 | [diff] [blame] | 2187 | pw.println(prefix + "Activities:"); |
Bryce Lee | d946f86 | 2018-01-16 15:59:47 -0800 | [diff] [blame] | 2188 | |
Bryce Lee | a33c13d | 2018-02-08 14:37:06 -0800 | [diff] [blame] | 2189 | if (!mActivities.isEmpty()) { |
| 2190 | final Iterator<Map.Entry<IBinder, ActivityClientRecord>> activitiesIterator = |
| 2191 | mActivities.entrySet().iterator(); |
| 2192 | |
| 2193 | while (activitiesIterator.hasNext()) { |
| 2194 | final ArrayMap.Entry<IBinder, ActivityClientRecord> entry = |
| 2195 | activitiesIterator.next(); |
| 2196 | pw.println(prefix + " [token:" + entry.getKey().hashCode() + " record:" |
| 2197 | + entry.getValue().toString() + "]"); |
| 2198 | } |
Bryce Lee | d946f86 | 2018-01-16 15:59:47 -0800 | [diff] [blame] | 2199 | } |
| 2200 | |
Bryce Lee | a33c13d | 2018-02-08 14:37:06 -0800 | [diff] [blame] | 2201 | if (!mRecentDestroyedActivities.isEmpty()) { |
| 2202 | pw.println(prefix + "Recent destroyed activities:"); |
| 2203 | for (int i = 0, size = mRecentDestroyedActivities.size(); i < size; i++) { |
| 2204 | final DestroyedActivityInfo info = mRecentDestroyedActivities.get(i); |
| 2205 | pw.print(prefix); |
| 2206 | info.dump(pw, " "); |
| 2207 | } |
| 2208 | } |
Bryce Lee | d946f86 | 2018-01-16 15:59:47 -0800 | [diff] [blame] | 2209 | } |
| 2210 | |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2211 | public static void dumpMemInfoTable(PrintWriter pw, Debug.MemoryInfo memInfo, boolean checkin, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2212 | boolean dumpFullInfo, boolean dumpDalvik, boolean dumpSummaryOnly, |
| 2213 | int pid, String processName, |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2214 | long nativeMax, long nativeAllocated, long nativeFree, |
| 2215 | long dalvikMax, long dalvikAllocated, long dalvikFree) { |
| 2216 | |
| 2217 | // For checkin, we print one long comma-separated list of values |
| 2218 | if (checkin) { |
| 2219 | // NOTE: if you change anything significant below, also consider changing |
| 2220 | // ACTIVITY_THREAD_CHECKIN_VERSION. |
| 2221 | |
| 2222 | // Header |
| 2223 | pw.print(ACTIVITY_THREAD_CHECKIN_VERSION); pw.print(','); |
| 2224 | pw.print(pid); pw.print(','); |
| 2225 | pw.print(processName); pw.print(','); |
| 2226 | |
| 2227 | // Heap info - max |
| 2228 | pw.print(nativeMax); pw.print(','); |
| 2229 | pw.print(dalvikMax); pw.print(','); |
| 2230 | pw.print("N/A,"); |
| 2231 | pw.print(nativeMax + dalvikMax); pw.print(','); |
| 2232 | |
| 2233 | // Heap info - allocated |
| 2234 | pw.print(nativeAllocated); pw.print(','); |
| 2235 | pw.print(dalvikAllocated); pw.print(','); |
| 2236 | pw.print("N/A,"); |
| 2237 | pw.print(nativeAllocated + dalvikAllocated); pw.print(','); |
| 2238 | |
| 2239 | // Heap info - free |
| 2240 | pw.print(nativeFree); pw.print(','); |
| 2241 | pw.print(dalvikFree); pw.print(','); |
| 2242 | pw.print("N/A,"); |
| 2243 | pw.print(nativeFree + dalvikFree); pw.print(','); |
| 2244 | |
| 2245 | // Heap info - proportional set size |
| 2246 | pw.print(memInfo.nativePss); pw.print(','); |
| 2247 | pw.print(memInfo.dalvikPss); pw.print(','); |
| 2248 | pw.print(memInfo.otherPss); pw.print(','); |
| 2249 | pw.print(memInfo.getTotalPss()); pw.print(','); |
| 2250 | |
| 2251 | // Heap info - swappable set size |
| 2252 | pw.print(memInfo.nativeSwappablePss); pw.print(','); |
| 2253 | pw.print(memInfo.dalvikSwappablePss); pw.print(','); |
| 2254 | pw.print(memInfo.otherSwappablePss); pw.print(','); |
| 2255 | pw.print(memInfo.getTotalSwappablePss()); pw.print(','); |
| 2256 | |
| 2257 | // Heap info - shared dirty |
| 2258 | pw.print(memInfo.nativeSharedDirty); pw.print(','); |
| 2259 | pw.print(memInfo.dalvikSharedDirty); pw.print(','); |
| 2260 | pw.print(memInfo.otherSharedDirty); pw.print(','); |
| 2261 | pw.print(memInfo.getTotalSharedDirty()); pw.print(','); |
| 2262 | |
| 2263 | // Heap info - shared clean |
| 2264 | pw.print(memInfo.nativeSharedClean); pw.print(','); |
| 2265 | pw.print(memInfo.dalvikSharedClean); pw.print(','); |
| 2266 | pw.print(memInfo.otherSharedClean); pw.print(','); |
| 2267 | pw.print(memInfo.getTotalSharedClean()); pw.print(','); |
| 2268 | |
| 2269 | // Heap info - private Dirty |
| 2270 | pw.print(memInfo.nativePrivateDirty); pw.print(','); |
| 2271 | pw.print(memInfo.dalvikPrivateDirty); pw.print(','); |
| 2272 | pw.print(memInfo.otherPrivateDirty); pw.print(','); |
| 2273 | pw.print(memInfo.getTotalPrivateDirty()); pw.print(','); |
| 2274 | |
| 2275 | // Heap info - private Clean |
| 2276 | pw.print(memInfo.nativePrivateClean); pw.print(','); |
| 2277 | pw.print(memInfo.dalvikPrivateClean); pw.print(','); |
| 2278 | pw.print(memInfo.otherPrivateClean); pw.print(','); |
| 2279 | pw.print(memInfo.getTotalPrivateClean()); pw.print(','); |
| 2280 | |
Martijn Coenen | 41f94ed | 2015-12-14 15:28:51 +0100 | [diff] [blame] | 2281 | // Heap info - swapped out |
| 2282 | pw.print(memInfo.nativeSwappedOut); pw.print(','); |
| 2283 | pw.print(memInfo.dalvikSwappedOut); pw.print(','); |
| 2284 | pw.print(memInfo.otherSwappedOut); pw.print(','); |
| 2285 | pw.print(memInfo.getTotalSwappedOut()); pw.print(','); |
| 2286 | |
| 2287 | // Heap info - swapped out pss |
| 2288 | if (memInfo.hasSwappedOutPss) { |
| 2289 | pw.print(memInfo.nativeSwappedOutPss); pw.print(','); |
| 2290 | pw.print(memInfo.dalvikSwappedOutPss); pw.print(','); |
| 2291 | pw.print(memInfo.otherSwappedOutPss); pw.print(','); |
| 2292 | pw.print(memInfo.getTotalSwappedOutPss()); pw.print(','); |
| 2293 | } else { |
| 2294 | pw.print("N/A,"); |
| 2295 | pw.print("N/A,"); |
| 2296 | pw.print("N/A,"); |
| 2297 | pw.print("N/A,"); |
| 2298 | } |
| 2299 | |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2300 | // Heap info - other areas |
| 2301 | for (int i=0; i<Debug.MemoryInfo.NUM_OTHER_STATS; i++) { |
| 2302 | pw.print(Debug.MemoryInfo.getOtherLabel(i)); pw.print(','); |
| 2303 | pw.print(memInfo.getOtherPss(i)); pw.print(','); |
| 2304 | pw.print(memInfo.getOtherSwappablePss(i)); pw.print(','); |
| 2305 | pw.print(memInfo.getOtherSharedDirty(i)); pw.print(','); |
| 2306 | pw.print(memInfo.getOtherSharedClean(i)); pw.print(','); |
| 2307 | pw.print(memInfo.getOtherPrivateDirty(i)); pw.print(','); |
| 2308 | pw.print(memInfo.getOtherPrivateClean(i)); pw.print(','); |
Martijn Coenen | 41f94ed | 2015-12-14 15:28:51 +0100 | [diff] [blame] | 2309 | pw.print(memInfo.getOtherSwappedOut(i)); pw.print(','); |
| 2310 | if (memInfo.hasSwappedOutPss) { |
| 2311 | pw.print(memInfo.getOtherSwappedOutPss(i)); pw.print(','); |
| 2312 | } else { |
| 2313 | pw.print("N/A,"); |
| 2314 | } |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2315 | } |
| 2316 | return; |
| 2317 | } |
| 2318 | |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2319 | if (!dumpSummaryOnly) { |
| 2320 | if (dumpFullInfo) { |
| 2321 | printRow(pw, HEAP_FULL_COLUMN, "", "Pss", "Pss", "Shared", "Private", |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2322 | "Shared", "Private", memInfo.hasSwappedOutPss ? "SwapPss" : "Swap", |
| 2323 | "Heap", "Heap", "Heap"); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2324 | printRow(pw, HEAP_FULL_COLUMN, "", "Total", "Clean", "Dirty", "Dirty", |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2325 | "Clean", "Clean", "Dirty", |
| 2326 | "Size", "Alloc", "Free"); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2327 | printRow(pw, HEAP_FULL_COLUMN, "", "------", "------", "------", "------", |
| 2328 | "------", "------", "------", "------", "------", "------"); |
| 2329 | printRow(pw, HEAP_FULL_COLUMN, "Native Heap", memInfo.nativePss, |
| 2330 | memInfo.nativeSwappablePss, memInfo.nativeSharedDirty, |
| 2331 | memInfo.nativePrivateDirty, memInfo.nativeSharedClean, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2332 | memInfo.nativePrivateClean, memInfo.hasSwappedOutPss ? |
Richard Uhler | 91702eb3 | 2017-06-23 16:54:25 +0100 | [diff] [blame] | 2333 | memInfo.nativeSwappedOutPss : memInfo.nativeSwappedOut, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2334 | nativeMax, nativeAllocated, nativeFree); |
| 2335 | printRow(pw, HEAP_FULL_COLUMN, "Dalvik Heap", memInfo.dalvikPss, |
| 2336 | memInfo.dalvikSwappablePss, memInfo.dalvikSharedDirty, |
| 2337 | memInfo.dalvikPrivateDirty, memInfo.dalvikSharedClean, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2338 | memInfo.dalvikPrivateClean, memInfo.hasSwappedOutPss ? |
Richard Uhler | 91702eb3 | 2017-06-23 16:54:25 +0100 | [diff] [blame] | 2339 | memInfo.dalvikSwappedOutPss : memInfo.dalvikSwappedOut, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2340 | dalvikMax, dalvikAllocated, dalvikFree); |
| 2341 | } else { |
| 2342 | printRow(pw, HEAP_COLUMN, "", "Pss", "Private", |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2343 | "Private", memInfo.hasSwappedOutPss ? "SwapPss" : "Swap", |
| 2344 | "Heap", "Heap", "Heap"); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2345 | printRow(pw, HEAP_COLUMN, "", "Total", "Dirty", |
| 2346 | "Clean", "Dirty", "Size", "Alloc", "Free"); |
| 2347 | printRow(pw, HEAP_COLUMN, "", "------", "------", "------", |
| 2348 | "------", "------", "------", "------", "------"); |
| 2349 | printRow(pw, HEAP_COLUMN, "Native Heap", memInfo.nativePss, |
| 2350 | memInfo.nativePrivateDirty, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2351 | memInfo.nativePrivateClean, |
| 2352 | memInfo.hasSwappedOutPss ? memInfo.nativeSwappedOutPss : |
| 2353 | memInfo.nativeSwappedOut, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2354 | nativeMax, nativeAllocated, nativeFree); |
| 2355 | printRow(pw, HEAP_COLUMN, "Dalvik Heap", memInfo.dalvikPss, |
| 2356 | memInfo.dalvikPrivateDirty, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2357 | memInfo.dalvikPrivateClean, |
| 2358 | memInfo.hasSwappedOutPss ? memInfo.dalvikSwappedOutPss : |
| 2359 | memInfo.dalvikSwappedOut, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2360 | dalvikMax, dalvikAllocated, dalvikFree); |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2361 | } |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2362 | |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2363 | int otherPss = memInfo.otherPss; |
| 2364 | int otherSwappablePss = memInfo.otherSwappablePss; |
| 2365 | int otherSharedDirty = memInfo.otherSharedDirty; |
| 2366 | int otherPrivateDirty = memInfo.otherPrivateDirty; |
| 2367 | int otherSharedClean = memInfo.otherSharedClean; |
| 2368 | int otherPrivateClean = memInfo.otherPrivateClean; |
| 2369 | int otherSwappedOut = memInfo.otherSwappedOut; |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2370 | int otherSwappedOutPss = memInfo.otherSwappedOutPss; |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2371 | |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2372 | for (int i=0; i<Debug.MemoryInfo.NUM_OTHER_STATS; i++) { |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2373 | final int myPss = memInfo.getOtherPss(i); |
| 2374 | final int mySwappablePss = memInfo.getOtherSwappablePss(i); |
| 2375 | final int mySharedDirty = memInfo.getOtherSharedDirty(i); |
| 2376 | final int myPrivateDirty = memInfo.getOtherPrivateDirty(i); |
| 2377 | final int mySharedClean = memInfo.getOtherSharedClean(i); |
| 2378 | final int myPrivateClean = memInfo.getOtherPrivateClean(i); |
| 2379 | final int mySwappedOut = memInfo.getOtherSwappedOut(i); |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2380 | final int mySwappedOutPss = memInfo.getOtherSwappedOutPss(i); |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2381 | if (myPss != 0 || mySharedDirty != 0 || myPrivateDirty != 0 |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2382 | || mySharedClean != 0 || myPrivateClean != 0 |
| 2383 | || (memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut) != 0) { |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2384 | if (dumpFullInfo) { |
| 2385 | printRow(pw, HEAP_FULL_COLUMN, Debug.MemoryInfo.getOtherLabel(i), |
| 2386 | myPss, mySwappablePss, mySharedDirty, myPrivateDirty, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2387 | mySharedClean, myPrivateClean, |
| 2388 | memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut, |
| 2389 | "", "", ""); |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2390 | } else { |
| 2391 | printRow(pw, HEAP_COLUMN, Debug.MemoryInfo.getOtherLabel(i), |
| 2392 | myPss, myPrivateDirty, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2393 | myPrivateClean, |
| 2394 | memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut, |
| 2395 | "", "", ""); |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2396 | } |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2397 | otherPss -= myPss; |
| 2398 | otherSwappablePss -= mySwappablePss; |
| 2399 | otherSharedDirty -= mySharedDirty; |
| 2400 | otherPrivateDirty -= myPrivateDirty; |
| 2401 | otherSharedClean -= mySharedClean; |
| 2402 | otherPrivateClean -= myPrivateClean; |
| 2403 | otherSwappedOut -= mySwappedOut; |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2404 | otherSwappedOutPss -= mySwappedOutPss; |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2405 | } |
| 2406 | } |
| 2407 | |
| 2408 | if (dumpFullInfo) { |
| 2409 | printRow(pw, HEAP_FULL_COLUMN, "Unknown", otherPss, otherSwappablePss, |
| 2410 | otherSharedDirty, otherPrivateDirty, otherSharedClean, otherPrivateClean, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2411 | memInfo.hasSwappedOutPss ? otherSwappedOutPss : otherSwappedOut, |
| 2412 | "", "", ""); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2413 | printRow(pw, HEAP_FULL_COLUMN, "TOTAL", memInfo.getTotalPss(), |
| 2414 | memInfo.getTotalSwappablePss(), |
| 2415 | memInfo.getTotalSharedDirty(), memInfo.getTotalPrivateDirty(), |
| 2416 | memInfo.getTotalSharedClean(), memInfo.getTotalPrivateClean(), |
Thierry Strudel | 9b51160 | 2016-02-25 17:46:38 -0800 | [diff] [blame] | 2417 | memInfo.hasSwappedOutPss ? memInfo.getTotalSwappedOutPss() : |
| 2418 | memInfo.getTotalSwappedOut(), |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2419 | nativeMax+dalvikMax, nativeAllocated+dalvikAllocated, |
| 2420 | nativeFree+dalvikFree); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2421 | } else { |
| 2422 | printRow(pw, HEAP_COLUMN, "Unknown", otherPss, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2423 | otherPrivateDirty, otherPrivateClean, |
| 2424 | memInfo.hasSwappedOutPss ? otherSwappedOutPss : otherSwappedOut, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2425 | "", "", ""); |
| 2426 | printRow(pw, HEAP_COLUMN, "TOTAL", memInfo.getTotalPss(), |
| 2427 | memInfo.getTotalPrivateDirty(), |
| 2428 | memInfo.getTotalPrivateClean(), |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2429 | memInfo.hasSwappedOutPss ? memInfo.getTotalSwappedOutPss() : |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2430 | memInfo.getTotalSwappedOut(), |
| 2431 | nativeMax+dalvikMax, |
| 2432 | nativeAllocated+dalvikAllocated, nativeFree+dalvikFree); |
| 2433 | } |
| 2434 | |
| 2435 | if (dumpDalvik) { |
| 2436 | pw.println(" "); |
| 2437 | pw.println(" Dalvik Details"); |
| 2438 | |
| 2439 | for (int i=Debug.MemoryInfo.NUM_OTHER_STATS; |
| 2440 | i<Debug.MemoryInfo.NUM_OTHER_STATS + Debug.MemoryInfo.NUM_DVK_STATS; i++) { |
| 2441 | final int myPss = memInfo.getOtherPss(i); |
| 2442 | final int mySwappablePss = memInfo.getOtherSwappablePss(i); |
| 2443 | final int mySharedDirty = memInfo.getOtherSharedDirty(i); |
| 2444 | final int myPrivateDirty = memInfo.getOtherPrivateDirty(i); |
| 2445 | final int mySharedClean = memInfo.getOtherSharedClean(i); |
| 2446 | final int myPrivateClean = memInfo.getOtherPrivateClean(i); |
| 2447 | final int mySwappedOut = memInfo.getOtherSwappedOut(i); |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2448 | final int mySwappedOutPss = memInfo.getOtherSwappedOutPss(i); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2449 | if (myPss != 0 || mySharedDirty != 0 || myPrivateDirty != 0 |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2450 | || mySharedClean != 0 || myPrivateClean != 0 |
| 2451 | || (memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut) != 0) { |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2452 | if (dumpFullInfo) { |
| 2453 | printRow(pw, HEAP_FULL_COLUMN, Debug.MemoryInfo.getOtherLabel(i), |
| 2454 | myPss, mySwappablePss, mySharedDirty, myPrivateDirty, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2455 | mySharedClean, myPrivateClean, |
| 2456 | memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut, |
| 2457 | "", "", ""); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2458 | } else { |
| 2459 | printRow(pw, HEAP_COLUMN, Debug.MemoryInfo.getOtherLabel(i), |
| 2460 | myPss, myPrivateDirty, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2461 | myPrivateClean, |
| 2462 | memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut, |
| 2463 | "", "", ""); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2464 | } |
| 2465 | } |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2466 | } |
| 2467 | } |
| 2468 | } |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2469 | |
| 2470 | pw.println(" "); |
| 2471 | pw.println(" App Summary"); |
| 2472 | printRow(pw, ONE_COUNT_COLUMN_HEADER, "", "Pss(KB)"); |
| 2473 | printRow(pw, ONE_COUNT_COLUMN_HEADER, "", "------"); |
| 2474 | printRow(pw, ONE_COUNT_COLUMN, |
| 2475 | "Java Heap:", memInfo.getSummaryJavaHeap()); |
| 2476 | printRow(pw, ONE_COUNT_COLUMN, |
| 2477 | "Native Heap:", memInfo.getSummaryNativeHeap()); |
| 2478 | printRow(pw, ONE_COUNT_COLUMN, |
| 2479 | "Code:", memInfo.getSummaryCode()); |
| 2480 | printRow(pw, ONE_COUNT_COLUMN, |
| 2481 | "Stack:", memInfo.getSummaryStack()); |
| 2482 | printRow(pw, ONE_COUNT_COLUMN, |
| 2483 | "Graphics:", memInfo.getSummaryGraphics()); |
| 2484 | printRow(pw, ONE_COUNT_COLUMN, |
| 2485 | "Private Other:", memInfo.getSummaryPrivateOther()); |
| 2486 | printRow(pw, ONE_COUNT_COLUMN, |
| 2487 | "System:", memInfo.getSummarySystem()); |
| 2488 | pw.println(" "); |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2489 | if (memInfo.hasSwappedOutPss) { |
| 2490 | printRow(pw, TWO_COUNT_COLUMNS, |
| 2491 | "TOTAL:", memInfo.getSummaryTotalPss(), |
| 2492 | "TOTAL SWAP PSS:", memInfo.getSummaryTotalSwapPss()); |
| 2493 | } else { |
| 2494 | printRow(pw, TWO_COUNT_COLUMNS, |
| 2495 | "TOTAL:", memInfo.getSummaryTotalPss(), |
| 2496 | "TOTAL SWAP (KB):", memInfo.getSummaryTotalSwap()); |
| 2497 | } |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2498 | } |
| 2499 | |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2500 | /** |
| 2501 | * Dump heap info to proto. |
| 2502 | * |
| 2503 | * @param hasSwappedOutPss determines whether to use dirtySwap or dirtySwapPss |
| 2504 | */ |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 2505 | private static void dumpMemoryInfo(ProtoOutputStream proto, long fieldId, String name, |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2506 | int pss, int cleanPss, int sharedDirty, int privateDirty, |
| 2507 | int sharedClean, int privateClean, |
| 2508 | boolean hasSwappedOutPss, int dirtySwap, int dirtySwapPss) { |
| 2509 | final long token = proto.start(fieldId); |
| 2510 | |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 2511 | proto.write(MemInfoProto.ProcessMemory.MemoryInfo.NAME, name); |
| 2512 | proto.write(MemInfoProto.ProcessMemory.MemoryInfo.TOTAL_PSS_KB, pss); |
| 2513 | proto.write(MemInfoProto.ProcessMemory.MemoryInfo.CLEAN_PSS_KB, cleanPss); |
| 2514 | proto.write(MemInfoProto.ProcessMemory.MemoryInfo.SHARED_DIRTY_KB, sharedDirty); |
| 2515 | proto.write(MemInfoProto.ProcessMemory.MemoryInfo.PRIVATE_DIRTY_KB, privateDirty); |
| 2516 | proto.write(MemInfoProto.ProcessMemory.MemoryInfo.SHARED_CLEAN_KB, sharedClean); |
| 2517 | proto.write(MemInfoProto.ProcessMemory.MemoryInfo.PRIVATE_CLEAN_KB, privateClean); |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2518 | if (hasSwappedOutPss) { |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 2519 | proto.write(MemInfoProto.ProcessMemory.MemoryInfo.DIRTY_SWAP_PSS_KB, dirtySwapPss); |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2520 | } else { |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 2521 | proto.write(MemInfoProto.ProcessMemory.MemoryInfo.DIRTY_SWAP_KB, dirtySwap); |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2522 | } |
| 2523 | |
| 2524 | proto.end(token); |
| 2525 | } |
| 2526 | |
| 2527 | /** |
| 2528 | * Dump mem info data to proto. |
| 2529 | */ |
| 2530 | public static void dumpMemInfoTable(ProtoOutputStream proto, Debug.MemoryInfo memInfo, |
| 2531 | boolean dumpDalvik, boolean dumpSummaryOnly, |
| 2532 | long nativeMax, long nativeAllocated, long nativeFree, |
| 2533 | long dalvikMax, long dalvikAllocated, long dalvikFree) { |
| 2534 | |
| 2535 | if (!dumpSummaryOnly) { |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 2536 | final long nhToken = proto.start(MemInfoProto.ProcessMemory.NATIVE_HEAP); |
| 2537 | dumpMemoryInfo(proto, MemInfoProto.ProcessMemory.HeapInfo.MEM_INFO, "Native Heap", |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2538 | memInfo.nativePss, memInfo.nativeSwappablePss, memInfo.nativeSharedDirty, |
| 2539 | memInfo.nativePrivateDirty, memInfo.nativeSharedClean, |
| 2540 | memInfo.nativePrivateClean, memInfo.hasSwappedOutPss, |
| 2541 | memInfo.nativeSwappedOut, memInfo.nativeSwappedOutPss); |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 2542 | proto.write(MemInfoProto.ProcessMemory.HeapInfo.HEAP_SIZE_KB, nativeMax); |
| 2543 | proto.write(MemInfoProto.ProcessMemory.HeapInfo.HEAP_ALLOC_KB, nativeAllocated); |
| 2544 | proto.write(MemInfoProto.ProcessMemory.HeapInfo.HEAP_FREE_KB, nativeFree); |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2545 | proto.end(nhToken); |
| 2546 | |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 2547 | final long dvToken = proto.start(MemInfoProto.ProcessMemory.DALVIK_HEAP); |
| 2548 | dumpMemoryInfo(proto, MemInfoProto.ProcessMemory.HeapInfo.MEM_INFO, "Dalvik Heap", |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2549 | memInfo.dalvikPss, memInfo.dalvikSwappablePss, memInfo.dalvikSharedDirty, |
| 2550 | memInfo.dalvikPrivateDirty, memInfo.dalvikSharedClean, |
| 2551 | memInfo.dalvikPrivateClean, memInfo.hasSwappedOutPss, |
| 2552 | memInfo.dalvikSwappedOut, memInfo.dalvikSwappedOutPss); |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 2553 | proto.write(MemInfoProto.ProcessMemory.HeapInfo.HEAP_SIZE_KB, dalvikMax); |
| 2554 | proto.write(MemInfoProto.ProcessMemory.HeapInfo.HEAP_ALLOC_KB, dalvikAllocated); |
| 2555 | proto.write(MemInfoProto.ProcessMemory.HeapInfo.HEAP_FREE_KB, dalvikFree); |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2556 | proto.end(dvToken); |
| 2557 | |
| 2558 | int otherPss = memInfo.otherPss; |
| 2559 | int otherSwappablePss = memInfo.otherSwappablePss; |
| 2560 | int otherSharedDirty = memInfo.otherSharedDirty; |
| 2561 | int otherPrivateDirty = memInfo.otherPrivateDirty; |
| 2562 | int otherSharedClean = memInfo.otherSharedClean; |
| 2563 | int otherPrivateClean = memInfo.otherPrivateClean; |
| 2564 | int otherSwappedOut = memInfo.otherSwappedOut; |
| 2565 | int otherSwappedOutPss = memInfo.otherSwappedOutPss; |
| 2566 | |
| 2567 | for (int i = 0; i < Debug.MemoryInfo.NUM_OTHER_STATS; i++) { |
| 2568 | final int myPss = memInfo.getOtherPss(i); |
| 2569 | final int mySwappablePss = memInfo.getOtherSwappablePss(i); |
| 2570 | final int mySharedDirty = memInfo.getOtherSharedDirty(i); |
| 2571 | final int myPrivateDirty = memInfo.getOtherPrivateDirty(i); |
| 2572 | final int mySharedClean = memInfo.getOtherSharedClean(i); |
| 2573 | final int myPrivateClean = memInfo.getOtherPrivateClean(i); |
| 2574 | final int mySwappedOut = memInfo.getOtherSwappedOut(i); |
| 2575 | final int mySwappedOutPss = memInfo.getOtherSwappedOutPss(i); |
| 2576 | if (myPss != 0 || mySharedDirty != 0 || myPrivateDirty != 0 |
| 2577 | || mySharedClean != 0 || myPrivateClean != 0 |
| 2578 | || (memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut) != 0) { |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 2579 | dumpMemoryInfo(proto, MemInfoProto.ProcessMemory.OTHER_HEAPS, |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2580 | Debug.MemoryInfo.getOtherLabel(i), |
| 2581 | myPss, mySwappablePss, mySharedDirty, myPrivateDirty, |
| 2582 | mySharedClean, myPrivateClean, |
| 2583 | memInfo.hasSwappedOutPss, mySwappedOut, mySwappedOutPss); |
| 2584 | |
| 2585 | otherPss -= myPss; |
| 2586 | otherSwappablePss -= mySwappablePss; |
| 2587 | otherSharedDirty -= mySharedDirty; |
| 2588 | otherPrivateDirty -= myPrivateDirty; |
| 2589 | otherSharedClean -= mySharedClean; |
| 2590 | otherPrivateClean -= myPrivateClean; |
| 2591 | otherSwappedOut -= mySwappedOut; |
| 2592 | otherSwappedOutPss -= mySwappedOutPss; |
| 2593 | } |
| 2594 | } |
| 2595 | |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 2596 | dumpMemoryInfo(proto, MemInfoProto.ProcessMemory.UNKNOWN_HEAP, "Unknown", |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2597 | otherPss, otherSwappablePss, |
| 2598 | otherSharedDirty, otherPrivateDirty, otherSharedClean, otherPrivateClean, |
| 2599 | memInfo.hasSwappedOutPss, otherSwappedOut, otherSwappedOutPss); |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 2600 | final long tToken = proto.start(MemInfoProto.ProcessMemory.TOTAL_HEAP); |
| 2601 | dumpMemoryInfo(proto, MemInfoProto.ProcessMemory.HeapInfo.MEM_INFO, "TOTAL", |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2602 | memInfo.getTotalPss(), memInfo.getTotalSwappablePss(), |
| 2603 | memInfo.getTotalSharedDirty(), memInfo.getTotalPrivateDirty(), |
| 2604 | memInfo.getTotalSharedClean(), memInfo.getTotalPrivateClean(), |
| 2605 | memInfo.hasSwappedOutPss, memInfo.getTotalSwappedOut(), |
| 2606 | memInfo.getTotalSwappedOutPss()); |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 2607 | proto.write(MemInfoProto.ProcessMemory.HeapInfo.HEAP_SIZE_KB, nativeMax + dalvikMax); |
| 2608 | proto.write(MemInfoProto.ProcessMemory.HeapInfo.HEAP_ALLOC_KB, |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2609 | nativeAllocated + dalvikAllocated); |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 2610 | proto.write(MemInfoProto.ProcessMemory.HeapInfo.HEAP_FREE_KB, nativeFree + dalvikFree); |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2611 | proto.end(tToken); |
| 2612 | |
| 2613 | if (dumpDalvik) { |
| 2614 | for (int i = Debug.MemoryInfo.NUM_OTHER_STATS; |
| 2615 | i < Debug.MemoryInfo.NUM_OTHER_STATS + Debug.MemoryInfo.NUM_DVK_STATS; |
| 2616 | i++) { |
| 2617 | final int myPss = memInfo.getOtherPss(i); |
| 2618 | final int mySwappablePss = memInfo.getOtherSwappablePss(i); |
| 2619 | final int mySharedDirty = memInfo.getOtherSharedDirty(i); |
| 2620 | final int myPrivateDirty = memInfo.getOtherPrivateDirty(i); |
| 2621 | final int mySharedClean = memInfo.getOtherSharedClean(i); |
| 2622 | final int myPrivateClean = memInfo.getOtherPrivateClean(i); |
| 2623 | final int mySwappedOut = memInfo.getOtherSwappedOut(i); |
| 2624 | final int mySwappedOutPss = memInfo.getOtherSwappedOutPss(i); |
| 2625 | if (myPss != 0 || mySharedDirty != 0 || myPrivateDirty != 0 |
| 2626 | || mySharedClean != 0 || myPrivateClean != 0 |
| 2627 | || (memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut) != 0) { |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 2628 | dumpMemoryInfo(proto, MemInfoProto.ProcessMemory.DALVIK_DETAILS, |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2629 | Debug.MemoryInfo.getOtherLabel(i), |
| 2630 | myPss, mySwappablePss, mySharedDirty, myPrivateDirty, |
| 2631 | mySharedClean, myPrivateClean, |
| 2632 | memInfo.hasSwappedOutPss, mySwappedOut, mySwappedOutPss); |
| 2633 | } |
| 2634 | } |
| 2635 | } |
| 2636 | } |
| 2637 | |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 2638 | final long asToken = proto.start(MemInfoProto.ProcessMemory.APP_SUMMARY); |
| 2639 | proto.write(MemInfoProto.ProcessMemory.AppSummary.JAVA_HEAP_PSS_KB, |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2640 | memInfo.getSummaryJavaHeap()); |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 2641 | proto.write(MemInfoProto.ProcessMemory.AppSummary.NATIVE_HEAP_PSS_KB, |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2642 | memInfo.getSummaryNativeHeap()); |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 2643 | proto.write(MemInfoProto.ProcessMemory.AppSummary.CODE_PSS_KB, memInfo.getSummaryCode()); |
| 2644 | proto.write(MemInfoProto.ProcessMemory.AppSummary.STACK_PSS_KB, memInfo.getSummaryStack()); |
| 2645 | proto.write(MemInfoProto.ProcessMemory.AppSummary.GRAPHICS_PSS_KB, |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2646 | memInfo.getSummaryGraphics()); |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 2647 | proto.write(MemInfoProto.ProcessMemory.AppSummary.PRIVATE_OTHER_PSS_KB, |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2648 | memInfo.getSummaryPrivateOther()); |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 2649 | proto.write(MemInfoProto.ProcessMemory.AppSummary.SYSTEM_PSS_KB, |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2650 | memInfo.getSummarySystem()); |
| 2651 | if (memInfo.hasSwappedOutPss) { |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 2652 | proto.write(MemInfoProto.ProcessMemory.AppSummary.TOTAL_SWAP_PSS, |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2653 | memInfo.getSummaryTotalSwapPss()); |
| 2654 | } else { |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 2655 | proto.write(MemInfoProto.ProcessMemory.AppSummary.TOTAL_SWAP_PSS, |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2656 | memInfo.getSummaryTotalSwap()); |
| 2657 | } |
| 2658 | proto.end(asToken); |
| 2659 | } |
| 2660 | |
Jeff Hamilton | 52d3203 | 2011-01-08 15:31:26 -0600 | [diff] [blame] | 2661 | public void registerOnActivityPausedListener(Activity activity, |
| 2662 | OnActivityPausedListener listener) { |
| 2663 | synchronized (mOnPauseListeners) { |
| 2664 | ArrayList<OnActivityPausedListener> list = mOnPauseListeners.get(activity); |
| 2665 | if (list == null) { |
| 2666 | list = new ArrayList<OnActivityPausedListener>(); |
| 2667 | mOnPauseListeners.put(activity, list); |
| 2668 | } |
| 2669 | list.add(listener); |
| 2670 | } |
| 2671 | } |
| 2672 | |
Jeff Hamilton | ce3224c | 2011-01-17 11:05:03 -0800 | [diff] [blame] | 2673 | public void unregisterOnActivityPausedListener(Activity activity, |
| 2674 | OnActivityPausedListener listener) { |
| 2675 | synchronized (mOnPauseListeners) { |
| 2676 | ArrayList<OnActivityPausedListener> list = mOnPauseListeners.get(activity); |
| 2677 | if (list != null) { |
| 2678 | list.remove(listener); |
| 2679 | } |
| 2680 | } |
| 2681 | } |
| 2682 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2683 | public final ActivityInfo resolveActivityInfo(Intent intent) { |
| 2684 | ActivityInfo aInfo = intent.resolveActivityInfo( |
| 2685 | mInitialApplication.getPackageManager(), PackageManager.GET_SHARED_LIBRARY_FILES); |
| 2686 | if (aInfo == null) { |
| 2687 | // Throw an exception. |
| 2688 | Instrumentation.checkStartActivityResult( |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 2689 | ActivityManager.START_CLASS_NOT_FOUND, intent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2690 | } |
| 2691 | return aInfo; |
| 2692 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2693 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2694 | public final Activity startActivityNow(Activity parent, String id, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2695 | Intent intent, ActivityInfo activityInfo, IBinder token, Bundle state, |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 2696 | Activity.NonConfigurationInstances lastNonConfigurationInstances) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2697 | ActivityClientRecord r = new ActivityClientRecord(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2698 | r.token = token; |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 2699 | r.ident = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2700 | r.intent = intent; |
| 2701 | r.state = state; |
| 2702 | r.parent = parent; |
| 2703 | r.embeddedID = id; |
| 2704 | r.activityInfo = activityInfo; |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 2705 | r.lastNonConfigurationInstances = lastNonConfigurationInstances; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2706 | if (localLOGV) { |
| 2707 | ComponentName compname = intent.getComponent(); |
| 2708 | String name; |
| 2709 | if (compname != null) { |
| 2710 | name = compname.toShortString(); |
| 2711 | } else { |
| 2712 | name = "(Intent " + intent + ").getComponent() returned null"; |
| 2713 | } |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2714 | Slog.v(TAG, "Performing launch: action=" + intent.getAction() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2715 | + ", comp=" + name |
| 2716 | + ", token=" + token); |
| 2717 | } |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 2718 | // TODO(lifecycler): Can't switch to use #handleLaunchActivity() because it will try to |
| 2719 | // call #reportSizeConfigurations(), but the server might not know anything about the |
| 2720 | // activity if it was launched from LocalAcvitivyManager. |
| 2721 | return performLaunchActivity(r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2722 | } |
| 2723 | |
| 2724 | public final Activity getActivity(IBinder token) { |
| 2725 | return mActivities.get(token).activity; |
| 2726 | } |
| 2727 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 2728 | @Override |
| 2729 | public ActivityClientRecord getActivityClient(IBinder token) { |
| 2730 | return mActivities.get(token); |
| 2731 | } |
| 2732 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2733 | public final void sendActivityResult( |
| 2734 | IBinder token, String id, int requestCode, |
| 2735 | int resultCode, Intent data) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2736 | if (DEBUG_RESULTS) Slog.v(TAG, "sendActivityResult: id=" + id |
Chris Tate | 8a7dc17 | 2009-03-24 20:11:42 -0700 | [diff] [blame] | 2737 | + " req=" + requestCode + " res=" + resultCode + " data=" + data); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2738 | ArrayList<ResultInfo> list = new ArrayList<ResultInfo>(); |
| 2739 | list.add(new ResultInfo(id, requestCode, resultCode, data)); |
Andrii Kulian | 9c5ea9c | 2017-12-07 09:31:01 -0800 | [diff] [blame] | 2740 | final ClientTransaction clientTransaction = ClientTransaction.obtain(mAppThread, token); |
| 2741 | clientTransaction.addCallback(ActivityResultItem.obtain(list)); |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 2742 | try { |
| 2743 | mAppThread.scheduleTransaction(clientTransaction); |
| 2744 | } catch (RemoteException e) { |
| 2745 | // Local scheduling |
| 2746 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2747 | } |
| 2748 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 2749 | void sendMessage(int what, Object obj) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 2750 | sendMessage(what, obj, 0, 0, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2751 | } |
| 2752 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 2753 | private void sendMessage(int what, Object obj, int arg1) { |
| 2754 | sendMessage(what, obj, arg1, 0, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2755 | } |
| 2756 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 2757 | private void sendMessage(int what, Object obj, int arg1, int arg2) { |
| 2758 | sendMessage(what, obj, arg1, arg2, false); |
| 2759 | } |
| 2760 | |
| 2761 | private void sendMessage(int what, Object obj, int arg1, int arg2, boolean async) { |
| 2762 | if (DEBUG_MESSAGES) Slog.v( |
| 2763 | TAG, "SCHEDULE " + what + " " + mH.codeToString(what) |
| 2764 | + ": " + arg1 + " / " + obj); |
| 2765 | Message msg = Message.obtain(); |
| 2766 | msg.what = what; |
| 2767 | msg.obj = obj; |
| 2768 | msg.arg1 = arg1; |
| 2769 | msg.arg2 = arg2; |
| 2770 | if (async) { |
| 2771 | msg.setAsynchronous(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2772 | } |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 2773 | mH.sendMessage(msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2774 | } |
| 2775 | |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 2776 | private void sendMessage(int what, Object obj, int arg1, int arg2, int seq) { |
| 2777 | if (DEBUG_MESSAGES) Slog.v( |
| 2778 | TAG, "SCHEDULE " + mH.codeToString(what) + " arg1=" + arg1 + " arg2=" + arg2 + |
| 2779 | "seq= " + seq); |
| 2780 | Message msg = Message.obtain(); |
| 2781 | msg.what = what; |
| 2782 | SomeArgs args = SomeArgs.obtain(); |
| 2783 | args.arg1 = obj; |
| 2784 | args.argi1 = arg1; |
| 2785 | args.argi2 = arg2; |
| 2786 | args.argi3 = seq; |
| 2787 | msg.obj = args; |
| 2788 | mH.sendMessage(msg); |
| 2789 | } |
| 2790 | |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 2791 | final void scheduleContextCleanup(ContextImpl context, String who, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2792 | String what) { |
| 2793 | ContextCleanupInfo cci = new ContextCleanupInfo(); |
| 2794 | cci.context = context; |
| 2795 | cci.who = who; |
| 2796 | cci.what = what; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 2797 | sendMessage(H.CLEAN_UP_CONTEXT, cci); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2798 | } |
| 2799 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 2800 | /** Core implementation of activity launch. */ |
| 2801 | private Activity performLaunchActivity(ActivityClientRecord r) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2802 | ActivityInfo aInfo = r.activityInfo; |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2803 | if (r.packageInfo == null) { |
| 2804 | r.packageInfo = getPackageInfo(aInfo.applicationInfo, r.compatInfo, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2805 | Context.CONTEXT_INCLUDE_CODE); |
| 2806 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2807 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2808 | ComponentName component = r.intent.getComponent(); |
| 2809 | if (component == null) { |
| 2810 | component = r.intent.resolveActivity( |
| 2811 | mInitialApplication.getPackageManager()); |
| 2812 | r.intent.setComponent(component); |
| 2813 | } |
| 2814 | |
| 2815 | if (r.activityInfo.targetActivity != null) { |
| 2816 | component = new ComponentName(r.activityInfo.packageName, |
| 2817 | r.activityInfo.targetActivity); |
| 2818 | } |
| 2819 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 2820 | ContextImpl appContext = createBaseContextForActivity(r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2821 | Activity activity = null; |
| 2822 | try { |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 2823 | java.lang.ClassLoader cl = appContext.getClassLoader(); |
Dan Sandler | 07fe63e | 2017-08-15 16:41:11 -0400 | [diff] [blame] | 2824 | activity = mInstrumentation.newActivity( |
| 2825 | cl, component.getClassName(), r.intent); |
Brad Fitzpatrick | 5f8b5c1 | 2011-01-20 15:12:08 -0800 | [diff] [blame] | 2826 | StrictMode.incrementExpectedActivityCount(activity.getClass()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2827 | r.intent.setExtrasClassLoader(cl); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 2828 | r.intent.prepareToEnterProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2829 | if (r.state != null) { |
| 2830 | r.state.setClassLoader(cl); |
| 2831 | } |
| 2832 | } catch (Exception e) { |
| 2833 | if (!mInstrumentation.onException(activity, e)) { |
| 2834 | throw new RuntimeException( |
| 2835 | "Unable to instantiate activity " + component |
| 2836 | + ": " + e.toString(), e); |
| 2837 | } |
| 2838 | } |
| 2839 | |
| 2840 | try { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2841 | Application app = r.packageInfo.makeApplication(false, mInstrumentation); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2842 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2843 | if (localLOGV) Slog.v(TAG, "Performing launch of " + r); |
| 2844 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2845 | TAG, r + ": app=" + app |
| 2846 | + ", appName=" + app.getPackageName() |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2847 | + ", pkg=" + r.packageInfo.getPackageName() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2848 | + ", comp=" + r.intent.getComponent().toShortString() |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2849 | + ", dir=" + r.packageInfo.getAppDir()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2850 | |
| 2851 | if (activity != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2852 | CharSequence title = r.activityInfo.loadLabel(appContext.getPackageManager()); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 2853 | Configuration config = new Configuration(mCompatConfiguration); |
Andrii Kulian | d0ad938 | 2016-04-18 20:54:20 -0700 | [diff] [blame] | 2854 | if (r.overrideConfig != null) { |
| 2855 | config.updateFrom(r.overrideConfig); |
| 2856 | } |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2857 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Launching activity " |
Dianne Hackborn | dc6b635 | 2009-09-30 14:20:09 -0700 | [diff] [blame] | 2858 | + r.activityInfo.name + " with config " + config); |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 2859 | Window window = null; |
| 2860 | if (r.mPendingRemoveWindow != null && r.mPreserveWindow) { |
| 2861 | window = r.mPendingRemoveWindow; |
| 2862 | r.mPendingRemoveWindow = null; |
| 2863 | r.mPendingRemoveWindowManager = null; |
| 2864 | } |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 2865 | appContext.setOuterContext(activity); |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 2866 | activity.attach(appContext, this, getInstrumentation(), r.token, |
| 2867 | r.ident, app, r.intent, r.activityInfo, title, r.parent, |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 2868 | r.embeddedID, r.lastNonConfigurationInstances, config, |
Andrii Kulian | 51c1b67 | 2017-04-07 18:39:32 -0700 | [diff] [blame] | 2869 | r.referrer, r.voiceInteractor, window, r.configCallback); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2870 | |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 2871 | r.lastNonConfigurationInstances = null; |
Sudheer Shanka | 84a4895 | 2017-03-08 18:19:01 -0800 | [diff] [blame] | 2872 | checkAndBlockForNetworkAccess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2873 | activity.mStartedActivity = false; |
| 2874 | int theme = r.activityInfo.getThemeResource(); |
| 2875 | if (theme != 0) { |
| 2876 | activity.setTheme(theme); |
| 2877 | } |
| 2878 | |
| 2879 | activity.mCalled = false; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2880 | if (r.isPersistable()) { |
| 2881 | mInstrumentation.callActivityOnCreate(activity, r.state, r.persistentState); |
| 2882 | } else { |
| 2883 | mInstrumentation.callActivityOnCreate(activity, r.state); |
| 2884 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2885 | if (!activity.mCalled) { |
| 2886 | throw new SuperNotCalledException( |
| 2887 | "Activity " + r.intent.getComponent().toShortString() + |
| 2888 | " did not call through to super.onCreate()"); |
| 2889 | } |
| 2890 | r.activity = activity; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2891 | } |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 2892 | r.setState(ON_CREATE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2893 | |
| 2894 | mActivities.put(r.token, r); |
| 2895 | |
| 2896 | } catch (SuperNotCalledException e) { |
| 2897 | throw e; |
| 2898 | |
| 2899 | } catch (Exception e) { |
| 2900 | if (!mInstrumentation.onException(activity, e)) { |
| 2901 | throw new RuntimeException( |
| 2902 | "Unable to start activity " + component |
| 2903 | + ": " + e.toString(), e); |
| 2904 | } |
| 2905 | } |
| 2906 | |
| 2907 | return activity; |
| 2908 | } |
| 2909 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 2910 | @Override |
| 2911 | public void handleStartActivity(ActivityClientRecord r, |
| 2912 | PendingTransactionActions pendingActions) { |
| 2913 | final Activity activity = r.activity; |
| 2914 | if (r.activity == null) { |
| 2915 | // TODO(lifecycler): What do we do in this case? |
| 2916 | return; |
| 2917 | } |
| 2918 | if (!r.stopped) { |
| 2919 | throw new IllegalStateException("Can't start activity that is not stopped."); |
| 2920 | } |
| 2921 | if (r.activity.mFinished) { |
| 2922 | // TODO(lifecycler): How can this happen? |
| 2923 | return; |
| 2924 | } |
| 2925 | |
| 2926 | // Start |
| 2927 | activity.performStart(); |
| 2928 | r.setState(ON_START); |
| 2929 | |
| 2930 | if (pendingActions == null) { |
| 2931 | // No more work to do. |
| 2932 | return; |
| 2933 | } |
| 2934 | |
| 2935 | // Restore instance state |
| 2936 | if (pendingActions.shouldRestoreInstanceState()) { |
| 2937 | if (r.isPersistable()) { |
| 2938 | if (r.state != null || r.persistentState != null) { |
| 2939 | mInstrumentation.callActivityOnRestoreInstanceState(activity, r.state, |
| 2940 | r.persistentState); |
| 2941 | } |
| 2942 | } else if (r.state != null) { |
| 2943 | mInstrumentation.callActivityOnRestoreInstanceState(activity, r.state); |
| 2944 | } |
| 2945 | } |
| 2946 | |
| 2947 | // Call postOnCreate() |
| 2948 | if (pendingActions.shouldCallOnPostCreate()) { |
| 2949 | activity.mCalled = false; |
| 2950 | if (r.isPersistable()) { |
| 2951 | mInstrumentation.callActivityOnPostCreate(activity, r.state, |
| 2952 | r.persistentState); |
| 2953 | } else { |
| 2954 | mInstrumentation.callActivityOnPostCreate(activity, r.state); |
| 2955 | } |
| 2956 | if (!activity.mCalled) { |
| 2957 | throw new SuperNotCalledException( |
| 2958 | "Activity " + r.intent.getComponent().toShortString() |
| 2959 | + " did not call through to super.onPostCreate()"); |
| 2960 | } |
| 2961 | } |
| 2962 | } |
| 2963 | |
Sudheer Shanka | 84a4895 | 2017-03-08 18:19:01 -0800 | [diff] [blame] | 2964 | /** |
| 2965 | * Checks if {@link #mNetworkBlockSeq} is {@link #INVALID_PROC_STATE_SEQ} and if so, returns |
| 2966 | * immediately. Otherwise, makes a blocking call to ActivityManagerService to wait for the |
| 2967 | * network rules to get updated. |
| 2968 | */ |
| 2969 | private void checkAndBlockForNetworkAccess() { |
| 2970 | synchronized (mNetworkPolicyLock) { |
| 2971 | if (mNetworkBlockSeq != INVALID_PROC_STATE_SEQ) { |
| 2972 | try { |
| 2973 | ActivityManager.getService().waitForNetworkStateUpdate(mNetworkBlockSeq); |
| 2974 | mNetworkBlockSeq = INVALID_PROC_STATE_SEQ; |
| 2975 | } catch (RemoteException ignored) {} |
| 2976 | } |
| 2977 | } |
| 2978 | } |
| 2979 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 2980 | private ContextImpl createBaseContextForActivity(ActivityClientRecord r) { |
| 2981 | final int displayId; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2982 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 2983 | displayId = ActivityManager.getService().getActivityDisplayId(r.token); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2984 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2985 | throw e.rethrowFromSystemServer(); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2986 | } |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 2987 | |
Wale Ogunwale | 7c72668 | 2015-02-06 17:34:28 -0800 | [diff] [blame] | 2988 | ContextImpl appContext = ContextImpl.createActivityContext( |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2989 | this, r.packageInfo, r.activityInfo, r.token, displayId, r.overrideConfig); |
Wale Ogunwale | 7c72668 | 2015-02-06 17:34:28 -0800 | [diff] [blame] | 2990 | |
| 2991 | final DisplayManagerGlobal dm = DisplayManagerGlobal.getInstance(); |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 2992 | // For debugging purposes, if the activity's package name contains the value of |
| 2993 | // the "debug.use-second-display" system property as a substring, then show |
| 2994 | // its content on a secondary display if there is one. |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 2995 | String pkgName = SystemProperties.get("debug.second-display.pkg"); |
| 2996 | if (pkgName != null && !pkgName.isEmpty() |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2997 | && r.packageInfo.mPackageName.contains(pkgName)) { |
Wale Ogunwale | 7c72668 | 2015-02-06 17:34:28 -0800 | [diff] [blame] | 2998 | for (int id : dm.getDisplayIds()) { |
| 2999 | if (id != Display.DEFAULT_DISPLAY) { |
Wale Ogunwale | 2669851 | 2015-06-05 16:55:33 -0700 | [diff] [blame] | 3000 | Display display = |
Bryce Lee | 609bf65 | 2017-02-09 16:50:13 -0800 | [diff] [blame] | 3001 | dm.getCompatibleDisplay(id, appContext.getResources()); |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 3002 | appContext = (ContextImpl) appContext.createDisplayContext(display); |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 3003 | break; |
| 3004 | } |
| 3005 | } |
| 3006 | } |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 3007 | return appContext; |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 3008 | } |
| 3009 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 3010 | /** |
| 3011 | * Extended implementation of activity launch. Used when server requests a launch or relaunch. |
| 3012 | */ |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 3013 | @Override |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 3014 | public Activity handleLaunchActivity(ActivityClientRecord r, |
| 3015 | PendingTransactionActions pendingActions) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3016 | // If we are getting ready to gc after going to the background, well |
| 3017 | // we are back active so skip it. |
| 3018 | unscheduleGcIdler(); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3019 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3020 | |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 3021 | if (r.profilerInfo != null) { |
| 3022 | mProfiler.setProfiler(r.profilerInfo); |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 3023 | mProfiler.startProfiling(); |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 3024 | } |
| 3025 | |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 3026 | // Make sure we are running with the most recent config. |
| 3027 | handleConfigurationChanged(null, null); |
| 3028 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3029 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3030 | TAG, "Handling launch of " + r); |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 3031 | |
Chet Haase | 0d1c27a | 2014-11-03 18:35:16 +0000 | [diff] [blame] | 3032 | // Initialize before creating the activity |
Jesse Hall | c37984f | 2017-05-23 16:55:08 -0700 | [diff] [blame] | 3033 | if (!ThreadedRenderer.sRendererDisabled) { |
| 3034 | GraphicsEnvironment.earlyInitEGL(); |
| 3035 | } |
Chet Haase | 0d1c27a | 2014-11-03 18:35:16 +0000 | [diff] [blame] | 3036 | WindowManagerGlobal.initialize(); |
| 3037 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 3038 | final Activity a = performLaunchActivity(r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3039 | |
| 3040 | if (a != null) { |
Dianne Hackborn | 871ecdc | 2009-12-11 15:24:33 -0800 | [diff] [blame] | 3041 | r.createdConfig = new Configuration(mConfiguration); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 3042 | reportSizeConfigurations(r); |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 3043 | if (!r.activity.mFinished && pendingActions != null) { |
| 3044 | pendingActions.setOldState(r.state); |
| 3045 | pendingActions.setRestoreInstanceState(true); |
| 3046 | pendingActions.setCallOnPostCreate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3047 | } |
| 3048 | } else { |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 3049 | // 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] | 3050 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3051 | ActivityManager.getService() |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 3052 | .finishActivity(r.token, Activity.RESULT_CANCELED, null, |
| 3053 | Activity.DONT_FINISH_TASK_WITH_ACTIVITY); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3054 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3055 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3056 | } |
| 3057 | } |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 3058 | |
| 3059 | return a; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3060 | } |
| 3061 | |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 3062 | private void reportSizeConfigurations(ActivityClientRecord r) { |
| 3063 | Configuration[] configurations = r.activity.getResources().getSizeConfigurations(); |
| 3064 | if (configurations == null) { |
| 3065 | return; |
| 3066 | } |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 3067 | SparseIntArray horizontal = new SparseIntArray(); |
| 3068 | SparseIntArray vertical = new SparseIntArray(); |
| 3069 | SparseIntArray smallest = new SparseIntArray(); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 3070 | for (int i = configurations.length - 1; i >= 0; i--) { |
| 3071 | Configuration config = configurations[i]; |
| 3072 | if (config.screenHeightDp != Configuration.SCREEN_HEIGHT_DP_UNDEFINED) { |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 3073 | vertical.put(config.screenHeightDp, 0); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 3074 | } |
| 3075 | if (config.screenWidthDp != Configuration.SCREEN_WIDTH_DP_UNDEFINED) { |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 3076 | horizontal.put(config.screenWidthDp, 0); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 3077 | } |
| 3078 | if (config.smallestScreenWidthDp != Configuration.SMALLEST_SCREEN_WIDTH_DP_UNDEFINED) { |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 3079 | smallest.put(config.smallestScreenWidthDp, 0); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 3080 | } |
| 3081 | } |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 3082 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3083 | ActivityManager.getService().reportSizeConfigurations(r.token, |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 3084 | horizontal.copyKeys(), vertical.copyKeys(), smallest.copyKeys()); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 3085 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3086 | throw ex.rethrowFromSystemServer(); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 3087 | } |
| 3088 | |
| 3089 | } |
| 3090 | |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 3091 | private void deliverNewIntents(ActivityClientRecord r, List<ReferrerIntent> intents) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3092 | final int N = intents.size(); |
| 3093 | for (int i=0; i<N; i++) { |
Dianne Hackborn | a01a0fa | 2014-12-02 10:33:14 -0800 | [diff] [blame] | 3094 | ReferrerIntent intent = intents.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3095 | intent.setExtrasClassLoader(r.activity.getClassLoader()); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 3096 | intent.prepareToEnterProcess(); |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 3097 | r.activity.mFragments.noteStateNotSaved(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3098 | mInstrumentation.callActivityOnNewIntent(r.activity, intent); |
| 3099 | } |
| 3100 | } |
| 3101 | |
Wale Ogunwale | 826c706 | 2016-09-13 08:25:54 -0700 | [diff] [blame] | 3102 | void performNewIntents(IBinder token, List<ReferrerIntent> intents, boolean andPause) { |
| 3103 | final ActivityClientRecord r = mActivities.get(token); |
| 3104 | if (r == null) { |
| 3105 | return; |
| 3106 | } |
| 3107 | |
| 3108 | final boolean resumed = !r.paused; |
| 3109 | if (resumed) { |
| 3110 | r.activity.mTemporaryPause = true; |
| 3111 | mInstrumentation.callActivityOnPause(r.activity); |
| 3112 | } |
Sudheer Shanka | 43b5ea4 | 2017-06-21 11:24:53 -0700 | [diff] [blame] | 3113 | checkAndBlockForNetworkAccess(); |
Wale Ogunwale | 826c706 | 2016-09-13 08:25:54 -0700 | [diff] [blame] | 3114 | deliverNewIntents(r, intents); |
| 3115 | if (resumed) { |
Dake Gu | 67decfa | 2017-12-27 11:48:08 -0800 | [diff] [blame] | 3116 | r.activity.performResume(false); |
Wale Ogunwale | 826c706 | 2016-09-13 08:25:54 -0700 | [diff] [blame] | 3117 | r.activity.mTemporaryPause = false; |
| 3118 | } |
| 3119 | |
| 3120 | if (r.paused && andPause) { |
| 3121 | // In this case the activity was in the paused state when we delivered the intent, |
| 3122 | // to guarantee onResume gets called after onNewIntent we temporarily resume the |
| 3123 | // activity and pause again as the caller wanted. |
| 3124 | performResumeActivity(token, false, "performNewIntents"); |
| 3125 | performPauseActivityIfNeeded(r, "performNewIntents"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3126 | } |
| 3127 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3128 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 3129 | @Override |
| 3130 | public void handleNewIntent(IBinder token, List<ReferrerIntent> intents, boolean andPause) { |
| 3131 | performNewIntents(token, intents, andPause); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3132 | } |
| 3133 | |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 3134 | public void handleRequestAssistContextExtras(RequestAssistContextExtras cmd) { |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 3135 | // Filling for autofill has a few differences: |
Felipe Leme | 1ca634a | 2016-11-28 17:21:21 -0800 | [diff] [blame] | 3136 | // - it does not need an AssistContent |
| 3137 | // - it does not call onProvideAssistData() |
| 3138 | // - it needs an IAutoFillCallback |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 3139 | boolean forAutofill = cmd.requestType == ActivityManager.ASSIST_CONTEXT_AUTOFILL; |
Felipe Leme | 1ca634a | 2016-11-28 17:21:21 -0800 | [diff] [blame] | 3140 | |
Felipe Leme | 85d1c2d | 2017-04-21 08:56:04 -0700 | [diff] [blame] | 3141 | // TODO: decide if lastSessionId logic applies to autofill sessions |
Amith Yamasani | 4f128e4 | 2016-05-10 11:44:12 -0700 | [diff] [blame] | 3142 | if (mLastSessionId != cmd.sessionId) { |
| 3143 | // Clear the existing structures |
| 3144 | mLastSessionId = cmd.sessionId; |
| 3145 | for (int i = mLastAssistStructures.size() - 1; i >= 0; i--) { |
| 3146 | AssistStructure structure = mLastAssistStructures.get(i).get(); |
| 3147 | if (structure != null) { |
| 3148 | structure.clearSendChannel(); |
| 3149 | } |
| 3150 | mLastAssistStructures.remove(i); |
Dianne Hackborn | 782d498 | 2015-07-08 17:36:37 -0700 | [diff] [blame] | 3151 | } |
| 3152 | } |
Felipe Leme | 29a5b0d | 2016-10-25 14:57:11 -0700 | [diff] [blame] | 3153 | |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 3154 | Bundle data = new Bundle(); |
Dianne Hackborn | 09d57fe | 2015-05-27 18:05:52 -0700 | [diff] [blame] | 3155 | AssistStructure structure = null; |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 3156 | AssistContent content = forAutofill ? null : new AssistContent(); |
Amith Yamasani | 858f98d | 2017-02-22 12:59:53 -0800 | [diff] [blame] | 3157 | final long startTime = SystemClock.uptimeMillis(); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 3158 | ActivityClientRecord r = mActivities.get(cmd.activityToken); |
Dianne Hackborn | a3acdb3 | 2015-06-08 17:07:40 -0700 | [diff] [blame] | 3159 | Uri referrer = null; |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 3160 | if (r != null) { |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 3161 | if (!forAutofill) { |
Felipe Leme | 1ca634a | 2016-11-28 17:21:21 -0800 | [diff] [blame] | 3162 | r.activity.getApplication().dispatchOnProvideAssistData(r.activity, data); |
Felipe Leme | 29a5b0d | 2016-10-25 14:57:11 -0700 | [diff] [blame] | 3163 | r.activity.onProvideAssistData(data); |
Felipe Leme | 6d55387 | 2016-12-08 17:13:25 -0800 | [diff] [blame] | 3164 | referrer = r.activity.onProvideReferrer(); |
Felipe Leme | 29a5b0d | 2016-10-25 14:57:11 -0700 | [diff] [blame] | 3165 | } |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 3166 | if (cmd.requestType == ActivityManager.ASSIST_CONTEXT_FULL || forAutofill) { |
Svet Ganov | fd31f85 | 2017-04-26 15:54:27 -0700 | [diff] [blame] | 3167 | structure = new AssistStructure(r.activity, forAutofill, cmd.flags); |
Adam Skory | 4aaed14 | 2015-04-22 11:29:31 -0600 | [diff] [blame] | 3168 | Intent activityIntent = r.activity.getIntent(); |
Felipe Leme | 6d55387 | 2016-12-08 17:13:25 -0800 | [diff] [blame] | 3169 | boolean notSecure = r.window == null || |
Dianne Hackborn | 09d57fe | 2015-05-27 18:05:52 -0700 | [diff] [blame] | 3170 | (r.window.getAttributes().flags |
Felipe Leme | 6d55387 | 2016-12-08 17:13:25 -0800 | [diff] [blame] | 3171 | & WindowManager.LayoutParams.FLAG_SECURE) == 0; |
| 3172 | if (activityIntent != null && notSecure) { |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 3173 | if (!forAutofill) { |
Felipe Leme | 1ca634a | 2016-11-28 17:21:21 -0800 | [diff] [blame] | 3174 | Intent intent = new Intent(activityIntent); |
| 3175 | intent.setFlags(intent.getFlags() & ~(Intent.FLAG_GRANT_WRITE_URI_PERMISSION |
| 3176 | | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION)); |
| 3177 | intent.removeUnsafeExtras(); |
Felipe Leme | 29a5b0d | 2016-10-25 14:57:11 -0700 | [diff] [blame] | 3178 | content.setDefaultIntent(intent); |
| 3179 | } |
Adam Skory | 4aaed14 | 2015-04-22 11:29:31 -0600 | [diff] [blame] | 3180 | } else { |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 3181 | if (!forAutofill) { |
Felipe Leme | 29a5b0d | 2016-10-25 14:57:11 -0700 | [diff] [blame] | 3182 | content.setDefaultIntent(new Intent()); |
| 3183 | } |
Adam Skory | 4aaed14 | 2015-04-22 11:29:31 -0600 | [diff] [blame] | 3184 | } |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 3185 | if (!forAutofill) { |
Felipe Leme | 29a5b0d | 2016-10-25 14:57:11 -0700 | [diff] [blame] | 3186 | r.activity.onProvideAssistContent(content); |
| 3187 | } |
Dianne Hackborn | a83ce1d | 2015-03-11 15:16:13 -0700 | [diff] [blame] | 3188 | } |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 3189 | } |
Dianne Hackborn | 09d57fe | 2015-05-27 18:05:52 -0700 | [diff] [blame] | 3190 | if (structure == null) { |
| 3191 | structure = new AssistStructure(); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 3192 | } |
Felipe Leme | 0200d9e | 2017-01-24 15:10:26 -0800 | [diff] [blame] | 3193 | |
Felipe Leme | 85d1c2d | 2017-04-21 08:56:04 -0700 | [diff] [blame] | 3194 | // TODO: decide if lastSessionId logic applies to autofill sessions |
Amith Yamasani | 858f98d | 2017-02-22 12:59:53 -0800 | [diff] [blame] | 3195 | |
| 3196 | structure.setAcquisitionStartTime(startTime); |
| 3197 | structure.setAcquisitionEndTime(SystemClock.uptimeMillis()); |
| 3198 | |
Amith Yamasani | 4f128e4 | 2016-05-10 11:44:12 -0700 | [diff] [blame] | 3199 | mLastAssistStructures.add(new WeakReference<>(structure)); |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3200 | IActivityManager mgr = ActivityManager.getService(); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 3201 | try { |
Dianne Hackborn | a3acdb3 | 2015-06-08 17:07:40 -0700 | [diff] [blame] | 3202 | mgr.reportAssistContextExtras(cmd.requestToken, data, structure, content, referrer); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 3203 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3204 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 3205 | } |
| 3206 | } |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 3207 | |
| 3208 | public void handleTranslucentConversionComplete(IBinder token, boolean drawComplete) { |
| 3209 | ActivityClientRecord r = mActivities.get(token); |
| 3210 | if (r != null) { |
| 3211 | r.activity.onTranslucentConversionComplete(drawComplete); |
| 3212 | } |
| 3213 | } |
| 3214 | |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 3215 | public void onNewActivityOptions(IBinder token, ActivityOptions options) { |
| 3216 | ActivityClientRecord r = mActivities.get(token); |
| 3217 | if (r != null) { |
| 3218 | r.activity.onNewActivityOptions(options); |
| 3219 | } |
| 3220 | } |
| 3221 | |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 3222 | public void handleInstallProvider(ProviderInfo info) { |
Jeff Sharkey | bb2e2ca | 2014-10-23 11:42:31 -0700 | [diff] [blame] | 3223 | final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); |
| 3224 | try { |
Jeff Sharkey | a6bfeae | 2017-07-05 16:50:24 -0600 | [diff] [blame] | 3225 | installContentProviders(mInitialApplication, Arrays.asList(info)); |
Jeff Sharkey | bb2e2ca | 2014-10-23 11:42:31 -0700 | [diff] [blame] | 3226 | } finally { |
| 3227 | StrictMode.setThreadPolicy(oldPolicy); |
| 3228 | } |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 3229 | } |
| 3230 | |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 3231 | private void handleEnterAnimationComplete(IBinder token) { |
| 3232 | ActivityClientRecord r = mActivities.get(token); |
| 3233 | if (r != null) { |
Filip Gruszczynski | 6eafa90 | 2014-11-14 14:24:37 -0800 | [diff] [blame] | 3234 | r.activity.dispatchEnterAnimationComplete(); |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 3235 | } |
| 3236 | } |
| 3237 | |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 3238 | private void handleStartBinderTracking() { |
| 3239 | Binder.enableTracing(); |
| 3240 | } |
| 3241 | |
| 3242 | private void handleStopBinderTrackingAndDump(ParcelFileDescriptor fd) { |
| 3243 | try { |
| 3244 | Binder.disableTracing(); |
| 3245 | Binder.getTransactionTracker().writeTracesToFile(fd); |
| 3246 | } finally { |
| 3247 | IoUtils.closeQuietly(fd); |
| 3248 | Binder.getTransactionTracker().clearTraces(); |
| 3249 | } |
| 3250 | } |
| 3251 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 3252 | @Override |
| 3253 | public void handleMultiWindowModeChanged(IBinder token, boolean isInMultiWindowMode, |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 3254 | Configuration overrideConfig) { |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 3255 | final ActivityClientRecord r = mActivities.get(token); |
| 3256 | if (r != null) { |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 3257 | final Configuration newConfig = new Configuration(mConfiguration); |
| 3258 | if (overrideConfig != null) { |
| 3259 | newConfig.updateFrom(overrideConfig); |
| 3260 | } |
| 3261 | r.activity.dispatchMultiWindowModeChanged(isInMultiWindowMode, newConfig); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 3262 | } |
| 3263 | } |
| 3264 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 3265 | @Override |
| 3266 | public void handlePictureInPictureModeChanged(IBinder token, boolean isInPipMode, |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 3267 | Configuration overrideConfig) { |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 3268 | final ActivityClientRecord r = mActivities.get(token); |
| 3269 | if (r != null) { |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 3270 | final Configuration newConfig = new Configuration(mConfiguration); |
| 3271 | if (overrideConfig != null) { |
| 3272 | newConfig.updateFrom(overrideConfig); |
| 3273 | } |
| 3274 | r.activity.dispatchPictureInPictureModeChanged(isInPipMode, newConfig); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 3275 | } |
| 3276 | } |
| 3277 | |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 3278 | private void handleLocalVoiceInteractionStarted(IBinder token, IVoiceInteractor interactor) { |
| 3279 | final ActivityClientRecord r = mActivities.get(token); |
| 3280 | if (r != null) { |
| 3281 | r.voiceInteractor = interactor; |
| 3282 | r.activity.setVoiceInteractor(interactor); |
| 3283 | if (interactor == null) { |
| 3284 | r.activity.onLocalVoiceInteractionStopped(); |
| 3285 | } else { |
| 3286 | r.activity.onLocalVoiceInteractionStarted(); |
| 3287 | } |
| 3288 | } |
| 3289 | } |
| 3290 | |
Andreas Gampe | ab8a63b | 2018-01-05 13:55:15 -0800 | [diff] [blame] | 3291 | private static boolean attemptAttachAgent(String agent, ClassLoader classLoader) { |
Leonard Mosescu | f3409ce | 2016-10-06 17:32:05 -0700 | [diff] [blame] | 3292 | try { |
Andreas Gampe | ab8a63b | 2018-01-05 13:55:15 -0800 | [diff] [blame] | 3293 | VMDebug.attachAgent(agent, classLoader); |
| 3294 | return true; |
Leonard Mosescu | f3409ce | 2016-10-06 17:32:05 -0700 | [diff] [blame] | 3295 | } catch (IOException e) { |
Andreas Gampe | ab8a63b | 2018-01-05 13:55:15 -0800 | [diff] [blame] | 3296 | Slog.e(TAG, "Attaching agent with " + classLoader + " failed: " + agent); |
| 3297 | return false; |
| 3298 | } |
| 3299 | } |
| 3300 | |
| 3301 | static void handleAttachAgent(String agent, LoadedApk loadedApk) { |
| 3302 | ClassLoader classLoader = loadedApk != null ? loadedApk.getClassLoader() : null; |
| 3303 | if (attemptAttachAgent(agent, classLoader)) { |
| 3304 | return; |
| 3305 | } |
| 3306 | if (classLoader != null) { |
| 3307 | attemptAttachAgent(agent, null); |
Leonard Mosescu | f3409ce | 2016-10-06 17:32:05 -0700 | [diff] [blame] | 3308 | } |
| 3309 | } |
| 3310 | |
Brad Fitzpatrick | bfb1919 | 2010-10-29 15:25:44 -0700 | [diff] [blame] | 3311 | private static final ThreadLocal<Intent> sCurrentBroadcastIntent = new ThreadLocal<Intent>(); |
| 3312 | |
| 3313 | /** |
| 3314 | * Return the Intent that's currently being handled by a |
| 3315 | * BroadcastReceiver on this thread, or null if none. |
| 3316 | * @hide |
| 3317 | */ |
| 3318 | public static Intent getIntentBeingBroadcast() { |
| 3319 | return sCurrentBroadcastIntent.get(); |
| 3320 | } |
| 3321 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3322 | private void handleReceiver(ReceiverData data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3323 | // If we are getting ready to gc after going to the background, well |
| 3324 | // we are back active so skip it. |
| 3325 | unscheduleGcIdler(); |
| 3326 | |
| 3327 | String component = data.intent.getComponent().getClassName(); |
| 3328 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3329 | LoadedApk packageInfo = getPackageInfoNoCheck( |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 3330 | data.info.applicationInfo, data.compatInfo); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3331 | |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3332 | IActivityManager mgr = ActivityManager.getService(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3333 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 3334 | Application app; |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3335 | BroadcastReceiver receiver; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 3336 | ContextImpl context; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3337 | try { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3338 | app = packageInfo.makeApplication(false, mInstrumentation); |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 3339 | context = (ContextImpl) app.getBaseContext(); |
| 3340 | if (data.info.splitName != null) { |
| 3341 | context = (ContextImpl) context.createContextForSplit(data.info.splitName); |
| 3342 | } |
| 3343 | java.lang.ClassLoader cl = context.getClassLoader(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3344 | data.intent.setExtrasClassLoader(cl); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 3345 | data.intent.prepareToEnterProcess(); |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 3346 | data.setExtrasClassLoader(cl); |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3347 | receiver = packageInfo.getAppFactory() |
Jason Monk | a80bfb5 | 2017-11-16 17:15:37 -0500 | [diff] [blame] | 3348 | .instantiateReceiver(cl, data.info.name, data.intent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3349 | } catch (Exception e) { |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 3350 | if (DEBUG_BROADCAST) Slog.i(TAG, |
| 3351 | "Finishing failed broadcast to " + data.intent.getComponent()); |
| 3352 | data.sendFinished(mgr); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3353 | throw new RuntimeException( |
| 3354 | "Unable to instantiate receiver " + component |
| 3355 | + ": " + e.toString(), e); |
| 3356 | } |
| 3357 | |
| 3358 | try { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3359 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3360 | TAG, "Performing receive of " + data.intent |
| 3361 | + ": app=" + app |
| 3362 | + ", appName=" + app.getPackageName() |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3363 | + ", pkg=" + packageInfo.getPackageName() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3364 | + ", comp=" + data.intent.getComponent().toShortString() |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3365 | + ", dir=" + packageInfo.getAppDir()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3366 | |
Brad Fitzpatrick | bfb1919 | 2010-10-29 15:25:44 -0700 | [diff] [blame] | 3367 | sCurrentBroadcastIntent.set(data.intent); |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 3368 | receiver.setPendingResult(data); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3369 | receiver.onReceive(context.getReceiverRestrictedContext(), |
| 3370 | data.intent); |
| 3371 | } catch (Exception e) { |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 3372 | if (DEBUG_BROADCAST) Slog.i(TAG, |
| 3373 | "Finishing failed broadcast to " + data.intent.getComponent()); |
| 3374 | data.sendFinished(mgr); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3375 | if (!mInstrumentation.onException(receiver, e)) { |
| 3376 | throw new RuntimeException( |
| 3377 | "Unable to start receiver " + component |
| 3378 | + ": " + e.toString(), e); |
| 3379 | } |
Brad Fitzpatrick | bfb1919 | 2010-10-29 15:25:44 -0700 | [diff] [blame] | 3380 | } finally { |
| 3381 | sCurrentBroadcastIntent.set(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3382 | } |
| 3383 | |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 3384 | if (receiver.getPendingResult() != null) { |
| 3385 | data.finish(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3386 | } |
| 3387 | } |
| 3388 | |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3389 | // Instantiate a BackupAgent and tell it that it's alive |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3390 | private void handleCreateBackupAgent(CreateBackupAgentData data) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3391 | if (DEBUG_BACKUP) Slog.v(TAG, "handleCreateBackupAgent: " + data); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3392 | |
Christopher Tate | 346acb1 | 2012-10-15 19:20:25 -0700 | [diff] [blame] | 3393 | // Sanity check the requested target package's uid against ours |
| 3394 | try { |
| 3395 | PackageInfo requestedPackage = getPackageManager().getPackageInfo( |
| 3396 | data.appInfo.packageName, 0, UserHandle.myUserId()); |
| 3397 | if (requestedPackage.applicationInfo.uid != Process.myUid()) { |
| 3398 | Slog.w(TAG, "Asked to instantiate non-matching package " |
| 3399 | + data.appInfo.packageName); |
| 3400 | return; |
| 3401 | } |
| 3402 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3403 | throw e.rethrowFromSystemServer(); |
Christopher Tate | 346acb1 | 2012-10-15 19:20:25 -0700 | [diff] [blame] | 3404 | } |
| 3405 | |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3406 | // no longer idle; we have backup work to do |
| 3407 | unscheduleGcIdler(); |
| 3408 | |
| 3409 | // instantiate the BackupAgent class named in the manifest |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3410 | LoadedApk packageInfo = getPackageInfoNoCheck(data.appInfo, data.compatInfo); |
| 3411 | String packageName = packageInfo.mPackageName; |
Christopher Tate | 346acb1 | 2012-10-15 19:20:25 -0700 | [diff] [blame] | 3412 | if (packageName == null) { |
| 3413 | Slog.d(TAG, "Asked to create backup agent for nonexistent package"); |
| 3414 | return; |
| 3415 | } |
| 3416 | |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3417 | String classname = data.appInfo.backupAgentName; |
Christopher Tate | 79ec80d | 2011-06-24 14:58:49 -0700 | [diff] [blame] | 3418 | // full backup operation but no app-supplied agent? use the default implementation |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 3419 | if (classname == null && (data.backupMode == ApplicationThreadConstants.BACKUP_MODE_FULL |
| 3420 | || data.backupMode == ApplicationThreadConstants.BACKUP_MODE_RESTORE_FULL)) { |
Christopher Tate | 4a627c7 | 2011-04-01 14:43:32 -0700 | [diff] [blame] | 3421 | classname = "android.app.backup.FullBackupAgent"; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3422 | } |
Christopher Tate | 4a627c7 | 2011-04-01 14:43:32 -0700 | [diff] [blame] | 3423 | |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3424 | try { |
Christopher Tate | d1475e0 | 2009-07-09 15:36:17 -0700 | [diff] [blame] | 3425 | IBinder binder = null; |
Christopher Tate | 2e40d11 | 2014-07-15 12:37:38 -0700 | [diff] [blame] | 3426 | BackupAgent agent = mBackupAgents.get(packageName); |
| 3427 | if (agent != null) { |
| 3428 | // reusing the existing instance |
| 3429 | if (DEBUG_BACKUP) { |
| 3430 | Slog.v(TAG, "Reusing existing agent instance"); |
Christopher Tate | d1475e0 | 2009-07-09 15:36:17 -0700 | [diff] [blame] | 3431 | } |
Christopher Tate | 2e40d11 | 2014-07-15 12:37:38 -0700 | [diff] [blame] | 3432 | binder = agent.onBind(); |
| 3433 | } else { |
| 3434 | try { |
| 3435 | if (DEBUG_BACKUP) Slog.v(TAG, "Initializing agent class " + classname); |
| 3436 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3437 | java.lang.ClassLoader cl = packageInfo.getClassLoader(); |
Dan Sandler | 07fe63e | 2017-08-15 16:41:11 -0400 | [diff] [blame] | 3438 | agent = (BackupAgent) cl.loadClass(classname).newInstance(); |
Christopher Tate | 2e40d11 | 2014-07-15 12:37:38 -0700 | [diff] [blame] | 3439 | |
| 3440 | // set up the agent's context |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3441 | ContextImpl context = ContextImpl.createAppContext(this, packageInfo); |
Christopher Tate | 2e40d11 | 2014-07-15 12:37:38 -0700 | [diff] [blame] | 3442 | context.setOuterContext(agent); |
| 3443 | agent.attach(context); |
| 3444 | |
| 3445 | agent.onCreate(); |
| 3446 | binder = agent.onBind(); |
| 3447 | mBackupAgents.put(packageName, agent); |
| 3448 | } catch (Exception e) { |
| 3449 | // If this is during restore, fail silently; otherwise go |
| 3450 | // ahead and let the user see the crash. |
| 3451 | Slog.e(TAG, "Agent threw during creation: " + e); |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 3452 | if (data.backupMode != ApplicationThreadConstants.BACKUP_MODE_RESTORE |
| 3453 | && data.backupMode != |
| 3454 | ApplicationThreadConstants.BACKUP_MODE_RESTORE_FULL) { |
Christopher Tate | 2e40d11 | 2014-07-15 12:37:38 -0700 | [diff] [blame] | 3455 | throw e; |
| 3456 | } |
| 3457 | // falling through with 'binder' still null |
| 3458 | } |
Christopher Tate | d1475e0 | 2009-07-09 15:36:17 -0700 | [diff] [blame] | 3459 | } |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3460 | |
| 3461 | // tell the OS that we're live now |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3462 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3463 | ActivityManager.getService().backupAgentCreated(packageName, binder); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3464 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3465 | throw e.rethrowFromSystemServer(); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3466 | } |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3467 | } catch (Exception e) { |
| 3468 | throw new RuntimeException("Unable to create BackupAgent " |
Christopher Tate | 4a627c7 | 2011-04-01 14:43:32 -0700 | [diff] [blame] | 3469 | + classname + ": " + e.toString(), e); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3470 | } |
| 3471 | } |
| 3472 | |
| 3473 | // Tear down a BackupAgent |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3474 | private void handleDestroyBackupAgent(CreateBackupAgentData data) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3475 | if (DEBUG_BACKUP) Slog.v(TAG, "handleDestroyBackupAgent: " + data); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3476 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3477 | LoadedApk packageInfo = getPackageInfoNoCheck(data.appInfo, data.compatInfo); |
| 3478 | String packageName = packageInfo.mPackageName; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3479 | BackupAgent agent = mBackupAgents.get(packageName); |
| 3480 | if (agent != null) { |
| 3481 | try { |
| 3482 | agent.onDestroy(); |
| 3483 | } catch (Exception e) { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 3484 | 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] | 3485 | e.printStackTrace(); |
| 3486 | } |
| 3487 | mBackupAgents.remove(packageName); |
| 3488 | } else { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 3489 | Slog.w(TAG, "Attempt to destroy unknown backup agent " + data); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3490 | } |
| 3491 | } |
| 3492 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3493 | private void handleCreateService(CreateServiceData data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3494 | // If we are getting ready to gc after going to the background, well |
| 3495 | // we are back active so skip it. |
| 3496 | unscheduleGcIdler(); |
| 3497 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3498 | LoadedApk packageInfo = getPackageInfoNoCheck( |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 3499 | data.info.applicationInfo, data.compatInfo); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3500 | Service service = null; |
| 3501 | try { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3502 | java.lang.ClassLoader cl = packageInfo.getClassLoader(); |
| 3503 | service = packageInfo.getAppFactory() |
Jason Monk | a80bfb5 | 2017-11-16 17:15:37 -0500 | [diff] [blame] | 3504 | .instantiateService(cl, data.info.name, data.intent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3505 | } catch (Exception e) { |
| 3506 | if (!mInstrumentation.onException(service, e)) { |
| 3507 | throw new RuntimeException( |
| 3508 | "Unable to instantiate service " + data.info.name |
| 3509 | + ": " + e.toString(), e); |
| 3510 | } |
| 3511 | } |
| 3512 | |
| 3513 | try { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3514 | 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] | 3515 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3516 | ContextImpl context = ContextImpl.createAppContext(this, packageInfo); |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 3517 | context.setOuterContext(service); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3518 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3519 | Application app = packageInfo.makeApplication(false, mInstrumentation); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3520 | service.attach(context, this, data.info.name, data.token, app, |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3521 | ActivityManager.getService()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3522 | service.onCreate(); |
| 3523 | mServices.put(data.token, service); |
| 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 | data.token, SERVICE_DONE_EXECUTING_ANON, 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(service, e)) { |
| 3532 | throw new RuntimeException( |
| 3533 | "Unable to create service " + data.info.name |
| 3534 | + ": " + e.toString(), e); |
| 3535 | } |
| 3536 | } |
| 3537 | } |
| 3538 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3539 | private void handleBindService(BindServiceData data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3540 | Service s = mServices.get(data.token); |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 3541 | if (DEBUG_SERVICE) |
| 3542 | Slog.v(TAG, "handleBindService s=" + s + " rebind=" + data.rebind); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3543 | if (s != null) { |
| 3544 | try { |
| 3545 | data.intent.setExtrasClassLoader(s.getClassLoader()); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 3546 | data.intent.prepareToEnterProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3547 | try { |
| 3548 | if (!data.rebind) { |
| 3549 | IBinder binder = s.onBind(data.intent); |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3550 | ActivityManager.getService().publishService( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3551 | data.token, data.intent, binder); |
| 3552 | } else { |
| 3553 | s.onRebind(data.intent); |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3554 | ActivityManager.getService().serviceDoneExecuting( |
Dianne Hackborn | 455625e | 2015-01-21 09:55:13 -0800 | [diff] [blame] | 3555 | data.token, SERVICE_DONE_EXECUTING_ANON, 0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3556 | } |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 3557 | ensureJitEnabled(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3558 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3559 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3560 | } |
| 3561 | } catch (Exception e) { |
| 3562 | if (!mInstrumentation.onException(s, e)) { |
| 3563 | throw new RuntimeException( |
| 3564 | "Unable to bind to service " + s |
| 3565 | + " with " + data.intent + ": " + e.toString(), e); |
| 3566 | } |
| 3567 | } |
| 3568 | } |
| 3569 | } |
| 3570 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3571 | private void handleUnbindService(BindServiceData data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3572 | Service s = mServices.get(data.token); |
| 3573 | if (s != null) { |
| 3574 | try { |
| 3575 | data.intent.setExtrasClassLoader(s.getClassLoader()); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 3576 | data.intent.prepareToEnterProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3577 | boolean doRebind = s.onUnbind(data.intent); |
| 3578 | try { |
| 3579 | if (doRebind) { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3580 | ActivityManager.getService().unbindFinished( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3581 | data.token, data.intent, doRebind); |
| 3582 | } else { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3583 | ActivityManager.getService().serviceDoneExecuting( |
Dianne Hackborn | 455625e | 2015-01-21 09:55:13 -0800 | [diff] [blame] | 3584 | data.token, SERVICE_DONE_EXECUTING_ANON, 0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3585 | } |
| 3586 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3587 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3588 | } |
| 3589 | } catch (Exception e) { |
| 3590 | if (!mInstrumentation.onException(s, e)) { |
| 3591 | throw new RuntimeException( |
| 3592 | "Unable to unbind to service " + s |
| 3593 | + " with " + data.intent + ": " + e.toString(), e); |
| 3594 | } |
| 3595 | } |
| 3596 | } |
| 3597 | } |
| 3598 | |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 3599 | private void handleDumpService(DumpComponentInfo info) { |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3600 | final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); |
| 3601 | try { |
| 3602 | Service s = mServices.get(info.token); |
| 3603 | if (s != null) { |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 3604 | PrintWriter pw = new FastPrintWriter(new FileOutputStream( |
| 3605 | info.fd.getFileDescriptor())); |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3606 | s.dump(info.fd.getFileDescriptor(), pw, info.args); |
| 3607 | pw.flush(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3608 | } |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3609 | } finally { |
| 3610 | IoUtils.closeQuietly(info.fd); |
| 3611 | StrictMode.setThreadPolicy(oldPolicy); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3612 | } |
| 3613 | } |
| 3614 | |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 3615 | private void handleDumpActivity(DumpComponentInfo info) { |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3616 | final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); |
| 3617 | try { |
| 3618 | ActivityClientRecord r = mActivities.get(info.token); |
| 3619 | if (r != null && r.activity != null) { |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 3620 | PrintWriter pw = new FastPrintWriter(new FileOutputStream( |
| 3621 | info.fd.getFileDescriptor())); |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3622 | r.activity.dump(info.prefix, info.fd.getFileDescriptor(), pw, info.args); |
| 3623 | pw.flush(); |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 3624 | } |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3625 | } finally { |
| 3626 | IoUtils.closeQuietly(info.fd); |
| 3627 | StrictMode.setThreadPolicy(oldPolicy); |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 3628 | } |
| 3629 | } |
| 3630 | |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 3631 | private void handleDumpProvider(DumpComponentInfo info) { |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3632 | final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); |
| 3633 | try { |
| 3634 | ProviderClientRecord r = mLocalProviders.get(info.token); |
| 3635 | if (r != null && r.mLocalProvider != null) { |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 3636 | PrintWriter pw = new FastPrintWriter(new FileOutputStream( |
| 3637 | info.fd.getFileDescriptor())); |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3638 | r.mLocalProvider.dump(info.fd.getFileDescriptor(), pw, info.args); |
| 3639 | pw.flush(); |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 3640 | } |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3641 | } finally { |
| 3642 | IoUtils.closeQuietly(info.fd); |
| 3643 | StrictMode.setThreadPolicy(oldPolicy); |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 3644 | } |
| 3645 | } |
| 3646 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3647 | private void handleServiceArgs(ServiceArgsData data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3648 | Service s = mServices.get(data.token); |
| 3649 | if (s != null) { |
| 3650 | try { |
| 3651 | if (data.args != null) { |
| 3652 | data.args.setExtrasClassLoader(s.getClassLoader()); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 3653 | data.args.prepareToEnterProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3654 | } |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 3655 | int res; |
| 3656 | if (!data.taskRemoved) { |
| 3657 | res = s.onStartCommand(data.args, data.flags, data.startId); |
| 3658 | } else { |
| 3659 | s.onTaskRemoved(data.args); |
| 3660 | res = Service.START_TASK_REMOVED_COMPLETE; |
| 3661 | } |
Brad Fitzpatrick | 333b8cb | 2010-08-26 12:04:57 -0700 | [diff] [blame] | 3662 | |
| 3663 | QueuedWork.waitToFinish(); |
| 3664 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3665 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3666 | ActivityManager.getService().serviceDoneExecuting( |
Dianne Hackborn | 455625e | 2015-01-21 09:55:13 -0800 | [diff] [blame] | 3667 | data.token, SERVICE_DONE_EXECUTING_START, data.startId, res); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3668 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3669 | throw e.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3670 | } |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 3671 | ensureJitEnabled(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3672 | } catch (Exception e) { |
| 3673 | if (!mInstrumentation.onException(s, e)) { |
| 3674 | throw new RuntimeException( |
| 3675 | "Unable to start service " + s |
| 3676 | + " with " + data.args + ": " + e.toString(), e); |
| 3677 | } |
| 3678 | } |
| 3679 | } |
| 3680 | } |
| 3681 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3682 | private void handleStopService(IBinder token) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3683 | Service s = mServices.remove(token); |
| 3684 | if (s != null) { |
| 3685 | try { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3686 | if (localLOGV) Slog.v(TAG, "Destroying service " + s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3687 | s.onDestroy(); |
Amith Yamasani | 7592825 | 2017-05-22 15:10:47 -0700 | [diff] [blame] | 3688 | s.detachAndCleanUp(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3689 | Context context = s.getBaseContext(); |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 3690 | if (context instanceof ContextImpl) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3691 | final String who = s.getClassName(); |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 3692 | ((ContextImpl) context).scheduleFinalCleanup(who, "Service"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3693 | } |
Brad Fitzpatrick | 333b8cb | 2010-08-26 12:04:57 -0700 | [diff] [blame] | 3694 | |
| 3695 | QueuedWork.waitToFinish(); |
| 3696 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3697 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3698 | ActivityManager.getService().serviceDoneExecuting( |
Dianne Hackborn | 455625e | 2015-01-21 09:55:13 -0800 | [diff] [blame] | 3699 | token, SERVICE_DONE_EXECUTING_STOP, 0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3700 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3701 | throw e.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3702 | } |
| 3703 | } catch (Exception e) { |
| 3704 | if (!mInstrumentation.onException(s, e)) { |
| 3705 | throw new RuntimeException( |
| 3706 | "Unable to stop service " + s |
| 3707 | + ": " + e.toString(), e); |
| 3708 | } |
Craig Mautner | 66c4a82 | 2015-01-16 12:48:16 -0800 | [diff] [blame] | 3709 | Slog.i(TAG, "handleStopService: exception for " + token, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3710 | } |
Craig Mautner | 9776ad4 | 2015-01-15 14:38:39 -0800 | [diff] [blame] | 3711 | } else { |
| 3712 | Slog.i(TAG, "handleStopService: token=" + token + " not found."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3713 | } |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3714 | //Slog.i(TAG, "Running services: " + mServices); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3715 | } |
| 3716 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 3717 | ActivityClientRecord performResumeActivity(IBinder token, boolean clearHide, String reason) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3718 | ActivityClientRecord r = mActivities.get(token); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3719 | if (localLOGV) Slog.v(TAG, "Performing resume of " + r |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3720 | + " finished=" + r.activity.mFinished); |
| 3721 | if (r != null && !r.activity.mFinished) { |
| 3722 | if (clearHide) { |
| 3723 | r.hideForNow = false; |
| 3724 | r.activity.mStartedActivity = false; |
| 3725 | } |
| 3726 | try { |
Dianne Hackborn | 6bdd3a1 | 2015-08-05 15:01:28 -0700 | [diff] [blame] | 3727 | r.activity.onStateNotSaved(); |
Dianne Hackborn | 689586d | 2012-10-01 18:23:04 -0700 | [diff] [blame] | 3728 | r.activity.mFragments.noteStateNotSaved(); |
Sudheer Shanka | 43b5ea4 | 2017-06-21 11:24:53 -0700 | [diff] [blame] | 3729 | checkAndBlockForNetworkAccess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3730 | if (r.pendingIntents != null) { |
| 3731 | deliverNewIntents(r, r.pendingIntents); |
| 3732 | r.pendingIntents = null; |
| 3733 | } |
| 3734 | if (r.pendingResults != null) { |
| 3735 | deliverResults(r, r.pendingResults); |
| 3736 | r.pendingResults = null; |
| 3737 | } |
Dake Gu | 67decfa | 2017-12-27 11:48:08 -0800 | [diff] [blame] | 3738 | r.activity.performResume(r.startsNotResumed); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3739 | |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 3740 | EventLog.writeEvent(LOG_AM_ON_RESUME_CALLED, UserHandle.myUserId(), |
| 3741 | r.activity.getComponentName().getClassName(), reason); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3742 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3743 | r.state = null; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3744 | r.persistentState = null; |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 3745 | r.setState(ON_RESUME); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3746 | } catch (Exception e) { |
| 3747 | if (!mInstrumentation.onException(r.activity, e)) { |
| 3748 | throw new RuntimeException( |
| 3749 | "Unable to resume activity " |
| 3750 | + r.intent.getComponent().toShortString() |
| 3751 | + ": " + e.toString(), e); |
| 3752 | } |
| 3753 | } |
| 3754 | } |
| 3755 | return r; |
| 3756 | } |
| 3757 | |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 3758 | static final void cleanUpPendingRemoveWindows(ActivityClientRecord r, boolean force) { |
| 3759 | if (r.mPreserveWindow && !force) { |
| 3760 | return; |
| 3761 | } |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 3762 | if (r.mPendingRemoveWindow != null) { |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 3763 | r.mPendingRemoveWindowManager.removeViewImmediate( |
| 3764 | r.mPendingRemoveWindow.getDecorView()); |
| 3765 | IBinder wtoken = r.mPendingRemoveWindow.getDecorView().getWindowToken(); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 3766 | if (wtoken != null) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 3767 | WindowManagerGlobal.getInstance().closeAll(wtoken, |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 3768 | r.activity.getClass().getName(), "Activity"); |
| 3769 | } |
| 3770 | } |
| 3771 | r.mPendingRemoveWindow = null; |
| 3772 | r.mPendingRemoveWindowManager = null; |
| 3773 | } |
| 3774 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 3775 | @Override |
| 3776 | public void handleResumeActivity(IBinder token, boolean clearHide, boolean isForward, |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 3777 | String reason) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3778 | // If we are getting ready to gc after going to the background, well |
| 3779 | // we are back active so skip it. |
| 3780 | unscheduleGcIdler(); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3781 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3782 | |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 3783 | // TODO Push resumeArgs into the activity for consideration |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 3784 | final ActivityClientRecord r = performResumeActivity(token, clearHide, reason); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3785 | |
| 3786 | if (r != null) { |
| 3787 | final Activity a = r.activity; |
| 3788 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3789 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3790 | TAG, "Resume " + r + " started activity: " + |
| 3791 | a.mStartedActivity + ", hideForNow: " + r.hideForNow |
| 3792 | + ", finished: " + a.mFinished); |
| 3793 | |
| 3794 | final int forwardBit = isForward ? |
| 3795 | WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION : 0; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3796 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3797 | // If the window hasn't yet been added to the window manager, |
| 3798 | // and this guy didn't finish itself or start another activity, |
| 3799 | // then go ahead and add the window. |
Dianne Hackborn | 061d58a | 2010-03-12 15:07:06 -0800 | [diff] [blame] | 3800 | boolean willBeVisible = !a.mStartedActivity; |
| 3801 | if (!willBeVisible) { |
| 3802 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3803 | willBeVisible = ActivityManager.getService().willActivityBeVisible( |
Dianne Hackborn | 061d58a | 2010-03-12 15:07:06 -0800 | [diff] [blame] | 3804 | a.getActivityToken()); |
| 3805 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3806 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 061d58a | 2010-03-12 15:07:06 -0800 | [diff] [blame] | 3807 | } |
| 3808 | } |
| 3809 | if (r.window == null && !a.mFinished && willBeVisible) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3810 | r.window = r.activity.getWindow(); |
| 3811 | View decor = r.window.getDecorView(); |
| 3812 | decor.setVisibility(View.INVISIBLE); |
| 3813 | ViewManager wm = a.getWindowManager(); |
| 3814 | WindowManager.LayoutParams l = r.window.getAttributes(); |
| 3815 | a.mDecor = decor; |
| 3816 | l.type = WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
| 3817 | l.softInputMode |= forwardBit; |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 3818 | if (r.mPreserveWindow) { |
| 3819 | a.mWindowAdded = true; |
| 3820 | r.mPreserveWindow = false; |
Robert Carr | b259485 | 2016-04-25 16:21:13 -0700 | [diff] [blame] | 3821 | // Normally the ViewRoot sets up callbacks with the Activity |
| 3822 | // in addView->ViewRootImpl#setView. If we are instead reusing |
| 3823 | // the decor view we have to notify the view root that the |
| 3824 | // callbacks may have changed. |
| 3825 | ViewRootImpl impl = decor.getViewRootImpl(); |
Robert Carr | 311ecba | 2016-04-27 12:59:45 -0700 | [diff] [blame] | 3826 | if (impl != null) { |
| 3827 | impl.notifyChildRebuilt(); |
| 3828 | } |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 3829 | } |
Bryce Lee | 4b51b32 | 2017-04-07 10:27:19 -0700 | [diff] [blame] | 3830 | if (a.mVisibleFromClient) { |
| 3831 | if (!a.mWindowAdded) { |
| 3832 | a.mWindowAdded = true; |
| 3833 | wm.addView(decor, l); |
| 3834 | } else { |
| 3835 | // The activity will get a callback for this {@link LayoutParams} change |
| 3836 | // earlier. However, at that time the decor will not be set (this is set |
| 3837 | // in this method), so no action will be taken. This call ensures the |
| 3838 | // callback occurs with the decor set. |
| 3839 | a.onWindowAttributesChanged(l); |
| 3840 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3841 | } |
| 3842 | |
| 3843 | // If the window has already been added, but during resume |
| 3844 | // we started another activity, then don't yet make the |
Dianne Hackborn | 061d58a | 2010-03-12 15:07:06 -0800 | [diff] [blame] | 3845 | // window visible. |
| 3846 | } else if (!willBeVisible) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3847 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3848 | TAG, "Launch " + r + " mStartedActivity set"); |
| 3849 | r.hideForNow = true; |
| 3850 | } |
| 3851 | |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 3852 | // Get rid of anything left hanging around. |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 3853 | cleanUpPendingRemoveWindows(r, false /* force */); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 3854 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3855 | // The window is now visible if it has been added, we are not |
| 3856 | // simply finishing, and we are not starting another activity. |
Dianne Hackborn | 061d58a | 2010-03-12 15:07:06 -0800 | [diff] [blame] | 3857 | if (!r.activity.mFinished && willBeVisible |
Dianne Hackborn | c1e605e | 2009-09-25 17:18:15 -0700 | [diff] [blame] | 3858 | && r.activity.mDecor != null && !r.hideForNow) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3859 | if (r.newConfig != null) { |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 3860 | performConfigurationChangedForActivity(r, r.newConfig); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3861 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Resuming activity " |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 3862 | + r.activityInfo.name + " with newConfig " + r.activity.mCurrentConfig); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3863 | r.newConfig = null; |
| 3864 | } |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3865 | if (localLOGV) Slog.v(TAG, "Resuming " + r + " with isForward=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3866 | + isForward); |
| 3867 | WindowManager.LayoutParams l = r.window.getAttributes(); |
| 3868 | if ((l.softInputMode |
| 3869 | & WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) |
| 3870 | != forwardBit) { |
| 3871 | l.softInputMode = (l.softInputMode |
| 3872 | & (~WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION)) |
| 3873 | | forwardBit; |
Dianne Hackborn | c1e605e | 2009-09-25 17:18:15 -0700 | [diff] [blame] | 3874 | if (r.activity.mVisibleFromClient) { |
| 3875 | ViewManager wm = a.getWindowManager(); |
| 3876 | View decor = r.window.getDecorView(); |
| 3877 | wm.updateViewLayout(decor, l); |
| 3878 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3879 | } |
Bryce Lee | 4b51b32 | 2017-04-07 10:27:19 -0700 | [diff] [blame] | 3880 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3881 | r.activity.mVisibleFromServer = true; |
| 3882 | mNumVisibleActivities++; |
| 3883 | if (r.activity.mVisibleFromClient) { |
| 3884 | r.activity.makeVisible(); |
| 3885 | } |
| 3886 | } |
| 3887 | |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 3888 | r.nextIdle = mNewActivities; |
| 3889 | mNewActivities = r; |
| 3890 | if (localLOGV) { |
| 3891 | Slog.v(TAG, "Scheduling idle handler for " + r); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 3892 | } |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 3893 | Looper.myQueue().addIdleHandler(new Idler()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3894 | } else { |
| 3895 | // If an exception was thrown when trying to resume, then |
| 3896 | // just end this activity. |
| 3897 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3898 | ActivityManager.getService() |
Wale Ogunwale | ba7881c | 2015-08-01 19:28:29 -0700 | [diff] [blame] | 3899 | .finishActivity(token, Activity.RESULT_CANCELED, null, |
| 3900 | Activity.DONT_FINISH_TASK_WITH_ACTIVITY); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3901 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3902 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3903 | } |
| 3904 | } |
| 3905 | } |
| 3906 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 3907 | @Override |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 3908 | public void handlePauseActivity(IBinder token, boolean finished, boolean userLeaving, |
| 3909 | int configChanges, boolean dontReport, PendingTransactionActions pendingActions) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3910 | ActivityClientRecord r = mActivities.get(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3911 | if (r != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3912 | if (userLeaving) { |
| 3913 | performUserLeavingActivity(r); |
| 3914 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3915 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3916 | r.activity.mConfigChangeFlags |= configChanges; |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 3917 | performPauseActivity(r, finished, "handlePauseActivity", pendingActions); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3918 | |
Dianne Hackborn | aa93bcd | 2010-10-27 13:57:00 -0700 | [diff] [blame] | 3919 | // Make sure any pending writes are now committed. |
Dianne Hackborn | 5d9d03a | 2011-01-24 13:15:09 -0800 | [diff] [blame] | 3920 | if (r.isPreHoneycomb()) { |
| 3921 | QueuedWork.waitToFinish(); |
| 3922 | } |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 3923 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3924 | // Tell the activity manager we have paused. |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 3925 | if (!dontReport) { |
| 3926 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3927 | ActivityManager.getService().activityPaused(token); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 3928 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3929 | throw ex.rethrowFromSystemServer(); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 3930 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3931 | } |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3932 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3933 | } |
| 3934 | } |
| 3935 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3936 | final void performUserLeavingActivity(ActivityClientRecord r) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3937 | mInstrumentation.callActivityOnUserLeaving(r.activity); |
| 3938 | } |
| 3939 | |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 3940 | final Bundle performPauseActivity(IBinder token, boolean finished, String reason, |
| 3941 | PendingTransactionActions pendingActions) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3942 | ActivityClientRecord r = mActivities.get(token); |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 3943 | return r != null ? performPauseActivity(r, finished, reason, pendingActions) : null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3944 | } |
| 3945 | |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 3946 | /** |
| 3947 | * Pause the activity. |
| 3948 | * @return Saved instance state for pre-Honeycomb apps if it was saved, {@code null} otherwise. |
| 3949 | */ |
| 3950 | private Bundle performPauseActivity(ActivityClientRecord r, boolean finished, String reason, |
| 3951 | PendingTransactionActions pendingActions) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3952 | if (r.paused) { |
| 3953 | if (r.activity.mFinished) { |
| 3954 | // If we are finishing, we won't call onResume() in certain cases. |
| 3955 | // So here we likewise don't want to call onPause() if the activity |
| 3956 | // isn't resumed. |
| 3957 | return null; |
| 3958 | } |
| 3959 | RuntimeException e = new RuntimeException( |
| 3960 | "Performing pause of activity that is not resumed: " |
| 3961 | + r.intent.getComponent().toShortString()); |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 3962 | Slog.e(TAG, e.getMessage(), e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3963 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3964 | if (finished) { |
| 3965 | r.activity.mFinished = true; |
| 3966 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3967 | |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 3968 | // Pre-Honeycomb apps always save their state before pausing |
| 3969 | final boolean shouldSaveState = !r.activity.mFinished && r.isPreHoneycomb(); |
| 3970 | if (shouldSaveState) { |
| 3971 | callActivityOnSaveInstanceState(r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3972 | } |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 3973 | |
| 3974 | performPauseActivityIfNeeded(r, reason); |
Jeff Hamilton | 52d3203 | 2011-01-08 15:31:26 -0600 | [diff] [blame] | 3975 | |
| 3976 | // Notify any outstanding on paused listeners |
| 3977 | ArrayList<OnActivityPausedListener> listeners; |
| 3978 | synchronized (mOnPauseListeners) { |
| 3979 | listeners = mOnPauseListeners.remove(r.activity); |
| 3980 | } |
| 3981 | int size = (listeners != null ? listeners.size() : 0); |
| 3982 | for (int i = 0; i < size; i++) { |
| 3983 | listeners.get(i).onPaused(r.activity); |
| 3984 | } |
| 3985 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 3986 | final Bundle oldState = pendingActions != null ? pendingActions.getOldState() : null; |
| 3987 | if (oldState != null) { |
| 3988 | // We need to keep around the original state, in case we need to be created again. |
| 3989 | // But we only do this for pre-Honeycomb apps, which always save their state when |
| 3990 | // pausing, so we can not have them save their state when restarting from a paused |
| 3991 | // state. For HC and later, we want to (and can) let the state be saved as the |
| 3992 | // normal part of stopping the activity. |
| 3993 | if (r.isPreHoneycomb()) { |
| 3994 | r.state = oldState; |
| 3995 | } |
| 3996 | } |
| 3997 | |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 3998 | return shouldSaveState ? r.state : null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3999 | } |
| 4000 | |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 4001 | private void performPauseActivityIfNeeded(ActivityClientRecord r, String reason) { |
| 4002 | if (r.paused) { |
| 4003 | // You are already paused silly... |
| 4004 | return; |
| 4005 | } |
| 4006 | |
| 4007 | try { |
| 4008 | r.activity.mCalled = false; |
| 4009 | mInstrumentation.callActivityOnPause(r.activity); |
| 4010 | EventLog.writeEvent(LOG_AM_ON_PAUSE_CALLED, UserHandle.myUserId(), |
| 4011 | r.activity.getComponentName().getClassName(), reason); |
| 4012 | if (!r.activity.mCalled) { |
| 4013 | throw new SuperNotCalledException("Activity " + safeToComponentShortString(r.intent) |
| 4014 | + " did not call through to super.onPause()"); |
| 4015 | } |
| 4016 | } catch (SuperNotCalledException e) { |
| 4017 | throw e; |
| 4018 | } catch (Exception e) { |
| 4019 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4020 | throw new RuntimeException("Unable to pause activity " |
| 4021 | + safeToComponentShortString(r.intent) + ": " + e.toString(), e); |
| 4022 | } |
| 4023 | } |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4024 | r.setState(ON_PAUSE); |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 4025 | } |
| 4026 | |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 4027 | final void performStopActivity(IBinder token, boolean saveState, String reason) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4028 | ActivityClientRecord r = mActivities.get(token); |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 4029 | performStopActivityInner(r, null, false, saveState, reason); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4030 | } |
| 4031 | |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 4032 | private static final class ProviderRefCount { |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 4033 | public final ContentProviderHolder holder; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 4034 | public final ProviderClientRecord client; |
| 4035 | public int stableCount; |
| 4036 | public int unstableCount; |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 4037 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 4038 | // When this is set, the stable and unstable ref counts are 0 and |
| 4039 | // we have a pending operation scheduled to remove the ref count |
| 4040 | // from the activity manager. On the activity manager we are still |
| 4041 | // holding an unstable ref, though it is not reflected in the counts |
| 4042 | // here. |
| 4043 | public boolean removePending; |
| 4044 | |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 4045 | ProviderRefCount(ContentProviderHolder inHolder, |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 4046 | ProviderClientRecord inClient, int sCount, int uCount) { |
| 4047 | holder = inHolder; |
| 4048 | client = inClient; |
| 4049 | stableCount = sCount; |
| 4050 | unstableCount = uCount; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4051 | } |
| 4052 | } |
| 4053 | |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4054 | /** |
| 4055 | * Core implementation of stopping an activity. Note this is a little |
| 4056 | * tricky because the server's meaning of stop is slightly different |
| 4057 | * than our client -- for the server, stop means to save state and give |
| 4058 | * it the result when it is done, but the window may still be visible. |
| 4059 | * For the client, we want to call onStop()/onStart() to indicate when |
Wale Ogunwale | b5066fe | 2016-09-21 07:33:43 -0700 | [diff] [blame] | 4060 | * the activity's UI visibility changes. |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4061 | */ |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4062 | private void performStopActivityInner(ActivityClientRecord r, StopInfo info, boolean keepShown, |
| 4063 | boolean saveState, String reason) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4064 | if (localLOGV) Slog.v(TAG, "Performing stop of " + r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4065 | if (r != null) { |
| 4066 | if (!keepShown && r.stopped) { |
| 4067 | if (r.activity.mFinished) { |
| 4068 | // If we are finishing, we won't call onResume() in certain |
| 4069 | // cases. So here we likewise don't want to call onStop() |
| 4070 | // if the activity isn't resumed. |
| 4071 | return; |
| 4072 | } |
| 4073 | RuntimeException e = new RuntimeException( |
Andrii Kulian | 58178f2 | 2016-03-16 13:44:56 -0700 | [diff] [blame] | 4074 | "Performing stop of activity that is already stopped: " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4075 | + r.intent.getComponent().toShortString()); |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 4076 | Slog.e(TAG, e.getMessage(), e); |
Andrii Kulian | 58178f2 | 2016-03-16 13:44:56 -0700 | [diff] [blame] | 4077 | Slog.e(TAG, r.getStateString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4078 | } |
| 4079 | |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 4080 | // One must first be paused before stopped... |
| 4081 | performPauseActivityIfNeeded(r, reason); |
| 4082 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4083 | if (info != null) { |
| 4084 | try { |
| 4085 | // First create a thumbnail for the activity... |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4086 | // For now, don't create the thumbnail here; we are |
| 4087 | // doing that by doing a screen snapshot. |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4088 | info.setDescription(r.activity.onCreateDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4089 | } catch (Exception e) { |
| 4090 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4091 | throw new RuntimeException( |
| 4092 | "Unable to save state of activity " |
| 4093 | + r.intent.getComponent().toShortString() |
| 4094 | + ": " + e.toString(), e); |
| 4095 | } |
| 4096 | } |
| 4097 | } |
| 4098 | |
| 4099 | if (!keepShown) { |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 4100 | callActivityOnStop(r, saveState, reason); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4101 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4102 | } |
| 4103 | } |
| 4104 | |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 4105 | /** |
| 4106 | * Calls {@link Activity#onStop()} and {@link Activity#onSaveInstanceState(Bundle)}, and updates |
| 4107 | * the client record's state. |
| 4108 | * All calls to stop an activity must be done through this method to make sure that |
| 4109 | * {@link Activity#onSaveInstanceState(Bundle)} is also executed in the same call. |
| 4110 | */ |
| 4111 | private void callActivityOnStop(ActivityClientRecord r, boolean saveState, String reason) { |
Andrii Kulian | 391161f | 2018-01-29 10:50:02 -0800 | [diff] [blame] | 4112 | // Before P onSaveInstanceState was called before onStop, starting with P it's |
| 4113 | // called after. Before Honeycomb state was always saved before onPause. |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 4114 | final boolean shouldSaveState = saveState && !r.activity.mFinished && r.state == null |
| 4115 | && !r.isPreHoneycomb(); |
Andrii Kulian | 391161f | 2018-01-29 10:50:02 -0800 | [diff] [blame] | 4116 | final boolean isPreP = r.isPreP(); |
| 4117 | if (shouldSaveState && isPreP) { |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 4118 | callActivityOnSaveInstanceState(r); |
| 4119 | } |
| 4120 | |
| 4121 | try { |
| 4122 | r.activity.performStop(false /*preserveWindow*/); |
| 4123 | } catch (SuperNotCalledException e) { |
| 4124 | throw e; |
| 4125 | } catch (Exception e) { |
| 4126 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4127 | throw new RuntimeException( |
| 4128 | "Unable to stop activity " |
| 4129 | + r.intent.getComponent().toShortString() |
| 4130 | + ": " + e.toString(), e); |
| 4131 | } |
| 4132 | } |
| 4133 | r.setState(ON_STOP); |
| 4134 | EventLog.writeEvent(LOG_AM_ON_STOP_CALLED, UserHandle.myUserId(), |
| 4135 | r.activity.getComponentName().getClassName(), reason); |
Andrii Kulian | 391161f | 2018-01-29 10:50:02 -0800 | [diff] [blame] | 4136 | |
| 4137 | if (shouldSaveState && !isPreP) { |
| 4138 | callActivityOnSaveInstanceState(r); |
| 4139 | } |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 4140 | } |
| 4141 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 4142 | private void updateVisibility(ActivityClientRecord r, boolean show) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4143 | View v = r.activity.mDecor; |
| 4144 | if (v != null) { |
| 4145 | if (show) { |
| 4146 | if (!r.activity.mVisibleFromServer) { |
| 4147 | r.activity.mVisibleFromServer = true; |
| 4148 | mNumVisibleActivities++; |
| 4149 | if (r.activity.mVisibleFromClient) { |
| 4150 | r.activity.makeVisible(); |
| 4151 | } |
| 4152 | } |
| 4153 | if (r.newConfig != null) { |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4154 | performConfigurationChangedForActivity(r, r.newConfig); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4155 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Updating activity vis " |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 4156 | + r.activityInfo.name + " with new config " |
| 4157 | + r.activity.mCurrentConfig); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4158 | r.newConfig = null; |
| 4159 | } |
| 4160 | } else { |
| 4161 | if (r.activity.mVisibleFromServer) { |
| 4162 | r.activity.mVisibleFromServer = false; |
| 4163 | mNumVisibleActivities--; |
| 4164 | v.setVisibility(View.INVISIBLE); |
| 4165 | } |
| 4166 | } |
| 4167 | } |
| 4168 | } |
| 4169 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 4170 | @Override |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4171 | public void handleStopActivity(IBinder token, boolean show, int configChanges, |
| 4172 | PendingTransactionActions pendingActions) { |
| 4173 | final ActivityClientRecord r = mActivities.get(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4174 | r.activity.mConfigChangeFlags |= configChanges; |
| 4175 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4176 | final StopInfo stopInfo = new StopInfo(); |
| 4177 | performStopActivityInner(r, stopInfo, show, true, "handleStopActivity"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4178 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4179 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4180 | TAG, "Finishing stop of " + r + ": show=" + show |
| 4181 | + " win=" + r.window); |
| 4182 | |
| 4183 | updateVisibility(r, show); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4184 | |
Dianne Hackborn | 5d9d03a | 2011-01-24 13:15:09 -0800 | [diff] [blame] | 4185 | // Make sure any pending writes are now committed. |
| 4186 | if (!r.isPreHoneycomb()) { |
| 4187 | QueuedWork.waitToFinish(); |
| 4188 | } |
| 4189 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4190 | stopInfo.setActivity(r); |
| 4191 | stopInfo.setState(r.state); |
| 4192 | stopInfo.setPersistentState(r.persistentState); |
| 4193 | pendingActions.setStopInfo(stopInfo); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4194 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4195 | } |
| 4196 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4197 | /** |
| 4198 | * Schedule the call to tell the activity manager we have stopped. We don't do this |
| 4199 | * immediately, because we want to have a chance for any other pending work (in particular |
| 4200 | * memory trim requests) to complete before you tell the activity manager to proceed and allow |
| 4201 | * us to go fully into the background. |
| 4202 | */ |
| 4203 | @Override |
| 4204 | public void reportStop(PendingTransactionActions pendingActions) { |
| 4205 | mH.post(pendingActions.getStopInfo()); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 4206 | } |
| 4207 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4208 | @Override |
| 4209 | public void performRestartActivity(IBinder token, boolean start) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4210 | ActivityClientRecord r = mActivities.get(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4211 | if (r.stopped) { |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4212 | r.activity.performRestart(start); |
| 4213 | if (start) { |
| 4214 | r.setState(ON_START); |
| 4215 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4216 | } |
| 4217 | } |
| 4218 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 4219 | @Override |
| 4220 | public void handleWindowVisibility(IBinder token, boolean show) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4221 | ActivityClientRecord r = mActivities.get(token); |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 4222 | |
Dianne Hackborn | bfddc0f | 2010-12-14 11:28:01 -0800 | [diff] [blame] | 4223 | if (r == null) { |
| 4224 | Log.w(TAG, "handleWindowVisibility: no activity for token " + token); |
| 4225 | return; |
| 4226 | } |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 4227 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4228 | if (!show && !r.stopped) { |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 4229 | performStopActivityInner(r, null, show, false, "handleWindowVisibility"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4230 | } else if (show && r.stopped) { |
| 4231 | // If we are getting ready to gc after going to the background, well |
| 4232 | // we are back active so skip it. |
| 4233 | unscheduleGcIdler(); |
| 4234 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4235 | r.activity.performRestart(true /* start */); |
| 4236 | r.setState(ON_START); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4237 | } |
| 4238 | if (r.activity.mDecor != null) { |
Joe Onorato | 43a1765 | 2011-04-06 19:22:23 -0700 | [diff] [blame] | 4239 | if (false) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4240 | TAG, "Handle window " + r + " visibility: " + show); |
| 4241 | updateVisibility(r, show); |
| 4242 | } |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4243 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4244 | } |
| 4245 | |
Wale Ogunwale | b5066fe | 2016-09-21 07:33:43 -0700 | [diff] [blame] | 4246 | // TODO: This method should be changed to use {@link #performStopActivityInner} to perform to |
| 4247 | // stop operation on the activity to reduce code duplication and the chance of fixing a bug in |
| 4248 | // one place and missing the other. |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 4249 | private void handleSleeping(IBinder token, boolean sleeping) { |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 4250 | ActivityClientRecord r = mActivities.get(token); |
| 4251 | |
| 4252 | if (r == null) { |
Dianne Hackborn | 842e04b | 2011-01-22 13:00:12 -0800 | [diff] [blame] | 4253 | Log.w(TAG, "handleSleeping: no activity for token " + token); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 4254 | return; |
| 4255 | } |
| 4256 | |
| 4257 | if (sleeping) { |
Dianne Hackborn | 842e04b | 2011-01-22 13:00:12 -0800 | [diff] [blame] | 4258 | if (!r.stopped && !r.isPreHoneycomb()) { |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 4259 | callActivityOnStop(r, true /* saveState */, "sleeping"); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 4260 | } |
Dianne Hackborn | 5d9d03a | 2011-01-24 13:15:09 -0800 | [diff] [blame] | 4261 | |
| 4262 | // Make sure any pending writes are now committed. |
| 4263 | if (!r.isPreHoneycomb()) { |
| 4264 | QueuedWork.waitToFinish(); |
| 4265 | } |
| 4266 | |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 4267 | // Tell activity manager we slept. |
| 4268 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 4269 | ActivityManager.getService().activitySlept(r.token); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 4270 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4271 | throw ex.rethrowFromSystemServer(); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 4272 | } |
| 4273 | } else { |
| 4274 | if (r.stopped && r.activity.mVisibleFromServer) { |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4275 | r.activity.performRestart(true /* start */); |
| 4276 | r.setState(ON_START); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 4277 | } |
| 4278 | } |
| 4279 | } |
| 4280 | |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 4281 | private void handleSetCoreSettings(Bundle coreSettings) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4282 | synchronized (mResourcesManager) { |
Svetoslav Ganov | 9aa597e | 2011-03-03 18:17:41 -0800 | [diff] [blame] | 4283 | mCoreSettings = coreSettings; |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 4284 | } |
Jon Miranda | 836c0a8 | 2014-08-11 12:32:26 -0700 | [diff] [blame] | 4285 | onCoreSettingsChange(); |
| 4286 | } |
| 4287 | |
| 4288 | private void onCoreSettingsChange() { |
| 4289 | boolean debugViewAttributes = |
| 4290 | mCoreSettings.getInt(Settings.Global.DEBUG_VIEW_ATTRIBUTES, 0) != 0; |
| 4291 | if (debugViewAttributes != View.mDebugViewAttributes) { |
| 4292 | View.mDebugViewAttributes = debugViewAttributes; |
| 4293 | |
| 4294 | // request all activities to relaunch for the changes to take place |
Fyodor Kupolov | cb93d6f | 2017-05-04 17:27:16 -0700 | [diff] [blame] | 4295 | requestRelaunchAllActivities(); |
| 4296 | } |
| 4297 | } |
| 4298 | |
| 4299 | private void requestRelaunchAllActivities() { |
| 4300 | for (Map.Entry<IBinder, ActivityClientRecord> entry : mActivities.entrySet()) { |
| 4301 | final Activity activity = entry.getValue().activity; |
| 4302 | if (!activity.mFinished) { |
| 4303 | try { |
| 4304 | ActivityManager.getService().requestActivityRelaunch(entry.getKey()); |
| 4305 | } catch (RemoteException e) { |
| 4306 | throw e.rethrowFromSystemServer(); |
| 4307 | } |
Jon Miranda | 836c0a8 | 2014-08-11 12:32:26 -0700 | [diff] [blame] | 4308 | } |
| 4309 | } |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 4310 | } |
| 4311 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4312 | private void handleUpdatePackageCompatibilityInfo(UpdateCompatibilityData data) { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 4313 | LoadedApk apk = peekPackageInfo(data.pkg, false); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4314 | if (apk != null) { |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 4315 | apk.setCompatibilityInfo(data.info); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4316 | } |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 4317 | apk = peekPackageInfo(data.pkg, true); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4318 | if (apk != null) { |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 4319 | apk.setCompatibilityInfo(data.info); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4320 | } |
| 4321 | handleConfigurationChanged(mConfiguration, data.info); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 4322 | WindowManagerGlobal.getInstance().reportNewConfiguration(mConfiguration); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4323 | } |
| 4324 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 4325 | private void deliverResults(ActivityClientRecord r, List<ResultInfo> results) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4326 | final int N = results.size(); |
| 4327 | for (int i=0; i<N; i++) { |
| 4328 | ResultInfo ri = results.get(i); |
| 4329 | try { |
| 4330 | if (ri.mData != null) { |
| 4331 | ri.mData.setExtrasClassLoader(r.activity.getClassLoader()); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 4332 | ri.mData.prepareToEnterProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4333 | } |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4334 | if (DEBUG_RESULTS) Slog.v(TAG, |
Chris Tate | 8a7dc17 | 2009-03-24 20:11:42 -0700 | [diff] [blame] | 4335 | "Delivering result to activity " + r + " : " + ri); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4336 | r.activity.dispatchActivityResult(ri.mResultWho, |
| 4337 | ri.mRequestCode, ri.mResultCode, ri.mData); |
| 4338 | } catch (Exception e) { |
| 4339 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4340 | throw new RuntimeException( |
| 4341 | "Failure delivering result " + ri + " to activity " |
| 4342 | + r.intent.getComponent().toShortString() |
| 4343 | + ": " + e.toString(), e); |
| 4344 | } |
| 4345 | } |
| 4346 | } |
| 4347 | } |
| 4348 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 4349 | @Override |
| 4350 | public void handleSendResult(IBinder token, List<ResultInfo> results) { |
| 4351 | ActivityClientRecord r = mActivities.get(token); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4352 | 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] | 4353 | if (r != null) { |
| 4354 | final boolean resumed = !r.paused; |
| 4355 | if (!r.activity.mFinished && r.activity.mDecor != null |
| 4356 | && r.hideForNow && resumed) { |
| 4357 | // We had hidden the activity because it started another |
| 4358 | // one... we have gotten a result back and we are not |
| 4359 | // paused, so make sure our window is visible. |
| 4360 | updateVisibility(r, true); |
| 4361 | } |
| 4362 | if (resumed) { |
| 4363 | try { |
| 4364 | // Now we are idle. |
| 4365 | r.activity.mCalled = false; |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 4366 | r.activity.mTemporaryPause = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4367 | mInstrumentation.callActivityOnPause(r.activity); |
| 4368 | if (!r.activity.mCalled) { |
| 4369 | throw new SuperNotCalledException( |
| 4370 | "Activity " + r.intent.getComponent().toShortString() |
| 4371 | + " did not call through to super.onPause()"); |
| 4372 | } |
| 4373 | } catch (SuperNotCalledException e) { |
| 4374 | throw e; |
| 4375 | } catch (Exception e) { |
| 4376 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4377 | throw new RuntimeException( |
| 4378 | "Unable to pause activity " |
| 4379 | + r.intent.getComponent().toShortString() |
| 4380 | + ": " + e.toString(), e); |
| 4381 | } |
| 4382 | } |
| 4383 | } |
Sudheer Shanka | 43b5ea4 | 2017-06-21 11:24:53 -0700 | [diff] [blame] | 4384 | checkAndBlockForNetworkAccess(); |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 4385 | deliverResults(r, results); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4386 | if (resumed) { |
Dake Gu | 67decfa | 2017-12-27 11:48:08 -0800 | [diff] [blame] | 4387 | r.activity.performResume(false); |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 4388 | r.activity.mTemporaryPause = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4389 | } |
| 4390 | } |
| 4391 | } |
| 4392 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4393 | /** Core implementation of activity destroy call. */ |
| 4394 | ActivityClientRecord performDestroyActivity(IBinder token, boolean finishing, |
Bryce Lee | a33c13d | 2018-02-08 14:37:06 -0800 | [diff] [blame] | 4395 | int configChanges, boolean getNonConfigInstance, String reason) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4396 | ActivityClientRecord r = mActivities.get(token); |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4397 | Class<? extends Activity> activityClass = null; |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4398 | if (localLOGV) Slog.v(TAG, "Performing finish of " + r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4399 | if (r != null) { |
Brad Fitzpatrick | 5f8b5c1 | 2011-01-20 15:12:08 -0800 | [diff] [blame] | 4400 | activityClass = r.activity.getClass(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4401 | r.activity.mConfigChangeFlags |= configChanges; |
| 4402 | if (finishing) { |
| 4403 | r.activity.mFinished = true; |
| 4404 | } |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 4405 | |
| 4406 | performPauseActivityIfNeeded(r, "destroy"); |
| 4407 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4408 | if (!r.stopped) { |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 4409 | callActivityOnStop(r, false /* saveState */, "destroy"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4410 | } |
| 4411 | if (getNonConfigInstance) { |
| 4412 | try { |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 4413 | r.lastNonConfigurationInstances |
| 4414 | = r.activity.retainNonConfigurationInstances(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4415 | } catch (Exception e) { |
| 4416 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4417 | throw new RuntimeException( |
| 4418 | "Unable to retain activity " |
| 4419 | + r.intent.getComponent().toShortString() |
| 4420 | + ": " + e.toString(), e); |
| 4421 | } |
| 4422 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4423 | } |
| 4424 | try { |
| 4425 | r.activity.mCalled = false; |
Dianne Hackborn | 2dedce6 | 2010-04-15 14:45:25 -0700 | [diff] [blame] | 4426 | mInstrumentation.callActivityOnDestroy(r.activity); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4427 | if (!r.activity.mCalled) { |
| 4428 | throw new SuperNotCalledException( |
Mitsuru Oshima | d9aef73 | 2009-06-16 20:20:50 -0700 | [diff] [blame] | 4429 | "Activity " + safeToComponentShortString(r.intent) + |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4430 | " did not call through to super.onDestroy()"); |
| 4431 | } |
| 4432 | if (r.window != null) { |
| 4433 | r.window.closeAllPanels(); |
| 4434 | } |
| 4435 | } catch (SuperNotCalledException e) { |
| 4436 | throw e; |
| 4437 | } catch (Exception e) { |
| 4438 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4439 | throw new RuntimeException( |
Mitsuru Oshima | d9aef73 | 2009-06-16 20:20:50 -0700 | [diff] [blame] | 4440 | "Unable to destroy activity " + safeToComponentShortString(r.intent) |
| 4441 | + ": " + e.toString(), e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4442 | } |
| 4443 | } |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4444 | r.setState(ON_DESTROY); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4445 | } |
| 4446 | mActivities.remove(token); |
Bryce Lee | a33c13d | 2018-02-08 14:37:06 -0800 | [diff] [blame] | 4447 | mRecentDestroyedActivities.add(0, new DestroyedActivityInfo(token.hashCode(), reason)); |
| 4448 | |
| 4449 | final int recentDestroyedActivitiesSize = mRecentDestroyedActivities.size(); |
| 4450 | if (recentDestroyedActivitiesSize > MAX_DESTROYED_ACTIVITIES) { |
| 4451 | mRecentDestroyedActivities.remove(recentDestroyedActivitiesSize - 1); |
| 4452 | } |
Brad Fitzpatrick | 5f8b5c1 | 2011-01-20 15:12:08 -0800 | [diff] [blame] | 4453 | StrictMode.decrementExpectedActivityCount(activityClass); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4454 | return r; |
| 4455 | } |
| 4456 | |
Mitsuru Oshima | d9aef73 | 2009-06-16 20:20:50 -0700 | [diff] [blame] | 4457 | private static String safeToComponentShortString(Intent intent) { |
| 4458 | ComponentName component = intent.getComponent(); |
| 4459 | return component == null ? "[Unknown]" : component.toShortString(); |
| 4460 | } |
| 4461 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 4462 | @Override |
| 4463 | public void handleDestroyActivity(IBinder token, boolean finishing, int configChanges, |
Bryce Lee | a33c13d | 2018-02-08 14:37:06 -0800 | [diff] [blame] | 4464 | boolean getNonConfigInstance, String reason) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4465 | ActivityClientRecord r = performDestroyActivity(token, finishing, |
Bryce Lee | a33c13d | 2018-02-08 14:37:06 -0800 | [diff] [blame] | 4466 | configChanges, getNonConfigInstance, reason); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4467 | if (r != null) { |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4468 | cleanUpPendingRemoveWindows(r, finishing); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4469 | WindowManager wm = r.activity.getWindowManager(); |
| 4470 | View v = r.activity.mDecor; |
| 4471 | if (v != null) { |
| 4472 | if (r.activity.mVisibleFromServer) { |
| 4473 | mNumVisibleActivities--; |
| 4474 | } |
| 4475 | IBinder wtoken = v.getWindowToken(); |
| 4476 | if (r.activity.mWindowAdded) { |
Robert Carr | 77bdfb5 | 2016-05-02 18:18:31 -0700 | [diff] [blame] | 4477 | if (r.mPreserveWindow) { |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4478 | // Hold off on removing this until the new activity's |
| 4479 | // window is being added. |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4480 | r.mPendingRemoveWindow = r.window; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4481 | r.mPendingRemoveWindowManager = wm; |
Andrii Kulian | eac0ea5 | 2016-05-11 15:50:24 -0700 | [diff] [blame] | 4482 | // We can only keep the part of the view hierarchy that we control, |
| 4483 | // everything else must be removed, because it might not be able to |
| 4484 | // behave properly when activity is relaunching. |
| 4485 | r.window.clearContentView(); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4486 | } else { |
| 4487 | wm.removeViewImmediate(v); |
| 4488 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4489 | } |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4490 | if (wtoken != null && r.mPendingRemoveWindow == null) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 4491 | WindowManagerGlobal.getInstance().closeAll(wtoken, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4492 | r.activity.getClass().getName(), "Activity"); |
Andrii Kulian | eac0ea5 | 2016-05-11 15:50:24 -0700 | [diff] [blame] | 4493 | } else if (r.mPendingRemoveWindow != null) { |
| 4494 | // We're preserving only one window, others should be closed so app views |
| 4495 | // will be detached before the final tear down. It should be done now because |
| 4496 | // some components (e.g. WebView) rely on detach callbacks to perform receiver |
| 4497 | // unregister and other cleanup. |
| 4498 | WindowManagerGlobal.getInstance().closeAllExceptView(token, v, |
| 4499 | r.activity.getClass().getName(), "Activity"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4500 | } |
| 4501 | r.activity.mDecor = null; |
| 4502 | } |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4503 | if (r.mPendingRemoveWindow == null) { |
| 4504 | // If we are delaying the removal of the activity window, then |
| 4505 | // we can't clean up all windows here. Note that we can't do |
| 4506 | // so later either, which means any windows that aren't closed |
| 4507 | // by the app will leak. Well we try to warning them a lot |
| 4508 | // about leaking windows, because that is a bug, so if they are |
| 4509 | // using this recreate facility then they get to live with leaks. |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 4510 | WindowManagerGlobal.getInstance().closeAll(token, |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4511 | r.activity.getClass().getName(), "Activity"); |
| 4512 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4513 | |
| 4514 | // Mocked out contexts won't be participating in the normal |
| 4515 | // process lifecycle, but if we're running with a proper |
| 4516 | // ApplicationContext we need to have it tear down things |
| 4517 | // cleanly. |
| 4518 | Context c = r.activity.getBaseContext(); |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 4519 | if (c instanceof ContextImpl) { |
| 4520 | ((ContextImpl) c).scheduleFinalCleanup( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4521 | r.activity.getClass().getName(), "Activity"); |
| 4522 | } |
| 4523 | } |
| 4524 | if (finishing) { |
| 4525 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 4526 | ActivityManager.getService().activityDestroyed(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4527 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4528 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4529 | } |
| 4530 | } |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4531 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4532 | } |
| 4533 | |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 4534 | @Override |
| 4535 | public ActivityClientRecord prepareRelaunchActivity(IBinder token, |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 4536 | List<ResultInfo> pendingResults, List<ReferrerIntent> pendingNewIntents, |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 4537 | int configChanges, MergedConfiguration config, boolean preserveWindow) { |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4538 | ActivityClientRecord target = null; |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 4539 | boolean scheduleRelaunch = false; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4540 | |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4541 | synchronized (mResourcesManager) { |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4542 | for (int i=0; i<mRelaunchingActivities.size(); i++) { |
| 4543 | ActivityClientRecord r = mRelaunchingActivities.get(i); |
Filip Gruszczynski | c3b6179 | 2016-01-22 16:43:48 -0800 | [diff] [blame] | 4544 | if (DEBUG_ORDER) Slog.d(TAG, "requestRelaunchActivity: " + this + ", trying: " + r); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4545 | if (r.token == token) { |
| 4546 | target = r; |
| 4547 | if (pendingResults != null) { |
| 4548 | if (r.pendingResults != null) { |
| 4549 | r.pendingResults.addAll(pendingResults); |
| 4550 | } else { |
| 4551 | r.pendingResults = pendingResults; |
| 4552 | } |
| 4553 | } |
| 4554 | if (pendingNewIntents != null) { |
| 4555 | if (r.pendingIntents != null) { |
| 4556 | r.pendingIntents.addAll(pendingNewIntents); |
| 4557 | } else { |
| 4558 | r.pendingIntents = pendingNewIntents; |
| 4559 | } |
| 4560 | } |
| 4561 | break; |
| 4562 | } |
| 4563 | } |
| 4564 | |
| 4565 | if (target == null) { |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 4566 | if (DEBUG_ORDER) Slog.d(TAG, "requestRelaunchActivity: target is null"); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4567 | target = new ActivityClientRecord(); |
| 4568 | target.token = token; |
| 4569 | target.pendingResults = pendingResults; |
| 4570 | target.pendingIntents = pendingNewIntents; |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4571 | target.mPreserveWindow = preserveWindow; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4572 | mRelaunchingActivities.add(target); |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 4573 | scheduleRelaunch = true; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4574 | } |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 4575 | target.createdConfig = config.getGlobalConfiguration(); |
| 4576 | target.overrideConfig = config.getOverrideConfiguration(); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4577 | target.pendingConfigChanges |= configChanges; |
| 4578 | } |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 4579 | |
| 4580 | return scheduleRelaunch ? target : null; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4581 | } |
| 4582 | |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 4583 | @Override |
| 4584 | public void handleRelaunchActivity(ActivityClientRecord tmp, |
| 4585 | PendingTransactionActions pendingActions) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4586 | // If we are getting ready to gc after going to the background, well |
| 4587 | // we are back active so skip it. |
| 4588 | unscheduleGcIdler(); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4589 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4590 | |
| 4591 | Configuration changedConfig = null; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4592 | int configChanges = 0; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4593 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4594 | // First: make sure we have the most recent configuration and most |
| 4595 | // recent version of the activity, or skip it if some previous call |
| 4596 | // had taken a more recent version. |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4597 | synchronized (mResourcesManager) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4598 | int N = mRelaunchingActivities.size(); |
| 4599 | IBinder token = tmp.token; |
| 4600 | tmp = null; |
| 4601 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4602 | ActivityClientRecord r = mRelaunchingActivities.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4603 | if (r.token == token) { |
| 4604 | tmp = r; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4605 | configChanges |= tmp.pendingConfigChanges; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4606 | mRelaunchingActivities.remove(i); |
| 4607 | i--; |
| 4608 | N--; |
| 4609 | } |
| 4610 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4611 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4612 | if (tmp == null) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4613 | 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] | 4614 | return; |
| 4615 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4616 | |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4617 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Relaunching activity " |
| 4618 | + tmp.token + " with configChanges=0x" |
| 4619 | + Integer.toHexString(configChanges)); |
| 4620 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4621 | if (mPendingConfiguration != null) { |
| 4622 | changedConfig = mPendingConfiguration; |
| 4623 | mPendingConfiguration = null; |
| 4624 | } |
| 4625 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4626 | |
Dianne Hackborn | 871ecdc | 2009-12-11 15:24:33 -0800 | [diff] [blame] | 4627 | if (tmp.createdConfig != null) { |
| 4628 | // If the activity manager is passing us its current config, |
| 4629 | // assume that is really what we want regardless of what we |
| 4630 | // may have pending. |
| 4631 | if (mConfiguration == null |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4632 | || (tmp.createdConfig.isOtherSeqNewer(mConfiguration) |
| 4633 | && mConfiguration.diff(tmp.createdConfig) != 0)) { |
| 4634 | if (changedConfig == null |
| 4635 | || tmp.createdConfig.isOtherSeqNewer(changedConfig)) { |
| 4636 | changedConfig = tmp.createdConfig; |
| 4637 | } |
Dianne Hackborn | 871ecdc | 2009-12-11 15:24:33 -0800 | [diff] [blame] | 4638 | } |
| 4639 | } |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 4640 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4641 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Relaunching activity " |
Dianne Hackborn | dc6b635 | 2009-09-30 14:20:09 -0700 | [diff] [blame] | 4642 | + tmp.token + ": changedConfig=" + changedConfig); |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 4643 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4644 | // If there was a pending configuration change, execute it first. |
| 4645 | if (changedConfig != null) { |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 4646 | mCurDefaultDisplayDpi = changedConfig.densityDpi; |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 4647 | updateDefaultDensity(); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4648 | handleConfigurationChanged(changedConfig, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4649 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4650 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4651 | ActivityClientRecord r = mActivities.get(tmp.token); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4652 | 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] | 4653 | if (r == null) { |
| 4654 | return; |
| 4655 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4656 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4657 | r.activity.mConfigChangeFlags |= configChanges; |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4658 | r.mPreserveWindow = tmp.mPreserveWindow; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4659 | |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4660 | r.activity.mChangingConfigurations = true; |
| 4661 | |
Robert Carr | 23fa16b | 2016-01-13 13:19:58 -0800 | [diff] [blame] | 4662 | // If we are preserving the main window across relaunches we would also like to preserve |
| 4663 | // the children. However the client side view system does not support preserving |
| 4664 | // the child views so we notify the window manager to expect these windows to |
| 4665 | // be replaced and defer requests to destroy or hide them. This way we can achieve |
| 4666 | // visual continuity. It's important that we do this here prior to pause and destroy |
| 4667 | // as that is when we may hide or remove the child views. |
Robert Carr | 77bdfb5 | 2016-05-02 18:18:31 -0700 | [diff] [blame] | 4668 | // |
| 4669 | // There is another scenario, if we have decided locally to relaunch the app from a |
| 4670 | // call to recreate, then none of the windows will be prepared for replacement or |
| 4671 | // preserved by the server, so we want to notify it that we are preparing to replace |
| 4672 | // everything |
Robert Carr | 23fa16b | 2016-01-13 13:19:58 -0800 | [diff] [blame] | 4673 | try { |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 4674 | if (r.mPreserveWindow) { |
Robert Carr | 77bdfb5 | 2016-05-02 18:18:31 -0700 | [diff] [blame] | 4675 | WindowManagerGlobal.getWindowSession().prepareToReplaceWindows( |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 4676 | r.token, true /* childrenOnly */); |
Robert Carr | 23fa16b | 2016-01-13 13:19:58 -0800 | [diff] [blame] | 4677 | } |
| 4678 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4679 | throw e.rethrowFromSystemServer(); |
Robert Carr | 23fa16b | 2016-01-13 13:19:58 -0800 | [diff] [blame] | 4680 | } |
| 4681 | |
Dianne Hackborn | e2b0480 | 2010-12-09 09:24:55 -0800 | [diff] [blame] | 4682 | // Need to ensure state is saved. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4683 | if (!r.paused) { |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 4684 | performPauseActivity(r, false, "handleRelaunchActivity", |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4685 | null /* pendingActions */); |
Dianne Hackborn | e2b0480 | 2010-12-09 09:24:55 -0800 | [diff] [blame] | 4686 | } |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 4687 | if (!r.stopped) { |
| 4688 | callActivityOnStop(r, true /* saveState */, "handleRelaunchActivity"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4689 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4690 | |
Bryce Lee | a33c13d | 2018-02-08 14:37:06 -0800 | [diff] [blame] | 4691 | handleDestroyActivity(r.token, false, configChanges, true, "handleRelaunchActivity"); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4692 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4693 | r.activity = null; |
| 4694 | r.window = null; |
| 4695 | r.hideForNow = false; |
| 4696 | r.nextIdle = null; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4697 | // Merge any pending results and pending intents; don't just replace them |
| 4698 | if (tmp.pendingResults != null) { |
| 4699 | if (r.pendingResults == null) { |
| 4700 | r.pendingResults = tmp.pendingResults; |
| 4701 | } else { |
| 4702 | r.pendingResults.addAll(tmp.pendingResults); |
| 4703 | } |
| 4704 | } |
| 4705 | if (tmp.pendingIntents != null) { |
| 4706 | if (r.pendingIntents == null) { |
| 4707 | r.pendingIntents = tmp.pendingIntents; |
| 4708 | } else { |
| 4709 | r.pendingIntents.addAll(tmp.pendingIntents); |
| 4710 | } |
| 4711 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4712 | r.startsNotResumed = tmp.startsNotResumed; |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 4713 | r.overrideConfig = tmp.overrideConfig; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4714 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4715 | handleLaunchActivity(r, pendingActions); |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 4716 | // Only report a successful relaunch to WindowManager. |
| 4717 | pendingActions.setReportRelaunchToWindowManager(true); |
| 4718 | } |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4719 | |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 4720 | @Override |
| 4721 | public void reportRelaunch(IBinder token, PendingTransactionActions pendingActions) { |
| 4722 | try { |
| 4723 | ActivityManager.getService().activityRelaunched(token); |
| 4724 | final ActivityClientRecord r = mActivities.get(token); |
| 4725 | if (pendingActions.shouldReportRelaunchToWindowManager() && r != null |
| 4726 | && r.window != null) { |
| 4727 | r.window.reportActivityRelaunched(); |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4728 | } |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 4729 | } catch (RemoteException e) { |
| 4730 | throw e.rethrowFromSystemServer(); |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4731 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4732 | } |
| 4733 | |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 4734 | private void callActivityOnSaveInstanceState(ActivityClientRecord r) { |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 4735 | r.state = new Bundle(); |
| 4736 | r.state.setAllowFds(false); |
| 4737 | if (r.isPersistable()) { |
| 4738 | r.persistentState = new PersistableBundle(); |
| 4739 | mInstrumentation.callActivityOnSaveInstanceState(r.activity, r.state, |
| 4740 | r.persistentState); |
| 4741 | } else { |
| 4742 | mInstrumentation.callActivityOnSaveInstanceState(r.activity, r.state); |
| 4743 | } |
| 4744 | } |
| 4745 | |
Dianne Hackborn | 73c1416 | 2012-09-19 15:45:06 -0700 | [diff] [blame] | 4746 | ArrayList<ComponentCallbacks2> collectComponentCallbacks( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4747 | boolean allActivities, Configuration newConfig) { |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 4748 | ArrayList<ComponentCallbacks2> callbacks |
| 4749 | = new ArrayList<ComponentCallbacks2>(); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4750 | |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4751 | synchronized (mResourcesManager) { |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 4752 | final int NAPP = mAllApplications.size(); |
| 4753 | for (int i=0; i<NAPP; i++) { |
Dianne Hackborn | 73c1416 | 2012-09-19 15:45:06 -0700 | [diff] [blame] | 4754 | callbacks.add(mAllApplications.get(i)); |
| 4755 | } |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 4756 | final int NACT = mActivities.size(); |
| 4757 | for (int i=0; i<NACT; i++) { |
| 4758 | ActivityClientRecord ar = mActivities.valueAt(i); |
| 4759 | Activity a = ar.activity; |
| 4760 | if (a != null) { |
| 4761 | Configuration thisConfig = applyConfigCompatMainThread( |
| 4762 | mCurDefaultDisplayDpi, newConfig, |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 4763 | ar.packageInfo.getCompatibilityInfo()); |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 4764 | if (!ar.activity.mFinished && (allActivities || !ar.paused)) { |
| 4765 | // If the activity is currently resumed, its configuration |
| 4766 | // needs to change right now. |
| 4767 | callbacks.add(a); |
| 4768 | } else if (thisConfig != null) { |
| 4769 | // Otherwise, we will tell it about the change |
| 4770 | // the next time it is resumed or shown. Note that |
| 4771 | // the activity manager may, before then, decide the |
| 4772 | // activity needs to be destroyed to handle its new |
| 4773 | // configuration. |
| 4774 | if (DEBUG_CONFIGURATION) { |
| 4775 | Slog.v(TAG, "Setting activity " |
| 4776 | + ar.activityInfo.name + " newConfig=" + thisConfig); |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 4777 | } |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 4778 | ar.newConfig = thisConfig; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4779 | } |
| 4780 | } |
| 4781 | } |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 4782 | final int NSVC = mServices.size(); |
| 4783 | for (int i=0; i<NSVC; i++) { |
| 4784 | callbacks.add(mServices.valueAt(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4785 | } |
| 4786 | } |
| 4787 | synchronized (mProviderMap) { |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 4788 | final int NPRV = mLocalProviders.size(); |
| 4789 | for (int i=0; i<NPRV; i++) { |
| 4790 | callbacks.add(mLocalProviders.valueAt(i).mLocalProvider); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4791 | } |
| 4792 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4793 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4794 | return callbacks; |
| 4795 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4796 | |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 4797 | /** |
| 4798 | * Updates the configuration for an Activity. The ActivityClientRecord's |
| 4799 | * {@link ActivityClientRecord#overrideConfig} is used to compute the final Configuration for |
| 4800 | * that Activity. {@link ActivityClientRecord#tmpConfig} is used as a temporary for delivering |
| 4801 | * the updated Configuration. |
| 4802 | * @param r ActivityClientRecord representing the Activity. |
| 4803 | * @param newBaseConfig The new configuration to use. This may be augmented with |
| 4804 | * {@link ActivityClientRecord#overrideConfig}. |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 4805 | */ |
| 4806 | private void performConfigurationChangedForActivity(ActivityClientRecord r, |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4807 | Configuration newBaseConfig) { |
| 4808 | performConfigurationChangedForActivity(r, newBaseConfig, |
| 4809 | r.activity.getDisplay().getDisplayId(), false /* movedToDifferentDisplay */); |
| 4810 | } |
| 4811 | |
| 4812 | /** |
| 4813 | * Updates the configuration for an Activity. The ActivityClientRecord's |
| 4814 | * {@link ActivityClientRecord#overrideConfig} is used to compute the final Configuration for |
| 4815 | * that Activity. {@link ActivityClientRecord#tmpConfig} is used as a temporary for delivering |
| 4816 | * the updated Configuration. |
| 4817 | * @param r ActivityClientRecord representing the Activity. |
| 4818 | * @param newBaseConfig The new configuration to use. This may be augmented with |
| 4819 | * {@link ActivityClientRecord#overrideConfig}. |
| 4820 | * @param displayId The id of the display where the Activity currently resides. |
| 4821 | * @param movedToDifferentDisplay Indicates if the activity was moved to different display. |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 4822 | * @return {@link Configuration} instance sent to client, null if not sent. |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4823 | */ |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 4824 | private Configuration performConfigurationChangedForActivity(ActivityClientRecord r, |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4825 | Configuration newBaseConfig, int displayId, boolean movedToDifferentDisplay) { |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 4826 | r.tmpConfig.setTo(newBaseConfig); |
| 4827 | if (r.overrideConfig != null) { |
| 4828 | r.tmpConfig.updateFrom(r.overrideConfig); |
| 4829 | } |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 4830 | final Configuration reportedConfig = performActivityConfigurationChanged(r.activity, |
| 4831 | r.tmpConfig, r.overrideConfig, displayId, movedToDifferentDisplay); |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 4832 | freeTextLayoutCachesIfNeeded(r.activity.mCurrentConfig.diff(r.tmpConfig)); |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 4833 | return reportedConfig; |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 4834 | } |
| 4835 | |
| 4836 | /** |
Adam Lesinski | c1b0ebf | 2016-06-09 11:17:10 -0700 | [diff] [blame] | 4837 | * Creates a new Configuration only if override would modify base. Otherwise returns base. |
| 4838 | * @param base The base configuration. |
| 4839 | * @param override The update to apply to the base configuration. Can be null. |
| 4840 | * @return A Configuration representing base with override applied. |
| 4841 | */ |
| 4842 | private static Configuration createNewConfigAndUpdateIfNotNull(@NonNull Configuration base, |
| 4843 | @Nullable Configuration override) { |
| 4844 | if (override == null) { |
| 4845 | return base; |
| 4846 | } |
| 4847 | Configuration newConfig = new Configuration(base); |
| 4848 | newConfig.updateFrom(override); |
| 4849 | return newConfig; |
| 4850 | } |
| 4851 | |
| 4852 | /** |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4853 | * 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] | 4854 | * @param cb The component callback to notify of configuration change. |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4855 | * @param newConfig The new configuration. |
| 4856 | */ |
| 4857 | private void performConfigurationChanged(ComponentCallbacks2 cb, Configuration newConfig) { |
| 4858 | if (!REPORT_TO_ACTIVITY) { |
| 4859 | return; |
| 4860 | } |
| 4861 | |
| 4862 | // ContextThemeWrappers may override the configuration for that context. We must check and |
| 4863 | // apply any overrides defined. |
| 4864 | Configuration contextThemeWrapperOverrideConfig = null; |
| 4865 | if (cb instanceof ContextThemeWrapper) { |
| 4866 | final ContextThemeWrapper contextThemeWrapper = (ContextThemeWrapper) cb; |
| 4867 | contextThemeWrapperOverrideConfig = contextThemeWrapper.getOverrideConfiguration(); |
| 4868 | } |
| 4869 | |
| 4870 | // Apply the ContextThemeWrapper override if necessary. |
| 4871 | // NOTE: Make sure the configurations are not modified, as they are treated as immutable |
| 4872 | // in many places. |
| 4873 | final Configuration configToReport = createNewConfigAndUpdateIfNotNull( |
| 4874 | newConfig, contextThemeWrapperOverrideConfig); |
| 4875 | cb.onConfigurationChanged(configToReport); |
| 4876 | } |
| 4877 | |
| 4878 | /** |
| 4879 | * Decides whether to update an Activity's configuration and whether to inform it. |
| 4880 | * @param activity The activity to notify of configuration change. |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 4881 | * @param newConfig The new configuration. |
Adam Lesinski | c1b0ebf | 2016-06-09 11:17:10 -0700 | [diff] [blame] | 4882 | * @param amOverrideConfig The override config that differentiates the Activity's configuration |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4883 | * from the base global configuration. This is supplied by |
| 4884 | * ActivityManager. |
| 4885 | * @param displayId Id of the display where activity currently resides. |
| 4886 | * @param movedToDifferentDisplay Indicates if the activity was moved to different display. |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 4887 | * @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] | 4888 | */ |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 4889 | private Configuration performActivityConfigurationChanged(Activity activity, |
| 4890 | Configuration newConfig, Configuration amOverrideConfig, int displayId, |
| 4891 | boolean movedToDifferentDisplay) { |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4892 | if (activity == null) { |
| 4893 | throw new IllegalArgumentException("No activity provided."); |
| 4894 | } |
| 4895 | final IBinder activityToken = activity.getActivityToken(); |
| 4896 | if (activityToken == null) { |
| 4897 | 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] | 4898 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4899 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4900 | boolean shouldChangeConfig = false; |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4901 | if (activity.mCurrentConfig == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4902 | shouldChangeConfig = true; |
| 4903 | } else { |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4904 | // If the new config is the same as the config this Activity is already running with and |
| 4905 | // the override config also didn't change, then don't bother calling |
| 4906 | // onConfigurationChanged. |
Bryce Lee | 658d984 | 2017-07-28 08:33:36 -0700 | [diff] [blame] | 4907 | final int diff = activity.mCurrentConfig.diffPublicOnly(newConfig); |
| 4908 | |
Andrii Kulian | 3b3c914 | 2016-07-18 19:15:56 -0700 | [diff] [blame] | 4909 | if (diff != 0 || !mResourcesManager.isSameResourcesOverrideConfig(activityToken, |
| 4910 | amOverrideConfig)) { |
Chong Zhang | 4951f9d | 2016-06-23 13:15:08 -0700 | [diff] [blame] | 4911 | // Always send the task-level config changes. For system-level configuration, if |
| 4912 | // this activity doesn't handle any of the config changes, then don't bother |
| 4913 | // calling onConfigurationChanged as we're going to destroy it. |
| 4914 | if (!mUpdatingSystemConfig |
| 4915 | || (~activity.mActivityInfo.getRealConfigChanged() & diff) == 0 |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4916 | || !REPORT_TO_ACTIVITY) { |
Chong Zhang | 4951f9d | 2016-06-23 13:15:08 -0700 | [diff] [blame] | 4917 | shouldChangeConfig = true; |
| 4918 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4919 | } |
| 4920 | } |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4921 | if (!shouldChangeConfig && !movedToDifferentDisplay) { |
| 4922 | // Nothing significant, don't proceed with updating and reporting. |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 4923 | return null; |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4924 | } |
| 4925 | |
| 4926 | // Propagate the configuration change to ResourcesManager and Activity. |
| 4927 | |
| 4928 | // ContextThemeWrappers may override the configuration for that context. We must check and |
| 4929 | // apply any overrides defined. |
| 4930 | Configuration contextThemeWrapperOverrideConfig = activity.getOverrideConfiguration(); |
| 4931 | |
| 4932 | // We only update an Activity's configuration if this is not a global configuration change. |
| 4933 | // This must also be done before the callback, or else we violate the contract that the new |
| 4934 | // resources are available in ComponentCallbacks2#onConfigurationChanged(Configuration). |
| 4935 | // Also apply the ContextThemeWrapper override if necessary. |
| 4936 | // NOTE: Make sure the configurations are not modified, as they are treated as immutable in |
| 4937 | // many places. |
| 4938 | final Configuration finalOverrideConfig = createNewConfigAndUpdateIfNotNull( |
| 4939 | amOverrideConfig, contextThemeWrapperOverrideConfig); |
| 4940 | mResourcesManager.updateResourcesForActivity(activityToken, finalOverrideConfig, |
| 4941 | displayId, movedToDifferentDisplay); |
| 4942 | |
| 4943 | activity.mConfigChangeFlags = 0; |
| 4944 | activity.mCurrentConfig = new Configuration(newConfig); |
| 4945 | |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 4946 | // Apply the ContextThemeWrapper override if necessary. |
| 4947 | // NOTE: Make sure the configurations are not modified, as they are treated as immutable |
| 4948 | // in many places. |
| 4949 | final Configuration configToReport = createNewConfigAndUpdateIfNotNull(newConfig, |
| 4950 | contextThemeWrapperOverrideConfig); |
| 4951 | |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4952 | if (!REPORT_TO_ACTIVITY) { |
| 4953 | // Not configured to report to activity. |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 4954 | return configToReport; |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4955 | } |
| 4956 | |
| 4957 | if (movedToDifferentDisplay) { |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 4958 | activity.dispatchMovedToDisplay(displayId, configToReport); |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4959 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4960 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4961 | if (shouldChangeConfig) { |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4962 | activity.mCalled = false; |
| 4963 | activity.onConfigurationChanged(configToReport); |
| 4964 | if (!activity.mCalled) { |
| 4965 | throw new SuperNotCalledException("Activity " + activity.getLocalClassName() + |
| 4966 | " did not call through to super.onConfigurationChanged()"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4967 | } |
| 4968 | } |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 4969 | |
| 4970 | return configToReport; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4971 | } |
| 4972 | |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 4973 | public final void applyConfigurationToResources(Configuration config) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4974 | synchronized (mResourcesManager) { |
| 4975 | mResourcesManager.applyConfigurationToResourcesLocked(config, null); |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 4976 | } |
| 4977 | } |
| 4978 | |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 4979 | final Configuration applyCompatConfiguration(int displayDensity) { |
Dianne Hackborn | 836e262 | 2011-10-04 18:32:39 -0700 | [diff] [blame] | 4980 | Configuration config = mConfiguration; |
| 4981 | if (mCompatConfiguration == null) { |
| 4982 | mCompatConfiguration = new Configuration(); |
| 4983 | } |
| 4984 | mCompatConfiguration.setTo(mConfiguration); |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 4985 | if (mResourcesManager.applyCompatConfigurationLocked(displayDensity, |
| 4986 | mCompatConfiguration)) { |
Dianne Hackborn | 836e262 | 2011-10-04 18:32:39 -0700 | [diff] [blame] | 4987 | config = mCompatConfiguration; |
| 4988 | } |
| 4989 | return config; |
| 4990 | } |
| 4991 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 4992 | @Override |
| 4993 | public void handleConfigurationChanged(Configuration config) { |
| 4994 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "configChanged"); |
| 4995 | mCurDefaultDisplayDpi = config.densityDpi; |
| 4996 | mUpdatingSystemConfig = true; |
| 4997 | try { |
| 4998 | handleConfigurationChanged(config, null /* compat */); |
| 4999 | } finally { |
| 5000 | mUpdatingSystemConfig = false; |
| 5001 | } |
| 5002 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
| 5003 | } |
| 5004 | |
| 5005 | private void handleConfigurationChanged(Configuration config, CompatibilityInfo compat) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5006 | |
Fabrice Di Meglio | 30ca5cd | 2012-05-07 17:45:44 -0700 | [diff] [blame] | 5007 | int configDiff = 0; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5008 | |
Bryce Lee | 658d984 | 2017-07-28 08:33:36 -0700 | [diff] [blame] | 5009 | // This flag tracks whether the new configuration is fundamentally equivalent to the |
| 5010 | // existing configuration. This is necessary to determine whether non-activity |
| 5011 | // callbacks should receive notice when the only changes are related to non-public fields. |
| 5012 | // We do not gate calling {@link #performActivityConfigurationChanged} based on this flag |
| 5013 | // as that method uses the same check on the activity config override as well. |
| 5014 | final boolean equivalent = config != null && mConfiguration != null |
| 5015 | && (0 == mConfiguration.diffPublicOnly(config)); |
Todd Kennedy | 35a9a38 | 2018-01-25 13:25:37 -0800 | [diff] [blame] | 5016 | final Theme systemTheme = getSystemContext().getTheme(); |
| 5017 | final Theme systemUiTheme = getSystemUiContext().getTheme(); |
Bryce Lee | 658d984 | 2017-07-28 08:33:36 -0700 | [diff] [blame] | 5018 | |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 5019 | synchronized (mResourcesManager) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5020 | if (mPendingConfiguration != null) { |
| 5021 | if (!mPendingConfiguration.isOtherSeqNewer(config)) { |
| 5022 | config = mPendingConfiguration; |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 5023 | mCurDefaultDisplayDpi = config.densityDpi; |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 5024 | updateDefaultDensity(); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5025 | } |
| 5026 | mPendingConfiguration = null; |
| 5027 | } |
| 5028 | |
| 5029 | if (config == null) { |
| 5030 | return; |
| 5031 | } |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 5032 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 5033 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Handle configuration changed: " |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5034 | + config); |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 5035 | |
| 5036 | mResourcesManager.applyConfigurationToResourcesLocked(config, compat); |
Adam Lesinski | b61e405 | 2016-05-19 18:23:05 -0700 | [diff] [blame] | 5037 | updateLocaleListFromAppContext(mInitialApplication.getApplicationContext(), |
| 5038 | mResourcesManager.getConfiguration().getLocales()); |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 5039 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5040 | if (mConfiguration == null) { |
| 5041 | mConfiguration = new Configuration(); |
| 5042 | } |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 5043 | if (!mConfiguration.isOtherSeqNewer(config) && compat == null) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5044 | return; |
| 5045 | } |
Alan Viverette | e54d245 | 2015-05-06 10:41:43 -0700 | [diff] [blame] | 5046 | |
| 5047 | configDiff = mConfiguration.updateFrom(config); |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 5048 | config = applyCompatConfiguration(mCurDefaultDisplayDpi); |
Alan Viverette | 395cd01 | 2015-08-11 17:27:04 -0400 | [diff] [blame] | 5049 | |
Alan Viverette | 395cd01 | 2015-08-11 17:27:04 -0400 | [diff] [blame] | 5050 | if ((systemTheme.getChangingConfigurations() & configDiff) != 0) { |
| 5051 | systemTheme.rebase(); |
| 5052 | } |
Adam Lesinski | a82b626 | 2017-03-21 16:56:17 -0700 | [diff] [blame] | 5053 | |
Adam Lesinski | a82b626 | 2017-03-21 16:56:17 -0700 | [diff] [blame] | 5054 | if ((systemUiTheme.getChangingConfigurations() & configDiff) != 0) { |
| 5055 | systemUiTheme.rebase(); |
| 5056 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5057 | } |
Dianne Hackborn | 73c1416 | 2012-09-19 15:45:06 -0700 | [diff] [blame] | 5058 | |
| 5059 | ArrayList<ComponentCallbacks2> callbacks = collectComponentCallbacks(false, config); |
| 5060 | |
Fabrice Di Meglio | 30ca5cd | 2012-05-07 17:45:44 -0700 | [diff] [blame] | 5061 | freeTextLayoutCachesIfNeeded(configDiff); |
| 5062 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5063 | if (callbacks != null) { |
| 5064 | final int N = callbacks.size(); |
| 5065 | for (int i=0; i<N; i++) { |
Andrii Kulian | 701214b | 2016-04-07 09:36:33 -0700 | [diff] [blame] | 5066 | ComponentCallbacks2 cb = callbacks.get(i); |
| 5067 | if (cb instanceof Activity) { |
| 5068 | // If callback is an Activity - call corresponding method to consider override |
| 5069 | // config and avoid onConfigurationChanged if it hasn't changed. |
| 5070 | Activity a = (Activity) cb; |
| 5071 | performConfigurationChangedForActivity(mActivities.get(a.getActivityToken()), |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5072 | config); |
Bryce Lee | 658d984 | 2017-07-28 08:33:36 -0700 | [diff] [blame] | 5073 | } else if (!equivalent) { |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5074 | performConfigurationChanged(cb, config); |
Andrii Kulian | 701214b | 2016-04-07 09:36:33 -0700 | [diff] [blame] | 5075 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5076 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5077 | } |
| 5078 | } |
| 5079 | |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 5080 | void handleApplicationInfoChanged(@NonNull final ApplicationInfo ai) { |
Adam Lesinski | d33ef56 | 2017-01-19 14:49:59 -0800 | [diff] [blame] | 5081 | // Updates triggered by package installation go through a package update |
| 5082 | // receiver. Here we try to capture ApplicationInfo changes that are |
| 5083 | // caused by other sources, such as overlays. That means we want to be as conservative |
| 5084 | // about code changes as possible. Take the diff of the old ApplicationInfo and the new |
| 5085 | // to see if anything needs to change. |
Fyodor Kupolov | b7865ce | 2017-05-05 15:08:03 -0700 | [diff] [blame] | 5086 | LoadedApk apk; |
| 5087 | LoadedApk resApk; |
| 5088 | // Update all affected loaded packages with new package information |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 5089 | synchronized (mResourcesManager) { |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 5090 | WeakReference<LoadedApk> ref = mPackages.get(ai.packageName); |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 5091 | apk = ref != null ? ref.get() : null; |
Fyodor Kupolov | b7865ce | 2017-05-05 15:08:03 -0700 | [diff] [blame] | 5092 | ref = mResourcePackages.get(ai.packageName); |
| 5093 | resApk = ref != null ? ref.get() : null; |
| 5094 | } |
| 5095 | if (apk != null) { |
| 5096 | final ArrayList<String> oldPaths = new ArrayList<>(); |
| 5097 | LoadedApk.makePaths(this, apk.getApplicationInfo(), oldPaths); |
| 5098 | apk.updateApplicationInfo(ai, oldPaths); |
| 5099 | } |
| 5100 | if (resApk != null) { |
| 5101 | final ArrayList<String> oldPaths = new ArrayList<>(); |
| 5102 | LoadedApk.makePaths(this, resApk.getApplicationInfo(), oldPaths); |
| 5103 | resApk.updateApplicationInfo(ai, oldPaths); |
| 5104 | } |
| 5105 | synchronized (mResourcesManager) { |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 5106 | // Update all affected Resources objects to use new ResourcesImpl |
| 5107 | mResourcesManager.applyNewResourceDirsLocked(ai.sourceDir, ai.resourceDirs); |
| 5108 | } |
| 5109 | |
| 5110 | ApplicationPackageManager.configurationChanged(); |
| 5111 | |
| 5112 | // Trigger a regular Configuration change event, only with a different assetsSeq number |
| 5113 | // so that we actually call through to all components. |
Adam Lesinski | a82b626 | 2017-03-21 16:56:17 -0700 | [diff] [blame] | 5114 | // TODO(adamlesinski): Change this to make use of ActivityManager's upcoming ability to |
| 5115 | // store configurations per-process. |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 5116 | Configuration newConfig = new Configuration(); |
Adam Lesinski | a82b626 | 2017-03-21 16:56:17 -0700 | [diff] [blame] | 5117 | newConfig.assetsSeq = (mConfiguration != null ? mConfiguration.assetsSeq : 0) + 1; |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 5118 | handleConfigurationChanged(newConfig, null); |
| 5119 | |
Fyodor Kupolov | cb93d6f | 2017-05-04 17:27:16 -0700 | [diff] [blame] | 5120 | requestRelaunchAllActivities(); |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 5121 | } |
| 5122 | |
Romain Guy | 46bfc48 | 2013-08-16 18:38:29 -0700 | [diff] [blame] | 5123 | static void freeTextLayoutCachesIfNeeded(int configDiff) { |
Fabrice Di Meglio | 30ca5cd | 2012-05-07 17:45:44 -0700 | [diff] [blame] | 5124 | if (configDiff != 0) { |
| 5125 | // Ask text layout engine to free its caches if there is a locale change |
| 5126 | boolean hasLocaleConfigChange = ((configDiff & ActivityInfo.CONFIG_LOCALE) != 0); |
| 5127 | if (hasLocaleConfigChange) { |
| 5128 | Canvas.freeTextLayoutCaches(); |
| 5129 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Cleared TextLayout Caches"); |
| 5130 | } |
| 5131 | } |
| 5132 | } |
| 5133 | |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5134 | /** |
| 5135 | * Handle new activity configuration and/or move to a different display. |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 5136 | * @param activityToken Target activity token. |
| 5137 | * @param overrideConfig Activity override config. |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5138 | * @param displayId Id of the display where activity was moved to, -1 if there was no move and |
| 5139 | * value didn't change. |
| 5140 | */ |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 5141 | @Override |
| 5142 | public void handleActivityConfigurationChanged(IBinder activityToken, |
| 5143 | Configuration overrideConfig, int displayId) { |
| 5144 | ActivityClientRecord r = mActivities.get(activityToken); |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5145 | // Check input params. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5146 | if (r == null || r.activity == null) { |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5147 | 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] | 5148 | return; |
| 5149 | } |
Andrii Kulian | 51c1b67 | 2017-04-07 18:39:32 -0700 | [diff] [blame] | 5150 | final boolean movedToDifferentDisplay = displayId != INVALID_DISPLAY |
| 5151 | && displayId != r.activity.getDisplay().getDisplayId(); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 5152 | |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5153 | // Perform updates. |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 5154 | r.overrideConfig = overrideConfig; |
Stephen Kiazyk | f903b73 | 2017-03-20 16:23:45 -0700 | [diff] [blame] | 5155 | final ViewRootImpl viewRoot = r.activity.mDecor != null |
| 5156 | ? r.activity.mDecor.getViewRootImpl() : null; |
| 5157 | |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5158 | if (movedToDifferentDisplay) { |
| 5159 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Handle activity moved to display, activity:" |
| 5160 | + r.activityInfo.name + ", displayId=" + displayId |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 5161 | + ", config=" + overrideConfig); |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5162 | |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 5163 | final Configuration reportedConfig = performConfigurationChangedForActivity(r, |
| 5164 | mCompatConfiguration, displayId, true /* movedToDifferentDisplay */); |
Andrii Kulian | ce1ecf1 | 2017-03-17 14:58:36 -0700 | [diff] [blame] | 5165 | if (viewRoot != null) { |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 5166 | viewRoot.onMovedToDisplay(displayId, reportedConfig); |
Andrii Kulian | ce1ecf1 | 2017-03-17 14:58:36 -0700 | [diff] [blame] | 5167 | } |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5168 | } else { |
| 5169 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Handle activity config changed: " |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 5170 | + r.activityInfo.name + ", config=" + overrideConfig); |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5171 | performConfigurationChangedForActivity(r, mCompatConfiguration); |
| 5172 | } |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 5173 | // Notify the ViewRootImpl instance about configuration changes. It may have initiated this |
| 5174 | // update to make sure that resources are updated before updating itself. |
Andrii Kulian | ce1ecf1 | 2017-03-17 14:58:36 -0700 | [diff] [blame] | 5175 | if (viewRoot != null) { |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 5176 | viewRoot.updateConfiguration(displayId); |
Andrii Kulian | ce1ecf1 | 2017-03-17 14:58:36 -0700 | [diff] [blame] | 5177 | } |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 5178 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5179 | } |
| 5180 | |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 5181 | final void handleProfilerControl(boolean start, ProfilerInfo profilerInfo, int profileType) { |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 5182 | if (start) { |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 5183 | try { |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 5184 | switch (profileType) { |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 5185 | default: |
| 5186 | mProfiler.setProfiler(profilerInfo); |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 5187 | mProfiler.startProfiling(); |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 5188 | break; |
| 5189 | } |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 5190 | } catch (RuntimeException e) { |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 5191 | Slog.w(TAG, "Profiling failed on path " + profilerInfo.profileFile |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 5192 | + " -- can the process access this path?"); |
Dianne Hackborn | 9c8dd55 | 2009-06-23 19:22:52 -0700 | [diff] [blame] | 5193 | } finally { |
Andreas Gampe | 2b073a0 | 2017-06-22 17:28:57 -0700 | [diff] [blame] | 5194 | profilerInfo.closeFd(); |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 5195 | } |
| 5196 | } else { |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 5197 | switch (profileType) { |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 5198 | default: |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 5199 | mProfiler.stopProfiling(); |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 5200 | break; |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 5201 | } |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 5202 | } |
| 5203 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 5204 | |
Andreas Gampe | 4c79fea | 2016-01-28 20:11:41 -0800 | [diff] [blame] | 5205 | /** |
| 5206 | * Public entrypoint to stop profiling. This is required to end profiling when the app crashes, |
| 5207 | * so that profiler data won't be lost. |
| 5208 | * |
| 5209 | * @hide |
| 5210 | */ |
| 5211 | public void stopProfiling() { |
Amith Yamasani | b168443 | 2017-01-26 14:57:20 -0800 | [diff] [blame] | 5212 | if (mProfiler != null) { |
| 5213 | mProfiler.stopProfiling(); |
| 5214 | } |
Andreas Gampe | 4c79fea | 2016-01-28 20:11:41 -0800 | [diff] [blame] | 5215 | } |
| 5216 | |
Christopher Ferris | 8d652f8 | 2017-04-11 16:29:18 -0700 | [diff] [blame] | 5217 | static void handleDumpHeap(DumpHeapData dhd) { |
Makoto Onuki | 4556b7b | 2017-07-07 14:58:58 -0700 | [diff] [blame] | 5218 | if (dhd.runGc) { |
| 5219 | System.gc(); |
| 5220 | System.runFinalization(); |
| 5221 | System.gc(); |
| 5222 | } |
Christopher Ferris | 8d652f8 | 2017-04-11 16:29:18 -0700 | [diff] [blame] | 5223 | if (dhd.managed) { |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 5224 | try { |
| 5225 | Debug.dumpHprofData(dhd.path, dhd.fd.getFileDescriptor()); |
| 5226 | } catch (IOException e) { |
| 5227 | Slog.w(TAG, "Managed heap dump failed on path " + dhd.path |
| 5228 | + " -- can the process access this path?"); |
| 5229 | } finally { |
| 5230 | try { |
| 5231 | dhd.fd.close(); |
| 5232 | } catch (IOException e) { |
| 5233 | Slog.w(TAG, "Failure closing profile fd", e); |
| 5234 | } |
| 5235 | } |
Christopher Ferris | 8d652f8 | 2017-04-11 16:29:18 -0700 | [diff] [blame] | 5236 | } else if (dhd.mallocInfo) { |
| 5237 | Debug.dumpNativeMallocInfo(dhd.fd.getFileDescriptor()); |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 5238 | } else { |
Andy McFadden | 06a6b55 | 2010-07-13 16:28:09 -0700 | [diff] [blame] | 5239 | Debug.dumpNativeHeap(dhd.fd.getFileDescriptor()); |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 5240 | } |
Dianne Hackborn | b9a5e4a | 2015-03-03 17:04:12 -0800 | [diff] [blame] | 5241 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5242 | ActivityManager.getService().dumpHeapFinished(dhd.path); |
Dianne Hackborn | b9a5e4a | 2015-03-03 17:04:12 -0800 | [diff] [blame] | 5243 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5244 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | b9a5e4a | 2015-03-03 17:04:12 -0800 | [diff] [blame] | 5245 | } |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 5246 | } |
| 5247 | |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 5248 | final void handleDispatchPackageBroadcast(int cmd, String[] packages) { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5249 | boolean hasPkgInfo = false; |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5250 | switch (cmd) { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 5251 | case ApplicationThreadConstants.PACKAGE_REMOVED: |
| 5252 | case ApplicationThreadConstants.PACKAGE_REMOVED_DONT_KILL: |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5253 | { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 5254 | final boolean killApp = cmd == ApplicationThreadConstants.PACKAGE_REMOVED; |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5255 | if (packages == null) { |
| 5256 | break; |
| 5257 | } |
| 5258 | synchronized (mResourcesManager) { |
| 5259 | for (int i = packages.length - 1; i >= 0; i--) { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5260 | if (!hasPkgInfo) { |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5261 | WeakReference<LoadedApk> ref = mPackages.get(packages[i]); |
| 5262 | if (ref != null && ref.get() != null) { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5263 | hasPkgInfo = true; |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5264 | } else { |
| 5265 | ref = mResourcePackages.get(packages[i]); |
| 5266 | if (ref != null && ref.get() != null) { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5267 | hasPkgInfo = true; |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5268 | } |
| 5269 | } |
| 5270 | } |
| 5271 | if (killApp) { |
| 5272 | mPackages.remove(packages[i]); |
| 5273 | mResourcePackages.remove(packages[i]); |
| 5274 | } |
| 5275 | } |
| 5276 | } |
| 5277 | break; |
| 5278 | } |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 5279 | case ApplicationThreadConstants.PACKAGE_REPLACED: |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5280 | { |
| 5281 | if (packages == null) { |
| 5282 | break; |
| 5283 | } |
| 5284 | synchronized (mResourcesManager) { |
| 5285 | for (int i = packages.length - 1; i >= 0; i--) { |
| 5286 | WeakReference<LoadedApk> ref = mPackages.get(packages[i]); |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5287 | LoadedApk pkgInfo = ref != null ? ref.get() : null; |
| 5288 | if (pkgInfo != null) { |
| 5289 | hasPkgInfo = true; |
mark_chen | 89764e3 | 2014-12-12 15:38:48 +0800 | [diff] [blame] | 5290 | } else { |
| 5291 | ref = mResourcePackages.get(packages[i]); |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5292 | pkgInfo = ref != null ? ref.get() : null; |
| 5293 | if (pkgInfo != null) { |
| 5294 | hasPkgInfo = true; |
mark_chen | 89764e3 | 2014-12-12 15:38:48 +0800 | [diff] [blame] | 5295 | } |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 5296 | } |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5297 | // If the package is being replaced, yet it still has a valid |
| 5298 | // LoadedApk object, the package was updated with _DONT_KILL. |
| 5299 | // Adjust it's internal references to the application info and |
| 5300 | // resources. |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5301 | if (pkgInfo != null) { |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5302 | try { |
| 5303 | final String packageName = packages[i]; |
| 5304 | final ApplicationInfo aInfo = |
| 5305 | sPackageManager.getApplicationInfo( |
| 5306 | packageName, |
Svet Ganov | 6ce9239 | 2017-09-27 16:04:10 -0700 | [diff] [blame] | 5307 | PackageManager.GET_SHARED_LIBRARY_FILES, |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5308 | UserHandle.myUserId()); |
| 5309 | |
| 5310 | if (mActivities.size() > 0) { |
| 5311 | for (ActivityClientRecord ar : mActivities.values()) { |
| 5312 | if (ar.activityInfo.applicationInfo.packageName |
| 5313 | .equals(packageName)) { |
| 5314 | ar.activityInfo.applicationInfo = aInfo; |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5315 | ar.packageInfo = pkgInfo; |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5316 | } |
| 5317 | } |
| 5318 | } |
| 5319 | final List<String> oldPaths = |
| 5320 | sPackageManager.getPreviousCodePaths(packageName); |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5321 | pkgInfo.updateApplicationInfo(aInfo, oldPaths); |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5322 | } catch (RemoteException e) { |
| 5323 | } |
| 5324 | } |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 5325 | } |
| 5326 | } |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5327 | break; |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 5328 | } |
| 5329 | } |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5330 | ApplicationPackageManager.handlePackageBroadcast(cmd, packages, hasPkgInfo); |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 5331 | } |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 5332 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5333 | final void handleLowMemory() { |
Dianne Hackborn | 73c1416 | 2012-09-19 15:45:06 -0700 | [diff] [blame] | 5334 | ArrayList<ComponentCallbacks2> callbacks = collectComponentCallbacks(true, null); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 5335 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5336 | final int N = callbacks.size(); |
| 5337 | for (int i=0; i<N; i++) { |
| 5338 | callbacks.get(i).onLowMemory(); |
| 5339 | } |
| 5340 | |
Chris Tate | ce22905 | 2009-03-25 16:44:52 -0700 | [diff] [blame] | 5341 | // Ask SQLite to free up as much memory as it can, mostly from its page caches. |
| 5342 | if (Process.myUid() != Process.SYSTEM_UID) { |
| 5343 | int sqliteReleased = SQLiteDatabase.releaseMemory(); |
| 5344 | EventLog.writeEvent(SQLITE_MEM_RELEASED_EVENT_LOG_TAG, sqliteReleased); |
| 5345 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 5346 | |
Mike Reed | caf0df1 | 2009-04-27 14:32:05 -0400 | [diff] [blame] | 5347 | // Ask graphics to free up as much as possible (font/image caches) |
| 5348 | Canvas.freeCaches(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5349 | |
Fabrice Di Meglio | 30ca5cd | 2012-05-07 17:45:44 -0700 | [diff] [blame] | 5350 | // Ask text layout engine to free also as much as possible |
| 5351 | Canvas.freeTextLayoutCaches(); |
| 5352 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5353 | BinderInternal.forceGc("mem"); |
| 5354 | } |
| 5355 | |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 5356 | final void handleTrimMemory(int level) { |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 5357 | if (DEBUG_MEMORY_TRIM) Slog.v(TAG, "Trimming memory to level: " + level); |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 5358 | |
Dianne Hackborn | 73c1416 | 2012-09-19 15:45:06 -0700 | [diff] [blame] | 5359 | ArrayList<ComponentCallbacks2> callbacks = collectComponentCallbacks(true, null); |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 5360 | |
| 5361 | final int N = callbacks.size(); |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 5362 | for (int i = 0; i < N; i++) { |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 5363 | callbacks.get(i).onTrimMemory(level); |
| 5364 | } |
Romain Guy | 19f86e8 | 2012-04-23 15:19:07 -0700 | [diff] [blame] | 5365 | |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 5366 | WindowManagerGlobal.getInstance().trimMemory(level); |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 5367 | } |
| 5368 | |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 5369 | private void setupGraphicsSupport(Context context) { |
Andreas Gampe | 4c8e542 | 2016-05-18 11:58:47 -0700 | [diff] [blame] | 5370 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "setupGraphicsSupport"); |
Romain Guy | a958265 | 2011-11-10 14:20:10 -0800 | [diff] [blame] | 5371 | |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 5372 | // The system package doesn't have real data directories, so don't set up cache paths. |
| 5373 | if (!"android".equals(context.getPackageName())) { |
| 5374 | // This cache location probably points at credential-encrypted |
| 5375 | // storage which may not be accessible yet; assign it anyway instead |
| 5376 | // of pointing at device-encrypted storage. |
| 5377 | final File cacheDir = context.getCacheDir(); |
| 5378 | if (cacheDir != null) { |
| 5379 | // Provide a usable directory for temporary files |
| 5380 | System.setProperty("java.io.tmpdir", cacheDir.getAbsolutePath()); |
| 5381 | } else { |
| 5382 | Log.v(TAG, "Unable to initialize \"java.io.tmpdir\" property " |
| 5383 | + "due to missing cache directory"); |
Romain Guy | a958265 | 2011-11-10 14:20:10 -0800 | [diff] [blame] | 5384 | } |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 5385 | |
| 5386 | // Setup a location to store generated/compiled graphics code. |
| 5387 | final Context deviceContext = context.createDeviceProtectedStorageContext(); |
| 5388 | final File codeCacheDir = deviceContext.getCodeCacheDir(); |
| 5389 | if (codeCacheDir != null) { |
| 5390 | try { |
| 5391 | int uid = Process.myUid(); |
| 5392 | String[] packages = getPackageManager().getPackagesForUid(uid); |
| 5393 | if (packages != null) { |
Romain Guy | cecbe07 | 2017-07-18 15:42:06 -0700 | [diff] [blame] | 5394 | ThreadedRenderer.setupDiskCache(codeCacheDir); |
| 5395 | RenderScriptCacheDir.setupDiskCache(codeCacheDir); |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 5396 | } |
| 5397 | } catch (RemoteException e) { |
| 5398 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
| 5399 | throw e.rethrowFromSystemServer(); |
| 5400 | } |
| 5401 | } else { |
| 5402 | Log.w(TAG, "Unable to use shader/script cache: missing code-cache directory"); |
| 5403 | } |
Romain Guy | a958265 | 2011-11-10 14:20:10 -0800 | [diff] [blame] | 5404 | } |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 5405 | |
Cody Northrop | 86cedcb | 2017-10-20 09:03:13 -0600 | [diff] [blame] | 5406 | GraphicsEnvironment.getInstance().setup(context); |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 5407 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 5408 | } |
| 5409 | |
| 5410 | private void updateDefaultDensity() { |
Alan Viverette | 2ac46f1 | 2016-02-04 16:58:14 -0500 | [diff] [blame] | 5411 | final int densityDpi = mCurDefaultDisplayDpi; |
| 5412 | if (!mDensityCompatMode |
| 5413 | && densityDpi != Configuration.DENSITY_DPI_UNDEFINED |
| 5414 | && densityDpi != DisplayMetrics.DENSITY_DEVICE) { |
| 5415 | DisplayMetrics.DENSITY_DEVICE = densityDpi; |
| 5416 | Bitmap.setDefaultDensity(densityDpi); |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 5417 | } |
| 5418 | } |
| 5419 | |
Todd Kennedy | e713efc | 2016-05-10 13:45:40 -0700 | [diff] [blame] | 5420 | /** |
| 5421 | * Returns the correct library directory for the current ABI. |
| 5422 | * <p> |
| 5423 | * If we're dealing with a multi-arch application that has both 32 and 64 bit shared |
| 5424 | * libraries, we might need to choose the secondary depending on what the current |
| 5425 | * runtime's instruction set is. |
| 5426 | */ |
| 5427 | private String getInstrumentationLibrary(ApplicationInfo appInfo, InstrumentationInfo insInfo) { |
| 5428 | if (appInfo.primaryCpuAbi != null && appInfo.secondaryCpuAbi != null) { |
| 5429 | // Get the instruction set supported by the secondary ABI. In the presence |
| 5430 | // of a native bridge this might be different than the one secondary ABI used. |
| 5431 | String secondaryIsa = |
| 5432 | VMRuntime.getInstructionSet(appInfo.secondaryCpuAbi); |
| 5433 | final String secondaryDexCodeIsa = |
| 5434 | SystemProperties.get("ro.dalvik.vm.isa." + secondaryIsa); |
| 5435 | secondaryIsa = secondaryDexCodeIsa.isEmpty() ? secondaryIsa : secondaryDexCodeIsa; |
| 5436 | |
| 5437 | final String runtimeIsa = VMRuntime.getRuntime().vmInstructionSet(); |
| 5438 | if (runtimeIsa.equals(secondaryIsa)) { |
| 5439 | return insInfo.secondaryNativeLibraryDir; |
| 5440 | } |
| 5441 | } |
| 5442 | return insInfo.nativeLibraryDir; |
| 5443 | } |
| 5444 | |
Adam Lesinski | b61e405 | 2016-05-19 18:23:05 -0700 | [diff] [blame] | 5445 | /** |
| 5446 | * The LocaleList set for the app's resources may have been shuffled so that the preferred |
| 5447 | * Locale is at position 0. We must find the index of this preferred Locale in the |
| 5448 | * original LocaleList. |
| 5449 | */ |
| 5450 | private void updateLocaleListFromAppContext(Context context, LocaleList newLocaleList) { |
| 5451 | final Locale bestLocale = context.getResources().getConfiguration().getLocales().get(0); |
| 5452 | final int newLocaleListSize = newLocaleList.size(); |
| 5453 | for (int i = 0; i < newLocaleListSize; i++) { |
| 5454 | if (bestLocale.equals(newLocaleList.get(i))) { |
| 5455 | LocaleList.setDefault(newLocaleList, i); |
| 5456 | return; |
| 5457 | } |
| 5458 | } |
Adam Lesinski | 27d3016 | 2016-05-25 16:45:14 -0700 | [diff] [blame] | 5459 | |
| 5460 | // The app may have overridden the LocaleList with its own Locale |
| 5461 | // (not present in the available list). Push the chosen Locale |
| 5462 | // to the front of the list. |
| 5463 | LocaleList.setDefault(new LocaleList(bestLocale, newLocaleList)); |
Adam Lesinski | b61e405 | 2016-05-19 18:23:05 -0700 | [diff] [blame] | 5464 | } |
| 5465 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 5466 | private void handleBindApplication(AppBindData data) { |
Calin Juravle | 8f5770d | 2016-04-12 14:12:04 +0100 | [diff] [blame] | 5467 | // Register the UI Thread as a sensitive thread to the runtime. |
| 5468 | VMRuntime.registerSensitiveThread(); |
Man Cao | cfa78b2 | 2015-06-11 20:14:34 -0700 | [diff] [blame] | 5469 | if (data.trackAllocation) { |
| 5470 | DdmVmInternal.enableRecentAllocations(true); |
| 5471 | } |
| 5472 | |
Dianne Hackborn | d98885c | 2016-03-01 17:13:03 -0800 | [diff] [blame] | 5473 | // Note when this process has started. |
| 5474 | Process.setStartTimes(SystemClock.elapsedRealtime(), SystemClock.uptimeMillis()); |
| 5475 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5476 | mBoundApplication = data; |
| 5477 | mConfiguration = new Configuration(data.config); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 5478 | mCompatConfiguration = new Configuration(data.config); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5479 | |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 5480 | mProfiler = new Profiler(); |
Andreas Gampe | ab8a63b | 2018-01-05 13:55:15 -0800 | [diff] [blame] | 5481 | String agent = null; |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 5482 | if (data.initProfilerInfo != null) { |
| 5483 | mProfiler.profileFile = data.initProfilerInfo.profileFile; |
| 5484 | mProfiler.profileFd = data.initProfilerInfo.profileFd; |
| 5485 | mProfiler.samplingInterval = data.initProfilerInfo.samplingInterval; |
| 5486 | mProfiler.autoStopProfiler = data.initProfilerInfo.autoStopProfiler; |
Shukang Zhou | 6ffd4f9 | 2017-01-25 16:07:57 -0800 | [diff] [blame] | 5487 | mProfiler.streamingOutput = data.initProfilerInfo.streamingOutput; |
Andreas Gampe | ab8a63b | 2018-01-05 13:55:15 -0800 | [diff] [blame] | 5488 | if (data.initProfilerInfo.attachAgentDuringBind) { |
| 5489 | agent = data.initProfilerInfo.agent; |
| 5490 | } |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 5491 | } |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 5492 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5493 | // send up app name; do this *before* waiting for debugger |
Christopher Tate | 8ee038d | 2009-11-06 11:30:20 -0800 | [diff] [blame] | 5494 | Process.setArgV0(data.processName); |
Siva Velusamy | d693dfa | 2012-09-10 14:36:58 -0700 | [diff] [blame] | 5495 | android.ddm.DdmHandleAppName.setAppName(data.processName, |
| 5496 | UserHandle.myUserId()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5497 | |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 5498 | if (mProfiler.profileFd != null) { |
| 5499 | mProfiler.startProfiling(); |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 5500 | } |
| 5501 | |
Joe Onorato | d630f10 | 2011-03-17 18:42:26 -0700 | [diff] [blame] | 5502 | // If the app is Honeycomb MR1 or earlier, switch its AsyncTask |
| 5503 | // implementation to use the pool executor. Normally, we use the |
| 5504 | // serialized executor as the default. This has to happen in the |
| 5505 | // main thread so the main looper is set right. |
Dianne Hackborn | 81e9276 | 2011-10-09 16:00:21 -0700 | [diff] [blame] | 5506 | if (data.appInfo.targetSdkVersion <= android.os.Build.VERSION_CODES.HONEYCOMB_MR1) { |
Joe Onorato | d630f10 | 2011-03-17 18:42:26 -0700 | [diff] [blame] | 5507 | AsyncTask.setDefaultExecutor(AsyncTask.THREAD_POOL_EXECUTOR); |
| 5508 | } |
| 5509 | |
Dianne Hackborn | 7895bc2 | 2014-09-05 15:09:03 -0700 | [diff] [blame] | 5510 | Message.updateCheckRecycle(data.appInfo.targetSdkVersion); |
| 5511 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5512 | /* |
| 5513 | * Before spawning a new process, reset the time zone to be the system time zone. |
| 5514 | * This needs to be done because the system time zone could have changed after the |
| 5515 | * the spawning of this process. Without doing this this process would have the incorrect |
| 5516 | * system time zone. |
| 5517 | */ |
| 5518 | TimeZone.setDefault(null); |
| 5519 | |
Adam Lesinski | b61e405 | 2016-05-19 18:23:05 -0700 | [diff] [blame] | 5520 | /* |
| 5521 | * Set the LocaleList. This may change once we create the App Context. |
| 5522 | */ |
| 5523 | LocaleList.setDefault(data.config.getLocales()); |
| 5524 | |
| 5525 | synchronized (mResourcesManager) { |
| 5526 | /* |
| 5527 | * Update the system configuration since its preloaded and might not |
| 5528 | * reflect configuration changes. The configuration object passed |
| 5529 | * in AppBindData can be safely assumed to be up to date |
| 5530 | */ |
| 5531 | mResourcesManager.applyConfigurationToResourcesLocked(data.config, data.compatInfo); |
| 5532 | mCurDefaultDisplayDpi = data.config.densityDpi; |
| 5533 | |
| 5534 | // This calls mResourcesManager so keep it within the synchronized block. |
| 5535 | applyCompatConfiguration(mCurDefaultDisplayDpi); |
| 5536 | } |
| 5537 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5538 | data.info = getPackageInfoNoCheck(data.appInfo, data.compatInfo); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5539 | |
Andreas Gampe | ab8a63b | 2018-01-05 13:55:15 -0800 | [diff] [blame] | 5540 | if (agent != null) { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5541 | handleAttachAgent(agent, data.info); |
Andreas Gampe | ab8a63b | 2018-01-05 13:55:15 -0800 | [diff] [blame] | 5542 | } |
| 5543 | |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 5544 | /** |
| 5545 | * Switch this process to density compatibility mode if needed. |
| 5546 | */ |
| 5547 | if ((data.appInfo.flags&ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES) |
| 5548 | == 0) { |
| 5549 | mDensityCompatMode = true; |
| 5550 | Bitmap.setDefaultDensity(DisplayMetrics.DENSITY_DEFAULT); |
| 5551 | } |
| 5552 | updateDefaultDensity(); |
| 5553 | |
Neil Fuller | c66ec40 | 2016-11-14 16:06:42 +0000 | [diff] [blame] | 5554 | final String use24HourSetting = mCoreSettings.getString(Settings.System.TIME_12_24); |
| 5555 | Boolean is24Hr = null; |
| 5556 | if (use24HourSetting != null) { |
| 5557 | is24Hr = "24".equals(use24HourSetting) ? Boolean.TRUE : Boolean.FALSE; |
| 5558 | } |
| 5559 | // null : use locale default for 12/24 hour formatting, |
| 5560 | // false : use 12 hour format, |
| 5561 | // true : use 24 hour format. |
Narayan Kamath | ccb2a086 | 2013-12-19 14:49:36 +0000 | [diff] [blame] | 5562 | DateFormat.set24HourTimePref(is24Hr); |
| 5563 | |
Jon Miranda | 836c0a8 | 2014-08-11 12:32:26 -0700 | [diff] [blame] | 5564 | View.mDebugViewAttributes = |
| 5565 | mCoreSettings.getInt(Settings.Global.DEBUG_VIEW_ATTRIBUTES, 0) != 0; |
| 5566 | |
Jeff Sharkey | 8918298 | 2017-11-01 19:02:56 -0600 | [diff] [blame] | 5567 | StrictMode.initThreadDefaults(data.appInfo); |
| 5568 | StrictMode.initVmDefaults(data.appInfo); |
Jeff Sharkey | 344744b | 2016-01-28 19:03:30 -0700 | [diff] [blame] | 5569 | |
Svet Ganov | 37e4327 | 2016-09-09 16:01:32 -0700 | [diff] [blame] | 5570 | // We deprecated Build.SERIAL and only apps that target pre NMR1 |
| 5571 | // SDK can see it. Since access to the serial is now behind a |
| 5572 | // permission we push down the value and here we fix it up |
| 5573 | // before any app code has been loaded. |
| 5574 | try { |
| 5575 | Field field = Build.class.getDeclaredField("SERIAL"); |
| 5576 | field.setAccessible(true); |
| 5577 | field.set(Build.class, data.buildSerial); |
| 5578 | } catch (NoSuchFieldException | IllegalAccessException e) { |
| 5579 | /* ignore */ |
| 5580 | } |
| 5581 | |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 5582 | if (data.debugMode != ApplicationThreadConstants.DEBUG_OFF) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5583 | // XXX should have option to change the port. |
| 5584 | Debug.changeDebugPort(8100); |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 5585 | if (data.debugMode == ApplicationThreadConstants.DEBUG_WAIT) { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5586 | Slog.w(TAG, "Application " + data.info.getPackageName() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5587 | + " is waiting for the debugger on port 8100..."); |
| 5588 | |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5589 | IActivityManager mgr = ActivityManager.getService(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5590 | try { |
| 5591 | mgr.showWaitingForDebugger(mAppThread, true); |
| 5592 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5593 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5594 | } |
| 5595 | |
| 5596 | Debug.waitForDebugger(); |
| 5597 | |
| 5598 | try { |
| 5599 | mgr.showWaitingForDebugger(mAppThread, false); |
| 5600 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5601 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5602 | } |
| 5603 | |
| 5604 | } else { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5605 | Slog.w(TAG, "Application " + data.info.getPackageName() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5606 | + " can be debugged on port 8100..."); |
| 5607 | } |
| 5608 | } |
| 5609 | |
Jamie Gennis | f9c7d6b | 2013-03-25 14:18:25 -0700 | [diff] [blame] | 5610 | // Allow application-generated systrace messages if we're debuggable. |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 5611 | boolean isAppDebuggable = (data.appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0; |
| 5612 | Trace.setAppTracingAllowed(isAppDebuggable); |
| 5613 | if (isAppDebuggable && data.enableBinderTracking) { |
| 5614 | Binder.enableTracing(); |
| 5615 | } |
Jamie Gennis | f9c7d6b | 2013-03-25 14:18:25 -0700 | [diff] [blame] | 5616 | |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 5617 | /** |
| 5618 | * Initialize the default http proxy in this process for the reasons we set the time zone. |
| 5619 | */ |
Andreas Gampe | 4c8e542 | 2016-05-18 11:58:47 -0700 | [diff] [blame] | 5620 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "Setup proxies"); |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 5621 | final IBinder b = ServiceManager.getService(Context.CONNECTIVITY_SERVICE); |
Dianne Hackborn | d4d32c5 | 2011-11-08 17:33:59 -0800 | [diff] [blame] | 5622 | if (b != null) { |
| 5623 | // In pre-boot mode (doing initial launch to collect password), not |
| 5624 | // all system is up. This includes the connectivity service, so don't |
| 5625 | // crash if we can't get it. |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 5626 | final IConnectivityManager service = IConnectivityManager.Stub.asInterface(b); |
Dianne Hackborn | d4d32c5 | 2011-11-08 17:33:59 -0800 | [diff] [blame] | 5627 | try { |
Paul Jensen | cee9b51 | 2015-05-06 07:32:40 -0400 | [diff] [blame] | 5628 | final ProxyInfo proxyInfo = service.getProxyForNetwork(null); |
Jason Monk | 207900c | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 5629 | Proxy.setHttpProxySystemProperty(proxyInfo); |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5630 | } catch (RemoteException e) { |
Andreas Gampe | 4c8e542 | 2016-05-18 11:58:47 -0700 | [diff] [blame] | 5631 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5632 | throw e.rethrowFromSystemServer(); |
| 5633 | } |
Dianne Hackborn | d4d32c5 | 2011-11-08 17:33:59 -0800 | [diff] [blame] | 5634 | } |
Andreas Gampe | 4c8e542 | 2016-05-18 11:58:47 -0700 | [diff] [blame] | 5635 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 5636 | |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 5637 | // Instrumentation info affects the class loader, so load it before |
| 5638 | // setting up the app context. |
| 5639 | final InstrumentationInfo ii; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5640 | if (data.instrumentationName != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5641 | try { |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 5642 | ii = new ApplicationPackageManager(null, getPackageManager()) |
| 5643 | .getInstrumentationInfo(data.instrumentationName, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5644 | } catch (PackageManager.NameNotFoundException e) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5645 | throw new RuntimeException( |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 5646 | "Unable to find instrumentation info for: " + data.instrumentationName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5647 | } |
| 5648 | |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 5649 | mInstrumentationPackageName = ii.packageName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5650 | mInstrumentationAppDir = ii.sourceDir; |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 5651 | mInstrumentationSplitAppDirs = ii.splitSourceDirs; |
Todd Kennedy | e713efc | 2016-05-10 13:45:40 -0700 | [diff] [blame] | 5652 | mInstrumentationLibDir = getInstrumentationLibrary(data.appInfo, ii); |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5653 | mInstrumentedAppDir = data.info.getAppDir(); |
| 5654 | mInstrumentedSplitAppDirs = data.info.getSplitAppDirs(); |
| 5655 | mInstrumentedLibDir = data.info.getLibDir(); |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 5656 | } else { |
| 5657 | ii = null; |
| 5658 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5659 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5660 | final ContextImpl appContext = ContextImpl.createAppContext(this, data.info); |
Adam Lesinski | b61e405 | 2016-05-19 18:23:05 -0700 | [diff] [blame] | 5661 | updateLocaleListFromAppContext(appContext, |
| 5662 | mResourcesManager.getConfiguration().getLocales()); |
Seigo Nonaka | c14dd78 | 2016-03-30 23:09:16 +0900 | [diff] [blame] | 5663 | |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 5664 | if (!Process.isIsolated()) { |
Jeff Sharkey | 8918298 | 2017-11-01 19:02:56 -0600 | [diff] [blame] | 5665 | final int oldMask = StrictMode.allowThreadDiskWritesMask(); |
| 5666 | try { |
| 5667 | setupGraphicsSupport(appContext); |
| 5668 | } finally { |
| 5669 | StrictMode.setThreadPolicyMask(oldMask); |
| 5670 | } |
Michael Lentine | 2ba303f | 2016-02-01 20:44:34 -0600 | [diff] [blame] | 5671 | } |
Michael Lentine | 03d8f768 | 2016-01-31 15:37:11 -0600 | [diff] [blame] | 5672 | |
Calin Juravle | 37dfc8e | 2017-03-13 19:02:32 -0700 | [diff] [blame] | 5673 | // If we use profiles, setup the dex reporter to notify package manager |
| 5674 | // of any relevant dex loads. The idle maintenance job will use the information |
| 5675 | // reported to optimize the loaded dex files. |
| 5676 | // Note that we only need one global reporter per app. |
| 5677 | // Make sure we do this before calling onCreate so that we can capture the |
| 5678 | // complete application startup. |
| 5679 | if (SystemProperties.getBoolean("dalvik.vm.usejitprofiles", false)) { |
Calin Juravle | f5a7bfc | 2017-03-13 23:30:30 -0700 | [diff] [blame] | 5680 | BaseDexClassLoader.setReporter(DexLoadReporter.getInstance()); |
Calin Juravle | 37dfc8e | 2017-03-13 19:02:32 -0700 | [diff] [blame] | 5681 | } |
| 5682 | |
Chad Brubaker | 78d4712 | 2015-11-17 22:26:58 -0800 | [diff] [blame] | 5683 | // Install the Network Security Config Provider. This must happen before the application |
| 5684 | // code is loaded to prevent issues with instances of TLS objects being created before |
| 5685 | // the provider is installed. |
Andreas Gampe | 4c8e542 | 2016-05-18 11:58:47 -0700 | [diff] [blame] | 5686 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "NetworkSecurityConfigProvider.install"); |
Chad Brubaker | 276ee96 | 2016-06-08 12:57:46 -0700 | [diff] [blame] | 5687 | NetworkSecurityConfigProvider.install(appContext); |
Andreas Gampe | 4c8e542 | 2016-05-18 11:58:47 -0700 | [diff] [blame] | 5688 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Chad Brubaker | 78d4712 | 2015-11-17 22:26:58 -0800 | [diff] [blame] | 5689 | |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 5690 | // Continue loading instrumentation. |
| 5691 | if (ii != null) { |
Dianne Hackborn | f4ef6eb | 2017-12-07 13:57:21 -0800 | [diff] [blame] | 5692 | ApplicationInfo instrApp; |
| 5693 | try { |
| 5694 | instrApp = getPackageManager().getApplicationInfo(ii.packageName, 0, |
| 5695 | UserHandle.myUserId()); |
| 5696 | } catch (RemoteException e) { |
| 5697 | instrApp = null; |
| 5698 | } |
| 5699 | if (instrApp == null) { |
| 5700 | instrApp = new ApplicationInfo(); |
| 5701 | } |
Jeff Sharkey | 1544779 | 2015-11-05 16:18:51 -0800 | [diff] [blame] | 5702 | ii.copyTo(instrApp); |
Fyodor Kupolov | af38b8e | 2015-12-02 16:16:07 -0800 | [diff] [blame] | 5703 | instrApp.initForUser(UserHandle.myUserId()); |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5704 | final LoadedApk pi = getPackageInfo(instrApp, data.compatInfo, |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 5705 | appContext.getClassLoader(), false, true, false); |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5706 | final ContextImpl instrContext = ContextImpl.createAppContext(this, pi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5707 | |
| 5708 | try { |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 5709 | final ClassLoader cl = instrContext.getClassLoader(); |
Dan Sandler | 07fe63e | 2017-08-15 16:41:11 -0400 | [diff] [blame] | 5710 | mInstrumentation = (Instrumentation) |
| 5711 | cl.loadClass(data.instrumentationName.getClassName()).newInstance(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5712 | } catch (Exception e) { |
| 5713 | throw new RuntimeException( |
| 5714 | "Unable to instantiate instrumentation " |
| 5715 | + data.instrumentationName + ": " + e.toString(), e); |
| 5716 | } |
| 5717 | |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 5718 | final ComponentName component = new ComponentName(ii.packageName, ii.name); |
| 5719 | mInstrumentation.init(this, instrContext, appContext, component, |
| 5720 | data.instrumentationWatcher, data.instrumentationUiAutomationConnection); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5721 | |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 5722 | if (mProfiler.profileFile != null && !ii.handleProfiling |
| 5723 | && mProfiler.profileFd == null) { |
| 5724 | mProfiler.handlingProfiling = true; |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 5725 | final File file = new File(mProfiler.profileFile); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5726 | file.getParentFile().mkdirs(); |
| 5727 | Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024); |
| 5728 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5729 | } else { |
| 5730 | mInstrumentation = new Instrumentation(); |
Jason Monk | a80bfb5 | 2017-11-16 17:15:37 -0500 | [diff] [blame] | 5731 | mInstrumentation.basicInit(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5732 | } |
| 5733 | |
Dianne Hackborn | 3b81bc1 | 2011-01-15 11:50:52 -0800 | [diff] [blame] | 5734 | if ((data.appInfo.flags&ApplicationInfo.FLAG_LARGE_HEAP) != 0) { |
Dianne Hackborn | de39851 | 2011-01-18 18:45:21 -0800 | [diff] [blame] | 5735 | dalvik.system.VMRuntime.getRuntime().clearGrowthLimit(); |
Mathieu Chartier | 24cee07 | 2015-01-08 14:42:20 -0800 | [diff] [blame] | 5736 | } else { |
| 5737 | // Small heap, clamp to the current growth limit and let the heap release |
| 5738 | // pages after the growth limit to the non growth limit capacity. b/18387825 |
| 5739 | dalvik.system.VMRuntime.getRuntime().clampGrowthLimit(); |
Dianne Hackborn | 3b81bc1 | 2011-01-15 11:50:52 -0800 | [diff] [blame] | 5740 | } |
| 5741 | |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 5742 | // Allow disk access during application and provider setup. This could |
Jeff Sharkey | 7c50167 | 2012-02-28 12:08:37 -0800 | [diff] [blame] | 5743 | // block processing ordered broadcasts, but later processing would |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 5744 | // probably end up doing the same disk access. |
Kurt Nelson | 5e15436 | 2017-06-29 17:20:56 -0700 | [diff] [blame] | 5745 | Application app; |
Jeff Sharkey | 7c50167 | 2012-02-28 12:08:37 -0800 | [diff] [blame] | 5746 | final StrictMode.ThreadPolicy savedPolicy = StrictMode.allowThreadDiskWrites(); |
Kurt Nelson | 571c3f6 | 2017-07-10 11:09:04 -0700 | [diff] [blame] | 5747 | final StrictMode.ThreadPolicy writesAllowedPolicy = StrictMode.getThreadPolicy(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5748 | try { |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 5749 | // If the app is being launched for full backup or restore, bring it up in |
| 5750 | // a restricted environment with the base application class. |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5751 | app = data.info.makeApplication(data.restrictedBackupMode, null); |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 5752 | |
| 5753 | // Propagate autofill compat state |
| 5754 | app.setAutofillCompatibilityEnabled(data.autofillCompatibilityEnabled); |
| 5755 | |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 5756 | mInitialApplication = app; |
Jeff Sharkey | 7c50167 | 2012-02-28 12:08:37 -0800 | [diff] [blame] | 5757 | |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 5758 | // don't bring up providers in restricted mode; they may depend on the |
| 5759 | // app's custom Application class |
| 5760 | if (!data.restrictedBackupMode) { |
Jeff Sharkey | 3e19589 | 2016-03-05 19:48:59 -0700 | [diff] [blame] | 5761 | if (!ArrayUtils.isEmpty(data.providers)) { |
| 5762 | installContentProviders(app, data.providers); |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 5763 | // For process that contains content providers, we want to |
| 5764 | // ensure that the JIT is enabled "at some point". |
| 5765 | mH.sendEmptyMessageDelayed(H.ENABLE_JIT, 10*1000); |
| 5766 | } |
| 5767 | } |
| 5768 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5769 | // Do this after providers, since instrumentation tests generally start their |
| 5770 | // test thread at this point, and we don't want that racing. |
| 5771 | try { |
| 5772 | mInstrumentation.onCreate(data.instrumentationArgs); |
| 5773 | } |
| 5774 | catch (Exception e) { |
| 5775 | throw new RuntimeException( |
| 5776 | "Exception thrown in onCreate() of " |
| 5777 | + data.instrumentationName + ": " + e.toString(), e); |
| 5778 | } |
Kurt Nelson | 571c3f6 | 2017-07-10 11:09:04 -0700 | [diff] [blame] | 5779 | try { |
| 5780 | mInstrumentation.callApplicationOnCreate(app); |
| 5781 | } catch (Exception e) { |
| 5782 | if (!mInstrumentation.onException(app, e)) { |
| 5783 | throw new RuntimeException( |
| 5784 | "Unable to create application " + app.getClass().getName() |
| 5785 | + ": " + e.toString(), e); |
| 5786 | } |
| 5787 | } |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 5788 | } finally { |
Kurt Nelson | 571c3f6 | 2017-07-10 11:09:04 -0700 | [diff] [blame] | 5789 | // If the app targets < O-MR1, or doesn't change the thread policy |
| 5790 | // during startup, clobber the policy to maintain behavior of b/36951662 |
| 5791 | if (data.appInfo.targetSdkVersion <= Build.VERSION_CODES.O |
| 5792 | || StrictMode.getThreadPolicy().equals(writesAllowedPolicy)) { |
| 5793 | StrictMode.setThreadPolicy(savedPolicy); |
Kurt Nelson | 5e15436 | 2017-06-29 17:20:56 -0700 | [diff] [blame] | 5794 | } |
| 5795 | } |
| 5796 | |
Clara Bayarri | 4b5a4d2 | 2017-01-27 20:15:45 +0000 | [diff] [blame] | 5797 | // Preload fonts resources |
Seigo Nonaka | 54084b6 | 2017-04-24 14:46:23 -0700 | [diff] [blame] | 5798 | FontsContract.setApplicationContextForResources(appContext); |
Torne (Richard Coles) | 85ecae5 | 2018-01-30 18:13:00 -0500 | [diff] [blame] | 5799 | if (!Process.isIsolated()) { |
| 5800 | try { |
| 5801 | final ApplicationInfo info = |
| 5802 | getPackageManager().getApplicationInfo( |
| 5803 | data.appInfo.packageName, |
| 5804 | PackageManager.GET_META_DATA /*flags*/, |
| 5805 | UserHandle.myUserId()); |
| 5806 | if (info.metaData != null) { |
| 5807 | final int preloadedFontsResource = info.metaData.getInt( |
| 5808 | ApplicationInfo.METADATA_PRELOADED_FONTS, 0); |
| 5809 | if (preloadedFontsResource != 0) { |
| 5810 | data.info.getResources().preloadFonts(preloadedFontsResource); |
| 5811 | } |
Clara Bayarri | 4b5a4d2 | 2017-01-27 20:15:45 +0000 | [diff] [blame] | 5812 | } |
Torne (Richard Coles) | 85ecae5 | 2018-01-30 18:13:00 -0500 | [diff] [blame] | 5813 | } catch (RemoteException e) { |
| 5814 | throw e.rethrowFromSystemServer(); |
Clara Bayarri | 4b5a4d2 | 2017-01-27 20:15:45 +0000 | [diff] [blame] | 5815 | } |
Clara Bayarri | 4b5a4d2 | 2017-01-27 20:15:45 +0000 | [diff] [blame] | 5816 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5817 | } |
| 5818 | |
| 5819 | /*package*/ final void finishInstrumentation(int resultCode, Bundle results) { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5820 | IActivityManager am = ActivityManager.getService(); |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 5821 | if (mProfiler.profileFile != null && mProfiler.handlingProfiling |
| 5822 | && mProfiler.profileFd == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5823 | Debug.stopMethodTracing(); |
| 5824 | } |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5825 | //Slog.i(TAG, "am: " + ActivityManager.getService() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5826 | // + ", app thr: " + mAppThread); |
| 5827 | try { |
| 5828 | am.finishInstrumentation(mAppThread, resultCode, results); |
| 5829 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5830 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5831 | } |
| 5832 | } |
| 5833 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 5834 | private void installContentProviders( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5835 | Context context, List<ProviderInfo> providers) { |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 5836 | final ArrayList<ContentProviderHolder> results = new ArrayList<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5837 | |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 5838 | for (ProviderInfo cpi : providers) { |
Dianne Hackborn | 40e9f29 | 2012-11-27 19:12:23 -0800 | [diff] [blame] | 5839 | if (DEBUG_PROVIDER) { |
| 5840 | StringBuilder buf = new StringBuilder(128); |
| 5841 | buf.append("Pub "); |
| 5842 | buf.append(cpi.authority); |
| 5843 | buf.append(": "); |
| 5844 | buf.append(cpi.name); |
| 5845 | Log.i(TAG, buf.toString()); |
| 5846 | } |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 5847 | ContentProviderHolder cph = installProvider(context, null, cpi, |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5848 | false /*noisy*/, true /*noReleaseNeeded*/, true /*stable*/); |
| 5849 | if (cph != null) { |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5850 | cph.noReleaseNeeded = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5851 | results.add(cph); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5852 | } |
| 5853 | } |
| 5854 | |
| 5855 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5856 | ActivityManager.getService().publishContentProviders( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5857 | getApplicationThread(), results); |
| 5858 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5859 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5860 | } |
| 5861 | } |
| 5862 | |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 5863 | public final IContentProvider acquireProvider( |
| 5864 | Context c, String auth, int userId, boolean stable) { |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 5865 | final IContentProvider provider = acquireExistingProvider(c, auth, userId, stable); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5866 | if (provider != null) { |
| 5867 | return provider; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5868 | } |
| 5869 | |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 5870 | // There is a possible race here. Another thread may try to acquire |
| 5871 | // the same provider at the same time. When this happens, we want to ensure |
| 5872 | // that the first one wins. |
| 5873 | // Note that we cannot hold the lock while acquiring and installing the |
| 5874 | // provider since it might take a long time to run and it could also potentially |
| 5875 | // 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] | 5876 | ContentProviderHolder holder = null; |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 5877 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5878 | holder = ActivityManager.getService().getContentProvider( |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 5879 | getApplicationThread(), auth, userId, stable); |
| 5880 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5881 | throw ex.rethrowFromSystemServer(); |
Wale Ogunwale | 67fe0a4 | 2015-04-24 14:44:54 -0700 | [diff] [blame] | 5882 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5883 | if (holder == null) { |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 5884 | 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] | 5885 | return null; |
| 5886 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5887 | |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5888 | // Install provider will increment the reference count for us, and break |
| 5889 | // any ties in the race. |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5890 | holder = installProvider(c, holder, holder.info, |
| 5891 | true /*noisy*/, holder.noReleaseNeeded, stable); |
| 5892 | return holder.provider; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5893 | } |
| 5894 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5895 | private final void incProviderRefLocked(ProviderRefCount prc, boolean stable) { |
| 5896 | if (stable) { |
| 5897 | prc.stableCount += 1; |
| 5898 | if (prc.stableCount == 1) { |
| 5899 | // We are acquiring a new stable reference on the provider. |
| 5900 | int unstableDelta; |
| 5901 | if (prc.removePending) { |
| 5902 | // We have a pending remove operation, which is holding the |
| 5903 | // last unstable reference. At this point we are converting |
| 5904 | // that unstable reference to our new stable reference. |
| 5905 | unstableDelta = -1; |
| 5906 | // Cancel the removal of the provider. |
| 5907 | if (DEBUG_PROVIDER) { |
| 5908 | Slog.v(TAG, "incProviderRef: stable " |
| 5909 | + "snatched provider from the jaws of death"); |
| 5910 | } |
| 5911 | prc.removePending = false; |
Guobin Zhang | 9e3e5266 | 2013-03-21 13:57:11 +0800 | [diff] [blame] | 5912 | // There is a race! It fails to remove the message, which |
| 5913 | // will be handled in completeRemoveProvider(). |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5914 | mH.removeMessages(H.REMOVE_PROVIDER, prc); |
| 5915 | } else { |
| 5916 | unstableDelta = 0; |
| 5917 | } |
| 5918 | try { |
| 5919 | if (DEBUG_PROVIDER) { |
| 5920 | Slog.v(TAG, "incProviderRef Now stable - " |
| 5921 | + prc.holder.info.name + ": unstableDelta=" |
| 5922 | + unstableDelta); |
| 5923 | } |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5924 | ActivityManager.getService().refContentProvider( |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5925 | prc.holder.connection, 1, unstableDelta); |
| 5926 | } catch (RemoteException e) { |
| 5927 | //do nothing content provider object is dead any way |
| 5928 | } |
| 5929 | } |
| 5930 | } else { |
| 5931 | prc.unstableCount += 1; |
| 5932 | if (prc.unstableCount == 1) { |
| 5933 | // We are acquiring a new unstable reference on the provider. |
| 5934 | if (prc.removePending) { |
| 5935 | // Oh look, we actually have a remove pending for the |
| 5936 | // provider, which is still holding the last unstable |
| 5937 | // reference. We just need to cancel that to take new |
| 5938 | // ownership of the reference. |
| 5939 | if (DEBUG_PROVIDER) { |
| 5940 | Slog.v(TAG, "incProviderRef: unstable " |
| 5941 | + "snatched provider from the jaws of death"); |
| 5942 | } |
| 5943 | prc.removePending = false; |
| 5944 | mH.removeMessages(H.REMOVE_PROVIDER, prc); |
| 5945 | } else { |
| 5946 | // First unstable ref, increment our count in the |
| 5947 | // activity manager. |
| 5948 | try { |
| 5949 | if (DEBUG_PROVIDER) { |
| 5950 | Slog.v(TAG, "incProviderRef: Now unstable - " |
| 5951 | + prc.holder.info.name); |
| 5952 | } |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5953 | ActivityManager.getService().refContentProvider( |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5954 | prc.holder.connection, 0, 1); |
| 5955 | } catch (RemoteException e) { |
| 5956 | //do nothing content provider object is dead any way |
| 5957 | } |
| 5958 | } |
| 5959 | } |
| 5960 | } |
| 5961 | } |
| 5962 | |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 5963 | public final IContentProvider acquireExistingProvider( |
| 5964 | Context c, String auth, int userId, boolean stable) { |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5965 | synchronized (mProviderMap) { |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 5966 | final ProviderKey key = new ProviderKey(auth, userId); |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 5967 | final ProviderClientRecord pr = mProviderMap.get(key); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5968 | if (pr == null) { |
| 5969 | return null; |
| 5970 | } |
| 5971 | |
| 5972 | IContentProvider provider = pr.mProvider; |
| 5973 | IBinder jBinder = provider.asBinder(); |
Dianne Hackborn | c428aae | 2012-10-03 16:38:22 -0700 | [diff] [blame] | 5974 | if (!jBinder.isBinderAlive()) { |
| 5975 | // The hosting process of the provider has died; we can't |
| 5976 | // use this one. |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 5977 | Log.i(TAG, "Acquiring provider " + auth + " for user " + userId |
Dianne Hackborn | c428aae | 2012-10-03 16:38:22 -0700 | [diff] [blame] | 5978 | + ": existing object's process dead"); |
| 5979 | handleUnstableProviderDiedLocked(jBinder, true); |
| 5980 | return null; |
| 5981 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5982 | |
| 5983 | // Only increment the ref count if we have one. If we don't then the |
| 5984 | // provider is not reference counted and never needs to be released. |
Dianne Hackborn | cca1f0e | 2010-09-26 18:34:53 -0700 | [diff] [blame] | 5985 | ProviderRefCount prc = mProviderRefCountMap.get(jBinder); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5986 | if (prc != null) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5987 | incProviderRefLocked(prc, stable); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5988 | } |
| 5989 | return provider; |
| 5990 | } |
Dianne Hackborn | cca1f0e | 2010-09-26 18:34:53 -0700 | [diff] [blame] | 5991 | } |
| 5992 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5993 | public final boolean releaseProvider(IContentProvider provider, boolean stable) { |
| 5994 | if (provider == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5995 | return false; |
| 5996 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5997 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5998 | IBinder jBinder = provider.asBinder(); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5999 | synchronized (mProviderMap) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6000 | ProviderRefCount prc = mProviderRefCountMap.get(jBinder); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6001 | if (prc == null) { |
| 6002 | // 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] | 6003 | return false; |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6004 | } |
| 6005 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6006 | boolean lastRef = false; |
| 6007 | if (stable) { |
| 6008 | if (prc.stableCount == 0) { |
| 6009 | if (DEBUG_PROVIDER) Slog.v(TAG, |
| 6010 | "releaseProvider: stable ref count already 0, how?"); |
| 6011 | return false; |
| 6012 | } |
| 6013 | prc.stableCount -= 1; |
| 6014 | if (prc.stableCount == 0) { |
| 6015 | // What we do at this point depends on whether there are |
| 6016 | // any unstable refs left: if there are, we just tell the |
| 6017 | // activity manager to decrement its stable count; if there |
| 6018 | // aren't, we need to enqueue this provider to be removed, |
| 6019 | // and convert to holding a single unstable ref while |
| 6020 | // doing so. |
| 6021 | lastRef = prc.unstableCount == 0; |
| 6022 | try { |
| 6023 | if (DEBUG_PROVIDER) { |
| 6024 | Slog.v(TAG, "releaseProvider: No longer stable w/lastRef=" |
| 6025 | + lastRef + " - " + prc.holder.info.name); |
| 6026 | } |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6027 | ActivityManager.getService().refContentProvider( |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6028 | prc.holder.connection, -1, lastRef ? 1 : 0); |
| 6029 | } catch (RemoteException e) { |
| 6030 | //do nothing content provider object is dead any way |
| 6031 | } |
| 6032 | } |
| 6033 | } else { |
| 6034 | if (prc.unstableCount == 0) { |
| 6035 | if (DEBUG_PROVIDER) Slog.v(TAG, |
| 6036 | "releaseProvider: unstable ref count already 0, how?"); |
| 6037 | return false; |
| 6038 | } |
| 6039 | prc.unstableCount -= 1; |
| 6040 | if (prc.unstableCount == 0) { |
| 6041 | // If this is the last reference, we need to enqueue |
| 6042 | // this provider to be removed instead of telling the |
| 6043 | // activity manager to remove it at this point. |
| 6044 | lastRef = prc.stableCount == 0; |
| 6045 | if (!lastRef) { |
| 6046 | try { |
| 6047 | if (DEBUG_PROVIDER) { |
| 6048 | Slog.v(TAG, "releaseProvider: No longer unstable - " |
| 6049 | + prc.holder.info.name); |
| 6050 | } |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6051 | ActivityManager.getService().refContentProvider( |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6052 | prc.holder.connection, 0, -1); |
| 6053 | } catch (RemoteException e) { |
| 6054 | //do nothing content provider object is dead any way |
| 6055 | } |
| 6056 | } |
| 6057 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6058 | } |
| 6059 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6060 | if (lastRef) { |
| 6061 | if (!prc.removePending) { |
| 6062 | // Schedule the actual remove asynchronously, since we don't know the context |
| 6063 | // this will be called in. |
| 6064 | // TODO: it would be nice to post a delayed message, so |
| 6065 | // if we come back and need the same provider quickly |
| 6066 | // we will still have it available. |
| 6067 | if (DEBUG_PROVIDER) { |
| 6068 | Slog.v(TAG, "releaseProvider: Enqueueing pending removal - " |
| 6069 | + prc.holder.info.name); |
| 6070 | } |
| 6071 | prc.removePending = true; |
| 6072 | Message msg = mH.obtainMessage(H.REMOVE_PROVIDER, prc); |
| 6073 | mH.sendMessage(msg); |
| 6074 | } else { |
| 6075 | Slog.w(TAG, "Duplicate remove pending of provider " + prc.holder.info.name); |
| 6076 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6077 | } |
| 6078 | return true; |
| 6079 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6080 | } |
| 6081 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6082 | final void completeRemoveProvider(ProviderRefCount prc) { |
| 6083 | synchronized (mProviderMap) { |
| 6084 | if (!prc.removePending) { |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6085 | // There was a race! Some other client managed to acquire |
| 6086 | // the provider before the removal was completed. |
| 6087 | // Abort the removal. We will do it later. |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6088 | if (DEBUG_PROVIDER) Slog.v(TAG, "completeRemoveProvider: lost the race, " |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6089 | + "provider still in use"); |
| 6090 | return; |
| 6091 | } |
| 6092 | |
Guobin Zhang | 9e3e5266 | 2013-03-21 13:57:11 +0800 | [diff] [blame] | 6093 | // More complicated race!! Some client managed to acquire the |
| 6094 | // provider and release it before the removal was completed. |
| 6095 | // Continue the removal, and abort the next remove message. |
| 6096 | prc.removePending = false; |
| 6097 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6098 | final IBinder jBinder = prc.holder.provider.asBinder(); |
| 6099 | ProviderRefCount existingPrc = mProviderRefCountMap.get(jBinder); |
| 6100 | if (existingPrc == prc) { |
| 6101 | mProviderRefCountMap.remove(jBinder); |
| 6102 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6103 | |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 6104 | for (int i=mProviderMap.size()-1; i>=0; i--) { |
| 6105 | ProviderClientRecord pr = mProviderMap.valueAt(i); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6106 | IBinder myBinder = pr.mProvider.asBinder(); |
| 6107 | if (myBinder == jBinder) { |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 6108 | mProviderMap.removeAt(i); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6109 | } |
| 6110 | } |
| 6111 | } |
| 6112 | |
| 6113 | try { |
| 6114 | if (DEBUG_PROVIDER) { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6115 | Slog.v(TAG, "removeProvider: Invoking ActivityManagerService." |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6116 | + "removeContentProvider(" + prc.holder.info.name + ")"); |
| 6117 | } |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6118 | ActivityManager.getService().removeContentProvider( |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6119 | prc.holder.connection, false); |
| 6120 | } catch (RemoteException e) { |
| 6121 | //do nothing content provider object is dead any way |
| 6122 | } |
| 6123 | } |
| 6124 | |
| 6125 | final void handleUnstableProviderDied(IBinder provider, boolean fromClient) { |
Dianne Hackborn | c428aae | 2012-10-03 16:38:22 -0700 | [diff] [blame] | 6126 | synchronized (mProviderMap) { |
| 6127 | handleUnstableProviderDiedLocked(provider, fromClient); |
| 6128 | } |
| 6129 | } |
| 6130 | |
| 6131 | final void handleUnstableProviderDiedLocked(IBinder provider, boolean fromClient) { |
| 6132 | ProviderRefCount prc = mProviderRefCountMap.get(provider); |
| 6133 | if (prc != null) { |
| 6134 | if (DEBUG_PROVIDER) Slog.v(TAG, "Cleaning up dead provider " |
| 6135 | + provider + " " + prc.holder.info.name); |
| 6136 | mProviderRefCountMap.remove(provider); |
You Kim | bc74de6 | 2013-10-01 00:13:26 +0900 | [diff] [blame] | 6137 | for (int i=mProviderMap.size()-1; i>=0; i--) { |
| 6138 | ProviderClientRecord pr = mProviderMap.valueAt(i); |
| 6139 | if (pr != null && pr.mProvider.asBinder() == provider) { |
| 6140 | Slog.i(TAG, "Removing dead content provider:" + pr.mProvider.toString()); |
| 6141 | mProviderMap.removeAt(i); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6142 | } |
Dianne Hackborn | c428aae | 2012-10-03 16:38:22 -0700 | [diff] [blame] | 6143 | } |
You Kim | bc74de6 | 2013-10-01 00:13:26 +0900 | [diff] [blame] | 6144 | |
Dianne Hackborn | c428aae | 2012-10-03 16:38:22 -0700 | [diff] [blame] | 6145 | if (fromClient) { |
| 6146 | // We found out about this due to execution in our client |
| 6147 | // code. Tell the activity manager about it now, to ensure |
| 6148 | // that the next time we go to do anything with the provider |
| 6149 | // it knows it is dead (so we don't race with its death |
| 6150 | // notification). |
| 6151 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6152 | ActivityManager.getService().unstableProviderDied( |
Dianne Hackborn | c428aae | 2012-10-03 16:38:22 -0700 | [diff] [blame] | 6153 | prc.holder.connection); |
| 6154 | } catch (RemoteException e) { |
| 6155 | //do nothing content provider object is dead any way |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6156 | } |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 6157 | } |
| 6158 | } |
| 6159 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6160 | |
Jeff Sharkey | 7aa7601 | 2013-09-30 14:26:27 -0700 | [diff] [blame] | 6161 | final void appNotRespondingViaProvider(IBinder provider) { |
| 6162 | synchronized (mProviderMap) { |
| 6163 | ProviderRefCount prc = mProviderRefCountMap.get(provider); |
| 6164 | if (prc != null) { |
| 6165 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6166 | ActivityManager.getService() |
Jeff Sharkey | 7aa7601 | 2013-09-30 14:26:27 -0700 | [diff] [blame] | 6167 | .appNotRespondingViaProvider(prc.holder.connection); |
| 6168 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 6169 | throw e.rethrowFromSystemServer(); |
Jeff Sharkey | 7aa7601 | 2013-09-30 14:26:27 -0700 | [diff] [blame] | 6170 | } |
| 6171 | } |
| 6172 | } |
| 6173 | } |
| 6174 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6175 | private ProviderClientRecord installProviderAuthoritiesLocked(IContentProvider provider, |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 6176 | ContentProvider localProvider, ContentProviderHolder holder) { |
Andreas Gampe | 18e99c1 | 2015-03-06 15:29:06 -0800 | [diff] [blame] | 6177 | final String auths[] = holder.info.authority.split(";"); |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 6178 | final int userId = UserHandle.getUserId(holder.info.applicationInfo.uid); |
| 6179 | |
Jeff Sharkey | 0a17db1 | 2016-11-04 11:23:46 -0600 | [diff] [blame] | 6180 | if (provider != null) { |
| 6181 | // If this provider is hosted by the core OS and cannot be upgraded, |
| 6182 | // then I guess we're okay doing blocking calls to it. |
| 6183 | for (String auth : auths) { |
| 6184 | switch (auth) { |
| 6185 | case ContactsContract.AUTHORITY: |
| 6186 | case CallLog.AUTHORITY: |
| 6187 | case CallLog.SHADOW_AUTHORITY: |
| 6188 | case BlockedNumberContract.AUTHORITY: |
| 6189 | case CalendarContract.AUTHORITY: |
| 6190 | case Downloads.Impl.AUTHORITY: |
Jeff Sharkey | cb62162 | 2016-11-11 14:04:32 -0700 | [diff] [blame] | 6191 | case "telephony": |
Jeff Sharkey | 0a17db1 | 2016-11-04 11:23:46 -0600 | [diff] [blame] | 6192 | Binder.allowBlocking(provider.asBinder()); |
| 6193 | } |
| 6194 | } |
| 6195 | } |
| 6196 | |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 6197 | final ProviderClientRecord pcr = new ProviderClientRecord( |
| 6198 | auths, provider, localProvider, holder); |
| 6199 | for (String auth : auths) { |
| 6200 | final ProviderKey key = new ProviderKey(auth, userId); |
| 6201 | final ProviderClientRecord existing = mProviderMap.get(key); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6202 | if (existing != null) { |
| 6203 | Slog.w(TAG, "Content provider " + pcr.mHolder.info.name |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 6204 | + " already published as " + auth); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6205 | } else { |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 6206 | mProviderMap.put(key, pcr); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6207 | } |
| 6208 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6209 | return pcr; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6210 | } |
| 6211 | |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6212 | /** |
| 6213 | * Installs the provider. |
| 6214 | * |
| 6215 | * Providers that are local to the process or that come from the system server |
| 6216 | * may be installed permanently which is indicated by setting noReleaseNeeded to true. |
| 6217 | * Other remote providers are reference counted. The initial reference count |
| 6218 | * for all reference counted providers is one. Providers that are not reference |
| 6219 | * counted do not have a reference count (at all). |
| 6220 | * |
| 6221 | * This method detects when a provider has already been installed. When this happens, |
| 6222 | * it increments the reference count of the existing provider (if appropriate) |
| 6223 | * and returns the existing provider. This can happen due to concurrent |
| 6224 | * attempts to acquire the same provider. |
| 6225 | */ |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 6226 | private ContentProviderHolder installProvider(Context context, |
| 6227 | ContentProviderHolder holder, ProviderInfo info, |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6228 | boolean noisy, boolean noReleaseNeeded, boolean stable) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6229 | ContentProvider localProvider = null; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6230 | IContentProvider provider; |
Dianne Hackborn | 5f48fca | 2012-05-30 11:06:31 -0700 | [diff] [blame] | 6231 | if (holder == null || holder.provider == null) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6232 | if (DEBUG_PROVIDER || noisy) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 6233 | Slog.d(TAG, "Loading provider " + info.authority + ": " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6234 | + info.name); |
| 6235 | } |
| 6236 | Context c = null; |
| 6237 | ApplicationInfo ai = info.applicationInfo; |
| 6238 | if (context.getPackageName().equals(ai.packageName)) { |
| 6239 | c = context; |
| 6240 | } else if (mInitialApplication != null && |
| 6241 | mInitialApplication.getPackageName().equals(ai.packageName)) { |
| 6242 | c = mInitialApplication; |
| 6243 | } else { |
| 6244 | try { |
| 6245 | c = context.createPackageContext(ai.packageName, |
| 6246 | Context.CONTEXT_INCLUDE_CODE); |
| 6247 | } catch (PackageManager.NameNotFoundException e) { |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 6248 | // Ignore |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6249 | } |
| 6250 | } |
| 6251 | if (c == null) { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 6252 | Slog.w(TAG, "Unable to get context for package " + |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6253 | ai.packageName + |
| 6254 | " while loading content provider " + |
| 6255 | info.name); |
| 6256 | return null; |
| 6257 | } |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 6258 | |
| 6259 | if (info.splitName != null) { |
| 6260 | try { |
| 6261 | c = c.createContextForSplit(info.splitName); |
| 6262 | } catch (NameNotFoundException e) { |
| 6263 | throw new RuntimeException(e); |
| 6264 | } |
| 6265 | } |
| 6266 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6267 | try { |
| 6268 | final java.lang.ClassLoader cl = c.getClassLoader(); |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 6269 | LoadedApk packageInfo = peekPackageInfo(ai.packageName, true); |
| 6270 | if (packageInfo == null) { |
Jason Monk | a80bfb5 | 2017-11-16 17:15:37 -0500 | [diff] [blame] | 6271 | // System startup case. |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 6272 | packageInfo = getSystemContext().mPackageInfo; |
Jason Monk | a80bfb5 | 2017-11-16 17:15:37 -0500 | [diff] [blame] | 6273 | } |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 6274 | localProvider = packageInfo.getAppFactory() |
Jason Monk | a80bfb5 | 2017-11-16 17:15:37 -0500 | [diff] [blame] | 6275 | .instantiateProvider(cl, info.name); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6276 | provider = localProvider.getIContentProvider(); |
| 6277 | if (provider == null) { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 6278 | Slog.e(TAG, "Failed to instantiate class " + |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6279 | info.name + " from sourceDir " + |
| 6280 | info.applicationInfo.sourceDir); |
| 6281 | return null; |
| 6282 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6283 | if (DEBUG_PROVIDER) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6284 | TAG, "Instantiating local provider " + info.name); |
| 6285 | // XXX Need to create the correct context for this provider. |
| 6286 | localProvider.attachInfo(c, info); |
| 6287 | } catch (java.lang.Exception e) { |
| 6288 | if (!mInstrumentation.onException(null, e)) { |
| 6289 | throw new RuntimeException( |
| 6290 | "Unable to get provider " + info.name |
| 6291 | + ": " + e.toString(), e); |
| 6292 | } |
| 6293 | return null; |
| 6294 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6295 | } else { |
| 6296 | provider = holder.provider; |
| 6297 | 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] | 6298 | + info.name); |
| 6299 | } |
| 6300 | |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 6301 | ContentProviderHolder retHolder; |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6302 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6303 | synchronized (mProviderMap) { |
| 6304 | if (DEBUG_PROVIDER) Slog.v(TAG, "Checking to add " + provider |
| 6305 | + " / " + info.name); |
| 6306 | IBinder jBinder = provider.asBinder(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6307 | if (localProvider != null) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6308 | ComponentName cname = new ComponentName(info.packageName, info.name); |
| 6309 | ProviderClientRecord pr = mLocalProvidersByName.get(cname); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6310 | if (pr != null) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6311 | if (DEBUG_PROVIDER) { |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6312 | Slog.v(TAG, "installProvider: lost the race, " |
| 6313 | + "using existing local provider"); |
| 6314 | } |
| 6315 | provider = pr.mProvider; |
| 6316 | } else { |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 6317 | holder = new ContentProviderHolder(info); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6318 | holder.provider = provider; |
| 6319 | holder.noReleaseNeeded = true; |
| 6320 | pr = installProviderAuthoritiesLocked(provider, localProvider, holder); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6321 | mLocalProviders.put(jBinder, pr); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6322 | mLocalProvidersByName.put(cname, pr); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6323 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6324 | retHolder = pr.mHolder; |
| 6325 | } else { |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6326 | ProviderRefCount prc = mProviderRefCountMap.get(jBinder); |
| 6327 | if (prc != null) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6328 | if (DEBUG_PROVIDER) { |
| 6329 | Slog.v(TAG, "installProvider: lost the race, updating ref count"); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6330 | } |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 6331 | // We need to transfer our new reference to the existing |
| 6332 | // ref count, releasing the old one... but only if |
| 6333 | // release is needed (that is, it is not running in the |
| 6334 | // system process). |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6335 | if (!noReleaseNeeded) { |
| 6336 | incProviderRefLocked(prc, stable); |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 6337 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6338 | ActivityManager.getService().removeContentProvider( |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 6339 | holder.connection, stable); |
| 6340 | } catch (RemoteException e) { |
| 6341 | //do nothing content provider object is dead any way |
| 6342 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6343 | } |
| 6344 | } else { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6345 | ProviderClientRecord client = installProviderAuthoritiesLocked( |
| 6346 | provider, localProvider, holder); |
| 6347 | if (noReleaseNeeded) { |
| 6348 | prc = new ProviderRefCount(holder, client, 1000, 1000); |
| 6349 | } else { |
| 6350 | prc = stable |
| 6351 | ? new ProviderRefCount(holder, client, 1, 0) |
| 6352 | : new ProviderRefCount(holder, client, 0, 1); |
| 6353 | } |
| 6354 | mProviderRefCountMap.put(jBinder, prc); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6355 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6356 | retHolder = prc.holder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6357 | } |
| 6358 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6359 | return retHolder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6360 | } |
| 6361 | |
Torne (Richard Coles) | 466cbe4 | 2017-05-31 14:09:14 -0400 | [diff] [blame] | 6362 | private void handleRunIsolatedEntryPoint(String entryPoint, String[] entryPointArgs) { |
| 6363 | try { |
| 6364 | Method main = Class.forName(entryPoint).getMethod("main", String[].class); |
| 6365 | main.invoke(null, new Object[]{entryPointArgs}); |
| 6366 | } catch (ReflectiveOperationException e) { |
| 6367 | throw new AndroidRuntimeException("runIsolatedEntryPoint failed", e); |
| 6368 | } |
| 6369 | // The process will be empty after this method returns; exit the VM now. |
| 6370 | System.exit(0); |
| 6371 | } |
| 6372 | |
Sudheer Shanka | f669010 | 2017-10-16 10:20:32 -0700 | [diff] [blame] | 6373 | private void attach(boolean system, long startSeq) { |
Jeff Sharkey | 66a017b | 2013-01-17 18:18:22 -0800 | [diff] [blame] | 6374 | sCurrentActivityThread = this; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6375 | mSystemThread = system; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6376 | if (!system) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 6377 | ViewRootImpl.addFirstDrawHandler(new Runnable() { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 6378 | @Override |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 6379 | public void run() { |
| 6380 | ensureJitEnabled(); |
| 6381 | } |
| 6382 | }); |
Siva Velusamy | d693dfa | 2012-09-10 14:36:58 -0700 | [diff] [blame] | 6383 | android.ddm.DdmHandleAppName.setAppName("<pre-initialized>", |
| 6384 | UserHandle.myUserId()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6385 | RuntimeInit.setApplicationObject(mAppThread.asBinder()); |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6386 | final IActivityManager mgr = ActivityManager.getService(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6387 | try { |
Sudheer Shanka | f669010 | 2017-10-16 10:20:32 -0700 | [diff] [blame] | 6388 | mgr.attachApplication(mAppThread, startSeq); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6389 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 6390 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6391 | } |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 6392 | // Watch for getting close to heap limit. |
| 6393 | BinderInternal.addGcWatcher(new Runnable() { |
| 6394 | @Override public void run() { |
| 6395 | if (!mSomeActivitiesChanged) { |
| 6396 | return; |
| 6397 | } |
| 6398 | Runtime runtime = Runtime.getRuntime(); |
| 6399 | long dalvikMax = runtime.maxMemory(); |
| 6400 | long dalvikUsed = runtime.totalMemory() - runtime.freeMemory(); |
| 6401 | if (dalvikUsed > ((3*dalvikMax)/4)) { |
| 6402 | if (DEBUG_MEMORY_TRIM) Slog.d(TAG, "Dalvik max=" + (dalvikMax/1024) |
| 6403 | + " total=" + (runtime.totalMemory()/1024) |
| 6404 | + " used=" + (dalvikUsed/1024)); |
| 6405 | mSomeActivitiesChanged = false; |
| 6406 | try { |
| 6407 | mgr.releaseSomeActivities(mAppThread); |
| 6408 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 6409 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 6410 | } |
| 6411 | } |
| 6412 | } |
| 6413 | }); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6414 | } else { |
| 6415 | // Don't set application object here -- if the system crashes, |
| 6416 | // 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] | 6417 | android.ddm.DdmHandleAppName.setAppName("system_process", |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 6418 | UserHandle.myUserId()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6419 | try { |
| 6420 | mInstrumentation = new Instrumentation(); |
Jason Monk | a80bfb5 | 2017-11-16 17:15:37 -0500 | [diff] [blame] | 6421 | mInstrumentation.basicInit(this); |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 6422 | ContextImpl context = ContextImpl.createAppContext( |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 6423 | this, getSystemContext().mPackageInfo); |
| 6424 | mInitialApplication = context.mPackageInfo.makeApplication(true, null); |
Jeff Brown | 7fc8e35 | 2014-09-16 18:06:47 -0700 | [diff] [blame] | 6425 | mInitialApplication.onCreate(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6426 | } catch (Exception e) { |
| 6427 | throw new RuntimeException( |
| 6428 | "Unable to instantiate Application():" + e.toString(), e); |
| 6429 | } |
| 6430 | } |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 6431 | |
| 6432 | // add dropbox logging to libcore |
| 6433 | DropBox.setReporter(new DropBoxReporter()); |
| 6434 | |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 6435 | ViewRootImpl.ConfigChangedCallback configChangedCallback |
| 6436 | = (Configuration globalConfig) -> { |
| 6437 | synchronized (mResourcesManager) { |
| 6438 | // We need to apply this change to the resources immediately, because upon returning |
| 6439 | // the view hierarchy will be informed about it. |
| 6440 | if (mResourcesManager.applyConfigurationToResourcesLocked(globalConfig, |
| 6441 | null /* compat */)) { |
| 6442 | updateLocaleListFromAppContext(mInitialApplication.getApplicationContext(), |
| 6443 | mResourcesManager.getConfiguration().getLocales()); |
Adam Lesinski | b61e405 | 2016-05-19 18:23:05 -0700 | [diff] [blame] | 6444 | |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 6445 | // This actually changed the resources! Tell everyone about it. |
| 6446 | if (mPendingConfiguration == null |
| 6447 | || mPendingConfiguration.isOtherSeqNewer(globalConfig)) { |
| 6448 | mPendingConfiguration = globalConfig; |
| 6449 | sendMessage(H.CONFIGURATION_CHANGED, globalConfig); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6450 | } |
| 6451 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6452 | } |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 6453 | }; |
| 6454 | ViewRootImpl.addConfigCallback(configChangedCallback); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6455 | } |
| 6456 | |
Romain Guy | 5e9120d | 2012-01-30 12:17:22 -0800 | [diff] [blame] | 6457 | public static ActivityThread systemMain() { |
Alan Viverette | 5e1565e | 2014-07-29 16:14:25 -0700 | [diff] [blame] | 6458 | // The system process on low-memory devices do not get to use hardware |
| 6459 | // accelerated drawing, since this can add too much overhead to the |
| 6460 | // process. |
| 6461 | if (!ActivityManager.isHighEndGfx()) { |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 6462 | ThreadedRenderer.disable(true); |
John Reck | 73840ea | 2014-09-22 07:39:18 -0700 | [diff] [blame] | 6463 | } else { |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 6464 | ThreadedRenderer.enableForegroundTrimming(); |
Alan Viverette | 5e1565e | 2014-07-29 16:14:25 -0700 | [diff] [blame] | 6465 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6466 | ActivityThread thread = new ActivityThread(); |
Sudheer Shanka | f669010 | 2017-10-16 10:20:32 -0700 | [diff] [blame] | 6467 | thread.attach(true, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6468 | return thread; |
| 6469 | } |
| 6470 | |
Jeff Brown | 10e8971 | 2011-07-08 18:52:57 -0700 | [diff] [blame] | 6471 | public final void installSystemProviders(List<ProviderInfo> providers) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6472 | if (providers != null) { |
Jeff Brown | 10e8971 | 2011-07-08 18:52:57 -0700 | [diff] [blame] | 6473 | installContentProviders(mInitialApplication, providers); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6474 | } |
| 6475 | } |
| 6476 | |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 6477 | public int getIntCoreSetting(String key, int defaultValue) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 6478 | synchronized (mResourcesManager) { |
Svetoslav Ganov | 9aa597e | 2011-03-03 18:17:41 -0800 | [diff] [blame] | 6479 | if (mCoreSettings != null) { |
| 6480 | return mCoreSettings.getInt(key, defaultValue); |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 6481 | } |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 6482 | return defaultValue; |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 6483 | } |
| 6484 | } |
| 6485 | |
Geremy Condra | 69689a7 | 2012-09-11 16:57:17 -0700 | [diff] [blame] | 6486 | private static class EventLoggingReporter implements EventLogger.Reporter { |
| 6487 | @Override |
| 6488 | public void report (int code, Object... list) { |
| 6489 | EventLog.writeEvent(code, list); |
| 6490 | } |
| 6491 | } |
| 6492 | |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 6493 | private class DropBoxReporter implements DropBox.Reporter { |
| 6494 | |
| 6495 | private DropBoxManager dropBox; |
| 6496 | |
Narayan Kamath | 7f06224 | 2015-04-08 13:24:13 +0100 | [diff] [blame] | 6497 | public DropBoxReporter() {} |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 6498 | |
| 6499 | @Override |
| 6500 | public void addData(String tag, byte[] data, int flags) { |
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.addData(tag, data, flags); |
| 6503 | } |
| 6504 | |
| 6505 | @Override |
| 6506 | public void addText(String tag, String data) { |
Narayan Kamath | 7f06224 | 2015-04-08 13:24:13 +0100 | [diff] [blame] | 6507 | ensureInitialized(); |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 6508 | dropBox.addText(tag, data); |
| 6509 | } |
Narayan Kamath | 7f06224 | 2015-04-08 13:24:13 +0100 | [diff] [blame] | 6510 | |
| 6511 | private synchronized void ensureInitialized() { |
| 6512 | if (dropBox == null) { |
| 6513 | dropBox = (DropBoxManager) getSystemContext().getSystemService(Context.DROPBOX_SERVICE); |
| 6514 | } |
| 6515 | } |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 6516 | } |
| 6517 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 6518 | public static void main(String[] args) { |
Narayan Kamath | fbb32f6 | 2015-06-12 15:34:35 +0100 | [diff] [blame] | 6519 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "ActivityThreadMain"); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 6520 | |
Brad Fitzpatrick | 4d9e6d2 | 2010-11-15 08:49:51 -0800 | [diff] [blame] | 6521 | // CloseGuard defaults to true and can be quite spammy. We |
| 6522 | // disable it here, but selectively enable it later (via |
| 6523 | // StrictMode) on debug builds, but using DropBox, not logs. |
| 6524 | CloseGuard.setEnabled(false); |
| 6525 | |
Andreas Gampe | d281b42 | 2016-07-08 03:50:27 +0000 | [diff] [blame] | 6526 | Environment.initForCurrentUser(); |
Jeff Sharkey | b049e21 | 2012-09-07 23:16:01 -0700 | [diff] [blame] | 6527 | |
Geremy Condra | 69689a7 | 2012-09-11 16:57:17 -0700 | [diff] [blame] | 6528 | // Set the reporter for event logging in libcore |
| 6529 | EventLogger.setReporter(new EventLoggingReporter()); |
| 6530 | |
Robin Lee | 3d076af | 2014-04-25 14:57:49 +0100 | [diff] [blame] | 6531 | // Make sure TrustedCertificateStore looks in the right place for CA certificates |
| 6532 | final File configDir = Environment.getUserConfigDirectory(UserHandle.myUserId()); |
| 6533 | TrustedCertificateStore.setDefaultUserDirectory(configDir); |
| 6534 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6535 | Process.setArgV0("<pre-initialized>"); |
| 6536 | |
| 6537 | Looper.prepareMainLooper(); |
| 6538 | |
Sudheer Shanka | f669010 | 2017-10-16 10:20:32 -0700 | [diff] [blame] | 6539 | // Find the value for {@link #PROC_START_SEQ_IDENT} if provided on the command line. |
| 6540 | // It will be in the format "seq=114" |
| 6541 | long startSeq = 0; |
| 6542 | if (args != null) { |
| 6543 | for (int i = args.length - 1; i >= 0; --i) { |
| 6544 | if (args[i] != null && args[i].startsWith(PROC_START_SEQ_IDENT)) { |
| 6545 | startSeq = Long.parseLong( |
| 6546 | args[i].substring(PROC_START_SEQ_IDENT.length())); |
| 6547 | } |
| 6548 | } |
| 6549 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6550 | ActivityThread thread = new ActivityThread(); |
Sudheer Shanka | f669010 | 2017-10-16 10:20:32 -0700 | [diff] [blame] | 6551 | thread.attach(false, startSeq); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6552 | |
Vairavan Srinivasan | 7335cfd | 2012-08-18 18:36:03 -0700 | [diff] [blame] | 6553 | if (sMainThreadHandler == null) { |
| 6554 | sMainThreadHandler = thread.getHandler(); |
| 6555 | } |
| 6556 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6557 | if (false) { |
| 6558 | Looper.myLooper().setMessageLogging(new |
| 6559 | LogPrinter(Log.DEBUG, "ActivityThread")); |
| 6560 | } |
| 6561 | |
Narayan Kamath | fbb32f6 | 2015-06-12 15:34:35 +0100 | [diff] [blame] | 6562 | // End of event ActivityThreadMain. |
| 6563 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6564 | Looper.loop(); |
| 6565 | |
Jeff Brown | 10e8971 | 2011-07-08 18:52:57 -0700 | [diff] [blame] | 6566 | throw new RuntimeException("Main thread loop unexpectedly exited"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6567 | } |
Chris Craik | fc29424 | 2016-12-13 18:10:46 -0800 | [diff] [blame] | 6568 | |
| 6569 | // ------------------ Regular JNI ------------------------ |
| 6570 | |
| 6571 | private native void nDumpGraphicsInfo(FileDescriptor fd); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6572 | } |