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 | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 19 | import static android.view.Display.INVALID_DISPLAY; |
| 20 | |
Adam Lesinski | c1b0ebf | 2016-06-09 11:17:10 -0700 | [diff] [blame] | 21 | import android.annotation.NonNull; |
| 22 | import android.annotation.Nullable; |
Dianne Hackborn | 69c6adc | 2015-06-02 10:52:59 -0700 | [diff] [blame] | 23 | import android.app.assist.AssistContent; |
| 24 | import android.app.assist.AssistStructure; |
Christopher Tate | 4528186 | 2010-03-05 15:46:30 -0800 | [diff] [blame] | 25 | import android.app.backup.BackupAgent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 26 | import android.content.BroadcastReceiver; |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 27 | import android.content.ComponentCallbacks2; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | import android.content.ComponentName; |
| 29 | import android.content.ContentProvider; |
| 30 | import android.content.Context; |
| 31 | import android.content.IContentProvider; |
| 32 | import android.content.Intent; |
Suchi Amalapurapu | 1ccac75 | 2009-06-12 10:09:58 -0700 | [diff] [blame] | 33 | import android.content.IIntentReceiver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | import android.content.pm.ActivityInfo; |
| 35 | import android.content.pm.ApplicationInfo; |
| 36 | import android.content.pm.IPackageManager; |
| 37 | import android.content.pm.InstrumentationInfo; |
Christopher Tate | 346acb1 | 2012-10-15 19:20:25 -0700 | [diff] [blame] | 38 | import android.content.pm.PackageInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | import android.content.pm.PackageManager; |
Sen Hu | bde7570 | 2010-05-28 01:54:03 -0700 | [diff] [blame] | 40 | import android.content.pm.PackageManager.NameNotFoundException; |
Dianne Hackborn | 3f7c9f2 | 2017-04-04 15:36:33 -0700 | [diff] [blame] | 41 | import android.content.pm.ParceledListSlice; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | import android.content.pm.ProviderInfo; |
| 43 | import android.content.pm.ServiceInfo; |
| 44 | import android.content.res.AssetManager; |
Mitsuru Oshima | ba3ba57 | 2009-07-08 18:49:26 -0700 | [diff] [blame] | 45 | import android.content.res.CompatibilityInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 | import android.content.res.Configuration; |
| 47 | import android.content.res.Resources; |
Alan Viverette | e54d245 | 2015-05-06 10:41:43 -0700 | [diff] [blame] | 48 | import android.content.res.Resources.Theme; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | import android.database.sqlite.SQLiteDatabase; |
| 50 | import android.database.sqlite.SQLiteDebug; |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 51 | import android.database.sqlite.SQLiteDebug.DbStats; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | import android.graphics.Bitmap; |
| 53 | import android.graphics.Canvas; |
Clara Bayarri | ff22161 | 2017-03-15 17:27:31 +0000 | [diff] [blame] | 54 | import android.graphics.Typeface; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 55 | import android.hardware.display.DisplayManagerGlobal; |
Paul Jensen | e0bef71 | 2014-12-10 15:12:18 -0500 | [diff] [blame] | 56 | import android.net.ConnectivityManager; |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 57 | import android.net.IConnectivityManager; |
Paul Jensen | e0bef71 | 2014-12-10 15:12:18 -0500 | [diff] [blame] | 58 | import android.net.Network; |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 59 | import android.net.Proxy; |
Jason Monk | 207900c | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 60 | import android.net.ProxyInfo; |
Jason Monk | 83520b9 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 61 | import android.net.Uri; |
Joe Onorato | d630f10 | 2011-03-17 18:42:26 -0700 | [diff] [blame] | 62 | import android.os.AsyncTask; |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 63 | import android.os.Binder; |
Jeff Sharkey | 344744b | 2016-01-28 19:03:30 -0700 | [diff] [blame] | 64 | import android.os.Build; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 65 | import android.os.Bundle; |
| 66 | import android.os.Debug; |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 67 | import android.os.DropBoxManager; |
Jeff Sharkey | b049e21 | 2012-09-07 23:16:01 -0700 | [diff] [blame] | 68 | import android.os.Environment; |
Jesse Hall | b12249b | 2016-12-12 12:53:02 -0800 | [diff] [blame] | 69 | import android.os.GraphicsEnvironment; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 70 | import android.os.Handler; |
| 71 | import android.os.IBinder; |
Adam Lesinski | b61e405 | 2016-05-19 18:23:05 -0700 | [diff] [blame] | 72 | import android.os.LocaleList; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 73 | import android.os.Looper; |
| 74 | import android.os.Message; |
| 75 | import android.os.MessageQueue; |
Dianne Hackborn | fabb70b | 2014-11-11 12:22:36 -0800 | [diff] [blame] | 76 | import android.os.Parcel; |
Dianne Hackborn | 9c8dd55 | 2009-06-23 19:22:52 -0700 | [diff] [blame] | 77 | import android.os.ParcelFileDescriptor; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 78 | import android.os.PersistableBundle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 79 | import android.os.Process; |
| 80 | import android.os.RemoteException; |
| 81 | import android.os.ServiceManager; |
Brad Fitzpatrick | 438d059 | 2010-06-10 12:19:19 -0700 | [diff] [blame] | 82 | import android.os.StrictMode; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 83 | import android.os.SystemClock; |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 84 | import android.os.SystemProperties; |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 85 | import android.os.Trace; |
Jeff Sharkey | 369f509 | 2016-02-29 11:16:21 -0700 | [diff] [blame] | 86 | import android.os.TransactionTooLargeException; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 87 | import android.os.UserHandle; |
Jeff Sharkey | 0a17db1 | 2016-11-04 11:23:46 -0600 | [diff] [blame] | 88 | import android.provider.BlockedNumberContract; |
| 89 | import android.provider.CalendarContract; |
| 90 | import android.provider.CallLog; |
| 91 | import android.provider.ContactsContract; |
| 92 | import android.provider.Downloads; |
Narayan Kamath | ccb2a086 | 2013-12-19 14:49:36 +0000 | [diff] [blame] | 93 | import android.provider.Settings; |
Chad Brubaker | c72875b | 2016-04-27 16:35:11 -0700 | [diff] [blame] | 94 | import android.security.NetworkSecurityPolicy; |
Chad Brubaker | 78d4712 | 2015-11-17 22:26:58 -0800 | [diff] [blame] | 95 | import android.security.net.config.NetworkSecurityConfigProvider; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 96 | import android.util.AndroidRuntimeException; |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 97 | import android.util.ArrayMap; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 98 | import android.util.DisplayMetrics; |
| 99 | import android.util.EventLog; |
| 100 | import android.util.Log; |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 101 | import android.util.LogPrinter; |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 102 | import android.util.Pair; |
Jeff Brown | 6754ba2 | 2011-12-14 20:20:01 -0800 | [diff] [blame] | 103 | import android.util.PrintWriterPrinter; |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 104 | import android.util.Slog; |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 105 | import android.util.SparseIntArray; |
Adam Powell | 1487466 | 2013-07-18 19:42:41 -0700 | [diff] [blame] | 106 | import android.util.SuperNotCalledException; |
Adam Lesinski | 3ad1b48 | 2016-04-01 16:41:41 -0700 | [diff] [blame] | 107 | import android.view.ContextThemeWrapper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 108 | import android.view.Display; |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 109 | import android.view.ThreadedRenderer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 110 | import android.view.View; |
| 111 | import android.view.ViewDebug; |
| 112 | import android.view.ViewManager; |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 113 | import android.view.ViewRootImpl; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 114 | import android.view.Window; |
| 115 | import android.view.WindowManager; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 116 | import android.view.WindowManagerGlobal; |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 117 | import android.renderscript.RenderScriptCacheDir; |
Richard Uhler | 2c03619 | 2016-09-14 09:48:31 +0100 | [diff] [blame] | 118 | import android.webkit.WebView; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 119 | |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 120 | import com.android.internal.annotations.GuardedBy; |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 121 | import com.android.internal.app.IVoiceInteractor; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 122 | import com.android.internal.content.ReferrerIntent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 123 | import com.android.internal.os.BinderInternal; |
| 124 | import com.android.internal.os.RuntimeInit; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 125 | import com.android.internal.os.SamplingProfilerIntegration; |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 126 | import com.android.internal.os.SomeArgs; |
Jeff Sharkey | 3e19589 | 2016-03-05 19:48:59 -0700 | [diff] [blame] | 127 | import com.android.internal.util.ArrayUtils; |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 128 | import com.android.internal.util.FastPrintWriter; |
Kenny Root | 12e7522 | 2013-04-23 22:34:24 -0700 | [diff] [blame] | 129 | import com.android.org.conscrypt.OpenSSLSocketImpl; |
Robin Lee | 3d076af | 2014-04-25 14:57:49 +0100 | [diff] [blame] | 130 | import com.android.org.conscrypt.TrustedCertificateStore; |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 131 | import com.google.android.collect.Lists; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 132 | |
| 133 | import java.io.File; |
| 134 | import java.io.FileDescriptor; |
| 135 | import java.io.FileOutputStream; |
Dianne Hackborn | 9c8dd55 | 2009-06-23 19:22:52 -0700 | [diff] [blame] | 136 | import java.io.IOException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 137 | import java.io.PrintWriter; |
| 138 | import java.lang.ref.WeakReference; |
Svet Ganov | 37e4327 | 2016-09-09 16:01:32 -0700 | [diff] [blame] | 139 | import java.lang.reflect.Field; |
Robert Greenwalt | 03595d0 | 2010-11-02 14:08:23 -0700 | [diff] [blame] | 140 | import java.net.InetAddress; |
Narayan Kamath | ccb2a086 | 2013-12-19 14:49:36 +0000 | [diff] [blame] | 141 | import java.text.DateFormat; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 142 | import java.util.ArrayList; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 143 | import java.util.List; |
Adam Lesinski | b61e405 | 2016-05-19 18:23:05 -0700 | [diff] [blame] | 144 | import java.util.Locale; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 145 | import java.util.Map; |
Kenny Root | e6585b3 | 2013-12-13 12:00:26 -0800 | [diff] [blame] | 146 | import java.util.Objects; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 147 | import java.util.TimeZone; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 148 | |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 149 | import libcore.io.DropBox; |
Geremy Condra | 69689a7 | 2012-09-11 16:57:17 -0700 | [diff] [blame] | 150 | import libcore.io.EventLogger; |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 151 | import libcore.io.IoUtils; |
Paul Jensen | e401d17 | 2014-09-12 10:47:39 -0400 | [diff] [blame] | 152 | import libcore.net.event.NetworkEventDispatcher; |
Calin Juravle | 37dfc8e | 2017-03-13 19:02:32 -0700 | [diff] [blame] | 153 | import dalvik.system.BaseDexClassLoader; |
Brad Fitzpatrick | 4d9e6d2 | 2010-11-15 08:49:51 -0800 | [diff] [blame] | 154 | import dalvik.system.CloseGuard; |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 155 | import dalvik.system.VMDebug; |
Mathieu Chartier | 1e37090 | 2013-07-18 10:58:01 -0700 | [diff] [blame] | 156 | import dalvik.system.VMRuntime; |
Man Cao | cfa78b2 | 2015-06-11 20:14:34 -0700 | [diff] [blame] | 157 | import org.apache.harmony.dalvik.ddmc.DdmVmInternal; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 158 | |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 159 | final class RemoteServiceException extends AndroidRuntimeException { |
| 160 | public RemoteServiceException(String msg) { |
| 161 | super(msg); |
| 162 | } |
| 163 | } |
| 164 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 165 | /** |
| 166 | * This manages the execution of the main thread in an |
| 167 | * application process, scheduling and executing activities, |
| 168 | * broadcasts, and other operations on it as the activity |
| 169 | * manager requests. |
| 170 | * |
| 171 | * {@hide} |
| 172 | */ |
| 173 | public final class ActivityThread { |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 174 | /** @hide */ |
| 175 | public static final String TAG = "ActivityThread"; |
Jim Miller | 0b2a6d0 | 2010-07-13 18:01:29 -0700 | [diff] [blame] | 176 | 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] | 177 | static final boolean localLOGV = false; |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 178 | static final boolean DEBUG_MESSAGES = false; |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 179 | /** @hide */ |
| 180 | public static final boolean DEBUG_BROADCAST = false; |
Chris Tate | 8a7dc17 | 2009-03-24 20:11:42 -0700 | [diff] [blame] | 181 | private static final boolean DEBUG_RESULTS = false; |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 182 | private static final boolean DEBUG_BACKUP = false; |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 183 | public static final boolean DEBUG_CONFIGURATION = false; |
Dianne Hackborn | a0c283e | 2012-02-09 10:47:01 -0800 | [diff] [blame] | 184 | private static final boolean DEBUG_SERVICE = false; |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 185 | private static final boolean DEBUG_MEMORY_TRIM = false; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 186 | private static final boolean DEBUG_PROVIDER = false; |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 187 | private static final boolean DEBUG_ORDER = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 188 | 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] | 189 | private static final int SQLITE_MEM_RELEASED_EVENT_LOG_TAG = 75003; |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 190 | private static final int LOG_AM_ON_PAUSE_CALLED = 30021; |
| 191 | private static final int LOG_AM_ON_RESUME_CALLED = 30022; |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 192 | 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] | 193 | |
Dianne Hackborn | 455625e | 2015-01-21 09:55:13 -0800 | [diff] [blame] | 194 | /** Type for IActivityManager.serviceDoneExecuting: anonymous operation */ |
| 195 | public static final int SERVICE_DONE_EXECUTING_ANON = 0; |
| 196 | /** Type for IActivityManager.serviceDoneExecuting: done with an onStart call */ |
| 197 | public static final int SERVICE_DONE_EXECUTING_START = 1; |
| 198 | /** Type for IActivityManager.serviceDoneExecuting: done stopping (destroying) service */ |
| 199 | public static final int SERVICE_DONE_EXECUTING_STOP = 2; |
| 200 | |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 201 | // Details for pausing activity. |
| 202 | private static final int USER_LEAVING = 1; |
| 203 | private static final int DONT_REPORT = 2; |
| 204 | |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 205 | // Whether to invoke an activity callback after delivering new configuration. |
| 206 | private static final boolean REPORT_TO_ACTIVITY = true; |
| 207 | |
Sudheer Shanka | 84a4895 | 2017-03-08 18:19:01 -0800 | [diff] [blame] | 208 | /** |
| 209 | * Denotes an invalid sequence number corresponding to a process state change. |
| 210 | */ |
| 211 | public static final long INVALID_PROC_STATE_SEQ = -1; |
| 212 | |
| 213 | private final Object mNetworkPolicyLock = new Object(); |
| 214 | |
| 215 | /** |
| 216 | * Denotes the sequence number of the process state change for which the main thread needs |
| 217 | * to block until the network rules are updated for it. |
| 218 | * |
| 219 | * Value of {@link #INVALID_PROC_STATE_SEQ} indicates there is no need for blocking. |
| 220 | */ |
| 221 | @GuardedBy("mNetworkPolicyLock") |
| 222 | private long mNetworkBlockSeq = INVALID_PROC_STATE_SEQ; |
| 223 | |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 224 | private ContextImpl mSystemContext; |
Adam Lesinski | a82b626 | 2017-03-21 16:56:17 -0700 | [diff] [blame] | 225 | private ContextImpl mSystemUiContext; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 226 | |
Jeff Sharkey | d589663 | 2016-03-04 16:16:00 -0700 | [diff] [blame] | 227 | static volatile IPackageManager sPackageManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 228 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 229 | final ApplicationThread mAppThread = new ApplicationThread(); |
| 230 | final Looper mLooper = Looper.myLooper(); |
| 231 | final H mH = new H(); |
Dianne Hackborn | 782d498 | 2015-07-08 17:36:37 -0700 | [diff] [blame] | 232 | final ArrayMap<IBinder, ActivityClientRecord> mActivities = new ArrayMap<>(); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 233 | // List of new activities (via ActivityRecord.nextIdle) that should |
| 234 | // be reported when next we idle. |
| 235 | ActivityClientRecord mNewActivities = null; |
| 236 | // Number of activities that are currently visible on-screen. |
| 237 | int mNumVisibleActivities = 0; |
Amith Yamasani | 4f128e4 | 2016-05-10 11:44:12 -0700 | [diff] [blame] | 238 | ArrayList<WeakReference<AssistStructure>> mLastAssistStructures = new ArrayList<>(); |
| 239 | private int mLastSessionId; |
Dianne Hackborn | 782d498 | 2015-07-08 17:36:37 -0700 | [diff] [blame] | 240 | final ArrayMap<IBinder, Service> mServices = new ArrayMap<>(); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 241 | AppBindData mBoundApplication; |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 242 | Profiler mProfiler; |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 243 | int mCurDefaultDisplayDpi; |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 244 | boolean mDensityCompatMode; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 245 | Configuration mConfiguration; |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 246 | Configuration mCompatConfiguration; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 247 | Application mInitialApplication; |
| 248 | final ArrayList<Application> mAllApplications |
| 249 | = new ArrayList<Application>(); |
| 250 | // set of instantiated backup agents, keyed by package name |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 251 | final ArrayMap<String, BackupAgent> mBackupAgents = new ArrayMap<String, BackupAgent>(); |
Jeff Sharkey | 66a017b | 2013-01-17 18:18:22 -0800 | [diff] [blame] | 252 | /** Reference to singleton {@link ActivityThread} */ |
Jeff Sharkey | d589663 | 2016-03-04 16:16:00 -0700 | [diff] [blame] | 253 | private static volatile ActivityThread sCurrentActivityThread; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 254 | Instrumentation mInstrumentation; |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 255 | String mInstrumentationPackageName = null; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 256 | String mInstrumentationAppDir = null; |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 257 | String[] mInstrumentationSplitAppDirs = null; |
| 258 | String mInstrumentationLibDir = null; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 259 | String mInstrumentedAppDir = null; |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 260 | String[] mInstrumentedSplitAppDirs = null; |
| 261 | String mInstrumentedLibDir = null; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 262 | boolean mSystemThread = false; |
| 263 | boolean mJitEnabled = false; |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 264 | boolean mSomeActivitiesChanged = false; |
Chong Zhang | 4951f9d | 2016-06-23 13:15:08 -0700 | [diff] [blame] | 265 | boolean mUpdatingSystemConfig = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 266 | |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 267 | // These can be accessed by multiple threads; mResourcesManager is the lock. |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 268 | // XXX For now we keep around information about all packages we have |
| 269 | // seen, not removing entries from this map. |
Dianne Hackborn | 1fbee79 | 2011-11-30 11:29:58 -0800 | [diff] [blame] | 270 | // NOTE: The activity and window managers need to call in to |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 271 | // ActivityThread to do things like update resource configurations, |
Dianne Hackborn | 1fbee79 | 2011-11-30 11:29:58 -0800 | [diff] [blame] | 272 | // which means this lock gets held while the activity and window managers |
| 273 | // holds their own lock. Thus you MUST NEVER call back into the activity manager |
| 274 | // 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] | 275 | // 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] | 276 | @GuardedBy("mResourcesManager") |
| 277 | final ArrayMap<String, WeakReference<LoadedApk>> mPackages = new ArrayMap<>(); |
| 278 | @GuardedBy("mResourcesManager") |
| 279 | final ArrayMap<String, WeakReference<LoadedApk>> mResourcePackages = new ArrayMap<>(); |
| 280 | @GuardedBy("mResourcesManager") |
| 281 | final ArrayList<ActivityClientRecord> mRelaunchingActivities = new ArrayList<>(); |
| 282 | @GuardedBy("mResourcesManager") |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 283 | Configuration mPendingConfiguration = null; |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 284 | // Because we merge activity relaunch operations we can't depend on the ordering provided by |
| 285 | // the handler messages. We need to introduce secondary ordering mechanism, which will allow |
| 286 | // us to drop certain events, if we know that they happened before relaunch we already executed. |
| 287 | // This represents the order of receiving the request from AM. |
| 288 | @GuardedBy("mResourcesManager") |
| 289 | int mLifecycleSeq = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 290 | |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 291 | private final ResourcesManager mResourcesManager; |
| 292 | |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 293 | private static final class ProviderKey { |
| 294 | final String authority; |
| 295 | final int userId; |
| 296 | |
| 297 | public ProviderKey(String authority, int userId) { |
| 298 | this.authority = authority; |
| 299 | this.userId = userId; |
| 300 | } |
| 301 | |
| 302 | @Override |
| 303 | public boolean equals(Object o) { |
| 304 | if (o instanceof ProviderKey) { |
| 305 | final ProviderKey other = (ProviderKey) o; |
Kenny Root | e6585b3 | 2013-12-13 12:00:26 -0800 | [diff] [blame] | 306 | return Objects.equals(authority, other.authority) && userId == other.userId; |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 307 | } |
| 308 | return false; |
| 309 | } |
| 310 | |
| 311 | @Override |
| 312 | public int hashCode() { |
| 313 | return ((authority != null) ? authority.hashCode() : 0) ^ userId; |
| 314 | } |
| 315 | } |
| 316 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 317 | // The lock of mProviderMap protects the following variables. |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 318 | final ArrayMap<ProviderKey, ProviderClientRecord> mProviderMap |
| 319 | = new ArrayMap<ProviderKey, ProviderClientRecord>(); |
| 320 | final ArrayMap<IBinder, ProviderRefCount> mProviderRefCountMap |
| 321 | = new ArrayMap<IBinder, ProviderRefCount>(); |
| 322 | final ArrayMap<IBinder, ProviderClientRecord> mLocalProviders |
| 323 | = new ArrayMap<IBinder, ProviderClientRecord>(); |
| 324 | final ArrayMap<ComponentName, ProviderClientRecord> mLocalProvidersByName |
| 325 | = new ArrayMap<ComponentName, ProviderClientRecord>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 326 | |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 327 | final ArrayMap<Activity, ArrayList<OnActivityPausedListener>> mOnPauseListeners |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 328 | = new ArrayMap<Activity, ArrayList<OnActivityPausedListener>>(); |
Jeff Hamilton | 52d3203 | 2011-01-08 15:31:26 -0600 | [diff] [blame] | 329 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 330 | final GcIdler mGcIdler = new GcIdler(); |
| 331 | boolean mGcIdlerScheduled = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 332 | |
Jeff Sharkey | d589663 | 2016-03-04 16:16:00 -0700 | [diff] [blame] | 333 | static volatile Handler sMainThreadHandler; // set once in main() |
Brad Fitzpatrick | 333b8cb | 2010-08-26 12:04:57 -0700 | [diff] [blame] | 334 | |
Svetoslav Ganov | 9aa597e | 2011-03-03 18:17:41 -0800 | [diff] [blame] | 335 | Bundle mCoreSettings = null; |
| 336 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 337 | static final class ActivityClientRecord { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 338 | IBinder token; |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 339 | int ident; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 340 | Intent intent; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 341 | String referrer; |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 342 | IVoiceInteractor voiceInteractor; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 343 | Bundle state; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 344 | PersistableBundle persistentState; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 345 | Activity activity; |
| 346 | Window window; |
| 347 | Activity parent; |
| 348 | String embeddedID; |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 349 | Activity.NonConfigurationInstances lastNonConfigurationInstances; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 350 | boolean paused; |
| 351 | boolean stopped; |
| 352 | boolean hideForNow; |
| 353 | Configuration newConfig; |
Dianne Hackborn | e88846e | 2009-09-30 21:34:25 -0700 | [diff] [blame] | 354 | Configuration createdConfig; |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 355 | Configuration overrideConfig; |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 356 | // Used for consolidating configs before sending on to Activity. |
| 357 | private Configuration tmpConfig = new Configuration(); |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 358 | // Callback used for updating activity override config. |
| 359 | ViewRootImpl.ActivityConfigCallback configCallback; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 360 | ActivityClientRecord nextIdle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 361 | |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 362 | ProfilerInfo profilerInfo; |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 363 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 364 | ActivityInfo activityInfo; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 365 | CompatibilityInfo compatInfo; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 366 | LoadedApk packageInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 367 | |
| 368 | List<ResultInfo> pendingResults; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 369 | List<ReferrerIntent> pendingIntents; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 370 | |
| 371 | boolean startsNotResumed; |
| 372 | boolean isForward; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 373 | int pendingConfigChanges; |
| 374 | boolean onlyLocalRequest; |
| 375 | |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 376 | Window mPendingRemoveWindow; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 377 | WindowManager mPendingRemoveWindowManager; |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 378 | boolean mPreserveWindow; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 379 | |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 380 | // Set for relaunch requests, indicates the order number of the relaunch operation, so it |
| 381 | // can be compared with other lifecycle operations. |
| 382 | int relaunchSeq = 0; |
| 383 | |
| 384 | // Can only be accessed from the UI thread. This represents the latest processed message |
| 385 | // that is related to lifecycle events/ |
| 386 | int lastProcessedSeq = 0; |
| 387 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 388 | ActivityClientRecord() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 389 | parent = null; |
| 390 | embeddedID = null; |
| 391 | paused = false; |
| 392 | stopped = false; |
| 393 | hideForNow = false; |
| 394 | nextIdle = null; |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 395 | configCallback = (Configuration overrideConfig, int newDisplayId) -> { |
| 396 | if (activity == null) { |
| 397 | throw new IllegalStateException( |
| 398 | "Received config update for non-existing activity"); |
| 399 | } |
| 400 | activity.mMainThread.handleActivityConfigurationChanged( |
| 401 | new ActivityConfigChangeData(token, overrideConfig), newDisplayId); |
| 402 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 403 | } |
| 404 | |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 405 | public boolean isPreHoneycomb() { |
| 406 | if (activity != null) { |
| 407 | return activity.getApplicationInfo().targetSdkVersion |
| 408 | < android.os.Build.VERSION_CODES.HONEYCOMB; |
| 409 | } |
| 410 | return false; |
| 411 | } |
| 412 | |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 413 | public boolean isPersistable() { |
Craig Mautner | 43e52ed | 2014-06-16 17:18:52 -0700 | [diff] [blame] | 414 | return activityInfo.persistableMode == ActivityInfo.PERSIST_ACROSS_REBOOTS; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 415 | } |
| 416 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 417 | public String toString() { |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 418 | ComponentName componentName = intent != null ? intent.getComponent() : null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 419 | return "ActivityRecord{" |
| 420 | + Integer.toHexString(System.identityHashCode(this)) |
| 421 | + " token=" + token + " " + (componentName == null |
| 422 | ? "no component name" : componentName.toShortString()) |
| 423 | + "}"; |
| 424 | } |
Andrii Kulian | 58178f2 | 2016-03-16 13:44:56 -0700 | [diff] [blame] | 425 | |
| 426 | public String getStateString() { |
| 427 | StringBuilder sb = new StringBuilder(); |
| 428 | sb.append("ActivityClientRecord{"); |
| 429 | sb.append("paused=").append(paused); |
| 430 | sb.append(", stopped=").append(stopped); |
| 431 | sb.append(", hideForNow=").append(hideForNow); |
| 432 | sb.append(", startsNotResumed=").append(startsNotResumed); |
| 433 | sb.append(", isForward=").append(isForward); |
| 434 | sb.append(", pendingConfigChanges=").append(pendingConfigChanges); |
| 435 | sb.append(", onlyLocalRequest=").append(onlyLocalRequest); |
| 436 | sb.append(", preserveWindow=").append(mPreserveWindow); |
| 437 | if (activity != null) { |
| 438 | sb.append(", Activity{"); |
| 439 | sb.append("resumed=").append(activity.mResumed); |
| 440 | sb.append(", stopped=").append(activity.mStopped); |
| 441 | sb.append(", finished=").append(activity.isFinishing()); |
| 442 | sb.append(", destroyed=").append(activity.isDestroyed()); |
| 443 | sb.append(", startedActivity=").append(activity.mStartedActivity); |
| 444 | sb.append(", temporaryPause=").append(activity.mTemporaryPause); |
| 445 | sb.append(", changingConfigurations=").append(activity.mChangingConfigurations); |
| 446 | sb.append(", visibleBehind=").append(activity.mVisibleBehind); |
| 447 | sb.append("}"); |
| 448 | } |
| 449 | sb.append("}"); |
| 450 | return sb.toString(); |
| 451 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 452 | } |
| 453 | |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 454 | final class ProviderClientRecord { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 455 | final String[] mNames; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 456 | final IContentProvider mProvider; |
| 457 | final ContentProvider mLocalProvider; |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 458 | final ContentProviderHolder mHolder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 459 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 460 | ProviderClientRecord(String[] names, IContentProvider provider, |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 461 | ContentProvider localProvider, ContentProviderHolder holder) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 462 | mNames = names; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 463 | mProvider = provider; |
| 464 | mLocalProvider = localProvider; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 465 | mHolder = holder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 466 | } |
| 467 | } |
| 468 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 469 | static final class NewIntentData { |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 470 | List<ReferrerIntent> intents; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 471 | IBinder token; |
Wale Ogunwale | 826c706 | 2016-09-13 08:25:54 -0700 | [diff] [blame] | 472 | boolean andPause; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 473 | public String toString() { |
Wale Ogunwale | 826c706 | 2016-09-13 08:25:54 -0700 | [diff] [blame] | 474 | return "NewIntentData{intents=" + intents + " token=" + token |
| 475 | + " andPause=" + andPause +"}"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 476 | } |
| 477 | } |
| 478 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 479 | static final class ReceiverData extends BroadcastReceiver.PendingResult { |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 480 | public ReceiverData(Intent intent, int resultCode, String resultData, Bundle resultExtras, |
Dianne Hackborn | 20e8098 | 2012-08-31 19:00:44 -0700 | [diff] [blame] | 481 | boolean ordered, boolean sticky, IBinder token, int sendingUser) { |
| 482 | super(resultCode, resultData, resultExtras, TYPE_COMPONENT, ordered, sticky, |
riddle_hsu | 1f5ac4d | 2015-01-03 15:38:21 +0800 | [diff] [blame] | 483 | token, sendingUser, intent.getFlags()); |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 484 | this.intent = intent; |
| 485 | } |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 486 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 487 | Intent intent; |
| 488 | ActivityInfo info; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 489 | CompatibilityInfo compatInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 490 | public String toString() { |
| 491 | return "ReceiverData{intent=" + intent + " packageName=" + |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 492 | info.packageName + " resultCode=" + getResultCode() |
| 493 | + " resultData=" + getResultData() + " resultExtras=" |
| 494 | + getResultExtras(false) + "}"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 495 | } |
| 496 | } |
| 497 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 498 | static final class CreateBackupAgentData { |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 499 | ApplicationInfo appInfo; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 500 | CompatibilityInfo compatInfo; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 501 | int backupMode; |
| 502 | public String toString() { |
| 503 | return "CreateBackupAgentData{appInfo=" + appInfo |
| 504 | + " backupAgent=" + appInfo.backupAgentName |
| 505 | + " mode=" + backupMode + "}"; |
| 506 | } |
| 507 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 508 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 509 | static final class CreateServiceData { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 510 | IBinder token; |
| 511 | ServiceInfo info; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 512 | CompatibilityInfo compatInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 513 | Intent intent; |
| 514 | public String toString() { |
| 515 | return "CreateServiceData{token=" + token + " className=" |
| 516 | + info.name + " packageName=" + info.packageName |
| 517 | + " intent=" + intent + "}"; |
| 518 | } |
| 519 | } |
| 520 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 521 | static final class BindServiceData { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 522 | IBinder token; |
| 523 | Intent intent; |
| 524 | boolean rebind; |
| 525 | public String toString() { |
| 526 | return "BindServiceData{token=" + token + " intent=" + intent + "}"; |
| 527 | } |
| 528 | } |
| 529 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 530 | static final class ServiceArgsData { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 531 | IBinder token; |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 532 | boolean taskRemoved; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 533 | int startId; |
Dianne Hackborn | f6f9f2d | 2009-08-21 16:26:03 -0700 | [diff] [blame] | 534 | int flags; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 535 | Intent args; |
| 536 | public String toString() { |
| 537 | return "ServiceArgsData{token=" + token + " startId=" + startId |
| 538 | + " args=" + args + "}"; |
| 539 | } |
| 540 | } |
| 541 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 542 | static final class AppBindData { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 543 | LoadedApk info; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 544 | String processName; |
| 545 | ApplicationInfo appInfo; |
| 546 | List<ProviderInfo> providers; |
| 547 | ComponentName instrumentationName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 548 | Bundle instrumentationArgs; |
| 549 | IInstrumentationWatcher instrumentationWatcher; |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 550 | IUiAutomationConnection instrumentationUiAutomationConnection; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 551 | int debugMode; |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 552 | boolean enableBinderTracking; |
Man Cao | cfa78b2 | 2015-06-11 20:14:34 -0700 | [diff] [blame] | 553 | boolean trackAllocation; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 554 | boolean restrictedBackupMode; |
Dianne Hackborn | 5d927c2 | 2011-09-02 12:22:18 -0700 | [diff] [blame] | 555 | boolean persistent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 556 | Configuration config; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 557 | CompatibilityInfo compatInfo; |
Svet Ganov | 37e4327 | 2016-09-09 16:01:32 -0700 | [diff] [blame] | 558 | String buildSerial; |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 559 | |
| 560 | /** Initial values for {@link Profiler}. */ |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 561 | ProfilerInfo initProfilerInfo; |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 562 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 563 | public String toString() { |
| 564 | return "AppBindData{appInfo=" + appInfo + "}"; |
| 565 | } |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 566 | } |
| 567 | |
| 568 | static final class Profiler { |
| 569 | String profileFile; |
| 570 | ParcelFileDescriptor profileFd; |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 571 | int samplingInterval; |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 572 | boolean autoStopProfiler; |
Shukang Zhou | 6ffd4f9 | 2017-01-25 16:07:57 -0800 | [diff] [blame] | 573 | boolean streamingOutput; |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 574 | boolean profiling; |
| 575 | boolean handlingProfiling; |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 576 | public void setProfiler(ProfilerInfo profilerInfo) { |
| 577 | ParcelFileDescriptor fd = profilerInfo.profileFd; |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 578 | if (profiling) { |
| 579 | if (fd != null) { |
| 580 | try { |
| 581 | fd.close(); |
| 582 | } catch (IOException e) { |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 583 | // Ignore |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 584 | } |
| 585 | } |
| 586 | return; |
| 587 | } |
| 588 | if (profileFd != null) { |
| 589 | try { |
| 590 | profileFd.close(); |
| 591 | } catch (IOException e) { |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 592 | // Ignore |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 593 | } |
| 594 | } |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 595 | profileFile = profilerInfo.profileFile; |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 596 | profileFd = fd; |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 597 | samplingInterval = profilerInfo.samplingInterval; |
| 598 | autoStopProfiler = profilerInfo.autoStopProfiler; |
Shukang Zhou | 6ffd4f9 | 2017-01-25 16:07:57 -0800 | [diff] [blame] | 599 | streamingOutput = profilerInfo.streamingOutput; |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 600 | } |
| 601 | public void startProfiling() { |
| 602 | if (profileFd == null || profiling) { |
| 603 | return; |
| 604 | } |
| 605 | try { |
Andreas Gampe | eff0639 | 2016-05-10 12:51:45 -0700 | [diff] [blame] | 606 | int bufferSize = SystemProperties.getInt("debug.traceview-buffer-size-mb", 8); |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 607 | VMDebug.startMethodTracing(profileFile, profileFd.getFileDescriptor(), |
Shukang Zhou | 6ffd4f9 | 2017-01-25 16:07:57 -0800 | [diff] [blame] | 608 | bufferSize * 1024 * 1024, 0, samplingInterval != 0, samplingInterval, |
| 609 | streamingOutput); |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 610 | profiling = true; |
| 611 | } catch (RuntimeException e) { |
| 612 | Slog.w(TAG, "Profiling failed on path " + profileFile); |
| 613 | try { |
| 614 | profileFd.close(); |
| 615 | profileFd = null; |
| 616 | } catch (IOException e2) { |
| 617 | Slog.w(TAG, "Failure closing profile fd", e2); |
| 618 | } |
| 619 | } |
| 620 | } |
| 621 | public void stopProfiling() { |
| 622 | if (profiling) { |
| 623 | profiling = false; |
| 624 | Debug.stopMethodTracing(); |
| 625 | if (profileFd != null) { |
| 626 | try { |
| 627 | profileFd.close(); |
| 628 | } catch (IOException e) { |
| 629 | } |
| 630 | } |
| 631 | profileFd = null; |
| 632 | profileFile = null; |
| 633 | } |
| 634 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 635 | } |
| 636 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 637 | static final class DumpComponentInfo { |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 638 | ParcelFileDescriptor fd; |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 639 | IBinder token; |
Dianne Hackborn | 30d7189 | 2010-12-11 10:37:55 -0800 | [diff] [blame] | 640 | String prefix; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 641 | String[] args; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 642 | } |
| 643 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 644 | static final class ResultData { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 645 | IBinder token; |
| 646 | List<ResultInfo> results; |
| 647 | public String toString() { |
| 648 | return "ResultData{token=" + token + " results" + results + "}"; |
| 649 | } |
| 650 | } |
| 651 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 652 | static final class ContextCleanupInfo { |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 653 | ContextImpl context; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 654 | String what; |
| 655 | String who; |
| 656 | } |
| 657 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 658 | static final class DumpHeapData { |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 659 | String path; |
| 660 | ParcelFileDescriptor fd; |
| 661 | } |
| 662 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 663 | static final class UpdateCompatibilityData { |
| 664 | String pkg; |
| 665 | CompatibilityInfo info; |
| 666 | } |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 667 | |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 668 | static final class RequestAssistContextExtras { |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 669 | IBinder activityToken; |
| 670 | IBinder requestToken; |
| 671 | int requestType; |
Amith Yamasani | 4f128e4 | 2016-05-10 11:44:12 -0700 | [diff] [blame] | 672 | int sessionId; |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 673 | } |
Anwar Ghuloum | 3a8ce1b | 2013-04-26 16:18:28 -0700 | [diff] [blame] | 674 | |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 675 | static final class ActivityConfigChangeData { |
| 676 | final IBinder activityToken; |
| 677 | final Configuration overrideConfig; |
| 678 | public ActivityConfigChangeData(IBinder token, Configuration config) { |
| 679 | activityToken = token; |
| 680 | overrideConfig = config; |
| 681 | } |
| 682 | } |
| 683 | |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 684 | private class ApplicationThread extends IApplicationThread.Stub { |
Vasu Nori | 3c7131f | 2010-09-21 14:36:57 -0700 | [diff] [blame] | 685 | private static final String DB_INFO_FORMAT = " %8s %8s %14s %14s %s"; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 686 | |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 687 | private int mLastProcessState = -1; |
| 688 | |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 689 | private void updatePendingConfiguration(Configuration config) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 690 | synchronized (mResourcesManager) { |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 691 | if (mPendingConfiguration == null || |
| 692 | mPendingConfiguration.isOtherSeqNewer(config)) { |
| 693 | mPendingConfiguration = config; |
| 694 | } |
| 695 | } |
| 696 | } |
| 697 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 698 | public final void schedulePauseActivity(IBinder token, boolean finished, |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 699 | boolean userLeaving, int configChanges, boolean dontReport) { |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 700 | int seq = getLifecycleSeq(); |
| 701 | if (DEBUG_ORDER) Slog.d(TAG, "pauseActivity " + ActivityThread.this |
| 702 | + " operation received seq: " + seq); |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 703 | sendMessage( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 704 | finished ? H.PAUSE_ACTIVITY_FINISHING : H.PAUSE_ACTIVITY, |
| 705 | token, |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 706 | (userLeaving ? USER_LEAVING : 0) | (dontReport ? DONT_REPORT : 0), |
| 707 | configChanges, |
| 708 | seq); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 709 | } |
| 710 | |
| 711 | public final void scheduleStopActivity(IBinder token, boolean showWindow, |
| 712 | int configChanges) { |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 713 | int seq = getLifecycleSeq(); |
| 714 | if (DEBUG_ORDER) Slog.d(TAG, "stopActivity " + ActivityThread.this |
| 715 | + " operation received seq: " + seq); |
| 716 | sendMessage( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 717 | showWindow ? H.STOP_ACTIVITY_SHOW : H.STOP_ACTIVITY_HIDE, |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 718 | token, 0, configChanges, seq); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 719 | } |
| 720 | |
| 721 | public final void scheduleWindowVisibility(IBinder token, boolean showWindow) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 722 | sendMessage( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 723 | showWindow ? H.SHOW_WINDOW : H.HIDE_WINDOW, |
| 724 | token); |
| 725 | } |
| 726 | |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 727 | public final void scheduleSleeping(IBinder token, boolean sleeping) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 728 | sendMessage(H.SLEEPING, token, sleeping ? 1 : 0); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 729 | } |
| 730 | |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 731 | public final void scheduleResumeActivity(IBinder token, int processState, |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 732 | boolean isForward, Bundle resumeArgs) { |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 733 | int seq = getLifecycleSeq(); |
| 734 | if (DEBUG_ORDER) Slog.d(TAG, "resumeActivity " + ActivityThread.this |
| 735 | + " operation received seq: " + seq); |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 736 | updateProcessState(processState, false); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 737 | sendMessage(H.RESUME_ACTIVITY, token, isForward ? 1 : 0, 0, seq); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 738 | } |
| 739 | |
| 740 | public final void scheduleSendResult(IBinder token, List<ResultInfo> results) { |
| 741 | ResultData res = new ResultData(); |
| 742 | res.token = token; |
| 743 | res.results = results; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 744 | sendMessage(H.SEND_RESULT, res); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 745 | } |
| 746 | |
| 747 | // we use token to identify this activity without having to send the |
| 748 | // activity itself back to the activity manager. (matters more with ipc) |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 749 | @Override |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 750 | public final void scheduleLaunchActivity(Intent intent, IBinder token, int ident, |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 751 | ActivityInfo info, Configuration curConfig, Configuration overrideConfig, |
| 752 | CompatibilityInfo compatInfo, String referrer, IVoiceInteractor voiceInteractor, |
| 753 | int procState, Bundle state, PersistableBundle persistentState, |
| 754 | List<ResultInfo> pendingResults, List<ReferrerIntent> pendingNewIntents, |
| 755 | boolean notResumed, boolean isForward, ProfilerInfo profilerInfo) { |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 756 | |
| 757 | updateProcessState(procState, false); |
| 758 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 759 | ActivityClientRecord r = new ActivityClientRecord(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 760 | |
| 761 | r.token = token; |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 762 | r.ident = ident; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 763 | r.intent = intent; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 764 | r.referrer = referrer; |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 765 | r.voiceInteractor = voiceInteractor; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 766 | r.activityInfo = info; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 767 | r.compatInfo = compatInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 768 | r.state = state; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 769 | r.persistentState = persistentState; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 770 | |
| 771 | r.pendingResults = pendingResults; |
| 772 | r.pendingIntents = pendingNewIntents; |
| 773 | |
| 774 | r.startsNotResumed = notResumed; |
| 775 | r.isForward = isForward; |
| 776 | |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 777 | r.profilerInfo = profilerInfo; |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 778 | |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 779 | r.overrideConfig = overrideConfig; |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 780 | updatePendingConfiguration(curConfig); |
| 781 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 782 | sendMessage(H.LAUNCH_ACTIVITY, r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 783 | } |
| 784 | |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 785 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 786 | public final void scheduleRelaunchActivity(IBinder token, |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 787 | List<ResultInfo> pendingResults, List<ReferrerIntent> pendingNewIntents, |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 788 | int configChanges, boolean notResumed, Configuration config, |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 789 | Configuration overrideConfig, boolean preserveWindow) { |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 790 | requestRelaunchActivity(token, pendingResults, pendingNewIntents, |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 791 | configChanges, notResumed, config, overrideConfig, true, preserveWindow); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 792 | } |
| 793 | |
Wale Ogunwale | 826c706 | 2016-09-13 08:25:54 -0700 | [diff] [blame] | 794 | public final void scheduleNewIntent( |
| 795 | List<ReferrerIntent> intents, IBinder token, boolean andPause) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 796 | NewIntentData data = new NewIntentData(); |
| 797 | data.intents = intents; |
| 798 | data.token = token; |
Wale Ogunwale | 826c706 | 2016-09-13 08:25:54 -0700 | [diff] [blame] | 799 | data.andPause = andPause; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 800 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 801 | sendMessage(H.NEW_INTENT, data); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 802 | } |
| 803 | |
| 804 | public final void scheduleDestroyActivity(IBinder token, boolean finishing, |
| 805 | int configChanges) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 806 | sendMessage(H.DESTROY_ACTIVITY, token, finishing ? 1 : 0, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 807 | configChanges); |
| 808 | } |
| 809 | |
| 810 | public final void scheduleReceiver(Intent intent, ActivityInfo info, |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 811 | CompatibilityInfo compatInfo, int resultCode, String data, Bundle extras, |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 812 | boolean sync, int sendingUser, int processState) { |
| 813 | updateProcessState(processState, false); |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 814 | ReceiverData r = new ReceiverData(intent, resultCode, data, extras, |
Dianne Hackborn | 20e8098 | 2012-08-31 19:00:44 -0700 | [diff] [blame] | 815 | sync, false, mAppThread.asBinder(), sendingUser); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 816 | r.info = info; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 817 | r.compatInfo = compatInfo; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 818 | sendMessage(H.RECEIVER, r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 819 | } |
| 820 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 821 | public final void scheduleCreateBackupAgent(ApplicationInfo app, |
| 822 | CompatibilityInfo compatInfo, int backupMode) { |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 823 | CreateBackupAgentData d = new CreateBackupAgentData(); |
| 824 | d.appInfo = app; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 825 | d.compatInfo = compatInfo; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 826 | d.backupMode = backupMode; |
| 827 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 828 | sendMessage(H.CREATE_BACKUP_AGENT, d); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 829 | } |
| 830 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 831 | public final void scheduleDestroyBackupAgent(ApplicationInfo app, |
| 832 | CompatibilityInfo compatInfo) { |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 833 | CreateBackupAgentData d = new CreateBackupAgentData(); |
| 834 | d.appInfo = app; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 835 | d.compatInfo = compatInfo; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 836 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 837 | sendMessage(H.DESTROY_BACKUP_AGENT, d); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 838 | } |
| 839 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 840 | public final void scheduleCreateService(IBinder token, |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 841 | ServiceInfo info, CompatibilityInfo compatInfo, int processState) { |
| 842 | updateProcessState(processState, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 843 | CreateServiceData s = new CreateServiceData(); |
| 844 | s.token = token; |
| 845 | s.info = info; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 846 | s.compatInfo = compatInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 847 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 848 | sendMessage(H.CREATE_SERVICE, s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 849 | } |
| 850 | |
| 851 | public final void scheduleBindService(IBinder token, Intent intent, |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 852 | boolean rebind, int processState) { |
| 853 | updateProcessState(processState, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 854 | BindServiceData s = new BindServiceData(); |
| 855 | s.token = token; |
| 856 | s.intent = intent; |
| 857 | s.rebind = rebind; |
| 858 | |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 859 | if (DEBUG_SERVICE) |
| 860 | Slog.v(TAG, "scheduleBindService token=" + token + " intent=" + intent + " uid=" |
| 861 | + Binder.getCallingUid() + " pid=" + Binder.getCallingPid()); |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 862 | sendMessage(H.BIND_SERVICE, s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 863 | } |
| 864 | |
| 865 | public final void scheduleUnbindService(IBinder token, Intent intent) { |
| 866 | BindServiceData s = new BindServiceData(); |
| 867 | s.token = token; |
| 868 | s.intent = intent; |
| 869 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 870 | sendMessage(H.UNBIND_SERVICE, s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 871 | } |
| 872 | |
Dianne Hackborn | 3f7c9f2 | 2017-04-04 15:36:33 -0700 | [diff] [blame] | 873 | public final void scheduleServiceArgs(IBinder token, ParceledListSlice args) { |
| 874 | List<ServiceStartArgs> list = args.getList(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 875 | |
Dianne Hackborn | 3f7c9f2 | 2017-04-04 15:36:33 -0700 | [diff] [blame] | 876 | for (int i = 0; i < list.size(); i++) { |
| 877 | ServiceStartArgs ssa = list.get(i); |
| 878 | ServiceArgsData s = new ServiceArgsData(); |
| 879 | s.token = token; |
| 880 | s.taskRemoved = ssa.taskRemoved; |
| 881 | s.startId = ssa.startId; |
| 882 | s.flags = ssa.flags; |
| 883 | s.args = ssa.args; |
| 884 | |
| 885 | sendMessage(H.SERVICE_ARGS, s); |
| 886 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 887 | } |
| 888 | |
| 889 | public final void scheduleStopService(IBinder token) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 890 | sendMessage(H.STOP_SERVICE, token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 891 | } |
| 892 | |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 893 | public final void bindApplication(String processName, ApplicationInfo appInfo, |
| 894 | List<ProviderInfo> providers, ComponentName instrumentationName, |
| 895 | ProfilerInfo profilerInfo, Bundle instrumentationArgs, |
| 896 | IInstrumentationWatcher instrumentationWatcher, |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 897 | IUiAutomationConnection instrumentationUiConnection, int debugMode, |
Pablo Ceballos | a4d4e82 | 2015-10-05 10:27:52 -0700 | [diff] [blame] | 898 | boolean enableBinderTracking, boolean trackAllocation, |
| 899 | boolean isRestrictedBackupMode, boolean persistent, Configuration config, |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 900 | CompatibilityInfo compatInfo, Map services, Bundle coreSettings, |
Svet Ganov | 37e4327 | 2016-09-09 16:01:32 -0700 | [diff] [blame] | 901 | String buildSerial) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 902 | |
| 903 | if (services != null) { |
| 904 | // Setup the service cache in the ServiceManager |
| 905 | ServiceManager.initServiceCache(services); |
| 906 | } |
| 907 | |
Svetoslav Ganov | 9aa597e | 2011-03-03 18:17:41 -0800 | [diff] [blame] | 908 | setCoreSettings(coreSettings); |
| 909 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 910 | AppBindData data = new AppBindData(); |
| 911 | data.processName = processName; |
| 912 | data.appInfo = appInfo; |
| 913 | data.providers = providers; |
| 914 | data.instrumentationName = instrumentationName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 915 | data.instrumentationArgs = instrumentationArgs; |
| 916 | data.instrumentationWatcher = instrumentationWatcher; |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 917 | data.instrumentationUiAutomationConnection = instrumentationUiConnection; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 918 | data.debugMode = debugMode; |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 919 | data.enableBinderTracking = enableBinderTracking; |
Man Cao | cfa78b2 | 2015-06-11 20:14:34 -0700 | [diff] [blame] | 920 | data.trackAllocation = trackAllocation; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 921 | data.restrictedBackupMode = isRestrictedBackupMode; |
Dianne Hackborn | 5d927c2 | 2011-09-02 12:22:18 -0700 | [diff] [blame] | 922 | data.persistent = persistent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 923 | data.config = config; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 924 | data.compatInfo = compatInfo; |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 925 | data.initProfilerInfo = profilerInfo; |
Svet Ganov | 37e4327 | 2016-09-09 16:01:32 -0700 | [diff] [blame] | 926 | data.buildSerial = buildSerial; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 927 | sendMessage(H.BIND_APPLICATION, data); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 928 | } |
| 929 | |
| 930 | public final void scheduleExit() { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 931 | sendMessage(H.EXIT_APPLICATION, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 932 | } |
| 933 | |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 934 | public final void scheduleSuicide() { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 935 | sendMessage(H.SUICIDE, null); |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 936 | } |
| 937 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 938 | public void scheduleConfigurationChanged(Configuration config) { |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 939 | updatePendingConfiguration(config); |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 940 | sendMessage(H.CONFIGURATION_CHANGED, config); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 941 | } |
| 942 | |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 943 | public void scheduleApplicationInfoChanged(ApplicationInfo ai) { |
| 944 | sendMessage(H.APPLICATION_INFO_CHANGED, ai); |
| 945 | } |
| 946 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 947 | public void updateTimeZone() { |
| 948 | TimeZone.setDefault(null); |
| 949 | } |
| 950 | |
Robert Greenwalt | 03595d0 | 2010-11-02 14:08:23 -0700 | [diff] [blame] | 951 | public void clearDnsCache() { |
| 952 | // a non-standard API to get this to libcore |
| 953 | InetAddress.clearDnsCache(); |
Paul Jensen | e401d17 | 2014-09-12 10:47:39 -0400 | [diff] [blame] | 954 | // Allow libcore to perform the necessary actions as it sees fit upon a network |
| 955 | // configuration change. |
| 956 | NetworkEventDispatcher.getInstance().onNetworkConfigurationChanged(); |
Robert Greenwalt | 03595d0 | 2010-11-02 14:08:23 -0700 | [diff] [blame] | 957 | } |
| 958 | |
Jason Monk | 83520b9 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 959 | public void setHttpProxy(String host, String port, String exclList, Uri pacFileUrl) { |
Paul Jensen | 72db88e | 2015-03-10 10:54:12 -0400 | [diff] [blame] | 960 | final ConnectivityManager cm = ConnectivityManager.from(getSystemContext()); |
| 961 | final Network network = cm.getBoundNetworkForProcess(); |
Paul Jensen | e0bef71 | 2014-12-10 15:12:18 -0500 | [diff] [blame] | 962 | if (network != null) { |
Paul Jensen | 72db88e | 2015-03-10 10:54:12 -0400 | [diff] [blame] | 963 | Proxy.setHttpProxySystemProperty(cm.getDefaultProxy()); |
Paul Jensen | e0bef71 | 2014-12-10 15:12:18 -0500 | [diff] [blame] | 964 | } else { |
| 965 | Proxy.setHttpProxySystemProperty(host, port, exclList, pacFileUrl); |
| 966 | } |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 967 | } |
| 968 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 969 | public void processInBackground() { |
| 970 | mH.removeMessages(H.GC_WHEN_IDLE); |
| 971 | mH.sendMessage(mH.obtainMessage(H.GC_WHEN_IDLE)); |
| 972 | } |
| 973 | |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 974 | public void dumpService(ParcelFileDescriptor pfd, IBinder servicetoken, String[] args) { |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 975 | DumpComponentInfo data = new DumpComponentInfo(); |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 976 | try { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 977 | data.fd = pfd.dup(); |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 978 | data.token = servicetoken; |
| 979 | data.args = args; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 980 | sendMessage(H.DUMP_SERVICE, data, 0, 0, true /*async*/); |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 981 | } catch (IOException e) { |
| 982 | Slog.w(TAG, "dumpService failed", e); |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 983 | } finally { |
| 984 | IoUtils.closeQuietly(pfd); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 985 | } |
| 986 | } |
| 987 | |
| 988 | // This function exists to make sure all receiver dispatching is |
| 989 | // correctly ordered, since these are one-way calls and the binder driver |
| 990 | // applies transaction ordering per object for such calls. |
| 991 | public void scheduleRegisteredReceiver(IIntentReceiver receiver, Intent intent, |
Dianne Hackborn | 68d881c | 2009-10-05 13:58:17 -0700 | [diff] [blame] | 992 | int resultCode, String dataStr, Bundle extras, boolean ordered, |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 993 | boolean sticky, int sendingUser, int processState) throws RemoteException { |
| 994 | updateProcessState(processState, false); |
Dianne Hackborn | 20e8098 | 2012-08-31 19:00:44 -0700 | [diff] [blame] | 995 | receiver.performReceive(intent, resultCode, dataStr, extras, ordered, |
| 996 | sticky, sendingUser); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 997 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 998 | |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 999 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1000 | public void scheduleLowMemory() { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1001 | sendMessage(H.LOW_MEMORY, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1002 | } |
| 1003 | |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 1004 | @Override |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 1005 | public void scheduleActivityConfigurationChanged( |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 1006 | IBinder token, Configuration overrideConfig) { |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 1007 | sendMessage(H.ACTIVITY_CONFIGURATION_CHANGED, |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 1008 | new ActivityConfigChangeData(token, overrideConfig)); |
| 1009 | } |
| 1010 | |
| 1011 | @Override |
| 1012 | public void scheduleActivityMovedToDisplay(IBinder token, int displayId, |
| 1013 | Configuration overrideConfig) { |
| 1014 | sendMessage(H.ACTIVITY_MOVED_TO_DISPLAY, |
| 1015 | new ActivityConfigChangeData(token, overrideConfig), displayId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1016 | } |
| 1017 | |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 1018 | @Override |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 1019 | public void profilerControl(boolean start, ProfilerInfo profilerInfo, int profileType) { |
| 1020 | sendMessage(H.PROFILER_CONTROL, profilerInfo, start ? 1 : 0, profileType); |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 1021 | } |
| 1022 | |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 1023 | public void dumpHeap(boolean managed, String path, ParcelFileDescriptor fd) { |
| 1024 | DumpHeapData dhd = new DumpHeapData(); |
| 1025 | dhd.path = path; |
| 1026 | dhd.fd = fd; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1027 | sendMessage(H.DUMP_HEAP, dhd, managed ? 1 : 0, 0, true /*async*/); |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 1028 | } |
| 1029 | |
Leonard Mosescu | f3409ce | 2016-10-06 17:32:05 -0700 | [diff] [blame] | 1030 | public void attachAgent(String agent) { |
| 1031 | sendMessage(H.ATTACH_AGENT, agent); |
| 1032 | } |
| 1033 | |
Dianne Hackborn | 06de2ea | 2009-05-21 12:56:43 -0700 | [diff] [blame] | 1034 | public void setSchedulingGroup(int group) { |
| 1035 | // Note: do this immediately, since going into the foreground |
| 1036 | // should happen regardless of what pending work we have to do |
| 1037 | // and the activity manager will wait for us to report back that |
| 1038 | // we are done before sending us to the background. |
| 1039 | try { |
| 1040 | Process.setProcessGroup(Process.myPid(), group); |
| 1041 | } catch (Exception e) { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 1042 | Slog.w(TAG, "Failed setting process group to " + group, e); |
Dianne Hackborn | 06de2ea | 2009-05-21 12:56:43 -0700 | [diff] [blame] | 1043 | } |
| 1044 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1045 | |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1046 | public void dispatchPackageBroadcast(int cmd, String[] packages) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1047 | sendMessage(H.DISPATCH_PACKAGE_BROADCAST, packages, cmd); |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1048 | } |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 1049 | |
| 1050 | public void scheduleCrash(String msg) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1051 | sendMessage(H.SCHEDULE_CRASH, msg); |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 1052 | } |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1053 | |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1054 | public void dumpActivity(ParcelFileDescriptor pfd, IBinder activitytoken, |
Dianne Hackborn | 30d7189 | 2010-12-11 10:37:55 -0800 | [diff] [blame] | 1055 | String prefix, String[] args) { |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1056 | DumpComponentInfo data = new DumpComponentInfo(); |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 1057 | try { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1058 | data.fd = pfd.dup(); |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 1059 | data.token = activitytoken; |
| 1060 | data.prefix = prefix; |
| 1061 | data.args = args; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1062 | sendMessage(H.DUMP_ACTIVITY, data, 0, 0, true /*async*/); |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 1063 | } catch (IOException e) { |
| 1064 | Slog.w(TAG, "dumpActivity failed", e); |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1065 | } finally { |
| 1066 | IoUtils.closeQuietly(pfd); |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1067 | } |
| 1068 | } |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 1069 | |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1070 | public void dumpProvider(ParcelFileDescriptor pfd, IBinder providertoken, |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1071 | String[] args) { |
| 1072 | DumpComponentInfo data = new DumpComponentInfo(); |
| 1073 | try { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1074 | data.fd = pfd.dup(); |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1075 | data.token = providertoken; |
| 1076 | data.args = args; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1077 | sendMessage(H.DUMP_PROVIDER, data, 0, 0, true /*async*/); |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1078 | } catch (IOException e) { |
| 1079 | Slog.w(TAG, "dumpProvider failed", e); |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1080 | } finally { |
| 1081 | IoUtils.closeQuietly(pfd); |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1082 | } |
| 1083 | } |
| 1084 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1085 | @Override |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1086 | public void dumpMemInfo(ParcelFileDescriptor pfd, Debug.MemoryInfo mem, boolean checkin, |
Colin Cross | c4fb5f9 | 2016-02-02 16:51:15 -0800 | [diff] [blame] | 1087 | boolean dumpFullInfo, boolean dumpDalvik, boolean dumpSummaryOnly, |
| 1088 | boolean dumpUnreachable, String[] args) { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1089 | FileOutputStream fout = new FileOutputStream(pfd.getFileDescriptor()); |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 1090 | PrintWriter pw = new FastPrintWriter(fout); |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 1091 | try { |
Colin Cross | c4fb5f9 | 2016-02-02 16:51:15 -0800 | [diff] [blame] | 1092 | dumpMemInfo(pw, mem, checkin, dumpFullInfo, dumpDalvik, dumpSummaryOnly, dumpUnreachable); |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 1093 | } finally { |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 1094 | pw.flush(); |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1095 | IoUtils.closeQuietly(pfd); |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 1096 | } |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 1097 | } |
| 1098 | |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 1099 | private void dumpMemInfo(PrintWriter pw, Debug.MemoryInfo memInfo, boolean checkin, |
Colin Cross | c4fb5f9 | 2016-02-02 16:51:15 -0800 | [diff] [blame] | 1100 | boolean dumpFullInfo, boolean dumpDalvik, boolean dumpSummaryOnly, boolean dumpUnreachable) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1101 | long nativeMax = Debug.getNativeHeapSize() / 1024; |
| 1102 | long nativeAllocated = Debug.getNativeHeapAllocatedSize() / 1024; |
| 1103 | long nativeFree = Debug.getNativeHeapFreeSize() / 1024; |
| 1104 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1105 | Runtime runtime = Runtime.getRuntime(); |
Mathieu Chartier | d288a26 | 2015-07-10 13:44:42 -0700 | [diff] [blame] | 1106 | runtime.gc(); // Do GC since countInstancesOfClass counts unreachable objects. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1107 | long dalvikMax = runtime.totalMemory() / 1024; |
| 1108 | long dalvikFree = runtime.freeMemory() / 1024; |
| 1109 | long dalvikAllocated = dalvikMax - dalvikFree; |
Richard Uhler | 2c03619 | 2016-09-14 09:48:31 +0100 | [diff] [blame] | 1110 | |
| 1111 | Class[] classesToCount = new Class[] { |
| 1112 | ContextImpl.class, |
| 1113 | Activity.class, |
| 1114 | WebView.class, |
| 1115 | OpenSSLSocketImpl.class |
| 1116 | }; |
| 1117 | long[] instanceCounts = VMDebug.countInstancesOfClasses(classesToCount, true); |
| 1118 | long appContextInstanceCount = instanceCounts[0]; |
| 1119 | long activityInstanceCount = instanceCounts[1]; |
| 1120 | long webviewInstanceCount = instanceCounts[2]; |
| 1121 | long openSslSocketCount = instanceCounts[3]; |
| 1122 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1123 | long viewInstanceCount = ViewDebug.getViewInstanceCount(); |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1124 | long viewRootInstanceCount = ViewDebug.getViewRootImplCount(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1125 | int globalAssetCount = AssetManager.getGlobalAssetCount(); |
| 1126 | int globalAssetManagerCount = AssetManager.getGlobalAssetManagerCount(); |
| 1127 | int binderLocalObjectCount = Debug.getBinderLocalObjectCount(); |
| 1128 | int binderProxyObjectCount = Debug.getBinderProxyObjectCount(); |
| 1129 | int binderDeathObjectCount = Debug.getBinderDeathObjectCount(); |
Dianne Hackborn | fabb70b | 2014-11-11 12:22:36 -0800 | [diff] [blame] | 1130 | long parcelSize = Parcel.getGlobalAllocSize(); |
| 1131 | long parcelCount = Parcel.getGlobalAllocCount(); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1132 | SQLiteDebug.PagerStats stats = SQLiteDebug.getDatabaseInfo(); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1133 | |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 1134 | dumpMemInfoTable(pw, memInfo, checkin, dumpFullInfo, dumpDalvik, dumpSummaryOnly, |
| 1135 | Process.myPid(), |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 1136 | (mBoundApplication != null) ? mBoundApplication.processName : "unknown", |
| 1137 | nativeMax, nativeAllocated, nativeFree, |
| 1138 | dalvikMax, dalvikAllocated, dalvikFree); |
| 1139 | |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 1140 | if (checkin) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1141 | // NOTE: if you change anything significant below, also consider changing |
| 1142 | // ACTIVITY_THREAD_CHECKIN_VERSION. |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 1143 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1144 | // Object counts |
| 1145 | pw.print(viewInstanceCount); pw.print(','); |
| 1146 | pw.print(viewRootInstanceCount); pw.print(','); |
| 1147 | pw.print(appContextInstanceCount); pw.print(','); |
| 1148 | pw.print(activityInstanceCount); pw.print(','); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1149 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1150 | pw.print(globalAssetCount); pw.print(','); |
| 1151 | pw.print(globalAssetManagerCount); pw.print(','); |
| 1152 | pw.print(binderLocalObjectCount); pw.print(','); |
| 1153 | pw.print(binderProxyObjectCount); pw.print(','); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1154 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1155 | pw.print(binderDeathObjectCount); pw.print(','); |
| 1156 | pw.print(openSslSocketCount); pw.print(','); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1157 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1158 | // SQL |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1159 | pw.print(stats.memoryUsed / 1024); pw.print(','); |
Jeff Brown | 2a293b6 | 2012-01-19 14:02:22 -0800 | [diff] [blame] | 1160 | pw.print(stats.memoryUsed / 1024); pw.print(','); |
| 1161 | pw.print(stats.pageCacheOverflow / 1024); pw.print(','); |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 1162 | pw.print(stats.largestMemAlloc / 1024); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1163 | for (int i = 0; i < stats.dbStats.size(); i++) { |
| 1164 | DbStats dbStats = stats.dbStats.get(i); |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 1165 | pw.print(','); pw.print(dbStats.dbName); |
| 1166 | pw.print(','); pw.print(dbStats.pageSize); |
| 1167 | pw.print(','); pw.print(dbStats.dbSize); |
| 1168 | pw.print(','); pw.print(dbStats.lookaside); |
| 1169 | pw.print(','); pw.print(dbStats.cache); |
| 1170 | pw.print(','); pw.print(dbStats.cache); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1171 | } |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 1172 | pw.println(); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1173 | |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 1174 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1175 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1176 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1177 | pw.println(" "); |
| 1178 | pw.println(" Objects"); |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1179 | printRow(pw, TWO_COUNT_COLUMNS, "Views:", viewInstanceCount, "ViewRootImpl:", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1180 | viewRootInstanceCount); |
| 1181 | |
| 1182 | printRow(pw, TWO_COUNT_COLUMNS, "AppContexts:", appContextInstanceCount, |
| 1183 | "Activities:", activityInstanceCount); |
| 1184 | |
| 1185 | printRow(pw, TWO_COUNT_COLUMNS, "Assets:", globalAssetCount, |
| 1186 | "AssetManagers:", globalAssetManagerCount); |
| 1187 | |
| 1188 | printRow(pw, TWO_COUNT_COLUMNS, "Local Binders:", binderLocalObjectCount, |
| 1189 | "Proxy Binders:", binderProxyObjectCount); |
Dianne Hackborn | fabb70b | 2014-11-11 12:22:36 -0800 | [diff] [blame] | 1190 | printRow(pw, TWO_COUNT_COLUMNS, "Parcel memory:", parcelSize/1024, |
| 1191 | "Parcel count:", parcelCount); |
| 1192 | printRow(pw, TWO_COUNT_COLUMNS, "Death Recipients:", binderDeathObjectCount, |
| 1193 | "OpenSSL Sockets:", openSslSocketCount); |
Richard Uhler | 2c03619 | 2016-09-14 09:48:31 +0100 | [diff] [blame] | 1194 | printRow(pw, ONE_COUNT_COLUMN, "WebViews:", webviewInstanceCount); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1195 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1196 | // SQLite mem info |
| 1197 | pw.println(" "); |
| 1198 | pw.println(" SQL"); |
Jeff Brown | 2a293b6 | 2012-01-19 14:02:22 -0800 | [diff] [blame] | 1199 | printRow(pw, ONE_COUNT_COLUMN, "MEMORY_USED:", stats.memoryUsed / 1024); |
| 1200 | printRow(pw, TWO_COUNT_COLUMNS, "PAGECACHE_OVERFLOW:", |
| 1201 | stats.pageCacheOverflow / 1024, "MALLOC_SIZE:", stats.largestMemAlloc / 1024); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1202 | pw.println(" "); |
| 1203 | int N = stats.dbStats.size(); |
| 1204 | if (N > 0) { |
| 1205 | pw.println(" DATABASES"); |
Vasu Nori | 3c7131f | 2010-09-21 14:36:57 -0700 | [diff] [blame] | 1206 | printRow(pw, " %8s %8s %14s %14s %s", "pgsz", "dbsz", "Lookaside(b)", "cache", |
| 1207 | "Dbname"); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1208 | for (int i = 0; i < N; i++) { |
| 1209 | DbStats dbStats = stats.dbStats.get(i); |
Vasu Nori | 3c7131f | 2010-09-21 14:36:57 -0700 | [diff] [blame] | 1210 | printRow(pw, DB_INFO_FORMAT, |
| 1211 | (dbStats.pageSize > 0) ? String.valueOf(dbStats.pageSize) : " ", |
| 1212 | (dbStats.dbSize > 0) ? String.valueOf(dbStats.dbSize) : " ", |
| 1213 | (dbStats.lookaside > 0) ? String.valueOf(dbStats.lookaside) : " ", |
| 1214 | dbStats.cache, dbStats.dbName); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1215 | } |
| 1216 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1217 | |
Dianne Hackborn | 82e1ee9 | 2009-08-11 18:56:41 -0700 | [diff] [blame] | 1218 | // Asset details. |
| 1219 | String assetAlloc = AssetManager.getAssetAllocations(); |
| 1220 | if (assetAlloc != null) { |
| 1221 | pw.println(" "); |
| 1222 | pw.println(" Asset Allocations"); |
| 1223 | pw.print(assetAlloc); |
| 1224 | } |
Colin Cross | c4fb5f9 | 2016-02-02 16:51:15 -0800 | [diff] [blame] | 1225 | |
| 1226 | // Unreachable native memory |
| 1227 | if (dumpUnreachable) { |
| 1228 | boolean showContents = ((mBoundApplication != null) |
| 1229 | && ((mBoundApplication.appInfo.flags&ApplicationInfo.FLAG_DEBUGGABLE) != 0)) |
| 1230 | || android.os.Build.IS_DEBUGGABLE; |
| 1231 | pw.println(" "); |
| 1232 | pw.println(" Unreachable memory"); |
| 1233 | pw.print(Debug.getUnreachableMemory(100, showContents)); |
| 1234 | } |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 1235 | } |
| 1236 | |
| 1237 | @Override |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1238 | public void dumpGfxInfo(ParcelFileDescriptor pfd, String[] args) { |
Chris Craik | fc29424 | 2016-12-13 18:10:46 -0800 | [diff] [blame] | 1239 | nDumpGraphicsInfo(pfd.getFileDescriptor()); |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1240 | WindowManagerGlobal.getInstance().dumpGfxInfo(pfd.getFileDescriptor(), args); |
| 1241 | IoUtils.closeQuietly(pfd); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1242 | } |
| 1243 | |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1244 | private void dumpDatabaseInfo(ParcelFileDescriptor pfd, String[] args) { |
| 1245 | PrintWriter pw = new FastPrintWriter( |
| 1246 | new FileOutputStream(pfd.getFileDescriptor())); |
Jeff Brown | 6754ba2 | 2011-12-14 20:20:01 -0800 | [diff] [blame] | 1247 | PrintWriterPrinter printer = new PrintWriterPrinter(pw); |
| 1248 | SQLiteDebug.dump(printer, args); |
| 1249 | pw.flush(); |
| 1250 | } |
| 1251 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1252 | @Override |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1253 | public void dumpDbInfo(final ParcelFileDescriptor pfd, final String[] args) { |
riddle_hsu | 1d6c40a | 2014-07-31 00:18:00 +0800 | [diff] [blame] | 1254 | if (mSystemThread) { |
Felipe Leme | 29de492 | 2016-06-07 16:14:07 -0700 | [diff] [blame] | 1255 | // Ensure this invocation is asynchronous to prevent writer waiting if buffer cannot |
| 1256 | // be consumed. But it must duplicate the file descriptor first, since caller might |
| 1257 | // be closing it. |
| 1258 | final ParcelFileDescriptor dup; |
| 1259 | try { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1260 | dup = pfd.dup(); |
Felipe Leme | 29de492 | 2016-06-07 16:14:07 -0700 | [diff] [blame] | 1261 | } catch (IOException e) { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1262 | Log.w(TAG, "Could not dup FD " + pfd.getFileDescriptor().getInt$()); |
Felipe Leme | 29de492 | 2016-06-07 16:14:07 -0700 | [diff] [blame] | 1263 | return; |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1264 | } finally { |
| 1265 | IoUtils.closeQuietly(pfd); |
Felipe Leme | 29de492 | 2016-06-07 16:14:07 -0700 | [diff] [blame] | 1266 | } |
| 1267 | |
riddle_hsu | 1d6c40a | 2014-07-31 00:18:00 +0800 | [diff] [blame] | 1268 | AsyncTask.THREAD_POOL_EXECUTOR.execute(new Runnable() { |
| 1269 | @Override |
| 1270 | public void run() { |
Felipe Leme | c74972f | 2016-06-08 09:12:37 -0700 | [diff] [blame] | 1271 | try { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1272 | dumpDatabaseInfo(dup, args); |
Felipe Leme | c74972f | 2016-06-08 09:12:37 -0700 | [diff] [blame] | 1273 | } finally { |
| 1274 | IoUtils.closeQuietly(dup); |
| 1275 | } |
riddle_hsu | 1d6c40a | 2014-07-31 00:18:00 +0800 | [diff] [blame] | 1276 | } |
| 1277 | }); |
| 1278 | } else { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1279 | dumpDatabaseInfo(pfd, args); |
| 1280 | IoUtils.closeQuietly(pfd); |
riddle_hsu | 1d6c40a | 2014-07-31 00:18:00 +0800 | [diff] [blame] | 1281 | } |
| 1282 | } |
| 1283 | |
| 1284 | @Override |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1285 | public void unstableProviderDied(IBinder provider) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1286 | sendMessage(H.UNSTABLE_PROVIDER_DIED, provider); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1287 | } |
| 1288 | |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 1289 | @Override |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 1290 | public void requestAssistContextExtras(IBinder activityToken, IBinder requestToken, |
Felipe Leme | 0200d9e | 2017-01-24 15:10:26 -0800 | [diff] [blame] | 1291 | int requestType, int sessionId) { |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 1292 | RequestAssistContextExtras cmd = new RequestAssistContextExtras(); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 1293 | cmd.activityToken = activityToken; |
| 1294 | cmd.requestToken = requestToken; |
| 1295 | cmd.requestType = requestType; |
Amith Yamasani | 4f128e4 | 2016-05-10 11:44:12 -0700 | [diff] [blame] | 1296 | cmd.sessionId = sessionId; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1297 | sendMessage(H.REQUEST_ASSIST_CONTEXT_EXTRAS, cmd); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 1298 | } |
| 1299 | |
Svetoslav Ganov | 9aa597e | 2011-03-03 18:17:41 -0800 | [diff] [blame] | 1300 | public void setCoreSettings(Bundle coreSettings) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1301 | sendMessage(H.SET_CORE_SETTINGS, coreSettings); |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1302 | } |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1303 | |
| 1304 | public void updatePackageCompatibilityInfo(String pkg, CompatibilityInfo info) { |
| 1305 | UpdateCompatibilityData ucd = new UpdateCompatibilityData(); |
| 1306 | ucd.pkg = pkg; |
| 1307 | ucd.info = info; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1308 | sendMessage(H.UPDATE_PACKAGE_COMPATIBILITY_INFO, ucd); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1309 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1310 | |
| 1311 | public void scheduleTrimMemory(int level) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1312 | sendMessage(H.TRIM_MEMORY, null, level); |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1313 | } |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1314 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1315 | public void scheduleTranslucentConversionComplete(IBinder token, boolean drawComplete) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1316 | sendMessage(H.TRANSLUCENT_CONVERSION_COMPLETE, token, drawComplete ? 1 : 0); |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1317 | } |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 1318 | |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1319 | public void scheduleOnNewActivityOptions(IBinder token, Bundle options) { |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1320 | sendMessage(H.ON_NEW_ACTIVITY_OPTIONS, |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1321 | new Pair<IBinder, ActivityOptions>(token, ActivityOptions.fromBundle(options))); |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1322 | } |
| 1323 | |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 1324 | public void setProcessState(int state) { |
| 1325 | updateProcessState(state, true); |
| 1326 | } |
| 1327 | |
| 1328 | public void updateProcessState(int processState, boolean fromIpc) { |
| 1329 | synchronized (this) { |
| 1330 | if (mLastProcessState != processState) { |
| 1331 | mLastProcessState = processState; |
Mathieu Chartier | 1e37090 | 2013-07-18 10:58:01 -0700 | [diff] [blame] | 1332 | // Update Dalvik state based on ActivityManager.PROCESS_STATE_* constants. |
| 1333 | final int DALVIK_PROCESS_STATE_JANK_PERCEPTIBLE = 0; |
| 1334 | final int DALVIK_PROCESS_STATE_JANK_IMPERCEPTIBLE = 1; |
| 1335 | int dalvikProcessState = DALVIK_PROCESS_STATE_JANK_IMPERCEPTIBLE; |
| 1336 | // TODO: Tune this since things like gmail sync are important background but not jank perceptible. |
| 1337 | if (processState <= ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND) { |
| 1338 | dalvikProcessState = DALVIK_PROCESS_STATE_JANK_PERCEPTIBLE; |
| 1339 | } |
| 1340 | VMRuntime.getRuntime().updateProcessState(dalvikProcessState); |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 1341 | if (false) { |
| 1342 | Slog.i(TAG, "******************* PROCESS STATE CHANGED TO: " + processState |
| 1343 | + (fromIpc ? " (from ipc": "")); |
| 1344 | } |
| 1345 | } |
| 1346 | } |
| 1347 | } |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 1348 | |
Sudheer Shanka | 84a4895 | 2017-03-08 18:19:01 -0800 | [diff] [blame] | 1349 | /** |
| 1350 | * Updates {@link #mNetworkBlockSeq}. This is used by ActivityManagerService to inform |
| 1351 | * the main thread that it needs to wait for the network rules to get updated before |
| 1352 | * launching an activity. |
| 1353 | */ |
| 1354 | @Override |
| 1355 | public void setNetworkBlockSeq(long procStateSeq) { |
| 1356 | synchronized (mNetworkPolicyLock) { |
| 1357 | mNetworkBlockSeq = procStateSeq; |
| 1358 | } |
| 1359 | } |
| 1360 | |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 1361 | @Override |
| 1362 | public void scheduleInstallProvider(ProviderInfo provider) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1363 | sendMessage(H.INSTALL_PROVIDER, provider); |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 1364 | } |
Narayan Kamath | ccb2a086 | 2013-12-19 14:49:36 +0000 | [diff] [blame] | 1365 | |
| 1366 | @Override |
Neil Fuller | b7146fe | 2016-11-15 16:52:15 +0000 | [diff] [blame] | 1367 | public final void updateTimePrefs(int timeFormatPreference) { |
| 1368 | final Boolean timeFormatPreferenceBool; |
| 1369 | // For convenience we are using the Intent extra values. |
| 1370 | if (timeFormatPreference == Intent.EXTRA_TIME_PREF_VALUE_USE_12_HOUR) { |
| 1371 | timeFormatPreferenceBool = Boolean.FALSE; |
| 1372 | } else if (timeFormatPreference == Intent.EXTRA_TIME_PREF_VALUE_USE_24_HOUR) { |
| 1373 | timeFormatPreferenceBool = Boolean.TRUE; |
| 1374 | } else { |
| 1375 | // timeFormatPreference == Intent.EXTRA_TIME_PREF_VALUE_USE_LOCALE_DEFAULT |
| 1376 | // (or unknown). |
| 1377 | timeFormatPreferenceBool = null; |
| 1378 | } |
| 1379 | DateFormat.set24HourTimePref(timeFormatPreferenceBool); |
Narayan Kamath | ccb2a086 | 2013-12-19 14:49:36 +0000 | [diff] [blame] | 1380 | } |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 1381 | |
| 1382 | @Override |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 1383 | public void scheduleCancelVisibleBehind(IBinder token) { |
| 1384 | sendMessage(H.CANCEL_VISIBLE_BEHIND, token); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 1385 | } |
| 1386 | |
| 1387 | @Override |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 1388 | public void scheduleBackgroundVisibleBehindChanged(IBinder token, boolean visible) { |
| 1389 | sendMessage(H.BACKGROUND_VISIBLE_BEHIND_CHANGED, token, visible ? 1 : 0); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 1390 | } |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 1391 | |
Jeff Sharkey | 605eb79 | 2014-11-04 13:34:06 -0800 | [diff] [blame] | 1392 | @Override |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 1393 | public void scheduleEnterAnimationComplete(IBinder token) { |
| 1394 | sendMessage(H.ENTER_ANIMATION_COMPLETE, token); |
| 1395 | } |
Jeff Sharkey | 605eb79 | 2014-11-04 13:34:06 -0800 | [diff] [blame] | 1396 | |
| 1397 | @Override |
| 1398 | public void notifyCleartextNetwork(byte[] firstPacket) { |
| 1399 | if (StrictMode.vmCleartextNetworkEnabled()) { |
| 1400 | StrictMode.onCleartextNetworkDetected(firstPacket); |
| 1401 | } |
| 1402 | } |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 1403 | |
| 1404 | @Override |
| 1405 | public void startBinderTracking() { |
| 1406 | sendMessage(H.START_BINDER_TRACKING, null); |
| 1407 | } |
| 1408 | |
| 1409 | @Override |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1410 | public void stopBinderTrackingAndDump(ParcelFileDescriptor pfd) { |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 1411 | try { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1412 | sendMessage(H.STOP_BINDER_TRACKING_AND_DUMP, pfd.dup()); |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 1413 | } catch (IOException e) { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1414 | } finally { |
| 1415 | IoUtils.closeQuietly(pfd); |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 1416 | } |
| 1417 | } |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 1418 | |
| 1419 | @Override |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 1420 | public void scheduleMultiWindowModeChanged(IBinder token, boolean isInMultiWindowMode, |
| 1421 | Configuration overrideConfig) throws RemoteException { |
| 1422 | SomeArgs args = SomeArgs.obtain(); |
| 1423 | args.arg1 = token; |
| 1424 | args.arg2 = overrideConfig; |
| 1425 | args.argi1 = isInMultiWindowMode ? 1 : 0; |
| 1426 | sendMessage(H.MULTI_WINDOW_MODE_CHANGED, args); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 1427 | } |
| 1428 | |
| 1429 | @Override |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 1430 | public void schedulePictureInPictureModeChanged(IBinder token, boolean isInPipMode, |
| 1431 | Configuration overrideConfig) throws RemoteException { |
| 1432 | SomeArgs args = SomeArgs.obtain(); |
| 1433 | args.arg1 = token; |
| 1434 | args.arg2 = overrideConfig; |
| 1435 | args.argi1 = isInPipMode ? 1 : 0; |
| 1436 | sendMessage(H.PICTURE_IN_PICTURE_MODE_CHANGED, args); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 1437 | } |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1438 | |
| 1439 | @Override |
| 1440 | public void scheduleLocalVoiceInteractionStarted(IBinder token, |
| 1441 | IVoiceInteractor voiceInteractor) throws RemoteException { |
| 1442 | SomeArgs args = SomeArgs.obtain(); |
| 1443 | args.arg1 = token; |
| 1444 | args.arg2 = voiceInteractor; |
| 1445 | sendMessage(H.LOCAL_VOICE_INTERACTION_STARTED, args); |
| 1446 | } |
Chad Brubaker | c72875b | 2016-04-27 16:35:11 -0700 | [diff] [blame] | 1447 | |
| 1448 | @Override |
| 1449 | public void handleTrustStorageUpdate() { |
| 1450 | NetworkSecurityPolicy.getInstance().handleTrustStorageUpdate(); |
| 1451 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1452 | } |
| 1453 | |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1454 | private int getLifecycleSeq() { |
| 1455 | synchronized (mResourcesManager) { |
| 1456 | return mLifecycleSeq++; |
| 1457 | } |
| 1458 | } |
| 1459 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1460 | private class H extends Handler { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1461 | public static final int LAUNCH_ACTIVITY = 100; |
| 1462 | public static final int PAUSE_ACTIVITY = 101; |
| 1463 | public static final int PAUSE_ACTIVITY_FINISHING= 102; |
| 1464 | public static final int STOP_ACTIVITY_SHOW = 103; |
| 1465 | public static final int STOP_ACTIVITY_HIDE = 104; |
| 1466 | public static final int SHOW_WINDOW = 105; |
| 1467 | public static final int HIDE_WINDOW = 106; |
| 1468 | public static final int RESUME_ACTIVITY = 107; |
| 1469 | public static final int SEND_RESULT = 108; |
Brian Carlstrom | ed7e007 | 2011-03-24 13:27:57 -0700 | [diff] [blame] | 1470 | public static final int DESTROY_ACTIVITY = 109; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1471 | public static final int BIND_APPLICATION = 110; |
| 1472 | public static final int EXIT_APPLICATION = 111; |
| 1473 | public static final int NEW_INTENT = 112; |
| 1474 | public static final int RECEIVER = 113; |
| 1475 | public static final int CREATE_SERVICE = 114; |
| 1476 | public static final int SERVICE_ARGS = 115; |
| 1477 | public static final int STOP_SERVICE = 116; |
Dianne Hackborn | 0923328 | 2014-04-30 11:33:59 -0700 | [diff] [blame] | 1478 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1479 | public static final int CONFIGURATION_CHANGED = 118; |
| 1480 | public static final int CLEAN_UP_CONTEXT = 119; |
| 1481 | public static final int GC_WHEN_IDLE = 120; |
| 1482 | public static final int BIND_SERVICE = 121; |
| 1483 | public static final int UNBIND_SERVICE = 122; |
| 1484 | public static final int DUMP_SERVICE = 123; |
| 1485 | public static final int LOW_MEMORY = 124; |
| 1486 | public static final int ACTIVITY_CONFIGURATION_CHANGED = 125; |
| 1487 | public static final int RELAUNCH_ACTIVITY = 126; |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 1488 | public static final int PROFILER_CONTROL = 127; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1489 | public static final int CREATE_BACKUP_AGENT = 128; |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 1490 | public static final int DESTROY_BACKUP_AGENT = 129; |
| 1491 | public static final int SUICIDE = 130; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1492 | public static final int REMOVE_PROVIDER = 131; |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 1493 | public static final int ENABLE_JIT = 132; |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1494 | public static final int DISPATCH_PACKAGE_BROADCAST = 133; |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 1495 | public static final int SCHEDULE_CRASH = 134; |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 1496 | public static final int DUMP_HEAP = 135; |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1497 | public static final int DUMP_ACTIVITY = 136; |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1498 | public static final int SLEEPING = 137; |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1499 | public static final int SET_CORE_SETTINGS = 138; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1500 | public static final int UPDATE_PACKAGE_COMPATIBILITY_INFO = 139; |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1501 | public static final int TRIM_MEMORY = 140; |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1502 | public static final int DUMP_PROVIDER = 141; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1503 | public static final int UNSTABLE_PROVIDER_DIED = 142; |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 1504 | public static final int REQUEST_ASSIST_CONTEXT_EXTRAS = 143; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1505 | public static final int TRANSLUCENT_CONVERSION_COMPLETE = 144; |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 1506 | public static final int INSTALL_PROVIDER = 145; |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1507 | public static final int ON_NEW_ACTIVITY_OPTIONS = 146; |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 1508 | public static final int CANCEL_VISIBLE_BEHIND = 147; |
| 1509 | public static final int BACKGROUND_VISIBLE_BEHIND_CHANGED = 148; |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 1510 | public static final int ENTER_ANIMATION_COMPLETE = 149; |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 1511 | public static final int START_BINDER_TRACKING = 150; |
| 1512 | public static final int STOP_BINDER_TRACKING_AND_DUMP = 151; |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 1513 | public static final int MULTI_WINDOW_MODE_CHANGED = 152; |
| 1514 | public static final int PICTURE_IN_PICTURE_MODE_CHANGED = 153; |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1515 | public static final int LOCAL_VOICE_INTERACTION_STARTED = 154; |
Leonard Mosescu | f3409ce | 2016-10-06 17:32:05 -0700 | [diff] [blame] | 1516 | public static final int ATTACH_AGENT = 155; |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 1517 | public static final int APPLICATION_INFO_CHANGED = 156; |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 1518 | public static final int ACTIVITY_MOVED_TO_DISPLAY = 157; |
Narayan Kamath | ccb2a086 | 2013-12-19 14:49:36 +0000 | [diff] [blame] | 1519 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1520 | String codeToString(int code) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 1521 | if (DEBUG_MESSAGES) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1522 | switch (code) { |
| 1523 | case LAUNCH_ACTIVITY: return "LAUNCH_ACTIVITY"; |
| 1524 | case PAUSE_ACTIVITY: return "PAUSE_ACTIVITY"; |
| 1525 | case PAUSE_ACTIVITY_FINISHING: return "PAUSE_ACTIVITY_FINISHING"; |
| 1526 | case STOP_ACTIVITY_SHOW: return "STOP_ACTIVITY_SHOW"; |
| 1527 | case STOP_ACTIVITY_HIDE: return "STOP_ACTIVITY_HIDE"; |
| 1528 | case SHOW_WINDOW: return "SHOW_WINDOW"; |
| 1529 | case HIDE_WINDOW: return "HIDE_WINDOW"; |
| 1530 | case RESUME_ACTIVITY: return "RESUME_ACTIVITY"; |
| 1531 | case SEND_RESULT: return "SEND_RESULT"; |
| 1532 | case DESTROY_ACTIVITY: return "DESTROY_ACTIVITY"; |
| 1533 | case BIND_APPLICATION: return "BIND_APPLICATION"; |
| 1534 | case EXIT_APPLICATION: return "EXIT_APPLICATION"; |
| 1535 | case NEW_INTENT: return "NEW_INTENT"; |
| 1536 | case RECEIVER: return "RECEIVER"; |
| 1537 | case CREATE_SERVICE: return "CREATE_SERVICE"; |
| 1538 | case SERVICE_ARGS: return "SERVICE_ARGS"; |
| 1539 | case STOP_SERVICE: return "STOP_SERVICE"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1540 | case CONFIGURATION_CHANGED: return "CONFIGURATION_CHANGED"; |
| 1541 | case CLEAN_UP_CONTEXT: return "CLEAN_UP_CONTEXT"; |
| 1542 | case GC_WHEN_IDLE: return "GC_WHEN_IDLE"; |
| 1543 | case BIND_SERVICE: return "BIND_SERVICE"; |
| 1544 | case UNBIND_SERVICE: return "UNBIND_SERVICE"; |
| 1545 | case DUMP_SERVICE: return "DUMP_SERVICE"; |
| 1546 | case LOW_MEMORY: return "LOW_MEMORY"; |
| 1547 | case ACTIVITY_CONFIGURATION_CHANGED: return "ACTIVITY_CONFIGURATION_CHANGED"; |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 1548 | case ACTIVITY_MOVED_TO_DISPLAY: return "ACTIVITY_MOVED_TO_DISPLAY"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1549 | case RELAUNCH_ACTIVITY: return "RELAUNCH_ACTIVITY"; |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 1550 | case PROFILER_CONTROL: return "PROFILER_CONTROL"; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1551 | case CREATE_BACKUP_AGENT: return "CREATE_BACKUP_AGENT"; |
| 1552 | case DESTROY_BACKUP_AGENT: return "DESTROY_BACKUP_AGENT"; |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 1553 | case SUICIDE: return "SUICIDE"; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1554 | case REMOVE_PROVIDER: return "REMOVE_PROVIDER"; |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 1555 | case ENABLE_JIT: return "ENABLE_JIT"; |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1556 | case DISPATCH_PACKAGE_BROADCAST: return "DISPATCH_PACKAGE_BROADCAST"; |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 1557 | case SCHEDULE_CRASH: return "SCHEDULE_CRASH"; |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 1558 | case DUMP_HEAP: return "DUMP_HEAP"; |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1559 | case DUMP_ACTIVITY: return "DUMP_ACTIVITY"; |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1560 | case SLEEPING: return "SLEEPING"; |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1561 | case SET_CORE_SETTINGS: return "SET_CORE_SETTINGS"; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1562 | case UPDATE_PACKAGE_COMPATIBILITY_INFO: return "UPDATE_PACKAGE_COMPATIBILITY_INFO"; |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1563 | case TRIM_MEMORY: return "TRIM_MEMORY"; |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1564 | case DUMP_PROVIDER: return "DUMP_PROVIDER"; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1565 | case UNSTABLE_PROVIDER_DIED: return "UNSTABLE_PROVIDER_DIED"; |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 1566 | case REQUEST_ASSIST_CONTEXT_EXTRAS: return "REQUEST_ASSIST_CONTEXT_EXTRAS"; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1567 | case TRANSLUCENT_CONVERSION_COMPLETE: return "TRANSLUCENT_CONVERSION_COMPLETE"; |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 1568 | case INSTALL_PROVIDER: return "INSTALL_PROVIDER"; |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1569 | case ON_NEW_ACTIVITY_OPTIONS: return "ON_NEW_ACTIVITY_OPTIONS"; |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 1570 | case CANCEL_VISIBLE_BEHIND: return "CANCEL_VISIBLE_BEHIND"; |
| 1571 | case BACKGROUND_VISIBLE_BEHIND_CHANGED: return "BACKGROUND_VISIBLE_BEHIND_CHANGED"; |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 1572 | case ENTER_ANIMATION_COMPLETE: return "ENTER_ANIMATION_COMPLETE"; |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 1573 | case MULTI_WINDOW_MODE_CHANGED: return "MULTI_WINDOW_MODE_CHANGED"; |
| 1574 | case PICTURE_IN_PICTURE_MODE_CHANGED: return "PICTURE_IN_PICTURE_MODE_CHANGED"; |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1575 | case LOCAL_VOICE_INTERACTION_STARTED: return "LOCAL_VOICE_INTERACTION_STARTED"; |
Leonard Mosescu | f3409ce | 2016-10-06 17:32:05 -0700 | [diff] [blame] | 1576 | case ATTACH_AGENT: return "ATTACH_AGENT"; |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 1577 | case APPLICATION_INFO_CHANGED: return "APPLICATION_INFO_CHANGED"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1578 | } |
| 1579 | } |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 1580 | return Integer.toString(code); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1581 | } |
| 1582 | public void handleMessage(Message msg) { |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 1583 | 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] | 1584 | switch (msg.what) { |
| 1585 | case LAUNCH_ACTIVITY: { |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1586 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityStart"); |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 1587 | final ActivityClientRecord r = (ActivityClientRecord) msg.obj; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1588 | |
| 1589 | r.packageInfo = getPackageInfoNoCheck( |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1590 | r.activityInfo.applicationInfo, r.compatInfo); |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 1591 | handleLaunchActivity(r, null, "LAUNCH_ACTIVITY"); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1592 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1593 | } break; |
| 1594 | case RELAUNCH_ACTIVITY: { |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1595 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityRestart"); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1596 | ActivityClientRecord r = (ActivityClientRecord)msg.obj; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 1597 | handleRelaunchActivity(r); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1598 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1599 | } break; |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1600 | case PAUSE_ACTIVITY: { |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1601 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityPause"); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1602 | SomeArgs args = (SomeArgs) msg.obj; |
| 1603 | handlePauseActivity((IBinder) args.arg1, false, |
| 1604 | (args.argi1 & USER_LEAVING) != 0, args.argi2, |
| 1605 | (args.argi1 & DONT_REPORT) != 0, args.argi3); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1606 | maybeSnapshot(); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1607 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1608 | } break; |
| 1609 | case PAUSE_ACTIVITY_FINISHING: { |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1610 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityPause"); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1611 | SomeArgs args = (SomeArgs) msg.obj; |
| 1612 | handlePauseActivity((IBinder) args.arg1, true, (args.argi1 & USER_LEAVING) != 0, |
| 1613 | args.argi2, (args.argi1 & DONT_REPORT) != 0, args.argi3); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1614 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1615 | } break; |
| 1616 | case STOP_ACTIVITY_SHOW: { |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1617 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityStop"); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1618 | SomeArgs args = (SomeArgs) msg.obj; |
| 1619 | handleStopActivity((IBinder) args.arg1, true, args.argi2, args.argi3); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1620 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1621 | } break; |
| 1622 | case STOP_ACTIVITY_HIDE: { |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1623 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityStop"); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1624 | SomeArgs args = (SomeArgs) msg.obj; |
| 1625 | handleStopActivity((IBinder) args.arg1, false, args.argi2, args.argi3); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1626 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1627 | } break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1628 | case SHOW_WINDOW: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1629 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityShowWindow"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1630 | handleWindowVisibility((IBinder)msg.obj, true); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1631 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1632 | break; |
| 1633 | case HIDE_WINDOW: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1634 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityHideWindow"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1635 | handleWindowVisibility((IBinder)msg.obj, false); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1636 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1637 | break; |
| 1638 | case RESUME_ACTIVITY: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1639 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityResume"); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1640 | SomeArgs args = (SomeArgs) msg.obj; |
| 1641 | handleResumeActivity((IBinder) args.arg1, true, args.argi1 != 0, true, |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 1642 | args.argi3, "RESUME_ACTIVITY"); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1643 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1644 | break; |
| 1645 | case SEND_RESULT: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1646 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityDeliverResult"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1647 | handleSendResult((ResultData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1648 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1649 | break; |
| 1650 | case DESTROY_ACTIVITY: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1651 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityDestroy"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1652 | handleDestroyActivity((IBinder)msg.obj, msg.arg1 != 0, |
| 1653 | msg.arg2, false); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1654 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1655 | break; |
| 1656 | case BIND_APPLICATION: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1657 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "bindApplication"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1658 | AppBindData data = (AppBindData)msg.obj; |
| 1659 | handleBindApplication(data); |
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; |
| 1662 | case EXIT_APPLICATION: |
| 1663 | if (mInitialApplication != null) { |
| 1664 | mInitialApplication.onTerminate(); |
| 1665 | } |
| 1666 | Looper.myLooper().quit(); |
| 1667 | break; |
| 1668 | case NEW_INTENT: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1669 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityNewIntent"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1670 | handleNewIntent((NewIntentData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1671 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1672 | break; |
| 1673 | case RECEIVER: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1674 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "broadcastReceiveComp"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1675 | handleReceiver((ReceiverData)msg.obj); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1676 | maybeSnapshot(); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1677 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1678 | break; |
| 1679 | case CREATE_SERVICE: |
Tim Murray | b6f5a42 | 2016-04-07 15:25:22 -0700 | [diff] [blame] | 1680 | 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] | 1681 | handleCreateService((CreateServiceData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1682 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1683 | break; |
| 1684 | case BIND_SERVICE: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1685 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "serviceBind"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1686 | handleBindService((BindServiceData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1687 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1688 | break; |
| 1689 | case UNBIND_SERVICE: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1690 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "serviceUnbind"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1691 | handleUnbindService((BindServiceData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1692 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1693 | break; |
| 1694 | case SERVICE_ARGS: |
Tim Murray | b6f5a42 | 2016-04-07 15:25:22 -0700 | [diff] [blame] | 1695 | 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] | 1696 | handleServiceArgs((ServiceArgsData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1697 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1698 | break; |
| 1699 | case STOP_SERVICE: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1700 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "serviceStop"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1701 | handleStopService((IBinder)msg.obj); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1702 | maybeSnapshot(); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1703 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1704 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1705 | case CONFIGURATION_CHANGED: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1706 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "configChanged"); |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 1707 | mCurDefaultDisplayDpi = ((Configuration)msg.obj).densityDpi; |
Chong Zhang | 4951f9d | 2016-06-23 13:15:08 -0700 | [diff] [blame] | 1708 | mUpdatingSystemConfig = true; |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 1709 | try { |
| 1710 | handleConfigurationChanged((Configuration) msg.obj, null); |
| 1711 | } finally { |
| 1712 | mUpdatingSystemConfig = false; |
| 1713 | } |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1714 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1715 | break; |
| 1716 | case CLEAN_UP_CONTEXT: |
| 1717 | ContextCleanupInfo cci = (ContextCleanupInfo)msg.obj; |
| 1718 | cci.context.performFinalCleanup(cci.who, cci.what); |
| 1719 | break; |
| 1720 | case GC_WHEN_IDLE: |
| 1721 | scheduleGcIdler(); |
| 1722 | break; |
| 1723 | case DUMP_SERVICE: |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1724 | handleDumpService((DumpComponentInfo)msg.obj); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1725 | break; |
| 1726 | case LOW_MEMORY: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1727 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "lowMemory"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1728 | handleLowMemory(); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1729 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1730 | break; |
| 1731 | case ACTIVITY_CONFIGURATION_CHANGED: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1732 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityConfigChanged"); |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 1733 | handleActivityConfigurationChanged((ActivityConfigChangeData) msg.obj, |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 1734 | INVALID_DISPLAY); |
| 1735 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
| 1736 | break; |
| 1737 | case ACTIVITY_MOVED_TO_DISPLAY: |
| 1738 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityMovedToDisplay"); |
| 1739 | handleActivityConfigurationChanged((ActivityConfigChangeData) msg.obj, |
| 1740 | msg.arg1 /* displayId */); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1741 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1742 | break; |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 1743 | case PROFILER_CONTROL: |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 1744 | handleProfilerControl(msg.arg1 != 0, (ProfilerInfo)msg.obj, msg.arg2); |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 1745 | break; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1746 | case CREATE_BACKUP_AGENT: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1747 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "backupCreateAgent"); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1748 | handleCreateBackupAgent((CreateBackupAgentData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1749 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1750 | break; |
| 1751 | case DESTROY_BACKUP_AGENT: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1752 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "backupDestroyAgent"); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1753 | handleDestroyBackupAgent((CreateBackupAgentData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1754 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1755 | break; |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 1756 | case SUICIDE: |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1757 | Process.killProcess(Process.myPid()); |
| 1758 | break; |
| 1759 | case REMOVE_PROVIDER: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1760 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "providerRemove"); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1761 | completeRemoveProvider((ProviderRefCount)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1762 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 1763 | break; |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 1764 | case ENABLE_JIT: |
| 1765 | ensureJitEnabled(); |
| 1766 | break; |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1767 | case DISPATCH_PACKAGE_BROADCAST: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1768 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "broadcastPackage"); |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1769 | handleDispatchPackageBroadcast(msg.arg1, (String[])msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1770 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1771 | break; |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 1772 | case SCHEDULE_CRASH: |
| 1773 | throw new RemoteServiceException((String)msg.obj); |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 1774 | case DUMP_HEAP: |
| 1775 | handleDumpHeap(msg.arg1 != 0, (DumpHeapData)msg.obj); |
| 1776 | break; |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1777 | case DUMP_ACTIVITY: |
| 1778 | handleDumpActivity((DumpComponentInfo)msg.obj); |
| 1779 | break; |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1780 | case DUMP_PROVIDER: |
| 1781 | handleDumpProvider((DumpComponentInfo)msg.obj); |
| 1782 | break; |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1783 | case SLEEPING: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1784 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "sleeping"); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1785 | handleSleeping((IBinder)msg.obj, msg.arg1 != 0); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1786 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1787 | break; |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1788 | case SET_CORE_SETTINGS: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1789 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "setCoreSettings"); |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1790 | handleSetCoreSettings((Bundle) msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1791 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1792 | break; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1793 | case UPDATE_PACKAGE_COMPATIBILITY_INFO: |
| 1794 | handleUpdatePackageCompatibilityInfo((UpdateCompatibilityData)msg.obj); |
Dianne Hackborn | f0754f5b | 2011-07-21 16:02:07 -0700 | [diff] [blame] | 1795 | break; |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1796 | case TRIM_MEMORY: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1797 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "trimMemory"); |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1798 | handleTrimMemory(msg.arg1); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1799 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Dianne Hackborn | f0754f5b | 2011-07-21 16:02:07 -0700 | [diff] [blame] | 1800 | break; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1801 | case UNSTABLE_PROVIDER_DIED: |
| 1802 | handleUnstableProviderDied((IBinder)msg.obj, false); |
| 1803 | break; |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 1804 | case REQUEST_ASSIST_CONTEXT_EXTRAS: |
| 1805 | handleRequestAssistContextExtras((RequestAssistContextExtras)msg.obj); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 1806 | break; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1807 | case TRANSLUCENT_CONVERSION_COMPLETE: |
| 1808 | handleTranslucentConversionComplete((IBinder)msg.obj, msg.arg1 == 1); |
| 1809 | break; |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 1810 | case INSTALL_PROVIDER: |
| 1811 | handleInstallProvider((ProviderInfo) msg.obj); |
| 1812 | break; |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1813 | case ON_NEW_ACTIVITY_OPTIONS: |
| 1814 | Pair<IBinder, ActivityOptions> pair = (Pair<IBinder, ActivityOptions>) msg.obj; |
| 1815 | onNewActivityOptions(pair.first, pair.second); |
Dake Gu | 7ef70b0 | 2014-07-08 18:37:12 -0700 | [diff] [blame] | 1816 | break; |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 1817 | case CANCEL_VISIBLE_BEHIND: |
| 1818 | handleCancelVisibleBehind((IBinder) msg.obj); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 1819 | break; |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 1820 | case BACKGROUND_VISIBLE_BEHIND_CHANGED: |
| 1821 | handleOnBackgroundVisibleBehindChanged((IBinder) msg.obj, msg.arg1 > 0); |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1822 | break; |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 1823 | case ENTER_ANIMATION_COMPLETE: |
| 1824 | handleEnterAnimationComplete((IBinder) msg.obj); |
| 1825 | break; |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 1826 | case START_BINDER_TRACKING: |
| 1827 | handleStartBinderTracking(); |
| 1828 | break; |
| 1829 | case STOP_BINDER_TRACKING_AND_DUMP: |
| 1830 | handleStopBinderTrackingAndDump((ParcelFileDescriptor) msg.obj); |
| 1831 | break; |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 1832 | case MULTI_WINDOW_MODE_CHANGED: |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 1833 | handleMultiWindowModeChanged((IBinder) ((SomeArgs) msg.obj).arg1, |
| 1834 | ((SomeArgs) msg.obj).argi1 == 1, |
| 1835 | (Configuration) ((SomeArgs) msg.obj).arg2); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 1836 | break; |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 1837 | case PICTURE_IN_PICTURE_MODE_CHANGED: |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 1838 | handlePictureInPictureModeChanged((IBinder) ((SomeArgs) msg.obj).arg1, |
| 1839 | ((SomeArgs) msg.obj).argi1 == 1, |
| 1840 | (Configuration) ((SomeArgs) msg.obj).arg2); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 1841 | break; |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1842 | case LOCAL_VOICE_INTERACTION_STARTED: |
| 1843 | handleLocalVoiceInteractionStarted((IBinder) ((SomeArgs) msg.obj).arg1, |
| 1844 | (IVoiceInteractor) ((SomeArgs) msg.obj).arg2); |
Amith Yamasani | 6101911 | 2017-01-10 15:05:00 -0800 | [diff] [blame] | 1845 | break; |
Leonard Mosescu | f3409ce | 2016-10-06 17:32:05 -0700 | [diff] [blame] | 1846 | case ATTACH_AGENT: |
| 1847 | handleAttachAgent((String) msg.obj); |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1848 | break; |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 1849 | case APPLICATION_INFO_CHANGED: |
| 1850 | mUpdatingSystemConfig = true; |
| 1851 | try { |
| 1852 | handleApplicationInfoChanged((ApplicationInfo) msg.obj); |
| 1853 | } finally { |
| 1854 | mUpdatingSystemConfig = false; |
| 1855 | } |
| 1856 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1857 | } |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1858 | Object obj = msg.obj; |
| 1859 | if (obj instanceof SomeArgs) { |
| 1860 | ((SomeArgs) obj).recycle(); |
| 1861 | } |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 1862 | 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] | 1863 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1864 | |
Brian Carlstrom | ed7e007 | 2011-03-24 13:27:57 -0700 | [diff] [blame] | 1865 | private void maybeSnapshot() { |
| 1866 | if (mBoundApplication != null && SamplingProfilerIntegration.isEnabled()) { |
Sen Hu | bde7570 | 2010-05-28 01:54:03 -0700 | [diff] [blame] | 1867 | // convert the *private* ActivityThread.PackageInfo to *public* known |
| 1868 | // android.content.pm.PackageInfo |
| 1869 | String packageName = mBoundApplication.info.mPackageName; |
| 1870 | android.content.pm.PackageInfo packageInfo = null; |
| 1871 | try { |
| 1872 | Context context = getSystemContext(); |
| 1873 | if(context == null) { |
| 1874 | Log.e(TAG, "cannot get a valid context"); |
| 1875 | return; |
| 1876 | } |
| 1877 | PackageManager pm = context.getPackageManager(); |
| 1878 | if(pm == null) { |
| 1879 | Log.e(TAG, "cannot get a valid PackageManager"); |
| 1880 | return; |
| 1881 | } |
| 1882 | packageInfo = pm.getPackageInfo( |
| 1883 | packageName, PackageManager.GET_ACTIVITIES); |
| 1884 | } catch (NameNotFoundException e) { |
| 1885 | Log.e(TAG, "cannot get package info for " + packageName, e); |
| 1886 | } |
| 1887 | SamplingProfilerIntegration.writeSnapshot(mBoundApplication.processName, packageInfo); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1888 | } |
| 1889 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1890 | } |
| 1891 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1892 | private class Idler implements MessageQueue.IdleHandler { |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 1893 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1894 | public final boolean queueIdle() { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1895 | ActivityClientRecord a = mNewActivities; |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 1896 | boolean stopProfiling = false; |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 1897 | if (mBoundApplication != null && mProfiler.profileFd != null |
| 1898 | && mProfiler.autoStopProfiler) { |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 1899 | stopProfiling = true; |
| 1900 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1901 | if (a != null) { |
| 1902 | mNewActivities = null; |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 1903 | IActivityManager am = ActivityManager.getService(); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1904 | ActivityClientRecord prev; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1905 | do { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 1906 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1907 | TAG, "Reporting idle of " + a + |
| 1908 | " finished=" + |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1909 | (a.activity != null && a.activity.mFinished)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1910 | if (a.activity != null && !a.activity.mFinished) { |
| 1911 | try { |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 1912 | am.activityIdle(a.token, a.createdConfig, stopProfiling); |
Dianne Hackborn | e88846e | 2009-09-30 21:34:25 -0700 | [diff] [blame] | 1913 | a.createdConfig = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1914 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1915 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1916 | } |
| 1917 | } |
| 1918 | prev = a; |
| 1919 | a = a.nextIdle; |
| 1920 | prev.nextIdle = null; |
| 1921 | } while (a != null); |
| 1922 | } |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 1923 | if (stopProfiling) { |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 1924 | mProfiler.stopProfiling(); |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 1925 | } |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 1926 | ensureJitEnabled(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1927 | return false; |
| 1928 | } |
| 1929 | } |
| 1930 | |
| 1931 | final class GcIdler implements MessageQueue.IdleHandler { |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 1932 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1933 | public final boolean queueIdle() { |
| 1934 | doGcIfNeeded(); |
| 1935 | return false; |
| 1936 | } |
| 1937 | } |
| 1938 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1939 | public static ActivityThread currentActivityThread() { |
Jeff Sharkey | 66a017b | 2013-01-17 18:18:22 -0800 | [diff] [blame] | 1940 | return sCurrentActivityThread; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1941 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1942 | |
Wale Ogunwale | 9a6ef1e | 2015-06-02 13:41:00 -0700 | [diff] [blame] | 1943 | public static boolean isSystem() { |
| 1944 | return (sCurrentActivityThread != null) ? sCurrentActivityThread.mSystemThread : false; |
| 1945 | } |
| 1946 | |
Svetoslav | fbf0eca | 2015-05-01 16:52:41 -0700 | [diff] [blame] | 1947 | public static String currentOpPackageName() { |
| 1948 | ActivityThread am = currentActivityThread(); |
| 1949 | return (am != null && am.getApplication() != null) |
| 1950 | ? am.getApplication().getOpPackageName() : null; |
| 1951 | } |
| 1952 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1953 | public static String currentPackageName() { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1954 | ActivityThread am = currentActivityThread(); |
| 1955 | return (am != null && am.mBoundApplication != null) |
Dianne Hackborn | b57a50b | 2013-04-11 17:29:32 -0700 | [diff] [blame] | 1956 | ? am.mBoundApplication.appInfo.packageName : null; |
| 1957 | } |
| 1958 | |
| 1959 | public static String currentProcessName() { |
| 1960 | ActivityThread am = currentActivityThread(); |
| 1961 | return (am != null && am.mBoundApplication != null) |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1962 | ? am.mBoundApplication.processName : null; |
| 1963 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1964 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1965 | public static Application currentApplication() { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1966 | ActivityThread am = currentActivityThread(); |
| 1967 | return am != null ? am.mInitialApplication : null; |
| 1968 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1969 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1970 | public static IPackageManager getPackageManager() { |
| 1971 | if (sPackageManager != null) { |
| 1972 | //Slog.v("PackageManager", "returning cur default = " + sPackageManager); |
| 1973 | return sPackageManager; |
| 1974 | } |
| 1975 | IBinder b = ServiceManager.getService("package"); |
| 1976 | //Slog.v("PackageManager", "default service binder = " + b); |
| 1977 | sPackageManager = IPackageManager.Stub.asInterface(b); |
| 1978 | //Slog.v("PackageManager", "default service = " + sPackageManager); |
| 1979 | return sPackageManager; |
| 1980 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1981 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1982 | private Configuration mMainThreadConfig = new Configuration(); |
Amith Yamasani | 4f128e4 | 2016-05-10 11:44:12 -0700 | [diff] [blame] | 1983 | |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 1984 | Configuration applyConfigCompatMainThread(int displayDensity, Configuration config, |
| 1985 | CompatibilityInfo compat) { |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1986 | if (config == null) { |
| 1987 | return null; |
| 1988 | } |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 1989 | if (!compat.supportsScreen()) { |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1990 | mMainThreadConfig.setTo(config); |
| 1991 | config = mMainThreadConfig; |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 1992 | compat.applyToConfiguration(displayDensity, config); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1993 | } |
| 1994 | return config; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1995 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1996 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1997 | /** |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 1998 | * Creates the top level resources for the given package. Will return an existing |
| 1999 | * Resources if one has already been created. |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2000 | */ |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 2001 | Resources getTopLevelResources(String resDir, String[] splitResDirs, String[] overlayDirs, |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 2002 | String[] libDirs, int displayId, LoadedApk pkgInfo) { |
| 2003 | return mResourcesManager.getResources(null, resDir, splitResDirs, overlayDirs, libDirs, |
| 2004 | displayId, null, pkgInfo.getCompatibilityInfo(), pkgInfo.getClassLoader()); |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 2005 | } |
| 2006 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2007 | final Handler getHandler() { |
| 2008 | return mH; |
| 2009 | } |
| 2010 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2011 | public final LoadedApk getPackageInfo(String packageName, CompatibilityInfo compatInfo, |
| 2012 | int flags) { |
Amith Yamasani | 98edc95 | 2012-09-25 14:09:27 -0700 | [diff] [blame] | 2013 | return getPackageInfo(packageName, compatInfo, flags, UserHandle.myUserId()); |
| 2014 | } |
| 2015 | |
| 2016 | public final LoadedApk getPackageInfo(String packageName, CompatibilityInfo compatInfo, |
| 2017 | int flags, int userId) { |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 2018 | final boolean differentUser = (UserHandle.myUserId() != userId); |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 2019 | synchronized (mResourcesManager) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2020 | WeakReference<LoadedApk> ref; |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 2021 | if (differentUser) { |
| 2022 | // Caching not supported across users |
| 2023 | ref = null; |
| 2024 | } else if ((flags & Context.CONTEXT_INCLUDE_CODE) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2025 | ref = mPackages.get(packageName); |
| 2026 | } else { |
| 2027 | ref = mResourcePackages.get(packageName); |
| 2028 | } |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 2029 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2030 | LoadedApk packageInfo = ref != null ? ref.get() : null; |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2031 | //Slog.i(TAG, "getPackageInfo " + packageName + ": " + packageInfo); |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 2032 | //if (packageInfo != null) Slog.i(TAG, "isUptoDate " + packageInfo.mResDir |
| 2033 | // + ": " + packageInfo.mResources.getAssets().isUpToDate()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2034 | if (packageInfo != null && (packageInfo.mResources == null |
| 2035 | || packageInfo.mResources.getAssets().isUpToDate())) { |
| 2036 | if (packageInfo.isSecurityViolation() |
| 2037 | && (flags&Context.CONTEXT_IGNORE_SECURITY) == 0) { |
| 2038 | throw new SecurityException( |
| 2039 | "Requesting code from " + packageName |
| 2040 | + " to be run in process " |
| 2041 | + mBoundApplication.processName |
| 2042 | + "/" + mBoundApplication.appInfo.uid); |
| 2043 | } |
| 2044 | return packageInfo; |
| 2045 | } |
| 2046 | } |
| 2047 | |
| 2048 | ApplicationInfo ai = null; |
| 2049 | try { |
| 2050 | ai = getPackageManager().getApplicationInfo(packageName, |
Jeff Sharkey | c5967e9 | 2016-01-07 18:50:29 -0700 | [diff] [blame] | 2051 | PackageManager.GET_SHARED_LIBRARY_FILES |
| 2052 | | PackageManager.MATCH_DEBUG_TRIAGED_MISSING, |
| 2053 | userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2054 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2055 | throw e.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2056 | } |
| 2057 | |
| 2058 | if (ai != null) { |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2059 | return getPackageInfo(ai, compatInfo, flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2060 | } |
| 2061 | |
| 2062 | return null; |
| 2063 | } |
| 2064 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2065 | public final LoadedApk getPackageInfo(ApplicationInfo ai, CompatibilityInfo compatInfo, |
| 2066 | int flags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2067 | boolean includeCode = (flags&Context.CONTEXT_INCLUDE_CODE) != 0; |
| 2068 | boolean securityViolation = includeCode && ai.uid != 0 |
| 2069 | && ai.uid != Process.SYSTEM_UID && (mBoundApplication != null |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 2070 | ? !UserHandle.isSameApp(ai.uid, mBoundApplication.appInfo.uid) |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 2071 | : true); |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 2072 | boolean registerPackage = includeCode && (flags&Context.CONTEXT_REGISTER_PACKAGE) != 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2073 | if ((flags&(Context.CONTEXT_INCLUDE_CODE |
| 2074 | |Context.CONTEXT_IGNORE_SECURITY)) |
| 2075 | == Context.CONTEXT_INCLUDE_CODE) { |
| 2076 | if (securityViolation) { |
| 2077 | String msg = "Requesting code from " + ai.packageName |
| 2078 | + " (with uid " + ai.uid + ")"; |
| 2079 | if (mBoundApplication != null) { |
| 2080 | msg = msg + " to be run in process " |
| 2081 | + mBoundApplication.processName + " (with uid " |
| 2082 | + mBoundApplication.appInfo.uid + ")"; |
| 2083 | } |
| 2084 | throw new SecurityException(msg); |
| 2085 | } |
| 2086 | } |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 2087 | return getPackageInfo(ai, compatInfo, null, securityViolation, includeCode, |
| 2088 | registerPackage); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2089 | } |
| 2090 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2091 | public final LoadedApk getPackageInfoNoCheck(ApplicationInfo ai, |
| 2092 | CompatibilityInfo compatInfo) { |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 2093 | return getPackageInfo(ai, compatInfo, null, false, true, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2094 | } |
| 2095 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2096 | public final LoadedApk peekPackageInfo(String packageName, boolean includeCode) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 2097 | synchronized (mResourcesManager) { |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2098 | WeakReference<LoadedApk> ref; |
| 2099 | if (includeCode) { |
| 2100 | ref = mPackages.get(packageName); |
| 2101 | } else { |
| 2102 | ref = mResourcePackages.get(packageName); |
| 2103 | } |
| 2104 | return ref != null ? ref.get() : null; |
| 2105 | } |
| 2106 | } |
| 2107 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 2108 | private LoadedApk getPackageInfo(ApplicationInfo aInfo, CompatibilityInfo compatInfo, |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 2109 | ClassLoader baseLoader, boolean securityViolation, boolean includeCode, |
| 2110 | boolean registerPackage) { |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 2111 | final boolean differentUser = (UserHandle.myUserId() != UserHandle.getUserId(aInfo.uid)); |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 2112 | synchronized (mResourcesManager) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2113 | WeakReference<LoadedApk> ref; |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 2114 | if (differentUser) { |
| 2115 | // Caching not supported across users |
| 2116 | ref = null; |
| 2117 | } else if (includeCode) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2118 | ref = mPackages.get(aInfo.packageName); |
| 2119 | } else { |
| 2120 | ref = mResourcePackages.get(aInfo.packageName); |
| 2121 | } |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 2122 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2123 | LoadedApk packageInfo = ref != null ? ref.get() : null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2124 | if (packageInfo == null || (packageInfo.mResources != null |
| 2125 | && !packageInfo.mResources.getAssets().isUpToDate())) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2126 | if (localLOGV) Slog.v(TAG, (includeCode ? "Loading code package " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2127 | : "Loading resource-only package ") + aInfo.packageName |
| 2128 | + " (in " + (mBoundApplication != null |
| 2129 | ? mBoundApplication.processName : null) |
| 2130 | + ")"); |
| 2131 | packageInfo = |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 2132 | new LoadedApk(this, aInfo, compatInfo, baseLoader, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2133 | securityViolation, includeCode && |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 2134 | (aInfo.flags&ApplicationInfo.FLAG_HAS_CODE) != 0, registerPackage); |
Narayan Kamath | cb38318 | 2014-10-29 17:56:42 +0000 | [diff] [blame] | 2135 | |
| 2136 | if (mSystemThread && "android".equals(aInfo.packageName)) { |
| 2137 | packageInfo.installSystemApplicationInfo(aInfo, |
| 2138 | getSystemContext().mPackageInfo.getClassLoader()); |
| 2139 | } |
| 2140 | |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 2141 | if (differentUser) { |
| 2142 | // Caching not supported across users |
| 2143 | } else if (includeCode) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2144 | mPackages.put(aInfo.packageName, |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2145 | new WeakReference<LoadedApk>(packageInfo)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2146 | } else { |
| 2147 | mResourcePackages.put(aInfo.packageName, |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2148 | new WeakReference<LoadedApk>(packageInfo)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2149 | } |
| 2150 | } |
| 2151 | return packageInfo; |
| 2152 | } |
| 2153 | } |
| 2154 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2155 | ActivityThread() { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 2156 | mResourcesManager = ResourcesManager.getInstance(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2157 | } |
| 2158 | |
| 2159 | public ApplicationThread getApplicationThread() |
| 2160 | { |
| 2161 | return mAppThread; |
| 2162 | } |
| 2163 | |
| 2164 | public Instrumentation getInstrumentation() |
| 2165 | { |
| 2166 | return mInstrumentation; |
| 2167 | } |
| 2168 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2169 | public boolean isProfiling() { |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 2170 | return mProfiler != null && mProfiler.profileFile != null |
| 2171 | && mProfiler.profileFd == null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2172 | } |
| 2173 | |
| 2174 | public String getProfileFilePath() { |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 2175 | return mProfiler.profileFile; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2176 | } |
| 2177 | |
| 2178 | public Looper getLooper() { |
| 2179 | return mLooper; |
| 2180 | } |
| 2181 | |
| 2182 | public Application getApplication() { |
| 2183 | return mInitialApplication; |
| 2184 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2185 | |
Dianne Hackborn | d97c7ad | 2009-06-19 11:37:35 -0700 | [diff] [blame] | 2186 | public String getProcessName() { |
| 2187 | return mBoundApplication.processName; |
| 2188 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2189 | |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 2190 | public ContextImpl getSystemContext() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2191 | synchronized (this) { |
| 2192 | if (mSystemContext == null) { |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 2193 | mSystemContext = ContextImpl.createSystemContext(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2194 | } |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 2195 | return mSystemContext; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2196 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2197 | } |
| 2198 | |
Adam Lesinski | a82b626 | 2017-03-21 16:56:17 -0700 | [diff] [blame] | 2199 | public ContextImpl getSystemUiContext() { |
| 2200 | synchronized (this) { |
| 2201 | if (mSystemUiContext == null) { |
| 2202 | mSystemUiContext = ContextImpl.createSystemUiContext(this); |
| 2203 | } |
| 2204 | return mSystemUiContext; |
| 2205 | } |
| 2206 | } |
| 2207 | |
Narayan Kamath | 29564cd | 2014-08-07 10:57:40 +0100 | [diff] [blame] | 2208 | public void installSystemApplicationInfo(ApplicationInfo info, ClassLoader classLoader) { |
Mike Cleron | 432b713 | 2009-09-24 15:28:29 -0700 | [diff] [blame] | 2209 | synchronized (this) { |
Narayan Kamath | 29564cd | 2014-08-07 10:57:40 +0100 | [diff] [blame] | 2210 | getSystemContext().installSystemApplicationInfo(info, classLoader); |
Adam Lesinski | a82b626 | 2017-03-21 16:56:17 -0700 | [diff] [blame] | 2211 | getSystemUiContext().installSystemApplicationInfo(info, classLoader); |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 2212 | |
| 2213 | // give ourselves a default profiler |
| 2214 | mProfiler = new Profiler(); |
Mike Cleron | 432b713 | 2009-09-24 15:28:29 -0700 | [diff] [blame] | 2215 | } |
| 2216 | } |
| 2217 | |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 2218 | void ensureJitEnabled() { |
| 2219 | if (!mJitEnabled) { |
| 2220 | mJitEnabled = true; |
| 2221 | dalvik.system.VMRuntime.getRuntime().startJitCompilation(); |
| 2222 | } |
| 2223 | } |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 2224 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2225 | void scheduleGcIdler() { |
| 2226 | if (!mGcIdlerScheduled) { |
| 2227 | mGcIdlerScheduled = true; |
| 2228 | Looper.myQueue().addIdleHandler(mGcIdler); |
| 2229 | } |
| 2230 | mH.removeMessages(H.GC_WHEN_IDLE); |
| 2231 | } |
| 2232 | |
| 2233 | void unscheduleGcIdler() { |
| 2234 | if (mGcIdlerScheduled) { |
| 2235 | mGcIdlerScheduled = false; |
| 2236 | Looper.myQueue().removeIdleHandler(mGcIdler); |
| 2237 | } |
| 2238 | mH.removeMessages(H.GC_WHEN_IDLE); |
| 2239 | } |
| 2240 | |
| 2241 | void doGcIfNeeded() { |
| 2242 | mGcIdlerScheduled = false; |
| 2243 | final long now = SystemClock.uptimeMillis(); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2244 | //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] | 2245 | // + "m now=" + now); |
| 2246 | if ((BinderInternal.getLastGcTime()+MIN_TIME_BETWEEN_GCS) < now) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2247 | //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] | 2248 | BinderInternal.forceGc("bg"); |
| 2249 | } |
| 2250 | } |
| 2251 | |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2252 | private static final String HEAP_FULL_COLUMN |
| 2253 | = "%13s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s"; |
| 2254 | private static final String HEAP_COLUMN |
| 2255 | = "%13s %8s %8s %8s %8s %8s %8s %8s"; |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2256 | private static final String ONE_COUNT_COLUMN = "%21s %8d"; |
| 2257 | private static final String TWO_COUNT_COLUMNS = "%21s %8d %21s %8d"; |
| 2258 | private static final String ONE_COUNT_COLUMN_HEADER = "%21s %8s"; |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2259 | |
| 2260 | // Formatting for checkin service - update version if row format changes |
Martijn Coenen | 41f94ed | 2015-12-14 15:28:51 +0100 | [diff] [blame] | 2261 | private static final int ACTIVITY_THREAD_CHECKIN_VERSION = 4; |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2262 | |
| 2263 | static void printRow(PrintWriter pw, String format, Object...objs) { |
| 2264 | pw.println(String.format(format, objs)); |
| 2265 | } |
| 2266 | |
| 2267 | public static void dumpMemInfoTable(PrintWriter pw, Debug.MemoryInfo memInfo, boolean checkin, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2268 | boolean dumpFullInfo, boolean dumpDalvik, boolean dumpSummaryOnly, |
| 2269 | int pid, String processName, |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2270 | long nativeMax, long nativeAllocated, long nativeFree, |
| 2271 | long dalvikMax, long dalvikAllocated, long dalvikFree) { |
| 2272 | |
| 2273 | // For checkin, we print one long comma-separated list of values |
| 2274 | if (checkin) { |
| 2275 | // NOTE: if you change anything significant below, also consider changing |
| 2276 | // ACTIVITY_THREAD_CHECKIN_VERSION. |
| 2277 | |
| 2278 | // Header |
| 2279 | pw.print(ACTIVITY_THREAD_CHECKIN_VERSION); pw.print(','); |
| 2280 | pw.print(pid); pw.print(','); |
| 2281 | pw.print(processName); pw.print(','); |
| 2282 | |
| 2283 | // Heap info - max |
| 2284 | pw.print(nativeMax); pw.print(','); |
| 2285 | pw.print(dalvikMax); pw.print(','); |
| 2286 | pw.print("N/A,"); |
| 2287 | pw.print(nativeMax + dalvikMax); pw.print(','); |
| 2288 | |
| 2289 | // Heap info - allocated |
| 2290 | pw.print(nativeAllocated); pw.print(','); |
| 2291 | pw.print(dalvikAllocated); pw.print(','); |
| 2292 | pw.print("N/A,"); |
| 2293 | pw.print(nativeAllocated + dalvikAllocated); pw.print(','); |
| 2294 | |
| 2295 | // Heap info - free |
| 2296 | pw.print(nativeFree); pw.print(','); |
| 2297 | pw.print(dalvikFree); pw.print(','); |
| 2298 | pw.print("N/A,"); |
| 2299 | pw.print(nativeFree + dalvikFree); pw.print(','); |
| 2300 | |
| 2301 | // Heap info - proportional set size |
| 2302 | pw.print(memInfo.nativePss); pw.print(','); |
| 2303 | pw.print(memInfo.dalvikPss); pw.print(','); |
| 2304 | pw.print(memInfo.otherPss); pw.print(','); |
| 2305 | pw.print(memInfo.getTotalPss()); pw.print(','); |
| 2306 | |
| 2307 | // Heap info - swappable set size |
| 2308 | pw.print(memInfo.nativeSwappablePss); pw.print(','); |
| 2309 | pw.print(memInfo.dalvikSwappablePss); pw.print(','); |
| 2310 | pw.print(memInfo.otherSwappablePss); pw.print(','); |
| 2311 | pw.print(memInfo.getTotalSwappablePss()); pw.print(','); |
| 2312 | |
| 2313 | // Heap info - shared dirty |
| 2314 | pw.print(memInfo.nativeSharedDirty); pw.print(','); |
| 2315 | pw.print(memInfo.dalvikSharedDirty); pw.print(','); |
| 2316 | pw.print(memInfo.otherSharedDirty); pw.print(','); |
| 2317 | pw.print(memInfo.getTotalSharedDirty()); pw.print(','); |
| 2318 | |
| 2319 | // Heap info - shared clean |
| 2320 | pw.print(memInfo.nativeSharedClean); pw.print(','); |
| 2321 | pw.print(memInfo.dalvikSharedClean); pw.print(','); |
| 2322 | pw.print(memInfo.otherSharedClean); pw.print(','); |
| 2323 | pw.print(memInfo.getTotalSharedClean()); pw.print(','); |
| 2324 | |
| 2325 | // Heap info - private Dirty |
| 2326 | pw.print(memInfo.nativePrivateDirty); pw.print(','); |
| 2327 | pw.print(memInfo.dalvikPrivateDirty); pw.print(','); |
| 2328 | pw.print(memInfo.otherPrivateDirty); pw.print(','); |
| 2329 | pw.print(memInfo.getTotalPrivateDirty()); pw.print(','); |
| 2330 | |
| 2331 | // Heap info - private Clean |
| 2332 | pw.print(memInfo.nativePrivateClean); pw.print(','); |
| 2333 | pw.print(memInfo.dalvikPrivateClean); pw.print(','); |
| 2334 | pw.print(memInfo.otherPrivateClean); pw.print(','); |
| 2335 | pw.print(memInfo.getTotalPrivateClean()); pw.print(','); |
| 2336 | |
Martijn Coenen | 41f94ed | 2015-12-14 15:28:51 +0100 | [diff] [blame] | 2337 | // Heap info - swapped out |
| 2338 | pw.print(memInfo.nativeSwappedOut); pw.print(','); |
| 2339 | pw.print(memInfo.dalvikSwappedOut); pw.print(','); |
| 2340 | pw.print(memInfo.otherSwappedOut); pw.print(','); |
| 2341 | pw.print(memInfo.getTotalSwappedOut()); pw.print(','); |
| 2342 | |
| 2343 | // Heap info - swapped out pss |
| 2344 | if (memInfo.hasSwappedOutPss) { |
| 2345 | pw.print(memInfo.nativeSwappedOutPss); pw.print(','); |
| 2346 | pw.print(memInfo.dalvikSwappedOutPss); pw.print(','); |
| 2347 | pw.print(memInfo.otherSwappedOutPss); pw.print(','); |
| 2348 | pw.print(memInfo.getTotalSwappedOutPss()); pw.print(','); |
| 2349 | } else { |
| 2350 | pw.print("N/A,"); |
| 2351 | pw.print("N/A,"); |
| 2352 | pw.print("N/A,"); |
| 2353 | pw.print("N/A,"); |
| 2354 | } |
| 2355 | |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2356 | // Heap info - other areas |
| 2357 | for (int i=0; i<Debug.MemoryInfo.NUM_OTHER_STATS; i++) { |
| 2358 | pw.print(Debug.MemoryInfo.getOtherLabel(i)); pw.print(','); |
| 2359 | pw.print(memInfo.getOtherPss(i)); pw.print(','); |
| 2360 | pw.print(memInfo.getOtherSwappablePss(i)); pw.print(','); |
| 2361 | pw.print(memInfo.getOtherSharedDirty(i)); pw.print(','); |
| 2362 | pw.print(memInfo.getOtherSharedClean(i)); pw.print(','); |
| 2363 | pw.print(memInfo.getOtherPrivateDirty(i)); pw.print(','); |
| 2364 | pw.print(memInfo.getOtherPrivateClean(i)); pw.print(','); |
Martijn Coenen | 41f94ed | 2015-12-14 15:28:51 +0100 | [diff] [blame] | 2365 | pw.print(memInfo.getOtherSwappedOut(i)); pw.print(','); |
| 2366 | if (memInfo.hasSwappedOutPss) { |
| 2367 | pw.print(memInfo.getOtherSwappedOutPss(i)); pw.print(','); |
| 2368 | } else { |
| 2369 | pw.print("N/A,"); |
| 2370 | } |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2371 | } |
| 2372 | return; |
| 2373 | } |
| 2374 | |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2375 | if (!dumpSummaryOnly) { |
| 2376 | if (dumpFullInfo) { |
| 2377 | printRow(pw, HEAP_FULL_COLUMN, "", "Pss", "Pss", "Shared", "Private", |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2378 | "Shared", "Private", memInfo.hasSwappedOutPss ? "SwapPss" : "Swap", |
| 2379 | "Heap", "Heap", "Heap"); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2380 | printRow(pw, HEAP_FULL_COLUMN, "", "Total", "Clean", "Dirty", "Dirty", |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2381 | "Clean", "Clean", "Dirty", |
| 2382 | "Size", "Alloc", "Free"); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2383 | printRow(pw, HEAP_FULL_COLUMN, "", "------", "------", "------", "------", |
| 2384 | "------", "------", "------", "------", "------", "------"); |
| 2385 | printRow(pw, HEAP_FULL_COLUMN, "Native Heap", memInfo.nativePss, |
| 2386 | memInfo.nativeSwappablePss, memInfo.nativeSharedDirty, |
| 2387 | memInfo.nativePrivateDirty, memInfo.nativeSharedClean, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2388 | memInfo.nativePrivateClean, memInfo.hasSwappedOutPss ? |
| 2389 | memInfo.nativeSwappedOut : memInfo.nativeSwappedOutPss, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2390 | nativeMax, nativeAllocated, nativeFree); |
| 2391 | printRow(pw, HEAP_FULL_COLUMN, "Dalvik Heap", memInfo.dalvikPss, |
| 2392 | memInfo.dalvikSwappablePss, memInfo.dalvikSharedDirty, |
| 2393 | memInfo.dalvikPrivateDirty, memInfo.dalvikSharedClean, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2394 | memInfo.dalvikPrivateClean, memInfo.hasSwappedOutPss ? |
| 2395 | memInfo.dalvikSwappedOut : memInfo.dalvikSwappedOutPss, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2396 | dalvikMax, dalvikAllocated, dalvikFree); |
| 2397 | } else { |
| 2398 | printRow(pw, HEAP_COLUMN, "", "Pss", "Private", |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2399 | "Private", memInfo.hasSwappedOutPss ? "SwapPss" : "Swap", |
| 2400 | "Heap", "Heap", "Heap"); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2401 | printRow(pw, HEAP_COLUMN, "", "Total", "Dirty", |
| 2402 | "Clean", "Dirty", "Size", "Alloc", "Free"); |
| 2403 | printRow(pw, HEAP_COLUMN, "", "------", "------", "------", |
| 2404 | "------", "------", "------", "------", "------"); |
| 2405 | printRow(pw, HEAP_COLUMN, "Native Heap", memInfo.nativePss, |
| 2406 | memInfo.nativePrivateDirty, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2407 | memInfo.nativePrivateClean, |
| 2408 | memInfo.hasSwappedOutPss ? memInfo.nativeSwappedOutPss : |
| 2409 | memInfo.nativeSwappedOut, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2410 | nativeMax, nativeAllocated, nativeFree); |
| 2411 | printRow(pw, HEAP_COLUMN, "Dalvik Heap", memInfo.dalvikPss, |
| 2412 | memInfo.dalvikPrivateDirty, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2413 | memInfo.dalvikPrivateClean, |
| 2414 | memInfo.hasSwappedOutPss ? memInfo.dalvikSwappedOutPss : |
| 2415 | memInfo.dalvikSwappedOut, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2416 | dalvikMax, dalvikAllocated, dalvikFree); |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2417 | } |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2418 | |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2419 | int otherPss = memInfo.otherPss; |
| 2420 | int otherSwappablePss = memInfo.otherSwappablePss; |
| 2421 | int otherSharedDirty = memInfo.otherSharedDirty; |
| 2422 | int otherPrivateDirty = memInfo.otherPrivateDirty; |
| 2423 | int otherSharedClean = memInfo.otherSharedClean; |
| 2424 | int otherPrivateClean = memInfo.otherPrivateClean; |
| 2425 | int otherSwappedOut = memInfo.otherSwappedOut; |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2426 | int otherSwappedOutPss = memInfo.otherSwappedOutPss; |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2427 | |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2428 | for (int i=0; i<Debug.MemoryInfo.NUM_OTHER_STATS; i++) { |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2429 | final int myPss = memInfo.getOtherPss(i); |
| 2430 | final int mySwappablePss = memInfo.getOtherSwappablePss(i); |
| 2431 | final int mySharedDirty = memInfo.getOtherSharedDirty(i); |
| 2432 | final int myPrivateDirty = memInfo.getOtherPrivateDirty(i); |
| 2433 | final int mySharedClean = memInfo.getOtherSharedClean(i); |
| 2434 | final int myPrivateClean = memInfo.getOtherPrivateClean(i); |
| 2435 | final int mySwappedOut = memInfo.getOtherSwappedOut(i); |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2436 | final int mySwappedOutPss = memInfo.getOtherSwappedOutPss(i); |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2437 | if (myPss != 0 || mySharedDirty != 0 || myPrivateDirty != 0 |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2438 | || mySharedClean != 0 || myPrivateClean != 0 |
| 2439 | || (memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut) != 0) { |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2440 | if (dumpFullInfo) { |
| 2441 | printRow(pw, HEAP_FULL_COLUMN, Debug.MemoryInfo.getOtherLabel(i), |
| 2442 | myPss, mySwappablePss, mySharedDirty, myPrivateDirty, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2443 | mySharedClean, myPrivateClean, |
| 2444 | memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut, |
| 2445 | "", "", ""); |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2446 | } else { |
| 2447 | printRow(pw, HEAP_COLUMN, Debug.MemoryInfo.getOtherLabel(i), |
| 2448 | myPss, myPrivateDirty, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2449 | myPrivateClean, |
| 2450 | memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut, |
| 2451 | "", "", ""); |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2452 | } |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2453 | otherPss -= myPss; |
| 2454 | otherSwappablePss -= mySwappablePss; |
| 2455 | otherSharedDirty -= mySharedDirty; |
| 2456 | otherPrivateDirty -= myPrivateDirty; |
| 2457 | otherSharedClean -= mySharedClean; |
| 2458 | otherPrivateClean -= myPrivateClean; |
| 2459 | otherSwappedOut -= mySwappedOut; |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2460 | otherSwappedOutPss -= mySwappedOutPss; |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2461 | } |
| 2462 | } |
| 2463 | |
| 2464 | if (dumpFullInfo) { |
| 2465 | printRow(pw, HEAP_FULL_COLUMN, "Unknown", otherPss, otherSwappablePss, |
| 2466 | otherSharedDirty, otherPrivateDirty, otherSharedClean, otherPrivateClean, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2467 | memInfo.hasSwappedOutPss ? otherSwappedOutPss : otherSwappedOut, |
| 2468 | "", "", ""); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2469 | printRow(pw, HEAP_FULL_COLUMN, "TOTAL", memInfo.getTotalPss(), |
| 2470 | memInfo.getTotalSwappablePss(), |
| 2471 | memInfo.getTotalSharedDirty(), memInfo.getTotalPrivateDirty(), |
| 2472 | memInfo.getTotalSharedClean(), memInfo.getTotalPrivateClean(), |
Thierry Strudel | 9b51160 | 2016-02-25 17:46:38 -0800 | [diff] [blame] | 2473 | memInfo.hasSwappedOutPss ? memInfo.getTotalSwappedOutPss() : |
| 2474 | memInfo.getTotalSwappedOut(), |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2475 | nativeMax+dalvikMax, nativeAllocated+dalvikAllocated, |
| 2476 | nativeFree+dalvikFree); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2477 | } else { |
| 2478 | printRow(pw, HEAP_COLUMN, "Unknown", otherPss, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2479 | otherPrivateDirty, otherPrivateClean, |
| 2480 | memInfo.hasSwappedOutPss ? otherSwappedOutPss : otherSwappedOut, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2481 | "", "", ""); |
| 2482 | printRow(pw, HEAP_COLUMN, "TOTAL", memInfo.getTotalPss(), |
| 2483 | memInfo.getTotalPrivateDirty(), |
| 2484 | memInfo.getTotalPrivateClean(), |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2485 | memInfo.hasSwappedOutPss ? memInfo.getTotalSwappedOutPss() : |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2486 | memInfo.getTotalSwappedOut(), |
| 2487 | nativeMax+dalvikMax, |
| 2488 | nativeAllocated+dalvikAllocated, nativeFree+dalvikFree); |
| 2489 | } |
| 2490 | |
| 2491 | if (dumpDalvik) { |
| 2492 | pw.println(" "); |
| 2493 | pw.println(" Dalvik Details"); |
| 2494 | |
| 2495 | for (int i=Debug.MemoryInfo.NUM_OTHER_STATS; |
| 2496 | i<Debug.MemoryInfo.NUM_OTHER_STATS + Debug.MemoryInfo.NUM_DVK_STATS; i++) { |
| 2497 | final int myPss = memInfo.getOtherPss(i); |
| 2498 | final int mySwappablePss = memInfo.getOtherSwappablePss(i); |
| 2499 | final int mySharedDirty = memInfo.getOtherSharedDirty(i); |
| 2500 | final int myPrivateDirty = memInfo.getOtherPrivateDirty(i); |
| 2501 | final int mySharedClean = memInfo.getOtherSharedClean(i); |
| 2502 | final int myPrivateClean = memInfo.getOtherPrivateClean(i); |
| 2503 | final int mySwappedOut = memInfo.getOtherSwappedOut(i); |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2504 | final int mySwappedOutPss = memInfo.getOtherSwappedOutPss(i); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2505 | if (myPss != 0 || mySharedDirty != 0 || myPrivateDirty != 0 |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2506 | || mySharedClean != 0 || myPrivateClean != 0 |
| 2507 | || (memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut) != 0) { |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2508 | if (dumpFullInfo) { |
| 2509 | printRow(pw, HEAP_FULL_COLUMN, Debug.MemoryInfo.getOtherLabel(i), |
| 2510 | myPss, mySwappablePss, mySharedDirty, myPrivateDirty, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2511 | mySharedClean, myPrivateClean, |
| 2512 | memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut, |
| 2513 | "", "", ""); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2514 | } else { |
| 2515 | printRow(pw, HEAP_COLUMN, Debug.MemoryInfo.getOtherLabel(i), |
| 2516 | myPss, myPrivateDirty, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2517 | myPrivateClean, |
| 2518 | memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut, |
| 2519 | "", "", ""); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2520 | } |
| 2521 | } |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2522 | } |
| 2523 | } |
| 2524 | } |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2525 | |
| 2526 | pw.println(" "); |
| 2527 | pw.println(" App Summary"); |
| 2528 | printRow(pw, ONE_COUNT_COLUMN_HEADER, "", "Pss(KB)"); |
| 2529 | printRow(pw, ONE_COUNT_COLUMN_HEADER, "", "------"); |
| 2530 | printRow(pw, ONE_COUNT_COLUMN, |
| 2531 | "Java Heap:", memInfo.getSummaryJavaHeap()); |
| 2532 | printRow(pw, ONE_COUNT_COLUMN, |
| 2533 | "Native Heap:", memInfo.getSummaryNativeHeap()); |
| 2534 | printRow(pw, ONE_COUNT_COLUMN, |
| 2535 | "Code:", memInfo.getSummaryCode()); |
| 2536 | printRow(pw, ONE_COUNT_COLUMN, |
| 2537 | "Stack:", memInfo.getSummaryStack()); |
| 2538 | printRow(pw, ONE_COUNT_COLUMN, |
| 2539 | "Graphics:", memInfo.getSummaryGraphics()); |
| 2540 | printRow(pw, ONE_COUNT_COLUMN, |
| 2541 | "Private Other:", memInfo.getSummaryPrivateOther()); |
| 2542 | printRow(pw, ONE_COUNT_COLUMN, |
| 2543 | "System:", memInfo.getSummarySystem()); |
| 2544 | pw.println(" "); |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2545 | if (memInfo.hasSwappedOutPss) { |
| 2546 | printRow(pw, TWO_COUNT_COLUMNS, |
| 2547 | "TOTAL:", memInfo.getSummaryTotalPss(), |
| 2548 | "TOTAL SWAP PSS:", memInfo.getSummaryTotalSwapPss()); |
| 2549 | } else { |
| 2550 | printRow(pw, TWO_COUNT_COLUMNS, |
| 2551 | "TOTAL:", memInfo.getSummaryTotalPss(), |
| 2552 | "TOTAL SWAP (KB):", memInfo.getSummaryTotalSwap()); |
| 2553 | } |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2554 | } |
| 2555 | |
Jeff Hamilton | 52d3203 | 2011-01-08 15:31:26 -0600 | [diff] [blame] | 2556 | public void registerOnActivityPausedListener(Activity activity, |
| 2557 | OnActivityPausedListener listener) { |
| 2558 | synchronized (mOnPauseListeners) { |
| 2559 | ArrayList<OnActivityPausedListener> list = mOnPauseListeners.get(activity); |
| 2560 | if (list == null) { |
| 2561 | list = new ArrayList<OnActivityPausedListener>(); |
| 2562 | mOnPauseListeners.put(activity, list); |
| 2563 | } |
| 2564 | list.add(listener); |
| 2565 | } |
| 2566 | } |
| 2567 | |
Jeff Hamilton | ce3224c | 2011-01-17 11:05:03 -0800 | [diff] [blame] | 2568 | public void unregisterOnActivityPausedListener(Activity activity, |
| 2569 | OnActivityPausedListener listener) { |
| 2570 | synchronized (mOnPauseListeners) { |
| 2571 | ArrayList<OnActivityPausedListener> list = mOnPauseListeners.get(activity); |
| 2572 | if (list != null) { |
| 2573 | list.remove(listener); |
| 2574 | } |
| 2575 | } |
| 2576 | } |
| 2577 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2578 | public final ActivityInfo resolveActivityInfo(Intent intent) { |
| 2579 | ActivityInfo aInfo = intent.resolveActivityInfo( |
| 2580 | mInitialApplication.getPackageManager(), PackageManager.GET_SHARED_LIBRARY_FILES); |
| 2581 | if (aInfo == null) { |
| 2582 | // Throw an exception. |
| 2583 | Instrumentation.checkStartActivityResult( |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 2584 | ActivityManager.START_CLASS_NOT_FOUND, intent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2585 | } |
| 2586 | return aInfo; |
| 2587 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2588 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2589 | public final Activity startActivityNow(Activity parent, String id, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2590 | Intent intent, ActivityInfo activityInfo, IBinder token, Bundle state, |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 2591 | Activity.NonConfigurationInstances lastNonConfigurationInstances) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2592 | ActivityClientRecord r = new ActivityClientRecord(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2593 | r.token = token; |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 2594 | r.ident = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2595 | r.intent = intent; |
| 2596 | r.state = state; |
| 2597 | r.parent = parent; |
| 2598 | r.embeddedID = id; |
| 2599 | r.activityInfo = activityInfo; |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 2600 | r.lastNonConfigurationInstances = lastNonConfigurationInstances; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2601 | if (localLOGV) { |
| 2602 | ComponentName compname = intent.getComponent(); |
| 2603 | String name; |
| 2604 | if (compname != null) { |
| 2605 | name = compname.toShortString(); |
| 2606 | } else { |
| 2607 | name = "(Intent " + intent + ").getComponent() returned null"; |
| 2608 | } |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2609 | Slog.v(TAG, "Performing launch: action=" + intent.getAction() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2610 | + ", comp=" + name |
| 2611 | + ", token=" + token); |
| 2612 | } |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 2613 | return performLaunchActivity(r, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2614 | } |
| 2615 | |
| 2616 | public final Activity getActivity(IBinder token) { |
| 2617 | return mActivities.get(token).activity; |
| 2618 | } |
| 2619 | |
| 2620 | public final void sendActivityResult( |
| 2621 | IBinder token, String id, int requestCode, |
| 2622 | int resultCode, Intent data) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2623 | if (DEBUG_RESULTS) Slog.v(TAG, "sendActivityResult: id=" + id |
Chris Tate | 8a7dc17 | 2009-03-24 20:11:42 -0700 | [diff] [blame] | 2624 | + " req=" + requestCode + " res=" + resultCode + " data=" + data); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2625 | ArrayList<ResultInfo> list = new ArrayList<ResultInfo>(); |
| 2626 | list.add(new ResultInfo(id, requestCode, resultCode, data)); |
| 2627 | mAppThread.scheduleSendResult(token, list); |
| 2628 | } |
| 2629 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 2630 | private void sendMessage(int what, Object obj) { |
| 2631 | sendMessage(what, obj, 0, 0, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2632 | } |
| 2633 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 2634 | private void sendMessage(int what, Object obj, int arg1) { |
| 2635 | sendMessage(what, obj, arg1, 0, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2636 | } |
| 2637 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 2638 | private void sendMessage(int what, Object obj, int arg1, int arg2) { |
| 2639 | sendMessage(what, obj, arg1, arg2, false); |
| 2640 | } |
| 2641 | |
| 2642 | private void sendMessage(int what, Object obj, int arg1, int arg2, boolean async) { |
| 2643 | if (DEBUG_MESSAGES) Slog.v( |
| 2644 | TAG, "SCHEDULE " + what + " " + mH.codeToString(what) |
| 2645 | + ": " + arg1 + " / " + obj); |
| 2646 | Message msg = Message.obtain(); |
| 2647 | msg.what = what; |
| 2648 | msg.obj = obj; |
| 2649 | msg.arg1 = arg1; |
| 2650 | msg.arg2 = arg2; |
| 2651 | if (async) { |
| 2652 | msg.setAsynchronous(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2653 | } |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 2654 | mH.sendMessage(msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2655 | } |
| 2656 | |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 2657 | private void sendMessage(int what, Object obj, int arg1, int arg2, int seq) { |
| 2658 | if (DEBUG_MESSAGES) Slog.v( |
| 2659 | TAG, "SCHEDULE " + mH.codeToString(what) + " arg1=" + arg1 + " arg2=" + arg2 + |
| 2660 | "seq= " + seq); |
| 2661 | Message msg = Message.obtain(); |
| 2662 | msg.what = what; |
| 2663 | SomeArgs args = SomeArgs.obtain(); |
| 2664 | args.arg1 = obj; |
| 2665 | args.argi1 = arg1; |
| 2666 | args.argi2 = arg2; |
| 2667 | args.argi3 = seq; |
| 2668 | msg.obj = args; |
| 2669 | mH.sendMessage(msg); |
| 2670 | } |
| 2671 | |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 2672 | final void scheduleContextCleanup(ContextImpl context, String who, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2673 | String what) { |
| 2674 | ContextCleanupInfo cci = new ContextCleanupInfo(); |
| 2675 | cci.context = context; |
| 2676 | cci.who = who; |
| 2677 | cci.what = what; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 2678 | sendMessage(H.CLEAN_UP_CONTEXT, cci); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2679 | } |
| 2680 | |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 2681 | private Activity performLaunchActivity(ActivityClientRecord r, Intent customIntent) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2682 | // System.out.println("##### [" + System.currentTimeMillis() + "] ActivityThread.performLaunchActivity(" + r + ")"); |
| 2683 | |
| 2684 | ActivityInfo aInfo = r.activityInfo; |
| 2685 | if (r.packageInfo == null) { |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2686 | r.packageInfo = getPackageInfo(aInfo.applicationInfo, r.compatInfo, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2687 | Context.CONTEXT_INCLUDE_CODE); |
| 2688 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2689 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2690 | ComponentName component = r.intent.getComponent(); |
| 2691 | if (component == null) { |
| 2692 | component = r.intent.resolveActivity( |
| 2693 | mInitialApplication.getPackageManager()); |
| 2694 | r.intent.setComponent(component); |
| 2695 | } |
| 2696 | |
| 2697 | if (r.activityInfo.targetActivity != null) { |
| 2698 | component = new ComponentName(r.activityInfo.packageName, |
| 2699 | r.activityInfo.targetActivity); |
| 2700 | } |
| 2701 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 2702 | ContextImpl appContext = createBaseContextForActivity(r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2703 | Activity activity = null; |
| 2704 | try { |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 2705 | java.lang.ClassLoader cl = appContext.getClassLoader(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2706 | activity = mInstrumentation.newActivity( |
| 2707 | cl, component.getClassName(), r.intent); |
Brad Fitzpatrick | 5f8b5c1 | 2011-01-20 15:12:08 -0800 | [diff] [blame] | 2708 | StrictMode.incrementExpectedActivityCount(activity.getClass()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2709 | r.intent.setExtrasClassLoader(cl); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 2710 | r.intent.prepareToEnterProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2711 | if (r.state != null) { |
| 2712 | r.state.setClassLoader(cl); |
| 2713 | } |
| 2714 | } catch (Exception e) { |
| 2715 | if (!mInstrumentation.onException(activity, e)) { |
| 2716 | throw new RuntimeException( |
| 2717 | "Unable to instantiate activity " + component |
| 2718 | + ": " + e.toString(), e); |
| 2719 | } |
| 2720 | } |
| 2721 | |
| 2722 | try { |
Dianne Hackborn | 0be1f78 | 2009-11-09 12:30:12 -0800 | [diff] [blame] | 2723 | Application app = r.packageInfo.makeApplication(false, mInstrumentation); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2724 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2725 | if (localLOGV) Slog.v(TAG, "Performing launch of " + r); |
| 2726 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2727 | TAG, r + ": app=" + app |
| 2728 | + ", appName=" + app.getPackageName() |
| 2729 | + ", pkg=" + r.packageInfo.getPackageName() |
| 2730 | + ", comp=" + r.intent.getComponent().toShortString() |
| 2731 | + ", dir=" + r.packageInfo.getAppDir()); |
| 2732 | |
| 2733 | if (activity != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2734 | CharSequence title = r.activityInfo.loadLabel(appContext.getPackageManager()); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 2735 | Configuration config = new Configuration(mCompatConfiguration); |
Andrii Kulian | d0ad938 | 2016-04-18 20:54:20 -0700 | [diff] [blame] | 2736 | if (r.overrideConfig != null) { |
| 2737 | config.updateFrom(r.overrideConfig); |
| 2738 | } |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2739 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Launching activity " |
Dianne Hackborn | dc6b635 | 2009-09-30 14:20:09 -0700 | [diff] [blame] | 2740 | + r.activityInfo.name + " with config " + config); |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 2741 | Window window = null; |
| 2742 | if (r.mPendingRemoveWindow != null && r.mPreserveWindow) { |
| 2743 | window = r.mPendingRemoveWindow; |
| 2744 | r.mPendingRemoveWindow = null; |
| 2745 | r.mPendingRemoveWindowManager = null; |
| 2746 | } |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 2747 | appContext.setOuterContext(activity); |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 2748 | activity.attach(appContext, this, getInstrumentation(), r.token, |
| 2749 | r.ident, app, r.intent, r.activityInfo, title, r.parent, |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 2750 | r.embeddedID, r.lastNonConfigurationInstances, config, |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 2751 | r.referrer, r.voiceInteractor, window); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2752 | |
Christopher Tate | b70f3df | 2009-04-07 16:07:59 -0700 | [diff] [blame] | 2753 | if (customIntent != null) { |
| 2754 | activity.mIntent = customIntent; |
| 2755 | } |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 2756 | r.lastNonConfigurationInstances = null; |
Sudheer Shanka | 84a4895 | 2017-03-08 18:19:01 -0800 | [diff] [blame] | 2757 | checkAndBlockForNetworkAccess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2758 | activity.mStartedActivity = false; |
| 2759 | int theme = r.activityInfo.getThemeResource(); |
| 2760 | if (theme != 0) { |
| 2761 | activity.setTheme(theme); |
| 2762 | } |
| 2763 | |
| 2764 | activity.mCalled = false; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2765 | if (r.isPersistable()) { |
| 2766 | mInstrumentation.callActivityOnCreate(activity, r.state, r.persistentState); |
| 2767 | } else { |
| 2768 | mInstrumentation.callActivityOnCreate(activity, r.state); |
| 2769 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2770 | if (!activity.mCalled) { |
| 2771 | throw new SuperNotCalledException( |
| 2772 | "Activity " + r.intent.getComponent().toShortString() + |
| 2773 | " did not call through to super.onCreate()"); |
| 2774 | } |
| 2775 | r.activity = activity; |
| 2776 | r.stopped = true; |
| 2777 | if (!r.activity.mFinished) { |
| 2778 | activity.performStart(); |
| 2779 | r.stopped = false; |
| 2780 | } |
| 2781 | if (!r.activity.mFinished) { |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2782 | if (r.isPersistable()) { |
| 2783 | if (r.state != null || r.persistentState != null) { |
| 2784 | mInstrumentation.callActivityOnRestoreInstanceState(activity, r.state, |
| 2785 | r.persistentState); |
| 2786 | } |
| 2787 | } else if (r.state != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2788 | mInstrumentation.callActivityOnRestoreInstanceState(activity, r.state); |
| 2789 | } |
| 2790 | } |
| 2791 | if (!r.activity.mFinished) { |
| 2792 | activity.mCalled = false; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2793 | if (r.isPersistable()) { |
| 2794 | mInstrumentation.callActivityOnPostCreate(activity, r.state, |
| 2795 | r.persistentState); |
| 2796 | } else { |
| 2797 | mInstrumentation.callActivityOnPostCreate(activity, r.state); |
| 2798 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2799 | if (!activity.mCalled) { |
| 2800 | throw new SuperNotCalledException( |
| 2801 | "Activity " + r.intent.getComponent().toShortString() + |
| 2802 | " did not call through to super.onPostCreate()"); |
| 2803 | } |
| 2804 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2805 | } |
| 2806 | r.paused = true; |
| 2807 | |
| 2808 | mActivities.put(r.token, r); |
| 2809 | |
| 2810 | } catch (SuperNotCalledException e) { |
| 2811 | throw e; |
| 2812 | |
| 2813 | } catch (Exception e) { |
| 2814 | if (!mInstrumentation.onException(activity, e)) { |
| 2815 | throw new RuntimeException( |
| 2816 | "Unable to start activity " + component |
| 2817 | + ": " + e.toString(), e); |
| 2818 | } |
| 2819 | } |
| 2820 | |
| 2821 | return activity; |
| 2822 | } |
| 2823 | |
Sudheer Shanka | 84a4895 | 2017-03-08 18:19:01 -0800 | [diff] [blame] | 2824 | /** |
| 2825 | * Checks if {@link #mNetworkBlockSeq} is {@link #INVALID_PROC_STATE_SEQ} and if so, returns |
| 2826 | * immediately. Otherwise, makes a blocking call to ActivityManagerService to wait for the |
| 2827 | * network rules to get updated. |
| 2828 | */ |
| 2829 | private void checkAndBlockForNetworkAccess() { |
| 2830 | synchronized (mNetworkPolicyLock) { |
| 2831 | if (mNetworkBlockSeq != INVALID_PROC_STATE_SEQ) { |
| 2832 | try { |
| 2833 | ActivityManager.getService().waitForNetworkStateUpdate(mNetworkBlockSeq); |
| 2834 | mNetworkBlockSeq = INVALID_PROC_STATE_SEQ; |
| 2835 | } catch (RemoteException ignored) {} |
| 2836 | } |
| 2837 | } |
| 2838 | } |
| 2839 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 2840 | private ContextImpl createBaseContextForActivity(ActivityClientRecord r) { |
| 2841 | final int displayId; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2842 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 2843 | displayId = ActivityManager.getService().getActivityDisplayId(r.token); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2844 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2845 | throw e.rethrowFromSystemServer(); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2846 | } |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 2847 | |
Wale Ogunwale | 7c72668 | 2015-02-06 17:34:28 -0800 | [diff] [blame] | 2848 | ContextImpl appContext = ContextImpl.createActivityContext( |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 2849 | this, r.packageInfo, r.activityInfo, r.token, displayId, r.overrideConfig); |
Wale Ogunwale | 7c72668 | 2015-02-06 17:34:28 -0800 | [diff] [blame] | 2850 | |
| 2851 | final DisplayManagerGlobal dm = DisplayManagerGlobal.getInstance(); |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 2852 | // For debugging purposes, if the activity's package name contains the value of |
| 2853 | // the "debug.use-second-display" system property as a substring, then show |
| 2854 | // its content on a secondary display if there is one. |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 2855 | String pkgName = SystemProperties.get("debug.second-display.pkg"); |
| 2856 | if (pkgName != null && !pkgName.isEmpty() |
| 2857 | && r.packageInfo.mPackageName.contains(pkgName)) { |
Wale Ogunwale | 7c72668 | 2015-02-06 17:34:28 -0800 | [diff] [blame] | 2858 | for (int id : dm.getDisplayIds()) { |
| 2859 | if (id != Display.DEFAULT_DISPLAY) { |
Wale Ogunwale | 2669851 | 2015-06-05 16:55:33 -0700 | [diff] [blame] | 2860 | Display display = |
Bryce Lee | 609bf65 | 2017-02-09 16:50:13 -0800 | [diff] [blame] | 2861 | dm.getCompatibleDisplay(id, appContext.getResources()); |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 2862 | appContext = (ContextImpl) appContext.createDisplayContext(display); |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 2863 | break; |
| 2864 | } |
| 2865 | } |
| 2866 | } |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 2867 | return appContext; |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 2868 | } |
| 2869 | |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 2870 | private void handleLaunchActivity(ActivityClientRecord r, Intent customIntent, String reason) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2871 | // If we are getting ready to gc after going to the background, well |
| 2872 | // we are back active so skip it. |
| 2873 | unscheduleGcIdler(); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 2874 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2875 | |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 2876 | if (r.profilerInfo != null) { |
| 2877 | mProfiler.setProfiler(r.profilerInfo); |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 2878 | mProfiler.startProfiling(); |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 2879 | } |
| 2880 | |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 2881 | // Make sure we are running with the most recent config. |
| 2882 | handleConfigurationChanged(null, null); |
| 2883 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2884 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2885 | TAG, "Handling launch of " + r); |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 2886 | |
Chet Haase | 0d1c27a | 2014-11-03 18:35:16 +0000 | [diff] [blame] | 2887 | // Initialize before creating the activity |
| 2888 | WindowManagerGlobal.initialize(); |
| 2889 | |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 2890 | Activity a = performLaunchActivity(r, customIntent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2891 | |
| 2892 | if (a != null) { |
Dianne Hackborn | 871ecdc | 2009-12-11 15:24:33 -0800 | [diff] [blame] | 2893 | r.createdConfig = new Configuration(mConfiguration); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 2894 | reportSizeConfigurations(r); |
Dianne Hackborn | 9e0f5d9 | 2010-02-22 15:05:42 -0800 | [diff] [blame] | 2895 | Bundle oldState = r.state; |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 2896 | handleResumeActivity(r.token, false, r.isForward, |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 2897 | !r.activity.mFinished && !r.startsNotResumed, r.lastProcessedSeq, reason); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2898 | |
| 2899 | if (!r.activity.mFinished && r.startsNotResumed) { |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 2900 | // The activity manager actually wants this one to start out paused, because it |
| 2901 | // needs to be visible but isn't in the foreground. We accomplish this by going |
| 2902 | // through the normal startup (because activities expect to go through onResume() |
| 2903 | // the first time they run, before their window is displayed), and then pausing it. |
| 2904 | // However, in this case we do -not- need to do the full pause cycle (of freezing |
| 2905 | // and such) because the activity manager assumes it can just retain the current |
| 2906 | // state it has. |
| 2907 | performPauseActivityIfNeeded(r, reason); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2908 | |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 2909 | // We need to keep around the original state, in case we need to be created again. |
| 2910 | // But we only do this for pre-Honeycomb apps, which always save their state when |
| 2911 | // pausing, so we can not have them save their state when restarting from a paused |
| 2912 | // state. For HC and later, we want to (and can) let the state be saved as the |
| 2913 | // normal part of stopping the activity. |
| 2914 | if (r.isPreHoneycomb()) { |
| 2915 | r.state = oldState; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2916 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2917 | } |
| 2918 | } else { |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 2919 | // 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] | 2920 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 2921 | ActivityManager.getService() |
Wale Ogunwale | ba7881c | 2015-08-01 19:28:29 -0700 | [diff] [blame] | 2922 | .finishActivity(r.token, Activity.RESULT_CANCELED, null, |
| 2923 | Activity.DONT_FINISH_TASK_WITH_ACTIVITY); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2924 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2925 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2926 | } |
| 2927 | } |
| 2928 | } |
| 2929 | |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 2930 | private void reportSizeConfigurations(ActivityClientRecord r) { |
| 2931 | Configuration[] configurations = r.activity.getResources().getSizeConfigurations(); |
| 2932 | if (configurations == null) { |
| 2933 | return; |
| 2934 | } |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 2935 | SparseIntArray horizontal = new SparseIntArray(); |
| 2936 | SparseIntArray vertical = new SparseIntArray(); |
| 2937 | SparseIntArray smallest = new SparseIntArray(); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 2938 | for (int i = configurations.length - 1; i >= 0; i--) { |
| 2939 | Configuration config = configurations[i]; |
| 2940 | if (config.screenHeightDp != Configuration.SCREEN_HEIGHT_DP_UNDEFINED) { |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 2941 | vertical.put(config.screenHeightDp, 0); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 2942 | } |
| 2943 | if (config.screenWidthDp != Configuration.SCREEN_WIDTH_DP_UNDEFINED) { |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 2944 | horizontal.put(config.screenWidthDp, 0); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 2945 | } |
| 2946 | if (config.smallestScreenWidthDp != Configuration.SMALLEST_SCREEN_WIDTH_DP_UNDEFINED) { |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 2947 | smallest.put(config.smallestScreenWidthDp, 0); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 2948 | } |
| 2949 | } |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 2950 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 2951 | ActivityManager.getService().reportSizeConfigurations(r.token, |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 2952 | horizontal.copyKeys(), vertical.copyKeys(), smallest.copyKeys()); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 2953 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2954 | throw ex.rethrowFromSystemServer(); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 2955 | } |
| 2956 | |
| 2957 | } |
| 2958 | |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 2959 | private void deliverNewIntents(ActivityClientRecord r, List<ReferrerIntent> intents) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2960 | final int N = intents.size(); |
| 2961 | for (int i=0; i<N; i++) { |
Dianne Hackborn | a01a0fa | 2014-12-02 10:33:14 -0800 | [diff] [blame] | 2962 | ReferrerIntent intent = intents.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2963 | intent.setExtrasClassLoader(r.activity.getClassLoader()); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 2964 | intent.prepareToEnterProcess(); |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 2965 | r.activity.mFragments.noteStateNotSaved(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2966 | mInstrumentation.callActivityOnNewIntent(r.activity, intent); |
| 2967 | } |
| 2968 | } |
| 2969 | |
Wale Ogunwale | 826c706 | 2016-09-13 08:25:54 -0700 | [diff] [blame] | 2970 | void performNewIntents(IBinder token, List<ReferrerIntent> intents, boolean andPause) { |
| 2971 | final ActivityClientRecord r = mActivities.get(token); |
| 2972 | if (r == null) { |
| 2973 | return; |
| 2974 | } |
| 2975 | |
| 2976 | final boolean resumed = !r.paused; |
| 2977 | if (resumed) { |
| 2978 | r.activity.mTemporaryPause = true; |
| 2979 | mInstrumentation.callActivityOnPause(r.activity); |
| 2980 | } |
| 2981 | deliverNewIntents(r, intents); |
| 2982 | if (resumed) { |
| 2983 | r.activity.performResume(); |
| 2984 | r.activity.mTemporaryPause = false; |
| 2985 | } |
| 2986 | |
| 2987 | if (r.paused && andPause) { |
| 2988 | // In this case the activity was in the paused state when we delivered the intent, |
| 2989 | // to guarantee onResume gets called after onNewIntent we temporarily resume the |
| 2990 | // activity and pause again as the caller wanted. |
| 2991 | performResumeActivity(token, false, "performNewIntents"); |
| 2992 | performPauseActivityIfNeeded(r, "performNewIntents"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2993 | } |
| 2994 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2995 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 2996 | private void handleNewIntent(NewIntentData data) { |
Wale Ogunwale | 826c706 | 2016-09-13 08:25:54 -0700 | [diff] [blame] | 2997 | performNewIntents(data.token, data.intents, data.andPause); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2998 | } |
| 2999 | |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 3000 | public void handleRequestAssistContextExtras(RequestAssistContextExtras cmd) { |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 3001 | // Filling for autofill has a few differences: |
Felipe Leme | 1ca634a | 2016-11-28 17:21:21 -0800 | [diff] [blame] | 3002 | // - it does not need an AssistContent |
| 3003 | // - it does not call onProvideAssistData() |
| 3004 | // - it needs an IAutoFillCallback |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 3005 | boolean forAutofill = cmd.requestType == ActivityManager.ASSIST_CONTEXT_AUTOFILL; |
Felipe Leme | 1ca634a | 2016-11-28 17:21:21 -0800 | [diff] [blame] | 3006 | |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 3007 | // TODO(b/33197203): decide if lastSessionId logic applies to autofill sessions |
Amith Yamasani | 4f128e4 | 2016-05-10 11:44:12 -0700 | [diff] [blame] | 3008 | if (mLastSessionId != cmd.sessionId) { |
| 3009 | // Clear the existing structures |
| 3010 | mLastSessionId = cmd.sessionId; |
| 3011 | for (int i = mLastAssistStructures.size() - 1; i >= 0; i--) { |
| 3012 | AssistStructure structure = mLastAssistStructures.get(i).get(); |
| 3013 | if (structure != null) { |
| 3014 | structure.clearSendChannel(); |
| 3015 | } |
| 3016 | mLastAssistStructures.remove(i); |
Dianne Hackborn | 782d498 | 2015-07-08 17:36:37 -0700 | [diff] [blame] | 3017 | } |
| 3018 | } |
Felipe Leme | 29a5b0d | 2016-10-25 14:57:11 -0700 | [diff] [blame] | 3019 | |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 3020 | Bundle data = new Bundle(); |
Dianne Hackborn | 09d57fe | 2015-05-27 18:05:52 -0700 | [diff] [blame] | 3021 | AssistStructure structure = null; |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 3022 | AssistContent content = forAutofill ? null : new AssistContent(); |
Amith Yamasani | 858f98d | 2017-02-22 12:59:53 -0800 | [diff] [blame] | 3023 | final long startTime = SystemClock.uptimeMillis(); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 3024 | ActivityClientRecord r = mActivities.get(cmd.activityToken); |
Dianne Hackborn | a3acdb3 | 2015-06-08 17:07:40 -0700 | [diff] [blame] | 3025 | Uri referrer = null; |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 3026 | if (r != null) { |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 3027 | if (!forAutofill) { |
Felipe Leme | 1ca634a | 2016-11-28 17:21:21 -0800 | [diff] [blame] | 3028 | r.activity.getApplication().dispatchOnProvideAssistData(r.activity, data); |
Felipe Leme | 29a5b0d | 2016-10-25 14:57:11 -0700 | [diff] [blame] | 3029 | r.activity.onProvideAssistData(data); |
Felipe Leme | 6d55387 | 2016-12-08 17:13:25 -0800 | [diff] [blame] | 3030 | referrer = r.activity.onProvideReferrer(); |
Felipe Leme | 29a5b0d | 2016-10-25 14:57:11 -0700 | [diff] [blame] | 3031 | } |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 3032 | if (cmd.requestType == ActivityManager.ASSIST_CONTEXT_FULL || forAutofill) { |
| 3033 | structure = new AssistStructure(r.activity, forAutofill); |
Adam Skory | 4aaed14 | 2015-04-22 11:29:31 -0600 | [diff] [blame] | 3034 | Intent activityIntent = r.activity.getIntent(); |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 3035 | // TODO(b/33197203): re-evaluate conditions below for autofill. In particular, |
Felipe Leme | 1ca634a | 2016-11-28 17:21:21 -0800 | [diff] [blame] | 3036 | // FLAG_SECURE might be allowed on AUTO_FILL but not on AUTO_FILL_SAVE) |
Felipe Leme | 6d55387 | 2016-12-08 17:13:25 -0800 | [diff] [blame] | 3037 | boolean notSecure = r.window == null || |
Dianne Hackborn | 09d57fe | 2015-05-27 18:05:52 -0700 | [diff] [blame] | 3038 | (r.window.getAttributes().flags |
Felipe Leme | 6d55387 | 2016-12-08 17:13:25 -0800 | [diff] [blame] | 3039 | & WindowManager.LayoutParams.FLAG_SECURE) == 0; |
| 3040 | if (activityIntent != null && notSecure) { |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 3041 | if (!forAutofill) { |
Felipe Leme | 1ca634a | 2016-11-28 17:21:21 -0800 | [diff] [blame] | 3042 | Intent intent = new Intent(activityIntent); |
| 3043 | intent.setFlags(intent.getFlags() & ~(Intent.FLAG_GRANT_WRITE_URI_PERMISSION |
| 3044 | | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION)); |
| 3045 | intent.removeUnsafeExtras(); |
Felipe Leme | 29a5b0d | 2016-10-25 14:57:11 -0700 | [diff] [blame] | 3046 | content.setDefaultIntent(intent); |
| 3047 | } |
Adam Skory | 4aaed14 | 2015-04-22 11:29:31 -0600 | [diff] [blame] | 3048 | } else { |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 3049 | if (!forAutofill) { |
Felipe Leme | 29a5b0d | 2016-10-25 14:57:11 -0700 | [diff] [blame] | 3050 | content.setDefaultIntent(new Intent()); |
| 3051 | } |
Adam Skory | 4aaed14 | 2015-04-22 11:29:31 -0600 | [diff] [blame] | 3052 | } |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 3053 | if (!forAutofill) { |
Felipe Leme | 29a5b0d | 2016-10-25 14:57:11 -0700 | [diff] [blame] | 3054 | r.activity.onProvideAssistContent(content); |
| 3055 | } |
Dianne Hackborn | a83ce1d | 2015-03-11 15:16:13 -0700 | [diff] [blame] | 3056 | } |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 3057 | } |
Dianne Hackborn | 09d57fe | 2015-05-27 18:05:52 -0700 | [diff] [blame] | 3058 | if (structure == null) { |
| 3059 | structure = new AssistStructure(); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 3060 | } |
Felipe Leme | 0200d9e | 2017-01-24 15:10:26 -0800 | [diff] [blame] | 3061 | |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 3062 | // TODO(b/33197203): decide if lastSessionId logic applies to autofill sessions |
Amith Yamasani | 858f98d | 2017-02-22 12:59:53 -0800 | [diff] [blame] | 3063 | |
| 3064 | structure.setAcquisitionStartTime(startTime); |
| 3065 | structure.setAcquisitionEndTime(SystemClock.uptimeMillis()); |
| 3066 | |
Amith Yamasani | 4f128e4 | 2016-05-10 11:44:12 -0700 | [diff] [blame] | 3067 | mLastAssistStructures.add(new WeakReference<>(structure)); |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3068 | IActivityManager mgr = ActivityManager.getService(); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 3069 | try { |
Dianne Hackborn | a3acdb3 | 2015-06-08 17:07:40 -0700 | [diff] [blame] | 3070 | mgr.reportAssistContextExtras(cmd.requestToken, data, structure, content, referrer); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 3071 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3072 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 3073 | } |
| 3074 | } |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 3075 | |
| 3076 | public void handleTranslucentConversionComplete(IBinder token, boolean drawComplete) { |
| 3077 | ActivityClientRecord r = mActivities.get(token); |
| 3078 | if (r != null) { |
| 3079 | r.activity.onTranslucentConversionComplete(drawComplete); |
| 3080 | } |
| 3081 | } |
| 3082 | |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 3083 | public void onNewActivityOptions(IBinder token, ActivityOptions options) { |
| 3084 | ActivityClientRecord r = mActivities.get(token); |
| 3085 | if (r != null) { |
| 3086 | r.activity.onNewActivityOptions(options); |
| 3087 | } |
| 3088 | } |
| 3089 | |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3090 | public void handleCancelVisibleBehind(IBinder token) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3091 | ActivityClientRecord r = mActivities.get(token); |
| 3092 | if (r != null) { |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3093 | mSomeActivitiesChanged = true; |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3094 | final Activity activity = r.activity; |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3095 | if (activity.mVisibleBehind) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3096 | activity.mCalled = false; |
Jose Lima | fcf7083 | 2014-08-27 23:09:05 -0700 | [diff] [blame] | 3097 | activity.onVisibleBehindCanceled(); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3098 | // Tick, tick, tick. The activity has 500 msec to return or it will be destroyed. |
| 3099 | if (!activity.mCalled) { |
| 3100 | throw new SuperNotCalledException("Activity " + activity.getLocalClassName() + |
Jose Lima | fcf7083 | 2014-08-27 23:09:05 -0700 | [diff] [blame] | 3101 | " did not call through to super.onVisibleBehindCanceled()"); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3102 | } |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3103 | activity.mVisibleBehind = false; |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3104 | } |
| 3105 | } |
| 3106 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3107 | ActivityManager.getService().backgroundResourcesReleased(token); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3108 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3109 | throw e.rethrowFromSystemServer(); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3110 | } |
| 3111 | } |
| 3112 | |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3113 | public void handleOnBackgroundVisibleBehindChanged(IBinder token, boolean visible) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3114 | ActivityClientRecord r = mActivities.get(token); |
| 3115 | if (r != null) { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3116 | r.activity.onBackgroundVisibleBehindChanged(visible); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3117 | } |
| 3118 | } |
| 3119 | |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 3120 | public void handleInstallProvider(ProviderInfo info) { |
Jeff Sharkey | bb2e2ca | 2014-10-23 11:42:31 -0700 | [diff] [blame] | 3121 | final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); |
| 3122 | try { |
| 3123 | installContentProviders(mInitialApplication, Lists.newArrayList(info)); |
| 3124 | } finally { |
| 3125 | StrictMode.setThreadPolicy(oldPolicy); |
| 3126 | } |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 3127 | } |
| 3128 | |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 3129 | private void handleEnterAnimationComplete(IBinder token) { |
| 3130 | ActivityClientRecord r = mActivities.get(token); |
| 3131 | if (r != null) { |
Filip Gruszczynski | 6eafa90 | 2014-11-14 14:24:37 -0800 | [diff] [blame] | 3132 | r.activity.dispatchEnterAnimationComplete(); |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 3133 | } |
| 3134 | } |
| 3135 | |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 3136 | private void handleStartBinderTracking() { |
| 3137 | Binder.enableTracing(); |
| 3138 | } |
| 3139 | |
| 3140 | private void handleStopBinderTrackingAndDump(ParcelFileDescriptor fd) { |
| 3141 | try { |
| 3142 | Binder.disableTracing(); |
| 3143 | Binder.getTransactionTracker().writeTracesToFile(fd); |
| 3144 | } finally { |
| 3145 | IoUtils.closeQuietly(fd); |
| 3146 | Binder.getTransactionTracker().clearTraces(); |
| 3147 | } |
| 3148 | } |
| 3149 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 3150 | private void handleMultiWindowModeChanged(IBinder token, boolean isInMultiWindowMode, |
| 3151 | Configuration overrideConfig) { |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 3152 | final ActivityClientRecord r = mActivities.get(token); |
| 3153 | if (r != null) { |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 3154 | final Configuration newConfig = new Configuration(mConfiguration); |
| 3155 | if (overrideConfig != null) { |
| 3156 | newConfig.updateFrom(overrideConfig); |
| 3157 | } |
| 3158 | r.activity.dispatchMultiWindowModeChanged(isInMultiWindowMode, newConfig); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 3159 | } |
| 3160 | } |
| 3161 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 3162 | private void handlePictureInPictureModeChanged(IBinder token, boolean isInPipMode, |
| 3163 | Configuration overrideConfig) { |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 3164 | final ActivityClientRecord r = mActivities.get(token); |
| 3165 | if (r != null) { |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 3166 | final Configuration newConfig = new Configuration(mConfiguration); |
| 3167 | if (overrideConfig != null) { |
| 3168 | newConfig.updateFrom(overrideConfig); |
| 3169 | } |
| 3170 | r.activity.dispatchPictureInPictureModeChanged(isInPipMode, newConfig); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 3171 | } |
| 3172 | } |
| 3173 | |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 3174 | private void handleLocalVoiceInteractionStarted(IBinder token, IVoiceInteractor interactor) { |
| 3175 | final ActivityClientRecord r = mActivities.get(token); |
| 3176 | if (r != null) { |
| 3177 | r.voiceInteractor = interactor; |
| 3178 | r.activity.setVoiceInteractor(interactor); |
| 3179 | if (interactor == null) { |
| 3180 | r.activity.onLocalVoiceInteractionStopped(); |
| 3181 | } else { |
| 3182 | r.activity.onLocalVoiceInteractionStarted(); |
| 3183 | } |
| 3184 | } |
| 3185 | } |
| 3186 | |
Leonard Mosescu | f3409ce | 2016-10-06 17:32:05 -0700 | [diff] [blame] | 3187 | static final void handleAttachAgent(String agent) { |
| 3188 | try { |
| 3189 | VMDebug.attachAgent(agent); |
| 3190 | } catch (IOException e) { |
| 3191 | Slog.e(TAG, "Attaching agent failed: " + agent); |
| 3192 | } |
| 3193 | } |
| 3194 | |
Brad Fitzpatrick | bfb1919 | 2010-10-29 15:25:44 -0700 | [diff] [blame] | 3195 | private static final ThreadLocal<Intent> sCurrentBroadcastIntent = new ThreadLocal<Intent>(); |
| 3196 | |
| 3197 | /** |
| 3198 | * Return the Intent that's currently being handled by a |
| 3199 | * BroadcastReceiver on this thread, or null if none. |
| 3200 | * @hide |
| 3201 | */ |
| 3202 | public static Intent getIntentBeingBroadcast() { |
| 3203 | return sCurrentBroadcastIntent.get(); |
| 3204 | } |
| 3205 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3206 | private void handleReceiver(ReceiverData data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3207 | // If we are getting ready to gc after going to the background, well |
| 3208 | // we are back active so skip it. |
| 3209 | unscheduleGcIdler(); |
| 3210 | |
| 3211 | String component = data.intent.getComponent().getClassName(); |
| 3212 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3213 | LoadedApk packageInfo = getPackageInfoNoCheck( |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 3214 | data.info.applicationInfo, data.compatInfo); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3215 | |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3216 | IActivityManager mgr = ActivityManager.getService(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3217 | |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 3218 | Application app; |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3219 | BroadcastReceiver receiver; |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 3220 | ContextImpl context; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3221 | try { |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 3222 | app = packageInfo.makeApplication(false, mInstrumentation); |
| 3223 | context = (ContextImpl) app.getBaseContext(); |
| 3224 | if (data.info.splitName != null) { |
| 3225 | context = (ContextImpl) context.createContextForSplit(data.info.splitName); |
| 3226 | } |
| 3227 | java.lang.ClassLoader cl = context.getClassLoader(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3228 | data.intent.setExtrasClassLoader(cl); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 3229 | data.intent.prepareToEnterProcess(); |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 3230 | data.setExtrasClassLoader(cl); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3231 | receiver = (BroadcastReceiver)cl.loadClass(component).newInstance(); |
| 3232 | } catch (Exception e) { |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 3233 | if (DEBUG_BROADCAST) Slog.i(TAG, |
| 3234 | "Finishing failed broadcast to " + data.intent.getComponent()); |
| 3235 | data.sendFinished(mgr); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3236 | throw new RuntimeException( |
| 3237 | "Unable to instantiate receiver " + component |
| 3238 | + ": " + e.toString(), e); |
| 3239 | } |
| 3240 | |
| 3241 | try { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3242 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3243 | TAG, "Performing receive of " + data.intent |
| 3244 | + ": app=" + app |
| 3245 | + ", appName=" + app.getPackageName() |
| 3246 | + ", pkg=" + packageInfo.getPackageName() |
| 3247 | + ", comp=" + data.intent.getComponent().toShortString() |
| 3248 | + ", dir=" + packageInfo.getAppDir()); |
| 3249 | |
Brad Fitzpatrick | bfb1919 | 2010-10-29 15:25:44 -0700 | [diff] [blame] | 3250 | sCurrentBroadcastIntent.set(data.intent); |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 3251 | receiver.setPendingResult(data); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3252 | receiver.onReceive(context.getReceiverRestrictedContext(), |
| 3253 | data.intent); |
| 3254 | } catch (Exception e) { |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 3255 | if (DEBUG_BROADCAST) Slog.i(TAG, |
| 3256 | "Finishing failed broadcast to " + data.intent.getComponent()); |
| 3257 | data.sendFinished(mgr); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3258 | if (!mInstrumentation.onException(receiver, e)) { |
| 3259 | throw new RuntimeException( |
| 3260 | "Unable to start receiver " + component |
| 3261 | + ": " + e.toString(), e); |
| 3262 | } |
Brad Fitzpatrick | bfb1919 | 2010-10-29 15:25:44 -0700 | [diff] [blame] | 3263 | } finally { |
| 3264 | sCurrentBroadcastIntent.set(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3265 | } |
| 3266 | |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 3267 | if (receiver.getPendingResult() != null) { |
| 3268 | data.finish(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3269 | } |
| 3270 | } |
| 3271 | |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3272 | // Instantiate a BackupAgent and tell it that it's alive |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3273 | private void handleCreateBackupAgent(CreateBackupAgentData data) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3274 | if (DEBUG_BACKUP) Slog.v(TAG, "handleCreateBackupAgent: " + data); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3275 | |
Christopher Tate | 346acb1 | 2012-10-15 19:20:25 -0700 | [diff] [blame] | 3276 | // Sanity check the requested target package's uid against ours |
| 3277 | try { |
| 3278 | PackageInfo requestedPackage = getPackageManager().getPackageInfo( |
| 3279 | data.appInfo.packageName, 0, UserHandle.myUserId()); |
| 3280 | if (requestedPackage.applicationInfo.uid != Process.myUid()) { |
| 3281 | Slog.w(TAG, "Asked to instantiate non-matching package " |
| 3282 | + data.appInfo.packageName); |
| 3283 | return; |
| 3284 | } |
| 3285 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3286 | throw e.rethrowFromSystemServer(); |
Christopher Tate | 346acb1 | 2012-10-15 19:20:25 -0700 | [diff] [blame] | 3287 | } |
| 3288 | |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3289 | // no longer idle; we have backup work to do |
| 3290 | unscheduleGcIdler(); |
| 3291 | |
| 3292 | // instantiate the BackupAgent class named in the manifest |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 3293 | LoadedApk packageInfo = getPackageInfoNoCheck(data.appInfo, data.compatInfo); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3294 | String packageName = packageInfo.mPackageName; |
Christopher Tate | 346acb1 | 2012-10-15 19:20:25 -0700 | [diff] [blame] | 3295 | if (packageName == null) { |
| 3296 | Slog.d(TAG, "Asked to create backup agent for nonexistent package"); |
| 3297 | return; |
| 3298 | } |
| 3299 | |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3300 | String classname = data.appInfo.backupAgentName; |
Christopher Tate | 79ec80d | 2011-06-24 14:58:49 -0700 | [diff] [blame] | 3301 | // full backup operation but no app-supplied agent? use the default implementation |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 3302 | if (classname == null && (data.backupMode == ApplicationThreadConstants.BACKUP_MODE_FULL |
| 3303 | || data.backupMode == ApplicationThreadConstants.BACKUP_MODE_RESTORE_FULL)) { |
Christopher Tate | 4a627c7 | 2011-04-01 14:43:32 -0700 | [diff] [blame] | 3304 | classname = "android.app.backup.FullBackupAgent"; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3305 | } |
Christopher Tate | 4a627c7 | 2011-04-01 14:43:32 -0700 | [diff] [blame] | 3306 | |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3307 | try { |
Christopher Tate | d1475e0 | 2009-07-09 15:36:17 -0700 | [diff] [blame] | 3308 | IBinder binder = null; |
Christopher Tate | 2e40d11 | 2014-07-15 12:37:38 -0700 | [diff] [blame] | 3309 | BackupAgent agent = mBackupAgents.get(packageName); |
| 3310 | if (agent != null) { |
| 3311 | // reusing the existing instance |
| 3312 | if (DEBUG_BACKUP) { |
| 3313 | Slog.v(TAG, "Reusing existing agent instance"); |
Christopher Tate | d1475e0 | 2009-07-09 15:36:17 -0700 | [diff] [blame] | 3314 | } |
Christopher Tate | 2e40d11 | 2014-07-15 12:37:38 -0700 | [diff] [blame] | 3315 | binder = agent.onBind(); |
| 3316 | } else { |
| 3317 | try { |
| 3318 | if (DEBUG_BACKUP) Slog.v(TAG, "Initializing agent class " + classname); |
| 3319 | |
| 3320 | java.lang.ClassLoader cl = packageInfo.getClassLoader(); |
| 3321 | agent = (BackupAgent) cl.loadClass(classname).newInstance(); |
| 3322 | |
| 3323 | // set up the agent's context |
| 3324 | ContextImpl context = ContextImpl.createAppContext(this, packageInfo); |
| 3325 | context.setOuterContext(agent); |
| 3326 | agent.attach(context); |
| 3327 | |
| 3328 | agent.onCreate(); |
| 3329 | binder = agent.onBind(); |
| 3330 | mBackupAgents.put(packageName, agent); |
| 3331 | } catch (Exception e) { |
| 3332 | // If this is during restore, fail silently; otherwise go |
| 3333 | // ahead and let the user see the crash. |
| 3334 | Slog.e(TAG, "Agent threw during creation: " + e); |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 3335 | if (data.backupMode != ApplicationThreadConstants.BACKUP_MODE_RESTORE |
| 3336 | && data.backupMode != |
| 3337 | ApplicationThreadConstants.BACKUP_MODE_RESTORE_FULL) { |
Christopher Tate | 2e40d11 | 2014-07-15 12:37:38 -0700 | [diff] [blame] | 3338 | throw e; |
| 3339 | } |
| 3340 | // falling through with 'binder' still null |
| 3341 | } |
Christopher Tate | d1475e0 | 2009-07-09 15:36:17 -0700 | [diff] [blame] | 3342 | } |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3343 | |
| 3344 | // tell the OS that we're live now |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3345 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3346 | ActivityManager.getService().backupAgentCreated(packageName, binder); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3347 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3348 | throw e.rethrowFromSystemServer(); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3349 | } |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3350 | } catch (Exception e) { |
| 3351 | throw new RuntimeException("Unable to create BackupAgent " |
Christopher Tate | 4a627c7 | 2011-04-01 14:43:32 -0700 | [diff] [blame] | 3352 | + classname + ": " + e.toString(), e); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3353 | } |
| 3354 | } |
| 3355 | |
| 3356 | // Tear down a BackupAgent |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3357 | private void handleDestroyBackupAgent(CreateBackupAgentData data) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3358 | if (DEBUG_BACKUP) Slog.v(TAG, "handleDestroyBackupAgent: " + data); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3359 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 3360 | LoadedApk packageInfo = getPackageInfoNoCheck(data.appInfo, data.compatInfo); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3361 | String packageName = packageInfo.mPackageName; |
| 3362 | BackupAgent agent = mBackupAgents.get(packageName); |
| 3363 | if (agent != null) { |
| 3364 | try { |
| 3365 | agent.onDestroy(); |
| 3366 | } catch (Exception e) { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 3367 | 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] | 3368 | e.printStackTrace(); |
| 3369 | } |
| 3370 | mBackupAgents.remove(packageName); |
| 3371 | } else { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 3372 | Slog.w(TAG, "Attempt to destroy unknown backup agent " + data); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3373 | } |
| 3374 | } |
| 3375 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3376 | private void handleCreateService(CreateServiceData data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3377 | // If we are getting ready to gc after going to the background, well |
| 3378 | // we are back active so skip it. |
| 3379 | unscheduleGcIdler(); |
| 3380 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3381 | LoadedApk packageInfo = getPackageInfoNoCheck( |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 3382 | data.info.applicationInfo, data.compatInfo); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3383 | Service service = null; |
| 3384 | try { |
| 3385 | java.lang.ClassLoader cl = packageInfo.getClassLoader(); |
| 3386 | service = (Service) cl.loadClass(data.info.name).newInstance(); |
| 3387 | } catch (Exception e) { |
| 3388 | if (!mInstrumentation.onException(service, e)) { |
| 3389 | throw new RuntimeException( |
| 3390 | "Unable to instantiate service " + data.info.name |
| 3391 | + ": " + e.toString(), e); |
| 3392 | } |
| 3393 | } |
| 3394 | |
| 3395 | try { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3396 | 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] | 3397 | |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 3398 | ContextImpl context = ContextImpl.createAppContext(this, packageInfo); |
| 3399 | context.setOuterContext(service); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3400 | |
Dianne Hackborn | 0be1f78 | 2009-11-09 12:30:12 -0800 | [diff] [blame] | 3401 | Application app = packageInfo.makeApplication(false, mInstrumentation); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3402 | service.attach(context, this, data.info.name, data.token, app, |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3403 | ActivityManager.getService()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3404 | service.onCreate(); |
| 3405 | mServices.put(data.token, service); |
| 3406 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3407 | ActivityManager.getService().serviceDoneExecuting( |
Dianne Hackborn | 455625e | 2015-01-21 09:55:13 -0800 | [diff] [blame] | 3408 | data.token, SERVICE_DONE_EXECUTING_ANON, 0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3409 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3410 | throw e.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3411 | } |
| 3412 | } catch (Exception e) { |
| 3413 | if (!mInstrumentation.onException(service, e)) { |
| 3414 | throw new RuntimeException( |
| 3415 | "Unable to create service " + data.info.name |
| 3416 | + ": " + e.toString(), e); |
| 3417 | } |
| 3418 | } |
| 3419 | } |
| 3420 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3421 | private void handleBindService(BindServiceData data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3422 | Service s = mServices.get(data.token); |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 3423 | if (DEBUG_SERVICE) |
| 3424 | Slog.v(TAG, "handleBindService s=" + s + " rebind=" + data.rebind); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3425 | if (s != null) { |
| 3426 | try { |
| 3427 | data.intent.setExtrasClassLoader(s.getClassLoader()); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 3428 | data.intent.prepareToEnterProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3429 | try { |
| 3430 | if (!data.rebind) { |
| 3431 | IBinder binder = s.onBind(data.intent); |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3432 | ActivityManager.getService().publishService( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3433 | data.token, data.intent, binder); |
| 3434 | } else { |
| 3435 | s.onRebind(data.intent); |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3436 | ActivityManager.getService().serviceDoneExecuting( |
Dianne Hackborn | 455625e | 2015-01-21 09:55:13 -0800 | [diff] [blame] | 3437 | data.token, SERVICE_DONE_EXECUTING_ANON, 0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3438 | } |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 3439 | ensureJitEnabled(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3440 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3441 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3442 | } |
| 3443 | } catch (Exception e) { |
| 3444 | if (!mInstrumentation.onException(s, e)) { |
| 3445 | throw new RuntimeException( |
| 3446 | "Unable to bind to service " + s |
| 3447 | + " with " + data.intent + ": " + e.toString(), e); |
| 3448 | } |
| 3449 | } |
| 3450 | } |
| 3451 | } |
| 3452 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3453 | private void handleUnbindService(BindServiceData data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3454 | Service s = mServices.get(data.token); |
| 3455 | if (s != null) { |
| 3456 | try { |
| 3457 | data.intent.setExtrasClassLoader(s.getClassLoader()); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 3458 | data.intent.prepareToEnterProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3459 | boolean doRebind = s.onUnbind(data.intent); |
| 3460 | try { |
| 3461 | if (doRebind) { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3462 | ActivityManager.getService().unbindFinished( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3463 | data.token, data.intent, doRebind); |
| 3464 | } else { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3465 | ActivityManager.getService().serviceDoneExecuting( |
Dianne Hackborn | 455625e | 2015-01-21 09:55:13 -0800 | [diff] [blame] | 3466 | data.token, SERVICE_DONE_EXECUTING_ANON, 0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3467 | } |
| 3468 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3469 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3470 | } |
| 3471 | } catch (Exception e) { |
| 3472 | if (!mInstrumentation.onException(s, e)) { |
| 3473 | throw new RuntimeException( |
| 3474 | "Unable to unbind to service " + s |
| 3475 | + " with " + data.intent + ": " + e.toString(), e); |
| 3476 | } |
| 3477 | } |
| 3478 | } |
| 3479 | } |
| 3480 | |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 3481 | private void handleDumpService(DumpComponentInfo info) { |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3482 | final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); |
| 3483 | try { |
| 3484 | Service s = mServices.get(info.token); |
| 3485 | if (s != null) { |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 3486 | PrintWriter pw = new FastPrintWriter(new FileOutputStream( |
| 3487 | info.fd.getFileDescriptor())); |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3488 | s.dump(info.fd.getFileDescriptor(), pw, info.args); |
| 3489 | pw.flush(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3490 | } |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3491 | } finally { |
| 3492 | IoUtils.closeQuietly(info.fd); |
| 3493 | StrictMode.setThreadPolicy(oldPolicy); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3494 | } |
| 3495 | } |
| 3496 | |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 3497 | private void handleDumpActivity(DumpComponentInfo info) { |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3498 | final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); |
| 3499 | try { |
| 3500 | ActivityClientRecord r = mActivities.get(info.token); |
| 3501 | if (r != null && r.activity != null) { |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 3502 | PrintWriter pw = new FastPrintWriter(new FileOutputStream( |
| 3503 | info.fd.getFileDescriptor())); |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3504 | r.activity.dump(info.prefix, info.fd.getFileDescriptor(), pw, info.args); |
| 3505 | pw.flush(); |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 3506 | } |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3507 | } finally { |
| 3508 | IoUtils.closeQuietly(info.fd); |
| 3509 | StrictMode.setThreadPolicy(oldPolicy); |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 3510 | } |
| 3511 | } |
| 3512 | |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 3513 | private void handleDumpProvider(DumpComponentInfo info) { |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3514 | final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); |
| 3515 | try { |
| 3516 | ProviderClientRecord r = mLocalProviders.get(info.token); |
| 3517 | if (r != null && r.mLocalProvider != null) { |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 3518 | PrintWriter pw = new FastPrintWriter(new FileOutputStream( |
| 3519 | info.fd.getFileDescriptor())); |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3520 | r.mLocalProvider.dump(info.fd.getFileDescriptor(), pw, info.args); |
| 3521 | pw.flush(); |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 3522 | } |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3523 | } finally { |
| 3524 | IoUtils.closeQuietly(info.fd); |
| 3525 | StrictMode.setThreadPolicy(oldPolicy); |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 3526 | } |
| 3527 | } |
| 3528 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3529 | private void handleServiceArgs(ServiceArgsData data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3530 | Service s = mServices.get(data.token); |
| 3531 | if (s != null) { |
| 3532 | try { |
| 3533 | if (data.args != null) { |
| 3534 | data.args.setExtrasClassLoader(s.getClassLoader()); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 3535 | data.args.prepareToEnterProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3536 | } |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 3537 | int res; |
| 3538 | if (!data.taskRemoved) { |
| 3539 | res = s.onStartCommand(data.args, data.flags, data.startId); |
| 3540 | } else { |
| 3541 | s.onTaskRemoved(data.args); |
| 3542 | res = Service.START_TASK_REMOVED_COMPLETE; |
| 3543 | } |
Brad Fitzpatrick | 333b8cb | 2010-08-26 12:04:57 -0700 | [diff] [blame] | 3544 | |
| 3545 | QueuedWork.waitToFinish(); |
| 3546 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3547 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3548 | ActivityManager.getService().serviceDoneExecuting( |
Dianne Hackborn | 455625e | 2015-01-21 09:55:13 -0800 | [diff] [blame] | 3549 | data.token, SERVICE_DONE_EXECUTING_START, data.startId, res); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3550 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3551 | throw e.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3552 | } |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 3553 | ensureJitEnabled(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3554 | } catch (Exception e) { |
| 3555 | if (!mInstrumentation.onException(s, e)) { |
| 3556 | throw new RuntimeException( |
| 3557 | "Unable to start service " + s |
| 3558 | + " with " + data.args + ": " + e.toString(), e); |
| 3559 | } |
| 3560 | } |
| 3561 | } |
| 3562 | } |
| 3563 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3564 | private void handleStopService(IBinder token) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3565 | Service s = mServices.remove(token); |
| 3566 | if (s != null) { |
| 3567 | try { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3568 | if (localLOGV) Slog.v(TAG, "Destroying service " + s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3569 | s.onDestroy(); |
| 3570 | Context context = s.getBaseContext(); |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 3571 | if (context instanceof ContextImpl) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3572 | final String who = s.getClassName(); |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 3573 | ((ContextImpl) context).scheduleFinalCleanup(who, "Service"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3574 | } |
Brad Fitzpatrick | 333b8cb | 2010-08-26 12:04:57 -0700 | [diff] [blame] | 3575 | |
| 3576 | QueuedWork.waitToFinish(); |
| 3577 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3578 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3579 | ActivityManager.getService().serviceDoneExecuting( |
Dianne Hackborn | 455625e | 2015-01-21 09:55:13 -0800 | [diff] [blame] | 3580 | token, SERVICE_DONE_EXECUTING_STOP, 0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3581 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3582 | throw e.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3583 | } |
| 3584 | } catch (Exception e) { |
| 3585 | if (!mInstrumentation.onException(s, e)) { |
| 3586 | throw new RuntimeException( |
| 3587 | "Unable to stop service " + s |
| 3588 | + ": " + e.toString(), e); |
| 3589 | } |
Craig Mautner | 66c4a82 | 2015-01-16 12:48:16 -0800 | [diff] [blame] | 3590 | Slog.i(TAG, "handleStopService: exception for " + token, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3591 | } |
Craig Mautner | 9776ad4 | 2015-01-15 14:38:39 -0800 | [diff] [blame] | 3592 | } else { |
| 3593 | Slog.i(TAG, "handleStopService: token=" + token + " not found."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3594 | } |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3595 | //Slog.i(TAG, "Running services: " + mServices); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3596 | } |
| 3597 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3598 | public final ActivityClientRecord performResumeActivity(IBinder token, |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 3599 | boolean clearHide, String reason) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3600 | ActivityClientRecord r = mActivities.get(token); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3601 | if (localLOGV) Slog.v(TAG, "Performing resume of " + r |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3602 | + " finished=" + r.activity.mFinished); |
| 3603 | if (r != null && !r.activity.mFinished) { |
| 3604 | if (clearHide) { |
| 3605 | r.hideForNow = false; |
| 3606 | r.activity.mStartedActivity = false; |
| 3607 | } |
| 3608 | try { |
Dianne Hackborn | 6bdd3a1 | 2015-08-05 15:01:28 -0700 | [diff] [blame] | 3609 | r.activity.onStateNotSaved(); |
Dianne Hackborn | 689586d | 2012-10-01 18:23:04 -0700 | [diff] [blame] | 3610 | r.activity.mFragments.noteStateNotSaved(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3611 | if (r.pendingIntents != null) { |
| 3612 | deliverNewIntents(r, r.pendingIntents); |
| 3613 | r.pendingIntents = null; |
| 3614 | } |
| 3615 | if (r.pendingResults != null) { |
| 3616 | deliverResults(r, r.pendingResults); |
| 3617 | r.pendingResults = null; |
| 3618 | } |
| 3619 | r.activity.performResume(); |
| 3620 | |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 3621 | synchronized (mResourcesManager) { |
| 3622 | // If there is a pending local relaunch that was requested when the activity was |
| 3623 | // paused, it will put the activity into paused state when it finally happens. |
| 3624 | // Since the activity resumed before being relaunched, we don't want that to |
| 3625 | // happen, so we need to clear the request to relaunch paused. |
| 3626 | for (int i = mRelaunchingActivities.size() - 1; i >= 0; i--) { |
| 3627 | final ActivityClientRecord relaunching = mRelaunchingActivities.get(i); |
| 3628 | if (relaunching.token == r.token |
| 3629 | && relaunching.onlyLocalRequest && relaunching.startsNotResumed) { |
| 3630 | relaunching.startsNotResumed = false; |
| 3631 | } |
Filip Gruszczynski | c3b6179 | 2016-01-22 16:43:48 -0800 | [diff] [blame] | 3632 | } |
| 3633 | } |
| 3634 | |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 3635 | EventLog.writeEvent(LOG_AM_ON_RESUME_CALLED, UserHandle.myUserId(), |
| 3636 | r.activity.getComponentName().getClassName(), reason); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3637 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3638 | r.paused = false; |
| 3639 | r.stopped = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3640 | r.state = null; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3641 | r.persistentState = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3642 | } catch (Exception e) { |
| 3643 | if (!mInstrumentation.onException(r.activity, e)) { |
| 3644 | throw new RuntimeException( |
| 3645 | "Unable to resume activity " |
| 3646 | + r.intent.getComponent().toShortString() |
| 3647 | + ": " + e.toString(), e); |
| 3648 | } |
| 3649 | } |
| 3650 | } |
| 3651 | return r; |
| 3652 | } |
| 3653 | |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 3654 | static final void cleanUpPendingRemoveWindows(ActivityClientRecord r, boolean force) { |
| 3655 | if (r.mPreserveWindow && !force) { |
| 3656 | return; |
| 3657 | } |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 3658 | if (r.mPendingRemoveWindow != null) { |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 3659 | r.mPendingRemoveWindowManager.removeViewImmediate( |
| 3660 | r.mPendingRemoveWindow.getDecorView()); |
| 3661 | IBinder wtoken = r.mPendingRemoveWindow.getDecorView().getWindowToken(); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 3662 | if (wtoken != null) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 3663 | WindowManagerGlobal.getInstance().closeAll(wtoken, |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 3664 | r.activity.getClass().getName(), "Activity"); |
| 3665 | } |
| 3666 | } |
| 3667 | r.mPendingRemoveWindow = null; |
| 3668 | r.mPendingRemoveWindowManager = null; |
| 3669 | } |
| 3670 | |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 3671 | final void handleResumeActivity(IBinder token, |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 3672 | boolean clearHide, boolean isForward, boolean reallyResume, int seq, String reason) { |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 3673 | ActivityClientRecord r = mActivities.get(token); |
| 3674 | if (!checkAndUpdateLifecycleSeq(seq, r, "resumeActivity")) { |
| 3675 | return; |
| 3676 | } |
| 3677 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3678 | // If we are getting ready to gc after going to the background, well |
| 3679 | // we are back active so skip it. |
| 3680 | unscheduleGcIdler(); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3681 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3682 | |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 3683 | // TODO Push resumeArgs into the activity for consideration |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 3684 | r = performResumeActivity(token, clearHide, reason); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3685 | |
| 3686 | if (r != null) { |
| 3687 | final Activity a = r.activity; |
| 3688 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3689 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3690 | TAG, "Resume " + r + " started activity: " + |
| 3691 | a.mStartedActivity + ", hideForNow: " + r.hideForNow |
| 3692 | + ", finished: " + a.mFinished); |
| 3693 | |
| 3694 | final int forwardBit = isForward ? |
| 3695 | WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION : 0; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3696 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3697 | // If the window hasn't yet been added to the window manager, |
| 3698 | // and this guy didn't finish itself or start another activity, |
| 3699 | // then go ahead and add the window. |
Dianne Hackborn | 061d58a | 2010-03-12 15:07:06 -0800 | [diff] [blame] | 3700 | boolean willBeVisible = !a.mStartedActivity; |
| 3701 | if (!willBeVisible) { |
| 3702 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3703 | willBeVisible = ActivityManager.getService().willActivityBeVisible( |
Dianne Hackborn | 061d58a | 2010-03-12 15:07:06 -0800 | [diff] [blame] | 3704 | a.getActivityToken()); |
| 3705 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3706 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 061d58a | 2010-03-12 15:07:06 -0800 | [diff] [blame] | 3707 | } |
| 3708 | } |
| 3709 | if (r.window == null && !a.mFinished && willBeVisible) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3710 | r.window = r.activity.getWindow(); |
| 3711 | View decor = r.window.getDecorView(); |
| 3712 | decor.setVisibility(View.INVISIBLE); |
| 3713 | ViewManager wm = a.getWindowManager(); |
| 3714 | WindowManager.LayoutParams l = r.window.getAttributes(); |
| 3715 | a.mDecor = decor; |
| 3716 | l.type = WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
| 3717 | l.softInputMode |= forwardBit; |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 3718 | if (r.mPreserveWindow) { |
| 3719 | a.mWindowAdded = true; |
| 3720 | r.mPreserveWindow = false; |
Robert Carr | b259485 | 2016-04-25 16:21:13 -0700 | [diff] [blame] | 3721 | // Normally the ViewRoot sets up callbacks with the Activity |
| 3722 | // in addView->ViewRootImpl#setView. If we are instead reusing |
| 3723 | // the decor view we have to notify the view root that the |
| 3724 | // callbacks may have changed. |
| 3725 | ViewRootImpl impl = decor.getViewRootImpl(); |
Robert Carr | 311ecba | 2016-04-27 12:59:45 -0700 | [diff] [blame] | 3726 | if (impl != null) { |
| 3727 | impl.notifyChildRebuilt(); |
| 3728 | } |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 3729 | } |
Bryce Lee | 4b51b32 | 2017-04-07 10:27:19 -0700 | [diff] [blame^] | 3730 | if (a.mVisibleFromClient) { |
| 3731 | if (!a.mWindowAdded) { |
| 3732 | a.mWindowAdded = true; |
| 3733 | wm.addView(decor, l); |
| 3734 | } else { |
| 3735 | // The activity will get a callback for this {@link LayoutParams} change |
| 3736 | // earlier. However, at that time the decor will not be set (this is set |
| 3737 | // in this method), so no action will be taken. This call ensures the |
| 3738 | // callback occurs with the decor set. |
| 3739 | a.onWindowAttributesChanged(l); |
| 3740 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3741 | } |
| 3742 | |
| 3743 | // If the window has already been added, but during resume |
| 3744 | // we started another activity, then don't yet make the |
Dianne Hackborn | 061d58a | 2010-03-12 15:07:06 -0800 | [diff] [blame] | 3745 | // window visible. |
| 3746 | } else if (!willBeVisible) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3747 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3748 | TAG, "Launch " + r + " mStartedActivity set"); |
| 3749 | r.hideForNow = true; |
| 3750 | } |
| 3751 | |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 3752 | // Get rid of anything left hanging around. |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 3753 | cleanUpPendingRemoveWindows(r, false /* force */); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 3754 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3755 | // The window is now visible if it has been added, we are not |
| 3756 | // simply finishing, and we are not starting another activity. |
Dianne Hackborn | 061d58a | 2010-03-12 15:07:06 -0800 | [diff] [blame] | 3757 | if (!r.activity.mFinished && willBeVisible |
Dianne Hackborn | c1e605e | 2009-09-25 17:18:15 -0700 | [diff] [blame] | 3758 | && r.activity.mDecor != null && !r.hideForNow) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3759 | if (r.newConfig != null) { |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 3760 | performConfigurationChangedForActivity(r, r.newConfig); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3761 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Resuming activity " |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 3762 | + r.activityInfo.name + " with newConfig " + r.activity.mCurrentConfig); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3763 | r.newConfig = null; |
| 3764 | } |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3765 | if (localLOGV) Slog.v(TAG, "Resuming " + r + " with isForward=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3766 | + isForward); |
| 3767 | WindowManager.LayoutParams l = r.window.getAttributes(); |
| 3768 | if ((l.softInputMode |
| 3769 | & WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) |
| 3770 | != forwardBit) { |
| 3771 | l.softInputMode = (l.softInputMode |
| 3772 | & (~WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION)) |
| 3773 | | forwardBit; |
Dianne Hackborn | c1e605e | 2009-09-25 17:18:15 -0700 | [diff] [blame] | 3774 | if (r.activity.mVisibleFromClient) { |
| 3775 | ViewManager wm = a.getWindowManager(); |
| 3776 | View decor = r.window.getDecorView(); |
| 3777 | wm.updateViewLayout(decor, l); |
| 3778 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3779 | } |
Bryce Lee | 4b51b32 | 2017-04-07 10:27:19 -0700 | [diff] [blame^] | 3780 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3781 | r.activity.mVisibleFromServer = true; |
| 3782 | mNumVisibleActivities++; |
| 3783 | if (r.activity.mVisibleFromClient) { |
| 3784 | r.activity.makeVisible(); |
| 3785 | } |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 3786 | final ViewRootImpl viewRoot = r.activity.mDecor.getViewRootImpl(); |
| 3787 | if (viewRoot != null) { |
| 3788 | // TODO: Figure out the best place to set the callback. |
| 3789 | // This looks like a place where decor view is already initialized. |
| 3790 | viewRoot.setActivityConfigCallback(r.configCallback); |
| 3791 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3792 | } |
| 3793 | |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 3794 | if (!r.onlyLocalRequest) { |
| 3795 | r.nextIdle = mNewActivities; |
| 3796 | mNewActivities = r; |
| 3797 | if (localLOGV) Slog.v( |
| 3798 | TAG, "Scheduling idle handler for " + r); |
| 3799 | Looper.myQueue().addIdleHandler(new Idler()); |
| 3800 | } |
| 3801 | r.onlyLocalRequest = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3802 | |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 3803 | // Tell the activity manager we have resumed. |
| 3804 | if (reallyResume) { |
| 3805 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3806 | ActivityManager.getService().activityResumed(token); |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 3807 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3808 | throw ex.rethrowFromSystemServer(); |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 3809 | } |
| 3810 | } |
| 3811 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3812 | } else { |
| 3813 | // If an exception was thrown when trying to resume, then |
| 3814 | // just end this activity. |
| 3815 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3816 | ActivityManager.getService() |
Wale Ogunwale | ba7881c | 2015-08-01 19:28:29 -0700 | [diff] [blame] | 3817 | .finishActivity(token, Activity.RESULT_CANCELED, null, |
| 3818 | Activity.DONT_FINISH_TASK_WITH_ACTIVITY); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3819 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3820 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3821 | } |
| 3822 | } |
| 3823 | } |
| 3824 | |
| 3825 | private int mThumbnailWidth = -1; |
| 3826 | private int mThumbnailHeight = -1; |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3827 | private Bitmap mAvailThumbnailBitmap = null; |
| 3828 | private Canvas mThumbnailCanvas = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3829 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3830 | private Bitmap createThumbnailBitmap(ActivityClientRecord r) { |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3831 | Bitmap thumbnail = mAvailThumbnailBitmap; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3832 | try { |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3833 | if (thumbnail == null) { |
| 3834 | int w = mThumbnailWidth; |
| 3835 | int h; |
| 3836 | if (w < 0) { |
| 3837 | Resources res = r.activity.getResources(); |
Winson Chung | 6784f1c | 2014-05-22 11:22:41 -0700 | [diff] [blame] | 3838 | int wId = com.android.internal.R.dimen.thumbnail_width; |
| 3839 | int hId = com.android.internal.R.dimen.thumbnail_height; |
Winson Chung | fd08622 | 2014-05-13 15:49:42 -0700 | [diff] [blame] | 3840 | mThumbnailWidth = w = res.getDimensionPixelSize(wId); |
| 3841 | mThumbnailHeight = h = res.getDimensionPixelSize(hId); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3842 | } else { |
| 3843 | h = mThumbnailHeight; |
| 3844 | } |
| 3845 | |
| 3846 | // On platforms where we don't want thumbnails, set dims to (0,0) |
| 3847 | if ((w > 0) && (h > 0)) { |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 3848 | thumbnail = Bitmap.createBitmap(r.activity.getResources().getDisplayMetrics(), |
| 3849 | w, h, THUMBNAIL_FORMAT); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3850 | thumbnail.eraseColor(0); |
| 3851 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3852 | } |
| 3853 | |
Dianne Hackborn | fb3806d | 2010-12-09 13:14:12 -0800 | [diff] [blame] | 3854 | if (thumbnail != null) { |
| 3855 | Canvas cv = mThumbnailCanvas; |
| 3856 | if (cv == null) { |
| 3857 | mThumbnailCanvas = cv = new Canvas(); |
| 3858 | } |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 3859 | |
Dianne Hackborn | fb3806d | 2010-12-09 13:14:12 -0800 | [diff] [blame] | 3860 | cv.setBitmap(thumbnail); |
| 3861 | if (!r.activity.onCreateThumbnail(thumbnail, cv)) { |
| 3862 | mAvailThumbnailBitmap = thumbnail; |
| 3863 | thumbnail = null; |
| 3864 | } |
Dianne Hackborn | 6311d0a | 2011-08-02 16:37:58 -0700 | [diff] [blame] | 3865 | cv.setBitmap(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3866 | } |
Jim Miller | 0b2a6d0 | 2010-07-13 18:01:29 -0700 | [diff] [blame] | 3867 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3868 | } catch (Exception e) { |
| 3869 | if (!mInstrumentation.onException(r.activity, e)) { |
| 3870 | throw new RuntimeException( |
| 3871 | "Unable to create thumbnail of " |
| 3872 | + r.intent.getComponent().toShortString() |
| 3873 | + ": " + e.toString(), e); |
| 3874 | } |
| 3875 | thumbnail = null; |
| 3876 | } |
| 3877 | |
| 3878 | return thumbnail; |
| 3879 | } |
| 3880 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3881 | private void handlePauseActivity(IBinder token, boolean finished, |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 3882 | boolean userLeaving, int configChanges, boolean dontReport, int seq) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3883 | ActivityClientRecord r = mActivities.get(token); |
Filip Gruszczynski | c3b6179 | 2016-01-22 16:43:48 -0800 | [diff] [blame] | 3884 | if (DEBUG_ORDER) Slog.d(TAG, "handlePauseActivity " + r + ", seq: " + seq); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 3885 | if (!checkAndUpdateLifecycleSeq(seq, r, "pauseActivity")) { |
| 3886 | return; |
| 3887 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3888 | if (r != null) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3889 | //Slog.v(TAG, "userLeaving=" + userLeaving + " handling pause of " + r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3890 | if (userLeaving) { |
| 3891 | performUserLeavingActivity(r); |
| 3892 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3893 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3894 | r.activity.mConfigChangeFlags |= configChanges; |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 3895 | performPauseActivity(token, finished, r.isPreHoneycomb(), "handlePauseActivity"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3896 | |
Dianne Hackborn | aa93bcd | 2010-10-27 13:57:00 -0700 | [diff] [blame] | 3897 | // Make sure any pending writes are now committed. |
Dianne Hackborn | 5d9d03a | 2011-01-24 13:15:09 -0800 | [diff] [blame] | 3898 | if (r.isPreHoneycomb()) { |
| 3899 | QueuedWork.waitToFinish(); |
| 3900 | } |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 3901 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3902 | // Tell the activity manager we have paused. |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 3903 | if (!dontReport) { |
| 3904 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3905 | ActivityManager.getService().activityPaused(token); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 3906 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3907 | throw ex.rethrowFromSystemServer(); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 3908 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3909 | } |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3910 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3911 | } |
| 3912 | } |
| 3913 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3914 | final void performUserLeavingActivity(ActivityClientRecord r) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3915 | mInstrumentation.callActivityOnUserLeaving(r.activity); |
| 3916 | } |
| 3917 | |
| 3918 | final Bundle performPauseActivity(IBinder token, boolean finished, |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 3919 | boolean saveState, String reason) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3920 | ActivityClientRecord r = mActivities.get(token); |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 3921 | return r != null ? performPauseActivity(r, finished, saveState, reason) : null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3922 | } |
| 3923 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3924 | final Bundle performPauseActivity(ActivityClientRecord r, boolean finished, |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 3925 | boolean saveState, String reason) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3926 | if (r.paused) { |
| 3927 | if (r.activity.mFinished) { |
| 3928 | // If we are finishing, we won't call onResume() in certain cases. |
| 3929 | // So here we likewise don't want to call onPause() if the activity |
| 3930 | // isn't resumed. |
| 3931 | return null; |
| 3932 | } |
| 3933 | RuntimeException e = new RuntimeException( |
| 3934 | "Performing pause of activity that is not resumed: " |
| 3935 | + r.intent.getComponent().toShortString()); |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 3936 | Slog.e(TAG, e.getMessage(), e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3937 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3938 | if (finished) { |
| 3939 | r.activity.mFinished = true; |
| 3940 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3941 | |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 3942 | // Next have the activity save its current state and managed dialogs... |
| 3943 | if (!r.activity.mFinished && saveState) { |
| 3944 | callCallActivityOnSaveInstanceState(r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3945 | } |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 3946 | |
| 3947 | performPauseActivityIfNeeded(r, reason); |
Jeff Hamilton | 52d3203 | 2011-01-08 15:31:26 -0600 | [diff] [blame] | 3948 | |
| 3949 | // Notify any outstanding on paused listeners |
| 3950 | ArrayList<OnActivityPausedListener> listeners; |
| 3951 | synchronized (mOnPauseListeners) { |
| 3952 | listeners = mOnPauseListeners.remove(r.activity); |
| 3953 | } |
| 3954 | int size = (listeners != null ? listeners.size() : 0); |
| 3955 | for (int i = 0; i < size; i++) { |
| 3956 | listeners.get(i).onPaused(r.activity); |
| 3957 | } |
| 3958 | |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3959 | return !r.activity.mFinished && saveState ? r.state : null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3960 | } |
| 3961 | |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 3962 | private void performPauseActivityIfNeeded(ActivityClientRecord r, String reason) { |
| 3963 | if (r.paused) { |
| 3964 | // You are already paused silly... |
| 3965 | return; |
| 3966 | } |
| 3967 | |
| 3968 | try { |
| 3969 | r.activity.mCalled = false; |
| 3970 | mInstrumentation.callActivityOnPause(r.activity); |
| 3971 | EventLog.writeEvent(LOG_AM_ON_PAUSE_CALLED, UserHandle.myUserId(), |
| 3972 | r.activity.getComponentName().getClassName(), reason); |
| 3973 | if (!r.activity.mCalled) { |
| 3974 | throw new SuperNotCalledException("Activity " + safeToComponentShortString(r.intent) |
| 3975 | + " did not call through to super.onPause()"); |
| 3976 | } |
| 3977 | } catch (SuperNotCalledException e) { |
| 3978 | throw e; |
| 3979 | } catch (Exception e) { |
| 3980 | if (!mInstrumentation.onException(r.activity, e)) { |
| 3981 | throw new RuntimeException("Unable to pause activity " |
| 3982 | + safeToComponentShortString(r.intent) + ": " + e.toString(), e); |
| 3983 | } |
| 3984 | } |
| 3985 | r.paused = true; |
| 3986 | } |
| 3987 | |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 3988 | final void performStopActivity(IBinder token, boolean saveState, String reason) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3989 | ActivityClientRecord r = mActivities.get(token); |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 3990 | performStopActivityInner(r, null, false, saveState, reason); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3991 | } |
| 3992 | |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 3993 | private static class StopInfo implements Runnable { |
| 3994 | ActivityClientRecord activity; |
| 3995 | Bundle state; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3996 | PersistableBundle persistentState; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3997 | CharSequence description; |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 3998 | |
| 3999 | @Override public void run() { |
| 4000 | // Tell activity manager we have been stopped. |
| 4001 | try { |
| 4002 | if (DEBUG_MEMORY_TRIM) Slog.v(TAG, "Reporting activity stopped: " + activity); |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 4003 | ActivityManager.getService().activityStopped( |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 4004 | activity.token, state, persistentState, description); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 4005 | } catch (RemoteException ex) { |
Jeff Sharkey | 369f509 | 2016-02-29 11:16:21 -0700 | [diff] [blame] | 4006 | if (ex instanceof TransactionTooLargeException |
Jeff Sharkey | 9ad8613 | 2016-03-01 11:22:59 -0700 | [diff] [blame] | 4007 | && activity.packageInfo.getTargetSdkVersion() < Build.VERSION_CODES.N) { |
Jeff Sharkey | b8e8a91 | 2016-03-09 16:27:40 -0700 | [diff] [blame] | 4008 | Log.e(TAG, "App sent too much data in instance state, so it was ignored", ex); |
Jeff Sharkey | 369f509 | 2016-02-29 11:16:21 -0700 | [diff] [blame] | 4009 | return; |
| 4010 | } |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4011 | throw ex.rethrowFromSystemServer(); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 4012 | } |
| 4013 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4014 | } |
| 4015 | |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 4016 | private static final class ProviderRefCount { |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 4017 | public final ContentProviderHolder holder; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 4018 | public final ProviderClientRecord client; |
| 4019 | public int stableCount; |
| 4020 | public int unstableCount; |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 4021 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 4022 | // When this is set, the stable and unstable ref counts are 0 and |
| 4023 | // we have a pending operation scheduled to remove the ref count |
| 4024 | // from the activity manager. On the activity manager we are still |
| 4025 | // holding an unstable ref, though it is not reflected in the counts |
| 4026 | // here. |
| 4027 | public boolean removePending; |
| 4028 | |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 4029 | ProviderRefCount(ContentProviderHolder inHolder, |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 4030 | ProviderClientRecord inClient, int sCount, int uCount) { |
| 4031 | holder = inHolder; |
| 4032 | client = inClient; |
| 4033 | stableCount = sCount; |
| 4034 | unstableCount = uCount; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4035 | } |
| 4036 | } |
| 4037 | |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4038 | /** |
| 4039 | * Core implementation of stopping an activity. Note this is a little |
| 4040 | * tricky because the server's meaning of stop is slightly different |
| 4041 | * than our client -- for the server, stop means to save state and give |
| 4042 | * it the result when it is done, but the window may still be visible. |
| 4043 | * For the client, we want to call onStop()/onStart() to indicate when |
Wale Ogunwale | b5066fe | 2016-09-21 07:33:43 -0700 | [diff] [blame] | 4044 | * the activity's UI visibility changes. |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4045 | */ |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 4046 | private void performStopActivityInner(ActivityClientRecord r, |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 4047 | StopInfo info, boolean keepShown, boolean saveState, String reason) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4048 | if (localLOGV) Slog.v(TAG, "Performing stop of " + r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4049 | if (r != null) { |
| 4050 | if (!keepShown && r.stopped) { |
| 4051 | if (r.activity.mFinished) { |
| 4052 | // If we are finishing, we won't call onResume() in certain |
| 4053 | // cases. So here we likewise don't want to call onStop() |
| 4054 | // if the activity isn't resumed. |
| 4055 | return; |
| 4056 | } |
| 4057 | RuntimeException e = new RuntimeException( |
Andrii Kulian | 58178f2 | 2016-03-16 13:44:56 -0700 | [diff] [blame] | 4058 | "Performing stop of activity that is already stopped: " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4059 | + r.intent.getComponent().toShortString()); |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 4060 | Slog.e(TAG, e.getMessage(), e); |
Andrii Kulian | 58178f2 | 2016-03-16 13:44:56 -0700 | [diff] [blame] | 4061 | Slog.e(TAG, r.getStateString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4062 | } |
| 4063 | |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 4064 | // One must first be paused before stopped... |
| 4065 | performPauseActivityIfNeeded(r, reason); |
| 4066 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4067 | if (info != null) { |
| 4068 | try { |
| 4069 | // First create a thumbnail for the activity... |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4070 | // For now, don't create the thumbnail here; we are |
| 4071 | // doing that by doing a screen snapshot. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4072 | info.description = r.activity.onCreateDescription(); |
| 4073 | } catch (Exception e) { |
| 4074 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4075 | throw new RuntimeException( |
| 4076 | "Unable to save state of activity " |
| 4077 | + r.intent.getComponent().toShortString() |
| 4078 | + ": " + e.toString(), e); |
| 4079 | } |
| 4080 | } |
| 4081 | } |
| 4082 | |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4083 | // Next have the activity save its current state and managed dialogs... |
| 4084 | if (!r.activity.mFinished && saveState) { |
| 4085 | if (r.state == null) { |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 4086 | callCallActivityOnSaveInstanceState(r); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4087 | } |
| 4088 | } |
| 4089 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4090 | if (!keepShown) { |
| 4091 | try { |
| 4092 | // Now we are idle. |
Chong Zhang | 7687f25 | 2016-02-26 12:03:33 -0800 | [diff] [blame] | 4093 | r.activity.performStop(false /*preserveWindow*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4094 | } catch (Exception e) { |
| 4095 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4096 | throw new RuntimeException( |
| 4097 | "Unable to stop activity " |
| 4098 | + r.intent.getComponent().toShortString() |
| 4099 | + ": " + e.toString(), e); |
| 4100 | } |
| 4101 | } |
| 4102 | r.stopped = true; |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 4103 | EventLog.writeEvent(LOG_AM_ON_STOP_CALLED, UserHandle.myUserId(), |
| 4104 | r.activity.getComponentName().getClassName(), reason); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4105 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4106 | } |
| 4107 | } |
| 4108 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 4109 | private void updateVisibility(ActivityClientRecord r, boolean show) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4110 | View v = r.activity.mDecor; |
| 4111 | if (v != null) { |
| 4112 | if (show) { |
| 4113 | if (!r.activity.mVisibleFromServer) { |
| 4114 | r.activity.mVisibleFromServer = true; |
| 4115 | mNumVisibleActivities++; |
| 4116 | if (r.activity.mVisibleFromClient) { |
| 4117 | r.activity.makeVisible(); |
| 4118 | } |
| 4119 | } |
| 4120 | if (r.newConfig != null) { |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4121 | performConfigurationChangedForActivity(r, r.newConfig); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4122 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Updating activity vis " |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 4123 | + r.activityInfo.name + " with new config " |
| 4124 | + r.activity.mCurrentConfig); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4125 | r.newConfig = null; |
| 4126 | } |
| 4127 | } else { |
| 4128 | if (r.activity.mVisibleFromServer) { |
| 4129 | r.activity.mVisibleFromServer = false; |
| 4130 | mNumVisibleActivities--; |
| 4131 | v.setVisibility(View.INVISIBLE); |
| 4132 | } |
| 4133 | } |
| 4134 | } |
| 4135 | } |
| 4136 | |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 4137 | private void handleStopActivity(IBinder token, boolean show, int configChanges, int seq) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4138 | ActivityClientRecord r = mActivities.get(token); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 4139 | if (!checkAndUpdateLifecycleSeq(seq, r, "stopActivity")) { |
| 4140 | return; |
| 4141 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4142 | r.activity.mConfigChangeFlags |= configChanges; |
| 4143 | |
| 4144 | StopInfo info = new StopInfo(); |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 4145 | performStopActivityInner(r, info, show, true, "handleStopActivity"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4146 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4147 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4148 | TAG, "Finishing stop of " + r + ": show=" + show |
| 4149 | + " win=" + r.window); |
| 4150 | |
| 4151 | updateVisibility(r, show); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4152 | |
Dianne Hackborn | 5d9d03a | 2011-01-24 13:15:09 -0800 | [diff] [blame] | 4153 | // Make sure any pending writes are now committed. |
| 4154 | if (!r.isPreHoneycomb()) { |
| 4155 | QueuedWork.waitToFinish(); |
| 4156 | } |
| 4157 | |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 4158 | // Schedule the call to tell the activity manager we have |
| 4159 | // stopped. We don't do this immediately, because we want to |
| 4160 | // have a chance for any other pending work (in particular memory |
| 4161 | // trim requests) to complete before you tell the activity |
| 4162 | // manager to proceed and allow us to go fully into the background. |
| 4163 | info.activity = r; |
| 4164 | info.state = r.state; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 4165 | info.persistentState = r.persistentState; |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 4166 | mH.post(info); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4167 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4168 | } |
| 4169 | |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 4170 | private static boolean checkAndUpdateLifecycleSeq(int seq, ActivityClientRecord r, |
| 4171 | String action) { |
| 4172 | if (r == null) { |
| 4173 | return true; |
| 4174 | } |
| 4175 | if (seq < r.lastProcessedSeq) { |
| 4176 | if (DEBUG_ORDER) Slog.d(TAG, action + " for " + r + " ignored, because seq=" + seq |
| 4177 | + " < mCurrentLifecycleSeq=" + r.lastProcessedSeq); |
| 4178 | return false; |
| 4179 | } |
| 4180 | r.lastProcessedSeq = seq; |
| 4181 | return true; |
| 4182 | } |
| 4183 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4184 | final void performRestartActivity(IBinder token) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4185 | ActivityClientRecord r = mActivities.get(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4186 | if (r.stopped) { |
| 4187 | r.activity.performRestart(); |
| 4188 | r.stopped = false; |
| 4189 | } |
| 4190 | } |
| 4191 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 4192 | private void handleWindowVisibility(IBinder token, boolean show) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4193 | ActivityClientRecord r = mActivities.get(token); |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 4194 | |
Dianne Hackborn | bfddc0f | 2010-12-14 11:28:01 -0800 | [diff] [blame] | 4195 | if (r == null) { |
| 4196 | Log.w(TAG, "handleWindowVisibility: no activity for token " + token); |
| 4197 | return; |
| 4198 | } |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 4199 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4200 | if (!show && !r.stopped) { |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 4201 | performStopActivityInner(r, null, show, false, "handleWindowVisibility"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4202 | } else if (show && r.stopped) { |
| 4203 | // If we are getting ready to gc after going to the background, well |
| 4204 | // we are back active so skip it. |
| 4205 | unscheduleGcIdler(); |
| 4206 | |
| 4207 | r.activity.performRestart(); |
| 4208 | r.stopped = false; |
| 4209 | } |
| 4210 | if (r.activity.mDecor != null) { |
Joe Onorato | 43a1765 | 2011-04-06 19:22:23 -0700 | [diff] [blame] | 4211 | if (false) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4212 | TAG, "Handle window " + r + " visibility: " + show); |
| 4213 | updateVisibility(r, show); |
| 4214 | } |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4215 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4216 | } |
| 4217 | |
Wale Ogunwale | b5066fe | 2016-09-21 07:33:43 -0700 | [diff] [blame] | 4218 | // TODO: This method should be changed to use {@link #performStopActivityInner} to perform to |
| 4219 | // stop operation on the activity to reduce code duplication and the chance of fixing a bug in |
| 4220 | // one place and missing the other. |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 4221 | private void handleSleeping(IBinder token, boolean sleeping) { |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 4222 | ActivityClientRecord r = mActivities.get(token); |
| 4223 | |
| 4224 | if (r == null) { |
Dianne Hackborn | 842e04b | 2011-01-22 13:00:12 -0800 | [diff] [blame] | 4225 | Log.w(TAG, "handleSleeping: no activity for token " + token); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 4226 | return; |
| 4227 | } |
| 4228 | |
| 4229 | if (sleeping) { |
Dianne Hackborn | 842e04b | 2011-01-22 13:00:12 -0800 | [diff] [blame] | 4230 | if (!r.stopped && !r.isPreHoneycomb()) { |
Wale Ogunwale | b5066fe | 2016-09-21 07:33:43 -0700 | [diff] [blame] | 4231 | if (!r.activity.mFinished && r.state == null) { |
| 4232 | callCallActivityOnSaveInstanceState(r); |
| 4233 | } |
| 4234 | |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 4235 | try { |
| 4236 | // Now we are idle. |
Chong Zhang | 7687f25 | 2016-02-26 12:03:33 -0800 | [diff] [blame] | 4237 | r.activity.performStop(false /*preserveWindow*/); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 4238 | } catch (Exception e) { |
| 4239 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4240 | throw new RuntimeException( |
| 4241 | "Unable to stop activity " |
| 4242 | + r.intent.getComponent().toShortString() |
| 4243 | + ": " + e.toString(), e); |
| 4244 | } |
| 4245 | } |
| 4246 | r.stopped = true; |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 4247 | EventLog.writeEvent(LOG_AM_ON_STOP_CALLED, UserHandle.myUserId(), |
| 4248 | r.activity.getComponentName().getClassName(), "sleeping"); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 4249 | } |
Dianne Hackborn | 5d9d03a | 2011-01-24 13:15:09 -0800 | [diff] [blame] | 4250 | |
| 4251 | // Make sure any pending writes are now committed. |
| 4252 | if (!r.isPreHoneycomb()) { |
| 4253 | QueuedWork.waitToFinish(); |
| 4254 | } |
| 4255 | |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 4256 | // Tell activity manager we slept. |
| 4257 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 4258 | ActivityManager.getService().activitySlept(r.token); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 4259 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4260 | throw ex.rethrowFromSystemServer(); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 4261 | } |
| 4262 | } else { |
| 4263 | if (r.stopped && r.activity.mVisibleFromServer) { |
| 4264 | r.activity.performRestart(); |
| 4265 | r.stopped = false; |
| 4266 | } |
| 4267 | } |
| 4268 | } |
| 4269 | |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 4270 | private void handleSetCoreSettings(Bundle coreSettings) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4271 | synchronized (mResourcesManager) { |
Svetoslav Ganov | 9aa597e | 2011-03-03 18:17:41 -0800 | [diff] [blame] | 4272 | mCoreSettings = coreSettings; |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 4273 | } |
Jon Miranda | 836c0a8 | 2014-08-11 12:32:26 -0700 | [diff] [blame] | 4274 | onCoreSettingsChange(); |
| 4275 | } |
| 4276 | |
| 4277 | private void onCoreSettingsChange() { |
| 4278 | boolean debugViewAttributes = |
| 4279 | mCoreSettings.getInt(Settings.Global.DEBUG_VIEW_ATTRIBUTES, 0) != 0; |
| 4280 | if (debugViewAttributes != View.mDebugViewAttributes) { |
| 4281 | View.mDebugViewAttributes = debugViewAttributes; |
| 4282 | |
| 4283 | // request all activities to relaunch for the changes to take place |
| 4284 | for (Map.Entry<IBinder, ActivityClientRecord> entry : mActivities.entrySet()) { |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4285 | requestRelaunchActivity(entry.getKey(), null, null, 0, false, null, null, false, |
| 4286 | false /* preserveWindow */); |
Jon Miranda | 836c0a8 | 2014-08-11 12:32:26 -0700 | [diff] [blame] | 4287 | } |
| 4288 | } |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 4289 | } |
| 4290 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4291 | private void handleUpdatePackageCompatibilityInfo(UpdateCompatibilityData data) { |
| 4292 | LoadedApk apk = peekPackageInfo(data.pkg, false); |
| 4293 | if (apk != null) { |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 4294 | apk.setCompatibilityInfo(data.info); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4295 | } |
| 4296 | apk = peekPackageInfo(data.pkg, true); |
| 4297 | if (apk != null) { |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 4298 | apk.setCompatibilityInfo(data.info); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4299 | } |
| 4300 | handleConfigurationChanged(mConfiguration, data.info); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 4301 | WindowManagerGlobal.getInstance().reportNewConfiguration(mConfiguration); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4302 | } |
| 4303 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 4304 | private void deliverResults(ActivityClientRecord r, List<ResultInfo> results) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4305 | final int N = results.size(); |
| 4306 | for (int i=0; i<N; i++) { |
| 4307 | ResultInfo ri = results.get(i); |
| 4308 | try { |
| 4309 | if (ri.mData != null) { |
| 4310 | ri.mData.setExtrasClassLoader(r.activity.getClassLoader()); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 4311 | ri.mData.prepareToEnterProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4312 | } |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4313 | if (DEBUG_RESULTS) Slog.v(TAG, |
Chris Tate | 8a7dc17 | 2009-03-24 20:11:42 -0700 | [diff] [blame] | 4314 | "Delivering result to activity " + r + " : " + ri); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4315 | r.activity.dispatchActivityResult(ri.mResultWho, |
| 4316 | ri.mRequestCode, ri.mResultCode, ri.mData); |
| 4317 | } catch (Exception e) { |
| 4318 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4319 | throw new RuntimeException( |
| 4320 | "Failure delivering result " + ri + " to activity " |
| 4321 | + r.intent.getComponent().toShortString() |
| 4322 | + ": " + e.toString(), e); |
| 4323 | } |
| 4324 | } |
| 4325 | } |
| 4326 | } |
| 4327 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 4328 | private void handleSendResult(ResultData res) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4329 | ActivityClientRecord r = mActivities.get(res.token); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4330 | 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] | 4331 | if (r != null) { |
| 4332 | final boolean resumed = !r.paused; |
| 4333 | if (!r.activity.mFinished && r.activity.mDecor != null |
| 4334 | && r.hideForNow && resumed) { |
| 4335 | // We had hidden the activity because it started another |
| 4336 | // one... we have gotten a result back and we are not |
| 4337 | // paused, so make sure our window is visible. |
| 4338 | updateVisibility(r, true); |
| 4339 | } |
| 4340 | if (resumed) { |
| 4341 | try { |
| 4342 | // Now we are idle. |
| 4343 | r.activity.mCalled = false; |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 4344 | r.activity.mTemporaryPause = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4345 | mInstrumentation.callActivityOnPause(r.activity); |
| 4346 | if (!r.activity.mCalled) { |
| 4347 | throw new SuperNotCalledException( |
| 4348 | "Activity " + r.intent.getComponent().toShortString() |
| 4349 | + " did not call through to super.onPause()"); |
| 4350 | } |
| 4351 | } catch (SuperNotCalledException e) { |
| 4352 | throw e; |
| 4353 | } catch (Exception e) { |
| 4354 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4355 | throw new RuntimeException( |
| 4356 | "Unable to pause activity " |
| 4357 | + r.intent.getComponent().toShortString() |
| 4358 | + ": " + e.toString(), e); |
| 4359 | } |
| 4360 | } |
| 4361 | } |
| 4362 | deliverResults(r, res.results); |
| 4363 | if (resumed) { |
Dianne Hackborn | b46ed76 | 2011-06-02 18:33:15 -0700 | [diff] [blame] | 4364 | r.activity.performResume(); |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 4365 | r.activity.mTemporaryPause = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4366 | } |
| 4367 | } |
| 4368 | } |
| 4369 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4370 | public final ActivityClientRecord performDestroyActivity(IBinder token, boolean finishing) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4371 | return performDestroyActivity(token, finishing, 0, false); |
| 4372 | } |
| 4373 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 4374 | private ActivityClientRecord performDestroyActivity(IBinder token, boolean finishing, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4375 | int configChanges, boolean getNonConfigInstance) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4376 | ActivityClientRecord r = mActivities.get(token); |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4377 | Class<? extends Activity> activityClass = null; |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4378 | if (localLOGV) Slog.v(TAG, "Performing finish of " + r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4379 | if (r != null) { |
Brad Fitzpatrick | 5f8b5c1 | 2011-01-20 15:12:08 -0800 | [diff] [blame] | 4380 | activityClass = r.activity.getClass(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4381 | r.activity.mConfigChangeFlags |= configChanges; |
| 4382 | if (finishing) { |
| 4383 | r.activity.mFinished = true; |
| 4384 | } |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 4385 | |
| 4386 | performPauseActivityIfNeeded(r, "destroy"); |
| 4387 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4388 | if (!r.stopped) { |
| 4389 | try { |
Chong Zhang | 7687f25 | 2016-02-26 12:03:33 -0800 | [diff] [blame] | 4390 | r.activity.performStop(r.mPreserveWindow); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4391 | } catch (SuperNotCalledException e) { |
| 4392 | throw e; |
| 4393 | } catch (Exception e) { |
| 4394 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4395 | throw new RuntimeException( |
| 4396 | "Unable to stop activity " |
Mitsuru Oshima | d9aef73 | 2009-06-16 20:20:50 -0700 | [diff] [blame] | 4397 | + safeToComponentShortString(r.intent) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4398 | + ": " + e.toString(), e); |
| 4399 | } |
| 4400 | } |
| 4401 | r.stopped = true; |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 4402 | EventLog.writeEvent(LOG_AM_ON_STOP_CALLED, UserHandle.myUserId(), |
| 4403 | r.activity.getComponentName().getClassName(), "destroy"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4404 | } |
| 4405 | if (getNonConfigInstance) { |
| 4406 | try { |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 4407 | r.lastNonConfigurationInstances |
| 4408 | = r.activity.retainNonConfigurationInstances(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4409 | } catch (Exception e) { |
| 4410 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4411 | throw new RuntimeException( |
| 4412 | "Unable to retain activity " |
| 4413 | + r.intent.getComponent().toShortString() |
| 4414 | + ": " + e.toString(), e); |
| 4415 | } |
| 4416 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4417 | } |
| 4418 | try { |
| 4419 | r.activity.mCalled = false; |
Dianne Hackborn | 2dedce6 | 2010-04-15 14:45:25 -0700 | [diff] [blame] | 4420 | mInstrumentation.callActivityOnDestroy(r.activity); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4421 | if (!r.activity.mCalled) { |
| 4422 | throw new SuperNotCalledException( |
Mitsuru Oshima | d9aef73 | 2009-06-16 20:20:50 -0700 | [diff] [blame] | 4423 | "Activity " + safeToComponentShortString(r.intent) + |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4424 | " did not call through to super.onDestroy()"); |
| 4425 | } |
| 4426 | if (r.window != null) { |
| 4427 | r.window.closeAllPanels(); |
| 4428 | } |
| 4429 | } catch (SuperNotCalledException e) { |
| 4430 | throw e; |
| 4431 | } catch (Exception e) { |
| 4432 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4433 | throw new RuntimeException( |
Mitsuru Oshima | d9aef73 | 2009-06-16 20:20:50 -0700 | [diff] [blame] | 4434 | "Unable to destroy activity " + safeToComponentShortString(r.intent) |
| 4435 | + ": " + e.toString(), e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4436 | } |
| 4437 | } |
| 4438 | } |
| 4439 | mActivities.remove(token); |
Brad Fitzpatrick | 5f8b5c1 | 2011-01-20 15:12:08 -0800 | [diff] [blame] | 4440 | StrictMode.decrementExpectedActivityCount(activityClass); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4441 | return r; |
| 4442 | } |
| 4443 | |
Mitsuru Oshima | d9aef73 | 2009-06-16 20:20:50 -0700 | [diff] [blame] | 4444 | private static String safeToComponentShortString(Intent intent) { |
| 4445 | ComponentName component = intent.getComponent(); |
| 4446 | return component == null ? "[Unknown]" : component.toShortString(); |
| 4447 | } |
| 4448 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 4449 | private void handleDestroyActivity(IBinder token, boolean finishing, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4450 | int configChanges, boolean getNonConfigInstance) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4451 | ActivityClientRecord r = performDestroyActivity(token, finishing, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4452 | configChanges, getNonConfigInstance); |
| 4453 | if (r != null) { |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4454 | cleanUpPendingRemoveWindows(r, finishing); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4455 | WindowManager wm = r.activity.getWindowManager(); |
| 4456 | View v = r.activity.mDecor; |
| 4457 | if (v != null) { |
| 4458 | if (r.activity.mVisibleFromServer) { |
| 4459 | mNumVisibleActivities--; |
| 4460 | } |
| 4461 | IBinder wtoken = v.getWindowToken(); |
| 4462 | if (r.activity.mWindowAdded) { |
Robert Carr | 77bdfb5 | 2016-05-02 18:18:31 -0700 | [diff] [blame] | 4463 | if (r.mPreserveWindow) { |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4464 | // Hold off on removing this until the new activity's |
| 4465 | // window is being added. |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4466 | r.mPendingRemoveWindow = r.window; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4467 | r.mPendingRemoveWindowManager = wm; |
Andrii Kulian | eac0ea5 | 2016-05-11 15:50:24 -0700 | [diff] [blame] | 4468 | // We can only keep the part of the view hierarchy that we control, |
| 4469 | // everything else must be removed, because it might not be able to |
| 4470 | // behave properly when activity is relaunching. |
| 4471 | r.window.clearContentView(); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4472 | } else { |
| 4473 | wm.removeViewImmediate(v); |
| 4474 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4475 | } |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4476 | if (wtoken != null && r.mPendingRemoveWindow == null) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 4477 | WindowManagerGlobal.getInstance().closeAll(wtoken, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4478 | r.activity.getClass().getName(), "Activity"); |
Andrii Kulian | eac0ea5 | 2016-05-11 15:50:24 -0700 | [diff] [blame] | 4479 | } else if (r.mPendingRemoveWindow != null) { |
| 4480 | // We're preserving only one window, others should be closed so app views |
| 4481 | // will be detached before the final tear down. It should be done now because |
| 4482 | // some components (e.g. WebView) rely on detach callbacks to perform receiver |
| 4483 | // unregister and other cleanup. |
| 4484 | WindowManagerGlobal.getInstance().closeAllExceptView(token, v, |
| 4485 | r.activity.getClass().getName(), "Activity"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4486 | } |
| 4487 | r.activity.mDecor = null; |
| 4488 | } |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4489 | if (r.mPendingRemoveWindow == null) { |
| 4490 | // If we are delaying the removal of the activity window, then |
| 4491 | // we can't clean up all windows here. Note that we can't do |
| 4492 | // so later either, which means any windows that aren't closed |
| 4493 | // by the app will leak. Well we try to warning them a lot |
| 4494 | // about leaking windows, because that is a bug, so if they are |
| 4495 | // using this recreate facility then they get to live with leaks. |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 4496 | WindowManagerGlobal.getInstance().closeAll(token, |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4497 | r.activity.getClass().getName(), "Activity"); |
| 4498 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4499 | |
| 4500 | // Mocked out contexts won't be participating in the normal |
| 4501 | // process lifecycle, but if we're running with a proper |
| 4502 | // ApplicationContext we need to have it tear down things |
| 4503 | // cleanly. |
| 4504 | Context c = r.activity.getBaseContext(); |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 4505 | if (c instanceof ContextImpl) { |
| 4506 | ((ContextImpl) c).scheduleFinalCleanup( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4507 | r.activity.getClass().getName(), "Activity"); |
| 4508 | } |
| 4509 | } |
| 4510 | if (finishing) { |
| 4511 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 4512 | ActivityManager.getService().activityDestroyed(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4513 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4514 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4515 | } |
| 4516 | } |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4517 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4518 | } |
| 4519 | |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4520 | /** |
| 4521 | * @param preserveWindow Whether the activity should try to reuse the window it created, |
| 4522 | * including the decor view after the relaunch. |
| 4523 | */ |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4524 | public final void requestRelaunchActivity(IBinder token, |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 4525 | List<ResultInfo> pendingResults, List<ReferrerIntent> pendingNewIntents, |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4526 | int configChanges, boolean notResumed, Configuration config, |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4527 | Configuration overrideConfig, boolean fromServer, boolean preserveWindow) { |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4528 | ActivityClientRecord target = null; |
| 4529 | |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4530 | synchronized (mResourcesManager) { |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4531 | for (int i=0; i<mRelaunchingActivities.size(); i++) { |
| 4532 | ActivityClientRecord r = mRelaunchingActivities.get(i); |
Filip Gruszczynski | c3b6179 | 2016-01-22 16:43:48 -0800 | [diff] [blame] | 4533 | if (DEBUG_ORDER) Slog.d(TAG, "requestRelaunchActivity: " + this + ", trying: " + r); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4534 | if (r.token == token) { |
| 4535 | target = r; |
| 4536 | if (pendingResults != null) { |
| 4537 | if (r.pendingResults != null) { |
| 4538 | r.pendingResults.addAll(pendingResults); |
| 4539 | } else { |
| 4540 | r.pendingResults = pendingResults; |
| 4541 | } |
| 4542 | } |
| 4543 | if (pendingNewIntents != null) { |
| 4544 | if (r.pendingIntents != null) { |
| 4545 | r.pendingIntents.addAll(pendingNewIntents); |
| 4546 | } else { |
| 4547 | r.pendingIntents = pendingNewIntents; |
| 4548 | } |
| 4549 | } |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4550 | |
| 4551 | // For each relaunch request, activity manager expects an answer |
| 4552 | if (!r.onlyLocalRequest && fromServer) { |
| 4553 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 4554 | ActivityManager.getService().activityRelaunched(token); |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4555 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4556 | throw e.rethrowFromSystemServer(); |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4557 | } |
| 4558 | } |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4559 | break; |
| 4560 | } |
| 4561 | } |
| 4562 | |
| 4563 | if (target == null) { |
Filip Gruszczynski | c3b6179 | 2016-01-22 16:43:48 -0800 | [diff] [blame] | 4564 | if (DEBUG_ORDER) Slog.d(TAG, "requestRelaunchActivity: target is null, fromServer:" |
| 4565 | + fromServer); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4566 | target = new ActivityClientRecord(); |
| 4567 | target.token = token; |
| 4568 | target.pendingResults = pendingResults; |
| 4569 | target.pendingIntents = pendingNewIntents; |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4570 | target.mPreserveWindow = preserveWindow; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4571 | if (!fromServer) { |
Filip Gruszczynski | c3b6179 | 2016-01-22 16:43:48 -0800 | [diff] [blame] | 4572 | final ActivityClientRecord existing = mActivities.get(token); |
| 4573 | if (DEBUG_ORDER) Slog.d(TAG, "requestRelaunchActivity: " + existing); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4574 | if (existing != null) { |
Filip Gruszczynski | c3b6179 | 2016-01-22 16:43:48 -0800 | [diff] [blame] | 4575 | if (DEBUG_ORDER) Slog.d(TAG, "requestRelaunchActivity: paused= " |
| 4576 | + existing.paused);; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4577 | target.startsNotResumed = existing.paused; |
Wale Ogunwale | 93f543c | 2015-02-17 16:55:03 -0800 | [diff] [blame] | 4578 | target.overrideConfig = existing.overrideConfig; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4579 | } |
| 4580 | target.onlyLocalRequest = true; |
| 4581 | } |
| 4582 | mRelaunchingActivities.add(target); |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 4583 | sendMessage(H.RELAUNCH_ACTIVITY, target); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4584 | } |
| 4585 | |
| 4586 | if (fromServer) { |
| 4587 | target.startsNotResumed = notResumed; |
| 4588 | target.onlyLocalRequest = false; |
| 4589 | } |
| 4590 | if (config != null) { |
| 4591 | target.createdConfig = config; |
| 4592 | } |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 4593 | if (overrideConfig != null) { |
| 4594 | target.overrideConfig = overrideConfig; |
| 4595 | } |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4596 | target.pendingConfigChanges |= configChanges; |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 4597 | target.relaunchSeq = getLifecycleSeq(); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4598 | } |
Filip Gruszczynski | c3b6179 | 2016-01-22 16:43:48 -0800 | [diff] [blame] | 4599 | if (DEBUG_ORDER) Slog.d(TAG, "relaunchActivity " + ActivityThread.this + ", target " |
| 4600 | + target + " operation received seq: " + target.relaunchSeq); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4601 | } |
| 4602 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 4603 | private void handleRelaunchActivity(ActivityClientRecord tmp) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4604 | // If we are getting ready to gc after going to the background, well |
| 4605 | // we are back active so skip it. |
| 4606 | unscheduleGcIdler(); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4607 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4608 | |
| 4609 | Configuration changedConfig = null; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4610 | int configChanges = 0; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4611 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4612 | // First: make sure we have the most recent configuration and most |
| 4613 | // recent version of the activity, or skip it if some previous call |
| 4614 | // had taken a more recent version. |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4615 | synchronized (mResourcesManager) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4616 | int N = mRelaunchingActivities.size(); |
| 4617 | IBinder token = tmp.token; |
| 4618 | tmp = null; |
| 4619 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4620 | ActivityClientRecord r = mRelaunchingActivities.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4621 | if (r.token == token) { |
| 4622 | tmp = r; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4623 | configChanges |= tmp.pendingConfigChanges; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4624 | mRelaunchingActivities.remove(i); |
| 4625 | i--; |
| 4626 | N--; |
| 4627 | } |
| 4628 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4629 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4630 | if (tmp == null) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4631 | 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] | 4632 | return; |
| 4633 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4634 | |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4635 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Relaunching activity " |
| 4636 | + tmp.token + " with configChanges=0x" |
| 4637 | + Integer.toHexString(configChanges)); |
| 4638 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4639 | if (mPendingConfiguration != null) { |
| 4640 | changedConfig = mPendingConfiguration; |
| 4641 | mPendingConfiguration = null; |
| 4642 | } |
| 4643 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4644 | |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 4645 | if (tmp.lastProcessedSeq > tmp.relaunchSeq) { |
| 4646 | Slog.wtf(TAG, "For some reason target: " + tmp + " has lower sequence: " |
| 4647 | + tmp.relaunchSeq + " than current sequence: " + tmp.lastProcessedSeq); |
| 4648 | } else { |
| 4649 | tmp.lastProcessedSeq = tmp.relaunchSeq; |
| 4650 | } |
Dianne Hackborn | 871ecdc | 2009-12-11 15:24:33 -0800 | [diff] [blame] | 4651 | if (tmp.createdConfig != null) { |
| 4652 | // If the activity manager is passing us its current config, |
| 4653 | // assume that is really what we want regardless of what we |
| 4654 | // may have pending. |
| 4655 | if (mConfiguration == null |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4656 | || (tmp.createdConfig.isOtherSeqNewer(mConfiguration) |
| 4657 | && mConfiguration.diff(tmp.createdConfig) != 0)) { |
| 4658 | if (changedConfig == null |
| 4659 | || tmp.createdConfig.isOtherSeqNewer(changedConfig)) { |
| 4660 | changedConfig = tmp.createdConfig; |
| 4661 | } |
Dianne Hackborn | 871ecdc | 2009-12-11 15:24:33 -0800 | [diff] [blame] | 4662 | } |
| 4663 | } |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 4664 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4665 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Relaunching activity " |
Dianne Hackborn | dc6b635 | 2009-09-30 14:20:09 -0700 | [diff] [blame] | 4666 | + tmp.token + ": changedConfig=" + changedConfig); |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 4667 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4668 | // If there was a pending configuration change, execute it first. |
| 4669 | if (changedConfig != null) { |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 4670 | mCurDefaultDisplayDpi = changedConfig.densityDpi; |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 4671 | updateDefaultDensity(); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4672 | handleConfigurationChanged(changedConfig, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4673 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4674 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4675 | ActivityClientRecord r = mActivities.get(tmp.token); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4676 | 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] | 4677 | if (r == null) { |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4678 | if (!tmp.onlyLocalRequest) { |
| 4679 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 4680 | ActivityManager.getService().activityRelaunched(tmp.token); |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4681 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4682 | throw e.rethrowFromSystemServer(); |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4683 | } |
| 4684 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4685 | return; |
| 4686 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4687 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4688 | r.activity.mConfigChangeFlags |= configChanges; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4689 | r.onlyLocalRequest = tmp.onlyLocalRequest; |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4690 | r.mPreserveWindow = tmp.mPreserveWindow; |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 4691 | r.lastProcessedSeq = tmp.lastProcessedSeq; |
| 4692 | r.relaunchSeq = tmp.relaunchSeq; |
Christopher Tate | b70f3df | 2009-04-07 16:07:59 -0700 | [diff] [blame] | 4693 | Intent currentIntent = r.activity.mIntent; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4694 | |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4695 | r.activity.mChangingConfigurations = true; |
| 4696 | |
Robert Carr | 23fa16b | 2016-01-13 13:19:58 -0800 | [diff] [blame] | 4697 | // If we are preserving the main window across relaunches we would also like to preserve |
| 4698 | // the children. However the client side view system does not support preserving |
| 4699 | // the child views so we notify the window manager to expect these windows to |
| 4700 | // be replaced and defer requests to destroy or hide them. This way we can achieve |
| 4701 | // visual continuity. It's important that we do this here prior to pause and destroy |
| 4702 | // as that is when we may hide or remove the child views. |
Robert Carr | 77bdfb5 | 2016-05-02 18:18:31 -0700 | [diff] [blame] | 4703 | // |
| 4704 | // There is another scenario, if we have decided locally to relaunch the app from a |
| 4705 | // call to recreate, then none of the windows will be prepared for replacement or |
| 4706 | // preserved by the server, so we want to notify it that we are preparing to replace |
| 4707 | // everything |
Robert Carr | 23fa16b | 2016-01-13 13:19:58 -0800 | [diff] [blame] | 4708 | try { |
Robert Carr | 77bdfb5 | 2016-05-02 18:18:31 -0700 | [diff] [blame] | 4709 | if (r.mPreserveWindow || r.onlyLocalRequest) { |
| 4710 | WindowManagerGlobal.getWindowSession().prepareToReplaceWindows( |
| 4711 | r.token, !r.onlyLocalRequest); |
Robert Carr | 23fa16b | 2016-01-13 13:19:58 -0800 | [diff] [blame] | 4712 | } |
| 4713 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4714 | throw e.rethrowFromSystemServer(); |
Robert Carr | 23fa16b | 2016-01-13 13:19:58 -0800 | [diff] [blame] | 4715 | } |
| 4716 | |
Dianne Hackborn | e2b0480 | 2010-12-09 09:24:55 -0800 | [diff] [blame] | 4717 | // Need to ensure state is saved. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4718 | if (!r.paused) { |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 4719 | performPauseActivity(r.token, false, r.isPreHoneycomb(), "handleRelaunchActivity"); |
Dianne Hackborn | e2b0480 | 2010-12-09 09:24:55 -0800 | [diff] [blame] | 4720 | } |
| 4721 | if (r.state == null && !r.stopped && !r.isPreHoneycomb()) { |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 4722 | callCallActivityOnSaveInstanceState(r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4723 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4724 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4725 | handleDestroyActivity(r.token, false, configChanges, true); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4726 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4727 | r.activity = null; |
| 4728 | r.window = null; |
| 4729 | r.hideForNow = false; |
| 4730 | r.nextIdle = null; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4731 | // Merge any pending results and pending intents; don't just replace them |
| 4732 | if (tmp.pendingResults != null) { |
| 4733 | if (r.pendingResults == null) { |
| 4734 | r.pendingResults = tmp.pendingResults; |
| 4735 | } else { |
| 4736 | r.pendingResults.addAll(tmp.pendingResults); |
| 4737 | } |
| 4738 | } |
| 4739 | if (tmp.pendingIntents != null) { |
| 4740 | if (r.pendingIntents == null) { |
| 4741 | r.pendingIntents = tmp.pendingIntents; |
| 4742 | } else { |
| 4743 | r.pendingIntents.addAll(tmp.pendingIntents); |
| 4744 | } |
| 4745 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4746 | r.startsNotResumed = tmp.startsNotResumed; |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 4747 | r.overrideConfig = tmp.overrideConfig; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4748 | |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 4749 | handleLaunchActivity(r, currentIntent, "handleRelaunchActivity"); |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4750 | |
| 4751 | if (!tmp.onlyLocalRequest) { |
| 4752 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 4753 | ActivityManager.getService().activityRelaunched(r.token); |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 4754 | if (r.window != null) { |
| 4755 | r.window.reportActivityRelaunched(); |
| 4756 | } |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4757 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4758 | throw e.rethrowFromSystemServer(); |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4759 | } |
| 4760 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4761 | } |
| 4762 | |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 4763 | private void callCallActivityOnSaveInstanceState(ActivityClientRecord r) { |
| 4764 | r.state = new Bundle(); |
| 4765 | r.state.setAllowFds(false); |
| 4766 | if (r.isPersistable()) { |
| 4767 | r.persistentState = new PersistableBundle(); |
| 4768 | mInstrumentation.callActivityOnSaveInstanceState(r.activity, r.state, |
| 4769 | r.persistentState); |
| 4770 | } else { |
| 4771 | mInstrumentation.callActivityOnSaveInstanceState(r.activity, r.state); |
| 4772 | } |
| 4773 | } |
| 4774 | |
Dianne Hackborn | 73c1416 | 2012-09-19 15:45:06 -0700 | [diff] [blame] | 4775 | ArrayList<ComponentCallbacks2> collectComponentCallbacks( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4776 | boolean allActivities, Configuration newConfig) { |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 4777 | ArrayList<ComponentCallbacks2> callbacks |
| 4778 | = new ArrayList<ComponentCallbacks2>(); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4779 | |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4780 | synchronized (mResourcesManager) { |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 4781 | final int NAPP = mAllApplications.size(); |
| 4782 | for (int i=0; i<NAPP; i++) { |
Dianne Hackborn | 73c1416 | 2012-09-19 15:45:06 -0700 | [diff] [blame] | 4783 | callbacks.add(mAllApplications.get(i)); |
| 4784 | } |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 4785 | final int NACT = mActivities.size(); |
| 4786 | for (int i=0; i<NACT; i++) { |
| 4787 | ActivityClientRecord ar = mActivities.valueAt(i); |
| 4788 | Activity a = ar.activity; |
| 4789 | if (a != null) { |
| 4790 | Configuration thisConfig = applyConfigCompatMainThread( |
| 4791 | mCurDefaultDisplayDpi, newConfig, |
| 4792 | ar.packageInfo.getCompatibilityInfo()); |
| 4793 | if (!ar.activity.mFinished && (allActivities || !ar.paused)) { |
| 4794 | // If the activity is currently resumed, its configuration |
| 4795 | // needs to change right now. |
| 4796 | callbacks.add(a); |
| 4797 | } else if (thisConfig != null) { |
| 4798 | // Otherwise, we will tell it about the change |
| 4799 | // the next time it is resumed or shown. Note that |
| 4800 | // the activity manager may, before then, decide the |
| 4801 | // activity needs to be destroyed to handle its new |
| 4802 | // configuration. |
| 4803 | if (DEBUG_CONFIGURATION) { |
| 4804 | Slog.v(TAG, "Setting activity " |
| 4805 | + ar.activityInfo.name + " newConfig=" + thisConfig); |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 4806 | } |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 4807 | ar.newConfig = thisConfig; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4808 | } |
| 4809 | } |
| 4810 | } |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 4811 | final int NSVC = mServices.size(); |
| 4812 | for (int i=0; i<NSVC; i++) { |
| 4813 | callbacks.add(mServices.valueAt(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4814 | } |
| 4815 | } |
| 4816 | synchronized (mProviderMap) { |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 4817 | final int NPRV = mLocalProviders.size(); |
| 4818 | for (int i=0; i<NPRV; i++) { |
| 4819 | callbacks.add(mLocalProviders.valueAt(i).mLocalProvider); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4820 | } |
| 4821 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4822 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4823 | return callbacks; |
| 4824 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4825 | |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 4826 | /** |
| 4827 | * Updates the configuration for an Activity. The ActivityClientRecord's |
| 4828 | * {@link ActivityClientRecord#overrideConfig} is used to compute the final Configuration for |
| 4829 | * that Activity. {@link ActivityClientRecord#tmpConfig} is used as a temporary for delivering |
| 4830 | * the updated Configuration. |
| 4831 | * @param r ActivityClientRecord representing the Activity. |
| 4832 | * @param newBaseConfig The new configuration to use. This may be augmented with |
| 4833 | * {@link ActivityClientRecord#overrideConfig}. |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 4834 | */ |
| 4835 | private void performConfigurationChangedForActivity(ActivityClientRecord r, |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4836 | Configuration newBaseConfig) { |
| 4837 | performConfigurationChangedForActivity(r, newBaseConfig, |
| 4838 | r.activity.getDisplay().getDisplayId(), false /* movedToDifferentDisplay */); |
| 4839 | } |
| 4840 | |
| 4841 | /** |
| 4842 | * Updates the configuration for an Activity. The ActivityClientRecord's |
| 4843 | * {@link ActivityClientRecord#overrideConfig} is used to compute the final Configuration for |
| 4844 | * that Activity. {@link ActivityClientRecord#tmpConfig} is used as a temporary for delivering |
| 4845 | * the updated Configuration. |
| 4846 | * @param r ActivityClientRecord representing the Activity. |
| 4847 | * @param newBaseConfig The new configuration to use. This may be augmented with |
| 4848 | * {@link ActivityClientRecord#overrideConfig}. |
| 4849 | * @param displayId The id of the display where the Activity currently resides. |
| 4850 | * @param movedToDifferentDisplay Indicates if the activity was moved to different display. |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 4851 | * @return {@link Configuration} instance sent to client, null if not sent. |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4852 | */ |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 4853 | private Configuration performConfigurationChangedForActivity(ActivityClientRecord r, |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4854 | Configuration newBaseConfig, int displayId, boolean movedToDifferentDisplay) { |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 4855 | r.tmpConfig.setTo(newBaseConfig); |
| 4856 | if (r.overrideConfig != null) { |
| 4857 | r.tmpConfig.updateFrom(r.overrideConfig); |
| 4858 | } |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 4859 | final Configuration reportedConfig = performActivityConfigurationChanged(r.activity, |
| 4860 | r.tmpConfig, r.overrideConfig, displayId, movedToDifferentDisplay); |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 4861 | freeTextLayoutCachesIfNeeded(r.activity.mCurrentConfig.diff(r.tmpConfig)); |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 4862 | return reportedConfig; |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 4863 | } |
| 4864 | |
| 4865 | /** |
Adam Lesinski | c1b0ebf | 2016-06-09 11:17:10 -0700 | [diff] [blame] | 4866 | * Creates a new Configuration only if override would modify base. Otherwise returns base. |
| 4867 | * @param base The base configuration. |
| 4868 | * @param override The update to apply to the base configuration. Can be null. |
| 4869 | * @return A Configuration representing base with override applied. |
| 4870 | */ |
| 4871 | private static Configuration createNewConfigAndUpdateIfNotNull(@NonNull Configuration base, |
| 4872 | @Nullable Configuration override) { |
| 4873 | if (override == null) { |
| 4874 | return base; |
| 4875 | } |
| 4876 | Configuration newConfig = new Configuration(base); |
| 4877 | newConfig.updateFrom(override); |
| 4878 | return newConfig; |
| 4879 | } |
| 4880 | |
| 4881 | /** |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4882 | * 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] | 4883 | * @param cb The component callback to notify of configuration change. |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4884 | * @param newConfig The new configuration. |
| 4885 | */ |
| 4886 | private void performConfigurationChanged(ComponentCallbacks2 cb, Configuration newConfig) { |
| 4887 | if (!REPORT_TO_ACTIVITY) { |
| 4888 | return; |
| 4889 | } |
| 4890 | |
| 4891 | // ContextThemeWrappers may override the configuration for that context. We must check and |
| 4892 | // apply any overrides defined. |
| 4893 | Configuration contextThemeWrapperOverrideConfig = null; |
| 4894 | if (cb instanceof ContextThemeWrapper) { |
| 4895 | final ContextThemeWrapper contextThemeWrapper = (ContextThemeWrapper) cb; |
| 4896 | contextThemeWrapperOverrideConfig = contextThemeWrapper.getOverrideConfiguration(); |
| 4897 | } |
| 4898 | |
| 4899 | // Apply the ContextThemeWrapper override if necessary. |
| 4900 | // NOTE: Make sure the configurations are not modified, as they are treated as immutable |
| 4901 | // in many places. |
| 4902 | final Configuration configToReport = createNewConfigAndUpdateIfNotNull( |
| 4903 | newConfig, contextThemeWrapperOverrideConfig); |
| 4904 | cb.onConfigurationChanged(configToReport); |
| 4905 | } |
| 4906 | |
| 4907 | /** |
| 4908 | * Decides whether to update an Activity's configuration and whether to inform it. |
| 4909 | * @param activity The activity to notify of configuration change. |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 4910 | * @param newConfig The new configuration. |
Adam Lesinski | c1b0ebf | 2016-06-09 11:17:10 -0700 | [diff] [blame] | 4911 | * @param amOverrideConfig The override config that differentiates the Activity's configuration |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4912 | * from the base global configuration. This is supplied by |
| 4913 | * ActivityManager. |
| 4914 | * @param displayId Id of the display where 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 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] | 4917 | */ |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 4918 | private Configuration performActivityConfigurationChanged(Activity activity, |
| 4919 | Configuration newConfig, Configuration amOverrideConfig, int displayId, |
| 4920 | boolean movedToDifferentDisplay) { |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4921 | if (activity == null) { |
| 4922 | throw new IllegalArgumentException("No activity provided."); |
| 4923 | } |
| 4924 | final IBinder activityToken = activity.getActivityToken(); |
| 4925 | if (activityToken == null) { |
| 4926 | 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] | 4927 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4928 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4929 | boolean shouldChangeConfig = false; |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4930 | if (activity.mCurrentConfig == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4931 | shouldChangeConfig = true; |
| 4932 | } else { |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4933 | // If the new config is the same as the config this Activity is already running with and |
| 4934 | // the override config also didn't change, then don't bother calling |
| 4935 | // onConfigurationChanged. |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 4936 | int diff = activity.mCurrentConfig.diff(newConfig); |
Andrii Kulian | 3b3c914 | 2016-07-18 19:15:56 -0700 | [diff] [blame] | 4937 | if (diff != 0 || !mResourcesManager.isSameResourcesOverrideConfig(activityToken, |
| 4938 | amOverrideConfig)) { |
Chong Zhang | 4951f9d | 2016-06-23 13:15:08 -0700 | [diff] [blame] | 4939 | // Always send the task-level config changes. For system-level configuration, if |
| 4940 | // this activity doesn't handle any of the config changes, then don't bother |
| 4941 | // calling onConfigurationChanged as we're going to destroy it. |
| 4942 | if (!mUpdatingSystemConfig |
| 4943 | || (~activity.mActivityInfo.getRealConfigChanged() & diff) == 0 |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4944 | || !REPORT_TO_ACTIVITY) { |
Chong Zhang | 4951f9d | 2016-06-23 13:15:08 -0700 | [diff] [blame] | 4945 | shouldChangeConfig = true; |
| 4946 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4947 | } |
| 4948 | } |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4949 | if (!shouldChangeConfig && !movedToDifferentDisplay) { |
| 4950 | // Nothing significant, don't proceed with updating and reporting. |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 4951 | return null; |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4952 | } |
| 4953 | |
| 4954 | // Propagate the configuration change to ResourcesManager and Activity. |
| 4955 | |
| 4956 | // ContextThemeWrappers may override the configuration for that context. We must check and |
| 4957 | // apply any overrides defined. |
| 4958 | Configuration contextThemeWrapperOverrideConfig = activity.getOverrideConfiguration(); |
| 4959 | |
| 4960 | // We only update an Activity's configuration if this is not a global configuration change. |
| 4961 | // This must also be done before the callback, or else we violate the contract that the new |
| 4962 | // resources are available in ComponentCallbacks2#onConfigurationChanged(Configuration). |
| 4963 | // Also apply the ContextThemeWrapper override if necessary. |
| 4964 | // NOTE: Make sure the configurations are not modified, as they are treated as immutable in |
| 4965 | // many places. |
| 4966 | final Configuration finalOverrideConfig = createNewConfigAndUpdateIfNotNull( |
| 4967 | amOverrideConfig, contextThemeWrapperOverrideConfig); |
| 4968 | mResourcesManager.updateResourcesForActivity(activityToken, finalOverrideConfig, |
| 4969 | displayId, movedToDifferentDisplay); |
| 4970 | |
| 4971 | activity.mConfigChangeFlags = 0; |
| 4972 | activity.mCurrentConfig = new Configuration(newConfig); |
| 4973 | |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 4974 | // Apply the ContextThemeWrapper override if necessary. |
| 4975 | // NOTE: Make sure the configurations are not modified, as they are treated as immutable |
| 4976 | // in many places. |
| 4977 | final Configuration configToReport = createNewConfigAndUpdateIfNotNull(newConfig, |
| 4978 | contextThemeWrapperOverrideConfig); |
| 4979 | |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4980 | if (!REPORT_TO_ACTIVITY) { |
| 4981 | // Not configured to report to activity. |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 4982 | return configToReport; |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4983 | } |
| 4984 | |
| 4985 | if (movedToDifferentDisplay) { |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 4986 | activity.dispatchMovedToDisplay(displayId, configToReport); |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4987 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4988 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4989 | if (shouldChangeConfig) { |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 4990 | activity.mCalled = false; |
| 4991 | activity.onConfigurationChanged(configToReport); |
| 4992 | if (!activity.mCalled) { |
| 4993 | throw new SuperNotCalledException("Activity " + activity.getLocalClassName() + |
| 4994 | " did not call through to super.onConfigurationChanged()"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4995 | } |
| 4996 | } |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 4997 | |
| 4998 | return configToReport; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4999 | } |
| 5000 | |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 5001 | public final void applyConfigurationToResources(Configuration config) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 5002 | synchronized (mResourcesManager) { |
| 5003 | mResourcesManager.applyConfigurationToResourcesLocked(config, null); |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 5004 | } |
| 5005 | } |
| 5006 | |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 5007 | final Configuration applyCompatConfiguration(int displayDensity) { |
Dianne Hackborn | 836e262 | 2011-10-04 18:32:39 -0700 | [diff] [blame] | 5008 | Configuration config = mConfiguration; |
| 5009 | if (mCompatConfiguration == null) { |
| 5010 | mCompatConfiguration = new Configuration(); |
| 5011 | } |
| 5012 | mCompatConfiguration.setTo(mConfiguration); |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 5013 | if (mResourcesManager.applyCompatConfigurationLocked(displayDensity, |
| 5014 | mCompatConfiguration)) { |
Dianne Hackborn | 836e262 | 2011-10-04 18:32:39 -0700 | [diff] [blame] | 5015 | config = mCompatConfiguration; |
| 5016 | } |
| 5017 | return config; |
| 5018 | } |
| 5019 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 5020 | final void handleConfigurationChanged(Configuration config, CompatibilityInfo compat) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5021 | |
Fabrice Di Meglio | 30ca5cd | 2012-05-07 17:45:44 -0700 | [diff] [blame] | 5022 | int configDiff = 0; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5023 | |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 5024 | synchronized (mResourcesManager) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5025 | if (mPendingConfiguration != null) { |
| 5026 | if (!mPendingConfiguration.isOtherSeqNewer(config)) { |
| 5027 | config = mPendingConfiguration; |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 5028 | mCurDefaultDisplayDpi = config.densityDpi; |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 5029 | updateDefaultDensity(); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5030 | } |
| 5031 | mPendingConfiguration = null; |
| 5032 | } |
| 5033 | |
| 5034 | if (config == null) { |
| 5035 | return; |
| 5036 | } |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 5037 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 5038 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Handle configuration changed: " |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5039 | + config); |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 5040 | |
| 5041 | mResourcesManager.applyConfigurationToResourcesLocked(config, compat); |
Adam Lesinski | b61e405 | 2016-05-19 18:23:05 -0700 | [diff] [blame] | 5042 | updateLocaleListFromAppContext(mInitialApplication.getApplicationContext(), |
| 5043 | mResourcesManager.getConfiguration().getLocales()); |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 5044 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5045 | if (mConfiguration == null) { |
| 5046 | mConfiguration = new Configuration(); |
| 5047 | } |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 5048 | if (!mConfiguration.isOtherSeqNewer(config) && compat == null) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5049 | return; |
| 5050 | } |
Alan Viverette | e54d245 | 2015-05-06 10:41:43 -0700 | [diff] [blame] | 5051 | |
| 5052 | configDiff = mConfiguration.updateFrom(config); |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 5053 | config = applyCompatConfiguration(mCurDefaultDisplayDpi); |
Alan Viverette | 395cd01 | 2015-08-11 17:27:04 -0400 | [diff] [blame] | 5054 | |
| 5055 | final Theme systemTheme = getSystemContext().getTheme(); |
| 5056 | if ((systemTheme.getChangingConfigurations() & configDiff) != 0) { |
| 5057 | systemTheme.rebase(); |
| 5058 | } |
Adam Lesinski | a82b626 | 2017-03-21 16:56:17 -0700 | [diff] [blame] | 5059 | |
| 5060 | final Theme systemUiTheme = getSystemUiContext().getTheme(); |
| 5061 | if ((systemUiTheme.getChangingConfigurations() & configDiff) != 0) { |
| 5062 | systemUiTheme.rebase(); |
| 5063 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5064 | } |
Dianne Hackborn | 73c1416 | 2012-09-19 15:45:06 -0700 | [diff] [blame] | 5065 | |
| 5066 | ArrayList<ComponentCallbacks2> callbacks = collectComponentCallbacks(false, config); |
| 5067 | |
Fabrice Di Meglio | 30ca5cd | 2012-05-07 17:45:44 -0700 | [diff] [blame] | 5068 | freeTextLayoutCachesIfNeeded(configDiff); |
| 5069 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5070 | if (callbacks != null) { |
| 5071 | final int N = callbacks.size(); |
| 5072 | for (int i=0; i<N; i++) { |
Andrii Kulian | 701214b | 2016-04-07 09:36:33 -0700 | [diff] [blame] | 5073 | ComponentCallbacks2 cb = callbacks.get(i); |
| 5074 | if (cb instanceof Activity) { |
| 5075 | // If callback is an Activity - call corresponding method to consider override |
| 5076 | // config and avoid onConfigurationChanged if it hasn't changed. |
| 5077 | Activity a = (Activity) cb; |
| 5078 | performConfigurationChangedForActivity(mActivities.get(a.getActivityToken()), |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5079 | config); |
Andrii Kulian | 701214b | 2016-04-07 09:36:33 -0700 | [diff] [blame] | 5080 | } else { |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5081 | performConfigurationChanged(cb, config); |
Andrii Kulian | 701214b | 2016-04-07 09:36:33 -0700 | [diff] [blame] | 5082 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5083 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5084 | } |
| 5085 | } |
| 5086 | |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 5087 | void handleApplicationInfoChanged(@NonNull final ApplicationInfo ai) { |
Adam Lesinski | d33ef56 | 2017-01-19 14:49:59 -0800 | [diff] [blame] | 5088 | // Updates triggered by package installation go through a package update |
| 5089 | // receiver. Here we try to capture ApplicationInfo changes that are |
| 5090 | // caused by other sources, such as overlays. That means we want to be as conservative |
| 5091 | // about code changes as possible. Take the diff of the old ApplicationInfo and the new |
| 5092 | // to see if anything needs to change. |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 5093 | synchronized (mResourcesManager) { |
| 5094 | // Update all affected loaded packages with new package information |
| 5095 | WeakReference<LoadedApk> ref = mPackages.get(ai.packageName); |
| 5096 | LoadedApk apk = ref != null ? ref.get() : null; |
| 5097 | if (apk != null) { |
Adam Lesinski | d33ef56 | 2017-01-19 14:49:59 -0800 | [diff] [blame] | 5098 | final ArrayList<String> oldPaths = new ArrayList<>(); |
Dimitry Ivanov | 638d810 | 2017-02-22 15:39:42 -0800 | [diff] [blame] | 5099 | LoadedApk.makePaths(this, apk.getApplicationInfo(), oldPaths); |
Adam Lesinski | d33ef56 | 2017-01-19 14:49:59 -0800 | [diff] [blame] | 5100 | apk.updateApplicationInfo(ai, oldPaths); |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 5101 | } |
| 5102 | |
| 5103 | ref = mResourcePackages.get(ai.packageName); |
| 5104 | apk = ref != null ? ref.get() : null; |
| 5105 | if (apk != null) { |
Adam Lesinski | d33ef56 | 2017-01-19 14:49:59 -0800 | [diff] [blame] | 5106 | final ArrayList<String> oldPaths = new ArrayList<>(); |
Dimitry Ivanov | 638d810 | 2017-02-22 15:39:42 -0800 | [diff] [blame] | 5107 | LoadedApk.makePaths(this, apk.getApplicationInfo(), oldPaths); |
Adam Lesinski | d33ef56 | 2017-01-19 14:49:59 -0800 | [diff] [blame] | 5108 | apk.updateApplicationInfo(ai, oldPaths); |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 5109 | } |
| 5110 | |
| 5111 | // Update all affected Resources objects to use new ResourcesImpl |
| 5112 | mResourcesManager.applyNewResourceDirsLocked(ai.sourceDir, ai.resourceDirs); |
| 5113 | } |
| 5114 | |
| 5115 | ApplicationPackageManager.configurationChanged(); |
| 5116 | |
| 5117 | // Trigger a regular Configuration change event, only with a different assetsSeq number |
| 5118 | // so that we actually call through to all components. |
Adam Lesinski | a82b626 | 2017-03-21 16:56:17 -0700 | [diff] [blame] | 5119 | // TODO(adamlesinski): Change this to make use of ActivityManager's upcoming ability to |
| 5120 | // store configurations per-process. |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 5121 | Configuration newConfig = new Configuration(); |
Adam Lesinski | a82b626 | 2017-03-21 16:56:17 -0700 | [diff] [blame] | 5122 | newConfig.assetsSeq = (mConfiguration != null ? mConfiguration.assetsSeq : 0) + 1; |
MÃ¥rten Kongstad | 49a4a1d | 2017-01-12 08:36:37 +0100 | [diff] [blame] | 5123 | handleConfigurationChanged(newConfig, null); |
| 5124 | |
| 5125 | // Schedule all activities to reload |
| 5126 | for (final Map.Entry<IBinder, ActivityClientRecord> entry : mActivities.entrySet()) { |
| 5127 | final Activity activity = entry.getValue().activity; |
| 5128 | if (!activity.mFinished) { |
| 5129 | requestRelaunchActivity(entry.getKey(), null, null, 0, false, null, null, false, |
| 5130 | false); |
| 5131 | } |
| 5132 | } |
| 5133 | } |
| 5134 | |
Romain Guy | 46bfc48 | 2013-08-16 18:38:29 -0700 | [diff] [blame] | 5135 | static void freeTextLayoutCachesIfNeeded(int configDiff) { |
Fabrice Di Meglio | 30ca5cd | 2012-05-07 17:45:44 -0700 | [diff] [blame] | 5136 | if (configDiff != 0) { |
| 5137 | // Ask text layout engine to free its caches if there is a locale change |
| 5138 | boolean hasLocaleConfigChange = ((configDiff & ActivityInfo.CONFIG_LOCALE) != 0); |
| 5139 | if (hasLocaleConfigChange) { |
| 5140 | Canvas.freeTextLayoutCaches(); |
| 5141 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Cleared TextLayout Caches"); |
| 5142 | } |
| 5143 | } |
| 5144 | } |
| 5145 | |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5146 | /** |
| 5147 | * Handle new activity configuration and/or move to a different display. |
| 5148 | * @param data Configuration update data. |
| 5149 | * @param displayId Id of the display where activity was moved to, -1 if there was no move and |
| 5150 | * value didn't change. |
| 5151 | */ |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 5152 | void handleActivityConfigurationChanged(ActivityConfigChangeData data, int displayId) { |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 5153 | ActivityClientRecord r = mActivities.get(data.activityToken); |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5154 | // Check input params. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5155 | if (r == null || r.activity == null) { |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5156 | 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] | 5157 | return; |
| 5158 | } |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5159 | final boolean movedToDifferentDisplay = displayId != INVALID_DISPLAY; |
| 5160 | if (movedToDifferentDisplay) { |
| 5161 | if (r.activity.getDisplay().getDisplayId() == displayId) { |
| 5162 | throw new IllegalArgumentException("Activity is already on the target display: " |
| 5163 | + displayId); |
| 5164 | } |
| 5165 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 5166 | |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5167 | // Perform updates. |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 5168 | r.overrideConfig = data.overrideConfig; |
Stephen Kiazyk | f903b73 | 2017-03-20 16:23:45 -0700 | [diff] [blame] | 5169 | final ViewRootImpl viewRoot = r.activity.mDecor != null |
| 5170 | ? r.activity.mDecor.getViewRootImpl() : null; |
| 5171 | |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5172 | if (movedToDifferentDisplay) { |
| 5173 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Handle activity moved to display, activity:" |
| 5174 | + r.activityInfo.name + ", displayId=" + displayId |
| 5175 | + ", config=" + data.overrideConfig); |
| 5176 | |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 5177 | final Configuration reportedConfig = performConfigurationChangedForActivity(r, |
| 5178 | mCompatConfiguration, displayId, true /* movedToDifferentDisplay */); |
Andrii Kulian | ce1ecf1 | 2017-03-17 14:58:36 -0700 | [diff] [blame] | 5179 | if (viewRoot != null) { |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 5180 | viewRoot.onMovedToDisplay(displayId, reportedConfig); |
Andrii Kulian | ce1ecf1 | 2017-03-17 14:58:36 -0700 | [diff] [blame] | 5181 | } |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 5182 | } else { |
| 5183 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Handle activity config changed: " |
| 5184 | + r.activityInfo.name + ", config=" + data.overrideConfig); |
| 5185 | performConfigurationChangedForActivity(r, mCompatConfiguration); |
| 5186 | } |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 5187 | // Notify the ViewRootImpl instance about configuration changes. It may have initiated this |
| 5188 | // update to make sure that resources are updated before updating itself. |
Andrii Kulian | ce1ecf1 | 2017-03-17 14:58:36 -0700 | [diff] [blame] | 5189 | if (viewRoot != null) { |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 5190 | viewRoot.updateConfiguration(displayId); |
Andrii Kulian | ce1ecf1 | 2017-03-17 14:58:36 -0700 | [diff] [blame] | 5191 | } |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 5192 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5193 | } |
| 5194 | |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 5195 | final void handleProfilerControl(boolean start, ProfilerInfo profilerInfo, int profileType) { |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 5196 | if (start) { |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 5197 | try { |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 5198 | switch (profileType) { |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 5199 | default: |
| 5200 | mProfiler.setProfiler(profilerInfo); |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 5201 | mProfiler.startProfiling(); |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 5202 | break; |
| 5203 | } |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 5204 | } catch (RuntimeException e) { |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 5205 | Slog.w(TAG, "Profiling failed on path " + profilerInfo.profileFile |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 5206 | + " -- can the process access this path?"); |
Dianne Hackborn | 9c8dd55 | 2009-06-23 19:22:52 -0700 | [diff] [blame] | 5207 | } finally { |
| 5208 | try { |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 5209 | profilerInfo.profileFd.close(); |
Dianne Hackborn | 9c8dd55 | 2009-06-23 19:22:52 -0700 | [diff] [blame] | 5210 | } catch (IOException e) { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 5211 | Slog.w(TAG, "Failure closing profile fd", e); |
Dianne Hackborn | 9c8dd55 | 2009-06-23 19:22:52 -0700 | [diff] [blame] | 5212 | } |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 5213 | } |
| 5214 | } else { |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 5215 | switch (profileType) { |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 5216 | default: |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 5217 | mProfiler.stopProfiling(); |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 5218 | break; |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 5219 | } |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 5220 | } |
| 5221 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 5222 | |
Andreas Gampe | 4c79fea | 2016-01-28 20:11:41 -0800 | [diff] [blame] | 5223 | /** |
| 5224 | * Public entrypoint to stop profiling. This is required to end profiling when the app crashes, |
| 5225 | * so that profiler data won't be lost. |
| 5226 | * |
| 5227 | * @hide |
| 5228 | */ |
| 5229 | public void stopProfiling() { |
Amith Yamasani | b168443 | 2017-01-26 14:57:20 -0800 | [diff] [blame] | 5230 | if (mProfiler != null) { |
| 5231 | mProfiler.stopProfiling(); |
| 5232 | } |
Andreas Gampe | 4c79fea | 2016-01-28 20:11:41 -0800 | [diff] [blame] | 5233 | } |
| 5234 | |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 5235 | static final void handleDumpHeap(boolean managed, DumpHeapData dhd) { |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 5236 | if (managed) { |
| 5237 | try { |
| 5238 | Debug.dumpHprofData(dhd.path, dhd.fd.getFileDescriptor()); |
| 5239 | } catch (IOException e) { |
| 5240 | Slog.w(TAG, "Managed heap dump failed on path " + dhd.path |
| 5241 | + " -- can the process access this path?"); |
| 5242 | } finally { |
| 5243 | try { |
| 5244 | dhd.fd.close(); |
| 5245 | } catch (IOException e) { |
| 5246 | Slog.w(TAG, "Failure closing profile fd", e); |
| 5247 | } |
| 5248 | } |
| 5249 | } else { |
Andy McFadden | 06a6b55 | 2010-07-13 16:28:09 -0700 | [diff] [blame] | 5250 | Debug.dumpNativeHeap(dhd.fd.getFileDescriptor()); |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 5251 | } |
Dianne Hackborn | b9a5e4a | 2015-03-03 17:04:12 -0800 | [diff] [blame] | 5252 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5253 | ActivityManager.getService().dumpHeapFinished(dhd.path); |
Dianne Hackborn | b9a5e4a | 2015-03-03 17:04:12 -0800 | [diff] [blame] | 5254 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5255 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | b9a5e4a | 2015-03-03 17:04:12 -0800 | [diff] [blame] | 5256 | } |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 5257 | } |
| 5258 | |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 5259 | final void handleDispatchPackageBroadcast(int cmd, String[] packages) { |
| 5260 | boolean hasPkgInfo = false; |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5261 | switch (cmd) { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 5262 | case ApplicationThreadConstants.PACKAGE_REMOVED: |
| 5263 | case ApplicationThreadConstants.PACKAGE_REMOVED_DONT_KILL: |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5264 | { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 5265 | final boolean killApp = cmd == ApplicationThreadConstants.PACKAGE_REMOVED; |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5266 | if (packages == null) { |
| 5267 | break; |
| 5268 | } |
| 5269 | synchronized (mResourcesManager) { |
| 5270 | for (int i = packages.length - 1; i >= 0; i--) { |
| 5271 | if (!hasPkgInfo) { |
| 5272 | WeakReference<LoadedApk> ref = mPackages.get(packages[i]); |
| 5273 | if (ref != null && ref.get() != null) { |
| 5274 | hasPkgInfo = true; |
| 5275 | } else { |
| 5276 | ref = mResourcePackages.get(packages[i]); |
| 5277 | if (ref != null && ref.get() != null) { |
| 5278 | hasPkgInfo = true; |
| 5279 | } |
| 5280 | } |
| 5281 | } |
| 5282 | if (killApp) { |
| 5283 | mPackages.remove(packages[i]); |
| 5284 | mResourcePackages.remove(packages[i]); |
| 5285 | } |
| 5286 | } |
| 5287 | } |
| 5288 | break; |
| 5289 | } |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 5290 | case ApplicationThreadConstants.PACKAGE_REPLACED: |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5291 | { |
| 5292 | if (packages == null) { |
| 5293 | break; |
| 5294 | } |
| 5295 | synchronized (mResourcesManager) { |
| 5296 | for (int i = packages.length - 1; i >= 0; i--) { |
| 5297 | WeakReference<LoadedApk> ref = mPackages.get(packages[i]); |
| 5298 | LoadedApk pkgInfo = ref != null ? ref.get() : null; |
| 5299 | if (pkgInfo != null) { |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 5300 | hasPkgInfo = true; |
mark_chen | 89764e3 | 2014-12-12 15:38:48 +0800 | [diff] [blame] | 5301 | } else { |
| 5302 | ref = mResourcePackages.get(packages[i]); |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5303 | pkgInfo = ref != null ? ref.get() : null; |
| 5304 | if (pkgInfo != null) { |
mark_chen | 89764e3 | 2014-12-12 15:38:48 +0800 | [diff] [blame] | 5305 | hasPkgInfo = true; |
| 5306 | } |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 5307 | } |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5308 | // If the package is being replaced, yet it still has a valid |
| 5309 | // LoadedApk object, the package was updated with _DONT_KILL. |
| 5310 | // Adjust it's internal references to the application info and |
| 5311 | // resources. |
| 5312 | if (pkgInfo != null) { |
| 5313 | try { |
| 5314 | final String packageName = packages[i]; |
| 5315 | final ApplicationInfo aInfo = |
| 5316 | sPackageManager.getApplicationInfo( |
| 5317 | packageName, |
| 5318 | 0 /*flags*/, |
| 5319 | UserHandle.myUserId()); |
| 5320 | |
| 5321 | if (mActivities.size() > 0) { |
| 5322 | for (ActivityClientRecord ar : mActivities.values()) { |
| 5323 | if (ar.activityInfo.applicationInfo.packageName |
| 5324 | .equals(packageName)) { |
| 5325 | ar.activityInfo.applicationInfo = aInfo; |
| 5326 | ar.packageInfo = pkgInfo; |
| 5327 | } |
| 5328 | } |
| 5329 | } |
| 5330 | final List<String> oldPaths = |
| 5331 | sPackageManager.getPreviousCodePaths(packageName); |
| 5332 | pkgInfo.updateApplicationInfo(aInfo, oldPaths); |
| 5333 | } catch (RemoteException e) { |
| 5334 | } |
| 5335 | } |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 5336 | } |
| 5337 | } |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5338 | break; |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 5339 | } |
| 5340 | } |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 5341 | ApplicationPackageManager.handlePackageBroadcast(cmd, packages, hasPkgInfo); |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 5342 | } |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 5343 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5344 | final void handleLowMemory() { |
Dianne Hackborn | 73c1416 | 2012-09-19 15:45:06 -0700 | [diff] [blame] | 5345 | ArrayList<ComponentCallbacks2> callbacks = collectComponentCallbacks(true, null); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 5346 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5347 | final int N = callbacks.size(); |
| 5348 | for (int i=0; i<N; i++) { |
| 5349 | callbacks.get(i).onLowMemory(); |
| 5350 | } |
| 5351 | |
Chris Tate | ce22905 | 2009-03-25 16:44:52 -0700 | [diff] [blame] | 5352 | // Ask SQLite to free up as much memory as it can, mostly from its page caches. |
| 5353 | if (Process.myUid() != Process.SYSTEM_UID) { |
| 5354 | int sqliteReleased = SQLiteDatabase.releaseMemory(); |
| 5355 | EventLog.writeEvent(SQLITE_MEM_RELEASED_EVENT_LOG_TAG, sqliteReleased); |
| 5356 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 5357 | |
Mike Reed | caf0df1 | 2009-04-27 14:32:05 -0400 | [diff] [blame] | 5358 | // Ask graphics to free up as much as possible (font/image caches) |
| 5359 | Canvas.freeCaches(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5360 | |
Fabrice Di Meglio | 30ca5cd | 2012-05-07 17:45:44 -0700 | [diff] [blame] | 5361 | // Ask text layout engine to free also as much as possible |
| 5362 | Canvas.freeTextLayoutCaches(); |
| 5363 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5364 | BinderInternal.forceGc("mem"); |
| 5365 | } |
| 5366 | |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 5367 | final void handleTrimMemory(int level) { |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 5368 | if (DEBUG_MEMORY_TRIM) Slog.v(TAG, "Trimming memory to level: " + level); |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 5369 | |
Dianne Hackborn | 73c1416 | 2012-09-19 15:45:06 -0700 | [diff] [blame] | 5370 | ArrayList<ComponentCallbacks2> callbacks = collectComponentCallbacks(true, null); |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 5371 | |
| 5372 | final int N = callbacks.size(); |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 5373 | for (int i = 0; i < N; i++) { |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 5374 | callbacks.get(i).onTrimMemory(level); |
| 5375 | } |
Romain Guy | 19f86e8 | 2012-04-23 15:19:07 -0700 | [diff] [blame] | 5376 | |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 5377 | WindowManagerGlobal.getInstance().trimMemory(level); |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 5378 | } |
| 5379 | |
Jesse Hall | b12249b | 2016-12-12 12:53:02 -0800 | [diff] [blame] | 5380 | private void setupGraphicsSupport(Context context, File cacheDir) { |
Dianne Hackborn | a0c283e | 2012-02-09 10:47:01 -0800 | [diff] [blame] | 5381 | if (Process.isIsolated()) { |
| 5382 | // Isolated processes aren't going to do UI. |
| 5383 | return; |
| 5384 | } |
Andreas Gampe | 4c8e542 | 2016-05-18 11:58:47 -0700 | [diff] [blame] | 5385 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "setupGraphicsSupport"); |
Romain Guy | a958265 | 2011-11-10 14:20:10 -0800 | [diff] [blame] | 5386 | try { |
| 5387 | int uid = Process.myUid(); |
| 5388 | String[] packages = getPackageManager().getPackagesForUid(uid); |
| 5389 | |
Shuo Gao | 7c69a66 | 2016-03-01 13:32:03 +0800 | [diff] [blame] | 5390 | if (packages != null) { |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 5391 | ThreadedRenderer.setupDiskCache(cacheDir); |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 5392 | RenderScriptCacheDir.setupDiskCache(cacheDir); |
Jesse Hall | b12249b | 2016-12-12 12:53:02 -0800 | [diff] [blame] | 5393 | GraphicsEnvironment.setupGraphicsEnvironment(context); |
Romain Guy | a958265 | 2011-11-10 14:20:10 -0800 | [diff] [blame] | 5394 | } |
| 5395 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5396 | throw e.rethrowFromSystemServer(); |
Andreas Gampe | 4c8e542 | 2016-05-18 11:58:47 -0700 | [diff] [blame] | 5397 | } finally { |
| 5398 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Romain Guy | a958265 | 2011-11-10 14:20:10 -0800 | [diff] [blame] | 5399 | } |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 5400 | } |
| 5401 | |
| 5402 | private void updateDefaultDensity() { |
Alan Viverette | 2ac46f1 | 2016-02-04 16:58:14 -0500 | [diff] [blame] | 5403 | final int densityDpi = mCurDefaultDisplayDpi; |
| 5404 | if (!mDensityCompatMode |
| 5405 | && densityDpi != Configuration.DENSITY_DPI_UNDEFINED |
| 5406 | && densityDpi != DisplayMetrics.DENSITY_DEVICE) { |
| 5407 | DisplayMetrics.DENSITY_DEVICE = densityDpi; |
| 5408 | Bitmap.setDefaultDensity(densityDpi); |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 5409 | } |
| 5410 | } |
| 5411 | |
Todd Kennedy | e713efc | 2016-05-10 13:45:40 -0700 | [diff] [blame] | 5412 | /** |
| 5413 | * Returns the correct library directory for the current ABI. |
| 5414 | * <p> |
| 5415 | * If we're dealing with a multi-arch application that has both 32 and 64 bit shared |
| 5416 | * libraries, we might need to choose the secondary depending on what the current |
| 5417 | * runtime's instruction set is. |
| 5418 | */ |
| 5419 | private String getInstrumentationLibrary(ApplicationInfo appInfo, InstrumentationInfo insInfo) { |
| 5420 | if (appInfo.primaryCpuAbi != null && appInfo.secondaryCpuAbi != null) { |
| 5421 | // Get the instruction set supported by the secondary ABI. In the presence |
| 5422 | // of a native bridge this might be different than the one secondary ABI used. |
| 5423 | String secondaryIsa = |
| 5424 | VMRuntime.getInstructionSet(appInfo.secondaryCpuAbi); |
| 5425 | final String secondaryDexCodeIsa = |
| 5426 | SystemProperties.get("ro.dalvik.vm.isa." + secondaryIsa); |
| 5427 | secondaryIsa = secondaryDexCodeIsa.isEmpty() ? secondaryIsa : secondaryDexCodeIsa; |
| 5428 | |
| 5429 | final String runtimeIsa = VMRuntime.getRuntime().vmInstructionSet(); |
| 5430 | if (runtimeIsa.equals(secondaryIsa)) { |
| 5431 | return insInfo.secondaryNativeLibraryDir; |
| 5432 | } |
| 5433 | } |
| 5434 | return insInfo.nativeLibraryDir; |
| 5435 | } |
| 5436 | |
Adam Lesinski | b61e405 | 2016-05-19 18:23:05 -0700 | [diff] [blame] | 5437 | /** |
| 5438 | * The LocaleList set for the app's resources may have been shuffled so that the preferred |
| 5439 | * Locale is at position 0. We must find the index of this preferred Locale in the |
| 5440 | * original LocaleList. |
| 5441 | */ |
| 5442 | private void updateLocaleListFromAppContext(Context context, LocaleList newLocaleList) { |
| 5443 | final Locale bestLocale = context.getResources().getConfiguration().getLocales().get(0); |
| 5444 | final int newLocaleListSize = newLocaleList.size(); |
| 5445 | for (int i = 0; i < newLocaleListSize; i++) { |
| 5446 | if (bestLocale.equals(newLocaleList.get(i))) { |
| 5447 | LocaleList.setDefault(newLocaleList, i); |
| 5448 | return; |
| 5449 | } |
| 5450 | } |
Adam Lesinski | 27d3016 | 2016-05-25 16:45:14 -0700 | [diff] [blame] | 5451 | |
| 5452 | // The app may have overridden the LocaleList with its own Locale |
| 5453 | // (not present in the available list). Push the chosen Locale |
| 5454 | // to the front of the list. |
| 5455 | LocaleList.setDefault(new LocaleList(bestLocale, newLocaleList)); |
Adam Lesinski | b61e405 | 2016-05-19 18:23:05 -0700 | [diff] [blame] | 5456 | } |
| 5457 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 5458 | private void handleBindApplication(AppBindData data) { |
Calin Juravle | 8f5770d | 2016-04-12 14:12:04 +0100 | [diff] [blame] | 5459 | // Register the UI Thread as a sensitive thread to the runtime. |
| 5460 | VMRuntime.registerSensitiveThread(); |
Man Cao | cfa78b2 | 2015-06-11 20:14:34 -0700 | [diff] [blame] | 5461 | if (data.trackAllocation) { |
| 5462 | DdmVmInternal.enableRecentAllocations(true); |
| 5463 | } |
| 5464 | |
Dianne Hackborn | d98885c | 2016-03-01 17:13:03 -0800 | [diff] [blame] | 5465 | // Note when this process has started. |
| 5466 | Process.setStartTimes(SystemClock.elapsedRealtime(), SystemClock.uptimeMillis()); |
| 5467 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5468 | mBoundApplication = data; |
| 5469 | mConfiguration = new Configuration(data.config); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 5470 | mCompatConfiguration = new Configuration(data.config); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5471 | |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 5472 | mProfiler = new Profiler(); |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 5473 | if (data.initProfilerInfo != null) { |
| 5474 | mProfiler.profileFile = data.initProfilerInfo.profileFile; |
| 5475 | mProfiler.profileFd = data.initProfilerInfo.profileFd; |
| 5476 | mProfiler.samplingInterval = data.initProfilerInfo.samplingInterval; |
| 5477 | mProfiler.autoStopProfiler = data.initProfilerInfo.autoStopProfiler; |
Shukang Zhou | 6ffd4f9 | 2017-01-25 16:07:57 -0800 | [diff] [blame] | 5478 | mProfiler.streamingOutput = data.initProfilerInfo.streamingOutput; |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 5479 | } |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 5480 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5481 | // send up app name; do this *before* waiting for debugger |
Christopher Tate | 8ee038d | 2009-11-06 11:30:20 -0800 | [diff] [blame] | 5482 | Process.setArgV0(data.processName); |
Siva Velusamy | d693dfa | 2012-09-10 14:36:58 -0700 | [diff] [blame] | 5483 | android.ddm.DdmHandleAppName.setAppName(data.processName, |
| 5484 | UserHandle.myUserId()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5485 | |
Dianne Hackborn | 5d927c2 | 2011-09-02 12:22:18 -0700 | [diff] [blame] | 5486 | if (data.persistent) { |
| 5487 | // Persistent processes on low-memory devices do not get to |
| 5488 | // use hardware accelerated drawing, since this can add too much |
| 5489 | // overhead to the process. |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 5490 | if (!ActivityManager.isHighEndGfx()) { |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 5491 | ThreadedRenderer.disable(false); |
Dianne Hackborn | 5d927c2 | 2011-09-02 12:22:18 -0700 | [diff] [blame] | 5492 | } |
| 5493 | } |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 5494 | |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 5495 | if (mProfiler.profileFd != null) { |
| 5496 | mProfiler.startProfiling(); |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 5497 | } |
| 5498 | |
Joe Onorato | d630f10 | 2011-03-17 18:42:26 -0700 | [diff] [blame] | 5499 | // If the app is Honeycomb MR1 or earlier, switch its AsyncTask |
| 5500 | // implementation to use the pool executor. Normally, we use the |
| 5501 | // serialized executor as the default. This has to happen in the |
| 5502 | // main thread so the main looper is set right. |
Dianne Hackborn | 81e9276 | 2011-10-09 16:00:21 -0700 | [diff] [blame] | 5503 | if (data.appInfo.targetSdkVersion <= android.os.Build.VERSION_CODES.HONEYCOMB_MR1) { |
Joe Onorato | d630f10 | 2011-03-17 18:42:26 -0700 | [diff] [blame] | 5504 | AsyncTask.setDefaultExecutor(AsyncTask.THREAD_POOL_EXECUTOR); |
| 5505 | } |
| 5506 | |
Dianne Hackborn | 7895bc2 | 2014-09-05 15:09:03 -0700 | [diff] [blame] | 5507 | Message.updateCheckRecycle(data.appInfo.targetSdkVersion); |
| 5508 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5509 | /* |
| 5510 | * Before spawning a new process, reset the time zone to be the system time zone. |
| 5511 | * This needs to be done because the system time zone could have changed after the |
| 5512 | * the spawning of this process. Without doing this this process would have the incorrect |
| 5513 | * system time zone. |
| 5514 | */ |
| 5515 | TimeZone.setDefault(null); |
| 5516 | |
Adam Lesinski | b61e405 | 2016-05-19 18:23:05 -0700 | [diff] [blame] | 5517 | /* |
| 5518 | * Set the LocaleList. This may change once we create the App Context. |
| 5519 | */ |
| 5520 | LocaleList.setDefault(data.config.getLocales()); |
| 5521 | |
| 5522 | synchronized (mResourcesManager) { |
| 5523 | /* |
| 5524 | * Update the system configuration since its preloaded and might not |
| 5525 | * reflect configuration changes. The configuration object passed |
| 5526 | * in AppBindData can be safely assumed to be up to date |
| 5527 | */ |
| 5528 | mResourcesManager.applyConfigurationToResourcesLocked(data.config, data.compatInfo); |
| 5529 | mCurDefaultDisplayDpi = data.config.densityDpi; |
| 5530 | |
| 5531 | // This calls mResourcesManager so keep it within the synchronized block. |
| 5532 | applyCompatConfiguration(mCurDefaultDisplayDpi); |
| 5533 | } |
| 5534 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 5535 | data.info = getPackageInfoNoCheck(data.appInfo, data.compatInfo); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5536 | |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 5537 | /** |
| 5538 | * Switch this process to density compatibility mode if needed. |
| 5539 | */ |
| 5540 | if ((data.appInfo.flags&ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES) |
| 5541 | == 0) { |
| 5542 | mDensityCompatMode = true; |
| 5543 | Bitmap.setDefaultDensity(DisplayMetrics.DENSITY_DEFAULT); |
| 5544 | } |
| 5545 | updateDefaultDensity(); |
| 5546 | |
Neil Fuller | c66ec40 | 2016-11-14 16:06:42 +0000 | [diff] [blame] | 5547 | final String use24HourSetting = mCoreSettings.getString(Settings.System.TIME_12_24); |
| 5548 | Boolean is24Hr = null; |
| 5549 | if (use24HourSetting != null) { |
| 5550 | is24Hr = "24".equals(use24HourSetting) ? Boolean.TRUE : Boolean.FALSE; |
| 5551 | } |
| 5552 | // null : use locale default for 12/24 hour formatting, |
| 5553 | // false : use 12 hour format, |
| 5554 | // true : use 24 hour format. |
Narayan Kamath | ccb2a086 | 2013-12-19 14:49:36 +0000 | [diff] [blame] | 5555 | DateFormat.set24HourTimePref(is24Hr); |
| 5556 | |
Jon Miranda | 836c0a8 | 2014-08-11 12:32:26 -0700 | [diff] [blame] | 5557 | View.mDebugViewAttributes = |
| 5558 | mCoreSettings.getInt(Settings.Global.DEBUG_VIEW_ATTRIBUTES, 0) != 0; |
| 5559 | |
Dianne Hackborn | 96e240f | 2009-07-26 17:42:30 -0700 | [diff] [blame] | 5560 | /** |
Brad Fitzpatrick | 438d059 | 2010-06-10 12:19:19 -0700 | [diff] [blame] | 5561 | * For system applications on userdebug/eng builds, log stack |
| 5562 | * traces of disk and network access to dropbox for analysis. |
| 5563 | */ |
Brad Fitzpatrick | ad13b98 | 2010-07-14 12:35:53 -0700 | [diff] [blame] | 5564 | if ((data.appInfo.flags & |
| 5565 | (ApplicationInfo.FLAG_SYSTEM | |
Brad Fitzpatrick | 50d66f9 | 2010-09-13 21:29:05 -0700 | [diff] [blame] | 5566 | ApplicationInfo.FLAG_UPDATED_SYSTEM_APP)) != 0) { |
| 5567 | StrictMode.conditionallyEnableDebugLogging(); |
Brad Fitzpatrick | 438d059 | 2010-06-10 12:19:19 -0700 | [diff] [blame] | 5568 | } |
| 5569 | |
| 5570 | /** |
Jeff Sharkey | 344744b | 2016-01-28 19:03:30 -0700 | [diff] [blame] | 5571 | * For apps targetting Honeycomb or later, we don't allow network usage |
| 5572 | * on the main event loop / UI thread. This is what ultimately throws |
| 5573 | * {@link NetworkOnMainThreadException}. |
Brad Fitzpatrick | b6e1841 | 2010-10-28 14:50:05 -0700 | [diff] [blame] | 5574 | */ |
Jeff Sharkey | 344744b | 2016-01-28 19:03:30 -0700 | [diff] [blame] | 5575 | if (data.appInfo.targetSdkVersion >= Build.VERSION_CODES.HONEYCOMB) { |
Brad Fitzpatrick | b6e1841 | 2010-10-28 14:50:05 -0700 | [diff] [blame] | 5576 | StrictMode.enableDeathOnNetwork(); |
| 5577 | } |
| 5578 | |
Jeff Sharkey | 344744b | 2016-01-28 19:03:30 -0700 | [diff] [blame] | 5579 | /** |
| 5580 | * For apps targetting N or later, we don't allow file:// Uri exposure. |
| 5581 | * This is what ultimately throws {@link FileUriExposedException}. |
| 5582 | */ |
| 5583 | if (data.appInfo.targetSdkVersion >= Build.VERSION_CODES.N) { |
Thierry Strudel | e60b28d | 2016-02-25 02:14:16 +0000 | [diff] [blame] | 5584 | StrictMode.enableDeathOnFileUriExposure(); |
Jeff Sharkey | 344744b | 2016-01-28 19:03:30 -0700 | [diff] [blame] | 5585 | } |
| 5586 | |
Svet Ganov | 37e4327 | 2016-09-09 16:01:32 -0700 | [diff] [blame] | 5587 | // We deprecated Build.SERIAL and only apps that target pre NMR1 |
| 5588 | // SDK can see it. Since access to the serial is now behind a |
| 5589 | // permission we push down the value and here we fix it up |
| 5590 | // before any app code has been loaded. |
| 5591 | try { |
| 5592 | Field field = Build.class.getDeclaredField("SERIAL"); |
| 5593 | field.setAccessible(true); |
| 5594 | field.set(Build.class, data.buildSerial); |
| 5595 | } catch (NoSuchFieldException | IllegalAccessException e) { |
| 5596 | /* ignore */ |
| 5597 | } |
| 5598 | |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 5599 | if (data.debugMode != ApplicationThreadConstants.DEBUG_OFF) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5600 | // XXX should have option to change the port. |
| 5601 | Debug.changeDebugPort(8100); |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 5602 | if (data.debugMode == ApplicationThreadConstants.DEBUG_WAIT) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 5603 | Slog.w(TAG, "Application " + data.info.getPackageName() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5604 | + " is waiting for the debugger on port 8100..."); |
| 5605 | |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5606 | IActivityManager mgr = ActivityManager.getService(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5607 | try { |
| 5608 | mgr.showWaitingForDebugger(mAppThread, true); |
| 5609 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5610 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5611 | } |
| 5612 | |
| 5613 | Debug.waitForDebugger(); |
| 5614 | |
| 5615 | try { |
| 5616 | mgr.showWaitingForDebugger(mAppThread, false); |
| 5617 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5618 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5619 | } |
| 5620 | |
| 5621 | } else { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 5622 | Slog.w(TAG, "Application " + data.info.getPackageName() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5623 | + " can be debugged on port 8100..."); |
| 5624 | } |
| 5625 | } |
| 5626 | |
Jamie Gennis | f9c7d6b | 2013-03-25 14:18:25 -0700 | [diff] [blame] | 5627 | // Allow application-generated systrace messages if we're debuggable. |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 5628 | boolean isAppDebuggable = (data.appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0; |
| 5629 | Trace.setAppTracingAllowed(isAppDebuggable); |
| 5630 | if (isAppDebuggable && data.enableBinderTracking) { |
| 5631 | Binder.enableTracing(); |
| 5632 | } |
Jamie Gennis | f9c7d6b | 2013-03-25 14:18:25 -0700 | [diff] [blame] | 5633 | |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 5634 | /** |
| 5635 | * Initialize the default http proxy in this process for the reasons we set the time zone. |
| 5636 | */ |
Andreas Gampe | 4c8e542 | 2016-05-18 11:58:47 -0700 | [diff] [blame] | 5637 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "Setup proxies"); |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 5638 | final IBinder b = ServiceManager.getService(Context.CONNECTIVITY_SERVICE); |
Dianne Hackborn | d4d32c5 | 2011-11-08 17:33:59 -0800 | [diff] [blame] | 5639 | if (b != null) { |
| 5640 | // In pre-boot mode (doing initial launch to collect password), not |
| 5641 | // all system is up. This includes the connectivity service, so don't |
| 5642 | // crash if we can't get it. |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 5643 | final IConnectivityManager service = IConnectivityManager.Stub.asInterface(b); |
Dianne Hackborn | d4d32c5 | 2011-11-08 17:33:59 -0800 | [diff] [blame] | 5644 | try { |
Paul Jensen | cee9b51 | 2015-05-06 07:32:40 -0400 | [diff] [blame] | 5645 | final ProxyInfo proxyInfo = service.getProxyForNetwork(null); |
Jason Monk | 207900c | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 5646 | Proxy.setHttpProxySystemProperty(proxyInfo); |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5647 | } catch (RemoteException e) { |
Andreas Gampe | 4c8e542 | 2016-05-18 11:58:47 -0700 | [diff] [blame] | 5648 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5649 | throw e.rethrowFromSystemServer(); |
| 5650 | } |
Dianne Hackborn | d4d32c5 | 2011-11-08 17:33:59 -0800 | [diff] [blame] | 5651 | } |
Andreas Gampe | 4c8e542 | 2016-05-18 11:58:47 -0700 | [diff] [blame] | 5652 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 5653 | |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 5654 | // Instrumentation info affects the class loader, so load it before |
| 5655 | // setting up the app context. |
| 5656 | final InstrumentationInfo ii; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5657 | if (data.instrumentationName != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5658 | try { |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 5659 | ii = new ApplicationPackageManager(null, getPackageManager()) |
| 5660 | .getInstrumentationInfo(data.instrumentationName, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5661 | } catch (PackageManager.NameNotFoundException e) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5662 | throw new RuntimeException( |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 5663 | "Unable to find instrumentation info for: " + data.instrumentationName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5664 | } |
| 5665 | |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 5666 | mInstrumentationPackageName = ii.packageName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5667 | mInstrumentationAppDir = ii.sourceDir; |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 5668 | mInstrumentationSplitAppDirs = ii.splitSourceDirs; |
Todd Kennedy | e713efc | 2016-05-10 13:45:40 -0700 | [diff] [blame] | 5669 | mInstrumentationLibDir = getInstrumentationLibrary(data.appInfo, ii); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5670 | mInstrumentedAppDir = data.info.getAppDir(); |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 5671 | mInstrumentedSplitAppDirs = data.info.getSplitAppDirs(); |
| 5672 | mInstrumentedLibDir = data.info.getLibDir(); |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 5673 | } else { |
| 5674 | ii = null; |
| 5675 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5676 | |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 5677 | final ContextImpl appContext = ContextImpl.createAppContext(this, data.info); |
Adam Lesinski | b61e405 | 2016-05-19 18:23:05 -0700 | [diff] [blame] | 5678 | updateLocaleListFromAppContext(appContext, |
| 5679 | mResourcesManager.getConfiguration().getLocales()); |
Seigo Nonaka | c14dd78 | 2016-03-30 23:09:16 +0900 | [diff] [blame] | 5680 | |
Jeff Sharkey | e6cb097 | 2016-02-01 09:59:12 -0700 | [diff] [blame] | 5681 | if (!Process.isIsolated() && !"android".equals(appContext.getPackageName())) { |
Jeff Sharkey | e84bdd3 | 2016-02-08 12:16:00 -0700 | [diff] [blame] | 5682 | // This cache location probably points at credential-encrypted |
| 5683 | // storage which may not be accessible yet; assign it anyway instead |
| 5684 | // of pointing at device-encrypted storage. |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 5685 | final File cacheDir = appContext.getCacheDir(); |
| 5686 | if (cacheDir != null) { |
| 5687 | // Provide a usable directory for temporary files |
| 5688 | System.setProperty("java.io.tmpdir", cacheDir.getAbsolutePath()); |
| 5689 | } else { |
| 5690 | Log.v(TAG, "Unable to initialize \"java.io.tmpdir\" property " |
| 5691 | + "due to missing cache directory"); |
| 5692 | } |
Alan Viverette | 346296b | 2015-09-01 13:08:05 -0400 | [diff] [blame] | 5693 | |
Calin Juravle | 2a727d7 | 2016-04-15 19:33:46 +0100 | [diff] [blame] | 5694 | // Setup a location to store generated/compiled graphics code. |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 5695 | final Context deviceContext = appContext.createDeviceProtectedStorageContext(); |
Jeff Sharkey | e84bdd3 | 2016-02-08 12:16:00 -0700 | [diff] [blame] | 5696 | final File codeCacheDir = deviceContext.getCodeCacheDir(); |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 5697 | if (codeCacheDir != null) { |
Jesse Hall | b12249b | 2016-12-12 12:53:02 -0800 | [diff] [blame] | 5698 | setupGraphicsSupport(appContext, codeCacheDir); |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 5699 | } else { |
Calin Juravle | 2a727d7 | 2016-04-15 19:33:46 +0100 | [diff] [blame] | 5700 | Log.e(TAG, "Unable to setupGraphicsSupport due to missing code-cache directory"); |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 5701 | } |
Michael Lentine | 2ba303f | 2016-02-01 20:44:34 -0600 | [diff] [blame] | 5702 | } |
Michael Lentine | 03d8f768 | 2016-01-31 15:37:11 -0600 | [diff] [blame] | 5703 | |
Calin Juravle | 37dfc8e | 2017-03-13 19:02:32 -0700 | [diff] [blame] | 5704 | // If we use profiles, setup the dex reporter to notify package manager |
| 5705 | // of any relevant dex loads. The idle maintenance job will use the information |
| 5706 | // reported to optimize the loaded dex files. |
| 5707 | // Note that we only need one global reporter per app. |
| 5708 | // Make sure we do this before calling onCreate so that we can capture the |
| 5709 | // complete application startup. |
| 5710 | if (SystemProperties.getBoolean("dalvik.vm.usejitprofiles", false)) { |
Calin Juravle | f5a7bfc | 2017-03-13 23:30:30 -0700 | [diff] [blame] | 5711 | BaseDexClassLoader.setReporter(DexLoadReporter.getInstance()); |
Calin Juravle | 37dfc8e | 2017-03-13 19:02:32 -0700 | [diff] [blame] | 5712 | } |
| 5713 | |
Chad Brubaker | 78d4712 | 2015-11-17 22:26:58 -0800 | [diff] [blame] | 5714 | // Install the Network Security Config Provider. This must happen before the application |
| 5715 | // code is loaded to prevent issues with instances of TLS objects being created before |
| 5716 | // the provider is installed. |
Andreas Gampe | 4c8e542 | 2016-05-18 11:58:47 -0700 | [diff] [blame] | 5717 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "NetworkSecurityConfigProvider.install"); |
Chad Brubaker | 276ee96 | 2016-06-08 12:57:46 -0700 | [diff] [blame] | 5718 | NetworkSecurityConfigProvider.install(appContext); |
Andreas Gampe | 4c8e542 | 2016-05-18 11:58:47 -0700 | [diff] [blame] | 5719 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Chad Brubaker | 78d4712 | 2015-11-17 22:26:58 -0800 | [diff] [blame] | 5720 | |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 5721 | // Continue loading instrumentation. |
| 5722 | if (ii != null) { |
Alan Viverette | 346296b | 2015-09-01 13:08:05 -0400 | [diff] [blame] | 5723 | final ApplicationInfo instrApp = new ApplicationInfo(); |
Jeff Sharkey | 1544779 | 2015-11-05 16:18:51 -0800 | [diff] [blame] | 5724 | ii.copyTo(instrApp); |
Fyodor Kupolov | af38b8e | 2015-12-02 16:16:07 -0800 | [diff] [blame] | 5725 | instrApp.initForUser(UserHandle.myUserId()); |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 5726 | final LoadedApk pi = getPackageInfo(instrApp, data.compatInfo, |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 5727 | appContext.getClassLoader(), false, true, false); |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 5728 | final ContextImpl instrContext = ContextImpl.createAppContext(this, pi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5729 | |
| 5730 | try { |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 5731 | final ClassLoader cl = instrContext.getClassLoader(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5732 | mInstrumentation = (Instrumentation) |
| 5733 | cl.loadClass(data.instrumentationName.getClassName()).newInstance(); |
| 5734 | } catch (Exception e) { |
| 5735 | throw new RuntimeException( |
| 5736 | "Unable to instantiate instrumentation " |
| 5737 | + data.instrumentationName + ": " + e.toString(), e); |
| 5738 | } |
| 5739 | |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 5740 | final ComponentName component = new ComponentName(ii.packageName, ii.name); |
| 5741 | mInstrumentation.init(this, instrContext, appContext, component, |
| 5742 | data.instrumentationWatcher, data.instrumentationUiAutomationConnection); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5743 | |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 5744 | if (mProfiler.profileFile != null && !ii.handleProfiling |
| 5745 | && mProfiler.profileFd == null) { |
| 5746 | mProfiler.handlingProfiling = true; |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 5747 | final File file = new File(mProfiler.profileFile); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5748 | file.getParentFile().mkdirs(); |
| 5749 | Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024); |
| 5750 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5751 | } else { |
| 5752 | mInstrumentation = new Instrumentation(); |
| 5753 | } |
| 5754 | |
Dianne Hackborn | 3b81bc1 | 2011-01-15 11:50:52 -0800 | [diff] [blame] | 5755 | if ((data.appInfo.flags&ApplicationInfo.FLAG_LARGE_HEAP) != 0) { |
Dianne Hackborn | de39851 | 2011-01-18 18:45:21 -0800 | [diff] [blame] | 5756 | dalvik.system.VMRuntime.getRuntime().clearGrowthLimit(); |
Mathieu Chartier | 24cee07 | 2015-01-08 14:42:20 -0800 | [diff] [blame] | 5757 | } else { |
| 5758 | // Small heap, clamp to the current growth limit and let the heap release |
| 5759 | // pages after the growth limit to the non growth limit capacity. b/18387825 |
| 5760 | dalvik.system.VMRuntime.getRuntime().clampGrowthLimit(); |
Dianne Hackborn | 3b81bc1 | 2011-01-15 11:50:52 -0800 | [diff] [blame] | 5761 | } |
| 5762 | |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 5763 | // Allow disk access during application and provider setup. This could |
Jeff Sharkey | 7c50167 | 2012-02-28 12:08:37 -0800 | [diff] [blame] | 5764 | // block processing ordered broadcasts, but later processing would |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 5765 | // probably end up doing the same disk access. |
Jeff Sharkey | 7c50167 | 2012-02-28 12:08:37 -0800 | [diff] [blame] | 5766 | final StrictMode.ThreadPolicy savedPolicy = StrictMode.allowThreadDiskWrites(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5767 | try { |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 5768 | // If the app is being launched for full backup or restore, bring it up in |
| 5769 | // a restricted environment with the base application class. |
| 5770 | Application app = data.info.makeApplication(data.restrictedBackupMode, null); |
| 5771 | mInitialApplication = app; |
Jeff Sharkey | 7c50167 | 2012-02-28 12:08:37 -0800 | [diff] [blame] | 5772 | |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 5773 | // don't bring up providers in restricted mode; they may depend on the |
| 5774 | // app's custom Application class |
| 5775 | if (!data.restrictedBackupMode) { |
Jeff Sharkey | 3e19589 | 2016-03-05 19:48:59 -0700 | [diff] [blame] | 5776 | if (!ArrayUtils.isEmpty(data.providers)) { |
| 5777 | installContentProviders(app, data.providers); |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 5778 | // For process that contains content providers, we want to |
| 5779 | // ensure that the JIT is enabled "at some point". |
| 5780 | mH.sendEmptyMessageDelayed(H.ENABLE_JIT, 10*1000); |
| 5781 | } |
| 5782 | } |
| 5783 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5784 | // Do this after providers, since instrumentation tests generally start their |
| 5785 | // test thread at this point, and we don't want that racing. |
| 5786 | try { |
| 5787 | mInstrumentation.onCreate(data.instrumentationArgs); |
| 5788 | } |
| 5789 | catch (Exception e) { |
| 5790 | throw new RuntimeException( |
| 5791 | "Exception thrown in onCreate() of " |
| 5792 | + data.instrumentationName + ": " + e.toString(), e); |
| 5793 | } |
| 5794 | |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 5795 | try { |
| 5796 | mInstrumentation.callApplicationOnCreate(app); |
| 5797 | } catch (Exception e) { |
| 5798 | if (!mInstrumentation.onException(app, e)) { |
| 5799 | throw new RuntimeException( |
| 5800 | "Unable to create application " + app.getClass().getName() |
| 5801 | + ": " + e.toString(), e); |
| 5802 | } |
| 5803 | } |
| 5804 | } finally { |
| 5805 | StrictMode.setThreadPolicy(savedPolicy); |
| 5806 | } |
Clara Bayarri | 4b5a4d2 | 2017-01-27 20:15:45 +0000 | [diff] [blame] | 5807 | |
| 5808 | // Preload fonts resources |
Clara Bayarri | ff22161 | 2017-03-15 17:27:31 +0000 | [diff] [blame] | 5809 | Typeface.setApplicationContext(appContext); |
Clara Bayarri | 4b5a4d2 | 2017-01-27 20:15:45 +0000 | [diff] [blame] | 5810 | try { |
| 5811 | final ApplicationInfo info = |
Amith Yamasani | 336d29d | 2017-02-14 15:14:09 -0800 | [diff] [blame] | 5812 | getPackageManager().getApplicationInfo( |
Clara Bayarri | 4b5a4d2 | 2017-01-27 20:15:45 +0000 | [diff] [blame] | 5813 | data.appInfo.packageName, |
| 5814 | PackageManager.GET_META_DATA /*flags*/, |
| 5815 | UserHandle.myUserId()); |
| 5816 | if (info.metaData != null) { |
| 5817 | final int preloadedFontsResource = info.metaData.getInt( |
| 5818 | ApplicationInfo.METADATA_PRELOADED_FONTS, 0); |
| 5819 | if (preloadedFontsResource != 0) { |
| 5820 | data.info.mResources.preloadFonts(preloadedFontsResource); |
| 5821 | } |
| 5822 | } |
| 5823 | } catch (RemoteException e) { |
| 5824 | throw e.rethrowFromSystemServer(); |
| 5825 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5826 | } |
| 5827 | |
| 5828 | /*package*/ final void finishInstrumentation(int resultCode, Bundle results) { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5829 | IActivityManager am = ActivityManager.getService(); |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 5830 | if (mProfiler.profileFile != null && mProfiler.handlingProfiling |
| 5831 | && mProfiler.profileFd == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5832 | Debug.stopMethodTracing(); |
| 5833 | } |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5834 | //Slog.i(TAG, "am: " + ActivityManager.getService() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5835 | // + ", app thr: " + mAppThread); |
| 5836 | try { |
| 5837 | am.finishInstrumentation(mAppThread, resultCode, results); |
| 5838 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5839 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5840 | } |
| 5841 | } |
| 5842 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 5843 | private void installContentProviders( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5844 | Context context, List<ProviderInfo> providers) { |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 5845 | final ArrayList<ContentProviderHolder> results = new ArrayList<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5846 | |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 5847 | for (ProviderInfo cpi : providers) { |
Dianne Hackborn | 40e9f29 | 2012-11-27 19:12:23 -0800 | [diff] [blame] | 5848 | if (DEBUG_PROVIDER) { |
| 5849 | StringBuilder buf = new StringBuilder(128); |
| 5850 | buf.append("Pub "); |
| 5851 | buf.append(cpi.authority); |
| 5852 | buf.append(": "); |
| 5853 | buf.append(cpi.name); |
| 5854 | Log.i(TAG, buf.toString()); |
| 5855 | } |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 5856 | ContentProviderHolder cph = installProvider(context, null, cpi, |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5857 | false /*noisy*/, true /*noReleaseNeeded*/, true /*stable*/); |
| 5858 | if (cph != null) { |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5859 | cph.noReleaseNeeded = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5860 | results.add(cph); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5861 | } |
| 5862 | } |
| 5863 | |
| 5864 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5865 | ActivityManager.getService().publishContentProviders( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5866 | getApplicationThread(), results); |
| 5867 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5868 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5869 | } |
| 5870 | } |
| 5871 | |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 5872 | public final IContentProvider acquireProvider( |
| 5873 | Context c, String auth, int userId, boolean stable) { |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 5874 | final IContentProvider provider = acquireExistingProvider(c, auth, userId, stable); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5875 | if (provider != null) { |
| 5876 | return provider; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5877 | } |
| 5878 | |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 5879 | // There is a possible race here. Another thread may try to acquire |
| 5880 | // the same provider at the same time. When this happens, we want to ensure |
| 5881 | // that the first one wins. |
| 5882 | // Note that we cannot hold the lock while acquiring and installing the |
| 5883 | // provider since it might take a long time to run and it could also potentially |
| 5884 | // 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] | 5885 | ContentProviderHolder holder = null; |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 5886 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5887 | holder = ActivityManager.getService().getContentProvider( |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 5888 | getApplicationThread(), auth, userId, stable); |
| 5889 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5890 | throw ex.rethrowFromSystemServer(); |
Wale Ogunwale | 67fe0a4 | 2015-04-24 14:44:54 -0700 | [diff] [blame] | 5891 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5892 | if (holder == null) { |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 5893 | 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] | 5894 | return null; |
| 5895 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5896 | |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5897 | // Install provider will increment the reference count for us, and break |
| 5898 | // any ties in the race. |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5899 | holder = installProvider(c, holder, holder.info, |
| 5900 | true /*noisy*/, holder.noReleaseNeeded, stable); |
| 5901 | return holder.provider; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5902 | } |
| 5903 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5904 | private final void incProviderRefLocked(ProviderRefCount prc, boolean stable) { |
| 5905 | if (stable) { |
| 5906 | prc.stableCount += 1; |
| 5907 | if (prc.stableCount == 1) { |
| 5908 | // We are acquiring a new stable reference on the provider. |
| 5909 | int unstableDelta; |
| 5910 | if (prc.removePending) { |
| 5911 | // We have a pending remove operation, which is holding the |
| 5912 | // last unstable reference. At this point we are converting |
| 5913 | // that unstable reference to our new stable reference. |
| 5914 | unstableDelta = -1; |
| 5915 | // Cancel the removal of the provider. |
| 5916 | if (DEBUG_PROVIDER) { |
| 5917 | Slog.v(TAG, "incProviderRef: stable " |
| 5918 | + "snatched provider from the jaws of death"); |
| 5919 | } |
| 5920 | prc.removePending = false; |
Guobin Zhang | 9e3e5266 | 2013-03-21 13:57:11 +0800 | [diff] [blame] | 5921 | // There is a race! It fails to remove the message, which |
| 5922 | // will be handled in completeRemoveProvider(). |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5923 | mH.removeMessages(H.REMOVE_PROVIDER, prc); |
| 5924 | } else { |
| 5925 | unstableDelta = 0; |
| 5926 | } |
| 5927 | try { |
| 5928 | if (DEBUG_PROVIDER) { |
| 5929 | Slog.v(TAG, "incProviderRef Now stable - " |
| 5930 | + prc.holder.info.name + ": unstableDelta=" |
| 5931 | + unstableDelta); |
| 5932 | } |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5933 | ActivityManager.getService().refContentProvider( |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5934 | prc.holder.connection, 1, unstableDelta); |
| 5935 | } catch (RemoteException e) { |
| 5936 | //do nothing content provider object is dead any way |
| 5937 | } |
| 5938 | } |
| 5939 | } else { |
| 5940 | prc.unstableCount += 1; |
| 5941 | if (prc.unstableCount == 1) { |
| 5942 | // We are acquiring a new unstable reference on the provider. |
| 5943 | if (prc.removePending) { |
| 5944 | // Oh look, we actually have a remove pending for the |
| 5945 | // provider, which is still holding the last unstable |
| 5946 | // reference. We just need to cancel that to take new |
| 5947 | // ownership of the reference. |
| 5948 | if (DEBUG_PROVIDER) { |
| 5949 | Slog.v(TAG, "incProviderRef: unstable " |
| 5950 | + "snatched provider from the jaws of death"); |
| 5951 | } |
| 5952 | prc.removePending = false; |
| 5953 | mH.removeMessages(H.REMOVE_PROVIDER, prc); |
| 5954 | } else { |
| 5955 | // First unstable ref, increment our count in the |
| 5956 | // activity manager. |
| 5957 | try { |
| 5958 | if (DEBUG_PROVIDER) { |
| 5959 | Slog.v(TAG, "incProviderRef: Now unstable - " |
| 5960 | + prc.holder.info.name); |
| 5961 | } |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 5962 | ActivityManager.getService().refContentProvider( |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5963 | prc.holder.connection, 0, 1); |
| 5964 | } catch (RemoteException e) { |
| 5965 | //do nothing content provider object is dead any way |
| 5966 | } |
| 5967 | } |
| 5968 | } |
| 5969 | } |
| 5970 | } |
| 5971 | |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 5972 | public final IContentProvider acquireExistingProvider( |
| 5973 | Context c, String auth, int userId, boolean stable) { |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5974 | synchronized (mProviderMap) { |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 5975 | final ProviderKey key = new ProviderKey(auth, userId); |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 5976 | final ProviderClientRecord pr = mProviderMap.get(key); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5977 | if (pr == null) { |
| 5978 | return null; |
| 5979 | } |
| 5980 | |
| 5981 | IContentProvider provider = pr.mProvider; |
| 5982 | IBinder jBinder = provider.asBinder(); |
Dianne Hackborn | c428aae | 2012-10-03 16:38:22 -0700 | [diff] [blame] | 5983 | if (!jBinder.isBinderAlive()) { |
| 5984 | // The hosting process of the provider has died; we can't |
| 5985 | // use this one. |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 5986 | Log.i(TAG, "Acquiring provider " + auth + " for user " + userId |
Dianne Hackborn | c428aae | 2012-10-03 16:38:22 -0700 | [diff] [blame] | 5987 | + ": existing object's process dead"); |
| 5988 | handleUnstableProviderDiedLocked(jBinder, true); |
| 5989 | return null; |
| 5990 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5991 | |
| 5992 | // Only increment the ref count if we have one. If we don't then the |
| 5993 | // provider is not reference counted and never needs to be released. |
Dianne Hackborn | cca1f0e | 2010-09-26 18:34:53 -0700 | [diff] [blame] | 5994 | ProviderRefCount prc = mProviderRefCountMap.get(jBinder); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5995 | if (prc != null) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5996 | incProviderRefLocked(prc, stable); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5997 | } |
| 5998 | return provider; |
| 5999 | } |
Dianne Hackborn | cca1f0e | 2010-09-26 18:34:53 -0700 | [diff] [blame] | 6000 | } |
| 6001 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6002 | public final boolean releaseProvider(IContentProvider provider, boolean stable) { |
| 6003 | if (provider == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6004 | return false; |
| 6005 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6006 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6007 | IBinder jBinder = provider.asBinder(); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6008 | synchronized (mProviderMap) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6009 | ProviderRefCount prc = mProviderRefCountMap.get(jBinder); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6010 | if (prc == null) { |
| 6011 | // 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] | 6012 | return false; |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6013 | } |
| 6014 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6015 | boolean lastRef = false; |
| 6016 | if (stable) { |
| 6017 | if (prc.stableCount == 0) { |
| 6018 | if (DEBUG_PROVIDER) Slog.v(TAG, |
| 6019 | "releaseProvider: stable ref count already 0, how?"); |
| 6020 | return false; |
| 6021 | } |
| 6022 | prc.stableCount -= 1; |
| 6023 | if (prc.stableCount == 0) { |
| 6024 | // What we do at this point depends on whether there are |
| 6025 | // any unstable refs left: if there are, we just tell the |
| 6026 | // activity manager to decrement its stable count; if there |
| 6027 | // aren't, we need to enqueue this provider to be removed, |
| 6028 | // and convert to holding a single unstable ref while |
| 6029 | // doing so. |
| 6030 | lastRef = prc.unstableCount == 0; |
| 6031 | try { |
| 6032 | if (DEBUG_PROVIDER) { |
| 6033 | Slog.v(TAG, "releaseProvider: No longer stable w/lastRef=" |
| 6034 | + lastRef + " - " + prc.holder.info.name); |
| 6035 | } |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6036 | ActivityManager.getService().refContentProvider( |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6037 | prc.holder.connection, -1, lastRef ? 1 : 0); |
| 6038 | } catch (RemoteException e) { |
| 6039 | //do nothing content provider object is dead any way |
| 6040 | } |
| 6041 | } |
| 6042 | } else { |
| 6043 | if (prc.unstableCount == 0) { |
| 6044 | if (DEBUG_PROVIDER) Slog.v(TAG, |
| 6045 | "releaseProvider: unstable ref count already 0, how?"); |
| 6046 | return false; |
| 6047 | } |
| 6048 | prc.unstableCount -= 1; |
| 6049 | if (prc.unstableCount == 0) { |
| 6050 | // If this is the last reference, we need to enqueue |
| 6051 | // this provider to be removed instead of telling the |
| 6052 | // activity manager to remove it at this point. |
| 6053 | lastRef = prc.stableCount == 0; |
| 6054 | if (!lastRef) { |
| 6055 | try { |
| 6056 | if (DEBUG_PROVIDER) { |
| 6057 | Slog.v(TAG, "releaseProvider: No longer unstable - " |
| 6058 | + prc.holder.info.name); |
| 6059 | } |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6060 | ActivityManager.getService().refContentProvider( |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6061 | prc.holder.connection, 0, -1); |
| 6062 | } catch (RemoteException e) { |
| 6063 | //do nothing content provider object is dead any way |
| 6064 | } |
| 6065 | } |
| 6066 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6067 | } |
| 6068 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6069 | if (lastRef) { |
| 6070 | if (!prc.removePending) { |
| 6071 | // Schedule the actual remove asynchronously, since we don't know the context |
| 6072 | // this will be called in. |
| 6073 | // TODO: it would be nice to post a delayed message, so |
| 6074 | // if we come back and need the same provider quickly |
| 6075 | // we will still have it available. |
| 6076 | if (DEBUG_PROVIDER) { |
| 6077 | Slog.v(TAG, "releaseProvider: Enqueueing pending removal - " |
| 6078 | + prc.holder.info.name); |
| 6079 | } |
| 6080 | prc.removePending = true; |
| 6081 | Message msg = mH.obtainMessage(H.REMOVE_PROVIDER, prc); |
| 6082 | mH.sendMessage(msg); |
| 6083 | } else { |
| 6084 | Slog.w(TAG, "Duplicate remove pending of provider " + prc.holder.info.name); |
| 6085 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6086 | } |
| 6087 | return true; |
| 6088 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6089 | } |
| 6090 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6091 | final void completeRemoveProvider(ProviderRefCount prc) { |
| 6092 | synchronized (mProviderMap) { |
| 6093 | if (!prc.removePending) { |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6094 | // There was a race! Some other client managed to acquire |
| 6095 | // the provider before the removal was completed. |
| 6096 | // Abort the removal. We will do it later. |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6097 | if (DEBUG_PROVIDER) Slog.v(TAG, "completeRemoveProvider: lost the race, " |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6098 | + "provider still in use"); |
| 6099 | return; |
| 6100 | } |
| 6101 | |
Guobin Zhang | 9e3e5266 | 2013-03-21 13:57:11 +0800 | [diff] [blame] | 6102 | // More complicated race!! Some client managed to acquire the |
| 6103 | // provider and release it before the removal was completed. |
| 6104 | // Continue the removal, and abort the next remove message. |
| 6105 | prc.removePending = false; |
| 6106 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6107 | final IBinder jBinder = prc.holder.provider.asBinder(); |
| 6108 | ProviderRefCount existingPrc = mProviderRefCountMap.get(jBinder); |
| 6109 | if (existingPrc == prc) { |
| 6110 | mProviderRefCountMap.remove(jBinder); |
| 6111 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6112 | |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 6113 | for (int i=mProviderMap.size()-1; i>=0; i--) { |
| 6114 | ProviderClientRecord pr = mProviderMap.valueAt(i); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6115 | IBinder myBinder = pr.mProvider.asBinder(); |
| 6116 | if (myBinder == jBinder) { |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 6117 | mProviderMap.removeAt(i); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6118 | } |
| 6119 | } |
| 6120 | } |
| 6121 | |
| 6122 | try { |
| 6123 | if (DEBUG_PROVIDER) { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6124 | Slog.v(TAG, "removeProvider: Invoking ActivityManagerService." |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6125 | + "removeContentProvider(" + prc.holder.info.name + ")"); |
| 6126 | } |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6127 | ActivityManager.getService().removeContentProvider( |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6128 | prc.holder.connection, false); |
| 6129 | } catch (RemoteException e) { |
| 6130 | //do nothing content provider object is dead any way |
| 6131 | } |
| 6132 | } |
| 6133 | |
| 6134 | final void handleUnstableProviderDied(IBinder provider, boolean fromClient) { |
Dianne Hackborn | c428aae | 2012-10-03 16:38:22 -0700 | [diff] [blame] | 6135 | synchronized (mProviderMap) { |
| 6136 | handleUnstableProviderDiedLocked(provider, fromClient); |
| 6137 | } |
| 6138 | } |
| 6139 | |
| 6140 | final void handleUnstableProviderDiedLocked(IBinder provider, boolean fromClient) { |
| 6141 | ProviderRefCount prc = mProviderRefCountMap.get(provider); |
| 6142 | if (prc != null) { |
| 6143 | if (DEBUG_PROVIDER) Slog.v(TAG, "Cleaning up dead provider " |
| 6144 | + provider + " " + prc.holder.info.name); |
| 6145 | mProviderRefCountMap.remove(provider); |
You Kim | bc74de6 | 2013-10-01 00:13:26 +0900 | [diff] [blame] | 6146 | for (int i=mProviderMap.size()-1; i>=0; i--) { |
| 6147 | ProviderClientRecord pr = mProviderMap.valueAt(i); |
| 6148 | if (pr != null && pr.mProvider.asBinder() == provider) { |
| 6149 | Slog.i(TAG, "Removing dead content provider:" + pr.mProvider.toString()); |
| 6150 | mProviderMap.removeAt(i); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6151 | } |
Dianne Hackborn | c428aae | 2012-10-03 16:38:22 -0700 | [diff] [blame] | 6152 | } |
You Kim | bc74de6 | 2013-10-01 00:13:26 +0900 | [diff] [blame] | 6153 | |
Dianne Hackborn | c428aae | 2012-10-03 16:38:22 -0700 | [diff] [blame] | 6154 | if (fromClient) { |
| 6155 | // We found out about this due to execution in our client |
| 6156 | // code. Tell the activity manager about it now, to ensure |
| 6157 | // that the next time we go to do anything with the provider |
| 6158 | // it knows it is dead (so we don't race with its death |
| 6159 | // notification). |
| 6160 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6161 | ActivityManager.getService().unstableProviderDied( |
Dianne Hackborn | c428aae | 2012-10-03 16:38:22 -0700 | [diff] [blame] | 6162 | prc.holder.connection); |
| 6163 | } catch (RemoteException e) { |
| 6164 | //do nothing content provider object is dead any way |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6165 | } |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 6166 | } |
| 6167 | } |
| 6168 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6169 | |
Jeff Sharkey | 7aa7601 | 2013-09-30 14:26:27 -0700 | [diff] [blame] | 6170 | final void appNotRespondingViaProvider(IBinder provider) { |
| 6171 | synchronized (mProviderMap) { |
| 6172 | ProviderRefCount prc = mProviderRefCountMap.get(provider); |
| 6173 | if (prc != null) { |
| 6174 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6175 | ActivityManager.getService() |
Jeff Sharkey | 7aa7601 | 2013-09-30 14:26:27 -0700 | [diff] [blame] | 6176 | .appNotRespondingViaProvider(prc.holder.connection); |
| 6177 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 6178 | throw e.rethrowFromSystemServer(); |
Jeff Sharkey | 7aa7601 | 2013-09-30 14:26:27 -0700 | [diff] [blame] | 6179 | } |
| 6180 | } |
| 6181 | } |
| 6182 | } |
| 6183 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6184 | private ProviderClientRecord installProviderAuthoritiesLocked(IContentProvider provider, |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 6185 | ContentProvider localProvider, ContentProviderHolder holder) { |
Andreas Gampe | 18e99c1 | 2015-03-06 15:29:06 -0800 | [diff] [blame] | 6186 | final String auths[] = holder.info.authority.split(";"); |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 6187 | final int userId = UserHandle.getUserId(holder.info.applicationInfo.uid); |
| 6188 | |
Jeff Sharkey | 0a17db1 | 2016-11-04 11:23:46 -0600 | [diff] [blame] | 6189 | if (provider != null) { |
| 6190 | // If this provider is hosted by the core OS and cannot be upgraded, |
| 6191 | // then I guess we're okay doing blocking calls to it. |
| 6192 | for (String auth : auths) { |
| 6193 | switch (auth) { |
| 6194 | case ContactsContract.AUTHORITY: |
| 6195 | case CallLog.AUTHORITY: |
| 6196 | case CallLog.SHADOW_AUTHORITY: |
| 6197 | case BlockedNumberContract.AUTHORITY: |
| 6198 | case CalendarContract.AUTHORITY: |
| 6199 | case Downloads.Impl.AUTHORITY: |
Jeff Sharkey | cb62162 | 2016-11-11 14:04:32 -0700 | [diff] [blame] | 6200 | case "telephony": |
Jeff Sharkey | 0a17db1 | 2016-11-04 11:23:46 -0600 | [diff] [blame] | 6201 | Binder.allowBlocking(provider.asBinder()); |
| 6202 | } |
| 6203 | } |
| 6204 | } |
| 6205 | |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 6206 | final ProviderClientRecord pcr = new ProviderClientRecord( |
| 6207 | auths, provider, localProvider, holder); |
| 6208 | for (String auth : auths) { |
| 6209 | final ProviderKey key = new ProviderKey(auth, userId); |
| 6210 | final ProviderClientRecord existing = mProviderMap.get(key); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6211 | if (existing != null) { |
| 6212 | Slog.w(TAG, "Content provider " + pcr.mHolder.info.name |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 6213 | + " already published as " + auth); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6214 | } else { |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 6215 | mProviderMap.put(key, pcr); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6216 | } |
| 6217 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6218 | return pcr; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6219 | } |
| 6220 | |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6221 | /** |
| 6222 | * Installs the provider. |
| 6223 | * |
| 6224 | * Providers that are local to the process or that come from the system server |
| 6225 | * may be installed permanently which is indicated by setting noReleaseNeeded to true. |
| 6226 | * Other remote providers are reference counted. The initial reference count |
| 6227 | * for all reference counted providers is one. Providers that are not reference |
| 6228 | * counted do not have a reference count (at all). |
| 6229 | * |
| 6230 | * This method detects when a provider has already been installed. When this happens, |
| 6231 | * it increments the reference count of the existing provider (if appropriate) |
| 6232 | * and returns the existing provider. This can happen due to concurrent |
| 6233 | * attempts to acquire the same provider. |
| 6234 | */ |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 6235 | private ContentProviderHolder installProvider(Context context, |
| 6236 | ContentProviderHolder holder, ProviderInfo info, |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6237 | boolean noisy, boolean noReleaseNeeded, boolean stable) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6238 | ContentProvider localProvider = null; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6239 | IContentProvider provider; |
Dianne Hackborn | 5f48fca | 2012-05-30 11:06:31 -0700 | [diff] [blame] | 6240 | if (holder == null || holder.provider == null) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6241 | if (DEBUG_PROVIDER || noisy) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 6242 | Slog.d(TAG, "Loading provider " + info.authority + ": " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6243 | + info.name); |
| 6244 | } |
| 6245 | Context c = null; |
| 6246 | ApplicationInfo ai = info.applicationInfo; |
| 6247 | if (context.getPackageName().equals(ai.packageName)) { |
| 6248 | c = context; |
| 6249 | } else if (mInitialApplication != null && |
| 6250 | mInitialApplication.getPackageName().equals(ai.packageName)) { |
| 6251 | c = mInitialApplication; |
| 6252 | } else { |
| 6253 | try { |
| 6254 | c = context.createPackageContext(ai.packageName, |
| 6255 | Context.CONTEXT_INCLUDE_CODE); |
| 6256 | } catch (PackageManager.NameNotFoundException e) { |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 6257 | // Ignore |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6258 | } |
| 6259 | } |
| 6260 | if (c == null) { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 6261 | Slog.w(TAG, "Unable to get context for package " + |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6262 | ai.packageName + |
| 6263 | " while loading content provider " + |
| 6264 | info.name); |
| 6265 | return null; |
| 6266 | } |
Adam Lesinski | 4e86281 | 2016-11-21 16:02:24 -0800 | [diff] [blame] | 6267 | |
| 6268 | if (info.splitName != null) { |
| 6269 | try { |
| 6270 | c = c.createContextForSplit(info.splitName); |
| 6271 | } catch (NameNotFoundException e) { |
| 6272 | throw new RuntimeException(e); |
| 6273 | } |
| 6274 | } |
| 6275 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6276 | try { |
| 6277 | final java.lang.ClassLoader cl = c.getClassLoader(); |
| 6278 | localProvider = (ContentProvider)cl. |
| 6279 | loadClass(info.name).newInstance(); |
| 6280 | provider = localProvider.getIContentProvider(); |
| 6281 | if (provider == null) { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 6282 | Slog.e(TAG, "Failed to instantiate class " + |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6283 | info.name + " from sourceDir " + |
| 6284 | info.applicationInfo.sourceDir); |
| 6285 | return null; |
| 6286 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6287 | if (DEBUG_PROVIDER) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6288 | TAG, "Instantiating local provider " + info.name); |
| 6289 | // XXX Need to create the correct context for this provider. |
| 6290 | localProvider.attachInfo(c, info); |
| 6291 | } catch (java.lang.Exception e) { |
| 6292 | if (!mInstrumentation.onException(null, e)) { |
| 6293 | throw new RuntimeException( |
| 6294 | "Unable to get provider " + info.name |
| 6295 | + ": " + e.toString(), e); |
| 6296 | } |
| 6297 | return null; |
| 6298 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6299 | } else { |
| 6300 | provider = holder.provider; |
| 6301 | 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] | 6302 | + info.name); |
| 6303 | } |
| 6304 | |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 6305 | ContentProviderHolder retHolder; |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6306 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6307 | synchronized (mProviderMap) { |
| 6308 | if (DEBUG_PROVIDER) Slog.v(TAG, "Checking to add " + provider |
| 6309 | + " / " + info.name); |
| 6310 | IBinder jBinder = provider.asBinder(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6311 | if (localProvider != null) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6312 | ComponentName cname = new ComponentName(info.packageName, info.name); |
| 6313 | ProviderClientRecord pr = mLocalProvidersByName.get(cname); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6314 | if (pr != null) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6315 | if (DEBUG_PROVIDER) { |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6316 | Slog.v(TAG, "installProvider: lost the race, " |
| 6317 | + "using existing local provider"); |
| 6318 | } |
| 6319 | provider = pr.mProvider; |
| 6320 | } else { |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 6321 | holder = new ContentProviderHolder(info); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6322 | holder.provider = provider; |
| 6323 | holder.noReleaseNeeded = true; |
| 6324 | pr = installProviderAuthoritiesLocked(provider, localProvider, holder); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6325 | mLocalProviders.put(jBinder, pr); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6326 | mLocalProvidersByName.put(cname, pr); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6327 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6328 | retHolder = pr.mHolder; |
| 6329 | } else { |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6330 | ProviderRefCount prc = mProviderRefCountMap.get(jBinder); |
| 6331 | if (prc != null) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6332 | if (DEBUG_PROVIDER) { |
| 6333 | Slog.v(TAG, "installProvider: lost the race, updating ref count"); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6334 | } |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 6335 | // We need to transfer our new reference to the existing |
| 6336 | // ref count, releasing the old one... but only if |
| 6337 | // release is needed (that is, it is not running in the |
| 6338 | // system process). |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6339 | if (!noReleaseNeeded) { |
| 6340 | incProviderRefLocked(prc, stable); |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 6341 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6342 | ActivityManager.getService().removeContentProvider( |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 6343 | holder.connection, stable); |
| 6344 | } catch (RemoteException e) { |
| 6345 | //do nothing content provider object is dead any way |
| 6346 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6347 | } |
| 6348 | } else { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6349 | ProviderClientRecord client = installProviderAuthoritiesLocked( |
| 6350 | provider, localProvider, holder); |
| 6351 | if (noReleaseNeeded) { |
| 6352 | prc = new ProviderRefCount(holder, client, 1000, 1000); |
| 6353 | } else { |
| 6354 | prc = stable |
| 6355 | ? new ProviderRefCount(holder, client, 1, 0) |
| 6356 | : new ProviderRefCount(holder, client, 0, 1); |
| 6357 | } |
| 6358 | mProviderRefCountMap.put(jBinder, prc); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 6359 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6360 | retHolder = prc.holder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6361 | } |
| 6362 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 6363 | return retHolder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6364 | } |
| 6365 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 6366 | private void attach(boolean system) { |
Jeff Sharkey | 66a017b | 2013-01-17 18:18:22 -0800 | [diff] [blame] | 6367 | sCurrentActivityThread = this; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6368 | mSystemThread = system; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6369 | if (!system) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 6370 | ViewRootImpl.addFirstDrawHandler(new Runnable() { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 6371 | @Override |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 6372 | public void run() { |
| 6373 | ensureJitEnabled(); |
| 6374 | } |
| 6375 | }); |
Siva Velusamy | d693dfa | 2012-09-10 14:36:58 -0700 | [diff] [blame] | 6376 | android.ddm.DdmHandleAppName.setAppName("<pre-initialized>", |
| 6377 | UserHandle.myUserId()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6378 | RuntimeInit.setApplicationObject(mAppThread.asBinder()); |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 6379 | final IActivityManager mgr = ActivityManager.getService(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6380 | try { |
| 6381 | mgr.attachApplication(mAppThread); |
| 6382 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 6383 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6384 | } |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 6385 | // Watch for getting close to heap limit. |
| 6386 | BinderInternal.addGcWatcher(new Runnable() { |
| 6387 | @Override public void run() { |
| 6388 | if (!mSomeActivitiesChanged) { |
| 6389 | return; |
| 6390 | } |
| 6391 | Runtime runtime = Runtime.getRuntime(); |
| 6392 | long dalvikMax = runtime.maxMemory(); |
| 6393 | long dalvikUsed = runtime.totalMemory() - runtime.freeMemory(); |
| 6394 | if (dalvikUsed > ((3*dalvikMax)/4)) { |
| 6395 | if (DEBUG_MEMORY_TRIM) Slog.d(TAG, "Dalvik max=" + (dalvikMax/1024) |
| 6396 | + " total=" + (runtime.totalMemory()/1024) |
| 6397 | + " used=" + (dalvikUsed/1024)); |
| 6398 | mSomeActivitiesChanged = false; |
| 6399 | try { |
| 6400 | mgr.releaseSomeActivities(mAppThread); |
| 6401 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 6402 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 6403 | } |
| 6404 | } |
| 6405 | } |
| 6406 | }); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6407 | } else { |
| 6408 | // Don't set application object here -- if the system crashes, |
| 6409 | // 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] | 6410 | android.ddm.DdmHandleAppName.setAppName("system_process", |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 6411 | UserHandle.myUserId()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6412 | try { |
| 6413 | mInstrumentation = new Instrumentation(); |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 6414 | ContextImpl context = ContextImpl.createAppContext( |
| 6415 | this, getSystemContext().mPackageInfo); |
Jeff Brown | 7fc8e35 | 2014-09-16 18:06:47 -0700 | [diff] [blame] | 6416 | mInitialApplication = context.mPackageInfo.makeApplication(true, null); |
| 6417 | mInitialApplication.onCreate(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6418 | } catch (Exception e) { |
| 6419 | throw new RuntimeException( |
| 6420 | "Unable to instantiate Application():" + e.toString(), e); |
| 6421 | } |
| 6422 | } |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 6423 | |
| 6424 | // add dropbox logging to libcore |
| 6425 | DropBox.setReporter(new DropBoxReporter()); |
| 6426 | |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 6427 | ViewRootImpl.ConfigChangedCallback configChangedCallback |
| 6428 | = (Configuration globalConfig) -> { |
| 6429 | synchronized (mResourcesManager) { |
| 6430 | // We need to apply this change to the resources immediately, because upon returning |
| 6431 | // the view hierarchy will be informed about it. |
| 6432 | if (mResourcesManager.applyConfigurationToResourcesLocked(globalConfig, |
| 6433 | null /* compat */)) { |
| 6434 | updateLocaleListFromAppContext(mInitialApplication.getApplicationContext(), |
| 6435 | mResourcesManager.getConfiguration().getLocales()); |
Adam Lesinski | b61e405 | 2016-05-19 18:23:05 -0700 | [diff] [blame] | 6436 | |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 6437 | // This actually changed the resources! Tell everyone about it. |
| 6438 | if (mPendingConfiguration == null |
| 6439 | || mPendingConfiguration.isOtherSeqNewer(globalConfig)) { |
| 6440 | mPendingConfiguration = globalConfig; |
| 6441 | sendMessage(H.CONFIGURATION_CHANGED, globalConfig); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6442 | } |
| 6443 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6444 | } |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 6445 | }; |
| 6446 | ViewRootImpl.addConfigCallback(configChangedCallback); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6447 | } |
| 6448 | |
Romain Guy | 5e9120d | 2012-01-30 12:17:22 -0800 | [diff] [blame] | 6449 | public static ActivityThread systemMain() { |
Alan Viverette | 5e1565e | 2014-07-29 16:14:25 -0700 | [diff] [blame] | 6450 | // The system process on low-memory devices do not get to use hardware |
| 6451 | // accelerated drawing, since this can add too much overhead to the |
| 6452 | // process. |
| 6453 | if (!ActivityManager.isHighEndGfx()) { |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 6454 | ThreadedRenderer.disable(true); |
John Reck | 73840ea | 2014-09-22 07:39:18 -0700 | [diff] [blame] | 6455 | } else { |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 6456 | ThreadedRenderer.enableForegroundTrimming(); |
Alan Viverette | 5e1565e | 2014-07-29 16:14:25 -0700 | [diff] [blame] | 6457 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6458 | ActivityThread thread = new ActivityThread(); |
| 6459 | thread.attach(true); |
| 6460 | return thread; |
| 6461 | } |
| 6462 | |
Jeff Brown | 10e8971 | 2011-07-08 18:52:57 -0700 | [diff] [blame] | 6463 | public final void installSystemProviders(List<ProviderInfo> providers) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6464 | if (providers != null) { |
Jeff Brown | 10e8971 | 2011-07-08 18:52:57 -0700 | [diff] [blame] | 6465 | installContentProviders(mInitialApplication, providers); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6466 | } |
| 6467 | } |
| 6468 | |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 6469 | public int getIntCoreSetting(String key, int defaultValue) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 6470 | synchronized (mResourcesManager) { |
Svetoslav Ganov | 9aa597e | 2011-03-03 18:17:41 -0800 | [diff] [blame] | 6471 | if (mCoreSettings != null) { |
| 6472 | return mCoreSettings.getInt(key, defaultValue); |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 6473 | } |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 6474 | return defaultValue; |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 6475 | } |
| 6476 | } |
| 6477 | |
Geremy Condra | 69689a7 | 2012-09-11 16:57:17 -0700 | [diff] [blame] | 6478 | private static class EventLoggingReporter implements EventLogger.Reporter { |
| 6479 | @Override |
| 6480 | public void report (int code, Object... list) { |
| 6481 | EventLog.writeEvent(code, list); |
| 6482 | } |
| 6483 | } |
| 6484 | |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 6485 | private class DropBoxReporter implements DropBox.Reporter { |
| 6486 | |
| 6487 | private DropBoxManager dropBox; |
| 6488 | |
Narayan Kamath | 7f06224 | 2015-04-08 13:24:13 +0100 | [diff] [blame] | 6489 | public DropBoxReporter() {} |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 6490 | |
| 6491 | @Override |
| 6492 | public void addData(String tag, byte[] data, int flags) { |
Narayan Kamath | 7f06224 | 2015-04-08 13:24:13 +0100 | [diff] [blame] | 6493 | ensureInitialized(); |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 6494 | dropBox.addData(tag, data, flags); |
| 6495 | } |
| 6496 | |
| 6497 | @Override |
| 6498 | public void addText(String tag, String data) { |
Narayan Kamath | 7f06224 | 2015-04-08 13:24:13 +0100 | [diff] [blame] | 6499 | ensureInitialized(); |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 6500 | dropBox.addText(tag, data); |
| 6501 | } |
Narayan Kamath | 7f06224 | 2015-04-08 13:24:13 +0100 | [diff] [blame] | 6502 | |
| 6503 | private synchronized void ensureInitialized() { |
| 6504 | if (dropBox == null) { |
| 6505 | dropBox = (DropBoxManager) getSystemContext().getSystemService(Context.DROPBOX_SERVICE); |
| 6506 | } |
| 6507 | } |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 6508 | } |
| 6509 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 6510 | public static void main(String[] args) { |
Narayan Kamath | fbb32f6 | 2015-06-12 15:34:35 +0100 | [diff] [blame] | 6511 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "ActivityThreadMain"); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 6512 | SamplingProfilerIntegration.start(); |
| 6513 | |
Brad Fitzpatrick | 4d9e6d2 | 2010-11-15 08:49:51 -0800 | [diff] [blame] | 6514 | // CloseGuard defaults to true and can be quite spammy. We |
| 6515 | // disable it here, but selectively enable it later (via |
| 6516 | // StrictMode) on debug builds, but using DropBox, not logs. |
| 6517 | CloseGuard.setEnabled(false); |
| 6518 | |
Andreas Gampe | d281b42 | 2016-07-08 03:50:27 +0000 | [diff] [blame] | 6519 | Environment.initForCurrentUser(); |
Jeff Sharkey | b049e21 | 2012-09-07 23:16:01 -0700 | [diff] [blame] | 6520 | |
Geremy Condra | 69689a7 | 2012-09-11 16:57:17 -0700 | [diff] [blame] | 6521 | // Set the reporter for event logging in libcore |
| 6522 | EventLogger.setReporter(new EventLoggingReporter()); |
| 6523 | |
Robin Lee | 3d076af | 2014-04-25 14:57:49 +0100 | [diff] [blame] | 6524 | // Make sure TrustedCertificateStore looks in the right place for CA certificates |
| 6525 | final File configDir = Environment.getUserConfigDirectory(UserHandle.myUserId()); |
| 6526 | TrustedCertificateStore.setDefaultUserDirectory(configDir); |
| 6527 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6528 | Process.setArgV0("<pre-initialized>"); |
| 6529 | |
| 6530 | Looper.prepareMainLooper(); |
| 6531 | |
| 6532 | ActivityThread thread = new ActivityThread(); |
| 6533 | thread.attach(false); |
| 6534 | |
Vairavan Srinivasan | 7335cfd | 2012-08-18 18:36:03 -0700 | [diff] [blame] | 6535 | if (sMainThreadHandler == null) { |
| 6536 | sMainThreadHandler = thread.getHandler(); |
| 6537 | } |
| 6538 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6539 | if (false) { |
| 6540 | Looper.myLooper().setMessageLogging(new |
| 6541 | LogPrinter(Log.DEBUG, "ActivityThread")); |
| 6542 | } |
| 6543 | |
Narayan Kamath | fbb32f6 | 2015-06-12 15:34:35 +0100 | [diff] [blame] | 6544 | // End of event ActivityThreadMain. |
| 6545 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6546 | Looper.loop(); |
| 6547 | |
Jeff Brown | 10e8971 | 2011-07-08 18:52:57 -0700 | [diff] [blame] | 6548 | throw new RuntimeException("Main thread loop unexpectedly exited"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6549 | } |
Chris Craik | fc29424 | 2016-12-13 18:10:46 -0800 | [diff] [blame] | 6550 | |
| 6551 | // ------------------ Regular JNI ------------------------ |
| 6552 | |
| 6553 | private native void nDumpGraphicsInfo(FileDescriptor fd); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6554 | } |