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 | |
Dianne Hackborn | 69c6adc | 2015-06-02 10:52:59 -0700 | [diff] [blame] | 19 | import android.app.assist.AssistContent; |
| 20 | import android.app.assist.AssistStructure; |
Christopher Tate | 4528186 | 2010-03-05 15:46:30 -0800 | [diff] [blame] | 21 | import android.app.backup.BackupAgent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 22 | import android.content.BroadcastReceiver; |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 23 | import android.content.ComponentCallbacks2; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | import android.content.ComponentName; |
| 25 | import android.content.ContentProvider; |
| 26 | import android.content.Context; |
| 27 | import android.content.IContentProvider; |
| 28 | import android.content.Intent; |
Suchi Amalapurapu | 1ccac75 | 2009-06-12 10:09:58 -0700 | [diff] [blame] | 29 | import android.content.IIntentReceiver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | import android.content.pm.ActivityInfo; |
| 31 | import android.content.pm.ApplicationInfo; |
| 32 | import android.content.pm.IPackageManager; |
| 33 | import android.content.pm.InstrumentationInfo; |
Christopher Tate | 346acb1 | 2012-10-15 19:20:25 -0700 | [diff] [blame] | 34 | import android.content.pm.PackageInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | import android.content.pm.PackageManager; |
Sen Hu | bde7570 | 2010-05-28 01:54:03 -0700 | [diff] [blame] | 36 | import android.content.pm.PackageManager.NameNotFoundException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | import android.content.pm.ProviderInfo; |
| 38 | import android.content.pm.ServiceInfo; |
| 39 | import android.content.res.AssetManager; |
Mitsuru Oshima | ba3ba57 | 2009-07-08 18:49:26 -0700 | [diff] [blame] | 40 | import android.content.res.CompatibilityInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | import android.content.res.Configuration; |
| 42 | import android.content.res.Resources; |
Alan Viverette | e54d245 | 2015-05-06 10:41:43 -0700 | [diff] [blame] | 43 | import android.content.res.Resources.Theme; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | import android.database.sqlite.SQLiteDatabase; |
| 45 | import android.database.sqlite.SQLiteDebug; |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 46 | import android.database.sqlite.SQLiteDebug.DbStats; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | import android.graphics.Bitmap; |
| 48 | import android.graphics.Canvas; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 49 | import android.hardware.display.DisplayManagerGlobal; |
Paul Jensen | e0bef71 | 2014-12-10 15:12:18 -0500 | [diff] [blame] | 50 | import android.net.ConnectivityManager; |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 51 | import android.net.IConnectivityManager; |
Paul Jensen | e0bef71 | 2014-12-10 15:12:18 -0500 | [diff] [blame] | 52 | import android.net.Network; |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 53 | import android.net.Proxy; |
Jason Monk | 207900c | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 54 | import android.net.ProxyInfo; |
Jason Monk | 83520b9 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 55 | import android.net.Uri; |
Joe Onorato | d630f10 | 2011-03-17 18:42:26 -0700 | [diff] [blame] | 56 | import android.os.AsyncTask; |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 57 | import android.os.Binder; |
Jeff Sharkey | 344744b | 2016-01-28 19:03:30 -0700 | [diff] [blame] | 58 | import android.os.Build; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 59 | import android.os.Bundle; |
| 60 | import android.os.Debug; |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 61 | import android.os.DropBoxManager; |
Jeff Sharkey | b049e21 | 2012-09-07 23:16:01 -0700 | [diff] [blame] | 62 | import android.os.Environment; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 63 | import android.os.Handler; |
| 64 | import android.os.IBinder; |
| 65 | import android.os.Looper; |
| 66 | import android.os.Message; |
| 67 | import android.os.MessageQueue; |
Dianne Hackborn | fabb70b | 2014-11-11 12:22:36 -0800 | [diff] [blame] | 68 | import android.os.Parcel; |
Dianne Hackborn | 9c8dd55 | 2009-06-23 19:22:52 -0700 | [diff] [blame] | 69 | import android.os.ParcelFileDescriptor; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 70 | import android.os.PersistableBundle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 71 | import android.os.Process; |
| 72 | import android.os.RemoteException; |
| 73 | import android.os.ServiceManager; |
Brad Fitzpatrick | 438d059 | 2010-06-10 12:19:19 -0700 | [diff] [blame] | 74 | import android.os.StrictMode; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 75 | import android.os.SystemClock; |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 76 | import android.os.SystemProperties; |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 77 | import android.os.Trace; |
Jeff Sharkey | 369f509 | 2016-02-29 11:16:21 -0700 | [diff] [blame] | 78 | import android.os.TransactionTooLargeException; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 79 | import android.os.UserHandle; |
Narayan Kamath | ccb2a086 | 2013-12-19 14:49:36 +0000 | [diff] [blame] | 80 | import android.provider.Settings; |
Alex Klyubin | f9034cc | 2015-02-12 11:43:09 -0800 | [diff] [blame] | 81 | import android.security.NetworkSecurityPolicy; |
Chad Brubaker | 78d4712 | 2015-11-17 22:26:58 -0800 | [diff] [blame] | 82 | import android.security.net.config.NetworkSecurityConfigProvider; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 83 | import android.util.AndroidRuntimeException; |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 84 | import android.util.ArrayMap; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 85 | import android.util.DisplayMetrics; |
| 86 | import android.util.EventLog; |
| 87 | import android.util.Log; |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 88 | import android.util.LogPrinter; |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 89 | import android.util.Pair; |
Jeff Brown | 6754ba2 | 2011-12-14 20:20:01 -0800 | [diff] [blame] | 90 | import android.util.PrintWriterPrinter; |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 91 | import android.util.Slog; |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 92 | import android.util.SparseIntArray; |
Adam Powell | 1487466 | 2013-07-18 19:42:41 -0700 | [diff] [blame] | 93 | import android.util.SuperNotCalledException; |
Adam Lesinski | 3ad1b48 | 2016-04-01 16:41:41 -0700 | [diff] [blame] | 94 | import android.view.ContextThemeWrapper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 95 | import android.view.Display; |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 96 | import android.view.ThreadedRenderer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 97 | import android.view.View; |
| 98 | import android.view.ViewDebug; |
| 99 | import android.view.ViewManager; |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 100 | import android.view.ViewRootImpl; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 101 | import android.view.Window; |
| 102 | import android.view.WindowManager; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 103 | import android.view.WindowManagerGlobal; |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 104 | import android.renderscript.RenderScriptCacheDir; |
Alex Klyubin | dcdaf87 | 2015-05-13 15:57:09 -0700 | [diff] [blame] | 105 | import android.security.keystore.AndroidKeyStoreProvider; |
Calin Juravle | 6905239 | 2015-12-17 17:06:49 +0200 | [diff] [blame] | 106 | import android.system.Os; |
| 107 | import android.system.OsConstants; |
| 108 | import android.system.ErrnoException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 109 | |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 110 | import com.android.internal.annotations.GuardedBy; |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 111 | import com.android.internal.app.IVoiceInteractor; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 112 | import com.android.internal.content.ReferrerIntent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 113 | import com.android.internal.os.BinderInternal; |
| 114 | import com.android.internal.os.RuntimeInit; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 115 | import com.android.internal.os.SamplingProfilerIntegration; |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 116 | import com.android.internal.os.SomeArgs; |
Jeff Sharkey | 3e19589 | 2016-03-05 19:48:59 -0700 | [diff] [blame] | 117 | import com.android.internal.util.ArrayUtils; |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 118 | import com.android.internal.util.FastPrintWriter; |
Kenny Root | 12e7522 | 2013-04-23 22:34:24 -0700 | [diff] [blame] | 119 | import com.android.org.conscrypt.OpenSSLSocketImpl; |
Robin Lee | 3d076af | 2014-04-25 14:57:49 +0100 | [diff] [blame] | 120 | import com.android.org.conscrypt.TrustedCertificateStore; |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 121 | import com.google.android.collect.Lists; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 122 | |
| 123 | import java.io.File; |
| 124 | import java.io.FileDescriptor; |
| 125 | import java.io.FileOutputStream; |
Dianne Hackborn | 9c8dd55 | 2009-06-23 19:22:52 -0700 | [diff] [blame] | 126 | import java.io.IOException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 127 | import java.io.PrintWriter; |
| 128 | import java.lang.ref.WeakReference; |
Robert Greenwalt | 03595d0 | 2010-11-02 14:08:23 -0700 | [diff] [blame] | 129 | import java.net.InetAddress; |
Narayan Kamath | ccb2a086 | 2013-12-19 14:49:36 +0000 | [diff] [blame] | 130 | import java.text.DateFormat; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 131 | import java.util.ArrayList; |
Calin Juravle | f19c963 | 2015-12-10 17:32:15 +0000 | [diff] [blame] | 132 | import java.util.Collections; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 133 | import java.util.List; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 134 | import java.util.Map; |
Kenny Root | e6585b3 | 2013-12-13 12:00:26 -0800 | [diff] [blame] | 135 | import java.util.Objects; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 136 | import java.util.TimeZone; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 137 | |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 138 | import libcore.io.DropBox; |
Geremy Condra | 69689a7 | 2012-09-11 16:57:17 -0700 | [diff] [blame] | 139 | import libcore.io.EventLogger; |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 140 | import libcore.io.IoUtils; |
Paul Jensen | e401d17 | 2014-09-12 10:47:39 -0400 | [diff] [blame] | 141 | import libcore.net.event.NetworkEventDispatcher; |
Brad Fitzpatrick | 4d9e6d2 | 2010-11-15 08:49:51 -0800 | [diff] [blame] | 142 | import dalvik.system.CloseGuard; |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 143 | import dalvik.system.VMDebug; |
Mathieu Chartier | 1e37090 | 2013-07-18 10:58:01 -0700 | [diff] [blame] | 144 | import dalvik.system.VMRuntime; |
Man Cao | cfa78b2 | 2015-06-11 20:14:34 -0700 | [diff] [blame] | 145 | import org.apache.harmony.dalvik.ddmc.DdmVmInternal; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 146 | |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 147 | final class RemoteServiceException extends AndroidRuntimeException { |
| 148 | public RemoteServiceException(String msg) { |
| 149 | super(msg); |
| 150 | } |
| 151 | } |
| 152 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 153 | /** |
| 154 | * This manages the execution of the main thread in an |
| 155 | * application process, scheduling and executing activities, |
| 156 | * broadcasts, and other operations on it as the activity |
| 157 | * manager requests. |
| 158 | * |
| 159 | * {@hide} |
| 160 | */ |
| 161 | public final class ActivityThread { |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 162 | /** @hide */ |
| 163 | public static final String TAG = "ActivityThread"; |
Jim Miller | 0b2a6d0 | 2010-07-13 18:01:29 -0700 | [diff] [blame] | 164 | 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] | 165 | static final boolean localLOGV = false; |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 166 | static final boolean DEBUG_MESSAGES = false; |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 167 | /** @hide */ |
| 168 | public static final boolean DEBUG_BROADCAST = false; |
Chris Tate | 8a7dc17 | 2009-03-24 20:11:42 -0700 | [diff] [blame] | 169 | private static final boolean DEBUG_RESULTS = false; |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 170 | private static final boolean DEBUG_BACKUP = false; |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 171 | public static final boolean DEBUG_CONFIGURATION = false; |
Dianne Hackborn | a0c283e | 2012-02-09 10:47:01 -0800 | [diff] [blame] | 172 | private static final boolean DEBUG_SERVICE = false; |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 173 | private static final boolean DEBUG_MEMORY_TRIM = false; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 174 | private static final boolean DEBUG_PROVIDER = false; |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 175 | private static final boolean DEBUG_ORDER = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 176 | 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] | 177 | private static final int SQLITE_MEM_RELEASED_EVENT_LOG_TAG = 75003; |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 178 | private static final int LOG_AM_ON_PAUSE_CALLED = 30021; |
| 179 | private static final int LOG_AM_ON_RESUME_CALLED = 30022; |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 180 | 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] | 181 | |
Dianne Hackborn | 455625e | 2015-01-21 09:55:13 -0800 | [diff] [blame] | 182 | /** Type for IActivityManager.serviceDoneExecuting: anonymous operation */ |
| 183 | public static final int SERVICE_DONE_EXECUTING_ANON = 0; |
| 184 | /** Type for IActivityManager.serviceDoneExecuting: done with an onStart call */ |
| 185 | public static final int SERVICE_DONE_EXECUTING_START = 1; |
| 186 | /** Type for IActivityManager.serviceDoneExecuting: done stopping (destroying) service */ |
| 187 | public static final int SERVICE_DONE_EXECUTING_STOP = 2; |
| 188 | |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 189 | // Details for pausing activity. |
| 190 | private static final int USER_LEAVING = 1; |
| 191 | private static final int DONT_REPORT = 2; |
| 192 | |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 193 | // Whether to invoke an activity callback after delivering new configuration. |
| 194 | private static final boolean REPORT_TO_ACTIVITY = true; |
| 195 | |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 196 | private ContextImpl mSystemContext; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 197 | |
Jeff Sharkey | d589663 | 2016-03-04 16:16:00 -0700 | [diff] [blame] | 198 | static volatile IPackageManager sPackageManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 199 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 200 | final ApplicationThread mAppThread = new ApplicationThread(); |
| 201 | final Looper mLooper = Looper.myLooper(); |
| 202 | final H mH = new H(); |
Dianne Hackborn | 782d498 | 2015-07-08 17:36:37 -0700 | [diff] [blame] | 203 | final ArrayMap<IBinder, ActivityClientRecord> mActivities = new ArrayMap<>(); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 204 | // List of new activities (via ActivityRecord.nextIdle) that should |
| 205 | // be reported when next we idle. |
| 206 | ActivityClientRecord mNewActivities = null; |
| 207 | // Number of activities that are currently visible on-screen. |
| 208 | int mNumVisibleActivities = 0; |
Amith Yamasani | 4f128e4 | 2016-05-10 11:44:12 -0700 | [diff] [blame] | 209 | ArrayList<WeakReference<AssistStructure>> mLastAssistStructures = new ArrayList<>(); |
| 210 | private int mLastSessionId; |
Dianne Hackborn | 782d498 | 2015-07-08 17:36:37 -0700 | [diff] [blame] | 211 | final ArrayMap<IBinder, Service> mServices = new ArrayMap<>(); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 212 | AppBindData mBoundApplication; |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 213 | Profiler mProfiler; |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 214 | int mCurDefaultDisplayDpi; |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 215 | boolean mDensityCompatMode; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 216 | Configuration mConfiguration; |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 217 | Configuration mCompatConfiguration; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 218 | Application mInitialApplication; |
| 219 | final ArrayList<Application> mAllApplications |
| 220 | = new ArrayList<Application>(); |
| 221 | // set of instantiated backup agents, keyed by package name |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 222 | final ArrayMap<String, BackupAgent> mBackupAgents = new ArrayMap<String, BackupAgent>(); |
Jeff Sharkey | 66a017b | 2013-01-17 18:18:22 -0800 | [diff] [blame] | 223 | /** Reference to singleton {@link ActivityThread} */ |
Jeff Sharkey | d589663 | 2016-03-04 16:16:00 -0700 | [diff] [blame] | 224 | private static volatile ActivityThread sCurrentActivityThread; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 225 | Instrumentation mInstrumentation; |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 226 | String mInstrumentationPackageName = null; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 227 | String mInstrumentationAppDir = null; |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 228 | String[] mInstrumentationSplitAppDirs = null; |
| 229 | String mInstrumentationLibDir = null; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 230 | String mInstrumentedAppDir = null; |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 231 | String[] mInstrumentedSplitAppDirs = null; |
| 232 | String mInstrumentedLibDir = null; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 233 | boolean mSystemThread = false; |
| 234 | boolean mJitEnabled = false; |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 235 | boolean mSomeActivitiesChanged = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 236 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 237 | // These can be accessed by multiple threads; mPackages is the lock. |
| 238 | // XXX For now we keep around information about all packages we have |
| 239 | // seen, not removing entries from this map. |
Dianne Hackborn | 1fbee79 | 2011-11-30 11:29:58 -0800 | [diff] [blame] | 240 | // NOTE: The activity and window managers need to call in to |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 241 | // ActivityThread to do things like update resource configurations, |
Dianne Hackborn | 1fbee79 | 2011-11-30 11:29:58 -0800 | [diff] [blame] | 242 | // which means this lock gets held while the activity and window managers |
| 243 | // holds their own lock. Thus you MUST NEVER call back into the activity manager |
| 244 | // 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] | 245 | // 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] | 246 | final ArrayMap<String, WeakReference<LoadedApk>> mPackages |
| 247 | = new ArrayMap<String, WeakReference<LoadedApk>>(); |
| 248 | final ArrayMap<String, WeakReference<LoadedApk>> mResourcePackages |
| 249 | = new ArrayMap<String, WeakReference<LoadedApk>>(); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 250 | final ArrayList<ActivityClientRecord> mRelaunchingActivities |
| 251 | = new ArrayList<ActivityClientRecord>(); |
| 252 | Configuration mPendingConfiguration = null; |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 253 | // Because we merge activity relaunch operations we can't depend on the ordering provided by |
| 254 | // the handler messages. We need to introduce secondary ordering mechanism, which will allow |
| 255 | // us to drop certain events, if we know that they happened before relaunch we already executed. |
| 256 | // This represents the order of receiving the request from AM. |
| 257 | @GuardedBy("mResourcesManager") |
| 258 | int mLifecycleSeq = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 259 | |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 260 | private final ResourcesManager mResourcesManager; |
| 261 | |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 262 | private static final class ProviderKey { |
| 263 | final String authority; |
| 264 | final int userId; |
| 265 | |
| 266 | public ProviderKey(String authority, int userId) { |
| 267 | this.authority = authority; |
| 268 | this.userId = userId; |
| 269 | } |
| 270 | |
| 271 | @Override |
| 272 | public boolean equals(Object o) { |
| 273 | if (o instanceof ProviderKey) { |
| 274 | final ProviderKey other = (ProviderKey) o; |
Kenny Root | e6585b3 | 2013-12-13 12:00:26 -0800 | [diff] [blame] | 275 | return Objects.equals(authority, other.authority) && userId == other.userId; |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 276 | } |
| 277 | return false; |
| 278 | } |
| 279 | |
| 280 | @Override |
| 281 | public int hashCode() { |
| 282 | return ((authority != null) ? authority.hashCode() : 0) ^ userId; |
| 283 | } |
| 284 | } |
| 285 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 286 | // The lock of mProviderMap protects the following variables. |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 287 | final ArrayMap<ProviderKey, ProviderClientRecord> mProviderMap |
| 288 | = new ArrayMap<ProviderKey, ProviderClientRecord>(); |
| 289 | final ArrayMap<IBinder, ProviderRefCount> mProviderRefCountMap |
| 290 | = new ArrayMap<IBinder, ProviderRefCount>(); |
| 291 | final ArrayMap<IBinder, ProviderClientRecord> mLocalProviders |
| 292 | = new ArrayMap<IBinder, ProviderClientRecord>(); |
| 293 | final ArrayMap<ComponentName, ProviderClientRecord> mLocalProvidersByName |
| 294 | = new ArrayMap<ComponentName, ProviderClientRecord>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 295 | |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 296 | final ArrayMap<Activity, ArrayList<OnActivityPausedListener>> mOnPauseListeners |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 297 | = new ArrayMap<Activity, ArrayList<OnActivityPausedListener>>(); |
Jeff Hamilton | 52d3203 | 2011-01-08 15:31:26 -0600 | [diff] [blame] | 298 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 299 | final GcIdler mGcIdler = new GcIdler(); |
| 300 | boolean mGcIdlerScheduled = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 301 | |
Jeff Sharkey | d589663 | 2016-03-04 16:16:00 -0700 | [diff] [blame] | 302 | static volatile Handler sMainThreadHandler; // set once in main() |
Brad Fitzpatrick | 333b8cb | 2010-08-26 12:04:57 -0700 | [diff] [blame] | 303 | |
Svetoslav Ganov | 9aa597e | 2011-03-03 18:17:41 -0800 | [diff] [blame] | 304 | Bundle mCoreSettings = null; |
| 305 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 306 | static final class ActivityClientRecord { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 307 | IBinder token; |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 308 | int ident; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 309 | Intent intent; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 310 | String referrer; |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 311 | IVoiceInteractor voiceInteractor; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 312 | Bundle state; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 313 | PersistableBundle persistentState; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 314 | Activity activity; |
| 315 | Window window; |
| 316 | Activity parent; |
| 317 | String embeddedID; |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 318 | Activity.NonConfigurationInstances lastNonConfigurationInstances; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 319 | boolean paused; |
| 320 | boolean stopped; |
| 321 | boolean hideForNow; |
| 322 | Configuration newConfig; |
Dianne Hackborn | e88846e | 2009-09-30 21:34:25 -0700 | [diff] [blame] | 323 | Configuration createdConfig; |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 324 | Configuration overrideConfig; |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 325 | // Used for consolidating configs before sending on to Activity. |
| 326 | private Configuration tmpConfig = new Configuration(); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 327 | ActivityClientRecord nextIdle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 328 | |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 329 | ProfilerInfo profilerInfo; |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 330 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 331 | ActivityInfo activityInfo; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 332 | CompatibilityInfo compatInfo; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 333 | LoadedApk packageInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 334 | |
| 335 | List<ResultInfo> pendingResults; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 336 | List<ReferrerIntent> pendingIntents; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 337 | |
| 338 | boolean startsNotResumed; |
| 339 | boolean isForward; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 340 | int pendingConfigChanges; |
| 341 | boolean onlyLocalRequest; |
| 342 | |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 343 | Window mPendingRemoveWindow; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 344 | WindowManager mPendingRemoveWindowManager; |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 345 | boolean mPreserveWindow; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 346 | |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 347 | // Set for relaunch requests, indicates the order number of the relaunch operation, so it |
| 348 | // can be compared with other lifecycle operations. |
| 349 | int relaunchSeq = 0; |
| 350 | |
| 351 | // Can only be accessed from the UI thread. This represents the latest processed message |
| 352 | // that is related to lifecycle events/ |
| 353 | int lastProcessedSeq = 0; |
| 354 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 355 | ActivityClientRecord() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 356 | parent = null; |
| 357 | embeddedID = null; |
| 358 | paused = false; |
| 359 | stopped = false; |
| 360 | hideForNow = false; |
| 361 | nextIdle = null; |
| 362 | } |
| 363 | |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 364 | public boolean isPreHoneycomb() { |
| 365 | if (activity != null) { |
| 366 | return activity.getApplicationInfo().targetSdkVersion |
| 367 | < android.os.Build.VERSION_CODES.HONEYCOMB; |
| 368 | } |
| 369 | return false; |
| 370 | } |
| 371 | |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 372 | public boolean isPersistable() { |
Craig Mautner | 43e52ed | 2014-06-16 17:18:52 -0700 | [diff] [blame] | 373 | return activityInfo.persistableMode == ActivityInfo.PERSIST_ACROSS_REBOOTS; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 374 | } |
| 375 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 376 | public String toString() { |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 377 | ComponentName componentName = intent != null ? intent.getComponent() : null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 378 | return "ActivityRecord{" |
| 379 | + Integer.toHexString(System.identityHashCode(this)) |
| 380 | + " token=" + token + " " + (componentName == null |
| 381 | ? "no component name" : componentName.toShortString()) |
| 382 | + "}"; |
| 383 | } |
Andrii Kulian | 58178f2 | 2016-03-16 13:44:56 -0700 | [diff] [blame] | 384 | |
| 385 | public String getStateString() { |
| 386 | StringBuilder sb = new StringBuilder(); |
| 387 | sb.append("ActivityClientRecord{"); |
| 388 | sb.append("paused=").append(paused); |
| 389 | sb.append(", stopped=").append(stopped); |
| 390 | sb.append(", hideForNow=").append(hideForNow); |
| 391 | sb.append(", startsNotResumed=").append(startsNotResumed); |
| 392 | sb.append(", isForward=").append(isForward); |
| 393 | sb.append(", pendingConfigChanges=").append(pendingConfigChanges); |
| 394 | sb.append(", onlyLocalRequest=").append(onlyLocalRequest); |
| 395 | sb.append(", preserveWindow=").append(mPreserveWindow); |
| 396 | if (activity != null) { |
| 397 | sb.append(", Activity{"); |
| 398 | sb.append("resumed=").append(activity.mResumed); |
| 399 | sb.append(", stopped=").append(activity.mStopped); |
| 400 | sb.append(", finished=").append(activity.isFinishing()); |
| 401 | sb.append(", destroyed=").append(activity.isDestroyed()); |
| 402 | sb.append(", startedActivity=").append(activity.mStartedActivity); |
| 403 | sb.append(", temporaryPause=").append(activity.mTemporaryPause); |
| 404 | sb.append(", changingConfigurations=").append(activity.mChangingConfigurations); |
| 405 | sb.append(", visibleBehind=").append(activity.mVisibleBehind); |
| 406 | sb.append("}"); |
| 407 | } |
| 408 | sb.append("}"); |
| 409 | return sb.toString(); |
| 410 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 411 | } |
| 412 | |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 413 | final class ProviderClientRecord { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 414 | final String[] mNames; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 415 | final IContentProvider mProvider; |
| 416 | final ContentProvider mLocalProvider; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 417 | final IActivityManager.ContentProviderHolder mHolder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 418 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 419 | ProviderClientRecord(String[] names, IContentProvider provider, |
| 420 | ContentProvider localProvider, |
| 421 | IActivityManager.ContentProviderHolder holder) { |
| 422 | mNames = names; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 423 | mProvider = provider; |
| 424 | mLocalProvider = localProvider; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 425 | mHolder = holder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 426 | } |
| 427 | } |
| 428 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 429 | static final class NewIntentData { |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 430 | List<ReferrerIntent> intents; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 431 | IBinder token; |
| 432 | public String toString() { |
| 433 | return "NewIntentData{intents=" + intents + " token=" + token + "}"; |
| 434 | } |
| 435 | } |
| 436 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 437 | static final class ReceiverData extends BroadcastReceiver.PendingResult { |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 438 | public ReceiverData(Intent intent, int resultCode, String resultData, Bundle resultExtras, |
Dianne Hackborn | 20e8098 | 2012-08-31 19:00:44 -0700 | [diff] [blame] | 439 | boolean ordered, boolean sticky, IBinder token, int sendingUser) { |
| 440 | super(resultCode, resultData, resultExtras, TYPE_COMPONENT, ordered, sticky, |
riddle_hsu | 1f5ac4d | 2015-01-03 15:38:21 +0800 | [diff] [blame] | 441 | token, sendingUser, intent.getFlags()); |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 442 | this.intent = intent; |
| 443 | } |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 444 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 445 | Intent intent; |
| 446 | ActivityInfo info; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 447 | CompatibilityInfo compatInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 448 | public String toString() { |
| 449 | return "ReceiverData{intent=" + intent + " packageName=" + |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 450 | info.packageName + " resultCode=" + getResultCode() |
| 451 | + " resultData=" + getResultData() + " resultExtras=" |
| 452 | + getResultExtras(false) + "}"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 453 | } |
| 454 | } |
| 455 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 456 | static final class CreateBackupAgentData { |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 457 | ApplicationInfo appInfo; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 458 | CompatibilityInfo compatInfo; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 459 | int backupMode; |
| 460 | public String toString() { |
| 461 | return "CreateBackupAgentData{appInfo=" + appInfo |
| 462 | + " backupAgent=" + appInfo.backupAgentName |
| 463 | + " mode=" + backupMode + "}"; |
| 464 | } |
| 465 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 466 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 467 | static final class CreateServiceData { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 468 | IBinder token; |
| 469 | ServiceInfo info; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 470 | CompatibilityInfo compatInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 471 | Intent intent; |
| 472 | public String toString() { |
| 473 | return "CreateServiceData{token=" + token + " className=" |
| 474 | + info.name + " packageName=" + info.packageName |
| 475 | + " intent=" + intent + "}"; |
| 476 | } |
| 477 | } |
| 478 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 479 | static final class BindServiceData { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 480 | IBinder token; |
| 481 | Intent intent; |
| 482 | boolean rebind; |
| 483 | public String toString() { |
| 484 | return "BindServiceData{token=" + token + " intent=" + intent + "}"; |
| 485 | } |
| 486 | } |
| 487 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 488 | static final class ServiceArgsData { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 489 | IBinder token; |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 490 | boolean taskRemoved; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 491 | int startId; |
Dianne Hackborn | f6f9f2d | 2009-08-21 16:26:03 -0700 | [diff] [blame] | 492 | int flags; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 493 | Intent args; |
| 494 | public String toString() { |
| 495 | return "ServiceArgsData{token=" + token + " startId=" + startId |
| 496 | + " args=" + args + "}"; |
| 497 | } |
| 498 | } |
| 499 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 500 | static final class AppBindData { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 501 | LoadedApk info; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 502 | String processName; |
| 503 | ApplicationInfo appInfo; |
| 504 | List<ProviderInfo> providers; |
| 505 | ComponentName instrumentationName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 506 | Bundle instrumentationArgs; |
| 507 | IInstrumentationWatcher instrumentationWatcher; |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 508 | IUiAutomationConnection instrumentationUiAutomationConnection; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 509 | int debugMode; |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 510 | boolean enableBinderTracking; |
Man Cao | cfa78b2 | 2015-06-11 20:14:34 -0700 | [diff] [blame] | 511 | boolean trackAllocation; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 512 | boolean restrictedBackupMode; |
Dianne Hackborn | 5d927c2 | 2011-09-02 12:22:18 -0700 | [diff] [blame] | 513 | boolean persistent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 514 | Configuration config; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 515 | CompatibilityInfo compatInfo; |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 516 | |
| 517 | /** Initial values for {@link Profiler}. */ |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 518 | ProfilerInfo initProfilerInfo; |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 519 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 520 | public String toString() { |
| 521 | return "AppBindData{appInfo=" + appInfo + "}"; |
| 522 | } |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | static final class Profiler { |
| 526 | String profileFile; |
| 527 | ParcelFileDescriptor profileFd; |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 528 | int samplingInterval; |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 529 | boolean autoStopProfiler; |
| 530 | boolean profiling; |
| 531 | boolean handlingProfiling; |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 532 | public void setProfiler(ProfilerInfo profilerInfo) { |
| 533 | ParcelFileDescriptor fd = profilerInfo.profileFd; |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 534 | if (profiling) { |
| 535 | if (fd != null) { |
| 536 | try { |
| 537 | fd.close(); |
| 538 | } catch (IOException e) { |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 539 | // Ignore |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 540 | } |
| 541 | } |
| 542 | return; |
| 543 | } |
| 544 | if (profileFd != null) { |
| 545 | try { |
| 546 | profileFd.close(); |
| 547 | } catch (IOException e) { |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 548 | // Ignore |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 549 | } |
| 550 | } |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 551 | profileFile = profilerInfo.profileFile; |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 552 | profileFd = fd; |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 553 | samplingInterval = profilerInfo.samplingInterval; |
| 554 | autoStopProfiler = profilerInfo.autoStopProfiler; |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 555 | } |
| 556 | public void startProfiling() { |
| 557 | if (profileFd == null || profiling) { |
| 558 | return; |
| 559 | } |
| 560 | try { |
Andreas Gampe | eff0639 | 2016-05-10 12:51:45 -0700 | [diff] [blame] | 561 | int bufferSize = SystemProperties.getInt("debug.traceview-buffer-size-mb", 8); |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 562 | VMDebug.startMethodTracing(profileFile, profileFd.getFileDescriptor(), |
Andreas Gampe | 0f03a01 | 2016-05-09 14:26:07 -0700 | [diff] [blame] | 563 | bufferSize * 1024 * 1024, 0, samplingInterval != 0, samplingInterval); |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 564 | profiling = true; |
| 565 | } catch (RuntimeException e) { |
| 566 | Slog.w(TAG, "Profiling failed on path " + profileFile); |
| 567 | try { |
| 568 | profileFd.close(); |
| 569 | profileFd = null; |
| 570 | } catch (IOException e2) { |
| 571 | Slog.w(TAG, "Failure closing profile fd", e2); |
| 572 | } |
| 573 | } |
| 574 | } |
| 575 | public void stopProfiling() { |
| 576 | if (profiling) { |
| 577 | profiling = false; |
| 578 | Debug.stopMethodTracing(); |
| 579 | if (profileFd != null) { |
| 580 | try { |
| 581 | profileFd.close(); |
| 582 | } catch (IOException e) { |
| 583 | } |
| 584 | } |
| 585 | profileFd = null; |
| 586 | profileFile = null; |
| 587 | } |
| 588 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 589 | } |
| 590 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 591 | static final class DumpComponentInfo { |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 592 | ParcelFileDescriptor fd; |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 593 | IBinder token; |
Dianne Hackborn | 30d7189 | 2010-12-11 10:37:55 -0800 | [diff] [blame] | 594 | String prefix; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 595 | String[] args; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 596 | } |
| 597 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 598 | static final class ResultData { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 599 | IBinder token; |
| 600 | List<ResultInfo> results; |
| 601 | public String toString() { |
| 602 | return "ResultData{token=" + token + " results" + results + "}"; |
| 603 | } |
| 604 | } |
| 605 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 606 | static final class ContextCleanupInfo { |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 607 | ContextImpl context; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 608 | String what; |
| 609 | String who; |
| 610 | } |
| 611 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 612 | static final class DumpHeapData { |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 613 | String path; |
| 614 | ParcelFileDescriptor fd; |
| 615 | } |
| 616 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 617 | static final class UpdateCompatibilityData { |
| 618 | String pkg; |
| 619 | CompatibilityInfo info; |
| 620 | } |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 621 | |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 622 | static final class RequestAssistContextExtras { |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 623 | IBinder activityToken; |
| 624 | IBinder requestToken; |
| 625 | int requestType; |
Amith Yamasani | 4f128e4 | 2016-05-10 11:44:12 -0700 | [diff] [blame] | 626 | int sessionId; |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 627 | } |
Anwar Ghuloum | 3a8ce1b | 2013-04-26 16:18:28 -0700 | [diff] [blame] | 628 | |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 629 | static final class ActivityConfigChangeData { |
| 630 | final IBinder activityToken; |
| 631 | final Configuration overrideConfig; |
| 632 | public ActivityConfigChangeData(IBinder token, Configuration config) { |
| 633 | activityToken = token; |
| 634 | overrideConfig = config; |
| 635 | } |
| 636 | } |
| 637 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 638 | private native void dumpGraphicsInfo(FileDescriptor fd); |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 639 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 640 | private class ApplicationThread extends ApplicationThreadNative { |
Vasu Nori | 3c7131f | 2010-09-21 14:36:57 -0700 | [diff] [blame] | 641 | private static final String DB_INFO_FORMAT = " %8s %8s %14s %14s %s"; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 642 | |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 643 | private int mLastProcessState = -1; |
| 644 | |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 645 | private void updatePendingConfiguration(Configuration config) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 646 | synchronized (mResourcesManager) { |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 647 | if (mPendingConfiguration == null || |
| 648 | mPendingConfiguration.isOtherSeqNewer(config)) { |
| 649 | mPendingConfiguration = config; |
| 650 | } |
| 651 | } |
| 652 | } |
| 653 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 654 | public final void schedulePauseActivity(IBinder token, boolean finished, |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 655 | boolean userLeaving, int configChanges, boolean dontReport) { |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 656 | int seq = getLifecycleSeq(); |
| 657 | if (DEBUG_ORDER) Slog.d(TAG, "pauseActivity " + ActivityThread.this |
| 658 | + " operation received seq: " + seq); |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 659 | sendMessage( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 660 | finished ? H.PAUSE_ACTIVITY_FINISHING : H.PAUSE_ACTIVITY, |
| 661 | token, |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 662 | (userLeaving ? USER_LEAVING : 0) | (dontReport ? DONT_REPORT : 0), |
| 663 | configChanges, |
| 664 | seq); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 665 | } |
| 666 | |
| 667 | public final void scheduleStopActivity(IBinder token, boolean showWindow, |
| 668 | int configChanges) { |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 669 | int seq = getLifecycleSeq(); |
| 670 | if (DEBUG_ORDER) Slog.d(TAG, "stopActivity " + ActivityThread.this |
| 671 | + " operation received seq: " + seq); |
| 672 | sendMessage( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 673 | showWindow ? H.STOP_ACTIVITY_SHOW : H.STOP_ACTIVITY_HIDE, |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 674 | token, 0, configChanges, seq); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 675 | } |
| 676 | |
| 677 | public final void scheduleWindowVisibility(IBinder token, boolean showWindow) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 678 | sendMessage( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 679 | showWindow ? H.SHOW_WINDOW : H.HIDE_WINDOW, |
| 680 | token); |
| 681 | } |
| 682 | |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 683 | public final void scheduleSleeping(IBinder token, boolean sleeping) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 684 | sendMessage(H.SLEEPING, token, sleeping ? 1 : 0); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 685 | } |
| 686 | |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 687 | public final void scheduleResumeActivity(IBinder token, int processState, |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 688 | boolean isForward, Bundle resumeArgs) { |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 689 | int seq = getLifecycleSeq(); |
| 690 | if (DEBUG_ORDER) Slog.d(TAG, "resumeActivity " + ActivityThread.this |
| 691 | + " operation received seq: " + seq); |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 692 | updateProcessState(processState, false); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 693 | 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] | 694 | } |
| 695 | |
| 696 | public final void scheduleSendResult(IBinder token, List<ResultInfo> results) { |
| 697 | ResultData res = new ResultData(); |
| 698 | res.token = token; |
| 699 | res.results = results; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 700 | sendMessage(H.SEND_RESULT, res); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | // we use token to identify this activity without having to send the |
| 704 | // activity itself back to the activity manager. (matters more with ipc) |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 705 | @Override |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 706 | public final void scheduleLaunchActivity(Intent intent, IBinder token, int ident, |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 707 | ActivityInfo info, Configuration curConfig, Configuration overrideConfig, |
| 708 | CompatibilityInfo compatInfo, String referrer, IVoiceInteractor voiceInteractor, |
| 709 | int procState, Bundle state, PersistableBundle persistentState, |
| 710 | List<ResultInfo> pendingResults, List<ReferrerIntent> pendingNewIntents, |
| 711 | boolean notResumed, boolean isForward, ProfilerInfo profilerInfo) { |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 712 | |
| 713 | updateProcessState(procState, false); |
| 714 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 715 | ActivityClientRecord r = new ActivityClientRecord(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 716 | |
| 717 | r.token = token; |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 718 | r.ident = ident; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 719 | r.intent = intent; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 720 | r.referrer = referrer; |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 721 | r.voiceInteractor = voiceInteractor; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 722 | r.activityInfo = info; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 723 | r.compatInfo = compatInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 724 | r.state = state; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 725 | r.persistentState = persistentState; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 726 | |
| 727 | r.pendingResults = pendingResults; |
| 728 | r.pendingIntents = pendingNewIntents; |
| 729 | |
| 730 | r.startsNotResumed = notResumed; |
| 731 | r.isForward = isForward; |
| 732 | |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 733 | r.profilerInfo = profilerInfo; |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 734 | |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 735 | r.overrideConfig = overrideConfig; |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 736 | updatePendingConfiguration(curConfig); |
| 737 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 738 | sendMessage(H.LAUNCH_ACTIVITY, r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 739 | } |
| 740 | |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 741 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 742 | public final void scheduleRelaunchActivity(IBinder token, |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 743 | List<ResultInfo> pendingResults, List<ReferrerIntent> pendingNewIntents, |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 744 | int configChanges, boolean notResumed, Configuration config, |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 745 | Configuration overrideConfig, boolean preserveWindow) { |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 746 | requestRelaunchActivity(token, pendingResults, pendingNewIntents, |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 747 | configChanges, notResumed, config, overrideConfig, true, preserveWindow); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 748 | } |
| 749 | |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 750 | public final void scheduleNewIntent(List<ReferrerIntent> intents, IBinder token) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 751 | NewIntentData data = new NewIntentData(); |
| 752 | data.intents = intents; |
| 753 | data.token = token; |
| 754 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 755 | sendMessage(H.NEW_INTENT, data); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 756 | } |
| 757 | |
| 758 | public final void scheduleDestroyActivity(IBinder token, boolean finishing, |
| 759 | int configChanges) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 760 | sendMessage(H.DESTROY_ACTIVITY, token, finishing ? 1 : 0, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 761 | configChanges); |
| 762 | } |
| 763 | |
| 764 | public final void scheduleReceiver(Intent intent, ActivityInfo info, |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 765 | CompatibilityInfo compatInfo, int resultCode, String data, Bundle extras, |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 766 | boolean sync, int sendingUser, int processState) { |
| 767 | updateProcessState(processState, false); |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 768 | ReceiverData r = new ReceiverData(intent, resultCode, data, extras, |
Dianne Hackborn | 20e8098 | 2012-08-31 19:00:44 -0700 | [diff] [blame] | 769 | sync, false, mAppThread.asBinder(), sendingUser); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 770 | r.info = info; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 771 | r.compatInfo = compatInfo; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 772 | sendMessage(H.RECEIVER, r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 773 | } |
| 774 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 775 | public final void scheduleCreateBackupAgent(ApplicationInfo app, |
| 776 | CompatibilityInfo compatInfo, int backupMode) { |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 777 | CreateBackupAgentData d = new CreateBackupAgentData(); |
| 778 | d.appInfo = app; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 779 | d.compatInfo = compatInfo; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 780 | d.backupMode = backupMode; |
| 781 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 782 | sendMessage(H.CREATE_BACKUP_AGENT, d); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 783 | } |
| 784 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 785 | public final void scheduleDestroyBackupAgent(ApplicationInfo app, |
| 786 | CompatibilityInfo compatInfo) { |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 787 | CreateBackupAgentData d = new CreateBackupAgentData(); |
| 788 | d.appInfo = app; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 789 | d.compatInfo = compatInfo; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 790 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 791 | sendMessage(H.DESTROY_BACKUP_AGENT, d); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 792 | } |
| 793 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 794 | public final void scheduleCreateService(IBinder token, |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 795 | ServiceInfo info, CompatibilityInfo compatInfo, int processState) { |
| 796 | updateProcessState(processState, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 797 | CreateServiceData s = new CreateServiceData(); |
| 798 | s.token = token; |
| 799 | s.info = info; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 800 | s.compatInfo = compatInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 801 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 802 | sendMessage(H.CREATE_SERVICE, s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 803 | } |
| 804 | |
| 805 | public final void scheduleBindService(IBinder token, Intent intent, |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 806 | boolean rebind, int processState) { |
| 807 | updateProcessState(processState, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 808 | BindServiceData s = new BindServiceData(); |
| 809 | s.token = token; |
| 810 | s.intent = intent; |
| 811 | s.rebind = rebind; |
| 812 | |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 813 | if (DEBUG_SERVICE) |
| 814 | Slog.v(TAG, "scheduleBindService token=" + token + " intent=" + intent + " uid=" |
| 815 | + Binder.getCallingUid() + " pid=" + Binder.getCallingPid()); |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 816 | sendMessage(H.BIND_SERVICE, s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 817 | } |
| 818 | |
| 819 | public final void scheduleUnbindService(IBinder token, Intent intent) { |
| 820 | BindServiceData s = new BindServiceData(); |
| 821 | s.token = token; |
| 822 | s.intent = intent; |
| 823 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 824 | sendMessage(H.UNBIND_SERVICE, s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 825 | } |
| 826 | |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 827 | public final void scheduleServiceArgs(IBinder token, boolean taskRemoved, int startId, |
Dianne Hackborn | f6f9f2d | 2009-08-21 16:26:03 -0700 | [diff] [blame] | 828 | int flags ,Intent args) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 829 | ServiceArgsData s = new ServiceArgsData(); |
| 830 | s.token = token; |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 831 | s.taskRemoved = taskRemoved; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 832 | s.startId = startId; |
Dianne Hackborn | f6f9f2d | 2009-08-21 16:26:03 -0700 | [diff] [blame] | 833 | s.flags = flags; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 834 | s.args = args; |
| 835 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 836 | sendMessage(H.SERVICE_ARGS, s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 837 | } |
| 838 | |
| 839 | public final void scheduleStopService(IBinder token) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 840 | sendMessage(H.STOP_SERVICE, token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 841 | } |
| 842 | |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 843 | public final void bindApplication(String processName, ApplicationInfo appInfo, |
| 844 | List<ProviderInfo> providers, ComponentName instrumentationName, |
| 845 | ProfilerInfo profilerInfo, Bundle instrumentationArgs, |
| 846 | IInstrumentationWatcher instrumentationWatcher, |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 847 | IUiAutomationConnection instrumentationUiConnection, int debugMode, |
Pablo Ceballos | a4d4e82 | 2015-10-05 10:27:52 -0700 | [diff] [blame] | 848 | boolean enableBinderTracking, boolean trackAllocation, |
| 849 | boolean isRestrictedBackupMode, boolean persistent, Configuration config, |
| 850 | CompatibilityInfo compatInfo, Map<String, IBinder> services, Bundle coreSettings) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 851 | |
| 852 | if (services != null) { |
| 853 | // Setup the service cache in the ServiceManager |
| 854 | ServiceManager.initServiceCache(services); |
| 855 | } |
| 856 | |
Svetoslav Ganov | 9aa597e | 2011-03-03 18:17:41 -0800 | [diff] [blame] | 857 | setCoreSettings(coreSettings); |
| 858 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 859 | AppBindData data = new AppBindData(); |
| 860 | data.processName = processName; |
| 861 | data.appInfo = appInfo; |
| 862 | data.providers = providers; |
| 863 | data.instrumentationName = instrumentationName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 864 | data.instrumentationArgs = instrumentationArgs; |
| 865 | data.instrumentationWatcher = instrumentationWatcher; |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 866 | data.instrumentationUiAutomationConnection = instrumentationUiConnection; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 867 | data.debugMode = debugMode; |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 868 | data.enableBinderTracking = enableBinderTracking; |
Man Cao | cfa78b2 | 2015-06-11 20:14:34 -0700 | [diff] [blame] | 869 | data.trackAllocation = trackAllocation; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 870 | data.restrictedBackupMode = isRestrictedBackupMode; |
Dianne Hackborn | 5d927c2 | 2011-09-02 12:22:18 -0700 | [diff] [blame] | 871 | data.persistent = persistent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 872 | data.config = config; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 873 | data.compatInfo = compatInfo; |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 874 | data.initProfilerInfo = profilerInfo; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 875 | sendMessage(H.BIND_APPLICATION, data); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 876 | } |
| 877 | |
| 878 | public final void scheduleExit() { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 879 | sendMessage(H.EXIT_APPLICATION, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 880 | } |
| 881 | |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 882 | public final void scheduleSuicide() { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 883 | sendMessage(H.SUICIDE, null); |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 884 | } |
| 885 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 886 | public void scheduleConfigurationChanged(Configuration config) { |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 887 | updatePendingConfiguration(config); |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 888 | sendMessage(H.CONFIGURATION_CHANGED, config); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 889 | } |
| 890 | |
| 891 | public void updateTimeZone() { |
| 892 | TimeZone.setDefault(null); |
| 893 | } |
| 894 | |
Robert Greenwalt | 03595d0 | 2010-11-02 14:08:23 -0700 | [diff] [blame] | 895 | public void clearDnsCache() { |
| 896 | // a non-standard API to get this to libcore |
| 897 | InetAddress.clearDnsCache(); |
Paul Jensen | e401d17 | 2014-09-12 10:47:39 -0400 | [diff] [blame] | 898 | // Allow libcore to perform the necessary actions as it sees fit upon a network |
| 899 | // configuration change. |
| 900 | NetworkEventDispatcher.getInstance().onNetworkConfigurationChanged(); |
Robert Greenwalt | 03595d0 | 2010-11-02 14:08:23 -0700 | [diff] [blame] | 901 | } |
| 902 | |
Jason Monk | 83520b9 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 903 | public void setHttpProxy(String host, String port, String exclList, Uri pacFileUrl) { |
Paul Jensen | 72db88e | 2015-03-10 10:54:12 -0400 | [diff] [blame] | 904 | final ConnectivityManager cm = ConnectivityManager.from(getSystemContext()); |
| 905 | final Network network = cm.getBoundNetworkForProcess(); |
Paul Jensen | e0bef71 | 2014-12-10 15:12:18 -0500 | [diff] [blame] | 906 | if (network != null) { |
Paul Jensen | 72db88e | 2015-03-10 10:54:12 -0400 | [diff] [blame] | 907 | Proxy.setHttpProxySystemProperty(cm.getDefaultProxy()); |
Paul Jensen | e0bef71 | 2014-12-10 15:12:18 -0500 | [diff] [blame] | 908 | } else { |
| 909 | Proxy.setHttpProxySystemProperty(host, port, exclList, pacFileUrl); |
| 910 | } |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 911 | } |
| 912 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 913 | public void processInBackground() { |
| 914 | mH.removeMessages(H.GC_WHEN_IDLE); |
| 915 | mH.sendMessage(mH.obtainMessage(H.GC_WHEN_IDLE)); |
| 916 | } |
| 917 | |
| 918 | public void dumpService(FileDescriptor fd, IBinder servicetoken, String[] args) { |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 919 | DumpComponentInfo data = new DumpComponentInfo(); |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 920 | try { |
| 921 | data.fd = ParcelFileDescriptor.dup(fd); |
| 922 | data.token = servicetoken; |
| 923 | data.args = args; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 924 | sendMessage(H.DUMP_SERVICE, data, 0, 0, true /*async*/); |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 925 | } catch (IOException e) { |
| 926 | Slog.w(TAG, "dumpService failed", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 927 | } |
| 928 | } |
| 929 | |
| 930 | // This function exists to make sure all receiver dispatching is |
| 931 | // correctly ordered, since these are one-way calls and the binder driver |
| 932 | // applies transaction ordering per object for such calls. |
| 933 | public void scheduleRegisteredReceiver(IIntentReceiver receiver, Intent intent, |
Dianne Hackborn | 68d881c | 2009-10-05 13:58:17 -0700 | [diff] [blame] | 934 | int resultCode, String dataStr, Bundle extras, boolean ordered, |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 935 | boolean sticky, int sendingUser, int processState) throws RemoteException { |
| 936 | updateProcessState(processState, false); |
Dianne Hackborn | 20e8098 | 2012-08-31 19:00:44 -0700 | [diff] [blame] | 937 | receiver.performReceive(intent, resultCode, dataStr, extras, ordered, |
| 938 | sticky, sendingUser); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 939 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 940 | |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 941 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 942 | public void scheduleLowMemory() { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 943 | sendMessage(H.LOW_MEMORY, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 944 | } |
| 945 | |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 946 | @Override |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 947 | public void scheduleActivityConfigurationChanged( |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 948 | IBinder token, Configuration overrideConfig, boolean reportToActivity) { |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 949 | sendMessage(H.ACTIVITY_CONFIGURATION_CHANGED, |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 950 | new ActivityConfigChangeData(token, overrideConfig), reportToActivity ? 1 : 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 951 | } |
| 952 | |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 953 | @Override |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 954 | public void profilerControl(boolean start, ProfilerInfo profilerInfo, int profileType) { |
| 955 | sendMessage(H.PROFILER_CONTROL, profilerInfo, start ? 1 : 0, profileType); |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 956 | } |
| 957 | |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 958 | public void dumpHeap(boolean managed, String path, ParcelFileDescriptor fd) { |
| 959 | DumpHeapData dhd = new DumpHeapData(); |
| 960 | dhd.path = path; |
| 961 | dhd.fd = fd; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 962 | sendMessage(H.DUMP_HEAP, dhd, managed ? 1 : 0, 0, true /*async*/); |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 963 | } |
| 964 | |
Dianne Hackborn | 06de2ea | 2009-05-21 12:56:43 -0700 | [diff] [blame] | 965 | public void setSchedulingGroup(int group) { |
| 966 | // Note: do this immediately, since going into the foreground |
| 967 | // should happen regardless of what pending work we have to do |
| 968 | // and the activity manager will wait for us to report back that |
| 969 | // we are done before sending us to the background. |
| 970 | try { |
| 971 | Process.setProcessGroup(Process.myPid(), group); |
| 972 | } catch (Exception e) { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 973 | Slog.w(TAG, "Failed setting process group to " + group, e); |
Dianne Hackborn | 06de2ea | 2009-05-21 12:56:43 -0700 | [diff] [blame] | 974 | } |
| 975 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 976 | |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 977 | public void dispatchPackageBroadcast(int cmd, String[] packages) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 978 | sendMessage(H.DISPATCH_PACKAGE_BROADCAST, packages, cmd); |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 979 | } |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 980 | |
| 981 | public void scheduleCrash(String msg) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 982 | sendMessage(H.SCHEDULE_CRASH, msg); |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 983 | } |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 984 | |
Dianne Hackborn | 30d7189 | 2010-12-11 10:37:55 -0800 | [diff] [blame] | 985 | public void dumpActivity(FileDescriptor fd, IBinder activitytoken, |
| 986 | String prefix, String[] args) { |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 987 | DumpComponentInfo data = new DumpComponentInfo(); |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 988 | try { |
| 989 | data.fd = ParcelFileDescriptor.dup(fd); |
| 990 | data.token = activitytoken; |
| 991 | data.prefix = prefix; |
| 992 | data.args = args; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 993 | sendMessage(H.DUMP_ACTIVITY, data, 0, 0, true /*async*/); |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 994 | } catch (IOException e) { |
| 995 | Slog.w(TAG, "dumpActivity failed", e); |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 996 | } |
| 997 | } |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 998 | |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 999 | public void dumpProvider(FileDescriptor fd, IBinder providertoken, |
| 1000 | String[] args) { |
| 1001 | DumpComponentInfo data = new DumpComponentInfo(); |
| 1002 | try { |
| 1003 | data.fd = ParcelFileDescriptor.dup(fd); |
| 1004 | data.token = providertoken; |
| 1005 | data.args = args; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1006 | sendMessage(H.DUMP_PROVIDER, data, 0, 0, true /*async*/); |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1007 | } catch (IOException e) { |
| 1008 | Slog.w(TAG, "dumpProvider failed", e); |
| 1009 | } |
| 1010 | } |
| 1011 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1012 | @Override |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 1013 | public void dumpMemInfo(FileDescriptor fd, Debug.MemoryInfo mem, boolean checkin, |
Colin Cross | c4fb5f9 | 2016-02-02 16:51:15 -0800 | [diff] [blame] | 1014 | boolean dumpFullInfo, boolean dumpDalvik, boolean dumpSummaryOnly, |
| 1015 | boolean dumpUnreachable, String[] args) { |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 1016 | FileOutputStream fout = new FileOutputStream(fd); |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 1017 | PrintWriter pw = new FastPrintWriter(fout); |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 1018 | try { |
Colin Cross | c4fb5f9 | 2016-02-02 16:51:15 -0800 | [diff] [blame] | 1019 | dumpMemInfo(pw, mem, checkin, dumpFullInfo, dumpDalvik, dumpSummaryOnly, dumpUnreachable); |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 1020 | } finally { |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 1021 | pw.flush(); |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 1022 | } |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 1023 | } |
| 1024 | |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 1025 | private void dumpMemInfo(PrintWriter pw, Debug.MemoryInfo memInfo, boolean checkin, |
Colin Cross | c4fb5f9 | 2016-02-02 16:51:15 -0800 | [diff] [blame] | 1026 | boolean dumpFullInfo, boolean dumpDalvik, boolean dumpSummaryOnly, boolean dumpUnreachable) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1027 | long nativeMax = Debug.getNativeHeapSize() / 1024; |
| 1028 | long nativeAllocated = Debug.getNativeHeapAllocatedSize() / 1024; |
| 1029 | long nativeFree = Debug.getNativeHeapFreeSize() / 1024; |
| 1030 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1031 | Runtime runtime = Runtime.getRuntime(); |
Mathieu Chartier | d288a26 | 2015-07-10 13:44:42 -0700 | [diff] [blame] | 1032 | runtime.gc(); // Do GC since countInstancesOfClass counts unreachable objects. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1033 | long dalvikMax = runtime.totalMemory() / 1024; |
| 1034 | long dalvikFree = runtime.freeMemory() / 1024; |
| 1035 | long dalvikAllocated = dalvikMax - dalvikFree; |
| 1036 | long viewInstanceCount = ViewDebug.getViewInstanceCount(); |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1037 | long viewRootInstanceCount = ViewDebug.getViewRootImplCount(); |
Brian Carlstrom | c21550a | 2010-10-05 21:34:06 -0700 | [diff] [blame] | 1038 | long appContextInstanceCount = Debug.countInstancesOfClass(ContextImpl.class); |
| 1039 | long activityInstanceCount = Debug.countInstancesOfClass(Activity.class); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1040 | int globalAssetCount = AssetManager.getGlobalAssetCount(); |
| 1041 | int globalAssetManagerCount = AssetManager.getGlobalAssetManagerCount(); |
| 1042 | int binderLocalObjectCount = Debug.getBinderLocalObjectCount(); |
| 1043 | int binderProxyObjectCount = Debug.getBinderProxyObjectCount(); |
| 1044 | int binderDeathObjectCount = Debug.getBinderDeathObjectCount(); |
Dianne Hackborn | fabb70b | 2014-11-11 12:22:36 -0800 | [diff] [blame] | 1045 | long parcelSize = Parcel.getGlobalAllocSize(); |
| 1046 | long parcelCount = Parcel.getGlobalAllocCount(); |
Brian Carlstrom | c9d5b31 | 2010-10-05 22:23:41 -0700 | [diff] [blame] | 1047 | long openSslSocketCount = Debug.countInstancesOfClass(OpenSSLSocketImpl.class); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1048 | SQLiteDebug.PagerStats stats = SQLiteDebug.getDatabaseInfo(); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1049 | |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 1050 | dumpMemInfoTable(pw, memInfo, checkin, dumpFullInfo, dumpDalvik, dumpSummaryOnly, |
| 1051 | Process.myPid(), |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 1052 | (mBoundApplication != null) ? mBoundApplication.processName : "unknown", |
| 1053 | nativeMax, nativeAllocated, nativeFree, |
| 1054 | dalvikMax, dalvikAllocated, dalvikFree); |
| 1055 | |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 1056 | if (checkin) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1057 | // NOTE: if you change anything significant below, also consider changing |
| 1058 | // ACTIVITY_THREAD_CHECKIN_VERSION. |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 1059 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1060 | // Object counts |
| 1061 | pw.print(viewInstanceCount); pw.print(','); |
| 1062 | pw.print(viewRootInstanceCount); pw.print(','); |
| 1063 | pw.print(appContextInstanceCount); pw.print(','); |
| 1064 | pw.print(activityInstanceCount); pw.print(','); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1065 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1066 | pw.print(globalAssetCount); pw.print(','); |
| 1067 | pw.print(globalAssetManagerCount); pw.print(','); |
| 1068 | pw.print(binderLocalObjectCount); pw.print(','); |
| 1069 | pw.print(binderProxyObjectCount); pw.print(','); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1070 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1071 | pw.print(binderDeathObjectCount); pw.print(','); |
| 1072 | pw.print(openSslSocketCount); pw.print(','); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1073 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1074 | // SQL |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1075 | pw.print(stats.memoryUsed / 1024); pw.print(','); |
Jeff Brown | 2a293b6 | 2012-01-19 14:02:22 -0800 | [diff] [blame] | 1076 | pw.print(stats.memoryUsed / 1024); pw.print(','); |
| 1077 | pw.print(stats.pageCacheOverflow / 1024); pw.print(','); |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 1078 | pw.print(stats.largestMemAlloc / 1024); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1079 | for (int i = 0; i < stats.dbStats.size(); i++) { |
| 1080 | DbStats dbStats = stats.dbStats.get(i); |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 1081 | pw.print(','); pw.print(dbStats.dbName); |
| 1082 | pw.print(','); pw.print(dbStats.pageSize); |
| 1083 | pw.print(','); pw.print(dbStats.dbSize); |
| 1084 | pw.print(','); pw.print(dbStats.lookaside); |
| 1085 | pw.print(','); pw.print(dbStats.cache); |
| 1086 | pw.print(','); pw.print(dbStats.cache); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1087 | } |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 1088 | pw.println(); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1089 | |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 1090 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1091 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1092 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1093 | pw.println(" "); |
| 1094 | pw.println(" Objects"); |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1095 | printRow(pw, TWO_COUNT_COLUMNS, "Views:", viewInstanceCount, "ViewRootImpl:", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1096 | viewRootInstanceCount); |
| 1097 | |
| 1098 | printRow(pw, TWO_COUNT_COLUMNS, "AppContexts:", appContextInstanceCount, |
| 1099 | "Activities:", activityInstanceCount); |
| 1100 | |
| 1101 | printRow(pw, TWO_COUNT_COLUMNS, "Assets:", globalAssetCount, |
| 1102 | "AssetManagers:", globalAssetManagerCount); |
| 1103 | |
| 1104 | printRow(pw, TWO_COUNT_COLUMNS, "Local Binders:", binderLocalObjectCount, |
| 1105 | "Proxy Binders:", binderProxyObjectCount); |
Dianne Hackborn | fabb70b | 2014-11-11 12:22:36 -0800 | [diff] [blame] | 1106 | printRow(pw, TWO_COUNT_COLUMNS, "Parcel memory:", parcelSize/1024, |
| 1107 | "Parcel count:", parcelCount); |
| 1108 | printRow(pw, TWO_COUNT_COLUMNS, "Death Recipients:", binderDeathObjectCount, |
| 1109 | "OpenSSL Sockets:", openSslSocketCount); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1110 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1111 | // SQLite mem info |
| 1112 | pw.println(" "); |
| 1113 | pw.println(" SQL"); |
Jeff Brown | 2a293b6 | 2012-01-19 14:02:22 -0800 | [diff] [blame] | 1114 | printRow(pw, ONE_COUNT_COLUMN, "MEMORY_USED:", stats.memoryUsed / 1024); |
| 1115 | printRow(pw, TWO_COUNT_COLUMNS, "PAGECACHE_OVERFLOW:", |
| 1116 | stats.pageCacheOverflow / 1024, "MALLOC_SIZE:", stats.largestMemAlloc / 1024); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1117 | pw.println(" "); |
| 1118 | int N = stats.dbStats.size(); |
| 1119 | if (N > 0) { |
| 1120 | pw.println(" DATABASES"); |
Vasu Nori | 3c7131f | 2010-09-21 14:36:57 -0700 | [diff] [blame] | 1121 | printRow(pw, " %8s %8s %14s %14s %s", "pgsz", "dbsz", "Lookaside(b)", "cache", |
| 1122 | "Dbname"); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1123 | for (int i = 0; i < N; i++) { |
| 1124 | DbStats dbStats = stats.dbStats.get(i); |
Vasu Nori | 3c7131f | 2010-09-21 14:36:57 -0700 | [diff] [blame] | 1125 | printRow(pw, DB_INFO_FORMAT, |
| 1126 | (dbStats.pageSize > 0) ? String.valueOf(dbStats.pageSize) : " ", |
| 1127 | (dbStats.dbSize > 0) ? String.valueOf(dbStats.dbSize) : " ", |
| 1128 | (dbStats.lookaside > 0) ? String.valueOf(dbStats.lookaside) : " ", |
| 1129 | dbStats.cache, dbStats.dbName); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1130 | } |
| 1131 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1132 | |
Dianne Hackborn | 82e1ee9 | 2009-08-11 18:56:41 -0700 | [diff] [blame] | 1133 | // Asset details. |
| 1134 | String assetAlloc = AssetManager.getAssetAllocations(); |
| 1135 | if (assetAlloc != null) { |
| 1136 | pw.println(" "); |
| 1137 | pw.println(" Asset Allocations"); |
| 1138 | pw.print(assetAlloc); |
| 1139 | } |
Colin Cross | c4fb5f9 | 2016-02-02 16:51:15 -0800 | [diff] [blame] | 1140 | |
| 1141 | // Unreachable native memory |
| 1142 | if (dumpUnreachable) { |
| 1143 | boolean showContents = ((mBoundApplication != null) |
| 1144 | && ((mBoundApplication.appInfo.flags&ApplicationInfo.FLAG_DEBUGGABLE) != 0)) |
| 1145 | || android.os.Build.IS_DEBUGGABLE; |
| 1146 | pw.println(" "); |
| 1147 | pw.println(" Unreachable memory"); |
| 1148 | pw.print(Debug.getUnreachableMemory(100, showContents)); |
| 1149 | } |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 1150 | } |
| 1151 | |
| 1152 | @Override |
| 1153 | public void dumpGfxInfo(FileDescriptor fd, String[] args) { |
| 1154 | dumpGraphicsInfo(fd); |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 1155 | WindowManagerGlobal.getInstance().dumpGfxInfo(fd, args); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1156 | } |
| 1157 | |
riddle_hsu | 1d6c40a | 2014-07-31 00:18:00 +0800 | [diff] [blame] | 1158 | private void dumpDatabaseInfo(FileDescriptor fd, String[] args) { |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 1159 | PrintWriter pw = new FastPrintWriter(new FileOutputStream(fd)); |
Jeff Brown | 6754ba2 | 2011-12-14 20:20:01 -0800 | [diff] [blame] | 1160 | PrintWriterPrinter printer = new PrintWriterPrinter(pw); |
| 1161 | SQLiteDebug.dump(printer, args); |
| 1162 | pw.flush(); |
| 1163 | } |
| 1164 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1165 | @Override |
riddle_hsu | 1d6c40a | 2014-07-31 00:18:00 +0800 | [diff] [blame] | 1166 | public void dumpDbInfo(final FileDescriptor fd, final String[] args) { |
| 1167 | if (mSystemThread) { |
| 1168 | // Ensure this invocation is asynchronous to prevent |
| 1169 | // writer waiting due to buffer cannot be consumed. |
| 1170 | AsyncTask.THREAD_POOL_EXECUTOR.execute(new Runnable() { |
| 1171 | @Override |
| 1172 | public void run() { |
| 1173 | dumpDatabaseInfo(fd, args); |
| 1174 | } |
| 1175 | }); |
| 1176 | } else { |
| 1177 | dumpDatabaseInfo(fd, args); |
| 1178 | } |
| 1179 | } |
| 1180 | |
| 1181 | @Override |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1182 | public void unstableProviderDied(IBinder provider) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1183 | sendMessage(H.UNSTABLE_PROVIDER_DIED, provider); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1184 | } |
| 1185 | |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 1186 | @Override |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 1187 | public void requestAssistContextExtras(IBinder activityToken, IBinder requestToken, |
Amith Yamasani | 4f128e4 | 2016-05-10 11:44:12 -0700 | [diff] [blame] | 1188 | int requestType, int sessionId) { |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 1189 | RequestAssistContextExtras cmd = new RequestAssistContextExtras(); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 1190 | cmd.activityToken = activityToken; |
| 1191 | cmd.requestToken = requestToken; |
| 1192 | cmd.requestType = requestType; |
Amith Yamasani | 4f128e4 | 2016-05-10 11:44:12 -0700 | [diff] [blame] | 1193 | cmd.sessionId = sessionId; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1194 | sendMessage(H.REQUEST_ASSIST_CONTEXT_EXTRAS, cmd); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 1195 | } |
| 1196 | |
Svetoslav Ganov | 9aa597e | 2011-03-03 18:17:41 -0800 | [diff] [blame] | 1197 | public void setCoreSettings(Bundle coreSettings) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1198 | sendMessage(H.SET_CORE_SETTINGS, coreSettings); |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1199 | } |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1200 | |
| 1201 | public void updatePackageCompatibilityInfo(String pkg, CompatibilityInfo info) { |
| 1202 | UpdateCompatibilityData ucd = new UpdateCompatibilityData(); |
| 1203 | ucd.pkg = pkg; |
| 1204 | ucd.info = info; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1205 | sendMessage(H.UPDATE_PACKAGE_COMPATIBILITY_INFO, ucd); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1206 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1207 | |
| 1208 | public void scheduleTrimMemory(int level) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1209 | sendMessage(H.TRIM_MEMORY, null, level); |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1210 | } |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1211 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1212 | public void scheduleTranslucentConversionComplete(IBinder token, boolean drawComplete) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1213 | sendMessage(H.TRANSLUCENT_CONVERSION_COMPLETE, token, drawComplete ? 1 : 0); |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1214 | } |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 1215 | |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1216 | public void scheduleOnNewActivityOptions(IBinder token, ActivityOptions options) { |
| 1217 | sendMessage(H.ON_NEW_ACTIVITY_OPTIONS, |
| 1218 | new Pair<IBinder, ActivityOptions>(token, options)); |
| 1219 | } |
| 1220 | |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 1221 | public void setProcessState(int state) { |
| 1222 | updateProcessState(state, true); |
| 1223 | } |
| 1224 | |
| 1225 | public void updateProcessState(int processState, boolean fromIpc) { |
| 1226 | synchronized (this) { |
| 1227 | if (mLastProcessState != processState) { |
| 1228 | mLastProcessState = processState; |
Mathieu Chartier | 1e37090 | 2013-07-18 10:58:01 -0700 | [diff] [blame] | 1229 | // Update Dalvik state based on ActivityManager.PROCESS_STATE_* constants. |
| 1230 | final int DALVIK_PROCESS_STATE_JANK_PERCEPTIBLE = 0; |
| 1231 | final int DALVIK_PROCESS_STATE_JANK_IMPERCEPTIBLE = 1; |
| 1232 | int dalvikProcessState = DALVIK_PROCESS_STATE_JANK_IMPERCEPTIBLE; |
| 1233 | // TODO: Tune this since things like gmail sync are important background but not jank perceptible. |
| 1234 | if (processState <= ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND) { |
| 1235 | dalvikProcessState = DALVIK_PROCESS_STATE_JANK_PERCEPTIBLE; |
| 1236 | } |
| 1237 | VMRuntime.getRuntime().updateProcessState(dalvikProcessState); |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 1238 | if (false) { |
| 1239 | Slog.i(TAG, "******************* PROCESS STATE CHANGED TO: " + processState |
| 1240 | + (fromIpc ? " (from ipc": "")); |
| 1241 | } |
| 1242 | } |
| 1243 | } |
| 1244 | } |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 1245 | |
| 1246 | @Override |
| 1247 | public void scheduleInstallProvider(ProviderInfo provider) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1248 | sendMessage(H.INSTALL_PROVIDER, provider); |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 1249 | } |
Narayan Kamath | ccb2a086 | 2013-12-19 14:49:36 +0000 | [diff] [blame] | 1250 | |
| 1251 | @Override |
| 1252 | public final void updateTimePrefs(boolean is24Hour) { |
| 1253 | DateFormat.set24HourTimePref(is24Hour); |
| 1254 | } |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 1255 | |
| 1256 | @Override |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 1257 | public void scheduleCancelVisibleBehind(IBinder token) { |
| 1258 | sendMessage(H.CANCEL_VISIBLE_BEHIND, token); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 1259 | } |
| 1260 | |
| 1261 | @Override |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 1262 | public void scheduleBackgroundVisibleBehindChanged(IBinder token, boolean visible) { |
| 1263 | sendMessage(H.BACKGROUND_VISIBLE_BEHIND_CHANGED, token, visible ? 1 : 0); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 1264 | } |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 1265 | |
Jeff Sharkey | 605eb79 | 2014-11-04 13:34:06 -0800 | [diff] [blame] | 1266 | @Override |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 1267 | public void scheduleEnterAnimationComplete(IBinder token) { |
| 1268 | sendMessage(H.ENTER_ANIMATION_COMPLETE, token); |
| 1269 | } |
Jeff Sharkey | 605eb79 | 2014-11-04 13:34:06 -0800 | [diff] [blame] | 1270 | |
| 1271 | @Override |
| 1272 | public void notifyCleartextNetwork(byte[] firstPacket) { |
| 1273 | if (StrictMode.vmCleartextNetworkEnabled()) { |
| 1274 | StrictMode.onCleartextNetworkDetected(firstPacket); |
| 1275 | } |
| 1276 | } |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 1277 | |
| 1278 | @Override |
| 1279 | public void startBinderTracking() { |
| 1280 | sendMessage(H.START_BINDER_TRACKING, null); |
| 1281 | } |
| 1282 | |
| 1283 | @Override |
| 1284 | public void stopBinderTrackingAndDump(FileDescriptor fd) { |
| 1285 | try { |
| 1286 | sendMessage(H.STOP_BINDER_TRACKING_AND_DUMP, ParcelFileDescriptor.dup(fd)); |
| 1287 | } catch (IOException e) { |
| 1288 | } |
| 1289 | } |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 1290 | |
| 1291 | @Override |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 1292 | public void scheduleMultiWindowModeChanged(IBinder token, boolean isInMultiWindowMode) |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 1293 | throws RemoteException { |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 1294 | sendMessage(H.MULTI_WINDOW_MODE_CHANGED, token, isInMultiWindowMode ? 1 : 0); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 1295 | } |
| 1296 | |
| 1297 | @Override |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 1298 | public void schedulePictureInPictureModeChanged(IBinder token, boolean isInPipMode) |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 1299 | throws RemoteException { |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 1300 | sendMessage(H.PICTURE_IN_PICTURE_MODE_CHANGED, token, isInPipMode ? 1 : 0); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 1301 | } |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1302 | |
| 1303 | @Override |
| 1304 | public void scheduleLocalVoiceInteractionStarted(IBinder token, |
| 1305 | IVoiceInteractor voiceInteractor) throws RemoteException { |
| 1306 | SomeArgs args = SomeArgs.obtain(); |
| 1307 | args.arg1 = token; |
| 1308 | args.arg2 = voiceInteractor; |
| 1309 | sendMessage(H.LOCAL_VOICE_INTERACTION_STARTED, args); |
| 1310 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1311 | } |
| 1312 | |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1313 | private int getLifecycleSeq() { |
| 1314 | synchronized (mResourcesManager) { |
| 1315 | return mLifecycleSeq++; |
| 1316 | } |
| 1317 | } |
| 1318 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1319 | private class H extends Handler { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1320 | public static final int LAUNCH_ACTIVITY = 100; |
| 1321 | public static final int PAUSE_ACTIVITY = 101; |
| 1322 | public static final int PAUSE_ACTIVITY_FINISHING= 102; |
| 1323 | public static final int STOP_ACTIVITY_SHOW = 103; |
| 1324 | public static final int STOP_ACTIVITY_HIDE = 104; |
| 1325 | public static final int SHOW_WINDOW = 105; |
| 1326 | public static final int HIDE_WINDOW = 106; |
| 1327 | public static final int RESUME_ACTIVITY = 107; |
| 1328 | public static final int SEND_RESULT = 108; |
Brian Carlstrom | ed7e007 | 2011-03-24 13:27:57 -0700 | [diff] [blame] | 1329 | public static final int DESTROY_ACTIVITY = 109; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1330 | public static final int BIND_APPLICATION = 110; |
| 1331 | public static final int EXIT_APPLICATION = 111; |
| 1332 | public static final int NEW_INTENT = 112; |
| 1333 | public static final int RECEIVER = 113; |
| 1334 | public static final int CREATE_SERVICE = 114; |
| 1335 | public static final int SERVICE_ARGS = 115; |
| 1336 | public static final int STOP_SERVICE = 116; |
Dianne Hackborn | 0923328 | 2014-04-30 11:33:59 -0700 | [diff] [blame] | 1337 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1338 | public static final int CONFIGURATION_CHANGED = 118; |
| 1339 | public static final int CLEAN_UP_CONTEXT = 119; |
| 1340 | public static final int GC_WHEN_IDLE = 120; |
| 1341 | public static final int BIND_SERVICE = 121; |
| 1342 | public static final int UNBIND_SERVICE = 122; |
| 1343 | public static final int DUMP_SERVICE = 123; |
| 1344 | public static final int LOW_MEMORY = 124; |
| 1345 | public static final int ACTIVITY_CONFIGURATION_CHANGED = 125; |
| 1346 | public static final int RELAUNCH_ACTIVITY = 126; |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 1347 | public static final int PROFILER_CONTROL = 127; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1348 | public static final int CREATE_BACKUP_AGENT = 128; |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 1349 | public static final int DESTROY_BACKUP_AGENT = 129; |
| 1350 | public static final int SUICIDE = 130; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1351 | public static final int REMOVE_PROVIDER = 131; |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 1352 | public static final int ENABLE_JIT = 132; |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1353 | public static final int DISPATCH_PACKAGE_BROADCAST = 133; |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 1354 | public static final int SCHEDULE_CRASH = 134; |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 1355 | public static final int DUMP_HEAP = 135; |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1356 | public static final int DUMP_ACTIVITY = 136; |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1357 | public static final int SLEEPING = 137; |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1358 | public static final int SET_CORE_SETTINGS = 138; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1359 | public static final int UPDATE_PACKAGE_COMPATIBILITY_INFO = 139; |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1360 | public static final int TRIM_MEMORY = 140; |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1361 | public static final int DUMP_PROVIDER = 141; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1362 | public static final int UNSTABLE_PROVIDER_DIED = 142; |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 1363 | public static final int REQUEST_ASSIST_CONTEXT_EXTRAS = 143; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1364 | public static final int TRANSLUCENT_CONVERSION_COMPLETE = 144; |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 1365 | public static final int INSTALL_PROVIDER = 145; |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1366 | public static final int ON_NEW_ACTIVITY_OPTIONS = 146; |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 1367 | public static final int CANCEL_VISIBLE_BEHIND = 147; |
| 1368 | public static final int BACKGROUND_VISIBLE_BEHIND_CHANGED = 148; |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 1369 | public static final int ENTER_ANIMATION_COMPLETE = 149; |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 1370 | public static final int START_BINDER_TRACKING = 150; |
| 1371 | public static final int STOP_BINDER_TRACKING_AND_DUMP = 151; |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 1372 | public static final int MULTI_WINDOW_MODE_CHANGED = 152; |
| 1373 | public static final int PICTURE_IN_PICTURE_MODE_CHANGED = 153; |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1374 | public static final int LOCAL_VOICE_INTERACTION_STARTED = 154; |
Narayan Kamath | ccb2a086 | 2013-12-19 14:49:36 +0000 | [diff] [blame] | 1375 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1376 | String codeToString(int code) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 1377 | if (DEBUG_MESSAGES) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1378 | switch (code) { |
| 1379 | case LAUNCH_ACTIVITY: return "LAUNCH_ACTIVITY"; |
| 1380 | case PAUSE_ACTIVITY: return "PAUSE_ACTIVITY"; |
| 1381 | case PAUSE_ACTIVITY_FINISHING: return "PAUSE_ACTIVITY_FINISHING"; |
| 1382 | case STOP_ACTIVITY_SHOW: return "STOP_ACTIVITY_SHOW"; |
| 1383 | case STOP_ACTIVITY_HIDE: return "STOP_ACTIVITY_HIDE"; |
| 1384 | case SHOW_WINDOW: return "SHOW_WINDOW"; |
| 1385 | case HIDE_WINDOW: return "HIDE_WINDOW"; |
| 1386 | case RESUME_ACTIVITY: return "RESUME_ACTIVITY"; |
| 1387 | case SEND_RESULT: return "SEND_RESULT"; |
| 1388 | case DESTROY_ACTIVITY: return "DESTROY_ACTIVITY"; |
| 1389 | case BIND_APPLICATION: return "BIND_APPLICATION"; |
| 1390 | case EXIT_APPLICATION: return "EXIT_APPLICATION"; |
| 1391 | case NEW_INTENT: return "NEW_INTENT"; |
| 1392 | case RECEIVER: return "RECEIVER"; |
| 1393 | case CREATE_SERVICE: return "CREATE_SERVICE"; |
| 1394 | case SERVICE_ARGS: return "SERVICE_ARGS"; |
| 1395 | case STOP_SERVICE: return "STOP_SERVICE"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1396 | case CONFIGURATION_CHANGED: return "CONFIGURATION_CHANGED"; |
| 1397 | case CLEAN_UP_CONTEXT: return "CLEAN_UP_CONTEXT"; |
| 1398 | case GC_WHEN_IDLE: return "GC_WHEN_IDLE"; |
| 1399 | case BIND_SERVICE: return "BIND_SERVICE"; |
| 1400 | case UNBIND_SERVICE: return "UNBIND_SERVICE"; |
| 1401 | case DUMP_SERVICE: return "DUMP_SERVICE"; |
| 1402 | case LOW_MEMORY: return "LOW_MEMORY"; |
| 1403 | case ACTIVITY_CONFIGURATION_CHANGED: return "ACTIVITY_CONFIGURATION_CHANGED"; |
| 1404 | case RELAUNCH_ACTIVITY: return "RELAUNCH_ACTIVITY"; |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 1405 | case PROFILER_CONTROL: return "PROFILER_CONTROL"; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1406 | case CREATE_BACKUP_AGENT: return "CREATE_BACKUP_AGENT"; |
| 1407 | case DESTROY_BACKUP_AGENT: return "DESTROY_BACKUP_AGENT"; |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 1408 | case SUICIDE: return "SUICIDE"; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1409 | case REMOVE_PROVIDER: return "REMOVE_PROVIDER"; |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 1410 | case ENABLE_JIT: return "ENABLE_JIT"; |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1411 | case DISPATCH_PACKAGE_BROADCAST: return "DISPATCH_PACKAGE_BROADCAST"; |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 1412 | case SCHEDULE_CRASH: return "SCHEDULE_CRASH"; |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 1413 | case DUMP_HEAP: return "DUMP_HEAP"; |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1414 | case DUMP_ACTIVITY: return "DUMP_ACTIVITY"; |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1415 | case SLEEPING: return "SLEEPING"; |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1416 | case SET_CORE_SETTINGS: return "SET_CORE_SETTINGS"; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1417 | case UPDATE_PACKAGE_COMPATIBILITY_INFO: return "UPDATE_PACKAGE_COMPATIBILITY_INFO"; |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1418 | case TRIM_MEMORY: return "TRIM_MEMORY"; |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1419 | case DUMP_PROVIDER: return "DUMP_PROVIDER"; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1420 | case UNSTABLE_PROVIDER_DIED: return "UNSTABLE_PROVIDER_DIED"; |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 1421 | case REQUEST_ASSIST_CONTEXT_EXTRAS: return "REQUEST_ASSIST_CONTEXT_EXTRAS"; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1422 | case TRANSLUCENT_CONVERSION_COMPLETE: return "TRANSLUCENT_CONVERSION_COMPLETE"; |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 1423 | case INSTALL_PROVIDER: return "INSTALL_PROVIDER"; |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1424 | case ON_NEW_ACTIVITY_OPTIONS: return "ON_NEW_ACTIVITY_OPTIONS"; |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 1425 | case CANCEL_VISIBLE_BEHIND: return "CANCEL_VISIBLE_BEHIND"; |
| 1426 | case BACKGROUND_VISIBLE_BEHIND_CHANGED: return "BACKGROUND_VISIBLE_BEHIND_CHANGED"; |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 1427 | case ENTER_ANIMATION_COMPLETE: return "ENTER_ANIMATION_COMPLETE"; |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 1428 | case MULTI_WINDOW_MODE_CHANGED: return "MULTI_WINDOW_MODE_CHANGED"; |
| 1429 | case PICTURE_IN_PICTURE_MODE_CHANGED: return "PICTURE_IN_PICTURE_MODE_CHANGED"; |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1430 | 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] | 1431 | } |
| 1432 | } |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 1433 | return Integer.toString(code); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1434 | } |
| 1435 | public void handleMessage(Message msg) { |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 1436 | 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] | 1437 | switch (msg.what) { |
| 1438 | case LAUNCH_ACTIVITY: { |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1439 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityStart"); |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 1440 | final ActivityClientRecord r = (ActivityClientRecord) msg.obj; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1441 | |
| 1442 | r.packageInfo = getPackageInfoNoCheck( |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1443 | r.activityInfo.applicationInfo, r.compatInfo); |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 1444 | handleLaunchActivity(r, null, "LAUNCH_ACTIVITY"); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1445 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1446 | } break; |
| 1447 | case RELAUNCH_ACTIVITY: { |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1448 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityRestart"); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1449 | ActivityClientRecord r = (ActivityClientRecord)msg.obj; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 1450 | handleRelaunchActivity(r); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1451 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1452 | } break; |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1453 | case PAUSE_ACTIVITY: { |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1454 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityPause"); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1455 | SomeArgs args = (SomeArgs) msg.obj; |
| 1456 | handlePauseActivity((IBinder) args.arg1, false, |
| 1457 | (args.argi1 & USER_LEAVING) != 0, args.argi2, |
| 1458 | (args.argi1 & DONT_REPORT) != 0, args.argi3); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1459 | maybeSnapshot(); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1460 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1461 | } break; |
| 1462 | case PAUSE_ACTIVITY_FINISHING: { |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1463 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityPause"); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1464 | SomeArgs args = (SomeArgs) msg.obj; |
| 1465 | handlePauseActivity((IBinder) args.arg1, true, (args.argi1 & USER_LEAVING) != 0, |
| 1466 | args.argi2, (args.argi1 & DONT_REPORT) != 0, args.argi3); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1467 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1468 | } break; |
| 1469 | case STOP_ACTIVITY_SHOW: { |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1470 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityStop"); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1471 | SomeArgs args = (SomeArgs) msg.obj; |
| 1472 | handleStopActivity((IBinder) args.arg1, true, args.argi2, args.argi3); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1473 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1474 | } break; |
| 1475 | case STOP_ACTIVITY_HIDE: { |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1476 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityStop"); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1477 | SomeArgs args = (SomeArgs) msg.obj; |
| 1478 | handleStopActivity((IBinder) args.arg1, false, args.argi2, args.argi3); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1479 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1480 | } break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1481 | case SHOW_WINDOW: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1482 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityShowWindow"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1483 | handleWindowVisibility((IBinder)msg.obj, true); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1484 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1485 | break; |
| 1486 | case HIDE_WINDOW: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1487 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityHideWindow"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1488 | handleWindowVisibility((IBinder)msg.obj, false); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1489 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1490 | break; |
| 1491 | case RESUME_ACTIVITY: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1492 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityResume"); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1493 | SomeArgs args = (SomeArgs) msg.obj; |
| 1494 | handleResumeActivity((IBinder) args.arg1, true, args.argi1 != 0, true, |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 1495 | args.argi3, "RESUME_ACTIVITY"); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1496 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1497 | break; |
| 1498 | case SEND_RESULT: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1499 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityDeliverResult"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1500 | handleSendResult((ResultData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1501 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1502 | break; |
| 1503 | case DESTROY_ACTIVITY: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1504 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityDestroy"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1505 | handleDestroyActivity((IBinder)msg.obj, msg.arg1 != 0, |
| 1506 | msg.arg2, false); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1507 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1508 | break; |
| 1509 | case BIND_APPLICATION: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1510 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "bindApplication"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1511 | AppBindData data = (AppBindData)msg.obj; |
| 1512 | handleBindApplication(data); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1513 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1514 | break; |
| 1515 | case EXIT_APPLICATION: |
| 1516 | if (mInitialApplication != null) { |
| 1517 | mInitialApplication.onTerminate(); |
| 1518 | } |
| 1519 | Looper.myLooper().quit(); |
| 1520 | break; |
| 1521 | case NEW_INTENT: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1522 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityNewIntent"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1523 | handleNewIntent((NewIntentData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1524 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1525 | break; |
| 1526 | case RECEIVER: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1527 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "broadcastReceiveComp"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1528 | handleReceiver((ReceiverData)msg.obj); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1529 | maybeSnapshot(); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1530 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1531 | break; |
| 1532 | case CREATE_SERVICE: |
Tim Murray | b6f5a42 | 2016-04-07 15:25:22 -0700 | [diff] [blame] | 1533 | 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] | 1534 | handleCreateService((CreateServiceData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1535 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1536 | break; |
| 1537 | case BIND_SERVICE: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1538 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "serviceBind"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1539 | handleBindService((BindServiceData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1540 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1541 | break; |
| 1542 | case UNBIND_SERVICE: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1543 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "serviceUnbind"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1544 | handleUnbindService((BindServiceData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1545 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1546 | break; |
| 1547 | case SERVICE_ARGS: |
Tim Murray | b6f5a42 | 2016-04-07 15:25:22 -0700 | [diff] [blame] | 1548 | 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] | 1549 | handleServiceArgs((ServiceArgsData)msg.obj); |
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 STOP_SERVICE: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1553 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "serviceStop"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1554 | handleStopService((IBinder)msg.obj); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1555 | maybeSnapshot(); |
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; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1558 | case CONFIGURATION_CHANGED: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1559 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "configChanged"); |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 1560 | mCurDefaultDisplayDpi = ((Configuration)msg.obj).densityDpi; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1561 | handleConfigurationChanged((Configuration)msg.obj, null); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1562 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1563 | break; |
| 1564 | case CLEAN_UP_CONTEXT: |
| 1565 | ContextCleanupInfo cci = (ContextCleanupInfo)msg.obj; |
| 1566 | cci.context.performFinalCleanup(cci.who, cci.what); |
| 1567 | break; |
| 1568 | case GC_WHEN_IDLE: |
| 1569 | scheduleGcIdler(); |
| 1570 | break; |
| 1571 | case DUMP_SERVICE: |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1572 | handleDumpService((DumpComponentInfo)msg.obj); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1573 | break; |
| 1574 | case LOW_MEMORY: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1575 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "lowMemory"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1576 | handleLowMemory(); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1577 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1578 | break; |
| 1579 | case ACTIVITY_CONFIGURATION_CHANGED: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1580 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityConfigChanged"); |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 1581 | handleActivityConfigurationChanged((ActivityConfigChangeData) msg.obj, |
| 1582 | msg.arg1 == 1 ? REPORT_TO_ACTIVITY : !REPORT_TO_ACTIVITY); |
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; |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 1585 | case PROFILER_CONTROL: |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 1586 | handleProfilerControl(msg.arg1 != 0, (ProfilerInfo)msg.obj, msg.arg2); |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 1587 | break; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1588 | case CREATE_BACKUP_AGENT: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1589 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "backupCreateAgent"); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1590 | handleCreateBackupAgent((CreateBackupAgentData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1591 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1592 | break; |
| 1593 | case DESTROY_BACKUP_AGENT: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1594 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "backupDestroyAgent"); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1595 | handleDestroyBackupAgent((CreateBackupAgentData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1596 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1597 | break; |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 1598 | case SUICIDE: |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1599 | Process.killProcess(Process.myPid()); |
| 1600 | break; |
| 1601 | case REMOVE_PROVIDER: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1602 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "providerRemove"); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1603 | completeRemoveProvider((ProviderRefCount)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1604 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 1605 | break; |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 1606 | case ENABLE_JIT: |
| 1607 | ensureJitEnabled(); |
| 1608 | break; |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1609 | case DISPATCH_PACKAGE_BROADCAST: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1610 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "broadcastPackage"); |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1611 | handleDispatchPackageBroadcast(msg.arg1, (String[])msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1612 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1613 | break; |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 1614 | case SCHEDULE_CRASH: |
| 1615 | throw new RemoteServiceException((String)msg.obj); |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 1616 | case DUMP_HEAP: |
| 1617 | handleDumpHeap(msg.arg1 != 0, (DumpHeapData)msg.obj); |
| 1618 | break; |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1619 | case DUMP_ACTIVITY: |
| 1620 | handleDumpActivity((DumpComponentInfo)msg.obj); |
| 1621 | break; |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1622 | case DUMP_PROVIDER: |
| 1623 | handleDumpProvider((DumpComponentInfo)msg.obj); |
| 1624 | break; |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1625 | case SLEEPING: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1626 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "sleeping"); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1627 | handleSleeping((IBinder)msg.obj, msg.arg1 != 0); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1628 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1629 | break; |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1630 | case SET_CORE_SETTINGS: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1631 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "setCoreSettings"); |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1632 | handleSetCoreSettings((Bundle) msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1633 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1634 | break; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1635 | case UPDATE_PACKAGE_COMPATIBILITY_INFO: |
| 1636 | handleUpdatePackageCompatibilityInfo((UpdateCompatibilityData)msg.obj); |
Dianne Hackborn | f0754f5b | 2011-07-21 16:02:07 -0700 | [diff] [blame] | 1637 | break; |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1638 | case TRIM_MEMORY: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1639 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "trimMemory"); |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1640 | handleTrimMemory(msg.arg1); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1641 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Dianne Hackborn | f0754f5b | 2011-07-21 16:02:07 -0700 | [diff] [blame] | 1642 | break; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1643 | case UNSTABLE_PROVIDER_DIED: |
| 1644 | handleUnstableProviderDied((IBinder)msg.obj, false); |
| 1645 | break; |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 1646 | case REQUEST_ASSIST_CONTEXT_EXTRAS: |
| 1647 | handleRequestAssistContextExtras((RequestAssistContextExtras)msg.obj); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 1648 | break; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1649 | case TRANSLUCENT_CONVERSION_COMPLETE: |
| 1650 | handleTranslucentConversionComplete((IBinder)msg.obj, msg.arg1 == 1); |
| 1651 | break; |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 1652 | case INSTALL_PROVIDER: |
| 1653 | handleInstallProvider((ProviderInfo) msg.obj); |
| 1654 | break; |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1655 | case ON_NEW_ACTIVITY_OPTIONS: |
| 1656 | Pair<IBinder, ActivityOptions> pair = (Pair<IBinder, ActivityOptions>) msg.obj; |
| 1657 | onNewActivityOptions(pair.first, pair.second); |
Dake Gu | 7ef70b0 | 2014-07-08 18:37:12 -0700 | [diff] [blame] | 1658 | break; |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 1659 | case CANCEL_VISIBLE_BEHIND: |
| 1660 | handleCancelVisibleBehind((IBinder) msg.obj); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 1661 | break; |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 1662 | case BACKGROUND_VISIBLE_BEHIND_CHANGED: |
| 1663 | handleOnBackgroundVisibleBehindChanged((IBinder) msg.obj, msg.arg1 > 0); |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1664 | break; |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 1665 | case ENTER_ANIMATION_COMPLETE: |
| 1666 | handleEnterAnimationComplete((IBinder) msg.obj); |
| 1667 | break; |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 1668 | case START_BINDER_TRACKING: |
| 1669 | handleStartBinderTracking(); |
| 1670 | break; |
| 1671 | case STOP_BINDER_TRACKING_AND_DUMP: |
| 1672 | handleStopBinderTrackingAndDump((ParcelFileDescriptor) msg.obj); |
| 1673 | break; |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 1674 | case MULTI_WINDOW_MODE_CHANGED: |
| 1675 | handleMultiWindowModeChanged((IBinder) msg.obj, msg.arg1 == 1); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 1676 | break; |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 1677 | case PICTURE_IN_PICTURE_MODE_CHANGED: |
| 1678 | handlePictureInPictureModeChanged((IBinder) msg.obj, msg.arg1 == 1); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 1679 | break; |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1680 | case LOCAL_VOICE_INTERACTION_STARTED: |
| 1681 | handleLocalVoiceInteractionStarted((IBinder) ((SomeArgs) msg.obj).arg1, |
| 1682 | (IVoiceInteractor) ((SomeArgs) msg.obj).arg2); |
| 1683 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1684 | } |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1685 | Object obj = msg.obj; |
| 1686 | if (obj instanceof SomeArgs) { |
| 1687 | ((SomeArgs) obj).recycle(); |
| 1688 | } |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 1689 | 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] | 1690 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1691 | |
Brian Carlstrom | ed7e007 | 2011-03-24 13:27:57 -0700 | [diff] [blame] | 1692 | private void maybeSnapshot() { |
| 1693 | if (mBoundApplication != null && SamplingProfilerIntegration.isEnabled()) { |
Sen Hu | bde7570 | 2010-05-28 01:54:03 -0700 | [diff] [blame] | 1694 | // convert the *private* ActivityThread.PackageInfo to *public* known |
| 1695 | // android.content.pm.PackageInfo |
| 1696 | String packageName = mBoundApplication.info.mPackageName; |
| 1697 | android.content.pm.PackageInfo packageInfo = null; |
| 1698 | try { |
| 1699 | Context context = getSystemContext(); |
| 1700 | if(context == null) { |
| 1701 | Log.e(TAG, "cannot get a valid context"); |
| 1702 | return; |
| 1703 | } |
| 1704 | PackageManager pm = context.getPackageManager(); |
| 1705 | if(pm == null) { |
| 1706 | Log.e(TAG, "cannot get a valid PackageManager"); |
| 1707 | return; |
| 1708 | } |
| 1709 | packageInfo = pm.getPackageInfo( |
| 1710 | packageName, PackageManager.GET_ACTIVITIES); |
| 1711 | } catch (NameNotFoundException e) { |
| 1712 | Log.e(TAG, "cannot get package info for " + packageName, e); |
| 1713 | } |
| 1714 | SamplingProfilerIntegration.writeSnapshot(mBoundApplication.processName, packageInfo); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1715 | } |
| 1716 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1717 | } |
| 1718 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1719 | private class Idler implements MessageQueue.IdleHandler { |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 1720 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1721 | public final boolean queueIdle() { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1722 | ActivityClientRecord a = mNewActivities; |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 1723 | boolean stopProfiling = false; |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 1724 | if (mBoundApplication != null && mProfiler.profileFd != null |
| 1725 | && mProfiler.autoStopProfiler) { |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 1726 | stopProfiling = true; |
| 1727 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1728 | if (a != null) { |
| 1729 | mNewActivities = null; |
| 1730 | IActivityManager am = ActivityManagerNative.getDefault(); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1731 | ActivityClientRecord prev; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1732 | do { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 1733 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1734 | TAG, "Reporting idle of " + a + |
| 1735 | " finished=" + |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1736 | (a.activity != null && a.activity.mFinished)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1737 | if (a.activity != null && !a.activity.mFinished) { |
| 1738 | try { |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 1739 | am.activityIdle(a.token, a.createdConfig, stopProfiling); |
Dianne Hackborn | e88846e | 2009-09-30 21:34:25 -0700 | [diff] [blame] | 1740 | a.createdConfig = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1741 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1742 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1743 | } |
| 1744 | } |
| 1745 | prev = a; |
| 1746 | a = a.nextIdle; |
| 1747 | prev.nextIdle = null; |
| 1748 | } while (a != null); |
| 1749 | } |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 1750 | if (stopProfiling) { |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 1751 | mProfiler.stopProfiling(); |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 1752 | } |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 1753 | ensureJitEnabled(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1754 | return false; |
| 1755 | } |
| 1756 | } |
| 1757 | |
| 1758 | final class GcIdler implements MessageQueue.IdleHandler { |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 1759 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1760 | public final boolean queueIdle() { |
| 1761 | doGcIfNeeded(); |
| 1762 | return false; |
| 1763 | } |
| 1764 | } |
| 1765 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1766 | public static ActivityThread currentActivityThread() { |
Jeff Sharkey | 66a017b | 2013-01-17 18:18:22 -0800 | [diff] [blame] | 1767 | return sCurrentActivityThread; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1768 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1769 | |
Wale Ogunwale | 9a6ef1e | 2015-06-02 13:41:00 -0700 | [diff] [blame] | 1770 | public static boolean isSystem() { |
| 1771 | return (sCurrentActivityThread != null) ? sCurrentActivityThread.mSystemThread : false; |
| 1772 | } |
| 1773 | |
Svetoslav | fbf0eca | 2015-05-01 16:52:41 -0700 | [diff] [blame] | 1774 | public static String currentOpPackageName() { |
| 1775 | ActivityThread am = currentActivityThread(); |
| 1776 | return (am != null && am.getApplication() != null) |
| 1777 | ? am.getApplication().getOpPackageName() : null; |
| 1778 | } |
| 1779 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1780 | public static String currentPackageName() { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1781 | ActivityThread am = currentActivityThread(); |
| 1782 | return (am != null && am.mBoundApplication != null) |
Dianne Hackborn | b57a50b | 2013-04-11 17:29:32 -0700 | [diff] [blame] | 1783 | ? am.mBoundApplication.appInfo.packageName : null; |
| 1784 | } |
| 1785 | |
| 1786 | public static String currentProcessName() { |
| 1787 | ActivityThread am = currentActivityThread(); |
| 1788 | return (am != null && am.mBoundApplication != null) |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1789 | ? am.mBoundApplication.processName : null; |
| 1790 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1791 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1792 | public static Application currentApplication() { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1793 | ActivityThread am = currentActivityThread(); |
| 1794 | return am != null ? am.mInitialApplication : null; |
| 1795 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1796 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1797 | public static IPackageManager getPackageManager() { |
| 1798 | if (sPackageManager != null) { |
| 1799 | //Slog.v("PackageManager", "returning cur default = " + sPackageManager); |
| 1800 | return sPackageManager; |
| 1801 | } |
| 1802 | IBinder b = ServiceManager.getService("package"); |
| 1803 | //Slog.v("PackageManager", "default service binder = " + b); |
| 1804 | sPackageManager = IPackageManager.Stub.asInterface(b); |
| 1805 | //Slog.v("PackageManager", "default service = " + sPackageManager); |
| 1806 | return sPackageManager; |
| 1807 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1808 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1809 | private Configuration mMainThreadConfig = new Configuration(); |
Amith Yamasani | 4f128e4 | 2016-05-10 11:44:12 -0700 | [diff] [blame] | 1810 | |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 1811 | Configuration applyConfigCompatMainThread(int displayDensity, Configuration config, |
| 1812 | CompatibilityInfo compat) { |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1813 | if (config == null) { |
| 1814 | return null; |
| 1815 | } |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 1816 | if (!compat.supportsScreen()) { |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1817 | mMainThreadConfig.setTo(config); |
| 1818 | config = mMainThreadConfig; |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 1819 | compat.applyToConfiguration(displayDensity, config); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1820 | } |
| 1821 | return config; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1822 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1823 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1824 | /** |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 1825 | * Creates the top level resources for the given package. Will return an existing |
| 1826 | * Resources if one has already been created. |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1827 | */ |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 1828 | Resources getTopLevelResources(String resDir, String[] splitResDirs, String[] overlayDirs, |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 1829 | String[] libDirs, int displayId, LoadedApk pkgInfo) { |
| 1830 | return mResourcesManager.getResources(null, resDir, splitResDirs, overlayDirs, libDirs, |
| 1831 | displayId, null, pkgInfo.getCompatibilityInfo(), pkgInfo.getClassLoader()); |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 1832 | } |
| 1833 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1834 | final Handler getHandler() { |
| 1835 | return mH; |
| 1836 | } |
| 1837 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1838 | public final LoadedApk getPackageInfo(String packageName, CompatibilityInfo compatInfo, |
| 1839 | int flags) { |
Amith Yamasani | 98edc95 | 2012-09-25 14:09:27 -0700 | [diff] [blame] | 1840 | return getPackageInfo(packageName, compatInfo, flags, UserHandle.myUserId()); |
| 1841 | } |
| 1842 | |
| 1843 | public final LoadedApk getPackageInfo(String packageName, CompatibilityInfo compatInfo, |
| 1844 | int flags, int userId) { |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 1845 | final boolean differentUser = (UserHandle.myUserId() != userId); |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 1846 | synchronized (mResourcesManager) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1847 | WeakReference<LoadedApk> ref; |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 1848 | if (differentUser) { |
| 1849 | // Caching not supported across users |
| 1850 | ref = null; |
| 1851 | } else if ((flags & Context.CONTEXT_INCLUDE_CODE) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1852 | ref = mPackages.get(packageName); |
| 1853 | } else { |
| 1854 | ref = mResourcePackages.get(packageName); |
| 1855 | } |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 1856 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1857 | LoadedApk packageInfo = ref != null ? ref.get() : null; |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 1858 | //Slog.i(TAG, "getPackageInfo " + packageName + ": " + packageInfo); |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1859 | //if (packageInfo != null) Slog.i(TAG, "isUptoDate " + packageInfo.mResDir |
| 1860 | // + ": " + packageInfo.mResources.getAssets().isUpToDate()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1861 | if (packageInfo != null && (packageInfo.mResources == null |
| 1862 | || packageInfo.mResources.getAssets().isUpToDate())) { |
| 1863 | if (packageInfo.isSecurityViolation() |
| 1864 | && (flags&Context.CONTEXT_IGNORE_SECURITY) == 0) { |
| 1865 | throw new SecurityException( |
| 1866 | "Requesting code from " + packageName |
| 1867 | + " to be run in process " |
| 1868 | + mBoundApplication.processName |
| 1869 | + "/" + mBoundApplication.appInfo.uid); |
| 1870 | } |
| 1871 | return packageInfo; |
| 1872 | } |
| 1873 | } |
| 1874 | |
| 1875 | ApplicationInfo ai = null; |
| 1876 | try { |
| 1877 | ai = getPackageManager().getApplicationInfo(packageName, |
Jeff Sharkey | c5967e9 | 2016-01-07 18:50:29 -0700 | [diff] [blame] | 1878 | PackageManager.GET_SHARED_LIBRARY_FILES |
| 1879 | | PackageManager.MATCH_DEBUG_TRIAGED_MISSING, |
| 1880 | userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1881 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1882 | throw e.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1883 | } |
| 1884 | |
| 1885 | if (ai != null) { |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1886 | return getPackageInfo(ai, compatInfo, flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1887 | } |
| 1888 | |
| 1889 | return null; |
| 1890 | } |
| 1891 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1892 | public final LoadedApk getPackageInfo(ApplicationInfo ai, CompatibilityInfo compatInfo, |
| 1893 | int flags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1894 | boolean includeCode = (flags&Context.CONTEXT_INCLUDE_CODE) != 0; |
| 1895 | boolean securityViolation = includeCode && ai.uid != 0 |
| 1896 | && ai.uid != Process.SYSTEM_UID && (mBoundApplication != null |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 1897 | ? !UserHandle.isSameApp(ai.uid, mBoundApplication.appInfo.uid) |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 1898 | : true); |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 1899 | boolean registerPackage = includeCode && (flags&Context.CONTEXT_REGISTER_PACKAGE) != 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1900 | if ((flags&(Context.CONTEXT_INCLUDE_CODE |
| 1901 | |Context.CONTEXT_IGNORE_SECURITY)) |
| 1902 | == Context.CONTEXT_INCLUDE_CODE) { |
| 1903 | if (securityViolation) { |
| 1904 | String msg = "Requesting code from " + ai.packageName |
| 1905 | + " (with uid " + ai.uid + ")"; |
| 1906 | if (mBoundApplication != null) { |
| 1907 | msg = msg + " to be run in process " |
| 1908 | + mBoundApplication.processName + " (with uid " |
| 1909 | + mBoundApplication.appInfo.uid + ")"; |
| 1910 | } |
| 1911 | throw new SecurityException(msg); |
| 1912 | } |
| 1913 | } |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 1914 | return getPackageInfo(ai, compatInfo, null, securityViolation, includeCode, |
| 1915 | registerPackage); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1916 | } |
| 1917 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1918 | public final LoadedApk getPackageInfoNoCheck(ApplicationInfo ai, |
| 1919 | CompatibilityInfo compatInfo) { |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 1920 | return getPackageInfo(ai, compatInfo, null, false, true, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1921 | } |
| 1922 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1923 | public final LoadedApk peekPackageInfo(String packageName, boolean includeCode) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 1924 | synchronized (mResourcesManager) { |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1925 | WeakReference<LoadedApk> ref; |
| 1926 | if (includeCode) { |
| 1927 | ref = mPackages.get(packageName); |
| 1928 | } else { |
| 1929 | ref = mResourcePackages.get(packageName); |
| 1930 | } |
| 1931 | return ref != null ? ref.get() : null; |
| 1932 | } |
| 1933 | } |
| 1934 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1935 | private LoadedApk getPackageInfo(ApplicationInfo aInfo, CompatibilityInfo compatInfo, |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 1936 | ClassLoader baseLoader, boolean securityViolation, boolean includeCode, |
| 1937 | boolean registerPackage) { |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 1938 | final boolean differentUser = (UserHandle.myUserId() != UserHandle.getUserId(aInfo.uid)); |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 1939 | synchronized (mResourcesManager) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1940 | WeakReference<LoadedApk> ref; |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 1941 | if (differentUser) { |
| 1942 | // Caching not supported across users |
| 1943 | ref = null; |
| 1944 | } else if (includeCode) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1945 | ref = mPackages.get(aInfo.packageName); |
| 1946 | } else { |
| 1947 | ref = mResourcePackages.get(aInfo.packageName); |
| 1948 | } |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 1949 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1950 | LoadedApk packageInfo = ref != null ? ref.get() : null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1951 | if (packageInfo == null || (packageInfo.mResources != null |
| 1952 | && !packageInfo.mResources.getAssets().isUpToDate())) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 1953 | if (localLOGV) Slog.v(TAG, (includeCode ? "Loading code package " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1954 | : "Loading resource-only package ") + aInfo.packageName |
| 1955 | + " (in " + (mBoundApplication != null |
| 1956 | ? mBoundApplication.processName : null) |
| 1957 | + ")"); |
| 1958 | packageInfo = |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 1959 | new LoadedApk(this, aInfo, compatInfo, baseLoader, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1960 | securityViolation, includeCode && |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 1961 | (aInfo.flags&ApplicationInfo.FLAG_HAS_CODE) != 0, registerPackage); |
Narayan Kamath | cb38318 | 2014-10-29 17:56:42 +0000 | [diff] [blame] | 1962 | |
| 1963 | if (mSystemThread && "android".equals(aInfo.packageName)) { |
| 1964 | packageInfo.installSystemApplicationInfo(aInfo, |
| 1965 | getSystemContext().mPackageInfo.getClassLoader()); |
| 1966 | } |
| 1967 | |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 1968 | if (differentUser) { |
| 1969 | // Caching not supported across users |
| 1970 | } else if (includeCode) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1971 | mPackages.put(aInfo.packageName, |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1972 | new WeakReference<LoadedApk>(packageInfo)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1973 | } else { |
| 1974 | mResourcePackages.put(aInfo.packageName, |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1975 | new WeakReference<LoadedApk>(packageInfo)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1976 | } |
| 1977 | } |
| 1978 | return packageInfo; |
| 1979 | } |
| 1980 | } |
| 1981 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1982 | ActivityThread() { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 1983 | mResourcesManager = ResourcesManager.getInstance(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1984 | } |
| 1985 | |
| 1986 | public ApplicationThread getApplicationThread() |
| 1987 | { |
| 1988 | return mAppThread; |
| 1989 | } |
| 1990 | |
| 1991 | public Instrumentation getInstrumentation() |
| 1992 | { |
| 1993 | return mInstrumentation; |
| 1994 | } |
| 1995 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1996 | public boolean isProfiling() { |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 1997 | return mProfiler != null && mProfiler.profileFile != null |
| 1998 | && mProfiler.profileFd == null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1999 | } |
| 2000 | |
| 2001 | public String getProfileFilePath() { |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 2002 | return mProfiler.profileFile; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2003 | } |
| 2004 | |
| 2005 | public Looper getLooper() { |
| 2006 | return mLooper; |
| 2007 | } |
| 2008 | |
| 2009 | public Application getApplication() { |
| 2010 | return mInitialApplication; |
| 2011 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2012 | |
Dianne Hackborn | d97c7ad | 2009-06-19 11:37:35 -0700 | [diff] [blame] | 2013 | public String getProcessName() { |
| 2014 | return mBoundApplication.processName; |
| 2015 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2016 | |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 2017 | public ContextImpl getSystemContext() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2018 | synchronized (this) { |
| 2019 | if (mSystemContext == null) { |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 2020 | mSystemContext = ContextImpl.createSystemContext(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2021 | } |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 2022 | return mSystemContext; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2023 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2024 | } |
| 2025 | |
Narayan Kamath | 29564cd | 2014-08-07 10:57:40 +0100 | [diff] [blame] | 2026 | public void installSystemApplicationInfo(ApplicationInfo info, ClassLoader classLoader) { |
Mike Cleron | 432b713 | 2009-09-24 15:28:29 -0700 | [diff] [blame] | 2027 | synchronized (this) { |
Narayan Kamath | 29564cd | 2014-08-07 10:57:40 +0100 | [diff] [blame] | 2028 | getSystemContext().installSystemApplicationInfo(info, classLoader); |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 2029 | |
| 2030 | // give ourselves a default profiler |
| 2031 | mProfiler = new Profiler(); |
Mike Cleron | 432b713 | 2009-09-24 15:28:29 -0700 | [diff] [blame] | 2032 | } |
| 2033 | } |
| 2034 | |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 2035 | void ensureJitEnabled() { |
| 2036 | if (!mJitEnabled) { |
| 2037 | mJitEnabled = true; |
| 2038 | dalvik.system.VMRuntime.getRuntime().startJitCompilation(); |
| 2039 | } |
| 2040 | } |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 2041 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2042 | void scheduleGcIdler() { |
| 2043 | if (!mGcIdlerScheduled) { |
| 2044 | mGcIdlerScheduled = true; |
| 2045 | Looper.myQueue().addIdleHandler(mGcIdler); |
| 2046 | } |
| 2047 | mH.removeMessages(H.GC_WHEN_IDLE); |
| 2048 | } |
| 2049 | |
| 2050 | void unscheduleGcIdler() { |
| 2051 | if (mGcIdlerScheduled) { |
| 2052 | mGcIdlerScheduled = false; |
| 2053 | Looper.myQueue().removeIdleHandler(mGcIdler); |
| 2054 | } |
| 2055 | mH.removeMessages(H.GC_WHEN_IDLE); |
| 2056 | } |
| 2057 | |
| 2058 | void doGcIfNeeded() { |
| 2059 | mGcIdlerScheduled = false; |
| 2060 | final long now = SystemClock.uptimeMillis(); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2061 | //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] | 2062 | // + "m now=" + now); |
| 2063 | if ((BinderInternal.getLastGcTime()+MIN_TIME_BETWEEN_GCS) < now) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2064 | //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] | 2065 | BinderInternal.forceGc("bg"); |
| 2066 | } |
| 2067 | } |
| 2068 | |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2069 | private static final String HEAP_FULL_COLUMN |
| 2070 | = "%13s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s"; |
| 2071 | private static final String HEAP_COLUMN |
| 2072 | = "%13s %8s %8s %8s %8s %8s %8s %8s"; |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2073 | private static final String ONE_COUNT_COLUMN = "%21s %8d"; |
| 2074 | private static final String TWO_COUNT_COLUMNS = "%21s %8d %21s %8d"; |
| 2075 | private static final String ONE_COUNT_COLUMN_HEADER = "%21s %8s"; |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2076 | |
| 2077 | // Formatting for checkin service - update version if row format changes |
Martijn Coenen | 41f94ed | 2015-12-14 15:28:51 +0100 | [diff] [blame] | 2078 | private static final int ACTIVITY_THREAD_CHECKIN_VERSION = 4; |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2079 | |
| 2080 | static void printRow(PrintWriter pw, String format, Object...objs) { |
| 2081 | pw.println(String.format(format, objs)); |
| 2082 | } |
| 2083 | |
| 2084 | public static void dumpMemInfoTable(PrintWriter pw, Debug.MemoryInfo memInfo, boolean checkin, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2085 | boolean dumpFullInfo, boolean dumpDalvik, boolean dumpSummaryOnly, |
| 2086 | int pid, String processName, |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2087 | long nativeMax, long nativeAllocated, long nativeFree, |
| 2088 | long dalvikMax, long dalvikAllocated, long dalvikFree) { |
| 2089 | |
| 2090 | // For checkin, we print one long comma-separated list of values |
| 2091 | if (checkin) { |
| 2092 | // NOTE: if you change anything significant below, also consider changing |
| 2093 | // ACTIVITY_THREAD_CHECKIN_VERSION. |
| 2094 | |
| 2095 | // Header |
| 2096 | pw.print(ACTIVITY_THREAD_CHECKIN_VERSION); pw.print(','); |
| 2097 | pw.print(pid); pw.print(','); |
| 2098 | pw.print(processName); pw.print(','); |
| 2099 | |
| 2100 | // Heap info - max |
| 2101 | pw.print(nativeMax); pw.print(','); |
| 2102 | pw.print(dalvikMax); pw.print(','); |
| 2103 | pw.print("N/A,"); |
| 2104 | pw.print(nativeMax + dalvikMax); pw.print(','); |
| 2105 | |
| 2106 | // Heap info - allocated |
| 2107 | pw.print(nativeAllocated); pw.print(','); |
| 2108 | pw.print(dalvikAllocated); pw.print(','); |
| 2109 | pw.print("N/A,"); |
| 2110 | pw.print(nativeAllocated + dalvikAllocated); pw.print(','); |
| 2111 | |
| 2112 | // Heap info - free |
| 2113 | pw.print(nativeFree); pw.print(','); |
| 2114 | pw.print(dalvikFree); pw.print(','); |
| 2115 | pw.print("N/A,"); |
| 2116 | pw.print(nativeFree + dalvikFree); pw.print(','); |
| 2117 | |
| 2118 | // Heap info - proportional set size |
| 2119 | pw.print(memInfo.nativePss); pw.print(','); |
| 2120 | pw.print(memInfo.dalvikPss); pw.print(','); |
| 2121 | pw.print(memInfo.otherPss); pw.print(','); |
| 2122 | pw.print(memInfo.getTotalPss()); pw.print(','); |
| 2123 | |
| 2124 | // Heap info - swappable set size |
| 2125 | pw.print(memInfo.nativeSwappablePss); pw.print(','); |
| 2126 | pw.print(memInfo.dalvikSwappablePss); pw.print(','); |
| 2127 | pw.print(memInfo.otherSwappablePss); pw.print(','); |
| 2128 | pw.print(memInfo.getTotalSwappablePss()); pw.print(','); |
| 2129 | |
| 2130 | // Heap info - shared dirty |
| 2131 | pw.print(memInfo.nativeSharedDirty); pw.print(','); |
| 2132 | pw.print(memInfo.dalvikSharedDirty); pw.print(','); |
| 2133 | pw.print(memInfo.otherSharedDirty); pw.print(','); |
| 2134 | pw.print(memInfo.getTotalSharedDirty()); pw.print(','); |
| 2135 | |
| 2136 | // Heap info - shared clean |
| 2137 | pw.print(memInfo.nativeSharedClean); pw.print(','); |
| 2138 | pw.print(memInfo.dalvikSharedClean); pw.print(','); |
| 2139 | pw.print(memInfo.otherSharedClean); pw.print(','); |
| 2140 | pw.print(memInfo.getTotalSharedClean()); pw.print(','); |
| 2141 | |
| 2142 | // Heap info - private Dirty |
| 2143 | pw.print(memInfo.nativePrivateDirty); pw.print(','); |
| 2144 | pw.print(memInfo.dalvikPrivateDirty); pw.print(','); |
| 2145 | pw.print(memInfo.otherPrivateDirty); pw.print(','); |
| 2146 | pw.print(memInfo.getTotalPrivateDirty()); pw.print(','); |
| 2147 | |
| 2148 | // Heap info - private Clean |
| 2149 | pw.print(memInfo.nativePrivateClean); pw.print(','); |
| 2150 | pw.print(memInfo.dalvikPrivateClean); pw.print(','); |
| 2151 | pw.print(memInfo.otherPrivateClean); pw.print(','); |
| 2152 | pw.print(memInfo.getTotalPrivateClean()); pw.print(','); |
| 2153 | |
Martijn Coenen | 41f94ed | 2015-12-14 15:28:51 +0100 | [diff] [blame] | 2154 | // Heap info - swapped out |
| 2155 | pw.print(memInfo.nativeSwappedOut); pw.print(','); |
| 2156 | pw.print(memInfo.dalvikSwappedOut); pw.print(','); |
| 2157 | pw.print(memInfo.otherSwappedOut); pw.print(','); |
| 2158 | pw.print(memInfo.getTotalSwappedOut()); pw.print(','); |
| 2159 | |
| 2160 | // Heap info - swapped out pss |
| 2161 | if (memInfo.hasSwappedOutPss) { |
| 2162 | pw.print(memInfo.nativeSwappedOutPss); pw.print(','); |
| 2163 | pw.print(memInfo.dalvikSwappedOutPss); pw.print(','); |
| 2164 | pw.print(memInfo.otherSwappedOutPss); pw.print(','); |
| 2165 | pw.print(memInfo.getTotalSwappedOutPss()); pw.print(','); |
| 2166 | } else { |
| 2167 | pw.print("N/A,"); |
| 2168 | pw.print("N/A,"); |
| 2169 | pw.print("N/A,"); |
| 2170 | pw.print("N/A,"); |
| 2171 | } |
| 2172 | |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2173 | // Heap info - other areas |
| 2174 | for (int i=0; i<Debug.MemoryInfo.NUM_OTHER_STATS; i++) { |
| 2175 | pw.print(Debug.MemoryInfo.getOtherLabel(i)); pw.print(','); |
| 2176 | pw.print(memInfo.getOtherPss(i)); pw.print(','); |
| 2177 | pw.print(memInfo.getOtherSwappablePss(i)); pw.print(','); |
| 2178 | pw.print(memInfo.getOtherSharedDirty(i)); pw.print(','); |
| 2179 | pw.print(memInfo.getOtherSharedClean(i)); pw.print(','); |
| 2180 | pw.print(memInfo.getOtherPrivateDirty(i)); pw.print(','); |
| 2181 | pw.print(memInfo.getOtherPrivateClean(i)); pw.print(','); |
Martijn Coenen | 41f94ed | 2015-12-14 15:28:51 +0100 | [diff] [blame] | 2182 | pw.print(memInfo.getOtherSwappedOut(i)); pw.print(','); |
| 2183 | if (memInfo.hasSwappedOutPss) { |
| 2184 | pw.print(memInfo.getOtherSwappedOutPss(i)); pw.print(','); |
| 2185 | } else { |
| 2186 | pw.print("N/A,"); |
| 2187 | } |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2188 | } |
| 2189 | return; |
| 2190 | } |
| 2191 | |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2192 | if (!dumpSummaryOnly) { |
| 2193 | if (dumpFullInfo) { |
| 2194 | printRow(pw, HEAP_FULL_COLUMN, "", "Pss", "Pss", "Shared", "Private", |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2195 | "Shared", "Private", memInfo.hasSwappedOutPss ? "SwapPss" : "Swap", |
| 2196 | "Heap", "Heap", "Heap"); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2197 | printRow(pw, HEAP_FULL_COLUMN, "", "Total", "Clean", "Dirty", "Dirty", |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2198 | "Clean", "Clean", "Dirty", |
| 2199 | "Size", "Alloc", "Free"); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2200 | printRow(pw, HEAP_FULL_COLUMN, "", "------", "------", "------", "------", |
| 2201 | "------", "------", "------", "------", "------", "------"); |
| 2202 | printRow(pw, HEAP_FULL_COLUMN, "Native Heap", memInfo.nativePss, |
| 2203 | memInfo.nativeSwappablePss, memInfo.nativeSharedDirty, |
| 2204 | memInfo.nativePrivateDirty, memInfo.nativeSharedClean, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2205 | memInfo.nativePrivateClean, memInfo.hasSwappedOutPss ? |
| 2206 | memInfo.nativeSwappedOut : memInfo.nativeSwappedOutPss, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2207 | nativeMax, nativeAllocated, nativeFree); |
| 2208 | printRow(pw, HEAP_FULL_COLUMN, "Dalvik Heap", memInfo.dalvikPss, |
| 2209 | memInfo.dalvikSwappablePss, memInfo.dalvikSharedDirty, |
| 2210 | memInfo.dalvikPrivateDirty, memInfo.dalvikSharedClean, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2211 | memInfo.dalvikPrivateClean, memInfo.hasSwappedOutPss ? |
| 2212 | memInfo.dalvikSwappedOut : memInfo.dalvikSwappedOutPss, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2213 | dalvikMax, dalvikAllocated, dalvikFree); |
| 2214 | } else { |
| 2215 | printRow(pw, HEAP_COLUMN, "", "Pss", "Private", |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2216 | "Private", memInfo.hasSwappedOutPss ? "SwapPss" : "Swap", |
| 2217 | "Heap", "Heap", "Heap"); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2218 | printRow(pw, HEAP_COLUMN, "", "Total", "Dirty", |
| 2219 | "Clean", "Dirty", "Size", "Alloc", "Free"); |
| 2220 | printRow(pw, HEAP_COLUMN, "", "------", "------", "------", |
| 2221 | "------", "------", "------", "------", "------"); |
| 2222 | printRow(pw, HEAP_COLUMN, "Native Heap", memInfo.nativePss, |
| 2223 | memInfo.nativePrivateDirty, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2224 | memInfo.nativePrivateClean, |
| 2225 | memInfo.hasSwappedOutPss ? memInfo.nativeSwappedOutPss : |
| 2226 | memInfo.nativeSwappedOut, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2227 | nativeMax, nativeAllocated, nativeFree); |
| 2228 | printRow(pw, HEAP_COLUMN, "Dalvik Heap", memInfo.dalvikPss, |
| 2229 | memInfo.dalvikPrivateDirty, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2230 | memInfo.dalvikPrivateClean, |
| 2231 | memInfo.hasSwappedOutPss ? memInfo.dalvikSwappedOutPss : |
| 2232 | memInfo.dalvikSwappedOut, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2233 | dalvikMax, dalvikAllocated, dalvikFree); |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2234 | } |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2235 | |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2236 | int otherPss = memInfo.otherPss; |
| 2237 | int otherSwappablePss = memInfo.otherSwappablePss; |
| 2238 | int otherSharedDirty = memInfo.otherSharedDirty; |
| 2239 | int otherPrivateDirty = memInfo.otherPrivateDirty; |
| 2240 | int otherSharedClean = memInfo.otherSharedClean; |
| 2241 | int otherPrivateClean = memInfo.otherPrivateClean; |
| 2242 | int otherSwappedOut = memInfo.otherSwappedOut; |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2243 | int otherSwappedOutPss = memInfo.otherSwappedOutPss; |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2244 | |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2245 | for (int i=0; i<Debug.MemoryInfo.NUM_OTHER_STATS; i++) { |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2246 | final int myPss = memInfo.getOtherPss(i); |
| 2247 | final int mySwappablePss = memInfo.getOtherSwappablePss(i); |
| 2248 | final int mySharedDirty = memInfo.getOtherSharedDirty(i); |
| 2249 | final int myPrivateDirty = memInfo.getOtherPrivateDirty(i); |
| 2250 | final int mySharedClean = memInfo.getOtherSharedClean(i); |
| 2251 | final int myPrivateClean = memInfo.getOtherPrivateClean(i); |
| 2252 | final int mySwappedOut = memInfo.getOtherSwappedOut(i); |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2253 | final int mySwappedOutPss = memInfo.getOtherSwappedOutPss(i); |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2254 | if (myPss != 0 || mySharedDirty != 0 || myPrivateDirty != 0 |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2255 | || mySharedClean != 0 || myPrivateClean != 0 |
| 2256 | || (memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut) != 0) { |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2257 | if (dumpFullInfo) { |
| 2258 | printRow(pw, HEAP_FULL_COLUMN, Debug.MemoryInfo.getOtherLabel(i), |
| 2259 | myPss, mySwappablePss, mySharedDirty, myPrivateDirty, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2260 | mySharedClean, myPrivateClean, |
| 2261 | memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut, |
| 2262 | "", "", ""); |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2263 | } else { |
| 2264 | printRow(pw, HEAP_COLUMN, Debug.MemoryInfo.getOtherLabel(i), |
| 2265 | myPss, myPrivateDirty, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2266 | myPrivateClean, |
| 2267 | memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut, |
| 2268 | "", "", ""); |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2269 | } |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2270 | otherPss -= myPss; |
| 2271 | otherSwappablePss -= mySwappablePss; |
| 2272 | otherSharedDirty -= mySharedDirty; |
| 2273 | otherPrivateDirty -= myPrivateDirty; |
| 2274 | otherSharedClean -= mySharedClean; |
| 2275 | otherPrivateClean -= myPrivateClean; |
| 2276 | otherSwappedOut -= mySwappedOut; |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2277 | otherSwappedOutPss -= mySwappedOutPss; |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2278 | } |
| 2279 | } |
| 2280 | |
| 2281 | if (dumpFullInfo) { |
| 2282 | printRow(pw, HEAP_FULL_COLUMN, "Unknown", otherPss, otherSwappablePss, |
| 2283 | otherSharedDirty, otherPrivateDirty, otherSharedClean, otherPrivateClean, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2284 | memInfo.hasSwappedOutPss ? otherSwappedOutPss : otherSwappedOut, |
| 2285 | "", "", ""); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2286 | printRow(pw, HEAP_FULL_COLUMN, "TOTAL", memInfo.getTotalPss(), |
| 2287 | memInfo.getTotalSwappablePss(), |
| 2288 | memInfo.getTotalSharedDirty(), memInfo.getTotalPrivateDirty(), |
| 2289 | memInfo.getTotalSharedClean(), memInfo.getTotalPrivateClean(), |
Thierry Strudel | 9b51160 | 2016-02-25 17:46:38 -0800 | [diff] [blame] | 2290 | memInfo.hasSwappedOutPss ? memInfo.getTotalSwappedOutPss() : |
| 2291 | memInfo.getTotalSwappedOut(), |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2292 | nativeMax+dalvikMax, nativeAllocated+dalvikAllocated, |
| 2293 | nativeFree+dalvikFree); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2294 | } else { |
| 2295 | printRow(pw, HEAP_COLUMN, "Unknown", otherPss, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2296 | otherPrivateDirty, otherPrivateClean, |
| 2297 | memInfo.hasSwappedOutPss ? otherSwappedOutPss : otherSwappedOut, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2298 | "", "", ""); |
| 2299 | printRow(pw, HEAP_COLUMN, "TOTAL", memInfo.getTotalPss(), |
| 2300 | memInfo.getTotalPrivateDirty(), |
| 2301 | memInfo.getTotalPrivateClean(), |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2302 | memInfo.hasSwappedOutPss ? memInfo.getTotalSwappedOutPss() : |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2303 | memInfo.getTotalSwappedOut(), |
| 2304 | nativeMax+dalvikMax, |
| 2305 | nativeAllocated+dalvikAllocated, nativeFree+dalvikFree); |
| 2306 | } |
| 2307 | |
| 2308 | if (dumpDalvik) { |
| 2309 | pw.println(" "); |
| 2310 | pw.println(" Dalvik Details"); |
| 2311 | |
| 2312 | for (int i=Debug.MemoryInfo.NUM_OTHER_STATS; |
| 2313 | i<Debug.MemoryInfo.NUM_OTHER_STATS + Debug.MemoryInfo.NUM_DVK_STATS; i++) { |
| 2314 | final int myPss = memInfo.getOtherPss(i); |
| 2315 | final int mySwappablePss = memInfo.getOtherSwappablePss(i); |
| 2316 | final int mySharedDirty = memInfo.getOtherSharedDirty(i); |
| 2317 | final int myPrivateDirty = memInfo.getOtherPrivateDirty(i); |
| 2318 | final int mySharedClean = memInfo.getOtherSharedClean(i); |
| 2319 | final int myPrivateClean = memInfo.getOtherPrivateClean(i); |
| 2320 | final int mySwappedOut = memInfo.getOtherSwappedOut(i); |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2321 | final int mySwappedOutPss = memInfo.getOtherSwappedOutPss(i); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2322 | if (myPss != 0 || mySharedDirty != 0 || myPrivateDirty != 0 |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2323 | || mySharedClean != 0 || myPrivateClean != 0 |
| 2324 | || (memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut) != 0) { |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2325 | if (dumpFullInfo) { |
| 2326 | printRow(pw, HEAP_FULL_COLUMN, Debug.MemoryInfo.getOtherLabel(i), |
| 2327 | myPss, mySwappablePss, mySharedDirty, myPrivateDirty, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2328 | mySharedClean, myPrivateClean, |
| 2329 | memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut, |
| 2330 | "", "", ""); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2331 | } else { |
| 2332 | printRow(pw, HEAP_COLUMN, Debug.MemoryInfo.getOtherLabel(i), |
| 2333 | myPss, myPrivateDirty, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2334 | myPrivateClean, |
| 2335 | memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut, |
| 2336 | "", "", ""); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2337 | } |
| 2338 | } |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2339 | } |
| 2340 | } |
| 2341 | } |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2342 | |
| 2343 | pw.println(" "); |
| 2344 | pw.println(" App Summary"); |
| 2345 | printRow(pw, ONE_COUNT_COLUMN_HEADER, "", "Pss(KB)"); |
| 2346 | printRow(pw, ONE_COUNT_COLUMN_HEADER, "", "------"); |
| 2347 | printRow(pw, ONE_COUNT_COLUMN, |
| 2348 | "Java Heap:", memInfo.getSummaryJavaHeap()); |
| 2349 | printRow(pw, ONE_COUNT_COLUMN, |
| 2350 | "Native Heap:", memInfo.getSummaryNativeHeap()); |
| 2351 | printRow(pw, ONE_COUNT_COLUMN, |
| 2352 | "Code:", memInfo.getSummaryCode()); |
| 2353 | printRow(pw, ONE_COUNT_COLUMN, |
| 2354 | "Stack:", memInfo.getSummaryStack()); |
| 2355 | printRow(pw, ONE_COUNT_COLUMN, |
| 2356 | "Graphics:", memInfo.getSummaryGraphics()); |
| 2357 | printRow(pw, ONE_COUNT_COLUMN, |
| 2358 | "Private Other:", memInfo.getSummaryPrivateOther()); |
| 2359 | printRow(pw, ONE_COUNT_COLUMN, |
| 2360 | "System:", memInfo.getSummarySystem()); |
| 2361 | pw.println(" "); |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2362 | if (memInfo.hasSwappedOutPss) { |
| 2363 | printRow(pw, TWO_COUNT_COLUMNS, |
| 2364 | "TOTAL:", memInfo.getSummaryTotalPss(), |
| 2365 | "TOTAL SWAP PSS:", memInfo.getSummaryTotalSwapPss()); |
| 2366 | } else { |
| 2367 | printRow(pw, TWO_COUNT_COLUMNS, |
| 2368 | "TOTAL:", memInfo.getSummaryTotalPss(), |
| 2369 | "TOTAL SWAP (KB):", memInfo.getSummaryTotalSwap()); |
| 2370 | } |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2371 | } |
| 2372 | |
Jeff Hamilton | 52d3203 | 2011-01-08 15:31:26 -0600 | [diff] [blame] | 2373 | public void registerOnActivityPausedListener(Activity activity, |
| 2374 | OnActivityPausedListener listener) { |
| 2375 | synchronized (mOnPauseListeners) { |
| 2376 | ArrayList<OnActivityPausedListener> list = mOnPauseListeners.get(activity); |
| 2377 | if (list == null) { |
| 2378 | list = new ArrayList<OnActivityPausedListener>(); |
| 2379 | mOnPauseListeners.put(activity, list); |
| 2380 | } |
| 2381 | list.add(listener); |
| 2382 | } |
| 2383 | } |
| 2384 | |
Jeff Hamilton | ce3224c | 2011-01-17 11:05:03 -0800 | [diff] [blame] | 2385 | public void unregisterOnActivityPausedListener(Activity activity, |
| 2386 | OnActivityPausedListener listener) { |
| 2387 | synchronized (mOnPauseListeners) { |
| 2388 | ArrayList<OnActivityPausedListener> list = mOnPauseListeners.get(activity); |
| 2389 | if (list != null) { |
| 2390 | list.remove(listener); |
| 2391 | } |
| 2392 | } |
| 2393 | } |
| 2394 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2395 | public final ActivityInfo resolveActivityInfo(Intent intent) { |
| 2396 | ActivityInfo aInfo = intent.resolveActivityInfo( |
| 2397 | mInitialApplication.getPackageManager(), PackageManager.GET_SHARED_LIBRARY_FILES); |
| 2398 | if (aInfo == null) { |
| 2399 | // Throw an exception. |
| 2400 | Instrumentation.checkStartActivityResult( |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 2401 | ActivityManager.START_CLASS_NOT_FOUND, intent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2402 | } |
| 2403 | return aInfo; |
| 2404 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2405 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2406 | public final Activity startActivityNow(Activity parent, String id, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2407 | Intent intent, ActivityInfo activityInfo, IBinder token, Bundle state, |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 2408 | Activity.NonConfigurationInstances lastNonConfigurationInstances) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2409 | ActivityClientRecord r = new ActivityClientRecord(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2410 | r.token = token; |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 2411 | r.ident = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2412 | r.intent = intent; |
| 2413 | r.state = state; |
| 2414 | r.parent = parent; |
| 2415 | r.embeddedID = id; |
| 2416 | r.activityInfo = activityInfo; |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 2417 | r.lastNonConfigurationInstances = lastNonConfigurationInstances; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2418 | if (localLOGV) { |
| 2419 | ComponentName compname = intent.getComponent(); |
| 2420 | String name; |
| 2421 | if (compname != null) { |
| 2422 | name = compname.toShortString(); |
| 2423 | } else { |
| 2424 | name = "(Intent " + intent + ").getComponent() returned null"; |
| 2425 | } |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2426 | Slog.v(TAG, "Performing launch: action=" + intent.getAction() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2427 | + ", comp=" + name |
| 2428 | + ", token=" + token); |
| 2429 | } |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 2430 | return performLaunchActivity(r, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2431 | } |
| 2432 | |
| 2433 | public final Activity getActivity(IBinder token) { |
| 2434 | return mActivities.get(token).activity; |
| 2435 | } |
| 2436 | |
| 2437 | public final void sendActivityResult( |
| 2438 | IBinder token, String id, int requestCode, |
| 2439 | int resultCode, Intent data) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2440 | if (DEBUG_RESULTS) Slog.v(TAG, "sendActivityResult: id=" + id |
Chris Tate | 8a7dc17 | 2009-03-24 20:11:42 -0700 | [diff] [blame] | 2441 | + " req=" + requestCode + " res=" + resultCode + " data=" + data); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2442 | ArrayList<ResultInfo> list = new ArrayList<ResultInfo>(); |
| 2443 | list.add(new ResultInfo(id, requestCode, resultCode, data)); |
| 2444 | mAppThread.scheduleSendResult(token, list); |
| 2445 | } |
| 2446 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 2447 | private void sendMessage(int what, Object obj) { |
| 2448 | sendMessage(what, obj, 0, 0, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2449 | } |
| 2450 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 2451 | private void sendMessage(int what, Object obj, int arg1) { |
| 2452 | sendMessage(what, obj, arg1, 0, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2453 | } |
| 2454 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 2455 | private void sendMessage(int what, Object obj, int arg1, int arg2) { |
| 2456 | sendMessage(what, obj, arg1, arg2, false); |
| 2457 | } |
| 2458 | |
| 2459 | private void sendMessage(int what, Object obj, int arg1, int arg2, boolean async) { |
| 2460 | if (DEBUG_MESSAGES) Slog.v( |
| 2461 | TAG, "SCHEDULE " + what + " " + mH.codeToString(what) |
| 2462 | + ": " + arg1 + " / " + obj); |
| 2463 | Message msg = Message.obtain(); |
| 2464 | msg.what = what; |
| 2465 | msg.obj = obj; |
| 2466 | msg.arg1 = arg1; |
| 2467 | msg.arg2 = arg2; |
| 2468 | if (async) { |
| 2469 | msg.setAsynchronous(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2470 | } |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 2471 | mH.sendMessage(msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2472 | } |
| 2473 | |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 2474 | private void sendMessage(int what, Object obj, int arg1, int arg2, int seq) { |
| 2475 | if (DEBUG_MESSAGES) Slog.v( |
| 2476 | TAG, "SCHEDULE " + mH.codeToString(what) + " arg1=" + arg1 + " arg2=" + arg2 + |
| 2477 | "seq= " + seq); |
| 2478 | Message msg = Message.obtain(); |
| 2479 | msg.what = what; |
| 2480 | SomeArgs args = SomeArgs.obtain(); |
| 2481 | args.arg1 = obj; |
| 2482 | args.argi1 = arg1; |
| 2483 | args.argi2 = arg2; |
| 2484 | args.argi3 = seq; |
| 2485 | msg.obj = args; |
| 2486 | mH.sendMessage(msg); |
| 2487 | } |
| 2488 | |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 2489 | final void scheduleContextCleanup(ContextImpl context, String who, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2490 | String what) { |
| 2491 | ContextCleanupInfo cci = new ContextCleanupInfo(); |
| 2492 | cci.context = context; |
| 2493 | cci.who = who; |
| 2494 | cci.what = what; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 2495 | sendMessage(H.CLEAN_UP_CONTEXT, cci); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2496 | } |
| 2497 | |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 2498 | private Activity performLaunchActivity(ActivityClientRecord r, Intent customIntent) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2499 | // System.out.println("##### [" + System.currentTimeMillis() + "] ActivityThread.performLaunchActivity(" + r + ")"); |
| 2500 | |
| 2501 | ActivityInfo aInfo = r.activityInfo; |
| 2502 | if (r.packageInfo == null) { |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2503 | r.packageInfo = getPackageInfo(aInfo.applicationInfo, r.compatInfo, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2504 | Context.CONTEXT_INCLUDE_CODE); |
| 2505 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2506 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2507 | ComponentName component = r.intent.getComponent(); |
| 2508 | if (component == null) { |
| 2509 | component = r.intent.resolveActivity( |
| 2510 | mInitialApplication.getPackageManager()); |
| 2511 | r.intent.setComponent(component); |
| 2512 | } |
| 2513 | |
| 2514 | if (r.activityInfo.targetActivity != null) { |
| 2515 | component = new ComponentName(r.activityInfo.packageName, |
| 2516 | r.activityInfo.targetActivity); |
| 2517 | } |
| 2518 | |
| 2519 | Activity activity = null; |
| 2520 | try { |
| 2521 | java.lang.ClassLoader cl = r.packageInfo.getClassLoader(); |
| 2522 | activity = mInstrumentation.newActivity( |
| 2523 | cl, component.getClassName(), r.intent); |
Brad Fitzpatrick | 5f8b5c1 | 2011-01-20 15:12:08 -0800 | [diff] [blame] | 2524 | StrictMode.incrementExpectedActivityCount(activity.getClass()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2525 | r.intent.setExtrasClassLoader(cl); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 2526 | r.intent.prepareToEnterProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2527 | if (r.state != null) { |
| 2528 | r.state.setClassLoader(cl); |
| 2529 | } |
| 2530 | } catch (Exception e) { |
| 2531 | if (!mInstrumentation.onException(activity, e)) { |
| 2532 | throw new RuntimeException( |
| 2533 | "Unable to instantiate activity " + component |
| 2534 | + ": " + e.toString(), e); |
| 2535 | } |
| 2536 | } |
| 2537 | |
| 2538 | try { |
Dianne Hackborn | 0be1f78 | 2009-11-09 12:30:12 -0800 | [diff] [blame] | 2539 | Application app = r.packageInfo.makeApplication(false, mInstrumentation); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2540 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2541 | if (localLOGV) Slog.v(TAG, "Performing launch of " + r); |
| 2542 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2543 | TAG, r + ": app=" + app |
| 2544 | + ", appName=" + app.getPackageName() |
| 2545 | + ", pkg=" + r.packageInfo.getPackageName() |
| 2546 | + ", comp=" + r.intent.getComponent().toShortString() |
| 2547 | + ", dir=" + r.packageInfo.getAppDir()); |
| 2548 | |
| 2549 | if (activity != null) { |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 2550 | Context appContext = createBaseContextForActivity(r, activity); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2551 | CharSequence title = r.activityInfo.loadLabel(appContext.getPackageManager()); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 2552 | Configuration config = new Configuration(mCompatConfiguration); |
Andrii Kulian | d0ad938 | 2016-04-18 20:54:20 -0700 | [diff] [blame] | 2553 | if (r.overrideConfig != null) { |
| 2554 | config.updateFrom(r.overrideConfig); |
| 2555 | } |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2556 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Launching activity " |
Dianne Hackborn | dc6b635 | 2009-09-30 14:20:09 -0700 | [diff] [blame] | 2557 | + r.activityInfo.name + " with config " + config); |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 2558 | Window window = null; |
| 2559 | if (r.mPendingRemoveWindow != null && r.mPreserveWindow) { |
| 2560 | window = r.mPendingRemoveWindow; |
| 2561 | r.mPendingRemoveWindow = null; |
| 2562 | r.mPendingRemoveWindowManager = null; |
| 2563 | } |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 2564 | activity.attach(appContext, this, getInstrumentation(), r.token, |
| 2565 | r.ident, app, r.intent, r.activityInfo, title, r.parent, |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 2566 | r.embeddedID, r.lastNonConfigurationInstances, config, |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 2567 | r.referrer, r.voiceInteractor, window); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2568 | |
Christopher Tate | b70f3df | 2009-04-07 16:07:59 -0700 | [diff] [blame] | 2569 | if (customIntent != null) { |
| 2570 | activity.mIntent = customIntent; |
| 2571 | } |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 2572 | r.lastNonConfigurationInstances = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2573 | activity.mStartedActivity = false; |
| 2574 | int theme = r.activityInfo.getThemeResource(); |
| 2575 | if (theme != 0) { |
| 2576 | activity.setTheme(theme); |
| 2577 | } |
| 2578 | |
| 2579 | activity.mCalled = false; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2580 | if (r.isPersistable()) { |
| 2581 | mInstrumentation.callActivityOnCreate(activity, r.state, r.persistentState); |
| 2582 | } else { |
| 2583 | mInstrumentation.callActivityOnCreate(activity, r.state); |
| 2584 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2585 | if (!activity.mCalled) { |
| 2586 | throw new SuperNotCalledException( |
| 2587 | "Activity " + r.intent.getComponent().toShortString() + |
| 2588 | " did not call through to super.onCreate()"); |
| 2589 | } |
| 2590 | r.activity = activity; |
| 2591 | r.stopped = true; |
| 2592 | if (!r.activity.mFinished) { |
| 2593 | activity.performStart(); |
| 2594 | r.stopped = false; |
| 2595 | } |
| 2596 | if (!r.activity.mFinished) { |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2597 | if (r.isPersistable()) { |
| 2598 | if (r.state != null || r.persistentState != null) { |
| 2599 | mInstrumentation.callActivityOnRestoreInstanceState(activity, r.state, |
| 2600 | r.persistentState); |
| 2601 | } |
| 2602 | } else if (r.state != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2603 | mInstrumentation.callActivityOnRestoreInstanceState(activity, r.state); |
| 2604 | } |
| 2605 | } |
| 2606 | if (!r.activity.mFinished) { |
| 2607 | activity.mCalled = false; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2608 | if (r.isPersistable()) { |
| 2609 | mInstrumentation.callActivityOnPostCreate(activity, r.state, |
| 2610 | r.persistentState); |
| 2611 | } else { |
| 2612 | mInstrumentation.callActivityOnPostCreate(activity, r.state); |
| 2613 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2614 | if (!activity.mCalled) { |
| 2615 | throw new SuperNotCalledException( |
| 2616 | "Activity " + r.intent.getComponent().toShortString() + |
| 2617 | " did not call through to super.onPostCreate()"); |
| 2618 | } |
| 2619 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2620 | } |
| 2621 | r.paused = true; |
| 2622 | |
| 2623 | mActivities.put(r.token, r); |
| 2624 | |
| 2625 | } catch (SuperNotCalledException e) { |
| 2626 | throw e; |
| 2627 | |
| 2628 | } catch (Exception e) { |
| 2629 | if (!mInstrumentation.onException(activity, e)) { |
| 2630 | throw new RuntimeException( |
| 2631 | "Unable to start activity " + component |
| 2632 | + ": " + e.toString(), e); |
| 2633 | } |
| 2634 | } |
| 2635 | |
| 2636 | return activity; |
| 2637 | } |
| 2638 | |
Wale Ogunwale | 7c72668 | 2015-02-06 17:34:28 -0800 | [diff] [blame] | 2639 | private Context createBaseContextForActivity(ActivityClientRecord r, final Activity activity) { |
| 2640 | int displayId = Display.DEFAULT_DISPLAY; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2641 | try { |
Craig Mautner | aa7e3ed | 2015-02-17 10:17:21 -0800 | [diff] [blame] | 2642 | displayId = ActivityManagerNative.getDefault().getActivityDisplayId(r.token); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2643 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2644 | throw e.rethrowFromSystemServer(); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2645 | } |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 2646 | |
Wale Ogunwale | 7c72668 | 2015-02-06 17:34:28 -0800 | [diff] [blame] | 2647 | ContextImpl appContext = ContextImpl.createActivityContext( |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 2648 | this, r.packageInfo, r.token, displayId, r.overrideConfig); |
Wale Ogunwale | 7c72668 | 2015-02-06 17:34:28 -0800 | [diff] [blame] | 2649 | appContext.setOuterContext(activity); |
| 2650 | Context baseContext = appContext; |
| 2651 | |
| 2652 | final DisplayManagerGlobal dm = DisplayManagerGlobal.getInstance(); |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 2653 | // For debugging purposes, if the activity's package name contains the value of |
| 2654 | // the "debug.use-second-display" system property as a substring, then show |
| 2655 | // its content on a secondary display if there is one. |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 2656 | String pkgName = SystemProperties.get("debug.second-display.pkg"); |
| 2657 | if (pkgName != null && !pkgName.isEmpty() |
| 2658 | && r.packageInfo.mPackageName.contains(pkgName)) { |
Wale Ogunwale | 7c72668 | 2015-02-06 17:34:28 -0800 | [diff] [blame] | 2659 | for (int id : dm.getDisplayIds()) { |
| 2660 | if (id != Display.DEFAULT_DISPLAY) { |
Wale Ogunwale | 2669851 | 2015-06-05 16:55:33 -0700 | [diff] [blame] | 2661 | Display display = |
| 2662 | dm.getCompatibleDisplay(id, appContext.getDisplayAdjustments(id)); |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 2663 | baseContext = appContext.createDisplayContext(display); |
| 2664 | break; |
| 2665 | } |
| 2666 | } |
| 2667 | } |
| 2668 | return baseContext; |
| 2669 | } |
| 2670 | |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 2671 | private void handleLaunchActivity(ActivityClientRecord r, Intent customIntent, String reason) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2672 | // If we are getting ready to gc after going to the background, well |
| 2673 | // we are back active so skip it. |
| 2674 | unscheduleGcIdler(); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 2675 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2676 | |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 2677 | if (r.profilerInfo != null) { |
| 2678 | mProfiler.setProfiler(r.profilerInfo); |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 2679 | mProfiler.startProfiling(); |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 2680 | } |
| 2681 | |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 2682 | // Make sure we are running with the most recent config. |
| 2683 | handleConfigurationChanged(null, null); |
| 2684 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2685 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2686 | TAG, "Handling launch of " + r); |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 2687 | |
Chet Haase | 0d1c27a | 2014-11-03 18:35:16 +0000 | [diff] [blame] | 2688 | // Initialize before creating the activity |
| 2689 | WindowManagerGlobal.initialize(); |
| 2690 | |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 2691 | Activity a = performLaunchActivity(r, customIntent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2692 | |
| 2693 | if (a != null) { |
Dianne Hackborn | 871ecdc | 2009-12-11 15:24:33 -0800 | [diff] [blame] | 2694 | r.createdConfig = new Configuration(mConfiguration); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 2695 | reportSizeConfigurations(r); |
Dianne Hackborn | 9e0f5d9 | 2010-02-22 15:05:42 -0800 | [diff] [blame] | 2696 | Bundle oldState = r.state; |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 2697 | handleResumeActivity(r.token, false, r.isForward, |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 2698 | !r.activity.mFinished && !r.startsNotResumed, r.lastProcessedSeq, reason); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2699 | |
| 2700 | if (!r.activity.mFinished && r.startsNotResumed) { |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 2701 | // The activity manager actually wants this one to start out paused, because it |
| 2702 | // needs to be visible but isn't in the foreground. We accomplish this by going |
| 2703 | // through the normal startup (because activities expect to go through onResume() |
| 2704 | // the first time they run, before their window is displayed), and then pausing it. |
| 2705 | // However, in this case we do -not- need to do the full pause cycle (of freezing |
| 2706 | // and such) because the activity manager assumes it can just retain the current |
| 2707 | // state it has. |
| 2708 | performPauseActivityIfNeeded(r, reason); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2709 | |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 2710 | // We need to keep around the original state, in case we need to be created again. |
| 2711 | // But we only do this for pre-Honeycomb apps, which always save their state when |
| 2712 | // pausing, so we can not have them save their state when restarting from a paused |
| 2713 | // state. For HC and later, we want to (and can) let the state be saved as the |
| 2714 | // normal part of stopping the activity. |
| 2715 | if (r.isPreHoneycomb()) { |
| 2716 | r.state = oldState; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2717 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2718 | } |
| 2719 | } else { |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 2720 | // 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] | 2721 | try { |
| 2722 | ActivityManagerNative.getDefault() |
Wale Ogunwale | ba7881c | 2015-08-01 19:28:29 -0700 | [diff] [blame] | 2723 | .finishActivity(r.token, Activity.RESULT_CANCELED, null, |
| 2724 | Activity.DONT_FINISH_TASK_WITH_ACTIVITY); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2725 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2726 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2727 | } |
| 2728 | } |
| 2729 | } |
| 2730 | |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 2731 | private void reportSizeConfigurations(ActivityClientRecord r) { |
| 2732 | Configuration[] configurations = r.activity.getResources().getSizeConfigurations(); |
| 2733 | if (configurations == null) { |
| 2734 | return; |
| 2735 | } |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 2736 | SparseIntArray horizontal = new SparseIntArray(); |
| 2737 | SparseIntArray vertical = new SparseIntArray(); |
| 2738 | SparseIntArray smallest = new SparseIntArray(); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 2739 | for (int i = configurations.length - 1; i >= 0; i--) { |
| 2740 | Configuration config = configurations[i]; |
| 2741 | if (config.screenHeightDp != Configuration.SCREEN_HEIGHT_DP_UNDEFINED) { |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 2742 | vertical.put(config.screenHeightDp, 0); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 2743 | } |
| 2744 | if (config.screenWidthDp != Configuration.SCREEN_WIDTH_DP_UNDEFINED) { |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 2745 | horizontal.put(config.screenWidthDp, 0); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 2746 | } |
| 2747 | if (config.smallestScreenWidthDp != Configuration.SMALLEST_SCREEN_WIDTH_DP_UNDEFINED) { |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 2748 | smallest.put(config.smallestScreenWidthDp, 0); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 2749 | } |
| 2750 | } |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 2751 | try { |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 2752 | ActivityManagerNative.getDefault().reportSizeConfigurations(r.token, |
| 2753 | horizontal.copyKeys(), vertical.copyKeys(), smallest.copyKeys()); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 2754 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2755 | throw ex.rethrowFromSystemServer(); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 2756 | } |
| 2757 | |
| 2758 | } |
| 2759 | |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 2760 | private void deliverNewIntents(ActivityClientRecord r, List<ReferrerIntent> intents) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2761 | final int N = intents.size(); |
| 2762 | for (int i=0; i<N; i++) { |
Dianne Hackborn | a01a0fa | 2014-12-02 10:33:14 -0800 | [diff] [blame] | 2763 | ReferrerIntent intent = intents.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2764 | intent.setExtrasClassLoader(r.activity.getClassLoader()); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 2765 | intent.prepareToEnterProcess(); |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 2766 | r.activity.mFragments.noteStateNotSaved(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2767 | mInstrumentation.callActivityOnNewIntent(r.activity, intent); |
| 2768 | } |
| 2769 | } |
| 2770 | |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 2771 | public final void performNewIntents(IBinder token, List<ReferrerIntent> intents) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2772 | ActivityClientRecord r = mActivities.get(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2773 | if (r != null) { |
| 2774 | final boolean resumed = !r.paused; |
| 2775 | if (resumed) { |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 2776 | r.activity.mTemporaryPause = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2777 | mInstrumentation.callActivityOnPause(r.activity); |
| 2778 | } |
| 2779 | deliverNewIntents(r, intents); |
| 2780 | if (resumed) { |
Dianne Hackborn | b46ed76 | 2011-06-02 18:33:15 -0700 | [diff] [blame] | 2781 | r.activity.performResume(); |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 2782 | r.activity.mTemporaryPause = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2783 | } |
| 2784 | } |
| 2785 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2786 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 2787 | private void handleNewIntent(NewIntentData data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2788 | performNewIntents(data.token, data.intents); |
| 2789 | } |
| 2790 | |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 2791 | public void handleRequestAssistContextExtras(RequestAssistContextExtras cmd) { |
Amith Yamasani | 4f128e4 | 2016-05-10 11:44:12 -0700 | [diff] [blame] | 2792 | if (mLastSessionId != cmd.sessionId) { |
| 2793 | // Clear the existing structures |
| 2794 | mLastSessionId = cmd.sessionId; |
| 2795 | for (int i = mLastAssistStructures.size() - 1; i >= 0; i--) { |
| 2796 | AssistStructure structure = mLastAssistStructures.get(i).get(); |
| 2797 | if (structure != null) { |
| 2798 | structure.clearSendChannel(); |
| 2799 | } |
| 2800 | mLastAssistStructures.remove(i); |
Dianne Hackborn | 782d498 | 2015-07-08 17:36:37 -0700 | [diff] [blame] | 2801 | } |
| 2802 | } |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 2803 | Bundle data = new Bundle(); |
Dianne Hackborn | 09d57fe | 2015-05-27 18:05:52 -0700 | [diff] [blame] | 2804 | AssistStructure structure = null; |
| 2805 | AssistContent content = new AssistContent(); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 2806 | ActivityClientRecord r = mActivities.get(cmd.activityToken); |
Dianne Hackborn | a3acdb3 | 2015-06-08 17:07:40 -0700 | [diff] [blame] | 2807 | Uri referrer = null; |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 2808 | if (r != null) { |
| 2809 | r.activity.getApplication().dispatchOnProvideAssistData(r.activity, data); |
| 2810 | r.activity.onProvideAssistData(data); |
Dianne Hackborn | a3acdb3 | 2015-06-08 17:07:40 -0700 | [diff] [blame] | 2811 | referrer = r.activity.onProvideReferrer(); |
Dianne Hackborn | a83ce1d | 2015-03-11 15:16:13 -0700 | [diff] [blame] | 2812 | if (cmd.requestType == ActivityManager.ASSIST_CONTEXT_FULL) { |
Dianne Hackborn | 09d57fe | 2015-05-27 18:05:52 -0700 | [diff] [blame] | 2813 | structure = new AssistStructure(r.activity); |
Adam Skory | 4aaed14 | 2015-04-22 11:29:31 -0600 | [diff] [blame] | 2814 | Intent activityIntent = r.activity.getIntent(); |
Dianne Hackborn | 09d57fe | 2015-05-27 18:05:52 -0700 | [diff] [blame] | 2815 | if (activityIntent != null && (r.window == null || |
| 2816 | (r.window.getAttributes().flags |
| 2817 | & WindowManager.LayoutParams.FLAG_SECURE) == 0)) { |
Adam Skory | 4aaed14 | 2015-04-22 11:29:31 -0600 | [diff] [blame] | 2818 | Intent intent = new Intent(activityIntent); |
| 2819 | intent.setFlags(intent.getFlags() & ~(Intent.FLAG_GRANT_WRITE_URI_PERMISSION |
| 2820 | | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION)); |
| 2821 | intent.removeUnsafeExtras(); |
Adam Skory | cd70c64 | 2015-06-05 11:41:55 -0600 | [diff] [blame] | 2822 | content.setDefaultIntent(intent); |
Adam Skory | 4aaed14 | 2015-04-22 11:29:31 -0600 | [diff] [blame] | 2823 | } else { |
Adam Skory | cd70c64 | 2015-06-05 11:41:55 -0600 | [diff] [blame] | 2824 | content.setDefaultIntent(new Intent()); |
Adam Skory | 4aaed14 | 2015-04-22 11:29:31 -0600 | [diff] [blame] | 2825 | } |
Dianne Hackborn | a83ce1d | 2015-03-11 15:16:13 -0700 | [diff] [blame] | 2826 | r.activity.onProvideAssistContent(content); |
Dianne Hackborn | a83ce1d | 2015-03-11 15:16:13 -0700 | [diff] [blame] | 2827 | } |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 2828 | } |
Dianne Hackborn | 09d57fe | 2015-05-27 18:05:52 -0700 | [diff] [blame] | 2829 | if (structure == null) { |
| 2830 | structure = new AssistStructure(); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 2831 | } |
Amith Yamasani | 4f128e4 | 2016-05-10 11:44:12 -0700 | [diff] [blame] | 2832 | mLastAssistStructures.add(new WeakReference<>(structure)); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 2833 | IActivityManager mgr = ActivityManagerNative.getDefault(); |
| 2834 | try { |
Dianne Hackborn | a3acdb3 | 2015-06-08 17:07:40 -0700 | [diff] [blame] | 2835 | mgr.reportAssistContextExtras(cmd.requestToken, data, structure, content, referrer); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 2836 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2837 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 2838 | } |
| 2839 | } |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 2840 | |
| 2841 | public void handleTranslucentConversionComplete(IBinder token, boolean drawComplete) { |
| 2842 | ActivityClientRecord r = mActivities.get(token); |
| 2843 | if (r != null) { |
| 2844 | r.activity.onTranslucentConversionComplete(drawComplete); |
| 2845 | } |
| 2846 | } |
| 2847 | |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 2848 | public void onNewActivityOptions(IBinder token, ActivityOptions options) { |
| 2849 | ActivityClientRecord r = mActivities.get(token); |
| 2850 | if (r != null) { |
| 2851 | r.activity.onNewActivityOptions(options); |
| 2852 | } |
| 2853 | } |
| 2854 | |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 2855 | public void handleCancelVisibleBehind(IBinder token) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 2856 | ActivityClientRecord r = mActivities.get(token); |
| 2857 | if (r != null) { |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 2858 | mSomeActivitiesChanged = true; |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 2859 | final Activity activity = r.activity; |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 2860 | if (activity.mVisibleBehind) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 2861 | activity.mCalled = false; |
Jose Lima | fcf7083 | 2014-08-27 23:09:05 -0700 | [diff] [blame] | 2862 | activity.onVisibleBehindCanceled(); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 2863 | // Tick, tick, tick. The activity has 500 msec to return or it will be destroyed. |
| 2864 | if (!activity.mCalled) { |
| 2865 | throw new SuperNotCalledException("Activity " + activity.getLocalClassName() + |
Jose Lima | fcf7083 | 2014-08-27 23:09:05 -0700 | [diff] [blame] | 2866 | " did not call through to super.onVisibleBehindCanceled()"); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 2867 | } |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 2868 | activity.mVisibleBehind = false; |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 2869 | } |
| 2870 | } |
| 2871 | try { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 2872 | ActivityManagerNative.getDefault().backgroundResourcesReleased(token); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 2873 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2874 | throw e.rethrowFromSystemServer(); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 2875 | } |
| 2876 | } |
| 2877 | |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 2878 | public void handleOnBackgroundVisibleBehindChanged(IBinder token, boolean visible) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 2879 | ActivityClientRecord r = mActivities.get(token); |
| 2880 | if (r != null) { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 2881 | r.activity.onBackgroundVisibleBehindChanged(visible); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 2882 | } |
| 2883 | } |
| 2884 | |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 2885 | public void handleInstallProvider(ProviderInfo info) { |
Jeff Sharkey | bb2e2ca | 2014-10-23 11:42:31 -0700 | [diff] [blame] | 2886 | final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); |
| 2887 | try { |
| 2888 | installContentProviders(mInitialApplication, Lists.newArrayList(info)); |
| 2889 | } finally { |
| 2890 | StrictMode.setThreadPolicy(oldPolicy); |
| 2891 | } |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 2892 | } |
| 2893 | |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 2894 | private void handleEnterAnimationComplete(IBinder token) { |
| 2895 | ActivityClientRecord r = mActivities.get(token); |
| 2896 | if (r != null) { |
Filip Gruszczynski | 6eafa90 | 2014-11-14 14:24:37 -0800 | [diff] [blame] | 2897 | r.activity.dispatchEnterAnimationComplete(); |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 2898 | } |
| 2899 | } |
| 2900 | |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 2901 | private void handleStartBinderTracking() { |
| 2902 | Binder.enableTracing(); |
| 2903 | } |
| 2904 | |
| 2905 | private void handleStopBinderTrackingAndDump(ParcelFileDescriptor fd) { |
| 2906 | try { |
| 2907 | Binder.disableTracing(); |
| 2908 | Binder.getTransactionTracker().writeTracesToFile(fd); |
| 2909 | } finally { |
| 2910 | IoUtils.closeQuietly(fd); |
| 2911 | Binder.getTransactionTracker().clearTraces(); |
| 2912 | } |
| 2913 | } |
| 2914 | |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 2915 | private void handleMultiWindowModeChanged(IBinder token, boolean isInMultiWindowMode) { |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 2916 | final ActivityClientRecord r = mActivities.get(token); |
| 2917 | if (r != null) { |
Adam Powell | 858cf03 | 2016-05-09 15:45:37 -0700 | [diff] [blame] | 2918 | r.activity.dispatchMultiWindowModeChanged(isInMultiWindowMode); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 2919 | } |
| 2920 | } |
| 2921 | |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 2922 | private void handlePictureInPictureModeChanged(IBinder token, boolean isInPipMode) { |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 2923 | final ActivityClientRecord r = mActivities.get(token); |
| 2924 | if (r != null) { |
Adam Powell | 858cf03 | 2016-05-09 15:45:37 -0700 | [diff] [blame] | 2925 | r.activity.dispatchPictureInPictureModeChanged(isInPipMode); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 2926 | } |
| 2927 | } |
| 2928 | |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 2929 | private void handleLocalVoiceInteractionStarted(IBinder token, IVoiceInteractor interactor) { |
| 2930 | final ActivityClientRecord r = mActivities.get(token); |
| 2931 | if (r != null) { |
| 2932 | r.voiceInteractor = interactor; |
| 2933 | r.activity.setVoiceInteractor(interactor); |
| 2934 | if (interactor == null) { |
| 2935 | r.activity.onLocalVoiceInteractionStopped(); |
| 2936 | } else { |
| 2937 | r.activity.onLocalVoiceInteractionStarted(); |
| 2938 | } |
| 2939 | } |
| 2940 | } |
| 2941 | |
Brad Fitzpatrick | bfb1919 | 2010-10-29 15:25:44 -0700 | [diff] [blame] | 2942 | private static final ThreadLocal<Intent> sCurrentBroadcastIntent = new ThreadLocal<Intent>(); |
| 2943 | |
| 2944 | /** |
| 2945 | * Return the Intent that's currently being handled by a |
| 2946 | * BroadcastReceiver on this thread, or null if none. |
| 2947 | * @hide |
| 2948 | */ |
| 2949 | public static Intent getIntentBeingBroadcast() { |
| 2950 | return sCurrentBroadcastIntent.get(); |
| 2951 | } |
| 2952 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 2953 | private void handleReceiver(ReceiverData data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2954 | // If we are getting ready to gc after going to the background, well |
| 2955 | // we are back active so skip it. |
| 2956 | unscheduleGcIdler(); |
| 2957 | |
| 2958 | String component = data.intent.getComponent().getClassName(); |
| 2959 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2960 | LoadedApk packageInfo = getPackageInfoNoCheck( |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2961 | data.info.applicationInfo, data.compatInfo); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2962 | |
| 2963 | IActivityManager mgr = ActivityManagerNative.getDefault(); |
| 2964 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 2965 | BroadcastReceiver receiver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2966 | try { |
| 2967 | java.lang.ClassLoader cl = packageInfo.getClassLoader(); |
| 2968 | data.intent.setExtrasClassLoader(cl); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 2969 | data.intent.prepareToEnterProcess(); |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 2970 | data.setExtrasClassLoader(cl); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2971 | receiver = (BroadcastReceiver)cl.loadClass(component).newInstance(); |
| 2972 | } catch (Exception e) { |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 2973 | if (DEBUG_BROADCAST) Slog.i(TAG, |
| 2974 | "Finishing failed broadcast to " + data.intent.getComponent()); |
| 2975 | data.sendFinished(mgr); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2976 | throw new RuntimeException( |
| 2977 | "Unable to instantiate receiver " + component |
| 2978 | + ": " + e.toString(), e); |
| 2979 | } |
| 2980 | |
| 2981 | try { |
Dianne Hackborn | 0be1f78 | 2009-11-09 12:30:12 -0800 | [diff] [blame] | 2982 | Application app = packageInfo.makeApplication(false, mInstrumentation); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2983 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2984 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2985 | TAG, "Performing receive of " + data.intent |
| 2986 | + ": app=" + app |
| 2987 | + ", appName=" + app.getPackageName() |
| 2988 | + ", pkg=" + packageInfo.getPackageName() |
| 2989 | + ", comp=" + data.intent.getComponent().toShortString() |
| 2990 | + ", dir=" + packageInfo.getAppDir()); |
| 2991 | |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 2992 | ContextImpl context = (ContextImpl)app.getBaseContext(); |
Brad Fitzpatrick | bfb1919 | 2010-10-29 15:25:44 -0700 | [diff] [blame] | 2993 | sCurrentBroadcastIntent.set(data.intent); |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 2994 | receiver.setPendingResult(data); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2995 | receiver.onReceive(context.getReceiverRestrictedContext(), |
| 2996 | data.intent); |
| 2997 | } catch (Exception e) { |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 2998 | if (DEBUG_BROADCAST) Slog.i(TAG, |
| 2999 | "Finishing failed broadcast to " + data.intent.getComponent()); |
| 3000 | data.sendFinished(mgr); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3001 | if (!mInstrumentation.onException(receiver, e)) { |
| 3002 | throw new RuntimeException( |
| 3003 | "Unable to start receiver " + component |
| 3004 | + ": " + e.toString(), e); |
| 3005 | } |
Brad Fitzpatrick | bfb1919 | 2010-10-29 15:25:44 -0700 | [diff] [blame] | 3006 | } finally { |
| 3007 | sCurrentBroadcastIntent.set(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3008 | } |
| 3009 | |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 3010 | if (receiver.getPendingResult() != null) { |
| 3011 | data.finish(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3012 | } |
| 3013 | } |
| 3014 | |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3015 | // Instantiate a BackupAgent and tell it that it's alive |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3016 | private void handleCreateBackupAgent(CreateBackupAgentData data) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3017 | if (DEBUG_BACKUP) Slog.v(TAG, "handleCreateBackupAgent: " + data); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3018 | |
Christopher Tate | 346acb1 | 2012-10-15 19:20:25 -0700 | [diff] [blame] | 3019 | // Sanity check the requested target package's uid against ours |
| 3020 | try { |
| 3021 | PackageInfo requestedPackage = getPackageManager().getPackageInfo( |
| 3022 | data.appInfo.packageName, 0, UserHandle.myUserId()); |
| 3023 | if (requestedPackage.applicationInfo.uid != Process.myUid()) { |
| 3024 | Slog.w(TAG, "Asked to instantiate non-matching package " |
| 3025 | + data.appInfo.packageName); |
| 3026 | return; |
| 3027 | } |
| 3028 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3029 | throw e.rethrowFromSystemServer(); |
Christopher Tate | 346acb1 | 2012-10-15 19:20:25 -0700 | [diff] [blame] | 3030 | } |
| 3031 | |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3032 | // no longer idle; we have backup work to do |
| 3033 | unscheduleGcIdler(); |
| 3034 | |
| 3035 | // instantiate the BackupAgent class named in the manifest |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 3036 | LoadedApk packageInfo = getPackageInfoNoCheck(data.appInfo, data.compatInfo); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3037 | String packageName = packageInfo.mPackageName; |
Christopher Tate | 346acb1 | 2012-10-15 19:20:25 -0700 | [diff] [blame] | 3038 | if (packageName == null) { |
| 3039 | Slog.d(TAG, "Asked to create backup agent for nonexistent package"); |
| 3040 | return; |
| 3041 | } |
| 3042 | |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3043 | String classname = data.appInfo.backupAgentName; |
Christopher Tate | 79ec80d | 2011-06-24 14:58:49 -0700 | [diff] [blame] | 3044 | // full backup operation but no app-supplied agent? use the default implementation |
| 3045 | if (classname == null && (data.backupMode == IApplicationThread.BACKUP_MODE_FULL |
| 3046 | || data.backupMode == IApplicationThread.BACKUP_MODE_RESTORE_FULL)) { |
Christopher Tate | 4a627c7 | 2011-04-01 14:43:32 -0700 | [diff] [blame] | 3047 | classname = "android.app.backup.FullBackupAgent"; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3048 | } |
Christopher Tate | 4a627c7 | 2011-04-01 14:43:32 -0700 | [diff] [blame] | 3049 | |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3050 | try { |
Christopher Tate | d1475e0 | 2009-07-09 15:36:17 -0700 | [diff] [blame] | 3051 | IBinder binder = null; |
Christopher Tate | 2e40d11 | 2014-07-15 12:37:38 -0700 | [diff] [blame] | 3052 | BackupAgent agent = mBackupAgents.get(packageName); |
| 3053 | if (agent != null) { |
| 3054 | // reusing the existing instance |
| 3055 | if (DEBUG_BACKUP) { |
| 3056 | Slog.v(TAG, "Reusing existing agent instance"); |
Christopher Tate | d1475e0 | 2009-07-09 15:36:17 -0700 | [diff] [blame] | 3057 | } |
Christopher Tate | 2e40d11 | 2014-07-15 12:37:38 -0700 | [diff] [blame] | 3058 | binder = agent.onBind(); |
| 3059 | } else { |
| 3060 | try { |
| 3061 | if (DEBUG_BACKUP) Slog.v(TAG, "Initializing agent class " + classname); |
| 3062 | |
| 3063 | java.lang.ClassLoader cl = packageInfo.getClassLoader(); |
| 3064 | agent = (BackupAgent) cl.loadClass(classname).newInstance(); |
| 3065 | |
| 3066 | // set up the agent's context |
| 3067 | ContextImpl context = ContextImpl.createAppContext(this, packageInfo); |
| 3068 | context.setOuterContext(agent); |
| 3069 | agent.attach(context); |
| 3070 | |
| 3071 | agent.onCreate(); |
| 3072 | binder = agent.onBind(); |
| 3073 | mBackupAgents.put(packageName, agent); |
| 3074 | } catch (Exception e) { |
| 3075 | // If this is during restore, fail silently; otherwise go |
| 3076 | // ahead and let the user see the crash. |
| 3077 | Slog.e(TAG, "Agent threw during creation: " + e); |
| 3078 | if (data.backupMode != IApplicationThread.BACKUP_MODE_RESTORE |
| 3079 | && data.backupMode != IApplicationThread.BACKUP_MODE_RESTORE_FULL) { |
| 3080 | throw e; |
| 3081 | } |
| 3082 | // falling through with 'binder' still null |
| 3083 | } |
Christopher Tate | d1475e0 | 2009-07-09 15:36:17 -0700 | [diff] [blame] | 3084 | } |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3085 | |
| 3086 | // tell the OS that we're live now |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3087 | try { |
| 3088 | ActivityManagerNative.getDefault().backupAgentCreated(packageName, binder); |
| 3089 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3090 | throw e.rethrowFromSystemServer(); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3091 | } |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3092 | } catch (Exception e) { |
| 3093 | throw new RuntimeException("Unable to create BackupAgent " |
Christopher Tate | 4a627c7 | 2011-04-01 14:43:32 -0700 | [diff] [blame] | 3094 | + classname + ": " + e.toString(), e); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3095 | } |
| 3096 | } |
| 3097 | |
| 3098 | // Tear down a BackupAgent |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3099 | private void handleDestroyBackupAgent(CreateBackupAgentData data) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3100 | if (DEBUG_BACKUP) Slog.v(TAG, "handleDestroyBackupAgent: " + data); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3101 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 3102 | LoadedApk packageInfo = getPackageInfoNoCheck(data.appInfo, data.compatInfo); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3103 | String packageName = packageInfo.mPackageName; |
| 3104 | BackupAgent agent = mBackupAgents.get(packageName); |
| 3105 | if (agent != null) { |
| 3106 | try { |
| 3107 | agent.onDestroy(); |
| 3108 | } catch (Exception e) { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 3109 | 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] | 3110 | e.printStackTrace(); |
| 3111 | } |
| 3112 | mBackupAgents.remove(packageName); |
| 3113 | } else { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 3114 | Slog.w(TAG, "Attempt to destroy unknown backup agent " + data); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3115 | } |
| 3116 | } |
| 3117 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3118 | private void handleCreateService(CreateServiceData data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3119 | // If we are getting ready to gc after going to the background, well |
| 3120 | // we are back active so skip it. |
| 3121 | unscheduleGcIdler(); |
| 3122 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3123 | LoadedApk packageInfo = getPackageInfoNoCheck( |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 3124 | data.info.applicationInfo, data.compatInfo); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3125 | Service service = null; |
| 3126 | try { |
| 3127 | java.lang.ClassLoader cl = packageInfo.getClassLoader(); |
| 3128 | service = (Service) cl.loadClass(data.info.name).newInstance(); |
| 3129 | } catch (Exception e) { |
| 3130 | if (!mInstrumentation.onException(service, e)) { |
| 3131 | throw new RuntimeException( |
| 3132 | "Unable to instantiate service " + data.info.name |
| 3133 | + ": " + e.toString(), e); |
| 3134 | } |
| 3135 | } |
| 3136 | |
| 3137 | try { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3138 | 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] | 3139 | |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 3140 | ContextImpl context = ContextImpl.createAppContext(this, packageInfo); |
| 3141 | context.setOuterContext(service); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3142 | |
Dianne Hackborn | 0be1f78 | 2009-11-09 12:30:12 -0800 | [diff] [blame] | 3143 | Application app = packageInfo.makeApplication(false, mInstrumentation); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3144 | service.attach(context, this, data.info.name, data.token, app, |
| 3145 | ActivityManagerNative.getDefault()); |
| 3146 | service.onCreate(); |
| 3147 | mServices.put(data.token, service); |
| 3148 | try { |
Dianne Hackborn | f6f9f2d | 2009-08-21 16:26:03 -0700 | [diff] [blame] | 3149 | ActivityManagerNative.getDefault().serviceDoneExecuting( |
Dianne Hackborn | 455625e | 2015-01-21 09:55:13 -0800 | [diff] [blame] | 3150 | data.token, SERVICE_DONE_EXECUTING_ANON, 0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3151 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3152 | throw e.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3153 | } |
| 3154 | } catch (Exception e) { |
| 3155 | if (!mInstrumentation.onException(service, e)) { |
| 3156 | throw new RuntimeException( |
| 3157 | "Unable to create service " + data.info.name |
| 3158 | + ": " + e.toString(), e); |
| 3159 | } |
| 3160 | } |
| 3161 | } |
| 3162 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3163 | private void handleBindService(BindServiceData data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3164 | Service s = mServices.get(data.token); |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 3165 | if (DEBUG_SERVICE) |
| 3166 | Slog.v(TAG, "handleBindService s=" + s + " rebind=" + data.rebind); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3167 | if (s != null) { |
| 3168 | try { |
| 3169 | data.intent.setExtrasClassLoader(s.getClassLoader()); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 3170 | data.intent.prepareToEnterProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3171 | try { |
| 3172 | if (!data.rebind) { |
| 3173 | IBinder binder = s.onBind(data.intent); |
| 3174 | ActivityManagerNative.getDefault().publishService( |
| 3175 | data.token, data.intent, binder); |
| 3176 | } else { |
| 3177 | s.onRebind(data.intent); |
| 3178 | ActivityManagerNative.getDefault().serviceDoneExecuting( |
Dianne Hackborn | 455625e | 2015-01-21 09:55:13 -0800 | [diff] [blame] | 3179 | data.token, SERVICE_DONE_EXECUTING_ANON, 0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3180 | } |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 3181 | ensureJitEnabled(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3182 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3183 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3184 | } |
| 3185 | } catch (Exception e) { |
| 3186 | if (!mInstrumentation.onException(s, e)) { |
| 3187 | throw new RuntimeException( |
| 3188 | "Unable to bind to service " + s |
| 3189 | + " with " + data.intent + ": " + e.toString(), e); |
| 3190 | } |
| 3191 | } |
| 3192 | } |
| 3193 | } |
| 3194 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3195 | private void handleUnbindService(BindServiceData data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3196 | Service s = mServices.get(data.token); |
| 3197 | if (s != null) { |
| 3198 | try { |
| 3199 | data.intent.setExtrasClassLoader(s.getClassLoader()); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 3200 | data.intent.prepareToEnterProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3201 | boolean doRebind = s.onUnbind(data.intent); |
| 3202 | try { |
| 3203 | if (doRebind) { |
| 3204 | ActivityManagerNative.getDefault().unbindFinished( |
| 3205 | data.token, data.intent, doRebind); |
| 3206 | } else { |
| 3207 | ActivityManagerNative.getDefault().serviceDoneExecuting( |
Dianne Hackborn | 455625e | 2015-01-21 09:55:13 -0800 | [diff] [blame] | 3208 | data.token, SERVICE_DONE_EXECUTING_ANON, 0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3209 | } |
| 3210 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3211 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3212 | } |
| 3213 | } catch (Exception e) { |
| 3214 | if (!mInstrumentation.onException(s, e)) { |
| 3215 | throw new RuntimeException( |
| 3216 | "Unable to unbind to service " + s |
| 3217 | + " with " + data.intent + ": " + e.toString(), e); |
| 3218 | } |
| 3219 | } |
| 3220 | } |
| 3221 | } |
| 3222 | |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 3223 | private void handleDumpService(DumpComponentInfo info) { |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3224 | final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); |
| 3225 | try { |
| 3226 | Service s = mServices.get(info.token); |
| 3227 | if (s != null) { |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 3228 | PrintWriter pw = new FastPrintWriter(new FileOutputStream( |
| 3229 | info.fd.getFileDescriptor())); |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3230 | s.dump(info.fd.getFileDescriptor(), pw, info.args); |
| 3231 | pw.flush(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3232 | } |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3233 | } finally { |
| 3234 | IoUtils.closeQuietly(info.fd); |
| 3235 | StrictMode.setThreadPolicy(oldPolicy); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3236 | } |
| 3237 | } |
| 3238 | |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 3239 | private void handleDumpActivity(DumpComponentInfo info) { |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3240 | final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); |
| 3241 | try { |
| 3242 | ActivityClientRecord r = mActivities.get(info.token); |
| 3243 | if (r != null && r.activity != null) { |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 3244 | PrintWriter pw = new FastPrintWriter(new FileOutputStream( |
| 3245 | info.fd.getFileDescriptor())); |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3246 | r.activity.dump(info.prefix, info.fd.getFileDescriptor(), pw, info.args); |
| 3247 | pw.flush(); |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 3248 | } |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3249 | } finally { |
| 3250 | IoUtils.closeQuietly(info.fd); |
| 3251 | StrictMode.setThreadPolicy(oldPolicy); |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 3252 | } |
| 3253 | } |
| 3254 | |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 3255 | private void handleDumpProvider(DumpComponentInfo info) { |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3256 | final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); |
| 3257 | try { |
| 3258 | ProviderClientRecord r = mLocalProviders.get(info.token); |
| 3259 | if (r != null && r.mLocalProvider != null) { |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 3260 | PrintWriter pw = new FastPrintWriter(new FileOutputStream( |
| 3261 | info.fd.getFileDescriptor())); |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3262 | r.mLocalProvider.dump(info.fd.getFileDescriptor(), pw, info.args); |
| 3263 | pw.flush(); |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 3264 | } |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3265 | } finally { |
| 3266 | IoUtils.closeQuietly(info.fd); |
| 3267 | StrictMode.setThreadPolicy(oldPolicy); |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 3268 | } |
| 3269 | } |
| 3270 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3271 | private void handleServiceArgs(ServiceArgsData data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3272 | Service s = mServices.get(data.token); |
| 3273 | if (s != null) { |
| 3274 | try { |
| 3275 | if (data.args != null) { |
| 3276 | data.args.setExtrasClassLoader(s.getClassLoader()); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 3277 | data.args.prepareToEnterProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3278 | } |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 3279 | int res; |
| 3280 | if (!data.taskRemoved) { |
| 3281 | res = s.onStartCommand(data.args, data.flags, data.startId); |
| 3282 | } else { |
| 3283 | s.onTaskRemoved(data.args); |
| 3284 | res = Service.START_TASK_REMOVED_COMPLETE; |
| 3285 | } |
Brad Fitzpatrick | 333b8cb | 2010-08-26 12:04:57 -0700 | [diff] [blame] | 3286 | |
| 3287 | QueuedWork.waitToFinish(); |
| 3288 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3289 | try { |
Dianne Hackborn | f6f9f2d | 2009-08-21 16:26:03 -0700 | [diff] [blame] | 3290 | ActivityManagerNative.getDefault().serviceDoneExecuting( |
Dianne Hackborn | 455625e | 2015-01-21 09:55:13 -0800 | [diff] [blame] | 3291 | data.token, SERVICE_DONE_EXECUTING_START, data.startId, res); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3292 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3293 | throw e.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3294 | } |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 3295 | ensureJitEnabled(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3296 | } catch (Exception e) { |
| 3297 | if (!mInstrumentation.onException(s, e)) { |
| 3298 | throw new RuntimeException( |
| 3299 | "Unable to start service " + s |
| 3300 | + " with " + data.args + ": " + e.toString(), e); |
| 3301 | } |
| 3302 | } |
| 3303 | } |
| 3304 | } |
| 3305 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3306 | private void handleStopService(IBinder token) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3307 | Service s = mServices.remove(token); |
| 3308 | if (s != null) { |
| 3309 | try { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3310 | if (localLOGV) Slog.v(TAG, "Destroying service " + s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3311 | s.onDestroy(); |
| 3312 | Context context = s.getBaseContext(); |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 3313 | if (context instanceof ContextImpl) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3314 | final String who = s.getClassName(); |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 3315 | ((ContextImpl) context).scheduleFinalCleanup(who, "Service"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3316 | } |
Brad Fitzpatrick | 333b8cb | 2010-08-26 12:04:57 -0700 | [diff] [blame] | 3317 | |
| 3318 | QueuedWork.waitToFinish(); |
| 3319 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3320 | try { |
Dianne Hackborn | f6f9f2d | 2009-08-21 16:26:03 -0700 | [diff] [blame] | 3321 | ActivityManagerNative.getDefault().serviceDoneExecuting( |
Dianne Hackborn | 455625e | 2015-01-21 09:55:13 -0800 | [diff] [blame] | 3322 | token, SERVICE_DONE_EXECUTING_STOP, 0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3323 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3324 | throw e.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3325 | } |
| 3326 | } catch (Exception e) { |
| 3327 | if (!mInstrumentation.onException(s, e)) { |
| 3328 | throw new RuntimeException( |
| 3329 | "Unable to stop service " + s |
| 3330 | + ": " + e.toString(), e); |
| 3331 | } |
Craig Mautner | 66c4a82 | 2015-01-16 12:48:16 -0800 | [diff] [blame] | 3332 | Slog.i(TAG, "handleStopService: exception for " + token, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3333 | } |
Craig Mautner | 9776ad4 | 2015-01-15 14:38:39 -0800 | [diff] [blame] | 3334 | } else { |
| 3335 | Slog.i(TAG, "handleStopService: token=" + token + " not found."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3336 | } |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3337 | //Slog.i(TAG, "Running services: " + mServices); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3338 | } |
| 3339 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3340 | public final ActivityClientRecord performResumeActivity(IBinder token, |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 3341 | boolean clearHide, String reason) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3342 | ActivityClientRecord r = mActivities.get(token); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3343 | if (localLOGV) Slog.v(TAG, "Performing resume of " + r |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3344 | + " finished=" + r.activity.mFinished); |
| 3345 | if (r != null && !r.activity.mFinished) { |
| 3346 | if (clearHide) { |
| 3347 | r.hideForNow = false; |
| 3348 | r.activity.mStartedActivity = false; |
| 3349 | } |
| 3350 | try { |
Dianne Hackborn | 6bdd3a1 | 2015-08-05 15:01:28 -0700 | [diff] [blame] | 3351 | r.activity.onStateNotSaved(); |
Dianne Hackborn | 689586d | 2012-10-01 18:23:04 -0700 | [diff] [blame] | 3352 | r.activity.mFragments.noteStateNotSaved(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3353 | if (r.pendingIntents != null) { |
| 3354 | deliverNewIntents(r, r.pendingIntents); |
| 3355 | r.pendingIntents = null; |
| 3356 | } |
| 3357 | if (r.pendingResults != null) { |
| 3358 | deliverResults(r, r.pendingResults); |
| 3359 | r.pendingResults = null; |
| 3360 | } |
| 3361 | r.activity.performResume(); |
| 3362 | |
Filip Gruszczynski | c3b6179 | 2016-01-22 16:43:48 -0800 | [diff] [blame] | 3363 | // If there is a pending local relaunch that was requested when the activity was |
| 3364 | // paused, it will put the activity into paused state when it finally happens. |
| 3365 | // Since the activity resumed before being relaunched, we don't want that to happen, |
| 3366 | // so we need to clear the request to relaunch paused. |
| 3367 | for (int i = mRelaunchingActivities.size() - 1; i >= 0; i--) { |
| 3368 | final ActivityClientRecord relaunching = mRelaunchingActivities.get(i); |
| 3369 | if (relaunching.token == r.token |
| 3370 | && relaunching.onlyLocalRequest && relaunching.startsNotResumed) { |
| 3371 | relaunching.startsNotResumed = false; |
| 3372 | } |
| 3373 | } |
| 3374 | |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 3375 | EventLog.writeEvent(LOG_AM_ON_RESUME_CALLED, UserHandle.myUserId(), |
| 3376 | r.activity.getComponentName().getClassName(), reason); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3377 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3378 | r.paused = false; |
| 3379 | r.stopped = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3380 | r.state = null; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3381 | r.persistentState = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3382 | } catch (Exception e) { |
| 3383 | if (!mInstrumentation.onException(r.activity, e)) { |
| 3384 | throw new RuntimeException( |
| 3385 | "Unable to resume activity " |
| 3386 | + r.intent.getComponent().toShortString() |
| 3387 | + ": " + e.toString(), e); |
| 3388 | } |
| 3389 | } |
| 3390 | } |
| 3391 | return r; |
| 3392 | } |
| 3393 | |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 3394 | static final void cleanUpPendingRemoveWindows(ActivityClientRecord r, boolean force) { |
| 3395 | if (r.mPreserveWindow && !force) { |
| 3396 | return; |
| 3397 | } |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 3398 | if (r.mPendingRemoveWindow != null) { |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 3399 | r.mPendingRemoveWindowManager.removeViewImmediate( |
| 3400 | r.mPendingRemoveWindow.getDecorView()); |
| 3401 | IBinder wtoken = r.mPendingRemoveWindow.getDecorView().getWindowToken(); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 3402 | if (wtoken != null) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 3403 | WindowManagerGlobal.getInstance().closeAll(wtoken, |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 3404 | r.activity.getClass().getName(), "Activity"); |
| 3405 | } |
| 3406 | } |
| 3407 | r.mPendingRemoveWindow = null; |
| 3408 | r.mPendingRemoveWindowManager = null; |
| 3409 | } |
| 3410 | |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 3411 | final void handleResumeActivity(IBinder token, |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 3412 | boolean clearHide, boolean isForward, boolean reallyResume, int seq, String reason) { |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 3413 | ActivityClientRecord r = mActivities.get(token); |
| 3414 | if (!checkAndUpdateLifecycleSeq(seq, r, "resumeActivity")) { |
| 3415 | return; |
| 3416 | } |
| 3417 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3418 | // If we are getting ready to gc after going to the background, well |
| 3419 | // we are back active so skip it. |
| 3420 | unscheduleGcIdler(); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3421 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3422 | |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 3423 | // TODO Push resumeArgs into the activity for consideration |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 3424 | r = performResumeActivity(token, clearHide, reason); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3425 | |
| 3426 | if (r != null) { |
| 3427 | final Activity a = r.activity; |
| 3428 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3429 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3430 | TAG, "Resume " + r + " started activity: " + |
| 3431 | a.mStartedActivity + ", hideForNow: " + r.hideForNow |
| 3432 | + ", finished: " + a.mFinished); |
| 3433 | |
| 3434 | final int forwardBit = isForward ? |
| 3435 | WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION : 0; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3436 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3437 | // If the window hasn't yet been added to the window manager, |
| 3438 | // and this guy didn't finish itself or start another activity, |
| 3439 | // then go ahead and add the window. |
Dianne Hackborn | 061d58a | 2010-03-12 15:07:06 -0800 | [diff] [blame] | 3440 | boolean willBeVisible = !a.mStartedActivity; |
| 3441 | if (!willBeVisible) { |
| 3442 | try { |
| 3443 | willBeVisible = ActivityManagerNative.getDefault().willActivityBeVisible( |
| 3444 | a.getActivityToken()); |
| 3445 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3446 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 061d58a | 2010-03-12 15:07:06 -0800 | [diff] [blame] | 3447 | } |
| 3448 | } |
| 3449 | if (r.window == null && !a.mFinished && willBeVisible) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3450 | r.window = r.activity.getWindow(); |
| 3451 | View decor = r.window.getDecorView(); |
| 3452 | decor.setVisibility(View.INVISIBLE); |
| 3453 | ViewManager wm = a.getWindowManager(); |
| 3454 | WindowManager.LayoutParams l = r.window.getAttributes(); |
| 3455 | a.mDecor = decor; |
| 3456 | l.type = WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
| 3457 | l.softInputMode |= forwardBit; |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 3458 | if (r.mPreserveWindow) { |
| 3459 | a.mWindowAdded = true; |
| 3460 | r.mPreserveWindow = false; |
Robert Carr | b259485 | 2016-04-25 16:21:13 -0700 | [diff] [blame] | 3461 | // Normally the ViewRoot sets up callbacks with the Activity |
| 3462 | // in addView->ViewRootImpl#setView. If we are instead reusing |
| 3463 | // the decor view we have to notify the view root that the |
| 3464 | // callbacks may have changed. |
| 3465 | ViewRootImpl impl = decor.getViewRootImpl(); |
Robert Carr | 311ecba | 2016-04-27 12:59:45 -0700 | [diff] [blame] | 3466 | if (impl != null) { |
| 3467 | impl.notifyChildRebuilt(); |
| 3468 | } |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 3469 | } |
| 3470 | if (a.mVisibleFromClient && !a.mWindowAdded) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3471 | a.mWindowAdded = true; |
| 3472 | wm.addView(decor, l); |
| 3473 | } |
| 3474 | |
| 3475 | // If the window has already been added, but during resume |
| 3476 | // we started another activity, then don't yet make the |
Dianne Hackborn | 061d58a | 2010-03-12 15:07:06 -0800 | [diff] [blame] | 3477 | // window visible. |
| 3478 | } else if (!willBeVisible) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3479 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3480 | TAG, "Launch " + r + " mStartedActivity set"); |
| 3481 | r.hideForNow = true; |
| 3482 | } |
| 3483 | |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 3484 | // Get rid of anything left hanging around. |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 3485 | cleanUpPendingRemoveWindows(r, false /* force */); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 3486 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3487 | // The window is now visible if it has been added, we are not |
| 3488 | // simply finishing, and we are not starting another activity. |
Dianne Hackborn | 061d58a | 2010-03-12 15:07:06 -0800 | [diff] [blame] | 3489 | if (!r.activity.mFinished && willBeVisible |
Dianne Hackborn | c1e605e | 2009-09-25 17:18:15 -0700 | [diff] [blame] | 3490 | && r.activity.mDecor != null && !r.hideForNow) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3491 | if (r.newConfig != null) { |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 3492 | performConfigurationChangedForActivity(r, r.newConfig, REPORT_TO_ACTIVITY); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3493 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Resuming activity " |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 3494 | + r.activityInfo.name + " with newConfig " + r.activity.mCurrentConfig); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3495 | r.newConfig = null; |
| 3496 | } |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3497 | if (localLOGV) Slog.v(TAG, "Resuming " + r + " with isForward=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3498 | + isForward); |
| 3499 | WindowManager.LayoutParams l = r.window.getAttributes(); |
| 3500 | if ((l.softInputMode |
| 3501 | & WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) |
| 3502 | != forwardBit) { |
| 3503 | l.softInputMode = (l.softInputMode |
| 3504 | & (~WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION)) |
| 3505 | | forwardBit; |
Dianne Hackborn | c1e605e | 2009-09-25 17:18:15 -0700 | [diff] [blame] | 3506 | if (r.activity.mVisibleFromClient) { |
| 3507 | ViewManager wm = a.getWindowManager(); |
| 3508 | View decor = r.window.getDecorView(); |
| 3509 | wm.updateViewLayout(decor, l); |
| 3510 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3511 | } |
| 3512 | r.activity.mVisibleFromServer = true; |
| 3513 | mNumVisibleActivities++; |
| 3514 | if (r.activity.mVisibleFromClient) { |
| 3515 | r.activity.makeVisible(); |
| 3516 | } |
| 3517 | } |
| 3518 | |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 3519 | if (!r.onlyLocalRequest) { |
| 3520 | r.nextIdle = mNewActivities; |
| 3521 | mNewActivities = r; |
| 3522 | if (localLOGV) Slog.v( |
| 3523 | TAG, "Scheduling idle handler for " + r); |
| 3524 | Looper.myQueue().addIdleHandler(new Idler()); |
| 3525 | } |
| 3526 | r.onlyLocalRequest = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3527 | |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 3528 | // Tell the activity manager we have resumed. |
| 3529 | if (reallyResume) { |
| 3530 | try { |
| 3531 | ActivityManagerNative.getDefault().activityResumed(token); |
| 3532 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3533 | throw ex.rethrowFromSystemServer(); |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 3534 | } |
| 3535 | } |
| 3536 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3537 | } else { |
| 3538 | // If an exception was thrown when trying to resume, then |
| 3539 | // just end this activity. |
| 3540 | try { |
| 3541 | ActivityManagerNative.getDefault() |
Wale Ogunwale | ba7881c | 2015-08-01 19:28:29 -0700 | [diff] [blame] | 3542 | .finishActivity(token, Activity.RESULT_CANCELED, null, |
| 3543 | Activity.DONT_FINISH_TASK_WITH_ACTIVITY); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3544 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3545 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3546 | } |
| 3547 | } |
| 3548 | } |
| 3549 | |
| 3550 | private int mThumbnailWidth = -1; |
| 3551 | private int mThumbnailHeight = -1; |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3552 | private Bitmap mAvailThumbnailBitmap = null; |
| 3553 | private Canvas mThumbnailCanvas = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3554 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3555 | private Bitmap createThumbnailBitmap(ActivityClientRecord r) { |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3556 | Bitmap thumbnail = mAvailThumbnailBitmap; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3557 | try { |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3558 | if (thumbnail == null) { |
| 3559 | int w = mThumbnailWidth; |
| 3560 | int h; |
| 3561 | if (w < 0) { |
| 3562 | Resources res = r.activity.getResources(); |
Winson Chung | 6784f1c | 2014-05-22 11:22:41 -0700 | [diff] [blame] | 3563 | int wId = com.android.internal.R.dimen.thumbnail_width; |
| 3564 | int hId = com.android.internal.R.dimen.thumbnail_height; |
Winson Chung | fd08622 | 2014-05-13 15:49:42 -0700 | [diff] [blame] | 3565 | mThumbnailWidth = w = res.getDimensionPixelSize(wId); |
| 3566 | mThumbnailHeight = h = res.getDimensionPixelSize(hId); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3567 | } else { |
| 3568 | h = mThumbnailHeight; |
| 3569 | } |
| 3570 | |
| 3571 | // On platforms where we don't want thumbnails, set dims to (0,0) |
| 3572 | if ((w > 0) && (h > 0)) { |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 3573 | thumbnail = Bitmap.createBitmap(r.activity.getResources().getDisplayMetrics(), |
| 3574 | w, h, THUMBNAIL_FORMAT); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3575 | thumbnail.eraseColor(0); |
| 3576 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3577 | } |
| 3578 | |
Dianne Hackborn | fb3806d | 2010-12-09 13:14:12 -0800 | [diff] [blame] | 3579 | if (thumbnail != null) { |
| 3580 | Canvas cv = mThumbnailCanvas; |
| 3581 | if (cv == null) { |
| 3582 | mThumbnailCanvas = cv = new Canvas(); |
| 3583 | } |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 3584 | |
Dianne Hackborn | fb3806d | 2010-12-09 13:14:12 -0800 | [diff] [blame] | 3585 | cv.setBitmap(thumbnail); |
| 3586 | if (!r.activity.onCreateThumbnail(thumbnail, cv)) { |
| 3587 | mAvailThumbnailBitmap = thumbnail; |
| 3588 | thumbnail = null; |
| 3589 | } |
Dianne Hackborn | 6311d0a | 2011-08-02 16:37:58 -0700 | [diff] [blame] | 3590 | cv.setBitmap(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3591 | } |
Jim Miller | 0b2a6d0 | 2010-07-13 18:01:29 -0700 | [diff] [blame] | 3592 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3593 | } catch (Exception e) { |
| 3594 | if (!mInstrumentation.onException(r.activity, e)) { |
| 3595 | throw new RuntimeException( |
| 3596 | "Unable to create thumbnail of " |
| 3597 | + r.intent.getComponent().toShortString() |
| 3598 | + ": " + e.toString(), e); |
| 3599 | } |
| 3600 | thumbnail = null; |
| 3601 | } |
| 3602 | |
| 3603 | return thumbnail; |
| 3604 | } |
| 3605 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3606 | private void handlePauseActivity(IBinder token, boolean finished, |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 3607 | boolean userLeaving, int configChanges, boolean dontReport, int seq) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3608 | ActivityClientRecord r = mActivities.get(token); |
Filip Gruszczynski | c3b6179 | 2016-01-22 16:43:48 -0800 | [diff] [blame] | 3609 | if (DEBUG_ORDER) Slog.d(TAG, "handlePauseActivity " + r + ", seq: " + seq); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 3610 | if (!checkAndUpdateLifecycleSeq(seq, r, "pauseActivity")) { |
| 3611 | return; |
| 3612 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3613 | if (r != null) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3614 | //Slog.v(TAG, "userLeaving=" + userLeaving + " handling pause of " + r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3615 | if (userLeaving) { |
| 3616 | performUserLeavingActivity(r); |
| 3617 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3618 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3619 | r.activity.mConfigChangeFlags |= configChanges; |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 3620 | performPauseActivity(token, finished, r.isPreHoneycomb(), "handlePauseActivity"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3621 | |
Dianne Hackborn | aa93bcd | 2010-10-27 13:57:00 -0700 | [diff] [blame] | 3622 | // Make sure any pending writes are now committed. |
Dianne Hackborn | 5d9d03a | 2011-01-24 13:15:09 -0800 | [diff] [blame] | 3623 | if (r.isPreHoneycomb()) { |
| 3624 | QueuedWork.waitToFinish(); |
| 3625 | } |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 3626 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3627 | // Tell the activity manager we have paused. |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 3628 | if (!dontReport) { |
| 3629 | try { |
| 3630 | ActivityManagerNative.getDefault().activityPaused(token); |
| 3631 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3632 | throw ex.rethrowFromSystemServer(); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 3633 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3634 | } |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3635 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3636 | } |
| 3637 | } |
| 3638 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3639 | final void performUserLeavingActivity(ActivityClientRecord r) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3640 | mInstrumentation.callActivityOnUserLeaving(r.activity); |
| 3641 | } |
| 3642 | |
| 3643 | final Bundle performPauseActivity(IBinder token, boolean finished, |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 3644 | boolean saveState, String reason) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3645 | ActivityClientRecord r = mActivities.get(token); |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 3646 | return r != null ? performPauseActivity(r, finished, saveState, reason) : null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3647 | } |
| 3648 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3649 | final Bundle performPauseActivity(ActivityClientRecord r, boolean finished, |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 3650 | boolean saveState, String reason) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3651 | if (r.paused) { |
| 3652 | if (r.activity.mFinished) { |
| 3653 | // If we are finishing, we won't call onResume() in certain cases. |
| 3654 | // So here we likewise don't want to call onPause() if the activity |
| 3655 | // isn't resumed. |
| 3656 | return null; |
| 3657 | } |
| 3658 | RuntimeException e = new RuntimeException( |
| 3659 | "Performing pause of activity that is not resumed: " |
| 3660 | + r.intent.getComponent().toShortString()); |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 3661 | Slog.e(TAG, e.getMessage(), e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3662 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3663 | if (finished) { |
| 3664 | r.activity.mFinished = true; |
| 3665 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3666 | |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 3667 | // Next have the activity save its current state and managed dialogs... |
| 3668 | if (!r.activity.mFinished && saveState) { |
| 3669 | callCallActivityOnSaveInstanceState(r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3670 | } |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 3671 | |
| 3672 | performPauseActivityIfNeeded(r, reason); |
Jeff Hamilton | 52d3203 | 2011-01-08 15:31:26 -0600 | [diff] [blame] | 3673 | |
| 3674 | // Notify any outstanding on paused listeners |
| 3675 | ArrayList<OnActivityPausedListener> listeners; |
| 3676 | synchronized (mOnPauseListeners) { |
| 3677 | listeners = mOnPauseListeners.remove(r.activity); |
| 3678 | } |
| 3679 | int size = (listeners != null ? listeners.size() : 0); |
| 3680 | for (int i = 0; i < size; i++) { |
| 3681 | listeners.get(i).onPaused(r.activity); |
| 3682 | } |
| 3683 | |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3684 | return !r.activity.mFinished && saveState ? r.state : null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3685 | } |
| 3686 | |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 3687 | private void performPauseActivityIfNeeded(ActivityClientRecord r, String reason) { |
| 3688 | if (r.paused) { |
| 3689 | // You are already paused silly... |
| 3690 | return; |
| 3691 | } |
| 3692 | |
| 3693 | try { |
| 3694 | r.activity.mCalled = false; |
| 3695 | mInstrumentation.callActivityOnPause(r.activity); |
| 3696 | EventLog.writeEvent(LOG_AM_ON_PAUSE_CALLED, UserHandle.myUserId(), |
| 3697 | r.activity.getComponentName().getClassName(), reason); |
| 3698 | if (!r.activity.mCalled) { |
| 3699 | throw new SuperNotCalledException("Activity " + safeToComponentShortString(r.intent) |
| 3700 | + " did not call through to super.onPause()"); |
| 3701 | } |
| 3702 | } catch (SuperNotCalledException e) { |
| 3703 | throw e; |
| 3704 | } catch (Exception e) { |
| 3705 | if (!mInstrumentation.onException(r.activity, e)) { |
| 3706 | throw new RuntimeException("Unable to pause activity " |
| 3707 | + safeToComponentShortString(r.intent) + ": " + e.toString(), e); |
| 3708 | } |
| 3709 | } |
| 3710 | r.paused = true; |
| 3711 | } |
| 3712 | |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 3713 | final void performStopActivity(IBinder token, boolean saveState, String reason) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3714 | ActivityClientRecord r = mActivities.get(token); |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 3715 | performStopActivityInner(r, null, false, saveState, reason); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3716 | } |
| 3717 | |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 3718 | private static class StopInfo implements Runnable { |
| 3719 | ActivityClientRecord activity; |
| 3720 | Bundle state; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3721 | PersistableBundle persistentState; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3722 | CharSequence description; |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 3723 | |
| 3724 | @Override public void run() { |
| 3725 | // Tell activity manager we have been stopped. |
| 3726 | try { |
| 3727 | if (DEBUG_MEMORY_TRIM) Slog.v(TAG, "Reporting activity stopped: " + activity); |
| 3728 | ActivityManagerNative.getDefault().activityStopped( |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3729 | activity.token, state, persistentState, description); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 3730 | } catch (RemoteException ex) { |
Jeff Sharkey | 369f509 | 2016-02-29 11:16:21 -0700 | [diff] [blame] | 3731 | if (ex instanceof TransactionTooLargeException |
Jeff Sharkey | 9ad8613 | 2016-03-01 11:22:59 -0700 | [diff] [blame] | 3732 | && activity.packageInfo.getTargetSdkVersion() < Build.VERSION_CODES.N) { |
Jeff Sharkey | b8e8a91 | 2016-03-09 16:27:40 -0700 | [diff] [blame] | 3733 | 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] | 3734 | return; |
| 3735 | } |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3736 | throw ex.rethrowFromSystemServer(); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 3737 | } |
| 3738 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3739 | } |
| 3740 | |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 3741 | private static final class ProviderRefCount { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 3742 | public final IActivityManager.ContentProviderHolder holder; |
| 3743 | public final ProviderClientRecord client; |
| 3744 | public int stableCount; |
| 3745 | public int unstableCount; |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 3746 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 3747 | // When this is set, the stable and unstable ref counts are 0 and |
| 3748 | // we have a pending operation scheduled to remove the ref count |
| 3749 | // from the activity manager. On the activity manager we are still |
| 3750 | // holding an unstable ref, though it is not reflected in the counts |
| 3751 | // here. |
| 3752 | public boolean removePending; |
| 3753 | |
| 3754 | ProviderRefCount(IActivityManager.ContentProviderHolder inHolder, |
| 3755 | ProviderClientRecord inClient, int sCount, int uCount) { |
| 3756 | holder = inHolder; |
| 3757 | client = inClient; |
| 3758 | stableCount = sCount; |
| 3759 | unstableCount = uCount; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3760 | } |
| 3761 | } |
| 3762 | |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3763 | /** |
| 3764 | * Core implementation of stopping an activity. Note this is a little |
| 3765 | * tricky because the server's meaning of stop is slightly different |
| 3766 | * than our client -- for the server, stop means to save state and give |
| 3767 | * it the result when it is done, but the window may still be visible. |
| 3768 | * For the client, we want to call onStop()/onStart() to indicate when |
| 3769 | * the activity's UI visibillity changes. |
| 3770 | */ |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3771 | private void performStopActivityInner(ActivityClientRecord r, |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 3772 | StopInfo info, boolean keepShown, boolean saveState, String reason) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3773 | if (localLOGV) Slog.v(TAG, "Performing stop of " + r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3774 | if (r != null) { |
| 3775 | if (!keepShown && r.stopped) { |
| 3776 | if (r.activity.mFinished) { |
| 3777 | // If we are finishing, we won't call onResume() in certain |
| 3778 | // cases. So here we likewise don't want to call onStop() |
| 3779 | // if the activity isn't resumed. |
| 3780 | return; |
| 3781 | } |
| 3782 | RuntimeException e = new RuntimeException( |
Andrii Kulian | 58178f2 | 2016-03-16 13:44:56 -0700 | [diff] [blame] | 3783 | "Performing stop of activity that is already stopped: " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3784 | + r.intent.getComponent().toShortString()); |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 3785 | Slog.e(TAG, e.getMessage(), e); |
Andrii Kulian | 58178f2 | 2016-03-16 13:44:56 -0700 | [diff] [blame] | 3786 | Slog.e(TAG, r.getStateString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3787 | } |
| 3788 | |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 3789 | // One must first be paused before stopped... |
| 3790 | performPauseActivityIfNeeded(r, reason); |
| 3791 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3792 | if (info != null) { |
| 3793 | try { |
| 3794 | // First create a thumbnail for the activity... |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3795 | // For now, don't create the thumbnail here; we are |
| 3796 | // doing that by doing a screen snapshot. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3797 | info.description = r.activity.onCreateDescription(); |
| 3798 | } catch (Exception e) { |
| 3799 | if (!mInstrumentation.onException(r.activity, e)) { |
| 3800 | throw new RuntimeException( |
| 3801 | "Unable to save state of activity " |
| 3802 | + r.intent.getComponent().toShortString() |
| 3803 | + ": " + e.toString(), e); |
| 3804 | } |
| 3805 | } |
| 3806 | } |
| 3807 | |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3808 | // Next have the activity save its current state and managed dialogs... |
| 3809 | if (!r.activity.mFinished && saveState) { |
| 3810 | if (r.state == null) { |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3811 | callCallActivityOnSaveInstanceState(r); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3812 | } |
| 3813 | } |
| 3814 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3815 | if (!keepShown) { |
| 3816 | try { |
| 3817 | // Now we are idle. |
Chong Zhang | 7687f25 | 2016-02-26 12:03:33 -0800 | [diff] [blame] | 3818 | r.activity.performStop(false /*preserveWindow*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3819 | } catch (Exception e) { |
| 3820 | if (!mInstrumentation.onException(r.activity, e)) { |
| 3821 | throw new RuntimeException( |
| 3822 | "Unable to stop activity " |
| 3823 | + r.intent.getComponent().toShortString() |
| 3824 | + ": " + e.toString(), e); |
| 3825 | } |
| 3826 | } |
| 3827 | r.stopped = true; |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 3828 | EventLog.writeEvent(LOG_AM_ON_STOP_CALLED, UserHandle.myUserId(), |
| 3829 | r.activity.getComponentName().getClassName(), reason); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3830 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3831 | } |
| 3832 | } |
| 3833 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3834 | private void updateVisibility(ActivityClientRecord r, boolean show) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3835 | View v = r.activity.mDecor; |
| 3836 | if (v != null) { |
| 3837 | if (show) { |
| 3838 | if (!r.activity.mVisibleFromServer) { |
| 3839 | r.activity.mVisibleFromServer = true; |
| 3840 | mNumVisibleActivities++; |
| 3841 | if (r.activity.mVisibleFromClient) { |
| 3842 | r.activity.makeVisible(); |
| 3843 | } |
| 3844 | } |
| 3845 | if (r.newConfig != null) { |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 3846 | performConfigurationChangedForActivity(r, r.newConfig, REPORT_TO_ACTIVITY); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3847 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Updating activity vis " |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 3848 | + r.activityInfo.name + " with new config " |
| 3849 | + r.activity.mCurrentConfig); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3850 | r.newConfig = null; |
| 3851 | } |
| 3852 | } else { |
| 3853 | if (r.activity.mVisibleFromServer) { |
| 3854 | r.activity.mVisibleFromServer = false; |
| 3855 | mNumVisibleActivities--; |
| 3856 | v.setVisibility(View.INVISIBLE); |
| 3857 | } |
| 3858 | } |
| 3859 | } |
| 3860 | } |
| 3861 | |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 3862 | private void handleStopActivity(IBinder token, boolean show, int configChanges, int seq) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3863 | ActivityClientRecord r = mActivities.get(token); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 3864 | if (!checkAndUpdateLifecycleSeq(seq, r, "stopActivity")) { |
| 3865 | return; |
| 3866 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3867 | r.activity.mConfigChangeFlags |= configChanges; |
| 3868 | |
| 3869 | StopInfo info = new StopInfo(); |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 3870 | performStopActivityInner(r, info, show, true, "handleStopActivity"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3871 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3872 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3873 | TAG, "Finishing stop of " + r + ": show=" + show |
| 3874 | + " win=" + r.window); |
| 3875 | |
| 3876 | updateVisibility(r, show); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3877 | |
Dianne Hackborn | 5d9d03a | 2011-01-24 13:15:09 -0800 | [diff] [blame] | 3878 | // Make sure any pending writes are now committed. |
| 3879 | if (!r.isPreHoneycomb()) { |
| 3880 | QueuedWork.waitToFinish(); |
| 3881 | } |
| 3882 | |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 3883 | // Schedule the call to tell the activity manager we have |
| 3884 | // stopped. We don't do this immediately, because we want to |
| 3885 | // have a chance for any other pending work (in particular memory |
| 3886 | // trim requests) to complete before you tell the activity |
| 3887 | // manager to proceed and allow us to go fully into the background. |
| 3888 | info.activity = r; |
| 3889 | info.state = r.state; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3890 | info.persistentState = r.persistentState; |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 3891 | mH.post(info); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3892 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3893 | } |
| 3894 | |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 3895 | private static boolean checkAndUpdateLifecycleSeq(int seq, ActivityClientRecord r, |
| 3896 | String action) { |
| 3897 | if (r == null) { |
| 3898 | return true; |
| 3899 | } |
| 3900 | if (seq < r.lastProcessedSeq) { |
| 3901 | if (DEBUG_ORDER) Slog.d(TAG, action + " for " + r + " ignored, because seq=" + seq |
| 3902 | + " < mCurrentLifecycleSeq=" + r.lastProcessedSeq); |
| 3903 | return false; |
| 3904 | } |
| 3905 | r.lastProcessedSeq = seq; |
| 3906 | return true; |
| 3907 | } |
| 3908 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3909 | final void performRestartActivity(IBinder token) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3910 | ActivityClientRecord r = mActivities.get(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3911 | if (r.stopped) { |
| 3912 | r.activity.performRestart(); |
| 3913 | r.stopped = false; |
| 3914 | } |
| 3915 | } |
| 3916 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3917 | private void handleWindowVisibility(IBinder token, boolean show) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3918 | ActivityClientRecord r = mActivities.get(token); |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 3919 | |
Dianne Hackborn | bfddc0f | 2010-12-14 11:28:01 -0800 | [diff] [blame] | 3920 | if (r == null) { |
| 3921 | Log.w(TAG, "handleWindowVisibility: no activity for token " + token); |
| 3922 | return; |
| 3923 | } |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 3924 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3925 | if (!show && !r.stopped) { |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 3926 | performStopActivityInner(r, null, show, false, "handleWindowVisibility"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3927 | } else if (show && r.stopped) { |
| 3928 | // If we are getting ready to gc after going to the background, well |
| 3929 | // we are back active so skip it. |
| 3930 | unscheduleGcIdler(); |
| 3931 | |
| 3932 | r.activity.performRestart(); |
| 3933 | r.stopped = false; |
| 3934 | } |
| 3935 | if (r.activity.mDecor != null) { |
Joe Onorato | 43a1765 | 2011-04-06 19:22:23 -0700 | [diff] [blame] | 3936 | if (false) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3937 | TAG, "Handle window " + r + " visibility: " + show); |
| 3938 | updateVisibility(r, show); |
| 3939 | } |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3940 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3941 | } |
| 3942 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3943 | private void handleSleeping(IBinder token, boolean sleeping) { |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 3944 | ActivityClientRecord r = mActivities.get(token); |
| 3945 | |
| 3946 | if (r == null) { |
Dianne Hackborn | 842e04b | 2011-01-22 13:00:12 -0800 | [diff] [blame] | 3947 | Log.w(TAG, "handleSleeping: no activity for token " + token); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 3948 | return; |
| 3949 | } |
| 3950 | |
| 3951 | if (sleeping) { |
Dianne Hackborn | 842e04b | 2011-01-22 13:00:12 -0800 | [diff] [blame] | 3952 | if (!r.stopped && !r.isPreHoneycomb()) { |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 3953 | try { |
| 3954 | // Now we are idle. |
Chong Zhang | 7687f25 | 2016-02-26 12:03:33 -0800 | [diff] [blame] | 3955 | r.activity.performStop(false /*preserveWindow*/); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 3956 | } catch (Exception e) { |
| 3957 | if (!mInstrumentation.onException(r.activity, e)) { |
| 3958 | throw new RuntimeException( |
| 3959 | "Unable to stop activity " |
| 3960 | + r.intent.getComponent().toShortString() |
| 3961 | + ": " + e.toString(), e); |
| 3962 | } |
| 3963 | } |
| 3964 | r.stopped = true; |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 3965 | EventLog.writeEvent(LOG_AM_ON_STOP_CALLED, UserHandle.myUserId(), |
| 3966 | r.activity.getComponentName().getClassName(), "sleeping"); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 3967 | } |
Dianne Hackborn | 5d9d03a | 2011-01-24 13:15:09 -0800 | [diff] [blame] | 3968 | |
| 3969 | // Make sure any pending writes are now committed. |
| 3970 | if (!r.isPreHoneycomb()) { |
| 3971 | QueuedWork.waitToFinish(); |
| 3972 | } |
| 3973 | |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 3974 | // Tell activity manager we slept. |
| 3975 | try { |
| 3976 | ActivityManagerNative.getDefault().activitySlept(r.token); |
| 3977 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3978 | throw ex.rethrowFromSystemServer(); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 3979 | } |
| 3980 | } else { |
| 3981 | if (r.stopped && r.activity.mVisibleFromServer) { |
| 3982 | r.activity.performRestart(); |
| 3983 | r.stopped = false; |
| 3984 | } |
| 3985 | } |
| 3986 | } |
| 3987 | |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 3988 | private void handleSetCoreSettings(Bundle coreSettings) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 3989 | synchronized (mResourcesManager) { |
Svetoslav Ganov | 9aa597e | 2011-03-03 18:17:41 -0800 | [diff] [blame] | 3990 | mCoreSettings = coreSettings; |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 3991 | } |
Jon Miranda | 836c0a8 | 2014-08-11 12:32:26 -0700 | [diff] [blame] | 3992 | onCoreSettingsChange(); |
| 3993 | } |
| 3994 | |
| 3995 | private void onCoreSettingsChange() { |
| 3996 | boolean debugViewAttributes = |
| 3997 | mCoreSettings.getInt(Settings.Global.DEBUG_VIEW_ATTRIBUTES, 0) != 0; |
| 3998 | if (debugViewAttributes != View.mDebugViewAttributes) { |
| 3999 | View.mDebugViewAttributes = debugViewAttributes; |
| 4000 | |
| 4001 | // request all activities to relaunch for the changes to take place |
| 4002 | for (Map.Entry<IBinder, ActivityClientRecord> entry : mActivities.entrySet()) { |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4003 | requestRelaunchActivity(entry.getKey(), null, null, 0, false, null, null, false, |
| 4004 | false /* preserveWindow */); |
Jon Miranda | 836c0a8 | 2014-08-11 12:32:26 -0700 | [diff] [blame] | 4005 | } |
| 4006 | } |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 4007 | } |
| 4008 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4009 | private void handleUpdatePackageCompatibilityInfo(UpdateCompatibilityData data) { |
| 4010 | LoadedApk apk = peekPackageInfo(data.pkg, false); |
| 4011 | if (apk != null) { |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 4012 | apk.setCompatibilityInfo(data.info); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4013 | } |
| 4014 | apk = peekPackageInfo(data.pkg, true); |
| 4015 | if (apk != null) { |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 4016 | apk.setCompatibilityInfo(data.info); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4017 | } |
| 4018 | handleConfigurationChanged(mConfiguration, data.info); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 4019 | WindowManagerGlobal.getInstance().reportNewConfiguration(mConfiguration); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4020 | } |
| 4021 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 4022 | private void deliverResults(ActivityClientRecord r, List<ResultInfo> results) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4023 | final int N = results.size(); |
| 4024 | for (int i=0; i<N; i++) { |
| 4025 | ResultInfo ri = results.get(i); |
| 4026 | try { |
| 4027 | if (ri.mData != null) { |
| 4028 | ri.mData.setExtrasClassLoader(r.activity.getClassLoader()); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 4029 | ri.mData.prepareToEnterProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4030 | } |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4031 | if (DEBUG_RESULTS) Slog.v(TAG, |
Chris Tate | 8a7dc17 | 2009-03-24 20:11:42 -0700 | [diff] [blame] | 4032 | "Delivering result to activity " + r + " : " + ri); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4033 | r.activity.dispatchActivityResult(ri.mResultWho, |
| 4034 | ri.mRequestCode, ri.mResultCode, ri.mData); |
| 4035 | } catch (Exception e) { |
| 4036 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4037 | throw new RuntimeException( |
| 4038 | "Failure delivering result " + ri + " to activity " |
| 4039 | + r.intent.getComponent().toShortString() |
| 4040 | + ": " + e.toString(), e); |
| 4041 | } |
| 4042 | } |
| 4043 | } |
| 4044 | } |
| 4045 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 4046 | private void handleSendResult(ResultData res) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4047 | ActivityClientRecord r = mActivities.get(res.token); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4048 | 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] | 4049 | if (r != null) { |
| 4050 | final boolean resumed = !r.paused; |
| 4051 | if (!r.activity.mFinished && r.activity.mDecor != null |
| 4052 | && r.hideForNow && resumed) { |
| 4053 | // We had hidden the activity because it started another |
| 4054 | // one... we have gotten a result back and we are not |
| 4055 | // paused, so make sure our window is visible. |
| 4056 | updateVisibility(r, true); |
| 4057 | } |
| 4058 | if (resumed) { |
| 4059 | try { |
| 4060 | // Now we are idle. |
| 4061 | r.activity.mCalled = false; |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 4062 | r.activity.mTemporaryPause = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4063 | mInstrumentation.callActivityOnPause(r.activity); |
| 4064 | if (!r.activity.mCalled) { |
| 4065 | throw new SuperNotCalledException( |
| 4066 | "Activity " + r.intent.getComponent().toShortString() |
| 4067 | + " did not call through to super.onPause()"); |
| 4068 | } |
| 4069 | } catch (SuperNotCalledException e) { |
| 4070 | throw e; |
| 4071 | } catch (Exception e) { |
| 4072 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4073 | throw new RuntimeException( |
| 4074 | "Unable to pause activity " |
| 4075 | + r.intent.getComponent().toShortString() |
| 4076 | + ": " + e.toString(), e); |
| 4077 | } |
| 4078 | } |
| 4079 | } |
| 4080 | deliverResults(r, res.results); |
| 4081 | if (resumed) { |
Dianne Hackborn | b46ed76 | 2011-06-02 18:33:15 -0700 | [diff] [blame] | 4082 | r.activity.performResume(); |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 4083 | r.activity.mTemporaryPause = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4084 | } |
| 4085 | } |
| 4086 | } |
| 4087 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4088 | public final ActivityClientRecord performDestroyActivity(IBinder token, boolean finishing) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4089 | return performDestroyActivity(token, finishing, 0, false); |
| 4090 | } |
| 4091 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 4092 | private ActivityClientRecord performDestroyActivity(IBinder token, boolean finishing, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4093 | int configChanges, boolean getNonConfigInstance) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4094 | ActivityClientRecord r = mActivities.get(token); |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4095 | Class<? extends Activity> activityClass = null; |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4096 | if (localLOGV) Slog.v(TAG, "Performing finish of " + r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4097 | if (r != null) { |
Brad Fitzpatrick | 5f8b5c1 | 2011-01-20 15:12:08 -0800 | [diff] [blame] | 4098 | activityClass = r.activity.getClass(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4099 | r.activity.mConfigChangeFlags |= configChanges; |
| 4100 | if (finishing) { |
| 4101 | r.activity.mFinished = true; |
| 4102 | } |
Wale Ogunwale | 5dc6d65 | 2016-05-04 10:24:33 -0700 | [diff] [blame] | 4103 | |
| 4104 | performPauseActivityIfNeeded(r, "destroy"); |
| 4105 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4106 | if (!r.stopped) { |
| 4107 | try { |
Chong Zhang | 7687f25 | 2016-02-26 12:03:33 -0800 | [diff] [blame] | 4108 | r.activity.performStop(r.mPreserveWindow); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4109 | } catch (SuperNotCalledException e) { |
| 4110 | throw e; |
| 4111 | } catch (Exception e) { |
| 4112 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4113 | throw new RuntimeException( |
| 4114 | "Unable to stop activity " |
Mitsuru Oshima | d9aef73 | 2009-06-16 20:20:50 -0700 | [diff] [blame] | 4115 | + safeToComponentShortString(r.intent) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4116 | + ": " + e.toString(), e); |
| 4117 | } |
| 4118 | } |
| 4119 | r.stopped = true; |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 4120 | EventLog.writeEvent(LOG_AM_ON_STOP_CALLED, UserHandle.myUserId(), |
| 4121 | r.activity.getComponentName().getClassName(), "destroy"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4122 | } |
| 4123 | if (getNonConfigInstance) { |
| 4124 | try { |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 4125 | r.lastNonConfigurationInstances |
| 4126 | = r.activity.retainNonConfigurationInstances(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4127 | } catch (Exception e) { |
| 4128 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4129 | throw new RuntimeException( |
| 4130 | "Unable to retain activity " |
| 4131 | + r.intent.getComponent().toShortString() |
| 4132 | + ": " + e.toString(), e); |
| 4133 | } |
| 4134 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4135 | } |
| 4136 | try { |
| 4137 | r.activity.mCalled = false; |
Dianne Hackborn | 2dedce6 | 2010-04-15 14:45:25 -0700 | [diff] [blame] | 4138 | mInstrumentation.callActivityOnDestroy(r.activity); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4139 | if (!r.activity.mCalled) { |
| 4140 | throw new SuperNotCalledException( |
Mitsuru Oshima | d9aef73 | 2009-06-16 20:20:50 -0700 | [diff] [blame] | 4141 | "Activity " + safeToComponentShortString(r.intent) + |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4142 | " did not call through to super.onDestroy()"); |
| 4143 | } |
| 4144 | if (r.window != null) { |
| 4145 | r.window.closeAllPanels(); |
| 4146 | } |
| 4147 | } catch (SuperNotCalledException e) { |
| 4148 | throw e; |
| 4149 | } catch (Exception e) { |
| 4150 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4151 | throw new RuntimeException( |
Mitsuru Oshima | d9aef73 | 2009-06-16 20:20:50 -0700 | [diff] [blame] | 4152 | "Unable to destroy activity " + safeToComponentShortString(r.intent) |
| 4153 | + ": " + e.toString(), e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4154 | } |
| 4155 | } |
| 4156 | } |
| 4157 | mActivities.remove(token); |
Brad Fitzpatrick | 5f8b5c1 | 2011-01-20 15:12:08 -0800 | [diff] [blame] | 4158 | StrictMode.decrementExpectedActivityCount(activityClass); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4159 | return r; |
| 4160 | } |
| 4161 | |
Mitsuru Oshima | d9aef73 | 2009-06-16 20:20:50 -0700 | [diff] [blame] | 4162 | private static String safeToComponentShortString(Intent intent) { |
| 4163 | ComponentName component = intent.getComponent(); |
| 4164 | return component == null ? "[Unknown]" : component.toShortString(); |
| 4165 | } |
| 4166 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 4167 | private void handleDestroyActivity(IBinder token, boolean finishing, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4168 | int configChanges, boolean getNonConfigInstance) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4169 | ActivityClientRecord r = performDestroyActivity(token, finishing, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4170 | configChanges, getNonConfigInstance); |
| 4171 | if (r != null) { |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4172 | cleanUpPendingRemoveWindows(r, finishing); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4173 | WindowManager wm = r.activity.getWindowManager(); |
| 4174 | View v = r.activity.mDecor; |
| 4175 | if (v != null) { |
| 4176 | if (r.activity.mVisibleFromServer) { |
| 4177 | mNumVisibleActivities--; |
| 4178 | } |
| 4179 | IBinder wtoken = v.getWindowToken(); |
| 4180 | if (r.activity.mWindowAdded) { |
Robert Carr | 77bdfb5 | 2016-05-02 18:18:31 -0700 | [diff] [blame] | 4181 | if (r.mPreserveWindow) { |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4182 | // Hold off on removing this until the new activity's |
| 4183 | // window is being added. |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4184 | r.mPendingRemoveWindow = r.window; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4185 | r.mPendingRemoveWindowManager = wm; |
Andrii Kulian | eac0ea5 | 2016-05-11 15:50:24 -0700 | [diff] [blame] | 4186 | // We can only keep the part of the view hierarchy that we control, |
| 4187 | // everything else must be removed, because it might not be able to |
| 4188 | // behave properly when activity is relaunching. |
| 4189 | r.window.clearContentView(); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4190 | } else { |
| 4191 | wm.removeViewImmediate(v); |
| 4192 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4193 | } |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4194 | if (wtoken != null && r.mPendingRemoveWindow == null) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 4195 | WindowManagerGlobal.getInstance().closeAll(wtoken, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4196 | r.activity.getClass().getName(), "Activity"); |
Andrii Kulian | eac0ea5 | 2016-05-11 15:50:24 -0700 | [diff] [blame] | 4197 | } else if (r.mPendingRemoveWindow != null) { |
| 4198 | // We're preserving only one window, others should be closed so app views |
| 4199 | // will be detached before the final tear down. It should be done now because |
| 4200 | // some components (e.g. WebView) rely on detach callbacks to perform receiver |
| 4201 | // unregister and other cleanup. |
| 4202 | WindowManagerGlobal.getInstance().closeAllExceptView(token, v, |
| 4203 | r.activity.getClass().getName(), "Activity"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4204 | } |
| 4205 | r.activity.mDecor = null; |
| 4206 | } |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4207 | if (r.mPendingRemoveWindow == null) { |
| 4208 | // If we are delaying the removal of the activity window, then |
| 4209 | // we can't clean up all windows here. Note that we can't do |
| 4210 | // so later either, which means any windows that aren't closed |
| 4211 | // by the app will leak. Well we try to warning them a lot |
| 4212 | // about leaking windows, because that is a bug, so if they are |
| 4213 | // using this recreate facility then they get to live with leaks. |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 4214 | WindowManagerGlobal.getInstance().closeAll(token, |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4215 | r.activity.getClass().getName(), "Activity"); |
| 4216 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4217 | |
| 4218 | // Mocked out contexts won't be participating in the normal |
| 4219 | // process lifecycle, but if we're running with a proper |
| 4220 | // ApplicationContext we need to have it tear down things |
| 4221 | // cleanly. |
| 4222 | Context c = r.activity.getBaseContext(); |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 4223 | if (c instanceof ContextImpl) { |
| 4224 | ((ContextImpl) c).scheduleFinalCleanup( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4225 | r.activity.getClass().getName(), "Activity"); |
| 4226 | } |
| 4227 | } |
| 4228 | if (finishing) { |
| 4229 | try { |
| 4230 | ActivityManagerNative.getDefault().activityDestroyed(token); |
| 4231 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4232 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4233 | } |
| 4234 | } |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4235 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4236 | } |
| 4237 | |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4238 | /** |
| 4239 | * @param preserveWindow Whether the activity should try to reuse the window it created, |
| 4240 | * including the decor view after the relaunch. |
| 4241 | */ |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4242 | public final void requestRelaunchActivity(IBinder token, |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 4243 | List<ResultInfo> pendingResults, List<ReferrerIntent> pendingNewIntents, |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4244 | int configChanges, boolean notResumed, Configuration config, |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4245 | Configuration overrideConfig, boolean fromServer, boolean preserveWindow) { |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4246 | ActivityClientRecord target = null; |
| 4247 | |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4248 | synchronized (mResourcesManager) { |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4249 | for (int i=0; i<mRelaunchingActivities.size(); i++) { |
| 4250 | ActivityClientRecord r = mRelaunchingActivities.get(i); |
Filip Gruszczynski | c3b6179 | 2016-01-22 16:43:48 -0800 | [diff] [blame] | 4251 | if (DEBUG_ORDER) Slog.d(TAG, "requestRelaunchActivity: " + this + ", trying: " + r); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4252 | if (r.token == token) { |
| 4253 | target = r; |
| 4254 | if (pendingResults != null) { |
| 4255 | if (r.pendingResults != null) { |
| 4256 | r.pendingResults.addAll(pendingResults); |
| 4257 | } else { |
| 4258 | r.pendingResults = pendingResults; |
| 4259 | } |
| 4260 | } |
| 4261 | if (pendingNewIntents != null) { |
| 4262 | if (r.pendingIntents != null) { |
| 4263 | r.pendingIntents.addAll(pendingNewIntents); |
| 4264 | } else { |
| 4265 | r.pendingIntents = pendingNewIntents; |
| 4266 | } |
| 4267 | } |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4268 | |
| 4269 | // For each relaunch request, activity manager expects an answer |
| 4270 | if (!r.onlyLocalRequest && fromServer) { |
| 4271 | try { |
| 4272 | ActivityManagerNative.getDefault().activityRelaunched(token); |
| 4273 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4274 | throw e.rethrowFromSystemServer(); |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4275 | } |
| 4276 | } |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4277 | break; |
| 4278 | } |
| 4279 | } |
| 4280 | |
| 4281 | if (target == null) { |
Filip Gruszczynski | c3b6179 | 2016-01-22 16:43:48 -0800 | [diff] [blame] | 4282 | if (DEBUG_ORDER) Slog.d(TAG, "requestRelaunchActivity: target is null, fromServer:" |
| 4283 | + fromServer); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4284 | target = new ActivityClientRecord(); |
| 4285 | target.token = token; |
| 4286 | target.pendingResults = pendingResults; |
| 4287 | target.pendingIntents = pendingNewIntents; |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4288 | target.mPreserveWindow = preserveWindow; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4289 | if (!fromServer) { |
Filip Gruszczynski | c3b6179 | 2016-01-22 16:43:48 -0800 | [diff] [blame] | 4290 | final ActivityClientRecord existing = mActivities.get(token); |
| 4291 | if (DEBUG_ORDER) Slog.d(TAG, "requestRelaunchActivity: " + existing); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4292 | if (existing != null) { |
Filip Gruszczynski | c3b6179 | 2016-01-22 16:43:48 -0800 | [diff] [blame] | 4293 | if (DEBUG_ORDER) Slog.d(TAG, "requestRelaunchActivity: paused= " |
| 4294 | + existing.paused);; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4295 | target.startsNotResumed = existing.paused; |
Wale Ogunwale | 93f543c | 2015-02-17 16:55:03 -0800 | [diff] [blame] | 4296 | target.overrideConfig = existing.overrideConfig; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4297 | } |
| 4298 | target.onlyLocalRequest = true; |
| 4299 | } |
| 4300 | mRelaunchingActivities.add(target); |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 4301 | sendMessage(H.RELAUNCH_ACTIVITY, target); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4302 | } |
| 4303 | |
| 4304 | if (fromServer) { |
| 4305 | target.startsNotResumed = notResumed; |
| 4306 | target.onlyLocalRequest = false; |
| 4307 | } |
| 4308 | if (config != null) { |
| 4309 | target.createdConfig = config; |
| 4310 | } |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 4311 | if (overrideConfig != null) { |
| 4312 | target.overrideConfig = overrideConfig; |
| 4313 | } |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4314 | target.pendingConfigChanges |= configChanges; |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 4315 | target.relaunchSeq = getLifecycleSeq(); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4316 | } |
Filip Gruszczynski | c3b6179 | 2016-01-22 16:43:48 -0800 | [diff] [blame] | 4317 | if (DEBUG_ORDER) Slog.d(TAG, "relaunchActivity " + ActivityThread.this + ", target " |
| 4318 | + target + " operation received seq: " + target.relaunchSeq); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4319 | } |
| 4320 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 4321 | private void handleRelaunchActivity(ActivityClientRecord tmp) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4322 | // If we are getting ready to gc after going to the background, well |
| 4323 | // we are back active so skip it. |
| 4324 | unscheduleGcIdler(); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4325 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4326 | |
| 4327 | Configuration changedConfig = null; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4328 | int configChanges = 0; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4329 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4330 | // First: make sure we have the most recent configuration and most |
| 4331 | // recent version of the activity, or skip it if some previous call |
| 4332 | // had taken a more recent version. |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4333 | synchronized (mResourcesManager) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4334 | int N = mRelaunchingActivities.size(); |
| 4335 | IBinder token = tmp.token; |
| 4336 | tmp = null; |
| 4337 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4338 | ActivityClientRecord r = mRelaunchingActivities.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4339 | if (r.token == token) { |
| 4340 | tmp = r; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4341 | configChanges |= tmp.pendingConfigChanges; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4342 | mRelaunchingActivities.remove(i); |
| 4343 | i--; |
| 4344 | N--; |
| 4345 | } |
| 4346 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4347 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4348 | if (tmp == null) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4349 | 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] | 4350 | return; |
| 4351 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4352 | |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4353 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Relaunching activity " |
| 4354 | + tmp.token + " with configChanges=0x" |
| 4355 | + Integer.toHexString(configChanges)); |
| 4356 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4357 | if (mPendingConfiguration != null) { |
| 4358 | changedConfig = mPendingConfiguration; |
| 4359 | mPendingConfiguration = null; |
| 4360 | } |
| 4361 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4362 | |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 4363 | if (tmp.lastProcessedSeq > tmp.relaunchSeq) { |
| 4364 | Slog.wtf(TAG, "For some reason target: " + tmp + " has lower sequence: " |
| 4365 | + tmp.relaunchSeq + " than current sequence: " + tmp.lastProcessedSeq); |
| 4366 | } else { |
| 4367 | tmp.lastProcessedSeq = tmp.relaunchSeq; |
| 4368 | } |
Dianne Hackborn | 871ecdc | 2009-12-11 15:24:33 -0800 | [diff] [blame] | 4369 | if (tmp.createdConfig != null) { |
| 4370 | // If the activity manager is passing us its current config, |
| 4371 | // assume that is really what we want regardless of what we |
| 4372 | // may have pending. |
| 4373 | if (mConfiguration == null |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4374 | || (tmp.createdConfig.isOtherSeqNewer(mConfiguration) |
| 4375 | && mConfiguration.diff(tmp.createdConfig) != 0)) { |
| 4376 | if (changedConfig == null |
| 4377 | || tmp.createdConfig.isOtherSeqNewer(changedConfig)) { |
| 4378 | changedConfig = tmp.createdConfig; |
| 4379 | } |
Dianne Hackborn | 871ecdc | 2009-12-11 15:24:33 -0800 | [diff] [blame] | 4380 | } |
| 4381 | } |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 4382 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4383 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Relaunching activity " |
Dianne Hackborn | dc6b635 | 2009-09-30 14:20:09 -0700 | [diff] [blame] | 4384 | + tmp.token + ": changedConfig=" + changedConfig); |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 4385 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4386 | // If there was a pending configuration change, execute it first. |
| 4387 | if (changedConfig != null) { |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 4388 | mCurDefaultDisplayDpi = changedConfig.densityDpi; |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 4389 | updateDefaultDensity(); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4390 | handleConfigurationChanged(changedConfig, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4391 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4392 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4393 | ActivityClientRecord r = mActivities.get(tmp.token); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4394 | 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] | 4395 | if (r == null) { |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4396 | if (!tmp.onlyLocalRequest) { |
| 4397 | try { |
| 4398 | ActivityManagerNative.getDefault().activityRelaunched(tmp.token); |
| 4399 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4400 | throw e.rethrowFromSystemServer(); |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4401 | } |
| 4402 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4403 | return; |
| 4404 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4405 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4406 | r.activity.mConfigChangeFlags |= configChanges; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4407 | r.onlyLocalRequest = tmp.onlyLocalRequest; |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4408 | r.mPreserveWindow = tmp.mPreserveWindow; |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 4409 | r.lastProcessedSeq = tmp.lastProcessedSeq; |
| 4410 | r.relaunchSeq = tmp.relaunchSeq; |
Christopher Tate | b70f3df | 2009-04-07 16:07:59 -0700 | [diff] [blame] | 4411 | Intent currentIntent = r.activity.mIntent; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4412 | |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4413 | r.activity.mChangingConfigurations = true; |
| 4414 | |
Robert Carr | 23fa16b | 2016-01-13 13:19:58 -0800 | [diff] [blame] | 4415 | // If we are preserving the main window across relaunches we would also like to preserve |
| 4416 | // the children. However the client side view system does not support preserving |
| 4417 | // the child views so we notify the window manager to expect these windows to |
| 4418 | // be replaced and defer requests to destroy or hide them. This way we can achieve |
| 4419 | // visual continuity. It's important that we do this here prior to pause and destroy |
| 4420 | // as that is when we may hide or remove the child views. |
Robert Carr | 77bdfb5 | 2016-05-02 18:18:31 -0700 | [diff] [blame] | 4421 | // |
| 4422 | // There is another scenario, if we have decided locally to relaunch the app from a |
| 4423 | // call to recreate, then none of the windows will be prepared for replacement or |
| 4424 | // preserved by the server, so we want to notify it that we are preparing to replace |
| 4425 | // everything |
Robert Carr | 23fa16b | 2016-01-13 13:19:58 -0800 | [diff] [blame] | 4426 | try { |
Robert Carr | 77bdfb5 | 2016-05-02 18:18:31 -0700 | [diff] [blame] | 4427 | if (r.mPreserveWindow || r.onlyLocalRequest) { |
| 4428 | WindowManagerGlobal.getWindowSession().prepareToReplaceWindows( |
| 4429 | r.token, !r.onlyLocalRequest); |
Robert Carr | 23fa16b | 2016-01-13 13:19:58 -0800 | [diff] [blame] | 4430 | } |
| 4431 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4432 | throw e.rethrowFromSystemServer(); |
Robert Carr | 23fa16b | 2016-01-13 13:19:58 -0800 | [diff] [blame] | 4433 | } |
| 4434 | |
Dianne Hackborn | e2b0480 | 2010-12-09 09:24:55 -0800 | [diff] [blame] | 4435 | // Need to ensure state is saved. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4436 | if (!r.paused) { |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 4437 | performPauseActivity(r.token, false, r.isPreHoneycomb(), "handleRelaunchActivity"); |
Dianne Hackborn | e2b0480 | 2010-12-09 09:24:55 -0800 | [diff] [blame] | 4438 | } |
| 4439 | if (r.state == null && !r.stopped && !r.isPreHoneycomb()) { |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 4440 | callCallActivityOnSaveInstanceState(r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4441 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4442 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4443 | handleDestroyActivity(r.token, false, configChanges, true); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4444 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4445 | r.activity = null; |
| 4446 | r.window = null; |
| 4447 | r.hideForNow = false; |
| 4448 | r.nextIdle = null; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4449 | // Merge any pending results and pending intents; don't just replace them |
| 4450 | if (tmp.pendingResults != null) { |
| 4451 | if (r.pendingResults == null) { |
| 4452 | r.pendingResults = tmp.pendingResults; |
| 4453 | } else { |
| 4454 | r.pendingResults.addAll(tmp.pendingResults); |
| 4455 | } |
| 4456 | } |
| 4457 | if (tmp.pendingIntents != null) { |
| 4458 | if (r.pendingIntents == null) { |
| 4459 | r.pendingIntents = tmp.pendingIntents; |
| 4460 | } else { |
| 4461 | r.pendingIntents.addAll(tmp.pendingIntents); |
| 4462 | } |
| 4463 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4464 | r.startsNotResumed = tmp.startsNotResumed; |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 4465 | r.overrideConfig = tmp.overrideConfig; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4466 | |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 4467 | handleLaunchActivity(r, currentIntent, "handleRelaunchActivity"); |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4468 | |
| 4469 | if (!tmp.onlyLocalRequest) { |
| 4470 | try { |
| 4471 | ActivityManagerNative.getDefault().activityRelaunched(r.token); |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 4472 | if (r.window != null) { |
| 4473 | r.window.reportActivityRelaunched(); |
| 4474 | } |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4475 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4476 | throw e.rethrowFromSystemServer(); |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4477 | } |
| 4478 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4479 | } |
| 4480 | |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 4481 | private void callCallActivityOnSaveInstanceState(ActivityClientRecord r) { |
| 4482 | r.state = new Bundle(); |
| 4483 | r.state.setAllowFds(false); |
| 4484 | if (r.isPersistable()) { |
| 4485 | r.persistentState = new PersistableBundle(); |
| 4486 | mInstrumentation.callActivityOnSaveInstanceState(r.activity, r.state, |
| 4487 | r.persistentState); |
| 4488 | } else { |
| 4489 | mInstrumentation.callActivityOnSaveInstanceState(r.activity, r.state); |
| 4490 | } |
| 4491 | } |
| 4492 | |
Dianne Hackborn | 73c1416 | 2012-09-19 15:45:06 -0700 | [diff] [blame] | 4493 | ArrayList<ComponentCallbacks2> collectComponentCallbacks( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4494 | boolean allActivities, Configuration newConfig) { |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 4495 | ArrayList<ComponentCallbacks2> callbacks |
| 4496 | = new ArrayList<ComponentCallbacks2>(); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4497 | |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4498 | synchronized (mResourcesManager) { |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 4499 | final int NAPP = mAllApplications.size(); |
| 4500 | for (int i=0; i<NAPP; i++) { |
Dianne Hackborn | 73c1416 | 2012-09-19 15:45:06 -0700 | [diff] [blame] | 4501 | callbacks.add(mAllApplications.get(i)); |
| 4502 | } |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 4503 | final int NACT = mActivities.size(); |
| 4504 | for (int i=0; i<NACT; i++) { |
| 4505 | ActivityClientRecord ar = mActivities.valueAt(i); |
| 4506 | Activity a = ar.activity; |
| 4507 | if (a != null) { |
| 4508 | Configuration thisConfig = applyConfigCompatMainThread( |
| 4509 | mCurDefaultDisplayDpi, newConfig, |
| 4510 | ar.packageInfo.getCompatibilityInfo()); |
| 4511 | if (!ar.activity.mFinished && (allActivities || !ar.paused)) { |
| 4512 | // If the activity is currently resumed, its configuration |
| 4513 | // needs to change right now. |
| 4514 | callbacks.add(a); |
| 4515 | } else if (thisConfig != null) { |
| 4516 | // Otherwise, we will tell it about the change |
| 4517 | // the next time it is resumed or shown. Note that |
| 4518 | // the activity manager may, before then, decide the |
| 4519 | // activity needs to be destroyed to handle its new |
| 4520 | // configuration. |
| 4521 | if (DEBUG_CONFIGURATION) { |
| 4522 | Slog.v(TAG, "Setting activity " |
| 4523 | + ar.activityInfo.name + " newConfig=" + thisConfig); |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 4524 | } |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 4525 | ar.newConfig = thisConfig; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4526 | } |
| 4527 | } |
| 4528 | } |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 4529 | final int NSVC = mServices.size(); |
| 4530 | for (int i=0; i<NSVC; i++) { |
| 4531 | callbacks.add(mServices.valueAt(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4532 | } |
| 4533 | } |
| 4534 | synchronized (mProviderMap) { |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 4535 | final int NPRV = mLocalProviders.size(); |
| 4536 | for (int i=0; i<NPRV; i++) { |
| 4537 | callbacks.add(mLocalProviders.valueAt(i).mLocalProvider); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4538 | } |
| 4539 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4540 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4541 | return callbacks; |
| 4542 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4543 | |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 4544 | /** |
| 4545 | * Updates the configuration for an Activity. The ActivityClientRecord's |
| 4546 | * {@link ActivityClientRecord#overrideConfig} is used to compute the final Configuration for |
| 4547 | * that Activity. {@link ActivityClientRecord#tmpConfig} is used as a temporary for delivering |
| 4548 | * the updated Configuration. |
| 4549 | * @param r ActivityClientRecord representing the Activity. |
| 4550 | * @param newBaseConfig The new configuration to use. This may be augmented with |
| 4551 | * {@link ActivityClientRecord#overrideConfig}. |
| 4552 | * @param reportToActivity true if the change should be reported to the Activity's callback. |
| 4553 | */ |
| 4554 | private void performConfigurationChangedForActivity(ActivityClientRecord r, |
| 4555 | Configuration newBaseConfig, |
| 4556 | boolean reportToActivity) { |
| 4557 | r.tmpConfig.setTo(newBaseConfig); |
| 4558 | if (r.overrideConfig != null) { |
| 4559 | r.tmpConfig.updateFrom(r.overrideConfig); |
| 4560 | } |
| 4561 | performConfigurationChanged(r.activity, r.token, r.tmpConfig, r.overrideConfig, |
| 4562 | reportToActivity); |
| 4563 | freeTextLayoutCachesIfNeeded(r.activity.mCurrentConfig.diff(r.tmpConfig)); |
| 4564 | } |
| 4565 | |
| 4566 | /** |
| 4567 | * Decides whether to update an Activity's configuration and whether to tell the |
| 4568 | * Activity/Component about it. |
| 4569 | * @param cb The component callback to notify of configuration change. |
| 4570 | * @param activityToken The Activity binder token for which this configuration change happened. |
| 4571 | * If the change is global, this is null. |
| 4572 | * @param newConfig The new configuration. |
| 4573 | * @param overrideConfig The override config that differentiates the Activity's configuration |
| 4574 | * from the base global configuration. |
| 4575 | * @param reportToActivity Notify the Activity of the change. |
| 4576 | */ |
| 4577 | private void performConfigurationChanged(ComponentCallbacks2 cb, |
| 4578 | IBinder activityToken, |
| 4579 | Configuration newConfig, |
| 4580 | Configuration overrideConfig, |
| 4581 | boolean reportToActivity) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4582 | // Only for Activity objects, check that they actually call up to their |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 4583 | // superclass implementation. ComponentCallbacks2 is an interface, so |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4584 | // we check the runtime type and act accordingly. |
| 4585 | Activity activity = (cb instanceof Activity) ? (Activity) cb : null; |
| 4586 | if (activity != null) { |
| 4587 | activity.mCalled = false; |
| 4588 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4589 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4590 | boolean shouldChangeConfig = false; |
| 4591 | if ((activity == null) || (activity.mCurrentConfig == null)) { |
| 4592 | shouldChangeConfig = true; |
| 4593 | } else { |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4594 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4595 | // If the new config is the same as the config this Activity |
| 4596 | // is already running with then don't bother calling |
| 4597 | // onConfigurationChanged |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 4598 | int diff = activity.mCurrentConfig.diff(newConfig); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4599 | if (diff != 0) { |
Jorim Jaggi | 1793d47 | 2016-04-27 20:59:40 -0700 | [diff] [blame] | 4600 | shouldChangeConfig = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4601 | } |
| 4602 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4603 | |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 4604 | if (DEBUG_CONFIGURATION) { |
| 4605 | Slog.v(TAG, "Config callback " + cb + ": shouldChangeConfig=" + shouldChangeConfig); |
| 4606 | } |
| 4607 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4608 | if (shouldChangeConfig) { |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 4609 | if (activityToken != null) { |
| 4610 | // We only update an Activity's configuration if this is not a global |
| 4611 | // configuration change. This must also be done before the callback, |
| 4612 | // or else we violate the contract that the new resources are available |
| 4613 | // in {@link ComponentCallbacks2#onConfigurationChanged(Configuration)}. |
| 4614 | mResourcesManager.updateResourcesForActivity(activityToken, overrideConfig); |
| 4615 | } |
| 4616 | |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 4617 | if (reportToActivity) { |
Adam Lesinski | 3ad1b48 | 2016-04-01 16:41:41 -0700 | [diff] [blame] | 4618 | Configuration configToReport = newConfig; |
| 4619 | |
| 4620 | if (cb instanceof ContextThemeWrapper) { |
| 4621 | // ContextThemeWrappers may override the configuration for that context. |
| 4622 | // We must check and apply any overrides defined. |
| 4623 | ContextThemeWrapper contextThemeWrapper = (ContextThemeWrapper) cb; |
| 4624 | final Configuration localOverrideConfig = |
| 4625 | contextThemeWrapper.getOverrideConfiguration(); |
| 4626 | if (localOverrideConfig != null) { |
| 4627 | configToReport = new Configuration(newConfig); |
| 4628 | configToReport.updateFrom(localOverrideConfig); |
| 4629 | } |
| 4630 | } |
| 4631 | |
| 4632 | cb.onConfigurationChanged(configToReport); |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 4633 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4634 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4635 | if (activity != null) { |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 4636 | if (reportToActivity && !activity.mCalled) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4637 | throw new SuperNotCalledException( |
| 4638 | "Activity " + activity.getLocalClassName() + |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 4639 | " did not call through to super.onConfigurationChanged()"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4640 | } |
| 4641 | activity.mConfigChangeFlags = 0; |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 4642 | activity.mCurrentConfig = new Configuration(newConfig); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4643 | } |
| 4644 | } |
| 4645 | } |
| 4646 | |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 4647 | public final void applyConfigurationToResources(Configuration config) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4648 | synchronized (mResourcesManager) { |
| 4649 | mResourcesManager.applyConfigurationToResourcesLocked(config, null); |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 4650 | } |
| 4651 | } |
| 4652 | |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 4653 | final Configuration applyCompatConfiguration(int displayDensity) { |
Dianne Hackborn | 836e262 | 2011-10-04 18:32:39 -0700 | [diff] [blame] | 4654 | Configuration config = mConfiguration; |
| 4655 | if (mCompatConfiguration == null) { |
| 4656 | mCompatConfiguration = new Configuration(); |
| 4657 | } |
| 4658 | mCompatConfiguration.setTo(mConfiguration); |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 4659 | if (mResourcesManager.applyCompatConfigurationLocked(displayDensity, |
| 4660 | mCompatConfiguration)) { |
Dianne Hackborn | 836e262 | 2011-10-04 18:32:39 -0700 | [diff] [blame] | 4661 | config = mCompatConfiguration; |
| 4662 | } |
| 4663 | return config; |
| 4664 | } |
| 4665 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4666 | final void handleConfigurationChanged(Configuration config, CompatibilityInfo compat) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4667 | |
Fabrice Di Meglio | 30ca5cd | 2012-05-07 17:45:44 -0700 | [diff] [blame] | 4668 | int configDiff = 0; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4669 | |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4670 | synchronized (mResourcesManager) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4671 | if (mPendingConfiguration != null) { |
| 4672 | if (!mPendingConfiguration.isOtherSeqNewer(config)) { |
| 4673 | config = mPendingConfiguration; |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 4674 | mCurDefaultDisplayDpi = config.densityDpi; |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 4675 | updateDefaultDensity(); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4676 | } |
| 4677 | mPendingConfiguration = null; |
| 4678 | } |
| 4679 | |
| 4680 | if (config == null) { |
| 4681 | return; |
| 4682 | } |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 4683 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4684 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Handle configuration changed: " |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4685 | + config); |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4686 | |
| 4687 | mResourcesManager.applyConfigurationToResourcesLocked(config, compat); |
| 4688 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4689 | if (mConfiguration == null) { |
| 4690 | mConfiguration = new Configuration(); |
| 4691 | } |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4692 | if (!mConfiguration.isOtherSeqNewer(config) && compat == null) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4693 | return; |
| 4694 | } |
Alan Viverette | e54d245 | 2015-05-06 10:41:43 -0700 | [diff] [blame] | 4695 | |
| 4696 | configDiff = mConfiguration.updateFrom(config); |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 4697 | config = applyCompatConfiguration(mCurDefaultDisplayDpi); |
Alan Viverette | 395cd01 | 2015-08-11 17:27:04 -0400 | [diff] [blame] | 4698 | |
| 4699 | final Theme systemTheme = getSystemContext().getTheme(); |
| 4700 | if ((systemTheme.getChangingConfigurations() & configDiff) != 0) { |
| 4701 | systemTheme.rebase(); |
| 4702 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4703 | } |
Dianne Hackborn | 73c1416 | 2012-09-19 15:45:06 -0700 | [diff] [blame] | 4704 | |
| 4705 | ArrayList<ComponentCallbacks2> callbacks = collectComponentCallbacks(false, config); |
| 4706 | |
Fabrice Di Meglio | 30ca5cd | 2012-05-07 17:45:44 -0700 | [diff] [blame] | 4707 | freeTextLayoutCachesIfNeeded(configDiff); |
| 4708 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4709 | if (callbacks != null) { |
| 4710 | final int N = callbacks.size(); |
| 4711 | for (int i=0; i<N; i++) { |
Andrii Kulian | 701214b | 2016-04-07 09:36:33 -0700 | [diff] [blame] | 4712 | ComponentCallbacks2 cb = callbacks.get(i); |
| 4713 | if (cb instanceof Activity) { |
| 4714 | // If callback is an Activity - call corresponding method to consider override |
| 4715 | // config and avoid onConfigurationChanged if it hasn't changed. |
| 4716 | Activity a = (Activity) cb; |
| 4717 | performConfigurationChangedForActivity(mActivities.get(a.getActivityToken()), |
| 4718 | config, REPORT_TO_ACTIVITY); |
| 4719 | } else { |
| 4720 | performConfigurationChanged(cb, null, config, null, REPORT_TO_ACTIVITY); |
| 4721 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4722 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4723 | } |
| 4724 | } |
| 4725 | |
Romain Guy | 46bfc48 | 2013-08-16 18:38:29 -0700 | [diff] [blame] | 4726 | static void freeTextLayoutCachesIfNeeded(int configDiff) { |
Fabrice Di Meglio | 30ca5cd | 2012-05-07 17:45:44 -0700 | [diff] [blame] | 4727 | if (configDiff != 0) { |
| 4728 | // Ask text layout engine to free its caches if there is a locale change |
| 4729 | boolean hasLocaleConfigChange = ((configDiff & ActivityInfo.CONFIG_LOCALE) != 0); |
| 4730 | if (hasLocaleConfigChange) { |
| 4731 | Canvas.freeTextLayoutCaches(); |
| 4732 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Cleared TextLayout Caches"); |
| 4733 | } |
| 4734 | } |
| 4735 | } |
| 4736 | |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 4737 | final void handleActivityConfigurationChanged(ActivityConfigChangeData data, |
| 4738 | boolean reportToActivity) { |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 4739 | ActivityClientRecord r = mActivities.get(data.activityToken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4740 | if (r == null || r.activity == null) { |
| 4741 | return; |
| 4742 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4743 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4744 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Handle activity config changed: " |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 4745 | + r.activityInfo.name + ", with callback=" + reportToActivity); |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 4746 | |
Adam Lesinski | 082614c | 2016-03-04 14:33:47 -0800 | [diff] [blame] | 4747 | r.overrideConfig = data.overrideConfig; |
| 4748 | performConfigurationChangedForActivity(r, mCompatConfiguration, reportToActivity); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4749 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4750 | } |
| 4751 | |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 4752 | final void handleProfilerControl(boolean start, ProfilerInfo profilerInfo, int profileType) { |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 4753 | if (start) { |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 4754 | try { |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 4755 | switch (profileType) { |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 4756 | default: |
| 4757 | mProfiler.setProfiler(profilerInfo); |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 4758 | mProfiler.startProfiling(); |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 4759 | break; |
| 4760 | } |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 4761 | } catch (RuntimeException e) { |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 4762 | Slog.w(TAG, "Profiling failed on path " + profilerInfo.profileFile |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 4763 | + " -- can the process access this path?"); |
Dianne Hackborn | 9c8dd55 | 2009-06-23 19:22:52 -0700 | [diff] [blame] | 4764 | } finally { |
| 4765 | try { |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 4766 | profilerInfo.profileFd.close(); |
Dianne Hackborn | 9c8dd55 | 2009-06-23 19:22:52 -0700 | [diff] [blame] | 4767 | } catch (IOException e) { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 4768 | Slog.w(TAG, "Failure closing profile fd", e); |
Dianne Hackborn | 9c8dd55 | 2009-06-23 19:22:52 -0700 | [diff] [blame] | 4769 | } |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 4770 | } |
| 4771 | } else { |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 4772 | switch (profileType) { |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 4773 | default: |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 4774 | mProfiler.stopProfiling(); |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 4775 | break; |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 4776 | } |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 4777 | } |
| 4778 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4779 | |
Andreas Gampe | 4c79fea | 2016-01-28 20:11:41 -0800 | [diff] [blame] | 4780 | /** |
| 4781 | * Public entrypoint to stop profiling. This is required to end profiling when the app crashes, |
| 4782 | * so that profiler data won't be lost. |
| 4783 | * |
| 4784 | * @hide |
| 4785 | */ |
| 4786 | public void stopProfiling() { |
| 4787 | mProfiler.stopProfiling(); |
| 4788 | } |
| 4789 | |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 4790 | static final void handleDumpHeap(boolean managed, DumpHeapData dhd) { |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 4791 | if (managed) { |
| 4792 | try { |
| 4793 | Debug.dumpHprofData(dhd.path, dhd.fd.getFileDescriptor()); |
| 4794 | } catch (IOException e) { |
| 4795 | Slog.w(TAG, "Managed heap dump failed on path " + dhd.path |
| 4796 | + " -- can the process access this path?"); |
| 4797 | } finally { |
| 4798 | try { |
| 4799 | dhd.fd.close(); |
| 4800 | } catch (IOException e) { |
| 4801 | Slog.w(TAG, "Failure closing profile fd", e); |
| 4802 | } |
| 4803 | } |
| 4804 | } else { |
Andy McFadden | 06a6b55 | 2010-07-13 16:28:09 -0700 | [diff] [blame] | 4805 | Debug.dumpNativeHeap(dhd.fd.getFileDescriptor()); |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 4806 | } |
Dianne Hackborn | b9a5e4a | 2015-03-03 17:04:12 -0800 | [diff] [blame] | 4807 | try { |
| 4808 | ActivityManagerNative.getDefault().dumpHeapFinished(dhd.path); |
| 4809 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4810 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | b9a5e4a | 2015-03-03 17:04:12 -0800 | [diff] [blame] | 4811 | } |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 4812 | } |
| 4813 | |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 4814 | final void handleDispatchPackageBroadcast(int cmd, String[] packages) { |
| 4815 | boolean hasPkgInfo = false; |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 4816 | switch (cmd) { |
| 4817 | case IApplicationThread.PACKAGE_REMOVED: |
| 4818 | case IApplicationThread.PACKAGE_REMOVED_DONT_KILL: |
| 4819 | { |
| 4820 | final boolean killApp = cmd == IApplicationThread.PACKAGE_REMOVED; |
| 4821 | if (packages == null) { |
| 4822 | break; |
| 4823 | } |
| 4824 | synchronized (mResourcesManager) { |
| 4825 | for (int i = packages.length - 1; i >= 0; i--) { |
| 4826 | if (!hasPkgInfo) { |
| 4827 | WeakReference<LoadedApk> ref = mPackages.get(packages[i]); |
| 4828 | if (ref != null && ref.get() != null) { |
| 4829 | hasPkgInfo = true; |
| 4830 | } else { |
| 4831 | ref = mResourcePackages.get(packages[i]); |
| 4832 | if (ref != null && ref.get() != null) { |
| 4833 | hasPkgInfo = true; |
| 4834 | } |
| 4835 | } |
| 4836 | } |
| 4837 | if (killApp) { |
| 4838 | mPackages.remove(packages[i]); |
| 4839 | mResourcePackages.remove(packages[i]); |
| 4840 | } |
| 4841 | } |
| 4842 | } |
| 4843 | break; |
| 4844 | } |
| 4845 | case IApplicationThread.PACKAGE_REPLACED: |
| 4846 | { |
| 4847 | if (packages == null) { |
| 4848 | break; |
| 4849 | } |
| 4850 | synchronized (mResourcesManager) { |
| 4851 | for (int i = packages.length - 1; i >= 0; i--) { |
| 4852 | WeakReference<LoadedApk> ref = mPackages.get(packages[i]); |
| 4853 | LoadedApk pkgInfo = ref != null ? ref.get() : null; |
| 4854 | if (pkgInfo != null) { |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 4855 | hasPkgInfo = true; |
mark_chen | 89764e3 | 2014-12-12 15:38:48 +0800 | [diff] [blame] | 4856 | } else { |
| 4857 | ref = mResourcePackages.get(packages[i]); |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 4858 | pkgInfo = ref != null ? ref.get() : null; |
| 4859 | if (pkgInfo != null) { |
mark_chen | 89764e3 | 2014-12-12 15:38:48 +0800 | [diff] [blame] | 4860 | hasPkgInfo = true; |
| 4861 | } |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 4862 | } |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 4863 | // If the package is being replaced, yet it still has a valid |
| 4864 | // LoadedApk object, the package was updated with _DONT_KILL. |
| 4865 | // Adjust it's internal references to the application info and |
| 4866 | // resources. |
| 4867 | if (pkgInfo != null) { |
| 4868 | try { |
| 4869 | final String packageName = packages[i]; |
| 4870 | final ApplicationInfo aInfo = |
| 4871 | sPackageManager.getApplicationInfo( |
| 4872 | packageName, |
| 4873 | 0 /*flags*/, |
| 4874 | UserHandle.myUserId()); |
| 4875 | |
| 4876 | if (mActivities.size() > 0) { |
| 4877 | for (ActivityClientRecord ar : mActivities.values()) { |
| 4878 | if (ar.activityInfo.applicationInfo.packageName |
| 4879 | .equals(packageName)) { |
| 4880 | ar.activityInfo.applicationInfo = aInfo; |
| 4881 | ar.packageInfo = pkgInfo; |
| 4882 | } |
| 4883 | } |
| 4884 | } |
| 4885 | final List<String> oldPaths = |
| 4886 | sPackageManager.getPreviousCodePaths(packageName); |
| 4887 | pkgInfo.updateApplicationInfo(aInfo, oldPaths); |
| 4888 | } catch (RemoteException e) { |
| 4889 | } |
| 4890 | } |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 4891 | } |
| 4892 | } |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 4893 | break; |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 4894 | } |
| 4895 | } |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 4896 | ApplicationPackageManager.handlePackageBroadcast(cmd, packages, hasPkgInfo); |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 4897 | } |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 4898 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4899 | final void handleLowMemory() { |
Dianne Hackborn | 73c1416 | 2012-09-19 15:45:06 -0700 | [diff] [blame] | 4900 | ArrayList<ComponentCallbacks2> callbacks = collectComponentCallbacks(true, null); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4901 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4902 | final int N = callbacks.size(); |
| 4903 | for (int i=0; i<N; i++) { |
| 4904 | callbacks.get(i).onLowMemory(); |
| 4905 | } |
| 4906 | |
Chris Tate | ce22905 | 2009-03-25 16:44:52 -0700 | [diff] [blame] | 4907 | // Ask SQLite to free up as much memory as it can, mostly from its page caches. |
| 4908 | if (Process.myUid() != Process.SYSTEM_UID) { |
| 4909 | int sqliteReleased = SQLiteDatabase.releaseMemory(); |
| 4910 | EventLog.writeEvent(SQLITE_MEM_RELEASED_EVENT_LOG_TAG, sqliteReleased); |
| 4911 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4912 | |
Mike Reed | caf0df1 | 2009-04-27 14:32:05 -0400 | [diff] [blame] | 4913 | // Ask graphics to free up as much as possible (font/image caches) |
| 4914 | Canvas.freeCaches(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4915 | |
Fabrice Di Meglio | 30ca5cd | 2012-05-07 17:45:44 -0700 | [diff] [blame] | 4916 | // Ask text layout engine to free also as much as possible |
| 4917 | Canvas.freeTextLayoutCaches(); |
| 4918 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4919 | BinderInternal.forceGc("mem"); |
| 4920 | } |
| 4921 | |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 4922 | final void handleTrimMemory(int level) { |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 4923 | if (DEBUG_MEMORY_TRIM) Slog.v(TAG, "Trimming memory to level: " + level); |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 4924 | |
Dianne Hackborn | 73c1416 | 2012-09-19 15:45:06 -0700 | [diff] [blame] | 4925 | ArrayList<ComponentCallbacks2> callbacks = collectComponentCallbacks(true, null); |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 4926 | |
| 4927 | final int N = callbacks.size(); |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 4928 | for (int i = 0; i < N; i++) { |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 4929 | callbacks.get(i).onTrimMemory(level); |
| 4930 | } |
Romain Guy | 19f86e8 | 2012-04-23 15:19:07 -0700 | [diff] [blame] | 4931 | |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 4932 | WindowManagerGlobal.getInstance().trimMemory(level); |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 4933 | } |
| 4934 | |
Jeff Sharkey | e1d330a | 2012-05-02 13:46:21 -0700 | [diff] [blame] | 4935 | private void setupGraphicsSupport(LoadedApk info, File cacheDir) { |
Dianne Hackborn | a0c283e | 2012-02-09 10:47:01 -0800 | [diff] [blame] | 4936 | if (Process.isIsolated()) { |
| 4937 | // Isolated processes aren't going to do UI. |
| 4938 | return; |
| 4939 | } |
Romain Guy | a958265 | 2011-11-10 14:20:10 -0800 | [diff] [blame] | 4940 | try { |
| 4941 | int uid = Process.myUid(); |
| 4942 | String[] packages = getPackageManager().getPackagesForUid(uid); |
| 4943 | |
Shuo Gao | 7c69a66 | 2016-03-01 13:32:03 +0800 | [diff] [blame] | 4944 | if (packages != null) { |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 4945 | ThreadedRenderer.setupDiskCache(cacheDir); |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 4946 | RenderScriptCacheDir.setupDiskCache(cacheDir); |
Romain Guy | a958265 | 2011-11-10 14:20:10 -0800 | [diff] [blame] | 4947 | } |
| 4948 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4949 | throw e.rethrowFromSystemServer(); |
Romain Guy | a958265 | 2011-11-10 14:20:10 -0800 | [diff] [blame] | 4950 | } |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 4951 | } |
| 4952 | |
| 4953 | private void updateDefaultDensity() { |
Alan Viverette | 2ac46f1 | 2016-02-04 16:58:14 -0500 | [diff] [blame] | 4954 | final int densityDpi = mCurDefaultDisplayDpi; |
| 4955 | if (!mDensityCompatMode |
| 4956 | && densityDpi != Configuration.DENSITY_DPI_UNDEFINED |
| 4957 | && densityDpi != DisplayMetrics.DENSITY_DEVICE) { |
| 4958 | DisplayMetrics.DENSITY_DEVICE = densityDpi; |
| 4959 | Bitmap.setDefaultDensity(densityDpi); |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 4960 | } |
| 4961 | } |
| 4962 | |
Todd Kennedy | e713efc | 2016-05-10 13:45:40 -0700 | [diff] [blame] | 4963 | /** |
| 4964 | * Returns the correct library directory for the current ABI. |
| 4965 | * <p> |
| 4966 | * If we're dealing with a multi-arch application that has both 32 and 64 bit shared |
| 4967 | * libraries, we might need to choose the secondary depending on what the current |
| 4968 | * runtime's instruction set is. |
| 4969 | */ |
| 4970 | private String getInstrumentationLibrary(ApplicationInfo appInfo, InstrumentationInfo insInfo) { |
| 4971 | if (appInfo.primaryCpuAbi != null && appInfo.secondaryCpuAbi != null) { |
| 4972 | // Get the instruction set supported by the secondary ABI. In the presence |
| 4973 | // of a native bridge this might be different than the one secondary ABI used. |
| 4974 | String secondaryIsa = |
| 4975 | VMRuntime.getInstructionSet(appInfo.secondaryCpuAbi); |
| 4976 | final String secondaryDexCodeIsa = |
| 4977 | SystemProperties.get("ro.dalvik.vm.isa." + secondaryIsa); |
| 4978 | secondaryIsa = secondaryDexCodeIsa.isEmpty() ? secondaryIsa : secondaryDexCodeIsa; |
| 4979 | |
| 4980 | final String runtimeIsa = VMRuntime.getRuntime().vmInstructionSet(); |
| 4981 | if (runtimeIsa.equals(secondaryIsa)) { |
| 4982 | return insInfo.secondaryNativeLibraryDir; |
| 4983 | } |
| 4984 | } |
| 4985 | return insInfo.nativeLibraryDir; |
| 4986 | } |
| 4987 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 4988 | private void handleBindApplication(AppBindData data) { |
Calin Juravle | 8f5770d | 2016-04-12 14:12:04 +0100 | [diff] [blame] | 4989 | // Register the UI Thread as a sensitive thread to the runtime. |
| 4990 | VMRuntime.registerSensitiveThread(); |
Man Cao | cfa78b2 | 2015-06-11 20:14:34 -0700 | [diff] [blame] | 4991 | if (data.trackAllocation) { |
| 4992 | DdmVmInternal.enableRecentAllocations(true); |
| 4993 | } |
| 4994 | |
Dianne Hackborn | d98885c | 2016-03-01 17:13:03 -0800 | [diff] [blame] | 4995 | // Note when this process has started. |
| 4996 | Process.setStartTimes(SystemClock.elapsedRealtime(), SystemClock.uptimeMillis()); |
| 4997 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4998 | mBoundApplication = data; |
| 4999 | mConfiguration = new Configuration(data.config); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 5000 | mCompatConfiguration = new Configuration(data.config); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5001 | |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 5002 | mProfiler = new Profiler(); |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 5003 | if (data.initProfilerInfo != null) { |
| 5004 | mProfiler.profileFile = data.initProfilerInfo.profileFile; |
| 5005 | mProfiler.profileFd = data.initProfilerInfo.profileFd; |
| 5006 | mProfiler.samplingInterval = data.initProfilerInfo.samplingInterval; |
| 5007 | mProfiler.autoStopProfiler = data.initProfilerInfo.autoStopProfiler; |
| 5008 | } |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 5009 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5010 | // send up app name; do this *before* waiting for debugger |
Christopher Tate | 8ee038d | 2009-11-06 11:30:20 -0800 | [diff] [blame] | 5011 | Process.setArgV0(data.processName); |
Siva Velusamy | d693dfa | 2012-09-10 14:36:58 -0700 | [diff] [blame] | 5012 | android.ddm.DdmHandleAppName.setAppName(data.processName, |
| 5013 | UserHandle.myUserId()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5014 | |
Dianne Hackborn | 5d927c2 | 2011-09-02 12:22:18 -0700 | [diff] [blame] | 5015 | if (data.persistent) { |
| 5016 | // Persistent processes on low-memory devices do not get to |
| 5017 | // use hardware accelerated drawing, since this can add too much |
| 5018 | // overhead to the process. |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 5019 | if (!ActivityManager.isHighEndGfx()) { |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 5020 | ThreadedRenderer.disable(false); |
Dianne Hackborn | 5d927c2 | 2011-09-02 12:22:18 -0700 | [diff] [blame] | 5021 | } |
| 5022 | } |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 5023 | |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 5024 | if (mProfiler.profileFd != null) { |
| 5025 | mProfiler.startProfiling(); |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 5026 | } |
| 5027 | |
Joe Onorato | d630f10 | 2011-03-17 18:42:26 -0700 | [diff] [blame] | 5028 | // If the app is Honeycomb MR1 or earlier, switch its AsyncTask |
| 5029 | // implementation to use the pool executor. Normally, we use the |
| 5030 | // serialized executor as the default. This has to happen in the |
| 5031 | // main thread so the main looper is set right. |
Dianne Hackborn | 81e9276 | 2011-10-09 16:00:21 -0700 | [diff] [blame] | 5032 | if (data.appInfo.targetSdkVersion <= android.os.Build.VERSION_CODES.HONEYCOMB_MR1) { |
Joe Onorato | d630f10 | 2011-03-17 18:42:26 -0700 | [diff] [blame] | 5033 | AsyncTask.setDefaultExecutor(AsyncTask.THREAD_POOL_EXECUTOR); |
| 5034 | } |
| 5035 | |
Dianne Hackborn | 7895bc2 | 2014-09-05 15:09:03 -0700 | [diff] [blame] | 5036 | Message.updateCheckRecycle(data.appInfo.targetSdkVersion); |
| 5037 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5038 | /* |
| 5039 | * Before spawning a new process, reset the time zone to be the system time zone. |
| 5040 | * This needs to be done because the system time zone could have changed after the |
| 5041 | * the spawning of this process. Without doing this this process would have the incorrect |
| 5042 | * system time zone. |
| 5043 | */ |
| 5044 | TimeZone.setDefault(null); |
| 5045 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 5046 | data.info = getPackageInfoNoCheck(data.appInfo, data.compatInfo); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5047 | |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 5048 | /** |
| 5049 | * Switch this process to density compatibility mode if needed. |
| 5050 | */ |
| 5051 | if ((data.appInfo.flags&ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES) |
| 5052 | == 0) { |
| 5053 | mDensityCompatMode = true; |
| 5054 | Bitmap.setDefaultDensity(DisplayMetrics.DENSITY_DEFAULT); |
| 5055 | } |
| 5056 | updateDefaultDensity(); |
| 5057 | |
Narayan Kamath | ccb2a086 | 2013-12-19 14:49:36 +0000 | [diff] [blame] | 5058 | final boolean is24Hr = "24".equals(mCoreSettings.getString(Settings.System.TIME_12_24)); |
| 5059 | DateFormat.set24HourTimePref(is24Hr); |
| 5060 | |
Jon Miranda | 836c0a8 | 2014-08-11 12:32:26 -0700 | [diff] [blame] | 5061 | View.mDebugViewAttributes = |
| 5062 | mCoreSettings.getInt(Settings.Global.DEBUG_VIEW_ATTRIBUTES, 0) != 0; |
| 5063 | |
Dianne Hackborn | 96e240f | 2009-07-26 17:42:30 -0700 | [diff] [blame] | 5064 | /** |
Brad Fitzpatrick | 438d059 | 2010-06-10 12:19:19 -0700 | [diff] [blame] | 5065 | * For system applications on userdebug/eng builds, log stack |
| 5066 | * traces of disk and network access to dropbox for analysis. |
| 5067 | */ |
Brad Fitzpatrick | ad13b98 | 2010-07-14 12:35:53 -0700 | [diff] [blame] | 5068 | if ((data.appInfo.flags & |
| 5069 | (ApplicationInfo.FLAG_SYSTEM | |
Brad Fitzpatrick | 50d66f9 | 2010-09-13 21:29:05 -0700 | [diff] [blame] | 5070 | ApplicationInfo.FLAG_UPDATED_SYSTEM_APP)) != 0) { |
| 5071 | StrictMode.conditionallyEnableDebugLogging(); |
Brad Fitzpatrick | 438d059 | 2010-06-10 12:19:19 -0700 | [diff] [blame] | 5072 | } |
| 5073 | |
| 5074 | /** |
Jeff Sharkey | 344744b | 2016-01-28 19:03:30 -0700 | [diff] [blame] | 5075 | * For apps targetting Honeycomb or later, we don't allow network usage |
| 5076 | * on the main event loop / UI thread. This is what ultimately throws |
| 5077 | * {@link NetworkOnMainThreadException}. |
Brad Fitzpatrick | b6e1841 | 2010-10-28 14:50:05 -0700 | [diff] [blame] | 5078 | */ |
Jeff Sharkey | 344744b | 2016-01-28 19:03:30 -0700 | [diff] [blame] | 5079 | if (data.appInfo.targetSdkVersion >= Build.VERSION_CODES.HONEYCOMB) { |
Brad Fitzpatrick | b6e1841 | 2010-10-28 14:50:05 -0700 | [diff] [blame] | 5080 | StrictMode.enableDeathOnNetwork(); |
| 5081 | } |
| 5082 | |
Jeff Sharkey | 344744b | 2016-01-28 19:03:30 -0700 | [diff] [blame] | 5083 | /** |
| 5084 | * For apps targetting N or later, we don't allow file:// Uri exposure. |
| 5085 | * This is what ultimately throws {@link FileUriExposedException}. |
| 5086 | */ |
| 5087 | if (data.appInfo.targetSdkVersion >= Build.VERSION_CODES.N) { |
Thierry Strudel | e60b28d | 2016-02-25 02:14:16 +0000 | [diff] [blame] | 5088 | StrictMode.enableDeathOnFileUriExposure(); |
Jeff Sharkey | 344744b | 2016-01-28 19:03:30 -0700 | [diff] [blame] | 5089 | } |
| 5090 | |
Alex Klyubin | f9034cc | 2015-02-12 11:43:09 -0800 | [diff] [blame] | 5091 | NetworkSecurityPolicy.getInstance().setCleartextTrafficPermitted( |
| 5092 | (data.appInfo.flags & ApplicationInfo.FLAG_USES_CLEARTEXT_TRAFFIC) != 0); |
| 5093 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5094 | if (data.debugMode != IApplicationThread.DEBUG_OFF) { |
| 5095 | // XXX should have option to change the port. |
| 5096 | Debug.changeDebugPort(8100); |
| 5097 | if (data.debugMode == IApplicationThread.DEBUG_WAIT) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 5098 | Slog.w(TAG, "Application " + data.info.getPackageName() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5099 | + " is waiting for the debugger on port 8100..."); |
| 5100 | |
| 5101 | IActivityManager mgr = ActivityManagerNative.getDefault(); |
| 5102 | try { |
| 5103 | mgr.showWaitingForDebugger(mAppThread, true); |
| 5104 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5105 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5106 | } |
| 5107 | |
| 5108 | Debug.waitForDebugger(); |
| 5109 | |
| 5110 | try { |
| 5111 | mgr.showWaitingForDebugger(mAppThread, false); |
| 5112 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5113 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5114 | } |
| 5115 | |
| 5116 | } else { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 5117 | Slog.w(TAG, "Application " + data.info.getPackageName() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5118 | + " can be debugged on port 8100..."); |
| 5119 | } |
| 5120 | } |
| 5121 | |
Jamie Gennis | f9c7d6b | 2013-03-25 14:18:25 -0700 | [diff] [blame] | 5122 | // Allow application-generated systrace messages if we're debuggable. |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 5123 | boolean isAppDebuggable = (data.appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0; |
| 5124 | Trace.setAppTracingAllowed(isAppDebuggable); |
| 5125 | if (isAppDebuggable && data.enableBinderTracking) { |
| 5126 | Binder.enableTracing(); |
| 5127 | } |
Jamie Gennis | f9c7d6b | 2013-03-25 14:18:25 -0700 | [diff] [blame] | 5128 | |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 5129 | /** |
| 5130 | * Initialize the default http proxy in this process for the reasons we set the time zone. |
| 5131 | */ |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 5132 | final IBinder b = ServiceManager.getService(Context.CONNECTIVITY_SERVICE); |
Dianne Hackborn | d4d32c5 | 2011-11-08 17:33:59 -0800 | [diff] [blame] | 5133 | if (b != null) { |
| 5134 | // In pre-boot mode (doing initial launch to collect password), not |
| 5135 | // all system is up. This includes the connectivity service, so don't |
| 5136 | // crash if we can't get it. |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 5137 | final IConnectivityManager service = IConnectivityManager.Stub.asInterface(b); |
Dianne Hackborn | d4d32c5 | 2011-11-08 17:33:59 -0800 | [diff] [blame] | 5138 | try { |
Paul Jensen | cee9b51 | 2015-05-06 07:32:40 -0400 | [diff] [blame] | 5139 | final ProxyInfo proxyInfo = service.getProxyForNetwork(null); |
Jason Monk | 207900c | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 5140 | Proxy.setHttpProxySystemProperty(proxyInfo); |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5141 | } catch (RemoteException e) { |
| 5142 | throw e.rethrowFromSystemServer(); |
| 5143 | } |
Dianne Hackborn | d4d32c5 | 2011-11-08 17:33:59 -0800 | [diff] [blame] | 5144 | } |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 5145 | |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 5146 | // Instrumentation info affects the class loader, so load it before |
| 5147 | // setting up the app context. |
| 5148 | final InstrumentationInfo ii; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5149 | if (data.instrumentationName != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5150 | try { |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 5151 | ii = new ApplicationPackageManager(null, getPackageManager()) |
| 5152 | .getInstrumentationInfo(data.instrumentationName, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5153 | } catch (PackageManager.NameNotFoundException e) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5154 | throw new RuntimeException( |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 5155 | "Unable to find instrumentation info for: " + data.instrumentationName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5156 | } |
| 5157 | |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 5158 | mInstrumentationPackageName = ii.packageName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5159 | mInstrumentationAppDir = ii.sourceDir; |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 5160 | mInstrumentationSplitAppDirs = ii.splitSourceDirs; |
Todd Kennedy | e713efc | 2016-05-10 13:45:40 -0700 | [diff] [blame] | 5161 | mInstrumentationLibDir = getInstrumentationLibrary(data.appInfo, ii); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5162 | mInstrumentedAppDir = data.info.getAppDir(); |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 5163 | mInstrumentedSplitAppDirs = data.info.getSplitAppDirs(); |
| 5164 | mInstrumentedLibDir = data.info.getLibDir(); |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 5165 | } else { |
| 5166 | ii = null; |
| 5167 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5168 | |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 5169 | final ContextImpl appContext = ContextImpl.createAppContext(this, data.info); |
Seigo Nonaka | c14dd78 | 2016-03-30 23:09:16 +0900 | [diff] [blame] | 5170 | synchronized (mResourcesManager) { |
| 5171 | /* |
| 5172 | * Initialize the default locales in this process for the reasons we set the time zone. |
| 5173 | * |
| 5174 | * We do this through ResourcesManager, since we need to do locale negotiation. |
| 5175 | */ |
| 5176 | mResourcesManager.setDefaultLocalesLocked(data.config.getLocales()); |
| 5177 | |
| 5178 | /* |
| 5179 | * Update the system configuration since its preloaded and might not |
| 5180 | * reflect configuration changes. The configuration object passed |
| 5181 | * in AppBindData can be safely assumed to be up to date |
| 5182 | */ |
| 5183 | mResourcesManager.applyConfigurationToResourcesLocked(data.config, data.compatInfo); |
| 5184 | mCurDefaultDisplayDpi = data.config.densityDpi; |
| 5185 | |
| 5186 | // This calls mResourcesManager so keep it within the synchronized block. |
| 5187 | applyCompatConfiguration(mCurDefaultDisplayDpi); |
| 5188 | } |
| 5189 | |
Jeff Sharkey | e6cb097 | 2016-02-01 09:59:12 -0700 | [diff] [blame] | 5190 | if (!Process.isIsolated() && !"android".equals(appContext.getPackageName())) { |
Jeff Sharkey | e84bdd3 | 2016-02-08 12:16:00 -0700 | [diff] [blame] | 5191 | // This cache location probably points at credential-encrypted |
| 5192 | // storage which may not be accessible yet; assign it anyway instead |
| 5193 | // of pointing at device-encrypted storage. |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 5194 | final File cacheDir = appContext.getCacheDir(); |
| 5195 | if (cacheDir != null) { |
| 5196 | // Provide a usable directory for temporary files |
| 5197 | System.setProperty("java.io.tmpdir", cacheDir.getAbsolutePath()); |
| 5198 | } else { |
| 5199 | Log.v(TAG, "Unable to initialize \"java.io.tmpdir\" property " |
| 5200 | + "due to missing cache directory"); |
| 5201 | } |
Alan Viverette | 346296b | 2015-09-01 13:08:05 -0400 | [diff] [blame] | 5202 | |
Calin Juravle | 2a727d7 | 2016-04-15 19:33:46 +0100 | [diff] [blame] | 5203 | // Setup a location to store generated/compiled graphics code. |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 5204 | final Context deviceContext = appContext.createDeviceProtectedStorageContext(); |
Jeff Sharkey | e84bdd3 | 2016-02-08 12:16:00 -0700 | [diff] [blame] | 5205 | final File codeCacheDir = deviceContext.getCodeCacheDir(); |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 5206 | if (codeCacheDir != null) { |
| 5207 | setupGraphicsSupport(data.info, codeCacheDir); |
| 5208 | } else { |
Calin Juravle | 2a727d7 | 2016-04-15 19:33:46 +0100 | [diff] [blame] | 5209 | Log.e(TAG, "Unable to setupGraphicsSupport due to missing code-cache directory"); |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 5210 | } |
Michael Lentine | 2ba303f | 2016-02-01 20:44:34 -0600 | [diff] [blame] | 5211 | } |
Michael Lentine | 03d8f768 | 2016-01-31 15:37:11 -0600 | [diff] [blame] | 5212 | |
Chad Brubaker | 78d4712 | 2015-11-17 22:26:58 -0800 | [diff] [blame] | 5213 | // Install the Network Security Config Provider. This must happen before the application |
| 5214 | // code is loaded to prevent issues with instances of TLS objects being created before |
| 5215 | // the provider is installed. |
| 5216 | NetworkSecurityConfigProvider.install(appContext); |
| 5217 | |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 5218 | // Continue loading instrumentation. |
| 5219 | if (ii != null) { |
Alan Viverette | 346296b | 2015-09-01 13:08:05 -0400 | [diff] [blame] | 5220 | final ApplicationInfo instrApp = new ApplicationInfo(); |
Jeff Sharkey | 1544779 | 2015-11-05 16:18:51 -0800 | [diff] [blame] | 5221 | ii.copyTo(instrApp); |
Fyodor Kupolov | af38b8e | 2015-12-02 16:16:07 -0800 | [diff] [blame] | 5222 | instrApp.initForUser(UserHandle.myUserId()); |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 5223 | final LoadedApk pi = getPackageInfo(instrApp, data.compatInfo, |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 5224 | appContext.getClassLoader(), false, true, false); |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 5225 | final ContextImpl instrContext = ContextImpl.createAppContext(this, pi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5226 | |
| 5227 | try { |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 5228 | final ClassLoader cl = instrContext.getClassLoader(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5229 | mInstrumentation = (Instrumentation) |
| 5230 | cl.loadClass(data.instrumentationName.getClassName()).newInstance(); |
| 5231 | } catch (Exception e) { |
| 5232 | throw new RuntimeException( |
| 5233 | "Unable to instantiate instrumentation " |
| 5234 | + data.instrumentationName + ": " + e.toString(), e); |
| 5235 | } |
| 5236 | |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 5237 | final ComponentName component = new ComponentName(ii.packageName, ii.name); |
| 5238 | mInstrumentation.init(this, instrContext, appContext, component, |
| 5239 | data.instrumentationWatcher, data.instrumentationUiAutomationConnection); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5240 | |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 5241 | if (mProfiler.profileFile != null && !ii.handleProfiling |
| 5242 | && mProfiler.profileFd == null) { |
| 5243 | mProfiler.handlingProfiling = true; |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 5244 | final File file = new File(mProfiler.profileFile); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5245 | file.getParentFile().mkdirs(); |
| 5246 | Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024); |
| 5247 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5248 | } else { |
| 5249 | mInstrumentation = new Instrumentation(); |
| 5250 | } |
| 5251 | |
Dianne Hackborn | 3b81bc1 | 2011-01-15 11:50:52 -0800 | [diff] [blame] | 5252 | if ((data.appInfo.flags&ApplicationInfo.FLAG_LARGE_HEAP) != 0) { |
Dianne Hackborn | de39851 | 2011-01-18 18:45:21 -0800 | [diff] [blame] | 5253 | dalvik.system.VMRuntime.getRuntime().clearGrowthLimit(); |
Mathieu Chartier | 24cee07 | 2015-01-08 14:42:20 -0800 | [diff] [blame] | 5254 | } else { |
| 5255 | // Small heap, clamp to the current growth limit and let the heap release |
| 5256 | // pages after the growth limit to the non growth limit capacity. b/18387825 |
| 5257 | dalvik.system.VMRuntime.getRuntime().clampGrowthLimit(); |
Dianne Hackborn | 3b81bc1 | 2011-01-15 11:50:52 -0800 | [diff] [blame] | 5258 | } |
| 5259 | |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 5260 | // Allow disk access during application and provider setup. This could |
Jeff Sharkey | 7c50167 | 2012-02-28 12:08:37 -0800 | [diff] [blame] | 5261 | // block processing ordered broadcasts, but later processing would |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 5262 | // probably end up doing the same disk access. |
Jeff Sharkey | 7c50167 | 2012-02-28 12:08:37 -0800 | [diff] [blame] | 5263 | final StrictMode.ThreadPolicy savedPolicy = StrictMode.allowThreadDiskWrites(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5264 | try { |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 5265 | // If the app is being launched for full backup or restore, bring it up in |
| 5266 | // a restricted environment with the base application class. |
| 5267 | Application app = data.info.makeApplication(data.restrictedBackupMode, null); |
| 5268 | mInitialApplication = app; |
Jeff Sharkey | 7c50167 | 2012-02-28 12:08:37 -0800 | [diff] [blame] | 5269 | |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 5270 | // don't bring up providers in restricted mode; they may depend on the |
| 5271 | // app's custom Application class |
| 5272 | if (!data.restrictedBackupMode) { |
Jeff Sharkey | 3e19589 | 2016-03-05 19:48:59 -0700 | [diff] [blame] | 5273 | if (!ArrayUtils.isEmpty(data.providers)) { |
| 5274 | installContentProviders(app, data.providers); |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 5275 | // For process that contains content providers, we want to |
| 5276 | // ensure that the JIT is enabled "at some point". |
| 5277 | mH.sendEmptyMessageDelayed(H.ENABLE_JIT, 10*1000); |
| 5278 | } |
| 5279 | } |
| 5280 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5281 | // Do this after providers, since instrumentation tests generally start their |
| 5282 | // test thread at this point, and we don't want that racing. |
| 5283 | try { |
| 5284 | mInstrumentation.onCreate(data.instrumentationArgs); |
| 5285 | } |
| 5286 | catch (Exception e) { |
| 5287 | throw new RuntimeException( |
| 5288 | "Exception thrown in onCreate() of " |
| 5289 | + data.instrumentationName + ": " + e.toString(), e); |
| 5290 | } |
| 5291 | |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 5292 | try { |
| 5293 | mInstrumentation.callApplicationOnCreate(app); |
| 5294 | } catch (Exception e) { |
| 5295 | if (!mInstrumentation.onException(app, e)) { |
| 5296 | throw new RuntimeException( |
| 5297 | "Unable to create application " + app.getClass().getName() |
| 5298 | + ": " + e.toString(), e); |
| 5299 | } |
| 5300 | } |
| 5301 | } finally { |
| 5302 | StrictMode.setThreadPolicy(savedPolicy); |
| 5303 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5304 | } |
| 5305 | |
| 5306 | /*package*/ final void finishInstrumentation(int resultCode, Bundle results) { |
| 5307 | IActivityManager am = ActivityManagerNative.getDefault(); |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 5308 | if (mProfiler.profileFile != null && mProfiler.handlingProfiling |
| 5309 | && mProfiler.profileFd == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5310 | Debug.stopMethodTracing(); |
| 5311 | } |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 5312 | //Slog.i(TAG, "am: " + ActivityManagerNative.getDefault() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5313 | // + ", app thr: " + mAppThread); |
| 5314 | try { |
| 5315 | am.finishInstrumentation(mAppThread, resultCode, results); |
| 5316 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5317 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5318 | } |
| 5319 | } |
| 5320 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 5321 | private void installContentProviders( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5322 | Context context, List<ProviderInfo> providers) { |
| 5323 | final ArrayList<IActivityManager.ContentProviderHolder> results = |
| 5324 | new ArrayList<IActivityManager.ContentProviderHolder>(); |
| 5325 | |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 5326 | for (ProviderInfo cpi : providers) { |
Dianne Hackborn | 40e9f29 | 2012-11-27 19:12:23 -0800 | [diff] [blame] | 5327 | if (DEBUG_PROVIDER) { |
| 5328 | StringBuilder buf = new StringBuilder(128); |
| 5329 | buf.append("Pub "); |
| 5330 | buf.append(cpi.authority); |
| 5331 | buf.append(": "); |
| 5332 | buf.append(cpi.name); |
| 5333 | Log.i(TAG, buf.toString()); |
| 5334 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5335 | IActivityManager.ContentProviderHolder cph = installProvider(context, null, cpi, |
| 5336 | false /*noisy*/, true /*noReleaseNeeded*/, true /*stable*/); |
| 5337 | if (cph != null) { |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5338 | cph.noReleaseNeeded = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5339 | results.add(cph); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5340 | } |
| 5341 | } |
| 5342 | |
| 5343 | try { |
| 5344 | ActivityManagerNative.getDefault().publishContentProviders( |
| 5345 | getApplicationThread(), results); |
| 5346 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5347 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5348 | } |
| 5349 | } |
| 5350 | |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 5351 | public final IContentProvider acquireProvider( |
| 5352 | Context c, String auth, int userId, boolean stable) { |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 5353 | final IContentProvider provider = acquireExistingProvider(c, auth, userId, stable); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5354 | if (provider != null) { |
| 5355 | return provider; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5356 | } |
| 5357 | |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 5358 | // There is a possible race here. Another thread may try to acquire |
| 5359 | // the same provider at the same time. When this happens, we want to ensure |
| 5360 | // that the first one wins. |
| 5361 | // Note that we cannot hold the lock while acquiring and installing the |
| 5362 | // provider since it might take a long time to run and it could also potentially |
| 5363 | // 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] | 5364 | IActivityManager.ContentProviderHolder holder = null; |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 5365 | try { |
| 5366 | holder = ActivityManagerNative.getDefault().getContentProvider( |
| 5367 | getApplicationThread(), auth, userId, stable); |
| 5368 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5369 | throw ex.rethrowFromSystemServer(); |
Wale Ogunwale | 67fe0a4 | 2015-04-24 14:44:54 -0700 | [diff] [blame] | 5370 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5371 | if (holder == null) { |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 5372 | 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] | 5373 | return null; |
| 5374 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5375 | |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5376 | // Install provider will increment the reference count for us, and break |
| 5377 | // any ties in the race. |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5378 | holder = installProvider(c, holder, holder.info, |
| 5379 | true /*noisy*/, holder.noReleaseNeeded, stable); |
| 5380 | return holder.provider; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5381 | } |
| 5382 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5383 | private final void incProviderRefLocked(ProviderRefCount prc, boolean stable) { |
| 5384 | if (stable) { |
| 5385 | prc.stableCount += 1; |
| 5386 | if (prc.stableCount == 1) { |
| 5387 | // We are acquiring a new stable reference on the provider. |
| 5388 | int unstableDelta; |
| 5389 | if (prc.removePending) { |
| 5390 | // We have a pending remove operation, which is holding the |
| 5391 | // last unstable reference. At this point we are converting |
| 5392 | // that unstable reference to our new stable reference. |
| 5393 | unstableDelta = -1; |
| 5394 | // Cancel the removal of the provider. |
| 5395 | if (DEBUG_PROVIDER) { |
| 5396 | Slog.v(TAG, "incProviderRef: stable " |
| 5397 | + "snatched provider from the jaws of death"); |
| 5398 | } |
| 5399 | prc.removePending = false; |
Guobin Zhang | 9e3e5266 | 2013-03-21 13:57:11 +0800 | [diff] [blame] | 5400 | // There is a race! It fails to remove the message, which |
| 5401 | // will be handled in completeRemoveProvider(). |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5402 | mH.removeMessages(H.REMOVE_PROVIDER, prc); |
| 5403 | } else { |
| 5404 | unstableDelta = 0; |
| 5405 | } |
| 5406 | try { |
| 5407 | if (DEBUG_PROVIDER) { |
| 5408 | Slog.v(TAG, "incProviderRef Now stable - " |
| 5409 | + prc.holder.info.name + ": unstableDelta=" |
| 5410 | + unstableDelta); |
| 5411 | } |
| 5412 | ActivityManagerNative.getDefault().refContentProvider( |
| 5413 | prc.holder.connection, 1, unstableDelta); |
| 5414 | } catch (RemoteException e) { |
| 5415 | //do nothing content provider object is dead any way |
| 5416 | } |
| 5417 | } |
| 5418 | } else { |
| 5419 | prc.unstableCount += 1; |
| 5420 | if (prc.unstableCount == 1) { |
| 5421 | // We are acquiring a new unstable reference on the provider. |
| 5422 | if (prc.removePending) { |
| 5423 | // Oh look, we actually have a remove pending for the |
| 5424 | // provider, which is still holding the last unstable |
| 5425 | // reference. We just need to cancel that to take new |
| 5426 | // ownership of the reference. |
| 5427 | if (DEBUG_PROVIDER) { |
| 5428 | Slog.v(TAG, "incProviderRef: unstable " |
| 5429 | + "snatched provider from the jaws of death"); |
| 5430 | } |
| 5431 | prc.removePending = false; |
| 5432 | mH.removeMessages(H.REMOVE_PROVIDER, prc); |
| 5433 | } else { |
| 5434 | // First unstable ref, increment our count in the |
| 5435 | // activity manager. |
| 5436 | try { |
| 5437 | if (DEBUG_PROVIDER) { |
| 5438 | Slog.v(TAG, "incProviderRef: Now unstable - " |
| 5439 | + prc.holder.info.name); |
| 5440 | } |
| 5441 | ActivityManagerNative.getDefault().refContentProvider( |
| 5442 | prc.holder.connection, 0, 1); |
| 5443 | } catch (RemoteException e) { |
| 5444 | //do nothing content provider object is dead any way |
| 5445 | } |
| 5446 | } |
| 5447 | } |
| 5448 | } |
| 5449 | } |
| 5450 | |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 5451 | public final IContentProvider acquireExistingProvider( |
| 5452 | Context c, String auth, int userId, boolean stable) { |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5453 | synchronized (mProviderMap) { |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 5454 | final ProviderKey key = new ProviderKey(auth, userId); |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 5455 | final ProviderClientRecord pr = mProviderMap.get(key); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5456 | if (pr == null) { |
| 5457 | return null; |
| 5458 | } |
| 5459 | |
| 5460 | IContentProvider provider = pr.mProvider; |
| 5461 | IBinder jBinder = provider.asBinder(); |
Dianne Hackborn | c428aae | 2012-10-03 16:38:22 -0700 | [diff] [blame] | 5462 | if (!jBinder.isBinderAlive()) { |
| 5463 | // The hosting process of the provider has died; we can't |
| 5464 | // use this one. |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 5465 | Log.i(TAG, "Acquiring provider " + auth + " for user " + userId |
Dianne Hackborn | c428aae | 2012-10-03 16:38:22 -0700 | [diff] [blame] | 5466 | + ": existing object's process dead"); |
| 5467 | handleUnstableProviderDiedLocked(jBinder, true); |
| 5468 | return null; |
| 5469 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5470 | |
| 5471 | // Only increment the ref count if we have one. If we don't then the |
| 5472 | // provider is not reference counted and never needs to be released. |
Dianne Hackborn | cca1f0e | 2010-09-26 18:34:53 -0700 | [diff] [blame] | 5473 | ProviderRefCount prc = mProviderRefCountMap.get(jBinder); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5474 | if (prc != null) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5475 | incProviderRefLocked(prc, stable); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5476 | } |
| 5477 | return provider; |
| 5478 | } |
Dianne Hackborn | cca1f0e | 2010-09-26 18:34:53 -0700 | [diff] [blame] | 5479 | } |
| 5480 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5481 | public final boolean releaseProvider(IContentProvider provider, boolean stable) { |
| 5482 | if (provider == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5483 | return false; |
| 5484 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5485 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5486 | IBinder jBinder = provider.asBinder(); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5487 | synchronized (mProviderMap) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5488 | ProviderRefCount prc = mProviderRefCountMap.get(jBinder); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5489 | if (prc == null) { |
| 5490 | // 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] | 5491 | return false; |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5492 | } |
| 5493 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5494 | boolean lastRef = false; |
| 5495 | if (stable) { |
| 5496 | if (prc.stableCount == 0) { |
| 5497 | if (DEBUG_PROVIDER) Slog.v(TAG, |
| 5498 | "releaseProvider: stable ref count already 0, how?"); |
| 5499 | return false; |
| 5500 | } |
| 5501 | prc.stableCount -= 1; |
| 5502 | if (prc.stableCount == 0) { |
| 5503 | // What we do at this point depends on whether there are |
| 5504 | // any unstable refs left: if there are, we just tell the |
| 5505 | // activity manager to decrement its stable count; if there |
| 5506 | // aren't, we need to enqueue this provider to be removed, |
| 5507 | // and convert to holding a single unstable ref while |
| 5508 | // doing so. |
| 5509 | lastRef = prc.unstableCount == 0; |
| 5510 | try { |
| 5511 | if (DEBUG_PROVIDER) { |
| 5512 | Slog.v(TAG, "releaseProvider: No longer stable w/lastRef=" |
| 5513 | + lastRef + " - " + prc.holder.info.name); |
| 5514 | } |
| 5515 | ActivityManagerNative.getDefault().refContentProvider( |
| 5516 | prc.holder.connection, -1, lastRef ? 1 : 0); |
| 5517 | } catch (RemoteException e) { |
| 5518 | //do nothing content provider object is dead any way |
| 5519 | } |
| 5520 | } |
| 5521 | } else { |
| 5522 | if (prc.unstableCount == 0) { |
| 5523 | if (DEBUG_PROVIDER) Slog.v(TAG, |
| 5524 | "releaseProvider: unstable ref count already 0, how?"); |
| 5525 | return false; |
| 5526 | } |
| 5527 | prc.unstableCount -= 1; |
| 5528 | if (prc.unstableCount == 0) { |
| 5529 | // If this is the last reference, we need to enqueue |
| 5530 | // this provider to be removed instead of telling the |
| 5531 | // activity manager to remove it at this point. |
| 5532 | lastRef = prc.stableCount == 0; |
| 5533 | if (!lastRef) { |
| 5534 | try { |
| 5535 | if (DEBUG_PROVIDER) { |
| 5536 | Slog.v(TAG, "releaseProvider: No longer unstable - " |
| 5537 | + prc.holder.info.name); |
| 5538 | } |
| 5539 | ActivityManagerNative.getDefault().refContentProvider( |
| 5540 | prc.holder.connection, 0, -1); |
| 5541 | } catch (RemoteException e) { |
| 5542 | //do nothing content provider object is dead any way |
| 5543 | } |
| 5544 | } |
| 5545 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5546 | } |
| 5547 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5548 | if (lastRef) { |
| 5549 | if (!prc.removePending) { |
| 5550 | // Schedule the actual remove asynchronously, since we don't know the context |
| 5551 | // this will be called in. |
| 5552 | // TODO: it would be nice to post a delayed message, so |
| 5553 | // if we come back and need the same provider quickly |
| 5554 | // we will still have it available. |
| 5555 | if (DEBUG_PROVIDER) { |
| 5556 | Slog.v(TAG, "releaseProvider: Enqueueing pending removal - " |
| 5557 | + prc.holder.info.name); |
| 5558 | } |
| 5559 | prc.removePending = true; |
| 5560 | Message msg = mH.obtainMessage(H.REMOVE_PROVIDER, prc); |
| 5561 | mH.sendMessage(msg); |
| 5562 | } else { |
| 5563 | Slog.w(TAG, "Duplicate remove pending of provider " + prc.holder.info.name); |
| 5564 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5565 | } |
| 5566 | return true; |
| 5567 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5568 | } |
| 5569 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5570 | final void completeRemoveProvider(ProviderRefCount prc) { |
| 5571 | synchronized (mProviderMap) { |
| 5572 | if (!prc.removePending) { |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5573 | // There was a race! Some other client managed to acquire |
| 5574 | // the provider before the removal was completed. |
| 5575 | // Abort the removal. We will do it later. |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5576 | if (DEBUG_PROVIDER) Slog.v(TAG, "completeRemoveProvider: lost the race, " |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5577 | + "provider still in use"); |
| 5578 | return; |
| 5579 | } |
| 5580 | |
Guobin Zhang | 9e3e5266 | 2013-03-21 13:57:11 +0800 | [diff] [blame] | 5581 | // More complicated race!! Some client managed to acquire the |
| 5582 | // provider and release it before the removal was completed. |
| 5583 | // Continue the removal, and abort the next remove message. |
| 5584 | prc.removePending = false; |
| 5585 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5586 | final IBinder jBinder = prc.holder.provider.asBinder(); |
| 5587 | ProviderRefCount existingPrc = mProviderRefCountMap.get(jBinder); |
| 5588 | if (existingPrc == prc) { |
| 5589 | mProviderRefCountMap.remove(jBinder); |
| 5590 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5591 | |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 5592 | for (int i=mProviderMap.size()-1; i>=0; i--) { |
| 5593 | ProviderClientRecord pr = mProviderMap.valueAt(i); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5594 | IBinder myBinder = pr.mProvider.asBinder(); |
| 5595 | if (myBinder == jBinder) { |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 5596 | mProviderMap.removeAt(i); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5597 | } |
| 5598 | } |
| 5599 | } |
| 5600 | |
| 5601 | try { |
| 5602 | if (DEBUG_PROVIDER) { |
| 5603 | Slog.v(TAG, "removeProvider: Invoking ActivityManagerNative." |
| 5604 | + "removeContentProvider(" + prc.holder.info.name + ")"); |
| 5605 | } |
| 5606 | ActivityManagerNative.getDefault().removeContentProvider( |
| 5607 | prc.holder.connection, false); |
| 5608 | } catch (RemoteException e) { |
| 5609 | //do nothing content provider object is dead any way |
| 5610 | } |
| 5611 | } |
| 5612 | |
| 5613 | final void handleUnstableProviderDied(IBinder provider, boolean fromClient) { |
Dianne Hackborn | c428aae | 2012-10-03 16:38:22 -0700 | [diff] [blame] | 5614 | synchronized (mProviderMap) { |
| 5615 | handleUnstableProviderDiedLocked(provider, fromClient); |
| 5616 | } |
| 5617 | } |
| 5618 | |
| 5619 | final void handleUnstableProviderDiedLocked(IBinder provider, boolean fromClient) { |
| 5620 | ProviderRefCount prc = mProviderRefCountMap.get(provider); |
| 5621 | if (prc != null) { |
| 5622 | if (DEBUG_PROVIDER) Slog.v(TAG, "Cleaning up dead provider " |
| 5623 | + provider + " " + prc.holder.info.name); |
| 5624 | mProviderRefCountMap.remove(provider); |
You Kim | bc74de6 | 2013-10-01 00:13:26 +0900 | [diff] [blame] | 5625 | for (int i=mProviderMap.size()-1; i>=0; i--) { |
| 5626 | ProviderClientRecord pr = mProviderMap.valueAt(i); |
| 5627 | if (pr != null && pr.mProvider.asBinder() == provider) { |
| 5628 | Slog.i(TAG, "Removing dead content provider:" + pr.mProvider.toString()); |
| 5629 | mProviderMap.removeAt(i); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5630 | } |
Dianne Hackborn | c428aae | 2012-10-03 16:38:22 -0700 | [diff] [blame] | 5631 | } |
You Kim | bc74de6 | 2013-10-01 00:13:26 +0900 | [diff] [blame] | 5632 | |
Dianne Hackborn | c428aae | 2012-10-03 16:38:22 -0700 | [diff] [blame] | 5633 | if (fromClient) { |
| 5634 | // We found out about this due to execution in our client |
| 5635 | // code. Tell the activity manager about it now, to ensure |
| 5636 | // that the next time we go to do anything with the provider |
| 5637 | // it knows it is dead (so we don't race with its death |
| 5638 | // notification). |
| 5639 | try { |
| 5640 | ActivityManagerNative.getDefault().unstableProviderDied( |
| 5641 | prc.holder.connection); |
| 5642 | } catch (RemoteException e) { |
| 5643 | //do nothing content provider object is dead any way |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5644 | } |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 5645 | } |
| 5646 | } |
| 5647 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5648 | |
Jeff Sharkey | 7aa7601 | 2013-09-30 14:26:27 -0700 | [diff] [blame] | 5649 | final void appNotRespondingViaProvider(IBinder provider) { |
| 5650 | synchronized (mProviderMap) { |
| 5651 | ProviderRefCount prc = mProviderRefCountMap.get(provider); |
| 5652 | if (prc != null) { |
| 5653 | try { |
| 5654 | ActivityManagerNative.getDefault() |
| 5655 | .appNotRespondingViaProvider(prc.holder.connection); |
| 5656 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5657 | throw e.rethrowFromSystemServer(); |
Jeff Sharkey | 7aa7601 | 2013-09-30 14:26:27 -0700 | [diff] [blame] | 5658 | } |
| 5659 | } |
| 5660 | } |
| 5661 | } |
| 5662 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5663 | private ProviderClientRecord installProviderAuthoritiesLocked(IContentProvider provider, |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 5664 | ContentProvider localProvider, IActivityManager.ContentProviderHolder holder) { |
Andreas Gampe | 18e99c1 | 2015-03-06 15:29:06 -0800 | [diff] [blame] | 5665 | final String auths[] = holder.info.authority.split(";"); |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 5666 | final int userId = UserHandle.getUserId(holder.info.applicationInfo.uid); |
| 5667 | |
| 5668 | final ProviderClientRecord pcr = new ProviderClientRecord( |
| 5669 | auths, provider, localProvider, holder); |
| 5670 | for (String auth : auths) { |
| 5671 | final ProviderKey key = new ProviderKey(auth, userId); |
| 5672 | final ProviderClientRecord existing = mProviderMap.get(key); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5673 | if (existing != null) { |
| 5674 | Slog.w(TAG, "Content provider " + pcr.mHolder.info.name |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 5675 | + " already published as " + auth); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5676 | } else { |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 5677 | mProviderMap.put(key, pcr); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5678 | } |
| 5679 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5680 | return pcr; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5681 | } |
| 5682 | |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5683 | /** |
| 5684 | * Installs the provider. |
| 5685 | * |
| 5686 | * Providers that are local to the process or that come from the system server |
| 5687 | * may be installed permanently which is indicated by setting noReleaseNeeded to true. |
| 5688 | * Other remote providers are reference counted. The initial reference count |
| 5689 | * for all reference counted providers is one. Providers that are not reference |
| 5690 | * counted do not have a reference count (at all). |
| 5691 | * |
| 5692 | * This method detects when a provider has already been installed. When this happens, |
| 5693 | * it increments the reference count of the existing provider (if appropriate) |
| 5694 | * and returns the existing provider. This can happen due to concurrent |
| 5695 | * attempts to acquire the same provider. |
| 5696 | */ |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5697 | private IActivityManager.ContentProviderHolder installProvider(Context context, |
| 5698 | IActivityManager.ContentProviderHolder holder, ProviderInfo info, |
| 5699 | boolean noisy, boolean noReleaseNeeded, boolean stable) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5700 | ContentProvider localProvider = null; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5701 | IContentProvider provider; |
Dianne Hackborn | 5f48fca | 2012-05-30 11:06:31 -0700 | [diff] [blame] | 5702 | if (holder == null || holder.provider == null) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5703 | if (DEBUG_PROVIDER || noisy) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 5704 | Slog.d(TAG, "Loading provider " + info.authority + ": " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5705 | + info.name); |
| 5706 | } |
| 5707 | Context c = null; |
| 5708 | ApplicationInfo ai = info.applicationInfo; |
| 5709 | if (context.getPackageName().equals(ai.packageName)) { |
| 5710 | c = context; |
| 5711 | } else if (mInitialApplication != null && |
| 5712 | mInitialApplication.getPackageName().equals(ai.packageName)) { |
| 5713 | c = mInitialApplication; |
| 5714 | } else { |
| 5715 | try { |
| 5716 | c = context.createPackageContext(ai.packageName, |
| 5717 | Context.CONTEXT_INCLUDE_CODE); |
| 5718 | } catch (PackageManager.NameNotFoundException e) { |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 5719 | // Ignore |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5720 | } |
| 5721 | } |
| 5722 | if (c == null) { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 5723 | Slog.w(TAG, "Unable to get context for package " + |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5724 | ai.packageName + |
| 5725 | " while loading content provider " + |
| 5726 | info.name); |
| 5727 | return null; |
| 5728 | } |
| 5729 | try { |
| 5730 | final java.lang.ClassLoader cl = c.getClassLoader(); |
| 5731 | localProvider = (ContentProvider)cl. |
| 5732 | loadClass(info.name).newInstance(); |
| 5733 | provider = localProvider.getIContentProvider(); |
| 5734 | if (provider == null) { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 5735 | Slog.e(TAG, "Failed to instantiate class " + |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5736 | info.name + " from sourceDir " + |
| 5737 | info.applicationInfo.sourceDir); |
| 5738 | return null; |
| 5739 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5740 | if (DEBUG_PROVIDER) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5741 | TAG, "Instantiating local provider " + info.name); |
| 5742 | // XXX Need to create the correct context for this provider. |
| 5743 | localProvider.attachInfo(c, info); |
| 5744 | } catch (java.lang.Exception e) { |
| 5745 | if (!mInstrumentation.onException(null, e)) { |
| 5746 | throw new RuntimeException( |
| 5747 | "Unable to get provider " + info.name |
| 5748 | + ": " + e.toString(), e); |
| 5749 | } |
| 5750 | return null; |
| 5751 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5752 | } else { |
| 5753 | provider = holder.provider; |
| 5754 | 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] | 5755 | + info.name); |
| 5756 | } |
| 5757 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5758 | IActivityManager.ContentProviderHolder retHolder; |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5759 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5760 | synchronized (mProviderMap) { |
| 5761 | if (DEBUG_PROVIDER) Slog.v(TAG, "Checking to add " + provider |
| 5762 | + " / " + info.name); |
| 5763 | IBinder jBinder = provider.asBinder(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5764 | if (localProvider != null) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5765 | ComponentName cname = new ComponentName(info.packageName, info.name); |
| 5766 | ProviderClientRecord pr = mLocalProvidersByName.get(cname); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5767 | if (pr != null) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5768 | if (DEBUG_PROVIDER) { |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5769 | Slog.v(TAG, "installProvider: lost the race, " |
| 5770 | + "using existing local provider"); |
| 5771 | } |
| 5772 | provider = pr.mProvider; |
| 5773 | } else { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5774 | holder = new IActivityManager.ContentProviderHolder(info); |
| 5775 | holder.provider = provider; |
| 5776 | holder.noReleaseNeeded = true; |
| 5777 | pr = installProviderAuthoritiesLocked(provider, localProvider, holder); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5778 | mLocalProviders.put(jBinder, pr); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5779 | mLocalProvidersByName.put(cname, pr); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5780 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5781 | retHolder = pr.mHolder; |
| 5782 | } else { |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5783 | ProviderRefCount prc = mProviderRefCountMap.get(jBinder); |
| 5784 | if (prc != null) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5785 | if (DEBUG_PROVIDER) { |
| 5786 | Slog.v(TAG, "installProvider: lost the race, updating ref count"); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5787 | } |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 5788 | // We need to transfer our new reference to the existing |
| 5789 | // ref count, releasing the old one... but only if |
| 5790 | // release is needed (that is, it is not running in the |
| 5791 | // system process). |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5792 | if (!noReleaseNeeded) { |
| 5793 | incProviderRefLocked(prc, stable); |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 5794 | try { |
| 5795 | ActivityManagerNative.getDefault().removeContentProvider( |
| 5796 | holder.connection, stable); |
| 5797 | } catch (RemoteException e) { |
| 5798 | //do nothing content provider object is dead any way |
| 5799 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5800 | } |
| 5801 | } else { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5802 | ProviderClientRecord client = installProviderAuthoritiesLocked( |
| 5803 | provider, localProvider, holder); |
| 5804 | if (noReleaseNeeded) { |
| 5805 | prc = new ProviderRefCount(holder, client, 1000, 1000); |
| 5806 | } else { |
| 5807 | prc = stable |
| 5808 | ? new ProviderRefCount(holder, client, 1, 0) |
| 5809 | : new ProviderRefCount(holder, client, 0, 1); |
| 5810 | } |
| 5811 | mProviderRefCountMap.put(jBinder, prc); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5812 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5813 | retHolder = prc.holder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5814 | } |
| 5815 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5816 | |
| 5817 | return retHolder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5818 | } |
| 5819 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 5820 | private void attach(boolean system) { |
Jeff Sharkey | 66a017b | 2013-01-17 18:18:22 -0800 | [diff] [blame] | 5821 | sCurrentActivityThread = this; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5822 | mSystemThread = system; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5823 | if (!system) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 5824 | ViewRootImpl.addFirstDrawHandler(new Runnable() { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 5825 | @Override |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 5826 | public void run() { |
| 5827 | ensureJitEnabled(); |
| 5828 | } |
| 5829 | }); |
Siva Velusamy | d693dfa | 2012-09-10 14:36:58 -0700 | [diff] [blame] | 5830 | android.ddm.DdmHandleAppName.setAppName("<pre-initialized>", |
| 5831 | UserHandle.myUserId()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5832 | RuntimeInit.setApplicationObject(mAppThread.asBinder()); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 5833 | final IActivityManager mgr = ActivityManagerNative.getDefault(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5834 | try { |
| 5835 | mgr.attachApplication(mAppThread); |
| 5836 | } catch (RemoteException ex) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5837 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5838 | } |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 5839 | // Watch for getting close to heap limit. |
| 5840 | BinderInternal.addGcWatcher(new Runnable() { |
| 5841 | @Override public void run() { |
| 5842 | if (!mSomeActivitiesChanged) { |
| 5843 | return; |
| 5844 | } |
| 5845 | Runtime runtime = Runtime.getRuntime(); |
| 5846 | long dalvikMax = runtime.maxMemory(); |
| 5847 | long dalvikUsed = runtime.totalMemory() - runtime.freeMemory(); |
| 5848 | if (dalvikUsed > ((3*dalvikMax)/4)) { |
| 5849 | if (DEBUG_MEMORY_TRIM) Slog.d(TAG, "Dalvik max=" + (dalvikMax/1024) |
| 5850 | + " total=" + (runtime.totalMemory()/1024) |
| 5851 | + " used=" + (dalvikUsed/1024)); |
| 5852 | mSomeActivitiesChanged = false; |
| 5853 | try { |
| 5854 | mgr.releaseSomeActivities(mAppThread); |
| 5855 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5856 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 5857 | } |
| 5858 | } |
| 5859 | } |
| 5860 | }); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5861 | } else { |
| 5862 | // Don't set application object here -- if the system crashes, |
| 5863 | // 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] | 5864 | android.ddm.DdmHandleAppName.setAppName("system_process", |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 5865 | UserHandle.myUserId()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5866 | try { |
| 5867 | mInstrumentation = new Instrumentation(); |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 5868 | ContextImpl context = ContextImpl.createAppContext( |
| 5869 | this, getSystemContext().mPackageInfo); |
Jeff Brown | 7fc8e35 | 2014-09-16 18:06:47 -0700 | [diff] [blame] | 5870 | mInitialApplication = context.mPackageInfo.makeApplication(true, null); |
| 5871 | mInitialApplication.onCreate(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5872 | } catch (Exception e) { |
| 5873 | throw new RuntimeException( |
| 5874 | "Unable to instantiate Application():" + e.toString(), e); |
| 5875 | } |
| 5876 | } |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 5877 | |
| 5878 | // add dropbox logging to libcore |
| 5879 | DropBox.setReporter(new DropBoxReporter()); |
| 5880 | |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 5881 | ViewRootImpl.addConfigCallback(new ComponentCallbacks2() { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 5882 | @Override |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5883 | public void onConfigurationChanged(Configuration newConfig) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 5884 | synchronized (mResourcesManager) { |
Dianne Hackborn | ae07816 | 2010-03-18 11:29:37 -0700 | [diff] [blame] | 5885 | // We need to apply this change to the resources |
| 5886 | // immediately, because upon returning the view |
| 5887 | // hierarchy will be informed about it. |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 5888 | if (mResourcesManager.applyConfigurationToResourcesLocked(newConfig, null)) { |
Dianne Hackborn | ae07816 | 2010-03-18 11:29:37 -0700 | [diff] [blame] | 5889 | // This actually changed the resources! Tell |
| 5890 | // everyone about it. |
| 5891 | if (mPendingConfiguration == null || |
| 5892 | mPendingConfiguration.isOtherSeqNewer(newConfig)) { |
| 5893 | mPendingConfiguration = newConfig; |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 5894 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 5895 | sendMessage(H.CONFIGURATION_CHANGED, newConfig); |
Dianne Hackborn | ae07816 | 2010-03-18 11:29:37 -0700 | [diff] [blame] | 5896 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5897 | } |
| 5898 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5899 | } |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 5900 | @Override |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5901 | public void onLowMemory() { |
| 5902 | } |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 5903 | @Override |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 5904 | public void onTrimMemory(int level) { |
| 5905 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5906 | }); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5907 | } |
| 5908 | |
Romain Guy | 5e9120d | 2012-01-30 12:17:22 -0800 | [diff] [blame] | 5909 | public static ActivityThread systemMain() { |
Alan Viverette | 5e1565e | 2014-07-29 16:14:25 -0700 | [diff] [blame] | 5910 | // The system process on low-memory devices do not get to use hardware |
| 5911 | // accelerated drawing, since this can add too much overhead to the |
| 5912 | // process. |
| 5913 | if (!ActivityManager.isHighEndGfx()) { |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 5914 | ThreadedRenderer.disable(true); |
John Reck | 73840ea | 2014-09-22 07:39:18 -0700 | [diff] [blame] | 5915 | } else { |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 5916 | ThreadedRenderer.enableForegroundTrimming(); |
Alan Viverette | 5e1565e | 2014-07-29 16:14:25 -0700 | [diff] [blame] | 5917 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5918 | ActivityThread thread = new ActivityThread(); |
| 5919 | thread.attach(true); |
| 5920 | return thread; |
| 5921 | } |
| 5922 | |
Jeff Brown | 10e8971 | 2011-07-08 18:52:57 -0700 | [diff] [blame] | 5923 | public final void installSystemProviders(List<ProviderInfo> providers) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5924 | if (providers != null) { |
Jeff Brown | 10e8971 | 2011-07-08 18:52:57 -0700 | [diff] [blame] | 5925 | installContentProviders(mInitialApplication, providers); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5926 | } |
| 5927 | } |
| 5928 | |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 5929 | public int getIntCoreSetting(String key, int defaultValue) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 5930 | synchronized (mResourcesManager) { |
Svetoslav Ganov | 9aa597e | 2011-03-03 18:17:41 -0800 | [diff] [blame] | 5931 | if (mCoreSettings != null) { |
| 5932 | return mCoreSettings.getInt(key, defaultValue); |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 5933 | } |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 5934 | return defaultValue; |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 5935 | } |
| 5936 | } |
| 5937 | |
Geremy Condra | 69689a7 | 2012-09-11 16:57:17 -0700 | [diff] [blame] | 5938 | private static class EventLoggingReporter implements EventLogger.Reporter { |
| 5939 | @Override |
| 5940 | public void report (int code, Object... list) { |
| 5941 | EventLog.writeEvent(code, list); |
| 5942 | } |
| 5943 | } |
| 5944 | |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 5945 | private class DropBoxReporter implements DropBox.Reporter { |
| 5946 | |
| 5947 | private DropBoxManager dropBox; |
| 5948 | |
Narayan Kamath | 7f06224 | 2015-04-08 13:24:13 +0100 | [diff] [blame] | 5949 | public DropBoxReporter() {} |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 5950 | |
| 5951 | @Override |
| 5952 | public void addData(String tag, byte[] data, int flags) { |
Narayan Kamath | 7f06224 | 2015-04-08 13:24:13 +0100 | [diff] [blame] | 5953 | ensureInitialized(); |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 5954 | dropBox.addData(tag, data, flags); |
| 5955 | } |
| 5956 | |
| 5957 | @Override |
| 5958 | public void addText(String tag, String data) { |
Narayan Kamath | 7f06224 | 2015-04-08 13:24:13 +0100 | [diff] [blame] | 5959 | ensureInitialized(); |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 5960 | dropBox.addText(tag, data); |
| 5961 | } |
Narayan Kamath | 7f06224 | 2015-04-08 13:24:13 +0100 | [diff] [blame] | 5962 | |
| 5963 | private synchronized void ensureInitialized() { |
| 5964 | if (dropBox == null) { |
| 5965 | dropBox = (DropBoxManager) getSystemContext().getSystemService(Context.DROPBOX_SERVICE); |
| 5966 | } |
| 5967 | } |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 5968 | } |
| 5969 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 5970 | public static void main(String[] args) { |
Narayan Kamath | fbb32f6 | 2015-06-12 15:34:35 +0100 | [diff] [blame] | 5971 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "ActivityThreadMain"); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 5972 | SamplingProfilerIntegration.start(); |
| 5973 | |
Brad Fitzpatrick | 4d9e6d2 | 2010-11-15 08:49:51 -0800 | [diff] [blame] | 5974 | // CloseGuard defaults to true and can be quite spammy. We |
| 5975 | // disable it here, but selectively enable it later (via |
| 5976 | // StrictMode) on debug builds, but using DropBox, not logs. |
| 5977 | CloseGuard.setEnabled(false); |
| 5978 | |
Jeff Sharkey | b049e21 | 2012-09-07 23:16:01 -0700 | [diff] [blame] | 5979 | Environment.initForCurrentUser(); |
| 5980 | |
Geremy Condra | 69689a7 | 2012-09-11 16:57:17 -0700 | [diff] [blame] | 5981 | // Set the reporter for event logging in libcore |
| 5982 | EventLogger.setReporter(new EventLoggingReporter()); |
| 5983 | |
Alex Klyubin | 4812563 | 2015-04-29 13:16:30 -0700 | [diff] [blame] | 5984 | AndroidKeyStoreProvider.install(); |
Kenny Root | 8b51475 | 2013-02-04 09:35:16 -0800 | [diff] [blame] | 5985 | |
Robin Lee | 3d076af | 2014-04-25 14:57:49 +0100 | [diff] [blame] | 5986 | // Make sure TrustedCertificateStore looks in the right place for CA certificates |
| 5987 | final File configDir = Environment.getUserConfigDirectory(UserHandle.myUserId()); |
| 5988 | TrustedCertificateStore.setDefaultUserDirectory(configDir); |
| 5989 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5990 | Process.setArgV0("<pre-initialized>"); |
| 5991 | |
| 5992 | Looper.prepareMainLooper(); |
| 5993 | |
| 5994 | ActivityThread thread = new ActivityThread(); |
| 5995 | thread.attach(false); |
| 5996 | |
Vairavan Srinivasan | 7335cfd | 2012-08-18 18:36:03 -0700 | [diff] [blame] | 5997 | if (sMainThreadHandler == null) { |
| 5998 | sMainThreadHandler = thread.getHandler(); |
| 5999 | } |
| 6000 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6001 | if (false) { |
| 6002 | Looper.myLooper().setMessageLogging(new |
| 6003 | LogPrinter(Log.DEBUG, "ActivityThread")); |
| 6004 | } |
| 6005 | |
Narayan Kamath | fbb32f6 | 2015-06-12 15:34:35 +0100 | [diff] [blame] | 6006 | // End of event ActivityThreadMain. |
| 6007 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6008 | Looper.loop(); |
| 6009 | |
Jeff Brown | 10e8971 | 2011-07-08 18:52:57 -0700 | [diff] [blame] | 6010 | throw new RuntimeException("Main thread loop unexpectedly exited"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6011 | } |
| 6012 | } |