The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.app; |
| 18 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 19 | import static android.app.servertransaction.ActivityLifecycleItem.ON_CREATE; |
| 20 | import static android.app.servertransaction.ActivityLifecycleItem.ON_DESTROY; |
| 21 | import static android.app.servertransaction.ActivityLifecycleItem.ON_PAUSE; |
| 22 | import static android.app.servertransaction.ActivityLifecycleItem.ON_RESUME; |
| 23 | import static android.app.servertransaction.ActivityLifecycleItem.ON_START; |
| 24 | import static android.app.servertransaction.ActivityLifecycleItem.ON_STOP; |
| 25 | import static android.app.servertransaction.ActivityLifecycleItem.PRE_ON_CREATE; |
Jeff Sharkey | bc2ae00 | 2018-07-31 10:45:37 -0600 | [diff] [blame] | 26 | import static android.content.ContentResolver.DEPRECATE_DATA_COLUMNS; |
| 27 | import static android.content.ContentResolver.DEPRECATE_DATA_PREFIX; |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 28 | import static android.view.Display.INVALID_DISPLAY; |
| 29 | |
Adam Lesinski | c1b0ebf | 2016-06-09 11:17:10 -0700 | [diff] [blame] | 30 | import android.annotation.NonNull; |
| 31 | import android.annotation.Nullable; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 32 | import android.annotation.UnsupportedAppUsage; |
Dianne Hackborn | 69c6adc | 2015-06-02 10:52:59 -0700 | [diff] [blame] | 33 | import android.app.assist.AssistContent; |
| 34 | import android.app.assist.AssistStructure; |
Christopher Tate | 4528186 | 2010-03-05 15:46:30 -0800 | [diff] [blame] | 35 | import android.app.backup.BackupAgent; |
Andrii Kulian | 914aa7d | 2018-03-19 21:51:53 -0700 | [diff] [blame] | 36 | import android.app.servertransaction.ActivityLifecycleItem; |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 37 | import android.app.servertransaction.ActivityLifecycleItem.LifecycleState; |
Andrii Kulian | 914aa7d | 2018-03-19 21:51:53 -0700 | [diff] [blame] | 38 | import android.app.servertransaction.ActivityRelaunchItem; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 39 | import android.app.servertransaction.ActivityResultItem; |
| 40 | import android.app.servertransaction.ClientTransaction; |
Riddle Hsu | d3062cb | 2018-06-30 02:06:42 +0800 | [diff] [blame] | 41 | import android.app.servertransaction.ClientTransactionItem; |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 42 | import android.app.servertransaction.PendingTransactionActions; |
| 43 | import android.app.servertransaction.PendingTransactionActions.StopInfo; |
| 44 | import android.app.servertransaction.TransactionExecutor; |
Andrii Kulian | 914aa7d | 2018-03-19 21:51:53 -0700 | [diff] [blame] | 45 | import android.app.servertransaction.TransactionExecutorHelper; |
Felipe Leme | a4f39cd | 2019-02-19 15:08:59 -0800 | [diff] [blame] | 46 | import android.content.AutofillOptions; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | import android.content.BroadcastReceiver; |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 48 | import android.content.ComponentCallbacks2; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | import android.content.ComponentName; |
Felipe Leme | 326f15a | 2019-02-19 09:42:24 -0800 | [diff] [blame] | 50 | import android.content.ContentCaptureOptions; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 | import android.content.ContentProvider; |
Jeff Sharkey | bc2ae00 | 2018-07-31 10:45:37 -0600 | [diff] [blame] | 52 | import android.content.ContentResolver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 53 | import android.content.Context; |
| 54 | import android.content.IContentProvider; |
Suchi Amalapurapu | 1ccac75 | 2009-06-12 10:09:58 -0700 | [diff] [blame] | 55 | import android.content.IIntentReceiver; |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 56 | import android.content.Intent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | import android.content.pm.ActivityInfo; |
| 58 | import android.content.pm.ApplicationInfo; |
| 59 | import android.content.pm.IPackageManager; |
| 60 | import android.content.pm.InstrumentationInfo; |
Christopher Tate | 346acb1 | 2012-10-15 19:20:25 -0700 | [diff] [blame] | 61 | import android.content.pm.PackageInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | import android.content.pm.PackageManager; |
Sen Hu | bde7570 | 2010-05-28 01:54:03 -0700 | [diff] [blame] | 63 | import android.content.pm.PackageManager.NameNotFoundException; |
Dianne Hackborn | 3f7c9f2 | 2017-04-04 15:36:33 -0700 | [diff] [blame] | 64 | import android.content.pm.ParceledListSlice; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 65 | import android.content.pm.ProviderInfo; |
| 66 | import android.content.pm.ServiceInfo; |
| 67 | import android.content.res.AssetManager; |
Mitsuru Oshima | ba3ba57 | 2009-07-08 18:49:26 -0700 | [diff] [blame] | 68 | import android.content.res.CompatibilityInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | import android.content.res.Configuration; |
| 70 | import android.content.res.Resources; |
Alan Viverette | e54d245 | 2015-05-06 10:41:43 -0700 | [diff] [blame] | 71 | import android.content.res.Resources.Theme; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 72 | import android.database.sqlite.SQLiteDatabase; |
| 73 | import android.database.sqlite.SQLiteDebug; |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 74 | import android.database.sqlite.SQLiteDebug.DbStats; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 75 | import android.graphics.Bitmap; |
| 76 | import android.graphics.Canvas; |
John Reck | 8785ceb | 2018-10-29 16:45:58 -0700 | [diff] [blame] | 77 | import android.graphics.HardwareRenderer; |
Leon Scroggins III | 8290eab | 2018-03-19 10:51:44 -0400 | [diff] [blame] | 78 | import android.graphics.ImageDecoder; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 79 | import android.hardware.display.DisplayManagerGlobal; |
Paul Jensen | e0bef71 | 2014-12-10 15:12:18 -0500 | [diff] [blame] | 80 | import android.net.ConnectivityManager; |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 81 | import android.net.IConnectivityManager; |
| 82 | import android.net.Proxy; |
Jason Monk | 83520b9 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 83 | import android.net.Uri; |
Joe Onorato | d630f10 | 2011-03-17 18:42:26 -0700 | [diff] [blame] | 84 | import android.os.AsyncTask; |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 85 | import android.os.Binder; |
Jeff Sharkey | 344744b | 2016-01-28 19:03:30 -0700 | [diff] [blame] | 86 | import android.os.Build; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 87 | import android.os.Bundle; |
| 88 | import android.os.Debug; |
Jeff Sharkey | b049e21 | 2012-09-07 23:16:01 -0700 | [diff] [blame] | 89 | import android.os.Environment; |
Jeff Sharkey | bc2ae00 | 2018-07-31 10:45:37 -0600 | [diff] [blame] | 90 | import android.os.FileUtils; |
Jesse Hall | b12249b | 2016-12-12 12:53:02 -0800 | [diff] [blame] | 91 | import android.os.GraphicsEnvironment; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 92 | import android.os.Handler; |
Jeff Sharkey | 8439ac0 | 2017-12-12 17:26:23 -0700 | [diff] [blame] | 93 | import android.os.HandlerExecutor; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 94 | import android.os.IBinder; |
Adam Lesinski | b61e405 | 2016-05-19 18:23:05 -0700 | [diff] [blame] | 95 | import android.os.LocaleList; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 96 | import android.os.Looper; |
| 97 | import android.os.Message; |
| 98 | import android.os.MessageQueue; |
Dianne Hackborn | fabb70b | 2014-11-11 12:22:36 -0800 | [diff] [blame] | 99 | import android.os.Parcel; |
Dianne Hackborn | 9c8dd55 | 2009-06-23 19:22:52 -0700 | [diff] [blame] | 100 | import android.os.ParcelFileDescriptor; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 101 | import android.os.PersistableBundle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 102 | import android.os.Process; |
Makoto Onuki | 2c6657f | 2018-06-06 15:24:02 -0700 | [diff] [blame] | 103 | import android.os.RemoteCallback; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 104 | import android.os.RemoteException; |
| 105 | import android.os.ServiceManager; |
Brad Fitzpatrick | 438d059 | 2010-06-10 12:19:19 -0700 | [diff] [blame] | 106 | import android.os.StrictMode; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 107 | import android.os.SystemClock; |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 108 | import android.os.SystemProperties; |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 109 | import android.os.Trace; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 110 | import android.os.UserHandle; |
Jeff Sharkey | 0a17db1 | 2016-11-04 11:23:46 -0600 | [diff] [blame] | 111 | import android.provider.BlockedNumberContract; |
| 112 | import android.provider.CalendarContract; |
| 113 | import android.provider.CallLog; |
| 114 | import android.provider.ContactsContract; |
| 115 | import android.provider.Downloads; |
Seigo Nonaka | 54084b6 | 2017-04-24 14:46:23 -0700 | [diff] [blame] | 116 | import android.provider.FontsContract; |
Narayan Kamath | ccb2a086 | 2013-12-19 14:49:36 +0000 | [diff] [blame] | 117 | import android.provider.Settings; |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 118 | import android.renderscript.RenderScriptCacheDir; |
Chad Brubaker | c72875b | 2016-04-27 16:35:11 -0700 | [diff] [blame] | 119 | import android.security.NetworkSecurityPolicy; |
Chad Brubaker | 78d4712 | 2015-11-17 22:26:58 -0800 | [diff] [blame] | 120 | import android.security.net.config.NetworkSecurityConfigProvider; |
Jeff Sharkey | bc2ae00 | 2018-07-31 10:45:37 -0600 | [diff] [blame] | 121 | import android.system.ErrnoException; |
| 122 | import android.system.OsConstants; |
| 123 | import android.system.StructStat; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 124 | import android.util.AndroidRuntimeException; |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 125 | import android.util.ArrayMap; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 126 | import android.util.DisplayMetrics; |
| 127 | import android.util.EventLog; |
| 128 | import android.util.Log; |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 129 | import android.util.LogPrinter; |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 130 | import android.util.MergedConfiguration; |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 131 | import android.util.Pair; |
Jeff Brown | 6754ba2 | 2011-12-14 20:20:01 -0800 | [diff] [blame] | 132 | import android.util.PrintWriterPrinter; |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 133 | import android.util.Slog; |
Annie Meng | d582787 | 2019-01-30 20:28:57 +0000 | [diff] [blame] | 134 | import android.util.SparseArray; |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 135 | import android.util.SparseIntArray; |
Adam Powell | 1487466 | 2013-07-18 19:42:41 -0700 | [diff] [blame] | 136 | import android.util.SuperNotCalledException; |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 137 | import android.util.proto.ProtoOutputStream; |
Jorim Jaggi | b29e318 | 2018-04-30 18:51:56 +0200 | [diff] [blame] | 138 | import android.view.Choreographer; |
Adam Lesinski | 3ad1b48 | 2016-04-01 16:41:41 -0700 | [diff] [blame] | 139 | import android.view.ContextThemeWrapper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 140 | import android.view.Display; |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 141 | import android.view.ThreadedRenderer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 142 | import android.view.View; |
| 143 | import android.view.ViewDebug; |
| 144 | import android.view.ViewManager; |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 145 | import android.view.ViewRootImpl; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 146 | import android.view.Window; |
| 147 | import android.view.WindowManager; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 148 | import android.view.WindowManagerGlobal; |
Richard Uhler | 2c03619 | 2016-09-14 09:48:31 +0100 | [diff] [blame] | 149 | import android.webkit.WebView; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 150 | |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 151 | import com.android.internal.annotations.GuardedBy; |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 152 | import com.android.internal.annotations.VisibleForTesting; |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 153 | import com.android.internal.app.IVoiceInteractor; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 154 | import com.android.internal.content.ReferrerIntent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 155 | import com.android.internal.os.BinderInternal; |
| 156 | import com.android.internal.os.RuntimeInit; |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 157 | import com.android.internal.os.SomeArgs; |
Jeff Sharkey | 3e19589 | 2016-03-05 19:48:59 -0700 | [diff] [blame] | 158 | import com.android.internal.util.ArrayUtils; |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 159 | import com.android.internal.util.FastPrintWriter; |
Jorim Jaggi | b29e318 | 2018-04-30 18:51:56 +0200 | [diff] [blame] | 160 | import com.android.internal.util.function.pooled.PooledLambda; |
Kenny Root | 12e7522 | 2013-04-23 22:34:24 -0700 | [diff] [blame] | 161 | import com.android.org.conscrypt.OpenSSLSocketImpl; |
Robin Lee | 3d076af | 2014-04-25 14:57:49 +0100 | [diff] [blame] | 162 | import com.android.org.conscrypt.TrustedCertificateStore; |
Yi Jin | 6c6e9ca | 2018-03-20 16:53:35 -0700 | [diff] [blame] | 163 | import com.android.server.am.MemInfoDumpProto; |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 164 | |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 165 | import dalvik.system.CloseGuard; |
| 166 | import dalvik.system.VMDebug; |
| 167 | import dalvik.system.VMRuntime; |
| 168 | |
Jeff Sharkey | bc2ae00 | 2018-07-31 10:45:37 -0600 | [diff] [blame] | 169 | import libcore.io.ForwardingOs; |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 170 | import libcore.io.IoUtils; |
Jeff Sharkey | bc2ae00 | 2018-07-31 10:45:37 -0600 | [diff] [blame] | 171 | import libcore.io.Os; |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 172 | import libcore.net.event.NetworkEventDispatcher; |
| 173 | |
| 174 | import org.apache.harmony.dalvik.ddmc.DdmVmInternal; |
| 175 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 176 | import java.io.File; |
| 177 | import java.io.FileDescriptor; |
Jeff Sharkey | bc2ae00 | 2018-07-31 10:45:37 -0600 | [diff] [blame] | 178 | import java.io.FileNotFoundException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 179 | import java.io.FileOutputStream; |
Dianne Hackborn | 9c8dd55 | 2009-06-23 19:22:52 -0700 | [diff] [blame] | 180 | import java.io.IOException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 181 | import java.io.PrintWriter; |
| 182 | import java.lang.ref.WeakReference; |
Torne (Richard Coles) | 466cbe4 | 2017-05-31 14:09:14 -0400 | [diff] [blame] | 183 | import java.lang.reflect.Method; |
Robert Greenwalt | 03595d0 | 2010-11-02 14:08:23 -0700 | [diff] [blame] | 184 | import java.net.InetAddress; |
Jeff Sharkey | 416d462 | 2019-02-27 22:14:16 -0700 | [diff] [blame] | 185 | import java.nio.file.Files; |
Narayan Kamath | ccb2a086 | 2013-12-19 14:49:36 +0000 | [diff] [blame] | 186 | import java.text.DateFormat; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 187 | import java.util.ArrayList; |
Jeff Sharkey | a6bfeae | 2017-07-05 16:50:24 -0600 | [diff] [blame] | 188 | import java.util.Arrays; |
Riddle Hsu | d3062cb | 2018-06-30 02:06:42 +0800 | [diff] [blame] | 189 | import java.util.Collections; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 190 | import java.util.List; |
Adam Lesinski | b61e405 | 2016-05-19 18:23:05 -0700 | [diff] [blame] | 191 | import java.util.Locale; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 192 | import java.util.Map; |
Kenny Root | e6585b3 | 2013-12-13 12:00:26 -0800 | [diff] [blame] | 193 | import java.util.Objects; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 194 | import java.util.TimeZone; |
Jeff Sharkey | 8439ac0 | 2017-12-12 17:26:23 -0700 | [diff] [blame] | 195 | import java.util.concurrent.Executor; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 196 | |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 197 | final class RemoteServiceException extends AndroidRuntimeException { |
| 198 | public RemoteServiceException(String msg) { |
| 199 | super(msg); |
| 200 | } |
| 201 | } |
| 202 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 203 | /** |
| 204 | * This manages the execution of the main thread in an |
| 205 | * application process, scheduling and executing activities, |
| 206 | * broadcasts, and other operations on it as the activity |
| 207 | * manager requests. |
| 208 | * |
| 209 | * {@hide} |
| 210 | */ |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 211 | public final class ActivityThread extends ClientTransactionHandler { |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 212 | /** @hide */ |
| 213 | public static final String TAG = "ActivityThread"; |
Jim Miller | 0b2a6d0 | 2010-07-13 18:01:29 -0700 | [diff] [blame] | 214 | 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] | 215 | static final boolean localLOGV = false; |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 216 | static final boolean DEBUG_MESSAGES = false; |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 217 | /** @hide */ |
| 218 | public static final boolean DEBUG_BROADCAST = false; |
Chris Tate | 8a7dc17 | 2009-03-24 20:11:42 -0700 | [diff] [blame] | 219 | private static final boolean DEBUG_RESULTS = false; |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 220 | private static final boolean DEBUG_BACKUP = false; |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 221 | public static final boolean DEBUG_CONFIGURATION = false; |
Dianne Hackborn | a0c283e | 2012-02-09 10:47:01 -0800 | [diff] [blame] | 222 | private static final boolean DEBUG_SERVICE = false; |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 223 | public static final boolean DEBUG_MEMORY_TRIM = false; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 224 | private static final boolean DEBUG_PROVIDER = false; |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 225 | public static final boolean DEBUG_ORDER = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 226 | private static final long MIN_TIME_BETWEEN_GCS = 5*1000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 227 | 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] | 228 | |
Dianne Hackborn | 455625e | 2015-01-21 09:55:13 -0800 | [diff] [blame] | 229 | /** Type for IActivityManager.serviceDoneExecuting: anonymous operation */ |
| 230 | public static final int SERVICE_DONE_EXECUTING_ANON = 0; |
| 231 | /** Type for IActivityManager.serviceDoneExecuting: done with an onStart call */ |
| 232 | public static final int SERVICE_DONE_EXECUTING_START = 1; |
| 233 | /** Type for IActivityManager.serviceDoneExecuting: done stopping (destroying) service */ |
| 234 | public static final int SERVICE_DONE_EXECUTING_STOP = 2; |
| 235 | |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 236 | // Whether to invoke an activity callback after delivering new configuration. |
| 237 | private static final boolean REPORT_TO_ACTIVITY = true; |
| 238 | |
Sudheer Shanka | 84a4895 | 2017-03-08 18:19:01 -0800 | [diff] [blame] | 239 | /** |
| 240 | * Denotes an invalid sequence number corresponding to a process state change. |
| 241 | */ |
| 242 | public static final long INVALID_PROC_STATE_SEQ = -1; |
| 243 | |
Sudheer Shanka | f669010 | 2017-10-16 10:20:32 -0700 | [diff] [blame] | 244 | /** |
| 245 | * Identifier for the sequence no. associated with this process start. It will be provided |
| 246 | * as one of the arguments when the process starts. |
| 247 | */ |
| 248 | public static final String PROC_START_SEQ_IDENT = "seq="; |
| 249 | |
Sudheer Shanka | 84a4895 | 2017-03-08 18:19:01 -0800 | [diff] [blame] | 250 | private final Object mNetworkPolicyLock = new Object(); |
| 251 | |
| 252 | /** |
| 253 | * Denotes the sequence number of the process state change for which the main thread needs |
| 254 | * to block until the network rules are updated for it. |
| 255 | * |
| 256 | * Value of {@link #INVALID_PROC_STATE_SEQ} indicates there is no need for blocking. |
| 257 | */ |
| 258 | @GuardedBy("mNetworkPolicyLock") |
| 259 | private long mNetworkBlockSeq = INVALID_PROC_STATE_SEQ; |
| 260 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 261 | @UnsupportedAppUsage |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 262 | private ContextImpl mSystemContext; |
Adam Lesinski | a82b626 | 2017-03-21 16:56:17 -0700 | [diff] [blame] | 263 | private ContextImpl mSystemUiContext; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 264 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 265 | @UnsupportedAppUsage |
Jeff Sharkey | d589663 | 2016-03-04 16:16:00 -0700 | [diff] [blame] | 266 | static volatile IPackageManager sPackageManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 267 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 268 | @UnsupportedAppUsage |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 269 | final ApplicationThread mAppThread = new ApplicationThread(); |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 270 | @UnsupportedAppUsage |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 271 | final Looper mLooper = Looper.myLooper(); |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 272 | @UnsupportedAppUsage |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 273 | final H mH = new H(); |
Jeff Sharkey | 8439ac0 | 2017-12-12 17:26:23 -0700 | [diff] [blame] | 274 | final Executor mExecutor = new HandlerExecutor(mH); |
Garfield Tan | 0443b37 | 2019-01-04 15:00:13 -0800 | [diff] [blame] | 275 | /** |
| 276 | * Maps from activity token to local record of running activities in this process. |
| 277 | * |
| 278 | * This variable is readable if the code is running in activity thread or holding {@link |
| 279 | * #mResourcesManager}. It's only writable if the code is running in activity thread and holding |
| 280 | * {@link #mResourcesManager}. |
| 281 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 282 | @UnsupportedAppUsage |
Dianne Hackborn | 782d498 | 2015-07-08 17:36:37 -0700 | [diff] [blame] | 283 | final ArrayMap<IBinder, ActivityClientRecord> mActivities = new ArrayMap<>(); |
Riddle Hsu | 66b74a8 | 2018-07-26 00:20:12 +0800 | [diff] [blame] | 284 | /** The activities to be truly destroyed (not include relaunch). */ |
Riddle Hsu | d3062cb | 2018-06-30 02:06:42 +0800 | [diff] [blame] | 285 | final Map<IBinder, ClientTransactionItem> mActivitiesToBeDestroyed = |
| 286 | Collections.synchronizedMap(new ArrayMap<IBinder, ClientTransactionItem>()); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 287 | // List of new activities (via ActivityRecord.nextIdle) that should |
| 288 | // be reported when next we idle. |
| 289 | ActivityClientRecord mNewActivities = null; |
| 290 | // Number of activities that are currently visible on-screen. |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 291 | @UnsupportedAppUsage |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 292 | int mNumVisibleActivities = 0; |
Amith Yamasani | 4f128e4 | 2016-05-10 11:44:12 -0700 | [diff] [blame] | 293 | ArrayList<WeakReference<AssistStructure>> mLastAssistStructures = new ArrayList<>(); |
| 294 | private int mLastSessionId; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 295 | @UnsupportedAppUsage |
Dianne Hackborn | 782d498 | 2015-07-08 17:36:37 -0700 | [diff] [blame] | 296 | final ArrayMap<IBinder, Service> mServices = new ArrayMap<>(); |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 297 | @UnsupportedAppUsage |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 298 | AppBindData mBoundApplication; |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 299 | Profiler mProfiler; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 300 | @UnsupportedAppUsage |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 301 | int mCurDefaultDisplayDpi; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 302 | @UnsupportedAppUsage |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 303 | boolean mDensityCompatMode; |
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 | Configuration mConfiguration; |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 306 | Configuration mCompatConfiguration; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 307 | @UnsupportedAppUsage |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 308 | Application mInitialApplication; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 309 | @UnsupportedAppUsage |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 310 | final ArrayList<Application> mAllApplications |
| 311 | = new ArrayList<Application>(); |
Annie Meng | d582787 | 2019-01-30 20:28:57 +0000 | [diff] [blame] | 312 | /** |
| 313 | * Bookkeeping of instantiated backup agents indexed first by user id, then by package name. |
| 314 | * Indexing by user id supports parallel backups across users on system packages as they run in |
| 315 | * the same process with the same package name. Indexing by package name supports multiple |
| 316 | * distinct applications running in the same process. |
| 317 | */ |
| 318 | private final SparseArray<ArrayMap<String, BackupAgent>> mBackupAgentsByUser = |
| 319 | new SparseArray<>(); |
Jeff Sharkey | 66a017b | 2013-01-17 18:18:22 -0800 | [diff] [blame] | 320 | /** Reference to singleton {@link ActivityThread} */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 321 | @UnsupportedAppUsage |
Jeff Sharkey | d589663 | 2016-03-04 16:16:00 -0700 | [diff] [blame] | 322 | private static volatile ActivityThread sCurrentActivityThread; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 323 | @UnsupportedAppUsage |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 324 | Instrumentation mInstrumentation; |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 325 | String mInstrumentationPackageName = null; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 326 | @UnsupportedAppUsage |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 327 | String mInstrumentationAppDir = null; |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 328 | String[] mInstrumentationSplitAppDirs = null; |
| 329 | String mInstrumentationLibDir = null; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 330 | @UnsupportedAppUsage |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 331 | String mInstrumentedAppDir = null; |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 332 | String[] mInstrumentedSplitAppDirs = null; |
| 333 | String mInstrumentedLibDir = null; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 334 | boolean mSystemThread = false; |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 335 | boolean mSomeActivitiesChanged = false; |
Chong Zhang | 4951f9d | 2016-06-23 13:15:08 -0700 | [diff] [blame] | 336 | boolean mUpdatingSystemConfig = false; |
David Brazdil | d960cc4 | 2018-01-31 07:59:17 +0000 | [diff] [blame] | 337 | /* package */ boolean mHiddenApiWarningShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 338 | |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 339 | // These can be accessed by multiple threads; mResourcesManager is the lock. |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 340 | // XXX For now we keep around information about all packages we have |
| 341 | // seen, not removing entries from this map. |
Dianne Hackborn | 1fbee79 | 2011-11-30 11:29:58 -0800 | [diff] [blame] | 342 | // NOTE: The activity and window managers need to call in to |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 343 | // ActivityThread to do things like update resource configurations, |
Dianne Hackborn | 1fbee79 | 2011-11-30 11:29:58 -0800 | [diff] [blame] | 344 | // which means this lock gets held while the activity and window managers |
| 345 | // holds their own lock. Thus you MUST NEVER call back into the activity manager |
| 346 | // 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] | 347 | // 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] | 348 | @GuardedBy("mResourcesManager") |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 349 | @UnsupportedAppUsage |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 350 | final ArrayMap<String, WeakReference<LoadedApk>> mPackages = new ArrayMap<>(); |
| 351 | @GuardedBy("mResourcesManager") |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 352 | @UnsupportedAppUsage |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 353 | final ArrayMap<String, WeakReference<LoadedApk>> mResourcePackages = new ArrayMap<>(); |
| 354 | @GuardedBy("mResourcesManager") |
| 355 | final ArrayList<ActivityClientRecord> mRelaunchingActivities = new ArrayList<>(); |
| 356 | @GuardedBy("mResourcesManager") |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 357 | @UnsupportedAppUsage |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 358 | Configuration mPendingConfiguration = null; |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 359 | // An executor that performs multi-step transactions. |
| 360 | private final TransactionExecutor mTransactionExecutor = new TransactionExecutor(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 361 | |
Mathew Inwood | 8c854f8 | 2018-09-14 12:35:36 +0100 | [diff] [blame] | 362 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 363 | private final ResourcesManager mResourcesManager; |
| 364 | |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 365 | private static final class ProviderKey { |
| 366 | final String authority; |
| 367 | final int userId; |
| 368 | |
| 369 | public ProviderKey(String authority, int userId) { |
| 370 | this.authority = authority; |
| 371 | this.userId = userId; |
| 372 | } |
| 373 | |
| 374 | @Override |
| 375 | public boolean equals(Object o) { |
| 376 | if (o instanceof ProviderKey) { |
| 377 | final ProviderKey other = (ProviderKey) o; |
Kenny Root | e6585b3 | 2013-12-13 12:00:26 -0800 | [diff] [blame] | 378 | return Objects.equals(authority, other.authority) && userId == other.userId; |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 379 | } |
| 380 | return false; |
| 381 | } |
| 382 | |
| 383 | @Override |
| 384 | public int hashCode() { |
| 385 | return ((authority != null) ? authority.hashCode() : 0) ^ userId; |
| 386 | } |
| 387 | } |
| 388 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 389 | // The lock of mProviderMap protects the following variables. |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 390 | @UnsupportedAppUsage |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 391 | final ArrayMap<ProviderKey, ProviderClientRecord> mProviderMap |
| 392 | = new ArrayMap<ProviderKey, ProviderClientRecord>(); |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 393 | @UnsupportedAppUsage |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 394 | final ArrayMap<IBinder, ProviderRefCount> mProviderRefCountMap |
| 395 | = new ArrayMap<IBinder, ProviderRefCount>(); |
Mathew Inwood | 8c854f8 | 2018-09-14 12:35:36 +0100 | [diff] [blame] | 396 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 397 | final ArrayMap<IBinder, ProviderClientRecord> mLocalProviders |
| 398 | = new ArrayMap<IBinder, ProviderClientRecord>(); |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 399 | @UnsupportedAppUsage |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 400 | final ArrayMap<ComponentName, ProviderClientRecord> mLocalProvidersByName |
| 401 | = new ArrayMap<ComponentName, ProviderClientRecord>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 402 | |
Makoto Onuki | b6c79ea | 2018-05-31 11:03:56 -0700 | [diff] [blame] | 403 | // Mitigation for b/74523247: Used to serialize calls to AM.getContentProvider(). |
| 404 | // Note we never removes items from this map but that's okay because there are only so many |
| 405 | // users and so many authorities. |
| 406 | // TODO Remove it once we move CPR.wait() from AMS to the client side. |
| 407 | @GuardedBy("mGetProviderLocks") |
| 408 | final ArrayMap<ProviderKey, Object> mGetProviderLocks = new ArrayMap<>(); |
| 409 | |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 410 | final ArrayMap<Activity, ArrayList<OnActivityPausedListener>> mOnPauseListeners |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 411 | = new ArrayMap<Activity, ArrayList<OnActivityPausedListener>>(); |
Jeff Hamilton | 52d3203 | 2011-01-08 15:31:26 -0600 | [diff] [blame] | 412 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 413 | final GcIdler mGcIdler = new GcIdler(); |
Tim Murray | 59f3dc1 | 2018-10-22 15:26:08 -0700 | [diff] [blame] | 414 | final PurgeIdler mPurgeIdler = new PurgeIdler(); |
| 415 | |
| 416 | boolean mPurgeIdlerScheduled = false; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 417 | boolean mGcIdlerScheduled = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 418 | |
Mathew Inwood | 8c854f8 | 2018-09-14 12:35:36 +0100 | [diff] [blame] | 419 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Jeff Sharkey | d589663 | 2016-03-04 16:16:00 -0700 | [diff] [blame] | 420 | static volatile Handler sMainThreadHandler; // set once in main() |
Brad Fitzpatrick | 333b8cb | 2010-08-26 12:04:57 -0700 | [diff] [blame] | 421 | |
Svetoslav Ganov | 9aa597e | 2011-03-03 18:17:41 -0800 | [diff] [blame] | 422 | Bundle mCoreSettings = null; |
| 423 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 424 | /** Activity client record, used for bookkeeping for the real {@link Activity} instance. */ |
| 425 | public static final class ActivityClientRecord { |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 426 | @UnsupportedAppUsage |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 427 | public IBinder token; |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 428 | int ident; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 429 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 430 | Intent intent; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 431 | String referrer; |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 432 | IVoiceInteractor voiceInteractor; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 433 | Bundle state; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 434 | PersistableBundle persistentState; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 435 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 436 | Activity activity; |
| 437 | Window window; |
| 438 | Activity parent; |
| 439 | String embeddedID; |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 440 | Activity.NonConfigurationInstances lastNonConfigurationInstances; |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 441 | // TODO(lifecycler): Use mLifecycleState instead. |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 442 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 443 | boolean paused; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 444 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 445 | boolean stopped; |
| 446 | boolean hideForNow; |
| 447 | Configuration newConfig; |
Dianne Hackborn | e88846e | 2009-09-30 21:34:25 -0700 | [diff] [blame] | 448 | Configuration createdConfig; |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 449 | Configuration overrideConfig; |
Garfield Tan | 0443b37 | 2019-01-04 15:00:13 -0800 | [diff] [blame] | 450 | // Used to save the last reported configuration from server side so that activity |
| 451 | // configuration transactions can always use the latest configuration. |
| 452 | @GuardedBy("this") |
| 453 | private Configuration mPendingOverrideConfig; |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 454 | // Used for consolidating configs before sending on to Activity. |
| 455 | private Configuration tmpConfig = new Configuration(); |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 456 | // Callback used for updating activity override config. |
| 457 | ViewRootImpl.ActivityConfigCallback configCallback; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 458 | ActivityClientRecord nextIdle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 459 | |
Andrii Kulian | d70cdb9 | 2019-01-08 15:03:50 -0800 | [diff] [blame] | 460 | // Indicates whether this activity is currently the topmost resumed one in the system. |
| 461 | // This holds the last reported value from server. |
| 462 | boolean isTopResumedActivity; |
| 463 | // This holds the value last sent to the activity. This is needed, because an update from |
| 464 | // server may come at random time, but we always need to report changes between ON_RESUME |
| 465 | // and ON_PAUSE to the app. |
| 466 | boolean lastReportedTopResumedState; |
| 467 | |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 468 | ProfilerInfo profilerInfo; |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 469 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 470 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 471 | ActivityInfo activityInfo; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 472 | @UnsupportedAppUsage |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 473 | CompatibilityInfo compatInfo; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 474 | @UnsupportedAppUsage |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 475 | public LoadedApk packageInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 476 | |
| 477 | List<ResultInfo> pendingResults; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 478 | List<ReferrerIntent> pendingIntents; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 479 | |
| 480 | boolean startsNotResumed; |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 481 | public final boolean isForward; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 482 | int pendingConfigChanges; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 483 | |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 484 | Window mPendingRemoveWindow; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 485 | WindowManager mPendingRemoveWindowManager; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 486 | @UnsupportedAppUsage |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 487 | boolean mPreserveWindow; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 488 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 489 | @LifecycleState |
| 490 | private int mLifecycleState = PRE_ON_CREATE; |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 491 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 492 | @VisibleForTesting |
Mathew Inwood | 8c854f8 | 2018-09-14 12:35:36 +0100 | [diff] [blame] | 493 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 494 | public ActivityClientRecord() { |
| 495 | this.isForward = false; |
| 496 | init(); |
| 497 | } |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 498 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 499 | public ActivityClientRecord(IBinder token, Intent intent, int ident, |
| 500 | ActivityInfo info, Configuration overrideConfig, CompatibilityInfo compatInfo, |
| 501 | String referrer, IVoiceInteractor voiceInteractor, Bundle state, |
| 502 | PersistableBundle persistentState, List<ResultInfo> pendingResults, |
| 503 | List<ReferrerIntent> pendingNewIntents, boolean isForward, |
| 504 | ProfilerInfo profilerInfo, ClientTransactionHandler client) { |
| 505 | this.token = token; |
| 506 | this.ident = ident; |
| 507 | this.intent = intent; |
| 508 | this.referrer = referrer; |
| 509 | this.voiceInteractor = voiceInteractor; |
| 510 | this.activityInfo = info; |
| 511 | this.compatInfo = compatInfo; |
| 512 | this.state = state; |
| 513 | this.persistentState = persistentState; |
| 514 | this.pendingResults = pendingResults; |
| 515 | this.pendingIntents = pendingNewIntents; |
| 516 | this.isForward = isForward; |
| 517 | this.profilerInfo = profilerInfo; |
| 518 | this.overrideConfig = overrideConfig; |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 519 | this.packageInfo = client.getPackageInfoNoCheck(activityInfo.applicationInfo, |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 520 | compatInfo); |
| 521 | init(); |
| 522 | } |
| 523 | |
| 524 | /** Common initializer for all constructors. */ |
| 525 | private void init() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 526 | parent = null; |
| 527 | embeddedID = null; |
| 528 | paused = false; |
| 529 | stopped = false; |
| 530 | hideForNow = false; |
| 531 | nextIdle = null; |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 532 | configCallback = (Configuration overrideConfig, int newDisplayId) -> { |
| 533 | if (activity == null) { |
| 534 | throw new IllegalStateException( |
| 535 | "Received config update for non-existing activity"); |
| 536 | } |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 537 | activity.mMainThread.handleActivityConfigurationChanged(token, overrideConfig, |
| 538 | newDisplayId); |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 539 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 540 | } |
| 541 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 542 | /** Get the current lifecycle state. */ |
| 543 | public int getLifecycleState() { |
| 544 | return mLifecycleState; |
| 545 | } |
| 546 | |
| 547 | /** Update the current lifecycle state for internal bookkeeping. */ |
| 548 | public void setState(@LifecycleState int newLifecycleState) { |
| 549 | mLifecycleState = newLifecycleState; |
| 550 | switch (mLifecycleState) { |
| 551 | case ON_CREATE: |
| 552 | paused = true; |
| 553 | stopped = true; |
| 554 | break; |
| 555 | case ON_START: |
| 556 | paused = true; |
| 557 | stopped = false; |
| 558 | break; |
| 559 | case ON_RESUME: |
| 560 | paused = false; |
| 561 | stopped = false; |
| 562 | break; |
| 563 | case ON_PAUSE: |
| 564 | paused = true; |
| 565 | stopped = false; |
| 566 | break; |
| 567 | case ON_STOP: |
| 568 | paused = true; |
| 569 | stopped = true; |
| 570 | break; |
| 571 | } |
| 572 | } |
| 573 | |
Andrii Kulian | 391161f | 2018-01-29 10:50:02 -0800 | [diff] [blame] | 574 | private boolean isPreHoneycomb() { |
| 575 | return activity != null && activity.getApplicationInfo().targetSdkVersion |
| 576 | < android.os.Build.VERSION_CODES.HONEYCOMB; |
| 577 | } |
| 578 | |
| 579 | private boolean isPreP() { |
| 580 | return activity != null && activity.getApplicationInfo().targetSdkVersion |
| 581 | < android.os.Build.VERSION_CODES.P; |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 582 | } |
| 583 | |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 584 | public boolean isPersistable() { |
Craig Mautner | 43e52ed | 2014-06-16 17:18:52 -0700 | [diff] [blame] | 585 | return activityInfo.persistableMode == ActivityInfo.PERSIST_ACROSS_REBOOTS; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 586 | } |
| 587 | |
Andrii Kulian | 914aa7d | 2018-03-19 21:51:53 -0700 | [diff] [blame] | 588 | public boolean isVisibleFromServer() { |
| 589 | return activity != null && activity.mVisibleFromServer; |
| 590 | } |
| 591 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 592 | public String toString() { |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 593 | ComponentName componentName = intent != null ? intent.getComponent() : null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 594 | return "ActivityRecord{" |
| 595 | + Integer.toHexString(System.identityHashCode(this)) |
| 596 | + " token=" + token + " " + (componentName == null |
| 597 | ? "no component name" : componentName.toShortString()) |
| 598 | + "}"; |
| 599 | } |
Andrii Kulian | 58178f2 | 2016-03-16 13:44:56 -0700 | [diff] [blame] | 600 | |
| 601 | public String getStateString() { |
| 602 | StringBuilder sb = new StringBuilder(); |
| 603 | sb.append("ActivityClientRecord{"); |
| 604 | sb.append("paused=").append(paused); |
| 605 | sb.append(", stopped=").append(stopped); |
| 606 | sb.append(", hideForNow=").append(hideForNow); |
| 607 | sb.append(", startsNotResumed=").append(startsNotResumed); |
| 608 | sb.append(", isForward=").append(isForward); |
| 609 | sb.append(", pendingConfigChanges=").append(pendingConfigChanges); |
Andrii Kulian | 58178f2 | 2016-03-16 13:44:56 -0700 | [diff] [blame] | 610 | sb.append(", preserveWindow=").append(mPreserveWindow); |
| 611 | if (activity != null) { |
| 612 | sb.append(", Activity{"); |
| 613 | sb.append("resumed=").append(activity.mResumed); |
| 614 | sb.append(", stopped=").append(activity.mStopped); |
| 615 | sb.append(", finished=").append(activity.isFinishing()); |
| 616 | sb.append(", destroyed=").append(activity.isDestroyed()); |
| 617 | sb.append(", startedActivity=").append(activity.mStartedActivity); |
| 618 | sb.append(", temporaryPause=").append(activity.mTemporaryPause); |
| 619 | sb.append(", changingConfigurations=").append(activity.mChangingConfigurations); |
Andrii Kulian | 58178f2 | 2016-03-16 13:44:56 -0700 | [diff] [blame] | 620 | sb.append("}"); |
| 621 | } |
| 622 | sb.append("}"); |
| 623 | return sb.toString(); |
| 624 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 625 | } |
| 626 | |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 627 | final class ProviderClientRecord { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 628 | final String[] mNames; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 629 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 630 | final IContentProvider mProvider; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 631 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 632 | final ContentProvider mLocalProvider; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 633 | @UnsupportedAppUsage |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 634 | final ContentProviderHolder mHolder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 635 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 636 | ProviderClientRecord(String[] names, IContentProvider provider, |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 637 | ContentProvider localProvider, ContentProviderHolder holder) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 638 | mNames = names; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 639 | mProvider = provider; |
| 640 | mLocalProvider = localProvider; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 641 | mHolder = holder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 642 | } |
| 643 | } |
| 644 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 645 | static final class ReceiverData extends BroadcastReceiver.PendingResult { |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 646 | public ReceiverData(Intent intent, int resultCode, String resultData, Bundle resultExtras, |
Dianne Hackborn | 20e8098 | 2012-08-31 19:00:44 -0700 | [diff] [blame] | 647 | boolean ordered, boolean sticky, IBinder token, int sendingUser) { |
| 648 | super(resultCode, resultData, resultExtras, TYPE_COMPONENT, ordered, sticky, |
riddle_hsu | 1f5ac4d | 2015-01-03 15:38:21 +0800 | [diff] [blame] | 649 | token, sendingUser, intent.getFlags()); |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 650 | this.intent = intent; |
| 651 | } |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 652 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 653 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 654 | Intent intent; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 655 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 656 | ActivityInfo info; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 657 | @UnsupportedAppUsage |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 658 | CompatibilityInfo compatInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 659 | public String toString() { |
| 660 | return "ReceiverData{intent=" + intent + " packageName=" + |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 661 | info.packageName + " resultCode=" + getResultCode() |
| 662 | + " resultData=" + getResultData() + " resultExtras=" |
| 663 | + getResultExtras(false) + "}"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 664 | } |
| 665 | } |
| 666 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 667 | static final class CreateBackupAgentData { |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 668 | ApplicationInfo appInfo; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 669 | CompatibilityInfo compatInfo; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 670 | int backupMode; |
Ruslan Tkhakokhov | 063180f | 2019-01-28 20:29:46 +0000 | [diff] [blame] | 671 | int userId; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 672 | public String toString() { |
| 673 | return "CreateBackupAgentData{appInfo=" + appInfo |
| 674 | + " backupAgent=" + appInfo.backupAgentName |
Ruslan Tkhakokhov | 063180f | 2019-01-28 20:29:46 +0000 | [diff] [blame] | 675 | + " mode=" + backupMode + " userId=" + userId + "}"; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 676 | } |
| 677 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 678 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 679 | static final class CreateServiceData { |
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 | IBinder token; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 682 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 683 | ServiceInfo info; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 684 | @UnsupportedAppUsage |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 685 | CompatibilityInfo compatInfo; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 686 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 687 | Intent intent; |
| 688 | public String toString() { |
| 689 | return "CreateServiceData{token=" + token + " className=" |
| 690 | + info.name + " packageName=" + info.packageName |
| 691 | + " intent=" + intent + "}"; |
| 692 | } |
| 693 | } |
| 694 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 695 | static final class BindServiceData { |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 696 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 697 | IBinder token; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 698 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 699 | Intent intent; |
| 700 | boolean rebind; |
| 701 | public String toString() { |
| 702 | return "BindServiceData{token=" + token + " intent=" + intent + "}"; |
| 703 | } |
| 704 | } |
| 705 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 706 | static final class ServiceArgsData { |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 707 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 708 | IBinder token; |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 709 | boolean taskRemoved; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 710 | int startId; |
Dianne Hackborn | f6f9f2d | 2009-08-21 16:26:03 -0700 | [diff] [blame] | 711 | int flags; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 712 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 713 | Intent args; |
| 714 | public String toString() { |
| 715 | return "ServiceArgsData{token=" + token + " startId=" + startId |
| 716 | + " args=" + args + "}"; |
| 717 | } |
| 718 | } |
| 719 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 720 | static final class AppBindData { |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 721 | @UnsupportedAppUsage |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 722 | LoadedApk info; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 723 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 724 | String processName; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 725 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 726 | ApplicationInfo appInfo; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 727 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 728 | List<ProviderInfo> providers; |
| 729 | ComponentName instrumentationName; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 730 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 731 | Bundle instrumentationArgs; |
| 732 | IInstrumentationWatcher instrumentationWatcher; |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 733 | IUiAutomationConnection instrumentationUiAutomationConnection; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 734 | int debugMode; |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 735 | boolean enableBinderTracking; |
Man Cao | cfa78b2 | 2015-06-11 20:14:34 -0700 | [diff] [blame] | 736 | boolean trackAllocation; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 737 | @UnsupportedAppUsage |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 738 | boolean restrictedBackupMode; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 739 | @UnsupportedAppUsage |
Dianne Hackborn | 5d927c2 | 2011-09-02 12:22:18 -0700 | [diff] [blame] | 740 | boolean persistent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 741 | Configuration config; |
Mathew Inwood | 8c854f8 | 2018-09-14 12:35:36 +0100 | [diff] [blame] | 742 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 743 | CompatibilityInfo compatInfo; |
Svet Ganov | 37e4327 | 2016-09-09 16:01:32 -0700 | [diff] [blame] | 744 | String buildSerial; |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 745 | |
| 746 | /** Initial values for {@link Profiler}. */ |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 747 | ProfilerInfo initProfilerInfo; |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 748 | |
Felipe Leme | a4f39cd | 2019-02-19 15:08:59 -0800 | [diff] [blame] | 749 | AutofillOptions autofillOptions; |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 750 | |
Felipe Leme | 326f15a | 2019-02-19 09:42:24 -0800 | [diff] [blame] | 751 | /** |
| 752 | * Content capture options for the application - when null, it means ContentCapture is not |
| 753 | * enabled for the package. |
| 754 | */ |
| 755 | @Nullable |
| 756 | ContentCaptureOptions contentCaptureOptions; |
| 757 | |
| 758 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 759 | public String toString() { |
| 760 | return "AppBindData{appInfo=" + appInfo + "}"; |
| 761 | } |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 762 | } |
| 763 | |
| 764 | static final class Profiler { |
| 765 | String profileFile; |
| 766 | ParcelFileDescriptor profileFd; |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 767 | int samplingInterval; |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 768 | boolean autoStopProfiler; |
Shukang Zhou | 6ffd4f9 | 2017-01-25 16:07:57 -0800 | [diff] [blame] | 769 | boolean streamingOutput; |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 770 | boolean profiling; |
| 771 | boolean handlingProfiling; |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 772 | public void setProfiler(ProfilerInfo profilerInfo) { |
| 773 | ParcelFileDescriptor fd = profilerInfo.profileFd; |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 774 | if (profiling) { |
| 775 | if (fd != null) { |
| 776 | try { |
| 777 | fd.close(); |
| 778 | } catch (IOException e) { |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 779 | // Ignore |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 780 | } |
| 781 | } |
| 782 | return; |
| 783 | } |
| 784 | if (profileFd != null) { |
| 785 | try { |
| 786 | profileFd.close(); |
| 787 | } catch (IOException e) { |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 788 | // Ignore |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 789 | } |
| 790 | } |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 791 | profileFile = profilerInfo.profileFile; |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 792 | profileFd = fd; |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 793 | samplingInterval = profilerInfo.samplingInterval; |
| 794 | autoStopProfiler = profilerInfo.autoStopProfiler; |
Shukang Zhou | 6ffd4f9 | 2017-01-25 16:07:57 -0800 | [diff] [blame] | 795 | streamingOutput = profilerInfo.streamingOutput; |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 796 | } |
| 797 | public void startProfiling() { |
| 798 | if (profileFd == null || profiling) { |
| 799 | return; |
| 800 | } |
| 801 | try { |
Andreas Gampe | eff0639 | 2016-05-10 12:51:45 -0700 | [diff] [blame] | 802 | int bufferSize = SystemProperties.getInt("debug.traceview-buffer-size-mb", 8); |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 803 | VMDebug.startMethodTracing(profileFile, profileFd.getFileDescriptor(), |
Shukang Zhou | 6ffd4f9 | 2017-01-25 16:07:57 -0800 | [diff] [blame] | 804 | bufferSize * 1024 * 1024, 0, samplingInterval != 0, samplingInterval, |
| 805 | streamingOutput); |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 806 | profiling = true; |
| 807 | } catch (RuntimeException e) { |
Andreas Gampe | 4f68924 | 2018-03-14 23:13:28 -0700 | [diff] [blame] | 808 | Slog.w(TAG, "Profiling failed on path " + profileFile, e); |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 809 | try { |
| 810 | profileFd.close(); |
| 811 | profileFd = null; |
| 812 | } catch (IOException e2) { |
| 813 | Slog.w(TAG, "Failure closing profile fd", e2); |
| 814 | } |
| 815 | } |
| 816 | } |
| 817 | public void stopProfiling() { |
| 818 | if (profiling) { |
| 819 | profiling = false; |
| 820 | Debug.stopMethodTracing(); |
| 821 | if (profileFd != null) { |
| 822 | try { |
| 823 | profileFd.close(); |
| 824 | } catch (IOException e) { |
| 825 | } |
| 826 | } |
| 827 | profileFd = null; |
| 828 | profileFile = null; |
| 829 | } |
| 830 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 831 | } |
| 832 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 833 | static final class DumpComponentInfo { |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 834 | ParcelFileDescriptor fd; |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 835 | IBinder token; |
Dianne Hackborn | 30d7189 | 2010-12-11 10:37:55 -0800 | [diff] [blame] | 836 | String prefix; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 837 | String[] args; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 838 | } |
| 839 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 840 | static final class ContextCleanupInfo { |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 841 | ContextImpl context; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 842 | String what; |
| 843 | String who; |
| 844 | } |
| 845 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 846 | static final class DumpHeapData { |
Christopher Ferris | 8d652f8 | 2017-04-11 16:29:18 -0700 | [diff] [blame] | 847 | public boolean managed; |
| 848 | public boolean mallocInfo; |
Makoto Onuki | 4556b7b | 2017-07-07 14:58:58 -0700 | [diff] [blame] | 849 | public boolean runGc; |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 850 | String path; |
| 851 | ParcelFileDescriptor fd; |
Makoto Onuki | 2c6657f | 2018-06-06 15:24:02 -0700 | [diff] [blame] | 852 | RemoteCallback finishCallback; |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 853 | } |
| 854 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 855 | static final class UpdateCompatibilityData { |
| 856 | String pkg; |
| 857 | CompatibilityInfo info; |
| 858 | } |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 859 | |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 860 | static final class RequestAssistContextExtras { |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 861 | IBinder activityToken; |
| 862 | IBinder requestToken; |
| 863 | int requestType; |
Amith Yamasani | 4f128e4 | 2016-05-10 11:44:12 -0700 | [diff] [blame] | 864 | int sessionId; |
Svet Ganov | fd31f85 | 2017-04-26 15:54:27 -0700 | [diff] [blame] | 865 | int flags; |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 866 | } |
Anwar Ghuloum | 3a8ce1b | 2013-04-26 16:18:28 -0700 | [diff] [blame] | 867 | |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 868 | private class ApplicationThread extends IApplicationThread.Stub { |
Vasu Nori | 3c7131f | 2010-09-21 14:36:57 -0700 | [diff] [blame] | 869 | private static final String DB_INFO_FORMAT = " %8s %8s %14s %14s %s"; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 870 | |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 871 | private int mLastProcessState = -1; |
| 872 | |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 873 | private void updatePendingConfiguration(Configuration config) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 874 | synchronized (mResourcesManager) { |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 875 | if (mPendingConfiguration == null || |
| 876 | mPendingConfiguration.isOtherSeqNewer(config)) { |
| 877 | mPendingConfiguration = config; |
| 878 | } |
| 879 | } |
| 880 | } |
| 881 | |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 882 | public final void scheduleSleeping(IBinder token, boolean sleeping) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 883 | sendMessage(H.SLEEPING, token, sleeping ? 1 : 0); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 884 | } |
| 885 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 886 | public final void scheduleReceiver(Intent intent, ActivityInfo info, |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 887 | CompatibilityInfo compatInfo, int resultCode, String data, Bundle extras, |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 888 | boolean sync, int sendingUser, int processState) { |
| 889 | updateProcessState(processState, false); |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 890 | ReceiverData r = new ReceiverData(intent, resultCode, data, extras, |
Dianne Hackborn | 20e8098 | 2012-08-31 19:00:44 -0700 | [diff] [blame] | 891 | sync, false, mAppThread.asBinder(), sendingUser); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 892 | r.info = info; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 893 | r.compatInfo = compatInfo; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 894 | sendMessage(H.RECEIVER, r); |
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 | public final void scheduleCreateBackupAgent(ApplicationInfo app, |
Ruslan Tkhakokhov | 063180f | 2019-01-28 20:29:46 +0000 | [diff] [blame] | 898 | CompatibilityInfo compatInfo, int backupMode, int userId) { |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 899 | CreateBackupAgentData d = new CreateBackupAgentData(); |
| 900 | d.appInfo = app; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 901 | d.compatInfo = compatInfo; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 902 | d.backupMode = backupMode; |
Ruslan Tkhakokhov | 063180f | 2019-01-28 20:29:46 +0000 | [diff] [blame] | 903 | d.userId = userId; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 904 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 905 | sendMessage(H.CREATE_BACKUP_AGENT, d); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 906 | } |
| 907 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 908 | public final void scheduleDestroyBackupAgent(ApplicationInfo app, |
Annie Meng | d582787 | 2019-01-30 20:28:57 +0000 | [diff] [blame] | 909 | CompatibilityInfo compatInfo, int userId) { |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 910 | CreateBackupAgentData d = new CreateBackupAgentData(); |
| 911 | d.appInfo = app; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 912 | d.compatInfo = compatInfo; |
Annie Meng | d582787 | 2019-01-30 20:28:57 +0000 | [diff] [blame] | 913 | d.userId = userId; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 914 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 915 | sendMessage(H.DESTROY_BACKUP_AGENT, d); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 916 | } |
| 917 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 918 | public final void scheduleCreateService(IBinder token, |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 919 | ServiceInfo info, CompatibilityInfo compatInfo, int processState) { |
| 920 | updateProcessState(processState, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 921 | CreateServiceData s = new CreateServiceData(); |
| 922 | s.token = token; |
| 923 | s.info = info; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 924 | s.compatInfo = compatInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 925 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 926 | sendMessage(H.CREATE_SERVICE, s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 927 | } |
| 928 | |
| 929 | public final void scheduleBindService(IBinder token, Intent intent, |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 930 | boolean rebind, int processState) { |
| 931 | updateProcessState(processState, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 932 | BindServiceData s = new BindServiceData(); |
| 933 | s.token = token; |
| 934 | s.intent = intent; |
| 935 | s.rebind = rebind; |
| 936 | |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 937 | if (DEBUG_SERVICE) |
| 938 | Slog.v(TAG, "scheduleBindService token=" + token + " intent=" + intent + " uid=" |
| 939 | + Binder.getCallingUid() + " pid=" + Binder.getCallingPid()); |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 940 | sendMessage(H.BIND_SERVICE, s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 941 | } |
| 942 | |
| 943 | public final void scheduleUnbindService(IBinder token, Intent intent) { |
| 944 | BindServiceData s = new BindServiceData(); |
| 945 | s.token = token; |
| 946 | s.intent = intent; |
| 947 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 948 | sendMessage(H.UNBIND_SERVICE, s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 949 | } |
| 950 | |
Dianne Hackborn | 3f7c9f2 | 2017-04-04 15:36:33 -0700 | [diff] [blame] | 951 | public final void scheduleServiceArgs(IBinder token, ParceledListSlice args) { |
| 952 | List<ServiceStartArgs> list = args.getList(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 953 | |
Dianne Hackborn | 3f7c9f2 | 2017-04-04 15:36:33 -0700 | [diff] [blame] | 954 | for (int i = 0; i < list.size(); i++) { |
| 955 | ServiceStartArgs ssa = list.get(i); |
| 956 | ServiceArgsData s = new ServiceArgsData(); |
| 957 | s.token = token; |
| 958 | s.taskRemoved = ssa.taskRemoved; |
| 959 | s.startId = ssa.startId; |
| 960 | s.flags = ssa.flags; |
| 961 | s.args = ssa.args; |
| 962 | |
| 963 | sendMessage(H.SERVICE_ARGS, s); |
| 964 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 965 | } |
| 966 | |
| 967 | public final void scheduleStopService(IBinder token) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 968 | sendMessage(H.STOP_SERVICE, token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 969 | } |
| 970 | |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 971 | public final void bindApplication(String processName, ApplicationInfo appInfo, |
| 972 | List<ProviderInfo> providers, ComponentName instrumentationName, |
| 973 | ProfilerInfo profilerInfo, Bundle instrumentationArgs, |
| 974 | IInstrumentationWatcher instrumentationWatcher, |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 975 | IUiAutomationConnection instrumentationUiConnection, int debugMode, |
Pablo Ceballos | a4d4e82 | 2015-10-05 10:27:52 -0700 | [diff] [blame] | 976 | boolean enableBinderTracking, boolean trackAllocation, |
| 977 | boolean isRestrictedBackupMode, boolean persistent, Configuration config, |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 978 | CompatibilityInfo compatInfo, Map services, Bundle coreSettings, |
Felipe Leme | a4f39cd | 2019-02-19 15:08:59 -0800 | [diff] [blame] | 979 | String buildSerial, AutofillOptions autofillOptions, |
Felipe Leme | 326f15a | 2019-02-19 09:42:24 -0800 | [diff] [blame] | 980 | ContentCaptureOptions contentCaptureOptions) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 981 | if (services != null) { |
Makoto Onuki | 4589565 | 2018-05-07 14:43:05 -0700 | [diff] [blame] | 982 | if (false) { |
| 983 | // Test code to make sure the app could see the passed-in services. |
| 984 | for (Object oname : services.keySet()) { |
| 985 | if (services.get(oname) == null) { |
| 986 | continue; // AM just passed in a null service. |
| 987 | } |
| 988 | String name = (String) oname; |
| 989 | |
| 990 | // See b/79378449 about the following exemption. |
| 991 | switch (name) { |
| 992 | case "package": |
| 993 | case Context.WINDOW_SERVICE: |
| 994 | continue; |
| 995 | } |
| 996 | |
| 997 | if (ServiceManager.getService(name) == null) { |
| 998 | Log.wtf(TAG, "Service " + name + " should be accessible by this app"); |
| 999 | } |
| 1000 | } |
| 1001 | } |
| 1002 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1003 | // Setup the service cache in the ServiceManager |
| 1004 | ServiceManager.initServiceCache(services); |
| 1005 | } |
| 1006 | |
Svetoslav Ganov | 9aa597e | 2011-03-03 18:17:41 -0800 | [diff] [blame] | 1007 | setCoreSettings(coreSettings); |
| 1008 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1009 | AppBindData data = new AppBindData(); |
| 1010 | data.processName = processName; |
| 1011 | data.appInfo = appInfo; |
| 1012 | data.providers = providers; |
| 1013 | data.instrumentationName = instrumentationName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1014 | data.instrumentationArgs = instrumentationArgs; |
| 1015 | data.instrumentationWatcher = instrumentationWatcher; |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 1016 | data.instrumentationUiAutomationConnection = instrumentationUiConnection; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1017 | data.debugMode = debugMode; |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 1018 | data.enableBinderTracking = enableBinderTracking; |
Man Cao | cfa78b2 | 2015-06-11 20:14:34 -0700 | [diff] [blame] | 1019 | data.trackAllocation = trackAllocation; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1020 | data.restrictedBackupMode = isRestrictedBackupMode; |
Dianne Hackborn | 5d927c2 | 2011-09-02 12:22:18 -0700 | [diff] [blame] | 1021 | data.persistent = persistent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1022 | data.config = config; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1023 | data.compatInfo = compatInfo; |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 1024 | data.initProfilerInfo = profilerInfo; |
Svet Ganov | 37e4327 | 2016-09-09 16:01:32 -0700 | [diff] [blame] | 1025 | data.buildSerial = buildSerial; |
Felipe Leme | a4f39cd | 2019-02-19 15:08:59 -0800 | [diff] [blame] | 1026 | data.autofillOptions = autofillOptions; |
Felipe Leme | 326f15a | 2019-02-19 09:42:24 -0800 | [diff] [blame] | 1027 | data.contentCaptureOptions = contentCaptureOptions; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1028 | sendMessage(H.BIND_APPLICATION, data); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1029 | } |
| 1030 | |
Torne (Richard Coles) | 466cbe4 | 2017-05-31 14:09:14 -0400 | [diff] [blame] | 1031 | public final void runIsolatedEntryPoint(String entryPoint, String[] entryPointArgs) { |
| 1032 | SomeArgs args = SomeArgs.obtain(); |
| 1033 | args.arg1 = entryPoint; |
| 1034 | args.arg2 = entryPointArgs; |
| 1035 | sendMessage(H.RUN_ISOLATED_ENTRY_POINT, args); |
| 1036 | } |
| 1037 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1038 | public final void scheduleExit() { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1039 | sendMessage(H.EXIT_APPLICATION, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1040 | } |
| 1041 | |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 1042 | public final void scheduleSuicide() { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1043 | sendMessage(H.SUICIDE, null); |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 1044 | } |
| 1045 | |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 1046 | public void scheduleApplicationInfoChanged(ApplicationInfo ai) { |
| 1047 | sendMessage(H.APPLICATION_INFO_CHANGED, ai); |
| 1048 | } |
| 1049 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1050 | public void updateTimeZone() { |
| 1051 | TimeZone.setDefault(null); |
| 1052 | } |
| 1053 | |
Robert Greenwalt | 03595d0 | 2010-11-02 14:08:23 -0700 | [diff] [blame] | 1054 | public void clearDnsCache() { |
| 1055 | // a non-standard API to get this to libcore |
| 1056 | InetAddress.clearDnsCache(); |
Paul Jensen | e401d17 | 2014-09-12 10:47:39 -0400 | [diff] [blame] | 1057 | // Allow libcore to perform the necessary actions as it sees fit upon a network |
| 1058 | // configuration change. |
| 1059 | NetworkEventDispatcher.getInstance().onNetworkConfigurationChanged(); |
Robert Greenwalt | 03595d0 | 2010-11-02 14:08:23 -0700 | [diff] [blame] | 1060 | } |
| 1061 | |
Irina Dumitrescu | 18622d3 | 2018-12-05 16:19:47 +0000 | [diff] [blame] | 1062 | public void updateHttpProxy() { |
Chalard Jean | 100df0a | 2018-05-15 23:11:45 +0900 | [diff] [blame] | 1063 | final ConnectivityManager cm = ConnectivityManager.from( |
| 1064 | getApplication() != null ? getApplication() : getSystemContext()); |
Irina Dumitrescu | 18622d3 | 2018-12-05 16:19:47 +0000 | [diff] [blame] | 1065 | Proxy.setHttpProxySystemProperty(cm.getDefaultProxy()); |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 1066 | } |
| 1067 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1068 | public void processInBackground() { |
| 1069 | mH.removeMessages(H.GC_WHEN_IDLE); |
| 1070 | mH.sendMessage(mH.obtainMessage(H.GC_WHEN_IDLE)); |
| 1071 | } |
| 1072 | |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1073 | public void dumpService(ParcelFileDescriptor pfd, IBinder servicetoken, String[] args) { |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1074 | DumpComponentInfo data = new DumpComponentInfo(); |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 1075 | try { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1076 | data.fd = pfd.dup(); |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 1077 | data.token = servicetoken; |
| 1078 | data.args = args; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1079 | sendMessage(H.DUMP_SERVICE, data, 0, 0, true /*async*/); |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 1080 | } catch (IOException e) { |
| 1081 | Slog.w(TAG, "dumpService failed", e); |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1082 | } finally { |
| 1083 | IoUtils.closeQuietly(pfd); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1084 | } |
| 1085 | } |
| 1086 | |
| 1087 | // This function exists to make sure all receiver dispatching is |
| 1088 | // correctly ordered, since these are one-way calls and the binder driver |
| 1089 | // applies transaction ordering per object for such calls. |
| 1090 | public void scheduleRegisteredReceiver(IIntentReceiver receiver, Intent intent, |
Dianne Hackborn | 68d881c | 2009-10-05 13:58:17 -0700 | [diff] [blame] | 1091 | int resultCode, String dataStr, Bundle extras, boolean ordered, |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 1092 | boolean sticky, int sendingUser, int processState) throws RemoteException { |
| 1093 | updateProcessState(processState, false); |
Dianne Hackborn | 20e8098 | 2012-08-31 19:00:44 -0700 | [diff] [blame] | 1094 | receiver.performReceive(intent, resultCode, dataStr, extras, ordered, |
| 1095 | sticky, sendingUser); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1096 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1097 | |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 1098 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1099 | public void scheduleLowMemory() { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1100 | sendMessage(H.LOW_MEMORY, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1101 | } |
| 1102 | |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 1103 | @Override |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 1104 | public void profilerControl(boolean start, ProfilerInfo profilerInfo, int profileType) { |
| 1105 | sendMessage(H.PROFILER_CONTROL, profilerInfo, start ? 1 : 0, profileType); |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 1106 | } |
| 1107 | |
Makoto Onuki | 4556b7b | 2017-07-07 14:58:58 -0700 | [diff] [blame] | 1108 | @Override |
Christopher Ferris | 8d652f8 | 2017-04-11 16:29:18 -0700 | [diff] [blame] | 1109 | public void dumpHeap(boolean managed, boolean mallocInfo, boolean runGc, String path, |
Makoto Onuki | 2c6657f | 2018-06-06 15:24:02 -0700 | [diff] [blame] | 1110 | ParcelFileDescriptor fd, RemoteCallback finishCallback) { |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 1111 | DumpHeapData dhd = new DumpHeapData(); |
Christopher Ferris | 8d652f8 | 2017-04-11 16:29:18 -0700 | [diff] [blame] | 1112 | dhd.managed = managed; |
| 1113 | dhd.mallocInfo = mallocInfo; |
Makoto Onuki | 4556b7b | 2017-07-07 14:58:58 -0700 | [diff] [blame] | 1114 | dhd.runGc = runGc; |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 1115 | dhd.path = path; |
| 1116 | dhd.fd = fd; |
Makoto Onuki | 2c6657f | 2018-06-06 15:24:02 -0700 | [diff] [blame] | 1117 | dhd.finishCallback = finishCallback; |
Christopher Ferris | 8d652f8 | 2017-04-11 16:29:18 -0700 | [diff] [blame] | 1118 | sendMessage(H.DUMP_HEAP, dhd, 0, 0, true /*async*/); |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 1119 | } |
| 1120 | |
Leonard Mosescu | f3409ce | 2016-10-06 17:32:05 -0700 | [diff] [blame] | 1121 | public void attachAgent(String agent) { |
| 1122 | sendMessage(H.ATTACH_AGENT, agent); |
| 1123 | } |
| 1124 | |
Dianne Hackborn | 06de2ea | 2009-05-21 12:56:43 -0700 | [diff] [blame] | 1125 | public void setSchedulingGroup(int group) { |
| 1126 | // Note: do this immediately, since going into the foreground |
| 1127 | // should happen regardless of what pending work we have to do |
| 1128 | // and the activity manager will wait for us to report back that |
| 1129 | // we are done before sending us to the background. |
| 1130 | try { |
| 1131 | Process.setProcessGroup(Process.myPid(), group); |
| 1132 | } catch (Exception e) { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 1133 | Slog.w(TAG, "Failed setting process group to " + group, e); |
Dianne Hackborn | 06de2ea | 2009-05-21 12:56:43 -0700 | [diff] [blame] | 1134 | } |
| 1135 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1136 | |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1137 | public void dispatchPackageBroadcast(int cmd, String[] packages) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1138 | sendMessage(H.DISPATCH_PACKAGE_BROADCAST, packages, cmd); |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1139 | } |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 1140 | |
| 1141 | public void scheduleCrash(String msg) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1142 | sendMessage(H.SCHEDULE_CRASH, msg); |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 1143 | } |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1144 | |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1145 | public void dumpActivity(ParcelFileDescriptor pfd, IBinder activitytoken, |
Dianne Hackborn | 30d7189 | 2010-12-11 10:37:55 -0800 | [diff] [blame] | 1146 | String prefix, String[] args) { |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1147 | DumpComponentInfo data = new DumpComponentInfo(); |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 1148 | try { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1149 | data.fd = pfd.dup(); |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 1150 | data.token = activitytoken; |
| 1151 | data.prefix = prefix; |
| 1152 | data.args = args; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1153 | sendMessage(H.DUMP_ACTIVITY, data, 0, 0, true /*async*/); |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 1154 | } catch (IOException e) { |
| 1155 | Slog.w(TAG, "dumpActivity failed", e); |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1156 | } finally { |
| 1157 | IoUtils.closeQuietly(pfd); |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1158 | } |
| 1159 | } |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 1160 | |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1161 | public void dumpProvider(ParcelFileDescriptor pfd, IBinder providertoken, |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1162 | String[] args) { |
| 1163 | DumpComponentInfo data = new DumpComponentInfo(); |
| 1164 | try { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1165 | data.fd = pfd.dup(); |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1166 | data.token = providertoken; |
| 1167 | data.args = args; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1168 | sendMessage(H.DUMP_PROVIDER, data, 0, 0, true /*async*/); |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1169 | } catch (IOException e) { |
| 1170 | Slog.w(TAG, "dumpProvider failed", e); |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1171 | } finally { |
| 1172 | IoUtils.closeQuietly(pfd); |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1173 | } |
| 1174 | } |
| 1175 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1176 | @Override |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1177 | public void dumpMemInfo(ParcelFileDescriptor pfd, Debug.MemoryInfo mem, boolean checkin, |
Colin Cross | c4fb5f9 | 2016-02-02 16:51:15 -0800 | [diff] [blame] | 1178 | boolean dumpFullInfo, boolean dumpDalvik, boolean dumpSummaryOnly, |
| 1179 | boolean dumpUnreachable, String[] args) { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1180 | FileOutputStream fout = new FileOutputStream(pfd.getFileDescriptor()); |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 1181 | PrintWriter pw = new FastPrintWriter(fout); |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 1182 | try { |
Colin Cross | c4fb5f9 | 2016-02-02 16:51:15 -0800 | [diff] [blame] | 1183 | dumpMemInfo(pw, mem, checkin, dumpFullInfo, dumpDalvik, dumpSummaryOnly, dumpUnreachable); |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 1184 | } finally { |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 1185 | pw.flush(); |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1186 | IoUtils.closeQuietly(pfd); |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 1187 | } |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 1188 | } |
| 1189 | |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 1190 | private void dumpMemInfo(PrintWriter pw, Debug.MemoryInfo memInfo, boolean checkin, |
Colin Cross | c4fb5f9 | 2016-02-02 16:51:15 -0800 | [diff] [blame] | 1191 | boolean dumpFullInfo, boolean dumpDalvik, boolean dumpSummaryOnly, boolean dumpUnreachable) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1192 | long nativeMax = Debug.getNativeHeapSize() / 1024; |
| 1193 | long nativeAllocated = Debug.getNativeHeapAllocatedSize() / 1024; |
| 1194 | long nativeFree = Debug.getNativeHeapFreeSize() / 1024; |
| 1195 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1196 | Runtime runtime = Runtime.getRuntime(); |
Mathieu Chartier | d288a26 | 2015-07-10 13:44:42 -0700 | [diff] [blame] | 1197 | runtime.gc(); // Do GC since countInstancesOfClass counts unreachable objects. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1198 | long dalvikMax = runtime.totalMemory() / 1024; |
| 1199 | long dalvikFree = runtime.freeMemory() / 1024; |
| 1200 | long dalvikAllocated = dalvikMax - dalvikFree; |
Richard Uhler | 2c03619 | 2016-09-14 09:48:31 +0100 | [diff] [blame] | 1201 | |
| 1202 | Class[] classesToCount = new Class[] { |
| 1203 | ContextImpl.class, |
| 1204 | Activity.class, |
| 1205 | WebView.class, |
| 1206 | OpenSSLSocketImpl.class |
| 1207 | }; |
| 1208 | long[] instanceCounts = VMDebug.countInstancesOfClasses(classesToCount, true); |
| 1209 | long appContextInstanceCount = instanceCounts[0]; |
| 1210 | long activityInstanceCount = instanceCounts[1]; |
| 1211 | long webviewInstanceCount = instanceCounts[2]; |
| 1212 | long openSslSocketCount = instanceCounts[3]; |
| 1213 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1214 | long viewInstanceCount = ViewDebug.getViewInstanceCount(); |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1215 | long viewRootInstanceCount = ViewDebug.getViewRootImplCount(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1216 | int globalAssetCount = AssetManager.getGlobalAssetCount(); |
| 1217 | int globalAssetManagerCount = AssetManager.getGlobalAssetManagerCount(); |
| 1218 | int binderLocalObjectCount = Debug.getBinderLocalObjectCount(); |
| 1219 | int binderProxyObjectCount = Debug.getBinderProxyObjectCount(); |
| 1220 | int binderDeathObjectCount = Debug.getBinderDeathObjectCount(); |
Dianne Hackborn | fabb70b | 2014-11-11 12:22:36 -0800 | [diff] [blame] | 1221 | long parcelSize = Parcel.getGlobalAllocSize(); |
| 1222 | long parcelCount = Parcel.getGlobalAllocCount(); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1223 | SQLiteDebug.PagerStats stats = SQLiteDebug.getDatabaseInfo(); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1224 | |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 1225 | dumpMemInfoTable(pw, memInfo, checkin, dumpFullInfo, dumpDalvik, dumpSummaryOnly, |
| 1226 | Process.myPid(), |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 1227 | (mBoundApplication != null) ? mBoundApplication.processName : "unknown", |
| 1228 | nativeMax, nativeAllocated, nativeFree, |
| 1229 | dalvikMax, dalvikAllocated, dalvikFree); |
| 1230 | |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 1231 | if (checkin) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1232 | // NOTE: if you change anything significant below, also consider changing |
| 1233 | // ACTIVITY_THREAD_CHECKIN_VERSION. |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 1234 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1235 | // Object counts |
| 1236 | pw.print(viewInstanceCount); pw.print(','); |
| 1237 | pw.print(viewRootInstanceCount); pw.print(','); |
| 1238 | pw.print(appContextInstanceCount); pw.print(','); |
| 1239 | pw.print(activityInstanceCount); pw.print(','); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1240 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1241 | pw.print(globalAssetCount); pw.print(','); |
| 1242 | pw.print(globalAssetManagerCount); pw.print(','); |
| 1243 | pw.print(binderLocalObjectCount); pw.print(','); |
| 1244 | pw.print(binderProxyObjectCount); pw.print(','); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1245 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1246 | pw.print(binderDeathObjectCount); pw.print(','); |
| 1247 | pw.print(openSslSocketCount); pw.print(','); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1248 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1249 | // SQL |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1250 | pw.print(stats.memoryUsed / 1024); pw.print(','); |
Jeff Brown | 2a293b6 | 2012-01-19 14:02:22 -0800 | [diff] [blame] | 1251 | pw.print(stats.memoryUsed / 1024); pw.print(','); |
| 1252 | pw.print(stats.pageCacheOverflow / 1024); pw.print(','); |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 1253 | pw.print(stats.largestMemAlloc / 1024); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1254 | for (int i = 0; i < stats.dbStats.size(); i++) { |
| 1255 | DbStats dbStats = stats.dbStats.get(i); |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 1256 | pw.print(','); pw.print(dbStats.dbName); |
| 1257 | pw.print(','); pw.print(dbStats.pageSize); |
| 1258 | pw.print(','); pw.print(dbStats.dbSize); |
| 1259 | pw.print(','); pw.print(dbStats.lookaside); |
| 1260 | pw.print(','); pw.print(dbStats.cache); |
| 1261 | pw.print(','); pw.print(dbStats.cache); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1262 | } |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 1263 | pw.println(); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1264 | |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 1265 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1266 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1267 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1268 | pw.println(" "); |
| 1269 | pw.println(" Objects"); |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1270 | printRow(pw, TWO_COUNT_COLUMNS, "Views:", viewInstanceCount, "ViewRootImpl:", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1271 | viewRootInstanceCount); |
| 1272 | |
| 1273 | printRow(pw, TWO_COUNT_COLUMNS, "AppContexts:", appContextInstanceCount, |
| 1274 | "Activities:", activityInstanceCount); |
| 1275 | |
| 1276 | printRow(pw, TWO_COUNT_COLUMNS, "Assets:", globalAssetCount, |
| 1277 | "AssetManagers:", globalAssetManagerCount); |
| 1278 | |
| 1279 | printRow(pw, TWO_COUNT_COLUMNS, "Local Binders:", binderLocalObjectCount, |
| 1280 | "Proxy Binders:", binderProxyObjectCount); |
Dianne Hackborn | fabb70b | 2014-11-11 12:22:36 -0800 | [diff] [blame] | 1281 | printRow(pw, TWO_COUNT_COLUMNS, "Parcel memory:", parcelSize/1024, |
| 1282 | "Parcel count:", parcelCount); |
| 1283 | printRow(pw, TWO_COUNT_COLUMNS, "Death Recipients:", binderDeathObjectCount, |
| 1284 | "OpenSSL Sockets:", openSslSocketCount); |
Richard Uhler | 2c03619 | 2016-09-14 09:48:31 +0100 | [diff] [blame] | 1285 | printRow(pw, ONE_COUNT_COLUMN, "WebViews:", webviewInstanceCount); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1286 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1287 | // SQLite mem info |
| 1288 | pw.println(" "); |
| 1289 | pw.println(" SQL"); |
Jeff Brown | 2a293b6 | 2012-01-19 14:02:22 -0800 | [diff] [blame] | 1290 | printRow(pw, ONE_COUNT_COLUMN, "MEMORY_USED:", stats.memoryUsed / 1024); |
| 1291 | printRow(pw, TWO_COUNT_COLUMNS, "PAGECACHE_OVERFLOW:", |
| 1292 | stats.pageCacheOverflow / 1024, "MALLOC_SIZE:", stats.largestMemAlloc / 1024); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1293 | pw.println(" "); |
| 1294 | int N = stats.dbStats.size(); |
| 1295 | if (N > 0) { |
| 1296 | pw.println(" DATABASES"); |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 1297 | printRow(pw, DB_INFO_FORMAT, "pgsz", "dbsz", "Lookaside(b)", "cache", |
Vasu Nori | 3c7131f | 2010-09-21 14:36:57 -0700 | [diff] [blame] | 1298 | "Dbname"); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1299 | for (int i = 0; i < N; i++) { |
| 1300 | DbStats dbStats = stats.dbStats.get(i); |
Vasu Nori | 3c7131f | 2010-09-21 14:36:57 -0700 | [diff] [blame] | 1301 | printRow(pw, DB_INFO_FORMAT, |
| 1302 | (dbStats.pageSize > 0) ? String.valueOf(dbStats.pageSize) : " ", |
| 1303 | (dbStats.dbSize > 0) ? String.valueOf(dbStats.dbSize) : " ", |
| 1304 | (dbStats.lookaside > 0) ? String.valueOf(dbStats.lookaside) : " ", |
| 1305 | dbStats.cache, dbStats.dbName); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1306 | } |
| 1307 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1308 | |
Dianne Hackborn | 82e1ee9 | 2009-08-11 18:56:41 -0700 | [diff] [blame] | 1309 | // Asset details. |
| 1310 | String assetAlloc = AssetManager.getAssetAllocations(); |
| 1311 | if (assetAlloc != null) { |
| 1312 | pw.println(" "); |
| 1313 | pw.println(" Asset Allocations"); |
| 1314 | pw.print(assetAlloc); |
| 1315 | } |
Colin Cross | c4fb5f9 | 2016-02-02 16:51:15 -0800 | [diff] [blame] | 1316 | |
| 1317 | // Unreachable native memory |
| 1318 | if (dumpUnreachable) { |
| 1319 | boolean showContents = ((mBoundApplication != null) |
| 1320 | && ((mBoundApplication.appInfo.flags&ApplicationInfo.FLAG_DEBUGGABLE) != 0)) |
| 1321 | || android.os.Build.IS_DEBUGGABLE; |
| 1322 | pw.println(" "); |
| 1323 | pw.println(" Unreachable memory"); |
| 1324 | pw.print(Debug.getUnreachableMemory(100, showContents)); |
| 1325 | } |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 1326 | } |
| 1327 | |
| 1328 | @Override |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 1329 | public void dumpMemInfoProto(ParcelFileDescriptor pfd, Debug.MemoryInfo mem, |
| 1330 | boolean dumpFullInfo, boolean dumpDalvik, boolean dumpSummaryOnly, |
| 1331 | boolean dumpUnreachable, String[] args) { |
| 1332 | ProtoOutputStream proto = new ProtoOutputStream(pfd.getFileDescriptor()); |
| 1333 | try { |
| 1334 | dumpMemInfo(proto, mem, dumpFullInfo, dumpDalvik, dumpSummaryOnly, dumpUnreachable); |
| 1335 | } finally { |
| 1336 | proto.flush(); |
| 1337 | IoUtils.closeQuietly(pfd); |
| 1338 | } |
| 1339 | } |
| 1340 | |
| 1341 | private void dumpMemInfo(ProtoOutputStream proto, Debug.MemoryInfo memInfo, |
| 1342 | boolean dumpFullInfo, boolean dumpDalvik, |
| 1343 | boolean dumpSummaryOnly, boolean dumpUnreachable) { |
| 1344 | long nativeMax = Debug.getNativeHeapSize() / 1024; |
| 1345 | long nativeAllocated = Debug.getNativeHeapAllocatedSize() / 1024; |
| 1346 | long nativeFree = Debug.getNativeHeapFreeSize() / 1024; |
| 1347 | |
| 1348 | Runtime runtime = Runtime.getRuntime(); |
| 1349 | runtime.gc(); // Do GC since countInstancesOfClass counts unreachable objects. |
| 1350 | long dalvikMax = runtime.totalMemory() / 1024; |
| 1351 | long dalvikFree = runtime.freeMemory() / 1024; |
| 1352 | long dalvikAllocated = dalvikMax - dalvikFree; |
| 1353 | |
| 1354 | Class[] classesToCount = new Class[] { |
| 1355 | ContextImpl.class, |
| 1356 | Activity.class, |
| 1357 | WebView.class, |
| 1358 | OpenSSLSocketImpl.class |
| 1359 | }; |
| 1360 | long[] instanceCounts = VMDebug.countInstancesOfClasses(classesToCount, true); |
| 1361 | long appContextInstanceCount = instanceCounts[0]; |
| 1362 | long activityInstanceCount = instanceCounts[1]; |
| 1363 | long webviewInstanceCount = instanceCounts[2]; |
| 1364 | long openSslSocketCount = instanceCounts[3]; |
| 1365 | |
| 1366 | long viewInstanceCount = ViewDebug.getViewInstanceCount(); |
| 1367 | long viewRootInstanceCount = ViewDebug.getViewRootImplCount(); |
| 1368 | int globalAssetCount = AssetManager.getGlobalAssetCount(); |
| 1369 | int globalAssetManagerCount = AssetManager.getGlobalAssetManagerCount(); |
| 1370 | int binderLocalObjectCount = Debug.getBinderLocalObjectCount(); |
| 1371 | int binderProxyObjectCount = Debug.getBinderProxyObjectCount(); |
| 1372 | int binderDeathObjectCount = Debug.getBinderDeathObjectCount(); |
| 1373 | long parcelSize = Parcel.getGlobalAllocSize(); |
| 1374 | long parcelCount = Parcel.getGlobalAllocCount(); |
| 1375 | SQLiteDebug.PagerStats stats = SQLiteDebug.getDatabaseInfo(); |
| 1376 | |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 1377 | final long mToken = proto.start(MemInfoDumpProto.AppData.PROCESS_MEMORY); |
| 1378 | proto.write(MemInfoDumpProto.ProcessMemory.PID, Process.myPid()); |
| 1379 | proto.write(MemInfoDumpProto.ProcessMemory.PROCESS_NAME, |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 1380 | (mBoundApplication != null) ? mBoundApplication.processName : "unknown"); |
| 1381 | dumpMemInfoTable(proto, memInfo, dumpDalvik, dumpSummaryOnly, |
| 1382 | nativeMax, nativeAllocated, nativeFree, |
| 1383 | dalvikMax, dalvikAllocated, dalvikFree); |
| 1384 | proto.end(mToken); |
| 1385 | |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 1386 | final long oToken = proto.start(MemInfoDumpProto.AppData.OBJECTS); |
| 1387 | proto.write(MemInfoDumpProto.AppData.ObjectStats.VIEW_INSTANCE_COUNT, |
| 1388 | viewInstanceCount); |
| 1389 | proto.write(MemInfoDumpProto.AppData.ObjectStats.VIEW_ROOT_INSTANCE_COUNT, |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 1390 | viewRootInstanceCount); |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 1391 | proto.write(MemInfoDumpProto.AppData.ObjectStats.APP_CONTEXT_INSTANCE_COUNT, |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 1392 | appContextInstanceCount); |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 1393 | proto.write(MemInfoDumpProto.AppData.ObjectStats.ACTIVITY_INSTANCE_COUNT, |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 1394 | activityInstanceCount); |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 1395 | proto.write(MemInfoDumpProto.AppData.ObjectStats.GLOBAL_ASSET_COUNT, |
| 1396 | globalAssetCount); |
| 1397 | proto.write(MemInfoDumpProto.AppData.ObjectStats.GLOBAL_ASSET_MANAGER_COUNT, |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 1398 | globalAssetManagerCount); |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 1399 | proto.write(MemInfoDumpProto.AppData.ObjectStats.LOCAL_BINDER_OBJECT_COUNT, |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 1400 | binderLocalObjectCount); |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 1401 | proto.write(MemInfoDumpProto.AppData.ObjectStats.PROXY_BINDER_OBJECT_COUNT, |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 1402 | binderProxyObjectCount); |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 1403 | proto.write(MemInfoDumpProto.AppData.ObjectStats.PARCEL_MEMORY_KB, |
| 1404 | parcelSize / 1024); |
| 1405 | proto.write(MemInfoDumpProto.AppData.ObjectStats.PARCEL_COUNT, parcelCount); |
| 1406 | proto.write(MemInfoDumpProto.AppData.ObjectStats.BINDER_OBJECT_DEATH_COUNT, |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 1407 | binderDeathObjectCount); |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 1408 | proto.write(MemInfoDumpProto.AppData.ObjectStats.OPEN_SSL_SOCKET_COUNT, |
| 1409 | openSslSocketCount); |
| 1410 | proto.write(MemInfoDumpProto.AppData.ObjectStats.WEBVIEW_INSTANCE_COUNT, |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 1411 | webviewInstanceCount); |
| 1412 | proto.end(oToken); |
| 1413 | |
| 1414 | // SQLite mem info |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 1415 | final long sToken = proto.start(MemInfoDumpProto.AppData.SQL); |
| 1416 | proto.write(MemInfoDumpProto.AppData.SqlStats.MEMORY_USED_KB, |
| 1417 | stats.memoryUsed / 1024); |
| 1418 | proto.write(MemInfoDumpProto.AppData.SqlStats.PAGECACHE_OVERFLOW_KB, |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 1419 | stats.pageCacheOverflow / 1024); |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 1420 | proto.write(MemInfoDumpProto.AppData.SqlStats.MALLOC_SIZE_KB, |
| 1421 | stats.largestMemAlloc / 1024); |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 1422 | int n = stats.dbStats.size(); |
| 1423 | for (int i = 0; i < n; i++) { |
| 1424 | DbStats dbStats = stats.dbStats.get(i); |
| 1425 | |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 1426 | final long dToken = proto.start(MemInfoDumpProto.AppData.SqlStats.DATABASES); |
| 1427 | proto.write(MemInfoDumpProto.AppData.SqlStats.Database.NAME, dbStats.dbName); |
| 1428 | proto.write(MemInfoDumpProto.AppData.SqlStats.Database.PAGE_SIZE, dbStats.pageSize); |
| 1429 | proto.write(MemInfoDumpProto.AppData.SqlStats.Database.DB_SIZE, dbStats.dbSize); |
| 1430 | proto.write(MemInfoDumpProto.AppData.SqlStats.Database.LOOKASIDE_B, |
| 1431 | dbStats.lookaside); |
| 1432 | proto.write(MemInfoDumpProto.AppData.SqlStats.Database.CACHE, dbStats.cache); |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 1433 | proto.end(dToken); |
| 1434 | } |
| 1435 | proto.end(sToken); |
| 1436 | |
| 1437 | // Asset details. |
| 1438 | String assetAlloc = AssetManager.getAssetAllocations(); |
| 1439 | if (assetAlloc != null) { |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 1440 | proto.write(MemInfoDumpProto.AppData.ASSET_ALLOCATIONS, assetAlloc); |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 1441 | } |
| 1442 | |
| 1443 | // Unreachable native memory |
| 1444 | if (dumpUnreachable) { |
| 1445 | int flags = mBoundApplication == null ? 0 : mBoundApplication.appInfo.flags; |
| 1446 | boolean showContents = (flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0 |
| 1447 | || android.os.Build.IS_DEBUGGABLE; |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 1448 | proto.write(MemInfoDumpProto.AppData.UNREACHABLE_MEMORY, |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 1449 | Debug.getUnreachableMemory(100, showContents)); |
| 1450 | } |
| 1451 | } |
| 1452 | |
| 1453 | @Override |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1454 | public void dumpGfxInfo(ParcelFileDescriptor pfd, String[] args) { |
Chris Craik | fc29424 | 2016-12-13 18:10:46 -0800 | [diff] [blame] | 1455 | nDumpGraphicsInfo(pfd.getFileDescriptor()); |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1456 | WindowManagerGlobal.getInstance().dumpGfxInfo(pfd.getFileDescriptor(), args); |
| 1457 | IoUtils.closeQuietly(pfd); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1458 | } |
| 1459 | |
Makoto Onuki | 016dc59 | 2018-08-14 12:26:45 -0700 | [diff] [blame] | 1460 | private File getDatabasesDir(Context context) { |
| 1461 | // There's no simple way to get the databases/ path, so do it this way. |
| 1462 | return context.getDatabasePath("a").getParentFile(); |
| 1463 | } |
| 1464 | |
| 1465 | private void dumpDatabaseInfo(ParcelFileDescriptor pfd, String[] args, boolean isSystem) { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1466 | PrintWriter pw = new FastPrintWriter( |
| 1467 | new FileOutputStream(pfd.getFileDescriptor())); |
Jeff Brown | 6754ba2 | 2011-12-14 20:20:01 -0800 | [diff] [blame] | 1468 | PrintWriterPrinter printer = new PrintWriterPrinter(pw); |
Makoto Onuki | ee93ad2 | 2018-10-18 16:24:13 -0700 | [diff] [blame] | 1469 | SQLiteDebug.dump(printer, args, isSystem); |
Jeff Brown | 6754ba2 | 2011-12-14 20:20:01 -0800 | [diff] [blame] | 1470 | pw.flush(); |
| 1471 | } |
| 1472 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1473 | @Override |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1474 | public void dumpDbInfo(final ParcelFileDescriptor pfd, final String[] args) { |
riddle_hsu | 1d6c40a | 2014-07-31 00:18:00 +0800 | [diff] [blame] | 1475 | if (mSystemThread) { |
Felipe Leme | 29de492 | 2016-06-07 16:14:07 -0700 | [diff] [blame] | 1476 | // Ensure this invocation is asynchronous to prevent writer waiting if buffer cannot |
| 1477 | // be consumed. But it must duplicate the file descriptor first, since caller might |
| 1478 | // be closing it. |
| 1479 | final ParcelFileDescriptor dup; |
| 1480 | try { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1481 | dup = pfd.dup(); |
Felipe Leme | 29de492 | 2016-06-07 16:14:07 -0700 | [diff] [blame] | 1482 | } catch (IOException e) { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1483 | Log.w(TAG, "Could not dup FD " + pfd.getFileDescriptor().getInt$()); |
Felipe Leme | 29de492 | 2016-06-07 16:14:07 -0700 | [diff] [blame] | 1484 | return; |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1485 | } finally { |
| 1486 | IoUtils.closeQuietly(pfd); |
Felipe Leme | 29de492 | 2016-06-07 16:14:07 -0700 | [diff] [blame] | 1487 | } |
| 1488 | |
riddle_hsu | 1d6c40a | 2014-07-31 00:18:00 +0800 | [diff] [blame] | 1489 | AsyncTask.THREAD_POOL_EXECUTOR.execute(new Runnable() { |
| 1490 | @Override |
| 1491 | public void run() { |
Felipe Leme | c74972f | 2016-06-08 09:12:37 -0700 | [diff] [blame] | 1492 | try { |
Makoto Onuki | 016dc59 | 2018-08-14 12:26:45 -0700 | [diff] [blame] | 1493 | dumpDatabaseInfo(dup, args, true); |
Felipe Leme | c74972f | 2016-06-08 09:12:37 -0700 | [diff] [blame] | 1494 | } finally { |
| 1495 | IoUtils.closeQuietly(dup); |
| 1496 | } |
riddle_hsu | 1d6c40a | 2014-07-31 00:18:00 +0800 | [diff] [blame] | 1497 | } |
| 1498 | }); |
| 1499 | } else { |
Makoto Onuki | 016dc59 | 2018-08-14 12:26:45 -0700 | [diff] [blame] | 1500 | dumpDatabaseInfo(pfd, args, false); |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1501 | IoUtils.closeQuietly(pfd); |
riddle_hsu | 1d6c40a | 2014-07-31 00:18:00 +0800 | [diff] [blame] | 1502 | } |
| 1503 | } |
| 1504 | |
| 1505 | @Override |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1506 | public void unstableProviderDied(IBinder provider) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1507 | sendMessage(H.UNSTABLE_PROVIDER_DIED, provider); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1508 | } |
| 1509 | |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 1510 | @Override |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 1511 | public void requestAssistContextExtras(IBinder activityToken, IBinder requestToken, |
Svet Ganov | fd31f85 | 2017-04-26 15:54:27 -0700 | [diff] [blame] | 1512 | int requestType, int sessionId, int flags) { |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 1513 | RequestAssistContextExtras cmd = new RequestAssistContextExtras(); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 1514 | cmd.activityToken = activityToken; |
| 1515 | cmd.requestToken = requestToken; |
| 1516 | cmd.requestType = requestType; |
Amith Yamasani | 4f128e4 | 2016-05-10 11:44:12 -0700 | [diff] [blame] | 1517 | cmd.sessionId = sessionId; |
Svet Ganov | fd31f85 | 2017-04-26 15:54:27 -0700 | [diff] [blame] | 1518 | cmd.flags = flags; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1519 | sendMessage(H.REQUEST_ASSIST_CONTEXT_EXTRAS, cmd); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 1520 | } |
| 1521 | |
Svetoslav Ganov | 9aa597e | 2011-03-03 18:17:41 -0800 | [diff] [blame] | 1522 | public void setCoreSettings(Bundle coreSettings) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1523 | sendMessage(H.SET_CORE_SETTINGS, coreSettings); |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1524 | } |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1525 | |
| 1526 | public void updatePackageCompatibilityInfo(String pkg, CompatibilityInfo info) { |
| 1527 | UpdateCompatibilityData ucd = new UpdateCompatibilityData(); |
| 1528 | ucd.pkg = pkg; |
| 1529 | ucd.info = info; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1530 | sendMessage(H.UPDATE_PACKAGE_COMPATIBILITY_INFO, ucd); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1531 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1532 | |
| 1533 | public void scheduleTrimMemory(int level) { |
Jorim Jaggi | b29e318 | 2018-04-30 18:51:56 +0200 | [diff] [blame] | 1534 | final Runnable r = PooledLambda.obtainRunnable(ActivityThread::handleTrimMemory, |
Yohei Yukawa | e2fa39e | 2018-09-22 13:13:10 -0700 | [diff] [blame] | 1535 | ActivityThread.this, level).recycleOnUse(); |
Jorim Jaggi | b29e318 | 2018-04-30 18:51:56 +0200 | [diff] [blame] | 1536 | // Schedule trimming memory after drawing the frame to minimize jank-risk. |
| 1537 | Choreographer choreographer = Choreographer.getMainThreadInstance(); |
| 1538 | if (choreographer != null) { |
| 1539 | choreographer.postCallback(Choreographer.CALLBACK_COMMIT, r, null); |
| 1540 | } else { |
| 1541 | mH.post(r); |
| 1542 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1543 | } |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1544 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1545 | public void scheduleTranslucentConversionComplete(IBinder token, boolean drawComplete) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1546 | sendMessage(H.TRANSLUCENT_CONVERSION_COMPLETE, token, drawComplete ? 1 : 0); |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1547 | } |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 1548 | |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1549 | public void scheduleOnNewActivityOptions(IBinder token, Bundle options) { |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1550 | sendMessage(H.ON_NEW_ACTIVITY_OPTIONS, |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1551 | new Pair<IBinder, ActivityOptions>(token, ActivityOptions.fromBundle(options))); |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1552 | } |
| 1553 | |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 1554 | public void setProcessState(int state) { |
| 1555 | updateProcessState(state, true); |
| 1556 | } |
| 1557 | |
| 1558 | public void updateProcessState(int processState, boolean fromIpc) { |
| 1559 | synchronized (this) { |
| 1560 | if (mLastProcessState != processState) { |
| 1561 | mLastProcessState = processState; |
Mathieu Chartier | 1e37090 | 2013-07-18 10:58:01 -0700 | [diff] [blame] | 1562 | // Update Dalvik state based on ActivityManager.PROCESS_STATE_* constants. |
| 1563 | final int DALVIK_PROCESS_STATE_JANK_PERCEPTIBLE = 0; |
| 1564 | final int DALVIK_PROCESS_STATE_JANK_IMPERCEPTIBLE = 1; |
| 1565 | int dalvikProcessState = DALVIK_PROCESS_STATE_JANK_IMPERCEPTIBLE; |
| 1566 | // TODO: Tune this since things like gmail sync are important background but not jank perceptible. |
| 1567 | if (processState <= ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND) { |
| 1568 | dalvikProcessState = DALVIK_PROCESS_STATE_JANK_PERCEPTIBLE; |
| 1569 | } |
| 1570 | VMRuntime.getRuntime().updateProcessState(dalvikProcessState); |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 1571 | if (false) { |
| 1572 | Slog.i(TAG, "******************* PROCESS STATE CHANGED TO: " + processState |
| 1573 | + (fromIpc ? " (from ipc": "")); |
| 1574 | } |
| 1575 | } |
| 1576 | } |
| 1577 | } |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 1578 | |
Sudheer Shanka | 84a4895 | 2017-03-08 18:19:01 -0800 | [diff] [blame] | 1579 | /** |
| 1580 | * Updates {@link #mNetworkBlockSeq}. This is used by ActivityManagerService to inform |
| 1581 | * the main thread that it needs to wait for the network rules to get updated before |
| 1582 | * launching an activity. |
| 1583 | */ |
| 1584 | @Override |
| 1585 | public void setNetworkBlockSeq(long procStateSeq) { |
| 1586 | synchronized (mNetworkPolicyLock) { |
| 1587 | mNetworkBlockSeq = procStateSeq; |
| 1588 | } |
| 1589 | } |
| 1590 | |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 1591 | @Override |
| 1592 | public void scheduleInstallProvider(ProviderInfo provider) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1593 | sendMessage(H.INSTALL_PROVIDER, provider); |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 1594 | } |
Narayan Kamath | ccb2a086 | 2013-12-19 14:49:36 +0000 | [diff] [blame] | 1595 | |
| 1596 | @Override |
Neil Fuller | b7146fe | 2016-11-15 16:52:15 +0000 | [diff] [blame] | 1597 | public final void updateTimePrefs(int timeFormatPreference) { |
| 1598 | final Boolean timeFormatPreferenceBool; |
| 1599 | // For convenience we are using the Intent extra values. |
| 1600 | if (timeFormatPreference == Intent.EXTRA_TIME_PREF_VALUE_USE_12_HOUR) { |
| 1601 | timeFormatPreferenceBool = Boolean.FALSE; |
| 1602 | } else if (timeFormatPreference == Intent.EXTRA_TIME_PREF_VALUE_USE_24_HOUR) { |
| 1603 | timeFormatPreferenceBool = Boolean.TRUE; |
| 1604 | } else { |
| 1605 | // timeFormatPreference == Intent.EXTRA_TIME_PREF_VALUE_USE_LOCALE_DEFAULT |
| 1606 | // (or unknown). |
| 1607 | timeFormatPreferenceBool = null; |
| 1608 | } |
| 1609 | DateFormat.set24HourTimePref(timeFormatPreferenceBool); |
Narayan Kamath | ccb2a086 | 2013-12-19 14:49:36 +0000 | [diff] [blame] | 1610 | } |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 1611 | |
| 1612 | @Override |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 1613 | public void scheduleEnterAnimationComplete(IBinder token) { |
| 1614 | sendMessage(H.ENTER_ANIMATION_COMPLETE, token); |
| 1615 | } |
Jeff Sharkey | 605eb79 | 2014-11-04 13:34:06 -0800 | [diff] [blame] | 1616 | |
| 1617 | @Override |
| 1618 | public void notifyCleartextNetwork(byte[] firstPacket) { |
| 1619 | if (StrictMode.vmCleartextNetworkEnabled()) { |
| 1620 | StrictMode.onCleartextNetworkDetected(firstPacket); |
| 1621 | } |
| 1622 | } |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 1623 | |
| 1624 | @Override |
| 1625 | public void startBinderTracking() { |
| 1626 | sendMessage(H.START_BINDER_TRACKING, null); |
| 1627 | } |
| 1628 | |
| 1629 | @Override |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1630 | public void stopBinderTrackingAndDump(ParcelFileDescriptor pfd) { |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 1631 | try { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1632 | sendMessage(H.STOP_BINDER_TRACKING_AND_DUMP, pfd.dup()); |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 1633 | } catch (IOException e) { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1634 | } finally { |
| 1635 | IoUtils.closeQuietly(pfd); |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 1636 | } |
| 1637 | } |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 1638 | |
| 1639 | @Override |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1640 | public void scheduleLocalVoiceInteractionStarted(IBinder token, |
| 1641 | IVoiceInteractor voiceInteractor) throws RemoteException { |
| 1642 | SomeArgs args = SomeArgs.obtain(); |
| 1643 | args.arg1 = token; |
| 1644 | args.arg2 = voiceInteractor; |
| 1645 | sendMessage(H.LOCAL_VOICE_INTERACTION_STARTED, args); |
| 1646 | } |
Chad Brubaker | c72875b | 2016-04-27 16:35:11 -0700 | [diff] [blame] | 1647 | |
| 1648 | @Override |
| 1649 | public void handleTrustStorageUpdate() { |
| 1650 | NetworkSecurityPolicy.getInstance().handleTrustStorageUpdate(); |
| 1651 | } |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 1652 | |
| 1653 | @Override |
| 1654 | public void scheduleTransaction(ClientTransaction transaction) throws RemoteException { |
| 1655 | ActivityThread.this.scheduleTransaction(transaction); |
| 1656 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1657 | } |
| 1658 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 1659 | @Override |
| 1660 | public void updatePendingConfiguration(Configuration config) { |
| 1661 | mAppThread.updatePendingConfiguration(config); |
| 1662 | } |
| 1663 | |
| 1664 | @Override |
| 1665 | public void updateProcessState(int processState, boolean fromIpc) { |
| 1666 | mAppThread.updateProcessState(processState, fromIpc); |
| 1667 | } |
| 1668 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 1669 | class H extends Handler { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1670 | public static final int BIND_APPLICATION = 110; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 1671 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1672 | public static final int EXIT_APPLICATION = 111; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 1673 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1674 | public static final int RECEIVER = 113; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 1675 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1676 | public static final int CREATE_SERVICE = 114; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 1677 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1678 | public static final int SERVICE_ARGS = 115; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 1679 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1680 | public static final int STOP_SERVICE = 116; |
Dianne Hackborn | 0923328 | 2014-04-30 11:33:59 -0700 | [diff] [blame] | 1681 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1682 | public static final int CONFIGURATION_CHANGED = 118; |
| 1683 | public static final int CLEAN_UP_CONTEXT = 119; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 1684 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1685 | public static final int GC_WHEN_IDLE = 120; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 1686 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1687 | public static final int BIND_SERVICE = 121; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 1688 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1689 | public static final int UNBIND_SERVICE = 122; |
| 1690 | public static final int DUMP_SERVICE = 123; |
| 1691 | public static final int LOW_MEMORY = 124; |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 1692 | public static final int PROFILER_CONTROL = 127; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1693 | public static final int CREATE_BACKUP_AGENT = 128; |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 1694 | public static final int DESTROY_BACKUP_AGENT = 129; |
| 1695 | public static final int SUICIDE = 130; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 1696 | @UnsupportedAppUsage |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1697 | public static final int REMOVE_PROVIDER = 131; |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1698 | public static final int DISPATCH_PACKAGE_BROADCAST = 133; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 1699 | @UnsupportedAppUsage |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 1700 | public static final int SCHEDULE_CRASH = 134; |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 1701 | public static final int DUMP_HEAP = 135; |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1702 | public static final int DUMP_ACTIVITY = 136; |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1703 | public static final int SLEEPING = 137; |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1704 | public static final int SET_CORE_SETTINGS = 138; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1705 | public static final int UPDATE_PACKAGE_COMPATIBILITY_INFO = 139; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 1706 | @UnsupportedAppUsage |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1707 | public static final int DUMP_PROVIDER = 141; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1708 | public static final int UNSTABLE_PROVIDER_DIED = 142; |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 1709 | public static final int REQUEST_ASSIST_CONTEXT_EXTRAS = 143; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1710 | public static final int TRANSLUCENT_CONVERSION_COMPLETE = 144; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 1711 | @UnsupportedAppUsage |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 1712 | public static final int INSTALL_PROVIDER = 145; |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1713 | public static final int ON_NEW_ACTIVITY_OPTIONS = 146; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 1714 | @UnsupportedAppUsage |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 1715 | public static final int ENTER_ANIMATION_COMPLETE = 149; |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 1716 | public static final int START_BINDER_TRACKING = 150; |
| 1717 | public static final int STOP_BINDER_TRACKING_AND_DUMP = 151; |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1718 | public static final int LOCAL_VOICE_INTERACTION_STARTED = 154; |
Leonard Mosescu | f3409ce | 2016-10-06 17:32:05 -0700 | [diff] [blame] | 1719 | public static final int ATTACH_AGENT = 155; |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 1720 | public static final int APPLICATION_INFO_CHANGED = 156; |
Torne (Richard Coles) | 466cbe4 | 2017-05-31 14:09:14 -0400 | [diff] [blame] | 1721 | public static final int RUN_ISOLATED_ENTRY_POINT = 158; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 1722 | public static final int EXECUTE_TRANSACTION = 159; |
Andrii Kulian | 320e3b5 | 2018-05-03 16:26:25 -0700 | [diff] [blame] | 1723 | public static final int RELAUNCH_ACTIVITY = 160; |
Tim Murray | 59f3dc1 | 2018-10-22 15:26:08 -0700 | [diff] [blame] | 1724 | public static final int PURGE_RESOURCES = 161; |
Narayan Kamath | ccb2a086 | 2013-12-19 14:49:36 +0000 | [diff] [blame] | 1725 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1726 | String codeToString(int code) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 1727 | if (DEBUG_MESSAGES) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1728 | switch (code) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1729 | case BIND_APPLICATION: return "BIND_APPLICATION"; |
| 1730 | case EXIT_APPLICATION: return "EXIT_APPLICATION"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1731 | case RECEIVER: return "RECEIVER"; |
| 1732 | case CREATE_SERVICE: return "CREATE_SERVICE"; |
| 1733 | case SERVICE_ARGS: return "SERVICE_ARGS"; |
| 1734 | case STOP_SERVICE: return "STOP_SERVICE"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1735 | case CONFIGURATION_CHANGED: return "CONFIGURATION_CHANGED"; |
| 1736 | case CLEAN_UP_CONTEXT: return "CLEAN_UP_CONTEXT"; |
| 1737 | case GC_WHEN_IDLE: return "GC_WHEN_IDLE"; |
| 1738 | case BIND_SERVICE: return "BIND_SERVICE"; |
| 1739 | case UNBIND_SERVICE: return "UNBIND_SERVICE"; |
| 1740 | case DUMP_SERVICE: return "DUMP_SERVICE"; |
| 1741 | case LOW_MEMORY: return "LOW_MEMORY"; |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 1742 | case PROFILER_CONTROL: return "PROFILER_CONTROL"; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1743 | case CREATE_BACKUP_AGENT: return "CREATE_BACKUP_AGENT"; |
| 1744 | case DESTROY_BACKUP_AGENT: return "DESTROY_BACKUP_AGENT"; |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 1745 | case SUICIDE: return "SUICIDE"; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1746 | case REMOVE_PROVIDER: return "REMOVE_PROVIDER"; |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1747 | case DISPATCH_PACKAGE_BROADCAST: return "DISPATCH_PACKAGE_BROADCAST"; |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 1748 | case SCHEDULE_CRASH: return "SCHEDULE_CRASH"; |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 1749 | case DUMP_HEAP: return "DUMP_HEAP"; |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1750 | case DUMP_ACTIVITY: return "DUMP_ACTIVITY"; |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1751 | case SLEEPING: return "SLEEPING"; |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1752 | case SET_CORE_SETTINGS: return "SET_CORE_SETTINGS"; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1753 | case UPDATE_PACKAGE_COMPATIBILITY_INFO: return "UPDATE_PACKAGE_COMPATIBILITY_INFO"; |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1754 | case DUMP_PROVIDER: return "DUMP_PROVIDER"; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1755 | case UNSTABLE_PROVIDER_DIED: return "UNSTABLE_PROVIDER_DIED"; |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 1756 | case REQUEST_ASSIST_CONTEXT_EXTRAS: return "REQUEST_ASSIST_CONTEXT_EXTRAS"; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1757 | case TRANSLUCENT_CONVERSION_COMPLETE: return "TRANSLUCENT_CONVERSION_COMPLETE"; |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 1758 | case INSTALL_PROVIDER: return "INSTALL_PROVIDER"; |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1759 | case ON_NEW_ACTIVITY_OPTIONS: return "ON_NEW_ACTIVITY_OPTIONS"; |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 1760 | case ENTER_ANIMATION_COMPLETE: return "ENTER_ANIMATION_COMPLETE"; |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1761 | case LOCAL_VOICE_INTERACTION_STARTED: return "LOCAL_VOICE_INTERACTION_STARTED"; |
Leonard Mosescu | f3409ce | 2016-10-06 17:32:05 -0700 | [diff] [blame] | 1762 | case ATTACH_AGENT: return "ATTACH_AGENT"; |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 1763 | case APPLICATION_INFO_CHANGED: return "APPLICATION_INFO_CHANGED"; |
Torne (Richard Coles) | 466cbe4 | 2017-05-31 14:09:14 -0400 | [diff] [blame] | 1764 | case RUN_ISOLATED_ENTRY_POINT: return "RUN_ISOLATED_ENTRY_POINT"; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 1765 | case EXECUTE_TRANSACTION: return "EXECUTE_TRANSACTION"; |
Andrii Kulian | 320e3b5 | 2018-05-03 16:26:25 -0700 | [diff] [blame] | 1766 | case RELAUNCH_ACTIVITY: return "RELAUNCH_ACTIVITY"; |
Tim Murray | 59f3dc1 | 2018-10-22 15:26:08 -0700 | [diff] [blame] | 1767 | case PURGE_RESOURCES: return "PURGE_RESOURCES"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1768 | } |
| 1769 | } |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 1770 | return Integer.toString(code); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1771 | } |
| 1772 | public void handleMessage(Message msg) { |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 1773 | 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] | 1774 | switch (msg.what) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1775 | case BIND_APPLICATION: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1776 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "bindApplication"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1777 | AppBindData data = (AppBindData)msg.obj; |
| 1778 | handleBindApplication(data); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1779 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1780 | break; |
| 1781 | case EXIT_APPLICATION: |
| 1782 | if (mInitialApplication != null) { |
| 1783 | mInitialApplication.onTerminate(); |
| 1784 | } |
| 1785 | Looper.myLooper().quit(); |
| 1786 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1787 | case RECEIVER: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1788 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "broadcastReceiveComp"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1789 | handleReceiver((ReceiverData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1790 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1791 | break; |
| 1792 | case CREATE_SERVICE: |
Tim Murray | b6f5a42 | 2016-04-07 15:25:22 -0700 | [diff] [blame] | 1793 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, ("serviceCreate: " + String.valueOf(msg.obj))); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1794 | handleCreateService((CreateServiceData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1795 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1796 | break; |
| 1797 | case BIND_SERVICE: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1798 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "serviceBind"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1799 | handleBindService((BindServiceData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1800 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1801 | break; |
| 1802 | case UNBIND_SERVICE: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1803 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "serviceUnbind"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1804 | handleUnbindService((BindServiceData)msg.obj); |
Tim Murray | 59f3dc1 | 2018-10-22 15:26:08 -0700 | [diff] [blame] | 1805 | schedulePurgeIdler(); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1806 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1807 | break; |
| 1808 | case SERVICE_ARGS: |
Tim Murray | b6f5a42 | 2016-04-07 15:25:22 -0700 | [diff] [blame] | 1809 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, ("serviceStart: " + String.valueOf(msg.obj))); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1810 | handleServiceArgs((ServiceArgsData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1811 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1812 | break; |
| 1813 | case STOP_SERVICE: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1814 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "serviceStop"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1815 | handleStopService((IBinder)msg.obj); |
Tim Murray | 59f3dc1 | 2018-10-22 15:26:08 -0700 | [diff] [blame] | 1816 | schedulePurgeIdler(); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1817 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1818 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1819 | case CONFIGURATION_CHANGED: |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 1820 | handleConfigurationChanged((Configuration) msg.obj); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1821 | break; |
| 1822 | case CLEAN_UP_CONTEXT: |
| 1823 | ContextCleanupInfo cci = (ContextCleanupInfo)msg.obj; |
| 1824 | cci.context.performFinalCleanup(cci.who, cci.what); |
| 1825 | break; |
| 1826 | case GC_WHEN_IDLE: |
| 1827 | scheduleGcIdler(); |
| 1828 | break; |
| 1829 | case DUMP_SERVICE: |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1830 | handleDumpService((DumpComponentInfo)msg.obj); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1831 | break; |
| 1832 | case LOW_MEMORY: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1833 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "lowMemory"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1834 | handleLowMemory(); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1835 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1836 | break; |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 1837 | case PROFILER_CONTROL: |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 1838 | handleProfilerControl(msg.arg1 != 0, (ProfilerInfo)msg.obj, msg.arg2); |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 1839 | break; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1840 | case CREATE_BACKUP_AGENT: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1841 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "backupCreateAgent"); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1842 | handleCreateBackupAgent((CreateBackupAgentData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1843 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1844 | break; |
| 1845 | case DESTROY_BACKUP_AGENT: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1846 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "backupDestroyAgent"); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1847 | handleDestroyBackupAgent((CreateBackupAgentData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1848 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1849 | break; |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 1850 | case SUICIDE: |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1851 | Process.killProcess(Process.myPid()); |
| 1852 | break; |
| 1853 | case REMOVE_PROVIDER: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1854 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "providerRemove"); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1855 | completeRemoveProvider((ProviderRefCount)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1856 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 1857 | break; |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1858 | case DISPATCH_PACKAGE_BROADCAST: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1859 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "broadcastPackage"); |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1860 | handleDispatchPackageBroadcast(msg.arg1, (String[])msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1861 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1862 | break; |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 1863 | case SCHEDULE_CRASH: |
| 1864 | throw new RemoteServiceException((String)msg.obj); |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 1865 | case DUMP_HEAP: |
Christopher Ferris | 8d652f8 | 2017-04-11 16:29:18 -0700 | [diff] [blame] | 1866 | handleDumpHeap((DumpHeapData) msg.obj); |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 1867 | break; |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1868 | case DUMP_ACTIVITY: |
| 1869 | handleDumpActivity((DumpComponentInfo)msg.obj); |
| 1870 | break; |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1871 | case DUMP_PROVIDER: |
| 1872 | handleDumpProvider((DumpComponentInfo)msg.obj); |
| 1873 | break; |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1874 | case SLEEPING: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1875 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "sleeping"); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1876 | handleSleeping((IBinder)msg.obj, msg.arg1 != 0); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1877 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1878 | break; |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1879 | case SET_CORE_SETTINGS: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1880 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "setCoreSettings"); |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1881 | handleSetCoreSettings((Bundle) msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1882 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1883 | break; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1884 | case UPDATE_PACKAGE_COMPATIBILITY_INFO: |
| 1885 | handleUpdatePackageCompatibilityInfo((UpdateCompatibilityData)msg.obj); |
Dianne Hackborn | f0754f5b | 2011-07-21 16:02:07 -0700 | [diff] [blame] | 1886 | break; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1887 | case UNSTABLE_PROVIDER_DIED: |
| 1888 | handleUnstableProviderDied((IBinder)msg.obj, false); |
| 1889 | break; |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 1890 | case REQUEST_ASSIST_CONTEXT_EXTRAS: |
| 1891 | handleRequestAssistContextExtras((RequestAssistContextExtras)msg.obj); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 1892 | break; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1893 | case TRANSLUCENT_CONVERSION_COMPLETE: |
| 1894 | handleTranslucentConversionComplete((IBinder)msg.obj, msg.arg1 == 1); |
| 1895 | break; |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 1896 | case INSTALL_PROVIDER: |
| 1897 | handleInstallProvider((ProviderInfo) msg.obj); |
| 1898 | break; |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1899 | case ON_NEW_ACTIVITY_OPTIONS: |
| 1900 | Pair<IBinder, ActivityOptions> pair = (Pair<IBinder, ActivityOptions>) msg.obj; |
| 1901 | onNewActivityOptions(pair.first, pair.second); |
Dake Gu | 7ef70b0 | 2014-07-08 18:37:12 -0700 | [diff] [blame] | 1902 | break; |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 1903 | case ENTER_ANIMATION_COMPLETE: |
| 1904 | handleEnterAnimationComplete((IBinder) msg.obj); |
| 1905 | break; |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 1906 | case START_BINDER_TRACKING: |
| 1907 | handleStartBinderTracking(); |
| 1908 | break; |
| 1909 | case STOP_BINDER_TRACKING_AND_DUMP: |
| 1910 | handleStopBinderTrackingAndDump((ParcelFileDescriptor) msg.obj); |
| 1911 | break; |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1912 | case LOCAL_VOICE_INTERACTION_STARTED: |
| 1913 | handleLocalVoiceInteractionStarted((IBinder) ((SomeArgs) msg.obj).arg1, |
| 1914 | (IVoiceInteractor) ((SomeArgs) msg.obj).arg2); |
Amith Yamasani | 6101911 | 2017-01-10 15:05:00 -0800 | [diff] [blame] | 1915 | break; |
Andreas Gampe | ab8a63b | 2018-01-05 13:55:15 -0800 | [diff] [blame] | 1916 | case ATTACH_AGENT: { |
| 1917 | Application app = getApplication(); |
| 1918 | handleAttachAgent((String) msg.obj, app != null ? app.mLoadedApk : null); |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1919 | break; |
Andreas Gampe | ab8a63b | 2018-01-05 13:55:15 -0800 | [diff] [blame] | 1920 | } |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 1921 | case APPLICATION_INFO_CHANGED: |
| 1922 | mUpdatingSystemConfig = true; |
| 1923 | try { |
| 1924 | handleApplicationInfoChanged((ApplicationInfo) msg.obj); |
| 1925 | } finally { |
| 1926 | mUpdatingSystemConfig = false; |
| 1927 | } |
| 1928 | break; |
Torne (Richard Coles) | 466cbe4 | 2017-05-31 14:09:14 -0400 | [diff] [blame] | 1929 | case RUN_ISOLATED_ENTRY_POINT: |
| 1930 | handleRunIsolatedEntryPoint((String) ((SomeArgs) msg.obj).arg1, |
| 1931 | (String[]) ((SomeArgs) msg.obj).arg2); |
| 1932 | break; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 1933 | case EXECUTE_TRANSACTION: |
Andrii Kulian | 0447068 | 2018-01-10 15:32:31 -0800 | [diff] [blame] | 1934 | final ClientTransaction transaction = (ClientTransaction) msg.obj; |
| 1935 | mTransactionExecutor.execute(transaction); |
| 1936 | if (isSystem()) { |
| 1937 | // Client transactions inside system process are recycled on the client side |
| 1938 | // instead of ClientLifecycleManager to avoid being cleared before this |
| 1939 | // message is handled. |
| 1940 | transaction.recycle(); |
| 1941 | } |
Andrii Kulian | 914aa7d | 2018-03-19 21:51:53 -0700 | [diff] [blame] | 1942 | // TODO(lifecycler): Recycle locally scheduled transactions. |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 1943 | break; |
Andrii Kulian | 320e3b5 | 2018-05-03 16:26:25 -0700 | [diff] [blame] | 1944 | case RELAUNCH_ACTIVITY: |
| 1945 | handleRelaunchActivityLocally((IBinder) msg.obj); |
| 1946 | break; |
Tim Murray | 59f3dc1 | 2018-10-22 15:26:08 -0700 | [diff] [blame] | 1947 | case PURGE_RESOURCES: |
| 1948 | schedulePurgeIdler(); |
| 1949 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1950 | } |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1951 | Object obj = msg.obj; |
| 1952 | if (obj instanceof SomeArgs) { |
| 1953 | ((SomeArgs) obj).recycle(); |
| 1954 | } |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 1955 | 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] | 1956 | } |
| 1957 | } |
| 1958 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1959 | private class Idler implements MessageQueue.IdleHandler { |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 1960 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1961 | public final boolean queueIdle() { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1962 | ActivityClientRecord a = mNewActivities; |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 1963 | boolean stopProfiling = false; |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 1964 | if (mBoundApplication != null && mProfiler.profileFd != null |
| 1965 | && mProfiler.autoStopProfiler) { |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 1966 | stopProfiling = true; |
| 1967 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1968 | if (a != null) { |
| 1969 | mNewActivities = null; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1970 | IActivityTaskManager am = ActivityTaskManager.getService(); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1971 | ActivityClientRecord prev; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1972 | do { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 1973 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1974 | TAG, "Reporting idle of " + a + |
| 1975 | " finished=" + |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1976 | (a.activity != null && a.activity.mFinished)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1977 | if (a.activity != null && !a.activity.mFinished) { |
| 1978 | try { |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 1979 | am.activityIdle(a.token, a.createdConfig, stopProfiling); |
Dianne Hackborn | e88846e | 2009-09-30 21:34:25 -0700 | [diff] [blame] | 1980 | a.createdConfig = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1981 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1982 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1983 | } |
| 1984 | } |
| 1985 | prev = a; |
| 1986 | a = a.nextIdle; |
| 1987 | prev.nextIdle = null; |
| 1988 | } while (a != null); |
| 1989 | } |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 1990 | if (stopProfiling) { |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 1991 | mProfiler.stopProfiling(); |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 1992 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1993 | return false; |
| 1994 | } |
| 1995 | } |
| 1996 | |
| 1997 | final class GcIdler implements MessageQueue.IdleHandler { |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 1998 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1999 | public final boolean queueIdle() { |
| 2000 | doGcIfNeeded(); |
Tim Murray | 59f3dc1 | 2018-10-22 15:26:08 -0700 | [diff] [blame] | 2001 | nPurgePendingResources(); |
| 2002 | return false; |
| 2003 | } |
| 2004 | } |
| 2005 | |
| 2006 | final class PurgeIdler implements MessageQueue.IdleHandler { |
| 2007 | @Override |
| 2008 | public boolean queueIdle() { |
| 2009 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "purgePendingResources"); |
| 2010 | nPurgePendingResources(); |
| 2011 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2012 | return false; |
| 2013 | } |
| 2014 | } |
| 2015 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 2016 | @UnsupportedAppUsage |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 2017 | public static ActivityThread currentActivityThread() { |
Jeff Sharkey | 66a017b | 2013-01-17 18:18:22 -0800 | [diff] [blame] | 2018 | return sCurrentActivityThread; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2019 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2020 | |
Wale Ogunwale | 9a6ef1e | 2015-06-02 13:41:00 -0700 | [diff] [blame] | 2021 | public static boolean isSystem() { |
| 2022 | return (sCurrentActivityThread != null) ? sCurrentActivityThread.mSystemThread : false; |
| 2023 | } |
| 2024 | |
Svetoslav | fbf0eca | 2015-05-01 16:52:41 -0700 | [diff] [blame] | 2025 | public static String currentOpPackageName() { |
| 2026 | ActivityThread am = currentActivityThread(); |
| 2027 | return (am != null && am.getApplication() != null) |
| 2028 | ? am.getApplication().getOpPackageName() : null; |
| 2029 | } |
| 2030 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 2031 | @UnsupportedAppUsage |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 2032 | public static String currentPackageName() { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2033 | ActivityThread am = currentActivityThread(); |
| 2034 | return (am != null && am.mBoundApplication != null) |
Dianne Hackborn | b57a50b | 2013-04-11 17:29:32 -0700 | [diff] [blame] | 2035 | ? am.mBoundApplication.appInfo.packageName : null; |
| 2036 | } |
| 2037 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 2038 | @UnsupportedAppUsage |
Dianne Hackborn | b57a50b | 2013-04-11 17:29:32 -0700 | [diff] [blame] | 2039 | public static String currentProcessName() { |
| 2040 | ActivityThread am = currentActivityThread(); |
| 2041 | return (am != null && am.mBoundApplication != null) |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2042 | ? am.mBoundApplication.processName : null; |
| 2043 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2044 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 2045 | @UnsupportedAppUsage |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 2046 | public static Application currentApplication() { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2047 | ActivityThread am = currentActivityThread(); |
| 2048 | return am != null ? am.mInitialApplication : null; |
| 2049 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2050 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 2051 | @UnsupportedAppUsage |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2052 | public static IPackageManager getPackageManager() { |
| 2053 | if (sPackageManager != null) { |
| 2054 | //Slog.v("PackageManager", "returning cur default = " + sPackageManager); |
| 2055 | return sPackageManager; |
| 2056 | } |
| 2057 | IBinder b = ServiceManager.getService("package"); |
| 2058 | //Slog.v("PackageManager", "default service binder = " + b); |
| 2059 | sPackageManager = IPackageManager.Stub.asInterface(b); |
| 2060 | //Slog.v("PackageManager", "default service = " + sPackageManager); |
| 2061 | return sPackageManager; |
| 2062 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2063 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 2064 | private Configuration mMainThreadConfig = new Configuration(); |
Amith Yamasani | 4f128e4 | 2016-05-10 11:44:12 -0700 | [diff] [blame] | 2065 | |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 2066 | Configuration applyConfigCompatMainThread(int displayDensity, Configuration config, |
| 2067 | CompatibilityInfo compat) { |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 2068 | if (config == null) { |
| 2069 | return null; |
| 2070 | } |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 2071 | if (!compat.supportsScreen()) { |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 2072 | mMainThreadConfig.setTo(config); |
| 2073 | config = mMainThreadConfig; |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 2074 | compat.applyToConfiguration(displayDensity, config); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 2075 | } |
| 2076 | return config; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2077 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2078 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2079 | /** |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 2080 | * Creates the top level resources for the given package. Will return an existing |
| 2081 | * Resources if one has already been created. |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2082 | */ |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 2083 | Resources getTopLevelResources(String resDir, String[] splitResDirs, String[] overlayDirs, |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 2084 | String[] libDirs, int displayId, LoadedApk pkgInfo) { |
| 2085 | return mResourcesManager.getResources(null, resDir, splitResDirs, overlayDirs, libDirs, |
| 2086 | displayId, null, pkgInfo.getCompatibilityInfo(), pkgInfo.getClassLoader()); |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 2087 | } |
| 2088 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 2089 | @UnsupportedAppUsage |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2090 | final Handler getHandler() { |
| 2091 | return mH; |
| 2092 | } |
| 2093 | |
Mathew Inwood | 8c854f8 | 2018-09-14 12:35:36 +0100 | [diff] [blame] | 2094 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2095 | public final LoadedApk getPackageInfo(String packageName, CompatibilityInfo compatInfo, |
| 2096 | int flags) { |
| 2097 | return getPackageInfo(packageName, compatInfo, flags, UserHandle.myUserId()); |
Amith Yamasani | 98edc95 | 2012-09-25 14:09:27 -0700 | [diff] [blame] | 2098 | } |
| 2099 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2100 | public final LoadedApk getPackageInfo(String packageName, CompatibilityInfo compatInfo, |
| 2101 | int flags, int userId) { |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 2102 | final boolean differentUser = (UserHandle.myUserId() != userId); |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 2103 | synchronized (mResourcesManager) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2104 | WeakReference<LoadedApk> ref; |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 2105 | if (differentUser) { |
| 2106 | // Caching not supported across users |
| 2107 | ref = null; |
| 2108 | } else if ((flags & Context.CONTEXT_INCLUDE_CODE) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2109 | ref = mPackages.get(packageName); |
| 2110 | } else { |
| 2111 | ref = mResourcePackages.get(packageName); |
| 2112 | } |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 2113 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2114 | LoadedApk packageInfo = ref != null ? ref.get() : null; |
| 2115 | //Slog.i(TAG, "getPackageInfo " + packageName + ": " + packageInfo); |
| 2116 | //if (packageInfo != null) Slog.i(TAG, "isUptoDate " + packageInfo.mResDir |
| 2117 | // + ": " + packageInfo.mResources.getAssets().isUpToDate()); |
| 2118 | if (packageInfo != null && (packageInfo.mResources == null |
| 2119 | || packageInfo.mResources.getAssets().isUpToDate())) { |
| 2120 | if (packageInfo.isSecurityViolation() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2121 | && (flags&Context.CONTEXT_IGNORE_SECURITY) == 0) { |
| 2122 | throw new SecurityException( |
| 2123 | "Requesting code from " + packageName |
| 2124 | + " to be run in process " |
| 2125 | + mBoundApplication.processName |
| 2126 | + "/" + mBoundApplication.appInfo.uid); |
| 2127 | } |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2128 | return packageInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2129 | } |
| 2130 | } |
| 2131 | |
| 2132 | ApplicationInfo ai = null; |
| 2133 | try { |
| 2134 | ai = getPackageManager().getApplicationInfo(packageName, |
Jeff Sharkey | c5967e9 | 2016-01-07 18:50:29 -0700 | [diff] [blame] | 2135 | PackageManager.GET_SHARED_LIBRARY_FILES |
| 2136 | | PackageManager.MATCH_DEBUG_TRIAGED_MISSING, |
Jeff Sharkey | ec5f7d1 | 2018-08-08 09:15:04 -0600 | [diff] [blame] | 2137 | (userId < 0) ? UserHandle.myUserId() : userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2138 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2139 | throw e.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2140 | } |
| 2141 | |
| 2142 | if (ai != null) { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2143 | return getPackageInfo(ai, compatInfo, flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2144 | } |
| 2145 | |
| 2146 | return null; |
| 2147 | } |
| 2148 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 2149 | @UnsupportedAppUsage |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2150 | public final LoadedApk getPackageInfo(ApplicationInfo ai, CompatibilityInfo compatInfo, |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2151 | int flags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2152 | boolean includeCode = (flags&Context.CONTEXT_INCLUDE_CODE) != 0; |
| 2153 | boolean securityViolation = includeCode && ai.uid != 0 |
| 2154 | && ai.uid != Process.SYSTEM_UID && (mBoundApplication != null |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 2155 | ? !UserHandle.isSameApp(ai.uid, mBoundApplication.appInfo.uid) |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 2156 | : true); |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 2157 | boolean registerPackage = includeCode && (flags&Context.CONTEXT_REGISTER_PACKAGE) != 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2158 | if ((flags&(Context.CONTEXT_INCLUDE_CODE |
| 2159 | |Context.CONTEXT_IGNORE_SECURITY)) |
| 2160 | == Context.CONTEXT_INCLUDE_CODE) { |
| 2161 | if (securityViolation) { |
| 2162 | String msg = "Requesting code from " + ai.packageName |
| 2163 | + " (with uid " + ai.uid + ")"; |
| 2164 | if (mBoundApplication != null) { |
| 2165 | msg = msg + " to be run in process " |
| 2166 | + mBoundApplication.processName + " (with uid " |
| 2167 | + mBoundApplication.appInfo.uid + ")"; |
| 2168 | } |
| 2169 | throw new SecurityException(msg); |
| 2170 | } |
| 2171 | } |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2172 | return getPackageInfo(ai, compatInfo, null, securityViolation, includeCode, |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 2173 | registerPackage); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2174 | } |
| 2175 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 2176 | @Override |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 2177 | @UnsupportedAppUsage |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2178 | public final LoadedApk getPackageInfoNoCheck(ApplicationInfo ai, |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2179 | CompatibilityInfo compatInfo) { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2180 | return getPackageInfo(ai, compatInfo, null, false, true, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2181 | } |
| 2182 | |
Mathew Inwood | 8c854f8 | 2018-09-14 12:35:36 +0100 | [diff] [blame] | 2183 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2184 | public final LoadedApk peekPackageInfo(String packageName, boolean includeCode) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 2185 | synchronized (mResourcesManager) { |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2186 | WeakReference<LoadedApk> ref; |
| 2187 | if (includeCode) { |
| 2188 | ref = mPackages.get(packageName); |
| 2189 | } else { |
| 2190 | ref = mResourcePackages.get(packageName); |
| 2191 | } |
| 2192 | return ref != null ? ref.get() : null; |
| 2193 | } |
| 2194 | } |
| 2195 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2196 | private LoadedApk getPackageInfo(ApplicationInfo aInfo, CompatibilityInfo compatInfo, |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 2197 | ClassLoader baseLoader, boolean securityViolation, boolean includeCode, |
| 2198 | boolean registerPackage) { |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 2199 | final boolean differentUser = (UserHandle.myUserId() != UserHandle.getUserId(aInfo.uid)); |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 2200 | synchronized (mResourcesManager) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2201 | WeakReference<LoadedApk> ref; |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 2202 | if (differentUser) { |
| 2203 | // Caching not supported across users |
| 2204 | ref = null; |
| 2205 | } else if (includeCode) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2206 | ref = mPackages.get(aInfo.packageName); |
| 2207 | } else { |
| 2208 | ref = mResourcePackages.get(aInfo.packageName); |
| 2209 | } |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 2210 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2211 | LoadedApk packageInfo = ref != null ? ref.get() : null; |
| 2212 | if (packageInfo == null || (packageInfo.mResources != null |
| 2213 | && !packageInfo.mResources.getAssets().isUpToDate())) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2214 | if (localLOGV) Slog.v(TAG, (includeCode ? "Loading code package " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2215 | : "Loading resource-only package ") + aInfo.packageName |
| 2216 | + " (in " + (mBoundApplication != null |
| 2217 | ? mBoundApplication.processName : null) |
| 2218 | + ")"); |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2219 | packageInfo = |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 2220 | new LoadedApk(this, aInfo, compatInfo, baseLoader, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2221 | securityViolation, includeCode && |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 2222 | (aInfo.flags&ApplicationInfo.FLAG_HAS_CODE) != 0, registerPackage); |
Narayan Kamath | cb38318 | 2014-10-29 17:56:42 +0000 | [diff] [blame] | 2223 | |
| 2224 | if (mSystemThread && "android".equals(aInfo.packageName)) { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2225 | packageInfo.installSystemApplicationInfo(aInfo, |
| 2226 | getSystemContext().mPackageInfo.getClassLoader()); |
Narayan Kamath | cb38318 | 2014-10-29 17:56:42 +0000 | [diff] [blame] | 2227 | } |
| 2228 | |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 2229 | if (differentUser) { |
| 2230 | // Caching not supported across users |
| 2231 | } else if (includeCode) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2232 | mPackages.put(aInfo.packageName, |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2233 | new WeakReference<LoadedApk>(packageInfo)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2234 | } else { |
| 2235 | mResourcePackages.put(aInfo.packageName, |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2236 | new WeakReference<LoadedApk>(packageInfo)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2237 | } |
| 2238 | } |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2239 | return packageInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2240 | } |
| 2241 | } |
| 2242 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 2243 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2244 | ActivityThread() { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 2245 | mResourcesManager = ResourcesManager.getInstance(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2246 | } |
| 2247 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 2248 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2249 | public ApplicationThread getApplicationThread() |
| 2250 | { |
| 2251 | return mAppThread; |
| 2252 | } |
| 2253 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 2254 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2255 | public Instrumentation getInstrumentation() |
| 2256 | { |
| 2257 | return mInstrumentation; |
| 2258 | } |
| 2259 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2260 | public boolean isProfiling() { |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 2261 | return mProfiler != null && mProfiler.profileFile != null |
| 2262 | && mProfiler.profileFd == null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2263 | } |
| 2264 | |
| 2265 | public String getProfileFilePath() { |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 2266 | return mProfiler.profileFile; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2267 | } |
| 2268 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 2269 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2270 | public Looper getLooper() { |
| 2271 | return mLooper; |
| 2272 | } |
| 2273 | |
Jeff Sharkey | 8439ac0 | 2017-12-12 17:26:23 -0700 | [diff] [blame] | 2274 | public Executor getExecutor() { |
| 2275 | return mExecutor; |
| 2276 | } |
| 2277 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 2278 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2279 | public Application getApplication() { |
| 2280 | return mInitialApplication; |
| 2281 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2282 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 2283 | @UnsupportedAppUsage |
Dianne Hackborn | d97c7ad | 2009-06-19 11:37:35 -0700 | [diff] [blame] | 2284 | public String getProcessName() { |
| 2285 | return mBoundApplication.processName; |
| 2286 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2287 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 2288 | @UnsupportedAppUsage |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 2289 | public ContextImpl getSystemContext() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2290 | synchronized (this) { |
| 2291 | if (mSystemContext == null) { |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 2292 | mSystemContext = ContextImpl.createSystemContext(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2293 | } |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 2294 | return mSystemContext; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2295 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2296 | } |
| 2297 | |
Adam Lesinski | a82b626 | 2017-03-21 16:56:17 -0700 | [diff] [blame] | 2298 | public ContextImpl getSystemUiContext() { |
| 2299 | synchronized (this) { |
| 2300 | if (mSystemUiContext == null) { |
Adam Lesinski | 6f1a917 | 2017-04-10 16:35:19 -0700 | [diff] [blame] | 2301 | mSystemUiContext = ContextImpl.createSystemUiContext(getSystemContext()); |
Adam Lesinski | a82b626 | 2017-03-21 16:56:17 -0700 | [diff] [blame] | 2302 | } |
| 2303 | return mSystemUiContext; |
| 2304 | } |
| 2305 | } |
| 2306 | |
lumark | 0b05f9e | 2018-11-26 15:09:06 +0800 | [diff] [blame] | 2307 | /** |
| 2308 | * Create the context instance base on system resources & display information which used for UI. |
| 2309 | * @param displayId The ID of the display where the UI is shown. |
| 2310 | * @see ContextImpl#createSystemUiContext(ContextImpl, int) |
| 2311 | */ |
| 2312 | public ContextImpl createSystemUiContext(int displayId) { |
| 2313 | return ContextImpl.createSystemUiContext(getSystemUiContext(), displayId); |
| 2314 | } |
| 2315 | |
Narayan Kamath | 29564cd | 2014-08-07 10:57:40 +0100 | [diff] [blame] | 2316 | public void installSystemApplicationInfo(ApplicationInfo info, ClassLoader classLoader) { |
Mike Cleron | 432b713 | 2009-09-24 15:28:29 -0700 | [diff] [blame] | 2317 | synchronized (this) { |
Narayan Kamath | 29564cd | 2014-08-07 10:57:40 +0100 | [diff] [blame] | 2318 | getSystemContext().installSystemApplicationInfo(info, classLoader); |
Adam Lesinski | a82b626 | 2017-03-21 16:56:17 -0700 | [diff] [blame] | 2319 | getSystemUiContext().installSystemApplicationInfo(info, classLoader); |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 2320 | |
| 2321 | // give ourselves a default profiler |
| 2322 | mProfiler = new Profiler(); |
Mike Cleron | 432b713 | 2009-09-24 15:28:29 -0700 | [diff] [blame] | 2323 | } |
| 2324 | } |
| 2325 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 2326 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2327 | void scheduleGcIdler() { |
| 2328 | if (!mGcIdlerScheduled) { |
| 2329 | mGcIdlerScheduled = true; |
| 2330 | Looper.myQueue().addIdleHandler(mGcIdler); |
| 2331 | } |
| 2332 | mH.removeMessages(H.GC_WHEN_IDLE); |
| 2333 | } |
| 2334 | |
| 2335 | void unscheduleGcIdler() { |
| 2336 | if (mGcIdlerScheduled) { |
| 2337 | mGcIdlerScheduled = false; |
| 2338 | Looper.myQueue().removeIdleHandler(mGcIdler); |
| 2339 | } |
| 2340 | mH.removeMessages(H.GC_WHEN_IDLE); |
| 2341 | } |
| 2342 | |
Tim Murray | 59f3dc1 | 2018-10-22 15:26:08 -0700 | [diff] [blame] | 2343 | void schedulePurgeIdler() { |
| 2344 | if (!mPurgeIdlerScheduled) { |
| 2345 | mPurgeIdlerScheduled = true; |
| 2346 | Looper.myQueue().addIdleHandler(mPurgeIdler); |
| 2347 | } |
| 2348 | mH.removeMessages(H.PURGE_RESOURCES); |
| 2349 | } |
| 2350 | |
| 2351 | void unschedulePurgeIdler() { |
| 2352 | if (mPurgeIdlerScheduled) { |
| 2353 | mPurgeIdlerScheduled = false; |
| 2354 | Looper.myQueue().removeIdleHandler(mPurgeIdler); |
| 2355 | } |
| 2356 | mH.removeMessages(H.PURGE_RESOURCES); |
| 2357 | } |
| 2358 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2359 | void doGcIfNeeded() { |
| 2360 | mGcIdlerScheduled = false; |
| 2361 | final long now = SystemClock.uptimeMillis(); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2362 | //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] | 2363 | // + "m now=" + now); |
| 2364 | if ((BinderInternal.getLastGcTime()+MIN_TIME_BETWEEN_GCS) < now) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2365 | //Slog.i(TAG, "**** WE DO, WE DO WANT TO GC!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2366 | BinderInternal.forceGc("bg"); |
| 2367 | } |
| 2368 | } |
| 2369 | |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2370 | private static final String HEAP_FULL_COLUMN |
| 2371 | = "%13s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s"; |
| 2372 | private static final String HEAP_COLUMN |
| 2373 | = "%13s %8s %8s %8s %8s %8s %8s %8s"; |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2374 | private static final String ONE_COUNT_COLUMN = "%21s %8d"; |
| 2375 | private static final String TWO_COUNT_COLUMNS = "%21s %8d %21s %8d"; |
| 2376 | private static final String ONE_COUNT_COLUMN_HEADER = "%21s %8s"; |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2377 | |
| 2378 | // Formatting for checkin service - update version if row format changes |
Martijn Coenen | 41f94ed | 2015-12-14 15:28:51 +0100 | [diff] [blame] | 2379 | private static final int ACTIVITY_THREAD_CHECKIN_VERSION = 4; |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2380 | |
| 2381 | static void printRow(PrintWriter pw, String format, Object...objs) { |
| 2382 | pw.println(String.format(format, objs)); |
| 2383 | } |
| 2384 | |
| 2385 | public static void dumpMemInfoTable(PrintWriter pw, Debug.MemoryInfo memInfo, boolean checkin, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2386 | boolean dumpFullInfo, boolean dumpDalvik, boolean dumpSummaryOnly, |
| 2387 | int pid, String processName, |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2388 | long nativeMax, long nativeAllocated, long nativeFree, |
| 2389 | long dalvikMax, long dalvikAllocated, long dalvikFree) { |
| 2390 | |
| 2391 | // For checkin, we print one long comma-separated list of values |
| 2392 | if (checkin) { |
| 2393 | // NOTE: if you change anything significant below, also consider changing |
| 2394 | // ACTIVITY_THREAD_CHECKIN_VERSION. |
| 2395 | |
| 2396 | // Header |
| 2397 | pw.print(ACTIVITY_THREAD_CHECKIN_VERSION); pw.print(','); |
| 2398 | pw.print(pid); pw.print(','); |
| 2399 | pw.print(processName); pw.print(','); |
| 2400 | |
| 2401 | // Heap info - max |
| 2402 | pw.print(nativeMax); pw.print(','); |
| 2403 | pw.print(dalvikMax); pw.print(','); |
| 2404 | pw.print("N/A,"); |
| 2405 | pw.print(nativeMax + dalvikMax); pw.print(','); |
| 2406 | |
| 2407 | // Heap info - allocated |
| 2408 | pw.print(nativeAllocated); pw.print(','); |
| 2409 | pw.print(dalvikAllocated); pw.print(','); |
| 2410 | pw.print("N/A,"); |
| 2411 | pw.print(nativeAllocated + dalvikAllocated); pw.print(','); |
| 2412 | |
| 2413 | // Heap info - free |
| 2414 | pw.print(nativeFree); pw.print(','); |
| 2415 | pw.print(dalvikFree); pw.print(','); |
| 2416 | pw.print("N/A,"); |
| 2417 | pw.print(nativeFree + dalvikFree); pw.print(','); |
| 2418 | |
| 2419 | // Heap info - proportional set size |
| 2420 | pw.print(memInfo.nativePss); pw.print(','); |
| 2421 | pw.print(memInfo.dalvikPss); pw.print(','); |
| 2422 | pw.print(memInfo.otherPss); pw.print(','); |
| 2423 | pw.print(memInfo.getTotalPss()); pw.print(','); |
| 2424 | |
| 2425 | // Heap info - swappable set size |
| 2426 | pw.print(memInfo.nativeSwappablePss); pw.print(','); |
| 2427 | pw.print(memInfo.dalvikSwappablePss); pw.print(','); |
| 2428 | pw.print(memInfo.otherSwappablePss); pw.print(','); |
| 2429 | pw.print(memInfo.getTotalSwappablePss()); pw.print(','); |
| 2430 | |
| 2431 | // Heap info - shared dirty |
| 2432 | pw.print(memInfo.nativeSharedDirty); pw.print(','); |
| 2433 | pw.print(memInfo.dalvikSharedDirty); pw.print(','); |
| 2434 | pw.print(memInfo.otherSharedDirty); pw.print(','); |
| 2435 | pw.print(memInfo.getTotalSharedDirty()); pw.print(','); |
| 2436 | |
| 2437 | // Heap info - shared clean |
| 2438 | pw.print(memInfo.nativeSharedClean); pw.print(','); |
| 2439 | pw.print(memInfo.dalvikSharedClean); pw.print(','); |
| 2440 | pw.print(memInfo.otherSharedClean); pw.print(','); |
| 2441 | pw.print(memInfo.getTotalSharedClean()); pw.print(','); |
| 2442 | |
| 2443 | // Heap info - private Dirty |
| 2444 | pw.print(memInfo.nativePrivateDirty); pw.print(','); |
| 2445 | pw.print(memInfo.dalvikPrivateDirty); pw.print(','); |
| 2446 | pw.print(memInfo.otherPrivateDirty); pw.print(','); |
| 2447 | pw.print(memInfo.getTotalPrivateDirty()); pw.print(','); |
| 2448 | |
| 2449 | // Heap info - private Clean |
| 2450 | pw.print(memInfo.nativePrivateClean); pw.print(','); |
| 2451 | pw.print(memInfo.dalvikPrivateClean); pw.print(','); |
| 2452 | pw.print(memInfo.otherPrivateClean); pw.print(','); |
| 2453 | pw.print(memInfo.getTotalPrivateClean()); pw.print(','); |
| 2454 | |
Martijn Coenen | 41f94ed | 2015-12-14 15:28:51 +0100 | [diff] [blame] | 2455 | // Heap info - swapped out |
| 2456 | pw.print(memInfo.nativeSwappedOut); pw.print(','); |
| 2457 | pw.print(memInfo.dalvikSwappedOut); pw.print(','); |
| 2458 | pw.print(memInfo.otherSwappedOut); pw.print(','); |
| 2459 | pw.print(memInfo.getTotalSwappedOut()); pw.print(','); |
| 2460 | |
| 2461 | // Heap info - swapped out pss |
| 2462 | if (memInfo.hasSwappedOutPss) { |
| 2463 | pw.print(memInfo.nativeSwappedOutPss); pw.print(','); |
| 2464 | pw.print(memInfo.dalvikSwappedOutPss); pw.print(','); |
| 2465 | pw.print(memInfo.otherSwappedOutPss); pw.print(','); |
| 2466 | pw.print(memInfo.getTotalSwappedOutPss()); pw.print(','); |
| 2467 | } else { |
| 2468 | pw.print("N/A,"); |
| 2469 | pw.print("N/A,"); |
| 2470 | pw.print("N/A,"); |
| 2471 | pw.print("N/A,"); |
| 2472 | } |
| 2473 | |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2474 | // Heap info - other areas |
| 2475 | for (int i=0; i<Debug.MemoryInfo.NUM_OTHER_STATS; i++) { |
| 2476 | pw.print(Debug.MemoryInfo.getOtherLabel(i)); pw.print(','); |
| 2477 | pw.print(memInfo.getOtherPss(i)); pw.print(','); |
| 2478 | pw.print(memInfo.getOtherSwappablePss(i)); pw.print(','); |
| 2479 | pw.print(memInfo.getOtherSharedDirty(i)); pw.print(','); |
| 2480 | pw.print(memInfo.getOtherSharedClean(i)); pw.print(','); |
| 2481 | pw.print(memInfo.getOtherPrivateDirty(i)); pw.print(','); |
| 2482 | pw.print(memInfo.getOtherPrivateClean(i)); pw.print(','); |
Martijn Coenen | 41f94ed | 2015-12-14 15:28:51 +0100 | [diff] [blame] | 2483 | pw.print(memInfo.getOtherSwappedOut(i)); pw.print(','); |
| 2484 | if (memInfo.hasSwappedOutPss) { |
| 2485 | pw.print(memInfo.getOtherSwappedOutPss(i)); pw.print(','); |
| 2486 | } else { |
| 2487 | pw.print("N/A,"); |
| 2488 | } |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2489 | } |
| 2490 | return; |
| 2491 | } |
| 2492 | |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2493 | if (!dumpSummaryOnly) { |
| 2494 | if (dumpFullInfo) { |
| 2495 | printRow(pw, HEAP_FULL_COLUMN, "", "Pss", "Pss", "Shared", "Private", |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2496 | "Shared", "Private", memInfo.hasSwappedOutPss ? "SwapPss" : "Swap", |
| 2497 | "Heap", "Heap", "Heap"); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2498 | printRow(pw, HEAP_FULL_COLUMN, "", "Total", "Clean", "Dirty", "Dirty", |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2499 | "Clean", "Clean", "Dirty", |
| 2500 | "Size", "Alloc", "Free"); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2501 | printRow(pw, HEAP_FULL_COLUMN, "", "------", "------", "------", "------", |
| 2502 | "------", "------", "------", "------", "------", "------"); |
| 2503 | printRow(pw, HEAP_FULL_COLUMN, "Native Heap", memInfo.nativePss, |
| 2504 | memInfo.nativeSwappablePss, memInfo.nativeSharedDirty, |
| 2505 | memInfo.nativePrivateDirty, memInfo.nativeSharedClean, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2506 | memInfo.nativePrivateClean, memInfo.hasSwappedOutPss ? |
Richard Uhler | 91702eb3 | 2017-06-23 16:54:25 +0100 | [diff] [blame] | 2507 | memInfo.nativeSwappedOutPss : memInfo.nativeSwappedOut, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2508 | nativeMax, nativeAllocated, nativeFree); |
| 2509 | printRow(pw, HEAP_FULL_COLUMN, "Dalvik Heap", memInfo.dalvikPss, |
| 2510 | memInfo.dalvikSwappablePss, memInfo.dalvikSharedDirty, |
| 2511 | memInfo.dalvikPrivateDirty, memInfo.dalvikSharedClean, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2512 | memInfo.dalvikPrivateClean, memInfo.hasSwappedOutPss ? |
Richard Uhler | 91702eb3 | 2017-06-23 16:54:25 +0100 | [diff] [blame] | 2513 | memInfo.dalvikSwappedOutPss : memInfo.dalvikSwappedOut, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2514 | dalvikMax, dalvikAllocated, dalvikFree); |
| 2515 | } else { |
| 2516 | printRow(pw, HEAP_COLUMN, "", "Pss", "Private", |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2517 | "Private", memInfo.hasSwappedOutPss ? "SwapPss" : "Swap", |
| 2518 | "Heap", "Heap", "Heap"); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2519 | printRow(pw, HEAP_COLUMN, "", "Total", "Dirty", |
| 2520 | "Clean", "Dirty", "Size", "Alloc", "Free"); |
| 2521 | printRow(pw, HEAP_COLUMN, "", "------", "------", "------", |
| 2522 | "------", "------", "------", "------", "------"); |
| 2523 | printRow(pw, HEAP_COLUMN, "Native Heap", memInfo.nativePss, |
| 2524 | memInfo.nativePrivateDirty, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2525 | memInfo.nativePrivateClean, |
| 2526 | memInfo.hasSwappedOutPss ? memInfo.nativeSwappedOutPss : |
| 2527 | memInfo.nativeSwappedOut, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2528 | nativeMax, nativeAllocated, nativeFree); |
| 2529 | printRow(pw, HEAP_COLUMN, "Dalvik Heap", memInfo.dalvikPss, |
| 2530 | memInfo.dalvikPrivateDirty, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2531 | memInfo.dalvikPrivateClean, |
| 2532 | memInfo.hasSwappedOutPss ? memInfo.dalvikSwappedOutPss : |
| 2533 | memInfo.dalvikSwappedOut, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2534 | dalvikMax, dalvikAllocated, dalvikFree); |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2535 | } |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2536 | |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2537 | int otherPss = memInfo.otherPss; |
| 2538 | int otherSwappablePss = memInfo.otherSwappablePss; |
| 2539 | int otherSharedDirty = memInfo.otherSharedDirty; |
| 2540 | int otherPrivateDirty = memInfo.otherPrivateDirty; |
| 2541 | int otherSharedClean = memInfo.otherSharedClean; |
| 2542 | int otherPrivateClean = memInfo.otherPrivateClean; |
| 2543 | int otherSwappedOut = memInfo.otherSwappedOut; |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2544 | int otherSwappedOutPss = memInfo.otherSwappedOutPss; |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2545 | |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2546 | for (int i=0; i<Debug.MemoryInfo.NUM_OTHER_STATS; i++) { |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2547 | final int myPss = memInfo.getOtherPss(i); |
| 2548 | final int mySwappablePss = memInfo.getOtherSwappablePss(i); |
| 2549 | final int mySharedDirty = memInfo.getOtherSharedDirty(i); |
| 2550 | final int myPrivateDirty = memInfo.getOtherPrivateDirty(i); |
| 2551 | final int mySharedClean = memInfo.getOtherSharedClean(i); |
| 2552 | final int myPrivateClean = memInfo.getOtherPrivateClean(i); |
| 2553 | final int mySwappedOut = memInfo.getOtherSwappedOut(i); |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2554 | final int mySwappedOutPss = memInfo.getOtherSwappedOutPss(i); |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2555 | if (myPss != 0 || mySharedDirty != 0 || myPrivateDirty != 0 |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2556 | || mySharedClean != 0 || myPrivateClean != 0 |
| 2557 | || (memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut) != 0) { |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2558 | if (dumpFullInfo) { |
| 2559 | printRow(pw, HEAP_FULL_COLUMN, Debug.MemoryInfo.getOtherLabel(i), |
| 2560 | myPss, mySwappablePss, mySharedDirty, myPrivateDirty, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2561 | mySharedClean, myPrivateClean, |
| 2562 | memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut, |
| 2563 | "", "", ""); |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2564 | } else { |
| 2565 | printRow(pw, HEAP_COLUMN, Debug.MemoryInfo.getOtherLabel(i), |
| 2566 | myPss, myPrivateDirty, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2567 | myPrivateClean, |
| 2568 | memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut, |
| 2569 | "", "", ""); |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2570 | } |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2571 | otherPss -= myPss; |
| 2572 | otherSwappablePss -= mySwappablePss; |
| 2573 | otherSharedDirty -= mySharedDirty; |
| 2574 | otherPrivateDirty -= myPrivateDirty; |
| 2575 | otherSharedClean -= mySharedClean; |
| 2576 | otherPrivateClean -= myPrivateClean; |
| 2577 | otherSwappedOut -= mySwappedOut; |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2578 | otherSwappedOutPss -= mySwappedOutPss; |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2579 | } |
| 2580 | } |
| 2581 | |
| 2582 | if (dumpFullInfo) { |
| 2583 | printRow(pw, HEAP_FULL_COLUMN, "Unknown", otherPss, otherSwappablePss, |
| 2584 | otherSharedDirty, otherPrivateDirty, otherSharedClean, otherPrivateClean, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2585 | memInfo.hasSwappedOutPss ? otherSwappedOutPss : otherSwappedOut, |
| 2586 | "", "", ""); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2587 | printRow(pw, HEAP_FULL_COLUMN, "TOTAL", memInfo.getTotalPss(), |
| 2588 | memInfo.getTotalSwappablePss(), |
| 2589 | memInfo.getTotalSharedDirty(), memInfo.getTotalPrivateDirty(), |
| 2590 | memInfo.getTotalSharedClean(), memInfo.getTotalPrivateClean(), |
Thierry Strudel | 9b51160 | 2016-02-25 17:46:38 -0800 | [diff] [blame] | 2591 | memInfo.hasSwappedOutPss ? memInfo.getTotalSwappedOutPss() : |
| 2592 | memInfo.getTotalSwappedOut(), |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2593 | nativeMax+dalvikMax, nativeAllocated+dalvikAllocated, |
| 2594 | nativeFree+dalvikFree); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2595 | } else { |
| 2596 | printRow(pw, HEAP_COLUMN, "Unknown", otherPss, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2597 | otherPrivateDirty, otherPrivateClean, |
| 2598 | memInfo.hasSwappedOutPss ? otherSwappedOutPss : otherSwappedOut, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2599 | "", "", ""); |
| 2600 | printRow(pw, HEAP_COLUMN, "TOTAL", memInfo.getTotalPss(), |
| 2601 | memInfo.getTotalPrivateDirty(), |
| 2602 | memInfo.getTotalPrivateClean(), |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2603 | memInfo.hasSwappedOutPss ? memInfo.getTotalSwappedOutPss() : |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2604 | memInfo.getTotalSwappedOut(), |
| 2605 | nativeMax+dalvikMax, |
| 2606 | nativeAllocated+dalvikAllocated, nativeFree+dalvikFree); |
| 2607 | } |
| 2608 | |
| 2609 | if (dumpDalvik) { |
| 2610 | pw.println(" "); |
| 2611 | pw.println(" Dalvik Details"); |
| 2612 | |
| 2613 | for (int i=Debug.MemoryInfo.NUM_OTHER_STATS; |
| 2614 | i<Debug.MemoryInfo.NUM_OTHER_STATS + Debug.MemoryInfo.NUM_DVK_STATS; i++) { |
| 2615 | final int myPss = memInfo.getOtherPss(i); |
| 2616 | final int mySwappablePss = memInfo.getOtherSwappablePss(i); |
| 2617 | final int mySharedDirty = memInfo.getOtherSharedDirty(i); |
| 2618 | final int myPrivateDirty = memInfo.getOtherPrivateDirty(i); |
| 2619 | final int mySharedClean = memInfo.getOtherSharedClean(i); |
| 2620 | final int myPrivateClean = memInfo.getOtherPrivateClean(i); |
| 2621 | final int mySwappedOut = memInfo.getOtherSwappedOut(i); |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2622 | final int mySwappedOutPss = memInfo.getOtherSwappedOutPss(i); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2623 | if (myPss != 0 || mySharedDirty != 0 || myPrivateDirty != 0 |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2624 | || mySharedClean != 0 || myPrivateClean != 0 |
| 2625 | || (memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut) != 0) { |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2626 | if (dumpFullInfo) { |
| 2627 | printRow(pw, HEAP_FULL_COLUMN, Debug.MemoryInfo.getOtherLabel(i), |
| 2628 | myPss, mySwappablePss, mySharedDirty, myPrivateDirty, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2629 | mySharedClean, myPrivateClean, |
| 2630 | memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut, |
| 2631 | "", "", ""); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2632 | } else { |
| 2633 | printRow(pw, HEAP_COLUMN, Debug.MemoryInfo.getOtherLabel(i), |
| 2634 | myPss, myPrivateDirty, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2635 | myPrivateClean, |
| 2636 | memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut, |
| 2637 | "", "", ""); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2638 | } |
| 2639 | } |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2640 | } |
| 2641 | } |
| 2642 | } |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2643 | |
| 2644 | pw.println(" "); |
| 2645 | pw.println(" App Summary"); |
| 2646 | printRow(pw, ONE_COUNT_COLUMN_HEADER, "", "Pss(KB)"); |
| 2647 | printRow(pw, ONE_COUNT_COLUMN_HEADER, "", "------"); |
| 2648 | printRow(pw, ONE_COUNT_COLUMN, |
| 2649 | "Java Heap:", memInfo.getSummaryJavaHeap()); |
| 2650 | printRow(pw, ONE_COUNT_COLUMN, |
| 2651 | "Native Heap:", memInfo.getSummaryNativeHeap()); |
| 2652 | printRow(pw, ONE_COUNT_COLUMN, |
| 2653 | "Code:", memInfo.getSummaryCode()); |
| 2654 | printRow(pw, ONE_COUNT_COLUMN, |
| 2655 | "Stack:", memInfo.getSummaryStack()); |
| 2656 | printRow(pw, ONE_COUNT_COLUMN, |
| 2657 | "Graphics:", memInfo.getSummaryGraphics()); |
| 2658 | printRow(pw, ONE_COUNT_COLUMN, |
| 2659 | "Private Other:", memInfo.getSummaryPrivateOther()); |
| 2660 | printRow(pw, ONE_COUNT_COLUMN, |
| 2661 | "System:", memInfo.getSummarySystem()); |
| 2662 | pw.println(" "); |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2663 | if (memInfo.hasSwappedOutPss) { |
| 2664 | printRow(pw, TWO_COUNT_COLUMNS, |
| 2665 | "TOTAL:", memInfo.getSummaryTotalPss(), |
| 2666 | "TOTAL SWAP PSS:", memInfo.getSummaryTotalSwapPss()); |
| 2667 | } else { |
| 2668 | printRow(pw, TWO_COUNT_COLUMNS, |
| 2669 | "TOTAL:", memInfo.getSummaryTotalPss(), |
| 2670 | "TOTAL SWAP (KB):", memInfo.getSummaryTotalSwap()); |
| 2671 | } |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2672 | } |
| 2673 | |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2674 | /** |
| 2675 | * Dump heap info to proto. |
| 2676 | * |
| 2677 | * @param hasSwappedOutPss determines whether to use dirtySwap or dirtySwapPss |
| 2678 | */ |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 2679 | private static void dumpMemoryInfo(ProtoOutputStream proto, long fieldId, String name, |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2680 | int pss, int cleanPss, int sharedDirty, int privateDirty, |
| 2681 | int sharedClean, int privateClean, |
| 2682 | boolean hasSwappedOutPss, int dirtySwap, int dirtySwapPss) { |
| 2683 | final long token = proto.start(fieldId); |
| 2684 | |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 2685 | proto.write(MemInfoDumpProto.ProcessMemory.MemoryInfo.NAME, name); |
| 2686 | proto.write(MemInfoDumpProto.ProcessMemory.MemoryInfo.TOTAL_PSS_KB, pss); |
| 2687 | proto.write(MemInfoDumpProto.ProcessMemory.MemoryInfo.CLEAN_PSS_KB, cleanPss); |
| 2688 | proto.write(MemInfoDumpProto.ProcessMemory.MemoryInfo.SHARED_DIRTY_KB, sharedDirty); |
| 2689 | proto.write(MemInfoDumpProto.ProcessMemory.MemoryInfo.PRIVATE_DIRTY_KB, privateDirty); |
| 2690 | proto.write(MemInfoDumpProto.ProcessMemory.MemoryInfo.SHARED_CLEAN_KB, sharedClean); |
| 2691 | proto.write(MemInfoDumpProto.ProcessMemory.MemoryInfo.PRIVATE_CLEAN_KB, privateClean); |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2692 | if (hasSwappedOutPss) { |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 2693 | proto.write(MemInfoDumpProto.ProcessMemory.MemoryInfo.DIRTY_SWAP_PSS_KB, dirtySwapPss); |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2694 | } else { |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 2695 | proto.write(MemInfoDumpProto.ProcessMemory.MemoryInfo.DIRTY_SWAP_KB, dirtySwap); |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2696 | } |
| 2697 | |
| 2698 | proto.end(token); |
| 2699 | } |
| 2700 | |
| 2701 | /** |
| 2702 | * Dump mem info data to proto. |
| 2703 | */ |
| 2704 | public static void dumpMemInfoTable(ProtoOutputStream proto, Debug.MemoryInfo memInfo, |
| 2705 | boolean dumpDalvik, boolean dumpSummaryOnly, |
| 2706 | long nativeMax, long nativeAllocated, long nativeFree, |
| 2707 | long dalvikMax, long dalvikAllocated, long dalvikFree) { |
| 2708 | |
| 2709 | if (!dumpSummaryOnly) { |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 2710 | final long nhToken = proto.start(MemInfoDumpProto.ProcessMemory.NATIVE_HEAP); |
| 2711 | dumpMemoryInfo(proto, MemInfoDumpProto.ProcessMemory.HeapInfo.MEM_INFO, "Native Heap", |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2712 | memInfo.nativePss, memInfo.nativeSwappablePss, memInfo.nativeSharedDirty, |
| 2713 | memInfo.nativePrivateDirty, memInfo.nativeSharedClean, |
| 2714 | memInfo.nativePrivateClean, memInfo.hasSwappedOutPss, |
| 2715 | memInfo.nativeSwappedOut, memInfo.nativeSwappedOutPss); |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 2716 | proto.write(MemInfoDumpProto.ProcessMemory.HeapInfo.HEAP_SIZE_KB, nativeMax); |
| 2717 | proto.write(MemInfoDumpProto.ProcessMemory.HeapInfo.HEAP_ALLOC_KB, nativeAllocated); |
| 2718 | proto.write(MemInfoDumpProto.ProcessMemory.HeapInfo.HEAP_FREE_KB, nativeFree); |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2719 | proto.end(nhToken); |
| 2720 | |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 2721 | final long dvToken = proto.start(MemInfoDumpProto.ProcessMemory.DALVIK_HEAP); |
| 2722 | dumpMemoryInfo(proto, MemInfoDumpProto.ProcessMemory.HeapInfo.MEM_INFO, "Dalvik Heap", |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2723 | memInfo.dalvikPss, memInfo.dalvikSwappablePss, memInfo.dalvikSharedDirty, |
| 2724 | memInfo.dalvikPrivateDirty, memInfo.dalvikSharedClean, |
| 2725 | memInfo.dalvikPrivateClean, memInfo.hasSwappedOutPss, |
| 2726 | memInfo.dalvikSwappedOut, memInfo.dalvikSwappedOutPss); |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 2727 | proto.write(MemInfoDumpProto.ProcessMemory.HeapInfo.HEAP_SIZE_KB, dalvikMax); |
| 2728 | proto.write(MemInfoDumpProto.ProcessMemory.HeapInfo.HEAP_ALLOC_KB, dalvikAllocated); |
| 2729 | proto.write(MemInfoDumpProto.ProcessMemory.HeapInfo.HEAP_FREE_KB, dalvikFree); |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2730 | proto.end(dvToken); |
| 2731 | |
| 2732 | int otherPss = memInfo.otherPss; |
| 2733 | int otherSwappablePss = memInfo.otherSwappablePss; |
| 2734 | int otherSharedDirty = memInfo.otherSharedDirty; |
| 2735 | int otherPrivateDirty = memInfo.otherPrivateDirty; |
| 2736 | int otherSharedClean = memInfo.otherSharedClean; |
| 2737 | int otherPrivateClean = memInfo.otherPrivateClean; |
| 2738 | int otherSwappedOut = memInfo.otherSwappedOut; |
| 2739 | int otherSwappedOutPss = memInfo.otherSwappedOutPss; |
| 2740 | |
| 2741 | for (int i = 0; i < Debug.MemoryInfo.NUM_OTHER_STATS; i++) { |
| 2742 | final int myPss = memInfo.getOtherPss(i); |
| 2743 | final int mySwappablePss = memInfo.getOtherSwappablePss(i); |
| 2744 | final int mySharedDirty = memInfo.getOtherSharedDirty(i); |
| 2745 | final int myPrivateDirty = memInfo.getOtherPrivateDirty(i); |
| 2746 | final int mySharedClean = memInfo.getOtherSharedClean(i); |
| 2747 | final int myPrivateClean = memInfo.getOtherPrivateClean(i); |
| 2748 | final int mySwappedOut = memInfo.getOtherSwappedOut(i); |
| 2749 | final int mySwappedOutPss = memInfo.getOtherSwappedOutPss(i); |
| 2750 | if (myPss != 0 || mySharedDirty != 0 || myPrivateDirty != 0 |
| 2751 | || mySharedClean != 0 || myPrivateClean != 0 |
| 2752 | || (memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut) != 0) { |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 2753 | dumpMemoryInfo(proto, MemInfoDumpProto.ProcessMemory.OTHER_HEAPS, |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2754 | Debug.MemoryInfo.getOtherLabel(i), |
| 2755 | myPss, mySwappablePss, mySharedDirty, myPrivateDirty, |
| 2756 | mySharedClean, myPrivateClean, |
| 2757 | memInfo.hasSwappedOutPss, mySwappedOut, mySwappedOutPss); |
| 2758 | |
| 2759 | otherPss -= myPss; |
| 2760 | otherSwappablePss -= mySwappablePss; |
| 2761 | otherSharedDirty -= mySharedDirty; |
| 2762 | otherPrivateDirty -= myPrivateDirty; |
| 2763 | otherSharedClean -= mySharedClean; |
| 2764 | otherPrivateClean -= myPrivateClean; |
| 2765 | otherSwappedOut -= mySwappedOut; |
| 2766 | otherSwappedOutPss -= mySwappedOutPss; |
| 2767 | } |
| 2768 | } |
| 2769 | |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 2770 | dumpMemoryInfo(proto, MemInfoDumpProto.ProcessMemory.UNKNOWN_HEAP, "Unknown", |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2771 | otherPss, otherSwappablePss, |
| 2772 | otherSharedDirty, otherPrivateDirty, otherSharedClean, otherPrivateClean, |
| 2773 | memInfo.hasSwappedOutPss, otherSwappedOut, otherSwappedOutPss); |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 2774 | final long tToken = proto.start(MemInfoDumpProto.ProcessMemory.TOTAL_HEAP); |
| 2775 | dumpMemoryInfo(proto, MemInfoDumpProto.ProcessMemory.HeapInfo.MEM_INFO, "TOTAL", |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2776 | memInfo.getTotalPss(), memInfo.getTotalSwappablePss(), |
| 2777 | memInfo.getTotalSharedDirty(), memInfo.getTotalPrivateDirty(), |
| 2778 | memInfo.getTotalSharedClean(), memInfo.getTotalPrivateClean(), |
| 2779 | memInfo.hasSwappedOutPss, memInfo.getTotalSwappedOut(), |
| 2780 | memInfo.getTotalSwappedOutPss()); |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 2781 | proto.write(MemInfoDumpProto.ProcessMemory.HeapInfo.HEAP_SIZE_KB, |
| 2782 | nativeMax + dalvikMax); |
| 2783 | proto.write(MemInfoDumpProto.ProcessMemory.HeapInfo.HEAP_ALLOC_KB, |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2784 | nativeAllocated + dalvikAllocated); |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 2785 | proto.write(MemInfoDumpProto.ProcessMemory.HeapInfo.HEAP_FREE_KB, |
| 2786 | nativeFree + dalvikFree); |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2787 | proto.end(tToken); |
| 2788 | |
| 2789 | if (dumpDalvik) { |
| 2790 | for (int i = Debug.MemoryInfo.NUM_OTHER_STATS; |
| 2791 | i < Debug.MemoryInfo.NUM_OTHER_STATS + Debug.MemoryInfo.NUM_DVK_STATS; |
| 2792 | i++) { |
| 2793 | final int myPss = memInfo.getOtherPss(i); |
| 2794 | final int mySwappablePss = memInfo.getOtherSwappablePss(i); |
| 2795 | final int mySharedDirty = memInfo.getOtherSharedDirty(i); |
| 2796 | final int myPrivateDirty = memInfo.getOtherPrivateDirty(i); |
| 2797 | final int mySharedClean = memInfo.getOtherSharedClean(i); |
| 2798 | final int myPrivateClean = memInfo.getOtherPrivateClean(i); |
| 2799 | final int mySwappedOut = memInfo.getOtherSwappedOut(i); |
| 2800 | final int mySwappedOutPss = memInfo.getOtherSwappedOutPss(i); |
| 2801 | if (myPss != 0 || mySharedDirty != 0 || myPrivateDirty != 0 |
| 2802 | || mySharedClean != 0 || myPrivateClean != 0 |
| 2803 | || (memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut) != 0) { |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 2804 | dumpMemoryInfo(proto, MemInfoDumpProto.ProcessMemory.DALVIK_DETAILS, |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2805 | Debug.MemoryInfo.getOtherLabel(i), |
| 2806 | myPss, mySwappablePss, mySharedDirty, myPrivateDirty, |
| 2807 | mySharedClean, myPrivateClean, |
| 2808 | memInfo.hasSwappedOutPss, mySwappedOut, mySwappedOutPss); |
| 2809 | } |
| 2810 | } |
| 2811 | } |
| 2812 | } |
| 2813 | |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 2814 | final long asToken = proto.start(MemInfoDumpProto.ProcessMemory.APP_SUMMARY); |
| 2815 | proto.write(MemInfoDumpProto.ProcessMemory.AppSummary.JAVA_HEAP_PSS_KB, |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2816 | memInfo.getSummaryJavaHeap()); |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 2817 | proto.write(MemInfoDumpProto.ProcessMemory.AppSummary.NATIVE_HEAP_PSS_KB, |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2818 | memInfo.getSummaryNativeHeap()); |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 2819 | proto.write(MemInfoDumpProto.ProcessMemory.AppSummary.CODE_PSS_KB, |
| 2820 | memInfo.getSummaryCode()); |
| 2821 | proto.write(MemInfoDumpProto.ProcessMemory.AppSummary.STACK_PSS_KB, |
| 2822 | memInfo.getSummaryStack()); |
| 2823 | proto.write(MemInfoDumpProto.ProcessMemory.AppSummary.GRAPHICS_PSS_KB, |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2824 | memInfo.getSummaryGraphics()); |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 2825 | proto.write(MemInfoDumpProto.ProcessMemory.AppSummary.PRIVATE_OTHER_PSS_KB, |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2826 | memInfo.getSummaryPrivateOther()); |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 2827 | proto.write(MemInfoDumpProto.ProcessMemory.AppSummary.SYSTEM_PSS_KB, |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2828 | memInfo.getSummarySystem()); |
| 2829 | if (memInfo.hasSwappedOutPss) { |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 2830 | proto.write(MemInfoDumpProto.ProcessMemory.AppSummary.TOTAL_SWAP_PSS, |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2831 | memInfo.getSummaryTotalSwapPss()); |
| 2832 | } else { |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 2833 | proto.write(MemInfoDumpProto.ProcessMemory.AppSummary.TOTAL_SWAP_PSS, |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2834 | memInfo.getSummaryTotalSwap()); |
| 2835 | } |
| 2836 | proto.end(asToken); |
| 2837 | } |
| 2838 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 2839 | @UnsupportedAppUsage |
Jeff Hamilton | 52d3203 | 2011-01-08 15:31:26 -0600 | [diff] [blame] | 2840 | public void registerOnActivityPausedListener(Activity activity, |
| 2841 | OnActivityPausedListener listener) { |
| 2842 | synchronized (mOnPauseListeners) { |
| 2843 | ArrayList<OnActivityPausedListener> list = mOnPauseListeners.get(activity); |
| 2844 | if (list == null) { |
| 2845 | list = new ArrayList<OnActivityPausedListener>(); |
| 2846 | mOnPauseListeners.put(activity, list); |
| 2847 | } |
| 2848 | list.add(listener); |
| 2849 | } |
| 2850 | } |
| 2851 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 2852 | @UnsupportedAppUsage |
Jeff Hamilton | ce3224c | 2011-01-17 11:05:03 -0800 | [diff] [blame] | 2853 | public void unregisterOnActivityPausedListener(Activity activity, |
| 2854 | OnActivityPausedListener listener) { |
| 2855 | synchronized (mOnPauseListeners) { |
| 2856 | ArrayList<OnActivityPausedListener> list = mOnPauseListeners.get(activity); |
| 2857 | if (list != null) { |
| 2858 | list.remove(listener); |
| 2859 | } |
| 2860 | } |
| 2861 | } |
| 2862 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2863 | public final ActivityInfo resolveActivityInfo(Intent intent) { |
| 2864 | ActivityInfo aInfo = intent.resolveActivityInfo( |
| 2865 | mInitialApplication.getPackageManager(), PackageManager.GET_SHARED_LIBRARY_FILES); |
| 2866 | if (aInfo == null) { |
| 2867 | // Throw an exception. |
| 2868 | Instrumentation.checkStartActivityResult( |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 2869 | ActivityManager.START_CLASS_NOT_FOUND, intent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2870 | } |
| 2871 | return aInfo; |
| 2872 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2873 | |
Mathew Inwood | 8c854f8 | 2018-09-14 12:35:36 +0100 | [diff] [blame] | 2874 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2875 | public final Activity startActivityNow(Activity parent, String id, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2876 | Intent intent, ActivityInfo activityInfo, IBinder token, Bundle state, |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 2877 | Activity.NonConfigurationInstances lastNonConfigurationInstances) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2878 | ActivityClientRecord r = new ActivityClientRecord(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2879 | r.token = token; |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 2880 | r.ident = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2881 | r.intent = intent; |
| 2882 | r.state = state; |
| 2883 | r.parent = parent; |
| 2884 | r.embeddedID = id; |
| 2885 | r.activityInfo = activityInfo; |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 2886 | r.lastNonConfigurationInstances = lastNonConfigurationInstances; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2887 | if (localLOGV) { |
| 2888 | ComponentName compname = intent.getComponent(); |
| 2889 | String name; |
| 2890 | if (compname != null) { |
| 2891 | name = compname.toShortString(); |
| 2892 | } else { |
| 2893 | name = "(Intent " + intent + ").getComponent() returned null"; |
| 2894 | } |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2895 | Slog.v(TAG, "Performing launch: action=" + intent.getAction() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2896 | + ", comp=" + name |
| 2897 | + ", token=" + token); |
| 2898 | } |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 2899 | // TODO(lifecycler): Can't switch to use #handleLaunchActivity() because it will try to |
| 2900 | // call #reportSizeConfigurations(), but the server might not know anything about the |
| 2901 | // activity if it was launched from LocalAcvitivyManager. |
Andrii Kulian | 770c403 | 2018-05-02 18:40:59 -0700 | [diff] [blame] | 2902 | return performLaunchActivity(r, null /* customIntent */); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2903 | } |
| 2904 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 2905 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2906 | public final Activity getActivity(IBinder token) { |
Andrii Kulian | d56ed0c | 2018-06-14 12:22:18 -0700 | [diff] [blame] | 2907 | final ActivityClientRecord activityRecord = mActivities.get(token); |
| 2908 | return activityRecord != null ? activityRecord.activity : null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2909 | } |
| 2910 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 2911 | @Override |
| 2912 | public ActivityClientRecord getActivityClient(IBinder token) { |
| 2913 | return mActivities.get(token); |
| 2914 | } |
| 2915 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 2916 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2917 | public final void sendActivityResult( |
| 2918 | IBinder token, String id, int requestCode, |
| 2919 | int resultCode, Intent data) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2920 | if (DEBUG_RESULTS) Slog.v(TAG, "sendActivityResult: id=" + id |
Chris Tate | 8a7dc17 | 2009-03-24 20:11:42 -0700 | [diff] [blame] | 2921 | + " req=" + requestCode + " res=" + resultCode + " data=" + data); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2922 | ArrayList<ResultInfo> list = new ArrayList<ResultInfo>(); |
| 2923 | list.add(new ResultInfo(id, requestCode, resultCode, data)); |
Andrii Kulian | 9c5ea9c | 2017-12-07 09:31:01 -0800 | [diff] [blame] | 2924 | final ClientTransaction clientTransaction = ClientTransaction.obtain(mAppThread, token); |
| 2925 | clientTransaction.addCallback(ActivityResultItem.obtain(list)); |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 2926 | try { |
| 2927 | mAppThread.scheduleTransaction(clientTransaction); |
| 2928 | } catch (RemoteException e) { |
| 2929 | // Local scheduling |
| 2930 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2931 | } |
| 2932 | |
Andrii Kulian | 914aa7d | 2018-03-19 21:51:53 -0700 | [diff] [blame] | 2933 | @Override |
| 2934 | TransactionExecutor getTransactionExecutor() { |
| 2935 | return mTransactionExecutor; |
| 2936 | } |
| 2937 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 2938 | void sendMessage(int what, Object obj) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 2939 | sendMessage(what, obj, 0, 0, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2940 | } |
| 2941 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 2942 | private void sendMessage(int what, Object obj, int arg1) { |
| 2943 | sendMessage(what, obj, arg1, 0, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2944 | } |
| 2945 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 2946 | private void sendMessage(int what, Object obj, int arg1, int arg2) { |
| 2947 | sendMessage(what, obj, arg1, arg2, false); |
| 2948 | } |
| 2949 | |
| 2950 | private void sendMessage(int what, Object obj, int arg1, int arg2, boolean async) { |
| 2951 | if (DEBUG_MESSAGES) Slog.v( |
| 2952 | TAG, "SCHEDULE " + what + " " + mH.codeToString(what) |
| 2953 | + ": " + arg1 + " / " + obj); |
| 2954 | Message msg = Message.obtain(); |
| 2955 | msg.what = what; |
| 2956 | msg.obj = obj; |
| 2957 | msg.arg1 = arg1; |
| 2958 | msg.arg2 = arg2; |
| 2959 | if (async) { |
| 2960 | msg.setAsynchronous(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2961 | } |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 2962 | mH.sendMessage(msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2963 | } |
| 2964 | |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 2965 | private void sendMessage(int what, Object obj, int arg1, int arg2, int seq) { |
| 2966 | if (DEBUG_MESSAGES) Slog.v( |
| 2967 | TAG, "SCHEDULE " + mH.codeToString(what) + " arg1=" + arg1 + " arg2=" + arg2 + |
| 2968 | "seq= " + seq); |
| 2969 | Message msg = Message.obtain(); |
| 2970 | msg.what = what; |
| 2971 | SomeArgs args = SomeArgs.obtain(); |
| 2972 | args.arg1 = obj; |
| 2973 | args.argi1 = arg1; |
| 2974 | args.argi2 = arg2; |
| 2975 | args.argi3 = seq; |
| 2976 | msg.obj = args; |
| 2977 | mH.sendMessage(msg); |
| 2978 | } |
| 2979 | |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 2980 | final void scheduleContextCleanup(ContextImpl context, String who, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2981 | String what) { |
| 2982 | ContextCleanupInfo cci = new ContextCleanupInfo(); |
| 2983 | cci.context = context; |
| 2984 | cci.who = who; |
| 2985 | cci.what = what; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 2986 | sendMessage(H.CLEAN_UP_CONTEXT, cci); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2987 | } |
| 2988 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 2989 | /** Core implementation of activity launch. */ |
Andrii Kulian | 770c403 | 2018-05-02 18:40:59 -0700 | [diff] [blame] | 2990 | private Activity performLaunchActivity(ActivityClientRecord r, Intent customIntent) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2991 | ActivityInfo aInfo = r.activityInfo; |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2992 | if (r.packageInfo == null) { |
| 2993 | r.packageInfo = getPackageInfo(aInfo.applicationInfo, r.compatInfo, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2994 | Context.CONTEXT_INCLUDE_CODE); |
| 2995 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2996 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2997 | ComponentName component = r.intent.getComponent(); |
| 2998 | if (component == null) { |
| 2999 | component = r.intent.resolveActivity( |
| 3000 | mInitialApplication.getPackageManager()); |
| 3001 | r.intent.setComponent(component); |
| 3002 | } |
| 3003 | |
| 3004 | if (r.activityInfo.targetActivity != null) { |
| 3005 | component = new ComponentName(r.activityInfo.packageName, |
| 3006 | r.activityInfo.targetActivity); |
| 3007 | } |
| 3008 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 3009 | ContextImpl appContext = createBaseContextForActivity(r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3010 | Activity activity = null; |
| 3011 | try { |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 3012 | java.lang.ClassLoader cl = appContext.getClassLoader(); |
Dan Sandler | 07fe63e | 2017-08-15 16:41:11 -0400 | [diff] [blame] | 3013 | activity = mInstrumentation.newActivity( |
| 3014 | cl, component.getClassName(), r.intent); |
Brad Fitzpatrick | 5f8b5c1 | 2011-01-20 15:12:08 -0800 | [diff] [blame] | 3015 | StrictMode.incrementExpectedActivityCount(activity.getClass()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3016 | r.intent.setExtrasClassLoader(cl); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 3017 | r.intent.prepareToEnterProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3018 | if (r.state != null) { |
| 3019 | r.state.setClassLoader(cl); |
| 3020 | } |
| 3021 | } catch (Exception e) { |
| 3022 | if (!mInstrumentation.onException(activity, e)) { |
| 3023 | throw new RuntimeException( |
| 3024 | "Unable to instantiate activity " + component |
| 3025 | + ": " + e.toString(), e); |
| 3026 | } |
| 3027 | } |
| 3028 | |
| 3029 | try { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3030 | Application app = r.packageInfo.makeApplication(false, mInstrumentation); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3031 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3032 | if (localLOGV) Slog.v(TAG, "Performing launch of " + r); |
| 3033 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3034 | TAG, r + ": app=" + app |
| 3035 | + ", appName=" + app.getPackageName() |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3036 | + ", pkg=" + r.packageInfo.getPackageName() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3037 | + ", comp=" + r.intent.getComponent().toShortString() |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3038 | + ", dir=" + r.packageInfo.getAppDir()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3039 | |
| 3040 | if (activity != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3041 | CharSequence title = r.activityInfo.loadLabel(appContext.getPackageManager()); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 3042 | Configuration config = new Configuration(mCompatConfiguration); |
Andrii Kulian | d0ad938 | 2016-04-18 20:54:20 -0700 | [diff] [blame] | 3043 | if (r.overrideConfig != null) { |
| 3044 | config.updateFrom(r.overrideConfig); |
| 3045 | } |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3046 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Launching activity " |
Dianne Hackborn | dc6b635 | 2009-09-30 14:20:09 -0700 | [diff] [blame] | 3047 | + r.activityInfo.name + " with config " + config); |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 3048 | Window window = null; |
| 3049 | if (r.mPendingRemoveWindow != null && r.mPreserveWindow) { |
| 3050 | window = r.mPendingRemoveWindow; |
| 3051 | r.mPendingRemoveWindow = null; |
| 3052 | r.mPendingRemoveWindowManager = null; |
| 3053 | } |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 3054 | appContext.setOuterContext(activity); |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 3055 | activity.attach(appContext, this, getInstrumentation(), r.token, |
| 3056 | r.ident, app, r.intent, r.activityInfo, title, r.parent, |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 3057 | r.embeddedID, r.lastNonConfigurationInstances, config, |
Andrii Kulian | 51c1b67 | 2017-04-07 18:39:32 -0700 | [diff] [blame] | 3058 | r.referrer, r.voiceInteractor, window, r.configCallback); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3059 | |
Andrii Kulian | 770c403 | 2018-05-02 18:40:59 -0700 | [diff] [blame] | 3060 | if (customIntent != null) { |
| 3061 | activity.mIntent = customIntent; |
| 3062 | } |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 3063 | r.lastNonConfigurationInstances = null; |
Sudheer Shanka | 84a4895 | 2017-03-08 18:19:01 -0800 | [diff] [blame] | 3064 | checkAndBlockForNetworkAccess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3065 | activity.mStartedActivity = false; |
| 3066 | int theme = r.activityInfo.getThemeResource(); |
| 3067 | if (theme != 0) { |
| 3068 | activity.setTheme(theme); |
| 3069 | } |
| 3070 | |
| 3071 | activity.mCalled = false; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3072 | if (r.isPersistable()) { |
| 3073 | mInstrumentation.callActivityOnCreate(activity, r.state, r.persistentState); |
| 3074 | } else { |
| 3075 | mInstrumentation.callActivityOnCreate(activity, r.state); |
| 3076 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3077 | if (!activity.mCalled) { |
| 3078 | throw new SuperNotCalledException( |
| 3079 | "Activity " + r.intent.getComponent().toShortString() + |
| 3080 | " did not call through to super.onCreate()"); |
| 3081 | } |
| 3082 | r.activity = activity; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3083 | } |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 3084 | r.setState(ON_CREATE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3085 | |
Garfield Tan | 0443b37 | 2019-01-04 15:00:13 -0800 | [diff] [blame] | 3086 | // updatePendingActivityConfiguration() reads from mActivities to update |
| 3087 | // ActivityClientRecord which runs in a different thread. Protect modifications to |
| 3088 | // mActivities to avoid race. |
| 3089 | synchronized (mResourcesManager) { |
| 3090 | mActivities.put(r.token, r); |
| 3091 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3092 | |
| 3093 | } catch (SuperNotCalledException e) { |
| 3094 | throw e; |
| 3095 | |
| 3096 | } catch (Exception e) { |
| 3097 | if (!mInstrumentation.onException(activity, e)) { |
| 3098 | throw new RuntimeException( |
| 3099 | "Unable to start activity " + component |
| 3100 | + ": " + e.toString(), e); |
| 3101 | } |
| 3102 | } |
| 3103 | |
| 3104 | return activity; |
| 3105 | } |
| 3106 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 3107 | @Override |
| 3108 | public void handleStartActivity(ActivityClientRecord r, |
| 3109 | PendingTransactionActions pendingActions) { |
| 3110 | final Activity activity = r.activity; |
| 3111 | if (r.activity == null) { |
| 3112 | // TODO(lifecycler): What do we do in this case? |
| 3113 | return; |
| 3114 | } |
| 3115 | if (!r.stopped) { |
| 3116 | throw new IllegalStateException("Can't start activity that is not stopped."); |
| 3117 | } |
Andrii Kulian | c10482f | 2019-03-07 18:09:28 +0000 | [diff] [blame] | 3118 | if (r.activity.mFinished) { |
| 3119 | // TODO(lifecycler): How can this happen? |
| 3120 | return; |
| 3121 | } |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 3122 | |
| 3123 | // Start |
Andrii Kulian | d25680c | 2018-02-21 15:16:58 -0800 | [diff] [blame] | 3124 | activity.performStart("handleStartActivity"); |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 3125 | r.setState(ON_START); |
| 3126 | |
| 3127 | if (pendingActions == null) { |
| 3128 | // No more work to do. |
| 3129 | return; |
| 3130 | } |
| 3131 | |
| 3132 | // Restore instance state |
| 3133 | if (pendingActions.shouldRestoreInstanceState()) { |
| 3134 | if (r.isPersistable()) { |
| 3135 | if (r.state != null || r.persistentState != null) { |
| 3136 | mInstrumentation.callActivityOnRestoreInstanceState(activity, r.state, |
| 3137 | r.persistentState); |
| 3138 | } |
| 3139 | } else if (r.state != null) { |
| 3140 | mInstrumentation.callActivityOnRestoreInstanceState(activity, r.state); |
| 3141 | } |
| 3142 | } |
| 3143 | |
| 3144 | // Call postOnCreate() |
| 3145 | if (pendingActions.shouldCallOnPostCreate()) { |
| 3146 | activity.mCalled = false; |
| 3147 | if (r.isPersistable()) { |
| 3148 | mInstrumentation.callActivityOnPostCreate(activity, r.state, |
| 3149 | r.persistentState); |
| 3150 | } else { |
| 3151 | mInstrumentation.callActivityOnPostCreate(activity, r.state); |
| 3152 | } |
| 3153 | if (!activity.mCalled) { |
| 3154 | throw new SuperNotCalledException( |
| 3155 | "Activity " + r.intent.getComponent().toShortString() |
| 3156 | + " did not call through to super.onPostCreate()"); |
| 3157 | } |
| 3158 | } |
| 3159 | } |
| 3160 | |
Sudheer Shanka | 84a4895 | 2017-03-08 18:19:01 -0800 | [diff] [blame] | 3161 | /** |
| 3162 | * Checks if {@link #mNetworkBlockSeq} is {@link #INVALID_PROC_STATE_SEQ} and if so, returns |
| 3163 | * immediately. Otherwise, makes a blocking call to ActivityManagerService to wait for the |
| 3164 | * network rules to get updated. |
| 3165 | */ |
| 3166 | private void checkAndBlockForNetworkAccess() { |
| 3167 | synchronized (mNetworkPolicyLock) { |
| 3168 | if (mNetworkBlockSeq != INVALID_PROC_STATE_SEQ) { |
| 3169 | try { |
| 3170 | ActivityManager.getService().waitForNetworkStateUpdate(mNetworkBlockSeq); |
| 3171 | mNetworkBlockSeq = INVALID_PROC_STATE_SEQ; |
| 3172 | } catch (RemoteException ignored) {} |
| 3173 | } |
| 3174 | } |
| 3175 | } |
| 3176 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 3177 | private ContextImpl createBaseContextForActivity(ActivityClientRecord r) { |
| 3178 | final int displayId; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3179 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3180 | displayId = ActivityTaskManager.getService().getActivityDisplayId(r.token); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3181 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3182 | throw e.rethrowFromSystemServer(); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3183 | } |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 3184 | |
Wale Ogunwale | 7c72668 | 2015-02-06 17:34:28 -0800 | [diff] [blame] | 3185 | ContextImpl appContext = ContextImpl.createActivityContext( |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3186 | this, r.packageInfo, r.activityInfo, r.token, displayId, r.overrideConfig); |
Wale Ogunwale | 7c72668 | 2015-02-06 17:34:28 -0800 | [diff] [blame] | 3187 | |
| 3188 | final DisplayManagerGlobal dm = DisplayManagerGlobal.getInstance(); |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 3189 | // For debugging purposes, if the activity's package name contains the value of |
| 3190 | // the "debug.use-second-display" system property as a substring, then show |
| 3191 | // its content on a secondary display if there is one. |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 3192 | String pkgName = SystemProperties.get("debug.second-display.pkg"); |
| 3193 | if (pkgName != null && !pkgName.isEmpty() |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3194 | && r.packageInfo.mPackageName.contains(pkgName)) { |
Wale Ogunwale | 7c72668 | 2015-02-06 17:34:28 -0800 | [diff] [blame] | 3195 | for (int id : dm.getDisplayIds()) { |
| 3196 | if (id != Display.DEFAULT_DISPLAY) { |
Wale Ogunwale | 2669851 | 2015-06-05 16:55:33 -0700 | [diff] [blame] | 3197 | Display display = |
Bryce Lee | 609bf65 | 2017-02-09 16:50:13 -0800 | [diff] [blame] | 3198 | dm.getCompatibleDisplay(id, appContext.getResources()); |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 3199 | appContext = (ContextImpl) appContext.createDisplayContext(display); |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 3200 | break; |
| 3201 | } |
| 3202 | } |
| 3203 | } |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 3204 | return appContext; |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 3205 | } |
| 3206 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 3207 | /** |
| 3208 | * Extended implementation of activity launch. Used when server requests a launch or relaunch. |
| 3209 | */ |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 3210 | @Override |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 3211 | public Activity handleLaunchActivity(ActivityClientRecord r, |
Andrii Kulian | 770c403 | 2018-05-02 18:40:59 -0700 | [diff] [blame] | 3212 | PendingTransactionActions pendingActions, Intent customIntent) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3213 | // If we are getting ready to gc after going to the background, well |
| 3214 | // we are back active so skip it. |
| 3215 | unscheduleGcIdler(); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3216 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3217 | |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 3218 | if (r.profilerInfo != null) { |
| 3219 | mProfiler.setProfiler(r.profilerInfo); |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 3220 | mProfiler.startProfiling(); |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 3221 | } |
| 3222 | |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 3223 | // Make sure we are running with the most recent config. |
| 3224 | handleConfigurationChanged(null, null); |
| 3225 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3226 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3227 | TAG, "Handling launch of " + r); |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 3228 | |
Chet Haase | 0d1c27a | 2014-11-03 18:35:16 +0000 | [diff] [blame] | 3229 | // Initialize before creating the activity |
Stan Iliev | 898123b | 2019-02-14 14:57:44 -0500 | [diff] [blame] | 3230 | if (!ThreadedRenderer.sRendererDisabled |
| 3231 | && (r.activityInfo.flags & ActivityInfo.FLAG_HARDWARE_ACCELERATED) != 0) { |
| 3232 | HardwareRenderer.preload(); |
Jesse Hall | c37984f | 2017-05-23 16:55:08 -0700 | [diff] [blame] | 3233 | } |
Chet Haase | 0d1c27a | 2014-11-03 18:35:16 +0000 | [diff] [blame] | 3234 | WindowManagerGlobal.initialize(); |
| 3235 | |
Andrii Kulian | 770c403 | 2018-05-02 18:40:59 -0700 | [diff] [blame] | 3236 | final Activity a = performLaunchActivity(r, customIntent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3237 | |
| 3238 | if (a != null) { |
Dianne Hackborn | 871ecdc | 2009-12-11 15:24:33 -0800 | [diff] [blame] | 3239 | r.createdConfig = new Configuration(mConfiguration); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 3240 | reportSizeConfigurations(r); |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 3241 | if (!r.activity.mFinished && pendingActions != null) { |
| 3242 | pendingActions.setOldState(r.state); |
| 3243 | pendingActions.setRestoreInstanceState(true); |
| 3244 | pendingActions.setCallOnPostCreate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3245 | } |
| 3246 | } else { |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 3247 | // 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] | 3248 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3249 | ActivityTaskManager.getService() |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 3250 | .finishActivity(r.token, Activity.RESULT_CANCELED, null, |
| 3251 | Activity.DONT_FINISH_TASK_WITH_ACTIVITY); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3252 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3253 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3254 | } |
| 3255 | } |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 3256 | |
| 3257 | return a; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3258 | } |
| 3259 | |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 3260 | private void reportSizeConfigurations(ActivityClientRecord r) { |
Riddle Hsu | 66b74a8 | 2018-07-26 00:20:12 +0800 | [diff] [blame] | 3261 | if (mActivitiesToBeDestroyed.containsKey(r.token)) { |
| 3262 | // Size configurations of a destroyed activity is meaningless. |
| 3263 | return; |
| 3264 | } |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 3265 | Configuration[] configurations = r.activity.getResources().getSizeConfigurations(); |
| 3266 | if (configurations == null) { |
| 3267 | return; |
| 3268 | } |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 3269 | SparseIntArray horizontal = new SparseIntArray(); |
| 3270 | SparseIntArray vertical = new SparseIntArray(); |
| 3271 | SparseIntArray smallest = new SparseIntArray(); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 3272 | for (int i = configurations.length - 1; i >= 0; i--) { |
| 3273 | Configuration config = configurations[i]; |
| 3274 | if (config.screenHeightDp != Configuration.SCREEN_HEIGHT_DP_UNDEFINED) { |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 3275 | vertical.put(config.screenHeightDp, 0); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 3276 | } |
| 3277 | if (config.screenWidthDp != Configuration.SCREEN_WIDTH_DP_UNDEFINED) { |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 3278 | horizontal.put(config.screenWidthDp, 0); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 3279 | } |
| 3280 | if (config.smallestScreenWidthDp != Configuration.SMALLEST_SCREEN_WIDTH_DP_UNDEFINED) { |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 3281 | smallest.put(config.smallestScreenWidthDp, 0); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 3282 | } |
| 3283 | } |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 3284 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3285 | ActivityTaskManager.getService().reportSizeConfigurations(r.token, |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 3286 | horizontal.copyKeys(), vertical.copyKeys(), smallest.copyKeys()); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 3287 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3288 | throw ex.rethrowFromSystemServer(); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 3289 | } |
| 3290 | |
| 3291 | } |
| 3292 | |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 3293 | private void deliverNewIntents(ActivityClientRecord r, List<ReferrerIntent> intents) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3294 | final int N = intents.size(); |
| 3295 | for (int i=0; i<N; i++) { |
Dianne Hackborn | a01a0fa | 2014-12-02 10:33:14 -0800 | [diff] [blame] | 3296 | ReferrerIntent intent = intents.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3297 | intent.setExtrasClassLoader(r.activity.getClassLoader()); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 3298 | intent.prepareToEnterProcess(); |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 3299 | r.activity.mFragments.noteStateNotSaved(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3300 | mInstrumentation.callActivityOnNewIntent(r.activity, intent); |
| 3301 | } |
| 3302 | } |
| 3303 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 3304 | @UnsupportedAppUsage |
Wale Ogunwale | 826c706 | 2016-09-13 08:25:54 -0700 | [diff] [blame] | 3305 | void performNewIntents(IBinder token, List<ReferrerIntent> intents, boolean andPause) { |
| 3306 | final ActivityClientRecord r = mActivities.get(token); |
| 3307 | if (r == null) { |
| 3308 | return; |
| 3309 | } |
| 3310 | |
| 3311 | final boolean resumed = !r.paused; |
| 3312 | if (resumed) { |
| 3313 | r.activity.mTemporaryPause = true; |
Andrii Kulian | d70cdb9 | 2019-01-08 15:03:50 -0800 | [diff] [blame] | 3314 | performPauseActivityIfNeeded(r, "performNewIntents"); |
Wale Ogunwale | 826c706 | 2016-09-13 08:25:54 -0700 | [diff] [blame] | 3315 | } |
Sudheer Shanka | 43b5ea4 | 2017-06-21 11:24:53 -0700 | [diff] [blame] | 3316 | checkAndBlockForNetworkAccess(); |
Wale Ogunwale | 826c706 | 2016-09-13 08:25:54 -0700 | [diff] [blame] | 3317 | deliverNewIntents(r, intents); |
| 3318 | if (resumed) { |
Andrii Kulian | d70cdb9 | 2019-01-08 15:03:50 -0800 | [diff] [blame] | 3319 | performResumeActivity(token, false, "performNewIntents"); |
Wale Ogunwale | 826c706 | 2016-09-13 08:25:54 -0700 | [diff] [blame] | 3320 | r.activity.mTemporaryPause = false; |
Andrii Kulian | d70cdb9 | 2019-01-08 15:03:50 -0800 | [diff] [blame] | 3321 | } else if (andPause) { |
Wale Ogunwale | 826c706 | 2016-09-13 08:25:54 -0700 | [diff] [blame] | 3322 | // In this case the activity was in the paused state when we delivered the intent, |
| 3323 | // to guarantee onResume gets called after onNewIntent we temporarily resume the |
| 3324 | // activity and pause again as the caller wanted. |
| 3325 | performResumeActivity(token, false, "performNewIntents"); |
| 3326 | performPauseActivityIfNeeded(r, "performNewIntents"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3327 | } |
| 3328 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3329 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 3330 | @Override |
| 3331 | public void handleNewIntent(IBinder token, List<ReferrerIntent> intents, boolean andPause) { |
| 3332 | performNewIntents(token, intents, andPause); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3333 | } |
| 3334 | |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 3335 | public void handleRequestAssistContextExtras(RequestAssistContextExtras cmd) { |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 3336 | // Filling for autofill has a few differences: |
Felipe Leme | 1ca634a | 2016-11-28 17:21:21 -0800 | [diff] [blame] | 3337 | // - it does not need an AssistContent |
| 3338 | // - it does not call onProvideAssistData() |
| 3339 | // - it needs an IAutoFillCallback |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 3340 | boolean forAutofill = cmd.requestType == ActivityManager.ASSIST_CONTEXT_AUTOFILL; |
Felipe Leme | 1ca634a | 2016-11-28 17:21:21 -0800 | [diff] [blame] | 3341 | |
Felipe Leme | 85d1c2d | 2017-04-21 08:56:04 -0700 | [diff] [blame] | 3342 | // TODO: decide if lastSessionId logic applies to autofill sessions |
Amith Yamasani | 4f128e4 | 2016-05-10 11:44:12 -0700 | [diff] [blame] | 3343 | if (mLastSessionId != cmd.sessionId) { |
| 3344 | // Clear the existing structures |
| 3345 | mLastSessionId = cmd.sessionId; |
| 3346 | for (int i = mLastAssistStructures.size() - 1; i >= 0; i--) { |
| 3347 | AssistStructure structure = mLastAssistStructures.get(i).get(); |
| 3348 | if (structure != null) { |
| 3349 | structure.clearSendChannel(); |
| 3350 | } |
| 3351 | mLastAssistStructures.remove(i); |
Dianne Hackborn | 782d498 | 2015-07-08 17:36:37 -0700 | [diff] [blame] | 3352 | } |
| 3353 | } |
Felipe Leme | 29a5b0d | 2016-10-25 14:57:11 -0700 | [diff] [blame] | 3354 | |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 3355 | Bundle data = new Bundle(); |
Dianne Hackborn | 09d57fe | 2015-05-27 18:05:52 -0700 | [diff] [blame] | 3356 | AssistStructure structure = null; |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 3357 | AssistContent content = forAutofill ? null : new AssistContent(); |
Amith Yamasani | 858f98d | 2017-02-22 12:59:53 -0800 | [diff] [blame] | 3358 | final long startTime = SystemClock.uptimeMillis(); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 3359 | ActivityClientRecord r = mActivities.get(cmd.activityToken); |
Dianne Hackborn | a3acdb3 | 2015-06-08 17:07:40 -0700 | [diff] [blame] | 3360 | Uri referrer = null; |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 3361 | if (r != null) { |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 3362 | if (!forAutofill) { |
Felipe Leme | 1ca634a | 2016-11-28 17:21:21 -0800 | [diff] [blame] | 3363 | r.activity.getApplication().dispatchOnProvideAssistData(r.activity, data); |
Felipe Leme | 29a5b0d | 2016-10-25 14:57:11 -0700 | [diff] [blame] | 3364 | r.activity.onProvideAssistData(data); |
Felipe Leme | 6d55387 | 2016-12-08 17:13:25 -0800 | [diff] [blame] | 3365 | referrer = r.activity.onProvideReferrer(); |
Felipe Leme | 29a5b0d | 2016-10-25 14:57:11 -0700 | [diff] [blame] | 3366 | } |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 3367 | if (cmd.requestType == ActivityManager.ASSIST_CONTEXT_FULL || forAutofill) { |
Svet Ganov | fd31f85 | 2017-04-26 15:54:27 -0700 | [diff] [blame] | 3368 | structure = new AssistStructure(r.activity, forAutofill, cmd.flags); |
Adam Skory | 4aaed14 | 2015-04-22 11:29:31 -0600 | [diff] [blame] | 3369 | Intent activityIntent = r.activity.getIntent(); |
Felipe Leme | 6d55387 | 2016-12-08 17:13:25 -0800 | [diff] [blame] | 3370 | boolean notSecure = r.window == null || |
Dianne Hackborn | 09d57fe | 2015-05-27 18:05:52 -0700 | [diff] [blame] | 3371 | (r.window.getAttributes().flags |
Felipe Leme | 6d55387 | 2016-12-08 17:13:25 -0800 | [diff] [blame] | 3372 | & WindowManager.LayoutParams.FLAG_SECURE) == 0; |
| 3373 | if (activityIntent != null && notSecure) { |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 3374 | if (!forAutofill) { |
Felipe Leme | 1ca634a | 2016-11-28 17:21:21 -0800 | [diff] [blame] | 3375 | Intent intent = new Intent(activityIntent); |
| 3376 | intent.setFlags(intent.getFlags() & ~(Intent.FLAG_GRANT_WRITE_URI_PERMISSION |
| 3377 | | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION)); |
| 3378 | intent.removeUnsafeExtras(); |
Felipe Leme | 29a5b0d | 2016-10-25 14:57:11 -0700 | [diff] [blame] | 3379 | content.setDefaultIntent(intent); |
| 3380 | } |
Adam Skory | 4aaed14 | 2015-04-22 11:29:31 -0600 | [diff] [blame] | 3381 | } else { |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 3382 | if (!forAutofill) { |
Felipe Leme | 29a5b0d | 2016-10-25 14:57:11 -0700 | [diff] [blame] | 3383 | content.setDefaultIntent(new Intent()); |
| 3384 | } |
Adam Skory | 4aaed14 | 2015-04-22 11:29:31 -0600 | [diff] [blame] | 3385 | } |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 3386 | if (!forAutofill) { |
Felipe Leme | 29a5b0d | 2016-10-25 14:57:11 -0700 | [diff] [blame] | 3387 | r.activity.onProvideAssistContent(content); |
| 3388 | } |
Dianne Hackborn | a83ce1d | 2015-03-11 15:16:13 -0700 | [diff] [blame] | 3389 | } |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 3390 | } |
Dianne Hackborn | 09d57fe | 2015-05-27 18:05:52 -0700 | [diff] [blame] | 3391 | if (structure == null) { |
| 3392 | structure = new AssistStructure(); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 3393 | } |
Felipe Leme | 0200d9e | 2017-01-24 15:10:26 -0800 | [diff] [blame] | 3394 | |
Felipe Leme | 85d1c2d | 2017-04-21 08:56:04 -0700 | [diff] [blame] | 3395 | // TODO: decide if lastSessionId logic applies to autofill sessions |
Amith Yamasani | 858f98d | 2017-02-22 12:59:53 -0800 | [diff] [blame] | 3396 | |
| 3397 | structure.setAcquisitionStartTime(startTime); |
| 3398 | structure.setAcquisitionEndTime(SystemClock.uptimeMillis()); |
| 3399 | |
Amith Yamasani | 4f128e4 | 2016-05-10 11:44:12 -0700 | [diff] [blame] | 3400 | mLastAssistStructures.add(new WeakReference<>(structure)); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3401 | IActivityTaskManager mgr = ActivityTaskManager.getService(); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 3402 | try { |
Dianne Hackborn | a3acdb3 | 2015-06-08 17:07:40 -0700 | [diff] [blame] | 3403 | mgr.reportAssistContextExtras(cmd.requestToken, data, structure, content, referrer); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 3404 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3405 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 3406 | } |
| 3407 | } |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 3408 | |
| 3409 | public void handleTranslucentConversionComplete(IBinder token, boolean drawComplete) { |
| 3410 | ActivityClientRecord r = mActivities.get(token); |
| 3411 | if (r != null) { |
| 3412 | r.activity.onTranslucentConversionComplete(drawComplete); |
| 3413 | } |
| 3414 | } |
| 3415 | |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 3416 | public void onNewActivityOptions(IBinder token, ActivityOptions options) { |
| 3417 | ActivityClientRecord r = mActivities.get(token); |
| 3418 | if (r != null) { |
| 3419 | r.activity.onNewActivityOptions(options); |
| 3420 | } |
| 3421 | } |
| 3422 | |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 3423 | public void handleInstallProvider(ProviderInfo info) { |
Jeff Sharkey | bb2e2ca | 2014-10-23 11:42:31 -0700 | [diff] [blame] | 3424 | final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); |
| 3425 | try { |
Jeff Sharkey | a6bfeae | 2017-07-05 16:50:24 -0600 | [diff] [blame] | 3426 | installContentProviders(mInitialApplication, Arrays.asList(info)); |
Jeff Sharkey | bb2e2ca | 2014-10-23 11:42:31 -0700 | [diff] [blame] | 3427 | } finally { |
| 3428 | StrictMode.setThreadPolicy(oldPolicy); |
| 3429 | } |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 3430 | } |
| 3431 | |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 3432 | private void handleEnterAnimationComplete(IBinder token) { |
| 3433 | ActivityClientRecord r = mActivities.get(token); |
| 3434 | if (r != null) { |
Filip Gruszczynski | 6eafa90 | 2014-11-14 14:24:37 -0800 | [diff] [blame] | 3435 | r.activity.dispatchEnterAnimationComplete(); |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 3436 | } |
| 3437 | } |
| 3438 | |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 3439 | private void handleStartBinderTracking() { |
| 3440 | Binder.enableTracing(); |
| 3441 | } |
| 3442 | |
| 3443 | private void handleStopBinderTrackingAndDump(ParcelFileDescriptor fd) { |
| 3444 | try { |
| 3445 | Binder.disableTracing(); |
| 3446 | Binder.getTransactionTracker().writeTracesToFile(fd); |
| 3447 | } finally { |
| 3448 | IoUtils.closeQuietly(fd); |
| 3449 | Binder.getTransactionTracker().clearTraces(); |
| 3450 | } |
| 3451 | } |
| 3452 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 3453 | @Override |
| 3454 | public void handleMultiWindowModeChanged(IBinder token, boolean isInMultiWindowMode, |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 3455 | Configuration overrideConfig) { |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 3456 | final ActivityClientRecord r = mActivities.get(token); |
| 3457 | if (r != null) { |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 3458 | final Configuration newConfig = new Configuration(mConfiguration); |
| 3459 | if (overrideConfig != null) { |
| 3460 | newConfig.updateFrom(overrideConfig); |
| 3461 | } |
| 3462 | r.activity.dispatchMultiWindowModeChanged(isInMultiWindowMode, newConfig); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 3463 | } |
| 3464 | } |
| 3465 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 3466 | @Override |
| 3467 | public void handlePictureInPictureModeChanged(IBinder token, boolean isInPipMode, |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 3468 | Configuration overrideConfig) { |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 3469 | final ActivityClientRecord r = mActivities.get(token); |
| 3470 | if (r != null) { |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 3471 | final Configuration newConfig = new Configuration(mConfiguration); |
| 3472 | if (overrideConfig != null) { |
| 3473 | newConfig.updateFrom(overrideConfig); |
| 3474 | } |
| 3475 | r.activity.dispatchPictureInPictureModeChanged(isInPipMode, newConfig); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 3476 | } |
| 3477 | } |
| 3478 | |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 3479 | private void handleLocalVoiceInteractionStarted(IBinder token, IVoiceInteractor interactor) { |
| 3480 | final ActivityClientRecord r = mActivities.get(token); |
| 3481 | if (r != null) { |
| 3482 | r.voiceInteractor = interactor; |
| 3483 | r.activity.setVoiceInteractor(interactor); |
| 3484 | if (interactor == null) { |
| 3485 | r.activity.onLocalVoiceInteractionStopped(); |
| 3486 | } else { |
| 3487 | r.activity.onLocalVoiceInteractionStarted(); |
| 3488 | } |
| 3489 | } |
| 3490 | } |
| 3491 | |
Andreas Gampe | ab8a63b | 2018-01-05 13:55:15 -0800 | [diff] [blame] | 3492 | private static boolean attemptAttachAgent(String agent, ClassLoader classLoader) { |
Leonard Mosescu | f3409ce | 2016-10-06 17:32:05 -0700 | [diff] [blame] | 3493 | try { |
Andreas Gampe | ab8a63b | 2018-01-05 13:55:15 -0800 | [diff] [blame] | 3494 | VMDebug.attachAgent(agent, classLoader); |
| 3495 | return true; |
Leonard Mosescu | f3409ce | 2016-10-06 17:32:05 -0700 | [diff] [blame] | 3496 | } catch (IOException e) { |
Andreas Gampe | ab8a63b | 2018-01-05 13:55:15 -0800 | [diff] [blame] | 3497 | Slog.e(TAG, "Attaching agent with " + classLoader + " failed: " + agent); |
| 3498 | return false; |
| 3499 | } |
| 3500 | } |
| 3501 | |
| 3502 | static void handleAttachAgent(String agent, LoadedApk loadedApk) { |
| 3503 | ClassLoader classLoader = loadedApk != null ? loadedApk.getClassLoader() : null; |
| 3504 | if (attemptAttachAgent(agent, classLoader)) { |
| 3505 | return; |
| 3506 | } |
| 3507 | if (classLoader != null) { |
| 3508 | attemptAttachAgent(agent, null); |
Leonard Mosescu | f3409ce | 2016-10-06 17:32:05 -0700 | [diff] [blame] | 3509 | } |
| 3510 | } |
| 3511 | |
Brad Fitzpatrick | bfb1919 | 2010-10-29 15:25:44 -0700 | [diff] [blame] | 3512 | private static final ThreadLocal<Intent> sCurrentBroadcastIntent = new ThreadLocal<Intent>(); |
| 3513 | |
| 3514 | /** |
| 3515 | * Return the Intent that's currently being handled by a |
| 3516 | * BroadcastReceiver on this thread, or null if none. |
| 3517 | * @hide |
| 3518 | */ |
| 3519 | public static Intent getIntentBeingBroadcast() { |
| 3520 | return sCurrentBroadcastIntent.get(); |
| 3521 | } |
| 3522 | |
Mathew Inwood | 31755f9 | 2018-12-20 13:53:36 +0000 | [diff] [blame] | 3523 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3524 | private void handleReceiver(ReceiverData data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3525 | // If we are getting ready to gc after going to the background, well |
| 3526 | // we are back active so skip it. |
| 3527 | unscheduleGcIdler(); |
| 3528 | |
| 3529 | String component = data.intent.getComponent().getClassName(); |
| 3530 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3531 | LoadedApk packageInfo = getPackageInfoNoCheck( |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 3532 | data.info.applicationInfo, data.compatInfo); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3533 | |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3534 | IActivityManager mgr = ActivityManager.getService(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3535 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 3536 | Application app; |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3537 | BroadcastReceiver receiver; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 3538 | ContextImpl context; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3539 | try { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3540 | app = packageInfo.makeApplication(false, mInstrumentation); |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 3541 | context = (ContextImpl) app.getBaseContext(); |
| 3542 | if (data.info.splitName != null) { |
| 3543 | context = (ContextImpl) context.createContextForSplit(data.info.splitName); |
| 3544 | } |
| 3545 | java.lang.ClassLoader cl = context.getClassLoader(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3546 | data.intent.setExtrasClassLoader(cl); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 3547 | data.intent.prepareToEnterProcess(); |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 3548 | data.setExtrasClassLoader(cl); |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3549 | receiver = packageInfo.getAppFactory() |
Jason Monk | a80bfb5 | 2017-11-16 17:15:37 -0500 | [diff] [blame] | 3550 | .instantiateReceiver(cl, data.info.name, data.intent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3551 | } catch (Exception e) { |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 3552 | if (DEBUG_BROADCAST) Slog.i(TAG, |
| 3553 | "Finishing failed broadcast to " + data.intent.getComponent()); |
| 3554 | data.sendFinished(mgr); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3555 | throw new RuntimeException( |
| 3556 | "Unable to instantiate receiver " + component |
| 3557 | + ": " + e.toString(), e); |
| 3558 | } |
| 3559 | |
| 3560 | try { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3561 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3562 | TAG, "Performing receive of " + data.intent |
| 3563 | + ": app=" + app |
| 3564 | + ", appName=" + app.getPackageName() |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3565 | + ", pkg=" + packageInfo.getPackageName() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3566 | + ", comp=" + data.intent.getComponent().toShortString() |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3567 | + ", dir=" + packageInfo.getAppDir()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3568 | |
Brad Fitzpatrick | bfb1919 | 2010-10-29 15:25:44 -0700 | [diff] [blame] | 3569 | sCurrentBroadcastIntent.set(data.intent); |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 3570 | receiver.setPendingResult(data); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3571 | receiver.onReceive(context.getReceiverRestrictedContext(), |
| 3572 | data.intent); |
| 3573 | } catch (Exception e) { |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 3574 | if (DEBUG_BROADCAST) Slog.i(TAG, |
| 3575 | "Finishing failed broadcast to " + data.intent.getComponent()); |
| 3576 | data.sendFinished(mgr); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3577 | if (!mInstrumentation.onException(receiver, e)) { |
| 3578 | throw new RuntimeException( |
| 3579 | "Unable to start receiver " + component |
| 3580 | + ": " + e.toString(), e); |
| 3581 | } |
Brad Fitzpatrick | bfb1919 | 2010-10-29 15:25:44 -0700 | [diff] [blame] | 3582 | } finally { |
| 3583 | sCurrentBroadcastIntent.set(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3584 | } |
| 3585 | |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 3586 | if (receiver.getPendingResult() != null) { |
| 3587 | data.finish(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3588 | } |
| 3589 | } |
| 3590 | |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3591 | // Instantiate a BackupAgent and tell it that it's alive |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3592 | private void handleCreateBackupAgent(CreateBackupAgentData data) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3593 | if (DEBUG_BACKUP) Slog.v(TAG, "handleCreateBackupAgent: " + data); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3594 | |
Christopher Tate | 346acb1 | 2012-10-15 19:20:25 -0700 | [diff] [blame] | 3595 | // Sanity check the requested target package's uid against ours |
| 3596 | try { |
| 3597 | PackageInfo requestedPackage = getPackageManager().getPackageInfo( |
| 3598 | data.appInfo.packageName, 0, UserHandle.myUserId()); |
| 3599 | if (requestedPackage.applicationInfo.uid != Process.myUid()) { |
| 3600 | Slog.w(TAG, "Asked to instantiate non-matching package " |
| 3601 | + data.appInfo.packageName); |
| 3602 | return; |
| 3603 | } |
| 3604 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3605 | throw e.rethrowFromSystemServer(); |
Christopher Tate | 346acb1 | 2012-10-15 19:20:25 -0700 | [diff] [blame] | 3606 | } |
| 3607 | |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3608 | // no longer idle; we have backup work to do |
| 3609 | unscheduleGcIdler(); |
| 3610 | |
| 3611 | // instantiate the BackupAgent class named in the manifest |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3612 | LoadedApk packageInfo = getPackageInfoNoCheck(data.appInfo, data.compatInfo); |
| 3613 | String packageName = packageInfo.mPackageName; |
Christopher Tate | 346acb1 | 2012-10-15 19:20:25 -0700 | [diff] [blame] | 3614 | if (packageName == null) { |
| 3615 | Slog.d(TAG, "Asked to create backup agent for nonexistent package"); |
| 3616 | return; |
| 3617 | } |
| 3618 | |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3619 | String classname = data.appInfo.backupAgentName; |
Christopher Tate | 79ec80d | 2011-06-24 14:58:49 -0700 | [diff] [blame] | 3620 | // full backup operation but no app-supplied agent? use the default implementation |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 3621 | if (classname == null && (data.backupMode == ApplicationThreadConstants.BACKUP_MODE_FULL |
| 3622 | || data.backupMode == ApplicationThreadConstants.BACKUP_MODE_RESTORE_FULL)) { |
Christopher Tate | 4a627c7 | 2011-04-01 14:43:32 -0700 | [diff] [blame] | 3623 | classname = "android.app.backup.FullBackupAgent"; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3624 | } |
Christopher Tate | 4a627c7 | 2011-04-01 14:43:32 -0700 | [diff] [blame] | 3625 | |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3626 | try { |
Christopher Tate | d1475e0 | 2009-07-09 15:36:17 -0700 | [diff] [blame] | 3627 | IBinder binder = null; |
Annie Meng | d582787 | 2019-01-30 20:28:57 +0000 | [diff] [blame] | 3628 | ArrayMap<String, BackupAgent> backupAgents = getBackupAgentsForUser(data.userId); |
| 3629 | BackupAgent agent = backupAgents.get(packageName); |
Christopher Tate | 2e40d11 | 2014-07-15 12:37:38 -0700 | [diff] [blame] | 3630 | if (agent != null) { |
| 3631 | // reusing the existing instance |
| 3632 | if (DEBUG_BACKUP) { |
| 3633 | Slog.v(TAG, "Reusing existing agent instance"); |
Christopher Tate | d1475e0 | 2009-07-09 15:36:17 -0700 | [diff] [blame] | 3634 | } |
Christopher Tate | 2e40d11 | 2014-07-15 12:37:38 -0700 | [diff] [blame] | 3635 | binder = agent.onBind(); |
| 3636 | } else { |
| 3637 | try { |
| 3638 | if (DEBUG_BACKUP) Slog.v(TAG, "Initializing agent class " + classname); |
| 3639 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3640 | java.lang.ClassLoader cl = packageInfo.getClassLoader(); |
Dan Sandler | 07fe63e | 2017-08-15 16:41:11 -0400 | [diff] [blame] | 3641 | agent = (BackupAgent) cl.loadClass(classname).newInstance(); |
Christopher Tate | 2e40d11 | 2014-07-15 12:37:38 -0700 | [diff] [blame] | 3642 | |
| 3643 | // set up the agent's context |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3644 | ContextImpl context = ContextImpl.createAppContext(this, packageInfo); |
Christopher Tate | 2e40d11 | 2014-07-15 12:37:38 -0700 | [diff] [blame] | 3645 | context.setOuterContext(agent); |
| 3646 | agent.attach(context); |
| 3647 | |
Ruslan Tkhakokhov | 063180f | 2019-01-28 20:29:46 +0000 | [diff] [blame] | 3648 | agent.onCreate(UserHandle.of(data.userId)); |
Christopher Tate | 2e40d11 | 2014-07-15 12:37:38 -0700 | [diff] [blame] | 3649 | binder = agent.onBind(); |
Annie Meng | d582787 | 2019-01-30 20:28:57 +0000 | [diff] [blame] | 3650 | backupAgents.put(packageName, agent); |
Christopher Tate | 2e40d11 | 2014-07-15 12:37:38 -0700 | [diff] [blame] | 3651 | } catch (Exception e) { |
| 3652 | // If this is during restore, fail silently; otherwise go |
| 3653 | // ahead and let the user see the crash. |
| 3654 | Slog.e(TAG, "Agent threw during creation: " + e); |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 3655 | if (data.backupMode != ApplicationThreadConstants.BACKUP_MODE_RESTORE |
| 3656 | && data.backupMode != |
| 3657 | ApplicationThreadConstants.BACKUP_MODE_RESTORE_FULL) { |
Christopher Tate | 2e40d11 | 2014-07-15 12:37:38 -0700 | [diff] [blame] | 3658 | throw e; |
| 3659 | } |
| 3660 | // falling through with 'binder' still null |
| 3661 | } |
Christopher Tate | d1475e0 | 2009-07-09 15:36:17 -0700 | [diff] [blame] | 3662 | } |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3663 | |
| 3664 | // tell the OS that we're live now |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3665 | try { |
Annie Meng | d582787 | 2019-01-30 20:28:57 +0000 | [diff] [blame] | 3666 | ActivityManager.getService().backupAgentCreated(packageName, binder, data.userId); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3667 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3668 | throw e.rethrowFromSystemServer(); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3669 | } |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3670 | } catch (Exception e) { |
| 3671 | throw new RuntimeException("Unable to create BackupAgent " |
Christopher Tate | 4a627c7 | 2011-04-01 14:43:32 -0700 | [diff] [blame] | 3672 | + classname + ": " + e.toString(), e); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3673 | } |
| 3674 | } |
| 3675 | |
| 3676 | // Tear down a BackupAgent |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3677 | private void handleDestroyBackupAgent(CreateBackupAgentData data) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3678 | if (DEBUG_BACKUP) Slog.v(TAG, "handleDestroyBackupAgent: " + data); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3679 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3680 | LoadedApk packageInfo = getPackageInfoNoCheck(data.appInfo, data.compatInfo); |
| 3681 | String packageName = packageInfo.mPackageName; |
Annie Meng | d582787 | 2019-01-30 20:28:57 +0000 | [diff] [blame] | 3682 | ArrayMap<String, BackupAgent> backupAgents = getBackupAgentsForUser(data.userId); |
| 3683 | BackupAgent agent = backupAgents.get(packageName); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3684 | if (agent != null) { |
| 3685 | try { |
| 3686 | agent.onDestroy(); |
| 3687 | } catch (Exception e) { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 3688 | 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] | 3689 | e.printStackTrace(); |
| 3690 | } |
Annie Meng | d582787 | 2019-01-30 20:28:57 +0000 | [diff] [blame] | 3691 | backupAgents.remove(packageName); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3692 | } else { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 3693 | Slog.w(TAG, "Attempt to destroy unknown backup agent " + data); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3694 | } |
| 3695 | } |
| 3696 | |
Annie Meng | d582787 | 2019-01-30 20:28:57 +0000 | [diff] [blame] | 3697 | private ArrayMap<String, BackupAgent> getBackupAgentsForUser(int userId) { |
| 3698 | ArrayMap<String, BackupAgent> backupAgents = mBackupAgentsByUser.get(userId); |
| 3699 | if (backupAgents == null) { |
| 3700 | backupAgents = new ArrayMap<>(); |
| 3701 | mBackupAgentsByUser.put(userId, backupAgents); |
| 3702 | } |
| 3703 | return backupAgents; |
| 3704 | } |
| 3705 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 3706 | @UnsupportedAppUsage |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3707 | private void handleCreateService(CreateServiceData data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3708 | // If we are getting ready to gc after going to the background, well |
| 3709 | // we are back active so skip it. |
| 3710 | unscheduleGcIdler(); |
| 3711 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3712 | LoadedApk packageInfo = getPackageInfoNoCheck( |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 3713 | data.info.applicationInfo, data.compatInfo); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3714 | Service service = null; |
| 3715 | try { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3716 | java.lang.ClassLoader cl = packageInfo.getClassLoader(); |
| 3717 | service = packageInfo.getAppFactory() |
Jason Monk | a80bfb5 | 2017-11-16 17:15:37 -0500 | [diff] [blame] | 3718 | .instantiateService(cl, data.info.name, data.intent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3719 | } catch (Exception e) { |
| 3720 | if (!mInstrumentation.onException(service, e)) { |
| 3721 | throw new RuntimeException( |
| 3722 | "Unable to instantiate service " + data.info.name |
| 3723 | + ": " + e.toString(), e); |
| 3724 | } |
| 3725 | } |
| 3726 | |
| 3727 | try { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3728 | 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] | 3729 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3730 | ContextImpl context = ContextImpl.createAppContext(this, packageInfo); |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 3731 | context.setOuterContext(service); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3732 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3733 | Application app = packageInfo.makeApplication(false, mInstrumentation); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3734 | service.attach(context, this, data.info.name, data.token, app, |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3735 | ActivityManager.getService()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3736 | service.onCreate(); |
| 3737 | mServices.put(data.token, service); |
| 3738 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3739 | ActivityManager.getService().serviceDoneExecuting( |
Dianne Hackborn | 455625e | 2015-01-21 09:55:13 -0800 | [diff] [blame] | 3740 | data.token, SERVICE_DONE_EXECUTING_ANON, 0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3741 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3742 | throw e.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3743 | } |
| 3744 | } catch (Exception e) { |
| 3745 | if (!mInstrumentation.onException(service, e)) { |
| 3746 | throw new RuntimeException( |
| 3747 | "Unable to create service " + data.info.name |
| 3748 | + ": " + e.toString(), e); |
| 3749 | } |
| 3750 | } |
| 3751 | } |
| 3752 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3753 | private void handleBindService(BindServiceData data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3754 | Service s = mServices.get(data.token); |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 3755 | if (DEBUG_SERVICE) |
| 3756 | Slog.v(TAG, "handleBindService s=" + s + " rebind=" + data.rebind); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3757 | if (s != null) { |
| 3758 | try { |
| 3759 | data.intent.setExtrasClassLoader(s.getClassLoader()); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 3760 | data.intent.prepareToEnterProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3761 | try { |
| 3762 | if (!data.rebind) { |
| 3763 | IBinder binder = s.onBind(data.intent); |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3764 | ActivityManager.getService().publishService( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3765 | data.token, data.intent, binder); |
| 3766 | } else { |
| 3767 | s.onRebind(data.intent); |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3768 | ActivityManager.getService().serviceDoneExecuting( |
Dianne Hackborn | 455625e | 2015-01-21 09:55:13 -0800 | [diff] [blame] | 3769 | data.token, SERVICE_DONE_EXECUTING_ANON, 0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3770 | } |
| 3771 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3772 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3773 | } |
| 3774 | } catch (Exception e) { |
| 3775 | if (!mInstrumentation.onException(s, e)) { |
| 3776 | throw new RuntimeException( |
| 3777 | "Unable to bind to service " + s |
| 3778 | + " with " + data.intent + ": " + e.toString(), e); |
| 3779 | } |
| 3780 | } |
| 3781 | } |
| 3782 | } |
| 3783 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3784 | private void handleUnbindService(BindServiceData data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3785 | Service s = mServices.get(data.token); |
| 3786 | if (s != null) { |
| 3787 | try { |
| 3788 | data.intent.setExtrasClassLoader(s.getClassLoader()); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 3789 | data.intent.prepareToEnterProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3790 | boolean doRebind = s.onUnbind(data.intent); |
| 3791 | try { |
| 3792 | if (doRebind) { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3793 | ActivityManager.getService().unbindFinished( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3794 | data.token, data.intent, doRebind); |
| 3795 | } else { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3796 | ActivityManager.getService().serviceDoneExecuting( |
Dianne Hackborn | 455625e | 2015-01-21 09:55:13 -0800 | [diff] [blame] | 3797 | data.token, SERVICE_DONE_EXECUTING_ANON, 0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3798 | } |
| 3799 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3800 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3801 | } |
| 3802 | } catch (Exception e) { |
| 3803 | if (!mInstrumentation.onException(s, e)) { |
| 3804 | throw new RuntimeException( |
| 3805 | "Unable to unbind to service " + s |
| 3806 | + " with " + data.intent + ": " + e.toString(), e); |
| 3807 | } |
| 3808 | } |
| 3809 | } |
| 3810 | } |
| 3811 | |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 3812 | private void handleDumpService(DumpComponentInfo info) { |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3813 | final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); |
| 3814 | try { |
| 3815 | Service s = mServices.get(info.token); |
| 3816 | if (s != null) { |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 3817 | PrintWriter pw = new FastPrintWriter(new FileOutputStream( |
| 3818 | info.fd.getFileDescriptor())); |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3819 | s.dump(info.fd.getFileDescriptor(), pw, info.args); |
| 3820 | pw.flush(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3821 | } |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3822 | } finally { |
| 3823 | IoUtils.closeQuietly(info.fd); |
| 3824 | StrictMode.setThreadPolicy(oldPolicy); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3825 | } |
| 3826 | } |
| 3827 | |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 3828 | private void handleDumpActivity(DumpComponentInfo info) { |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3829 | final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); |
| 3830 | try { |
| 3831 | ActivityClientRecord r = mActivities.get(info.token); |
| 3832 | if (r != null && r.activity != null) { |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 3833 | PrintWriter pw = new FastPrintWriter(new FileOutputStream( |
| 3834 | info.fd.getFileDescriptor())); |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3835 | r.activity.dump(info.prefix, info.fd.getFileDescriptor(), pw, info.args); |
| 3836 | pw.flush(); |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 3837 | } |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3838 | } finally { |
| 3839 | IoUtils.closeQuietly(info.fd); |
| 3840 | StrictMode.setThreadPolicy(oldPolicy); |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 3841 | } |
| 3842 | } |
| 3843 | |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 3844 | private void handleDumpProvider(DumpComponentInfo info) { |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3845 | final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); |
| 3846 | try { |
| 3847 | ProviderClientRecord r = mLocalProviders.get(info.token); |
| 3848 | if (r != null && r.mLocalProvider != null) { |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 3849 | PrintWriter pw = new FastPrintWriter(new FileOutputStream( |
| 3850 | info.fd.getFileDescriptor())); |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3851 | r.mLocalProvider.dump(info.fd.getFileDescriptor(), pw, info.args); |
| 3852 | pw.flush(); |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 3853 | } |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3854 | } finally { |
| 3855 | IoUtils.closeQuietly(info.fd); |
| 3856 | StrictMode.setThreadPolicy(oldPolicy); |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 3857 | } |
| 3858 | } |
| 3859 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3860 | private void handleServiceArgs(ServiceArgsData data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3861 | Service s = mServices.get(data.token); |
| 3862 | if (s != null) { |
| 3863 | try { |
| 3864 | if (data.args != null) { |
| 3865 | data.args.setExtrasClassLoader(s.getClassLoader()); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 3866 | data.args.prepareToEnterProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3867 | } |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 3868 | int res; |
| 3869 | if (!data.taskRemoved) { |
| 3870 | res = s.onStartCommand(data.args, data.flags, data.startId); |
| 3871 | } else { |
| 3872 | s.onTaskRemoved(data.args); |
| 3873 | res = Service.START_TASK_REMOVED_COMPLETE; |
| 3874 | } |
Brad Fitzpatrick | 333b8cb | 2010-08-26 12:04:57 -0700 | [diff] [blame] | 3875 | |
| 3876 | QueuedWork.waitToFinish(); |
| 3877 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3878 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3879 | ActivityManager.getService().serviceDoneExecuting( |
Dianne Hackborn | 455625e | 2015-01-21 09:55:13 -0800 | [diff] [blame] | 3880 | data.token, SERVICE_DONE_EXECUTING_START, data.startId, res); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3881 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3882 | throw e.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3883 | } |
| 3884 | } catch (Exception e) { |
| 3885 | if (!mInstrumentation.onException(s, e)) { |
| 3886 | throw new RuntimeException( |
| 3887 | "Unable to start service " + s |
| 3888 | + " with " + data.args + ": " + e.toString(), e); |
| 3889 | } |
| 3890 | } |
| 3891 | } |
| 3892 | } |
| 3893 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3894 | private void handleStopService(IBinder token) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3895 | Service s = mServices.remove(token); |
| 3896 | if (s != null) { |
| 3897 | try { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3898 | if (localLOGV) Slog.v(TAG, "Destroying service " + s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3899 | s.onDestroy(); |
Amith Yamasani | 7592825 | 2017-05-22 15:10:47 -0700 | [diff] [blame] | 3900 | s.detachAndCleanUp(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3901 | Context context = s.getBaseContext(); |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 3902 | if (context instanceof ContextImpl) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3903 | final String who = s.getClassName(); |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 3904 | ((ContextImpl) context).scheduleFinalCleanup(who, "Service"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3905 | } |
Brad Fitzpatrick | 333b8cb | 2010-08-26 12:04:57 -0700 | [diff] [blame] | 3906 | |
| 3907 | QueuedWork.waitToFinish(); |
| 3908 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3909 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3910 | ActivityManager.getService().serviceDoneExecuting( |
Dianne Hackborn | 455625e | 2015-01-21 09:55:13 -0800 | [diff] [blame] | 3911 | token, SERVICE_DONE_EXECUTING_STOP, 0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3912 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3913 | throw e.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3914 | } |
| 3915 | } catch (Exception e) { |
| 3916 | if (!mInstrumentation.onException(s, e)) { |
| 3917 | throw new RuntimeException( |
| 3918 | "Unable to stop service " + s |
| 3919 | + ": " + e.toString(), e); |
| 3920 | } |
Craig Mautner | 66c4a82 | 2015-01-16 12:48:16 -0800 | [diff] [blame] | 3921 | Slog.i(TAG, "handleStopService: exception for " + token, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3922 | } |
Craig Mautner | 9776ad4 | 2015-01-15 14:38:39 -0800 | [diff] [blame] | 3923 | } else { |
| 3924 | Slog.i(TAG, "handleStopService: token=" + token + " not found."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3925 | } |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3926 | //Slog.i(TAG, "Running services: " + mServices); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3927 | } |
| 3928 | |
Andrii Kulian | d9e2acb | 2018-03-29 16:07:11 -0700 | [diff] [blame] | 3929 | /** |
| 3930 | * Resume the activity. |
| 3931 | * @param token Target activity token. |
| 3932 | * @param finalStateRequest Flag indicating if this is part of final state resolution for a |
| 3933 | * transaction. |
| 3934 | * @param reason Reason for performing the action. |
| 3935 | * |
| 3936 | * @return The {@link ActivityClientRecord} that was resumed, {@code null} otherwise. |
| 3937 | */ |
| 3938 | @VisibleForTesting |
| 3939 | public ActivityClientRecord performResumeActivity(IBinder token, boolean finalStateRequest, |
Andrii Kulian | dfbf971 | 2018-03-08 15:42:24 -0800 | [diff] [blame] | 3940 | String reason) { |
Andrii Kulian | d9e2acb | 2018-03-29 16:07:11 -0700 | [diff] [blame] | 3941 | final ActivityClientRecord r = mActivities.get(token); |
| 3942 | if (localLOGV) { |
| 3943 | Slog.v(TAG, "Performing resume of " + r + " finished=" + r.activity.mFinished); |
| 3944 | } |
Andrii Kulian | c10482f | 2019-03-07 18:09:28 +0000 | [diff] [blame] | 3945 | if (r == null || r.activity.mFinished) { |
Andrii Kulian | d9e2acb | 2018-03-29 16:07:11 -0700 | [diff] [blame] | 3946 | return null; |
| 3947 | } |
| 3948 | if (r.getLifecycleState() == ON_RESUME) { |
| 3949 | if (!finalStateRequest) { |
| 3950 | final RuntimeException e = new IllegalStateException( |
| 3951 | "Trying to resume activity which is already resumed"); |
| 3952 | Slog.e(TAG, e.getMessage(), e); |
| 3953 | Slog.e(TAG, r.getStateString()); |
| 3954 | // TODO(lifecycler): A double resume request is possible when an activity |
| 3955 | // receives two consequent transactions with relaunch requests and "resumed" |
| 3956 | // final state requests and the second relaunch is omitted. We still try to |
| 3957 | // handle two resume requests for the final state. For cases other than this |
| 3958 | // one, we don't expect it to happen. |
Andrii Kulian | 9956d89 | 2018-02-14 13:48:56 -0800 | [diff] [blame] | 3959 | } |
Andrii Kulian | d9e2acb | 2018-03-29 16:07:11 -0700 | [diff] [blame] | 3960 | return null; |
| 3961 | } |
| 3962 | if (finalStateRequest) { |
| 3963 | r.hideForNow = false; |
| 3964 | r.activity.mStartedActivity = false; |
| 3965 | } |
| 3966 | try { |
| 3967 | r.activity.onStateNotSaved(); |
| 3968 | r.activity.mFragments.noteStateNotSaved(); |
| 3969 | checkAndBlockForNetworkAccess(); |
| 3970 | if (r.pendingIntents != null) { |
| 3971 | deliverNewIntents(r, r.pendingIntents); |
| 3972 | r.pendingIntents = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3973 | } |
Andrii Kulian | d9e2acb | 2018-03-29 16:07:11 -0700 | [diff] [blame] | 3974 | if (r.pendingResults != null) { |
Andrii Kulian | e55b009 | 2018-04-19 15:29:22 -0700 | [diff] [blame] | 3975 | deliverResults(r, r.pendingResults, reason); |
Andrii Kulian | d9e2acb | 2018-03-29 16:07:11 -0700 | [diff] [blame] | 3976 | r.pendingResults = null; |
| 3977 | } |
| 3978 | r.activity.performResume(r.startsNotResumed, reason); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3979 | |
Andrii Kulian | d9e2acb | 2018-03-29 16:07:11 -0700 | [diff] [blame] | 3980 | r.state = null; |
| 3981 | r.persistentState = null; |
| 3982 | r.setState(ON_RESUME); |
Andrii Kulian | d70cdb9 | 2019-01-08 15:03:50 -0800 | [diff] [blame] | 3983 | |
| 3984 | reportTopResumedActivityChanged(r, r.isTopResumedActivity); |
Andrii Kulian | d9e2acb | 2018-03-29 16:07:11 -0700 | [diff] [blame] | 3985 | } catch (Exception e) { |
| 3986 | if (!mInstrumentation.onException(r.activity, e)) { |
| 3987 | throw new RuntimeException("Unable to resume activity " |
| 3988 | + r.intent.getComponent().toShortString() + ": " + e.toString(), e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3989 | } |
| 3990 | } |
| 3991 | return r; |
| 3992 | } |
| 3993 | |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 3994 | static final void cleanUpPendingRemoveWindows(ActivityClientRecord r, boolean force) { |
| 3995 | if (r.mPreserveWindow && !force) { |
| 3996 | return; |
| 3997 | } |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 3998 | if (r.mPendingRemoveWindow != null) { |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 3999 | r.mPendingRemoveWindowManager.removeViewImmediate( |
| 4000 | r.mPendingRemoveWindow.getDecorView()); |
| 4001 | IBinder wtoken = r.mPendingRemoveWindow.getDecorView().getWindowToken(); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4002 | if (wtoken != null) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 4003 | WindowManagerGlobal.getInstance().closeAll(wtoken, |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4004 | r.activity.getClass().getName(), "Activity"); |
| 4005 | } |
| 4006 | } |
| 4007 | r.mPendingRemoveWindow = null; |
| 4008 | r.mPendingRemoveWindowManager = null; |
| 4009 | } |
| 4010 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 4011 | @Override |
Andrii Kulian | dfbf971 | 2018-03-08 15:42:24 -0800 | [diff] [blame] | 4012 | public void handleResumeActivity(IBinder token, boolean finalStateRequest, boolean isForward, |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4013 | String reason) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4014 | // If we are getting ready to gc after going to the background, well |
| 4015 | // we are back active so skip it. |
| 4016 | unscheduleGcIdler(); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4017 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4018 | |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 4019 | // TODO Push resumeArgs into the activity for consideration |
Andrii Kulian | dfbf971 | 2018-03-08 15:42:24 -0800 | [diff] [blame] | 4020 | final ActivityClientRecord r = performResumeActivity(token, finalStateRequest, reason); |
Andrii Kulian | d9e2acb | 2018-03-29 16:07:11 -0700 | [diff] [blame] | 4021 | if (r == null) { |
| 4022 | // We didn't actually resume the activity, so skipping any follow-up actions. |
| 4023 | return; |
| 4024 | } |
Riddle Hsu | 66b74a8 | 2018-07-26 00:20:12 +0800 | [diff] [blame] | 4025 | if (mActivitiesToBeDestroyed.containsKey(token)) { |
| 4026 | // Although the activity is resumed, it is going to be destroyed. So the following |
| 4027 | // UI operations are unnecessary and also prevents exception because its token may |
| 4028 | // be gone that window manager cannot recognize it. All necessary cleanup actions |
| 4029 | // performed below will be done while handling destruction. |
| 4030 | return; |
| 4031 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4032 | |
Andrii Kulian | d9e2acb | 2018-03-29 16:07:11 -0700 | [diff] [blame] | 4033 | final Activity a = r.activity; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4034 | |
Andrii Kulian | d9e2acb | 2018-03-29 16:07:11 -0700 | [diff] [blame] | 4035 | if (localLOGV) { |
| 4036 | Slog.v(TAG, "Resume " + r + " started activity: " + a.mStartedActivity |
| 4037 | + ", hideForNow: " + r.hideForNow + ", finished: " + a.mFinished); |
| 4038 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4039 | |
Andrii Kulian | d9e2acb | 2018-03-29 16:07:11 -0700 | [diff] [blame] | 4040 | final int forwardBit = isForward |
| 4041 | ? WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION : 0; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4042 | |
Andrii Kulian | d9e2acb | 2018-03-29 16:07:11 -0700 | [diff] [blame] | 4043 | // If the window hasn't yet been added to the window manager, |
| 4044 | // and this guy didn't finish itself or start another activity, |
| 4045 | // then go ahead and add the window. |
| 4046 | boolean willBeVisible = !a.mStartedActivity; |
| 4047 | if (!willBeVisible) { |
| 4048 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4049 | willBeVisible = ActivityTaskManager.getService().willActivityBeVisible( |
Andrii Kulian | d9e2acb | 2018-03-29 16:07:11 -0700 | [diff] [blame] | 4050 | a.getActivityToken()); |
| 4051 | } catch (RemoteException e) { |
| 4052 | throw e.rethrowFromSystemServer(); |
| 4053 | } |
| 4054 | } |
| 4055 | if (r.window == null && !a.mFinished && willBeVisible) { |
| 4056 | r.window = r.activity.getWindow(); |
| 4057 | View decor = r.window.getDecorView(); |
| 4058 | decor.setVisibility(View.INVISIBLE); |
| 4059 | ViewManager wm = a.getWindowManager(); |
| 4060 | WindowManager.LayoutParams l = r.window.getAttributes(); |
| 4061 | a.mDecor = decor; |
| 4062 | l.type = WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
| 4063 | l.softInputMode |= forwardBit; |
| 4064 | if (r.mPreserveWindow) { |
| 4065 | a.mWindowAdded = true; |
| 4066 | r.mPreserveWindow = false; |
| 4067 | // Normally the ViewRoot sets up callbacks with the Activity |
| 4068 | // in addView->ViewRootImpl#setView. If we are instead reusing |
| 4069 | // the decor view we have to notify the view root that the |
| 4070 | // callbacks may have changed. |
| 4071 | ViewRootImpl impl = decor.getViewRootImpl(); |
| 4072 | if (impl != null) { |
| 4073 | impl.notifyChildRebuilt(); |
Dianne Hackborn | 061d58a | 2010-03-12 15:07:06 -0800 | [diff] [blame] | 4074 | } |
| 4075 | } |
Andrii Kulian | d9e2acb | 2018-03-29 16:07:11 -0700 | [diff] [blame] | 4076 | if (a.mVisibleFromClient) { |
| 4077 | if (!a.mWindowAdded) { |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4078 | a.mWindowAdded = true; |
Andrii Kulian | d9e2acb | 2018-03-29 16:07:11 -0700 | [diff] [blame] | 4079 | wm.addView(decor, l); |
| 4080 | } else { |
| 4081 | // The activity will get a callback for this {@link LayoutParams} change |
| 4082 | // earlier. However, at that time the decor will not be set (this is set |
| 4083 | // in this method), so no action will be taken. This call ensures the |
| 4084 | // callback occurs with the decor set. |
| 4085 | a.onWindowAttributesChanged(l); |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4086 | } |
Andrii Kulian | d9e2acb | 2018-03-29 16:07:11 -0700 | [diff] [blame] | 4087 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4088 | |
| 4089 | // If the window has already been added, but during resume |
| 4090 | // we started another activity, then don't yet make the |
Dianne Hackborn | 061d58a | 2010-03-12 15:07:06 -0800 | [diff] [blame] | 4091 | // window visible. |
Andrii Kulian | d9e2acb | 2018-03-29 16:07:11 -0700 | [diff] [blame] | 4092 | } else if (!willBeVisible) { |
| 4093 | if (localLOGV) Slog.v(TAG, "Launch " + r + " mStartedActivity set"); |
| 4094 | r.hideForNow = true; |
| 4095 | } |
| 4096 | |
| 4097 | // Get rid of anything left hanging around. |
| 4098 | cleanUpPendingRemoveWindows(r, false /* force */); |
| 4099 | |
| 4100 | // The window is now visible if it has been added, we are not |
| 4101 | // simply finishing, and we are not starting another activity. |
| 4102 | if (!r.activity.mFinished && willBeVisible && r.activity.mDecor != null && !r.hideForNow) { |
| 4103 | if (r.newConfig != null) { |
| 4104 | performConfigurationChangedForActivity(r, r.newConfig); |
| 4105 | if (DEBUG_CONFIGURATION) { |
| 4106 | Slog.v(TAG, "Resuming activity " + r.activityInfo.name + " with newConfig " |
| 4107 | + r.activity.mCurrentConfig); |
| 4108 | } |
| 4109 | r.newConfig = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4110 | } |
Andrii Kulian | d9e2acb | 2018-03-29 16:07:11 -0700 | [diff] [blame] | 4111 | if (localLOGV) Slog.v(TAG, "Resuming " + r + " with isForward=" + isForward); |
| 4112 | WindowManager.LayoutParams l = r.window.getAttributes(); |
| 4113 | if ((l.softInputMode |
| 4114 | & WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) |
| 4115 | != forwardBit) { |
| 4116 | l.softInputMode = (l.softInputMode |
| 4117 | & (~WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION)) |
| 4118 | | forwardBit; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4119 | if (r.activity.mVisibleFromClient) { |
Andrii Kulian | d9e2acb | 2018-03-29 16:07:11 -0700 | [diff] [blame] | 4120 | ViewManager wm = a.getWindowManager(); |
| 4121 | View decor = r.window.getDecorView(); |
| 4122 | wm.updateViewLayout(decor, l); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4123 | } |
| 4124 | } |
| 4125 | |
Andrii Kulian | d9e2acb | 2018-03-29 16:07:11 -0700 | [diff] [blame] | 4126 | r.activity.mVisibleFromServer = true; |
| 4127 | mNumVisibleActivities++; |
| 4128 | if (r.activity.mVisibleFromClient) { |
| 4129 | r.activity.makeVisible(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4130 | } |
| 4131 | } |
Andrii Kulian | d9e2acb | 2018-03-29 16:07:11 -0700 | [diff] [blame] | 4132 | |
| 4133 | r.nextIdle = mNewActivities; |
| 4134 | mNewActivities = r; |
| 4135 | if (localLOGV) Slog.v(TAG, "Scheduling idle handler for " + r); |
| 4136 | Looper.myQueue().addIdleHandler(new Idler()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4137 | } |
| 4138 | |
Andrii Kulian | d70cdb9 | 2019-01-08 15:03:50 -0800 | [diff] [blame] | 4139 | |
| 4140 | @Override |
| 4141 | public void handleTopResumedActivityChanged(IBinder token, boolean onTop, String reason) { |
| 4142 | ActivityClientRecord r = mActivities.get(token); |
| 4143 | if (r == null || r.activity == null) { |
| 4144 | Slog.w(TAG, "Not found target activity to report position change for token: " + token); |
| 4145 | return; |
| 4146 | } |
| 4147 | |
| 4148 | if (DEBUG_ORDER) { |
| 4149 | Slog.d(TAG, "Received position change to top: " + onTop + " for activity: " + r); |
| 4150 | } |
| 4151 | |
| 4152 | if (r.isTopResumedActivity == onTop) { |
| 4153 | throw new IllegalStateException("Activity top position already set to onTop=" + onTop); |
| 4154 | } |
| 4155 | |
| 4156 | r.isTopResumedActivity = onTop; |
| 4157 | |
| 4158 | if (r.getLifecycleState() == ON_RESUME) { |
| 4159 | reportTopResumedActivityChanged(r, onTop); |
| 4160 | } else { |
| 4161 | if (DEBUG_ORDER) { |
| 4162 | Slog.d(TAG, "Won't deliver top position change in state=" + r.getLifecycleState()); |
| 4163 | } |
| 4164 | } |
| 4165 | } |
| 4166 | |
| 4167 | /** |
| 4168 | * Call {@link Activity#onTopResumedActivityChanged(boolean)} if its top resumed state changed |
| 4169 | * since the last report. |
| 4170 | */ |
| 4171 | private void reportTopResumedActivityChanged(ActivityClientRecord r, boolean onTop) { |
| 4172 | if (r.lastReportedTopResumedState != onTop) { |
| 4173 | r.lastReportedTopResumedState = onTop; |
| 4174 | r.activity.onTopResumedActivityChanged(onTop); |
| 4175 | } |
| 4176 | } |
| 4177 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 4178 | @Override |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4179 | public void handlePauseActivity(IBinder token, boolean finished, boolean userLeaving, |
Andrii Kulian | a6176e3 | 2018-02-27 11:51:18 -0800 | [diff] [blame] | 4180 | int configChanges, PendingTransactionActions pendingActions, String reason) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4181 | ActivityClientRecord r = mActivities.get(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4182 | if (r != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4183 | if (userLeaving) { |
| 4184 | performUserLeavingActivity(r); |
| 4185 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4186 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4187 | r.activity.mConfigChangeFlags |= configChanges; |
Andrii Kulian | d25680c | 2018-02-21 15:16:58 -0800 | [diff] [blame] | 4188 | performPauseActivity(r, finished, reason, pendingActions); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4189 | |
Dianne Hackborn | aa93bcd | 2010-10-27 13:57:00 -0700 | [diff] [blame] | 4190 | // Make sure any pending writes are now committed. |
Dianne Hackborn | 5d9d03a | 2011-01-24 13:15:09 -0800 | [diff] [blame] | 4191 | if (r.isPreHoneycomb()) { |
| 4192 | QueuedWork.waitToFinish(); |
| 4193 | } |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4194 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4195 | } |
| 4196 | } |
| 4197 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4198 | final void performUserLeavingActivity(ActivityClientRecord r) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4199 | mInstrumentation.callActivityOnUserLeaving(r.activity); |
| 4200 | } |
| 4201 | |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 4202 | final Bundle performPauseActivity(IBinder token, boolean finished, String reason, |
| 4203 | PendingTransactionActions pendingActions) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4204 | ActivityClientRecord r = mActivities.get(token); |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 4205 | return r != null ? performPauseActivity(r, finished, reason, pendingActions) : null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4206 | } |
| 4207 | |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 4208 | /** |
| 4209 | * Pause the activity. |
| 4210 | * @return Saved instance state for pre-Honeycomb apps if it was saved, {@code null} otherwise. |
| 4211 | */ |
| 4212 | private Bundle performPauseActivity(ActivityClientRecord r, boolean finished, String reason, |
| 4213 | PendingTransactionActions pendingActions) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4214 | if (r.paused) { |
Andrii Kulian | c10482f | 2019-03-07 18:09:28 +0000 | [diff] [blame] | 4215 | if (r.activity.mFinished) { |
| 4216 | // If we are finishing, we won't call onResume() in certain cases. |
| 4217 | // So here we likewise don't want to call onPause() if the activity |
| 4218 | // isn't resumed. |
| 4219 | return null; |
| 4220 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4221 | RuntimeException e = new RuntimeException( |
| 4222 | "Performing pause of activity that is not resumed: " |
| 4223 | + r.intent.getComponent().toShortString()); |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 4224 | Slog.e(TAG, e.getMessage(), e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4225 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4226 | if (finished) { |
| 4227 | r.activity.mFinished = true; |
| 4228 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4229 | |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 4230 | // Pre-Honeycomb apps always save their state before pausing |
| 4231 | final boolean shouldSaveState = !r.activity.mFinished && r.isPreHoneycomb(); |
| 4232 | if (shouldSaveState) { |
| 4233 | callActivityOnSaveInstanceState(r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4234 | } |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 4235 | |
| 4236 | performPauseActivityIfNeeded(r, reason); |
Jeff Hamilton | 52d3203 | 2011-01-08 15:31:26 -0600 | [diff] [blame] | 4237 | |
| 4238 | // Notify any outstanding on paused listeners |
| 4239 | ArrayList<OnActivityPausedListener> listeners; |
| 4240 | synchronized (mOnPauseListeners) { |
| 4241 | listeners = mOnPauseListeners.remove(r.activity); |
| 4242 | } |
| 4243 | int size = (listeners != null ? listeners.size() : 0); |
| 4244 | for (int i = 0; i < size; i++) { |
| 4245 | listeners.get(i).onPaused(r.activity); |
| 4246 | } |
| 4247 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4248 | final Bundle oldState = pendingActions != null ? pendingActions.getOldState() : null; |
| 4249 | if (oldState != null) { |
| 4250 | // We need to keep around the original state, in case we need to be created again. |
| 4251 | // But we only do this for pre-Honeycomb apps, which always save their state when |
| 4252 | // pausing, so we can not have them save their state when restarting from a paused |
| 4253 | // state. For HC and later, we want to (and can) let the state be saved as the |
| 4254 | // normal part of stopping the activity. |
| 4255 | if (r.isPreHoneycomb()) { |
| 4256 | r.state = oldState; |
| 4257 | } |
| 4258 | } |
| 4259 | |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 4260 | return shouldSaveState ? r.state : null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4261 | } |
| 4262 | |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 4263 | private void performPauseActivityIfNeeded(ActivityClientRecord r, String reason) { |
| 4264 | if (r.paused) { |
| 4265 | // You are already paused silly... |
| 4266 | return; |
| 4267 | } |
| 4268 | |
Andrii Kulian | d70cdb9 | 2019-01-08 15:03:50 -0800 | [diff] [blame] | 4269 | // Always reporting top resumed position loss when pausing an activity. If necessary, it |
| 4270 | // will be restored in performResumeActivity(). |
| 4271 | reportTopResumedActivityChanged(r, false /* onTop */); |
| 4272 | |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 4273 | try { |
| 4274 | r.activity.mCalled = false; |
| 4275 | mInstrumentation.callActivityOnPause(r.activity); |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 4276 | if (!r.activity.mCalled) { |
| 4277 | throw new SuperNotCalledException("Activity " + safeToComponentShortString(r.intent) |
| 4278 | + " did not call through to super.onPause()"); |
| 4279 | } |
| 4280 | } catch (SuperNotCalledException e) { |
| 4281 | throw e; |
| 4282 | } catch (Exception e) { |
| 4283 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4284 | throw new RuntimeException("Unable to pause activity " |
| 4285 | + safeToComponentShortString(r.intent) + ": " + e.toString(), e); |
| 4286 | } |
| 4287 | } |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4288 | r.setState(ON_PAUSE); |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 4289 | } |
| 4290 | |
Andrii Kulian | 829829c | 2018-03-19 18:19:05 -0700 | [diff] [blame] | 4291 | /** Called from {@link LocalActivityManager}. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 4292 | @UnsupportedAppUsage |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 4293 | final void performStopActivity(IBinder token, boolean saveState, String reason) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4294 | ActivityClientRecord r = mActivities.get(token); |
Andrii Kulian | 829829c | 2018-03-19 18:19:05 -0700 | [diff] [blame] | 4295 | performStopActivityInner(r, null /* stopInfo */, false /* keepShown */, saveState, |
| 4296 | false /* finalStateRequest */, reason); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4297 | } |
| 4298 | |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 4299 | private static final class ProviderRefCount { |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 4300 | public final ContentProviderHolder holder; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 4301 | public final ProviderClientRecord client; |
| 4302 | public int stableCount; |
| 4303 | public int unstableCount; |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 4304 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 4305 | // When this is set, the stable and unstable ref counts are 0 and |
| 4306 | // we have a pending operation scheduled to remove the ref count |
| 4307 | // from the activity manager. On the activity manager we are still |
| 4308 | // holding an unstable ref, though it is not reflected in the counts |
| 4309 | // here. |
| 4310 | public boolean removePending; |
| 4311 | |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 4312 | ProviderRefCount(ContentProviderHolder inHolder, |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 4313 | ProviderClientRecord inClient, int sCount, int uCount) { |
| 4314 | holder = inHolder; |
| 4315 | client = inClient; |
| 4316 | stableCount = sCount; |
| 4317 | unstableCount = uCount; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4318 | } |
| 4319 | } |
| 4320 | |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4321 | /** |
| 4322 | * Core implementation of stopping an activity. Note this is a little |
| 4323 | * tricky because the server's meaning of stop is slightly different |
| 4324 | * than our client -- for the server, stop means to save state and give |
| 4325 | * it the result when it is done, but the window may still be visible. |
| 4326 | * For the client, we want to call onStop()/onStart() to indicate when |
Wale Ogunwale | b5066fe | 2016-09-21 07:33:43 -0700 | [diff] [blame] | 4327 | * the activity's UI visibility changes. |
Andrii Kulian | 829829c | 2018-03-19 18:19:05 -0700 | [diff] [blame] | 4328 | * @param r Target activity client record. |
| 4329 | * @param info Action that will report activity stop to server. |
| 4330 | * @param keepShown Flag indicating whether the activity is still shown. |
| 4331 | * @param saveState Flag indicating whether the activity state should be saved. |
| 4332 | * @param finalStateRequest Flag indicating if this call is handling final lifecycle state |
| 4333 | * request for a transaction. |
| 4334 | * @param reason Reason for performing this operation. |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4335 | */ |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4336 | private void performStopActivityInner(ActivityClientRecord r, StopInfo info, boolean keepShown, |
Andrii Kulian | 829829c | 2018-03-19 18:19:05 -0700 | [diff] [blame] | 4337 | boolean saveState, boolean finalStateRequest, String reason) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4338 | if (localLOGV) Slog.v(TAG, "Performing stop of " + r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4339 | if (r != null) { |
Andrii Kulian | c10482f | 2019-03-07 18:09:28 +0000 | [diff] [blame] | 4340 | if (!keepShown && r.stopped) { |
| 4341 | if (r.activity.mFinished) { |
| 4342 | // If we are finishing, we won't call onResume() in certain |
| 4343 | // cases. So here we likewise don't want to call onStop() |
| 4344 | // if the activity isn't resumed. |
| 4345 | return; |
| 4346 | } |
| 4347 | if (!finalStateRequest) { |
| 4348 | final RuntimeException e = new RuntimeException( |
| 4349 | "Performing stop of activity that is already stopped: " |
| 4350 | + r.intent.getComponent().toShortString()); |
| 4351 | Slog.e(TAG, e.getMessage(), e); |
| 4352 | Slog.e(TAG, r.getStateString()); |
| 4353 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4354 | } |
| 4355 | |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 4356 | // One must first be paused before stopped... |
| 4357 | performPauseActivityIfNeeded(r, reason); |
| 4358 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4359 | if (info != null) { |
| 4360 | try { |
| 4361 | // First create a thumbnail for the activity... |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4362 | // For now, don't create the thumbnail here; we are |
| 4363 | // doing that by doing a screen snapshot. |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4364 | info.setDescription(r.activity.onCreateDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4365 | } catch (Exception e) { |
| 4366 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4367 | throw new RuntimeException( |
| 4368 | "Unable to save state of activity " |
| 4369 | + r.intent.getComponent().toShortString() |
| 4370 | + ": " + e.toString(), e); |
| 4371 | } |
| 4372 | } |
| 4373 | } |
| 4374 | |
| 4375 | if (!keepShown) { |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 4376 | callActivityOnStop(r, saveState, reason); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4377 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4378 | } |
| 4379 | } |
| 4380 | |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 4381 | /** |
| 4382 | * Calls {@link Activity#onStop()} and {@link Activity#onSaveInstanceState(Bundle)}, and updates |
| 4383 | * the client record's state. |
| 4384 | * All calls to stop an activity must be done through this method to make sure that |
| 4385 | * {@link Activity#onSaveInstanceState(Bundle)} is also executed in the same call. |
| 4386 | */ |
| 4387 | private void callActivityOnStop(ActivityClientRecord r, boolean saveState, String reason) { |
Andrii Kulian | 391161f | 2018-01-29 10:50:02 -0800 | [diff] [blame] | 4388 | // Before P onSaveInstanceState was called before onStop, starting with P it's |
| 4389 | // called after. Before Honeycomb state was always saved before onPause. |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 4390 | final boolean shouldSaveState = saveState && !r.activity.mFinished && r.state == null |
| 4391 | && !r.isPreHoneycomb(); |
Andrii Kulian | 391161f | 2018-01-29 10:50:02 -0800 | [diff] [blame] | 4392 | final boolean isPreP = r.isPreP(); |
| 4393 | if (shouldSaveState && isPreP) { |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 4394 | callActivityOnSaveInstanceState(r); |
| 4395 | } |
| 4396 | |
| 4397 | try { |
Garfield Tan | c1681e6 | 2018-05-29 11:05:05 -0700 | [diff] [blame] | 4398 | r.activity.performStop(r.mPreserveWindow, reason); |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 4399 | } catch (SuperNotCalledException e) { |
| 4400 | throw e; |
| 4401 | } catch (Exception e) { |
| 4402 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4403 | throw new RuntimeException( |
| 4404 | "Unable to stop activity " |
| 4405 | + r.intent.getComponent().toShortString() |
| 4406 | + ": " + e.toString(), e); |
| 4407 | } |
| 4408 | } |
| 4409 | r.setState(ON_STOP); |
Andrii Kulian | 391161f | 2018-01-29 10:50:02 -0800 | [diff] [blame] | 4410 | |
| 4411 | if (shouldSaveState && !isPreP) { |
| 4412 | callActivityOnSaveInstanceState(r); |
| 4413 | } |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 4414 | } |
| 4415 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 4416 | private void updateVisibility(ActivityClientRecord r, boolean show) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4417 | View v = r.activity.mDecor; |
| 4418 | if (v != null) { |
| 4419 | if (show) { |
| 4420 | if (!r.activity.mVisibleFromServer) { |
| 4421 | r.activity.mVisibleFromServer = true; |
| 4422 | mNumVisibleActivities++; |
| 4423 | if (r.activity.mVisibleFromClient) { |
| 4424 | r.activity.makeVisible(); |
| 4425 | } |
| 4426 | } |
| 4427 | if (r.newConfig != null) { |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4428 | performConfigurationChangedForActivity(r, r.newConfig); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4429 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Updating activity vis " |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 4430 | + r.activityInfo.name + " with new config " |
| 4431 | + r.activity.mCurrentConfig); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4432 | r.newConfig = null; |
| 4433 | } |
| 4434 | } else { |
| 4435 | if (r.activity.mVisibleFromServer) { |
| 4436 | r.activity.mVisibleFromServer = false; |
| 4437 | mNumVisibleActivities--; |
| 4438 | v.setVisibility(View.INVISIBLE); |
| 4439 | } |
| 4440 | } |
| 4441 | } |
| 4442 | } |
| 4443 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 4444 | @Override |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4445 | public void handleStopActivity(IBinder token, boolean show, int configChanges, |
Andrii Kulian | 829829c | 2018-03-19 18:19:05 -0700 | [diff] [blame] | 4446 | PendingTransactionActions pendingActions, boolean finalStateRequest, String reason) { |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4447 | final ActivityClientRecord r = mActivities.get(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4448 | r.activity.mConfigChangeFlags |= configChanges; |
| 4449 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4450 | final StopInfo stopInfo = new StopInfo(); |
Andrii Kulian | 829829c | 2018-03-19 18:19:05 -0700 | [diff] [blame] | 4451 | performStopActivityInner(r, stopInfo, show, true /* saveState */, finalStateRequest, |
| 4452 | reason); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4453 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4454 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4455 | TAG, "Finishing stop of " + r + ": show=" + show |
| 4456 | + " win=" + r.window); |
| 4457 | |
| 4458 | updateVisibility(r, show); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4459 | |
Dianne Hackborn | 5d9d03a | 2011-01-24 13:15:09 -0800 | [diff] [blame] | 4460 | // Make sure any pending writes are now committed. |
| 4461 | if (!r.isPreHoneycomb()) { |
| 4462 | QueuedWork.waitToFinish(); |
| 4463 | } |
| 4464 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4465 | stopInfo.setActivity(r); |
| 4466 | stopInfo.setState(r.state); |
| 4467 | stopInfo.setPersistentState(r.persistentState); |
| 4468 | pendingActions.setStopInfo(stopInfo); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4469 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4470 | } |
| 4471 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4472 | /** |
| 4473 | * Schedule the call to tell the activity manager we have stopped. We don't do this |
| 4474 | * immediately, because we want to have a chance for any other pending work (in particular |
| 4475 | * memory trim requests) to complete before you tell the activity manager to proceed and allow |
| 4476 | * us to go fully into the background. |
| 4477 | */ |
| 4478 | @Override |
| 4479 | public void reportStop(PendingTransactionActions pendingActions) { |
| 4480 | mH.post(pendingActions.getStopInfo()); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 4481 | } |
| 4482 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4483 | @Override |
| 4484 | public void performRestartActivity(IBinder token, boolean start) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4485 | ActivityClientRecord r = mActivities.get(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4486 | if (r.stopped) { |
Andrii Kulian | d25680c | 2018-02-21 15:16:58 -0800 | [diff] [blame] | 4487 | r.activity.performRestart(start, "performRestartActivity"); |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4488 | if (start) { |
| 4489 | r.setState(ON_START); |
| 4490 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4491 | } |
| 4492 | } |
| 4493 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 4494 | @Override |
| 4495 | public void handleWindowVisibility(IBinder token, boolean show) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4496 | ActivityClientRecord r = mActivities.get(token); |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 4497 | |
Dianne Hackborn | bfddc0f | 2010-12-14 11:28:01 -0800 | [diff] [blame] | 4498 | if (r == null) { |
| 4499 | Log.w(TAG, "handleWindowVisibility: no activity for token " + token); |
| 4500 | return; |
| 4501 | } |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 4502 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4503 | if (!show && !r.stopped) { |
Andrii Kulian | 829829c | 2018-03-19 18:19:05 -0700 | [diff] [blame] | 4504 | performStopActivityInner(r, null /* stopInfo */, show, false /* saveState */, |
| 4505 | false /* finalStateRequest */, "handleWindowVisibility"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4506 | } else if (show && r.stopped) { |
| 4507 | // If we are getting ready to gc after going to the background, well |
| 4508 | // we are back active so skip it. |
| 4509 | unscheduleGcIdler(); |
| 4510 | |
Andrii Kulian | d25680c | 2018-02-21 15:16:58 -0800 | [diff] [blame] | 4511 | r.activity.performRestart(true /* start */, "handleWindowVisibility"); |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4512 | r.setState(ON_START); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4513 | } |
| 4514 | if (r.activity.mDecor != null) { |
Joe Onorato | 43a1765 | 2011-04-06 19:22:23 -0700 | [diff] [blame] | 4515 | if (false) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4516 | TAG, "Handle window " + r + " visibility: " + show); |
| 4517 | updateVisibility(r, show); |
| 4518 | } |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4519 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4520 | } |
| 4521 | |
Wale Ogunwale | b5066fe | 2016-09-21 07:33:43 -0700 | [diff] [blame] | 4522 | // TODO: This method should be changed to use {@link #performStopActivityInner} to perform to |
| 4523 | // stop operation on the activity to reduce code duplication and the chance of fixing a bug in |
| 4524 | // one place and missing the other. |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 4525 | private void handleSleeping(IBinder token, boolean sleeping) { |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 4526 | ActivityClientRecord r = mActivities.get(token); |
| 4527 | |
| 4528 | if (r == null) { |
Dianne Hackborn | 842e04b | 2011-01-22 13:00:12 -0800 | [diff] [blame] | 4529 | Log.w(TAG, "handleSleeping: no activity for token " + token); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 4530 | return; |
| 4531 | } |
| 4532 | |
| 4533 | if (sleeping) { |
Dianne Hackborn | 842e04b | 2011-01-22 13:00:12 -0800 | [diff] [blame] | 4534 | if (!r.stopped && !r.isPreHoneycomb()) { |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 4535 | callActivityOnStop(r, true /* saveState */, "sleeping"); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 4536 | } |
Dianne Hackborn | 5d9d03a | 2011-01-24 13:15:09 -0800 | [diff] [blame] | 4537 | |
| 4538 | // Make sure any pending writes are now committed. |
| 4539 | if (!r.isPreHoneycomb()) { |
| 4540 | QueuedWork.waitToFinish(); |
| 4541 | } |
| 4542 | |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 4543 | // Tell activity manager we slept. |
| 4544 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4545 | ActivityTaskManager.getService().activitySlept(r.token); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 4546 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4547 | throw ex.rethrowFromSystemServer(); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 4548 | } |
| 4549 | } else { |
| 4550 | if (r.stopped && r.activity.mVisibleFromServer) { |
Andrii Kulian | d25680c | 2018-02-21 15:16:58 -0800 | [diff] [blame] | 4551 | r.activity.performRestart(true /* start */, "handleSleeping"); |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4552 | r.setState(ON_START); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 4553 | } |
| 4554 | } |
| 4555 | } |
| 4556 | |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 4557 | private void handleSetCoreSettings(Bundle coreSettings) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4558 | synchronized (mResourcesManager) { |
Svetoslav Ganov | 9aa597e | 2011-03-03 18:17:41 -0800 | [diff] [blame] | 4559 | mCoreSettings = coreSettings; |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 4560 | } |
Jon Miranda | 836c0a8 | 2014-08-11 12:32:26 -0700 | [diff] [blame] | 4561 | onCoreSettingsChange(); |
| 4562 | } |
| 4563 | |
| 4564 | private void onCoreSettingsChange() { |
Aurimas Liutikas | 8f004c8 | 2019-01-17 17:20:10 -0800 | [diff] [blame] | 4565 | if (updateDebugViewAttributeState()) { |
Jon Miranda | 836c0a8 | 2014-08-11 12:32:26 -0700 | [diff] [blame] | 4566 | // request all activities to relaunch for the changes to take place |
Wale Ogunwale | 5527a50 | 2018-02-20 18:18:21 -0800 | [diff] [blame] | 4567 | relaunchAllActivities(); |
Fyodor Kupolov | cb93d6f | 2017-05-04 17:27:16 -0700 | [diff] [blame] | 4568 | } |
| 4569 | } |
| 4570 | |
Aurimas Liutikas | 8f004c8 | 2019-01-17 17:20:10 -0800 | [diff] [blame] | 4571 | private boolean updateDebugViewAttributeState() { |
| 4572 | boolean previousState = View.sDebugViewAttributes; |
| 4573 | |
| 4574 | View.sDebugViewAttributesApplicationPackage = mCoreSettings.getString( |
| 4575 | Settings.Global.DEBUG_VIEW_ATTRIBUTES_APPLICATION_PACKAGE, ""); |
| 4576 | String currentPackage = (mBoundApplication != null && mBoundApplication.appInfo != null) |
| 4577 | ? mBoundApplication.appInfo.packageName : ""; |
| 4578 | View.sDebugViewAttributes = |
| 4579 | mCoreSettings.getInt(Settings.Global.DEBUG_VIEW_ATTRIBUTES, 0) != 0 |
| 4580 | || View.sDebugViewAttributesApplicationPackage.equals(currentPackage); |
| 4581 | return previousState != View.sDebugViewAttributes; |
| 4582 | } |
| 4583 | |
Wale Ogunwale | 5527a50 | 2018-02-20 18:18:21 -0800 | [diff] [blame] | 4584 | private void relaunchAllActivities() { |
Fyodor Kupolov | cb93d6f | 2017-05-04 17:27:16 -0700 | [diff] [blame] | 4585 | for (Map.Entry<IBinder, ActivityClientRecord> entry : mActivities.entrySet()) { |
| 4586 | final Activity activity = entry.getValue().activity; |
| 4587 | if (!activity.mFinished) { |
Andrii Kulian | 320e3b5 | 2018-05-03 16:26:25 -0700 | [diff] [blame] | 4588 | scheduleRelaunchActivity(entry.getKey()); |
Jon Miranda | 836c0a8 | 2014-08-11 12:32:26 -0700 | [diff] [blame] | 4589 | } |
| 4590 | } |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 4591 | } |
| 4592 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4593 | private void handleUpdatePackageCompatibilityInfo(UpdateCompatibilityData data) { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 4594 | LoadedApk apk = peekPackageInfo(data.pkg, false); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4595 | if (apk != null) { |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 4596 | apk.setCompatibilityInfo(data.info); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4597 | } |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 4598 | apk = peekPackageInfo(data.pkg, true); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4599 | if (apk != null) { |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 4600 | apk.setCompatibilityInfo(data.info); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4601 | } |
| 4602 | handleConfigurationChanged(mConfiguration, data.info); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 4603 | WindowManagerGlobal.getInstance().reportNewConfiguration(mConfiguration); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4604 | } |
| 4605 | |
Andrii Kulian | e55b009 | 2018-04-19 15:29:22 -0700 | [diff] [blame] | 4606 | 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] | 4607 | final int N = results.size(); |
| 4608 | for (int i=0; i<N; i++) { |
| 4609 | ResultInfo ri = results.get(i); |
| 4610 | try { |
| 4611 | if (ri.mData != null) { |
| 4612 | ri.mData.setExtrasClassLoader(r.activity.getClassLoader()); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 4613 | ri.mData.prepareToEnterProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4614 | } |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4615 | if (DEBUG_RESULTS) Slog.v(TAG, |
Chris Tate | 8a7dc17 | 2009-03-24 20:11:42 -0700 | [diff] [blame] | 4616 | "Delivering result to activity " + r + " : " + ri); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4617 | r.activity.dispatchActivityResult(ri.mResultWho, |
Andrii Kulian | e55b009 | 2018-04-19 15:29:22 -0700 | [diff] [blame] | 4618 | ri.mRequestCode, ri.mResultCode, ri.mData, reason); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4619 | } catch (Exception e) { |
| 4620 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4621 | throw new RuntimeException( |
| 4622 | "Failure delivering result " + ri + " to activity " |
| 4623 | + r.intent.getComponent().toShortString() |
| 4624 | + ": " + e.toString(), e); |
| 4625 | } |
| 4626 | } |
| 4627 | } |
| 4628 | } |
| 4629 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 4630 | @Override |
Andrii Kulian | e55b009 | 2018-04-19 15:29:22 -0700 | [diff] [blame] | 4631 | public void handleSendResult(IBinder token, List<ResultInfo> results, String reason) { |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 4632 | ActivityClientRecord r = mActivities.get(token); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4633 | 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] | 4634 | if (r != null) { |
| 4635 | final boolean resumed = !r.paused; |
| 4636 | if (!r.activity.mFinished && r.activity.mDecor != null |
| 4637 | && r.hideForNow && resumed) { |
| 4638 | // We had hidden the activity because it started another |
| 4639 | // one... we have gotten a result back and we are not |
| 4640 | // paused, so make sure our window is visible. |
| 4641 | updateVisibility(r, true); |
| 4642 | } |
| 4643 | if (resumed) { |
| 4644 | try { |
| 4645 | // Now we are idle. |
| 4646 | r.activity.mCalled = false; |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 4647 | r.activity.mTemporaryPause = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4648 | mInstrumentation.callActivityOnPause(r.activity); |
| 4649 | if (!r.activity.mCalled) { |
| 4650 | throw new SuperNotCalledException( |
| 4651 | "Activity " + r.intent.getComponent().toShortString() |
| 4652 | + " did not call through to super.onPause()"); |
| 4653 | } |
| 4654 | } catch (SuperNotCalledException e) { |
| 4655 | throw e; |
| 4656 | } catch (Exception e) { |
| 4657 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4658 | throw new RuntimeException( |
| 4659 | "Unable to pause activity " |
| 4660 | + r.intent.getComponent().toShortString() |
| 4661 | + ": " + e.toString(), e); |
| 4662 | } |
| 4663 | } |
| 4664 | } |
Sudheer Shanka | 43b5ea4 | 2017-06-21 11:24:53 -0700 | [diff] [blame] | 4665 | checkAndBlockForNetworkAccess(); |
Andrii Kulian | e55b009 | 2018-04-19 15:29:22 -0700 | [diff] [blame] | 4666 | deliverResults(r, results, reason); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4667 | if (resumed) { |
Andrii Kulian | e55b009 | 2018-04-19 15:29:22 -0700 | [diff] [blame] | 4668 | r.activity.performResume(false, reason); |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 4669 | r.activity.mTemporaryPause = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4670 | } |
| 4671 | } |
| 4672 | } |
| 4673 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4674 | /** Core implementation of activity destroy call. */ |
| 4675 | ActivityClientRecord performDestroyActivity(IBinder token, boolean finishing, |
Bryce Lee | a33c13d | 2018-02-08 14:37:06 -0800 | [diff] [blame] | 4676 | int configChanges, boolean getNonConfigInstance, String reason) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4677 | ActivityClientRecord r = mActivities.get(token); |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4678 | Class<? extends Activity> activityClass = null; |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4679 | if (localLOGV) Slog.v(TAG, "Performing finish of " + r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4680 | if (r != null) { |
Brad Fitzpatrick | 5f8b5c1 | 2011-01-20 15:12:08 -0800 | [diff] [blame] | 4681 | activityClass = r.activity.getClass(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4682 | r.activity.mConfigChangeFlags |= configChanges; |
| 4683 | if (finishing) { |
| 4684 | r.activity.mFinished = true; |
| 4685 | } |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 4686 | |
| 4687 | performPauseActivityIfNeeded(r, "destroy"); |
| 4688 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4689 | if (!r.stopped) { |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 4690 | callActivityOnStop(r, false /* saveState */, "destroy"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4691 | } |
| 4692 | if (getNonConfigInstance) { |
| 4693 | try { |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 4694 | r.lastNonConfigurationInstances |
| 4695 | = r.activity.retainNonConfigurationInstances(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4696 | } catch (Exception e) { |
| 4697 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4698 | throw new RuntimeException( |
| 4699 | "Unable to retain activity " |
| 4700 | + r.intent.getComponent().toShortString() |
| 4701 | + ": " + e.toString(), e); |
| 4702 | } |
| 4703 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4704 | } |
| 4705 | try { |
| 4706 | r.activity.mCalled = false; |
Dianne Hackborn | 2dedce6 | 2010-04-15 14:45:25 -0700 | [diff] [blame] | 4707 | mInstrumentation.callActivityOnDestroy(r.activity); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4708 | if (!r.activity.mCalled) { |
| 4709 | throw new SuperNotCalledException( |
Mitsuru Oshima | d9aef73 | 2009-06-16 20:20:50 -0700 | [diff] [blame] | 4710 | "Activity " + safeToComponentShortString(r.intent) + |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4711 | " did not call through to super.onDestroy()"); |
| 4712 | } |
| 4713 | if (r.window != null) { |
| 4714 | r.window.closeAllPanels(); |
| 4715 | } |
| 4716 | } catch (SuperNotCalledException e) { |
| 4717 | throw e; |
| 4718 | } catch (Exception e) { |
| 4719 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4720 | throw new RuntimeException( |
Mitsuru Oshima | d9aef73 | 2009-06-16 20:20:50 -0700 | [diff] [blame] | 4721 | "Unable to destroy activity " + safeToComponentShortString(r.intent) |
| 4722 | + ": " + e.toString(), e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4723 | } |
| 4724 | } |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4725 | r.setState(ON_DESTROY); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4726 | } |
Tim Murray | 59f3dc1 | 2018-10-22 15:26:08 -0700 | [diff] [blame] | 4727 | schedulePurgeIdler(); |
Garfield Tan | 0443b37 | 2019-01-04 15:00:13 -0800 | [diff] [blame] | 4728 | // updatePendingActivityConfiguration() reads from mActivities to update |
| 4729 | // ActivityClientRecord which runs in a different thread. Protect modifications to |
| 4730 | // mActivities to avoid race. |
| 4731 | synchronized (mResourcesManager) { |
| 4732 | mActivities.remove(token); |
| 4733 | } |
Brad Fitzpatrick | 5f8b5c1 | 2011-01-20 15:12:08 -0800 | [diff] [blame] | 4734 | StrictMode.decrementExpectedActivityCount(activityClass); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4735 | return r; |
| 4736 | } |
| 4737 | |
Mitsuru Oshima | d9aef73 | 2009-06-16 20:20:50 -0700 | [diff] [blame] | 4738 | private static String safeToComponentShortString(Intent intent) { |
| 4739 | ComponentName component = intent.getComponent(); |
| 4740 | return component == null ? "[Unknown]" : component.toShortString(); |
| 4741 | } |
| 4742 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 4743 | @Override |
Riddle Hsu | d3062cb | 2018-06-30 02:06:42 +0800 | [diff] [blame] | 4744 | public Map<IBinder, ClientTransactionItem> getActivitiesToBeDestroyed() { |
| 4745 | return mActivitiesToBeDestroyed; |
| 4746 | } |
| 4747 | |
| 4748 | @Override |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 4749 | public void handleDestroyActivity(IBinder token, boolean finishing, int configChanges, |
Bryce Lee | a33c13d | 2018-02-08 14:37:06 -0800 | [diff] [blame] | 4750 | boolean getNonConfigInstance, String reason) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4751 | ActivityClientRecord r = performDestroyActivity(token, finishing, |
Bryce Lee | a33c13d | 2018-02-08 14:37:06 -0800 | [diff] [blame] | 4752 | configChanges, getNonConfigInstance, reason); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4753 | if (r != null) { |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4754 | cleanUpPendingRemoveWindows(r, finishing); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4755 | WindowManager wm = r.activity.getWindowManager(); |
| 4756 | View v = r.activity.mDecor; |
| 4757 | if (v != null) { |
| 4758 | if (r.activity.mVisibleFromServer) { |
| 4759 | mNumVisibleActivities--; |
| 4760 | } |
| 4761 | IBinder wtoken = v.getWindowToken(); |
| 4762 | if (r.activity.mWindowAdded) { |
Robert Carr | 77bdfb5 | 2016-05-02 18:18:31 -0700 | [diff] [blame] | 4763 | if (r.mPreserveWindow) { |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4764 | // Hold off on removing this until the new activity's |
| 4765 | // window is being added. |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4766 | r.mPendingRemoveWindow = r.window; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4767 | r.mPendingRemoveWindowManager = wm; |
Andrii Kulian | eac0ea5 | 2016-05-11 15:50:24 -0700 | [diff] [blame] | 4768 | // We can only keep the part of the view hierarchy that we control, |
| 4769 | // everything else must be removed, because it might not be able to |
| 4770 | // behave properly when activity is relaunching. |
| 4771 | r.window.clearContentView(); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4772 | } else { |
| 4773 | wm.removeViewImmediate(v); |
| 4774 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4775 | } |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4776 | if (wtoken != null && r.mPendingRemoveWindow == null) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 4777 | WindowManagerGlobal.getInstance().closeAll(wtoken, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4778 | r.activity.getClass().getName(), "Activity"); |
Andrii Kulian | eac0ea5 | 2016-05-11 15:50:24 -0700 | [diff] [blame] | 4779 | } else if (r.mPendingRemoveWindow != null) { |
| 4780 | // We're preserving only one window, others should be closed so app views |
| 4781 | // will be detached before the final tear down. It should be done now because |
| 4782 | // some components (e.g. WebView) rely on detach callbacks to perform receiver |
| 4783 | // unregister and other cleanup. |
| 4784 | WindowManagerGlobal.getInstance().closeAllExceptView(token, v, |
| 4785 | r.activity.getClass().getName(), "Activity"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4786 | } |
| 4787 | r.activity.mDecor = null; |
| 4788 | } |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4789 | if (r.mPendingRemoveWindow == null) { |
| 4790 | // If we are delaying the removal of the activity window, then |
| 4791 | // we can't clean up all windows here. Note that we can't do |
| 4792 | // so later either, which means any windows that aren't closed |
| 4793 | // by the app will leak. Well we try to warning them a lot |
| 4794 | // about leaking windows, because that is a bug, so if they are |
| 4795 | // using this recreate facility then they get to live with leaks. |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 4796 | WindowManagerGlobal.getInstance().closeAll(token, |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4797 | r.activity.getClass().getName(), "Activity"); |
| 4798 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4799 | |
| 4800 | // Mocked out contexts won't be participating in the normal |
| 4801 | // process lifecycle, but if we're running with a proper |
| 4802 | // ApplicationContext we need to have it tear down things |
| 4803 | // cleanly. |
| 4804 | Context c = r.activity.getBaseContext(); |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 4805 | if (c instanceof ContextImpl) { |
| 4806 | ((ContextImpl) c).scheduleFinalCleanup( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4807 | r.activity.getClass().getName(), "Activity"); |
| 4808 | } |
| 4809 | } |
| 4810 | if (finishing) { |
| 4811 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4812 | ActivityTaskManager.getService().activityDestroyed(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4813 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4814 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4815 | } |
| 4816 | } |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4817 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4818 | } |
| 4819 | |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 4820 | @Override |
| 4821 | public ActivityClientRecord prepareRelaunchActivity(IBinder token, |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 4822 | List<ResultInfo> pendingResults, List<ReferrerIntent> pendingNewIntents, |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 4823 | int configChanges, MergedConfiguration config, boolean preserveWindow) { |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4824 | ActivityClientRecord target = null; |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 4825 | boolean scheduleRelaunch = false; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4826 | |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4827 | synchronized (mResourcesManager) { |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4828 | for (int i=0; i<mRelaunchingActivities.size(); i++) { |
| 4829 | ActivityClientRecord r = mRelaunchingActivities.get(i); |
Filip Gruszczynski | c3b6179 | 2016-01-22 16:43:48 -0800 | [diff] [blame] | 4830 | if (DEBUG_ORDER) Slog.d(TAG, "requestRelaunchActivity: " + this + ", trying: " + r); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4831 | if (r.token == token) { |
| 4832 | target = r; |
| 4833 | if (pendingResults != null) { |
| 4834 | if (r.pendingResults != null) { |
| 4835 | r.pendingResults.addAll(pendingResults); |
| 4836 | } else { |
| 4837 | r.pendingResults = pendingResults; |
| 4838 | } |
| 4839 | } |
| 4840 | if (pendingNewIntents != null) { |
| 4841 | if (r.pendingIntents != null) { |
| 4842 | r.pendingIntents.addAll(pendingNewIntents); |
| 4843 | } else { |
| 4844 | r.pendingIntents = pendingNewIntents; |
| 4845 | } |
| 4846 | } |
| 4847 | break; |
| 4848 | } |
| 4849 | } |
| 4850 | |
| 4851 | if (target == null) { |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 4852 | if (DEBUG_ORDER) Slog.d(TAG, "requestRelaunchActivity: target is null"); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4853 | target = new ActivityClientRecord(); |
| 4854 | target.token = token; |
| 4855 | target.pendingResults = pendingResults; |
| 4856 | target.pendingIntents = pendingNewIntents; |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4857 | target.mPreserveWindow = preserveWindow; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4858 | mRelaunchingActivities.add(target); |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 4859 | scheduleRelaunch = true; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4860 | } |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 4861 | target.createdConfig = config.getGlobalConfiguration(); |
| 4862 | target.overrideConfig = config.getOverrideConfiguration(); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4863 | target.pendingConfigChanges |= configChanges; |
| 4864 | } |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 4865 | |
| 4866 | return scheduleRelaunch ? target : null; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4867 | } |
| 4868 | |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 4869 | @Override |
| 4870 | public void handleRelaunchActivity(ActivityClientRecord tmp, |
| 4871 | PendingTransactionActions pendingActions) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4872 | // If we are getting ready to gc after going to the background, well |
| 4873 | // we are back active so skip it. |
| 4874 | unscheduleGcIdler(); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4875 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4876 | |
| 4877 | Configuration changedConfig = null; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4878 | int configChanges = 0; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4879 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4880 | // First: make sure we have the most recent configuration and most |
| 4881 | // recent version of the activity, or skip it if some previous call |
| 4882 | // had taken a more recent version. |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4883 | synchronized (mResourcesManager) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4884 | int N = mRelaunchingActivities.size(); |
| 4885 | IBinder token = tmp.token; |
| 4886 | tmp = null; |
| 4887 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4888 | ActivityClientRecord r = mRelaunchingActivities.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4889 | if (r.token == token) { |
| 4890 | tmp = r; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4891 | configChanges |= tmp.pendingConfigChanges; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4892 | mRelaunchingActivities.remove(i); |
| 4893 | i--; |
| 4894 | N--; |
| 4895 | } |
| 4896 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4897 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4898 | if (tmp == null) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4899 | 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] | 4900 | return; |
| 4901 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4902 | |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4903 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Relaunching activity " |
| 4904 | + tmp.token + " with configChanges=0x" |
| 4905 | + Integer.toHexString(configChanges)); |
| 4906 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4907 | if (mPendingConfiguration != null) { |
| 4908 | changedConfig = mPendingConfiguration; |
| 4909 | mPendingConfiguration = null; |
| 4910 | } |
| 4911 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4912 | |
Dianne Hackborn | 871ecdc | 2009-12-11 15:24:33 -0800 | [diff] [blame] | 4913 | if (tmp.createdConfig != null) { |
| 4914 | // If the activity manager is passing us its current config, |
| 4915 | // assume that is really what we want regardless of what we |
| 4916 | // may have pending. |
| 4917 | if (mConfiguration == null |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4918 | || (tmp.createdConfig.isOtherSeqNewer(mConfiguration) |
| 4919 | && mConfiguration.diff(tmp.createdConfig) != 0)) { |
| 4920 | if (changedConfig == null |
| 4921 | || tmp.createdConfig.isOtherSeqNewer(changedConfig)) { |
| 4922 | changedConfig = tmp.createdConfig; |
| 4923 | } |
Dianne Hackborn | 871ecdc | 2009-12-11 15:24:33 -0800 | [diff] [blame] | 4924 | } |
| 4925 | } |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 4926 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4927 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Relaunching activity " |
Dianne Hackborn | dc6b635 | 2009-09-30 14:20:09 -0700 | [diff] [blame] | 4928 | + tmp.token + ": changedConfig=" + changedConfig); |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 4929 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4930 | // If there was a pending configuration change, execute it first. |
| 4931 | if (changedConfig != null) { |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 4932 | mCurDefaultDisplayDpi = changedConfig.densityDpi; |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 4933 | updateDefaultDensity(); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4934 | handleConfigurationChanged(changedConfig, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4935 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4936 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4937 | ActivityClientRecord r = mActivities.get(tmp.token); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4938 | 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] | 4939 | if (r == null) { |
| 4940 | return; |
| 4941 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4942 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4943 | r.activity.mConfigChangeFlags |= configChanges; |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4944 | r.mPreserveWindow = tmp.mPreserveWindow; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4945 | |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4946 | r.activity.mChangingConfigurations = true; |
| 4947 | |
Robert Carr | 23fa16b | 2016-01-13 13:19:58 -0800 | [diff] [blame] | 4948 | // If we are preserving the main window across relaunches we would also like to preserve |
| 4949 | // the children. However the client side view system does not support preserving |
| 4950 | // the child views so we notify the window manager to expect these windows to |
| 4951 | // be replaced and defer requests to destroy or hide them. This way we can achieve |
| 4952 | // visual continuity. It's important that we do this here prior to pause and destroy |
| 4953 | // as that is when we may hide or remove the child views. |
Robert Carr | 77bdfb5 | 2016-05-02 18:18:31 -0700 | [diff] [blame] | 4954 | // |
| 4955 | // There is another scenario, if we have decided locally to relaunch the app from a |
| 4956 | // call to recreate, then none of the windows will be prepared for replacement or |
| 4957 | // preserved by the server, so we want to notify it that we are preparing to replace |
| 4958 | // everything |
Robert Carr | 23fa16b | 2016-01-13 13:19:58 -0800 | [diff] [blame] | 4959 | try { |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 4960 | if (r.mPreserveWindow) { |
Robert Carr | 77bdfb5 | 2016-05-02 18:18:31 -0700 | [diff] [blame] | 4961 | WindowManagerGlobal.getWindowSession().prepareToReplaceWindows( |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 4962 | r.token, true /* childrenOnly */); |
Robert Carr | 23fa16b | 2016-01-13 13:19:58 -0800 | [diff] [blame] | 4963 | } |
| 4964 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4965 | throw e.rethrowFromSystemServer(); |
Robert Carr | 23fa16b | 2016-01-13 13:19:58 -0800 | [diff] [blame] | 4966 | } |
| 4967 | |
Wale Ogunwale | 5527a50 | 2018-02-20 18:18:21 -0800 | [diff] [blame] | 4968 | handleRelaunchActivityInner(r, configChanges, tmp.pendingResults, tmp.pendingIntents, |
| 4969 | pendingActions, tmp.startsNotResumed, tmp.overrideConfig, "handleRelaunchActivity"); |
| 4970 | |
| 4971 | if (pendingActions != null) { |
| 4972 | // Only report a successful relaunch to WindowManager. |
| 4973 | pendingActions.setReportRelaunchToWindowManager(true); |
Dianne Hackborn | e2b0480 | 2010-12-09 09:24:55 -0800 | [diff] [blame] | 4974 | } |
Wale Ogunwale | 5527a50 | 2018-02-20 18:18:21 -0800 | [diff] [blame] | 4975 | } |
| 4976 | |
Andrii Kulian | 320e3b5 | 2018-05-03 16:26:25 -0700 | [diff] [blame] | 4977 | /** |
| 4978 | * Post a message to relaunch the activity. We do this instead of launching it immediately, |
| 4979 | * because this will destroy the activity from which it was called and interfere with the |
| 4980 | * lifecycle changes it was going through before. We need to make sure that we have finished |
| 4981 | * handling current transaction item before relaunching the activity. |
| 4982 | */ |
| 4983 | void scheduleRelaunchActivity(IBinder token) { |
| 4984 | sendMessage(H.RELAUNCH_ACTIVITY, token); |
| 4985 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4986 | |
Andrii Kulian | 320e3b5 | 2018-05-03 16:26:25 -0700 | [diff] [blame] | 4987 | /** Performs the activity relaunch locally vs. requesting from system-server. */ |
| 4988 | private void handleRelaunchActivityLocally(IBinder token) { |
Wale Ogunwale | 5527a50 | 2018-02-20 18:18:21 -0800 | [diff] [blame] | 4989 | final ActivityClientRecord r = mActivities.get(token); |
| 4990 | if (r == null) { |
Andrii Kulian | 320e3b5 | 2018-05-03 16:26:25 -0700 | [diff] [blame] | 4991 | Log.w(TAG, "Activity to relaunch no longer exists"); |
Wale Ogunwale | 5527a50 | 2018-02-20 18:18:21 -0800 | [diff] [blame] | 4992 | return; |
| 4993 | } |
| 4994 | |
| 4995 | final int prevState = r.getLifecycleState(); |
| 4996 | |
Andrii Kulian | 320e3b5 | 2018-05-03 16:26:25 -0700 | [diff] [blame] | 4997 | if (prevState < ON_RESUME || prevState > ON_STOP) { |
| 4998 | Log.w(TAG, "Activity state must be in [ON_RESUME..ON_STOP] in order to be relaunched," |
| 4999 | + "current state is " + prevState); |
Wale Ogunwale | 5527a50 | 2018-02-20 18:18:21 -0800 | [diff] [blame] | 5000 | return; |
| 5001 | } |
| 5002 | |
Wale Ogunwale | 5527a50 | 2018-02-20 18:18:21 -0800 | [diff] [blame] | 5003 | |
Andrii Kulian | 914aa7d | 2018-03-19 21:51:53 -0700 | [diff] [blame] | 5004 | // Initialize a relaunch request. |
| 5005 | final MergedConfiguration mergedConfiguration = new MergedConfiguration( |
| 5006 | r.createdConfig != null ? r.createdConfig : mConfiguration, |
| 5007 | r.overrideConfig); |
| 5008 | final ActivityRelaunchItem activityRelaunchItem = ActivityRelaunchItem.obtain( |
| 5009 | null /* pendingResults */, null /* pendingIntents */, 0 /* configChanges */, |
| 5010 | mergedConfiguration, r.mPreserveWindow); |
| 5011 | // Make sure to match the existing lifecycle state in the end of the transaction. |
| 5012 | final ActivityLifecycleItem lifecycleRequest = |
| 5013 | TransactionExecutorHelper.getLifecycleRequestForCurrentState(r); |
| 5014 | // Schedule the transaction. |
| 5015 | final ClientTransaction transaction = ClientTransaction.obtain(this.mAppThread, r.token); |
| 5016 | transaction.addCallback(activityRelaunchItem); |
| 5017 | transaction.setLifecycleStateRequest(lifecycleRequest); |
| 5018 | executeTransaction(transaction); |
Wale Ogunwale | 5527a50 | 2018-02-20 18:18:21 -0800 | [diff] [blame] | 5019 | } |
| 5020 | |
| 5021 | private void handleRelaunchActivityInner(ActivityClientRecord r, int configChanges, |
| 5022 | List<ResultInfo> pendingResults, List<ReferrerIntent> pendingIntents, |
| 5023 | PendingTransactionActions pendingActions, boolean startsNotResumed, |
| 5024 | Configuration overrideConfig, String reason) { |
Andrii Kulian | 770c403 | 2018-05-02 18:40:59 -0700 | [diff] [blame] | 5025 | // Preserve last used intent, it may be set from Activity#setIntent(). |
| 5026 | final Intent customIntent = r.activity.mIntent; |
Wale Ogunwale | 5527a50 | 2018-02-20 18:18:21 -0800 | [diff] [blame] | 5027 | // Need to ensure state is saved. |
| 5028 | if (!r.paused) { |
| 5029 | performPauseActivity(r, false, reason, null /* pendingActions */); |
| 5030 | } |
| 5031 | if (!r.stopped) { |
| 5032 | callActivityOnStop(r, true /* saveState */, reason); |
| 5033 | } |
| 5034 | |
| 5035 | handleDestroyActivity(r.token, false, configChanges, true, reason); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 5036 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5037 | r.activity = null; |
| 5038 | r.window = null; |
| 5039 | r.hideForNow = false; |
| 5040 | r.nextIdle = null; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5041 | // Merge any pending results and pending intents; don't just replace them |
Wale Ogunwale | 5527a50 | 2018-02-20 18:18:21 -0800 | [diff] [blame] | 5042 | if (pendingResults != null) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5043 | if (r.pendingResults == null) { |
Wale Ogunwale | 5527a50 | 2018-02-20 18:18:21 -0800 | [diff] [blame] | 5044 | r.pendingResults = pendingResults; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5045 | } else { |
Wale Ogunwale | 5527a50 | 2018-02-20 18:18:21 -0800 | [diff] [blame] | 5046 | r.pendingResults.addAll(pendingResults); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5047 | } |
| 5048 | } |
Wale Ogunwale | 5527a50 | 2018-02-20 18:18:21 -0800 | [diff] [blame] | 5049 | if (pendingIntents != null) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5050 | if (r.pendingIntents == null) { |
Wale Ogunwale | 5527a50 | 2018-02-20 18:18:21 -0800 | [diff] [blame] | 5051 | r.pendingIntents = pendingIntents; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5052 | } else { |
Wale Ogunwale | 5527a50 | 2018-02-20 18:18:21 -0800 | [diff] [blame] | 5053 | r.pendingIntents.addAll(pendingIntents); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5054 | } |
| 5055 | } |
Wale Ogunwale | 5527a50 | 2018-02-20 18:18:21 -0800 | [diff] [blame] | 5056 | r.startsNotResumed = startsNotResumed; |
| 5057 | r.overrideConfig = overrideConfig; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 5058 | |
Andrii Kulian | 770c403 | 2018-05-02 18:40:59 -0700 | [diff] [blame] | 5059 | handleLaunchActivity(r, pendingActions, customIntent); |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 5060 | } |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 5061 | |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 5062 | @Override |
| 5063 | public void reportRelaunch(IBinder token, PendingTransactionActions pendingActions) { |
| 5064 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 5065 | ActivityTaskManager.getService().activityRelaunched(token); |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 5066 | final ActivityClientRecord r = mActivities.get(token); |
| 5067 | if (pendingActions.shouldReportRelaunchToWindowManager() && r != null |
| 5068 | && r.window != null) { |
| 5069 | r.window.reportActivityRelaunched(); |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 5070 | } |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 5071 | } catch (RemoteException e) { |
| 5072 | throw e.rethrowFromSystemServer(); |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 5073 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5074 | } |
| 5075 | |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 5076 | private void callActivityOnSaveInstanceState(ActivityClientRecord r) { |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 5077 | r.state = new Bundle(); |
| 5078 | r.state.setAllowFds(false); |
| 5079 | if (r.isPersistable()) { |
| 5080 | r.persistentState = new PersistableBundle(); |
| 5081 | mInstrumentation.callActivityOnSaveInstanceState(r.activity, r.state, |
| 5082 | r.persistentState); |
| 5083 | } else { |
| 5084 | mInstrumentation.callActivityOnSaveInstanceState(r.activity, r.state); |
| 5085 | } |
| 5086 | } |
| 5087 | |
Dianne Hackborn | 73c1416 | 2012-09-19 15:45:06 -0700 | [diff] [blame] | 5088 | ArrayList<ComponentCallbacks2> collectComponentCallbacks( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5089 | boolean allActivities, Configuration newConfig) { |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 5090 | ArrayList<ComponentCallbacks2> callbacks |
| 5091 | = new ArrayList<ComponentCallbacks2>(); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 5092 | |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 5093 | synchronized (mResourcesManager) { |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 5094 | final int NAPP = mAllApplications.size(); |
| 5095 | for (int i=0; i<NAPP; i++) { |
Dianne Hackborn | 73c1416 | 2012-09-19 15:45:06 -0700 | [diff] [blame] | 5096 | callbacks.add(mAllApplications.get(i)); |
| 5097 | } |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 5098 | final int NACT = mActivities.size(); |
| 5099 | for (int i=0; i<NACT; i++) { |
| 5100 | ActivityClientRecord ar = mActivities.valueAt(i); |
| 5101 | Activity a = ar.activity; |
| 5102 | if (a != null) { |
| 5103 | Configuration thisConfig = applyConfigCompatMainThread( |
| 5104 | mCurDefaultDisplayDpi, newConfig, |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5105 | ar.packageInfo.getCompatibilityInfo()); |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 5106 | if (!ar.activity.mFinished && (allActivities || !ar.paused)) { |
| 5107 | // If the activity is currently resumed, its configuration |
| 5108 | // needs to change right now. |
| 5109 | callbacks.add(a); |
| 5110 | } else if (thisConfig != null) { |
| 5111 | // Otherwise, we will tell it about the change |
| 5112 | // the next time it is resumed or shown. Note that |
| 5113 | // the activity manager may, before then, decide the |
| 5114 | // activity needs to be destroyed to handle its new |
| 5115 | // configuration. |
| 5116 | if (DEBUG_CONFIGURATION) { |
| 5117 | Slog.v(TAG, "Setting activity " |
| 5118 | + ar.activityInfo.name + " newConfig=" + thisConfig); |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 5119 | } |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 5120 | ar.newConfig = thisConfig; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5121 | } |
| 5122 | } |
| 5123 | } |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 5124 | final int NSVC = mServices.size(); |
| 5125 | for (int i=0; i<NSVC; i++) { |
| 5126 | callbacks.add(mServices.valueAt(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5127 | } |
| 5128 | } |
| 5129 | synchronized (mProviderMap) { |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 5130 | final int NPRV = mLocalProviders.size(); |
| 5131 | for (int i=0; i<NPRV; i++) { |
| 5132 | callbacks.add(mLocalProviders.valueAt(i).mLocalProvider); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5133 | } |
| 5134 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 5135 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5136 | return callbacks; |
| 5137 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 5138 | |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 5139 | /** |
| 5140 | * Updates the configuration for an Activity. The ActivityClientRecord's |
| 5141 | * {@link ActivityClientRecord#overrideConfig} is used to compute the final Configuration for |
| 5142 | * that Activity. {@link ActivityClientRecord#tmpConfig} is used as a temporary for delivering |
| 5143 | * the updated Configuration. |
| 5144 | * @param r ActivityClientRecord representing the Activity. |
| 5145 | * @param newBaseConfig The new configuration to use. This may be augmented with |
| 5146 | * {@link ActivityClientRecord#overrideConfig}. |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 5147 | */ |
| 5148 | private void performConfigurationChangedForActivity(ActivityClientRecord r, |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5149 | Configuration newBaseConfig) { |
| 5150 | performConfigurationChangedForActivity(r, newBaseConfig, |
Yohei Yukawa | 5281b6b | 2018-10-15 07:38:25 +0800 | [diff] [blame] | 5151 | r.activity.getDisplayId(), false /* movedToDifferentDisplay */); |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5152 | } |
| 5153 | |
| 5154 | /** |
| 5155 | * Updates the configuration for an Activity. The ActivityClientRecord's |
| 5156 | * {@link ActivityClientRecord#overrideConfig} is used to compute the final Configuration for |
| 5157 | * that Activity. {@link ActivityClientRecord#tmpConfig} is used as a temporary for delivering |
| 5158 | * the updated Configuration. |
| 5159 | * @param r ActivityClientRecord representing the Activity. |
| 5160 | * @param newBaseConfig The new configuration to use. This may be augmented with |
| 5161 | * {@link ActivityClientRecord#overrideConfig}. |
| 5162 | * @param displayId The id of the display where the Activity currently resides. |
| 5163 | * @param movedToDifferentDisplay Indicates if the activity was moved to different display. |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 5164 | * @return {@link Configuration} instance sent to client, null if not sent. |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5165 | */ |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 5166 | private Configuration performConfigurationChangedForActivity(ActivityClientRecord r, |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5167 | Configuration newBaseConfig, int displayId, boolean movedToDifferentDisplay) { |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 5168 | r.tmpConfig.setTo(newBaseConfig); |
| 5169 | if (r.overrideConfig != null) { |
| 5170 | r.tmpConfig.updateFrom(r.overrideConfig); |
| 5171 | } |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 5172 | final Configuration reportedConfig = performActivityConfigurationChanged(r.activity, |
| 5173 | r.tmpConfig, r.overrideConfig, displayId, movedToDifferentDisplay); |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 5174 | freeTextLayoutCachesIfNeeded(r.activity.mCurrentConfig.diff(r.tmpConfig)); |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 5175 | return reportedConfig; |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 5176 | } |
| 5177 | |
| 5178 | /** |
Adam Lesinski | c1b0ebf | 2016-06-09 11:17:10 -0700 | [diff] [blame] | 5179 | * Creates a new Configuration only if override would modify base. Otherwise returns base. |
| 5180 | * @param base The base configuration. |
| 5181 | * @param override The update to apply to the base configuration. Can be null. |
| 5182 | * @return A Configuration representing base with override applied. |
| 5183 | */ |
| 5184 | private static Configuration createNewConfigAndUpdateIfNotNull(@NonNull Configuration base, |
| 5185 | @Nullable Configuration override) { |
| 5186 | if (override == null) { |
| 5187 | return base; |
| 5188 | } |
| 5189 | Configuration newConfig = new Configuration(base); |
| 5190 | newConfig.updateFrom(override); |
| 5191 | return newConfig; |
| 5192 | } |
| 5193 | |
| 5194 | /** |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5195 | * 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] | 5196 | * @param cb The component callback to notify of configuration change. |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5197 | * @param newConfig The new configuration. |
| 5198 | */ |
| 5199 | private void performConfigurationChanged(ComponentCallbacks2 cb, Configuration newConfig) { |
| 5200 | if (!REPORT_TO_ACTIVITY) { |
| 5201 | return; |
| 5202 | } |
| 5203 | |
| 5204 | // ContextThemeWrappers may override the configuration for that context. We must check and |
| 5205 | // apply any overrides defined. |
| 5206 | Configuration contextThemeWrapperOverrideConfig = null; |
| 5207 | if (cb instanceof ContextThemeWrapper) { |
| 5208 | final ContextThemeWrapper contextThemeWrapper = (ContextThemeWrapper) cb; |
| 5209 | contextThemeWrapperOverrideConfig = contextThemeWrapper.getOverrideConfiguration(); |
| 5210 | } |
| 5211 | |
| 5212 | // Apply the ContextThemeWrapper override if necessary. |
| 5213 | // NOTE: Make sure the configurations are not modified, as they are treated as immutable |
| 5214 | // in many places. |
| 5215 | final Configuration configToReport = createNewConfigAndUpdateIfNotNull( |
| 5216 | newConfig, contextThemeWrapperOverrideConfig); |
| 5217 | cb.onConfigurationChanged(configToReport); |
| 5218 | } |
| 5219 | |
| 5220 | /** |
| 5221 | * Decides whether to update an Activity's configuration and whether to inform it. |
| 5222 | * @param activity The activity to notify of configuration change. |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 5223 | * @param newConfig The new configuration. |
Adam Lesinski | c1b0ebf | 2016-06-09 11:17:10 -0700 | [diff] [blame] | 5224 | * @param amOverrideConfig The override config that differentiates the Activity's configuration |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5225 | * from the base global configuration. This is supplied by |
| 5226 | * ActivityManager. |
| 5227 | * @param displayId Id of the display where activity currently resides. |
| 5228 | * @param movedToDifferentDisplay Indicates if the activity was moved to different display. |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 5229 | * @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] | 5230 | */ |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 5231 | private Configuration performActivityConfigurationChanged(Activity activity, |
| 5232 | Configuration newConfig, Configuration amOverrideConfig, int displayId, |
| 5233 | boolean movedToDifferentDisplay) { |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5234 | if (activity == null) { |
| 5235 | throw new IllegalArgumentException("No activity provided."); |
| 5236 | } |
| 5237 | final IBinder activityToken = activity.getActivityToken(); |
| 5238 | if (activityToken == null) { |
| 5239 | 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] | 5240 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 5241 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5242 | boolean shouldChangeConfig = false; |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5243 | if (activity.mCurrentConfig == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5244 | shouldChangeConfig = true; |
| 5245 | } else { |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5246 | // If the new config is the same as the config this Activity is already running with and |
| 5247 | // the override config also didn't change, then don't bother calling |
| 5248 | // onConfigurationChanged. |
Bryce Lee | 658d984 | 2017-07-28 08:33:36 -0700 | [diff] [blame] | 5249 | final int diff = activity.mCurrentConfig.diffPublicOnly(newConfig); |
| 5250 | |
Andrii Kulian | 3b3c914 | 2016-07-18 19:15:56 -0700 | [diff] [blame] | 5251 | if (diff != 0 || !mResourcesManager.isSameResourcesOverrideConfig(activityToken, |
| 5252 | amOverrideConfig)) { |
Chong Zhang | 4951f9d | 2016-06-23 13:15:08 -0700 | [diff] [blame] | 5253 | // Always send the task-level config changes. For system-level configuration, if |
| 5254 | // this activity doesn't handle any of the config changes, then don't bother |
| 5255 | // calling onConfigurationChanged as we're going to destroy it. |
| 5256 | if (!mUpdatingSystemConfig |
| 5257 | || (~activity.mActivityInfo.getRealConfigChanged() & diff) == 0 |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5258 | || !REPORT_TO_ACTIVITY) { |
Chong Zhang | 4951f9d | 2016-06-23 13:15:08 -0700 | [diff] [blame] | 5259 | shouldChangeConfig = true; |
| 5260 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5261 | } |
| 5262 | } |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5263 | if (!shouldChangeConfig && !movedToDifferentDisplay) { |
| 5264 | // Nothing significant, don't proceed with updating and reporting. |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 5265 | return null; |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5266 | } |
| 5267 | |
| 5268 | // Propagate the configuration change to ResourcesManager and Activity. |
| 5269 | |
| 5270 | // ContextThemeWrappers may override the configuration for that context. We must check and |
| 5271 | // apply any overrides defined. |
| 5272 | Configuration contextThemeWrapperOverrideConfig = activity.getOverrideConfiguration(); |
| 5273 | |
| 5274 | // We only update an Activity's configuration if this is not a global configuration change. |
| 5275 | // This must also be done before the callback, or else we violate the contract that the new |
| 5276 | // resources are available in ComponentCallbacks2#onConfigurationChanged(Configuration). |
| 5277 | // Also apply the ContextThemeWrapper override if necessary. |
| 5278 | // NOTE: Make sure the configurations are not modified, as they are treated as immutable in |
| 5279 | // many places. |
| 5280 | final Configuration finalOverrideConfig = createNewConfigAndUpdateIfNotNull( |
| 5281 | amOverrideConfig, contextThemeWrapperOverrideConfig); |
| 5282 | mResourcesManager.updateResourcesForActivity(activityToken, finalOverrideConfig, |
| 5283 | displayId, movedToDifferentDisplay); |
| 5284 | |
| 5285 | activity.mConfigChangeFlags = 0; |
| 5286 | activity.mCurrentConfig = new Configuration(newConfig); |
| 5287 | |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 5288 | // Apply the ContextThemeWrapper override if necessary. |
| 5289 | // NOTE: Make sure the configurations are not modified, as they are treated as immutable |
| 5290 | // in many places. |
| 5291 | final Configuration configToReport = createNewConfigAndUpdateIfNotNull(newConfig, |
| 5292 | contextThemeWrapperOverrideConfig); |
| 5293 | |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5294 | if (!REPORT_TO_ACTIVITY) { |
| 5295 | // Not configured to report to activity. |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 5296 | return configToReport; |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5297 | } |
| 5298 | |
| 5299 | if (movedToDifferentDisplay) { |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 5300 | activity.dispatchMovedToDisplay(displayId, configToReport); |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5301 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 5302 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5303 | if (shouldChangeConfig) { |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5304 | activity.mCalled = false; |
| 5305 | activity.onConfigurationChanged(configToReport); |
| 5306 | if (!activity.mCalled) { |
| 5307 | throw new SuperNotCalledException("Activity " + activity.getLocalClassName() + |
| 5308 | " did not call through to super.onConfigurationChanged()"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5309 | } |
| 5310 | } |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 5311 | |
| 5312 | return configToReport; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5313 | } |
| 5314 | |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 5315 | public final void applyConfigurationToResources(Configuration config) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 5316 | synchronized (mResourcesManager) { |
| 5317 | mResourcesManager.applyConfigurationToResourcesLocked(config, null); |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 5318 | } |
| 5319 | } |
| 5320 | |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 5321 | final Configuration applyCompatConfiguration(int displayDensity) { |
Dianne Hackborn | 836e262 | 2011-10-04 18:32:39 -0700 | [diff] [blame] | 5322 | Configuration config = mConfiguration; |
| 5323 | if (mCompatConfiguration == null) { |
| 5324 | mCompatConfiguration = new Configuration(); |
| 5325 | } |
| 5326 | mCompatConfiguration.setTo(mConfiguration); |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 5327 | if (mResourcesManager.applyCompatConfigurationLocked(displayDensity, |
| 5328 | mCompatConfiguration)) { |
Dianne Hackborn | 836e262 | 2011-10-04 18:32:39 -0700 | [diff] [blame] | 5329 | config = mCompatConfiguration; |
| 5330 | } |
| 5331 | return config; |
| 5332 | } |
| 5333 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 5334 | @Override |
| 5335 | public void handleConfigurationChanged(Configuration config) { |
| 5336 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "configChanged"); |
| 5337 | mCurDefaultDisplayDpi = config.densityDpi; |
| 5338 | mUpdatingSystemConfig = true; |
| 5339 | try { |
| 5340 | handleConfigurationChanged(config, null /* compat */); |
| 5341 | } finally { |
| 5342 | mUpdatingSystemConfig = false; |
| 5343 | } |
| 5344 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
| 5345 | } |
| 5346 | |
| 5347 | private void handleConfigurationChanged(Configuration config, CompatibilityInfo compat) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5348 | |
Fabrice Di Meglio | 30ca5cd | 2012-05-07 17:45:44 -0700 | [diff] [blame] | 5349 | int configDiff = 0; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5350 | |
Bryce Lee | 658d984 | 2017-07-28 08:33:36 -0700 | [diff] [blame] | 5351 | // This flag tracks whether the new configuration is fundamentally equivalent to the |
| 5352 | // existing configuration. This is necessary to determine whether non-activity |
| 5353 | // callbacks should receive notice when the only changes are related to non-public fields. |
| 5354 | // We do not gate calling {@link #performActivityConfigurationChanged} based on this flag |
| 5355 | // as that method uses the same check on the activity config override as well. |
| 5356 | final boolean equivalent = config != null && mConfiguration != null |
| 5357 | && (0 == mConfiguration.diffPublicOnly(config)); |
Todd Kennedy | 35a9a38 | 2018-01-25 13:25:37 -0800 | [diff] [blame] | 5358 | final Theme systemTheme = getSystemContext().getTheme(); |
| 5359 | final Theme systemUiTheme = getSystemUiContext().getTheme(); |
Bryce Lee | 658d984 | 2017-07-28 08:33:36 -0700 | [diff] [blame] | 5360 | |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 5361 | synchronized (mResourcesManager) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5362 | if (mPendingConfiguration != null) { |
| 5363 | if (!mPendingConfiguration.isOtherSeqNewer(config)) { |
| 5364 | config = mPendingConfiguration; |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 5365 | mCurDefaultDisplayDpi = config.densityDpi; |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 5366 | updateDefaultDensity(); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5367 | } |
| 5368 | mPendingConfiguration = null; |
| 5369 | } |
| 5370 | |
| 5371 | if (config == null) { |
| 5372 | return; |
| 5373 | } |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 5374 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 5375 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Handle configuration changed: " |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5376 | + config); |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 5377 | |
| 5378 | mResourcesManager.applyConfigurationToResourcesLocked(config, compat); |
Adam Lesinski | b61e405 | 2016-05-19 18:23:05 -0700 | [diff] [blame] | 5379 | updateLocaleListFromAppContext(mInitialApplication.getApplicationContext(), |
| 5380 | mResourcesManager.getConfiguration().getLocales()); |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 5381 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5382 | if (mConfiguration == null) { |
| 5383 | mConfiguration = new Configuration(); |
| 5384 | } |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 5385 | if (!mConfiguration.isOtherSeqNewer(config) && compat == null) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5386 | return; |
| 5387 | } |
Alan Viverette | e54d245 | 2015-05-06 10:41:43 -0700 | [diff] [blame] | 5388 | |
| 5389 | configDiff = mConfiguration.updateFrom(config); |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 5390 | config = applyCompatConfiguration(mCurDefaultDisplayDpi); |
Alan Viverette | 395cd01 | 2015-08-11 17:27:04 -0400 | [diff] [blame] | 5391 | |
Alan Viverette | 395cd01 | 2015-08-11 17:27:04 -0400 | [diff] [blame] | 5392 | if ((systemTheme.getChangingConfigurations() & configDiff) != 0) { |
| 5393 | systemTheme.rebase(); |
| 5394 | } |
Adam Lesinski | a82b626 | 2017-03-21 16:56:17 -0700 | [diff] [blame] | 5395 | |
Adam Lesinski | a82b626 | 2017-03-21 16:56:17 -0700 | [diff] [blame] | 5396 | if ((systemUiTheme.getChangingConfigurations() & configDiff) != 0) { |
| 5397 | systemUiTheme.rebase(); |
| 5398 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5399 | } |
Dianne Hackborn | 73c1416 | 2012-09-19 15:45:06 -0700 | [diff] [blame] | 5400 | |
| 5401 | ArrayList<ComponentCallbacks2> callbacks = collectComponentCallbacks(false, config); |
| 5402 | |
Fabrice Di Meglio | 30ca5cd | 2012-05-07 17:45:44 -0700 | [diff] [blame] | 5403 | freeTextLayoutCachesIfNeeded(configDiff); |
| 5404 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5405 | if (callbacks != null) { |
| 5406 | final int N = callbacks.size(); |
| 5407 | for (int i=0; i<N; i++) { |
Andrii Kulian | 701214b | 2016-04-07 09:36:33 -0700 | [diff] [blame] | 5408 | ComponentCallbacks2 cb = callbacks.get(i); |
| 5409 | if (cb instanceof Activity) { |
| 5410 | // If callback is an Activity - call corresponding method to consider override |
| 5411 | // config and avoid onConfigurationChanged if it hasn't changed. |
| 5412 | Activity a = (Activity) cb; |
| 5413 | performConfigurationChangedForActivity(mActivities.get(a.getActivityToken()), |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5414 | config); |
Bryce Lee | 658d984 | 2017-07-28 08:33:36 -0700 | [diff] [blame] | 5415 | } else if (!equivalent) { |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5416 | performConfigurationChanged(cb, config); |
Andrii Kulian | 701214b | 2016-04-07 09:36:33 -0700 | [diff] [blame] | 5417 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5418 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5419 | } |
| 5420 | } |
| 5421 | |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 5422 | void handleApplicationInfoChanged(@NonNull final ApplicationInfo ai) { |
Adam Lesinski | d33ef56 | 2017-01-19 14:49:59 -0800 | [diff] [blame] | 5423 | // Updates triggered by package installation go through a package update |
| 5424 | // receiver. Here we try to capture ApplicationInfo changes that are |
| 5425 | // caused by other sources, such as overlays. That means we want to be as conservative |
| 5426 | // about code changes as possible. Take the diff of the old ApplicationInfo and the new |
| 5427 | // to see if anything needs to change. |
Fyodor Kupolov | b7865ce | 2017-05-05 15:08:03 -0700 | [diff] [blame] | 5428 | LoadedApk apk; |
| 5429 | LoadedApk resApk; |
| 5430 | // Update all affected loaded packages with new package information |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 5431 | synchronized (mResourcesManager) { |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 5432 | WeakReference<LoadedApk> ref = mPackages.get(ai.packageName); |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 5433 | apk = ref != null ? ref.get() : null; |
Fyodor Kupolov | b7865ce | 2017-05-05 15:08:03 -0700 | [diff] [blame] | 5434 | ref = mResourcePackages.get(ai.packageName); |
| 5435 | resApk = ref != null ? ref.get() : null; |
| 5436 | } |
| 5437 | if (apk != null) { |
| 5438 | final ArrayList<String> oldPaths = new ArrayList<>(); |
| 5439 | LoadedApk.makePaths(this, apk.getApplicationInfo(), oldPaths); |
| 5440 | apk.updateApplicationInfo(ai, oldPaths); |
| 5441 | } |
| 5442 | if (resApk != null) { |
| 5443 | final ArrayList<String> oldPaths = new ArrayList<>(); |
| 5444 | LoadedApk.makePaths(this, resApk.getApplicationInfo(), oldPaths); |
| 5445 | resApk.updateApplicationInfo(ai, oldPaths); |
| 5446 | } |
| 5447 | synchronized (mResourcesManager) { |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 5448 | // Update all affected Resources objects to use new ResourcesImpl |
| 5449 | mResourcesManager.applyNewResourceDirsLocked(ai.sourceDir, ai.resourceDirs); |
| 5450 | } |
| 5451 | |
| 5452 | ApplicationPackageManager.configurationChanged(); |
| 5453 | |
| 5454 | // Trigger a regular Configuration change event, only with a different assetsSeq number |
| 5455 | // so that we actually call through to all components. |
Adam Lesinski | a82b626 | 2017-03-21 16:56:17 -0700 | [diff] [blame] | 5456 | // TODO(adamlesinski): Change this to make use of ActivityManager's upcoming ability to |
| 5457 | // store configurations per-process. |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 5458 | Configuration newConfig = new Configuration(); |
Adam Lesinski | a82b626 | 2017-03-21 16:56:17 -0700 | [diff] [blame] | 5459 | newConfig.assetsSeq = (mConfiguration != null ? mConfiguration.assetsSeq : 0) + 1; |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 5460 | handleConfigurationChanged(newConfig, null); |
| 5461 | |
Wale Ogunwale | 5527a50 | 2018-02-20 18:18:21 -0800 | [diff] [blame] | 5462 | relaunchAllActivities(); |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 5463 | } |
| 5464 | |
Romain Guy | 46bfc48 | 2013-08-16 18:38:29 -0700 | [diff] [blame] | 5465 | static void freeTextLayoutCachesIfNeeded(int configDiff) { |
Fabrice Di Meglio | 30ca5cd | 2012-05-07 17:45:44 -0700 | [diff] [blame] | 5466 | if (configDiff != 0) { |
| 5467 | // Ask text layout engine to free its caches if there is a locale change |
| 5468 | boolean hasLocaleConfigChange = ((configDiff & ActivityInfo.CONFIG_LOCALE) != 0); |
| 5469 | if (hasLocaleConfigChange) { |
| 5470 | Canvas.freeTextLayoutCaches(); |
| 5471 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Cleared TextLayout Caches"); |
| 5472 | } |
| 5473 | } |
| 5474 | } |
| 5475 | |
Garfield Tan | 0443b37 | 2019-01-04 15:00:13 -0800 | [diff] [blame] | 5476 | @Override |
| 5477 | public void updatePendingActivityConfiguration(IBinder activityToken, |
| 5478 | Configuration overrideConfig) { |
| 5479 | final ActivityClientRecord r; |
| 5480 | synchronized (mResourcesManager) { |
| 5481 | r = mActivities.get(activityToken); |
| 5482 | } |
| 5483 | |
| 5484 | if (r == null) { |
| 5485 | if (DEBUG_CONFIGURATION) { |
| 5486 | Slog.w(TAG, "Not found target activity to update its pending config."); |
| 5487 | } |
| 5488 | return; |
| 5489 | } |
| 5490 | |
| 5491 | synchronized (r) { |
| 5492 | r.mPendingOverrideConfig = overrideConfig; |
| 5493 | } |
| 5494 | } |
| 5495 | |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5496 | /** |
| 5497 | * Handle new activity configuration and/or move to a different display. |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 5498 | * @param activityToken Target activity token. |
| 5499 | * @param overrideConfig Activity override config. |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5500 | * @param displayId Id of the display where activity was moved to, -1 if there was no move and |
| 5501 | * value didn't change. |
| 5502 | */ |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 5503 | @Override |
| 5504 | public void handleActivityConfigurationChanged(IBinder activityToken, |
| 5505 | Configuration overrideConfig, int displayId) { |
| 5506 | ActivityClientRecord r = mActivities.get(activityToken); |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5507 | // Check input params. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5508 | if (r == null || r.activity == null) { |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5509 | 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] | 5510 | return; |
| 5511 | } |
Andrii Kulian | 51c1b67 | 2017-04-07 18:39:32 -0700 | [diff] [blame] | 5512 | final boolean movedToDifferentDisplay = displayId != INVALID_DISPLAY |
Yohei Yukawa | 5281b6b | 2018-10-15 07:38:25 +0800 | [diff] [blame] | 5513 | && displayId != r.activity.getDisplayId(); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 5514 | |
Garfield Tan | 0443b37 | 2019-01-04 15:00:13 -0800 | [diff] [blame] | 5515 | synchronized (r) { |
| 5516 | if (r.mPendingOverrideConfig != null |
| 5517 | && !r.mPendingOverrideConfig.isOtherSeqNewer(overrideConfig)) { |
| 5518 | overrideConfig = r.mPendingOverrideConfig; |
| 5519 | } |
| 5520 | r.mPendingOverrideConfig = null; |
| 5521 | } |
| 5522 | |
| 5523 | if (r.overrideConfig != null && !r.overrideConfig.isOtherSeqNewer(overrideConfig) |
| 5524 | && !movedToDifferentDisplay) { |
| 5525 | if (DEBUG_CONFIGURATION) { |
| 5526 | Slog.v(TAG, "Activity already handled newer configuration so drop this" |
| 5527 | + " transaction. overrideConfig=" + overrideConfig + " r.overrideConfig=" |
| 5528 | + r.overrideConfig); |
| 5529 | } |
| 5530 | return; |
| 5531 | } |
| 5532 | |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5533 | // Perform updates. |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 5534 | r.overrideConfig = overrideConfig; |
Stephen Kiazyk | f903b73 | 2017-03-20 16:23:45 -0700 | [diff] [blame] | 5535 | final ViewRootImpl viewRoot = r.activity.mDecor != null |
| 5536 | ? r.activity.mDecor.getViewRootImpl() : null; |
| 5537 | |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5538 | if (movedToDifferentDisplay) { |
| 5539 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Handle activity moved to display, activity:" |
| 5540 | + r.activityInfo.name + ", displayId=" + displayId |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 5541 | + ", config=" + overrideConfig); |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5542 | |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 5543 | final Configuration reportedConfig = performConfigurationChangedForActivity(r, |
| 5544 | mCompatConfiguration, displayId, true /* movedToDifferentDisplay */); |
Andrii Kulian | ce1ecf1 | 2017-03-17 14:58:36 -0700 | [diff] [blame] | 5545 | if (viewRoot != null) { |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 5546 | viewRoot.onMovedToDisplay(displayId, reportedConfig); |
Andrii Kulian | ce1ecf1 | 2017-03-17 14:58:36 -0700 | [diff] [blame] | 5547 | } |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5548 | } else { |
| 5549 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Handle activity config changed: " |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 5550 | + r.activityInfo.name + ", config=" + overrideConfig); |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5551 | performConfigurationChangedForActivity(r, mCompatConfiguration); |
| 5552 | } |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 5553 | // Notify the ViewRootImpl instance about configuration changes. It may have initiated this |
| 5554 | // update to make sure that resources are updated before updating itself. |
Andrii Kulian | ce1ecf1 | 2017-03-17 14:58:36 -0700 | [diff] [blame] | 5555 | if (viewRoot != null) { |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 5556 | viewRoot.updateConfiguration(displayId); |
Andrii Kulian | ce1ecf1 | 2017-03-17 14:58:36 -0700 | [diff] [blame] | 5557 | } |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 5558 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5559 | } |
| 5560 | |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 5561 | final void handleProfilerControl(boolean start, ProfilerInfo profilerInfo, int profileType) { |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 5562 | if (start) { |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 5563 | try { |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 5564 | switch (profileType) { |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 5565 | default: |
| 5566 | mProfiler.setProfiler(profilerInfo); |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 5567 | mProfiler.startProfiling(); |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 5568 | break; |
| 5569 | } |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 5570 | } catch (RuntimeException e) { |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 5571 | Slog.w(TAG, "Profiling failed on path " + profilerInfo.profileFile |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 5572 | + " -- can the process access this path?"); |
Dianne Hackborn | 9c8dd55 | 2009-06-23 19:22:52 -0700 | [diff] [blame] | 5573 | } finally { |
Andreas Gampe | 2b073a0 | 2017-06-22 17:28:57 -0700 | [diff] [blame] | 5574 | profilerInfo.closeFd(); |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 5575 | } |
| 5576 | } else { |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 5577 | switch (profileType) { |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 5578 | default: |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 5579 | mProfiler.stopProfiling(); |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 5580 | break; |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 5581 | } |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 5582 | } |
| 5583 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 5584 | |
Andreas Gampe | 4c79fea | 2016-01-28 20:11:41 -0800 | [diff] [blame] | 5585 | /** |
| 5586 | * Public entrypoint to stop profiling. This is required to end profiling when the app crashes, |
| 5587 | * so that profiler data won't be lost. |
| 5588 | * |
| 5589 | * @hide |
| 5590 | */ |
| 5591 | public void stopProfiling() { |
Amith Yamasani | b168443 | 2017-01-26 14:57:20 -0800 | [diff] [blame] | 5592 | if (mProfiler != null) { |
| 5593 | mProfiler.stopProfiling(); |
| 5594 | } |
Andreas Gampe | 4c79fea | 2016-01-28 20:11:41 -0800 | [diff] [blame] | 5595 | } |
| 5596 | |
Christopher Ferris | 8d652f8 | 2017-04-11 16:29:18 -0700 | [diff] [blame] | 5597 | static void handleDumpHeap(DumpHeapData dhd) { |
Makoto Onuki | 4556b7b | 2017-07-07 14:58:58 -0700 | [diff] [blame] | 5598 | if (dhd.runGc) { |
| 5599 | System.gc(); |
| 5600 | System.runFinalization(); |
| 5601 | System.gc(); |
| 5602 | } |
Christopher Ferris | 8d652f8 | 2017-04-11 16:29:18 -0700 | [diff] [blame] | 5603 | if (dhd.managed) { |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 5604 | try { |
| 5605 | Debug.dumpHprofData(dhd.path, dhd.fd.getFileDescriptor()); |
| 5606 | } catch (IOException e) { |
| 5607 | Slog.w(TAG, "Managed heap dump failed on path " + dhd.path |
| 5608 | + " -- can the process access this path?"); |
| 5609 | } finally { |
| 5610 | try { |
| 5611 | dhd.fd.close(); |
| 5612 | } catch (IOException e) { |
| 5613 | Slog.w(TAG, "Failure closing profile fd", e); |
| 5614 | } |
| 5615 | } |
Christopher Ferris | 8d652f8 | 2017-04-11 16:29:18 -0700 | [diff] [blame] | 5616 | } else if (dhd.mallocInfo) { |
| 5617 | Debug.dumpNativeMallocInfo(dhd.fd.getFileDescriptor()); |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 5618 | } else { |
Andy McFadden | 06a6b55 | 2010-07-13 16:28:09 -0700 | [diff] [blame] | 5619 | Debug.dumpNativeHeap(dhd.fd.getFileDescriptor()); |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 5620 | } |
Dianne Hackborn | b9a5e4a | 2015-03-03 17:04:12 -0800 | [diff] [blame] | 5621 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5622 | ActivityManager.getService().dumpHeapFinished(dhd.path); |
Dianne Hackborn | b9a5e4a | 2015-03-03 17:04:12 -0800 | [diff] [blame] | 5623 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5624 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | b9a5e4a | 2015-03-03 17:04:12 -0800 | [diff] [blame] | 5625 | } |
Makoto Onuki | 2c6657f | 2018-06-06 15:24:02 -0700 | [diff] [blame] | 5626 | if (dhd.finishCallback != null) { |
| 5627 | dhd.finishCallback.sendResult(null); |
| 5628 | } |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 5629 | } |
| 5630 | |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 5631 | final void handleDispatchPackageBroadcast(int cmd, String[] packages) { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5632 | boolean hasPkgInfo = false; |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5633 | switch (cmd) { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 5634 | case ApplicationThreadConstants.PACKAGE_REMOVED: |
| 5635 | case ApplicationThreadConstants.PACKAGE_REMOVED_DONT_KILL: |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5636 | { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 5637 | final boolean killApp = cmd == ApplicationThreadConstants.PACKAGE_REMOVED; |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5638 | if (packages == null) { |
| 5639 | break; |
| 5640 | } |
| 5641 | synchronized (mResourcesManager) { |
| 5642 | for (int i = packages.length - 1; i >= 0; i--) { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5643 | if (!hasPkgInfo) { |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5644 | WeakReference<LoadedApk> ref = mPackages.get(packages[i]); |
| 5645 | if (ref != null && ref.get() != null) { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5646 | hasPkgInfo = true; |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5647 | } else { |
| 5648 | ref = mResourcePackages.get(packages[i]); |
| 5649 | if (ref != null && ref.get() != null) { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5650 | hasPkgInfo = true; |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5651 | } |
| 5652 | } |
| 5653 | } |
| 5654 | if (killApp) { |
| 5655 | mPackages.remove(packages[i]); |
| 5656 | mResourcePackages.remove(packages[i]); |
| 5657 | } |
| 5658 | } |
| 5659 | } |
| 5660 | break; |
| 5661 | } |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 5662 | case ApplicationThreadConstants.PACKAGE_REPLACED: |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5663 | { |
| 5664 | if (packages == null) { |
| 5665 | break; |
| 5666 | } |
| 5667 | synchronized (mResourcesManager) { |
| 5668 | for (int i = packages.length - 1; i >= 0; i--) { |
| 5669 | WeakReference<LoadedApk> ref = mPackages.get(packages[i]); |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5670 | LoadedApk pkgInfo = ref != null ? ref.get() : null; |
| 5671 | if (pkgInfo != null) { |
| 5672 | hasPkgInfo = true; |
mark_chen | 89764e3 | 2014-12-12 15:38:48 +0800 | [diff] [blame] | 5673 | } else { |
| 5674 | ref = mResourcePackages.get(packages[i]); |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5675 | pkgInfo = ref != null ? ref.get() : null; |
| 5676 | if (pkgInfo != null) { |
| 5677 | hasPkgInfo = true; |
mark_chen | 89764e3 | 2014-12-12 15:38:48 +0800 | [diff] [blame] | 5678 | } |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 5679 | } |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5680 | // If the package is being replaced, yet it still has a valid |
| 5681 | // LoadedApk object, the package was updated with _DONT_KILL. |
| 5682 | // Adjust it's internal references to the application info and |
| 5683 | // resources. |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5684 | if (pkgInfo != null) { |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5685 | try { |
| 5686 | final String packageName = packages[i]; |
| 5687 | final ApplicationInfo aInfo = |
| 5688 | sPackageManager.getApplicationInfo( |
| 5689 | packageName, |
Svet Ganov | 6ce9239 | 2017-09-27 16:04:10 -0700 | [diff] [blame] | 5690 | PackageManager.GET_SHARED_LIBRARY_FILES, |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5691 | UserHandle.myUserId()); |
| 5692 | |
| 5693 | if (mActivities.size() > 0) { |
| 5694 | for (ActivityClientRecord ar : mActivities.values()) { |
| 5695 | if (ar.activityInfo.applicationInfo.packageName |
| 5696 | .equals(packageName)) { |
| 5697 | ar.activityInfo.applicationInfo = aInfo; |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5698 | ar.packageInfo = pkgInfo; |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5699 | } |
| 5700 | } |
| 5701 | } |
Todd Kennedy | b9656a9 | 2018-05-02 10:59:45 +0100 | [diff] [blame] | 5702 | final ArrayList<String> oldPaths = new ArrayList<>(); |
| 5703 | LoadedApk.makePaths(this, pkgInfo.getApplicationInfo(), oldPaths); |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5704 | pkgInfo.updateApplicationInfo(aInfo, oldPaths); |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5705 | } catch (RemoteException e) { |
| 5706 | } |
| 5707 | } |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 5708 | } |
| 5709 | } |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5710 | break; |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 5711 | } |
| 5712 | } |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5713 | ApplicationPackageManager.handlePackageBroadcast(cmd, packages, hasPkgInfo); |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 5714 | } |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 5715 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5716 | final void handleLowMemory() { |
Dianne Hackborn | 73c1416 | 2012-09-19 15:45:06 -0700 | [diff] [blame] | 5717 | ArrayList<ComponentCallbacks2> callbacks = collectComponentCallbacks(true, null); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 5718 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5719 | final int N = callbacks.size(); |
| 5720 | for (int i=0; i<N; i++) { |
| 5721 | callbacks.get(i).onLowMemory(); |
| 5722 | } |
| 5723 | |
Chris Tate | ce22905 | 2009-03-25 16:44:52 -0700 | [diff] [blame] | 5724 | // Ask SQLite to free up as much memory as it can, mostly from its page caches. |
| 5725 | if (Process.myUid() != Process.SYSTEM_UID) { |
| 5726 | int sqliteReleased = SQLiteDatabase.releaseMemory(); |
| 5727 | EventLog.writeEvent(SQLITE_MEM_RELEASED_EVENT_LOG_TAG, sqliteReleased); |
| 5728 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 5729 | |
Mike Reed | caf0df1 | 2009-04-27 14:32:05 -0400 | [diff] [blame] | 5730 | // Ask graphics to free up as much as possible (font/image caches) |
| 5731 | Canvas.freeCaches(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5732 | |
Fabrice Di Meglio | 30ca5cd | 2012-05-07 17:45:44 -0700 | [diff] [blame] | 5733 | // Ask text layout engine to free also as much as possible |
| 5734 | Canvas.freeTextLayoutCaches(); |
| 5735 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5736 | BinderInternal.forceGc("mem"); |
| 5737 | } |
| 5738 | |
Jorim Jaggi | b29e318 | 2018-04-30 18:51:56 +0200 | [diff] [blame] | 5739 | private void handleTrimMemory(int level) { |
| 5740 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "trimMemory"); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 5741 | if (DEBUG_MEMORY_TRIM) Slog.v(TAG, "Trimming memory to level: " + level); |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 5742 | |
Dianne Hackborn | 73c1416 | 2012-09-19 15:45:06 -0700 | [diff] [blame] | 5743 | ArrayList<ComponentCallbacks2> callbacks = collectComponentCallbacks(true, null); |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 5744 | |
| 5745 | final int N = callbacks.size(); |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 5746 | for (int i = 0; i < N; i++) { |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 5747 | callbacks.get(i).onTrimMemory(level); |
| 5748 | } |
Romain Guy | 19f86e8 | 2012-04-23 15:19:07 -0700 | [diff] [blame] | 5749 | |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 5750 | WindowManagerGlobal.getInstance().trimMemory(level); |
Jorim Jaggi | b29e318 | 2018-04-30 18:51:56 +0200 | [diff] [blame] | 5751 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 5752 | } |
| 5753 | |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 5754 | private void setupGraphicsSupport(Context context) { |
Andreas Gampe | 4c8e542 | 2016-05-18 11:58:47 -0700 | [diff] [blame] | 5755 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "setupGraphicsSupport"); |
Romain Guy | a958265 | 2011-11-10 14:20:10 -0800 | [diff] [blame] | 5756 | |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 5757 | // The system package doesn't have real data directories, so don't set up cache paths. |
| 5758 | if (!"android".equals(context.getPackageName())) { |
| 5759 | // This cache location probably points at credential-encrypted |
| 5760 | // storage which may not be accessible yet; assign it anyway instead |
| 5761 | // of pointing at device-encrypted storage. |
| 5762 | final File cacheDir = context.getCacheDir(); |
| 5763 | if (cacheDir != null) { |
| 5764 | // Provide a usable directory for temporary files |
| 5765 | System.setProperty("java.io.tmpdir", cacheDir.getAbsolutePath()); |
| 5766 | } else { |
| 5767 | Log.v(TAG, "Unable to initialize \"java.io.tmpdir\" property " |
| 5768 | + "due to missing cache directory"); |
Romain Guy | a958265 | 2011-11-10 14:20:10 -0800 | [diff] [blame] | 5769 | } |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 5770 | |
| 5771 | // Setup a location to store generated/compiled graphics code. |
| 5772 | final Context deviceContext = context.createDeviceProtectedStorageContext(); |
| 5773 | final File codeCacheDir = deviceContext.getCodeCacheDir(); |
| 5774 | if (codeCacheDir != null) { |
| 5775 | try { |
| 5776 | int uid = Process.myUid(); |
| 5777 | String[] packages = getPackageManager().getPackagesForUid(uid); |
| 5778 | if (packages != null) { |
John Reck | 8785ceb | 2018-10-29 16:45:58 -0700 | [diff] [blame] | 5779 | HardwareRenderer.setupDiskCache(codeCacheDir); |
Romain Guy | cecbe07 | 2017-07-18 15:42:06 -0700 | [diff] [blame] | 5780 | RenderScriptCacheDir.setupDiskCache(codeCacheDir); |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 5781 | } |
| 5782 | } catch (RemoteException e) { |
| 5783 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
| 5784 | throw e.rethrowFromSystemServer(); |
| 5785 | } |
| 5786 | } else { |
| 5787 | Log.w(TAG, "Unable to use shader/script cache: missing code-cache directory"); |
| 5788 | } |
Romain Guy | a958265 | 2011-11-10 14:20:10 -0800 | [diff] [blame] | 5789 | } |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 5790 | |
Cody Northrop | deb4328 | 2018-10-04 16:04:05 -0600 | [diff] [blame] | 5791 | GraphicsEnvironment.getInstance().setup(context, mCoreSettings); |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 5792 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 5793 | } |
| 5794 | |
| 5795 | private void updateDefaultDensity() { |
Alan Viverette | 2ac46f1 | 2016-02-04 16:58:14 -0500 | [diff] [blame] | 5796 | final int densityDpi = mCurDefaultDisplayDpi; |
| 5797 | if (!mDensityCompatMode |
| 5798 | && densityDpi != Configuration.DENSITY_DPI_UNDEFINED |
| 5799 | && densityDpi != DisplayMetrics.DENSITY_DEVICE) { |
| 5800 | DisplayMetrics.DENSITY_DEVICE = densityDpi; |
| 5801 | Bitmap.setDefaultDensity(densityDpi); |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 5802 | } |
| 5803 | } |
| 5804 | |
Todd Kennedy | e713efc | 2016-05-10 13:45:40 -0700 | [diff] [blame] | 5805 | /** |
| 5806 | * Returns the correct library directory for the current ABI. |
| 5807 | * <p> |
| 5808 | * If we're dealing with a multi-arch application that has both 32 and 64 bit shared |
| 5809 | * libraries, we might need to choose the secondary depending on what the current |
| 5810 | * runtime's instruction set is. |
| 5811 | */ |
| 5812 | private String getInstrumentationLibrary(ApplicationInfo appInfo, InstrumentationInfo insInfo) { |
Patrick Baumann | eb59580 | 2018-04-17 09:49:55 -0700 | [diff] [blame] | 5813 | if (appInfo.primaryCpuAbi != null && appInfo.secondaryCpuAbi != null |
| 5814 | && appInfo.secondaryCpuAbi.equals(insInfo.secondaryCpuAbi)) { |
Todd Kennedy | e713efc | 2016-05-10 13:45:40 -0700 | [diff] [blame] | 5815 | // Get the instruction set supported by the secondary ABI. In the presence |
| 5816 | // of a native bridge this might be different than the one secondary ABI used. |
| 5817 | String secondaryIsa = |
| 5818 | VMRuntime.getInstructionSet(appInfo.secondaryCpuAbi); |
| 5819 | final String secondaryDexCodeIsa = |
| 5820 | SystemProperties.get("ro.dalvik.vm.isa." + secondaryIsa); |
| 5821 | secondaryIsa = secondaryDexCodeIsa.isEmpty() ? secondaryIsa : secondaryDexCodeIsa; |
| 5822 | |
| 5823 | final String runtimeIsa = VMRuntime.getRuntime().vmInstructionSet(); |
| 5824 | if (runtimeIsa.equals(secondaryIsa)) { |
| 5825 | return insInfo.secondaryNativeLibraryDir; |
| 5826 | } |
| 5827 | } |
| 5828 | return insInfo.nativeLibraryDir; |
| 5829 | } |
| 5830 | |
Adam Lesinski | b61e405 | 2016-05-19 18:23:05 -0700 | [diff] [blame] | 5831 | /** |
| 5832 | * The LocaleList set for the app's resources may have been shuffled so that the preferred |
| 5833 | * Locale is at position 0. We must find the index of this preferred Locale in the |
| 5834 | * original LocaleList. |
| 5835 | */ |
| 5836 | private void updateLocaleListFromAppContext(Context context, LocaleList newLocaleList) { |
| 5837 | final Locale bestLocale = context.getResources().getConfiguration().getLocales().get(0); |
| 5838 | final int newLocaleListSize = newLocaleList.size(); |
| 5839 | for (int i = 0; i < newLocaleListSize; i++) { |
| 5840 | if (bestLocale.equals(newLocaleList.get(i))) { |
| 5841 | LocaleList.setDefault(newLocaleList, i); |
| 5842 | return; |
| 5843 | } |
| 5844 | } |
Adam Lesinski | 27d3016 | 2016-05-25 16:45:14 -0700 | [diff] [blame] | 5845 | |
| 5846 | // The app may have overridden the LocaleList with its own Locale |
| 5847 | // (not present in the available list). Push the chosen Locale |
| 5848 | // to the front of the list. |
| 5849 | LocaleList.setDefault(new LocaleList(bestLocale, newLocaleList)); |
Adam Lesinski | b61e405 | 2016-05-19 18:23:05 -0700 | [diff] [blame] | 5850 | } |
| 5851 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 5852 | @UnsupportedAppUsage |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 5853 | private void handleBindApplication(AppBindData data) { |
Calin Juravle | 8f5770d | 2016-04-12 14:12:04 +0100 | [diff] [blame] | 5854 | // Register the UI Thread as a sensitive thread to the runtime. |
| 5855 | VMRuntime.registerSensitiveThread(); |
Man Cao | cfa78b2 | 2015-06-11 20:14:34 -0700 | [diff] [blame] | 5856 | if (data.trackAllocation) { |
| 5857 | DdmVmInternal.enableRecentAllocations(true); |
| 5858 | } |
| 5859 | |
Dianne Hackborn | d98885c | 2016-03-01 17:13:03 -0800 | [diff] [blame] | 5860 | // Note when this process has started. |
| 5861 | Process.setStartTimes(SystemClock.elapsedRealtime(), SystemClock.uptimeMillis()); |
| 5862 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5863 | mBoundApplication = data; |
| 5864 | mConfiguration = new Configuration(data.config); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 5865 | mCompatConfiguration = new Configuration(data.config); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5866 | |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 5867 | mProfiler = new Profiler(); |
Andreas Gampe | ab8a63b | 2018-01-05 13:55:15 -0800 | [diff] [blame] | 5868 | String agent = null; |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 5869 | if (data.initProfilerInfo != null) { |
| 5870 | mProfiler.profileFile = data.initProfilerInfo.profileFile; |
| 5871 | mProfiler.profileFd = data.initProfilerInfo.profileFd; |
| 5872 | mProfiler.samplingInterval = data.initProfilerInfo.samplingInterval; |
| 5873 | mProfiler.autoStopProfiler = data.initProfilerInfo.autoStopProfiler; |
Shukang Zhou | 6ffd4f9 | 2017-01-25 16:07:57 -0800 | [diff] [blame] | 5874 | mProfiler.streamingOutput = data.initProfilerInfo.streamingOutput; |
Andreas Gampe | ab8a63b | 2018-01-05 13:55:15 -0800 | [diff] [blame] | 5875 | if (data.initProfilerInfo.attachAgentDuringBind) { |
| 5876 | agent = data.initProfilerInfo.agent; |
| 5877 | } |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 5878 | } |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 5879 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5880 | // send up app name; do this *before* waiting for debugger |
Christopher Tate | 8ee038d | 2009-11-06 11:30:20 -0800 | [diff] [blame] | 5881 | Process.setArgV0(data.processName); |
Siva Velusamy | d693dfa | 2012-09-10 14:36:58 -0700 | [diff] [blame] | 5882 | android.ddm.DdmHandleAppName.setAppName(data.processName, |
| 5883 | UserHandle.myUserId()); |
Mathew Inwood | 37b6ca8 | 2018-05-02 10:42:23 +0100 | [diff] [blame] | 5884 | VMRuntime.setProcessPackageName(data.appInfo.packageName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5885 | |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 5886 | if (mProfiler.profileFd != null) { |
| 5887 | mProfiler.startProfiling(); |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 5888 | } |
| 5889 | |
Joe Onorato | d630f10 | 2011-03-17 18:42:26 -0700 | [diff] [blame] | 5890 | // If the app is Honeycomb MR1 or earlier, switch its AsyncTask |
| 5891 | // implementation to use the pool executor. Normally, we use the |
| 5892 | // serialized executor as the default. This has to happen in the |
| 5893 | // main thread so the main looper is set right. |
Dianne Hackborn | 81e9276 | 2011-10-09 16:00:21 -0700 | [diff] [blame] | 5894 | if (data.appInfo.targetSdkVersion <= android.os.Build.VERSION_CODES.HONEYCOMB_MR1) { |
Joe Onorato | d630f10 | 2011-03-17 18:42:26 -0700 | [diff] [blame] | 5895 | AsyncTask.setDefaultExecutor(AsyncTask.THREAD_POOL_EXECUTOR); |
| 5896 | } |
| 5897 | |
Dianne Hackborn | 7895bc2 | 2014-09-05 15:09:03 -0700 | [diff] [blame] | 5898 | Message.updateCheckRecycle(data.appInfo.targetSdkVersion); |
| 5899 | |
Leon Scroggins III | 8290eab | 2018-03-19 10:51:44 -0400 | [diff] [blame] | 5900 | // Prior to P, internal calls to decode Bitmaps used BitmapFactory, |
| 5901 | // which may scale up to account for density. In P, we switched to |
| 5902 | // ImageDecoder, which skips the upscale to save memory. ImageDecoder |
| 5903 | // needs to still scale up in older apps, in case they rely on the |
| 5904 | // size of the Bitmap without considering its density. |
| 5905 | ImageDecoder.sApiLevel = data.appInfo.targetSdkVersion; |
| 5906 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5907 | /* |
| 5908 | * Before spawning a new process, reset the time zone to be the system time zone. |
| 5909 | * This needs to be done because the system time zone could have changed after the |
| 5910 | * the spawning of this process. Without doing this this process would have the incorrect |
| 5911 | * system time zone. |
| 5912 | */ |
| 5913 | TimeZone.setDefault(null); |
| 5914 | |
Adam Lesinski | b61e405 | 2016-05-19 18:23:05 -0700 | [diff] [blame] | 5915 | /* |
| 5916 | * Set the LocaleList. This may change once we create the App Context. |
| 5917 | */ |
| 5918 | LocaleList.setDefault(data.config.getLocales()); |
| 5919 | |
| 5920 | synchronized (mResourcesManager) { |
| 5921 | /* |
| 5922 | * Update the system configuration since its preloaded and might not |
| 5923 | * reflect configuration changes. The configuration object passed |
| 5924 | * in AppBindData can be safely assumed to be up to date |
| 5925 | */ |
| 5926 | mResourcesManager.applyConfigurationToResourcesLocked(data.config, data.compatInfo); |
| 5927 | mCurDefaultDisplayDpi = data.config.densityDpi; |
| 5928 | |
| 5929 | // This calls mResourcesManager so keep it within the synchronized block. |
| 5930 | applyCompatConfiguration(mCurDefaultDisplayDpi); |
| 5931 | } |
| 5932 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5933 | data.info = getPackageInfoNoCheck(data.appInfo, data.compatInfo); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5934 | |
Andreas Gampe | ab8a63b | 2018-01-05 13:55:15 -0800 | [diff] [blame] | 5935 | if (agent != null) { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5936 | handleAttachAgent(agent, data.info); |
Andreas Gampe | ab8a63b | 2018-01-05 13:55:15 -0800 | [diff] [blame] | 5937 | } |
| 5938 | |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 5939 | /** |
| 5940 | * Switch this process to density compatibility mode if needed. |
| 5941 | */ |
| 5942 | if ((data.appInfo.flags&ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES) |
| 5943 | == 0) { |
| 5944 | mDensityCompatMode = true; |
| 5945 | Bitmap.setDefaultDensity(DisplayMetrics.DENSITY_DEFAULT); |
| 5946 | } |
| 5947 | updateDefaultDensity(); |
| 5948 | |
Neil Fuller | c66ec40 | 2016-11-14 16:06:42 +0000 | [diff] [blame] | 5949 | final String use24HourSetting = mCoreSettings.getString(Settings.System.TIME_12_24); |
| 5950 | Boolean is24Hr = null; |
| 5951 | if (use24HourSetting != null) { |
| 5952 | is24Hr = "24".equals(use24HourSetting) ? Boolean.TRUE : Boolean.FALSE; |
| 5953 | } |
| 5954 | // null : use locale default for 12/24 hour formatting, |
| 5955 | // false : use 12 hour format, |
| 5956 | // true : use 24 hour format. |
Narayan Kamath | ccb2a086 | 2013-12-19 14:49:36 +0000 | [diff] [blame] | 5957 | DateFormat.set24HourTimePref(is24Hr); |
| 5958 | |
Aurimas Liutikas | 8f004c8 | 2019-01-17 17:20:10 -0800 | [diff] [blame] | 5959 | updateDebugViewAttributeState(); |
Jon Miranda | 836c0a8 | 2014-08-11 12:32:26 -0700 | [diff] [blame] | 5960 | |
Jeff Sharkey | 8918298 | 2017-11-01 19:02:56 -0600 | [diff] [blame] | 5961 | StrictMode.initThreadDefaults(data.appInfo); |
| 5962 | StrictMode.initVmDefaults(data.appInfo); |
Jeff Sharkey | 344744b | 2016-01-28 19:03:30 -0700 | [diff] [blame] | 5963 | |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 5964 | if (data.debugMode != ApplicationThreadConstants.DEBUG_OFF) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5965 | // XXX should have option to change the port. |
| 5966 | Debug.changeDebugPort(8100); |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 5967 | if (data.debugMode == ApplicationThreadConstants.DEBUG_WAIT) { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5968 | Slog.w(TAG, "Application " + data.info.getPackageName() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5969 | + " is waiting for the debugger on port 8100..."); |
| 5970 | |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5971 | IActivityManager mgr = ActivityManager.getService(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5972 | try { |
| 5973 | mgr.showWaitingForDebugger(mAppThread, true); |
| 5974 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5975 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5976 | } |
| 5977 | |
| 5978 | Debug.waitForDebugger(); |
| 5979 | |
| 5980 | try { |
| 5981 | mgr.showWaitingForDebugger(mAppThread, false); |
| 5982 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5983 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5984 | } |
| 5985 | |
| 5986 | } else { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5987 | Slog.w(TAG, "Application " + data.info.getPackageName() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5988 | + " can be debugged on port 8100..."); |
| 5989 | } |
| 5990 | } |
| 5991 | |
Chris Craik | ce03028 | 2018-10-16 14:33:11 -0700 | [diff] [blame] | 5992 | // Allow binder tracing, and application-generated systrace messages if we're profileable. |
| 5993 | boolean isAppProfileable = data.appInfo.isProfileableByShell(); |
| 5994 | Trace.setAppTracingAllowed(isAppProfileable); |
| 5995 | if (isAppProfileable && data.enableBinderTracking) { |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 5996 | Binder.enableTracing(); |
| 5997 | } |
Jamie Gennis | f9c7d6b | 2013-03-25 14:18:25 -0700 | [diff] [blame] | 5998 | |
Ryan Savitski | cfdc151 | 2018-12-14 16:20:52 +0000 | [diff] [blame] | 5999 | // Initialize heap profiling. |
| 6000 | if (isAppProfileable || Build.IS_DEBUGGABLE) { |
| 6001 | nInitZygoteChildHeapProfiling(); |
| 6002 | } |
| 6003 | |
Chris Craik | ce03028 | 2018-10-16 14:33:11 -0700 | [diff] [blame] | 6004 | // Allow renderer debugging features if we're debuggable. |
| 6005 | boolean isAppDebuggable = (data.appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0; |
John Reck | 8785ceb | 2018-10-29 16:45:58 -0700 | [diff] [blame] | 6006 | HardwareRenderer.setDebuggingEnabled(isAppDebuggable || Build.IS_DEBUGGABLE); |
| 6007 | HardwareRenderer.setPackageName(data.appInfo.packageName); |
Chris Craik | ce03028 | 2018-10-16 14:33:11 -0700 | [diff] [blame] | 6008 | |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 6009 | /** |
| 6010 | * Initialize the default http proxy in this process for the reasons we set the time zone. |
| 6011 | */ |
Andreas Gampe | 4c8e542 | 2016-05-18 11:58:47 -0700 | [diff] [blame] | 6012 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "Setup proxies"); |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 6013 | final IBinder b = ServiceManager.getService(Context.CONNECTIVITY_SERVICE); |
Dianne Hackborn | d4d32c5 | 2011-11-08 17:33:59 -0800 | [diff] [blame] | 6014 | if (b != null) { |
| 6015 | // In pre-boot mode (doing initial launch to collect password), not |
| 6016 | // all system is up. This includes the connectivity service, so don't |
| 6017 | // crash if we can't get it. |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 6018 | final IConnectivityManager service = IConnectivityManager.Stub.asInterface(b); |
Dianne Hackborn | d4d32c5 | 2011-11-08 17:33:59 -0800 | [diff] [blame] | 6019 | try { |
Irina Dumitrescu | 18622d3 | 2018-12-05 16:19:47 +0000 | [diff] [blame] | 6020 | Proxy.setHttpProxySystemProperty(service.getProxyForNetwork(null)); |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 6021 | } catch (RemoteException e) { |
Andreas Gampe | 4c8e542 | 2016-05-18 11:58:47 -0700 | [diff] [blame] | 6022 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 6023 | throw e.rethrowFromSystemServer(); |
| 6024 | } |
Dianne Hackborn | d4d32c5 | 2011-11-08 17:33:59 -0800 | [diff] [blame] | 6025 | } |
Andreas Gampe | 4c8e542 | 2016-05-18 11:58:47 -0700 | [diff] [blame] | 6026 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 6027 | |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 6028 | // Instrumentation info affects the class loader, so load it before |
| 6029 | // setting up the app context. |
| 6030 | final InstrumentationInfo ii; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6031 | if (data.instrumentationName != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6032 | try { |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 6033 | ii = new ApplicationPackageManager(null, getPackageManager()) |
| 6034 | .getInstrumentationInfo(data.instrumentationName, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6035 | } catch (PackageManager.NameNotFoundException e) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6036 | throw new RuntimeException( |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 6037 | "Unable to find instrumentation info for: " + data.instrumentationName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6038 | } |
| 6039 | |
Patrick Baumann | eb59580 | 2018-04-17 09:49:55 -0700 | [diff] [blame] | 6040 | // Warn of potential ABI mismatches. |
| 6041 | if (!Objects.equals(data.appInfo.primaryCpuAbi, ii.primaryCpuAbi) |
| 6042 | || !Objects.equals(data.appInfo.secondaryCpuAbi, ii.secondaryCpuAbi)) { |
| 6043 | Slog.w(TAG, "Package uses different ABI(s) than its instrumentation: " |
| 6044 | + "package[" + data.appInfo.packageName + "]: " |
| 6045 | + data.appInfo.primaryCpuAbi + ", " + data.appInfo.secondaryCpuAbi |
| 6046 | + " instrumentation[" + ii.packageName + "]: " |
| 6047 | + ii.primaryCpuAbi + ", " + ii.secondaryCpuAbi); |
| 6048 | } |
| 6049 | |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 6050 | mInstrumentationPackageName = ii.packageName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6051 | mInstrumentationAppDir = ii.sourceDir; |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 6052 | mInstrumentationSplitAppDirs = ii.splitSourceDirs; |
Todd Kennedy | e713efc | 2016-05-10 13:45:40 -0700 | [diff] [blame] | 6053 | mInstrumentationLibDir = getInstrumentationLibrary(data.appInfo, ii); |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 6054 | mInstrumentedAppDir = data.info.getAppDir(); |
| 6055 | mInstrumentedSplitAppDirs = data.info.getSplitAppDirs(); |
| 6056 | mInstrumentedLibDir = data.info.getLibDir(); |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 6057 | } else { |
| 6058 | ii = null; |
| 6059 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6060 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 6061 | final ContextImpl appContext = ContextImpl.createAppContext(this, data.info); |
Adam Lesinski | b61e405 | 2016-05-19 18:23:05 -0700 | [diff] [blame] | 6062 | updateLocaleListFromAppContext(appContext, |
| 6063 | mResourcesManager.getConfiguration().getLocales()); |
Seigo Nonaka | c14dd78 | 2016-03-30 23:09:16 +0900 | [diff] [blame] | 6064 | |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 6065 | if (!Process.isIsolated()) { |
Jeff Sharkey | 8918298 | 2017-11-01 19:02:56 -0600 | [diff] [blame] | 6066 | final int oldMask = StrictMode.allowThreadDiskWritesMask(); |
| 6067 | try { |
| 6068 | setupGraphicsSupport(appContext); |
| 6069 | } finally { |
| 6070 | StrictMode.setThreadPolicyMask(oldMask); |
| 6071 | } |
John Reck | 5642847 | 2018-03-16 17:27:17 -0700 | [diff] [blame] | 6072 | } else { |
John Reck | 8785ceb | 2018-10-29 16:45:58 -0700 | [diff] [blame] | 6073 | HardwareRenderer.setIsolatedProcess(true); |
Michael Lentine | 2ba303f | 2016-02-01 20:44:34 -0600 | [diff] [blame] | 6074 | } |
Michael Lentine | 03d8f768 | 2016-01-31 15:37:11 -0600 | [diff] [blame] | 6075 | |
Chad Brubaker | 78d4712 | 2015-11-17 22:26:58 -0800 | [diff] [blame] | 6076 | // Install the Network Security Config Provider. This must happen before the application |
| 6077 | // code is loaded to prevent issues with instances of TLS objects being created before |
| 6078 | // the provider is installed. |
Andreas Gampe | 4c8e542 | 2016-05-18 11:58:47 -0700 | [diff] [blame] | 6079 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "NetworkSecurityConfigProvider.install"); |
Chad Brubaker | 276ee96 | 2016-06-08 12:57:46 -0700 | [diff] [blame] | 6080 | NetworkSecurityConfigProvider.install(appContext); |
Andreas Gampe | 4c8e542 | 2016-05-18 11:58:47 -0700 | [diff] [blame] | 6081 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Chad Brubaker | 78d4712 | 2015-11-17 22:26:58 -0800 | [diff] [blame] | 6082 | |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 6083 | // Continue loading instrumentation. |
| 6084 | if (ii != null) { |
Dianne Hackborn | f4ef6eb | 2017-12-07 13:57:21 -0800 | [diff] [blame] | 6085 | ApplicationInfo instrApp; |
| 6086 | try { |
| 6087 | instrApp = getPackageManager().getApplicationInfo(ii.packageName, 0, |
| 6088 | UserHandle.myUserId()); |
| 6089 | } catch (RemoteException e) { |
| 6090 | instrApp = null; |
| 6091 | } |
| 6092 | if (instrApp == null) { |
| 6093 | instrApp = new ApplicationInfo(); |
| 6094 | } |
Jeff Sharkey | 1544779 | 2015-11-05 16:18:51 -0800 | [diff] [blame] | 6095 | ii.copyTo(instrApp); |
Fyodor Kupolov | af38b8e | 2015-12-02 16:16:07 -0800 | [diff] [blame] | 6096 | instrApp.initForUser(UserHandle.myUserId()); |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 6097 | final LoadedApk pi = getPackageInfo(instrApp, data.compatInfo, |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 6098 | appContext.getClassLoader(), false, true, false); |
Makoto Onuki | 4becc35 | 2019-01-30 13:30:41 -0800 | [diff] [blame] | 6099 | |
| 6100 | // The test context's op package name == the target app's op package name, because |
| 6101 | // the app ops manager checks the op package name against the real calling UID, |
| 6102 | // which is what the target package name is associated with. |
| 6103 | final ContextImpl instrContext = ContextImpl.createAppContext(this, pi, |
| 6104 | appContext.getOpPackageName()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6105 | |
| 6106 | try { |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 6107 | final ClassLoader cl = instrContext.getClassLoader(); |
Dan Sandler | 07fe63e | 2017-08-15 16:41:11 -0400 | [diff] [blame] | 6108 | mInstrumentation = (Instrumentation) |
| 6109 | cl.loadClass(data.instrumentationName.getClassName()).newInstance(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6110 | } catch (Exception e) { |
| 6111 | throw new RuntimeException( |
| 6112 | "Unable to instantiate instrumentation " |
| 6113 | + data.instrumentationName + ": " + e.toString(), e); |
| 6114 | } |
| 6115 | |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 6116 | final ComponentName component = new ComponentName(ii.packageName, ii.name); |
| 6117 | mInstrumentation.init(this, instrContext, appContext, component, |
| 6118 | data.instrumentationWatcher, data.instrumentationUiAutomationConnection); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6119 | |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 6120 | if (mProfiler.profileFile != null && !ii.handleProfiling |
| 6121 | && mProfiler.profileFd == null) { |
| 6122 | mProfiler.handlingProfiling = true; |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 6123 | final File file = new File(mProfiler.profileFile); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6124 | file.getParentFile().mkdirs(); |
| 6125 | Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024); |
| 6126 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6127 | } else { |
| 6128 | mInstrumentation = new Instrumentation(); |
Jason Monk | a80bfb5 | 2017-11-16 17:15:37 -0500 | [diff] [blame] | 6129 | mInstrumentation.basicInit(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6130 | } |
| 6131 | |
Dianne Hackborn | 3b81bc1 | 2011-01-15 11:50:52 -0800 | [diff] [blame] | 6132 | if ((data.appInfo.flags&ApplicationInfo.FLAG_LARGE_HEAP) != 0) { |
Dianne Hackborn | de39851 | 2011-01-18 18:45:21 -0800 | [diff] [blame] | 6133 | dalvik.system.VMRuntime.getRuntime().clearGrowthLimit(); |
Mathieu Chartier | 24cee07 | 2015-01-08 14:42:20 -0800 | [diff] [blame] | 6134 | } else { |
| 6135 | // Small heap, clamp to the current growth limit and let the heap release |
| 6136 | // pages after the growth limit to the non growth limit capacity. b/18387825 |
| 6137 | dalvik.system.VMRuntime.getRuntime().clampGrowthLimit(); |
Dianne Hackborn | 3b81bc1 | 2011-01-15 11:50:52 -0800 | [diff] [blame] | 6138 | } |
| 6139 | |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 6140 | // Allow disk access during application and provider setup. This could |
Jeff Sharkey | 7c50167 | 2012-02-28 12:08:37 -0800 | [diff] [blame] | 6141 | // block processing ordered broadcasts, but later processing would |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 6142 | // probably end up doing the same disk access. |
Kurt Nelson | 5e15436 | 2017-06-29 17:20:56 -0700 | [diff] [blame] | 6143 | Application app; |
Jeff Sharkey | 7c50167 | 2012-02-28 12:08:37 -0800 | [diff] [blame] | 6144 | final StrictMode.ThreadPolicy savedPolicy = StrictMode.allowThreadDiskWrites(); |
Kurt Nelson | 571c3f6 | 2017-07-10 11:09:04 -0700 | [diff] [blame] | 6145 | final StrictMode.ThreadPolicy writesAllowedPolicy = StrictMode.getThreadPolicy(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6146 | try { |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 6147 | // If the app is being launched for full backup or restore, bring it up in |
| 6148 | // a restricted environment with the base application class. |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 6149 | app = data.info.makeApplication(data.restrictedBackupMode, null); |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 6150 | |
| 6151 | // Propagate autofill compat state |
Felipe Leme | a4f39cd | 2019-02-19 15:08:59 -0800 | [diff] [blame] | 6152 | app.setAutofillOptions(data.autofillOptions); |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 6153 | |
Felipe Leme | 326f15a | 2019-02-19 09:42:24 -0800 | [diff] [blame] | 6154 | // Propagate Content Capture options |
| 6155 | app.setContentCaptureOptions(data.contentCaptureOptions); |
| 6156 | |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 6157 | mInitialApplication = app; |
Jeff Sharkey | 7c50167 | 2012-02-28 12:08:37 -0800 | [diff] [blame] | 6158 | |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 6159 | // don't bring up providers in restricted mode; they may depend on the |
| 6160 | // app's custom Application class |
| 6161 | if (!data.restrictedBackupMode) { |
Jeff Sharkey | 3e19589 | 2016-03-05 19:48:59 -0700 | [diff] [blame] | 6162 | if (!ArrayUtils.isEmpty(data.providers)) { |
| 6163 | installContentProviders(app, data.providers); |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 6164 | } |
| 6165 | } |
| 6166 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6167 | // Do this after providers, since instrumentation tests generally start their |
| 6168 | // test thread at this point, and we don't want that racing. |
| 6169 | try { |
| 6170 | mInstrumentation.onCreate(data.instrumentationArgs); |
| 6171 | } |
| 6172 | catch (Exception e) { |
| 6173 | throw new RuntimeException( |
| 6174 | "Exception thrown in onCreate() of " |
| 6175 | + data.instrumentationName + ": " + e.toString(), e); |
| 6176 | } |
Kurt Nelson | 571c3f6 | 2017-07-10 11:09:04 -0700 | [diff] [blame] | 6177 | try { |
| 6178 | mInstrumentation.callApplicationOnCreate(app); |
| 6179 | } catch (Exception e) { |
| 6180 | if (!mInstrumentation.onException(app, e)) { |
| 6181 | throw new RuntimeException( |
| 6182 | "Unable to create application " + app.getClass().getName() |
| 6183 | + ": " + e.toString(), e); |
| 6184 | } |
| 6185 | } |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 6186 | } finally { |
Kurt Nelson | 571c3f6 | 2017-07-10 11:09:04 -0700 | [diff] [blame] | 6187 | // If the app targets < O-MR1, or doesn't change the thread policy |
| 6188 | // during startup, clobber the policy to maintain behavior of b/36951662 |
Jeff Sharkey | aa1a911 | 2018-04-10 15:18:12 -0600 | [diff] [blame] | 6189 | if (data.appInfo.targetSdkVersion < Build.VERSION_CODES.O_MR1 |
Kurt Nelson | 571c3f6 | 2017-07-10 11:09:04 -0700 | [diff] [blame] | 6190 | || StrictMode.getThreadPolicy().equals(writesAllowedPolicy)) { |
| 6191 | StrictMode.setThreadPolicy(savedPolicy); |
Kurt Nelson | 5e15436 | 2017-06-29 17:20:56 -0700 | [diff] [blame] | 6192 | } |
| 6193 | } |
| 6194 | |
Clara Bayarri | 4b5a4d2 | 2017-01-27 20:15:45 +0000 | [diff] [blame] | 6195 | // Preload fonts resources |
Seigo Nonaka | 54084b6 | 2017-04-24 14:46:23 -0700 | [diff] [blame] | 6196 | FontsContract.setApplicationContextForResources(appContext); |
Torne (Richard Coles) | 85ecae5 | 2018-01-30 18:13:00 -0500 | [diff] [blame] | 6197 | if (!Process.isIsolated()) { |
| 6198 | try { |
| 6199 | final ApplicationInfo info = |
| 6200 | getPackageManager().getApplicationInfo( |
| 6201 | data.appInfo.packageName, |
| 6202 | PackageManager.GET_META_DATA /*flags*/, |
| 6203 | UserHandle.myUserId()); |
| 6204 | if (info.metaData != null) { |
| 6205 | final int preloadedFontsResource = info.metaData.getInt( |
| 6206 | ApplicationInfo.METADATA_PRELOADED_FONTS, 0); |
| 6207 | if (preloadedFontsResource != 0) { |
| 6208 | data.info.getResources().preloadFonts(preloadedFontsResource); |
| 6209 | } |
Clara Bayarri | 4b5a4d2 | 2017-01-27 20:15:45 +0000 | [diff] [blame] | 6210 | } |
Torne (Richard Coles) | 85ecae5 | 2018-01-30 18:13:00 -0500 | [diff] [blame] | 6211 | } catch (RemoteException e) { |
| 6212 | throw e.rethrowFromSystemServer(); |
Clara Bayarri | 4b5a4d2 | 2017-01-27 20:15:45 +0000 | [diff] [blame] | 6213 | } |
Clara Bayarri | 4b5a4d2 | 2017-01-27 20:15:45 +0000 | [diff] [blame] | 6214 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6215 | } |
| 6216 | |
| 6217 | /*package*/ final void finishInstrumentation(int resultCode, Bundle results) { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6218 | IActivityManager am = ActivityManager.getService(); |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 6219 | if (mProfiler.profileFile != null && mProfiler.handlingProfiling |
| 6220 | && mProfiler.profileFd == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6221 | Debug.stopMethodTracing(); |
| 6222 | } |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6223 | //Slog.i(TAG, "am: " + ActivityManager.getService() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6224 | // + ", app thr: " + mAppThread); |
| 6225 | try { |
| 6226 | am.finishInstrumentation(mAppThread, resultCode, results); |
| 6227 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 6228 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6229 | } |
| 6230 | } |
| 6231 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 6232 | @UnsupportedAppUsage |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 6233 | private void installContentProviders( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6234 | Context context, List<ProviderInfo> providers) { |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 6235 | final ArrayList<ContentProviderHolder> results = new ArrayList<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6236 | |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 6237 | for (ProviderInfo cpi : providers) { |
Dianne Hackborn | 40e9f29 | 2012-11-27 19:12:23 -0800 | [diff] [blame] | 6238 | if (DEBUG_PROVIDER) { |
| 6239 | StringBuilder buf = new StringBuilder(128); |
| 6240 | buf.append("Pub "); |
| 6241 | buf.append(cpi.authority); |
| 6242 | buf.append(": "); |
| 6243 | buf.append(cpi.name); |
| 6244 | Log.i(TAG, buf.toString()); |
| 6245 | } |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 6246 | ContentProviderHolder cph = installProvider(context, null, cpi, |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6247 | false /*noisy*/, true /*noReleaseNeeded*/, true /*stable*/); |
| 6248 | if (cph != null) { |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6249 | cph.noReleaseNeeded = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6250 | results.add(cph); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6251 | } |
| 6252 | } |
| 6253 | |
| 6254 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6255 | ActivityManager.getService().publishContentProviders( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6256 | getApplicationThread(), results); |
| 6257 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 6258 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6259 | } |
| 6260 | } |
| 6261 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 6262 | @UnsupportedAppUsage |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 6263 | public final IContentProvider acquireProvider( |
| 6264 | Context c, String auth, int userId, boolean stable) { |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 6265 | final IContentProvider provider = acquireExistingProvider(c, auth, userId, stable); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6266 | if (provider != null) { |
| 6267 | return provider; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6268 | } |
| 6269 | |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 6270 | // There is a possible race here. Another thread may try to acquire |
| 6271 | // the same provider at the same time. When this happens, we want to ensure |
| 6272 | // that the first one wins. |
| 6273 | // Note that we cannot hold the lock while acquiring and installing the |
| 6274 | // provider since it might take a long time to run and it could also potentially |
| 6275 | // 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] | 6276 | ContentProviderHolder holder = null; |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 6277 | try { |
Makoto Onuki | b6c79ea | 2018-05-31 11:03:56 -0700 | [diff] [blame] | 6278 | synchronized (getGetProviderLock(auth, userId)) { |
| 6279 | holder = ActivityManager.getService().getContentProvider( |
Dianne Hackborn | 24bbe58 | 2018-12-17 11:58:31 -0800 | [diff] [blame] | 6280 | getApplicationThread(), c.getOpPackageName(), auth, userId, stable); |
Makoto Onuki | b6c79ea | 2018-05-31 11:03:56 -0700 | [diff] [blame] | 6281 | } |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 6282 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 6283 | throw ex.rethrowFromSystemServer(); |
Wale Ogunwale | 67fe0a4 | 2015-04-24 14:44:54 -0700 | [diff] [blame] | 6284 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6285 | if (holder == null) { |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 6286 | 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] | 6287 | return null; |
| 6288 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6289 | |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6290 | // Install provider will increment the reference count for us, and break |
| 6291 | // any ties in the race. |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6292 | holder = installProvider(c, holder, holder.info, |
| 6293 | true /*noisy*/, holder.noReleaseNeeded, stable); |
| 6294 | return holder.provider; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6295 | } |
| 6296 | |
Makoto Onuki | b6c79ea | 2018-05-31 11:03:56 -0700 | [diff] [blame] | 6297 | private Object getGetProviderLock(String auth, int userId) { |
| 6298 | final ProviderKey key = new ProviderKey(auth, userId); |
| 6299 | synchronized (mGetProviderLocks) { |
| 6300 | Object lock = mGetProviderLocks.get(key); |
| 6301 | if (lock == null) { |
| 6302 | lock = key; |
| 6303 | mGetProviderLocks.put(key, lock); |
| 6304 | } |
| 6305 | return lock; |
| 6306 | } |
| 6307 | } |
| 6308 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6309 | private final void incProviderRefLocked(ProviderRefCount prc, boolean stable) { |
| 6310 | if (stable) { |
| 6311 | prc.stableCount += 1; |
| 6312 | if (prc.stableCount == 1) { |
| 6313 | // We are acquiring a new stable reference on the provider. |
| 6314 | int unstableDelta; |
| 6315 | if (prc.removePending) { |
| 6316 | // We have a pending remove operation, which is holding the |
| 6317 | // last unstable reference. At this point we are converting |
| 6318 | // that unstable reference to our new stable reference. |
| 6319 | unstableDelta = -1; |
| 6320 | // Cancel the removal of the provider. |
| 6321 | if (DEBUG_PROVIDER) { |
| 6322 | Slog.v(TAG, "incProviderRef: stable " |
| 6323 | + "snatched provider from the jaws of death"); |
| 6324 | } |
| 6325 | prc.removePending = false; |
Guobin Zhang | 9e3e5266 | 2013-03-21 13:57:11 +0800 | [diff] [blame] | 6326 | // There is a race! It fails to remove the message, which |
| 6327 | // will be handled in completeRemoveProvider(). |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6328 | mH.removeMessages(H.REMOVE_PROVIDER, prc); |
| 6329 | } else { |
| 6330 | unstableDelta = 0; |
| 6331 | } |
| 6332 | try { |
| 6333 | if (DEBUG_PROVIDER) { |
| 6334 | Slog.v(TAG, "incProviderRef Now stable - " |
| 6335 | + prc.holder.info.name + ": unstableDelta=" |
| 6336 | + unstableDelta); |
| 6337 | } |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6338 | ActivityManager.getService().refContentProvider( |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6339 | prc.holder.connection, 1, unstableDelta); |
| 6340 | } catch (RemoteException e) { |
| 6341 | //do nothing content provider object is dead any way |
| 6342 | } |
| 6343 | } |
| 6344 | } else { |
| 6345 | prc.unstableCount += 1; |
| 6346 | if (prc.unstableCount == 1) { |
| 6347 | // We are acquiring a new unstable reference on the provider. |
| 6348 | if (prc.removePending) { |
| 6349 | // Oh look, we actually have a remove pending for the |
| 6350 | // provider, which is still holding the last unstable |
| 6351 | // reference. We just need to cancel that to take new |
| 6352 | // ownership of the reference. |
| 6353 | if (DEBUG_PROVIDER) { |
| 6354 | Slog.v(TAG, "incProviderRef: unstable " |
| 6355 | + "snatched provider from the jaws of death"); |
| 6356 | } |
| 6357 | prc.removePending = false; |
| 6358 | mH.removeMessages(H.REMOVE_PROVIDER, prc); |
| 6359 | } else { |
| 6360 | // First unstable ref, increment our count in the |
| 6361 | // activity manager. |
| 6362 | try { |
| 6363 | if (DEBUG_PROVIDER) { |
| 6364 | Slog.v(TAG, "incProviderRef: Now unstable - " |
| 6365 | + prc.holder.info.name); |
| 6366 | } |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6367 | ActivityManager.getService().refContentProvider( |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6368 | prc.holder.connection, 0, 1); |
| 6369 | } catch (RemoteException e) { |
| 6370 | //do nothing content provider object is dead any way |
| 6371 | } |
| 6372 | } |
| 6373 | } |
| 6374 | } |
| 6375 | } |
| 6376 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 6377 | @UnsupportedAppUsage |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 6378 | public final IContentProvider acquireExistingProvider( |
| 6379 | Context c, String auth, int userId, boolean stable) { |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6380 | synchronized (mProviderMap) { |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 6381 | final ProviderKey key = new ProviderKey(auth, userId); |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 6382 | final ProviderClientRecord pr = mProviderMap.get(key); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6383 | if (pr == null) { |
| 6384 | return null; |
| 6385 | } |
| 6386 | |
| 6387 | IContentProvider provider = pr.mProvider; |
| 6388 | IBinder jBinder = provider.asBinder(); |
Dianne Hackborn | c428aae | 2012-10-03 16:38:22 -0700 | [diff] [blame] | 6389 | if (!jBinder.isBinderAlive()) { |
| 6390 | // The hosting process of the provider has died; we can't |
| 6391 | // use this one. |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 6392 | Log.i(TAG, "Acquiring provider " + auth + " for user " + userId |
Dianne Hackborn | c428aae | 2012-10-03 16:38:22 -0700 | [diff] [blame] | 6393 | + ": existing object's process dead"); |
| 6394 | handleUnstableProviderDiedLocked(jBinder, true); |
| 6395 | return null; |
| 6396 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6397 | |
| 6398 | // Only increment the ref count if we have one. If we don't then the |
| 6399 | // provider is not reference counted and never needs to be released. |
Dianne Hackborn | cca1f0e | 2010-09-26 18:34:53 -0700 | [diff] [blame] | 6400 | ProviderRefCount prc = mProviderRefCountMap.get(jBinder); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6401 | if (prc != null) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6402 | incProviderRefLocked(prc, stable); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6403 | } |
| 6404 | return provider; |
| 6405 | } |
Dianne Hackborn | cca1f0e | 2010-09-26 18:34:53 -0700 | [diff] [blame] | 6406 | } |
| 6407 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 6408 | @UnsupportedAppUsage |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6409 | public final boolean releaseProvider(IContentProvider provider, boolean stable) { |
| 6410 | if (provider == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6411 | return false; |
| 6412 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6413 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6414 | IBinder jBinder = provider.asBinder(); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6415 | synchronized (mProviderMap) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6416 | ProviderRefCount prc = mProviderRefCountMap.get(jBinder); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6417 | if (prc == null) { |
| 6418 | // 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] | 6419 | return false; |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6420 | } |
| 6421 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6422 | boolean lastRef = false; |
| 6423 | if (stable) { |
| 6424 | if (prc.stableCount == 0) { |
| 6425 | if (DEBUG_PROVIDER) Slog.v(TAG, |
| 6426 | "releaseProvider: stable ref count already 0, how?"); |
| 6427 | return false; |
| 6428 | } |
| 6429 | prc.stableCount -= 1; |
| 6430 | if (prc.stableCount == 0) { |
| 6431 | // What we do at this point depends on whether there are |
| 6432 | // any unstable refs left: if there are, we just tell the |
| 6433 | // activity manager to decrement its stable count; if there |
| 6434 | // aren't, we need to enqueue this provider to be removed, |
| 6435 | // and convert to holding a single unstable ref while |
| 6436 | // doing so. |
| 6437 | lastRef = prc.unstableCount == 0; |
| 6438 | try { |
| 6439 | if (DEBUG_PROVIDER) { |
| 6440 | Slog.v(TAG, "releaseProvider: No longer stable w/lastRef=" |
| 6441 | + lastRef + " - " + prc.holder.info.name); |
| 6442 | } |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6443 | ActivityManager.getService().refContentProvider( |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6444 | prc.holder.connection, -1, lastRef ? 1 : 0); |
| 6445 | } catch (RemoteException e) { |
| 6446 | //do nothing content provider object is dead any way |
| 6447 | } |
| 6448 | } |
| 6449 | } else { |
| 6450 | if (prc.unstableCount == 0) { |
| 6451 | if (DEBUG_PROVIDER) Slog.v(TAG, |
| 6452 | "releaseProvider: unstable ref count already 0, how?"); |
| 6453 | return false; |
| 6454 | } |
| 6455 | prc.unstableCount -= 1; |
| 6456 | if (prc.unstableCount == 0) { |
| 6457 | // If this is the last reference, we need to enqueue |
| 6458 | // this provider to be removed instead of telling the |
| 6459 | // activity manager to remove it at this point. |
| 6460 | lastRef = prc.stableCount == 0; |
| 6461 | if (!lastRef) { |
| 6462 | try { |
| 6463 | if (DEBUG_PROVIDER) { |
| 6464 | Slog.v(TAG, "releaseProvider: No longer unstable - " |
| 6465 | + prc.holder.info.name); |
| 6466 | } |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6467 | ActivityManager.getService().refContentProvider( |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6468 | prc.holder.connection, 0, -1); |
| 6469 | } catch (RemoteException e) { |
| 6470 | //do nothing content provider object is dead any way |
| 6471 | } |
| 6472 | } |
| 6473 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6474 | } |
| 6475 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6476 | if (lastRef) { |
| 6477 | if (!prc.removePending) { |
| 6478 | // Schedule the actual remove asynchronously, since we don't know the context |
| 6479 | // this will be called in. |
| 6480 | // TODO: it would be nice to post a delayed message, so |
| 6481 | // if we come back and need the same provider quickly |
| 6482 | // we will still have it available. |
| 6483 | if (DEBUG_PROVIDER) { |
| 6484 | Slog.v(TAG, "releaseProvider: Enqueueing pending removal - " |
| 6485 | + prc.holder.info.name); |
| 6486 | } |
| 6487 | prc.removePending = true; |
| 6488 | Message msg = mH.obtainMessage(H.REMOVE_PROVIDER, prc); |
| 6489 | mH.sendMessage(msg); |
| 6490 | } else { |
| 6491 | Slog.w(TAG, "Duplicate remove pending of provider " + prc.holder.info.name); |
| 6492 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6493 | } |
| 6494 | return true; |
| 6495 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6496 | } |
| 6497 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6498 | final void completeRemoveProvider(ProviderRefCount prc) { |
| 6499 | synchronized (mProviderMap) { |
| 6500 | if (!prc.removePending) { |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6501 | // There was a race! Some other client managed to acquire |
| 6502 | // the provider before the removal was completed. |
| 6503 | // Abort the removal. We will do it later. |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6504 | if (DEBUG_PROVIDER) Slog.v(TAG, "completeRemoveProvider: lost the race, " |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6505 | + "provider still in use"); |
| 6506 | return; |
| 6507 | } |
| 6508 | |
Guobin Zhang | 9e3e5266 | 2013-03-21 13:57:11 +0800 | [diff] [blame] | 6509 | // More complicated race!! Some client managed to acquire the |
| 6510 | // provider and release it before the removal was completed. |
| 6511 | // Continue the removal, and abort the next remove message. |
| 6512 | prc.removePending = false; |
| 6513 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6514 | final IBinder jBinder = prc.holder.provider.asBinder(); |
| 6515 | ProviderRefCount existingPrc = mProviderRefCountMap.get(jBinder); |
| 6516 | if (existingPrc == prc) { |
| 6517 | mProviderRefCountMap.remove(jBinder); |
| 6518 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6519 | |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 6520 | for (int i=mProviderMap.size()-1; i>=0; i--) { |
| 6521 | ProviderClientRecord pr = mProviderMap.valueAt(i); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6522 | IBinder myBinder = pr.mProvider.asBinder(); |
| 6523 | if (myBinder == jBinder) { |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 6524 | mProviderMap.removeAt(i); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6525 | } |
| 6526 | } |
| 6527 | } |
| 6528 | |
| 6529 | try { |
| 6530 | if (DEBUG_PROVIDER) { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6531 | Slog.v(TAG, "removeProvider: Invoking ActivityManagerService." |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6532 | + "removeContentProvider(" + prc.holder.info.name + ")"); |
| 6533 | } |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6534 | ActivityManager.getService().removeContentProvider( |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6535 | prc.holder.connection, false); |
| 6536 | } catch (RemoteException e) { |
| 6537 | //do nothing content provider object is dead any way |
| 6538 | } |
| 6539 | } |
| 6540 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 6541 | @UnsupportedAppUsage |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6542 | final void handleUnstableProviderDied(IBinder provider, boolean fromClient) { |
Dianne Hackborn | c428aae | 2012-10-03 16:38:22 -0700 | [diff] [blame] | 6543 | synchronized (mProviderMap) { |
| 6544 | handleUnstableProviderDiedLocked(provider, fromClient); |
| 6545 | } |
| 6546 | } |
| 6547 | |
| 6548 | final void handleUnstableProviderDiedLocked(IBinder provider, boolean fromClient) { |
| 6549 | ProviderRefCount prc = mProviderRefCountMap.get(provider); |
| 6550 | if (prc != null) { |
| 6551 | if (DEBUG_PROVIDER) Slog.v(TAG, "Cleaning up dead provider " |
| 6552 | + provider + " " + prc.holder.info.name); |
| 6553 | mProviderRefCountMap.remove(provider); |
You Kim | bc74de6 | 2013-10-01 00:13:26 +0900 | [diff] [blame] | 6554 | for (int i=mProviderMap.size()-1; i>=0; i--) { |
| 6555 | ProviderClientRecord pr = mProviderMap.valueAt(i); |
| 6556 | if (pr != null && pr.mProvider.asBinder() == provider) { |
| 6557 | Slog.i(TAG, "Removing dead content provider:" + pr.mProvider.toString()); |
| 6558 | mProviderMap.removeAt(i); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6559 | } |
Dianne Hackborn | c428aae | 2012-10-03 16:38:22 -0700 | [diff] [blame] | 6560 | } |
You Kim | bc74de6 | 2013-10-01 00:13:26 +0900 | [diff] [blame] | 6561 | |
Dianne Hackborn | c428aae | 2012-10-03 16:38:22 -0700 | [diff] [blame] | 6562 | if (fromClient) { |
| 6563 | // We found out about this due to execution in our client |
| 6564 | // code. Tell the activity manager about it now, to ensure |
| 6565 | // that the next time we go to do anything with the provider |
| 6566 | // it knows it is dead (so we don't race with its death |
| 6567 | // notification). |
| 6568 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6569 | ActivityManager.getService().unstableProviderDied( |
Dianne Hackborn | c428aae | 2012-10-03 16:38:22 -0700 | [diff] [blame] | 6570 | prc.holder.connection); |
| 6571 | } catch (RemoteException e) { |
| 6572 | //do nothing content provider object is dead any way |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6573 | } |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 6574 | } |
| 6575 | } |
| 6576 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6577 | |
Jeff Sharkey | 7aa7601 | 2013-09-30 14:26:27 -0700 | [diff] [blame] | 6578 | final void appNotRespondingViaProvider(IBinder provider) { |
| 6579 | synchronized (mProviderMap) { |
| 6580 | ProviderRefCount prc = mProviderRefCountMap.get(provider); |
| 6581 | if (prc != null) { |
| 6582 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6583 | ActivityManager.getService() |
Jeff Sharkey | 7aa7601 | 2013-09-30 14:26:27 -0700 | [diff] [blame] | 6584 | .appNotRespondingViaProvider(prc.holder.connection); |
| 6585 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 6586 | throw e.rethrowFromSystemServer(); |
Jeff Sharkey | 7aa7601 | 2013-09-30 14:26:27 -0700 | [diff] [blame] | 6587 | } |
| 6588 | } |
| 6589 | } |
| 6590 | } |
| 6591 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6592 | private ProviderClientRecord installProviderAuthoritiesLocked(IContentProvider provider, |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 6593 | ContentProvider localProvider, ContentProviderHolder holder) { |
Andreas Gampe | 18e99c1 | 2015-03-06 15:29:06 -0800 | [diff] [blame] | 6594 | final String auths[] = holder.info.authority.split(";"); |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 6595 | final int userId = UserHandle.getUserId(holder.info.applicationInfo.uid); |
| 6596 | |
Jeff Sharkey | 0a17db1 | 2016-11-04 11:23:46 -0600 | [diff] [blame] | 6597 | if (provider != null) { |
| 6598 | // If this provider is hosted by the core OS and cannot be upgraded, |
| 6599 | // then I guess we're okay doing blocking calls to it. |
| 6600 | for (String auth : auths) { |
| 6601 | switch (auth) { |
| 6602 | case ContactsContract.AUTHORITY: |
| 6603 | case CallLog.AUTHORITY: |
| 6604 | case CallLog.SHADOW_AUTHORITY: |
| 6605 | case BlockedNumberContract.AUTHORITY: |
| 6606 | case CalendarContract.AUTHORITY: |
| 6607 | case Downloads.Impl.AUTHORITY: |
Jeff Sharkey | cb62162 | 2016-11-11 14:04:32 -0700 | [diff] [blame] | 6608 | case "telephony": |
Jeff Sharkey | 0a17db1 | 2016-11-04 11:23:46 -0600 | [diff] [blame] | 6609 | Binder.allowBlocking(provider.asBinder()); |
| 6610 | } |
| 6611 | } |
| 6612 | } |
| 6613 | |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 6614 | final ProviderClientRecord pcr = new ProviderClientRecord( |
| 6615 | auths, provider, localProvider, holder); |
| 6616 | for (String auth : auths) { |
| 6617 | final ProviderKey key = new ProviderKey(auth, userId); |
| 6618 | final ProviderClientRecord existing = mProviderMap.get(key); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6619 | if (existing != null) { |
| 6620 | Slog.w(TAG, "Content provider " + pcr.mHolder.info.name |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 6621 | + " already published as " + auth); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6622 | } else { |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 6623 | mProviderMap.put(key, pcr); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6624 | } |
| 6625 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6626 | return pcr; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6627 | } |
| 6628 | |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6629 | /** |
| 6630 | * Installs the provider. |
| 6631 | * |
| 6632 | * Providers that are local to the process or that come from the system server |
| 6633 | * may be installed permanently which is indicated by setting noReleaseNeeded to true. |
| 6634 | * Other remote providers are reference counted. The initial reference count |
| 6635 | * for all reference counted providers is one. Providers that are not reference |
| 6636 | * counted do not have a reference count (at all). |
| 6637 | * |
| 6638 | * This method detects when a provider has already been installed. When this happens, |
| 6639 | * it increments the reference count of the existing provider (if appropriate) |
| 6640 | * and returns the existing provider. This can happen due to concurrent |
| 6641 | * attempts to acquire the same provider. |
| 6642 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 6643 | @UnsupportedAppUsage |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 6644 | private ContentProviderHolder installProvider(Context context, |
| 6645 | ContentProviderHolder holder, ProviderInfo info, |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6646 | boolean noisy, boolean noReleaseNeeded, boolean stable) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6647 | ContentProvider localProvider = null; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6648 | IContentProvider provider; |
Dianne Hackborn | 5f48fca | 2012-05-30 11:06:31 -0700 | [diff] [blame] | 6649 | if (holder == null || holder.provider == null) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6650 | if (DEBUG_PROVIDER || noisy) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 6651 | Slog.d(TAG, "Loading provider " + info.authority + ": " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6652 | + info.name); |
| 6653 | } |
| 6654 | Context c = null; |
| 6655 | ApplicationInfo ai = info.applicationInfo; |
| 6656 | if (context.getPackageName().equals(ai.packageName)) { |
| 6657 | c = context; |
| 6658 | } else if (mInitialApplication != null && |
| 6659 | mInitialApplication.getPackageName().equals(ai.packageName)) { |
| 6660 | c = mInitialApplication; |
| 6661 | } else { |
| 6662 | try { |
| 6663 | c = context.createPackageContext(ai.packageName, |
| 6664 | Context.CONTEXT_INCLUDE_CODE); |
| 6665 | } catch (PackageManager.NameNotFoundException e) { |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 6666 | // Ignore |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6667 | } |
| 6668 | } |
| 6669 | if (c == null) { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 6670 | Slog.w(TAG, "Unable to get context for package " + |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6671 | ai.packageName + |
| 6672 | " while loading content provider " + |
| 6673 | info.name); |
| 6674 | return null; |
| 6675 | } |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 6676 | |
| 6677 | if (info.splitName != null) { |
| 6678 | try { |
| 6679 | c = c.createContextForSplit(info.splitName); |
| 6680 | } catch (NameNotFoundException e) { |
| 6681 | throw new RuntimeException(e); |
| 6682 | } |
| 6683 | } |
| 6684 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6685 | try { |
| 6686 | final java.lang.ClassLoader cl = c.getClassLoader(); |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 6687 | LoadedApk packageInfo = peekPackageInfo(ai.packageName, true); |
| 6688 | if (packageInfo == null) { |
Jason Monk | a80bfb5 | 2017-11-16 17:15:37 -0500 | [diff] [blame] | 6689 | // System startup case. |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 6690 | packageInfo = getSystemContext().mPackageInfo; |
Jason Monk | a80bfb5 | 2017-11-16 17:15:37 -0500 | [diff] [blame] | 6691 | } |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 6692 | localProvider = packageInfo.getAppFactory() |
Jason Monk | a80bfb5 | 2017-11-16 17:15:37 -0500 | [diff] [blame] | 6693 | .instantiateProvider(cl, info.name); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6694 | provider = localProvider.getIContentProvider(); |
| 6695 | if (provider == null) { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 6696 | Slog.e(TAG, "Failed to instantiate class " + |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6697 | info.name + " from sourceDir " + |
| 6698 | info.applicationInfo.sourceDir); |
| 6699 | return null; |
| 6700 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6701 | if (DEBUG_PROVIDER) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6702 | TAG, "Instantiating local provider " + info.name); |
| 6703 | // XXX Need to create the correct context for this provider. |
| 6704 | localProvider.attachInfo(c, info); |
| 6705 | } catch (java.lang.Exception e) { |
| 6706 | if (!mInstrumentation.onException(null, e)) { |
| 6707 | throw new RuntimeException( |
| 6708 | "Unable to get provider " + info.name |
| 6709 | + ": " + e.toString(), e); |
| 6710 | } |
| 6711 | return null; |
| 6712 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6713 | } else { |
| 6714 | provider = holder.provider; |
| 6715 | 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] | 6716 | + info.name); |
| 6717 | } |
| 6718 | |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 6719 | ContentProviderHolder retHolder; |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6720 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6721 | synchronized (mProviderMap) { |
| 6722 | if (DEBUG_PROVIDER) Slog.v(TAG, "Checking to add " + provider |
| 6723 | + " / " + info.name); |
| 6724 | IBinder jBinder = provider.asBinder(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6725 | if (localProvider != null) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6726 | ComponentName cname = new ComponentName(info.packageName, info.name); |
| 6727 | ProviderClientRecord pr = mLocalProvidersByName.get(cname); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6728 | if (pr != null) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6729 | if (DEBUG_PROVIDER) { |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6730 | Slog.v(TAG, "installProvider: lost the race, " |
| 6731 | + "using existing local provider"); |
| 6732 | } |
| 6733 | provider = pr.mProvider; |
| 6734 | } else { |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 6735 | holder = new ContentProviderHolder(info); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6736 | holder.provider = provider; |
| 6737 | holder.noReleaseNeeded = true; |
| 6738 | pr = installProviderAuthoritiesLocked(provider, localProvider, holder); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6739 | mLocalProviders.put(jBinder, pr); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6740 | mLocalProvidersByName.put(cname, pr); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6741 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6742 | retHolder = pr.mHolder; |
| 6743 | } else { |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6744 | ProviderRefCount prc = mProviderRefCountMap.get(jBinder); |
| 6745 | if (prc != null) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6746 | if (DEBUG_PROVIDER) { |
| 6747 | Slog.v(TAG, "installProvider: lost the race, updating ref count"); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6748 | } |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 6749 | // We need to transfer our new reference to the existing |
| 6750 | // ref count, releasing the old one... but only if |
| 6751 | // release is needed (that is, it is not running in the |
| 6752 | // system process). |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6753 | if (!noReleaseNeeded) { |
| 6754 | incProviderRefLocked(prc, stable); |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 6755 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6756 | ActivityManager.getService().removeContentProvider( |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 6757 | holder.connection, stable); |
| 6758 | } catch (RemoteException e) { |
| 6759 | //do nothing content provider object is dead any way |
| 6760 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6761 | } |
| 6762 | } else { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6763 | ProviderClientRecord client = installProviderAuthoritiesLocked( |
| 6764 | provider, localProvider, holder); |
| 6765 | if (noReleaseNeeded) { |
| 6766 | prc = new ProviderRefCount(holder, client, 1000, 1000); |
| 6767 | } else { |
| 6768 | prc = stable |
| 6769 | ? new ProviderRefCount(holder, client, 1, 0) |
| 6770 | : new ProviderRefCount(holder, client, 0, 1); |
| 6771 | } |
| 6772 | mProviderRefCountMap.put(jBinder, prc); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6773 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6774 | retHolder = prc.holder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6775 | } |
| 6776 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6777 | return retHolder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6778 | } |
| 6779 | |
Torne (Richard Coles) | 466cbe4 | 2017-05-31 14:09:14 -0400 | [diff] [blame] | 6780 | private void handleRunIsolatedEntryPoint(String entryPoint, String[] entryPointArgs) { |
| 6781 | try { |
| 6782 | Method main = Class.forName(entryPoint).getMethod("main", String[].class); |
| 6783 | main.invoke(null, new Object[]{entryPointArgs}); |
| 6784 | } catch (ReflectiveOperationException e) { |
| 6785 | throw new AndroidRuntimeException("runIsolatedEntryPoint failed", e); |
| 6786 | } |
| 6787 | // The process will be empty after this method returns; exit the VM now. |
| 6788 | System.exit(0); |
| 6789 | } |
| 6790 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 6791 | @UnsupportedAppUsage |
Sudheer Shanka | f669010 | 2017-10-16 10:20:32 -0700 | [diff] [blame] | 6792 | private void attach(boolean system, long startSeq) { |
Jeff Sharkey | 66a017b | 2013-01-17 18:18:22 -0800 | [diff] [blame] | 6793 | sCurrentActivityThread = this; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6794 | mSystemThread = system; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6795 | if (!system) { |
Siva Velusamy | d693dfa | 2012-09-10 14:36:58 -0700 | [diff] [blame] | 6796 | android.ddm.DdmHandleAppName.setAppName("<pre-initialized>", |
| 6797 | UserHandle.myUserId()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6798 | RuntimeInit.setApplicationObject(mAppThread.asBinder()); |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6799 | final IActivityManager mgr = ActivityManager.getService(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6800 | try { |
Sudheer Shanka | f669010 | 2017-10-16 10:20:32 -0700 | [diff] [blame] | 6801 | mgr.attachApplication(mAppThread, startSeq); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6802 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 6803 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6804 | } |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 6805 | // Watch for getting close to heap limit. |
| 6806 | BinderInternal.addGcWatcher(new Runnable() { |
| 6807 | @Override public void run() { |
| 6808 | if (!mSomeActivitiesChanged) { |
| 6809 | return; |
| 6810 | } |
| 6811 | Runtime runtime = Runtime.getRuntime(); |
| 6812 | long dalvikMax = runtime.maxMemory(); |
| 6813 | long dalvikUsed = runtime.totalMemory() - runtime.freeMemory(); |
| 6814 | if (dalvikUsed > ((3*dalvikMax)/4)) { |
| 6815 | if (DEBUG_MEMORY_TRIM) Slog.d(TAG, "Dalvik max=" + (dalvikMax/1024) |
| 6816 | + " total=" + (runtime.totalMemory()/1024) |
| 6817 | + " used=" + (dalvikUsed/1024)); |
| 6818 | mSomeActivitiesChanged = false; |
| 6819 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 6820 | ActivityTaskManager.getService().releaseSomeActivities(mAppThread); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 6821 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 6822 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 6823 | } |
| 6824 | } |
| 6825 | } |
| 6826 | }); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6827 | } else { |
| 6828 | // Don't set application object here -- if the system crashes, |
| 6829 | // 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] | 6830 | android.ddm.DdmHandleAppName.setAppName("system_process", |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 6831 | UserHandle.myUserId()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6832 | try { |
| 6833 | mInstrumentation = new Instrumentation(); |
Jason Monk | a80bfb5 | 2017-11-16 17:15:37 -0500 | [diff] [blame] | 6834 | mInstrumentation.basicInit(this); |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 6835 | ContextImpl context = ContextImpl.createAppContext( |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 6836 | this, getSystemContext().mPackageInfo); |
| 6837 | mInitialApplication = context.mPackageInfo.makeApplication(true, null); |
Jeff Brown | 7fc8e35 | 2014-09-16 18:06:47 -0700 | [diff] [blame] | 6838 | mInitialApplication.onCreate(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6839 | } catch (Exception e) { |
| 6840 | throw new RuntimeException( |
| 6841 | "Unable to instantiate Application():" + e.toString(), e); |
| 6842 | } |
| 6843 | } |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 6844 | |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 6845 | ViewRootImpl.ConfigChangedCallback configChangedCallback |
| 6846 | = (Configuration globalConfig) -> { |
| 6847 | synchronized (mResourcesManager) { |
| 6848 | // We need to apply this change to the resources immediately, because upon returning |
| 6849 | // the view hierarchy will be informed about it. |
| 6850 | if (mResourcesManager.applyConfigurationToResourcesLocked(globalConfig, |
| 6851 | null /* compat */)) { |
| 6852 | updateLocaleListFromAppContext(mInitialApplication.getApplicationContext(), |
| 6853 | mResourcesManager.getConfiguration().getLocales()); |
Adam Lesinski | b61e405 | 2016-05-19 18:23:05 -0700 | [diff] [blame] | 6854 | |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 6855 | // This actually changed the resources! Tell everyone about it. |
| 6856 | if (mPendingConfiguration == null |
| 6857 | || mPendingConfiguration.isOtherSeqNewer(globalConfig)) { |
| 6858 | mPendingConfiguration = globalConfig; |
| 6859 | sendMessage(H.CONFIGURATION_CHANGED, globalConfig); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6860 | } |
| 6861 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6862 | } |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 6863 | }; |
| 6864 | ViewRootImpl.addConfigCallback(configChangedCallback); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6865 | } |
| 6866 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 6867 | @UnsupportedAppUsage |
Romain Guy | 5e9120d | 2012-01-30 12:17:22 -0800 | [diff] [blame] | 6868 | public static ActivityThread systemMain() { |
Alan Viverette | 5e1565e | 2014-07-29 16:14:25 -0700 | [diff] [blame] | 6869 | // The system process on low-memory devices do not get to use hardware |
| 6870 | // accelerated drawing, since this can add too much overhead to the |
| 6871 | // process. |
| 6872 | if (!ActivityManager.isHighEndGfx()) { |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 6873 | ThreadedRenderer.disable(true); |
John Reck | 73840ea | 2014-09-22 07:39:18 -0700 | [diff] [blame] | 6874 | } else { |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 6875 | ThreadedRenderer.enableForegroundTrimming(); |
Alan Viverette | 5e1565e | 2014-07-29 16:14:25 -0700 | [diff] [blame] | 6876 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6877 | ActivityThread thread = new ActivityThread(); |
Sudheer Shanka | f669010 | 2017-10-16 10:20:32 -0700 | [diff] [blame] | 6878 | thread.attach(true, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6879 | return thread; |
| 6880 | } |
| 6881 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 6882 | @UnsupportedAppUsage |
Jeff Brown | 10e8971 | 2011-07-08 18:52:57 -0700 | [diff] [blame] | 6883 | public final void installSystemProviders(List<ProviderInfo> providers) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6884 | if (providers != null) { |
Jeff Brown | 10e8971 | 2011-07-08 18:52:57 -0700 | [diff] [blame] | 6885 | installContentProviders(mInitialApplication, providers); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6886 | } |
| 6887 | } |
| 6888 | |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 6889 | public int getIntCoreSetting(String key, int defaultValue) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 6890 | synchronized (mResourcesManager) { |
Svetoslav Ganov | 9aa597e | 2011-03-03 18:17:41 -0800 | [diff] [blame] | 6891 | if (mCoreSettings != null) { |
| 6892 | return mCoreSettings.getInt(key, defaultValue); |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 6893 | } |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 6894 | return defaultValue; |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 6895 | } |
| 6896 | } |
| 6897 | |
Jeff Sharkey | bc2ae00 | 2018-07-31 10:45:37 -0600 | [diff] [blame] | 6898 | private static class AndroidOs extends ForwardingOs { |
| 6899 | /** |
| 6900 | * Install selective syscall interception. For example, this is used to |
| 6901 | * implement special filesystem paths that will be redirected to |
| 6902 | * {@link ContentResolver#openFileDescriptor(Uri, String)}. |
| 6903 | */ |
| 6904 | public static void install() { |
| 6905 | // If feature is disabled, we don't need to install |
| 6906 | if (!DEPRECATE_DATA_COLUMNS) return; |
| 6907 | |
| 6908 | // If app is modern enough, we don't need to install |
| 6909 | if (VMRuntime.getRuntime().getTargetSdkVersion() >= Build.VERSION_CODES.Q) return; |
| 6910 | |
| 6911 | // Install interception and make sure it sticks! |
| 6912 | Os def = null; |
| 6913 | do { |
| 6914 | def = Os.getDefault(); |
| 6915 | } while (!Os.compareAndSetDefault(def, new AndroidOs(def))); |
| 6916 | } |
| 6917 | |
| 6918 | private AndroidOs(Os os) { |
| 6919 | super(os); |
| 6920 | } |
| 6921 | |
| 6922 | private FileDescriptor openDeprecatedDataPath(String path, int mode) throws ErrnoException { |
| 6923 | final Uri uri = ContentResolver.translateDeprecatedDataPath(path); |
| 6924 | Log.v(TAG, "Redirecting " + path + " to " + uri); |
| 6925 | |
| 6926 | final ContentResolver cr = currentActivityThread().getApplication() |
| 6927 | .getContentResolver(); |
| 6928 | try { |
| 6929 | final FileDescriptor fd = new FileDescriptor(); |
| 6930 | fd.setInt$(cr.openFileDescriptor(uri, |
| 6931 | FileUtils.translateModePosixToString(mode)).detachFd()); |
| 6932 | return fd; |
Jeff Sharkey | b50f51e | 2019-02-27 13:55:38 -0700 | [diff] [blame] | 6933 | } catch (SecurityException e) { |
| 6934 | throw new ErrnoException(e.getMessage(), OsConstants.EACCES); |
Jeff Sharkey | bc2ae00 | 2018-07-31 10:45:37 -0600 | [diff] [blame] | 6935 | } catch (FileNotFoundException e) { |
| 6936 | throw new ErrnoException(e.getMessage(), OsConstants.ENOENT); |
| 6937 | } |
| 6938 | } |
| 6939 | |
Jeff Sharkey | 416d462 | 2019-02-27 22:14:16 -0700 | [diff] [blame] | 6940 | private void deleteDeprecatedDataPath(String path) throws ErrnoException { |
| 6941 | final Uri uri = ContentResolver.translateDeprecatedDataPath(path); |
| 6942 | Log.v(TAG, "Redirecting " + path + " to " + uri); |
| 6943 | |
| 6944 | final ContentResolver cr = currentActivityThread().getApplication() |
| 6945 | .getContentResolver(); |
| 6946 | try { |
| 6947 | if (cr.delete(uri, null, null) == 0) { |
| 6948 | throw new FileNotFoundException(); |
| 6949 | } |
| 6950 | } catch (SecurityException e) { |
| 6951 | throw new ErrnoException(e.getMessage(), OsConstants.EACCES); |
| 6952 | } catch (FileNotFoundException e) { |
| 6953 | throw new ErrnoException(e.getMessage(), OsConstants.ENOENT); |
| 6954 | } |
| 6955 | } |
| 6956 | |
Jeff Sharkey | bc2ae00 | 2018-07-31 10:45:37 -0600 | [diff] [blame] | 6957 | @Override |
| 6958 | public boolean access(String path, int mode) throws ErrnoException { |
| 6959 | if (path != null && path.startsWith(DEPRECATE_DATA_PREFIX)) { |
| 6960 | // If we opened it okay, then access check succeeded |
| 6961 | IoUtils.closeQuietly( |
| 6962 | openDeprecatedDataPath(path, FileUtils.translateModeAccessToPosix(mode))); |
| 6963 | return true; |
| 6964 | } else { |
| 6965 | return super.access(path, mode); |
| 6966 | } |
| 6967 | } |
| 6968 | |
| 6969 | @Override |
| 6970 | public FileDescriptor open(String path, int flags, int mode) throws ErrnoException { |
| 6971 | if (path != null && path.startsWith(DEPRECATE_DATA_PREFIX)) { |
| 6972 | return openDeprecatedDataPath(path, mode); |
| 6973 | } else { |
| 6974 | return super.open(path, flags, mode); |
| 6975 | } |
| 6976 | } |
| 6977 | |
| 6978 | @Override |
| 6979 | public StructStat stat(String path) throws ErrnoException { |
| 6980 | if (path != null && path.startsWith(DEPRECATE_DATA_PREFIX)) { |
| 6981 | final FileDescriptor fd = openDeprecatedDataPath(path, OsConstants.O_RDONLY); |
| 6982 | try { |
| 6983 | return android.system.Os.fstat(fd); |
| 6984 | } finally { |
| 6985 | IoUtils.closeQuietly(fd); |
| 6986 | } |
| 6987 | } else { |
| 6988 | return super.stat(path); |
Narayan Kamath | 7f06224 | 2015-04-08 13:24:13 +0100 | [diff] [blame] | 6989 | } |
| 6990 | } |
Jeff Sharkey | 416d462 | 2019-02-27 22:14:16 -0700 | [diff] [blame] | 6991 | |
| 6992 | @Override |
| 6993 | public void unlink(String path) throws ErrnoException { |
| 6994 | if (path != null && path.startsWith(DEPRECATE_DATA_PREFIX)) { |
| 6995 | deleteDeprecatedDataPath(path); |
| 6996 | } else { |
| 6997 | super.unlink(path); |
| 6998 | } |
| 6999 | } |
| 7000 | |
| 7001 | @Override |
| 7002 | public void remove(String path) throws ErrnoException { |
| 7003 | if (path != null && path.startsWith(DEPRECATE_DATA_PREFIX)) { |
| 7004 | deleteDeprecatedDataPath(path); |
| 7005 | } else { |
| 7006 | super.remove(path); |
| 7007 | } |
| 7008 | } |
| 7009 | |
| 7010 | @Override |
| 7011 | public void rename(String oldPath, String newPath) throws ErrnoException { |
| 7012 | try { |
| 7013 | super.rename(oldPath, newPath); |
| 7014 | } catch (ErrnoException e) { |
| 7015 | if (e.errno == OsConstants.EXDEV) { |
| 7016 | Log.v(TAG, "Recovering failed rename " + oldPath + " to " + newPath); |
| 7017 | try { |
| 7018 | Files.move(new File(oldPath).toPath(), new File(newPath).toPath()); |
| 7019 | } catch (IOException e2) { |
| 7020 | throw e; |
| 7021 | } |
| 7022 | } else { |
| 7023 | throw e; |
| 7024 | } |
| 7025 | } |
| 7026 | } |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 7027 | } |
| 7028 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 7029 | public static void main(String[] args) { |
Narayan Kamath | fbb32f6 | 2015-06-12 15:34:35 +0100 | [diff] [blame] | 7030 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "ActivityThreadMain"); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 7031 | |
Jeff Sharkey | bc2ae00 | 2018-07-31 10:45:37 -0600 | [diff] [blame] | 7032 | // Install selective syscall interception |
| 7033 | AndroidOs.install(); |
| 7034 | |
Brad Fitzpatrick | 4d9e6d2 | 2010-11-15 08:49:51 -0800 | [diff] [blame] | 7035 | // CloseGuard defaults to true and can be quite spammy. We |
| 7036 | // disable it here, but selectively enable it later (via |
| 7037 | // StrictMode) on debug builds, but using DropBox, not logs. |
| 7038 | CloseGuard.setEnabled(false); |
| 7039 | |
Andreas Gampe | d281b42 | 2016-07-08 03:50:27 +0000 | [diff] [blame] | 7040 | Environment.initForCurrentUser(); |
Jeff Sharkey | b049e21 | 2012-09-07 23:16:01 -0700 | [diff] [blame] | 7041 | |
Robin Lee | 3d076af | 2014-04-25 14:57:49 +0100 | [diff] [blame] | 7042 | // Make sure TrustedCertificateStore looks in the right place for CA certificates |
| 7043 | final File configDir = Environment.getUserConfigDirectory(UserHandle.myUserId()); |
| 7044 | TrustedCertificateStore.setDefaultUserDirectory(configDir); |
| 7045 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7046 | Process.setArgV0("<pre-initialized>"); |
| 7047 | |
| 7048 | Looper.prepareMainLooper(); |
| 7049 | |
Sudheer Shanka | f669010 | 2017-10-16 10:20:32 -0700 | [diff] [blame] | 7050 | // Find the value for {@link #PROC_START_SEQ_IDENT} if provided on the command line. |
| 7051 | // It will be in the format "seq=114" |
| 7052 | long startSeq = 0; |
| 7053 | if (args != null) { |
| 7054 | for (int i = args.length - 1; i >= 0; --i) { |
| 7055 | if (args[i] != null && args[i].startsWith(PROC_START_SEQ_IDENT)) { |
| 7056 | startSeq = Long.parseLong( |
| 7057 | args[i].substring(PROC_START_SEQ_IDENT.length())); |
| 7058 | } |
| 7059 | } |
| 7060 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7061 | ActivityThread thread = new ActivityThread(); |
Sudheer Shanka | f669010 | 2017-10-16 10:20:32 -0700 | [diff] [blame] | 7062 | thread.attach(false, startSeq); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7063 | |
Vairavan Srinivasan | 7335cfd | 2012-08-18 18:36:03 -0700 | [diff] [blame] | 7064 | if (sMainThreadHandler == null) { |
| 7065 | sMainThreadHandler = thread.getHandler(); |
| 7066 | } |
| 7067 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 7068 | if (false) { |
| 7069 | Looper.myLooper().setMessageLogging(new |
| 7070 | LogPrinter(Log.DEBUG, "ActivityThread")); |
| 7071 | } |
| 7072 | |
Narayan Kamath | fbb32f6 | 2015-06-12 15:34:35 +0100 | [diff] [blame] | 7073 | // End of event ActivityThreadMain. |
| 7074 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7075 | Looper.loop(); |
| 7076 | |
Jeff Brown | 10e8971 | 2011-07-08 18:52:57 -0700 | [diff] [blame] | 7077 | throw new RuntimeException("Main thread loop unexpectedly exited"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7078 | } |
Chris Craik | fc29424 | 2016-12-13 18:10:46 -0800 | [diff] [blame] | 7079 | |
| 7080 | // ------------------ Regular JNI ------------------------ |
Tim Murray | 59f3dc1 | 2018-10-22 15:26:08 -0700 | [diff] [blame] | 7081 | private native void nPurgePendingResources(); |
Chris Craik | fc29424 | 2016-12-13 18:10:46 -0800 | [diff] [blame] | 7082 | private native void nDumpGraphicsInfo(FileDescriptor fd); |
Ryan Savitski | cfdc151 | 2018-12-14 16:20:52 +0000 | [diff] [blame] | 7083 | private native void nInitZygoteChildHeapProfiling(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7084 | } |