The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.app; |
| 18 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 19 | import static android.app.servertransaction.ActivityLifecycleItem.ON_CREATE; |
| 20 | import static android.app.servertransaction.ActivityLifecycleItem.ON_DESTROY; |
| 21 | import static android.app.servertransaction.ActivityLifecycleItem.ON_PAUSE; |
| 22 | import static android.app.servertransaction.ActivityLifecycleItem.ON_RESUME; |
| 23 | import static android.app.servertransaction.ActivityLifecycleItem.ON_START; |
| 24 | import static android.app.servertransaction.ActivityLifecycleItem.ON_STOP; |
| 25 | import static android.app.servertransaction.ActivityLifecycleItem.PRE_ON_CREATE; |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 26 | import static android.view.Display.INVALID_DISPLAY; |
| 27 | |
Adam Lesinski | c1b0ebf | 2016-06-09 11:17:10 -0700 | [diff] [blame] | 28 | import android.annotation.NonNull; |
| 29 | import android.annotation.Nullable; |
Dianne Hackborn | 69c6adc | 2015-06-02 10:52:59 -0700 | [diff] [blame] | 30 | import android.app.assist.AssistContent; |
| 31 | import android.app.assist.AssistStructure; |
Christopher Tate | 4528186 | 2010-03-05 15:46:30 -0800 | [diff] [blame] | 32 | import android.app.backup.BackupAgent; |
Andrii Kulian | 914aa7d | 2018-03-19 21:51:53 -0700 | [diff] [blame] | 33 | import android.app.servertransaction.ActivityLifecycleItem; |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 34 | import android.app.servertransaction.ActivityLifecycleItem.LifecycleState; |
Andrii Kulian | 914aa7d | 2018-03-19 21:51:53 -0700 | [diff] [blame] | 35 | import android.app.servertransaction.ActivityRelaunchItem; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 36 | import android.app.servertransaction.ActivityResultItem; |
| 37 | import android.app.servertransaction.ClientTransaction; |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 38 | import android.app.servertransaction.PendingTransactionActions; |
| 39 | import android.app.servertransaction.PendingTransactionActions.StopInfo; |
| 40 | import android.app.servertransaction.TransactionExecutor; |
Andrii Kulian | 914aa7d | 2018-03-19 21:51:53 -0700 | [diff] [blame] | 41 | import android.app.servertransaction.TransactionExecutorHelper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | import android.content.BroadcastReceiver; |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 43 | import android.content.ComponentCallbacks2; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | import android.content.ComponentName; |
| 45 | import android.content.ContentProvider; |
| 46 | import android.content.Context; |
| 47 | import android.content.IContentProvider; |
Suchi Amalapurapu | 1ccac75 | 2009-06-12 10:09:58 -0700 | [diff] [blame] | 48 | import android.content.IIntentReceiver; |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 49 | import android.content.Intent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 50 | import android.content.pm.ActivityInfo; |
| 51 | import android.content.pm.ApplicationInfo; |
| 52 | import android.content.pm.IPackageManager; |
| 53 | import android.content.pm.InstrumentationInfo; |
Christopher Tate | 346acb1 | 2012-10-15 19:20:25 -0700 | [diff] [blame] | 54 | import android.content.pm.PackageInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | import android.content.pm.PackageManager; |
Sen Hu | bde7570 | 2010-05-28 01:54:03 -0700 | [diff] [blame] | 56 | import android.content.pm.PackageManager.NameNotFoundException; |
Dianne Hackborn | 3f7c9f2 | 2017-04-04 15:36:33 -0700 | [diff] [blame] | 57 | import android.content.pm.ParceledListSlice; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 58 | import android.content.pm.ProviderInfo; |
| 59 | import android.content.pm.ServiceInfo; |
| 60 | import android.content.res.AssetManager; |
Mitsuru Oshima | ba3ba57 | 2009-07-08 18:49:26 -0700 | [diff] [blame] | 61 | import android.content.res.CompatibilityInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | import android.content.res.Configuration; |
| 63 | import android.content.res.Resources; |
Alan Viverette | e54d245 | 2015-05-06 10:41:43 -0700 | [diff] [blame] | 64 | import android.content.res.Resources.Theme; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 65 | import android.database.sqlite.SQLiteDatabase; |
| 66 | import android.database.sqlite.SQLiteDebug; |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 67 | import android.database.sqlite.SQLiteDebug.DbStats; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 68 | import android.graphics.Bitmap; |
| 69 | import android.graphics.Canvas; |
Leon Scroggins III | 8290eab | 2018-03-19 10:51:44 -0400 | [diff] [blame] | 70 | import android.graphics.ImageDecoder; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 71 | import android.hardware.display.DisplayManagerGlobal; |
Paul Jensen | e0bef71 | 2014-12-10 15:12:18 -0500 | [diff] [blame] | 72 | import android.net.ConnectivityManager; |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 73 | import android.net.IConnectivityManager; |
Paul Jensen | e0bef71 | 2014-12-10 15:12:18 -0500 | [diff] [blame] | 74 | import android.net.Network; |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 75 | import android.net.Proxy; |
Jason Monk | 207900c | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 76 | import android.net.ProxyInfo; |
Jason Monk | 83520b9 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 77 | import android.net.Uri; |
Joe Onorato | d630f10 | 2011-03-17 18:42:26 -0700 | [diff] [blame] | 78 | import android.os.AsyncTask; |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 79 | import android.os.Binder; |
Jeff Sharkey | 344744b | 2016-01-28 19:03:30 -0700 | [diff] [blame] | 80 | import android.os.Build; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 81 | import android.os.Bundle; |
| 82 | import android.os.Debug; |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 83 | import android.os.DropBoxManager; |
Jeff Sharkey | b049e21 | 2012-09-07 23:16:01 -0700 | [diff] [blame] | 84 | import android.os.Environment; |
Jesse Hall | b12249b | 2016-12-12 12:53:02 -0800 | [diff] [blame] | 85 | import android.os.GraphicsEnvironment; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 86 | import android.os.Handler; |
Jeff Sharkey | 8439ac0 | 2017-12-12 17:26:23 -0700 | [diff] [blame] | 87 | import android.os.HandlerExecutor; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 88 | import android.os.IBinder; |
Adam Lesinski | b61e405 | 2016-05-19 18:23:05 -0700 | [diff] [blame] | 89 | import android.os.LocaleList; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 90 | import android.os.Looper; |
| 91 | import android.os.Message; |
| 92 | import android.os.MessageQueue; |
Dianne Hackborn | fabb70b | 2014-11-11 12:22:36 -0800 | [diff] [blame] | 93 | import android.os.Parcel; |
Dianne Hackborn | 9c8dd55 | 2009-06-23 19:22:52 -0700 | [diff] [blame] | 94 | import android.os.ParcelFileDescriptor; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 95 | import android.os.PersistableBundle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 96 | import android.os.Process; |
| 97 | import android.os.RemoteException; |
| 98 | import android.os.ServiceManager; |
Brad Fitzpatrick | 438d059 | 2010-06-10 12:19:19 -0700 | [diff] [blame] | 99 | import android.os.StrictMode; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 100 | import android.os.SystemClock; |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 101 | import android.os.SystemProperties; |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 102 | import android.os.Trace; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 103 | import android.os.UserHandle; |
Jeff Sharkey | 0a17db1 | 2016-11-04 11:23:46 -0600 | [diff] [blame] | 104 | import android.provider.BlockedNumberContract; |
| 105 | import android.provider.CalendarContract; |
| 106 | import android.provider.CallLog; |
| 107 | import android.provider.ContactsContract; |
| 108 | import android.provider.Downloads; |
Seigo Nonaka | 54084b6 | 2017-04-24 14:46:23 -0700 | [diff] [blame] | 109 | import android.provider.FontsContract; |
Narayan Kamath | ccb2a086 | 2013-12-19 14:49:36 +0000 | [diff] [blame] | 110 | import android.provider.Settings; |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 111 | import android.renderscript.RenderScriptCacheDir; |
Chad Brubaker | c72875b | 2016-04-27 16:35:11 -0700 | [diff] [blame] | 112 | import android.security.NetworkSecurityPolicy; |
Chad Brubaker | 78d4712 | 2015-11-17 22:26:58 -0800 | [diff] [blame] | 113 | import android.security.net.config.NetworkSecurityConfigProvider; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 114 | import android.util.AndroidRuntimeException; |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 115 | import android.util.ArrayMap; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 116 | import android.util.DisplayMetrics; |
| 117 | import android.util.EventLog; |
| 118 | import android.util.Log; |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 119 | import android.util.LogPrinter; |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 120 | import android.util.MergedConfiguration; |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 121 | import android.util.Pair; |
Jeff Brown | 6754ba2 | 2011-12-14 20:20:01 -0800 | [diff] [blame] | 122 | import android.util.PrintWriterPrinter; |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 123 | import android.util.Slog; |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 124 | import android.util.SparseIntArray; |
Adam Powell | 1487466 | 2013-07-18 19:42:41 -0700 | [diff] [blame] | 125 | import android.util.SuperNotCalledException; |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 126 | import android.util.proto.ProtoOutputStream; |
Jorim Jaggi | b29e318 | 2018-04-30 18:51:56 +0200 | [diff] [blame] | 127 | import android.view.Choreographer; |
Adam Lesinski | 3ad1b48 | 2016-04-01 16:41:41 -0700 | [diff] [blame] | 128 | import android.view.ContextThemeWrapper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 129 | import android.view.Display; |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 130 | import android.view.ThreadedRenderer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 131 | import android.view.View; |
| 132 | import android.view.ViewDebug; |
| 133 | import android.view.ViewManager; |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 134 | import android.view.ViewRootImpl; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 135 | import android.view.Window; |
| 136 | import android.view.WindowManager; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 137 | import android.view.WindowManagerGlobal; |
Richard Uhler | 2c03619 | 2016-09-14 09:48:31 +0100 | [diff] [blame] | 138 | import android.webkit.WebView; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 139 | |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 140 | import com.android.internal.annotations.GuardedBy; |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 141 | import com.android.internal.annotations.VisibleForTesting; |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 142 | import com.android.internal.app.IVoiceInteractor; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 143 | import com.android.internal.content.ReferrerIntent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 144 | import com.android.internal.os.BinderInternal; |
| 145 | import com.android.internal.os.RuntimeInit; |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 146 | import com.android.internal.os.SomeArgs; |
Jeff Sharkey | 3e19589 | 2016-03-05 19:48:59 -0700 | [diff] [blame] | 147 | import com.android.internal.util.ArrayUtils; |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 148 | import com.android.internal.util.FastPrintWriter; |
Jorim Jaggi | b29e318 | 2018-04-30 18:51:56 +0200 | [diff] [blame] | 149 | import com.android.internal.util.function.pooled.PooledLambda; |
Kenny Root | 12e7522 | 2013-04-23 22:34:24 -0700 | [diff] [blame] | 150 | import com.android.org.conscrypt.OpenSSLSocketImpl; |
Robin Lee | 3d076af | 2014-04-25 14:57:49 +0100 | [diff] [blame] | 151 | import com.android.org.conscrypt.TrustedCertificateStore; |
Yi Jin | 6c6e9ca | 2018-03-20 16:53:35 -0700 | [diff] [blame] | 152 | import com.android.server.am.MemInfoDumpProto; |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 153 | |
| 154 | import dalvik.system.BaseDexClassLoader; |
| 155 | import dalvik.system.CloseGuard; |
| 156 | import dalvik.system.VMDebug; |
| 157 | import dalvik.system.VMRuntime; |
| 158 | |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 159 | import libcore.io.DropBox; |
| 160 | import libcore.io.EventLogger; |
| 161 | import libcore.io.IoUtils; |
| 162 | import libcore.net.event.NetworkEventDispatcher; |
| 163 | |
| 164 | import org.apache.harmony.dalvik.ddmc.DdmVmInternal; |
| 165 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 166 | import java.io.File; |
| 167 | import java.io.FileDescriptor; |
| 168 | import java.io.FileOutputStream; |
Dianne Hackborn | 9c8dd55 | 2009-06-23 19:22:52 -0700 | [diff] [blame] | 169 | import java.io.IOException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 170 | import java.io.PrintWriter; |
| 171 | import java.lang.ref.WeakReference; |
Svet Ganov | 37e4327 | 2016-09-09 16:01:32 -0700 | [diff] [blame] | 172 | import java.lang.reflect.Field; |
Torne (Richard Coles) | 466cbe4 | 2017-05-31 14:09:14 -0400 | [diff] [blame] | 173 | import java.lang.reflect.Method; |
Robert Greenwalt | 03595d0 | 2010-11-02 14:08:23 -0700 | [diff] [blame] | 174 | import java.net.InetAddress; |
Narayan Kamath | ccb2a086 | 2013-12-19 14:49:36 +0000 | [diff] [blame] | 175 | import java.text.DateFormat; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 176 | import java.util.ArrayList; |
Jeff Sharkey | a6bfeae | 2017-07-05 16:50:24 -0600 | [diff] [blame] | 177 | import java.util.Arrays; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 178 | import java.util.List; |
Adam Lesinski | b61e405 | 2016-05-19 18:23:05 -0700 | [diff] [blame] | 179 | import java.util.Locale; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 180 | import java.util.Map; |
Kenny Root | e6585b3 | 2013-12-13 12:00:26 -0800 | [diff] [blame] | 181 | import java.util.Objects; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 182 | import java.util.TimeZone; |
Jeff Sharkey | 8439ac0 | 2017-12-12 17:26:23 -0700 | [diff] [blame] | 183 | import java.util.concurrent.Executor; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 184 | |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 185 | final class RemoteServiceException extends AndroidRuntimeException { |
| 186 | public RemoteServiceException(String msg) { |
| 187 | super(msg); |
| 188 | } |
| 189 | } |
| 190 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 191 | /** |
| 192 | * This manages the execution of the main thread in an |
| 193 | * application process, scheduling and executing activities, |
| 194 | * broadcasts, and other operations on it as the activity |
| 195 | * manager requests. |
| 196 | * |
| 197 | * {@hide} |
| 198 | */ |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 199 | public final class ActivityThread extends ClientTransactionHandler { |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 200 | /** @hide */ |
| 201 | public static final String TAG = "ActivityThread"; |
Jim Miller | 0b2a6d0 | 2010-07-13 18:01:29 -0700 | [diff] [blame] | 202 | 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] | 203 | static final boolean localLOGV = false; |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 204 | static final boolean DEBUG_MESSAGES = false; |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 205 | /** @hide */ |
| 206 | public static final boolean DEBUG_BROADCAST = false; |
Chris Tate | 8a7dc17 | 2009-03-24 20:11:42 -0700 | [diff] [blame] | 207 | private static final boolean DEBUG_RESULTS = false; |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 208 | private static final boolean DEBUG_BACKUP = false; |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 209 | public static final boolean DEBUG_CONFIGURATION = false; |
Dianne Hackborn | a0c283e | 2012-02-09 10:47:01 -0800 | [diff] [blame] | 210 | private static final boolean DEBUG_SERVICE = false; |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 211 | public static final boolean DEBUG_MEMORY_TRIM = false; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 212 | private static final boolean DEBUG_PROVIDER = false; |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 213 | public static final boolean DEBUG_ORDER = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 214 | 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] | 215 | 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] | 216 | |
Dianne Hackborn | 455625e | 2015-01-21 09:55:13 -0800 | [diff] [blame] | 217 | /** Type for IActivityManager.serviceDoneExecuting: anonymous operation */ |
| 218 | public static final int SERVICE_DONE_EXECUTING_ANON = 0; |
| 219 | /** Type for IActivityManager.serviceDoneExecuting: done with an onStart call */ |
| 220 | public static final int SERVICE_DONE_EXECUTING_START = 1; |
| 221 | /** Type for IActivityManager.serviceDoneExecuting: done stopping (destroying) service */ |
| 222 | public static final int SERVICE_DONE_EXECUTING_STOP = 2; |
| 223 | |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 224 | // Whether to invoke an activity callback after delivering new configuration. |
| 225 | private static final boolean REPORT_TO_ACTIVITY = true; |
| 226 | |
Sudheer Shanka | 84a4895 | 2017-03-08 18:19:01 -0800 | [diff] [blame] | 227 | /** |
| 228 | * Denotes an invalid sequence number corresponding to a process state change. |
| 229 | */ |
| 230 | public static final long INVALID_PROC_STATE_SEQ = -1; |
| 231 | |
Sudheer Shanka | f669010 | 2017-10-16 10:20:32 -0700 | [diff] [blame] | 232 | /** |
| 233 | * Identifier for the sequence no. associated with this process start. It will be provided |
| 234 | * as one of the arguments when the process starts. |
| 235 | */ |
| 236 | public static final String PROC_START_SEQ_IDENT = "seq="; |
| 237 | |
Sudheer Shanka | 84a4895 | 2017-03-08 18:19:01 -0800 | [diff] [blame] | 238 | private final Object mNetworkPolicyLock = new Object(); |
| 239 | |
| 240 | /** |
| 241 | * Denotes the sequence number of the process state change for which the main thread needs |
| 242 | * to block until the network rules are updated for it. |
| 243 | * |
| 244 | * Value of {@link #INVALID_PROC_STATE_SEQ} indicates there is no need for blocking. |
| 245 | */ |
| 246 | @GuardedBy("mNetworkPolicyLock") |
| 247 | private long mNetworkBlockSeq = INVALID_PROC_STATE_SEQ; |
| 248 | |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 249 | private ContextImpl mSystemContext; |
Adam Lesinski | a82b626 | 2017-03-21 16:56:17 -0700 | [diff] [blame] | 250 | private ContextImpl mSystemUiContext; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 251 | |
Jeff Sharkey | d589663 | 2016-03-04 16:16:00 -0700 | [diff] [blame] | 252 | static volatile IPackageManager sPackageManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 253 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 254 | final ApplicationThread mAppThread = new ApplicationThread(); |
| 255 | final Looper mLooper = Looper.myLooper(); |
| 256 | final H mH = new H(); |
Jeff Sharkey | 8439ac0 | 2017-12-12 17:26:23 -0700 | [diff] [blame] | 257 | final Executor mExecutor = new HandlerExecutor(mH); |
Dianne Hackborn | 782d498 | 2015-07-08 17:36:37 -0700 | [diff] [blame] | 258 | final ArrayMap<IBinder, ActivityClientRecord> mActivities = new ArrayMap<>(); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 259 | // List of new activities (via ActivityRecord.nextIdle) that should |
| 260 | // be reported when next we idle. |
| 261 | ActivityClientRecord mNewActivities = null; |
| 262 | // Number of activities that are currently visible on-screen. |
| 263 | int mNumVisibleActivities = 0; |
Amith Yamasani | 4f128e4 | 2016-05-10 11:44:12 -0700 | [diff] [blame] | 264 | ArrayList<WeakReference<AssistStructure>> mLastAssistStructures = new ArrayList<>(); |
| 265 | private int mLastSessionId; |
Dianne Hackborn | 782d498 | 2015-07-08 17:36:37 -0700 | [diff] [blame] | 266 | final ArrayMap<IBinder, Service> mServices = new ArrayMap<>(); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 267 | AppBindData mBoundApplication; |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 268 | Profiler mProfiler; |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 269 | int mCurDefaultDisplayDpi; |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 270 | boolean mDensityCompatMode; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 271 | Configuration mConfiguration; |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 272 | Configuration mCompatConfiguration; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 273 | Application mInitialApplication; |
| 274 | final ArrayList<Application> mAllApplications |
| 275 | = new ArrayList<Application>(); |
| 276 | // set of instantiated backup agents, keyed by package name |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 277 | final ArrayMap<String, BackupAgent> mBackupAgents = new ArrayMap<String, BackupAgent>(); |
Jeff Sharkey | 66a017b | 2013-01-17 18:18:22 -0800 | [diff] [blame] | 278 | /** Reference to singleton {@link ActivityThread} */ |
Jeff Sharkey | d589663 | 2016-03-04 16:16:00 -0700 | [diff] [blame] | 279 | private static volatile ActivityThread sCurrentActivityThread; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 280 | Instrumentation mInstrumentation; |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 281 | String mInstrumentationPackageName = null; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 282 | String mInstrumentationAppDir = null; |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 283 | String[] mInstrumentationSplitAppDirs = null; |
| 284 | String mInstrumentationLibDir = null; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 285 | String mInstrumentedAppDir = null; |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 286 | String[] mInstrumentedSplitAppDirs = null; |
| 287 | String mInstrumentedLibDir = null; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 288 | boolean mSystemThread = false; |
| 289 | boolean mJitEnabled = false; |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 290 | boolean mSomeActivitiesChanged = false; |
Chong Zhang | 4951f9d | 2016-06-23 13:15:08 -0700 | [diff] [blame] | 291 | boolean mUpdatingSystemConfig = false; |
David Brazdil | d960cc4 | 2018-01-31 07:59:17 +0000 | [diff] [blame] | 292 | /* package */ boolean mHiddenApiWarningShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 293 | |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 294 | // These can be accessed by multiple threads; mResourcesManager is the lock. |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 295 | // XXX For now we keep around information about all packages we have |
| 296 | // seen, not removing entries from this map. |
Dianne Hackborn | 1fbee79 | 2011-11-30 11:29:58 -0800 | [diff] [blame] | 297 | // NOTE: The activity and window managers need to call in to |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 298 | // ActivityThread to do things like update resource configurations, |
Dianne Hackborn | 1fbee79 | 2011-11-30 11:29:58 -0800 | [diff] [blame] | 299 | // which means this lock gets held while the activity and window managers |
| 300 | // holds their own lock. Thus you MUST NEVER call back into the activity manager |
| 301 | // 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] | 302 | // 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] | 303 | @GuardedBy("mResourcesManager") |
| 304 | final ArrayMap<String, WeakReference<LoadedApk>> mPackages = new ArrayMap<>(); |
| 305 | @GuardedBy("mResourcesManager") |
| 306 | final ArrayMap<String, WeakReference<LoadedApk>> mResourcePackages = new ArrayMap<>(); |
| 307 | @GuardedBy("mResourcesManager") |
| 308 | final ArrayList<ActivityClientRecord> mRelaunchingActivities = new ArrayList<>(); |
| 309 | @GuardedBy("mResourcesManager") |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 310 | Configuration mPendingConfiguration = null; |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 311 | // An executor that performs multi-step transactions. |
| 312 | private final TransactionExecutor mTransactionExecutor = new TransactionExecutor(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 313 | |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 314 | private final ResourcesManager mResourcesManager; |
| 315 | |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 316 | private static final class ProviderKey { |
| 317 | final String authority; |
| 318 | final int userId; |
| 319 | |
| 320 | public ProviderKey(String authority, int userId) { |
| 321 | this.authority = authority; |
| 322 | this.userId = userId; |
| 323 | } |
| 324 | |
| 325 | @Override |
| 326 | public boolean equals(Object o) { |
| 327 | if (o instanceof ProviderKey) { |
| 328 | final ProviderKey other = (ProviderKey) o; |
Kenny Root | e6585b3 | 2013-12-13 12:00:26 -0800 | [diff] [blame] | 329 | return Objects.equals(authority, other.authority) && userId == other.userId; |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 330 | } |
| 331 | return false; |
| 332 | } |
| 333 | |
| 334 | @Override |
| 335 | public int hashCode() { |
| 336 | return ((authority != null) ? authority.hashCode() : 0) ^ userId; |
| 337 | } |
| 338 | } |
| 339 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 340 | // The lock of mProviderMap protects the following variables. |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 341 | final ArrayMap<ProviderKey, ProviderClientRecord> mProviderMap |
| 342 | = new ArrayMap<ProviderKey, ProviderClientRecord>(); |
| 343 | final ArrayMap<IBinder, ProviderRefCount> mProviderRefCountMap |
| 344 | = new ArrayMap<IBinder, ProviderRefCount>(); |
| 345 | final ArrayMap<IBinder, ProviderClientRecord> mLocalProviders |
| 346 | = new ArrayMap<IBinder, ProviderClientRecord>(); |
| 347 | final ArrayMap<ComponentName, ProviderClientRecord> mLocalProvidersByName |
| 348 | = new ArrayMap<ComponentName, ProviderClientRecord>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 349 | |
Makoto Onuki | b6c79ea | 2018-05-31 11:03:56 -0700 | [diff] [blame] | 350 | // Mitigation for b/74523247: Used to serialize calls to AM.getContentProvider(). |
| 351 | // Note we never removes items from this map but that's okay because there are only so many |
| 352 | // users and so many authorities. |
| 353 | // TODO Remove it once we move CPR.wait() from AMS to the client side. |
| 354 | @GuardedBy("mGetProviderLocks") |
| 355 | final ArrayMap<ProviderKey, Object> mGetProviderLocks = new ArrayMap<>(); |
| 356 | |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 357 | final ArrayMap<Activity, ArrayList<OnActivityPausedListener>> mOnPauseListeners |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 358 | = new ArrayMap<Activity, ArrayList<OnActivityPausedListener>>(); |
Jeff Hamilton | 52d3203 | 2011-01-08 15:31:26 -0600 | [diff] [blame] | 359 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 360 | final GcIdler mGcIdler = new GcIdler(); |
| 361 | boolean mGcIdlerScheduled = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 362 | |
Jeff Sharkey | d589663 | 2016-03-04 16:16:00 -0700 | [diff] [blame] | 363 | static volatile Handler sMainThreadHandler; // set once in main() |
Brad Fitzpatrick | 333b8cb | 2010-08-26 12:04:57 -0700 | [diff] [blame] | 364 | |
Svetoslav Ganov | 9aa597e | 2011-03-03 18:17:41 -0800 | [diff] [blame] | 365 | Bundle mCoreSettings = null; |
| 366 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 367 | /** Activity client record, used for bookkeeping for the real {@link Activity} instance. */ |
| 368 | public static final class ActivityClientRecord { |
| 369 | public IBinder token; |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 370 | int ident; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 371 | Intent intent; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 372 | String referrer; |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 373 | IVoiceInteractor voiceInteractor; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 374 | Bundle state; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 375 | PersistableBundle persistentState; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 376 | Activity activity; |
| 377 | Window window; |
| 378 | Activity parent; |
| 379 | String embeddedID; |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 380 | Activity.NonConfigurationInstances lastNonConfigurationInstances; |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 381 | // TODO(lifecycler): Use mLifecycleState instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 382 | boolean paused; |
| 383 | boolean stopped; |
| 384 | boolean hideForNow; |
| 385 | Configuration newConfig; |
Dianne Hackborn | e88846e | 2009-09-30 21:34:25 -0700 | [diff] [blame] | 386 | Configuration createdConfig; |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 387 | Configuration overrideConfig; |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 388 | // Used for consolidating configs before sending on to Activity. |
| 389 | private Configuration tmpConfig = new Configuration(); |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 390 | // Callback used for updating activity override config. |
| 391 | ViewRootImpl.ActivityConfigCallback configCallback; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 392 | ActivityClientRecord nextIdle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 393 | |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 394 | ProfilerInfo profilerInfo; |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 395 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 396 | ActivityInfo activityInfo; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 397 | CompatibilityInfo compatInfo; |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 398 | public LoadedApk packageInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 399 | |
| 400 | List<ResultInfo> pendingResults; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 401 | List<ReferrerIntent> pendingIntents; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 402 | |
| 403 | boolean startsNotResumed; |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 404 | public final boolean isForward; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 405 | int pendingConfigChanges; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 406 | |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 407 | Window mPendingRemoveWindow; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 408 | WindowManager mPendingRemoveWindowManager; |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 409 | boolean mPreserveWindow; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 410 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 411 | @LifecycleState |
| 412 | private int mLifecycleState = PRE_ON_CREATE; |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 413 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 414 | @VisibleForTesting |
| 415 | public ActivityClientRecord() { |
| 416 | this.isForward = false; |
| 417 | init(); |
| 418 | } |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 419 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 420 | public ActivityClientRecord(IBinder token, Intent intent, int ident, |
| 421 | ActivityInfo info, Configuration overrideConfig, CompatibilityInfo compatInfo, |
| 422 | String referrer, IVoiceInteractor voiceInteractor, Bundle state, |
| 423 | PersistableBundle persistentState, List<ResultInfo> pendingResults, |
| 424 | List<ReferrerIntent> pendingNewIntents, boolean isForward, |
| 425 | ProfilerInfo profilerInfo, ClientTransactionHandler client) { |
| 426 | this.token = token; |
| 427 | this.ident = ident; |
| 428 | this.intent = intent; |
| 429 | this.referrer = referrer; |
| 430 | this.voiceInteractor = voiceInteractor; |
| 431 | this.activityInfo = info; |
| 432 | this.compatInfo = compatInfo; |
| 433 | this.state = state; |
| 434 | this.persistentState = persistentState; |
| 435 | this.pendingResults = pendingResults; |
| 436 | this.pendingIntents = pendingNewIntents; |
| 437 | this.isForward = isForward; |
| 438 | this.profilerInfo = profilerInfo; |
| 439 | this.overrideConfig = overrideConfig; |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 440 | this.packageInfo = client.getPackageInfoNoCheck(activityInfo.applicationInfo, |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 441 | compatInfo); |
| 442 | init(); |
| 443 | } |
| 444 | |
| 445 | /** Common initializer for all constructors. */ |
| 446 | private void init() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 447 | parent = null; |
| 448 | embeddedID = null; |
| 449 | paused = false; |
| 450 | stopped = false; |
| 451 | hideForNow = false; |
| 452 | nextIdle = null; |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 453 | configCallback = (Configuration overrideConfig, int newDisplayId) -> { |
| 454 | if (activity == null) { |
| 455 | throw new IllegalStateException( |
| 456 | "Received config update for non-existing activity"); |
| 457 | } |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 458 | activity.mMainThread.handleActivityConfigurationChanged(token, overrideConfig, |
| 459 | newDisplayId); |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 460 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 461 | } |
| 462 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 463 | /** Get the current lifecycle state. */ |
| 464 | public int getLifecycleState() { |
| 465 | return mLifecycleState; |
| 466 | } |
| 467 | |
| 468 | /** Update the current lifecycle state for internal bookkeeping. */ |
| 469 | public void setState(@LifecycleState int newLifecycleState) { |
| 470 | mLifecycleState = newLifecycleState; |
| 471 | switch (mLifecycleState) { |
| 472 | case ON_CREATE: |
| 473 | paused = true; |
| 474 | stopped = true; |
| 475 | break; |
| 476 | case ON_START: |
| 477 | paused = true; |
| 478 | stopped = false; |
| 479 | break; |
| 480 | case ON_RESUME: |
| 481 | paused = false; |
| 482 | stopped = false; |
| 483 | break; |
| 484 | case ON_PAUSE: |
| 485 | paused = true; |
| 486 | stopped = false; |
| 487 | break; |
| 488 | case ON_STOP: |
| 489 | paused = true; |
| 490 | stopped = true; |
| 491 | break; |
| 492 | } |
| 493 | } |
| 494 | |
Andrii Kulian | 391161f | 2018-01-29 10:50:02 -0800 | [diff] [blame] | 495 | private boolean isPreHoneycomb() { |
| 496 | return activity != null && activity.getApplicationInfo().targetSdkVersion |
| 497 | < android.os.Build.VERSION_CODES.HONEYCOMB; |
| 498 | } |
| 499 | |
| 500 | private boolean isPreP() { |
| 501 | return activity != null && activity.getApplicationInfo().targetSdkVersion |
| 502 | < android.os.Build.VERSION_CODES.P; |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 503 | } |
| 504 | |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 505 | public boolean isPersistable() { |
Craig Mautner | 43e52ed | 2014-06-16 17:18:52 -0700 | [diff] [blame] | 506 | return activityInfo.persistableMode == ActivityInfo.PERSIST_ACROSS_REBOOTS; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 507 | } |
| 508 | |
Andrii Kulian | 914aa7d | 2018-03-19 21:51:53 -0700 | [diff] [blame] | 509 | public boolean isVisibleFromServer() { |
| 510 | return activity != null && activity.mVisibleFromServer; |
| 511 | } |
| 512 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 513 | public String toString() { |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 514 | ComponentName componentName = intent != null ? intent.getComponent() : null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 515 | return "ActivityRecord{" |
| 516 | + Integer.toHexString(System.identityHashCode(this)) |
| 517 | + " token=" + token + " " + (componentName == null |
| 518 | ? "no component name" : componentName.toShortString()) |
| 519 | + "}"; |
| 520 | } |
Andrii Kulian | 58178f2 | 2016-03-16 13:44:56 -0700 | [diff] [blame] | 521 | |
| 522 | public String getStateString() { |
| 523 | StringBuilder sb = new StringBuilder(); |
| 524 | sb.append("ActivityClientRecord{"); |
| 525 | sb.append("paused=").append(paused); |
| 526 | sb.append(", stopped=").append(stopped); |
| 527 | sb.append(", hideForNow=").append(hideForNow); |
| 528 | sb.append(", startsNotResumed=").append(startsNotResumed); |
| 529 | sb.append(", isForward=").append(isForward); |
| 530 | sb.append(", pendingConfigChanges=").append(pendingConfigChanges); |
Andrii Kulian | 58178f2 | 2016-03-16 13:44:56 -0700 | [diff] [blame] | 531 | sb.append(", preserveWindow=").append(mPreserveWindow); |
| 532 | if (activity != null) { |
| 533 | sb.append(", Activity{"); |
| 534 | sb.append("resumed=").append(activity.mResumed); |
| 535 | sb.append(", stopped=").append(activity.mStopped); |
| 536 | sb.append(", finished=").append(activity.isFinishing()); |
| 537 | sb.append(", destroyed=").append(activity.isDestroyed()); |
| 538 | sb.append(", startedActivity=").append(activity.mStartedActivity); |
| 539 | sb.append(", temporaryPause=").append(activity.mTemporaryPause); |
| 540 | sb.append(", changingConfigurations=").append(activity.mChangingConfigurations); |
Andrii Kulian | 58178f2 | 2016-03-16 13:44:56 -0700 | [diff] [blame] | 541 | sb.append("}"); |
| 542 | } |
| 543 | sb.append("}"); |
| 544 | return sb.toString(); |
| 545 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 546 | } |
| 547 | |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 548 | final class ProviderClientRecord { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 549 | final String[] mNames; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 550 | final IContentProvider mProvider; |
| 551 | final ContentProvider mLocalProvider; |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 552 | final ContentProviderHolder mHolder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 553 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 554 | ProviderClientRecord(String[] names, IContentProvider provider, |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 555 | ContentProvider localProvider, ContentProviderHolder holder) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 556 | mNames = names; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 557 | mProvider = provider; |
| 558 | mLocalProvider = localProvider; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 559 | mHolder = holder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 560 | } |
| 561 | } |
| 562 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 563 | static final class ReceiverData extends BroadcastReceiver.PendingResult { |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 564 | public ReceiverData(Intent intent, int resultCode, String resultData, Bundle resultExtras, |
Dianne Hackborn | 20e8098 | 2012-08-31 19:00:44 -0700 | [diff] [blame] | 565 | boolean ordered, boolean sticky, IBinder token, int sendingUser) { |
| 566 | super(resultCode, resultData, resultExtras, TYPE_COMPONENT, ordered, sticky, |
riddle_hsu | 1f5ac4d | 2015-01-03 15:38:21 +0800 | [diff] [blame] | 567 | token, sendingUser, intent.getFlags()); |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 568 | this.intent = intent; |
| 569 | } |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 570 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 571 | Intent intent; |
| 572 | ActivityInfo info; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 573 | CompatibilityInfo compatInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 574 | public String toString() { |
| 575 | return "ReceiverData{intent=" + intent + " packageName=" + |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 576 | info.packageName + " resultCode=" + getResultCode() |
| 577 | + " resultData=" + getResultData() + " resultExtras=" |
| 578 | + getResultExtras(false) + "}"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 579 | } |
| 580 | } |
| 581 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 582 | static final class CreateBackupAgentData { |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 583 | ApplicationInfo appInfo; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 584 | CompatibilityInfo compatInfo; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 585 | int backupMode; |
| 586 | public String toString() { |
| 587 | return "CreateBackupAgentData{appInfo=" + appInfo |
| 588 | + " backupAgent=" + appInfo.backupAgentName |
| 589 | + " mode=" + backupMode + "}"; |
| 590 | } |
| 591 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 592 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 593 | static final class CreateServiceData { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 594 | IBinder token; |
| 595 | ServiceInfo info; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 596 | CompatibilityInfo compatInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 597 | Intent intent; |
| 598 | public String toString() { |
| 599 | return "CreateServiceData{token=" + token + " className=" |
| 600 | + info.name + " packageName=" + info.packageName |
| 601 | + " intent=" + intent + "}"; |
| 602 | } |
| 603 | } |
| 604 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 605 | static final class BindServiceData { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 606 | IBinder token; |
| 607 | Intent intent; |
| 608 | boolean rebind; |
| 609 | public String toString() { |
| 610 | return "BindServiceData{token=" + token + " intent=" + intent + "}"; |
| 611 | } |
| 612 | } |
| 613 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 614 | static final class ServiceArgsData { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 615 | IBinder token; |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 616 | boolean taskRemoved; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 617 | int startId; |
Dianne Hackborn | f6f9f2d | 2009-08-21 16:26:03 -0700 | [diff] [blame] | 618 | int flags; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 619 | Intent args; |
| 620 | public String toString() { |
| 621 | return "ServiceArgsData{token=" + token + " startId=" + startId |
| 622 | + " args=" + args + "}"; |
| 623 | } |
| 624 | } |
| 625 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 626 | static final class AppBindData { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 627 | LoadedApk info; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 628 | String processName; |
| 629 | ApplicationInfo appInfo; |
| 630 | List<ProviderInfo> providers; |
| 631 | ComponentName instrumentationName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 632 | Bundle instrumentationArgs; |
| 633 | IInstrumentationWatcher instrumentationWatcher; |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 634 | IUiAutomationConnection instrumentationUiAutomationConnection; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 635 | int debugMode; |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 636 | boolean enableBinderTracking; |
Man Cao | cfa78b2 | 2015-06-11 20:14:34 -0700 | [diff] [blame] | 637 | boolean trackAllocation; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 638 | boolean restrictedBackupMode; |
Dianne Hackborn | 5d927c2 | 2011-09-02 12:22:18 -0700 | [diff] [blame] | 639 | boolean persistent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 640 | Configuration config; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 641 | CompatibilityInfo compatInfo; |
Svet Ganov | 37e4327 | 2016-09-09 16:01:32 -0700 | [diff] [blame] | 642 | String buildSerial; |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 643 | |
| 644 | /** Initial values for {@link Profiler}. */ |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 645 | ProfilerInfo initProfilerInfo; |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 646 | |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 647 | boolean autofillCompatibilityEnabled; |
| 648 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 649 | public String toString() { |
| 650 | return "AppBindData{appInfo=" + appInfo + "}"; |
| 651 | } |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | static final class Profiler { |
| 655 | String profileFile; |
| 656 | ParcelFileDescriptor profileFd; |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 657 | int samplingInterval; |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 658 | boolean autoStopProfiler; |
Shukang Zhou | 6ffd4f9 | 2017-01-25 16:07:57 -0800 | [diff] [blame] | 659 | boolean streamingOutput; |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 660 | boolean profiling; |
| 661 | boolean handlingProfiling; |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 662 | public void setProfiler(ProfilerInfo profilerInfo) { |
| 663 | ParcelFileDescriptor fd = profilerInfo.profileFd; |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 664 | if (profiling) { |
| 665 | if (fd != null) { |
| 666 | try { |
| 667 | fd.close(); |
| 668 | } catch (IOException e) { |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 669 | // Ignore |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 670 | } |
| 671 | } |
| 672 | return; |
| 673 | } |
| 674 | if (profileFd != null) { |
| 675 | try { |
| 676 | profileFd.close(); |
| 677 | } catch (IOException e) { |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 678 | // Ignore |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 679 | } |
| 680 | } |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 681 | profileFile = profilerInfo.profileFile; |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 682 | profileFd = fd; |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 683 | samplingInterval = profilerInfo.samplingInterval; |
| 684 | autoStopProfiler = profilerInfo.autoStopProfiler; |
Shukang Zhou | 6ffd4f9 | 2017-01-25 16:07:57 -0800 | [diff] [blame] | 685 | streamingOutput = profilerInfo.streamingOutput; |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 686 | } |
| 687 | public void startProfiling() { |
| 688 | if (profileFd == null || profiling) { |
| 689 | return; |
| 690 | } |
| 691 | try { |
Andreas Gampe | eff0639 | 2016-05-10 12:51:45 -0700 | [diff] [blame] | 692 | int bufferSize = SystemProperties.getInt("debug.traceview-buffer-size-mb", 8); |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 693 | VMDebug.startMethodTracing(profileFile, profileFd.getFileDescriptor(), |
Shukang Zhou | 6ffd4f9 | 2017-01-25 16:07:57 -0800 | [diff] [blame] | 694 | bufferSize * 1024 * 1024, 0, samplingInterval != 0, samplingInterval, |
| 695 | streamingOutput); |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 696 | profiling = true; |
| 697 | } catch (RuntimeException e) { |
Andreas Gampe | 4f68924 | 2018-03-14 23:13:28 -0700 | [diff] [blame] | 698 | Slog.w(TAG, "Profiling failed on path " + profileFile, e); |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 699 | try { |
| 700 | profileFd.close(); |
| 701 | profileFd = null; |
| 702 | } catch (IOException e2) { |
| 703 | Slog.w(TAG, "Failure closing profile fd", e2); |
| 704 | } |
| 705 | } |
| 706 | } |
| 707 | public void stopProfiling() { |
| 708 | if (profiling) { |
| 709 | profiling = false; |
| 710 | Debug.stopMethodTracing(); |
| 711 | if (profileFd != null) { |
| 712 | try { |
| 713 | profileFd.close(); |
| 714 | } catch (IOException e) { |
| 715 | } |
| 716 | } |
| 717 | profileFd = null; |
| 718 | profileFile = null; |
| 719 | } |
| 720 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 721 | } |
| 722 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 723 | static final class DumpComponentInfo { |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 724 | ParcelFileDescriptor fd; |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 725 | IBinder token; |
Dianne Hackborn | 30d7189 | 2010-12-11 10:37:55 -0800 | [diff] [blame] | 726 | String prefix; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 727 | String[] args; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 728 | } |
| 729 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 730 | static final class ContextCleanupInfo { |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 731 | ContextImpl context; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 732 | String what; |
| 733 | String who; |
| 734 | } |
| 735 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 736 | static final class DumpHeapData { |
Christopher Ferris | 8d652f8 | 2017-04-11 16:29:18 -0700 | [diff] [blame] | 737 | public boolean managed; |
| 738 | public boolean mallocInfo; |
Makoto Onuki | 4556b7b | 2017-07-07 14:58:58 -0700 | [diff] [blame] | 739 | public boolean runGc; |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 740 | String path; |
| 741 | ParcelFileDescriptor fd; |
| 742 | } |
| 743 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 744 | static final class UpdateCompatibilityData { |
| 745 | String pkg; |
| 746 | CompatibilityInfo info; |
| 747 | } |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 748 | |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 749 | static final class RequestAssistContextExtras { |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 750 | IBinder activityToken; |
| 751 | IBinder requestToken; |
| 752 | int requestType; |
Amith Yamasani | 4f128e4 | 2016-05-10 11:44:12 -0700 | [diff] [blame] | 753 | int sessionId; |
Svet Ganov | fd31f85 | 2017-04-26 15:54:27 -0700 | [diff] [blame] | 754 | int flags; |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 755 | } |
Anwar Ghuloum | 3a8ce1b | 2013-04-26 16:18:28 -0700 | [diff] [blame] | 756 | |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 757 | private class ApplicationThread extends IApplicationThread.Stub { |
Vasu Nori | 3c7131f | 2010-09-21 14:36:57 -0700 | [diff] [blame] | 758 | private static final String DB_INFO_FORMAT = " %8s %8s %14s %14s %s"; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 759 | |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 760 | private int mLastProcessState = -1; |
| 761 | |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 762 | private void updatePendingConfiguration(Configuration config) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 763 | synchronized (mResourcesManager) { |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 764 | if (mPendingConfiguration == null || |
| 765 | mPendingConfiguration.isOtherSeqNewer(config)) { |
| 766 | mPendingConfiguration = config; |
| 767 | } |
| 768 | } |
| 769 | } |
| 770 | |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 771 | public final void scheduleSleeping(IBinder token, boolean sleeping) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 772 | sendMessage(H.SLEEPING, token, sleeping ? 1 : 0); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 773 | } |
| 774 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 775 | public final void scheduleReceiver(Intent intent, ActivityInfo info, |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 776 | CompatibilityInfo compatInfo, int resultCode, String data, Bundle extras, |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 777 | boolean sync, int sendingUser, int processState) { |
| 778 | updateProcessState(processState, false); |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 779 | ReceiverData r = new ReceiverData(intent, resultCode, data, extras, |
Dianne Hackborn | 20e8098 | 2012-08-31 19:00:44 -0700 | [diff] [blame] | 780 | sync, false, mAppThread.asBinder(), sendingUser); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 781 | r.info = info; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 782 | r.compatInfo = compatInfo; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 783 | sendMessage(H.RECEIVER, r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 784 | } |
| 785 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 786 | public final void scheduleCreateBackupAgent(ApplicationInfo app, |
| 787 | CompatibilityInfo compatInfo, int backupMode) { |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 788 | CreateBackupAgentData d = new CreateBackupAgentData(); |
| 789 | d.appInfo = app; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 790 | d.compatInfo = compatInfo; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 791 | d.backupMode = backupMode; |
| 792 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 793 | sendMessage(H.CREATE_BACKUP_AGENT, d); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 794 | } |
| 795 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 796 | public final void scheduleDestroyBackupAgent(ApplicationInfo app, |
| 797 | CompatibilityInfo compatInfo) { |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 798 | CreateBackupAgentData d = new CreateBackupAgentData(); |
| 799 | d.appInfo = app; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 800 | d.compatInfo = compatInfo; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 801 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 802 | sendMessage(H.DESTROY_BACKUP_AGENT, d); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 803 | } |
| 804 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 805 | public final void scheduleCreateService(IBinder token, |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 806 | ServiceInfo info, CompatibilityInfo compatInfo, int processState) { |
| 807 | updateProcessState(processState, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 808 | CreateServiceData s = new CreateServiceData(); |
| 809 | s.token = token; |
| 810 | s.info = info; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 811 | s.compatInfo = compatInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 812 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 813 | sendMessage(H.CREATE_SERVICE, s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 814 | } |
| 815 | |
| 816 | public final void scheduleBindService(IBinder token, Intent intent, |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 817 | boolean rebind, int processState) { |
| 818 | updateProcessState(processState, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 819 | BindServiceData s = new BindServiceData(); |
| 820 | s.token = token; |
| 821 | s.intent = intent; |
| 822 | s.rebind = rebind; |
| 823 | |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 824 | if (DEBUG_SERVICE) |
| 825 | Slog.v(TAG, "scheduleBindService token=" + token + " intent=" + intent + " uid=" |
| 826 | + Binder.getCallingUid() + " pid=" + Binder.getCallingPid()); |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 827 | sendMessage(H.BIND_SERVICE, s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 828 | } |
| 829 | |
| 830 | public final void scheduleUnbindService(IBinder token, Intent intent) { |
| 831 | BindServiceData s = new BindServiceData(); |
| 832 | s.token = token; |
| 833 | s.intent = intent; |
| 834 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 835 | sendMessage(H.UNBIND_SERVICE, s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 836 | } |
| 837 | |
Dianne Hackborn | 3f7c9f2 | 2017-04-04 15:36:33 -0700 | [diff] [blame] | 838 | public final void scheduleServiceArgs(IBinder token, ParceledListSlice args) { |
| 839 | List<ServiceStartArgs> list = args.getList(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 840 | |
Dianne Hackborn | 3f7c9f2 | 2017-04-04 15:36:33 -0700 | [diff] [blame] | 841 | for (int i = 0; i < list.size(); i++) { |
| 842 | ServiceStartArgs ssa = list.get(i); |
| 843 | ServiceArgsData s = new ServiceArgsData(); |
| 844 | s.token = token; |
| 845 | s.taskRemoved = ssa.taskRemoved; |
| 846 | s.startId = ssa.startId; |
| 847 | s.flags = ssa.flags; |
| 848 | s.args = ssa.args; |
| 849 | |
| 850 | sendMessage(H.SERVICE_ARGS, s); |
| 851 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 852 | } |
| 853 | |
| 854 | public final void scheduleStopService(IBinder token) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 855 | sendMessage(H.STOP_SERVICE, token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 856 | } |
| 857 | |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 858 | public final void bindApplication(String processName, ApplicationInfo appInfo, |
| 859 | List<ProviderInfo> providers, ComponentName instrumentationName, |
| 860 | ProfilerInfo profilerInfo, Bundle instrumentationArgs, |
| 861 | IInstrumentationWatcher instrumentationWatcher, |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 862 | IUiAutomationConnection instrumentationUiConnection, int debugMode, |
Pablo Ceballos | a4d4e82 | 2015-10-05 10:27:52 -0700 | [diff] [blame] | 863 | boolean enableBinderTracking, boolean trackAllocation, |
| 864 | boolean isRestrictedBackupMode, boolean persistent, Configuration config, |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 865 | CompatibilityInfo compatInfo, Map services, Bundle coreSettings, |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 866 | String buildSerial, boolean autofillCompatibilityEnabled) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 867 | |
| 868 | if (services != null) { |
Makoto Onuki | 4589565 | 2018-05-07 14:43:05 -0700 | [diff] [blame] | 869 | if (false) { |
| 870 | // Test code to make sure the app could see the passed-in services. |
| 871 | for (Object oname : services.keySet()) { |
| 872 | if (services.get(oname) == null) { |
| 873 | continue; // AM just passed in a null service. |
| 874 | } |
| 875 | String name = (String) oname; |
| 876 | |
| 877 | // See b/79378449 about the following exemption. |
| 878 | switch (name) { |
| 879 | case "package": |
| 880 | case Context.WINDOW_SERVICE: |
| 881 | continue; |
| 882 | } |
| 883 | |
| 884 | if (ServiceManager.getService(name) == null) { |
| 885 | Log.wtf(TAG, "Service " + name + " should be accessible by this app"); |
| 886 | } |
| 887 | } |
| 888 | } |
| 889 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 890 | // Setup the service cache in the ServiceManager |
| 891 | ServiceManager.initServiceCache(services); |
| 892 | } |
| 893 | |
Svetoslav Ganov | 9aa597e | 2011-03-03 18:17:41 -0800 | [diff] [blame] | 894 | setCoreSettings(coreSettings); |
| 895 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 896 | AppBindData data = new AppBindData(); |
| 897 | data.processName = processName; |
| 898 | data.appInfo = appInfo; |
| 899 | data.providers = providers; |
| 900 | data.instrumentationName = instrumentationName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 901 | data.instrumentationArgs = instrumentationArgs; |
| 902 | data.instrumentationWatcher = instrumentationWatcher; |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 903 | data.instrumentationUiAutomationConnection = instrumentationUiConnection; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 904 | data.debugMode = debugMode; |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 905 | data.enableBinderTracking = enableBinderTracking; |
Man Cao | cfa78b2 | 2015-06-11 20:14:34 -0700 | [diff] [blame] | 906 | data.trackAllocation = trackAllocation; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 907 | data.restrictedBackupMode = isRestrictedBackupMode; |
Dianne Hackborn | 5d927c2 | 2011-09-02 12:22:18 -0700 | [diff] [blame] | 908 | data.persistent = persistent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 909 | data.config = config; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 910 | data.compatInfo = compatInfo; |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 911 | data.initProfilerInfo = profilerInfo; |
Svet Ganov | 37e4327 | 2016-09-09 16:01:32 -0700 | [diff] [blame] | 912 | data.buildSerial = buildSerial; |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 913 | data.autofillCompatibilityEnabled = autofillCompatibilityEnabled; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 914 | sendMessage(H.BIND_APPLICATION, data); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 915 | } |
| 916 | |
Torne (Richard Coles) | 466cbe4 | 2017-05-31 14:09:14 -0400 | [diff] [blame] | 917 | public final void runIsolatedEntryPoint(String entryPoint, String[] entryPointArgs) { |
| 918 | SomeArgs args = SomeArgs.obtain(); |
| 919 | args.arg1 = entryPoint; |
| 920 | args.arg2 = entryPointArgs; |
| 921 | sendMessage(H.RUN_ISOLATED_ENTRY_POINT, args); |
| 922 | } |
| 923 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 924 | public final void scheduleExit() { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 925 | sendMessage(H.EXIT_APPLICATION, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 926 | } |
| 927 | |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 928 | public final void scheduleSuicide() { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 929 | sendMessage(H.SUICIDE, null); |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 930 | } |
| 931 | |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 932 | public void scheduleApplicationInfoChanged(ApplicationInfo ai) { |
| 933 | sendMessage(H.APPLICATION_INFO_CHANGED, ai); |
| 934 | } |
| 935 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 936 | public void updateTimeZone() { |
| 937 | TimeZone.setDefault(null); |
| 938 | } |
| 939 | |
Robert Greenwalt | 03595d0 | 2010-11-02 14:08:23 -0700 | [diff] [blame] | 940 | public void clearDnsCache() { |
| 941 | // a non-standard API to get this to libcore |
| 942 | InetAddress.clearDnsCache(); |
Paul Jensen | e401d17 | 2014-09-12 10:47:39 -0400 | [diff] [blame] | 943 | // Allow libcore to perform the necessary actions as it sees fit upon a network |
| 944 | // configuration change. |
| 945 | NetworkEventDispatcher.getInstance().onNetworkConfigurationChanged(); |
Robert Greenwalt | 03595d0 | 2010-11-02 14:08:23 -0700 | [diff] [blame] | 946 | } |
| 947 | |
Jason Monk | 83520b9 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 948 | public void setHttpProxy(String host, String port, String exclList, Uri pacFileUrl) { |
Chalard Jean | 100df0a | 2018-05-15 23:11:45 +0900 | [diff] [blame] | 949 | final ConnectivityManager cm = ConnectivityManager.from( |
| 950 | getApplication() != null ? getApplication() : getSystemContext()); |
Paul Jensen | 72db88e | 2015-03-10 10:54:12 -0400 | [diff] [blame] | 951 | final Network network = cm.getBoundNetworkForProcess(); |
Paul Jensen | e0bef71 | 2014-12-10 15:12:18 -0500 | [diff] [blame] | 952 | if (network != null) { |
Paul Jensen | 72db88e | 2015-03-10 10:54:12 -0400 | [diff] [blame] | 953 | Proxy.setHttpProxySystemProperty(cm.getDefaultProxy()); |
Paul Jensen | e0bef71 | 2014-12-10 15:12:18 -0500 | [diff] [blame] | 954 | } else { |
| 955 | Proxy.setHttpProxySystemProperty(host, port, exclList, pacFileUrl); |
| 956 | } |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 957 | } |
| 958 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 959 | public void processInBackground() { |
| 960 | mH.removeMessages(H.GC_WHEN_IDLE); |
| 961 | mH.sendMessage(mH.obtainMessage(H.GC_WHEN_IDLE)); |
| 962 | } |
| 963 | |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 964 | public void dumpService(ParcelFileDescriptor pfd, IBinder servicetoken, String[] args) { |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 965 | DumpComponentInfo data = new DumpComponentInfo(); |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 966 | try { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 967 | data.fd = pfd.dup(); |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 968 | data.token = servicetoken; |
| 969 | data.args = args; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 970 | sendMessage(H.DUMP_SERVICE, data, 0, 0, true /*async*/); |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 971 | } catch (IOException e) { |
| 972 | Slog.w(TAG, "dumpService failed", e); |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 973 | } finally { |
| 974 | IoUtils.closeQuietly(pfd); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 975 | } |
| 976 | } |
| 977 | |
| 978 | // This function exists to make sure all receiver dispatching is |
| 979 | // correctly ordered, since these are one-way calls and the binder driver |
| 980 | // applies transaction ordering per object for such calls. |
| 981 | public void scheduleRegisteredReceiver(IIntentReceiver receiver, Intent intent, |
Dianne Hackborn | 68d881c | 2009-10-05 13:58:17 -0700 | [diff] [blame] | 982 | int resultCode, String dataStr, Bundle extras, boolean ordered, |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 983 | boolean sticky, int sendingUser, int processState) throws RemoteException { |
| 984 | updateProcessState(processState, false); |
Dianne Hackborn | 20e8098 | 2012-08-31 19:00:44 -0700 | [diff] [blame] | 985 | receiver.performReceive(intent, resultCode, dataStr, extras, ordered, |
| 986 | sticky, sendingUser); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 987 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 988 | |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 989 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 990 | public void scheduleLowMemory() { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 991 | sendMessage(H.LOW_MEMORY, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 992 | } |
| 993 | |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 994 | @Override |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 995 | public void profilerControl(boolean start, ProfilerInfo profilerInfo, int profileType) { |
| 996 | sendMessage(H.PROFILER_CONTROL, profilerInfo, start ? 1 : 0, profileType); |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 997 | } |
| 998 | |
Makoto Onuki | 4556b7b | 2017-07-07 14:58:58 -0700 | [diff] [blame] | 999 | @Override |
Christopher Ferris | 8d652f8 | 2017-04-11 16:29:18 -0700 | [diff] [blame] | 1000 | public void dumpHeap(boolean managed, boolean mallocInfo, boolean runGc, String path, |
| 1001 | ParcelFileDescriptor fd) { |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 1002 | DumpHeapData dhd = new DumpHeapData(); |
Christopher Ferris | 8d652f8 | 2017-04-11 16:29:18 -0700 | [diff] [blame] | 1003 | dhd.managed = managed; |
| 1004 | dhd.mallocInfo = mallocInfo; |
Makoto Onuki | 4556b7b | 2017-07-07 14:58:58 -0700 | [diff] [blame] | 1005 | dhd.runGc = runGc; |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 1006 | dhd.path = path; |
| 1007 | dhd.fd = fd; |
Christopher Ferris | 8d652f8 | 2017-04-11 16:29:18 -0700 | [diff] [blame] | 1008 | sendMessage(H.DUMP_HEAP, dhd, 0, 0, true /*async*/); |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 1009 | } |
| 1010 | |
Leonard Mosescu | f3409ce | 2016-10-06 17:32:05 -0700 | [diff] [blame] | 1011 | public void attachAgent(String agent) { |
| 1012 | sendMessage(H.ATTACH_AGENT, agent); |
| 1013 | } |
| 1014 | |
Dianne Hackborn | 06de2ea | 2009-05-21 12:56:43 -0700 | [diff] [blame] | 1015 | public void setSchedulingGroup(int group) { |
| 1016 | // Note: do this immediately, since going into the foreground |
| 1017 | // should happen regardless of what pending work we have to do |
| 1018 | // and the activity manager will wait for us to report back that |
| 1019 | // we are done before sending us to the background. |
| 1020 | try { |
| 1021 | Process.setProcessGroup(Process.myPid(), group); |
| 1022 | } catch (Exception e) { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 1023 | Slog.w(TAG, "Failed setting process group to " + group, e); |
Dianne Hackborn | 06de2ea | 2009-05-21 12:56:43 -0700 | [diff] [blame] | 1024 | } |
| 1025 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1026 | |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1027 | public void dispatchPackageBroadcast(int cmd, String[] packages) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1028 | sendMessage(H.DISPATCH_PACKAGE_BROADCAST, packages, cmd); |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1029 | } |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 1030 | |
| 1031 | public void scheduleCrash(String msg) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1032 | sendMessage(H.SCHEDULE_CRASH, msg); |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 1033 | } |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1034 | |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1035 | public void dumpActivity(ParcelFileDescriptor pfd, IBinder activitytoken, |
Dianne Hackborn | 30d7189 | 2010-12-11 10:37:55 -0800 | [diff] [blame] | 1036 | String prefix, String[] args) { |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1037 | DumpComponentInfo data = new DumpComponentInfo(); |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 1038 | try { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1039 | data.fd = pfd.dup(); |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 1040 | data.token = activitytoken; |
| 1041 | data.prefix = prefix; |
| 1042 | data.args = args; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1043 | sendMessage(H.DUMP_ACTIVITY, data, 0, 0, true /*async*/); |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 1044 | } catch (IOException e) { |
| 1045 | Slog.w(TAG, "dumpActivity failed", e); |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1046 | } finally { |
| 1047 | IoUtils.closeQuietly(pfd); |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1048 | } |
| 1049 | } |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 1050 | |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1051 | public void dumpProvider(ParcelFileDescriptor pfd, IBinder providertoken, |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1052 | String[] args) { |
| 1053 | DumpComponentInfo data = new DumpComponentInfo(); |
| 1054 | try { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1055 | data.fd = pfd.dup(); |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1056 | data.token = providertoken; |
| 1057 | data.args = args; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1058 | sendMessage(H.DUMP_PROVIDER, data, 0, 0, true /*async*/); |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1059 | } catch (IOException e) { |
| 1060 | Slog.w(TAG, "dumpProvider failed", e); |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1061 | } finally { |
| 1062 | IoUtils.closeQuietly(pfd); |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1063 | } |
| 1064 | } |
| 1065 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1066 | @Override |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1067 | public void dumpMemInfo(ParcelFileDescriptor pfd, Debug.MemoryInfo mem, boolean checkin, |
Colin Cross | c4fb5f9 | 2016-02-02 16:51:15 -0800 | [diff] [blame] | 1068 | boolean dumpFullInfo, boolean dumpDalvik, boolean dumpSummaryOnly, |
| 1069 | boolean dumpUnreachable, String[] args) { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1070 | FileOutputStream fout = new FileOutputStream(pfd.getFileDescriptor()); |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 1071 | PrintWriter pw = new FastPrintWriter(fout); |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 1072 | try { |
Colin Cross | c4fb5f9 | 2016-02-02 16:51:15 -0800 | [diff] [blame] | 1073 | dumpMemInfo(pw, mem, checkin, dumpFullInfo, dumpDalvik, dumpSummaryOnly, dumpUnreachable); |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 1074 | } finally { |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 1075 | pw.flush(); |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1076 | IoUtils.closeQuietly(pfd); |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 1077 | } |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 1078 | } |
| 1079 | |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 1080 | private void dumpMemInfo(PrintWriter pw, Debug.MemoryInfo memInfo, boolean checkin, |
Colin Cross | c4fb5f9 | 2016-02-02 16:51:15 -0800 | [diff] [blame] | 1081 | boolean dumpFullInfo, boolean dumpDalvik, boolean dumpSummaryOnly, boolean dumpUnreachable) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1082 | long nativeMax = Debug.getNativeHeapSize() / 1024; |
| 1083 | long nativeAllocated = Debug.getNativeHeapAllocatedSize() / 1024; |
| 1084 | long nativeFree = Debug.getNativeHeapFreeSize() / 1024; |
| 1085 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1086 | Runtime runtime = Runtime.getRuntime(); |
Mathieu Chartier | d288a26 | 2015-07-10 13:44:42 -0700 | [diff] [blame] | 1087 | runtime.gc(); // Do GC since countInstancesOfClass counts unreachable objects. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1088 | long dalvikMax = runtime.totalMemory() / 1024; |
| 1089 | long dalvikFree = runtime.freeMemory() / 1024; |
| 1090 | long dalvikAllocated = dalvikMax - dalvikFree; |
Richard Uhler | 2c03619 | 2016-09-14 09:48:31 +0100 | [diff] [blame] | 1091 | |
| 1092 | Class[] classesToCount = new Class[] { |
| 1093 | ContextImpl.class, |
| 1094 | Activity.class, |
| 1095 | WebView.class, |
| 1096 | OpenSSLSocketImpl.class |
| 1097 | }; |
| 1098 | long[] instanceCounts = VMDebug.countInstancesOfClasses(classesToCount, true); |
| 1099 | long appContextInstanceCount = instanceCounts[0]; |
| 1100 | long activityInstanceCount = instanceCounts[1]; |
| 1101 | long webviewInstanceCount = instanceCounts[2]; |
| 1102 | long openSslSocketCount = instanceCounts[3]; |
| 1103 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1104 | long viewInstanceCount = ViewDebug.getViewInstanceCount(); |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1105 | long viewRootInstanceCount = ViewDebug.getViewRootImplCount(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1106 | int globalAssetCount = AssetManager.getGlobalAssetCount(); |
| 1107 | int globalAssetManagerCount = AssetManager.getGlobalAssetManagerCount(); |
| 1108 | int binderLocalObjectCount = Debug.getBinderLocalObjectCount(); |
| 1109 | int binderProxyObjectCount = Debug.getBinderProxyObjectCount(); |
| 1110 | int binderDeathObjectCount = Debug.getBinderDeathObjectCount(); |
Dianne Hackborn | fabb70b | 2014-11-11 12:22:36 -0800 | [diff] [blame] | 1111 | long parcelSize = Parcel.getGlobalAllocSize(); |
| 1112 | long parcelCount = Parcel.getGlobalAllocCount(); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1113 | SQLiteDebug.PagerStats stats = SQLiteDebug.getDatabaseInfo(); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1114 | |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 1115 | dumpMemInfoTable(pw, memInfo, checkin, dumpFullInfo, dumpDalvik, dumpSummaryOnly, |
| 1116 | Process.myPid(), |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 1117 | (mBoundApplication != null) ? mBoundApplication.processName : "unknown", |
| 1118 | nativeMax, nativeAllocated, nativeFree, |
| 1119 | dalvikMax, dalvikAllocated, dalvikFree); |
| 1120 | |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 1121 | if (checkin) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1122 | // NOTE: if you change anything significant below, also consider changing |
| 1123 | // ACTIVITY_THREAD_CHECKIN_VERSION. |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 1124 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1125 | // Object counts |
| 1126 | pw.print(viewInstanceCount); pw.print(','); |
| 1127 | pw.print(viewRootInstanceCount); pw.print(','); |
| 1128 | pw.print(appContextInstanceCount); pw.print(','); |
| 1129 | pw.print(activityInstanceCount); pw.print(','); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1130 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1131 | pw.print(globalAssetCount); pw.print(','); |
| 1132 | pw.print(globalAssetManagerCount); pw.print(','); |
| 1133 | pw.print(binderLocalObjectCount); pw.print(','); |
| 1134 | pw.print(binderProxyObjectCount); pw.print(','); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1135 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1136 | pw.print(binderDeathObjectCount); pw.print(','); |
| 1137 | pw.print(openSslSocketCount); pw.print(','); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1138 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1139 | // SQL |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1140 | pw.print(stats.memoryUsed / 1024); pw.print(','); |
Jeff Brown | 2a293b6 | 2012-01-19 14:02:22 -0800 | [diff] [blame] | 1141 | pw.print(stats.memoryUsed / 1024); pw.print(','); |
| 1142 | pw.print(stats.pageCacheOverflow / 1024); pw.print(','); |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 1143 | pw.print(stats.largestMemAlloc / 1024); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1144 | for (int i = 0; i < stats.dbStats.size(); i++) { |
| 1145 | DbStats dbStats = stats.dbStats.get(i); |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 1146 | pw.print(','); pw.print(dbStats.dbName); |
| 1147 | pw.print(','); pw.print(dbStats.pageSize); |
| 1148 | pw.print(','); pw.print(dbStats.dbSize); |
| 1149 | pw.print(','); pw.print(dbStats.lookaside); |
| 1150 | pw.print(','); pw.print(dbStats.cache); |
| 1151 | pw.print(','); pw.print(dbStats.cache); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1152 | } |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 1153 | pw.println(); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1154 | |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 1155 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1156 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1157 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1158 | pw.println(" "); |
| 1159 | pw.println(" Objects"); |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1160 | printRow(pw, TWO_COUNT_COLUMNS, "Views:", viewInstanceCount, "ViewRootImpl:", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1161 | viewRootInstanceCount); |
| 1162 | |
| 1163 | printRow(pw, TWO_COUNT_COLUMNS, "AppContexts:", appContextInstanceCount, |
| 1164 | "Activities:", activityInstanceCount); |
| 1165 | |
| 1166 | printRow(pw, TWO_COUNT_COLUMNS, "Assets:", globalAssetCount, |
| 1167 | "AssetManagers:", globalAssetManagerCount); |
| 1168 | |
| 1169 | printRow(pw, TWO_COUNT_COLUMNS, "Local Binders:", binderLocalObjectCount, |
| 1170 | "Proxy Binders:", binderProxyObjectCount); |
Dianne Hackborn | fabb70b | 2014-11-11 12:22:36 -0800 | [diff] [blame] | 1171 | printRow(pw, TWO_COUNT_COLUMNS, "Parcel memory:", parcelSize/1024, |
| 1172 | "Parcel count:", parcelCount); |
| 1173 | printRow(pw, TWO_COUNT_COLUMNS, "Death Recipients:", binderDeathObjectCount, |
| 1174 | "OpenSSL Sockets:", openSslSocketCount); |
Richard Uhler | 2c03619 | 2016-09-14 09:48:31 +0100 | [diff] [blame] | 1175 | printRow(pw, ONE_COUNT_COLUMN, "WebViews:", webviewInstanceCount); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1176 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1177 | // SQLite mem info |
| 1178 | pw.println(" "); |
| 1179 | pw.println(" SQL"); |
Jeff Brown | 2a293b6 | 2012-01-19 14:02:22 -0800 | [diff] [blame] | 1180 | printRow(pw, ONE_COUNT_COLUMN, "MEMORY_USED:", stats.memoryUsed / 1024); |
| 1181 | printRow(pw, TWO_COUNT_COLUMNS, "PAGECACHE_OVERFLOW:", |
| 1182 | stats.pageCacheOverflow / 1024, "MALLOC_SIZE:", stats.largestMemAlloc / 1024); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1183 | pw.println(" "); |
| 1184 | int N = stats.dbStats.size(); |
| 1185 | if (N > 0) { |
| 1186 | pw.println(" DATABASES"); |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 1187 | printRow(pw, DB_INFO_FORMAT, "pgsz", "dbsz", "Lookaside(b)", "cache", |
Vasu Nori | 3c7131f | 2010-09-21 14:36:57 -0700 | [diff] [blame] | 1188 | "Dbname"); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1189 | for (int i = 0; i < N; i++) { |
| 1190 | DbStats dbStats = stats.dbStats.get(i); |
Vasu Nori | 3c7131f | 2010-09-21 14:36:57 -0700 | [diff] [blame] | 1191 | printRow(pw, DB_INFO_FORMAT, |
| 1192 | (dbStats.pageSize > 0) ? String.valueOf(dbStats.pageSize) : " ", |
| 1193 | (dbStats.dbSize > 0) ? String.valueOf(dbStats.dbSize) : " ", |
| 1194 | (dbStats.lookaside > 0) ? String.valueOf(dbStats.lookaside) : " ", |
| 1195 | dbStats.cache, dbStats.dbName); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1196 | } |
| 1197 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1198 | |
Dianne Hackborn | 82e1ee9 | 2009-08-11 18:56:41 -0700 | [diff] [blame] | 1199 | // Asset details. |
| 1200 | String assetAlloc = AssetManager.getAssetAllocations(); |
| 1201 | if (assetAlloc != null) { |
| 1202 | pw.println(" "); |
| 1203 | pw.println(" Asset Allocations"); |
| 1204 | pw.print(assetAlloc); |
| 1205 | } |
Colin Cross | c4fb5f9 | 2016-02-02 16:51:15 -0800 | [diff] [blame] | 1206 | |
| 1207 | // Unreachable native memory |
| 1208 | if (dumpUnreachable) { |
| 1209 | boolean showContents = ((mBoundApplication != null) |
| 1210 | && ((mBoundApplication.appInfo.flags&ApplicationInfo.FLAG_DEBUGGABLE) != 0)) |
| 1211 | || android.os.Build.IS_DEBUGGABLE; |
| 1212 | pw.println(" "); |
| 1213 | pw.println(" Unreachable memory"); |
| 1214 | pw.print(Debug.getUnreachableMemory(100, showContents)); |
| 1215 | } |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 1216 | } |
| 1217 | |
| 1218 | @Override |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 1219 | public void dumpMemInfoProto(ParcelFileDescriptor pfd, Debug.MemoryInfo mem, |
| 1220 | boolean dumpFullInfo, boolean dumpDalvik, boolean dumpSummaryOnly, |
| 1221 | boolean dumpUnreachable, String[] args) { |
| 1222 | ProtoOutputStream proto = new ProtoOutputStream(pfd.getFileDescriptor()); |
| 1223 | try { |
| 1224 | dumpMemInfo(proto, mem, dumpFullInfo, dumpDalvik, dumpSummaryOnly, dumpUnreachable); |
| 1225 | } finally { |
| 1226 | proto.flush(); |
| 1227 | IoUtils.closeQuietly(pfd); |
| 1228 | } |
| 1229 | } |
| 1230 | |
| 1231 | private void dumpMemInfo(ProtoOutputStream proto, Debug.MemoryInfo memInfo, |
| 1232 | boolean dumpFullInfo, boolean dumpDalvik, |
| 1233 | boolean dumpSummaryOnly, boolean dumpUnreachable) { |
| 1234 | long nativeMax = Debug.getNativeHeapSize() / 1024; |
| 1235 | long nativeAllocated = Debug.getNativeHeapAllocatedSize() / 1024; |
| 1236 | long nativeFree = Debug.getNativeHeapFreeSize() / 1024; |
| 1237 | |
| 1238 | Runtime runtime = Runtime.getRuntime(); |
| 1239 | runtime.gc(); // Do GC since countInstancesOfClass counts unreachable objects. |
| 1240 | long dalvikMax = runtime.totalMemory() / 1024; |
| 1241 | long dalvikFree = runtime.freeMemory() / 1024; |
| 1242 | long dalvikAllocated = dalvikMax - dalvikFree; |
| 1243 | |
| 1244 | Class[] classesToCount = new Class[] { |
| 1245 | ContextImpl.class, |
| 1246 | Activity.class, |
| 1247 | WebView.class, |
| 1248 | OpenSSLSocketImpl.class |
| 1249 | }; |
| 1250 | long[] instanceCounts = VMDebug.countInstancesOfClasses(classesToCount, true); |
| 1251 | long appContextInstanceCount = instanceCounts[0]; |
| 1252 | long activityInstanceCount = instanceCounts[1]; |
| 1253 | long webviewInstanceCount = instanceCounts[2]; |
| 1254 | long openSslSocketCount = instanceCounts[3]; |
| 1255 | |
| 1256 | long viewInstanceCount = ViewDebug.getViewInstanceCount(); |
| 1257 | long viewRootInstanceCount = ViewDebug.getViewRootImplCount(); |
| 1258 | int globalAssetCount = AssetManager.getGlobalAssetCount(); |
| 1259 | int globalAssetManagerCount = AssetManager.getGlobalAssetManagerCount(); |
| 1260 | int binderLocalObjectCount = Debug.getBinderLocalObjectCount(); |
| 1261 | int binderProxyObjectCount = Debug.getBinderProxyObjectCount(); |
| 1262 | int binderDeathObjectCount = Debug.getBinderDeathObjectCount(); |
| 1263 | long parcelSize = Parcel.getGlobalAllocSize(); |
| 1264 | long parcelCount = Parcel.getGlobalAllocCount(); |
| 1265 | SQLiteDebug.PagerStats stats = SQLiteDebug.getDatabaseInfo(); |
| 1266 | |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 1267 | final long mToken = proto.start(MemInfoDumpProto.AppData.PROCESS_MEMORY); |
| 1268 | proto.write(MemInfoDumpProto.ProcessMemory.PID, Process.myPid()); |
| 1269 | proto.write(MemInfoDumpProto.ProcessMemory.PROCESS_NAME, |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 1270 | (mBoundApplication != null) ? mBoundApplication.processName : "unknown"); |
| 1271 | dumpMemInfoTable(proto, memInfo, dumpDalvik, dumpSummaryOnly, |
| 1272 | nativeMax, nativeAllocated, nativeFree, |
| 1273 | dalvikMax, dalvikAllocated, dalvikFree); |
| 1274 | proto.end(mToken); |
| 1275 | |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 1276 | final long oToken = proto.start(MemInfoDumpProto.AppData.OBJECTS); |
| 1277 | proto.write(MemInfoDumpProto.AppData.ObjectStats.VIEW_INSTANCE_COUNT, |
| 1278 | viewInstanceCount); |
| 1279 | proto.write(MemInfoDumpProto.AppData.ObjectStats.VIEW_ROOT_INSTANCE_COUNT, |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 1280 | viewRootInstanceCount); |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 1281 | proto.write(MemInfoDumpProto.AppData.ObjectStats.APP_CONTEXT_INSTANCE_COUNT, |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 1282 | appContextInstanceCount); |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 1283 | proto.write(MemInfoDumpProto.AppData.ObjectStats.ACTIVITY_INSTANCE_COUNT, |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 1284 | activityInstanceCount); |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 1285 | proto.write(MemInfoDumpProto.AppData.ObjectStats.GLOBAL_ASSET_COUNT, |
| 1286 | globalAssetCount); |
| 1287 | proto.write(MemInfoDumpProto.AppData.ObjectStats.GLOBAL_ASSET_MANAGER_COUNT, |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 1288 | globalAssetManagerCount); |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 1289 | proto.write(MemInfoDumpProto.AppData.ObjectStats.LOCAL_BINDER_OBJECT_COUNT, |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 1290 | binderLocalObjectCount); |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 1291 | proto.write(MemInfoDumpProto.AppData.ObjectStats.PROXY_BINDER_OBJECT_COUNT, |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 1292 | binderProxyObjectCount); |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 1293 | proto.write(MemInfoDumpProto.AppData.ObjectStats.PARCEL_MEMORY_KB, |
| 1294 | parcelSize / 1024); |
| 1295 | proto.write(MemInfoDumpProto.AppData.ObjectStats.PARCEL_COUNT, parcelCount); |
| 1296 | proto.write(MemInfoDumpProto.AppData.ObjectStats.BINDER_OBJECT_DEATH_COUNT, |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 1297 | binderDeathObjectCount); |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 1298 | proto.write(MemInfoDumpProto.AppData.ObjectStats.OPEN_SSL_SOCKET_COUNT, |
| 1299 | openSslSocketCount); |
| 1300 | proto.write(MemInfoDumpProto.AppData.ObjectStats.WEBVIEW_INSTANCE_COUNT, |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 1301 | webviewInstanceCount); |
| 1302 | proto.end(oToken); |
| 1303 | |
| 1304 | // SQLite mem info |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 1305 | final long sToken = proto.start(MemInfoDumpProto.AppData.SQL); |
| 1306 | proto.write(MemInfoDumpProto.AppData.SqlStats.MEMORY_USED_KB, |
| 1307 | stats.memoryUsed / 1024); |
| 1308 | proto.write(MemInfoDumpProto.AppData.SqlStats.PAGECACHE_OVERFLOW_KB, |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 1309 | stats.pageCacheOverflow / 1024); |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 1310 | proto.write(MemInfoDumpProto.AppData.SqlStats.MALLOC_SIZE_KB, |
| 1311 | stats.largestMemAlloc / 1024); |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 1312 | int n = stats.dbStats.size(); |
| 1313 | for (int i = 0; i < n; i++) { |
| 1314 | DbStats dbStats = stats.dbStats.get(i); |
| 1315 | |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 1316 | final long dToken = proto.start(MemInfoDumpProto.AppData.SqlStats.DATABASES); |
| 1317 | proto.write(MemInfoDumpProto.AppData.SqlStats.Database.NAME, dbStats.dbName); |
| 1318 | proto.write(MemInfoDumpProto.AppData.SqlStats.Database.PAGE_SIZE, dbStats.pageSize); |
| 1319 | proto.write(MemInfoDumpProto.AppData.SqlStats.Database.DB_SIZE, dbStats.dbSize); |
| 1320 | proto.write(MemInfoDumpProto.AppData.SqlStats.Database.LOOKASIDE_B, |
| 1321 | dbStats.lookaside); |
| 1322 | proto.write(MemInfoDumpProto.AppData.SqlStats.Database.CACHE, dbStats.cache); |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 1323 | proto.end(dToken); |
| 1324 | } |
| 1325 | proto.end(sToken); |
| 1326 | |
| 1327 | // Asset details. |
| 1328 | String assetAlloc = AssetManager.getAssetAllocations(); |
| 1329 | if (assetAlloc != null) { |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 1330 | proto.write(MemInfoDumpProto.AppData.ASSET_ALLOCATIONS, assetAlloc); |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 1331 | } |
| 1332 | |
| 1333 | // Unreachable native memory |
| 1334 | if (dumpUnreachable) { |
| 1335 | int flags = mBoundApplication == null ? 0 : mBoundApplication.appInfo.flags; |
| 1336 | boolean showContents = (flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0 |
| 1337 | || android.os.Build.IS_DEBUGGABLE; |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 1338 | proto.write(MemInfoDumpProto.AppData.UNREACHABLE_MEMORY, |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 1339 | Debug.getUnreachableMemory(100, showContents)); |
| 1340 | } |
| 1341 | } |
| 1342 | |
| 1343 | @Override |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1344 | public void dumpGfxInfo(ParcelFileDescriptor pfd, String[] args) { |
Chris Craik | fc29424 | 2016-12-13 18:10:46 -0800 | [diff] [blame] | 1345 | nDumpGraphicsInfo(pfd.getFileDescriptor()); |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1346 | WindowManagerGlobal.getInstance().dumpGfxInfo(pfd.getFileDescriptor(), args); |
| 1347 | IoUtils.closeQuietly(pfd); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1348 | } |
| 1349 | |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1350 | private void dumpDatabaseInfo(ParcelFileDescriptor pfd, String[] args) { |
| 1351 | PrintWriter pw = new FastPrintWriter( |
| 1352 | new FileOutputStream(pfd.getFileDescriptor())); |
Jeff Brown | 6754ba2 | 2011-12-14 20:20:01 -0800 | [diff] [blame] | 1353 | PrintWriterPrinter printer = new PrintWriterPrinter(pw); |
| 1354 | SQLiteDebug.dump(printer, args); |
| 1355 | pw.flush(); |
| 1356 | } |
| 1357 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1358 | @Override |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1359 | public void dumpDbInfo(final ParcelFileDescriptor pfd, final String[] args) { |
riddle_hsu | 1d6c40a | 2014-07-31 00:18:00 +0800 | [diff] [blame] | 1360 | if (mSystemThread) { |
Felipe Leme | 29de492 | 2016-06-07 16:14:07 -0700 | [diff] [blame] | 1361 | // Ensure this invocation is asynchronous to prevent writer waiting if buffer cannot |
| 1362 | // be consumed. But it must duplicate the file descriptor first, since caller might |
| 1363 | // be closing it. |
| 1364 | final ParcelFileDescriptor dup; |
| 1365 | try { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1366 | dup = pfd.dup(); |
Felipe Leme | 29de492 | 2016-06-07 16:14:07 -0700 | [diff] [blame] | 1367 | } catch (IOException e) { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1368 | Log.w(TAG, "Could not dup FD " + pfd.getFileDescriptor().getInt$()); |
Felipe Leme | 29de492 | 2016-06-07 16:14:07 -0700 | [diff] [blame] | 1369 | return; |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1370 | } finally { |
| 1371 | IoUtils.closeQuietly(pfd); |
Felipe Leme | 29de492 | 2016-06-07 16:14:07 -0700 | [diff] [blame] | 1372 | } |
| 1373 | |
riddle_hsu | 1d6c40a | 2014-07-31 00:18:00 +0800 | [diff] [blame] | 1374 | AsyncTask.THREAD_POOL_EXECUTOR.execute(new Runnable() { |
| 1375 | @Override |
| 1376 | public void run() { |
Felipe Leme | c74972f | 2016-06-08 09:12:37 -0700 | [diff] [blame] | 1377 | try { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1378 | dumpDatabaseInfo(dup, args); |
Felipe Leme | c74972f | 2016-06-08 09:12:37 -0700 | [diff] [blame] | 1379 | } finally { |
| 1380 | IoUtils.closeQuietly(dup); |
| 1381 | } |
riddle_hsu | 1d6c40a | 2014-07-31 00:18:00 +0800 | [diff] [blame] | 1382 | } |
| 1383 | }); |
| 1384 | } else { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1385 | dumpDatabaseInfo(pfd, args); |
| 1386 | IoUtils.closeQuietly(pfd); |
riddle_hsu | 1d6c40a | 2014-07-31 00:18:00 +0800 | [diff] [blame] | 1387 | } |
| 1388 | } |
| 1389 | |
| 1390 | @Override |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1391 | public void unstableProviderDied(IBinder provider) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1392 | sendMessage(H.UNSTABLE_PROVIDER_DIED, provider); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1393 | } |
| 1394 | |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 1395 | @Override |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 1396 | public void requestAssistContextExtras(IBinder activityToken, IBinder requestToken, |
Svet Ganov | fd31f85 | 2017-04-26 15:54:27 -0700 | [diff] [blame] | 1397 | int requestType, int sessionId, int flags) { |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 1398 | RequestAssistContextExtras cmd = new RequestAssistContextExtras(); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 1399 | cmd.activityToken = activityToken; |
| 1400 | cmd.requestToken = requestToken; |
| 1401 | cmd.requestType = requestType; |
Amith Yamasani | 4f128e4 | 2016-05-10 11:44:12 -0700 | [diff] [blame] | 1402 | cmd.sessionId = sessionId; |
Svet Ganov | fd31f85 | 2017-04-26 15:54:27 -0700 | [diff] [blame] | 1403 | cmd.flags = flags; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1404 | sendMessage(H.REQUEST_ASSIST_CONTEXT_EXTRAS, cmd); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 1405 | } |
| 1406 | |
Svetoslav Ganov | 9aa597e | 2011-03-03 18:17:41 -0800 | [diff] [blame] | 1407 | public void setCoreSettings(Bundle coreSettings) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1408 | sendMessage(H.SET_CORE_SETTINGS, coreSettings); |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1409 | } |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1410 | |
| 1411 | public void updatePackageCompatibilityInfo(String pkg, CompatibilityInfo info) { |
| 1412 | UpdateCompatibilityData ucd = new UpdateCompatibilityData(); |
| 1413 | ucd.pkg = pkg; |
| 1414 | ucd.info = info; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1415 | sendMessage(H.UPDATE_PACKAGE_COMPATIBILITY_INFO, ucd); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1416 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1417 | |
| 1418 | public void scheduleTrimMemory(int level) { |
Jorim Jaggi | b29e318 | 2018-04-30 18:51:56 +0200 | [diff] [blame] | 1419 | final Runnable r = PooledLambda.obtainRunnable(ActivityThread::handleTrimMemory, |
| 1420 | ActivityThread.this, level); |
| 1421 | // Schedule trimming memory after drawing the frame to minimize jank-risk. |
| 1422 | Choreographer choreographer = Choreographer.getMainThreadInstance(); |
| 1423 | if (choreographer != null) { |
| 1424 | choreographer.postCallback(Choreographer.CALLBACK_COMMIT, r, null); |
| 1425 | } else { |
| 1426 | mH.post(r); |
| 1427 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1428 | } |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1429 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1430 | public void scheduleTranslucentConversionComplete(IBinder token, boolean drawComplete) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1431 | sendMessage(H.TRANSLUCENT_CONVERSION_COMPLETE, token, drawComplete ? 1 : 0); |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1432 | } |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 1433 | |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1434 | public void scheduleOnNewActivityOptions(IBinder token, Bundle options) { |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1435 | sendMessage(H.ON_NEW_ACTIVITY_OPTIONS, |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1436 | new Pair<IBinder, ActivityOptions>(token, ActivityOptions.fromBundle(options))); |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1437 | } |
| 1438 | |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 1439 | public void setProcessState(int state) { |
| 1440 | updateProcessState(state, true); |
| 1441 | } |
| 1442 | |
| 1443 | public void updateProcessState(int processState, boolean fromIpc) { |
| 1444 | synchronized (this) { |
| 1445 | if (mLastProcessState != processState) { |
| 1446 | mLastProcessState = processState; |
Mathieu Chartier | 1e37090 | 2013-07-18 10:58:01 -0700 | [diff] [blame] | 1447 | // Update Dalvik state based on ActivityManager.PROCESS_STATE_* constants. |
| 1448 | final int DALVIK_PROCESS_STATE_JANK_PERCEPTIBLE = 0; |
| 1449 | final int DALVIK_PROCESS_STATE_JANK_IMPERCEPTIBLE = 1; |
| 1450 | int dalvikProcessState = DALVIK_PROCESS_STATE_JANK_IMPERCEPTIBLE; |
| 1451 | // TODO: Tune this since things like gmail sync are important background but not jank perceptible. |
| 1452 | if (processState <= ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND) { |
| 1453 | dalvikProcessState = DALVIK_PROCESS_STATE_JANK_PERCEPTIBLE; |
| 1454 | } |
| 1455 | VMRuntime.getRuntime().updateProcessState(dalvikProcessState); |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 1456 | if (false) { |
| 1457 | Slog.i(TAG, "******************* PROCESS STATE CHANGED TO: " + processState |
| 1458 | + (fromIpc ? " (from ipc": "")); |
| 1459 | } |
| 1460 | } |
| 1461 | } |
| 1462 | } |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 1463 | |
Sudheer Shanka | 84a4895 | 2017-03-08 18:19:01 -0800 | [diff] [blame] | 1464 | /** |
| 1465 | * Updates {@link #mNetworkBlockSeq}. This is used by ActivityManagerService to inform |
| 1466 | * the main thread that it needs to wait for the network rules to get updated before |
| 1467 | * launching an activity. |
| 1468 | */ |
| 1469 | @Override |
| 1470 | public void setNetworkBlockSeq(long procStateSeq) { |
| 1471 | synchronized (mNetworkPolicyLock) { |
| 1472 | mNetworkBlockSeq = procStateSeq; |
| 1473 | } |
| 1474 | } |
| 1475 | |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 1476 | @Override |
| 1477 | public void scheduleInstallProvider(ProviderInfo provider) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1478 | sendMessage(H.INSTALL_PROVIDER, provider); |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 1479 | } |
Narayan Kamath | ccb2a086 | 2013-12-19 14:49:36 +0000 | [diff] [blame] | 1480 | |
| 1481 | @Override |
Neil Fuller | b7146fe | 2016-11-15 16:52:15 +0000 | [diff] [blame] | 1482 | public final void updateTimePrefs(int timeFormatPreference) { |
| 1483 | final Boolean timeFormatPreferenceBool; |
| 1484 | // For convenience we are using the Intent extra values. |
| 1485 | if (timeFormatPreference == Intent.EXTRA_TIME_PREF_VALUE_USE_12_HOUR) { |
| 1486 | timeFormatPreferenceBool = Boolean.FALSE; |
| 1487 | } else if (timeFormatPreference == Intent.EXTRA_TIME_PREF_VALUE_USE_24_HOUR) { |
| 1488 | timeFormatPreferenceBool = Boolean.TRUE; |
| 1489 | } else { |
| 1490 | // timeFormatPreference == Intent.EXTRA_TIME_PREF_VALUE_USE_LOCALE_DEFAULT |
| 1491 | // (or unknown). |
| 1492 | timeFormatPreferenceBool = null; |
| 1493 | } |
| 1494 | DateFormat.set24HourTimePref(timeFormatPreferenceBool); |
Narayan Kamath | ccb2a086 | 2013-12-19 14:49:36 +0000 | [diff] [blame] | 1495 | } |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 1496 | |
| 1497 | @Override |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 1498 | public void scheduleEnterAnimationComplete(IBinder token) { |
| 1499 | sendMessage(H.ENTER_ANIMATION_COMPLETE, token); |
| 1500 | } |
Jeff Sharkey | 605eb79 | 2014-11-04 13:34:06 -0800 | [diff] [blame] | 1501 | |
| 1502 | @Override |
| 1503 | public void notifyCleartextNetwork(byte[] firstPacket) { |
| 1504 | if (StrictMode.vmCleartextNetworkEnabled()) { |
| 1505 | StrictMode.onCleartextNetworkDetected(firstPacket); |
| 1506 | } |
| 1507 | } |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 1508 | |
| 1509 | @Override |
| 1510 | public void startBinderTracking() { |
| 1511 | sendMessage(H.START_BINDER_TRACKING, null); |
| 1512 | } |
| 1513 | |
| 1514 | @Override |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1515 | public void stopBinderTrackingAndDump(ParcelFileDescriptor pfd) { |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 1516 | try { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1517 | sendMessage(H.STOP_BINDER_TRACKING_AND_DUMP, pfd.dup()); |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 1518 | } catch (IOException e) { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1519 | } finally { |
| 1520 | IoUtils.closeQuietly(pfd); |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 1521 | } |
| 1522 | } |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 1523 | |
| 1524 | @Override |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1525 | public void scheduleLocalVoiceInteractionStarted(IBinder token, |
| 1526 | IVoiceInteractor voiceInteractor) throws RemoteException { |
| 1527 | SomeArgs args = SomeArgs.obtain(); |
| 1528 | args.arg1 = token; |
| 1529 | args.arg2 = voiceInteractor; |
| 1530 | sendMessage(H.LOCAL_VOICE_INTERACTION_STARTED, args); |
| 1531 | } |
Chad Brubaker | c72875b | 2016-04-27 16:35:11 -0700 | [diff] [blame] | 1532 | |
| 1533 | @Override |
| 1534 | public void handleTrustStorageUpdate() { |
| 1535 | NetworkSecurityPolicy.getInstance().handleTrustStorageUpdate(); |
| 1536 | } |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 1537 | |
| 1538 | @Override |
| 1539 | public void scheduleTransaction(ClientTransaction transaction) throws RemoteException { |
| 1540 | ActivityThread.this.scheduleTransaction(transaction); |
| 1541 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1542 | } |
| 1543 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 1544 | @Override |
| 1545 | public void updatePendingConfiguration(Configuration config) { |
| 1546 | mAppThread.updatePendingConfiguration(config); |
| 1547 | } |
| 1548 | |
| 1549 | @Override |
| 1550 | public void updateProcessState(int processState, boolean fromIpc) { |
| 1551 | mAppThread.updateProcessState(processState, fromIpc); |
| 1552 | } |
| 1553 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 1554 | class H extends Handler { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1555 | public static final int BIND_APPLICATION = 110; |
| 1556 | public static final int EXIT_APPLICATION = 111; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1557 | public static final int RECEIVER = 113; |
| 1558 | public static final int CREATE_SERVICE = 114; |
| 1559 | public static final int SERVICE_ARGS = 115; |
| 1560 | public static final int STOP_SERVICE = 116; |
Dianne Hackborn | 0923328 | 2014-04-30 11:33:59 -0700 | [diff] [blame] | 1561 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1562 | public static final int CONFIGURATION_CHANGED = 118; |
| 1563 | public static final int CLEAN_UP_CONTEXT = 119; |
| 1564 | public static final int GC_WHEN_IDLE = 120; |
| 1565 | public static final int BIND_SERVICE = 121; |
| 1566 | public static final int UNBIND_SERVICE = 122; |
| 1567 | public static final int DUMP_SERVICE = 123; |
| 1568 | public static final int LOW_MEMORY = 124; |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 1569 | public static final int PROFILER_CONTROL = 127; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1570 | public static final int CREATE_BACKUP_AGENT = 128; |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 1571 | public static final int DESTROY_BACKUP_AGENT = 129; |
| 1572 | public static final int SUICIDE = 130; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1573 | public static final int REMOVE_PROVIDER = 131; |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 1574 | public static final int ENABLE_JIT = 132; |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1575 | public static final int DISPATCH_PACKAGE_BROADCAST = 133; |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 1576 | public static final int SCHEDULE_CRASH = 134; |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 1577 | public static final int DUMP_HEAP = 135; |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1578 | public static final int DUMP_ACTIVITY = 136; |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1579 | public static final int SLEEPING = 137; |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1580 | public static final int SET_CORE_SETTINGS = 138; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1581 | public static final int UPDATE_PACKAGE_COMPATIBILITY_INFO = 139; |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1582 | public static final int DUMP_PROVIDER = 141; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1583 | public static final int UNSTABLE_PROVIDER_DIED = 142; |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 1584 | public static final int REQUEST_ASSIST_CONTEXT_EXTRAS = 143; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1585 | public static final int TRANSLUCENT_CONVERSION_COMPLETE = 144; |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 1586 | public static final int INSTALL_PROVIDER = 145; |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1587 | public static final int ON_NEW_ACTIVITY_OPTIONS = 146; |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 1588 | public static final int ENTER_ANIMATION_COMPLETE = 149; |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 1589 | public static final int START_BINDER_TRACKING = 150; |
| 1590 | public static final int STOP_BINDER_TRACKING_AND_DUMP = 151; |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1591 | public static final int LOCAL_VOICE_INTERACTION_STARTED = 154; |
Leonard Mosescu | f3409ce | 2016-10-06 17:32:05 -0700 | [diff] [blame] | 1592 | public static final int ATTACH_AGENT = 155; |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 1593 | public static final int APPLICATION_INFO_CHANGED = 156; |
Torne (Richard Coles) | 466cbe4 | 2017-05-31 14:09:14 -0400 | [diff] [blame] | 1594 | public static final int RUN_ISOLATED_ENTRY_POINT = 158; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 1595 | public static final int EXECUTE_TRANSACTION = 159; |
Andrii Kulian | 320e3b5 | 2018-05-03 16:26:25 -0700 | [diff] [blame] | 1596 | public static final int RELAUNCH_ACTIVITY = 160; |
Narayan Kamath | ccb2a086 | 2013-12-19 14:49:36 +0000 | [diff] [blame] | 1597 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1598 | String codeToString(int code) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 1599 | if (DEBUG_MESSAGES) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1600 | switch (code) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1601 | case BIND_APPLICATION: return "BIND_APPLICATION"; |
| 1602 | case EXIT_APPLICATION: return "EXIT_APPLICATION"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1603 | case RECEIVER: return "RECEIVER"; |
| 1604 | case CREATE_SERVICE: return "CREATE_SERVICE"; |
| 1605 | case SERVICE_ARGS: return "SERVICE_ARGS"; |
| 1606 | case STOP_SERVICE: return "STOP_SERVICE"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1607 | case CONFIGURATION_CHANGED: return "CONFIGURATION_CHANGED"; |
| 1608 | case CLEAN_UP_CONTEXT: return "CLEAN_UP_CONTEXT"; |
| 1609 | case GC_WHEN_IDLE: return "GC_WHEN_IDLE"; |
| 1610 | case BIND_SERVICE: return "BIND_SERVICE"; |
| 1611 | case UNBIND_SERVICE: return "UNBIND_SERVICE"; |
| 1612 | case DUMP_SERVICE: return "DUMP_SERVICE"; |
| 1613 | case LOW_MEMORY: return "LOW_MEMORY"; |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 1614 | case PROFILER_CONTROL: return "PROFILER_CONTROL"; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1615 | case CREATE_BACKUP_AGENT: return "CREATE_BACKUP_AGENT"; |
| 1616 | case DESTROY_BACKUP_AGENT: return "DESTROY_BACKUP_AGENT"; |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 1617 | case SUICIDE: return "SUICIDE"; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1618 | case REMOVE_PROVIDER: return "REMOVE_PROVIDER"; |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 1619 | case ENABLE_JIT: return "ENABLE_JIT"; |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1620 | case DISPATCH_PACKAGE_BROADCAST: return "DISPATCH_PACKAGE_BROADCAST"; |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 1621 | case SCHEDULE_CRASH: return "SCHEDULE_CRASH"; |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 1622 | case DUMP_HEAP: return "DUMP_HEAP"; |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1623 | case DUMP_ACTIVITY: return "DUMP_ACTIVITY"; |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1624 | case SLEEPING: return "SLEEPING"; |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1625 | case SET_CORE_SETTINGS: return "SET_CORE_SETTINGS"; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1626 | case UPDATE_PACKAGE_COMPATIBILITY_INFO: return "UPDATE_PACKAGE_COMPATIBILITY_INFO"; |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1627 | case DUMP_PROVIDER: return "DUMP_PROVIDER"; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1628 | case UNSTABLE_PROVIDER_DIED: return "UNSTABLE_PROVIDER_DIED"; |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 1629 | case REQUEST_ASSIST_CONTEXT_EXTRAS: return "REQUEST_ASSIST_CONTEXT_EXTRAS"; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1630 | case TRANSLUCENT_CONVERSION_COMPLETE: return "TRANSLUCENT_CONVERSION_COMPLETE"; |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 1631 | case INSTALL_PROVIDER: return "INSTALL_PROVIDER"; |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1632 | case ON_NEW_ACTIVITY_OPTIONS: return "ON_NEW_ACTIVITY_OPTIONS"; |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 1633 | case ENTER_ANIMATION_COMPLETE: return "ENTER_ANIMATION_COMPLETE"; |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1634 | case LOCAL_VOICE_INTERACTION_STARTED: return "LOCAL_VOICE_INTERACTION_STARTED"; |
Leonard Mosescu | f3409ce | 2016-10-06 17:32:05 -0700 | [diff] [blame] | 1635 | case ATTACH_AGENT: return "ATTACH_AGENT"; |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 1636 | case APPLICATION_INFO_CHANGED: return "APPLICATION_INFO_CHANGED"; |
Torne (Richard Coles) | 466cbe4 | 2017-05-31 14:09:14 -0400 | [diff] [blame] | 1637 | case RUN_ISOLATED_ENTRY_POINT: return "RUN_ISOLATED_ENTRY_POINT"; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 1638 | case EXECUTE_TRANSACTION: return "EXECUTE_TRANSACTION"; |
Andrii Kulian | 320e3b5 | 2018-05-03 16:26:25 -0700 | [diff] [blame] | 1639 | case RELAUNCH_ACTIVITY: return "RELAUNCH_ACTIVITY"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1640 | } |
| 1641 | } |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 1642 | return Integer.toString(code); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1643 | } |
| 1644 | public void handleMessage(Message msg) { |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 1645 | 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] | 1646 | switch (msg.what) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1647 | case BIND_APPLICATION: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1648 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "bindApplication"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1649 | AppBindData data = (AppBindData)msg.obj; |
| 1650 | handleBindApplication(data); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1651 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1652 | break; |
| 1653 | case EXIT_APPLICATION: |
| 1654 | if (mInitialApplication != null) { |
| 1655 | mInitialApplication.onTerminate(); |
| 1656 | } |
| 1657 | Looper.myLooper().quit(); |
| 1658 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1659 | case RECEIVER: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1660 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "broadcastReceiveComp"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1661 | handleReceiver((ReceiverData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1662 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1663 | break; |
| 1664 | case CREATE_SERVICE: |
Tim Murray | b6f5a42 | 2016-04-07 15:25:22 -0700 | [diff] [blame] | 1665 | 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] | 1666 | handleCreateService((CreateServiceData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1667 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1668 | break; |
| 1669 | case BIND_SERVICE: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1670 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "serviceBind"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1671 | handleBindService((BindServiceData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1672 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1673 | break; |
| 1674 | case UNBIND_SERVICE: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1675 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "serviceUnbind"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1676 | handleUnbindService((BindServiceData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1677 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1678 | break; |
| 1679 | case SERVICE_ARGS: |
Tim Murray | b6f5a42 | 2016-04-07 15:25:22 -0700 | [diff] [blame] | 1680 | 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] | 1681 | handleServiceArgs((ServiceArgsData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1682 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1683 | break; |
| 1684 | case STOP_SERVICE: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1685 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "serviceStop"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1686 | handleStopService((IBinder)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1687 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1688 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1689 | case CONFIGURATION_CHANGED: |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 1690 | handleConfigurationChanged((Configuration) msg.obj); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1691 | break; |
| 1692 | case CLEAN_UP_CONTEXT: |
| 1693 | ContextCleanupInfo cci = (ContextCleanupInfo)msg.obj; |
| 1694 | cci.context.performFinalCleanup(cci.who, cci.what); |
| 1695 | break; |
| 1696 | case GC_WHEN_IDLE: |
| 1697 | scheduleGcIdler(); |
| 1698 | break; |
| 1699 | case DUMP_SERVICE: |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1700 | handleDumpService((DumpComponentInfo)msg.obj); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1701 | break; |
| 1702 | case LOW_MEMORY: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1703 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "lowMemory"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1704 | handleLowMemory(); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1705 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1706 | break; |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 1707 | case PROFILER_CONTROL: |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 1708 | handleProfilerControl(msg.arg1 != 0, (ProfilerInfo)msg.obj, msg.arg2); |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 1709 | break; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1710 | case CREATE_BACKUP_AGENT: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1711 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "backupCreateAgent"); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1712 | handleCreateBackupAgent((CreateBackupAgentData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1713 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1714 | break; |
| 1715 | case DESTROY_BACKUP_AGENT: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1716 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "backupDestroyAgent"); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1717 | handleDestroyBackupAgent((CreateBackupAgentData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1718 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1719 | break; |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 1720 | case SUICIDE: |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1721 | Process.killProcess(Process.myPid()); |
| 1722 | break; |
| 1723 | case REMOVE_PROVIDER: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1724 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "providerRemove"); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1725 | completeRemoveProvider((ProviderRefCount)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1726 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 1727 | break; |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 1728 | case ENABLE_JIT: |
| 1729 | ensureJitEnabled(); |
| 1730 | break; |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1731 | case DISPATCH_PACKAGE_BROADCAST: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1732 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "broadcastPackage"); |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1733 | handleDispatchPackageBroadcast(msg.arg1, (String[])msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1734 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1735 | break; |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 1736 | case SCHEDULE_CRASH: |
| 1737 | throw new RemoteServiceException((String)msg.obj); |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 1738 | case DUMP_HEAP: |
Christopher Ferris | 8d652f8 | 2017-04-11 16:29:18 -0700 | [diff] [blame] | 1739 | handleDumpHeap((DumpHeapData) msg.obj); |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 1740 | break; |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1741 | case DUMP_ACTIVITY: |
| 1742 | handleDumpActivity((DumpComponentInfo)msg.obj); |
| 1743 | break; |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1744 | case DUMP_PROVIDER: |
| 1745 | handleDumpProvider((DumpComponentInfo)msg.obj); |
| 1746 | break; |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1747 | case SLEEPING: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1748 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "sleeping"); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1749 | handleSleeping((IBinder)msg.obj, msg.arg1 != 0); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1750 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1751 | break; |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1752 | case SET_CORE_SETTINGS: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1753 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "setCoreSettings"); |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1754 | handleSetCoreSettings((Bundle) msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1755 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1756 | break; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1757 | case UPDATE_PACKAGE_COMPATIBILITY_INFO: |
| 1758 | handleUpdatePackageCompatibilityInfo((UpdateCompatibilityData)msg.obj); |
Dianne Hackborn | f0754f5b | 2011-07-21 16:02:07 -0700 | [diff] [blame] | 1759 | break; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1760 | case UNSTABLE_PROVIDER_DIED: |
| 1761 | handleUnstableProviderDied((IBinder)msg.obj, false); |
| 1762 | break; |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 1763 | case REQUEST_ASSIST_CONTEXT_EXTRAS: |
| 1764 | handleRequestAssistContextExtras((RequestAssistContextExtras)msg.obj); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 1765 | break; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1766 | case TRANSLUCENT_CONVERSION_COMPLETE: |
| 1767 | handleTranslucentConversionComplete((IBinder)msg.obj, msg.arg1 == 1); |
| 1768 | break; |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 1769 | case INSTALL_PROVIDER: |
| 1770 | handleInstallProvider((ProviderInfo) msg.obj); |
| 1771 | break; |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1772 | case ON_NEW_ACTIVITY_OPTIONS: |
| 1773 | Pair<IBinder, ActivityOptions> pair = (Pair<IBinder, ActivityOptions>) msg.obj; |
| 1774 | onNewActivityOptions(pair.first, pair.second); |
Dake Gu | 7ef70b0 | 2014-07-08 18:37:12 -0700 | [diff] [blame] | 1775 | break; |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 1776 | case ENTER_ANIMATION_COMPLETE: |
| 1777 | handleEnterAnimationComplete((IBinder) msg.obj); |
| 1778 | break; |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 1779 | case START_BINDER_TRACKING: |
| 1780 | handleStartBinderTracking(); |
| 1781 | break; |
| 1782 | case STOP_BINDER_TRACKING_AND_DUMP: |
| 1783 | handleStopBinderTrackingAndDump((ParcelFileDescriptor) msg.obj); |
| 1784 | break; |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1785 | case LOCAL_VOICE_INTERACTION_STARTED: |
| 1786 | handleLocalVoiceInteractionStarted((IBinder) ((SomeArgs) msg.obj).arg1, |
| 1787 | (IVoiceInteractor) ((SomeArgs) msg.obj).arg2); |
Amith Yamasani | 6101911 | 2017-01-10 15:05:00 -0800 | [diff] [blame] | 1788 | break; |
Andreas Gampe | ab8a63b | 2018-01-05 13:55:15 -0800 | [diff] [blame] | 1789 | case ATTACH_AGENT: { |
| 1790 | Application app = getApplication(); |
| 1791 | handleAttachAgent((String) msg.obj, app != null ? app.mLoadedApk : null); |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1792 | break; |
Andreas Gampe | ab8a63b | 2018-01-05 13:55:15 -0800 | [diff] [blame] | 1793 | } |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 1794 | case APPLICATION_INFO_CHANGED: |
| 1795 | mUpdatingSystemConfig = true; |
| 1796 | try { |
| 1797 | handleApplicationInfoChanged((ApplicationInfo) msg.obj); |
| 1798 | } finally { |
| 1799 | mUpdatingSystemConfig = false; |
| 1800 | } |
| 1801 | break; |
Torne (Richard Coles) | 466cbe4 | 2017-05-31 14:09:14 -0400 | [diff] [blame] | 1802 | case RUN_ISOLATED_ENTRY_POINT: |
| 1803 | handleRunIsolatedEntryPoint((String) ((SomeArgs) msg.obj).arg1, |
| 1804 | (String[]) ((SomeArgs) msg.obj).arg2); |
| 1805 | break; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 1806 | case EXECUTE_TRANSACTION: |
Andrii Kulian | 0447068 | 2018-01-10 15:32:31 -0800 | [diff] [blame] | 1807 | final ClientTransaction transaction = (ClientTransaction) msg.obj; |
| 1808 | mTransactionExecutor.execute(transaction); |
| 1809 | if (isSystem()) { |
| 1810 | // Client transactions inside system process are recycled on the client side |
| 1811 | // instead of ClientLifecycleManager to avoid being cleared before this |
| 1812 | // message is handled. |
| 1813 | transaction.recycle(); |
| 1814 | } |
Andrii Kulian | 914aa7d | 2018-03-19 21:51:53 -0700 | [diff] [blame] | 1815 | // TODO(lifecycler): Recycle locally scheduled transactions. |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 1816 | break; |
Andrii Kulian | 320e3b5 | 2018-05-03 16:26:25 -0700 | [diff] [blame] | 1817 | case RELAUNCH_ACTIVITY: |
| 1818 | handleRelaunchActivityLocally((IBinder) msg.obj); |
| 1819 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1820 | } |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1821 | Object obj = msg.obj; |
| 1822 | if (obj instanceof SomeArgs) { |
| 1823 | ((SomeArgs) obj).recycle(); |
| 1824 | } |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 1825 | 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] | 1826 | } |
| 1827 | } |
| 1828 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1829 | private class Idler implements MessageQueue.IdleHandler { |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 1830 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1831 | public final boolean queueIdle() { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1832 | ActivityClientRecord a = mNewActivities; |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 1833 | boolean stopProfiling = false; |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 1834 | if (mBoundApplication != null && mProfiler.profileFd != null |
| 1835 | && mProfiler.autoStopProfiler) { |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 1836 | stopProfiling = true; |
| 1837 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1838 | if (a != null) { |
| 1839 | mNewActivities = null; |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 1840 | IActivityManager am = ActivityManager.getService(); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1841 | ActivityClientRecord prev; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1842 | do { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 1843 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1844 | TAG, "Reporting idle of " + a + |
| 1845 | " finished=" + |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1846 | (a.activity != null && a.activity.mFinished)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1847 | if (a.activity != null && !a.activity.mFinished) { |
| 1848 | try { |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 1849 | am.activityIdle(a.token, a.createdConfig, stopProfiling); |
Dianne Hackborn | e88846e | 2009-09-30 21:34:25 -0700 | [diff] [blame] | 1850 | a.createdConfig = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1851 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1852 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1853 | } |
| 1854 | } |
| 1855 | prev = a; |
| 1856 | a = a.nextIdle; |
| 1857 | prev.nextIdle = null; |
| 1858 | } while (a != null); |
| 1859 | } |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 1860 | if (stopProfiling) { |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 1861 | mProfiler.stopProfiling(); |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 1862 | } |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 1863 | ensureJitEnabled(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1864 | return false; |
| 1865 | } |
| 1866 | } |
| 1867 | |
| 1868 | final class GcIdler implements MessageQueue.IdleHandler { |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 1869 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1870 | public final boolean queueIdle() { |
| 1871 | doGcIfNeeded(); |
| 1872 | return false; |
| 1873 | } |
| 1874 | } |
| 1875 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1876 | public static ActivityThread currentActivityThread() { |
Jeff Sharkey | 66a017b | 2013-01-17 18:18:22 -0800 | [diff] [blame] | 1877 | return sCurrentActivityThread; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1878 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1879 | |
Wale Ogunwale | 9a6ef1e | 2015-06-02 13:41:00 -0700 | [diff] [blame] | 1880 | public static boolean isSystem() { |
| 1881 | return (sCurrentActivityThread != null) ? sCurrentActivityThread.mSystemThread : false; |
| 1882 | } |
| 1883 | |
Svetoslav | fbf0eca | 2015-05-01 16:52:41 -0700 | [diff] [blame] | 1884 | public static String currentOpPackageName() { |
| 1885 | ActivityThread am = currentActivityThread(); |
| 1886 | return (am != null && am.getApplication() != null) |
| 1887 | ? am.getApplication().getOpPackageName() : null; |
| 1888 | } |
| 1889 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1890 | public static String currentPackageName() { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1891 | ActivityThread am = currentActivityThread(); |
| 1892 | return (am != null && am.mBoundApplication != null) |
Dianne Hackborn | b57a50b | 2013-04-11 17:29:32 -0700 | [diff] [blame] | 1893 | ? am.mBoundApplication.appInfo.packageName : null; |
| 1894 | } |
| 1895 | |
| 1896 | public static String currentProcessName() { |
| 1897 | ActivityThread am = currentActivityThread(); |
| 1898 | return (am != null && am.mBoundApplication != null) |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1899 | ? am.mBoundApplication.processName : null; |
| 1900 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1901 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1902 | public static Application currentApplication() { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1903 | ActivityThread am = currentActivityThread(); |
| 1904 | return am != null ? am.mInitialApplication : null; |
| 1905 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1906 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1907 | public static IPackageManager getPackageManager() { |
| 1908 | if (sPackageManager != null) { |
| 1909 | //Slog.v("PackageManager", "returning cur default = " + sPackageManager); |
| 1910 | return sPackageManager; |
| 1911 | } |
| 1912 | IBinder b = ServiceManager.getService("package"); |
| 1913 | //Slog.v("PackageManager", "default service binder = " + b); |
| 1914 | sPackageManager = IPackageManager.Stub.asInterface(b); |
| 1915 | //Slog.v("PackageManager", "default service = " + sPackageManager); |
| 1916 | return sPackageManager; |
| 1917 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1918 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1919 | private Configuration mMainThreadConfig = new Configuration(); |
Amith Yamasani | 4f128e4 | 2016-05-10 11:44:12 -0700 | [diff] [blame] | 1920 | |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 1921 | Configuration applyConfigCompatMainThread(int displayDensity, Configuration config, |
| 1922 | CompatibilityInfo compat) { |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1923 | if (config == null) { |
| 1924 | return null; |
| 1925 | } |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 1926 | if (!compat.supportsScreen()) { |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1927 | mMainThreadConfig.setTo(config); |
| 1928 | config = mMainThreadConfig; |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 1929 | compat.applyToConfiguration(displayDensity, config); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1930 | } |
| 1931 | return config; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1932 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1933 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1934 | /** |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 1935 | * Creates the top level resources for the given package. Will return an existing |
| 1936 | * Resources if one has already been created. |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1937 | */ |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 1938 | Resources getTopLevelResources(String resDir, String[] splitResDirs, String[] overlayDirs, |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 1939 | String[] libDirs, int displayId, LoadedApk pkgInfo) { |
| 1940 | return mResourcesManager.getResources(null, resDir, splitResDirs, overlayDirs, libDirs, |
| 1941 | displayId, null, pkgInfo.getCompatibilityInfo(), pkgInfo.getClassLoader()); |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 1942 | } |
| 1943 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1944 | final Handler getHandler() { |
| 1945 | return mH; |
| 1946 | } |
| 1947 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 1948 | public final LoadedApk getPackageInfo(String packageName, CompatibilityInfo compatInfo, |
| 1949 | int flags) { |
| 1950 | return getPackageInfo(packageName, compatInfo, flags, UserHandle.myUserId()); |
Amith Yamasani | 98edc95 | 2012-09-25 14:09:27 -0700 | [diff] [blame] | 1951 | } |
| 1952 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 1953 | public final LoadedApk getPackageInfo(String packageName, CompatibilityInfo compatInfo, |
| 1954 | int flags, int userId) { |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 1955 | final boolean differentUser = (UserHandle.myUserId() != userId); |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 1956 | synchronized (mResourcesManager) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1957 | WeakReference<LoadedApk> ref; |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 1958 | if (differentUser) { |
| 1959 | // Caching not supported across users |
| 1960 | ref = null; |
| 1961 | } else if ((flags & Context.CONTEXT_INCLUDE_CODE) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1962 | ref = mPackages.get(packageName); |
| 1963 | } else { |
| 1964 | ref = mResourcePackages.get(packageName); |
| 1965 | } |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 1966 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 1967 | LoadedApk packageInfo = ref != null ? ref.get() : null; |
| 1968 | //Slog.i(TAG, "getPackageInfo " + packageName + ": " + packageInfo); |
| 1969 | //if (packageInfo != null) Slog.i(TAG, "isUptoDate " + packageInfo.mResDir |
| 1970 | // + ": " + packageInfo.mResources.getAssets().isUpToDate()); |
| 1971 | if (packageInfo != null && (packageInfo.mResources == null |
| 1972 | || packageInfo.mResources.getAssets().isUpToDate())) { |
| 1973 | if (packageInfo.isSecurityViolation() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1974 | && (flags&Context.CONTEXT_IGNORE_SECURITY) == 0) { |
| 1975 | throw new SecurityException( |
| 1976 | "Requesting code from " + packageName |
| 1977 | + " to be run in process " |
| 1978 | + mBoundApplication.processName |
| 1979 | + "/" + mBoundApplication.appInfo.uid); |
| 1980 | } |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 1981 | return packageInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1982 | } |
| 1983 | } |
| 1984 | |
| 1985 | ApplicationInfo ai = null; |
| 1986 | try { |
| 1987 | ai = getPackageManager().getApplicationInfo(packageName, |
Jeff Sharkey | c5967e9 | 2016-01-07 18:50:29 -0700 | [diff] [blame] | 1988 | PackageManager.GET_SHARED_LIBRARY_FILES |
| 1989 | | PackageManager.MATCH_DEBUG_TRIAGED_MISSING, |
| 1990 | userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1991 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1992 | throw e.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1993 | } |
| 1994 | |
| 1995 | if (ai != null) { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 1996 | return getPackageInfo(ai, compatInfo, flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1997 | } |
| 1998 | |
| 1999 | return null; |
| 2000 | } |
| 2001 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2002 | public final LoadedApk getPackageInfo(ApplicationInfo ai, CompatibilityInfo compatInfo, |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2003 | int flags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2004 | boolean includeCode = (flags&Context.CONTEXT_INCLUDE_CODE) != 0; |
| 2005 | boolean securityViolation = includeCode && ai.uid != 0 |
| 2006 | && ai.uid != Process.SYSTEM_UID && (mBoundApplication != null |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 2007 | ? !UserHandle.isSameApp(ai.uid, mBoundApplication.appInfo.uid) |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 2008 | : true); |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 2009 | boolean registerPackage = includeCode && (flags&Context.CONTEXT_REGISTER_PACKAGE) != 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2010 | if ((flags&(Context.CONTEXT_INCLUDE_CODE |
| 2011 | |Context.CONTEXT_IGNORE_SECURITY)) |
| 2012 | == Context.CONTEXT_INCLUDE_CODE) { |
| 2013 | if (securityViolation) { |
| 2014 | String msg = "Requesting code from " + ai.packageName |
| 2015 | + " (with uid " + ai.uid + ")"; |
| 2016 | if (mBoundApplication != null) { |
| 2017 | msg = msg + " to be run in process " |
| 2018 | + mBoundApplication.processName + " (with uid " |
| 2019 | + mBoundApplication.appInfo.uid + ")"; |
| 2020 | } |
| 2021 | throw new SecurityException(msg); |
| 2022 | } |
| 2023 | } |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2024 | return getPackageInfo(ai, compatInfo, null, securityViolation, includeCode, |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 2025 | registerPackage); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2026 | } |
| 2027 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 2028 | @Override |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2029 | public final LoadedApk getPackageInfoNoCheck(ApplicationInfo ai, |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2030 | CompatibilityInfo compatInfo) { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2031 | return getPackageInfo(ai, compatInfo, null, false, true, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2032 | } |
| 2033 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2034 | public final LoadedApk peekPackageInfo(String packageName, boolean includeCode) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 2035 | synchronized (mResourcesManager) { |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2036 | WeakReference<LoadedApk> ref; |
| 2037 | if (includeCode) { |
| 2038 | ref = mPackages.get(packageName); |
| 2039 | } else { |
| 2040 | ref = mResourcePackages.get(packageName); |
| 2041 | } |
| 2042 | return ref != null ? ref.get() : null; |
| 2043 | } |
| 2044 | } |
| 2045 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2046 | private LoadedApk getPackageInfo(ApplicationInfo aInfo, CompatibilityInfo compatInfo, |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 2047 | ClassLoader baseLoader, boolean securityViolation, boolean includeCode, |
| 2048 | boolean registerPackage) { |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 2049 | final boolean differentUser = (UserHandle.myUserId() != UserHandle.getUserId(aInfo.uid)); |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 2050 | synchronized (mResourcesManager) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2051 | WeakReference<LoadedApk> ref; |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 2052 | if (differentUser) { |
| 2053 | // Caching not supported across users |
| 2054 | ref = null; |
| 2055 | } else if (includeCode) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2056 | ref = mPackages.get(aInfo.packageName); |
| 2057 | } else { |
| 2058 | ref = mResourcePackages.get(aInfo.packageName); |
| 2059 | } |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 2060 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2061 | LoadedApk packageInfo = ref != null ? ref.get() : null; |
| 2062 | if (packageInfo == null || (packageInfo.mResources != null |
| 2063 | && !packageInfo.mResources.getAssets().isUpToDate())) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2064 | if (localLOGV) Slog.v(TAG, (includeCode ? "Loading code package " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2065 | : "Loading resource-only package ") + aInfo.packageName |
| 2066 | + " (in " + (mBoundApplication != null |
| 2067 | ? mBoundApplication.processName : null) |
| 2068 | + ")"); |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2069 | packageInfo = |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 2070 | new LoadedApk(this, aInfo, compatInfo, baseLoader, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2071 | securityViolation, includeCode && |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 2072 | (aInfo.flags&ApplicationInfo.FLAG_HAS_CODE) != 0, registerPackage); |
Narayan Kamath | cb38318 | 2014-10-29 17:56:42 +0000 | [diff] [blame] | 2073 | |
| 2074 | if (mSystemThread && "android".equals(aInfo.packageName)) { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2075 | packageInfo.installSystemApplicationInfo(aInfo, |
| 2076 | getSystemContext().mPackageInfo.getClassLoader()); |
Narayan Kamath | cb38318 | 2014-10-29 17:56:42 +0000 | [diff] [blame] | 2077 | } |
| 2078 | |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 2079 | if (differentUser) { |
| 2080 | // Caching not supported across users |
| 2081 | } else if (includeCode) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2082 | mPackages.put(aInfo.packageName, |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2083 | new WeakReference<LoadedApk>(packageInfo)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2084 | } else { |
| 2085 | mResourcePackages.put(aInfo.packageName, |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2086 | new WeakReference<LoadedApk>(packageInfo)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2087 | } |
| 2088 | } |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2089 | return packageInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2090 | } |
| 2091 | } |
| 2092 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2093 | ActivityThread() { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 2094 | mResourcesManager = ResourcesManager.getInstance(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2095 | } |
| 2096 | |
| 2097 | public ApplicationThread getApplicationThread() |
| 2098 | { |
| 2099 | return mAppThread; |
| 2100 | } |
| 2101 | |
| 2102 | public Instrumentation getInstrumentation() |
| 2103 | { |
| 2104 | return mInstrumentation; |
| 2105 | } |
| 2106 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2107 | public boolean isProfiling() { |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 2108 | return mProfiler != null && mProfiler.profileFile != null |
| 2109 | && mProfiler.profileFd == null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2110 | } |
| 2111 | |
| 2112 | public String getProfileFilePath() { |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 2113 | return mProfiler.profileFile; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2114 | } |
| 2115 | |
| 2116 | public Looper getLooper() { |
| 2117 | return mLooper; |
| 2118 | } |
| 2119 | |
Jeff Sharkey | 8439ac0 | 2017-12-12 17:26:23 -0700 | [diff] [blame] | 2120 | public Executor getExecutor() { |
| 2121 | return mExecutor; |
| 2122 | } |
| 2123 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2124 | public Application getApplication() { |
| 2125 | return mInitialApplication; |
| 2126 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2127 | |
Dianne Hackborn | d97c7ad | 2009-06-19 11:37:35 -0700 | [diff] [blame] | 2128 | public String getProcessName() { |
| 2129 | return mBoundApplication.processName; |
| 2130 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2131 | |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 2132 | public ContextImpl getSystemContext() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2133 | synchronized (this) { |
| 2134 | if (mSystemContext == null) { |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 2135 | mSystemContext = ContextImpl.createSystemContext(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2136 | } |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 2137 | return mSystemContext; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2138 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2139 | } |
| 2140 | |
Adam Lesinski | a82b626 | 2017-03-21 16:56:17 -0700 | [diff] [blame] | 2141 | public ContextImpl getSystemUiContext() { |
| 2142 | synchronized (this) { |
| 2143 | if (mSystemUiContext == null) { |
Adam Lesinski | 6f1a917 | 2017-04-10 16:35:19 -0700 | [diff] [blame] | 2144 | mSystemUiContext = ContextImpl.createSystemUiContext(getSystemContext()); |
Adam Lesinski | a82b626 | 2017-03-21 16:56:17 -0700 | [diff] [blame] | 2145 | } |
| 2146 | return mSystemUiContext; |
| 2147 | } |
| 2148 | } |
| 2149 | |
Narayan Kamath | 29564cd | 2014-08-07 10:57:40 +0100 | [diff] [blame] | 2150 | public void installSystemApplicationInfo(ApplicationInfo info, ClassLoader classLoader) { |
Mike Cleron | 432b713 | 2009-09-24 15:28:29 -0700 | [diff] [blame] | 2151 | synchronized (this) { |
Narayan Kamath | 29564cd | 2014-08-07 10:57:40 +0100 | [diff] [blame] | 2152 | getSystemContext().installSystemApplicationInfo(info, classLoader); |
Adam Lesinski | a82b626 | 2017-03-21 16:56:17 -0700 | [diff] [blame] | 2153 | getSystemUiContext().installSystemApplicationInfo(info, classLoader); |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 2154 | |
| 2155 | // give ourselves a default profiler |
| 2156 | mProfiler = new Profiler(); |
Mike Cleron | 432b713 | 2009-09-24 15:28:29 -0700 | [diff] [blame] | 2157 | } |
| 2158 | } |
| 2159 | |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 2160 | void ensureJitEnabled() { |
| 2161 | if (!mJitEnabled) { |
| 2162 | mJitEnabled = true; |
| 2163 | dalvik.system.VMRuntime.getRuntime().startJitCompilation(); |
| 2164 | } |
| 2165 | } |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 2166 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2167 | void scheduleGcIdler() { |
| 2168 | if (!mGcIdlerScheduled) { |
| 2169 | mGcIdlerScheduled = true; |
| 2170 | Looper.myQueue().addIdleHandler(mGcIdler); |
| 2171 | } |
| 2172 | mH.removeMessages(H.GC_WHEN_IDLE); |
| 2173 | } |
| 2174 | |
| 2175 | void unscheduleGcIdler() { |
| 2176 | if (mGcIdlerScheduled) { |
| 2177 | mGcIdlerScheduled = false; |
| 2178 | Looper.myQueue().removeIdleHandler(mGcIdler); |
| 2179 | } |
| 2180 | mH.removeMessages(H.GC_WHEN_IDLE); |
| 2181 | } |
| 2182 | |
| 2183 | void doGcIfNeeded() { |
| 2184 | mGcIdlerScheduled = false; |
| 2185 | final long now = SystemClock.uptimeMillis(); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2186 | //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] | 2187 | // + "m now=" + now); |
| 2188 | if ((BinderInternal.getLastGcTime()+MIN_TIME_BETWEEN_GCS) < now) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2189 | //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] | 2190 | BinderInternal.forceGc("bg"); |
| 2191 | } |
| 2192 | } |
| 2193 | |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2194 | private static final String HEAP_FULL_COLUMN |
| 2195 | = "%13s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s"; |
| 2196 | private static final String HEAP_COLUMN |
| 2197 | = "%13s %8s %8s %8s %8s %8s %8s %8s"; |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2198 | private static final String ONE_COUNT_COLUMN = "%21s %8d"; |
| 2199 | private static final String TWO_COUNT_COLUMNS = "%21s %8d %21s %8d"; |
| 2200 | private static final String ONE_COUNT_COLUMN_HEADER = "%21s %8s"; |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2201 | |
| 2202 | // Formatting for checkin service - update version if row format changes |
Martijn Coenen | 41f94ed | 2015-12-14 15:28:51 +0100 | [diff] [blame] | 2203 | private static final int ACTIVITY_THREAD_CHECKIN_VERSION = 4; |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2204 | |
| 2205 | static void printRow(PrintWriter pw, String format, Object...objs) { |
| 2206 | pw.println(String.format(format, objs)); |
| 2207 | } |
| 2208 | |
| 2209 | public static void dumpMemInfoTable(PrintWriter pw, Debug.MemoryInfo memInfo, boolean checkin, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2210 | boolean dumpFullInfo, boolean dumpDalvik, boolean dumpSummaryOnly, |
| 2211 | int pid, String processName, |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2212 | long nativeMax, long nativeAllocated, long nativeFree, |
| 2213 | long dalvikMax, long dalvikAllocated, long dalvikFree) { |
| 2214 | |
| 2215 | // For checkin, we print one long comma-separated list of values |
| 2216 | if (checkin) { |
| 2217 | // NOTE: if you change anything significant below, also consider changing |
| 2218 | // ACTIVITY_THREAD_CHECKIN_VERSION. |
| 2219 | |
| 2220 | // Header |
| 2221 | pw.print(ACTIVITY_THREAD_CHECKIN_VERSION); pw.print(','); |
| 2222 | pw.print(pid); pw.print(','); |
| 2223 | pw.print(processName); pw.print(','); |
| 2224 | |
| 2225 | // Heap info - max |
| 2226 | pw.print(nativeMax); pw.print(','); |
| 2227 | pw.print(dalvikMax); pw.print(','); |
| 2228 | pw.print("N/A,"); |
| 2229 | pw.print(nativeMax + dalvikMax); pw.print(','); |
| 2230 | |
| 2231 | // Heap info - allocated |
| 2232 | pw.print(nativeAllocated); pw.print(','); |
| 2233 | pw.print(dalvikAllocated); pw.print(','); |
| 2234 | pw.print("N/A,"); |
| 2235 | pw.print(nativeAllocated + dalvikAllocated); pw.print(','); |
| 2236 | |
| 2237 | // Heap info - free |
| 2238 | pw.print(nativeFree); pw.print(','); |
| 2239 | pw.print(dalvikFree); pw.print(','); |
| 2240 | pw.print("N/A,"); |
| 2241 | pw.print(nativeFree + dalvikFree); pw.print(','); |
| 2242 | |
| 2243 | // Heap info - proportional set size |
| 2244 | pw.print(memInfo.nativePss); pw.print(','); |
| 2245 | pw.print(memInfo.dalvikPss); pw.print(','); |
| 2246 | pw.print(memInfo.otherPss); pw.print(','); |
| 2247 | pw.print(memInfo.getTotalPss()); pw.print(','); |
| 2248 | |
| 2249 | // Heap info - swappable set size |
| 2250 | pw.print(memInfo.nativeSwappablePss); pw.print(','); |
| 2251 | pw.print(memInfo.dalvikSwappablePss); pw.print(','); |
| 2252 | pw.print(memInfo.otherSwappablePss); pw.print(','); |
| 2253 | pw.print(memInfo.getTotalSwappablePss()); pw.print(','); |
| 2254 | |
| 2255 | // Heap info - shared dirty |
| 2256 | pw.print(memInfo.nativeSharedDirty); pw.print(','); |
| 2257 | pw.print(memInfo.dalvikSharedDirty); pw.print(','); |
| 2258 | pw.print(memInfo.otherSharedDirty); pw.print(','); |
| 2259 | pw.print(memInfo.getTotalSharedDirty()); pw.print(','); |
| 2260 | |
| 2261 | // Heap info - shared clean |
| 2262 | pw.print(memInfo.nativeSharedClean); pw.print(','); |
| 2263 | pw.print(memInfo.dalvikSharedClean); pw.print(','); |
| 2264 | pw.print(memInfo.otherSharedClean); pw.print(','); |
| 2265 | pw.print(memInfo.getTotalSharedClean()); pw.print(','); |
| 2266 | |
| 2267 | // Heap info - private Dirty |
| 2268 | pw.print(memInfo.nativePrivateDirty); pw.print(','); |
| 2269 | pw.print(memInfo.dalvikPrivateDirty); pw.print(','); |
| 2270 | pw.print(memInfo.otherPrivateDirty); pw.print(','); |
| 2271 | pw.print(memInfo.getTotalPrivateDirty()); pw.print(','); |
| 2272 | |
| 2273 | // Heap info - private Clean |
| 2274 | pw.print(memInfo.nativePrivateClean); pw.print(','); |
| 2275 | pw.print(memInfo.dalvikPrivateClean); pw.print(','); |
| 2276 | pw.print(memInfo.otherPrivateClean); pw.print(','); |
| 2277 | pw.print(memInfo.getTotalPrivateClean()); pw.print(','); |
| 2278 | |
Martijn Coenen | 41f94ed | 2015-12-14 15:28:51 +0100 | [diff] [blame] | 2279 | // Heap info - swapped out |
| 2280 | pw.print(memInfo.nativeSwappedOut); pw.print(','); |
| 2281 | pw.print(memInfo.dalvikSwappedOut); pw.print(','); |
| 2282 | pw.print(memInfo.otherSwappedOut); pw.print(','); |
| 2283 | pw.print(memInfo.getTotalSwappedOut()); pw.print(','); |
| 2284 | |
| 2285 | // Heap info - swapped out pss |
| 2286 | if (memInfo.hasSwappedOutPss) { |
| 2287 | pw.print(memInfo.nativeSwappedOutPss); pw.print(','); |
| 2288 | pw.print(memInfo.dalvikSwappedOutPss); pw.print(','); |
| 2289 | pw.print(memInfo.otherSwappedOutPss); pw.print(','); |
| 2290 | pw.print(memInfo.getTotalSwappedOutPss()); pw.print(','); |
| 2291 | } else { |
| 2292 | pw.print("N/A,"); |
| 2293 | pw.print("N/A,"); |
| 2294 | pw.print("N/A,"); |
| 2295 | pw.print("N/A,"); |
| 2296 | } |
| 2297 | |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2298 | // Heap info - other areas |
| 2299 | for (int i=0; i<Debug.MemoryInfo.NUM_OTHER_STATS; i++) { |
| 2300 | pw.print(Debug.MemoryInfo.getOtherLabel(i)); pw.print(','); |
| 2301 | pw.print(memInfo.getOtherPss(i)); pw.print(','); |
| 2302 | pw.print(memInfo.getOtherSwappablePss(i)); pw.print(','); |
| 2303 | pw.print(memInfo.getOtherSharedDirty(i)); pw.print(','); |
| 2304 | pw.print(memInfo.getOtherSharedClean(i)); pw.print(','); |
| 2305 | pw.print(memInfo.getOtherPrivateDirty(i)); pw.print(','); |
| 2306 | pw.print(memInfo.getOtherPrivateClean(i)); pw.print(','); |
Martijn Coenen | 41f94ed | 2015-12-14 15:28:51 +0100 | [diff] [blame] | 2307 | pw.print(memInfo.getOtherSwappedOut(i)); pw.print(','); |
| 2308 | if (memInfo.hasSwappedOutPss) { |
| 2309 | pw.print(memInfo.getOtherSwappedOutPss(i)); pw.print(','); |
| 2310 | } else { |
| 2311 | pw.print("N/A,"); |
| 2312 | } |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2313 | } |
| 2314 | return; |
| 2315 | } |
| 2316 | |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2317 | if (!dumpSummaryOnly) { |
| 2318 | if (dumpFullInfo) { |
| 2319 | printRow(pw, HEAP_FULL_COLUMN, "", "Pss", "Pss", "Shared", "Private", |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2320 | "Shared", "Private", memInfo.hasSwappedOutPss ? "SwapPss" : "Swap", |
| 2321 | "Heap", "Heap", "Heap"); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2322 | printRow(pw, HEAP_FULL_COLUMN, "", "Total", "Clean", "Dirty", "Dirty", |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2323 | "Clean", "Clean", "Dirty", |
| 2324 | "Size", "Alloc", "Free"); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2325 | printRow(pw, HEAP_FULL_COLUMN, "", "------", "------", "------", "------", |
| 2326 | "------", "------", "------", "------", "------", "------"); |
| 2327 | printRow(pw, HEAP_FULL_COLUMN, "Native Heap", memInfo.nativePss, |
| 2328 | memInfo.nativeSwappablePss, memInfo.nativeSharedDirty, |
| 2329 | memInfo.nativePrivateDirty, memInfo.nativeSharedClean, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2330 | memInfo.nativePrivateClean, memInfo.hasSwappedOutPss ? |
Richard Uhler | 91702eb3 | 2017-06-23 16:54:25 +0100 | [diff] [blame] | 2331 | memInfo.nativeSwappedOutPss : memInfo.nativeSwappedOut, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2332 | nativeMax, nativeAllocated, nativeFree); |
| 2333 | printRow(pw, HEAP_FULL_COLUMN, "Dalvik Heap", memInfo.dalvikPss, |
| 2334 | memInfo.dalvikSwappablePss, memInfo.dalvikSharedDirty, |
| 2335 | memInfo.dalvikPrivateDirty, memInfo.dalvikSharedClean, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2336 | memInfo.dalvikPrivateClean, memInfo.hasSwappedOutPss ? |
Richard Uhler | 91702eb3 | 2017-06-23 16:54:25 +0100 | [diff] [blame] | 2337 | memInfo.dalvikSwappedOutPss : memInfo.dalvikSwappedOut, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2338 | dalvikMax, dalvikAllocated, dalvikFree); |
| 2339 | } else { |
| 2340 | printRow(pw, HEAP_COLUMN, "", "Pss", "Private", |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2341 | "Private", memInfo.hasSwappedOutPss ? "SwapPss" : "Swap", |
| 2342 | "Heap", "Heap", "Heap"); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2343 | printRow(pw, HEAP_COLUMN, "", "Total", "Dirty", |
| 2344 | "Clean", "Dirty", "Size", "Alloc", "Free"); |
| 2345 | printRow(pw, HEAP_COLUMN, "", "------", "------", "------", |
| 2346 | "------", "------", "------", "------", "------"); |
| 2347 | printRow(pw, HEAP_COLUMN, "Native Heap", memInfo.nativePss, |
| 2348 | memInfo.nativePrivateDirty, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2349 | memInfo.nativePrivateClean, |
| 2350 | memInfo.hasSwappedOutPss ? memInfo.nativeSwappedOutPss : |
| 2351 | memInfo.nativeSwappedOut, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2352 | nativeMax, nativeAllocated, nativeFree); |
| 2353 | printRow(pw, HEAP_COLUMN, "Dalvik Heap", memInfo.dalvikPss, |
| 2354 | memInfo.dalvikPrivateDirty, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2355 | memInfo.dalvikPrivateClean, |
| 2356 | memInfo.hasSwappedOutPss ? memInfo.dalvikSwappedOutPss : |
| 2357 | memInfo.dalvikSwappedOut, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2358 | dalvikMax, dalvikAllocated, dalvikFree); |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2359 | } |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2360 | |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2361 | int otherPss = memInfo.otherPss; |
| 2362 | int otherSwappablePss = memInfo.otherSwappablePss; |
| 2363 | int otherSharedDirty = memInfo.otherSharedDirty; |
| 2364 | int otherPrivateDirty = memInfo.otherPrivateDirty; |
| 2365 | int otherSharedClean = memInfo.otherSharedClean; |
| 2366 | int otherPrivateClean = memInfo.otherPrivateClean; |
| 2367 | int otherSwappedOut = memInfo.otherSwappedOut; |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2368 | int otherSwappedOutPss = memInfo.otherSwappedOutPss; |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2369 | |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2370 | for (int i=0; i<Debug.MemoryInfo.NUM_OTHER_STATS; i++) { |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2371 | final int myPss = memInfo.getOtherPss(i); |
| 2372 | final int mySwappablePss = memInfo.getOtherSwappablePss(i); |
| 2373 | final int mySharedDirty = memInfo.getOtherSharedDirty(i); |
| 2374 | final int myPrivateDirty = memInfo.getOtherPrivateDirty(i); |
| 2375 | final int mySharedClean = memInfo.getOtherSharedClean(i); |
| 2376 | final int myPrivateClean = memInfo.getOtherPrivateClean(i); |
| 2377 | final int mySwappedOut = memInfo.getOtherSwappedOut(i); |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2378 | final int mySwappedOutPss = memInfo.getOtherSwappedOutPss(i); |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2379 | if (myPss != 0 || mySharedDirty != 0 || myPrivateDirty != 0 |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2380 | || mySharedClean != 0 || myPrivateClean != 0 |
| 2381 | || (memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut) != 0) { |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2382 | if (dumpFullInfo) { |
| 2383 | printRow(pw, HEAP_FULL_COLUMN, Debug.MemoryInfo.getOtherLabel(i), |
| 2384 | myPss, mySwappablePss, mySharedDirty, myPrivateDirty, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2385 | mySharedClean, myPrivateClean, |
| 2386 | memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut, |
| 2387 | "", "", ""); |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2388 | } else { |
| 2389 | printRow(pw, HEAP_COLUMN, Debug.MemoryInfo.getOtherLabel(i), |
| 2390 | myPss, myPrivateDirty, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2391 | myPrivateClean, |
| 2392 | memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut, |
| 2393 | "", "", ""); |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2394 | } |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2395 | otherPss -= myPss; |
| 2396 | otherSwappablePss -= mySwappablePss; |
| 2397 | otherSharedDirty -= mySharedDirty; |
| 2398 | otherPrivateDirty -= myPrivateDirty; |
| 2399 | otherSharedClean -= mySharedClean; |
| 2400 | otherPrivateClean -= myPrivateClean; |
| 2401 | otherSwappedOut -= mySwappedOut; |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2402 | otherSwappedOutPss -= mySwappedOutPss; |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2403 | } |
| 2404 | } |
| 2405 | |
| 2406 | if (dumpFullInfo) { |
| 2407 | printRow(pw, HEAP_FULL_COLUMN, "Unknown", otherPss, otherSwappablePss, |
| 2408 | otherSharedDirty, otherPrivateDirty, otherSharedClean, otherPrivateClean, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2409 | memInfo.hasSwappedOutPss ? otherSwappedOutPss : otherSwappedOut, |
| 2410 | "", "", ""); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2411 | printRow(pw, HEAP_FULL_COLUMN, "TOTAL", memInfo.getTotalPss(), |
| 2412 | memInfo.getTotalSwappablePss(), |
| 2413 | memInfo.getTotalSharedDirty(), memInfo.getTotalPrivateDirty(), |
| 2414 | memInfo.getTotalSharedClean(), memInfo.getTotalPrivateClean(), |
Thierry Strudel | 9b51160 | 2016-02-25 17:46:38 -0800 | [diff] [blame] | 2415 | memInfo.hasSwappedOutPss ? memInfo.getTotalSwappedOutPss() : |
| 2416 | memInfo.getTotalSwappedOut(), |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2417 | nativeMax+dalvikMax, nativeAllocated+dalvikAllocated, |
| 2418 | nativeFree+dalvikFree); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2419 | } else { |
| 2420 | printRow(pw, HEAP_COLUMN, "Unknown", otherPss, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2421 | otherPrivateDirty, otherPrivateClean, |
| 2422 | memInfo.hasSwappedOutPss ? otherSwappedOutPss : otherSwappedOut, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2423 | "", "", ""); |
| 2424 | printRow(pw, HEAP_COLUMN, "TOTAL", memInfo.getTotalPss(), |
| 2425 | memInfo.getTotalPrivateDirty(), |
| 2426 | memInfo.getTotalPrivateClean(), |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2427 | memInfo.hasSwappedOutPss ? memInfo.getTotalSwappedOutPss() : |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2428 | memInfo.getTotalSwappedOut(), |
| 2429 | nativeMax+dalvikMax, |
| 2430 | nativeAllocated+dalvikAllocated, nativeFree+dalvikFree); |
| 2431 | } |
| 2432 | |
| 2433 | if (dumpDalvik) { |
| 2434 | pw.println(" "); |
| 2435 | pw.println(" Dalvik Details"); |
| 2436 | |
| 2437 | for (int i=Debug.MemoryInfo.NUM_OTHER_STATS; |
| 2438 | i<Debug.MemoryInfo.NUM_OTHER_STATS + Debug.MemoryInfo.NUM_DVK_STATS; i++) { |
| 2439 | final int myPss = memInfo.getOtherPss(i); |
| 2440 | final int mySwappablePss = memInfo.getOtherSwappablePss(i); |
| 2441 | final int mySharedDirty = memInfo.getOtherSharedDirty(i); |
| 2442 | final int myPrivateDirty = memInfo.getOtherPrivateDirty(i); |
| 2443 | final int mySharedClean = memInfo.getOtherSharedClean(i); |
| 2444 | final int myPrivateClean = memInfo.getOtherPrivateClean(i); |
| 2445 | final int mySwappedOut = memInfo.getOtherSwappedOut(i); |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2446 | final int mySwappedOutPss = memInfo.getOtherSwappedOutPss(i); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2447 | if (myPss != 0 || mySharedDirty != 0 || myPrivateDirty != 0 |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2448 | || mySharedClean != 0 || myPrivateClean != 0 |
| 2449 | || (memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut) != 0) { |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2450 | if (dumpFullInfo) { |
| 2451 | printRow(pw, HEAP_FULL_COLUMN, Debug.MemoryInfo.getOtherLabel(i), |
| 2452 | myPss, mySwappablePss, mySharedDirty, myPrivateDirty, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2453 | mySharedClean, myPrivateClean, |
| 2454 | memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut, |
| 2455 | "", "", ""); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2456 | } else { |
| 2457 | printRow(pw, HEAP_COLUMN, Debug.MemoryInfo.getOtherLabel(i), |
| 2458 | myPss, myPrivateDirty, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2459 | myPrivateClean, |
| 2460 | memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut, |
| 2461 | "", "", ""); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2462 | } |
| 2463 | } |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2464 | } |
| 2465 | } |
| 2466 | } |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2467 | |
| 2468 | pw.println(" "); |
| 2469 | pw.println(" App Summary"); |
| 2470 | printRow(pw, ONE_COUNT_COLUMN_HEADER, "", "Pss(KB)"); |
| 2471 | printRow(pw, ONE_COUNT_COLUMN_HEADER, "", "------"); |
| 2472 | printRow(pw, ONE_COUNT_COLUMN, |
| 2473 | "Java Heap:", memInfo.getSummaryJavaHeap()); |
| 2474 | printRow(pw, ONE_COUNT_COLUMN, |
| 2475 | "Native Heap:", memInfo.getSummaryNativeHeap()); |
| 2476 | printRow(pw, ONE_COUNT_COLUMN, |
| 2477 | "Code:", memInfo.getSummaryCode()); |
| 2478 | printRow(pw, ONE_COUNT_COLUMN, |
| 2479 | "Stack:", memInfo.getSummaryStack()); |
| 2480 | printRow(pw, ONE_COUNT_COLUMN, |
| 2481 | "Graphics:", memInfo.getSummaryGraphics()); |
| 2482 | printRow(pw, ONE_COUNT_COLUMN, |
| 2483 | "Private Other:", memInfo.getSummaryPrivateOther()); |
| 2484 | printRow(pw, ONE_COUNT_COLUMN, |
| 2485 | "System:", memInfo.getSummarySystem()); |
| 2486 | pw.println(" "); |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2487 | if (memInfo.hasSwappedOutPss) { |
| 2488 | printRow(pw, TWO_COUNT_COLUMNS, |
| 2489 | "TOTAL:", memInfo.getSummaryTotalPss(), |
| 2490 | "TOTAL SWAP PSS:", memInfo.getSummaryTotalSwapPss()); |
| 2491 | } else { |
| 2492 | printRow(pw, TWO_COUNT_COLUMNS, |
| 2493 | "TOTAL:", memInfo.getSummaryTotalPss(), |
| 2494 | "TOTAL SWAP (KB):", memInfo.getSummaryTotalSwap()); |
| 2495 | } |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2496 | } |
| 2497 | |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2498 | /** |
| 2499 | * Dump heap info to proto. |
| 2500 | * |
| 2501 | * @param hasSwappedOutPss determines whether to use dirtySwap or dirtySwapPss |
| 2502 | */ |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 2503 | private static void dumpMemoryInfo(ProtoOutputStream proto, long fieldId, String name, |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2504 | int pss, int cleanPss, int sharedDirty, int privateDirty, |
| 2505 | int sharedClean, int privateClean, |
| 2506 | boolean hasSwappedOutPss, int dirtySwap, int dirtySwapPss) { |
| 2507 | final long token = proto.start(fieldId); |
| 2508 | |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 2509 | proto.write(MemInfoDumpProto.ProcessMemory.MemoryInfo.NAME, name); |
| 2510 | proto.write(MemInfoDumpProto.ProcessMemory.MemoryInfo.TOTAL_PSS_KB, pss); |
| 2511 | proto.write(MemInfoDumpProto.ProcessMemory.MemoryInfo.CLEAN_PSS_KB, cleanPss); |
| 2512 | proto.write(MemInfoDumpProto.ProcessMemory.MemoryInfo.SHARED_DIRTY_KB, sharedDirty); |
| 2513 | proto.write(MemInfoDumpProto.ProcessMemory.MemoryInfo.PRIVATE_DIRTY_KB, privateDirty); |
| 2514 | proto.write(MemInfoDumpProto.ProcessMemory.MemoryInfo.SHARED_CLEAN_KB, sharedClean); |
| 2515 | proto.write(MemInfoDumpProto.ProcessMemory.MemoryInfo.PRIVATE_CLEAN_KB, privateClean); |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2516 | if (hasSwappedOutPss) { |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 2517 | proto.write(MemInfoDumpProto.ProcessMemory.MemoryInfo.DIRTY_SWAP_PSS_KB, dirtySwapPss); |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2518 | } else { |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 2519 | proto.write(MemInfoDumpProto.ProcessMemory.MemoryInfo.DIRTY_SWAP_KB, dirtySwap); |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2520 | } |
| 2521 | |
| 2522 | proto.end(token); |
| 2523 | } |
| 2524 | |
| 2525 | /** |
| 2526 | * Dump mem info data to proto. |
| 2527 | */ |
| 2528 | public static void dumpMemInfoTable(ProtoOutputStream proto, Debug.MemoryInfo memInfo, |
| 2529 | boolean dumpDalvik, boolean dumpSummaryOnly, |
| 2530 | long nativeMax, long nativeAllocated, long nativeFree, |
| 2531 | long dalvikMax, long dalvikAllocated, long dalvikFree) { |
| 2532 | |
| 2533 | if (!dumpSummaryOnly) { |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 2534 | final long nhToken = proto.start(MemInfoDumpProto.ProcessMemory.NATIVE_HEAP); |
| 2535 | dumpMemoryInfo(proto, MemInfoDumpProto.ProcessMemory.HeapInfo.MEM_INFO, "Native Heap", |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2536 | memInfo.nativePss, memInfo.nativeSwappablePss, memInfo.nativeSharedDirty, |
| 2537 | memInfo.nativePrivateDirty, memInfo.nativeSharedClean, |
| 2538 | memInfo.nativePrivateClean, memInfo.hasSwappedOutPss, |
| 2539 | memInfo.nativeSwappedOut, memInfo.nativeSwappedOutPss); |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 2540 | proto.write(MemInfoDumpProto.ProcessMemory.HeapInfo.HEAP_SIZE_KB, nativeMax); |
| 2541 | proto.write(MemInfoDumpProto.ProcessMemory.HeapInfo.HEAP_ALLOC_KB, nativeAllocated); |
| 2542 | proto.write(MemInfoDumpProto.ProcessMemory.HeapInfo.HEAP_FREE_KB, nativeFree); |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2543 | proto.end(nhToken); |
| 2544 | |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 2545 | final long dvToken = proto.start(MemInfoDumpProto.ProcessMemory.DALVIK_HEAP); |
| 2546 | dumpMemoryInfo(proto, MemInfoDumpProto.ProcessMemory.HeapInfo.MEM_INFO, "Dalvik Heap", |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2547 | memInfo.dalvikPss, memInfo.dalvikSwappablePss, memInfo.dalvikSharedDirty, |
| 2548 | memInfo.dalvikPrivateDirty, memInfo.dalvikSharedClean, |
| 2549 | memInfo.dalvikPrivateClean, memInfo.hasSwappedOutPss, |
| 2550 | memInfo.dalvikSwappedOut, memInfo.dalvikSwappedOutPss); |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 2551 | proto.write(MemInfoDumpProto.ProcessMemory.HeapInfo.HEAP_SIZE_KB, dalvikMax); |
| 2552 | proto.write(MemInfoDumpProto.ProcessMemory.HeapInfo.HEAP_ALLOC_KB, dalvikAllocated); |
| 2553 | proto.write(MemInfoDumpProto.ProcessMemory.HeapInfo.HEAP_FREE_KB, dalvikFree); |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2554 | proto.end(dvToken); |
| 2555 | |
| 2556 | int otherPss = memInfo.otherPss; |
| 2557 | int otherSwappablePss = memInfo.otherSwappablePss; |
| 2558 | int otherSharedDirty = memInfo.otherSharedDirty; |
| 2559 | int otherPrivateDirty = memInfo.otherPrivateDirty; |
| 2560 | int otherSharedClean = memInfo.otherSharedClean; |
| 2561 | int otherPrivateClean = memInfo.otherPrivateClean; |
| 2562 | int otherSwappedOut = memInfo.otherSwappedOut; |
| 2563 | int otherSwappedOutPss = memInfo.otherSwappedOutPss; |
| 2564 | |
| 2565 | for (int i = 0; i < Debug.MemoryInfo.NUM_OTHER_STATS; i++) { |
| 2566 | final int myPss = memInfo.getOtherPss(i); |
| 2567 | final int mySwappablePss = memInfo.getOtherSwappablePss(i); |
| 2568 | final int mySharedDirty = memInfo.getOtherSharedDirty(i); |
| 2569 | final int myPrivateDirty = memInfo.getOtherPrivateDirty(i); |
| 2570 | final int mySharedClean = memInfo.getOtherSharedClean(i); |
| 2571 | final int myPrivateClean = memInfo.getOtherPrivateClean(i); |
| 2572 | final int mySwappedOut = memInfo.getOtherSwappedOut(i); |
| 2573 | final int mySwappedOutPss = memInfo.getOtherSwappedOutPss(i); |
| 2574 | if (myPss != 0 || mySharedDirty != 0 || myPrivateDirty != 0 |
| 2575 | || mySharedClean != 0 || myPrivateClean != 0 |
| 2576 | || (memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut) != 0) { |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 2577 | dumpMemoryInfo(proto, MemInfoDumpProto.ProcessMemory.OTHER_HEAPS, |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2578 | Debug.MemoryInfo.getOtherLabel(i), |
| 2579 | myPss, mySwappablePss, mySharedDirty, myPrivateDirty, |
| 2580 | mySharedClean, myPrivateClean, |
| 2581 | memInfo.hasSwappedOutPss, mySwappedOut, mySwappedOutPss); |
| 2582 | |
| 2583 | otherPss -= myPss; |
| 2584 | otherSwappablePss -= mySwappablePss; |
| 2585 | otherSharedDirty -= mySharedDirty; |
| 2586 | otherPrivateDirty -= myPrivateDirty; |
| 2587 | otherSharedClean -= mySharedClean; |
| 2588 | otherPrivateClean -= myPrivateClean; |
| 2589 | otherSwappedOut -= mySwappedOut; |
| 2590 | otherSwappedOutPss -= mySwappedOutPss; |
| 2591 | } |
| 2592 | } |
| 2593 | |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 2594 | dumpMemoryInfo(proto, MemInfoDumpProto.ProcessMemory.UNKNOWN_HEAP, "Unknown", |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2595 | otherPss, otherSwappablePss, |
| 2596 | otherSharedDirty, otherPrivateDirty, otherSharedClean, otherPrivateClean, |
| 2597 | memInfo.hasSwappedOutPss, otherSwappedOut, otherSwappedOutPss); |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 2598 | final long tToken = proto.start(MemInfoDumpProto.ProcessMemory.TOTAL_HEAP); |
| 2599 | dumpMemoryInfo(proto, MemInfoDumpProto.ProcessMemory.HeapInfo.MEM_INFO, "TOTAL", |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2600 | memInfo.getTotalPss(), memInfo.getTotalSwappablePss(), |
| 2601 | memInfo.getTotalSharedDirty(), memInfo.getTotalPrivateDirty(), |
| 2602 | memInfo.getTotalSharedClean(), memInfo.getTotalPrivateClean(), |
| 2603 | memInfo.hasSwappedOutPss, memInfo.getTotalSwappedOut(), |
| 2604 | memInfo.getTotalSwappedOutPss()); |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 2605 | proto.write(MemInfoDumpProto.ProcessMemory.HeapInfo.HEAP_SIZE_KB, |
| 2606 | nativeMax + dalvikMax); |
| 2607 | proto.write(MemInfoDumpProto.ProcessMemory.HeapInfo.HEAP_ALLOC_KB, |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2608 | nativeAllocated + dalvikAllocated); |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 2609 | proto.write(MemInfoDumpProto.ProcessMemory.HeapInfo.HEAP_FREE_KB, |
| 2610 | nativeFree + dalvikFree); |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2611 | proto.end(tToken); |
| 2612 | |
| 2613 | if (dumpDalvik) { |
| 2614 | for (int i = Debug.MemoryInfo.NUM_OTHER_STATS; |
| 2615 | i < Debug.MemoryInfo.NUM_OTHER_STATS + Debug.MemoryInfo.NUM_DVK_STATS; |
| 2616 | i++) { |
| 2617 | final int myPss = memInfo.getOtherPss(i); |
| 2618 | final int mySwappablePss = memInfo.getOtherSwappablePss(i); |
| 2619 | final int mySharedDirty = memInfo.getOtherSharedDirty(i); |
| 2620 | final int myPrivateDirty = memInfo.getOtherPrivateDirty(i); |
| 2621 | final int mySharedClean = memInfo.getOtherSharedClean(i); |
| 2622 | final int myPrivateClean = memInfo.getOtherPrivateClean(i); |
| 2623 | final int mySwappedOut = memInfo.getOtherSwappedOut(i); |
| 2624 | final int mySwappedOutPss = memInfo.getOtherSwappedOutPss(i); |
| 2625 | if (myPss != 0 || mySharedDirty != 0 || myPrivateDirty != 0 |
| 2626 | || mySharedClean != 0 || myPrivateClean != 0 |
| 2627 | || (memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut) != 0) { |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 2628 | dumpMemoryInfo(proto, MemInfoDumpProto.ProcessMemory.DALVIK_DETAILS, |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2629 | Debug.MemoryInfo.getOtherLabel(i), |
| 2630 | myPss, mySwappablePss, mySharedDirty, myPrivateDirty, |
| 2631 | mySharedClean, myPrivateClean, |
| 2632 | memInfo.hasSwappedOutPss, mySwappedOut, mySwappedOutPss); |
| 2633 | } |
| 2634 | } |
| 2635 | } |
| 2636 | } |
| 2637 | |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 2638 | final long asToken = proto.start(MemInfoDumpProto.ProcessMemory.APP_SUMMARY); |
| 2639 | proto.write(MemInfoDumpProto.ProcessMemory.AppSummary.JAVA_HEAP_PSS_KB, |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2640 | memInfo.getSummaryJavaHeap()); |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 2641 | proto.write(MemInfoDumpProto.ProcessMemory.AppSummary.NATIVE_HEAP_PSS_KB, |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2642 | memInfo.getSummaryNativeHeap()); |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 2643 | proto.write(MemInfoDumpProto.ProcessMemory.AppSummary.CODE_PSS_KB, |
| 2644 | memInfo.getSummaryCode()); |
| 2645 | proto.write(MemInfoDumpProto.ProcessMemory.AppSummary.STACK_PSS_KB, |
| 2646 | memInfo.getSummaryStack()); |
| 2647 | proto.write(MemInfoDumpProto.ProcessMemory.AppSummary.GRAPHICS_PSS_KB, |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2648 | memInfo.getSummaryGraphics()); |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 2649 | proto.write(MemInfoDumpProto.ProcessMemory.AppSummary.PRIVATE_OTHER_PSS_KB, |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2650 | memInfo.getSummaryPrivateOther()); |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 2651 | proto.write(MemInfoDumpProto.ProcessMemory.AppSummary.SYSTEM_PSS_KB, |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2652 | memInfo.getSummarySystem()); |
| 2653 | if (memInfo.hasSwappedOutPss) { |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 2654 | proto.write(MemInfoDumpProto.ProcessMemory.AppSummary.TOTAL_SWAP_PSS, |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2655 | memInfo.getSummaryTotalSwapPss()); |
| 2656 | } else { |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 2657 | proto.write(MemInfoDumpProto.ProcessMemory.AppSummary.TOTAL_SWAP_PSS, |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2658 | memInfo.getSummaryTotalSwap()); |
| 2659 | } |
| 2660 | proto.end(asToken); |
| 2661 | } |
| 2662 | |
Jeff Hamilton | 52d3203 | 2011-01-08 15:31:26 -0600 | [diff] [blame] | 2663 | public void registerOnActivityPausedListener(Activity activity, |
| 2664 | OnActivityPausedListener listener) { |
| 2665 | synchronized (mOnPauseListeners) { |
| 2666 | ArrayList<OnActivityPausedListener> list = mOnPauseListeners.get(activity); |
| 2667 | if (list == null) { |
| 2668 | list = new ArrayList<OnActivityPausedListener>(); |
| 2669 | mOnPauseListeners.put(activity, list); |
| 2670 | } |
| 2671 | list.add(listener); |
| 2672 | } |
| 2673 | } |
| 2674 | |
Jeff Hamilton | ce3224c | 2011-01-17 11:05:03 -0800 | [diff] [blame] | 2675 | public void unregisterOnActivityPausedListener(Activity activity, |
| 2676 | OnActivityPausedListener listener) { |
| 2677 | synchronized (mOnPauseListeners) { |
| 2678 | ArrayList<OnActivityPausedListener> list = mOnPauseListeners.get(activity); |
| 2679 | if (list != null) { |
| 2680 | list.remove(listener); |
| 2681 | } |
| 2682 | } |
| 2683 | } |
| 2684 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2685 | public final ActivityInfo resolveActivityInfo(Intent intent) { |
| 2686 | ActivityInfo aInfo = intent.resolveActivityInfo( |
| 2687 | mInitialApplication.getPackageManager(), PackageManager.GET_SHARED_LIBRARY_FILES); |
| 2688 | if (aInfo == null) { |
| 2689 | // Throw an exception. |
| 2690 | Instrumentation.checkStartActivityResult( |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 2691 | ActivityManager.START_CLASS_NOT_FOUND, intent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2692 | } |
| 2693 | return aInfo; |
| 2694 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2695 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2696 | public final Activity startActivityNow(Activity parent, String id, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2697 | Intent intent, ActivityInfo activityInfo, IBinder token, Bundle state, |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 2698 | Activity.NonConfigurationInstances lastNonConfigurationInstances) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2699 | ActivityClientRecord r = new ActivityClientRecord(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2700 | r.token = token; |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 2701 | r.ident = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2702 | r.intent = intent; |
| 2703 | r.state = state; |
| 2704 | r.parent = parent; |
| 2705 | r.embeddedID = id; |
| 2706 | r.activityInfo = activityInfo; |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 2707 | r.lastNonConfigurationInstances = lastNonConfigurationInstances; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2708 | if (localLOGV) { |
| 2709 | ComponentName compname = intent.getComponent(); |
| 2710 | String name; |
| 2711 | if (compname != null) { |
| 2712 | name = compname.toShortString(); |
| 2713 | } else { |
| 2714 | name = "(Intent " + intent + ").getComponent() returned null"; |
| 2715 | } |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2716 | Slog.v(TAG, "Performing launch: action=" + intent.getAction() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2717 | + ", comp=" + name |
| 2718 | + ", token=" + token); |
| 2719 | } |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 2720 | // TODO(lifecycler): Can't switch to use #handleLaunchActivity() because it will try to |
| 2721 | // call #reportSizeConfigurations(), but the server might not know anything about the |
| 2722 | // activity if it was launched from LocalAcvitivyManager. |
Andrii Kulian | 770c403 | 2018-05-02 18:40:59 -0700 | [diff] [blame] | 2723 | return performLaunchActivity(r, null /* customIntent */); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2724 | } |
| 2725 | |
| 2726 | public final Activity getActivity(IBinder token) { |
| 2727 | return mActivities.get(token).activity; |
| 2728 | } |
| 2729 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 2730 | @Override |
| 2731 | public ActivityClientRecord getActivityClient(IBinder token) { |
| 2732 | return mActivities.get(token); |
| 2733 | } |
| 2734 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2735 | public final void sendActivityResult( |
| 2736 | IBinder token, String id, int requestCode, |
| 2737 | int resultCode, Intent data) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2738 | if (DEBUG_RESULTS) Slog.v(TAG, "sendActivityResult: id=" + id |
Chris Tate | 8a7dc17 | 2009-03-24 20:11:42 -0700 | [diff] [blame] | 2739 | + " req=" + requestCode + " res=" + resultCode + " data=" + data); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2740 | ArrayList<ResultInfo> list = new ArrayList<ResultInfo>(); |
| 2741 | list.add(new ResultInfo(id, requestCode, resultCode, data)); |
Andrii Kulian | 9c5ea9c | 2017-12-07 09:31:01 -0800 | [diff] [blame] | 2742 | final ClientTransaction clientTransaction = ClientTransaction.obtain(mAppThread, token); |
| 2743 | clientTransaction.addCallback(ActivityResultItem.obtain(list)); |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 2744 | try { |
| 2745 | mAppThread.scheduleTransaction(clientTransaction); |
| 2746 | } catch (RemoteException e) { |
| 2747 | // Local scheduling |
| 2748 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2749 | } |
| 2750 | |
Andrii Kulian | 914aa7d | 2018-03-19 21:51:53 -0700 | [diff] [blame] | 2751 | @Override |
| 2752 | TransactionExecutor getTransactionExecutor() { |
| 2753 | return mTransactionExecutor; |
| 2754 | } |
| 2755 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 2756 | void sendMessage(int what, Object obj) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 2757 | sendMessage(what, obj, 0, 0, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2758 | } |
| 2759 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 2760 | private void sendMessage(int what, Object obj, int arg1) { |
| 2761 | sendMessage(what, obj, arg1, 0, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2762 | } |
| 2763 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 2764 | private void sendMessage(int what, Object obj, int arg1, int arg2) { |
| 2765 | sendMessage(what, obj, arg1, arg2, false); |
| 2766 | } |
| 2767 | |
| 2768 | private void sendMessage(int what, Object obj, int arg1, int arg2, boolean async) { |
| 2769 | if (DEBUG_MESSAGES) Slog.v( |
| 2770 | TAG, "SCHEDULE " + what + " " + mH.codeToString(what) |
| 2771 | + ": " + arg1 + " / " + obj); |
| 2772 | Message msg = Message.obtain(); |
| 2773 | msg.what = what; |
| 2774 | msg.obj = obj; |
| 2775 | msg.arg1 = arg1; |
| 2776 | msg.arg2 = arg2; |
| 2777 | if (async) { |
| 2778 | msg.setAsynchronous(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2779 | } |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 2780 | mH.sendMessage(msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2781 | } |
| 2782 | |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 2783 | private void sendMessage(int what, Object obj, int arg1, int arg2, int seq) { |
| 2784 | if (DEBUG_MESSAGES) Slog.v( |
| 2785 | TAG, "SCHEDULE " + mH.codeToString(what) + " arg1=" + arg1 + " arg2=" + arg2 + |
| 2786 | "seq= " + seq); |
| 2787 | Message msg = Message.obtain(); |
| 2788 | msg.what = what; |
| 2789 | SomeArgs args = SomeArgs.obtain(); |
| 2790 | args.arg1 = obj; |
| 2791 | args.argi1 = arg1; |
| 2792 | args.argi2 = arg2; |
| 2793 | args.argi3 = seq; |
| 2794 | msg.obj = args; |
| 2795 | mH.sendMessage(msg); |
| 2796 | } |
| 2797 | |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 2798 | final void scheduleContextCleanup(ContextImpl context, String who, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2799 | String what) { |
| 2800 | ContextCleanupInfo cci = new ContextCleanupInfo(); |
| 2801 | cci.context = context; |
| 2802 | cci.who = who; |
| 2803 | cci.what = what; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 2804 | sendMessage(H.CLEAN_UP_CONTEXT, cci); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2805 | } |
| 2806 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 2807 | /** Core implementation of activity launch. */ |
Andrii Kulian | 770c403 | 2018-05-02 18:40:59 -0700 | [diff] [blame] | 2808 | private Activity performLaunchActivity(ActivityClientRecord r, Intent customIntent) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2809 | ActivityInfo aInfo = r.activityInfo; |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2810 | if (r.packageInfo == null) { |
| 2811 | r.packageInfo = getPackageInfo(aInfo.applicationInfo, r.compatInfo, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2812 | Context.CONTEXT_INCLUDE_CODE); |
| 2813 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2814 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2815 | ComponentName component = r.intent.getComponent(); |
| 2816 | if (component == null) { |
| 2817 | component = r.intent.resolveActivity( |
| 2818 | mInitialApplication.getPackageManager()); |
| 2819 | r.intent.setComponent(component); |
| 2820 | } |
| 2821 | |
| 2822 | if (r.activityInfo.targetActivity != null) { |
| 2823 | component = new ComponentName(r.activityInfo.packageName, |
| 2824 | r.activityInfo.targetActivity); |
| 2825 | } |
| 2826 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 2827 | ContextImpl appContext = createBaseContextForActivity(r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2828 | Activity activity = null; |
| 2829 | try { |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 2830 | java.lang.ClassLoader cl = appContext.getClassLoader(); |
Dan Sandler | 07fe63e | 2017-08-15 16:41:11 -0400 | [diff] [blame] | 2831 | activity = mInstrumentation.newActivity( |
| 2832 | cl, component.getClassName(), r.intent); |
Brad Fitzpatrick | 5f8b5c1 | 2011-01-20 15:12:08 -0800 | [diff] [blame] | 2833 | StrictMode.incrementExpectedActivityCount(activity.getClass()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2834 | r.intent.setExtrasClassLoader(cl); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 2835 | r.intent.prepareToEnterProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2836 | if (r.state != null) { |
| 2837 | r.state.setClassLoader(cl); |
| 2838 | } |
| 2839 | } catch (Exception e) { |
| 2840 | if (!mInstrumentation.onException(activity, e)) { |
| 2841 | throw new RuntimeException( |
| 2842 | "Unable to instantiate activity " + component |
| 2843 | + ": " + e.toString(), e); |
| 2844 | } |
| 2845 | } |
| 2846 | |
| 2847 | try { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2848 | Application app = r.packageInfo.makeApplication(false, mInstrumentation); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2849 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2850 | if (localLOGV) Slog.v(TAG, "Performing launch of " + r); |
| 2851 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2852 | TAG, r + ": app=" + app |
| 2853 | + ", appName=" + app.getPackageName() |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2854 | + ", pkg=" + r.packageInfo.getPackageName() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2855 | + ", comp=" + r.intent.getComponent().toShortString() |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2856 | + ", dir=" + r.packageInfo.getAppDir()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2857 | |
| 2858 | if (activity != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2859 | CharSequence title = r.activityInfo.loadLabel(appContext.getPackageManager()); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 2860 | Configuration config = new Configuration(mCompatConfiguration); |
Andrii Kulian | d0ad938 | 2016-04-18 20:54:20 -0700 | [diff] [blame] | 2861 | if (r.overrideConfig != null) { |
| 2862 | config.updateFrom(r.overrideConfig); |
| 2863 | } |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2864 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Launching activity " |
Dianne Hackborn | dc6b635 | 2009-09-30 14:20:09 -0700 | [diff] [blame] | 2865 | + r.activityInfo.name + " with config " + config); |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 2866 | Window window = null; |
| 2867 | if (r.mPendingRemoveWindow != null && r.mPreserveWindow) { |
| 2868 | window = r.mPendingRemoveWindow; |
| 2869 | r.mPendingRemoveWindow = null; |
| 2870 | r.mPendingRemoveWindowManager = null; |
| 2871 | } |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 2872 | appContext.setOuterContext(activity); |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 2873 | activity.attach(appContext, this, getInstrumentation(), r.token, |
| 2874 | r.ident, app, r.intent, r.activityInfo, title, r.parent, |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 2875 | r.embeddedID, r.lastNonConfigurationInstances, config, |
Andrii Kulian | 51c1b67 | 2017-04-07 18:39:32 -0700 | [diff] [blame] | 2876 | r.referrer, r.voiceInteractor, window, r.configCallback); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2877 | |
Andrii Kulian | 770c403 | 2018-05-02 18:40:59 -0700 | [diff] [blame] | 2878 | if (customIntent != null) { |
| 2879 | activity.mIntent = customIntent; |
| 2880 | } |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 2881 | r.lastNonConfigurationInstances = null; |
Sudheer Shanka | 84a4895 | 2017-03-08 18:19:01 -0800 | [diff] [blame] | 2882 | checkAndBlockForNetworkAccess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2883 | activity.mStartedActivity = false; |
| 2884 | int theme = r.activityInfo.getThemeResource(); |
| 2885 | if (theme != 0) { |
| 2886 | activity.setTheme(theme); |
| 2887 | } |
| 2888 | |
| 2889 | activity.mCalled = false; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2890 | if (r.isPersistable()) { |
| 2891 | mInstrumentation.callActivityOnCreate(activity, r.state, r.persistentState); |
| 2892 | } else { |
| 2893 | mInstrumentation.callActivityOnCreate(activity, r.state); |
| 2894 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2895 | if (!activity.mCalled) { |
| 2896 | throw new SuperNotCalledException( |
| 2897 | "Activity " + r.intent.getComponent().toShortString() + |
| 2898 | " did not call through to super.onCreate()"); |
| 2899 | } |
| 2900 | r.activity = activity; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2901 | } |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 2902 | r.setState(ON_CREATE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2903 | |
| 2904 | mActivities.put(r.token, r); |
| 2905 | |
| 2906 | } catch (SuperNotCalledException e) { |
| 2907 | throw e; |
| 2908 | |
| 2909 | } catch (Exception e) { |
| 2910 | if (!mInstrumentation.onException(activity, e)) { |
| 2911 | throw new RuntimeException( |
| 2912 | "Unable to start activity " + component |
| 2913 | + ": " + e.toString(), e); |
| 2914 | } |
| 2915 | } |
| 2916 | |
| 2917 | return activity; |
| 2918 | } |
| 2919 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 2920 | @Override |
| 2921 | public void handleStartActivity(ActivityClientRecord r, |
| 2922 | PendingTransactionActions pendingActions) { |
| 2923 | final Activity activity = r.activity; |
| 2924 | if (r.activity == null) { |
| 2925 | // TODO(lifecycler): What do we do in this case? |
| 2926 | return; |
| 2927 | } |
| 2928 | if (!r.stopped) { |
| 2929 | throw new IllegalStateException("Can't start activity that is not stopped."); |
| 2930 | } |
| 2931 | if (r.activity.mFinished) { |
| 2932 | // TODO(lifecycler): How can this happen? |
| 2933 | return; |
| 2934 | } |
| 2935 | |
| 2936 | // Start |
Andrii Kulian | d25680c | 2018-02-21 15:16:58 -0800 | [diff] [blame] | 2937 | activity.performStart("handleStartActivity"); |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 2938 | r.setState(ON_START); |
| 2939 | |
| 2940 | if (pendingActions == null) { |
| 2941 | // No more work to do. |
| 2942 | return; |
| 2943 | } |
| 2944 | |
| 2945 | // Restore instance state |
| 2946 | if (pendingActions.shouldRestoreInstanceState()) { |
| 2947 | if (r.isPersistable()) { |
| 2948 | if (r.state != null || r.persistentState != null) { |
| 2949 | mInstrumentation.callActivityOnRestoreInstanceState(activity, r.state, |
| 2950 | r.persistentState); |
| 2951 | } |
| 2952 | } else if (r.state != null) { |
| 2953 | mInstrumentation.callActivityOnRestoreInstanceState(activity, r.state); |
| 2954 | } |
| 2955 | } |
| 2956 | |
| 2957 | // Call postOnCreate() |
| 2958 | if (pendingActions.shouldCallOnPostCreate()) { |
| 2959 | activity.mCalled = false; |
| 2960 | if (r.isPersistable()) { |
| 2961 | mInstrumentation.callActivityOnPostCreate(activity, r.state, |
| 2962 | r.persistentState); |
| 2963 | } else { |
| 2964 | mInstrumentation.callActivityOnPostCreate(activity, r.state); |
| 2965 | } |
| 2966 | if (!activity.mCalled) { |
| 2967 | throw new SuperNotCalledException( |
| 2968 | "Activity " + r.intent.getComponent().toShortString() |
| 2969 | + " did not call through to super.onPostCreate()"); |
| 2970 | } |
| 2971 | } |
| 2972 | } |
| 2973 | |
Sudheer Shanka | 84a4895 | 2017-03-08 18:19:01 -0800 | [diff] [blame] | 2974 | /** |
| 2975 | * Checks if {@link #mNetworkBlockSeq} is {@link #INVALID_PROC_STATE_SEQ} and if so, returns |
| 2976 | * immediately. Otherwise, makes a blocking call to ActivityManagerService to wait for the |
| 2977 | * network rules to get updated. |
| 2978 | */ |
| 2979 | private void checkAndBlockForNetworkAccess() { |
| 2980 | synchronized (mNetworkPolicyLock) { |
| 2981 | if (mNetworkBlockSeq != INVALID_PROC_STATE_SEQ) { |
| 2982 | try { |
| 2983 | ActivityManager.getService().waitForNetworkStateUpdate(mNetworkBlockSeq); |
| 2984 | mNetworkBlockSeq = INVALID_PROC_STATE_SEQ; |
| 2985 | } catch (RemoteException ignored) {} |
| 2986 | } |
| 2987 | } |
| 2988 | } |
| 2989 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 2990 | private ContextImpl createBaseContextForActivity(ActivityClientRecord r) { |
| 2991 | final int displayId; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2992 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 2993 | displayId = ActivityManager.getService().getActivityDisplayId(r.token); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2994 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2995 | throw e.rethrowFromSystemServer(); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2996 | } |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 2997 | |
Wale Ogunwale | 7c72668 | 2015-02-06 17:34:28 -0800 | [diff] [blame] | 2998 | ContextImpl appContext = ContextImpl.createActivityContext( |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2999 | this, r.packageInfo, r.activityInfo, r.token, displayId, r.overrideConfig); |
Wale Ogunwale | 7c72668 | 2015-02-06 17:34:28 -0800 | [diff] [blame] | 3000 | |
| 3001 | final DisplayManagerGlobal dm = DisplayManagerGlobal.getInstance(); |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 3002 | // For debugging purposes, if the activity's package name contains the value of |
| 3003 | // the "debug.use-second-display" system property as a substring, then show |
| 3004 | // its content on a secondary display if there is one. |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 3005 | String pkgName = SystemProperties.get("debug.second-display.pkg"); |
| 3006 | if (pkgName != null && !pkgName.isEmpty() |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3007 | && r.packageInfo.mPackageName.contains(pkgName)) { |
Wale Ogunwale | 7c72668 | 2015-02-06 17:34:28 -0800 | [diff] [blame] | 3008 | for (int id : dm.getDisplayIds()) { |
| 3009 | if (id != Display.DEFAULT_DISPLAY) { |
Wale Ogunwale | 2669851 | 2015-06-05 16:55:33 -0700 | [diff] [blame] | 3010 | Display display = |
Bryce Lee | 609bf65 | 2017-02-09 16:50:13 -0800 | [diff] [blame] | 3011 | dm.getCompatibleDisplay(id, appContext.getResources()); |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 3012 | appContext = (ContextImpl) appContext.createDisplayContext(display); |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 3013 | break; |
| 3014 | } |
| 3015 | } |
| 3016 | } |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 3017 | return appContext; |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 3018 | } |
| 3019 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 3020 | /** |
| 3021 | * Extended implementation of activity launch. Used when server requests a launch or relaunch. |
| 3022 | */ |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 3023 | @Override |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 3024 | public Activity handleLaunchActivity(ActivityClientRecord r, |
Andrii Kulian | 770c403 | 2018-05-02 18:40:59 -0700 | [diff] [blame] | 3025 | PendingTransactionActions pendingActions, Intent customIntent) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3026 | // If we are getting ready to gc after going to the background, well |
| 3027 | // we are back active so skip it. |
| 3028 | unscheduleGcIdler(); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3029 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3030 | |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 3031 | if (r.profilerInfo != null) { |
| 3032 | mProfiler.setProfiler(r.profilerInfo); |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 3033 | mProfiler.startProfiling(); |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 3034 | } |
| 3035 | |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 3036 | // Make sure we are running with the most recent config. |
| 3037 | handleConfigurationChanged(null, null); |
| 3038 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3039 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3040 | TAG, "Handling launch of " + r); |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 3041 | |
Chet Haase | 0d1c27a | 2014-11-03 18:35:16 +0000 | [diff] [blame] | 3042 | // Initialize before creating the activity |
Jesse Hall | c37984f | 2017-05-23 16:55:08 -0700 | [diff] [blame] | 3043 | if (!ThreadedRenderer.sRendererDisabled) { |
| 3044 | GraphicsEnvironment.earlyInitEGL(); |
| 3045 | } |
Chet Haase | 0d1c27a | 2014-11-03 18:35:16 +0000 | [diff] [blame] | 3046 | WindowManagerGlobal.initialize(); |
| 3047 | |
Andrii Kulian | 770c403 | 2018-05-02 18:40:59 -0700 | [diff] [blame] | 3048 | final Activity a = performLaunchActivity(r, customIntent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3049 | |
| 3050 | if (a != null) { |
Dianne Hackborn | 871ecdc | 2009-12-11 15:24:33 -0800 | [diff] [blame] | 3051 | r.createdConfig = new Configuration(mConfiguration); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 3052 | reportSizeConfigurations(r); |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 3053 | if (!r.activity.mFinished && pendingActions != null) { |
| 3054 | pendingActions.setOldState(r.state); |
| 3055 | pendingActions.setRestoreInstanceState(true); |
| 3056 | pendingActions.setCallOnPostCreate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3057 | } |
| 3058 | } else { |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 3059 | // 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] | 3060 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3061 | ActivityManager.getService() |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 3062 | .finishActivity(r.token, Activity.RESULT_CANCELED, null, |
| 3063 | Activity.DONT_FINISH_TASK_WITH_ACTIVITY); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3064 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3065 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3066 | } |
| 3067 | } |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 3068 | |
| 3069 | return a; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3070 | } |
| 3071 | |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 3072 | private void reportSizeConfigurations(ActivityClientRecord r) { |
| 3073 | Configuration[] configurations = r.activity.getResources().getSizeConfigurations(); |
| 3074 | if (configurations == null) { |
| 3075 | return; |
| 3076 | } |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 3077 | SparseIntArray horizontal = new SparseIntArray(); |
| 3078 | SparseIntArray vertical = new SparseIntArray(); |
| 3079 | SparseIntArray smallest = new SparseIntArray(); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 3080 | for (int i = configurations.length - 1; i >= 0; i--) { |
| 3081 | Configuration config = configurations[i]; |
| 3082 | if (config.screenHeightDp != Configuration.SCREEN_HEIGHT_DP_UNDEFINED) { |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 3083 | vertical.put(config.screenHeightDp, 0); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 3084 | } |
| 3085 | if (config.screenWidthDp != Configuration.SCREEN_WIDTH_DP_UNDEFINED) { |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 3086 | horizontal.put(config.screenWidthDp, 0); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 3087 | } |
| 3088 | if (config.smallestScreenWidthDp != Configuration.SMALLEST_SCREEN_WIDTH_DP_UNDEFINED) { |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 3089 | smallest.put(config.smallestScreenWidthDp, 0); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 3090 | } |
| 3091 | } |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 3092 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3093 | ActivityManager.getService().reportSizeConfigurations(r.token, |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 3094 | horizontal.copyKeys(), vertical.copyKeys(), smallest.copyKeys()); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 3095 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3096 | throw ex.rethrowFromSystemServer(); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 3097 | } |
| 3098 | |
| 3099 | } |
| 3100 | |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 3101 | private void deliverNewIntents(ActivityClientRecord r, List<ReferrerIntent> intents) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3102 | final int N = intents.size(); |
| 3103 | for (int i=0; i<N; i++) { |
Dianne Hackborn | a01a0fa | 2014-12-02 10:33:14 -0800 | [diff] [blame] | 3104 | ReferrerIntent intent = intents.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3105 | intent.setExtrasClassLoader(r.activity.getClassLoader()); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 3106 | intent.prepareToEnterProcess(); |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 3107 | r.activity.mFragments.noteStateNotSaved(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3108 | mInstrumentation.callActivityOnNewIntent(r.activity, intent); |
| 3109 | } |
| 3110 | } |
| 3111 | |
Wale Ogunwale | 826c706 | 2016-09-13 08:25:54 -0700 | [diff] [blame] | 3112 | void performNewIntents(IBinder token, List<ReferrerIntent> intents, boolean andPause) { |
| 3113 | final ActivityClientRecord r = mActivities.get(token); |
| 3114 | if (r == null) { |
| 3115 | return; |
| 3116 | } |
| 3117 | |
| 3118 | final boolean resumed = !r.paused; |
| 3119 | if (resumed) { |
| 3120 | r.activity.mTemporaryPause = true; |
| 3121 | mInstrumentation.callActivityOnPause(r.activity); |
| 3122 | } |
Sudheer Shanka | 43b5ea4 | 2017-06-21 11:24:53 -0700 | [diff] [blame] | 3123 | checkAndBlockForNetworkAccess(); |
Wale Ogunwale | 826c706 | 2016-09-13 08:25:54 -0700 | [diff] [blame] | 3124 | deliverNewIntents(r, intents); |
| 3125 | if (resumed) { |
Andrii Kulian | d25680c | 2018-02-21 15:16:58 -0800 | [diff] [blame] | 3126 | r.activity.performResume(false, "performNewIntents"); |
Wale Ogunwale | 826c706 | 2016-09-13 08:25:54 -0700 | [diff] [blame] | 3127 | r.activity.mTemporaryPause = false; |
| 3128 | } |
| 3129 | |
| 3130 | if (r.paused && andPause) { |
| 3131 | // In this case the activity was in the paused state when we delivered the intent, |
| 3132 | // to guarantee onResume gets called after onNewIntent we temporarily resume the |
| 3133 | // activity and pause again as the caller wanted. |
| 3134 | performResumeActivity(token, false, "performNewIntents"); |
| 3135 | performPauseActivityIfNeeded(r, "performNewIntents"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3136 | } |
| 3137 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3138 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 3139 | @Override |
| 3140 | public void handleNewIntent(IBinder token, List<ReferrerIntent> intents, boolean andPause) { |
| 3141 | performNewIntents(token, intents, andPause); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3142 | } |
| 3143 | |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 3144 | public void handleRequestAssistContextExtras(RequestAssistContextExtras cmd) { |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 3145 | // Filling for autofill has a few differences: |
Felipe Leme | 1ca634a | 2016-11-28 17:21:21 -0800 | [diff] [blame] | 3146 | // - it does not need an AssistContent |
| 3147 | // - it does not call onProvideAssistData() |
| 3148 | // - it needs an IAutoFillCallback |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 3149 | boolean forAutofill = cmd.requestType == ActivityManager.ASSIST_CONTEXT_AUTOFILL; |
Felipe Leme | 1ca634a | 2016-11-28 17:21:21 -0800 | [diff] [blame] | 3150 | |
Felipe Leme | 85d1c2d | 2017-04-21 08:56:04 -0700 | [diff] [blame] | 3151 | // TODO: decide if lastSessionId logic applies to autofill sessions |
Amith Yamasani | 4f128e4 | 2016-05-10 11:44:12 -0700 | [diff] [blame] | 3152 | if (mLastSessionId != cmd.sessionId) { |
| 3153 | // Clear the existing structures |
| 3154 | mLastSessionId = cmd.sessionId; |
| 3155 | for (int i = mLastAssistStructures.size() - 1; i >= 0; i--) { |
| 3156 | AssistStructure structure = mLastAssistStructures.get(i).get(); |
| 3157 | if (structure != null) { |
| 3158 | structure.clearSendChannel(); |
| 3159 | } |
| 3160 | mLastAssistStructures.remove(i); |
Dianne Hackborn | 782d498 | 2015-07-08 17:36:37 -0700 | [diff] [blame] | 3161 | } |
| 3162 | } |
Felipe Leme | 29a5b0d | 2016-10-25 14:57:11 -0700 | [diff] [blame] | 3163 | |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 3164 | Bundle data = new Bundle(); |
Dianne Hackborn | 09d57fe | 2015-05-27 18:05:52 -0700 | [diff] [blame] | 3165 | AssistStructure structure = null; |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 3166 | AssistContent content = forAutofill ? null : new AssistContent(); |
Amith Yamasani | 858f98d | 2017-02-22 12:59:53 -0800 | [diff] [blame] | 3167 | final long startTime = SystemClock.uptimeMillis(); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 3168 | ActivityClientRecord r = mActivities.get(cmd.activityToken); |
Dianne Hackborn | a3acdb3 | 2015-06-08 17:07:40 -0700 | [diff] [blame] | 3169 | Uri referrer = null; |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 3170 | if (r != null) { |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 3171 | if (!forAutofill) { |
Felipe Leme | 1ca634a | 2016-11-28 17:21:21 -0800 | [diff] [blame] | 3172 | r.activity.getApplication().dispatchOnProvideAssistData(r.activity, data); |
Felipe Leme | 29a5b0d | 2016-10-25 14:57:11 -0700 | [diff] [blame] | 3173 | r.activity.onProvideAssistData(data); |
Felipe Leme | 6d55387 | 2016-12-08 17:13:25 -0800 | [diff] [blame] | 3174 | referrer = r.activity.onProvideReferrer(); |
Felipe Leme | 29a5b0d | 2016-10-25 14:57:11 -0700 | [diff] [blame] | 3175 | } |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 3176 | if (cmd.requestType == ActivityManager.ASSIST_CONTEXT_FULL || forAutofill) { |
Svet Ganov | fd31f85 | 2017-04-26 15:54:27 -0700 | [diff] [blame] | 3177 | structure = new AssistStructure(r.activity, forAutofill, cmd.flags); |
Adam Skory | 4aaed14 | 2015-04-22 11:29:31 -0600 | [diff] [blame] | 3178 | Intent activityIntent = r.activity.getIntent(); |
Felipe Leme | 6d55387 | 2016-12-08 17:13:25 -0800 | [diff] [blame] | 3179 | boolean notSecure = r.window == null || |
Dianne Hackborn | 09d57fe | 2015-05-27 18:05:52 -0700 | [diff] [blame] | 3180 | (r.window.getAttributes().flags |
Felipe Leme | 6d55387 | 2016-12-08 17:13:25 -0800 | [diff] [blame] | 3181 | & WindowManager.LayoutParams.FLAG_SECURE) == 0; |
| 3182 | if (activityIntent != null && notSecure) { |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 3183 | if (!forAutofill) { |
Felipe Leme | 1ca634a | 2016-11-28 17:21:21 -0800 | [diff] [blame] | 3184 | Intent intent = new Intent(activityIntent); |
| 3185 | intent.setFlags(intent.getFlags() & ~(Intent.FLAG_GRANT_WRITE_URI_PERMISSION |
| 3186 | | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION)); |
| 3187 | intent.removeUnsafeExtras(); |
Felipe Leme | 29a5b0d | 2016-10-25 14:57:11 -0700 | [diff] [blame] | 3188 | content.setDefaultIntent(intent); |
| 3189 | } |
Adam Skory | 4aaed14 | 2015-04-22 11:29:31 -0600 | [diff] [blame] | 3190 | } else { |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 3191 | if (!forAutofill) { |
Felipe Leme | 29a5b0d | 2016-10-25 14:57:11 -0700 | [diff] [blame] | 3192 | content.setDefaultIntent(new Intent()); |
| 3193 | } |
Adam Skory | 4aaed14 | 2015-04-22 11:29:31 -0600 | [diff] [blame] | 3194 | } |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 3195 | if (!forAutofill) { |
Felipe Leme | 29a5b0d | 2016-10-25 14:57:11 -0700 | [diff] [blame] | 3196 | r.activity.onProvideAssistContent(content); |
| 3197 | } |
Dianne Hackborn | a83ce1d | 2015-03-11 15:16:13 -0700 | [diff] [blame] | 3198 | } |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 3199 | } |
Dianne Hackborn | 09d57fe | 2015-05-27 18:05:52 -0700 | [diff] [blame] | 3200 | if (structure == null) { |
| 3201 | structure = new AssistStructure(); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 3202 | } |
Felipe Leme | 0200d9e | 2017-01-24 15:10:26 -0800 | [diff] [blame] | 3203 | |
Felipe Leme | 85d1c2d | 2017-04-21 08:56:04 -0700 | [diff] [blame] | 3204 | // TODO: decide if lastSessionId logic applies to autofill sessions |
Amith Yamasani | 858f98d | 2017-02-22 12:59:53 -0800 | [diff] [blame] | 3205 | |
| 3206 | structure.setAcquisitionStartTime(startTime); |
| 3207 | structure.setAcquisitionEndTime(SystemClock.uptimeMillis()); |
| 3208 | |
Amith Yamasani | 4f128e4 | 2016-05-10 11:44:12 -0700 | [diff] [blame] | 3209 | mLastAssistStructures.add(new WeakReference<>(structure)); |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3210 | IActivityManager mgr = ActivityManager.getService(); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 3211 | try { |
Dianne Hackborn | a3acdb3 | 2015-06-08 17:07:40 -0700 | [diff] [blame] | 3212 | mgr.reportAssistContextExtras(cmd.requestToken, data, structure, content, referrer); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 3213 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3214 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 3215 | } |
| 3216 | } |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 3217 | |
| 3218 | public void handleTranslucentConversionComplete(IBinder token, boolean drawComplete) { |
| 3219 | ActivityClientRecord r = mActivities.get(token); |
| 3220 | if (r != null) { |
| 3221 | r.activity.onTranslucentConversionComplete(drawComplete); |
| 3222 | } |
| 3223 | } |
| 3224 | |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 3225 | public void onNewActivityOptions(IBinder token, ActivityOptions options) { |
| 3226 | ActivityClientRecord r = mActivities.get(token); |
| 3227 | if (r != null) { |
| 3228 | r.activity.onNewActivityOptions(options); |
| 3229 | } |
| 3230 | } |
| 3231 | |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 3232 | public void handleInstallProvider(ProviderInfo info) { |
Jeff Sharkey | bb2e2ca | 2014-10-23 11:42:31 -0700 | [diff] [blame] | 3233 | final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); |
| 3234 | try { |
Jeff Sharkey | a6bfeae | 2017-07-05 16:50:24 -0600 | [diff] [blame] | 3235 | installContentProviders(mInitialApplication, Arrays.asList(info)); |
Jeff Sharkey | bb2e2ca | 2014-10-23 11:42:31 -0700 | [diff] [blame] | 3236 | } finally { |
| 3237 | StrictMode.setThreadPolicy(oldPolicy); |
| 3238 | } |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 3239 | } |
| 3240 | |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 3241 | private void handleEnterAnimationComplete(IBinder token) { |
| 3242 | ActivityClientRecord r = mActivities.get(token); |
| 3243 | if (r != null) { |
Filip Gruszczynski | 6eafa90 | 2014-11-14 14:24:37 -0800 | [diff] [blame] | 3244 | r.activity.dispatchEnterAnimationComplete(); |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 3245 | } |
| 3246 | } |
| 3247 | |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 3248 | private void handleStartBinderTracking() { |
| 3249 | Binder.enableTracing(); |
| 3250 | } |
| 3251 | |
| 3252 | private void handleStopBinderTrackingAndDump(ParcelFileDescriptor fd) { |
| 3253 | try { |
| 3254 | Binder.disableTracing(); |
| 3255 | Binder.getTransactionTracker().writeTracesToFile(fd); |
| 3256 | } finally { |
| 3257 | IoUtils.closeQuietly(fd); |
| 3258 | Binder.getTransactionTracker().clearTraces(); |
| 3259 | } |
| 3260 | } |
| 3261 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 3262 | @Override |
| 3263 | public void handleMultiWindowModeChanged(IBinder token, boolean isInMultiWindowMode, |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 3264 | Configuration overrideConfig) { |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 3265 | final ActivityClientRecord r = mActivities.get(token); |
| 3266 | if (r != null) { |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 3267 | final Configuration newConfig = new Configuration(mConfiguration); |
| 3268 | if (overrideConfig != null) { |
| 3269 | newConfig.updateFrom(overrideConfig); |
| 3270 | } |
| 3271 | r.activity.dispatchMultiWindowModeChanged(isInMultiWindowMode, newConfig); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 3272 | } |
| 3273 | } |
| 3274 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 3275 | @Override |
| 3276 | public void handlePictureInPictureModeChanged(IBinder token, boolean isInPipMode, |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 3277 | Configuration overrideConfig) { |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 3278 | final ActivityClientRecord r = mActivities.get(token); |
| 3279 | if (r != null) { |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 3280 | final Configuration newConfig = new Configuration(mConfiguration); |
| 3281 | if (overrideConfig != null) { |
| 3282 | newConfig.updateFrom(overrideConfig); |
| 3283 | } |
| 3284 | r.activity.dispatchPictureInPictureModeChanged(isInPipMode, newConfig); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 3285 | } |
| 3286 | } |
| 3287 | |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 3288 | private void handleLocalVoiceInteractionStarted(IBinder token, IVoiceInteractor interactor) { |
| 3289 | final ActivityClientRecord r = mActivities.get(token); |
| 3290 | if (r != null) { |
| 3291 | r.voiceInteractor = interactor; |
| 3292 | r.activity.setVoiceInteractor(interactor); |
| 3293 | if (interactor == null) { |
| 3294 | r.activity.onLocalVoiceInteractionStopped(); |
| 3295 | } else { |
| 3296 | r.activity.onLocalVoiceInteractionStarted(); |
| 3297 | } |
| 3298 | } |
| 3299 | } |
| 3300 | |
Andreas Gampe | ab8a63b | 2018-01-05 13:55:15 -0800 | [diff] [blame] | 3301 | private static boolean attemptAttachAgent(String agent, ClassLoader classLoader) { |
Leonard Mosescu | f3409ce | 2016-10-06 17:32:05 -0700 | [diff] [blame] | 3302 | try { |
Andreas Gampe | ab8a63b | 2018-01-05 13:55:15 -0800 | [diff] [blame] | 3303 | VMDebug.attachAgent(agent, classLoader); |
| 3304 | return true; |
Leonard Mosescu | f3409ce | 2016-10-06 17:32:05 -0700 | [diff] [blame] | 3305 | } catch (IOException e) { |
Andreas Gampe | ab8a63b | 2018-01-05 13:55:15 -0800 | [diff] [blame] | 3306 | Slog.e(TAG, "Attaching agent with " + classLoader + " failed: " + agent); |
| 3307 | return false; |
| 3308 | } |
| 3309 | } |
| 3310 | |
| 3311 | static void handleAttachAgent(String agent, LoadedApk loadedApk) { |
| 3312 | ClassLoader classLoader = loadedApk != null ? loadedApk.getClassLoader() : null; |
| 3313 | if (attemptAttachAgent(agent, classLoader)) { |
| 3314 | return; |
| 3315 | } |
| 3316 | if (classLoader != null) { |
| 3317 | attemptAttachAgent(agent, null); |
Leonard Mosescu | f3409ce | 2016-10-06 17:32:05 -0700 | [diff] [blame] | 3318 | } |
| 3319 | } |
| 3320 | |
Brad Fitzpatrick | bfb1919 | 2010-10-29 15:25:44 -0700 | [diff] [blame] | 3321 | private static final ThreadLocal<Intent> sCurrentBroadcastIntent = new ThreadLocal<Intent>(); |
| 3322 | |
| 3323 | /** |
| 3324 | * Return the Intent that's currently being handled by a |
| 3325 | * BroadcastReceiver on this thread, or null if none. |
| 3326 | * @hide |
| 3327 | */ |
| 3328 | public static Intent getIntentBeingBroadcast() { |
| 3329 | return sCurrentBroadcastIntent.get(); |
| 3330 | } |
| 3331 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3332 | private void handleReceiver(ReceiverData data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3333 | // If we are getting ready to gc after going to the background, well |
| 3334 | // we are back active so skip it. |
| 3335 | unscheduleGcIdler(); |
| 3336 | |
| 3337 | String component = data.intent.getComponent().getClassName(); |
| 3338 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3339 | LoadedApk packageInfo = getPackageInfoNoCheck( |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 3340 | data.info.applicationInfo, data.compatInfo); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3341 | |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3342 | IActivityManager mgr = ActivityManager.getService(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3343 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 3344 | Application app; |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3345 | BroadcastReceiver receiver; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 3346 | ContextImpl context; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3347 | try { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3348 | app = packageInfo.makeApplication(false, mInstrumentation); |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 3349 | context = (ContextImpl) app.getBaseContext(); |
| 3350 | if (data.info.splitName != null) { |
| 3351 | context = (ContextImpl) context.createContextForSplit(data.info.splitName); |
| 3352 | } |
| 3353 | java.lang.ClassLoader cl = context.getClassLoader(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3354 | data.intent.setExtrasClassLoader(cl); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 3355 | data.intent.prepareToEnterProcess(); |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 3356 | data.setExtrasClassLoader(cl); |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3357 | receiver = packageInfo.getAppFactory() |
Jason Monk | a80bfb5 | 2017-11-16 17:15:37 -0500 | [diff] [blame] | 3358 | .instantiateReceiver(cl, data.info.name, data.intent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3359 | } catch (Exception e) { |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 3360 | if (DEBUG_BROADCAST) Slog.i(TAG, |
| 3361 | "Finishing failed broadcast to " + data.intent.getComponent()); |
| 3362 | data.sendFinished(mgr); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3363 | throw new RuntimeException( |
| 3364 | "Unable to instantiate receiver " + component |
| 3365 | + ": " + e.toString(), e); |
| 3366 | } |
| 3367 | |
| 3368 | try { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3369 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3370 | TAG, "Performing receive of " + data.intent |
| 3371 | + ": app=" + app |
| 3372 | + ", appName=" + app.getPackageName() |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3373 | + ", pkg=" + packageInfo.getPackageName() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3374 | + ", comp=" + data.intent.getComponent().toShortString() |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3375 | + ", dir=" + packageInfo.getAppDir()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3376 | |
Brad Fitzpatrick | bfb1919 | 2010-10-29 15:25:44 -0700 | [diff] [blame] | 3377 | sCurrentBroadcastIntent.set(data.intent); |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 3378 | receiver.setPendingResult(data); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3379 | receiver.onReceive(context.getReceiverRestrictedContext(), |
| 3380 | data.intent); |
| 3381 | } catch (Exception e) { |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 3382 | if (DEBUG_BROADCAST) Slog.i(TAG, |
| 3383 | "Finishing failed broadcast to " + data.intent.getComponent()); |
| 3384 | data.sendFinished(mgr); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3385 | if (!mInstrumentation.onException(receiver, e)) { |
| 3386 | throw new RuntimeException( |
| 3387 | "Unable to start receiver " + component |
| 3388 | + ": " + e.toString(), e); |
| 3389 | } |
Brad Fitzpatrick | bfb1919 | 2010-10-29 15:25:44 -0700 | [diff] [blame] | 3390 | } finally { |
| 3391 | sCurrentBroadcastIntent.set(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3392 | } |
| 3393 | |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 3394 | if (receiver.getPendingResult() != null) { |
| 3395 | data.finish(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3396 | } |
| 3397 | } |
| 3398 | |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3399 | // Instantiate a BackupAgent and tell it that it's alive |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3400 | private void handleCreateBackupAgent(CreateBackupAgentData data) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3401 | if (DEBUG_BACKUP) Slog.v(TAG, "handleCreateBackupAgent: " + data); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3402 | |
Christopher Tate | 346acb1 | 2012-10-15 19:20:25 -0700 | [diff] [blame] | 3403 | // Sanity check the requested target package's uid against ours |
| 3404 | try { |
| 3405 | PackageInfo requestedPackage = getPackageManager().getPackageInfo( |
| 3406 | data.appInfo.packageName, 0, UserHandle.myUserId()); |
| 3407 | if (requestedPackage.applicationInfo.uid != Process.myUid()) { |
| 3408 | Slog.w(TAG, "Asked to instantiate non-matching package " |
| 3409 | + data.appInfo.packageName); |
| 3410 | return; |
| 3411 | } |
| 3412 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3413 | throw e.rethrowFromSystemServer(); |
Christopher Tate | 346acb1 | 2012-10-15 19:20:25 -0700 | [diff] [blame] | 3414 | } |
| 3415 | |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3416 | // no longer idle; we have backup work to do |
| 3417 | unscheduleGcIdler(); |
| 3418 | |
| 3419 | // instantiate the BackupAgent class named in the manifest |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3420 | LoadedApk packageInfo = getPackageInfoNoCheck(data.appInfo, data.compatInfo); |
| 3421 | String packageName = packageInfo.mPackageName; |
Christopher Tate | 346acb1 | 2012-10-15 19:20:25 -0700 | [diff] [blame] | 3422 | if (packageName == null) { |
| 3423 | Slog.d(TAG, "Asked to create backup agent for nonexistent package"); |
| 3424 | return; |
| 3425 | } |
| 3426 | |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3427 | String classname = data.appInfo.backupAgentName; |
Christopher Tate | 79ec80d | 2011-06-24 14:58:49 -0700 | [diff] [blame] | 3428 | // full backup operation but no app-supplied agent? use the default implementation |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 3429 | if (classname == null && (data.backupMode == ApplicationThreadConstants.BACKUP_MODE_FULL |
| 3430 | || data.backupMode == ApplicationThreadConstants.BACKUP_MODE_RESTORE_FULL)) { |
Christopher Tate | 4a627c7 | 2011-04-01 14:43:32 -0700 | [diff] [blame] | 3431 | classname = "android.app.backup.FullBackupAgent"; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3432 | } |
Christopher Tate | 4a627c7 | 2011-04-01 14:43:32 -0700 | [diff] [blame] | 3433 | |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3434 | try { |
Christopher Tate | d1475e0 | 2009-07-09 15:36:17 -0700 | [diff] [blame] | 3435 | IBinder binder = null; |
Christopher Tate | 2e40d11 | 2014-07-15 12:37:38 -0700 | [diff] [blame] | 3436 | BackupAgent agent = mBackupAgents.get(packageName); |
| 3437 | if (agent != null) { |
| 3438 | // reusing the existing instance |
| 3439 | if (DEBUG_BACKUP) { |
| 3440 | Slog.v(TAG, "Reusing existing agent instance"); |
Christopher Tate | d1475e0 | 2009-07-09 15:36:17 -0700 | [diff] [blame] | 3441 | } |
Christopher Tate | 2e40d11 | 2014-07-15 12:37:38 -0700 | [diff] [blame] | 3442 | binder = agent.onBind(); |
| 3443 | } else { |
| 3444 | try { |
| 3445 | if (DEBUG_BACKUP) Slog.v(TAG, "Initializing agent class " + classname); |
| 3446 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3447 | java.lang.ClassLoader cl = packageInfo.getClassLoader(); |
Dan Sandler | 07fe63e | 2017-08-15 16:41:11 -0400 | [diff] [blame] | 3448 | agent = (BackupAgent) cl.loadClass(classname).newInstance(); |
Christopher Tate | 2e40d11 | 2014-07-15 12:37:38 -0700 | [diff] [blame] | 3449 | |
| 3450 | // set up the agent's context |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3451 | ContextImpl context = ContextImpl.createAppContext(this, packageInfo); |
Christopher Tate | 2e40d11 | 2014-07-15 12:37:38 -0700 | [diff] [blame] | 3452 | context.setOuterContext(agent); |
| 3453 | agent.attach(context); |
| 3454 | |
| 3455 | agent.onCreate(); |
| 3456 | binder = agent.onBind(); |
| 3457 | mBackupAgents.put(packageName, agent); |
| 3458 | } catch (Exception e) { |
| 3459 | // If this is during restore, fail silently; otherwise go |
| 3460 | // ahead and let the user see the crash. |
| 3461 | Slog.e(TAG, "Agent threw during creation: " + e); |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 3462 | if (data.backupMode != ApplicationThreadConstants.BACKUP_MODE_RESTORE |
| 3463 | && data.backupMode != |
| 3464 | ApplicationThreadConstants.BACKUP_MODE_RESTORE_FULL) { |
Christopher Tate | 2e40d11 | 2014-07-15 12:37:38 -0700 | [diff] [blame] | 3465 | throw e; |
| 3466 | } |
| 3467 | // falling through with 'binder' still null |
| 3468 | } |
Christopher Tate | d1475e0 | 2009-07-09 15:36:17 -0700 | [diff] [blame] | 3469 | } |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3470 | |
| 3471 | // tell the OS that we're live now |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3472 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3473 | ActivityManager.getService().backupAgentCreated(packageName, binder); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3474 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3475 | throw e.rethrowFromSystemServer(); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3476 | } |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3477 | } catch (Exception e) { |
| 3478 | throw new RuntimeException("Unable to create BackupAgent " |
Christopher Tate | 4a627c7 | 2011-04-01 14:43:32 -0700 | [diff] [blame] | 3479 | + classname + ": " + e.toString(), e); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3480 | } |
| 3481 | } |
| 3482 | |
| 3483 | // Tear down a BackupAgent |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3484 | private void handleDestroyBackupAgent(CreateBackupAgentData data) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3485 | if (DEBUG_BACKUP) Slog.v(TAG, "handleDestroyBackupAgent: " + data); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3486 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3487 | LoadedApk packageInfo = getPackageInfoNoCheck(data.appInfo, data.compatInfo); |
| 3488 | String packageName = packageInfo.mPackageName; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3489 | BackupAgent agent = mBackupAgents.get(packageName); |
| 3490 | if (agent != null) { |
| 3491 | try { |
| 3492 | agent.onDestroy(); |
| 3493 | } catch (Exception e) { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 3494 | 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] | 3495 | e.printStackTrace(); |
| 3496 | } |
| 3497 | mBackupAgents.remove(packageName); |
| 3498 | } else { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 3499 | Slog.w(TAG, "Attempt to destroy unknown backup agent " + data); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3500 | } |
| 3501 | } |
| 3502 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3503 | private void handleCreateService(CreateServiceData data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3504 | // If we are getting ready to gc after going to the background, well |
| 3505 | // we are back active so skip it. |
| 3506 | unscheduleGcIdler(); |
| 3507 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3508 | LoadedApk packageInfo = getPackageInfoNoCheck( |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 3509 | data.info.applicationInfo, data.compatInfo); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3510 | Service service = null; |
| 3511 | try { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3512 | java.lang.ClassLoader cl = packageInfo.getClassLoader(); |
| 3513 | service = packageInfo.getAppFactory() |
Jason Monk | a80bfb5 | 2017-11-16 17:15:37 -0500 | [diff] [blame] | 3514 | .instantiateService(cl, data.info.name, data.intent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3515 | } catch (Exception e) { |
| 3516 | if (!mInstrumentation.onException(service, e)) { |
| 3517 | throw new RuntimeException( |
| 3518 | "Unable to instantiate service " + data.info.name |
| 3519 | + ": " + e.toString(), e); |
| 3520 | } |
| 3521 | } |
| 3522 | |
| 3523 | try { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3524 | 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] | 3525 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3526 | ContextImpl context = ContextImpl.createAppContext(this, packageInfo); |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 3527 | context.setOuterContext(service); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3528 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3529 | Application app = packageInfo.makeApplication(false, mInstrumentation); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3530 | service.attach(context, this, data.info.name, data.token, app, |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3531 | ActivityManager.getService()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3532 | service.onCreate(); |
| 3533 | mServices.put(data.token, service); |
| 3534 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3535 | ActivityManager.getService().serviceDoneExecuting( |
Dianne Hackborn | 455625e | 2015-01-21 09:55:13 -0800 | [diff] [blame] | 3536 | data.token, SERVICE_DONE_EXECUTING_ANON, 0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3537 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3538 | throw e.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3539 | } |
| 3540 | } catch (Exception e) { |
| 3541 | if (!mInstrumentation.onException(service, e)) { |
| 3542 | throw new RuntimeException( |
| 3543 | "Unable to create service " + data.info.name |
| 3544 | + ": " + e.toString(), e); |
| 3545 | } |
| 3546 | } |
| 3547 | } |
| 3548 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3549 | private void handleBindService(BindServiceData data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3550 | Service s = mServices.get(data.token); |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 3551 | if (DEBUG_SERVICE) |
| 3552 | Slog.v(TAG, "handleBindService s=" + s + " rebind=" + data.rebind); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3553 | if (s != null) { |
| 3554 | try { |
| 3555 | data.intent.setExtrasClassLoader(s.getClassLoader()); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 3556 | data.intent.prepareToEnterProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3557 | try { |
| 3558 | if (!data.rebind) { |
| 3559 | IBinder binder = s.onBind(data.intent); |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3560 | ActivityManager.getService().publishService( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3561 | data.token, data.intent, binder); |
| 3562 | } else { |
| 3563 | s.onRebind(data.intent); |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3564 | ActivityManager.getService().serviceDoneExecuting( |
Dianne Hackborn | 455625e | 2015-01-21 09:55:13 -0800 | [diff] [blame] | 3565 | data.token, SERVICE_DONE_EXECUTING_ANON, 0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3566 | } |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 3567 | ensureJitEnabled(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3568 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3569 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3570 | } |
| 3571 | } catch (Exception e) { |
| 3572 | if (!mInstrumentation.onException(s, e)) { |
| 3573 | throw new RuntimeException( |
| 3574 | "Unable to bind to service " + s |
| 3575 | + " with " + data.intent + ": " + e.toString(), e); |
| 3576 | } |
| 3577 | } |
| 3578 | } |
| 3579 | } |
| 3580 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3581 | private void handleUnbindService(BindServiceData data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3582 | Service s = mServices.get(data.token); |
| 3583 | if (s != null) { |
| 3584 | try { |
| 3585 | data.intent.setExtrasClassLoader(s.getClassLoader()); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 3586 | data.intent.prepareToEnterProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3587 | boolean doRebind = s.onUnbind(data.intent); |
| 3588 | try { |
| 3589 | if (doRebind) { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3590 | ActivityManager.getService().unbindFinished( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3591 | data.token, data.intent, doRebind); |
| 3592 | } else { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3593 | ActivityManager.getService().serviceDoneExecuting( |
Dianne Hackborn | 455625e | 2015-01-21 09:55:13 -0800 | [diff] [blame] | 3594 | data.token, SERVICE_DONE_EXECUTING_ANON, 0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3595 | } |
| 3596 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3597 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3598 | } |
| 3599 | } catch (Exception e) { |
| 3600 | if (!mInstrumentation.onException(s, e)) { |
| 3601 | throw new RuntimeException( |
| 3602 | "Unable to unbind to service " + s |
| 3603 | + " with " + data.intent + ": " + e.toString(), e); |
| 3604 | } |
| 3605 | } |
| 3606 | } |
| 3607 | } |
| 3608 | |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 3609 | private void handleDumpService(DumpComponentInfo info) { |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3610 | final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); |
| 3611 | try { |
| 3612 | Service s = mServices.get(info.token); |
| 3613 | if (s != null) { |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 3614 | PrintWriter pw = new FastPrintWriter(new FileOutputStream( |
| 3615 | info.fd.getFileDescriptor())); |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3616 | s.dump(info.fd.getFileDescriptor(), pw, info.args); |
| 3617 | pw.flush(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3618 | } |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3619 | } finally { |
| 3620 | IoUtils.closeQuietly(info.fd); |
| 3621 | StrictMode.setThreadPolicy(oldPolicy); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3622 | } |
| 3623 | } |
| 3624 | |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 3625 | private void handleDumpActivity(DumpComponentInfo info) { |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3626 | final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); |
| 3627 | try { |
| 3628 | ActivityClientRecord r = mActivities.get(info.token); |
| 3629 | if (r != null && r.activity != null) { |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 3630 | PrintWriter pw = new FastPrintWriter(new FileOutputStream( |
| 3631 | info.fd.getFileDescriptor())); |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3632 | r.activity.dump(info.prefix, info.fd.getFileDescriptor(), pw, info.args); |
| 3633 | pw.flush(); |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 3634 | } |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3635 | } finally { |
| 3636 | IoUtils.closeQuietly(info.fd); |
| 3637 | StrictMode.setThreadPolicy(oldPolicy); |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 3638 | } |
| 3639 | } |
| 3640 | |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 3641 | private void handleDumpProvider(DumpComponentInfo info) { |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3642 | final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); |
| 3643 | try { |
| 3644 | ProviderClientRecord r = mLocalProviders.get(info.token); |
| 3645 | if (r != null && r.mLocalProvider != null) { |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 3646 | PrintWriter pw = new FastPrintWriter(new FileOutputStream( |
| 3647 | info.fd.getFileDescriptor())); |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3648 | r.mLocalProvider.dump(info.fd.getFileDescriptor(), pw, info.args); |
| 3649 | pw.flush(); |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 3650 | } |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3651 | } finally { |
| 3652 | IoUtils.closeQuietly(info.fd); |
| 3653 | StrictMode.setThreadPolicy(oldPolicy); |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 3654 | } |
| 3655 | } |
| 3656 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3657 | private void handleServiceArgs(ServiceArgsData data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3658 | Service s = mServices.get(data.token); |
| 3659 | if (s != null) { |
| 3660 | try { |
| 3661 | if (data.args != null) { |
| 3662 | data.args.setExtrasClassLoader(s.getClassLoader()); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 3663 | data.args.prepareToEnterProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3664 | } |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 3665 | int res; |
| 3666 | if (!data.taskRemoved) { |
| 3667 | res = s.onStartCommand(data.args, data.flags, data.startId); |
| 3668 | } else { |
| 3669 | s.onTaskRemoved(data.args); |
| 3670 | res = Service.START_TASK_REMOVED_COMPLETE; |
| 3671 | } |
Brad Fitzpatrick | 333b8cb | 2010-08-26 12:04:57 -0700 | [diff] [blame] | 3672 | |
| 3673 | QueuedWork.waitToFinish(); |
| 3674 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3675 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3676 | ActivityManager.getService().serviceDoneExecuting( |
Dianne Hackborn | 455625e | 2015-01-21 09:55:13 -0800 | [diff] [blame] | 3677 | data.token, SERVICE_DONE_EXECUTING_START, data.startId, res); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3678 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3679 | throw e.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3680 | } |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 3681 | ensureJitEnabled(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3682 | } catch (Exception e) { |
| 3683 | if (!mInstrumentation.onException(s, e)) { |
| 3684 | throw new RuntimeException( |
| 3685 | "Unable to start service " + s |
| 3686 | + " with " + data.args + ": " + e.toString(), e); |
| 3687 | } |
| 3688 | } |
| 3689 | } |
| 3690 | } |
| 3691 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3692 | private void handleStopService(IBinder token) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3693 | Service s = mServices.remove(token); |
| 3694 | if (s != null) { |
| 3695 | try { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3696 | if (localLOGV) Slog.v(TAG, "Destroying service " + s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3697 | s.onDestroy(); |
Amith Yamasani | 7592825 | 2017-05-22 15:10:47 -0700 | [diff] [blame] | 3698 | s.detachAndCleanUp(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3699 | Context context = s.getBaseContext(); |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 3700 | if (context instanceof ContextImpl) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3701 | final String who = s.getClassName(); |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 3702 | ((ContextImpl) context).scheduleFinalCleanup(who, "Service"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3703 | } |
Brad Fitzpatrick | 333b8cb | 2010-08-26 12:04:57 -0700 | [diff] [blame] | 3704 | |
| 3705 | QueuedWork.waitToFinish(); |
| 3706 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3707 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3708 | ActivityManager.getService().serviceDoneExecuting( |
Dianne Hackborn | 455625e | 2015-01-21 09:55:13 -0800 | [diff] [blame] | 3709 | token, SERVICE_DONE_EXECUTING_STOP, 0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3710 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3711 | throw e.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3712 | } |
| 3713 | } catch (Exception e) { |
| 3714 | if (!mInstrumentation.onException(s, e)) { |
| 3715 | throw new RuntimeException( |
| 3716 | "Unable to stop service " + s |
| 3717 | + ": " + e.toString(), e); |
| 3718 | } |
Craig Mautner | 66c4a82 | 2015-01-16 12:48:16 -0800 | [diff] [blame] | 3719 | Slog.i(TAG, "handleStopService: exception for " + token, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3720 | } |
Craig Mautner | 9776ad4 | 2015-01-15 14:38:39 -0800 | [diff] [blame] | 3721 | } else { |
| 3722 | Slog.i(TAG, "handleStopService: token=" + token + " not found."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3723 | } |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3724 | //Slog.i(TAG, "Running services: " + mServices); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3725 | } |
| 3726 | |
Andrii Kulian | d9e2acb | 2018-03-29 16:07:11 -0700 | [diff] [blame] | 3727 | /** |
| 3728 | * Resume the activity. |
| 3729 | * @param token Target activity token. |
| 3730 | * @param finalStateRequest Flag indicating if this is part of final state resolution for a |
| 3731 | * transaction. |
| 3732 | * @param reason Reason for performing the action. |
| 3733 | * |
| 3734 | * @return The {@link ActivityClientRecord} that was resumed, {@code null} otherwise. |
| 3735 | */ |
| 3736 | @VisibleForTesting |
| 3737 | public ActivityClientRecord performResumeActivity(IBinder token, boolean finalStateRequest, |
Andrii Kulian | dfbf971 | 2018-03-08 15:42:24 -0800 | [diff] [blame] | 3738 | String reason) { |
Andrii Kulian | d9e2acb | 2018-03-29 16:07:11 -0700 | [diff] [blame] | 3739 | final ActivityClientRecord r = mActivities.get(token); |
| 3740 | if (localLOGV) { |
| 3741 | Slog.v(TAG, "Performing resume of " + r + " finished=" + r.activity.mFinished); |
| 3742 | } |
| 3743 | if (r == null || r.activity.mFinished) { |
| 3744 | return null; |
| 3745 | } |
| 3746 | if (r.getLifecycleState() == ON_RESUME) { |
| 3747 | if (!finalStateRequest) { |
| 3748 | final RuntimeException e = new IllegalStateException( |
| 3749 | "Trying to resume activity which is already resumed"); |
| 3750 | Slog.e(TAG, e.getMessage(), e); |
| 3751 | Slog.e(TAG, r.getStateString()); |
| 3752 | // TODO(lifecycler): A double resume request is possible when an activity |
| 3753 | // receives two consequent transactions with relaunch requests and "resumed" |
| 3754 | // final state requests and the second relaunch is omitted. We still try to |
| 3755 | // handle two resume requests for the final state. For cases other than this |
| 3756 | // one, we don't expect it to happen. |
Andrii Kulian | 9956d89 | 2018-02-14 13:48:56 -0800 | [diff] [blame] | 3757 | } |
Andrii Kulian | d9e2acb | 2018-03-29 16:07:11 -0700 | [diff] [blame] | 3758 | return null; |
| 3759 | } |
| 3760 | if (finalStateRequest) { |
| 3761 | r.hideForNow = false; |
| 3762 | r.activity.mStartedActivity = false; |
| 3763 | } |
| 3764 | try { |
| 3765 | r.activity.onStateNotSaved(); |
| 3766 | r.activity.mFragments.noteStateNotSaved(); |
| 3767 | checkAndBlockForNetworkAccess(); |
| 3768 | if (r.pendingIntents != null) { |
| 3769 | deliverNewIntents(r, r.pendingIntents); |
| 3770 | r.pendingIntents = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3771 | } |
Andrii Kulian | d9e2acb | 2018-03-29 16:07:11 -0700 | [diff] [blame] | 3772 | if (r.pendingResults != null) { |
Andrii Kulian | e55b009 | 2018-04-19 15:29:22 -0700 | [diff] [blame] | 3773 | deliverResults(r, r.pendingResults, reason); |
Andrii Kulian | d9e2acb | 2018-03-29 16:07:11 -0700 | [diff] [blame] | 3774 | r.pendingResults = null; |
| 3775 | } |
| 3776 | r.activity.performResume(r.startsNotResumed, reason); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3777 | |
Andrii Kulian | d9e2acb | 2018-03-29 16:07:11 -0700 | [diff] [blame] | 3778 | r.state = null; |
| 3779 | r.persistentState = null; |
| 3780 | r.setState(ON_RESUME); |
| 3781 | } catch (Exception e) { |
| 3782 | if (!mInstrumentation.onException(r.activity, e)) { |
| 3783 | throw new RuntimeException("Unable to resume activity " |
| 3784 | + r.intent.getComponent().toShortString() + ": " + e.toString(), e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3785 | } |
| 3786 | } |
| 3787 | return r; |
| 3788 | } |
| 3789 | |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 3790 | static final void cleanUpPendingRemoveWindows(ActivityClientRecord r, boolean force) { |
| 3791 | if (r.mPreserveWindow && !force) { |
| 3792 | return; |
| 3793 | } |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 3794 | if (r.mPendingRemoveWindow != null) { |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 3795 | r.mPendingRemoveWindowManager.removeViewImmediate( |
| 3796 | r.mPendingRemoveWindow.getDecorView()); |
| 3797 | IBinder wtoken = r.mPendingRemoveWindow.getDecorView().getWindowToken(); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 3798 | if (wtoken != null) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 3799 | WindowManagerGlobal.getInstance().closeAll(wtoken, |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 3800 | r.activity.getClass().getName(), "Activity"); |
| 3801 | } |
| 3802 | } |
| 3803 | r.mPendingRemoveWindow = null; |
| 3804 | r.mPendingRemoveWindowManager = null; |
| 3805 | } |
| 3806 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 3807 | @Override |
Andrii Kulian | dfbf971 | 2018-03-08 15:42:24 -0800 | [diff] [blame] | 3808 | public void handleResumeActivity(IBinder token, boolean finalStateRequest, boolean isForward, |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 3809 | String reason) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3810 | // If we are getting ready to gc after going to the background, well |
| 3811 | // we are back active so skip it. |
| 3812 | unscheduleGcIdler(); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3813 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3814 | |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 3815 | // TODO Push resumeArgs into the activity for consideration |
Andrii Kulian | dfbf971 | 2018-03-08 15:42:24 -0800 | [diff] [blame] | 3816 | final ActivityClientRecord r = performResumeActivity(token, finalStateRequest, reason); |
Andrii Kulian | d9e2acb | 2018-03-29 16:07:11 -0700 | [diff] [blame] | 3817 | if (r == null) { |
| 3818 | // We didn't actually resume the activity, so skipping any follow-up actions. |
| 3819 | return; |
| 3820 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3821 | |
Andrii Kulian | d9e2acb | 2018-03-29 16:07:11 -0700 | [diff] [blame] | 3822 | final Activity a = r.activity; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3823 | |
Andrii Kulian | d9e2acb | 2018-03-29 16:07:11 -0700 | [diff] [blame] | 3824 | if (localLOGV) { |
| 3825 | Slog.v(TAG, "Resume " + r + " started activity: " + a.mStartedActivity |
| 3826 | + ", hideForNow: " + r.hideForNow + ", finished: " + a.mFinished); |
| 3827 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3828 | |
Andrii Kulian | d9e2acb | 2018-03-29 16:07:11 -0700 | [diff] [blame] | 3829 | final int forwardBit = isForward |
| 3830 | ? WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION : 0; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3831 | |
Andrii Kulian | d9e2acb | 2018-03-29 16:07:11 -0700 | [diff] [blame] | 3832 | // If the window hasn't yet been added to the window manager, |
| 3833 | // and this guy didn't finish itself or start another activity, |
| 3834 | // then go ahead and add the window. |
| 3835 | boolean willBeVisible = !a.mStartedActivity; |
| 3836 | if (!willBeVisible) { |
| 3837 | try { |
| 3838 | willBeVisible = ActivityManager.getService().willActivityBeVisible( |
| 3839 | a.getActivityToken()); |
| 3840 | } catch (RemoteException e) { |
| 3841 | throw e.rethrowFromSystemServer(); |
| 3842 | } |
| 3843 | } |
| 3844 | if (r.window == null && !a.mFinished && willBeVisible) { |
| 3845 | r.window = r.activity.getWindow(); |
| 3846 | View decor = r.window.getDecorView(); |
| 3847 | decor.setVisibility(View.INVISIBLE); |
| 3848 | ViewManager wm = a.getWindowManager(); |
| 3849 | WindowManager.LayoutParams l = r.window.getAttributes(); |
| 3850 | a.mDecor = decor; |
| 3851 | l.type = WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
| 3852 | l.softInputMode |= forwardBit; |
| 3853 | if (r.mPreserveWindow) { |
| 3854 | a.mWindowAdded = true; |
| 3855 | r.mPreserveWindow = false; |
| 3856 | // Normally the ViewRoot sets up callbacks with the Activity |
| 3857 | // in addView->ViewRootImpl#setView. If we are instead reusing |
| 3858 | // the decor view we have to notify the view root that the |
| 3859 | // callbacks may have changed. |
| 3860 | ViewRootImpl impl = decor.getViewRootImpl(); |
| 3861 | if (impl != null) { |
| 3862 | impl.notifyChildRebuilt(); |
Dianne Hackborn | 061d58a | 2010-03-12 15:07:06 -0800 | [diff] [blame] | 3863 | } |
| 3864 | } |
Andrii Kulian | d9e2acb | 2018-03-29 16:07:11 -0700 | [diff] [blame] | 3865 | if (a.mVisibleFromClient) { |
| 3866 | if (!a.mWindowAdded) { |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 3867 | a.mWindowAdded = true; |
Andrii Kulian | d9e2acb | 2018-03-29 16:07:11 -0700 | [diff] [blame] | 3868 | wm.addView(decor, l); |
| 3869 | } else { |
| 3870 | // The activity will get a callback for this {@link LayoutParams} change |
| 3871 | // earlier. However, at that time the decor will not be set (this is set |
| 3872 | // in this method), so no action will be taken. This call ensures the |
| 3873 | // callback occurs with the decor set. |
| 3874 | a.onWindowAttributesChanged(l); |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 3875 | } |
Andrii Kulian | d9e2acb | 2018-03-29 16:07:11 -0700 | [diff] [blame] | 3876 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3877 | |
| 3878 | // If the window has already been added, but during resume |
| 3879 | // we started another activity, then don't yet make the |
Dianne Hackborn | 061d58a | 2010-03-12 15:07:06 -0800 | [diff] [blame] | 3880 | // window visible. |
Andrii Kulian | d9e2acb | 2018-03-29 16:07:11 -0700 | [diff] [blame] | 3881 | } else if (!willBeVisible) { |
| 3882 | if (localLOGV) Slog.v(TAG, "Launch " + r + " mStartedActivity set"); |
| 3883 | r.hideForNow = true; |
| 3884 | } |
| 3885 | |
| 3886 | // Get rid of anything left hanging around. |
| 3887 | cleanUpPendingRemoveWindows(r, false /* force */); |
| 3888 | |
| 3889 | // The window is now visible if it has been added, we are not |
| 3890 | // simply finishing, and we are not starting another activity. |
| 3891 | if (!r.activity.mFinished && willBeVisible && r.activity.mDecor != null && !r.hideForNow) { |
| 3892 | if (r.newConfig != null) { |
| 3893 | performConfigurationChangedForActivity(r, r.newConfig); |
| 3894 | if (DEBUG_CONFIGURATION) { |
| 3895 | Slog.v(TAG, "Resuming activity " + r.activityInfo.name + " with newConfig " |
| 3896 | + r.activity.mCurrentConfig); |
| 3897 | } |
| 3898 | r.newConfig = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3899 | } |
Andrii Kulian | d9e2acb | 2018-03-29 16:07:11 -0700 | [diff] [blame] | 3900 | if (localLOGV) Slog.v(TAG, "Resuming " + r + " with isForward=" + isForward); |
| 3901 | WindowManager.LayoutParams l = r.window.getAttributes(); |
| 3902 | if ((l.softInputMode |
| 3903 | & WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) |
| 3904 | != forwardBit) { |
| 3905 | l.softInputMode = (l.softInputMode |
| 3906 | & (~WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION)) |
| 3907 | | forwardBit; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3908 | if (r.activity.mVisibleFromClient) { |
Andrii Kulian | d9e2acb | 2018-03-29 16:07:11 -0700 | [diff] [blame] | 3909 | ViewManager wm = a.getWindowManager(); |
| 3910 | View decor = r.window.getDecorView(); |
| 3911 | wm.updateViewLayout(decor, l); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3912 | } |
| 3913 | } |
| 3914 | |
Andrii Kulian | d9e2acb | 2018-03-29 16:07:11 -0700 | [diff] [blame] | 3915 | r.activity.mVisibleFromServer = true; |
| 3916 | mNumVisibleActivities++; |
| 3917 | if (r.activity.mVisibleFromClient) { |
| 3918 | r.activity.makeVisible(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3919 | } |
| 3920 | } |
Andrii Kulian | d9e2acb | 2018-03-29 16:07:11 -0700 | [diff] [blame] | 3921 | |
| 3922 | r.nextIdle = mNewActivities; |
| 3923 | mNewActivities = r; |
| 3924 | if (localLOGV) Slog.v(TAG, "Scheduling idle handler for " + r); |
| 3925 | Looper.myQueue().addIdleHandler(new Idler()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3926 | } |
| 3927 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 3928 | @Override |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 3929 | public void handlePauseActivity(IBinder token, boolean finished, boolean userLeaving, |
Andrii Kulian | a6176e3 | 2018-02-27 11:51:18 -0800 | [diff] [blame] | 3930 | int configChanges, PendingTransactionActions pendingActions, String reason) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3931 | ActivityClientRecord r = mActivities.get(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3932 | if (r != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3933 | if (userLeaving) { |
| 3934 | performUserLeavingActivity(r); |
| 3935 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3936 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3937 | r.activity.mConfigChangeFlags |= configChanges; |
Andrii Kulian | d25680c | 2018-02-21 15:16:58 -0800 | [diff] [blame] | 3938 | performPauseActivity(r, finished, reason, pendingActions); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3939 | |
Dianne Hackborn | aa93bcd | 2010-10-27 13:57:00 -0700 | [diff] [blame] | 3940 | // Make sure any pending writes are now committed. |
Dianne Hackborn | 5d9d03a | 2011-01-24 13:15:09 -0800 | [diff] [blame] | 3941 | if (r.isPreHoneycomb()) { |
| 3942 | QueuedWork.waitToFinish(); |
| 3943 | } |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3944 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3945 | } |
| 3946 | } |
| 3947 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3948 | final void performUserLeavingActivity(ActivityClientRecord r) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3949 | mInstrumentation.callActivityOnUserLeaving(r.activity); |
| 3950 | } |
| 3951 | |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 3952 | final Bundle performPauseActivity(IBinder token, boolean finished, String reason, |
| 3953 | PendingTransactionActions pendingActions) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3954 | ActivityClientRecord r = mActivities.get(token); |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 3955 | return r != null ? performPauseActivity(r, finished, reason, pendingActions) : null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3956 | } |
| 3957 | |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 3958 | /** |
| 3959 | * Pause the activity. |
| 3960 | * @return Saved instance state for pre-Honeycomb apps if it was saved, {@code null} otherwise. |
| 3961 | */ |
| 3962 | private Bundle performPauseActivity(ActivityClientRecord r, boolean finished, String reason, |
| 3963 | PendingTransactionActions pendingActions) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3964 | if (r.paused) { |
| 3965 | if (r.activity.mFinished) { |
| 3966 | // If we are finishing, we won't call onResume() in certain cases. |
| 3967 | // So here we likewise don't want to call onPause() if the activity |
| 3968 | // isn't resumed. |
| 3969 | return null; |
| 3970 | } |
| 3971 | RuntimeException e = new RuntimeException( |
| 3972 | "Performing pause of activity that is not resumed: " |
| 3973 | + r.intent.getComponent().toShortString()); |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 3974 | Slog.e(TAG, e.getMessage(), e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3975 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3976 | if (finished) { |
| 3977 | r.activity.mFinished = true; |
| 3978 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3979 | |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 3980 | // Pre-Honeycomb apps always save their state before pausing |
| 3981 | final boolean shouldSaveState = !r.activity.mFinished && r.isPreHoneycomb(); |
| 3982 | if (shouldSaveState) { |
| 3983 | callActivityOnSaveInstanceState(r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3984 | } |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 3985 | |
| 3986 | performPauseActivityIfNeeded(r, reason); |
Jeff Hamilton | 52d3203 | 2011-01-08 15:31:26 -0600 | [diff] [blame] | 3987 | |
| 3988 | // Notify any outstanding on paused listeners |
| 3989 | ArrayList<OnActivityPausedListener> listeners; |
| 3990 | synchronized (mOnPauseListeners) { |
| 3991 | listeners = mOnPauseListeners.remove(r.activity); |
| 3992 | } |
| 3993 | int size = (listeners != null ? listeners.size() : 0); |
| 3994 | for (int i = 0; i < size; i++) { |
| 3995 | listeners.get(i).onPaused(r.activity); |
| 3996 | } |
| 3997 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 3998 | final Bundle oldState = pendingActions != null ? pendingActions.getOldState() : null; |
| 3999 | if (oldState != null) { |
| 4000 | // We need to keep around the original state, in case we need to be created again. |
| 4001 | // But we only do this for pre-Honeycomb apps, which always save their state when |
| 4002 | // pausing, so we can not have them save their state when restarting from a paused |
| 4003 | // state. For HC and later, we want to (and can) let the state be saved as the |
| 4004 | // normal part of stopping the activity. |
| 4005 | if (r.isPreHoneycomb()) { |
| 4006 | r.state = oldState; |
| 4007 | } |
| 4008 | } |
| 4009 | |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 4010 | return shouldSaveState ? r.state : null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4011 | } |
| 4012 | |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 4013 | private void performPauseActivityIfNeeded(ActivityClientRecord r, String reason) { |
| 4014 | if (r.paused) { |
| 4015 | // You are already paused silly... |
| 4016 | return; |
| 4017 | } |
| 4018 | |
| 4019 | try { |
| 4020 | r.activity.mCalled = false; |
| 4021 | mInstrumentation.callActivityOnPause(r.activity); |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 4022 | if (!r.activity.mCalled) { |
| 4023 | throw new SuperNotCalledException("Activity " + safeToComponentShortString(r.intent) |
| 4024 | + " did not call through to super.onPause()"); |
| 4025 | } |
| 4026 | } catch (SuperNotCalledException e) { |
| 4027 | throw e; |
| 4028 | } catch (Exception e) { |
| 4029 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4030 | throw new RuntimeException("Unable to pause activity " |
| 4031 | + safeToComponentShortString(r.intent) + ": " + e.toString(), e); |
| 4032 | } |
| 4033 | } |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4034 | r.setState(ON_PAUSE); |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 4035 | } |
| 4036 | |
Andrii Kulian | 829829c | 2018-03-19 18:19:05 -0700 | [diff] [blame] | 4037 | /** Called from {@link LocalActivityManager}. */ |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 4038 | final void performStopActivity(IBinder token, boolean saveState, String reason) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4039 | ActivityClientRecord r = mActivities.get(token); |
Andrii Kulian | 829829c | 2018-03-19 18:19:05 -0700 | [diff] [blame] | 4040 | performStopActivityInner(r, null /* stopInfo */, false /* keepShown */, saveState, |
| 4041 | false /* finalStateRequest */, reason); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4042 | } |
| 4043 | |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 4044 | private static final class ProviderRefCount { |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 4045 | public final ContentProviderHolder holder; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 4046 | public final ProviderClientRecord client; |
| 4047 | public int stableCount; |
| 4048 | public int unstableCount; |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 4049 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 4050 | // When this is set, the stable and unstable ref counts are 0 and |
| 4051 | // we have a pending operation scheduled to remove the ref count |
| 4052 | // from the activity manager. On the activity manager we are still |
| 4053 | // holding an unstable ref, though it is not reflected in the counts |
| 4054 | // here. |
| 4055 | public boolean removePending; |
| 4056 | |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 4057 | ProviderRefCount(ContentProviderHolder inHolder, |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 4058 | ProviderClientRecord inClient, int sCount, int uCount) { |
| 4059 | holder = inHolder; |
| 4060 | client = inClient; |
| 4061 | stableCount = sCount; |
| 4062 | unstableCount = uCount; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4063 | } |
| 4064 | } |
| 4065 | |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4066 | /** |
| 4067 | * Core implementation of stopping an activity. Note this is a little |
| 4068 | * tricky because the server's meaning of stop is slightly different |
| 4069 | * than our client -- for the server, stop means to save state and give |
| 4070 | * it the result when it is done, but the window may still be visible. |
| 4071 | * For the client, we want to call onStop()/onStart() to indicate when |
Wale Ogunwale | b5066fe | 2016-09-21 07:33:43 -0700 | [diff] [blame] | 4072 | * the activity's UI visibility changes. |
Andrii Kulian | 829829c | 2018-03-19 18:19:05 -0700 | [diff] [blame] | 4073 | * @param r Target activity client record. |
| 4074 | * @param info Action that will report activity stop to server. |
| 4075 | * @param keepShown Flag indicating whether the activity is still shown. |
| 4076 | * @param saveState Flag indicating whether the activity state should be saved. |
| 4077 | * @param finalStateRequest Flag indicating if this call is handling final lifecycle state |
| 4078 | * request for a transaction. |
| 4079 | * @param reason Reason for performing this operation. |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4080 | */ |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4081 | private void performStopActivityInner(ActivityClientRecord r, StopInfo info, boolean keepShown, |
Andrii Kulian | 829829c | 2018-03-19 18:19:05 -0700 | [diff] [blame] | 4082 | boolean saveState, boolean finalStateRequest, String reason) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4083 | if (localLOGV) Slog.v(TAG, "Performing stop of " + r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4084 | if (r != null) { |
| 4085 | if (!keepShown && r.stopped) { |
| 4086 | if (r.activity.mFinished) { |
| 4087 | // If we are finishing, we won't call onResume() in certain |
| 4088 | // cases. So here we likewise don't want to call onStop() |
| 4089 | // if the activity isn't resumed. |
| 4090 | return; |
| 4091 | } |
Andrii Kulian | 829829c | 2018-03-19 18:19:05 -0700 | [diff] [blame] | 4092 | if (!finalStateRequest) { |
| 4093 | final RuntimeException e = new RuntimeException( |
| 4094 | "Performing stop of activity that is already stopped: " |
| 4095 | + r.intent.getComponent().toShortString()); |
| 4096 | Slog.e(TAG, e.getMessage(), e); |
| 4097 | Slog.e(TAG, r.getStateString()); |
| 4098 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4099 | } |
| 4100 | |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 4101 | // One must first be paused before stopped... |
| 4102 | performPauseActivityIfNeeded(r, reason); |
| 4103 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4104 | if (info != null) { |
| 4105 | try { |
| 4106 | // First create a thumbnail for the activity... |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4107 | // For now, don't create the thumbnail here; we are |
| 4108 | // doing that by doing a screen snapshot. |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4109 | info.setDescription(r.activity.onCreateDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4110 | } catch (Exception e) { |
| 4111 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4112 | throw new RuntimeException( |
| 4113 | "Unable to save state of activity " |
| 4114 | + r.intent.getComponent().toShortString() |
| 4115 | + ": " + e.toString(), e); |
| 4116 | } |
| 4117 | } |
| 4118 | } |
| 4119 | |
| 4120 | if (!keepShown) { |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 4121 | callActivityOnStop(r, saveState, reason); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4122 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4123 | } |
| 4124 | } |
| 4125 | |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 4126 | /** |
| 4127 | * Calls {@link Activity#onStop()} and {@link Activity#onSaveInstanceState(Bundle)}, and updates |
| 4128 | * the client record's state. |
| 4129 | * All calls to stop an activity must be done through this method to make sure that |
| 4130 | * {@link Activity#onSaveInstanceState(Bundle)} is also executed in the same call. |
| 4131 | */ |
| 4132 | private void callActivityOnStop(ActivityClientRecord r, boolean saveState, String reason) { |
Andrii Kulian | 391161f | 2018-01-29 10:50:02 -0800 | [diff] [blame] | 4133 | // Before P onSaveInstanceState was called before onStop, starting with P it's |
| 4134 | // called after. Before Honeycomb state was always saved before onPause. |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 4135 | final boolean shouldSaveState = saveState && !r.activity.mFinished && r.state == null |
| 4136 | && !r.isPreHoneycomb(); |
Andrii Kulian | 391161f | 2018-01-29 10:50:02 -0800 | [diff] [blame] | 4137 | final boolean isPreP = r.isPreP(); |
| 4138 | if (shouldSaveState && isPreP) { |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 4139 | callActivityOnSaveInstanceState(r); |
| 4140 | } |
| 4141 | |
| 4142 | try { |
Andrii Kulian | d25680c | 2018-02-21 15:16:58 -0800 | [diff] [blame] | 4143 | r.activity.performStop(false /*preserveWindow*/, reason); |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 4144 | } catch (SuperNotCalledException e) { |
| 4145 | throw e; |
| 4146 | } catch (Exception e) { |
| 4147 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4148 | throw new RuntimeException( |
| 4149 | "Unable to stop activity " |
| 4150 | + r.intent.getComponent().toShortString() |
| 4151 | + ": " + e.toString(), e); |
| 4152 | } |
| 4153 | } |
| 4154 | r.setState(ON_STOP); |
Andrii Kulian | 391161f | 2018-01-29 10:50:02 -0800 | [diff] [blame] | 4155 | |
| 4156 | if (shouldSaveState && !isPreP) { |
| 4157 | callActivityOnSaveInstanceState(r); |
| 4158 | } |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 4159 | } |
| 4160 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 4161 | private void updateVisibility(ActivityClientRecord r, boolean show) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4162 | View v = r.activity.mDecor; |
| 4163 | if (v != null) { |
| 4164 | if (show) { |
| 4165 | if (!r.activity.mVisibleFromServer) { |
| 4166 | r.activity.mVisibleFromServer = true; |
| 4167 | mNumVisibleActivities++; |
| 4168 | if (r.activity.mVisibleFromClient) { |
| 4169 | r.activity.makeVisible(); |
| 4170 | } |
| 4171 | } |
| 4172 | if (r.newConfig != null) { |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4173 | performConfigurationChangedForActivity(r, r.newConfig); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4174 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Updating activity vis " |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 4175 | + r.activityInfo.name + " with new config " |
| 4176 | + r.activity.mCurrentConfig); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4177 | r.newConfig = null; |
| 4178 | } |
| 4179 | } else { |
| 4180 | if (r.activity.mVisibleFromServer) { |
| 4181 | r.activity.mVisibleFromServer = false; |
| 4182 | mNumVisibleActivities--; |
| 4183 | v.setVisibility(View.INVISIBLE); |
| 4184 | } |
| 4185 | } |
| 4186 | } |
| 4187 | } |
| 4188 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 4189 | @Override |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4190 | public void handleStopActivity(IBinder token, boolean show, int configChanges, |
Andrii Kulian | 829829c | 2018-03-19 18:19:05 -0700 | [diff] [blame] | 4191 | PendingTransactionActions pendingActions, boolean finalStateRequest, String reason) { |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4192 | final ActivityClientRecord r = mActivities.get(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4193 | r.activity.mConfigChangeFlags |= configChanges; |
| 4194 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4195 | final StopInfo stopInfo = new StopInfo(); |
Andrii Kulian | 829829c | 2018-03-19 18:19:05 -0700 | [diff] [blame] | 4196 | performStopActivityInner(r, stopInfo, show, true /* saveState */, finalStateRequest, |
| 4197 | reason); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4198 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4199 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4200 | TAG, "Finishing stop of " + r + ": show=" + show |
| 4201 | + " win=" + r.window); |
| 4202 | |
| 4203 | updateVisibility(r, show); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4204 | |
Dianne Hackborn | 5d9d03a | 2011-01-24 13:15:09 -0800 | [diff] [blame] | 4205 | // Make sure any pending writes are now committed. |
| 4206 | if (!r.isPreHoneycomb()) { |
| 4207 | QueuedWork.waitToFinish(); |
| 4208 | } |
| 4209 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4210 | stopInfo.setActivity(r); |
| 4211 | stopInfo.setState(r.state); |
| 4212 | stopInfo.setPersistentState(r.persistentState); |
| 4213 | pendingActions.setStopInfo(stopInfo); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4214 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4215 | } |
| 4216 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4217 | /** |
| 4218 | * Schedule the call to tell the activity manager we have stopped. We don't do this |
| 4219 | * immediately, because we want to have a chance for any other pending work (in particular |
| 4220 | * memory trim requests) to complete before you tell the activity manager to proceed and allow |
| 4221 | * us to go fully into the background. |
| 4222 | */ |
| 4223 | @Override |
| 4224 | public void reportStop(PendingTransactionActions pendingActions) { |
| 4225 | mH.post(pendingActions.getStopInfo()); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 4226 | } |
| 4227 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4228 | @Override |
| 4229 | public void performRestartActivity(IBinder token, boolean start) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4230 | ActivityClientRecord r = mActivities.get(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4231 | if (r.stopped) { |
Andrii Kulian | d25680c | 2018-02-21 15:16:58 -0800 | [diff] [blame] | 4232 | r.activity.performRestart(start, "performRestartActivity"); |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4233 | if (start) { |
| 4234 | r.setState(ON_START); |
| 4235 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4236 | } |
| 4237 | } |
| 4238 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 4239 | @Override |
| 4240 | public void handleWindowVisibility(IBinder token, boolean show) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4241 | ActivityClientRecord r = mActivities.get(token); |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 4242 | |
Dianne Hackborn | bfddc0f | 2010-12-14 11:28:01 -0800 | [diff] [blame] | 4243 | if (r == null) { |
| 4244 | Log.w(TAG, "handleWindowVisibility: no activity for token " + token); |
| 4245 | return; |
| 4246 | } |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 4247 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4248 | if (!show && !r.stopped) { |
Andrii Kulian | 829829c | 2018-03-19 18:19:05 -0700 | [diff] [blame] | 4249 | performStopActivityInner(r, null /* stopInfo */, show, false /* saveState */, |
| 4250 | false /* finalStateRequest */, "handleWindowVisibility"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4251 | } else if (show && r.stopped) { |
| 4252 | // If we are getting ready to gc after going to the background, well |
| 4253 | // we are back active so skip it. |
| 4254 | unscheduleGcIdler(); |
| 4255 | |
Andrii Kulian | d25680c | 2018-02-21 15:16:58 -0800 | [diff] [blame] | 4256 | r.activity.performRestart(true /* start */, "handleWindowVisibility"); |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4257 | r.setState(ON_START); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4258 | } |
| 4259 | if (r.activity.mDecor != null) { |
Joe Onorato | 43a1765 | 2011-04-06 19:22:23 -0700 | [diff] [blame] | 4260 | if (false) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4261 | TAG, "Handle window " + r + " visibility: " + show); |
| 4262 | updateVisibility(r, show); |
| 4263 | } |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4264 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4265 | } |
| 4266 | |
Wale Ogunwale | b5066fe | 2016-09-21 07:33:43 -0700 | [diff] [blame] | 4267 | // TODO: This method should be changed to use {@link #performStopActivityInner} to perform to |
| 4268 | // stop operation on the activity to reduce code duplication and the chance of fixing a bug in |
| 4269 | // one place and missing the other. |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 4270 | private void handleSleeping(IBinder token, boolean sleeping) { |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 4271 | ActivityClientRecord r = mActivities.get(token); |
| 4272 | |
| 4273 | if (r == null) { |
Dianne Hackborn | 842e04b | 2011-01-22 13:00:12 -0800 | [diff] [blame] | 4274 | Log.w(TAG, "handleSleeping: no activity for token " + token); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 4275 | return; |
| 4276 | } |
| 4277 | |
| 4278 | if (sleeping) { |
Dianne Hackborn | 842e04b | 2011-01-22 13:00:12 -0800 | [diff] [blame] | 4279 | if (!r.stopped && !r.isPreHoneycomb()) { |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 4280 | callActivityOnStop(r, true /* saveState */, "sleeping"); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 4281 | } |
Dianne Hackborn | 5d9d03a | 2011-01-24 13:15:09 -0800 | [diff] [blame] | 4282 | |
| 4283 | // Make sure any pending writes are now committed. |
| 4284 | if (!r.isPreHoneycomb()) { |
| 4285 | QueuedWork.waitToFinish(); |
| 4286 | } |
| 4287 | |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 4288 | // Tell activity manager we slept. |
| 4289 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 4290 | ActivityManager.getService().activitySlept(r.token); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 4291 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4292 | throw ex.rethrowFromSystemServer(); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 4293 | } |
| 4294 | } else { |
| 4295 | if (r.stopped && r.activity.mVisibleFromServer) { |
Andrii Kulian | d25680c | 2018-02-21 15:16:58 -0800 | [diff] [blame] | 4296 | r.activity.performRestart(true /* start */, "handleSleeping"); |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4297 | r.setState(ON_START); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 4298 | } |
| 4299 | } |
| 4300 | } |
| 4301 | |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 4302 | private void handleSetCoreSettings(Bundle coreSettings) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4303 | synchronized (mResourcesManager) { |
Svetoslav Ganov | 9aa597e | 2011-03-03 18:17:41 -0800 | [diff] [blame] | 4304 | mCoreSettings = coreSettings; |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 4305 | } |
Jon Miranda | 836c0a8 | 2014-08-11 12:32:26 -0700 | [diff] [blame] | 4306 | onCoreSettingsChange(); |
| 4307 | } |
| 4308 | |
| 4309 | private void onCoreSettingsChange() { |
| 4310 | boolean debugViewAttributes = |
| 4311 | mCoreSettings.getInt(Settings.Global.DEBUG_VIEW_ATTRIBUTES, 0) != 0; |
| 4312 | if (debugViewAttributes != View.mDebugViewAttributes) { |
| 4313 | View.mDebugViewAttributes = debugViewAttributes; |
| 4314 | |
| 4315 | // request all activities to relaunch for the changes to take place |
Wale Ogunwale | 5527a50 | 2018-02-20 18:18:21 -0800 | [diff] [blame] | 4316 | relaunchAllActivities(); |
Fyodor Kupolov | cb93d6f | 2017-05-04 17:27:16 -0700 | [diff] [blame] | 4317 | } |
| 4318 | } |
| 4319 | |
Wale Ogunwale | 5527a50 | 2018-02-20 18:18:21 -0800 | [diff] [blame] | 4320 | private void relaunchAllActivities() { |
Fyodor Kupolov | cb93d6f | 2017-05-04 17:27:16 -0700 | [diff] [blame] | 4321 | for (Map.Entry<IBinder, ActivityClientRecord> entry : mActivities.entrySet()) { |
| 4322 | final Activity activity = entry.getValue().activity; |
| 4323 | if (!activity.mFinished) { |
Andrii Kulian | 320e3b5 | 2018-05-03 16:26:25 -0700 | [diff] [blame] | 4324 | scheduleRelaunchActivity(entry.getKey()); |
Jon Miranda | 836c0a8 | 2014-08-11 12:32:26 -0700 | [diff] [blame] | 4325 | } |
| 4326 | } |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 4327 | } |
| 4328 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4329 | private void handleUpdatePackageCompatibilityInfo(UpdateCompatibilityData data) { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 4330 | LoadedApk apk = peekPackageInfo(data.pkg, false); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4331 | if (apk != null) { |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 4332 | apk.setCompatibilityInfo(data.info); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4333 | } |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 4334 | apk = peekPackageInfo(data.pkg, true); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4335 | if (apk != null) { |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 4336 | apk.setCompatibilityInfo(data.info); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4337 | } |
| 4338 | handleConfigurationChanged(mConfiguration, data.info); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 4339 | WindowManagerGlobal.getInstance().reportNewConfiguration(mConfiguration); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4340 | } |
| 4341 | |
Andrii Kulian | e55b009 | 2018-04-19 15:29:22 -0700 | [diff] [blame] | 4342 | 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] | 4343 | final int N = results.size(); |
| 4344 | for (int i=0; i<N; i++) { |
| 4345 | ResultInfo ri = results.get(i); |
| 4346 | try { |
| 4347 | if (ri.mData != null) { |
| 4348 | ri.mData.setExtrasClassLoader(r.activity.getClassLoader()); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 4349 | ri.mData.prepareToEnterProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4350 | } |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4351 | if (DEBUG_RESULTS) Slog.v(TAG, |
Chris Tate | 8a7dc17 | 2009-03-24 20:11:42 -0700 | [diff] [blame] | 4352 | "Delivering result to activity " + r + " : " + ri); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4353 | r.activity.dispatchActivityResult(ri.mResultWho, |
Andrii Kulian | e55b009 | 2018-04-19 15:29:22 -0700 | [diff] [blame] | 4354 | ri.mRequestCode, ri.mResultCode, ri.mData, reason); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4355 | } catch (Exception e) { |
| 4356 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4357 | throw new RuntimeException( |
| 4358 | "Failure delivering result " + ri + " to activity " |
| 4359 | + r.intent.getComponent().toShortString() |
| 4360 | + ": " + e.toString(), e); |
| 4361 | } |
| 4362 | } |
| 4363 | } |
| 4364 | } |
| 4365 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 4366 | @Override |
Andrii Kulian | e55b009 | 2018-04-19 15:29:22 -0700 | [diff] [blame] | 4367 | public void handleSendResult(IBinder token, List<ResultInfo> results, String reason) { |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 4368 | ActivityClientRecord r = mActivities.get(token); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4369 | 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] | 4370 | if (r != null) { |
| 4371 | final boolean resumed = !r.paused; |
| 4372 | if (!r.activity.mFinished && r.activity.mDecor != null |
| 4373 | && r.hideForNow && resumed) { |
| 4374 | // We had hidden the activity because it started another |
| 4375 | // one... we have gotten a result back and we are not |
| 4376 | // paused, so make sure our window is visible. |
| 4377 | updateVisibility(r, true); |
| 4378 | } |
| 4379 | if (resumed) { |
| 4380 | try { |
| 4381 | // Now we are idle. |
| 4382 | r.activity.mCalled = false; |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 4383 | r.activity.mTemporaryPause = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4384 | mInstrumentation.callActivityOnPause(r.activity); |
| 4385 | if (!r.activity.mCalled) { |
| 4386 | throw new SuperNotCalledException( |
| 4387 | "Activity " + r.intent.getComponent().toShortString() |
| 4388 | + " did not call through to super.onPause()"); |
| 4389 | } |
| 4390 | } catch (SuperNotCalledException e) { |
| 4391 | throw e; |
| 4392 | } catch (Exception e) { |
| 4393 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4394 | throw new RuntimeException( |
| 4395 | "Unable to pause activity " |
| 4396 | + r.intent.getComponent().toShortString() |
| 4397 | + ": " + e.toString(), e); |
| 4398 | } |
| 4399 | } |
| 4400 | } |
Sudheer Shanka | 43b5ea4 | 2017-06-21 11:24:53 -0700 | [diff] [blame] | 4401 | checkAndBlockForNetworkAccess(); |
Andrii Kulian | e55b009 | 2018-04-19 15:29:22 -0700 | [diff] [blame] | 4402 | deliverResults(r, results, reason); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4403 | if (resumed) { |
Andrii Kulian | e55b009 | 2018-04-19 15:29:22 -0700 | [diff] [blame] | 4404 | r.activity.performResume(false, reason); |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 4405 | r.activity.mTemporaryPause = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4406 | } |
| 4407 | } |
| 4408 | } |
| 4409 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4410 | /** Core implementation of activity destroy call. */ |
| 4411 | ActivityClientRecord performDestroyActivity(IBinder token, boolean finishing, |
Bryce Lee | a33c13d | 2018-02-08 14:37:06 -0800 | [diff] [blame] | 4412 | int configChanges, boolean getNonConfigInstance, String reason) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4413 | ActivityClientRecord r = mActivities.get(token); |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4414 | Class<? extends Activity> activityClass = null; |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4415 | if (localLOGV) Slog.v(TAG, "Performing finish of " + r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4416 | if (r != null) { |
Brad Fitzpatrick | 5f8b5c1 | 2011-01-20 15:12:08 -0800 | [diff] [blame] | 4417 | activityClass = r.activity.getClass(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4418 | r.activity.mConfigChangeFlags |= configChanges; |
| 4419 | if (finishing) { |
| 4420 | r.activity.mFinished = true; |
| 4421 | } |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 4422 | |
| 4423 | performPauseActivityIfNeeded(r, "destroy"); |
| 4424 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4425 | if (!r.stopped) { |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 4426 | callActivityOnStop(r, false /* saveState */, "destroy"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4427 | } |
| 4428 | if (getNonConfigInstance) { |
| 4429 | try { |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 4430 | r.lastNonConfigurationInstances |
| 4431 | = r.activity.retainNonConfigurationInstances(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4432 | } catch (Exception e) { |
| 4433 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4434 | throw new RuntimeException( |
| 4435 | "Unable to retain activity " |
| 4436 | + r.intent.getComponent().toShortString() |
| 4437 | + ": " + e.toString(), e); |
| 4438 | } |
| 4439 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4440 | } |
| 4441 | try { |
| 4442 | r.activity.mCalled = false; |
Dianne Hackborn | 2dedce6 | 2010-04-15 14:45:25 -0700 | [diff] [blame] | 4443 | mInstrumentation.callActivityOnDestroy(r.activity); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4444 | if (!r.activity.mCalled) { |
| 4445 | throw new SuperNotCalledException( |
Mitsuru Oshima | d9aef73 | 2009-06-16 20:20:50 -0700 | [diff] [blame] | 4446 | "Activity " + safeToComponentShortString(r.intent) + |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4447 | " did not call through to super.onDestroy()"); |
| 4448 | } |
| 4449 | if (r.window != null) { |
| 4450 | r.window.closeAllPanels(); |
| 4451 | } |
| 4452 | } catch (SuperNotCalledException e) { |
| 4453 | throw e; |
| 4454 | } catch (Exception e) { |
| 4455 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4456 | throw new RuntimeException( |
Mitsuru Oshima | d9aef73 | 2009-06-16 20:20:50 -0700 | [diff] [blame] | 4457 | "Unable to destroy activity " + safeToComponentShortString(r.intent) |
| 4458 | + ": " + e.toString(), e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4459 | } |
| 4460 | } |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4461 | r.setState(ON_DESTROY); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4462 | } |
| 4463 | mActivities.remove(token); |
Brad Fitzpatrick | 5f8b5c1 | 2011-01-20 15:12:08 -0800 | [diff] [blame] | 4464 | StrictMode.decrementExpectedActivityCount(activityClass); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4465 | return r; |
| 4466 | } |
| 4467 | |
Mitsuru Oshima | d9aef73 | 2009-06-16 20:20:50 -0700 | [diff] [blame] | 4468 | private static String safeToComponentShortString(Intent intent) { |
| 4469 | ComponentName component = intent.getComponent(); |
| 4470 | return component == null ? "[Unknown]" : component.toShortString(); |
| 4471 | } |
| 4472 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 4473 | @Override |
| 4474 | public void handleDestroyActivity(IBinder token, boolean finishing, int configChanges, |
Bryce Lee | a33c13d | 2018-02-08 14:37:06 -0800 | [diff] [blame] | 4475 | boolean getNonConfigInstance, String reason) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4476 | ActivityClientRecord r = performDestroyActivity(token, finishing, |
Bryce Lee | a33c13d | 2018-02-08 14:37:06 -0800 | [diff] [blame] | 4477 | configChanges, getNonConfigInstance, reason); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4478 | if (r != null) { |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4479 | cleanUpPendingRemoveWindows(r, finishing); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4480 | WindowManager wm = r.activity.getWindowManager(); |
| 4481 | View v = r.activity.mDecor; |
| 4482 | if (v != null) { |
| 4483 | if (r.activity.mVisibleFromServer) { |
| 4484 | mNumVisibleActivities--; |
| 4485 | } |
| 4486 | IBinder wtoken = v.getWindowToken(); |
| 4487 | if (r.activity.mWindowAdded) { |
Robert Carr | 77bdfb5 | 2016-05-02 18:18:31 -0700 | [diff] [blame] | 4488 | if (r.mPreserveWindow) { |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4489 | // Hold off on removing this until the new activity's |
| 4490 | // window is being added. |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4491 | r.mPendingRemoveWindow = r.window; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4492 | r.mPendingRemoveWindowManager = wm; |
Andrii Kulian | eac0ea5 | 2016-05-11 15:50:24 -0700 | [diff] [blame] | 4493 | // We can only keep the part of the view hierarchy that we control, |
| 4494 | // everything else must be removed, because it might not be able to |
| 4495 | // behave properly when activity is relaunching. |
| 4496 | r.window.clearContentView(); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4497 | } else { |
| 4498 | wm.removeViewImmediate(v); |
| 4499 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4500 | } |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4501 | if (wtoken != null && r.mPendingRemoveWindow == null) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 4502 | WindowManagerGlobal.getInstance().closeAll(wtoken, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4503 | r.activity.getClass().getName(), "Activity"); |
Andrii Kulian | eac0ea5 | 2016-05-11 15:50:24 -0700 | [diff] [blame] | 4504 | } else if (r.mPendingRemoveWindow != null) { |
| 4505 | // We're preserving only one window, others should be closed so app views |
| 4506 | // will be detached before the final tear down. It should be done now because |
| 4507 | // some components (e.g. WebView) rely on detach callbacks to perform receiver |
| 4508 | // unregister and other cleanup. |
| 4509 | WindowManagerGlobal.getInstance().closeAllExceptView(token, v, |
| 4510 | r.activity.getClass().getName(), "Activity"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4511 | } |
| 4512 | r.activity.mDecor = null; |
| 4513 | } |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4514 | if (r.mPendingRemoveWindow == null) { |
| 4515 | // If we are delaying the removal of the activity window, then |
| 4516 | // we can't clean up all windows here. Note that we can't do |
| 4517 | // so later either, which means any windows that aren't closed |
| 4518 | // by the app will leak. Well we try to warning them a lot |
| 4519 | // about leaking windows, because that is a bug, so if they are |
| 4520 | // using this recreate facility then they get to live with leaks. |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 4521 | WindowManagerGlobal.getInstance().closeAll(token, |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4522 | r.activity.getClass().getName(), "Activity"); |
| 4523 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4524 | |
| 4525 | // Mocked out contexts won't be participating in the normal |
| 4526 | // process lifecycle, but if we're running with a proper |
| 4527 | // ApplicationContext we need to have it tear down things |
| 4528 | // cleanly. |
| 4529 | Context c = r.activity.getBaseContext(); |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 4530 | if (c instanceof ContextImpl) { |
| 4531 | ((ContextImpl) c).scheduleFinalCleanup( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4532 | r.activity.getClass().getName(), "Activity"); |
| 4533 | } |
| 4534 | } |
| 4535 | if (finishing) { |
| 4536 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 4537 | ActivityManager.getService().activityDestroyed(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4538 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4539 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4540 | } |
| 4541 | } |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4542 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4543 | } |
| 4544 | |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 4545 | @Override |
| 4546 | public ActivityClientRecord prepareRelaunchActivity(IBinder token, |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 4547 | List<ResultInfo> pendingResults, List<ReferrerIntent> pendingNewIntents, |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 4548 | int configChanges, MergedConfiguration config, boolean preserveWindow) { |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4549 | ActivityClientRecord target = null; |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 4550 | boolean scheduleRelaunch = false; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4551 | |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4552 | synchronized (mResourcesManager) { |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4553 | for (int i=0; i<mRelaunchingActivities.size(); i++) { |
| 4554 | ActivityClientRecord r = mRelaunchingActivities.get(i); |
Filip Gruszczynski | c3b6179 | 2016-01-22 16:43:48 -0800 | [diff] [blame] | 4555 | if (DEBUG_ORDER) Slog.d(TAG, "requestRelaunchActivity: " + this + ", trying: " + r); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4556 | if (r.token == token) { |
| 4557 | target = r; |
| 4558 | if (pendingResults != null) { |
| 4559 | if (r.pendingResults != null) { |
| 4560 | r.pendingResults.addAll(pendingResults); |
| 4561 | } else { |
| 4562 | r.pendingResults = pendingResults; |
| 4563 | } |
| 4564 | } |
| 4565 | if (pendingNewIntents != null) { |
| 4566 | if (r.pendingIntents != null) { |
| 4567 | r.pendingIntents.addAll(pendingNewIntents); |
| 4568 | } else { |
| 4569 | r.pendingIntents = pendingNewIntents; |
| 4570 | } |
| 4571 | } |
| 4572 | break; |
| 4573 | } |
| 4574 | } |
| 4575 | |
| 4576 | if (target == null) { |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 4577 | if (DEBUG_ORDER) Slog.d(TAG, "requestRelaunchActivity: target is null"); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4578 | target = new ActivityClientRecord(); |
| 4579 | target.token = token; |
| 4580 | target.pendingResults = pendingResults; |
| 4581 | target.pendingIntents = pendingNewIntents; |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4582 | target.mPreserveWindow = preserveWindow; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4583 | mRelaunchingActivities.add(target); |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 4584 | scheduleRelaunch = true; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4585 | } |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 4586 | target.createdConfig = config.getGlobalConfiguration(); |
| 4587 | target.overrideConfig = config.getOverrideConfiguration(); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4588 | target.pendingConfigChanges |= configChanges; |
| 4589 | } |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 4590 | |
| 4591 | return scheduleRelaunch ? target : null; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4592 | } |
| 4593 | |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 4594 | @Override |
| 4595 | public void handleRelaunchActivity(ActivityClientRecord tmp, |
| 4596 | PendingTransactionActions pendingActions) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4597 | // If we are getting ready to gc after going to the background, well |
| 4598 | // we are back active so skip it. |
| 4599 | unscheduleGcIdler(); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4600 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4601 | |
| 4602 | Configuration changedConfig = null; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4603 | int configChanges = 0; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4604 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4605 | // First: make sure we have the most recent configuration and most |
| 4606 | // recent version of the activity, or skip it if some previous call |
| 4607 | // had taken a more recent version. |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4608 | synchronized (mResourcesManager) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4609 | int N = mRelaunchingActivities.size(); |
| 4610 | IBinder token = tmp.token; |
| 4611 | tmp = null; |
| 4612 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4613 | ActivityClientRecord r = mRelaunchingActivities.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4614 | if (r.token == token) { |
| 4615 | tmp = r; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4616 | configChanges |= tmp.pendingConfigChanges; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4617 | mRelaunchingActivities.remove(i); |
| 4618 | i--; |
| 4619 | N--; |
| 4620 | } |
| 4621 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4622 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4623 | if (tmp == null) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4624 | 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] | 4625 | return; |
| 4626 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4627 | |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4628 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Relaunching activity " |
| 4629 | + tmp.token + " with configChanges=0x" |
| 4630 | + Integer.toHexString(configChanges)); |
| 4631 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4632 | if (mPendingConfiguration != null) { |
| 4633 | changedConfig = mPendingConfiguration; |
| 4634 | mPendingConfiguration = null; |
| 4635 | } |
| 4636 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4637 | |
Dianne Hackborn | 871ecdc | 2009-12-11 15:24:33 -0800 | [diff] [blame] | 4638 | if (tmp.createdConfig != null) { |
| 4639 | // If the activity manager is passing us its current config, |
| 4640 | // assume that is really what we want regardless of what we |
| 4641 | // may have pending. |
| 4642 | if (mConfiguration == null |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4643 | || (tmp.createdConfig.isOtherSeqNewer(mConfiguration) |
| 4644 | && mConfiguration.diff(tmp.createdConfig) != 0)) { |
| 4645 | if (changedConfig == null |
| 4646 | || tmp.createdConfig.isOtherSeqNewer(changedConfig)) { |
| 4647 | changedConfig = tmp.createdConfig; |
| 4648 | } |
Dianne Hackborn | 871ecdc | 2009-12-11 15:24:33 -0800 | [diff] [blame] | 4649 | } |
| 4650 | } |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 4651 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4652 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Relaunching activity " |
Dianne Hackborn | dc6b635 | 2009-09-30 14:20:09 -0700 | [diff] [blame] | 4653 | + tmp.token + ": changedConfig=" + changedConfig); |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 4654 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4655 | // If there was a pending configuration change, execute it first. |
| 4656 | if (changedConfig != null) { |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 4657 | mCurDefaultDisplayDpi = changedConfig.densityDpi; |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 4658 | updateDefaultDensity(); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4659 | handleConfigurationChanged(changedConfig, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4660 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4661 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4662 | ActivityClientRecord r = mActivities.get(tmp.token); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4663 | 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] | 4664 | if (r == null) { |
| 4665 | return; |
| 4666 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4667 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4668 | r.activity.mConfigChangeFlags |= configChanges; |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4669 | r.mPreserveWindow = tmp.mPreserveWindow; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4670 | |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4671 | r.activity.mChangingConfigurations = true; |
| 4672 | |
Robert Carr | 23fa16b | 2016-01-13 13:19:58 -0800 | [diff] [blame] | 4673 | // If we are preserving the main window across relaunches we would also like to preserve |
| 4674 | // the children. However the client side view system does not support preserving |
| 4675 | // the child views so we notify the window manager to expect these windows to |
| 4676 | // be replaced and defer requests to destroy or hide them. This way we can achieve |
| 4677 | // visual continuity. It's important that we do this here prior to pause and destroy |
| 4678 | // as that is when we may hide or remove the child views. |
Robert Carr | 77bdfb5 | 2016-05-02 18:18:31 -0700 | [diff] [blame] | 4679 | // |
| 4680 | // There is another scenario, if we have decided locally to relaunch the app from a |
| 4681 | // call to recreate, then none of the windows will be prepared for replacement or |
| 4682 | // preserved by the server, so we want to notify it that we are preparing to replace |
| 4683 | // everything |
Robert Carr | 23fa16b | 2016-01-13 13:19:58 -0800 | [diff] [blame] | 4684 | try { |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 4685 | if (r.mPreserveWindow) { |
Robert Carr | 77bdfb5 | 2016-05-02 18:18:31 -0700 | [diff] [blame] | 4686 | WindowManagerGlobal.getWindowSession().prepareToReplaceWindows( |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 4687 | r.token, true /* childrenOnly */); |
Robert Carr | 23fa16b | 2016-01-13 13:19:58 -0800 | [diff] [blame] | 4688 | } |
| 4689 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4690 | throw e.rethrowFromSystemServer(); |
Robert Carr | 23fa16b | 2016-01-13 13:19:58 -0800 | [diff] [blame] | 4691 | } |
| 4692 | |
Wale Ogunwale | 5527a50 | 2018-02-20 18:18:21 -0800 | [diff] [blame] | 4693 | handleRelaunchActivityInner(r, configChanges, tmp.pendingResults, tmp.pendingIntents, |
| 4694 | pendingActions, tmp.startsNotResumed, tmp.overrideConfig, "handleRelaunchActivity"); |
| 4695 | |
| 4696 | if (pendingActions != null) { |
| 4697 | // Only report a successful relaunch to WindowManager. |
| 4698 | pendingActions.setReportRelaunchToWindowManager(true); |
Dianne Hackborn | e2b0480 | 2010-12-09 09:24:55 -0800 | [diff] [blame] | 4699 | } |
Wale Ogunwale | 5527a50 | 2018-02-20 18:18:21 -0800 | [diff] [blame] | 4700 | } |
| 4701 | |
Andrii Kulian | 320e3b5 | 2018-05-03 16:26:25 -0700 | [diff] [blame] | 4702 | /** |
| 4703 | * Post a message to relaunch the activity. We do this instead of launching it immediately, |
| 4704 | * because this will destroy the activity from which it was called and interfere with the |
| 4705 | * lifecycle changes it was going through before. We need to make sure that we have finished |
| 4706 | * handling current transaction item before relaunching the activity. |
| 4707 | */ |
| 4708 | void scheduleRelaunchActivity(IBinder token) { |
| 4709 | sendMessage(H.RELAUNCH_ACTIVITY, token); |
| 4710 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4711 | |
Andrii Kulian | 320e3b5 | 2018-05-03 16:26:25 -0700 | [diff] [blame] | 4712 | /** Performs the activity relaunch locally vs. requesting from system-server. */ |
| 4713 | private void handleRelaunchActivityLocally(IBinder token) { |
Wale Ogunwale | 5527a50 | 2018-02-20 18:18:21 -0800 | [diff] [blame] | 4714 | final ActivityClientRecord r = mActivities.get(token); |
| 4715 | if (r == null) { |
Andrii Kulian | 320e3b5 | 2018-05-03 16:26:25 -0700 | [diff] [blame] | 4716 | Log.w(TAG, "Activity to relaunch no longer exists"); |
Wale Ogunwale | 5527a50 | 2018-02-20 18:18:21 -0800 | [diff] [blame] | 4717 | return; |
| 4718 | } |
| 4719 | |
| 4720 | final int prevState = r.getLifecycleState(); |
| 4721 | |
Andrii Kulian | 320e3b5 | 2018-05-03 16:26:25 -0700 | [diff] [blame] | 4722 | if (prevState < ON_RESUME || prevState > ON_STOP) { |
| 4723 | Log.w(TAG, "Activity state must be in [ON_RESUME..ON_STOP] in order to be relaunched," |
| 4724 | + "current state is " + prevState); |
Wale Ogunwale | 5527a50 | 2018-02-20 18:18:21 -0800 | [diff] [blame] | 4725 | return; |
| 4726 | } |
| 4727 | |
Wale Ogunwale | 5527a50 | 2018-02-20 18:18:21 -0800 | [diff] [blame] | 4728 | |
Andrii Kulian | 914aa7d | 2018-03-19 21:51:53 -0700 | [diff] [blame] | 4729 | // Initialize a relaunch request. |
| 4730 | final MergedConfiguration mergedConfiguration = new MergedConfiguration( |
| 4731 | r.createdConfig != null ? r.createdConfig : mConfiguration, |
| 4732 | r.overrideConfig); |
| 4733 | final ActivityRelaunchItem activityRelaunchItem = ActivityRelaunchItem.obtain( |
| 4734 | null /* pendingResults */, null /* pendingIntents */, 0 /* configChanges */, |
| 4735 | mergedConfiguration, r.mPreserveWindow); |
| 4736 | // Make sure to match the existing lifecycle state in the end of the transaction. |
| 4737 | final ActivityLifecycleItem lifecycleRequest = |
| 4738 | TransactionExecutorHelper.getLifecycleRequestForCurrentState(r); |
| 4739 | // Schedule the transaction. |
| 4740 | final ClientTransaction transaction = ClientTransaction.obtain(this.mAppThread, r.token); |
| 4741 | transaction.addCallback(activityRelaunchItem); |
| 4742 | transaction.setLifecycleStateRequest(lifecycleRequest); |
| 4743 | executeTransaction(transaction); |
Wale Ogunwale | 5527a50 | 2018-02-20 18:18:21 -0800 | [diff] [blame] | 4744 | } |
| 4745 | |
| 4746 | private void handleRelaunchActivityInner(ActivityClientRecord r, int configChanges, |
| 4747 | List<ResultInfo> pendingResults, List<ReferrerIntent> pendingIntents, |
| 4748 | PendingTransactionActions pendingActions, boolean startsNotResumed, |
| 4749 | Configuration overrideConfig, String reason) { |
Andrii Kulian | 770c403 | 2018-05-02 18:40:59 -0700 | [diff] [blame] | 4750 | // Preserve last used intent, it may be set from Activity#setIntent(). |
| 4751 | final Intent customIntent = r.activity.mIntent; |
Wale Ogunwale | 5527a50 | 2018-02-20 18:18:21 -0800 | [diff] [blame] | 4752 | // Need to ensure state is saved. |
| 4753 | if (!r.paused) { |
| 4754 | performPauseActivity(r, false, reason, null /* pendingActions */); |
| 4755 | } |
| 4756 | if (!r.stopped) { |
| 4757 | callActivityOnStop(r, true /* saveState */, reason); |
| 4758 | } |
| 4759 | |
| 4760 | handleDestroyActivity(r.token, false, configChanges, true, reason); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4761 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4762 | r.activity = null; |
| 4763 | r.window = null; |
| 4764 | r.hideForNow = false; |
| 4765 | r.nextIdle = null; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4766 | // Merge any pending results and pending intents; don't just replace them |
Wale Ogunwale | 5527a50 | 2018-02-20 18:18:21 -0800 | [diff] [blame] | 4767 | if (pendingResults != null) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4768 | if (r.pendingResults == null) { |
Wale Ogunwale | 5527a50 | 2018-02-20 18:18:21 -0800 | [diff] [blame] | 4769 | r.pendingResults = pendingResults; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4770 | } else { |
Wale Ogunwale | 5527a50 | 2018-02-20 18:18:21 -0800 | [diff] [blame] | 4771 | r.pendingResults.addAll(pendingResults); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4772 | } |
| 4773 | } |
Wale Ogunwale | 5527a50 | 2018-02-20 18:18:21 -0800 | [diff] [blame] | 4774 | if (pendingIntents != null) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4775 | if (r.pendingIntents == null) { |
Wale Ogunwale | 5527a50 | 2018-02-20 18:18:21 -0800 | [diff] [blame] | 4776 | r.pendingIntents = pendingIntents; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4777 | } else { |
Wale Ogunwale | 5527a50 | 2018-02-20 18:18:21 -0800 | [diff] [blame] | 4778 | r.pendingIntents.addAll(pendingIntents); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4779 | } |
| 4780 | } |
Wale Ogunwale | 5527a50 | 2018-02-20 18:18:21 -0800 | [diff] [blame] | 4781 | r.startsNotResumed = startsNotResumed; |
| 4782 | r.overrideConfig = overrideConfig; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4783 | |
Andrii Kulian | 770c403 | 2018-05-02 18:40:59 -0700 | [diff] [blame] | 4784 | handleLaunchActivity(r, pendingActions, customIntent); |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 4785 | } |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4786 | |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 4787 | @Override |
| 4788 | public void reportRelaunch(IBinder token, PendingTransactionActions pendingActions) { |
| 4789 | try { |
| 4790 | ActivityManager.getService().activityRelaunched(token); |
| 4791 | final ActivityClientRecord r = mActivities.get(token); |
| 4792 | if (pendingActions.shouldReportRelaunchToWindowManager() && r != null |
| 4793 | && r.window != null) { |
| 4794 | r.window.reportActivityRelaunched(); |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4795 | } |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 4796 | } catch (RemoteException e) { |
| 4797 | throw e.rethrowFromSystemServer(); |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4798 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4799 | } |
| 4800 | |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 4801 | private void callActivityOnSaveInstanceState(ActivityClientRecord r) { |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 4802 | r.state = new Bundle(); |
| 4803 | r.state.setAllowFds(false); |
| 4804 | if (r.isPersistable()) { |
| 4805 | r.persistentState = new PersistableBundle(); |
| 4806 | mInstrumentation.callActivityOnSaveInstanceState(r.activity, r.state, |
| 4807 | r.persistentState); |
| 4808 | } else { |
| 4809 | mInstrumentation.callActivityOnSaveInstanceState(r.activity, r.state); |
| 4810 | } |
| 4811 | } |
| 4812 | |
Dianne Hackborn | 73c1416 | 2012-09-19 15:45:06 -0700 | [diff] [blame] | 4813 | ArrayList<ComponentCallbacks2> collectComponentCallbacks( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4814 | boolean allActivities, Configuration newConfig) { |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 4815 | ArrayList<ComponentCallbacks2> callbacks |
| 4816 | = new ArrayList<ComponentCallbacks2>(); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4817 | |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4818 | synchronized (mResourcesManager) { |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 4819 | final int NAPP = mAllApplications.size(); |
| 4820 | for (int i=0; i<NAPP; i++) { |
Dianne Hackborn | 73c1416 | 2012-09-19 15:45:06 -0700 | [diff] [blame] | 4821 | callbacks.add(mAllApplications.get(i)); |
| 4822 | } |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 4823 | final int NACT = mActivities.size(); |
| 4824 | for (int i=0; i<NACT; i++) { |
| 4825 | ActivityClientRecord ar = mActivities.valueAt(i); |
| 4826 | Activity a = ar.activity; |
| 4827 | if (a != null) { |
| 4828 | Configuration thisConfig = applyConfigCompatMainThread( |
| 4829 | mCurDefaultDisplayDpi, newConfig, |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 4830 | ar.packageInfo.getCompatibilityInfo()); |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 4831 | if (!ar.activity.mFinished && (allActivities || !ar.paused)) { |
| 4832 | // If the activity is currently resumed, its configuration |
| 4833 | // needs to change right now. |
| 4834 | callbacks.add(a); |
| 4835 | } else if (thisConfig != null) { |
| 4836 | // Otherwise, we will tell it about the change |
| 4837 | // the next time it is resumed or shown. Note that |
| 4838 | // the activity manager may, before then, decide the |
| 4839 | // activity needs to be destroyed to handle its new |
| 4840 | // configuration. |
| 4841 | if (DEBUG_CONFIGURATION) { |
| 4842 | Slog.v(TAG, "Setting activity " |
| 4843 | + ar.activityInfo.name + " newConfig=" + thisConfig); |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 4844 | } |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 4845 | ar.newConfig = thisConfig; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4846 | } |
| 4847 | } |
| 4848 | } |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 4849 | final int NSVC = mServices.size(); |
| 4850 | for (int i=0; i<NSVC; i++) { |
| 4851 | callbacks.add(mServices.valueAt(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4852 | } |
| 4853 | } |
| 4854 | synchronized (mProviderMap) { |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 4855 | final int NPRV = mLocalProviders.size(); |
| 4856 | for (int i=0; i<NPRV; i++) { |
| 4857 | callbacks.add(mLocalProviders.valueAt(i).mLocalProvider); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4858 | } |
| 4859 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4860 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4861 | return callbacks; |
| 4862 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4863 | |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 4864 | /** |
| 4865 | * Updates the configuration for an Activity. The ActivityClientRecord's |
| 4866 | * {@link ActivityClientRecord#overrideConfig} is used to compute the final Configuration for |
| 4867 | * that Activity. {@link ActivityClientRecord#tmpConfig} is used as a temporary for delivering |
| 4868 | * the updated Configuration. |
| 4869 | * @param r ActivityClientRecord representing the Activity. |
| 4870 | * @param newBaseConfig The new configuration to use. This may be augmented with |
| 4871 | * {@link ActivityClientRecord#overrideConfig}. |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 4872 | */ |
| 4873 | private void performConfigurationChangedForActivity(ActivityClientRecord r, |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4874 | Configuration newBaseConfig) { |
| 4875 | performConfigurationChangedForActivity(r, newBaseConfig, |
| 4876 | r.activity.getDisplay().getDisplayId(), false /* movedToDifferentDisplay */); |
| 4877 | } |
| 4878 | |
| 4879 | /** |
| 4880 | * Updates the configuration for an Activity. The ActivityClientRecord's |
| 4881 | * {@link ActivityClientRecord#overrideConfig} is used to compute the final Configuration for |
| 4882 | * that Activity. {@link ActivityClientRecord#tmpConfig} is used as a temporary for delivering |
| 4883 | * the updated Configuration. |
| 4884 | * @param r ActivityClientRecord representing the Activity. |
| 4885 | * @param newBaseConfig The new configuration to use. This may be augmented with |
| 4886 | * {@link ActivityClientRecord#overrideConfig}. |
| 4887 | * @param displayId The id of the display where the Activity currently resides. |
| 4888 | * @param movedToDifferentDisplay Indicates if the activity was moved to different display. |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 4889 | * @return {@link Configuration} instance sent to client, null if not sent. |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4890 | */ |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 4891 | private Configuration performConfigurationChangedForActivity(ActivityClientRecord r, |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4892 | Configuration newBaseConfig, int displayId, boolean movedToDifferentDisplay) { |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 4893 | r.tmpConfig.setTo(newBaseConfig); |
| 4894 | if (r.overrideConfig != null) { |
| 4895 | r.tmpConfig.updateFrom(r.overrideConfig); |
| 4896 | } |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 4897 | final Configuration reportedConfig = performActivityConfigurationChanged(r.activity, |
| 4898 | r.tmpConfig, r.overrideConfig, displayId, movedToDifferentDisplay); |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 4899 | freeTextLayoutCachesIfNeeded(r.activity.mCurrentConfig.diff(r.tmpConfig)); |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 4900 | return reportedConfig; |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 4901 | } |
| 4902 | |
| 4903 | /** |
Adam Lesinski | c1b0ebf | 2016-06-09 11:17:10 -0700 | [diff] [blame] | 4904 | * Creates a new Configuration only if override would modify base. Otherwise returns base. |
| 4905 | * @param base The base configuration. |
| 4906 | * @param override The update to apply to the base configuration. Can be null. |
| 4907 | * @return A Configuration representing base with override applied. |
| 4908 | */ |
| 4909 | private static Configuration createNewConfigAndUpdateIfNotNull(@NonNull Configuration base, |
| 4910 | @Nullable Configuration override) { |
| 4911 | if (override == null) { |
| 4912 | return base; |
| 4913 | } |
| 4914 | Configuration newConfig = new Configuration(base); |
| 4915 | newConfig.updateFrom(override); |
| 4916 | return newConfig; |
| 4917 | } |
| 4918 | |
| 4919 | /** |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4920 | * 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] | 4921 | * @param cb The component callback to notify of configuration change. |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4922 | * @param newConfig The new configuration. |
| 4923 | */ |
| 4924 | private void performConfigurationChanged(ComponentCallbacks2 cb, Configuration newConfig) { |
| 4925 | if (!REPORT_TO_ACTIVITY) { |
| 4926 | return; |
| 4927 | } |
| 4928 | |
| 4929 | // ContextThemeWrappers may override the configuration for that context. We must check and |
| 4930 | // apply any overrides defined. |
| 4931 | Configuration contextThemeWrapperOverrideConfig = null; |
| 4932 | if (cb instanceof ContextThemeWrapper) { |
| 4933 | final ContextThemeWrapper contextThemeWrapper = (ContextThemeWrapper) cb; |
| 4934 | contextThemeWrapperOverrideConfig = contextThemeWrapper.getOverrideConfiguration(); |
| 4935 | } |
| 4936 | |
| 4937 | // Apply the ContextThemeWrapper override if necessary. |
| 4938 | // NOTE: Make sure the configurations are not modified, as they are treated as immutable |
| 4939 | // in many places. |
| 4940 | final Configuration configToReport = createNewConfigAndUpdateIfNotNull( |
| 4941 | newConfig, contextThemeWrapperOverrideConfig); |
| 4942 | cb.onConfigurationChanged(configToReport); |
| 4943 | } |
| 4944 | |
| 4945 | /** |
| 4946 | * Decides whether to update an Activity's configuration and whether to inform it. |
| 4947 | * @param activity The activity to notify of configuration change. |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 4948 | * @param newConfig The new configuration. |
Adam Lesinski | c1b0ebf | 2016-06-09 11:17:10 -0700 | [diff] [blame] | 4949 | * @param amOverrideConfig The override config that differentiates the Activity's configuration |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4950 | * from the base global configuration. This is supplied by |
| 4951 | * ActivityManager. |
| 4952 | * @param displayId Id of the display where activity currently resides. |
| 4953 | * @param movedToDifferentDisplay Indicates if the activity was moved to different display. |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 4954 | * @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] | 4955 | */ |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 4956 | private Configuration performActivityConfigurationChanged(Activity activity, |
| 4957 | Configuration newConfig, Configuration amOverrideConfig, int displayId, |
| 4958 | boolean movedToDifferentDisplay) { |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4959 | if (activity == null) { |
| 4960 | throw new IllegalArgumentException("No activity provided."); |
| 4961 | } |
| 4962 | final IBinder activityToken = activity.getActivityToken(); |
| 4963 | if (activityToken == null) { |
| 4964 | 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] | 4965 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4966 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4967 | boolean shouldChangeConfig = false; |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4968 | if (activity.mCurrentConfig == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4969 | shouldChangeConfig = true; |
| 4970 | } else { |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4971 | // If the new config is the same as the config this Activity is already running with and |
| 4972 | // the override config also didn't change, then don't bother calling |
| 4973 | // onConfigurationChanged. |
Bryce Lee | 658d984 | 2017-07-28 08:33:36 -0700 | [diff] [blame] | 4974 | final int diff = activity.mCurrentConfig.diffPublicOnly(newConfig); |
| 4975 | |
Andrii Kulian | 3b3c914 | 2016-07-18 19:15:56 -0700 | [diff] [blame] | 4976 | if (diff != 0 || !mResourcesManager.isSameResourcesOverrideConfig(activityToken, |
| 4977 | amOverrideConfig)) { |
Chong Zhang | 4951f9d | 2016-06-23 13:15:08 -0700 | [diff] [blame] | 4978 | // Always send the task-level config changes. For system-level configuration, if |
| 4979 | // this activity doesn't handle any of the config changes, then don't bother |
| 4980 | // calling onConfigurationChanged as we're going to destroy it. |
| 4981 | if (!mUpdatingSystemConfig |
| 4982 | || (~activity.mActivityInfo.getRealConfigChanged() & diff) == 0 |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4983 | || !REPORT_TO_ACTIVITY) { |
Chong Zhang | 4951f9d | 2016-06-23 13:15:08 -0700 | [diff] [blame] | 4984 | shouldChangeConfig = true; |
| 4985 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4986 | } |
| 4987 | } |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4988 | if (!shouldChangeConfig && !movedToDifferentDisplay) { |
| 4989 | // Nothing significant, don't proceed with updating and reporting. |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 4990 | return null; |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4991 | } |
| 4992 | |
| 4993 | // Propagate the configuration change to ResourcesManager and Activity. |
| 4994 | |
| 4995 | // ContextThemeWrappers may override the configuration for that context. We must check and |
| 4996 | // apply any overrides defined. |
| 4997 | Configuration contextThemeWrapperOverrideConfig = activity.getOverrideConfiguration(); |
| 4998 | |
| 4999 | // We only update an Activity's configuration if this is not a global configuration change. |
| 5000 | // This must also be done before the callback, or else we violate the contract that the new |
| 5001 | // resources are available in ComponentCallbacks2#onConfigurationChanged(Configuration). |
| 5002 | // Also apply the ContextThemeWrapper override if necessary. |
| 5003 | // NOTE: Make sure the configurations are not modified, as they are treated as immutable in |
| 5004 | // many places. |
| 5005 | final Configuration finalOverrideConfig = createNewConfigAndUpdateIfNotNull( |
| 5006 | amOverrideConfig, contextThemeWrapperOverrideConfig); |
| 5007 | mResourcesManager.updateResourcesForActivity(activityToken, finalOverrideConfig, |
| 5008 | displayId, movedToDifferentDisplay); |
| 5009 | |
| 5010 | activity.mConfigChangeFlags = 0; |
| 5011 | activity.mCurrentConfig = new Configuration(newConfig); |
| 5012 | |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 5013 | // Apply the ContextThemeWrapper override if necessary. |
| 5014 | // NOTE: Make sure the configurations are not modified, as they are treated as immutable |
| 5015 | // in many places. |
| 5016 | final Configuration configToReport = createNewConfigAndUpdateIfNotNull(newConfig, |
| 5017 | contextThemeWrapperOverrideConfig); |
| 5018 | |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5019 | if (!REPORT_TO_ACTIVITY) { |
| 5020 | // Not configured to report to activity. |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 5021 | return configToReport; |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5022 | } |
| 5023 | |
| 5024 | if (movedToDifferentDisplay) { |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 5025 | activity.dispatchMovedToDisplay(displayId, configToReport); |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5026 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 5027 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5028 | if (shouldChangeConfig) { |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5029 | activity.mCalled = false; |
| 5030 | activity.onConfigurationChanged(configToReport); |
| 5031 | if (!activity.mCalled) { |
| 5032 | throw new SuperNotCalledException("Activity " + activity.getLocalClassName() + |
| 5033 | " did not call through to super.onConfigurationChanged()"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5034 | } |
| 5035 | } |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 5036 | |
| 5037 | return configToReport; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5038 | } |
| 5039 | |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 5040 | public final void applyConfigurationToResources(Configuration config) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 5041 | synchronized (mResourcesManager) { |
| 5042 | mResourcesManager.applyConfigurationToResourcesLocked(config, null); |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 5043 | } |
| 5044 | } |
| 5045 | |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 5046 | final Configuration applyCompatConfiguration(int displayDensity) { |
Dianne Hackborn | 836e262 | 2011-10-04 18:32:39 -0700 | [diff] [blame] | 5047 | Configuration config = mConfiguration; |
| 5048 | if (mCompatConfiguration == null) { |
| 5049 | mCompatConfiguration = new Configuration(); |
| 5050 | } |
| 5051 | mCompatConfiguration.setTo(mConfiguration); |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 5052 | if (mResourcesManager.applyCompatConfigurationLocked(displayDensity, |
| 5053 | mCompatConfiguration)) { |
Dianne Hackborn | 836e262 | 2011-10-04 18:32:39 -0700 | [diff] [blame] | 5054 | config = mCompatConfiguration; |
| 5055 | } |
| 5056 | return config; |
| 5057 | } |
| 5058 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 5059 | @Override |
| 5060 | public void handleConfigurationChanged(Configuration config) { |
| 5061 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "configChanged"); |
| 5062 | mCurDefaultDisplayDpi = config.densityDpi; |
| 5063 | mUpdatingSystemConfig = true; |
| 5064 | try { |
| 5065 | handleConfigurationChanged(config, null /* compat */); |
| 5066 | } finally { |
| 5067 | mUpdatingSystemConfig = false; |
| 5068 | } |
| 5069 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
| 5070 | } |
| 5071 | |
| 5072 | private void handleConfigurationChanged(Configuration config, CompatibilityInfo compat) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5073 | |
Fabrice Di Meglio | 30ca5cd | 2012-05-07 17:45:44 -0700 | [diff] [blame] | 5074 | int configDiff = 0; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5075 | |
Bryce Lee | 658d984 | 2017-07-28 08:33:36 -0700 | [diff] [blame] | 5076 | // This flag tracks whether the new configuration is fundamentally equivalent to the |
| 5077 | // existing configuration. This is necessary to determine whether non-activity |
| 5078 | // callbacks should receive notice when the only changes are related to non-public fields. |
| 5079 | // We do not gate calling {@link #performActivityConfigurationChanged} based on this flag |
| 5080 | // as that method uses the same check on the activity config override as well. |
| 5081 | final boolean equivalent = config != null && mConfiguration != null |
| 5082 | && (0 == mConfiguration.diffPublicOnly(config)); |
Todd Kennedy | 35a9a38 | 2018-01-25 13:25:37 -0800 | [diff] [blame] | 5083 | final Theme systemTheme = getSystemContext().getTheme(); |
| 5084 | final Theme systemUiTheme = getSystemUiContext().getTheme(); |
Bryce Lee | 658d984 | 2017-07-28 08:33:36 -0700 | [diff] [blame] | 5085 | |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 5086 | synchronized (mResourcesManager) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5087 | if (mPendingConfiguration != null) { |
| 5088 | if (!mPendingConfiguration.isOtherSeqNewer(config)) { |
| 5089 | config = mPendingConfiguration; |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 5090 | mCurDefaultDisplayDpi = config.densityDpi; |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 5091 | updateDefaultDensity(); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5092 | } |
| 5093 | mPendingConfiguration = null; |
| 5094 | } |
| 5095 | |
| 5096 | if (config == null) { |
| 5097 | return; |
| 5098 | } |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 5099 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 5100 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Handle configuration changed: " |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5101 | + config); |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 5102 | |
| 5103 | mResourcesManager.applyConfigurationToResourcesLocked(config, compat); |
Adam Lesinski | b61e405 | 2016-05-19 18:23:05 -0700 | [diff] [blame] | 5104 | updateLocaleListFromAppContext(mInitialApplication.getApplicationContext(), |
| 5105 | mResourcesManager.getConfiguration().getLocales()); |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 5106 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5107 | if (mConfiguration == null) { |
| 5108 | mConfiguration = new Configuration(); |
| 5109 | } |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 5110 | if (!mConfiguration.isOtherSeqNewer(config) && compat == null) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5111 | return; |
| 5112 | } |
Alan Viverette | e54d245 | 2015-05-06 10:41:43 -0700 | [diff] [blame] | 5113 | |
| 5114 | configDiff = mConfiguration.updateFrom(config); |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 5115 | config = applyCompatConfiguration(mCurDefaultDisplayDpi); |
Alan Viverette | 395cd01 | 2015-08-11 17:27:04 -0400 | [diff] [blame] | 5116 | |
Alan Viverette | 395cd01 | 2015-08-11 17:27:04 -0400 | [diff] [blame] | 5117 | if ((systemTheme.getChangingConfigurations() & configDiff) != 0) { |
| 5118 | systemTheme.rebase(); |
| 5119 | } |
Adam Lesinski | a82b626 | 2017-03-21 16:56:17 -0700 | [diff] [blame] | 5120 | |
Adam Lesinski | a82b626 | 2017-03-21 16:56:17 -0700 | [diff] [blame] | 5121 | if ((systemUiTheme.getChangingConfigurations() & configDiff) != 0) { |
| 5122 | systemUiTheme.rebase(); |
| 5123 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5124 | } |
Dianne Hackborn | 73c1416 | 2012-09-19 15:45:06 -0700 | [diff] [blame] | 5125 | |
| 5126 | ArrayList<ComponentCallbacks2> callbacks = collectComponentCallbacks(false, config); |
| 5127 | |
Fabrice Di Meglio | 30ca5cd | 2012-05-07 17:45:44 -0700 | [diff] [blame] | 5128 | freeTextLayoutCachesIfNeeded(configDiff); |
| 5129 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5130 | if (callbacks != null) { |
| 5131 | final int N = callbacks.size(); |
| 5132 | for (int i=0; i<N; i++) { |
Andrii Kulian | 701214b | 2016-04-07 09:36:33 -0700 | [diff] [blame] | 5133 | ComponentCallbacks2 cb = callbacks.get(i); |
| 5134 | if (cb instanceof Activity) { |
| 5135 | // If callback is an Activity - call corresponding method to consider override |
| 5136 | // config and avoid onConfigurationChanged if it hasn't changed. |
| 5137 | Activity a = (Activity) cb; |
| 5138 | performConfigurationChangedForActivity(mActivities.get(a.getActivityToken()), |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5139 | config); |
Bryce Lee | 658d984 | 2017-07-28 08:33:36 -0700 | [diff] [blame] | 5140 | } else if (!equivalent) { |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5141 | performConfigurationChanged(cb, config); |
Andrii Kulian | 701214b | 2016-04-07 09:36:33 -0700 | [diff] [blame] | 5142 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5143 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5144 | } |
| 5145 | } |
| 5146 | |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 5147 | void handleApplicationInfoChanged(@NonNull final ApplicationInfo ai) { |
Adam Lesinski | d33ef56 | 2017-01-19 14:49:59 -0800 | [diff] [blame] | 5148 | // Updates triggered by package installation go through a package update |
| 5149 | // receiver. Here we try to capture ApplicationInfo changes that are |
| 5150 | // caused by other sources, such as overlays. That means we want to be as conservative |
| 5151 | // about code changes as possible. Take the diff of the old ApplicationInfo and the new |
| 5152 | // to see if anything needs to change. |
Fyodor Kupolov | b7865ce | 2017-05-05 15:08:03 -0700 | [diff] [blame] | 5153 | LoadedApk apk; |
| 5154 | LoadedApk resApk; |
| 5155 | // Update all affected loaded packages with new package information |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 5156 | synchronized (mResourcesManager) { |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 5157 | WeakReference<LoadedApk> ref = mPackages.get(ai.packageName); |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 5158 | apk = ref != null ? ref.get() : null; |
Fyodor Kupolov | b7865ce | 2017-05-05 15:08:03 -0700 | [diff] [blame] | 5159 | ref = mResourcePackages.get(ai.packageName); |
| 5160 | resApk = ref != null ? ref.get() : null; |
| 5161 | } |
| 5162 | if (apk != null) { |
| 5163 | final ArrayList<String> oldPaths = new ArrayList<>(); |
| 5164 | LoadedApk.makePaths(this, apk.getApplicationInfo(), oldPaths); |
| 5165 | apk.updateApplicationInfo(ai, oldPaths); |
| 5166 | } |
| 5167 | if (resApk != null) { |
| 5168 | final ArrayList<String> oldPaths = new ArrayList<>(); |
| 5169 | LoadedApk.makePaths(this, resApk.getApplicationInfo(), oldPaths); |
| 5170 | resApk.updateApplicationInfo(ai, oldPaths); |
| 5171 | } |
| 5172 | synchronized (mResourcesManager) { |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 5173 | // Update all affected Resources objects to use new ResourcesImpl |
| 5174 | mResourcesManager.applyNewResourceDirsLocked(ai.sourceDir, ai.resourceDirs); |
| 5175 | } |
| 5176 | |
| 5177 | ApplicationPackageManager.configurationChanged(); |
| 5178 | |
| 5179 | // Trigger a regular Configuration change event, only with a different assetsSeq number |
| 5180 | // so that we actually call through to all components. |
Adam Lesinski | a82b626 | 2017-03-21 16:56:17 -0700 | [diff] [blame] | 5181 | // TODO(adamlesinski): Change this to make use of ActivityManager's upcoming ability to |
| 5182 | // store configurations per-process. |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 5183 | Configuration newConfig = new Configuration(); |
Adam Lesinski | a82b626 | 2017-03-21 16:56:17 -0700 | [diff] [blame] | 5184 | newConfig.assetsSeq = (mConfiguration != null ? mConfiguration.assetsSeq : 0) + 1; |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 5185 | handleConfigurationChanged(newConfig, null); |
| 5186 | |
Wale Ogunwale | 5527a50 | 2018-02-20 18:18:21 -0800 | [diff] [blame] | 5187 | relaunchAllActivities(); |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 5188 | } |
| 5189 | |
Romain Guy | 46bfc48 | 2013-08-16 18:38:29 -0700 | [diff] [blame] | 5190 | static void freeTextLayoutCachesIfNeeded(int configDiff) { |
Fabrice Di Meglio | 30ca5cd | 2012-05-07 17:45:44 -0700 | [diff] [blame] | 5191 | if (configDiff != 0) { |
| 5192 | // Ask text layout engine to free its caches if there is a locale change |
| 5193 | boolean hasLocaleConfigChange = ((configDiff & ActivityInfo.CONFIG_LOCALE) != 0); |
| 5194 | if (hasLocaleConfigChange) { |
| 5195 | Canvas.freeTextLayoutCaches(); |
| 5196 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Cleared TextLayout Caches"); |
| 5197 | } |
| 5198 | } |
| 5199 | } |
| 5200 | |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5201 | /** |
| 5202 | * Handle new activity configuration and/or move to a different display. |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 5203 | * @param activityToken Target activity token. |
| 5204 | * @param overrideConfig Activity override config. |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5205 | * @param displayId Id of the display where activity was moved to, -1 if there was no move and |
| 5206 | * value didn't change. |
| 5207 | */ |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 5208 | @Override |
| 5209 | public void handleActivityConfigurationChanged(IBinder activityToken, |
| 5210 | Configuration overrideConfig, int displayId) { |
| 5211 | ActivityClientRecord r = mActivities.get(activityToken); |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5212 | // Check input params. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5213 | if (r == null || r.activity == null) { |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5214 | 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] | 5215 | return; |
| 5216 | } |
Andrii Kulian | 51c1b67 | 2017-04-07 18:39:32 -0700 | [diff] [blame] | 5217 | final boolean movedToDifferentDisplay = displayId != INVALID_DISPLAY |
| 5218 | && displayId != r.activity.getDisplay().getDisplayId(); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 5219 | |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5220 | // Perform updates. |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 5221 | r.overrideConfig = overrideConfig; |
Stephen Kiazyk | f903b73 | 2017-03-20 16:23:45 -0700 | [diff] [blame] | 5222 | final ViewRootImpl viewRoot = r.activity.mDecor != null |
| 5223 | ? r.activity.mDecor.getViewRootImpl() : null; |
| 5224 | |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5225 | if (movedToDifferentDisplay) { |
| 5226 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Handle activity moved to display, activity:" |
| 5227 | + r.activityInfo.name + ", displayId=" + displayId |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 5228 | + ", config=" + overrideConfig); |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5229 | |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 5230 | final Configuration reportedConfig = performConfigurationChangedForActivity(r, |
| 5231 | mCompatConfiguration, displayId, true /* movedToDifferentDisplay */); |
Andrii Kulian | ce1ecf1 | 2017-03-17 14:58:36 -0700 | [diff] [blame] | 5232 | if (viewRoot != null) { |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 5233 | viewRoot.onMovedToDisplay(displayId, reportedConfig); |
Andrii Kulian | ce1ecf1 | 2017-03-17 14:58:36 -0700 | [diff] [blame] | 5234 | } |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5235 | } else { |
| 5236 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Handle activity config changed: " |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 5237 | + r.activityInfo.name + ", config=" + overrideConfig); |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5238 | performConfigurationChangedForActivity(r, mCompatConfiguration); |
| 5239 | } |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 5240 | // Notify the ViewRootImpl instance about configuration changes. It may have initiated this |
| 5241 | // update to make sure that resources are updated before updating itself. |
Andrii Kulian | ce1ecf1 | 2017-03-17 14:58:36 -0700 | [diff] [blame] | 5242 | if (viewRoot != null) { |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 5243 | viewRoot.updateConfiguration(displayId); |
Andrii Kulian | ce1ecf1 | 2017-03-17 14:58:36 -0700 | [diff] [blame] | 5244 | } |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 5245 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5246 | } |
| 5247 | |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 5248 | final void handleProfilerControl(boolean start, ProfilerInfo profilerInfo, int profileType) { |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 5249 | if (start) { |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 5250 | try { |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 5251 | switch (profileType) { |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 5252 | default: |
| 5253 | mProfiler.setProfiler(profilerInfo); |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 5254 | mProfiler.startProfiling(); |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 5255 | break; |
| 5256 | } |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 5257 | } catch (RuntimeException e) { |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 5258 | Slog.w(TAG, "Profiling failed on path " + profilerInfo.profileFile |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 5259 | + " -- can the process access this path?"); |
Dianne Hackborn | 9c8dd55 | 2009-06-23 19:22:52 -0700 | [diff] [blame] | 5260 | } finally { |
Andreas Gampe | 2b073a0 | 2017-06-22 17:28:57 -0700 | [diff] [blame] | 5261 | profilerInfo.closeFd(); |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 5262 | } |
| 5263 | } else { |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 5264 | switch (profileType) { |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 5265 | default: |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 5266 | mProfiler.stopProfiling(); |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 5267 | break; |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 5268 | } |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 5269 | } |
| 5270 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 5271 | |
Andreas Gampe | 4c79fea | 2016-01-28 20:11:41 -0800 | [diff] [blame] | 5272 | /** |
| 5273 | * Public entrypoint to stop profiling. This is required to end profiling when the app crashes, |
| 5274 | * so that profiler data won't be lost. |
| 5275 | * |
| 5276 | * @hide |
| 5277 | */ |
| 5278 | public void stopProfiling() { |
Amith Yamasani | b168443 | 2017-01-26 14:57:20 -0800 | [diff] [blame] | 5279 | if (mProfiler != null) { |
| 5280 | mProfiler.stopProfiling(); |
| 5281 | } |
Andreas Gampe | 4c79fea | 2016-01-28 20:11:41 -0800 | [diff] [blame] | 5282 | } |
| 5283 | |
Christopher Ferris | 8d652f8 | 2017-04-11 16:29:18 -0700 | [diff] [blame] | 5284 | static void handleDumpHeap(DumpHeapData dhd) { |
Makoto Onuki | 4556b7b | 2017-07-07 14:58:58 -0700 | [diff] [blame] | 5285 | if (dhd.runGc) { |
| 5286 | System.gc(); |
| 5287 | System.runFinalization(); |
| 5288 | System.gc(); |
| 5289 | } |
Christopher Ferris | 8d652f8 | 2017-04-11 16:29:18 -0700 | [diff] [blame] | 5290 | if (dhd.managed) { |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 5291 | try { |
| 5292 | Debug.dumpHprofData(dhd.path, dhd.fd.getFileDescriptor()); |
| 5293 | } catch (IOException e) { |
| 5294 | Slog.w(TAG, "Managed heap dump failed on path " + dhd.path |
| 5295 | + " -- can the process access this path?"); |
| 5296 | } finally { |
| 5297 | try { |
| 5298 | dhd.fd.close(); |
| 5299 | } catch (IOException e) { |
| 5300 | Slog.w(TAG, "Failure closing profile fd", e); |
| 5301 | } |
| 5302 | } |
Christopher Ferris | 8d652f8 | 2017-04-11 16:29:18 -0700 | [diff] [blame] | 5303 | } else if (dhd.mallocInfo) { |
| 5304 | Debug.dumpNativeMallocInfo(dhd.fd.getFileDescriptor()); |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 5305 | } else { |
Andy McFadden | 06a6b55 | 2010-07-13 16:28:09 -0700 | [diff] [blame] | 5306 | Debug.dumpNativeHeap(dhd.fd.getFileDescriptor()); |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 5307 | } |
Dianne Hackborn | b9a5e4a | 2015-03-03 17:04:12 -0800 | [diff] [blame] | 5308 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5309 | ActivityManager.getService().dumpHeapFinished(dhd.path); |
Dianne Hackborn | b9a5e4a | 2015-03-03 17:04:12 -0800 | [diff] [blame] | 5310 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5311 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | b9a5e4a | 2015-03-03 17:04:12 -0800 | [diff] [blame] | 5312 | } |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 5313 | } |
| 5314 | |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 5315 | final void handleDispatchPackageBroadcast(int cmd, String[] packages) { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5316 | boolean hasPkgInfo = false; |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5317 | switch (cmd) { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 5318 | case ApplicationThreadConstants.PACKAGE_REMOVED: |
| 5319 | case ApplicationThreadConstants.PACKAGE_REMOVED_DONT_KILL: |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5320 | { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 5321 | final boolean killApp = cmd == ApplicationThreadConstants.PACKAGE_REMOVED; |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5322 | if (packages == null) { |
| 5323 | break; |
| 5324 | } |
| 5325 | synchronized (mResourcesManager) { |
| 5326 | for (int i = packages.length - 1; i >= 0; i--) { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5327 | if (!hasPkgInfo) { |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5328 | WeakReference<LoadedApk> ref = mPackages.get(packages[i]); |
| 5329 | if (ref != null && ref.get() != null) { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5330 | hasPkgInfo = true; |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5331 | } else { |
| 5332 | ref = mResourcePackages.get(packages[i]); |
| 5333 | if (ref != null && ref.get() != null) { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5334 | hasPkgInfo = true; |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5335 | } |
| 5336 | } |
| 5337 | } |
| 5338 | if (killApp) { |
| 5339 | mPackages.remove(packages[i]); |
| 5340 | mResourcePackages.remove(packages[i]); |
| 5341 | } |
| 5342 | } |
| 5343 | } |
| 5344 | break; |
| 5345 | } |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 5346 | case ApplicationThreadConstants.PACKAGE_REPLACED: |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5347 | { |
| 5348 | if (packages == null) { |
| 5349 | break; |
| 5350 | } |
| 5351 | synchronized (mResourcesManager) { |
| 5352 | for (int i = packages.length - 1; i >= 0; i--) { |
| 5353 | WeakReference<LoadedApk> ref = mPackages.get(packages[i]); |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5354 | LoadedApk pkgInfo = ref != null ? ref.get() : null; |
| 5355 | if (pkgInfo != null) { |
| 5356 | hasPkgInfo = true; |
mark_chen | 89764e3 | 2014-12-12 15:38:48 +0800 | [diff] [blame] | 5357 | } else { |
| 5358 | ref = mResourcePackages.get(packages[i]); |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5359 | pkgInfo = ref != null ? ref.get() : null; |
| 5360 | if (pkgInfo != null) { |
| 5361 | hasPkgInfo = true; |
mark_chen | 89764e3 | 2014-12-12 15:38:48 +0800 | [diff] [blame] | 5362 | } |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 5363 | } |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5364 | // If the package is being replaced, yet it still has a valid |
| 5365 | // LoadedApk object, the package was updated with _DONT_KILL. |
| 5366 | // Adjust it's internal references to the application info and |
| 5367 | // resources. |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5368 | if (pkgInfo != null) { |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5369 | try { |
| 5370 | final String packageName = packages[i]; |
| 5371 | final ApplicationInfo aInfo = |
| 5372 | sPackageManager.getApplicationInfo( |
| 5373 | packageName, |
Svet Ganov | 6ce9239 | 2017-09-27 16:04:10 -0700 | [diff] [blame] | 5374 | PackageManager.GET_SHARED_LIBRARY_FILES, |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5375 | UserHandle.myUserId()); |
| 5376 | |
| 5377 | if (mActivities.size() > 0) { |
| 5378 | for (ActivityClientRecord ar : mActivities.values()) { |
| 5379 | if (ar.activityInfo.applicationInfo.packageName |
| 5380 | .equals(packageName)) { |
| 5381 | ar.activityInfo.applicationInfo = aInfo; |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5382 | ar.packageInfo = pkgInfo; |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5383 | } |
| 5384 | } |
| 5385 | } |
Todd Kennedy | b9656a9 | 2018-05-02 10:59:45 +0100 | [diff] [blame] | 5386 | final ArrayList<String> oldPaths = new ArrayList<>(); |
| 5387 | LoadedApk.makePaths(this, pkgInfo.getApplicationInfo(), oldPaths); |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5388 | pkgInfo.updateApplicationInfo(aInfo, oldPaths); |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5389 | } catch (RemoteException e) { |
| 5390 | } |
| 5391 | } |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 5392 | } |
| 5393 | } |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5394 | break; |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 5395 | } |
| 5396 | } |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5397 | ApplicationPackageManager.handlePackageBroadcast(cmd, packages, hasPkgInfo); |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 5398 | } |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 5399 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5400 | final void handleLowMemory() { |
Dianne Hackborn | 73c1416 | 2012-09-19 15:45:06 -0700 | [diff] [blame] | 5401 | ArrayList<ComponentCallbacks2> callbacks = collectComponentCallbacks(true, null); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 5402 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5403 | final int N = callbacks.size(); |
| 5404 | for (int i=0; i<N; i++) { |
| 5405 | callbacks.get(i).onLowMemory(); |
| 5406 | } |
| 5407 | |
Chris Tate | ce22905 | 2009-03-25 16:44:52 -0700 | [diff] [blame] | 5408 | // Ask SQLite to free up as much memory as it can, mostly from its page caches. |
| 5409 | if (Process.myUid() != Process.SYSTEM_UID) { |
| 5410 | int sqliteReleased = SQLiteDatabase.releaseMemory(); |
| 5411 | EventLog.writeEvent(SQLITE_MEM_RELEASED_EVENT_LOG_TAG, sqliteReleased); |
| 5412 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 5413 | |
Mike Reed | caf0df1 | 2009-04-27 14:32:05 -0400 | [diff] [blame] | 5414 | // Ask graphics to free up as much as possible (font/image caches) |
| 5415 | Canvas.freeCaches(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5416 | |
Fabrice Di Meglio | 30ca5cd | 2012-05-07 17:45:44 -0700 | [diff] [blame] | 5417 | // Ask text layout engine to free also as much as possible |
| 5418 | Canvas.freeTextLayoutCaches(); |
| 5419 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5420 | BinderInternal.forceGc("mem"); |
| 5421 | } |
| 5422 | |
Jorim Jaggi | b29e318 | 2018-04-30 18:51:56 +0200 | [diff] [blame] | 5423 | private void handleTrimMemory(int level) { |
| 5424 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "trimMemory"); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 5425 | if (DEBUG_MEMORY_TRIM) Slog.v(TAG, "Trimming memory to level: " + level); |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 5426 | |
Dianne Hackborn | 73c1416 | 2012-09-19 15:45:06 -0700 | [diff] [blame] | 5427 | ArrayList<ComponentCallbacks2> callbacks = collectComponentCallbacks(true, null); |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 5428 | |
| 5429 | final int N = callbacks.size(); |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 5430 | for (int i = 0; i < N; i++) { |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 5431 | callbacks.get(i).onTrimMemory(level); |
| 5432 | } |
Romain Guy | 19f86e8 | 2012-04-23 15:19:07 -0700 | [diff] [blame] | 5433 | |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 5434 | WindowManagerGlobal.getInstance().trimMemory(level); |
Jorim Jaggi | b29e318 | 2018-04-30 18:51:56 +0200 | [diff] [blame] | 5435 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 5436 | } |
| 5437 | |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 5438 | private void setupGraphicsSupport(Context context) { |
Andreas Gampe | 4c8e542 | 2016-05-18 11:58:47 -0700 | [diff] [blame] | 5439 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "setupGraphicsSupport"); |
Romain Guy | a958265 | 2011-11-10 14:20:10 -0800 | [diff] [blame] | 5440 | |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 5441 | // The system package doesn't have real data directories, so don't set up cache paths. |
| 5442 | if (!"android".equals(context.getPackageName())) { |
| 5443 | // This cache location probably points at credential-encrypted |
| 5444 | // storage which may not be accessible yet; assign it anyway instead |
| 5445 | // of pointing at device-encrypted storage. |
| 5446 | final File cacheDir = context.getCacheDir(); |
| 5447 | if (cacheDir != null) { |
| 5448 | // Provide a usable directory for temporary files |
| 5449 | System.setProperty("java.io.tmpdir", cacheDir.getAbsolutePath()); |
| 5450 | } else { |
| 5451 | Log.v(TAG, "Unable to initialize \"java.io.tmpdir\" property " |
| 5452 | + "due to missing cache directory"); |
Romain Guy | a958265 | 2011-11-10 14:20:10 -0800 | [diff] [blame] | 5453 | } |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 5454 | |
| 5455 | // Setup a location to store generated/compiled graphics code. |
| 5456 | final Context deviceContext = context.createDeviceProtectedStorageContext(); |
| 5457 | final File codeCacheDir = deviceContext.getCodeCacheDir(); |
| 5458 | if (codeCacheDir != null) { |
| 5459 | try { |
| 5460 | int uid = Process.myUid(); |
| 5461 | String[] packages = getPackageManager().getPackagesForUid(uid); |
| 5462 | if (packages != null) { |
Romain Guy | cecbe07 | 2017-07-18 15:42:06 -0700 | [diff] [blame] | 5463 | ThreadedRenderer.setupDiskCache(codeCacheDir); |
| 5464 | RenderScriptCacheDir.setupDiskCache(codeCacheDir); |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 5465 | } |
| 5466 | } catch (RemoteException e) { |
| 5467 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
| 5468 | throw e.rethrowFromSystemServer(); |
| 5469 | } |
| 5470 | } else { |
| 5471 | Log.w(TAG, "Unable to use shader/script cache: missing code-cache directory"); |
| 5472 | } |
Romain Guy | a958265 | 2011-11-10 14:20:10 -0800 | [diff] [blame] | 5473 | } |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 5474 | |
Cody Northrop | 86cedcb | 2017-10-20 09:03:13 -0600 | [diff] [blame] | 5475 | GraphicsEnvironment.getInstance().setup(context); |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 5476 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 5477 | } |
| 5478 | |
| 5479 | private void updateDefaultDensity() { |
Alan Viverette | 2ac46f1 | 2016-02-04 16:58:14 -0500 | [diff] [blame] | 5480 | final int densityDpi = mCurDefaultDisplayDpi; |
| 5481 | if (!mDensityCompatMode |
| 5482 | && densityDpi != Configuration.DENSITY_DPI_UNDEFINED |
| 5483 | && densityDpi != DisplayMetrics.DENSITY_DEVICE) { |
| 5484 | DisplayMetrics.DENSITY_DEVICE = densityDpi; |
| 5485 | Bitmap.setDefaultDensity(densityDpi); |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 5486 | } |
| 5487 | } |
| 5488 | |
Todd Kennedy | e713efc | 2016-05-10 13:45:40 -0700 | [diff] [blame] | 5489 | /** |
| 5490 | * Returns the correct library directory for the current ABI. |
| 5491 | * <p> |
| 5492 | * If we're dealing with a multi-arch application that has both 32 and 64 bit shared |
| 5493 | * libraries, we might need to choose the secondary depending on what the current |
| 5494 | * runtime's instruction set is. |
| 5495 | */ |
| 5496 | private String getInstrumentationLibrary(ApplicationInfo appInfo, InstrumentationInfo insInfo) { |
Patrick Baumann | eb59580 | 2018-04-17 09:49:55 -0700 | [diff] [blame] | 5497 | if (appInfo.primaryCpuAbi != null && appInfo.secondaryCpuAbi != null |
| 5498 | && appInfo.secondaryCpuAbi.equals(insInfo.secondaryCpuAbi)) { |
Todd Kennedy | e713efc | 2016-05-10 13:45:40 -0700 | [diff] [blame] | 5499 | // Get the instruction set supported by the secondary ABI. In the presence |
| 5500 | // of a native bridge this might be different than the one secondary ABI used. |
| 5501 | String secondaryIsa = |
| 5502 | VMRuntime.getInstructionSet(appInfo.secondaryCpuAbi); |
| 5503 | final String secondaryDexCodeIsa = |
| 5504 | SystemProperties.get("ro.dalvik.vm.isa." + secondaryIsa); |
| 5505 | secondaryIsa = secondaryDexCodeIsa.isEmpty() ? secondaryIsa : secondaryDexCodeIsa; |
| 5506 | |
| 5507 | final String runtimeIsa = VMRuntime.getRuntime().vmInstructionSet(); |
| 5508 | if (runtimeIsa.equals(secondaryIsa)) { |
| 5509 | return insInfo.secondaryNativeLibraryDir; |
| 5510 | } |
| 5511 | } |
| 5512 | return insInfo.nativeLibraryDir; |
| 5513 | } |
| 5514 | |
Adam Lesinski | b61e405 | 2016-05-19 18:23:05 -0700 | [diff] [blame] | 5515 | /** |
| 5516 | * The LocaleList set for the app's resources may have been shuffled so that the preferred |
| 5517 | * Locale is at position 0. We must find the index of this preferred Locale in the |
| 5518 | * original LocaleList. |
| 5519 | */ |
| 5520 | private void updateLocaleListFromAppContext(Context context, LocaleList newLocaleList) { |
| 5521 | final Locale bestLocale = context.getResources().getConfiguration().getLocales().get(0); |
| 5522 | final int newLocaleListSize = newLocaleList.size(); |
| 5523 | for (int i = 0; i < newLocaleListSize; i++) { |
| 5524 | if (bestLocale.equals(newLocaleList.get(i))) { |
| 5525 | LocaleList.setDefault(newLocaleList, i); |
| 5526 | return; |
| 5527 | } |
| 5528 | } |
Adam Lesinski | 27d3016 | 2016-05-25 16:45:14 -0700 | [diff] [blame] | 5529 | |
| 5530 | // The app may have overridden the LocaleList with its own Locale |
| 5531 | // (not present in the available list). Push the chosen Locale |
| 5532 | // to the front of the list. |
| 5533 | LocaleList.setDefault(new LocaleList(bestLocale, newLocaleList)); |
Adam Lesinski | b61e405 | 2016-05-19 18:23:05 -0700 | [diff] [blame] | 5534 | } |
| 5535 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 5536 | private void handleBindApplication(AppBindData data) { |
Calin Juravle | 8f5770d | 2016-04-12 14:12:04 +0100 | [diff] [blame] | 5537 | // Register the UI Thread as a sensitive thread to the runtime. |
| 5538 | VMRuntime.registerSensitiveThread(); |
Man Cao | cfa78b2 | 2015-06-11 20:14:34 -0700 | [diff] [blame] | 5539 | if (data.trackAllocation) { |
| 5540 | DdmVmInternal.enableRecentAllocations(true); |
| 5541 | } |
| 5542 | |
Dianne Hackborn | d98885c | 2016-03-01 17:13:03 -0800 | [diff] [blame] | 5543 | // Note when this process has started. |
| 5544 | Process.setStartTimes(SystemClock.elapsedRealtime(), SystemClock.uptimeMillis()); |
| 5545 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5546 | mBoundApplication = data; |
| 5547 | mConfiguration = new Configuration(data.config); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 5548 | mCompatConfiguration = new Configuration(data.config); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5549 | |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 5550 | mProfiler = new Profiler(); |
Andreas Gampe | ab8a63b | 2018-01-05 13:55:15 -0800 | [diff] [blame] | 5551 | String agent = null; |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 5552 | if (data.initProfilerInfo != null) { |
| 5553 | mProfiler.profileFile = data.initProfilerInfo.profileFile; |
| 5554 | mProfiler.profileFd = data.initProfilerInfo.profileFd; |
| 5555 | mProfiler.samplingInterval = data.initProfilerInfo.samplingInterval; |
| 5556 | mProfiler.autoStopProfiler = data.initProfilerInfo.autoStopProfiler; |
Shukang Zhou | 6ffd4f9 | 2017-01-25 16:07:57 -0800 | [diff] [blame] | 5557 | mProfiler.streamingOutput = data.initProfilerInfo.streamingOutput; |
Andreas Gampe | ab8a63b | 2018-01-05 13:55:15 -0800 | [diff] [blame] | 5558 | if (data.initProfilerInfo.attachAgentDuringBind) { |
| 5559 | agent = data.initProfilerInfo.agent; |
| 5560 | } |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 5561 | } |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 5562 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5563 | // send up app name; do this *before* waiting for debugger |
Christopher Tate | 8ee038d | 2009-11-06 11:30:20 -0800 | [diff] [blame] | 5564 | Process.setArgV0(data.processName); |
Siva Velusamy | d693dfa | 2012-09-10 14:36:58 -0700 | [diff] [blame] | 5565 | android.ddm.DdmHandleAppName.setAppName(data.processName, |
| 5566 | UserHandle.myUserId()); |
Mathew Inwood | 37b6ca8 | 2018-05-02 10:42:23 +0100 | [diff] [blame] | 5567 | VMRuntime.setProcessPackageName(data.appInfo.packageName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5568 | |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 5569 | if (mProfiler.profileFd != null) { |
| 5570 | mProfiler.startProfiling(); |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 5571 | } |
| 5572 | |
Joe Onorato | d630f10 | 2011-03-17 18:42:26 -0700 | [diff] [blame] | 5573 | // If the app is Honeycomb MR1 or earlier, switch its AsyncTask |
| 5574 | // implementation to use the pool executor. Normally, we use the |
| 5575 | // serialized executor as the default. This has to happen in the |
| 5576 | // main thread so the main looper is set right. |
Dianne Hackborn | 81e9276 | 2011-10-09 16:00:21 -0700 | [diff] [blame] | 5577 | if (data.appInfo.targetSdkVersion <= android.os.Build.VERSION_CODES.HONEYCOMB_MR1) { |
Joe Onorato | d630f10 | 2011-03-17 18:42:26 -0700 | [diff] [blame] | 5578 | AsyncTask.setDefaultExecutor(AsyncTask.THREAD_POOL_EXECUTOR); |
| 5579 | } |
| 5580 | |
Dianne Hackborn | 7895bc2 | 2014-09-05 15:09:03 -0700 | [diff] [blame] | 5581 | Message.updateCheckRecycle(data.appInfo.targetSdkVersion); |
| 5582 | |
Leon Scroggins III | 8290eab | 2018-03-19 10:51:44 -0400 | [diff] [blame] | 5583 | // Prior to P, internal calls to decode Bitmaps used BitmapFactory, |
| 5584 | // which may scale up to account for density. In P, we switched to |
| 5585 | // ImageDecoder, which skips the upscale to save memory. ImageDecoder |
| 5586 | // needs to still scale up in older apps, in case they rely on the |
| 5587 | // size of the Bitmap without considering its density. |
| 5588 | ImageDecoder.sApiLevel = data.appInfo.targetSdkVersion; |
| 5589 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5590 | /* |
| 5591 | * Before spawning a new process, reset the time zone to be the system time zone. |
| 5592 | * This needs to be done because the system time zone could have changed after the |
| 5593 | * the spawning of this process. Without doing this this process would have the incorrect |
| 5594 | * system time zone. |
| 5595 | */ |
| 5596 | TimeZone.setDefault(null); |
| 5597 | |
Adam Lesinski | b61e405 | 2016-05-19 18:23:05 -0700 | [diff] [blame] | 5598 | /* |
| 5599 | * Set the LocaleList. This may change once we create the App Context. |
| 5600 | */ |
| 5601 | LocaleList.setDefault(data.config.getLocales()); |
| 5602 | |
| 5603 | synchronized (mResourcesManager) { |
| 5604 | /* |
| 5605 | * Update the system configuration since its preloaded and might not |
| 5606 | * reflect configuration changes. The configuration object passed |
| 5607 | * in AppBindData can be safely assumed to be up to date |
| 5608 | */ |
| 5609 | mResourcesManager.applyConfigurationToResourcesLocked(data.config, data.compatInfo); |
| 5610 | mCurDefaultDisplayDpi = data.config.densityDpi; |
| 5611 | |
| 5612 | // This calls mResourcesManager so keep it within the synchronized block. |
| 5613 | applyCompatConfiguration(mCurDefaultDisplayDpi); |
| 5614 | } |
| 5615 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5616 | data.info = getPackageInfoNoCheck(data.appInfo, data.compatInfo); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5617 | |
Andreas Gampe | ab8a63b | 2018-01-05 13:55:15 -0800 | [diff] [blame] | 5618 | if (agent != null) { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5619 | handleAttachAgent(agent, data.info); |
Andreas Gampe | ab8a63b | 2018-01-05 13:55:15 -0800 | [diff] [blame] | 5620 | } |
| 5621 | |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 5622 | /** |
| 5623 | * Switch this process to density compatibility mode if needed. |
| 5624 | */ |
| 5625 | if ((data.appInfo.flags&ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES) |
| 5626 | == 0) { |
| 5627 | mDensityCompatMode = true; |
| 5628 | Bitmap.setDefaultDensity(DisplayMetrics.DENSITY_DEFAULT); |
| 5629 | } |
| 5630 | updateDefaultDensity(); |
| 5631 | |
Neil Fuller | c66ec40 | 2016-11-14 16:06:42 +0000 | [diff] [blame] | 5632 | final String use24HourSetting = mCoreSettings.getString(Settings.System.TIME_12_24); |
| 5633 | Boolean is24Hr = null; |
| 5634 | if (use24HourSetting != null) { |
| 5635 | is24Hr = "24".equals(use24HourSetting) ? Boolean.TRUE : Boolean.FALSE; |
| 5636 | } |
| 5637 | // null : use locale default for 12/24 hour formatting, |
| 5638 | // false : use 12 hour format, |
| 5639 | // true : use 24 hour format. |
Narayan Kamath | ccb2a086 | 2013-12-19 14:49:36 +0000 | [diff] [blame] | 5640 | DateFormat.set24HourTimePref(is24Hr); |
| 5641 | |
Jon Miranda | 836c0a8 | 2014-08-11 12:32:26 -0700 | [diff] [blame] | 5642 | View.mDebugViewAttributes = |
| 5643 | mCoreSettings.getInt(Settings.Global.DEBUG_VIEW_ATTRIBUTES, 0) != 0; |
| 5644 | |
Jeff Sharkey | 8918298 | 2017-11-01 19:02:56 -0600 | [diff] [blame] | 5645 | StrictMode.initThreadDefaults(data.appInfo); |
| 5646 | StrictMode.initVmDefaults(data.appInfo); |
Jeff Sharkey | 344744b | 2016-01-28 19:03:30 -0700 | [diff] [blame] | 5647 | |
Svet Ganov | 37e4327 | 2016-09-09 16:01:32 -0700 | [diff] [blame] | 5648 | // We deprecated Build.SERIAL and only apps that target pre NMR1 |
| 5649 | // SDK can see it. Since access to the serial is now behind a |
| 5650 | // permission we push down the value and here we fix it up |
| 5651 | // before any app code has been loaded. |
| 5652 | try { |
| 5653 | Field field = Build.class.getDeclaredField("SERIAL"); |
| 5654 | field.setAccessible(true); |
| 5655 | field.set(Build.class, data.buildSerial); |
| 5656 | } catch (NoSuchFieldException | IllegalAccessException e) { |
| 5657 | /* ignore */ |
| 5658 | } |
| 5659 | |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 5660 | if (data.debugMode != ApplicationThreadConstants.DEBUG_OFF) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5661 | // XXX should have option to change the port. |
| 5662 | Debug.changeDebugPort(8100); |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 5663 | if (data.debugMode == ApplicationThreadConstants.DEBUG_WAIT) { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5664 | Slog.w(TAG, "Application " + data.info.getPackageName() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5665 | + " is waiting for the debugger on port 8100..."); |
| 5666 | |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5667 | IActivityManager mgr = ActivityManager.getService(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5668 | try { |
| 5669 | mgr.showWaitingForDebugger(mAppThread, true); |
| 5670 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5671 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5672 | } |
| 5673 | |
| 5674 | Debug.waitForDebugger(); |
| 5675 | |
| 5676 | try { |
| 5677 | mgr.showWaitingForDebugger(mAppThread, false); |
| 5678 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5679 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5680 | } |
| 5681 | |
| 5682 | } else { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5683 | Slog.w(TAG, "Application " + data.info.getPackageName() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5684 | + " can be debugged on port 8100..."); |
| 5685 | } |
| 5686 | } |
| 5687 | |
Jamie Gennis | f9c7d6b | 2013-03-25 14:18:25 -0700 | [diff] [blame] | 5688 | // Allow application-generated systrace messages if we're debuggable. |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 5689 | boolean isAppDebuggable = (data.appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0; |
| 5690 | Trace.setAppTracingAllowed(isAppDebuggable); |
John Reck | 5642847 | 2018-03-16 17:27:17 -0700 | [diff] [blame] | 5691 | ThreadedRenderer.setDebuggingEnabled(isAppDebuggable || Build.IS_DEBUGGABLE); |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 5692 | if (isAppDebuggable && data.enableBinderTracking) { |
| 5693 | Binder.enableTracing(); |
| 5694 | } |
Jamie Gennis | f9c7d6b | 2013-03-25 14:18:25 -0700 | [diff] [blame] | 5695 | |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 5696 | /** |
| 5697 | * Initialize the default http proxy in this process for the reasons we set the time zone. |
| 5698 | */ |
Andreas Gampe | 4c8e542 | 2016-05-18 11:58:47 -0700 | [diff] [blame] | 5699 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "Setup proxies"); |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 5700 | final IBinder b = ServiceManager.getService(Context.CONNECTIVITY_SERVICE); |
Dianne Hackborn | d4d32c5 | 2011-11-08 17:33:59 -0800 | [diff] [blame] | 5701 | if (b != null) { |
| 5702 | // In pre-boot mode (doing initial launch to collect password), not |
| 5703 | // all system is up. This includes the connectivity service, so don't |
| 5704 | // crash if we can't get it. |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 5705 | final IConnectivityManager service = IConnectivityManager.Stub.asInterface(b); |
Dianne Hackborn | d4d32c5 | 2011-11-08 17:33:59 -0800 | [diff] [blame] | 5706 | try { |
Paul Jensen | cee9b51 | 2015-05-06 07:32:40 -0400 | [diff] [blame] | 5707 | final ProxyInfo proxyInfo = service.getProxyForNetwork(null); |
Jason Monk | 207900c | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 5708 | Proxy.setHttpProxySystemProperty(proxyInfo); |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5709 | } catch (RemoteException e) { |
Andreas Gampe | 4c8e542 | 2016-05-18 11:58:47 -0700 | [diff] [blame] | 5710 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5711 | throw e.rethrowFromSystemServer(); |
| 5712 | } |
Dianne Hackborn | d4d32c5 | 2011-11-08 17:33:59 -0800 | [diff] [blame] | 5713 | } |
Andreas Gampe | 4c8e542 | 2016-05-18 11:58:47 -0700 | [diff] [blame] | 5714 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 5715 | |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 5716 | // Instrumentation info affects the class loader, so load it before |
| 5717 | // setting up the app context. |
| 5718 | final InstrumentationInfo ii; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5719 | if (data.instrumentationName != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5720 | try { |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 5721 | ii = new ApplicationPackageManager(null, getPackageManager()) |
| 5722 | .getInstrumentationInfo(data.instrumentationName, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5723 | } catch (PackageManager.NameNotFoundException e) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5724 | throw new RuntimeException( |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 5725 | "Unable to find instrumentation info for: " + data.instrumentationName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5726 | } |
| 5727 | |
Patrick Baumann | eb59580 | 2018-04-17 09:49:55 -0700 | [diff] [blame] | 5728 | // Warn of potential ABI mismatches. |
| 5729 | if (!Objects.equals(data.appInfo.primaryCpuAbi, ii.primaryCpuAbi) |
| 5730 | || !Objects.equals(data.appInfo.secondaryCpuAbi, ii.secondaryCpuAbi)) { |
| 5731 | Slog.w(TAG, "Package uses different ABI(s) than its instrumentation: " |
| 5732 | + "package[" + data.appInfo.packageName + "]: " |
| 5733 | + data.appInfo.primaryCpuAbi + ", " + data.appInfo.secondaryCpuAbi |
| 5734 | + " instrumentation[" + ii.packageName + "]: " |
| 5735 | + ii.primaryCpuAbi + ", " + ii.secondaryCpuAbi); |
| 5736 | } |
| 5737 | |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 5738 | mInstrumentationPackageName = ii.packageName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5739 | mInstrumentationAppDir = ii.sourceDir; |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 5740 | mInstrumentationSplitAppDirs = ii.splitSourceDirs; |
Todd Kennedy | e713efc | 2016-05-10 13:45:40 -0700 | [diff] [blame] | 5741 | mInstrumentationLibDir = getInstrumentationLibrary(data.appInfo, ii); |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5742 | mInstrumentedAppDir = data.info.getAppDir(); |
| 5743 | mInstrumentedSplitAppDirs = data.info.getSplitAppDirs(); |
| 5744 | mInstrumentedLibDir = data.info.getLibDir(); |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 5745 | } else { |
| 5746 | ii = null; |
| 5747 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5748 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5749 | final ContextImpl appContext = ContextImpl.createAppContext(this, data.info); |
Adam Lesinski | b61e405 | 2016-05-19 18:23:05 -0700 | [diff] [blame] | 5750 | updateLocaleListFromAppContext(appContext, |
| 5751 | mResourcesManager.getConfiguration().getLocales()); |
Seigo Nonaka | c14dd78 | 2016-03-30 23:09:16 +0900 | [diff] [blame] | 5752 | |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 5753 | if (!Process.isIsolated()) { |
Jeff Sharkey | 8918298 | 2017-11-01 19:02:56 -0600 | [diff] [blame] | 5754 | final int oldMask = StrictMode.allowThreadDiskWritesMask(); |
| 5755 | try { |
| 5756 | setupGraphicsSupport(appContext); |
| 5757 | } finally { |
| 5758 | StrictMode.setThreadPolicyMask(oldMask); |
| 5759 | } |
John Reck | 5642847 | 2018-03-16 17:27:17 -0700 | [diff] [blame] | 5760 | } else { |
| 5761 | ThreadedRenderer.setIsolatedProcess(true); |
Michael Lentine | 2ba303f | 2016-02-01 20:44:34 -0600 | [diff] [blame] | 5762 | } |
Michael Lentine | 03d8f768 | 2016-01-31 15:37:11 -0600 | [diff] [blame] | 5763 | |
Calin Juravle | 37dfc8e | 2017-03-13 19:02:32 -0700 | [diff] [blame] | 5764 | // If we use profiles, setup the dex reporter to notify package manager |
| 5765 | // of any relevant dex loads. The idle maintenance job will use the information |
| 5766 | // reported to optimize the loaded dex files. |
| 5767 | // Note that we only need one global reporter per app. |
| 5768 | // Make sure we do this before calling onCreate so that we can capture the |
| 5769 | // complete application startup. |
| 5770 | if (SystemProperties.getBoolean("dalvik.vm.usejitprofiles", false)) { |
Calin Juravle | f5a7bfc | 2017-03-13 23:30:30 -0700 | [diff] [blame] | 5771 | BaseDexClassLoader.setReporter(DexLoadReporter.getInstance()); |
Calin Juravle | 37dfc8e | 2017-03-13 19:02:32 -0700 | [diff] [blame] | 5772 | } |
| 5773 | |
Chad Brubaker | 78d4712 | 2015-11-17 22:26:58 -0800 | [diff] [blame] | 5774 | // Install the Network Security Config Provider. This must happen before the application |
| 5775 | // code is loaded to prevent issues with instances of TLS objects being created before |
| 5776 | // the provider is installed. |
Andreas Gampe | 4c8e542 | 2016-05-18 11:58:47 -0700 | [diff] [blame] | 5777 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "NetworkSecurityConfigProvider.install"); |
Chad Brubaker | 276ee96 | 2016-06-08 12:57:46 -0700 | [diff] [blame] | 5778 | NetworkSecurityConfigProvider.install(appContext); |
Andreas Gampe | 4c8e542 | 2016-05-18 11:58:47 -0700 | [diff] [blame] | 5779 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Chad Brubaker | 78d4712 | 2015-11-17 22:26:58 -0800 | [diff] [blame] | 5780 | |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 5781 | // Continue loading instrumentation. |
| 5782 | if (ii != null) { |
Dianne Hackborn | f4ef6eb | 2017-12-07 13:57:21 -0800 | [diff] [blame] | 5783 | ApplicationInfo instrApp; |
| 5784 | try { |
| 5785 | instrApp = getPackageManager().getApplicationInfo(ii.packageName, 0, |
| 5786 | UserHandle.myUserId()); |
| 5787 | } catch (RemoteException e) { |
| 5788 | instrApp = null; |
| 5789 | } |
| 5790 | if (instrApp == null) { |
| 5791 | instrApp = new ApplicationInfo(); |
| 5792 | } |
Jeff Sharkey | 1544779 | 2015-11-05 16:18:51 -0800 | [diff] [blame] | 5793 | ii.copyTo(instrApp); |
Fyodor Kupolov | af38b8e | 2015-12-02 16:16:07 -0800 | [diff] [blame] | 5794 | instrApp.initForUser(UserHandle.myUserId()); |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5795 | final LoadedApk pi = getPackageInfo(instrApp, data.compatInfo, |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 5796 | appContext.getClassLoader(), false, true, false); |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5797 | final ContextImpl instrContext = ContextImpl.createAppContext(this, pi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5798 | |
| 5799 | try { |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 5800 | final ClassLoader cl = instrContext.getClassLoader(); |
Dan Sandler | 07fe63e | 2017-08-15 16:41:11 -0400 | [diff] [blame] | 5801 | mInstrumentation = (Instrumentation) |
| 5802 | cl.loadClass(data.instrumentationName.getClassName()).newInstance(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5803 | } catch (Exception e) { |
| 5804 | throw new RuntimeException( |
| 5805 | "Unable to instantiate instrumentation " |
| 5806 | + data.instrumentationName + ": " + e.toString(), e); |
| 5807 | } |
| 5808 | |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 5809 | final ComponentName component = new ComponentName(ii.packageName, ii.name); |
| 5810 | mInstrumentation.init(this, instrContext, appContext, component, |
| 5811 | data.instrumentationWatcher, data.instrumentationUiAutomationConnection); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5812 | |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 5813 | if (mProfiler.profileFile != null && !ii.handleProfiling |
| 5814 | && mProfiler.profileFd == null) { |
| 5815 | mProfiler.handlingProfiling = true; |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 5816 | final File file = new File(mProfiler.profileFile); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5817 | file.getParentFile().mkdirs(); |
| 5818 | Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024); |
| 5819 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5820 | } else { |
| 5821 | mInstrumentation = new Instrumentation(); |
Jason Monk | a80bfb5 | 2017-11-16 17:15:37 -0500 | [diff] [blame] | 5822 | mInstrumentation.basicInit(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5823 | } |
| 5824 | |
Dianne Hackborn | 3b81bc1 | 2011-01-15 11:50:52 -0800 | [diff] [blame] | 5825 | if ((data.appInfo.flags&ApplicationInfo.FLAG_LARGE_HEAP) != 0) { |
Dianne Hackborn | de39851 | 2011-01-18 18:45:21 -0800 | [diff] [blame] | 5826 | dalvik.system.VMRuntime.getRuntime().clearGrowthLimit(); |
Mathieu Chartier | 24cee07 | 2015-01-08 14:42:20 -0800 | [diff] [blame] | 5827 | } else { |
| 5828 | // Small heap, clamp to the current growth limit and let the heap release |
| 5829 | // pages after the growth limit to the non growth limit capacity. b/18387825 |
| 5830 | dalvik.system.VMRuntime.getRuntime().clampGrowthLimit(); |
Dianne Hackborn | 3b81bc1 | 2011-01-15 11:50:52 -0800 | [diff] [blame] | 5831 | } |
| 5832 | |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 5833 | // Allow disk access during application and provider setup. This could |
Jeff Sharkey | 7c50167 | 2012-02-28 12:08:37 -0800 | [diff] [blame] | 5834 | // block processing ordered broadcasts, but later processing would |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 5835 | // probably end up doing the same disk access. |
Kurt Nelson | 5e15436 | 2017-06-29 17:20:56 -0700 | [diff] [blame] | 5836 | Application app; |
Jeff Sharkey | 7c50167 | 2012-02-28 12:08:37 -0800 | [diff] [blame] | 5837 | final StrictMode.ThreadPolicy savedPolicy = StrictMode.allowThreadDiskWrites(); |
Kurt Nelson | 571c3f6 | 2017-07-10 11:09:04 -0700 | [diff] [blame] | 5838 | final StrictMode.ThreadPolicy writesAllowedPolicy = StrictMode.getThreadPolicy(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5839 | try { |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 5840 | // If the app is being launched for full backup or restore, bring it up in |
| 5841 | // a restricted environment with the base application class. |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5842 | app = data.info.makeApplication(data.restrictedBackupMode, null); |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 5843 | |
| 5844 | // Propagate autofill compat state |
| 5845 | app.setAutofillCompatibilityEnabled(data.autofillCompatibilityEnabled); |
| 5846 | |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 5847 | mInitialApplication = app; |
Jeff Sharkey | 7c50167 | 2012-02-28 12:08:37 -0800 | [diff] [blame] | 5848 | |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 5849 | // don't bring up providers in restricted mode; they may depend on the |
| 5850 | // app's custom Application class |
| 5851 | if (!data.restrictedBackupMode) { |
Jeff Sharkey | 3e19589 | 2016-03-05 19:48:59 -0700 | [diff] [blame] | 5852 | if (!ArrayUtils.isEmpty(data.providers)) { |
| 5853 | installContentProviders(app, data.providers); |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 5854 | // For process that contains content providers, we want to |
| 5855 | // ensure that the JIT is enabled "at some point". |
| 5856 | mH.sendEmptyMessageDelayed(H.ENABLE_JIT, 10*1000); |
| 5857 | } |
| 5858 | } |
| 5859 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5860 | // Do this after providers, since instrumentation tests generally start their |
| 5861 | // test thread at this point, and we don't want that racing. |
| 5862 | try { |
| 5863 | mInstrumentation.onCreate(data.instrumentationArgs); |
| 5864 | } |
| 5865 | catch (Exception e) { |
| 5866 | throw new RuntimeException( |
| 5867 | "Exception thrown in onCreate() of " |
| 5868 | + data.instrumentationName + ": " + e.toString(), e); |
| 5869 | } |
Kurt Nelson | 571c3f6 | 2017-07-10 11:09:04 -0700 | [diff] [blame] | 5870 | try { |
| 5871 | mInstrumentation.callApplicationOnCreate(app); |
| 5872 | } catch (Exception e) { |
| 5873 | if (!mInstrumentation.onException(app, e)) { |
| 5874 | throw new RuntimeException( |
| 5875 | "Unable to create application " + app.getClass().getName() |
| 5876 | + ": " + e.toString(), e); |
| 5877 | } |
| 5878 | } |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 5879 | } finally { |
Kurt Nelson | 571c3f6 | 2017-07-10 11:09:04 -0700 | [diff] [blame] | 5880 | // If the app targets < O-MR1, or doesn't change the thread policy |
| 5881 | // during startup, clobber the policy to maintain behavior of b/36951662 |
Jeff Sharkey | aa1a911 | 2018-04-10 15:18:12 -0600 | [diff] [blame] | 5882 | if (data.appInfo.targetSdkVersion < Build.VERSION_CODES.O_MR1 |
Kurt Nelson | 571c3f6 | 2017-07-10 11:09:04 -0700 | [diff] [blame] | 5883 | || StrictMode.getThreadPolicy().equals(writesAllowedPolicy)) { |
| 5884 | StrictMode.setThreadPolicy(savedPolicy); |
Kurt Nelson | 5e15436 | 2017-06-29 17:20:56 -0700 | [diff] [blame] | 5885 | } |
| 5886 | } |
| 5887 | |
Clara Bayarri | 4b5a4d2 | 2017-01-27 20:15:45 +0000 | [diff] [blame] | 5888 | // Preload fonts resources |
Seigo Nonaka | 54084b6 | 2017-04-24 14:46:23 -0700 | [diff] [blame] | 5889 | FontsContract.setApplicationContextForResources(appContext); |
Torne (Richard Coles) | 85ecae5 | 2018-01-30 18:13:00 -0500 | [diff] [blame] | 5890 | if (!Process.isIsolated()) { |
| 5891 | try { |
| 5892 | final ApplicationInfo info = |
| 5893 | getPackageManager().getApplicationInfo( |
| 5894 | data.appInfo.packageName, |
| 5895 | PackageManager.GET_META_DATA /*flags*/, |
| 5896 | UserHandle.myUserId()); |
| 5897 | if (info.metaData != null) { |
| 5898 | final int preloadedFontsResource = info.metaData.getInt( |
| 5899 | ApplicationInfo.METADATA_PRELOADED_FONTS, 0); |
| 5900 | if (preloadedFontsResource != 0) { |
| 5901 | data.info.getResources().preloadFonts(preloadedFontsResource); |
| 5902 | } |
Clara Bayarri | 4b5a4d2 | 2017-01-27 20:15:45 +0000 | [diff] [blame] | 5903 | } |
Torne (Richard Coles) | 85ecae5 | 2018-01-30 18:13:00 -0500 | [diff] [blame] | 5904 | } catch (RemoteException e) { |
| 5905 | throw e.rethrowFromSystemServer(); |
Clara Bayarri | 4b5a4d2 | 2017-01-27 20:15:45 +0000 | [diff] [blame] | 5906 | } |
Clara Bayarri | 4b5a4d2 | 2017-01-27 20:15:45 +0000 | [diff] [blame] | 5907 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5908 | } |
| 5909 | |
| 5910 | /*package*/ final void finishInstrumentation(int resultCode, Bundle results) { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5911 | IActivityManager am = ActivityManager.getService(); |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 5912 | if (mProfiler.profileFile != null && mProfiler.handlingProfiling |
| 5913 | && mProfiler.profileFd == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5914 | Debug.stopMethodTracing(); |
| 5915 | } |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5916 | //Slog.i(TAG, "am: " + ActivityManager.getService() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5917 | // + ", app thr: " + mAppThread); |
| 5918 | try { |
| 5919 | am.finishInstrumentation(mAppThread, resultCode, results); |
| 5920 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5921 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5922 | } |
| 5923 | } |
| 5924 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 5925 | private void installContentProviders( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5926 | Context context, List<ProviderInfo> providers) { |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 5927 | final ArrayList<ContentProviderHolder> results = new ArrayList<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5928 | |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 5929 | for (ProviderInfo cpi : providers) { |
Dianne Hackborn | 40e9f29 | 2012-11-27 19:12:23 -0800 | [diff] [blame] | 5930 | if (DEBUG_PROVIDER) { |
| 5931 | StringBuilder buf = new StringBuilder(128); |
| 5932 | buf.append("Pub "); |
| 5933 | buf.append(cpi.authority); |
| 5934 | buf.append(": "); |
| 5935 | buf.append(cpi.name); |
| 5936 | Log.i(TAG, buf.toString()); |
| 5937 | } |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 5938 | ContentProviderHolder cph = installProvider(context, null, cpi, |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5939 | false /*noisy*/, true /*noReleaseNeeded*/, true /*stable*/); |
| 5940 | if (cph != null) { |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5941 | cph.noReleaseNeeded = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5942 | results.add(cph); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5943 | } |
| 5944 | } |
| 5945 | |
| 5946 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5947 | ActivityManager.getService().publishContentProviders( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5948 | getApplicationThread(), results); |
| 5949 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5950 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5951 | } |
| 5952 | } |
| 5953 | |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 5954 | public final IContentProvider acquireProvider( |
| 5955 | Context c, String auth, int userId, boolean stable) { |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 5956 | final IContentProvider provider = acquireExistingProvider(c, auth, userId, stable); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5957 | if (provider != null) { |
| 5958 | return provider; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5959 | } |
| 5960 | |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 5961 | // There is a possible race here. Another thread may try to acquire |
| 5962 | // the same provider at the same time. When this happens, we want to ensure |
| 5963 | // that the first one wins. |
| 5964 | // Note that we cannot hold the lock while acquiring and installing the |
| 5965 | // provider since it might take a long time to run and it could also potentially |
| 5966 | // 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] | 5967 | ContentProviderHolder holder = null; |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 5968 | try { |
Makoto Onuki | b6c79ea | 2018-05-31 11:03:56 -0700 | [diff] [blame] | 5969 | synchronized (getGetProviderLock(auth, userId)) { |
| 5970 | holder = ActivityManager.getService().getContentProvider( |
| 5971 | getApplicationThread(), auth, userId, stable); |
| 5972 | } |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 5973 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5974 | throw ex.rethrowFromSystemServer(); |
Wale Ogunwale | 67fe0a4 | 2015-04-24 14:44:54 -0700 | [diff] [blame] | 5975 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5976 | if (holder == null) { |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 5977 | 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] | 5978 | return null; |
| 5979 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5980 | |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5981 | // Install provider will increment the reference count for us, and break |
| 5982 | // any ties in the race. |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5983 | holder = installProvider(c, holder, holder.info, |
| 5984 | true /*noisy*/, holder.noReleaseNeeded, stable); |
| 5985 | return holder.provider; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5986 | } |
| 5987 | |
Makoto Onuki | b6c79ea | 2018-05-31 11:03:56 -0700 | [diff] [blame] | 5988 | private Object getGetProviderLock(String auth, int userId) { |
| 5989 | final ProviderKey key = new ProviderKey(auth, userId); |
| 5990 | synchronized (mGetProviderLocks) { |
| 5991 | Object lock = mGetProviderLocks.get(key); |
| 5992 | if (lock == null) { |
| 5993 | lock = key; |
| 5994 | mGetProviderLocks.put(key, lock); |
| 5995 | } |
| 5996 | return lock; |
| 5997 | } |
| 5998 | } |
| 5999 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6000 | private final void incProviderRefLocked(ProviderRefCount prc, boolean stable) { |
| 6001 | if (stable) { |
| 6002 | prc.stableCount += 1; |
| 6003 | if (prc.stableCount == 1) { |
| 6004 | // We are acquiring a new stable reference on the provider. |
| 6005 | int unstableDelta; |
| 6006 | if (prc.removePending) { |
| 6007 | // We have a pending remove operation, which is holding the |
| 6008 | // last unstable reference. At this point we are converting |
| 6009 | // that unstable reference to our new stable reference. |
| 6010 | unstableDelta = -1; |
| 6011 | // Cancel the removal of the provider. |
| 6012 | if (DEBUG_PROVIDER) { |
| 6013 | Slog.v(TAG, "incProviderRef: stable " |
| 6014 | + "snatched provider from the jaws of death"); |
| 6015 | } |
| 6016 | prc.removePending = false; |
Guobin Zhang | 9e3e5266 | 2013-03-21 13:57:11 +0800 | [diff] [blame] | 6017 | // There is a race! It fails to remove the message, which |
| 6018 | // will be handled in completeRemoveProvider(). |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6019 | mH.removeMessages(H.REMOVE_PROVIDER, prc); |
| 6020 | } else { |
| 6021 | unstableDelta = 0; |
| 6022 | } |
| 6023 | try { |
| 6024 | if (DEBUG_PROVIDER) { |
| 6025 | Slog.v(TAG, "incProviderRef Now stable - " |
| 6026 | + prc.holder.info.name + ": unstableDelta=" |
| 6027 | + unstableDelta); |
| 6028 | } |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6029 | ActivityManager.getService().refContentProvider( |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6030 | prc.holder.connection, 1, unstableDelta); |
| 6031 | } catch (RemoteException e) { |
| 6032 | //do nothing content provider object is dead any way |
| 6033 | } |
| 6034 | } |
| 6035 | } else { |
| 6036 | prc.unstableCount += 1; |
| 6037 | if (prc.unstableCount == 1) { |
| 6038 | // We are acquiring a new unstable reference on the provider. |
| 6039 | if (prc.removePending) { |
| 6040 | // Oh look, we actually have a remove pending for the |
| 6041 | // provider, which is still holding the last unstable |
| 6042 | // reference. We just need to cancel that to take new |
| 6043 | // ownership of the reference. |
| 6044 | if (DEBUG_PROVIDER) { |
| 6045 | Slog.v(TAG, "incProviderRef: unstable " |
| 6046 | + "snatched provider from the jaws of death"); |
| 6047 | } |
| 6048 | prc.removePending = false; |
| 6049 | mH.removeMessages(H.REMOVE_PROVIDER, prc); |
| 6050 | } else { |
| 6051 | // First unstable ref, increment our count in the |
| 6052 | // activity manager. |
| 6053 | try { |
| 6054 | if (DEBUG_PROVIDER) { |
| 6055 | Slog.v(TAG, "incProviderRef: Now unstable - " |
| 6056 | + prc.holder.info.name); |
| 6057 | } |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6058 | ActivityManager.getService().refContentProvider( |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6059 | prc.holder.connection, 0, 1); |
| 6060 | } catch (RemoteException e) { |
| 6061 | //do nothing content provider object is dead any way |
| 6062 | } |
| 6063 | } |
| 6064 | } |
| 6065 | } |
| 6066 | } |
| 6067 | |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 6068 | public final IContentProvider acquireExistingProvider( |
| 6069 | Context c, String auth, int userId, boolean stable) { |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6070 | synchronized (mProviderMap) { |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 6071 | final ProviderKey key = new ProviderKey(auth, userId); |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 6072 | final ProviderClientRecord pr = mProviderMap.get(key); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6073 | if (pr == null) { |
| 6074 | return null; |
| 6075 | } |
| 6076 | |
| 6077 | IContentProvider provider = pr.mProvider; |
| 6078 | IBinder jBinder = provider.asBinder(); |
Dianne Hackborn | c428aae | 2012-10-03 16:38:22 -0700 | [diff] [blame] | 6079 | if (!jBinder.isBinderAlive()) { |
| 6080 | // The hosting process of the provider has died; we can't |
| 6081 | // use this one. |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 6082 | Log.i(TAG, "Acquiring provider " + auth + " for user " + userId |
Dianne Hackborn | c428aae | 2012-10-03 16:38:22 -0700 | [diff] [blame] | 6083 | + ": existing object's process dead"); |
| 6084 | handleUnstableProviderDiedLocked(jBinder, true); |
| 6085 | return null; |
| 6086 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6087 | |
| 6088 | // Only increment the ref count if we have one. If we don't then the |
| 6089 | // provider is not reference counted and never needs to be released. |
Dianne Hackborn | cca1f0e | 2010-09-26 18:34:53 -0700 | [diff] [blame] | 6090 | ProviderRefCount prc = mProviderRefCountMap.get(jBinder); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6091 | if (prc != null) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6092 | incProviderRefLocked(prc, stable); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6093 | } |
| 6094 | return provider; |
| 6095 | } |
Dianne Hackborn | cca1f0e | 2010-09-26 18:34:53 -0700 | [diff] [blame] | 6096 | } |
| 6097 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6098 | public final boolean releaseProvider(IContentProvider provider, boolean stable) { |
| 6099 | if (provider == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6100 | return false; |
| 6101 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6102 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6103 | IBinder jBinder = provider.asBinder(); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6104 | synchronized (mProviderMap) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6105 | ProviderRefCount prc = mProviderRefCountMap.get(jBinder); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6106 | if (prc == null) { |
| 6107 | // 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] | 6108 | return false; |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6109 | } |
| 6110 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6111 | boolean lastRef = false; |
| 6112 | if (stable) { |
| 6113 | if (prc.stableCount == 0) { |
| 6114 | if (DEBUG_PROVIDER) Slog.v(TAG, |
| 6115 | "releaseProvider: stable ref count already 0, how?"); |
| 6116 | return false; |
| 6117 | } |
| 6118 | prc.stableCount -= 1; |
| 6119 | if (prc.stableCount == 0) { |
| 6120 | // What we do at this point depends on whether there are |
| 6121 | // any unstable refs left: if there are, we just tell the |
| 6122 | // activity manager to decrement its stable count; if there |
| 6123 | // aren't, we need to enqueue this provider to be removed, |
| 6124 | // and convert to holding a single unstable ref while |
| 6125 | // doing so. |
| 6126 | lastRef = prc.unstableCount == 0; |
| 6127 | try { |
| 6128 | if (DEBUG_PROVIDER) { |
| 6129 | Slog.v(TAG, "releaseProvider: No longer stable w/lastRef=" |
| 6130 | + lastRef + " - " + prc.holder.info.name); |
| 6131 | } |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6132 | ActivityManager.getService().refContentProvider( |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6133 | prc.holder.connection, -1, lastRef ? 1 : 0); |
| 6134 | } catch (RemoteException e) { |
| 6135 | //do nothing content provider object is dead any way |
| 6136 | } |
| 6137 | } |
| 6138 | } else { |
| 6139 | if (prc.unstableCount == 0) { |
| 6140 | if (DEBUG_PROVIDER) Slog.v(TAG, |
| 6141 | "releaseProvider: unstable ref count already 0, how?"); |
| 6142 | return false; |
| 6143 | } |
| 6144 | prc.unstableCount -= 1; |
| 6145 | if (prc.unstableCount == 0) { |
| 6146 | // If this is the last reference, we need to enqueue |
| 6147 | // this provider to be removed instead of telling the |
| 6148 | // activity manager to remove it at this point. |
| 6149 | lastRef = prc.stableCount == 0; |
| 6150 | if (!lastRef) { |
| 6151 | try { |
| 6152 | if (DEBUG_PROVIDER) { |
| 6153 | Slog.v(TAG, "releaseProvider: No longer unstable - " |
| 6154 | + prc.holder.info.name); |
| 6155 | } |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6156 | ActivityManager.getService().refContentProvider( |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6157 | prc.holder.connection, 0, -1); |
| 6158 | } catch (RemoteException e) { |
| 6159 | //do nothing content provider object is dead any way |
| 6160 | } |
| 6161 | } |
| 6162 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6163 | } |
| 6164 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6165 | if (lastRef) { |
| 6166 | if (!prc.removePending) { |
| 6167 | // Schedule the actual remove asynchronously, since we don't know the context |
| 6168 | // this will be called in. |
| 6169 | // TODO: it would be nice to post a delayed message, so |
| 6170 | // if we come back and need the same provider quickly |
| 6171 | // we will still have it available. |
| 6172 | if (DEBUG_PROVIDER) { |
| 6173 | Slog.v(TAG, "releaseProvider: Enqueueing pending removal - " |
| 6174 | + prc.holder.info.name); |
| 6175 | } |
| 6176 | prc.removePending = true; |
| 6177 | Message msg = mH.obtainMessage(H.REMOVE_PROVIDER, prc); |
| 6178 | mH.sendMessage(msg); |
| 6179 | } else { |
| 6180 | Slog.w(TAG, "Duplicate remove pending of provider " + prc.holder.info.name); |
| 6181 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6182 | } |
| 6183 | return true; |
| 6184 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6185 | } |
| 6186 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6187 | final void completeRemoveProvider(ProviderRefCount prc) { |
| 6188 | synchronized (mProviderMap) { |
| 6189 | if (!prc.removePending) { |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6190 | // There was a race! Some other client managed to acquire |
| 6191 | // the provider before the removal was completed. |
| 6192 | // Abort the removal. We will do it later. |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6193 | if (DEBUG_PROVIDER) Slog.v(TAG, "completeRemoveProvider: lost the race, " |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6194 | + "provider still in use"); |
| 6195 | return; |
| 6196 | } |
| 6197 | |
Guobin Zhang | 9e3e5266 | 2013-03-21 13:57:11 +0800 | [diff] [blame] | 6198 | // More complicated race!! Some client managed to acquire the |
| 6199 | // provider and release it before the removal was completed. |
| 6200 | // Continue the removal, and abort the next remove message. |
| 6201 | prc.removePending = false; |
| 6202 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6203 | final IBinder jBinder = prc.holder.provider.asBinder(); |
| 6204 | ProviderRefCount existingPrc = mProviderRefCountMap.get(jBinder); |
| 6205 | if (existingPrc == prc) { |
| 6206 | mProviderRefCountMap.remove(jBinder); |
| 6207 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6208 | |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 6209 | for (int i=mProviderMap.size()-1; i>=0; i--) { |
| 6210 | ProviderClientRecord pr = mProviderMap.valueAt(i); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6211 | IBinder myBinder = pr.mProvider.asBinder(); |
| 6212 | if (myBinder == jBinder) { |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 6213 | mProviderMap.removeAt(i); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6214 | } |
| 6215 | } |
| 6216 | } |
| 6217 | |
| 6218 | try { |
| 6219 | if (DEBUG_PROVIDER) { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6220 | Slog.v(TAG, "removeProvider: Invoking ActivityManagerService." |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6221 | + "removeContentProvider(" + prc.holder.info.name + ")"); |
| 6222 | } |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6223 | ActivityManager.getService().removeContentProvider( |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6224 | prc.holder.connection, false); |
| 6225 | } catch (RemoteException e) { |
| 6226 | //do nothing content provider object is dead any way |
| 6227 | } |
| 6228 | } |
| 6229 | |
| 6230 | final void handleUnstableProviderDied(IBinder provider, boolean fromClient) { |
Dianne Hackborn | c428aae | 2012-10-03 16:38:22 -0700 | [diff] [blame] | 6231 | synchronized (mProviderMap) { |
| 6232 | handleUnstableProviderDiedLocked(provider, fromClient); |
| 6233 | } |
| 6234 | } |
| 6235 | |
| 6236 | final void handleUnstableProviderDiedLocked(IBinder provider, boolean fromClient) { |
| 6237 | ProviderRefCount prc = mProviderRefCountMap.get(provider); |
| 6238 | if (prc != null) { |
| 6239 | if (DEBUG_PROVIDER) Slog.v(TAG, "Cleaning up dead provider " |
| 6240 | + provider + " " + prc.holder.info.name); |
| 6241 | mProviderRefCountMap.remove(provider); |
You Kim | bc74de6 | 2013-10-01 00:13:26 +0900 | [diff] [blame] | 6242 | for (int i=mProviderMap.size()-1; i>=0; i--) { |
| 6243 | ProviderClientRecord pr = mProviderMap.valueAt(i); |
| 6244 | if (pr != null && pr.mProvider.asBinder() == provider) { |
| 6245 | Slog.i(TAG, "Removing dead content provider:" + pr.mProvider.toString()); |
| 6246 | mProviderMap.removeAt(i); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6247 | } |
Dianne Hackborn | c428aae | 2012-10-03 16:38:22 -0700 | [diff] [blame] | 6248 | } |
You Kim | bc74de6 | 2013-10-01 00:13:26 +0900 | [diff] [blame] | 6249 | |
Dianne Hackborn | c428aae | 2012-10-03 16:38:22 -0700 | [diff] [blame] | 6250 | if (fromClient) { |
| 6251 | // We found out about this due to execution in our client |
| 6252 | // code. Tell the activity manager about it now, to ensure |
| 6253 | // that the next time we go to do anything with the provider |
| 6254 | // it knows it is dead (so we don't race with its death |
| 6255 | // notification). |
| 6256 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6257 | ActivityManager.getService().unstableProviderDied( |
Dianne Hackborn | c428aae | 2012-10-03 16:38:22 -0700 | [diff] [blame] | 6258 | prc.holder.connection); |
| 6259 | } catch (RemoteException e) { |
| 6260 | //do nothing content provider object is dead any way |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6261 | } |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 6262 | } |
| 6263 | } |
| 6264 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6265 | |
Jeff Sharkey | 7aa7601 | 2013-09-30 14:26:27 -0700 | [diff] [blame] | 6266 | final void appNotRespondingViaProvider(IBinder provider) { |
| 6267 | synchronized (mProviderMap) { |
| 6268 | ProviderRefCount prc = mProviderRefCountMap.get(provider); |
| 6269 | if (prc != null) { |
| 6270 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6271 | ActivityManager.getService() |
Jeff Sharkey | 7aa7601 | 2013-09-30 14:26:27 -0700 | [diff] [blame] | 6272 | .appNotRespondingViaProvider(prc.holder.connection); |
| 6273 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 6274 | throw e.rethrowFromSystemServer(); |
Jeff Sharkey | 7aa7601 | 2013-09-30 14:26:27 -0700 | [diff] [blame] | 6275 | } |
| 6276 | } |
| 6277 | } |
| 6278 | } |
| 6279 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6280 | private ProviderClientRecord installProviderAuthoritiesLocked(IContentProvider provider, |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 6281 | ContentProvider localProvider, ContentProviderHolder holder) { |
Andreas Gampe | 18e99c1 | 2015-03-06 15:29:06 -0800 | [diff] [blame] | 6282 | final String auths[] = holder.info.authority.split(";"); |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 6283 | final int userId = UserHandle.getUserId(holder.info.applicationInfo.uid); |
| 6284 | |
Jeff Sharkey | 0a17db1 | 2016-11-04 11:23:46 -0600 | [diff] [blame] | 6285 | if (provider != null) { |
| 6286 | // If this provider is hosted by the core OS and cannot be upgraded, |
| 6287 | // then I guess we're okay doing blocking calls to it. |
| 6288 | for (String auth : auths) { |
| 6289 | switch (auth) { |
| 6290 | case ContactsContract.AUTHORITY: |
| 6291 | case CallLog.AUTHORITY: |
| 6292 | case CallLog.SHADOW_AUTHORITY: |
| 6293 | case BlockedNumberContract.AUTHORITY: |
| 6294 | case CalendarContract.AUTHORITY: |
| 6295 | case Downloads.Impl.AUTHORITY: |
Jeff Sharkey | cb62162 | 2016-11-11 14:04:32 -0700 | [diff] [blame] | 6296 | case "telephony": |
Jeff Sharkey | 0a17db1 | 2016-11-04 11:23:46 -0600 | [diff] [blame] | 6297 | Binder.allowBlocking(provider.asBinder()); |
| 6298 | } |
| 6299 | } |
| 6300 | } |
| 6301 | |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 6302 | final ProviderClientRecord pcr = new ProviderClientRecord( |
| 6303 | auths, provider, localProvider, holder); |
| 6304 | for (String auth : auths) { |
| 6305 | final ProviderKey key = new ProviderKey(auth, userId); |
| 6306 | final ProviderClientRecord existing = mProviderMap.get(key); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6307 | if (existing != null) { |
| 6308 | Slog.w(TAG, "Content provider " + pcr.mHolder.info.name |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 6309 | + " already published as " + auth); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6310 | } else { |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 6311 | mProviderMap.put(key, pcr); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6312 | } |
| 6313 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6314 | return pcr; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6315 | } |
| 6316 | |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6317 | /** |
| 6318 | * Installs the provider. |
| 6319 | * |
| 6320 | * Providers that are local to the process or that come from the system server |
| 6321 | * may be installed permanently which is indicated by setting noReleaseNeeded to true. |
| 6322 | * Other remote providers are reference counted. The initial reference count |
| 6323 | * for all reference counted providers is one. Providers that are not reference |
| 6324 | * counted do not have a reference count (at all). |
| 6325 | * |
| 6326 | * This method detects when a provider has already been installed. When this happens, |
| 6327 | * it increments the reference count of the existing provider (if appropriate) |
| 6328 | * and returns the existing provider. This can happen due to concurrent |
| 6329 | * attempts to acquire the same provider. |
| 6330 | */ |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 6331 | private ContentProviderHolder installProvider(Context context, |
| 6332 | ContentProviderHolder holder, ProviderInfo info, |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6333 | boolean noisy, boolean noReleaseNeeded, boolean stable) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6334 | ContentProvider localProvider = null; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6335 | IContentProvider provider; |
Dianne Hackborn | 5f48fca | 2012-05-30 11:06:31 -0700 | [diff] [blame] | 6336 | if (holder == null || holder.provider == null) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6337 | if (DEBUG_PROVIDER || noisy) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 6338 | Slog.d(TAG, "Loading provider " + info.authority + ": " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6339 | + info.name); |
| 6340 | } |
| 6341 | Context c = null; |
| 6342 | ApplicationInfo ai = info.applicationInfo; |
| 6343 | if (context.getPackageName().equals(ai.packageName)) { |
| 6344 | c = context; |
| 6345 | } else if (mInitialApplication != null && |
| 6346 | mInitialApplication.getPackageName().equals(ai.packageName)) { |
| 6347 | c = mInitialApplication; |
| 6348 | } else { |
| 6349 | try { |
| 6350 | c = context.createPackageContext(ai.packageName, |
| 6351 | Context.CONTEXT_INCLUDE_CODE); |
| 6352 | } catch (PackageManager.NameNotFoundException e) { |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 6353 | // Ignore |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6354 | } |
| 6355 | } |
| 6356 | if (c == null) { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 6357 | Slog.w(TAG, "Unable to get context for package " + |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6358 | ai.packageName + |
| 6359 | " while loading content provider " + |
| 6360 | info.name); |
| 6361 | return null; |
| 6362 | } |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 6363 | |
| 6364 | if (info.splitName != null) { |
| 6365 | try { |
| 6366 | c = c.createContextForSplit(info.splitName); |
| 6367 | } catch (NameNotFoundException e) { |
| 6368 | throw new RuntimeException(e); |
| 6369 | } |
| 6370 | } |
| 6371 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6372 | try { |
| 6373 | final java.lang.ClassLoader cl = c.getClassLoader(); |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 6374 | LoadedApk packageInfo = peekPackageInfo(ai.packageName, true); |
| 6375 | if (packageInfo == null) { |
Jason Monk | a80bfb5 | 2017-11-16 17:15:37 -0500 | [diff] [blame] | 6376 | // System startup case. |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 6377 | packageInfo = getSystemContext().mPackageInfo; |
Jason Monk | a80bfb5 | 2017-11-16 17:15:37 -0500 | [diff] [blame] | 6378 | } |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 6379 | localProvider = packageInfo.getAppFactory() |
Jason Monk | a80bfb5 | 2017-11-16 17:15:37 -0500 | [diff] [blame] | 6380 | .instantiateProvider(cl, info.name); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6381 | provider = localProvider.getIContentProvider(); |
| 6382 | if (provider == null) { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 6383 | Slog.e(TAG, "Failed to instantiate class " + |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6384 | info.name + " from sourceDir " + |
| 6385 | info.applicationInfo.sourceDir); |
| 6386 | return null; |
| 6387 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6388 | if (DEBUG_PROVIDER) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6389 | TAG, "Instantiating local provider " + info.name); |
| 6390 | // XXX Need to create the correct context for this provider. |
| 6391 | localProvider.attachInfo(c, info); |
| 6392 | } catch (java.lang.Exception e) { |
| 6393 | if (!mInstrumentation.onException(null, e)) { |
| 6394 | throw new RuntimeException( |
| 6395 | "Unable to get provider " + info.name |
| 6396 | + ": " + e.toString(), e); |
| 6397 | } |
| 6398 | return null; |
| 6399 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6400 | } else { |
| 6401 | provider = holder.provider; |
| 6402 | 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] | 6403 | + info.name); |
| 6404 | } |
| 6405 | |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 6406 | ContentProviderHolder retHolder; |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6407 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6408 | synchronized (mProviderMap) { |
| 6409 | if (DEBUG_PROVIDER) Slog.v(TAG, "Checking to add " + provider |
| 6410 | + " / " + info.name); |
| 6411 | IBinder jBinder = provider.asBinder(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6412 | if (localProvider != null) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6413 | ComponentName cname = new ComponentName(info.packageName, info.name); |
| 6414 | ProviderClientRecord pr = mLocalProvidersByName.get(cname); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6415 | if (pr != null) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6416 | if (DEBUG_PROVIDER) { |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6417 | Slog.v(TAG, "installProvider: lost the race, " |
| 6418 | + "using existing local provider"); |
| 6419 | } |
| 6420 | provider = pr.mProvider; |
| 6421 | } else { |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 6422 | holder = new ContentProviderHolder(info); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6423 | holder.provider = provider; |
| 6424 | holder.noReleaseNeeded = true; |
| 6425 | pr = installProviderAuthoritiesLocked(provider, localProvider, holder); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6426 | mLocalProviders.put(jBinder, pr); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6427 | mLocalProvidersByName.put(cname, pr); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6428 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6429 | retHolder = pr.mHolder; |
| 6430 | } else { |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6431 | ProviderRefCount prc = mProviderRefCountMap.get(jBinder); |
| 6432 | if (prc != null) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6433 | if (DEBUG_PROVIDER) { |
| 6434 | Slog.v(TAG, "installProvider: lost the race, updating ref count"); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6435 | } |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 6436 | // We need to transfer our new reference to the existing |
| 6437 | // ref count, releasing the old one... but only if |
| 6438 | // release is needed (that is, it is not running in the |
| 6439 | // system process). |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6440 | if (!noReleaseNeeded) { |
| 6441 | incProviderRefLocked(prc, stable); |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 6442 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6443 | ActivityManager.getService().removeContentProvider( |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 6444 | holder.connection, stable); |
| 6445 | } catch (RemoteException e) { |
| 6446 | //do nothing content provider object is dead any way |
| 6447 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6448 | } |
| 6449 | } else { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6450 | ProviderClientRecord client = installProviderAuthoritiesLocked( |
| 6451 | provider, localProvider, holder); |
| 6452 | if (noReleaseNeeded) { |
| 6453 | prc = new ProviderRefCount(holder, client, 1000, 1000); |
| 6454 | } else { |
| 6455 | prc = stable |
| 6456 | ? new ProviderRefCount(holder, client, 1, 0) |
| 6457 | : new ProviderRefCount(holder, client, 0, 1); |
| 6458 | } |
| 6459 | mProviderRefCountMap.put(jBinder, prc); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6460 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6461 | retHolder = prc.holder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6462 | } |
| 6463 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6464 | return retHolder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6465 | } |
| 6466 | |
Torne (Richard Coles) | 466cbe4 | 2017-05-31 14:09:14 -0400 | [diff] [blame] | 6467 | private void handleRunIsolatedEntryPoint(String entryPoint, String[] entryPointArgs) { |
| 6468 | try { |
| 6469 | Method main = Class.forName(entryPoint).getMethod("main", String[].class); |
| 6470 | main.invoke(null, new Object[]{entryPointArgs}); |
| 6471 | } catch (ReflectiveOperationException e) { |
| 6472 | throw new AndroidRuntimeException("runIsolatedEntryPoint failed", e); |
| 6473 | } |
| 6474 | // The process will be empty after this method returns; exit the VM now. |
| 6475 | System.exit(0); |
| 6476 | } |
| 6477 | |
Sudheer Shanka | f669010 | 2017-10-16 10:20:32 -0700 | [diff] [blame] | 6478 | private void attach(boolean system, long startSeq) { |
Jeff Sharkey | 66a017b | 2013-01-17 18:18:22 -0800 | [diff] [blame] | 6479 | sCurrentActivityThread = this; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6480 | mSystemThread = system; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6481 | if (!system) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 6482 | ViewRootImpl.addFirstDrawHandler(new Runnable() { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 6483 | @Override |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 6484 | public void run() { |
| 6485 | ensureJitEnabled(); |
| 6486 | } |
| 6487 | }); |
Siva Velusamy | d693dfa | 2012-09-10 14:36:58 -0700 | [diff] [blame] | 6488 | android.ddm.DdmHandleAppName.setAppName("<pre-initialized>", |
| 6489 | UserHandle.myUserId()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6490 | RuntimeInit.setApplicationObject(mAppThread.asBinder()); |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6491 | final IActivityManager mgr = ActivityManager.getService(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6492 | try { |
Sudheer Shanka | f669010 | 2017-10-16 10:20:32 -0700 | [diff] [blame] | 6493 | mgr.attachApplication(mAppThread, startSeq); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6494 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 6495 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6496 | } |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 6497 | // Watch for getting close to heap limit. |
| 6498 | BinderInternal.addGcWatcher(new Runnable() { |
| 6499 | @Override public void run() { |
| 6500 | if (!mSomeActivitiesChanged) { |
| 6501 | return; |
| 6502 | } |
| 6503 | Runtime runtime = Runtime.getRuntime(); |
| 6504 | long dalvikMax = runtime.maxMemory(); |
| 6505 | long dalvikUsed = runtime.totalMemory() - runtime.freeMemory(); |
| 6506 | if (dalvikUsed > ((3*dalvikMax)/4)) { |
| 6507 | if (DEBUG_MEMORY_TRIM) Slog.d(TAG, "Dalvik max=" + (dalvikMax/1024) |
| 6508 | + " total=" + (runtime.totalMemory()/1024) |
| 6509 | + " used=" + (dalvikUsed/1024)); |
| 6510 | mSomeActivitiesChanged = false; |
| 6511 | try { |
| 6512 | mgr.releaseSomeActivities(mAppThread); |
| 6513 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 6514 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 6515 | } |
| 6516 | } |
| 6517 | } |
| 6518 | }); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6519 | } else { |
| 6520 | // Don't set application object here -- if the system crashes, |
| 6521 | // 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] | 6522 | android.ddm.DdmHandleAppName.setAppName("system_process", |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 6523 | UserHandle.myUserId()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6524 | try { |
| 6525 | mInstrumentation = new Instrumentation(); |
Jason Monk | a80bfb5 | 2017-11-16 17:15:37 -0500 | [diff] [blame] | 6526 | mInstrumentation.basicInit(this); |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 6527 | ContextImpl context = ContextImpl.createAppContext( |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 6528 | this, getSystemContext().mPackageInfo); |
| 6529 | mInitialApplication = context.mPackageInfo.makeApplication(true, null); |
Jeff Brown | 7fc8e35 | 2014-09-16 18:06:47 -0700 | [diff] [blame] | 6530 | mInitialApplication.onCreate(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6531 | } catch (Exception e) { |
| 6532 | throw new RuntimeException( |
| 6533 | "Unable to instantiate Application():" + e.toString(), e); |
| 6534 | } |
| 6535 | } |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 6536 | |
| 6537 | // add dropbox logging to libcore |
| 6538 | DropBox.setReporter(new DropBoxReporter()); |
| 6539 | |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 6540 | ViewRootImpl.ConfigChangedCallback configChangedCallback |
| 6541 | = (Configuration globalConfig) -> { |
| 6542 | synchronized (mResourcesManager) { |
| 6543 | // We need to apply this change to the resources immediately, because upon returning |
| 6544 | // the view hierarchy will be informed about it. |
| 6545 | if (mResourcesManager.applyConfigurationToResourcesLocked(globalConfig, |
| 6546 | null /* compat */)) { |
| 6547 | updateLocaleListFromAppContext(mInitialApplication.getApplicationContext(), |
| 6548 | mResourcesManager.getConfiguration().getLocales()); |
Adam Lesinski | b61e405 | 2016-05-19 18:23:05 -0700 | [diff] [blame] | 6549 | |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 6550 | // This actually changed the resources! Tell everyone about it. |
| 6551 | if (mPendingConfiguration == null |
| 6552 | || mPendingConfiguration.isOtherSeqNewer(globalConfig)) { |
| 6553 | mPendingConfiguration = globalConfig; |
| 6554 | sendMessage(H.CONFIGURATION_CHANGED, globalConfig); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6555 | } |
| 6556 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6557 | } |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 6558 | }; |
| 6559 | ViewRootImpl.addConfigCallback(configChangedCallback); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6560 | } |
| 6561 | |
Romain Guy | 5e9120d | 2012-01-30 12:17:22 -0800 | [diff] [blame] | 6562 | public static ActivityThread systemMain() { |
Alan Viverette | 5e1565e | 2014-07-29 16:14:25 -0700 | [diff] [blame] | 6563 | // The system process on low-memory devices do not get to use hardware |
| 6564 | // accelerated drawing, since this can add too much overhead to the |
| 6565 | // process. |
| 6566 | if (!ActivityManager.isHighEndGfx()) { |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 6567 | ThreadedRenderer.disable(true); |
John Reck | 73840ea | 2014-09-22 07:39:18 -0700 | [diff] [blame] | 6568 | } else { |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 6569 | ThreadedRenderer.enableForegroundTrimming(); |
Alan Viverette | 5e1565e | 2014-07-29 16:14:25 -0700 | [diff] [blame] | 6570 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6571 | ActivityThread thread = new ActivityThread(); |
Sudheer Shanka | f669010 | 2017-10-16 10:20:32 -0700 | [diff] [blame] | 6572 | thread.attach(true, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6573 | return thread; |
| 6574 | } |
| 6575 | |
Jeff Brown | 10e8971 | 2011-07-08 18:52:57 -0700 | [diff] [blame] | 6576 | public final void installSystemProviders(List<ProviderInfo> providers) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6577 | if (providers != null) { |
Jeff Brown | 10e8971 | 2011-07-08 18:52:57 -0700 | [diff] [blame] | 6578 | installContentProviders(mInitialApplication, providers); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6579 | } |
| 6580 | } |
| 6581 | |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 6582 | public int getIntCoreSetting(String key, int defaultValue) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 6583 | synchronized (mResourcesManager) { |
Svetoslav Ganov | 9aa597e | 2011-03-03 18:17:41 -0800 | [diff] [blame] | 6584 | if (mCoreSettings != null) { |
| 6585 | return mCoreSettings.getInt(key, defaultValue); |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 6586 | } |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 6587 | return defaultValue; |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 6588 | } |
| 6589 | } |
| 6590 | |
Geremy Condra | 69689a7 | 2012-09-11 16:57:17 -0700 | [diff] [blame] | 6591 | private static class EventLoggingReporter implements EventLogger.Reporter { |
| 6592 | @Override |
| 6593 | public void report (int code, Object... list) { |
| 6594 | EventLog.writeEvent(code, list); |
| 6595 | } |
| 6596 | } |
| 6597 | |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 6598 | private class DropBoxReporter implements DropBox.Reporter { |
| 6599 | |
| 6600 | private DropBoxManager dropBox; |
| 6601 | |
Narayan Kamath | 7f06224 | 2015-04-08 13:24:13 +0100 | [diff] [blame] | 6602 | public DropBoxReporter() {} |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 6603 | |
| 6604 | @Override |
| 6605 | public void addData(String tag, byte[] data, int flags) { |
Narayan Kamath | 7f06224 | 2015-04-08 13:24:13 +0100 | [diff] [blame] | 6606 | ensureInitialized(); |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 6607 | dropBox.addData(tag, data, flags); |
| 6608 | } |
| 6609 | |
| 6610 | @Override |
| 6611 | public void addText(String tag, String data) { |
Narayan Kamath | 7f06224 | 2015-04-08 13:24:13 +0100 | [diff] [blame] | 6612 | ensureInitialized(); |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 6613 | dropBox.addText(tag, data); |
| 6614 | } |
Narayan Kamath | 7f06224 | 2015-04-08 13:24:13 +0100 | [diff] [blame] | 6615 | |
| 6616 | private synchronized void ensureInitialized() { |
| 6617 | if (dropBox == null) { |
| 6618 | dropBox = (DropBoxManager) getSystemContext().getSystemService(Context.DROPBOX_SERVICE); |
| 6619 | } |
| 6620 | } |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 6621 | } |
| 6622 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 6623 | public static void main(String[] args) { |
Narayan Kamath | fbb32f6 | 2015-06-12 15:34:35 +0100 | [diff] [blame] | 6624 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "ActivityThreadMain"); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 6625 | |
Brad Fitzpatrick | 4d9e6d2 | 2010-11-15 08:49:51 -0800 | [diff] [blame] | 6626 | // CloseGuard defaults to true and can be quite spammy. We |
| 6627 | // disable it here, but selectively enable it later (via |
| 6628 | // StrictMode) on debug builds, but using DropBox, not logs. |
| 6629 | CloseGuard.setEnabled(false); |
| 6630 | |
Andreas Gampe | d281b42 | 2016-07-08 03:50:27 +0000 | [diff] [blame] | 6631 | Environment.initForCurrentUser(); |
Jeff Sharkey | b049e21 | 2012-09-07 23:16:01 -0700 | [diff] [blame] | 6632 | |
Geremy Condra | 69689a7 | 2012-09-11 16:57:17 -0700 | [diff] [blame] | 6633 | // Set the reporter for event logging in libcore |
| 6634 | EventLogger.setReporter(new EventLoggingReporter()); |
| 6635 | |
Robin Lee | 3d076af | 2014-04-25 14:57:49 +0100 | [diff] [blame] | 6636 | // Make sure TrustedCertificateStore looks in the right place for CA certificates |
| 6637 | final File configDir = Environment.getUserConfigDirectory(UserHandle.myUserId()); |
| 6638 | TrustedCertificateStore.setDefaultUserDirectory(configDir); |
| 6639 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6640 | Process.setArgV0("<pre-initialized>"); |
| 6641 | |
| 6642 | Looper.prepareMainLooper(); |
| 6643 | |
Sudheer Shanka | f669010 | 2017-10-16 10:20:32 -0700 | [diff] [blame] | 6644 | // Find the value for {@link #PROC_START_SEQ_IDENT} if provided on the command line. |
| 6645 | // It will be in the format "seq=114" |
| 6646 | long startSeq = 0; |
| 6647 | if (args != null) { |
| 6648 | for (int i = args.length - 1; i >= 0; --i) { |
| 6649 | if (args[i] != null && args[i].startsWith(PROC_START_SEQ_IDENT)) { |
| 6650 | startSeq = Long.parseLong( |
| 6651 | args[i].substring(PROC_START_SEQ_IDENT.length())); |
| 6652 | } |
| 6653 | } |
| 6654 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6655 | ActivityThread thread = new ActivityThread(); |
Sudheer Shanka | f669010 | 2017-10-16 10:20:32 -0700 | [diff] [blame] | 6656 | thread.attach(false, startSeq); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6657 | |
Vairavan Srinivasan | 7335cfd | 2012-08-18 18:36:03 -0700 | [diff] [blame] | 6658 | if (sMainThreadHandler == null) { |
| 6659 | sMainThreadHandler = thread.getHandler(); |
| 6660 | } |
| 6661 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6662 | if (false) { |
| 6663 | Looper.myLooper().setMessageLogging(new |
| 6664 | LogPrinter(Log.DEBUG, "ActivityThread")); |
| 6665 | } |
| 6666 | |
Narayan Kamath | fbb32f6 | 2015-06-12 15:34:35 +0100 | [diff] [blame] | 6667 | // End of event ActivityThreadMain. |
| 6668 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6669 | Looper.loop(); |
| 6670 | |
Jeff Brown | 10e8971 | 2011-07-08 18:52:57 -0700 | [diff] [blame] | 6671 | throw new RuntimeException("Main thread loop unexpectedly exited"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6672 | } |
Chris Craik | fc29424 | 2016-12-13 18:10:46 -0800 | [diff] [blame] | 6673 | |
| 6674 | // ------------------ Regular JNI ------------------------ |
| 6675 | |
| 6676 | private native void nDumpGraphicsInfo(FileDescriptor fd); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6677 | } |