The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.app; |
| 18 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 19 | import static android.app.servertransaction.ActivityLifecycleItem.ON_CREATE; |
| 20 | import static android.app.servertransaction.ActivityLifecycleItem.ON_DESTROY; |
| 21 | import static android.app.servertransaction.ActivityLifecycleItem.ON_PAUSE; |
| 22 | import static android.app.servertransaction.ActivityLifecycleItem.ON_RESUME; |
| 23 | import static android.app.servertransaction.ActivityLifecycleItem.ON_START; |
| 24 | import static android.app.servertransaction.ActivityLifecycleItem.ON_STOP; |
| 25 | import static android.app.servertransaction.ActivityLifecycleItem.PRE_ON_CREATE; |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 26 | import static android.view.Display.INVALID_DISPLAY; |
| 27 | |
Adam Lesinski | c1b0ebf | 2016-06-09 11:17:10 -0700 | [diff] [blame] | 28 | import android.annotation.NonNull; |
| 29 | import android.annotation.Nullable; |
Dianne Hackborn | 69c6adc | 2015-06-02 10:52:59 -0700 | [diff] [blame] | 30 | import android.app.assist.AssistContent; |
| 31 | import android.app.assist.AssistStructure; |
Christopher Tate | 4528186 | 2010-03-05 15:46:30 -0800 | [diff] [blame] | 32 | import android.app.backup.BackupAgent; |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 33 | import android.app.servertransaction.ActivityLifecycleItem.LifecycleState; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 34 | import android.app.servertransaction.ActivityResultItem; |
| 35 | import android.app.servertransaction.ClientTransaction; |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 36 | import android.app.servertransaction.PendingTransactionActions; |
| 37 | import android.app.servertransaction.PendingTransactionActions.StopInfo; |
| 38 | import android.app.servertransaction.TransactionExecutor; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | import android.content.BroadcastReceiver; |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 40 | import android.content.ComponentCallbacks2; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | import android.content.ComponentName; |
| 42 | import android.content.ContentProvider; |
| 43 | import android.content.Context; |
| 44 | import android.content.IContentProvider; |
Suchi Amalapurapu | 1ccac75 | 2009-06-12 10:09:58 -0700 | [diff] [blame] | 45 | import android.content.IIntentReceiver; |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 46 | import android.content.Intent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | import android.content.pm.ActivityInfo; |
| 48 | import android.content.pm.ApplicationInfo; |
| 49 | import android.content.pm.IPackageManager; |
| 50 | import android.content.pm.InstrumentationInfo; |
Christopher Tate | 346acb1 | 2012-10-15 19:20:25 -0700 | [diff] [blame] | 51 | import android.content.pm.PackageInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | import android.content.pm.PackageManager; |
Sen Hu | bde7570 | 2010-05-28 01:54:03 -0700 | [diff] [blame] | 53 | import android.content.pm.PackageManager.NameNotFoundException; |
Dianne Hackborn | 3f7c9f2 | 2017-04-04 15:36:33 -0700 | [diff] [blame] | 54 | import android.content.pm.ParceledListSlice; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | import android.content.pm.ProviderInfo; |
| 56 | import android.content.pm.ServiceInfo; |
| 57 | import android.content.res.AssetManager; |
Mitsuru Oshima | ba3ba57 | 2009-07-08 18:49:26 -0700 | [diff] [blame] | 58 | import android.content.res.CompatibilityInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 59 | import android.content.res.Configuration; |
| 60 | import android.content.res.Resources; |
Alan Viverette | e54d245 | 2015-05-06 10:41:43 -0700 | [diff] [blame] | 61 | import android.content.res.Resources.Theme; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | import android.database.sqlite.SQLiteDatabase; |
| 63 | import android.database.sqlite.SQLiteDebug; |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 64 | import android.database.sqlite.SQLiteDebug.DbStats; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 65 | import android.graphics.Bitmap; |
| 66 | import android.graphics.Canvas; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 67 | import android.hardware.display.DisplayManagerGlobal; |
Paul Jensen | e0bef71 | 2014-12-10 15:12:18 -0500 | [diff] [blame] | 68 | import android.net.ConnectivityManager; |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 69 | import android.net.IConnectivityManager; |
Paul Jensen | e0bef71 | 2014-12-10 15:12:18 -0500 | [diff] [blame] | 70 | import android.net.Network; |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 71 | import android.net.Proxy; |
Jason Monk | 207900c | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 72 | import android.net.ProxyInfo; |
Jason Monk | 83520b9 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 73 | import android.net.Uri; |
Joe Onorato | d630f10 | 2011-03-17 18:42:26 -0700 | [diff] [blame] | 74 | import android.os.AsyncTask; |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 75 | import android.os.Binder; |
Jeff Sharkey | 344744b | 2016-01-28 19:03:30 -0700 | [diff] [blame] | 76 | import android.os.Build; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 77 | import android.os.Bundle; |
| 78 | import android.os.Debug; |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 79 | import android.os.DropBoxManager; |
Jeff Sharkey | b049e21 | 2012-09-07 23:16:01 -0700 | [diff] [blame] | 80 | import android.os.Environment; |
Jesse Hall | b12249b | 2016-12-12 12:53:02 -0800 | [diff] [blame] | 81 | import android.os.GraphicsEnvironment; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 82 | import android.os.Handler; |
Jeff Sharkey | 8439ac0 | 2017-12-12 17:26:23 -0700 | [diff] [blame] | 83 | import android.os.HandlerExecutor; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 84 | import android.os.IBinder; |
Adam Lesinski | b61e405 | 2016-05-19 18:23:05 -0700 | [diff] [blame] | 85 | import android.os.LocaleList; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 86 | import android.os.Looper; |
| 87 | import android.os.Message; |
| 88 | import android.os.MessageQueue; |
Dianne Hackborn | fabb70b | 2014-11-11 12:22:36 -0800 | [diff] [blame] | 89 | import android.os.Parcel; |
Dianne Hackborn | 9c8dd55 | 2009-06-23 19:22:52 -0700 | [diff] [blame] | 90 | import android.os.ParcelFileDescriptor; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 91 | import android.os.PersistableBundle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 92 | import android.os.Process; |
| 93 | import android.os.RemoteException; |
| 94 | import android.os.ServiceManager; |
Brad Fitzpatrick | 438d059 | 2010-06-10 12:19:19 -0700 | [diff] [blame] | 95 | import android.os.StrictMode; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 96 | import android.os.SystemClock; |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 97 | import android.os.SystemProperties; |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 98 | import android.os.Trace; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 99 | import android.os.UserHandle; |
Jeff Sharkey | 0a17db1 | 2016-11-04 11:23:46 -0600 | [diff] [blame] | 100 | import android.provider.BlockedNumberContract; |
| 101 | import android.provider.CalendarContract; |
| 102 | import android.provider.CallLog; |
| 103 | import android.provider.ContactsContract; |
| 104 | import android.provider.Downloads; |
Seigo Nonaka | 54084b6 | 2017-04-24 14:46:23 -0700 | [diff] [blame] | 105 | import android.provider.FontsContract; |
Narayan Kamath | ccb2a086 | 2013-12-19 14:49:36 +0000 | [diff] [blame] | 106 | import android.provider.Settings; |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 107 | import android.renderscript.RenderScriptCacheDir; |
Chad Brubaker | c72875b | 2016-04-27 16:35:11 -0700 | [diff] [blame] | 108 | import android.security.NetworkSecurityPolicy; |
Chad Brubaker | 78d4712 | 2015-11-17 22:26:58 -0800 | [diff] [blame] | 109 | import android.security.net.config.NetworkSecurityConfigProvider; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 110 | import android.util.AndroidRuntimeException; |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 111 | import android.util.ArrayMap; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 112 | import android.util.DisplayMetrics; |
| 113 | import android.util.EventLog; |
| 114 | import android.util.Log; |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 115 | import android.util.LogPrinter; |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 116 | import android.util.Pair; |
Jeff Brown | 6754ba2 | 2011-12-14 20:20:01 -0800 | [diff] [blame] | 117 | import android.util.PrintWriterPrinter; |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 118 | import android.util.Slog; |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 119 | import android.util.SparseIntArray; |
Adam Powell | 1487466 | 2013-07-18 19:42:41 -0700 | [diff] [blame] | 120 | import android.util.SuperNotCalledException; |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 121 | import android.util.proto.ProtoOutputStream; |
Adam Lesinski | 3ad1b48 | 2016-04-01 16:41:41 -0700 | [diff] [blame] | 122 | import android.view.ContextThemeWrapper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 123 | import android.view.Display; |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 124 | import android.view.ThreadedRenderer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 125 | import android.view.View; |
| 126 | import android.view.ViewDebug; |
| 127 | import android.view.ViewManager; |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 128 | import android.view.ViewRootImpl; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 129 | import android.view.Window; |
| 130 | import android.view.WindowManager; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 131 | import android.view.WindowManagerGlobal; |
Richard Uhler | 2c03619 | 2016-09-14 09:48:31 +0100 | [diff] [blame] | 132 | import android.webkit.WebView; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 133 | |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 134 | import com.android.internal.annotations.GuardedBy; |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 135 | import com.android.internal.annotations.VisibleForTesting; |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 136 | import com.android.internal.app.IVoiceInteractor; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 137 | import com.android.internal.content.ReferrerIntent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 138 | import com.android.internal.os.BinderInternal; |
| 139 | import com.android.internal.os.RuntimeInit; |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 140 | import com.android.internal.os.SomeArgs; |
Jeff Sharkey | 3e19589 | 2016-03-05 19:48:59 -0700 | [diff] [blame] | 141 | import com.android.internal.util.ArrayUtils; |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 142 | import com.android.internal.util.FastPrintWriter; |
Kenny Root | 12e7522 | 2013-04-23 22:34:24 -0700 | [diff] [blame] | 143 | import com.android.org.conscrypt.OpenSSLSocketImpl; |
Robin Lee | 3d076af | 2014-04-25 14:57:49 +0100 | [diff] [blame] | 144 | import com.android.org.conscrypt.TrustedCertificateStore; |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 145 | import com.android.server.am.proto.MemInfoProto; |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 146 | |
| 147 | import dalvik.system.BaseDexClassLoader; |
| 148 | import dalvik.system.CloseGuard; |
| 149 | import dalvik.system.VMDebug; |
| 150 | import dalvik.system.VMRuntime; |
| 151 | |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 152 | import libcore.io.DropBox; |
| 153 | import libcore.io.EventLogger; |
| 154 | import libcore.io.IoUtils; |
| 155 | import libcore.net.event.NetworkEventDispatcher; |
| 156 | |
| 157 | import org.apache.harmony.dalvik.ddmc.DdmVmInternal; |
| 158 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 159 | import java.io.File; |
| 160 | import java.io.FileDescriptor; |
| 161 | import java.io.FileOutputStream; |
Dianne Hackborn | 9c8dd55 | 2009-06-23 19:22:52 -0700 | [diff] [blame] | 162 | import java.io.IOException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 163 | import java.io.PrintWriter; |
| 164 | import java.lang.ref.WeakReference; |
Svet Ganov | 37e4327 | 2016-09-09 16:01:32 -0700 | [diff] [blame] | 165 | import java.lang.reflect.Field; |
Torne (Richard Coles) | 466cbe4 | 2017-05-31 14:09:14 -0400 | [diff] [blame] | 166 | import java.lang.reflect.Method; |
Robert Greenwalt | 03595d0 | 2010-11-02 14:08:23 -0700 | [diff] [blame] | 167 | import java.net.InetAddress; |
Narayan Kamath | ccb2a086 | 2013-12-19 14:49:36 +0000 | [diff] [blame] | 168 | import java.text.DateFormat; |
Bryce Lee | d946f86 | 2018-01-16 15:59:47 -0800 | [diff] [blame] | 169 | import java.util.ArrayDeque; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 170 | import java.util.ArrayList; |
Jeff Sharkey | a6bfeae | 2017-07-05 16:50:24 -0600 | [diff] [blame] | 171 | import java.util.Arrays; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 172 | import java.util.List; |
Adam Lesinski | b61e405 | 2016-05-19 18:23:05 -0700 | [diff] [blame] | 173 | import java.util.Locale; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 174 | import java.util.Map; |
Kenny Root | e6585b3 | 2013-12-13 12:00:26 -0800 | [diff] [blame] | 175 | import java.util.Objects; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 176 | import java.util.TimeZone; |
Jeff Sharkey | 8439ac0 | 2017-12-12 17:26:23 -0700 | [diff] [blame] | 177 | import java.util.concurrent.Executor; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 178 | |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 179 | final class RemoteServiceException extends AndroidRuntimeException { |
| 180 | public RemoteServiceException(String msg) { |
| 181 | super(msg); |
| 182 | } |
| 183 | } |
| 184 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 185 | /** |
| 186 | * This manages the execution of the main thread in an |
| 187 | * application process, scheduling and executing activities, |
| 188 | * broadcasts, and other operations on it as the activity |
| 189 | * manager requests. |
| 190 | * |
| 191 | * {@hide} |
| 192 | */ |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 193 | public final class ActivityThread extends ClientTransactionHandler { |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 194 | /** @hide */ |
| 195 | public static final String TAG = "ActivityThread"; |
Jim Miller | 0b2a6d0 | 2010-07-13 18:01:29 -0700 | [diff] [blame] | 196 | 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] | 197 | static final boolean localLOGV = false; |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 198 | static final boolean DEBUG_MESSAGES = false; |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 199 | /** @hide */ |
| 200 | public static final boolean DEBUG_BROADCAST = false; |
Chris Tate | 8a7dc17 | 2009-03-24 20:11:42 -0700 | [diff] [blame] | 201 | private static final boolean DEBUG_RESULTS = false; |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 202 | private static final boolean DEBUG_BACKUP = false; |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 203 | public static final boolean DEBUG_CONFIGURATION = false; |
Dianne Hackborn | a0c283e | 2012-02-09 10:47:01 -0800 | [diff] [blame] | 204 | private static final boolean DEBUG_SERVICE = false; |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 205 | public static final boolean DEBUG_MEMORY_TRIM = false; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 206 | private static final boolean DEBUG_PROVIDER = false; |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 207 | private static final boolean DEBUG_ORDER = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 208 | 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] | 209 | private static final int SQLITE_MEM_RELEASED_EVENT_LOG_TAG = 75003; |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 210 | private static final int LOG_AM_ON_PAUSE_CALLED = 30021; |
| 211 | private static final int LOG_AM_ON_RESUME_CALLED = 30022; |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 212 | private static final int LOG_AM_ON_STOP_CALLED = 30049; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 213 | |
Dianne Hackborn | 455625e | 2015-01-21 09:55:13 -0800 | [diff] [blame] | 214 | /** Type for IActivityManager.serviceDoneExecuting: anonymous operation */ |
| 215 | public static final int SERVICE_DONE_EXECUTING_ANON = 0; |
| 216 | /** Type for IActivityManager.serviceDoneExecuting: done with an onStart call */ |
| 217 | public static final int SERVICE_DONE_EXECUTING_START = 1; |
| 218 | /** Type for IActivityManager.serviceDoneExecuting: done stopping (destroying) service */ |
| 219 | public static final int SERVICE_DONE_EXECUTING_STOP = 2; |
| 220 | |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 221 | // Whether to invoke an activity callback after delivering new configuration. |
| 222 | private static final boolean REPORT_TO_ACTIVITY = true; |
| 223 | |
Bryce Lee | d946f86 | 2018-01-16 15:59:47 -0800 | [diff] [blame] | 224 | // Maximum number of recent tokens to maintain for debugging purposes |
| 225 | private static final int MAX_RECENT_TOKENS = 10; |
| 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<>(); |
Bryce Lee | d946f86 | 2018-01-16 15:59:47 -0800 | [diff] [blame] | 259 | final ArrayDeque<Integer> mRecentTokens = new ArrayDeque<>(); |
| 260 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 261 | // List of new activities (via ActivityRecord.nextIdle) that should |
| 262 | // be reported when next we idle. |
| 263 | ActivityClientRecord mNewActivities = null; |
| 264 | // Number of activities that are currently visible on-screen. |
| 265 | int mNumVisibleActivities = 0; |
Amith Yamasani | 4f128e4 | 2016-05-10 11:44:12 -0700 | [diff] [blame] | 266 | ArrayList<WeakReference<AssistStructure>> mLastAssistStructures = new ArrayList<>(); |
| 267 | private int mLastSessionId; |
Dianne Hackborn | 782d498 | 2015-07-08 17:36:37 -0700 | [diff] [blame] | 268 | final ArrayMap<IBinder, Service> mServices = new ArrayMap<>(); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 269 | AppBindData mBoundApplication; |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 270 | Profiler mProfiler; |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 271 | int mCurDefaultDisplayDpi; |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 272 | boolean mDensityCompatMode; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 273 | Configuration mConfiguration; |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 274 | Configuration mCompatConfiguration; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 275 | Application mInitialApplication; |
| 276 | final ArrayList<Application> mAllApplications |
| 277 | = new ArrayList<Application>(); |
| 278 | // set of instantiated backup agents, keyed by package name |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 279 | final ArrayMap<String, BackupAgent> mBackupAgents = new ArrayMap<String, BackupAgent>(); |
Jeff Sharkey | 66a017b | 2013-01-17 18:18:22 -0800 | [diff] [blame] | 280 | /** Reference to singleton {@link ActivityThread} */ |
Jeff Sharkey | d589663 | 2016-03-04 16:16:00 -0700 | [diff] [blame] | 281 | private static volatile ActivityThread sCurrentActivityThread; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 282 | Instrumentation mInstrumentation; |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 283 | String mInstrumentationPackageName = null; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 284 | String mInstrumentationAppDir = null; |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 285 | String[] mInstrumentationSplitAppDirs = null; |
| 286 | String mInstrumentationLibDir = null; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 287 | String mInstrumentedAppDir = null; |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 288 | String[] mInstrumentedSplitAppDirs = null; |
| 289 | String mInstrumentedLibDir = null; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 290 | boolean mSystemThread = false; |
| 291 | boolean mJitEnabled = false; |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 292 | boolean mSomeActivitiesChanged = false; |
Chong Zhang | 4951f9d | 2016-06-23 13:15:08 -0700 | [diff] [blame] | 293 | boolean mUpdatingSystemConfig = false; |
David Brazdil | d960cc4 | 2018-01-31 07:59:17 +0000 | [diff] [blame] | 294 | /* package */ boolean mHiddenApiWarningShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 295 | |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 296 | // These can be accessed by multiple threads; mResourcesManager is the lock. |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 297 | // XXX For now we keep around information about all packages we have |
| 298 | // seen, not removing entries from this map. |
Dianne Hackborn | 1fbee79 | 2011-11-30 11:29:58 -0800 | [diff] [blame] | 299 | // NOTE: The activity and window managers need to call in to |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 300 | // ActivityThread to do things like update resource configurations, |
Dianne Hackborn | 1fbee79 | 2011-11-30 11:29:58 -0800 | [diff] [blame] | 301 | // which means this lock gets held while the activity and window managers |
| 302 | // holds their own lock. Thus you MUST NEVER call back into the activity manager |
| 303 | // 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] | 304 | // 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] | 305 | @GuardedBy("mResourcesManager") |
| 306 | final ArrayMap<String, WeakReference<LoadedApk>> mPackages = new ArrayMap<>(); |
| 307 | @GuardedBy("mResourcesManager") |
| 308 | final ArrayMap<String, WeakReference<LoadedApk>> mResourcePackages = new ArrayMap<>(); |
| 309 | @GuardedBy("mResourcesManager") |
| 310 | final ArrayList<ActivityClientRecord> mRelaunchingActivities = new ArrayList<>(); |
| 311 | @GuardedBy("mResourcesManager") |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 312 | Configuration mPendingConfiguration = null; |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 313 | // An executor that performs multi-step transactions. |
| 314 | private final TransactionExecutor mTransactionExecutor = new TransactionExecutor(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 315 | |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 316 | private final ResourcesManager mResourcesManager; |
| 317 | |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 318 | private static final class ProviderKey { |
| 319 | final String authority; |
| 320 | final int userId; |
| 321 | |
| 322 | public ProviderKey(String authority, int userId) { |
| 323 | this.authority = authority; |
| 324 | this.userId = userId; |
| 325 | } |
| 326 | |
| 327 | @Override |
| 328 | public boolean equals(Object o) { |
| 329 | if (o instanceof ProviderKey) { |
| 330 | final ProviderKey other = (ProviderKey) o; |
Kenny Root | e6585b3 | 2013-12-13 12:00:26 -0800 | [diff] [blame] | 331 | return Objects.equals(authority, other.authority) && userId == other.userId; |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 332 | } |
| 333 | return false; |
| 334 | } |
| 335 | |
| 336 | @Override |
| 337 | public int hashCode() { |
| 338 | return ((authority != null) ? authority.hashCode() : 0) ^ userId; |
| 339 | } |
| 340 | } |
| 341 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 342 | // The lock of mProviderMap protects the following variables. |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 343 | final ArrayMap<ProviderKey, ProviderClientRecord> mProviderMap |
| 344 | = new ArrayMap<ProviderKey, ProviderClientRecord>(); |
| 345 | final ArrayMap<IBinder, ProviderRefCount> mProviderRefCountMap |
| 346 | = new ArrayMap<IBinder, ProviderRefCount>(); |
| 347 | final ArrayMap<IBinder, ProviderClientRecord> mLocalProviders |
| 348 | = new ArrayMap<IBinder, ProviderClientRecord>(); |
| 349 | final ArrayMap<ComponentName, ProviderClientRecord> mLocalProvidersByName |
| 350 | = new ArrayMap<ComponentName, ProviderClientRecord>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 351 | |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 352 | final ArrayMap<Activity, ArrayList<OnActivityPausedListener>> mOnPauseListeners |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 353 | = new ArrayMap<Activity, ArrayList<OnActivityPausedListener>>(); |
Jeff Hamilton | 52d3203 | 2011-01-08 15:31:26 -0600 | [diff] [blame] | 354 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 355 | final GcIdler mGcIdler = new GcIdler(); |
| 356 | boolean mGcIdlerScheduled = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 357 | |
Jeff Sharkey | d589663 | 2016-03-04 16:16:00 -0700 | [diff] [blame] | 358 | static volatile Handler sMainThreadHandler; // set once in main() |
Brad Fitzpatrick | 333b8cb | 2010-08-26 12:04:57 -0700 | [diff] [blame] | 359 | |
Svetoslav Ganov | 9aa597e | 2011-03-03 18:17:41 -0800 | [diff] [blame] | 360 | Bundle mCoreSettings = null; |
| 361 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 362 | /** Activity client record, used for bookkeeping for the real {@link Activity} instance. */ |
| 363 | public static final class ActivityClientRecord { |
| 364 | public IBinder token; |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 365 | int ident; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 366 | Intent intent; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 367 | String referrer; |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 368 | IVoiceInteractor voiceInteractor; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 369 | Bundle state; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 370 | PersistableBundle persistentState; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 371 | Activity activity; |
| 372 | Window window; |
| 373 | Activity parent; |
| 374 | String embeddedID; |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 375 | Activity.NonConfigurationInstances lastNonConfigurationInstances; |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 376 | // TODO(lifecycler): Use mLifecycleState instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 377 | boolean paused; |
| 378 | boolean stopped; |
| 379 | boolean hideForNow; |
| 380 | Configuration newConfig; |
Dianne Hackborn | e88846e | 2009-09-30 21:34:25 -0700 | [diff] [blame] | 381 | Configuration createdConfig; |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 382 | Configuration overrideConfig; |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 383 | // Used for consolidating configs before sending on to Activity. |
| 384 | private Configuration tmpConfig = new Configuration(); |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 385 | // Callback used for updating activity override config. |
| 386 | ViewRootImpl.ActivityConfigCallback configCallback; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 387 | ActivityClientRecord nextIdle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 388 | |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 389 | ProfilerInfo profilerInfo; |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 390 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 391 | ActivityInfo activityInfo; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 392 | CompatibilityInfo compatInfo; |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 393 | public LoadedApk packageInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 394 | |
| 395 | List<ResultInfo> pendingResults; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 396 | List<ReferrerIntent> pendingIntents; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 397 | |
| 398 | boolean startsNotResumed; |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 399 | public final boolean isForward; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 400 | int pendingConfigChanges; |
| 401 | boolean onlyLocalRequest; |
| 402 | |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 403 | Window mPendingRemoveWindow; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 404 | WindowManager mPendingRemoveWindowManager; |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 405 | boolean mPreserveWindow; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 406 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 407 | @LifecycleState |
| 408 | private int mLifecycleState = PRE_ON_CREATE; |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 409 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 410 | @VisibleForTesting |
| 411 | public ActivityClientRecord() { |
| 412 | this.isForward = false; |
| 413 | init(); |
| 414 | } |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 415 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 416 | public ActivityClientRecord(IBinder token, Intent intent, int ident, |
| 417 | ActivityInfo info, Configuration overrideConfig, CompatibilityInfo compatInfo, |
| 418 | String referrer, IVoiceInteractor voiceInteractor, Bundle state, |
| 419 | PersistableBundle persistentState, List<ResultInfo> pendingResults, |
| 420 | List<ReferrerIntent> pendingNewIntents, boolean isForward, |
| 421 | ProfilerInfo profilerInfo, ClientTransactionHandler client) { |
| 422 | this.token = token; |
| 423 | this.ident = ident; |
| 424 | this.intent = intent; |
| 425 | this.referrer = referrer; |
| 426 | this.voiceInteractor = voiceInteractor; |
| 427 | this.activityInfo = info; |
| 428 | this.compatInfo = compatInfo; |
| 429 | this.state = state; |
| 430 | this.persistentState = persistentState; |
| 431 | this.pendingResults = pendingResults; |
| 432 | this.pendingIntents = pendingNewIntents; |
| 433 | this.isForward = isForward; |
| 434 | this.profilerInfo = profilerInfo; |
| 435 | this.overrideConfig = overrideConfig; |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 436 | this.packageInfo = client.getPackageInfoNoCheck(activityInfo.applicationInfo, |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 437 | compatInfo); |
| 438 | init(); |
| 439 | } |
| 440 | |
| 441 | /** Common initializer for all constructors. */ |
| 442 | private void init() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 443 | parent = null; |
| 444 | embeddedID = null; |
| 445 | paused = false; |
| 446 | stopped = false; |
| 447 | hideForNow = false; |
| 448 | nextIdle = null; |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 449 | configCallback = (Configuration overrideConfig, int newDisplayId) -> { |
| 450 | if (activity == null) { |
| 451 | throw new IllegalStateException( |
| 452 | "Received config update for non-existing activity"); |
| 453 | } |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 454 | activity.mMainThread.handleActivityConfigurationChanged(token, overrideConfig, |
| 455 | newDisplayId); |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 456 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 457 | } |
| 458 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 459 | /** Get the current lifecycle state. */ |
| 460 | public int getLifecycleState() { |
| 461 | return mLifecycleState; |
| 462 | } |
| 463 | |
| 464 | /** Update the current lifecycle state for internal bookkeeping. */ |
| 465 | public void setState(@LifecycleState int newLifecycleState) { |
| 466 | mLifecycleState = newLifecycleState; |
| 467 | switch (mLifecycleState) { |
| 468 | case ON_CREATE: |
| 469 | paused = true; |
| 470 | stopped = true; |
| 471 | break; |
| 472 | case ON_START: |
| 473 | paused = true; |
| 474 | stopped = false; |
| 475 | break; |
| 476 | case ON_RESUME: |
| 477 | paused = false; |
| 478 | stopped = false; |
| 479 | break; |
| 480 | case ON_PAUSE: |
| 481 | paused = true; |
| 482 | stopped = false; |
| 483 | break; |
| 484 | case ON_STOP: |
| 485 | paused = true; |
| 486 | stopped = true; |
| 487 | break; |
| 488 | } |
| 489 | } |
| 490 | |
Andrii Kulian | 391161f | 2018-01-29 10:50:02 -0800 | [diff] [blame] | 491 | private boolean isPreHoneycomb() { |
| 492 | return activity != null && activity.getApplicationInfo().targetSdkVersion |
| 493 | < android.os.Build.VERSION_CODES.HONEYCOMB; |
| 494 | } |
| 495 | |
| 496 | private boolean isPreP() { |
| 497 | return activity != null && activity.getApplicationInfo().targetSdkVersion |
| 498 | < android.os.Build.VERSION_CODES.P; |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 499 | } |
| 500 | |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 501 | public boolean isPersistable() { |
Craig Mautner | 43e52ed | 2014-06-16 17:18:52 -0700 | [diff] [blame] | 502 | return activityInfo.persistableMode == ActivityInfo.PERSIST_ACROSS_REBOOTS; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 503 | } |
| 504 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 505 | public String toString() { |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 506 | ComponentName componentName = intent != null ? intent.getComponent() : null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 507 | return "ActivityRecord{" |
| 508 | + Integer.toHexString(System.identityHashCode(this)) |
| 509 | + " token=" + token + " " + (componentName == null |
| 510 | ? "no component name" : componentName.toShortString()) |
| 511 | + "}"; |
| 512 | } |
Andrii Kulian | 58178f2 | 2016-03-16 13:44:56 -0700 | [diff] [blame] | 513 | |
| 514 | public String getStateString() { |
| 515 | StringBuilder sb = new StringBuilder(); |
| 516 | sb.append("ActivityClientRecord{"); |
| 517 | sb.append("paused=").append(paused); |
| 518 | sb.append(", stopped=").append(stopped); |
| 519 | sb.append(", hideForNow=").append(hideForNow); |
| 520 | sb.append(", startsNotResumed=").append(startsNotResumed); |
| 521 | sb.append(", isForward=").append(isForward); |
| 522 | sb.append(", pendingConfigChanges=").append(pendingConfigChanges); |
| 523 | sb.append(", onlyLocalRequest=").append(onlyLocalRequest); |
| 524 | sb.append(", preserveWindow=").append(mPreserveWindow); |
| 525 | if (activity != null) { |
| 526 | sb.append(", Activity{"); |
| 527 | sb.append("resumed=").append(activity.mResumed); |
| 528 | sb.append(", stopped=").append(activity.mStopped); |
| 529 | sb.append(", finished=").append(activity.isFinishing()); |
| 530 | sb.append(", destroyed=").append(activity.isDestroyed()); |
| 531 | sb.append(", startedActivity=").append(activity.mStartedActivity); |
| 532 | sb.append(", temporaryPause=").append(activity.mTemporaryPause); |
| 533 | sb.append(", changingConfigurations=").append(activity.mChangingConfigurations); |
Andrii Kulian | 58178f2 | 2016-03-16 13:44:56 -0700 | [diff] [blame] | 534 | sb.append("}"); |
| 535 | } |
| 536 | sb.append("}"); |
| 537 | return sb.toString(); |
| 538 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 539 | } |
| 540 | |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 541 | final class ProviderClientRecord { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 542 | final String[] mNames; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 543 | final IContentProvider mProvider; |
| 544 | final ContentProvider mLocalProvider; |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 545 | final ContentProviderHolder mHolder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 546 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 547 | ProviderClientRecord(String[] names, IContentProvider provider, |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 548 | ContentProvider localProvider, ContentProviderHolder holder) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 549 | mNames = names; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 550 | mProvider = provider; |
| 551 | mLocalProvider = localProvider; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 552 | mHolder = holder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 553 | } |
| 554 | } |
| 555 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 556 | static final class ReceiverData extends BroadcastReceiver.PendingResult { |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 557 | public ReceiverData(Intent intent, int resultCode, String resultData, Bundle resultExtras, |
Dianne Hackborn | 20e8098 | 2012-08-31 19:00:44 -0700 | [diff] [blame] | 558 | boolean ordered, boolean sticky, IBinder token, int sendingUser) { |
| 559 | super(resultCode, resultData, resultExtras, TYPE_COMPONENT, ordered, sticky, |
riddle_hsu | 1f5ac4d | 2015-01-03 15:38:21 +0800 | [diff] [blame] | 560 | token, sendingUser, intent.getFlags()); |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 561 | this.intent = intent; |
| 562 | } |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 563 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 564 | Intent intent; |
| 565 | ActivityInfo info; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 566 | CompatibilityInfo compatInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 567 | public String toString() { |
| 568 | return "ReceiverData{intent=" + intent + " packageName=" + |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 569 | info.packageName + " resultCode=" + getResultCode() |
| 570 | + " resultData=" + getResultData() + " resultExtras=" |
| 571 | + getResultExtras(false) + "}"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 572 | } |
| 573 | } |
| 574 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 575 | static final class CreateBackupAgentData { |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 576 | ApplicationInfo appInfo; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 577 | CompatibilityInfo compatInfo; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 578 | int backupMode; |
| 579 | public String toString() { |
| 580 | return "CreateBackupAgentData{appInfo=" + appInfo |
| 581 | + " backupAgent=" + appInfo.backupAgentName |
| 582 | + " mode=" + backupMode + "}"; |
| 583 | } |
| 584 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 585 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 586 | static final class CreateServiceData { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 587 | IBinder token; |
| 588 | ServiceInfo info; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 589 | CompatibilityInfo compatInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 590 | Intent intent; |
| 591 | public String toString() { |
| 592 | return "CreateServiceData{token=" + token + " className=" |
| 593 | + info.name + " packageName=" + info.packageName |
| 594 | + " intent=" + intent + "}"; |
| 595 | } |
| 596 | } |
| 597 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 598 | static final class BindServiceData { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 599 | IBinder token; |
| 600 | Intent intent; |
| 601 | boolean rebind; |
| 602 | public String toString() { |
| 603 | return "BindServiceData{token=" + token + " intent=" + intent + "}"; |
| 604 | } |
| 605 | } |
| 606 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 607 | static final class ServiceArgsData { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 608 | IBinder token; |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 609 | boolean taskRemoved; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 610 | int startId; |
Dianne Hackborn | f6f9f2d | 2009-08-21 16:26:03 -0700 | [diff] [blame] | 611 | int flags; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 612 | Intent args; |
| 613 | public String toString() { |
| 614 | return "ServiceArgsData{token=" + token + " startId=" + startId |
| 615 | + " args=" + args + "}"; |
| 616 | } |
| 617 | } |
| 618 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 619 | static final class AppBindData { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 620 | LoadedApk info; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 621 | String processName; |
| 622 | ApplicationInfo appInfo; |
| 623 | List<ProviderInfo> providers; |
| 624 | ComponentName instrumentationName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 625 | Bundle instrumentationArgs; |
| 626 | IInstrumentationWatcher instrumentationWatcher; |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 627 | IUiAutomationConnection instrumentationUiAutomationConnection; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 628 | int debugMode; |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 629 | boolean enableBinderTracking; |
Man Cao | cfa78b2 | 2015-06-11 20:14:34 -0700 | [diff] [blame] | 630 | boolean trackAllocation; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 631 | boolean restrictedBackupMode; |
Dianne Hackborn | 5d927c2 | 2011-09-02 12:22:18 -0700 | [diff] [blame] | 632 | boolean persistent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 633 | Configuration config; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 634 | CompatibilityInfo compatInfo; |
Svet Ganov | 37e4327 | 2016-09-09 16:01:32 -0700 | [diff] [blame] | 635 | String buildSerial; |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 636 | |
| 637 | /** Initial values for {@link Profiler}. */ |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 638 | ProfilerInfo initProfilerInfo; |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 639 | |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 640 | boolean autofillCompatibilityEnabled; |
| 641 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 642 | public String toString() { |
| 643 | return "AppBindData{appInfo=" + appInfo + "}"; |
| 644 | } |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | static final class Profiler { |
| 648 | String profileFile; |
| 649 | ParcelFileDescriptor profileFd; |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 650 | int samplingInterval; |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 651 | boolean autoStopProfiler; |
Shukang Zhou | 6ffd4f9 | 2017-01-25 16:07:57 -0800 | [diff] [blame] | 652 | boolean streamingOutput; |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 653 | boolean profiling; |
| 654 | boolean handlingProfiling; |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 655 | public void setProfiler(ProfilerInfo profilerInfo) { |
| 656 | ParcelFileDescriptor fd = profilerInfo.profileFd; |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 657 | if (profiling) { |
| 658 | if (fd != null) { |
| 659 | try { |
| 660 | fd.close(); |
| 661 | } catch (IOException e) { |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 662 | // Ignore |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 663 | } |
| 664 | } |
| 665 | return; |
| 666 | } |
| 667 | if (profileFd != null) { |
| 668 | try { |
| 669 | profileFd.close(); |
| 670 | } catch (IOException e) { |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 671 | // Ignore |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 672 | } |
| 673 | } |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 674 | profileFile = profilerInfo.profileFile; |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 675 | profileFd = fd; |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 676 | samplingInterval = profilerInfo.samplingInterval; |
| 677 | autoStopProfiler = profilerInfo.autoStopProfiler; |
Shukang Zhou | 6ffd4f9 | 2017-01-25 16:07:57 -0800 | [diff] [blame] | 678 | streamingOutput = profilerInfo.streamingOutput; |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 679 | } |
| 680 | public void startProfiling() { |
| 681 | if (profileFd == null || profiling) { |
| 682 | return; |
| 683 | } |
| 684 | try { |
Andreas Gampe | eff0639 | 2016-05-10 12:51:45 -0700 | [diff] [blame] | 685 | int bufferSize = SystemProperties.getInt("debug.traceview-buffer-size-mb", 8); |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 686 | VMDebug.startMethodTracing(profileFile, profileFd.getFileDescriptor(), |
Shukang Zhou | 6ffd4f9 | 2017-01-25 16:07:57 -0800 | [diff] [blame] | 687 | bufferSize * 1024 * 1024, 0, samplingInterval != 0, samplingInterval, |
| 688 | streamingOutput); |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 689 | profiling = true; |
| 690 | } catch (RuntimeException e) { |
| 691 | Slog.w(TAG, "Profiling failed on path " + profileFile); |
| 692 | try { |
| 693 | profileFd.close(); |
| 694 | profileFd = null; |
| 695 | } catch (IOException e2) { |
| 696 | Slog.w(TAG, "Failure closing profile fd", e2); |
| 697 | } |
| 698 | } |
| 699 | } |
| 700 | public void stopProfiling() { |
| 701 | if (profiling) { |
| 702 | profiling = false; |
| 703 | Debug.stopMethodTracing(); |
| 704 | if (profileFd != null) { |
| 705 | try { |
| 706 | profileFd.close(); |
| 707 | } catch (IOException e) { |
| 708 | } |
| 709 | } |
| 710 | profileFd = null; |
| 711 | profileFile = null; |
| 712 | } |
| 713 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 714 | } |
| 715 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 716 | static final class DumpComponentInfo { |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 717 | ParcelFileDescriptor fd; |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 718 | IBinder token; |
Dianne Hackborn | 30d7189 | 2010-12-11 10:37:55 -0800 | [diff] [blame] | 719 | String prefix; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 720 | String[] args; |
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 ContextCleanupInfo { |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 724 | ContextImpl context; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 725 | String what; |
| 726 | String who; |
| 727 | } |
| 728 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 729 | static final class DumpHeapData { |
Christopher Ferris | 8d652f8 | 2017-04-11 16:29:18 -0700 | [diff] [blame] | 730 | public boolean managed; |
| 731 | public boolean mallocInfo; |
Makoto Onuki | 4556b7b | 2017-07-07 14:58:58 -0700 | [diff] [blame] | 732 | public boolean runGc; |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 733 | String path; |
| 734 | ParcelFileDescriptor fd; |
| 735 | } |
| 736 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 737 | static final class UpdateCompatibilityData { |
| 738 | String pkg; |
| 739 | CompatibilityInfo info; |
| 740 | } |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 741 | |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 742 | static final class RequestAssistContextExtras { |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 743 | IBinder activityToken; |
| 744 | IBinder requestToken; |
| 745 | int requestType; |
Amith Yamasani | 4f128e4 | 2016-05-10 11:44:12 -0700 | [diff] [blame] | 746 | int sessionId; |
Svet Ganov | fd31f85 | 2017-04-26 15:54:27 -0700 | [diff] [blame] | 747 | int flags; |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 748 | } |
Anwar Ghuloum | 3a8ce1b | 2013-04-26 16:18:28 -0700 | [diff] [blame] | 749 | |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 750 | private class ApplicationThread extends IApplicationThread.Stub { |
Vasu Nori | 3c7131f | 2010-09-21 14:36:57 -0700 | [diff] [blame] | 751 | private static final String DB_INFO_FORMAT = " %8s %8s %14s %14s %s"; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 752 | |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 753 | private int mLastProcessState = -1; |
| 754 | |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 755 | private void updatePendingConfiguration(Configuration config) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 756 | synchronized (mResourcesManager) { |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 757 | if (mPendingConfiguration == null || |
| 758 | mPendingConfiguration.isOtherSeqNewer(config)) { |
| 759 | mPendingConfiguration = config; |
| 760 | } |
| 761 | } |
| 762 | } |
| 763 | |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 764 | public final void scheduleSleeping(IBinder token, boolean sleeping) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 765 | sendMessage(H.SLEEPING, token, sleeping ? 1 : 0); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 766 | } |
| 767 | |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 768 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 769 | public final void scheduleRelaunchActivity(IBinder token, |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 770 | List<ResultInfo> pendingResults, List<ReferrerIntent> pendingNewIntents, |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 771 | int configChanges, boolean notResumed, Configuration config, |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 772 | Configuration overrideConfig, boolean preserveWindow) { |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 773 | requestRelaunchActivity(token, pendingResults, pendingNewIntents, |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 774 | configChanges, notResumed, config, overrideConfig, true, preserveWindow); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 775 | } |
| 776 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 777 | public final void scheduleReceiver(Intent intent, ActivityInfo info, |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 778 | CompatibilityInfo compatInfo, int resultCode, String data, Bundle extras, |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 779 | boolean sync, int sendingUser, int processState) { |
| 780 | updateProcessState(processState, false); |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 781 | ReceiverData r = new ReceiverData(intent, resultCode, data, extras, |
Dianne Hackborn | 20e8098 | 2012-08-31 19:00:44 -0700 | [diff] [blame] | 782 | sync, false, mAppThread.asBinder(), sendingUser); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 783 | r.info = info; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 784 | r.compatInfo = compatInfo; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 785 | sendMessage(H.RECEIVER, r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 786 | } |
| 787 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 788 | public final void scheduleCreateBackupAgent(ApplicationInfo app, |
| 789 | CompatibilityInfo compatInfo, int backupMode) { |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 790 | CreateBackupAgentData d = new CreateBackupAgentData(); |
| 791 | d.appInfo = app; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 792 | d.compatInfo = compatInfo; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 793 | d.backupMode = backupMode; |
| 794 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 795 | sendMessage(H.CREATE_BACKUP_AGENT, d); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 796 | } |
| 797 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 798 | public final void scheduleDestroyBackupAgent(ApplicationInfo app, |
| 799 | CompatibilityInfo compatInfo) { |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 800 | CreateBackupAgentData d = new CreateBackupAgentData(); |
| 801 | d.appInfo = app; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 802 | d.compatInfo = compatInfo; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 803 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 804 | sendMessage(H.DESTROY_BACKUP_AGENT, d); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 805 | } |
| 806 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 807 | public final void scheduleCreateService(IBinder token, |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 808 | ServiceInfo info, CompatibilityInfo compatInfo, int processState) { |
| 809 | updateProcessState(processState, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 810 | CreateServiceData s = new CreateServiceData(); |
| 811 | s.token = token; |
| 812 | s.info = info; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 813 | s.compatInfo = compatInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 814 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 815 | sendMessage(H.CREATE_SERVICE, s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 816 | } |
| 817 | |
| 818 | public final void scheduleBindService(IBinder token, Intent intent, |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 819 | boolean rebind, int processState) { |
| 820 | updateProcessState(processState, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 821 | BindServiceData s = new BindServiceData(); |
| 822 | s.token = token; |
| 823 | s.intent = intent; |
| 824 | s.rebind = rebind; |
| 825 | |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 826 | if (DEBUG_SERVICE) |
| 827 | Slog.v(TAG, "scheduleBindService token=" + token + " intent=" + intent + " uid=" |
| 828 | + Binder.getCallingUid() + " pid=" + Binder.getCallingPid()); |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 829 | sendMessage(H.BIND_SERVICE, s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 830 | } |
| 831 | |
| 832 | public final void scheduleUnbindService(IBinder token, Intent intent) { |
| 833 | BindServiceData s = new BindServiceData(); |
| 834 | s.token = token; |
| 835 | s.intent = intent; |
| 836 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 837 | sendMessage(H.UNBIND_SERVICE, s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 838 | } |
| 839 | |
Dianne Hackborn | 3f7c9f2 | 2017-04-04 15:36:33 -0700 | [diff] [blame] | 840 | public final void scheduleServiceArgs(IBinder token, ParceledListSlice args) { |
| 841 | List<ServiceStartArgs> list = args.getList(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 842 | |
Dianne Hackborn | 3f7c9f2 | 2017-04-04 15:36:33 -0700 | [diff] [blame] | 843 | for (int i = 0; i < list.size(); i++) { |
| 844 | ServiceStartArgs ssa = list.get(i); |
| 845 | ServiceArgsData s = new ServiceArgsData(); |
| 846 | s.token = token; |
| 847 | s.taskRemoved = ssa.taskRemoved; |
| 848 | s.startId = ssa.startId; |
| 849 | s.flags = ssa.flags; |
| 850 | s.args = ssa.args; |
| 851 | |
| 852 | sendMessage(H.SERVICE_ARGS, s); |
| 853 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 854 | } |
| 855 | |
| 856 | public final void scheduleStopService(IBinder token) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 857 | sendMessage(H.STOP_SERVICE, token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 858 | } |
| 859 | |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 860 | public final void bindApplication(String processName, ApplicationInfo appInfo, |
| 861 | List<ProviderInfo> providers, ComponentName instrumentationName, |
| 862 | ProfilerInfo profilerInfo, Bundle instrumentationArgs, |
| 863 | IInstrumentationWatcher instrumentationWatcher, |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 864 | IUiAutomationConnection instrumentationUiConnection, int debugMode, |
Pablo Ceballos | a4d4e82 | 2015-10-05 10:27:52 -0700 | [diff] [blame] | 865 | boolean enableBinderTracking, boolean trackAllocation, |
| 866 | boolean isRestrictedBackupMode, boolean persistent, Configuration config, |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 867 | CompatibilityInfo compatInfo, Map services, Bundle coreSettings, |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 868 | String buildSerial, boolean autofillCompatibilityEnabled) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 869 | |
| 870 | if (services != null) { |
| 871 | // Setup the service cache in the ServiceManager |
| 872 | ServiceManager.initServiceCache(services); |
| 873 | } |
| 874 | |
Svetoslav Ganov | 9aa597e | 2011-03-03 18:17:41 -0800 | [diff] [blame] | 875 | setCoreSettings(coreSettings); |
| 876 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 877 | AppBindData data = new AppBindData(); |
| 878 | data.processName = processName; |
| 879 | data.appInfo = appInfo; |
| 880 | data.providers = providers; |
| 881 | data.instrumentationName = instrumentationName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 882 | data.instrumentationArgs = instrumentationArgs; |
| 883 | data.instrumentationWatcher = instrumentationWatcher; |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 884 | data.instrumentationUiAutomationConnection = instrumentationUiConnection; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 885 | data.debugMode = debugMode; |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 886 | data.enableBinderTracking = enableBinderTracking; |
Man Cao | cfa78b2 | 2015-06-11 20:14:34 -0700 | [diff] [blame] | 887 | data.trackAllocation = trackAllocation; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 888 | data.restrictedBackupMode = isRestrictedBackupMode; |
Dianne Hackborn | 5d927c2 | 2011-09-02 12:22:18 -0700 | [diff] [blame] | 889 | data.persistent = persistent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 890 | data.config = config; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 891 | data.compatInfo = compatInfo; |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 892 | data.initProfilerInfo = profilerInfo; |
Svet Ganov | 37e4327 | 2016-09-09 16:01:32 -0700 | [diff] [blame] | 893 | data.buildSerial = buildSerial; |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 894 | data.autofillCompatibilityEnabled = autofillCompatibilityEnabled; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 895 | sendMessage(H.BIND_APPLICATION, data); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 896 | } |
| 897 | |
Torne (Richard Coles) | 466cbe4 | 2017-05-31 14:09:14 -0400 | [diff] [blame] | 898 | public final void runIsolatedEntryPoint(String entryPoint, String[] entryPointArgs) { |
| 899 | SomeArgs args = SomeArgs.obtain(); |
| 900 | args.arg1 = entryPoint; |
| 901 | args.arg2 = entryPointArgs; |
| 902 | sendMessage(H.RUN_ISOLATED_ENTRY_POINT, args); |
| 903 | } |
| 904 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 905 | public final void scheduleExit() { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 906 | sendMessage(H.EXIT_APPLICATION, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 907 | } |
| 908 | |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 909 | public final void scheduleSuicide() { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 910 | sendMessage(H.SUICIDE, null); |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 911 | } |
| 912 | |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 913 | public void scheduleApplicationInfoChanged(ApplicationInfo ai) { |
| 914 | sendMessage(H.APPLICATION_INFO_CHANGED, ai); |
| 915 | } |
| 916 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 917 | public void updateTimeZone() { |
| 918 | TimeZone.setDefault(null); |
| 919 | } |
| 920 | |
Robert Greenwalt | 03595d0 | 2010-11-02 14:08:23 -0700 | [diff] [blame] | 921 | public void clearDnsCache() { |
| 922 | // a non-standard API to get this to libcore |
| 923 | InetAddress.clearDnsCache(); |
Paul Jensen | e401d17 | 2014-09-12 10:47:39 -0400 | [diff] [blame] | 924 | // Allow libcore to perform the necessary actions as it sees fit upon a network |
| 925 | // configuration change. |
| 926 | NetworkEventDispatcher.getInstance().onNetworkConfigurationChanged(); |
Robert Greenwalt | 03595d0 | 2010-11-02 14:08:23 -0700 | [diff] [blame] | 927 | } |
| 928 | |
Jason Monk | 83520b9 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 929 | public void setHttpProxy(String host, String port, String exclList, Uri pacFileUrl) { |
Paul Jensen | 72db88e | 2015-03-10 10:54:12 -0400 | [diff] [blame] | 930 | final ConnectivityManager cm = ConnectivityManager.from(getSystemContext()); |
| 931 | final Network network = cm.getBoundNetworkForProcess(); |
Paul Jensen | e0bef71 | 2014-12-10 15:12:18 -0500 | [diff] [blame] | 932 | if (network != null) { |
Paul Jensen | 72db88e | 2015-03-10 10:54:12 -0400 | [diff] [blame] | 933 | Proxy.setHttpProxySystemProperty(cm.getDefaultProxy()); |
Paul Jensen | e0bef71 | 2014-12-10 15:12:18 -0500 | [diff] [blame] | 934 | } else { |
| 935 | Proxy.setHttpProxySystemProperty(host, port, exclList, pacFileUrl); |
| 936 | } |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 937 | } |
| 938 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 939 | public void processInBackground() { |
| 940 | mH.removeMessages(H.GC_WHEN_IDLE); |
| 941 | mH.sendMessage(mH.obtainMessage(H.GC_WHEN_IDLE)); |
| 942 | } |
| 943 | |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 944 | public void dumpService(ParcelFileDescriptor pfd, IBinder servicetoken, String[] args) { |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 945 | DumpComponentInfo data = new DumpComponentInfo(); |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 946 | try { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 947 | data.fd = pfd.dup(); |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 948 | data.token = servicetoken; |
| 949 | data.args = args; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 950 | sendMessage(H.DUMP_SERVICE, data, 0, 0, true /*async*/); |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 951 | } catch (IOException e) { |
| 952 | Slog.w(TAG, "dumpService failed", e); |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 953 | } finally { |
| 954 | IoUtils.closeQuietly(pfd); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 955 | } |
| 956 | } |
| 957 | |
| 958 | // This function exists to make sure all receiver dispatching is |
| 959 | // correctly ordered, since these are one-way calls and the binder driver |
| 960 | // applies transaction ordering per object for such calls. |
| 961 | public void scheduleRegisteredReceiver(IIntentReceiver receiver, Intent intent, |
Dianne Hackborn | 68d881c | 2009-10-05 13:58:17 -0700 | [diff] [blame] | 962 | int resultCode, String dataStr, Bundle extras, boolean ordered, |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 963 | boolean sticky, int sendingUser, int processState) throws RemoteException { |
| 964 | updateProcessState(processState, false); |
Dianne Hackborn | 20e8098 | 2012-08-31 19:00:44 -0700 | [diff] [blame] | 965 | receiver.performReceive(intent, resultCode, dataStr, extras, ordered, |
| 966 | sticky, sendingUser); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 967 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 968 | |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 969 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 970 | public void scheduleLowMemory() { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 971 | sendMessage(H.LOW_MEMORY, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 972 | } |
| 973 | |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 974 | @Override |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 975 | public void profilerControl(boolean start, ProfilerInfo profilerInfo, int profileType) { |
| 976 | sendMessage(H.PROFILER_CONTROL, profilerInfo, start ? 1 : 0, profileType); |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 977 | } |
| 978 | |
Makoto Onuki | 4556b7b | 2017-07-07 14:58:58 -0700 | [diff] [blame] | 979 | @Override |
Christopher Ferris | 8d652f8 | 2017-04-11 16:29:18 -0700 | [diff] [blame] | 980 | public void dumpHeap(boolean managed, boolean mallocInfo, boolean runGc, String path, |
| 981 | ParcelFileDescriptor fd) { |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 982 | DumpHeapData dhd = new DumpHeapData(); |
Christopher Ferris | 8d652f8 | 2017-04-11 16:29:18 -0700 | [diff] [blame] | 983 | dhd.managed = managed; |
| 984 | dhd.mallocInfo = mallocInfo; |
Makoto Onuki | 4556b7b | 2017-07-07 14:58:58 -0700 | [diff] [blame] | 985 | dhd.runGc = runGc; |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 986 | dhd.path = path; |
| 987 | dhd.fd = fd; |
Christopher Ferris | 8d652f8 | 2017-04-11 16:29:18 -0700 | [diff] [blame] | 988 | sendMessage(H.DUMP_HEAP, dhd, 0, 0, true /*async*/); |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 989 | } |
| 990 | |
Leonard Mosescu | f3409ce | 2016-10-06 17:32:05 -0700 | [diff] [blame] | 991 | public void attachAgent(String agent) { |
| 992 | sendMessage(H.ATTACH_AGENT, agent); |
| 993 | } |
| 994 | |
Dianne Hackborn | 06de2ea | 2009-05-21 12:56:43 -0700 | [diff] [blame] | 995 | public void setSchedulingGroup(int group) { |
| 996 | // Note: do this immediately, since going into the foreground |
| 997 | // should happen regardless of what pending work we have to do |
| 998 | // and the activity manager will wait for us to report back that |
| 999 | // we are done before sending us to the background. |
| 1000 | try { |
| 1001 | Process.setProcessGroup(Process.myPid(), group); |
| 1002 | } catch (Exception e) { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 1003 | Slog.w(TAG, "Failed setting process group to " + group, e); |
Dianne Hackborn | 06de2ea | 2009-05-21 12:56:43 -0700 | [diff] [blame] | 1004 | } |
| 1005 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1006 | |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1007 | public void dispatchPackageBroadcast(int cmd, String[] packages) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1008 | sendMessage(H.DISPATCH_PACKAGE_BROADCAST, packages, cmd); |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1009 | } |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 1010 | |
| 1011 | public void scheduleCrash(String msg) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1012 | sendMessage(H.SCHEDULE_CRASH, msg); |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 1013 | } |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1014 | |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1015 | public void dumpActivity(ParcelFileDescriptor pfd, IBinder activitytoken, |
Dianne Hackborn | 30d7189 | 2010-12-11 10:37:55 -0800 | [diff] [blame] | 1016 | String prefix, String[] args) { |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1017 | DumpComponentInfo data = new DumpComponentInfo(); |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 1018 | try { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1019 | data.fd = pfd.dup(); |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 1020 | data.token = activitytoken; |
| 1021 | data.prefix = prefix; |
| 1022 | data.args = args; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1023 | sendMessage(H.DUMP_ACTIVITY, data, 0, 0, true /*async*/); |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 1024 | } catch (IOException e) { |
| 1025 | Slog.w(TAG, "dumpActivity failed", e); |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1026 | } finally { |
| 1027 | IoUtils.closeQuietly(pfd); |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1028 | } |
| 1029 | } |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 1030 | |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1031 | public void dumpProvider(ParcelFileDescriptor pfd, IBinder providertoken, |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1032 | String[] args) { |
| 1033 | DumpComponentInfo data = new DumpComponentInfo(); |
| 1034 | try { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1035 | data.fd = pfd.dup(); |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1036 | data.token = providertoken; |
| 1037 | data.args = args; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1038 | sendMessage(H.DUMP_PROVIDER, data, 0, 0, true /*async*/); |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1039 | } catch (IOException e) { |
| 1040 | Slog.w(TAG, "dumpProvider failed", e); |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1041 | } finally { |
| 1042 | IoUtils.closeQuietly(pfd); |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1043 | } |
| 1044 | } |
| 1045 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1046 | @Override |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1047 | public void dumpMemInfo(ParcelFileDescriptor pfd, Debug.MemoryInfo mem, boolean checkin, |
Colin Cross | c4fb5f9 | 2016-02-02 16:51:15 -0800 | [diff] [blame] | 1048 | boolean dumpFullInfo, boolean dumpDalvik, boolean dumpSummaryOnly, |
| 1049 | boolean dumpUnreachable, String[] args) { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1050 | FileOutputStream fout = new FileOutputStream(pfd.getFileDescriptor()); |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 1051 | PrintWriter pw = new FastPrintWriter(fout); |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 1052 | try { |
Colin Cross | c4fb5f9 | 2016-02-02 16:51:15 -0800 | [diff] [blame] | 1053 | dumpMemInfo(pw, mem, checkin, dumpFullInfo, dumpDalvik, dumpSummaryOnly, dumpUnreachable); |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 1054 | } finally { |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 1055 | pw.flush(); |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1056 | IoUtils.closeQuietly(pfd); |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 1057 | } |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 1058 | } |
| 1059 | |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 1060 | private void dumpMemInfo(PrintWriter pw, Debug.MemoryInfo memInfo, boolean checkin, |
Colin Cross | c4fb5f9 | 2016-02-02 16:51:15 -0800 | [diff] [blame] | 1061 | boolean dumpFullInfo, boolean dumpDalvik, boolean dumpSummaryOnly, boolean dumpUnreachable) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1062 | long nativeMax = Debug.getNativeHeapSize() / 1024; |
| 1063 | long nativeAllocated = Debug.getNativeHeapAllocatedSize() / 1024; |
| 1064 | long nativeFree = Debug.getNativeHeapFreeSize() / 1024; |
| 1065 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1066 | Runtime runtime = Runtime.getRuntime(); |
Mathieu Chartier | d288a26 | 2015-07-10 13:44:42 -0700 | [diff] [blame] | 1067 | runtime.gc(); // Do GC since countInstancesOfClass counts unreachable objects. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1068 | long dalvikMax = runtime.totalMemory() / 1024; |
| 1069 | long dalvikFree = runtime.freeMemory() / 1024; |
| 1070 | long dalvikAllocated = dalvikMax - dalvikFree; |
Richard Uhler | 2c03619 | 2016-09-14 09:48:31 +0100 | [diff] [blame] | 1071 | |
| 1072 | Class[] classesToCount = new Class[] { |
| 1073 | ContextImpl.class, |
| 1074 | Activity.class, |
| 1075 | WebView.class, |
| 1076 | OpenSSLSocketImpl.class |
| 1077 | }; |
| 1078 | long[] instanceCounts = VMDebug.countInstancesOfClasses(classesToCount, true); |
| 1079 | long appContextInstanceCount = instanceCounts[0]; |
| 1080 | long activityInstanceCount = instanceCounts[1]; |
| 1081 | long webviewInstanceCount = instanceCounts[2]; |
| 1082 | long openSslSocketCount = instanceCounts[3]; |
| 1083 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1084 | long viewInstanceCount = ViewDebug.getViewInstanceCount(); |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1085 | long viewRootInstanceCount = ViewDebug.getViewRootImplCount(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1086 | int globalAssetCount = AssetManager.getGlobalAssetCount(); |
| 1087 | int globalAssetManagerCount = AssetManager.getGlobalAssetManagerCount(); |
| 1088 | int binderLocalObjectCount = Debug.getBinderLocalObjectCount(); |
| 1089 | int binderProxyObjectCount = Debug.getBinderProxyObjectCount(); |
| 1090 | int binderDeathObjectCount = Debug.getBinderDeathObjectCount(); |
Dianne Hackborn | fabb70b | 2014-11-11 12:22:36 -0800 | [diff] [blame] | 1091 | long parcelSize = Parcel.getGlobalAllocSize(); |
| 1092 | long parcelCount = Parcel.getGlobalAllocCount(); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1093 | SQLiteDebug.PagerStats stats = SQLiteDebug.getDatabaseInfo(); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1094 | |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 1095 | dumpMemInfoTable(pw, memInfo, checkin, dumpFullInfo, dumpDalvik, dumpSummaryOnly, |
| 1096 | Process.myPid(), |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 1097 | (mBoundApplication != null) ? mBoundApplication.processName : "unknown", |
| 1098 | nativeMax, nativeAllocated, nativeFree, |
| 1099 | dalvikMax, dalvikAllocated, dalvikFree); |
| 1100 | |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 1101 | if (checkin) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1102 | // NOTE: if you change anything significant below, also consider changing |
| 1103 | // ACTIVITY_THREAD_CHECKIN_VERSION. |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 1104 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1105 | // Object counts |
| 1106 | pw.print(viewInstanceCount); pw.print(','); |
| 1107 | pw.print(viewRootInstanceCount); pw.print(','); |
| 1108 | pw.print(appContextInstanceCount); pw.print(','); |
| 1109 | pw.print(activityInstanceCount); pw.print(','); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1110 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1111 | pw.print(globalAssetCount); pw.print(','); |
| 1112 | pw.print(globalAssetManagerCount); pw.print(','); |
| 1113 | pw.print(binderLocalObjectCount); pw.print(','); |
| 1114 | pw.print(binderProxyObjectCount); pw.print(','); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1115 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1116 | pw.print(binderDeathObjectCount); pw.print(','); |
| 1117 | pw.print(openSslSocketCount); pw.print(','); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1118 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1119 | // SQL |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1120 | pw.print(stats.memoryUsed / 1024); pw.print(','); |
Jeff Brown | 2a293b6 | 2012-01-19 14:02:22 -0800 | [diff] [blame] | 1121 | pw.print(stats.memoryUsed / 1024); pw.print(','); |
| 1122 | pw.print(stats.pageCacheOverflow / 1024); pw.print(','); |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 1123 | pw.print(stats.largestMemAlloc / 1024); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1124 | for (int i = 0; i < stats.dbStats.size(); i++) { |
| 1125 | DbStats dbStats = stats.dbStats.get(i); |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 1126 | pw.print(','); pw.print(dbStats.dbName); |
| 1127 | pw.print(','); pw.print(dbStats.pageSize); |
| 1128 | pw.print(','); pw.print(dbStats.dbSize); |
| 1129 | pw.print(','); pw.print(dbStats.lookaside); |
| 1130 | pw.print(','); pw.print(dbStats.cache); |
| 1131 | pw.print(','); pw.print(dbStats.cache); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1132 | } |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 1133 | pw.println(); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1134 | |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 1135 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1136 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1137 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1138 | pw.println(" "); |
| 1139 | pw.println(" Objects"); |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1140 | printRow(pw, TWO_COUNT_COLUMNS, "Views:", viewInstanceCount, "ViewRootImpl:", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1141 | viewRootInstanceCount); |
| 1142 | |
| 1143 | printRow(pw, TWO_COUNT_COLUMNS, "AppContexts:", appContextInstanceCount, |
| 1144 | "Activities:", activityInstanceCount); |
| 1145 | |
| 1146 | printRow(pw, TWO_COUNT_COLUMNS, "Assets:", globalAssetCount, |
| 1147 | "AssetManagers:", globalAssetManagerCount); |
| 1148 | |
| 1149 | printRow(pw, TWO_COUNT_COLUMNS, "Local Binders:", binderLocalObjectCount, |
| 1150 | "Proxy Binders:", binderProxyObjectCount); |
Dianne Hackborn | fabb70b | 2014-11-11 12:22:36 -0800 | [diff] [blame] | 1151 | printRow(pw, TWO_COUNT_COLUMNS, "Parcel memory:", parcelSize/1024, |
| 1152 | "Parcel count:", parcelCount); |
| 1153 | printRow(pw, TWO_COUNT_COLUMNS, "Death Recipients:", binderDeathObjectCount, |
| 1154 | "OpenSSL Sockets:", openSslSocketCount); |
Richard Uhler | 2c03619 | 2016-09-14 09:48:31 +0100 | [diff] [blame] | 1155 | printRow(pw, ONE_COUNT_COLUMN, "WebViews:", webviewInstanceCount); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1156 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1157 | // SQLite mem info |
| 1158 | pw.println(" "); |
| 1159 | pw.println(" SQL"); |
Jeff Brown | 2a293b6 | 2012-01-19 14:02:22 -0800 | [diff] [blame] | 1160 | printRow(pw, ONE_COUNT_COLUMN, "MEMORY_USED:", stats.memoryUsed / 1024); |
| 1161 | printRow(pw, TWO_COUNT_COLUMNS, "PAGECACHE_OVERFLOW:", |
| 1162 | stats.pageCacheOverflow / 1024, "MALLOC_SIZE:", stats.largestMemAlloc / 1024); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1163 | pw.println(" "); |
| 1164 | int N = stats.dbStats.size(); |
| 1165 | if (N > 0) { |
| 1166 | pw.println(" DATABASES"); |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 1167 | printRow(pw, DB_INFO_FORMAT, "pgsz", "dbsz", "Lookaside(b)", "cache", |
Vasu Nori | 3c7131f | 2010-09-21 14:36:57 -0700 | [diff] [blame] | 1168 | "Dbname"); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1169 | for (int i = 0; i < N; i++) { |
| 1170 | DbStats dbStats = stats.dbStats.get(i); |
Vasu Nori | 3c7131f | 2010-09-21 14:36:57 -0700 | [diff] [blame] | 1171 | printRow(pw, DB_INFO_FORMAT, |
| 1172 | (dbStats.pageSize > 0) ? String.valueOf(dbStats.pageSize) : " ", |
| 1173 | (dbStats.dbSize > 0) ? String.valueOf(dbStats.dbSize) : " ", |
| 1174 | (dbStats.lookaside > 0) ? String.valueOf(dbStats.lookaside) : " ", |
| 1175 | dbStats.cache, dbStats.dbName); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1176 | } |
| 1177 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1178 | |
Dianne Hackborn | 82e1ee9 | 2009-08-11 18:56:41 -0700 | [diff] [blame] | 1179 | // Asset details. |
| 1180 | String assetAlloc = AssetManager.getAssetAllocations(); |
| 1181 | if (assetAlloc != null) { |
| 1182 | pw.println(" "); |
| 1183 | pw.println(" Asset Allocations"); |
| 1184 | pw.print(assetAlloc); |
| 1185 | } |
Colin Cross | c4fb5f9 | 2016-02-02 16:51:15 -0800 | [diff] [blame] | 1186 | |
| 1187 | // Unreachable native memory |
| 1188 | if (dumpUnreachable) { |
| 1189 | boolean showContents = ((mBoundApplication != null) |
| 1190 | && ((mBoundApplication.appInfo.flags&ApplicationInfo.FLAG_DEBUGGABLE) != 0)) |
| 1191 | || android.os.Build.IS_DEBUGGABLE; |
| 1192 | pw.println(" "); |
| 1193 | pw.println(" Unreachable memory"); |
| 1194 | pw.print(Debug.getUnreachableMemory(100, showContents)); |
| 1195 | } |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 1196 | } |
| 1197 | |
| 1198 | @Override |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 1199 | public void dumpMemInfoProto(ParcelFileDescriptor pfd, Debug.MemoryInfo mem, |
| 1200 | boolean dumpFullInfo, boolean dumpDalvik, boolean dumpSummaryOnly, |
| 1201 | boolean dumpUnreachable, String[] args) { |
| 1202 | ProtoOutputStream proto = new ProtoOutputStream(pfd.getFileDescriptor()); |
| 1203 | try { |
| 1204 | dumpMemInfo(proto, mem, dumpFullInfo, dumpDalvik, dumpSummaryOnly, dumpUnreachable); |
| 1205 | } finally { |
| 1206 | proto.flush(); |
| 1207 | IoUtils.closeQuietly(pfd); |
| 1208 | } |
| 1209 | } |
| 1210 | |
| 1211 | private void dumpMemInfo(ProtoOutputStream proto, Debug.MemoryInfo memInfo, |
| 1212 | boolean dumpFullInfo, boolean dumpDalvik, |
| 1213 | boolean dumpSummaryOnly, boolean dumpUnreachable) { |
| 1214 | long nativeMax = Debug.getNativeHeapSize() / 1024; |
| 1215 | long nativeAllocated = Debug.getNativeHeapAllocatedSize() / 1024; |
| 1216 | long nativeFree = Debug.getNativeHeapFreeSize() / 1024; |
| 1217 | |
| 1218 | Runtime runtime = Runtime.getRuntime(); |
| 1219 | runtime.gc(); // Do GC since countInstancesOfClass counts unreachable objects. |
| 1220 | long dalvikMax = runtime.totalMemory() / 1024; |
| 1221 | long dalvikFree = runtime.freeMemory() / 1024; |
| 1222 | long dalvikAllocated = dalvikMax - dalvikFree; |
| 1223 | |
| 1224 | Class[] classesToCount = new Class[] { |
| 1225 | ContextImpl.class, |
| 1226 | Activity.class, |
| 1227 | WebView.class, |
| 1228 | OpenSSLSocketImpl.class |
| 1229 | }; |
| 1230 | long[] instanceCounts = VMDebug.countInstancesOfClasses(classesToCount, true); |
| 1231 | long appContextInstanceCount = instanceCounts[0]; |
| 1232 | long activityInstanceCount = instanceCounts[1]; |
| 1233 | long webviewInstanceCount = instanceCounts[2]; |
| 1234 | long openSslSocketCount = instanceCounts[3]; |
| 1235 | |
| 1236 | long viewInstanceCount = ViewDebug.getViewInstanceCount(); |
| 1237 | long viewRootInstanceCount = ViewDebug.getViewRootImplCount(); |
| 1238 | int globalAssetCount = AssetManager.getGlobalAssetCount(); |
| 1239 | int globalAssetManagerCount = AssetManager.getGlobalAssetManagerCount(); |
| 1240 | int binderLocalObjectCount = Debug.getBinderLocalObjectCount(); |
| 1241 | int binderProxyObjectCount = Debug.getBinderProxyObjectCount(); |
| 1242 | int binderDeathObjectCount = Debug.getBinderDeathObjectCount(); |
| 1243 | long parcelSize = Parcel.getGlobalAllocSize(); |
| 1244 | long parcelCount = Parcel.getGlobalAllocCount(); |
| 1245 | SQLiteDebug.PagerStats stats = SQLiteDebug.getDatabaseInfo(); |
| 1246 | |
| 1247 | final long mToken = proto.start(MemInfoProto.AppData.PROCESS_MEMORY); |
| 1248 | proto.write(MemInfoProto.ProcessMemory.PID, Process.myPid()); |
| 1249 | proto.write(MemInfoProto.ProcessMemory.PROCESS_NAME, |
| 1250 | (mBoundApplication != null) ? mBoundApplication.processName : "unknown"); |
| 1251 | dumpMemInfoTable(proto, memInfo, dumpDalvik, dumpSummaryOnly, |
| 1252 | nativeMax, nativeAllocated, nativeFree, |
| 1253 | dalvikMax, dalvikAllocated, dalvikFree); |
| 1254 | proto.end(mToken); |
| 1255 | |
| 1256 | final long oToken = proto.start(MemInfoProto.AppData.OBJECTS); |
| 1257 | proto.write(MemInfoProto.AppData.ObjectStats.VIEW_INSTANCE_COUNT, viewInstanceCount); |
| 1258 | proto.write(MemInfoProto.AppData.ObjectStats.VIEW_ROOT_INSTANCE_COUNT, |
| 1259 | viewRootInstanceCount); |
| 1260 | proto.write(MemInfoProto.AppData.ObjectStats.APP_CONTEXT_INSTANCE_COUNT, |
| 1261 | appContextInstanceCount); |
| 1262 | proto.write(MemInfoProto.AppData.ObjectStats.ACTIVITY_INSTANCE_COUNT, |
| 1263 | activityInstanceCount); |
| 1264 | proto.write(MemInfoProto.AppData.ObjectStats.GLOBAL_ASSET_COUNT, globalAssetCount); |
| 1265 | proto.write(MemInfoProto.AppData.ObjectStats.GLOBAL_ASSET_MANAGER_COUNT, |
| 1266 | globalAssetManagerCount); |
| 1267 | proto.write(MemInfoProto.AppData.ObjectStats.LOCAL_BINDER_OBJECT_COUNT, |
| 1268 | binderLocalObjectCount); |
| 1269 | proto.write(MemInfoProto.AppData.ObjectStats.PROXY_BINDER_OBJECT_COUNT, |
| 1270 | binderProxyObjectCount); |
| 1271 | proto.write(MemInfoProto.AppData.ObjectStats.PARCEL_MEMORY_KB, parcelSize / 1024); |
| 1272 | proto.write(MemInfoProto.AppData.ObjectStats.PARCEL_COUNT, parcelCount); |
| 1273 | proto.write(MemInfoProto.AppData.ObjectStats.BINDER_OBJECT_DEATH_COUNT, |
| 1274 | binderDeathObjectCount); |
| 1275 | proto.write(MemInfoProto.AppData.ObjectStats.OPEN_SSL_SOCKET_COUNT, openSslSocketCount); |
| 1276 | proto.write(MemInfoProto.AppData.ObjectStats.WEBVIEW_INSTANCE_COUNT, |
| 1277 | webviewInstanceCount); |
| 1278 | proto.end(oToken); |
| 1279 | |
| 1280 | // SQLite mem info |
| 1281 | final long sToken = proto.start(MemInfoProto.AppData.SQL); |
| 1282 | proto.write(MemInfoProto.AppData.SqlStats.MEMORY_USED_KB, stats.memoryUsed / 1024); |
| 1283 | proto.write(MemInfoProto.AppData.SqlStats.PAGECACHE_OVERFLOW_KB, |
| 1284 | stats.pageCacheOverflow / 1024); |
| 1285 | proto.write(MemInfoProto.AppData.SqlStats.MALLOC_SIZE_KB, stats.largestMemAlloc / 1024); |
| 1286 | int n = stats.dbStats.size(); |
| 1287 | for (int i = 0; i < n; i++) { |
| 1288 | DbStats dbStats = stats.dbStats.get(i); |
| 1289 | |
| 1290 | final long dToken = proto.start(MemInfoProto.AppData.SqlStats.DATABASES); |
| 1291 | proto.write(MemInfoProto.AppData.SqlStats.Database.NAME, dbStats.dbName); |
| 1292 | proto.write(MemInfoProto.AppData.SqlStats.Database.PAGE_SIZE, dbStats.pageSize); |
| 1293 | proto.write(MemInfoProto.AppData.SqlStats.Database.DB_SIZE, dbStats.dbSize); |
| 1294 | proto.write(MemInfoProto.AppData.SqlStats.Database.LOOKASIDE_B, dbStats.lookaside); |
| 1295 | proto.write(MemInfoProto.AppData.SqlStats.Database.CACHE, dbStats.cache); |
| 1296 | proto.end(dToken); |
| 1297 | } |
| 1298 | proto.end(sToken); |
| 1299 | |
| 1300 | // Asset details. |
| 1301 | String assetAlloc = AssetManager.getAssetAllocations(); |
| 1302 | if (assetAlloc != null) { |
| 1303 | proto.write(MemInfoProto.AppData.ASSET_ALLOCATIONS, assetAlloc); |
| 1304 | } |
| 1305 | |
| 1306 | // Unreachable native memory |
| 1307 | if (dumpUnreachable) { |
| 1308 | int flags = mBoundApplication == null ? 0 : mBoundApplication.appInfo.flags; |
| 1309 | boolean showContents = (flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0 |
| 1310 | || android.os.Build.IS_DEBUGGABLE; |
| 1311 | proto.write(MemInfoProto.AppData.UNREACHABLE_MEMORY, |
| 1312 | Debug.getUnreachableMemory(100, showContents)); |
| 1313 | } |
| 1314 | } |
| 1315 | |
| 1316 | @Override |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1317 | public void dumpGfxInfo(ParcelFileDescriptor pfd, String[] args) { |
Chris Craik | fc29424 | 2016-12-13 18:10:46 -0800 | [diff] [blame] | 1318 | nDumpGraphicsInfo(pfd.getFileDescriptor()); |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1319 | WindowManagerGlobal.getInstance().dumpGfxInfo(pfd.getFileDescriptor(), args); |
| 1320 | IoUtils.closeQuietly(pfd); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1321 | } |
| 1322 | |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1323 | private void dumpDatabaseInfo(ParcelFileDescriptor pfd, String[] args) { |
| 1324 | PrintWriter pw = new FastPrintWriter( |
| 1325 | new FileOutputStream(pfd.getFileDescriptor())); |
Jeff Brown | 6754ba2 | 2011-12-14 20:20:01 -0800 | [diff] [blame] | 1326 | PrintWriterPrinter printer = new PrintWriterPrinter(pw); |
| 1327 | SQLiteDebug.dump(printer, args); |
| 1328 | pw.flush(); |
| 1329 | } |
| 1330 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1331 | @Override |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1332 | public void dumpDbInfo(final ParcelFileDescriptor pfd, final String[] args) { |
riddle_hsu | 1d6c40a | 2014-07-31 00:18:00 +0800 | [diff] [blame] | 1333 | if (mSystemThread) { |
Felipe Leme | 29de492 | 2016-06-07 16:14:07 -0700 | [diff] [blame] | 1334 | // Ensure this invocation is asynchronous to prevent writer waiting if buffer cannot |
| 1335 | // be consumed. But it must duplicate the file descriptor first, since caller might |
| 1336 | // be closing it. |
| 1337 | final ParcelFileDescriptor dup; |
| 1338 | try { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1339 | dup = pfd.dup(); |
Felipe Leme | 29de492 | 2016-06-07 16:14:07 -0700 | [diff] [blame] | 1340 | } catch (IOException e) { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1341 | Log.w(TAG, "Could not dup FD " + pfd.getFileDescriptor().getInt$()); |
Felipe Leme | 29de492 | 2016-06-07 16:14:07 -0700 | [diff] [blame] | 1342 | return; |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1343 | } finally { |
| 1344 | IoUtils.closeQuietly(pfd); |
Felipe Leme | 29de492 | 2016-06-07 16:14:07 -0700 | [diff] [blame] | 1345 | } |
| 1346 | |
riddle_hsu | 1d6c40a | 2014-07-31 00:18:00 +0800 | [diff] [blame] | 1347 | AsyncTask.THREAD_POOL_EXECUTOR.execute(new Runnable() { |
| 1348 | @Override |
| 1349 | public void run() { |
Felipe Leme | c74972f | 2016-06-08 09:12:37 -0700 | [diff] [blame] | 1350 | try { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1351 | dumpDatabaseInfo(dup, args); |
Felipe Leme | c74972f | 2016-06-08 09:12:37 -0700 | [diff] [blame] | 1352 | } finally { |
| 1353 | IoUtils.closeQuietly(dup); |
| 1354 | } |
riddle_hsu | 1d6c40a | 2014-07-31 00:18:00 +0800 | [diff] [blame] | 1355 | } |
| 1356 | }); |
| 1357 | } else { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1358 | dumpDatabaseInfo(pfd, args); |
| 1359 | IoUtils.closeQuietly(pfd); |
riddle_hsu | 1d6c40a | 2014-07-31 00:18:00 +0800 | [diff] [blame] | 1360 | } |
| 1361 | } |
| 1362 | |
| 1363 | @Override |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1364 | public void unstableProviderDied(IBinder provider) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1365 | sendMessage(H.UNSTABLE_PROVIDER_DIED, provider); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1366 | } |
| 1367 | |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 1368 | @Override |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 1369 | public void requestAssistContextExtras(IBinder activityToken, IBinder requestToken, |
Svet Ganov | fd31f85 | 2017-04-26 15:54:27 -0700 | [diff] [blame] | 1370 | int requestType, int sessionId, int flags) { |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 1371 | RequestAssistContextExtras cmd = new RequestAssistContextExtras(); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 1372 | cmd.activityToken = activityToken; |
| 1373 | cmd.requestToken = requestToken; |
| 1374 | cmd.requestType = requestType; |
Amith Yamasani | 4f128e4 | 2016-05-10 11:44:12 -0700 | [diff] [blame] | 1375 | cmd.sessionId = sessionId; |
Svet Ganov | fd31f85 | 2017-04-26 15:54:27 -0700 | [diff] [blame] | 1376 | cmd.flags = flags; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1377 | sendMessage(H.REQUEST_ASSIST_CONTEXT_EXTRAS, cmd); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 1378 | } |
| 1379 | |
Svetoslav Ganov | 9aa597e | 2011-03-03 18:17:41 -0800 | [diff] [blame] | 1380 | public void setCoreSettings(Bundle coreSettings) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1381 | sendMessage(H.SET_CORE_SETTINGS, coreSettings); |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1382 | } |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1383 | |
| 1384 | public void updatePackageCompatibilityInfo(String pkg, CompatibilityInfo info) { |
| 1385 | UpdateCompatibilityData ucd = new UpdateCompatibilityData(); |
| 1386 | ucd.pkg = pkg; |
| 1387 | ucd.info = info; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1388 | sendMessage(H.UPDATE_PACKAGE_COMPATIBILITY_INFO, ucd); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1389 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1390 | |
| 1391 | public void scheduleTrimMemory(int level) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1392 | sendMessage(H.TRIM_MEMORY, null, level); |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1393 | } |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1394 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1395 | public void scheduleTranslucentConversionComplete(IBinder token, boolean drawComplete) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1396 | sendMessage(H.TRANSLUCENT_CONVERSION_COMPLETE, token, drawComplete ? 1 : 0); |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1397 | } |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 1398 | |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1399 | public void scheduleOnNewActivityOptions(IBinder token, Bundle options) { |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1400 | sendMessage(H.ON_NEW_ACTIVITY_OPTIONS, |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1401 | new Pair<IBinder, ActivityOptions>(token, ActivityOptions.fromBundle(options))); |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1402 | } |
| 1403 | |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 1404 | public void setProcessState(int state) { |
| 1405 | updateProcessState(state, true); |
| 1406 | } |
| 1407 | |
| 1408 | public void updateProcessState(int processState, boolean fromIpc) { |
| 1409 | synchronized (this) { |
| 1410 | if (mLastProcessState != processState) { |
| 1411 | mLastProcessState = processState; |
Mathieu Chartier | 1e37090 | 2013-07-18 10:58:01 -0700 | [diff] [blame] | 1412 | // Update Dalvik state based on ActivityManager.PROCESS_STATE_* constants. |
| 1413 | final int DALVIK_PROCESS_STATE_JANK_PERCEPTIBLE = 0; |
| 1414 | final int DALVIK_PROCESS_STATE_JANK_IMPERCEPTIBLE = 1; |
| 1415 | int dalvikProcessState = DALVIK_PROCESS_STATE_JANK_IMPERCEPTIBLE; |
| 1416 | // TODO: Tune this since things like gmail sync are important background but not jank perceptible. |
| 1417 | if (processState <= ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND) { |
| 1418 | dalvikProcessState = DALVIK_PROCESS_STATE_JANK_PERCEPTIBLE; |
| 1419 | } |
| 1420 | VMRuntime.getRuntime().updateProcessState(dalvikProcessState); |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 1421 | if (false) { |
| 1422 | Slog.i(TAG, "******************* PROCESS STATE CHANGED TO: " + processState |
| 1423 | + (fromIpc ? " (from ipc": "")); |
| 1424 | } |
| 1425 | } |
| 1426 | } |
| 1427 | } |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 1428 | |
Sudheer Shanka | 84a4895 | 2017-03-08 18:19:01 -0800 | [diff] [blame] | 1429 | /** |
| 1430 | * Updates {@link #mNetworkBlockSeq}. This is used by ActivityManagerService to inform |
| 1431 | * the main thread that it needs to wait for the network rules to get updated before |
| 1432 | * launching an activity. |
| 1433 | */ |
| 1434 | @Override |
| 1435 | public void setNetworkBlockSeq(long procStateSeq) { |
| 1436 | synchronized (mNetworkPolicyLock) { |
| 1437 | mNetworkBlockSeq = procStateSeq; |
| 1438 | } |
| 1439 | } |
| 1440 | |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 1441 | @Override |
| 1442 | public void scheduleInstallProvider(ProviderInfo provider) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1443 | sendMessage(H.INSTALL_PROVIDER, provider); |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 1444 | } |
Narayan Kamath | ccb2a086 | 2013-12-19 14:49:36 +0000 | [diff] [blame] | 1445 | |
| 1446 | @Override |
Neil Fuller | b7146fe | 2016-11-15 16:52:15 +0000 | [diff] [blame] | 1447 | public final void updateTimePrefs(int timeFormatPreference) { |
| 1448 | final Boolean timeFormatPreferenceBool; |
| 1449 | // For convenience we are using the Intent extra values. |
| 1450 | if (timeFormatPreference == Intent.EXTRA_TIME_PREF_VALUE_USE_12_HOUR) { |
| 1451 | timeFormatPreferenceBool = Boolean.FALSE; |
| 1452 | } else if (timeFormatPreference == Intent.EXTRA_TIME_PREF_VALUE_USE_24_HOUR) { |
| 1453 | timeFormatPreferenceBool = Boolean.TRUE; |
| 1454 | } else { |
| 1455 | // timeFormatPreference == Intent.EXTRA_TIME_PREF_VALUE_USE_LOCALE_DEFAULT |
| 1456 | // (or unknown). |
| 1457 | timeFormatPreferenceBool = null; |
| 1458 | } |
| 1459 | DateFormat.set24HourTimePref(timeFormatPreferenceBool); |
Narayan Kamath | ccb2a086 | 2013-12-19 14:49:36 +0000 | [diff] [blame] | 1460 | } |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 1461 | |
| 1462 | @Override |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 1463 | public void scheduleEnterAnimationComplete(IBinder token) { |
| 1464 | sendMessage(H.ENTER_ANIMATION_COMPLETE, token); |
| 1465 | } |
Jeff Sharkey | 605eb79 | 2014-11-04 13:34:06 -0800 | [diff] [blame] | 1466 | |
| 1467 | @Override |
| 1468 | public void notifyCleartextNetwork(byte[] firstPacket) { |
| 1469 | if (StrictMode.vmCleartextNetworkEnabled()) { |
| 1470 | StrictMode.onCleartextNetworkDetected(firstPacket); |
| 1471 | } |
| 1472 | } |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 1473 | |
| 1474 | @Override |
| 1475 | public void startBinderTracking() { |
| 1476 | sendMessage(H.START_BINDER_TRACKING, null); |
| 1477 | } |
| 1478 | |
| 1479 | @Override |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1480 | public void stopBinderTrackingAndDump(ParcelFileDescriptor pfd) { |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 1481 | try { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1482 | sendMessage(H.STOP_BINDER_TRACKING_AND_DUMP, pfd.dup()); |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 1483 | } catch (IOException e) { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1484 | } finally { |
| 1485 | IoUtils.closeQuietly(pfd); |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 1486 | } |
| 1487 | } |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 1488 | |
| 1489 | @Override |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1490 | public void scheduleLocalVoiceInteractionStarted(IBinder token, |
| 1491 | IVoiceInteractor voiceInteractor) throws RemoteException { |
| 1492 | SomeArgs args = SomeArgs.obtain(); |
| 1493 | args.arg1 = token; |
| 1494 | args.arg2 = voiceInteractor; |
| 1495 | sendMessage(H.LOCAL_VOICE_INTERACTION_STARTED, args); |
| 1496 | } |
Chad Brubaker | c72875b | 2016-04-27 16:35:11 -0700 | [diff] [blame] | 1497 | |
| 1498 | @Override |
| 1499 | public void handleTrustStorageUpdate() { |
| 1500 | NetworkSecurityPolicy.getInstance().handleTrustStorageUpdate(); |
| 1501 | } |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 1502 | |
| 1503 | @Override |
| 1504 | public void scheduleTransaction(ClientTransaction transaction) throws RemoteException { |
| 1505 | ActivityThread.this.scheduleTransaction(transaction); |
| 1506 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1507 | } |
| 1508 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 1509 | @Override |
| 1510 | public void updatePendingConfiguration(Configuration config) { |
| 1511 | mAppThread.updatePendingConfiguration(config); |
| 1512 | } |
| 1513 | |
| 1514 | @Override |
| 1515 | public void updateProcessState(int processState, boolean fromIpc) { |
| 1516 | mAppThread.updateProcessState(processState, fromIpc); |
| 1517 | } |
| 1518 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 1519 | class H extends Handler { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1520 | public static final int BIND_APPLICATION = 110; |
| 1521 | public static final int EXIT_APPLICATION = 111; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1522 | public static final int RECEIVER = 113; |
| 1523 | public static final int CREATE_SERVICE = 114; |
| 1524 | public static final int SERVICE_ARGS = 115; |
| 1525 | public static final int STOP_SERVICE = 116; |
Dianne Hackborn | 0923328 | 2014-04-30 11:33:59 -0700 | [diff] [blame] | 1526 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1527 | public static final int CONFIGURATION_CHANGED = 118; |
| 1528 | public static final int CLEAN_UP_CONTEXT = 119; |
| 1529 | public static final int GC_WHEN_IDLE = 120; |
| 1530 | public static final int BIND_SERVICE = 121; |
| 1531 | public static final int UNBIND_SERVICE = 122; |
| 1532 | public static final int DUMP_SERVICE = 123; |
| 1533 | public static final int LOW_MEMORY = 124; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1534 | public static final int RELAUNCH_ACTIVITY = 126; |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 1535 | public static final int PROFILER_CONTROL = 127; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1536 | public static final int CREATE_BACKUP_AGENT = 128; |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 1537 | public static final int DESTROY_BACKUP_AGENT = 129; |
| 1538 | public static final int SUICIDE = 130; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1539 | public static final int REMOVE_PROVIDER = 131; |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 1540 | public static final int ENABLE_JIT = 132; |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1541 | public static final int DISPATCH_PACKAGE_BROADCAST = 133; |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 1542 | public static final int SCHEDULE_CRASH = 134; |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 1543 | public static final int DUMP_HEAP = 135; |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1544 | public static final int DUMP_ACTIVITY = 136; |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1545 | public static final int SLEEPING = 137; |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1546 | public static final int SET_CORE_SETTINGS = 138; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1547 | public static final int UPDATE_PACKAGE_COMPATIBILITY_INFO = 139; |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1548 | public static final int TRIM_MEMORY = 140; |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1549 | public static final int DUMP_PROVIDER = 141; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1550 | public static final int UNSTABLE_PROVIDER_DIED = 142; |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 1551 | public static final int REQUEST_ASSIST_CONTEXT_EXTRAS = 143; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1552 | public static final int TRANSLUCENT_CONVERSION_COMPLETE = 144; |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 1553 | public static final int INSTALL_PROVIDER = 145; |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1554 | public static final int ON_NEW_ACTIVITY_OPTIONS = 146; |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 1555 | public static final int ENTER_ANIMATION_COMPLETE = 149; |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 1556 | public static final int START_BINDER_TRACKING = 150; |
| 1557 | public static final int STOP_BINDER_TRACKING_AND_DUMP = 151; |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1558 | public static final int LOCAL_VOICE_INTERACTION_STARTED = 154; |
Leonard Mosescu | f3409ce | 2016-10-06 17:32:05 -0700 | [diff] [blame] | 1559 | public static final int ATTACH_AGENT = 155; |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 1560 | public static final int APPLICATION_INFO_CHANGED = 156; |
Torne (Richard Coles) | 466cbe4 | 2017-05-31 14:09:14 -0400 | [diff] [blame] | 1561 | public static final int RUN_ISOLATED_ENTRY_POINT = 158; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 1562 | public static final int EXECUTE_TRANSACTION = 159; |
Narayan Kamath | ccb2a086 | 2013-12-19 14:49:36 +0000 | [diff] [blame] | 1563 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1564 | String codeToString(int code) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 1565 | if (DEBUG_MESSAGES) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1566 | switch (code) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1567 | case BIND_APPLICATION: return "BIND_APPLICATION"; |
| 1568 | case EXIT_APPLICATION: return "EXIT_APPLICATION"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1569 | case RECEIVER: return "RECEIVER"; |
| 1570 | case CREATE_SERVICE: return "CREATE_SERVICE"; |
| 1571 | case SERVICE_ARGS: return "SERVICE_ARGS"; |
| 1572 | case STOP_SERVICE: return "STOP_SERVICE"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1573 | case CONFIGURATION_CHANGED: return "CONFIGURATION_CHANGED"; |
| 1574 | case CLEAN_UP_CONTEXT: return "CLEAN_UP_CONTEXT"; |
| 1575 | case GC_WHEN_IDLE: return "GC_WHEN_IDLE"; |
| 1576 | case BIND_SERVICE: return "BIND_SERVICE"; |
| 1577 | case UNBIND_SERVICE: return "UNBIND_SERVICE"; |
| 1578 | case DUMP_SERVICE: return "DUMP_SERVICE"; |
| 1579 | case LOW_MEMORY: return "LOW_MEMORY"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1580 | case RELAUNCH_ACTIVITY: return "RELAUNCH_ACTIVITY"; |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 1581 | case PROFILER_CONTROL: return "PROFILER_CONTROL"; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1582 | case CREATE_BACKUP_AGENT: return "CREATE_BACKUP_AGENT"; |
| 1583 | case DESTROY_BACKUP_AGENT: return "DESTROY_BACKUP_AGENT"; |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 1584 | case SUICIDE: return "SUICIDE"; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1585 | case REMOVE_PROVIDER: return "REMOVE_PROVIDER"; |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 1586 | case ENABLE_JIT: return "ENABLE_JIT"; |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1587 | case DISPATCH_PACKAGE_BROADCAST: return "DISPATCH_PACKAGE_BROADCAST"; |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 1588 | case SCHEDULE_CRASH: return "SCHEDULE_CRASH"; |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 1589 | case DUMP_HEAP: return "DUMP_HEAP"; |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1590 | case DUMP_ACTIVITY: return "DUMP_ACTIVITY"; |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1591 | case SLEEPING: return "SLEEPING"; |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1592 | case SET_CORE_SETTINGS: return "SET_CORE_SETTINGS"; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1593 | case UPDATE_PACKAGE_COMPATIBILITY_INFO: return "UPDATE_PACKAGE_COMPATIBILITY_INFO"; |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1594 | case TRIM_MEMORY: return "TRIM_MEMORY"; |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1595 | case DUMP_PROVIDER: return "DUMP_PROVIDER"; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1596 | case UNSTABLE_PROVIDER_DIED: return "UNSTABLE_PROVIDER_DIED"; |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 1597 | case REQUEST_ASSIST_CONTEXT_EXTRAS: return "REQUEST_ASSIST_CONTEXT_EXTRAS"; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1598 | case TRANSLUCENT_CONVERSION_COMPLETE: return "TRANSLUCENT_CONVERSION_COMPLETE"; |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 1599 | case INSTALL_PROVIDER: return "INSTALL_PROVIDER"; |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1600 | case ON_NEW_ACTIVITY_OPTIONS: return "ON_NEW_ACTIVITY_OPTIONS"; |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 1601 | case ENTER_ANIMATION_COMPLETE: return "ENTER_ANIMATION_COMPLETE"; |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1602 | case LOCAL_VOICE_INTERACTION_STARTED: return "LOCAL_VOICE_INTERACTION_STARTED"; |
Leonard Mosescu | f3409ce | 2016-10-06 17:32:05 -0700 | [diff] [blame] | 1603 | case ATTACH_AGENT: return "ATTACH_AGENT"; |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 1604 | case APPLICATION_INFO_CHANGED: return "APPLICATION_INFO_CHANGED"; |
Torne (Richard Coles) | 466cbe4 | 2017-05-31 14:09:14 -0400 | [diff] [blame] | 1605 | case RUN_ISOLATED_ENTRY_POINT: return "RUN_ISOLATED_ENTRY_POINT"; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 1606 | case EXECUTE_TRANSACTION: return "EXECUTE_TRANSACTION"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1607 | } |
| 1608 | } |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 1609 | return Integer.toString(code); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1610 | } |
| 1611 | public void handleMessage(Message msg) { |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 1612 | 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] | 1613 | switch (msg.what) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1614 | case RELAUNCH_ACTIVITY: { |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1615 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityRestart"); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1616 | ActivityClientRecord r = (ActivityClientRecord)msg.obj; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 1617 | handleRelaunchActivity(r); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1618 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1619 | } break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1620 | case BIND_APPLICATION: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1621 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "bindApplication"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1622 | AppBindData data = (AppBindData)msg.obj; |
| 1623 | handleBindApplication(data); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1624 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1625 | break; |
| 1626 | case EXIT_APPLICATION: |
| 1627 | if (mInitialApplication != null) { |
| 1628 | mInitialApplication.onTerminate(); |
| 1629 | } |
| 1630 | Looper.myLooper().quit(); |
| 1631 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1632 | case RECEIVER: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1633 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "broadcastReceiveComp"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1634 | handleReceiver((ReceiverData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1635 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1636 | break; |
| 1637 | case CREATE_SERVICE: |
Tim Murray | b6f5a42 | 2016-04-07 15:25:22 -0700 | [diff] [blame] | 1638 | 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] | 1639 | handleCreateService((CreateServiceData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1640 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1641 | break; |
| 1642 | case BIND_SERVICE: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1643 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "serviceBind"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1644 | handleBindService((BindServiceData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1645 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1646 | break; |
| 1647 | case UNBIND_SERVICE: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1648 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "serviceUnbind"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1649 | handleUnbindService((BindServiceData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1650 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1651 | break; |
| 1652 | case SERVICE_ARGS: |
Tim Murray | b6f5a42 | 2016-04-07 15:25:22 -0700 | [diff] [blame] | 1653 | 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] | 1654 | handleServiceArgs((ServiceArgsData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1655 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1656 | break; |
| 1657 | case STOP_SERVICE: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1658 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "serviceStop"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1659 | handleStopService((IBinder)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1660 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1661 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1662 | case CONFIGURATION_CHANGED: |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 1663 | handleConfigurationChanged((Configuration) msg.obj); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1664 | break; |
| 1665 | case CLEAN_UP_CONTEXT: |
| 1666 | ContextCleanupInfo cci = (ContextCleanupInfo)msg.obj; |
| 1667 | cci.context.performFinalCleanup(cci.who, cci.what); |
| 1668 | break; |
| 1669 | case GC_WHEN_IDLE: |
| 1670 | scheduleGcIdler(); |
| 1671 | break; |
| 1672 | case DUMP_SERVICE: |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1673 | handleDumpService((DumpComponentInfo)msg.obj); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1674 | break; |
| 1675 | case LOW_MEMORY: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1676 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "lowMemory"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1677 | handleLowMemory(); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1678 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1679 | break; |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 1680 | case PROFILER_CONTROL: |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 1681 | handleProfilerControl(msg.arg1 != 0, (ProfilerInfo)msg.obj, msg.arg2); |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 1682 | break; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1683 | case CREATE_BACKUP_AGENT: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1684 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "backupCreateAgent"); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1685 | handleCreateBackupAgent((CreateBackupAgentData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1686 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1687 | break; |
| 1688 | case DESTROY_BACKUP_AGENT: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1689 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "backupDestroyAgent"); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1690 | handleDestroyBackupAgent((CreateBackupAgentData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1691 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1692 | break; |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 1693 | case SUICIDE: |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1694 | Process.killProcess(Process.myPid()); |
| 1695 | break; |
| 1696 | case REMOVE_PROVIDER: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1697 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "providerRemove"); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1698 | completeRemoveProvider((ProviderRefCount)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1699 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 1700 | break; |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 1701 | case ENABLE_JIT: |
| 1702 | ensureJitEnabled(); |
| 1703 | break; |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1704 | case DISPATCH_PACKAGE_BROADCAST: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1705 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "broadcastPackage"); |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1706 | handleDispatchPackageBroadcast(msg.arg1, (String[])msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1707 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1708 | break; |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 1709 | case SCHEDULE_CRASH: |
| 1710 | throw new RemoteServiceException((String)msg.obj); |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 1711 | case DUMP_HEAP: |
Christopher Ferris | 8d652f8 | 2017-04-11 16:29:18 -0700 | [diff] [blame] | 1712 | handleDumpHeap((DumpHeapData) msg.obj); |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 1713 | break; |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1714 | case DUMP_ACTIVITY: |
| 1715 | handleDumpActivity((DumpComponentInfo)msg.obj); |
| 1716 | break; |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1717 | case DUMP_PROVIDER: |
| 1718 | handleDumpProvider((DumpComponentInfo)msg.obj); |
| 1719 | break; |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1720 | case SLEEPING: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1721 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "sleeping"); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1722 | handleSleeping((IBinder)msg.obj, msg.arg1 != 0); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1723 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1724 | break; |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1725 | case SET_CORE_SETTINGS: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1726 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "setCoreSettings"); |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1727 | handleSetCoreSettings((Bundle) msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1728 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1729 | break; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1730 | case UPDATE_PACKAGE_COMPATIBILITY_INFO: |
| 1731 | handleUpdatePackageCompatibilityInfo((UpdateCompatibilityData)msg.obj); |
Dianne Hackborn | f0754f5b | 2011-07-21 16:02:07 -0700 | [diff] [blame] | 1732 | break; |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1733 | case TRIM_MEMORY: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1734 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "trimMemory"); |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1735 | handleTrimMemory(msg.arg1); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1736 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Dianne Hackborn | f0754f5b | 2011-07-21 16:02:07 -0700 | [diff] [blame] | 1737 | break; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1738 | case UNSTABLE_PROVIDER_DIED: |
| 1739 | handleUnstableProviderDied((IBinder)msg.obj, false); |
| 1740 | break; |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 1741 | case REQUEST_ASSIST_CONTEXT_EXTRAS: |
| 1742 | handleRequestAssistContextExtras((RequestAssistContextExtras)msg.obj); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 1743 | break; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1744 | case TRANSLUCENT_CONVERSION_COMPLETE: |
| 1745 | handleTranslucentConversionComplete((IBinder)msg.obj, msg.arg1 == 1); |
| 1746 | break; |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 1747 | case INSTALL_PROVIDER: |
| 1748 | handleInstallProvider((ProviderInfo) msg.obj); |
| 1749 | break; |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1750 | case ON_NEW_ACTIVITY_OPTIONS: |
| 1751 | Pair<IBinder, ActivityOptions> pair = (Pair<IBinder, ActivityOptions>) msg.obj; |
| 1752 | onNewActivityOptions(pair.first, pair.second); |
Dake Gu | 7ef70b0 | 2014-07-08 18:37:12 -0700 | [diff] [blame] | 1753 | break; |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 1754 | case ENTER_ANIMATION_COMPLETE: |
| 1755 | handleEnterAnimationComplete((IBinder) msg.obj); |
| 1756 | break; |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 1757 | case START_BINDER_TRACKING: |
| 1758 | handleStartBinderTracking(); |
| 1759 | break; |
| 1760 | case STOP_BINDER_TRACKING_AND_DUMP: |
| 1761 | handleStopBinderTrackingAndDump((ParcelFileDescriptor) msg.obj); |
| 1762 | break; |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1763 | case LOCAL_VOICE_INTERACTION_STARTED: |
| 1764 | handleLocalVoiceInteractionStarted((IBinder) ((SomeArgs) msg.obj).arg1, |
| 1765 | (IVoiceInteractor) ((SomeArgs) msg.obj).arg2); |
Amith Yamasani | 6101911 | 2017-01-10 15:05:00 -0800 | [diff] [blame] | 1766 | break; |
Andreas Gampe | ab8a63b | 2018-01-05 13:55:15 -0800 | [diff] [blame] | 1767 | case ATTACH_AGENT: { |
| 1768 | Application app = getApplication(); |
| 1769 | handleAttachAgent((String) msg.obj, app != null ? app.mLoadedApk : null); |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1770 | break; |
Andreas Gampe | ab8a63b | 2018-01-05 13:55:15 -0800 | [diff] [blame] | 1771 | } |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 1772 | case APPLICATION_INFO_CHANGED: |
| 1773 | mUpdatingSystemConfig = true; |
| 1774 | try { |
| 1775 | handleApplicationInfoChanged((ApplicationInfo) msg.obj); |
| 1776 | } finally { |
| 1777 | mUpdatingSystemConfig = false; |
| 1778 | } |
| 1779 | break; |
Torne (Richard Coles) | 466cbe4 | 2017-05-31 14:09:14 -0400 | [diff] [blame] | 1780 | case RUN_ISOLATED_ENTRY_POINT: |
| 1781 | handleRunIsolatedEntryPoint((String) ((SomeArgs) msg.obj).arg1, |
| 1782 | (String[]) ((SomeArgs) msg.obj).arg2); |
| 1783 | break; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 1784 | case EXECUTE_TRANSACTION: |
Andrii Kulian | 0447068 | 2018-01-10 15:32:31 -0800 | [diff] [blame] | 1785 | final ClientTransaction transaction = (ClientTransaction) msg.obj; |
| 1786 | mTransactionExecutor.execute(transaction); |
| 1787 | if (isSystem()) { |
| 1788 | // Client transactions inside system process are recycled on the client side |
| 1789 | // instead of ClientLifecycleManager to avoid being cleared before this |
| 1790 | // message is handled. |
| 1791 | transaction.recycle(); |
| 1792 | } |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 1793 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1794 | } |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1795 | Object obj = msg.obj; |
| 1796 | if (obj instanceof SomeArgs) { |
| 1797 | ((SomeArgs) obj).recycle(); |
| 1798 | } |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 1799 | 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] | 1800 | } |
| 1801 | } |
| 1802 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1803 | private class Idler implements MessageQueue.IdleHandler { |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 1804 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1805 | public final boolean queueIdle() { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1806 | ActivityClientRecord a = mNewActivities; |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 1807 | boolean stopProfiling = false; |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 1808 | if (mBoundApplication != null && mProfiler.profileFd != null |
| 1809 | && mProfiler.autoStopProfiler) { |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 1810 | stopProfiling = true; |
| 1811 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1812 | if (a != null) { |
| 1813 | mNewActivities = null; |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 1814 | IActivityManager am = ActivityManager.getService(); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1815 | ActivityClientRecord prev; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1816 | do { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 1817 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1818 | TAG, "Reporting idle of " + a + |
| 1819 | " finished=" + |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1820 | (a.activity != null && a.activity.mFinished)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1821 | if (a.activity != null && !a.activity.mFinished) { |
| 1822 | try { |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 1823 | am.activityIdle(a.token, a.createdConfig, stopProfiling); |
Dianne Hackborn | e88846e | 2009-09-30 21:34:25 -0700 | [diff] [blame] | 1824 | a.createdConfig = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1825 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1826 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1827 | } |
| 1828 | } |
| 1829 | prev = a; |
| 1830 | a = a.nextIdle; |
| 1831 | prev.nextIdle = null; |
| 1832 | } while (a != null); |
| 1833 | } |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 1834 | if (stopProfiling) { |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 1835 | mProfiler.stopProfiling(); |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 1836 | } |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 1837 | ensureJitEnabled(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1838 | return false; |
| 1839 | } |
| 1840 | } |
| 1841 | |
| 1842 | final class GcIdler implements MessageQueue.IdleHandler { |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 1843 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1844 | public final boolean queueIdle() { |
| 1845 | doGcIfNeeded(); |
| 1846 | return false; |
| 1847 | } |
| 1848 | } |
| 1849 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1850 | public static ActivityThread currentActivityThread() { |
Jeff Sharkey | 66a017b | 2013-01-17 18:18:22 -0800 | [diff] [blame] | 1851 | return sCurrentActivityThread; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1852 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1853 | |
Wale Ogunwale | 9a6ef1e | 2015-06-02 13:41:00 -0700 | [diff] [blame] | 1854 | public static boolean isSystem() { |
| 1855 | return (sCurrentActivityThread != null) ? sCurrentActivityThread.mSystemThread : false; |
| 1856 | } |
| 1857 | |
Svetoslav | fbf0eca | 2015-05-01 16:52:41 -0700 | [diff] [blame] | 1858 | public static String currentOpPackageName() { |
| 1859 | ActivityThread am = currentActivityThread(); |
| 1860 | return (am != null && am.getApplication() != null) |
| 1861 | ? am.getApplication().getOpPackageName() : null; |
| 1862 | } |
| 1863 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1864 | public static String currentPackageName() { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1865 | ActivityThread am = currentActivityThread(); |
| 1866 | return (am != null && am.mBoundApplication != null) |
Dianne Hackborn | b57a50b | 2013-04-11 17:29:32 -0700 | [diff] [blame] | 1867 | ? am.mBoundApplication.appInfo.packageName : null; |
| 1868 | } |
| 1869 | |
| 1870 | public static String currentProcessName() { |
| 1871 | ActivityThread am = currentActivityThread(); |
| 1872 | return (am != null && am.mBoundApplication != null) |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1873 | ? am.mBoundApplication.processName : null; |
| 1874 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1875 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1876 | public static Application currentApplication() { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1877 | ActivityThread am = currentActivityThread(); |
| 1878 | return am != null ? am.mInitialApplication : null; |
| 1879 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1880 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1881 | public static IPackageManager getPackageManager() { |
| 1882 | if (sPackageManager != null) { |
| 1883 | //Slog.v("PackageManager", "returning cur default = " + sPackageManager); |
| 1884 | return sPackageManager; |
| 1885 | } |
| 1886 | IBinder b = ServiceManager.getService("package"); |
| 1887 | //Slog.v("PackageManager", "default service binder = " + b); |
| 1888 | sPackageManager = IPackageManager.Stub.asInterface(b); |
| 1889 | //Slog.v("PackageManager", "default service = " + sPackageManager); |
| 1890 | return sPackageManager; |
| 1891 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1892 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1893 | private Configuration mMainThreadConfig = new Configuration(); |
Amith Yamasani | 4f128e4 | 2016-05-10 11:44:12 -0700 | [diff] [blame] | 1894 | |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 1895 | Configuration applyConfigCompatMainThread(int displayDensity, Configuration config, |
| 1896 | CompatibilityInfo compat) { |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1897 | if (config == null) { |
| 1898 | return null; |
| 1899 | } |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 1900 | if (!compat.supportsScreen()) { |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1901 | mMainThreadConfig.setTo(config); |
| 1902 | config = mMainThreadConfig; |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 1903 | compat.applyToConfiguration(displayDensity, config); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1904 | } |
| 1905 | return config; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1906 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1907 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1908 | /** |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 1909 | * Creates the top level resources for the given package. Will return an existing |
| 1910 | * Resources if one has already been created. |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1911 | */ |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 1912 | Resources getTopLevelResources(String resDir, String[] splitResDirs, String[] overlayDirs, |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 1913 | String[] libDirs, int displayId, LoadedApk pkgInfo) { |
| 1914 | return mResourcesManager.getResources(null, resDir, splitResDirs, overlayDirs, libDirs, |
| 1915 | displayId, null, pkgInfo.getCompatibilityInfo(), pkgInfo.getClassLoader()); |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 1916 | } |
| 1917 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1918 | final Handler getHandler() { |
| 1919 | return mH; |
| 1920 | } |
| 1921 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 1922 | public final LoadedApk getPackageInfo(String packageName, CompatibilityInfo compatInfo, |
| 1923 | int flags) { |
| 1924 | return getPackageInfo(packageName, compatInfo, flags, UserHandle.myUserId()); |
Amith Yamasani | 98edc95 | 2012-09-25 14:09:27 -0700 | [diff] [blame] | 1925 | } |
| 1926 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 1927 | public final LoadedApk getPackageInfo(String packageName, CompatibilityInfo compatInfo, |
| 1928 | int flags, int userId) { |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 1929 | final boolean differentUser = (UserHandle.myUserId() != userId); |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 1930 | synchronized (mResourcesManager) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1931 | WeakReference<LoadedApk> ref; |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 1932 | if (differentUser) { |
| 1933 | // Caching not supported across users |
| 1934 | ref = null; |
| 1935 | } else if ((flags & Context.CONTEXT_INCLUDE_CODE) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1936 | ref = mPackages.get(packageName); |
| 1937 | } else { |
| 1938 | ref = mResourcePackages.get(packageName); |
| 1939 | } |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 1940 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 1941 | LoadedApk packageInfo = ref != null ? ref.get() : null; |
| 1942 | //Slog.i(TAG, "getPackageInfo " + packageName + ": " + packageInfo); |
| 1943 | //if (packageInfo != null) Slog.i(TAG, "isUptoDate " + packageInfo.mResDir |
| 1944 | // + ": " + packageInfo.mResources.getAssets().isUpToDate()); |
| 1945 | if (packageInfo != null && (packageInfo.mResources == null |
| 1946 | || packageInfo.mResources.getAssets().isUpToDate())) { |
| 1947 | if (packageInfo.isSecurityViolation() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1948 | && (flags&Context.CONTEXT_IGNORE_SECURITY) == 0) { |
| 1949 | throw new SecurityException( |
| 1950 | "Requesting code from " + packageName |
| 1951 | + " to be run in process " |
| 1952 | + mBoundApplication.processName |
| 1953 | + "/" + mBoundApplication.appInfo.uid); |
| 1954 | } |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 1955 | return packageInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1956 | } |
| 1957 | } |
| 1958 | |
| 1959 | ApplicationInfo ai = null; |
| 1960 | try { |
| 1961 | ai = getPackageManager().getApplicationInfo(packageName, |
Jeff Sharkey | c5967e9 | 2016-01-07 18:50:29 -0700 | [diff] [blame] | 1962 | PackageManager.GET_SHARED_LIBRARY_FILES |
| 1963 | | PackageManager.MATCH_DEBUG_TRIAGED_MISSING, |
| 1964 | userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1965 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1966 | throw e.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1967 | } |
| 1968 | |
| 1969 | if (ai != null) { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 1970 | return getPackageInfo(ai, compatInfo, flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1971 | } |
| 1972 | |
| 1973 | return null; |
| 1974 | } |
| 1975 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 1976 | public final LoadedApk getPackageInfo(ApplicationInfo ai, CompatibilityInfo compatInfo, |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1977 | int flags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1978 | boolean includeCode = (flags&Context.CONTEXT_INCLUDE_CODE) != 0; |
| 1979 | boolean securityViolation = includeCode && ai.uid != 0 |
| 1980 | && ai.uid != Process.SYSTEM_UID && (mBoundApplication != null |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 1981 | ? !UserHandle.isSameApp(ai.uid, mBoundApplication.appInfo.uid) |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 1982 | : true); |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 1983 | boolean registerPackage = includeCode && (flags&Context.CONTEXT_REGISTER_PACKAGE) != 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1984 | if ((flags&(Context.CONTEXT_INCLUDE_CODE |
| 1985 | |Context.CONTEXT_IGNORE_SECURITY)) |
| 1986 | == Context.CONTEXT_INCLUDE_CODE) { |
| 1987 | if (securityViolation) { |
| 1988 | String msg = "Requesting code from " + ai.packageName |
| 1989 | + " (with uid " + ai.uid + ")"; |
| 1990 | if (mBoundApplication != null) { |
| 1991 | msg = msg + " to be run in process " |
| 1992 | + mBoundApplication.processName + " (with uid " |
| 1993 | + mBoundApplication.appInfo.uid + ")"; |
| 1994 | } |
| 1995 | throw new SecurityException(msg); |
| 1996 | } |
| 1997 | } |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 1998 | return getPackageInfo(ai, compatInfo, null, securityViolation, includeCode, |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 1999 | registerPackage); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2000 | } |
| 2001 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 2002 | @Override |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2003 | public final LoadedApk getPackageInfoNoCheck(ApplicationInfo ai, |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2004 | CompatibilityInfo compatInfo) { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2005 | return getPackageInfo(ai, compatInfo, null, false, true, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2006 | } |
| 2007 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2008 | public final LoadedApk peekPackageInfo(String packageName, boolean includeCode) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 2009 | synchronized (mResourcesManager) { |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2010 | WeakReference<LoadedApk> ref; |
| 2011 | if (includeCode) { |
| 2012 | ref = mPackages.get(packageName); |
| 2013 | } else { |
| 2014 | ref = mResourcePackages.get(packageName); |
| 2015 | } |
| 2016 | return ref != null ? ref.get() : null; |
| 2017 | } |
| 2018 | } |
| 2019 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2020 | private LoadedApk getPackageInfo(ApplicationInfo aInfo, CompatibilityInfo compatInfo, |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 2021 | ClassLoader baseLoader, boolean securityViolation, boolean includeCode, |
| 2022 | boolean registerPackage) { |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 2023 | final boolean differentUser = (UserHandle.myUserId() != UserHandle.getUserId(aInfo.uid)); |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 2024 | synchronized (mResourcesManager) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2025 | WeakReference<LoadedApk> ref; |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 2026 | if (differentUser) { |
| 2027 | // Caching not supported across users |
| 2028 | ref = null; |
| 2029 | } else if (includeCode) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2030 | ref = mPackages.get(aInfo.packageName); |
| 2031 | } else { |
| 2032 | ref = mResourcePackages.get(aInfo.packageName); |
| 2033 | } |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 2034 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2035 | LoadedApk packageInfo = ref != null ? ref.get() : null; |
| 2036 | if (packageInfo == null || (packageInfo.mResources != null |
| 2037 | && !packageInfo.mResources.getAssets().isUpToDate())) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2038 | if (localLOGV) Slog.v(TAG, (includeCode ? "Loading code package " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2039 | : "Loading resource-only package ") + aInfo.packageName |
| 2040 | + " (in " + (mBoundApplication != null |
| 2041 | ? mBoundApplication.processName : null) |
| 2042 | + ")"); |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2043 | packageInfo = |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 2044 | new LoadedApk(this, aInfo, compatInfo, baseLoader, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2045 | securityViolation, includeCode && |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 2046 | (aInfo.flags&ApplicationInfo.FLAG_HAS_CODE) != 0, registerPackage); |
Narayan Kamath | cb38318 | 2014-10-29 17:56:42 +0000 | [diff] [blame] | 2047 | |
| 2048 | if (mSystemThread && "android".equals(aInfo.packageName)) { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2049 | packageInfo.installSystemApplicationInfo(aInfo, |
| 2050 | getSystemContext().mPackageInfo.getClassLoader()); |
Narayan Kamath | cb38318 | 2014-10-29 17:56:42 +0000 | [diff] [blame] | 2051 | } |
| 2052 | |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 2053 | if (differentUser) { |
| 2054 | // Caching not supported across users |
| 2055 | } else if (includeCode) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2056 | mPackages.put(aInfo.packageName, |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2057 | new WeakReference<LoadedApk>(packageInfo)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2058 | } else { |
| 2059 | mResourcePackages.put(aInfo.packageName, |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2060 | new WeakReference<LoadedApk>(packageInfo)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2061 | } |
| 2062 | } |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2063 | return packageInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2064 | } |
| 2065 | } |
| 2066 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2067 | ActivityThread() { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 2068 | mResourcesManager = ResourcesManager.getInstance(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2069 | } |
| 2070 | |
| 2071 | public ApplicationThread getApplicationThread() |
| 2072 | { |
| 2073 | return mAppThread; |
| 2074 | } |
| 2075 | |
| 2076 | public Instrumentation getInstrumentation() |
| 2077 | { |
| 2078 | return mInstrumentation; |
| 2079 | } |
| 2080 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2081 | public boolean isProfiling() { |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 2082 | return mProfiler != null && mProfiler.profileFile != null |
| 2083 | && mProfiler.profileFd == null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2084 | } |
| 2085 | |
| 2086 | public String getProfileFilePath() { |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 2087 | return mProfiler.profileFile; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2088 | } |
| 2089 | |
| 2090 | public Looper getLooper() { |
| 2091 | return mLooper; |
| 2092 | } |
| 2093 | |
Jeff Sharkey | 8439ac0 | 2017-12-12 17:26:23 -0700 | [diff] [blame] | 2094 | public Executor getExecutor() { |
| 2095 | return mExecutor; |
| 2096 | } |
| 2097 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2098 | public Application getApplication() { |
| 2099 | return mInitialApplication; |
| 2100 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2101 | |
Dianne Hackborn | d97c7ad | 2009-06-19 11:37:35 -0700 | [diff] [blame] | 2102 | public String getProcessName() { |
| 2103 | return mBoundApplication.processName; |
| 2104 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2105 | |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 2106 | public ContextImpl getSystemContext() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2107 | synchronized (this) { |
| 2108 | if (mSystemContext == null) { |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 2109 | mSystemContext = ContextImpl.createSystemContext(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2110 | } |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 2111 | return mSystemContext; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2112 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2113 | } |
| 2114 | |
Adam Lesinski | a82b626 | 2017-03-21 16:56:17 -0700 | [diff] [blame] | 2115 | public ContextImpl getSystemUiContext() { |
| 2116 | synchronized (this) { |
| 2117 | if (mSystemUiContext == null) { |
Adam Lesinski | 6f1a917 | 2017-04-10 16:35:19 -0700 | [diff] [blame] | 2118 | mSystemUiContext = ContextImpl.createSystemUiContext(getSystemContext()); |
Adam Lesinski | a82b626 | 2017-03-21 16:56:17 -0700 | [diff] [blame] | 2119 | } |
| 2120 | return mSystemUiContext; |
| 2121 | } |
| 2122 | } |
| 2123 | |
Narayan Kamath | 29564cd | 2014-08-07 10:57:40 +0100 | [diff] [blame] | 2124 | public void installSystemApplicationInfo(ApplicationInfo info, ClassLoader classLoader) { |
Mike Cleron | 432b713 | 2009-09-24 15:28:29 -0700 | [diff] [blame] | 2125 | synchronized (this) { |
Narayan Kamath | 29564cd | 2014-08-07 10:57:40 +0100 | [diff] [blame] | 2126 | getSystemContext().installSystemApplicationInfo(info, classLoader); |
Adam Lesinski | a82b626 | 2017-03-21 16:56:17 -0700 | [diff] [blame] | 2127 | getSystemUiContext().installSystemApplicationInfo(info, classLoader); |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 2128 | |
| 2129 | // give ourselves a default profiler |
| 2130 | mProfiler = new Profiler(); |
Mike Cleron | 432b713 | 2009-09-24 15:28:29 -0700 | [diff] [blame] | 2131 | } |
| 2132 | } |
| 2133 | |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 2134 | void ensureJitEnabled() { |
| 2135 | if (!mJitEnabled) { |
| 2136 | mJitEnabled = true; |
| 2137 | dalvik.system.VMRuntime.getRuntime().startJitCompilation(); |
| 2138 | } |
| 2139 | } |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 2140 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2141 | void scheduleGcIdler() { |
| 2142 | if (!mGcIdlerScheduled) { |
| 2143 | mGcIdlerScheduled = true; |
| 2144 | Looper.myQueue().addIdleHandler(mGcIdler); |
| 2145 | } |
| 2146 | mH.removeMessages(H.GC_WHEN_IDLE); |
| 2147 | } |
| 2148 | |
| 2149 | void unscheduleGcIdler() { |
| 2150 | if (mGcIdlerScheduled) { |
| 2151 | mGcIdlerScheduled = false; |
| 2152 | Looper.myQueue().removeIdleHandler(mGcIdler); |
| 2153 | } |
| 2154 | mH.removeMessages(H.GC_WHEN_IDLE); |
| 2155 | } |
| 2156 | |
| 2157 | void doGcIfNeeded() { |
| 2158 | mGcIdlerScheduled = false; |
| 2159 | final long now = SystemClock.uptimeMillis(); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2160 | //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] | 2161 | // + "m now=" + now); |
| 2162 | if ((BinderInternal.getLastGcTime()+MIN_TIME_BETWEEN_GCS) < now) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2163 | //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] | 2164 | BinderInternal.forceGc("bg"); |
| 2165 | } |
| 2166 | } |
| 2167 | |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2168 | private static final String HEAP_FULL_COLUMN |
| 2169 | = "%13s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s"; |
| 2170 | private static final String HEAP_COLUMN |
| 2171 | = "%13s %8s %8s %8s %8s %8s %8s %8s"; |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2172 | private static final String ONE_COUNT_COLUMN = "%21s %8d"; |
| 2173 | private static final String TWO_COUNT_COLUMNS = "%21s %8d %21s %8d"; |
| 2174 | private static final String ONE_COUNT_COLUMN_HEADER = "%21s %8s"; |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2175 | |
| 2176 | // Formatting for checkin service - update version if row format changes |
Martijn Coenen | 41f94ed | 2015-12-14 15:28:51 +0100 | [diff] [blame] | 2177 | private static final int ACTIVITY_THREAD_CHECKIN_VERSION = 4; |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2178 | |
| 2179 | static void printRow(PrintWriter pw, String format, Object...objs) { |
| 2180 | pw.println(String.format(format, objs)); |
| 2181 | } |
| 2182 | |
Bryce Lee | d946f86 | 2018-01-16 15:59:47 -0800 | [diff] [blame] | 2183 | @Override |
| 2184 | public void dump(PrintWriter pw, String prefix) { |
| 2185 | pw.println(prefix + "mActivities:"); |
| 2186 | |
| 2187 | for (ArrayMap.Entry<IBinder, ActivityClientRecord> entry : mActivities.entrySet()) { |
| 2188 | pw.println(prefix + " [token:" + entry.getKey().hashCode() + " record:" |
| 2189 | + entry.getValue().toString() + "]"); |
| 2190 | } |
| 2191 | |
| 2192 | pw.println(prefix + "mRecentTokens:" + mRecentTokens); |
| 2193 | } |
| 2194 | |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2195 | public static void dumpMemInfoTable(PrintWriter pw, Debug.MemoryInfo memInfo, boolean checkin, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2196 | boolean dumpFullInfo, boolean dumpDalvik, boolean dumpSummaryOnly, |
| 2197 | int pid, String processName, |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2198 | long nativeMax, long nativeAllocated, long nativeFree, |
| 2199 | long dalvikMax, long dalvikAllocated, long dalvikFree) { |
| 2200 | |
| 2201 | // For checkin, we print one long comma-separated list of values |
| 2202 | if (checkin) { |
| 2203 | // NOTE: if you change anything significant below, also consider changing |
| 2204 | // ACTIVITY_THREAD_CHECKIN_VERSION. |
| 2205 | |
| 2206 | // Header |
| 2207 | pw.print(ACTIVITY_THREAD_CHECKIN_VERSION); pw.print(','); |
| 2208 | pw.print(pid); pw.print(','); |
| 2209 | pw.print(processName); pw.print(','); |
| 2210 | |
| 2211 | // Heap info - max |
| 2212 | pw.print(nativeMax); pw.print(','); |
| 2213 | pw.print(dalvikMax); pw.print(','); |
| 2214 | pw.print("N/A,"); |
| 2215 | pw.print(nativeMax + dalvikMax); pw.print(','); |
| 2216 | |
| 2217 | // Heap info - allocated |
| 2218 | pw.print(nativeAllocated); pw.print(','); |
| 2219 | pw.print(dalvikAllocated); pw.print(','); |
| 2220 | pw.print("N/A,"); |
| 2221 | pw.print(nativeAllocated + dalvikAllocated); pw.print(','); |
| 2222 | |
| 2223 | // Heap info - free |
| 2224 | pw.print(nativeFree); pw.print(','); |
| 2225 | pw.print(dalvikFree); pw.print(','); |
| 2226 | pw.print("N/A,"); |
| 2227 | pw.print(nativeFree + dalvikFree); pw.print(','); |
| 2228 | |
| 2229 | // Heap info - proportional set size |
| 2230 | pw.print(memInfo.nativePss); pw.print(','); |
| 2231 | pw.print(memInfo.dalvikPss); pw.print(','); |
| 2232 | pw.print(memInfo.otherPss); pw.print(','); |
| 2233 | pw.print(memInfo.getTotalPss()); pw.print(','); |
| 2234 | |
| 2235 | // Heap info - swappable set size |
| 2236 | pw.print(memInfo.nativeSwappablePss); pw.print(','); |
| 2237 | pw.print(memInfo.dalvikSwappablePss); pw.print(','); |
| 2238 | pw.print(memInfo.otherSwappablePss); pw.print(','); |
| 2239 | pw.print(memInfo.getTotalSwappablePss()); pw.print(','); |
| 2240 | |
| 2241 | // Heap info - shared dirty |
| 2242 | pw.print(memInfo.nativeSharedDirty); pw.print(','); |
| 2243 | pw.print(memInfo.dalvikSharedDirty); pw.print(','); |
| 2244 | pw.print(memInfo.otherSharedDirty); pw.print(','); |
| 2245 | pw.print(memInfo.getTotalSharedDirty()); pw.print(','); |
| 2246 | |
| 2247 | // Heap info - shared clean |
| 2248 | pw.print(memInfo.nativeSharedClean); pw.print(','); |
| 2249 | pw.print(memInfo.dalvikSharedClean); pw.print(','); |
| 2250 | pw.print(memInfo.otherSharedClean); pw.print(','); |
| 2251 | pw.print(memInfo.getTotalSharedClean()); pw.print(','); |
| 2252 | |
| 2253 | // Heap info - private Dirty |
| 2254 | pw.print(memInfo.nativePrivateDirty); pw.print(','); |
| 2255 | pw.print(memInfo.dalvikPrivateDirty); pw.print(','); |
| 2256 | pw.print(memInfo.otherPrivateDirty); pw.print(','); |
| 2257 | pw.print(memInfo.getTotalPrivateDirty()); pw.print(','); |
| 2258 | |
| 2259 | // Heap info - private Clean |
| 2260 | pw.print(memInfo.nativePrivateClean); pw.print(','); |
| 2261 | pw.print(memInfo.dalvikPrivateClean); pw.print(','); |
| 2262 | pw.print(memInfo.otherPrivateClean); pw.print(','); |
| 2263 | pw.print(memInfo.getTotalPrivateClean()); pw.print(','); |
| 2264 | |
Martijn Coenen | 41f94ed | 2015-12-14 15:28:51 +0100 | [diff] [blame] | 2265 | // Heap info - swapped out |
| 2266 | pw.print(memInfo.nativeSwappedOut); pw.print(','); |
| 2267 | pw.print(memInfo.dalvikSwappedOut); pw.print(','); |
| 2268 | pw.print(memInfo.otherSwappedOut); pw.print(','); |
| 2269 | pw.print(memInfo.getTotalSwappedOut()); pw.print(','); |
| 2270 | |
| 2271 | // Heap info - swapped out pss |
| 2272 | if (memInfo.hasSwappedOutPss) { |
| 2273 | pw.print(memInfo.nativeSwappedOutPss); pw.print(','); |
| 2274 | pw.print(memInfo.dalvikSwappedOutPss); pw.print(','); |
| 2275 | pw.print(memInfo.otherSwappedOutPss); pw.print(','); |
| 2276 | pw.print(memInfo.getTotalSwappedOutPss()); pw.print(','); |
| 2277 | } else { |
| 2278 | pw.print("N/A,"); |
| 2279 | pw.print("N/A,"); |
| 2280 | pw.print("N/A,"); |
| 2281 | pw.print("N/A,"); |
| 2282 | } |
| 2283 | |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2284 | // Heap info - other areas |
| 2285 | for (int i=0; i<Debug.MemoryInfo.NUM_OTHER_STATS; i++) { |
| 2286 | pw.print(Debug.MemoryInfo.getOtherLabel(i)); pw.print(','); |
| 2287 | pw.print(memInfo.getOtherPss(i)); pw.print(','); |
| 2288 | pw.print(memInfo.getOtherSwappablePss(i)); pw.print(','); |
| 2289 | pw.print(memInfo.getOtherSharedDirty(i)); pw.print(','); |
| 2290 | pw.print(memInfo.getOtherSharedClean(i)); pw.print(','); |
| 2291 | pw.print(memInfo.getOtherPrivateDirty(i)); pw.print(','); |
| 2292 | pw.print(memInfo.getOtherPrivateClean(i)); pw.print(','); |
Martijn Coenen | 41f94ed | 2015-12-14 15:28:51 +0100 | [diff] [blame] | 2293 | pw.print(memInfo.getOtherSwappedOut(i)); pw.print(','); |
| 2294 | if (memInfo.hasSwappedOutPss) { |
| 2295 | pw.print(memInfo.getOtherSwappedOutPss(i)); pw.print(','); |
| 2296 | } else { |
| 2297 | pw.print("N/A,"); |
| 2298 | } |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2299 | } |
| 2300 | return; |
| 2301 | } |
| 2302 | |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2303 | if (!dumpSummaryOnly) { |
| 2304 | if (dumpFullInfo) { |
| 2305 | printRow(pw, HEAP_FULL_COLUMN, "", "Pss", "Pss", "Shared", "Private", |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2306 | "Shared", "Private", memInfo.hasSwappedOutPss ? "SwapPss" : "Swap", |
| 2307 | "Heap", "Heap", "Heap"); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2308 | printRow(pw, HEAP_FULL_COLUMN, "", "Total", "Clean", "Dirty", "Dirty", |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2309 | "Clean", "Clean", "Dirty", |
| 2310 | "Size", "Alloc", "Free"); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2311 | printRow(pw, HEAP_FULL_COLUMN, "", "------", "------", "------", "------", |
| 2312 | "------", "------", "------", "------", "------", "------"); |
| 2313 | printRow(pw, HEAP_FULL_COLUMN, "Native Heap", memInfo.nativePss, |
| 2314 | memInfo.nativeSwappablePss, memInfo.nativeSharedDirty, |
| 2315 | memInfo.nativePrivateDirty, memInfo.nativeSharedClean, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2316 | memInfo.nativePrivateClean, memInfo.hasSwappedOutPss ? |
Richard Uhler | 91702eb3 | 2017-06-23 16:54:25 +0100 | [diff] [blame] | 2317 | memInfo.nativeSwappedOutPss : memInfo.nativeSwappedOut, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2318 | nativeMax, nativeAllocated, nativeFree); |
| 2319 | printRow(pw, HEAP_FULL_COLUMN, "Dalvik Heap", memInfo.dalvikPss, |
| 2320 | memInfo.dalvikSwappablePss, memInfo.dalvikSharedDirty, |
| 2321 | memInfo.dalvikPrivateDirty, memInfo.dalvikSharedClean, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2322 | memInfo.dalvikPrivateClean, memInfo.hasSwappedOutPss ? |
Richard Uhler | 91702eb3 | 2017-06-23 16:54:25 +0100 | [diff] [blame] | 2323 | memInfo.dalvikSwappedOutPss : memInfo.dalvikSwappedOut, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2324 | dalvikMax, dalvikAllocated, dalvikFree); |
| 2325 | } else { |
| 2326 | printRow(pw, HEAP_COLUMN, "", "Pss", "Private", |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2327 | "Private", memInfo.hasSwappedOutPss ? "SwapPss" : "Swap", |
| 2328 | "Heap", "Heap", "Heap"); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2329 | printRow(pw, HEAP_COLUMN, "", "Total", "Dirty", |
| 2330 | "Clean", "Dirty", "Size", "Alloc", "Free"); |
| 2331 | printRow(pw, HEAP_COLUMN, "", "------", "------", "------", |
| 2332 | "------", "------", "------", "------", "------"); |
| 2333 | printRow(pw, HEAP_COLUMN, "Native Heap", memInfo.nativePss, |
| 2334 | memInfo.nativePrivateDirty, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2335 | memInfo.nativePrivateClean, |
| 2336 | memInfo.hasSwappedOutPss ? memInfo.nativeSwappedOutPss : |
| 2337 | memInfo.nativeSwappedOut, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2338 | nativeMax, nativeAllocated, nativeFree); |
| 2339 | printRow(pw, HEAP_COLUMN, "Dalvik Heap", memInfo.dalvikPss, |
| 2340 | memInfo.dalvikPrivateDirty, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2341 | memInfo.dalvikPrivateClean, |
| 2342 | memInfo.hasSwappedOutPss ? memInfo.dalvikSwappedOutPss : |
| 2343 | memInfo.dalvikSwappedOut, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2344 | dalvikMax, dalvikAllocated, dalvikFree); |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2345 | } |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2346 | |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2347 | int otherPss = memInfo.otherPss; |
| 2348 | int otherSwappablePss = memInfo.otherSwappablePss; |
| 2349 | int otherSharedDirty = memInfo.otherSharedDirty; |
| 2350 | int otherPrivateDirty = memInfo.otherPrivateDirty; |
| 2351 | int otherSharedClean = memInfo.otherSharedClean; |
| 2352 | int otherPrivateClean = memInfo.otherPrivateClean; |
| 2353 | int otherSwappedOut = memInfo.otherSwappedOut; |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2354 | int otherSwappedOutPss = memInfo.otherSwappedOutPss; |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2355 | |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2356 | for (int i=0; i<Debug.MemoryInfo.NUM_OTHER_STATS; i++) { |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2357 | final int myPss = memInfo.getOtherPss(i); |
| 2358 | final int mySwappablePss = memInfo.getOtherSwappablePss(i); |
| 2359 | final int mySharedDirty = memInfo.getOtherSharedDirty(i); |
| 2360 | final int myPrivateDirty = memInfo.getOtherPrivateDirty(i); |
| 2361 | final int mySharedClean = memInfo.getOtherSharedClean(i); |
| 2362 | final int myPrivateClean = memInfo.getOtherPrivateClean(i); |
| 2363 | final int mySwappedOut = memInfo.getOtherSwappedOut(i); |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2364 | final int mySwappedOutPss = memInfo.getOtherSwappedOutPss(i); |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2365 | if (myPss != 0 || mySharedDirty != 0 || myPrivateDirty != 0 |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2366 | || mySharedClean != 0 || myPrivateClean != 0 |
| 2367 | || (memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut) != 0) { |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2368 | if (dumpFullInfo) { |
| 2369 | printRow(pw, HEAP_FULL_COLUMN, Debug.MemoryInfo.getOtherLabel(i), |
| 2370 | myPss, mySwappablePss, mySharedDirty, myPrivateDirty, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2371 | mySharedClean, myPrivateClean, |
| 2372 | memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut, |
| 2373 | "", "", ""); |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2374 | } else { |
| 2375 | printRow(pw, HEAP_COLUMN, Debug.MemoryInfo.getOtherLabel(i), |
| 2376 | myPss, myPrivateDirty, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2377 | myPrivateClean, |
| 2378 | memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut, |
| 2379 | "", "", ""); |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2380 | } |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2381 | otherPss -= myPss; |
| 2382 | otherSwappablePss -= mySwappablePss; |
| 2383 | otherSharedDirty -= mySharedDirty; |
| 2384 | otherPrivateDirty -= myPrivateDirty; |
| 2385 | otherSharedClean -= mySharedClean; |
| 2386 | otherPrivateClean -= myPrivateClean; |
| 2387 | otherSwappedOut -= mySwappedOut; |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2388 | otherSwappedOutPss -= mySwappedOutPss; |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2389 | } |
| 2390 | } |
| 2391 | |
| 2392 | if (dumpFullInfo) { |
| 2393 | printRow(pw, HEAP_FULL_COLUMN, "Unknown", otherPss, otherSwappablePss, |
| 2394 | otherSharedDirty, otherPrivateDirty, otherSharedClean, otherPrivateClean, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2395 | memInfo.hasSwappedOutPss ? otherSwappedOutPss : otherSwappedOut, |
| 2396 | "", "", ""); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2397 | printRow(pw, HEAP_FULL_COLUMN, "TOTAL", memInfo.getTotalPss(), |
| 2398 | memInfo.getTotalSwappablePss(), |
| 2399 | memInfo.getTotalSharedDirty(), memInfo.getTotalPrivateDirty(), |
| 2400 | memInfo.getTotalSharedClean(), memInfo.getTotalPrivateClean(), |
Thierry Strudel | 9b51160 | 2016-02-25 17:46:38 -0800 | [diff] [blame] | 2401 | memInfo.hasSwappedOutPss ? memInfo.getTotalSwappedOutPss() : |
| 2402 | memInfo.getTotalSwappedOut(), |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2403 | nativeMax+dalvikMax, nativeAllocated+dalvikAllocated, |
| 2404 | nativeFree+dalvikFree); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2405 | } else { |
| 2406 | printRow(pw, HEAP_COLUMN, "Unknown", otherPss, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2407 | otherPrivateDirty, otherPrivateClean, |
| 2408 | memInfo.hasSwappedOutPss ? otherSwappedOutPss : otherSwappedOut, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2409 | "", "", ""); |
| 2410 | printRow(pw, HEAP_COLUMN, "TOTAL", memInfo.getTotalPss(), |
| 2411 | memInfo.getTotalPrivateDirty(), |
| 2412 | memInfo.getTotalPrivateClean(), |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2413 | memInfo.hasSwappedOutPss ? memInfo.getTotalSwappedOutPss() : |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2414 | memInfo.getTotalSwappedOut(), |
| 2415 | nativeMax+dalvikMax, |
| 2416 | nativeAllocated+dalvikAllocated, nativeFree+dalvikFree); |
| 2417 | } |
| 2418 | |
| 2419 | if (dumpDalvik) { |
| 2420 | pw.println(" "); |
| 2421 | pw.println(" Dalvik Details"); |
| 2422 | |
| 2423 | for (int i=Debug.MemoryInfo.NUM_OTHER_STATS; |
| 2424 | i<Debug.MemoryInfo.NUM_OTHER_STATS + Debug.MemoryInfo.NUM_DVK_STATS; i++) { |
| 2425 | final int myPss = memInfo.getOtherPss(i); |
| 2426 | final int mySwappablePss = memInfo.getOtherSwappablePss(i); |
| 2427 | final int mySharedDirty = memInfo.getOtherSharedDirty(i); |
| 2428 | final int myPrivateDirty = memInfo.getOtherPrivateDirty(i); |
| 2429 | final int mySharedClean = memInfo.getOtherSharedClean(i); |
| 2430 | final int myPrivateClean = memInfo.getOtherPrivateClean(i); |
| 2431 | final int mySwappedOut = memInfo.getOtherSwappedOut(i); |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2432 | final int mySwappedOutPss = memInfo.getOtherSwappedOutPss(i); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2433 | if (myPss != 0 || mySharedDirty != 0 || myPrivateDirty != 0 |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2434 | || mySharedClean != 0 || myPrivateClean != 0 |
| 2435 | || (memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut) != 0) { |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2436 | if (dumpFullInfo) { |
| 2437 | printRow(pw, HEAP_FULL_COLUMN, Debug.MemoryInfo.getOtherLabel(i), |
| 2438 | myPss, mySwappablePss, mySharedDirty, myPrivateDirty, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2439 | mySharedClean, myPrivateClean, |
| 2440 | memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut, |
| 2441 | "", "", ""); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2442 | } else { |
| 2443 | printRow(pw, HEAP_COLUMN, Debug.MemoryInfo.getOtherLabel(i), |
| 2444 | myPss, myPrivateDirty, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2445 | myPrivateClean, |
| 2446 | memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut, |
| 2447 | "", "", ""); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2448 | } |
| 2449 | } |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2450 | } |
| 2451 | } |
| 2452 | } |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2453 | |
| 2454 | pw.println(" "); |
| 2455 | pw.println(" App Summary"); |
| 2456 | printRow(pw, ONE_COUNT_COLUMN_HEADER, "", "Pss(KB)"); |
| 2457 | printRow(pw, ONE_COUNT_COLUMN_HEADER, "", "------"); |
| 2458 | printRow(pw, ONE_COUNT_COLUMN, |
| 2459 | "Java Heap:", memInfo.getSummaryJavaHeap()); |
| 2460 | printRow(pw, ONE_COUNT_COLUMN, |
| 2461 | "Native Heap:", memInfo.getSummaryNativeHeap()); |
| 2462 | printRow(pw, ONE_COUNT_COLUMN, |
| 2463 | "Code:", memInfo.getSummaryCode()); |
| 2464 | printRow(pw, ONE_COUNT_COLUMN, |
| 2465 | "Stack:", memInfo.getSummaryStack()); |
| 2466 | printRow(pw, ONE_COUNT_COLUMN, |
| 2467 | "Graphics:", memInfo.getSummaryGraphics()); |
| 2468 | printRow(pw, ONE_COUNT_COLUMN, |
| 2469 | "Private Other:", memInfo.getSummaryPrivateOther()); |
| 2470 | printRow(pw, ONE_COUNT_COLUMN, |
| 2471 | "System:", memInfo.getSummarySystem()); |
| 2472 | pw.println(" "); |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2473 | if (memInfo.hasSwappedOutPss) { |
| 2474 | printRow(pw, TWO_COUNT_COLUMNS, |
| 2475 | "TOTAL:", memInfo.getSummaryTotalPss(), |
| 2476 | "TOTAL SWAP PSS:", memInfo.getSummaryTotalSwapPss()); |
| 2477 | } else { |
| 2478 | printRow(pw, TWO_COUNT_COLUMNS, |
| 2479 | "TOTAL:", memInfo.getSummaryTotalPss(), |
| 2480 | "TOTAL SWAP (KB):", memInfo.getSummaryTotalSwap()); |
| 2481 | } |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2482 | } |
| 2483 | |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2484 | /** |
| 2485 | * Dump heap info to proto. |
| 2486 | * |
| 2487 | * @param hasSwappedOutPss determines whether to use dirtySwap or dirtySwapPss |
| 2488 | */ |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 2489 | private static void dumpMemoryInfo(ProtoOutputStream proto, long fieldId, String name, |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2490 | int pss, int cleanPss, int sharedDirty, int privateDirty, |
| 2491 | int sharedClean, int privateClean, |
| 2492 | boolean hasSwappedOutPss, int dirtySwap, int dirtySwapPss) { |
| 2493 | final long token = proto.start(fieldId); |
| 2494 | |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 2495 | proto.write(MemInfoProto.ProcessMemory.MemoryInfo.NAME, name); |
| 2496 | proto.write(MemInfoProto.ProcessMemory.MemoryInfo.TOTAL_PSS_KB, pss); |
| 2497 | proto.write(MemInfoProto.ProcessMemory.MemoryInfo.CLEAN_PSS_KB, cleanPss); |
| 2498 | proto.write(MemInfoProto.ProcessMemory.MemoryInfo.SHARED_DIRTY_KB, sharedDirty); |
| 2499 | proto.write(MemInfoProto.ProcessMemory.MemoryInfo.PRIVATE_DIRTY_KB, privateDirty); |
| 2500 | proto.write(MemInfoProto.ProcessMemory.MemoryInfo.SHARED_CLEAN_KB, sharedClean); |
| 2501 | proto.write(MemInfoProto.ProcessMemory.MemoryInfo.PRIVATE_CLEAN_KB, privateClean); |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2502 | if (hasSwappedOutPss) { |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 2503 | proto.write(MemInfoProto.ProcessMemory.MemoryInfo.DIRTY_SWAP_PSS_KB, dirtySwapPss); |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2504 | } else { |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 2505 | proto.write(MemInfoProto.ProcessMemory.MemoryInfo.DIRTY_SWAP_KB, dirtySwap); |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2506 | } |
| 2507 | |
| 2508 | proto.end(token); |
| 2509 | } |
| 2510 | |
| 2511 | /** |
| 2512 | * Dump mem info data to proto. |
| 2513 | */ |
| 2514 | public static void dumpMemInfoTable(ProtoOutputStream proto, Debug.MemoryInfo memInfo, |
| 2515 | boolean dumpDalvik, boolean dumpSummaryOnly, |
| 2516 | long nativeMax, long nativeAllocated, long nativeFree, |
| 2517 | long dalvikMax, long dalvikAllocated, long dalvikFree) { |
| 2518 | |
| 2519 | if (!dumpSummaryOnly) { |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 2520 | final long nhToken = proto.start(MemInfoProto.ProcessMemory.NATIVE_HEAP); |
| 2521 | dumpMemoryInfo(proto, MemInfoProto.ProcessMemory.HeapInfo.MEM_INFO, "Native Heap", |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2522 | memInfo.nativePss, memInfo.nativeSwappablePss, memInfo.nativeSharedDirty, |
| 2523 | memInfo.nativePrivateDirty, memInfo.nativeSharedClean, |
| 2524 | memInfo.nativePrivateClean, memInfo.hasSwappedOutPss, |
| 2525 | memInfo.nativeSwappedOut, memInfo.nativeSwappedOutPss); |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 2526 | proto.write(MemInfoProto.ProcessMemory.HeapInfo.HEAP_SIZE_KB, nativeMax); |
| 2527 | proto.write(MemInfoProto.ProcessMemory.HeapInfo.HEAP_ALLOC_KB, nativeAllocated); |
| 2528 | proto.write(MemInfoProto.ProcessMemory.HeapInfo.HEAP_FREE_KB, nativeFree); |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2529 | proto.end(nhToken); |
| 2530 | |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 2531 | final long dvToken = proto.start(MemInfoProto.ProcessMemory.DALVIK_HEAP); |
| 2532 | dumpMemoryInfo(proto, MemInfoProto.ProcessMemory.HeapInfo.MEM_INFO, "Dalvik Heap", |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2533 | memInfo.dalvikPss, memInfo.dalvikSwappablePss, memInfo.dalvikSharedDirty, |
| 2534 | memInfo.dalvikPrivateDirty, memInfo.dalvikSharedClean, |
| 2535 | memInfo.dalvikPrivateClean, memInfo.hasSwappedOutPss, |
| 2536 | memInfo.dalvikSwappedOut, memInfo.dalvikSwappedOutPss); |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 2537 | proto.write(MemInfoProto.ProcessMemory.HeapInfo.HEAP_SIZE_KB, dalvikMax); |
| 2538 | proto.write(MemInfoProto.ProcessMemory.HeapInfo.HEAP_ALLOC_KB, dalvikAllocated); |
| 2539 | proto.write(MemInfoProto.ProcessMemory.HeapInfo.HEAP_FREE_KB, dalvikFree); |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2540 | proto.end(dvToken); |
| 2541 | |
| 2542 | int otherPss = memInfo.otherPss; |
| 2543 | int otherSwappablePss = memInfo.otherSwappablePss; |
| 2544 | int otherSharedDirty = memInfo.otherSharedDirty; |
| 2545 | int otherPrivateDirty = memInfo.otherPrivateDirty; |
| 2546 | int otherSharedClean = memInfo.otherSharedClean; |
| 2547 | int otherPrivateClean = memInfo.otherPrivateClean; |
| 2548 | int otherSwappedOut = memInfo.otherSwappedOut; |
| 2549 | int otherSwappedOutPss = memInfo.otherSwappedOutPss; |
| 2550 | |
| 2551 | for (int i = 0; i < Debug.MemoryInfo.NUM_OTHER_STATS; i++) { |
| 2552 | final int myPss = memInfo.getOtherPss(i); |
| 2553 | final int mySwappablePss = memInfo.getOtherSwappablePss(i); |
| 2554 | final int mySharedDirty = memInfo.getOtherSharedDirty(i); |
| 2555 | final int myPrivateDirty = memInfo.getOtherPrivateDirty(i); |
| 2556 | final int mySharedClean = memInfo.getOtherSharedClean(i); |
| 2557 | final int myPrivateClean = memInfo.getOtherPrivateClean(i); |
| 2558 | final int mySwappedOut = memInfo.getOtherSwappedOut(i); |
| 2559 | final int mySwappedOutPss = memInfo.getOtherSwappedOutPss(i); |
| 2560 | if (myPss != 0 || mySharedDirty != 0 || myPrivateDirty != 0 |
| 2561 | || mySharedClean != 0 || myPrivateClean != 0 |
| 2562 | || (memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut) != 0) { |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 2563 | dumpMemoryInfo(proto, MemInfoProto.ProcessMemory.OTHER_HEAPS, |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2564 | Debug.MemoryInfo.getOtherLabel(i), |
| 2565 | myPss, mySwappablePss, mySharedDirty, myPrivateDirty, |
| 2566 | mySharedClean, myPrivateClean, |
| 2567 | memInfo.hasSwappedOutPss, mySwappedOut, mySwappedOutPss); |
| 2568 | |
| 2569 | otherPss -= myPss; |
| 2570 | otherSwappablePss -= mySwappablePss; |
| 2571 | otherSharedDirty -= mySharedDirty; |
| 2572 | otherPrivateDirty -= myPrivateDirty; |
| 2573 | otherSharedClean -= mySharedClean; |
| 2574 | otherPrivateClean -= myPrivateClean; |
| 2575 | otherSwappedOut -= mySwappedOut; |
| 2576 | otherSwappedOutPss -= mySwappedOutPss; |
| 2577 | } |
| 2578 | } |
| 2579 | |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 2580 | dumpMemoryInfo(proto, MemInfoProto.ProcessMemory.UNKNOWN_HEAP, "Unknown", |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2581 | otherPss, otherSwappablePss, |
| 2582 | otherSharedDirty, otherPrivateDirty, otherSharedClean, otherPrivateClean, |
| 2583 | memInfo.hasSwappedOutPss, otherSwappedOut, otherSwappedOutPss); |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 2584 | final long tToken = proto.start(MemInfoProto.ProcessMemory.TOTAL_HEAP); |
| 2585 | dumpMemoryInfo(proto, MemInfoProto.ProcessMemory.HeapInfo.MEM_INFO, "TOTAL", |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2586 | memInfo.getTotalPss(), memInfo.getTotalSwappablePss(), |
| 2587 | memInfo.getTotalSharedDirty(), memInfo.getTotalPrivateDirty(), |
| 2588 | memInfo.getTotalSharedClean(), memInfo.getTotalPrivateClean(), |
| 2589 | memInfo.hasSwappedOutPss, memInfo.getTotalSwappedOut(), |
| 2590 | memInfo.getTotalSwappedOutPss()); |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 2591 | proto.write(MemInfoProto.ProcessMemory.HeapInfo.HEAP_SIZE_KB, nativeMax + dalvikMax); |
| 2592 | proto.write(MemInfoProto.ProcessMemory.HeapInfo.HEAP_ALLOC_KB, |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2593 | nativeAllocated + dalvikAllocated); |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 2594 | proto.write(MemInfoProto.ProcessMemory.HeapInfo.HEAP_FREE_KB, nativeFree + dalvikFree); |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2595 | proto.end(tToken); |
| 2596 | |
| 2597 | if (dumpDalvik) { |
| 2598 | for (int i = Debug.MemoryInfo.NUM_OTHER_STATS; |
| 2599 | i < Debug.MemoryInfo.NUM_OTHER_STATS + Debug.MemoryInfo.NUM_DVK_STATS; |
| 2600 | i++) { |
| 2601 | final int myPss = memInfo.getOtherPss(i); |
| 2602 | final int mySwappablePss = memInfo.getOtherSwappablePss(i); |
| 2603 | final int mySharedDirty = memInfo.getOtherSharedDirty(i); |
| 2604 | final int myPrivateDirty = memInfo.getOtherPrivateDirty(i); |
| 2605 | final int mySharedClean = memInfo.getOtherSharedClean(i); |
| 2606 | final int myPrivateClean = memInfo.getOtherPrivateClean(i); |
| 2607 | final int mySwappedOut = memInfo.getOtherSwappedOut(i); |
| 2608 | final int mySwappedOutPss = memInfo.getOtherSwappedOutPss(i); |
| 2609 | if (myPss != 0 || mySharedDirty != 0 || myPrivateDirty != 0 |
| 2610 | || mySharedClean != 0 || myPrivateClean != 0 |
| 2611 | || (memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut) != 0) { |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 2612 | dumpMemoryInfo(proto, MemInfoProto.ProcessMemory.DALVIK_DETAILS, |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2613 | Debug.MemoryInfo.getOtherLabel(i), |
| 2614 | myPss, mySwappablePss, mySharedDirty, myPrivateDirty, |
| 2615 | mySharedClean, myPrivateClean, |
| 2616 | memInfo.hasSwappedOutPss, mySwappedOut, mySwappedOutPss); |
| 2617 | } |
| 2618 | } |
| 2619 | } |
| 2620 | } |
| 2621 | |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 2622 | final long asToken = proto.start(MemInfoProto.ProcessMemory.APP_SUMMARY); |
| 2623 | proto.write(MemInfoProto.ProcessMemory.AppSummary.JAVA_HEAP_PSS_KB, |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2624 | memInfo.getSummaryJavaHeap()); |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 2625 | proto.write(MemInfoProto.ProcessMemory.AppSummary.NATIVE_HEAP_PSS_KB, |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2626 | memInfo.getSummaryNativeHeap()); |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 2627 | proto.write(MemInfoProto.ProcessMemory.AppSummary.CODE_PSS_KB, memInfo.getSummaryCode()); |
| 2628 | proto.write(MemInfoProto.ProcessMemory.AppSummary.STACK_PSS_KB, memInfo.getSummaryStack()); |
| 2629 | proto.write(MemInfoProto.ProcessMemory.AppSummary.GRAPHICS_PSS_KB, |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2630 | memInfo.getSummaryGraphics()); |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 2631 | proto.write(MemInfoProto.ProcessMemory.AppSummary.PRIVATE_OTHER_PSS_KB, |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2632 | memInfo.getSummaryPrivateOther()); |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 2633 | proto.write(MemInfoProto.ProcessMemory.AppSummary.SYSTEM_PSS_KB, |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2634 | memInfo.getSummarySystem()); |
| 2635 | if (memInfo.hasSwappedOutPss) { |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 2636 | proto.write(MemInfoProto.ProcessMemory.AppSummary.TOTAL_SWAP_PSS, |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2637 | memInfo.getSummaryTotalSwapPss()); |
| 2638 | } else { |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 2639 | proto.write(MemInfoProto.ProcessMemory.AppSummary.TOTAL_SWAP_PSS, |
Kweku Adams | 598e9a2 | 2017-11-02 17:12:20 -0700 | [diff] [blame] | 2640 | memInfo.getSummaryTotalSwap()); |
| 2641 | } |
| 2642 | proto.end(asToken); |
| 2643 | } |
| 2644 | |
Jeff Hamilton | 52d3203 | 2011-01-08 15:31:26 -0600 | [diff] [blame] | 2645 | public void registerOnActivityPausedListener(Activity activity, |
| 2646 | OnActivityPausedListener listener) { |
| 2647 | synchronized (mOnPauseListeners) { |
| 2648 | ArrayList<OnActivityPausedListener> list = mOnPauseListeners.get(activity); |
| 2649 | if (list == null) { |
| 2650 | list = new ArrayList<OnActivityPausedListener>(); |
| 2651 | mOnPauseListeners.put(activity, list); |
| 2652 | } |
| 2653 | list.add(listener); |
| 2654 | } |
| 2655 | } |
| 2656 | |
Jeff Hamilton | ce3224c | 2011-01-17 11:05:03 -0800 | [diff] [blame] | 2657 | public void unregisterOnActivityPausedListener(Activity activity, |
| 2658 | OnActivityPausedListener listener) { |
| 2659 | synchronized (mOnPauseListeners) { |
| 2660 | ArrayList<OnActivityPausedListener> list = mOnPauseListeners.get(activity); |
| 2661 | if (list != null) { |
| 2662 | list.remove(listener); |
| 2663 | } |
| 2664 | } |
| 2665 | } |
| 2666 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2667 | public final ActivityInfo resolveActivityInfo(Intent intent) { |
| 2668 | ActivityInfo aInfo = intent.resolveActivityInfo( |
| 2669 | mInitialApplication.getPackageManager(), PackageManager.GET_SHARED_LIBRARY_FILES); |
| 2670 | if (aInfo == null) { |
| 2671 | // Throw an exception. |
| 2672 | Instrumentation.checkStartActivityResult( |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 2673 | ActivityManager.START_CLASS_NOT_FOUND, intent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2674 | } |
| 2675 | return aInfo; |
| 2676 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2677 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2678 | public final Activity startActivityNow(Activity parent, String id, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2679 | Intent intent, ActivityInfo activityInfo, IBinder token, Bundle state, |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 2680 | Activity.NonConfigurationInstances lastNonConfigurationInstances) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2681 | ActivityClientRecord r = new ActivityClientRecord(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2682 | r.token = token; |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 2683 | r.ident = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2684 | r.intent = intent; |
| 2685 | r.state = state; |
| 2686 | r.parent = parent; |
| 2687 | r.embeddedID = id; |
| 2688 | r.activityInfo = activityInfo; |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 2689 | r.lastNonConfigurationInstances = lastNonConfigurationInstances; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2690 | if (localLOGV) { |
| 2691 | ComponentName compname = intent.getComponent(); |
| 2692 | String name; |
| 2693 | if (compname != null) { |
| 2694 | name = compname.toShortString(); |
| 2695 | } else { |
| 2696 | name = "(Intent " + intent + ").getComponent() returned null"; |
| 2697 | } |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2698 | Slog.v(TAG, "Performing launch: action=" + intent.getAction() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2699 | + ", comp=" + name |
| 2700 | + ", token=" + token); |
| 2701 | } |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 2702 | // TODO(lifecycler): Can't switch to use #handleLaunchActivity() because it will try to |
| 2703 | // call #reportSizeConfigurations(), but the server might not know anything about the |
| 2704 | // activity if it was launched from LocalAcvitivyManager. |
| 2705 | return performLaunchActivity(r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2706 | } |
| 2707 | |
| 2708 | public final Activity getActivity(IBinder token) { |
| 2709 | return mActivities.get(token).activity; |
| 2710 | } |
| 2711 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 2712 | @Override |
| 2713 | public ActivityClientRecord getActivityClient(IBinder token) { |
| 2714 | return mActivities.get(token); |
| 2715 | } |
| 2716 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2717 | public final void sendActivityResult( |
| 2718 | IBinder token, String id, int requestCode, |
| 2719 | int resultCode, Intent data) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2720 | if (DEBUG_RESULTS) Slog.v(TAG, "sendActivityResult: id=" + id |
Chris Tate | 8a7dc17 | 2009-03-24 20:11:42 -0700 | [diff] [blame] | 2721 | + " req=" + requestCode + " res=" + resultCode + " data=" + data); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2722 | ArrayList<ResultInfo> list = new ArrayList<ResultInfo>(); |
| 2723 | list.add(new ResultInfo(id, requestCode, resultCode, data)); |
Andrii Kulian | 9c5ea9c | 2017-12-07 09:31:01 -0800 | [diff] [blame] | 2724 | final ClientTransaction clientTransaction = ClientTransaction.obtain(mAppThread, token); |
| 2725 | clientTransaction.addCallback(ActivityResultItem.obtain(list)); |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 2726 | try { |
| 2727 | mAppThread.scheduleTransaction(clientTransaction); |
| 2728 | } catch (RemoteException e) { |
| 2729 | // Local scheduling |
| 2730 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2731 | } |
| 2732 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 2733 | void sendMessage(int what, Object obj) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 2734 | sendMessage(what, obj, 0, 0, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2735 | } |
| 2736 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 2737 | private void sendMessage(int what, Object obj, int arg1) { |
| 2738 | sendMessage(what, obj, arg1, 0, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2739 | } |
| 2740 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 2741 | private void sendMessage(int what, Object obj, int arg1, int arg2) { |
| 2742 | sendMessage(what, obj, arg1, arg2, false); |
| 2743 | } |
| 2744 | |
| 2745 | private void sendMessage(int what, Object obj, int arg1, int arg2, boolean async) { |
| 2746 | if (DEBUG_MESSAGES) Slog.v( |
| 2747 | TAG, "SCHEDULE " + what + " " + mH.codeToString(what) |
| 2748 | + ": " + arg1 + " / " + obj); |
| 2749 | Message msg = Message.obtain(); |
| 2750 | msg.what = what; |
| 2751 | msg.obj = obj; |
| 2752 | msg.arg1 = arg1; |
| 2753 | msg.arg2 = arg2; |
| 2754 | if (async) { |
| 2755 | msg.setAsynchronous(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2756 | } |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 2757 | mH.sendMessage(msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2758 | } |
| 2759 | |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 2760 | private void sendMessage(int what, Object obj, int arg1, int arg2, int seq) { |
| 2761 | if (DEBUG_MESSAGES) Slog.v( |
| 2762 | TAG, "SCHEDULE " + mH.codeToString(what) + " arg1=" + arg1 + " arg2=" + arg2 + |
| 2763 | "seq= " + seq); |
| 2764 | Message msg = Message.obtain(); |
| 2765 | msg.what = what; |
| 2766 | SomeArgs args = SomeArgs.obtain(); |
| 2767 | args.arg1 = obj; |
| 2768 | args.argi1 = arg1; |
| 2769 | args.argi2 = arg2; |
| 2770 | args.argi3 = seq; |
| 2771 | msg.obj = args; |
| 2772 | mH.sendMessage(msg); |
| 2773 | } |
| 2774 | |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 2775 | final void scheduleContextCleanup(ContextImpl context, String who, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2776 | String what) { |
| 2777 | ContextCleanupInfo cci = new ContextCleanupInfo(); |
| 2778 | cci.context = context; |
| 2779 | cci.who = who; |
| 2780 | cci.what = what; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 2781 | sendMessage(H.CLEAN_UP_CONTEXT, cci); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2782 | } |
| 2783 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 2784 | /** Core implementation of activity launch. */ |
| 2785 | private Activity performLaunchActivity(ActivityClientRecord r) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2786 | ActivityInfo aInfo = r.activityInfo; |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2787 | if (r.packageInfo == null) { |
| 2788 | r.packageInfo = getPackageInfo(aInfo.applicationInfo, r.compatInfo, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2789 | Context.CONTEXT_INCLUDE_CODE); |
| 2790 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2791 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2792 | ComponentName component = r.intent.getComponent(); |
| 2793 | if (component == null) { |
| 2794 | component = r.intent.resolveActivity( |
| 2795 | mInitialApplication.getPackageManager()); |
| 2796 | r.intent.setComponent(component); |
| 2797 | } |
| 2798 | |
| 2799 | if (r.activityInfo.targetActivity != null) { |
| 2800 | component = new ComponentName(r.activityInfo.packageName, |
| 2801 | r.activityInfo.targetActivity); |
| 2802 | } |
| 2803 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 2804 | ContextImpl appContext = createBaseContextForActivity(r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2805 | Activity activity = null; |
| 2806 | try { |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 2807 | java.lang.ClassLoader cl = appContext.getClassLoader(); |
Dan Sandler | 07fe63e | 2017-08-15 16:41:11 -0400 | [diff] [blame] | 2808 | activity = mInstrumentation.newActivity( |
| 2809 | cl, component.getClassName(), r.intent); |
Brad Fitzpatrick | 5f8b5c1 | 2011-01-20 15:12:08 -0800 | [diff] [blame] | 2810 | StrictMode.incrementExpectedActivityCount(activity.getClass()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2811 | r.intent.setExtrasClassLoader(cl); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 2812 | r.intent.prepareToEnterProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2813 | if (r.state != null) { |
| 2814 | r.state.setClassLoader(cl); |
| 2815 | } |
| 2816 | } catch (Exception e) { |
| 2817 | if (!mInstrumentation.onException(activity, e)) { |
| 2818 | throw new RuntimeException( |
| 2819 | "Unable to instantiate activity " + component |
| 2820 | + ": " + e.toString(), e); |
| 2821 | } |
| 2822 | } |
| 2823 | |
| 2824 | try { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2825 | Application app = r.packageInfo.makeApplication(false, mInstrumentation); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2826 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2827 | if (localLOGV) Slog.v(TAG, "Performing launch of " + r); |
| 2828 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2829 | TAG, r + ": app=" + app |
| 2830 | + ", appName=" + app.getPackageName() |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2831 | + ", pkg=" + r.packageInfo.getPackageName() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2832 | + ", comp=" + r.intent.getComponent().toShortString() |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2833 | + ", dir=" + r.packageInfo.getAppDir()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2834 | |
| 2835 | if (activity != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2836 | CharSequence title = r.activityInfo.loadLabel(appContext.getPackageManager()); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 2837 | Configuration config = new Configuration(mCompatConfiguration); |
Andrii Kulian | d0ad938 | 2016-04-18 20:54:20 -0700 | [diff] [blame] | 2838 | if (r.overrideConfig != null) { |
| 2839 | config.updateFrom(r.overrideConfig); |
| 2840 | } |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2841 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Launching activity " |
Dianne Hackborn | dc6b635 | 2009-09-30 14:20:09 -0700 | [diff] [blame] | 2842 | + r.activityInfo.name + " with config " + config); |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 2843 | Window window = null; |
| 2844 | if (r.mPendingRemoveWindow != null && r.mPreserveWindow) { |
| 2845 | window = r.mPendingRemoveWindow; |
| 2846 | r.mPendingRemoveWindow = null; |
| 2847 | r.mPendingRemoveWindowManager = null; |
| 2848 | } |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 2849 | appContext.setOuterContext(activity); |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 2850 | activity.attach(appContext, this, getInstrumentation(), r.token, |
| 2851 | r.ident, app, r.intent, r.activityInfo, title, r.parent, |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 2852 | r.embeddedID, r.lastNonConfigurationInstances, config, |
Andrii Kulian | 51c1b67 | 2017-04-07 18:39:32 -0700 | [diff] [blame] | 2853 | r.referrer, r.voiceInteractor, window, r.configCallback); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2854 | |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 2855 | r.lastNonConfigurationInstances = null; |
Sudheer Shanka | 84a4895 | 2017-03-08 18:19:01 -0800 | [diff] [blame] | 2856 | checkAndBlockForNetworkAccess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2857 | activity.mStartedActivity = false; |
| 2858 | int theme = r.activityInfo.getThemeResource(); |
| 2859 | if (theme != 0) { |
| 2860 | activity.setTheme(theme); |
| 2861 | } |
| 2862 | |
| 2863 | activity.mCalled = false; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2864 | if (r.isPersistable()) { |
| 2865 | mInstrumentation.callActivityOnCreate(activity, r.state, r.persistentState); |
| 2866 | } else { |
| 2867 | mInstrumentation.callActivityOnCreate(activity, r.state); |
| 2868 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2869 | if (!activity.mCalled) { |
| 2870 | throw new SuperNotCalledException( |
| 2871 | "Activity " + r.intent.getComponent().toShortString() + |
| 2872 | " did not call through to super.onCreate()"); |
| 2873 | } |
| 2874 | r.activity = activity; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2875 | } |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 2876 | r.setState(ON_CREATE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2877 | |
| 2878 | mActivities.put(r.token, r); |
Bryce Lee | d946f86 | 2018-01-16 15:59:47 -0800 | [diff] [blame] | 2879 | mRecentTokens.push(r.token.hashCode()); |
| 2880 | |
| 2881 | if (mRecentTokens.size() > MAX_RECENT_TOKENS) { |
| 2882 | mRecentTokens.removeLast(); |
| 2883 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2884 | |
| 2885 | } catch (SuperNotCalledException e) { |
| 2886 | throw e; |
| 2887 | |
| 2888 | } catch (Exception e) { |
| 2889 | if (!mInstrumentation.onException(activity, e)) { |
| 2890 | throw new RuntimeException( |
| 2891 | "Unable to start activity " + component |
| 2892 | + ": " + e.toString(), e); |
| 2893 | } |
| 2894 | } |
| 2895 | |
| 2896 | return activity; |
| 2897 | } |
| 2898 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 2899 | @Override |
| 2900 | public void handleStartActivity(ActivityClientRecord r, |
| 2901 | PendingTransactionActions pendingActions) { |
| 2902 | final Activity activity = r.activity; |
| 2903 | if (r.activity == null) { |
| 2904 | // TODO(lifecycler): What do we do in this case? |
| 2905 | return; |
| 2906 | } |
| 2907 | if (!r.stopped) { |
| 2908 | throw new IllegalStateException("Can't start activity that is not stopped."); |
| 2909 | } |
| 2910 | if (r.activity.mFinished) { |
| 2911 | // TODO(lifecycler): How can this happen? |
| 2912 | return; |
| 2913 | } |
| 2914 | |
| 2915 | // Start |
| 2916 | activity.performStart(); |
| 2917 | r.setState(ON_START); |
| 2918 | |
| 2919 | if (pendingActions == null) { |
| 2920 | // No more work to do. |
| 2921 | return; |
| 2922 | } |
| 2923 | |
| 2924 | // Restore instance state |
| 2925 | if (pendingActions.shouldRestoreInstanceState()) { |
| 2926 | if (r.isPersistable()) { |
| 2927 | if (r.state != null || r.persistentState != null) { |
| 2928 | mInstrumentation.callActivityOnRestoreInstanceState(activity, r.state, |
| 2929 | r.persistentState); |
| 2930 | } |
| 2931 | } else if (r.state != null) { |
| 2932 | mInstrumentation.callActivityOnRestoreInstanceState(activity, r.state); |
| 2933 | } |
| 2934 | } |
| 2935 | |
| 2936 | // Call postOnCreate() |
| 2937 | if (pendingActions.shouldCallOnPostCreate()) { |
| 2938 | activity.mCalled = false; |
| 2939 | if (r.isPersistable()) { |
| 2940 | mInstrumentation.callActivityOnPostCreate(activity, r.state, |
| 2941 | r.persistentState); |
| 2942 | } else { |
| 2943 | mInstrumentation.callActivityOnPostCreate(activity, r.state); |
| 2944 | } |
| 2945 | if (!activity.mCalled) { |
| 2946 | throw new SuperNotCalledException( |
| 2947 | "Activity " + r.intent.getComponent().toShortString() |
| 2948 | + " did not call through to super.onPostCreate()"); |
| 2949 | } |
| 2950 | } |
| 2951 | } |
| 2952 | |
Sudheer Shanka | 84a4895 | 2017-03-08 18:19:01 -0800 | [diff] [blame] | 2953 | /** |
| 2954 | * Checks if {@link #mNetworkBlockSeq} is {@link #INVALID_PROC_STATE_SEQ} and if so, returns |
| 2955 | * immediately. Otherwise, makes a blocking call to ActivityManagerService to wait for the |
| 2956 | * network rules to get updated. |
| 2957 | */ |
| 2958 | private void checkAndBlockForNetworkAccess() { |
| 2959 | synchronized (mNetworkPolicyLock) { |
| 2960 | if (mNetworkBlockSeq != INVALID_PROC_STATE_SEQ) { |
| 2961 | try { |
| 2962 | ActivityManager.getService().waitForNetworkStateUpdate(mNetworkBlockSeq); |
| 2963 | mNetworkBlockSeq = INVALID_PROC_STATE_SEQ; |
| 2964 | } catch (RemoteException ignored) {} |
| 2965 | } |
| 2966 | } |
| 2967 | } |
| 2968 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 2969 | private ContextImpl createBaseContextForActivity(ActivityClientRecord r) { |
| 2970 | final int displayId; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2971 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 2972 | displayId = ActivityManager.getService().getActivityDisplayId(r.token); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2973 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2974 | throw e.rethrowFromSystemServer(); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2975 | } |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 2976 | |
Wale Ogunwale | 7c72668 | 2015-02-06 17:34:28 -0800 | [diff] [blame] | 2977 | ContextImpl appContext = ContextImpl.createActivityContext( |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2978 | this, r.packageInfo, r.activityInfo, r.token, displayId, r.overrideConfig); |
Wale Ogunwale | 7c72668 | 2015-02-06 17:34:28 -0800 | [diff] [blame] | 2979 | |
| 2980 | final DisplayManagerGlobal dm = DisplayManagerGlobal.getInstance(); |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 2981 | // For debugging purposes, if the activity's package name contains the value of |
| 2982 | // the "debug.use-second-display" system property as a substring, then show |
| 2983 | // its content on a secondary display if there is one. |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 2984 | String pkgName = SystemProperties.get("debug.second-display.pkg"); |
| 2985 | if (pkgName != null && !pkgName.isEmpty() |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 2986 | && r.packageInfo.mPackageName.contains(pkgName)) { |
Wale Ogunwale | 7c72668 | 2015-02-06 17:34:28 -0800 | [diff] [blame] | 2987 | for (int id : dm.getDisplayIds()) { |
| 2988 | if (id != Display.DEFAULT_DISPLAY) { |
Wale Ogunwale | 2669851 | 2015-06-05 16:55:33 -0700 | [diff] [blame] | 2989 | Display display = |
Bryce Lee | 609bf65 | 2017-02-09 16:50:13 -0800 | [diff] [blame] | 2990 | dm.getCompatibleDisplay(id, appContext.getResources()); |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 2991 | appContext = (ContextImpl) appContext.createDisplayContext(display); |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 2992 | break; |
| 2993 | } |
| 2994 | } |
| 2995 | } |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 2996 | return appContext; |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 2997 | } |
| 2998 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 2999 | /** |
| 3000 | * Extended implementation of activity launch. Used when server requests a launch or relaunch. |
| 3001 | */ |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 3002 | @Override |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 3003 | public Activity handleLaunchActivity(ActivityClientRecord r, |
| 3004 | PendingTransactionActions pendingActions) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3005 | // If we are getting ready to gc after going to the background, well |
| 3006 | // we are back active so skip it. |
| 3007 | unscheduleGcIdler(); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3008 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3009 | |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 3010 | if (r.profilerInfo != null) { |
| 3011 | mProfiler.setProfiler(r.profilerInfo); |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 3012 | mProfiler.startProfiling(); |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 3013 | } |
| 3014 | |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 3015 | // Make sure we are running with the most recent config. |
| 3016 | handleConfigurationChanged(null, null); |
| 3017 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3018 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3019 | TAG, "Handling launch of " + r); |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 3020 | |
Chet Haase | 0d1c27a | 2014-11-03 18:35:16 +0000 | [diff] [blame] | 3021 | // Initialize before creating the activity |
Jesse Hall | c37984f | 2017-05-23 16:55:08 -0700 | [diff] [blame] | 3022 | if (!ThreadedRenderer.sRendererDisabled) { |
| 3023 | GraphicsEnvironment.earlyInitEGL(); |
| 3024 | } |
Chet Haase | 0d1c27a | 2014-11-03 18:35:16 +0000 | [diff] [blame] | 3025 | WindowManagerGlobal.initialize(); |
| 3026 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 3027 | final Activity a = performLaunchActivity(r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3028 | |
| 3029 | if (a != null) { |
Dianne Hackborn | 871ecdc | 2009-12-11 15:24:33 -0800 | [diff] [blame] | 3030 | r.createdConfig = new Configuration(mConfiguration); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 3031 | reportSizeConfigurations(r); |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 3032 | if (!r.activity.mFinished && pendingActions != null) { |
| 3033 | pendingActions.setOldState(r.state); |
| 3034 | pendingActions.setRestoreInstanceState(true); |
| 3035 | pendingActions.setCallOnPostCreate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3036 | } |
| 3037 | } else { |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 3038 | // 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] | 3039 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3040 | ActivityManager.getService() |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 3041 | .finishActivity(r.token, Activity.RESULT_CANCELED, null, |
| 3042 | Activity.DONT_FINISH_TASK_WITH_ACTIVITY); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3043 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3044 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3045 | } |
| 3046 | } |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 3047 | |
| 3048 | return a; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3049 | } |
| 3050 | |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 3051 | private void reportSizeConfigurations(ActivityClientRecord r) { |
| 3052 | Configuration[] configurations = r.activity.getResources().getSizeConfigurations(); |
| 3053 | if (configurations == null) { |
| 3054 | return; |
| 3055 | } |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 3056 | SparseIntArray horizontal = new SparseIntArray(); |
| 3057 | SparseIntArray vertical = new SparseIntArray(); |
| 3058 | SparseIntArray smallest = new SparseIntArray(); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 3059 | for (int i = configurations.length - 1; i >= 0; i--) { |
| 3060 | Configuration config = configurations[i]; |
| 3061 | if (config.screenHeightDp != Configuration.SCREEN_HEIGHT_DP_UNDEFINED) { |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 3062 | vertical.put(config.screenHeightDp, 0); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 3063 | } |
| 3064 | if (config.screenWidthDp != Configuration.SCREEN_WIDTH_DP_UNDEFINED) { |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 3065 | horizontal.put(config.screenWidthDp, 0); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 3066 | } |
| 3067 | if (config.smallestScreenWidthDp != Configuration.SMALLEST_SCREEN_WIDTH_DP_UNDEFINED) { |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 3068 | smallest.put(config.smallestScreenWidthDp, 0); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 3069 | } |
| 3070 | } |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 3071 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3072 | ActivityManager.getService().reportSizeConfigurations(r.token, |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 3073 | horizontal.copyKeys(), vertical.copyKeys(), smallest.copyKeys()); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 3074 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3075 | throw ex.rethrowFromSystemServer(); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 3076 | } |
| 3077 | |
| 3078 | } |
| 3079 | |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 3080 | private void deliverNewIntents(ActivityClientRecord r, List<ReferrerIntent> intents) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3081 | final int N = intents.size(); |
| 3082 | for (int i=0; i<N; i++) { |
Dianne Hackborn | a01a0fa | 2014-12-02 10:33:14 -0800 | [diff] [blame] | 3083 | ReferrerIntent intent = intents.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3084 | intent.setExtrasClassLoader(r.activity.getClassLoader()); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 3085 | intent.prepareToEnterProcess(); |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 3086 | r.activity.mFragments.noteStateNotSaved(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3087 | mInstrumentation.callActivityOnNewIntent(r.activity, intent); |
| 3088 | } |
| 3089 | } |
| 3090 | |
Wale Ogunwale | 826c706 | 2016-09-13 08:25:54 -0700 | [diff] [blame] | 3091 | void performNewIntents(IBinder token, List<ReferrerIntent> intents, boolean andPause) { |
| 3092 | final ActivityClientRecord r = mActivities.get(token); |
| 3093 | if (r == null) { |
| 3094 | return; |
| 3095 | } |
| 3096 | |
| 3097 | final boolean resumed = !r.paused; |
| 3098 | if (resumed) { |
| 3099 | r.activity.mTemporaryPause = true; |
| 3100 | mInstrumentation.callActivityOnPause(r.activity); |
| 3101 | } |
Sudheer Shanka | 43b5ea4 | 2017-06-21 11:24:53 -0700 | [diff] [blame] | 3102 | checkAndBlockForNetworkAccess(); |
Wale Ogunwale | 826c706 | 2016-09-13 08:25:54 -0700 | [diff] [blame] | 3103 | deliverNewIntents(r, intents); |
| 3104 | if (resumed) { |
Dake Gu | 67decfa | 2017-12-27 11:48:08 -0800 | [diff] [blame] | 3105 | r.activity.performResume(false); |
Wale Ogunwale | 826c706 | 2016-09-13 08:25:54 -0700 | [diff] [blame] | 3106 | r.activity.mTemporaryPause = false; |
| 3107 | } |
| 3108 | |
| 3109 | if (r.paused && andPause) { |
| 3110 | // In this case the activity was in the paused state when we delivered the intent, |
| 3111 | // to guarantee onResume gets called after onNewIntent we temporarily resume the |
| 3112 | // activity and pause again as the caller wanted. |
| 3113 | performResumeActivity(token, false, "performNewIntents"); |
| 3114 | performPauseActivityIfNeeded(r, "performNewIntents"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3115 | } |
| 3116 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3117 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 3118 | @Override |
| 3119 | public void handleNewIntent(IBinder token, List<ReferrerIntent> intents, boolean andPause) { |
| 3120 | performNewIntents(token, intents, andPause); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3121 | } |
| 3122 | |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 3123 | public void handleRequestAssistContextExtras(RequestAssistContextExtras cmd) { |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 3124 | // Filling for autofill has a few differences: |
Felipe Leme | 1ca634a | 2016-11-28 17:21:21 -0800 | [diff] [blame] | 3125 | // - it does not need an AssistContent |
| 3126 | // - it does not call onProvideAssistData() |
| 3127 | // - it needs an IAutoFillCallback |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 3128 | boolean forAutofill = cmd.requestType == ActivityManager.ASSIST_CONTEXT_AUTOFILL; |
Felipe Leme | 1ca634a | 2016-11-28 17:21:21 -0800 | [diff] [blame] | 3129 | |
Felipe Leme | 85d1c2d | 2017-04-21 08:56:04 -0700 | [diff] [blame] | 3130 | // TODO: decide if lastSessionId logic applies to autofill sessions |
Amith Yamasani | 4f128e4 | 2016-05-10 11:44:12 -0700 | [diff] [blame] | 3131 | if (mLastSessionId != cmd.sessionId) { |
| 3132 | // Clear the existing structures |
| 3133 | mLastSessionId = cmd.sessionId; |
| 3134 | for (int i = mLastAssistStructures.size() - 1; i >= 0; i--) { |
| 3135 | AssistStructure structure = mLastAssistStructures.get(i).get(); |
| 3136 | if (structure != null) { |
| 3137 | structure.clearSendChannel(); |
| 3138 | } |
| 3139 | mLastAssistStructures.remove(i); |
Dianne Hackborn | 782d498 | 2015-07-08 17:36:37 -0700 | [diff] [blame] | 3140 | } |
| 3141 | } |
Felipe Leme | 29a5b0d | 2016-10-25 14:57:11 -0700 | [diff] [blame] | 3142 | |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 3143 | Bundle data = new Bundle(); |
Dianne Hackborn | 09d57fe | 2015-05-27 18:05:52 -0700 | [diff] [blame] | 3144 | AssistStructure structure = null; |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 3145 | AssistContent content = forAutofill ? null : new AssistContent(); |
Amith Yamasani | 858f98d | 2017-02-22 12:59:53 -0800 | [diff] [blame] | 3146 | final long startTime = SystemClock.uptimeMillis(); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 3147 | ActivityClientRecord r = mActivities.get(cmd.activityToken); |
Dianne Hackborn | a3acdb3 | 2015-06-08 17:07:40 -0700 | [diff] [blame] | 3148 | Uri referrer = null; |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 3149 | if (r != null) { |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 3150 | if (!forAutofill) { |
Felipe Leme | 1ca634a | 2016-11-28 17:21:21 -0800 | [diff] [blame] | 3151 | r.activity.getApplication().dispatchOnProvideAssistData(r.activity, data); |
Felipe Leme | 29a5b0d | 2016-10-25 14:57:11 -0700 | [diff] [blame] | 3152 | r.activity.onProvideAssistData(data); |
Felipe Leme | 6d55387 | 2016-12-08 17:13:25 -0800 | [diff] [blame] | 3153 | referrer = r.activity.onProvideReferrer(); |
Felipe Leme | 29a5b0d | 2016-10-25 14:57:11 -0700 | [diff] [blame] | 3154 | } |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 3155 | if (cmd.requestType == ActivityManager.ASSIST_CONTEXT_FULL || forAutofill) { |
Svet Ganov | fd31f85 | 2017-04-26 15:54:27 -0700 | [diff] [blame] | 3156 | structure = new AssistStructure(r.activity, forAutofill, cmd.flags); |
Adam Skory | 4aaed14 | 2015-04-22 11:29:31 -0600 | [diff] [blame] | 3157 | Intent activityIntent = r.activity.getIntent(); |
Felipe Leme | 6d55387 | 2016-12-08 17:13:25 -0800 | [diff] [blame] | 3158 | boolean notSecure = r.window == null || |
Dianne Hackborn | 09d57fe | 2015-05-27 18:05:52 -0700 | [diff] [blame] | 3159 | (r.window.getAttributes().flags |
Felipe Leme | 6d55387 | 2016-12-08 17:13:25 -0800 | [diff] [blame] | 3160 | & WindowManager.LayoutParams.FLAG_SECURE) == 0; |
| 3161 | if (activityIntent != null && notSecure) { |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 3162 | if (!forAutofill) { |
Felipe Leme | 1ca634a | 2016-11-28 17:21:21 -0800 | [diff] [blame] | 3163 | Intent intent = new Intent(activityIntent); |
| 3164 | intent.setFlags(intent.getFlags() & ~(Intent.FLAG_GRANT_WRITE_URI_PERMISSION |
| 3165 | | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION)); |
| 3166 | intent.removeUnsafeExtras(); |
Felipe Leme | 29a5b0d | 2016-10-25 14:57:11 -0700 | [diff] [blame] | 3167 | content.setDefaultIntent(intent); |
| 3168 | } |
Adam Skory | 4aaed14 | 2015-04-22 11:29:31 -0600 | [diff] [blame] | 3169 | } else { |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 3170 | if (!forAutofill) { |
Felipe Leme | 29a5b0d | 2016-10-25 14:57:11 -0700 | [diff] [blame] | 3171 | content.setDefaultIntent(new Intent()); |
| 3172 | } |
Adam Skory | 4aaed14 | 2015-04-22 11:29:31 -0600 | [diff] [blame] | 3173 | } |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 3174 | if (!forAutofill) { |
Felipe Leme | 29a5b0d | 2016-10-25 14:57:11 -0700 | [diff] [blame] | 3175 | r.activity.onProvideAssistContent(content); |
| 3176 | } |
Dianne Hackborn | a83ce1d | 2015-03-11 15:16:13 -0700 | [diff] [blame] | 3177 | } |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 3178 | } |
Dianne Hackborn | 09d57fe | 2015-05-27 18:05:52 -0700 | [diff] [blame] | 3179 | if (structure == null) { |
| 3180 | structure = new AssistStructure(); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 3181 | } |
Felipe Leme | 0200d9e | 2017-01-24 15:10:26 -0800 | [diff] [blame] | 3182 | |
Felipe Leme | 85d1c2d | 2017-04-21 08:56:04 -0700 | [diff] [blame] | 3183 | // TODO: decide if lastSessionId logic applies to autofill sessions |
Amith Yamasani | 858f98d | 2017-02-22 12:59:53 -0800 | [diff] [blame] | 3184 | |
| 3185 | structure.setAcquisitionStartTime(startTime); |
| 3186 | structure.setAcquisitionEndTime(SystemClock.uptimeMillis()); |
| 3187 | |
Amith Yamasani | 4f128e4 | 2016-05-10 11:44:12 -0700 | [diff] [blame] | 3188 | mLastAssistStructures.add(new WeakReference<>(structure)); |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3189 | IActivityManager mgr = ActivityManager.getService(); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 3190 | try { |
Dianne Hackborn | a3acdb3 | 2015-06-08 17:07:40 -0700 | [diff] [blame] | 3191 | mgr.reportAssistContextExtras(cmd.requestToken, data, structure, content, referrer); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 3192 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3193 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 3194 | } |
| 3195 | } |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 3196 | |
| 3197 | public void handleTranslucentConversionComplete(IBinder token, boolean drawComplete) { |
| 3198 | ActivityClientRecord r = mActivities.get(token); |
| 3199 | if (r != null) { |
| 3200 | r.activity.onTranslucentConversionComplete(drawComplete); |
| 3201 | } |
| 3202 | } |
| 3203 | |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 3204 | public void onNewActivityOptions(IBinder token, ActivityOptions options) { |
| 3205 | ActivityClientRecord r = mActivities.get(token); |
| 3206 | if (r != null) { |
| 3207 | r.activity.onNewActivityOptions(options); |
| 3208 | } |
| 3209 | } |
| 3210 | |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 3211 | public void handleInstallProvider(ProviderInfo info) { |
Jeff Sharkey | bb2e2ca | 2014-10-23 11:42:31 -0700 | [diff] [blame] | 3212 | final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); |
| 3213 | try { |
Jeff Sharkey | a6bfeae | 2017-07-05 16:50:24 -0600 | [diff] [blame] | 3214 | installContentProviders(mInitialApplication, Arrays.asList(info)); |
Jeff Sharkey | bb2e2ca | 2014-10-23 11:42:31 -0700 | [diff] [blame] | 3215 | } finally { |
| 3216 | StrictMode.setThreadPolicy(oldPolicy); |
| 3217 | } |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 3218 | } |
| 3219 | |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 3220 | private void handleEnterAnimationComplete(IBinder token) { |
| 3221 | ActivityClientRecord r = mActivities.get(token); |
| 3222 | if (r != null) { |
Filip Gruszczynski | 6eafa90 | 2014-11-14 14:24:37 -0800 | [diff] [blame] | 3223 | r.activity.dispatchEnterAnimationComplete(); |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 3224 | } |
| 3225 | } |
| 3226 | |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 3227 | private void handleStartBinderTracking() { |
| 3228 | Binder.enableTracing(); |
| 3229 | } |
| 3230 | |
| 3231 | private void handleStopBinderTrackingAndDump(ParcelFileDescriptor fd) { |
| 3232 | try { |
| 3233 | Binder.disableTracing(); |
| 3234 | Binder.getTransactionTracker().writeTracesToFile(fd); |
| 3235 | } finally { |
| 3236 | IoUtils.closeQuietly(fd); |
| 3237 | Binder.getTransactionTracker().clearTraces(); |
| 3238 | } |
| 3239 | } |
| 3240 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 3241 | @Override |
| 3242 | public void handleMultiWindowModeChanged(IBinder token, boolean isInMultiWindowMode, |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 3243 | Configuration overrideConfig) { |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 3244 | final ActivityClientRecord r = mActivities.get(token); |
| 3245 | if (r != null) { |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 3246 | final Configuration newConfig = new Configuration(mConfiguration); |
| 3247 | if (overrideConfig != null) { |
| 3248 | newConfig.updateFrom(overrideConfig); |
| 3249 | } |
| 3250 | r.activity.dispatchMultiWindowModeChanged(isInMultiWindowMode, newConfig); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 3251 | } |
| 3252 | } |
| 3253 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 3254 | @Override |
| 3255 | public void handlePictureInPictureModeChanged(IBinder token, boolean isInPipMode, |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 3256 | Configuration overrideConfig) { |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 3257 | final ActivityClientRecord r = mActivities.get(token); |
| 3258 | if (r != null) { |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 3259 | final Configuration newConfig = new Configuration(mConfiguration); |
| 3260 | if (overrideConfig != null) { |
| 3261 | newConfig.updateFrom(overrideConfig); |
| 3262 | } |
| 3263 | r.activity.dispatchPictureInPictureModeChanged(isInPipMode, newConfig); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 3264 | } |
| 3265 | } |
| 3266 | |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 3267 | private void handleLocalVoiceInteractionStarted(IBinder token, IVoiceInteractor interactor) { |
| 3268 | final ActivityClientRecord r = mActivities.get(token); |
| 3269 | if (r != null) { |
| 3270 | r.voiceInteractor = interactor; |
| 3271 | r.activity.setVoiceInteractor(interactor); |
| 3272 | if (interactor == null) { |
| 3273 | r.activity.onLocalVoiceInteractionStopped(); |
| 3274 | } else { |
| 3275 | r.activity.onLocalVoiceInteractionStarted(); |
| 3276 | } |
| 3277 | } |
| 3278 | } |
| 3279 | |
Andreas Gampe | ab8a63b | 2018-01-05 13:55:15 -0800 | [diff] [blame] | 3280 | private static boolean attemptAttachAgent(String agent, ClassLoader classLoader) { |
Leonard Mosescu | f3409ce | 2016-10-06 17:32:05 -0700 | [diff] [blame] | 3281 | try { |
Andreas Gampe | ab8a63b | 2018-01-05 13:55:15 -0800 | [diff] [blame] | 3282 | VMDebug.attachAgent(agent, classLoader); |
| 3283 | return true; |
Leonard Mosescu | f3409ce | 2016-10-06 17:32:05 -0700 | [diff] [blame] | 3284 | } catch (IOException e) { |
Andreas Gampe | ab8a63b | 2018-01-05 13:55:15 -0800 | [diff] [blame] | 3285 | Slog.e(TAG, "Attaching agent with " + classLoader + " failed: " + agent); |
| 3286 | return false; |
| 3287 | } |
| 3288 | } |
| 3289 | |
| 3290 | static void handleAttachAgent(String agent, LoadedApk loadedApk) { |
| 3291 | ClassLoader classLoader = loadedApk != null ? loadedApk.getClassLoader() : null; |
| 3292 | if (attemptAttachAgent(agent, classLoader)) { |
| 3293 | return; |
| 3294 | } |
| 3295 | if (classLoader != null) { |
| 3296 | attemptAttachAgent(agent, null); |
Leonard Mosescu | f3409ce | 2016-10-06 17:32:05 -0700 | [diff] [blame] | 3297 | } |
| 3298 | } |
| 3299 | |
Brad Fitzpatrick | bfb1919 | 2010-10-29 15:25:44 -0700 | [diff] [blame] | 3300 | private static final ThreadLocal<Intent> sCurrentBroadcastIntent = new ThreadLocal<Intent>(); |
| 3301 | |
| 3302 | /** |
| 3303 | * Return the Intent that's currently being handled by a |
| 3304 | * BroadcastReceiver on this thread, or null if none. |
| 3305 | * @hide |
| 3306 | */ |
| 3307 | public static Intent getIntentBeingBroadcast() { |
| 3308 | return sCurrentBroadcastIntent.get(); |
| 3309 | } |
| 3310 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3311 | private void handleReceiver(ReceiverData data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3312 | // If we are getting ready to gc after going to the background, well |
| 3313 | // we are back active so skip it. |
| 3314 | unscheduleGcIdler(); |
| 3315 | |
| 3316 | String component = data.intent.getComponent().getClassName(); |
| 3317 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3318 | LoadedApk packageInfo = getPackageInfoNoCheck( |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 3319 | data.info.applicationInfo, data.compatInfo); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3320 | |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3321 | IActivityManager mgr = ActivityManager.getService(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3322 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 3323 | Application app; |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3324 | BroadcastReceiver receiver; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 3325 | ContextImpl context; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3326 | try { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3327 | app = packageInfo.makeApplication(false, mInstrumentation); |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 3328 | context = (ContextImpl) app.getBaseContext(); |
| 3329 | if (data.info.splitName != null) { |
| 3330 | context = (ContextImpl) context.createContextForSplit(data.info.splitName); |
| 3331 | } |
| 3332 | java.lang.ClassLoader cl = context.getClassLoader(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3333 | data.intent.setExtrasClassLoader(cl); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 3334 | data.intent.prepareToEnterProcess(); |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 3335 | data.setExtrasClassLoader(cl); |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3336 | receiver = packageInfo.getAppFactory() |
Jason Monk | a80bfb5 | 2017-11-16 17:15:37 -0500 | [diff] [blame] | 3337 | .instantiateReceiver(cl, data.info.name, data.intent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3338 | } catch (Exception e) { |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 3339 | if (DEBUG_BROADCAST) Slog.i(TAG, |
| 3340 | "Finishing failed broadcast to " + data.intent.getComponent()); |
| 3341 | data.sendFinished(mgr); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3342 | throw new RuntimeException( |
| 3343 | "Unable to instantiate receiver " + component |
| 3344 | + ": " + e.toString(), e); |
| 3345 | } |
| 3346 | |
| 3347 | try { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3348 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3349 | TAG, "Performing receive of " + data.intent |
| 3350 | + ": app=" + app |
| 3351 | + ", appName=" + app.getPackageName() |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3352 | + ", pkg=" + packageInfo.getPackageName() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3353 | + ", comp=" + data.intent.getComponent().toShortString() |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3354 | + ", dir=" + packageInfo.getAppDir()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3355 | |
Brad Fitzpatrick | bfb1919 | 2010-10-29 15:25:44 -0700 | [diff] [blame] | 3356 | sCurrentBroadcastIntent.set(data.intent); |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 3357 | receiver.setPendingResult(data); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3358 | receiver.onReceive(context.getReceiverRestrictedContext(), |
| 3359 | data.intent); |
| 3360 | } catch (Exception e) { |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 3361 | if (DEBUG_BROADCAST) Slog.i(TAG, |
| 3362 | "Finishing failed broadcast to " + data.intent.getComponent()); |
| 3363 | data.sendFinished(mgr); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3364 | if (!mInstrumentation.onException(receiver, e)) { |
| 3365 | throw new RuntimeException( |
| 3366 | "Unable to start receiver " + component |
| 3367 | + ": " + e.toString(), e); |
| 3368 | } |
Brad Fitzpatrick | bfb1919 | 2010-10-29 15:25:44 -0700 | [diff] [blame] | 3369 | } finally { |
| 3370 | sCurrentBroadcastIntent.set(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3371 | } |
| 3372 | |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 3373 | if (receiver.getPendingResult() != null) { |
| 3374 | data.finish(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3375 | } |
| 3376 | } |
| 3377 | |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3378 | // Instantiate a BackupAgent and tell it that it's alive |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3379 | private void handleCreateBackupAgent(CreateBackupAgentData data) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3380 | if (DEBUG_BACKUP) Slog.v(TAG, "handleCreateBackupAgent: " + data); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3381 | |
Christopher Tate | 346acb1 | 2012-10-15 19:20:25 -0700 | [diff] [blame] | 3382 | // Sanity check the requested target package's uid against ours |
| 3383 | try { |
| 3384 | PackageInfo requestedPackage = getPackageManager().getPackageInfo( |
| 3385 | data.appInfo.packageName, 0, UserHandle.myUserId()); |
| 3386 | if (requestedPackage.applicationInfo.uid != Process.myUid()) { |
| 3387 | Slog.w(TAG, "Asked to instantiate non-matching package " |
| 3388 | + data.appInfo.packageName); |
| 3389 | return; |
| 3390 | } |
| 3391 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3392 | throw e.rethrowFromSystemServer(); |
Christopher Tate | 346acb1 | 2012-10-15 19:20:25 -0700 | [diff] [blame] | 3393 | } |
| 3394 | |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3395 | // no longer idle; we have backup work to do |
| 3396 | unscheduleGcIdler(); |
| 3397 | |
| 3398 | // instantiate the BackupAgent class named in the manifest |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3399 | LoadedApk packageInfo = getPackageInfoNoCheck(data.appInfo, data.compatInfo); |
| 3400 | String packageName = packageInfo.mPackageName; |
Christopher Tate | 346acb1 | 2012-10-15 19:20:25 -0700 | [diff] [blame] | 3401 | if (packageName == null) { |
| 3402 | Slog.d(TAG, "Asked to create backup agent for nonexistent package"); |
| 3403 | return; |
| 3404 | } |
| 3405 | |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3406 | String classname = data.appInfo.backupAgentName; |
Christopher Tate | 79ec80d | 2011-06-24 14:58:49 -0700 | [diff] [blame] | 3407 | // full backup operation but no app-supplied agent? use the default implementation |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 3408 | if (classname == null && (data.backupMode == ApplicationThreadConstants.BACKUP_MODE_FULL |
| 3409 | || data.backupMode == ApplicationThreadConstants.BACKUP_MODE_RESTORE_FULL)) { |
Christopher Tate | 4a627c7 | 2011-04-01 14:43:32 -0700 | [diff] [blame] | 3410 | classname = "android.app.backup.FullBackupAgent"; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3411 | } |
Christopher Tate | 4a627c7 | 2011-04-01 14:43:32 -0700 | [diff] [blame] | 3412 | |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3413 | try { |
Christopher Tate | d1475e0 | 2009-07-09 15:36:17 -0700 | [diff] [blame] | 3414 | IBinder binder = null; |
Christopher Tate | 2e40d11 | 2014-07-15 12:37:38 -0700 | [diff] [blame] | 3415 | BackupAgent agent = mBackupAgents.get(packageName); |
| 3416 | if (agent != null) { |
| 3417 | // reusing the existing instance |
| 3418 | if (DEBUG_BACKUP) { |
| 3419 | Slog.v(TAG, "Reusing existing agent instance"); |
Christopher Tate | d1475e0 | 2009-07-09 15:36:17 -0700 | [diff] [blame] | 3420 | } |
Christopher Tate | 2e40d11 | 2014-07-15 12:37:38 -0700 | [diff] [blame] | 3421 | binder = agent.onBind(); |
| 3422 | } else { |
| 3423 | try { |
| 3424 | if (DEBUG_BACKUP) Slog.v(TAG, "Initializing agent class " + classname); |
| 3425 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3426 | java.lang.ClassLoader cl = packageInfo.getClassLoader(); |
Dan Sandler | 07fe63e | 2017-08-15 16:41:11 -0400 | [diff] [blame] | 3427 | agent = (BackupAgent) cl.loadClass(classname).newInstance(); |
Christopher Tate | 2e40d11 | 2014-07-15 12:37:38 -0700 | [diff] [blame] | 3428 | |
| 3429 | // set up the agent's context |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3430 | ContextImpl context = ContextImpl.createAppContext(this, packageInfo); |
Christopher Tate | 2e40d11 | 2014-07-15 12:37:38 -0700 | [diff] [blame] | 3431 | context.setOuterContext(agent); |
| 3432 | agent.attach(context); |
| 3433 | |
| 3434 | agent.onCreate(); |
| 3435 | binder = agent.onBind(); |
| 3436 | mBackupAgents.put(packageName, agent); |
| 3437 | } catch (Exception e) { |
| 3438 | // If this is during restore, fail silently; otherwise go |
| 3439 | // ahead and let the user see the crash. |
| 3440 | Slog.e(TAG, "Agent threw during creation: " + e); |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 3441 | if (data.backupMode != ApplicationThreadConstants.BACKUP_MODE_RESTORE |
| 3442 | && data.backupMode != |
| 3443 | ApplicationThreadConstants.BACKUP_MODE_RESTORE_FULL) { |
Christopher Tate | 2e40d11 | 2014-07-15 12:37:38 -0700 | [diff] [blame] | 3444 | throw e; |
| 3445 | } |
| 3446 | // falling through with 'binder' still null |
| 3447 | } |
Christopher Tate | d1475e0 | 2009-07-09 15:36:17 -0700 | [diff] [blame] | 3448 | } |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3449 | |
| 3450 | // tell the OS that we're live now |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3451 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3452 | ActivityManager.getService().backupAgentCreated(packageName, binder); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3453 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3454 | throw e.rethrowFromSystemServer(); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3455 | } |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3456 | } catch (Exception e) { |
| 3457 | throw new RuntimeException("Unable to create BackupAgent " |
Christopher Tate | 4a627c7 | 2011-04-01 14:43:32 -0700 | [diff] [blame] | 3458 | + classname + ": " + e.toString(), e); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3459 | } |
| 3460 | } |
| 3461 | |
| 3462 | // Tear down a BackupAgent |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3463 | private void handleDestroyBackupAgent(CreateBackupAgentData data) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3464 | if (DEBUG_BACKUP) Slog.v(TAG, "handleDestroyBackupAgent: " + data); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3465 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3466 | LoadedApk packageInfo = getPackageInfoNoCheck(data.appInfo, data.compatInfo); |
| 3467 | String packageName = packageInfo.mPackageName; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3468 | BackupAgent agent = mBackupAgents.get(packageName); |
| 3469 | if (agent != null) { |
| 3470 | try { |
| 3471 | agent.onDestroy(); |
| 3472 | } catch (Exception e) { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 3473 | 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] | 3474 | e.printStackTrace(); |
| 3475 | } |
| 3476 | mBackupAgents.remove(packageName); |
| 3477 | } else { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 3478 | Slog.w(TAG, "Attempt to destroy unknown backup agent " + data); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3479 | } |
| 3480 | } |
| 3481 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3482 | private void handleCreateService(CreateServiceData data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3483 | // If we are getting ready to gc after going to the background, well |
| 3484 | // we are back active so skip it. |
| 3485 | unscheduleGcIdler(); |
| 3486 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3487 | LoadedApk packageInfo = getPackageInfoNoCheck( |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 3488 | data.info.applicationInfo, data.compatInfo); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3489 | Service service = null; |
| 3490 | try { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3491 | java.lang.ClassLoader cl = packageInfo.getClassLoader(); |
| 3492 | service = packageInfo.getAppFactory() |
Jason Monk | a80bfb5 | 2017-11-16 17:15:37 -0500 | [diff] [blame] | 3493 | .instantiateService(cl, data.info.name, data.intent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3494 | } catch (Exception e) { |
| 3495 | if (!mInstrumentation.onException(service, e)) { |
| 3496 | throw new RuntimeException( |
| 3497 | "Unable to instantiate service " + data.info.name |
| 3498 | + ": " + e.toString(), e); |
| 3499 | } |
| 3500 | } |
| 3501 | |
| 3502 | try { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3503 | 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] | 3504 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3505 | ContextImpl context = ContextImpl.createAppContext(this, packageInfo); |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 3506 | context.setOuterContext(service); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3507 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 3508 | Application app = packageInfo.makeApplication(false, mInstrumentation); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3509 | service.attach(context, this, data.info.name, data.token, app, |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3510 | ActivityManager.getService()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3511 | service.onCreate(); |
| 3512 | mServices.put(data.token, service); |
| 3513 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3514 | ActivityManager.getService().serviceDoneExecuting( |
Dianne Hackborn | 455625e | 2015-01-21 09:55:13 -0800 | [diff] [blame] | 3515 | data.token, SERVICE_DONE_EXECUTING_ANON, 0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3516 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3517 | throw e.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3518 | } |
| 3519 | } catch (Exception e) { |
| 3520 | if (!mInstrumentation.onException(service, e)) { |
| 3521 | throw new RuntimeException( |
| 3522 | "Unable to create service " + data.info.name |
| 3523 | + ": " + e.toString(), e); |
| 3524 | } |
| 3525 | } |
| 3526 | } |
| 3527 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3528 | private void handleBindService(BindServiceData data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3529 | Service s = mServices.get(data.token); |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 3530 | if (DEBUG_SERVICE) |
| 3531 | Slog.v(TAG, "handleBindService s=" + s + " rebind=" + data.rebind); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3532 | if (s != null) { |
| 3533 | try { |
| 3534 | data.intent.setExtrasClassLoader(s.getClassLoader()); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 3535 | data.intent.prepareToEnterProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3536 | try { |
| 3537 | if (!data.rebind) { |
| 3538 | IBinder binder = s.onBind(data.intent); |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3539 | ActivityManager.getService().publishService( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3540 | data.token, data.intent, binder); |
| 3541 | } else { |
| 3542 | s.onRebind(data.intent); |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3543 | ActivityManager.getService().serviceDoneExecuting( |
Dianne Hackborn | 455625e | 2015-01-21 09:55:13 -0800 | [diff] [blame] | 3544 | data.token, SERVICE_DONE_EXECUTING_ANON, 0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3545 | } |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 3546 | ensureJitEnabled(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3547 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3548 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3549 | } |
| 3550 | } catch (Exception e) { |
| 3551 | if (!mInstrumentation.onException(s, e)) { |
| 3552 | throw new RuntimeException( |
| 3553 | "Unable to bind to service " + s |
| 3554 | + " with " + data.intent + ": " + e.toString(), e); |
| 3555 | } |
| 3556 | } |
| 3557 | } |
| 3558 | } |
| 3559 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3560 | private void handleUnbindService(BindServiceData data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3561 | Service s = mServices.get(data.token); |
| 3562 | if (s != null) { |
| 3563 | try { |
| 3564 | data.intent.setExtrasClassLoader(s.getClassLoader()); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 3565 | data.intent.prepareToEnterProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3566 | boolean doRebind = s.onUnbind(data.intent); |
| 3567 | try { |
| 3568 | if (doRebind) { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3569 | ActivityManager.getService().unbindFinished( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3570 | data.token, data.intent, doRebind); |
| 3571 | } else { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3572 | ActivityManager.getService().serviceDoneExecuting( |
Dianne Hackborn | 455625e | 2015-01-21 09:55:13 -0800 | [diff] [blame] | 3573 | data.token, SERVICE_DONE_EXECUTING_ANON, 0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3574 | } |
| 3575 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3576 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3577 | } |
| 3578 | } catch (Exception e) { |
| 3579 | if (!mInstrumentation.onException(s, e)) { |
| 3580 | throw new RuntimeException( |
| 3581 | "Unable to unbind to service " + s |
| 3582 | + " with " + data.intent + ": " + e.toString(), e); |
| 3583 | } |
| 3584 | } |
| 3585 | } |
| 3586 | } |
| 3587 | |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 3588 | private void handleDumpService(DumpComponentInfo info) { |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3589 | final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); |
| 3590 | try { |
| 3591 | Service s = mServices.get(info.token); |
| 3592 | if (s != null) { |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 3593 | PrintWriter pw = new FastPrintWriter(new FileOutputStream( |
| 3594 | info.fd.getFileDescriptor())); |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3595 | s.dump(info.fd.getFileDescriptor(), pw, info.args); |
| 3596 | pw.flush(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3597 | } |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3598 | } finally { |
| 3599 | IoUtils.closeQuietly(info.fd); |
| 3600 | StrictMode.setThreadPolicy(oldPolicy); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3601 | } |
| 3602 | } |
| 3603 | |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 3604 | private void handleDumpActivity(DumpComponentInfo info) { |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3605 | final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); |
| 3606 | try { |
| 3607 | ActivityClientRecord r = mActivities.get(info.token); |
| 3608 | if (r != null && r.activity != null) { |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 3609 | PrintWriter pw = new FastPrintWriter(new FileOutputStream( |
| 3610 | info.fd.getFileDescriptor())); |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3611 | r.activity.dump(info.prefix, info.fd.getFileDescriptor(), pw, info.args); |
| 3612 | pw.flush(); |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 3613 | } |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3614 | } finally { |
| 3615 | IoUtils.closeQuietly(info.fd); |
| 3616 | StrictMode.setThreadPolicy(oldPolicy); |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 3617 | } |
| 3618 | } |
| 3619 | |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 3620 | private void handleDumpProvider(DumpComponentInfo info) { |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3621 | final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); |
| 3622 | try { |
| 3623 | ProviderClientRecord r = mLocalProviders.get(info.token); |
| 3624 | if (r != null && r.mLocalProvider != null) { |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 3625 | PrintWriter pw = new FastPrintWriter(new FileOutputStream( |
| 3626 | info.fd.getFileDescriptor())); |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3627 | r.mLocalProvider.dump(info.fd.getFileDescriptor(), pw, info.args); |
| 3628 | pw.flush(); |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 3629 | } |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3630 | } finally { |
| 3631 | IoUtils.closeQuietly(info.fd); |
| 3632 | StrictMode.setThreadPolicy(oldPolicy); |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 3633 | } |
| 3634 | } |
| 3635 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3636 | private void handleServiceArgs(ServiceArgsData data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3637 | Service s = mServices.get(data.token); |
| 3638 | if (s != null) { |
| 3639 | try { |
| 3640 | if (data.args != null) { |
| 3641 | data.args.setExtrasClassLoader(s.getClassLoader()); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 3642 | data.args.prepareToEnterProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3643 | } |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 3644 | int res; |
| 3645 | if (!data.taskRemoved) { |
| 3646 | res = s.onStartCommand(data.args, data.flags, data.startId); |
| 3647 | } else { |
| 3648 | s.onTaskRemoved(data.args); |
| 3649 | res = Service.START_TASK_REMOVED_COMPLETE; |
| 3650 | } |
Brad Fitzpatrick | 333b8cb | 2010-08-26 12:04:57 -0700 | [diff] [blame] | 3651 | |
| 3652 | QueuedWork.waitToFinish(); |
| 3653 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3654 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3655 | ActivityManager.getService().serviceDoneExecuting( |
Dianne Hackborn | 455625e | 2015-01-21 09:55:13 -0800 | [diff] [blame] | 3656 | data.token, SERVICE_DONE_EXECUTING_START, data.startId, res); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3657 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3658 | throw e.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3659 | } |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 3660 | ensureJitEnabled(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3661 | } catch (Exception e) { |
| 3662 | if (!mInstrumentation.onException(s, e)) { |
| 3663 | throw new RuntimeException( |
| 3664 | "Unable to start service " + s |
| 3665 | + " with " + data.args + ": " + e.toString(), e); |
| 3666 | } |
| 3667 | } |
| 3668 | } |
| 3669 | } |
| 3670 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3671 | private void handleStopService(IBinder token) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3672 | Service s = mServices.remove(token); |
| 3673 | if (s != null) { |
| 3674 | try { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3675 | if (localLOGV) Slog.v(TAG, "Destroying service " + s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3676 | s.onDestroy(); |
Amith Yamasani | 7592825 | 2017-05-22 15:10:47 -0700 | [diff] [blame] | 3677 | s.detachAndCleanUp(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3678 | Context context = s.getBaseContext(); |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 3679 | if (context instanceof ContextImpl) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3680 | final String who = s.getClassName(); |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 3681 | ((ContextImpl) context).scheduleFinalCleanup(who, "Service"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3682 | } |
Brad Fitzpatrick | 333b8cb | 2010-08-26 12:04:57 -0700 | [diff] [blame] | 3683 | |
| 3684 | QueuedWork.waitToFinish(); |
| 3685 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3686 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3687 | ActivityManager.getService().serviceDoneExecuting( |
Dianne Hackborn | 455625e | 2015-01-21 09:55:13 -0800 | [diff] [blame] | 3688 | token, SERVICE_DONE_EXECUTING_STOP, 0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3689 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3690 | throw e.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3691 | } |
| 3692 | } catch (Exception e) { |
| 3693 | if (!mInstrumentation.onException(s, e)) { |
| 3694 | throw new RuntimeException( |
| 3695 | "Unable to stop service " + s |
| 3696 | + ": " + e.toString(), e); |
| 3697 | } |
Craig Mautner | 66c4a82 | 2015-01-16 12:48:16 -0800 | [diff] [blame] | 3698 | Slog.i(TAG, "handleStopService: exception for " + token, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3699 | } |
Craig Mautner | 9776ad4 | 2015-01-15 14:38:39 -0800 | [diff] [blame] | 3700 | } else { |
| 3701 | Slog.i(TAG, "handleStopService: token=" + token + " not found."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3702 | } |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3703 | //Slog.i(TAG, "Running services: " + mServices); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3704 | } |
| 3705 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 3706 | ActivityClientRecord performResumeActivity(IBinder token, boolean clearHide, String reason) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3707 | ActivityClientRecord r = mActivities.get(token); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3708 | if (localLOGV) Slog.v(TAG, "Performing resume of " + r |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3709 | + " finished=" + r.activity.mFinished); |
| 3710 | if (r != null && !r.activity.mFinished) { |
| 3711 | if (clearHide) { |
| 3712 | r.hideForNow = false; |
| 3713 | r.activity.mStartedActivity = false; |
| 3714 | } |
| 3715 | try { |
Dianne Hackborn | 6bdd3a1 | 2015-08-05 15:01:28 -0700 | [diff] [blame] | 3716 | r.activity.onStateNotSaved(); |
Dianne Hackborn | 689586d | 2012-10-01 18:23:04 -0700 | [diff] [blame] | 3717 | r.activity.mFragments.noteStateNotSaved(); |
Sudheer Shanka | 43b5ea4 | 2017-06-21 11:24:53 -0700 | [diff] [blame] | 3718 | checkAndBlockForNetworkAccess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3719 | if (r.pendingIntents != null) { |
| 3720 | deliverNewIntents(r, r.pendingIntents); |
| 3721 | r.pendingIntents = null; |
| 3722 | } |
| 3723 | if (r.pendingResults != null) { |
| 3724 | deliverResults(r, r.pendingResults); |
| 3725 | r.pendingResults = null; |
| 3726 | } |
Dake Gu | 67decfa | 2017-12-27 11:48:08 -0800 | [diff] [blame] | 3727 | r.activity.performResume(r.startsNotResumed); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3728 | |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 3729 | synchronized (mResourcesManager) { |
| 3730 | // If there is a pending local relaunch that was requested when the activity was |
| 3731 | // paused, it will put the activity into paused state when it finally happens. |
| 3732 | // Since the activity resumed before being relaunched, we don't want that to |
| 3733 | // happen, so we need to clear the request to relaunch paused. |
| 3734 | for (int i = mRelaunchingActivities.size() - 1; i >= 0; i--) { |
| 3735 | final ActivityClientRecord relaunching = mRelaunchingActivities.get(i); |
| 3736 | if (relaunching.token == r.token |
| 3737 | && relaunching.onlyLocalRequest && relaunching.startsNotResumed) { |
| 3738 | relaunching.startsNotResumed = false; |
| 3739 | } |
Filip Gruszczynski | c3b6179 | 2016-01-22 16:43:48 -0800 | [diff] [blame] | 3740 | } |
| 3741 | } |
| 3742 | |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 3743 | EventLog.writeEvent(LOG_AM_ON_RESUME_CALLED, UserHandle.myUserId(), |
| 3744 | r.activity.getComponentName().getClassName(), reason); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3745 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3746 | r.state = null; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3747 | r.persistentState = null; |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 3748 | r.setState(ON_RESUME); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3749 | } catch (Exception e) { |
| 3750 | if (!mInstrumentation.onException(r.activity, e)) { |
| 3751 | throw new RuntimeException( |
| 3752 | "Unable to resume activity " |
| 3753 | + r.intent.getComponent().toShortString() |
| 3754 | + ": " + e.toString(), e); |
| 3755 | } |
| 3756 | } |
| 3757 | } |
| 3758 | return r; |
| 3759 | } |
| 3760 | |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 3761 | static final void cleanUpPendingRemoveWindows(ActivityClientRecord r, boolean force) { |
| 3762 | if (r.mPreserveWindow && !force) { |
| 3763 | return; |
| 3764 | } |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 3765 | if (r.mPendingRemoveWindow != null) { |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 3766 | r.mPendingRemoveWindowManager.removeViewImmediate( |
| 3767 | r.mPendingRemoveWindow.getDecorView()); |
| 3768 | IBinder wtoken = r.mPendingRemoveWindow.getDecorView().getWindowToken(); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 3769 | if (wtoken != null) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 3770 | WindowManagerGlobal.getInstance().closeAll(wtoken, |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 3771 | r.activity.getClass().getName(), "Activity"); |
| 3772 | } |
| 3773 | } |
| 3774 | r.mPendingRemoveWindow = null; |
| 3775 | r.mPendingRemoveWindowManager = null; |
| 3776 | } |
| 3777 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 3778 | @Override |
| 3779 | public void handleResumeActivity(IBinder token, boolean clearHide, boolean isForward, |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 3780 | String reason) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3781 | // If we are getting ready to gc after going to the background, well |
| 3782 | // we are back active so skip it. |
| 3783 | unscheduleGcIdler(); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3784 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3785 | |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 3786 | // TODO Push resumeArgs into the activity for consideration |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 3787 | final ActivityClientRecord r = performResumeActivity(token, clearHide, reason); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3788 | |
| 3789 | if (r != null) { |
| 3790 | final Activity a = r.activity; |
| 3791 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3792 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3793 | TAG, "Resume " + r + " started activity: " + |
| 3794 | a.mStartedActivity + ", hideForNow: " + r.hideForNow |
| 3795 | + ", finished: " + a.mFinished); |
| 3796 | |
| 3797 | final int forwardBit = isForward ? |
| 3798 | WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION : 0; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3799 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3800 | // If the window hasn't yet been added to the window manager, |
| 3801 | // and this guy didn't finish itself or start another activity, |
| 3802 | // then go ahead and add the window. |
Dianne Hackborn | 061d58a | 2010-03-12 15:07:06 -0800 | [diff] [blame] | 3803 | boolean willBeVisible = !a.mStartedActivity; |
| 3804 | if (!willBeVisible) { |
| 3805 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3806 | willBeVisible = ActivityManager.getService().willActivityBeVisible( |
Dianne Hackborn | 061d58a | 2010-03-12 15:07:06 -0800 | [diff] [blame] | 3807 | a.getActivityToken()); |
| 3808 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3809 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 061d58a | 2010-03-12 15:07:06 -0800 | [diff] [blame] | 3810 | } |
| 3811 | } |
| 3812 | if (r.window == null && !a.mFinished && willBeVisible) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3813 | r.window = r.activity.getWindow(); |
| 3814 | View decor = r.window.getDecorView(); |
| 3815 | decor.setVisibility(View.INVISIBLE); |
| 3816 | ViewManager wm = a.getWindowManager(); |
| 3817 | WindowManager.LayoutParams l = r.window.getAttributes(); |
| 3818 | a.mDecor = decor; |
| 3819 | l.type = WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
| 3820 | l.softInputMode |= forwardBit; |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 3821 | if (r.mPreserveWindow) { |
| 3822 | a.mWindowAdded = true; |
| 3823 | r.mPreserveWindow = false; |
Robert Carr | b259485 | 2016-04-25 16:21:13 -0700 | [diff] [blame] | 3824 | // Normally the ViewRoot sets up callbacks with the Activity |
| 3825 | // in addView->ViewRootImpl#setView. If we are instead reusing |
| 3826 | // the decor view we have to notify the view root that the |
| 3827 | // callbacks may have changed. |
| 3828 | ViewRootImpl impl = decor.getViewRootImpl(); |
Robert Carr | 311ecba | 2016-04-27 12:59:45 -0700 | [diff] [blame] | 3829 | if (impl != null) { |
| 3830 | impl.notifyChildRebuilt(); |
| 3831 | } |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 3832 | } |
Bryce Lee | 4b51b32 | 2017-04-07 10:27:19 -0700 | [diff] [blame] | 3833 | if (a.mVisibleFromClient) { |
| 3834 | if (!a.mWindowAdded) { |
| 3835 | a.mWindowAdded = true; |
| 3836 | wm.addView(decor, l); |
| 3837 | } else { |
| 3838 | // The activity will get a callback for this {@link LayoutParams} change |
| 3839 | // earlier. However, at that time the decor will not be set (this is set |
| 3840 | // in this method), so no action will be taken. This call ensures the |
| 3841 | // callback occurs with the decor set. |
| 3842 | a.onWindowAttributesChanged(l); |
| 3843 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3844 | } |
| 3845 | |
| 3846 | // If the window has already been added, but during resume |
| 3847 | // we started another activity, then don't yet make the |
Dianne Hackborn | 061d58a | 2010-03-12 15:07:06 -0800 | [diff] [blame] | 3848 | // window visible. |
| 3849 | } else if (!willBeVisible) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3850 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3851 | TAG, "Launch " + r + " mStartedActivity set"); |
| 3852 | r.hideForNow = true; |
| 3853 | } |
| 3854 | |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 3855 | // Get rid of anything left hanging around. |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 3856 | cleanUpPendingRemoveWindows(r, false /* force */); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 3857 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3858 | // The window is now visible if it has been added, we are not |
| 3859 | // simply finishing, and we are not starting another activity. |
Dianne Hackborn | 061d58a | 2010-03-12 15:07:06 -0800 | [diff] [blame] | 3860 | if (!r.activity.mFinished && willBeVisible |
Dianne Hackborn | c1e605e | 2009-09-25 17:18:15 -0700 | [diff] [blame] | 3861 | && r.activity.mDecor != null && !r.hideForNow) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3862 | if (r.newConfig != null) { |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 3863 | performConfigurationChangedForActivity(r, r.newConfig); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3864 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Resuming activity " |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 3865 | + r.activityInfo.name + " with newConfig " + r.activity.mCurrentConfig); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3866 | r.newConfig = null; |
| 3867 | } |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3868 | if (localLOGV) Slog.v(TAG, "Resuming " + r + " with isForward=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3869 | + isForward); |
| 3870 | WindowManager.LayoutParams l = r.window.getAttributes(); |
| 3871 | if ((l.softInputMode |
| 3872 | & WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) |
| 3873 | != forwardBit) { |
| 3874 | l.softInputMode = (l.softInputMode |
| 3875 | & (~WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION)) |
| 3876 | | forwardBit; |
Dianne Hackborn | c1e605e | 2009-09-25 17:18:15 -0700 | [diff] [blame] | 3877 | if (r.activity.mVisibleFromClient) { |
| 3878 | ViewManager wm = a.getWindowManager(); |
| 3879 | View decor = r.window.getDecorView(); |
| 3880 | wm.updateViewLayout(decor, l); |
| 3881 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3882 | } |
Bryce Lee | 4b51b32 | 2017-04-07 10:27:19 -0700 | [diff] [blame] | 3883 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3884 | r.activity.mVisibleFromServer = true; |
| 3885 | mNumVisibleActivities++; |
| 3886 | if (r.activity.mVisibleFromClient) { |
| 3887 | r.activity.makeVisible(); |
| 3888 | } |
| 3889 | } |
| 3890 | |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 3891 | if (!r.onlyLocalRequest) { |
| 3892 | r.nextIdle = mNewActivities; |
| 3893 | mNewActivities = r; |
| 3894 | if (localLOGV) Slog.v( |
| 3895 | TAG, "Scheduling idle handler for " + r); |
| 3896 | Looper.myQueue().addIdleHandler(new Idler()); |
| 3897 | } |
| 3898 | r.onlyLocalRequest = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3899 | } else { |
| 3900 | // If an exception was thrown when trying to resume, then |
| 3901 | // just end this activity. |
| 3902 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3903 | ActivityManager.getService() |
Wale Ogunwale | ba7881c | 2015-08-01 19:28:29 -0700 | [diff] [blame] | 3904 | .finishActivity(token, Activity.RESULT_CANCELED, null, |
| 3905 | Activity.DONT_FINISH_TASK_WITH_ACTIVITY); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3906 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3907 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3908 | } |
| 3909 | } |
| 3910 | } |
| 3911 | |
| 3912 | private int mThumbnailWidth = -1; |
| 3913 | private int mThumbnailHeight = -1; |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3914 | private Bitmap mAvailThumbnailBitmap = null; |
| 3915 | private Canvas mThumbnailCanvas = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3916 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3917 | private Bitmap createThumbnailBitmap(ActivityClientRecord r) { |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3918 | Bitmap thumbnail = mAvailThumbnailBitmap; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3919 | try { |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3920 | if (thumbnail == null) { |
| 3921 | int w = mThumbnailWidth; |
| 3922 | int h; |
| 3923 | if (w < 0) { |
| 3924 | Resources res = r.activity.getResources(); |
Winson Chung | 6784f1c | 2014-05-22 11:22:41 -0700 | [diff] [blame] | 3925 | int wId = com.android.internal.R.dimen.thumbnail_width; |
| 3926 | int hId = com.android.internal.R.dimen.thumbnail_height; |
Winson Chung | fd08622 | 2014-05-13 15:49:42 -0700 | [diff] [blame] | 3927 | mThumbnailWidth = w = res.getDimensionPixelSize(wId); |
| 3928 | mThumbnailHeight = h = res.getDimensionPixelSize(hId); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3929 | } else { |
| 3930 | h = mThumbnailHeight; |
| 3931 | } |
| 3932 | |
| 3933 | // On platforms where we don't want thumbnails, set dims to (0,0) |
| 3934 | if ((w > 0) && (h > 0)) { |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 3935 | thumbnail = Bitmap.createBitmap(r.activity.getResources().getDisplayMetrics(), |
| 3936 | w, h, THUMBNAIL_FORMAT); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3937 | thumbnail.eraseColor(0); |
| 3938 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3939 | } |
| 3940 | |
Dianne Hackborn | fb3806d | 2010-12-09 13:14:12 -0800 | [diff] [blame] | 3941 | if (thumbnail != null) { |
| 3942 | Canvas cv = mThumbnailCanvas; |
| 3943 | if (cv == null) { |
| 3944 | mThumbnailCanvas = cv = new Canvas(); |
| 3945 | } |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 3946 | |
Dianne Hackborn | fb3806d | 2010-12-09 13:14:12 -0800 | [diff] [blame] | 3947 | cv.setBitmap(thumbnail); |
| 3948 | if (!r.activity.onCreateThumbnail(thumbnail, cv)) { |
| 3949 | mAvailThumbnailBitmap = thumbnail; |
| 3950 | thumbnail = null; |
| 3951 | } |
Dianne Hackborn | 6311d0a | 2011-08-02 16:37:58 -0700 | [diff] [blame] | 3952 | cv.setBitmap(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3953 | } |
Jim Miller | 0b2a6d0 | 2010-07-13 18:01:29 -0700 | [diff] [blame] | 3954 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3955 | } catch (Exception e) { |
| 3956 | if (!mInstrumentation.onException(r.activity, e)) { |
| 3957 | throw new RuntimeException( |
| 3958 | "Unable to create thumbnail of " |
| 3959 | + r.intent.getComponent().toShortString() |
| 3960 | + ": " + e.toString(), e); |
| 3961 | } |
| 3962 | thumbnail = null; |
| 3963 | } |
| 3964 | |
| 3965 | return thumbnail; |
| 3966 | } |
| 3967 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 3968 | @Override |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 3969 | public void handlePauseActivity(IBinder token, boolean finished, boolean userLeaving, |
| 3970 | int configChanges, boolean dontReport, PendingTransactionActions pendingActions) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3971 | ActivityClientRecord r = mActivities.get(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3972 | if (r != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3973 | if (userLeaving) { |
| 3974 | performUserLeavingActivity(r); |
| 3975 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3976 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3977 | r.activity.mConfigChangeFlags |= configChanges; |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 3978 | performPauseActivity(r, finished, "handlePauseActivity", pendingActions); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3979 | |
Dianne Hackborn | aa93bcd | 2010-10-27 13:57:00 -0700 | [diff] [blame] | 3980 | // Make sure any pending writes are now committed. |
Dianne Hackborn | 5d9d03a | 2011-01-24 13:15:09 -0800 | [diff] [blame] | 3981 | if (r.isPreHoneycomb()) { |
| 3982 | QueuedWork.waitToFinish(); |
| 3983 | } |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 3984 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3985 | // Tell the activity manager we have paused. |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 3986 | if (!dontReport) { |
| 3987 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3988 | ActivityManager.getService().activityPaused(token); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 3989 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3990 | throw ex.rethrowFromSystemServer(); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 3991 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3992 | } |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3993 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3994 | } |
| 3995 | } |
| 3996 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3997 | final void performUserLeavingActivity(ActivityClientRecord r) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3998 | mInstrumentation.callActivityOnUserLeaving(r.activity); |
| 3999 | } |
| 4000 | |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 4001 | final Bundle performPauseActivity(IBinder token, boolean finished, String reason, |
| 4002 | PendingTransactionActions pendingActions) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4003 | ActivityClientRecord r = mActivities.get(token); |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 4004 | return r != null ? performPauseActivity(r, finished, reason, pendingActions) : null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4005 | } |
| 4006 | |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 4007 | /** |
| 4008 | * Pause the activity. |
| 4009 | * @return Saved instance state for pre-Honeycomb apps if it was saved, {@code null} otherwise. |
| 4010 | */ |
| 4011 | private Bundle performPauseActivity(ActivityClientRecord r, boolean finished, String reason, |
| 4012 | PendingTransactionActions pendingActions) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4013 | if (r.paused) { |
| 4014 | if (r.activity.mFinished) { |
| 4015 | // If we are finishing, we won't call onResume() in certain cases. |
| 4016 | // So here we likewise don't want to call onPause() if the activity |
| 4017 | // isn't resumed. |
| 4018 | return null; |
| 4019 | } |
| 4020 | RuntimeException e = new RuntimeException( |
| 4021 | "Performing pause of activity that is not resumed: " |
| 4022 | + r.intent.getComponent().toShortString()); |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 4023 | Slog.e(TAG, e.getMessage(), e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4024 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4025 | if (finished) { |
| 4026 | r.activity.mFinished = true; |
| 4027 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4028 | |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 4029 | // Pre-Honeycomb apps always save their state before pausing |
| 4030 | final boolean shouldSaveState = !r.activity.mFinished && r.isPreHoneycomb(); |
| 4031 | if (shouldSaveState) { |
| 4032 | callActivityOnSaveInstanceState(r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4033 | } |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 4034 | |
| 4035 | performPauseActivityIfNeeded(r, reason); |
Jeff Hamilton | 52d3203 | 2011-01-08 15:31:26 -0600 | [diff] [blame] | 4036 | |
| 4037 | // Notify any outstanding on paused listeners |
| 4038 | ArrayList<OnActivityPausedListener> listeners; |
| 4039 | synchronized (mOnPauseListeners) { |
| 4040 | listeners = mOnPauseListeners.remove(r.activity); |
| 4041 | } |
| 4042 | int size = (listeners != null ? listeners.size() : 0); |
| 4043 | for (int i = 0; i < size; i++) { |
| 4044 | listeners.get(i).onPaused(r.activity); |
| 4045 | } |
| 4046 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4047 | final Bundle oldState = pendingActions != null ? pendingActions.getOldState() : null; |
| 4048 | if (oldState != null) { |
| 4049 | // We need to keep around the original state, in case we need to be created again. |
| 4050 | // But we only do this for pre-Honeycomb apps, which always save their state when |
| 4051 | // pausing, so we can not have them save their state when restarting from a paused |
| 4052 | // state. For HC and later, we want to (and can) let the state be saved as the |
| 4053 | // normal part of stopping the activity. |
| 4054 | if (r.isPreHoneycomb()) { |
| 4055 | r.state = oldState; |
| 4056 | } |
| 4057 | } |
| 4058 | |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 4059 | return shouldSaveState ? r.state : null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4060 | } |
| 4061 | |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 4062 | private void performPauseActivityIfNeeded(ActivityClientRecord r, String reason) { |
| 4063 | if (r.paused) { |
| 4064 | // You are already paused silly... |
| 4065 | return; |
| 4066 | } |
| 4067 | |
| 4068 | try { |
| 4069 | r.activity.mCalled = false; |
| 4070 | mInstrumentation.callActivityOnPause(r.activity); |
| 4071 | EventLog.writeEvent(LOG_AM_ON_PAUSE_CALLED, UserHandle.myUserId(), |
| 4072 | r.activity.getComponentName().getClassName(), reason); |
| 4073 | if (!r.activity.mCalled) { |
| 4074 | throw new SuperNotCalledException("Activity " + safeToComponentShortString(r.intent) |
| 4075 | + " did not call through to super.onPause()"); |
| 4076 | } |
| 4077 | } catch (SuperNotCalledException e) { |
| 4078 | throw e; |
| 4079 | } catch (Exception e) { |
| 4080 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4081 | throw new RuntimeException("Unable to pause activity " |
| 4082 | + safeToComponentShortString(r.intent) + ": " + e.toString(), e); |
| 4083 | } |
| 4084 | } |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4085 | r.setState(ON_PAUSE); |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 4086 | } |
| 4087 | |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 4088 | final void performStopActivity(IBinder token, boolean saveState, String reason) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4089 | ActivityClientRecord r = mActivities.get(token); |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 4090 | performStopActivityInner(r, null, false, saveState, reason); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4091 | } |
| 4092 | |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 4093 | private static final class ProviderRefCount { |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 4094 | public final ContentProviderHolder holder; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 4095 | public final ProviderClientRecord client; |
| 4096 | public int stableCount; |
| 4097 | public int unstableCount; |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 4098 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 4099 | // When this is set, the stable and unstable ref counts are 0 and |
| 4100 | // we have a pending operation scheduled to remove the ref count |
| 4101 | // from the activity manager. On the activity manager we are still |
| 4102 | // holding an unstable ref, though it is not reflected in the counts |
| 4103 | // here. |
| 4104 | public boolean removePending; |
| 4105 | |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 4106 | ProviderRefCount(ContentProviderHolder inHolder, |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 4107 | ProviderClientRecord inClient, int sCount, int uCount) { |
| 4108 | holder = inHolder; |
| 4109 | client = inClient; |
| 4110 | stableCount = sCount; |
| 4111 | unstableCount = uCount; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4112 | } |
| 4113 | } |
| 4114 | |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4115 | /** |
| 4116 | * Core implementation of stopping an activity. Note this is a little |
| 4117 | * tricky because the server's meaning of stop is slightly different |
| 4118 | * than our client -- for the server, stop means to save state and give |
| 4119 | * it the result when it is done, but the window may still be visible. |
| 4120 | * For the client, we want to call onStop()/onStart() to indicate when |
Wale Ogunwale | b5066fe | 2016-09-21 07:33:43 -0700 | [diff] [blame] | 4121 | * the activity's UI visibility changes. |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4122 | */ |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4123 | private void performStopActivityInner(ActivityClientRecord r, StopInfo info, boolean keepShown, |
| 4124 | boolean saveState, String reason) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4125 | if (localLOGV) Slog.v(TAG, "Performing stop of " + r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4126 | if (r != null) { |
| 4127 | if (!keepShown && r.stopped) { |
| 4128 | if (r.activity.mFinished) { |
| 4129 | // If we are finishing, we won't call onResume() in certain |
| 4130 | // cases. So here we likewise don't want to call onStop() |
| 4131 | // if the activity isn't resumed. |
| 4132 | return; |
| 4133 | } |
| 4134 | RuntimeException e = new RuntimeException( |
Andrii Kulian | 58178f2 | 2016-03-16 13:44:56 -0700 | [diff] [blame] | 4135 | "Performing stop of activity that is already stopped: " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4136 | + r.intent.getComponent().toShortString()); |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 4137 | Slog.e(TAG, e.getMessage(), e); |
Andrii Kulian | 58178f2 | 2016-03-16 13:44:56 -0700 | [diff] [blame] | 4138 | Slog.e(TAG, r.getStateString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4139 | } |
| 4140 | |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 4141 | // One must first be paused before stopped... |
| 4142 | performPauseActivityIfNeeded(r, reason); |
| 4143 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4144 | if (info != null) { |
| 4145 | try { |
| 4146 | // First create a thumbnail for the activity... |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4147 | // For now, don't create the thumbnail here; we are |
| 4148 | // doing that by doing a screen snapshot. |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4149 | info.setDescription(r.activity.onCreateDescription()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4150 | } catch (Exception e) { |
| 4151 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4152 | throw new RuntimeException( |
| 4153 | "Unable to save state of activity " |
| 4154 | + r.intent.getComponent().toShortString() |
| 4155 | + ": " + e.toString(), e); |
| 4156 | } |
| 4157 | } |
| 4158 | } |
| 4159 | |
| 4160 | if (!keepShown) { |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 4161 | callActivityOnStop(r, saveState, reason); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4162 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4163 | } |
| 4164 | } |
| 4165 | |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 4166 | /** |
| 4167 | * Calls {@link Activity#onStop()} and {@link Activity#onSaveInstanceState(Bundle)}, and updates |
| 4168 | * the client record's state. |
| 4169 | * All calls to stop an activity must be done through this method to make sure that |
| 4170 | * {@link Activity#onSaveInstanceState(Bundle)} is also executed in the same call. |
| 4171 | */ |
| 4172 | private void callActivityOnStop(ActivityClientRecord r, boolean saveState, String reason) { |
Andrii Kulian | 391161f | 2018-01-29 10:50:02 -0800 | [diff] [blame] | 4173 | // Before P onSaveInstanceState was called before onStop, starting with P it's |
| 4174 | // called after. Before Honeycomb state was always saved before onPause. |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 4175 | final boolean shouldSaveState = saveState && !r.activity.mFinished && r.state == null |
| 4176 | && !r.isPreHoneycomb(); |
Andrii Kulian | 391161f | 2018-01-29 10:50:02 -0800 | [diff] [blame] | 4177 | final boolean isPreP = r.isPreP(); |
| 4178 | if (shouldSaveState && isPreP) { |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 4179 | callActivityOnSaveInstanceState(r); |
| 4180 | } |
| 4181 | |
| 4182 | try { |
| 4183 | r.activity.performStop(false /*preserveWindow*/); |
| 4184 | } catch (SuperNotCalledException e) { |
| 4185 | throw e; |
| 4186 | } catch (Exception e) { |
| 4187 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4188 | throw new RuntimeException( |
| 4189 | "Unable to stop activity " |
| 4190 | + r.intent.getComponent().toShortString() |
| 4191 | + ": " + e.toString(), e); |
| 4192 | } |
| 4193 | } |
| 4194 | r.setState(ON_STOP); |
| 4195 | EventLog.writeEvent(LOG_AM_ON_STOP_CALLED, UserHandle.myUserId(), |
| 4196 | r.activity.getComponentName().getClassName(), reason); |
Andrii Kulian | 391161f | 2018-01-29 10:50:02 -0800 | [diff] [blame] | 4197 | |
| 4198 | if (shouldSaveState && !isPreP) { |
| 4199 | callActivityOnSaveInstanceState(r); |
| 4200 | } |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 4201 | } |
| 4202 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 4203 | private void updateVisibility(ActivityClientRecord r, boolean show) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4204 | View v = r.activity.mDecor; |
| 4205 | if (v != null) { |
| 4206 | if (show) { |
| 4207 | if (!r.activity.mVisibleFromServer) { |
| 4208 | r.activity.mVisibleFromServer = true; |
| 4209 | mNumVisibleActivities++; |
| 4210 | if (r.activity.mVisibleFromClient) { |
| 4211 | r.activity.makeVisible(); |
| 4212 | } |
| 4213 | } |
| 4214 | if (r.newConfig != null) { |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4215 | performConfigurationChangedForActivity(r, r.newConfig); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4216 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Updating activity vis " |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 4217 | + r.activityInfo.name + " with new config " |
| 4218 | + r.activity.mCurrentConfig); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4219 | r.newConfig = null; |
| 4220 | } |
| 4221 | } else { |
| 4222 | if (r.activity.mVisibleFromServer) { |
| 4223 | r.activity.mVisibleFromServer = false; |
| 4224 | mNumVisibleActivities--; |
| 4225 | v.setVisibility(View.INVISIBLE); |
| 4226 | } |
| 4227 | } |
| 4228 | } |
| 4229 | } |
| 4230 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 4231 | @Override |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4232 | public void handleStopActivity(IBinder token, boolean show, int configChanges, |
| 4233 | PendingTransactionActions pendingActions) { |
| 4234 | final ActivityClientRecord r = mActivities.get(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4235 | r.activity.mConfigChangeFlags |= configChanges; |
| 4236 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4237 | final StopInfo stopInfo = new StopInfo(); |
| 4238 | performStopActivityInner(r, stopInfo, show, true, "handleStopActivity"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4239 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4240 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4241 | TAG, "Finishing stop of " + r + ": show=" + show |
| 4242 | + " win=" + r.window); |
| 4243 | |
| 4244 | updateVisibility(r, show); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4245 | |
Dianne Hackborn | 5d9d03a | 2011-01-24 13:15:09 -0800 | [diff] [blame] | 4246 | // Make sure any pending writes are now committed. |
| 4247 | if (!r.isPreHoneycomb()) { |
| 4248 | QueuedWork.waitToFinish(); |
| 4249 | } |
| 4250 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4251 | stopInfo.setActivity(r); |
| 4252 | stopInfo.setState(r.state); |
| 4253 | stopInfo.setPersistentState(r.persistentState); |
| 4254 | pendingActions.setStopInfo(stopInfo); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4255 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4256 | } |
| 4257 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4258 | /** |
| 4259 | * Schedule the call to tell the activity manager we have stopped. We don't do this |
| 4260 | * immediately, because we want to have a chance for any other pending work (in particular |
| 4261 | * memory trim requests) to complete before you tell the activity manager to proceed and allow |
| 4262 | * us to go fully into the background. |
| 4263 | */ |
| 4264 | @Override |
| 4265 | public void reportStop(PendingTransactionActions pendingActions) { |
| 4266 | mH.post(pendingActions.getStopInfo()); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 4267 | } |
| 4268 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4269 | @Override |
| 4270 | public void performRestartActivity(IBinder token, boolean start) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4271 | ActivityClientRecord r = mActivities.get(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4272 | if (r.stopped) { |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4273 | r.activity.performRestart(start); |
| 4274 | if (start) { |
| 4275 | r.setState(ON_START); |
| 4276 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4277 | } |
| 4278 | } |
| 4279 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 4280 | @Override |
| 4281 | public void handleWindowVisibility(IBinder token, boolean show) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4282 | ActivityClientRecord r = mActivities.get(token); |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 4283 | |
Dianne Hackborn | bfddc0f | 2010-12-14 11:28:01 -0800 | [diff] [blame] | 4284 | if (r == null) { |
| 4285 | Log.w(TAG, "handleWindowVisibility: no activity for token " + token); |
| 4286 | return; |
| 4287 | } |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 4288 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4289 | if (!show && !r.stopped) { |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 4290 | performStopActivityInner(r, null, show, false, "handleWindowVisibility"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4291 | } else if (show && r.stopped) { |
| 4292 | // If we are getting ready to gc after going to the background, well |
| 4293 | // we are back active so skip it. |
| 4294 | unscheduleGcIdler(); |
| 4295 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4296 | r.activity.performRestart(true /* start */); |
| 4297 | r.setState(ON_START); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4298 | } |
| 4299 | if (r.activity.mDecor != null) { |
Joe Onorato | 43a1765 | 2011-04-06 19:22:23 -0700 | [diff] [blame] | 4300 | if (false) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4301 | TAG, "Handle window " + r + " visibility: " + show); |
| 4302 | updateVisibility(r, show); |
| 4303 | } |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4304 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4305 | } |
| 4306 | |
Wale Ogunwale | b5066fe | 2016-09-21 07:33:43 -0700 | [diff] [blame] | 4307 | // TODO: This method should be changed to use {@link #performStopActivityInner} to perform to |
| 4308 | // stop operation on the activity to reduce code duplication and the chance of fixing a bug in |
| 4309 | // one place and missing the other. |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 4310 | private void handleSleeping(IBinder token, boolean sleeping) { |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 4311 | ActivityClientRecord r = mActivities.get(token); |
| 4312 | |
| 4313 | if (r == null) { |
Dianne Hackborn | 842e04b | 2011-01-22 13:00:12 -0800 | [diff] [blame] | 4314 | Log.w(TAG, "handleSleeping: no activity for token " + token); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 4315 | return; |
| 4316 | } |
| 4317 | |
| 4318 | if (sleeping) { |
Dianne Hackborn | 842e04b | 2011-01-22 13:00:12 -0800 | [diff] [blame] | 4319 | if (!r.stopped && !r.isPreHoneycomb()) { |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 4320 | callActivityOnStop(r, true /* saveState */, "sleeping"); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 4321 | } |
Dianne Hackborn | 5d9d03a | 2011-01-24 13:15:09 -0800 | [diff] [blame] | 4322 | |
| 4323 | // Make sure any pending writes are now committed. |
| 4324 | if (!r.isPreHoneycomb()) { |
| 4325 | QueuedWork.waitToFinish(); |
| 4326 | } |
| 4327 | |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 4328 | // Tell activity manager we slept. |
| 4329 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 4330 | ActivityManager.getService().activitySlept(r.token); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 4331 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4332 | throw ex.rethrowFromSystemServer(); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 4333 | } |
| 4334 | } else { |
| 4335 | if (r.stopped && r.activity.mVisibleFromServer) { |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4336 | r.activity.performRestart(true /* start */); |
| 4337 | r.setState(ON_START); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 4338 | } |
| 4339 | } |
| 4340 | } |
| 4341 | |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 4342 | private void handleSetCoreSettings(Bundle coreSettings) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4343 | synchronized (mResourcesManager) { |
Svetoslav Ganov | 9aa597e | 2011-03-03 18:17:41 -0800 | [diff] [blame] | 4344 | mCoreSettings = coreSettings; |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 4345 | } |
Jon Miranda | 836c0a8 | 2014-08-11 12:32:26 -0700 | [diff] [blame] | 4346 | onCoreSettingsChange(); |
| 4347 | } |
| 4348 | |
| 4349 | private void onCoreSettingsChange() { |
| 4350 | boolean debugViewAttributes = |
| 4351 | mCoreSettings.getInt(Settings.Global.DEBUG_VIEW_ATTRIBUTES, 0) != 0; |
| 4352 | if (debugViewAttributes != View.mDebugViewAttributes) { |
| 4353 | View.mDebugViewAttributes = debugViewAttributes; |
| 4354 | |
| 4355 | // request all activities to relaunch for the changes to take place |
Fyodor Kupolov | cb93d6f | 2017-05-04 17:27:16 -0700 | [diff] [blame] | 4356 | requestRelaunchAllActivities(); |
| 4357 | } |
| 4358 | } |
| 4359 | |
| 4360 | private void requestRelaunchAllActivities() { |
| 4361 | for (Map.Entry<IBinder, ActivityClientRecord> entry : mActivities.entrySet()) { |
| 4362 | final Activity activity = entry.getValue().activity; |
| 4363 | if (!activity.mFinished) { |
| 4364 | try { |
| 4365 | ActivityManager.getService().requestActivityRelaunch(entry.getKey()); |
| 4366 | } catch (RemoteException e) { |
| 4367 | throw e.rethrowFromSystemServer(); |
| 4368 | } |
Jon Miranda | 836c0a8 | 2014-08-11 12:32:26 -0700 | [diff] [blame] | 4369 | } |
| 4370 | } |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 4371 | } |
| 4372 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4373 | private void handleUpdatePackageCompatibilityInfo(UpdateCompatibilityData data) { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 4374 | LoadedApk apk = peekPackageInfo(data.pkg, false); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4375 | if (apk != null) { |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 4376 | apk.setCompatibilityInfo(data.info); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4377 | } |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 4378 | apk = peekPackageInfo(data.pkg, true); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4379 | if (apk != null) { |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 4380 | apk.setCompatibilityInfo(data.info); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4381 | } |
| 4382 | handleConfigurationChanged(mConfiguration, data.info); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 4383 | WindowManagerGlobal.getInstance().reportNewConfiguration(mConfiguration); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4384 | } |
| 4385 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 4386 | private void deliverResults(ActivityClientRecord r, List<ResultInfo> results) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4387 | final int N = results.size(); |
| 4388 | for (int i=0; i<N; i++) { |
| 4389 | ResultInfo ri = results.get(i); |
| 4390 | try { |
| 4391 | if (ri.mData != null) { |
| 4392 | ri.mData.setExtrasClassLoader(r.activity.getClassLoader()); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 4393 | ri.mData.prepareToEnterProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4394 | } |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4395 | if (DEBUG_RESULTS) Slog.v(TAG, |
Chris Tate | 8a7dc17 | 2009-03-24 20:11:42 -0700 | [diff] [blame] | 4396 | "Delivering result to activity " + r + " : " + ri); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4397 | r.activity.dispatchActivityResult(ri.mResultWho, |
| 4398 | ri.mRequestCode, ri.mResultCode, ri.mData); |
| 4399 | } catch (Exception e) { |
| 4400 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4401 | throw new RuntimeException( |
| 4402 | "Failure delivering result " + ri + " to activity " |
| 4403 | + r.intent.getComponent().toShortString() |
| 4404 | + ": " + e.toString(), e); |
| 4405 | } |
| 4406 | } |
| 4407 | } |
| 4408 | } |
| 4409 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 4410 | @Override |
| 4411 | public void handleSendResult(IBinder token, List<ResultInfo> results) { |
| 4412 | ActivityClientRecord r = mActivities.get(token); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4413 | 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] | 4414 | if (r != null) { |
| 4415 | final boolean resumed = !r.paused; |
| 4416 | if (!r.activity.mFinished && r.activity.mDecor != null |
| 4417 | && r.hideForNow && resumed) { |
| 4418 | // We had hidden the activity because it started another |
| 4419 | // one... we have gotten a result back and we are not |
| 4420 | // paused, so make sure our window is visible. |
| 4421 | updateVisibility(r, true); |
| 4422 | } |
| 4423 | if (resumed) { |
| 4424 | try { |
| 4425 | // Now we are idle. |
| 4426 | r.activity.mCalled = false; |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 4427 | r.activity.mTemporaryPause = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4428 | mInstrumentation.callActivityOnPause(r.activity); |
| 4429 | if (!r.activity.mCalled) { |
| 4430 | throw new SuperNotCalledException( |
| 4431 | "Activity " + r.intent.getComponent().toShortString() |
| 4432 | + " did not call through to super.onPause()"); |
| 4433 | } |
| 4434 | } catch (SuperNotCalledException e) { |
| 4435 | throw e; |
| 4436 | } catch (Exception e) { |
| 4437 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4438 | throw new RuntimeException( |
| 4439 | "Unable to pause activity " |
| 4440 | + r.intent.getComponent().toShortString() |
| 4441 | + ": " + e.toString(), e); |
| 4442 | } |
| 4443 | } |
| 4444 | } |
Sudheer Shanka | 43b5ea4 | 2017-06-21 11:24:53 -0700 | [diff] [blame] | 4445 | checkAndBlockForNetworkAccess(); |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 4446 | deliverResults(r, results); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4447 | if (resumed) { |
Dake Gu | 67decfa | 2017-12-27 11:48:08 -0800 | [diff] [blame] | 4448 | r.activity.performResume(false); |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 4449 | r.activity.mTemporaryPause = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4450 | } |
| 4451 | } |
| 4452 | } |
| 4453 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4454 | /** Core implementation of activity destroy call. */ |
| 4455 | ActivityClientRecord performDestroyActivity(IBinder token, boolean finishing, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4456 | int configChanges, boolean getNonConfigInstance) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4457 | ActivityClientRecord r = mActivities.get(token); |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4458 | Class<? extends Activity> activityClass = null; |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4459 | if (localLOGV) Slog.v(TAG, "Performing finish of " + r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4460 | if (r != null) { |
Brad Fitzpatrick | 5f8b5c1 | 2011-01-20 15:12:08 -0800 | [diff] [blame] | 4461 | activityClass = r.activity.getClass(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4462 | r.activity.mConfigChangeFlags |= configChanges; |
| 4463 | if (finishing) { |
| 4464 | r.activity.mFinished = true; |
| 4465 | } |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 4466 | |
| 4467 | performPauseActivityIfNeeded(r, "destroy"); |
| 4468 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4469 | if (!r.stopped) { |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 4470 | callActivityOnStop(r, false /* saveState */, "destroy"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4471 | } |
| 4472 | if (getNonConfigInstance) { |
| 4473 | try { |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 4474 | r.lastNonConfigurationInstances |
| 4475 | = r.activity.retainNonConfigurationInstances(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4476 | } catch (Exception e) { |
| 4477 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4478 | throw new RuntimeException( |
| 4479 | "Unable to retain activity " |
| 4480 | + r.intent.getComponent().toShortString() |
| 4481 | + ": " + e.toString(), e); |
| 4482 | } |
| 4483 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4484 | } |
| 4485 | try { |
| 4486 | r.activity.mCalled = false; |
Dianne Hackborn | 2dedce6 | 2010-04-15 14:45:25 -0700 | [diff] [blame] | 4487 | mInstrumentation.callActivityOnDestroy(r.activity); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4488 | if (!r.activity.mCalled) { |
| 4489 | throw new SuperNotCalledException( |
Mitsuru Oshima | d9aef73 | 2009-06-16 20:20:50 -0700 | [diff] [blame] | 4490 | "Activity " + safeToComponentShortString(r.intent) + |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4491 | " did not call through to super.onDestroy()"); |
| 4492 | } |
| 4493 | if (r.window != null) { |
| 4494 | r.window.closeAllPanels(); |
| 4495 | } |
| 4496 | } catch (SuperNotCalledException e) { |
| 4497 | throw e; |
| 4498 | } catch (Exception e) { |
| 4499 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4500 | throw new RuntimeException( |
Mitsuru Oshima | d9aef73 | 2009-06-16 20:20:50 -0700 | [diff] [blame] | 4501 | "Unable to destroy activity " + safeToComponentShortString(r.intent) |
| 4502 | + ": " + e.toString(), e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4503 | } |
| 4504 | } |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4505 | r.setState(ON_DESTROY); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4506 | } |
| 4507 | mActivities.remove(token); |
Brad Fitzpatrick | 5f8b5c1 | 2011-01-20 15:12:08 -0800 | [diff] [blame] | 4508 | StrictMode.decrementExpectedActivityCount(activityClass); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4509 | return r; |
| 4510 | } |
| 4511 | |
Mitsuru Oshima | d9aef73 | 2009-06-16 20:20:50 -0700 | [diff] [blame] | 4512 | private static String safeToComponentShortString(Intent intent) { |
| 4513 | ComponentName component = intent.getComponent(); |
| 4514 | return component == null ? "[Unknown]" : component.toShortString(); |
| 4515 | } |
| 4516 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 4517 | @Override |
| 4518 | public void handleDestroyActivity(IBinder token, boolean finishing, int configChanges, |
| 4519 | boolean getNonConfigInstance) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4520 | ActivityClientRecord r = performDestroyActivity(token, finishing, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4521 | configChanges, getNonConfigInstance); |
| 4522 | if (r != null) { |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4523 | cleanUpPendingRemoveWindows(r, finishing); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4524 | WindowManager wm = r.activity.getWindowManager(); |
| 4525 | View v = r.activity.mDecor; |
| 4526 | if (v != null) { |
| 4527 | if (r.activity.mVisibleFromServer) { |
| 4528 | mNumVisibleActivities--; |
| 4529 | } |
| 4530 | IBinder wtoken = v.getWindowToken(); |
| 4531 | if (r.activity.mWindowAdded) { |
Robert Carr | 77bdfb5 | 2016-05-02 18:18:31 -0700 | [diff] [blame] | 4532 | if (r.mPreserveWindow) { |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4533 | // Hold off on removing this until the new activity's |
| 4534 | // window is being added. |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4535 | r.mPendingRemoveWindow = r.window; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4536 | r.mPendingRemoveWindowManager = wm; |
Andrii Kulian | eac0ea5 | 2016-05-11 15:50:24 -0700 | [diff] [blame] | 4537 | // We can only keep the part of the view hierarchy that we control, |
| 4538 | // everything else must be removed, because it might not be able to |
| 4539 | // behave properly when activity is relaunching. |
| 4540 | r.window.clearContentView(); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4541 | } else { |
| 4542 | wm.removeViewImmediate(v); |
| 4543 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4544 | } |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4545 | if (wtoken != null && r.mPendingRemoveWindow == null) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 4546 | WindowManagerGlobal.getInstance().closeAll(wtoken, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4547 | r.activity.getClass().getName(), "Activity"); |
Andrii Kulian | eac0ea5 | 2016-05-11 15:50:24 -0700 | [diff] [blame] | 4548 | } else if (r.mPendingRemoveWindow != null) { |
| 4549 | // We're preserving only one window, others should be closed so app views |
| 4550 | // will be detached before the final tear down. It should be done now because |
| 4551 | // some components (e.g. WebView) rely on detach callbacks to perform receiver |
| 4552 | // unregister and other cleanup. |
| 4553 | WindowManagerGlobal.getInstance().closeAllExceptView(token, v, |
| 4554 | r.activity.getClass().getName(), "Activity"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4555 | } |
| 4556 | r.activity.mDecor = null; |
| 4557 | } |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4558 | if (r.mPendingRemoveWindow == null) { |
| 4559 | // If we are delaying the removal of the activity window, then |
| 4560 | // we can't clean up all windows here. Note that we can't do |
| 4561 | // so later either, which means any windows that aren't closed |
| 4562 | // by the app will leak. Well we try to warning them a lot |
| 4563 | // about leaking windows, because that is a bug, so if they are |
| 4564 | // using this recreate facility then they get to live with leaks. |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 4565 | WindowManagerGlobal.getInstance().closeAll(token, |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4566 | r.activity.getClass().getName(), "Activity"); |
| 4567 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4568 | |
| 4569 | // Mocked out contexts won't be participating in the normal |
| 4570 | // process lifecycle, but if we're running with a proper |
| 4571 | // ApplicationContext we need to have it tear down things |
| 4572 | // cleanly. |
| 4573 | Context c = r.activity.getBaseContext(); |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 4574 | if (c instanceof ContextImpl) { |
| 4575 | ((ContextImpl) c).scheduleFinalCleanup( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4576 | r.activity.getClass().getName(), "Activity"); |
| 4577 | } |
| 4578 | } |
| 4579 | if (finishing) { |
| 4580 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 4581 | ActivityManager.getService().activityDestroyed(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4582 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4583 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4584 | } |
| 4585 | } |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4586 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4587 | } |
| 4588 | |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4589 | /** |
| 4590 | * @param preserveWindow Whether the activity should try to reuse the window it created, |
| 4591 | * including the decor view after the relaunch. |
| 4592 | */ |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4593 | public final void requestRelaunchActivity(IBinder token, |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 4594 | List<ResultInfo> pendingResults, List<ReferrerIntent> pendingNewIntents, |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4595 | int configChanges, boolean notResumed, Configuration config, |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4596 | Configuration overrideConfig, boolean fromServer, boolean preserveWindow) { |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4597 | ActivityClientRecord target = null; |
| 4598 | |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4599 | synchronized (mResourcesManager) { |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4600 | for (int i=0; i<mRelaunchingActivities.size(); i++) { |
| 4601 | ActivityClientRecord r = mRelaunchingActivities.get(i); |
Filip Gruszczynski | c3b6179 | 2016-01-22 16:43:48 -0800 | [diff] [blame] | 4602 | if (DEBUG_ORDER) Slog.d(TAG, "requestRelaunchActivity: " + this + ", trying: " + r); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4603 | if (r.token == token) { |
| 4604 | target = r; |
| 4605 | if (pendingResults != null) { |
| 4606 | if (r.pendingResults != null) { |
| 4607 | r.pendingResults.addAll(pendingResults); |
| 4608 | } else { |
| 4609 | r.pendingResults = pendingResults; |
| 4610 | } |
| 4611 | } |
| 4612 | if (pendingNewIntents != null) { |
| 4613 | if (r.pendingIntents != null) { |
| 4614 | r.pendingIntents.addAll(pendingNewIntents); |
| 4615 | } else { |
| 4616 | r.pendingIntents = pendingNewIntents; |
| 4617 | } |
| 4618 | } |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4619 | |
| 4620 | // For each relaunch request, activity manager expects an answer |
| 4621 | if (!r.onlyLocalRequest && fromServer) { |
| 4622 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 4623 | ActivityManager.getService().activityRelaunched(token); |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4624 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4625 | throw e.rethrowFromSystemServer(); |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4626 | } |
| 4627 | } |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4628 | break; |
| 4629 | } |
| 4630 | } |
| 4631 | |
| 4632 | if (target == null) { |
Filip Gruszczynski | c3b6179 | 2016-01-22 16:43:48 -0800 | [diff] [blame] | 4633 | if (DEBUG_ORDER) Slog.d(TAG, "requestRelaunchActivity: target is null, fromServer:" |
| 4634 | + fromServer); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4635 | target = new ActivityClientRecord(); |
| 4636 | target.token = token; |
| 4637 | target.pendingResults = pendingResults; |
| 4638 | target.pendingIntents = pendingNewIntents; |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4639 | target.mPreserveWindow = preserveWindow; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4640 | if (!fromServer) { |
Filip Gruszczynski | c3b6179 | 2016-01-22 16:43:48 -0800 | [diff] [blame] | 4641 | final ActivityClientRecord existing = mActivities.get(token); |
| 4642 | if (DEBUG_ORDER) Slog.d(TAG, "requestRelaunchActivity: " + existing); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4643 | if (existing != null) { |
Filip Gruszczynski | c3b6179 | 2016-01-22 16:43:48 -0800 | [diff] [blame] | 4644 | if (DEBUG_ORDER) Slog.d(TAG, "requestRelaunchActivity: paused= " |
| 4645 | + existing.paused);; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4646 | target.startsNotResumed = existing.paused; |
Wale Ogunwale | 93f543c | 2015-02-17 16:55:03 -0800 | [diff] [blame] | 4647 | target.overrideConfig = existing.overrideConfig; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4648 | } |
| 4649 | target.onlyLocalRequest = true; |
| 4650 | } |
| 4651 | mRelaunchingActivities.add(target); |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 4652 | sendMessage(H.RELAUNCH_ACTIVITY, target); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4653 | } |
| 4654 | |
| 4655 | if (fromServer) { |
| 4656 | target.startsNotResumed = notResumed; |
| 4657 | target.onlyLocalRequest = false; |
| 4658 | } |
| 4659 | if (config != null) { |
| 4660 | target.createdConfig = config; |
| 4661 | } |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 4662 | if (overrideConfig != null) { |
| 4663 | target.overrideConfig = overrideConfig; |
| 4664 | } |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4665 | target.pendingConfigChanges |= configChanges; |
| 4666 | } |
| 4667 | } |
| 4668 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 4669 | private void handleRelaunchActivity(ActivityClientRecord tmp) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4670 | // If we are getting ready to gc after going to the background, well |
| 4671 | // we are back active so skip it. |
| 4672 | unscheduleGcIdler(); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4673 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4674 | |
| 4675 | Configuration changedConfig = null; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4676 | int configChanges = 0; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4677 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4678 | // First: make sure we have the most recent configuration and most |
| 4679 | // recent version of the activity, or skip it if some previous call |
| 4680 | // had taken a more recent version. |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4681 | synchronized (mResourcesManager) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4682 | int N = mRelaunchingActivities.size(); |
| 4683 | IBinder token = tmp.token; |
| 4684 | tmp = null; |
| 4685 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4686 | ActivityClientRecord r = mRelaunchingActivities.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4687 | if (r.token == token) { |
| 4688 | tmp = r; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4689 | configChanges |= tmp.pendingConfigChanges; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4690 | mRelaunchingActivities.remove(i); |
| 4691 | i--; |
| 4692 | N--; |
| 4693 | } |
| 4694 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4695 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4696 | if (tmp == null) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4697 | 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] | 4698 | return; |
| 4699 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4700 | |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4701 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Relaunching activity " |
| 4702 | + tmp.token + " with configChanges=0x" |
| 4703 | + Integer.toHexString(configChanges)); |
| 4704 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4705 | if (mPendingConfiguration != null) { |
| 4706 | changedConfig = mPendingConfiguration; |
| 4707 | mPendingConfiguration = null; |
| 4708 | } |
| 4709 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4710 | |
Dianne Hackborn | 871ecdc | 2009-12-11 15:24:33 -0800 | [diff] [blame] | 4711 | if (tmp.createdConfig != null) { |
| 4712 | // If the activity manager is passing us its current config, |
| 4713 | // assume that is really what we want regardless of what we |
| 4714 | // may have pending. |
| 4715 | if (mConfiguration == null |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4716 | || (tmp.createdConfig.isOtherSeqNewer(mConfiguration) |
| 4717 | && mConfiguration.diff(tmp.createdConfig) != 0)) { |
| 4718 | if (changedConfig == null |
| 4719 | || tmp.createdConfig.isOtherSeqNewer(changedConfig)) { |
| 4720 | changedConfig = tmp.createdConfig; |
| 4721 | } |
Dianne Hackborn | 871ecdc | 2009-12-11 15:24:33 -0800 | [diff] [blame] | 4722 | } |
| 4723 | } |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 4724 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4725 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Relaunching activity " |
Dianne Hackborn | dc6b635 | 2009-09-30 14:20:09 -0700 | [diff] [blame] | 4726 | + tmp.token + ": changedConfig=" + changedConfig); |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 4727 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4728 | // If there was a pending configuration change, execute it first. |
| 4729 | if (changedConfig != null) { |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 4730 | mCurDefaultDisplayDpi = changedConfig.densityDpi; |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 4731 | updateDefaultDensity(); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4732 | handleConfigurationChanged(changedConfig, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4733 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4734 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4735 | ActivityClientRecord r = mActivities.get(tmp.token); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4736 | 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] | 4737 | if (r == null) { |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4738 | if (!tmp.onlyLocalRequest) { |
| 4739 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 4740 | ActivityManager.getService().activityRelaunched(tmp.token); |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4741 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4742 | throw e.rethrowFromSystemServer(); |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4743 | } |
| 4744 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4745 | return; |
| 4746 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4747 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4748 | r.activity.mConfigChangeFlags |= configChanges; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4749 | r.onlyLocalRequest = tmp.onlyLocalRequest; |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4750 | r.mPreserveWindow = tmp.mPreserveWindow; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4751 | |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4752 | r.activity.mChangingConfigurations = true; |
| 4753 | |
Robert Carr | 23fa16b | 2016-01-13 13:19:58 -0800 | [diff] [blame] | 4754 | // If we are preserving the main window across relaunches we would also like to preserve |
| 4755 | // the children. However the client side view system does not support preserving |
| 4756 | // the child views so we notify the window manager to expect these windows to |
| 4757 | // be replaced and defer requests to destroy or hide them. This way we can achieve |
| 4758 | // visual continuity. It's important that we do this here prior to pause and destroy |
| 4759 | // as that is when we may hide or remove the child views. |
Robert Carr | 77bdfb5 | 2016-05-02 18:18:31 -0700 | [diff] [blame] | 4760 | // |
| 4761 | // There is another scenario, if we have decided locally to relaunch the app from a |
| 4762 | // call to recreate, then none of the windows will be prepared for replacement or |
| 4763 | // preserved by the server, so we want to notify it that we are preparing to replace |
| 4764 | // everything |
Robert Carr | 23fa16b | 2016-01-13 13:19:58 -0800 | [diff] [blame] | 4765 | try { |
Robert Carr | 77bdfb5 | 2016-05-02 18:18:31 -0700 | [diff] [blame] | 4766 | if (r.mPreserveWindow || r.onlyLocalRequest) { |
| 4767 | WindowManagerGlobal.getWindowSession().prepareToReplaceWindows( |
| 4768 | r.token, !r.onlyLocalRequest); |
Robert Carr | 23fa16b | 2016-01-13 13:19:58 -0800 | [diff] [blame] | 4769 | } |
| 4770 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4771 | throw e.rethrowFromSystemServer(); |
Robert Carr | 23fa16b | 2016-01-13 13:19:58 -0800 | [diff] [blame] | 4772 | } |
| 4773 | |
Dianne Hackborn | e2b0480 | 2010-12-09 09:24:55 -0800 | [diff] [blame] | 4774 | // Need to ensure state is saved. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4775 | if (!r.paused) { |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 4776 | performPauseActivity(r, false, "handleRelaunchActivity", |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4777 | null /* pendingActions */); |
Dianne Hackborn | e2b0480 | 2010-12-09 09:24:55 -0800 | [diff] [blame] | 4778 | } |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 4779 | if (!r.stopped) { |
| 4780 | callActivityOnStop(r, true /* saveState */, "handleRelaunchActivity"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4781 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4782 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4783 | handleDestroyActivity(r.token, false, configChanges, true); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4784 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4785 | r.activity = null; |
| 4786 | r.window = null; |
| 4787 | r.hideForNow = false; |
| 4788 | r.nextIdle = null; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4789 | // Merge any pending results and pending intents; don't just replace them |
| 4790 | if (tmp.pendingResults != null) { |
| 4791 | if (r.pendingResults == null) { |
| 4792 | r.pendingResults = tmp.pendingResults; |
| 4793 | } else { |
| 4794 | r.pendingResults.addAll(tmp.pendingResults); |
| 4795 | } |
| 4796 | } |
| 4797 | if (tmp.pendingIntents != null) { |
| 4798 | if (r.pendingIntents == null) { |
| 4799 | r.pendingIntents = tmp.pendingIntents; |
| 4800 | } else { |
| 4801 | r.pendingIntents.addAll(tmp.pendingIntents); |
| 4802 | } |
| 4803 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4804 | r.startsNotResumed = tmp.startsNotResumed; |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 4805 | r.overrideConfig = tmp.overrideConfig; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4806 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4807 | // TODO(lifecycler): Move relaunch to lifecycler. |
| 4808 | PendingTransactionActions pendingActions = new PendingTransactionActions(); |
| 4809 | handleLaunchActivity(r, pendingActions); |
| 4810 | handleStartActivity(r, pendingActions); |
| 4811 | handleResumeActivity(r.token, false /* clearHide */, r.isForward, "relaunch"); |
| 4812 | if (r.startsNotResumed) { |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 4813 | performPauseActivity(r, false /* finished */, "relaunch", pendingActions); |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 4814 | } |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4815 | |
| 4816 | if (!tmp.onlyLocalRequest) { |
| 4817 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 4818 | ActivityManager.getService().activityRelaunched(r.token); |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 4819 | if (r.window != null) { |
| 4820 | r.window.reportActivityRelaunched(); |
| 4821 | } |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4822 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4823 | throw e.rethrowFromSystemServer(); |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4824 | } |
| 4825 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4826 | } |
| 4827 | |
Andrii Kulian | 8ae7957 | 2018-01-26 15:36:06 -0800 | [diff] [blame] | 4828 | private void callActivityOnSaveInstanceState(ActivityClientRecord r) { |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 4829 | r.state = new Bundle(); |
| 4830 | r.state.setAllowFds(false); |
| 4831 | if (r.isPersistable()) { |
| 4832 | r.persistentState = new PersistableBundle(); |
| 4833 | mInstrumentation.callActivityOnSaveInstanceState(r.activity, r.state, |
| 4834 | r.persistentState); |
| 4835 | } else { |
| 4836 | mInstrumentation.callActivityOnSaveInstanceState(r.activity, r.state); |
| 4837 | } |
| 4838 | } |
| 4839 | |
Dianne Hackborn | 73c1416 | 2012-09-19 15:45:06 -0700 | [diff] [blame] | 4840 | ArrayList<ComponentCallbacks2> collectComponentCallbacks( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4841 | boolean allActivities, Configuration newConfig) { |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 4842 | ArrayList<ComponentCallbacks2> callbacks |
| 4843 | = new ArrayList<ComponentCallbacks2>(); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4844 | |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4845 | synchronized (mResourcesManager) { |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 4846 | final int NAPP = mAllApplications.size(); |
| 4847 | for (int i=0; i<NAPP; i++) { |
Dianne Hackborn | 73c1416 | 2012-09-19 15:45:06 -0700 | [diff] [blame] | 4848 | callbacks.add(mAllApplications.get(i)); |
| 4849 | } |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 4850 | final int NACT = mActivities.size(); |
| 4851 | for (int i=0; i<NACT; i++) { |
| 4852 | ActivityClientRecord ar = mActivities.valueAt(i); |
| 4853 | Activity a = ar.activity; |
| 4854 | if (a != null) { |
| 4855 | Configuration thisConfig = applyConfigCompatMainThread( |
| 4856 | mCurDefaultDisplayDpi, newConfig, |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 4857 | ar.packageInfo.getCompatibilityInfo()); |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 4858 | if (!ar.activity.mFinished && (allActivities || !ar.paused)) { |
| 4859 | // If the activity is currently resumed, its configuration |
| 4860 | // needs to change right now. |
| 4861 | callbacks.add(a); |
| 4862 | } else if (thisConfig != null) { |
| 4863 | // Otherwise, we will tell it about the change |
| 4864 | // the next time it is resumed or shown. Note that |
| 4865 | // the activity manager may, before then, decide the |
| 4866 | // activity needs to be destroyed to handle its new |
| 4867 | // configuration. |
| 4868 | if (DEBUG_CONFIGURATION) { |
| 4869 | Slog.v(TAG, "Setting activity " |
| 4870 | + ar.activityInfo.name + " newConfig=" + thisConfig); |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 4871 | } |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 4872 | ar.newConfig = thisConfig; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4873 | } |
| 4874 | } |
| 4875 | } |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 4876 | final int NSVC = mServices.size(); |
| 4877 | for (int i=0; i<NSVC; i++) { |
| 4878 | callbacks.add(mServices.valueAt(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4879 | } |
| 4880 | } |
| 4881 | synchronized (mProviderMap) { |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 4882 | final int NPRV = mLocalProviders.size(); |
| 4883 | for (int i=0; i<NPRV; i++) { |
| 4884 | callbacks.add(mLocalProviders.valueAt(i).mLocalProvider); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4885 | } |
| 4886 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4887 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4888 | return callbacks; |
| 4889 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4890 | |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 4891 | /** |
| 4892 | * Updates the configuration for an Activity. The ActivityClientRecord's |
| 4893 | * {@link ActivityClientRecord#overrideConfig} is used to compute the final Configuration for |
| 4894 | * that Activity. {@link ActivityClientRecord#tmpConfig} is used as a temporary for delivering |
| 4895 | * the updated Configuration. |
| 4896 | * @param r ActivityClientRecord representing the Activity. |
| 4897 | * @param newBaseConfig The new configuration to use. This may be augmented with |
| 4898 | * {@link ActivityClientRecord#overrideConfig}. |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 4899 | */ |
| 4900 | private void performConfigurationChangedForActivity(ActivityClientRecord r, |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4901 | Configuration newBaseConfig) { |
| 4902 | performConfigurationChangedForActivity(r, newBaseConfig, |
| 4903 | r.activity.getDisplay().getDisplayId(), false /* movedToDifferentDisplay */); |
| 4904 | } |
| 4905 | |
| 4906 | /** |
| 4907 | * Updates the configuration for an Activity. The ActivityClientRecord's |
| 4908 | * {@link ActivityClientRecord#overrideConfig} is used to compute the final Configuration for |
| 4909 | * that Activity. {@link ActivityClientRecord#tmpConfig} is used as a temporary for delivering |
| 4910 | * the updated Configuration. |
| 4911 | * @param r ActivityClientRecord representing the Activity. |
| 4912 | * @param newBaseConfig The new configuration to use. This may be augmented with |
| 4913 | * {@link ActivityClientRecord#overrideConfig}. |
| 4914 | * @param displayId The id of the display where the Activity currently resides. |
| 4915 | * @param movedToDifferentDisplay Indicates if the activity was moved to different display. |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 4916 | * @return {@link Configuration} instance sent to client, null if not sent. |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4917 | */ |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 4918 | private Configuration performConfigurationChangedForActivity(ActivityClientRecord r, |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4919 | Configuration newBaseConfig, int displayId, boolean movedToDifferentDisplay) { |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 4920 | r.tmpConfig.setTo(newBaseConfig); |
| 4921 | if (r.overrideConfig != null) { |
| 4922 | r.tmpConfig.updateFrom(r.overrideConfig); |
| 4923 | } |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 4924 | final Configuration reportedConfig = performActivityConfigurationChanged(r.activity, |
| 4925 | r.tmpConfig, r.overrideConfig, displayId, movedToDifferentDisplay); |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 4926 | freeTextLayoutCachesIfNeeded(r.activity.mCurrentConfig.diff(r.tmpConfig)); |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 4927 | return reportedConfig; |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 4928 | } |
| 4929 | |
| 4930 | /** |
Adam Lesinski | c1b0ebf | 2016-06-09 11:17:10 -0700 | [diff] [blame] | 4931 | * Creates a new Configuration only if override would modify base. Otherwise returns base. |
| 4932 | * @param base The base configuration. |
| 4933 | * @param override The update to apply to the base configuration. Can be null. |
| 4934 | * @return A Configuration representing base with override applied. |
| 4935 | */ |
| 4936 | private static Configuration createNewConfigAndUpdateIfNotNull(@NonNull Configuration base, |
| 4937 | @Nullable Configuration override) { |
| 4938 | if (override == null) { |
| 4939 | return base; |
| 4940 | } |
| 4941 | Configuration newConfig = new Configuration(base); |
| 4942 | newConfig.updateFrom(override); |
| 4943 | return newConfig; |
| 4944 | } |
| 4945 | |
| 4946 | /** |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4947 | * 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] | 4948 | * @param cb The component callback to notify of configuration change. |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4949 | * @param newConfig The new configuration. |
| 4950 | */ |
| 4951 | private void performConfigurationChanged(ComponentCallbacks2 cb, Configuration newConfig) { |
| 4952 | if (!REPORT_TO_ACTIVITY) { |
| 4953 | return; |
| 4954 | } |
| 4955 | |
| 4956 | // ContextThemeWrappers may override the configuration for that context. We must check and |
| 4957 | // apply any overrides defined. |
| 4958 | Configuration contextThemeWrapperOverrideConfig = null; |
| 4959 | if (cb instanceof ContextThemeWrapper) { |
| 4960 | final ContextThemeWrapper contextThemeWrapper = (ContextThemeWrapper) cb; |
| 4961 | contextThemeWrapperOverrideConfig = contextThemeWrapper.getOverrideConfiguration(); |
| 4962 | } |
| 4963 | |
| 4964 | // Apply the ContextThemeWrapper override if necessary. |
| 4965 | // NOTE: Make sure the configurations are not modified, as they are treated as immutable |
| 4966 | // in many places. |
| 4967 | final Configuration configToReport = createNewConfigAndUpdateIfNotNull( |
| 4968 | newConfig, contextThemeWrapperOverrideConfig); |
| 4969 | cb.onConfigurationChanged(configToReport); |
| 4970 | } |
| 4971 | |
| 4972 | /** |
| 4973 | * Decides whether to update an Activity's configuration and whether to inform it. |
| 4974 | * @param activity The activity to notify of configuration change. |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 4975 | * @param newConfig The new configuration. |
Adam Lesinski | c1b0ebf | 2016-06-09 11:17:10 -0700 | [diff] [blame] | 4976 | * @param amOverrideConfig The override config that differentiates the Activity's configuration |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4977 | * from the base global configuration. This is supplied by |
| 4978 | * ActivityManager. |
| 4979 | * @param displayId Id of the display where activity currently resides. |
| 4980 | * @param movedToDifferentDisplay Indicates if the activity was moved to different display. |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 4981 | * @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] | 4982 | */ |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 4983 | private Configuration performActivityConfigurationChanged(Activity activity, |
| 4984 | Configuration newConfig, Configuration amOverrideConfig, int displayId, |
| 4985 | boolean movedToDifferentDisplay) { |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4986 | if (activity == null) { |
| 4987 | throw new IllegalArgumentException("No activity provided."); |
| 4988 | } |
| 4989 | final IBinder activityToken = activity.getActivityToken(); |
| 4990 | if (activityToken == null) { |
| 4991 | 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] | 4992 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4993 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4994 | boolean shouldChangeConfig = false; |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4995 | if (activity.mCurrentConfig == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4996 | shouldChangeConfig = true; |
| 4997 | } else { |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4998 | // If the new config is the same as the config this Activity is already running with and |
| 4999 | // the override config also didn't change, then don't bother calling |
| 5000 | // onConfigurationChanged. |
Bryce Lee | 658d984 | 2017-07-28 08:33:36 -0700 | [diff] [blame] | 5001 | final int diff = activity.mCurrentConfig.diffPublicOnly(newConfig); |
| 5002 | |
Andrii Kulian | 3b3c914 | 2016-07-18 19:15:56 -0700 | [diff] [blame] | 5003 | if (diff != 0 || !mResourcesManager.isSameResourcesOverrideConfig(activityToken, |
| 5004 | amOverrideConfig)) { |
Chong Zhang | 4951f9d | 2016-06-23 13:15:08 -0700 | [diff] [blame] | 5005 | // Always send the task-level config changes. For system-level configuration, if |
| 5006 | // this activity doesn't handle any of the config changes, then don't bother |
| 5007 | // calling onConfigurationChanged as we're going to destroy it. |
| 5008 | if (!mUpdatingSystemConfig |
| 5009 | || (~activity.mActivityInfo.getRealConfigChanged() & diff) == 0 |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5010 | || !REPORT_TO_ACTIVITY) { |
Chong Zhang | 4951f9d | 2016-06-23 13:15:08 -0700 | [diff] [blame] | 5011 | shouldChangeConfig = true; |
| 5012 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5013 | } |
| 5014 | } |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5015 | if (!shouldChangeConfig && !movedToDifferentDisplay) { |
| 5016 | // Nothing significant, don't proceed with updating and reporting. |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 5017 | return null; |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5018 | } |
| 5019 | |
| 5020 | // Propagate the configuration change to ResourcesManager and Activity. |
| 5021 | |
| 5022 | // ContextThemeWrappers may override the configuration for that context. We must check and |
| 5023 | // apply any overrides defined. |
| 5024 | Configuration contextThemeWrapperOverrideConfig = activity.getOverrideConfiguration(); |
| 5025 | |
| 5026 | // We only update an Activity's configuration if this is not a global configuration change. |
| 5027 | // This must also be done before the callback, or else we violate the contract that the new |
| 5028 | // resources are available in ComponentCallbacks2#onConfigurationChanged(Configuration). |
| 5029 | // Also apply the ContextThemeWrapper override if necessary. |
| 5030 | // NOTE: Make sure the configurations are not modified, as they are treated as immutable in |
| 5031 | // many places. |
| 5032 | final Configuration finalOverrideConfig = createNewConfigAndUpdateIfNotNull( |
| 5033 | amOverrideConfig, contextThemeWrapperOverrideConfig); |
| 5034 | mResourcesManager.updateResourcesForActivity(activityToken, finalOverrideConfig, |
| 5035 | displayId, movedToDifferentDisplay); |
| 5036 | |
| 5037 | activity.mConfigChangeFlags = 0; |
| 5038 | activity.mCurrentConfig = new Configuration(newConfig); |
| 5039 | |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 5040 | // Apply the ContextThemeWrapper override if necessary. |
| 5041 | // NOTE: Make sure the configurations are not modified, as they are treated as immutable |
| 5042 | // in many places. |
| 5043 | final Configuration configToReport = createNewConfigAndUpdateIfNotNull(newConfig, |
| 5044 | contextThemeWrapperOverrideConfig); |
| 5045 | |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5046 | if (!REPORT_TO_ACTIVITY) { |
| 5047 | // Not configured to report to activity. |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 5048 | return configToReport; |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5049 | } |
| 5050 | |
| 5051 | if (movedToDifferentDisplay) { |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 5052 | activity.dispatchMovedToDisplay(displayId, configToReport); |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5053 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 5054 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5055 | if (shouldChangeConfig) { |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5056 | activity.mCalled = false; |
| 5057 | activity.onConfigurationChanged(configToReport); |
| 5058 | if (!activity.mCalled) { |
| 5059 | throw new SuperNotCalledException("Activity " + activity.getLocalClassName() + |
| 5060 | " did not call through to super.onConfigurationChanged()"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5061 | } |
| 5062 | } |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 5063 | |
| 5064 | return configToReport; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5065 | } |
| 5066 | |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 5067 | public final void applyConfigurationToResources(Configuration config) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 5068 | synchronized (mResourcesManager) { |
| 5069 | mResourcesManager.applyConfigurationToResourcesLocked(config, null); |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 5070 | } |
| 5071 | } |
| 5072 | |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 5073 | final Configuration applyCompatConfiguration(int displayDensity) { |
Dianne Hackborn | 836e262 | 2011-10-04 18:32:39 -0700 | [diff] [blame] | 5074 | Configuration config = mConfiguration; |
| 5075 | if (mCompatConfiguration == null) { |
| 5076 | mCompatConfiguration = new Configuration(); |
| 5077 | } |
| 5078 | mCompatConfiguration.setTo(mConfiguration); |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 5079 | if (mResourcesManager.applyCompatConfigurationLocked(displayDensity, |
| 5080 | mCompatConfiguration)) { |
Dianne Hackborn | 836e262 | 2011-10-04 18:32:39 -0700 | [diff] [blame] | 5081 | config = mCompatConfiguration; |
| 5082 | } |
| 5083 | return config; |
| 5084 | } |
| 5085 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 5086 | @Override |
| 5087 | public void handleConfigurationChanged(Configuration config) { |
| 5088 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "configChanged"); |
| 5089 | mCurDefaultDisplayDpi = config.densityDpi; |
| 5090 | mUpdatingSystemConfig = true; |
| 5091 | try { |
| 5092 | handleConfigurationChanged(config, null /* compat */); |
| 5093 | } finally { |
| 5094 | mUpdatingSystemConfig = false; |
| 5095 | } |
| 5096 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
| 5097 | } |
| 5098 | |
| 5099 | private void handleConfigurationChanged(Configuration config, CompatibilityInfo compat) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5100 | |
Fabrice Di Meglio | 30ca5cd | 2012-05-07 17:45:44 -0700 | [diff] [blame] | 5101 | int configDiff = 0; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5102 | |
Bryce Lee | 658d984 | 2017-07-28 08:33:36 -0700 | [diff] [blame] | 5103 | // This flag tracks whether the new configuration is fundamentally equivalent to the |
| 5104 | // existing configuration. This is necessary to determine whether non-activity |
| 5105 | // callbacks should receive notice when the only changes are related to non-public fields. |
| 5106 | // We do not gate calling {@link #performActivityConfigurationChanged} based on this flag |
| 5107 | // as that method uses the same check on the activity config override as well. |
| 5108 | final boolean equivalent = config != null && mConfiguration != null |
| 5109 | && (0 == mConfiguration.diffPublicOnly(config)); |
Todd Kennedy | 35a9a38 | 2018-01-25 13:25:37 -0800 | [diff] [blame] | 5110 | final Theme systemTheme = getSystemContext().getTheme(); |
| 5111 | final Theme systemUiTheme = getSystemUiContext().getTheme(); |
Bryce Lee | 658d984 | 2017-07-28 08:33:36 -0700 | [diff] [blame] | 5112 | |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 5113 | synchronized (mResourcesManager) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5114 | if (mPendingConfiguration != null) { |
| 5115 | if (!mPendingConfiguration.isOtherSeqNewer(config)) { |
| 5116 | config = mPendingConfiguration; |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 5117 | mCurDefaultDisplayDpi = config.densityDpi; |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 5118 | updateDefaultDensity(); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5119 | } |
| 5120 | mPendingConfiguration = null; |
| 5121 | } |
| 5122 | |
| 5123 | if (config == null) { |
| 5124 | return; |
| 5125 | } |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 5126 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 5127 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Handle configuration changed: " |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5128 | + config); |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 5129 | |
| 5130 | mResourcesManager.applyConfigurationToResourcesLocked(config, compat); |
Adam Lesinski | b61e405 | 2016-05-19 18:23:05 -0700 | [diff] [blame] | 5131 | updateLocaleListFromAppContext(mInitialApplication.getApplicationContext(), |
| 5132 | mResourcesManager.getConfiguration().getLocales()); |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 5133 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5134 | if (mConfiguration == null) { |
| 5135 | mConfiguration = new Configuration(); |
| 5136 | } |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 5137 | if (!mConfiguration.isOtherSeqNewer(config) && compat == null) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5138 | return; |
| 5139 | } |
Alan Viverette | e54d245 | 2015-05-06 10:41:43 -0700 | [diff] [blame] | 5140 | |
| 5141 | configDiff = mConfiguration.updateFrom(config); |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 5142 | config = applyCompatConfiguration(mCurDefaultDisplayDpi); |
Alan Viverette | 395cd01 | 2015-08-11 17:27:04 -0400 | [diff] [blame] | 5143 | |
Alan Viverette | 395cd01 | 2015-08-11 17:27:04 -0400 | [diff] [blame] | 5144 | if ((systemTheme.getChangingConfigurations() & configDiff) != 0) { |
| 5145 | systemTheme.rebase(); |
| 5146 | } |
Adam Lesinski | a82b626 | 2017-03-21 16:56:17 -0700 | [diff] [blame] | 5147 | |
Adam Lesinski | a82b626 | 2017-03-21 16:56:17 -0700 | [diff] [blame] | 5148 | if ((systemUiTheme.getChangingConfigurations() & configDiff) != 0) { |
| 5149 | systemUiTheme.rebase(); |
| 5150 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5151 | } |
Dianne Hackborn | 73c1416 | 2012-09-19 15:45:06 -0700 | [diff] [blame] | 5152 | |
| 5153 | ArrayList<ComponentCallbacks2> callbacks = collectComponentCallbacks(false, config); |
| 5154 | |
Fabrice Di Meglio | 30ca5cd | 2012-05-07 17:45:44 -0700 | [diff] [blame] | 5155 | freeTextLayoutCachesIfNeeded(configDiff); |
| 5156 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5157 | if (callbacks != null) { |
| 5158 | final int N = callbacks.size(); |
| 5159 | for (int i=0; i<N; i++) { |
Andrii Kulian | 701214b | 2016-04-07 09:36:33 -0700 | [diff] [blame] | 5160 | ComponentCallbacks2 cb = callbacks.get(i); |
| 5161 | if (cb instanceof Activity) { |
| 5162 | // If callback is an Activity - call corresponding method to consider override |
| 5163 | // config and avoid onConfigurationChanged if it hasn't changed. |
| 5164 | Activity a = (Activity) cb; |
| 5165 | performConfigurationChangedForActivity(mActivities.get(a.getActivityToken()), |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5166 | config); |
Bryce Lee | 658d984 | 2017-07-28 08:33:36 -0700 | [diff] [blame] | 5167 | } else if (!equivalent) { |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5168 | performConfigurationChanged(cb, config); |
Andrii Kulian | 701214b | 2016-04-07 09:36:33 -0700 | [diff] [blame] | 5169 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5170 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5171 | } |
| 5172 | } |
| 5173 | |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 5174 | void handleApplicationInfoChanged(@NonNull final ApplicationInfo ai) { |
Adam Lesinski | d33ef56 | 2017-01-19 14:49:59 -0800 | [diff] [blame] | 5175 | // Updates triggered by package installation go through a package update |
| 5176 | // receiver. Here we try to capture ApplicationInfo changes that are |
| 5177 | // caused by other sources, such as overlays. That means we want to be as conservative |
| 5178 | // about code changes as possible. Take the diff of the old ApplicationInfo and the new |
| 5179 | // to see if anything needs to change. |
Fyodor Kupolov | b7865ce | 2017-05-05 15:08:03 -0700 | [diff] [blame] | 5180 | LoadedApk apk; |
| 5181 | LoadedApk resApk; |
| 5182 | // Update all affected loaded packages with new package information |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 5183 | synchronized (mResourcesManager) { |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 5184 | WeakReference<LoadedApk> ref = mPackages.get(ai.packageName); |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 5185 | apk = ref != null ? ref.get() : null; |
Fyodor Kupolov | b7865ce | 2017-05-05 15:08:03 -0700 | [diff] [blame] | 5186 | ref = mResourcePackages.get(ai.packageName); |
| 5187 | resApk = ref != null ? ref.get() : null; |
| 5188 | } |
| 5189 | if (apk != null) { |
| 5190 | final ArrayList<String> oldPaths = new ArrayList<>(); |
| 5191 | LoadedApk.makePaths(this, apk.getApplicationInfo(), oldPaths); |
| 5192 | apk.updateApplicationInfo(ai, oldPaths); |
| 5193 | } |
| 5194 | if (resApk != null) { |
| 5195 | final ArrayList<String> oldPaths = new ArrayList<>(); |
| 5196 | LoadedApk.makePaths(this, resApk.getApplicationInfo(), oldPaths); |
| 5197 | resApk.updateApplicationInfo(ai, oldPaths); |
| 5198 | } |
| 5199 | synchronized (mResourcesManager) { |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 5200 | // Update all affected Resources objects to use new ResourcesImpl |
| 5201 | mResourcesManager.applyNewResourceDirsLocked(ai.sourceDir, ai.resourceDirs); |
| 5202 | } |
| 5203 | |
| 5204 | ApplicationPackageManager.configurationChanged(); |
| 5205 | |
| 5206 | // Trigger a regular Configuration change event, only with a different assetsSeq number |
| 5207 | // so that we actually call through to all components. |
Adam Lesinski | a82b626 | 2017-03-21 16:56:17 -0700 | [diff] [blame] | 5208 | // TODO(adamlesinski): Change this to make use of ActivityManager's upcoming ability to |
| 5209 | // store configurations per-process. |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 5210 | Configuration newConfig = new Configuration(); |
Adam Lesinski | a82b626 | 2017-03-21 16:56:17 -0700 | [diff] [blame] | 5211 | newConfig.assetsSeq = (mConfiguration != null ? mConfiguration.assetsSeq : 0) + 1; |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 5212 | handleConfigurationChanged(newConfig, null); |
| 5213 | |
Fyodor Kupolov | cb93d6f | 2017-05-04 17:27:16 -0700 | [diff] [blame] | 5214 | requestRelaunchAllActivities(); |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 5215 | } |
| 5216 | |
Romain Guy | 46bfc48 | 2013-08-16 18:38:29 -0700 | [diff] [blame] | 5217 | static void freeTextLayoutCachesIfNeeded(int configDiff) { |
Fabrice Di Meglio | 30ca5cd | 2012-05-07 17:45:44 -0700 | [diff] [blame] | 5218 | if (configDiff != 0) { |
| 5219 | // Ask text layout engine to free its caches if there is a locale change |
| 5220 | boolean hasLocaleConfigChange = ((configDiff & ActivityInfo.CONFIG_LOCALE) != 0); |
| 5221 | if (hasLocaleConfigChange) { |
| 5222 | Canvas.freeTextLayoutCaches(); |
| 5223 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Cleared TextLayout Caches"); |
| 5224 | } |
| 5225 | } |
| 5226 | } |
| 5227 | |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5228 | /** |
| 5229 | * Handle new activity configuration and/or move to a different display. |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 5230 | * @param activityToken Target activity token. |
| 5231 | * @param overrideConfig Activity override config. |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5232 | * @param displayId Id of the display where activity was moved to, -1 if there was no move and |
| 5233 | * value didn't change. |
| 5234 | */ |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 5235 | @Override |
| 5236 | public void handleActivityConfigurationChanged(IBinder activityToken, |
| 5237 | Configuration overrideConfig, int displayId) { |
| 5238 | ActivityClientRecord r = mActivities.get(activityToken); |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5239 | // Check input params. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5240 | if (r == null || r.activity == null) { |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5241 | 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] | 5242 | return; |
| 5243 | } |
Andrii Kulian | 51c1b67 | 2017-04-07 18:39:32 -0700 | [diff] [blame] | 5244 | final boolean movedToDifferentDisplay = displayId != INVALID_DISPLAY |
| 5245 | && displayId != r.activity.getDisplay().getDisplayId(); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 5246 | |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5247 | // Perform updates. |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 5248 | r.overrideConfig = overrideConfig; |
Stephen Kiazyk | f903b73 | 2017-03-20 16:23:45 -0700 | [diff] [blame] | 5249 | final ViewRootImpl viewRoot = r.activity.mDecor != null |
| 5250 | ? r.activity.mDecor.getViewRootImpl() : null; |
| 5251 | |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5252 | if (movedToDifferentDisplay) { |
| 5253 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Handle activity moved to display, activity:" |
| 5254 | + r.activityInfo.name + ", displayId=" + displayId |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 5255 | + ", config=" + overrideConfig); |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5256 | |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 5257 | final Configuration reportedConfig = performConfigurationChangedForActivity(r, |
| 5258 | mCompatConfiguration, displayId, true /* movedToDifferentDisplay */); |
Andrii Kulian | ce1ecf1 | 2017-03-17 14:58:36 -0700 | [diff] [blame] | 5259 | if (viewRoot != null) { |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 5260 | viewRoot.onMovedToDisplay(displayId, reportedConfig); |
Andrii Kulian | ce1ecf1 | 2017-03-17 14:58:36 -0700 | [diff] [blame] | 5261 | } |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5262 | } else { |
| 5263 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Handle activity config changed: " |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 5264 | + r.activityInfo.name + ", config=" + overrideConfig); |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5265 | performConfigurationChangedForActivity(r, mCompatConfiguration); |
| 5266 | } |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 5267 | // Notify the ViewRootImpl instance about configuration changes. It may have initiated this |
| 5268 | // update to make sure that resources are updated before updating itself. |
Andrii Kulian | ce1ecf1 | 2017-03-17 14:58:36 -0700 | [diff] [blame] | 5269 | if (viewRoot != null) { |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 5270 | viewRoot.updateConfiguration(displayId); |
Andrii Kulian | ce1ecf1 | 2017-03-17 14:58:36 -0700 | [diff] [blame] | 5271 | } |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 5272 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5273 | } |
| 5274 | |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 5275 | final void handleProfilerControl(boolean start, ProfilerInfo profilerInfo, int profileType) { |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 5276 | if (start) { |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 5277 | try { |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 5278 | switch (profileType) { |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 5279 | default: |
| 5280 | mProfiler.setProfiler(profilerInfo); |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 5281 | mProfiler.startProfiling(); |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 5282 | break; |
| 5283 | } |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 5284 | } catch (RuntimeException e) { |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 5285 | Slog.w(TAG, "Profiling failed on path " + profilerInfo.profileFile |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 5286 | + " -- can the process access this path?"); |
Dianne Hackborn | 9c8dd55 | 2009-06-23 19:22:52 -0700 | [diff] [blame] | 5287 | } finally { |
Andreas Gampe | 2b073a0 | 2017-06-22 17:28:57 -0700 | [diff] [blame] | 5288 | profilerInfo.closeFd(); |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 5289 | } |
| 5290 | } else { |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 5291 | switch (profileType) { |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 5292 | default: |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 5293 | mProfiler.stopProfiling(); |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 5294 | break; |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 5295 | } |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 5296 | } |
| 5297 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 5298 | |
Andreas Gampe | 4c79fea | 2016-01-28 20:11:41 -0800 | [diff] [blame] | 5299 | /** |
| 5300 | * Public entrypoint to stop profiling. This is required to end profiling when the app crashes, |
| 5301 | * so that profiler data won't be lost. |
| 5302 | * |
| 5303 | * @hide |
| 5304 | */ |
| 5305 | public void stopProfiling() { |
Amith Yamasani | b168443 | 2017-01-26 14:57:20 -0800 | [diff] [blame] | 5306 | if (mProfiler != null) { |
| 5307 | mProfiler.stopProfiling(); |
| 5308 | } |
Andreas Gampe | 4c79fea | 2016-01-28 20:11:41 -0800 | [diff] [blame] | 5309 | } |
| 5310 | |
Christopher Ferris | 8d652f8 | 2017-04-11 16:29:18 -0700 | [diff] [blame] | 5311 | static void handleDumpHeap(DumpHeapData dhd) { |
Makoto Onuki | 4556b7b | 2017-07-07 14:58:58 -0700 | [diff] [blame] | 5312 | if (dhd.runGc) { |
| 5313 | System.gc(); |
| 5314 | System.runFinalization(); |
| 5315 | System.gc(); |
| 5316 | } |
Christopher Ferris | 8d652f8 | 2017-04-11 16:29:18 -0700 | [diff] [blame] | 5317 | if (dhd.managed) { |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 5318 | try { |
| 5319 | Debug.dumpHprofData(dhd.path, dhd.fd.getFileDescriptor()); |
| 5320 | } catch (IOException e) { |
| 5321 | Slog.w(TAG, "Managed heap dump failed on path " + dhd.path |
| 5322 | + " -- can the process access this path?"); |
| 5323 | } finally { |
| 5324 | try { |
| 5325 | dhd.fd.close(); |
| 5326 | } catch (IOException e) { |
| 5327 | Slog.w(TAG, "Failure closing profile fd", e); |
| 5328 | } |
| 5329 | } |
Christopher Ferris | 8d652f8 | 2017-04-11 16:29:18 -0700 | [diff] [blame] | 5330 | } else if (dhd.mallocInfo) { |
| 5331 | Debug.dumpNativeMallocInfo(dhd.fd.getFileDescriptor()); |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 5332 | } else { |
Andy McFadden | 06a6b55 | 2010-07-13 16:28:09 -0700 | [diff] [blame] | 5333 | Debug.dumpNativeHeap(dhd.fd.getFileDescriptor()); |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 5334 | } |
Dianne Hackborn | b9a5e4a | 2015-03-03 17:04:12 -0800 | [diff] [blame] | 5335 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5336 | ActivityManager.getService().dumpHeapFinished(dhd.path); |
Dianne Hackborn | b9a5e4a | 2015-03-03 17:04:12 -0800 | [diff] [blame] | 5337 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5338 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | b9a5e4a | 2015-03-03 17:04:12 -0800 | [diff] [blame] | 5339 | } |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 5340 | } |
| 5341 | |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 5342 | final void handleDispatchPackageBroadcast(int cmd, String[] packages) { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5343 | boolean hasPkgInfo = false; |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5344 | switch (cmd) { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 5345 | case ApplicationThreadConstants.PACKAGE_REMOVED: |
| 5346 | case ApplicationThreadConstants.PACKAGE_REMOVED_DONT_KILL: |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5347 | { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 5348 | final boolean killApp = cmd == ApplicationThreadConstants.PACKAGE_REMOVED; |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5349 | if (packages == null) { |
| 5350 | break; |
| 5351 | } |
| 5352 | synchronized (mResourcesManager) { |
| 5353 | for (int i = packages.length - 1; i >= 0; i--) { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5354 | if (!hasPkgInfo) { |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5355 | WeakReference<LoadedApk> ref = mPackages.get(packages[i]); |
| 5356 | if (ref != null && ref.get() != null) { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5357 | hasPkgInfo = true; |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5358 | } else { |
| 5359 | ref = mResourcePackages.get(packages[i]); |
| 5360 | if (ref != null && ref.get() != null) { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5361 | hasPkgInfo = true; |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5362 | } |
| 5363 | } |
| 5364 | } |
| 5365 | if (killApp) { |
| 5366 | mPackages.remove(packages[i]); |
| 5367 | mResourcePackages.remove(packages[i]); |
| 5368 | } |
| 5369 | } |
| 5370 | } |
| 5371 | break; |
| 5372 | } |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 5373 | case ApplicationThreadConstants.PACKAGE_REPLACED: |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5374 | { |
| 5375 | if (packages == null) { |
| 5376 | break; |
| 5377 | } |
| 5378 | synchronized (mResourcesManager) { |
| 5379 | for (int i = packages.length - 1; i >= 0; i--) { |
| 5380 | WeakReference<LoadedApk> ref = mPackages.get(packages[i]); |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5381 | LoadedApk pkgInfo = ref != null ? ref.get() : null; |
| 5382 | if (pkgInfo != null) { |
| 5383 | hasPkgInfo = true; |
mark_chen | 89764e3 | 2014-12-12 15:38:48 +0800 | [diff] [blame] | 5384 | } else { |
| 5385 | ref = mResourcePackages.get(packages[i]); |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5386 | pkgInfo = ref != null ? ref.get() : null; |
| 5387 | if (pkgInfo != null) { |
| 5388 | hasPkgInfo = true; |
mark_chen | 89764e3 | 2014-12-12 15:38:48 +0800 | [diff] [blame] | 5389 | } |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 5390 | } |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5391 | // If the package is being replaced, yet it still has a valid |
| 5392 | // LoadedApk object, the package was updated with _DONT_KILL. |
| 5393 | // Adjust it's internal references to the application info and |
| 5394 | // resources. |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5395 | if (pkgInfo != null) { |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5396 | try { |
| 5397 | final String packageName = packages[i]; |
| 5398 | final ApplicationInfo aInfo = |
| 5399 | sPackageManager.getApplicationInfo( |
| 5400 | packageName, |
Svet Ganov | 6ce9239 | 2017-09-27 16:04:10 -0700 | [diff] [blame] | 5401 | PackageManager.GET_SHARED_LIBRARY_FILES, |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5402 | UserHandle.myUserId()); |
| 5403 | |
| 5404 | if (mActivities.size() > 0) { |
| 5405 | for (ActivityClientRecord ar : mActivities.values()) { |
| 5406 | if (ar.activityInfo.applicationInfo.packageName |
| 5407 | .equals(packageName)) { |
| 5408 | ar.activityInfo.applicationInfo = aInfo; |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5409 | ar.packageInfo = pkgInfo; |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5410 | } |
| 5411 | } |
| 5412 | } |
| 5413 | final List<String> oldPaths = |
| 5414 | sPackageManager.getPreviousCodePaths(packageName); |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5415 | pkgInfo.updateApplicationInfo(aInfo, oldPaths); |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5416 | } catch (RemoteException e) { |
| 5417 | } |
| 5418 | } |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 5419 | } |
| 5420 | } |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5421 | break; |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 5422 | } |
| 5423 | } |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5424 | ApplicationPackageManager.handlePackageBroadcast(cmd, packages, hasPkgInfo); |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 5425 | } |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 5426 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5427 | final void handleLowMemory() { |
Dianne Hackborn | 73c1416 | 2012-09-19 15:45:06 -0700 | [diff] [blame] | 5428 | ArrayList<ComponentCallbacks2> callbacks = collectComponentCallbacks(true, null); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 5429 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5430 | final int N = callbacks.size(); |
| 5431 | for (int i=0; i<N; i++) { |
| 5432 | callbacks.get(i).onLowMemory(); |
| 5433 | } |
| 5434 | |
Chris Tate | ce22905 | 2009-03-25 16:44:52 -0700 | [diff] [blame] | 5435 | // Ask SQLite to free up as much memory as it can, mostly from its page caches. |
| 5436 | if (Process.myUid() != Process.SYSTEM_UID) { |
| 5437 | int sqliteReleased = SQLiteDatabase.releaseMemory(); |
| 5438 | EventLog.writeEvent(SQLITE_MEM_RELEASED_EVENT_LOG_TAG, sqliteReleased); |
| 5439 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 5440 | |
Mike Reed | caf0df1 | 2009-04-27 14:32:05 -0400 | [diff] [blame] | 5441 | // Ask graphics to free up as much as possible (font/image caches) |
| 5442 | Canvas.freeCaches(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5443 | |
Fabrice Di Meglio | 30ca5cd | 2012-05-07 17:45:44 -0700 | [diff] [blame] | 5444 | // Ask text layout engine to free also as much as possible |
| 5445 | Canvas.freeTextLayoutCaches(); |
| 5446 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5447 | BinderInternal.forceGc("mem"); |
| 5448 | } |
| 5449 | |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 5450 | final void handleTrimMemory(int level) { |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 5451 | if (DEBUG_MEMORY_TRIM) Slog.v(TAG, "Trimming memory to level: " + level); |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 5452 | |
Dianne Hackborn | 73c1416 | 2012-09-19 15:45:06 -0700 | [diff] [blame] | 5453 | ArrayList<ComponentCallbacks2> callbacks = collectComponentCallbacks(true, null); |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 5454 | |
| 5455 | final int N = callbacks.size(); |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 5456 | for (int i = 0; i < N; i++) { |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 5457 | callbacks.get(i).onTrimMemory(level); |
| 5458 | } |
Romain Guy | 19f86e8 | 2012-04-23 15:19:07 -0700 | [diff] [blame] | 5459 | |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 5460 | WindowManagerGlobal.getInstance().trimMemory(level); |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 5461 | } |
| 5462 | |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 5463 | private void setupGraphicsSupport(Context context) { |
Andreas Gampe | 4c8e542 | 2016-05-18 11:58:47 -0700 | [diff] [blame] | 5464 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "setupGraphicsSupport"); |
Romain Guy | a958265 | 2011-11-10 14:20:10 -0800 | [diff] [blame] | 5465 | |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 5466 | // The system package doesn't have real data directories, so don't set up cache paths. |
| 5467 | if (!"android".equals(context.getPackageName())) { |
| 5468 | // This cache location probably points at credential-encrypted |
| 5469 | // storage which may not be accessible yet; assign it anyway instead |
| 5470 | // of pointing at device-encrypted storage. |
| 5471 | final File cacheDir = context.getCacheDir(); |
| 5472 | if (cacheDir != null) { |
| 5473 | // Provide a usable directory for temporary files |
| 5474 | System.setProperty("java.io.tmpdir", cacheDir.getAbsolutePath()); |
| 5475 | } else { |
| 5476 | Log.v(TAG, "Unable to initialize \"java.io.tmpdir\" property " |
| 5477 | + "due to missing cache directory"); |
Romain Guy | a958265 | 2011-11-10 14:20:10 -0800 | [diff] [blame] | 5478 | } |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 5479 | |
| 5480 | // Setup a location to store generated/compiled graphics code. |
| 5481 | final Context deviceContext = context.createDeviceProtectedStorageContext(); |
| 5482 | final File codeCacheDir = deviceContext.getCodeCacheDir(); |
| 5483 | if (codeCacheDir != null) { |
| 5484 | try { |
| 5485 | int uid = Process.myUid(); |
| 5486 | String[] packages = getPackageManager().getPackagesForUid(uid); |
| 5487 | if (packages != null) { |
Romain Guy | cecbe07 | 2017-07-18 15:42:06 -0700 | [diff] [blame] | 5488 | ThreadedRenderer.setupDiskCache(codeCacheDir); |
| 5489 | RenderScriptCacheDir.setupDiskCache(codeCacheDir); |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 5490 | } |
| 5491 | } catch (RemoteException e) { |
| 5492 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
| 5493 | throw e.rethrowFromSystemServer(); |
| 5494 | } |
| 5495 | } else { |
| 5496 | Log.w(TAG, "Unable to use shader/script cache: missing code-cache directory"); |
| 5497 | } |
Romain Guy | a958265 | 2011-11-10 14:20:10 -0800 | [diff] [blame] | 5498 | } |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 5499 | |
Cody Northrop | 86cedcb | 2017-10-20 09:03:13 -0600 | [diff] [blame] | 5500 | GraphicsEnvironment.getInstance().setup(context); |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 5501 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 5502 | } |
| 5503 | |
| 5504 | private void updateDefaultDensity() { |
Alan Viverette | 2ac46f1 | 2016-02-04 16:58:14 -0500 | [diff] [blame] | 5505 | final int densityDpi = mCurDefaultDisplayDpi; |
| 5506 | if (!mDensityCompatMode |
| 5507 | && densityDpi != Configuration.DENSITY_DPI_UNDEFINED |
| 5508 | && densityDpi != DisplayMetrics.DENSITY_DEVICE) { |
| 5509 | DisplayMetrics.DENSITY_DEVICE = densityDpi; |
| 5510 | Bitmap.setDefaultDensity(densityDpi); |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 5511 | } |
| 5512 | } |
| 5513 | |
Todd Kennedy | e713efc | 2016-05-10 13:45:40 -0700 | [diff] [blame] | 5514 | /** |
| 5515 | * Returns the correct library directory for the current ABI. |
| 5516 | * <p> |
| 5517 | * If we're dealing with a multi-arch application that has both 32 and 64 bit shared |
| 5518 | * libraries, we might need to choose the secondary depending on what the current |
| 5519 | * runtime's instruction set is. |
| 5520 | */ |
| 5521 | private String getInstrumentationLibrary(ApplicationInfo appInfo, InstrumentationInfo insInfo) { |
| 5522 | if (appInfo.primaryCpuAbi != null && appInfo.secondaryCpuAbi != null) { |
| 5523 | // Get the instruction set supported by the secondary ABI. In the presence |
| 5524 | // of a native bridge this might be different than the one secondary ABI used. |
| 5525 | String secondaryIsa = |
| 5526 | VMRuntime.getInstructionSet(appInfo.secondaryCpuAbi); |
| 5527 | final String secondaryDexCodeIsa = |
| 5528 | SystemProperties.get("ro.dalvik.vm.isa." + secondaryIsa); |
| 5529 | secondaryIsa = secondaryDexCodeIsa.isEmpty() ? secondaryIsa : secondaryDexCodeIsa; |
| 5530 | |
| 5531 | final String runtimeIsa = VMRuntime.getRuntime().vmInstructionSet(); |
| 5532 | if (runtimeIsa.equals(secondaryIsa)) { |
| 5533 | return insInfo.secondaryNativeLibraryDir; |
| 5534 | } |
| 5535 | } |
| 5536 | return insInfo.nativeLibraryDir; |
| 5537 | } |
| 5538 | |
Adam Lesinski | b61e405 | 2016-05-19 18:23:05 -0700 | [diff] [blame] | 5539 | /** |
| 5540 | * The LocaleList set for the app's resources may have been shuffled so that the preferred |
| 5541 | * Locale is at position 0. We must find the index of this preferred Locale in the |
| 5542 | * original LocaleList. |
| 5543 | */ |
| 5544 | private void updateLocaleListFromAppContext(Context context, LocaleList newLocaleList) { |
| 5545 | final Locale bestLocale = context.getResources().getConfiguration().getLocales().get(0); |
| 5546 | final int newLocaleListSize = newLocaleList.size(); |
| 5547 | for (int i = 0; i < newLocaleListSize; i++) { |
| 5548 | if (bestLocale.equals(newLocaleList.get(i))) { |
| 5549 | LocaleList.setDefault(newLocaleList, i); |
| 5550 | return; |
| 5551 | } |
| 5552 | } |
Adam Lesinski | 27d3016 | 2016-05-25 16:45:14 -0700 | [diff] [blame] | 5553 | |
| 5554 | // The app may have overridden the LocaleList with its own Locale |
| 5555 | // (not present in the available list). Push the chosen Locale |
| 5556 | // to the front of the list. |
| 5557 | LocaleList.setDefault(new LocaleList(bestLocale, newLocaleList)); |
Adam Lesinski | b61e405 | 2016-05-19 18:23:05 -0700 | [diff] [blame] | 5558 | } |
| 5559 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 5560 | private void handleBindApplication(AppBindData data) { |
Calin Juravle | 8f5770d | 2016-04-12 14:12:04 +0100 | [diff] [blame] | 5561 | // Register the UI Thread as a sensitive thread to the runtime. |
| 5562 | VMRuntime.registerSensitiveThread(); |
Man Cao | cfa78b2 | 2015-06-11 20:14:34 -0700 | [diff] [blame] | 5563 | if (data.trackAllocation) { |
| 5564 | DdmVmInternal.enableRecentAllocations(true); |
| 5565 | } |
| 5566 | |
Dianne Hackborn | d98885c | 2016-03-01 17:13:03 -0800 | [diff] [blame] | 5567 | // Note when this process has started. |
| 5568 | Process.setStartTimes(SystemClock.elapsedRealtime(), SystemClock.uptimeMillis()); |
| 5569 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5570 | mBoundApplication = data; |
| 5571 | mConfiguration = new Configuration(data.config); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 5572 | mCompatConfiguration = new Configuration(data.config); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5573 | |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 5574 | mProfiler = new Profiler(); |
Andreas Gampe | ab8a63b | 2018-01-05 13:55:15 -0800 | [diff] [blame] | 5575 | String agent = null; |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 5576 | if (data.initProfilerInfo != null) { |
| 5577 | mProfiler.profileFile = data.initProfilerInfo.profileFile; |
| 5578 | mProfiler.profileFd = data.initProfilerInfo.profileFd; |
| 5579 | mProfiler.samplingInterval = data.initProfilerInfo.samplingInterval; |
| 5580 | mProfiler.autoStopProfiler = data.initProfilerInfo.autoStopProfiler; |
Shukang Zhou | 6ffd4f9 | 2017-01-25 16:07:57 -0800 | [diff] [blame] | 5581 | mProfiler.streamingOutput = data.initProfilerInfo.streamingOutput; |
Andreas Gampe | ab8a63b | 2018-01-05 13:55:15 -0800 | [diff] [blame] | 5582 | if (data.initProfilerInfo.attachAgentDuringBind) { |
| 5583 | agent = data.initProfilerInfo.agent; |
| 5584 | } |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 5585 | } |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 5586 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5587 | // send up app name; do this *before* waiting for debugger |
Christopher Tate | 8ee038d | 2009-11-06 11:30:20 -0800 | [diff] [blame] | 5588 | Process.setArgV0(data.processName); |
Siva Velusamy | d693dfa | 2012-09-10 14:36:58 -0700 | [diff] [blame] | 5589 | android.ddm.DdmHandleAppName.setAppName(data.processName, |
| 5590 | UserHandle.myUserId()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5591 | |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 5592 | if (mProfiler.profileFd != null) { |
| 5593 | mProfiler.startProfiling(); |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 5594 | } |
| 5595 | |
Joe Onorato | d630f10 | 2011-03-17 18:42:26 -0700 | [diff] [blame] | 5596 | // If the app is Honeycomb MR1 or earlier, switch its AsyncTask |
| 5597 | // implementation to use the pool executor. Normally, we use the |
| 5598 | // serialized executor as the default. This has to happen in the |
| 5599 | // main thread so the main looper is set right. |
Dianne Hackborn | 81e9276 | 2011-10-09 16:00:21 -0700 | [diff] [blame] | 5600 | if (data.appInfo.targetSdkVersion <= android.os.Build.VERSION_CODES.HONEYCOMB_MR1) { |
Joe Onorato | d630f10 | 2011-03-17 18:42:26 -0700 | [diff] [blame] | 5601 | AsyncTask.setDefaultExecutor(AsyncTask.THREAD_POOL_EXECUTOR); |
| 5602 | } |
| 5603 | |
Dianne Hackborn | 7895bc2 | 2014-09-05 15:09:03 -0700 | [diff] [blame] | 5604 | Message.updateCheckRecycle(data.appInfo.targetSdkVersion); |
| 5605 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5606 | /* |
| 5607 | * Before spawning a new process, reset the time zone to be the system time zone. |
| 5608 | * This needs to be done because the system time zone could have changed after the |
| 5609 | * the spawning of this process. Without doing this this process would have the incorrect |
| 5610 | * system time zone. |
| 5611 | */ |
| 5612 | TimeZone.setDefault(null); |
| 5613 | |
Adam Lesinski | b61e405 | 2016-05-19 18:23:05 -0700 | [diff] [blame] | 5614 | /* |
| 5615 | * Set the LocaleList. This may change once we create the App Context. |
| 5616 | */ |
| 5617 | LocaleList.setDefault(data.config.getLocales()); |
| 5618 | |
| 5619 | synchronized (mResourcesManager) { |
| 5620 | /* |
| 5621 | * Update the system configuration since its preloaded and might not |
| 5622 | * reflect configuration changes. The configuration object passed |
| 5623 | * in AppBindData can be safely assumed to be up to date |
| 5624 | */ |
| 5625 | mResourcesManager.applyConfigurationToResourcesLocked(data.config, data.compatInfo); |
| 5626 | mCurDefaultDisplayDpi = data.config.densityDpi; |
| 5627 | |
| 5628 | // This calls mResourcesManager so keep it within the synchronized block. |
| 5629 | applyCompatConfiguration(mCurDefaultDisplayDpi); |
| 5630 | } |
| 5631 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5632 | data.info = getPackageInfoNoCheck(data.appInfo, data.compatInfo); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5633 | |
Andreas Gampe | ab8a63b | 2018-01-05 13:55:15 -0800 | [diff] [blame] | 5634 | if (agent != null) { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5635 | handleAttachAgent(agent, data.info); |
Andreas Gampe | ab8a63b | 2018-01-05 13:55:15 -0800 | [diff] [blame] | 5636 | } |
| 5637 | |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 5638 | /** |
| 5639 | * Switch this process to density compatibility mode if needed. |
| 5640 | */ |
| 5641 | if ((data.appInfo.flags&ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES) |
| 5642 | == 0) { |
| 5643 | mDensityCompatMode = true; |
| 5644 | Bitmap.setDefaultDensity(DisplayMetrics.DENSITY_DEFAULT); |
| 5645 | } |
| 5646 | updateDefaultDensity(); |
| 5647 | |
Neil Fuller | c66ec40 | 2016-11-14 16:06:42 +0000 | [diff] [blame] | 5648 | final String use24HourSetting = mCoreSettings.getString(Settings.System.TIME_12_24); |
| 5649 | Boolean is24Hr = null; |
| 5650 | if (use24HourSetting != null) { |
| 5651 | is24Hr = "24".equals(use24HourSetting) ? Boolean.TRUE : Boolean.FALSE; |
| 5652 | } |
| 5653 | // null : use locale default for 12/24 hour formatting, |
| 5654 | // false : use 12 hour format, |
| 5655 | // true : use 24 hour format. |
Narayan Kamath | ccb2a086 | 2013-12-19 14:49:36 +0000 | [diff] [blame] | 5656 | DateFormat.set24HourTimePref(is24Hr); |
| 5657 | |
Jon Miranda | 836c0a8 | 2014-08-11 12:32:26 -0700 | [diff] [blame] | 5658 | View.mDebugViewAttributes = |
| 5659 | mCoreSettings.getInt(Settings.Global.DEBUG_VIEW_ATTRIBUTES, 0) != 0; |
| 5660 | |
Jeff Sharkey | 8918298 | 2017-11-01 19:02:56 -0600 | [diff] [blame] | 5661 | StrictMode.initThreadDefaults(data.appInfo); |
| 5662 | StrictMode.initVmDefaults(data.appInfo); |
Jeff Sharkey | 344744b | 2016-01-28 19:03:30 -0700 | [diff] [blame] | 5663 | |
Svet Ganov | 37e4327 | 2016-09-09 16:01:32 -0700 | [diff] [blame] | 5664 | // We deprecated Build.SERIAL and only apps that target pre NMR1 |
| 5665 | // SDK can see it. Since access to the serial is now behind a |
| 5666 | // permission we push down the value and here we fix it up |
| 5667 | // before any app code has been loaded. |
| 5668 | try { |
| 5669 | Field field = Build.class.getDeclaredField("SERIAL"); |
| 5670 | field.setAccessible(true); |
| 5671 | field.set(Build.class, data.buildSerial); |
| 5672 | } catch (NoSuchFieldException | IllegalAccessException e) { |
| 5673 | /* ignore */ |
| 5674 | } |
| 5675 | |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 5676 | if (data.debugMode != ApplicationThreadConstants.DEBUG_OFF) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5677 | // XXX should have option to change the port. |
| 5678 | Debug.changeDebugPort(8100); |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 5679 | if (data.debugMode == ApplicationThreadConstants.DEBUG_WAIT) { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5680 | Slog.w(TAG, "Application " + data.info.getPackageName() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5681 | + " is waiting for the debugger on port 8100..."); |
| 5682 | |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5683 | IActivityManager mgr = ActivityManager.getService(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5684 | try { |
| 5685 | mgr.showWaitingForDebugger(mAppThread, true); |
| 5686 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5687 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5688 | } |
| 5689 | |
| 5690 | Debug.waitForDebugger(); |
| 5691 | |
| 5692 | try { |
| 5693 | mgr.showWaitingForDebugger(mAppThread, false); |
| 5694 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5695 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5696 | } |
| 5697 | |
| 5698 | } else { |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5699 | Slog.w(TAG, "Application " + data.info.getPackageName() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5700 | + " can be debugged on port 8100..."); |
| 5701 | } |
| 5702 | } |
| 5703 | |
Jamie Gennis | f9c7d6b | 2013-03-25 14:18:25 -0700 | [diff] [blame] | 5704 | // Allow application-generated systrace messages if we're debuggable. |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 5705 | boolean isAppDebuggable = (data.appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0; |
| 5706 | Trace.setAppTracingAllowed(isAppDebuggable); |
| 5707 | if (isAppDebuggable && data.enableBinderTracking) { |
| 5708 | Binder.enableTracing(); |
| 5709 | } |
Jamie Gennis | f9c7d6b | 2013-03-25 14:18:25 -0700 | [diff] [blame] | 5710 | |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 5711 | /** |
| 5712 | * Initialize the default http proxy in this process for the reasons we set the time zone. |
| 5713 | */ |
Andreas Gampe | 4c8e542 | 2016-05-18 11:58:47 -0700 | [diff] [blame] | 5714 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "Setup proxies"); |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 5715 | final IBinder b = ServiceManager.getService(Context.CONNECTIVITY_SERVICE); |
Dianne Hackborn | d4d32c5 | 2011-11-08 17:33:59 -0800 | [diff] [blame] | 5716 | if (b != null) { |
| 5717 | // In pre-boot mode (doing initial launch to collect password), not |
| 5718 | // all system is up. This includes the connectivity service, so don't |
| 5719 | // crash if we can't get it. |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 5720 | final IConnectivityManager service = IConnectivityManager.Stub.asInterface(b); |
Dianne Hackborn | d4d32c5 | 2011-11-08 17:33:59 -0800 | [diff] [blame] | 5721 | try { |
Paul Jensen | cee9b51 | 2015-05-06 07:32:40 -0400 | [diff] [blame] | 5722 | final ProxyInfo proxyInfo = service.getProxyForNetwork(null); |
Jason Monk | 207900c | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 5723 | Proxy.setHttpProxySystemProperty(proxyInfo); |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5724 | } catch (RemoteException e) { |
Andreas Gampe | 4c8e542 | 2016-05-18 11:58:47 -0700 | [diff] [blame] | 5725 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5726 | throw e.rethrowFromSystemServer(); |
| 5727 | } |
Dianne Hackborn | d4d32c5 | 2011-11-08 17:33:59 -0800 | [diff] [blame] | 5728 | } |
Andreas Gampe | 4c8e542 | 2016-05-18 11:58:47 -0700 | [diff] [blame] | 5729 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 5730 | |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 5731 | // Instrumentation info affects the class loader, so load it before |
| 5732 | // setting up the app context. |
| 5733 | final InstrumentationInfo ii; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5734 | if (data.instrumentationName != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5735 | try { |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 5736 | ii = new ApplicationPackageManager(null, getPackageManager()) |
| 5737 | .getInstrumentationInfo(data.instrumentationName, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5738 | } catch (PackageManager.NameNotFoundException e) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5739 | throw new RuntimeException( |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 5740 | "Unable to find instrumentation info for: " + data.instrumentationName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5741 | } |
| 5742 | |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 5743 | mInstrumentationPackageName = ii.packageName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5744 | mInstrumentationAppDir = ii.sourceDir; |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 5745 | mInstrumentationSplitAppDirs = ii.splitSourceDirs; |
Todd Kennedy | e713efc | 2016-05-10 13:45:40 -0700 | [diff] [blame] | 5746 | mInstrumentationLibDir = getInstrumentationLibrary(data.appInfo, ii); |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5747 | mInstrumentedAppDir = data.info.getAppDir(); |
| 5748 | mInstrumentedSplitAppDirs = data.info.getSplitAppDirs(); |
| 5749 | mInstrumentedLibDir = data.info.getLibDir(); |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 5750 | } else { |
| 5751 | ii = null; |
| 5752 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5753 | |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5754 | final ContextImpl appContext = ContextImpl.createAppContext(this, data.info); |
Adam Lesinski | b61e405 | 2016-05-19 18:23:05 -0700 | [diff] [blame] | 5755 | updateLocaleListFromAppContext(appContext, |
| 5756 | mResourcesManager.getConfiguration().getLocales()); |
Seigo Nonaka | c14dd78 | 2016-03-30 23:09:16 +0900 | [diff] [blame] | 5757 | |
Jesse Hall | 317fa5a | 2017-05-23 15:46:55 -0700 | [diff] [blame] | 5758 | if (!Process.isIsolated()) { |
Jeff Sharkey | 8918298 | 2017-11-01 19:02:56 -0600 | [diff] [blame] | 5759 | final int oldMask = StrictMode.allowThreadDiskWritesMask(); |
| 5760 | try { |
| 5761 | setupGraphicsSupport(appContext); |
| 5762 | } finally { |
| 5763 | StrictMode.setThreadPolicyMask(oldMask); |
| 5764 | } |
Michael Lentine | 2ba303f | 2016-02-01 20:44:34 -0600 | [diff] [blame] | 5765 | } |
Michael Lentine | 03d8f768 | 2016-01-31 15:37:11 -0600 | [diff] [blame] | 5766 | |
Calin Juravle | 37dfc8e | 2017-03-13 19:02:32 -0700 | [diff] [blame] | 5767 | // If we use profiles, setup the dex reporter to notify package manager |
| 5768 | // of any relevant dex loads. The idle maintenance job will use the information |
| 5769 | // reported to optimize the loaded dex files. |
| 5770 | // Note that we only need one global reporter per app. |
| 5771 | // Make sure we do this before calling onCreate so that we can capture the |
| 5772 | // complete application startup. |
| 5773 | if (SystemProperties.getBoolean("dalvik.vm.usejitprofiles", false)) { |
Calin Juravle | f5a7bfc | 2017-03-13 23:30:30 -0700 | [diff] [blame] | 5774 | BaseDexClassLoader.setReporter(DexLoadReporter.getInstance()); |
Calin Juravle | 37dfc8e | 2017-03-13 19:02:32 -0700 | [diff] [blame] | 5775 | } |
| 5776 | |
Chad Brubaker | 78d4712 | 2015-11-17 22:26:58 -0800 | [diff] [blame] | 5777 | // Install the Network Security Config Provider. This must happen before the application |
| 5778 | // code is loaded to prevent issues with instances of TLS objects being created before |
| 5779 | // the provider is installed. |
Andreas Gampe | 4c8e542 | 2016-05-18 11:58:47 -0700 | [diff] [blame] | 5780 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "NetworkSecurityConfigProvider.install"); |
Chad Brubaker | 276ee96 | 2016-06-08 12:57:46 -0700 | [diff] [blame] | 5781 | NetworkSecurityConfigProvider.install(appContext); |
Andreas Gampe | 4c8e542 | 2016-05-18 11:58:47 -0700 | [diff] [blame] | 5782 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Chad Brubaker | 78d4712 | 2015-11-17 22:26:58 -0800 | [diff] [blame] | 5783 | |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 5784 | // Continue loading instrumentation. |
| 5785 | if (ii != null) { |
Dianne Hackborn | f4ef6eb | 2017-12-07 13:57:21 -0800 | [diff] [blame] | 5786 | ApplicationInfo instrApp; |
| 5787 | try { |
| 5788 | instrApp = getPackageManager().getApplicationInfo(ii.packageName, 0, |
| 5789 | UserHandle.myUserId()); |
| 5790 | } catch (RemoteException e) { |
| 5791 | instrApp = null; |
| 5792 | } |
| 5793 | if (instrApp == null) { |
| 5794 | instrApp = new ApplicationInfo(); |
| 5795 | } |
Jeff Sharkey | 1544779 | 2015-11-05 16:18:51 -0800 | [diff] [blame] | 5796 | ii.copyTo(instrApp); |
Fyodor Kupolov | af38b8e | 2015-12-02 16:16:07 -0800 | [diff] [blame] | 5797 | instrApp.initForUser(UserHandle.myUserId()); |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5798 | final LoadedApk pi = getPackageInfo(instrApp, data.compatInfo, |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 5799 | appContext.getClassLoader(), false, true, false); |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5800 | final ContextImpl instrContext = ContextImpl.createAppContext(this, pi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5801 | |
| 5802 | try { |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 5803 | final ClassLoader cl = instrContext.getClassLoader(); |
Dan Sandler | 07fe63e | 2017-08-15 16:41:11 -0400 | [diff] [blame] | 5804 | mInstrumentation = (Instrumentation) |
| 5805 | cl.loadClass(data.instrumentationName.getClassName()).newInstance(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5806 | } catch (Exception e) { |
| 5807 | throw new RuntimeException( |
| 5808 | "Unable to instantiate instrumentation " |
| 5809 | + data.instrumentationName + ": " + e.toString(), e); |
| 5810 | } |
| 5811 | |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 5812 | final ComponentName component = new ComponentName(ii.packageName, ii.name); |
| 5813 | mInstrumentation.init(this, instrContext, appContext, component, |
| 5814 | data.instrumentationWatcher, data.instrumentationUiAutomationConnection); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5815 | |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 5816 | if (mProfiler.profileFile != null && !ii.handleProfiling |
| 5817 | && mProfiler.profileFd == null) { |
| 5818 | mProfiler.handlingProfiling = true; |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 5819 | final File file = new File(mProfiler.profileFile); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5820 | file.getParentFile().mkdirs(); |
| 5821 | Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024); |
| 5822 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5823 | } else { |
| 5824 | mInstrumentation = new Instrumentation(); |
Jason Monk | a80bfb5 | 2017-11-16 17:15:37 -0500 | [diff] [blame] | 5825 | mInstrumentation.basicInit(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5826 | } |
| 5827 | |
Dianne Hackborn | 3b81bc1 | 2011-01-15 11:50:52 -0800 | [diff] [blame] | 5828 | if ((data.appInfo.flags&ApplicationInfo.FLAG_LARGE_HEAP) != 0) { |
Dianne Hackborn | de39851 | 2011-01-18 18:45:21 -0800 | [diff] [blame] | 5829 | dalvik.system.VMRuntime.getRuntime().clearGrowthLimit(); |
Mathieu Chartier | 24cee07 | 2015-01-08 14:42:20 -0800 | [diff] [blame] | 5830 | } else { |
| 5831 | // Small heap, clamp to the current growth limit and let the heap release |
| 5832 | // pages after the growth limit to the non growth limit capacity. b/18387825 |
| 5833 | dalvik.system.VMRuntime.getRuntime().clampGrowthLimit(); |
Dianne Hackborn | 3b81bc1 | 2011-01-15 11:50:52 -0800 | [diff] [blame] | 5834 | } |
| 5835 | |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 5836 | // Allow disk access during application and provider setup. This could |
Jeff Sharkey | 7c50167 | 2012-02-28 12:08:37 -0800 | [diff] [blame] | 5837 | // block processing ordered broadcasts, but later processing would |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 5838 | // probably end up doing the same disk access. |
Kurt Nelson | 5e15436 | 2017-06-29 17:20:56 -0700 | [diff] [blame] | 5839 | Application app; |
Jeff Sharkey | 7c50167 | 2012-02-28 12:08:37 -0800 | [diff] [blame] | 5840 | final StrictMode.ThreadPolicy savedPolicy = StrictMode.allowThreadDiskWrites(); |
Kurt Nelson | 571c3f6 | 2017-07-10 11:09:04 -0700 | [diff] [blame] | 5841 | final StrictMode.ThreadPolicy writesAllowedPolicy = StrictMode.getThreadPolicy(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5842 | try { |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 5843 | // If the app is being launched for full backup or restore, bring it up in |
| 5844 | // a restricted environment with the base application class. |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 5845 | app = data.info.makeApplication(data.restrictedBackupMode, null); |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 5846 | |
| 5847 | // Propagate autofill compat state |
| 5848 | app.setAutofillCompatibilityEnabled(data.autofillCompatibilityEnabled); |
| 5849 | |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 5850 | mInitialApplication = app; |
Jeff Sharkey | 7c50167 | 2012-02-28 12:08:37 -0800 | [diff] [blame] | 5851 | |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 5852 | // don't bring up providers in restricted mode; they may depend on the |
| 5853 | // app's custom Application class |
| 5854 | if (!data.restrictedBackupMode) { |
Jeff Sharkey | 3e19589 | 2016-03-05 19:48:59 -0700 | [diff] [blame] | 5855 | if (!ArrayUtils.isEmpty(data.providers)) { |
| 5856 | installContentProviders(app, data.providers); |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 5857 | // For process that contains content providers, we want to |
| 5858 | // ensure that the JIT is enabled "at some point". |
| 5859 | mH.sendEmptyMessageDelayed(H.ENABLE_JIT, 10*1000); |
| 5860 | } |
| 5861 | } |
| 5862 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5863 | // Do this after providers, since instrumentation tests generally start their |
| 5864 | // test thread at this point, and we don't want that racing. |
| 5865 | try { |
| 5866 | mInstrumentation.onCreate(data.instrumentationArgs); |
| 5867 | } |
| 5868 | catch (Exception e) { |
| 5869 | throw new RuntimeException( |
| 5870 | "Exception thrown in onCreate() of " |
| 5871 | + data.instrumentationName + ": " + e.toString(), e); |
| 5872 | } |
Kurt Nelson | 571c3f6 | 2017-07-10 11:09:04 -0700 | [diff] [blame] | 5873 | try { |
| 5874 | mInstrumentation.callApplicationOnCreate(app); |
| 5875 | } catch (Exception e) { |
| 5876 | if (!mInstrumentation.onException(app, e)) { |
| 5877 | throw new RuntimeException( |
| 5878 | "Unable to create application " + app.getClass().getName() |
| 5879 | + ": " + e.toString(), e); |
| 5880 | } |
| 5881 | } |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 5882 | } finally { |
Kurt Nelson | 571c3f6 | 2017-07-10 11:09:04 -0700 | [diff] [blame] | 5883 | // If the app targets < O-MR1, or doesn't change the thread policy |
| 5884 | // during startup, clobber the policy to maintain behavior of b/36951662 |
| 5885 | if (data.appInfo.targetSdkVersion <= Build.VERSION_CODES.O |
| 5886 | || StrictMode.getThreadPolicy().equals(writesAllowedPolicy)) { |
| 5887 | StrictMode.setThreadPolicy(savedPolicy); |
Kurt Nelson | 5e15436 | 2017-06-29 17:20:56 -0700 | [diff] [blame] | 5888 | } |
| 5889 | } |
| 5890 | |
Clara Bayarri | 4b5a4d2 | 2017-01-27 20:15:45 +0000 | [diff] [blame] | 5891 | // Preload fonts resources |
Seigo Nonaka | 54084b6 | 2017-04-24 14:46:23 -0700 | [diff] [blame] | 5892 | FontsContract.setApplicationContextForResources(appContext); |
Torne (Richard Coles) | 85ecae5 | 2018-01-30 18:13:00 -0500 | [diff] [blame] | 5893 | if (!Process.isIsolated()) { |
| 5894 | try { |
| 5895 | final ApplicationInfo info = |
| 5896 | getPackageManager().getApplicationInfo( |
| 5897 | data.appInfo.packageName, |
| 5898 | PackageManager.GET_META_DATA /*flags*/, |
| 5899 | UserHandle.myUserId()); |
| 5900 | if (info.metaData != null) { |
| 5901 | final int preloadedFontsResource = info.metaData.getInt( |
| 5902 | ApplicationInfo.METADATA_PRELOADED_FONTS, 0); |
| 5903 | if (preloadedFontsResource != 0) { |
| 5904 | data.info.getResources().preloadFonts(preloadedFontsResource); |
| 5905 | } |
Clara Bayarri | 4b5a4d2 | 2017-01-27 20:15:45 +0000 | [diff] [blame] | 5906 | } |
Torne (Richard Coles) | 85ecae5 | 2018-01-30 18:13:00 -0500 | [diff] [blame] | 5907 | } catch (RemoteException e) { |
| 5908 | throw e.rethrowFromSystemServer(); |
Clara Bayarri | 4b5a4d2 | 2017-01-27 20:15:45 +0000 | [diff] [blame] | 5909 | } |
Clara Bayarri | 4b5a4d2 | 2017-01-27 20:15:45 +0000 | [diff] [blame] | 5910 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5911 | } |
| 5912 | |
| 5913 | /*package*/ final void finishInstrumentation(int resultCode, Bundle results) { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5914 | IActivityManager am = ActivityManager.getService(); |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 5915 | if (mProfiler.profileFile != null && mProfiler.handlingProfiling |
| 5916 | && mProfiler.profileFd == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5917 | Debug.stopMethodTracing(); |
| 5918 | } |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5919 | //Slog.i(TAG, "am: " + ActivityManager.getService() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5920 | // + ", app thr: " + mAppThread); |
| 5921 | try { |
| 5922 | am.finishInstrumentation(mAppThread, resultCode, results); |
| 5923 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5924 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5925 | } |
| 5926 | } |
| 5927 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 5928 | private void installContentProviders( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5929 | Context context, List<ProviderInfo> providers) { |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 5930 | final ArrayList<ContentProviderHolder> results = new ArrayList<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5931 | |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 5932 | for (ProviderInfo cpi : providers) { |
Dianne Hackborn | 40e9f29 | 2012-11-27 19:12:23 -0800 | [diff] [blame] | 5933 | if (DEBUG_PROVIDER) { |
| 5934 | StringBuilder buf = new StringBuilder(128); |
| 5935 | buf.append("Pub "); |
| 5936 | buf.append(cpi.authority); |
| 5937 | buf.append(": "); |
| 5938 | buf.append(cpi.name); |
| 5939 | Log.i(TAG, buf.toString()); |
| 5940 | } |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 5941 | ContentProviderHolder cph = installProvider(context, null, cpi, |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5942 | false /*noisy*/, true /*noReleaseNeeded*/, true /*stable*/); |
| 5943 | if (cph != null) { |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5944 | cph.noReleaseNeeded = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5945 | results.add(cph); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5946 | } |
| 5947 | } |
| 5948 | |
| 5949 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5950 | ActivityManager.getService().publishContentProviders( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5951 | getApplicationThread(), results); |
| 5952 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5953 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5954 | } |
| 5955 | } |
| 5956 | |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 5957 | public final IContentProvider acquireProvider( |
| 5958 | Context c, String auth, int userId, boolean stable) { |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 5959 | final IContentProvider provider = acquireExistingProvider(c, auth, userId, stable); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5960 | if (provider != null) { |
| 5961 | return provider; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5962 | } |
| 5963 | |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 5964 | // There is a possible race here. Another thread may try to acquire |
| 5965 | // the same provider at the same time. When this happens, we want to ensure |
| 5966 | // that the first one wins. |
| 5967 | // Note that we cannot hold the lock while acquiring and installing the |
| 5968 | // provider since it might take a long time to run and it could also potentially |
| 5969 | // 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] | 5970 | ContentProviderHolder holder = null; |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 5971 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5972 | holder = ActivityManager.getService().getContentProvider( |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 5973 | getApplicationThread(), auth, userId, stable); |
| 5974 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5975 | throw ex.rethrowFromSystemServer(); |
Wale Ogunwale | 67fe0a4 | 2015-04-24 14:44:54 -0700 | [diff] [blame] | 5976 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5977 | if (holder == null) { |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 5978 | 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] | 5979 | return null; |
| 5980 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5981 | |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5982 | // Install provider will increment the reference count for us, and break |
| 5983 | // any ties in the race. |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5984 | holder = installProvider(c, holder, holder.info, |
| 5985 | true /*noisy*/, holder.noReleaseNeeded, stable); |
| 5986 | return holder.provider; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5987 | } |
| 5988 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5989 | private final void incProviderRefLocked(ProviderRefCount prc, boolean stable) { |
| 5990 | if (stable) { |
| 5991 | prc.stableCount += 1; |
| 5992 | if (prc.stableCount == 1) { |
| 5993 | // We are acquiring a new stable reference on the provider. |
| 5994 | int unstableDelta; |
| 5995 | if (prc.removePending) { |
| 5996 | // We have a pending remove operation, which is holding the |
| 5997 | // last unstable reference. At this point we are converting |
| 5998 | // that unstable reference to our new stable reference. |
| 5999 | unstableDelta = -1; |
| 6000 | // Cancel the removal of the provider. |
| 6001 | if (DEBUG_PROVIDER) { |
| 6002 | Slog.v(TAG, "incProviderRef: stable " |
| 6003 | + "snatched provider from the jaws of death"); |
| 6004 | } |
| 6005 | prc.removePending = false; |
Guobin Zhang | 9e3e5266 | 2013-03-21 13:57:11 +0800 | [diff] [blame] | 6006 | // There is a race! It fails to remove the message, which |
| 6007 | // will be handled in completeRemoveProvider(). |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6008 | mH.removeMessages(H.REMOVE_PROVIDER, prc); |
| 6009 | } else { |
| 6010 | unstableDelta = 0; |
| 6011 | } |
| 6012 | try { |
| 6013 | if (DEBUG_PROVIDER) { |
| 6014 | Slog.v(TAG, "incProviderRef Now stable - " |
| 6015 | + prc.holder.info.name + ": unstableDelta=" |
| 6016 | + unstableDelta); |
| 6017 | } |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6018 | ActivityManager.getService().refContentProvider( |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6019 | prc.holder.connection, 1, unstableDelta); |
| 6020 | } catch (RemoteException e) { |
| 6021 | //do nothing content provider object is dead any way |
| 6022 | } |
| 6023 | } |
| 6024 | } else { |
| 6025 | prc.unstableCount += 1; |
| 6026 | if (prc.unstableCount == 1) { |
| 6027 | // We are acquiring a new unstable reference on the provider. |
| 6028 | if (prc.removePending) { |
| 6029 | // Oh look, we actually have a remove pending for the |
| 6030 | // provider, which is still holding the last unstable |
| 6031 | // reference. We just need to cancel that to take new |
| 6032 | // ownership of the reference. |
| 6033 | if (DEBUG_PROVIDER) { |
| 6034 | Slog.v(TAG, "incProviderRef: unstable " |
| 6035 | + "snatched provider from the jaws of death"); |
| 6036 | } |
| 6037 | prc.removePending = false; |
| 6038 | mH.removeMessages(H.REMOVE_PROVIDER, prc); |
| 6039 | } else { |
| 6040 | // First unstable ref, increment our count in the |
| 6041 | // activity manager. |
| 6042 | try { |
| 6043 | if (DEBUG_PROVIDER) { |
| 6044 | Slog.v(TAG, "incProviderRef: Now unstable - " |
| 6045 | + prc.holder.info.name); |
| 6046 | } |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6047 | ActivityManager.getService().refContentProvider( |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6048 | prc.holder.connection, 0, 1); |
| 6049 | } catch (RemoteException e) { |
| 6050 | //do nothing content provider object is dead any way |
| 6051 | } |
| 6052 | } |
| 6053 | } |
| 6054 | } |
| 6055 | } |
| 6056 | |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 6057 | public final IContentProvider acquireExistingProvider( |
| 6058 | Context c, String auth, int userId, boolean stable) { |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6059 | synchronized (mProviderMap) { |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 6060 | final ProviderKey key = new ProviderKey(auth, userId); |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 6061 | final ProviderClientRecord pr = mProviderMap.get(key); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6062 | if (pr == null) { |
| 6063 | return null; |
| 6064 | } |
| 6065 | |
| 6066 | IContentProvider provider = pr.mProvider; |
| 6067 | IBinder jBinder = provider.asBinder(); |
Dianne Hackborn | c428aae | 2012-10-03 16:38:22 -0700 | [diff] [blame] | 6068 | if (!jBinder.isBinderAlive()) { |
| 6069 | // The hosting process of the provider has died; we can't |
| 6070 | // use this one. |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 6071 | Log.i(TAG, "Acquiring provider " + auth + " for user " + userId |
Dianne Hackborn | c428aae | 2012-10-03 16:38:22 -0700 | [diff] [blame] | 6072 | + ": existing object's process dead"); |
| 6073 | handleUnstableProviderDiedLocked(jBinder, true); |
| 6074 | return null; |
| 6075 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6076 | |
| 6077 | // Only increment the ref count if we have one. If we don't then the |
| 6078 | // provider is not reference counted and never needs to be released. |
Dianne Hackborn | cca1f0e | 2010-09-26 18:34:53 -0700 | [diff] [blame] | 6079 | ProviderRefCount prc = mProviderRefCountMap.get(jBinder); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6080 | if (prc != null) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6081 | incProviderRefLocked(prc, stable); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6082 | } |
| 6083 | return provider; |
| 6084 | } |
Dianne Hackborn | cca1f0e | 2010-09-26 18:34:53 -0700 | [diff] [blame] | 6085 | } |
| 6086 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6087 | public final boolean releaseProvider(IContentProvider provider, boolean stable) { |
| 6088 | if (provider == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6089 | return false; |
| 6090 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6091 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6092 | IBinder jBinder = provider.asBinder(); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6093 | synchronized (mProviderMap) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6094 | ProviderRefCount prc = mProviderRefCountMap.get(jBinder); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6095 | if (prc == null) { |
| 6096 | // 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] | 6097 | return false; |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6098 | } |
| 6099 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6100 | boolean lastRef = false; |
| 6101 | if (stable) { |
| 6102 | if (prc.stableCount == 0) { |
| 6103 | if (DEBUG_PROVIDER) Slog.v(TAG, |
| 6104 | "releaseProvider: stable ref count already 0, how?"); |
| 6105 | return false; |
| 6106 | } |
| 6107 | prc.stableCount -= 1; |
| 6108 | if (prc.stableCount == 0) { |
| 6109 | // What we do at this point depends on whether there are |
| 6110 | // any unstable refs left: if there are, we just tell the |
| 6111 | // activity manager to decrement its stable count; if there |
| 6112 | // aren't, we need to enqueue this provider to be removed, |
| 6113 | // and convert to holding a single unstable ref while |
| 6114 | // doing so. |
| 6115 | lastRef = prc.unstableCount == 0; |
| 6116 | try { |
| 6117 | if (DEBUG_PROVIDER) { |
| 6118 | Slog.v(TAG, "releaseProvider: No longer stable w/lastRef=" |
| 6119 | + lastRef + " - " + prc.holder.info.name); |
| 6120 | } |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6121 | ActivityManager.getService().refContentProvider( |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6122 | prc.holder.connection, -1, lastRef ? 1 : 0); |
| 6123 | } catch (RemoteException e) { |
| 6124 | //do nothing content provider object is dead any way |
| 6125 | } |
| 6126 | } |
| 6127 | } else { |
| 6128 | if (prc.unstableCount == 0) { |
| 6129 | if (DEBUG_PROVIDER) Slog.v(TAG, |
| 6130 | "releaseProvider: unstable ref count already 0, how?"); |
| 6131 | return false; |
| 6132 | } |
| 6133 | prc.unstableCount -= 1; |
| 6134 | if (prc.unstableCount == 0) { |
| 6135 | // If this is the last reference, we need to enqueue |
| 6136 | // this provider to be removed instead of telling the |
| 6137 | // activity manager to remove it at this point. |
| 6138 | lastRef = prc.stableCount == 0; |
| 6139 | if (!lastRef) { |
| 6140 | try { |
| 6141 | if (DEBUG_PROVIDER) { |
| 6142 | Slog.v(TAG, "releaseProvider: No longer unstable - " |
| 6143 | + prc.holder.info.name); |
| 6144 | } |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6145 | ActivityManager.getService().refContentProvider( |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6146 | prc.holder.connection, 0, -1); |
| 6147 | } catch (RemoteException e) { |
| 6148 | //do nothing content provider object is dead any way |
| 6149 | } |
| 6150 | } |
| 6151 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6152 | } |
| 6153 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6154 | if (lastRef) { |
| 6155 | if (!prc.removePending) { |
| 6156 | // Schedule the actual remove asynchronously, since we don't know the context |
| 6157 | // this will be called in. |
| 6158 | // TODO: it would be nice to post a delayed message, so |
| 6159 | // if we come back and need the same provider quickly |
| 6160 | // we will still have it available. |
| 6161 | if (DEBUG_PROVIDER) { |
| 6162 | Slog.v(TAG, "releaseProvider: Enqueueing pending removal - " |
| 6163 | + prc.holder.info.name); |
| 6164 | } |
| 6165 | prc.removePending = true; |
| 6166 | Message msg = mH.obtainMessage(H.REMOVE_PROVIDER, prc); |
| 6167 | mH.sendMessage(msg); |
| 6168 | } else { |
| 6169 | Slog.w(TAG, "Duplicate remove pending of provider " + prc.holder.info.name); |
| 6170 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6171 | } |
| 6172 | return true; |
| 6173 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6174 | } |
| 6175 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6176 | final void completeRemoveProvider(ProviderRefCount prc) { |
| 6177 | synchronized (mProviderMap) { |
| 6178 | if (!prc.removePending) { |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6179 | // There was a race! Some other client managed to acquire |
| 6180 | // the provider before the removal was completed. |
| 6181 | // Abort the removal. We will do it later. |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6182 | if (DEBUG_PROVIDER) Slog.v(TAG, "completeRemoveProvider: lost the race, " |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6183 | + "provider still in use"); |
| 6184 | return; |
| 6185 | } |
| 6186 | |
Guobin Zhang | 9e3e5266 | 2013-03-21 13:57:11 +0800 | [diff] [blame] | 6187 | // More complicated race!! Some client managed to acquire the |
| 6188 | // provider and release it before the removal was completed. |
| 6189 | // Continue the removal, and abort the next remove message. |
| 6190 | prc.removePending = false; |
| 6191 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6192 | final IBinder jBinder = prc.holder.provider.asBinder(); |
| 6193 | ProviderRefCount existingPrc = mProviderRefCountMap.get(jBinder); |
| 6194 | if (existingPrc == prc) { |
| 6195 | mProviderRefCountMap.remove(jBinder); |
| 6196 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6197 | |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 6198 | for (int i=mProviderMap.size()-1; i>=0; i--) { |
| 6199 | ProviderClientRecord pr = mProviderMap.valueAt(i); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6200 | IBinder myBinder = pr.mProvider.asBinder(); |
| 6201 | if (myBinder == jBinder) { |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 6202 | mProviderMap.removeAt(i); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6203 | } |
| 6204 | } |
| 6205 | } |
| 6206 | |
| 6207 | try { |
| 6208 | if (DEBUG_PROVIDER) { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6209 | Slog.v(TAG, "removeProvider: Invoking ActivityManagerService." |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6210 | + "removeContentProvider(" + prc.holder.info.name + ")"); |
| 6211 | } |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6212 | ActivityManager.getService().removeContentProvider( |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6213 | prc.holder.connection, false); |
| 6214 | } catch (RemoteException e) { |
| 6215 | //do nothing content provider object is dead any way |
| 6216 | } |
| 6217 | } |
| 6218 | |
| 6219 | final void handleUnstableProviderDied(IBinder provider, boolean fromClient) { |
Dianne Hackborn | c428aae | 2012-10-03 16:38:22 -0700 | [diff] [blame] | 6220 | synchronized (mProviderMap) { |
| 6221 | handleUnstableProviderDiedLocked(provider, fromClient); |
| 6222 | } |
| 6223 | } |
| 6224 | |
| 6225 | final void handleUnstableProviderDiedLocked(IBinder provider, boolean fromClient) { |
| 6226 | ProviderRefCount prc = mProviderRefCountMap.get(provider); |
| 6227 | if (prc != null) { |
| 6228 | if (DEBUG_PROVIDER) Slog.v(TAG, "Cleaning up dead provider " |
| 6229 | + provider + " " + prc.holder.info.name); |
| 6230 | mProviderRefCountMap.remove(provider); |
You Kim | bc74de6 | 2013-10-01 00:13:26 +0900 | [diff] [blame] | 6231 | for (int i=mProviderMap.size()-1; i>=0; i--) { |
| 6232 | ProviderClientRecord pr = mProviderMap.valueAt(i); |
| 6233 | if (pr != null && pr.mProvider.asBinder() == provider) { |
| 6234 | Slog.i(TAG, "Removing dead content provider:" + pr.mProvider.toString()); |
| 6235 | mProviderMap.removeAt(i); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6236 | } |
Dianne Hackborn | c428aae | 2012-10-03 16:38:22 -0700 | [diff] [blame] | 6237 | } |
You Kim | bc74de6 | 2013-10-01 00:13:26 +0900 | [diff] [blame] | 6238 | |
Dianne Hackborn | c428aae | 2012-10-03 16:38:22 -0700 | [diff] [blame] | 6239 | if (fromClient) { |
| 6240 | // We found out about this due to execution in our client |
| 6241 | // code. Tell the activity manager about it now, to ensure |
| 6242 | // that the next time we go to do anything with the provider |
| 6243 | // it knows it is dead (so we don't race with its death |
| 6244 | // notification). |
| 6245 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6246 | ActivityManager.getService().unstableProviderDied( |
Dianne Hackborn | c428aae | 2012-10-03 16:38:22 -0700 | [diff] [blame] | 6247 | prc.holder.connection); |
| 6248 | } catch (RemoteException e) { |
| 6249 | //do nothing content provider object is dead any way |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6250 | } |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 6251 | } |
| 6252 | } |
| 6253 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6254 | |
Jeff Sharkey | 7aa7601 | 2013-09-30 14:26:27 -0700 | [diff] [blame] | 6255 | final void appNotRespondingViaProvider(IBinder provider) { |
| 6256 | synchronized (mProviderMap) { |
| 6257 | ProviderRefCount prc = mProviderRefCountMap.get(provider); |
| 6258 | if (prc != null) { |
| 6259 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6260 | ActivityManager.getService() |
Jeff Sharkey | 7aa7601 | 2013-09-30 14:26:27 -0700 | [diff] [blame] | 6261 | .appNotRespondingViaProvider(prc.holder.connection); |
| 6262 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 6263 | throw e.rethrowFromSystemServer(); |
Jeff Sharkey | 7aa7601 | 2013-09-30 14:26:27 -0700 | [diff] [blame] | 6264 | } |
| 6265 | } |
| 6266 | } |
| 6267 | } |
| 6268 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6269 | private ProviderClientRecord installProviderAuthoritiesLocked(IContentProvider provider, |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 6270 | ContentProvider localProvider, ContentProviderHolder holder) { |
Andreas Gampe | 18e99c1 | 2015-03-06 15:29:06 -0800 | [diff] [blame] | 6271 | final String auths[] = holder.info.authority.split(";"); |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 6272 | final int userId = UserHandle.getUserId(holder.info.applicationInfo.uid); |
| 6273 | |
Jeff Sharkey | 0a17db1 | 2016-11-04 11:23:46 -0600 | [diff] [blame] | 6274 | if (provider != null) { |
| 6275 | // If this provider is hosted by the core OS and cannot be upgraded, |
| 6276 | // then I guess we're okay doing blocking calls to it. |
| 6277 | for (String auth : auths) { |
| 6278 | switch (auth) { |
| 6279 | case ContactsContract.AUTHORITY: |
| 6280 | case CallLog.AUTHORITY: |
| 6281 | case CallLog.SHADOW_AUTHORITY: |
| 6282 | case BlockedNumberContract.AUTHORITY: |
| 6283 | case CalendarContract.AUTHORITY: |
| 6284 | case Downloads.Impl.AUTHORITY: |
Jeff Sharkey | cb62162 | 2016-11-11 14:04:32 -0700 | [diff] [blame] | 6285 | case "telephony": |
Jeff Sharkey | 0a17db1 | 2016-11-04 11:23:46 -0600 | [diff] [blame] | 6286 | Binder.allowBlocking(provider.asBinder()); |
| 6287 | } |
| 6288 | } |
| 6289 | } |
| 6290 | |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 6291 | final ProviderClientRecord pcr = new ProviderClientRecord( |
| 6292 | auths, provider, localProvider, holder); |
| 6293 | for (String auth : auths) { |
| 6294 | final ProviderKey key = new ProviderKey(auth, userId); |
| 6295 | final ProviderClientRecord existing = mProviderMap.get(key); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6296 | if (existing != null) { |
| 6297 | Slog.w(TAG, "Content provider " + pcr.mHolder.info.name |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 6298 | + " already published as " + auth); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6299 | } else { |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 6300 | mProviderMap.put(key, pcr); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6301 | } |
| 6302 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6303 | return pcr; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6304 | } |
| 6305 | |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6306 | /** |
| 6307 | * Installs the provider. |
| 6308 | * |
| 6309 | * Providers that are local to the process or that come from the system server |
| 6310 | * may be installed permanently which is indicated by setting noReleaseNeeded to true. |
| 6311 | * Other remote providers are reference counted. The initial reference count |
| 6312 | * for all reference counted providers is one. Providers that are not reference |
| 6313 | * counted do not have a reference count (at all). |
| 6314 | * |
| 6315 | * This method detects when a provider has already been installed. When this happens, |
| 6316 | * it increments the reference count of the existing provider (if appropriate) |
| 6317 | * and returns the existing provider. This can happen due to concurrent |
| 6318 | * attempts to acquire the same provider. |
| 6319 | */ |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 6320 | private ContentProviderHolder installProvider(Context context, |
| 6321 | ContentProviderHolder holder, ProviderInfo info, |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6322 | boolean noisy, boolean noReleaseNeeded, boolean stable) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6323 | ContentProvider localProvider = null; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6324 | IContentProvider provider; |
Dianne Hackborn | 5f48fca | 2012-05-30 11:06:31 -0700 | [diff] [blame] | 6325 | if (holder == null || holder.provider == null) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6326 | if (DEBUG_PROVIDER || noisy) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 6327 | Slog.d(TAG, "Loading provider " + info.authority + ": " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6328 | + info.name); |
| 6329 | } |
| 6330 | Context c = null; |
| 6331 | ApplicationInfo ai = info.applicationInfo; |
| 6332 | if (context.getPackageName().equals(ai.packageName)) { |
| 6333 | c = context; |
| 6334 | } else if (mInitialApplication != null && |
| 6335 | mInitialApplication.getPackageName().equals(ai.packageName)) { |
| 6336 | c = mInitialApplication; |
| 6337 | } else { |
| 6338 | try { |
| 6339 | c = context.createPackageContext(ai.packageName, |
| 6340 | Context.CONTEXT_INCLUDE_CODE); |
| 6341 | } catch (PackageManager.NameNotFoundException e) { |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 6342 | // Ignore |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6343 | } |
| 6344 | } |
| 6345 | if (c == null) { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 6346 | Slog.w(TAG, "Unable to get context for package " + |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6347 | ai.packageName + |
| 6348 | " while loading content provider " + |
| 6349 | info.name); |
| 6350 | return null; |
| 6351 | } |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 6352 | |
| 6353 | if (info.splitName != null) { |
| 6354 | try { |
| 6355 | c = c.createContextForSplit(info.splitName); |
| 6356 | } catch (NameNotFoundException e) { |
| 6357 | throw new RuntimeException(e); |
| 6358 | } |
| 6359 | } |
| 6360 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6361 | try { |
| 6362 | final java.lang.ClassLoader cl = c.getClassLoader(); |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 6363 | LoadedApk packageInfo = peekPackageInfo(ai.packageName, true); |
| 6364 | if (packageInfo == null) { |
Jason Monk | a80bfb5 | 2017-11-16 17:15:37 -0500 | [diff] [blame] | 6365 | // System startup case. |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 6366 | packageInfo = getSystemContext().mPackageInfo; |
Jason Monk | a80bfb5 | 2017-11-16 17:15:37 -0500 | [diff] [blame] | 6367 | } |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 6368 | localProvider = packageInfo.getAppFactory() |
Jason Monk | a80bfb5 | 2017-11-16 17:15:37 -0500 | [diff] [blame] | 6369 | .instantiateProvider(cl, info.name); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6370 | provider = localProvider.getIContentProvider(); |
| 6371 | if (provider == null) { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 6372 | Slog.e(TAG, "Failed to instantiate class " + |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6373 | info.name + " from sourceDir " + |
| 6374 | info.applicationInfo.sourceDir); |
| 6375 | return null; |
| 6376 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6377 | if (DEBUG_PROVIDER) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6378 | TAG, "Instantiating local provider " + info.name); |
| 6379 | // XXX Need to create the correct context for this provider. |
| 6380 | localProvider.attachInfo(c, info); |
| 6381 | } catch (java.lang.Exception e) { |
| 6382 | if (!mInstrumentation.onException(null, e)) { |
| 6383 | throw new RuntimeException( |
| 6384 | "Unable to get provider " + info.name |
| 6385 | + ": " + e.toString(), e); |
| 6386 | } |
| 6387 | return null; |
| 6388 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6389 | } else { |
| 6390 | provider = holder.provider; |
| 6391 | 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] | 6392 | + info.name); |
| 6393 | } |
| 6394 | |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 6395 | ContentProviderHolder retHolder; |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6396 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6397 | synchronized (mProviderMap) { |
| 6398 | if (DEBUG_PROVIDER) Slog.v(TAG, "Checking to add " + provider |
| 6399 | + " / " + info.name); |
| 6400 | IBinder jBinder = provider.asBinder(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6401 | if (localProvider != null) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6402 | ComponentName cname = new ComponentName(info.packageName, info.name); |
| 6403 | ProviderClientRecord pr = mLocalProvidersByName.get(cname); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6404 | if (pr != null) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6405 | if (DEBUG_PROVIDER) { |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6406 | Slog.v(TAG, "installProvider: lost the race, " |
| 6407 | + "using existing local provider"); |
| 6408 | } |
| 6409 | provider = pr.mProvider; |
| 6410 | } else { |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 6411 | holder = new ContentProviderHolder(info); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6412 | holder.provider = provider; |
| 6413 | holder.noReleaseNeeded = true; |
| 6414 | pr = installProviderAuthoritiesLocked(provider, localProvider, holder); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6415 | mLocalProviders.put(jBinder, pr); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6416 | mLocalProvidersByName.put(cname, pr); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6417 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6418 | retHolder = pr.mHolder; |
| 6419 | } else { |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6420 | ProviderRefCount prc = mProviderRefCountMap.get(jBinder); |
| 6421 | if (prc != null) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6422 | if (DEBUG_PROVIDER) { |
| 6423 | Slog.v(TAG, "installProvider: lost the race, updating ref count"); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6424 | } |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 6425 | // We need to transfer our new reference to the existing |
| 6426 | // ref count, releasing the old one... but only if |
| 6427 | // release is needed (that is, it is not running in the |
| 6428 | // system process). |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6429 | if (!noReleaseNeeded) { |
| 6430 | incProviderRefLocked(prc, stable); |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 6431 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6432 | ActivityManager.getService().removeContentProvider( |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 6433 | holder.connection, stable); |
| 6434 | } catch (RemoteException e) { |
| 6435 | //do nothing content provider object is dead any way |
| 6436 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6437 | } |
| 6438 | } else { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6439 | ProviderClientRecord client = installProviderAuthoritiesLocked( |
| 6440 | provider, localProvider, holder); |
| 6441 | if (noReleaseNeeded) { |
| 6442 | prc = new ProviderRefCount(holder, client, 1000, 1000); |
| 6443 | } else { |
| 6444 | prc = stable |
| 6445 | ? new ProviderRefCount(holder, client, 1, 0) |
| 6446 | : new ProviderRefCount(holder, client, 0, 1); |
| 6447 | } |
| 6448 | mProviderRefCountMap.put(jBinder, prc); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6449 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6450 | retHolder = prc.holder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6451 | } |
| 6452 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6453 | return retHolder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6454 | } |
| 6455 | |
Torne (Richard Coles) | 466cbe4 | 2017-05-31 14:09:14 -0400 | [diff] [blame] | 6456 | private void handleRunIsolatedEntryPoint(String entryPoint, String[] entryPointArgs) { |
| 6457 | try { |
| 6458 | Method main = Class.forName(entryPoint).getMethod("main", String[].class); |
| 6459 | main.invoke(null, new Object[]{entryPointArgs}); |
| 6460 | } catch (ReflectiveOperationException e) { |
| 6461 | throw new AndroidRuntimeException("runIsolatedEntryPoint failed", e); |
| 6462 | } |
| 6463 | // The process will be empty after this method returns; exit the VM now. |
| 6464 | System.exit(0); |
| 6465 | } |
| 6466 | |
Sudheer Shanka | f669010 | 2017-10-16 10:20:32 -0700 | [diff] [blame] | 6467 | private void attach(boolean system, long startSeq) { |
Jeff Sharkey | 66a017b | 2013-01-17 18:18:22 -0800 | [diff] [blame] | 6468 | sCurrentActivityThread = this; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6469 | mSystemThread = system; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6470 | if (!system) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 6471 | ViewRootImpl.addFirstDrawHandler(new Runnable() { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 6472 | @Override |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 6473 | public void run() { |
| 6474 | ensureJitEnabled(); |
| 6475 | } |
| 6476 | }); |
Siva Velusamy | d693dfa | 2012-09-10 14:36:58 -0700 | [diff] [blame] | 6477 | android.ddm.DdmHandleAppName.setAppName("<pre-initialized>", |
| 6478 | UserHandle.myUserId()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6479 | RuntimeInit.setApplicationObject(mAppThread.asBinder()); |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6480 | final IActivityManager mgr = ActivityManager.getService(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6481 | try { |
Sudheer Shanka | f669010 | 2017-10-16 10:20:32 -0700 | [diff] [blame] | 6482 | mgr.attachApplication(mAppThread, startSeq); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6483 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 6484 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6485 | } |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 6486 | // Watch for getting close to heap limit. |
| 6487 | BinderInternal.addGcWatcher(new Runnable() { |
| 6488 | @Override public void run() { |
| 6489 | if (!mSomeActivitiesChanged) { |
| 6490 | return; |
| 6491 | } |
| 6492 | Runtime runtime = Runtime.getRuntime(); |
| 6493 | long dalvikMax = runtime.maxMemory(); |
| 6494 | long dalvikUsed = runtime.totalMemory() - runtime.freeMemory(); |
| 6495 | if (dalvikUsed > ((3*dalvikMax)/4)) { |
| 6496 | if (DEBUG_MEMORY_TRIM) Slog.d(TAG, "Dalvik max=" + (dalvikMax/1024) |
| 6497 | + " total=" + (runtime.totalMemory()/1024) |
| 6498 | + " used=" + (dalvikUsed/1024)); |
| 6499 | mSomeActivitiesChanged = false; |
| 6500 | try { |
| 6501 | mgr.releaseSomeActivities(mAppThread); |
| 6502 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 6503 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 6504 | } |
| 6505 | } |
| 6506 | } |
| 6507 | }); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6508 | } else { |
| 6509 | // Don't set application object here -- if the system crashes, |
| 6510 | // 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] | 6511 | android.ddm.DdmHandleAppName.setAppName("system_process", |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 6512 | UserHandle.myUserId()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6513 | try { |
| 6514 | mInstrumentation = new Instrumentation(); |
Jason Monk | a80bfb5 | 2017-11-16 17:15:37 -0500 | [diff] [blame] | 6515 | mInstrumentation.basicInit(this); |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 6516 | ContextImpl context = ContextImpl.createAppContext( |
Todd Kennedy | 233a0b1 | 2018-01-29 20:30:24 +0000 | [diff] [blame] | 6517 | this, getSystemContext().mPackageInfo); |
| 6518 | mInitialApplication = context.mPackageInfo.makeApplication(true, null); |
Jeff Brown | 7fc8e35 | 2014-09-16 18:06:47 -0700 | [diff] [blame] | 6519 | mInitialApplication.onCreate(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6520 | } catch (Exception e) { |
| 6521 | throw new RuntimeException( |
| 6522 | "Unable to instantiate Application():" + e.toString(), e); |
| 6523 | } |
| 6524 | } |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 6525 | |
| 6526 | // add dropbox logging to libcore |
| 6527 | DropBox.setReporter(new DropBoxReporter()); |
| 6528 | |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 6529 | ViewRootImpl.ConfigChangedCallback configChangedCallback |
| 6530 | = (Configuration globalConfig) -> { |
| 6531 | synchronized (mResourcesManager) { |
| 6532 | // We need to apply this change to the resources immediately, because upon returning |
| 6533 | // the view hierarchy will be informed about it. |
| 6534 | if (mResourcesManager.applyConfigurationToResourcesLocked(globalConfig, |
| 6535 | null /* compat */)) { |
| 6536 | updateLocaleListFromAppContext(mInitialApplication.getApplicationContext(), |
| 6537 | mResourcesManager.getConfiguration().getLocales()); |
Adam Lesinski | b61e405 | 2016-05-19 18:23:05 -0700 | [diff] [blame] | 6538 | |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 6539 | // This actually changed the resources! Tell everyone about it. |
| 6540 | if (mPendingConfiguration == null |
| 6541 | || mPendingConfiguration.isOtherSeqNewer(globalConfig)) { |
| 6542 | mPendingConfiguration = globalConfig; |
| 6543 | sendMessage(H.CONFIGURATION_CHANGED, globalConfig); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6544 | } |
| 6545 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6546 | } |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 6547 | }; |
| 6548 | ViewRootImpl.addConfigCallback(configChangedCallback); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6549 | } |
| 6550 | |
Romain Guy | 5e9120d | 2012-01-30 12:17:22 -0800 | [diff] [blame] | 6551 | public static ActivityThread systemMain() { |
Alan Viverette | 5e1565e | 2014-07-29 16:14:25 -0700 | [diff] [blame] | 6552 | // The system process on low-memory devices do not get to use hardware |
| 6553 | // accelerated drawing, since this can add too much overhead to the |
| 6554 | // process. |
| 6555 | if (!ActivityManager.isHighEndGfx()) { |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 6556 | ThreadedRenderer.disable(true); |
John Reck | 73840ea | 2014-09-22 07:39:18 -0700 | [diff] [blame] | 6557 | } else { |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 6558 | ThreadedRenderer.enableForegroundTrimming(); |
Alan Viverette | 5e1565e | 2014-07-29 16:14:25 -0700 | [diff] [blame] | 6559 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6560 | ActivityThread thread = new ActivityThread(); |
Sudheer Shanka | f669010 | 2017-10-16 10:20:32 -0700 | [diff] [blame] | 6561 | thread.attach(true, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6562 | return thread; |
| 6563 | } |
| 6564 | |
Jeff Brown | 10e8971 | 2011-07-08 18:52:57 -0700 | [diff] [blame] | 6565 | public final void installSystemProviders(List<ProviderInfo> providers) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6566 | if (providers != null) { |
Jeff Brown | 10e8971 | 2011-07-08 18:52:57 -0700 | [diff] [blame] | 6567 | installContentProviders(mInitialApplication, providers); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6568 | } |
| 6569 | } |
| 6570 | |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 6571 | public int getIntCoreSetting(String key, int defaultValue) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 6572 | synchronized (mResourcesManager) { |
Svetoslav Ganov | 9aa597e | 2011-03-03 18:17:41 -0800 | [diff] [blame] | 6573 | if (mCoreSettings != null) { |
| 6574 | return mCoreSettings.getInt(key, defaultValue); |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 6575 | } |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 6576 | return defaultValue; |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 6577 | } |
| 6578 | } |
| 6579 | |
Geremy Condra | 69689a7 | 2012-09-11 16:57:17 -0700 | [diff] [blame] | 6580 | private static class EventLoggingReporter implements EventLogger.Reporter { |
| 6581 | @Override |
| 6582 | public void report (int code, Object... list) { |
| 6583 | EventLog.writeEvent(code, list); |
| 6584 | } |
| 6585 | } |
| 6586 | |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 6587 | private class DropBoxReporter implements DropBox.Reporter { |
| 6588 | |
| 6589 | private DropBoxManager dropBox; |
| 6590 | |
Narayan Kamath | 7f06224 | 2015-04-08 13:24:13 +0100 | [diff] [blame] | 6591 | public DropBoxReporter() {} |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 6592 | |
| 6593 | @Override |
| 6594 | public void addData(String tag, byte[] data, int flags) { |
Narayan Kamath | 7f06224 | 2015-04-08 13:24:13 +0100 | [diff] [blame] | 6595 | ensureInitialized(); |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 6596 | dropBox.addData(tag, data, flags); |
| 6597 | } |
| 6598 | |
| 6599 | @Override |
| 6600 | public void addText(String tag, String data) { |
Narayan Kamath | 7f06224 | 2015-04-08 13:24:13 +0100 | [diff] [blame] | 6601 | ensureInitialized(); |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 6602 | dropBox.addText(tag, data); |
| 6603 | } |
Narayan Kamath | 7f06224 | 2015-04-08 13:24:13 +0100 | [diff] [blame] | 6604 | |
| 6605 | private synchronized void ensureInitialized() { |
| 6606 | if (dropBox == null) { |
| 6607 | dropBox = (DropBoxManager) getSystemContext().getSystemService(Context.DROPBOX_SERVICE); |
| 6608 | } |
| 6609 | } |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 6610 | } |
| 6611 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 6612 | public static void main(String[] args) { |
Narayan Kamath | fbb32f6 | 2015-06-12 15:34:35 +0100 | [diff] [blame] | 6613 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "ActivityThreadMain"); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 6614 | |
Brad Fitzpatrick | 4d9e6d2 | 2010-11-15 08:49:51 -0800 | [diff] [blame] | 6615 | // CloseGuard defaults to true and can be quite spammy. We |
| 6616 | // disable it here, but selectively enable it later (via |
| 6617 | // StrictMode) on debug builds, but using DropBox, not logs. |
| 6618 | CloseGuard.setEnabled(false); |
| 6619 | |
Andreas Gampe | d281b42 | 2016-07-08 03:50:27 +0000 | [diff] [blame] | 6620 | Environment.initForCurrentUser(); |
Jeff Sharkey | b049e21 | 2012-09-07 23:16:01 -0700 | [diff] [blame] | 6621 | |
Geremy Condra | 69689a7 | 2012-09-11 16:57:17 -0700 | [diff] [blame] | 6622 | // Set the reporter for event logging in libcore |
| 6623 | EventLogger.setReporter(new EventLoggingReporter()); |
| 6624 | |
Robin Lee | 3d076af | 2014-04-25 14:57:49 +0100 | [diff] [blame] | 6625 | // Make sure TrustedCertificateStore looks in the right place for CA certificates |
| 6626 | final File configDir = Environment.getUserConfigDirectory(UserHandle.myUserId()); |
| 6627 | TrustedCertificateStore.setDefaultUserDirectory(configDir); |
| 6628 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6629 | Process.setArgV0("<pre-initialized>"); |
| 6630 | |
| 6631 | Looper.prepareMainLooper(); |
| 6632 | |
Sudheer Shanka | f669010 | 2017-10-16 10:20:32 -0700 | [diff] [blame] | 6633 | // Find the value for {@link #PROC_START_SEQ_IDENT} if provided on the command line. |
| 6634 | // It will be in the format "seq=114" |
| 6635 | long startSeq = 0; |
| 6636 | if (args != null) { |
| 6637 | for (int i = args.length - 1; i >= 0; --i) { |
| 6638 | if (args[i] != null && args[i].startsWith(PROC_START_SEQ_IDENT)) { |
| 6639 | startSeq = Long.parseLong( |
| 6640 | args[i].substring(PROC_START_SEQ_IDENT.length())); |
| 6641 | } |
| 6642 | } |
| 6643 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6644 | ActivityThread thread = new ActivityThread(); |
Sudheer Shanka | f669010 | 2017-10-16 10:20:32 -0700 | [diff] [blame] | 6645 | thread.attach(false, startSeq); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6646 | |
Vairavan Srinivasan | 7335cfd | 2012-08-18 18:36:03 -0700 | [diff] [blame] | 6647 | if (sMainThreadHandler == null) { |
| 6648 | sMainThreadHandler = thread.getHandler(); |
| 6649 | } |
| 6650 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6651 | if (false) { |
| 6652 | Looper.myLooper().setMessageLogging(new |
| 6653 | LogPrinter(Log.DEBUG, "ActivityThread")); |
| 6654 | } |
| 6655 | |
Narayan Kamath | fbb32f6 | 2015-06-12 15:34:35 +0100 | [diff] [blame] | 6656 | // End of event ActivityThreadMain. |
| 6657 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6658 | Looper.loop(); |
| 6659 | |
Jeff Brown | 10e8971 | 2011-07-08 18:52:57 -0700 | [diff] [blame] | 6660 | throw new RuntimeException("Main thread loop unexpectedly exited"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6661 | } |
Chris Craik | fc29424 | 2016-12-13 18:10:46 -0800 | [diff] [blame] | 6662 | |
| 6663 | // ------------------ Regular JNI ------------------------ |
| 6664 | |
| 6665 | private native void nDumpGraphicsInfo(FileDescriptor fd); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6666 | } |