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 | |
Riddle Hsu | 50e3400 | 2019-04-12 20:42:05 +0800 | [diff] [blame] | 19 | import static android.app.ActivityManager.PROCESS_STATE_UNKNOWN; |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 20 | import static android.app.servertransaction.ActivityLifecycleItem.ON_CREATE; |
| 21 | import static android.app.servertransaction.ActivityLifecycleItem.ON_DESTROY; |
| 22 | import static android.app.servertransaction.ActivityLifecycleItem.ON_PAUSE; |
| 23 | import static android.app.servertransaction.ActivityLifecycleItem.ON_RESUME; |
| 24 | import static android.app.servertransaction.ActivityLifecycleItem.ON_START; |
| 25 | import static android.app.servertransaction.ActivityLifecycleItem.ON_STOP; |
| 26 | import static android.app.servertransaction.ActivityLifecycleItem.PRE_ON_CREATE; |
Jeff Sharkey | bc2ae00 | 2018-07-31 10:45:37 -0600 | [diff] [blame] | 27 | import static android.content.ContentResolver.DEPRECATE_DATA_COLUMNS; |
| 28 | import static android.content.ContentResolver.DEPRECATE_DATA_PREFIX; |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 29 | import static android.view.Display.INVALID_DISPLAY; |
| 30 | |
Adrian Roos | 03dd48c | 2019-03-19 17:17:37 -0400 | [diff] [blame] | 31 | import static com.android.internal.annotations.VisibleForTesting.Visibility.PACKAGE; |
| 32 | |
Adam Lesinski | c1b0ebf | 2016-06-09 11:17:10 -0700 | [diff] [blame] | 33 | import android.annotation.NonNull; |
| 34 | import android.annotation.Nullable; |
Dianne Hackborn | 69c6adc | 2015-06-02 10:52:59 -0700 | [diff] [blame] | 35 | import android.app.assist.AssistContent; |
| 36 | import android.app.assist.AssistStructure; |
Christopher Tate | 4528186 | 2010-03-05 15:46:30 -0800 | [diff] [blame] | 37 | import android.app.backup.BackupAgent; |
Andrii Kulian | 914aa7d | 2018-03-19 21:51:53 -0700 | [diff] [blame] | 38 | import android.app.servertransaction.ActivityLifecycleItem; |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 39 | import android.app.servertransaction.ActivityLifecycleItem.LifecycleState; |
Andrii Kulian | 914aa7d | 2018-03-19 21:51:53 -0700 | [diff] [blame] | 40 | import android.app.servertransaction.ActivityRelaunchItem; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 41 | import android.app.servertransaction.ActivityResultItem; |
| 42 | import android.app.servertransaction.ClientTransaction; |
Riddle Hsu | d3062cb | 2018-06-30 02:06:42 +0800 | [diff] [blame] | 43 | import android.app.servertransaction.ClientTransactionItem; |
jorgegil@google.com | 06bc323 | 2019-10-31 14:51:22 -0700 | [diff] [blame] | 44 | import android.app.servertransaction.PauseActivityItem; |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 45 | import android.app.servertransaction.PendingTransactionActions; |
| 46 | import android.app.servertransaction.PendingTransactionActions.StopInfo; |
jorgegil@google.com | 06bc323 | 2019-10-31 14:51:22 -0700 | [diff] [blame] | 47 | import android.app.servertransaction.ResumeActivityItem; |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 48 | import android.app.servertransaction.TransactionExecutor; |
Andrii Kulian | 914aa7d | 2018-03-19 21:51:53 -0700 | [diff] [blame] | 49 | import android.app.servertransaction.TransactionExecutorHelper; |
Artur Satayev | c895b1b | 2019-12-10 17:47:51 +0000 | [diff] [blame] | 50 | import android.compat.annotation.UnsupportedAppUsage; |
Felipe Leme | a4f39cd | 2019-02-19 15:08:59 -0800 | [diff] [blame] | 51 | import android.content.AutofillOptions; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | import android.content.BroadcastReceiver; |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 53 | import android.content.ComponentCallbacks2; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 | import android.content.ComponentName; |
Felipe Leme | 326f15a | 2019-02-19 09:42:24 -0800 | [diff] [blame] | 55 | import android.content.ContentCaptureOptions; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 56 | import android.content.ContentProvider; |
Jeff Sharkey | bc2ae00 | 2018-07-31 10:45:37 -0600 | [diff] [blame] | 57 | import android.content.ContentResolver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 58 | import android.content.Context; |
| 59 | import android.content.IContentProvider; |
Suchi Amalapurapu | 1ccac75 | 2009-06-12 10:09:58 -0700 | [diff] [blame] | 60 | import android.content.IIntentReceiver; |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 61 | import android.content.Intent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | import android.content.pm.ActivityInfo; |
| 63 | import android.content.pm.ApplicationInfo; |
| 64 | import android.content.pm.IPackageManager; |
| 65 | import android.content.pm.InstrumentationInfo; |
Christopher Tate | 346acb1 | 2012-10-15 19:20:25 -0700 | [diff] [blame] | 66 | import android.content.pm.PackageInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | import android.content.pm.PackageManager; |
Sen Hu | bde7570 | 2010-05-28 01:54:03 -0700 | [diff] [blame] | 68 | import android.content.pm.PackageManager.NameNotFoundException; |
Dianne Hackborn | 3f7c9f2 | 2017-04-04 15:36:33 -0700 | [diff] [blame] | 69 | import android.content.pm.ParceledListSlice; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 70 | import android.content.pm.ProviderInfo; |
| 71 | import android.content.pm.ServiceInfo; |
| 72 | import android.content.res.AssetManager; |
Mitsuru Oshima | ba3ba57 | 2009-07-08 18:49:26 -0700 | [diff] [blame] | 73 | import android.content.res.CompatibilityInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 74 | import android.content.res.Configuration; |
| 75 | import android.content.res.Resources; |
Alan Viverette | e54d245 | 2015-05-06 10:41:43 -0700 | [diff] [blame] | 76 | import android.content.res.Resources.Theme; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 77 | import android.database.sqlite.SQLiteDatabase; |
| 78 | import android.database.sqlite.SQLiteDebug; |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 79 | import android.database.sqlite.SQLiteDebug.DbStats; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 80 | import android.graphics.Bitmap; |
| 81 | import android.graphics.Canvas; |
John Reck | 8785ceb | 2018-10-29 16:45:58 -0700 | [diff] [blame] | 82 | import android.graphics.HardwareRenderer; |
Leon Scroggins III | 8290eab | 2018-03-19 10:51:44 -0400 | [diff] [blame] | 83 | import android.graphics.ImageDecoder; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 84 | import android.hardware.display.DisplayManagerGlobal; |
lumark | ddc77fb | 2019-06-27 22:22:23 +0800 | [diff] [blame] | 85 | import android.inputmethodservice.InputMethodService; |
Paul Jensen | e0bef71 | 2014-12-10 15:12:18 -0500 | [diff] [blame] | 86 | import android.net.ConnectivityManager; |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 87 | import android.net.IConnectivityManager; |
| 88 | import android.net.Proxy; |
Jason Monk | 83520b9 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 89 | import android.net.Uri; |
Joe Onorato | d630f10 | 2011-03-17 18:42:26 -0700 | [diff] [blame] | 90 | import android.os.AsyncTask; |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 91 | import android.os.Binder; |
Jeff Sharkey | 344744b | 2016-01-28 19:03:30 -0700 | [diff] [blame] | 92 | import android.os.Build; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 93 | import android.os.Bundle; |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 94 | import android.os.CancellationSignal; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 95 | import android.os.Debug; |
Jeff Sharkey | b049e21 | 2012-09-07 23:16:01 -0700 | [diff] [blame] | 96 | import android.os.Environment; |
Jeff Sharkey | bc2ae00 | 2018-07-31 10:45:37 -0600 | [diff] [blame] | 97 | import android.os.FileUtils; |
Jesse Hall | b12249b | 2016-12-12 12:53:02 -0800 | [diff] [blame] | 98 | import android.os.GraphicsEnvironment; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 99 | import android.os.Handler; |
Jeff Sharkey | 8439ac0 | 2017-12-12 17:26:23 -0700 | [diff] [blame] | 100 | import android.os.HandlerExecutor; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 101 | import android.os.IBinder; |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 102 | import android.os.ICancellationSignal; |
Adam Lesinski | b61e405 | 2016-05-19 18:23:05 -0700 | [diff] [blame] | 103 | import android.os.LocaleList; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 104 | import android.os.Looper; |
| 105 | import android.os.Message; |
| 106 | import android.os.MessageQueue; |
Dianne Hackborn | fabb70b | 2014-11-11 12:22:36 -0800 | [diff] [blame] | 107 | import android.os.Parcel; |
Dianne Hackborn | 9c8dd55 | 2009-06-23 19:22:52 -0700 | [diff] [blame] | 108 | import android.os.ParcelFileDescriptor; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 109 | import android.os.PersistableBundle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 110 | import android.os.Process; |
Makoto Onuki | 2c6657f | 2018-06-06 15:24:02 -0700 | [diff] [blame] | 111 | import android.os.RemoteCallback; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 112 | import android.os.RemoteException; |
| 113 | import android.os.ServiceManager; |
Jeffrey Huang | f58800b | 2020-01-23 13:22:10 -0800 | [diff] [blame] | 114 | import android.os.StatsFrameworkInitializer; |
| 115 | import android.os.StatsServiceManager; |
Brad Fitzpatrick | 438d059 | 2010-06-10 12:19:19 -0700 | [diff] [blame] | 116 | import android.os.StrictMode; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 117 | import android.os.SystemClock; |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 118 | import android.os.SystemProperties; |
Makoto Onuki | 6b0a7b8 | 2019-10-18 15:44:53 -0700 | [diff] [blame] | 119 | import android.os.TelephonyServiceManager; |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 120 | import android.os.Trace; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 121 | import android.os.UserHandle; |
Todd Kennedy | 8f13598 | 2019-07-02 07:35:15 -0700 | [diff] [blame] | 122 | import android.permission.IPermissionManager; |
Jeff Sharkey | 0a17db1 | 2016-11-04 11:23:46 -0600 | [diff] [blame] | 123 | import android.provider.BlockedNumberContract; |
| 124 | import android.provider.CalendarContract; |
| 125 | import android.provider.CallLog; |
| 126 | import android.provider.ContactsContract; |
| 127 | import android.provider.Downloads; |
Seigo Nonaka | 54084b6 | 2017-04-24 14:46:23 -0700 | [diff] [blame] | 128 | import android.provider.FontsContract; |
Narayan Kamath | ccb2a086 | 2013-12-19 14:49:36 +0000 | [diff] [blame] | 129 | import android.provider.Settings; |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 130 | import android.renderscript.RenderScriptCacheDir; |
Chad Brubaker | c72875b | 2016-04-27 16:35:11 -0700 | [diff] [blame] | 131 | import android.security.NetworkSecurityPolicy; |
Chad Brubaker | 78d4712 | 2015-11-17 22:26:58 -0800 | [diff] [blame] | 132 | import android.security.net.config.NetworkSecurityConfigProvider; |
Jeff Sharkey | bc2ae00 | 2018-07-31 10:45:37 -0600 | [diff] [blame] | 133 | import android.system.ErrnoException; |
| 134 | import android.system.OsConstants; |
| 135 | import android.system.StructStat; |
Makoto Onuki | 6b0a7b8 | 2019-10-18 15:44:53 -0700 | [diff] [blame] | 136 | import android.telephony.TelephonyFrameworkInitializer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 137 | import android.util.AndroidRuntimeException; |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 138 | import android.util.ArrayMap; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 139 | import android.util.DisplayMetrics; |
| 140 | import android.util.EventLog; |
| 141 | import android.util.Log; |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 142 | import android.util.LogPrinter; |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 143 | import android.util.MergedConfiguration; |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 144 | import android.util.Pair; |
Jeff Brown | 6754ba2 | 2011-12-14 20:20:01 -0800 | [diff] [blame] | 145 | import android.util.PrintWriterPrinter; |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 146 | import android.util.Slog; |
Annie Meng | d582787 | 2019-01-30 20:28:57 +0000 | [diff] [blame] | 147 | import android.util.SparseArray; |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 148 | import android.util.SparseIntArray; |
Adam Powell | 1487466 | 2013-07-18 19:42:41 -0700 | [diff] [blame] | 149 | import android.util.SuperNotCalledException; |
Kweku Adams | 4be0b1a | 2019-04-25 16:16:34 -0700 | [diff] [blame] | 150 | import android.util.UtilConfig; |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 151 | import android.util.proto.ProtoOutputStream; |
Jorim Jaggi | b29e318 | 2018-04-30 18:51:56 +0200 | [diff] [blame] | 152 | import android.view.Choreographer; |
Adam Lesinski | 3ad1b48 | 2016-04-01 16:41:41 -0700 | [diff] [blame] | 153 | import android.view.ContextThemeWrapper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 154 | import android.view.Display; |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 155 | import android.view.ThreadedRenderer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 156 | import android.view.View; |
| 157 | import android.view.ViewDebug; |
| 158 | import android.view.ViewManager; |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 159 | import android.view.ViewRootImpl; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 160 | import android.view.Window; |
| 161 | import android.view.WindowManager; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 162 | import android.view.WindowManagerGlobal; |
Richard Uhler | 2c03619 | 2016-09-14 09:48:31 +0100 | [diff] [blame] | 163 | import android.webkit.WebView; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 164 | |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 165 | import com.android.internal.annotations.GuardedBy; |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 166 | import com.android.internal.annotations.VisibleForTesting; |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 167 | import com.android.internal.app.IVoiceInteractor; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 168 | import com.android.internal.content.ReferrerIntent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 169 | import com.android.internal.os.BinderInternal; |
| 170 | import com.android.internal.os.RuntimeInit; |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 171 | import com.android.internal.os.SomeArgs; |
Jeff Sharkey | 3e19589 | 2016-03-05 19:48:59 -0700 | [diff] [blame] | 172 | import com.android.internal.util.ArrayUtils; |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 173 | import com.android.internal.util.FastPrintWriter; |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 174 | import com.android.internal.util.Preconditions; |
Jorim Jaggi | b29e318 | 2018-04-30 18:51:56 +0200 | [diff] [blame] | 175 | import com.android.internal.util.function.pooled.PooledLambda; |
Kenny Root | 12e7522 | 2013-04-23 22:34:24 -0700 | [diff] [blame] | 176 | import com.android.org.conscrypt.OpenSSLSocketImpl; |
Robin Lee | 3d076af | 2014-04-25 14:57:49 +0100 | [diff] [blame] | 177 | import com.android.org.conscrypt.TrustedCertificateStore; |
Yi Jin | 6c6e9ca | 2018-03-20 16:53:35 -0700 | [diff] [blame] | 178 | import com.android.server.am.MemInfoDumpProto; |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 179 | |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 180 | import dalvik.system.CloseGuard; |
| 181 | import dalvik.system.VMDebug; |
| 182 | import dalvik.system.VMRuntime; |
| 183 | |
Jeff Sharkey | bc2ae00 | 2018-07-31 10:45:37 -0600 | [diff] [blame] | 184 | import libcore.io.ForwardingOs; |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 185 | import libcore.io.IoUtils; |
Jeff Sharkey | bc2ae00 | 2018-07-31 10:45:37 -0600 | [diff] [blame] | 186 | import libcore.io.Os; |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 187 | import libcore.net.event.NetworkEventDispatcher; |
| 188 | |
| 189 | import org.apache.harmony.dalvik.ddmc.DdmVmInternal; |
| 190 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 191 | import java.io.File; |
| 192 | import java.io.FileDescriptor; |
Jeff Sharkey | bc2ae00 | 2018-07-31 10:45:37 -0600 | [diff] [blame] | 193 | import java.io.FileNotFoundException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 194 | import java.io.FileOutputStream; |
Dianne Hackborn | 9c8dd55 | 2009-06-23 19:22:52 -0700 | [diff] [blame] | 195 | import java.io.IOException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 196 | import java.io.PrintWriter; |
| 197 | import java.lang.ref.WeakReference; |
Torne (Richard Coles) | 466cbe4 | 2017-05-31 14:09:14 -0400 | [diff] [blame] | 198 | import java.lang.reflect.Method; |
Robert Greenwalt | 03595d0 | 2010-11-02 14:08:23 -0700 | [diff] [blame] | 199 | import java.net.InetAddress; |
Alex Light | 330e8be | 2019-08-12 10:58:29 -0700 | [diff] [blame] | 200 | import java.nio.file.Files; |
| 201 | import java.nio.file.Path; |
Narayan Kamath | ccb2a086 | 2013-12-19 14:49:36 +0000 | [diff] [blame] | 202 | import java.text.DateFormat; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 203 | import java.util.ArrayList; |
Jeff Sharkey | a6bfeae | 2017-07-05 16:50:24 -0600 | [diff] [blame] | 204 | import java.util.Arrays; |
Riddle Hsu | d3062cb | 2018-06-30 02:06:42 +0800 | [diff] [blame] | 205 | import java.util.Collections; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 206 | import java.util.List; |
Adam Lesinski | b61e405 | 2016-05-19 18:23:05 -0700 | [diff] [blame] | 207 | import java.util.Locale; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 208 | import java.util.Map; |
Kenny Root | e6585b3 | 2013-12-13 12:00:26 -0800 | [diff] [blame] | 209 | import java.util.Objects; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 210 | import java.util.TimeZone; |
Jeff Sharkey | 8439ac0 | 2017-12-12 17:26:23 -0700 | [diff] [blame] | 211 | import java.util.concurrent.Executor; |
Riddle Hsu | 50e3400 | 2019-04-12 20:42:05 +0800 | [diff] [blame] | 212 | import java.util.concurrent.atomic.AtomicInteger; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 213 | |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 214 | final class RemoteServiceException extends AndroidRuntimeException { |
| 215 | public RemoteServiceException(String msg) { |
| 216 | super(msg); |
| 217 | } |
| 218 | } |
| 219 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 220 | /** |
| 221 | * This manages the execution of the main thread in an |
| 222 | * application process, scheduling and executing activities, |
| 223 | * broadcasts, and other operations on it as the activity |
| 224 | * manager requests. |
| 225 | * |
| 226 | * {@hide} |
| 227 | */ |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 228 | public final class ActivityThread extends ClientTransactionHandler { |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 229 | /** @hide */ |
| 230 | public static final String TAG = "ActivityThread"; |
Jim Miller | 0b2a6d0 | 2010-07-13 18:01:29 -0700 | [diff] [blame] | 231 | 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] | 232 | static final boolean localLOGV = false; |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 233 | static final boolean DEBUG_MESSAGES = false; |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 234 | /** @hide */ |
| 235 | public static final boolean DEBUG_BROADCAST = false; |
Chris Tate | 8a7dc17 | 2009-03-24 20:11:42 -0700 | [diff] [blame] | 236 | private static final boolean DEBUG_RESULTS = false; |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 237 | private static final boolean DEBUG_BACKUP = false; |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 238 | public static final boolean DEBUG_CONFIGURATION = false; |
Dianne Hackborn | a0c283e | 2012-02-09 10:47:01 -0800 | [diff] [blame] | 239 | private static final boolean DEBUG_SERVICE = false; |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 240 | public static final boolean DEBUG_MEMORY_TRIM = false; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 241 | private static final boolean DEBUG_PROVIDER = false; |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 242 | public static final boolean DEBUG_ORDER = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 243 | private static final long MIN_TIME_BETWEEN_GCS = 5*1000; |
Riddle Hsu | 4e8e3b0 | 2019-04-12 17:37:10 +0800 | [diff] [blame] | 244 | /** |
Riddle Hsu | 50e3400 | 2019-04-12 20:42:05 +0800 | [diff] [blame] | 245 | * If the activity doesn't become idle in time, the timeout will ensure to apply the pending top |
| 246 | * process state. |
| 247 | */ |
| 248 | private static final long PENDING_TOP_PROCESS_STATE_TIMEOUT = 1000; |
| 249 | /** |
Riddle Hsu | 4e8e3b0 | 2019-04-12 17:37:10 +0800 | [diff] [blame] | 250 | * The delay to release the provider when it has no more references. It reduces the number of |
| 251 | * transactions for acquiring and releasing provider if the client accesses the provider |
| 252 | * frequently in a short time. |
| 253 | */ |
| 254 | private static final long CONTENT_PROVIDER_RETAIN_TIME = 1000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 255 | private static final int SQLITE_MEM_RELEASED_EVENT_LOG_TAG = 75003; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 256 | |
Dianne Hackborn | 455625e | 2015-01-21 09:55:13 -0800 | [diff] [blame] | 257 | /** Type for IActivityManager.serviceDoneExecuting: anonymous operation */ |
| 258 | public static final int SERVICE_DONE_EXECUTING_ANON = 0; |
| 259 | /** Type for IActivityManager.serviceDoneExecuting: done with an onStart call */ |
| 260 | public static final int SERVICE_DONE_EXECUTING_START = 1; |
| 261 | /** Type for IActivityManager.serviceDoneExecuting: done stopping (destroying) service */ |
| 262 | public static final int SERVICE_DONE_EXECUTING_STOP = 2; |
| 263 | |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 264 | // Whether to invoke an activity callback after delivering new configuration. |
| 265 | private static final boolean REPORT_TO_ACTIVITY = true; |
| 266 | |
Riddle Hsu | 50e3400 | 2019-04-12 20:42:05 +0800 | [diff] [blame] | 267 | /** Use foreground GC policy (less pause time) and higher JIT weight. */ |
| 268 | private static final int VM_PROCESS_STATE_JANK_PERCEPTIBLE = 0; |
| 269 | /** Use background GC policy and default JIT threshold. */ |
| 270 | private static final int VM_PROCESS_STATE_JANK_IMPERCEPTIBLE = 1; |
| 271 | |
Sudheer Shanka | 84a4895 | 2017-03-08 18:19:01 -0800 | [diff] [blame] | 272 | /** |
| 273 | * Denotes an invalid sequence number corresponding to a process state change. |
| 274 | */ |
| 275 | public static final long INVALID_PROC_STATE_SEQ = -1; |
| 276 | |
Sudheer Shanka | f669010 | 2017-10-16 10:20:32 -0700 | [diff] [blame] | 277 | /** |
| 278 | * Identifier for the sequence no. associated with this process start. It will be provided |
| 279 | * as one of the arguments when the process starts. |
| 280 | */ |
| 281 | public static final String PROC_START_SEQ_IDENT = "seq="; |
| 282 | |
Sudheer Shanka | 84a4895 | 2017-03-08 18:19:01 -0800 | [diff] [blame] | 283 | private final Object mNetworkPolicyLock = new Object(); |
| 284 | |
| 285 | /** |
| 286 | * Denotes the sequence number of the process state change for which the main thread needs |
| 287 | * to block until the network rules are updated for it. |
| 288 | * |
| 289 | * Value of {@link #INVALID_PROC_STATE_SEQ} indicates there is no need for blocking. |
| 290 | */ |
| 291 | @GuardedBy("mNetworkPolicyLock") |
| 292 | private long mNetworkBlockSeq = INVALID_PROC_STATE_SEQ; |
| 293 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 294 | @UnsupportedAppUsage |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 295 | private ContextImpl mSystemContext; |
Adam Lesinski | a82b626 | 2017-03-21 16:56:17 -0700 | [diff] [blame] | 296 | private ContextImpl mSystemUiContext; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 297 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 298 | @UnsupportedAppUsage |
Jeff Sharkey | d589663 | 2016-03-04 16:16:00 -0700 | [diff] [blame] | 299 | static volatile IPackageManager sPackageManager; |
Todd Kennedy | 8f13598 | 2019-07-02 07:35:15 -0700 | [diff] [blame] | 300 | private static volatile IPermissionManager sPermissionManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 301 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 302 | @UnsupportedAppUsage |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 303 | final ApplicationThread mAppThread = new ApplicationThread(); |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 304 | @UnsupportedAppUsage |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 305 | final Looper mLooper = Looper.myLooper(); |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 306 | @UnsupportedAppUsage |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 307 | final H mH = new H(); |
Jeff Sharkey | 8439ac0 | 2017-12-12 17:26:23 -0700 | [diff] [blame] | 308 | final Executor mExecutor = new HandlerExecutor(mH); |
Garfield Tan | 0443b37 | 2019-01-04 15:00:13 -0800 | [diff] [blame] | 309 | /** |
| 310 | * Maps from activity token to local record of running activities in this process. |
| 311 | * |
| 312 | * This variable is readable if the code is running in activity thread or holding {@link |
| 313 | * #mResourcesManager}. It's only writable if the code is running in activity thread and holding |
| 314 | * {@link #mResourcesManager}. |
| 315 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 316 | @UnsupportedAppUsage |
Dianne Hackborn | 782d498 | 2015-07-08 17:36:37 -0700 | [diff] [blame] | 317 | final ArrayMap<IBinder, ActivityClientRecord> mActivities = new ArrayMap<>(); |
Riddle Hsu | 66b74a8 | 2018-07-26 00:20:12 +0800 | [diff] [blame] | 318 | /** The activities to be truly destroyed (not include relaunch). */ |
Riddle Hsu | d3062cb | 2018-06-30 02:06:42 +0800 | [diff] [blame] | 319 | final Map<IBinder, ClientTransactionItem> mActivitiesToBeDestroyed = |
| 320 | Collections.synchronizedMap(new ArrayMap<IBinder, ClientTransactionItem>()); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 321 | // List of new activities (via ActivityRecord.nextIdle) that should |
| 322 | // be reported when next we idle. |
| 323 | ActivityClientRecord mNewActivities = null; |
| 324 | // Number of activities that are currently visible on-screen. |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 325 | @UnsupportedAppUsage |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 326 | int mNumVisibleActivities = 0; |
Riddle Hsu | 50e3400 | 2019-04-12 20:42:05 +0800 | [diff] [blame] | 327 | private final AtomicInteger mNumLaunchingActivities = new AtomicInteger(); |
| 328 | @GuardedBy("mAppThread") |
| 329 | private int mLastProcessState = PROCESS_STATE_UNKNOWN; |
| 330 | @GuardedBy("mAppThread") |
| 331 | private int mPendingProcessState = PROCESS_STATE_UNKNOWN; |
Amith Yamasani | 4f128e4 | 2016-05-10 11:44:12 -0700 | [diff] [blame] | 332 | ArrayList<WeakReference<AssistStructure>> mLastAssistStructures = new ArrayList<>(); |
| 333 | private int mLastSessionId; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 334 | @UnsupportedAppUsage |
Dianne Hackborn | 782d498 | 2015-07-08 17:36:37 -0700 | [diff] [blame] | 335 | final ArrayMap<IBinder, Service> mServices = new ArrayMap<>(); |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 336 | @UnsupportedAppUsage |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 337 | AppBindData mBoundApplication; |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 338 | Profiler mProfiler; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 339 | @UnsupportedAppUsage |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 340 | int mCurDefaultDisplayDpi; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 341 | @UnsupportedAppUsage |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 342 | boolean mDensityCompatMode; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 343 | @UnsupportedAppUsage |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 344 | Configuration mConfiguration; |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 345 | Configuration mCompatConfiguration; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 346 | @UnsupportedAppUsage |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 347 | Application mInitialApplication; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 348 | @UnsupportedAppUsage |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 349 | final ArrayList<Application> mAllApplications |
| 350 | = new ArrayList<Application>(); |
Annie Meng | d582787 | 2019-01-30 20:28:57 +0000 | [diff] [blame] | 351 | /** |
| 352 | * Bookkeeping of instantiated backup agents indexed first by user id, then by package name. |
| 353 | * Indexing by user id supports parallel backups across users on system packages as they run in |
| 354 | * the same process with the same package name. Indexing by package name supports multiple |
| 355 | * distinct applications running in the same process. |
| 356 | */ |
| 357 | private final SparseArray<ArrayMap<String, BackupAgent>> mBackupAgentsByUser = |
| 358 | new SparseArray<>(); |
Jeff Sharkey | 66a017b | 2013-01-17 18:18:22 -0800 | [diff] [blame] | 359 | /** Reference to singleton {@link ActivityThread} */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 360 | @UnsupportedAppUsage |
Jeff Sharkey | d589663 | 2016-03-04 16:16:00 -0700 | [diff] [blame] | 361 | private static volatile ActivityThread sCurrentActivityThread; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 362 | @UnsupportedAppUsage |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 363 | Instrumentation mInstrumentation; |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 364 | String mInstrumentationPackageName = null; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 365 | @UnsupportedAppUsage |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 366 | String mInstrumentationAppDir = null; |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 367 | String[] mInstrumentationSplitAppDirs = null; |
| 368 | String mInstrumentationLibDir = null; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 369 | @UnsupportedAppUsage |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 370 | String mInstrumentedAppDir = null; |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 371 | String[] mInstrumentedSplitAppDirs = null; |
| 372 | String mInstrumentedLibDir = null; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 373 | boolean mSystemThread = false; |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 374 | boolean mSomeActivitiesChanged = false; |
Chong Zhang | 4951f9d | 2016-06-23 13:15:08 -0700 | [diff] [blame] | 375 | boolean mUpdatingSystemConfig = false; |
David Brazdil | d960cc4 | 2018-01-31 07:59:17 +0000 | [diff] [blame] | 376 | /* package */ boolean mHiddenApiWarningShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 377 | |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 378 | // These can be accessed by multiple threads; mResourcesManager is the lock. |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 379 | // XXX For now we keep around information about all packages we have |
| 380 | // seen, not removing entries from this map. |
Dianne Hackborn | 1fbee79 | 2011-11-30 11:29:58 -0800 | [diff] [blame] | 381 | // NOTE: The activity and window managers need to call in to |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 382 | // ActivityThread to do things like update resource configurations, |
Dianne Hackborn | 1fbee79 | 2011-11-30 11:29:58 -0800 | [diff] [blame] | 383 | // which means this lock gets held while the activity and window managers |
| 384 | // holds their own lock. Thus you MUST NEVER call back into the activity manager |
| 385 | // 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] | 386 | // 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] | 387 | @GuardedBy("mResourcesManager") |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 388 | @UnsupportedAppUsage |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 389 | final ArrayMap<String, WeakReference<LoadedApk>> mPackages = new ArrayMap<>(); |
| 390 | @GuardedBy("mResourcesManager") |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 391 | @UnsupportedAppUsage |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 392 | final ArrayMap<String, WeakReference<LoadedApk>> mResourcePackages = new ArrayMap<>(); |
| 393 | @GuardedBy("mResourcesManager") |
| 394 | final ArrayList<ActivityClientRecord> mRelaunchingActivities = new ArrayList<>(); |
| 395 | @GuardedBy("mResourcesManager") |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 396 | @UnsupportedAppUsage |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 397 | Configuration mPendingConfiguration = null; |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 398 | // An executor that performs multi-step transactions. |
| 399 | private final TransactionExecutor mTransactionExecutor = new TransactionExecutor(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 400 | |
Mathew Inwood | 8c854f8 | 2018-09-14 12:35:36 +0100 | [diff] [blame] | 401 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 402 | private final ResourcesManager mResourcesManager; |
| 403 | |
Svet Ganov | 3b6be08 | 2019-04-28 10:21:01 -0700 | [diff] [blame] | 404 | // Registry of remote cancellation transports pending a reply with reply handles. |
| 405 | @GuardedBy("this") |
| 406 | private @Nullable Map<SafeCancellationTransport, CancellationSignal> mRemoteCancellations; |
| 407 | |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 408 | private static final class ProviderKey { |
| 409 | final String authority; |
| 410 | final int userId; |
| 411 | |
| 412 | public ProviderKey(String authority, int userId) { |
| 413 | this.authority = authority; |
| 414 | this.userId = userId; |
| 415 | } |
| 416 | |
| 417 | @Override |
| 418 | public boolean equals(Object o) { |
| 419 | if (o instanceof ProviderKey) { |
| 420 | final ProviderKey other = (ProviderKey) o; |
Kenny Root | e6585b3 | 2013-12-13 12:00:26 -0800 | [diff] [blame] | 421 | return Objects.equals(authority, other.authority) && userId == other.userId; |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 422 | } |
| 423 | return false; |
| 424 | } |
| 425 | |
| 426 | @Override |
| 427 | public int hashCode() { |
| 428 | return ((authority != null) ? authority.hashCode() : 0) ^ userId; |
| 429 | } |
| 430 | } |
| 431 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 432 | // The lock of mProviderMap protects the following variables. |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 433 | @UnsupportedAppUsage |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 434 | final ArrayMap<ProviderKey, ProviderClientRecord> mProviderMap |
| 435 | = new ArrayMap<ProviderKey, ProviderClientRecord>(); |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 436 | @UnsupportedAppUsage |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 437 | final ArrayMap<IBinder, ProviderRefCount> mProviderRefCountMap |
| 438 | = new ArrayMap<IBinder, ProviderRefCount>(); |
Mathew Inwood | 8c854f8 | 2018-09-14 12:35:36 +0100 | [diff] [blame] | 439 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 440 | final ArrayMap<IBinder, ProviderClientRecord> mLocalProviders |
| 441 | = new ArrayMap<IBinder, ProviderClientRecord>(); |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 442 | @UnsupportedAppUsage |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 443 | final ArrayMap<ComponentName, ProviderClientRecord> mLocalProvidersByName |
| 444 | = new ArrayMap<ComponentName, ProviderClientRecord>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 445 | |
Makoto Onuki | b6c79ea | 2018-05-31 11:03:56 -0700 | [diff] [blame] | 446 | // Mitigation for b/74523247: Used to serialize calls to AM.getContentProvider(). |
| 447 | // Note we never removes items from this map but that's okay because there are only so many |
| 448 | // users and so many authorities. |
| 449 | // TODO Remove it once we move CPR.wait() from AMS to the client side. |
| 450 | @GuardedBy("mGetProviderLocks") |
| 451 | final ArrayMap<ProviderKey, Object> mGetProviderLocks = new ArrayMap<>(); |
| 452 | |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 453 | final ArrayMap<Activity, ArrayList<OnActivityPausedListener>> mOnPauseListeners |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 454 | = new ArrayMap<Activity, ArrayList<OnActivityPausedListener>>(); |
Jeff Hamilton | 52d3203 | 2011-01-08 15:31:26 -0600 | [diff] [blame] | 455 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 456 | final GcIdler mGcIdler = new GcIdler(); |
Tim Murray | 59f3dc1 | 2018-10-22 15:26:08 -0700 | [diff] [blame] | 457 | final PurgeIdler mPurgeIdler = new PurgeIdler(); |
| 458 | |
| 459 | boolean mPurgeIdlerScheduled = false; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 460 | boolean mGcIdlerScheduled = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 461 | |
Mathew Inwood | 8c854f8 | 2018-09-14 12:35:36 +0100 | [diff] [blame] | 462 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Jeff Sharkey | d589663 | 2016-03-04 16:16:00 -0700 | [diff] [blame] | 463 | static volatile Handler sMainThreadHandler; // set once in main() |
Brad Fitzpatrick | 333b8cb | 2010-08-26 12:04:57 -0700 | [diff] [blame] | 464 | |
Svetoslav Ganov | 9aa597e | 2011-03-03 18:17:41 -0800 | [diff] [blame] | 465 | Bundle mCoreSettings = null; |
| 466 | |
lumark | ddc77fb | 2019-06-27 22:22:23 +0800 | [diff] [blame] | 467 | boolean mHasImeComponent = false; |
| 468 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 469 | /** Activity client record, used for bookkeeping for the real {@link Activity} instance. */ |
| 470 | public static final class ActivityClientRecord { |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 471 | @UnsupportedAppUsage |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 472 | public IBinder token; |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 473 | public IBinder assistToken; |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 474 | int ident; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 475 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 476 | Intent intent; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 477 | String referrer; |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 478 | IVoiceInteractor voiceInteractor; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 479 | Bundle state; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 480 | PersistableBundle persistentState; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 481 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 482 | Activity activity; |
| 483 | Window window; |
| 484 | Activity parent; |
| 485 | String embeddedID; |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 486 | Activity.NonConfigurationInstances lastNonConfigurationInstances; |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 487 | // TODO(lifecycler): Use mLifecycleState instead. |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 488 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 489 | boolean paused; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 490 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 491 | boolean stopped; |
| 492 | boolean hideForNow; |
| 493 | Configuration newConfig; |
Dianne Hackborn | e88846e | 2009-09-30 21:34:25 -0700 | [diff] [blame] | 494 | Configuration createdConfig; |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 495 | Configuration overrideConfig; |
Garfield Tan | 0443b37 | 2019-01-04 15:00:13 -0800 | [diff] [blame] | 496 | // Used to save the last reported configuration from server side so that activity |
| 497 | // configuration transactions can always use the latest configuration. |
| 498 | @GuardedBy("this") |
| 499 | private Configuration mPendingOverrideConfig; |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 500 | // Used for consolidating configs before sending on to Activity. |
| 501 | private Configuration tmpConfig = new Configuration(); |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 502 | // Callback used for updating activity override config. |
| 503 | ViewRootImpl.ActivityConfigCallback configCallback; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 504 | ActivityClientRecord nextIdle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 505 | |
Andrii Kulian | d70cdb9 | 2019-01-08 15:03:50 -0800 | [diff] [blame] | 506 | // Indicates whether this activity is currently the topmost resumed one in the system. |
| 507 | // This holds the last reported value from server. |
| 508 | boolean isTopResumedActivity; |
| 509 | // This holds the value last sent to the activity. This is needed, because an update from |
| 510 | // server may come at random time, but we always need to report changes between ON_RESUME |
| 511 | // and ON_PAUSE to the app. |
| 512 | boolean lastReportedTopResumedState; |
| 513 | |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 514 | ProfilerInfo profilerInfo; |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 515 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 516 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 517 | ActivityInfo activityInfo; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 518 | @UnsupportedAppUsage |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 519 | CompatibilityInfo compatInfo; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 520 | @UnsupportedAppUsage |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 521 | public LoadedApk packageInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 522 | |
| 523 | List<ResultInfo> pendingResults; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 524 | List<ReferrerIntent> pendingIntents; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 525 | |
| 526 | boolean startsNotResumed; |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 527 | public final boolean isForward; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 528 | int pendingConfigChanges; |
jorgegil@google.com | 06bc323 | 2019-10-31 14:51:22 -0700 | [diff] [blame] | 529 | // Whether we are in the process of performing on user leaving. |
| 530 | boolean mIsUserLeaving; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 531 | |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 532 | Window mPendingRemoveWindow; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 533 | WindowManager mPendingRemoveWindowManager; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 534 | @UnsupportedAppUsage |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 535 | boolean mPreserveWindow; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 536 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 537 | @LifecycleState |
| 538 | private int mLifecycleState = PRE_ON_CREATE; |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 539 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 540 | @VisibleForTesting |
Mathew Inwood | 8c854f8 | 2018-09-14 12:35:36 +0100 | [diff] [blame] | 541 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 542 | public ActivityClientRecord() { |
| 543 | this.isForward = false; |
| 544 | init(); |
| 545 | } |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 546 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 547 | public ActivityClientRecord(IBinder token, Intent intent, int ident, |
| 548 | ActivityInfo info, Configuration overrideConfig, CompatibilityInfo compatInfo, |
| 549 | String referrer, IVoiceInteractor voiceInteractor, Bundle state, |
| 550 | PersistableBundle persistentState, List<ResultInfo> pendingResults, |
| 551 | List<ReferrerIntent> pendingNewIntents, boolean isForward, |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 552 | ProfilerInfo profilerInfo, ClientTransactionHandler client, |
| 553 | IBinder assistToken) { |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 554 | this.token = token; |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 555 | this.assistToken = assistToken; |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 556 | this.ident = ident; |
| 557 | this.intent = intent; |
| 558 | this.referrer = referrer; |
| 559 | this.voiceInteractor = voiceInteractor; |
| 560 | this.activityInfo = info; |
| 561 | this.compatInfo = compatInfo; |
| 562 | this.state = state; |
| 563 | this.persistentState = persistentState; |
| 564 | this.pendingResults = pendingResults; |
| 565 | this.pendingIntents = pendingNewIntents; |
| 566 | this.isForward = isForward; |
| 567 | this.profilerInfo = profilerInfo; |
| 568 | this.overrideConfig = overrideConfig; |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 569 | this.packageInfo = client.getPackageInfoNoCheck(activityInfo.applicationInfo, |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 570 | compatInfo); |
| 571 | init(); |
| 572 | } |
| 573 | |
| 574 | /** Common initializer for all constructors. */ |
| 575 | private void init() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 576 | parent = null; |
| 577 | embeddedID = null; |
| 578 | paused = false; |
| 579 | stopped = false; |
| 580 | hideForNow = false; |
| 581 | nextIdle = null; |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 582 | configCallback = (Configuration overrideConfig, int newDisplayId) -> { |
| 583 | if (activity == null) { |
| 584 | throw new IllegalStateException( |
| 585 | "Received config update for non-existing activity"); |
| 586 | } |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 587 | activity.mMainThread.handleActivityConfigurationChanged(token, overrideConfig, |
| 588 | newDisplayId); |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 589 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 590 | } |
| 591 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 592 | /** Get the current lifecycle state. */ |
| 593 | public int getLifecycleState() { |
| 594 | return mLifecycleState; |
| 595 | } |
| 596 | |
| 597 | /** Update the current lifecycle state for internal bookkeeping. */ |
| 598 | public void setState(@LifecycleState int newLifecycleState) { |
| 599 | mLifecycleState = newLifecycleState; |
| 600 | switch (mLifecycleState) { |
| 601 | case ON_CREATE: |
| 602 | paused = true; |
| 603 | stopped = true; |
| 604 | break; |
| 605 | case ON_START: |
| 606 | paused = true; |
| 607 | stopped = false; |
| 608 | break; |
| 609 | case ON_RESUME: |
| 610 | paused = false; |
| 611 | stopped = false; |
| 612 | break; |
| 613 | case ON_PAUSE: |
| 614 | paused = true; |
| 615 | stopped = false; |
| 616 | break; |
| 617 | case ON_STOP: |
| 618 | paused = true; |
| 619 | stopped = true; |
| 620 | break; |
| 621 | } |
| 622 | } |
| 623 | |
Andrii Kulian | 391161f | 2018-01-29 10:50:02 -0800 | [diff] [blame] | 624 | private boolean isPreHoneycomb() { |
| 625 | return activity != null && activity.getApplicationInfo().targetSdkVersion |
| 626 | < android.os.Build.VERSION_CODES.HONEYCOMB; |
| 627 | } |
| 628 | |
| 629 | private boolean isPreP() { |
| 630 | return activity != null && activity.getApplicationInfo().targetSdkVersion |
| 631 | < android.os.Build.VERSION_CODES.P; |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 632 | } |
| 633 | |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 634 | public boolean isPersistable() { |
Craig Mautner | 43e52ed | 2014-06-16 17:18:52 -0700 | [diff] [blame] | 635 | return activityInfo.persistableMode == ActivityInfo.PERSIST_ACROSS_REBOOTS; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 636 | } |
| 637 | |
Andrii Kulian | 914aa7d | 2018-03-19 21:51:53 -0700 | [diff] [blame] | 638 | public boolean isVisibleFromServer() { |
| 639 | return activity != null && activity.mVisibleFromServer; |
| 640 | } |
| 641 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 642 | public String toString() { |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 643 | ComponentName componentName = intent != null ? intent.getComponent() : null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 644 | return "ActivityRecord{" |
| 645 | + Integer.toHexString(System.identityHashCode(this)) |
| 646 | + " token=" + token + " " + (componentName == null |
| 647 | ? "no component name" : componentName.toShortString()) |
| 648 | + "}"; |
| 649 | } |
Andrii Kulian | 58178f2 | 2016-03-16 13:44:56 -0700 | [diff] [blame] | 650 | |
| 651 | public String getStateString() { |
| 652 | StringBuilder sb = new StringBuilder(); |
| 653 | sb.append("ActivityClientRecord{"); |
| 654 | sb.append("paused=").append(paused); |
| 655 | sb.append(", stopped=").append(stopped); |
| 656 | sb.append(", hideForNow=").append(hideForNow); |
| 657 | sb.append(", startsNotResumed=").append(startsNotResumed); |
| 658 | sb.append(", isForward=").append(isForward); |
| 659 | sb.append(", pendingConfigChanges=").append(pendingConfigChanges); |
Andrii Kulian | 58178f2 | 2016-03-16 13:44:56 -0700 | [diff] [blame] | 660 | sb.append(", preserveWindow=").append(mPreserveWindow); |
| 661 | if (activity != null) { |
| 662 | sb.append(", Activity{"); |
| 663 | sb.append("resumed=").append(activity.mResumed); |
| 664 | sb.append(", stopped=").append(activity.mStopped); |
| 665 | sb.append(", finished=").append(activity.isFinishing()); |
| 666 | sb.append(", destroyed=").append(activity.isDestroyed()); |
| 667 | sb.append(", startedActivity=").append(activity.mStartedActivity); |
Andrii Kulian | 58178f2 | 2016-03-16 13:44:56 -0700 | [diff] [blame] | 668 | sb.append(", changingConfigurations=").append(activity.mChangingConfigurations); |
Andrii Kulian | 58178f2 | 2016-03-16 13:44:56 -0700 | [diff] [blame] | 669 | sb.append("}"); |
| 670 | } |
| 671 | sb.append("}"); |
| 672 | return sb.toString(); |
| 673 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 674 | } |
| 675 | |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 676 | final class ProviderClientRecord { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 677 | final String[] mNames; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 678 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 679 | final IContentProvider mProvider; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 680 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 681 | final ContentProvider mLocalProvider; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 682 | @UnsupportedAppUsage |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 683 | final ContentProviderHolder mHolder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 684 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 685 | ProviderClientRecord(String[] names, IContentProvider provider, |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 686 | ContentProvider localProvider, ContentProviderHolder holder) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 687 | mNames = names; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 688 | mProvider = provider; |
| 689 | mLocalProvider = localProvider; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 690 | mHolder = holder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 691 | } |
| 692 | } |
| 693 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 694 | static final class ReceiverData extends BroadcastReceiver.PendingResult { |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 695 | public ReceiverData(Intent intent, int resultCode, String resultData, Bundle resultExtras, |
Dianne Hackborn | 20e8098 | 2012-08-31 19:00:44 -0700 | [diff] [blame] | 696 | boolean ordered, boolean sticky, IBinder token, int sendingUser) { |
| 697 | super(resultCode, resultData, resultExtras, TYPE_COMPONENT, ordered, sticky, |
riddle_hsu | 1f5ac4d | 2015-01-03 15:38:21 +0800 | [diff] [blame] | 698 | token, sendingUser, intent.getFlags()); |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 699 | this.intent = intent; |
| 700 | } |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 701 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 702 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 703 | Intent intent; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 704 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 705 | ActivityInfo info; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 706 | @UnsupportedAppUsage |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 707 | CompatibilityInfo compatInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 708 | public String toString() { |
| 709 | return "ReceiverData{intent=" + intent + " packageName=" + |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 710 | info.packageName + " resultCode=" + getResultCode() |
| 711 | + " resultData=" + getResultData() + " resultExtras=" |
| 712 | + getResultExtras(false) + "}"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 713 | } |
| 714 | } |
| 715 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 716 | static final class CreateBackupAgentData { |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 717 | ApplicationInfo appInfo; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 718 | CompatibilityInfo compatInfo; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 719 | int backupMode; |
Ruslan Tkhakokhov | 063180f | 2019-01-28 20:29:46 +0000 | [diff] [blame] | 720 | int userId; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 721 | public String toString() { |
| 722 | return "CreateBackupAgentData{appInfo=" + appInfo |
| 723 | + " backupAgent=" + appInfo.backupAgentName |
Ruslan Tkhakokhov | 063180f | 2019-01-28 20:29:46 +0000 | [diff] [blame] | 724 | + " mode=" + backupMode + " userId=" + userId + "}"; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 725 | } |
| 726 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 727 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 728 | static final class CreateServiceData { |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 729 | @UnsupportedAppUsage |
Artur Satayev | 751e551 | 2019-11-15 19:12:49 +0000 | [diff] [blame] | 730 | CreateServiceData() { |
| 731 | } |
| 732 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 733 | IBinder token; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 734 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 735 | ServiceInfo info; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 736 | @UnsupportedAppUsage |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 737 | CompatibilityInfo compatInfo; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 738 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 739 | Intent intent; |
| 740 | public String toString() { |
| 741 | return "CreateServiceData{token=" + token + " className=" |
| 742 | + info.name + " packageName=" + info.packageName |
| 743 | + " intent=" + intent + "}"; |
| 744 | } |
| 745 | } |
| 746 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 747 | static final class BindServiceData { |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 748 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 749 | IBinder token; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 750 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 751 | Intent intent; |
| 752 | boolean rebind; |
| 753 | public String toString() { |
| 754 | return "BindServiceData{token=" + token + " intent=" + intent + "}"; |
| 755 | } |
| 756 | } |
| 757 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 758 | static final class ServiceArgsData { |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 759 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 760 | IBinder token; |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 761 | boolean taskRemoved; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 762 | int startId; |
Dianne Hackborn | f6f9f2d | 2009-08-21 16:26:03 -0700 | [diff] [blame] | 763 | int flags; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 764 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 765 | Intent args; |
| 766 | public String toString() { |
| 767 | return "ServiceArgsData{token=" + token + " startId=" + startId |
| 768 | + " args=" + args + "}"; |
| 769 | } |
| 770 | } |
| 771 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 772 | static final class AppBindData { |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 773 | @UnsupportedAppUsage |
Artur Satayev | 751e551 | 2019-11-15 19:12:49 +0000 | [diff] [blame] | 774 | AppBindData() { |
| 775 | } |
| 776 | @UnsupportedAppUsage |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 777 | LoadedApk info; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 778 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 779 | String processName; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 780 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 781 | ApplicationInfo appInfo; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 782 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 783 | List<ProviderInfo> providers; |
| 784 | ComponentName instrumentationName; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 785 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 786 | Bundle instrumentationArgs; |
| 787 | IInstrumentationWatcher instrumentationWatcher; |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 788 | IUiAutomationConnection instrumentationUiAutomationConnection; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 789 | int debugMode; |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 790 | boolean enableBinderTracking; |
Man Cao | cfa78b2 | 2015-06-11 20:14:34 -0700 | [diff] [blame] | 791 | boolean trackAllocation; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 792 | @UnsupportedAppUsage |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 793 | boolean restrictedBackupMode; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 794 | @UnsupportedAppUsage |
Dianne Hackborn | 5d927c2 | 2011-09-02 12:22:18 -0700 | [diff] [blame] | 795 | boolean persistent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 796 | Configuration config; |
Mathew Inwood | 8c854f8 | 2018-09-14 12:35:36 +0100 | [diff] [blame] | 797 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 798 | CompatibilityInfo compatInfo; |
Svet Ganov | 37e4327 | 2016-09-09 16:01:32 -0700 | [diff] [blame] | 799 | String buildSerial; |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 800 | |
| 801 | /** Initial values for {@link Profiler}. */ |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 802 | ProfilerInfo initProfilerInfo; |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 803 | |
Felipe Leme | a4f39cd | 2019-02-19 15:08:59 -0800 | [diff] [blame] | 804 | AutofillOptions autofillOptions; |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 805 | |
Felipe Leme | 326f15a | 2019-02-19 09:42:24 -0800 | [diff] [blame] | 806 | /** |
| 807 | * Content capture options for the application - when null, it means ContentCapture is not |
| 808 | * enabled for the package. |
| 809 | */ |
| 810 | @Nullable |
| 811 | ContentCaptureOptions contentCaptureOptions; |
| 812 | |
Mathew Inwood | 80652db | 2019-06-24 12:07:22 +0100 | [diff] [blame] | 813 | long[] disabledCompatChanges; |
| 814 | |
Felipe Leme | 326f15a | 2019-02-19 09:42:24 -0800 | [diff] [blame] | 815 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 816 | public String toString() { |
| 817 | return "AppBindData{appInfo=" + appInfo + "}"; |
| 818 | } |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 819 | } |
| 820 | |
| 821 | static final class Profiler { |
| 822 | String profileFile; |
| 823 | ParcelFileDescriptor profileFd; |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 824 | int samplingInterval; |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 825 | boolean autoStopProfiler; |
Shukang Zhou | 6ffd4f9 | 2017-01-25 16:07:57 -0800 | [diff] [blame] | 826 | boolean streamingOutput; |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 827 | boolean profiling; |
| 828 | boolean handlingProfiling; |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 829 | public void setProfiler(ProfilerInfo profilerInfo) { |
| 830 | ParcelFileDescriptor fd = profilerInfo.profileFd; |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 831 | if (profiling) { |
| 832 | if (fd != null) { |
| 833 | try { |
| 834 | fd.close(); |
| 835 | } catch (IOException e) { |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 836 | // Ignore |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 837 | } |
| 838 | } |
| 839 | return; |
| 840 | } |
| 841 | if (profileFd != null) { |
| 842 | try { |
| 843 | profileFd.close(); |
| 844 | } catch (IOException e) { |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 845 | // Ignore |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 846 | } |
| 847 | } |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 848 | profileFile = profilerInfo.profileFile; |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 849 | profileFd = fd; |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 850 | samplingInterval = profilerInfo.samplingInterval; |
| 851 | autoStopProfiler = profilerInfo.autoStopProfiler; |
Shukang Zhou | 6ffd4f9 | 2017-01-25 16:07:57 -0800 | [diff] [blame] | 852 | streamingOutput = profilerInfo.streamingOutput; |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 853 | } |
| 854 | public void startProfiling() { |
| 855 | if (profileFd == null || profiling) { |
| 856 | return; |
| 857 | } |
| 858 | try { |
Andreas Gampe | eff0639 | 2016-05-10 12:51:45 -0700 | [diff] [blame] | 859 | int bufferSize = SystemProperties.getInt("debug.traceview-buffer-size-mb", 8); |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 860 | VMDebug.startMethodTracing(profileFile, profileFd.getFileDescriptor(), |
Shukang Zhou | 6ffd4f9 | 2017-01-25 16:07:57 -0800 | [diff] [blame] | 861 | bufferSize * 1024 * 1024, 0, samplingInterval != 0, samplingInterval, |
| 862 | streamingOutput); |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 863 | profiling = true; |
| 864 | } catch (RuntimeException e) { |
Andreas Gampe | 4f68924 | 2018-03-14 23:13:28 -0700 | [diff] [blame] | 865 | Slog.w(TAG, "Profiling failed on path " + profileFile, e); |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 866 | try { |
| 867 | profileFd.close(); |
| 868 | profileFd = null; |
| 869 | } catch (IOException e2) { |
| 870 | Slog.w(TAG, "Failure closing profile fd", e2); |
| 871 | } |
| 872 | } |
| 873 | } |
| 874 | public void stopProfiling() { |
| 875 | if (profiling) { |
| 876 | profiling = false; |
| 877 | Debug.stopMethodTracing(); |
| 878 | if (profileFd != null) { |
| 879 | try { |
| 880 | profileFd.close(); |
| 881 | } catch (IOException e) { |
| 882 | } |
| 883 | } |
| 884 | profileFd = null; |
| 885 | profileFile = null; |
| 886 | } |
| 887 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 888 | } |
| 889 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 890 | static final class DumpComponentInfo { |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 891 | ParcelFileDescriptor fd; |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 892 | IBinder token; |
Dianne Hackborn | 30d7189 | 2010-12-11 10:37:55 -0800 | [diff] [blame] | 893 | String prefix; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 894 | String[] args; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 895 | } |
| 896 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 897 | static final class ContextCleanupInfo { |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 898 | ContextImpl context; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 899 | String what; |
| 900 | String who; |
| 901 | } |
| 902 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 903 | static final class DumpHeapData { |
Kweku Adams | 4af1b50 | 2019-05-23 16:23:48 -0700 | [diff] [blame] | 904 | // Whether to dump the native or managed heap. |
Christopher Ferris | 8d652f8 | 2017-04-11 16:29:18 -0700 | [diff] [blame] | 905 | public boolean managed; |
| 906 | public boolean mallocInfo; |
Makoto Onuki | 4556b7b | 2017-07-07 14:58:58 -0700 | [diff] [blame] | 907 | public boolean runGc; |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 908 | String path; |
| 909 | ParcelFileDescriptor fd; |
Makoto Onuki | 2c6657f | 2018-06-06 15:24:02 -0700 | [diff] [blame] | 910 | RemoteCallback finishCallback; |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 911 | } |
| 912 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 913 | static final class UpdateCompatibilityData { |
| 914 | String pkg; |
| 915 | CompatibilityInfo info; |
| 916 | } |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 917 | |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 918 | static final class RequestAssistContextExtras { |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 919 | IBinder activityToken; |
| 920 | IBinder requestToken; |
| 921 | int requestType; |
Amith Yamasani | 4f128e4 | 2016-05-10 11:44:12 -0700 | [diff] [blame] | 922 | int sessionId; |
Svet Ganov | fd31f85 | 2017-04-26 15:54:27 -0700 | [diff] [blame] | 923 | int flags; |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 924 | } |
Anwar Ghuloum | 3a8ce1b | 2013-04-26 16:18:28 -0700 | [diff] [blame] | 925 | |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 926 | private class ApplicationThread extends IApplicationThread.Stub { |
Vasu Nori | 3c7131f | 2010-09-21 14:36:57 -0700 | [diff] [blame] | 927 | private static final String DB_INFO_FORMAT = " %8s %8s %14s %14s %s"; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 928 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 929 | public final void scheduleReceiver(Intent intent, ActivityInfo info, |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 930 | CompatibilityInfo compatInfo, int resultCode, String data, Bundle extras, |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 931 | boolean sync, int sendingUser, int processState) { |
| 932 | updateProcessState(processState, false); |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 933 | ReceiverData r = new ReceiverData(intent, resultCode, data, extras, |
Dianne Hackborn | 20e8098 | 2012-08-31 19:00:44 -0700 | [diff] [blame] | 934 | sync, false, mAppThread.asBinder(), sendingUser); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 935 | r.info = info; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 936 | r.compatInfo = compatInfo; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 937 | sendMessage(H.RECEIVER, r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 938 | } |
| 939 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 940 | public final void scheduleCreateBackupAgent(ApplicationInfo app, |
Ruslan Tkhakokhov | 063180f | 2019-01-28 20:29:46 +0000 | [diff] [blame] | 941 | CompatibilityInfo compatInfo, int backupMode, int userId) { |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 942 | CreateBackupAgentData d = new CreateBackupAgentData(); |
| 943 | d.appInfo = app; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 944 | d.compatInfo = compatInfo; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 945 | d.backupMode = backupMode; |
Ruslan Tkhakokhov | 063180f | 2019-01-28 20:29:46 +0000 | [diff] [blame] | 946 | d.userId = userId; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 947 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 948 | sendMessage(H.CREATE_BACKUP_AGENT, d); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 949 | } |
| 950 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 951 | public final void scheduleDestroyBackupAgent(ApplicationInfo app, |
Annie Meng | d582787 | 2019-01-30 20:28:57 +0000 | [diff] [blame] | 952 | CompatibilityInfo compatInfo, int userId) { |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 953 | CreateBackupAgentData d = new CreateBackupAgentData(); |
| 954 | d.appInfo = app; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 955 | d.compatInfo = compatInfo; |
Annie Meng | d582787 | 2019-01-30 20:28:57 +0000 | [diff] [blame] | 956 | d.userId = userId; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 957 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 958 | sendMessage(H.DESTROY_BACKUP_AGENT, d); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 959 | } |
| 960 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 961 | public final void scheduleCreateService(IBinder token, |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 962 | ServiceInfo info, CompatibilityInfo compatInfo, int processState) { |
| 963 | updateProcessState(processState, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 964 | CreateServiceData s = new CreateServiceData(); |
| 965 | s.token = token; |
| 966 | s.info = info; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 967 | s.compatInfo = compatInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 968 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 969 | sendMessage(H.CREATE_SERVICE, s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 970 | } |
| 971 | |
| 972 | public final void scheduleBindService(IBinder token, Intent intent, |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 973 | boolean rebind, int processState) { |
| 974 | updateProcessState(processState, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 975 | BindServiceData s = new BindServiceData(); |
| 976 | s.token = token; |
| 977 | s.intent = intent; |
| 978 | s.rebind = rebind; |
| 979 | |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 980 | if (DEBUG_SERVICE) |
| 981 | Slog.v(TAG, "scheduleBindService token=" + token + " intent=" + intent + " uid=" |
| 982 | + Binder.getCallingUid() + " pid=" + Binder.getCallingPid()); |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 983 | sendMessage(H.BIND_SERVICE, s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 984 | } |
| 985 | |
| 986 | public final void scheduleUnbindService(IBinder token, Intent intent) { |
| 987 | BindServiceData s = new BindServiceData(); |
| 988 | s.token = token; |
| 989 | s.intent = intent; |
| 990 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 991 | sendMessage(H.UNBIND_SERVICE, s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 992 | } |
| 993 | |
Dianne Hackborn | 3f7c9f2 | 2017-04-04 15:36:33 -0700 | [diff] [blame] | 994 | public final void scheduleServiceArgs(IBinder token, ParceledListSlice args) { |
| 995 | List<ServiceStartArgs> list = args.getList(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 996 | |
Dianne Hackborn | 3f7c9f2 | 2017-04-04 15:36:33 -0700 | [diff] [blame] | 997 | for (int i = 0; i < list.size(); i++) { |
| 998 | ServiceStartArgs ssa = list.get(i); |
| 999 | ServiceArgsData s = new ServiceArgsData(); |
| 1000 | s.token = token; |
| 1001 | s.taskRemoved = ssa.taskRemoved; |
| 1002 | s.startId = ssa.startId; |
| 1003 | s.flags = ssa.flags; |
| 1004 | s.args = ssa.args; |
| 1005 | |
| 1006 | sendMessage(H.SERVICE_ARGS, s); |
| 1007 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1008 | } |
| 1009 | |
| 1010 | public final void scheduleStopService(IBinder token) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1011 | sendMessage(H.STOP_SERVICE, token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1012 | } |
| 1013 | |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 1014 | public final void bindApplication(String processName, ApplicationInfo appInfo, |
| 1015 | List<ProviderInfo> providers, ComponentName instrumentationName, |
| 1016 | ProfilerInfo profilerInfo, Bundle instrumentationArgs, |
| 1017 | IInstrumentationWatcher instrumentationWatcher, |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 1018 | IUiAutomationConnection instrumentationUiConnection, int debugMode, |
Pablo Ceballos | a4d4e82 | 2015-10-05 10:27:52 -0700 | [diff] [blame] | 1019 | boolean enableBinderTracking, boolean trackAllocation, |
| 1020 | boolean isRestrictedBackupMode, boolean persistent, Configuration config, |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1021 | CompatibilityInfo compatInfo, Map services, Bundle coreSettings, |
Felipe Leme | a4f39cd | 2019-02-19 15:08:59 -0800 | [diff] [blame] | 1022 | String buildSerial, AutofillOptions autofillOptions, |
Mathew Inwood | 80652db | 2019-06-24 12:07:22 +0100 | [diff] [blame] | 1023 | ContentCaptureOptions contentCaptureOptions, long[] disabledCompatChanges) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1024 | if (services != null) { |
Makoto Onuki | 4589565 | 2018-05-07 14:43:05 -0700 | [diff] [blame] | 1025 | if (false) { |
| 1026 | // Test code to make sure the app could see the passed-in services. |
| 1027 | for (Object oname : services.keySet()) { |
| 1028 | if (services.get(oname) == null) { |
| 1029 | continue; // AM just passed in a null service. |
| 1030 | } |
| 1031 | String name = (String) oname; |
| 1032 | |
| 1033 | // See b/79378449 about the following exemption. |
| 1034 | switch (name) { |
| 1035 | case "package": |
| 1036 | case Context.WINDOW_SERVICE: |
| 1037 | continue; |
| 1038 | } |
| 1039 | |
| 1040 | if (ServiceManager.getService(name) == null) { |
| 1041 | Log.wtf(TAG, "Service " + name + " should be accessible by this app"); |
| 1042 | } |
| 1043 | } |
| 1044 | } |
| 1045 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1046 | // Setup the service cache in the ServiceManager |
| 1047 | ServiceManager.initServiceCache(services); |
| 1048 | } |
| 1049 | |
Svetoslav Ganov | 9aa597e | 2011-03-03 18:17:41 -0800 | [diff] [blame] | 1050 | setCoreSettings(coreSettings); |
| 1051 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1052 | AppBindData data = new AppBindData(); |
| 1053 | data.processName = processName; |
| 1054 | data.appInfo = appInfo; |
| 1055 | data.providers = providers; |
| 1056 | data.instrumentationName = instrumentationName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1057 | data.instrumentationArgs = instrumentationArgs; |
| 1058 | data.instrumentationWatcher = instrumentationWatcher; |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 1059 | data.instrumentationUiAutomationConnection = instrumentationUiConnection; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1060 | data.debugMode = debugMode; |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 1061 | data.enableBinderTracking = enableBinderTracking; |
Man Cao | cfa78b2 | 2015-06-11 20:14:34 -0700 | [diff] [blame] | 1062 | data.trackAllocation = trackAllocation; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1063 | data.restrictedBackupMode = isRestrictedBackupMode; |
Dianne Hackborn | 5d927c2 | 2011-09-02 12:22:18 -0700 | [diff] [blame] | 1064 | data.persistent = persistent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1065 | data.config = config; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1066 | data.compatInfo = compatInfo; |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 1067 | data.initProfilerInfo = profilerInfo; |
Svet Ganov | 37e4327 | 2016-09-09 16:01:32 -0700 | [diff] [blame] | 1068 | data.buildSerial = buildSerial; |
Felipe Leme | a4f39cd | 2019-02-19 15:08:59 -0800 | [diff] [blame] | 1069 | data.autofillOptions = autofillOptions; |
Felipe Leme | 326f15a | 2019-02-19 09:42:24 -0800 | [diff] [blame] | 1070 | data.contentCaptureOptions = contentCaptureOptions; |
Mathew Inwood | 80652db | 2019-06-24 12:07:22 +0100 | [diff] [blame] | 1071 | data.disabledCompatChanges = disabledCompatChanges; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1072 | sendMessage(H.BIND_APPLICATION, data); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1073 | } |
| 1074 | |
Torne (Richard Coles) | 466cbe4 | 2017-05-31 14:09:14 -0400 | [diff] [blame] | 1075 | public final void runIsolatedEntryPoint(String entryPoint, String[] entryPointArgs) { |
| 1076 | SomeArgs args = SomeArgs.obtain(); |
| 1077 | args.arg1 = entryPoint; |
| 1078 | args.arg2 = entryPointArgs; |
| 1079 | sendMessage(H.RUN_ISOLATED_ENTRY_POINT, args); |
| 1080 | } |
| 1081 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1082 | public final void scheduleExit() { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1083 | sendMessage(H.EXIT_APPLICATION, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1084 | } |
| 1085 | |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 1086 | public final void scheduleSuicide() { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1087 | sendMessage(H.SUICIDE, null); |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 1088 | } |
| 1089 | |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 1090 | public void scheduleApplicationInfoChanged(ApplicationInfo ai) { |
Winson Chung | 6ee1742 | 2019-05-07 13:22:15 -0700 | [diff] [blame] | 1091 | mH.removeMessages(H.APPLICATION_INFO_CHANGED, ai); |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 1092 | sendMessage(H.APPLICATION_INFO_CHANGED, ai); |
| 1093 | } |
| 1094 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1095 | public void updateTimeZone() { |
| 1096 | TimeZone.setDefault(null); |
| 1097 | } |
| 1098 | |
Robert Greenwalt | 03595d0 | 2010-11-02 14:08:23 -0700 | [diff] [blame] | 1099 | public void clearDnsCache() { |
| 1100 | // a non-standard API to get this to libcore |
| 1101 | InetAddress.clearDnsCache(); |
Paul Jensen | e401d17 | 2014-09-12 10:47:39 -0400 | [diff] [blame] | 1102 | // Allow libcore to perform the necessary actions as it sees fit upon a network |
| 1103 | // configuration change. |
| 1104 | NetworkEventDispatcher.getInstance().onNetworkConfigurationChanged(); |
Robert Greenwalt | 03595d0 | 2010-11-02 14:08:23 -0700 | [diff] [blame] | 1105 | } |
| 1106 | |
Irina Dumitrescu | 18622d3 | 2018-12-05 16:19:47 +0000 | [diff] [blame] | 1107 | public void updateHttpProxy() { |
Irina Dumitrescu | 34a27c4 | 2019-04-15 19:20:38 +0100 | [diff] [blame] | 1108 | ActivityThread.updateHttpProxy( |
Chalard Jean | 100df0a | 2018-05-15 23:11:45 +0900 | [diff] [blame] | 1109 | getApplication() != null ? getApplication() : getSystemContext()); |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 1110 | } |
| 1111 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1112 | public void processInBackground() { |
| 1113 | mH.removeMessages(H.GC_WHEN_IDLE); |
| 1114 | mH.sendMessage(mH.obtainMessage(H.GC_WHEN_IDLE)); |
| 1115 | } |
| 1116 | |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1117 | public void dumpService(ParcelFileDescriptor pfd, IBinder servicetoken, String[] args) { |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1118 | DumpComponentInfo data = new DumpComponentInfo(); |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 1119 | try { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1120 | data.fd = pfd.dup(); |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 1121 | data.token = servicetoken; |
| 1122 | data.args = args; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1123 | sendMessage(H.DUMP_SERVICE, data, 0, 0, true /*async*/); |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 1124 | } catch (IOException e) { |
| 1125 | Slog.w(TAG, "dumpService failed", e); |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1126 | } finally { |
| 1127 | IoUtils.closeQuietly(pfd); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1128 | } |
| 1129 | } |
| 1130 | |
| 1131 | // This function exists to make sure all receiver dispatching is |
| 1132 | // correctly ordered, since these are one-way calls and the binder driver |
| 1133 | // applies transaction ordering per object for such calls. |
| 1134 | public void scheduleRegisteredReceiver(IIntentReceiver receiver, Intent intent, |
Dianne Hackborn | 68d881c | 2009-10-05 13:58:17 -0700 | [diff] [blame] | 1135 | int resultCode, String dataStr, Bundle extras, boolean ordered, |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 1136 | boolean sticky, int sendingUser, int processState) throws RemoteException { |
| 1137 | updateProcessState(processState, false); |
Dianne Hackborn | 20e8098 | 2012-08-31 19:00:44 -0700 | [diff] [blame] | 1138 | receiver.performReceive(intent, resultCode, dataStr, extras, ordered, |
| 1139 | sticky, sendingUser); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1140 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1141 | |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 1142 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1143 | public void scheduleLowMemory() { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1144 | sendMessage(H.LOW_MEMORY, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1145 | } |
| 1146 | |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 1147 | @Override |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 1148 | public void profilerControl(boolean start, ProfilerInfo profilerInfo, int profileType) { |
| 1149 | sendMessage(H.PROFILER_CONTROL, profilerInfo, start ? 1 : 0, profileType); |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 1150 | } |
| 1151 | |
Makoto Onuki | 4556b7b | 2017-07-07 14:58:58 -0700 | [diff] [blame] | 1152 | @Override |
Christopher Ferris | 8d652f8 | 2017-04-11 16:29:18 -0700 | [diff] [blame] | 1153 | public void dumpHeap(boolean managed, boolean mallocInfo, boolean runGc, String path, |
Makoto Onuki | 2c6657f | 2018-06-06 15:24:02 -0700 | [diff] [blame] | 1154 | ParcelFileDescriptor fd, RemoteCallback finishCallback) { |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 1155 | DumpHeapData dhd = new DumpHeapData(); |
Christopher Ferris | 8d652f8 | 2017-04-11 16:29:18 -0700 | [diff] [blame] | 1156 | dhd.managed = managed; |
| 1157 | dhd.mallocInfo = mallocInfo; |
Makoto Onuki | 4556b7b | 2017-07-07 14:58:58 -0700 | [diff] [blame] | 1158 | dhd.runGc = runGc; |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 1159 | dhd.path = path; |
Kweku Adams | 4af1b50 | 2019-05-23 16:23:48 -0700 | [diff] [blame] | 1160 | try { |
| 1161 | // Since we're going to dump the heap asynchronously, dup the file descriptor before |
| 1162 | // it's closed on returning from the IPC call. |
| 1163 | dhd.fd = fd.dup(); |
| 1164 | } catch (IOException e) { |
| 1165 | Slog.e(TAG, "Failed to duplicate heap dump file descriptor", e); |
| 1166 | return; |
| 1167 | } |
Makoto Onuki | 2c6657f | 2018-06-06 15:24:02 -0700 | [diff] [blame] | 1168 | dhd.finishCallback = finishCallback; |
Christopher Ferris | 8d652f8 | 2017-04-11 16:29:18 -0700 | [diff] [blame] | 1169 | sendMessage(H.DUMP_HEAP, dhd, 0, 0, true /*async*/); |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 1170 | } |
| 1171 | |
Leonard Mosescu | f3409ce | 2016-10-06 17:32:05 -0700 | [diff] [blame] | 1172 | public void attachAgent(String agent) { |
| 1173 | sendMessage(H.ATTACH_AGENT, agent); |
| 1174 | } |
| 1175 | |
Alex Light | 2d0691c | 2019-10-03 14:36:57 -0700 | [diff] [blame] | 1176 | public void attachStartupAgents(String dataDir) { |
| 1177 | sendMessage(H.ATTACH_STARTUP_AGENTS, dataDir); |
| 1178 | } |
| 1179 | |
Dianne Hackborn | 06de2ea | 2009-05-21 12:56:43 -0700 | [diff] [blame] | 1180 | public void setSchedulingGroup(int group) { |
| 1181 | // Note: do this immediately, since going into the foreground |
| 1182 | // should happen regardless of what pending work we have to do |
| 1183 | // and the activity manager will wait for us to report back that |
| 1184 | // we are done before sending us to the background. |
| 1185 | try { |
| 1186 | Process.setProcessGroup(Process.myPid(), group); |
| 1187 | } catch (Exception e) { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 1188 | Slog.w(TAG, "Failed setting process group to " + group, e); |
Dianne Hackborn | 06de2ea | 2009-05-21 12:56:43 -0700 | [diff] [blame] | 1189 | } |
| 1190 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1191 | |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1192 | public void dispatchPackageBroadcast(int cmd, String[] packages) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1193 | sendMessage(H.DISPATCH_PACKAGE_BROADCAST, packages, cmd); |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1194 | } |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 1195 | |
| 1196 | public void scheduleCrash(String msg) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1197 | sendMessage(H.SCHEDULE_CRASH, msg); |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 1198 | } |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1199 | |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1200 | public void dumpActivity(ParcelFileDescriptor pfd, IBinder activitytoken, |
Dianne Hackborn | 30d7189 | 2010-12-11 10:37:55 -0800 | [diff] [blame] | 1201 | String prefix, String[] args) { |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1202 | DumpComponentInfo data = new DumpComponentInfo(); |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 1203 | try { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1204 | data.fd = pfd.dup(); |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 1205 | data.token = activitytoken; |
| 1206 | data.prefix = prefix; |
| 1207 | data.args = args; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1208 | sendMessage(H.DUMP_ACTIVITY, data, 0, 0, true /*async*/); |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 1209 | } catch (IOException e) { |
| 1210 | Slog.w(TAG, "dumpActivity failed", e); |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1211 | } finally { |
| 1212 | IoUtils.closeQuietly(pfd); |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1213 | } |
| 1214 | } |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 1215 | |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1216 | public void dumpProvider(ParcelFileDescriptor pfd, IBinder providertoken, |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1217 | String[] args) { |
| 1218 | DumpComponentInfo data = new DumpComponentInfo(); |
| 1219 | try { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1220 | data.fd = pfd.dup(); |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1221 | data.token = providertoken; |
| 1222 | data.args = args; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1223 | sendMessage(H.DUMP_PROVIDER, data, 0, 0, true /*async*/); |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1224 | } catch (IOException e) { |
| 1225 | Slog.w(TAG, "dumpProvider failed", e); |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1226 | } finally { |
| 1227 | IoUtils.closeQuietly(pfd); |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1228 | } |
| 1229 | } |
| 1230 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1231 | @Override |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1232 | public void dumpMemInfo(ParcelFileDescriptor pfd, Debug.MemoryInfo mem, boolean checkin, |
Colin Cross | c4fb5f9 | 2016-02-02 16:51:15 -0800 | [diff] [blame] | 1233 | boolean dumpFullInfo, boolean dumpDalvik, boolean dumpSummaryOnly, |
| 1234 | boolean dumpUnreachable, String[] args) { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1235 | FileOutputStream fout = new FileOutputStream(pfd.getFileDescriptor()); |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 1236 | PrintWriter pw = new FastPrintWriter(fout); |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 1237 | try { |
Colin Cross | c4fb5f9 | 2016-02-02 16:51:15 -0800 | [diff] [blame] | 1238 | dumpMemInfo(pw, mem, checkin, dumpFullInfo, dumpDalvik, dumpSummaryOnly, dumpUnreachable); |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 1239 | } finally { |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 1240 | pw.flush(); |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1241 | IoUtils.closeQuietly(pfd); |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 1242 | } |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 1243 | } |
| 1244 | |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 1245 | private void dumpMemInfo(PrintWriter pw, Debug.MemoryInfo memInfo, boolean checkin, |
Colin Cross | c4fb5f9 | 2016-02-02 16:51:15 -0800 | [diff] [blame] | 1246 | boolean dumpFullInfo, boolean dumpDalvik, boolean dumpSummaryOnly, boolean dumpUnreachable) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1247 | long nativeMax = Debug.getNativeHeapSize() / 1024; |
| 1248 | long nativeAllocated = Debug.getNativeHeapAllocatedSize() / 1024; |
| 1249 | long nativeFree = Debug.getNativeHeapFreeSize() / 1024; |
| 1250 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1251 | Runtime runtime = Runtime.getRuntime(); |
Mathieu Chartier | d288a26 | 2015-07-10 13:44:42 -0700 | [diff] [blame] | 1252 | runtime.gc(); // Do GC since countInstancesOfClass counts unreachable objects. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1253 | long dalvikMax = runtime.totalMemory() / 1024; |
| 1254 | long dalvikFree = runtime.freeMemory() / 1024; |
| 1255 | long dalvikAllocated = dalvikMax - dalvikFree; |
Richard Uhler | 2c03619 | 2016-09-14 09:48:31 +0100 | [diff] [blame] | 1256 | |
| 1257 | Class[] classesToCount = new Class[] { |
| 1258 | ContextImpl.class, |
| 1259 | Activity.class, |
| 1260 | WebView.class, |
| 1261 | OpenSSLSocketImpl.class |
| 1262 | }; |
| 1263 | long[] instanceCounts = VMDebug.countInstancesOfClasses(classesToCount, true); |
| 1264 | long appContextInstanceCount = instanceCounts[0]; |
| 1265 | long activityInstanceCount = instanceCounts[1]; |
| 1266 | long webviewInstanceCount = instanceCounts[2]; |
| 1267 | long openSslSocketCount = instanceCounts[3]; |
| 1268 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1269 | long viewInstanceCount = ViewDebug.getViewInstanceCount(); |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1270 | long viewRootInstanceCount = ViewDebug.getViewRootImplCount(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1271 | int globalAssetCount = AssetManager.getGlobalAssetCount(); |
| 1272 | int globalAssetManagerCount = AssetManager.getGlobalAssetManagerCount(); |
| 1273 | int binderLocalObjectCount = Debug.getBinderLocalObjectCount(); |
| 1274 | int binderProxyObjectCount = Debug.getBinderProxyObjectCount(); |
| 1275 | int binderDeathObjectCount = Debug.getBinderDeathObjectCount(); |
Dianne Hackborn | fabb70b | 2014-11-11 12:22:36 -0800 | [diff] [blame] | 1276 | long parcelSize = Parcel.getGlobalAllocSize(); |
| 1277 | long parcelCount = Parcel.getGlobalAllocCount(); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1278 | SQLiteDebug.PagerStats stats = SQLiteDebug.getDatabaseInfo(); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1279 | |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 1280 | dumpMemInfoTable(pw, memInfo, checkin, dumpFullInfo, dumpDalvik, dumpSummaryOnly, |
| 1281 | Process.myPid(), |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 1282 | (mBoundApplication != null) ? mBoundApplication.processName : "unknown", |
| 1283 | nativeMax, nativeAllocated, nativeFree, |
| 1284 | dalvikMax, dalvikAllocated, dalvikFree); |
| 1285 | |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 1286 | if (checkin) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1287 | // NOTE: if you change anything significant below, also consider changing |
| 1288 | // ACTIVITY_THREAD_CHECKIN_VERSION. |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 1289 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1290 | // Object counts |
| 1291 | pw.print(viewInstanceCount); pw.print(','); |
| 1292 | pw.print(viewRootInstanceCount); pw.print(','); |
| 1293 | pw.print(appContextInstanceCount); pw.print(','); |
| 1294 | pw.print(activityInstanceCount); pw.print(','); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1295 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1296 | pw.print(globalAssetCount); pw.print(','); |
| 1297 | pw.print(globalAssetManagerCount); pw.print(','); |
| 1298 | pw.print(binderLocalObjectCount); pw.print(','); |
| 1299 | pw.print(binderProxyObjectCount); pw.print(','); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1300 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1301 | pw.print(binderDeathObjectCount); pw.print(','); |
| 1302 | pw.print(openSslSocketCount); pw.print(','); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1303 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1304 | // SQL |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1305 | pw.print(stats.memoryUsed / 1024); pw.print(','); |
Jeff Brown | 2a293b6 | 2012-01-19 14:02:22 -0800 | [diff] [blame] | 1306 | pw.print(stats.memoryUsed / 1024); pw.print(','); |
| 1307 | pw.print(stats.pageCacheOverflow / 1024); pw.print(','); |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 1308 | pw.print(stats.largestMemAlloc / 1024); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1309 | for (int i = 0; i < stats.dbStats.size(); i++) { |
| 1310 | DbStats dbStats = stats.dbStats.get(i); |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 1311 | pw.print(','); pw.print(dbStats.dbName); |
| 1312 | pw.print(','); pw.print(dbStats.pageSize); |
| 1313 | pw.print(','); pw.print(dbStats.dbSize); |
| 1314 | pw.print(','); pw.print(dbStats.lookaside); |
| 1315 | pw.print(','); pw.print(dbStats.cache); |
| 1316 | pw.print(','); pw.print(dbStats.cache); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1317 | } |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 1318 | pw.println(); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1319 | |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 1320 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1321 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1322 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1323 | pw.println(" "); |
| 1324 | pw.println(" Objects"); |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1325 | printRow(pw, TWO_COUNT_COLUMNS, "Views:", viewInstanceCount, "ViewRootImpl:", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1326 | viewRootInstanceCount); |
| 1327 | |
| 1328 | printRow(pw, TWO_COUNT_COLUMNS, "AppContexts:", appContextInstanceCount, |
| 1329 | "Activities:", activityInstanceCount); |
| 1330 | |
| 1331 | printRow(pw, TWO_COUNT_COLUMNS, "Assets:", globalAssetCount, |
| 1332 | "AssetManagers:", globalAssetManagerCount); |
| 1333 | |
| 1334 | printRow(pw, TWO_COUNT_COLUMNS, "Local Binders:", binderLocalObjectCount, |
| 1335 | "Proxy Binders:", binderProxyObjectCount); |
Dianne Hackborn | fabb70b | 2014-11-11 12:22:36 -0800 | [diff] [blame] | 1336 | printRow(pw, TWO_COUNT_COLUMNS, "Parcel memory:", parcelSize/1024, |
| 1337 | "Parcel count:", parcelCount); |
| 1338 | printRow(pw, TWO_COUNT_COLUMNS, "Death Recipients:", binderDeathObjectCount, |
| 1339 | "OpenSSL Sockets:", openSslSocketCount); |
Richard Uhler | 2c03619 | 2016-09-14 09:48:31 +0100 | [diff] [blame] | 1340 | printRow(pw, ONE_COUNT_COLUMN, "WebViews:", webviewInstanceCount); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1341 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1342 | // SQLite mem info |
| 1343 | pw.println(" "); |
| 1344 | pw.println(" SQL"); |
Jeff Brown | 2a293b6 | 2012-01-19 14:02:22 -0800 | [diff] [blame] | 1345 | printRow(pw, ONE_COUNT_COLUMN, "MEMORY_USED:", stats.memoryUsed / 1024); |
| 1346 | printRow(pw, TWO_COUNT_COLUMNS, "PAGECACHE_OVERFLOW:", |
| 1347 | stats.pageCacheOverflow / 1024, "MALLOC_SIZE:", stats.largestMemAlloc / 1024); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1348 | pw.println(" "); |
| 1349 | int N = stats.dbStats.size(); |
| 1350 | if (N > 0) { |
| 1351 | pw.println(" DATABASES"); |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 1352 | printRow(pw, DB_INFO_FORMAT, "pgsz", "dbsz", "Lookaside(b)", "cache", |
Vasu Nori | 3c7131f | 2010-09-21 14:36:57 -0700 | [diff] [blame] | 1353 | "Dbname"); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1354 | for (int i = 0; i < N; i++) { |
| 1355 | DbStats dbStats = stats.dbStats.get(i); |
Vasu Nori | 3c7131f | 2010-09-21 14:36:57 -0700 | [diff] [blame] | 1356 | printRow(pw, DB_INFO_FORMAT, |
| 1357 | (dbStats.pageSize > 0) ? String.valueOf(dbStats.pageSize) : " ", |
| 1358 | (dbStats.dbSize > 0) ? String.valueOf(dbStats.dbSize) : " ", |
| 1359 | (dbStats.lookaside > 0) ? String.valueOf(dbStats.lookaside) : " ", |
| 1360 | dbStats.cache, dbStats.dbName); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1361 | } |
| 1362 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1363 | |
Dianne Hackborn | 82e1ee9 | 2009-08-11 18:56:41 -0700 | [diff] [blame] | 1364 | // Asset details. |
| 1365 | String assetAlloc = AssetManager.getAssetAllocations(); |
| 1366 | if (assetAlloc != null) { |
| 1367 | pw.println(" "); |
| 1368 | pw.println(" Asset Allocations"); |
| 1369 | pw.print(assetAlloc); |
| 1370 | } |
Colin Cross | c4fb5f9 | 2016-02-02 16:51:15 -0800 | [diff] [blame] | 1371 | |
| 1372 | // Unreachable native memory |
| 1373 | if (dumpUnreachable) { |
| 1374 | boolean showContents = ((mBoundApplication != null) |
| 1375 | && ((mBoundApplication.appInfo.flags&ApplicationInfo.FLAG_DEBUGGABLE) != 0)) |
| 1376 | || android.os.Build.IS_DEBUGGABLE; |
| 1377 | pw.println(" "); |
| 1378 | pw.println(" Unreachable memory"); |
| 1379 | pw.print(Debug.getUnreachableMemory(100, showContents)); |
| 1380 | } |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 1381 | } |
| 1382 | |
| 1383 | @Override |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 1384 | public void dumpMemInfoProto(ParcelFileDescriptor pfd, Debug.MemoryInfo mem, |
| 1385 | boolean dumpFullInfo, boolean dumpDalvik, boolean dumpSummaryOnly, |
| 1386 | boolean dumpUnreachable, String[] args) { |
| 1387 | ProtoOutputStream proto = new ProtoOutputStream(pfd.getFileDescriptor()); |
| 1388 | try { |
| 1389 | dumpMemInfo(proto, mem, dumpFullInfo, dumpDalvik, dumpSummaryOnly, dumpUnreachable); |
| 1390 | } finally { |
| 1391 | proto.flush(); |
| 1392 | IoUtils.closeQuietly(pfd); |
| 1393 | } |
| 1394 | } |
| 1395 | |
| 1396 | private void dumpMemInfo(ProtoOutputStream proto, Debug.MemoryInfo memInfo, |
| 1397 | boolean dumpFullInfo, boolean dumpDalvik, |
| 1398 | boolean dumpSummaryOnly, boolean dumpUnreachable) { |
| 1399 | long nativeMax = Debug.getNativeHeapSize() / 1024; |
| 1400 | long nativeAllocated = Debug.getNativeHeapAllocatedSize() / 1024; |
| 1401 | long nativeFree = Debug.getNativeHeapFreeSize() / 1024; |
| 1402 | |
| 1403 | Runtime runtime = Runtime.getRuntime(); |
| 1404 | runtime.gc(); // Do GC since countInstancesOfClass counts unreachable objects. |
| 1405 | long dalvikMax = runtime.totalMemory() / 1024; |
| 1406 | long dalvikFree = runtime.freeMemory() / 1024; |
| 1407 | long dalvikAllocated = dalvikMax - dalvikFree; |
| 1408 | |
| 1409 | Class[] classesToCount = new Class[] { |
| 1410 | ContextImpl.class, |
| 1411 | Activity.class, |
| 1412 | WebView.class, |
| 1413 | OpenSSLSocketImpl.class |
| 1414 | }; |
| 1415 | long[] instanceCounts = VMDebug.countInstancesOfClasses(classesToCount, true); |
| 1416 | long appContextInstanceCount = instanceCounts[0]; |
| 1417 | long activityInstanceCount = instanceCounts[1]; |
| 1418 | long webviewInstanceCount = instanceCounts[2]; |
| 1419 | long openSslSocketCount = instanceCounts[3]; |
| 1420 | |
| 1421 | long viewInstanceCount = ViewDebug.getViewInstanceCount(); |
| 1422 | long viewRootInstanceCount = ViewDebug.getViewRootImplCount(); |
| 1423 | int globalAssetCount = AssetManager.getGlobalAssetCount(); |
| 1424 | int globalAssetManagerCount = AssetManager.getGlobalAssetManagerCount(); |
| 1425 | int binderLocalObjectCount = Debug.getBinderLocalObjectCount(); |
| 1426 | int binderProxyObjectCount = Debug.getBinderProxyObjectCount(); |
| 1427 | int binderDeathObjectCount = Debug.getBinderDeathObjectCount(); |
| 1428 | long parcelSize = Parcel.getGlobalAllocSize(); |
| 1429 | long parcelCount = Parcel.getGlobalAllocCount(); |
| 1430 | SQLiteDebug.PagerStats stats = SQLiteDebug.getDatabaseInfo(); |
| 1431 | |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 1432 | final long mToken = proto.start(MemInfoDumpProto.AppData.PROCESS_MEMORY); |
| 1433 | proto.write(MemInfoDumpProto.ProcessMemory.PID, Process.myPid()); |
| 1434 | proto.write(MemInfoDumpProto.ProcessMemory.PROCESS_NAME, |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 1435 | (mBoundApplication != null) ? mBoundApplication.processName : "unknown"); |
| 1436 | dumpMemInfoTable(proto, memInfo, dumpDalvik, dumpSummaryOnly, |
| 1437 | nativeMax, nativeAllocated, nativeFree, |
| 1438 | dalvikMax, dalvikAllocated, dalvikFree); |
| 1439 | proto.end(mToken); |
| 1440 | |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 1441 | final long oToken = proto.start(MemInfoDumpProto.AppData.OBJECTS); |
| 1442 | proto.write(MemInfoDumpProto.AppData.ObjectStats.VIEW_INSTANCE_COUNT, |
| 1443 | viewInstanceCount); |
| 1444 | proto.write(MemInfoDumpProto.AppData.ObjectStats.VIEW_ROOT_INSTANCE_COUNT, |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 1445 | viewRootInstanceCount); |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 1446 | proto.write(MemInfoDumpProto.AppData.ObjectStats.APP_CONTEXT_INSTANCE_COUNT, |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 1447 | appContextInstanceCount); |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 1448 | proto.write(MemInfoDumpProto.AppData.ObjectStats.ACTIVITY_INSTANCE_COUNT, |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 1449 | activityInstanceCount); |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 1450 | proto.write(MemInfoDumpProto.AppData.ObjectStats.GLOBAL_ASSET_COUNT, |
| 1451 | globalAssetCount); |
| 1452 | proto.write(MemInfoDumpProto.AppData.ObjectStats.GLOBAL_ASSET_MANAGER_COUNT, |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 1453 | globalAssetManagerCount); |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 1454 | proto.write(MemInfoDumpProto.AppData.ObjectStats.LOCAL_BINDER_OBJECT_COUNT, |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 1455 | binderLocalObjectCount); |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 1456 | proto.write(MemInfoDumpProto.AppData.ObjectStats.PROXY_BINDER_OBJECT_COUNT, |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 1457 | binderProxyObjectCount); |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 1458 | proto.write(MemInfoDumpProto.AppData.ObjectStats.PARCEL_MEMORY_KB, |
| 1459 | parcelSize / 1024); |
| 1460 | proto.write(MemInfoDumpProto.AppData.ObjectStats.PARCEL_COUNT, parcelCount); |
| 1461 | proto.write(MemInfoDumpProto.AppData.ObjectStats.BINDER_OBJECT_DEATH_COUNT, |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 1462 | binderDeathObjectCount); |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 1463 | proto.write(MemInfoDumpProto.AppData.ObjectStats.OPEN_SSL_SOCKET_COUNT, |
| 1464 | openSslSocketCount); |
| 1465 | proto.write(MemInfoDumpProto.AppData.ObjectStats.WEBVIEW_INSTANCE_COUNT, |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 1466 | webviewInstanceCount); |
| 1467 | proto.end(oToken); |
| 1468 | |
| 1469 | // SQLite mem info |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 1470 | final long sToken = proto.start(MemInfoDumpProto.AppData.SQL); |
| 1471 | proto.write(MemInfoDumpProto.AppData.SqlStats.MEMORY_USED_KB, |
| 1472 | stats.memoryUsed / 1024); |
| 1473 | proto.write(MemInfoDumpProto.AppData.SqlStats.PAGECACHE_OVERFLOW_KB, |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 1474 | stats.pageCacheOverflow / 1024); |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 1475 | proto.write(MemInfoDumpProto.AppData.SqlStats.MALLOC_SIZE_KB, |
| 1476 | stats.largestMemAlloc / 1024); |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 1477 | int n = stats.dbStats.size(); |
| 1478 | for (int i = 0; i < n; i++) { |
| 1479 | DbStats dbStats = stats.dbStats.get(i); |
| 1480 | |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 1481 | final long dToken = proto.start(MemInfoDumpProto.AppData.SqlStats.DATABASES); |
| 1482 | proto.write(MemInfoDumpProto.AppData.SqlStats.Database.NAME, dbStats.dbName); |
| 1483 | proto.write(MemInfoDumpProto.AppData.SqlStats.Database.PAGE_SIZE, dbStats.pageSize); |
| 1484 | proto.write(MemInfoDumpProto.AppData.SqlStats.Database.DB_SIZE, dbStats.dbSize); |
| 1485 | proto.write(MemInfoDumpProto.AppData.SqlStats.Database.LOOKASIDE_B, |
| 1486 | dbStats.lookaside); |
| 1487 | proto.write(MemInfoDumpProto.AppData.SqlStats.Database.CACHE, dbStats.cache); |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 1488 | proto.end(dToken); |
| 1489 | } |
| 1490 | proto.end(sToken); |
| 1491 | |
| 1492 | // Asset details. |
| 1493 | String assetAlloc = AssetManager.getAssetAllocations(); |
| 1494 | if (assetAlloc != null) { |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 1495 | proto.write(MemInfoDumpProto.AppData.ASSET_ALLOCATIONS, assetAlloc); |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 1496 | } |
| 1497 | |
| 1498 | // Unreachable native memory |
| 1499 | if (dumpUnreachable) { |
| 1500 | int flags = mBoundApplication == null ? 0 : mBoundApplication.appInfo.flags; |
| 1501 | boolean showContents = (flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0 |
| 1502 | || android.os.Build.IS_DEBUGGABLE; |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 1503 | proto.write(MemInfoDumpProto.AppData.UNREACHABLE_MEMORY, |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 1504 | Debug.getUnreachableMemory(100, showContents)); |
| 1505 | } |
| 1506 | } |
| 1507 | |
| 1508 | @Override |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1509 | public void dumpGfxInfo(ParcelFileDescriptor pfd, String[] args) { |
Chris Craik | fc29424 | 2016-12-13 18:10:46 -0800 | [diff] [blame] | 1510 | nDumpGraphicsInfo(pfd.getFileDescriptor()); |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1511 | WindowManagerGlobal.getInstance().dumpGfxInfo(pfd.getFileDescriptor(), args); |
| 1512 | IoUtils.closeQuietly(pfd); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1513 | } |
| 1514 | |
Makoto Onuki | 016dc59 | 2018-08-14 12:26:45 -0700 | [diff] [blame] | 1515 | private File getDatabasesDir(Context context) { |
| 1516 | // There's no simple way to get the databases/ path, so do it this way. |
| 1517 | return context.getDatabasePath("a").getParentFile(); |
| 1518 | } |
| 1519 | |
| 1520 | private void dumpDatabaseInfo(ParcelFileDescriptor pfd, String[] args, boolean isSystem) { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1521 | PrintWriter pw = new FastPrintWriter( |
| 1522 | new FileOutputStream(pfd.getFileDescriptor())); |
Jeff Brown | 6754ba2 | 2011-12-14 20:20:01 -0800 | [diff] [blame] | 1523 | PrintWriterPrinter printer = new PrintWriterPrinter(pw); |
Makoto Onuki | ee93ad2 | 2018-10-18 16:24:13 -0700 | [diff] [blame] | 1524 | SQLiteDebug.dump(printer, args, isSystem); |
Jeff Brown | 6754ba2 | 2011-12-14 20:20:01 -0800 | [diff] [blame] | 1525 | pw.flush(); |
| 1526 | } |
| 1527 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1528 | @Override |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1529 | public void dumpDbInfo(final ParcelFileDescriptor pfd, final String[] args) { |
riddle_hsu | 1d6c40a | 2014-07-31 00:18:00 +0800 | [diff] [blame] | 1530 | if (mSystemThread) { |
Felipe Leme | 29de492 | 2016-06-07 16:14:07 -0700 | [diff] [blame] | 1531 | // Ensure this invocation is asynchronous to prevent writer waiting if buffer cannot |
| 1532 | // be consumed. But it must duplicate the file descriptor first, since caller might |
| 1533 | // be closing it. |
| 1534 | final ParcelFileDescriptor dup; |
| 1535 | try { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1536 | dup = pfd.dup(); |
Felipe Leme | 29de492 | 2016-06-07 16:14:07 -0700 | [diff] [blame] | 1537 | } catch (IOException e) { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1538 | Log.w(TAG, "Could not dup FD " + pfd.getFileDescriptor().getInt$()); |
Felipe Leme | 29de492 | 2016-06-07 16:14:07 -0700 | [diff] [blame] | 1539 | return; |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1540 | } finally { |
| 1541 | IoUtils.closeQuietly(pfd); |
Felipe Leme | 29de492 | 2016-06-07 16:14:07 -0700 | [diff] [blame] | 1542 | } |
| 1543 | |
riddle_hsu | 1d6c40a | 2014-07-31 00:18:00 +0800 | [diff] [blame] | 1544 | AsyncTask.THREAD_POOL_EXECUTOR.execute(new Runnable() { |
| 1545 | @Override |
| 1546 | public void run() { |
Felipe Leme | c74972f | 2016-06-08 09:12:37 -0700 | [diff] [blame] | 1547 | try { |
Makoto Onuki | 016dc59 | 2018-08-14 12:26:45 -0700 | [diff] [blame] | 1548 | dumpDatabaseInfo(dup, args, true); |
Felipe Leme | c74972f | 2016-06-08 09:12:37 -0700 | [diff] [blame] | 1549 | } finally { |
| 1550 | IoUtils.closeQuietly(dup); |
| 1551 | } |
riddle_hsu | 1d6c40a | 2014-07-31 00:18:00 +0800 | [diff] [blame] | 1552 | } |
| 1553 | }); |
| 1554 | } else { |
Makoto Onuki | 016dc59 | 2018-08-14 12:26:45 -0700 | [diff] [blame] | 1555 | dumpDatabaseInfo(pfd, args, false); |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1556 | IoUtils.closeQuietly(pfd); |
riddle_hsu | 1d6c40a | 2014-07-31 00:18:00 +0800 | [diff] [blame] | 1557 | } |
| 1558 | } |
| 1559 | |
| 1560 | @Override |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1561 | public void unstableProviderDied(IBinder provider) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1562 | sendMessage(H.UNSTABLE_PROVIDER_DIED, provider); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1563 | } |
| 1564 | |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 1565 | @Override |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 1566 | public void requestAssistContextExtras(IBinder activityToken, IBinder requestToken, |
Svet Ganov | fd31f85 | 2017-04-26 15:54:27 -0700 | [diff] [blame] | 1567 | int requestType, int sessionId, int flags) { |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 1568 | RequestAssistContextExtras cmd = new RequestAssistContextExtras(); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 1569 | cmd.activityToken = activityToken; |
| 1570 | cmd.requestToken = requestToken; |
| 1571 | cmd.requestType = requestType; |
Amith Yamasani | 4f128e4 | 2016-05-10 11:44:12 -0700 | [diff] [blame] | 1572 | cmd.sessionId = sessionId; |
Svet Ganov | fd31f85 | 2017-04-26 15:54:27 -0700 | [diff] [blame] | 1573 | cmd.flags = flags; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1574 | sendMessage(H.REQUEST_ASSIST_CONTEXT_EXTRAS, cmd); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 1575 | } |
| 1576 | |
Svetoslav Ganov | 9aa597e | 2011-03-03 18:17:41 -0800 | [diff] [blame] | 1577 | public void setCoreSettings(Bundle coreSettings) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1578 | sendMessage(H.SET_CORE_SETTINGS, coreSettings); |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1579 | } |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1580 | |
| 1581 | public void updatePackageCompatibilityInfo(String pkg, CompatibilityInfo info) { |
| 1582 | UpdateCompatibilityData ucd = new UpdateCompatibilityData(); |
| 1583 | ucd.pkg = pkg; |
| 1584 | ucd.info = info; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1585 | sendMessage(H.UPDATE_PACKAGE_COMPATIBILITY_INFO, ucd); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1586 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1587 | |
| 1588 | public void scheduleTrimMemory(int level) { |
Jorim Jaggi | b29e318 | 2018-04-30 18:51:56 +0200 | [diff] [blame] | 1589 | final Runnable r = PooledLambda.obtainRunnable(ActivityThread::handleTrimMemory, |
Yohei Yukawa | e2fa39e | 2018-09-22 13:13:10 -0700 | [diff] [blame] | 1590 | ActivityThread.this, level).recycleOnUse(); |
Jorim Jaggi | b29e318 | 2018-04-30 18:51:56 +0200 | [diff] [blame] | 1591 | // Schedule trimming memory after drawing the frame to minimize jank-risk. |
| 1592 | Choreographer choreographer = Choreographer.getMainThreadInstance(); |
| 1593 | if (choreographer != null) { |
| 1594 | choreographer.postCallback(Choreographer.CALLBACK_COMMIT, r, null); |
| 1595 | } else { |
| 1596 | mH.post(r); |
| 1597 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1598 | } |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1599 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1600 | public void scheduleTranslucentConversionComplete(IBinder token, boolean drawComplete) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1601 | sendMessage(H.TRANSLUCENT_CONVERSION_COMPLETE, token, drawComplete ? 1 : 0); |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1602 | } |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 1603 | |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1604 | public void scheduleOnNewActivityOptions(IBinder token, Bundle options) { |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1605 | sendMessage(H.ON_NEW_ACTIVITY_OPTIONS, |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1606 | new Pair<IBinder, ActivityOptions>(token, ActivityOptions.fromBundle(options))); |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1607 | } |
| 1608 | |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 1609 | public void setProcessState(int state) { |
| 1610 | updateProcessState(state, true); |
| 1611 | } |
| 1612 | |
Sudheer Shanka | 84a4895 | 2017-03-08 18:19:01 -0800 | [diff] [blame] | 1613 | /** |
| 1614 | * Updates {@link #mNetworkBlockSeq}. This is used by ActivityManagerService to inform |
| 1615 | * the main thread that it needs to wait for the network rules to get updated before |
| 1616 | * launching an activity. |
| 1617 | */ |
| 1618 | @Override |
| 1619 | public void setNetworkBlockSeq(long procStateSeq) { |
| 1620 | synchronized (mNetworkPolicyLock) { |
| 1621 | mNetworkBlockSeq = procStateSeq; |
| 1622 | } |
| 1623 | } |
| 1624 | |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 1625 | @Override |
| 1626 | public void scheduleInstallProvider(ProviderInfo provider) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1627 | sendMessage(H.INSTALL_PROVIDER, provider); |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 1628 | } |
Narayan Kamath | ccb2a086 | 2013-12-19 14:49:36 +0000 | [diff] [blame] | 1629 | |
| 1630 | @Override |
Neil Fuller | b7146fe | 2016-11-15 16:52:15 +0000 | [diff] [blame] | 1631 | public final void updateTimePrefs(int timeFormatPreference) { |
| 1632 | final Boolean timeFormatPreferenceBool; |
| 1633 | // For convenience we are using the Intent extra values. |
| 1634 | if (timeFormatPreference == Intent.EXTRA_TIME_PREF_VALUE_USE_12_HOUR) { |
| 1635 | timeFormatPreferenceBool = Boolean.FALSE; |
| 1636 | } else if (timeFormatPreference == Intent.EXTRA_TIME_PREF_VALUE_USE_24_HOUR) { |
| 1637 | timeFormatPreferenceBool = Boolean.TRUE; |
| 1638 | } else { |
| 1639 | // timeFormatPreference == Intent.EXTRA_TIME_PREF_VALUE_USE_LOCALE_DEFAULT |
| 1640 | // (or unknown). |
| 1641 | timeFormatPreferenceBool = null; |
| 1642 | } |
| 1643 | DateFormat.set24HourTimePref(timeFormatPreferenceBool); |
Narayan Kamath | ccb2a086 | 2013-12-19 14:49:36 +0000 | [diff] [blame] | 1644 | } |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 1645 | |
| 1646 | @Override |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 1647 | public void scheduleEnterAnimationComplete(IBinder token) { |
| 1648 | sendMessage(H.ENTER_ANIMATION_COMPLETE, token); |
| 1649 | } |
Jeff Sharkey | 605eb79 | 2014-11-04 13:34:06 -0800 | [diff] [blame] | 1650 | |
| 1651 | @Override |
| 1652 | public void notifyCleartextNetwork(byte[] firstPacket) { |
| 1653 | if (StrictMode.vmCleartextNetworkEnabled()) { |
| 1654 | StrictMode.onCleartextNetworkDetected(firstPacket); |
| 1655 | } |
| 1656 | } |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 1657 | |
| 1658 | @Override |
| 1659 | public void startBinderTracking() { |
| 1660 | sendMessage(H.START_BINDER_TRACKING, null); |
| 1661 | } |
| 1662 | |
| 1663 | @Override |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1664 | public void stopBinderTrackingAndDump(ParcelFileDescriptor pfd) { |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 1665 | try { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1666 | sendMessage(H.STOP_BINDER_TRACKING_AND_DUMP, pfd.dup()); |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 1667 | } catch (IOException e) { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1668 | } finally { |
| 1669 | IoUtils.closeQuietly(pfd); |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 1670 | } |
| 1671 | } |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 1672 | |
| 1673 | @Override |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1674 | public void scheduleLocalVoiceInteractionStarted(IBinder token, |
| 1675 | IVoiceInteractor voiceInteractor) throws RemoteException { |
| 1676 | SomeArgs args = SomeArgs.obtain(); |
| 1677 | args.arg1 = token; |
| 1678 | args.arg2 = voiceInteractor; |
| 1679 | sendMessage(H.LOCAL_VOICE_INTERACTION_STARTED, args); |
| 1680 | } |
Chad Brubaker | c72875b | 2016-04-27 16:35:11 -0700 | [diff] [blame] | 1681 | |
| 1682 | @Override |
| 1683 | public void handleTrustStorageUpdate() { |
| 1684 | NetworkSecurityPolicy.getInstance().handleTrustStorageUpdate(); |
| 1685 | } |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 1686 | |
| 1687 | @Override |
| 1688 | public void scheduleTransaction(ClientTransaction transaction) throws RemoteException { |
| 1689 | ActivityThread.this.scheduleTransaction(transaction); |
| 1690 | } |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 1691 | |
| 1692 | @Override |
| 1693 | public void requestDirectActions(@NonNull IBinder activityToken, |
Svet Ganov | 3b6be08 | 2019-04-28 10:21:01 -0700 | [diff] [blame] | 1694 | @NonNull IVoiceInteractor interactor, @Nullable RemoteCallback cancellationCallback, |
| 1695 | @NonNull RemoteCallback callback) { |
| 1696 | final CancellationSignal cancellationSignal = new CancellationSignal(); |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 1697 | if (cancellationCallback != null) { |
Svet Ganov | 3b6be08 | 2019-04-28 10:21:01 -0700 | [diff] [blame] | 1698 | final ICancellationSignal transport = createSafeCancellationTransport( |
| 1699 | cancellationSignal); |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 1700 | final Bundle cancellationResult = new Bundle(); |
| 1701 | cancellationResult.putBinder(VoiceInteractor.KEY_CANCELLATION_SIGNAL, |
| 1702 | transport.asBinder()); |
| 1703 | cancellationCallback.sendResult(cancellationResult); |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 1704 | } |
Svet Ganov | 3b6be08 | 2019-04-28 10:21:01 -0700 | [diff] [blame] | 1705 | mH.sendMessage(PooledLambda.obtainMessage(ActivityThread::handleRequestDirectActions, |
| 1706 | ActivityThread.this, activityToken, interactor, cancellationSignal, callback)); |
| 1707 | } |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 1708 | |
Svet Ganov | 3b6be08 | 2019-04-28 10:21:01 -0700 | [diff] [blame] | 1709 | @Override |
| 1710 | public void performDirectAction(@NonNull IBinder activityToken, @NonNull String actionId, |
| 1711 | @Nullable Bundle arguments, @Nullable RemoteCallback cancellationCallback, |
| 1712 | @NonNull RemoteCallback resultCallback) { |
| 1713 | final CancellationSignal cancellationSignal = new CancellationSignal(); |
| 1714 | if (cancellationCallback != null) { |
| 1715 | final ICancellationSignal transport = createSafeCancellationTransport( |
| 1716 | cancellationSignal); |
| 1717 | final Bundle cancellationResult = new Bundle(); |
| 1718 | cancellationResult.putBinder(VoiceInteractor.KEY_CANCELLATION_SIGNAL, |
| 1719 | transport.asBinder()); |
| 1720 | cancellationCallback.sendResult(cancellationResult); |
| 1721 | } |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 1722 | mH.sendMessage(PooledLambda.obtainMessage(ActivityThread::handlePerformDirectAction, |
| 1723 | ActivityThread.this, activityToken, actionId, arguments, |
| 1724 | cancellationSignal, resultCallback)); |
| 1725 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1726 | } |
| 1727 | |
Svet Ganov | 3b6be08 | 2019-04-28 10:21:01 -0700 | [diff] [blame] | 1728 | private @NonNull SafeCancellationTransport createSafeCancellationTransport( |
| 1729 | @NonNull CancellationSignal cancellationSignal) { |
| 1730 | synchronized (ActivityThread.this) { |
| 1731 | if (mRemoteCancellations == null) { |
| 1732 | mRemoteCancellations = new ArrayMap<>(); |
| 1733 | } |
| 1734 | final SafeCancellationTransport transport = new SafeCancellationTransport( |
| 1735 | this, cancellationSignal); |
| 1736 | mRemoteCancellations.put(transport, cancellationSignal); |
| 1737 | return transport; |
| 1738 | } |
| 1739 | } |
| 1740 | |
| 1741 | private @NonNull CancellationSignal removeSafeCancellationTransport( |
| 1742 | @NonNull SafeCancellationTransport transport) { |
| 1743 | synchronized (ActivityThread.this) { |
| 1744 | final CancellationSignal cancellation = mRemoteCancellations.remove(transport); |
| 1745 | if (mRemoteCancellations.isEmpty()) { |
| 1746 | mRemoteCancellations = null; |
| 1747 | } |
| 1748 | return cancellation; |
| 1749 | } |
| 1750 | } |
| 1751 | |
| 1752 | private static final class SafeCancellationTransport extends ICancellationSignal.Stub { |
| 1753 | private final @NonNull WeakReference<ActivityThread> mWeakActivityThread; |
| 1754 | |
| 1755 | SafeCancellationTransport(@NonNull ActivityThread activityThread, |
| 1756 | @NonNull CancellationSignal cancellation) { |
| 1757 | mWeakActivityThread = new WeakReference<>(activityThread); |
| 1758 | } |
| 1759 | |
| 1760 | @Override |
| 1761 | public void cancel() { |
| 1762 | final ActivityThread activityThread = mWeakActivityThread.get(); |
| 1763 | if (activityThread != null) { |
| 1764 | final CancellationSignal cancellation = activityThread |
| 1765 | .removeSafeCancellationTransport(this); |
| 1766 | if (cancellation != null) { |
| 1767 | cancellation.cancel(); |
| 1768 | } |
| 1769 | } |
| 1770 | } |
| 1771 | } |
| 1772 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 1773 | class H extends Handler { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1774 | public static final int BIND_APPLICATION = 110; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 1775 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1776 | public static final int EXIT_APPLICATION = 111; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 1777 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1778 | public static final int RECEIVER = 113; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 1779 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1780 | public static final int CREATE_SERVICE = 114; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 1781 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1782 | public static final int SERVICE_ARGS = 115; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 1783 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1784 | public static final int STOP_SERVICE = 116; |
Dianne Hackborn | 0923328 | 2014-04-30 11:33:59 -0700 | [diff] [blame] | 1785 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1786 | public static final int CONFIGURATION_CHANGED = 118; |
| 1787 | public static final int CLEAN_UP_CONTEXT = 119; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 1788 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1789 | public static final int GC_WHEN_IDLE = 120; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 1790 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1791 | public static final int BIND_SERVICE = 121; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 1792 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1793 | public static final int UNBIND_SERVICE = 122; |
| 1794 | public static final int DUMP_SERVICE = 123; |
| 1795 | public static final int LOW_MEMORY = 124; |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 1796 | public static final int PROFILER_CONTROL = 127; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1797 | public static final int CREATE_BACKUP_AGENT = 128; |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 1798 | public static final int DESTROY_BACKUP_AGENT = 129; |
| 1799 | public static final int SUICIDE = 130; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 1800 | @UnsupportedAppUsage |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1801 | public static final int REMOVE_PROVIDER = 131; |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1802 | public static final int DISPATCH_PACKAGE_BROADCAST = 133; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 1803 | @UnsupportedAppUsage |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 1804 | public static final int SCHEDULE_CRASH = 134; |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 1805 | public static final int DUMP_HEAP = 135; |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1806 | public static final int DUMP_ACTIVITY = 136; |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1807 | public static final int SLEEPING = 137; |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1808 | public static final int SET_CORE_SETTINGS = 138; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1809 | public static final int UPDATE_PACKAGE_COMPATIBILITY_INFO = 139; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 1810 | @UnsupportedAppUsage |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1811 | public static final int DUMP_PROVIDER = 141; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1812 | public static final int UNSTABLE_PROVIDER_DIED = 142; |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 1813 | public static final int REQUEST_ASSIST_CONTEXT_EXTRAS = 143; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1814 | public static final int TRANSLUCENT_CONVERSION_COMPLETE = 144; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 1815 | @UnsupportedAppUsage |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 1816 | public static final int INSTALL_PROVIDER = 145; |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1817 | public static final int ON_NEW_ACTIVITY_OPTIONS = 146; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 1818 | @UnsupportedAppUsage |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 1819 | public static final int ENTER_ANIMATION_COMPLETE = 149; |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 1820 | public static final int START_BINDER_TRACKING = 150; |
| 1821 | public static final int STOP_BINDER_TRACKING_AND_DUMP = 151; |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1822 | public static final int LOCAL_VOICE_INTERACTION_STARTED = 154; |
Leonard Mosescu | f3409ce | 2016-10-06 17:32:05 -0700 | [diff] [blame] | 1823 | public static final int ATTACH_AGENT = 155; |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 1824 | public static final int APPLICATION_INFO_CHANGED = 156; |
Torne (Richard Coles) | 466cbe4 | 2017-05-31 14:09:14 -0400 | [diff] [blame] | 1825 | public static final int RUN_ISOLATED_ENTRY_POINT = 158; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 1826 | public static final int EXECUTE_TRANSACTION = 159; |
Andrii Kulian | 320e3b5 | 2018-05-03 16:26:25 -0700 | [diff] [blame] | 1827 | public static final int RELAUNCH_ACTIVITY = 160; |
Tim Murray | 59f3dc1 | 2018-10-22 15:26:08 -0700 | [diff] [blame] | 1828 | public static final int PURGE_RESOURCES = 161; |
Alex Light | 2d0691c | 2019-10-03 14:36:57 -0700 | [diff] [blame] | 1829 | public static final int ATTACH_STARTUP_AGENTS = 162; |
Narayan Kamath | ccb2a086 | 2013-12-19 14:49:36 +0000 | [diff] [blame] | 1830 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1831 | String codeToString(int code) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 1832 | if (DEBUG_MESSAGES) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1833 | switch (code) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1834 | case BIND_APPLICATION: return "BIND_APPLICATION"; |
| 1835 | case EXIT_APPLICATION: return "EXIT_APPLICATION"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1836 | case RECEIVER: return "RECEIVER"; |
| 1837 | case CREATE_SERVICE: return "CREATE_SERVICE"; |
| 1838 | case SERVICE_ARGS: return "SERVICE_ARGS"; |
| 1839 | case STOP_SERVICE: return "STOP_SERVICE"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1840 | case CONFIGURATION_CHANGED: return "CONFIGURATION_CHANGED"; |
| 1841 | case CLEAN_UP_CONTEXT: return "CLEAN_UP_CONTEXT"; |
| 1842 | case GC_WHEN_IDLE: return "GC_WHEN_IDLE"; |
| 1843 | case BIND_SERVICE: return "BIND_SERVICE"; |
| 1844 | case UNBIND_SERVICE: return "UNBIND_SERVICE"; |
| 1845 | case DUMP_SERVICE: return "DUMP_SERVICE"; |
| 1846 | case LOW_MEMORY: return "LOW_MEMORY"; |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 1847 | case PROFILER_CONTROL: return "PROFILER_CONTROL"; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1848 | case CREATE_BACKUP_AGENT: return "CREATE_BACKUP_AGENT"; |
| 1849 | case DESTROY_BACKUP_AGENT: return "DESTROY_BACKUP_AGENT"; |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 1850 | case SUICIDE: return "SUICIDE"; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1851 | case REMOVE_PROVIDER: return "REMOVE_PROVIDER"; |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1852 | case DISPATCH_PACKAGE_BROADCAST: return "DISPATCH_PACKAGE_BROADCAST"; |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 1853 | case SCHEDULE_CRASH: return "SCHEDULE_CRASH"; |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 1854 | case DUMP_HEAP: return "DUMP_HEAP"; |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1855 | case DUMP_ACTIVITY: return "DUMP_ACTIVITY"; |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1856 | case SET_CORE_SETTINGS: return "SET_CORE_SETTINGS"; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1857 | case UPDATE_PACKAGE_COMPATIBILITY_INFO: return "UPDATE_PACKAGE_COMPATIBILITY_INFO"; |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1858 | case DUMP_PROVIDER: return "DUMP_PROVIDER"; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1859 | case UNSTABLE_PROVIDER_DIED: return "UNSTABLE_PROVIDER_DIED"; |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 1860 | case REQUEST_ASSIST_CONTEXT_EXTRAS: return "REQUEST_ASSIST_CONTEXT_EXTRAS"; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1861 | case TRANSLUCENT_CONVERSION_COMPLETE: return "TRANSLUCENT_CONVERSION_COMPLETE"; |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 1862 | case INSTALL_PROVIDER: return "INSTALL_PROVIDER"; |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1863 | case ON_NEW_ACTIVITY_OPTIONS: return "ON_NEW_ACTIVITY_OPTIONS"; |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 1864 | case ENTER_ANIMATION_COMPLETE: return "ENTER_ANIMATION_COMPLETE"; |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1865 | case LOCAL_VOICE_INTERACTION_STARTED: return "LOCAL_VOICE_INTERACTION_STARTED"; |
Leonard Mosescu | f3409ce | 2016-10-06 17:32:05 -0700 | [diff] [blame] | 1866 | case ATTACH_AGENT: return "ATTACH_AGENT"; |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 1867 | case APPLICATION_INFO_CHANGED: return "APPLICATION_INFO_CHANGED"; |
Torne (Richard Coles) | 466cbe4 | 2017-05-31 14:09:14 -0400 | [diff] [blame] | 1868 | case RUN_ISOLATED_ENTRY_POINT: return "RUN_ISOLATED_ENTRY_POINT"; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 1869 | case EXECUTE_TRANSACTION: return "EXECUTE_TRANSACTION"; |
Andrii Kulian | 320e3b5 | 2018-05-03 16:26:25 -0700 | [diff] [blame] | 1870 | case RELAUNCH_ACTIVITY: return "RELAUNCH_ACTIVITY"; |
Tim Murray | 59f3dc1 | 2018-10-22 15:26:08 -0700 | [diff] [blame] | 1871 | case PURGE_RESOURCES: return "PURGE_RESOURCES"; |
Alex Light | 2d0691c | 2019-10-03 14:36:57 -0700 | [diff] [blame] | 1872 | case ATTACH_STARTUP_AGENTS: return "ATTACH_STARTUP_AGENTS"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1873 | } |
| 1874 | } |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 1875 | return Integer.toString(code); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1876 | } |
| 1877 | public void handleMessage(Message msg) { |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 1878 | 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] | 1879 | switch (msg.what) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1880 | case BIND_APPLICATION: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1881 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "bindApplication"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1882 | AppBindData data = (AppBindData)msg.obj; |
| 1883 | handleBindApplication(data); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1884 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1885 | break; |
| 1886 | case EXIT_APPLICATION: |
| 1887 | if (mInitialApplication != null) { |
| 1888 | mInitialApplication.onTerminate(); |
| 1889 | } |
| 1890 | Looper.myLooper().quit(); |
| 1891 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1892 | case RECEIVER: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1893 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "broadcastReceiveComp"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1894 | handleReceiver((ReceiverData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1895 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1896 | break; |
| 1897 | case CREATE_SERVICE: |
John Reck | e48e6da | 2019-06-20 14:59:51 -0700 | [diff] [blame] | 1898 | if (Trace.isTagEnabled(Trace.TRACE_TAG_ACTIVITY_MANAGER)) { |
| 1899 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, |
| 1900 | ("serviceCreate: " + String.valueOf(msg.obj))); |
| 1901 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1902 | handleCreateService((CreateServiceData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1903 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1904 | break; |
| 1905 | case BIND_SERVICE: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1906 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "serviceBind"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1907 | handleBindService((BindServiceData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1908 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1909 | break; |
| 1910 | case UNBIND_SERVICE: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1911 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "serviceUnbind"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1912 | handleUnbindService((BindServiceData)msg.obj); |
Tim Murray | 59f3dc1 | 2018-10-22 15:26:08 -0700 | [diff] [blame] | 1913 | schedulePurgeIdler(); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1914 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1915 | break; |
| 1916 | case SERVICE_ARGS: |
John Reck | e48e6da | 2019-06-20 14:59:51 -0700 | [diff] [blame] | 1917 | if (Trace.isTagEnabled(Trace.TRACE_TAG_ACTIVITY_MANAGER)) { |
| 1918 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, |
| 1919 | ("serviceStart: " + String.valueOf(msg.obj))); |
| 1920 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1921 | handleServiceArgs((ServiceArgsData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1922 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1923 | break; |
| 1924 | case STOP_SERVICE: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1925 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "serviceStop"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1926 | handleStopService((IBinder)msg.obj); |
Tim Murray | 59f3dc1 | 2018-10-22 15:26:08 -0700 | [diff] [blame] | 1927 | schedulePurgeIdler(); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1928 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1929 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1930 | case CONFIGURATION_CHANGED: |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 1931 | handleConfigurationChanged((Configuration) msg.obj); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1932 | break; |
| 1933 | case CLEAN_UP_CONTEXT: |
| 1934 | ContextCleanupInfo cci = (ContextCleanupInfo)msg.obj; |
| 1935 | cci.context.performFinalCleanup(cci.who, cci.what); |
| 1936 | break; |
| 1937 | case GC_WHEN_IDLE: |
| 1938 | scheduleGcIdler(); |
| 1939 | break; |
| 1940 | case DUMP_SERVICE: |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1941 | handleDumpService((DumpComponentInfo)msg.obj); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1942 | break; |
| 1943 | case LOW_MEMORY: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1944 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "lowMemory"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1945 | handleLowMemory(); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1946 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1947 | break; |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 1948 | case PROFILER_CONTROL: |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 1949 | handleProfilerControl(msg.arg1 != 0, (ProfilerInfo)msg.obj, msg.arg2); |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 1950 | break; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1951 | case CREATE_BACKUP_AGENT: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1952 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "backupCreateAgent"); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1953 | handleCreateBackupAgent((CreateBackupAgentData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1954 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1955 | break; |
| 1956 | case DESTROY_BACKUP_AGENT: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1957 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "backupDestroyAgent"); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1958 | handleDestroyBackupAgent((CreateBackupAgentData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1959 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1960 | break; |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 1961 | case SUICIDE: |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1962 | Process.killProcess(Process.myPid()); |
| 1963 | break; |
| 1964 | case REMOVE_PROVIDER: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1965 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "providerRemove"); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1966 | completeRemoveProvider((ProviderRefCount)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1967 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 1968 | break; |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1969 | case DISPATCH_PACKAGE_BROADCAST: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1970 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "broadcastPackage"); |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1971 | handleDispatchPackageBroadcast(msg.arg1, (String[])msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1972 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1973 | break; |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 1974 | case SCHEDULE_CRASH: |
| 1975 | throw new RemoteServiceException((String)msg.obj); |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 1976 | case DUMP_HEAP: |
Christopher Ferris | 8d652f8 | 2017-04-11 16:29:18 -0700 | [diff] [blame] | 1977 | handleDumpHeap((DumpHeapData) msg.obj); |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 1978 | break; |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1979 | case DUMP_ACTIVITY: |
| 1980 | handleDumpActivity((DumpComponentInfo)msg.obj); |
| 1981 | break; |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1982 | case DUMP_PROVIDER: |
| 1983 | handleDumpProvider((DumpComponentInfo)msg.obj); |
| 1984 | break; |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1985 | case SET_CORE_SETTINGS: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1986 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "setCoreSettings"); |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1987 | handleSetCoreSettings((Bundle) msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1988 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1989 | break; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1990 | case UPDATE_PACKAGE_COMPATIBILITY_INFO: |
| 1991 | handleUpdatePackageCompatibilityInfo((UpdateCompatibilityData)msg.obj); |
Dianne Hackborn | f0754f5b | 2011-07-21 16:02:07 -0700 | [diff] [blame] | 1992 | break; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1993 | case UNSTABLE_PROVIDER_DIED: |
| 1994 | handleUnstableProviderDied((IBinder)msg.obj, false); |
| 1995 | break; |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 1996 | case REQUEST_ASSIST_CONTEXT_EXTRAS: |
| 1997 | handleRequestAssistContextExtras((RequestAssistContextExtras)msg.obj); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 1998 | break; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1999 | case TRANSLUCENT_CONVERSION_COMPLETE: |
| 2000 | handleTranslucentConversionComplete((IBinder)msg.obj, msg.arg1 == 1); |
| 2001 | break; |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 2002 | case INSTALL_PROVIDER: |
| 2003 | handleInstallProvider((ProviderInfo) msg.obj); |
| 2004 | break; |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 2005 | case ON_NEW_ACTIVITY_OPTIONS: |
| 2006 | Pair<IBinder, ActivityOptions> pair = (Pair<IBinder, ActivityOptions>) msg.obj; |
| 2007 | onNewActivityOptions(pair.first, pair.second); |
Dake Gu | 7ef70b0 | 2014-07-08 18:37:12 -0700 | [diff] [blame] | 2008 | break; |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 2009 | case ENTER_ANIMATION_COMPLETE: |
| 2010 | handleEnterAnimationComplete((IBinder) msg.obj); |
| 2011 | break; |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 2012 | case START_BINDER_TRACKING: |
| 2013 | handleStartBinderTracking(); |
| 2014 | break; |
| 2015 | case STOP_BINDER_TRACKING_AND_DUMP: |
| 2016 | handleStopBinderTrackingAndDump((ParcelFileDescriptor) msg.obj); |
| 2017 | break; |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 2018 | case LOCAL_VOICE_INTERACTION_STARTED: |
| 2019 | handleLocalVoiceInteractionStarted((IBinder) ((SomeArgs) msg.obj).arg1, |
| 2020 | (IVoiceInteractor) ((SomeArgs) msg.obj).arg2); |
Amith Yamasani | 6101911 | 2017-01-10 15:05:00 -0800 | [diff] [blame] | 2021 | break; |
Andreas Gampe | ab8a63b | 2018-01-05 13:55:15 -0800 | [diff] [blame] | 2022 | case ATTACH_AGENT: { |
| 2023 | Application app = getApplication(); |
| 2024 | handleAttachAgent((String) msg.obj, app != null ? app.mLoadedApk : null); |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 2025 | break; |
Andreas Gampe | ab8a63b | 2018-01-05 13:55:15 -0800 | [diff] [blame] | 2026 | } |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 2027 | case APPLICATION_INFO_CHANGED: |
| 2028 | mUpdatingSystemConfig = true; |
| 2029 | try { |
| 2030 | handleApplicationInfoChanged((ApplicationInfo) msg.obj); |
| 2031 | } finally { |
| 2032 | mUpdatingSystemConfig = false; |
| 2033 | } |
| 2034 | break; |
Torne (Richard Coles) | 466cbe4 | 2017-05-31 14:09:14 -0400 | [diff] [blame] | 2035 | case RUN_ISOLATED_ENTRY_POINT: |
| 2036 | handleRunIsolatedEntryPoint((String) ((SomeArgs) msg.obj).arg1, |
| 2037 | (String[]) ((SomeArgs) msg.obj).arg2); |
| 2038 | break; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 2039 | case EXECUTE_TRANSACTION: |
Andrii Kulian | 0447068 | 2018-01-10 15:32:31 -0800 | [diff] [blame] | 2040 | final ClientTransaction transaction = (ClientTransaction) msg.obj; |
| 2041 | mTransactionExecutor.execute(transaction); |
| 2042 | if (isSystem()) { |
| 2043 | // Client transactions inside system process are recycled on the client side |
| 2044 | // instead of ClientLifecycleManager to avoid being cleared before this |
| 2045 | // message is handled. |
| 2046 | transaction.recycle(); |
| 2047 | } |
Andrii Kulian | 914aa7d | 2018-03-19 21:51:53 -0700 | [diff] [blame] | 2048 | // TODO(lifecycler): Recycle locally scheduled transactions. |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 2049 | break; |
Andrii Kulian | 320e3b5 | 2018-05-03 16:26:25 -0700 | [diff] [blame] | 2050 | case RELAUNCH_ACTIVITY: |
| 2051 | handleRelaunchActivityLocally((IBinder) msg.obj); |
| 2052 | break; |
Tim Murray | 59f3dc1 | 2018-10-22 15:26:08 -0700 | [diff] [blame] | 2053 | case PURGE_RESOURCES: |
| 2054 | schedulePurgeIdler(); |
| 2055 | break; |
Alex Light | 2d0691c | 2019-10-03 14:36:57 -0700 | [diff] [blame] | 2056 | case ATTACH_STARTUP_AGENTS: |
| 2057 | handleAttachStartupAgents((String) msg.obj); |
| 2058 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2059 | } |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 2060 | Object obj = msg.obj; |
| 2061 | if (obj instanceof SomeArgs) { |
| 2062 | ((SomeArgs) obj).recycle(); |
| 2063 | } |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 2064 | 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] | 2065 | } |
| 2066 | } |
| 2067 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 2068 | private class Idler implements MessageQueue.IdleHandler { |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 2069 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2070 | public final boolean queueIdle() { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2071 | ActivityClientRecord a = mNewActivities; |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 2072 | boolean stopProfiling = false; |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 2073 | if (mBoundApplication != null && mProfiler.profileFd != null |
| 2074 | && mProfiler.autoStopProfiler) { |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 2075 | stopProfiling = true; |
| 2076 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2077 | if (a != null) { |
| 2078 | mNewActivities = null; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2079 | IActivityTaskManager am = ActivityTaskManager.getService(); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2080 | ActivityClientRecord prev; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2081 | do { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2082 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2083 | TAG, "Reporting idle of " + a + |
| 2084 | " finished=" + |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 2085 | (a.activity != null && a.activity.mFinished)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2086 | if (a.activity != null && !a.activity.mFinished) { |
| 2087 | try { |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 2088 | am.activityIdle(a.token, a.createdConfig, stopProfiling); |
Dianne Hackborn | e88846e | 2009-09-30 21:34:25 -0700 | [diff] [blame] | 2089 | a.createdConfig = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2090 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2091 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2092 | } |
| 2093 | } |
| 2094 | prev = a; |
| 2095 | a = a.nextIdle; |
| 2096 | prev.nextIdle = null; |
| 2097 | } while (a != null); |
| 2098 | } |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 2099 | if (stopProfiling) { |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 2100 | mProfiler.stopProfiling(); |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 2101 | } |
Riddle Hsu | 50e3400 | 2019-04-12 20:42:05 +0800 | [diff] [blame] | 2102 | applyPendingProcessState(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2103 | return false; |
| 2104 | } |
| 2105 | } |
| 2106 | |
| 2107 | final class GcIdler implements MessageQueue.IdleHandler { |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 2108 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2109 | public final boolean queueIdle() { |
| 2110 | doGcIfNeeded(); |
Makoto Onuki | 0a9ee1a | 2019-06-19 08:58:02 -0700 | [diff] [blame] | 2111 | purgePendingResources(); |
Tim Murray | 59f3dc1 | 2018-10-22 15:26:08 -0700 | [diff] [blame] | 2112 | return false; |
| 2113 | } |
| 2114 | } |
| 2115 | |
| 2116 | final class PurgeIdler implements MessageQueue.IdleHandler { |
| 2117 | @Override |
| 2118 | public boolean queueIdle() { |
Makoto Onuki | 0a9ee1a | 2019-06-19 08:58:02 -0700 | [diff] [blame] | 2119 | purgePendingResources(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2120 | return false; |
| 2121 | } |
| 2122 | } |
| 2123 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 2124 | @UnsupportedAppUsage |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 2125 | public static ActivityThread currentActivityThread() { |
Jeff Sharkey | 66a017b | 2013-01-17 18:18:22 -0800 | [diff] [blame] | 2126 | return sCurrentActivityThread; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2127 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2128 | |
Wale Ogunwale | 9a6ef1e | 2015-06-02 13:41:00 -0700 | [diff] [blame] | 2129 | public static boolean isSystem() { |
| 2130 | return (sCurrentActivityThread != null) ? sCurrentActivityThread.mSystemThread : false; |
| 2131 | } |
| 2132 | |
Svetoslav | fbf0eca | 2015-05-01 16:52:41 -0700 | [diff] [blame] | 2133 | public static String currentOpPackageName() { |
| 2134 | ActivityThread am = currentActivityThread(); |
| 2135 | return (am != null && am.getApplication() != null) |
| 2136 | ? am.getApplication().getOpPackageName() : null; |
| 2137 | } |
| 2138 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 2139 | @UnsupportedAppUsage |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 2140 | public static String currentPackageName() { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2141 | ActivityThread am = currentActivityThread(); |
| 2142 | return (am != null && am.mBoundApplication != null) |
Dianne Hackborn | b57a50b | 2013-04-11 17:29:32 -0700 | [diff] [blame] | 2143 | ? am.mBoundApplication.appInfo.packageName : null; |
| 2144 | } |
| 2145 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 2146 | @UnsupportedAppUsage |
Dianne Hackborn | b57a50b | 2013-04-11 17:29:32 -0700 | [diff] [blame] | 2147 | public static String currentProcessName() { |
| 2148 | ActivityThread am = currentActivityThread(); |
| 2149 | return (am != null && am.mBoundApplication != null) |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2150 | ? am.mBoundApplication.processName : null; |
| 2151 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2152 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 2153 | @UnsupportedAppUsage |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 2154 | public static Application currentApplication() { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2155 | ActivityThread am = currentActivityThread(); |
| 2156 | return am != null ? am.mInitialApplication : null; |
| 2157 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2158 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 2159 | @UnsupportedAppUsage |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2160 | public static IPackageManager getPackageManager() { |
| 2161 | if (sPackageManager != null) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2162 | return sPackageManager; |
| 2163 | } |
Todd Kennedy | 8f13598 | 2019-07-02 07:35:15 -0700 | [diff] [blame] | 2164 | final IBinder b = ServiceManager.getService("package"); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2165 | sPackageManager = IPackageManager.Stub.asInterface(b); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2166 | return sPackageManager; |
| 2167 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2168 | |
Todd Kennedy | 8f13598 | 2019-07-02 07:35:15 -0700 | [diff] [blame] | 2169 | /** Returns the permission manager */ |
| 2170 | public static IPermissionManager getPermissionManager() { |
| 2171 | if (sPermissionManager != null) { |
| 2172 | return sPermissionManager; |
| 2173 | } |
| 2174 | final IBinder b = ServiceManager.getService("permissionmgr"); |
| 2175 | sPermissionManager = IPermissionManager.Stub.asInterface(b); |
| 2176 | return sPermissionManager; |
| 2177 | } |
| 2178 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 2179 | private Configuration mMainThreadConfig = new Configuration(); |
Amith Yamasani | 4f128e4 | 2016-05-10 11:44:12 -0700 | [diff] [blame] | 2180 | |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 2181 | Configuration applyConfigCompatMainThread(int displayDensity, Configuration config, |
| 2182 | CompatibilityInfo compat) { |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 2183 | if (config == null) { |
| 2184 | return null; |
| 2185 | } |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 2186 | if (!compat.supportsScreen()) { |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 2187 | mMainThreadConfig.setTo(config); |
| 2188 | config = mMainThreadConfig; |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 2189 | compat.applyToConfiguration(displayDensity, config); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 2190 | } |
| 2191 | return config; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2192 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2193 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2194 | /** |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 2195 | * Creates the top level resources for the given package. Will return an existing |
| 2196 | * Resources if one has already been created. |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2197 | */ |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 2198 | Resources getTopLevelResources(String resDir, String[] splitResDirs, String[] overlayDirs, |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 2199 | String[] libDirs, int displayId, LoadedApk pkgInfo) { |
| 2200 | return mResourcesManager.getResources(null, resDir, splitResDirs, overlayDirs, libDirs, |
| 2201 | displayId, null, pkgInfo.getCompatibilityInfo(), pkgInfo.getClassLoader()); |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 2202 | } |
| 2203 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 2204 | @UnsupportedAppUsage |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2205 | final Handler getHandler() { |
| 2206 | return mH; |
| 2207 | } |
| 2208 | |
Mathew Inwood | 8c854f8 | 2018-09-14 12:35:36 +0100 | [diff] [blame] | 2209 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2210 | public final LoadedApk getPackageInfo(String packageName, CompatibilityInfo compatInfo, |
| 2211 | int flags) { |
| 2212 | return getPackageInfo(packageName, compatInfo, flags, UserHandle.myUserId()); |
Amith Yamasani | 98edc95 | 2012-09-25 14:09:27 -0700 | [diff] [blame] | 2213 | } |
| 2214 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2215 | public final LoadedApk getPackageInfo(String packageName, CompatibilityInfo compatInfo, |
| 2216 | int flags, int userId) { |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 2217 | final boolean differentUser = (UserHandle.myUserId() != userId); |
Winson | 83708c8 | 2019-02-19 12:34:17 -0800 | [diff] [blame] | 2218 | ApplicationInfo ai; |
| 2219 | try { |
| 2220 | ai = getPackageManager().getApplicationInfo(packageName, |
| 2221 | PackageManager.GET_SHARED_LIBRARY_FILES |
| 2222 | | PackageManager.MATCH_DEBUG_TRIAGED_MISSING, |
| 2223 | (userId < 0) ? UserHandle.myUserId() : userId); |
| 2224 | } catch (RemoteException e) { |
| 2225 | throw e.rethrowFromSystemServer(); |
| 2226 | } |
| 2227 | |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 2228 | synchronized (mResourcesManager) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2229 | WeakReference<LoadedApk> ref; |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 2230 | if (differentUser) { |
| 2231 | // Caching not supported across users |
| 2232 | ref = null; |
| 2233 | } else if ((flags & Context.CONTEXT_INCLUDE_CODE) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2234 | ref = mPackages.get(packageName); |
| 2235 | } else { |
| 2236 | ref = mResourcePackages.get(packageName); |
| 2237 | } |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 2238 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2239 | LoadedApk packageInfo = ref != null ? ref.get() : null; |
Winson | 71cf350 | 2019-04-09 18:00:08 -0700 | [diff] [blame] | 2240 | if (ai != null && packageInfo != null) { |
| 2241 | if (!isLoadedApkResourceDirsUpToDate(packageInfo, ai)) { |
| 2242 | packageInfo.updateApplicationInfo(ai, null); |
| 2243 | } |
| 2244 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2245 | if (packageInfo.isSecurityViolation() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2246 | && (flags&Context.CONTEXT_IGNORE_SECURITY) == 0) { |
| 2247 | throw new SecurityException( |
| 2248 | "Requesting code from " + packageName |
| 2249 | + " to be run in process " |
| 2250 | + mBoundApplication.processName |
| 2251 | + "/" + mBoundApplication.appInfo.uid); |
| 2252 | } |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2253 | return packageInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2254 | } |
| 2255 | } |
| 2256 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2257 | if (ai != null) { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2258 | return getPackageInfo(ai, compatInfo, flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2259 | } |
| 2260 | |
| 2261 | return null; |
| 2262 | } |
| 2263 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 2264 | @UnsupportedAppUsage |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2265 | public final LoadedApk getPackageInfo(ApplicationInfo ai, CompatibilityInfo compatInfo, |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2266 | int flags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2267 | boolean includeCode = (flags&Context.CONTEXT_INCLUDE_CODE) != 0; |
| 2268 | boolean securityViolation = includeCode && ai.uid != 0 |
| 2269 | && ai.uid != Process.SYSTEM_UID && (mBoundApplication != null |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 2270 | ? !UserHandle.isSameApp(ai.uid, mBoundApplication.appInfo.uid) |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 2271 | : true); |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 2272 | boolean registerPackage = includeCode && (flags&Context.CONTEXT_REGISTER_PACKAGE) != 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2273 | if ((flags&(Context.CONTEXT_INCLUDE_CODE |
| 2274 | |Context.CONTEXT_IGNORE_SECURITY)) |
| 2275 | == Context.CONTEXT_INCLUDE_CODE) { |
| 2276 | if (securityViolation) { |
| 2277 | String msg = "Requesting code from " + ai.packageName |
| 2278 | + " (with uid " + ai.uid + ")"; |
| 2279 | if (mBoundApplication != null) { |
| 2280 | msg = msg + " to be run in process " |
| 2281 | + mBoundApplication.processName + " (with uid " |
| 2282 | + mBoundApplication.appInfo.uid + ")"; |
| 2283 | } |
| 2284 | throw new SecurityException(msg); |
| 2285 | } |
| 2286 | } |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2287 | return getPackageInfo(ai, compatInfo, null, securityViolation, includeCode, |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 2288 | registerPackage); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2289 | } |
| 2290 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 2291 | @Override |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 2292 | @UnsupportedAppUsage |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2293 | public final LoadedApk getPackageInfoNoCheck(ApplicationInfo ai, |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2294 | CompatibilityInfo compatInfo) { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2295 | return getPackageInfo(ai, compatInfo, null, false, true, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2296 | } |
| 2297 | |
Mathew Inwood | 8c854f8 | 2018-09-14 12:35:36 +0100 | [diff] [blame] | 2298 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2299 | public final LoadedApk peekPackageInfo(String packageName, boolean includeCode) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 2300 | synchronized (mResourcesManager) { |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2301 | WeakReference<LoadedApk> ref; |
| 2302 | if (includeCode) { |
| 2303 | ref = mPackages.get(packageName); |
| 2304 | } else { |
| 2305 | ref = mResourcePackages.get(packageName); |
| 2306 | } |
| 2307 | return ref != null ? ref.get() : null; |
| 2308 | } |
| 2309 | } |
| 2310 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2311 | private LoadedApk getPackageInfo(ApplicationInfo aInfo, CompatibilityInfo compatInfo, |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 2312 | ClassLoader baseLoader, boolean securityViolation, boolean includeCode, |
| 2313 | boolean registerPackage) { |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 2314 | final boolean differentUser = (UserHandle.myUserId() != UserHandle.getUserId(aInfo.uid)); |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 2315 | synchronized (mResourcesManager) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2316 | WeakReference<LoadedApk> ref; |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 2317 | if (differentUser) { |
| 2318 | // Caching not supported across users |
| 2319 | ref = null; |
| 2320 | } else if (includeCode) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2321 | ref = mPackages.get(aInfo.packageName); |
| 2322 | } else { |
| 2323 | ref = mResourcePackages.get(aInfo.packageName); |
| 2324 | } |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 2325 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2326 | LoadedApk packageInfo = ref != null ? ref.get() : null; |
Winson | 83708c8 | 2019-02-19 12:34:17 -0800 | [diff] [blame] | 2327 | |
Winson | 71cf350 | 2019-04-09 18:00:08 -0700 | [diff] [blame] | 2328 | if (packageInfo != null) { |
| 2329 | if (!isLoadedApkResourceDirsUpToDate(packageInfo, aInfo)) { |
| 2330 | packageInfo.updateApplicationInfo(aInfo, null); |
| 2331 | } |
Winson | 83708c8 | 2019-02-19 12:34:17 -0800 | [diff] [blame] | 2332 | |
Winson | 83708c8 | 2019-02-19 12:34:17 -0800 | [diff] [blame] | 2333 | return packageInfo; |
| 2334 | } |
| 2335 | |
| 2336 | if (localLOGV) { |
| 2337 | Slog.v(TAG, (includeCode ? "Loading code package " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2338 | : "Loading resource-only package ") + aInfo.packageName |
| 2339 | + " (in " + (mBoundApplication != null |
Winson | 83708c8 | 2019-02-19 12:34:17 -0800 | [diff] [blame] | 2340 | ? mBoundApplication.processName : null) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2341 | + ")"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2342 | } |
Winson | 83708c8 | 2019-02-19 12:34:17 -0800 | [diff] [blame] | 2343 | |
| 2344 | packageInfo = |
| 2345 | new LoadedApk(this, aInfo, compatInfo, baseLoader, |
| 2346 | securityViolation, includeCode |
| 2347 | && (aInfo.flags & ApplicationInfo.FLAG_HAS_CODE) != 0, registerPackage); |
| 2348 | |
| 2349 | if (mSystemThread && "android".equals(aInfo.packageName)) { |
| 2350 | packageInfo.installSystemApplicationInfo(aInfo, |
| 2351 | getSystemContext().mPackageInfo.getClassLoader()); |
| 2352 | } |
| 2353 | |
| 2354 | if (differentUser) { |
| 2355 | // Caching not supported across users |
| 2356 | } else if (includeCode) { |
| 2357 | mPackages.put(aInfo.packageName, |
| 2358 | new WeakReference<LoadedApk>(packageInfo)); |
| 2359 | } else { |
| 2360 | mResourcePackages.put(aInfo.packageName, |
| 2361 | new WeakReference<LoadedApk>(packageInfo)); |
| 2362 | } |
| 2363 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2364 | return packageInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2365 | } |
| 2366 | } |
| 2367 | |
Winson | 71cf350 | 2019-04-09 18:00:08 -0700 | [diff] [blame] | 2368 | private static boolean isLoadedApkResourceDirsUpToDate(LoadedApk loadedApk, |
| 2369 | ApplicationInfo appInfo) { |
Winson | 83708c8 | 2019-02-19 12:34:17 -0800 | [diff] [blame] | 2370 | Resources packageResources = loadedApk.mResources; |
| 2371 | String[] overlayDirs = ArrayUtils.defeatNullable(loadedApk.getOverlayDirs()); |
| 2372 | String[] resourceDirs = ArrayUtils.defeatNullable(appInfo.resourceDirs); |
| 2373 | |
| 2374 | return (packageResources == null || packageResources.getAssets().isUpToDate()) |
| 2375 | && overlayDirs.length == resourceDirs.length |
| 2376 | && ArrayUtils.containsAll(overlayDirs, resourceDirs); |
| 2377 | } |
| 2378 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 2379 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2380 | ActivityThread() { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 2381 | mResourcesManager = ResourcesManager.getInstance(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2382 | } |
| 2383 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 2384 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2385 | public ApplicationThread getApplicationThread() |
| 2386 | { |
| 2387 | return mAppThread; |
| 2388 | } |
| 2389 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 2390 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2391 | public Instrumentation getInstrumentation() |
| 2392 | { |
| 2393 | return mInstrumentation; |
| 2394 | } |
| 2395 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2396 | public boolean isProfiling() { |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 2397 | return mProfiler != null && mProfiler.profileFile != null |
| 2398 | && mProfiler.profileFd == null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2399 | } |
| 2400 | |
| 2401 | public String getProfileFilePath() { |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 2402 | return mProfiler.profileFile; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2403 | } |
| 2404 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 2405 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2406 | public Looper getLooper() { |
| 2407 | return mLooper; |
| 2408 | } |
| 2409 | |
Jeff Sharkey | 8439ac0 | 2017-12-12 17:26:23 -0700 | [diff] [blame] | 2410 | public Executor getExecutor() { |
| 2411 | return mExecutor; |
| 2412 | } |
| 2413 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 2414 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2415 | public Application getApplication() { |
| 2416 | return mInitialApplication; |
| 2417 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2418 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 2419 | @UnsupportedAppUsage |
Dianne Hackborn | d97c7ad | 2009-06-19 11:37:35 -0700 | [diff] [blame] | 2420 | public String getProcessName() { |
| 2421 | return mBoundApplication.processName; |
| 2422 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2423 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 2424 | @UnsupportedAppUsage |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 2425 | public ContextImpl getSystemContext() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2426 | synchronized (this) { |
| 2427 | if (mSystemContext == null) { |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 2428 | mSystemContext = ContextImpl.createSystemContext(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2429 | } |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 2430 | return mSystemContext; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2431 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2432 | } |
| 2433 | |
Adam Lesinski | a82b626 | 2017-03-21 16:56:17 -0700 | [diff] [blame] | 2434 | public ContextImpl getSystemUiContext() { |
| 2435 | synchronized (this) { |
| 2436 | if (mSystemUiContext == null) { |
Adam Lesinski | 6f1a917 | 2017-04-10 16:35:19 -0700 | [diff] [blame] | 2437 | mSystemUiContext = ContextImpl.createSystemUiContext(getSystemContext()); |
Adam Lesinski | a82b626 | 2017-03-21 16:56:17 -0700 | [diff] [blame] | 2438 | } |
| 2439 | return mSystemUiContext; |
| 2440 | } |
| 2441 | } |
| 2442 | |
lumark | 0b05f9e | 2018-11-26 15:09:06 +0800 | [diff] [blame] | 2443 | /** |
| 2444 | * Create the context instance base on system resources & display information which used for UI. |
| 2445 | * @param displayId The ID of the display where the UI is shown. |
| 2446 | * @see ContextImpl#createSystemUiContext(ContextImpl, int) |
| 2447 | */ |
| 2448 | public ContextImpl createSystemUiContext(int displayId) { |
| 2449 | return ContextImpl.createSystemUiContext(getSystemUiContext(), displayId); |
| 2450 | } |
| 2451 | |
Narayan Kamath | 29564cd | 2014-08-07 10:57:40 +0100 | [diff] [blame] | 2452 | public void installSystemApplicationInfo(ApplicationInfo info, ClassLoader classLoader) { |
Mike Cleron | 432b713 | 2009-09-24 15:28:29 -0700 | [diff] [blame] | 2453 | synchronized (this) { |
Narayan Kamath | 29564cd | 2014-08-07 10:57:40 +0100 | [diff] [blame] | 2454 | getSystemContext().installSystemApplicationInfo(info, classLoader); |
Adam Lesinski | a82b626 | 2017-03-21 16:56:17 -0700 | [diff] [blame] | 2455 | getSystemUiContext().installSystemApplicationInfo(info, classLoader); |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 2456 | |
| 2457 | // give ourselves a default profiler |
| 2458 | mProfiler = new Profiler(); |
Mike Cleron | 432b713 | 2009-09-24 15:28:29 -0700 | [diff] [blame] | 2459 | } |
| 2460 | } |
| 2461 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 2462 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2463 | void scheduleGcIdler() { |
| 2464 | if (!mGcIdlerScheduled) { |
| 2465 | mGcIdlerScheduled = true; |
| 2466 | Looper.myQueue().addIdleHandler(mGcIdler); |
| 2467 | } |
| 2468 | mH.removeMessages(H.GC_WHEN_IDLE); |
| 2469 | } |
| 2470 | |
| 2471 | void unscheduleGcIdler() { |
| 2472 | if (mGcIdlerScheduled) { |
| 2473 | mGcIdlerScheduled = false; |
| 2474 | Looper.myQueue().removeIdleHandler(mGcIdler); |
| 2475 | } |
| 2476 | mH.removeMessages(H.GC_WHEN_IDLE); |
| 2477 | } |
| 2478 | |
Tim Murray | 59f3dc1 | 2018-10-22 15:26:08 -0700 | [diff] [blame] | 2479 | void schedulePurgeIdler() { |
| 2480 | if (!mPurgeIdlerScheduled) { |
| 2481 | mPurgeIdlerScheduled = true; |
| 2482 | Looper.myQueue().addIdleHandler(mPurgeIdler); |
| 2483 | } |
| 2484 | mH.removeMessages(H.PURGE_RESOURCES); |
| 2485 | } |
| 2486 | |
| 2487 | void unschedulePurgeIdler() { |
| 2488 | if (mPurgeIdlerScheduled) { |
| 2489 | mPurgeIdlerScheduled = false; |
| 2490 | Looper.myQueue().removeIdleHandler(mPurgeIdler); |
| 2491 | } |
| 2492 | mH.removeMessages(H.PURGE_RESOURCES); |
| 2493 | } |
| 2494 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2495 | void doGcIfNeeded() { |
Makoto Onuki | 0a9ee1a | 2019-06-19 08:58:02 -0700 | [diff] [blame] | 2496 | doGcIfNeeded("bg"); |
| 2497 | } |
| 2498 | |
| 2499 | void doGcIfNeeded(String reason) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2500 | mGcIdlerScheduled = false; |
| 2501 | final long now = SystemClock.uptimeMillis(); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2502 | //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] | 2503 | // + "m now=" + now); |
| 2504 | if ((BinderInternal.getLastGcTime()+MIN_TIME_BETWEEN_GCS) < now) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2505 | //Slog.i(TAG, "**** WE DO, WE DO WANT TO GC!"); |
Makoto Onuki | 0a9ee1a | 2019-06-19 08:58:02 -0700 | [diff] [blame] | 2506 | BinderInternal.forceGc(reason); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2507 | } |
| 2508 | } |
| 2509 | |
Jing Ji | a736da8 | 2019-08-06 15:08:02 -0700 | [diff] [blame] | 2510 | private static final String HEAP_FULL_COLUMN = |
| 2511 | "%13s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s"; |
| 2512 | private static final String HEAP_COLUMN = |
| 2513 | "%13s %8s %8s %8s %8s %8s %8s %8s %8s"; |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2514 | private static final String ONE_COUNT_COLUMN = "%21s %8d"; |
| 2515 | private static final String TWO_COUNT_COLUMNS = "%21s %8d %21s %8d"; |
Jing Ji | a736da8 | 2019-08-06 15:08:02 -0700 | [diff] [blame] | 2516 | private static final String THREE_COUNT_COLUMNS = "%21s %8d %21s %8s %21s %8d"; |
| 2517 | private static final String TWO_COUNT_COLUMN_HEADER = "%21s %8s %21s %8s"; |
| 2518 | private static final String ONE_ALT_COUNT_COLUMN = "%21s %8s %21s %8d"; |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2519 | |
| 2520 | // Formatting for checkin service - update version if row format changes |
Martijn Coenen | 41f94ed | 2015-12-14 15:28:51 +0100 | [diff] [blame] | 2521 | private static final int ACTIVITY_THREAD_CHECKIN_VERSION = 4; |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2522 | |
| 2523 | static void printRow(PrintWriter pw, String format, Object...objs) { |
| 2524 | pw.println(String.format(format, objs)); |
| 2525 | } |
| 2526 | |
| 2527 | public static void dumpMemInfoTable(PrintWriter pw, Debug.MemoryInfo memInfo, boolean checkin, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2528 | boolean dumpFullInfo, boolean dumpDalvik, boolean dumpSummaryOnly, |
| 2529 | int pid, String processName, |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2530 | long nativeMax, long nativeAllocated, long nativeFree, |
| 2531 | long dalvikMax, long dalvikAllocated, long dalvikFree) { |
| 2532 | |
| 2533 | // For checkin, we print one long comma-separated list of values |
| 2534 | if (checkin) { |
| 2535 | // NOTE: if you change anything significant below, also consider changing |
| 2536 | // ACTIVITY_THREAD_CHECKIN_VERSION. |
| 2537 | |
| 2538 | // Header |
| 2539 | pw.print(ACTIVITY_THREAD_CHECKIN_VERSION); pw.print(','); |
| 2540 | pw.print(pid); pw.print(','); |
| 2541 | pw.print(processName); pw.print(','); |
| 2542 | |
| 2543 | // Heap info - max |
| 2544 | pw.print(nativeMax); pw.print(','); |
| 2545 | pw.print(dalvikMax); pw.print(','); |
| 2546 | pw.print("N/A,"); |
| 2547 | pw.print(nativeMax + dalvikMax); pw.print(','); |
| 2548 | |
| 2549 | // Heap info - allocated |
| 2550 | pw.print(nativeAllocated); pw.print(','); |
| 2551 | pw.print(dalvikAllocated); pw.print(','); |
| 2552 | pw.print("N/A,"); |
| 2553 | pw.print(nativeAllocated + dalvikAllocated); pw.print(','); |
| 2554 | |
| 2555 | // Heap info - free |
| 2556 | pw.print(nativeFree); pw.print(','); |
| 2557 | pw.print(dalvikFree); pw.print(','); |
| 2558 | pw.print("N/A,"); |
| 2559 | pw.print(nativeFree + dalvikFree); pw.print(','); |
| 2560 | |
| 2561 | // Heap info - proportional set size |
| 2562 | pw.print(memInfo.nativePss); pw.print(','); |
| 2563 | pw.print(memInfo.dalvikPss); pw.print(','); |
| 2564 | pw.print(memInfo.otherPss); pw.print(','); |
| 2565 | pw.print(memInfo.getTotalPss()); pw.print(','); |
| 2566 | |
| 2567 | // Heap info - swappable set size |
| 2568 | pw.print(memInfo.nativeSwappablePss); pw.print(','); |
| 2569 | pw.print(memInfo.dalvikSwappablePss); pw.print(','); |
| 2570 | pw.print(memInfo.otherSwappablePss); pw.print(','); |
| 2571 | pw.print(memInfo.getTotalSwappablePss()); pw.print(','); |
| 2572 | |
| 2573 | // Heap info - shared dirty |
| 2574 | pw.print(memInfo.nativeSharedDirty); pw.print(','); |
| 2575 | pw.print(memInfo.dalvikSharedDirty); pw.print(','); |
| 2576 | pw.print(memInfo.otherSharedDirty); pw.print(','); |
| 2577 | pw.print(memInfo.getTotalSharedDirty()); pw.print(','); |
| 2578 | |
| 2579 | // Heap info - shared clean |
| 2580 | pw.print(memInfo.nativeSharedClean); pw.print(','); |
| 2581 | pw.print(memInfo.dalvikSharedClean); pw.print(','); |
| 2582 | pw.print(memInfo.otherSharedClean); pw.print(','); |
| 2583 | pw.print(memInfo.getTotalSharedClean()); pw.print(','); |
| 2584 | |
| 2585 | // Heap info - private Dirty |
| 2586 | pw.print(memInfo.nativePrivateDirty); pw.print(','); |
| 2587 | pw.print(memInfo.dalvikPrivateDirty); pw.print(','); |
| 2588 | pw.print(memInfo.otherPrivateDirty); pw.print(','); |
| 2589 | pw.print(memInfo.getTotalPrivateDirty()); pw.print(','); |
| 2590 | |
| 2591 | // Heap info - private Clean |
| 2592 | pw.print(memInfo.nativePrivateClean); pw.print(','); |
| 2593 | pw.print(memInfo.dalvikPrivateClean); pw.print(','); |
| 2594 | pw.print(memInfo.otherPrivateClean); pw.print(','); |
| 2595 | pw.print(memInfo.getTotalPrivateClean()); pw.print(','); |
| 2596 | |
Martijn Coenen | 41f94ed | 2015-12-14 15:28:51 +0100 | [diff] [blame] | 2597 | // Heap info - swapped out |
| 2598 | pw.print(memInfo.nativeSwappedOut); pw.print(','); |
| 2599 | pw.print(memInfo.dalvikSwappedOut); pw.print(','); |
| 2600 | pw.print(memInfo.otherSwappedOut); pw.print(','); |
| 2601 | pw.print(memInfo.getTotalSwappedOut()); pw.print(','); |
| 2602 | |
| 2603 | // Heap info - swapped out pss |
| 2604 | if (memInfo.hasSwappedOutPss) { |
| 2605 | pw.print(memInfo.nativeSwappedOutPss); pw.print(','); |
| 2606 | pw.print(memInfo.dalvikSwappedOutPss); pw.print(','); |
| 2607 | pw.print(memInfo.otherSwappedOutPss); pw.print(','); |
| 2608 | pw.print(memInfo.getTotalSwappedOutPss()); pw.print(','); |
| 2609 | } else { |
| 2610 | pw.print("N/A,"); |
| 2611 | pw.print("N/A,"); |
| 2612 | pw.print("N/A,"); |
| 2613 | pw.print("N/A,"); |
| 2614 | } |
| 2615 | |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2616 | // Heap info - other areas |
| 2617 | for (int i=0; i<Debug.MemoryInfo.NUM_OTHER_STATS; i++) { |
| 2618 | pw.print(Debug.MemoryInfo.getOtherLabel(i)); pw.print(','); |
| 2619 | pw.print(memInfo.getOtherPss(i)); pw.print(','); |
| 2620 | pw.print(memInfo.getOtherSwappablePss(i)); pw.print(','); |
| 2621 | pw.print(memInfo.getOtherSharedDirty(i)); pw.print(','); |
| 2622 | pw.print(memInfo.getOtherSharedClean(i)); pw.print(','); |
| 2623 | pw.print(memInfo.getOtherPrivateDirty(i)); pw.print(','); |
| 2624 | pw.print(memInfo.getOtherPrivateClean(i)); pw.print(','); |
Martijn Coenen | 41f94ed | 2015-12-14 15:28:51 +0100 | [diff] [blame] | 2625 | pw.print(memInfo.getOtherSwappedOut(i)); pw.print(','); |
| 2626 | if (memInfo.hasSwappedOutPss) { |
| 2627 | pw.print(memInfo.getOtherSwappedOutPss(i)); pw.print(','); |
| 2628 | } else { |
| 2629 | pw.print("N/A,"); |
| 2630 | } |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2631 | } |
| 2632 | return; |
| 2633 | } |
| 2634 | |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2635 | if (!dumpSummaryOnly) { |
| 2636 | if (dumpFullInfo) { |
| 2637 | printRow(pw, HEAP_FULL_COLUMN, "", "Pss", "Pss", "Shared", "Private", |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2638 | "Shared", "Private", memInfo.hasSwappedOutPss ? "SwapPss" : "Swap", |
Jing Ji | a736da8 | 2019-08-06 15:08:02 -0700 | [diff] [blame] | 2639 | "Rss", "Heap", "Heap", "Heap"); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2640 | printRow(pw, HEAP_FULL_COLUMN, "", "Total", "Clean", "Dirty", "Dirty", |
Jing Ji | a736da8 | 2019-08-06 15:08:02 -0700 | [diff] [blame] | 2641 | "Clean", "Clean", "Dirty", "Total", |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2642 | "Size", "Alloc", "Free"); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2643 | printRow(pw, HEAP_FULL_COLUMN, "", "------", "------", "------", "------", |
Jing Ji | a736da8 | 2019-08-06 15:08:02 -0700 | [diff] [blame] | 2644 | "------", "------", "------", "------", "------", "------", "------"); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2645 | printRow(pw, HEAP_FULL_COLUMN, "Native Heap", memInfo.nativePss, |
| 2646 | memInfo.nativeSwappablePss, memInfo.nativeSharedDirty, |
| 2647 | memInfo.nativePrivateDirty, memInfo.nativeSharedClean, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2648 | memInfo.nativePrivateClean, memInfo.hasSwappedOutPss ? |
Richard Uhler | 91702eb3 | 2017-06-23 16:54:25 +0100 | [diff] [blame] | 2649 | memInfo.nativeSwappedOutPss : memInfo.nativeSwappedOut, |
Jing Ji | a736da8 | 2019-08-06 15:08:02 -0700 | [diff] [blame] | 2650 | memInfo.nativeRss, nativeMax, nativeAllocated, nativeFree); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2651 | printRow(pw, HEAP_FULL_COLUMN, "Dalvik Heap", memInfo.dalvikPss, |
| 2652 | memInfo.dalvikSwappablePss, memInfo.dalvikSharedDirty, |
| 2653 | memInfo.dalvikPrivateDirty, memInfo.dalvikSharedClean, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2654 | memInfo.dalvikPrivateClean, memInfo.hasSwappedOutPss ? |
Richard Uhler | 91702eb3 | 2017-06-23 16:54:25 +0100 | [diff] [blame] | 2655 | memInfo.dalvikSwappedOutPss : memInfo.dalvikSwappedOut, |
Jing Ji | a736da8 | 2019-08-06 15:08:02 -0700 | [diff] [blame] | 2656 | memInfo.dalvikRss, dalvikMax, dalvikAllocated, dalvikFree); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2657 | } else { |
| 2658 | printRow(pw, HEAP_COLUMN, "", "Pss", "Private", |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2659 | "Private", memInfo.hasSwappedOutPss ? "SwapPss" : "Swap", |
Jing Ji | a736da8 | 2019-08-06 15:08:02 -0700 | [diff] [blame] | 2660 | "Rss", "Heap", "Heap", "Heap"); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2661 | printRow(pw, HEAP_COLUMN, "", "Total", "Dirty", |
Jing Ji | a736da8 | 2019-08-06 15:08:02 -0700 | [diff] [blame] | 2662 | "Clean", "Dirty", "Total", "Size", "Alloc", "Free"); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2663 | printRow(pw, HEAP_COLUMN, "", "------", "------", "------", |
Jing Ji | a736da8 | 2019-08-06 15:08:02 -0700 | [diff] [blame] | 2664 | "------", "------", "------", "------", "------", "------"); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2665 | printRow(pw, HEAP_COLUMN, "Native Heap", memInfo.nativePss, |
| 2666 | memInfo.nativePrivateDirty, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2667 | memInfo.nativePrivateClean, |
| 2668 | memInfo.hasSwappedOutPss ? memInfo.nativeSwappedOutPss : |
Jing Ji | a736da8 | 2019-08-06 15:08:02 -0700 | [diff] [blame] | 2669 | memInfo.nativeSwappedOut, memInfo.nativeRss, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2670 | nativeMax, nativeAllocated, nativeFree); |
| 2671 | printRow(pw, HEAP_COLUMN, "Dalvik Heap", memInfo.dalvikPss, |
| 2672 | memInfo.dalvikPrivateDirty, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2673 | memInfo.dalvikPrivateClean, |
| 2674 | memInfo.hasSwappedOutPss ? memInfo.dalvikSwappedOutPss : |
Jing Ji | a736da8 | 2019-08-06 15:08:02 -0700 | [diff] [blame] | 2675 | memInfo.dalvikSwappedOut, memInfo.dalvikRss, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2676 | dalvikMax, dalvikAllocated, dalvikFree); |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2677 | } |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2678 | |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2679 | int otherPss = memInfo.otherPss; |
| 2680 | int otherSwappablePss = memInfo.otherSwappablePss; |
| 2681 | int otherSharedDirty = memInfo.otherSharedDirty; |
| 2682 | int otherPrivateDirty = memInfo.otherPrivateDirty; |
| 2683 | int otherSharedClean = memInfo.otherSharedClean; |
| 2684 | int otherPrivateClean = memInfo.otherPrivateClean; |
| 2685 | int otherSwappedOut = memInfo.otherSwappedOut; |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2686 | int otherSwappedOutPss = memInfo.otherSwappedOutPss; |
Jing Ji | a736da8 | 2019-08-06 15:08:02 -0700 | [diff] [blame] | 2687 | int otherRss = memInfo.otherRss; |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2688 | |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2689 | for (int i=0; i<Debug.MemoryInfo.NUM_OTHER_STATS; i++) { |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2690 | final int myPss = memInfo.getOtherPss(i); |
| 2691 | final int mySwappablePss = memInfo.getOtherSwappablePss(i); |
| 2692 | final int mySharedDirty = memInfo.getOtherSharedDirty(i); |
| 2693 | final int myPrivateDirty = memInfo.getOtherPrivateDirty(i); |
| 2694 | final int mySharedClean = memInfo.getOtherSharedClean(i); |
| 2695 | final int myPrivateClean = memInfo.getOtherPrivateClean(i); |
| 2696 | final int mySwappedOut = memInfo.getOtherSwappedOut(i); |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2697 | final int mySwappedOutPss = memInfo.getOtherSwappedOutPss(i); |
Jing Ji | a736da8 | 2019-08-06 15:08:02 -0700 | [diff] [blame] | 2698 | final int myRss = memInfo.getOtherRss(i); |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2699 | if (myPss != 0 || mySharedDirty != 0 || myPrivateDirty != 0 |
Jing Ji | a736da8 | 2019-08-06 15:08:02 -0700 | [diff] [blame] | 2700 | || mySharedClean != 0 || myPrivateClean != 0 || myRss != 0 |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2701 | || (memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut) != 0) { |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2702 | if (dumpFullInfo) { |
| 2703 | printRow(pw, HEAP_FULL_COLUMN, Debug.MemoryInfo.getOtherLabel(i), |
| 2704 | myPss, mySwappablePss, mySharedDirty, myPrivateDirty, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2705 | mySharedClean, myPrivateClean, |
| 2706 | memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut, |
Jing Ji | a736da8 | 2019-08-06 15:08:02 -0700 | [diff] [blame] | 2707 | myRss, "", "", ""); |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2708 | } else { |
| 2709 | printRow(pw, HEAP_COLUMN, Debug.MemoryInfo.getOtherLabel(i), |
| 2710 | myPss, myPrivateDirty, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2711 | myPrivateClean, |
| 2712 | memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut, |
Jing Ji | a736da8 | 2019-08-06 15:08:02 -0700 | [diff] [blame] | 2713 | myRss, "", "", ""); |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2714 | } |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2715 | otherPss -= myPss; |
| 2716 | otherSwappablePss -= mySwappablePss; |
| 2717 | otherSharedDirty -= mySharedDirty; |
| 2718 | otherPrivateDirty -= myPrivateDirty; |
| 2719 | otherSharedClean -= mySharedClean; |
| 2720 | otherPrivateClean -= myPrivateClean; |
| 2721 | otherSwappedOut -= mySwappedOut; |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2722 | otherSwappedOutPss -= mySwappedOutPss; |
Jing Ji | a736da8 | 2019-08-06 15:08:02 -0700 | [diff] [blame] | 2723 | otherRss -= myRss; |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2724 | } |
| 2725 | } |
| 2726 | |
| 2727 | if (dumpFullInfo) { |
| 2728 | printRow(pw, HEAP_FULL_COLUMN, "Unknown", otherPss, otherSwappablePss, |
| 2729 | otherSharedDirty, otherPrivateDirty, otherSharedClean, otherPrivateClean, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2730 | memInfo.hasSwappedOutPss ? otherSwappedOutPss : otherSwappedOut, |
Jing Ji | a736da8 | 2019-08-06 15:08:02 -0700 | [diff] [blame] | 2731 | otherRss, "", "", ""); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2732 | printRow(pw, HEAP_FULL_COLUMN, "TOTAL", memInfo.getTotalPss(), |
| 2733 | memInfo.getTotalSwappablePss(), |
| 2734 | memInfo.getTotalSharedDirty(), memInfo.getTotalPrivateDirty(), |
| 2735 | memInfo.getTotalSharedClean(), memInfo.getTotalPrivateClean(), |
Thierry Strudel | 9b51160 | 2016-02-25 17:46:38 -0800 | [diff] [blame] | 2736 | memInfo.hasSwappedOutPss ? memInfo.getTotalSwappedOutPss() : |
Jing Ji | a736da8 | 2019-08-06 15:08:02 -0700 | [diff] [blame] | 2737 | memInfo.getTotalSwappedOut(), memInfo.getTotalRss(), |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2738 | nativeMax+dalvikMax, nativeAllocated+dalvikAllocated, |
| 2739 | nativeFree+dalvikFree); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2740 | } else { |
| 2741 | printRow(pw, HEAP_COLUMN, "Unknown", otherPss, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2742 | otherPrivateDirty, otherPrivateClean, |
| 2743 | memInfo.hasSwappedOutPss ? otherSwappedOutPss : otherSwappedOut, |
Jing Ji | a736da8 | 2019-08-06 15:08:02 -0700 | [diff] [blame] | 2744 | otherRss, "", "", ""); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2745 | printRow(pw, HEAP_COLUMN, "TOTAL", memInfo.getTotalPss(), |
| 2746 | memInfo.getTotalPrivateDirty(), |
| 2747 | memInfo.getTotalPrivateClean(), |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2748 | memInfo.hasSwappedOutPss ? memInfo.getTotalSwappedOutPss() : |
Jing Ji | a736da8 | 2019-08-06 15:08:02 -0700 | [diff] [blame] | 2749 | memInfo.getTotalSwappedOut(), memInfo.getTotalPss(), |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2750 | nativeMax+dalvikMax, |
| 2751 | nativeAllocated+dalvikAllocated, nativeFree+dalvikFree); |
| 2752 | } |
| 2753 | |
| 2754 | if (dumpDalvik) { |
| 2755 | pw.println(" "); |
| 2756 | pw.println(" Dalvik Details"); |
| 2757 | |
| 2758 | for (int i=Debug.MemoryInfo.NUM_OTHER_STATS; |
| 2759 | i<Debug.MemoryInfo.NUM_OTHER_STATS + Debug.MemoryInfo.NUM_DVK_STATS; i++) { |
| 2760 | final int myPss = memInfo.getOtherPss(i); |
| 2761 | final int mySwappablePss = memInfo.getOtherSwappablePss(i); |
| 2762 | final int mySharedDirty = memInfo.getOtherSharedDirty(i); |
| 2763 | final int myPrivateDirty = memInfo.getOtherPrivateDirty(i); |
| 2764 | final int mySharedClean = memInfo.getOtherSharedClean(i); |
| 2765 | final int myPrivateClean = memInfo.getOtherPrivateClean(i); |
| 2766 | final int mySwappedOut = memInfo.getOtherSwappedOut(i); |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2767 | final int mySwappedOutPss = memInfo.getOtherSwappedOutPss(i); |
Jing Ji | a736da8 | 2019-08-06 15:08:02 -0700 | [diff] [blame] | 2768 | final int myRss = memInfo.getOtherRss(i); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2769 | if (myPss != 0 || mySharedDirty != 0 || myPrivateDirty != 0 |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2770 | || mySharedClean != 0 || myPrivateClean != 0 |
| 2771 | || (memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut) != 0) { |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2772 | if (dumpFullInfo) { |
| 2773 | printRow(pw, HEAP_FULL_COLUMN, Debug.MemoryInfo.getOtherLabel(i), |
| 2774 | myPss, mySwappablePss, mySharedDirty, myPrivateDirty, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2775 | mySharedClean, myPrivateClean, |
| 2776 | memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut, |
Jing Ji | a736da8 | 2019-08-06 15:08:02 -0700 | [diff] [blame] | 2777 | myRss, "", "", ""); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2778 | } else { |
| 2779 | printRow(pw, HEAP_COLUMN, Debug.MemoryInfo.getOtherLabel(i), |
| 2780 | myPss, myPrivateDirty, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2781 | myPrivateClean, |
| 2782 | memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut, |
Jing Ji | a736da8 | 2019-08-06 15:08:02 -0700 | [diff] [blame] | 2783 | myRss, "", "", ""); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2784 | } |
| 2785 | } |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2786 | } |
| 2787 | } |
| 2788 | } |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2789 | |
| 2790 | pw.println(" "); |
| 2791 | pw.println(" App Summary"); |
Jing Ji | a736da8 | 2019-08-06 15:08:02 -0700 | [diff] [blame] | 2792 | printRow(pw, TWO_COUNT_COLUMN_HEADER, "", "Pss(KB)", "", "Rss(KB)"); |
| 2793 | printRow(pw, TWO_COUNT_COLUMN_HEADER, "", "------", "", "------"); |
| 2794 | printRow(pw, TWO_COUNT_COLUMNS, |
| 2795 | "Java Heap:", memInfo.getSummaryJavaHeap(), "", memInfo.getSummaryJavaHeapRss()); |
| 2796 | printRow(pw, TWO_COUNT_COLUMNS, |
| 2797 | "Native Heap:", memInfo.getSummaryNativeHeap(), "", |
| 2798 | memInfo.getSummaryNativeHeapRss()); |
| 2799 | printRow(pw, TWO_COUNT_COLUMNS, |
| 2800 | "Code:", memInfo.getSummaryCode(), "", memInfo.getSummaryCodeRss()); |
| 2801 | printRow(pw, TWO_COUNT_COLUMNS, |
| 2802 | "Stack:", memInfo.getSummaryStack(), "", memInfo.getSummaryStackRss()); |
| 2803 | printRow(pw, TWO_COUNT_COLUMNS, |
| 2804 | "Graphics:", memInfo.getSummaryGraphics(), "", memInfo.getSummaryGraphicsRss()); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2805 | printRow(pw, ONE_COUNT_COLUMN, |
Jing Ji | a736da8 | 2019-08-06 15:08:02 -0700 | [diff] [blame] | 2806 | "Private Other:", memInfo.getSummaryPrivateOther()); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2807 | printRow(pw, ONE_COUNT_COLUMN, |
Jing Ji | a736da8 | 2019-08-06 15:08:02 -0700 | [diff] [blame] | 2808 | "System:", memInfo.getSummarySystem()); |
| 2809 | printRow(pw, ONE_ALT_COUNT_COLUMN, |
| 2810 | "Unknown:", "", "", memInfo.getSummaryUnknownRss()); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2811 | pw.println(" "); |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2812 | if (memInfo.hasSwappedOutPss) { |
Jing Ji | a736da8 | 2019-08-06 15:08:02 -0700 | [diff] [blame] | 2813 | printRow(pw, THREE_COUNT_COLUMNS, |
| 2814 | "TOTAL PSS:", memInfo.getSummaryTotalPss(), |
| 2815 | "TOTAL RSS:", memInfo.getTotalRss(), |
| 2816 | "TOTAL SWAP PSS:", memInfo.getSummaryTotalSwapPss()); |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2817 | } else { |
Jing Ji | a736da8 | 2019-08-06 15:08:02 -0700 | [diff] [blame] | 2818 | printRow(pw, THREE_COUNT_COLUMNS, |
| 2819 | "TOTAL PSS:", memInfo.getSummaryTotalPss(), |
| 2820 | "TOTAL RSS:", memInfo.getTotalRss(), |
| 2821 | "TOTAL SWAP (KB):", memInfo.getSummaryTotalSwap()); |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2822 | } |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2823 | } |
| 2824 | |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2825 | /** |
| 2826 | * Dump heap info to proto. |
| 2827 | * |
| 2828 | * @param hasSwappedOutPss determines whether to use dirtySwap or dirtySwapPss |
| 2829 | */ |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 2830 | private static void dumpMemoryInfo(ProtoOutputStream proto, long fieldId, String name, |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2831 | int pss, int cleanPss, int sharedDirty, int privateDirty, |
| 2832 | int sharedClean, int privateClean, |
Jing Ji | a736da8 | 2019-08-06 15:08:02 -0700 | [diff] [blame] | 2833 | boolean hasSwappedOutPss, int dirtySwap, int dirtySwapPss, int rss) { |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2834 | final long token = proto.start(fieldId); |
| 2835 | |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 2836 | proto.write(MemInfoDumpProto.ProcessMemory.MemoryInfo.NAME, name); |
| 2837 | proto.write(MemInfoDumpProto.ProcessMemory.MemoryInfo.TOTAL_PSS_KB, pss); |
| 2838 | proto.write(MemInfoDumpProto.ProcessMemory.MemoryInfo.CLEAN_PSS_KB, cleanPss); |
| 2839 | proto.write(MemInfoDumpProto.ProcessMemory.MemoryInfo.SHARED_DIRTY_KB, sharedDirty); |
| 2840 | proto.write(MemInfoDumpProto.ProcessMemory.MemoryInfo.PRIVATE_DIRTY_KB, privateDirty); |
| 2841 | proto.write(MemInfoDumpProto.ProcessMemory.MemoryInfo.SHARED_CLEAN_KB, sharedClean); |
| 2842 | proto.write(MemInfoDumpProto.ProcessMemory.MemoryInfo.PRIVATE_CLEAN_KB, privateClean); |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2843 | if (hasSwappedOutPss) { |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 2844 | proto.write(MemInfoDumpProto.ProcessMemory.MemoryInfo.DIRTY_SWAP_PSS_KB, dirtySwapPss); |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2845 | } else { |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 2846 | proto.write(MemInfoDumpProto.ProcessMemory.MemoryInfo.DIRTY_SWAP_KB, dirtySwap); |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2847 | } |
Jing Ji | a736da8 | 2019-08-06 15:08:02 -0700 | [diff] [blame] | 2848 | proto.write(MemInfoDumpProto.ProcessMemory.MemoryInfo.TOTAL_RSS_KB, rss); |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2849 | |
| 2850 | proto.end(token); |
| 2851 | } |
| 2852 | |
| 2853 | /** |
| 2854 | * Dump mem info data to proto. |
| 2855 | */ |
| 2856 | public static void dumpMemInfoTable(ProtoOutputStream proto, Debug.MemoryInfo memInfo, |
| 2857 | boolean dumpDalvik, boolean dumpSummaryOnly, |
| 2858 | long nativeMax, long nativeAllocated, long nativeFree, |
| 2859 | long dalvikMax, long dalvikAllocated, long dalvikFree) { |
| 2860 | |
| 2861 | if (!dumpSummaryOnly) { |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 2862 | final long nhToken = proto.start(MemInfoDumpProto.ProcessMemory.NATIVE_HEAP); |
| 2863 | dumpMemoryInfo(proto, MemInfoDumpProto.ProcessMemory.HeapInfo.MEM_INFO, "Native Heap", |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2864 | memInfo.nativePss, memInfo.nativeSwappablePss, memInfo.nativeSharedDirty, |
| 2865 | memInfo.nativePrivateDirty, memInfo.nativeSharedClean, |
| 2866 | memInfo.nativePrivateClean, memInfo.hasSwappedOutPss, |
Jing Ji | a736da8 | 2019-08-06 15:08:02 -0700 | [diff] [blame] | 2867 | memInfo.nativeSwappedOut, memInfo.nativeSwappedOutPss, |
| 2868 | memInfo.nativeRss); |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 2869 | proto.write(MemInfoDumpProto.ProcessMemory.HeapInfo.HEAP_SIZE_KB, nativeMax); |
| 2870 | proto.write(MemInfoDumpProto.ProcessMemory.HeapInfo.HEAP_ALLOC_KB, nativeAllocated); |
| 2871 | proto.write(MemInfoDumpProto.ProcessMemory.HeapInfo.HEAP_FREE_KB, nativeFree); |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2872 | proto.end(nhToken); |
| 2873 | |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 2874 | final long dvToken = proto.start(MemInfoDumpProto.ProcessMemory.DALVIK_HEAP); |
| 2875 | dumpMemoryInfo(proto, MemInfoDumpProto.ProcessMemory.HeapInfo.MEM_INFO, "Dalvik Heap", |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2876 | memInfo.dalvikPss, memInfo.dalvikSwappablePss, memInfo.dalvikSharedDirty, |
| 2877 | memInfo.dalvikPrivateDirty, memInfo.dalvikSharedClean, |
| 2878 | memInfo.dalvikPrivateClean, memInfo.hasSwappedOutPss, |
Jing Ji | a736da8 | 2019-08-06 15:08:02 -0700 | [diff] [blame] | 2879 | memInfo.dalvikSwappedOut, memInfo.dalvikSwappedOutPss, |
| 2880 | memInfo.dalvikRss); |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 2881 | proto.write(MemInfoDumpProto.ProcessMemory.HeapInfo.HEAP_SIZE_KB, dalvikMax); |
| 2882 | proto.write(MemInfoDumpProto.ProcessMemory.HeapInfo.HEAP_ALLOC_KB, dalvikAllocated); |
| 2883 | proto.write(MemInfoDumpProto.ProcessMemory.HeapInfo.HEAP_FREE_KB, dalvikFree); |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2884 | proto.end(dvToken); |
| 2885 | |
| 2886 | int otherPss = memInfo.otherPss; |
| 2887 | int otherSwappablePss = memInfo.otherSwappablePss; |
| 2888 | int otherSharedDirty = memInfo.otherSharedDirty; |
| 2889 | int otherPrivateDirty = memInfo.otherPrivateDirty; |
| 2890 | int otherSharedClean = memInfo.otherSharedClean; |
| 2891 | int otherPrivateClean = memInfo.otherPrivateClean; |
| 2892 | int otherSwappedOut = memInfo.otherSwappedOut; |
| 2893 | int otherSwappedOutPss = memInfo.otherSwappedOutPss; |
Jing Ji | a736da8 | 2019-08-06 15:08:02 -0700 | [diff] [blame] | 2894 | int otherRss = memInfo.otherRss; |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2895 | |
| 2896 | for (int i = 0; i < Debug.MemoryInfo.NUM_OTHER_STATS; i++) { |
| 2897 | final int myPss = memInfo.getOtherPss(i); |
| 2898 | final int mySwappablePss = memInfo.getOtherSwappablePss(i); |
| 2899 | final int mySharedDirty = memInfo.getOtherSharedDirty(i); |
| 2900 | final int myPrivateDirty = memInfo.getOtherPrivateDirty(i); |
| 2901 | final int mySharedClean = memInfo.getOtherSharedClean(i); |
| 2902 | final int myPrivateClean = memInfo.getOtherPrivateClean(i); |
| 2903 | final int mySwappedOut = memInfo.getOtherSwappedOut(i); |
| 2904 | final int mySwappedOutPss = memInfo.getOtherSwappedOutPss(i); |
Jing Ji | a736da8 | 2019-08-06 15:08:02 -0700 | [diff] [blame] | 2905 | final int myRss = memInfo.getOtherRss(i); |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2906 | if (myPss != 0 || mySharedDirty != 0 || myPrivateDirty != 0 |
Jing Ji | a736da8 | 2019-08-06 15:08:02 -0700 | [diff] [blame] | 2907 | || mySharedClean != 0 || myPrivateClean != 0 || myRss != 0 |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2908 | || (memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut) != 0) { |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 2909 | dumpMemoryInfo(proto, MemInfoDumpProto.ProcessMemory.OTHER_HEAPS, |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2910 | Debug.MemoryInfo.getOtherLabel(i), |
| 2911 | myPss, mySwappablePss, mySharedDirty, myPrivateDirty, |
| 2912 | mySharedClean, myPrivateClean, |
Jing Ji | a736da8 | 2019-08-06 15:08:02 -0700 | [diff] [blame] | 2913 | memInfo.hasSwappedOutPss, mySwappedOut, mySwappedOutPss, myRss); |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2914 | |
| 2915 | otherPss -= myPss; |
| 2916 | otherSwappablePss -= mySwappablePss; |
| 2917 | otherSharedDirty -= mySharedDirty; |
| 2918 | otherPrivateDirty -= myPrivateDirty; |
| 2919 | otherSharedClean -= mySharedClean; |
| 2920 | otherPrivateClean -= myPrivateClean; |
| 2921 | otherSwappedOut -= mySwappedOut; |
| 2922 | otherSwappedOutPss -= mySwappedOutPss; |
Jing Ji | a736da8 | 2019-08-06 15:08:02 -0700 | [diff] [blame] | 2923 | otherRss -= myRss; |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2924 | } |
| 2925 | } |
| 2926 | |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 2927 | dumpMemoryInfo(proto, MemInfoDumpProto.ProcessMemory.UNKNOWN_HEAP, "Unknown", |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2928 | otherPss, otherSwappablePss, |
| 2929 | otherSharedDirty, otherPrivateDirty, otherSharedClean, otherPrivateClean, |
Jing Ji | a736da8 | 2019-08-06 15:08:02 -0700 | [diff] [blame] | 2930 | memInfo.hasSwappedOutPss, otherSwappedOut, otherSwappedOutPss, otherRss); |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 2931 | final long tToken = proto.start(MemInfoDumpProto.ProcessMemory.TOTAL_HEAP); |
| 2932 | dumpMemoryInfo(proto, MemInfoDumpProto.ProcessMemory.HeapInfo.MEM_INFO, "TOTAL", |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2933 | memInfo.getTotalPss(), memInfo.getTotalSwappablePss(), |
| 2934 | memInfo.getTotalSharedDirty(), memInfo.getTotalPrivateDirty(), |
| 2935 | memInfo.getTotalSharedClean(), memInfo.getTotalPrivateClean(), |
| 2936 | memInfo.hasSwappedOutPss, memInfo.getTotalSwappedOut(), |
Jing Ji | a736da8 | 2019-08-06 15:08:02 -0700 | [diff] [blame] | 2937 | memInfo.getTotalSwappedOutPss(), memInfo.getTotalRss()); |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 2938 | proto.write(MemInfoDumpProto.ProcessMemory.HeapInfo.HEAP_SIZE_KB, |
| 2939 | nativeMax + dalvikMax); |
| 2940 | proto.write(MemInfoDumpProto.ProcessMemory.HeapInfo.HEAP_ALLOC_KB, |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2941 | nativeAllocated + dalvikAllocated); |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 2942 | proto.write(MemInfoDumpProto.ProcessMemory.HeapInfo.HEAP_FREE_KB, |
| 2943 | nativeFree + dalvikFree); |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2944 | proto.end(tToken); |
| 2945 | |
| 2946 | if (dumpDalvik) { |
| 2947 | for (int i = Debug.MemoryInfo.NUM_OTHER_STATS; |
| 2948 | i < Debug.MemoryInfo.NUM_OTHER_STATS + Debug.MemoryInfo.NUM_DVK_STATS; |
| 2949 | i++) { |
| 2950 | final int myPss = memInfo.getOtherPss(i); |
| 2951 | final int mySwappablePss = memInfo.getOtherSwappablePss(i); |
| 2952 | final int mySharedDirty = memInfo.getOtherSharedDirty(i); |
| 2953 | final int myPrivateDirty = memInfo.getOtherPrivateDirty(i); |
| 2954 | final int mySharedClean = memInfo.getOtherSharedClean(i); |
| 2955 | final int myPrivateClean = memInfo.getOtherPrivateClean(i); |
| 2956 | final int mySwappedOut = memInfo.getOtherSwappedOut(i); |
| 2957 | final int mySwappedOutPss = memInfo.getOtherSwappedOutPss(i); |
Jing Ji | a736da8 | 2019-08-06 15:08:02 -0700 | [diff] [blame] | 2958 | final int myRss = memInfo.getOtherRss(i); |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2959 | if (myPss != 0 || mySharedDirty != 0 || myPrivateDirty != 0 |
| 2960 | || mySharedClean != 0 || myPrivateClean != 0 |
| 2961 | || (memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut) != 0) { |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 2962 | dumpMemoryInfo(proto, MemInfoDumpProto.ProcessMemory.DALVIK_DETAILS, |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2963 | Debug.MemoryInfo.getOtherLabel(i), |
| 2964 | myPss, mySwappablePss, mySharedDirty, myPrivateDirty, |
| 2965 | mySharedClean, myPrivateClean, |
Jing Ji | a736da8 | 2019-08-06 15:08:02 -0700 | [diff] [blame] | 2966 | memInfo.hasSwappedOutPss, mySwappedOut, mySwappedOutPss, myRss); |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2967 | } |
| 2968 | } |
| 2969 | } |
| 2970 | } |
| 2971 | |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 2972 | final long asToken = proto.start(MemInfoDumpProto.ProcessMemory.APP_SUMMARY); |
| 2973 | proto.write(MemInfoDumpProto.ProcessMemory.AppSummary.JAVA_HEAP_PSS_KB, |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2974 | memInfo.getSummaryJavaHeap()); |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 2975 | proto.write(MemInfoDumpProto.ProcessMemory.AppSummary.NATIVE_HEAP_PSS_KB, |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2976 | memInfo.getSummaryNativeHeap()); |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 2977 | proto.write(MemInfoDumpProto.ProcessMemory.AppSummary.CODE_PSS_KB, |
| 2978 | memInfo.getSummaryCode()); |
| 2979 | proto.write(MemInfoDumpProto.ProcessMemory.AppSummary.STACK_PSS_KB, |
| 2980 | memInfo.getSummaryStack()); |
| 2981 | proto.write(MemInfoDumpProto.ProcessMemory.AppSummary.GRAPHICS_PSS_KB, |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2982 | memInfo.getSummaryGraphics()); |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 2983 | proto.write(MemInfoDumpProto.ProcessMemory.AppSummary.PRIVATE_OTHER_PSS_KB, |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2984 | memInfo.getSummaryPrivateOther()); |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 2985 | proto.write(MemInfoDumpProto.ProcessMemory.AppSummary.SYSTEM_PSS_KB, |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2986 | memInfo.getSummarySystem()); |
| 2987 | if (memInfo.hasSwappedOutPss) { |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 2988 | proto.write(MemInfoDumpProto.ProcessMemory.AppSummary.TOTAL_SWAP_PSS, |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2989 | memInfo.getSummaryTotalSwapPss()); |
| 2990 | } else { |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 2991 | proto.write(MemInfoDumpProto.ProcessMemory.AppSummary.TOTAL_SWAP_PSS, |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2992 | memInfo.getSummaryTotalSwap()); |
| 2993 | } |
Jing Ji | a736da8 | 2019-08-06 15:08:02 -0700 | [diff] [blame] | 2994 | proto.write(MemInfoDumpProto.ProcessMemory.AppSummary.JAVA_HEAP_RSS_KB, |
| 2995 | memInfo.getSummaryJavaHeapRss()); |
| 2996 | proto.write(MemInfoDumpProto.ProcessMemory.AppSummary.NATIVE_HEAP_RSS_KB, |
| 2997 | memInfo.getSummaryNativeHeapRss()); |
| 2998 | proto.write(MemInfoDumpProto.ProcessMemory.AppSummary.CODE_RSS_KB, |
| 2999 | memInfo.getSummaryCodeRss()); |
| 3000 | proto.write(MemInfoDumpProto.ProcessMemory.AppSummary.STACK_RSS_KB, |
| 3001 | memInfo.getSummaryStackRss()); |
| 3002 | proto.write(MemInfoDumpProto.ProcessMemory.AppSummary.GRAPHICS_RSS_KB, |
| 3003 | memInfo.getSummaryGraphicsRss()); |
| 3004 | proto.write(MemInfoDumpProto.ProcessMemory.AppSummary.UNKNOWN_RSS_KB, |
| 3005 | memInfo.getSummaryUnknownRss()); |
| 3006 | |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 3007 | proto.end(asToken); |
| 3008 | } |
| 3009 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 3010 | @UnsupportedAppUsage |
Jeff Hamilton | 52d3203 | 2011-01-08 15:31:26 -0600 | [diff] [blame] | 3011 | public void registerOnActivityPausedListener(Activity activity, |
| 3012 | OnActivityPausedListener listener) { |
| 3013 | synchronized (mOnPauseListeners) { |
| 3014 | ArrayList<OnActivityPausedListener> list = mOnPauseListeners.get(activity); |
| 3015 | if (list == null) { |
| 3016 | list = new ArrayList<OnActivityPausedListener>(); |
| 3017 | mOnPauseListeners.put(activity, list); |
| 3018 | } |
| 3019 | list.add(listener); |
| 3020 | } |
| 3021 | } |
| 3022 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 3023 | @UnsupportedAppUsage |
Jeff Hamilton | ce3224c | 2011-01-17 11:05:03 -0800 | [diff] [blame] | 3024 | public void unregisterOnActivityPausedListener(Activity activity, |
| 3025 | OnActivityPausedListener listener) { |
| 3026 | synchronized (mOnPauseListeners) { |
| 3027 | ArrayList<OnActivityPausedListener> list = mOnPauseListeners.get(activity); |
| 3028 | if (list != null) { |
| 3029 | list.remove(listener); |
| 3030 | } |
| 3031 | } |
| 3032 | } |
| 3033 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3034 | public final ActivityInfo resolveActivityInfo(Intent intent) { |
| 3035 | ActivityInfo aInfo = intent.resolveActivityInfo( |
| 3036 | mInitialApplication.getPackageManager(), PackageManager.GET_SHARED_LIBRARY_FILES); |
| 3037 | if (aInfo == null) { |
| 3038 | // Throw an exception. |
| 3039 | Instrumentation.checkStartActivityResult( |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 3040 | ActivityManager.START_CLASS_NOT_FOUND, intent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3041 | } |
| 3042 | return aInfo; |
| 3043 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3044 | |
Mathew Inwood | 8c854f8 | 2018-09-14 12:35:36 +0100 | [diff] [blame] | 3045 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3046 | public final Activity startActivityNow(Activity parent, String id, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3047 | Intent intent, ActivityInfo activityInfo, IBinder token, Bundle state, |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 3048 | Activity.NonConfigurationInstances lastNonConfigurationInstances, IBinder assistToken) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3049 | ActivityClientRecord r = new ActivityClientRecord(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3050 | r.token = token; |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 3051 | r.assistToken = assistToken; |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 3052 | r.ident = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3053 | r.intent = intent; |
| 3054 | r.state = state; |
| 3055 | r.parent = parent; |
| 3056 | r.embeddedID = id; |
| 3057 | r.activityInfo = activityInfo; |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 3058 | r.lastNonConfigurationInstances = lastNonConfigurationInstances; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3059 | if (localLOGV) { |
| 3060 | ComponentName compname = intent.getComponent(); |
| 3061 | String name; |
| 3062 | if (compname != null) { |
| 3063 | name = compname.toShortString(); |
| 3064 | } else { |
| 3065 | name = "(Intent " + intent + ").getComponent() returned null"; |
| 3066 | } |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3067 | Slog.v(TAG, "Performing launch: action=" + intent.getAction() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3068 | + ", comp=" + name |
| 3069 | + ", token=" + token); |
| 3070 | } |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 3071 | // TODO(lifecycler): Can't switch to use #handleLaunchActivity() because it will try to |
| 3072 | // call #reportSizeConfigurations(), but the server might not know anything about the |
| 3073 | // activity if it was launched from LocalAcvitivyManager. |
Andrii Kulian | 770c403 | 2018-05-02 18:40:59 -0700 | [diff] [blame] | 3074 | return performLaunchActivity(r, null /* customIntent */); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3075 | } |
| 3076 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 3077 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3078 | public final Activity getActivity(IBinder token) { |
Andrii Kulian | d56ed0c | 2018-06-14 12:22:18 -0700 | [diff] [blame] | 3079 | final ActivityClientRecord activityRecord = mActivities.get(token); |
| 3080 | return activityRecord != null ? activityRecord.activity : null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3081 | } |
| 3082 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 3083 | @Override |
| 3084 | public ActivityClientRecord getActivityClient(IBinder token) { |
| 3085 | return mActivities.get(token); |
| 3086 | } |
| 3087 | |
Riddle Hsu | 50e3400 | 2019-04-12 20:42:05 +0800 | [diff] [blame] | 3088 | @Override |
| 3089 | public void updatePendingConfiguration(Configuration config) { |
| 3090 | synchronized (mResourcesManager) { |
| 3091 | if (mPendingConfiguration == null || mPendingConfiguration.isOtherSeqNewer(config)) { |
| 3092 | mPendingConfiguration = config; |
| 3093 | } |
| 3094 | } |
| 3095 | } |
| 3096 | |
| 3097 | @Override |
| 3098 | public void updateProcessState(int processState, boolean fromIpc) { |
| 3099 | synchronized (mAppThread) { |
| 3100 | if (mLastProcessState == processState) { |
| 3101 | return; |
| 3102 | } |
| 3103 | mLastProcessState = processState; |
| 3104 | // Defer the top state for VM to avoid aggressive JIT compilation affecting activity |
| 3105 | // launch time. |
| 3106 | if (processState == ActivityManager.PROCESS_STATE_TOP |
| 3107 | && mNumLaunchingActivities.get() > 0) { |
| 3108 | mPendingProcessState = processState; |
| 3109 | mH.postDelayed(this::applyPendingProcessState, PENDING_TOP_PROCESS_STATE_TIMEOUT); |
| 3110 | } else { |
| 3111 | mPendingProcessState = PROCESS_STATE_UNKNOWN; |
| 3112 | updateVmProcessState(processState); |
| 3113 | } |
| 3114 | if (localLOGV) { |
| 3115 | Slog.i(TAG, "******************* PROCESS STATE CHANGED TO: " + processState |
| 3116 | + (fromIpc ? " (from ipc" : "")); |
| 3117 | } |
| 3118 | } |
| 3119 | } |
| 3120 | |
| 3121 | /** Update VM state based on ActivityManager.PROCESS_STATE_* constants. */ |
| 3122 | private void updateVmProcessState(int processState) { |
| 3123 | // TODO: Tune this since things like gmail sync are important background but not jank |
| 3124 | // perceptible. |
| 3125 | final int state = processState <= ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND |
| 3126 | ? VM_PROCESS_STATE_JANK_PERCEPTIBLE |
| 3127 | : VM_PROCESS_STATE_JANK_IMPERCEPTIBLE; |
| 3128 | VMRuntime.getRuntime().updateProcessState(state); |
| 3129 | } |
| 3130 | |
| 3131 | private void applyPendingProcessState() { |
| 3132 | synchronized (mAppThread) { |
| 3133 | if (mPendingProcessState == PROCESS_STATE_UNKNOWN) { |
| 3134 | return; |
| 3135 | } |
| 3136 | final int pendingState = mPendingProcessState; |
| 3137 | mPendingProcessState = PROCESS_STATE_UNKNOWN; |
| 3138 | // Only apply the pending state if the last state doesn't change. |
| 3139 | if (pendingState == mLastProcessState) { |
| 3140 | updateVmProcessState(pendingState); |
| 3141 | } |
| 3142 | } |
| 3143 | } |
| 3144 | |
| 3145 | @Override |
| 3146 | public void countLaunchingActivities(int num) { |
| 3147 | mNumLaunchingActivities.getAndAdd(num); |
| 3148 | } |
| 3149 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 3150 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3151 | public final void sendActivityResult( |
| 3152 | IBinder token, String id, int requestCode, |
| 3153 | int resultCode, Intent data) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3154 | if (DEBUG_RESULTS) Slog.v(TAG, "sendActivityResult: id=" + id |
Chris Tate | 8a7dc17 | 2009-03-24 20:11:42 -0700 | [diff] [blame] | 3155 | + " req=" + requestCode + " res=" + resultCode + " data=" + data); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3156 | ArrayList<ResultInfo> list = new ArrayList<ResultInfo>(); |
| 3157 | list.add(new ResultInfo(id, requestCode, resultCode, data)); |
Andrii Kulian | 9c5ea9c | 2017-12-07 09:31:01 -0800 | [diff] [blame] | 3158 | final ClientTransaction clientTransaction = ClientTransaction.obtain(mAppThread, token); |
| 3159 | clientTransaction.addCallback(ActivityResultItem.obtain(list)); |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 3160 | try { |
| 3161 | mAppThread.scheduleTransaction(clientTransaction); |
| 3162 | } catch (RemoteException e) { |
| 3163 | // Local scheduling |
| 3164 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3165 | } |
| 3166 | |
Andrii Kulian | 914aa7d | 2018-03-19 21:51:53 -0700 | [diff] [blame] | 3167 | @Override |
| 3168 | TransactionExecutor getTransactionExecutor() { |
| 3169 | return mTransactionExecutor; |
| 3170 | } |
| 3171 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 3172 | void sendMessage(int what, Object obj) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 3173 | sendMessage(what, obj, 0, 0, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3174 | } |
| 3175 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 3176 | private void sendMessage(int what, Object obj, int arg1) { |
| 3177 | sendMessage(what, obj, arg1, 0, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3178 | } |
| 3179 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 3180 | private void sendMessage(int what, Object obj, int arg1, int arg2) { |
| 3181 | sendMessage(what, obj, arg1, arg2, false); |
| 3182 | } |
| 3183 | |
| 3184 | private void sendMessage(int what, Object obj, int arg1, int arg2, boolean async) { |
Kweku Adams | 4af1b50 | 2019-05-23 16:23:48 -0700 | [diff] [blame] | 3185 | if (DEBUG_MESSAGES) { |
| 3186 | Slog.v(TAG, |
| 3187 | "SCHEDULE " + what + " " + mH.codeToString(what) + ": " + arg1 + " / " + obj); |
| 3188 | } |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 3189 | Message msg = Message.obtain(); |
| 3190 | msg.what = what; |
| 3191 | msg.obj = obj; |
| 3192 | msg.arg1 = arg1; |
| 3193 | msg.arg2 = arg2; |
| 3194 | if (async) { |
| 3195 | msg.setAsynchronous(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3196 | } |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 3197 | mH.sendMessage(msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3198 | } |
| 3199 | |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 3200 | private void sendMessage(int what, Object obj, int arg1, int arg2, int seq) { |
| 3201 | if (DEBUG_MESSAGES) Slog.v( |
| 3202 | TAG, "SCHEDULE " + mH.codeToString(what) + " arg1=" + arg1 + " arg2=" + arg2 + |
| 3203 | "seq= " + seq); |
| 3204 | Message msg = Message.obtain(); |
| 3205 | msg.what = what; |
| 3206 | SomeArgs args = SomeArgs.obtain(); |
| 3207 | args.arg1 = obj; |
| 3208 | args.argi1 = arg1; |
| 3209 | args.argi2 = arg2; |
| 3210 | args.argi3 = seq; |
| 3211 | msg.obj = args; |
| 3212 | mH.sendMessage(msg); |
| 3213 | } |
| 3214 | |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 3215 | final void scheduleContextCleanup(ContextImpl context, String who, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3216 | String what) { |
| 3217 | ContextCleanupInfo cci = new ContextCleanupInfo(); |
| 3218 | cci.context = context; |
| 3219 | cci.who = who; |
| 3220 | cci.what = what; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 3221 | sendMessage(H.CLEAN_UP_CONTEXT, cci); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3222 | } |
| 3223 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 3224 | /** Core implementation of activity launch. */ |
Andrii Kulian | 770c403 | 2018-05-02 18:40:59 -0700 | [diff] [blame] | 3225 | private Activity performLaunchActivity(ActivityClientRecord r, Intent customIntent) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3226 | ActivityInfo aInfo = r.activityInfo; |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3227 | if (r.packageInfo == null) { |
| 3228 | r.packageInfo = getPackageInfo(aInfo.applicationInfo, r.compatInfo, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3229 | Context.CONTEXT_INCLUDE_CODE); |
| 3230 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3231 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3232 | ComponentName component = r.intent.getComponent(); |
| 3233 | if (component == null) { |
| 3234 | component = r.intent.resolveActivity( |
| 3235 | mInitialApplication.getPackageManager()); |
| 3236 | r.intent.setComponent(component); |
| 3237 | } |
| 3238 | |
| 3239 | if (r.activityInfo.targetActivity != null) { |
| 3240 | component = new ComponentName(r.activityInfo.packageName, |
| 3241 | r.activityInfo.targetActivity); |
| 3242 | } |
| 3243 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 3244 | ContextImpl appContext = createBaseContextForActivity(r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3245 | Activity activity = null; |
| 3246 | try { |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 3247 | java.lang.ClassLoader cl = appContext.getClassLoader(); |
Dan Sandler | 07fe63e | 2017-08-15 16:41:11 -0400 | [diff] [blame] | 3248 | activity = mInstrumentation.newActivity( |
| 3249 | cl, component.getClassName(), r.intent); |
Brad Fitzpatrick | 5f8b5c1 | 2011-01-20 15:12:08 -0800 | [diff] [blame] | 3250 | StrictMode.incrementExpectedActivityCount(activity.getClass()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3251 | r.intent.setExtrasClassLoader(cl); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 3252 | r.intent.prepareToEnterProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3253 | if (r.state != null) { |
| 3254 | r.state.setClassLoader(cl); |
| 3255 | } |
| 3256 | } catch (Exception e) { |
| 3257 | if (!mInstrumentation.onException(activity, e)) { |
| 3258 | throw new RuntimeException( |
| 3259 | "Unable to instantiate activity " + component |
| 3260 | + ": " + e.toString(), e); |
| 3261 | } |
| 3262 | } |
| 3263 | |
| 3264 | try { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3265 | Application app = r.packageInfo.makeApplication(false, mInstrumentation); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3266 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3267 | if (localLOGV) Slog.v(TAG, "Performing launch of " + r); |
| 3268 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3269 | TAG, r + ": app=" + app |
| 3270 | + ", appName=" + app.getPackageName() |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3271 | + ", pkg=" + r.packageInfo.getPackageName() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3272 | + ", comp=" + r.intent.getComponent().toShortString() |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3273 | + ", dir=" + r.packageInfo.getAppDir()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3274 | |
| 3275 | if (activity != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3276 | CharSequence title = r.activityInfo.loadLabel(appContext.getPackageManager()); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 3277 | Configuration config = new Configuration(mCompatConfiguration); |
Andrii Kulian | d0ad938 | 2016-04-18 20:54:20 -0700 | [diff] [blame] | 3278 | if (r.overrideConfig != null) { |
| 3279 | config.updateFrom(r.overrideConfig); |
| 3280 | } |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3281 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Launching activity " |
Dianne Hackborn | dc6b635 | 2009-09-30 14:20:09 -0700 | [diff] [blame] | 3282 | + r.activityInfo.name + " with config " + config); |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 3283 | Window window = null; |
| 3284 | if (r.mPendingRemoveWindow != null && r.mPreserveWindow) { |
| 3285 | window = r.mPendingRemoveWindow; |
| 3286 | r.mPendingRemoveWindow = null; |
| 3287 | r.mPendingRemoveWindowManager = null; |
| 3288 | } |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 3289 | appContext.setOuterContext(activity); |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 3290 | activity.attach(appContext, this, getInstrumentation(), r.token, |
| 3291 | r.ident, app, r.intent, r.activityInfo, title, r.parent, |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 3292 | r.embeddedID, r.lastNonConfigurationInstances, config, |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 3293 | r.referrer, r.voiceInteractor, window, r.configCallback, |
| 3294 | r.assistToken); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3295 | |
Andrii Kulian | 770c403 | 2018-05-02 18:40:59 -0700 | [diff] [blame] | 3296 | if (customIntent != null) { |
| 3297 | activity.mIntent = customIntent; |
| 3298 | } |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 3299 | r.lastNonConfigurationInstances = null; |
Sudheer Shanka | 84a4895 | 2017-03-08 18:19:01 -0800 | [diff] [blame] | 3300 | checkAndBlockForNetworkAccess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3301 | activity.mStartedActivity = false; |
| 3302 | int theme = r.activityInfo.getThemeResource(); |
| 3303 | if (theme != 0) { |
| 3304 | activity.setTheme(theme); |
| 3305 | } |
| 3306 | |
| 3307 | activity.mCalled = false; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3308 | if (r.isPersistable()) { |
| 3309 | mInstrumentation.callActivityOnCreate(activity, r.state, r.persistentState); |
| 3310 | } else { |
| 3311 | mInstrumentation.callActivityOnCreate(activity, r.state); |
| 3312 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3313 | if (!activity.mCalled) { |
| 3314 | throw new SuperNotCalledException( |
| 3315 | "Activity " + r.intent.getComponent().toShortString() + |
| 3316 | " did not call through to super.onCreate()"); |
| 3317 | } |
| 3318 | r.activity = activity; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3319 | } |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 3320 | r.setState(ON_CREATE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3321 | |
Garfield Tan | 0443b37 | 2019-01-04 15:00:13 -0800 | [diff] [blame] | 3322 | // updatePendingActivityConfiguration() reads from mActivities to update |
| 3323 | // ActivityClientRecord which runs in a different thread. Protect modifications to |
| 3324 | // mActivities to avoid race. |
| 3325 | synchronized (mResourcesManager) { |
| 3326 | mActivities.put(r.token, r); |
| 3327 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3328 | |
| 3329 | } catch (SuperNotCalledException e) { |
| 3330 | throw e; |
| 3331 | |
| 3332 | } catch (Exception e) { |
| 3333 | if (!mInstrumentation.onException(activity, e)) { |
| 3334 | throw new RuntimeException( |
| 3335 | "Unable to start activity " + component |
| 3336 | + ": " + e.toString(), e); |
| 3337 | } |
| 3338 | } |
| 3339 | |
| 3340 | return activity; |
| 3341 | } |
| 3342 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 3343 | @Override |
Andrii Kulian | b9faa03 | 2019-10-17 23:11:54 -0700 | [diff] [blame] | 3344 | public void handleStartActivity(IBinder token, PendingTransactionActions pendingActions) { |
| 3345 | final ActivityClientRecord r = mActivities.get(token); |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 3346 | final Activity activity = r.activity; |
| 3347 | if (r.activity == null) { |
| 3348 | // TODO(lifecycler): What do we do in this case? |
| 3349 | return; |
| 3350 | } |
| 3351 | if (!r.stopped) { |
| 3352 | throw new IllegalStateException("Can't start activity that is not stopped."); |
| 3353 | } |
Andrii Kulian | 0f3356c | 2019-03-18 21:34:40 +0000 | [diff] [blame] | 3354 | if (r.activity.mFinished) { |
| 3355 | // TODO(lifecycler): How can this happen? |
| 3356 | return; |
| 3357 | } |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 3358 | |
Andrii Kulian | b9faa03 | 2019-10-17 23:11:54 -0700 | [diff] [blame] | 3359 | unscheduleGcIdler(); |
| 3360 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 3361 | // Start |
Andrii Kulian | d25680c | 2018-02-21 15:16:58 -0800 | [diff] [blame] | 3362 | activity.performStart("handleStartActivity"); |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 3363 | r.setState(ON_START); |
| 3364 | |
| 3365 | if (pendingActions == null) { |
| 3366 | // No more work to do. |
| 3367 | return; |
| 3368 | } |
| 3369 | |
| 3370 | // Restore instance state |
| 3371 | if (pendingActions.shouldRestoreInstanceState()) { |
| 3372 | if (r.isPersistable()) { |
| 3373 | if (r.state != null || r.persistentState != null) { |
| 3374 | mInstrumentation.callActivityOnRestoreInstanceState(activity, r.state, |
| 3375 | r.persistentState); |
| 3376 | } |
| 3377 | } else if (r.state != null) { |
| 3378 | mInstrumentation.callActivityOnRestoreInstanceState(activity, r.state); |
| 3379 | } |
| 3380 | } |
| 3381 | |
| 3382 | // Call postOnCreate() |
| 3383 | if (pendingActions.shouldCallOnPostCreate()) { |
| 3384 | activity.mCalled = false; |
| 3385 | if (r.isPersistable()) { |
| 3386 | mInstrumentation.callActivityOnPostCreate(activity, r.state, |
| 3387 | r.persistentState); |
| 3388 | } else { |
| 3389 | mInstrumentation.callActivityOnPostCreate(activity, r.state); |
| 3390 | } |
| 3391 | if (!activity.mCalled) { |
| 3392 | throw new SuperNotCalledException( |
| 3393 | "Activity " + r.intent.getComponent().toShortString() |
| 3394 | + " did not call through to super.onPostCreate()"); |
| 3395 | } |
| 3396 | } |
Andrii Kulian | b9faa03 | 2019-10-17 23:11:54 -0700 | [diff] [blame] | 3397 | |
| 3398 | updateVisibility(r, true /* show */); |
| 3399 | mSomeActivitiesChanged = true; |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 3400 | } |
| 3401 | |
Sudheer Shanka | 84a4895 | 2017-03-08 18:19:01 -0800 | [diff] [blame] | 3402 | /** |
| 3403 | * Checks if {@link #mNetworkBlockSeq} is {@link #INVALID_PROC_STATE_SEQ} and if so, returns |
| 3404 | * immediately. Otherwise, makes a blocking call to ActivityManagerService to wait for the |
| 3405 | * network rules to get updated. |
| 3406 | */ |
| 3407 | private void checkAndBlockForNetworkAccess() { |
| 3408 | synchronized (mNetworkPolicyLock) { |
| 3409 | if (mNetworkBlockSeq != INVALID_PROC_STATE_SEQ) { |
| 3410 | try { |
| 3411 | ActivityManager.getService().waitForNetworkStateUpdate(mNetworkBlockSeq); |
| 3412 | mNetworkBlockSeq = INVALID_PROC_STATE_SEQ; |
| 3413 | } catch (RemoteException ignored) {} |
| 3414 | } |
| 3415 | } |
| 3416 | } |
| 3417 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 3418 | private ContextImpl createBaseContextForActivity(ActivityClientRecord r) { |
| 3419 | final int displayId; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3420 | try { |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 3421 | displayId = ActivityTaskManager.getService().getDisplayId(r.token); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3422 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3423 | throw e.rethrowFromSystemServer(); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3424 | } |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 3425 | |
Wale Ogunwale | 7c72668 | 2015-02-06 17:34:28 -0800 | [diff] [blame] | 3426 | ContextImpl appContext = ContextImpl.createActivityContext( |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3427 | this, r.packageInfo, r.activityInfo, r.token, displayId, r.overrideConfig); |
Wale Ogunwale | 7c72668 | 2015-02-06 17:34:28 -0800 | [diff] [blame] | 3428 | |
| 3429 | final DisplayManagerGlobal dm = DisplayManagerGlobal.getInstance(); |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 3430 | // For debugging purposes, if the activity's package name contains the value of |
| 3431 | // the "debug.use-second-display" system property as a substring, then show |
| 3432 | // its content on a secondary display if there is one. |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 3433 | String pkgName = SystemProperties.get("debug.second-display.pkg"); |
| 3434 | if (pkgName != null && !pkgName.isEmpty() |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3435 | && r.packageInfo.mPackageName.contains(pkgName)) { |
Wale Ogunwale | 7c72668 | 2015-02-06 17:34:28 -0800 | [diff] [blame] | 3436 | for (int id : dm.getDisplayIds()) { |
| 3437 | if (id != Display.DEFAULT_DISPLAY) { |
Wale Ogunwale | 2669851 | 2015-06-05 16:55:33 -0700 | [diff] [blame] | 3438 | Display display = |
Bryce Lee | 609bf65 | 2017-02-09 16:50:13 -0800 | [diff] [blame] | 3439 | dm.getCompatibleDisplay(id, appContext.getResources()); |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 3440 | appContext = (ContextImpl) appContext.createDisplayContext(display); |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 3441 | break; |
| 3442 | } |
| 3443 | } |
| 3444 | } |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 3445 | return appContext; |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 3446 | } |
| 3447 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 3448 | /** |
| 3449 | * Extended implementation of activity launch. Used when server requests a launch or relaunch. |
| 3450 | */ |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 3451 | @Override |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 3452 | public Activity handleLaunchActivity(ActivityClientRecord r, |
Andrii Kulian | 770c403 | 2018-05-02 18:40:59 -0700 | [diff] [blame] | 3453 | PendingTransactionActions pendingActions, Intent customIntent) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3454 | // If we are getting ready to gc after going to the background, well |
| 3455 | // we are back active so skip it. |
| 3456 | unscheduleGcIdler(); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3457 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3458 | |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 3459 | if (r.profilerInfo != null) { |
| 3460 | mProfiler.setProfiler(r.profilerInfo); |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 3461 | mProfiler.startProfiling(); |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 3462 | } |
| 3463 | |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 3464 | // Make sure we are running with the most recent config. |
| 3465 | handleConfigurationChanged(null, null); |
| 3466 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3467 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3468 | TAG, "Handling launch of " + r); |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 3469 | |
Chet Haase | 0d1c27a | 2014-11-03 18:35:16 +0000 | [diff] [blame] | 3470 | // Initialize before creating the activity |
Stan Iliev | 898123b | 2019-02-14 14:57:44 -0500 | [diff] [blame] | 3471 | if (!ThreadedRenderer.sRendererDisabled |
| 3472 | && (r.activityInfo.flags & ActivityInfo.FLAG_HARDWARE_ACCELERATED) != 0) { |
| 3473 | HardwareRenderer.preload(); |
Jesse Hall | c37984f | 2017-05-23 16:55:08 -0700 | [diff] [blame] | 3474 | } |
Chet Haase | 0d1c27a | 2014-11-03 18:35:16 +0000 | [diff] [blame] | 3475 | WindowManagerGlobal.initialize(); |
| 3476 | |
Yiwei Zhang | e54faf5 | 2019-05-08 18:43:11 -0700 | [diff] [blame] | 3477 | // Hint the GraphicsEnvironment that an activity is launching on the process. |
| 3478 | GraphicsEnvironment.hintActivityLaunch(); |
| 3479 | |
Andrii Kulian | 770c403 | 2018-05-02 18:40:59 -0700 | [diff] [blame] | 3480 | final Activity a = performLaunchActivity(r, customIntent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3481 | |
| 3482 | if (a != null) { |
Dianne Hackborn | 871ecdc | 2009-12-11 15:24:33 -0800 | [diff] [blame] | 3483 | r.createdConfig = new Configuration(mConfiguration); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 3484 | reportSizeConfigurations(r); |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 3485 | if (!r.activity.mFinished && pendingActions != null) { |
| 3486 | pendingActions.setOldState(r.state); |
| 3487 | pendingActions.setRestoreInstanceState(true); |
| 3488 | pendingActions.setCallOnPostCreate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3489 | } |
| 3490 | } else { |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 3491 | // 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] | 3492 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3493 | ActivityTaskManager.getService() |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 3494 | .finishActivity(r.token, Activity.RESULT_CANCELED, null, |
| 3495 | Activity.DONT_FINISH_TASK_WITH_ACTIVITY); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3496 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3497 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3498 | } |
| 3499 | } |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 3500 | |
| 3501 | return a; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3502 | } |
| 3503 | |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 3504 | private void reportSizeConfigurations(ActivityClientRecord r) { |
Riddle Hsu | 66b74a8 | 2018-07-26 00:20:12 +0800 | [diff] [blame] | 3505 | if (mActivitiesToBeDestroyed.containsKey(r.token)) { |
| 3506 | // Size configurations of a destroyed activity is meaningless. |
| 3507 | return; |
| 3508 | } |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 3509 | Configuration[] configurations = r.activity.getResources().getSizeConfigurations(); |
| 3510 | if (configurations == null) { |
| 3511 | return; |
| 3512 | } |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 3513 | SparseIntArray horizontal = new SparseIntArray(); |
| 3514 | SparseIntArray vertical = new SparseIntArray(); |
| 3515 | SparseIntArray smallest = new SparseIntArray(); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 3516 | for (int i = configurations.length - 1; i >= 0; i--) { |
| 3517 | Configuration config = configurations[i]; |
| 3518 | if (config.screenHeightDp != Configuration.SCREEN_HEIGHT_DP_UNDEFINED) { |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 3519 | vertical.put(config.screenHeightDp, 0); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 3520 | } |
| 3521 | if (config.screenWidthDp != Configuration.SCREEN_WIDTH_DP_UNDEFINED) { |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 3522 | horizontal.put(config.screenWidthDp, 0); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 3523 | } |
| 3524 | if (config.smallestScreenWidthDp != Configuration.SMALLEST_SCREEN_WIDTH_DP_UNDEFINED) { |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 3525 | smallest.put(config.smallestScreenWidthDp, 0); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 3526 | } |
| 3527 | } |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 3528 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3529 | ActivityTaskManager.getService().reportSizeConfigurations(r.token, |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 3530 | horizontal.copyKeys(), vertical.copyKeys(), smallest.copyKeys()); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 3531 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3532 | throw ex.rethrowFromSystemServer(); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 3533 | } |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 3534 | } |
| 3535 | |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 3536 | private void deliverNewIntents(ActivityClientRecord r, List<ReferrerIntent> intents) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3537 | final int N = intents.size(); |
| 3538 | for (int i=0; i<N; i++) { |
Dianne Hackborn | a01a0fa | 2014-12-02 10:33:14 -0800 | [diff] [blame] | 3539 | ReferrerIntent intent = intents.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3540 | intent.setExtrasClassLoader(r.activity.getClassLoader()); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 3541 | intent.prepareToEnterProcess(); |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 3542 | r.activity.mFragments.noteStateNotSaved(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3543 | mInstrumentation.callActivityOnNewIntent(r.activity, intent); |
| 3544 | } |
| 3545 | } |
| 3546 | |
Louis Chang | 92d1652 | 2019-02-27 12:56:18 +0800 | [diff] [blame] | 3547 | @Override |
| 3548 | public void handleNewIntent(IBinder token, List<ReferrerIntent> intents) { |
Wale Ogunwale | 826c706 | 2016-09-13 08:25:54 -0700 | [diff] [blame] | 3549 | final ActivityClientRecord r = mActivities.get(token); |
| 3550 | if (r == null) { |
| 3551 | return; |
| 3552 | } |
| 3553 | |
Sudheer Shanka | 43b5ea4 | 2017-06-21 11:24:53 -0700 | [diff] [blame] | 3554 | checkAndBlockForNetworkAccess(); |
Wale Ogunwale | 826c706 | 2016-09-13 08:25:54 -0700 | [diff] [blame] | 3555 | deliverNewIntents(r, intents); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3556 | } |
| 3557 | |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 3558 | public void handleRequestAssistContextExtras(RequestAssistContextExtras cmd) { |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 3559 | // Filling for autofill has a few differences: |
Felipe Leme | 1ca634a | 2016-11-28 17:21:21 -0800 | [diff] [blame] | 3560 | // - it does not need an AssistContent |
| 3561 | // - it does not call onProvideAssistData() |
| 3562 | // - it needs an IAutoFillCallback |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 3563 | boolean forAutofill = cmd.requestType == ActivityManager.ASSIST_CONTEXT_AUTOFILL; |
Felipe Leme | 1ca634a | 2016-11-28 17:21:21 -0800 | [diff] [blame] | 3564 | |
Felipe Leme | 85d1c2d | 2017-04-21 08:56:04 -0700 | [diff] [blame] | 3565 | // TODO: decide if lastSessionId logic applies to autofill sessions |
Amith Yamasani | 4f128e4 | 2016-05-10 11:44:12 -0700 | [diff] [blame] | 3566 | if (mLastSessionId != cmd.sessionId) { |
| 3567 | // Clear the existing structures |
| 3568 | mLastSessionId = cmd.sessionId; |
| 3569 | for (int i = mLastAssistStructures.size() - 1; i >= 0; i--) { |
| 3570 | AssistStructure structure = mLastAssistStructures.get(i).get(); |
| 3571 | if (structure != null) { |
| 3572 | structure.clearSendChannel(); |
| 3573 | } |
| 3574 | mLastAssistStructures.remove(i); |
Dianne Hackborn | 782d498 | 2015-07-08 17:36:37 -0700 | [diff] [blame] | 3575 | } |
| 3576 | } |
Felipe Leme | 29a5b0d | 2016-10-25 14:57:11 -0700 | [diff] [blame] | 3577 | |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 3578 | Bundle data = new Bundle(); |
Dianne Hackborn | 09d57fe | 2015-05-27 18:05:52 -0700 | [diff] [blame] | 3579 | AssistStructure structure = null; |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 3580 | AssistContent content = forAutofill ? null : new AssistContent(); |
Amith Yamasani | 858f98d | 2017-02-22 12:59:53 -0800 | [diff] [blame] | 3581 | final long startTime = SystemClock.uptimeMillis(); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 3582 | ActivityClientRecord r = mActivities.get(cmd.activityToken); |
Dianne Hackborn | a3acdb3 | 2015-06-08 17:07:40 -0700 | [diff] [blame] | 3583 | Uri referrer = null; |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 3584 | if (r != null) { |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 3585 | if (!forAutofill) { |
Felipe Leme | 1ca634a | 2016-11-28 17:21:21 -0800 | [diff] [blame] | 3586 | r.activity.getApplication().dispatchOnProvideAssistData(r.activity, data); |
Felipe Leme | 29a5b0d | 2016-10-25 14:57:11 -0700 | [diff] [blame] | 3587 | r.activity.onProvideAssistData(data); |
Felipe Leme | 6d55387 | 2016-12-08 17:13:25 -0800 | [diff] [blame] | 3588 | referrer = r.activity.onProvideReferrer(); |
Felipe Leme | 29a5b0d | 2016-10-25 14:57:11 -0700 | [diff] [blame] | 3589 | } |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 3590 | if (cmd.requestType == ActivityManager.ASSIST_CONTEXT_FULL || forAutofill) { |
Svet Ganov | fd31f85 | 2017-04-26 15:54:27 -0700 | [diff] [blame] | 3591 | structure = new AssistStructure(r.activity, forAutofill, cmd.flags); |
Adam Skory | 4aaed14 | 2015-04-22 11:29:31 -0600 | [diff] [blame] | 3592 | Intent activityIntent = r.activity.getIntent(); |
Felipe Leme | 6d55387 | 2016-12-08 17:13:25 -0800 | [diff] [blame] | 3593 | boolean notSecure = r.window == null || |
Dianne Hackborn | 09d57fe | 2015-05-27 18:05:52 -0700 | [diff] [blame] | 3594 | (r.window.getAttributes().flags |
Felipe Leme | 6d55387 | 2016-12-08 17:13:25 -0800 | [diff] [blame] | 3595 | & WindowManager.LayoutParams.FLAG_SECURE) == 0; |
| 3596 | if (activityIntent != null && notSecure) { |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 3597 | if (!forAutofill) { |
Felipe Leme | 1ca634a | 2016-11-28 17:21:21 -0800 | [diff] [blame] | 3598 | Intent intent = new Intent(activityIntent); |
| 3599 | intent.setFlags(intent.getFlags() & ~(Intent.FLAG_GRANT_WRITE_URI_PERMISSION |
| 3600 | | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION)); |
| 3601 | intent.removeUnsafeExtras(); |
Felipe Leme | 29a5b0d | 2016-10-25 14:57:11 -0700 | [diff] [blame] | 3602 | content.setDefaultIntent(intent); |
| 3603 | } |
Adam Skory | 4aaed14 | 2015-04-22 11:29:31 -0600 | [diff] [blame] | 3604 | } else { |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 3605 | if (!forAutofill) { |
Felipe Leme | 29a5b0d | 2016-10-25 14:57:11 -0700 | [diff] [blame] | 3606 | content.setDefaultIntent(new Intent()); |
| 3607 | } |
Adam Skory | 4aaed14 | 2015-04-22 11:29:31 -0600 | [diff] [blame] | 3608 | } |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 3609 | if (!forAutofill) { |
Felipe Leme | 29a5b0d | 2016-10-25 14:57:11 -0700 | [diff] [blame] | 3610 | r.activity.onProvideAssistContent(content); |
| 3611 | } |
Dianne Hackborn | a83ce1d | 2015-03-11 15:16:13 -0700 | [diff] [blame] | 3612 | } |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 3613 | |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 3614 | } |
Dianne Hackborn | 09d57fe | 2015-05-27 18:05:52 -0700 | [diff] [blame] | 3615 | if (structure == null) { |
| 3616 | structure = new AssistStructure(); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 3617 | } |
Felipe Leme | 0200d9e | 2017-01-24 15:10:26 -0800 | [diff] [blame] | 3618 | |
Felipe Leme | 85d1c2d | 2017-04-21 08:56:04 -0700 | [diff] [blame] | 3619 | // TODO: decide if lastSessionId logic applies to autofill sessions |
Amith Yamasani | 858f98d | 2017-02-22 12:59:53 -0800 | [diff] [blame] | 3620 | |
| 3621 | structure.setAcquisitionStartTime(startTime); |
| 3622 | structure.setAcquisitionEndTime(SystemClock.uptimeMillis()); |
| 3623 | |
Amith Yamasani | 4f128e4 | 2016-05-10 11:44:12 -0700 | [diff] [blame] | 3624 | mLastAssistStructures.add(new WeakReference<>(structure)); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3625 | IActivityTaskManager mgr = ActivityTaskManager.getService(); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 3626 | try { |
Dianne Hackborn | a3acdb3 | 2015-06-08 17:07:40 -0700 | [diff] [blame] | 3627 | mgr.reportAssistContextExtras(cmd.requestToken, data, structure, content, referrer); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 3628 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3629 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 3630 | } |
| 3631 | } |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 3632 | |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 3633 | /** Fetches the user actions for the corresponding activity */ |
| 3634 | private void handleRequestDirectActions(@NonNull IBinder activityToken, |
Svet Ganov | 3b6be08 | 2019-04-28 10:21:01 -0700 | [diff] [blame] | 3635 | @NonNull IVoiceInteractor interactor, @NonNull CancellationSignal cancellationSignal, |
| 3636 | @NonNull RemoteCallback callback) { |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 3637 | final ActivityClientRecord r = mActivities.get(activityToken); |
Svet Ganov | 3b6be08 | 2019-04-28 10:21:01 -0700 | [diff] [blame] | 3638 | if (r == null) { |
Felipe Leme | ada5184 | 2019-05-14 15:19:52 -0700 | [diff] [blame] | 3639 | Log.w(TAG, "requestDirectActions(): no activity for " + activityToken); |
Svet Ganov | 3b6be08 | 2019-04-28 10:21:01 -0700 | [diff] [blame] | 3640 | callback.sendResult(null); |
| 3641 | return; |
| 3642 | } |
| 3643 | final int lifecycleState = r.getLifecycleState(); |
| 3644 | if (lifecycleState < ON_START || lifecycleState >= ON_STOP) { |
Felipe Leme | ada5184 | 2019-05-14 15:19:52 -0700 | [diff] [blame] | 3645 | Log.w(TAG, "requestDirectActions(" + r + "): wrong lifecycle: " + lifecycleState); |
Svet Ganov | 3b6be08 | 2019-04-28 10:21:01 -0700 | [diff] [blame] | 3646 | callback.sendResult(null); |
| 3647 | return; |
| 3648 | } |
| 3649 | if (r.activity.mVoiceInteractor == null |
| 3650 | || r.activity.mVoiceInteractor.mInteractor.asBinder() |
| 3651 | != interactor.asBinder()) { |
| 3652 | if (r.activity.mVoiceInteractor != null) { |
| 3653 | r.activity.mVoiceInteractor.destroy(); |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 3654 | } |
Svet Ganov | 3b6be08 | 2019-04-28 10:21:01 -0700 | [diff] [blame] | 3655 | r.activity.mVoiceInteractor = new VoiceInteractor(interactor, r.activity, |
| 3656 | r.activity, Looper.myLooper()); |
| 3657 | } |
| 3658 | r.activity.onGetDirectActions(cancellationSignal, (actions) -> { |
Daulet Zhanguzin | 0af97d6 | 2019-12-30 15:41:28 +0000 | [diff] [blame] | 3659 | Objects.requireNonNull(actions); |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 3660 | Preconditions.checkCollectionElementsNotNull(actions, "actions"); |
Svet Ganov | 3b6be08 | 2019-04-28 10:21:01 -0700 | [diff] [blame] | 3661 | if (!actions.isEmpty()) { |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 3662 | final int actionCount = actions.size(); |
| 3663 | for (int i = 0; i < actionCount; i++) { |
| 3664 | final DirectAction action = actions.get(i); |
| 3665 | action.setSource(r.activity.getTaskId(), r.activity.getAssistToken()); |
| 3666 | } |
| 3667 | final Bundle result = new Bundle(); |
| 3668 | result.putParcelable(DirectAction.KEY_ACTIONS_LIST, |
| 3669 | new ParceledListSlice<>(actions)); |
| 3670 | callback.sendResult(result); |
Svet Ganov | 3b6be08 | 2019-04-28 10:21:01 -0700 | [diff] [blame] | 3671 | } else { |
| 3672 | callback.sendResult(null); |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 3673 | } |
Svet Ganov | 3b6be08 | 2019-04-28 10:21:01 -0700 | [diff] [blame] | 3674 | }); |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 3675 | } |
| 3676 | |
| 3677 | /** Performs an actions in the corresponding activity */ |
| 3678 | private void handlePerformDirectAction(@NonNull IBinder activityToken, |
| 3679 | @NonNull String actionId, @Nullable Bundle arguments, |
| 3680 | @NonNull CancellationSignal cancellationSignal, |
| 3681 | @NonNull RemoteCallback resultCallback) { |
| 3682 | final ActivityClientRecord r = mActivities.get(activityToken); |
| 3683 | if (r != null) { |
| 3684 | final int lifecycleState = r.getLifecycleState(); |
| 3685 | if (lifecycleState < ON_START || lifecycleState >= ON_STOP) { |
| 3686 | resultCallback.sendResult(null); |
| 3687 | return; |
| 3688 | } |
| 3689 | final Bundle nonNullArguments = (arguments != null) ? arguments : Bundle.EMPTY; |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 3690 | r.activity.onPerformDirectAction(actionId, nonNullArguments, cancellationSignal, |
Svet Ganov | 3b6be08 | 2019-04-28 10:21:01 -0700 | [diff] [blame] | 3691 | resultCallback::sendResult); |
| 3692 | } else { |
| 3693 | resultCallback.sendResult(null); |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 3694 | } |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 3695 | } |
| 3696 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 3697 | public void handleTranslucentConversionComplete(IBinder token, boolean drawComplete) { |
| 3698 | ActivityClientRecord r = mActivities.get(token); |
| 3699 | if (r != null) { |
| 3700 | r.activity.onTranslucentConversionComplete(drawComplete); |
| 3701 | } |
| 3702 | } |
| 3703 | |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 3704 | public void onNewActivityOptions(IBinder token, ActivityOptions options) { |
| 3705 | ActivityClientRecord r = mActivities.get(token); |
| 3706 | if (r != null) { |
| 3707 | r.activity.onNewActivityOptions(options); |
| 3708 | } |
| 3709 | } |
| 3710 | |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 3711 | public void handleInstallProvider(ProviderInfo info) { |
Jeff Sharkey | bb2e2ca | 2014-10-23 11:42:31 -0700 | [diff] [blame] | 3712 | final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); |
| 3713 | try { |
Jeff Sharkey | a6bfeae | 2017-07-05 16:50:24 -0600 | [diff] [blame] | 3714 | installContentProviders(mInitialApplication, Arrays.asList(info)); |
Jeff Sharkey | bb2e2ca | 2014-10-23 11:42:31 -0700 | [diff] [blame] | 3715 | } finally { |
| 3716 | StrictMode.setThreadPolicy(oldPolicy); |
| 3717 | } |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 3718 | } |
| 3719 | |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 3720 | private void handleEnterAnimationComplete(IBinder token) { |
| 3721 | ActivityClientRecord r = mActivities.get(token); |
| 3722 | if (r != null) { |
Filip Gruszczynski | 6eafa90 | 2014-11-14 14:24:37 -0800 | [diff] [blame] | 3723 | r.activity.dispatchEnterAnimationComplete(); |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 3724 | } |
| 3725 | } |
| 3726 | |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 3727 | private void handleStartBinderTracking() { |
| 3728 | Binder.enableTracing(); |
| 3729 | } |
| 3730 | |
| 3731 | private void handleStopBinderTrackingAndDump(ParcelFileDescriptor fd) { |
| 3732 | try { |
| 3733 | Binder.disableTracing(); |
| 3734 | Binder.getTransactionTracker().writeTracesToFile(fd); |
| 3735 | } finally { |
| 3736 | IoUtils.closeQuietly(fd); |
| 3737 | Binder.getTransactionTracker().clearTraces(); |
| 3738 | } |
| 3739 | } |
| 3740 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 3741 | @Override |
| 3742 | public void handleMultiWindowModeChanged(IBinder token, boolean isInMultiWindowMode, |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 3743 | Configuration overrideConfig) { |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 3744 | final ActivityClientRecord r = mActivities.get(token); |
| 3745 | if (r != null) { |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 3746 | final Configuration newConfig = new Configuration(mConfiguration); |
| 3747 | if (overrideConfig != null) { |
| 3748 | newConfig.updateFrom(overrideConfig); |
| 3749 | } |
| 3750 | r.activity.dispatchMultiWindowModeChanged(isInMultiWindowMode, newConfig); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 3751 | } |
| 3752 | } |
| 3753 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 3754 | @Override |
| 3755 | public void handlePictureInPictureModeChanged(IBinder token, boolean isInPipMode, |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 3756 | Configuration overrideConfig) { |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 3757 | final ActivityClientRecord r = mActivities.get(token); |
| 3758 | if (r != null) { |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 3759 | final Configuration newConfig = new Configuration(mConfiguration); |
| 3760 | if (overrideConfig != null) { |
| 3761 | newConfig.updateFrom(overrideConfig); |
| 3762 | } |
| 3763 | r.activity.dispatchPictureInPictureModeChanged(isInPipMode, newConfig); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 3764 | } |
| 3765 | } |
| 3766 | |
jorgegil@google.com | 06bc323 | 2019-10-31 14:51:22 -0700 | [diff] [blame] | 3767 | @Override |
| 3768 | public void handlePictureInPictureRequested(IBinder token) { |
| 3769 | final ActivityClientRecord r = mActivities.get(token); |
| 3770 | if (r == null) { |
| 3771 | Log.w(TAG, "Activity to request PIP to no longer exists"); |
| 3772 | return; |
| 3773 | } |
| 3774 | |
| 3775 | r.activity.onPictureInPictureRequested(); |
| 3776 | } |
| 3777 | |
| 3778 | /** |
| 3779 | * Cycle activity through onPause and onUserLeaveHint so that PIP is entered if supported, then |
| 3780 | * return to its previous state. This allows activities that rely on onUserLeaveHint instead of |
| 3781 | * onPictureInPictureRequested to enter picture-in-picture. |
| 3782 | */ |
| 3783 | public void schedulePauseAndReturnToCurrentState(IBinder token) { |
| 3784 | final ActivityClientRecord r = mActivities.get(token); |
| 3785 | if (r == null) { |
| 3786 | Log.w(TAG, "Activity to request pause with user leaving hint to no longer exists"); |
| 3787 | return; |
| 3788 | } |
| 3789 | |
| 3790 | if (r.mIsUserLeaving) { |
| 3791 | // The activity is about to perform user leaving, so there's no need to cycle ourselves. |
| 3792 | return; |
| 3793 | } |
| 3794 | |
| 3795 | final int prevState = r.getLifecycleState(); |
| 3796 | if (prevState != ON_RESUME && prevState != ON_PAUSE) { |
| 3797 | return; |
| 3798 | } |
| 3799 | |
| 3800 | switch (prevState) { |
| 3801 | case ON_RESUME: |
| 3802 | // Schedule a PAUSE then return to RESUME. |
| 3803 | schedulePauseWithUserLeavingHint(r); |
| 3804 | scheduleResume(r); |
| 3805 | break; |
| 3806 | case ON_PAUSE: |
| 3807 | // Schedule a RESUME then return to PAUSE. |
| 3808 | scheduleResume(r); |
| 3809 | schedulePauseWithUserLeavingHint(r); |
| 3810 | break; |
| 3811 | } |
| 3812 | } |
| 3813 | |
| 3814 | private void schedulePauseWithUserLeavingHint(ActivityClientRecord r) { |
| 3815 | final ClientTransaction transaction = ClientTransaction.obtain(this.mAppThread, r.token); |
| 3816 | transaction.setLifecycleStateRequest(PauseActivityItem.obtain(r.activity.isFinishing(), |
| 3817 | /* userLeaving */ true, r.activity.mConfigChangeFlags, /* dontReport */ false)); |
| 3818 | executeTransaction(transaction); |
| 3819 | } |
| 3820 | |
| 3821 | private void scheduleResume(ActivityClientRecord r) { |
| 3822 | final ClientTransaction transaction = ClientTransaction.obtain(this.mAppThread, r.token); |
| 3823 | transaction.setLifecycleStateRequest(ResumeActivityItem.obtain(/* isForward */ false)); |
| 3824 | executeTransaction(transaction); |
| 3825 | } |
| 3826 | |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 3827 | private void handleLocalVoiceInteractionStarted(IBinder token, IVoiceInteractor interactor) { |
| 3828 | final ActivityClientRecord r = mActivities.get(token); |
| 3829 | if (r != null) { |
| 3830 | r.voiceInteractor = interactor; |
| 3831 | r.activity.setVoiceInteractor(interactor); |
| 3832 | if (interactor == null) { |
| 3833 | r.activity.onLocalVoiceInteractionStopped(); |
| 3834 | } else { |
| 3835 | r.activity.onLocalVoiceInteractionStarted(); |
| 3836 | } |
| 3837 | } |
| 3838 | } |
| 3839 | |
Andreas Gampe | ab8a63b | 2018-01-05 13:55:15 -0800 | [diff] [blame] | 3840 | private static boolean attemptAttachAgent(String agent, ClassLoader classLoader) { |
Leonard Mosescu | f3409ce | 2016-10-06 17:32:05 -0700 | [diff] [blame] | 3841 | try { |
Andreas Gampe | ab8a63b | 2018-01-05 13:55:15 -0800 | [diff] [blame] | 3842 | VMDebug.attachAgent(agent, classLoader); |
| 3843 | return true; |
Leonard Mosescu | f3409ce | 2016-10-06 17:32:05 -0700 | [diff] [blame] | 3844 | } catch (IOException e) { |
Andreas Gampe | ab8a63b | 2018-01-05 13:55:15 -0800 | [diff] [blame] | 3845 | Slog.e(TAG, "Attaching agent with " + classLoader + " failed: " + agent); |
| 3846 | return false; |
| 3847 | } |
| 3848 | } |
| 3849 | |
| 3850 | static void handleAttachAgent(String agent, LoadedApk loadedApk) { |
| 3851 | ClassLoader classLoader = loadedApk != null ? loadedApk.getClassLoader() : null; |
| 3852 | if (attemptAttachAgent(agent, classLoader)) { |
| 3853 | return; |
| 3854 | } |
| 3855 | if (classLoader != null) { |
| 3856 | attemptAttachAgent(agent, null); |
Leonard Mosescu | f3409ce | 2016-10-06 17:32:05 -0700 | [diff] [blame] | 3857 | } |
| 3858 | } |
| 3859 | |
Alex Light | 2d0691c | 2019-10-03 14:36:57 -0700 | [diff] [blame] | 3860 | static void handleAttachStartupAgents(String dataDir) { |
| 3861 | try { |
| 3862 | Path code_cache = ContextImpl.getCodeCacheDirBeforeBind(new File(dataDir)).toPath(); |
| 3863 | if (!Files.exists(code_cache)) { |
| 3864 | return; |
| 3865 | } |
| 3866 | Path startup_path = code_cache.resolve("startup_agents"); |
| 3867 | if (Files.exists(startup_path)) { |
| 3868 | for (Path p : Files.newDirectoryStream(startup_path)) { |
| 3869 | handleAttachAgent( |
| 3870 | p.toAbsolutePath().toString() |
| 3871 | + "=" |
| 3872 | + dataDir, |
| 3873 | null); |
| 3874 | } |
| 3875 | } |
| 3876 | } catch (Exception e) { |
| 3877 | // Ignored. |
| 3878 | } |
| 3879 | } |
| 3880 | |
Brad Fitzpatrick | bfb1919 | 2010-10-29 15:25:44 -0700 | [diff] [blame] | 3881 | private static final ThreadLocal<Intent> sCurrentBroadcastIntent = new ThreadLocal<Intent>(); |
| 3882 | |
| 3883 | /** |
| 3884 | * Return the Intent that's currently being handled by a |
| 3885 | * BroadcastReceiver on this thread, or null if none. |
| 3886 | * @hide |
| 3887 | */ |
| 3888 | public static Intent getIntentBeingBroadcast() { |
| 3889 | return sCurrentBroadcastIntent.get(); |
| 3890 | } |
| 3891 | |
Mathew Inwood | 31755f9 | 2018-12-20 13:53:36 +0000 | [diff] [blame] | 3892 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3893 | private void handleReceiver(ReceiverData data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3894 | // If we are getting ready to gc after going to the background, well |
| 3895 | // we are back active so skip it. |
| 3896 | unscheduleGcIdler(); |
| 3897 | |
| 3898 | String component = data.intent.getComponent().getClassName(); |
| 3899 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3900 | LoadedApk packageInfo = getPackageInfoNoCheck( |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 3901 | data.info.applicationInfo, data.compatInfo); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3902 | |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3903 | IActivityManager mgr = ActivityManager.getService(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3904 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 3905 | Application app; |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3906 | BroadcastReceiver receiver; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 3907 | ContextImpl context; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3908 | try { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3909 | app = packageInfo.makeApplication(false, mInstrumentation); |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 3910 | context = (ContextImpl) app.getBaseContext(); |
| 3911 | if (data.info.splitName != null) { |
| 3912 | context = (ContextImpl) context.createContextForSplit(data.info.splitName); |
| 3913 | } |
| 3914 | java.lang.ClassLoader cl = context.getClassLoader(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3915 | data.intent.setExtrasClassLoader(cl); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 3916 | data.intent.prepareToEnterProcess(); |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 3917 | data.setExtrasClassLoader(cl); |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3918 | receiver = packageInfo.getAppFactory() |
Jason Monk | a80bfb5 | 2017-11-16 17:15:37 -0500 | [diff] [blame] | 3919 | .instantiateReceiver(cl, data.info.name, data.intent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3920 | } catch (Exception e) { |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 3921 | if (DEBUG_BROADCAST) Slog.i(TAG, |
| 3922 | "Finishing failed broadcast to " + data.intent.getComponent()); |
| 3923 | data.sendFinished(mgr); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3924 | throw new RuntimeException( |
| 3925 | "Unable to instantiate receiver " + component |
| 3926 | + ": " + e.toString(), e); |
| 3927 | } |
| 3928 | |
| 3929 | try { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3930 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3931 | TAG, "Performing receive of " + data.intent |
| 3932 | + ": app=" + app |
| 3933 | + ", appName=" + app.getPackageName() |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3934 | + ", pkg=" + packageInfo.getPackageName() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3935 | + ", comp=" + data.intent.getComponent().toShortString() |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3936 | + ", dir=" + packageInfo.getAppDir()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3937 | |
Brad Fitzpatrick | bfb1919 | 2010-10-29 15:25:44 -0700 | [diff] [blame] | 3938 | sCurrentBroadcastIntent.set(data.intent); |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 3939 | receiver.setPendingResult(data); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3940 | receiver.onReceive(context.getReceiverRestrictedContext(), |
| 3941 | data.intent); |
| 3942 | } catch (Exception e) { |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 3943 | if (DEBUG_BROADCAST) Slog.i(TAG, |
| 3944 | "Finishing failed broadcast to " + data.intent.getComponent()); |
| 3945 | data.sendFinished(mgr); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3946 | if (!mInstrumentation.onException(receiver, e)) { |
| 3947 | throw new RuntimeException( |
| 3948 | "Unable to start receiver " + component |
| 3949 | + ": " + e.toString(), e); |
| 3950 | } |
Brad Fitzpatrick | bfb1919 | 2010-10-29 15:25:44 -0700 | [diff] [blame] | 3951 | } finally { |
| 3952 | sCurrentBroadcastIntent.set(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3953 | } |
| 3954 | |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 3955 | if (receiver.getPendingResult() != null) { |
| 3956 | data.finish(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3957 | } |
| 3958 | } |
| 3959 | |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3960 | // Instantiate a BackupAgent and tell it that it's alive |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3961 | private void handleCreateBackupAgent(CreateBackupAgentData data) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3962 | if (DEBUG_BACKUP) Slog.v(TAG, "handleCreateBackupAgent: " + data); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3963 | |
Christopher Tate | 346acb1 | 2012-10-15 19:20:25 -0700 | [diff] [blame] | 3964 | // Sanity check the requested target package's uid against ours |
| 3965 | try { |
| 3966 | PackageInfo requestedPackage = getPackageManager().getPackageInfo( |
| 3967 | data.appInfo.packageName, 0, UserHandle.myUserId()); |
| 3968 | if (requestedPackage.applicationInfo.uid != Process.myUid()) { |
| 3969 | Slog.w(TAG, "Asked to instantiate non-matching package " |
| 3970 | + data.appInfo.packageName); |
| 3971 | return; |
| 3972 | } |
| 3973 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3974 | throw e.rethrowFromSystemServer(); |
Christopher Tate | 346acb1 | 2012-10-15 19:20:25 -0700 | [diff] [blame] | 3975 | } |
| 3976 | |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3977 | // no longer idle; we have backup work to do |
| 3978 | unscheduleGcIdler(); |
| 3979 | |
| 3980 | // instantiate the BackupAgent class named in the manifest |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3981 | LoadedApk packageInfo = getPackageInfoNoCheck(data.appInfo, data.compatInfo); |
| 3982 | String packageName = packageInfo.mPackageName; |
Christopher Tate | 346acb1 | 2012-10-15 19:20:25 -0700 | [diff] [blame] | 3983 | if (packageName == null) { |
| 3984 | Slog.d(TAG, "Asked to create backup agent for nonexistent package"); |
| 3985 | return; |
| 3986 | } |
| 3987 | |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3988 | String classname = data.appInfo.backupAgentName; |
Christopher Tate | 79ec80d | 2011-06-24 14:58:49 -0700 | [diff] [blame] | 3989 | // full backup operation but no app-supplied agent? use the default implementation |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 3990 | if (classname == null && (data.backupMode == ApplicationThreadConstants.BACKUP_MODE_FULL |
| 3991 | || data.backupMode == ApplicationThreadConstants.BACKUP_MODE_RESTORE_FULL)) { |
Christopher Tate | 4a627c7 | 2011-04-01 14:43:32 -0700 | [diff] [blame] | 3992 | classname = "android.app.backup.FullBackupAgent"; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3993 | } |
Christopher Tate | 4a627c7 | 2011-04-01 14:43:32 -0700 | [diff] [blame] | 3994 | |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3995 | try { |
Christopher Tate | d1475e0 | 2009-07-09 15:36:17 -0700 | [diff] [blame] | 3996 | IBinder binder = null; |
Annie Meng | d582787 | 2019-01-30 20:28:57 +0000 | [diff] [blame] | 3997 | ArrayMap<String, BackupAgent> backupAgents = getBackupAgentsForUser(data.userId); |
| 3998 | BackupAgent agent = backupAgents.get(packageName); |
Christopher Tate | 2e40d11 | 2014-07-15 12:37:38 -0700 | [diff] [blame] | 3999 | if (agent != null) { |
| 4000 | // reusing the existing instance |
| 4001 | if (DEBUG_BACKUP) { |
| 4002 | Slog.v(TAG, "Reusing existing agent instance"); |
Christopher Tate | d1475e0 | 2009-07-09 15:36:17 -0700 | [diff] [blame] | 4003 | } |
Christopher Tate | 2e40d11 | 2014-07-15 12:37:38 -0700 | [diff] [blame] | 4004 | binder = agent.onBind(); |
| 4005 | } else { |
| 4006 | try { |
| 4007 | if (DEBUG_BACKUP) Slog.v(TAG, "Initializing agent class " + classname); |
| 4008 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 4009 | java.lang.ClassLoader cl = packageInfo.getClassLoader(); |
Dan Sandler | 07fe63e | 2017-08-15 16:41:11 -0400 | [diff] [blame] | 4010 | agent = (BackupAgent) cl.loadClass(classname).newInstance(); |
Christopher Tate | 2e40d11 | 2014-07-15 12:37:38 -0700 | [diff] [blame] | 4011 | |
| 4012 | // set up the agent's context |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 4013 | ContextImpl context = ContextImpl.createAppContext(this, packageInfo); |
Christopher Tate | 2e40d11 | 2014-07-15 12:37:38 -0700 | [diff] [blame] | 4014 | context.setOuterContext(agent); |
| 4015 | agent.attach(context); |
| 4016 | |
Ruslan Tkhakokhov | 063180f | 2019-01-28 20:29:46 +0000 | [diff] [blame] | 4017 | agent.onCreate(UserHandle.of(data.userId)); |
Christopher Tate | 2e40d11 | 2014-07-15 12:37:38 -0700 | [diff] [blame] | 4018 | binder = agent.onBind(); |
Annie Meng | d582787 | 2019-01-30 20:28:57 +0000 | [diff] [blame] | 4019 | backupAgents.put(packageName, agent); |
Christopher Tate | 2e40d11 | 2014-07-15 12:37:38 -0700 | [diff] [blame] | 4020 | } catch (Exception e) { |
| 4021 | // If this is during restore, fail silently; otherwise go |
| 4022 | // ahead and let the user see the crash. |
| 4023 | Slog.e(TAG, "Agent threw during creation: " + e); |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 4024 | if (data.backupMode != ApplicationThreadConstants.BACKUP_MODE_RESTORE |
| 4025 | && data.backupMode != |
| 4026 | ApplicationThreadConstants.BACKUP_MODE_RESTORE_FULL) { |
Christopher Tate | 2e40d11 | 2014-07-15 12:37:38 -0700 | [diff] [blame] | 4027 | throw e; |
| 4028 | } |
| 4029 | // falling through with 'binder' still null |
| 4030 | } |
Christopher Tate | d1475e0 | 2009-07-09 15:36:17 -0700 | [diff] [blame] | 4031 | } |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 4032 | |
| 4033 | // tell the OS that we're live now |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 4034 | try { |
Annie Meng | d582787 | 2019-01-30 20:28:57 +0000 | [diff] [blame] | 4035 | ActivityManager.getService().backupAgentCreated(packageName, binder, data.userId); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 4036 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4037 | throw e.rethrowFromSystemServer(); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 4038 | } |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 4039 | } catch (Exception e) { |
| 4040 | throw new RuntimeException("Unable to create BackupAgent " |
Christopher Tate | 4a627c7 | 2011-04-01 14:43:32 -0700 | [diff] [blame] | 4041 | + classname + ": " + e.toString(), e); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 4042 | } |
| 4043 | } |
| 4044 | |
| 4045 | // Tear down a BackupAgent |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 4046 | private void handleDestroyBackupAgent(CreateBackupAgentData data) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4047 | if (DEBUG_BACKUP) Slog.v(TAG, "handleDestroyBackupAgent: " + data); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4048 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 4049 | LoadedApk packageInfo = getPackageInfoNoCheck(data.appInfo, data.compatInfo); |
| 4050 | String packageName = packageInfo.mPackageName; |
Annie Meng | d582787 | 2019-01-30 20:28:57 +0000 | [diff] [blame] | 4051 | ArrayMap<String, BackupAgent> backupAgents = getBackupAgentsForUser(data.userId); |
| 4052 | BackupAgent agent = backupAgents.get(packageName); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 4053 | if (agent != null) { |
| 4054 | try { |
| 4055 | agent.onDestroy(); |
| 4056 | } catch (Exception e) { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 4057 | 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] | 4058 | e.printStackTrace(); |
| 4059 | } |
Annie Meng | d582787 | 2019-01-30 20:28:57 +0000 | [diff] [blame] | 4060 | backupAgents.remove(packageName); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 4061 | } else { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 4062 | Slog.w(TAG, "Attempt to destroy unknown backup agent " + data); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 4063 | } |
| 4064 | } |
| 4065 | |
Annie Meng | d582787 | 2019-01-30 20:28:57 +0000 | [diff] [blame] | 4066 | private ArrayMap<String, BackupAgent> getBackupAgentsForUser(int userId) { |
| 4067 | ArrayMap<String, BackupAgent> backupAgents = mBackupAgentsByUser.get(userId); |
| 4068 | if (backupAgents == null) { |
| 4069 | backupAgents = new ArrayMap<>(); |
| 4070 | mBackupAgentsByUser.put(userId, backupAgents); |
| 4071 | } |
| 4072 | return backupAgents; |
| 4073 | } |
| 4074 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 4075 | @UnsupportedAppUsage |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 4076 | private void handleCreateService(CreateServiceData data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4077 | // If we are getting ready to gc after going to the background, well |
| 4078 | // we are back active so skip it. |
| 4079 | unscheduleGcIdler(); |
| 4080 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 4081 | LoadedApk packageInfo = getPackageInfoNoCheck( |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4082 | data.info.applicationInfo, data.compatInfo); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4083 | Service service = null; |
| 4084 | try { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4085 | 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] | 4086 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 4087 | ContextImpl context = ContextImpl.createAppContext(this, packageInfo); |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 4088 | Application app = packageInfo.makeApplication(false, mInstrumentation); |
Dave Mankoff | 66d22c8 | 2019-09-11 14:14:45 -0400 | [diff] [blame] | 4089 | java.lang.ClassLoader cl = packageInfo.getClassLoader(); |
| 4090 | service = packageInfo.getAppFactory() |
| 4091 | .instantiateService(cl, data.info.name, data.intent); |
| 4092 | context.setOuterContext(service); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4093 | service.attach(context, this, data.info.name, data.token, app, |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 4094 | ActivityManager.getService()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4095 | service.onCreate(); |
| 4096 | mServices.put(data.token, service); |
| 4097 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 4098 | ActivityManager.getService().serviceDoneExecuting( |
Dianne Hackborn | 455625e | 2015-01-21 09:55:13 -0800 | [diff] [blame] | 4099 | data.token, SERVICE_DONE_EXECUTING_ANON, 0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4100 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4101 | throw e.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4102 | } |
| 4103 | } catch (Exception e) { |
| 4104 | if (!mInstrumentation.onException(service, e)) { |
| 4105 | throw new RuntimeException( |
| 4106 | "Unable to create service " + data.info.name |
| 4107 | + ": " + e.toString(), e); |
| 4108 | } |
| 4109 | } |
| 4110 | } |
| 4111 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 4112 | private void handleBindService(BindServiceData data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4113 | Service s = mServices.get(data.token); |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 4114 | if (DEBUG_SERVICE) |
| 4115 | Slog.v(TAG, "handleBindService s=" + s + " rebind=" + data.rebind); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4116 | if (s != null) { |
| 4117 | try { |
| 4118 | data.intent.setExtrasClassLoader(s.getClassLoader()); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 4119 | data.intent.prepareToEnterProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4120 | try { |
| 4121 | if (!data.rebind) { |
| 4122 | IBinder binder = s.onBind(data.intent); |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 4123 | ActivityManager.getService().publishService( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4124 | data.token, data.intent, binder); |
| 4125 | } else { |
| 4126 | s.onRebind(data.intent); |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 4127 | ActivityManager.getService().serviceDoneExecuting( |
Dianne Hackborn | 455625e | 2015-01-21 09:55:13 -0800 | [diff] [blame] | 4128 | data.token, SERVICE_DONE_EXECUTING_ANON, 0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4129 | } |
| 4130 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4131 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4132 | } |
| 4133 | } catch (Exception e) { |
| 4134 | if (!mInstrumentation.onException(s, e)) { |
| 4135 | throw new RuntimeException( |
| 4136 | "Unable to bind to service " + s |
| 4137 | + " with " + data.intent + ": " + e.toString(), e); |
| 4138 | } |
| 4139 | } |
| 4140 | } |
| 4141 | } |
| 4142 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 4143 | private void handleUnbindService(BindServiceData data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4144 | Service s = mServices.get(data.token); |
| 4145 | if (s != null) { |
| 4146 | try { |
| 4147 | data.intent.setExtrasClassLoader(s.getClassLoader()); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 4148 | data.intent.prepareToEnterProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4149 | boolean doRebind = s.onUnbind(data.intent); |
| 4150 | try { |
| 4151 | if (doRebind) { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 4152 | ActivityManager.getService().unbindFinished( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4153 | data.token, data.intent, doRebind); |
| 4154 | } else { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 4155 | ActivityManager.getService().serviceDoneExecuting( |
Dianne Hackborn | 455625e | 2015-01-21 09:55:13 -0800 | [diff] [blame] | 4156 | data.token, SERVICE_DONE_EXECUTING_ANON, 0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4157 | } |
| 4158 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4159 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4160 | } |
| 4161 | } catch (Exception e) { |
| 4162 | if (!mInstrumentation.onException(s, e)) { |
| 4163 | throw new RuntimeException( |
| 4164 | "Unable to unbind to service " + s |
| 4165 | + " with " + data.intent + ": " + e.toString(), e); |
| 4166 | } |
| 4167 | } |
| 4168 | } |
| 4169 | } |
| 4170 | |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 4171 | private void handleDumpService(DumpComponentInfo info) { |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 4172 | final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); |
| 4173 | try { |
| 4174 | Service s = mServices.get(info.token); |
| 4175 | if (s != null) { |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 4176 | PrintWriter pw = new FastPrintWriter(new FileOutputStream( |
| 4177 | info.fd.getFileDescriptor())); |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 4178 | s.dump(info.fd.getFileDescriptor(), pw, info.args); |
| 4179 | pw.flush(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4180 | } |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 4181 | } finally { |
| 4182 | IoUtils.closeQuietly(info.fd); |
| 4183 | StrictMode.setThreadPolicy(oldPolicy); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4184 | } |
| 4185 | } |
| 4186 | |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 4187 | private void handleDumpActivity(DumpComponentInfo info) { |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 4188 | final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); |
| 4189 | try { |
| 4190 | ActivityClientRecord r = mActivities.get(info.token); |
| 4191 | if (r != null && r.activity != null) { |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 4192 | PrintWriter pw = new FastPrintWriter(new FileOutputStream( |
| 4193 | info.fd.getFileDescriptor())); |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 4194 | r.activity.dump(info.prefix, info.fd.getFileDescriptor(), pw, info.args); |
| 4195 | pw.flush(); |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 4196 | } |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 4197 | } finally { |
| 4198 | IoUtils.closeQuietly(info.fd); |
| 4199 | StrictMode.setThreadPolicy(oldPolicy); |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 4200 | } |
| 4201 | } |
| 4202 | |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 4203 | private void handleDumpProvider(DumpComponentInfo info) { |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 4204 | final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); |
| 4205 | try { |
| 4206 | ProviderClientRecord r = mLocalProviders.get(info.token); |
| 4207 | if (r != null && r.mLocalProvider != null) { |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 4208 | PrintWriter pw = new FastPrintWriter(new FileOutputStream( |
| 4209 | info.fd.getFileDescriptor())); |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 4210 | r.mLocalProvider.dump(info.fd.getFileDescriptor(), pw, info.args); |
| 4211 | pw.flush(); |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 4212 | } |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 4213 | } finally { |
| 4214 | IoUtils.closeQuietly(info.fd); |
| 4215 | StrictMode.setThreadPolicy(oldPolicy); |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 4216 | } |
| 4217 | } |
| 4218 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 4219 | private void handleServiceArgs(ServiceArgsData data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4220 | Service s = mServices.get(data.token); |
| 4221 | if (s != null) { |
| 4222 | try { |
| 4223 | if (data.args != null) { |
| 4224 | data.args.setExtrasClassLoader(s.getClassLoader()); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 4225 | data.args.prepareToEnterProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4226 | } |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 4227 | int res; |
| 4228 | if (!data.taskRemoved) { |
| 4229 | res = s.onStartCommand(data.args, data.flags, data.startId); |
| 4230 | } else { |
| 4231 | s.onTaskRemoved(data.args); |
| 4232 | res = Service.START_TASK_REMOVED_COMPLETE; |
| 4233 | } |
Brad Fitzpatrick | 333b8cb | 2010-08-26 12:04:57 -0700 | [diff] [blame] | 4234 | |
| 4235 | QueuedWork.waitToFinish(); |
| 4236 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4237 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 4238 | ActivityManager.getService().serviceDoneExecuting( |
Dianne Hackborn | 455625e | 2015-01-21 09:55:13 -0800 | [diff] [blame] | 4239 | data.token, SERVICE_DONE_EXECUTING_START, data.startId, res); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4240 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4241 | throw e.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4242 | } |
| 4243 | } catch (Exception e) { |
| 4244 | if (!mInstrumentation.onException(s, e)) { |
| 4245 | throw new RuntimeException( |
| 4246 | "Unable to start service " + s |
| 4247 | + " with " + data.args + ": " + e.toString(), e); |
| 4248 | } |
| 4249 | } |
| 4250 | } |
| 4251 | } |
| 4252 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 4253 | private void handleStopService(IBinder token) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4254 | Service s = mServices.remove(token); |
| 4255 | if (s != null) { |
| 4256 | try { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4257 | if (localLOGV) Slog.v(TAG, "Destroying service " + s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4258 | s.onDestroy(); |
Amith Yamasani | 7592825 | 2017-05-22 15:10:47 -0700 | [diff] [blame] | 4259 | s.detachAndCleanUp(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4260 | Context context = s.getBaseContext(); |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 4261 | if (context instanceof ContextImpl) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4262 | final String who = s.getClassName(); |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 4263 | ((ContextImpl) context).scheduleFinalCleanup(who, "Service"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4264 | } |
Brad Fitzpatrick | 333b8cb | 2010-08-26 12:04:57 -0700 | [diff] [blame] | 4265 | |
| 4266 | QueuedWork.waitToFinish(); |
| 4267 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4268 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 4269 | ActivityManager.getService().serviceDoneExecuting( |
Dianne Hackborn | 455625e | 2015-01-21 09:55:13 -0800 | [diff] [blame] | 4270 | token, SERVICE_DONE_EXECUTING_STOP, 0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4271 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4272 | throw e.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4273 | } |
| 4274 | } catch (Exception e) { |
| 4275 | if (!mInstrumentation.onException(s, e)) { |
| 4276 | throw new RuntimeException( |
| 4277 | "Unable to stop service " + s |
| 4278 | + ": " + e.toString(), e); |
| 4279 | } |
Craig Mautner | 66c4a82 | 2015-01-16 12:48:16 -0800 | [diff] [blame] | 4280 | Slog.i(TAG, "handleStopService: exception for " + token, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4281 | } |
Craig Mautner | 9776ad4 | 2015-01-15 14:38:39 -0800 | [diff] [blame] | 4282 | } else { |
| 4283 | Slog.i(TAG, "handleStopService: token=" + token + " not found."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4284 | } |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4285 | //Slog.i(TAG, "Running services: " + mServices); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4286 | } |
| 4287 | |
Andrii Kulian | d9e2acb | 2018-03-29 16:07:11 -0700 | [diff] [blame] | 4288 | /** |
| 4289 | * Resume the activity. |
| 4290 | * @param token Target activity token. |
| 4291 | * @param finalStateRequest Flag indicating if this is part of final state resolution for a |
| 4292 | * transaction. |
| 4293 | * @param reason Reason for performing the action. |
| 4294 | * |
| 4295 | * @return The {@link ActivityClientRecord} that was resumed, {@code null} otherwise. |
| 4296 | */ |
| 4297 | @VisibleForTesting |
| 4298 | public ActivityClientRecord performResumeActivity(IBinder token, boolean finalStateRequest, |
Andrii Kulian | dfbf971 | 2018-03-08 15:42:24 -0800 | [diff] [blame] | 4299 | String reason) { |
Andrii Kulian | d9e2acb | 2018-03-29 16:07:11 -0700 | [diff] [blame] | 4300 | final ActivityClientRecord r = mActivities.get(token); |
| 4301 | if (localLOGV) { |
| 4302 | Slog.v(TAG, "Performing resume of " + r + " finished=" + r.activity.mFinished); |
| 4303 | } |
Andrii Kulian | 0f3356c | 2019-03-18 21:34:40 +0000 | [diff] [blame] | 4304 | if (r == null || r.activity.mFinished) { |
Andrii Kulian | d9e2acb | 2018-03-29 16:07:11 -0700 | [diff] [blame] | 4305 | return null; |
| 4306 | } |
| 4307 | if (r.getLifecycleState() == ON_RESUME) { |
| 4308 | if (!finalStateRequest) { |
| 4309 | final RuntimeException e = new IllegalStateException( |
| 4310 | "Trying to resume activity which is already resumed"); |
| 4311 | Slog.e(TAG, e.getMessage(), e); |
| 4312 | Slog.e(TAG, r.getStateString()); |
| 4313 | // TODO(lifecycler): A double resume request is possible when an activity |
| 4314 | // receives two consequent transactions with relaunch requests and "resumed" |
| 4315 | // final state requests and the second relaunch is omitted. We still try to |
| 4316 | // handle two resume requests for the final state. For cases other than this |
| 4317 | // one, we don't expect it to happen. |
Andrii Kulian | 9956d89 | 2018-02-14 13:48:56 -0800 | [diff] [blame] | 4318 | } |
Andrii Kulian | d9e2acb | 2018-03-29 16:07:11 -0700 | [diff] [blame] | 4319 | return null; |
| 4320 | } |
| 4321 | if (finalStateRequest) { |
| 4322 | r.hideForNow = false; |
| 4323 | r.activity.mStartedActivity = false; |
| 4324 | } |
| 4325 | try { |
| 4326 | r.activity.onStateNotSaved(); |
| 4327 | r.activity.mFragments.noteStateNotSaved(); |
| 4328 | checkAndBlockForNetworkAccess(); |
| 4329 | if (r.pendingIntents != null) { |
| 4330 | deliverNewIntents(r, r.pendingIntents); |
| 4331 | r.pendingIntents = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4332 | } |
Andrii Kulian | d9e2acb | 2018-03-29 16:07:11 -0700 | [diff] [blame] | 4333 | if (r.pendingResults != null) { |
Andrii Kulian | e55b009 | 2018-04-19 15:29:22 -0700 | [diff] [blame] | 4334 | deliverResults(r, r.pendingResults, reason); |
Andrii Kulian | d9e2acb | 2018-03-29 16:07:11 -0700 | [diff] [blame] | 4335 | r.pendingResults = null; |
| 4336 | } |
| 4337 | r.activity.performResume(r.startsNotResumed, reason); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4338 | |
Andrii Kulian | d9e2acb | 2018-03-29 16:07:11 -0700 | [diff] [blame] | 4339 | r.state = null; |
| 4340 | r.persistentState = null; |
| 4341 | r.setState(ON_RESUME); |
Andrii Kulian | d70cdb9 | 2019-01-08 15:03:50 -0800 | [diff] [blame] | 4342 | |
Andrii Kulian | 8602401 | 2019-04-18 19:41:23 -0700 | [diff] [blame] | 4343 | reportTopResumedActivityChanged(r, r.isTopResumedActivity, "topWhenResuming"); |
Andrii Kulian | d9e2acb | 2018-03-29 16:07:11 -0700 | [diff] [blame] | 4344 | } catch (Exception e) { |
| 4345 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4346 | throw new RuntimeException("Unable to resume activity " |
| 4347 | + r.intent.getComponent().toShortString() + ": " + e.toString(), e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4348 | } |
| 4349 | } |
| 4350 | return r; |
| 4351 | } |
| 4352 | |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4353 | static final void cleanUpPendingRemoveWindows(ActivityClientRecord r, boolean force) { |
| 4354 | if (r.mPreserveWindow && !force) { |
| 4355 | return; |
| 4356 | } |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4357 | if (r.mPendingRemoveWindow != null) { |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4358 | r.mPendingRemoveWindowManager.removeViewImmediate( |
| 4359 | r.mPendingRemoveWindow.getDecorView()); |
| 4360 | IBinder wtoken = r.mPendingRemoveWindow.getDecorView().getWindowToken(); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4361 | if (wtoken != null) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 4362 | WindowManagerGlobal.getInstance().closeAll(wtoken, |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4363 | r.activity.getClass().getName(), "Activity"); |
| 4364 | } |
| 4365 | } |
| 4366 | r.mPendingRemoveWindow = null; |
| 4367 | r.mPendingRemoveWindowManager = null; |
| 4368 | } |
| 4369 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 4370 | @Override |
Andrii Kulian | dfbf971 | 2018-03-08 15:42:24 -0800 | [diff] [blame] | 4371 | public void handleResumeActivity(IBinder token, boolean finalStateRequest, boolean isForward, |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4372 | String reason) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4373 | // If we are getting ready to gc after going to the background, well |
| 4374 | // we are back active so skip it. |
| 4375 | unscheduleGcIdler(); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4376 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4377 | |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 4378 | // TODO Push resumeArgs into the activity for consideration |
Andrii Kulian | dfbf971 | 2018-03-08 15:42:24 -0800 | [diff] [blame] | 4379 | final ActivityClientRecord r = performResumeActivity(token, finalStateRequest, reason); |
Andrii Kulian | d9e2acb | 2018-03-29 16:07:11 -0700 | [diff] [blame] | 4380 | if (r == null) { |
| 4381 | // We didn't actually resume the activity, so skipping any follow-up actions. |
| 4382 | return; |
| 4383 | } |
Riddle Hsu | 66b74a8 | 2018-07-26 00:20:12 +0800 | [diff] [blame] | 4384 | if (mActivitiesToBeDestroyed.containsKey(token)) { |
| 4385 | // Although the activity is resumed, it is going to be destroyed. So the following |
| 4386 | // UI operations are unnecessary and also prevents exception because its token may |
| 4387 | // be gone that window manager cannot recognize it. All necessary cleanup actions |
| 4388 | // performed below will be done while handling destruction. |
| 4389 | return; |
| 4390 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4391 | |
Andrii Kulian | d9e2acb | 2018-03-29 16:07:11 -0700 | [diff] [blame] | 4392 | final Activity a = r.activity; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4393 | |
Andrii Kulian | d9e2acb | 2018-03-29 16:07:11 -0700 | [diff] [blame] | 4394 | if (localLOGV) { |
| 4395 | Slog.v(TAG, "Resume " + r + " started activity: " + a.mStartedActivity |
| 4396 | + ", hideForNow: " + r.hideForNow + ", finished: " + a.mFinished); |
| 4397 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4398 | |
Andrii Kulian | d9e2acb | 2018-03-29 16:07:11 -0700 | [diff] [blame] | 4399 | final int forwardBit = isForward |
| 4400 | ? WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION : 0; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4401 | |
Andrii Kulian | d9e2acb | 2018-03-29 16:07:11 -0700 | [diff] [blame] | 4402 | // If the window hasn't yet been added to the window manager, |
| 4403 | // and this guy didn't finish itself or start another activity, |
| 4404 | // then go ahead and add the window. |
| 4405 | boolean willBeVisible = !a.mStartedActivity; |
| 4406 | if (!willBeVisible) { |
| 4407 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4408 | willBeVisible = ActivityTaskManager.getService().willActivityBeVisible( |
Andrii Kulian | d9e2acb | 2018-03-29 16:07:11 -0700 | [diff] [blame] | 4409 | a.getActivityToken()); |
| 4410 | } catch (RemoteException e) { |
| 4411 | throw e.rethrowFromSystemServer(); |
| 4412 | } |
| 4413 | } |
| 4414 | if (r.window == null && !a.mFinished && willBeVisible) { |
| 4415 | r.window = r.activity.getWindow(); |
| 4416 | View decor = r.window.getDecorView(); |
| 4417 | decor.setVisibility(View.INVISIBLE); |
| 4418 | ViewManager wm = a.getWindowManager(); |
| 4419 | WindowManager.LayoutParams l = r.window.getAttributes(); |
| 4420 | a.mDecor = decor; |
| 4421 | l.type = WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
| 4422 | l.softInputMode |= forwardBit; |
| 4423 | if (r.mPreserveWindow) { |
| 4424 | a.mWindowAdded = true; |
| 4425 | r.mPreserveWindow = false; |
| 4426 | // Normally the ViewRoot sets up callbacks with the Activity |
| 4427 | // in addView->ViewRootImpl#setView. If we are instead reusing |
| 4428 | // the decor view we have to notify the view root that the |
| 4429 | // callbacks may have changed. |
| 4430 | ViewRootImpl impl = decor.getViewRootImpl(); |
| 4431 | if (impl != null) { |
| 4432 | impl.notifyChildRebuilt(); |
Dianne Hackborn | 061d58a | 2010-03-12 15:07:06 -0800 | [diff] [blame] | 4433 | } |
| 4434 | } |
Andrii Kulian | d9e2acb | 2018-03-29 16:07:11 -0700 | [diff] [blame] | 4435 | if (a.mVisibleFromClient) { |
| 4436 | if (!a.mWindowAdded) { |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4437 | a.mWindowAdded = true; |
Andrii Kulian | d9e2acb | 2018-03-29 16:07:11 -0700 | [diff] [blame] | 4438 | wm.addView(decor, l); |
| 4439 | } else { |
| 4440 | // The activity will get a callback for this {@link LayoutParams} change |
| 4441 | // earlier. However, at that time the decor will not be set (this is set |
| 4442 | // in this method), so no action will be taken. This call ensures the |
| 4443 | // callback occurs with the decor set. |
| 4444 | a.onWindowAttributesChanged(l); |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4445 | } |
Andrii Kulian | d9e2acb | 2018-03-29 16:07:11 -0700 | [diff] [blame] | 4446 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4447 | |
| 4448 | // If the window has already been added, but during resume |
| 4449 | // we started another activity, then don't yet make the |
Dianne Hackborn | 061d58a | 2010-03-12 15:07:06 -0800 | [diff] [blame] | 4450 | // window visible. |
Andrii Kulian | d9e2acb | 2018-03-29 16:07:11 -0700 | [diff] [blame] | 4451 | } else if (!willBeVisible) { |
| 4452 | if (localLOGV) Slog.v(TAG, "Launch " + r + " mStartedActivity set"); |
| 4453 | r.hideForNow = true; |
| 4454 | } |
| 4455 | |
| 4456 | // Get rid of anything left hanging around. |
| 4457 | cleanUpPendingRemoveWindows(r, false /* force */); |
| 4458 | |
| 4459 | // The window is now visible if it has been added, we are not |
| 4460 | // simply finishing, and we are not starting another activity. |
| 4461 | if (!r.activity.mFinished && willBeVisible && r.activity.mDecor != null && !r.hideForNow) { |
| 4462 | if (r.newConfig != null) { |
| 4463 | performConfigurationChangedForActivity(r, r.newConfig); |
| 4464 | if (DEBUG_CONFIGURATION) { |
| 4465 | Slog.v(TAG, "Resuming activity " + r.activityInfo.name + " with newConfig " |
| 4466 | + r.activity.mCurrentConfig); |
| 4467 | } |
| 4468 | r.newConfig = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4469 | } |
Andrii Kulian | d9e2acb | 2018-03-29 16:07:11 -0700 | [diff] [blame] | 4470 | if (localLOGV) Slog.v(TAG, "Resuming " + r + " with isForward=" + isForward); |
Tiger Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 4471 | ViewRootImpl impl = r.window.getDecorView().getViewRootImpl(); |
| 4472 | WindowManager.LayoutParams l = impl != null |
| 4473 | ? impl.mWindowAttributes : r.window.getAttributes(); |
Andrii Kulian | d9e2acb | 2018-03-29 16:07:11 -0700 | [diff] [blame] | 4474 | if ((l.softInputMode |
| 4475 | & WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) |
| 4476 | != forwardBit) { |
| 4477 | l.softInputMode = (l.softInputMode |
| 4478 | & (~WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION)) |
| 4479 | | forwardBit; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4480 | if (r.activity.mVisibleFromClient) { |
Andrii Kulian | d9e2acb | 2018-03-29 16:07:11 -0700 | [diff] [blame] | 4481 | ViewManager wm = a.getWindowManager(); |
| 4482 | View decor = r.window.getDecorView(); |
| 4483 | wm.updateViewLayout(decor, l); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4484 | } |
| 4485 | } |
| 4486 | |
Andrii Kulian | d9e2acb | 2018-03-29 16:07:11 -0700 | [diff] [blame] | 4487 | r.activity.mVisibleFromServer = true; |
| 4488 | mNumVisibleActivities++; |
| 4489 | if (r.activity.mVisibleFromClient) { |
| 4490 | r.activity.makeVisible(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4491 | } |
| 4492 | } |
Andrii Kulian | d9e2acb | 2018-03-29 16:07:11 -0700 | [diff] [blame] | 4493 | |
| 4494 | r.nextIdle = mNewActivities; |
| 4495 | mNewActivities = r; |
| 4496 | if (localLOGV) Slog.v(TAG, "Scheduling idle handler for " + r); |
| 4497 | Looper.myQueue().addIdleHandler(new Idler()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4498 | } |
| 4499 | |
Andrii Kulian | d70cdb9 | 2019-01-08 15:03:50 -0800 | [diff] [blame] | 4500 | |
| 4501 | @Override |
| 4502 | public void handleTopResumedActivityChanged(IBinder token, boolean onTop, String reason) { |
| 4503 | ActivityClientRecord r = mActivities.get(token); |
| 4504 | if (r == null || r.activity == null) { |
| 4505 | Slog.w(TAG, "Not found target activity to report position change for token: " + token); |
| 4506 | return; |
| 4507 | } |
| 4508 | |
| 4509 | if (DEBUG_ORDER) { |
| 4510 | Slog.d(TAG, "Received position change to top: " + onTop + " for activity: " + r); |
| 4511 | } |
| 4512 | |
| 4513 | if (r.isTopResumedActivity == onTop) { |
| 4514 | throw new IllegalStateException("Activity top position already set to onTop=" + onTop); |
| 4515 | } |
| 4516 | |
| 4517 | r.isTopResumedActivity = onTop; |
| 4518 | |
| 4519 | if (r.getLifecycleState() == ON_RESUME) { |
Andrii Kulian | 8602401 | 2019-04-18 19:41:23 -0700 | [diff] [blame] | 4520 | reportTopResumedActivityChanged(r, onTop, "topStateChangedWhenResumed"); |
Andrii Kulian | d70cdb9 | 2019-01-08 15:03:50 -0800 | [diff] [blame] | 4521 | } else { |
| 4522 | if (DEBUG_ORDER) { |
| 4523 | Slog.d(TAG, "Won't deliver top position change in state=" + r.getLifecycleState()); |
| 4524 | } |
| 4525 | } |
| 4526 | } |
| 4527 | |
| 4528 | /** |
| 4529 | * Call {@link Activity#onTopResumedActivityChanged(boolean)} if its top resumed state changed |
| 4530 | * since the last report. |
| 4531 | */ |
Andrii Kulian | 8602401 | 2019-04-18 19:41:23 -0700 | [diff] [blame] | 4532 | private void reportTopResumedActivityChanged(ActivityClientRecord r, boolean onTop, |
| 4533 | String reason) { |
Andrii Kulian | d70cdb9 | 2019-01-08 15:03:50 -0800 | [diff] [blame] | 4534 | if (r.lastReportedTopResumedState != onTop) { |
| 4535 | r.lastReportedTopResumedState = onTop; |
Andrii Kulian | 8602401 | 2019-04-18 19:41:23 -0700 | [diff] [blame] | 4536 | r.activity.performTopResumedActivityChanged(onTop, reason); |
Andrii Kulian | d70cdb9 | 2019-01-08 15:03:50 -0800 | [diff] [blame] | 4537 | } |
| 4538 | } |
| 4539 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 4540 | @Override |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4541 | public void handlePauseActivity(IBinder token, boolean finished, boolean userLeaving, |
Andrii Kulian | a6176e3 | 2018-02-27 11:51:18 -0800 | [diff] [blame] | 4542 | int configChanges, PendingTransactionActions pendingActions, String reason) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4543 | ActivityClientRecord r = mActivities.get(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4544 | if (r != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4545 | if (userLeaving) { |
| 4546 | performUserLeavingActivity(r); |
jorgegil@google.com | 06bc323 | 2019-10-31 14:51:22 -0700 | [diff] [blame] | 4547 | r.mIsUserLeaving = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4548 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4549 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4550 | r.activity.mConfigChangeFlags |= configChanges; |
Andrii Kulian | d25680c | 2018-02-21 15:16:58 -0800 | [diff] [blame] | 4551 | performPauseActivity(r, finished, reason, pendingActions); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4552 | |
Dianne Hackborn | aa93bcd | 2010-10-27 13:57:00 -0700 | [diff] [blame] | 4553 | // Make sure any pending writes are now committed. |
Dianne Hackborn | 5d9d03a | 2011-01-24 13:15:09 -0800 | [diff] [blame] | 4554 | if (r.isPreHoneycomb()) { |
| 4555 | QueuedWork.waitToFinish(); |
| 4556 | } |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4557 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4558 | } |
| 4559 | } |
| 4560 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4561 | final void performUserLeavingActivity(ActivityClientRecord r) { |
jorgegil@google.com | 06bc323 | 2019-10-31 14:51:22 -0700 | [diff] [blame] | 4562 | r.mIsUserLeaving = true; |
| 4563 | mInstrumentation.callActivityOnPictureInPictureRequested(r.activity); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4564 | mInstrumentation.callActivityOnUserLeaving(r.activity); |
| 4565 | } |
| 4566 | |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 4567 | final Bundle performPauseActivity(IBinder token, boolean finished, String reason, |
| 4568 | PendingTransactionActions pendingActions) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4569 | ActivityClientRecord r = mActivities.get(token); |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 4570 | return r != null ? performPauseActivity(r, finished, reason, pendingActions) : null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4571 | } |
| 4572 | |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 4573 | /** |
| 4574 | * Pause the activity. |
| 4575 | * @return Saved instance state for pre-Honeycomb apps if it was saved, {@code null} otherwise. |
| 4576 | */ |
| 4577 | private Bundle performPauseActivity(ActivityClientRecord r, boolean finished, String reason, |
| 4578 | PendingTransactionActions pendingActions) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4579 | if (r.paused) { |
Andrii Kulian | 0f3356c | 2019-03-18 21:34:40 +0000 | [diff] [blame] | 4580 | if (r.activity.mFinished) { |
| 4581 | // If we are finishing, we won't call onResume() in certain cases. |
| 4582 | // So here we likewise don't want to call onPause() if the activity |
| 4583 | // isn't resumed. |
| 4584 | return null; |
| 4585 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4586 | RuntimeException e = new RuntimeException( |
| 4587 | "Performing pause of activity that is not resumed: " |
| 4588 | + r.intent.getComponent().toShortString()); |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 4589 | Slog.e(TAG, e.getMessage(), e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4590 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4591 | if (finished) { |
| 4592 | r.activity.mFinished = true; |
| 4593 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4594 | |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 4595 | // Pre-Honeycomb apps always save their state before pausing |
| 4596 | final boolean shouldSaveState = !r.activity.mFinished && r.isPreHoneycomb(); |
| 4597 | if (shouldSaveState) { |
| 4598 | callActivityOnSaveInstanceState(r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4599 | } |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 4600 | |
| 4601 | performPauseActivityIfNeeded(r, reason); |
Jeff Hamilton | 52d3203 | 2011-01-08 15:31:26 -0600 | [diff] [blame] | 4602 | |
| 4603 | // Notify any outstanding on paused listeners |
| 4604 | ArrayList<OnActivityPausedListener> listeners; |
| 4605 | synchronized (mOnPauseListeners) { |
| 4606 | listeners = mOnPauseListeners.remove(r.activity); |
| 4607 | } |
| 4608 | int size = (listeners != null ? listeners.size() : 0); |
| 4609 | for (int i = 0; i < size; i++) { |
| 4610 | listeners.get(i).onPaused(r.activity); |
| 4611 | } |
| 4612 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4613 | final Bundle oldState = pendingActions != null ? pendingActions.getOldState() : null; |
| 4614 | if (oldState != null) { |
| 4615 | // We need to keep around the original state, in case we need to be created again. |
| 4616 | // But we only do this for pre-Honeycomb apps, which always save their state when |
| 4617 | // pausing, so we can not have them save their state when restarting from a paused |
| 4618 | // state. For HC and later, we want to (and can) let the state be saved as the |
| 4619 | // normal part of stopping the activity. |
| 4620 | if (r.isPreHoneycomb()) { |
| 4621 | r.state = oldState; |
| 4622 | } |
| 4623 | } |
| 4624 | |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 4625 | return shouldSaveState ? r.state : null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4626 | } |
| 4627 | |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 4628 | private void performPauseActivityIfNeeded(ActivityClientRecord r, String reason) { |
| 4629 | if (r.paused) { |
| 4630 | // You are already paused silly... |
| 4631 | return; |
| 4632 | } |
| 4633 | |
Andrii Kulian | d70cdb9 | 2019-01-08 15:03:50 -0800 | [diff] [blame] | 4634 | // Always reporting top resumed position loss when pausing an activity. If necessary, it |
| 4635 | // will be restored in performResumeActivity(). |
Andrii Kulian | 8602401 | 2019-04-18 19:41:23 -0700 | [diff] [blame] | 4636 | reportTopResumedActivityChanged(r, false /* onTop */, "pausing"); |
Andrii Kulian | d70cdb9 | 2019-01-08 15:03:50 -0800 | [diff] [blame] | 4637 | |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 4638 | try { |
| 4639 | r.activity.mCalled = false; |
| 4640 | mInstrumentation.callActivityOnPause(r.activity); |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 4641 | if (!r.activity.mCalled) { |
| 4642 | throw new SuperNotCalledException("Activity " + safeToComponentShortString(r.intent) |
| 4643 | + " did not call through to super.onPause()"); |
| 4644 | } |
| 4645 | } catch (SuperNotCalledException e) { |
| 4646 | throw e; |
| 4647 | } catch (Exception e) { |
| 4648 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4649 | throw new RuntimeException("Unable to pause activity " |
| 4650 | + safeToComponentShortString(r.intent) + ": " + e.toString(), e); |
| 4651 | } |
| 4652 | } |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4653 | r.setState(ON_PAUSE); |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 4654 | } |
| 4655 | |
Andrii Kulian | 829829c | 2018-03-19 18:19:05 -0700 | [diff] [blame] | 4656 | /** Called from {@link LocalActivityManager}. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 4657 | @UnsupportedAppUsage |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 4658 | final void performStopActivity(IBinder token, boolean saveState, String reason) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4659 | ActivityClientRecord r = mActivities.get(token); |
Andrii Kulian | b9faa03 | 2019-10-17 23:11:54 -0700 | [diff] [blame] | 4660 | performStopActivityInner(r, null /* stopInfo */, saveState, false /* finalStateRequest */, |
| 4661 | reason); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4662 | } |
| 4663 | |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 4664 | private static final class ProviderRefCount { |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 4665 | public final ContentProviderHolder holder; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 4666 | public final ProviderClientRecord client; |
| 4667 | public int stableCount; |
| 4668 | public int unstableCount; |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 4669 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 4670 | // When this is set, the stable and unstable ref counts are 0 and |
| 4671 | // we have a pending operation scheduled to remove the ref count |
| 4672 | // from the activity manager. On the activity manager we are still |
| 4673 | // holding an unstable ref, though it is not reflected in the counts |
| 4674 | // here. |
| 4675 | public boolean removePending; |
| 4676 | |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 4677 | ProviderRefCount(ContentProviderHolder inHolder, |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 4678 | ProviderClientRecord inClient, int sCount, int uCount) { |
| 4679 | holder = inHolder; |
| 4680 | client = inClient; |
| 4681 | stableCount = sCount; |
| 4682 | unstableCount = uCount; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4683 | } |
| 4684 | } |
| 4685 | |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4686 | /** |
Andrii Kulian | b9faa03 | 2019-10-17 23:11:54 -0700 | [diff] [blame] | 4687 | * Core implementation of stopping an activity. |
Andrii Kulian | 829829c | 2018-03-19 18:19:05 -0700 | [diff] [blame] | 4688 | * @param r Target activity client record. |
| 4689 | * @param info Action that will report activity stop to server. |
Andrii Kulian | 829829c | 2018-03-19 18:19:05 -0700 | [diff] [blame] | 4690 | * @param saveState Flag indicating whether the activity state should be saved. |
| 4691 | * @param finalStateRequest Flag indicating if this call is handling final lifecycle state |
| 4692 | * request for a transaction. |
| 4693 | * @param reason Reason for performing this operation. |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4694 | */ |
Andrii Kulian | b9faa03 | 2019-10-17 23:11:54 -0700 | [diff] [blame] | 4695 | private void performStopActivityInner(ActivityClientRecord r, StopInfo info, |
Andrii Kulian | 829829c | 2018-03-19 18:19:05 -0700 | [diff] [blame] | 4696 | boolean saveState, boolean finalStateRequest, String reason) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4697 | if (localLOGV) Slog.v(TAG, "Performing stop of " + r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4698 | if (r != null) { |
Andrii Kulian | b9faa03 | 2019-10-17 23:11:54 -0700 | [diff] [blame] | 4699 | if (r.stopped) { |
Andrii Kulian | 0f3356c | 2019-03-18 21:34:40 +0000 | [diff] [blame] | 4700 | if (r.activity.mFinished) { |
| 4701 | // If we are finishing, we won't call onResume() in certain |
| 4702 | // cases. So here we likewise don't want to call onStop() |
| 4703 | // if the activity isn't resumed. |
| 4704 | return; |
| 4705 | } |
| 4706 | if (!finalStateRequest) { |
| 4707 | final RuntimeException e = new RuntimeException( |
| 4708 | "Performing stop of activity that is already stopped: " |
| 4709 | + r.intent.getComponent().toShortString()); |
| 4710 | Slog.e(TAG, e.getMessage(), e); |
| 4711 | Slog.e(TAG, r.getStateString()); |
| 4712 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4713 | } |
| 4714 | |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 4715 | // One must first be paused before stopped... |
| 4716 | performPauseActivityIfNeeded(r, reason); |
| 4717 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4718 | if (info != null) { |
| 4719 | try { |
| 4720 | // First create a thumbnail for the activity... |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4721 | // For now, don't create the thumbnail here; we are |
| 4722 | // doing that by doing a screen snapshot. |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4723 | info.setDescription(r.activity.onCreateDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4724 | } catch (Exception e) { |
| 4725 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4726 | throw new RuntimeException( |
| 4727 | "Unable to save state of activity " |
| 4728 | + r.intent.getComponent().toShortString() |
| 4729 | + ": " + e.toString(), e); |
| 4730 | } |
| 4731 | } |
| 4732 | } |
| 4733 | |
Andrii Kulian | b9faa03 | 2019-10-17 23:11:54 -0700 | [diff] [blame] | 4734 | callActivityOnStop(r, saveState, reason); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4735 | } |
| 4736 | } |
| 4737 | |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 4738 | /** |
| 4739 | * Calls {@link Activity#onStop()} and {@link Activity#onSaveInstanceState(Bundle)}, and updates |
| 4740 | * the client record's state. |
| 4741 | * All calls to stop an activity must be done through this method to make sure that |
| 4742 | * {@link Activity#onSaveInstanceState(Bundle)} is also executed in the same call. |
| 4743 | */ |
| 4744 | private void callActivityOnStop(ActivityClientRecord r, boolean saveState, String reason) { |
Andrii Kulian | 391161f | 2018-01-29 10:50:02 -0800 | [diff] [blame] | 4745 | // Before P onSaveInstanceState was called before onStop, starting with P it's |
| 4746 | // called after. Before Honeycomb state was always saved before onPause. |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 4747 | final boolean shouldSaveState = saveState && !r.activity.mFinished && r.state == null |
| 4748 | && !r.isPreHoneycomb(); |
Andrii Kulian | 391161f | 2018-01-29 10:50:02 -0800 | [diff] [blame] | 4749 | final boolean isPreP = r.isPreP(); |
| 4750 | if (shouldSaveState && isPreP) { |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 4751 | callActivityOnSaveInstanceState(r); |
| 4752 | } |
| 4753 | |
| 4754 | try { |
Garfield Tan | c1681e6 | 2018-05-29 11:05:05 -0700 | [diff] [blame] | 4755 | r.activity.performStop(r.mPreserveWindow, reason); |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 4756 | } catch (SuperNotCalledException e) { |
| 4757 | throw e; |
| 4758 | } catch (Exception e) { |
| 4759 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4760 | throw new RuntimeException( |
| 4761 | "Unable to stop activity " |
| 4762 | + r.intent.getComponent().toShortString() |
| 4763 | + ": " + e.toString(), e); |
| 4764 | } |
| 4765 | } |
| 4766 | r.setState(ON_STOP); |
Andrii Kulian | 391161f | 2018-01-29 10:50:02 -0800 | [diff] [blame] | 4767 | |
| 4768 | if (shouldSaveState && !isPreP) { |
| 4769 | callActivityOnSaveInstanceState(r); |
| 4770 | } |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 4771 | } |
| 4772 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 4773 | private void updateVisibility(ActivityClientRecord r, boolean show) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4774 | View v = r.activity.mDecor; |
| 4775 | if (v != null) { |
| 4776 | if (show) { |
| 4777 | if (!r.activity.mVisibleFromServer) { |
| 4778 | r.activity.mVisibleFromServer = true; |
| 4779 | mNumVisibleActivities++; |
| 4780 | if (r.activity.mVisibleFromClient) { |
| 4781 | r.activity.makeVisible(); |
| 4782 | } |
| 4783 | } |
| 4784 | if (r.newConfig != null) { |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4785 | performConfigurationChangedForActivity(r, r.newConfig); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4786 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Updating activity vis " |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 4787 | + r.activityInfo.name + " with new config " |
| 4788 | + r.activity.mCurrentConfig); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4789 | r.newConfig = null; |
| 4790 | } |
| 4791 | } else { |
| 4792 | if (r.activity.mVisibleFromServer) { |
| 4793 | r.activity.mVisibleFromServer = false; |
| 4794 | mNumVisibleActivities--; |
| 4795 | v.setVisibility(View.INVISIBLE); |
| 4796 | } |
| 4797 | } |
| 4798 | } |
| 4799 | } |
| 4800 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 4801 | @Override |
Andrii Kulian | b9faa03 | 2019-10-17 23:11:54 -0700 | [diff] [blame] | 4802 | public void handleStopActivity(IBinder token, int configChanges, |
Andrii Kulian | 829829c | 2018-03-19 18:19:05 -0700 | [diff] [blame] | 4803 | PendingTransactionActions pendingActions, boolean finalStateRequest, String reason) { |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4804 | final ActivityClientRecord r = mActivities.get(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4805 | r.activity.mConfigChangeFlags |= configChanges; |
| 4806 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4807 | final StopInfo stopInfo = new StopInfo(); |
Andrii Kulian | b9faa03 | 2019-10-17 23:11:54 -0700 | [diff] [blame] | 4808 | performStopActivityInner(r, stopInfo, true /* saveState */, finalStateRequest, |
Andrii Kulian | 829829c | 2018-03-19 18:19:05 -0700 | [diff] [blame] | 4809 | reason); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4810 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4811 | if (localLOGV) Slog.v( |
Andrii Kulian | b9faa03 | 2019-10-17 23:11:54 -0700 | [diff] [blame] | 4812 | TAG, "Finishing stop of " + r + ": win=" + r.window); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4813 | |
Andrii Kulian | b9faa03 | 2019-10-17 23:11:54 -0700 | [diff] [blame] | 4814 | updateVisibility(r, false); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4815 | |
Dianne Hackborn | 5d9d03a | 2011-01-24 13:15:09 -0800 | [diff] [blame] | 4816 | // Make sure any pending writes are now committed. |
| 4817 | if (!r.isPreHoneycomb()) { |
| 4818 | QueuedWork.waitToFinish(); |
| 4819 | } |
| 4820 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4821 | stopInfo.setActivity(r); |
| 4822 | stopInfo.setState(r.state); |
| 4823 | stopInfo.setPersistentState(r.persistentState); |
| 4824 | pendingActions.setStopInfo(stopInfo); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4825 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4826 | } |
| 4827 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4828 | /** |
| 4829 | * Schedule the call to tell the activity manager we have stopped. We don't do this |
| 4830 | * immediately, because we want to have a chance for any other pending work (in particular |
| 4831 | * memory trim requests) to complete before you tell the activity manager to proceed and allow |
| 4832 | * us to go fully into the background. |
| 4833 | */ |
| 4834 | @Override |
| 4835 | public void reportStop(PendingTransactionActions pendingActions) { |
| 4836 | mH.post(pendingActions.getStopInfo()); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 4837 | } |
| 4838 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4839 | @Override |
| 4840 | public void performRestartActivity(IBinder token, boolean start) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4841 | ActivityClientRecord r = mActivities.get(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4842 | if (r.stopped) { |
Andrii Kulian | d25680c | 2018-02-21 15:16:58 -0800 | [diff] [blame] | 4843 | r.activity.performRestart(start, "performRestartActivity"); |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4844 | if (start) { |
| 4845 | r.setState(ON_START); |
| 4846 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4847 | } |
| 4848 | } |
| 4849 | |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 4850 | private void handleSetCoreSettings(Bundle coreSettings) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4851 | synchronized (mResourcesManager) { |
Svetoslav Ganov | 9aa597e | 2011-03-03 18:17:41 -0800 | [diff] [blame] | 4852 | mCoreSettings = coreSettings; |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 4853 | } |
Jon Miranda | 836c0a8 | 2014-08-11 12:32:26 -0700 | [diff] [blame] | 4854 | onCoreSettingsChange(); |
| 4855 | } |
| 4856 | |
| 4857 | private void onCoreSettingsChange() { |
Aurimas Liutikas | 8f004c8 | 2019-01-17 17:20:10 -0800 | [diff] [blame] | 4858 | if (updateDebugViewAttributeState()) { |
Jon Miranda | 836c0a8 | 2014-08-11 12:32:26 -0700 | [diff] [blame] | 4859 | // request all activities to relaunch for the changes to take place |
Adrian Roos | 03dd48c | 2019-03-19 17:17:37 -0400 | [diff] [blame] | 4860 | relaunchAllActivities(false /* preserveWindows */); |
Fyodor Kupolov | cb93d6f | 2017-05-04 17:27:16 -0700 | [diff] [blame] | 4861 | } |
| 4862 | } |
| 4863 | |
Aurimas Liutikas | 8f004c8 | 2019-01-17 17:20:10 -0800 | [diff] [blame] | 4864 | private boolean updateDebugViewAttributeState() { |
| 4865 | boolean previousState = View.sDebugViewAttributes; |
| 4866 | |
| 4867 | View.sDebugViewAttributesApplicationPackage = mCoreSettings.getString( |
| 4868 | Settings.Global.DEBUG_VIEW_ATTRIBUTES_APPLICATION_PACKAGE, ""); |
| 4869 | String currentPackage = (mBoundApplication != null && mBoundApplication.appInfo != null) |
MÃ¥rten Kongstad | 62eed6b | 2019-09-19 15:35:44 +0200 | [diff] [blame] | 4870 | ? mBoundApplication.appInfo.packageName : "<unknown-app>"; |
Aurimas Liutikas | 8f004c8 | 2019-01-17 17:20:10 -0800 | [diff] [blame] | 4871 | View.sDebugViewAttributes = |
| 4872 | mCoreSettings.getInt(Settings.Global.DEBUG_VIEW_ATTRIBUTES, 0) != 0 |
| 4873 | || View.sDebugViewAttributesApplicationPackage.equals(currentPackage); |
| 4874 | return previousState != View.sDebugViewAttributes; |
| 4875 | } |
| 4876 | |
Adrian Roos | 03dd48c | 2019-03-19 17:17:37 -0400 | [diff] [blame] | 4877 | private void relaunchAllActivities(boolean preserveWindows) { |
Fyodor Kupolov | cb93d6f | 2017-05-04 17:27:16 -0700 | [diff] [blame] | 4878 | for (Map.Entry<IBinder, ActivityClientRecord> entry : mActivities.entrySet()) { |
Adrian Roos | 03dd48c | 2019-03-19 17:17:37 -0400 | [diff] [blame] | 4879 | final ActivityClientRecord r = entry.getValue(); |
| 4880 | if (!r.activity.mFinished) { |
| 4881 | if (preserveWindows && r.window != null) { |
| 4882 | r.mPreserveWindow = true; |
| 4883 | } |
Andrii Kulian | 320e3b5 | 2018-05-03 16:26:25 -0700 | [diff] [blame] | 4884 | scheduleRelaunchActivity(entry.getKey()); |
Jon Miranda | 836c0a8 | 2014-08-11 12:32:26 -0700 | [diff] [blame] | 4885 | } |
| 4886 | } |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 4887 | } |
| 4888 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4889 | private void handleUpdatePackageCompatibilityInfo(UpdateCompatibilityData data) { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 4890 | LoadedApk apk = peekPackageInfo(data.pkg, false); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4891 | if (apk != null) { |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 4892 | apk.setCompatibilityInfo(data.info); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4893 | } |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 4894 | apk = peekPackageInfo(data.pkg, true); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4895 | if (apk != null) { |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 4896 | apk.setCompatibilityInfo(data.info); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4897 | } |
| 4898 | handleConfigurationChanged(mConfiguration, data.info); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 4899 | WindowManagerGlobal.getInstance().reportNewConfiguration(mConfiguration); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4900 | } |
| 4901 | |
Andrii Kulian | e55b009 | 2018-04-19 15:29:22 -0700 | [diff] [blame] | 4902 | private void deliverResults(ActivityClientRecord r, List<ResultInfo> results, String reason) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4903 | final int N = results.size(); |
| 4904 | for (int i=0; i<N; i++) { |
| 4905 | ResultInfo ri = results.get(i); |
| 4906 | try { |
| 4907 | if (ri.mData != null) { |
| 4908 | ri.mData.setExtrasClassLoader(r.activity.getClassLoader()); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 4909 | ri.mData.prepareToEnterProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4910 | } |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4911 | if (DEBUG_RESULTS) Slog.v(TAG, |
Chris Tate | 8a7dc17 | 2009-03-24 20:11:42 -0700 | [diff] [blame] | 4912 | "Delivering result to activity " + r + " : " + ri); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4913 | r.activity.dispatchActivityResult(ri.mResultWho, |
Andrii Kulian | e55b009 | 2018-04-19 15:29:22 -0700 | [diff] [blame] | 4914 | ri.mRequestCode, ri.mResultCode, ri.mData, reason); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4915 | } catch (Exception e) { |
| 4916 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4917 | throw new RuntimeException( |
| 4918 | "Failure delivering result " + ri + " to activity " |
| 4919 | + r.intent.getComponent().toShortString() |
| 4920 | + ": " + e.toString(), e); |
| 4921 | } |
| 4922 | } |
| 4923 | } |
| 4924 | } |
| 4925 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 4926 | @Override |
Andrii Kulian | e55b009 | 2018-04-19 15:29:22 -0700 | [diff] [blame] | 4927 | public void handleSendResult(IBinder token, List<ResultInfo> results, String reason) { |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 4928 | ActivityClientRecord r = mActivities.get(token); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4929 | 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] | 4930 | if (r != null) { |
| 4931 | final boolean resumed = !r.paused; |
| 4932 | if (!r.activity.mFinished && r.activity.mDecor != null |
| 4933 | && r.hideForNow && resumed) { |
| 4934 | // We had hidden the activity because it started another |
| 4935 | // one... we have gotten a result back and we are not |
| 4936 | // paused, so make sure our window is visible. |
| 4937 | updateVisibility(r, true); |
| 4938 | } |
| 4939 | if (resumed) { |
| 4940 | try { |
| 4941 | // Now we are idle. |
| 4942 | r.activity.mCalled = false; |
| 4943 | mInstrumentation.callActivityOnPause(r.activity); |
| 4944 | if (!r.activity.mCalled) { |
| 4945 | throw new SuperNotCalledException( |
| 4946 | "Activity " + r.intent.getComponent().toShortString() |
| 4947 | + " did not call through to super.onPause()"); |
| 4948 | } |
| 4949 | } catch (SuperNotCalledException e) { |
| 4950 | throw e; |
| 4951 | } catch (Exception e) { |
| 4952 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4953 | throw new RuntimeException( |
| 4954 | "Unable to pause activity " |
| 4955 | + r.intent.getComponent().toShortString() |
| 4956 | + ": " + e.toString(), e); |
| 4957 | } |
| 4958 | } |
| 4959 | } |
Sudheer Shanka | 43b5ea4 | 2017-06-21 11:24:53 -0700 | [diff] [blame] | 4960 | checkAndBlockForNetworkAccess(); |
Andrii Kulian | e55b009 | 2018-04-19 15:29:22 -0700 | [diff] [blame] | 4961 | deliverResults(r, results, reason); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4962 | if (resumed) { |
Andrii Kulian | e55b009 | 2018-04-19 15:29:22 -0700 | [diff] [blame] | 4963 | r.activity.performResume(false, reason); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4964 | } |
| 4965 | } |
| 4966 | } |
| 4967 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4968 | /** Core implementation of activity destroy call. */ |
| 4969 | ActivityClientRecord performDestroyActivity(IBinder token, boolean finishing, |
Bryce Lee | a33c13d | 2018-02-08 14:37:06 -0800 | [diff] [blame] | 4970 | int configChanges, boolean getNonConfigInstance, String reason) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4971 | ActivityClientRecord r = mActivities.get(token); |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4972 | Class<? extends Activity> activityClass = null; |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4973 | if (localLOGV) Slog.v(TAG, "Performing finish of " + r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4974 | if (r != null) { |
Brad Fitzpatrick | 5f8b5c1 | 2011-01-20 15:12:08 -0800 | [diff] [blame] | 4975 | activityClass = r.activity.getClass(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4976 | r.activity.mConfigChangeFlags |= configChanges; |
| 4977 | if (finishing) { |
| 4978 | r.activity.mFinished = true; |
| 4979 | } |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 4980 | |
| 4981 | performPauseActivityIfNeeded(r, "destroy"); |
| 4982 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4983 | if (!r.stopped) { |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 4984 | callActivityOnStop(r, false /* saveState */, "destroy"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4985 | } |
| 4986 | if (getNonConfigInstance) { |
| 4987 | try { |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 4988 | r.lastNonConfigurationInstances |
| 4989 | = r.activity.retainNonConfigurationInstances(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4990 | } catch (Exception e) { |
| 4991 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4992 | throw new RuntimeException( |
| 4993 | "Unable to retain activity " |
| 4994 | + r.intent.getComponent().toShortString() |
| 4995 | + ": " + e.toString(), e); |
| 4996 | } |
| 4997 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4998 | } |
| 4999 | try { |
| 5000 | r.activity.mCalled = false; |
Dianne Hackborn | 2dedce6 | 2010-04-15 14:45:25 -0700 | [diff] [blame] | 5001 | mInstrumentation.callActivityOnDestroy(r.activity); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5002 | if (!r.activity.mCalled) { |
| 5003 | throw new SuperNotCalledException( |
Mitsuru Oshima | d9aef73 | 2009-06-16 20:20:50 -0700 | [diff] [blame] | 5004 | "Activity " + safeToComponentShortString(r.intent) + |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5005 | " did not call through to super.onDestroy()"); |
| 5006 | } |
| 5007 | if (r.window != null) { |
| 5008 | r.window.closeAllPanels(); |
| 5009 | } |
| 5010 | } catch (SuperNotCalledException e) { |
| 5011 | throw e; |
| 5012 | } catch (Exception e) { |
| 5013 | if (!mInstrumentation.onException(r.activity, e)) { |
| 5014 | throw new RuntimeException( |
Mitsuru Oshima | d9aef73 | 2009-06-16 20:20:50 -0700 | [diff] [blame] | 5015 | "Unable to destroy activity " + safeToComponentShortString(r.intent) |
| 5016 | + ": " + e.toString(), e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5017 | } |
| 5018 | } |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 5019 | r.setState(ON_DESTROY); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5020 | } |
Tim Murray | 59f3dc1 | 2018-10-22 15:26:08 -0700 | [diff] [blame] | 5021 | schedulePurgeIdler(); |
Garfield Tan | 0443b37 | 2019-01-04 15:00:13 -0800 | [diff] [blame] | 5022 | // updatePendingActivityConfiguration() reads from mActivities to update |
| 5023 | // ActivityClientRecord which runs in a different thread. Protect modifications to |
| 5024 | // mActivities to avoid race. |
| 5025 | synchronized (mResourcesManager) { |
| 5026 | mActivities.remove(token); |
| 5027 | } |
Brad Fitzpatrick | 5f8b5c1 | 2011-01-20 15:12:08 -0800 | [diff] [blame] | 5028 | StrictMode.decrementExpectedActivityCount(activityClass); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5029 | return r; |
| 5030 | } |
| 5031 | |
Mitsuru Oshima | d9aef73 | 2009-06-16 20:20:50 -0700 | [diff] [blame] | 5032 | private static String safeToComponentShortString(Intent intent) { |
| 5033 | ComponentName component = intent.getComponent(); |
| 5034 | return component == null ? "[Unknown]" : component.toShortString(); |
| 5035 | } |
| 5036 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 5037 | @Override |
Riddle Hsu | d3062cb | 2018-06-30 02:06:42 +0800 | [diff] [blame] | 5038 | public Map<IBinder, ClientTransactionItem> getActivitiesToBeDestroyed() { |
| 5039 | return mActivitiesToBeDestroyed; |
| 5040 | } |
| 5041 | |
| 5042 | @Override |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 5043 | public void handleDestroyActivity(IBinder token, boolean finishing, int configChanges, |
Bryce Lee | a33c13d | 2018-02-08 14:37:06 -0800 | [diff] [blame] | 5044 | boolean getNonConfigInstance, String reason) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 5045 | ActivityClientRecord r = performDestroyActivity(token, finishing, |
Bryce Lee | a33c13d | 2018-02-08 14:37:06 -0800 | [diff] [blame] | 5046 | configChanges, getNonConfigInstance, reason); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5047 | if (r != null) { |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 5048 | cleanUpPendingRemoveWindows(r, finishing); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5049 | WindowManager wm = r.activity.getWindowManager(); |
| 5050 | View v = r.activity.mDecor; |
| 5051 | if (v != null) { |
| 5052 | if (r.activity.mVisibleFromServer) { |
| 5053 | mNumVisibleActivities--; |
| 5054 | } |
| 5055 | IBinder wtoken = v.getWindowToken(); |
| 5056 | if (r.activity.mWindowAdded) { |
Robert Carr | 77bdfb5 | 2016-05-02 18:18:31 -0700 | [diff] [blame] | 5057 | if (r.mPreserveWindow) { |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 5058 | // Hold off on removing this until the new activity's |
| 5059 | // window is being added. |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 5060 | r.mPendingRemoveWindow = r.window; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 5061 | r.mPendingRemoveWindowManager = wm; |
Andrii Kulian | eac0ea5 | 2016-05-11 15:50:24 -0700 | [diff] [blame] | 5062 | // We can only keep the part of the view hierarchy that we control, |
| 5063 | // everything else must be removed, because it might not be able to |
| 5064 | // behave properly when activity is relaunching. |
| 5065 | r.window.clearContentView(); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 5066 | } else { |
| 5067 | wm.removeViewImmediate(v); |
| 5068 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5069 | } |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 5070 | if (wtoken != null && r.mPendingRemoveWindow == null) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 5071 | WindowManagerGlobal.getInstance().closeAll(wtoken, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5072 | r.activity.getClass().getName(), "Activity"); |
Andrii Kulian | eac0ea5 | 2016-05-11 15:50:24 -0700 | [diff] [blame] | 5073 | } else if (r.mPendingRemoveWindow != null) { |
| 5074 | // We're preserving only one window, others should be closed so app views |
| 5075 | // will be detached before the final tear down. It should be done now because |
| 5076 | // some components (e.g. WebView) rely on detach callbacks to perform receiver |
| 5077 | // unregister and other cleanup. |
| 5078 | WindowManagerGlobal.getInstance().closeAllExceptView(token, v, |
| 5079 | r.activity.getClass().getName(), "Activity"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5080 | } |
| 5081 | r.activity.mDecor = null; |
| 5082 | } |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 5083 | if (r.mPendingRemoveWindow == null) { |
| 5084 | // If we are delaying the removal of the activity window, then |
| 5085 | // we can't clean up all windows here. Note that we can't do |
| 5086 | // so later either, which means any windows that aren't closed |
| 5087 | // by the app will leak. Well we try to warning them a lot |
| 5088 | // about leaking windows, because that is a bug, so if they are |
| 5089 | // using this recreate facility then they get to live with leaks. |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 5090 | WindowManagerGlobal.getInstance().closeAll(token, |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 5091 | r.activity.getClass().getName(), "Activity"); |
| 5092 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5093 | |
| 5094 | // Mocked out contexts won't be participating in the normal |
| 5095 | // process lifecycle, but if we're running with a proper |
| 5096 | // ApplicationContext we need to have it tear down things |
| 5097 | // cleanly. |
| 5098 | Context c = r.activity.getBaseContext(); |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 5099 | if (c instanceof ContextImpl) { |
| 5100 | ((ContextImpl) c).scheduleFinalCleanup( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5101 | r.activity.getClass().getName(), "Activity"); |
| 5102 | } |
| 5103 | } |
| 5104 | if (finishing) { |
| 5105 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 5106 | ActivityTaskManager.getService().activityDestroyed(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5107 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5108 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5109 | } |
| 5110 | } |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 5111 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5112 | } |
| 5113 | |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 5114 | @Override |
| 5115 | public ActivityClientRecord prepareRelaunchActivity(IBinder token, |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 5116 | List<ResultInfo> pendingResults, List<ReferrerIntent> pendingNewIntents, |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 5117 | int configChanges, MergedConfiguration config, boolean preserveWindow) { |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 5118 | ActivityClientRecord target = null; |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 5119 | boolean scheduleRelaunch = false; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 5120 | |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 5121 | synchronized (mResourcesManager) { |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 5122 | for (int i=0; i<mRelaunchingActivities.size(); i++) { |
| 5123 | ActivityClientRecord r = mRelaunchingActivities.get(i); |
Filip Gruszczynski | c3b6179 | 2016-01-22 16:43:48 -0800 | [diff] [blame] | 5124 | if (DEBUG_ORDER) Slog.d(TAG, "requestRelaunchActivity: " + this + ", trying: " + r); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 5125 | if (r.token == token) { |
| 5126 | target = r; |
| 5127 | if (pendingResults != null) { |
| 5128 | if (r.pendingResults != null) { |
| 5129 | r.pendingResults.addAll(pendingResults); |
| 5130 | } else { |
| 5131 | r.pendingResults = pendingResults; |
| 5132 | } |
| 5133 | } |
| 5134 | if (pendingNewIntents != null) { |
| 5135 | if (r.pendingIntents != null) { |
| 5136 | r.pendingIntents.addAll(pendingNewIntents); |
| 5137 | } else { |
| 5138 | r.pendingIntents = pendingNewIntents; |
| 5139 | } |
| 5140 | } |
| 5141 | break; |
| 5142 | } |
| 5143 | } |
| 5144 | |
| 5145 | if (target == null) { |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 5146 | if (DEBUG_ORDER) Slog.d(TAG, "requestRelaunchActivity: target is null"); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 5147 | target = new ActivityClientRecord(); |
| 5148 | target.token = token; |
| 5149 | target.pendingResults = pendingResults; |
| 5150 | target.pendingIntents = pendingNewIntents; |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 5151 | target.mPreserveWindow = preserveWindow; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 5152 | mRelaunchingActivities.add(target); |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 5153 | scheduleRelaunch = true; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 5154 | } |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 5155 | target.createdConfig = config.getGlobalConfiguration(); |
| 5156 | target.overrideConfig = config.getOverrideConfiguration(); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 5157 | target.pendingConfigChanges |= configChanges; |
| 5158 | } |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 5159 | |
| 5160 | return scheduleRelaunch ? target : null; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 5161 | } |
| 5162 | |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 5163 | @Override |
| 5164 | public void handleRelaunchActivity(ActivityClientRecord tmp, |
| 5165 | PendingTransactionActions pendingActions) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5166 | // If we are getting ready to gc after going to the background, well |
| 5167 | // we are back active so skip it. |
| 5168 | unscheduleGcIdler(); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 5169 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5170 | |
| 5171 | Configuration changedConfig = null; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 5172 | int configChanges = 0; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 5173 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5174 | // First: make sure we have the most recent configuration and most |
| 5175 | // recent version of the activity, or skip it if some previous call |
| 5176 | // had taken a more recent version. |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 5177 | synchronized (mResourcesManager) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5178 | int N = mRelaunchingActivities.size(); |
| 5179 | IBinder token = tmp.token; |
| 5180 | tmp = null; |
| 5181 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 5182 | ActivityClientRecord r = mRelaunchingActivities.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5183 | if (r.token == token) { |
| 5184 | tmp = r; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 5185 | configChanges |= tmp.pendingConfigChanges; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5186 | mRelaunchingActivities.remove(i); |
| 5187 | i--; |
| 5188 | N--; |
| 5189 | } |
| 5190 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 5191 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5192 | if (tmp == null) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 5193 | 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] | 5194 | return; |
| 5195 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 5196 | |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 5197 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Relaunching activity " |
| 5198 | + tmp.token + " with configChanges=0x" |
| 5199 | + Integer.toHexString(configChanges)); |
| 5200 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5201 | if (mPendingConfiguration != null) { |
| 5202 | changedConfig = mPendingConfiguration; |
| 5203 | mPendingConfiguration = null; |
| 5204 | } |
| 5205 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 5206 | |
Dianne Hackborn | 871ecdc | 2009-12-11 15:24:33 -0800 | [diff] [blame] | 5207 | if (tmp.createdConfig != null) { |
| 5208 | // If the activity manager is passing us its current config, |
| 5209 | // assume that is really what we want regardless of what we |
| 5210 | // may have pending. |
| 5211 | if (mConfiguration == null |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5212 | || (tmp.createdConfig.isOtherSeqNewer(mConfiguration) |
| 5213 | && mConfiguration.diff(tmp.createdConfig) != 0)) { |
| 5214 | if (changedConfig == null |
| 5215 | || tmp.createdConfig.isOtherSeqNewer(changedConfig)) { |
| 5216 | changedConfig = tmp.createdConfig; |
| 5217 | } |
Dianne Hackborn | 871ecdc | 2009-12-11 15:24:33 -0800 | [diff] [blame] | 5218 | } |
| 5219 | } |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 5220 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 5221 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Relaunching activity " |
Dianne Hackborn | dc6b635 | 2009-09-30 14:20:09 -0700 | [diff] [blame] | 5222 | + tmp.token + ": changedConfig=" + changedConfig); |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 5223 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5224 | // If there was a pending configuration change, execute it first. |
| 5225 | if (changedConfig != null) { |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 5226 | mCurDefaultDisplayDpi = changedConfig.densityDpi; |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 5227 | updateDefaultDensity(); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 5228 | handleConfigurationChanged(changedConfig, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5229 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 5230 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 5231 | ActivityClientRecord r = mActivities.get(tmp.token); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 5232 | 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] | 5233 | if (r == null) { |
| 5234 | return; |
| 5235 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 5236 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5237 | r.activity.mConfigChangeFlags |= configChanges; |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 5238 | r.mPreserveWindow = tmp.mPreserveWindow; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 5239 | |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5240 | r.activity.mChangingConfigurations = true; |
| 5241 | |
Robert Carr | 23fa16b | 2016-01-13 13:19:58 -0800 | [diff] [blame] | 5242 | // If we are preserving the main window across relaunches we would also like to preserve |
| 5243 | // the children. However the client side view system does not support preserving |
| 5244 | // the child views so we notify the window manager to expect these windows to |
| 5245 | // be replaced and defer requests to destroy or hide them. This way we can achieve |
| 5246 | // visual continuity. It's important that we do this here prior to pause and destroy |
| 5247 | // as that is when we may hide or remove the child views. |
Robert Carr | 77bdfb5 | 2016-05-02 18:18:31 -0700 | [diff] [blame] | 5248 | // |
| 5249 | // There is another scenario, if we have decided locally to relaunch the app from a |
| 5250 | // call to recreate, then none of the windows will be prepared for replacement or |
| 5251 | // preserved by the server, so we want to notify it that we are preparing to replace |
| 5252 | // everything |
Robert Carr | 23fa16b | 2016-01-13 13:19:58 -0800 | [diff] [blame] | 5253 | try { |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 5254 | if (r.mPreserveWindow) { |
Robert Carr | 77bdfb5 | 2016-05-02 18:18:31 -0700 | [diff] [blame] | 5255 | WindowManagerGlobal.getWindowSession().prepareToReplaceWindows( |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 5256 | r.token, true /* childrenOnly */); |
Robert Carr | 23fa16b | 2016-01-13 13:19:58 -0800 | [diff] [blame] | 5257 | } |
| 5258 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5259 | throw e.rethrowFromSystemServer(); |
Robert Carr | 23fa16b | 2016-01-13 13:19:58 -0800 | [diff] [blame] | 5260 | } |
| 5261 | |
Wale Ogunwale | 5527a50 | 2018-02-20 18:18:21 -0800 | [diff] [blame] | 5262 | handleRelaunchActivityInner(r, configChanges, tmp.pendingResults, tmp.pendingIntents, |
| 5263 | pendingActions, tmp.startsNotResumed, tmp.overrideConfig, "handleRelaunchActivity"); |
| 5264 | |
| 5265 | if (pendingActions != null) { |
| 5266 | // Only report a successful relaunch to WindowManager. |
| 5267 | pendingActions.setReportRelaunchToWindowManager(true); |
Dianne Hackborn | e2b0480 | 2010-12-09 09:24:55 -0800 | [diff] [blame] | 5268 | } |
Wale Ogunwale | 5527a50 | 2018-02-20 18:18:21 -0800 | [diff] [blame] | 5269 | } |
| 5270 | |
Andrii Kulian | 320e3b5 | 2018-05-03 16:26:25 -0700 | [diff] [blame] | 5271 | /** |
| 5272 | * Post a message to relaunch the activity. We do this instead of launching it immediately, |
| 5273 | * because this will destroy the activity from which it was called and interfere with the |
| 5274 | * lifecycle changes it was going through before. We need to make sure that we have finished |
| 5275 | * handling current transaction item before relaunching the activity. |
| 5276 | */ |
| 5277 | void scheduleRelaunchActivity(IBinder token) { |
Amin Shaikh | 96e60d7 | 2019-04-24 13:47:57 -0400 | [diff] [blame] | 5278 | mH.removeMessages(H.RELAUNCH_ACTIVITY, token); |
Andrii Kulian | 320e3b5 | 2018-05-03 16:26:25 -0700 | [diff] [blame] | 5279 | sendMessage(H.RELAUNCH_ACTIVITY, token); |
| 5280 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 5281 | |
Andrii Kulian | 320e3b5 | 2018-05-03 16:26:25 -0700 | [diff] [blame] | 5282 | /** Performs the activity relaunch locally vs. requesting from system-server. */ |
| 5283 | private void handleRelaunchActivityLocally(IBinder token) { |
Wale Ogunwale | 5527a50 | 2018-02-20 18:18:21 -0800 | [diff] [blame] | 5284 | final ActivityClientRecord r = mActivities.get(token); |
| 5285 | if (r == null) { |
Andrii Kulian | 320e3b5 | 2018-05-03 16:26:25 -0700 | [diff] [blame] | 5286 | Log.w(TAG, "Activity to relaunch no longer exists"); |
Wale Ogunwale | 5527a50 | 2018-02-20 18:18:21 -0800 | [diff] [blame] | 5287 | return; |
| 5288 | } |
| 5289 | |
| 5290 | final int prevState = r.getLifecycleState(); |
| 5291 | |
Andrii Kulian | 320e3b5 | 2018-05-03 16:26:25 -0700 | [diff] [blame] | 5292 | if (prevState < ON_RESUME || prevState > ON_STOP) { |
| 5293 | Log.w(TAG, "Activity state must be in [ON_RESUME..ON_STOP] in order to be relaunched," |
| 5294 | + "current state is " + prevState); |
Wale Ogunwale | 5527a50 | 2018-02-20 18:18:21 -0800 | [diff] [blame] | 5295 | return; |
| 5296 | } |
| 5297 | |
Wale Ogunwale | 5527a50 | 2018-02-20 18:18:21 -0800 | [diff] [blame] | 5298 | |
Andrii Kulian | 914aa7d | 2018-03-19 21:51:53 -0700 | [diff] [blame] | 5299 | // Initialize a relaunch request. |
| 5300 | final MergedConfiguration mergedConfiguration = new MergedConfiguration( |
| 5301 | r.createdConfig != null ? r.createdConfig : mConfiguration, |
| 5302 | r.overrideConfig); |
| 5303 | final ActivityRelaunchItem activityRelaunchItem = ActivityRelaunchItem.obtain( |
| 5304 | null /* pendingResults */, null /* pendingIntents */, 0 /* configChanges */, |
| 5305 | mergedConfiguration, r.mPreserveWindow); |
| 5306 | // Make sure to match the existing lifecycle state in the end of the transaction. |
| 5307 | final ActivityLifecycleItem lifecycleRequest = |
| 5308 | TransactionExecutorHelper.getLifecycleRequestForCurrentState(r); |
| 5309 | // Schedule the transaction. |
| 5310 | final ClientTransaction transaction = ClientTransaction.obtain(this.mAppThread, r.token); |
| 5311 | transaction.addCallback(activityRelaunchItem); |
| 5312 | transaction.setLifecycleStateRequest(lifecycleRequest); |
| 5313 | executeTransaction(transaction); |
Wale Ogunwale | 5527a50 | 2018-02-20 18:18:21 -0800 | [diff] [blame] | 5314 | } |
| 5315 | |
| 5316 | private void handleRelaunchActivityInner(ActivityClientRecord r, int configChanges, |
| 5317 | List<ResultInfo> pendingResults, List<ReferrerIntent> pendingIntents, |
| 5318 | PendingTransactionActions pendingActions, boolean startsNotResumed, |
| 5319 | Configuration overrideConfig, String reason) { |
Andrii Kulian | 770c403 | 2018-05-02 18:40:59 -0700 | [diff] [blame] | 5320 | // Preserve last used intent, it may be set from Activity#setIntent(). |
| 5321 | final Intent customIntent = r.activity.mIntent; |
Wale Ogunwale | 5527a50 | 2018-02-20 18:18:21 -0800 | [diff] [blame] | 5322 | // Need to ensure state is saved. |
| 5323 | if (!r.paused) { |
| 5324 | performPauseActivity(r, false, reason, null /* pendingActions */); |
| 5325 | } |
| 5326 | if (!r.stopped) { |
| 5327 | callActivityOnStop(r, true /* saveState */, reason); |
| 5328 | } |
| 5329 | |
| 5330 | handleDestroyActivity(r.token, false, configChanges, true, reason); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 5331 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5332 | r.activity = null; |
| 5333 | r.window = null; |
| 5334 | r.hideForNow = false; |
| 5335 | r.nextIdle = null; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5336 | // Merge any pending results and pending intents; don't just replace them |
Wale Ogunwale | 5527a50 | 2018-02-20 18:18:21 -0800 | [diff] [blame] | 5337 | if (pendingResults != null) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5338 | if (r.pendingResults == null) { |
Wale Ogunwale | 5527a50 | 2018-02-20 18:18:21 -0800 | [diff] [blame] | 5339 | r.pendingResults = pendingResults; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5340 | } else { |
Wale Ogunwale | 5527a50 | 2018-02-20 18:18:21 -0800 | [diff] [blame] | 5341 | r.pendingResults.addAll(pendingResults); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5342 | } |
| 5343 | } |
Wale Ogunwale | 5527a50 | 2018-02-20 18:18:21 -0800 | [diff] [blame] | 5344 | if (pendingIntents != null) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5345 | if (r.pendingIntents == null) { |
Wale Ogunwale | 5527a50 | 2018-02-20 18:18:21 -0800 | [diff] [blame] | 5346 | r.pendingIntents = pendingIntents; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5347 | } else { |
Wale Ogunwale | 5527a50 | 2018-02-20 18:18:21 -0800 | [diff] [blame] | 5348 | r.pendingIntents.addAll(pendingIntents); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5349 | } |
| 5350 | } |
Wale Ogunwale | 5527a50 | 2018-02-20 18:18:21 -0800 | [diff] [blame] | 5351 | r.startsNotResumed = startsNotResumed; |
| 5352 | r.overrideConfig = overrideConfig; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 5353 | |
Andrii Kulian | 770c403 | 2018-05-02 18:40:59 -0700 | [diff] [blame] | 5354 | handleLaunchActivity(r, pendingActions, customIntent); |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 5355 | } |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 5356 | |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 5357 | @Override |
| 5358 | public void reportRelaunch(IBinder token, PendingTransactionActions pendingActions) { |
| 5359 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 5360 | ActivityTaskManager.getService().activityRelaunched(token); |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 5361 | final ActivityClientRecord r = mActivities.get(token); |
| 5362 | if (pendingActions.shouldReportRelaunchToWindowManager() && r != null |
| 5363 | && r.window != null) { |
| 5364 | r.window.reportActivityRelaunched(); |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 5365 | } |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 5366 | } catch (RemoteException e) { |
| 5367 | throw e.rethrowFromSystemServer(); |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 5368 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5369 | } |
| 5370 | |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 5371 | private void callActivityOnSaveInstanceState(ActivityClientRecord r) { |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 5372 | r.state = new Bundle(); |
| 5373 | r.state.setAllowFds(false); |
| 5374 | if (r.isPersistable()) { |
| 5375 | r.persistentState = new PersistableBundle(); |
| 5376 | mInstrumentation.callActivityOnSaveInstanceState(r.activity, r.state, |
| 5377 | r.persistentState); |
| 5378 | } else { |
| 5379 | mInstrumentation.callActivityOnSaveInstanceState(r.activity, r.state); |
| 5380 | } |
| 5381 | } |
| 5382 | |
Dianne Hackborn | 73c1416 | 2012-09-19 15:45:06 -0700 | [diff] [blame] | 5383 | ArrayList<ComponentCallbacks2> collectComponentCallbacks( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5384 | boolean allActivities, Configuration newConfig) { |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 5385 | ArrayList<ComponentCallbacks2> callbacks |
| 5386 | = new ArrayList<ComponentCallbacks2>(); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 5387 | |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 5388 | synchronized (mResourcesManager) { |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 5389 | final int NAPP = mAllApplications.size(); |
| 5390 | for (int i=0; i<NAPP; i++) { |
Dianne Hackborn | 73c1416 | 2012-09-19 15:45:06 -0700 | [diff] [blame] | 5391 | callbacks.add(mAllApplications.get(i)); |
| 5392 | } |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 5393 | final int NACT = mActivities.size(); |
| 5394 | for (int i=0; i<NACT; i++) { |
| 5395 | ActivityClientRecord ar = mActivities.valueAt(i); |
| 5396 | Activity a = ar.activity; |
| 5397 | if (a != null) { |
| 5398 | Configuration thisConfig = applyConfigCompatMainThread( |
| 5399 | mCurDefaultDisplayDpi, newConfig, |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5400 | ar.packageInfo.getCompatibilityInfo()); |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 5401 | if (!ar.activity.mFinished && (allActivities || !ar.paused)) { |
| 5402 | // If the activity is currently resumed, its configuration |
| 5403 | // needs to change right now. |
| 5404 | callbacks.add(a); |
| 5405 | } else if (thisConfig != null) { |
| 5406 | // Otherwise, we will tell it about the change |
| 5407 | // the next time it is resumed or shown. Note that |
| 5408 | // the activity manager may, before then, decide the |
| 5409 | // activity needs to be destroyed to handle its new |
| 5410 | // configuration. |
| 5411 | if (DEBUG_CONFIGURATION) { |
| 5412 | Slog.v(TAG, "Setting activity " |
| 5413 | + ar.activityInfo.name + " newConfig=" + thisConfig); |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 5414 | } |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 5415 | ar.newConfig = thisConfig; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5416 | } |
| 5417 | } |
| 5418 | } |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 5419 | final int NSVC = mServices.size(); |
| 5420 | for (int i=0; i<NSVC; i++) { |
lumark | ddc77fb | 2019-06-27 22:22:23 +0800 | [diff] [blame] | 5421 | final ComponentCallbacks2 serviceComp = mServices.valueAt(i); |
| 5422 | if (serviceComp instanceof InputMethodService) { |
| 5423 | mHasImeComponent = true; |
| 5424 | } |
| 5425 | callbacks.add(serviceComp); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5426 | } |
| 5427 | } |
| 5428 | synchronized (mProviderMap) { |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 5429 | final int NPRV = mLocalProviders.size(); |
| 5430 | for (int i=0; i<NPRV; i++) { |
| 5431 | callbacks.add(mLocalProviders.valueAt(i).mLocalProvider); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5432 | } |
| 5433 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 5434 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5435 | return callbacks; |
| 5436 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 5437 | |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 5438 | /** |
| 5439 | * Updates the configuration for an Activity. The ActivityClientRecord's |
| 5440 | * {@link ActivityClientRecord#overrideConfig} is used to compute the final Configuration for |
| 5441 | * that Activity. {@link ActivityClientRecord#tmpConfig} is used as a temporary for delivering |
| 5442 | * the updated Configuration. |
| 5443 | * @param r ActivityClientRecord representing the Activity. |
| 5444 | * @param newBaseConfig The new configuration to use. This may be augmented with |
| 5445 | * {@link ActivityClientRecord#overrideConfig}. |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 5446 | */ |
| 5447 | private void performConfigurationChangedForActivity(ActivityClientRecord r, |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5448 | Configuration newBaseConfig) { |
| 5449 | performConfigurationChangedForActivity(r, newBaseConfig, |
Yohei Yukawa | 5281b6b | 2018-10-15 07:38:25 +0800 | [diff] [blame] | 5450 | r.activity.getDisplayId(), false /* movedToDifferentDisplay */); |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5451 | } |
| 5452 | |
| 5453 | /** |
| 5454 | * Updates the configuration for an Activity. The ActivityClientRecord's |
| 5455 | * {@link ActivityClientRecord#overrideConfig} is used to compute the final Configuration for |
| 5456 | * that Activity. {@link ActivityClientRecord#tmpConfig} is used as a temporary for delivering |
| 5457 | * the updated Configuration. |
| 5458 | * @param r ActivityClientRecord representing the Activity. |
| 5459 | * @param newBaseConfig The new configuration to use. This may be augmented with |
| 5460 | * {@link ActivityClientRecord#overrideConfig}. |
| 5461 | * @param displayId The id of the display where the Activity currently resides. |
| 5462 | * @param movedToDifferentDisplay Indicates if the activity was moved to different display. |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 5463 | * @return {@link Configuration} instance sent to client, null if not sent. |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5464 | */ |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 5465 | private Configuration performConfigurationChangedForActivity(ActivityClientRecord r, |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5466 | Configuration newBaseConfig, int displayId, boolean movedToDifferentDisplay) { |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 5467 | r.tmpConfig.setTo(newBaseConfig); |
| 5468 | if (r.overrideConfig != null) { |
| 5469 | r.tmpConfig.updateFrom(r.overrideConfig); |
| 5470 | } |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 5471 | final Configuration reportedConfig = performActivityConfigurationChanged(r.activity, |
| 5472 | r.tmpConfig, r.overrideConfig, displayId, movedToDifferentDisplay); |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 5473 | freeTextLayoutCachesIfNeeded(r.activity.mCurrentConfig.diff(r.tmpConfig)); |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 5474 | return reportedConfig; |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 5475 | } |
| 5476 | |
| 5477 | /** |
Adam Lesinski | c1b0ebf | 2016-06-09 11:17:10 -0700 | [diff] [blame] | 5478 | * Creates a new Configuration only if override would modify base. Otherwise returns base. |
| 5479 | * @param base The base configuration. |
| 5480 | * @param override The update to apply to the base configuration. Can be null. |
| 5481 | * @return A Configuration representing base with override applied. |
| 5482 | */ |
| 5483 | private static Configuration createNewConfigAndUpdateIfNotNull(@NonNull Configuration base, |
| 5484 | @Nullable Configuration override) { |
| 5485 | if (override == null) { |
| 5486 | return base; |
| 5487 | } |
| 5488 | Configuration newConfig = new Configuration(base); |
| 5489 | newConfig.updateFrom(override); |
| 5490 | return newConfig; |
| 5491 | } |
| 5492 | |
| 5493 | /** |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5494 | * 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] | 5495 | * @param cb The component callback to notify of configuration change. |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5496 | * @param newConfig The new configuration. |
| 5497 | */ |
| 5498 | private void performConfigurationChanged(ComponentCallbacks2 cb, Configuration newConfig) { |
| 5499 | if (!REPORT_TO_ACTIVITY) { |
| 5500 | return; |
| 5501 | } |
| 5502 | |
| 5503 | // ContextThemeWrappers may override the configuration for that context. We must check and |
| 5504 | // apply any overrides defined. |
| 5505 | Configuration contextThemeWrapperOverrideConfig = null; |
| 5506 | if (cb instanceof ContextThemeWrapper) { |
| 5507 | final ContextThemeWrapper contextThemeWrapper = (ContextThemeWrapper) cb; |
| 5508 | contextThemeWrapperOverrideConfig = contextThemeWrapper.getOverrideConfiguration(); |
| 5509 | } |
| 5510 | |
| 5511 | // Apply the ContextThemeWrapper override if necessary. |
| 5512 | // NOTE: Make sure the configurations are not modified, as they are treated as immutable |
| 5513 | // in many places. |
| 5514 | final Configuration configToReport = createNewConfigAndUpdateIfNotNull( |
| 5515 | newConfig, contextThemeWrapperOverrideConfig); |
| 5516 | cb.onConfigurationChanged(configToReport); |
| 5517 | } |
| 5518 | |
| 5519 | /** |
| 5520 | * Decides whether to update an Activity's configuration and whether to inform it. |
| 5521 | * @param activity The activity to notify of configuration change. |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 5522 | * @param newConfig The new configuration. |
Adam Lesinski | c1b0ebf | 2016-06-09 11:17:10 -0700 | [diff] [blame] | 5523 | * @param amOverrideConfig The override config that differentiates the Activity's configuration |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5524 | * from the base global configuration. This is supplied by |
| 5525 | * ActivityManager. |
| 5526 | * @param displayId Id of the display where activity currently resides. |
| 5527 | * @param movedToDifferentDisplay Indicates if the activity was moved to different display. |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 5528 | * @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] | 5529 | */ |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 5530 | private Configuration performActivityConfigurationChanged(Activity activity, |
| 5531 | Configuration newConfig, Configuration amOverrideConfig, int displayId, |
| 5532 | boolean movedToDifferentDisplay) { |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5533 | if (activity == null) { |
| 5534 | throw new IllegalArgumentException("No activity provided."); |
| 5535 | } |
| 5536 | final IBinder activityToken = activity.getActivityToken(); |
| 5537 | if (activityToken == null) { |
| 5538 | 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] | 5539 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 5540 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5541 | boolean shouldChangeConfig = false; |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5542 | if (activity.mCurrentConfig == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5543 | shouldChangeConfig = true; |
| 5544 | } else { |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5545 | // If the new config is the same as the config this Activity is already running with and |
| 5546 | // the override config also didn't change, then don't bother calling |
| 5547 | // onConfigurationChanged. |
Bryce Lee | 658d984 | 2017-07-28 08:33:36 -0700 | [diff] [blame] | 5548 | final int diff = activity.mCurrentConfig.diffPublicOnly(newConfig); |
| 5549 | |
Andrii Kulian | 3b3c914 | 2016-07-18 19:15:56 -0700 | [diff] [blame] | 5550 | if (diff != 0 || !mResourcesManager.isSameResourcesOverrideConfig(activityToken, |
| 5551 | amOverrideConfig)) { |
Chong Zhang | 4951f9d | 2016-06-23 13:15:08 -0700 | [diff] [blame] | 5552 | // Always send the task-level config changes. For system-level configuration, if |
| 5553 | // this activity doesn't handle any of the config changes, then don't bother |
| 5554 | // calling onConfigurationChanged as we're going to destroy it. |
| 5555 | if (!mUpdatingSystemConfig |
| 5556 | || (~activity.mActivityInfo.getRealConfigChanged() & diff) == 0 |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5557 | || !REPORT_TO_ACTIVITY) { |
Chong Zhang | 4951f9d | 2016-06-23 13:15:08 -0700 | [diff] [blame] | 5558 | shouldChangeConfig = true; |
| 5559 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5560 | } |
| 5561 | } |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5562 | if (!shouldChangeConfig && !movedToDifferentDisplay) { |
| 5563 | // Nothing significant, don't proceed with updating and reporting. |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 5564 | return null; |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5565 | } |
| 5566 | |
| 5567 | // Propagate the configuration change to ResourcesManager and Activity. |
| 5568 | |
| 5569 | // ContextThemeWrappers may override the configuration for that context. We must check and |
| 5570 | // apply any overrides defined. |
| 5571 | Configuration contextThemeWrapperOverrideConfig = activity.getOverrideConfiguration(); |
| 5572 | |
| 5573 | // We only update an Activity's configuration if this is not a global configuration change. |
| 5574 | // This must also be done before the callback, or else we violate the contract that the new |
| 5575 | // resources are available in ComponentCallbacks2#onConfigurationChanged(Configuration). |
| 5576 | // Also apply the ContextThemeWrapper override if necessary. |
| 5577 | // NOTE: Make sure the configurations are not modified, as they are treated as immutable in |
| 5578 | // many places. |
| 5579 | final Configuration finalOverrideConfig = createNewConfigAndUpdateIfNotNull( |
| 5580 | amOverrideConfig, contextThemeWrapperOverrideConfig); |
| 5581 | mResourcesManager.updateResourcesForActivity(activityToken, finalOverrideConfig, |
| 5582 | displayId, movedToDifferentDisplay); |
| 5583 | |
| 5584 | activity.mConfigChangeFlags = 0; |
| 5585 | activity.mCurrentConfig = new Configuration(newConfig); |
| 5586 | |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 5587 | // Apply the ContextThemeWrapper override if necessary. |
| 5588 | // NOTE: Make sure the configurations are not modified, as they are treated as immutable |
| 5589 | // in many places. |
| 5590 | final Configuration configToReport = createNewConfigAndUpdateIfNotNull(newConfig, |
| 5591 | contextThemeWrapperOverrideConfig); |
| 5592 | |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5593 | if (!REPORT_TO_ACTIVITY) { |
| 5594 | // Not configured to report to activity. |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 5595 | return configToReport; |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5596 | } |
| 5597 | |
| 5598 | if (movedToDifferentDisplay) { |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 5599 | activity.dispatchMovedToDisplay(displayId, configToReport); |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5600 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 5601 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5602 | if (shouldChangeConfig) { |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5603 | activity.mCalled = false; |
| 5604 | activity.onConfigurationChanged(configToReport); |
| 5605 | if (!activity.mCalled) { |
| 5606 | throw new SuperNotCalledException("Activity " + activity.getLocalClassName() + |
| 5607 | " did not call through to super.onConfigurationChanged()"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5608 | } |
| 5609 | } |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 5610 | |
| 5611 | return configToReport; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5612 | } |
| 5613 | |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 5614 | public final void applyConfigurationToResources(Configuration config) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 5615 | synchronized (mResourcesManager) { |
| 5616 | mResourcesManager.applyConfigurationToResourcesLocked(config, null); |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 5617 | } |
| 5618 | } |
| 5619 | |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 5620 | final Configuration applyCompatConfiguration(int displayDensity) { |
Dianne Hackborn | 836e262 | 2011-10-04 18:32:39 -0700 | [diff] [blame] | 5621 | Configuration config = mConfiguration; |
| 5622 | if (mCompatConfiguration == null) { |
| 5623 | mCompatConfiguration = new Configuration(); |
| 5624 | } |
| 5625 | mCompatConfiguration.setTo(mConfiguration); |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 5626 | if (mResourcesManager.applyCompatConfigurationLocked(displayDensity, |
| 5627 | mCompatConfiguration)) { |
Dianne Hackborn | 836e262 | 2011-10-04 18:32:39 -0700 | [diff] [blame] | 5628 | config = mCompatConfiguration; |
| 5629 | } |
| 5630 | return config; |
| 5631 | } |
| 5632 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 5633 | @Override |
| 5634 | public void handleConfigurationChanged(Configuration config) { |
| 5635 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "configChanged"); |
| 5636 | mCurDefaultDisplayDpi = config.densityDpi; |
| 5637 | mUpdatingSystemConfig = true; |
| 5638 | try { |
| 5639 | handleConfigurationChanged(config, null /* compat */); |
| 5640 | } finally { |
| 5641 | mUpdatingSystemConfig = false; |
| 5642 | } |
| 5643 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
| 5644 | } |
| 5645 | |
| 5646 | private void handleConfigurationChanged(Configuration config, CompatibilityInfo compat) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5647 | |
Tiger Huang | 968064b | 2019-05-28 14:36:18 +0800 | [diff] [blame] | 5648 | int configDiff; |
| 5649 | boolean equivalent; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5650 | |
Todd Kennedy | 35a9a38 | 2018-01-25 13:25:37 -0800 | [diff] [blame] | 5651 | final Theme systemTheme = getSystemContext().getTheme(); |
| 5652 | final Theme systemUiTheme = getSystemUiContext().getTheme(); |
Bryce Lee | 658d984 | 2017-07-28 08:33:36 -0700 | [diff] [blame] | 5653 | |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 5654 | synchronized (mResourcesManager) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5655 | if (mPendingConfiguration != null) { |
| 5656 | if (!mPendingConfiguration.isOtherSeqNewer(config)) { |
| 5657 | config = mPendingConfiguration; |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 5658 | mCurDefaultDisplayDpi = config.densityDpi; |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 5659 | updateDefaultDensity(); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5660 | } |
| 5661 | mPendingConfiguration = null; |
| 5662 | } |
| 5663 | |
| 5664 | if (config == null) { |
lumark | ddc77fb | 2019-06-27 22:22:23 +0800 | [diff] [blame] | 5665 | // TODO (b/135719017): Temporary log for debugging IME service. |
| 5666 | if (Build.IS_DEBUGGABLE && mHasImeComponent) { |
| 5667 | Log.w(TAG, "handleConfigurationChanged for IME app but config is null"); |
| 5668 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5669 | return; |
| 5670 | } |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 5671 | |
Tiger Huang | 968064b | 2019-05-28 14:36:18 +0800 | [diff] [blame] | 5672 | // This flag tracks whether the new configuration is fundamentally equivalent to the |
| 5673 | // existing configuration. This is necessary to determine whether non-activity callbacks |
| 5674 | // should receive notice when the only changes are related to non-public fields. |
| 5675 | // We do not gate calling {@link #performActivityConfigurationChanged} based on this |
| 5676 | // flag as that method uses the same check on the activity config override as well. |
| 5677 | equivalent = mConfiguration != null && (0 == mConfiguration.diffPublicOnly(config)); |
| 5678 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 5679 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Handle configuration changed: " |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5680 | + config); |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 5681 | |
| 5682 | mResourcesManager.applyConfigurationToResourcesLocked(config, compat); |
Adam Lesinski | b61e405 | 2016-05-19 18:23:05 -0700 | [diff] [blame] | 5683 | updateLocaleListFromAppContext(mInitialApplication.getApplicationContext(), |
| 5684 | mResourcesManager.getConfiguration().getLocales()); |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 5685 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5686 | if (mConfiguration == null) { |
| 5687 | mConfiguration = new Configuration(); |
| 5688 | } |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 5689 | if (!mConfiguration.isOtherSeqNewer(config) && compat == null) { |
lumark | ddc77fb | 2019-06-27 22:22:23 +0800 | [diff] [blame] | 5690 | // TODO (b/135719017): Temporary log for debugging IME service. |
| 5691 | if (Build.IS_DEBUGGABLE && mHasImeComponent) { |
| 5692 | Log.w(TAG, "handleConfigurationChanged for IME app but config seq is obsolete " |
| 5693 | + ", config=" + config |
| 5694 | + ", mConfiguration=" + mConfiguration); |
| 5695 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5696 | return; |
| 5697 | } |
Alan Viverette | e54d245 | 2015-05-06 10:41:43 -0700 | [diff] [blame] | 5698 | |
| 5699 | configDiff = mConfiguration.updateFrom(config); |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 5700 | config = applyCompatConfiguration(mCurDefaultDisplayDpi); |
Alan Viverette | 395cd01 | 2015-08-11 17:27:04 -0400 | [diff] [blame] | 5701 | |
Alan Viverette | 395cd01 | 2015-08-11 17:27:04 -0400 | [diff] [blame] | 5702 | if ((systemTheme.getChangingConfigurations() & configDiff) != 0) { |
| 5703 | systemTheme.rebase(); |
| 5704 | } |
Adam Lesinski | a82b626 | 2017-03-21 16:56:17 -0700 | [diff] [blame] | 5705 | |
Adam Lesinski | a82b626 | 2017-03-21 16:56:17 -0700 | [diff] [blame] | 5706 | if ((systemUiTheme.getChangingConfigurations() & configDiff) != 0) { |
| 5707 | systemUiTheme.rebase(); |
| 5708 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5709 | } |
Dianne Hackborn | 73c1416 | 2012-09-19 15:45:06 -0700 | [diff] [blame] | 5710 | |
| 5711 | ArrayList<ComponentCallbacks2> callbacks = collectComponentCallbacks(false, config); |
| 5712 | |
Fabrice Di Meglio | 30ca5cd | 2012-05-07 17:45:44 -0700 | [diff] [blame] | 5713 | freeTextLayoutCachesIfNeeded(configDiff); |
| 5714 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5715 | if (callbacks != null) { |
| 5716 | final int N = callbacks.size(); |
| 5717 | for (int i=0; i<N; i++) { |
Andrii Kulian | 701214b | 2016-04-07 09:36:33 -0700 | [diff] [blame] | 5718 | ComponentCallbacks2 cb = callbacks.get(i); |
| 5719 | if (cb instanceof Activity) { |
| 5720 | // If callback is an Activity - call corresponding method to consider override |
| 5721 | // config and avoid onConfigurationChanged if it hasn't changed. |
| 5722 | Activity a = (Activity) cb; |
| 5723 | performConfigurationChangedForActivity(mActivities.get(a.getActivityToken()), |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5724 | config); |
Bryce Lee | 658d984 | 2017-07-28 08:33:36 -0700 | [diff] [blame] | 5725 | } else if (!equivalent) { |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5726 | performConfigurationChanged(cb, config); |
lumark | ddc77fb | 2019-06-27 22:22:23 +0800 | [diff] [blame] | 5727 | } else { |
| 5728 | // TODO (b/135719017): Temporary log for debugging IME service. |
| 5729 | if (Build.IS_DEBUGGABLE && cb instanceof InputMethodService) { |
| 5730 | Log.w(TAG, "performConfigurationChanged didn't callback to IME " |
| 5731 | + ", configDiff=" + configDiff |
| 5732 | + ", mConfiguration=" + mConfiguration); |
| 5733 | } |
Andrii Kulian | 701214b | 2016-04-07 09:36:33 -0700 | [diff] [blame] | 5734 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5735 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5736 | } |
| 5737 | } |
| 5738 | |
Winson | 72dbe7e | 2019-04-29 14:55:30 -0700 | [diff] [blame] | 5739 | /** |
| 5740 | * Updates the application info. |
| 5741 | * |
| 5742 | * This only works in the system process. Must be called on the main thread. |
| 5743 | */ |
| 5744 | public void handleSystemApplicationInfoChanged(@NonNull ApplicationInfo ai) { |
| 5745 | Preconditions.checkState(mSystemThread, "Must only be called in the system process"); |
| 5746 | handleApplicationInfoChanged(ai); |
| 5747 | } |
| 5748 | |
Adrian Roos | 03dd48c | 2019-03-19 17:17:37 -0400 | [diff] [blame] | 5749 | @VisibleForTesting(visibility = PACKAGE) |
| 5750 | public void handleApplicationInfoChanged(@NonNull final ApplicationInfo ai) { |
Adam Lesinski | d33ef56 | 2017-01-19 14:49:59 -0800 | [diff] [blame] | 5751 | // Updates triggered by package installation go through a package update |
| 5752 | // receiver. Here we try to capture ApplicationInfo changes that are |
| 5753 | // caused by other sources, such as overlays. That means we want to be as conservative |
| 5754 | // about code changes as possible. Take the diff of the old ApplicationInfo and the new |
| 5755 | // to see if anything needs to change. |
Fyodor Kupolov | b7865ce | 2017-05-05 15:08:03 -0700 | [diff] [blame] | 5756 | LoadedApk apk; |
| 5757 | LoadedApk resApk; |
| 5758 | // Update all affected loaded packages with new package information |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 5759 | synchronized (mResourcesManager) { |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 5760 | WeakReference<LoadedApk> ref = mPackages.get(ai.packageName); |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 5761 | apk = ref != null ? ref.get() : null; |
Fyodor Kupolov | b7865ce | 2017-05-05 15:08:03 -0700 | [diff] [blame] | 5762 | ref = mResourcePackages.get(ai.packageName); |
| 5763 | resApk = ref != null ? ref.get() : null; |
| 5764 | } |
Winson | d605e2d | 2019-02-11 16:05:51 -0800 | [diff] [blame] | 5765 | |
| 5766 | final String[] oldResDirs = new String[2]; |
| 5767 | |
Fyodor Kupolov | b7865ce | 2017-05-05 15:08:03 -0700 | [diff] [blame] | 5768 | if (apk != null) { |
Winson | d605e2d | 2019-02-11 16:05:51 -0800 | [diff] [blame] | 5769 | oldResDirs[0] = apk.getResDir(); |
Fyodor Kupolov | b7865ce | 2017-05-05 15:08:03 -0700 | [diff] [blame] | 5770 | final ArrayList<String> oldPaths = new ArrayList<>(); |
| 5771 | LoadedApk.makePaths(this, apk.getApplicationInfo(), oldPaths); |
| 5772 | apk.updateApplicationInfo(ai, oldPaths); |
| 5773 | } |
| 5774 | if (resApk != null) { |
Winson | d605e2d | 2019-02-11 16:05:51 -0800 | [diff] [blame] | 5775 | oldResDirs[1] = resApk.getResDir(); |
Fyodor Kupolov | b7865ce | 2017-05-05 15:08:03 -0700 | [diff] [blame] | 5776 | final ArrayList<String> oldPaths = new ArrayList<>(); |
| 5777 | LoadedApk.makePaths(this, resApk.getApplicationInfo(), oldPaths); |
| 5778 | resApk.updateApplicationInfo(ai, oldPaths); |
| 5779 | } |
Winson | d605e2d | 2019-02-11 16:05:51 -0800 | [diff] [blame] | 5780 | |
Fyodor Kupolov | b7865ce | 2017-05-05 15:08:03 -0700 | [diff] [blame] | 5781 | synchronized (mResourcesManager) { |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 5782 | // Update all affected Resources objects to use new ResourcesImpl |
Winson | d605e2d | 2019-02-11 16:05:51 -0800 | [diff] [blame] | 5783 | mResourcesManager.applyNewResourceDirsLocked(ai, oldResDirs); |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 5784 | } |
| 5785 | |
| 5786 | ApplicationPackageManager.configurationChanged(); |
| 5787 | |
| 5788 | // Trigger a regular Configuration change event, only with a different assetsSeq number |
| 5789 | // so that we actually call through to all components. |
Adam Lesinski | a82b626 | 2017-03-21 16:56:17 -0700 | [diff] [blame] | 5790 | // TODO(adamlesinski): Change this to make use of ActivityManager's upcoming ability to |
| 5791 | // store configurations per-process. |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 5792 | Configuration newConfig = new Configuration(); |
Adam Lesinski | a82b626 | 2017-03-21 16:56:17 -0700 | [diff] [blame] | 5793 | newConfig.assetsSeq = (mConfiguration != null ? mConfiguration.assetsSeq : 0) + 1; |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 5794 | handleConfigurationChanged(newConfig, null); |
| 5795 | |
Adrian Roos | 03dd48c | 2019-03-19 17:17:37 -0400 | [diff] [blame] | 5796 | // Preserve windows to avoid black flickers when overlays change. |
| 5797 | relaunchAllActivities(true /* preserveWindows */); |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 5798 | } |
| 5799 | |
Romain Guy | 46bfc48 | 2013-08-16 18:38:29 -0700 | [diff] [blame] | 5800 | static void freeTextLayoutCachesIfNeeded(int configDiff) { |
Fabrice Di Meglio | 30ca5cd | 2012-05-07 17:45:44 -0700 | [diff] [blame] | 5801 | if (configDiff != 0) { |
| 5802 | // Ask text layout engine to free its caches if there is a locale change |
| 5803 | boolean hasLocaleConfigChange = ((configDiff & ActivityInfo.CONFIG_LOCALE) != 0); |
| 5804 | if (hasLocaleConfigChange) { |
| 5805 | Canvas.freeTextLayoutCaches(); |
| 5806 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Cleared TextLayout Caches"); |
| 5807 | } |
| 5808 | } |
| 5809 | } |
| 5810 | |
Garfield Tan | 0443b37 | 2019-01-04 15:00:13 -0800 | [diff] [blame] | 5811 | @Override |
| 5812 | public void updatePendingActivityConfiguration(IBinder activityToken, |
| 5813 | Configuration overrideConfig) { |
| 5814 | final ActivityClientRecord r; |
| 5815 | synchronized (mResourcesManager) { |
| 5816 | r = mActivities.get(activityToken); |
| 5817 | } |
| 5818 | |
| 5819 | if (r == null) { |
| 5820 | if (DEBUG_CONFIGURATION) { |
| 5821 | Slog.w(TAG, "Not found target activity to update its pending config."); |
| 5822 | } |
| 5823 | return; |
| 5824 | } |
| 5825 | |
| 5826 | synchronized (r) { |
| 5827 | r.mPendingOverrideConfig = overrideConfig; |
| 5828 | } |
| 5829 | } |
| 5830 | |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5831 | /** |
| 5832 | * Handle new activity configuration and/or move to a different display. |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 5833 | * @param activityToken Target activity token. |
| 5834 | * @param overrideConfig Activity override config. |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5835 | * @param displayId Id of the display where activity was moved to, -1 if there was no move and |
| 5836 | * value didn't change. |
| 5837 | */ |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 5838 | @Override |
| 5839 | public void handleActivityConfigurationChanged(IBinder activityToken, |
| 5840 | Configuration overrideConfig, int displayId) { |
| 5841 | ActivityClientRecord r = mActivities.get(activityToken); |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5842 | // Check input params. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5843 | if (r == null || r.activity == null) { |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5844 | 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] | 5845 | return; |
| 5846 | } |
Andrii Kulian | 51c1b67 | 2017-04-07 18:39:32 -0700 | [diff] [blame] | 5847 | final boolean movedToDifferentDisplay = displayId != INVALID_DISPLAY |
Yohei Yukawa | 5281b6b | 2018-10-15 07:38:25 +0800 | [diff] [blame] | 5848 | && displayId != r.activity.getDisplayId(); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 5849 | |
Garfield Tan | 0443b37 | 2019-01-04 15:00:13 -0800 | [diff] [blame] | 5850 | synchronized (r) { |
| 5851 | if (r.mPendingOverrideConfig != null |
| 5852 | && !r.mPendingOverrideConfig.isOtherSeqNewer(overrideConfig)) { |
| 5853 | overrideConfig = r.mPendingOverrideConfig; |
| 5854 | } |
| 5855 | r.mPendingOverrideConfig = null; |
| 5856 | } |
| 5857 | |
| 5858 | if (r.overrideConfig != null && !r.overrideConfig.isOtherSeqNewer(overrideConfig) |
| 5859 | && !movedToDifferentDisplay) { |
| 5860 | if (DEBUG_CONFIGURATION) { |
| 5861 | Slog.v(TAG, "Activity already handled newer configuration so drop this" |
| 5862 | + " transaction. overrideConfig=" + overrideConfig + " r.overrideConfig=" |
| 5863 | + r.overrideConfig); |
| 5864 | } |
| 5865 | return; |
| 5866 | } |
| 5867 | |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5868 | // Perform updates. |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 5869 | r.overrideConfig = overrideConfig; |
Stephen Kiazyk | f903b73 | 2017-03-20 16:23:45 -0700 | [diff] [blame] | 5870 | final ViewRootImpl viewRoot = r.activity.mDecor != null |
| 5871 | ? r.activity.mDecor.getViewRootImpl() : null; |
| 5872 | |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5873 | if (movedToDifferentDisplay) { |
| 5874 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Handle activity moved to display, activity:" |
| 5875 | + r.activityInfo.name + ", displayId=" + displayId |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 5876 | + ", config=" + overrideConfig); |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5877 | |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 5878 | final Configuration reportedConfig = performConfigurationChangedForActivity(r, |
| 5879 | mCompatConfiguration, displayId, true /* movedToDifferentDisplay */); |
Andrii Kulian | ce1ecf1 | 2017-03-17 14:58:36 -0700 | [diff] [blame] | 5880 | if (viewRoot != null) { |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 5881 | viewRoot.onMovedToDisplay(displayId, reportedConfig); |
Andrii Kulian | ce1ecf1 | 2017-03-17 14:58:36 -0700 | [diff] [blame] | 5882 | } |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5883 | } else { |
| 5884 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Handle activity config changed: " |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 5885 | + r.activityInfo.name + ", config=" + overrideConfig); |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5886 | performConfigurationChangedForActivity(r, mCompatConfiguration); |
| 5887 | } |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 5888 | // Notify the ViewRootImpl instance about configuration changes. It may have initiated this |
| 5889 | // update to make sure that resources are updated before updating itself. |
Andrii Kulian | ce1ecf1 | 2017-03-17 14:58:36 -0700 | [diff] [blame] | 5890 | if (viewRoot != null) { |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 5891 | viewRoot.updateConfiguration(displayId); |
Andrii Kulian | ce1ecf1 | 2017-03-17 14:58:36 -0700 | [diff] [blame] | 5892 | } |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 5893 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5894 | } |
| 5895 | |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 5896 | final void handleProfilerControl(boolean start, ProfilerInfo profilerInfo, int profileType) { |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 5897 | if (start) { |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 5898 | try { |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 5899 | switch (profileType) { |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 5900 | default: |
| 5901 | mProfiler.setProfiler(profilerInfo); |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 5902 | mProfiler.startProfiling(); |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 5903 | break; |
| 5904 | } |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 5905 | } catch (RuntimeException e) { |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 5906 | Slog.w(TAG, "Profiling failed on path " + profilerInfo.profileFile |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 5907 | + " -- can the process access this path?"); |
Dianne Hackborn | 9c8dd55 | 2009-06-23 19:22:52 -0700 | [diff] [blame] | 5908 | } finally { |
Andreas Gampe | 2b073a0 | 2017-06-22 17:28:57 -0700 | [diff] [blame] | 5909 | profilerInfo.closeFd(); |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 5910 | } |
| 5911 | } else { |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 5912 | switch (profileType) { |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 5913 | default: |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 5914 | mProfiler.stopProfiling(); |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 5915 | break; |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 5916 | } |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 5917 | } |
| 5918 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 5919 | |
Andreas Gampe | 4c79fea | 2016-01-28 20:11:41 -0800 | [diff] [blame] | 5920 | /** |
| 5921 | * Public entrypoint to stop profiling. This is required to end profiling when the app crashes, |
| 5922 | * so that profiler data won't be lost. |
| 5923 | * |
| 5924 | * @hide |
| 5925 | */ |
| 5926 | public void stopProfiling() { |
Amith Yamasani | b168443 | 2017-01-26 14:57:20 -0800 | [diff] [blame] | 5927 | if (mProfiler != null) { |
| 5928 | mProfiler.stopProfiling(); |
| 5929 | } |
Andreas Gampe | 4c79fea | 2016-01-28 20:11:41 -0800 | [diff] [blame] | 5930 | } |
| 5931 | |
Christopher Ferris | 8d652f8 | 2017-04-11 16:29:18 -0700 | [diff] [blame] | 5932 | static void handleDumpHeap(DumpHeapData dhd) { |
Makoto Onuki | 4556b7b | 2017-07-07 14:58:58 -0700 | [diff] [blame] | 5933 | if (dhd.runGc) { |
| 5934 | System.gc(); |
| 5935 | System.runFinalization(); |
| 5936 | System.gc(); |
| 5937 | } |
Kweku Adams | 4af1b50 | 2019-05-23 16:23:48 -0700 | [diff] [blame] | 5938 | try (ParcelFileDescriptor fd = dhd.fd) { |
| 5939 | if (dhd.managed) { |
| 5940 | Debug.dumpHprofData(dhd.path, fd.getFileDescriptor()); |
| 5941 | } else if (dhd.mallocInfo) { |
| 5942 | Debug.dumpNativeMallocInfo(fd.getFileDescriptor()); |
| 5943 | } else { |
| 5944 | Debug.dumpNativeHeap(fd.getFileDescriptor()); |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 5945 | } |
Kweku Adams | 4af1b50 | 2019-05-23 16:23:48 -0700 | [diff] [blame] | 5946 | } catch (IOException e) { |
| 5947 | if (dhd.managed) { |
| 5948 | Slog.w(TAG, "Managed heap dump failed on path " + dhd.path |
| 5949 | + " -- can the process access this path?", e); |
| 5950 | } else { |
| 5951 | Slog.w(TAG, "Failed to dump heap", e); |
| 5952 | } |
| 5953 | } catch (RuntimeException e) { |
| 5954 | // This should no longer happening now that we're copying the file descriptor. |
| 5955 | Slog.wtf(TAG, "Heap dumper threw a runtime exception", e); |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 5956 | } |
Dianne Hackborn | b9a5e4a | 2015-03-03 17:04:12 -0800 | [diff] [blame] | 5957 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5958 | ActivityManager.getService().dumpHeapFinished(dhd.path); |
Dianne Hackborn | b9a5e4a | 2015-03-03 17:04:12 -0800 | [diff] [blame] | 5959 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5960 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | b9a5e4a | 2015-03-03 17:04:12 -0800 | [diff] [blame] | 5961 | } |
Makoto Onuki | 2c6657f | 2018-06-06 15:24:02 -0700 | [diff] [blame] | 5962 | if (dhd.finishCallback != null) { |
| 5963 | dhd.finishCallback.sendResult(null); |
| 5964 | } |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 5965 | } |
| 5966 | |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 5967 | final void handleDispatchPackageBroadcast(int cmd, String[] packages) { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5968 | boolean hasPkgInfo = false; |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5969 | switch (cmd) { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 5970 | case ApplicationThreadConstants.PACKAGE_REMOVED: |
| 5971 | case ApplicationThreadConstants.PACKAGE_REMOVED_DONT_KILL: |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5972 | { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 5973 | final boolean killApp = cmd == ApplicationThreadConstants.PACKAGE_REMOVED; |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5974 | if (packages == null) { |
| 5975 | break; |
| 5976 | } |
| 5977 | synchronized (mResourcesManager) { |
| 5978 | for (int i = packages.length - 1; i >= 0; i--) { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5979 | if (!hasPkgInfo) { |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5980 | WeakReference<LoadedApk> ref = mPackages.get(packages[i]); |
| 5981 | if (ref != null && ref.get() != null) { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5982 | hasPkgInfo = true; |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5983 | } else { |
| 5984 | ref = mResourcePackages.get(packages[i]); |
| 5985 | if (ref != null && ref.get() != null) { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5986 | hasPkgInfo = true; |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5987 | } |
| 5988 | } |
| 5989 | } |
| 5990 | if (killApp) { |
| 5991 | mPackages.remove(packages[i]); |
| 5992 | mResourcePackages.remove(packages[i]); |
| 5993 | } |
| 5994 | } |
| 5995 | } |
| 5996 | break; |
| 5997 | } |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 5998 | case ApplicationThreadConstants.PACKAGE_REPLACED: |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5999 | { |
| 6000 | if (packages == null) { |
| 6001 | break; |
| 6002 | } |
Winson | 23863be | 2019-04-04 17:41:28 -0700 | [diff] [blame] | 6003 | |
| 6004 | List<String> packagesHandled = new ArrayList<>(); |
| 6005 | |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 6006 | synchronized (mResourcesManager) { |
| 6007 | for (int i = packages.length - 1; i >= 0; i--) { |
Winson | 23863be | 2019-04-04 17:41:28 -0700 | [diff] [blame] | 6008 | String packageName = packages[i]; |
| 6009 | WeakReference<LoadedApk> ref = mPackages.get(packageName); |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 6010 | LoadedApk pkgInfo = ref != null ? ref.get() : null; |
| 6011 | if (pkgInfo != null) { |
| 6012 | hasPkgInfo = true; |
mark_chen | 89764e3 | 2014-12-12 15:38:48 +0800 | [diff] [blame] | 6013 | } else { |
Winson | 23863be | 2019-04-04 17:41:28 -0700 | [diff] [blame] | 6014 | ref = mResourcePackages.get(packageName); |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 6015 | pkgInfo = ref != null ? ref.get() : null; |
| 6016 | if (pkgInfo != null) { |
| 6017 | hasPkgInfo = true; |
mark_chen | 89764e3 | 2014-12-12 15:38:48 +0800 | [diff] [blame] | 6018 | } |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 6019 | } |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 6020 | // If the package is being replaced, yet it still has a valid |
| 6021 | // LoadedApk object, the package was updated with _DONT_KILL. |
| 6022 | // Adjust it's internal references to the application info and |
| 6023 | // resources. |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 6024 | if (pkgInfo != null) { |
Winson | 23863be | 2019-04-04 17:41:28 -0700 | [diff] [blame] | 6025 | packagesHandled.add(packageName); |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 6026 | try { |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 6027 | final ApplicationInfo aInfo = |
| 6028 | sPackageManager.getApplicationInfo( |
| 6029 | packageName, |
Svet Ganov | 6ce9239 | 2017-09-27 16:04:10 -0700 | [diff] [blame] | 6030 | PackageManager.GET_SHARED_LIBRARY_FILES, |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 6031 | UserHandle.myUserId()); |
| 6032 | |
| 6033 | if (mActivities.size() > 0) { |
| 6034 | for (ActivityClientRecord ar : mActivities.values()) { |
| 6035 | if (ar.activityInfo.applicationInfo.packageName |
| 6036 | .equals(packageName)) { |
| 6037 | ar.activityInfo.applicationInfo = aInfo; |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 6038 | ar.packageInfo = pkgInfo; |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 6039 | } |
| 6040 | } |
| 6041 | } |
Winson | d605e2d | 2019-02-11 16:05:51 -0800 | [diff] [blame] | 6042 | |
| 6043 | final String[] oldResDirs = { pkgInfo.getResDir() }; |
| 6044 | |
Todd Kennedy | b9656a9 | 2018-05-02 10:59:45 +0100 | [diff] [blame] | 6045 | final ArrayList<String> oldPaths = new ArrayList<>(); |
| 6046 | LoadedApk.makePaths(this, pkgInfo.getApplicationInfo(), oldPaths); |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 6047 | pkgInfo.updateApplicationInfo(aInfo, oldPaths); |
Winson | d605e2d | 2019-02-11 16:05:51 -0800 | [diff] [blame] | 6048 | |
| 6049 | synchronized (mResourcesManager) { |
| 6050 | // Update affected Resources objects to use new ResourcesImpl |
| 6051 | mResourcesManager.applyNewResourceDirsLocked(aInfo, oldResDirs); |
| 6052 | } |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 6053 | } catch (RemoteException e) { |
| 6054 | } |
| 6055 | } |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 6056 | } |
| 6057 | } |
Winson | 23863be | 2019-04-04 17:41:28 -0700 | [diff] [blame] | 6058 | |
| 6059 | try { |
| 6060 | getPackageManager().notifyPackagesReplacedReceived( |
| 6061 | packagesHandled.toArray(new String[0])); |
| 6062 | } catch (RemoteException ignored) { |
| 6063 | } |
| 6064 | |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 6065 | break; |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 6066 | } |
| 6067 | } |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 6068 | ApplicationPackageManager.handlePackageBroadcast(cmd, packages, hasPkgInfo); |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 6069 | } |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 6070 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6071 | final void handleLowMemory() { |
Dianne Hackborn | 73c1416 | 2012-09-19 15:45:06 -0700 | [diff] [blame] | 6072 | ArrayList<ComponentCallbacks2> callbacks = collectComponentCallbacks(true, null); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 6073 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6074 | final int N = callbacks.size(); |
| 6075 | for (int i=0; i<N; i++) { |
| 6076 | callbacks.get(i).onLowMemory(); |
| 6077 | } |
| 6078 | |
Chris Tate | ce22905 | 2009-03-25 16:44:52 -0700 | [diff] [blame] | 6079 | // Ask SQLite to free up as much memory as it can, mostly from its page caches. |
| 6080 | if (Process.myUid() != Process.SYSTEM_UID) { |
| 6081 | int sqliteReleased = SQLiteDatabase.releaseMemory(); |
| 6082 | EventLog.writeEvent(SQLITE_MEM_RELEASED_EVENT_LOG_TAG, sqliteReleased); |
| 6083 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 6084 | |
Mike Reed | caf0df1 | 2009-04-27 14:32:05 -0400 | [diff] [blame] | 6085 | // Ask graphics to free up as much as possible (font/image caches) |
| 6086 | Canvas.freeCaches(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6087 | |
Fabrice Di Meglio | 30ca5cd | 2012-05-07 17:45:44 -0700 | [diff] [blame] | 6088 | // Ask text layout engine to free also as much as possible |
| 6089 | Canvas.freeTextLayoutCaches(); |
| 6090 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6091 | BinderInternal.forceGc("mem"); |
| 6092 | } |
| 6093 | |
Jorim Jaggi | b29e318 | 2018-04-30 18:51:56 +0200 | [diff] [blame] | 6094 | private void handleTrimMemory(int level) { |
| 6095 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "trimMemory"); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 6096 | if (DEBUG_MEMORY_TRIM) Slog.v(TAG, "Trimming memory to level: " + level); |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 6097 | |
Dianne Hackborn | 73c1416 | 2012-09-19 15:45:06 -0700 | [diff] [blame] | 6098 | ArrayList<ComponentCallbacks2> callbacks = collectComponentCallbacks(true, null); |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 6099 | |
| 6100 | final int N = callbacks.size(); |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 6101 | for (int i = 0; i < N; i++) { |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 6102 | callbacks.get(i).onTrimMemory(level); |
| 6103 | } |
Romain Guy | 19f86e8 | 2012-04-23 15:19:07 -0700 | [diff] [blame] | 6104 | |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 6105 | WindowManagerGlobal.getInstance().trimMemory(level); |
Jorim Jaggi | b29e318 | 2018-04-30 18:51:56 +0200 | [diff] [blame] | 6106 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Makoto Onuki | 0a9ee1a | 2019-06-19 08:58:02 -0700 | [diff] [blame] | 6107 | |
| 6108 | if (SystemProperties.getInt("debug.am.run_gc_trim_level", Integer.MAX_VALUE) <= level) { |
| 6109 | unscheduleGcIdler(); |
| 6110 | doGcIfNeeded("tm"); |
| 6111 | } |
| 6112 | if (SystemProperties.getInt("debug.am.run_mallopt_trim_level", Integer.MAX_VALUE) |
| 6113 | <= level) { |
| 6114 | unschedulePurgeIdler(); |
| 6115 | purgePendingResources(); |
| 6116 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 6117 | } |
| 6118 | |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 6119 | private void setupGraphicsSupport(Context context) { |
Andreas Gampe | 4c8e542 | 2016-05-18 11:58:47 -0700 | [diff] [blame] | 6120 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "setupGraphicsSupport"); |
Romain Guy | a958265 | 2011-11-10 14:20:10 -0800 | [diff] [blame] | 6121 | |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 6122 | // The system package doesn't have real data directories, so don't set up cache paths. |
| 6123 | if (!"android".equals(context.getPackageName())) { |
| 6124 | // This cache location probably points at credential-encrypted |
| 6125 | // storage which may not be accessible yet; assign it anyway instead |
| 6126 | // of pointing at device-encrypted storage. |
| 6127 | final File cacheDir = context.getCacheDir(); |
| 6128 | if (cacheDir != null) { |
| 6129 | // Provide a usable directory for temporary files |
| 6130 | System.setProperty("java.io.tmpdir", cacheDir.getAbsolutePath()); |
| 6131 | } else { |
| 6132 | Log.v(TAG, "Unable to initialize \"java.io.tmpdir\" property " |
| 6133 | + "due to missing cache directory"); |
Romain Guy | a958265 | 2011-11-10 14:20:10 -0800 | [diff] [blame] | 6134 | } |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 6135 | |
| 6136 | // Setup a location to store generated/compiled graphics code. |
| 6137 | final Context deviceContext = context.createDeviceProtectedStorageContext(); |
| 6138 | final File codeCacheDir = deviceContext.getCodeCacheDir(); |
| 6139 | if (codeCacheDir != null) { |
| 6140 | try { |
| 6141 | int uid = Process.myUid(); |
| 6142 | String[] packages = getPackageManager().getPackagesForUid(uid); |
| 6143 | if (packages != null) { |
John Reck | 8785ceb | 2018-10-29 16:45:58 -0700 | [diff] [blame] | 6144 | HardwareRenderer.setupDiskCache(codeCacheDir); |
Romain Guy | cecbe07 | 2017-07-18 15:42:06 -0700 | [diff] [blame] | 6145 | RenderScriptCacheDir.setupDiskCache(codeCacheDir); |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 6146 | } |
| 6147 | } catch (RemoteException e) { |
| 6148 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
| 6149 | throw e.rethrowFromSystemServer(); |
| 6150 | } |
| 6151 | } else { |
| 6152 | Log.w(TAG, "Unable to use shader/script cache: missing code-cache directory"); |
| 6153 | } |
Romain Guy | a958265 | 2011-11-10 14:20:10 -0800 | [diff] [blame] | 6154 | } |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 6155 | |
Cody Northrop | deb4328 | 2018-10-04 16:04:05 -0600 | [diff] [blame] | 6156 | GraphicsEnvironment.getInstance().setup(context, mCoreSettings); |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 6157 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 6158 | } |
| 6159 | |
| 6160 | private void updateDefaultDensity() { |
Alan Viverette | 2ac46f1 | 2016-02-04 16:58:14 -0500 | [diff] [blame] | 6161 | final int densityDpi = mCurDefaultDisplayDpi; |
| 6162 | if (!mDensityCompatMode |
| 6163 | && densityDpi != Configuration.DENSITY_DPI_UNDEFINED |
| 6164 | && densityDpi != DisplayMetrics.DENSITY_DEVICE) { |
| 6165 | DisplayMetrics.DENSITY_DEVICE = densityDpi; |
| 6166 | Bitmap.setDefaultDensity(densityDpi); |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 6167 | } |
| 6168 | } |
| 6169 | |
Todd Kennedy | e713efc | 2016-05-10 13:45:40 -0700 | [diff] [blame] | 6170 | /** |
| 6171 | * Returns the correct library directory for the current ABI. |
| 6172 | * <p> |
| 6173 | * If we're dealing with a multi-arch application that has both 32 and 64 bit shared |
| 6174 | * libraries, we might need to choose the secondary depending on what the current |
| 6175 | * runtime's instruction set is. |
| 6176 | */ |
| 6177 | private String getInstrumentationLibrary(ApplicationInfo appInfo, InstrumentationInfo insInfo) { |
Patrick Baumann | eb59580 | 2018-04-17 09:49:55 -0700 | [diff] [blame] | 6178 | if (appInfo.primaryCpuAbi != null && appInfo.secondaryCpuAbi != null |
| 6179 | && appInfo.secondaryCpuAbi.equals(insInfo.secondaryCpuAbi)) { |
Todd Kennedy | e713efc | 2016-05-10 13:45:40 -0700 | [diff] [blame] | 6180 | // Get the instruction set supported by the secondary ABI. In the presence |
| 6181 | // of a native bridge this might be different than the one secondary ABI used. |
| 6182 | String secondaryIsa = |
| 6183 | VMRuntime.getInstructionSet(appInfo.secondaryCpuAbi); |
| 6184 | final String secondaryDexCodeIsa = |
| 6185 | SystemProperties.get("ro.dalvik.vm.isa." + secondaryIsa); |
| 6186 | secondaryIsa = secondaryDexCodeIsa.isEmpty() ? secondaryIsa : secondaryDexCodeIsa; |
| 6187 | |
| 6188 | final String runtimeIsa = VMRuntime.getRuntime().vmInstructionSet(); |
| 6189 | if (runtimeIsa.equals(secondaryIsa)) { |
| 6190 | return insInfo.secondaryNativeLibraryDir; |
| 6191 | } |
| 6192 | } |
| 6193 | return insInfo.nativeLibraryDir; |
| 6194 | } |
| 6195 | |
Adam Lesinski | b61e405 | 2016-05-19 18:23:05 -0700 | [diff] [blame] | 6196 | /** |
| 6197 | * The LocaleList set for the app's resources may have been shuffled so that the preferred |
| 6198 | * Locale is at position 0. We must find the index of this preferred Locale in the |
| 6199 | * original LocaleList. |
| 6200 | */ |
| 6201 | private void updateLocaleListFromAppContext(Context context, LocaleList newLocaleList) { |
| 6202 | final Locale bestLocale = context.getResources().getConfiguration().getLocales().get(0); |
| 6203 | final int newLocaleListSize = newLocaleList.size(); |
| 6204 | for (int i = 0; i < newLocaleListSize; i++) { |
| 6205 | if (bestLocale.equals(newLocaleList.get(i))) { |
| 6206 | LocaleList.setDefault(newLocaleList, i); |
| 6207 | return; |
| 6208 | } |
| 6209 | } |
Adam Lesinski | 27d3016 | 2016-05-25 16:45:14 -0700 | [diff] [blame] | 6210 | |
| 6211 | // The app may have overridden the LocaleList with its own Locale |
| 6212 | // (not present in the available list). Push the chosen Locale |
| 6213 | // to the front of the list. |
| 6214 | LocaleList.setDefault(new LocaleList(bestLocale, newLocaleList)); |
Adam Lesinski | b61e405 | 2016-05-19 18:23:05 -0700 | [diff] [blame] | 6215 | } |
| 6216 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 6217 | @UnsupportedAppUsage |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 6218 | private void handleBindApplication(AppBindData data) { |
Calin Juravle | 8f5770d | 2016-04-12 14:12:04 +0100 | [diff] [blame] | 6219 | // Register the UI Thread as a sensitive thread to the runtime. |
| 6220 | VMRuntime.registerSensitiveThread(); |
Mathieu Chartier | 90aa945 | 2019-03-29 13:49:35 -0700 | [diff] [blame] | 6221 | // In the case the stack depth property exists, pass it down to the runtime. |
| 6222 | String property = SystemProperties.get("debug.allocTracker.stackDepth"); |
| 6223 | if (property.length() != 0) { |
| 6224 | VMDebug.setAllocTrackerStackDepth(Integer.parseInt(property)); |
| 6225 | } |
Man Cao | cfa78b2 | 2015-06-11 20:14:34 -0700 | [diff] [blame] | 6226 | if (data.trackAllocation) { |
| 6227 | DdmVmInternal.enableRecentAllocations(true); |
| 6228 | } |
Dianne Hackborn | d98885c | 2016-03-01 17:13:03 -0800 | [diff] [blame] | 6229 | // Note when this process has started. |
| 6230 | Process.setStartTimes(SystemClock.elapsedRealtime(), SystemClock.uptimeMillis()); |
| 6231 | |
Mathew Inwood | 80652db | 2019-06-24 12:07:22 +0100 | [diff] [blame] | 6232 | AppCompatCallbacks.install(data.disabledCompatChanges); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6233 | mBoundApplication = data; |
| 6234 | mConfiguration = new Configuration(data.config); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 6235 | mCompatConfiguration = new Configuration(data.config); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6236 | |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 6237 | mProfiler = new Profiler(); |
Andreas Gampe | ab8a63b | 2018-01-05 13:55:15 -0800 | [diff] [blame] | 6238 | String agent = null; |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 6239 | if (data.initProfilerInfo != null) { |
| 6240 | mProfiler.profileFile = data.initProfilerInfo.profileFile; |
| 6241 | mProfiler.profileFd = data.initProfilerInfo.profileFd; |
| 6242 | mProfiler.samplingInterval = data.initProfilerInfo.samplingInterval; |
| 6243 | mProfiler.autoStopProfiler = data.initProfilerInfo.autoStopProfiler; |
Shukang Zhou | 6ffd4f9 | 2017-01-25 16:07:57 -0800 | [diff] [blame] | 6244 | mProfiler.streamingOutput = data.initProfilerInfo.streamingOutput; |
Andreas Gampe | ab8a63b | 2018-01-05 13:55:15 -0800 | [diff] [blame] | 6245 | if (data.initProfilerInfo.attachAgentDuringBind) { |
| 6246 | agent = data.initProfilerInfo.agent; |
| 6247 | } |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 6248 | } |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 6249 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6250 | // send up app name; do this *before* waiting for debugger |
Christopher Tate | 8ee038d | 2009-11-06 11:30:20 -0800 | [diff] [blame] | 6251 | Process.setArgV0(data.processName); |
Siva Velusamy | d693dfa | 2012-09-10 14:36:58 -0700 | [diff] [blame] | 6252 | android.ddm.DdmHandleAppName.setAppName(data.processName, |
Chester Hsieh | ab720ee | 2019-11-12 12:01:54 -0800 | [diff] [blame] | 6253 | data.appInfo.packageName, |
Siva Velusamy | d693dfa | 2012-09-10 14:36:58 -0700 | [diff] [blame] | 6254 | UserHandle.myUserId()); |
Mathew Inwood | 37b6ca8 | 2018-05-02 10:42:23 +0100 | [diff] [blame] | 6255 | VMRuntime.setProcessPackageName(data.appInfo.packageName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6256 | |
David Brazdil | 06f2e129 | 2019-04-03 13:00:55 +0100 | [diff] [blame] | 6257 | // Pass data directory path to ART. This is used for caching information and |
| 6258 | // should be set before any application code is loaded. |
| 6259 | VMRuntime.setProcessDataDirectory(data.appInfo.dataDir); |
| 6260 | |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 6261 | if (mProfiler.profileFd != null) { |
| 6262 | mProfiler.startProfiling(); |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 6263 | } |
| 6264 | |
Joe Onorato | d630f10 | 2011-03-17 18:42:26 -0700 | [diff] [blame] | 6265 | // If the app is Honeycomb MR1 or earlier, switch its AsyncTask |
| 6266 | // implementation to use the pool executor. Normally, we use the |
| 6267 | // serialized executor as the default. This has to happen in the |
| 6268 | // main thread so the main looper is set right. |
Dianne Hackborn | 81e9276 | 2011-10-09 16:00:21 -0700 | [diff] [blame] | 6269 | if (data.appInfo.targetSdkVersion <= android.os.Build.VERSION_CODES.HONEYCOMB_MR1) { |
Joe Onorato | d630f10 | 2011-03-17 18:42:26 -0700 | [diff] [blame] | 6270 | AsyncTask.setDefaultExecutor(AsyncTask.THREAD_POOL_EXECUTOR); |
| 6271 | } |
| 6272 | |
Kweku Adams | 4be0b1a | 2019-04-25 16:16:34 -0700 | [diff] [blame] | 6273 | // Let the util.*Array classes maintain "undefined" for apps targeting Pie or earlier. |
| 6274 | UtilConfig.setThrowExceptionForUpperArrayOutOfBounds( |
| 6275 | data.appInfo.targetSdkVersion >= Build.VERSION_CODES.Q); |
| 6276 | |
Dianne Hackborn | 7895bc2 | 2014-09-05 15:09:03 -0700 | [diff] [blame] | 6277 | Message.updateCheckRecycle(data.appInfo.targetSdkVersion); |
| 6278 | |
Leon Scroggins III | 8290eab | 2018-03-19 10:51:44 -0400 | [diff] [blame] | 6279 | // Prior to P, internal calls to decode Bitmaps used BitmapFactory, |
| 6280 | // which may scale up to account for density. In P, we switched to |
| 6281 | // ImageDecoder, which skips the upscale to save memory. ImageDecoder |
| 6282 | // needs to still scale up in older apps, in case they rely on the |
| 6283 | // size of the Bitmap without considering its density. |
| 6284 | ImageDecoder.sApiLevel = data.appInfo.targetSdkVersion; |
| 6285 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6286 | /* |
| 6287 | * Before spawning a new process, reset the time zone to be the system time zone. |
| 6288 | * This needs to be done because the system time zone could have changed after the |
| 6289 | * the spawning of this process. Without doing this this process would have the incorrect |
| 6290 | * system time zone. |
| 6291 | */ |
| 6292 | TimeZone.setDefault(null); |
| 6293 | |
Adam Lesinski | b61e405 | 2016-05-19 18:23:05 -0700 | [diff] [blame] | 6294 | /* |
| 6295 | * Set the LocaleList. This may change once we create the App Context. |
| 6296 | */ |
| 6297 | LocaleList.setDefault(data.config.getLocales()); |
| 6298 | |
| 6299 | synchronized (mResourcesManager) { |
| 6300 | /* |
| 6301 | * Update the system configuration since its preloaded and might not |
| 6302 | * reflect configuration changes. The configuration object passed |
| 6303 | * in AppBindData can be safely assumed to be up to date |
| 6304 | */ |
| 6305 | mResourcesManager.applyConfigurationToResourcesLocked(data.config, data.compatInfo); |
| 6306 | mCurDefaultDisplayDpi = data.config.densityDpi; |
| 6307 | |
| 6308 | // This calls mResourcesManager so keep it within the synchronized block. |
| 6309 | applyCompatConfiguration(mCurDefaultDisplayDpi); |
| 6310 | } |
| 6311 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 6312 | data.info = getPackageInfoNoCheck(data.appInfo, data.compatInfo); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6313 | |
Andreas Gampe | ab8a63b | 2018-01-05 13:55:15 -0800 | [diff] [blame] | 6314 | if (agent != null) { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 6315 | handleAttachAgent(agent, data.info); |
Andreas Gampe | ab8a63b | 2018-01-05 13:55:15 -0800 | [diff] [blame] | 6316 | } |
| 6317 | |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 6318 | /** |
| 6319 | * Switch this process to density compatibility mode if needed. |
| 6320 | */ |
| 6321 | if ((data.appInfo.flags&ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES) |
| 6322 | == 0) { |
| 6323 | mDensityCompatMode = true; |
| 6324 | Bitmap.setDefaultDensity(DisplayMetrics.DENSITY_DEFAULT); |
| 6325 | } |
| 6326 | updateDefaultDensity(); |
| 6327 | |
Neil Fuller | c66ec40 | 2016-11-14 16:06:42 +0000 | [diff] [blame] | 6328 | final String use24HourSetting = mCoreSettings.getString(Settings.System.TIME_12_24); |
| 6329 | Boolean is24Hr = null; |
| 6330 | if (use24HourSetting != null) { |
| 6331 | is24Hr = "24".equals(use24HourSetting) ? Boolean.TRUE : Boolean.FALSE; |
| 6332 | } |
| 6333 | // null : use locale default for 12/24 hour formatting, |
| 6334 | // false : use 12 hour format, |
| 6335 | // true : use 24 hour format. |
Narayan Kamath | ccb2a086 | 2013-12-19 14:49:36 +0000 | [diff] [blame] | 6336 | DateFormat.set24HourTimePref(is24Hr); |
| 6337 | |
Aurimas Liutikas | 8f004c8 | 2019-01-17 17:20:10 -0800 | [diff] [blame] | 6338 | updateDebugViewAttributeState(); |
Jon Miranda | 836c0a8 | 2014-08-11 12:32:26 -0700 | [diff] [blame] | 6339 | |
Jeff Sharkey | 8918298 | 2017-11-01 19:02:56 -0600 | [diff] [blame] | 6340 | StrictMode.initThreadDefaults(data.appInfo); |
| 6341 | StrictMode.initVmDefaults(data.appInfo); |
Jeff Sharkey | 344744b | 2016-01-28 19:03:30 -0700 | [diff] [blame] | 6342 | |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 6343 | if (data.debugMode != ApplicationThreadConstants.DEBUG_OFF) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6344 | // XXX should have option to change the port. |
| 6345 | Debug.changeDebugPort(8100); |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 6346 | if (data.debugMode == ApplicationThreadConstants.DEBUG_WAIT) { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 6347 | Slog.w(TAG, "Application " + data.info.getPackageName() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6348 | + " is waiting for the debugger on port 8100..."); |
| 6349 | |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6350 | IActivityManager mgr = ActivityManager.getService(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6351 | try { |
| 6352 | mgr.showWaitingForDebugger(mAppThread, true); |
| 6353 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 6354 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6355 | } |
| 6356 | |
| 6357 | Debug.waitForDebugger(); |
| 6358 | |
| 6359 | try { |
| 6360 | mgr.showWaitingForDebugger(mAppThread, false); |
| 6361 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 6362 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6363 | } |
| 6364 | |
| 6365 | } else { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 6366 | Slog.w(TAG, "Application " + data.info.getPackageName() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6367 | + " can be debugged on port 8100..."); |
| 6368 | } |
| 6369 | } |
| 6370 | |
Chris Craik | ce03028 | 2018-10-16 14:33:11 -0700 | [diff] [blame] | 6371 | // Allow binder tracing, and application-generated systrace messages if we're profileable. |
| 6372 | boolean isAppProfileable = data.appInfo.isProfileableByShell(); |
| 6373 | Trace.setAppTracingAllowed(isAppProfileable); |
| 6374 | if (isAppProfileable && data.enableBinderTracking) { |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 6375 | Binder.enableTracing(); |
| 6376 | } |
Jamie Gennis | f9c7d6b | 2013-03-25 14:18:25 -0700 | [diff] [blame] | 6377 | |
Ryan Savitski | cfdc151 | 2018-12-14 16:20:52 +0000 | [diff] [blame] | 6378 | // Initialize heap profiling. |
| 6379 | if (isAppProfileable || Build.IS_DEBUGGABLE) { |
| 6380 | nInitZygoteChildHeapProfiling(); |
| 6381 | } |
| 6382 | |
Chris Craik | ce03028 | 2018-10-16 14:33:11 -0700 | [diff] [blame] | 6383 | // Allow renderer debugging features if we're debuggable. |
| 6384 | boolean isAppDebuggable = (data.appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0; |
John Reck | 8785ceb | 2018-10-29 16:45:58 -0700 | [diff] [blame] | 6385 | HardwareRenderer.setDebuggingEnabled(isAppDebuggable || Build.IS_DEBUGGABLE); |
| 6386 | HardwareRenderer.setPackageName(data.appInfo.packageName); |
Chris Craik | ce03028 | 2018-10-16 14:33:11 -0700 | [diff] [blame] | 6387 | |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 6388 | /** |
| 6389 | * Initialize the default http proxy in this process for the reasons we set the time zone. |
| 6390 | */ |
Andreas Gampe | 4c8e542 | 2016-05-18 11:58:47 -0700 | [diff] [blame] | 6391 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "Setup proxies"); |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 6392 | final IBinder b = ServiceManager.getService(Context.CONNECTIVITY_SERVICE); |
Dianne Hackborn | d4d32c5 | 2011-11-08 17:33:59 -0800 | [diff] [blame] | 6393 | if (b != null) { |
| 6394 | // In pre-boot mode (doing initial launch to collect password), not |
| 6395 | // all system is up. This includes the connectivity service, so don't |
| 6396 | // crash if we can't get it. |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 6397 | final IConnectivityManager service = IConnectivityManager.Stub.asInterface(b); |
Dianne Hackborn | d4d32c5 | 2011-11-08 17:33:59 -0800 | [diff] [blame] | 6398 | try { |
Irina Dumitrescu | 18622d3 | 2018-12-05 16:19:47 +0000 | [diff] [blame] | 6399 | Proxy.setHttpProxySystemProperty(service.getProxyForNetwork(null)); |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 6400 | } catch (RemoteException e) { |
Andreas Gampe | 4c8e542 | 2016-05-18 11:58:47 -0700 | [diff] [blame] | 6401 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 6402 | throw e.rethrowFromSystemServer(); |
| 6403 | } |
Dianne Hackborn | d4d32c5 | 2011-11-08 17:33:59 -0800 | [diff] [blame] | 6404 | } |
Andreas Gampe | 4c8e542 | 2016-05-18 11:58:47 -0700 | [diff] [blame] | 6405 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 6406 | |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 6407 | // Instrumentation info affects the class loader, so load it before |
| 6408 | // setting up the app context. |
| 6409 | final InstrumentationInfo ii; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6410 | if (data.instrumentationName != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6411 | try { |
Todd Kennedy | 8f13598 | 2019-07-02 07:35:15 -0700 | [diff] [blame] | 6412 | ii = new ApplicationPackageManager( |
| 6413 | null, getPackageManager(), getPermissionManager()) |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 6414 | .getInstrumentationInfo(data.instrumentationName, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6415 | } catch (PackageManager.NameNotFoundException e) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6416 | throw new RuntimeException( |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 6417 | "Unable to find instrumentation info for: " + data.instrumentationName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6418 | } |
| 6419 | |
Patrick Baumann | eb59580 | 2018-04-17 09:49:55 -0700 | [diff] [blame] | 6420 | // Warn of potential ABI mismatches. |
| 6421 | if (!Objects.equals(data.appInfo.primaryCpuAbi, ii.primaryCpuAbi) |
| 6422 | || !Objects.equals(data.appInfo.secondaryCpuAbi, ii.secondaryCpuAbi)) { |
| 6423 | Slog.w(TAG, "Package uses different ABI(s) than its instrumentation: " |
| 6424 | + "package[" + data.appInfo.packageName + "]: " |
| 6425 | + data.appInfo.primaryCpuAbi + ", " + data.appInfo.secondaryCpuAbi |
| 6426 | + " instrumentation[" + ii.packageName + "]: " |
| 6427 | + ii.primaryCpuAbi + ", " + ii.secondaryCpuAbi); |
| 6428 | } |
| 6429 | |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 6430 | mInstrumentationPackageName = ii.packageName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6431 | mInstrumentationAppDir = ii.sourceDir; |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 6432 | mInstrumentationSplitAppDirs = ii.splitSourceDirs; |
Todd Kennedy | e713efc | 2016-05-10 13:45:40 -0700 | [diff] [blame] | 6433 | mInstrumentationLibDir = getInstrumentationLibrary(data.appInfo, ii); |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 6434 | mInstrumentedAppDir = data.info.getAppDir(); |
| 6435 | mInstrumentedSplitAppDirs = data.info.getSplitAppDirs(); |
| 6436 | mInstrumentedLibDir = data.info.getLibDir(); |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 6437 | } else { |
| 6438 | ii = null; |
| 6439 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6440 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 6441 | final ContextImpl appContext = ContextImpl.createAppContext(this, data.info); |
Adam Lesinski | b61e405 | 2016-05-19 18:23:05 -0700 | [diff] [blame] | 6442 | updateLocaleListFromAppContext(appContext, |
| 6443 | mResourcesManager.getConfiguration().getLocales()); |
Seigo Nonaka | c14dd78 | 2016-03-30 23:09:16 +0900 | [diff] [blame] | 6444 | |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 6445 | if (!Process.isIsolated()) { |
Jeff Sharkey | 8918298 | 2017-11-01 19:02:56 -0600 | [diff] [blame] | 6446 | final int oldMask = StrictMode.allowThreadDiskWritesMask(); |
| 6447 | try { |
| 6448 | setupGraphicsSupport(appContext); |
| 6449 | } finally { |
| 6450 | StrictMode.setThreadPolicyMask(oldMask); |
| 6451 | } |
John Reck | 5642847 | 2018-03-16 17:27:17 -0700 | [diff] [blame] | 6452 | } else { |
John Reck | 8785ceb | 2018-10-29 16:45:58 -0700 | [diff] [blame] | 6453 | HardwareRenderer.setIsolatedProcess(true); |
Michael Lentine | 2ba303f | 2016-02-01 20:44:34 -0600 | [diff] [blame] | 6454 | } |
Michael Lentine | 03d8f768 | 2016-01-31 15:37:11 -0600 | [diff] [blame] | 6455 | |
Chad Brubaker | 78d4712 | 2015-11-17 22:26:58 -0800 | [diff] [blame] | 6456 | // Install the Network Security Config Provider. This must happen before the application |
| 6457 | // code is loaded to prevent issues with instances of TLS objects being created before |
| 6458 | // the provider is installed. |
Andreas Gampe | 4c8e542 | 2016-05-18 11:58:47 -0700 | [diff] [blame] | 6459 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "NetworkSecurityConfigProvider.install"); |
Chad Brubaker | 276ee96 | 2016-06-08 12:57:46 -0700 | [diff] [blame] | 6460 | NetworkSecurityConfigProvider.install(appContext); |
Andreas Gampe | 4c8e542 | 2016-05-18 11:58:47 -0700 | [diff] [blame] | 6461 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Chad Brubaker | 78d4712 | 2015-11-17 22:26:58 -0800 | [diff] [blame] | 6462 | |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 6463 | // Continue loading instrumentation. |
| 6464 | if (ii != null) { |
Dianne Hackborn | f4ef6eb | 2017-12-07 13:57:21 -0800 | [diff] [blame] | 6465 | ApplicationInfo instrApp; |
| 6466 | try { |
| 6467 | instrApp = getPackageManager().getApplicationInfo(ii.packageName, 0, |
| 6468 | UserHandle.myUserId()); |
| 6469 | } catch (RemoteException e) { |
| 6470 | instrApp = null; |
| 6471 | } |
| 6472 | if (instrApp == null) { |
| 6473 | instrApp = new ApplicationInfo(); |
| 6474 | } |
Jeff Sharkey | 1544779 | 2015-11-05 16:18:51 -0800 | [diff] [blame] | 6475 | ii.copyTo(instrApp); |
Fyodor Kupolov | af38b8e | 2015-12-02 16:16:07 -0800 | [diff] [blame] | 6476 | instrApp.initForUser(UserHandle.myUserId()); |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 6477 | final LoadedApk pi = getPackageInfo(instrApp, data.compatInfo, |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 6478 | appContext.getClassLoader(), false, true, false); |
Makoto Onuki | 4becc35 | 2019-01-30 13:30:41 -0800 | [diff] [blame] | 6479 | |
| 6480 | // The test context's op package name == the target app's op package name, because |
| 6481 | // the app ops manager checks the op package name against the real calling UID, |
| 6482 | // which is what the target package name is associated with. |
| 6483 | final ContextImpl instrContext = ContextImpl.createAppContext(this, pi, |
| 6484 | appContext.getOpPackageName()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6485 | |
| 6486 | try { |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 6487 | final ClassLoader cl = instrContext.getClassLoader(); |
Dan Sandler | 07fe63e | 2017-08-15 16:41:11 -0400 | [diff] [blame] | 6488 | mInstrumentation = (Instrumentation) |
| 6489 | cl.loadClass(data.instrumentationName.getClassName()).newInstance(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6490 | } catch (Exception e) { |
| 6491 | throw new RuntimeException( |
| 6492 | "Unable to instantiate instrumentation " |
| 6493 | + data.instrumentationName + ": " + e.toString(), e); |
| 6494 | } |
| 6495 | |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 6496 | final ComponentName component = new ComponentName(ii.packageName, ii.name); |
| 6497 | mInstrumentation.init(this, instrContext, appContext, component, |
| 6498 | data.instrumentationWatcher, data.instrumentationUiAutomationConnection); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6499 | |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 6500 | if (mProfiler.profileFile != null && !ii.handleProfiling |
| 6501 | && mProfiler.profileFd == null) { |
| 6502 | mProfiler.handlingProfiling = true; |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 6503 | final File file = new File(mProfiler.profileFile); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6504 | file.getParentFile().mkdirs(); |
| 6505 | Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024); |
| 6506 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6507 | } else { |
| 6508 | mInstrumentation = new Instrumentation(); |
Jason Monk | a80bfb5 | 2017-11-16 17:15:37 -0500 | [diff] [blame] | 6509 | mInstrumentation.basicInit(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6510 | } |
| 6511 | |
Dianne Hackborn | 3b81bc1 | 2011-01-15 11:50:52 -0800 | [diff] [blame] | 6512 | if ((data.appInfo.flags&ApplicationInfo.FLAG_LARGE_HEAP) != 0) { |
Dianne Hackborn | de39851 | 2011-01-18 18:45:21 -0800 | [diff] [blame] | 6513 | dalvik.system.VMRuntime.getRuntime().clearGrowthLimit(); |
Mathieu Chartier | 24cee07 | 2015-01-08 14:42:20 -0800 | [diff] [blame] | 6514 | } else { |
| 6515 | // Small heap, clamp to the current growth limit and let the heap release |
| 6516 | // pages after the growth limit to the non growth limit capacity. b/18387825 |
| 6517 | dalvik.system.VMRuntime.getRuntime().clampGrowthLimit(); |
Dianne Hackborn | 3b81bc1 | 2011-01-15 11:50:52 -0800 | [diff] [blame] | 6518 | } |
| 6519 | |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 6520 | // Allow disk access during application and provider setup. This could |
Jeff Sharkey | 7c50167 | 2012-02-28 12:08:37 -0800 | [diff] [blame] | 6521 | // block processing ordered broadcasts, but later processing would |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 6522 | // probably end up doing the same disk access. |
Kurt Nelson | 5e15436 | 2017-06-29 17:20:56 -0700 | [diff] [blame] | 6523 | Application app; |
Jeff Sharkey | 7c50167 | 2012-02-28 12:08:37 -0800 | [diff] [blame] | 6524 | final StrictMode.ThreadPolicy savedPolicy = StrictMode.allowThreadDiskWrites(); |
Kurt Nelson | 571c3f6 | 2017-07-10 11:09:04 -0700 | [diff] [blame] | 6525 | final StrictMode.ThreadPolicy writesAllowedPolicy = StrictMode.getThreadPolicy(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6526 | try { |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 6527 | // If the app is being launched for full backup or restore, bring it up in |
| 6528 | // a restricted environment with the base application class. |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 6529 | app = data.info.makeApplication(data.restrictedBackupMode, null); |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 6530 | |
| 6531 | // Propagate autofill compat state |
Felipe Leme | a4f39cd | 2019-02-19 15:08:59 -0800 | [diff] [blame] | 6532 | app.setAutofillOptions(data.autofillOptions); |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 6533 | |
Felipe Leme | 326f15a | 2019-02-19 09:42:24 -0800 | [diff] [blame] | 6534 | // Propagate Content Capture options |
| 6535 | app.setContentCaptureOptions(data.contentCaptureOptions); |
| 6536 | |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 6537 | mInitialApplication = app; |
Jeff Sharkey | 7c50167 | 2012-02-28 12:08:37 -0800 | [diff] [blame] | 6538 | |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 6539 | // don't bring up providers in restricted mode; they may depend on the |
| 6540 | // app's custom Application class |
| 6541 | if (!data.restrictedBackupMode) { |
Jeff Sharkey | 3e19589 | 2016-03-05 19:48:59 -0700 | [diff] [blame] | 6542 | if (!ArrayUtils.isEmpty(data.providers)) { |
| 6543 | installContentProviders(app, data.providers); |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 6544 | } |
| 6545 | } |
| 6546 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6547 | // Do this after providers, since instrumentation tests generally start their |
| 6548 | // test thread at this point, and we don't want that racing. |
| 6549 | try { |
| 6550 | mInstrumentation.onCreate(data.instrumentationArgs); |
| 6551 | } |
| 6552 | catch (Exception e) { |
| 6553 | throw new RuntimeException( |
| 6554 | "Exception thrown in onCreate() of " |
| 6555 | + data.instrumentationName + ": " + e.toString(), e); |
| 6556 | } |
Kurt Nelson | 571c3f6 | 2017-07-10 11:09:04 -0700 | [diff] [blame] | 6557 | try { |
| 6558 | mInstrumentation.callApplicationOnCreate(app); |
| 6559 | } catch (Exception e) { |
| 6560 | if (!mInstrumentation.onException(app, e)) { |
| 6561 | throw new RuntimeException( |
| 6562 | "Unable to create application " + app.getClass().getName() |
| 6563 | + ": " + e.toString(), e); |
| 6564 | } |
| 6565 | } |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 6566 | } finally { |
Kurt Nelson | 571c3f6 | 2017-07-10 11:09:04 -0700 | [diff] [blame] | 6567 | // If the app targets < O-MR1, or doesn't change the thread policy |
| 6568 | // during startup, clobber the policy to maintain behavior of b/36951662 |
Jeff Sharkey | aa1a911 | 2018-04-10 15:18:12 -0600 | [diff] [blame] | 6569 | if (data.appInfo.targetSdkVersion < Build.VERSION_CODES.O_MR1 |
Kurt Nelson | 571c3f6 | 2017-07-10 11:09:04 -0700 | [diff] [blame] | 6570 | || StrictMode.getThreadPolicy().equals(writesAllowedPolicy)) { |
| 6571 | StrictMode.setThreadPolicy(savedPolicy); |
Kurt Nelson | 5e15436 | 2017-06-29 17:20:56 -0700 | [diff] [blame] | 6572 | } |
| 6573 | } |
| 6574 | |
Clara Bayarri | 4b5a4d2 | 2017-01-27 20:15:45 +0000 | [diff] [blame] | 6575 | // Preload fonts resources |
Seigo Nonaka | 54084b6 | 2017-04-24 14:46:23 -0700 | [diff] [blame] | 6576 | FontsContract.setApplicationContextForResources(appContext); |
Torne (Richard Coles) | 85ecae5 | 2018-01-30 18:13:00 -0500 | [diff] [blame] | 6577 | if (!Process.isIsolated()) { |
| 6578 | try { |
| 6579 | final ApplicationInfo info = |
| 6580 | getPackageManager().getApplicationInfo( |
| 6581 | data.appInfo.packageName, |
| 6582 | PackageManager.GET_META_DATA /*flags*/, |
| 6583 | UserHandle.myUserId()); |
| 6584 | if (info.metaData != null) { |
| 6585 | final int preloadedFontsResource = info.metaData.getInt( |
| 6586 | ApplicationInfo.METADATA_PRELOADED_FONTS, 0); |
| 6587 | if (preloadedFontsResource != 0) { |
| 6588 | data.info.getResources().preloadFonts(preloadedFontsResource); |
| 6589 | } |
Clara Bayarri | 4b5a4d2 | 2017-01-27 20:15:45 +0000 | [diff] [blame] | 6590 | } |
Torne (Richard Coles) | 85ecae5 | 2018-01-30 18:13:00 -0500 | [diff] [blame] | 6591 | } catch (RemoteException e) { |
| 6592 | throw e.rethrowFromSystemServer(); |
Clara Bayarri | 4b5a4d2 | 2017-01-27 20:15:45 +0000 | [diff] [blame] | 6593 | } |
Clara Bayarri | 4b5a4d2 | 2017-01-27 20:15:45 +0000 | [diff] [blame] | 6594 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6595 | } |
| 6596 | |
| 6597 | /*package*/ final void finishInstrumentation(int resultCode, Bundle results) { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6598 | IActivityManager am = ActivityManager.getService(); |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 6599 | if (mProfiler.profileFile != null && mProfiler.handlingProfiling |
| 6600 | && mProfiler.profileFd == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6601 | Debug.stopMethodTracing(); |
| 6602 | } |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6603 | //Slog.i(TAG, "am: " + ActivityManager.getService() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6604 | // + ", app thr: " + mAppThread); |
| 6605 | try { |
| 6606 | am.finishInstrumentation(mAppThread, resultCode, results); |
| 6607 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 6608 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6609 | } |
| 6610 | } |
| 6611 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 6612 | @UnsupportedAppUsage |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 6613 | private void installContentProviders( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6614 | Context context, List<ProviderInfo> providers) { |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 6615 | final ArrayList<ContentProviderHolder> results = new ArrayList<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6616 | |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 6617 | for (ProviderInfo cpi : providers) { |
Dianne Hackborn | 40e9f29 | 2012-11-27 19:12:23 -0800 | [diff] [blame] | 6618 | if (DEBUG_PROVIDER) { |
| 6619 | StringBuilder buf = new StringBuilder(128); |
| 6620 | buf.append("Pub "); |
| 6621 | buf.append(cpi.authority); |
| 6622 | buf.append(": "); |
| 6623 | buf.append(cpi.name); |
| 6624 | Log.i(TAG, buf.toString()); |
| 6625 | } |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 6626 | ContentProviderHolder cph = installProvider(context, null, cpi, |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6627 | false /*noisy*/, true /*noReleaseNeeded*/, true /*stable*/); |
| 6628 | if (cph != null) { |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6629 | cph.noReleaseNeeded = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6630 | results.add(cph); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6631 | } |
| 6632 | } |
| 6633 | |
| 6634 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6635 | ActivityManager.getService().publishContentProviders( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6636 | getApplicationThread(), results); |
| 6637 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 6638 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6639 | } |
| 6640 | } |
| 6641 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 6642 | @UnsupportedAppUsage |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 6643 | public final IContentProvider acquireProvider( |
| 6644 | Context c, String auth, int userId, boolean stable) { |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 6645 | final IContentProvider provider = acquireExistingProvider(c, auth, userId, stable); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6646 | if (provider != null) { |
| 6647 | return provider; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6648 | } |
| 6649 | |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 6650 | // There is a possible race here. Another thread may try to acquire |
| 6651 | // the same provider at the same time. When this happens, we want to ensure |
| 6652 | // that the first one wins. |
| 6653 | // Note that we cannot hold the lock while acquiring and installing the |
| 6654 | // provider since it might take a long time to run and it could also potentially |
| 6655 | // 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] | 6656 | ContentProviderHolder holder = null; |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 6657 | try { |
Makoto Onuki | b6c79ea | 2018-05-31 11:03:56 -0700 | [diff] [blame] | 6658 | synchronized (getGetProviderLock(auth, userId)) { |
| 6659 | holder = ActivityManager.getService().getContentProvider( |
Dianne Hackborn | 24bbe58 | 2018-12-17 11:58:31 -0800 | [diff] [blame] | 6660 | getApplicationThread(), c.getOpPackageName(), auth, userId, stable); |
Makoto Onuki | b6c79ea | 2018-05-31 11:03:56 -0700 | [diff] [blame] | 6661 | } |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 6662 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 6663 | throw ex.rethrowFromSystemServer(); |
Wale Ogunwale | 67fe0a4 | 2015-04-24 14:44:54 -0700 | [diff] [blame] | 6664 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6665 | if (holder == null) { |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 6666 | 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] | 6667 | return null; |
| 6668 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6669 | |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6670 | // Install provider will increment the reference count for us, and break |
| 6671 | // any ties in the race. |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6672 | holder = installProvider(c, holder, holder.info, |
| 6673 | true /*noisy*/, holder.noReleaseNeeded, stable); |
| 6674 | return holder.provider; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6675 | } |
| 6676 | |
Makoto Onuki | b6c79ea | 2018-05-31 11:03:56 -0700 | [diff] [blame] | 6677 | private Object getGetProviderLock(String auth, int userId) { |
| 6678 | final ProviderKey key = new ProviderKey(auth, userId); |
| 6679 | synchronized (mGetProviderLocks) { |
| 6680 | Object lock = mGetProviderLocks.get(key); |
| 6681 | if (lock == null) { |
| 6682 | lock = key; |
| 6683 | mGetProviderLocks.put(key, lock); |
| 6684 | } |
| 6685 | return lock; |
| 6686 | } |
| 6687 | } |
| 6688 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6689 | private final void incProviderRefLocked(ProviderRefCount prc, boolean stable) { |
| 6690 | if (stable) { |
| 6691 | prc.stableCount += 1; |
| 6692 | if (prc.stableCount == 1) { |
| 6693 | // We are acquiring a new stable reference on the provider. |
| 6694 | int unstableDelta; |
| 6695 | if (prc.removePending) { |
| 6696 | // We have a pending remove operation, which is holding the |
| 6697 | // last unstable reference. At this point we are converting |
| 6698 | // that unstable reference to our new stable reference. |
| 6699 | unstableDelta = -1; |
| 6700 | // Cancel the removal of the provider. |
| 6701 | if (DEBUG_PROVIDER) { |
| 6702 | Slog.v(TAG, "incProviderRef: stable " |
| 6703 | + "snatched provider from the jaws of death"); |
| 6704 | } |
| 6705 | prc.removePending = false; |
Guobin Zhang | 9e3e5266 | 2013-03-21 13:57:11 +0800 | [diff] [blame] | 6706 | // There is a race! It fails to remove the message, which |
| 6707 | // will be handled in completeRemoveProvider(). |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6708 | mH.removeMessages(H.REMOVE_PROVIDER, prc); |
| 6709 | } else { |
| 6710 | unstableDelta = 0; |
| 6711 | } |
| 6712 | try { |
| 6713 | if (DEBUG_PROVIDER) { |
| 6714 | Slog.v(TAG, "incProviderRef Now stable - " |
| 6715 | + prc.holder.info.name + ": unstableDelta=" |
| 6716 | + unstableDelta); |
| 6717 | } |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6718 | ActivityManager.getService().refContentProvider( |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6719 | prc.holder.connection, 1, unstableDelta); |
| 6720 | } catch (RemoteException e) { |
| 6721 | //do nothing content provider object is dead any way |
| 6722 | } |
| 6723 | } |
| 6724 | } else { |
| 6725 | prc.unstableCount += 1; |
| 6726 | if (prc.unstableCount == 1) { |
| 6727 | // We are acquiring a new unstable reference on the provider. |
| 6728 | if (prc.removePending) { |
| 6729 | // Oh look, we actually have a remove pending for the |
| 6730 | // provider, which is still holding the last unstable |
| 6731 | // reference. We just need to cancel that to take new |
| 6732 | // ownership of the reference. |
| 6733 | if (DEBUG_PROVIDER) { |
| 6734 | Slog.v(TAG, "incProviderRef: unstable " |
| 6735 | + "snatched provider from the jaws of death"); |
| 6736 | } |
| 6737 | prc.removePending = false; |
| 6738 | mH.removeMessages(H.REMOVE_PROVIDER, prc); |
| 6739 | } else { |
| 6740 | // First unstable ref, increment our count in the |
| 6741 | // activity manager. |
| 6742 | try { |
| 6743 | if (DEBUG_PROVIDER) { |
| 6744 | Slog.v(TAG, "incProviderRef: Now unstable - " |
| 6745 | + prc.holder.info.name); |
| 6746 | } |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6747 | ActivityManager.getService().refContentProvider( |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6748 | prc.holder.connection, 0, 1); |
| 6749 | } catch (RemoteException e) { |
| 6750 | //do nothing content provider object is dead any way |
| 6751 | } |
| 6752 | } |
| 6753 | } |
| 6754 | } |
| 6755 | } |
| 6756 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 6757 | @UnsupportedAppUsage |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 6758 | public final IContentProvider acquireExistingProvider( |
| 6759 | Context c, String auth, int userId, boolean stable) { |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6760 | synchronized (mProviderMap) { |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 6761 | final ProviderKey key = new ProviderKey(auth, userId); |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 6762 | final ProviderClientRecord pr = mProviderMap.get(key); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6763 | if (pr == null) { |
| 6764 | return null; |
| 6765 | } |
| 6766 | |
| 6767 | IContentProvider provider = pr.mProvider; |
| 6768 | IBinder jBinder = provider.asBinder(); |
Dianne Hackborn | c428aae | 2012-10-03 16:38:22 -0700 | [diff] [blame] | 6769 | if (!jBinder.isBinderAlive()) { |
| 6770 | // The hosting process of the provider has died; we can't |
| 6771 | // use this one. |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 6772 | Log.i(TAG, "Acquiring provider " + auth + " for user " + userId |
Dianne Hackborn | c428aae | 2012-10-03 16:38:22 -0700 | [diff] [blame] | 6773 | + ": existing object's process dead"); |
| 6774 | handleUnstableProviderDiedLocked(jBinder, true); |
| 6775 | return null; |
| 6776 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6777 | |
| 6778 | // Only increment the ref count if we have one. If we don't then the |
| 6779 | // provider is not reference counted and never needs to be released. |
Dianne Hackborn | cca1f0e | 2010-09-26 18:34:53 -0700 | [diff] [blame] | 6780 | ProviderRefCount prc = mProviderRefCountMap.get(jBinder); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6781 | if (prc != null) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6782 | incProviderRefLocked(prc, stable); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6783 | } |
| 6784 | return provider; |
| 6785 | } |
Dianne Hackborn | cca1f0e | 2010-09-26 18:34:53 -0700 | [diff] [blame] | 6786 | } |
| 6787 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 6788 | @UnsupportedAppUsage |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6789 | public final boolean releaseProvider(IContentProvider provider, boolean stable) { |
| 6790 | if (provider == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6791 | return false; |
| 6792 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6793 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6794 | IBinder jBinder = provider.asBinder(); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6795 | synchronized (mProviderMap) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6796 | ProviderRefCount prc = mProviderRefCountMap.get(jBinder); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6797 | if (prc == null) { |
| 6798 | // 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] | 6799 | return false; |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6800 | } |
| 6801 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6802 | boolean lastRef = false; |
| 6803 | if (stable) { |
| 6804 | if (prc.stableCount == 0) { |
| 6805 | if (DEBUG_PROVIDER) Slog.v(TAG, |
| 6806 | "releaseProvider: stable ref count already 0, how?"); |
| 6807 | return false; |
| 6808 | } |
| 6809 | prc.stableCount -= 1; |
| 6810 | if (prc.stableCount == 0) { |
| 6811 | // What we do at this point depends on whether there are |
| 6812 | // any unstable refs left: if there are, we just tell the |
| 6813 | // activity manager to decrement its stable count; if there |
| 6814 | // aren't, we need to enqueue this provider to be removed, |
| 6815 | // and convert to holding a single unstable ref while |
| 6816 | // doing so. |
| 6817 | lastRef = prc.unstableCount == 0; |
| 6818 | try { |
| 6819 | if (DEBUG_PROVIDER) { |
| 6820 | Slog.v(TAG, "releaseProvider: No longer stable w/lastRef=" |
| 6821 | + lastRef + " - " + prc.holder.info.name); |
| 6822 | } |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6823 | ActivityManager.getService().refContentProvider( |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6824 | prc.holder.connection, -1, lastRef ? 1 : 0); |
| 6825 | } catch (RemoteException e) { |
| 6826 | //do nothing content provider object is dead any way |
| 6827 | } |
| 6828 | } |
| 6829 | } else { |
| 6830 | if (prc.unstableCount == 0) { |
| 6831 | if (DEBUG_PROVIDER) Slog.v(TAG, |
| 6832 | "releaseProvider: unstable ref count already 0, how?"); |
| 6833 | return false; |
| 6834 | } |
| 6835 | prc.unstableCount -= 1; |
| 6836 | if (prc.unstableCount == 0) { |
| 6837 | // If this is the last reference, we need to enqueue |
| 6838 | // this provider to be removed instead of telling the |
| 6839 | // activity manager to remove it at this point. |
| 6840 | lastRef = prc.stableCount == 0; |
| 6841 | if (!lastRef) { |
| 6842 | try { |
| 6843 | if (DEBUG_PROVIDER) { |
| 6844 | Slog.v(TAG, "releaseProvider: No longer unstable - " |
| 6845 | + prc.holder.info.name); |
| 6846 | } |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6847 | ActivityManager.getService().refContentProvider( |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6848 | prc.holder.connection, 0, -1); |
| 6849 | } catch (RemoteException e) { |
| 6850 | //do nothing content provider object is dead any way |
| 6851 | } |
| 6852 | } |
| 6853 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6854 | } |
| 6855 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6856 | if (lastRef) { |
| 6857 | if (!prc.removePending) { |
| 6858 | // Schedule the actual remove asynchronously, since we don't know the context |
| 6859 | // this will be called in. |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6860 | if (DEBUG_PROVIDER) { |
| 6861 | Slog.v(TAG, "releaseProvider: Enqueueing pending removal - " |
| 6862 | + prc.holder.info.name); |
| 6863 | } |
| 6864 | prc.removePending = true; |
| 6865 | Message msg = mH.obtainMessage(H.REMOVE_PROVIDER, prc); |
Riddle Hsu | 4e8e3b0 | 2019-04-12 17:37:10 +0800 | [diff] [blame] | 6866 | mH.sendMessageDelayed(msg, CONTENT_PROVIDER_RETAIN_TIME); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6867 | } else { |
| 6868 | Slog.w(TAG, "Duplicate remove pending of provider " + prc.holder.info.name); |
| 6869 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6870 | } |
| 6871 | return true; |
| 6872 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6873 | } |
| 6874 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6875 | final void completeRemoveProvider(ProviderRefCount prc) { |
| 6876 | synchronized (mProviderMap) { |
| 6877 | if (!prc.removePending) { |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6878 | // There was a race! Some other client managed to acquire |
| 6879 | // the provider before the removal was completed. |
| 6880 | // Abort the removal. We will do it later. |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6881 | if (DEBUG_PROVIDER) Slog.v(TAG, "completeRemoveProvider: lost the race, " |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6882 | + "provider still in use"); |
| 6883 | return; |
| 6884 | } |
| 6885 | |
Guobin Zhang | 9e3e5266 | 2013-03-21 13:57:11 +0800 | [diff] [blame] | 6886 | // More complicated race!! Some client managed to acquire the |
| 6887 | // provider and release it before the removal was completed. |
| 6888 | // Continue the removal, and abort the next remove message. |
| 6889 | prc.removePending = false; |
| 6890 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6891 | final IBinder jBinder = prc.holder.provider.asBinder(); |
| 6892 | ProviderRefCount existingPrc = mProviderRefCountMap.get(jBinder); |
| 6893 | if (existingPrc == prc) { |
| 6894 | mProviderRefCountMap.remove(jBinder); |
| 6895 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6896 | |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 6897 | for (int i=mProviderMap.size()-1; i>=0; i--) { |
| 6898 | ProviderClientRecord pr = mProviderMap.valueAt(i); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6899 | IBinder myBinder = pr.mProvider.asBinder(); |
| 6900 | if (myBinder == jBinder) { |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 6901 | mProviderMap.removeAt(i); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6902 | } |
| 6903 | } |
| 6904 | } |
| 6905 | |
| 6906 | try { |
| 6907 | if (DEBUG_PROVIDER) { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6908 | Slog.v(TAG, "removeProvider: Invoking ActivityManagerService." |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6909 | + "removeContentProvider(" + prc.holder.info.name + ")"); |
| 6910 | } |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6911 | ActivityManager.getService().removeContentProvider( |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6912 | prc.holder.connection, false); |
| 6913 | } catch (RemoteException e) { |
| 6914 | //do nothing content provider object is dead any way |
| 6915 | } |
| 6916 | } |
| 6917 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 6918 | @UnsupportedAppUsage |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6919 | final void handleUnstableProviderDied(IBinder provider, boolean fromClient) { |
Dianne Hackborn | c428aae | 2012-10-03 16:38:22 -0700 | [diff] [blame] | 6920 | synchronized (mProviderMap) { |
| 6921 | handleUnstableProviderDiedLocked(provider, fromClient); |
| 6922 | } |
| 6923 | } |
| 6924 | |
| 6925 | final void handleUnstableProviderDiedLocked(IBinder provider, boolean fromClient) { |
| 6926 | ProviderRefCount prc = mProviderRefCountMap.get(provider); |
| 6927 | if (prc != null) { |
| 6928 | if (DEBUG_PROVIDER) Slog.v(TAG, "Cleaning up dead provider " |
| 6929 | + provider + " " + prc.holder.info.name); |
| 6930 | mProviderRefCountMap.remove(provider); |
You Kim | bc74de6 | 2013-10-01 00:13:26 +0900 | [diff] [blame] | 6931 | for (int i=mProviderMap.size()-1; i>=0; i--) { |
| 6932 | ProviderClientRecord pr = mProviderMap.valueAt(i); |
| 6933 | if (pr != null && pr.mProvider.asBinder() == provider) { |
| 6934 | Slog.i(TAG, "Removing dead content provider:" + pr.mProvider.toString()); |
| 6935 | mProviderMap.removeAt(i); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6936 | } |
Dianne Hackborn | c428aae | 2012-10-03 16:38:22 -0700 | [diff] [blame] | 6937 | } |
You Kim | bc74de6 | 2013-10-01 00:13:26 +0900 | [diff] [blame] | 6938 | |
Dianne Hackborn | c428aae | 2012-10-03 16:38:22 -0700 | [diff] [blame] | 6939 | if (fromClient) { |
| 6940 | // We found out about this due to execution in our client |
| 6941 | // code. Tell the activity manager about it now, to ensure |
| 6942 | // that the next time we go to do anything with the provider |
| 6943 | // it knows it is dead (so we don't race with its death |
| 6944 | // notification). |
| 6945 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6946 | ActivityManager.getService().unstableProviderDied( |
Dianne Hackborn | c428aae | 2012-10-03 16:38:22 -0700 | [diff] [blame] | 6947 | prc.holder.connection); |
| 6948 | } catch (RemoteException e) { |
| 6949 | //do nothing content provider object is dead any way |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6950 | } |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 6951 | } |
| 6952 | } |
| 6953 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6954 | |
Jeff Sharkey | 7aa7601 | 2013-09-30 14:26:27 -0700 | [diff] [blame] | 6955 | final void appNotRespondingViaProvider(IBinder provider) { |
| 6956 | synchronized (mProviderMap) { |
| 6957 | ProviderRefCount prc = mProviderRefCountMap.get(provider); |
| 6958 | if (prc != null) { |
| 6959 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6960 | ActivityManager.getService() |
Jeff Sharkey | 7aa7601 | 2013-09-30 14:26:27 -0700 | [diff] [blame] | 6961 | .appNotRespondingViaProvider(prc.holder.connection); |
| 6962 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 6963 | throw e.rethrowFromSystemServer(); |
Jeff Sharkey | 7aa7601 | 2013-09-30 14:26:27 -0700 | [diff] [blame] | 6964 | } |
| 6965 | } |
| 6966 | } |
| 6967 | } |
| 6968 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6969 | private ProviderClientRecord installProviderAuthoritiesLocked(IContentProvider provider, |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 6970 | ContentProvider localProvider, ContentProviderHolder holder) { |
Andreas Gampe | 18e99c1 | 2015-03-06 15:29:06 -0800 | [diff] [blame] | 6971 | final String auths[] = holder.info.authority.split(";"); |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 6972 | final int userId = UserHandle.getUserId(holder.info.applicationInfo.uid); |
| 6973 | |
Jeff Sharkey | 0a17db1 | 2016-11-04 11:23:46 -0600 | [diff] [blame] | 6974 | if (provider != null) { |
| 6975 | // If this provider is hosted by the core OS and cannot be upgraded, |
| 6976 | // then I guess we're okay doing blocking calls to it. |
| 6977 | for (String auth : auths) { |
| 6978 | switch (auth) { |
| 6979 | case ContactsContract.AUTHORITY: |
| 6980 | case CallLog.AUTHORITY: |
| 6981 | case CallLog.SHADOW_AUTHORITY: |
| 6982 | case BlockedNumberContract.AUTHORITY: |
| 6983 | case CalendarContract.AUTHORITY: |
| 6984 | case Downloads.Impl.AUTHORITY: |
Jeff Sharkey | cb62162 | 2016-11-11 14:04:32 -0700 | [diff] [blame] | 6985 | case "telephony": |
Jeff Sharkey | 0a17db1 | 2016-11-04 11:23:46 -0600 | [diff] [blame] | 6986 | Binder.allowBlocking(provider.asBinder()); |
| 6987 | } |
| 6988 | } |
| 6989 | } |
| 6990 | |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 6991 | final ProviderClientRecord pcr = new ProviderClientRecord( |
| 6992 | auths, provider, localProvider, holder); |
| 6993 | for (String auth : auths) { |
| 6994 | final ProviderKey key = new ProviderKey(auth, userId); |
| 6995 | final ProviderClientRecord existing = mProviderMap.get(key); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6996 | if (existing != null) { |
| 6997 | Slog.w(TAG, "Content provider " + pcr.mHolder.info.name |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 6998 | + " already published as " + auth); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6999 | } else { |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 7000 | mProviderMap.put(key, pcr); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7001 | } |
| 7002 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 7003 | return pcr; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7004 | } |
| 7005 | |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 7006 | /** |
| 7007 | * Installs the provider. |
| 7008 | * |
| 7009 | * Providers that are local to the process or that come from the system server |
| 7010 | * may be installed permanently which is indicated by setting noReleaseNeeded to true. |
| 7011 | * Other remote providers are reference counted. The initial reference count |
| 7012 | * for all reference counted providers is one. Providers that are not reference |
| 7013 | * counted do not have a reference count (at all). |
| 7014 | * |
| 7015 | * This method detects when a provider has already been installed. When this happens, |
| 7016 | * it increments the reference count of the existing provider (if appropriate) |
| 7017 | * and returns the existing provider. This can happen due to concurrent |
| 7018 | * attempts to acquire the same provider. |
| 7019 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 7020 | @UnsupportedAppUsage |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 7021 | private ContentProviderHolder installProvider(Context context, |
| 7022 | ContentProviderHolder holder, ProviderInfo info, |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 7023 | boolean noisy, boolean noReleaseNeeded, boolean stable) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7024 | ContentProvider localProvider = null; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 7025 | IContentProvider provider; |
Dianne Hackborn | 5f48fca | 2012-05-30 11:06:31 -0700 | [diff] [blame] | 7026 | if (holder == null || holder.provider == null) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 7027 | if (DEBUG_PROVIDER || noisy) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 7028 | Slog.d(TAG, "Loading provider " + info.authority + ": " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7029 | + info.name); |
| 7030 | } |
| 7031 | Context c = null; |
| 7032 | ApplicationInfo ai = info.applicationInfo; |
| 7033 | if (context.getPackageName().equals(ai.packageName)) { |
| 7034 | c = context; |
| 7035 | } else if (mInitialApplication != null && |
| 7036 | mInitialApplication.getPackageName().equals(ai.packageName)) { |
| 7037 | c = mInitialApplication; |
| 7038 | } else { |
| 7039 | try { |
| 7040 | c = context.createPackageContext(ai.packageName, |
| 7041 | Context.CONTEXT_INCLUDE_CODE); |
| 7042 | } catch (PackageManager.NameNotFoundException e) { |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 7043 | // Ignore |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7044 | } |
| 7045 | } |
| 7046 | if (c == null) { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 7047 | Slog.w(TAG, "Unable to get context for package " + |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7048 | ai.packageName + |
| 7049 | " while loading content provider " + |
| 7050 | info.name); |
| 7051 | return null; |
| 7052 | } |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 7053 | |
| 7054 | if (info.splitName != null) { |
| 7055 | try { |
| 7056 | c = c.createContextForSplit(info.splitName); |
| 7057 | } catch (NameNotFoundException e) { |
| 7058 | throw new RuntimeException(e); |
| 7059 | } |
| 7060 | } |
| 7061 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7062 | try { |
| 7063 | final java.lang.ClassLoader cl = c.getClassLoader(); |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 7064 | LoadedApk packageInfo = peekPackageInfo(ai.packageName, true); |
| 7065 | if (packageInfo == null) { |
Jason Monk | a80bfb5 | 2017-11-16 17:15:37 -0500 | [diff] [blame] | 7066 | // System startup case. |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 7067 | packageInfo = getSystemContext().mPackageInfo; |
Jason Monk | a80bfb5 | 2017-11-16 17:15:37 -0500 | [diff] [blame] | 7068 | } |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 7069 | localProvider = packageInfo.getAppFactory() |
Jason Monk | a80bfb5 | 2017-11-16 17:15:37 -0500 | [diff] [blame] | 7070 | .instantiateProvider(cl, info.name); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7071 | provider = localProvider.getIContentProvider(); |
| 7072 | if (provider == null) { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 7073 | Slog.e(TAG, "Failed to instantiate class " + |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7074 | info.name + " from sourceDir " + |
| 7075 | info.applicationInfo.sourceDir); |
| 7076 | return null; |
| 7077 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 7078 | if (DEBUG_PROVIDER) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7079 | TAG, "Instantiating local provider " + info.name); |
| 7080 | // XXX Need to create the correct context for this provider. |
| 7081 | localProvider.attachInfo(c, info); |
| 7082 | } catch (java.lang.Exception e) { |
| 7083 | if (!mInstrumentation.onException(null, e)) { |
| 7084 | throw new RuntimeException( |
| 7085 | "Unable to get provider " + info.name |
| 7086 | + ": " + e.toString(), e); |
| 7087 | } |
| 7088 | return null; |
| 7089 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 7090 | } else { |
| 7091 | provider = holder.provider; |
| 7092 | 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] | 7093 | + info.name); |
| 7094 | } |
| 7095 | |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 7096 | ContentProviderHolder retHolder; |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 7097 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 7098 | synchronized (mProviderMap) { |
| 7099 | if (DEBUG_PROVIDER) Slog.v(TAG, "Checking to add " + provider |
| 7100 | + " / " + info.name); |
| 7101 | IBinder jBinder = provider.asBinder(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7102 | if (localProvider != null) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 7103 | ComponentName cname = new ComponentName(info.packageName, info.name); |
| 7104 | ProviderClientRecord pr = mLocalProvidersByName.get(cname); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 7105 | if (pr != null) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 7106 | if (DEBUG_PROVIDER) { |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 7107 | Slog.v(TAG, "installProvider: lost the race, " |
| 7108 | + "using existing local provider"); |
| 7109 | } |
| 7110 | provider = pr.mProvider; |
| 7111 | } else { |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 7112 | holder = new ContentProviderHolder(info); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 7113 | holder.provider = provider; |
| 7114 | holder.noReleaseNeeded = true; |
| 7115 | pr = installProviderAuthoritiesLocked(provider, localProvider, holder); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 7116 | mLocalProviders.put(jBinder, pr); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 7117 | mLocalProvidersByName.put(cname, pr); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 7118 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 7119 | retHolder = pr.mHolder; |
| 7120 | } else { |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 7121 | ProviderRefCount prc = mProviderRefCountMap.get(jBinder); |
| 7122 | if (prc != null) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 7123 | if (DEBUG_PROVIDER) { |
| 7124 | Slog.v(TAG, "installProvider: lost the race, updating ref count"); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 7125 | } |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 7126 | // We need to transfer our new reference to the existing |
| 7127 | // ref count, releasing the old one... but only if |
| 7128 | // release is needed (that is, it is not running in the |
| 7129 | // system process). |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 7130 | if (!noReleaseNeeded) { |
| 7131 | incProviderRefLocked(prc, stable); |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 7132 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 7133 | ActivityManager.getService().removeContentProvider( |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 7134 | holder.connection, stable); |
| 7135 | } catch (RemoteException e) { |
| 7136 | //do nothing content provider object is dead any way |
| 7137 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 7138 | } |
| 7139 | } else { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 7140 | ProviderClientRecord client = installProviderAuthoritiesLocked( |
| 7141 | provider, localProvider, holder); |
| 7142 | if (noReleaseNeeded) { |
| 7143 | prc = new ProviderRefCount(holder, client, 1000, 1000); |
| 7144 | } else { |
| 7145 | prc = stable |
| 7146 | ? new ProviderRefCount(holder, client, 1, 0) |
| 7147 | : new ProviderRefCount(holder, client, 0, 1); |
| 7148 | } |
| 7149 | mProviderRefCountMap.put(jBinder, prc); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 7150 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 7151 | retHolder = prc.holder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7152 | } |
| 7153 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 7154 | return retHolder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7155 | } |
| 7156 | |
Torne (Richard Coles) | 466cbe4 | 2017-05-31 14:09:14 -0400 | [diff] [blame] | 7157 | private void handleRunIsolatedEntryPoint(String entryPoint, String[] entryPointArgs) { |
| 7158 | try { |
| 7159 | Method main = Class.forName(entryPoint).getMethod("main", String[].class); |
| 7160 | main.invoke(null, new Object[]{entryPointArgs}); |
| 7161 | } catch (ReflectiveOperationException e) { |
| 7162 | throw new AndroidRuntimeException("runIsolatedEntryPoint failed", e); |
| 7163 | } |
| 7164 | // The process will be empty after this method returns; exit the VM now. |
| 7165 | System.exit(0); |
| 7166 | } |
| 7167 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 7168 | @UnsupportedAppUsage |
Sudheer Shanka | f669010 | 2017-10-16 10:20:32 -0700 | [diff] [blame] | 7169 | private void attach(boolean system, long startSeq) { |
Jeff Sharkey | 66a017b | 2013-01-17 18:18:22 -0800 | [diff] [blame] | 7170 | sCurrentActivityThread = this; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7171 | mSystemThread = system; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7172 | if (!system) { |
Siva Velusamy | d693dfa | 2012-09-10 14:36:58 -0700 | [diff] [blame] | 7173 | android.ddm.DdmHandleAppName.setAppName("<pre-initialized>", |
| 7174 | UserHandle.myUserId()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7175 | RuntimeInit.setApplicationObject(mAppThread.asBinder()); |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 7176 | final IActivityManager mgr = ActivityManager.getService(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7177 | try { |
Sudheer Shanka | f669010 | 2017-10-16 10:20:32 -0700 | [diff] [blame] | 7178 | mgr.attachApplication(mAppThread, startSeq); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7179 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 7180 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7181 | } |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 7182 | // Watch for getting close to heap limit. |
| 7183 | BinderInternal.addGcWatcher(new Runnable() { |
| 7184 | @Override public void run() { |
| 7185 | if (!mSomeActivitiesChanged) { |
| 7186 | return; |
| 7187 | } |
| 7188 | Runtime runtime = Runtime.getRuntime(); |
| 7189 | long dalvikMax = runtime.maxMemory(); |
| 7190 | long dalvikUsed = runtime.totalMemory() - runtime.freeMemory(); |
| 7191 | if (dalvikUsed > ((3*dalvikMax)/4)) { |
| 7192 | if (DEBUG_MEMORY_TRIM) Slog.d(TAG, "Dalvik max=" + (dalvikMax/1024) |
| 7193 | + " total=" + (runtime.totalMemory()/1024) |
| 7194 | + " used=" + (dalvikUsed/1024)); |
| 7195 | mSomeActivitiesChanged = false; |
| 7196 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 7197 | ActivityTaskManager.getService().releaseSomeActivities(mAppThread); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 7198 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 7199 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 7200 | } |
| 7201 | } |
| 7202 | } |
| 7203 | }); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7204 | } else { |
| 7205 | // Don't set application object here -- if the system crashes, |
| 7206 | // 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] | 7207 | android.ddm.DdmHandleAppName.setAppName("system_process", |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 7208 | UserHandle.myUserId()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7209 | try { |
| 7210 | mInstrumentation = new Instrumentation(); |
Jason Monk | a80bfb5 | 2017-11-16 17:15:37 -0500 | [diff] [blame] | 7211 | mInstrumentation.basicInit(this); |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 7212 | ContextImpl context = ContextImpl.createAppContext( |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 7213 | this, getSystemContext().mPackageInfo); |
| 7214 | mInitialApplication = context.mPackageInfo.makeApplication(true, null); |
Jeff Brown | 7fc8e35 | 2014-09-16 18:06:47 -0700 | [diff] [blame] | 7215 | mInitialApplication.onCreate(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7216 | } catch (Exception e) { |
| 7217 | throw new RuntimeException( |
| 7218 | "Unable to instantiate Application():" + e.toString(), e); |
| 7219 | } |
| 7220 | } |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 7221 | |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 7222 | ViewRootImpl.ConfigChangedCallback configChangedCallback |
| 7223 | = (Configuration globalConfig) -> { |
| 7224 | synchronized (mResourcesManager) { |
lumark | ddc77fb | 2019-06-27 22:22:23 +0800 | [diff] [blame] | 7225 | // TODO (b/135719017): Temporary log for debugging IME service. |
| 7226 | if (Build.IS_DEBUGGABLE && mHasImeComponent) { |
| 7227 | Log.d(TAG, "ViewRootImpl.ConfigChangedCallback for IME, " |
| 7228 | + "config=" + globalConfig); |
| 7229 | } |
| 7230 | |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 7231 | // We need to apply this change to the resources immediately, because upon returning |
| 7232 | // the view hierarchy will be informed about it. |
| 7233 | if (mResourcesManager.applyConfigurationToResourcesLocked(globalConfig, |
| 7234 | null /* compat */)) { |
| 7235 | updateLocaleListFromAppContext(mInitialApplication.getApplicationContext(), |
| 7236 | mResourcesManager.getConfiguration().getLocales()); |
Adam Lesinski | b61e405 | 2016-05-19 18:23:05 -0700 | [diff] [blame] | 7237 | |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 7238 | // This actually changed the resources! Tell everyone about it. |
| 7239 | if (mPendingConfiguration == null |
| 7240 | || mPendingConfiguration.isOtherSeqNewer(globalConfig)) { |
| 7241 | mPendingConfiguration = globalConfig; |
| 7242 | sendMessage(H.CONFIGURATION_CHANGED, globalConfig); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7243 | } |
| 7244 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7245 | } |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 7246 | }; |
| 7247 | ViewRootImpl.addConfigCallback(configChangedCallback); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7248 | } |
| 7249 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 7250 | @UnsupportedAppUsage |
Romain Guy | 5e9120d | 2012-01-30 12:17:22 -0800 | [diff] [blame] | 7251 | public static ActivityThread systemMain() { |
Alan Viverette | 5e1565e | 2014-07-29 16:14:25 -0700 | [diff] [blame] | 7252 | // The system process on low-memory devices do not get to use hardware |
| 7253 | // accelerated drawing, since this can add too much overhead to the |
| 7254 | // process. |
| 7255 | if (!ActivityManager.isHighEndGfx()) { |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 7256 | ThreadedRenderer.disable(true); |
John Reck | 73840ea | 2014-09-22 07:39:18 -0700 | [diff] [blame] | 7257 | } else { |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 7258 | ThreadedRenderer.enableForegroundTrimming(); |
Alan Viverette | 5e1565e | 2014-07-29 16:14:25 -0700 | [diff] [blame] | 7259 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7260 | ActivityThread thread = new ActivityThread(); |
Sudheer Shanka | f669010 | 2017-10-16 10:20:32 -0700 | [diff] [blame] | 7261 | thread.attach(true, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7262 | return thread; |
| 7263 | } |
| 7264 | |
Irina Dumitrescu | 34a27c4 | 2019-04-15 19:20:38 +0100 | [diff] [blame] | 7265 | public static void updateHttpProxy(@NonNull Context context) { |
| 7266 | final ConnectivityManager cm = ConnectivityManager.from(context); |
| 7267 | Proxy.setHttpProxySystemProperty(cm.getDefaultProxy()); |
| 7268 | } |
| 7269 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 7270 | @UnsupportedAppUsage |
Jeff Brown | 10e8971 | 2011-07-08 18:52:57 -0700 | [diff] [blame] | 7271 | public final void installSystemProviders(List<ProviderInfo> providers) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7272 | if (providers != null) { |
Jeff Brown | 10e8971 | 2011-07-08 18:52:57 -0700 | [diff] [blame] | 7273 | installContentProviders(mInitialApplication, providers); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7274 | } |
| 7275 | } |
| 7276 | |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 7277 | public int getIntCoreSetting(String key, int defaultValue) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 7278 | synchronized (mResourcesManager) { |
Svetoslav Ganov | 9aa597e | 2011-03-03 18:17:41 -0800 | [diff] [blame] | 7279 | if (mCoreSettings != null) { |
| 7280 | return mCoreSettings.getInt(key, defaultValue); |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 7281 | } |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 7282 | return defaultValue; |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 7283 | } |
| 7284 | } |
| 7285 | |
Shu Chen | 9d744e5 | 2020-01-22 14:28:08 +0800 | [diff] [blame] | 7286 | float getFloatCoreSetting(String key, float defaultValue) { |
| 7287 | synchronized (mResourcesManager) { |
| 7288 | if (mCoreSettings != null) { |
| 7289 | return mCoreSettings.getFloat(key, defaultValue); |
| 7290 | } |
| 7291 | return defaultValue; |
| 7292 | } |
| 7293 | } |
| 7294 | |
Jeff Sharkey | bc2ae00 | 2018-07-31 10:45:37 -0600 | [diff] [blame] | 7295 | private static class AndroidOs extends ForwardingOs { |
| 7296 | /** |
| 7297 | * Install selective syscall interception. For example, this is used to |
| 7298 | * implement special filesystem paths that will be redirected to |
| 7299 | * {@link ContentResolver#openFileDescriptor(Uri, String)}. |
| 7300 | */ |
| 7301 | public static void install() { |
| 7302 | // If feature is disabled, we don't need to install |
| 7303 | if (!DEPRECATE_DATA_COLUMNS) return; |
| 7304 | |
Jeff Sharkey | bc2ae00 | 2018-07-31 10:45:37 -0600 | [diff] [blame] | 7305 | // Install interception and make sure it sticks! |
| 7306 | Os def = null; |
| 7307 | do { |
| 7308 | def = Os.getDefault(); |
| 7309 | } while (!Os.compareAndSetDefault(def, new AndroidOs(def))); |
| 7310 | } |
| 7311 | |
| 7312 | private AndroidOs(Os os) { |
| 7313 | super(os); |
| 7314 | } |
| 7315 | |
| 7316 | private FileDescriptor openDeprecatedDataPath(String path, int mode) throws ErrnoException { |
| 7317 | final Uri uri = ContentResolver.translateDeprecatedDataPath(path); |
| 7318 | Log.v(TAG, "Redirecting " + path + " to " + uri); |
| 7319 | |
| 7320 | final ContentResolver cr = currentActivityThread().getApplication() |
| 7321 | .getContentResolver(); |
| 7322 | try { |
| 7323 | final FileDescriptor fd = new FileDescriptor(); |
| 7324 | fd.setInt$(cr.openFileDescriptor(uri, |
| 7325 | FileUtils.translateModePosixToString(mode)).detachFd()); |
| 7326 | return fd; |
Jeff Sharkey | b50f51e | 2019-02-27 13:55:38 -0700 | [diff] [blame] | 7327 | } catch (SecurityException e) { |
| 7328 | throw new ErrnoException(e.getMessage(), OsConstants.EACCES); |
Jeff Sharkey | bc2ae00 | 2018-07-31 10:45:37 -0600 | [diff] [blame] | 7329 | } catch (FileNotFoundException e) { |
| 7330 | throw new ErrnoException(e.getMessage(), OsConstants.ENOENT); |
| 7331 | } |
| 7332 | } |
| 7333 | |
Jeff Sharkey | 416d462 | 2019-02-27 22:14:16 -0700 | [diff] [blame] | 7334 | private void deleteDeprecatedDataPath(String path) throws ErrnoException { |
| 7335 | final Uri uri = ContentResolver.translateDeprecatedDataPath(path); |
| 7336 | Log.v(TAG, "Redirecting " + path + " to " + uri); |
| 7337 | |
| 7338 | final ContentResolver cr = currentActivityThread().getApplication() |
| 7339 | .getContentResolver(); |
| 7340 | try { |
| 7341 | if (cr.delete(uri, null, null) == 0) { |
| 7342 | throw new FileNotFoundException(); |
| 7343 | } |
| 7344 | } catch (SecurityException e) { |
| 7345 | throw new ErrnoException(e.getMessage(), OsConstants.EACCES); |
| 7346 | } catch (FileNotFoundException e) { |
| 7347 | throw new ErrnoException(e.getMessage(), OsConstants.ENOENT); |
| 7348 | } |
| 7349 | } |
| 7350 | |
Jeff Sharkey | bc2ae00 | 2018-07-31 10:45:37 -0600 | [diff] [blame] | 7351 | @Override |
| 7352 | public boolean access(String path, int mode) throws ErrnoException { |
| 7353 | if (path != null && path.startsWith(DEPRECATE_DATA_PREFIX)) { |
| 7354 | // If we opened it okay, then access check succeeded |
| 7355 | IoUtils.closeQuietly( |
| 7356 | openDeprecatedDataPath(path, FileUtils.translateModeAccessToPosix(mode))); |
| 7357 | return true; |
| 7358 | } else { |
| 7359 | return super.access(path, mode); |
| 7360 | } |
| 7361 | } |
| 7362 | |
| 7363 | @Override |
| 7364 | public FileDescriptor open(String path, int flags, int mode) throws ErrnoException { |
| 7365 | if (path != null && path.startsWith(DEPRECATE_DATA_PREFIX)) { |
| 7366 | return openDeprecatedDataPath(path, mode); |
| 7367 | } else { |
| 7368 | return super.open(path, flags, mode); |
| 7369 | } |
| 7370 | } |
| 7371 | |
| 7372 | @Override |
| 7373 | public StructStat stat(String path) throws ErrnoException { |
| 7374 | if (path != null && path.startsWith(DEPRECATE_DATA_PREFIX)) { |
| 7375 | final FileDescriptor fd = openDeprecatedDataPath(path, OsConstants.O_RDONLY); |
| 7376 | try { |
| 7377 | return android.system.Os.fstat(fd); |
| 7378 | } finally { |
| 7379 | IoUtils.closeQuietly(fd); |
| 7380 | } |
| 7381 | } else { |
| 7382 | return super.stat(path); |
Narayan Kamath | 7f06224 | 2015-04-08 13:24:13 +0100 | [diff] [blame] | 7383 | } |
| 7384 | } |
Jeff Sharkey | 416d462 | 2019-02-27 22:14:16 -0700 | [diff] [blame] | 7385 | |
| 7386 | @Override |
| 7387 | public void unlink(String path) throws ErrnoException { |
| 7388 | if (path != null && path.startsWith(DEPRECATE_DATA_PREFIX)) { |
| 7389 | deleteDeprecatedDataPath(path); |
| 7390 | } else { |
| 7391 | super.unlink(path); |
| 7392 | } |
| 7393 | } |
| 7394 | |
| 7395 | @Override |
| 7396 | public void remove(String path) throws ErrnoException { |
| 7397 | if (path != null && path.startsWith(DEPRECATE_DATA_PREFIX)) { |
| 7398 | deleteDeprecatedDataPath(path); |
| 7399 | } else { |
| 7400 | super.remove(path); |
| 7401 | } |
| 7402 | } |
Zim | e59cb73 | 2019-12-12 10:54:45 +0000 | [diff] [blame] | 7403 | |
| 7404 | @Override |
| 7405 | public void rename(String oldPath, String newPath) throws ErrnoException { |
| 7406 | try { |
| 7407 | super.rename(oldPath, newPath); |
| 7408 | } catch (ErrnoException e) { |
| 7409 | if (e.errno == OsConstants.EXDEV && oldPath.startsWith("/storage/")) { |
| 7410 | Log.v(TAG, "Recovering failed rename " + oldPath + " to " + newPath); |
| 7411 | try { |
| 7412 | Files.move(new File(oldPath).toPath(), new File(newPath).toPath()); |
| 7413 | } catch (IOException e2) { |
| 7414 | throw e; |
| 7415 | } |
| 7416 | } else { |
| 7417 | throw e; |
| 7418 | } |
| 7419 | } |
| 7420 | } |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 7421 | } |
| 7422 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 7423 | public static void main(String[] args) { |
Narayan Kamath | fbb32f6 | 2015-06-12 15:34:35 +0100 | [diff] [blame] | 7424 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "ActivityThreadMain"); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 7425 | |
Jeff Sharkey | bc2ae00 | 2018-07-31 10:45:37 -0600 | [diff] [blame] | 7426 | // Install selective syscall interception |
| 7427 | AndroidOs.install(); |
| 7428 | |
Brad Fitzpatrick | 4d9e6d2 | 2010-11-15 08:49:51 -0800 | [diff] [blame] | 7429 | // CloseGuard defaults to true and can be quite spammy. We |
| 7430 | // disable it here, but selectively enable it later (via |
| 7431 | // StrictMode) on debug builds, but using DropBox, not logs. |
| 7432 | CloseGuard.setEnabled(false); |
| 7433 | |
Andreas Gampe | d281b42 | 2016-07-08 03:50:27 +0000 | [diff] [blame] | 7434 | Environment.initForCurrentUser(); |
Jeff Sharkey | b049e21 | 2012-09-07 23:16:01 -0700 | [diff] [blame] | 7435 | |
Robin Lee | 3d076af | 2014-04-25 14:57:49 +0100 | [diff] [blame] | 7436 | // Make sure TrustedCertificateStore looks in the right place for CA certificates |
| 7437 | final File configDir = Environment.getUserConfigDirectory(UserHandle.myUserId()); |
| 7438 | TrustedCertificateStore.setDefaultUserDirectory(configDir); |
| 7439 | |
Makoto Onuki | 6b0a7b8 | 2019-10-18 15:44:53 -0700 | [diff] [blame] | 7440 | // Call per-process mainline module initialization. |
| 7441 | initializeMainlineModules(); |
| 7442 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7443 | Process.setArgV0("<pre-initialized>"); |
| 7444 | |
| 7445 | Looper.prepareMainLooper(); |
| 7446 | |
Sudheer Shanka | f669010 | 2017-10-16 10:20:32 -0700 | [diff] [blame] | 7447 | // Find the value for {@link #PROC_START_SEQ_IDENT} if provided on the command line. |
| 7448 | // It will be in the format "seq=114" |
| 7449 | long startSeq = 0; |
| 7450 | if (args != null) { |
| 7451 | for (int i = args.length - 1; i >= 0; --i) { |
| 7452 | if (args[i] != null && args[i].startsWith(PROC_START_SEQ_IDENT)) { |
| 7453 | startSeq = Long.parseLong( |
| 7454 | args[i].substring(PROC_START_SEQ_IDENT.length())); |
| 7455 | } |
| 7456 | } |
| 7457 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7458 | ActivityThread thread = new ActivityThread(); |
Sudheer Shanka | f669010 | 2017-10-16 10:20:32 -0700 | [diff] [blame] | 7459 | thread.attach(false, startSeq); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7460 | |
Vairavan Srinivasan | 7335cfd | 2012-08-18 18:36:03 -0700 | [diff] [blame] | 7461 | if (sMainThreadHandler == null) { |
| 7462 | sMainThreadHandler = thread.getHandler(); |
| 7463 | } |
| 7464 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 7465 | if (false) { |
| 7466 | Looper.myLooper().setMessageLogging(new |
| 7467 | LogPrinter(Log.DEBUG, "ActivityThread")); |
| 7468 | } |
| 7469 | |
Narayan Kamath | fbb32f6 | 2015-06-12 15:34:35 +0100 | [diff] [blame] | 7470 | // End of event ActivityThreadMain. |
| 7471 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7472 | Looper.loop(); |
| 7473 | |
Jeff Brown | 10e8971 | 2011-07-08 18:52:57 -0700 | [diff] [blame] | 7474 | throw new RuntimeException("Main thread loop unexpectedly exited"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7475 | } |
Chris Craik | fc29424 | 2016-12-13 18:10:46 -0800 | [diff] [blame] | 7476 | |
Makoto Onuki | 6b0a7b8 | 2019-10-18 15:44:53 -0700 | [diff] [blame] | 7477 | /** |
| 7478 | * Call various initializer APIs in mainline modules that need to be called when each process |
| 7479 | * starts. |
| 7480 | */ |
| 7481 | public static void initializeMainlineModules() { |
| 7482 | TelephonyFrameworkInitializer.setTelephonyServiceManager(new TelephonyServiceManager()); |
Jeffrey Huang | f58800b | 2020-01-23 13:22:10 -0800 | [diff] [blame] | 7483 | StatsFrameworkInitializer.setStatsServiceManager(new StatsServiceManager()); |
Makoto Onuki | 6b0a7b8 | 2019-10-18 15:44:53 -0700 | [diff] [blame] | 7484 | } |
| 7485 | |
Makoto Onuki | 0a9ee1a | 2019-06-19 08:58:02 -0700 | [diff] [blame] | 7486 | private void purgePendingResources() { |
| 7487 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "purgePendingResources"); |
| 7488 | nPurgePendingResources(); |
| 7489 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
| 7490 | } |
| 7491 | |
Chris Craik | fc29424 | 2016-12-13 18:10:46 -0800 | [diff] [blame] | 7492 | // ------------------ Regular JNI ------------------------ |
Tim Murray | 59f3dc1 | 2018-10-22 15:26:08 -0700 | [diff] [blame] | 7493 | private native void nPurgePendingResources(); |
Chris Craik | fc29424 | 2016-12-13 18:10:46 -0800 | [diff] [blame] | 7494 | private native void nDumpGraphicsInfo(FileDescriptor fd); |
Ryan Savitski | cfdc151 | 2018-12-14 16:20:52 +0000 | [diff] [blame] | 7495 | private native void nInitZygoteChildHeapProfiling(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7496 | } |