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 | |
Adam Lesinski | c1b0ebf | 2016-06-09 11:17:10 -0700 | [diff] [blame] | 19 | import android.annotation.NonNull; |
| 20 | import android.annotation.Nullable; |
Dianne Hackborn | 69c6adc | 2015-06-02 10:52:59 -0700 | [diff] [blame] | 21 | import android.app.assist.AssistContent; |
| 22 | import android.app.assist.AssistStructure; |
Christopher Tate | 4528186 | 2010-03-05 15:46:30 -0800 | [diff] [blame] | 23 | import android.app.backup.BackupAgent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | import android.content.BroadcastReceiver; |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 25 | import android.content.ComponentCallbacks2; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 26 | import android.content.ComponentName; |
| 27 | import android.content.ContentProvider; |
| 28 | import android.content.Context; |
| 29 | import android.content.IContentProvider; |
| 30 | import android.content.Intent; |
Suchi Amalapurapu | 1ccac75 | 2009-06-12 10:09:58 -0700 | [diff] [blame] | 31 | import android.content.IIntentReceiver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | import android.content.pm.ActivityInfo; |
| 33 | import android.content.pm.ApplicationInfo; |
| 34 | import android.content.pm.IPackageManager; |
| 35 | import android.content.pm.InstrumentationInfo; |
Christopher Tate | 346acb1 | 2012-10-15 19:20:25 -0700 | [diff] [blame] | 36 | import android.content.pm.PackageInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | import android.content.pm.PackageManager; |
Sen Hu | bde7570 | 2010-05-28 01:54:03 -0700 | [diff] [blame] | 38 | import android.content.pm.PackageManager.NameNotFoundException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | import android.content.pm.ProviderInfo; |
| 40 | import android.content.pm.ServiceInfo; |
| 41 | import android.content.res.AssetManager; |
Mitsuru Oshima | ba3ba57 | 2009-07-08 18:49:26 -0700 | [diff] [blame] | 42 | import android.content.res.CompatibilityInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 43 | import android.content.res.Configuration; |
| 44 | import android.content.res.Resources; |
Alan Viverette | e54d245 | 2015-05-06 10:41:43 -0700 | [diff] [blame] | 45 | import android.content.res.Resources.Theme; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 | import android.database.sqlite.SQLiteDatabase; |
| 47 | import android.database.sqlite.SQLiteDebug; |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 48 | import android.database.sqlite.SQLiteDebug.DbStats; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | import android.graphics.Bitmap; |
| 50 | import android.graphics.Canvas; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 51 | import android.hardware.display.DisplayManagerGlobal; |
Paul Jensen | e0bef71 | 2014-12-10 15:12:18 -0500 | [diff] [blame] | 52 | import android.net.ConnectivityManager; |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 53 | import android.net.IConnectivityManager; |
Paul Jensen | e0bef71 | 2014-12-10 15:12:18 -0500 | [diff] [blame] | 54 | import android.net.Network; |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 55 | import android.net.Proxy; |
Jason Monk | 207900c | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 56 | import android.net.ProxyInfo; |
Jason Monk | 83520b9 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 57 | import android.net.Uri; |
Joe Onorato | d630f10 | 2011-03-17 18:42:26 -0700 | [diff] [blame] | 58 | import android.os.AsyncTask; |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 59 | import android.os.Binder; |
Jeff Sharkey | 344744b | 2016-01-28 19:03:30 -0700 | [diff] [blame] | 60 | import android.os.Build; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 61 | import android.os.Bundle; |
| 62 | import android.os.Debug; |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 63 | import android.os.DropBoxManager; |
Jeff Sharkey | b049e21 | 2012-09-07 23:16:01 -0700 | [diff] [blame] | 64 | import android.os.Environment; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 65 | import android.os.Handler; |
| 66 | import android.os.IBinder; |
Adam Lesinski | b61e405 | 2016-05-19 18:23:05 -0700 | [diff] [blame] | 67 | import android.os.LocaleList; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 68 | import android.os.Looper; |
| 69 | import android.os.Message; |
| 70 | import android.os.MessageQueue; |
Dianne Hackborn | fabb70b | 2014-11-11 12:22:36 -0800 | [diff] [blame] | 71 | import android.os.Parcel; |
Dianne Hackborn | 9c8dd55 | 2009-06-23 19:22:52 -0700 | [diff] [blame] | 72 | import android.os.ParcelFileDescriptor; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 73 | import android.os.PersistableBundle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 74 | import android.os.Process; |
| 75 | import android.os.RemoteException; |
| 76 | import android.os.ServiceManager; |
Brad Fitzpatrick | 438d059 | 2010-06-10 12:19:19 -0700 | [diff] [blame] | 77 | import android.os.StrictMode; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 78 | import android.os.SystemClock; |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 79 | import android.os.SystemProperties; |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 80 | import android.os.Trace; |
Jeff Sharkey | 369f509 | 2016-02-29 11:16:21 -0700 | [diff] [blame] | 81 | import android.os.TransactionTooLargeException; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 82 | import android.os.UserHandle; |
Narayan Kamath | ccb2a086 | 2013-12-19 14:49:36 +0000 | [diff] [blame] | 83 | import android.provider.Settings; |
Chad Brubaker | c72875b | 2016-04-27 16:35:11 -0700 | [diff] [blame] | 84 | import android.security.NetworkSecurityPolicy; |
Chad Brubaker | 78d4712 | 2015-11-17 22:26:58 -0800 | [diff] [blame] | 85 | import android.security.net.config.NetworkSecurityConfigProvider; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 86 | import android.util.AndroidRuntimeException; |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 87 | import android.util.ArrayMap; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 88 | import android.util.DisplayMetrics; |
| 89 | import android.util.EventLog; |
| 90 | import android.util.Log; |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 91 | import android.util.LogPrinter; |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 92 | import android.util.Pair; |
Jeff Brown | 6754ba2 | 2011-12-14 20:20:01 -0800 | [diff] [blame] | 93 | import android.util.PrintWriterPrinter; |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 94 | import android.util.Slog; |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 95 | import android.util.SparseIntArray; |
Adam Powell | 1487466 | 2013-07-18 19:42:41 -0700 | [diff] [blame] | 96 | import android.util.SuperNotCalledException; |
Adam Lesinski | 3ad1b48 | 2016-04-01 16:41:41 -0700 | [diff] [blame] | 97 | import android.view.ContextThemeWrapper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 98 | import android.view.Display; |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 99 | import android.view.ThreadedRenderer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 100 | import android.view.View; |
| 101 | import android.view.ViewDebug; |
| 102 | import android.view.ViewManager; |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 103 | import android.view.ViewRootImpl; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 104 | import android.view.Window; |
| 105 | import android.view.WindowManager; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 106 | import android.view.WindowManagerGlobal; |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 107 | import android.renderscript.RenderScriptCacheDir; |
Calin Juravle | 6905239 | 2015-12-17 17:06:49 +0200 | [diff] [blame] | 108 | import android.system.Os; |
| 109 | import android.system.OsConstants; |
| 110 | import android.system.ErrnoException; |
Richard Uhler | 2c03619 | 2016-09-14 09:48:31 +0100 | [diff] [blame] | 111 | import android.webkit.WebView; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 112 | |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 113 | import com.android.internal.annotations.GuardedBy; |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 114 | import com.android.internal.app.IVoiceInteractor; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 115 | import com.android.internal.content.ReferrerIntent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 116 | import com.android.internal.os.BinderInternal; |
| 117 | import com.android.internal.os.RuntimeInit; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 118 | import com.android.internal.os.SamplingProfilerIntegration; |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 119 | import com.android.internal.os.SomeArgs; |
Jeff Sharkey | 3e19589 | 2016-03-05 19:48:59 -0700 | [diff] [blame] | 120 | import com.android.internal.util.ArrayUtils; |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 121 | import com.android.internal.util.FastPrintWriter; |
Kenny Root | 12e7522 | 2013-04-23 22:34:24 -0700 | [diff] [blame] | 122 | import com.android.org.conscrypt.OpenSSLSocketImpl; |
Robin Lee | 3d076af | 2014-04-25 14:57:49 +0100 | [diff] [blame] | 123 | import com.android.org.conscrypt.TrustedCertificateStore; |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 124 | import com.google.android.collect.Lists; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 125 | |
| 126 | import java.io.File; |
| 127 | import java.io.FileDescriptor; |
| 128 | import java.io.FileOutputStream; |
Dianne Hackborn | 9c8dd55 | 2009-06-23 19:22:52 -0700 | [diff] [blame] | 129 | import java.io.IOException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 130 | import java.io.PrintWriter; |
| 131 | import java.lang.ref.WeakReference; |
Svet Ganov | 37e4327 | 2016-09-09 16:01:32 -0700 | [diff] [blame] | 132 | import java.lang.reflect.Field; |
| 133 | import java.lang.reflect.InvocationTargetException; |
Robert Greenwalt | 03595d0 | 2010-11-02 14:08:23 -0700 | [diff] [blame] | 134 | import java.net.InetAddress; |
Narayan Kamath | ccb2a086 | 2013-12-19 14:49:36 +0000 | [diff] [blame] | 135 | import java.text.DateFormat; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 136 | import java.util.ArrayList; |
Calin Juravle | f19c963 | 2015-12-10 17:32:15 +0000 | [diff] [blame] | 137 | import java.util.Collections; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 138 | import java.util.List; |
Adam Lesinski | b61e405 | 2016-05-19 18:23:05 -0700 | [diff] [blame] | 139 | import java.util.Locale; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 140 | import java.util.Map; |
Kenny Root | e6585b3 | 2013-12-13 12:00:26 -0800 | [diff] [blame] | 141 | import java.util.Objects; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 142 | import java.util.TimeZone; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 143 | |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 144 | import libcore.io.DropBox; |
Geremy Condra | 69689a7 | 2012-09-11 16:57:17 -0700 | [diff] [blame] | 145 | import libcore.io.EventLogger; |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 146 | import libcore.io.IoUtils; |
Paul Jensen | e401d17 | 2014-09-12 10:47:39 -0400 | [diff] [blame] | 147 | import libcore.net.event.NetworkEventDispatcher; |
Brad Fitzpatrick | 4d9e6d2 | 2010-11-15 08:49:51 -0800 | [diff] [blame] | 148 | import dalvik.system.CloseGuard; |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 149 | import dalvik.system.VMDebug; |
Mathieu Chartier | 1e37090 | 2013-07-18 10:58:01 -0700 | [diff] [blame] | 150 | import dalvik.system.VMRuntime; |
Man Cao | cfa78b2 | 2015-06-11 20:14:34 -0700 | [diff] [blame] | 151 | import org.apache.harmony.dalvik.ddmc.DdmVmInternal; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 152 | |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 153 | final class RemoteServiceException extends AndroidRuntimeException { |
| 154 | public RemoteServiceException(String msg) { |
| 155 | super(msg); |
| 156 | } |
| 157 | } |
| 158 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 159 | /** |
| 160 | * This manages the execution of the main thread in an |
| 161 | * application process, scheduling and executing activities, |
| 162 | * broadcasts, and other operations on it as the activity |
| 163 | * manager requests. |
| 164 | * |
| 165 | * {@hide} |
| 166 | */ |
| 167 | public final class ActivityThread { |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 168 | /** @hide */ |
| 169 | public static final String TAG = "ActivityThread"; |
Jim Miller | 0b2a6d0 | 2010-07-13 18:01:29 -0700 | [diff] [blame] | 170 | 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] | 171 | static final boolean localLOGV = false; |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 172 | static final boolean DEBUG_MESSAGES = false; |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 173 | /** @hide */ |
| 174 | public static final boolean DEBUG_BROADCAST = false; |
Chris Tate | 8a7dc17 | 2009-03-24 20:11:42 -0700 | [diff] [blame] | 175 | private static final boolean DEBUG_RESULTS = false; |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 176 | private static final boolean DEBUG_BACKUP = false; |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 177 | public static final boolean DEBUG_CONFIGURATION = false; |
Dianne Hackborn | a0c283e | 2012-02-09 10:47:01 -0800 | [diff] [blame] | 178 | private static final boolean DEBUG_SERVICE = false; |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 179 | private static final boolean DEBUG_MEMORY_TRIM = false; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 180 | private static final boolean DEBUG_PROVIDER = false; |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 181 | private static final boolean DEBUG_ORDER = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 182 | 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] | 183 | private static final int SQLITE_MEM_RELEASED_EVENT_LOG_TAG = 75003; |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 184 | private static final int LOG_AM_ON_PAUSE_CALLED = 30021; |
| 185 | private static final int LOG_AM_ON_RESUME_CALLED = 30022; |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 186 | 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] | 187 | |
Dianne Hackborn | 455625e | 2015-01-21 09:55:13 -0800 | [diff] [blame] | 188 | /** Type for IActivityManager.serviceDoneExecuting: anonymous operation */ |
| 189 | public static final int SERVICE_DONE_EXECUTING_ANON = 0; |
| 190 | /** Type for IActivityManager.serviceDoneExecuting: done with an onStart call */ |
| 191 | public static final int SERVICE_DONE_EXECUTING_START = 1; |
| 192 | /** Type for IActivityManager.serviceDoneExecuting: done stopping (destroying) service */ |
| 193 | public static final int SERVICE_DONE_EXECUTING_STOP = 2; |
| 194 | |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 195 | // Details for pausing activity. |
| 196 | private static final int USER_LEAVING = 1; |
| 197 | private static final int DONT_REPORT = 2; |
| 198 | |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 199 | // Whether to invoke an activity callback after delivering new configuration. |
| 200 | private static final boolean REPORT_TO_ACTIVITY = true; |
| 201 | |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 202 | private ContextImpl mSystemContext; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 203 | |
Jeff Sharkey | d589663 | 2016-03-04 16:16:00 -0700 | [diff] [blame] | 204 | static volatile IPackageManager sPackageManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 205 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 206 | final ApplicationThread mAppThread = new ApplicationThread(); |
| 207 | final Looper mLooper = Looper.myLooper(); |
| 208 | final H mH = new H(); |
Dianne Hackborn | 782d498 | 2015-07-08 17:36:37 -0700 | [diff] [blame] | 209 | final ArrayMap<IBinder, ActivityClientRecord> mActivities = new ArrayMap<>(); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 210 | // List of new activities (via ActivityRecord.nextIdle) that should |
| 211 | // be reported when next we idle. |
| 212 | ActivityClientRecord mNewActivities = null; |
| 213 | // Number of activities that are currently visible on-screen. |
| 214 | int mNumVisibleActivities = 0; |
Amith Yamasani | 4f128e4 | 2016-05-10 11:44:12 -0700 | [diff] [blame] | 215 | ArrayList<WeakReference<AssistStructure>> mLastAssistStructures = new ArrayList<>(); |
| 216 | private int mLastSessionId; |
Dianne Hackborn | 782d498 | 2015-07-08 17:36:37 -0700 | [diff] [blame] | 217 | final ArrayMap<IBinder, Service> mServices = new ArrayMap<>(); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 218 | AppBindData mBoundApplication; |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 219 | Profiler mProfiler; |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 220 | int mCurDefaultDisplayDpi; |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 221 | boolean mDensityCompatMode; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 222 | Configuration mConfiguration; |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 223 | Configuration mCompatConfiguration; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 224 | Application mInitialApplication; |
| 225 | final ArrayList<Application> mAllApplications |
| 226 | = new ArrayList<Application>(); |
| 227 | // set of instantiated backup agents, keyed by package name |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 228 | final ArrayMap<String, BackupAgent> mBackupAgents = new ArrayMap<String, BackupAgent>(); |
Jeff Sharkey | 66a017b | 2013-01-17 18:18:22 -0800 | [diff] [blame] | 229 | /** Reference to singleton {@link ActivityThread} */ |
Jeff Sharkey | d589663 | 2016-03-04 16:16:00 -0700 | [diff] [blame] | 230 | private static volatile ActivityThread sCurrentActivityThread; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 231 | Instrumentation mInstrumentation; |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 232 | String mInstrumentationPackageName = null; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 233 | String mInstrumentationAppDir = null; |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 234 | String[] mInstrumentationSplitAppDirs = null; |
| 235 | String mInstrumentationLibDir = null; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 236 | String mInstrumentedAppDir = null; |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 237 | String[] mInstrumentedSplitAppDirs = null; |
| 238 | String mInstrumentedLibDir = null; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 239 | boolean mSystemThread = false; |
| 240 | boolean mJitEnabled = false; |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 241 | boolean mSomeActivitiesChanged = false; |
Chong Zhang | 4951f9d | 2016-06-23 13:15:08 -0700 | [diff] [blame] | 242 | boolean mUpdatingSystemConfig = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 243 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 244 | // These can be accessed by multiple threads; mPackages is the lock. |
| 245 | // XXX For now we keep around information about all packages we have |
| 246 | // seen, not removing entries from this map. |
Dianne Hackborn | 1fbee79 | 2011-11-30 11:29:58 -0800 | [diff] [blame] | 247 | // NOTE: The activity and window managers need to call in to |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 248 | // ActivityThread to do things like update resource configurations, |
Dianne Hackborn | 1fbee79 | 2011-11-30 11:29:58 -0800 | [diff] [blame] | 249 | // which means this lock gets held while the activity and window managers |
| 250 | // holds their own lock. Thus you MUST NEVER call back into the activity manager |
| 251 | // 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] | 252 | // These LoadedApk are only valid for the userId that we're running as. |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 253 | final ArrayMap<String, WeakReference<LoadedApk>> mPackages |
| 254 | = new ArrayMap<String, WeakReference<LoadedApk>>(); |
| 255 | final ArrayMap<String, WeakReference<LoadedApk>> mResourcePackages |
| 256 | = new ArrayMap<String, WeakReference<LoadedApk>>(); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 257 | final ArrayList<ActivityClientRecord> mRelaunchingActivities |
| 258 | = new ArrayList<ActivityClientRecord>(); |
| 259 | Configuration mPendingConfiguration = null; |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 260 | // Because we merge activity relaunch operations we can't depend on the ordering provided by |
| 261 | // the handler messages. We need to introduce secondary ordering mechanism, which will allow |
| 262 | // us to drop certain events, if we know that they happened before relaunch we already executed. |
| 263 | // This represents the order of receiving the request from AM. |
| 264 | @GuardedBy("mResourcesManager") |
| 265 | int mLifecycleSeq = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 266 | |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 267 | private final ResourcesManager mResourcesManager; |
| 268 | |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 269 | private static final class ProviderKey { |
| 270 | final String authority; |
| 271 | final int userId; |
| 272 | |
| 273 | public ProviderKey(String authority, int userId) { |
| 274 | this.authority = authority; |
| 275 | this.userId = userId; |
| 276 | } |
| 277 | |
| 278 | @Override |
| 279 | public boolean equals(Object o) { |
| 280 | if (o instanceof ProviderKey) { |
| 281 | final ProviderKey other = (ProviderKey) o; |
Kenny Root | e6585b3 | 2013-12-13 12:00:26 -0800 | [diff] [blame] | 282 | return Objects.equals(authority, other.authority) && userId == other.userId; |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 283 | } |
| 284 | return false; |
| 285 | } |
| 286 | |
| 287 | @Override |
| 288 | public int hashCode() { |
| 289 | return ((authority != null) ? authority.hashCode() : 0) ^ userId; |
| 290 | } |
| 291 | } |
| 292 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 293 | // The lock of mProviderMap protects the following variables. |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 294 | final ArrayMap<ProviderKey, ProviderClientRecord> mProviderMap |
| 295 | = new ArrayMap<ProviderKey, ProviderClientRecord>(); |
| 296 | final ArrayMap<IBinder, ProviderRefCount> mProviderRefCountMap |
| 297 | = new ArrayMap<IBinder, ProviderRefCount>(); |
| 298 | final ArrayMap<IBinder, ProviderClientRecord> mLocalProviders |
| 299 | = new ArrayMap<IBinder, ProviderClientRecord>(); |
| 300 | final ArrayMap<ComponentName, ProviderClientRecord> mLocalProvidersByName |
| 301 | = new ArrayMap<ComponentName, ProviderClientRecord>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 302 | |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 303 | final ArrayMap<Activity, ArrayList<OnActivityPausedListener>> mOnPauseListeners |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 304 | = new ArrayMap<Activity, ArrayList<OnActivityPausedListener>>(); |
Jeff Hamilton | 52d3203 | 2011-01-08 15:31:26 -0600 | [diff] [blame] | 305 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 306 | final GcIdler mGcIdler = new GcIdler(); |
| 307 | boolean mGcIdlerScheduled = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 308 | |
Jeff Sharkey | d589663 | 2016-03-04 16:16:00 -0700 | [diff] [blame] | 309 | static volatile Handler sMainThreadHandler; // set once in main() |
Brad Fitzpatrick | 333b8cb | 2010-08-26 12:04:57 -0700 | [diff] [blame] | 310 | |
Svetoslav Ganov | 9aa597e | 2011-03-03 18:17:41 -0800 | [diff] [blame] | 311 | Bundle mCoreSettings = null; |
| 312 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 313 | static final class ActivityClientRecord { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 314 | IBinder token; |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 315 | int ident; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 316 | Intent intent; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 317 | String referrer; |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 318 | IVoiceInteractor voiceInteractor; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 319 | Bundle state; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 320 | PersistableBundle persistentState; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 321 | Activity activity; |
| 322 | Window window; |
| 323 | Activity parent; |
| 324 | String embeddedID; |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 325 | Activity.NonConfigurationInstances lastNonConfigurationInstances; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 326 | boolean paused; |
| 327 | boolean stopped; |
| 328 | boolean hideForNow; |
| 329 | Configuration newConfig; |
Dianne Hackborn | e88846e | 2009-09-30 21:34:25 -0700 | [diff] [blame] | 330 | Configuration createdConfig; |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 331 | Configuration overrideConfig; |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 332 | // Used for consolidating configs before sending on to Activity. |
| 333 | private Configuration tmpConfig = new Configuration(); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 334 | ActivityClientRecord nextIdle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 335 | |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 336 | ProfilerInfo profilerInfo; |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 337 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 338 | ActivityInfo activityInfo; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 339 | CompatibilityInfo compatInfo; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 340 | LoadedApk packageInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 341 | |
| 342 | List<ResultInfo> pendingResults; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 343 | List<ReferrerIntent> pendingIntents; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 344 | |
| 345 | boolean startsNotResumed; |
| 346 | boolean isForward; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 347 | int pendingConfigChanges; |
| 348 | boolean onlyLocalRequest; |
| 349 | |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 350 | Window mPendingRemoveWindow; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 351 | WindowManager mPendingRemoveWindowManager; |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 352 | boolean mPreserveWindow; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 353 | |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 354 | // Set for relaunch requests, indicates the order number of the relaunch operation, so it |
| 355 | // can be compared with other lifecycle operations. |
| 356 | int relaunchSeq = 0; |
| 357 | |
| 358 | // Can only be accessed from the UI thread. This represents the latest processed message |
| 359 | // that is related to lifecycle events/ |
| 360 | int lastProcessedSeq = 0; |
| 361 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 362 | ActivityClientRecord() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 363 | parent = null; |
| 364 | embeddedID = null; |
| 365 | paused = false; |
| 366 | stopped = false; |
| 367 | hideForNow = false; |
| 368 | nextIdle = null; |
| 369 | } |
| 370 | |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 371 | public boolean isPreHoneycomb() { |
| 372 | if (activity != null) { |
| 373 | return activity.getApplicationInfo().targetSdkVersion |
| 374 | < android.os.Build.VERSION_CODES.HONEYCOMB; |
| 375 | } |
| 376 | return false; |
| 377 | } |
| 378 | |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 379 | public boolean isPersistable() { |
Craig Mautner | 43e52ed | 2014-06-16 17:18:52 -0700 | [diff] [blame] | 380 | return activityInfo.persistableMode == ActivityInfo.PERSIST_ACROSS_REBOOTS; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 381 | } |
| 382 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 383 | public String toString() { |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 384 | ComponentName componentName = intent != null ? intent.getComponent() : null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 385 | return "ActivityRecord{" |
| 386 | + Integer.toHexString(System.identityHashCode(this)) |
| 387 | + " token=" + token + " " + (componentName == null |
| 388 | ? "no component name" : componentName.toShortString()) |
| 389 | + "}"; |
| 390 | } |
Andrii Kulian | 58178f2 | 2016-03-16 13:44:56 -0700 | [diff] [blame] | 391 | |
| 392 | public String getStateString() { |
| 393 | StringBuilder sb = new StringBuilder(); |
| 394 | sb.append("ActivityClientRecord{"); |
| 395 | sb.append("paused=").append(paused); |
| 396 | sb.append(", stopped=").append(stopped); |
| 397 | sb.append(", hideForNow=").append(hideForNow); |
| 398 | sb.append(", startsNotResumed=").append(startsNotResumed); |
| 399 | sb.append(", isForward=").append(isForward); |
| 400 | sb.append(", pendingConfigChanges=").append(pendingConfigChanges); |
| 401 | sb.append(", onlyLocalRequest=").append(onlyLocalRequest); |
| 402 | sb.append(", preserveWindow=").append(mPreserveWindow); |
| 403 | if (activity != null) { |
| 404 | sb.append(", Activity{"); |
| 405 | sb.append("resumed=").append(activity.mResumed); |
| 406 | sb.append(", stopped=").append(activity.mStopped); |
| 407 | sb.append(", finished=").append(activity.isFinishing()); |
| 408 | sb.append(", destroyed=").append(activity.isDestroyed()); |
| 409 | sb.append(", startedActivity=").append(activity.mStartedActivity); |
| 410 | sb.append(", temporaryPause=").append(activity.mTemporaryPause); |
| 411 | sb.append(", changingConfigurations=").append(activity.mChangingConfigurations); |
| 412 | sb.append(", visibleBehind=").append(activity.mVisibleBehind); |
| 413 | sb.append("}"); |
| 414 | } |
| 415 | sb.append("}"); |
| 416 | return sb.toString(); |
| 417 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 418 | } |
| 419 | |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 420 | final class ProviderClientRecord { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 421 | final String[] mNames; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 422 | final IContentProvider mProvider; |
| 423 | final ContentProvider mLocalProvider; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 424 | final IActivityManager.ContentProviderHolder mHolder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 425 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 426 | ProviderClientRecord(String[] names, IContentProvider provider, |
| 427 | ContentProvider localProvider, |
| 428 | IActivityManager.ContentProviderHolder holder) { |
| 429 | mNames = names; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 430 | mProvider = provider; |
| 431 | mLocalProvider = localProvider; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 432 | mHolder = holder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 433 | } |
| 434 | } |
| 435 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 436 | static final class NewIntentData { |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 437 | List<ReferrerIntent> intents; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 438 | IBinder token; |
Wale Ogunwale | 826c706 | 2016-09-13 08:25:54 -0700 | [diff] [blame] | 439 | boolean andPause; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 440 | public String toString() { |
Wale Ogunwale | 826c706 | 2016-09-13 08:25:54 -0700 | [diff] [blame] | 441 | return "NewIntentData{intents=" + intents + " token=" + token |
| 442 | + " andPause=" + andPause +"}"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 443 | } |
| 444 | } |
| 445 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 446 | static final class ReceiverData extends BroadcastReceiver.PendingResult { |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 447 | public ReceiverData(Intent intent, int resultCode, String resultData, Bundle resultExtras, |
Dianne Hackborn | 20e8098 | 2012-08-31 19:00:44 -0700 | [diff] [blame] | 448 | boolean ordered, boolean sticky, IBinder token, int sendingUser) { |
| 449 | super(resultCode, resultData, resultExtras, TYPE_COMPONENT, ordered, sticky, |
riddle_hsu | 1f5ac4d | 2015-01-03 15:38:21 +0800 | [diff] [blame] | 450 | token, sendingUser, intent.getFlags()); |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 451 | this.intent = intent; |
| 452 | } |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 453 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 454 | Intent intent; |
| 455 | ActivityInfo info; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 456 | CompatibilityInfo compatInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 457 | public String toString() { |
| 458 | return "ReceiverData{intent=" + intent + " packageName=" + |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 459 | info.packageName + " resultCode=" + getResultCode() |
| 460 | + " resultData=" + getResultData() + " resultExtras=" |
| 461 | + getResultExtras(false) + "}"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 462 | } |
| 463 | } |
| 464 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 465 | static final class CreateBackupAgentData { |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 466 | ApplicationInfo appInfo; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 467 | CompatibilityInfo compatInfo; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 468 | int backupMode; |
| 469 | public String toString() { |
| 470 | return "CreateBackupAgentData{appInfo=" + appInfo |
| 471 | + " backupAgent=" + appInfo.backupAgentName |
| 472 | + " mode=" + backupMode + "}"; |
| 473 | } |
| 474 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 475 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 476 | static final class CreateServiceData { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 477 | IBinder token; |
| 478 | ServiceInfo info; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 479 | CompatibilityInfo compatInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 480 | Intent intent; |
| 481 | public String toString() { |
| 482 | return "CreateServiceData{token=" + token + " className=" |
| 483 | + info.name + " packageName=" + info.packageName |
| 484 | + " intent=" + intent + "}"; |
| 485 | } |
| 486 | } |
| 487 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 488 | static final class BindServiceData { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 489 | IBinder token; |
| 490 | Intent intent; |
| 491 | boolean rebind; |
| 492 | public String toString() { |
| 493 | return "BindServiceData{token=" + token + " intent=" + intent + "}"; |
| 494 | } |
| 495 | } |
| 496 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 497 | static final class ServiceArgsData { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 498 | IBinder token; |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 499 | boolean taskRemoved; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 500 | int startId; |
Dianne Hackborn | f6f9f2d | 2009-08-21 16:26:03 -0700 | [diff] [blame] | 501 | int flags; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 502 | Intent args; |
| 503 | public String toString() { |
| 504 | return "ServiceArgsData{token=" + token + " startId=" + startId |
| 505 | + " args=" + args + "}"; |
| 506 | } |
| 507 | } |
| 508 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 509 | static final class AppBindData { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 510 | LoadedApk info; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 511 | String processName; |
| 512 | ApplicationInfo appInfo; |
| 513 | List<ProviderInfo> providers; |
| 514 | ComponentName instrumentationName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 515 | Bundle instrumentationArgs; |
| 516 | IInstrumentationWatcher instrumentationWatcher; |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 517 | IUiAutomationConnection instrumentationUiAutomationConnection; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 518 | int debugMode; |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 519 | boolean enableBinderTracking; |
Man Cao | cfa78b2 | 2015-06-11 20:14:34 -0700 | [diff] [blame] | 520 | boolean trackAllocation; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 521 | boolean restrictedBackupMode; |
Dianne Hackborn | 5d927c2 | 2011-09-02 12:22:18 -0700 | [diff] [blame] | 522 | boolean persistent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 523 | Configuration config; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 524 | CompatibilityInfo compatInfo; |
Svet Ganov | 37e4327 | 2016-09-09 16:01:32 -0700 | [diff] [blame] | 525 | String buildSerial; |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 526 | |
| 527 | /** Initial values for {@link Profiler}. */ |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 528 | ProfilerInfo initProfilerInfo; |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 529 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 530 | public String toString() { |
| 531 | return "AppBindData{appInfo=" + appInfo + "}"; |
| 532 | } |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 533 | } |
| 534 | |
| 535 | static final class Profiler { |
| 536 | String profileFile; |
| 537 | ParcelFileDescriptor profileFd; |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 538 | int samplingInterval; |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 539 | boolean autoStopProfiler; |
| 540 | boolean profiling; |
| 541 | boolean handlingProfiling; |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 542 | public void setProfiler(ProfilerInfo profilerInfo) { |
| 543 | ParcelFileDescriptor fd = profilerInfo.profileFd; |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 544 | if (profiling) { |
| 545 | if (fd != null) { |
| 546 | try { |
| 547 | fd.close(); |
| 548 | } catch (IOException e) { |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 549 | // Ignore |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 550 | } |
| 551 | } |
| 552 | return; |
| 553 | } |
| 554 | if (profileFd != null) { |
| 555 | try { |
| 556 | profileFd.close(); |
| 557 | } catch (IOException e) { |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 558 | // Ignore |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 559 | } |
| 560 | } |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 561 | profileFile = profilerInfo.profileFile; |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 562 | profileFd = fd; |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 563 | samplingInterval = profilerInfo.samplingInterval; |
| 564 | autoStopProfiler = profilerInfo.autoStopProfiler; |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 565 | } |
| 566 | public void startProfiling() { |
| 567 | if (profileFd == null || profiling) { |
| 568 | return; |
| 569 | } |
| 570 | try { |
Andreas Gampe | eff0639 | 2016-05-10 12:51:45 -0700 | [diff] [blame] | 571 | int bufferSize = SystemProperties.getInt("debug.traceview-buffer-size-mb", 8); |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 572 | VMDebug.startMethodTracing(profileFile, profileFd.getFileDescriptor(), |
Andreas Gampe | 0f03a01 | 2016-05-09 14:26:07 -0700 | [diff] [blame] | 573 | bufferSize * 1024 * 1024, 0, samplingInterval != 0, samplingInterval); |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 574 | profiling = true; |
| 575 | } catch (RuntimeException e) { |
| 576 | Slog.w(TAG, "Profiling failed on path " + profileFile); |
| 577 | try { |
| 578 | profileFd.close(); |
| 579 | profileFd = null; |
| 580 | } catch (IOException e2) { |
| 581 | Slog.w(TAG, "Failure closing profile fd", e2); |
| 582 | } |
| 583 | } |
| 584 | } |
| 585 | public void stopProfiling() { |
| 586 | if (profiling) { |
| 587 | profiling = false; |
| 588 | Debug.stopMethodTracing(); |
| 589 | if (profileFd != null) { |
| 590 | try { |
| 591 | profileFd.close(); |
| 592 | } catch (IOException e) { |
| 593 | } |
| 594 | } |
| 595 | profileFd = null; |
| 596 | profileFile = null; |
| 597 | } |
| 598 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 599 | } |
| 600 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 601 | static final class DumpComponentInfo { |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 602 | ParcelFileDescriptor fd; |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 603 | IBinder token; |
Dianne Hackborn | 30d7189 | 2010-12-11 10:37:55 -0800 | [diff] [blame] | 604 | String prefix; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 605 | String[] args; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 606 | } |
| 607 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 608 | static final class ResultData { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 609 | IBinder token; |
| 610 | List<ResultInfo> results; |
| 611 | public String toString() { |
| 612 | return "ResultData{token=" + token + " results" + results + "}"; |
| 613 | } |
| 614 | } |
| 615 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 616 | static final class ContextCleanupInfo { |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 617 | ContextImpl context; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 618 | String what; |
| 619 | String who; |
| 620 | } |
| 621 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 622 | static final class DumpHeapData { |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 623 | String path; |
| 624 | ParcelFileDescriptor fd; |
| 625 | } |
| 626 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 627 | static final class UpdateCompatibilityData { |
| 628 | String pkg; |
| 629 | CompatibilityInfo info; |
| 630 | } |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 631 | |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 632 | static final class RequestAssistContextExtras { |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 633 | IBinder activityToken; |
| 634 | IBinder requestToken; |
| 635 | int requestType; |
Amith Yamasani | 4f128e4 | 2016-05-10 11:44:12 -0700 | [diff] [blame] | 636 | int sessionId; |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 637 | } |
Anwar Ghuloum | 3a8ce1b | 2013-04-26 16:18:28 -0700 | [diff] [blame] | 638 | |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 639 | static final class ActivityConfigChangeData { |
| 640 | final IBinder activityToken; |
| 641 | final Configuration overrideConfig; |
| 642 | public ActivityConfigChangeData(IBinder token, Configuration config) { |
| 643 | activityToken = token; |
| 644 | overrideConfig = config; |
| 645 | } |
| 646 | } |
| 647 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 648 | private native void dumpGraphicsInfo(FileDescriptor fd); |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 649 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 650 | private class ApplicationThread extends ApplicationThreadNative { |
Vasu Nori | 3c7131f | 2010-09-21 14:36:57 -0700 | [diff] [blame] | 651 | private static final String DB_INFO_FORMAT = " %8s %8s %14s %14s %s"; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 652 | |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 653 | private int mLastProcessState = -1; |
| 654 | |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 655 | private void updatePendingConfiguration(Configuration config) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 656 | synchronized (mResourcesManager) { |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 657 | if (mPendingConfiguration == null || |
| 658 | mPendingConfiguration.isOtherSeqNewer(config)) { |
| 659 | mPendingConfiguration = config; |
| 660 | } |
| 661 | } |
| 662 | } |
| 663 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 664 | public final void schedulePauseActivity(IBinder token, boolean finished, |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 665 | boolean userLeaving, int configChanges, boolean dontReport) { |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 666 | int seq = getLifecycleSeq(); |
| 667 | if (DEBUG_ORDER) Slog.d(TAG, "pauseActivity " + ActivityThread.this |
| 668 | + " operation received seq: " + seq); |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 669 | sendMessage( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 670 | finished ? H.PAUSE_ACTIVITY_FINISHING : H.PAUSE_ACTIVITY, |
| 671 | token, |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 672 | (userLeaving ? USER_LEAVING : 0) | (dontReport ? DONT_REPORT : 0), |
| 673 | configChanges, |
| 674 | seq); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 675 | } |
| 676 | |
| 677 | public final void scheduleStopActivity(IBinder token, boolean showWindow, |
| 678 | int configChanges) { |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 679 | int seq = getLifecycleSeq(); |
| 680 | if (DEBUG_ORDER) Slog.d(TAG, "stopActivity " + ActivityThread.this |
| 681 | + " operation received seq: " + seq); |
| 682 | sendMessage( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 683 | showWindow ? H.STOP_ACTIVITY_SHOW : H.STOP_ACTIVITY_HIDE, |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 684 | token, 0, configChanges, seq); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 685 | } |
| 686 | |
| 687 | public final void scheduleWindowVisibility(IBinder token, boolean showWindow) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 688 | sendMessage( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 689 | showWindow ? H.SHOW_WINDOW : H.HIDE_WINDOW, |
| 690 | token); |
| 691 | } |
| 692 | |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 693 | public final void scheduleSleeping(IBinder token, boolean sleeping) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 694 | sendMessage(H.SLEEPING, token, sleeping ? 1 : 0); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 695 | } |
| 696 | |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 697 | public final void scheduleResumeActivity(IBinder token, int processState, |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 698 | boolean isForward, Bundle resumeArgs) { |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 699 | int seq = getLifecycleSeq(); |
| 700 | if (DEBUG_ORDER) Slog.d(TAG, "resumeActivity " + ActivityThread.this |
| 701 | + " operation received seq: " + seq); |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 702 | updateProcessState(processState, false); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 703 | 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] | 704 | } |
| 705 | |
| 706 | public final void scheduleSendResult(IBinder token, List<ResultInfo> results) { |
| 707 | ResultData res = new ResultData(); |
| 708 | res.token = token; |
| 709 | res.results = results; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 710 | sendMessage(H.SEND_RESULT, res); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 711 | } |
| 712 | |
| 713 | // we use token to identify this activity without having to send the |
| 714 | // activity itself back to the activity manager. (matters more with ipc) |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 715 | @Override |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 716 | public final void scheduleLaunchActivity(Intent intent, IBinder token, int ident, |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 717 | ActivityInfo info, Configuration curConfig, Configuration overrideConfig, |
| 718 | CompatibilityInfo compatInfo, String referrer, IVoiceInteractor voiceInteractor, |
| 719 | int procState, Bundle state, PersistableBundle persistentState, |
| 720 | List<ResultInfo> pendingResults, List<ReferrerIntent> pendingNewIntents, |
| 721 | boolean notResumed, boolean isForward, ProfilerInfo profilerInfo) { |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 722 | |
| 723 | updateProcessState(procState, false); |
| 724 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 725 | ActivityClientRecord r = new ActivityClientRecord(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 726 | |
| 727 | r.token = token; |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 728 | r.ident = ident; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 729 | r.intent = intent; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 730 | r.referrer = referrer; |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 731 | r.voiceInteractor = voiceInteractor; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 732 | r.activityInfo = info; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 733 | r.compatInfo = compatInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 734 | r.state = state; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 735 | r.persistentState = persistentState; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 736 | |
| 737 | r.pendingResults = pendingResults; |
| 738 | r.pendingIntents = pendingNewIntents; |
| 739 | |
| 740 | r.startsNotResumed = notResumed; |
| 741 | r.isForward = isForward; |
| 742 | |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 743 | r.profilerInfo = profilerInfo; |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 744 | |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 745 | r.overrideConfig = overrideConfig; |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 746 | updatePendingConfiguration(curConfig); |
| 747 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 748 | sendMessage(H.LAUNCH_ACTIVITY, r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 749 | } |
| 750 | |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 751 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 752 | public final void scheduleRelaunchActivity(IBinder token, |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 753 | List<ResultInfo> pendingResults, List<ReferrerIntent> pendingNewIntents, |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 754 | int configChanges, boolean notResumed, Configuration config, |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 755 | Configuration overrideConfig, boolean preserveWindow) { |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 756 | requestRelaunchActivity(token, pendingResults, pendingNewIntents, |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 757 | configChanges, notResumed, config, overrideConfig, true, preserveWindow); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 758 | } |
| 759 | |
Wale Ogunwale | 826c706 | 2016-09-13 08:25:54 -0700 | [diff] [blame] | 760 | public final void scheduleNewIntent( |
| 761 | List<ReferrerIntent> intents, IBinder token, boolean andPause) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 762 | NewIntentData data = new NewIntentData(); |
| 763 | data.intents = intents; |
| 764 | data.token = token; |
Wale Ogunwale | 826c706 | 2016-09-13 08:25:54 -0700 | [diff] [blame] | 765 | data.andPause = andPause; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 766 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 767 | sendMessage(H.NEW_INTENT, data); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 768 | } |
| 769 | |
| 770 | public final void scheduleDestroyActivity(IBinder token, boolean finishing, |
| 771 | int configChanges) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 772 | sendMessage(H.DESTROY_ACTIVITY, token, finishing ? 1 : 0, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 773 | configChanges); |
| 774 | } |
| 775 | |
| 776 | public final void scheduleReceiver(Intent intent, ActivityInfo info, |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 777 | CompatibilityInfo compatInfo, int resultCode, String data, Bundle extras, |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 778 | boolean sync, int sendingUser, int processState) { |
| 779 | updateProcessState(processState, false); |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 780 | ReceiverData r = new ReceiverData(intent, resultCode, data, extras, |
Dianne Hackborn | 20e8098 | 2012-08-31 19:00:44 -0700 | [diff] [blame] | 781 | sync, false, mAppThread.asBinder(), sendingUser); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 782 | r.info = info; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 783 | r.compatInfo = compatInfo; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 784 | sendMessage(H.RECEIVER, r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 785 | } |
| 786 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 787 | public final void scheduleCreateBackupAgent(ApplicationInfo app, |
| 788 | CompatibilityInfo compatInfo, int backupMode) { |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 789 | CreateBackupAgentData d = new CreateBackupAgentData(); |
| 790 | d.appInfo = app; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 791 | d.compatInfo = compatInfo; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 792 | d.backupMode = backupMode; |
| 793 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 794 | sendMessage(H.CREATE_BACKUP_AGENT, d); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 795 | } |
| 796 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 797 | public final void scheduleDestroyBackupAgent(ApplicationInfo app, |
| 798 | CompatibilityInfo compatInfo) { |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 799 | CreateBackupAgentData d = new CreateBackupAgentData(); |
| 800 | d.appInfo = app; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 801 | d.compatInfo = compatInfo; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 802 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 803 | sendMessage(H.DESTROY_BACKUP_AGENT, d); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 804 | } |
| 805 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 806 | public final void scheduleCreateService(IBinder token, |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 807 | ServiceInfo info, CompatibilityInfo compatInfo, int processState) { |
| 808 | updateProcessState(processState, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 809 | CreateServiceData s = new CreateServiceData(); |
| 810 | s.token = token; |
| 811 | s.info = info; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 812 | s.compatInfo = compatInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 813 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 814 | sendMessage(H.CREATE_SERVICE, s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | public final void scheduleBindService(IBinder token, Intent intent, |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 818 | boolean rebind, int processState) { |
| 819 | updateProcessState(processState, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 820 | BindServiceData s = new BindServiceData(); |
| 821 | s.token = token; |
| 822 | s.intent = intent; |
| 823 | s.rebind = rebind; |
| 824 | |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 825 | if (DEBUG_SERVICE) |
| 826 | Slog.v(TAG, "scheduleBindService token=" + token + " intent=" + intent + " uid=" |
| 827 | + Binder.getCallingUid() + " pid=" + Binder.getCallingPid()); |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 828 | sendMessage(H.BIND_SERVICE, s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 829 | } |
| 830 | |
| 831 | public final void scheduleUnbindService(IBinder token, Intent intent) { |
| 832 | BindServiceData s = new BindServiceData(); |
| 833 | s.token = token; |
| 834 | s.intent = intent; |
| 835 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 836 | sendMessage(H.UNBIND_SERVICE, s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 837 | } |
| 838 | |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 839 | public final void scheduleServiceArgs(IBinder token, boolean taskRemoved, int startId, |
Dianne Hackborn | f6f9f2d | 2009-08-21 16:26:03 -0700 | [diff] [blame] | 840 | int flags ,Intent args) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 841 | ServiceArgsData s = new ServiceArgsData(); |
| 842 | s.token = token; |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 843 | s.taskRemoved = taskRemoved; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 844 | s.startId = startId; |
Dianne Hackborn | f6f9f2d | 2009-08-21 16:26:03 -0700 | [diff] [blame] | 845 | s.flags = flags; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 846 | s.args = args; |
| 847 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 848 | sendMessage(H.SERVICE_ARGS, s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 849 | } |
| 850 | |
| 851 | public final void scheduleStopService(IBinder token) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 852 | sendMessage(H.STOP_SERVICE, token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 853 | } |
| 854 | |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 855 | public final void bindApplication(String processName, ApplicationInfo appInfo, |
| 856 | List<ProviderInfo> providers, ComponentName instrumentationName, |
| 857 | ProfilerInfo profilerInfo, Bundle instrumentationArgs, |
| 858 | IInstrumentationWatcher instrumentationWatcher, |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 859 | IUiAutomationConnection instrumentationUiConnection, int debugMode, |
Pablo Ceballos | a4d4e82 | 2015-10-05 10:27:52 -0700 | [diff] [blame] | 860 | boolean enableBinderTracking, boolean trackAllocation, |
| 861 | boolean isRestrictedBackupMode, boolean persistent, Configuration config, |
Svet Ganov | 37e4327 | 2016-09-09 16:01:32 -0700 | [diff] [blame] | 862 | CompatibilityInfo compatInfo, Map<String, IBinder> services, Bundle coreSettings, |
| 863 | String buildSerial) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 864 | |
| 865 | if (services != null) { |
| 866 | // Setup the service cache in the ServiceManager |
| 867 | ServiceManager.initServiceCache(services); |
| 868 | } |
| 869 | |
Svetoslav Ganov | 9aa597e | 2011-03-03 18:17:41 -0800 | [diff] [blame] | 870 | setCoreSettings(coreSettings); |
| 871 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 872 | AppBindData data = new AppBindData(); |
| 873 | data.processName = processName; |
| 874 | data.appInfo = appInfo; |
| 875 | data.providers = providers; |
| 876 | data.instrumentationName = instrumentationName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 877 | data.instrumentationArgs = instrumentationArgs; |
| 878 | data.instrumentationWatcher = instrumentationWatcher; |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 879 | data.instrumentationUiAutomationConnection = instrumentationUiConnection; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 880 | data.debugMode = debugMode; |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 881 | data.enableBinderTracking = enableBinderTracking; |
Man Cao | cfa78b2 | 2015-06-11 20:14:34 -0700 | [diff] [blame] | 882 | data.trackAllocation = trackAllocation; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 883 | data.restrictedBackupMode = isRestrictedBackupMode; |
Dianne Hackborn | 5d927c2 | 2011-09-02 12:22:18 -0700 | [diff] [blame] | 884 | data.persistent = persistent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 885 | data.config = config; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 886 | data.compatInfo = compatInfo; |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 887 | data.initProfilerInfo = profilerInfo; |
Svet Ganov | 37e4327 | 2016-09-09 16:01:32 -0700 | [diff] [blame] | 888 | data.buildSerial = buildSerial; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 889 | sendMessage(H.BIND_APPLICATION, data); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 890 | } |
| 891 | |
| 892 | public final void scheduleExit() { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 893 | sendMessage(H.EXIT_APPLICATION, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 894 | } |
| 895 | |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 896 | public final void scheduleSuicide() { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 897 | sendMessage(H.SUICIDE, null); |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 898 | } |
| 899 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 900 | public void scheduleConfigurationChanged(Configuration config) { |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 901 | updatePendingConfiguration(config); |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 902 | sendMessage(H.CONFIGURATION_CHANGED, config); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 903 | } |
| 904 | |
| 905 | public void updateTimeZone() { |
| 906 | TimeZone.setDefault(null); |
| 907 | } |
| 908 | |
Robert Greenwalt | 03595d0 | 2010-11-02 14:08:23 -0700 | [diff] [blame] | 909 | public void clearDnsCache() { |
| 910 | // a non-standard API to get this to libcore |
| 911 | InetAddress.clearDnsCache(); |
Paul Jensen | e401d17 | 2014-09-12 10:47:39 -0400 | [diff] [blame] | 912 | // Allow libcore to perform the necessary actions as it sees fit upon a network |
| 913 | // configuration change. |
| 914 | NetworkEventDispatcher.getInstance().onNetworkConfigurationChanged(); |
Robert Greenwalt | 03595d0 | 2010-11-02 14:08:23 -0700 | [diff] [blame] | 915 | } |
| 916 | |
Jason Monk | 83520b9 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 917 | public void setHttpProxy(String host, String port, String exclList, Uri pacFileUrl) { |
Paul Jensen | 72db88e | 2015-03-10 10:54:12 -0400 | [diff] [blame] | 918 | final ConnectivityManager cm = ConnectivityManager.from(getSystemContext()); |
| 919 | final Network network = cm.getBoundNetworkForProcess(); |
Paul Jensen | e0bef71 | 2014-12-10 15:12:18 -0500 | [diff] [blame] | 920 | if (network != null) { |
Paul Jensen | 72db88e | 2015-03-10 10:54:12 -0400 | [diff] [blame] | 921 | Proxy.setHttpProxySystemProperty(cm.getDefaultProxy()); |
Paul Jensen | e0bef71 | 2014-12-10 15:12:18 -0500 | [diff] [blame] | 922 | } else { |
| 923 | Proxy.setHttpProxySystemProperty(host, port, exclList, pacFileUrl); |
| 924 | } |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 925 | } |
| 926 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 927 | public void processInBackground() { |
| 928 | mH.removeMessages(H.GC_WHEN_IDLE); |
| 929 | mH.sendMessage(mH.obtainMessage(H.GC_WHEN_IDLE)); |
| 930 | } |
| 931 | |
| 932 | public void dumpService(FileDescriptor fd, IBinder servicetoken, String[] args) { |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 933 | DumpComponentInfo data = new DumpComponentInfo(); |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 934 | try { |
| 935 | data.fd = ParcelFileDescriptor.dup(fd); |
| 936 | data.token = servicetoken; |
| 937 | data.args = args; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 938 | sendMessage(H.DUMP_SERVICE, data, 0, 0, true /*async*/); |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 939 | } catch (IOException e) { |
| 940 | Slog.w(TAG, "dumpService failed", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 941 | } |
| 942 | } |
| 943 | |
| 944 | // This function exists to make sure all receiver dispatching is |
| 945 | // correctly ordered, since these are one-way calls and the binder driver |
| 946 | // applies transaction ordering per object for such calls. |
| 947 | public void scheduleRegisteredReceiver(IIntentReceiver receiver, Intent intent, |
Dianne Hackborn | 68d881c | 2009-10-05 13:58:17 -0700 | [diff] [blame] | 948 | int resultCode, String dataStr, Bundle extras, boolean ordered, |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 949 | boolean sticky, int sendingUser, int processState) throws RemoteException { |
| 950 | updateProcessState(processState, false); |
Dianne Hackborn | 20e8098 | 2012-08-31 19:00:44 -0700 | [diff] [blame] | 951 | receiver.performReceive(intent, resultCode, dataStr, extras, ordered, |
| 952 | sticky, sendingUser); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 953 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 954 | |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 955 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 956 | public void scheduleLowMemory() { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 957 | sendMessage(H.LOW_MEMORY, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 958 | } |
| 959 | |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 960 | @Override |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 961 | public void scheduleActivityConfigurationChanged( |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 962 | IBinder token, Configuration overrideConfig, boolean reportToActivity) { |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 963 | sendMessage(H.ACTIVITY_CONFIGURATION_CHANGED, |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 964 | new ActivityConfigChangeData(token, overrideConfig), reportToActivity ? 1 : 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 965 | } |
| 966 | |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 967 | @Override |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 968 | public void profilerControl(boolean start, ProfilerInfo profilerInfo, int profileType) { |
| 969 | sendMessage(H.PROFILER_CONTROL, profilerInfo, start ? 1 : 0, profileType); |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 970 | } |
| 971 | |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 972 | public void dumpHeap(boolean managed, String path, ParcelFileDescriptor fd) { |
| 973 | DumpHeapData dhd = new DumpHeapData(); |
| 974 | dhd.path = path; |
| 975 | dhd.fd = fd; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 976 | sendMessage(H.DUMP_HEAP, dhd, managed ? 1 : 0, 0, true /*async*/); |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 977 | } |
| 978 | |
Dianne Hackborn | 06de2ea | 2009-05-21 12:56:43 -0700 | [diff] [blame] | 979 | public void setSchedulingGroup(int group) { |
| 980 | // Note: do this immediately, since going into the foreground |
| 981 | // should happen regardless of what pending work we have to do |
| 982 | // and the activity manager will wait for us to report back that |
| 983 | // we are done before sending us to the background. |
| 984 | try { |
| 985 | Process.setProcessGroup(Process.myPid(), group); |
| 986 | } catch (Exception e) { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 987 | Slog.w(TAG, "Failed setting process group to " + group, e); |
Dianne Hackborn | 06de2ea | 2009-05-21 12:56:43 -0700 | [diff] [blame] | 988 | } |
| 989 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 990 | |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 991 | public void dispatchPackageBroadcast(int cmd, String[] packages) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 992 | sendMessage(H.DISPATCH_PACKAGE_BROADCAST, packages, cmd); |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 993 | } |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 994 | |
| 995 | public void scheduleCrash(String msg) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 996 | sendMessage(H.SCHEDULE_CRASH, msg); |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 997 | } |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 998 | |
Dianne Hackborn | 30d7189 | 2010-12-11 10:37:55 -0800 | [diff] [blame] | 999 | public void dumpActivity(FileDescriptor fd, IBinder activitytoken, |
| 1000 | String prefix, String[] args) { |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1001 | DumpComponentInfo data = new DumpComponentInfo(); |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 1002 | try { |
| 1003 | data.fd = ParcelFileDescriptor.dup(fd); |
| 1004 | data.token = activitytoken; |
| 1005 | data.prefix = prefix; |
| 1006 | data.args = args; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1007 | sendMessage(H.DUMP_ACTIVITY, data, 0, 0, true /*async*/); |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 1008 | } catch (IOException e) { |
| 1009 | Slog.w(TAG, "dumpActivity failed", e); |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1010 | } |
| 1011 | } |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 1012 | |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1013 | public void dumpProvider(FileDescriptor fd, IBinder providertoken, |
| 1014 | String[] args) { |
| 1015 | DumpComponentInfo data = new DumpComponentInfo(); |
| 1016 | try { |
| 1017 | data.fd = ParcelFileDescriptor.dup(fd); |
| 1018 | data.token = providertoken; |
| 1019 | data.args = args; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1020 | sendMessage(H.DUMP_PROVIDER, data, 0, 0, true /*async*/); |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1021 | } catch (IOException e) { |
| 1022 | Slog.w(TAG, "dumpProvider failed", e); |
| 1023 | } |
| 1024 | } |
| 1025 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1026 | @Override |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 1027 | public void dumpMemInfo(FileDescriptor fd, Debug.MemoryInfo mem, boolean checkin, |
Colin Cross | c4fb5f9 | 2016-02-02 16:51:15 -0800 | [diff] [blame] | 1028 | boolean dumpFullInfo, boolean dumpDalvik, boolean dumpSummaryOnly, |
| 1029 | boolean dumpUnreachable, String[] args) { |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 1030 | FileOutputStream fout = new FileOutputStream(fd); |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 1031 | PrintWriter pw = new FastPrintWriter(fout); |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 1032 | try { |
Colin Cross | c4fb5f9 | 2016-02-02 16:51:15 -0800 | [diff] [blame] | 1033 | dumpMemInfo(pw, mem, checkin, dumpFullInfo, dumpDalvik, dumpSummaryOnly, dumpUnreachable); |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 1034 | } finally { |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 1035 | pw.flush(); |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 1036 | } |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 1037 | } |
| 1038 | |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 1039 | private void dumpMemInfo(PrintWriter pw, Debug.MemoryInfo memInfo, boolean checkin, |
Colin Cross | c4fb5f9 | 2016-02-02 16:51:15 -0800 | [diff] [blame] | 1040 | boolean dumpFullInfo, boolean dumpDalvik, boolean dumpSummaryOnly, boolean dumpUnreachable) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1041 | long nativeMax = Debug.getNativeHeapSize() / 1024; |
| 1042 | long nativeAllocated = Debug.getNativeHeapAllocatedSize() / 1024; |
| 1043 | long nativeFree = Debug.getNativeHeapFreeSize() / 1024; |
| 1044 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1045 | Runtime runtime = Runtime.getRuntime(); |
Mathieu Chartier | d288a26 | 2015-07-10 13:44:42 -0700 | [diff] [blame] | 1046 | runtime.gc(); // Do GC since countInstancesOfClass counts unreachable objects. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1047 | long dalvikMax = runtime.totalMemory() / 1024; |
| 1048 | long dalvikFree = runtime.freeMemory() / 1024; |
| 1049 | long dalvikAllocated = dalvikMax - dalvikFree; |
Richard Uhler | 2c03619 | 2016-09-14 09:48:31 +0100 | [diff] [blame] | 1050 | |
| 1051 | Class[] classesToCount = new Class[] { |
| 1052 | ContextImpl.class, |
| 1053 | Activity.class, |
| 1054 | WebView.class, |
| 1055 | OpenSSLSocketImpl.class |
| 1056 | }; |
| 1057 | long[] instanceCounts = VMDebug.countInstancesOfClasses(classesToCount, true); |
| 1058 | long appContextInstanceCount = instanceCounts[0]; |
| 1059 | long activityInstanceCount = instanceCounts[1]; |
| 1060 | long webviewInstanceCount = instanceCounts[2]; |
| 1061 | long openSslSocketCount = instanceCounts[3]; |
| 1062 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1063 | long viewInstanceCount = ViewDebug.getViewInstanceCount(); |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1064 | long viewRootInstanceCount = ViewDebug.getViewRootImplCount(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1065 | int globalAssetCount = AssetManager.getGlobalAssetCount(); |
| 1066 | int globalAssetManagerCount = AssetManager.getGlobalAssetManagerCount(); |
| 1067 | int binderLocalObjectCount = Debug.getBinderLocalObjectCount(); |
| 1068 | int binderProxyObjectCount = Debug.getBinderProxyObjectCount(); |
| 1069 | int binderDeathObjectCount = Debug.getBinderDeathObjectCount(); |
Dianne Hackborn | fabb70b | 2014-11-11 12:22:36 -0800 | [diff] [blame] | 1070 | long parcelSize = Parcel.getGlobalAllocSize(); |
| 1071 | long parcelCount = Parcel.getGlobalAllocCount(); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1072 | SQLiteDebug.PagerStats stats = SQLiteDebug.getDatabaseInfo(); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1073 | |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 1074 | dumpMemInfoTable(pw, memInfo, checkin, dumpFullInfo, dumpDalvik, dumpSummaryOnly, |
| 1075 | Process.myPid(), |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 1076 | (mBoundApplication != null) ? mBoundApplication.processName : "unknown", |
| 1077 | nativeMax, nativeAllocated, nativeFree, |
| 1078 | dalvikMax, dalvikAllocated, dalvikFree); |
| 1079 | |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 1080 | if (checkin) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1081 | // NOTE: if you change anything significant below, also consider changing |
| 1082 | // ACTIVITY_THREAD_CHECKIN_VERSION. |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 1083 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1084 | // Object counts |
| 1085 | pw.print(viewInstanceCount); pw.print(','); |
| 1086 | pw.print(viewRootInstanceCount); pw.print(','); |
| 1087 | pw.print(appContextInstanceCount); pw.print(','); |
| 1088 | pw.print(activityInstanceCount); pw.print(','); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1089 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1090 | pw.print(globalAssetCount); pw.print(','); |
| 1091 | pw.print(globalAssetManagerCount); pw.print(','); |
| 1092 | pw.print(binderLocalObjectCount); pw.print(','); |
| 1093 | pw.print(binderProxyObjectCount); pw.print(','); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1094 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1095 | pw.print(binderDeathObjectCount); pw.print(','); |
| 1096 | pw.print(openSslSocketCount); pw.print(','); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1097 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1098 | // SQL |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1099 | pw.print(stats.memoryUsed / 1024); pw.print(','); |
Jeff Brown | 2a293b6 | 2012-01-19 14:02:22 -0800 | [diff] [blame] | 1100 | pw.print(stats.memoryUsed / 1024); pw.print(','); |
| 1101 | pw.print(stats.pageCacheOverflow / 1024); pw.print(','); |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 1102 | pw.print(stats.largestMemAlloc / 1024); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1103 | for (int i = 0; i < stats.dbStats.size(); i++) { |
| 1104 | DbStats dbStats = stats.dbStats.get(i); |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 1105 | pw.print(','); pw.print(dbStats.dbName); |
| 1106 | pw.print(','); pw.print(dbStats.pageSize); |
| 1107 | pw.print(','); pw.print(dbStats.dbSize); |
| 1108 | pw.print(','); pw.print(dbStats.lookaside); |
| 1109 | pw.print(','); pw.print(dbStats.cache); |
| 1110 | pw.print(','); pw.print(dbStats.cache); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1111 | } |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 1112 | pw.println(); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1113 | |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 1114 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1115 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1116 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1117 | pw.println(" "); |
| 1118 | pw.println(" Objects"); |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1119 | printRow(pw, TWO_COUNT_COLUMNS, "Views:", viewInstanceCount, "ViewRootImpl:", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1120 | viewRootInstanceCount); |
| 1121 | |
| 1122 | printRow(pw, TWO_COUNT_COLUMNS, "AppContexts:", appContextInstanceCount, |
| 1123 | "Activities:", activityInstanceCount); |
| 1124 | |
| 1125 | printRow(pw, TWO_COUNT_COLUMNS, "Assets:", globalAssetCount, |
| 1126 | "AssetManagers:", globalAssetManagerCount); |
| 1127 | |
| 1128 | printRow(pw, TWO_COUNT_COLUMNS, "Local Binders:", binderLocalObjectCount, |
| 1129 | "Proxy Binders:", binderProxyObjectCount); |
Dianne Hackborn | fabb70b | 2014-11-11 12:22:36 -0800 | [diff] [blame] | 1130 | printRow(pw, TWO_COUNT_COLUMNS, "Parcel memory:", parcelSize/1024, |
| 1131 | "Parcel count:", parcelCount); |
| 1132 | printRow(pw, TWO_COUNT_COLUMNS, "Death Recipients:", binderDeathObjectCount, |
| 1133 | "OpenSSL Sockets:", openSslSocketCount); |
Richard Uhler | 2c03619 | 2016-09-14 09:48:31 +0100 | [diff] [blame] | 1134 | printRow(pw, ONE_COUNT_COLUMN, "WebViews:", webviewInstanceCount); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1135 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1136 | // SQLite mem info |
| 1137 | pw.println(" "); |
| 1138 | pw.println(" SQL"); |
Jeff Brown | 2a293b6 | 2012-01-19 14:02:22 -0800 | [diff] [blame] | 1139 | printRow(pw, ONE_COUNT_COLUMN, "MEMORY_USED:", stats.memoryUsed / 1024); |
| 1140 | printRow(pw, TWO_COUNT_COLUMNS, "PAGECACHE_OVERFLOW:", |
| 1141 | stats.pageCacheOverflow / 1024, "MALLOC_SIZE:", stats.largestMemAlloc / 1024); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1142 | pw.println(" "); |
| 1143 | int N = stats.dbStats.size(); |
| 1144 | if (N > 0) { |
| 1145 | pw.println(" DATABASES"); |
Vasu Nori | 3c7131f | 2010-09-21 14:36:57 -0700 | [diff] [blame] | 1146 | printRow(pw, " %8s %8s %14s %14s %s", "pgsz", "dbsz", "Lookaside(b)", "cache", |
| 1147 | "Dbname"); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1148 | for (int i = 0; i < N; i++) { |
| 1149 | DbStats dbStats = stats.dbStats.get(i); |
Vasu Nori | 3c7131f | 2010-09-21 14:36:57 -0700 | [diff] [blame] | 1150 | printRow(pw, DB_INFO_FORMAT, |
| 1151 | (dbStats.pageSize > 0) ? String.valueOf(dbStats.pageSize) : " ", |
| 1152 | (dbStats.dbSize > 0) ? String.valueOf(dbStats.dbSize) : " ", |
| 1153 | (dbStats.lookaside > 0) ? String.valueOf(dbStats.lookaside) : " ", |
| 1154 | dbStats.cache, dbStats.dbName); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1155 | } |
| 1156 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1157 | |
Dianne Hackborn | 82e1ee9 | 2009-08-11 18:56:41 -0700 | [diff] [blame] | 1158 | // Asset details. |
| 1159 | String assetAlloc = AssetManager.getAssetAllocations(); |
| 1160 | if (assetAlloc != null) { |
| 1161 | pw.println(" "); |
| 1162 | pw.println(" Asset Allocations"); |
| 1163 | pw.print(assetAlloc); |
| 1164 | } |
Colin Cross | c4fb5f9 | 2016-02-02 16:51:15 -0800 | [diff] [blame] | 1165 | |
| 1166 | // Unreachable native memory |
| 1167 | if (dumpUnreachable) { |
| 1168 | boolean showContents = ((mBoundApplication != null) |
| 1169 | && ((mBoundApplication.appInfo.flags&ApplicationInfo.FLAG_DEBUGGABLE) != 0)) |
| 1170 | || android.os.Build.IS_DEBUGGABLE; |
| 1171 | pw.println(" "); |
| 1172 | pw.println(" Unreachable memory"); |
| 1173 | pw.print(Debug.getUnreachableMemory(100, showContents)); |
| 1174 | } |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 1175 | } |
| 1176 | |
| 1177 | @Override |
| 1178 | public void dumpGfxInfo(FileDescriptor fd, String[] args) { |
| 1179 | dumpGraphicsInfo(fd); |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 1180 | WindowManagerGlobal.getInstance().dumpGfxInfo(fd, args); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1181 | } |
| 1182 | |
riddle_hsu | 1d6c40a | 2014-07-31 00:18:00 +0800 | [diff] [blame] | 1183 | private void dumpDatabaseInfo(FileDescriptor fd, String[] args) { |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 1184 | PrintWriter pw = new FastPrintWriter(new FileOutputStream(fd)); |
Jeff Brown | 6754ba2 | 2011-12-14 20:20:01 -0800 | [diff] [blame] | 1185 | PrintWriterPrinter printer = new PrintWriterPrinter(pw); |
| 1186 | SQLiteDebug.dump(printer, args); |
| 1187 | pw.flush(); |
| 1188 | } |
| 1189 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1190 | @Override |
riddle_hsu | 1d6c40a | 2014-07-31 00:18:00 +0800 | [diff] [blame] | 1191 | public void dumpDbInfo(final FileDescriptor fd, final String[] args) { |
| 1192 | if (mSystemThread) { |
Felipe Leme | 29de492 | 2016-06-07 16:14:07 -0700 | [diff] [blame] | 1193 | // Ensure this invocation is asynchronous to prevent writer waiting if buffer cannot |
| 1194 | // be consumed. But it must duplicate the file descriptor first, since caller might |
| 1195 | // be closing it. |
| 1196 | final ParcelFileDescriptor dup; |
| 1197 | try { |
| 1198 | dup = ParcelFileDescriptor.dup(fd); |
| 1199 | } catch (IOException e) { |
| 1200 | Log.w(TAG, "Could not dup FD " + fd.getInt$()); |
| 1201 | return; |
| 1202 | } |
| 1203 | |
riddle_hsu | 1d6c40a | 2014-07-31 00:18:00 +0800 | [diff] [blame] | 1204 | AsyncTask.THREAD_POOL_EXECUTOR.execute(new Runnable() { |
| 1205 | @Override |
| 1206 | public void run() { |
Felipe Leme | c74972f | 2016-06-08 09:12:37 -0700 | [diff] [blame] | 1207 | try { |
| 1208 | dumpDatabaseInfo(dup.getFileDescriptor(), args); |
| 1209 | } finally { |
| 1210 | IoUtils.closeQuietly(dup); |
| 1211 | } |
riddle_hsu | 1d6c40a | 2014-07-31 00:18:00 +0800 | [diff] [blame] | 1212 | } |
| 1213 | }); |
| 1214 | } else { |
| 1215 | dumpDatabaseInfo(fd, args); |
| 1216 | } |
| 1217 | } |
| 1218 | |
| 1219 | @Override |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1220 | public void unstableProviderDied(IBinder provider) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1221 | sendMessage(H.UNSTABLE_PROVIDER_DIED, provider); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1222 | } |
| 1223 | |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 1224 | @Override |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 1225 | public void requestAssistContextExtras(IBinder activityToken, IBinder requestToken, |
Amith Yamasani | 4f128e4 | 2016-05-10 11:44:12 -0700 | [diff] [blame] | 1226 | int requestType, int sessionId) { |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 1227 | RequestAssistContextExtras cmd = new RequestAssistContextExtras(); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 1228 | cmd.activityToken = activityToken; |
| 1229 | cmd.requestToken = requestToken; |
| 1230 | cmd.requestType = requestType; |
Amith Yamasani | 4f128e4 | 2016-05-10 11:44:12 -0700 | [diff] [blame] | 1231 | cmd.sessionId = sessionId; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1232 | sendMessage(H.REQUEST_ASSIST_CONTEXT_EXTRAS, cmd); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 1233 | } |
| 1234 | |
Svetoslav Ganov | 9aa597e | 2011-03-03 18:17:41 -0800 | [diff] [blame] | 1235 | public void setCoreSettings(Bundle coreSettings) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1236 | sendMessage(H.SET_CORE_SETTINGS, coreSettings); |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1237 | } |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1238 | |
| 1239 | public void updatePackageCompatibilityInfo(String pkg, CompatibilityInfo info) { |
| 1240 | UpdateCompatibilityData ucd = new UpdateCompatibilityData(); |
| 1241 | ucd.pkg = pkg; |
| 1242 | ucd.info = info; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1243 | sendMessage(H.UPDATE_PACKAGE_COMPATIBILITY_INFO, ucd); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1244 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1245 | |
| 1246 | public void scheduleTrimMemory(int level) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1247 | sendMessage(H.TRIM_MEMORY, null, level); |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1248 | } |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1249 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1250 | public void scheduleTranslucentConversionComplete(IBinder token, boolean drawComplete) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1251 | sendMessage(H.TRANSLUCENT_CONVERSION_COMPLETE, token, drawComplete ? 1 : 0); |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1252 | } |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 1253 | |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1254 | public void scheduleOnNewActivityOptions(IBinder token, ActivityOptions options) { |
| 1255 | sendMessage(H.ON_NEW_ACTIVITY_OPTIONS, |
| 1256 | new Pair<IBinder, ActivityOptions>(token, options)); |
| 1257 | } |
| 1258 | |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 1259 | public void setProcessState(int state) { |
| 1260 | updateProcessState(state, true); |
| 1261 | } |
| 1262 | |
| 1263 | public void updateProcessState(int processState, boolean fromIpc) { |
| 1264 | synchronized (this) { |
| 1265 | if (mLastProcessState != processState) { |
| 1266 | mLastProcessState = processState; |
Mathieu Chartier | 1e37090 | 2013-07-18 10:58:01 -0700 | [diff] [blame] | 1267 | // Update Dalvik state based on ActivityManager.PROCESS_STATE_* constants. |
| 1268 | final int DALVIK_PROCESS_STATE_JANK_PERCEPTIBLE = 0; |
| 1269 | final int DALVIK_PROCESS_STATE_JANK_IMPERCEPTIBLE = 1; |
| 1270 | int dalvikProcessState = DALVIK_PROCESS_STATE_JANK_IMPERCEPTIBLE; |
| 1271 | // TODO: Tune this since things like gmail sync are important background but not jank perceptible. |
| 1272 | if (processState <= ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND) { |
| 1273 | dalvikProcessState = DALVIK_PROCESS_STATE_JANK_PERCEPTIBLE; |
| 1274 | } |
| 1275 | VMRuntime.getRuntime().updateProcessState(dalvikProcessState); |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 1276 | if (false) { |
| 1277 | Slog.i(TAG, "******************* PROCESS STATE CHANGED TO: " + processState |
| 1278 | + (fromIpc ? " (from ipc": "")); |
| 1279 | } |
| 1280 | } |
| 1281 | } |
| 1282 | } |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 1283 | |
| 1284 | @Override |
| 1285 | public void scheduleInstallProvider(ProviderInfo provider) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1286 | sendMessage(H.INSTALL_PROVIDER, provider); |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 1287 | } |
Narayan Kamath | ccb2a086 | 2013-12-19 14:49:36 +0000 | [diff] [blame] | 1288 | |
| 1289 | @Override |
| 1290 | public final void updateTimePrefs(boolean is24Hour) { |
| 1291 | DateFormat.set24HourTimePref(is24Hour); |
| 1292 | } |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 1293 | |
| 1294 | @Override |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 1295 | public void scheduleCancelVisibleBehind(IBinder token) { |
| 1296 | sendMessage(H.CANCEL_VISIBLE_BEHIND, token); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 1297 | } |
| 1298 | |
| 1299 | @Override |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 1300 | public void scheduleBackgroundVisibleBehindChanged(IBinder token, boolean visible) { |
| 1301 | sendMessage(H.BACKGROUND_VISIBLE_BEHIND_CHANGED, token, visible ? 1 : 0); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 1302 | } |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 1303 | |
Jeff Sharkey | 605eb79 | 2014-11-04 13:34:06 -0800 | [diff] [blame] | 1304 | @Override |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 1305 | public void scheduleEnterAnimationComplete(IBinder token) { |
| 1306 | sendMessage(H.ENTER_ANIMATION_COMPLETE, token); |
| 1307 | } |
Jeff Sharkey | 605eb79 | 2014-11-04 13:34:06 -0800 | [diff] [blame] | 1308 | |
| 1309 | @Override |
| 1310 | public void notifyCleartextNetwork(byte[] firstPacket) { |
| 1311 | if (StrictMode.vmCleartextNetworkEnabled()) { |
| 1312 | StrictMode.onCleartextNetworkDetected(firstPacket); |
| 1313 | } |
| 1314 | } |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 1315 | |
| 1316 | @Override |
| 1317 | public void startBinderTracking() { |
| 1318 | sendMessage(H.START_BINDER_TRACKING, null); |
| 1319 | } |
| 1320 | |
| 1321 | @Override |
| 1322 | public void stopBinderTrackingAndDump(FileDescriptor fd) { |
| 1323 | try { |
| 1324 | sendMessage(H.STOP_BINDER_TRACKING_AND_DUMP, ParcelFileDescriptor.dup(fd)); |
| 1325 | } catch (IOException e) { |
| 1326 | } |
| 1327 | } |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 1328 | |
| 1329 | @Override |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 1330 | public void scheduleMultiWindowModeChanged(IBinder token, boolean isInMultiWindowMode) |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 1331 | throws RemoteException { |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 1332 | sendMessage(H.MULTI_WINDOW_MODE_CHANGED, token, isInMultiWindowMode ? 1 : 0); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 1333 | } |
| 1334 | |
| 1335 | @Override |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 1336 | public void schedulePictureInPictureModeChanged(IBinder token, boolean isInPipMode) |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 1337 | throws RemoteException { |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 1338 | sendMessage(H.PICTURE_IN_PICTURE_MODE_CHANGED, token, isInPipMode ? 1 : 0); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 1339 | } |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1340 | |
| 1341 | @Override |
| 1342 | public void scheduleLocalVoiceInteractionStarted(IBinder token, |
| 1343 | IVoiceInteractor voiceInteractor) throws RemoteException { |
| 1344 | SomeArgs args = SomeArgs.obtain(); |
| 1345 | args.arg1 = token; |
| 1346 | args.arg2 = voiceInteractor; |
| 1347 | sendMessage(H.LOCAL_VOICE_INTERACTION_STARTED, args); |
| 1348 | } |
Chad Brubaker | c72875b | 2016-04-27 16:35:11 -0700 | [diff] [blame] | 1349 | |
| 1350 | @Override |
| 1351 | public void handleTrustStorageUpdate() { |
| 1352 | NetworkSecurityPolicy.getInstance().handleTrustStorageUpdate(); |
| 1353 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1354 | } |
| 1355 | |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1356 | private int getLifecycleSeq() { |
| 1357 | synchronized (mResourcesManager) { |
| 1358 | return mLifecycleSeq++; |
| 1359 | } |
| 1360 | } |
| 1361 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1362 | private class H extends Handler { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1363 | public static final int LAUNCH_ACTIVITY = 100; |
| 1364 | public static final int PAUSE_ACTIVITY = 101; |
| 1365 | public static final int PAUSE_ACTIVITY_FINISHING= 102; |
| 1366 | public static final int STOP_ACTIVITY_SHOW = 103; |
| 1367 | public static final int STOP_ACTIVITY_HIDE = 104; |
| 1368 | public static final int SHOW_WINDOW = 105; |
| 1369 | public static final int HIDE_WINDOW = 106; |
| 1370 | public static final int RESUME_ACTIVITY = 107; |
| 1371 | public static final int SEND_RESULT = 108; |
Brian Carlstrom | ed7e007 | 2011-03-24 13:27:57 -0700 | [diff] [blame] | 1372 | public static final int DESTROY_ACTIVITY = 109; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1373 | public static final int BIND_APPLICATION = 110; |
| 1374 | public static final int EXIT_APPLICATION = 111; |
| 1375 | public static final int NEW_INTENT = 112; |
| 1376 | public static final int RECEIVER = 113; |
| 1377 | public static final int CREATE_SERVICE = 114; |
| 1378 | public static final int SERVICE_ARGS = 115; |
| 1379 | public static final int STOP_SERVICE = 116; |
Dianne Hackborn | 0923328 | 2014-04-30 11:33:59 -0700 | [diff] [blame] | 1380 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1381 | public static final int CONFIGURATION_CHANGED = 118; |
| 1382 | public static final int CLEAN_UP_CONTEXT = 119; |
| 1383 | public static final int GC_WHEN_IDLE = 120; |
| 1384 | public static final int BIND_SERVICE = 121; |
| 1385 | public static final int UNBIND_SERVICE = 122; |
| 1386 | public static final int DUMP_SERVICE = 123; |
| 1387 | public static final int LOW_MEMORY = 124; |
| 1388 | public static final int ACTIVITY_CONFIGURATION_CHANGED = 125; |
| 1389 | public static final int RELAUNCH_ACTIVITY = 126; |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 1390 | public static final int PROFILER_CONTROL = 127; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1391 | public static final int CREATE_BACKUP_AGENT = 128; |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 1392 | public static final int DESTROY_BACKUP_AGENT = 129; |
| 1393 | public static final int SUICIDE = 130; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1394 | public static final int REMOVE_PROVIDER = 131; |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 1395 | public static final int ENABLE_JIT = 132; |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1396 | public static final int DISPATCH_PACKAGE_BROADCAST = 133; |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 1397 | public static final int SCHEDULE_CRASH = 134; |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 1398 | public static final int DUMP_HEAP = 135; |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1399 | public static final int DUMP_ACTIVITY = 136; |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1400 | public static final int SLEEPING = 137; |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1401 | public static final int SET_CORE_SETTINGS = 138; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1402 | public static final int UPDATE_PACKAGE_COMPATIBILITY_INFO = 139; |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1403 | public static final int TRIM_MEMORY = 140; |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1404 | public static final int DUMP_PROVIDER = 141; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1405 | public static final int UNSTABLE_PROVIDER_DIED = 142; |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 1406 | public static final int REQUEST_ASSIST_CONTEXT_EXTRAS = 143; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1407 | public static final int TRANSLUCENT_CONVERSION_COMPLETE = 144; |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 1408 | public static final int INSTALL_PROVIDER = 145; |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1409 | public static final int ON_NEW_ACTIVITY_OPTIONS = 146; |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 1410 | public static final int CANCEL_VISIBLE_BEHIND = 147; |
| 1411 | public static final int BACKGROUND_VISIBLE_BEHIND_CHANGED = 148; |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 1412 | public static final int ENTER_ANIMATION_COMPLETE = 149; |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 1413 | public static final int START_BINDER_TRACKING = 150; |
| 1414 | public static final int STOP_BINDER_TRACKING_AND_DUMP = 151; |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 1415 | public static final int MULTI_WINDOW_MODE_CHANGED = 152; |
| 1416 | public static final int PICTURE_IN_PICTURE_MODE_CHANGED = 153; |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1417 | public static final int LOCAL_VOICE_INTERACTION_STARTED = 154; |
Narayan Kamath | ccb2a086 | 2013-12-19 14:49:36 +0000 | [diff] [blame] | 1418 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1419 | String codeToString(int code) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 1420 | if (DEBUG_MESSAGES) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1421 | switch (code) { |
| 1422 | case LAUNCH_ACTIVITY: return "LAUNCH_ACTIVITY"; |
| 1423 | case PAUSE_ACTIVITY: return "PAUSE_ACTIVITY"; |
| 1424 | case PAUSE_ACTIVITY_FINISHING: return "PAUSE_ACTIVITY_FINISHING"; |
| 1425 | case STOP_ACTIVITY_SHOW: return "STOP_ACTIVITY_SHOW"; |
| 1426 | case STOP_ACTIVITY_HIDE: return "STOP_ACTIVITY_HIDE"; |
| 1427 | case SHOW_WINDOW: return "SHOW_WINDOW"; |
| 1428 | case HIDE_WINDOW: return "HIDE_WINDOW"; |
| 1429 | case RESUME_ACTIVITY: return "RESUME_ACTIVITY"; |
| 1430 | case SEND_RESULT: return "SEND_RESULT"; |
| 1431 | case DESTROY_ACTIVITY: return "DESTROY_ACTIVITY"; |
| 1432 | case BIND_APPLICATION: return "BIND_APPLICATION"; |
| 1433 | case EXIT_APPLICATION: return "EXIT_APPLICATION"; |
| 1434 | case NEW_INTENT: return "NEW_INTENT"; |
| 1435 | case RECEIVER: return "RECEIVER"; |
| 1436 | case CREATE_SERVICE: return "CREATE_SERVICE"; |
| 1437 | case SERVICE_ARGS: return "SERVICE_ARGS"; |
| 1438 | case STOP_SERVICE: return "STOP_SERVICE"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1439 | case CONFIGURATION_CHANGED: return "CONFIGURATION_CHANGED"; |
| 1440 | case CLEAN_UP_CONTEXT: return "CLEAN_UP_CONTEXT"; |
| 1441 | case GC_WHEN_IDLE: return "GC_WHEN_IDLE"; |
| 1442 | case BIND_SERVICE: return "BIND_SERVICE"; |
| 1443 | case UNBIND_SERVICE: return "UNBIND_SERVICE"; |
| 1444 | case DUMP_SERVICE: return "DUMP_SERVICE"; |
| 1445 | case LOW_MEMORY: return "LOW_MEMORY"; |
| 1446 | case ACTIVITY_CONFIGURATION_CHANGED: return "ACTIVITY_CONFIGURATION_CHANGED"; |
| 1447 | case RELAUNCH_ACTIVITY: return "RELAUNCH_ACTIVITY"; |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 1448 | case PROFILER_CONTROL: return "PROFILER_CONTROL"; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1449 | case CREATE_BACKUP_AGENT: return "CREATE_BACKUP_AGENT"; |
| 1450 | case DESTROY_BACKUP_AGENT: return "DESTROY_BACKUP_AGENT"; |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 1451 | case SUICIDE: return "SUICIDE"; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1452 | case REMOVE_PROVIDER: return "REMOVE_PROVIDER"; |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 1453 | case ENABLE_JIT: return "ENABLE_JIT"; |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1454 | case DISPATCH_PACKAGE_BROADCAST: return "DISPATCH_PACKAGE_BROADCAST"; |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 1455 | case SCHEDULE_CRASH: return "SCHEDULE_CRASH"; |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 1456 | case DUMP_HEAP: return "DUMP_HEAP"; |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1457 | case DUMP_ACTIVITY: return "DUMP_ACTIVITY"; |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1458 | case SLEEPING: return "SLEEPING"; |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1459 | case SET_CORE_SETTINGS: return "SET_CORE_SETTINGS"; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1460 | case UPDATE_PACKAGE_COMPATIBILITY_INFO: return "UPDATE_PACKAGE_COMPATIBILITY_INFO"; |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1461 | case TRIM_MEMORY: return "TRIM_MEMORY"; |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1462 | case DUMP_PROVIDER: return "DUMP_PROVIDER"; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1463 | case UNSTABLE_PROVIDER_DIED: return "UNSTABLE_PROVIDER_DIED"; |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 1464 | case REQUEST_ASSIST_CONTEXT_EXTRAS: return "REQUEST_ASSIST_CONTEXT_EXTRAS"; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1465 | case TRANSLUCENT_CONVERSION_COMPLETE: return "TRANSLUCENT_CONVERSION_COMPLETE"; |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 1466 | case INSTALL_PROVIDER: return "INSTALL_PROVIDER"; |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1467 | case ON_NEW_ACTIVITY_OPTIONS: return "ON_NEW_ACTIVITY_OPTIONS"; |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 1468 | case CANCEL_VISIBLE_BEHIND: return "CANCEL_VISIBLE_BEHIND"; |
| 1469 | case BACKGROUND_VISIBLE_BEHIND_CHANGED: return "BACKGROUND_VISIBLE_BEHIND_CHANGED"; |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 1470 | case ENTER_ANIMATION_COMPLETE: return "ENTER_ANIMATION_COMPLETE"; |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 1471 | case MULTI_WINDOW_MODE_CHANGED: return "MULTI_WINDOW_MODE_CHANGED"; |
| 1472 | case PICTURE_IN_PICTURE_MODE_CHANGED: return "PICTURE_IN_PICTURE_MODE_CHANGED"; |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1473 | case LOCAL_VOICE_INTERACTION_STARTED: return "LOCAL_VOICE_INTERACTION_STARTED"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1474 | } |
| 1475 | } |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 1476 | return Integer.toString(code); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1477 | } |
| 1478 | public void handleMessage(Message msg) { |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 1479 | 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] | 1480 | switch (msg.what) { |
| 1481 | case LAUNCH_ACTIVITY: { |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1482 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityStart"); |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 1483 | final ActivityClientRecord r = (ActivityClientRecord) msg.obj; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1484 | |
| 1485 | r.packageInfo = getPackageInfoNoCheck( |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1486 | r.activityInfo.applicationInfo, r.compatInfo); |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 1487 | handleLaunchActivity(r, null, "LAUNCH_ACTIVITY"); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1488 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1489 | } break; |
| 1490 | case RELAUNCH_ACTIVITY: { |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1491 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityRestart"); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1492 | ActivityClientRecord r = (ActivityClientRecord)msg.obj; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 1493 | handleRelaunchActivity(r); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1494 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1495 | } break; |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1496 | case PAUSE_ACTIVITY: { |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1497 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityPause"); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1498 | SomeArgs args = (SomeArgs) msg.obj; |
| 1499 | handlePauseActivity((IBinder) args.arg1, false, |
| 1500 | (args.argi1 & USER_LEAVING) != 0, args.argi2, |
| 1501 | (args.argi1 & DONT_REPORT) != 0, args.argi3); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1502 | maybeSnapshot(); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1503 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1504 | } break; |
| 1505 | case PAUSE_ACTIVITY_FINISHING: { |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1506 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityPause"); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1507 | SomeArgs args = (SomeArgs) msg.obj; |
| 1508 | handlePauseActivity((IBinder) args.arg1, true, (args.argi1 & USER_LEAVING) != 0, |
| 1509 | args.argi2, (args.argi1 & DONT_REPORT) != 0, args.argi3); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1510 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1511 | } break; |
| 1512 | case STOP_ACTIVITY_SHOW: { |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1513 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityStop"); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1514 | SomeArgs args = (SomeArgs) msg.obj; |
| 1515 | handleStopActivity((IBinder) args.arg1, true, args.argi2, args.argi3); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1516 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1517 | } break; |
| 1518 | case STOP_ACTIVITY_HIDE: { |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1519 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityStop"); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1520 | SomeArgs args = (SomeArgs) msg.obj; |
| 1521 | handleStopActivity((IBinder) args.arg1, false, args.argi2, args.argi3); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1522 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1523 | } break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1524 | case SHOW_WINDOW: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1525 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityShowWindow"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1526 | handleWindowVisibility((IBinder)msg.obj, true); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1527 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1528 | break; |
| 1529 | case HIDE_WINDOW: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1530 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityHideWindow"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1531 | handleWindowVisibility((IBinder)msg.obj, false); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1532 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1533 | break; |
| 1534 | case RESUME_ACTIVITY: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1535 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityResume"); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1536 | SomeArgs args = (SomeArgs) msg.obj; |
| 1537 | handleResumeActivity((IBinder) args.arg1, true, args.argi1 != 0, true, |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 1538 | args.argi3, "RESUME_ACTIVITY"); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1539 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1540 | break; |
| 1541 | case SEND_RESULT: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1542 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityDeliverResult"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1543 | handleSendResult((ResultData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1544 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1545 | break; |
| 1546 | case DESTROY_ACTIVITY: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1547 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityDestroy"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1548 | handleDestroyActivity((IBinder)msg.obj, msg.arg1 != 0, |
| 1549 | msg.arg2, false); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1550 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1551 | break; |
| 1552 | case BIND_APPLICATION: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1553 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "bindApplication"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1554 | AppBindData data = (AppBindData)msg.obj; |
| 1555 | handleBindApplication(data); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1556 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1557 | break; |
| 1558 | case EXIT_APPLICATION: |
| 1559 | if (mInitialApplication != null) { |
| 1560 | mInitialApplication.onTerminate(); |
| 1561 | } |
| 1562 | Looper.myLooper().quit(); |
| 1563 | break; |
| 1564 | case NEW_INTENT: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1565 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityNewIntent"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1566 | handleNewIntent((NewIntentData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1567 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1568 | break; |
| 1569 | case RECEIVER: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1570 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "broadcastReceiveComp"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1571 | handleReceiver((ReceiverData)msg.obj); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1572 | maybeSnapshot(); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1573 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1574 | break; |
| 1575 | case CREATE_SERVICE: |
Tim Murray | b6f5a42 | 2016-04-07 15:25:22 -0700 | [diff] [blame] | 1576 | 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] | 1577 | handleCreateService((CreateServiceData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1578 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1579 | break; |
| 1580 | case BIND_SERVICE: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1581 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "serviceBind"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1582 | handleBindService((BindServiceData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1583 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1584 | break; |
| 1585 | case UNBIND_SERVICE: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1586 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "serviceUnbind"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1587 | handleUnbindService((BindServiceData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1588 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1589 | break; |
| 1590 | case SERVICE_ARGS: |
Tim Murray | b6f5a42 | 2016-04-07 15:25:22 -0700 | [diff] [blame] | 1591 | 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] | 1592 | handleServiceArgs((ServiceArgsData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1593 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1594 | break; |
| 1595 | case STOP_SERVICE: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1596 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "serviceStop"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1597 | handleStopService((IBinder)msg.obj); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1598 | maybeSnapshot(); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1599 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1600 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1601 | case CONFIGURATION_CHANGED: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1602 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "configChanged"); |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 1603 | mCurDefaultDisplayDpi = ((Configuration)msg.obj).densityDpi; |
Chong Zhang | 4951f9d | 2016-06-23 13:15:08 -0700 | [diff] [blame] | 1604 | mUpdatingSystemConfig = true; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1605 | handleConfigurationChanged((Configuration)msg.obj, null); |
Chong Zhang | 4951f9d | 2016-06-23 13:15:08 -0700 | [diff] [blame] | 1606 | mUpdatingSystemConfig = false; |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1607 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1608 | break; |
| 1609 | case CLEAN_UP_CONTEXT: |
| 1610 | ContextCleanupInfo cci = (ContextCleanupInfo)msg.obj; |
| 1611 | cci.context.performFinalCleanup(cci.who, cci.what); |
| 1612 | break; |
| 1613 | case GC_WHEN_IDLE: |
| 1614 | scheduleGcIdler(); |
| 1615 | break; |
| 1616 | case DUMP_SERVICE: |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1617 | handleDumpService((DumpComponentInfo)msg.obj); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1618 | break; |
| 1619 | case LOW_MEMORY: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1620 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "lowMemory"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1621 | handleLowMemory(); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1622 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1623 | break; |
| 1624 | case ACTIVITY_CONFIGURATION_CHANGED: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1625 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityConfigChanged"); |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 1626 | handleActivityConfigurationChanged((ActivityConfigChangeData) msg.obj, |
| 1627 | msg.arg1 == 1 ? REPORT_TO_ACTIVITY : !REPORT_TO_ACTIVITY); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1628 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1629 | break; |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 1630 | case PROFILER_CONTROL: |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 1631 | handleProfilerControl(msg.arg1 != 0, (ProfilerInfo)msg.obj, msg.arg2); |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 1632 | break; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1633 | case CREATE_BACKUP_AGENT: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1634 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "backupCreateAgent"); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1635 | handleCreateBackupAgent((CreateBackupAgentData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1636 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1637 | break; |
| 1638 | case DESTROY_BACKUP_AGENT: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1639 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "backupDestroyAgent"); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1640 | handleDestroyBackupAgent((CreateBackupAgentData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1641 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1642 | break; |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 1643 | case SUICIDE: |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1644 | Process.killProcess(Process.myPid()); |
| 1645 | break; |
| 1646 | case REMOVE_PROVIDER: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1647 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "providerRemove"); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1648 | completeRemoveProvider((ProviderRefCount)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1649 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 1650 | break; |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 1651 | case ENABLE_JIT: |
| 1652 | ensureJitEnabled(); |
| 1653 | break; |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1654 | case DISPATCH_PACKAGE_BROADCAST: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1655 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "broadcastPackage"); |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1656 | handleDispatchPackageBroadcast(msg.arg1, (String[])msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1657 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1658 | break; |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 1659 | case SCHEDULE_CRASH: |
| 1660 | throw new RemoteServiceException((String)msg.obj); |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 1661 | case DUMP_HEAP: |
| 1662 | handleDumpHeap(msg.arg1 != 0, (DumpHeapData)msg.obj); |
| 1663 | break; |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1664 | case DUMP_ACTIVITY: |
| 1665 | handleDumpActivity((DumpComponentInfo)msg.obj); |
| 1666 | break; |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1667 | case DUMP_PROVIDER: |
| 1668 | handleDumpProvider((DumpComponentInfo)msg.obj); |
| 1669 | break; |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1670 | case SLEEPING: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1671 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "sleeping"); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1672 | handleSleeping((IBinder)msg.obj, msg.arg1 != 0); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1673 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1674 | break; |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1675 | case SET_CORE_SETTINGS: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1676 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "setCoreSettings"); |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1677 | handleSetCoreSettings((Bundle) msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1678 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1679 | break; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1680 | case UPDATE_PACKAGE_COMPATIBILITY_INFO: |
| 1681 | handleUpdatePackageCompatibilityInfo((UpdateCompatibilityData)msg.obj); |
Dianne Hackborn | f0754f5b | 2011-07-21 16:02:07 -0700 | [diff] [blame] | 1682 | break; |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1683 | case TRIM_MEMORY: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1684 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "trimMemory"); |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1685 | handleTrimMemory(msg.arg1); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1686 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Dianne Hackborn | f0754f5b | 2011-07-21 16:02:07 -0700 | [diff] [blame] | 1687 | break; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1688 | case UNSTABLE_PROVIDER_DIED: |
| 1689 | handleUnstableProviderDied((IBinder)msg.obj, false); |
| 1690 | break; |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 1691 | case REQUEST_ASSIST_CONTEXT_EXTRAS: |
| 1692 | handleRequestAssistContextExtras((RequestAssistContextExtras)msg.obj); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 1693 | break; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1694 | case TRANSLUCENT_CONVERSION_COMPLETE: |
| 1695 | handleTranslucentConversionComplete((IBinder)msg.obj, msg.arg1 == 1); |
| 1696 | break; |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 1697 | case INSTALL_PROVIDER: |
| 1698 | handleInstallProvider((ProviderInfo) msg.obj); |
| 1699 | break; |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1700 | case ON_NEW_ACTIVITY_OPTIONS: |
| 1701 | Pair<IBinder, ActivityOptions> pair = (Pair<IBinder, ActivityOptions>) msg.obj; |
| 1702 | onNewActivityOptions(pair.first, pair.second); |
Dake Gu | 7ef70b0 | 2014-07-08 18:37:12 -0700 | [diff] [blame] | 1703 | break; |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 1704 | case CANCEL_VISIBLE_BEHIND: |
| 1705 | handleCancelVisibleBehind((IBinder) msg.obj); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 1706 | break; |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 1707 | case BACKGROUND_VISIBLE_BEHIND_CHANGED: |
| 1708 | handleOnBackgroundVisibleBehindChanged((IBinder) msg.obj, msg.arg1 > 0); |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1709 | break; |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 1710 | case ENTER_ANIMATION_COMPLETE: |
| 1711 | handleEnterAnimationComplete((IBinder) msg.obj); |
| 1712 | break; |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 1713 | case START_BINDER_TRACKING: |
| 1714 | handleStartBinderTracking(); |
| 1715 | break; |
| 1716 | case STOP_BINDER_TRACKING_AND_DUMP: |
| 1717 | handleStopBinderTrackingAndDump((ParcelFileDescriptor) msg.obj); |
| 1718 | break; |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 1719 | case MULTI_WINDOW_MODE_CHANGED: |
| 1720 | handleMultiWindowModeChanged((IBinder) msg.obj, msg.arg1 == 1); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 1721 | break; |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 1722 | case PICTURE_IN_PICTURE_MODE_CHANGED: |
| 1723 | handlePictureInPictureModeChanged((IBinder) msg.obj, msg.arg1 == 1); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 1724 | break; |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1725 | case LOCAL_VOICE_INTERACTION_STARTED: |
| 1726 | handleLocalVoiceInteractionStarted((IBinder) ((SomeArgs) msg.obj).arg1, |
| 1727 | (IVoiceInteractor) ((SomeArgs) msg.obj).arg2); |
| 1728 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1729 | } |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1730 | Object obj = msg.obj; |
| 1731 | if (obj instanceof SomeArgs) { |
| 1732 | ((SomeArgs) obj).recycle(); |
| 1733 | } |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 1734 | 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] | 1735 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1736 | |
Brian Carlstrom | ed7e007 | 2011-03-24 13:27:57 -0700 | [diff] [blame] | 1737 | private void maybeSnapshot() { |
| 1738 | if (mBoundApplication != null && SamplingProfilerIntegration.isEnabled()) { |
Sen Hu | bde7570 | 2010-05-28 01:54:03 -0700 | [diff] [blame] | 1739 | // convert the *private* ActivityThread.PackageInfo to *public* known |
| 1740 | // android.content.pm.PackageInfo |
| 1741 | String packageName = mBoundApplication.info.mPackageName; |
| 1742 | android.content.pm.PackageInfo packageInfo = null; |
| 1743 | try { |
| 1744 | Context context = getSystemContext(); |
| 1745 | if(context == null) { |
| 1746 | Log.e(TAG, "cannot get a valid context"); |
| 1747 | return; |
| 1748 | } |
| 1749 | PackageManager pm = context.getPackageManager(); |
| 1750 | if(pm == null) { |
| 1751 | Log.e(TAG, "cannot get a valid PackageManager"); |
| 1752 | return; |
| 1753 | } |
| 1754 | packageInfo = pm.getPackageInfo( |
| 1755 | packageName, PackageManager.GET_ACTIVITIES); |
| 1756 | } catch (NameNotFoundException e) { |
| 1757 | Log.e(TAG, "cannot get package info for " + packageName, e); |
| 1758 | } |
| 1759 | SamplingProfilerIntegration.writeSnapshot(mBoundApplication.processName, packageInfo); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1760 | } |
| 1761 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1762 | } |
| 1763 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1764 | private class Idler implements MessageQueue.IdleHandler { |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 1765 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1766 | public final boolean queueIdle() { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1767 | ActivityClientRecord a = mNewActivities; |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 1768 | boolean stopProfiling = false; |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 1769 | if (mBoundApplication != null && mProfiler.profileFd != null |
| 1770 | && mProfiler.autoStopProfiler) { |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 1771 | stopProfiling = true; |
| 1772 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1773 | if (a != null) { |
| 1774 | mNewActivities = null; |
| 1775 | IActivityManager am = ActivityManagerNative.getDefault(); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1776 | ActivityClientRecord prev; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1777 | do { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 1778 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1779 | TAG, "Reporting idle of " + a + |
| 1780 | " finished=" + |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1781 | (a.activity != null && a.activity.mFinished)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1782 | if (a.activity != null && !a.activity.mFinished) { |
| 1783 | try { |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 1784 | am.activityIdle(a.token, a.createdConfig, stopProfiling); |
Dianne Hackborn | e88846e | 2009-09-30 21:34:25 -0700 | [diff] [blame] | 1785 | a.createdConfig = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1786 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1787 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1788 | } |
| 1789 | } |
| 1790 | prev = a; |
| 1791 | a = a.nextIdle; |
| 1792 | prev.nextIdle = null; |
| 1793 | } while (a != null); |
| 1794 | } |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 1795 | if (stopProfiling) { |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 1796 | mProfiler.stopProfiling(); |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 1797 | } |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 1798 | ensureJitEnabled(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1799 | return false; |
| 1800 | } |
| 1801 | } |
| 1802 | |
| 1803 | final class GcIdler implements MessageQueue.IdleHandler { |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 1804 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1805 | public final boolean queueIdle() { |
| 1806 | doGcIfNeeded(); |
| 1807 | return false; |
| 1808 | } |
| 1809 | } |
| 1810 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1811 | public static ActivityThread currentActivityThread() { |
Jeff Sharkey | 66a017b | 2013-01-17 18:18:22 -0800 | [diff] [blame] | 1812 | return sCurrentActivityThread; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1813 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1814 | |
Wale Ogunwale | 9a6ef1e | 2015-06-02 13:41:00 -0700 | [diff] [blame] | 1815 | public static boolean isSystem() { |
| 1816 | return (sCurrentActivityThread != null) ? sCurrentActivityThread.mSystemThread : false; |
| 1817 | } |
| 1818 | |
Svetoslav | fbf0eca | 2015-05-01 16:52:41 -0700 | [diff] [blame] | 1819 | public static String currentOpPackageName() { |
| 1820 | ActivityThread am = currentActivityThread(); |
| 1821 | return (am != null && am.getApplication() != null) |
| 1822 | ? am.getApplication().getOpPackageName() : null; |
| 1823 | } |
| 1824 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1825 | public static String currentPackageName() { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1826 | ActivityThread am = currentActivityThread(); |
| 1827 | return (am != null && am.mBoundApplication != null) |
Dianne Hackborn | b57a50b | 2013-04-11 17:29:32 -0700 | [diff] [blame] | 1828 | ? am.mBoundApplication.appInfo.packageName : null; |
| 1829 | } |
| 1830 | |
| 1831 | public static String currentProcessName() { |
| 1832 | ActivityThread am = currentActivityThread(); |
| 1833 | return (am != null && am.mBoundApplication != null) |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1834 | ? am.mBoundApplication.processName : null; |
| 1835 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1836 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1837 | public static Application currentApplication() { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1838 | ActivityThread am = currentActivityThread(); |
| 1839 | return am != null ? am.mInitialApplication : null; |
| 1840 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1841 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1842 | public static IPackageManager getPackageManager() { |
| 1843 | if (sPackageManager != null) { |
| 1844 | //Slog.v("PackageManager", "returning cur default = " + sPackageManager); |
| 1845 | return sPackageManager; |
| 1846 | } |
| 1847 | IBinder b = ServiceManager.getService("package"); |
| 1848 | //Slog.v("PackageManager", "default service binder = " + b); |
| 1849 | sPackageManager = IPackageManager.Stub.asInterface(b); |
| 1850 | //Slog.v("PackageManager", "default service = " + sPackageManager); |
| 1851 | return sPackageManager; |
| 1852 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1853 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1854 | private Configuration mMainThreadConfig = new Configuration(); |
Amith Yamasani | 4f128e4 | 2016-05-10 11:44:12 -0700 | [diff] [blame] | 1855 | |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 1856 | Configuration applyConfigCompatMainThread(int displayDensity, Configuration config, |
| 1857 | CompatibilityInfo compat) { |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1858 | if (config == null) { |
| 1859 | return null; |
| 1860 | } |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 1861 | if (!compat.supportsScreen()) { |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1862 | mMainThreadConfig.setTo(config); |
| 1863 | config = mMainThreadConfig; |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 1864 | compat.applyToConfiguration(displayDensity, config); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1865 | } |
| 1866 | return config; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1867 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1868 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1869 | /** |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 1870 | * Creates the top level resources for the given package. Will return an existing |
| 1871 | * Resources if one has already been created. |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1872 | */ |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 1873 | Resources getTopLevelResources(String resDir, String[] splitResDirs, String[] overlayDirs, |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 1874 | String[] libDirs, int displayId, LoadedApk pkgInfo) { |
| 1875 | return mResourcesManager.getResources(null, resDir, splitResDirs, overlayDirs, libDirs, |
| 1876 | displayId, null, pkgInfo.getCompatibilityInfo(), pkgInfo.getClassLoader()); |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 1877 | } |
| 1878 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1879 | final Handler getHandler() { |
| 1880 | return mH; |
| 1881 | } |
| 1882 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1883 | public final LoadedApk getPackageInfo(String packageName, CompatibilityInfo compatInfo, |
| 1884 | int flags) { |
Amith Yamasani | 98edc95 | 2012-09-25 14:09:27 -0700 | [diff] [blame] | 1885 | return getPackageInfo(packageName, compatInfo, flags, UserHandle.myUserId()); |
| 1886 | } |
| 1887 | |
| 1888 | public final LoadedApk getPackageInfo(String packageName, CompatibilityInfo compatInfo, |
| 1889 | int flags, int userId) { |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 1890 | final boolean differentUser = (UserHandle.myUserId() != userId); |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 1891 | synchronized (mResourcesManager) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1892 | WeakReference<LoadedApk> ref; |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 1893 | if (differentUser) { |
| 1894 | // Caching not supported across users |
| 1895 | ref = null; |
| 1896 | } else if ((flags & Context.CONTEXT_INCLUDE_CODE) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1897 | ref = mPackages.get(packageName); |
| 1898 | } else { |
| 1899 | ref = mResourcePackages.get(packageName); |
| 1900 | } |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 1901 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1902 | LoadedApk packageInfo = ref != null ? ref.get() : null; |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 1903 | //Slog.i(TAG, "getPackageInfo " + packageName + ": " + packageInfo); |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1904 | //if (packageInfo != null) Slog.i(TAG, "isUptoDate " + packageInfo.mResDir |
| 1905 | // + ": " + packageInfo.mResources.getAssets().isUpToDate()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1906 | if (packageInfo != null && (packageInfo.mResources == null |
| 1907 | || packageInfo.mResources.getAssets().isUpToDate())) { |
| 1908 | if (packageInfo.isSecurityViolation() |
| 1909 | && (flags&Context.CONTEXT_IGNORE_SECURITY) == 0) { |
| 1910 | throw new SecurityException( |
| 1911 | "Requesting code from " + packageName |
| 1912 | + " to be run in process " |
| 1913 | + mBoundApplication.processName |
| 1914 | + "/" + mBoundApplication.appInfo.uid); |
| 1915 | } |
| 1916 | return packageInfo; |
| 1917 | } |
| 1918 | } |
| 1919 | |
| 1920 | ApplicationInfo ai = null; |
| 1921 | try { |
| 1922 | ai = getPackageManager().getApplicationInfo(packageName, |
Jeff Sharkey | c5967e9 | 2016-01-07 18:50:29 -0700 | [diff] [blame] | 1923 | PackageManager.GET_SHARED_LIBRARY_FILES |
| 1924 | | PackageManager.MATCH_DEBUG_TRIAGED_MISSING, |
| 1925 | userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1926 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1927 | throw e.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1928 | } |
| 1929 | |
| 1930 | if (ai != null) { |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1931 | return getPackageInfo(ai, compatInfo, flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1932 | } |
| 1933 | |
| 1934 | return null; |
| 1935 | } |
| 1936 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1937 | public final LoadedApk getPackageInfo(ApplicationInfo ai, CompatibilityInfo compatInfo, |
| 1938 | int flags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1939 | boolean includeCode = (flags&Context.CONTEXT_INCLUDE_CODE) != 0; |
| 1940 | boolean securityViolation = includeCode && ai.uid != 0 |
| 1941 | && ai.uid != Process.SYSTEM_UID && (mBoundApplication != null |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 1942 | ? !UserHandle.isSameApp(ai.uid, mBoundApplication.appInfo.uid) |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 1943 | : true); |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 1944 | boolean registerPackage = includeCode && (flags&Context.CONTEXT_REGISTER_PACKAGE) != 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1945 | if ((flags&(Context.CONTEXT_INCLUDE_CODE |
| 1946 | |Context.CONTEXT_IGNORE_SECURITY)) |
| 1947 | == Context.CONTEXT_INCLUDE_CODE) { |
| 1948 | if (securityViolation) { |
| 1949 | String msg = "Requesting code from " + ai.packageName |
| 1950 | + " (with uid " + ai.uid + ")"; |
| 1951 | if (mBoundApplication != null) { |
| 1952 | msg = msg + " to be run in process " |
| 1953 | + mBoundApplication.processName + " (with uid " |
| 1954 | + mBoundApplication.appInfo.uid + ")"; |
| 1955 | } |
| 1956 | throw new SecurityException(msg); |
| 1957 | } |
| 1958 | } |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 1959 | return getPackageInfo(ai, compatInfo, null, securityViolation, includeCode, |
| 1960 | registerPackage); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1961 | } |
| 1962 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1963 | public final LoadedApk getPackageInfoNoCheck(ApplicationInfo ai, |
| 1964 | CompatibilityInfo compatInfo) { |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 1965 | return getPackageInfo(ai, compatInfo, null, false, true, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1966 | } |
| 1967 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1968 | public final LoadedApk peekPackageInfo(String packageName, boolean includeCode) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 1969 | synchronized (mResourcesManager) { |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1970 | WeakReference<LoadedApk> ref; |
| 1971 | if (includeCode) { |
| 1972 | ref = mPackages.get(packageName); |
| 1973 | } else { |
| 1974 | ref = mResourcePackages.get(packageName); |
| 1975 | } |
| 1976 | return ref != null ? ref.get() : null; |
| 1977 | } |
| 1978 | } |
| 1979 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1980 | private LoadedApk getPackageInfo(ApplicationInfo aInfo, CompatibilityInfo compatInfo, |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 1981 | ClassLoader baseLoader, boolean securityViolation, boolean includeCode, |
| 1982 | boolean registerPackage) { |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 1983 | final boolean differentUser = (UserHandle.myUserId() != UserHandle.getUserId(aInfo.uid)); |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 1984 | synchronized (mResourcesManager) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1985 | WeakReference<LoadedApk> ref; |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 1986 | if (differentUser) { |
| 1987 | // Caching not supported across users |
| 1988 | ref = null; |
| 1989 | } else if (includeCode) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1990 | ref = mPackages.get(aInfo.packageName); |
| 1991 | } else { |
| 1992 | ref = mResourcePackages.get(aInfo.packageName); |
| 1993 | } |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 1994 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1995 | LoadedApk packageInfo = ref != null ? ref.get() : null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1996 | if (packageInfo == null || (packageInfo.mResources != null |
| 1997 | && !packageInfo.mResources.getAssets().isUpToDate())) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 1998 | if (localLOGV) Slog.v(TAG, (includeCode ? "Loading code package " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1999 | : "Loading resource-only package ") + aInfo.packageName |
| 2000 | + " (in " + (mBoundApplication != null |
| 2001 | ? mBoundApplication.processName : null) |
| 2002 | + ")"); |
| 2003 | packageInfo = |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 2004 | new LoadedApk(this, aInfo, compatInfo, baseLoader, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2005 | securityViolation, includeCode && |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 2006 | (aInfo.flags&ApplicationInfo.FLAG_HAS_CODE) != 0, registerPackage); |
Narayan Kamath | cb38318 | 2014-10-29 17:56:42 +0000 | [diff] [blame] | 2007 | |
| 2008 | if (mSystemThread && "android".equals(aInfo.packageName)) { |
| 2009 | packageInfo.installSystemApplicationInfo(aInfo, |
| 2010 | getSystemContext().mPackageInfo.getClassLoader()); |
| 2011 | } |
| 2012 | |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 2013 | if (differentUser) { |
| 2014 | // Caching not supported across users |
| 2015 | } else if (includeCode) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2016 | mPackages.put(aInfo.packageName, |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2017 | new WeakReference<LoadedApk>(packageInfo)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2018 | } else { |
| 2019 | mResourcePackages.put(aInfo.packageName, |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2020 | new WeakReference<LoadedApk>(packageInfo)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2021 | } |
| 2022 | } |
| 2023 | return packageInfo; |
| 2024 | } |
| 2025 | } |
| 2026 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2027 | ActivityThread() { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 2028 | mResourcesManager = ResourcesManager.getInstance(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2029 | } |
| 2030 | |
| 2031 | public ApplicationThread getApplicationThread() |
| 2032 | { |
| 2033 | return mAppThread; |
| 2034 | } |
| 2035 | |
| 2036 | public Instrumentation getInstrumentation() |
| 2037 | { |
| 2038 | return mInstrumentation; |
| 2039 | } |
| 2040 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2041 | public boolean isProfiling() { |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 2042 | return mProfiler != null && mProfiler.profileFile != null |
| 2043 | && mProfiler.profileFd == null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2044 | } |
| 2045 | |
| 2046 | public String getProfileFilePath() { |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 2047 | return mProfiler.profileFile; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2048 | } |
| 2049 | |
| 2050 | public Looper getLooper() { |
| 2051 | return mLooper; |
| 2052 | } |
| 2053 | |
| 2054 | public Application getApplication() { |
| 2055 | return mInitialApplication; |
| 2056 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2057 | |
Dianne Hackborn | d97c7ad | 2009-06-19 11:37:35 -0700 | [diff] [blame] | 2058 | public String getProcessName() { |
| 2059 | return mBoundApplication.processName; |
| 2060 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2061 | |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 2062 | public ContextImpl getSystemContext() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2063 | synchronized (this) { |
| 2064 | if (mSystemContext == null) { |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 2065 | mSystemContext = ContextImpl.createSystemContext(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2066 | } |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 2067 | return mSystemContext; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2068 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2069 | } |
| 2070 | |
Narayan Kamath | 29564cd | 2014-08-07 10:57:40 +0100 | [diff] [blame] | 2071 | public void installSystemApplicationInfo(ApplicationInfo info, ClassLoader classLoader) { |
Mike Cleron | 432b713 | 2009-09-24 15:28:29 -0700 | [diff] [blame] | 2072 | synchronized (this) { |
Narayan Kamath | 29564cd | 2014-08-07 10:57:40 +0100 | [diff] [blame] | 2073 | getSystemContext().installSystemApplicationInfo(info, classLoader); |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 2074 | |
| 2075 | // give ourselves a default profiler |
| 2076 | mProfiler = new Profiler(); |
Mike Cleron | 432b713 | 2009-09-24 15:28:29 -0700 | [diff] [blame] | 2077 | } |
| 2078 | } |
| 2079 | |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 2080 | void ensureJitEnabled() { |
| 2081 | if (!mJitEnabled) { |
| 2082 | mJitEnabled = true; |
| 2083 | dalvik.system.VMRuntime.getRuntime().startJitCompilation(); |
| 2084 | } |
| 2085 | } |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 2086 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2087 | void scheduleGcIdler() { |
| 2088 | if (!mGcIdlerScheduled) { |
| 2089 | mGcIdlerScheduled = true; |
| 2090 | Looper.myQueue().addIdleHandler(mGcIdler); |
| 2091 | } |
| 2092 | mH.removeMessages(H.GC_WHEN_IDLE); |
| 2093 | } |
| 2094 | |
| 2095 | void unscheduleGcIdler() { |
| 2096 | if (mGcIdlerScheduled) { |
| 2097 | mGcIdlerScheduled = false; |
| 2098 | Looper.myQueue().removeIdleHandler(mGcIdler); |
| 2099 | } |
| 2100 | mH.removeMessages(H.GC_WHEN_IDLE); |
| 2101 | } |
| 2102 | |
| 2103 | void doGcIfNeeded() { |
| 2104 | mGcIdlerScheduled = false; |
| 2105 | final long now = SystemClock.uptimeMillis(); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2106 | //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] | 2107 | // + "m now=" + now); |
| 2108 | if ((BinderInternal.getLastGcTime()+MIN_TIME_BETWEEN_GCS) < now) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2109 | //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] | 2110 | BinderInternal.forceGc("bg"); |
| 2111 | } |
| 2112 | } |
| 2113 | |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2114 | private static final String HEAP_FULL_COLUMN |
| 2115 | = "%13s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s"; |
| 2116 | private static final String HEAP_COLUMN |
| 2117 | = "%13s %8s %8s %8s %8s %8s %8s %8s"; |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2118 | private static final String ONE_COUNT_COLUMN = "%21s %8d"; |
| 2119 | private static final String TWO_COUNT_COLUMNS = "%21s %8d %21s %8d"; |
| 2120 | private static final String ONE_COUNT_COLUMN_HEADER = "%21s %8s"; |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2121 | |
| 2122 | // Formatting for checkin service - update version if row format changes |
Martijn Coenen | 41f94ed | 2015-12-14 15:28:51 +0100 | [diff] [blame] | 2123 | private static final int ACTIVITY_THREAD_CHECKIN_VERSION = 4; |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2124 | |
| 2125 | static void printRow(PrintWriter pw, String format, Object...objs) { |
| 2126 | pw.println(String.format(format, objs)); |
| 2127 | } |
| 2128 | |
| 2129 | public static void dumpMemInfoTable(PrintWriter pw, Debug.MemoryInfo memInfo, boolean checkin, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2130 | boolean dumpFullInfo, boolean dumpDalvik, boolean dumpSummaryOnly, |
| 2131 | int pid, String processName, |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2132 | long nativeMax, long nativeAllocated, long nativeFree, |
| 2133 | long dalvikMax, long dalvikAllocated, long dalvikFree) { |
| 2134 | |
| 2135 | // For checkin, we print one long comma-separated list of values |
| 2136 | if (checkin) { |
| 2137 | // NOTE: if you change anything significant below, also consider changing |
| 2138 | // ACTIVITY_THREAD_CHECKIN_VERSION. |
| 2139 | |
| 2140 | // Header |
| 2141 | pw.print(ACTIVITY_THREAD_CHECKIN_VERSION); pw.print(','); |
| 2142 | pw.print(pid); pw.print(','); |
| 2143 | pw.print(processName); pw.print(','); |
| 2144 | |
| 2145 | // Heap info - max |
| 2146 | pw.print(nativeMax); pw.print(','); |
| 2147 | pw.print(dalvikMax); pw.print(','); |
| 2148 | pw.print("N/A,"); |
| 2149 | pw.print(nativeMax + dalvikMax); pw.print(','); |
| 2150 | |
| 2151 | // Heap info - allocated |
| 2152 | pw.print(nativeAllocated); pw.print(','); |
| 2153 | pw.print(dalvikAllocated); pw.print(','); |
| 2154 | pw.print("N/A,"); |
| 2155 | pw.print(nativeAllocated + dalvikAllocated); pw.print(','); |
| 2156 | |
| 2157 | // Heap info - free |
| 2158 | pw.print(nativeFree); pw.print(','); |
| 2159 | pw.print(dalvikFree); pw.print(','); |
| 2160 | pw.print("N/A,"); |
| 2161 | pw.print(nativeFree + dalvikFree); pw.print(','); |
| 2162 | |
| 2163 | // Heap info - proportional set size |
| 2164 | pw.print(memInfo.nativePss); pw.print(','); |
| 2165 | pw.print(memInfo.dalvikPss); pw.print(','); |
| 2166 | pw.print(memInfo.otherPss); pw.print(','); |
| 2167 | pw.print(memInfo.getTotalPss()); pw.print(','); |
| 2168 | |
| 2169 | // Heap info - swappable set size |
| 2170 | pw.print(memInfo.nativeSwappablePss); pw.print(','); |
| 2171 | pw.print(memInfo.dalvikSwappablePss); pw.print(','); |
| 2172 | pw.print(memInfo.otherSwappablePss); pw.print(','); |
| 2173 | pw.print(memInfo.getTotalSwappablePss()); pw.print(','); |
| 2174 | |
| 2175 | // Heap info - shared dirty |
| 2176 | pw.print(memInfo.nativeSharedDirty); pw.print(','); |
| 2177 | pw.print(memInfo.dalvikSharedDirty); pw.print(','); |
| 2178 | pw.print(memInfo.otherSharedDirty); pw.print(','); |
| 2179 | pw.print(memInfo.getTotalSharedDirty()); pw.print(','); |
| 2180 | |
| 2181 | // Heap info - shared clean |
| 2182 | pw.print(memInfo.nativeSharedClean); pw.print(','); |
| 2183 | pw.print(memInfo.dalvikSharedClean); pw.print(','); |
| 2184 | pw.print(memInfo.otherSharedClean); pw.print(','); |
| 2185 | pw.print(memInfo.getTotalSharedClean()); pw.print(','); |
| 2186 | |
| 2187 | // Heap info - private Dirty |
| 2188 | pw.print(memInfo.nativePrivateDirty); pw.print(','); |
| 2189 | pw.print(memInfo.dalvikPrivateDirty); pw.print(','); |
| 2190 | pw.print(memInfo.otherPrivateDirty); pw.print(','); |
| 2191 | pw.print(memInfo.getTotalPrivateDirty()); pw.print(','); |
| 2192 | |
| 2193 | // Heap info - private Clean |
| 2194 | pw.print(memInfo.nativePrivateClean); pw.print(','); |
| 2195 | pw.print(memInfo.dalvikPrivateClean); pw.print(','); |
| 2196 | pw.print(memInfo.otherPrivateClean); pw.print(','); |
| 2197 | pw.print(memInfo.getTotalPrivateClean()); pw.print(','); |
| 2198 | |
Martijn Coenen | 41f94ed | 2015-12-14 15:28:51 +0100 | [diff] [blame] | 2199 | // Heap info - swapped out |
| 2200 | pw.print(memInfo.nativeSwappedOut); pw.print(','); |
| 2201 | pw.print(memInfo.dalvikSwappedOut); pw.print(','); |
| 2202 | pw.print(memInfo.otherSwappedOut); pw.print(','); |
| 2203 | pw.print(memInfo.getTotalSwappedOut()); pw.print(','); |
| 2204 | |
| 2205 | // Heap info - swapped out pss |
| 2206 | if (memInfo.hasSwappedOutPss) { |
| 2207 | pw.print(memInfo.nativeSwappedOutPss); pw.print(','); |
| 2208 | pw.print(memInfo.dalvikSwappedOutPss); pw.print(','); |
| 2209 | pw.print(memInfo.otherSwappedOutPss); pw.print(','); |
| 2210 | pw.print(memInfo.getTotalSwappedOutPss()); pw.print(','); |
| 2211 | } else { |
| 2212 | pw.print("N/A,"); |
| 2213 | pw.print("N/A,"); |
| 2214 | pw.print("N/A,"); |
| 2215 | pw.print("N/A,"); |
| 2216 | } |
| 2217 | |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2218 | // Heap info - other areas |
| 2219 | for (int i=0; i<Debug.MemoryInfo.NUM_OTHER_STATS; i++) { |
| 2220 | pw.print(Debug.MemoryInfo.getOtherLabel(i)); pw.print(','); |
| 2221 | pw.print(memInfo.getOtherPss(i)); pw.print(','); |
| 2222 | pw.print(memInfo.getOtherSwappablePss(i)); pw.print(','); |
| 2223 | pw.print(memInfo.getOtherSharedDirty(i)); pw.print(','); |
| 2224 | pw.print(memInfo.getOtherSharedClean(i)); pw.print(','); |
| 2225 | pw.print(memInfo.getOtherPrivateDirty(i)); pw.print(','); |
| 2226 | pw.print(memInfo.getOtherPrivateClean(i)); pw.print(','); |
Martijn Coenen | 41f94ed | 2015-12-14 15:28:51 +0100 | [diff] [blame] | 2227 | pw.print(memInfo.getOtherSwappedOut(i)); pw.print(','); |
| 2228 | if (memInfo.hasSwappedOutPss) { |
| 2229 | pw.print(memInfo.getOtherSwappedOutPss(i)); pw.print(','); |
| 2230 | } else { |
| 2231 | pw.print("N/A,"); |
| 2232 | } |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2233 | } |
| 2234 | return; |
| 2235 | } |
| 2236 | |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2237 | if (!dumpSummaryOnly) { |
| 2238 | if (dumpFullInfo) { |
| 2239 | printRow(pw, HEAP_FULL_COLUMN, "", "Pss", "Pss", "Shared", "Private", |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2240 | "Shared", "Private", memInfo.hasSwappedOutPss ? "SwapPss" : "Swap", |
| 2241 | "Heap", "Heap", "Heap"); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2242 | printRow(pw, HEAP_FULL_COLUMN, "", "Total", "Clean", "Dirty", "Dirty", |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2243 | "Clean", "Clean", "Dirty", |
| 2244 | "Size", "Alloc", "Free"); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2245 | printRow(pw, HEAP_FULL_COLUMN, "", "------", "------", "------", "------", |
| 2246 | "------", "------", "------", "------", "------", "------"); |
| 2247 | printRow(pw, HEAP_FULL_COLUMN, "Native Heap", memInfo.nativePss, |
| 2248 | memInfo.nativeSwappablePss, memInfo.nativeSharedDirty, |
| 2249 | memInfo.nativePrivateDirty, memInfo.nativeSharedClean, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2250 | memInfo.nativePrivateClean, memInfo.hasSwappedOutPss ? |
| 2251 | memInfo.nativeSwappedOut : memInfo.nativeSwappedOutPss, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2252 | nativeMax, nativeAllocated, nativeFree); |
| 2253 | printRow(pw, HEAP_FULL_COLUMN, "Dalvik Heap", memInfo.dalvikPss, |
| 2254 | memInfo.dalvikSwappablePss, memInfo.dalvikSharedDirty, |
| 2255 | memInfo.dalvikPrivateDirty, memInfo.dalvikSharedClean, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2256 | memInfo.dalvikPrivateClean, memInfo.hasSwappedOutPss ? |
| 2257 | memInfo.dalvikSwappedOut : memInfo.dalvikSwappedOutPss, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2258 | dalvikMax, dalvikAllocated, dalvikFree); |
| 2259 | } else { |
| 2260 | printRow(pw, HEAP_COLUMN, "", "Pss", "Private", |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2261 | "Private", memInfo.hasSwappedOutPss ? "SwapPss" : "Swap", |
| 2262 | "Heap", "Heap", "Heap"); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2263 | printRow(pw, HEAP_COLUMN, "", "Total", "Dirty", |
| 2264 | "Clean", "Dirty", "Size", "Alloc", "Free"); |
| 2265 | printRow(pw, HEAP_COLUMN, "", "------", "------", "------", |
| 2266 | "------", "------", "------", "------", "------"); |
| 2267 | printRow(pw, HEAP_COLUMN, "Native Heap", memInfo.nativePss, |
| 2268 | memInfo.nativePrivateDirty, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2269 | memInfo.nativePrivateClean, |
| 2270 | memInfo.hasSwappedOutPss ? memInfo.nativeSwappedOutPss : |
| 2271 | memInfo.nativeSwappedOut, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2272 | nativeMax, nativeAllocated, nativeFree); |
| 2273 | printRow(pw, HEAP_COLUMN, "Dalvik Heap", memInfo.dalvikPss, |
| 2274 | memInfo.dalvikPrivateDirty, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2275 | memInfo.dalvikPrivateClean, |
| 2276 | memInfo.hasSwappedOutPss ? memInfo.dalvikSwappedOutPss : |
| 2277 | memInfo.dalvikSwappedOut, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2278 | dalvikMax, dalvikAllocated, dalvikFree); |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2279 | } |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2280 | |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2281 | int otherPss = memInfo.otherPss; |
| 2282 | int otherSwappablePss = memInfo.otherSwappablePss; |
| 2283 | int otherSharedDirty = memInfo.otherSharedDirty; |
| 2284 | int otherPrivateDirty = memInfo.otherPrivateDirty; |
| 2285 | int otherSharedClean = memInfo.otherSharedClean; |
| 2286 | int otherPrivateClean = memInfo.otherPrivateClean; |
| 2287 | int otherSwappedOut = memInfo.otherSwappedOut; |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2288 | int otherSwappedOutPss = memInfo.otherSwappedOutPss; |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2289 | |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2290 | for (int i=0; i<Debug.MemoryInfo.NUM_OTHER_STATS; i++) { |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2291 | final int myPss = memInfo.getOtherPss(i); |
| 2292 | final int mySwappablePss = memInfo.getOtherSwappablePss(i); |
| 2293 | final int mySharedDirty = memInfo.getOtherSharedDirty(i); |
| 2294 | final int myPrivateDirty = memInfo.getOtherPrivateDirty(i); |
| 2295 | final int mySharedClean = memInfo.getOtherSharedClean(i); |
| 2296 | final int myPrivateClean = memInfo.getOtherPrivateClean(i); |
| 2297 | final int mySwappedOut = memInfo.getOtherSwappedOut(i); |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2298 | final int mySwappedOutPss = memInfo.getOtherSwappedOutPss(i); |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2299 | if (myPss != 0 || mySharedDirty != 0 || myPrivateDirty != 0 |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2300 | || mySharedClean != 0 || myPrivateClean != 0 |
| 2301 | || (memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut) != 0) { |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2302 | if (dumpFullInfo) { |
| 2303 | printRow(pw, HEAP_FULL_COLUMN, Debug.MemoryInfo.getOtherLabel(i), |
| 2304 | myPss, mySwappablePss, mySharedDirty, myPrivateDirty, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2305 | mySharedClean, myPrivateClean, |
| 2306 | memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut, |
| 2307 | "", "", ""); |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2308 | } else { |
| 2309 | printRow(pw, HEAP_COLUMN, Debug.MemoryInfo.getOtherLabel(i), |
| 2310 | myPss, myPrivateDirty, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2311 | myPrivateClean, |
| 2312 | memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut, |
| 2313 | "", "", ""); |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2314 | } |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2315 | otherPss -= myPss; |
| 2316 | otherSwappablePss -= mySwappablePss; |
| 2317 | otherSharedDirty -= mySharedDirty; |
| 2318 | otherPrivateDirty -= myPrivateDirty; |
| 2319 | otherSharedClean -= mySharedClean; |
| 2320 | otherPrivateClean -= myPrivateClean; |
| 2321 | otherSwappedOut -= mySwappedOut; |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2322 | otherSwappedOutPss -= mySwappedOutPss; |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2323 | } |
| 2324 | } |
| 2325 | |
| 2326 | if (dumpFullInfo) { |
| 2327 | printRow(pw, HEAP_FULL_COLUMN, "Unknown", otherPss, otherSwappablePss, |
| 2328 | otherSharedDirty, otherPrivateDirty, otherSharedClean, otherPrivateClean, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2329 | memInfo.hasSwappedOutPss ? otherSwappedOutPss : otherSwappedOut, |
| 2330 | "", "", ""); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2331 | printRow(pw, HEAP_FULL_COLUMN, "TOTAL", memInfo.getTotalPss(), |
| 2332 | memInfo.getTotalSwappablePss(), |
| 2333 | memInfo.getTotalSharedDirty(), memInfo.getTotalPrivateDirty(), |
| 2334 | memInfo.getTotalSharedClean(), memInfo.getTotalPrivateClean(), |
Thierry Strudel | 9b51160 | 2016-02-25 17:46:38 -0800 | [diff] [blame] | 2335 | memInfo.hasSwappedOutPss ? memInfo.getTotalSwappedOutPss() : |
| 2336 | memInfo.getTotalSwappedOut(), |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2337 | nativeMax+dalvikMax, nativeAllocated+dalvikAllocated, |
| 2338 | nativeFree+dalvikFree); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2339 | } else { |
| 2340 | printRow(pw, HEAP_COLUMN, "Unknown", otherPss, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2341 | otherPrivateDirty, otherPrivateClean, |
| 2342 | memInfo.hasSwappedOutPss ? otherSwappedOutPss : otherSwappedOut, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2343 | "", "", ""); |
| 2344 | printRow(pw, HEAP_COLUMN, "TOTAL", memInfo.getTotalPss(), |
| 2345 | memInfo.getTotalPrivateDirty(), |
| 2346 | memInfo.getTotalPrivateClean(), |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2347 | memInfo.hasSwappedOutPss ? memInfo.getTotalSwappedOutPss() : |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2348 | memInfo.getTotalSwappedOut(), |
| 2349 | nativeMax+dalvikMax, |
| 2350 | nativeAllocated+dalvikAllocated, nativeFree+dalvikFree); |
| 2351 | } |
| 2352 | |
| 2353 | if (dumpDalvik) { |
| 2354 | pw.println(" "); |
| 2355 | pw.println(" Dalvik Details"); |
| 2356 | |
| 2357 | for (int i=Debug.MemoryInfo.NUM_OTHER_STATS; |
| 2358 | i<Debug.MemoryInfo.NUM_OTHER_STATS + Debug.MemoryInfo.NUM_DVK_STATS; i++) { |
| 2359 | final int myPss = memInfo.getOtherPss(i); |
| 2360 | final int mySwappablePss = memInfo.getOtherSwappablePss(i); |
| 2361 | final int mySharedDirty = memInfo.getOtherSharedDirty(i); |
| 2362 | final int myPrivateDirty = memInfo.getOtherPrivateDirty(i); |
| 2363 | final int mySharedClean = memInfo.getOtherSharedClean(i); |
| 2364 | final int myPrivateClean = memInfo.getOtherPrivateClean(i); |
| 2365 | final int mySwappedOut = memInfo.getOtherSwappedOut(i); |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2366 | final int mySwappedOutPss = memInfo.getOtherSwappedOutPss(i); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2367 | if (myPss != 0 || mySharedDirty != 0 || myPrivateDirty != 0 |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2368 | || mySharedClean != 0 || myPrivateClean != 0 |
| 2369 | || (memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut) != 0) { |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2370 | if (dumpFullInfo) { |
| 2371 | printRow(pw, HEAP_FULL_COLUMN, Debug.MemoryInfo.getOtherLabel(i), |
| 2372 | myPss, mySwappablePss, mySharedDirty, myPrivateDirty, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2373 | mySharedClean, myPrivateClean, |
| 2374 | memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut, |
| 2375 | "", "", ""); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2376 | } else { |
| 2377 | printRow(pw, HEAP_COLUMN, Debug.MemoryInfo.getOtherLabel(i), |
| 2378 | myPss, myPrivateDirty, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2379 | myPrivateClean, |
| 2380 | memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut, |
| 2381 | "", "", ""); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2382 | } |
| 2383 | } |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2384 | } |
| 2385 | } |
| 2386 | } |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2387 | |
| 2388 | pw.println(" "); |
| 2389 | pw.println(" App Summary"); |
| 2390 | printRow(pw, ONE_COUNT_COLUMN_HEADER, "", "Pss(KB)"); |
| 2391 | printRow(pw, ONE_COUNT_COLUMN_HEADER, "", "------"); |
| 2392 | printRow(pw, ONE_COUNT_COLUMN, |
| 2393 | "Java Heap:", memInfo.getSummaryJavaHeap()); |
| 2394 | printRow(pw, ONE_COUNT_COLUMN, |
| 2395 | "Native Heap:", memInfo.getSummaryNativeHeap()); |
| 2396 | printRow(pw, ONE_COUNT_COLUMN, |
| 2397 | "Code:", memInfo.getSummaryCode()); |
| 2398 | printRow(pw, ONE_COUNT_COLUMN, |
| 2399 | "Stack:", memInfo.getSummaryStack()); |
| 2400 | printRow(pw, ONE_COUNT_COLUMN, |
| 2401 | "Graphics:", memInfo.getSummaryGraphics()); |
| 2402 | printRow(pw, ONE_COUNT_COLUMN, |
| 2403 | "Private Other:", memInfo.getSummaryPrivateOther()); |
| 2404 | printRow(pw, ONE_COUNT_COLUMN, |
| 2405 | "System:", memInfo.getSummarySystem()); |
| 2406 | pw.println(" "); |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2407 | if (memInfo.hasSwappedOutPss) { |
| 2408 | printRow(pw, TWO_COUNT_COLUMNS, |
| 2409 | "TOTAL:", memInfo.getSummaryTotalPss(), |
| 2410 | "TOTAL SWAP PSS:", memInfo.getSummaryTotalSwapPss()); |
| 2411 | } else { |
| 2412 | printRow(pw, TWO_COUNT_COLUMNS, |
| 2413 | "TOTAL:", memInfo.getSummaryTotalPss(), |
| 2414 | "TOTAL SWAP (KB):", memInfo.getSummaryTotalSwap()); |
| 2415 | } |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2416 | } |
| 2417 | |
Jeff Hamilton | 52d3203 | 2011-01-08 15:31:26 -0600 | [diff] [blame] | 2418 | public void registerOnActivityPausedListener(Activity activity, |
| 2419 | OnActivityPausedListener listener) { |
| 2420 | synchronized (mOnPauseListeners) { |
| 2421 | ArrayList<OnActivityPausedListener> list = mOnPauseListeners.get(activity); |
| 2422 | if (list == null) { |
| 2423 | list = new ArrayList<OnActivityPausedListener>(); |
| 2424 | mOnPauseListeners.put(activity, list); |
| 2425 | } |
| 2426 | list.add(listener); |
| 2427 | } |
| 2428 | } |
| 2429 | |
Jeff Hamilton | ce3224c | 2011-01-17 11:05:03 -0800 | [diff] [blame] | 2430 | public void unregisterOnActivityPausedListener(Activity activity, |
| 2431 | OnActivityPausedListener listener) { |
| 2432 | synchronized (mOnPauseListeners) { |
| 2433 | ArrayList<OnActivityPausedListener> list = mOnPauseListeners.get(activity); |
| 2434 | if (list != null) { |
| 2435 | list.remove(listener); |
| 2436 | } |
| 2437 | } |
| 2438 | } |
| 2439 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2440 | public final ActivityInfo resolveActivityInfo(Intent intent) { |
| 2441 | ActivityInfo aInfo = intent.resolveActivityInfo( |
| 2442 | mInitialApplication.getPackageManager(), PackageManager.GET_SHARED_LIBRARY_FILES); |
| 2443 | if (aInfo == null) { |
| 2444 | // Throw an exception. |
| 2445 | Instrumentation.checkStartActivityResult( |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 2446 | ActivityManager.START_CLASS_NOT_FOUND, intent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2447 | } |
| 2448 | return aInfo; |
| 2449 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2450 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2451 | public final Activity startActivityNow(Activity parent, String id, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2452 | Intent intent, ActivityInfo activityInfo, IBinder token, Bundle state, |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 2453 | Activity.NonConfigurationInstances lastNonConfigurationInstances) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2454 | ActivityClientRecord r = new ActivityClientRecord(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2455 | r.token = token; |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 2456 | r.ident = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2457 | r.intent = intent; |
| 2458 | r.state = state; |
| 2459 | r.parent = parent; |
| 2460 | r.embeddedID = id; |
| 2461 | r.activityInfo = activityInfo; |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 2462 | r.lastNonConfigurationInstances = lastNonConfigurationInstances; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2463 | if (localLOGV) { |
| 2464 | ComponentName compname = intent.getComponent(); |
| 2465 | String name; |
| 2466 | if (compname != null) { |
| 2467 | name = compname.toShortString(); |
| 2468 | } else { |
| 2469 | name = "(Intent " + intent + ").getComponent() returned null"; |
| 2470 | } |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2471 | Slog.v(TAG, "Performing launch: action=" + intent.getAction() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2472 | + ", comp=" + name |
| 2473 | + ", token=" + token); |
| 2474 | } |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 2475 | return performLaunchActivity(r, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2476 | } |
| 2477 | |
| 2478 | public final Activity getActivity(IBinder token) { |
| 2479 | return mActivities.get(token).activity; |
| 2480 | } |
| 2481 | |
| 2482 | public final void sendActivityResult( |
| 2483 | IBinder token, String id, int requestCode, |
| 2484 | int resultCode, Intent data) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2485 | if (DEBUG_RESULTS) Slog.v(TAG, "sendActivityResult: id=" + id |
Chris Tate | 8a7dc17 | 2009-03-24 20:11:42 -0700 | [diff] [blame] | 2486 | + " req=" + requestCode + " res=" + resultCode + " data=" + data); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2487 | ArrayList<ResultInfo> list = new ArrayList<ResultInfo>(); |
| 2488 | list.add(new ResultInfo(id, requestCode, resultCode, data)); |
| 2489 | mAppThread.scheduleSendResult(token, list); |
| 2490 | } |
| 2491 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 2492 | private void sendMessage(int what, Object obj) { |
| 2493 | sendMessage(what, obj, 0, 0, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2494 | } |
| 2495 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 2496 | private void sendMessage(int what, Object obj, int arg1) { |
| 2497 | sendMessage(what, obj, arg1, 0, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2498 | } |
| 2499 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 2500 | private void sendMessage(int what, Object obj, int arg1, int arg2) { |
| 2501 | sendMessage(what, obj, arg1, arg2, false); |
| 2502 | } |
| 2503 | |
| 2504 | private void sendMessage(int what, Object obj, int arg1, int arg2, boolean async) { |
| 2505 | if (DEBUG_MESSAGES) Slog.v( |
| 2506 | TAG, "SCHEDULE " + what + " " + mH.codeToString(what) |
| 2507 | + ": " + arg1 + " / " + obj); |
| 2508 | Message msg = Message.obtain(); |
| 2509 | msg.what = what; |
| 2510 | msg.obj = obj; |
| 2511 | msg.arg1 = arg1; |
| 2512 | msg.arg2 = arg2; |
| 2513 | if (async) { |
| 2514 | msg.setAsynchronous(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2515 | } |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 2516 | mH.sendMessage(msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2517 | } |
| 2518 | |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 2519 | private void sendMessage(int what, Object obj, int arg1, int arg2, int seq) { |
| 2520 | if (DEBUG_MESSAGES) Slog.v( |
| 2521 | TAG, "SCHEDULE " + mH.codeToString(what) + " arg1=" + arg1 + " arg2=" + arg2 + |
| 2522 | "seq= " + seq); |
| 2523 | Message msg = Message.obtain(); |
| 2524 | msg.what = what; |
| 2525 | SomeArgs args = SomeArgs.obtain(); |
| 2526 | args.arg1 = obj; |
| 2527 | args.argi1 = arg1; |
| 2528 | args.argi2 = arg2; |
| 2529 | args.argi3 = seq; |
| 2530 | msg.obj = args; |
| 2531 | mH.sendMessage(msg); |
| 2532 | } |
| 2533 | |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 2534 | final void scheduleContextCleanup(ContextImpl context, String who, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2535 | String what) { |
| 2536 | ContextCleanupInfo cci = new ContextCleanupInfo(); |
| 2537 | cci.context = context; |
| 2538 | cci.who = who; |
| 2539 | cci.what = what; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 2540 | sendMessage(H.CLEAN_UP_CONTEXT, cci); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2541 | } |
| 2542 | |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 2543 | private Activity performLaunchActivity(ActivityClientRecord r, Intent customIntent) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2544 | // System.out.println("##### [" + System.currentTimeMillis() + "] ActivityThread.performLaunchActivity(" + r + ")"); |
| 2545 | |
| 2546 | ActivityInfo aInfo = r.activityInfo; |
| 2547 | if (r.packageInfo == null) { |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2548 | r.packageInfo = getPackageInfo(aInfo.applicationInfo, r.compatInfo, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2549 | Context.CONTEXT_INCLUDE_CODE); |
| 2550 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2551 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2552 | ComponentName component = r.intent.getComponent(); |
| 2553 | if (component == null) { |
| 2554 | component = r.intent.resolveActivity( |
| 2555 | mInitialApplication.getPackageManager()); |
| 2556 | r.intent.setComponent(component); |
| 2557 | } |
| 2558 | |
| 2559 | if (r.activityInfo.targetActivity != null) { |
| 2560 | component = new ComponentName(r.activityInfo.packageName, |
| 2561 | r.activityInfo.targetActivity); |
| 2562 | } |
| 2563 | |
| 2564 | Activity activity = null; |
| 2565 | try { |
| 2566 | java.lang.ClassLoader cl = r.packageInfo.getClassLoader(); |
| 2567 | activity = mInstrumentation.newActivity( |
| 2568 | cl, component.getClassName(), r.intent); |
Brad Fitzpatrick | 5f8b5c1 | 2011-01-20 15:12:08 -0800 | [diff] [blame] | 2569 | StrictMode.incrementExpectedActivityCount(activity.getClass()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2570 | r.intent.setExtrasClassLoader(cl); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 2571 | r.intent.prepareToEnterProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2572 | if (r.state != null) { |
| 2573 | r.state.setClassLoader(cl); |
| 2574 | } |
| 2575 | } catch (Exception e) { |
| 2576 | if (!mInstrumentation.onException(activity, e)) { |
| 2577 | throw new RuntimeException( |
| 2578 | "Unable to instantiate activity " + component |
| 2579 | + ": " + e.toString(), e); |
| 2580 | } |
| 2581 | } |
| 2582 | |
| 2583 | try { |
Dianne Hackborn | 0be1f78 | 2009-11-09 12:30:12 -0800 | [diff] [blame] | 2584 | Application app = r.packageInfo.makeApplication(false, mInstrumentation); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2585 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2586 | if (localLOGV) Slog.v(TAG, "Performing launch of " + r); |
| 2587 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2588 | TAG, r + ": app=" + app |
| 2589 | + ", appName=" + app.getPackageName() |
| 2590 | + ", pkg=" + r.packageInfo.getPackageName() |
| 2591 | + ", comp=" + r.intent.getComponent().toShortString() |
| 2592 | + ", dir=" + r.packageInfo.getAppDir()); |
| 2593 | |
| 2594 | if (activity != null) { |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 2595 | Context appContext = createBaseContextForActivity(r, activity); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2596 | CharSequence title = r.activityInfo.loadLabel(appContext.getPackageManager()); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 2597 | Configuration config = new Configuration(mCompatConfiguration); |
Andrii Kulian | d0ad938 | 2016-04-18 20:54:20 -0700 | [diff] [blame] | 2598 | if (r.overrideConfig != null) { |
| 2599 | config.updateFrom(r.overrideConfig); |
| 2600 | } |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2601 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Launching activity " |
Dianne Hackborn | dc6b635 | 2009-09-30 14:20:09 -0700 | [diff] [blame] | 2602 | + r.activityInfo.name + " with config " + config); |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 2603 | Window window = null; |
| 2604 | if (r.mPendingRemoveWindow != null && r.mPreserveWindow) { |
| 2605 | window = r.mPendingRemoveWindow; |
| 2606 | r.mPendingRemoveWindow = null; |
| 2607 | r.mPendingRemoveWindowManager = null; |
| 2608 | } |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 2609 | activity.attach(appContext, this, getInstrumentation(), r.token, |
| 2610 | r.ident, app, r.intent, r.activityInfo, title, r.parent, |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 2611 | r.embeddedID, r.lastNonConfigurationInstances, config, |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 2612 | r.referrer, r.voiceInteractor, window); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2613 | |
Christopher Tate | b70f3df | 2009-04-07 16:07:59 -0700 | [diff] [blame] | 2614 | if (customIntent != null) { |
| 2615 | activity.mIntent = customIntent; |
| 2616 | } |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 2617 | r.lastNonConfigurationInstances = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2618 | activity.mStartedActivity = false; |
| 2619 | int theme = r.activityInfo.getThemeResource(); |
| 2620 | if (theme != 0) { |
| 2621 | activity.setTheme(theme); |
| 2622 | } |
| 2623 | |
| 2624 | activity.mCalled = false; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2625 | if (r.isPersistable()) { |
| 2626 | mInstrumentation.callActivityOnCreate(activity, r.state, r.persistentState); |
| 2627 | } else { |
| 2628 | mInstrumentation.callActivityOnCreate(activity, r.state); |
| 2629 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2630 | if (!activity.mCalled) { |
| 2631 | throw new SuperNotCalledException( |
| 2632 | "Activity " + r.intent.getComponent().toShortString() + |
| 2633 | " did not call through to super.onCreate()"); |
| 2634 | } |
| 2635 | r.activity = activity; |
| 2636 | r.stopped = true; |
| 2637 | if (!r.activity.mFinished) { |
| 2638 | activity.performStart(); |
| 2639 | r.stopped = false; |
| 2640 | } |
| 2641 | if (!r.activity.mFinished) { |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2642 | if (r.isPersistable()) { |
| 2643 | if (r.state != null || r.persistentState != null) { |
| 2644 | mInstrumentation.callActivityOnRestoreInstanceState(activity, r.state, |
| 2645 | r.persistentState); |
| 2646 | } |
| 2647 | } else if (r.state != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2648 | mInstrumentation.callActivityOnRestoreInstanceState(activity, r.state); |
| 2649 | } |
| 2650 | } |
| 2651 | if (!r.activity.mFinished) { |
| 2652 | activity.mCalled = false; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2653 | if (r.isPersistable()) { |
| 2654 | mInstrumentation.callActivityOnPostCreate(activity, r.state, |
| 2655 | r.persistentState); |
| 2656 | } else { |
| 2657 | mInstrumentation.callActivityOnPostCreate(activity, r.state); |
| 2658 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2659 | if (!activity.mCalled) { |
| 2660 | throw new SuperNotCalledException( |
| 2661 | "Activity " + r.intent.getComponent().toShortString() + |
| 2662 | " did not call through to super.onPostCreate()"); |
| 2663 | } |
| 2664 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2665 | } |
| 2666 | r.paused = true; |
| 2667 | |
| 2668 | mActivities.put(r.token, r); |
| 2669 | |
| 2670 | } catch (SuperNotCalledException e) { |
| 2671 | throw e; |
| 2672 | |
| 2673 | } catch (Exception e) { |
| 2674 | if (!mInstrumentation.onException(activity, e)) { |
| 2675 | throw new RuntimeException( |
| 2676 | "Unable to start activity " + component |
| 2677 | + ": " + e.toString(), e); |
| 2678 | } |
| 2679 | } |
| 2680 | |
| 2681 | return activity; |
| 2682 | } |
| 2683 | |
Wale Ogunwale | 7c72668 | 2015-02-06 17:34:28 -0800 | [diff] [blame] | 2684 | private Context createBaseContextForActivity(ActivityClientRecord r, final Activity activity) { |
| 2685 | int displayId = Display.DEFAULT_DISPLAY; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2686 | try { |
Craig Mautner | aa7e3ed | 2015-02-17 10:17:21 -0800 | [diff] [blame] | 2687 | displayId = ActivityManagerNative.getDefault().getActivityDisplayId(r.token); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2688 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2689 | throw e.rethrowFromSystemServer(); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2690 | } |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 2691 | |
Wale Ogunwale | 7c72668 | 2015-02-06 17:34:28 -0800 | [diff] [blame] | 2692 | ContextImpl appContext = ContextImpl.createActivityContext( |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 2693 | this, r.packageInfo, r.token, displayId, r.overrideConfig); |
Wale Ogunwale | 7c72668 | 2015-02-06 17:34:28 -0800 | [diff] [blame] | 2694 | appContext.setOuterContext(activity); |
| 2695 | Context baseContext = appContext; |
| 2696 | |
| 2697 | final DisplayManagerGlobal dm = DisplayManagerGlobal.getInstance(); |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 2698 | // For debugging purposes, if the activity's package name contains the value of |
| 2699 | // the "debug.use-second-display" system property as a substring, then show |
| 2700 | // its content on a secondary display if there is one. |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 2701 | String pkgName = SystemProperties.get("debug.second-display.pkg"); |
| 2702 | if (pkgName != null && !pkgName.isEmpty() |
| 2703 | && r.packageInfo.mPackageName.contains(pkgName)) { |
Wale Ogunwale | 7c72668 | 2015-02-06 17:34:28 -0800 | [diff] [blame] | 2704 | for (int id : dm.getDisplayIds()) { |
| 2705 | if (id != Display.DEFAULT_DISPLAY) { |
Wale Ogunwale | 2669851 | 2015-06-05 16:55:33 -0700 | [diff] [blame] | 2706 | Display display = |
| 2707 | dm.getCompatibleDisplay(id, appContext.getDisplayAdjustments(id)); |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 2708 | baseContext = appContext.createDisplayContext(display); |
| 2709 | break; |
| 2710 | } |
| 2711 | } |
| 2712 | } |
| 2713 | return baseContext; |
| 2714 | } |
| 2715 | |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 2716 | private void handleLaunchActivity(ActivityClientRecord r, Intent customIntent, String reason) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2717 | // If we are getting ready to gc after going to the background, well |
| 2718 | // we are back active so skip it. |
| 2719 | unscheduleGcIdler(); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 2720 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2721 | |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 2722 | if (r.profilerInfo != null) { |
| 2723 | mProfiler.setProfiler(r.profilerInfo); |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 2724 | mProfiler.startProfiling(); |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 2725 | } |
| 2726 | |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 2727 | // Make sure we are running with the most recent config. |
| 2728 | handleConfigurationChanged(null, null); |
| 2729 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2730 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2731 | TAG, "Handling launch of " + r); |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 2732 | |
Chet Haase | 0d1c27a | 2014-11-03 18:35:16 +0000 | [diff] [blame] | 2733 | // Initialize before creating the activity |
| 2734 | WindowManagerGlobal.initialize(); |
| 2735 | |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 2736 | Activity a = performLaunchActivity(r, customIntent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2737 | |
| 2738 | if (a != null) { |
Dianne Hackborn | 871ecdc | 2009-12-11 15:24:33 -0800 | [diff] [blame] | 2739 | r.createdConfig = new Configuration(mConfiguration); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 2740 | reportSizeConfigurations(r); |
Dianne Hackborn | 9e0f5d9 | 2010-02-22 15:05:42 -0800 | [diff] [blame] | 2741 | Bundle oldState = r.state; |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 2742 | handleResumeActivity(r.token, false, r.isForward, |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 2743 | !r.activity.mFinished && !r.startsNotResumed, r.lastProcessedSeq, reason); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2744 | |
| 2745 | if (!r.activity.mFinished && r.startsNotResumed) { |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 2746 | // The activity manager actually wants this one to start out paused, because it |
| 2747 | // needs to be visible but isn't in the foreground. We accomplish this by going |
| 2748 | // through the normal startup (because activities expect to go through onResume() |
| 2749 | // the first time they run, before their window is displayed), and then pausing it. |
| 2750 | // However, in this case we do -not- need to do the full pause cycle (of freezing |
| 2751 | // and such) because the activity manager assumes it can just retain the current |
| 2752 | // state it has. |
| 2753 | performPauseActivityIfNeeded(r, reason); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2754 | |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 2755 | // We need to keep around the original state, in case we need to be created again. |
| 2756 | // But we only do this for pre-Honeycomb apps, which always save their state when |
| 2757 | // pausing, so we can not have them save their state when restarting from a paused |
| 2758 | // state. For HC and later, we want to (and can) let the state be saved as the |
| 2759 | // normal part of stopping the activity. |
| 2760 | if (r.isPreHoneycomb()) { |
| 2761 | r.state = oldState; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2762 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2763 | } |
| 2764 | } else { |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 2765 | // 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] | 2766 | try { |
| 2767 | ActivityManagerNative.getDefault() |
Wale Ogunwale | ba7881c | 2015-08-01 19:28:29 -0700 | [diff] [blame] | 2768 | .finishActivity(r.token, Activity.RESULT_CANCELED, null, |
| 2769 | Activity.DONT_FINISH_TASK_WITH_ACTIVITY); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2770 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2771 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2772 | } |
| 2773 | } |
| 2774 | } |
| 2775 | |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 2776 | private void reportSizeConfigurations(ActivityClientRecord r) { |
| 2777 | Configuration[] configurations = r.activity.getResources().getSizeConfigurations(); |
| 2778 | if (configurations == null) { |
| 2779 | return; |
| 2780 | } |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 2781 | SparseIntArray horizontal = new SparseIntArray(); |
| 2782 | SparseIntArray vertical = new SparseIntArray(); |
| 2783 | SparseIntArray smallest = new SparseIntArray(); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 2784 | for (int i = configurations.length - 1; i >= 0; i--) { |
| 2785 | Configuration config = configurations[i]; |
| 2786 | if (config.screenHeightDp != Configuration.SCREEN_HEIGHT_DP_UNDEFINED) { |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 2787 | vertical.put(config.screenHeightDp, 0); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 2788 | } |
| 2789 | if (config.screenWidthDp != Configuration.SCREEN_WIDTH_DP_UNDEFINED) { |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 2790 | horizontal.put(config.screenWidthDp, 0); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 2791 | } |
| 2792 | if (config.smallestScreenWidthDp != Configuration.SMALLEST_SCREEN_WIDTH_DP_UNDEFINED) { |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 2793 | smallest.put(config.smallestScreenWidthDp, 0); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 2794 | } |
| 2795 | } |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 2796 | try { |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 2797 | ActivityManagerNative.getDefault().reportSizeConfigurations(r.token, |
| 2798 | horizontal.copyKeys(), vertical.copyKeys(), smallest.copyKeys()); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 2799 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2800 | throw ex.rethrowFromSystemServer(); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 2801 | } |
| 2802 | |
| 2803 | } |
| 2804 | |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 2805 | private void deliverNewIntents(ActivityClientRecord r, List<ReferrerIntent> intents) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2806 | final int N = intents.size(); |
| 2807 | for (int i=0; i<N; i++) { |
Dianne Hackborn | a01a0fa | 2014-12-02 10:33:14 -0800 | [diff] [blame] | 2808 | ReferrerIntent intent = intents.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2809 | intent.setExtrasClassLoader(r.activity.getClassLoader()); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 2810 | intent.prepareToEnterProcess(); |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 2811 | r.activity.mFragments.noteStateNotSaved(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2812 | mInstrumentation.callActivityOnNewIntent(r.activity, intent); |
| 2813 | } |
| 2814 | } |
| 2815 | |
Wale Ogunwale | 826c706 | 2016-09-13 08:25:54 -0700 | [diff] [blame] | 2816 | void performNewIntents(IBinder token, List<ReferrerIntent> intents, boolean andPause) { |
| 2817 | final ActivityClientRecord r = mActivities.get(token); |
| 2818 | if (r == null) { |
| 2819 | return; |
| 2820 | } |
| 2821 | |
| 2822 | final boolean resumed = !r.paused; |
| 2823 | if (resumed) { |
| 2824 | r.activity.mTemporaryPause = true; |
| 2825 | mInstrumentation.callActivityOnPause(r.activity); |
| 2826 | } |
| 2827 | deliverNewIntents(r, intents); |
| 2828 | if (resumed) { |
| 2829 | r.activity.performResume(); |
| 2830 | r.activity.mTemporaryPause = false; |
| 2831 | } |
| 2832 | |
| 2833 | if (r.paused && andPause) { |
| 2834 | // In this case the activity was in the paused state when we delivered the intent, |
| 2835 | // to guarantee onResume gets called after onNewIntent we temporarily resume the |
| 2836 | // activity and pause again as the caller wanted. |
| 2837 | performResumeActivity(token, false, "performNewIntents"); |
| 2838 | performPauseActivityIfNeeded(r, "performNewIntents"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2839 | } |
| 2840 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2841 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 2842 | private void handleNewIntent(NewIntentData data) { |
Wale Ogunwale | 826c706 | 2016-09-13 08:25:54 -0700 | [diff] [blame] | 2843 | performNewIntents(data.token, data.intents, data.andPause); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2844 | } |
| 2845 | |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 2846 | public void handleRequestAssistContextExtras(RequestAssistContextExtras cmd) { |
Amith Yamasani | 4f128e4 | 2016-05-10 11:44:12 -0700 | [diff] [blame] | 2847 | if (mLastSessionId != cmd.sessionId) { |
| 2848 | // Clear the existing structures |
| 2849 | mLastSessionId = cmd.sessionId; |
| 2850 | for (int i = mLastAssistStructures.size() - 1; i >= 0; i--) { |
| 2851 | AssistStructure structure = mLastAssistStructures.get(i).get(); |
| 2852 | if (structure != null) { |
| 2853 | structure.clearSendChannel(); |
| 2854 | } |
| 2855 | mLastAssistStructures.remove(i); |
Dianne Hackborn | 782d498 | 2015-07-08 17:36:37 -0700 | [diff] [blame] | 2856 | } |
| 2857 | } |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 2858 | Bundle data = new Bundle(); |
Dianne Hackborn | 09d57fe | 2015-05-27 18:05:52 -0700 | [diff] [blame] | 2859 | AssistStructure structure = null; |
| 2860 | AssistContent content = new AssistContent(); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 2861 | ActivityClientRecord r = mActivities.get(cmd.activityToken); |
Dianne Hackborn | a3acdb3 | 2015-06-08 17:07:40 -0700 | [diff] [blame] | 2862 | Uri referrer = null; |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 2863 | if (r != null) { |
| 2864 | r.activity.getApplication().dispatchOnProvideAssistData(r.activity, data); |
| 2865 | r.activity.onProvideAssistData(data); |
Dianne Hackborn | a3acdb3 | 2015-06-08 17:07:40 -0700 | [diff] [blame] | 2866 | referrer = r.activity.onProvideReferrer(); |
Dianne Hackborn | a83ce1d | 2015-03-11 15:16:13 -0700 | [diff] [blame] | 2867 | if (cmd.requestType == ActivityManager.ASSIST_CONTEXT_FULL) { |
Dianne Hackborn | 09d57fe | 2015-05-27 18:05:52 -0700 | [diff] [blame] | 2868 | structure = new AssistStructure(r.activity); |
Adam Skory | 4aaed14 | 2015-04-22 11:29:31 -0600 | [diff] [blame] | 2869 | Intent activityIntent = r.activity.getIntent(); |
Dianne Hackborn | 09d57fe | 2015-05-27 18:05:52 -0700 | [diff] [blame] | 2870 | if (activityIntent != null && (r.window == null || |
| 2871 | (r.window.getAttributes().flags |
| 2872 | & WindowManager.LayoutParams.FLAG_SECURE) == 0)) { |
Adam Skory | 4aaed14 | 2015-04-22 11:29:31 -0600 | [diff] [blame] | 2873 | Intent intent = new Intent(activityIntent); |
| 2874 | intent.setFlags(intent.getFlags() & ~(Intent.FLAG_GRANT_WRITE_URI_PERMISSION |
| 2875 | | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION)); |
| 2876 | intent.removeUnsafeExtras(); |
Adam Skory | cd70c64 | 2015-06-05 11:41:55 -0600 | [diff] [blame] | 2877 | content.setDefaultIntent(intent); |
Adam Skory | 4aaed14 | 2015-04-22 11:29:31 -0600 | [diff] [blame] | 2878 | } else { |
Adam Skory | cd70c64 | 2015-06-05 11:41:55 -0600 | [diff] [blame] | 2879 | content.setDefaultIntent(new Intent()); |
Adam Skory | 4aaed14 | 2015-04-22 11:29:31 -0600 | [diff] [blame] | 2880 | } |
Dianne Hackborn | a83ce1d | 2015-03-11 15:16:13 -0700 | [diff] [blame] | 2881 | r.activity.onProvideAssistContent(content); |
Dianne Hackborn | a83ce1d | 2015-03-11 15:16:13 -0700 | [diff] [blame] | 2882 | } |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 2883 | } |
Dianne Hackborn | 09d57fe | 2015-05-27 18:05:52 -0700 | [diff] [blame] | 2884 | if (structure == null) { |
| 2885 | structure = new AssistStructure(); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 2886 | } |
Amith Yamasani | 4f128e4 | 2016-05-10 11:44:12 -0700 | [diff] [blame] | 2887 | mLastAssistStructures.add(new WeakReference<>(structure)); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 2888 | IActivityManager mgr = ActivityManagerNative.getDefault(); |
| 2889 | try { |
Dianne Hackborn | a3acdb3 | 2015-06-08 17:07:40 -0700 | [diff] [blame] | 2890 | mgr.reportAssistContextExtras(cmd.requestToken, data, structure, content, referrer); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 2891 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2892 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 2893 | } |
| 2894 | } |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 2895 | |
| 2896 | public void handleTranslucentConversionComplete(IBinder token, boolean drawComplete) { |
| 2897 | ActivityClientRecord r = mActivities.get(token); |
| 2898 | if (r != null) { |
| 2899 | r.activity.onTranslucentConversionComplete(drawComplete); |
| 2900 | } |
| 2901 | } |
| 2902 | |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 2903 | public void onNewActivityOptions(IBinder token, ActivityOptions options) { |
| 2904 | ActivityClientRecord r = mActivities.get(token); |
| 2905 | if (r != null) { |
| 2906 | r.activity.onNewActivityOptions(options); |
| 2907 | } |
| 2908 | } |
| 2909 | |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 2910 | public void handleCancelVisibleBehind(IBinder token) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 2911 | ActivityClientRecord r = mActivities.get(token); |
| 2912 | if (r != null) { |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 2913 | mSomeActivitiesChanged = true; |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 2914 | final Activity activity = r.activity; |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 2915 | if (activity.mVisibleBehind) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 2916 | activity.mCalled = false; |
Jose Lima | fcf7083 | 2014-08-27 23:09:05 -0700 | [diff] [blame] | 2917 | activity.onVisibleBehindCanceled(); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 2918 | // Tick, tick, tick. The activity has 500 msec to return or it will be destroyed. |
| 2919 | if (!activity.mCalled) { |
| 2920 | throw new SuperNotCalledException("Activity " + activity.getLocalClassName() + |
Jose Lima | fcf7083 | 2014-08-27 23:09:05 -0700 | [diff] [blame] | 2921 | " did not call through to super.onVisibleBehindCanceled()"); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 2922 | } |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 2923 | activity.mVisibleBehind = false; |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 2924 | } |
| 2925 | } |
| 2926 | try { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 2927 | ActivityManagerNative.getDefault().backgroundResourcesReleased(token); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 2928 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2929 | throw e.rethrowFromSystemServer(); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 2930 | } |
| 2931 | } |
| 2932 | |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 2933 | public void handleOnBackgroundVisibleBehindChanged(IBinder token, boolean visible) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 2934 | ActivityClientRecord r = mActivities.get(token); |
| 2935 | if (r != null) { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 2936 | r.activity.onBackgroundVisibleBehindChanged(visible); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 2937 | } |
| 2938 | } |
| 2939 | |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 2940 | public void handleInstallProvider(ProviderInfo info) { |
Jeff Sharkey | bb2e2ca | 2014-10-23 11:42:31 -0700 | [diff] [blame] | 2941 | final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); |
| 2942 | try { |
| 2943 | installContentProviders(mInitialApplication, Lists.newArrayList(info)); |
| 2944 | } finally { |
| 2945 | StrictMode.setThreadPolicy(oldPolicy); |
| 2946 | } |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 2947 | } |
| 2948 | |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 2949 | private void handleEnterAnimationComplete(IBinder token) { |
| 2950 | ActivityClientRecord r = mActivities.get(token); |
| 2951 | if (r != null) { |
Filip Gruszczynski | 6eafa90 | 2014-11-14 14:24:37 -0800 | [diff] [blame] | 2952 | r.activity.dispatchEnterAnimationComplete(); |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 2953 | } |
| 2954 | } |
| 2955 | |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 2956 | private void handleStartBinderTracking() { |
| 2957 | Binder.enableTracing(); |
| 2958 | } |
| 2959 | |
| 2960 | private void handleStopBinderTrackingAndDump(ParcelFileDescriptor fd) { |
| 2961 | try { |
| 2962 | Binder.disableTracing(); |
| 2963 | Binder.getTransactionTracker().writeTracesToFile(fd); |
| 2964 | } finally { |
| 2965 | IoUtils.closeQuietly(fd); |
| 2966 | Binder.getTransactionTracker().clearTraces(); |
| 2967 | } |
| 2968 | } |
| 2969 | |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 2970 | private void handleMultiWindowModeChanged(IBinder token, boolean isInMultiWindowMode) { |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 2971 | final ActivityClientRecord r = mActivities.get(token); |
| 2972 | if (r != null) { |
Adam Powell | 858cf03 | 2016-05-09 15:45:37 -0700 | [diff] [blame] | 2973 | r.activity.dispatchMultiWindowModeChanged(isInMultiWindowMode); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 2974 | } |
| 2975 | } |
| 2976 | |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 2977 | private void handlePictureInPictureModeChanged(IBinder token, boolean isInPipMode) { |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 2978 | final ActivityClientRecord r = mActivities.get(token); |
| 2979 | if (r != null) { |
Adam Powell | 858cf03 | 2016-05-09 15:45:37 -0700 | [diff] [blame] | 2980 | r.activity.dispatchPictureInPictureModeChanged(isInPipMode); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 2981 | } |
| 2982 | } |
| 2983 | |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 2984 | private void handleLocalVoiceInteractionStarted(IBinder token, IVoiceInteractor interactor) { |
| 2985 | final ActivityClientRecord r = mActivities.get(token); |
| 2986 | if (r != null) { |
| 2987 | r.voiceInteractor = interactor; |
| 2988 | r.activity.setVoiceInteractor(interactor); |
| 2989 | if (interactor == null) { |
| 2990 | r.activity.onLocalVoiceInteractionStopped(); |
| 2991 | } else { |
| 2992 | r.activity.onLocalVoiceInteractionStarted(); |
| 2993 | } |
| 2994 | } |
| 2995 | } |
| 2996 | |
Brad Fitzpatrick | bfb1919 | 2010-10-29 15:25:44 -0700 | [diff] [blame] | 2997 | private static final ThreadLocal<Intent> sCurrentBroadcastIntent = new ThreadLocal<Intent>(); |
| 2998 | |
| 2999 | /** |
| 3000 | * Return the Intent that's currently being handled by a |
| 3001 | * BroadcastReceiver on this thread, or null if none. |
| 3002 | * @hide |
| 3003 | */ |
| 3004 | public static Intent getIntentBeingBroadcast() { |
| 3005 | return sCurrentBroadcastIntent.get(); |
| 3006 | } |
| 3007 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3008 | private void handleReceiver(ReceiverData data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3009 | // If we are getting ready to gc after going to the background, well |
| 3010 | // we are back active so skip it. |
| 3011 | unscheduleGcIdler(); |
| 3012 | |
| 3013 | String component = data.intent.getComponent().getClassName(); |
| 3014 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3015 | LoadedApk packageInfo = getPackageInfoNoCheck( |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 3016 | data.info.applicationInfo, data.compatInfo); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3017 | |
| 3018 | IActivityManager mgr = ActivityManagerNative.getDefault(); |
| 3019 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3020 | BroadcastReceiver receiver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3021 | try { |
| 3022 | java.lang.ClassLoader cl = packageInfo.getClassLoader(); |
| 3023 | data.intent.setExtrasClassLoader(cl); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 3024 | data.intent.prepareToEnterProcess(); |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 3025 | data.setExtrasClassLoader(cl); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3026 | receiver = (BroadcastReceiver)cl.loadClass(component).newInstance(); |
| 3027 | } catch (Exception e) { |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 3028 | if (DEBUG_BROADCAST) Slog.i(TAG, |
| 3029 | "Finishing failed broadcast to " + data.intent.getComponent()); |
| 3030 | data.sendFinished(mgr); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3031 | throw new RuntimeException( |
| 3032 | "Unable to instantiate receiver " + component |
| 3033 | + ": " + e.toString(), e); |
| 3034 | } |
| 3035 | |
| 3036 | try { |
Dianne Hackborn | 0be1f78 | 2009-11-09 12:30:12 -0800 | [diff] [blame] | 3037 | Application app = packageInfo.makeApplication(false, mInstrumentation); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3038 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3039 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3040 | TAG, "Performing receive of " + data.intent |
| 3041 | + ": app=" + app |
| 3042 | + ", appName=" + app.getPackageName() |
| 3043 | + ", pkg=" + packageInfo.getPackageName() |
| 3044 | + ", comp=" + data.intent.getComponent().toShortString() |
| 3045 | + ", dir=" + packageInfo.getAppDir()); |
| 3046 | |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 3047 | ContextImpl context = (ContextImpl)app.getBaseContext(); |
Brad Fitzpatrick | bfb1919 | 2010-10-29 15:25:44 -0700 | [diff] [blame] | 3048 | sCurrentBroadcastIntent.set(data.intent); |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 3049 | receiver.setPendingResult(data); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3050 | receiver.onReceive(context.getReceiverRestrictedContext(), |
| 3051 | data.intent); |
| 3052 | } catch (Exception e) { |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 3053 | if (DEBUG_BROADCAST) Slog.i(TAG, |
| 3054 | "Finishing failed broadcast to " + data.intent.getComponent()); |
| 3055 | data.sendFinished(mgr); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3056 | if (!mInstrumentation.onException(receiver, e)) { |
| 3057 | throw new RuntimeException( |
| 3058 | "Unable to start receiver " + component |
| 3059 | + ": " + e.toString(), e); |
| 3060 | } |
Brad Fitzpatrick | bfb1919 | 2010-10-29 15:25:44 -0700 | [diff] [blame] | 3061 | } finally { |
| 3062 | sCurrentBroadcastIntent.set(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3063 | } |
| 3064 | |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 3065 | if (receiver.getPendingResult() != null) { |
| 3066 | data.finish(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3067 | } |
| 3068 | } |
| 3069 | |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3070 | // Instantiate a BackupAgent and tell it that it's alive |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3071 | private void handleCreateBackupAgent(CreateBackupAgentData data) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3072 | if (DEBUG_BACKUP) Slog.v(TAG, "handleCreateBackupAgent: " + data); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3073 | |
Christopher Tate | 346acb1 | 2012-10-15 19:20:25 -0700 | [diff] [blame] | 3074 | // Sanity check the requested target package's uid against ours |
| 3075 | try { |
| 3076 | PackageInfo requestedPackage = getPackageManager().getPackageInfo( |
| 3077 | data.appInfo.packageName, 0, UserHandle.myUserId()); |
| 3078 | if (requestedPackage.applicationInfo.uid != Process.myUid()) { |
| 3079 | Slog.w(TAG, "Asked to instantiate non-matching package " |
| 3080 | + data.appInfo.packageName); |
| 3081 | return; |
| 3082 | } |
| 3083 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3084 | throw e.rethrowFromSystemServer(); |
Christopher Tate | 346acb1 | 2012-10-15 19:20:25 -0700 | [diff] [blame] | 3085 | } |
| 3086 | |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3087 | // no longer idle; we have backup work to do |
| 3088 | unscheduleGcIdler(); |
| 3089 | |
| 3090 | // instantiate the BackupAgent class named in the manifest |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 3091 | LoadedApk packageInfo = getPackageInfoNoCheck(data.appInfo, data.compatInfo); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3092 | String packageName = packageInfo.mPackageName; |
Christopher Tate | 346acb1 | 2012-10-15 19:20:25 -0700 | [diff] [blame] | 3093 | if (packageName == null) { |
| 3094 | Slog.d(TAG, "Asked to create backup agent for nonexistent package"); |
| 3095 | return; |
| 3096 | } |
| 3097 | |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3098 | String classname = data.appInfo.backupAgentName; |
Christopher Tate | 79ec80d | 2011-06-24 14:58:49 -0700 | [diff] [blame] | 3099 | // full backup operation but no app-supplied agent? use the default implementation |
| 3100 | if (classname == null && (data.backupMode == IApplicationThread.BACKUP_MODE_FULL |
| 3101 | || data.backupMode == IApplicationThread.BACKUP_MODE_RESTORE_FULL)) { |
Christopher Tate | 4a627c7 | 2011-04-01 14:43:32 -0700 | [diff] [blame] | 3102 | classname = "android.app.backup.FullBackupAgent"; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3103 | } |
Christopher Tate | 4a627c7 | 2011-04-01 14:43:32 -0700 | [diff] [blame] | 3104 | |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3105 | try { |
Christopher Tate | d1475e0 | 2009-07-09 15:36:17 -0700 | [diff] [blame] | 3106 | IBinder binder = null; |
Christopher Tate | 2e40d11 | 2014-07-15 12:37:38 -0700 | [diff] [blame] | 3107 | BackupAgent agent = mBackupAgents.get(packageName); |
| 3108 | if (agent != null) { |
| 3109 | // reusing the existing instance |
| 3110 | if (DEBUG_BACKUP) { |
| 3111 | Slog.v(TAG, "Reusing existing agent instance"); |
Christopher Tate | d1475e0 | 2009-07-09 15:36:17 -0700 | [diff] [blame] | 3112 | } |
Christopher Tate | 2e40d11 | 2014-07-15 12:37:38 -0700 | [diff] [blame] | 3113 | binder = agent.onBind(); |
| 3114 | } else { |
| 3115 | try { |
| 3116 | if (DEBUG_BACKUP) Slog.v(TAG, "Initializing agent class " + classname); |
| 3117 | |
| 3118 | java.lang.ClassLoader cl = packageInfo.getClassLoader(); |
| 3119 | agent = (BackupAgent) cl.loadClass(classname).newInstance(); |
| 3120 | |
| 3121 | // set up the agent's context |
| 3122 | ContextImpl context = ContextImpl.createAppContext(this, packageInfo); |
| 3123 | context.setOuterContext(agent); |
| 3124 | agent.attach(context); |
| 3125 | |
| 3126 | agent.onCreate(); |
| 3127 | binder = agent.onBind(); |
| 3128 | mBackupAgents.put(packageName, agent); |
| 3129 | } catch (Exception e) { |
| 3130 | // If this is during restore, fail silently; otherwise go |
| 3131 | // ahead and let the user see the crash. |
| 3132 | Slog.e(TAG, "Agent threw during creation: " + e); |
| 3133 | if (data.backupMode != IApplicationThread.BACKUP_MODE_RESTORE |
| 3134 | && data.backupMode != IApplicationThread.BACKUP_MODE_RESTORE_FULL) { |
| 3135 | throw e; |
| 3136 | } |
| 3137 | // falling through with 'binder' still null |
| 3138 | } |
Christopher Tate | d1475e0 | 2009-07-09 15:36:17 -0700 | [diff] [blame] | 3139 | } |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3140 | |
| 3141 | // tell the OS that we're live now |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3142 | try { |
| 3143 | ActivityManagerNative.getDefault().backupAgentCreated(packageName, binder); |
| 3144 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3145 | throw e.rethrowFromSystemServer(); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3146 | } |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3147 | } catch (Exception e) { |
| 3148 | throw new RuntimeException("Unable to create BackupAgent " |
Christopher Tate | 4a627c7 | 2011-04-01 14:43:32 -0700 | [diff] [blame] | 3149 | + classname + ": " + e.toString(), e); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3150 | } |
| 3151 | } |
| 3152 | |
| 3153 | // Tear down a BackupAgent |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3154 | private void handleDestroyBackupAgent(CreateBackupAgentData data) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3155 | if (DEBUG_BACKUP) Slog.v(TAG, "handleDestroyBackupAgent: " + data); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3156 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 3157 | LoadedApk packageInfo = getPackageInfoNoCheck(data.appInfo, data.compatInfo); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3158 | String packageName = packageInfo.mPackageName; |
| 3159 | BackupAgent agent = mBackupAgents.get(packageName); |
| 3160 | if (agent != null) { |
| 3161 | try { |
| 3162 | agent.onDestroy(); |
| 3163 | } catch (Exception e) { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 3164 | 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] | 3165 | e.printStackTrace(); |
| 3166 | } |
| 3167 | mBackupAgents.remove(packageName); |
| 3168 | } else { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 3169 | Slog.w(TAG, "Attempt to destroy unknown backup agent " + data); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3170 | } |
| 3171 | } |
| 3172 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3173 | private void handleCreateService(CreateServiceData data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3174 | // If we are getting ready to gc after going to the background, well |
| 3175 | // we are back active so skip it. |
| 3176 | unscheduleGcIdler(); |
| 3177 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3178 | LoadedApk packageInfo = getPackageInfoNoCheck( |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 3179 | data.info.applicationInfo, data.compatInfo); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3180 | Service service = null; |
| 3181 | try { |
| 3182 | java.lang.ClassLoader cl = packageInfo.getClassLoader(); |
| 3183 | service = (Service) cl.loadClass(data.info.name).newInstance(); |
| 3184 | } catch (Exception e) { |
| 3185 | if (!mInstrumentation.onException(service, e)) { |
| 3186 | throw new RuntimeException( |
| 3187 | "Unable to instantiate service " + data.info.name |
| 3188 | + ": " + e.toString(), e); |
| 3189 | } |
| 3190 | } |
| 3191 | |
| 3192 | try { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3193 | 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] | 3194 | |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 3195 | ContextImpl context = ContextImpl.createAppContext(this, packageInfo); |
| 3196 | context.setOuterContext(service); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3197 | |
Dianne Hackborn | 0be1f78 | 2009-11-09 12:30:12 -0800 | [diff] [blame] | 3198 | Application app = packageInfo.makeApplication(false, mInstrumentation); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3199 | service.attach(context, this, data.info.name, data.token, app, |
| 3200 | ActivityManagerNative.getDefault()); |
| 3201 | service.onCreate(); |
| 3202 | mServices.put(data.token, service); |
| 3203 | try { |
Dianne Hackborn | f6f9f2d | 2009-08-21 16:26:03 -0700 | [diff] [blame] | 3204 | ActivityManagerNative.getDefault().serviceDoneExecuting( |
Dianne Hackborn | 455625e | 2015-01-21 09:55:13 -0800 | [diff] [blame] | 3205 | data.token, SERVICE_DONE_EXECUTING_ANON, 0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3206 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3207 | throw e.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3208 | } |
| 3209 | } catch (Exception e) { |
| 3210 | if (!mInstrumentation.onException(service, e)) { |
| 3211 | throw new RuntimeException( |
| 3212 | "Unable to create service " + data.info.name |
| 3213 | + ": " + e.toString(), e); |
| 3214 | } |
| 3215 | } |
| 3216 | } |
| 3217 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3218 | private void handleBindService(BindServiceData data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3219 | Service s = mServices.get(data.token); |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 3220 | if (DEBUG_SERVICE) |
| 3221 | Slog.v(TAG, "handleBindService s=" + s + " rebind=" + data.rebind); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3222 | if (s != null) { |
| 3223 | try { |
| 3224 | data.intent.setExtrasClassLoader(s.getClassLoader()); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 3225 | data.intent.prepareToEnterProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3226 | try { |
| 3227 | if (!data.rebind) { |
| 3228 | IBinder binder = s.onBind(data.intent); |
| 3229 | ActivityManagerNative.getDefault().publishService( |
| 3230 | data.token, data.intent, binder); |
| 3231 | } else { |
| 3232 | s.onRebind(data.intent); |
| 3233 | ActivityManagerNative.getDefault().serviceDoneExecuting( |
Dianne Hackborn | 455625e | 2015-01-21 09:55:13 -0800 | [diff] [blame] | 3234 | data.token, SERVICE_DONE_EXECUTING_ANON, 0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3235 | } |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 3236 | ensureJitEnabled(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3237 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3238 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3239 | } |
| 3240 | } catch (Exception e) { |
| 3241 | if (!mInstrumentation.onException(s, e)) { |
| 3242 | throw new RuntimeException( |
| 3243 | "Unable to bind to service " + s |
| 3244 | + " with " + data.intent + ": " + e.toString(), e); |
| 3245 | } |
| 3246 | } |
| 3247 | } |
| 3248 | } |
| 3249 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3250 | private void handleUnbindService(BindServiceData data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3251 | Service s = mServices.get(data.token); |
| 3252 | if (s != null) { |
| 3253 | try { |
| 3254 | data.intent.setExtrasClassLoader(s.getClassLoader()); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 3255 | data.intent.prepareToEnterProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3256 | boolean doRebind = s.onUnbind(data.intent); |
| 3257 | try { |
| 3258 | if (doRebind) { |
| 3259 | ActivityManagerNative.getDefault().unbindFinished( |
| 3260 | data.token, data.intent, doRebind); |
| 3261 | } else { |
| 3262 | ActivityManagerNative.getDefault().serviceDoneExecuting( |
Dianne Hackborn | 455625e | 2015-01-21 09:55:13 -0800 | [diff] [blame] | 3263 | data.token, SERVICE_DONE_EXECUTING_ANON, 0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3264 | } |
| 3265 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3266 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3267 | } |
| 3268 | } catch (Exception e) { |
| 3269 | if (!mInstrumentation.onException(s, e)) { |
| 3270 | throw new RuntimeException( |
| 3271 | "Unable to unbind to service " + s |
| 3272 | + " with " + data.intent + ": " + e.toString(), e); |
| 3273 | } |
| 3274 | } |
| 3275 | } |
| 3276 | } |
| 3277 | |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 3278 | private void handleDumpService(DumpComponentInfo info) { |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3279 | final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); |
| 3280 | try { |
| 3281 | Service s = mServices.get(info.token); |
| 3282 | if (s != null) { |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 3283 | PrintWriter pw = new FastPrintWriter(new FileOutputStream( |
| 3284 | info.fd.getFileDescriptor())); |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3285 | s.dump(info.fd.getFileDescriptor(), pw, info.args); |
| 3286 | pw.flush(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3287 | } |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3288 | } finally { |
| 3289 | IoUtils.closeQuietly(info.fd); |
| 3290 | StrictMode.setThreadPolicy(oldPolicy); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3291 | } |
| 3292 | } |
| 3293 | |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 3294 | private void handleDumpActivity(DumpComponentInfo info) { |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3295 | final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); |
| 3296 | try { |
| 3297 | ActivityClientRecord r = mActivities.get(info.token); |
| 3298 | if (r != null && r.activity != null) { |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 3299 | PrintWriter pw = new FastPrintWriter(new FileOutputStream( |
| 3300 | info.fd.getFileDescriptor())); |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3301 | r.activity.dump(info.prefix, info.fd.getFileDescriptor(), pw, info.args); |
| 3302 | pw.flush(); |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 3303 | } |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3304 | } finally { |
| 3305 | IoUtils.closeQuietly(info.fd); |
| 3306 | StrictMode.setThreadPolicy(oldPolicy); |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 3307 | } |
| 3308 | } |
| 3309 | |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 3310 | private void handleDumpProvider(DumpComponentInfo info) { |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3311 | final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); |
| 3312 | try { |
| 3313 | ProviderClientRecord r = mLocalProviders.get(info.token); |
| 3314 | if (r != null && r.mLocalProvider != null) { |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 3315 | PrintWriter pw = new FastPrintWriter(new FileOutputStream( |
| 3316 | info.fd.getFileDescriptor())); |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3317 | r.mLocalProvider.dump(info.fd.getFileDescriptor(), pw, info.args); |
| 3318 | pw.flush(); |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 3319 | } |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3320 | } finally { |
| 3321 | IoUtils.closeQuietly(info.fd); |
| 3322 | StrictMode.setThreadPolicy(oldPolicy); |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 3323 | } |
| 3324 | } |
| 3325 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3326 | private void handleServiceArgs(ServiceArgsData data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3327 | Service s = mServices.get(data.token); |
| 3328 | if (s != null) { |
| 3329 | try { |
| 3330 | if (data.args != null) { |
| 3331 | data.args.setExtrasClassLoader(s.getClassLoader()); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 3332 | data.args.prepareToEnterProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3333 | } |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 3334 | int res; |
| 3335 | if (!data.taskRemoved) { |
| 3336 | res = s.onStartCommand(data.args, data.flags, data.startId); |
| 3337 | } else { |
| 3338 | s.onTaskRemoved(data.args); |
| 3339 | res = Service.START_TASK_REMOVED_COMPLETE; |
| 3340 | } |
Brad Fitzpatrick | 333b8cb | 2010-08-26 12:04:57 -0700 | [diff] [blame] | 3341 | |
| 3342 | QueuedWork.waitToFinish(); |
| 3343 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3344 | try { |
Dianne Hackborn | f6f9f2d | 2009-08-21 16:26:03 -0700 | [diff] [blame] | 3345 | ActivityManagerNative.getDefault().serviceDoneExecuting( |
Dianne Hackborn | 455625e | 2015-01-21 09:55:13 -0800 | [diff] [blame] | 3346 | data.token, SERVICE_DONE_EXECUTING_START, data.startId, res); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3347 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3348 | throw e.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3349 | } |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 3350 | ensureJitEnabled(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3351 | } catch (Exception e) { |
| 3352 | if (!mInstrumentation.onException(s, e)) { |
| 3353 | throw new RuntimeException( |
| 3354 | "Unable to start service " + s |
| 3355 | + " with " + data.args + ": " + e.toString(), e); |
| 3356 | } |
| 3357 | } |
| 3358 | } |
| 3359 | } |
| 3360 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3361 | private void handleStopService(IBinder token) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3362 | Service s = mServices.remove(token); |
| 3363 | if (s != null) { |
| 3364 | try { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3365 | if (localLOGV) Slog.v(TAG, "Destroying service " + s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3366 | s.onDestroy(); |
| 3367 | Context context = s.getBaseContext(); |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 3368 | if (context instanceof ContextImpl) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3369 | final String who = s.getClassName(); |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 3370 | ((ContextImpl) context).scheduleFinalCleanup(who, "Service"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3371 | } |
Brad Fitzpatrick | 333b8cb | 2010-08-26 12:04:57 -0700 | [diff] [blame] | 3372 | |
| 3373 | QueuedWork.waitToFinish(); |
| 3374 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3375 | try { |
Dianne Hackborn | f6f9f2d | 2009-08-21 16:26:03 -0700 | [diff] [blame] | 3376 | ActivityManagerNative.getDefault().serviceDoneExecuting( |
Dianne Hackborn | 455625e | 2015-01-21 09:55:13 -0800 | [diff] [blame] | 3377 | token, SERVICE_DONE_EXECUTING_STOP, 0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3378 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3379 | throw e.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3380 | } |
| 3381 | } catch (Exception e) { |
| 3382 | if (!mInstrumentation.onException(s, e)) { |
| 3383 | throw new RuntimeException( |
| 3384 | "Unable to stop service " + s |
| 3385 | + ": " + e.toString(), e); |
| 3386 | } |
Craig Mautner | 66c4a82 | 2015-01-16 12:48:16 -0800 | [diff] [blame] | 3387 | Slog.i(TAG, "handleStopService: exception for " + token, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3388 | } |
Craig Mautner | 9776ad4 | 2015-01-15 14:38:39 -0800 | [diff] [blame] | 3389 | } else { |
| 3390 | Slog.i(TAG, "handleStopService: token=" + token + " not found."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3391 | } |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3392 | //Slog.i(TAG, "Running services: " + mServices); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3393 | } |
| 3394 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3395 | public final ActivityClientRecord performResumeActivity(IBinder token, |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 3396 | boolean clearHide, String reason) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3397 | ActivityClientRecord r = mActivities.get(token); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3398 | if (localLOGV) Slog.v(TAG, "Performing resume of " + r |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3399 | + " finished=" + r.activity.mFinished); |
| 3400 | if (r != null && !r.activity.mFinished) { |
| 3401 | if (clearHide) { |
| 3402 | r.hideForNow = false; |
| 3403 | r.activity.mStartedActivity = false; |
| 3404 | } |
| 3405 | try { |
Dianne Hackborn | 6bdd3a1 | 2015-08-05 15:01:28 -0700 | [diff] [blame] | 3406 | r.activity.onStateNotSaved(); |
Dianne Hackborn | 689586d | 2012-10-01 18:23:04 -0700 | [diff] [blame] | 3407 | r.activity.mFragments.noteStateNotSaved(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3408 | if (r.pendingIntents != null) { |
| 3409 | deliverNewIntents(r, r.pendingIntents); |
| 3410 | r.pendingIntents = null; |
| 3411 | } |
| 3412 | if (r.pendingResults != null) { |
| 3413 | deliverResults(r, r.pendingResults); |
| 3414 | r.pendingResults = null; |
| 3415 | } |
| 3416 | r.activity.performResume(); |
| 3417 | |
Filip Gruszczynski | c3b6179 | 2016-01-22 16:43:48 -0800 | [diff] [blame] | 3418 | // If there is a pending local relaunch that was requested when the activity was |
| 3419 | // paused, it will put the activity into paused state when it finally happens. |
| 3420 | // Since the activity resumed before being relaunched, we don't want that to happen, |
| 3421 | // so we need to clear the request to relaunch paused. |
| 3422 | for (int i = mRelaunchingActivities.size() - 1; i >= 0; i--) { |
| 3423 | final ActivityClientRecord relaunching = mRelaunchingActivities.get(i); |
| 3424 | if (relaunching.token == r.token |
| 3425 | && relaunching.onlyLocalRequest && relaunching.startsNotResumed) { |
| 3426 | relaunching.startsNotResumed = false; |
| 3427 | } |
| 3428 | } |
| 3429 | |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 3430 | EventLog.writeEvent(LOG_AM_ON_RESUME_CALLED, UserHandle.myUserId(), |
| 3431 | r.activity.getComponentName().getClassName(), reason); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3432 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3433 | r.paused = false; |
| 3434 | r.stopped = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3435 | r.state = null; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3436 | r.persistentState = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3437 | } catch (Exception e) { |
| 3438 | if (!mInstrumentation.onException(r.activity, e)) { |
| 3439 | throw new RuntimeException( |
| 3440 | "Unable to resume activity " |
| 3441 | + r.intent.getComponent().toShortString() |
| 3442 | + ": " + e.toString(), e); |
| 3443 | } |
| 3444 | } |
| 3445 | } |
| 3446 | return r; |
| 3447 | } |
| 3448 | |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 3449 | static final void cleanUpPendingRemoveWindows(ActivityClientRecord r, boolean force) { |
| 3450 | if (r.mPreserveWindow && !force) { |
| 3451 | return; |
| 3452 | } |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 3453 | if (r.mPendingRemoveWindow != null) { |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 3454 | r.mPendingRemoveWindowManager.removeViewImmediate( |
| 3455 | r.mPendingRemoveWindow.getDecorView()); |
| 3456 | IBinder wtoken = r.mPendingRemoveWindow.getDecorView().getWindowToken(); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 3457 | if (wtoken != null) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 3458 | WindowManagerGlobal.getInstance().closeAll(wtoken, |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 3459 | r.activity.getClass().getName(), "Activity"); |
| 3460 | } |
| 3461 | } |
| 3462 | r.mPendingRemoveWindow = null; |
| 3463 | r.mPendingRemoveWindowManager = null; |
| 3464 | } |
| 3465 | |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 3466 | final void handleResumeActivity(IBinder token, |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 3467 | boolean clearHide, boolean isForward, boolean reallyResume, int seq, String reason) { |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 3468 | ActivityClientRecord r = mActivities.get(token); |
| 3469 | if (!checkAndUpdateLifecycleSeq(seq, r, "resumeActivity")) { |
| 3470 | return; |
| 3471 | } |
| 3472 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3473 | // If we are getting ready to gc after going to the background, well |
| 3474 | // we are back active so skip it. |
| 3475 | unscheduleGcIdler(); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3476 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3477 | |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 3478 | // TODO Push resumeArgs into the activity for consideration |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 3479 | r = performResumeActivity(token, clearHide, reason); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3480 | |
| 3481 | if (r != null) { |
| 3482 | final Activity a = r.activity; |
| 3483 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3484 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3485 | TAG, "Resume " + r + " started activity: " + |
| 3486 | a.mStartedActivity + ", hideForNow: " + r.hideForNow |
| 3487 | + ", finished: " + a.mFinished); |
| 3488 | |
| 3489 | final int forwardBit = isForward ? |
| 3490 | WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION : 0; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3491 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3492 | // If the window hasn't yet been added to the window manager, |
| 3493 | // and this guy didn't finish itself or start another activity, |
| 3494 | // then go ahead and add the window. |
Dianne Hackborn | 061d58a | 2010-03-12 15:07:06 -0800 | [diff] [blame] | 3495 | boolean willBeVisible = !a.mStartedActivity; |
| 3496 | if (!willBeVisible) { |
| 3497 | try { |
| 3498 | willBeVisible = ActivityManagerNative.getDefault().willActivityBeVisible( |
| 3499 | a.getActivityToken()); |
| 3500 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3501 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 061d58a | 2010-03-12 15:07:06 -0800 | [diff] [blame] | 3502 | } |
| 3503 | } |
| 3504 | if (r.window == null && !a.mFinished && willBeVisible) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3505 | r.window = r.activity.getWindow(); |
| 3506 | View decor = r.window.getDecorView(); |
| 3507 | decor.setVisibility(View.INVISIBLE); |
| 3508 | ViewManager wm = a.getWindowManager(); |
| 3509 | WindowManager.LayoutParams l = r.window.getAttributes(); |
| 3510 | a.mDecor = decor; |
| 3511 | l.type = WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
| 3512 | l.softInputMode |= forwardBit; |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 3513 | if (r.mPreserveWindow) { |
| 3514 | a.mWindowAdded = true; |
| 3515 | r.mPreserveWindow = false; |
Robert Carr | b259485 | 2016-04-25 16:21:13 -0700 | [diff] [blame] | 3516 | // Normally the ViewRoot sets up callbacks with the Activity |
| 3517 | // in addView->ViewRootImpl#setView. If we are instead reusing |
| 3518 | // the decor view we have to notify the view root that the |
| 3519 | // callbacks may have changed. |
| 3520 | ViewRootImpl impl = decor.getViewRootImpl(); |
Robert Carr | 311ecba | 2016-04-27 12:59:45 -0700 | [diff] [blame] | 3521 | if (impl != null) { |
| 3522 | impl.notifyChildRebuilt(); |
| 3523 | } |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 3524 | } |
| 3525 | if (a.mVisibleFromClient && !a.mWindowAdded) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3526 | a.mWindowAdded = true; |
| 3527 | wm.addView(decor, l); |
| 3528 | } |
| 3529 | |
| 3530 | // If the window has already been added, but during resume |
| 3531 | // we started another activity, then don't yet make the |
Dianne Hackborn | 061d58a | 2010-03-12 15:07:06 -0800 | [diff] [blame] | 3532 | // window visible. |
| 3533 | } else if (!willBeVisible) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3534 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3535 | TAG, "Launch " + r + " mStartedActivity set"); |
| 3536 | r.hideForNow = true; |
| 3537 | } |
| 3538 | |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 3539 | // Get rid of anything left hanging around. |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 3540 | cleanUpPendingRemoveWindows(r, false /* force */); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 3541 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3542 | // The window is now visible if it has been added, we are not |
| 3543 | // simply finishing, and we are not starting another activity. |
Dianne Hackborn | 061d58a | 2010-03-12 15:07:06 -0800 | [diff] [blame] | 3544 | if (!r.activity.mFinished && willBeVisible |
Dianne Hackborn | c1e605e | 2009-09-25 17:18:15 -0700 | [diff] [blame] | 3545 | && r.activity.mDecor != null && !r.hideForNow) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3546 | if (r.newConfig != null) { |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 3547 | performConfigurationChangedForActivity(r, r.newConfig, REPORT_TO_ACTIVITY); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3548 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Resuming activity " |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 3549 | + r.activityInfo.name + " with newConfig " + r.activity.mCurrentConfig); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3550 | r.newConfig = null; |
| 3551 | } |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3552 | if (localLOGV) Slog.v(TAG, "Resuming " + r + " with isForward=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3553 | + isForward); |
| 3554 | WindowManager.LayoutParams l = r.window.getAttributes(); |
| 3555 | if ((l.softInputMode |
| 3556 | & WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) |
| 3557 | != forwardBit) { |
| 3558 | l.softInputMode = (l.softInputMode |
| 3559 | & (~WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION)) |
| 3560 | | forwardBit; |
Dianne Hackborn | c1e605e | 2009-09-25 17:18:15 -0700 | [diff] [blame] | 3561 | if (r.activity.mVisibleFromClient) { |
| 3562 | ViewManager wm = a.getWindowManager(); |
| 3563 | View decor = r.window.getDecorView(); |
| 3564 | wm.updateViewLayout(decor, l); |
| 3565 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3566 | } |
| 3567 | r.activity.mVisibleFromServer = true; |
| 3568 | mNumVisibleActivities++; |
| 3569 | if (r.activity.mVisibleFromClient) { |
| 3570 | r.activity.makeVisible(); |
| 3571 | } |
| 3572 | } |
| 3573 | |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 3574 | if (!r.onlyLocalRequest) { |
| 3575 | r.nextIdle = mNewActivities; |
| 3576 | mNewActivities = r; |
| 3577 | if (localLOGV) Slog.v( |
| 3578 | TAG, "Scheduling idle handler for " + r); |
| 3579 | Looper.myQueue().addIdleHandler(new Idler()); |
| 3580 | } |
| 3581 | r.onlyLocalRequest = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3582 | |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 3583 | // Tell the activity manager we have resumed. |
| 3584 | if (reallyResume) { |
| 3585 | try { |
| 3586 | ActivityManagerNative.getDefault().activityResumed(token); |
| 3587 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3588 | throw ex.rethrowFromSystemServer(); |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 3589 | } |
| 3590 | } |
| 3591 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3592 | } else { |
| 3593 | // If an exception was thrown when trying to resume, then |
| 3594 | // just end this activity. |
| 3595 | try { |
| 3596 | ActivityManagerNative.getDefault() |
Wale Ogunwale | ba7881c | 2015-08-01 19:28:29 -0700 | [diff] [blame] | 3597 | .finishActivity(token, Activity.RESULT_CANCELED, null, |
| 3598 | Activity.DONT_FINISH_TASK_WITH_ACTIVITY); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3599 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3600 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3601 | } |
| 3602 | } |
| 3603 | } |
| 3604 | |
| 3605 | private int mThumbnailWidth = -1; |
| 3606 | private int mThumbnailHeight = -1; |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3607 | private Bitmap mAvailThumbnailBitmap = null; |
| 3608 | private Canvas mThumbnailCanvas = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3609 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3610 | private Bitmap createThumbnailBitmap(ActivityClientRecord r) { |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3611 | Bitmap thumbnail = mAvailThumbnailBitmap; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3612 | try { |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3613 | if (thumbnail == null) { |
| 3614 | int w = mThumbnailWidth; |
| 3615 | int h; |
| 3616 | if (w < 0) { |
| 3617 | Resources res = r.activity.getResources(); |
Winson Chung | 6784f1c | 2014-05-22 11:22:41 -0700 | [diff] [blame] | 3618 | int wId = com.android.internal.R.dimen.thumbnail_width; |
| 3619 | int hId = com.android.internal.R.dimen.thumbnail_height; |
Winson Chung | fd08622 | 2014-05-13 15:49:42 -0700 | [diff] [blame] | 3620 | mThumbnailWidth = w = res.getDimensionPixelSize(wId); |
| 3621 | mThumbnailHeight = h = res.getDimensionPixelSize(hId); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3622 | } else { |
| 3623 | h = mThumbnailHeight; |
| 3624 | } |
| 3625 | |
| 3626 | // On platforms where we don't want thumbnails, set dims to (0,0) |
| 3627 | if ((w > 0) && (h > 0)) { |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 3628 | thumbnail = Bitmap.createBitmap(r.activity.getResources().getDisplayMetrics(), |
| 3629 | w, h, THUMBNAIL_FORMAT); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3630 | thumbnail.eraseColor(0); |
| 3631 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3632 | } |
| 3633 | |
Dianne Hackborn | fb3806d | 2010-12-09 13:14:12 -0800 | [diff] [blame] | 3634 | if (thumbnail != null) { |
| 3635 | Canvas cv = mThumbnailCanvas; |
| 3636 | if (cv == null) { |
| 3637 | mThumbnailCanvas = cv = new Canvas(); |
| 3638 | } |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 3639 | |
Dianne Hackborn | fb3806d | 2010-12-09 13:14:12 -0800 | [diff] [blame] | 3640 | cv.setBitmap(thumbnail); |
| 3641 | if (!r.activity.onCreateThumbnail(thumbnail, cv)) { |
| 3642 | mAvailThumbnailBitmap = thumbnail; |
| 3643 | thumbnail = null; |
| 3644 | } |
Dianne Hackborn | 6311d0a | 2011-08-02 16:37:58 -0700 | [diff] [blame] | 3645 | cv.setBitmap(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3646 | } |
Jim Miller | 0b2a6d0 | 2010-07-13 18:01:29 -0700 | [diff] [blame] | 3647 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3648 | } catch (Exception e) { |
| 3649 | if (!mInstrumentation.onException(r.activity, e)) { |
| 3650 | throw new RuntimeException( |
| 3651 | "Unable to create thumbnail of " |
| 3652 | + r.intent.getComponent().toShortString() |
| 3653 | + ": " + e.toString(), e); |
| 3654 | } |
| 3655 | thumbnail = null; |
| 3656 | } |
| 3657 | |
| 3658 | return thumbnail; |
| 3659 | } |
| 3660 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3661 | private void handlePauseActivity(IBinder token, boolean finished, |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 3662 | boolean userLeaving, int configChanges, boolean dontReport, int seq) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3663 | ActivityClientRecord r = mActivities.get(token); |
Filip Gruszczynski | c3b6179 | 2016-01-22 16:43:48 -0800 | [diff] [blame] | 3664 | if (DEBUG_ORDER) Slog.d(TAG, "handlePauseActivity " + r + ", seq: " + seq); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 3665 | if (!checkAndUpdateLifecycleSeq(seq, r, "pauseActivity")) { |
| 3666 | return; |
| 3667 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3668 | if (r != null) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3669 | //Slog.v(TAG, "userLeaving=" + userLeaving + " handling pause of " + r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3670 | if (userLeaving) { |
| 3671 | performUserLeavingActivity(r); |
| 3672 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3673 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3674 | r.activity.mConfigChangeFlags |= configChanges; |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 3675 | performPauseActivity(token, finished, r.isPreHoneycomb(), "handlePauseActivity"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3676 | |
Dianne Hackborn | aa93bcd | 2010-10-27 13:57:00 -0700 | [diff] [blame] | 3677 | // Make sure any pending writes are now committed. |
Dianne Hackborn | 5d9d03a | 2011-01-24 13:15:09 -0800 | [diff] [blame] | 3678 | if (r.isPreHoneycomb()) { |
| 3679 | QueuedWork.waitToFinish(); |
| 3680 | } |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 3681 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3682 | // Tell the activity manager we have paused. |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 3683 | if (!dontReport) { |
| 3684 | try { |
| 3685 | ActivityManagerNative.getDefault().activityPaused(token); |
| 3686 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3687 | throw ex.rethrowFromSystemServer(); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 3688 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3689 | } |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3690 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3691 | } |
| 3692 | } |
| 3693 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3694 | final void performUserLeavingActivity(ActivityClientRecord r) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3695 | mInstrumentation.callActivityOnUserLeaving(r.activity); |
| 3696 | } |
| 3697 | |
| 3698 | final Bundle performPauseActivity(IBinder token, boolean finished, |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 3699 | boolean saveState, String reason) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3700 | ActivityClientRecord r = mActivities.get(token); |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 3701 | return r != null ? performPauseActivity(r, finished, saveState, reason) : null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3702 | } |
| 3703 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3704 | final Bundle performPauseActivity(ActivityClientRecord r, boolean finished, |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 3705 | boolean saveState, String reason) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3706 | if (r.paused) { |
| 3707 | if (r.activity.mFinished) { |
| 3708 | // If we are finishing, we won't call onResume() in certain cases. |
| 3709 | // So here we likewise don't want to call onPause() if the activity |
| 3710 | // isn't resumed. |
| 3711 | return null; |
| 3712 | } |
| 3713 | RuntimeException e = new RuntimeException( |
| 3714 | "Performing pause of activity that is not resumed: " |
| 3715 | + r.intent.getComponent().toShortString()); |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 3716 | Slog.e(TAG, e.getMessage(), e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3717 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3718 | if (finished) { |
| 3719 | r.activity.mFinished = true; |
| 3720 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3721 | |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 3722 | // Next have the activity save its current state and managed dialogs... |
| 3723 | if (!r.activity.mFinished && saveState) { |
| 3724 | callCallActivityOnSaveInstanceState(r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3725 | } |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 3726 | |
| 3727 | performPauseActivityIfNeeded(r, reason); |
Jeff Hamilton | 52d3203 | 2011-01-08 15:31:26 -0600 | [diff] [blame] | 3728 | |
| 3729 | // Notify any outstanding on paused listeners |
| 3730 | ArrayList<OnActivityPausedListener> listeners; |
| 3731 | synchronized (mOnPauseListeners) { |
| 3732 | listeners = mOnPauseListeners.remove(r.activity); |
| 3733 | } |
| 3734 | int size = (listeners != null ? listeners.size() : 0); |
| 3735 | for (int i = 0; i < size; i++) { |
| 3736 | listeners.get(i).onPaused(r.activity); |
| 3737 | } |
| 3738 | |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3739 | return !r.activity.mFinished && saveState ? r.state : null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3740 | } |
| 3741 | |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 3742 | private void performPauseActivityIfNeeded(ActivityClientRecord r, String reason) { |
| 3743 | if (r.paused) { |
| 3744 | // You are already paused silly... |
| 3745 | return; |
| 3746 | } |
| 3747 | |
| 3748 | try { |
| 3749 | r.activity.mCalled = false; |
| 3750 | mInstrumentation.callActivityOnPause(r.activity); |
| 3751 | EventLog.writeEvent(LOG_AM_ON_PAUSE_CALLED, UserHandle.myUserId(), |
| 3752 | r.activity.getComponentName().getClassName(), reason); |
| 3753 | if (!r.activity.mCalled) { |
| 3754 | throw new SuperNotCalledException("Activity " + safeToComponentShortString(r.intent) |
| 3755 | + " did not call through to super.onPause()"); |
| 3756 | } |
| 3757 | } catch (SuperNotCalledException e) { |
| 3758 | throw e; |
| 3759 | } catch (Exception e) { |
| 3760 | if (!mInstrumentation.onException(r.activity, e)) { |
| 3761 | throw new RuntimeException("Unable to pause activity " |
| 3762 | + safeToComponentShortString(r.intent) + ": " + e.toString(), e); |
| 3763 | } |
| 3764 | } |
| 3765 | r.paused = true; |
| 3766 | } |
| 3767 | |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 3768 | final void performStopActivity(IBinder token, boolean saveState, String reason) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3769 | ActivityClientRecord r = mActivities.get(token); |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 3770 | performStopActivityInner(r, null, false, saveState, reason); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3771 | } |
| 3772 | |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 3773 | private static class StopInfo implements Runnable { |
| 3774 | ActivityClientRecord activity; |
| 3775 | Bundle state; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3776 | PersistableBundle persistentState; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3777 | CharSequence description; |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 3778 | |
| 3779 | @Override public void run() { |
| 3780 | // Tell activity manager we have been stopped. |
| 3781 | try { |
| 3782 | if (DEBUG_MEMORY_TRIM) Slog.v(TAG, "Reporting activity stopped: " + activity); |
| 3783 | ActivityManagerNative.getDefault().activityStopped( |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3784 | activity.token, state, persistentState, description); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 3785 | } catch (RemoteException ex) { |
Jeff Sharkey | 369f509 | 2016-02-29 11:16:21 -0700 | [diff] [blame] | 3786 | if (ex instanceof TransactionTooLargeException |
Jeff Sharkey | 9ad8613 | 2016-03-01 11:22:59 -0700 | [diff] [blame] | 3787 | && activity.packageInfo.getTargetSdkVersion() < Build.VERSION_CODES.N) { |
Jeff Sharkey | b8e8a91 | 2016-03-09 16:27:40 -0700 | [diff] [blame] | 3788 | 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] | 3789 | return; |
| 3790 | } |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3791 | throw ex.rethrowFromSystemServer(); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 3792 | } |
| 3793 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3794 | } |
| 3795 | |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 3796 | private static final class ProviderRefCount { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 3797 | public final IActivityManager.ContentProviderHolder holder; |
| 3798 | public final ProviderClientRecord client; |
| 3799 | public int stableCount; |
| 3800 | public int unstableCount; |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 3801 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 3802 | // When this is set, the stable and unstable ref counts are 0 and |
| 3803 | // we have a pending operation scheduled to remove the ref count |
| 3804 | // from the activity manager. On the activity manager we are still |
| 3805 | // holding an unstable ref, though it is not reflected in the counts |
| 3806 | // here. |
| 3807 | public boolean removePending; |
| 3808 | |
| 3809 | ProviderRefCount(IActivityManager.ContentProviderHolder inHolder, |
| 3810 | ProviderClientRecord inClient, int sCount, int uCount) { |
| 3811 | holder = inHolder; |
| 3812 | client = inClient; |
| 3813 | stableCount = sCount; |
| 3814 | unstableCount = uCount; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3815 | } |
| 3816 | } |
| 3817 | |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3818 | /** |
| 3819 | * Core implementation of stopping an activity. Note this is a little |
| 3820 | * tricky because the server's meaning of stop is slightly different |
| 3821 | * than our client -- for the server, stop means to save state and give |
| 3822 | * it the result when it is done, but the window may still be visible. |
| 3823 | * For the client, we want to call onStop()/onStart() to indicate when |
Wale Ogunwale | b5066fe | 2016-09-21 07:33:43 -0700 | [diff] [blame] | 3824 | * the activity's UI visibility changes. |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3825 | */ |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3826 | private void performStopActivityInner(ActivityClientRecord r, |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 3827 | StopInfo info, boolean keepShown, boolean saveState, String reason) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3828 | if (localLOGV) Slog.v(TAG, "Performing stop of " + r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3829 | if (r != null) { |
| 3830 | if (!keepShown && r.stopped) { |
| 3831 | if (r.activity.mFinished) { |
| 3832 | // If we are finishing, we won't call onResume() in certain |
| 3833 | // cases. So here we likewise don't want to call onStop() |
| 3834 | // if the activity isn't resumed. |
| 3835 | return; |
| 3836 | } |
| 3837 | RuntimeException e = new RuntimeException( |
Andrii Kulian | 58178f2 | 2016-03-16 13:44:56 -0700 | [diff] [blame] | 3838 | "Performing stop of activity that is already stopped: " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3839 | + r.intent.getComponent().toShortString()); |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 3840 | Slog.e(TAG, e.getMessage(), e); |
Andrii Kulian | 58178f2 | 2016-03-16 13:44:56 -0700 | [diff] [blame] | 3841 | Slog.e(TAG, r.getStateString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3842 | } |
| 3843 | |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 3844 | // One must first be paused before stopped... |
| 3845 | performPauseActivityIfNeeded(r, reason); |
| 3846 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3847 | if (info != null) { |
| 3848 | try { |
| 3849 | // First create a thumbnail for the activity... |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3850 | // For now, don't create the thumbnail here; we are |
| 3851 | // doing that by doing a screen snapshot. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3852 | info.description = r.activity.onCreateDescription(); |
| 3853 | } catch (Exception e) { |
| 3854 | if (!mInstrumentation.onException(r.activity, e)) { |
| 3855 | throw new RuntimeException( |
| 3856 | "Unable to save state of activity " |
| 3857 | + r.intent.getComponent().toShortString() |
| 3858 | + ": " + e.toString(), e); |
| 3859 | } |
| 3860 | } |
| 3861 | } |
| 3862 | |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3863 | // Next have the activity save its current state and managed dialogs... |
| 3864 | if (!r.activity.mFinished && saveState) { |
| 3865 | if (r.state == null) { |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3866 | callCallActivityOnSaveInstanceState(r); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3867 | } |
| 3868 | } |
| 3869 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3870 | if (!keepShown) { |
| 3871 | try { |
| 3872 | // Now we are idle. |
Chong Zhang | 7687f25 | 2016-02-26 12:03:33 -0800 | [diff] [blame] | 3873 | r.activity.performStop(false /*preserveWindow*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3874 | } catch (Exception e) { |
| 3875 | if (!mInstrumentation.onException(r.activity, e)) { |
| 3876 | throw new RuntimeException( |
| 3877 | "Unable to stop activity " |
| 3878 | + r.intent.getComponent().toShortString() |
| 3879 | + ": " + e.toString(), e); |
| 3880 | } |
| 3881 | } |
| 3882 | r.stopped = true; |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 3883 | EventLog.writeEvent(LOG_AM_ON_STOP_CALLED, UserHandle.myUserId(), |
| 3884 | r.activity.getComponentName().getClassName(), reason); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3885 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3886 | } |
| 3887 | } |
| 3888 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3889 | private void updateVisibility(ActivityClientRecord r, boolean show) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3890 | View v = r.activity.mDecor; |
| 3891 | if (v != null) { |
| 3892 | if (show) { |
| 3893 | if (!r.activity.mVisibleFromServer) { |
| 3894 | r.activity.mVisibleFromServer = true; |
| 3895 | mNumVisibleActivities++; |
| 3896 | if (r.activity.mVisibleFromClient) { |
| 3897 | r.activity.makeVisible(); |
| 3898 | } |
| 3899 | } |
| 3900 | if (r.newConfig != null) { |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 3901 | performConfigurationChangedForActivity(r, r.newConfig, REPORT_TO_ACTIVITY); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3902 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Updating activity vis " |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 3903 | + r.activityInfo.name + " with new config " |
| 3904 | + r.activity.mCurrentConfig); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3905 | r.newConfig = null; |
| 3906 | } |
| 3907 | } else { |
| 3908 | if (r.activity.mVisibleFromServer) { |
| 3909 | r.activity.mVisibleFromServer = false; |
| 3910 | mNumVisibleActivities--; |
| 3911 | v.setVisibility(View.INVISIBLE); |
| 3912 | } |
| 3913 | } |
| 3914 | } |
| 3915 | } |
| 3916 | |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 3917 | private void handleStopActivity(IBinder token, boolean show, int configChanges, int seq) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3918 | ActivityClientRecord r = mActivities.get(token); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 3919 | if (!checkAndUpdateLifecycleSeq(seq, r, "stopActivity")) { |
| 3920 | return; |
| 3921 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3922 | r.activity.mConfigChangeFlags |= configChanges; |
| 3923 | |
| 3924 | StopInfo info = new StopInfo(); |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 3925 | performStopActivityInner(r, info, show, true, "handleStopActivity"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3926 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3927 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3928 | TAG, "Finishing stop of " + r + ": show=" + show |
| 3929 | + " win=" + r.window); |
| 3930 | |
| 3931 | updateVisibility(r, show); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3932 | |
Dianne Hackborn | 5d9d03a | 2011-01-24 13:15:09 -0800 | [diff] [blame] | 3933 | // Make sure any pending writes are now committed. |
| 3934 | if (!r.isPreHoneycomb()) { |
| 3935 | QueuedWork.waitToFinish(); |
| 3936 | } |
| 3937 | |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 3938 | // Schedule the call to tell the activity manager we have |
| 3939 | // stopped. We don't do this immediately, because we want to |
| 3940 | // have a chance for any other pending work (in particular memory |
| 3941 | // trim requests) to complete before you tell the activity |
| 3942 | // manager to proceed and allow us to go fully into the background. |
| 3943 | info.activity = r; |
| 3944 | info.state = r.state; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3945 | info.persistentState = r.persistentState; |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 3946 | mH.post(info); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3947 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3948 | } |
| 3949 | |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 3950 | private static boolean checkAndUpdateLifecycleSeq(int seq, ActivityClientRecord r, |
| 3951 | String action) { |
| 3952 | if (r == null) { |
| 3953 | return true; |
| 3954 | } |
| 3955 | if (seq < r.lastProcessedSeq) { |
| 3956 | if (DEBUG_ORDER) Slog.d(TAG, action + " for " + r + " ignored, because seq=" + seq |
| 3957 | + " < mCurrentLifecycleSeq=" + r.lastProcessedSeq); |
| 3958 | return false; |
| 3959 | } |
| 3960 | r.lastProcessedSeq = seq; |
| 3961 | return true; |
| 3962 | } |
| 3963 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3964 | final void performRestartActivity(IBinder token) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3965 | ActivityClientRecord r = mActivities.get(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3966 | if (r.stopped) { |
| 3967 | r.activity.performRestart(); |
| 3968 | r.stopped = false; |
| 3969 | } |
| 3970 | } |
| 3971 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3972 | private void handleWindowVisibility(IBinder token, boolean show) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3973 | ActivityClientRecord r = mActivities.get(token); |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 3974 | |
Dianne Hackborn | bfddc0f | 2010-12-14 11:28:01 -0800 | [diff] [blame] | 3975 | if (r == null) { |
| 3976 | Log.w(TAG, "handleWindowVisibility: no activity for token " + token); |
| 3977 | return; |
| 3978 | } |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 3979 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3980 | if (!show && !r.stopped) { |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 3981 | performStopActivityInner(r, null, show, false, "handleWindowVisibility"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3982 | } else if (show && r.stopped) { |
| 3983 | // If we are getting ready to gc after going to the background, well |
| 3984 | // we are back active so skip it. |
| 3985 | unscheduleGcIdler(); |
| 3986 | |
| 3987 | r.activity.performRestart(); |
| 3988 | r.stopped = false; |
| 3989 | } |
| 3990 | if (r.activity.mDecor != null) { |
Joe Onorato | 43a1765 | 2011-04-06 19:22:23 -0700 | [diff] [blame] | 3991 | if (false) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3992 | TAG, "Handle window " + r + " visibility: " + show); |
| 3993 | updateVisibility(r, show); |
| 3994 | } |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3995 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3996 | } |
| 3997 | |
Wale Ogunwale | b5066fe | 2016-09-21 07:33:43 -0700 | [diff] [blame] | 3998 | // TODO: This method should be changed to use {@link #performStopActivityInner} to perform to |
| 3999 | // stop operation on the activity to reduce code duplication and the chance of fixing a bug in |
| 4000 | // one place and missing the other. |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 4001 | private void handleSleeping(IBinder token, boolean sleeping) { |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 4002 | ActivityClientRecord r = mActivities.get(token); |
| 4003 | |
| 4004 | if (r == null) { |
Dianne Hackborn | 842e04b | 2011-01-22 13:00:12 -0800 | [diff] [blame] | 4005 | Log.w(TAG, "handleSleeping: no activity for token " + token); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 4006 | return; |
| 4007 | } |
| 4008 | |
| 4009 | if (sleeping) { |
Dianne Hackborn | 842e04b | 2011-01-22 13:00:12 -0800 | [diff] [blame] | 4010 | if (!r.stopped && !r.isPreHoneycomb()) { |
Wale Ogunwale | b5066fe | 2016-09-21 07:33:43 -0700 | [diff] [blame] | 4011 | if (!r.activity.mFinished && r.state == null) { |
| 4012 | callCallActivityOnSaveInstanceState(r); |
| 4013 | } |
| 4014 | |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 4015 | try { |
| 4016 | // Now we are idle. |
Chong Zhang | 7687f25 | 2016-02-26 12:03:33 -0800 | [diff] [blame] | 4017 | r.activity.performStop(false /*preserveWindow*/); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 4018 | } catch (Exception e) { |
| 4019 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4020 | throw new RuntimeException( |
| 4021 | "Unable to stop activity " |
| 4022 | + r.intent.getComponent().toShortString() |
| 4023 | + ": " + e.toString(), e); |
| 4024 | } |
| 4025 | } |
| 4026 | r.stopped = true; |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 4027 | EventLog.writeEvent(LOG_AM_ON_STOP_CALLED, UserHandle.myUserId(), |
| 4028 | r.activity.getComponentName().getClassName(), "sleeping"); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 4029 | } |
Dianne Hackborn | 5d9d03a | 2011-01-24 13:15:09 -0800 | [diff] [blame] | 4030 | |
| 4031 | // Make sure any pending writes are now committed. |
| 4032 | if (!r.isPreHoneycomb()) { |
| 4033 | QueuedWork.waitToFinish(); |
| 4034 | } |
| 4035 | |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 4036 | // Tell activity manager we slept. |
| 4037 | try { |
| 4038 | ActivityManagerNative.getDefault().activitySlept(r.token); |
| 4039 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4040 | throw ex.rethrowFromSystemServer(); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 4041 | } |
| 4042 | } else { |
| 4043 | if (r.stopped && r.activity.mVisibleFromServer) { |
| 4044 | r.activity.performRestart(); |
| 4045 | r.stopped = false; |
| 4046 | } |
| 4047 | } |
| 4048 | } |
| 4049 | |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 4050 | private void handleSetCoreSettings(Bundle coreSettings) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4051 | synchronized (mResourcesManager) { |
Svetoslav Ganov | 9aa597e | 2011-03-03 18:17:41 -0800 | [diff] [blame] | 4052 | mCoreSettings = coreSettings; |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 4053 | } |
Jon Miranda | 836c0a8 | 2014-08-11 12:32:26 -0700 | [diff] [blame] | 4054 | onCoreSettingsChange(); |
| 4055 | } |
| 4056 | |
| 4057 | private void onCoreSettingsChange() { |
| 4058 | boolean debugViewAttributes = |
| 4059 | mCoreSettings.getInt(Settings.Global.DEBUG_VIEW_ATTRIBUTES, 0) != 0; |
| 4060 | if (debugViewAttributes != View.mDebugViewAttributes) { |
| 4061 | View.mDebugViewAttributes = debugViewAttributes; |
| 4062 | |
| 4063 | // request all activities to relaunch for the changes to take place |
| 4064 | for (Map.Entry<IBinder, ActivityClientRecord> entry : mActivities.entrySet()) { |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4065 | requestRelaunchActivity(entry.getKey(), null, null, 0, false, null, null, false, |
| 4066 | false /* preserveWindow */); |
Jon Miranda | 836c0a8 | 2014-08-11 12:32:26 -0700 | [diff] [blame] | 4067 | } |
| 4068 | } |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 4069 | } |
| 4070 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4071 | private void handleUpdatePackageCompatibilityInfo(UpdateCompatibilityData data) { |
| 4072 | LoadedApk apk = peekPackageInfo(data.pkg, false); |
| 4073 | if (apk != null) { |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 4074 | apk.setCompatibilityInfo(data.info); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4075 | } |
| 4076 | apk = peekPackageInfo(data.pkg, true); |
| 4077 | if (apk != null) { |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 4078 | apk.setCompatibilityInfo(data.info); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4079 | } |
| 4080 | handleConfigurationChanged(mConfiguration, data.info); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 4081 | WindowManagerGlobal.getInstance().reportNewConfiguration(mConfiguration); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4082 | } |
| 4083 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 4084 | private void deliverResults(ActivityClientRecord r, List<ResultInfo> results) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4085 | final int N = results.size(); |
| 4086 | for (int i=0; i<N; i++) { |
| 4087 | ResultInfo ri = results.get(i); |
| 4088 | try { |
| 4089 | if (ri.mData != null) { |
| 4090 | ri.mData.setExtrasClassLoader(r.activity.getClassLoader()); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 4091 | ri.mData.prepareToEnterProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4092 | } |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4093 | if (DEBUG_RESULTS) Slog.v(TAG, |
Chris Tate | 8a7dc17 | 2009-03-24 20:11:42 -0700 | [diff] [blame] | 4094 | "Delivering result to activity " + r + " : " + ri); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4095 | r.activity.dispatchActivityResult(ri.mResultWho, |
| 4096 | ri.mRequestCode, ri.mResultCode, ri.mData); |
| 4097 | } catch (Exception e) { |
| 4098 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4099 | throw new RuntimeException( |
| 4100 | "Failure delivering result " + ri + " to activity " |
| 4101 | + r.intent.getComponent().toShortString() |
| 4102 | + ": " + e.toString(), e); |
| 4103 | } |
| 4104 | } |
| 4105 | } |
| 4106 | } |
| 4107 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 4108 | private void handleSendResult(ResultData res) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4109 | ActivityClientRecord r = mActivities.get(res.token); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4110 | 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] | 4111 | if (r != null) { |
| 4112 | final boolean resumed = !r.paused; |
| 4113 | if (!r.activity.mFinished && r.activity.mDecor != null |
| 4114 | && r.hideForNow && resumed) { |
| 4115 | // We had hidden the activity because it started another |
| 4116 | // one... we have gotten a result back and we are not |
| 4117 | // paused, so make sure our window is visible. |
| 4118 | updateVisibility(r, true); |
| 4119 | } |
| 4120 | if (resumed) { |
| 4121 | try { |
| 4122 | // Now we are idle. |
| 4123 | r.activity.mCalled = false; |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 4124 | r.activity.mTemporaryPause = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4125 | mInstrumentation.callActivityOnPause(r.activity); |
| 4126 | if (!r.activity.mCalled) { |
| 4127 | throw new SuperNotCalledException( |
| 4128 | "Activity " + r.intent.getComponent().toShortString() |
| 4129 | + " did not call through to super.onPause()"); |
| 4130 | } |
| 4131 | } catch (SuperNotCalledException e) { |
| 4132 | throw e; |
| 4133 | } catch (Exception e) { |
| 4134 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4135 | throw new RuntimeException( |
| 4136 | "Unable to pause activity " |
| 4137 | + r.intent.getComponent().toShortString() |
| 4138 | + ": " + e.toString(), e); |
| 4139 | } |
| 4140 | } |
| 4141 | } |
| 4142 | deliverResults(r, res.results); |
| 4143 | if (resumed) { |
Dianne Hackborn | b46ed76 | 2011-06-02 18:33:15 -0700 | [diff] [blame] | 4144 | r.activity.performResume(); |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 4145 | r.activity.mTemporaryPause = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4146 | } |
| 4147 | } |
| 4148 | } |
| 4149 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4150 | public final ActivityClientRecord performDestroyActivity(IBinder token, boolean finishing) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4151 | return performDestroyActivity(token, finishing, 0, false); |
| 4152 | } |
| 4153 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 4154 | private ActivityClientRecord performDestroyActivity(IBinder token, boolean finishing, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4155 | int configChanges, boolean getNonConfigInstance) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4156 | ActivityClientRecord r = mActivities.get(token); |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4157 | Class<? extends Activity> activityClass = null; |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4158 | if (localLOGV) Slog.v(TAG, "Performing finish of " + r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4159 | if (r != null) { |
Brad Fitzpatrick | 5f8b5c1 | 2011-01-20 15:12:08 -0800 | [diff] [blame] | 4160 | activityClass = r.activity.getClass(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4161 | r.activity.mConfigChangeFlags |= configChanges; |
| 4162 | if (finishing) { |
| 4163 | r.activity.mFinished = true; |
| 4164 | } |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 4165 | |
| 4166 | performPauseActivityIfNeeded(r, "destroy"); |
| 4167 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4168 | if (!r.stopped) { |
| 4169 | try { |
Chong Zhang | 7687f25 | 2016-02-26 12:03:33 -0800 | [diff] [blame] | 4170 | r.activity.performStop(r.mPreserveWindow); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4171 | } catch (SuperNotCalledException e) { |
| 4172 | throw e; |
| 4173 | } catch (Exception e) { |
| 4174 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4175 | throw new RuntimeException( |
| 4176 | "Unable to stop activity " |
Mitsuru Oshima | d9aef73 | 2009-06-16 20:20:50 -0700 | [diff] [blame] | 4177 | + safeToComponentShortString(r.intent) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4178 | + ": " + e.toString(), e); |
| 4179 | } |
| 4180 | } |
| 4181 | r.stopped = true; |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 4182 | EventLog.writeEvent(LOG_AM_ON_STOP_CALLED, UserHandle.myUserId(), |
| 4183 | r.activity.getComponentName().getClassName(), "destroy"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4184 | } |
| 4185 | if (getNonConfigInstance) { |
| 4186 | try { |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 4187 | r.lastNonConfigurationInstances |
| 4188 | = r.activity.retainNonConfigurationInstances(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4189 | } catch (Exception e) { |
| 4190 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4191 | throw new RuntimeException( |
| 4192 | "Unable to retain activity " |
| 4193 | + r.intent.getComponent().toShortString() |
| 4194 | + ": " + e.toString(), e); |
| 4195 | } |
| 4196 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4197 | } |
| 4198 | try { |
| 4199 | r.activity.mCalled = false; |
Dianne Hackborn | 2dedce6 | 2010-04-15 14:45:25 -0700 | [diff] [blame] | 4200 | mInstrumentation.callActivityOnDestroy(r.activity); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4201 | if (!r.activity.mCalled) { |
| 4202 | throw new SuperNotCalledException( |
Mitsuru Oshima | d9aef73 | 2009-06-16 20:20:50 -0700 | [diff] [blame] | 4203 | "Activity " + safeToComponentShortString(r.intent) + |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4204 | " did not call through to super.onDestroy()"); |
| 4205 | } |
| 4206 | if (r.window != null) { |
| 4207 | r.window.closeAllPanels(); |
| 4208 | } |
| 4209 | } catch (SuperNotCalledException e) { |
| 4210 | throw e; |
| 4211 | } catch (Exception e) { |
| 4212 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4213 | throw new RuntimeException( |
Mitsuru Oshima | d9aef73 | 2009-06-16 20:20:50 -0700 | [diff] [blame] | 4214 | "Unable to destroy activity " + safeToComponentShortString(r.intent) |
| 4215 | + ": " + e.toString(), e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4216 | } |
| 4217 | } |
| 4218 | } |
| 4219 | mActivities.remove(token); |
Brad Fitzpatrick | 5f8b5c1 | 2011-01-20 15:12:08 -0800 | [diff] [blame] | 4220 | StrictMode.decrementExpectedActivityCount(activityClass); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4221 | return r; |
| 4222 | } |
| 4223 | |
Mitsuru Oshima | d9aef73 | 2009-06-16 20:20:50 -0700 | [diff] [blame] | 4224 | private static String safeToComponentShortString(Intent intent) { |
| 4225 | ComponentName component = intent.getComponent(); |
| 4226 | return component == null ? "[Unknown]" : component.toShortString(); |
| 4227 | } |
| 4228 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 4229 | private void handleDestroyActivity(IBinder token, boolean finishing, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4230 | int configChanges, boolean getNonConfigInstance) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4231 | ActivityClientRecord r = performDestroyActivity(token, finishing, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4232 | configChanges, getNonConfigInstance); |
| 4233 | if (r != null) { |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4234 | cleanUpPendingRemoveWindows(r, finishing); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4235 | WindowManager wm = r.activity.getWindowManager(); |
| 4236 | View v = r.activity.mDecor; |
| 4237 | if (v != null) { |
| 4238 | if (r.activity.mVisibleFromServer) { |
| 4239 | mNumVisibleActivities--; |
| 4240 | } |
| 4241 | IBinder wtoken = v.getWindowToken(); |
| 4242 | if (r.activity.mWindowAdded) { |
Robert Carr | 77bdfb5 | 2016-05-02 18:18:31 -0700 | [diff] [blame] | 4243 | if (r.mPreserveWindow) { |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4244 | // Hold off on removing this until the new activity's |
| 4245 | // window is being added. |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4246 | r.mPendingRemoveWindow = r.window; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4247 | r.mPendingRemoveWindowManager = wm; |
Andrii Kulian | eac0ea5 | 2016-05-11 15:50:24 -0700 | [diff] [blame] | 4248 | // We can only keep the part of the view hierarchy that we control, |
| 4249 | // everything else must be removed, because it might not be able to |
| 4250 | // behave properly when activity is relaunching. |
| 4251 | r.window.clearContentView(); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4252 | } else { |
| 4253 | wm.removeViewImmediate(v); |
| 4254 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4255 | } |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4256 | if (wtoken != null && r.mPendingRemoveWindow == null) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 4257 | WindowManagerGlobal.getInstance().closeAll(wtoken, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4258 | r.activity.getClass().getName(), "Activity"); |
Andrii Kulian | eac0ea5 | 2016-05-11 15:50:24 -0700 | [diff] [blame] | 4259 | } else if (r.mPendingRemoveWindow != null) { |
| 4260 | // We're preserving only one window, others should be closed so app views |
| 4261 | // will be detached before the final tear down. It should be done now because |
| 4262 | // some components (e.g. WebView) rely on detach callbacks to perform receiver |
| 4263 | // unregister and other cleanup. |
| 4264 | WindowManagerGlobal.getInstance().closeAllExceptView(token, v, |
| 4265 | r.activity.getClass().getName(), "Activity"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4266 | } |
| 4267 | r.activity.mDecor = null; |
| 4268 | } |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4269 | if (r.mPendingRemoveWindow == null) { |
| 4270 | // If we are delaying the removal of the activity window, then |
| 4271 | // we can't clean up all windows here. Note that we can't do |
| 4272 | // so later either, which means any windows that aren't closed |
| 4273 | // by the app will leak. Well we try to warning them a lot |
| 4274 | // about leaking windows, because that is a bug, so if they are |
| 4275 | // using this recreate facility then they get to live with leaks. |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 4276 | WindowManagerGlobal.getInstance().closeAll(token, |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4277 | r.activity.getClass().getName(), "Activity"); |
| 4278 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4279 | |
| 4280 | // Mocked out contexts won't be participating in the normal |
| 4281 | // process lifecycle, but if we're running with a proper |
| 4282 | // ApplicationContext we need to have it tear down things |
| 4283 | // cleanly. |
| 4284 | Context c = r.activity.getBaseContext(); |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 4285 | if (c instanceof ContextImpl) { |
| 4286 | ((ContextImpl) c).scheduleFinalCleanup( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4287 | r.activity.getClass().getName(), "Activity"); |
| 4288 | } |
| 4289 | } |
| 4290 | if (finishing) { |
| 4291 | try { |
| 4292 | ActivityManagerNative.getDefault().activityDestroyed(token); |
| 4293 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4294 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4295 | } |
| 4296 | } |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4297 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4298 | } |
| 4299 | |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4300 | /** |
| 4301 | * @param preserveWindow Whether the activity should try to reuse the window it created, |
| 4302 | * including the decor view after the relaunch. |
| 4303 | */ |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4304 | public final void requestRelaunchActivity(IBinder token, |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 4305 | List<ResultInfo> pendingResults, List<ReferrerIntent> pendingNewIntents, |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4306 | int configChanges, boolean notResumed, Configuration config, |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4307 | Configuration overrideConfig, boolean fromServer, boolean preserveWindow) { |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4308 | ActivityClientRecord target = null; |
| 4309 | |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4310 | synchronized (mResourcesManager) { |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4311 | for (int i=0; i<mRelaunchingActivities.size(); i++) { |
| 4312 | ActivityClientRecord r = mRelaunchingActivities.get(i); |
Filip Gruszczynski | c3b6179 | 2016-01-22 16:43:48 -0800 | [diff] [blame] | 4313 | if (DEBUG_ORDER) Slog.d(TAG, "requestRelaunchActivity: " + this + ", trying: " + r); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4314 | if (r.token == token) { |
| 4315 | target = r; |
| 4316 | if (pendingResults != null) { |
| 4317 | if (r.pendingResults != null) { |
| 4318 | r.pendingResults.addAll(pendingResults); |
| 4319 | } else { |
| 4320 | r.pendingResults = pendingResults; |
| 4321 | } |
| 4322 | } |
| 4323 | if (pendingNewIntents != null) { |
| 4324 | if (r.pendingIntents != null) { |
| 4325 | r.pendingIntents.addAll(pendingNewIntents); |
| 4326 | } else { |
| 4327 | r.pendingIntents = pendingNewIntents; |
| 4328 | } |
| 4329 | } |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4330 | |
| 4331 | // For each relaunch request, activity manager expects an answer |
| 4332 | if (!r.onlyLocalRequest && fromServer) { |
| 4333 | try { |
| 4334 | ActivityManagerNative.getDefault().activityRelaunched(token); |
| 4335 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4336 | throw e.rethrowFromSystemServer(); |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4337 | } |
| 4338 | } |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4339 | break; |
| 4340 | } |
| 4341 | } |
| 4342 | |
| 4343 | if (target == null) { |
Filip Gruszczynski | c3b6179 | 2016-01-22 16:43:48 -0800 | [diff] [blame] | 4344 | if (DEBUG_ORDER) Slog.d(TAG, "requestRelaunchActivity: target is null, fromServer:" |
| 4345 | + fromServer); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4346 | target = new ActivityClientRecord(); |
| 4347 | target.token = token; |
| 4348 | target.pendingResults = pendingResults; |
| 4349 | target.pendingIntents = pendingNewIntents; |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4350 | target.mPreserveWindow = preserveWindow; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4351 | if (!fromServer) { |
Filip Gruszczynski | c3b6179 | 2016-01-22 16:43:48 -0800 | [diff] [blame] | 4352 | final ActivityClientRecord existing = mActivities.get(token); |
| 4353 | if (DEBUG_ORDER) Slog.d(TAG, "requestRelaunchActivity: " + existing); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4354 | if (existing != null) { |
Filip Gruszczynski | c3b6179 | 2016-01-22 16:43:48 -0800 | [diff] [blame] | 4355 | if (DEBUG_ORDER) Slog.d(TAG, "requestRelaunchActivity: paused= " |
| 4356 | + existing.paused);; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4357 | target.startsNotResumed = existing.paused; |
Wale Ogunwale | 93f543c | 2015-02-17 16:55:03 -0800 | [diff] [blame] | 4358 | target.overrideConfig = existing.overrideConfig; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4359 | } |
| 4360 | target.onlyLocalRequest = true; |
| 4361 | } |
| 4362 | mRelaunchingActivities.add(target); |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 4363 | sendMessage(H.RELAUNCH_ACTIVITY, target); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4364 | } |
| 4365 | |
| 4366 | if (fromServer) { |
| 4367 | target.startsNotResumed = notResumed; |
| 4368 | target.onlyLocalRequest = false; |
| 4369 | } |
| 4370 | if (config != null) { |
| 4371 | target.createdConfig = config; |
| 4372 | } |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 4373 | if (overrideConfig != null) { |
| 4374 | target.overrideConfig = overrideConfig; |
| 4375 | } |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4376 | target.pendingConfigChanges |= configChanges; |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 4377 | target.relaunchSeq = getLifecycleSeq(); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4378 | } |
Filip Gruszczynski | c3b6179 | 2016-01-22 16:43:48 -0800 | [diff] [blame] | 4379 | if (DEBUG_ORDER) Slog.d(TAG, "relaunchActivity " + ActivityThread.this + ", target " |
| 4380 | + target + " operation received seq: " + target.relaunchSeq); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4381 | } |
| 4382 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 4383 | private void handleRelaunchActivity(ActivityClientRecord tmp) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4384 | // If we are getting ready to gc after going to the background, well |
| 4385 | // we are back active so skip it. |
| 4386 | unscheduleGcIdler(); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4387 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4388 | |
| 4389 | Configuration changedConfig = null; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4390 | int configChanges = 0; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4391 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4392 | // First: make sure we have the most recent configuration and most |
| 4393 | // recent version of the activity, or skip it if some previous call |
| 4394 | // had taken a more recent version. |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4395 | synchronized (mResourcesManager) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4396 | int N = mRelaunchingActivities.size(); |
| 4397 | IBinder token = tmp.token; |
| 4398 | tmp = null; |
| 4399 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4400 | ActivityClientRecord r = mRelaunchingActivities.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4401 | if (r.token == token) { |
| 4402 | tmp = r; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4403 | configChanges |= tmp.pendingConfigChanges; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4404 | mRelaunchingActivities.remove(i); |
| 4405 | i--; |
| 4406 | N--; |
| 4407 | } |
| 4408 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4409 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4410 | if (tmp == null) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4411 | 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] | 4412 | return; |
| 4413 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4414 | |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4415 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Relaunching activity " |
| 4416 | + tmp.token + " with configChanges=0x" |
| 4417 | + Integer.toHexString(configChanges)); |
| 4418 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4419 | if (mPendingConfiguration != null) { |
| 4420 | changedConfig = mPendingConfiguration; |
| 4421 | mPendingConfiguration = null; |
| 4422 | } |
| 4423 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4424 | |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 4425 | if (tmp.lastProcessedSeq > tmp.relaunchSeq) { |
| 4426 | Slog.wtf(TAG, "For some reason target: " + tmp + " has lower sequence: " |
| 4427 | + tmp.relaunchSeq + " than current sequence: " + tmp.lastProcessedSeq); |
| 4428 | } else { |
| 4429 | tmp.lastProcessedSeq = tmp.relaunchSeq; |
| 4430 | } |
Dianne Hackborn | 871ecdc | 2009-12-11 15:24:33 -0800 | [diff] [blame] | 4431 | if (tmp.createdConfig != null) { |
| 4432 | // If the activity manager is passing us its current config, |
| 4433 | // assume that is really what we want regardless of what we |
| 4434 | // may have pending. |
| 4435 | if (mConfiguration == null |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4436 | || (tmp.createdConfig.isOtherSeqNewer(mConfiguration) |
| 4437 | && mConfiguration.diff(tmp.createdConfig) != 0)) { |
| 4438 | if (changedConfig == null |
| 4439 | || tmp.createdConfig.isOtherSeqNewer(changedConfig)) { |
| 4440 | changedConfig = tmp.createdConfig; |
| 4441 | } |
Dianne Hackborn | 871ecdc | 2009-12-11 15:24:33 -0800 | [diff] [blame] | 4442 | } |
| 4443 | } |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 4444 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4445 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Relaunching activity " |
Dianne Hackborn | dc6b635 | 2009-09-30 14:20:09 -0700 | [diff] [blame] | 4446 | + tmp.token + ": changedConfig=" + changedConfig); |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 4447 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4448 | // If there was a pending configuration change, execute it first. |
| 4449 | if (changedConfig != null) { |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 4450 | mCurDefaultDisplayDpi = changedConfig.densityDpi; |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 4451 | updateDefaultDensity(); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4452 | handleConfigurationChanged(changedConfig, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4453 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4454 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4455 | ActivityClientRecord r = mActivities.get(tmp.token); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4456 | 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] | 4457 | if (r == null) { |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4458 | if (!tmp.onlyLocalRequest) { |
| 4459 | try { |
| 4460 | ActivityManagerNative.getDefault().activityRelaunched(tmp.token); |
| 4461 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4462 | throw e.rethrowFromSystemServer(); |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4463 | } |
| 4464 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4465 | return; |
| 4466 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4467 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4468 | r.activity.mConfigChangeFlags |= configChanges; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4469 | r.onlyLocalRequest = tmp.onlyLocalRequest; |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4470 | r.mPreserveWindow = tmp.mPreserveWindow; |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 4471 | r.lastProcessedSeq = tmp.lastProcessedSeq; |
| 4472 | r.relaunchSeq = tmp.relaunchSeq; |
Christopher Tate | b70f3df | 2009-04-07 16:07:59 -0700 | [diff] [blame] | 4473 | Intent currentIntent = r.activity.mIntent; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4474 | |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4475 | r.activity.mChangingConfigurations = true; |
| 4476 | |
Robert Carr | 23fa16b | 2016-01-13 13:19:58 -0800 | [diff] [blame] | 4477 | // If we are preserving the main window across relaunches we would also like to preserve |
| 4478 | // the children. However the client side view system does not support preserving |
| 4479 | // the child views so we notify the window manager to expect these windows to |
| 4480 | // be replaced and defer requests to destroy or hide them. This way we can achieve |
| 4481 | // visual continuity. It's important that we do this here prior to pause and destroy |
| 4482 | // as that is when we may hide or remove the child views. |
Robert Carr | 77bdfb5 | 2016-05-02 18:18:31 -0700 | [diff] [blame] | 4483 | // |
| 4484 | // There is another scenario, if we have decided locally to relaunch the app from a |
| 4485 | // call to recreate, then none of the windows will be prepared for replacement or |
| 4486 | // preserved by the server, so we want to notify it that we are preparing to replace |
| 4487 | // everything |
Robert Carr | 23fa16b | 2016-01-13 13:19:58 -0800 | [diff] [blame] | 4488 | try { |
Robert Carr | 77bdfb5 | 2016-05-02 18:18:31 -0700 | [diff] [blame] | 4489 | if (r.mPreserveWindow || r.onlyLocalRequest) { |
| 4490 | WindowManagerGlobal.getWindowSession().prepareToReplaceWindows( |
| 4491 | r.token, !r.onlyLocalRequest); |
Robert Carr | 23fa16b | 2016-01-13 13:19:58 -0800 | [diff] [blame] | 4492 | } |
| 4493 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4494 | throw e.rethrowFromSystemServer(); |
Robert Carr | 23fa16b | 2016-01-13 13:19:58 -0800 | [diff] [blame] | 4495 | } |
| 4496 | |
Dianne Hackborn | e2b0480 | 2010-12-09 09:24:55 -0800 | [diff] [blame] | 4497 | // Need to ensure state is saved. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4498 | if (!r.paused) { |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 4499 | performPauseActivity(r.token, false, r.isPreHoneycomb(), "handleRelaunchActivity"); |
Dianne Hackborn | e2b0480 | 2010-12-09 09:24:55 -0800 | [diff] [blame] | 4500 | } |
| 4501 | if (r.state == null && !r.stopped && !r.isPreHoneycomb()) { |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 4502 | callCallActivityOnSaveInstanceState(r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4503 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4504 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4505 | handleDestroyActivity(r.token, false, configChanges, true); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4506 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4507 | r.activity = null; |
| 4508 | r.window = null; |
| 4509 | r.hideForNow = false; |
| 4510 | r.nextIdle = null; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4511 | // Merge any pending results and pending intents; don't just replace them |
| 4512 | if (tmp.pendingResults != null) { |
| 4513 | if (r.pendingResults == null) { |
| 4514 | r.pendingResults = tmp.pendingResults; |
| 4515 | } else { |
| 4516 | r.pendingResults.addAll(tmp.pendingResults); |
| 4517 | } |
| 4518 | } |
| 4519 | if (tmp.pendingIntents != null) { |
| 4520 | if (r.pendingIntents == null) { |
| 4521 | r.pendingIntents = tmp.pendingIntents; |
| 4522 | } else { |
| 4523 | r.pendingIntents.addAll(tmp.pendingIntents); |
| 4524 | } |
| 4525 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4526 | r.startsNotResumed = tmp.startsNotResumed; |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 4527 | r.overrideConfig = tmp.overrideConfig; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4528 | |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 4529 | handleLaunchActivity(r, currentIntent, "handleRelaunchActivity"); |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4530 | |
| 4531 | if (!tmp.onlyLocalRequest) { |
| 4532 | try { |
| 4533 | ActivityManagerNative.getDefault().activityRelaunched(r.token); |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 4534 | if (r.window != null) { |
| 4535 | r.window.reportActivityRelaunched(); |
| 4536 | } |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4537 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4538 | throw e.rethrowFromSystemServer(); |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4539 | } |
| 4540 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4541 | } |
| 4542 | |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 4543 | private void callCallActivityOnSaveInstanceState(ActivityClientRecord r) { |
| 4544 | r.state = new Bundle(); |
| 4545 | r.state.setAllowFds(false); |
| 4546 | if (r.isPersistable()) { |
| 4547 | r.persistentState = new PersistableBundle(); |
| 4548 | mInstrumentation.callActivityOnSaveInstanceState(r.activity, r.state, |
| 4549 | r.persistentState); |
| 4550 | } else { |
| 4551 | mInstrumentation.callActivityOnSaveInstanceState(r.activity, r.state); |
| 4552 | } |
| 4553 | } |
| 4554 | |
Dianne Hackborn | 73c1416 | 2012-09-19 15:45:06 -0700 | [diff] [blame] | 4555 | ArrayList<ComponentCallbacks2> collectComponentCallbacks( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4556 | boolean allActivities, Configuration newConfig) { |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 4557 | ArrayList<ComponentCallbacks2> callbacks |
| 4558 | = new ArrayList<ComponentCallbacks2>(); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4559 | |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4560 | synchronized (mResourcesManager) { |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 4561 | final int NAPP = mAllApplications.size(); |
| 4562 | for (int i=0; i<NAPP; i++) { |
Dianne Hackborn | 73c1416 | 2012-09-19 15:45:06 -0700 | [diff] [blame] | 4563 | callbacks.add(mAllApplications.get(i)); |
| 4564 | } |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 4565 | final int NACT = mActivities.size(); |
| 4566 | for (int i=0; i<NACT; i++) { |
| 4567 | ActivityClientRecord ar = mActivities.valueAt(i); |
| 4568 | Activity a = ar.activity; |
| 4569 | if (a != null) { |
| 4570 | Configuration thisConfig = applyConfigCompatMainThread( |
| 4571 | mCurDefaultDisplayDpi, newConfig, |
| 4572 | ar.packageInfo.getCompatibilityInfo()); |
| 4573 | if (!ar.activity.mFinished && (allActivities || !ar.paused)) { |
| 4574 | // If the activity is currently resumed, its configuration |
| 4575 | // needs to change right now. |
| 4576 | callbacks.add(a); |
| 4577 | } else if (thisConfig != null) { |
| 4578 | // Otherwise, we will tell it about the change |
| 4579 | // the next time it is resumed or shown. Note that |
| 4580 | // the activity manager may, before then, decide the |
| 4581 | // activity needs to be destroyed to handle its new |
| 4582 | // configuration. |
| 4583 | if (DEBUG_CONFIGURATION) { |
| 4584 | Slog.v(TAG, "Setting activity " |
| 4585 | + ar.activityInfo.name + " newConfig=" + thisConfig); |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 4586 | } |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 4587 | ar.newConfig = thisConfig; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4588 | } |
| 4589 | } |
| 4590 | } |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 4591 | final int NSVC = mServices.size(); |
| 4592 | for (int i=0; i<NSVC; i++) { |
| 4593 | callbacks.add(mServices.valueAt(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4594 | } |
| 4595 | } |
| 4596 | synchronized (mProviderMap) { |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 4597 | final int NPRV = mLocalProviders.size(); |
| 4598 | for (int i=0; i<NPRV; i++) { |
| 4599 | callbacks.add(mLocalProviders.valueAt(i).mLocalProvider); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4600 | } |
| 4601 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4602 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4603 | return callbacks; |
| 4604 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4605 | |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 4606 | /** |
| 4607 | * Updates the configuration for an Activity. The ActivityClientRecord's |
| 4608 | * {@link ActivityClientRecord#overrideConfig} is used to compute the final Configuration for |
| 4609 | * that Activity. {@link ActivityClientRecord#tmpConfig} is used as a temporary for delivering |
| 4610 | * the updated Configuration. |
| 4611 | * @param r ActivityClientRecord representing the Activity. |
| 4612 | * @param newBaseConfig The new configuration to use. This may be augmented with |
| 4613 | * {@link ActivityClientRecord#overrideConfig}. |
| 4614 | * @param reportToActivity true if the change should be reported to the Activity's callback. |
| 4615 | */ |
| 4616 | private void performConfigurationChangedForActivity(ActivityClientRecord r, |
| 4617 | Configuration newBaseConfig, |
| 4618 | boolean reportToActivity) { |
| 4619 | r.tmpConfig.setTo(newBaseConfig); |
| 4620 | if (r.overrideConfig != null) { |
| 4621 | r.tmpConfig.updateFrom(r.overrideConfig); |
| 4622 | } |
| 4623 | performConfigurationChanged(r.activity, r.token, r.tmpConfig, r.overrideConfig, |
| 4624 | reportToActivity); |
| 4625 | freeTextLayoutCachesIfNeeded(r.activity.mCurrentConfig.diff(r.tmpConfig)); |
| 4626 | } |
| 4627 | |
| 4628 | /** |
Adam Lesinski | c1b0ebf | 2016-06-09 11:17:10 -0700 | [diff] [blame] | 4629 | * Creates a new Configuration only if override would modify base. Otherwise returns base. |
| 4630 | * @param base The base configuration. |
| 4631 | * @param override The update to apply to the base configuration. Can be null. |
| 4632 | * @return A Configuration representing base with override applied. |
| 4633 | */ |
| 4634 | private static Configuration createNewConfigAndUpdateIfNotNull(@NonNull Configuration base, |
| 4635 | @Nullable Configuration override) { |
| 4636 | if (override == null) { |
| 4637 | return base; |
| 4638 | } |
| 4639 | Configuration newConfig = new Configuration(base); |
| 4640 | newConfig.updateFrom(override); |
| 4641 | return newConfig; |
| 4642 | } |
| 4643 | |
| 4644 | /** |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 4645 | * Decides whether to update an Activity's configuration and whether to tell the |
| 4646 | * Activity/Component about it. |
| 4647 | * @param cb The component callback to notify of configuration change. |
| 4648 | * @param activityToken The Activity binder token for which this configuration change happened. |
| 4649 | * If the change is global, this is null. |
| 4650 | * @param newConfig The new configuration. |
Adam Lesinski | c1b0ebf | 2016-06-09 11:17:10 -0700 | [diff] [blame] | 4651 | * @param amOverrideConfig The override config that differentiates the Activity's configuration |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 4652 | * from the base global configuration. |
Adam Lesinski | c1b0ebf | 2016-06-09 11:17:10 -0700 | [diff] [blame] | 4653 | * This is supplied by ActivityManager. |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 4654 | * @param reportToActivity Notify the Activity of the change. |
| 4655 | */ |
| 4656 | private void performConfigurationChanged(ComponentCallbacks2 cb, |
| 4657 | IBinder activityToken, |
| 4658 | Configuration newConfig, |
Adam Lesinski | c1b0ebf | 2016-06-09 11:17:10 -0700 | [diff] [blame] | 4659 | Configuration amOverrideConfig, |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 4660 | boolean reportToActivity) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4661 | // Only for Activity objects, check that they actually call up to their |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 4662 | // superclass implementation. ComponentCallbacks2 is an interface, so |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4663 | // we check the runtime type and act accordingly. |
| 4664 | Activity activity = (cb instanceof Activity) ? (Activity) cb : null; |
| 4665 | if (activity != null) { |
| 4666 | activity.mCalled = false; |
| 4667 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4668 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4669 | boolean shouldChangeConfig = false; |
| 4670 | if ((activity == null) || (activity.mCurrentConfig == null)) { |
| 4671 | shouldChangeConfig = true; |
| 4672 | } else { |
Andrii Kulian | 3b3c914 | 2016-07-18 19:15:56 -0700 | [diff] [blame] | 4673 | // If the new config is the same as the config this Activity is already |
| 4674 | // running with and the override config also didn't change, then don't |
| 4675 | // bother calling onConfigurationChanged. |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 4676 | int diff = activity.mCurrentConfig.diff(newConfig); |
Andrii Kulian | 3b3c914 | 2016-07-18 19:15:56 -0700 | [diff] [blame] | 4677 | if (diff != 0 || !mResourcesManager.isSameResourcesOverrideConfig(activityToken, |
| 4678 | amOverrideConfig)) { |
Chong Zhang | 4951f9d | 2016-06-23 13:15:08 -0700 | [diff] [blame] | 4679 | // Always send the task-level config changes. For system-level configuration, if |
| 4680 | // this activity doesn't handle any of the config changes, then don't bother |
| 4681 | // calling onConfigurationChanged as we're going to destroy it. |
| 4682 | if (!mUpdatingSystemConfig |
| 4683 | || (~activity.mActivityInfo.getRealConfigChanged() & diff) == 0 |
| 4684 | || !reportToActivity) { |
| 4685 | shouldChangeConfig = true; |
| 4686 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4687 | } |
| 4688 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4689 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4690 | if (shouldChangeConfig) { |
Adam Lesinski | c1b0ebf | 2016-06-09 11:17:10 -0700 | [diff] [blame] | 4691 | // Propagate the configuration change to the Activity and ResourcesManager. |
| 4692 | |
| 4693 | // ContextThemeWrappers may override the configuration for that context. |
| 4694 | // We must check and apply any overrides defined. |
| 4695 | Configuration contextThemeWrapperOverrideConfig = null; |
| 4696 | if (cb instanceof ContextThemeWrapper) { |
| 4697 | final ContextThemeWrapper contextThemeWrapper = (ContextThemeWrapper) cb; |
| 4698 | contextThemeWrapperOverrideConfig = contextThemeWrapper.getOverrideConfiguration(); |
| 4699 | } |
| 4700 | |
| 4701 | // We only update an Activity's configuration if this is not a global |
| 4702 | // configuration change. This must also be done before the callback, |
| 4703 | // or else we violate the contract that the new resources are available |
| 4704 | // in {@link ComponentCallbacks2#onConfigurationChanged(Configuration)}. |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 4705 | if (activityToken != null) { |
Adam Lesinski | c1b0ebf | 2016-06-09 11:17:10 -0700 | [diff] [blame] | 4706 | // Apply the ContextThemeWrapper override if necessary. |
| 4707 | // NOTE: Make sure the configurations are not modified, as they are treated |
| 4708 | // as immutable in many places. |
| 4709 | final Configuration finalOverrideConfig = createNewConfigAndUpdateIfNotNull( |
| 4710 | amOverrideConfig, contextThemeWrapperOverrideConfig); |
| 4711 | mResourcesManager.updateResourcesForActivity(activityToken, finalOverrideConfig); |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 4712 | } |
| 4713 | |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 4714 | if (reportToActivity) { |
Adam Lesinski | c1b0ebf | 2016-06-09 11:17:10 -0700 | [diff] [blame] | 4715 | // Apply the ContextThemeWrapper override if necessary. |
| 4716 | // NOTE: Make sure the configurations are not modified, as they are treated |
| 4717 | // as immutable in many places. |
| 4718 | final Configuration configToReport = createNewConfigAndUpdateIfNotNull( |
| 4719 | newConfig, contextThemeWrapperOverrideConfig); |
Adam Lesinski | 3ad1b48 | 2016-04-01 16:41:41 -0700 | [diff] [blame] | 4720 | cb.onConfigurationChanged(configToReport); |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 4721 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4722 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4723 | if (activity != null) { |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 4724 | if (reportToActivity && !activity.mCalled) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4725 | throw new SuperNotCalledException( |
| 4726 | "Activity " + activity.getLocalClassName() + |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 4727 | " did not call through to super.onConfigurationChanged()"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4728 | } |
| 4729 | activity.mConfigChangeFlags = 0; |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 4730 | activity.mCurrentConfig = new Configuration(newConfig); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4731 | } |
| 4732 | } |
| 4733 | } |
| 4734 | |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 4735 | public final void applyConfigurationToResources(Configuration config) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4736 | synchronized (mResourcesManager) { |
| 4737 | mResourcesManager.applyConfigurationToResourcesLocked(config, null); |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 4738 | } |
| 4739 | } |
| 4740 | |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 4741 | final Configuration applyCompatConfiguration(int displayDensity) { |
Dianne Hackborn | 836e262 | 2011-10-04 18:32:39 -0700 | [diff] [blame] | 4742 | Configuration config = mConfiguration; |
| 4743 | if (mCompatConfiguration == null) { |
| 4744 | mCompatConfiguration = new Configuration(); |
| 4745 | } |
| 4746 | mCompatConfiguration.setTo(mConfiguration); |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 4747 | if (mResourcesManager.applyCompatConfigurationLocked(displayDensity, |
| 4748 | mCompatConfiguration)) { |
Dianne Hackborn | 836e262 | 2011-10-04 18:32:39 -0700 | [diff] [blame] | 4749 | config = mCompatConfiguration; |
| 4750 | } |
| 4751 | return config; |
| 4752 | } |
| 4753 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4754 | final void handleConfigurationChanged(Configuration config, CompatibilityInfo compat) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4755 | |
Fabrice Di Meglio | 30ca5cd | 2012-05-07 17:45:44 -0700 | [diff] [blame] | 4756 | int configDiff = 0; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4757 | |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4758 | synchronized (mResourcesManager) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4759 | if (mPendingConfiguration != null) { |
| 4760 | if (!mPendingConfiguration.isOtherSeqNewer(config)) { |
| 4761 | config = mPendingConfiguration; |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 4762 | mCurDefaultDisplayDpi = config.densityDpi; |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 4763 | updateDefaultDensity(); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4764 | } |
| 4765 | mPendingConfiguration = null; |
| 4766 | } |
| 4767 | |
| 4768 | if (config == null) { |
| 4769 | return; |
| 4770 | } |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 4771 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4772 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Handle configuration changed: " |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4773 | + config); |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4774 | |
| 4775 | mResourcesManager.applyConfigurationToResourcesLocked(config, compat); |
Adam Lesinski | b61e405 | 2016-05-19 18:23:05 -0700 | [diff] [blame] | 4776 | updateLocaleListFromAppContext(mInitialApplication.getApplicationContext(), |
| 4777 | mResourcesManager.getConfiguration().getLocales()); |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4778 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4779 | if (mConfiguration == null) { |
| 4780 | mConfiguration = new Configuration(); |
| 4781 | } |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4782 | if (!mConfiguration.isOtherSeqNewer(config) && compat == null) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4783 | return; |
| 4784 | } |
Alan Viverette | e54d245 | 2015-05-06 10:41:43 -0700 | [diff] [blame] | 4785 | |
| 4786 | configDiff = mConfiguration.updateFrom(config); |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 4787 | config = applyCompatConfiguration(mCurDefaultDisplayDpi); |
Alan Viverette | 395cd01 | 2015-08-11 17:27:04 -0400 | [diff] [blame] | 4788 | |
| 4789 | final Theme systemTheme = getSystemContext().getTheme(); |
| 4790 | if ((systemTheme.getChangingConfigurations() & configDiff) != 0) { |
| 4791 | systemTheme.rebase(); |
| 4792 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4793 | } |
Dianne Hackborn | 73c1416 | 2012-09-19 15:45:06 -0700 | [diff] [blame] | 4794 | |
| 4795 | ArrayList<ComponentCallbacks2> callbacks = collectComponentCallbacks(false, config); |
| 4796 | |
Fabrice Di Meglio | 30ca5cd | 2012-05-07 17:45:44 -0700 | [diff] [blame] | 4797 | freeTextLayoutCachesIfNeeded(configDiff); |
| 4798 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4799 | if (callbacks != null) { |
| 4800 | final int N = callbacks.size(); |
| 4801 | for (int i=0; i<N; i++) { |
Andrii Kulian | 701214b | 2016-04-07 09:36:33 -0700 | [diff] [blame] | 4802 | ComponentCallbacks2 cb = callbacks.get(i); |
| 4803 | if (cb instanceof Activity) { |
| 4804 | // If callback is an Activity - call corresponding method to consider override |
| 4805 | // config and avoid onConfigurationChanged if it hasn't changed. |
| 4806 | Activity a = (Activity) cb; |
| 4807 | performConfigurationChangedForActivity(mActivities.get(a.getActivityToken()), |
| 4808 | config, REPORT_TO_ACTIVITY); |
| 4809 | } else { |
| 4810 | performConfigurationChanged(cb, null, config, null, REPORT_TO_ACTIVITY); |
| 4811 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4812 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4813 | } |
| 4814 | } |
| 4815 | |
Romain Guy | 46bfc48 | 2013-08-16 18:38:29 -0700 | [diff] [blame] | 4816 | static void freeTextLayoutCachesIfNeeded(int configDiff) { |
Fabrice Di Meglio | 30ca5cd | 2012-05-07 17:45:44 -0700 | [diff] [blame] | 4817 | if (configDiff != 0) { |
| 4818 | // Ask text layout engine to free its caches if there is a locale change |
| 4819 | boolean hasLocaleConfigChange = ((configDiff & ActivityInfo.CONFIG_LOCALE) != 0); |
| 4820 | if (hasLocaleConfigChange) { |
| 4821 | Canvas.freeTextLayoutCaches(); |
| 4822 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Cleared TextLayout Caches"); |
| 4823 | } |
| 4824 | } |
| 4825 | } |
| 4826 | |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 4827 | final void handleActivityConfigurationChanged(ActivityConfigChangeData data, |
| 4828 | boolean reportToActivity) { |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 4829 | ActivityClientRecord r = mActivities.get(data.activityToken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4830 | if (r == null || r.activity == null) { |
| 4831 | return; |
| 4832 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4833 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4834 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Handle activity config changed: " |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 4835 | + r.activityInfo.name + ", with callback=" + reportToActivity); |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 4836 | |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 4837 | r.overrideConfig = data.overrideConfig; |
| 4838 | performConfigurationChangedForActivity(r, mCompatConfiguration, reportToActivity); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4839 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4840 | } |
| 4841 | |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 4842 | final void handleProfilerControl(boolean start, ProfilerInfo profilerInfo, int profileType) { |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 4843 | if (start) { |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 4844 | try { |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 4845 | switch (profileType) { |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 4846 | default: |
| 4847 | mProfiler.setProfiler(profilerInfo); |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 4848 | mProfiler.startProfiling(); |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 4849 | break; |
| 4850 | } |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 4851 | } catch (RuntimeException e) { |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 4852 | Slog.w(TAG, "Profiling failed on path " + profilerInfo.profileFile |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 4853 | + " -- can the process access this path?"); |
Dianne Hackborn | 9c8dd55 | 2009-06-23 19:22:52 -0700 | [diff] [blame] | 4854 | } finally { |
| 4855 | try { |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 4856 | profilerInfo.profileFd.close(); |
Dianne Hackborn | 9c8dd55 | 2009-06-23 19:22:52 -0700 | [diff] [blame] | 4857 | } catch (IOException e) { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 4858 | Slog.w(TAG, "Failure closing profile fd", e); |
Dianne Hackborn | 9c8dd55 | 2009-06-23 19:22:52 -0700 | [diff] [blame] | 4859 | } |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 4860 | } |
| 4861 | } else { |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 4862 | switch (profileType) { |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 4863 | default: |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 4864 | mProfiler.stopProfiling(); |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 4865 | break; |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 4866 | } |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 4867 | } |
| 4868 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4869 | |
Andreas Gampe | 4c79fea | 2016-01-28 20:11:41 -0800 | [diff] [blame] | 4870 | /** |
| 4871 | * Public entrypoint to stop profiling. This is required to end profiling when the app crashes, |
| 4872 | * so that profiler data won't be lost. |
| 4873 | * |
| 4874 | * @hide |
| 4875 | */ |
| 4876 | public void stopProfiling() { |
| 4877 | mProfiler.stopProfiling(); |
| 4878 | } |
| 4879 | |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 4880 | static final void handleDumpHeap(boolean managed, DumpHeapData dhd) { |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 4881 | if (managed) { |
| 4882 | try { |
| 4883 | Debug.dumpHprofData(dhd.path, dhd.fd.getFileDescriptor()); |
| 4884 | } catch (IOException e) { |
| 4885 | Slog.w(TAG, "Managed heap dump failed on path " + dhd.path |
| 4886 | + " -- can the process access this path?"); |
| 4887 | } finally { |
| 4888 | try { |
| 4889 | dhd.fd.close(); |
| 4890 | } catch (IOException e) { |
| 4891 | Slog.w(TAG, "Failure closing profile fd", e); |
| 4892 | } |
| 4893 | } |
| 4894 | } else { |
Andy McFadden | 06a6b55 | 2010-07-13 16:28:09 -0700 | [diff] [blame] | 4895 | Debug.dumpNativeHeap(dhd.fd.getFileDescriptor()); |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 4896 | } |
Dianne Hackborn | b9a5e4a | 2015-03-03 17:04:12 -0800 | [diff] [blame] | 4897 | try { |
| 4898 | ActivityManagerNative.getDefault().dumpHeapFinished(dhd.path); |
| 4899 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4900 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | b9a5e4a | 2015-03-03 17:04:12 -0800 | [diff] [blame] | 4901 | } |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 4902 | } |
| 4903 | |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 4904 | final void handleDispatchPackageBroadcast(int cmd, String[] packages) { |
| 4905 | boolean hasPkgInfo = false; |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 4906 | switch (cmd) { |
| 4907 | case IApplicationThread.PACKAGE_REMOVED: |
| 4908 | case IApplicationThread.PACKAGE_REMOVED_DONT_KILL: |
| 4909 | { |
| 4910 | final boolean killApp = cmd == IApplicationThread.PACKAGE_REMOVED; |
| 4911 | if (packages == null) { |
| 4912 | break; |
| 4913 | } |
| 4914 | synchronized (mResourcesManager) { |
| 4915 | for (int i = packages.length - 1; i >= 0; i--) { |
| 4916 | if (!hasPkgInfo) { |
| 4917 | WeakReference<LoadedApk> ref = mPackages.get(packages[i]); |
| 4918 | if (ref != null && ref.get() != null) { |
| 4919 | hasPkgInfo = true; |
| 4920 | } else { |
| 4921 | ref = mResourcePackages.get(packages[i]); |
| 4922 | if (ref != null && ref.get() != null) { |
| 4923 | hasPkgInfo = true; |
| 4924 | } |
| 4925 | } |
| 4926 | } |
| 4927 | if (killApp) { |
| 4928 | mPackages.remove(packages[i]); |
| 4929 | mResourcePackages.remove(packages[i]); |
| 4930 | } |
| 4931 | } |
| 4932 | } |
| 4933 | break; |
| 4934 | } |
| 4935 | case IApplicationThread.PACKAGE_REPLACED: |
| 4936 | { |
| 4937 | if (packages == null) { |
| 4938 | break; |
| 4939 | } |
| 4940 | synchronized (mResourcesManager) { |
| 4941 | for (int i = packages.length - 1; i >= 0; i--) { |
| 4942 | WeakReference<LoadedApk> ref = mPackages.get(packages[i]); |
| 4943 | LoadedApk pkgInfo = ref != null ? ref.get() : null; |
| 4944 | if (pkgInfo != null) { |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 4945 | hasPkgInfo = true; |
mark_chen | 89764e3 | 2014-12-12 15:38:48 +0800 | [diff] [blame] | 4946 | } else { |
| 4947 | ref = mResourcePackages.get(packages[i]); |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 4948 | pkgInfo = ref != null ? ref.get() : null; |
| 4949 | if (pkgInfo != null) { |
mark_chen | 89764e3 | 2014-12-12 15:38:48 +0800 | [diff] [blame] | 4950 | hasPkgInfo = true; |
| 4951 | } |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 4952 | } |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 4953 | // If the package is being replaced, yet it still has a valid |
| 4954 | // LoadedApk object, the package was updated with _DONT_KILL. |
| 4955 | // Adjust it's internal references to the application info and |
| 4956 | // resources. |
| 4957 | if (pkgInfo != null) { |
| 4958 | try { |
| 4959 | final String packageName = packages[i]; |
| 4960 | final ApplicationInfo aInfo = |
| 4961 | sPackageManager.getApplicationInfo( |
| 4962 | packageName, |
| 4963 | 0 /*flags*/, |
| 4964 | UserHandle.myUserId()); |
| 4965 | |
| 4966 | if (mActivities.size() > 0) { |
| 4967 | for (ActivityClientRecord ar : mActivities.values()) { |
| 4968 | if (ar.activityInfo.applicationInfo.packageName |
| 4969 | .equals(packageName)) { |
| 4970 | ar.activityInfo.applicationInfo = aInfo; |
| 4971 | ar.packageInfo = pkgInfo; |
| 4972 | } |
| 4973 | } |
| 4974 | } |
| 4975 | final List<String> oldPaths = |
| 4976 | sPackageManager.getPreviousCodePaths(packageName); |
| 4977 | pkgInfo.updateApplicationInfo(aInfo, oldPaths); |
| 4978 | } catch (RemoteException e) { |
| 4979 | } |
| 4980 | } |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 4981 | } |
| 4982 | } |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 4983 | break; |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 4984 | } |
| 4985 | } |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 4986 | ApplicationPackageManager.handlePackageBroadcast(cmd, packages, hasPkgInfo); |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 4987 | } |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 4988 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4989 | final void handleLowMemory() { |
Dianne Hackborn | 73c1416 | 2012-09-19 15:45:06 -0700 | [diff] [blame] | 4990 | ArrayList<ComponentCallbacks2> callbacks = collectComponentCallbacks(true, null); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4991 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4992 | final int N = callbacks.size(); |
| 4993 | for (int i=0; i<N; i++) { |
| 4994 | callbacks.get(i).onLowMemory(); |
| 4995 | } |
| 4996 | |
Chris Tate | ce22905 | 2009-03-25 16:44:52 -0700 | [diff] [blame] | 4997 | // Ask SQLite to free up as much memory as it can, mostly from its page caches. |
| 4998 | if (Process.myUid() != Process.SYSTEM_UID) { |
| 4999 | int sqliteReleased = SQLiteDatabase.releaseMemory(); |
| 5000 | EventLog.writeEvent(SQLITE_MEM_RELEASED_EVENT_LOG_TAG, sqliteReleased); |
| 5001 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 5002 | |
Mike Reed | caf0df1 | 2009-04-27 14:32:05 -0400 | [diff] [blame] | 5003 | // Ask graphics to free up as much as possible (font/image caches) |
| 5004 | Canvas.freeCaches(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5005 | |
Fabrice Di Meglio | 30ca5cd | 2012-05-07 17:45:44 -0700 | [diff] [blame] | 5006 | // Ask text layout engine to free also as much as possible |
| 5007 | Canvas.freeTextLayoutCaches(); |
| 5008 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5009 | BinderInternal.forceGc("mem"); |
| 5010 | } |
| 5011 | |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 5012 | final void handleTrimMemory(int level) { |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 5013 | if (DEBUG_MEMORY_TRIM) Slog.v(TAG, "Trimming memory to level: " + level); |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 5014 | |
Dianne Hackborn | 73c1416 | 2012-09-19 15:45:06 -0700 | [diff] [blame] | 5015 | ArrayList<ComponentCallbacks2> callbacks = collectComponentCallbacks(true, null); |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 5016 | |
| 5017 | final int N = callbacks.size(); |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 5018 | for (int i = 0; i < N; i++) { |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 5019 | callbacks.get(i).onTrimMemory(level); |
| 5020 | } |
Romain Guy | 19f86e8 | 2012-04-23 15:19:07 -0700 | [diff] [blame] | 5021 | |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 5022 | WindowManagerGlobal.getInstance().trimMemory(level); |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 5023 | } |
| 5024 | |
Jeff Sharkey | e1d330a | 2012-05-02 13:46:21 -0700 | [diff] [blame] | 5025 | private void setupGraphicsSupport(LoadedApk info, File cacheDir) { |
Dianne Hackborn | a0c283e | 2012-02-09 10:47:01 -0800 | [diff] [blame] | 5026 | if (Process.isIsolated()) { |
| 5027 | // Isolated processes aren't going to do UI. |
| 5028 | return; |
| 5029 | } |
Andreas Gampe | 4c8e542 | 2016-05-18 11:58:47 -0700 | [diff] [blame] | 5030 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "setupGraphicsSupport"); |
Romain Guy | a958265 | 2011-11-10 14:20:10 -0800 | [diff] [blame] | 5031 | try { |
| 5032 | int uid = Process.myUid(); |
| 5033 | String[] packages = getPackageManager().getPackagesForUid(uid); |
| 5034 | |
Shuo Gao | 7c69a66 | 2016-03-01 13:32:03 +0800 | [diff] [blame] | 5035 | if (packages != null) { |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 5036 | ThreadedRenderer.setupDiskCache(cacheDir); |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 5037 | RenderScriptCacheDir.setupDiskCache(cacheDir); |
Romain Guy | a958265 | 2011-11-10 14:20:10 -0800 | [diff] [blame] | 5038 | } |
| 5039 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5040 | throw e.rethrowFromSystemServer(); |
Andreas Gampe | 4c8e542 | 2016-05-18 11:58:47 -0700 | [diff] [blame] | 5041 | } finally { |
| 5042 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Romain Guy | a958265 | 2011-11-10 14:20:10 -0800 | [diff] [blame] | 5043 | } |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 5044 | } |
| 5045 | |
| 5046 | private void updateDefaultDensity() { |
Alan Viverette | 2ac46f1 | 2016-02-04 16:58:14 -0500 | [diff] [blame] | 5047 | final int densityDpi = mCurDefaultDisplayDpi; |
| 5048 | if (!mDensityCompatMode |
| 5049 | && densityDpi != Configuration.DENSITY_DPI_UNDEFINED |
| 5050 | && densityDpi != DisplayMetrics.DENSITY_DEVICE) { |
| 5051 | DisplayMetrics.DENSITY_DEVICE = densityDpi; |
| 5052 | Bitmap.setDefaultDensity(densityDpi); |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 5053 | } |
| 5054 | } |
| 5055 | |
Todd Kennedy | e713efc | 2016-05-10 13:45:40 -0700 | [diff] [blame] | 5056 | /** |
| 5057 | * Returns the correct library directory for the current ABI. |
| 5058 | * <p> |
| 5059 | * If we're dealing with a multi-arch application that has both 32 and 64 bit shared |
| 5060 | * libraries, we might need to choose the secondary depending on what the current |
| 5061 | * runtime's instruction set is. |
| 5062 | */ |
| 5063 | private String getInstrumentationLibrary(ApplicationInfo appInfo, InstrumentationInfo insInfo) { |
| 5064 | if (appInfo.primaryCpuAbi != null && appInfo.secondaryCpuAbi != null) { |
| 5065 | // Get the instruction set supported by the secondary ABI. In the presence |
| 5066 | // of a native bridge this might be different than the one secondary ABI used. |
| 5067 | String secondaryIsa = |
| 5068 | VMRuntime.getInstructionSet(appInfo.secondaryCpuAbi); |
| 5069 | final String secondaryDexCodeIsa = |
| 5070 | SystemProperties.get("ro.dalvik.vm.isa." + secondaryIsa); |
| 5071 | secondaryIsa = secondaryDexCodeIsa.isEmpty() ? secondaryIsa : secondaryDexCodeIsa; |
| 5072 | |
| 5073 | final String runtimeIsa = VMRuntime.getRuntime().vmInstructionSet(); |
| 5074 | if (runtimeIsa.equals(secondaryIsa)) { |
| 5075 | return insInfo.secondaryNativeLibraryDir; |
| 5076 | } |
| 5077 | } |
| 5078 | return insInfo.nativeLibraryDir; |
| 5079 | } |
| 5080 | |
Adam Lesinski | b61e405 | 2016-05-19 18:23:05 -0700 | [diff] [blame] | 5081 | /** |
| 5082 | * The LocaleList set for the app's resources may have been shuffled so that the preferred |
| 5083 | * Locale is at position 0. We must find the index of this preferred Locale in the |
| 5084 | * original LocaleList. |
| 5085 | */ |
| 5086 | private void updateLocaleListFromAppContext(Context context, LocaleList newLocaleList) { |
| 5087 | final Locale bestLocale = context.getResources().getConfiguration().getLocales().get(0); |
| 5088 | final int newLocaleListSize = newLocaleList.size(); |
| 5089 | for (int i = 0; i < newLocaleListSize; i++) { |
| 5090 | if (bestLocale.equals(newLocaleList.get(i))) { |
| 5091 | LocaleList.setDefault(newLocaleList, i); |
| 5092 | return; |
| 5093 | } |
| 5094 | } |
Adam Lesinski | 27d3016 | 2016-05-25 16:45:14 -0700 | [diff] [blame] | 5095 | |
| 5096 | // The app may have overridden the LocaleList with its own Locale |
| 5097 | // (not present in the available list). Push the chosen Locale |
| 5098 | // to the front of the list. |
| 5099 | LocaleList.setDefault(new LocaleList(bestLocale, newLocaleList)); |
Adam Lesinski | b61e405 | 2016-05-19 18:23:05 -0700 | [diff] [blame] | 5100 | } |
| 5101 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 5102 | private void handleBindApplication(AppBindData data) { |
Calin Juravle | 8f5770d | 2016-04-12 14:12:04 +0100 | [diff] [blame] | 5103 | // Register the UI Thread as a sensitive thread to the runtime. |
| 5104 | VMRuntime.registerSensitiveThread(); |
Man Cao | cfa78b2 | 2015-06-11 20:14:34 -0700 | [diff] [blame] | 5105 | if (data.trackAllocation) { |
| 5106 | DdmVmInternal.enableRecentAllocations(true); |
| 5107 | } |
| 5108 | |
Dianne Hackborn | d98885c | 2016-03-01 17:13:03 -0800 | [diff] [blame] | 5109 | // Note when this process has started. |
| 5110 | Process.setStartTimes(SystemClock.elapsedRealtime(), SystemClock.uptimeMillis()); |
| 5111 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5112 | mBoundApplication = data; |
| 5113 | mConfiguration = new Configuration(data.config); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 5114 | mCompatConfiguration = new Configuration(data.config); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5115 | |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 5116 | mProfiler = new Profiler(); |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 5117 | if (data.initProfilerInfo != null) { |
| 5118 | mProfiler.profileFile = data.initProfilerInfo.profileFile; |
| 5119 | mProfiler.profileFd = data.initProfilerInfo.profileFd; |
| 5120 | mProfiler.samplingInterval = data.initProfilerInfo.samplingInterval; |
| 5121 | mProfiler.autoStopProfiler = data.initProfilerInfo.autoStopProfiler; |
| 5122 | } |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 5123 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5124 | // send up app name; do this *before* waiting for debugger |
Christopher Tate | 8ee038d | 2009-11-06 11:30:20 -0800 | [diff] [blame] | 5125 | Process.setArgV0(data.processName); |
Siva Velusamy | d693dfa | 2012-09-10 14:36:58 -0700 | [diff] [blame] | 5126 | android.ddm.DdmHandleAppName.setAppName(data.processName, |
| 5127 | UserHandle.myUserId()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5128 | |
Dianne Hackborn | 5d927c2 | 2011-09-02 12:22:18 -0700 | [diff] [blame] | 5129 | if (data.persistent) { |
| 5130 | // Persistent processes on low-memory devices do not get to |
| 5131 | // use hardware accelerated drawing, since this can add too much |
| 5132 | // overhead to the process. |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 5133 | if (!ActivityManager.isHighEndGfx()) { |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 5134 | ThreadedRenderer.disable(false); |
Dianne Hackborn | 5d927c2 | 2011-09-02 12:22:18 -0700 | [diff] [blame] | 5135 | } |
| 5136 | } |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 5137 | |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 5138 | if (mProfiler.profileFd != null) { |
| 5139 | mProfiler.startProfiling(); |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 5140 | } |
| 5141 | |
Joe Onorato | d630f10 | 2011-03-17 18:42:26 -0700 | [diff] [blame] | 5142 | // If the app is Honeycomb MR1 or earlier, switch its AsyncTask |
| 5143 | // implementation to use the pool executor. Normally, we use the |
| 5144 | // serialized executor as the default. This has to happen in the |
| 5145 | // main thread so the main looper is set right. |
Dianne Hackborn | 81e9276 | 2011-10-09 16:00:21 -0700 | [diff] [blame] | 5146 | if (data.appInfo.targetSdkVersion <= android.os.Build.VERSION_CODES.HONEYCOMB_MR1) { |
Joe Onorato | d630f10 | 2011-03-17 18:42:26 -0700 | [diff] [blame] | 5147 | AsyncTask.setDefaultExecutor(AsyncTask.THREAD_POOL_EXECUTOR); |
| 5148 | } |
| 5149 | |
Dianne Hackborn | 7895bc2 | 2014-09-05 15:09:03 -0700 | [diff] [blame] | 5150 | Message.updateCheckRecycle(data.appInfo.targetSdkVersion); |
| 5151 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5152 | /* |
| 5153 | * Before spawning a new process, reset the time zone to be the system time zone. |
| 5154 | * This needs to be done because the system time zone could have changed after the |
| 5155 | * the spawning of this process. Without doing this this process would have the incorrect |
| 5156 | * system time zone. |
| 5157 | */ |
| 5158 | TimeZone.setDefault(null); |
| 5159 | |
Adam Lesinski | b61e405 | 2016-05-19 18:23:05 -0700 | [diff] [blame] | 5160 | /* |
| 5161 | * Set the LocaleList. This may change once we create the App Context. |
| 5162 | */ |
| 5163 | LocaleList.setDefault(data.config.getLocales()); |
| 5164 | |
| 5165 | synchronized (mResourcesManager) { |
| 5166 | /* |
| 5167 | * Update the system configuration since its preloaded and might not |
| 5168 | * reflect configuration changes. The configuration object passed |
| 5169 | * in AppBindData can be safely assumed to be up to date |
| 5170 | */ |
| 5171 | mResourcesManager.applyConfigurationToResourcesLocked(data.config, data.compatInfo); |
| 5172 | mCurDefaultDisplayDpi = data.config.densityDpi; |
| 5173 | |
| 5174 | // This calls mResourcesManager so keep it within the synchronized block. |
| 5175 | applyCompatConfiguration(mCurDefaultDisplayDpi); |
| 5176 | } |
| 5177 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 5178 | data.info = getPackageInfoNoCheck(data.appInfo, data.compatInfo); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5179 | |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 5180 | /** |
| 5181 | * Switch this process to density compatibility mode if needed. |
| 5182 | */ |
| 5183 | if ((data.appInfo.flags&ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES) |
| 5184 | == 0) { |
| 5185 | mDensityCompatMode = true; |
| 5186 | Bitmap.setDefaultDensity(DisplayMetrics.DENSITY_DEFAULT); |
| 5187 | } |
| 5188 | updateDefaultDensity(); |
| 5189 | |
Narayan Kamath | ccb2a086 | 2013-12-19 14:49:36 +0000 | [diff] [blame] | 5190 | final boolean is24Hr = "24".equals(mCoreSettings.getString(Settings.System.TIME_12_24)); |
| 5191 | DateFormat.set24HourTimePref(is24Hr); |
| 5192 | |
Jon Miranda | 836c0a8 | 2014-08-11 12:32:26 -0700 | [diff] [blame] | 5193 | View.mDebugViewAttributes = |
| 5194 | mCoreSettings.getInt(Settings.Global.DEBUG_VIEW_ATTRIBUTES, 0) != 0; |
| 5195 | |
Dianne Hackborn | 96e240f | 2009-07-26 17:42:30 -0700 | [diff] [blame] | 5196 | /** |
Brad Fitzpatrick | 438d059 | 2010-06-10 12:19:19 -0700 | [diff] [blame] | 5197 | * For system applications on userdebug/eng builds, log stack |
| 5198 | * traces of disk and network access to dropbox for analysis. |
| 5199 | */ |
Brad Fitzpatrick | ad13b98 | 2010-07-14 12:35:53 -0700 | [diff] [blame] | 5200 | if ((data.appInfo.flags & |
| 5201 | (ApplicationInfo.FLAG_SYSTEM | |
Brad Fitzpatrick | 50d66f9 | 2010-09-13 21:29:05 -0700 | [diff] [blame] | 5202 | ApplicationInfo.FLAG_UPDATED_SYSTEM_APP)) != 0) { |
| 5203 | StrictMode.conditionallyEnableDebugLogging(); |
Brad Fitzpatrick | 438d059 | 2010-06-10 12:19:19 -0700 | [diff] [blame] | 5204 | } |
| 5205 | |
| 5206 | /** |
Jeff Sharkey | 344744b | 2016-01-28 19:03:30 -0700 | [diff] [blame] | 5207 | * For apps targetting Honeycomb or later, we don't allow network usage |
| 5208 | * on the main event loop / UI thread. This is what ultimately throws |
| 5209 | * {@link NetworkOnMainThreadException}. |
Brad Fitzpatrick | b6e1841 | 2010-10-28 14:50:05 -0700 | [diff] [blame] | 5210 | */ |
Jeff Sharkey | 344744b | 2016-01-28 19:03:30 -0700 | [diff] [blame] | 5211 | if (data.appInfo.targetSdkVersion >= Build.VERSION_CODES.HONEYCOMB) { |
Brad Fitzpatrick | b6e1841 | 2010-10-28 14:50:05 -0700 | [diff] [blame] | 5212 | StrictMode.enableDeathOnNetwork(); |
| 5213 | } |
| 5214 | |
Jeff Sharkey | 344744b | 2016-01-28 19:03:30 -0700 | [diff] [blame] | 5215 | /** |
| 5216 | * For apps targetting N or later, we don't allow file:// Uri exposure. |
| 5217 | * This is what ultimately throws {@link FileUriExposedException}. |
| 5218 | */ |
| 5219 | if (data.appInfo.targetSdkVersion >= Build.VERSION_CODES.N) { |
Thierry Strudel | e60b28d | 2016-02-25 02:14:16 +0000 | [diff] [blame] | 5220 | StrictMode.enableDeathOnFileUriExposure(); |
Jeff Sharkey | 344744b | 2016-01-28 19:03:30 -0700 | [diff] [blame] | 5221 | } |
| 5222 | |
Svet Ganov | 37e4327 | 2016-09-09 16:01:32 -0700 | [diff] [blame] | 5223 | // We deprecated Build.SERIAL and only apps that target pre NMR1 |
| 5224 | // SDK can see it. Since access to the serial is now behind a |
| 5225 | // permission we push down the value and here we fix it up |
| 5226 | // before any app code has been loaded. |
| 5227 | try { |
| 5228 | Field field = Build.class.getDeclaredField("SERIAL"); |
| 5229 | field.setAccessible(true); |
| 5230 | field.set(Build.class, data.buildSerial); |
| 5231 | } catch (NoSuchFieldException | IllegalAccessException e) { |
| 5232 | /* ignore */ |
| 5233 | } |
| 5234 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5235 | if (data.debugMode != IApplicationThread.DEBUG_OFF) { |
| 5236 | // XXX should have option to change the port. |
| 5237 | Debug.changeDebugPort(8100); |
| 5238 | if (data.debugMode == IApplicationThread.DEBUG_WAIT) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 5239 | Slog.w(TAG, "Application " + data.info.getPackageName() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5240 | + " is waiting for the debugger on port 8100..."); |
| 5241 | |
| 5242 | IActivityManager mgr = ActivityManagerNative.getDefault(); |
| 5243 | try { |
| 5244 | mgr.showWaitingForDebugger(mAppThread, true); |
| 5245 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5246 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5247 | } |
| 5248 | |
| 5249 | Debug.waitForDebugger(); |
| 5250 | |
| 5251 | try { |
| 5252 | mgr.showWaitingForDebugger(mAppThread, false); |
| 5253 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5254 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5255 | } |
| 5256 | |
| 5257 | } else { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 5258 | Slog.w(TAG, "Application " + data.info.getPackageName() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5259 | + " can be debugged on port 8100..."); |
| 5260 | } |
| 5261 | } |
| 5262 | |
Jamie Gennis | f9c7d6b | 2013-03-25 14:18:25 -0700 | [diff] [blame] | 5263 | // Allow application-generated systrace messages if we're debuggable. |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 5264 | boolean isAppDebuggable = (data.appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0; |
| 5265 | Trace.setAppTracingAllowed(isAppDebuggable); |
| 5266 | if (isAppDebuggable && data.enableBinderTracking) { |
| 5267 | Binder.enableTracing(); |
| 5268 | } |
Jamie Gennis | f9c7d6b | 2013-03-25 14:18:25 -0700 | [diff] [blame] | 5269 | |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 5270 | /** |
| 5271 | * Initialize the default http proxy in this process for the reasons we set the time zone. |
| 5272 | */ |
Andreas Gampe | 4c8e542 | 2016-05-18 11:58:47 -0700 | [diff] [blame] | 5273 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "Setup proxies"); |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 5274 | final IBinder b = ServiceManager.getService(Context.CONNECTIVITY_SERVICE); |
Dianne Hackborn | d4d32c5 | 2011-11-08 17:33:59 -0800 | [diff] [blame] | 5275 | if (b != null) { |
| 5276 | // In pre-boot mode (doing initial launch to collect password), not |
| 5277 | // all system is up. This includes the connectivity service, so don't |
| 5278 | // crash if we can't get it. |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 5279 | final IConnectivityManager service = IConnectivityManager.Stub.asInterface(b); |
Dianne Hackborn | d4d32c5 | 2011-11-08 17:33:59 -0800 | [diff] [blame] | 5280 | try { |
Paul Jensen | cee9b51 | 2015-05-06 07:32:40 -0400 | [diff] [blame] | 5281 | final ProxyInfo proxyInfo = service.getProxyForNetwork(null); |
Jason Monk | 207900c | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 5282 | Proxy.setHttpProxySystemProperty(proxyInfo); |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5283 | } catch (RemoteException e) { |
Andreas Gampe | 4c8e542 | 2016-05-18 11:58:47 -0700 | [diff] [blame] | 5284 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5285 | throw e.rethrowFromSystemServer(); |
| 5286 | } |
Dianne Hackborn | d4d32c5 | 2011-11-08 17:33:59 -0800 | [diff] [blame] | 5287 | } |
Andreas Gampe | 4c8e542 | 2016-05-18 11:58:47 -0700 | [diff] [blame] | 5288 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 5289 | |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 5290 | // Instrumentation info affects the class loader, so load it before |
| 5291 | // setting up the app context. |
| 5292 | final InstrumentationInfo ii; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5293 | if (data.instrumentationName != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5294 | try { |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 5295 | ii = new ApplicationPackageManager(null, getPackageManager()) |
| 5296 | .getInstrumentationInfo(data.instrumentationName, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5297 | } catch (PackageManager.NameNotFoundException e) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5298 | throw new RuntimeException( |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 5299 | "Unable to find instrumentation info for: " + data.instrumentationName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5300 | } |
| 5301 | |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 5302 | mInstrumentationPackageName = ii.packageName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5303 | mInstrumentationAppDir = ii.sourceDir; |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 5304 | mInstrumentationSplitAppDirs = ii.splitSourceDirs; |
Todd Kennedy | e713efc | 2016-05-10 13:45:40 -0700 | [diff] [blame] | 5305 | mInstrumentationLibDir = getInstrumentationLibrary(data.appInfo, ii); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5306 | mInstrumentedAppDir = data.info.getAppDir(); |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 5307 | mInstrumentedSplitAppDirs = data.info.getSplitAppDirs(); |
| 5308 | mInstrumentedLibDir = data.info.getLibDir(); |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 5309 | } else { |
| 5310 | ii = null; |
| 5311 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5312 | |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 5313 | final ContextImpl appContext = ContextImpl.createAppContext(this, data.info); |
Adam Lesinski | b61e405 | 2016-05-19 18:23:05 -0700 | [diff] [blame] | 5314 | updateLocaleListFromAppContext(appContext, |
| 5315 | mResourcesManager.getConfiguration().getLocales()); |
Seigo Nonaka | c14dd78 | 2016-03-30 23:09:16 +0900 | [diff] [blame] | 5316 | |
Jeff Sharkey | e6cb097 | 2016-02-01 09:59:12 -0700 | [diff] [blame] | 5317 | if (!Process.isIsolated() && !"android".equals(appContext.getPackageName())) { |
Jeff Sharkey | e84bdd3 | 2016-02-08 12:16:00 -0700 | [diff] [blame] | 5318 | // This cache location probably points at credential-encrypted |
| 5319 | // storage which may not be accessible yet; assign it anyway instead |
| 5320 | // of pointing at device-encrypted storage. |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 5321 | final File cacheDir = appContext.getCacheDir(); |
| 5322 | if (cacheDir != null) { |
| 5323 | // Provide a usable directory for temporary files |
| 5324 | System.setProperty("java.io.tmpdir", cacheDir.getAbsolutePath()); |
| 5325 | } else { |
| 5326 | Log.v(TAG, "Unable to initialize \"java.io.tmpdir\" property " |
| 5327 | + "due to missing cache directory"); |
| 5328 | } |
Alan Viverette | 346296b | 2015-09-01 13:08:05 -0400 | [diff] [blame] | 5329 | |
Calin Juravle | 2a727d7 | 2016-04-15 19:33:46 +0100 | [diff] [blame] | 5330 | // Setup a location to store generated/compiled graphics code. |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 5331 | final Context deviceContext = appContext.createDeviceProtectedStorageContext(); |
Jeff Sharkey | e84bdd3 | 2016-02-08 12:16:00 -0700 | [diff] [blame] | 5332 | final File codeCacheDir = deviceContext.getCodeCacheDir(); |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 5333 | if (codeCacheDir != null) { |
| 5334 | setupGraphicsSupport(data.info, codeCacheDir); |
| 5335 | } else { |
Calin Juravle | 2a727d7 | 2016-04-15 19:33:46 +0100 | [diff] [blame] | 5336 | Log.e(TAG, "Unable to setupGraphicsSupport due to missing code-cache directory"); |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 5337 | } |
Michael Lentine | 2ba303f | 2016-02-01 20:44:34 -0600 | [diff] [blame] | 5338 | } |
Michael Lentine | 03d8f768 | 2016-01-31 15:37:11 -0600 | [diff] [blame] | 5339 | |
Chad Brubaker | 78d4712 | 2015-11-17 22:26:58 -0800 | [diff] [blame] | 5340 | // Install the Network Security Config Provider. This must happen before the application |
| 5341 | // code is loaded to prevent issues with instances of TLS objects being created before |
| 5342 | // the provider is installed. |
Andreas Gampe | 4c8e542 | 2016-05-18 11:58:47 -0700 | [diff] [blame] | 5343 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "NetworkSecurityConfigProvider.install"); |
Chad Brubaker | 276ee96 | 2016-06-08 12:57:46 -0700 | [diff] [blame] | 5344 | NetworkSecurityConfigProvider.install(appContext); |
Andreas Gampe | 4c8e542 | 2016-05-18 11:58:47 -0700 | [diff] [blame] | 5345 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Chad Brubaker | 78d4712 | 2015-11-17 22:26:58 -0800 | [diff] [blame] | 5346 | |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 5347 | // Continue loading instrumentation. |
| 5348 | if (ii != null) { |
Alan Viverette | 346296b | 2015-09-01 13:08:05 -0400 | [diff] [blame] | 5349 | final ApplicationInfo instrApp = new ApplicationInfo(); |
Jeff Sharkey | 1544779 | 2015-11-05 16:18:51 -0800 | [diff] [blame] | 5350 | ii.copyTo(instrApp); |
Fyodor Kupolov | af38b8e | 2015-12-02 16:16:07 -0800 | [diff] [blame] | 5351 | instrApp.initForUser(UserHandle.myUserId()); |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 5352 | final LoadedApk pi = getPackageInfo(instrApp, data.compatInfo, |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 5353 | appContext.getClassLoader(), false, true, false); |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 5354 | final ContextImpl instrContext = ContextImpl.createAppContext(this, pi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5355 | |
| 5356 | try { |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 5357 | final ClassLoader cl = instrContext.getClassLoader(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5358 | mInstrumentation = (Instrumentation) |
| 5359 | cl.loadClass(data.instrumentationName.getClassName()).newInstance(); |
| 5360 | } catch (Exception e) { |
| 5361 | throw new RuntimeException( |
| 5362 | "Unable to instantiate instrumentation " |
| 5363 | + data.instrumentationName + ": " + e.toString(), e); |
| 5364 | } |
| 5365 | |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 5366 | final ComponentName component = new ComponentName(ii.packageName, ii.name); |
| 5367 | mInstrumentation.init(this, instrContext, appContext, component, |
| 5368 | data.instrumentationWatcher, data.instrumentationUiAutomationConnection); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5369 | |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 5370 | if (mProfiler.profileFile != null && !ii.handleProfiling |
| 5371 | && mProfiler.profileFd == null) { |
| 5372 | mProfiler.handlingProfiling = true; |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 5373 | final File file = new File(mProfiler.profileFile); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5374 | file.getParentFile().mkdirs(); |
| 5375 | Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024); |
| 5376 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5377 | } else { |
| 5378 | mInstrumentation = new Instrumentation(); |
| 5379 | } |
| 5380 | |
Dianne Hackborn | 3b81bc1 | 2011-01-15 11:50:52 -0800 | [diff] [blame] | 5381 | if ((data.appInfo.flags&ApplicationInfo.FLAG_LARGE_HEAP) != 0) { |
Dianne Hackborn | de39851 | 2011-01-18 18:45:21 -0800 | [diff] [blame] | 5382 | dalvik.system.VMRuntime.getRuntime().clearGrowthLimit(); |
Mathieu Chartier | 24cee07 | 2015-01-08 14:42:20 -0800 | [diff] [blame] | 5383 | } else { |
| 5384 | // Small heap, clamp to the current growth limit and let the heap release |
| 5385 | // pages after the growth limit to the non growth limit capacity. b/18387825 |
| 5386 | dalvik.system.VMRuntime.getRuntime().clampGrowthLimit(); |
Dianne Hackborn | 3b81bc1 | 2011-01-15 11:50:52 -0800 | [diff] [blame] | 5387 | } |
| 5388 | |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 5389 | // Allow disk access during application and provider setup. This could |
Jeff Sharkey | 7c50167 | 2012-02-28 12:08:37 -0800 | [diff] [blame] | 5390 | // block processing ordered broadcasts, but later processing would |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 5391 | // probably end up doing the same disk access. |
Jeff Sharkey | 7c50167 | 2012-02-28 12:08:37 -0800 | [diff] [blame] | 5392 | final StrictMode.ThreadPolicy savedPolicy = StrictMode.allowThreadDiskWrites(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5393 | try { |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 5394 | // If the app is being launched for full backup or restore, bring it up in |
| 5395 | // a restricted environment with the base application class. |
| 5396 | Application app = data.info.makeApplication(data.restrictedBackupMode, null); |
| 5397 | mInitialApplication = app; |
Jeff Sharkey | 7c50167 | 2012-02-28 12:08:37 -0800 | [diff] [blame] | 5398 | |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 5399 | // don't bring up providers in restricted mode; they may depend on the |
| 5400 | // app's custom Application class |
| 5401 | if (!data.restrictedBackupMode) { |
Jeff Sharkey | 3e19589 | 2016-03-05 19:48:59 -0700 | [diff] [blame] | 5402 | if (!ArrayUtils.isEmpty(data.providers)) { |
| 5403 | installContentProviders(app, data.providers); |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 5404 | // For process that contains content providers, we want to |
| 5405 | // ensure that the JIT is enabled "at some point". |
| 5406 | mH.sendEmptyMessageDelayed(H.ENABLE_JIT, 10*1000); |
| 5407 | } |
| 5408 | } |
| 5409 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5410 | // Do this after providers, since instrumentation tests generally start their |
| 5411 | // test thread at this point, and we don't want that racing. |
| 5412 | try { |
| 5413 | mInstrumentation.onCreate(data.instrumentationArgs); |
| 5414 | } |
| 5415 | catch (Exception e) { |
| 5416 | throw new RuntimeException( |
| 5417 | "Exception thrown in onCreate() of " |
| 5418 | + data.instrumentationName + ": " + e.toString(), e); |
| 5419 | } |
| 5420 | |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 5421 | try { |
| 5422 | mInstrumentation.callApplicationOnCreate(app); |
| 5423 | } catch (Exception e) { |
| 5424 | if (!mInstrumentation.onException(app, e)) { |
| 5425 | throw new RuntimeException( |
| 5426 | "Unable to create application " + app.getClass().getName() |
| 5427 | + ": " + e.toString(), e); |
| 5428 | } |
| 5429 | } |
| 5430 | } finally { |
| 5431 | StrictMode.setThreadPolicy(savedPolicy); |
| 5432 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5433 | } |
| 5434 | |
| 5435 | /*package*/ final void finishInstrumentation(int resultCode, Bundle results) { |
| 5436 | IActivityManager am = ActivityManagerNative.getDefault(); |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 5437 | if (mProfiler.profileFile != null && mProfiler.handlingProfiling |
| 5438 | && mProfiler.profileFd == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5439 | Debug.stopMethodTracing(); |
| 5440 | } |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 5441 | //Slog.i(TAG, "am: " + ActivityManagerNative.getDefault() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5442 | // + ", app thr: " + mAppThread); |
| 5443 | try { |
| 5444 | am.finishInstrumentation(mAppThread, resultCode, results); |
| 5445 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5446 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5447 | } |
| 5448 | } |
| 5449 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 5450 | private void installContentProviders( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5451 | Context context, List<ProviderInfo> providers) { |
| 5452 | final ArrayList<IActivityManager.ContentProviderHolder> results = |
| 5453 | new ArrayList<IActivityManager.ContentProviderHolder>(); |
| 5454 | |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 5455 | for (ProviderInfo cpi : providers) { |
Dianne Hackborn | 40e9f29 | 2012-11-27 19:12:23 -0800 | [diff] [blame] | 5456 | if (DEBUG_PROVIDER) { |
| 5457 | StringBuilder buf = new StringBuilder(128); |
| 5458 | buf.append("Pub "); |
| 5459 | buf.append(cpi.authority); |
| 5460 | buf.append(": "); |
| 5461 | buf.append(cpi.name); |
| 5462 | Log.i(TAG, buf.toString()); |
| 5463 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5464 | IActivityManager.ContentProviderHolder cph = installProvider(context, null, cpi, |
| 5465 | false /*noisy*/, true /*noReleaseNeeded*/, true /*stable*/); |
| 5466 | if (cph != null) { |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5467 | cph.noReleaseNeeded = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5468 | results.add(cph); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5469 | } |
| 5470 | } |
| 5471 | |
| 5472 | try { |
| 5473 | ActivityManagerNative.getDefault().publishContentProviders( |
| 5474 | getApplicationThread(), results); |
| 5475 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5476 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5477 | } |
| 5478 | } |
| 5479 | |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 5480 | public final IContentProvider acquireProvider( |
| 5481 | Context c, String auth, int userId, boolean stable) { |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 5482 | final IContentProvider provider = acquireExistingProvider(c, auth, userId, stable); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5483 | if (provider != null) { |
| 5484 | return provider; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5485 | } |
| 5486 | |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 5487 | // There is a possible race here. Another thread may try to acquire |
| 5488 | // the same provider at the same time. When this happens, we want to ensure |
| 5489 | // that the first one wins. |
| 5490 | // Note that we cannot hold the lock while acquiring and installing the |
| 5491 | // provider since it might take a long time to run and it could also potentially |
| 5492 | // be re-entrant in the case where the provider is in the same process. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5493 | IActivityManager.ContentProviderHolder holder = null; |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 5494 | try { |
| 5495 | holder = ActivityManagerNative.getDefault().getContentProvider( |
| 5496 | getApplicationThread(), auth, userId, stable); |
| 5497 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5498 | throw ex.rethrowFromSystemServer(); |
Wale Ogunwale | 67fe0a4 | 2015-04-24 14:44:54 -0700 | [diff] [blame] | 5499 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5500 | if (holder == null) { |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 5501 | 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] | 5502 | return null; |
| 5503 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5504 | |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5505 | // Install provider will increment the reference count for us, and break |
| 5506 | // any ties in the race. |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5507 | holder = installProvider(c, holder, holder.info, |
| 5508 | true /*noisy*/, holder.noReleaseNeeded, stable); |
| 5509 | return holder.provider; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5510 | } |
| 5511 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5512 | private final void incProviderRefLocked(ProviderRefCount prc, boolean stable) { |
| 5513 | if (stable) { |
| 5514 | prc.stableCount += 1; |
| 5515 | if (prc.stableCount == 1) { |
| 5516 | // We are acquiring a new stable reference on the provider. |
| 5517 | int unstableDelta; |
| 5518 | if (prc.removePending) { |
| 5519 | // We have a pending remove operation, which is holding the |
| 5520 | // last unstable reference. At this point we are converting |
| 5521 | // that unstable reference to our new stable reference. |
| 5522 | unstableDelta = -1; |
| 5523 | // Cancel the removal of the provider. |
| 5524 | if (DEBUG_PROVIDER) { |
| 5525 | Slog.v(TAG, "incProviderRef: stable " |
| 5526 | + "snatched provider from the jaws of death"); |
| 5527 | } |
| 5528 | prc.removePending = false; |
Guobin Zhang | 9e3e5266 | 2013-03-21 13:57:11 +0800 | [diff] [blame] | 5529 | // There is a race! It fails to remove the message, which |
| 5530 | // will be handled in completeRemoveProvider(). |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5531 | mH.removeMessages(H.REMOVE_PROVIDER, prc); |
| 5532 | } else { |
| 5533 | unstableDelta = 0; |
| 5534 | } |
| 5535 | try { |
| 5536 | if (DEBUG_PROVIDER) { |
| 5537 | Slog.v(TAG, "incProviderRef Now stable - " |
| 5538 | + prc.holder.info.name + ": unstableDelta=" |
| 5539 | + unstableDelta); |
| 5540 | } |
| 5541 | ActivityManagerNative.getDefault().refContentProvider( |
| 5542 | prc.holder.connection, 1, unstableDelta); |
| 5543 | } catch (RemoteException e) { |
| 5544 | //do nothing content provider object is dead any way |
| 5545 | } |
| 5546 | } |
| 5547 | } else { |
| 5548 | prc.unstableCount += 1; |
| 5549 | if (prc.unstableCount == 1) { |
| 5550 | // We are acquiring a new unstable reference on the provider. |
| 5551 | if (prc.removePending) { |
| 5552 | // Oh look, we actually have a remove pending for the |
| 5553 | // provider, which is still holding the last unstable |
| 5554 | // reference. We just need to cancel that to take new |
| 5555 | // ownership of the reference. |
| 5556 | if (DEBUG_PROVIDER) { |
| 5557 | Slog.v(TAG, "incProviderRef: unstable " |
| 5558 | + "snatched provider from the jaws of death"); |
| 5559 | } |
| 5560 | prc.removePending = false; |
| 5561 | mH.removeMessages(H.REMOVE_PROVIDER, prc); |
| 5562 | } else { |
| 5563 | // First unstable ref, increment our count in the |
| 5564 | // activity manager. |
| 5565 | try { |
| 5566 | if (DEBUG_PROVIDER) { |
| 5567 | Slog.v(TAG, "incProviderRef: Now unstable - " |
| 5568 | + prc.holder.info.name); |
| 5569 | } |
| 5570 | ActivityManagerNative.getDefault().refContentProvider( |
| 5571 | prc.holder.connection, 0, 1); |
| 5572 | } catch (RemoteException e) { |
| 5573 | //do nothing content provider object is dead any way |
| 5574 | } |
| 5575 | } |
| 5576 | } |
| 5577 | } |
| 5578 | } |
| 5579 | |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 5580 | public final IContentProvider acquireExistingProvider( |
| 5581 | Context c, String auth, int userId, boolean stable) { |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5582 | synchronized (mProviderMap) { |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 5583 | final ProviderKey key = new ProviderKey(auth, userId); |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 5584 | final ProviderClientRecord pr = mProviderMap.get(key); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5585 | if (pr == null) { |
| 5586 | return null; |
| 5587 | } |
| 5588 | |
| 5589 | IContentProvider provider = pr.mProvider; |
| 5590 | IBinder jBinder = provider.asBinder(); |
Dianne Hackborn | c428aae | 2012-10-03 16:38:22 -0700 | [diff] [blame] | 5591 | if (!jBinder.isBinderAlive()) { |
| 5592 | // The hosting process of the provider has died; we can't |
| 5593 | // use this one. |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 5594 | Log.i(TAG, "Acquiring provider " + auth + " for user " + userId |
Dianne Hackborn | c428aae | 2012-10-03 16:38:22 -0700 | [diff] [blame] | 5595 | + ": existing object's process dead"); |
| 5596 | handleUnstableProviderDiedLocked(jBinder, true); |
| 5597 | return null; |
| 5598 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5599 | |
| 5600 | // Only increment the ref count if we have one. If we don't then the |
| 5601 | // provider is not reference counted and never needs to be released. |
Dianne Hackborn | cca1f0e | 2010-09-26 18:34:53 -0700 | [diff] [blame] | 5602 | ProviderRefCount prc = mProviderRefCountMap.get(jBinder); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5603 | if (prc != null) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5604 | incProviderRefLocked(prc, stable); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5605 | } |
| 5606 | return provider; |
| 5607 | } |
Dianne Hackborn | cca1f0e | 2010-09-26 18:34:53 -0700 | [diff] [blame] | 5608 | } |
| 5609 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5610 | public final boolean releaseProvider(IContentProvider provider, boolean stable) { |
| 5611 | if (provider == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5612 | return false; |
| 5613 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5614 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5615 | IBinder jBinder = provider.asBinder(); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5616 | synchronized (mProviderMap) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5617 | ProviderRefCount prc = mProviderRefCountMap.get(jBinder); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5618 | if (prc == null) { |
| 5619 | // 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] | 5620 | return false; |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5621 | } |
| 5622 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5623 | boolean lastRef = false; |
| 5624 | if (stable) { |
| 5625 | if (prc.stableCount == 0) { |
| 5626 | if (DEBUG_PROVIDER) Slog.v(TAG, |
| 5627 | "releaseProvider: stable ref count already 0, how?"); |
| 5628 | return false; |
| 5629 | } |
| 5630 | prc.stableCount -= 1; |
| 5631 | if (prc.stableCount == 0) { |
| 5632 | // What we do at this point depends on whether there are |
| 5633 | // any unstable refs left: if there are, we just tell the |
| 5634 | // activity manager to decrement its stable count; if there |
| 5635 | // aren't, we need to enqueue this provider to be removed, |
| 5636 | // and convert to holding a single unstable ref while |
| 5637 | // doing so. |
| 5638 | lastRef = prc.unstableCount == 0; |
| 5639 | try { |
| 5640 | if (DEBUG_PROVIDER) { |
| 5641 | Slog.v(TAG, "releaseProvider: No longer stable w/lastRef=" |
| 5642 | + lastRef + " - " + prc.holder.info.name); |
| 5643 | } |
| 5644 | ActivityManagerNative.getDefault().refContentProvider( |
| 5645 | prc.holder.connection, -1, lastRef ? 1 : 0); |
| 5646 | } catch (RemoteException e) { |
| 5647 | //do nothing content provider object is dead any way |
| 5648 | } |
| 5649 | } |
| 5650 | } else { |
| 5651 | if (prc.unstableCount == 0) { |
| 5652 | if (DEBUG_PROVIDER) Slog.v(TAG, |
| 5653 | "releaseProvider: unstable ref count already 0, how?"); |
| 5654 | return false; |
| 5655 | } |
| 5656 | prc.unstableCount -= 1; |
| 5657 | if (prc.unstableCount == 0) { |
| 5658 | // If this is the last reference, we need to enqueue |
| 5659 | // this provider to be removed instead of telling the |
| 5660 | // activity manager to remove it at this point. |
| 5661 | lastRef = prc.stableCount == 0; |
| 5662 | if (!lastRef) { |
| 5663 | try { |
| 5664 | if (DEBUG_PROVIDER) { |
| 5665 | Slog.v(TAG, "releaseProvider: No longer unstable - " |
| 5666 | + prc.holder.info.name); |
| 5667 | } |
| 5668 | ActivityManagerNative.getDefault().refContentProvider( |
| 5669 | prc.holder.connection, 0, -1); |
| 5670 | } catch (RemoteException e) { |
| 5671 | //do nothing content provider object is dead any way |
| 5672 | } |
| 5673 | } |
| 5674 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5675 | } |
| 5676 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5677 | if (lastRef) { |
| 5678 | if (!prc.removePending) { |
| 5679 | // Schedule the actual remove asynchronously, since we don't know the context |
| 5680 | // this will be called in. |
| 5681 | // TODO: it would be nice to post a delayed message, so |
| 5682 | // if we come back and need the same provider quickly |
| 5683 | // we will still have it available. |
| 5684 | if (DEBUG_PROVIDER) { |
| 5685 | Slog.v(TAG, "releaseProvider: Enqueueing pending removal - " |
| 5686 | + prc.holder.info.name); |
| 5687 | } |
| 5688 | prc.removePending = true; |
| 5689 | Message msg = mH.obtainMessage(H.REMOVE_PROVIDER, prc); |
| 5690 | mH.sendMessage(msg); |
| 5691 | } else { |
| 5692 | Slog.w(TAG, "Duplicate remove pending of provider " + prc.holder.info.name); |
| 5693 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5694 | } |
| 5695 | return true; |
| 5696 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5697 | } |
| 5698 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5699 | final void completeRemoveProvider(ProviderRefCount prc) { |
| 5700 | synchronized (mProviderMap) { |
| 5701 | if (!prc.removePending) { |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5702 | // There was a race! Some other client managed to acquire |
| 5703 | // the provider before the removal was completed. |
| 5704 | // Abort the removal. We will do it later. |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5705 | if (DEBUG_PROVIDER) Slog.v(TAG, "completeRemoveProvider: lost the race, " |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5706 | + "provider still in use"); |
| 5707 | return; |
| 5708 | } |
| 5709 | |
Guobin Zhang | 9e3e5266 | 2013-03-21 13:57:11 +0800 | [diff] [blame] | 5710 | // More complicated race!! Some client managed to acquire the |
| 5711 | // provider and release it before the removal was completed. |
| 5712 | // Continue the removal, and abort the next remove message. |
| 5713 | prc.removePending = false; |
| 5714 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5715 | final IBinder jBinder = prc.holder.provider.asBinder(); |
| 5716 | ProviderRefCount existingPrc = mProviderRefCountMap.get(jBinder); |
| 5717 | if (existingPrc == prc) { |
| 5718 | mProviderRefCountMap.remove(jBinder); |
| 5719 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5720 | |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 5721 | for (int i=mProviderMap.size()-1; i>=0; i--) { |
| 5722 | ProviderClientRecord pr = mProviderMap.valueAt(i); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5723 | IBinder myBinder = pr.mProvider.asBinder(); |
| 5724 | if (myBinder == jBinder) { |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 5725 | mProviderMap.removeAt(i); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5726 | } |
| 5727 | } |
| 5728 | } |
| 5729 | |
| 5730 | try { |
| 5731 | if (DEBUG_PROVIDER) { |
| 5732 | Slog.v(TAG, "removeProvider: Invoking ActivityManagerNative." |
| 5733 | + "removeContentProvider(" + prc.holder.info.name + ")"); |
| 5734 | } |
| 5735 | ActivityManagerNative.getDefault().removeContentProvider( |
| 5736 | prc.holder.connection, false); |
| 5737 | } catch (RemoteException e) { |
| 5738 | //do nothing content provider object is dead any way |
| 5739 | } |
| 5740 | } |
| 5741 | |
| 5742 | final void handleUnstableProviderDied(IBinder provider, boolean fromClient) { |
Dianne Hackborn | c428aae | 2012-10-03 16:38:22 -0700 | [diff] [blame] | 5743 | synchronized (mProviderMap) { |
| 5744 | handleUnstableProviderDiedLocked(provider, fromClient); |
| 5745 | } |
| 5746 | } |
| 5747 | |
| 5748 | final void handleUnstableProviderDiedLocked(IBinder provider, boolean fromClient) { |
| 5749 | ProviderRefCount prc = mProviderRefCountMap.get(provider); |
| 5750 | if (prc != null) { |
| 5751 | if (DEBUG_PROVIDER) Slog.v(TAG, "Cleaning up dead provider " |
| 5752 | + provider + " " + prc.holder.info.name); |
| 5753 | mProviderRefCountMap.remove(provider); |
You Kim | bc74de6 | 2013-10-01 00:13:26 +0900 | [diff] [blame] | 5754 | for (int i=mProviderMap.size()-1; i>=0; i--) { |
| 5755 | ProviderClientRecord pr = mProviderMap.valueAt(i); |
| 5756 | if (pr != null && pr.mProvider.asBinder() == provider) { |
| 5757 | Slog.i(TAG, "Removing dead content provider:" + pr.mProvider.toString()); |
| 5758 | mProviderMap.removeAt(i); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5759 | } |
Dianne Hackborn | c428aae | 2012-10-03 16:38:22 -0700 | [diff] [blame] | 5760 | } |
You Kim | bc74de6 | 2013-10-01 00:13:26 +0900 | [diff] [blame] | 5761 | |
Dianne Hackborn | c428aae | 2012-10-03 16:38:22 -0700 | [diff] [blame] | 5762 | if (fromClient) { |
| 5763 | // We found out about this due to execution in our client |
| 5764 | // code. Tell the activity manager about it now, to ensure |
| 5765 | // that the next time we go to do anything with the provider |
| 5766 | // it knows it is dead (so we don't race with its death |
| 5767 | // notification). |
| 5768 | try { |
| 5769 | ActivityManagerNative.getDefault().unstableProviderDied( |
| 5770 | prc.holder.connection); |
| 5771 | } catch (RemoteException e) { |
| 5772 | //do nothing content provider object is dead any way |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5773 | } |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 5774 | } |
| 5775 | } |
| 5776 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5777 | |
Jeff Sharkey | 7aa7601 | 2013-09-30 14:26:27 -0700 | [diff] [blame] | 5778 | final void appNotRespondingViaProvider(IBinder provider) { |
| 5779 | synchronized (mProviderMap) { |
| 5780 | ProviderRefCount prc = mProviderRefCountMap.get(provider); |
| 5781 | if (prc != null) { |
| 5782 | try { |
| 5783 | ActivityManagerNative.getDefault() |
| 5784 | .appNotRespondingViaProvider(prc.holder.connection); |
| 5785 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5786 | throw e.rethrowFromSystemServer(); |
Jeff Sharkey | 7aa7601 | 2013-09-30 14:26:27 -0700 | [diff] [blame] | 5787 | } |
| 5788 | } |
| 5789 | } |
| 5790 | } |
| 5791 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5792 | private ProviderClientRecord installProviderAuthoritiesLocked(IContentProvider provider, |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 5793 | ContentProvider localProvider, IActivityManager.ContentProviderHolder holder) { |
Andreas Gampe | 18e99c1 | 2015-03-06 15:29:06 -0800 | [diff] [blame] | 5794 | final String auths[] = holder.info.authority.split(";"); |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 5795 | final int userId = UserHandle.getUserId(holder.info.applicationInfo.uid); |
| 5796 | |
| 5797 | final ProviderClientRecord pcr = new ProviderClientRecord( |
| 5798 | auths, provider, localProvider, holder); |
| 5799 | for (String auth : auths) { |
| 5800 | final ProviderKey key = new ProviderKey(auth, userId); |
| 5801 | final ProviderClientRecord existing = mProviderMap.get(key); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5802 | if (existing != null) { |
| 5803 | Slog.w(TAG, "Content provider " + pcr.mHolder.info.name |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 5804 | + " already published as " + auth); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5805 | } else { |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 5806 | mProviderMap.put(key, pcr); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5807 | } |
| 5808 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5809 | return pcr; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5810 | } |
| 5811 | |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5812 | /** |
| 5813 | * Installs the provider. |
| 5814 | * |
| 5815 | * Providers that are local to the process or that come from the system server |
| 5816 | * may be installed permanently which is indicated by setting noReleaseNeeded to true. |
| 5817 | * Other remote providers are reference counted. The initial reference count |
| 5818 | * for all reference counted providers is one. Providers that are not reference |
| 5819 | * counted do not have a reference count (at all). |
| 5820 | * |
| 5821 | * This method detects when a provider has already been installed. When this happens, |
| 5822 | * it increments the reference count of the existing provider (if appropriate) |
| 5823 | * and returns the existing provider. This can happen due to concurrent |
| 5824 | * attempts to acquire the same provider. |
| 5825 | */ |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5826 | private IActivityManager.ContentProviderHolder installProvider(Context context, |
| 5827 | IActivityManager.ContentProviderHolder holder, ProviderInfo info, |
| 5828 | boolean noisy, boolean noReleaseNeeded, boolean stable) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5829 | ContentProvider localProvider = null; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5830 | IContentProvider provider; |
Dianne Hackborn | 5f48fca | 2012-05-30 11:06:31 -0700 | [diff] [blame] | 5831 | if (holder == null || holder.provider == null) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5832 | if (DEBUG_PROVIDER || noisy) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 5833 | Slog.d(TAG, "Loading provider " + info.authority + ": " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5834 | + info.name); |
| 5835 | } |
| 5836 | Context c = null; |
| 5837 | ApplicationInfo ai = info.applicationInfo; |
| 5838 | if (context.getPackageName().equals(ai.packageName)) { |
| 5839 | c = context; |
| 5840 | } else if (mInitialApplication != null && |
| 5841 | mInitialApplication.getPackageName().equals(ai.packageName)) { |
| 5842 | c = mInitialApplication; |
| 5843 | } else { |
| 5844 | try { |
| 5845 | c = context.createPackageContext(ai.packageName, |
| 5846 | Context.CONTEXT_INCLUDE_CODE); |
| 5847 | } catch (PackageManager.NameNotFoundException e) { |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 5848 | // Ignore |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5849 | } |
| 5850 | } |
| 5851 | if (c == null) { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 5852 | Slog.w(TAG, "Unable to get context for package " + |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5853 | ai.packageName + |
| 5854 | " while loading content provider " + |
| 5855 | info.name); |
| 5856 | return null; |
| 5857 | } |
| 5858 | try { |
| 5859 | final java.lang.ClassLoader cl = c.getClassLoader(); |
| 5860 | localProvider = (ContentProvider)cl. |
| 5861 | loadClass(info.name).newInstance(); |
| 5862 | provider = localProvider.getIContentProvider(); |
| 5863 | if (provider == null) { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 5864 | Slog.e(TAG, "Failed to instantiate class " + |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5865 | info.name + " from sourceDir " + |
| 5866 | info.applicationInfo.sourceDir); |
| 5867 | return null; |
| 5868 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5869 | if (DEBUG_PROVIDER) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5870 | TAG, "Instantiating local provider " + info.name); |
| 5871 | // XXX Need to create the correct context for this provider. |
| 5872 | localProvider.attachInfo(c, info); |
| 5873 | } catch (java.lang.Exception e) { |
| 5874 | if (!mInstrumentation.onException(null, e)) { |
| 5875 | throw new RuntimeException( |
| 5876 | "Unable to get provider " + info.name |
| 5877 | + ": " + e.toString(), e); |
| 5878 | } |
| 5879 | return null; |
| 5880 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5881 | } else { |
| 5882 | provider = holder.provider; |
| 5883 | 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] | 5884 | + info.name); |
| 5885 | } |
| 5886 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5887 | IActivityManager.ContentProviderHolder retHolder; |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5888 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5889 | synchronized (mProviderMap) { |
| 5890 | if (DEBUG_PROVIDER) Slog.v(TAG, "Checking to add " + provider |
| 5891 | + " / " + info.name); |
| 5892 | IBinder jBinder = provider.asBinder(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5893 | if (localProvider != null) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5894 | ComponentName cname = new ComponentName(info.packageName, info.name); |
| 5895 | ProviderClientRecord pr = mLocalProvidersByName.get(cname); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5896 | if (pr != null) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5897 | if (DEBUG_PROVIDER) { |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5898 | Slog.v(TAG, "installProvider: lost the race, " |
| 5899 | + "using existing local provider"); |
| 5900 | } |
| 5901 | provider = pr.mProvider; |
| 5902 | } else { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5903 | holder = new IActivityManager.ContentProviderHolder(info); |
| 5904 | holder.provider = provider; |
| 5905 | holder.noReleaseNeeded = true; |
| 5906 | pr = installProviderAuthoritiesLocked(provider, localProvider, holder); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5907 | mLocalProviders.put(jBinder, pr); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5908 | mLocalProvidersByName.put(cname, pr); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5909 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5910 | retHolder = pr.mHolder; |
| 5911 | } else { |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5912 | ProviderRefCount prc = mProviderRefCountMap.get(jBinder); |
| 5913 | if (prc != null) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5914 | if (DEBUG_PROVIDER) { |
| 5915 | Slog.v(TAG, "installProvider: lost the race, updating ref count"); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5916 | } |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 5917 | // We need to transfer our new reference to the existing |
| 5918 | // ref count, releasing the old one... but only if |
| 5919 | // release is needed (that is, it is not running in the |
| 5920 | // system process). |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5921 | if (!noReleaseNeeded) { |
| 5922 | incProviderRefLocked(prc, stable); |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 5923 | try { |
| 5924 | ActivityManagerNative.getDefault().removeContentProvider( |
| 5925 | holder.connection, stable); |
| 5926 | } catch (RemoteException e) { |
| 5927 | //do nothing content provider object is dead any way |
| 5928 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5929 | } |
| 5930 | } else { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5931 | ProviderClientRecord client = installProviderAuthoritiesLocked( |
| 5932 | provider, localProvider, holder); |
| 5933 | if (noReleaseNeeded) { |
| 5934 | prc = new ProviderRefCount(holder, client, 1000, 1000); |
| 5935 | } else { |
| 5936 | prc = stable |
| 5937 | ? new ProviderRefCount(holder, client, 1, 0) |
| 5938 | : new ProviderRefCount(holder, client, 0, 1); |
| 5939 | } |
| 5940 | mProviderRefCountMap.put(jBinder, prc); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5941 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5942 | retHolder = prc.holder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5943 | } |
| 5944 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5945 | |
| 5946 | return retHolder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5947 | } |
| 5948 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 5949 | private void attach(boolean system) { |
Jeff Sharkey | 66a017b | 2013-01-17 18:18:22 -0800 | [diff] [blame] | 5950 | sCurrentActivityThread = this; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5951 | mSystemThread = system; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5952 | if (!system) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 5953 | ViewRootImpl.addFirstDrawHandler(new Runnable() { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 5954 | @Override |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 5955 | public void run() { |
| 5956 | ensureJitEnabled(); |
| 5957 | } |
| 5958 | }); |
Siva Velusamy | d693dfa | 2012-09-10 14:36:58 -0700 | [diff] [blame] | 5959 | android.ddm.DdmHandleAppName.setAppName("<pre-initialized>", |
| 5960 | UserHandle.myUserId()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5961 | RuntimeInit.setApplicationObject(mAppThread.asBinder()); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 5962 | final IActivityManager mgr = ActivityManagerNative.getDefault(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5963 | try { |
| 5964 | mgr.attachApplication(mAppThread); |
| 5965 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5966 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5967 | } |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 5968 | // Watch for getting close to heap limit. |
| 5969 | BinderInternal.addGcWatcher(new Runnable() { |
| 5970 | @Override public void run() { |
| 5971 | if (!mSomeActivitiesChanged) { |
| 5972 | return; |
| 5973 | } |
| 5974 | Runtime runtime = Runtime.getRuntime(); |
| 5975 | long dalvikMax = runtime.maxMemory(); |
| 5976 | long dalvikUsed = runtime.totalMemory() - runtime.freeMemory(); |
| 5977 | if (dalvikUsed > ((3*dalvikMax)/4)) { |
| 5978 | if (DEBUG_MEMORY_TRIM) Slog.d(TAG, "Dalvik max=" + (dalvikMax/1024) |
| 5979 | + " total=" + (runtime.totalMemory()/1024) |
| 5980 | + " used=" + (dalvikUsed/1024)); |
| 5981 | mSomeActivitiesChanged = false; |
| 5982 | try { |
| 5983 | mgr.releaseSomeActivities(mAppThread); |
| 5984 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5985 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 5986 | } |
| 5987 | } |
| 5988 | } |
| 5989 | }); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5990 | } else { |
| 5991 | // Don't set application object here -- if the system crashes, |
| 5992 | // 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] | 5993 | android.ddm.DdmHandleAppName.setAppName("system_process", |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 5994 | UserHandle.myUserId()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5995 | try { |
| 5996 | mInstrumentation = new Instrumentation(); |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 5997 | ContextImpl context = ContextImpl.createAppContext( |
| 5998 | this, getSystemContext().mPackageInfo); |
Jeff Brown | 7fc8e35 | 2014-09-16 18:06:47 -0700 | [diff] [blame] | 5999 | mInitialApplication = context.mPackageInfo.makeApplication(true, null); |
| 6000 | mInitialApplication.onCreate(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6001 | } catch (Exception e) { |
| 6002 | throw new RuntimeException( |
| 6003 | "Unable to instantiate Application():" + e.toString(), e); |
| 6004 | } |
| 6005 | } |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 6006 | |
| 6007 | // add dropbox logging to libcore |
| 6008 | DropBox.setReporter(new DropBoxReporter()); |
| 6009 | |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 6010 | ViewRootImpl.addConfigCallback(new ComponentCallbacks2() { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 6011 | @Override |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6012 | public void onConfigurationChanged(Configuration newConfig) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 6013 | synchronized (mResourcesManager) { |
Dianne Hackborn | ae07816 | 2010-03-18 11:29:37 -0700 | [diff] [blame] | 6014 | // We need to apply this change to the resources |
| 6015 | // immediately, because upon returning the view |
| 6016 | // hierarchy will be informed about it. |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 6017 | if (mResourcesManager.applyConfigurationToResourcesLocked(newConfig, null)) { |
Adam Lesinski | b61e405 | 2016-05-19 18:23:05 -0700 | [diff] [blame] | 6018 | updateLocaleListFromAppContext(mInitialApplication.getApplicationContext(), |
| 6019 | mResourcesManager.getConfiguration().getLocales()); |
| 6020 | |
Dianne Hackborn | ae07816 | 2010-03-18 11:29:37 -0700 | [diff] [blame] | 6021 | // This actually changed the resources! Tell |
| 6022 | // everyone about it. |
| 6023 | if (mPendingConfiguration == null || |
| 6024 | mPendingConfiguration.isOtherSeqNewer(newConfig)) { |
| 6025 | mPendingConfiguration = newConfig; |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 6026 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 6027 | sendMessage(H.CONFIGURATION_CHANGED, newConfig); |
Dianne Hackborn | ae07816 | 2010-03-18 11:29:37 -0700 | [diff] [blame] | 6028 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6029 | } |
| 6030 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6031 | } |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 6032 | @Override |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6033 | public void onLowMemory() { |
| 6034 | } |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 6035 | @Override |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 6036 | public void onTrimMemory(int level) { |
| 6037 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6038 | }); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6039 | } |
| 6040 | |
Romain Guy | 5e9120d | 2012-01-30 12:17:22 -0800 | [diff] [blame] | 6041 | public static ActivityThread systemMain() { |
Alan Viverette | 5e1565e | 2014-07-29 16:14:25 -0700 | [diff] [blame] | 6042 | // The system process on low-memory devices do not get to use hardware |
| 6043 | // accelerated drawing, since this can add too much overhead to the |
| 6044 | // process. |
| 6045 | if (!ActivityManager.isHighEndGfx()) { |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 6046 | ThreadedRenderer.disable(true); |
John Reck | 73840ea | 2014-09-22 07:39:18 -0700 | [diff] [blame] | 6047 | } else { |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 6048 | ThreadedRenderer.enableForegroundTrimming(); |
Alan Viverette | 5e1565e | 2014-07-29 16:14:25 -0700 | [diff] [blame] | 6049 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6050 | ActivityThread thread = new ActivityThread(); |
| 6051 | thread.attach(true); |
| 6052 | return thread; |
| 6053 | } |
| 6054 | |
Jeff Brown | 10e8971 | 2011-07-08 18:52:57 -0700 | [diff] [blame] | 6055 | public final void installSystemProviders(List<ProviderInfo> providers) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6056 | if (providers != null) { |
Jeff Brown | 10e8971 | 2011-07-08 18:52:57 -0700 | [diff] [blame] | 6057 | installContentProviders(mInitialApplication, providers); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6058 | } |
| 6059 | } |
| 6060 | |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 6061 | public int getIntCoreSetting(String key, int defaultValue) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 6062 | synchronized (mResourcesManager) { |
Svetoslav Ganov | 9aa597e | 2011-03-03 18:17:41 -0800 | [diff] [blame] | 6063 | if (mCoreSettings != null) { |
| 6064 | return mCoreSettings.getInt(key, defaultValue); |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 6065 | } |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 6066 | return defaultValue; |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 6067 | } |
| 6068 | } |
| 6069 | |
Geremy Condra | 69689a7 | 2012-09-11 16:57:17 -0700 | [diff] [blame] | 6070 | private static class EventLoggingReporter implements EventLogger.Reporter { |
| 6071 | @Override |
| 6072 | public void report (int code, Object... list) { |
| 6073 | EventLog.writeEvent(code, list); |
| 6074 | } |
| 6075 | } |
| 6076 | |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 6077 | private class DropBoxReporter implements DropBox.Reporter { |
| 6078 | |
| 6079 | private DropBoxManager dropBox; |
| 6080 | |
Narayan Kamath | 7f06224 | 2015-04-08 13:24:13 +0100 | [diff] [blame] | 6081 | public DropBoxReporter() {} |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 6082 | |
| 6083 | @Override |
| 6084 | public void addData(String tag, byte[] data, int flags) { |
Narayan Kamath | 7f06224 | 2015-04-08 13:24:13 +0100 | [diff] [blame] | 6085 | ensureInitialized(); |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 6086 | dropBox.addData(tag, data, flags); |
| 6087 | } |
| 6088 | |
| 6089 | @Override |
| 6090 | public void addText(String tag, String data) { |
Narayan Kamath | 7f06224 | 2015-04-08 13:24:13 +0100 | [diff] [blame] | 6091 | ensureInitialized(); |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 6092 | dropBox.addText(tag, data); |
| 6093 | } |
Narayan Kamath | 7f06224 | 2015-04-08 13:24:13 +0100 | [diff] [blame] | 6094 | |
| 6095 | private synchronized void ensureInitialized() { |
| 6096 | if (dropBox == null) { |
| 6097 | dropBox = (DropBoxManager) getSystemContext().getSystemService(Context.DROPBOX_SERVICE); |
| 6098 | } |
| 6099 | } |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 6100 | } |
| 6101 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 6102 | public static void main(String[] args) { |
Narayan Kamath | fbb32f6 | 2015-06-12 15:34:35 +0100 | [diff] [blame] | 6103 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "ActivityThreadMain"); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 6104 | SamplingProfilerIntegration.start(); |
| 6105 | |
Brad Fitzpatrick | 4d9e6d2 | 2010-11-15 08:49:51 -0800 | [diff] [blame] | 6106 | // CloseGuard defaults to true and can be quite spammy. We |
| 6107 | // disable it here, but selectively enable it later (via |
| 6108 | // StrictMode) on debug builds, but using DropBox, not logs. |
| 6109 | CloseGuard.setEnabled(false); |
| 6110 | |
Andreas Gampe | d281b42 | 2016-07-08 03:50:27 +0000 | [diff] [blame] | 6111 | Environment.initForCurrentUser(); |
Jeff Sharkey | b049e21 | 2012-09-07 23:16:01 -0700 | [diff] [blame] | 6112 | |
Geremy Condra | 69689a7 | 2012-09-11 16:57:17 -0700 | [diff] [blame] | 6113 | // Set the reporter for event logging in libcore |
| 6114 | EventLogger.setReporter(new EventLoggingReporter()); |
| 6115 | |
Robin Lee | 3d076af | 2014-04-25 14:57:49 +0100 | [diff] [blame] | 6116 | // Make sure TrustedCertificateStore looks in the right place for CA certificates |
| 6117 | final File configDir = Environment.getUserConfigDirectory(UserHandle.myUserId()); |
| 6118 | TrustedCertificateStore.setDefaultUserDirectory(configDir); |
| 6119 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6120 | Process.setArgV0("<pre-initialized>"); |
| 6121 | |
| 6122 | Looper.prepareMainLooper(); |
| 6123 | |
| 6124 | ActivityThread thread = new ActivityThread(); |
| 6125 | thread.attach(false); |
| 6126 | |
Vairavan Srinivasan | 7335cfd | 2012-08-18 18:36:03 -0700 | [diff] [blame] | 6127 | if (sMainThreadHandler == null) { |
| 6128 | sMainThreadHandler = thread.getHandler(); |
| 6129 | } |
| 6130 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6131 | if (false) { |
| 6132 | Looper.myLooper().setMessageLogging(new |
| 6133 | LogPrinter(Log.DEBUG, "ActivityThread")); |
| 6134 | } |
| 6135 | |
Narayan Kamath | fbb32f6 | 2015-06-12 15:34:35 +0100 | [diff] [blame] | 6136 | // End of event ActivityThreadMain. |
| 6137 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6138 | Looper.loop(); |
| 6139 | |
Jeff Brown | 10e8971 | 2011-07-08 18:52:57 -0700 | [diff] [blame] | 6140 | throw new RuntimeException("Main thread loop unexpectedly exited"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6141 | } |
| 6142 | } |