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; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 78 | import android.os.UserHandle; |
Narayan Kamath | ccb2a086 | 2013-12-19 14:49:36 +0000 | [diff] [blame] | 79 | import android.provider.Settings; |
Alex Klyubin | f9034cc | 2015-02-12 11:43:09 -0800 | [diff] [blame] | 80 | import android.security.NetworkSecurityPolicy; |
Chad Brubaker | 78d4712 | 2015-11-17 22:26:58 -0800 | [diff] [blame] | 81 | import android.security.net.config.NetworkSecurityConfigProvider; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 82 | import android.util.AndroidRuntimeException; |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 83 | import android.util.ArrayMap; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 84 | import android.util.DisplayMetrics; |
| 85 | import android.util.EventLog; |
| 86 | import android.util.Log; |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 87 | import android.util.LogPrinter; |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 88 | import android.util.Pair; |
Jeff Brown | 6754ba2 | 2011-12-14 20:20:01 -0800 | [diff] [blame] | 89 | import android.util.PrintWriterPrinter; |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 90 | import android.util.Slog; |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 91 | import android.util.SparseIntArray; |
Adam Powell | 1487466 | 2013-07-18 19:42:41 -0700 | [diff] [blame] | 92 | import android.util.SuperNotCalledException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 93 | import android.view.Display; |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 94 | import android.view.ThreadedRenderer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 95 | import android.view.View; |
| 96 | import android.view.ViewDebug; |
| 97 | import android.view.ViewManager; |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 98 | import android.view.ViewRootImpl; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 99 | import android.view.Window; |
| 100 | import android.view.WindowManager; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 101 | import android.view.WindowManagerGlobal; |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 102 | import android.renderscript.RenderScriptCacheDir; |
Alex Klyubin | dcdaf87 | 2015-05-13 15:57:09 -0700 | [diff] [blame] | 103 | import android.security.keystore.AndroidKeyStoreProvider; |
Calin Juravle | 6905239 | 2015-12-17 17:06:49 +0200 | [diff] [blame] | 104 | import android.system.Os; |
| 105 | import android.system.OsConstants; |
| 106 | import android.system.ErrnoException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 107 | |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 108 | import com.android.internal.annotations.GuardedBy; |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 109 | import com.android.internal.app.IVoiceInteractor; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 110 | import com.android.internal.content.ReferrerIntent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 111 | import com.android.internal.os.BinderInternal; |
| 112 | import com.android.internal.os.RuntimeInit; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 113 | import com.android.internal.os.SamplingProfilerIntegration; |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 114 | import com.android.internal.os.SomeArgs; |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 115 | import com.android.internal.util.FastPrintWriter; |
Kenny Root | 12e7522 | 2013-04-23 22:34:24 -0700 | [diff] [blame] | 116 | import com.android.org.conscrypt.OpenSSLSocketImpl; |
Robin Lee | 3d076af | 2014-04-25 14:57:49 +0100 | [diff] [blame] | 117 | import com.android.org.conscrypt.TrustedCertificateStore; |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 118 | import com.google.android.collect.Lists; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 119 | |
| 120 | import java.io.File; |
| 121 | import java.io.FileDescriptor; |
| 122 | import java.io.FileOutputStream; |
Dianne Hackborn | 9c8dd55 | 2009-06-23 19:22:52 -0700 | [diff] [blame] | 123 | import java.io.IOException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 124 | import java.io.PrintWriter; |
| 125 | import java.lang.ref.WeakReference; |
Robert Greenwalt | 03595d0 | 2010-11-02 14:08:23 -0700 | [diff] [blame] | 126 | import java.net.InetAddress; |
Narayan Kamath | ccb2a086 | 2013-12-19 14:49:36 +0000 | [diff] [blame] | 127 | import java.text.DateFormat; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 128 | import java.util.ArrayList; |
Calin Juravle | f19c963 | 2015-12-10 17:32:15 +0000 | [diff] [blame] | 129 | import java.util.Collections; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 130 | import java.util.List; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 131 | import java.util.Map; |
Kenny Root | e6585b3 | 2013-12-13 12:00:26 -0800 | [diff] [blame] | 132 | import java.util.Objects; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 133 | import java.util.TimeZone; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 134 | |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 135 | import libcore.io.DropBox; |
Geremy Condra | 69689a7 | 2012-09-11 16:57:17 -0700 | [diff] [blame] | 136 | import libcore.io.EventLogger; |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 137 | import libcore.io.IoUtils; |
Paul Jensen | e401d17 | 2014-09-12 10:47:39 -0400 | [diff] [blame] | 138 | import libcore.net.event.NetworkEventDispatcher; |
Brad Fitzpatrick | 4d9e6d2 | 2010-11-15 08:49:51 -0800 | [diff] [blame] | 139 | import dalvik.system.CloseGuard; |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 140 | import dalvik.system.VMDebug; |
Mathieu Chartier | 1e37090 | 2013-07-18 10:58:01 -0700 | [diff] [blame] | 141 | import dalvik.system.VMRuntime; |
Man Cao | cfa78b2 | 2015-06-11 20:14:34 -0700 | [diff] [blame] | 142 | import org.apache.harmony.dalvik.ddmc.DdmVmInternal; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 143 | |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 144 | final class RemoteServiceException extends AndroidRuntimeException { |
| 145 | public RemoteServiceException(String msg) { |
| 146 | super(msg); |
| 147 | } |
| 148 | } |
| 149 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 150 | /** |
| 151 | * This manages the execution of the main thread in an |
| 152 | * application process, scheduling and executing activities, |
| 153 | * broadcasts, and other operations on it as the activity |
| 154 | * manager requests. |
| 155 | * |
| 156 | * {@hide} |
| 157 | */ |
| 158 | public final class ActivityThread { |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 159 | /** @hide */ |
| 160 | public static final String TAG = "ActivityThread"; |
Jim Miller | 0b2a6d0 | 2010-07-13 18:01:29 -0700 | [diff] [blame] | 161 | 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] | 162 | static final boolean localLOGV = false; |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 163 | static final boolean DEBUG_MESSAGES = false; |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 164 | /** @hide */ |
| 165 | public static final boolean DEBUG_BROADCAST = false; |
Chris Tate | 8a7dc17 | 2009-03-24 20:11:42 -0700 | [diff] [blame] | 166 | private static final boolean DEBUG_RESULTS = false; |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 167 | private static final boolean DEBUG_BACKUP = false; |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 168 | public static final boolean DEBUG_CONFIGURATION = false; |
Dianne Hackborn | a0c283e | 2012-02-09 10:47:01 -0800 | [diff] [blame] | 169 | private static final boolean DEBUG_SERVICE = false; |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 170 | private static final boolean DEBUG_MEMORY_TRIM = false; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 171 | private static final boolean DEBUG_PROVIDER = false; |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 172 | private static final boolean DEBUG_ORDER = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 173 | 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] | 174 | private static final int SQLITE_MEM_RELEASED_EVENT_LOG_TAG = 75003; |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 175 | private static final int LOG_AM_ON_PAUSE_CALLED = 30021; |
| 176 | private static final int LOG_AM_ON_RESUME_CALLED = 30022; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 177 | |
Dianne Hackborn | 455625e | 2015-01-21 09:55:13 -0800 | [diff] [blame] | 178 | /** Type for IActivityManager.serviceDoneExecuting: anonymous operation */ |
| 179 | public static final int SERVICE_DONE_EXECUTING_ANON = 0; |
| 180 | /** Type for IActivityManager.serviceDoneExecuting: done with an onStart call */ |
| 181 | public static final int SERVICE_DONE_EXECUTING_START = 1; |
| 182 | /** Type for IActivityManager.serviceDoneExecuting: done stopping (destroying) service */ |
| 183 | public static final int SERVICE_DONE_EXECUTING_STOP = 2; |
| 184 | |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 185 | // Details for pausing activity. |
| 186 | private static final int USER_LEAVING = 1; |
| 187 | private static final int DONT_REPORT = 2; |
| 188 | |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 189 | // Whether to invoke an activity callback after delivering new configuration. |
| 190 | private static final boolean REPORT_TO_ACTIVITY = true; |
| 191 | |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 192 | private ContextImpl mSystemContext; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 193 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 194 | static IPackageManager sPackageManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 195 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 196 | final ApplicationThread mAppThread = new ApplicationThread(); |
| 197 | final Looper mLooper = Looper.myLooper(); |
| 198 | final H mH = new H(); |
Dianne Hackborn | 782d498 | 2015-07-08 17:36:37 -0700 | [diff] [blame] | 199 | final ArrayMap<IBinder, ActivityClientRecord> mActivities = new ArrayMap<>(); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 200 | // List of new activities (via ActivityRecord.nextIdle) that should |
| 201 | // be reported when next we idle. |
| 202 | ActivityClientRecord mNewActivities = null; |
| 203 | // Number of activities that are currently visible on-screen. |
| 204 | int mNumVisibleActivities = 0; |
Dianne Hackborn | 782d498 | 2015-07-08 17:36:37 -0700 | [diff] [blame] | 205 | WeakReference<AssistStructure> mLastAssistStructure; |
| 206 | final ArrayMap<IBinder, Service> mServices = new ArrayMap<>(); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 207 | AppBindData mBoundApplication; |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 208 | Profiler mProfiler; |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 209 | int mCurDefaultDisplayDpi; |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 210 | boolean mDensityCompatMode; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 211 | Configuration mConfiguration; |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 212 | Configuration mCompatConfiguration; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 213 | Application mInitialApplication; |
| 214 | final ArrayList<Application> mAllApplications |
| 215 | = new ArrayList<Application>(); |
| 216 | // set of instantiated backup agents, keyed by package name |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 217 | final ArrayMap<String, BackupAgent> mBackupAgents = new ArrayMap<String, BackupAgent>(); |
Jeff Sharkey | 66a017b | 2013-01-17 18:18:22 -0800 | [diff] [blame] | 218 | /** Reference to singleton {@link ActivityThread} */ |
| 219 | private static ActivityThread sCurrentActivityThread; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 220 | Instrumentation mInstrumentation; |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 221 | String mInstrumentationPackageName = null; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 222 | String mInstrumentationAppDir = null; |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 223 | String[] mInstrumentationSplitAppDirs = null; |
| 224 | String mInstrumentationLibDir = null; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 225 | String mInstrumentedAppDir = null; |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 226 | String[] mInstrumentedSplitAppDirs = null; |
| 227 | String mInstrumentedLibDir = null; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 228 | boolean mSystemThread = false; |
| 229 | boolean mJitEnabled = false; |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 230 | boolean mSomeActivitiesChanged = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 231 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 232 | // These can be accessed by multiple threads; mPackages is the lock. |
| 233 | // XXX For now we keep around information about all packages we have |
| 234 | // seen, not removing entries from this map. |
Dianne Hackborn | 1fbee79 | 2011-11-30 11:29:58 -0800 | [diff] [blame] | 235 | // NOTE: The activity and window managers need to call in to |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 236 | // ActivityThread to do things like update resource configurations, |
Dianne Hackborn | 1fbee79 | 2011-11-30 11:29:58 -0800 | [diff] [blame] | 237 | // which means this lock gets held while the activity and window managers |
| 238 | // holds their own lock. Thus you MUST NEVER call back into the activity manager |
| 239 | // 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] | 240 | // 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] | 241 | final ArrayMap<String, WeakReference<LoadedApk>> mPackages |
| 242 | = new ArrayMap<String, WeakReference<LoadedApk>>(); |
| 243 | final ArrayMap<String, WeakReference<LoadedApk>> mResourcePackages |
| 244 | = new ArrayMap<String, WeakReference<LoadedApk>>(); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 245 | final ArrayList<ActivityClientRecord> mRelaunchingActivities |
| 246 | = new ArrayList<ActivityClientRecord>(); |
| 247 | Configuration mPendingConfiguration = null; |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 248 | // Because we merge activity relaunch operations we can't depend on the ordering provided by |
| 249 | // the handler messages. We need to introduce secondary ordering mechanism, which will allow |
| 250 | // us to drop certain events, if we know that they happened before relaunch we already executed. |
| 251 | // This represents the order of receiving the request from AM. |
| 252 | @GuardedBy("mResourcesManager") |
| 253 | int mLifecycleSeq = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 254 | |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 255 | private final ResourcesManager mResourcesManager; |
| 256 | |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 257 | private static final class ProviderKey { |
| 258 | final String authority; |
| 259 | final int userId; |
| 260 | |
| 261 | public ProviderKey(String authority, int userId) { |
| 262 | this.authority = authority; |
| 263 | this.userId = userId; |
| 264 | } |
| 265 | |
| 266 | @Override |
| 267 | public boolean equals(Object o) { |
| 268 | if (o instanceof ProviderKey) { |
| 269 | final ProviderKey other = (ProviderKey) o; |
Kenny Root | e6585b3 | 2013-12-13 12:00:26 -0800 | [diff] [blame] | 270 | return Objects.equals(authority, other.authority) && userId == other.userId; |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 271 | } |
| 272 | return false; |
| 273 | } |
| 274 | |
| 275 | @Override |
| 276 | public int hashCode() { |
| 277 | return ((authority != null) ? authority.hashCode() : 0) ^ userId; |
| 278 | } |
| 279 | } |
| 280 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 281 | // The lock of mProviderMap protects the following variables. |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 282 | final ArrayMap<ProviderKey, ProviderClientRecord> mProviderMap |
| 283 | = new ArrayMap<ProviderKey, ProviderClientRecord>(); |
| 284 | final ArrayMap<IBinder, ProviderRefCount> mProviderRefCountMap |
| 285 | = new ArrayMap<IBinder, ProviderRefCount>(); |
| 286 | final ArrayMap<IBinder, ProviderClientRecord> mLocalProviders |
| 287 | = new ArrayMap<IBinder, ProviderClientRecord>(); |
| 288 | final ArrayMap<ComponentName, ProviderClientRecord> mLocalProvidersByName |
| 289 | = new ArrayMap<ComponentName, ProviderClientRecord>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 290 | |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 291 | final ArrayMap<Activity, ArrayList<OnActivityPausedListener>> mOnPauseListeners |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 292 | = new ArrayMap<Activity, ArrayList<OnActivityPausedListener>>(); |
Jeff Hamilton | 52d3203 | 2011-01-08 15:31:26 -0600 | [diff] [blame] | 293 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 294 | final GcIdler mGcIdler = new GcIdler(); |
| 295 | boolean mGcIdlerScheduled = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 296 | |
Brad Fitzpatrick | 333b8cb | 2010-08-26 12:04:57 -0700 | [diff] [blame] | 297 | static Handler sMainThreadHandler; // set once in main() |
| 298 | |
Svetoslav Ganov | 9aa597e | 2011-03-03 18:17:41 -0800 | [diff] [blame] | 299 | Bundle mCoreSettings = null; |
| 300 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 301 | static final class ActivityClientRecord { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 302 | IBinder token; |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 303 | int ident; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 304 | Intent intent; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 305 | String referrer; |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 306 | IVoiceInteractor voiceInteractor; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 307 | Bundle state; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 308 | PersistableBundle persistentState; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 309 | Activity activity; |
| 310 | Window window; |
| 311 | Activity parent; |
| 312 | String embeddedID; |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 313 | Activity.NonConfigurationInstances lastNonConfigurationInstances; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 314 | boolean paused; |
| 315 | boolean stopped; |
| 316 | boolean hideForNow; |
| 317 | Configuration newConfig; |
Dianne Hackborn | e88846e | 2009-09-30 21:34:25 -0700 | [diff] [blame] | 318 | Configuration createdConfig; |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 319 | Configuration overrideConfig; |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 320 | // Used for consolidating configs before sending on to Activity. |
| 321 | private Configuration tmpConfig = new Configuration(); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 322 | ActivityClientRecord nextIdle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 323 | |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 324 | ProfilerInfo profilerInfo; |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 325 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 326 | ActivityInfo activityInfo; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 327 | CompatibilityInfo compatInfo; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 328 | LoadedApk packageInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 329 | |
| 330 | List<ResultInfo> pendingResults; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 331 | List<ReferrerIntent> pendingIntents; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 332 | |
| 333 | boolean startsNotResumed; |
| 334 | boolean isForward; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 335 | int pendingConfigChanges; |
| 336 | boolean onlyLocalRequest; |
| 337 | |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 338 | Window mPendingRemoveWindow; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 339 | WindowManager mPendingRemoveWindowManager; |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 340 | boolean mPreserveWindow; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 341 | |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 342 | // Set for relaunch requests, indicates the order number of the relaunch operation, so it |
| 343 | // can be compared with other lifecycle operations. |
| 344 | int relaunchSeq = 0; |
| 345 | |
| 346 | // Can only be accessed from the UI thread. This represents the latest processed message |
| 347 | // that is related to lifecycle events/ |
| 348 | int lastProcessedSeq = 0; |
| 349 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 350 | ActivityClientRecord() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 351 | parent = null; |
| 352 | embeddedID = null; |
| 353 | paused = false; |
| 354 | stopped = false; |
| 355 | hideForNow = false; |
| 356 | nextIdle = null; |
| 357 | } |
| 358 | |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 359 | public boolean isPreHoneycomb() { |
| 360 | if (activity != null) { |
| 361 | return activity.getApplicationInfo().targetSdkVersion |
| 362 | < android.os.Build.VERSION_CODES.HONEYCOMB; |
| 363 | } |
| 364 | return false; |
| 365 | } |
| 366 | |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 367 | public boolean isPersistable() { |
Craig Mautner | 43e52ed | 2014-06-16 17:18:52 -0700 | [diff] [blame] | 368 | return activityInfo.persistableMode == ActivityInfo.PERSIST_ACROSS_REBOOTS; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 369 | } |
| 370 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 371 | public String toString() { |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 372 | ComponentName componentName = intent != null ? intent.getComponent() : null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 373 | return "ActivityRecord{" |
| 374 | + Integer.toHexString(System.identityHashCode(this)) |
| 375 | + " token=" + token + " " + (componentName == null |
| 376 | ? "no component name" : componentName.toShortString()) |
| 377 | + "}"; |
| 378 | } |
| 379 | } |
| 380 | |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 381 | final class ProviderClientRecord { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 382 | final String[] mNames; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 383 | final IContentProvider mProvider; |
| 384 | final ContentProvider mLocalProvider; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 385 | final IActivityManager.ContentProviderHolder mHolder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 386 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 387 | ProviderClientRecord(String[] names, IContentProvider provider, |
| 388 | ContentProvider localProvider, |
| 389 | IActivityManager.ContentProviderHolder holder) { |
| 390 | mNames = names; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 391 | mProvider = provider; |
| 392 | mLocalProvider = localProvider; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 393 | mHolder = holder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 394 | } |
| 395 | } |
| 396 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 397 | static final class NewIntentData { |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 398 | List<ReferrerIntent> intents; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 399 | IBinder token; |
| 400 | public String toString() { |
| 401 | return "NewIntentData{intents=" + intents + " token=" + token + "}"; |
| 402 | } |
| 403 | } |
| 404 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 405 | static final class ReceiverData extends BroadcastReceiver.PendingResult { |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 406 | public ReceiverData(Intent intent, int resultCode, String resultData, Bundle resultExtras, |
Dianne Hackborn | 20e8098 | 2012-08-31 19:00:44 -0700 | [diff] [blame] | 407 | boolean ordered, boolean sticky, IBinder token, int sendingUser) { |
| 408 | super(resultCode, resultData, resultExtras, TYPE_COMPONENT, ordered, sticky, |
riddle_hsu | 1f5ac4d | 2015-01-03 15:38:21 +0800 | [diff] [blame] | 409 | token, sendingUser, intent.getFlags()); |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 410 | this.intent = intent; |
| 411 | } |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 412 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 413 | Intent intent; |
| 414 | ActivityInfo info; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 415 | CompatibilityInfo compatInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 416 | public String toString() { |
| 417 | return "ReceiverData{intent=" + intent + " packageName=" + |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 418 | info.packageName + " resultCode=" + getResultCode() |
| 419 | + " resultData=" + getResultData() + " resultExtras=" |
| 420 | + getResultExtras(false) + "}"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 421 | } |
| 422 | } |
| 423 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 424 | static final class CreateBackupAgentData { |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 425 | ApplicationInfo appInfo; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 426 | CompatibilityInfo compatInfo; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 427 | int backupMode; |
| 428 | public String toString() { |
| 429 | return "CreateBackupAgentData{appInfo=" + appInfo |
| 430 | + " backupAgent=" + appInfo.backupAgentName |
| 431 | + " mode=" + backupMode + "}"; |
| 432 | } |
| 433 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 434 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 435 | static final class CreateServiceData { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 436 | IBinder token; |
| 437 | ServiceInfo info; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 438 | CompatibilityInfo compatInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 439 | Intent intent; |
| 440 | public String toString() { |
| 441 | return "CreateServiceData{token=" + token + " className=" |
| 442 | + info.name + " packageName=" + info.packageName |
| 443 | + " intent=" + intent + "}"; |
| 444 | } |
| 445 | } |
| 446 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 447 | static final class BindServiceData { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 448 | IBinder token; |
| 449 | Intent intent; |
| 450 | boolean rebind; |
| 451 | public String toString() { |
| 452 | return "BindServiceData{token=" + token + " intent=" + intent + "}"; |
| 453 | } |
| 454 | } |
| 455 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 456 | static final class ServiceArgsData { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 457 | IBinder token; |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 458 | boolean taskRemoved; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 459 | int startId; |
Dianne Hackborn | f6f9f2d | 2009-08-21 16:26:03 -0700 | [diff] [blame] | 460 | int flags; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 461 | Intent args; |
| 462 | public String toString() { |
| 463 | return "ServiceArgsData{token=" + token + " startId=" + startId |
| 464 | + " args=" + args + "}"; |
| 465 | } |
| 466 | } |
| 467 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 468 | static final class AppBindData { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 469 | LoadedApk info; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 470 | String processName; |
| 471 | ApplicationInfo appInfo; |
| 472 | List<ProviderInfo> providers; |
| 473 | ComponentName instrumentationName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 474 | Bundle instrumentationArgs; |
| 475 | IInstrumentationWatcher instrumentationWatcher; |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 476 | IUiAutomationConnection instrumentationUiAutomationConnection; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 477 | int debugMode; |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 478 | boolean enableBinderTracking; |
Man Cao | cfa78b2 | 2015-06-11 20:14:34 -0700 | [diff] [blame] | 479 | boolean trackAllocation; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 480 | boolean restrictedBackupMode; |
Dianne Hackborn | 5d927c2 | 2011-09-02 12:22:18 -0700 | [diff] [blame] | 481 | boolean persistent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 482 | Configuration config; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 483 | CompatibilityInfo compatInfo; |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 484 | |
| 485 | /** Initial values for {@link Profiler}. */ |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 486 | ProfilerInfo initProfilerInfo; |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 487 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 488 | public String toString() { |
| 489 | return "AppBindData{appInfo=" + appInfo + "}"; |
| 490 | } |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | static final class Profiler { |
| 494 | String profileFile; |
| 495 | ParcelFileDescriptor profileFd; |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 496 | int samplingInterval; |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 497 | boolean autoStopProfiler; |
| 498 | boolean profiling; |
| 499 | boolean handlingProfiling; |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 500 | public void setProfiler(ProfilerInfo profilerInfo) { |
| 501 | ParcelFileDescriptor fd = profilerInfo.profileFd; |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 502 | if (profiling) { |
| 503 | if (fd != null) { |
| 504 | try { |
| 505 | fd.close(); |
| 506 | } catch (IOException e) { |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 507 | // Ignore |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 508 | } |
| 509 | } |
| 510 | return; |
| 511 | } |
| 512 | if (profileFd != null) { |
| 513 | try { |
| 514 | profileFd.close(); |
| 515 | } catch (IOException e) { |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 516 | // Ignore |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 517 | } |
| 518 | } |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 519 | profileFile = profilerInfo.profileFile; |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 520 | profileFd = fd; |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 521 | samplingInterval = profilerInfo.samplingInterval; |
| 522 | autoStopProfiler = profilerInfo.autoStopProfiler; |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 523 | } |
| 524 | public void startProfiling() { |
| 525 | if (profileFd == null || profiling) { |
| 526 | return; |
| 527 | } |
| 528 | try { |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 529 | VMDebug.startMethodTracing(profileFile, profileFd.getFileDescriptor(), |
| 530 | 8 * 1024 * 1024, 0, samplingInterval != 0, samplingInterval); |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 531 | profiling = true; |
| 532 | } catch (RuntimeException e) { |
| 533 | Slog.w(TAG, "Profiling failed on path " + profileFile); |
| 534 | try { |
| 535 | profileFd.close(); |
| 536 | profileFd = null; |
| 537 | } catch (IOException e2) { |
| 538 | Slog.w(TAG, "Failure closing profile fd", e2); |
| 539 | } |
| 540 | } |
| 541 | } |
| 542 | public void stopProfiling() { |
| 543 | if (profiling) { |
| 544 | profiling = false; |
| 545 | Debug.stopMethodTracing(); |
| 546 | if (profileFd != null) { |
| 547 | try { |
| 548 | profileFd.close(); |
| 549 | } catch (IOException e) { |
| 550 | } |
| 551 | } |
| 552 | profileFd = null; |
| 553 | profileFile = null; |
| 554 | } |
| 555 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 556 | } |
| 557 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 558 | static final class DumpComponentInfo { |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 559 | ParcelFileDescriptor fd; |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 560 | IBinder token; |
Dianne Hackborn | 30d7189 | 2010-12-11 10:37:55 -0800 | [diff] [blame] | 561 | String prefix; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 562 | String[] args; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 563 | } |
| 564 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 565 | static final class ResultData { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 566 | IBinder token; |
| 567 | List<ResultInfo> results; |
| 568 | public String toString() { |
| 569 | return "ResultData{token=" + token + " results" + results + "}"; |
| 570 | } |
| 571 | } |
| 572 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 573 | static final class ContextCleanupInfo { |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 574 | ContextImpl context; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 575 | String what; |
| 576 | String who; |
| 577 | } |
| 578 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 579 | static final class DumpHeapData { |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 580 | String path; |
| 581 | ParcelFileDescriptor fd; |
| 582 | } |
| 583 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 584 | static final class UpdateCompatibilityData { |
| 585 | String pkg; |
| 586 | CompatibilityInfo info; |
| 587 | } |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 588 | |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 589 | static final class RequestAssistContextExtras { |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 590 | IBinder activityToken; |
| 591 | IBinder requestToken; |
| 592 | int requestType; |
| 593 | } |
Anwar Ghuloum | 3a8ce1b | 2013-04-26 16:18:28 -0700 | [diff] [blame] | 594 | |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 595 | static final class ActivityConfigChangeData { |
| 596 | final IBinder activityToken; |
| 597 | final Configuration overrideConfig; |
| 598 | public ActivityConfigChangeData(IBinder token, Configuration config) { |
| 599 | activityToken = token; |
| 600 | overrideConfig = config; |
| 601 | } |
| 602 | } |
| 603 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 604 | private native void dumpGraphicsInfo(FileDescriptor fd); |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 605 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 606 | private class ApplicationThread extends ApplicationThreadNative { |
Vasu Nori | 3c7131f | 2010-09-21 14:36:57 -0700 | [diff] [blame] | 607 | private static final String DB_INFO_FORMAT = " %8s %8s %14s %14s %s"; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 608 | |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 609 | private int mLastProcessState = -1; |
| 610 | |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 611 | private void updatePendingConfiguration(Configuration config) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 612 | synchronized (mResourcesManager) { |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 613 | if (mPendingConfiguration == null || |
| 614 | mPendingConfiguration.isOtherSeqNewer(config)) { |
| 615 | mPendingConfiguration = config; |
| 616 | } |
| 617 | } |
| 618 | } |
| 619 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 620 | public final void schedulePauseActivity(IBinder token, boolean finished, |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 621 | boolean userLeaving, int configChanges, boolean dontReport) { |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 622 | int seq = getLifecycleSeq(); |
| 623 | if (DEBUG_ORDER) Slog.d(TAG, "pauseActivity " + ActivityThread.this |
| 624 | + " operation received seq: " + seq); |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 625 | sendMessage( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 626 | finished ? H.PAUSE_ACTIVITY_FINISHING : H.PAUSE_ACTIVITY, |
| 627 | token, |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 628 | (userLeaving ? USER_LEAVING : 0) | (dontReport ? DONT_REPORT : 0), |
| 629 | configChanges, |
| 630 | seq); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 631 | } |
| 632 | |
| 633 | public final void scheduleStopActivity(IBinder token, boolean showWindow, |
| 634 | int configChanges) { |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 635 | int seq = getLifecycleSeq(); |
| 636 | if (DEBUG_ORDER) Slog.d(TAG, "stopActivity " + ActivityThread.this |
| 637 | + " operation received seq: " + seq); |
| 638 | sendMessage( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 639 | showWindow ? H.STOP_ACTIVITY_SHOW : H.STOP_ACTIVITY_HIDE, |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 640 | token, 0, configChanges, seq); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 641 | } |
| 642 | |
| 643 | public final void scheduleWindowVisibility(IBinder token, boolean showWindow) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 644 | sendMessage( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 645 | showWindow ? H.SHOW_WINDOW : H.HIDE_WINDOW, |
| 646 | token); |
| 647 | } |
| 648 | |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 649 | public final void scheduleSleeping(IBinder token, boolean sleeping) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 650 | sendMessage(H.SLEEPING, token, sleeping ? 1 : 0); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 651 | } |
| 652 | |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 653 | public final void scheduleResumeActivity(IBinder token, int processState, |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 654 | boolean isForward, Bundle resumeArgs) { |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 655 | int seq = getLifecycleSeq(); |
| 656 | if (DEBUG_ORDER) Slog.d(TAG, "resumeActivity " + ActivityThread.this |
| 657 | + " operation received seq: " + seq); |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 658 | updateProcessState(processState, false); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 659 | 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] | 660 | } |
| 661 | |
| 662 | public final void scheduleSendResult(IBinder token, List<ResultInfo> results) { |
| 663 | ResultData res = new ResultData(); |
| 664 | res.token = token; |
| 665 | res.results = results; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 666 | sendMessage(H.SEND_RESULT, res); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 667 | } |
| 668 | |
| 669 | // we use token to identify this activity without having to send the |
| 670 | // activity itself back to the activity manager. (matters more with ipc) |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 671 | @Override |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 672 | public final void scheduleLaunchActivity(Intent intent, IBinder token, int ident, |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 673 | ActivityInfo info, Configuration curConfig, Configuration overrideConfig, |
| 674 | CompatibilityInfo compatInfo, String referrer, IVoiceInteractor voiceInteractor, |
| 675 | int procState, Bundle state, PersistableBundle persistentState, |
| 676 | List<ResultInfo> pendingResults, List<ReferrerIntent> pendingNewIntents, |
| 677 | boolean notResumed, boolean isForward, ProfilerInfo profilerInfo) { |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 678 | |
| 679 | updateProcessState(procState, false); |
| 680 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 681 | ActivityClientRecord r = new ActivityClientRecord(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 682 | |
| 683 | r.token = token; |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 684 | r.ident = ident; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 685 | r.intent = intent; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 686 | r.referrer = referrer; |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 687 | r.voiceInteractor = voiceInteractor; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 688 | r.activityInfo = info; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 689 | r.compatInfo = compatInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 690 | r.state = state; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 691 | r.persistentState = persistentState; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 692 | |
| 693 | r.pendingResults = pendingResults; |
| 694 | r.pendingIntents = pendingNewIntents; |
| 695 | |
| 696 | r.startsNotResumed = notResumed; |
| 697 | r.isForward = isForward; |
| 698 | |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 699 | r.profilerInfo = profilerInfo; |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 700 | |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 701 | r.overrideConfig = overrideConfig; |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 702 | updatePendingConfiguration(curConfig); |
| 703 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 704 | sendMessage(H.LAUNCH_ACTIVITY, r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 705 | } |
| 706 | |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 707 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 708 | public final void scheduleRelaunchActivity(IBinder token, |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 709 | List<ResultInfo> pendingResults, List<ReferrerIntent> pendingNewIntents, |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 710 | int configChanges, boolean notResumed, Configuration config, |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 711 | Configuration overrideConfig, boolean preserveWindow) { |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 712 | requestRelaunchActivity(token, pendingResults, pendingNewIntents, |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 713 | configChanges, notResumed, config, overrideConfig, true, preserveWindow); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 714 | } |
| 715 | |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 716 | public final void scheduleNewIntent(List<ReferrerIntent> intents, IBinder token) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 717 | NewIntentData data = new NewIntentData(); |
| 718 | data.intents = intents; |
| 719 | data.token = token; |
| 720 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 721 | sendMessage(H.NEW_INTENT, data); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 722 | } |
| 723 | |
| 724 | public final void scheduleDestroyActivity(IBinder token, boolean finishing, |
| 725 | int configChanges) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 726 | sendMessage(H.DESTROY_ACTIVITY, token, finishing ? 1 : 0, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 727 | configChanges); |
| 728 | } |
| 729 | |
| 730 | public final void scheduleReceiver(Intent intent, ActivityInfo info, |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 731 | CompatibilityInfo compatInfo, int resultCode, String data, Bundle extras, |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 732 | boolean sync, int sendingUser, int processState) { |
| 733 | updateProcessState(processState, false); |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 734 | ReceiverData r = new ReceiverData(intent, resultCode, data, extras, |
Dianne Hackborn | 20e8098 | 2012-08-31 19:00:44 -0700 | [diff] [blame] | 735 | sync, false, mAppThread.asBinder(), sendingUser); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 736 | r.info = info; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 737 | r.compatInfo = compatInfo; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 738 | sendMessage(H.RECEIVER, r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 739 | } |
| 740 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 741 | public final void scheduleCreateBackupAgent(ApplicationInfo app, |
| 742 | CompatibilityInfo compatInfo, int backupMode) { |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 743 | CreateBackupAgentData d = new CreateBackupAgentData(); |
| 744 | d.appInfo = app; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 745 | d.compatInfo = compatInfo; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 746 | d.backupMode = backupMode; |
| 747 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 748 | sendMessage(H.CREATE_BACKUP_AGENT, d); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 749 | } |
| 750 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 751 | public final void scheduleDestroyBackupAgent(ApplicationInfo app, |
| 752 | CompatibilityInfo compatInfo) { |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 753 | CreateBackupAgentData d = new CreateBackupAgentData(); |
| 754 | d.appInfo = app; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 755 | d.compatInfo = compatInfo; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 756 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 757 | sendMessage(H.DESTROY_BACKUP_AGENT, d); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 758 | } |
| 759 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 760 | public final void scheduleCreateService(IBinder token, |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 761 | ServiceInfo info, CompatibilityInfo compatInfo, int processState) { |
| 762 | updateProcessState(processState, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 763 | CreateServiceData s = new CreateServiceData(); |
| 764 | s.token = token; |
| 765 | s.info = info; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 766 | s.compatInfo = compatInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 767 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 768 | sendMessage(H.CREATE_SERVICE, s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 769 | } |
| 770 | |
| 771 | public final void scheduleBindService(IBinder token, Intent intent, |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 772 | boolean rebind, int processState) { |
| 773 | updateProcessState(processState, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 774 | BindServiceData s = new BindServiceData(); |
| 775 | s.token = token; |
| 776 | s.intent = intent; |
| 777 | s.rebind = rebind; |
| 778 | |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 779 | if (DEBUG_SERVICE) |
| 780 | Slog.v(TAG, "scheduleBindService token=" + token + " intent=" + intent + " uid=" |
| 781 | + Binder.getCallingUid() + " pid=" + Binder.getCallingPid()); |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 782 | sendMessage(H.BIND_SERVICE, s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 783 | } |
| 784 | |
| 785 | public final void scheduleUnbindService(IBinder token, Intent intent) { |
| 786 | BindServiceData s = new BindServiceData(); |
| 787 | s.token = token; |
| 788 | s.intent = intent; |
| 789 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 790 | sendMessage(H.UNBIND_SERVICE, s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 791 | } |
| 792 | |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 793 | public final void scheduleServiceArgs(IBinder token, boolean taskRemoved, int startId, |
Dianne Hackborn | f6f9f2d | 2009-08-21 16:26:03 -0700 | [diff] [blame] | 794 | int flags ,Intent args) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 795 | ServiceArgsData s = new ServiceArgsData(); |
| 796 | s.token = token; |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 797 | s.taskRemoved = taskRemoved; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 798 | s.startId = startId; |
Dianne Hackborn | f6f9f2d | 2009-08-21 16:26:03 -0700 | [diff] [blame] | 799 | s.flags = flags; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 800 | s.args = args; |
| 801 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 802 | sendMessage(H.SERVICE_ARGS, s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 803 | } |
| 804 | |
| 805 | public final void scheduleStopService(IBinder token) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 806 | sendMessage(H.STOP_SERVICE, token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 807 | } |
| 808 | |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 809 | public final void bindApplication(String processName, ApplicationInfo appInfo, |
| 810 | List<ProviderInfo> providers, ComponentName instrumentationName, |
| 811 | ProfilerInfo profilerInfo, Bundle instrumentationArgs, |
| 812 | IInstrumentationWatcher instrumentationWatcher, |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 813 | IUiAutomationConnection instrumentationUiConnection, int debugMode, |
Pablo Ceballos | a4d4e82 | 2015-10-05 10:27:52 -0700 | [diff] [blame] | 814 | boolean enableBinderTracking, boolean trackAllocation, |
| 815 | boolean isRestrictedBackupMode, boolean persistent, Configuration config, |
| 816 | CompatibilityInfo compatInfo, Map<String, IBinder> services, Bundle coreSettings) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 817 | |
| 818 | if (services != null) { |
| 819 | // Setup the service cache in the ServiceManager |
| 820 | ServiceManager.initServiceCache(services); |
| 821 | } |
| 822 | |
Svetoslav Ganov | 9aa597e | 2011-03-03 18:17:41 -0800 | [diff] [blame] | 823 | setCoreSettings(coreSettings); |
| 824 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 825 | AppBindData data = new AppBindData(); |
| 826 | data.processName = processName; |
| 827 | data.appInfo = appInfo; |
| 828 | data.providers = providers; |
| 829 | data.instrumentationName = instrumentationName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 830 | data.instrumentationArgs = instrumentationArgs; |
| 831 | data.instrumentationWatcher = instrumentationWatcher; |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 832 | data.instrumentationUiAutomationConnection = instrumentationUiConnection; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 833 | data.debugMode = debugMode; |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 834 | data.enableBinderTracking = enableBinderTracking; |
Man Cao | cfa78b2 | 2015-06-11 20:14:34 -0700 | [diff] [blame] | 835 | data.trackAllocation = trackAllocation; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 836 | data.restrictedBackupMode = isRestrictedBackupMode; |
Dianne Hackborn | 5d927c2 | 2011-09-02 12:22:18 -0700 | [diff] [blame] | 837 | data.persistent = persistent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 838 | data.config = config; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 839 | data.compatInfo = compatInfo; |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 840 | data.initProfilerInfo = profilerInfo; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 841 | sendMessage(H.BIND_APPLICATION, data); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 842 | } |
| 843 | |
| 844 | public final void scheduleExit() { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 845 | sendMessage(H.EXIT_APPLICATION, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 846 | } |
| 847 | |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 848 | public final void scheduleSuicide() { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 849 | sendMessage(H.SUICIDE, null); |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 850 | } |
| 851 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 852 | public void scheduleConfigurationChanged(Configuration config) { |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 853 | updatePendingConfiguration(config); |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 854 | sendMessage(H.CONFIGURATION_CHANGED, config); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 855 | } |
| 856 | |
| 857 | public void updateTimeZone() { |
| 858 | TimeZone.setDefault(null); |
| 859 | } |
| 860 | |
Robert Greenwalt | 03595d0 | 2010-11-02 14:08:23 -0700 | [diff] [blame] | 861 | public void clearDnsCache() { |
| 862 | // a non-standard API to get this to libcore |
| 863 | InetAddress.clearDnsCache(); |
Paul Jensen | e401d17 | 2014-09-12 10:47:39 -0400 | [diff] [blame] | 864 | // Allow libcore to perform the necessary actions as it sees fit upon a network |
| 865 | // configuration change. |
| 866 | NetworkEventDispatcher.getInstance().onNetworkConfigurationChanged(); |
Robert Greenwalt | 03595d0 | 2010-11-02 14:08:23 -0700 | [diff] [blame] | 867 | } |
| 868 | |
Jason Monk | 83520b9 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 869 | public void setHttpProxy(String host, String port, String exclList, Uri pacFileUrl) { |
Paul Jensen | 72db88e | 2015-03-10 10:54:12 -0400 | [diff] [blame] | 870 | final ConnectivityManager cm = ConnectivityManager.from(getSystemContext()); |
| 871 | final Network network = cm.getBoundNetworkForProcess(); |
Paul Jensen | e0bef71 | 2014-12-10 15:12:18 -0500 | [diff] [blame] | 872 | if (network != null) { |
Paul Jensen | 72db88e | 2015-03-10 10:54:12 -0400 | [diff] [blame] | 873 | Proxy.setHttpProxySystemProperty(cm.getDefaultProxy()); |
Paul Jensen | e0bef71 | 2014-12-10 15:12:18 -0500 | [diff] [blame] | 874 | } else { |
| 875 | Proxy.setHttpProxySystemProperty(host, port, exclList, pacFileUrl); |
| 876 | } |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 877 | } |
| 878 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 879 | public void processInBackground() { |
| 880 | mH.removeMessages(H.GC_WHEN_IDLE); |
| 881 | mH.sendMessage(mH.obtainMessage(H.GC_WHEN_IDLE)); |
| 882 | } |
| 883 | |
| 884 | public void dumpService(FileDescriptor fd, IBinder servicetoken, String[] args) { |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 885 | DumpComponentInfo data = new DumpComponentInfo(); |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 886 | try { |
| 887 | data.fd = ParcelFileDescriptor.dup(fd); |
| 888 | data.token = servicetoken; |
| 889 | data.args = args; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 890 | sendMessage(H.DUMP_SERVICE, data, 0, 0, true /*async*/); |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 891 | } catch (IOException e) { |
| 892 | Slog.w(TAG, "dumpService failed", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 893 | } |
| 894 | } |
| 895 | |
| 896 | // This function exists to make sure all receiver dispatching is |
| 897 | // correctly ordered, since these are one-way calls and the binder driver |
| 898 | // applies transaction ordering per object for such calls. |
| 899 | public void scheduleRegisteredReceiver(IIntentReceiver receiver, Intent intent, |
Dianne Hackborn | 68d881c | 2009-10-05 13:58:17 -0700 | [diff] [blame] | 900 | int resultCode, String dataStr, Bundle extras, boolean ordered, |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 901 | boolean sticky, int sendingUser, int processState) throws RemoteException { |
| 902 | updateProcessState(processState, false); |
Dianne Hackborn | 20e8098 | 2012-08-31 19:00:44 -0700 | [diff] [blame] | 903 | receiver.performReceive(intent, resultCode, dataStr, extras, ordered, |
| 904 | sticky, sendingUser); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 905 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 906 | |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 907 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 908 | public void scheduleLowMemory() { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 909 | sendMessage(H.LOW_MEMORY, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 910 | } |
| 911 | |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 912 | @Override |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 913 | public void scheduleActivityConfigurationChanged( |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 914 | IBinder token, Configuration overrideConfig, boolean reportToActivity) { |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 915 | sendMessage(H.ACTIVITY_CONFIGURATION_CHANGED, |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 916 | new ActivityConfigChangeData(token, overrideConfig), reportToActivity ? 1 : 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 917 | } |
| 918 | |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 919 | @Override |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 920 | public void profilerControl(boolean start, ProfilerInfo profilerInfo, int profileType) { |
| 921 | sendMessage(H.PROFILER_CONTROL, profilerInfo, start ? 1 : 0, profileType); |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 922 | } |
| 923 | |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 924 | public void dumpHeap(boolean managed, String path, ParcelFileDescriptor fd) { |
| 925 | DumpHeapData dhd = new DumpHeapData(); |
| 926 | dhd.path = path; |
| 927 | dhd.fd = fd; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 928 | sendMessage(H.DUMP_HEAP, dhd, managed ? 1 : 0, 0, true /*async*/); |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 929 | } |
| 930 | |
Dianne Hackborn | 06de2ea | 2009-05-21 12:56:43 -0700 | [diff] [blame] | 931 | public void setSchedulingGroup(int group) { |
| 932 | // Note: do this immediately, since going into the foreground |
| 933 | // should happen regardless of what pending work we have to do |
| 934 | // and the activity manager will wait for us to report back that |
| 935 | // we are done before sending us to the background. |
| 936 | try { |
| 937 | Process.setProcessGroup(Process.myPid(), group); |
| 938 | } catch (Exception e) { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 939 | Slog.w(TAG, "Failed setting process group to " + group, e); |
Dianne Hackborn | 06de2ea | 2009-05-21 12:56:43 -0700 | [diff] [blame] | 940 | } |
| 941 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 942 | |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 943 | public void dispatchPackageBroadcast(int cmd, String[] packages) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 944 | sendMessage(H.DISPATCH_PACKAGE_BROADCAST, packages, cmd); |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 945 | } |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 946 | |
| 947 | public void scheduleCrash(String msg) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 948 | sendMessage(H.SCHEDULE_CRASH, msg); |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 949 | } |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 950 | |
Dianne Hackborn | 30d7189 | 2010-12-11 10:37:55 -0800 | [diff] [blame] | 951 | public void dumpActivity(FileDescriptor fd, IBinder activitytoken, |
| 952 | String prefix, String[] args) { |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 953 | DumpComponentInfo data = new DumpComponentInfo(); |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 954 | try { |
| 955 | data.fd = ParcelFileDescriptor.dup(fd); |
| 956 | data.token = activitytoken; |
| 957 | data.prefix = prefix; |
| 958 | data.args = args; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 959 | sendMessage(H.DUMP_ACTIVITY, data, 0, 0, true /*async*/); |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 960 | } catch (IOException e) { |
| 961 | Slog.w(TAG, "dumpActivity failed", e); |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 962 | } |
| 963 | } |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 964 | |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 965 | public void dumpProvider(FileDescriptor fd, IBinder providertoken, |
| 966 | String[] args) { |
| 967 | DumpComponentInfo data = new DumpComponentInfo(); |
| 968 | try { |
| 969 | data.fd = ParcelFileDescriptor.dup(fd); |
| 970 | data.token = providertoken; |
| 971 | data.args = args; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 972 | sendMessage(H.DUMP_PROVIDER, data, 0, 0, true /*async*/); |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 973 | } catch (IOException e) { |
| 974 | Slog.w(TAG, "dumpProvider failed", e); |
| 975 | } |
| 976 | } |
| 977 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 978 | @Override |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 979 | public void dumpMemInfo(FileDescriptor fd, Debug.MemoryInfo mem, boolean checkin, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 980 | boolean dumpFullInfo, boolean dumpDalvik, boolean dumpSummaryOnly, String[] args) { |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 981 | FileOutputStream fout = new FileOutputStream(fd); |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 982 | PrintWriter pw = new FastPrintWriter(fout); |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 983 | try { |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 984 | dumpMemInfo(pw, mem, checkin, dumpFullInfo, dumpDalvik, dumpSummaryOnly); |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 985 | } finally { |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 986 | pw.flush(); |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 987 | } |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 988 | } |
| 989 | |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 990 | private void dumpMemInfo(PrintWriter pw, Debug.MemoryInfo memInfo, boolean checkin, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 991 | boolean dumpFullInfo, boolean dumpDalvik, boolean dumpSummaryOnly) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 992 | long nativeMax = Debug.getNativeHeapSize() / 1024; |
| 993 | long nativeAllocated = Debug.getNativeHeapAllocatedSize() / 1024; |
| 994 | long nativeFree = Debug.getNativeHeapFreeSize() / 1024; |
| 995 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 996 | Runtime runtime = Runtime.getRuntime(); |
Mathieu Chartier | d288a26 | 2015-07-10 13:44:42 -0700 | [diff] [blame] | 997 | runtime.gc(); // Do GC since countInstancesOfClass counts unreachable objects. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 998 | long dalvikMax = runtime.totalMemory() / 1024; |
| 999 | long dalvikFree = runtime.freeMemory() / 1024; |
| 1000 | long dalvikAllocated = dalvikMax - dalvikFree; |
| 1001 | long viewInstanceCount = ViewDebug.getViewInstanceCount(); |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1002 | long viewRootInstanceCount = ViewDebug.getViewRootImplCount(); |
Brian Carlstrom | c21550a | 2010-10-05 21:34:06 -0700 | [diff] [blame] | 1003 | long appContextInstanceCount = Debug.countInstancesOfClass(ContextImpl.class); |
| 1004 | long activityInstanceCount = Debug.countInstancesOfClass(Activity.class); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1005 | int globalAssetCount = AssetManager.getGlobalAssetCount(); |
| 1006 | int globalAssetManagerCount = AssetManager.getGlobalAssetManagerCount(); |
| 1007 | int binderLocalObjectCount = Debug.getBinderLocalObjectCount(); |
| 1008 | int binderProxyObjectCount = Debug.getBinderProxyObjectCount(); |
| 1009 | int binderDeathObjectCount = Debug.getBinderDeathObjectCount(); |
Dianne Hackborn | fabb70b | 2014-11-11 12:22:36 -0800 | [diff] [blame] | 1010 | long parcelSize = Parcel.getGlobalAllocSize(); |
| 1011 | long parcelCount = Parcel.getGlobalAllocCount(); |
Brian Carlstrom | c9d5b31 | 2010-10-05 22:23:41 -0700 | [diff] [blame] | 1012 | long openSslSocketCount = Debug.countInstancesOfClass(OpenSSLSocketImpl.class); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1013 | SQLiteDebug.PagerStats stats = SQLiteDebug.getDatabaseInfo(); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1014 | |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 1015 | dumpMemInfoTable(pw, memInfo, checkin, dumpFullInfo, dumpDalvik, dumpSummaryOnly, |
| 1016 | Process.myPid(), |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 1017 | (mBoundApplication != null) ? mBoundApplication.processName : "unknown", |
| 1018 | nativeMax, nativeAllocated, nativeFree, |
| 1019 | dalvikMax, dalvikAllocated, dalvikFree); |
| 1020 | |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 1021 | if (checkin) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1022 | // NOTE: if you change anything significant below, also consider changing |
| 1023 | // ACTIVITY_THREAD_CHECKIN_VERSION. |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 1024 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1025 | // Object counts |
| 1026 | pw.print(viewInstanceCount); pw.print(','); |
| 1027 | pw.print(viewRootInstanceCount); pw.print(','); |
| 1028 | pw.print(appContextInstanceCount); pw.print(','); |
| 1029 | pw.print(activityInstanceCount); pw.print(','); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1030 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1031 | pw.print(globalAssetCount); pw.print(','); |
| 1032 | pw.print(globalAssetManagerCount); pw.print(','); |
| 1033 | pw.print(binderLocalObjectCount); pw.print(','); |
| 1034 | pw.print(binderProxyObjectCount); pw.print(','); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1035 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1036 | pw.print(binderDeathObjectCount); pw.print(','); |
| 1037 | pw.print(openSslSocketCount); pw.print(','); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1038 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1039 | // SQL |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1040 | pw.print(stats.memoryUsed / 1024); pw.print(','); |
Jeff Brown | 2a293b6 | 2012-01-19 14:02:22 -0800 | [diff] [blame] | 1041 | pw.print(stats.memoryUsed / 1024); pw.print(','); |
| 1042 | pw.print(stats.pageCacheOverflow / 1024); pw.print(','); |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 1043 | pw.print(stats.largestMemAlloc / 1024); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1044 | for (int i = 0; i < stats.dbStats.size(); i++) { |
| 1045 | DbStats dbStats = stats.dbStats.get(i); |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 1046 | pw.print(','); pw.print(dbStats.dbName); |
| 1047 | pw.print(','); pw.print(dbStats.pageSize); |
| 1048 | pw.print(','); pw.print(dbStats.dbSize); |
| 1049 | pw.print(','); pw.print(dbStats.lookaside); |
| 1050 | pw.print(','); pw.print(dbStats.cache); |
| 1051 | pw.print(','); pw.print(dbStats.cache); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1052 | } |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 1053 | pw.println(); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1054 | |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 1055 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1056 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1057 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1058 | pw.println(" "); |
| 1059 | pw.println(" Objects"); |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1060 | printRow(pw, TWO_COUNT_COLUMNS, "Views:", viewInstanceCount, "ViewRootImpl:", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1061 | viewRootInstanceCount); |
| 1062 | |
| 1063 | printRow(pw, TWO_COUNT_COLUMNS, "AppContexts:", appContextInstanceCount, |
| 1064 | "Activities:", activityInstanceCount); |
| 1065 | |
| 1066 | printRow(pw, TWO_COUNT_COLUMNS, "Assets:", globalAssetCount, |
| 1067 | "AssetManagers:", globalAssetManagerCount); |
| 1068 | |
| 1069 | printRow(pw, TWO_COUNT_COLUMNS, "Local Binders:", binderLocalObjectCount, |
| 1070 | "Proxy Binders:", binderProxyObjectCount); |
Dianne Hackborn | fabb70b | 2014-11-11 12:22:36 -0800 | [diff] [blame] | 1071 | printRow(pw, TWO_COUNT_COLUMNS, "Parcel memory:", parcelSize/1024, |
| 1072 | "Parcel count:", parcelCount); |
| 1073 | printRow(pw, TWO_COUNT_COLUMNS, "Death Recipients:", binderDeathObjectCount, |
| 1074 | "OpenSSL Sockets:", openSslSocketCount); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1075 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1076 | // SQLite mem info |
| 1077 | pw.println(" "); |
| 1078 | pw.println(" SQL"); |
Jeff Brown | 2a293b6 | 2012-01-19 14:02:22 -0800 | [diff] [blame] | 1079 | printRow(pw, ONE_COUNT_COLUMN, "MEMORY_USED:", stats.memoryUsed / 1024); |
| 1080 | printRow(pw, TWO_COUNT_COLUMNS, "PAGECACHE_OVERFLOW:", |
| 1081 | stats.pageCacheOverflow / 1024, "MALLOC_SIZE:", stats.largestMemAlloc / 1024); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1082 | pw.println(" "); |
| 1083 | int N = stats.dbStats.size(); |
| 1084 | if (N > 0) { |
| 1085 | pw.println(" DATABASES"); |
Vasu Nori | 3c7131f | 2010-09-21 14:36:57 -0700 | [diff] [blame] | 1086 | printRow(pw, " %8s %8s %14s %14s %s", "pgsz", "dbsz", "Lookaside(b)", "cache", |
| 1087 | "Dbname"); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1088 | for (int i = 0; i < N; i++) { |
| 1089 | DbStats dbStats = stats.dbStats.get(i); |
Vasu Nori | 3c7131f | 2010-09-21 14:36:57 -0700 | [diff] [blame] | 1090 | printRow(pw, DB_INFO_FORMAT, |
| 1091 | (dbStats.pageSize > 0) ? String.valueOf(dbStats.pageSize) : " ", |
| 1092 | (dbStats.dbSize > 0) ? String.valueOf(dbStats.dbSize) : " ", |
| 1093 | (dbStats.lookaside > 0) ? String.valueOf(dbStats.lookaside) : " ", |
| 1094 | dbStats.cache, dbStats.dbName); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 1095 | } |
| 1096 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1097 | |
Dianne Hackborn | 82e1ee9 | 2009-08-11 18:56:41 -0700 | [diff] [blame] | 1098 | // Asset details. |
| 1099 | String assetAlloc = AssetManager.getAssetAllocations(); |
| 1100 | if (assetAlloc != null) { |
| 1101 | pw.println(" "); |
| 1102 | pw.println(" Asset Allocations"); |
| 1103 | pw.print(assetAlloc); |
| 1104 | } |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 1105 | } |
| 1106 | |
| 1107 | @Override |
| 1108 | public void dumpGfxInfo(FileDescriptor fd, String[] args) { |
| 1109 | dumpGraphicsInfo(fd); |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 1110 | WindowManagerGlobal.getInstance().dumpGfxInfo(fd, args); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1111 | } |
| 1112 | |
riddle_hsu | 1d6c40a | 2014-07-31 00:18:00 +0800 | [diff] [blame] | 1113 | private void dumpDatabaseInfo(FileDescriptor fd, String[] args) { |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 1114 | PrintWriter pw = new FastPrintWriter(new FileOutputStream(fd)); |
Jeff Brown | 6754ba2 | 2011-12-14 20:20:01 -0800 | [diff] [blame] | 1115 | PrintWriterPrinter printer = new PrintWriterPrinter(pw); |
| 1116 | SQLiteDebug.dump(printer, args); |
| 1117 | pw.flush(); |
| 1118 | } |
| 1119 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1120 | @Override |
riddle_hsu | 1d6c40a | 2014-07-31 00:18:00 +0800 | [diff] [blame] | 1121 | public void dumpDbInfo(final FileDescriptor fd, final String[] args) { |
| 1122 | if (mSystemThread) { |
| 1123 | // Ensure this invocation is asynchronous to prevent |
| 1124 | // writer waiting due to buffer cannot be consumed. |
| 1125 | AsyncTask.THREAD_POOL_EXECUTOR.execute(new Runnable() { |
| 1126 | @Override |
| 1127 | public void run() { |
| 1128 | dumpDatabaseInfo(fd, args); |
| 1129 | } |
| 1130 | }); |
| 1131 | } else { |
| 1132 | dumpDatabaseInfo(fd, args); |
| 1133 | } |
| 1134 | } |
| 1135 | |
| 1136 | @Override |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1137 | public void unstableProviderDied(IBinder provider) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1138 | sendMessage(H.UNSTABLE_PROVIDER_DIED, provider); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1139 | } |
| 1140 | |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 1141 | @Override |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 1142 | public void requestAssistContextExtras(IBinder activityToken, IBinder requestToken, |
Adam Skory | 7140a25 | 2013-09-11 12:04:58 +0100 | [diff] [blame] | 1143 | int requestType) { |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 1144 | RequestAssistContextExtras cmd = new RequestAssistContextExtras(); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 1145 | cmd.activityToken = activityToken; |
| 1146 | cmd.requestToken = requestToken; |
| 1147 | cmd.requestType = requestType; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1148 | sendMessage(H.REQUEST_ASSIST_CONTEXT_EXTRAS, cmd); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 1149 | } |
| 1150 | |
Svetoslav Ganov | 9aa597e | 2011-03-03 18:17:41 -0800 | [diff] [blame] | 1151 | public void setCoreSettings(Bundle coreSettings) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1152 | sendMessage(H.SET_CORE_SETTINGS, coreSettings); |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1153 | } |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1154 | |
| 1155 | public void updatePackageCompatibilityInfo(String pkg, CompatibilityInfo info) { |
| 1156 | UpdateCompatibilityData ucd = new UpdateCompatibilityData(); |
| 1157 | ucd.pkg = pkg; |
| 1158 | ucd.info = info; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1159 | sendMessage(H.UPDATE_PACKAGE_COMPATIBILITY_INFO, ucd); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1160 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1161 | |
| 1162 | public void scheduleTrimMemory(int level) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1163 | sendMessage(H.TRIM_MEMORY, null, level); |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1164 | } |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1165 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1166 | public void scheduleTranslucentConversionComplete(IBinder token, boolean drawComplete) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1167 | sendMessage(H.TRANSLUCENT_CONVERSION_COMPLETE, token, drawComplete ? 1 : 0); |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1168 | } |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 1169 | |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1170 | public void scheduleOnNewActivityOptions(IBinder token, ActivityOptions options) { |
| 1171 | sendMessage(H.ON_NEW_ACTIVITY_OPTIONS, |
| 1172 | new Pair<IBinder, ActivityOptions>(token, options)); |
| 1173 | } |
| 1174 | |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 1175 | public void setProcessState(int state) { |
| 1176 | updateProcessState(state, true); |
| 1177 | } |
| 1178 | |
| 1179 | public void updateProcessState(int processState, boolean fromIpc) { |
| 1180 | synchronized (this) { |
| 1181 | if (mLastProcessState != processState) { |
| 1182 | mLastProcessState = processState; |
Mathieu Chartier | 1e37090 | 2013-07-18 10:58:01 -0700 | [diff] [blame] | 1183 | // Update Dalvik state based on ActivityManager.PROCESS_STATE_* constants. |
| 1184 | final int DALVIK_PROCESS_STATE_JANK_PERCEPTIBLE = 0; |
| 1185 | final int DALVIK_PROCESS_STATE_JANK_IMPERCEPTIBLE = 1; |
| 1186 | int dalvikProcessState = DALVIK_PROCESS_STATE_JANK_IMPERCEPTIBLE; |
| 1187 | // TODO: Tune this since things like gmail sync are important background but not jank perceptible. |
| 1188 | if (processState <= ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND) { |
| 1189 | dalvikProcessState = DALVIK_PROCESS_STATE_JANK_PERCEPTIBLE; |
| 1190 | } |
| 1191 | VMRuntime.getRuntime().updateProcessState(dalvikProcessState); |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 1192 | if (false) { |
| 1193 | Slog.i(TAG, "******************* PROCESS STATE CHANGED TO: " + processState |
| 1194 | + (fromIpc ? " (from ipc": "")); |
| 1195 | } |
| 1196 | } |
| 1197 | } |
| 1198 | } |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 1199 | |
| 1200 | @Override |
| 1201 | public void scheduleInstallProvider(ProviderInfo provider) { |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 1202 | sendMessage(H.INSTALL_PROVIDER, provider); |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 1203 | } |
Narayan Kamath | ccb2a086 | 2013-12-19 14:49:36 +0000 | [diff] [blame] | 1204 | |
| 1205 | @Override |
| 1206 | public final void updateTimePrefs(boolean is24Hour) { |
| 1207 | DateFormat.set24HourTimePref(is24Hour); |
| 1208 | } |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 1209 | |
| 1210 | @Override |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 1211 | public void scheduleCancelVisibleBehind(IBinder token) { |
| 1212 | sendMessage(H.CANCEL_VISIBLE_BEHIND, token); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 1213 | } |
| 1214 | |
| 1215 | @Override |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 1216 | public void scheduleBackgroundVisibleBehindChanged(IBinder token, boolean visible) { |
| 1217 | sendMessage(H.BACKGROUND_VISIBLE_BEHIND_CHANGED, token, visible ? 1 : 0); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 1218 | } |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 1219 | |
Jeff Sharkey | 605eb79 | 2014-11-04 13:34:06 -0800 | [diff] [blame] | 1220 | @Override |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 1221 | public void scheduleEnterAnimationComplete(IBinder token) { |
| 1222 | sendMessage(H.ENTER_ANIMATION_COMPLETE, token); |
| 1223 | } |
Jeff Sharkey | 605eb79 | 2014-11-04 13:34:06 -0800 | [diff] [blame] | 1224 | |
| 1225 | @Override |
| 1226 | public void notifyCleartextNetwork(byte[] firstPacket) { |
| 1227 | if (StrictMode.vmCleartextNetworkEnabled()) { |
| 1228 | StrictMode.onCleartextNetworkDetected(firstPacket); |
| 1229 | } |
| 1230 | } |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 1231 | |
| 1232 | @Override |
| 1233 | public void startBinderTracking() { |
| 1234 | sendMessage(H.START_BINDER_TRACKING, null); |
| 1235 | } |
| 1236 | |
| 1237 | @Override |
| 1238 | public void stopBinderTrackingAndDump(FileDescriptor fd) { |
| 1239 | try { |
| 1240 | sendMessage(H.STOP_BINDER_TRACKING_AND_DUMP, ParcelFileDescriptor.dup(fd)); |
| 1241 | } catch (IOException e) { |
| 1242 | } |
| 1243 | } |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 1244 | |
| 1245 | @Override |
Wale Ogunwale | 3b93a4d | 2016-01-29 17:46:53 -0800 | [diff] [blame] | 1246 | public void scheduleMultiWindowChanged(IBinder token, boolean inMultiWindow) |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 1247 | throws RemoteException { |
Wale Ogunwale | 3b93a4d | 2016-01-29 17:46:53 -0800 | [diff] [blame] | 1248 | sendMessage(H.MULTI_WINDOW_CHANGED, token, inMultiWindow ? 1 : 0); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 1249 | } |
| 1250 | |
| 1251 | @Override |
Wale Ogunwale | 3b93a4d | 2016-01-29 17:46:53 -0800 | [diff] [blame] | 1252 | public void schedulePictureInPictureChanged(IBinder token, boolean inPip) |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 1253 | throws RemoteException { |
Wale Ogunwale | 3b93a4d | 2016-01-29 17:46:53 -0800 | [diff] [blame] | 1254 | sendMessage(H.PICTURE_IN_PICTURE_CHANGED, token, inPip ? 1 : 0); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 1255 | } |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1256 | |
| 1257 | @Override |
| 1258 | public void scheduleLocalVoiceInteractionStarted(IBinder token, |
| 1259 | IVoiceInteractor voiceInteractor) throws RemoteException { |
| 1260 | SomeArgs args = SomeArgs.obtain(); |
| 1261 | args.arg1 = token; |
| 1262 | args.arg2 = voiceInteractor; |
| 1263 | sendMessage(H.LOCAL_VOICE_INTERACTION_STARTED, args); |
| 1264 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1265 | } |
| 1266 | |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1267 | private int getLifecycleSeq() { |
| 1268 | synchronized (mResourcesManager) { |
| 1269 | return mLifecycleSeq++; |
| 1270 | } |
| 1271 | } |
| 1272 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1273 | private class H extends Handler { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1274 | public static final int LAUNCH_ACTIVITY = 100; |
| 1275 | public static final int PAUSE_ACTIVITY = 101; |
| 1276 | public static final int PAUSE_ACTIVITY_FINISHING= 102; |
| 1277 | public static final int STOP_ACTIVITY_SHOW = 103; |
| 1278 | public static final int STOP_ACTIVITY_HIDE = 104; |
| 1279 | public static final int SHOW_WINDOW = 105; |
| 1280 | public static final int HIDE_WINDOW = 106; |
| 1281 | public static final int RESUME_ACTIVITY = 107; |
| 1282 | public static final int SEND_RESULT = 108; |
Brian Carlstrom | ed7e007 | 2011-03-24 13:27:57 -0700 | [diff] [blame] | 1283 | public static final int DESTROY_ACTIVITY = 109; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1284 | public static final int BIND_APPLICATION = 110; |
| 1285 | public static final int EXIT_APPLICATION = 111; |
| 1286 | public static final int NEW_INTENT = 112; |
| 1287 | public static final int RECEIVER = 113; |
| 1288 | public static final int CREATE_SERVICE = 114; |
| 1289 | public static final int SERVICE_ARGS = 115; |
| 1290 | public static final int STOP_SERVICE = 116; |
Dianne Hackborn | 0923328 | 2014-04-30 11:33:59 -0700 | [diff] [blame] | 1291 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1292 | public static final int CONFIGURATION_CHANGED = 118; |
| 1293 | public static final int CLEAN_UP_CONTEXT = 119; |
| 1294 | public static final int GC_WHEN_IDLE = 120; |
| 1295 | public static final int BIND_SERVICE = 121; |
| 1296 | public static final int UNBIND_SERVICE = 122; |
| 1297 | public static final int DUMP_SERVICE = 123; |
| 1298 | public static final int LOW_MEMORY = 124; |
| 1299 | public static final int ACTIVITY_CONFIGURATION_CHANGED = 125; |
| 1300 | public static final int RELAUNCH_ACTIVITY = 126; |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 1301 | public static final int PROFILER_CONTROL = 127; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1302 | public static final int CREATE_BACKUP_AGENT = 128; |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 1303 | public static final int DESTROY_BACKUP_AGENT = 129; |
| 1304 | public static final int SUICIDE = 130; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1305 | public static final int REMOVE_PROVIDER = 131; |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 1306 | public static final int ENABLE_JIT = 132; |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1307 | public static final int DISPATCH_PACKAGE_BROADCAST = 133; |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 1308 | public static final int SCHEDULE_CRASH = 134; |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 1309 | public static final int DUMP_HEAP = 135; |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1310 | public static final int DUMP_ACTIVITY = 136; |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1311 | public static final int SLEEPING = 137; |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1312 | public static final int SET_CORE_SETTINGS = 138; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1313 | public static final int UPDATE_PACKAGE_COMPATIBILITY_INFO = 139; |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1314 | public static final int TRIM_MEMORY = 140; |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1315 | public static final int DUMP_PROVIDER = 141; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1316 | public static final int UNSTABLE_PROVIDER_DIED = 142; |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 1317 | public static final int REQUEST_ASSIST_CONTEXT_EXTRAS = 143; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1318 | public static final int TRANSLUCENT_CONVERSION_COMPLETE = 144; |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 1319 | public static final int INSTALL_PROVIDER = 145; |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1320 | public static final int ON_NEW_ACTIVITY_OPTIONS = 146; |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 1321 | public static final int CANCEL_VISIBLE_BEHIND = 147; |
| 1322 | public static final int BACKGROUND_VISIBLE_BEHIND_CHANGED = 148; |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 1323 | public static final int ENTER_ANIMATION_COMPLETE = 149; |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 1324 | public static final int START_BINDER_TRACKING = 150; |
| 1325 | public static final int STOP_BINDER_TRACKING_AND_DUMP = 151; |
Wale Ogunwale | 3b93a4d | 2016-01-29 17:46:53 -0800 | [diff] [blame] | 1326 | public static final int MULTI_WINDOW_CHANGED = 152; |
| 1327 | public static final int PICTURE_IN_PICTURE_CHANGED = 153; |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1328 | public static final int LOCAL_VOICE_INTERACTION_STARTED = 154; |
Narayan Kamath | ccb2a086 | 2013-12-19 14:49:36 +0000 | [diff] [blame] | 1329 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1330 | String codeToString(int code) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 1331 | if (DEBUG_MESSAGES) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1332 | switch (code) { |
| 1333 | case LAUNCH_ACTIVITY: return "LAUNCH_ACTIVITY"; |
| 1334 | case PAUSE_ACTIVITY: return "PAUSE_ACTIVITY"; |
| 1335 | case PAUSE_ACTIVITY_FINISHING: return "PAUSE_ACTIVITY_FINISHING"; |
| 1336 | case STOP_ACTIVITY_SHOW: return "STOP_ACTIVITY_SHOW"; |
| 1337 | case STOP_ACTIVITY_HIDE: return "STOP_ACTIVITY_HIDE"; |
| 1338 | case SHOW_WINDOW: return "SHOW_WINDOW"; |
| 1339 | case HIDE_WINDOW: return "HIDE_WINDOW"; |
| 1340 | case RESUME_ACTIVITY: return "RESUME_ACTIVITY"; |
| 1341 | case SEND_RESULT: return "SEND_RESULT"; |
| 1342 | case DESTROY_ACTIVITY: return "DESTROY_ACTIVITY"; |
| 1343 | case BIND_APPLICATION: return "BIND_APPLICATION"; |
| 1344 | case EXIT_APPLICATION: return "EXIT_APPLICATION"; |
| 1345 | case NEW_INTENT: return "NEW_INTENT"; |
| 1346 | case RECEIVER: return "RECEIVER"; |
| 1347 | case CREATE_SERVICE: return "CREATE_SERVICE"; |
| 1348 | case SERVICE_ARGS: return "SERVICE_ARGS"; |
| 1349 | case STOP_SERVICE: return "STOP_SERVICE"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1350 | case CONFIGURATION_CHANGED: return "CONFIGURATION_CHANGED"; |
| 1351 | case CLEAN_UP_CONTEXT: return "CLEAN_UP_CONTEXT"; |
| 1352 | case GC_WHEN_IDLE: return "GC_WHEN_IDLE"; |
| 1353 | case BIND_SERVICE: return "BIND_SERVICE"; |
| 1354 | case UNBIND_SERVICE: return "UNBIND_SERVICE"; |
| 1355 | case DUMP_SERVICE: return "DUMP_SERVICE"; |
| 1356 | case LOW_MEMORY: return "LOW_MEMORY"; |
| 1357 | case ACTIVITY_CONFIGURATION_CHANGED: return "ACTIVITY_CONFIGURATION_CHANGED"; |
| 1358 | case RELAUNCH_ACTIVITY: return "RELAUNCH_ACTIVITY"; |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 1359 | case PROFILER_CONTROL: return "PROFILER_CONTROL"; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1360 | case CREATE_BACKUP_AGENT: return "CREATE_BACKUP_AGENT"; |
| 1361 | case DESTROY_BACKUP_AGENT: return "DESTROY_BACKUP_AGENT"; |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 1362 | case SUICIDE: return "SUICIDE"; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1363 | case REMOVE_PROVIDER: return "REMOVE_PROVIDER"; |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 1364 | case ENABLE_JIT: return "ENABLE_JIT"; |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1365 | case DISPATCH_PACKAGE_BROADCAST: return "DISPATCH_PACKAGE_BROADCAST"; |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 1366 | case SCHEDULE_CRASH: return "SCHEDULE_CRASH"; |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 1367 | case DUMP_HEAP: return "DUMP_HEAP"; |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1368 | case DUMP_ACTIVITY: return "DUMP_ACTIVITY"; |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1369 | case SLEEPING: return "SLEEPING"; |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1370 | case SET_CORE_SETTINGS: return "SET_CORE_SETTINGS"; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1371 | case UPDATE_PACKAGE_COMPATIBILITY_INFO: return "UPDATE_PACKAGE_COMPATIBILITY_INFO"; |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1372 | case TRIM_MEMORY: return "TRIM_MEMORY"; |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1373 | case DUMP_PROVIDER: return "DUMP_PROVIDER"; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1374 | case UNSTABLE_PROVIDER_DIED: return "UNSTABLE_PROVIDER_DIED"; |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 1375 | case REQUEST_ASSIST_CONTEXT_EXTRAS: return "REQUEST_ASSIST_CONTEXT_EXTRAS"; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1376 | case TRANSLUCENT_CONVERSION_COMPLETE: return "TRANSLUCENT_CONVERSION_COMPLETE"; |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 1377 | case INSTALL_PROVIDER: return "INSTALL_PROVIDER"; |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1378 | case ON_NEW_ACTIVITY_OPTIONS: return "ON_NEW_ACTIVITY_OPTIONS"; |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 1379 | case CANCEL_VISIBLE_BEHIND: return "CANCEL_VISIBLE_BEHIND"; |
| 1380 | case BACKGROUND_VISIBLE_BEHIND_CHANGED: return "BACKGROUND_VISIBLE_BEHIND_CHANGED"; |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 1381 | case ENTER_ANIMATION_COMPLETE: return "ENTER_ANIMATION_COMPLETE"; |
Wale Ogunwale | 3b93a4d | 2016-01-29 17:46:53 -0800 | [diff] [blame] | 1382 | case MULTI_WINDOW_CHANGED: return "MULTI_WINDOW_CHANGED"; |
| 1383 | case PICTURE_IN_PICTURE_CHANGED: return "PICTURE_IN_PICTURE_CHANGED"; |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1384 | 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] | 1385 | } |
| 1386 | } |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 1387 | return Integer.toString(code); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1388 | } |
| 1389 | public void handleMessage(Message msg) { |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 1390 | 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] | 1391 | switch (msg.what) { |
| 1392 | case LAUNCH_ACTIVITY: { |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1393 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityStart"); |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 1394 | final ActivityClientRecord r = (ActivityClientRecord) msg.obj; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1395 | |
| 1396 | r.packageInfo = getPackageInfoNoCheck( |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1397 | r.activityInfo.applicationInfo, r.compatInfo); |
Christopher Tate | b70f3df | 2009-04-07 16:07:59 -0700 | [diff] [blame] | 1398 | handleLaunchActivity(r, null); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1399 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1400 | } break; |
| 1401 | case RELAUNCH_ACTIVITY: { |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1402 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityRestart"); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1403 | ActivityClientRecord r = (ActivityClientRecord)msg.obj; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 1404 | handleRelaunchActivity(r); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1405 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1406 | } break; |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1407 | case PAUSE_ACTIVITY: { |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1408 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityPause"); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1409 | SomeArgs args = (SomeArgs) msg.obj; |
| 1410 | handlePauseActivity((IBinder) args.arg1, false, |
| 1411 | (args.argi1 & USER_LEAVING) != 0, args.argi2, |
| 1412 | (args.argi1 & DONT_REPORT) != 0, args.argi3); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1413 | maybeSnapshot(); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1414 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1415 | } break; |
| 1416 | case PAUSE_ACTIVITY_FINISHING: { |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1417 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityPause"); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1418 | SomeArgs args = (SomeArgs) msg.obj; |
| 1419 | handlePauseActivity((IBinder) args.arg1, true, (args.argi1 & USER_LEAVING) != 0, |
| 1420 | args.argi2, (args.argi1 & DONT_REPORT) != 0, args.argi3); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1421 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1422 | } break; |
| 1423 | case STOP_ACTIVITY_SHOW: { |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1424 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityStop"); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1425 | SomeArgs args = (SomeArgs) msg.obj; |
| 1426 | handleStopActivity((IBinder) args.arg1, true, args.argi2, args.argi3); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1427 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1428 | } break; |
| 1429 | case STOP_ACTIVITY_HIDE: { |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1430 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityStop"); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1431 | SomeArgs args = (SomeArgs) msg.obj; |
| 1432 | handleStopActivity((IBinder) args.arg1, false, args.argi2, args.argi3); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1433 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1434 | } break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1435 | case SHOW_WINDOW: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1436 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityShowWindow"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1437 | handleWindowVisibility((IBinder)msg.obj, true); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1438 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1439 | break; |
| 1440 | case HIDE_WINDOW: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1441 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityHideWindow"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1442 | handleWindowVisibility((IBinder)msg.obj, false); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1443 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1444 | break; |
| 1445 | case RESUME_ACTIVITY: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1446 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityResume"); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1447 | SomeArgs args = (SomeArgs) msg.obj; |
| 1448 | handleResumeActivity((IBinder) args.arg1, true, args.argi1 != 0, true, |
| 1449 | args.argi3); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1450 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1451 | break; |
| 1452 | case SEND_RESULT: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1453 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityDeliverResult"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1454 | handleSendResult((ResultData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1455 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1456 | break; |
| 1457 | case DESTROY_ACTIVITY: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1458 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityDestroy"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1459 | handleDestroyActivity((IBinder)msg.obj, msg.arg1 != 0, |
| 1460 | msg.arg2, false); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1461 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1462 | break; |
| 1463 | case BIND_APPLICATION: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1464 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "bindApplication"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1465 | AppBindData data = (AppBindData)msg.obj; |
| 1466 | handleBindApplication(data); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1467 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1468 | break; |
| 1469 | case EXIT_APPLICATION: |
| 1470 | if (mInitialApplication != null) { |
| 1471 | mInitialApplication.onTerminate(); |
| 1472 | } |
| 1473 | Looper.myLooper().quit(); |
| 1474 | break; |
| 1475 | case NEW_INTENT: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1476 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityNewIntent"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1477 | handleNewIntent((NewIntentData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1478 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1479 | break; |
| 1480 | case RECEIVER: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1481 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "broadcastReceiveComp"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1482 | handleReceiver((ReceiverData)msg.obj); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1483 | maybeSnapshot(); |
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 CREATE_SERVICE: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1487 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "serviceCreate"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1488 | handleCreateService((CreateServiceData)msg.obj); |
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 BIND_SERVICE: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1492 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "serviceBind"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1493 | handleBindService((BindServiceData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1494 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1495 | break; |
| 1496 | case UNBIND_SERVICE: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1497 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "serviceUnbind"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1498 | handleUnbindService((BindServiceData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1499 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1500 | break; |
| 1501 | case SERVICE_ARGS: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1502 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "serviceStart"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1503 | handleServiceArgs((ServiceArgsData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1504 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1505 | break; |
| 1506 | case STOP_SERVICE: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1507 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "serviceStop"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1508 | handleStopService((IBinder)msg.obj); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1509 | maybeSnapshot(); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1510 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1511 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1512 | case CONFIGURATION_CHANGED: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1513 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "configChanged"); |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 1514 | mCurDefaultDisplayDpi = ((Configuration)msg.obj).densityDpi; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1515 | handleConfigurationChanged((Configuration)msg.obj, null); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1516 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1517 | break; |
| 1518 | case CLEAN_UP_CONTEXT: |
| 1519 | ContextCleanupInfo cci = (ContextCleanupInfo)msg.obj; |
| 1520 | cci.context.performFinalCleanup(cci.who, cci.what); |
| 1521 | break; |
| 1522 | case GC_WHEN_IDLE: |
| 1523 | scheduleGcIdler(); |
| 1524 | break; |
| 1525 | case DUMP_SERVICE: |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1526 | handleDumpService((DumpComponentInfo)msg.obj); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1527 | break; |
| 1528 | case LOW_MEMORY: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1529 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "lowMemory"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1530 | handleLowMemory(); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1531 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1532 | break; |
| 1533 | case ACTIVITY_CONFIGURATION_CHANGED: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1534 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityConfigChanged"); |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 1535 | handleActivityConfigurationChanged((ActivityConfigChangeData) msg.obj, |
| 1536 | msg.arg1 == 1 ? REPORT_TO_ACTIVITY : !REPORT_TO_ACTIVITY); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1537 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1538 | break; |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 1539 | case PROFILER_CONTROL: |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 1540 | handleProfilerControl(msg.arg1 != 0, (ProfilerInfo)msg.obj, msg.arg2); |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 1541 | break; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1542 | case CREATE_BACKUP_AGENT: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1543 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "backupCreateAgent"); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1544 | handleCreateBackupAgent((CreateBackupAgentData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1545 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1546 | break; |
| 1547 | case DESTROY_BACKUP_AGENT: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1548 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "backupDestroyAgent"); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1549 | handleDestroyBackupAgent((CreateBackupAgentData)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1550 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 1551 | break; |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 1552 | case SUICIDE: |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1553 | Process.killProcess(Process.myPid()); |
| 1554 | break; |
| 1555 | case REMOVE_PROVIDER: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1556 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "providerRemove"); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1557 | completeRemoveProvider((ProviderRefCount)msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1558 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Christopher Tate | 5e1ab33 | 2009-09-01 20:32:49 -0700 | [diff] [blame] | 1559 | break; |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 1560 | case ENABLE_JIT: |
| 1561 | ensureJitEnabled(); |
| 1562 | break; |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1563 | case DISPATCH_PACKAGE_BROADCAST: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1564 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "broadcastPackage"); |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1565 | handleDispatchPackageBroadcast(msg.arg1, (String[])msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1566 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1567 | break; |
Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 1568 | case SCHEDULE_CRASH: |
| 1569 | throw new RemoteServiceException((String)msg.obj); |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 1570 | case DUMP_HEAP: |
| 1571 | handleDumpHeap(msg.arg1 != 0, (DumpHeapData)msg.obj); |
| 1572 | break; |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 1573 | case DUMP_ACTIVITY: |
| 1574 | handleDumpActivity((DumpComponentInfo)msg.obj); |
| 1575 | break; |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 1576 | case DUMP_PROVIDER: |
| 1577 | handleDumpProvider((DumpComponentInfo)msg.obj); |
| 1578 | break; |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1579 | case SLEEPING: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1580 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "sleeping"); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1581 | handleSleeping((IBinder)msg.obj, msg.arg1 != 0); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1582 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1583 | break; |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1584 | case SET_CORE_SETTINGS: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1585 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "setCoreSettings"); |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1586 | handleSetCoreSettings((Bundle) msg.obj); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1587 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 1588 | break; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1589 | case UPDATE_PACKAGE_COMPATIBILITY_INFO: |
| 1590 | handleUpdatePackageCompatibilityInfo((UpdateCompatibilityData)msg.obj); |
Dianne Hackborn | f0754f5b | 2011-07-21 16:02:07 -0700 | [diff] [blame] | 1591 | break; |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1592 | case TRIM_MEMORY: |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1593 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "trimMemory"); |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1594 | handleTrimMemory(msg.arg1); |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 1595 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
Dianne Hackborn | f0754f5b | 2011-07-21 16:02:07 -0700 | [diff] [blame] | 1596 | break; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1597 | case UNSTABLE_PROVIDER_DIED: |
| 1598 | handleUnstableProviderDied((IBinder)msg.obj, false); |
| 1599 | break; |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 1600 | case REQUEST_ASSIST_CONTEXT_EXTRAS: |
| 1601 | handleRequestAssistContextExtras((RequestAssistContextExtras)msg.obj); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 1602 | break; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1603 | case TRANSLUCENT_CONVERSION_COMPLETE: |
| 1604 | handleTranslucentConversionComplete((IBinder)msg.obj, msg.arg1 == 1); |
| 1605 | break; |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 1606 | case INSTALL_PROVIDER: |
| 1607 | handleInstallProvider((ProviderInfo) msg.obj); |
| 1608 | break; |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1609 | case ON_NEW_ACTIVITY_OPTIONS: |
| 1610 | Pair<IBinder, ActivityOptions> pair = (Pair<IBinder, ActivityOptions>) msg.obj; |
| 1611 | onNewActivityOptions(pair.first, pair.second); |
Dake Gu | 7ef70b0 | 2014-07-08 18:37:12 -0700 | [diff] [blame] | 1612 | break; |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 1613 | case CANCEL_VISIBLE_BEHIND: |
| 1614 | handleCancelVisibleBehind((IBinder) msg.obj); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 1615 | break; |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 1616 | case BACKGROUND_VISIBLE_BEHIND_CHANGED: |
| 1617 | handleOnBackgroundVisibleBehindChanged((IBinder) msg.obj, msg.arg1 > 0); |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1618 | break; |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 1619 | case ENTER_ANIMATION_COMPLETE: |
| 1620 | handleEnterAnimationComplete((IBinder) msg.obj); |
| 1621 | break; |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 1622 | case START_BINDER_TRACKING: |
| 1623 | handleStartBinderTracking(); |
| 1624 | break; |
| 1625 | case STOP_BINDER_TRACKING_AND_DUMP: |
| 1626 | handleStopBinderTrackingAndDump((ParcelFileDescriptor) msg.obj); |
| 1627 | break; |
Wale Ogunwale | 3b93a4d | 2016-01-29 17:46:53 -0800 | [diff] [blame] | 1628 | case MULTI_WINDOW_CHANGED: |
| 1629 | handleMultiWindowChanged((IBinder) msg.obj, msg.arg1 == 1); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 1630 | break; |
Wale Ogunwale | 3b93a4d | 2016-01-29 17:46:53 -0800 | [diff] [blame] | 1631 | case PICTURE_IN_PICTURE_CHANGED: |
| 1632 | handlePictureInPictureChanged((IBinder) msg.obj, msg.arg1 == 1); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 1633 | break; |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 1634 | case LOCAL_VOICE_INTERACTION_STARTED: |
| 1635 | handleLocalVoiceInteractionStarted((IBinder) ((SomeArgs) msg.obj).arg1, |
| 1636 | (IVoiceInteractor) ((SomeArgs) msg.obj).arg2); |
| 1637 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1638 | } |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 1639 | Object obj = msg.obj; |
| 1640 | if (obj instanceof SomeArgs) { |
| 1641 | ((SomeArgs) obj).recycle(); |
| 1642 | } |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 1643 | 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] | 1644 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1645 | |
Brian Carlstrom | ed7e007 | 2011-03-24 13:27:57 -0700 | [diff] [blame] | 1646 | private void maybeSnapshot() { |
| 1647 | if (mBoundApplication != null && SamplingProfilerIntegration.isEnabled()) { |
Sen Hu | bde7570 | 2010-05-28 01:54:03 -0700 | [diff] [blame] | 1648 | // convert the *private* ActivityThread.PackageInfo to *public* known |
| 1649 | // android.content.pm.PackageInfo |
| 1650 | String packageName = mBoundApplication.info.mPackageName; |
| 1651 | android.content.pm.PackageInfo packageInfo = null; |
| 1652 | try { |
| 1653 | Context context = getSystemContext(); |
| 1654 | if(context == null) { |
| 1655 | Log.e(TAG, "cannot get a valid context"); |
| 1656 | return; |
| 1657 | } |
| 1658 | PackageManager pm = context.getPackageManager(); |
| 1659 | if(pm == null) { |
| 1660 | Log.e(TAG, "cannot get a valid PackageManager"); |
| 1661 | return; |
| 1662 | } |
| 1663 | packageInfo = pm.getPackageInfo( |
| 1664 | packageName, PackageManager.GET_ACTIVITIES); |
| 1665 | } catch (NameNotFoundException e) { |
| 1666 | Log.e(TAG, "cannot get package info for " + packageName, e); |
| 1667 | } |
| 1668 | SamplingProfilerIntegration.writeSnapshot(mBoundApplication.processName, packageInfo); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1669 | } |
| 1670 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1671 | } |
| 1672 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1673 | private class Idler implements MessageQueue.IdleHandler { |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 1674 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1675 | public final boolean queueIdle() { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1676 | ActivityClientRecord a = mNewActivities; |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 1677 | boolean stopProfiling = false; |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 1678 | if (mBoundApplication != null && mProfiler.profileFd != null |
| 1679 | && mProfiler.autoStopProfiler) { |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 1680 | stopProfiling = true; |
| 1681 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1682 | if (a != null) { |
| 1683 | mNewActivities = null; |
| 1684 | IActivityManager am = ActivityManagerNative.getDefault(); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1685 | ActivityClientRecord prev; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1686 | do { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 1687 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1688 | TAG, "Reporting idle of " + a + |
| 1689 | " finished=" + |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1690 | (a.activity != null && a.activity.mFinished)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1691 | if (a.activity != null && !a.activity.mFinished) { |
| 1692 | try { |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 1693 | am.activityIdle(a.token, a.createdConfig, stopProfiling); |
Dianne Hackborn | e88846e | 2009-09-30 21:34:25 -0700 | [diff] [blame] | 1694 | a.createdConfig = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1695 | } catch (RemoteException ex) { |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1696 | // Ignore |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1697 | } |
| 1698 | } |
| 1699 | prev = a; |
| 1700 | a = a.nextIdle; |
| 1701 | prev.nextIdle = null; |
| 1702 | } while (a != null); |
| 1703 | } |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 1704 | if (stopProfiling) { |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 1705 | mProfiler.stopProfiling(); |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 1706 | } |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 1707 | ensureJitEnabled(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1708 | return false; |
| 1709 | } |
| 1710 | } |
| 1711 | |
| 1712 | final class GcIdler implements MessageQueue.IdleHandler { |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 1713 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1714 | public final boolean queueIdle() { |
| 1715 | doGcIfNeeded(); |
| 1716 | return false; |
| 1717 | } |
| 1718 | } |
| 1719 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1720 | public static ActivityThread currentActivityThread() { |
Jeff Sharkey | 66a017b | 2013-01-17 18:18:22 -0800 | [diff] [blame] | 1721 | return sCurrentActivityThread; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1722 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1723 | |
Wale Ogunwale | 9a6ef1e | 2015-06-02 13:41:00 -0700 | [diff] [blame] | 1724 | public static boolean isSystem() { |
| 1725 | return (sCurrentActivityThread != null) ? sCurrentActivityThread.mSystemThread : false; |
| 1726 | } |
| 1727 | |
Svetoslav | fbf0eca | 2015-05-01 16:52:41 -0700 | [diff] [blame] | 1728 | public static String currentOpPackageName() { |
| 1729 | ActivityThread am = currentActivityThread(); |
| 1730 | return (am != null && am.getApplication() != null) |
| 1731 | ? am.getApplication().getOpPackageName() : null; |
| 1732 | } |
| 1733 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1734 | public static String currentPackageName() { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1735 | ActivityThread am = currentActivityThread(); |
| 1736 | return (am != null && am.mBoundApplication != null) |
Dianne Hackborn | b57a50b | 2013-04-11 17:29:32 -0700 | [diff] [blame] | 1737 | ? am.mBoundApplication.appInfo.packageName : null; |
| 1738 | } |
| 1739 | |
| 1740 | public static String currentProcessName() { |
| 1741 | ActivityThread am = currentActivityThread(); |
| 1742 | return (am != null && am.mBoundApplication != null) |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1743 | ? am.mBoundApplication.processName : null; |
| 1744 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1745 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1746 | public static Application currentApplication() { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1747 | ActivityThread am = currentActivityThread(); |
| 1748 | return am != null ? am.mInitialApplication : null; |
| 1749 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1750 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1751 | public static IPackageManager getPackageManager() { |
| 1752 | if (sPackageManager != null) { |
| 1753 | //Slog.v("PackageManager", "returning cur default = " + sPackageManager); |
| 1754 | return sPackageManager; |
| 1755 | } |
| 1756 | IBinder b = ServiceManager.getService("package"); |
| 1757 | //Slog.v("PackageManager", "default service binder = " + b); |
| 1758 | sPackageManager = IPackageManager.Stub.asInterface(b); |
| 1759 | //Slog.v("PackageManager", "default service = " + sPackageManager); |
| 1760 | return sPackageManager; |
| 1761 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1762 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1763 | private Configuration mMainThreadConfig = new Configuration(); |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 1764 | Configuration applyConfigCompatMainThread(int displayDensity, Configuration config, |
| 1765 | CompatibilityInfo compat) { |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1766 | if (config == null) { |
| 1767 | return null; |
| 1768 | } |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 1769 | if (!compat.supportsScreen()) { |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1770 | mMainThreadConfig.setTo(config); |
| 1771 | config = mMainThreadConfig; |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 1772 | compat.applyToConfiguration(displayDensity, config); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1773 | } |
| 1774 | return config; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1775 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1776 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1777 | /** |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1778 | * Creates the top level resources for the given package. |
| 1779 | */ |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 1780 | Resources getTopLevelResources(String resDir, String[] splitResDirs, String[] overlayDirs, |
| 1781 | String[] libDirs, int displayId, Configuration overrideConfiguration, |
Dianne Hackborn | 756220b | 2012-08-14 16:45:30 -0700 | [diff] [blame] | 1782 | LoadedApk pkgInfo) { |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 1783 | return mResourcesManager.getTopLevelResources(resDir, splitResDirs, overlayDirs, libDirs, |
Alan Viverette | 02fc5fe | 2015-08-27 13:16:09 -0400 | [diff] [blame] | 1784 | displayId, overrideConfiguration, pkgInfo.getCompatibilityInfo(), |
| 1785 | pkgInfo.getClassLoader()); |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1786 | } |
| 1787 | |
| 1788 | final Handler getHandler() { |
| 1789 | return mH; |
| 1790 | } |
| 1791 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1792 | public final LoadedApk getPackageInfo(String packageName, CompatibilityInfo compatInfo, |
| 1793 | int flags) { |
Amith Yamasani | 98edc95 | 2012-09-25 14:09:27 -0700 | [diff] [blame] | 1794 | return getPackageInfo(packageName, compatInfo, flags, UserHandle.myUserId()); |
| 1795 | } |
| 1796 | |
| 1797 | public final LoadedApk getPackageInfo(String packageName, CompatibilityInfo compatInfo, |
| 1798 | int flags, int userId) { |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 1799 | final boolean differentUser = (UserHandle.myUserId() != userId); |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 1800 | synchronized (mResourcesManager) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1801 | WeakReference<LoadedApk> ref; |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 1802 | if (differentUser) { |
| 1803 | // Caching not supported across users |
| 1804 | ref = null; |
| 1805 | } else if ((flags & Context.CONTEXT_INCLUDE_CODE) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1806 | ref = mPackages.get(packageName); |
| 1807 | } else { |
| 1808 | ref = mResourcePackages.get(packageName); |
| 1809 | } |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 1810 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1811 | LoadedApk packageInfo = ref != null ? ref.get() : null; |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 1812 | //Slog.i(TAG, "getPackageInfo " + packageName + ": " + packageInfo); |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 1813 | //if (packageInfo != null) Slog.i(TAG, "isUptoDate " + packageInfo.mResDir |
| 1814 | // + ": " + packageInfo.mResources.getAssets().isUpToDate()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1815 | if (packageInfo != null && (packageInfo.mResources == null |
| 1816 | || packageInfo.mResources.getAssets().isUpToDate())) { |
| 1817 | if (packageInfo.isSecurityViolation() |
| 1818 | && (flags&Context.CONTEXT_IGNORE_SECURITY) == 0) { |
| 1819 | throw new SecurityException( |
| 1820 | "Requesting code from " + packageName |
| 1821 | + " to be run in process " |
| 1822 | + mBoundApplication.processName |
| 1823 | + "/" + mBoundApplication.appInfo.uid); |
| 1824 | } |
| 1825 | return packageInfo; |
| 1826 | } |
| 1827 | } |
| 1828 | |
| 1829 | ApplicationInfo ai = null; |
| 1830 | try { |
| 1831 | ai = getPackageManager().getApplicationInfo(packageName, |
Jeff Sharkey | c5967e9 | 2016-01-07 18:50:29 -0700 | [diff] [blame] | 1832 | PackageManager.GET_SHARED_LIBRARY_FILES |
| 1833 | | PackageManager.MATCH_DEBUG_TRIAGED_MISSING, |
| 1834 | userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1835 | } catch (RemoteException e) { |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1836 | // Ignore |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1837 | } |
| 1838 | |
| 1839 | if (ai != null) { |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1840 | return getPackageInfo(ai, compatInfo, flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1841 | } |
| 1842 | |
| 1843 | return null; |
| 1844 | } |
| 1845 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1846 | public final LoadedApk getPackageInfo(ApplicationInfo ai, CompatibilityInfo compatInfo, |
| 1847 | int flags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1848 | boolean includeCode = (flags&Context.CONTEXT_INCLUDE_CODE) != 0; |
| 1849 | boolean securityViolation = includeCode && ai.uid != 0 |
| 1850 | && ai.uid != Process.SYSTEM_UID && (mBoundApplication != null |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 1851 | ? !UserHandle.isSameApp(ai.uid, mBoundApplication.appInfo.uid) |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 1852 | : true); |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 1853 | boolean registerPackage = includeCode && (flags&Context.CONTEXT_REGISTER_PACKAGE) != 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1854 | if ((flags&(Context.CONTEXT_INCLUDE_CODE |
| 1855 | |Context.CONTEXT_IGNORE_SECURITY)) |
| 1856 | == Context.CONTEXT_INCLUDE_CODE) { |
| 1857 | if (securityViolation) { |
| 1858 | String msg = "Requesting code from " + ai.packageName |
| 1859 | + " (with uid " + ai.uid + ")"; |
| 1860 | if (mBoundApplication != null) { |
| 1861 | msg = msg + " to be run in process " |
| 1862 | + mBoundApplication.processName + " (with uid " |
| 1863 | + mBoundApplication.appInfo.uid + ")"; |
| 1864 | } |
| 1865 | throw new SecurityException(msg); |
| 1866 | } |
| 1867 | } |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 1868 | return getPackageInfo(ai, compatInfo, null, securityViolation, includeCode, |
| 1869 | registerPackage); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1870 | } |
| 1871 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1872 | public final LoadedApk getPackageInfoNoCheck(ApplicationInfo ai, |
| 1873 | CompatibilityInfo compatInfo) { |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 1874 | return getPackageInfo(ai, compatInfo, null, false, true, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1875 | } |
| 1876 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1877 | public final LoadedApk peekPackageInfo(String packageName, boolean includeCode) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 1878 | synchronized (mResourcesManager) { |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1879 | WeakReference<LoadedApk> ref; |
| 1880 | if (includeCode) { |
| 1881 | ref = mPackages.get(packageName); |
| 1882 | } else { |
| 1883 | ref = mResourcePackages.get(packageName); |
| 1884 | } |
| 1885 | return ref != null ? ref.get() : null; |
| 1886 | } |
| 1887 | } |
| 1888 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1889 | private LoadedApk getPackageInfo(ApplicationInfo aInfo, CompatibilityInfo compatInfo, |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 1890 | ClassLoader baseLoader, boolean securityViolation, boolean includeCode, |
| 1891 | boolean registerPackage) { |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 1892 | final boolean differentUser = (UserHandle.myUserId() != UserHandle.getUserId(aInfo.uid)); |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 1893 | synchronized (mResourcesManager) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1894 | WeakReference<LoadedApk> ref; |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 1895 | if (differentUser) { |
| 1896 | // Caching not supported across users |
| 1897 | ref = null; |
| 1898 | } else if (includeCode) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1899 | ref = mPackages.get(aInfo.packageName); |
| 1900 | } else { |
| 1901 | ref = mResourcePackages.get(aInfo.packageName); |
| 1902 | } |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 1903 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1904 | LoadedApk packageInfo = ref != null ? ref.get() : null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1905 | if (packageInfo == null || (packageInfo.mResources != null |
| 1906 | && !packageInfo.mResources.getAssets().isUpToDate())) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 1907 | if (localLOGV) Slog.v(TAG, (includeCode ? "Loading code package " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1908 | : "Loading resource-only package ") + aInfo.packageName |
| 1909 | + " (in " + (mBoundApplication != null |
| 1910 | ? mBoundApplication.processName : null) |
| 1911 | + ")"); |
| 1912 | packageInfo = |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 1913 | new LoadedApk(this, aInfo, compatInfo, baseLoader, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1914 | securityViolation, includeCode && |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 1915 | (aInfo.flags&ApplicationInfo.FLAG_HAS_CODE) != 0, registerPackage); |
Narayan Kamath | cb38318 | 2014-10-29 17:56:42 +0000 | [diff] [blame] | 1916 | |
| 1917 | if (mSystemThread && "android".equals(aInfo.packageName)) { |
| 1918 | packageInfo.installSystemApplicationInfo(aInfo, |
| 1919 | getSystemContext().mPackageInfo.getClassLoader()); |
| 1920 | } |
| 1921 | |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 1922 | if (differentUser) { |
| 1923 | // Caching not supported across users |
| 1924 | } else if (includeCode) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1925 | mPackages.put(aInfo.packageName, |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1926 | new WeakReference<LoadedApk>(packageInfo)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1927 | } else { |
| 1928 | mResourcePackages.put(aInfo.packageName, |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1929 | new WeakReference<LoadedApk>(packageInfo)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1930 | } |
| 1931 | } |
| 1932 | return packageInfo; |
| 1933 | } |
| 1934 | } |
| 1935 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1936 | ActivityThread() { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 1937 | mResourcesManager = ResourcesManager.getInstance(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1938 | } |
| 1939 | |
| 1940 | public ApplicationThread getApplicationThread() |
| 1941 | { |
| 1942 | return mAppThread; |
| 1943 | } |
| 1944 | |
| 1945 | public Instrumentation getInstrumentation() |
| 1946 | { |
| 1947 | return mInstrumentation; |
| 1948 | } |
| 1949 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1950 | public boolean isProfiling() { |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 1951 | return mProfiler != null && mProfiler.profileFile != null |
| 1952 | && mProfiler.profileFd == null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1953 | } |
| 1954 | |
| 1955 | public String getProfileFilePath() { |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 1956 | return mProfiler.profileFile; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1957 | } |
| 1958 | |
| 1959 | public Looper getLooper() { |
| 1960 | return mLooper; |
| 1961 | } |
| 1962 | |
| 1963 | public Application getApplication() { |
| 1964 | return mInitialApplication; |
| 1965 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1966 | |
Dianne Hackborn | d97c7ad | 2009-06-19 11:37:35 -0700 | [diff] [blame] | 1967 | public String getProcessName() { |
| 1968 | return mBoundApplication.processName; |
| 1969 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 1970 | |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 1971 | public ContextImpl getSystemContext() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1972 | synchronized (this) { |
| 1973 | if (mSystemContext == null) { |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 1974 | mSystemContext = ContextImpl.createSystemContext(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1975 | } |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 1976 | return mSystemContext; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1977 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1978 | } |
| 1979 | |
Narayan Kamath | 29564cd | 2014-08-07 10:57:40 +0100 | [diff] [blame] | 1980 | public void installSystemApplicationInfo(ApplicationInfo info, ClassLoader classLoader) { |
Mike Cleron | 432b713 | 2009-09-24 15:28:29 -0700 | [diff] [blame] | 1981 | synchronized (this) { |
Narayan Kamath | 29564cd | 2014-08-07 10:57:40 +0100 | [diff] [blame] | 1982 | getSystemContext().installSystemApplicationInfo(info, classLoader); |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 1983 | |
| 1984 | // give ourselves a default profiler |
| 1985 | mProfiler = new Profiler(); |
Mike Cleron | 432b713 | 2009-09-24 15:28:29 -0700 | [diff] [blame] | 1986 | } |
| 1987 | } |
| 1988 | |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 1989 | void ensureJitEnabled() { |
| 1990 | if (!mJitEnabled) { |
| 1991 | mJitEnabled = true; |
| 1992 | dalvik.system.VMRuntime.getRuntime().startJitCompilation(); |
| 1993 | } |
| 1994 | } |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 1995 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1996 | void scheduleGcIdler() { |
| 1997 | if (!mGcIdlerScheduled) { |
| 1998 | mGcIdlerScheduled = true; |
| 1999 | Looper.myQueue().addIdleHandler(mGcIdler); |
| 2000 | } |
| 2001 | mH.removeMessages(H.GC_WHEN_IDLE); |
| 2002 | } |
| 2003 | |
| 2004 | void unscheduleGcIdler() { |
| 2005 | if (mGcIdlerScheduled) { |
| 2006 | mGcIdlerScheduled = false; |
| 2007 | Looper.myQueue().removeIdleHandler(mGcIdler); |
| 2008 | } |
| 2009 | mH.removeMessages(H.GC_WHEN_IDLE); |
| 2010 | } |
| 2011 | |
| 2012 | void doGcIfNeeded() { |
| 2013 | mGcIdlerScheduled = false; |
| 2014 | final long now = SystemClock.uptimeMillis(); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2015 | //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] | 2016 | // + "m now=" + now); |
| 2017 | if ((BinderInternal.getLastGcTime()+MIN_TIME_BETWEEN_GCS) < now) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2018 | //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] | 2019 | BinderInternal.forceGc("bg"); |
| 2020 | } |
| 2021 | } |
| 2022 | |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2023 | private static final String HEAP_FULL_COLUMN |
| 2024 | = "%13s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s"; |
| 2025 | private static final String HEAP_COLUMN |
| 2026 | = "%13s %8s %8s %8s %8s %8s %8s %8s"; |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2027 | private static final String ONE_COUNT_COLUMN = "%21s %8d"; |
| 2028 | private static final String TWO_COUNT_COLUMNS = "%21s %8d %21s %8d"; |
| 2029 | private static final String ONE_COUNT_COLUMN_HEADER = "%21s %8s"; |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2030 | |
| 2031 | // Formatting for checkin service - update version if row format changes |
Martijn Coenen | 41f94ed | 2015-12-14 15:28:51 +0100 | [diff] [blame] | 2032 | private static final int ACTIVITY_THREAD_CHECKIN_VERSION = 4; |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2033 | |
| 2034 | static void printRow(PrintWriter pw, String format, Object...objs) { |
| 2035 | pw.println(String.format(format, objs)); |
| 2036 | } |
| 2037 | |
| 2038 | public static void dumpMemInfoTable(PrintWriter pw, Debug.MemoryInfo memInfo, boolean checkin, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2039 | boolean dumpFullInfo, boolean dumpDalvik, boolean dumpSummaryOnly, |
| 2040 | int pid, String processName, |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2041 | long nativeMax, long nativeAllocated, long nativeFree, |
| 2042 | long dalvikMax, long dalvikAllocated, long dalvikFree) { |
| 2043 | |
| 2044 | // For checkin, we print one long comma-separated list of values |
| 2045 | if (checkin) { |
| 2046 | // NOTE: if you change anything significant below, also consider changing |
| 2047 | // ACTIVITY_THREAD_CHECKIN_VERSION. |
| 2048 | |
| 2049 | // Header |
| 2050 | pw.print(ACTIVITY_THREAD_CHECKIN_VERSION); pw.print(','); |
| 2051 | pw.print(pid); pw.print(','); |
| 2052 | pw.print(processName); pw.print(','); |
| 2053 | |
| 2054 | // Heap info - max |
| 2055 | pw.print(nativeMax); pw.print(','); |
| 2056 | pw.print(dalvikMax); pw.print(','); |
| 2057 | pw.print("N/A,"); |
| 2058 | pw.print(nativeMax + dalvikMax); pw.print(','); |
| 2059 | |
| 2060 | // Heap info - allocated |
| 2061 | pw.print(nativeAllocated); pw.print(','); |
| 2062 | pw.print(dalvikAllocated); pw.print(','); |
| 2063 | pw.print("N/A,"); |
| 2064 | pw.print(nativeAllocated + dalvikAllocated); pw.print(','); |
| 2065 | |
| 2066 | // Heap info - free |
| 2067 | pw.print(nativeFree); pw.print(','); |
| 2068 | pw.print(dalvikFree); pw.print(','); |
| 2069 | pw.print("N/A,"); |
| 2070 | pw.print(nativeFree + dalvikFree); pw.print(','); |
| 2071 | |
| 2072 | // Heap info - proportional set size |
| 2073 | pw.print(memInfo.nativePss); pw.print(','); |
| 2074 | pw.print(memInfo.dalvikPss); pw.print(','); |
| 2075 | pw.print(memInfo.otherPss); pw.print(','); |
| 2076 | pw.print(memInfo.getTotalPss()); pw.print(','); |
| 2077 | |
| 2078 | // Heap info - swappable set size |
| 2079 | pw.print(memInfo.nativeSwappablePss); pw.print(','); |
| 2080 | pw.print(memInfo.dalvikSwappablePss); pw.print(','); |
| 2081 | pw.print(memInfo.otherSwappablePss); pw.print(','); |
| 2082 | pw.print(memInfo.getTotalSwappablePss()); pw.print(','); |
| 2083 | |
| 2084 | // Heap info - shared dirty |
| 2085 | pw.print(memInfo.nativeSharedDirty); pw.print(','); |
| 2086 | pw.print(memInfo.dalvikSharedDirty); pw.print(','); |
| 2087 | pw.print(memInfo.otherSharedDirty); pw.print(','); |
| 2088 | pw.print(memInfo.getTotalSharedDirty()); pw.print(','); |
| 2089 | |
| 2090 | // Heap info - shared clean |
| 2091 | pw.print(memInfo.nativeSharedClean); pw.print(','); |
| 2092 | pw.print(memInfo.dalvikSharedClean); pw.print(','); |
| 2093 | pw.print(memInfo.otherSharedClean); pw.print(','); |
| 2094 | pw.print(memInfo.getTotalSharedClean()); pw.print(','); |
| 2095 | |
| 2096 | // Heap info - private Dirty |
| 2097 | pw.print(memInfo.nativePrivateDirty); pw.print(','); |
| 2098 | pw.print(memInfo.dalvikPrivateDirty); pw.print(','); |
| 2099 | pw.print(memInfo.otherPrivateDirty); pw.print(','); |
| 2100 | pw.print(memInfo.getTotalPrivateDirty()); pw.print(','); |
| 2101 | |
| 2102 | // Heap info - private Clean |
| 2103 | pw.print(memInfo.nativePrivateClean); pw.print(','); |
| 2104 | pw.print(memInfo.dalvikPrivateClean); pw.print(','); |
| 2105 | pw.print(memInfo.otherPrivateClean); pw.print(','); |
| 2106 | pw.print(memInfo.getTotalPrivateClean()); pw.print(','); |
| 2107 | |
Martijn Coenen | 41f94ed | 2015-12-14 15:28:51 +0100 | [diff] [blame] | 2108 | // Heap info - swapped out |
| 2109 | pw.print(memInfo.nativeSwappedOut); pw.print(','); |
| 2110 | pw.print(memInfo.dalvikSwappedOut); pw.print(','); |
| 2111 | pw.print(memInfo.otherSwappedOut); pw.print(','); |
| 2112 | pw.print(memInfo.getTotalSwappedOut()); pw.print(','); |
| 2113 | |
| 2114 | // Heap info - swapped out pss |
| 2115 | if (memInfo.hasSwappedOutPss) { |
| 2116 | pw.print(memInfo.nativeSwappedOutPss); pw.print(','); |
| 2117 | pw.print(memInfo.dalvikSwappedOutPss); pw.print(','); |
| 2118 | pw.print(memInfo.otherSwappedOutPss); pw.print(','); |
| 2119 | pw.print(memInfo.getTotalSwappedOutPss()); pw.print(','); |
| 2120 | } else { |
| 2121 | pw.print("N/A,"); |
| 2122 | pw.print("N/A,"); |
| 2123 | pw.print("N/A,"); |
| 2124 | pw.print("N/A,"); |
| 2125 | } |
| 2126 | |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2127 | // Heap info - other areas |
| 2128 | for (int i=0; i<Debug.MemoryInfo.NUM_OTHER_STATS; i++) { |
| 2129 | pw.print(Debug.MemoryInfo.getOtherLabel(i)); pw.print(','); |
| 2130 | pw.print(memInfo.getOtherPss(i)); pw.print(','); |
| 2131 | pw.print(memInfo.getOtherSwappablePss(i)); pw.print(','); |
| 2132 | pw.print(memInfo.getOtherSharedDirty(i)); pw.print(','); |
| 2133 | pw.print(memInfo.getOtherSharedClean(i)); pw.print(','); |
| 2134 | pw.print(memInfo.getOtherPrivateDirty(i)); pw.print(','); |
| 2135 | pw.print(memInfo.getOtherPrivateClean(i)); pw.print(','); |
Martijn Coenen | 41f94ed | 2015-12-14 15:28:51 +0100 | [diff] [blame] | 2136 | pw.print(memInfo.getOtherSwappedOut(i)); pw.print(','); |
| 2137 | if (memInfo.hasSwappedOutPss) { |
| 2138 | pw.print(memInfo.getOtherSwappedOutPss(i)); pw.print(','); |
| 2139 | } else { |
| 2140 | pw.print("N/A,"); |
| 2141 | } |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2142 | } |
| 2143 | return; |
| 2144 | } |
| 2145 | |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2146 | if (!dumpSummaryOnly) { |
| 2147 | if (dumpFullInfo) { |
| 2148 | printRow(pw, HEAP_FULL_COLUMN, "", "Pss", "Pss", "Shared", "Private", |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2149 | "Shared", "Private", memInfo.hasSwappedOutPss ? "SwapPss" : "Swap", |
| 2150 | "Heap", "Heap", "Heap"); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2151 | printRow(pw, HEAP_FULL_COLUMN, "", "Total", "Clean", "Dirty", "Dirty", |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2152 | "Clean", "Clean", "Dirty", |
| 2153 | "Size", "Alloc", "Free"); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2154 | printRow(pw, HEAP_FULL_COLUMN, "", "------", "------", "------", "------", |
| 2155 | "------", "------", "------", "------", "------", "------"); |
| 2156 | printRow(pw, HEAP_FULL_COLUMN, "Native Heap", memInfo.nativePss, |
| 2157 | memInfo.nativeSwappablePss, memInfo.nativeSharedDirty, |
| 2158 | memInfo.nativePrivateDirty, memInfo.nativeSharedClean, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2159 | memInfo.nativePrivateClean, memInfo.hasSwappedOutPss ? |
| 2160 | memInfo.nativeSwappedOut : memInfo.nativeSwappedOutPss, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2161 | nativeMax, nativeAllocated, nativeFree); |
| 2162 | printRow(pw, HEAP_FULL_COLUMN, "Dalvik Heap", memInfo.dalvikPss, |
| 2163 | memInfo.dalvikSwappablePss, memInfo.dalvikSharedDirty, |
| 2164 | memInfo.dalvikPrivateDirty, memInfo.dalvikSharedClean, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2165 | memInfo.dalvikPrivateClean, memInfo.hasSwappedOutPss ? |
| 2166 | memInfo.dalvikSwappedOut : memInfo.dalvikSwappedOutPss, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2167 | dalvikMax, dalvikAllocated, dalvikFree); |
| 2168 | } else { |
| 2169 | printRow(pw, HEAP_COLUMN, "", "Pss", "Private", |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2170 | "Private", memInfo.hasSwappedOutPss ? "SwapPss" : "Swap", |
| 2171 | "Heap", "Heap", "Heap"); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2172 | printRow(pw, HEAP_COLUMN, "", "Total", "Dirty", |
| 2173 | "Clean", "Dirty", "Size", "Alloc", "Free"); |
| 2174 | printRow(pw, HEAP_COLUMN, "", "------", "------", "------", |
| 2175 | "------", "------", "------", "------", "------"); |
| 2176 | printRow(pw, HEAP_COLUMN, "Native Heap", memInfo.nativePss, |
| 2177 | memInfo.nativePrivateDirty, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2178 | memInfo.nativePrivateClean, |
| 2179 | memInfo.hasSwappedOutPss ? memInfo.nativeSwappedOutPss : |
| 2180 | memInfo.nativeSwappedOut, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2181 | nativeMax, nativeAllocated, nativeFree); |
| 2182 | printRow(pw, HEAP_COLUMN, "Dalvik Heap", memInfo.dalvikPss, |
| 2183 | memInfo.dalvikPrivateDirty, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2184 | memInfo.dalvikPrivateClean, |
| 2185 | memInfo.hasSwappedOutPss ? memInfo.dalvikSwappedOutPss : |
| 2186 | memInfo.dalvikSwappedOut, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2187 | dalvikMax, dalvikAllocated, dalvikFree); |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2188 | } |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2189 | |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2190 | int otherPss = memInfo.otherPss; |
| 2191 | int otherSwappablePss = memInfo.otherSwappablePss; |
| 2192 | int otherSharedDirty = memInfo.otherSharedDirty; |
| 2193 | int otherPrivateDirty = memInfo.otherPrivateDirty; |
| 2194 | int otherSharedClean = memInfo.otherSharedClean; |
| 2195 | int otherPrivateClean = memInfo.otherPrivateClean; |
| 2196 | int otherSwappedOut = memInfo.otherSwappedOut; |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2197 | int otherSwappedOutPss = memInfo.otherSwappedOutPss; |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2198 | |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2199 | for (int i=0; i<Debug.MemoryInfo.NUM_OTHER_STATS; i++) { |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2200 | final int myPss = memInfo.getOtherPss(i); |
| 2201 | final int mySwappablePss = memInfo.getOtherSwappablePss(i); |
| 2202 | final int mySharedDirty = memInfo.getOtherSharedDirty(i); |
| 2203 | final int myPrivateDirty = memInfo.getOtherPrivateDirty(i); |
| 2204 | final int mySharedClean = memInfo.getOtherSharedClean(i); |
| 2205 | final int myPrivateClean = memInfo.getOtherPrivateClean(i); |
| 2206 | final int mySwappedOut = memInfo.getOtherSwappedOut(i); |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2207 | final int mySwappedOutPss = memInfo.getOtherSwappedOutPss(i); |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2208 | if (myPss != 0 || mySharedDirty != 0 || myPrivateDirty != 0 |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2209 | || mySharedClean != 0 || myPrivateClean != 0 |
| 2210 | || (memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut) != 0) { |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2211 | if (dumpFullInfo) { |
| 2212 | printRow(pw, HEAP_FULL_COLUMN, Debug.MemoryInfo.getOtherLabel(i), |
| 2213 | myPss, mySwappablePss, mySharedDirty, myPrivateDirty, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2214 | mySharedClean, myPrivateClean, |
| 2215 | memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut, |
| 2216 | "", "", ""); |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2217 | } else { |
| 2218 | printRow(pw, HEAP_COLUMN, Debug.MemoryInfo.getOtherLabel(i), |
| 2219 | myPss, myPrivateDirty, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2220 | myPrivateClean, |
| 2221 | memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut, |
| 2222 | "", "", ""); |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2223 | } |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2224 | otherPss -= myPss; |
| 2225 | otherSwappablePss -= mySwappablePss; |
| 2226 | otherSharedDirty -= mySharedDirty; |
| 2227 | otherPrivateDirty -= myPrivateDirty; |
| 2228 | otherSharedClean -= mySharedClean; |
| 2229 | otherPrivateClean -= myPrivateClean; |
| 2230 | otherSwappedOut -= mySwappedOut; |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2231 | otherSwappedOutPss -= mySwappedOutPss; |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2232 | } |
| 2233 | } |
| 2234 | |
| 2235 | if (dumpFullInfo) { |
| 2236 | printRow(pw, HEAP_FULL_COLUMN, "Unknown", otherPss, otherSwappablePss, |
| 2237 | otherSharedDirty, otherPrivateDirty, otherSharedClean, otherPrivateClean, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2238 | memInfo.hasSwappedOutPss ? otherSwappedOutPss : otherSwappedOut, |
| 2239 | "", "", ""); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2240 | printRow(pw, HEAP_FULL_COLUMN, "TOTAL", memInfo.getTotalPss(), |
| 2241 | memInfo.getTotalSwappablePss(), |
| 2242 | memInfo.getTotalSharedDirty(), memInfo.getTotalPrivateDirty(), |
| 2243 | memInfo.getTotalSharedClean(), memInfo.getTotalPrivateClean(), |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2244 | memInfo.hasSwappedOutPss ? memInfo.getTotalSwappedOut() : |
| 2245 | memInfo.getTotalSwappedOutPss(), |
| 2246 | nativeMax+dalvikMax, nativeAllocated+dalvikAllocated, |
| 2247 | nativeFree+dalvikFree); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2248 | } else { |
| 2249 | printRow(pw, HEAP_COLUMN, "Unknown", otherPss, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2250 | otherPrivateDirty, otherPrivateClean, |
| 2251 | memInfo.hasSwappedOutPss ? otherSwappedOutPss : otherSwappedOut, |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2252 | "", "", ""); |
| 2253 | printRow(pw, HEAP_COLUMN, "TOTAL", memInfo.getTotalPss(), |
| 2254 | memInfo.getTotalPrivateDirty(), |
| 2255 | memInfo.getTotalPrivateClean(), |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2256 | memInfo.hasSwappedOutPss ? memInfo.getTotalSwappedOutPss() : |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2257 | memInfo.getTotalSwappedOut(), |
| 2258 | nativeMax+dalvikMax, |
| 2259 | nativeAllocated+dalvikAllocated, nativeFree+dalvikFree); |
| 2260 | } |
| 2261 | |
| 2262 | if (dumpDalvik) { |
| 2263 | pw.println(" "); |
| 2264 | pw.println(" Dalvik Details"); |
| 2265 | |
| 2266 | for (int i=Debug.MemoryInfo.NUM_OTHER_STATS; |
| 2267 | i<Debug.MemoryInfo.NUM_OTHER_STATS + Debug.MemoryInfo.NUM_DVK_STATS; i++) { |
| 2268 | final int myPss = memInfo.getOtherPss(i); |
| 2269 | final int mySwappablePss = memInfo.getOtherSwappablePss(i); |
| 2270 | final int mySharedDirty = memInfo.getOtherSharedDirty(i); |
| 2271 | final int myPrivateDirty = memInfo.getOtherPrivateDirty(i); |
| 2272 | final int mySharedClean = memInfo.getOtherSharedClean(i); |
| 2273 | final int myPrivateClean = memInfo.getOtherPrivateClean(i); |
| 2274 | final int mySwappedOut = memInfo.getOtherSwappedOut(i); |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2275 | final int mySwappedOutPss = memInfo.getOtherSwappedOutPss(i); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2276 | if (myPss != 0 || mySharedDirty != 0 || myPrivateDirty != 0 |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2277 | || mySharedClean != 0 || myPrivateClean != 0 |
| 2278 | || (memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut) != 0) { |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2279 | if (dumpFullInfo) { |
| 2280 | printRow(pw, HEAP_FULL_COLUMN, Debug.MemoryInfo.getOtherLabel(i), |
| 2281 | myPss, mySwappablePss, mySharedDirty, myPrivateDirty, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2282 | mySharedClean, myPrivateClean, |
| 2283 | memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut, |
| 2284 | "", "", ""); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2285 | } else { |
| 2286 | printRow(pw, HEAP_COLUMN, Debug.MemoryInfo.getOtherLabel(i), |
| 2287 | myPss, myPrivateDirty, |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2288 | myPrivateClean, |
| 2289 | memInfo.hasSwappedOutPss ? mySwappedOutPss : mySwappedOut, |
| 2290 | "", "", ""); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2291 | } |
| 2292 | } |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2293 | } |
| 2294 | } |
| 2295 | } |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 2296 | |
| 2297 | pw.println(" "); |
| 2298 | pw.println(" App Summary"); |
| 2299 | printRow(pw, ONE_COUNT_COLUMN_HEADER, "", "Pss(KB)"); |
| 2300 | printRow(pw, ONE_COUNT_COLUMN_HEADER, "", "------"); |
| 2301 | printRow(pw, ONE_COUNT_COLUMN, |
| 2302 | "Java Heap:", memInfo.getSummaryJavaHeap()); |
| 2303 | printRow(pw, ONE_COUNT_COLUMN, |
| 2304 | "Native Heap:", memInfo.getSummaryNativeHeap()); |
| 2305 | printRow(pw, ONE_COUNT_COLUMN, |
| 2306 | "Code:", memInfo.getSummaryCode()); |
| 2307 | printRow(pw, ONE_COUNT_COLUMN, |
| 2308 | "Stack:", memInfo.getSummaryStack()); |
| 2309 | printRow(pw, ONE_COUNT_COLUMN, |
| 2310 | "Graphics:", memInfo.getSummaryGraphics()); |
| 2311 | printRow(pw, ONE_COUNT_COLUMN, |
| 2312 | "Private Other:", memInfo.getSummaryPrivateOther()); |
| 2313 | printRow(pw, ONE_COUNT_COLUMN, |
| 2314 | "System:", memInfo.getSummarySystem()); |
| 2315 | pw.println(" "); |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 2316 | if (memInfo.hasSwappedOutPss) { |
| 2317 | printRow(pw, TWO_COUNT_COLUMNS, |
| 2318 | "TOTAL:", memInfo.getSummaryTotalPss(), |
| 2319 | "TOTAL SWAP PSS:", memInfo.getSummaryTotalSwapPss()); |
| 2320 | } else { |
| 2321 | printRow(pw, TWO_COUNT_COLUMNS, |
| 2322 | "TOTAL:", memInfo.getSummaryTotalPss(), |
| 2323 | "TOTAL SWAP (KB):", memInfo.getSummaryTotalSwap()); |
| 2324 | } |
Dianne Hackborn | e77187d | 2013-10-25 16:32:41 -0700 | [diff] [blame] | 2325 | } |
| 2326 | |
Jeff Hamilton | 52d3203 | 2011-01-08 15:31:26 -0600 | [diff] [blame] | 2327 | public void registerOnActivityPausedListener(Activity activity, |
| 2328 | OnActivityPausedListener listener) { |
| 2329 | synchronized (mOnPauseListeners) { |
| 2330 | ArrayList<OnActivityPausedListener> list = mOnPauseListeners.get(activity); |
| 2331 | if (list == null) { |
| 2332 | list = new ArrayList<OnActivityPausedListener>(); |
| 2333 | mOnPauseListeners.put(activity, list); |
| 2334 | } |
| 2335 | list.add(listener); |
| 2336 | } |
| 2337 | } |
| 2338 | |
Jeff Hamilton | ce3224c | 2011-01-17 11:05:03 -0800 | [diff] [blame] | 2339 | public void unregisterOnActivityPausedListener(Activity activity, |
| 2340 | OnActivityPausedListener listener) { |
| 2341 | synchronized (mOnPauseListeners) { |
| 2342 | ArrayList<OnActivityPausedListener> list = mOnPauseListeners.get(activity); |
| 2343 | if (list != null) { |
| 2344 | list.remove(listener); |
| 2345 | } |
| 2346 | } |
| 2347 | } |
| 2348 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2349 | public final ActivityInfo resolveActivityInfo(Intent intent) { |
| 2350 | ActivityInfo aInfo = intent.resolveActivityInfo( |
| 2351 | mInitialApplication.getPackageManager(), PackageManager.GET_SHARED_LIBRARY_FILES); |
| 2352 | if (aInfo == null) { |
| 2353 | // Throw an exception. |
| 2354 | Instrumentation.checkStartActivityResult( |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 2355 | ActivityManager.START_CLASS_NOT_FOUND, intent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2356 | } |
| 2357 | return aInfo; |
| 2358 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2359 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2360 | public final Activity startActivityNow(Activity parent, String id, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2361 | Intent intent, ActivityInfo activityInfo, IBinder token, Bundle state, |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 2362 | Activity.NonConfigurationInstances lastNonConfigurationInstances) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2363 | ActivityClientRecord r = new ActivityClientRecord(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2364 | r.token = token; |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 2365 | r.ident = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2366 | r.intent = intent; |
| 2367 | r.state = state; |
| 2368 | r.parent = parent; |
| 2369 | r.embeddedID = id; |
| 2370 | r.activityInfo = activityInfo; |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 2371 | r.lastNonConfigurationInstances = lastNonConfigurationInstances; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2372 | if (localLOGV) { |
| 2373 | ComponentName compname = intent.getComponent(); |
| 2374 | String name; |
| 2375 | if (compname != null) { |
| 2376 | name = compname.toShortString(); |
| 2377 | } else { |
| 2378 | name = "(Intent " + intent + ").getComponent() returned null"; |
| 2379 | } |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2380 | Slog.v(TAG, "Performing launch: action=" + intent.getAction() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2381 | + ", comp=" + name |
| 2382 | + ", token=" + token); |
| 2383 | } |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 2384 | return performLaunchActivity(r, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2385 | } |
| 2386 | |
| 2387 | public final Activity getActivity(IBinder token) { |
| 2388 | return mActivities.get(token).activity; |
| 2389 | } |
| 2390 | |
| 2391 | public final void sendActivityResult( |
| 2392 | IBinder token, String id, int requestCode, |
| 2393 | int resultCode, Intent data) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2394 | if (DEBUG_RESULTS) Slog.v(TAG, "sendActivityResult: id=" + id |
Chris Tate | 8a7dc17 | 2009-03-24 20:11:42 -0700 | [diff] [blame] | 2395 | + " req=" + requestCode + " res=" + resultCode + " data=" + data); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2396 | ArrayList<ResultInfo> list = new ArrayList<ResultInfo>(); |
| 2397 | list.add(new ResultInfo(id, requestCode, resultCode, data)); |
| 2398 | mAppThread.scheduleSendResult(token, list); |
| 2399 | } |
| 2400 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 2401 | private void sendMessage(int what, Object obj) { |
| 2402 | sendMessage(what, obj, 0, 0, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2403 | } |
| 2404 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 2405 | private void sendMessage(int what, Object obj, int arg1) { |
| 2406 | sendMessage(what, obj, arg1, 0, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2407 | } |
| 2408 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 2409 | private void sendMessage(int what, Object obj, int arg1, int arg2) { |
| 2410 | sendMessage(what, obj, arg1, arg2, false); |
| 2411 | } |
| 2412 | |
| 2413 | private void sendMessage(int what, Object obj, int arg1, int arg2, boolean async) { |
| 2414 | if (DEBUG_MESSAGES) Slog.v( |
| 2415 | TAG, "SCHEDULE " + what + " " + mH.codeToString(what) |
| 2416 | + ": " + arg1 + " / " + obj); |
| 2417 | Message msg = Message.obtain(); |
| 2418 | msg.what = what; |
| 2419 | msg.obj = obj; |
| 2420 | msg.arg1 = arg1; |
| 2421 | msg.arg2 = arg2; |
| 2422 | if (async) { |
| 2423 | msg.setAsynchronous(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2424 | } |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 2425 | mH.sendMessage(msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2426 | } |
| 2427 | |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 2428 | private void sendMessage(int what, Object obj, int arg1, int arg2, int seq) { |
| 2429 | if (DEBUG_MESSAGES) Slog.v( |
| 2430 | TAG, "SCHEDULE " + mH.codeToString(what) + " arg1=" + arg1 + " arg2=" + arg2 + |
| 2431 | "seq= " + seq); |
| 2432 | Message msg = Message.obtain(); |
| 2433 | msg.what = what; |
| 2434 | SomeArgs args = SomeArgs.obtain(); |
| 2435 | args.arg1 = obj; |
| 2436 | args.argi1 = arg1; |
| 2437 | args.argi2 = arg2; |
| 2438 | args.argi3 = seq; |
| 2439 | msg.obj = args; |
| 2440 | mH.sendMessage(msg); |
| 2441 | } |
| 2442 | |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 2443 | final void scheduleContextCleanup(ContextImpl context, String who, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2444 | String what) { |
| 2445 | ContextCleanupInfo cci = new ContextCleanupInfo(); |
| 2446 | cci.context = context; |
| 2447 | cci.who = who; |
| 2448 | cci.what = what; |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 2449 | sendMessage(H.CLEAN_UP_CONTEXT, cci); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2450 | } |
| 2451 | |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 2452 | private Activity performLaunchActivity(ActivityClientRecord r, Intent customIntent) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2453 | // System.out.println("##### [" + System.currentTimeMillis() + "] ActivityThread.performLaunchActivity(" + r + ")"); |
| 2454 | |
| 2455 | ActivityInfo aInfo = r.activityInfo; |
| 2456 | if (r.packageInfo == null) { |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2457 | r.packageInfo = getPackageInfo(aInfo.applicationInfo, r.compatInfo, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2458 | Context.CONTEXT_INCLUDE_CODE); |
| 2459 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2460 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2461 | ComponentName component = r.intent.getComponent(); |
| 2462 | if (component == null) { |
| 2463 | component = r.intent.resolveActivity( |
| 2464 | mInitialApplication.getPackageManager()); |
| 2465 | r.intent.setComponent(component); |
| 2466 | } |
| 2467 | |
| 2468 | if (r.activityInfo.targetActivity != null) { |
| 2469 | component = new ComponentName(r.activityInfo.packageName, |
| 2470 | r.activityInfo.targetActivity); |
| 2471 | } |
| 2472 | |
| 2473 | Activity activity = null; |
| 2474 | try { |
| 2475 | java.lang.ClassLoader cl = r.packageInfo.getClassLoader(); |
| 2476 | activity = mInstrumentation.newActivity( |
| 2477 | cl, component.getClassName(), r.intent); |
Brad Fitzpatrick | 5f8b5c1 | 2011-01-20 15:12:08 -0800 | [diff] [blame] | 2478 | StrictMode.incrementExpectedActivityCount(activity.getClass()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2479 | r.intent.setExtrasClassLoader(cl); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 2480 | r.intent.prepareToEnterProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2481 | if (r.state != null) { |
| 2482 | r.state.setClassLoader(cl); |
| 2483 | } |
| 2484 | } catch (Exception e) { |
| 2485 | if (!mInstrumentation.onException(activity, e)) { |
| 2486 | throw new RuntimeException( |
| 2487 | "Unable to instantiate activity " + component |
| 2488 | + ": " + e.toString(), e); |
| 2489 | } |
| 2490 | } |
| 2491 | |
| 2492 | try { |
Dianne Hackborn | 0be1f78 | 2009-11-09 12:30:12 -0800 | [diff] [blame] | 2493 | Application app = r.packageInfo.makeApplication(false, mInstrumentation); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2494 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2495 | if (localLOGV) Slog.v(TAG, "Performing launch of " + r); |
| 2496 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2497 | TAG, r + ": app=" + app |
| 2498 | + ", appName=" + app.getPackageName() |
| 2499 | + ", pkg=" + r.packageInfo.getPackageName() |
| 2500 | + ", comp=" + r.intent.getComponent().toShortString() |
| 2501 | + ", dir=" + r.packageInfo.getAppDir()); |
| 2502 | |
| 2503 | if (activity != null) { |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 2504 | Context appContext = createBaseContextForActivity(r, activity); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2505 | CharSequence title = r.activityInfo.loadLabel(appContext.getPackageManager()); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 2506 | Configuration config = new Configuration(mCompatConfiguration); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2507 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Launching activity " |
Dianne Hackborn | dc6b635 | 2009-09-30 14:20:09 -0700 | [diff] [blame] | 2508 | + r.activityInfo.name + " with config " + config); |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 2509 | Window window = null; |
| 2510 | if (r.mPendingRemoveWindow != null && r.mPreserveWindow) { |
| 2511 | window = r.mPendingRemoveWindow; |
| 2512 | r.mPendingRemoveWindow = null; |
| 2513 | r.mPendingRemoveWindowManager = null; |
| 2514 | } |
Dianne Hackborn | b06ea70 | 2009-07-13 13:07:51 -0700 | [diff] [blame] | 2515 | activity.attach(appContext, this, getInstrumentation(), r.token, |
| 2516 | r.ident, app, r.intent, r.activityInfo, title, r.parent, |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 2517 | r.embeddedID, r.lastNonConfigurationInstances, config, |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 2518 | r.referrer, r.voiceInteractor, window); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2519 | |
Christopher Tate | b70f3df | 2009-04-07 16:07:59 -0700 | [diff] [blame] | 2520 | if (customIntent != null) { |
| 2521 | activity.mIntent = customIntent; |
| 2522 | } |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 2523 | r.lastNonConfigurationInstances = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2524 | activity.mStartedActivity = false; |
| 2525 | int theme = r.activityInfo.getThemeResource(); |
| 2526 | if (theme != 0) { |
| 2527 | activity.setTheme(theme); |
| 2528 | } |
| 2529 | |
| 2530 | activity.mCalled = false; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2531 | if (r.isPersistable()) { |
| 2532 | mInstrumentation.callActivityOnCreate(activity, r.state, r.persistentState); |
| 2533 | } else { |
| 2534 | mInstrumentation.callActivityOnCreate(activity, r.state); |
| 2535 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2536 | if (!activity.mCalled) { |
| 2537 | throw new SuperNotCalledException( |
| 2538 | "Activity " + r.intent.getComponent().toShortString() + |
| 2539 | " did not call through to super.onCreate()"); |
| 2540 | } |
| 2541 | r.activity = activity; |
| 2542 | r.stopped = true; |
| 2543 | if (!r.activity.mFinished) { |
| 2544 | activity.performStart(); |
| 2545 | r.stopped = false; |
| 2546 | } |
| 2547 | if (!r.activity.mFinished) { |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2548 | if (r.isPersistable()) { |
| 2549 | if (r.state != null || r.persistentState != null) { |
| 2550 | mInstrumentation.callActivityOnRestoreInstanceState(activity, r.state, |
| 2551 | r.persistentState); |
| 2552 | } |
| 2553 | } else if (r.state != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2554 | mInstrumentation.callActivityOnRestoreInstanceState(activity, r.state); |
| 2555 | } |
| 2556 | } |
| 2557 | if (!r.activity.mFinished) { |
| 2558 | activity.mCalled = false; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2559 | if (r.isPersistable()) { |
| 2560 | mInstrumentation.callActivityOnPostCreate(activity, r.state, |
| 2561 | r.persistentState); |
| 2562 | } else { |
| 2563 | mInstrumentation.callActivityOnPostCreate(activity, r.state); |
| 2564 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2565 | if (!activity.mCalled) { |
| 2566 | throw new SuperNotCalledException( |
| 2567 | "Activity " + r.intent.getComponent().toShortString() + |
| 2568 | " did not call through to super.onPostCreate()"); |
| 2569 | } |
| 2570 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2571 | } |
| 2572 | r.paused = true; |
| 2573 | |
| 2574 | mActivities.put(r.token, r); |
| 2575 | |
| 2576 | } catch (SuperNotCalledException e) { |
| 2577 | throw e; |
| 2578 | |
| 2579 | } catch (Exception e) { |
| 2580 | if (!mInstrumentation.onException(activity, e)) { |
| 2581 | throw new RuntimeException( |
| 2582 | "Unable to start activity " + component |
| 2583 | + ": " + e.toString(), e); |
| 2584 | } |
| 2585 | } |
| 2586 | |
| 2587 | return activity; |
| 2588 | } |
| 2589 | |
Wale Ogunwale | 7c72668 | 2015-02-06 17:34:28 -0800 | [diff] [blame] | 2590 | private Context createBaseContextForActivity(ActivityClientRecord r, final Activity activity) { |
| 2591 | int displayId = Display.DEFAULT_DISPLAY; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2592 | try { |
Craig Mautner | aa7e3ed | 2015-02-17 10:17:21 -0800 | [diff] [blame] | 2593 | displayId = ActivityManagerNative.getDefault().getActivityDisplayId(r.token); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2594 | } catch (RemoteException e) { |
| 2595 | } |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 2596 | |
Wale Ogunwale | 7c72668 | 2015-02-06 17:34:28 -0800 | [diff] [blame] | 2597 | ContextImpl appContext = ContextImpl.createActivityContext( |
| 2598 | this, r.packageInfo, displayId, r.overrideConfig); |
| 2599 | appContext.setOuterContext(activity); |
| 2600 | Context baseContext = appContext; |
| 2601 | |
| 2602 | final DisplayManagerGlobal dm = DisplayManagerGlobal.getInstance(); |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 2603 | // For debugging purposes, if the activity's package name contains the value of |
| 2604 | // the "debug.use-second-display" system property as a substring, then show |
| 2605 | // its content on a secondary display if there is one. |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 2606 | String pkgName = SystemProperties.get("debug.second-display.pkg"); |
| 2607 | if (pkgName != null && !pkgName.isEmpty() |
| 2608 | && r.packageInfo.mPackageName.contains(pkgName)) { |
Wale Ogunwale | 7c72668 | 2015-02-06 17:34:28 -0800 | [diff] [blame] | 2609 | for (int id : dm.getDisplayIds()) { |
| 2610 | if (id != Display.DEFAULT_DISPLAY) { |
Wale Ogunwale | 2669851 | 2015-06-05 16:55:33 -0700 | [diff] [blame] | 2611 | Display display = |
| 2612 | dm.getCompatibleDisplay(id, appContext.getDisplayAdjustments(id)); |
Jeff Brown | efd43bd | 2012-09-21 17:02:35 -0700 | [diff] [blame] | 2613 | baseContext = appContext.createDisplayContext(display); |
| 2614 | break; |
| 2615 | } |
| 2616 | } |
| 2617 | } |
| 2618 | return baseContext; |
| 2619 | } |
| 2620 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 2621 | private void handleLaunchActivity(ActivityClientRecord r, Intent customIntent) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2622 | // If we are getting ready to gc after going to the background, well |
| 2623 | // we are back active so skip it. |
| 2624 | unscheduleGcIdler(); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 2625 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2626 | |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 2627 | if (r.profilerInfo != null) { |
| 2628 | mProfiler.setProfiler(r.profilerInfo); |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 2629 | mProfiler.startProfiling(); |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 2630 | } |
| 2631 | |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 2632 | // Make sure we are running with the most recent config. |
| 2633 | handleConfigurationChanged(null, null); |
| 2634 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2635 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2636 | TAG, "Handling launch of " + r); |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 2637 | |
Chet Haase | 0d1c27a | 2014-11-03 18:35:16 +0000 | [diff] [blame] | 2638 | // Initialize before creating the activity |
| 2639 | WindowManagerGlobal.initialize(); |
| 2640 | |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 2641 | Activity a = performLaunchActivity(r, customIntent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2642 | |
| 2643 | if (a != null) { |
Dianne Hackborn | 871ecdc | 2009-12-11 15:24:33 -0800 | [diff] [blame] | 2644 | r.createdConfig = new Configuration(mConfiguration); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 2645 | reportSizeConfigurations(r); |
Dianne Hackborn | 9e0f5d9 | 2010-02-22 15:05:42 -0800 | [diff] [blame] | 2646 | Bundle oldState = r.state; |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 2647 | handleResumeActivity(r.token, false, r.isForward, |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 2648 | !r.activity.mFinished && !r.startsNotResumed, r.lastProcessedSeq); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2649 | |
| 2650 | if (!r.activity.mFinished && r.startsNotResumed) { |
| 2651 | // The activity manager actually wants this one to start out |
| 2652 | // paused, because it needs to be visible but isn't in the |
| 2653 | // foreground. We accomplish this by going through the |
| 2654 | // normal startup (because activities expect to go through |
| 2655 | // onResume() the first time they run, before their window |
| 2656 | // is displayed), and then pausing it. However, in this case |
| 2657 | // we do -not- need to do the full pause cycle (of freezing |
| 2658 | // and such) because the activity manager assumes it can just |
| 2659 | // retain the current state it has. |
| 2660 | try { |
| 2661 | r.activity.mCalled = false; |
| 2662 | mInstrumentation.callActivityOnPause(r.activity); |
Dianne Hackborn | 9e0f5d9 | 2010-02-22 15:05:42 -0800 | [diff] [blame] | 2663 | // We need to keep around the original state, in case |
Dianne Hackborn | 03fcc33 | 2012-05-15 12:49:40 -0700 | [diff] [blame] | 2664 | // we need to be created again. But we only do this |
| 2665 | // for pre-Honeycomb apps, which always save their state |
| 2666 | // when pausing, so we can not have them save their state |
| 2667 | // when restarting from a paused state. For HC and later, |
| 2668 | // we want to (and can) let the state be saved as the normal |
| 2669 | // part of stopping the activity. |
| 2670 | if (r.isPreHoneycomb()) { |
| 2671 | r.state = oldState; |
| 2672 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2673 | if (!r.activity.mCalled) { |
| 2674 | throw new SuperNotCalledException( |
| 2675 | "Activity " + r.intent.getComponent().toShortString() + |
| 2676 | " did not call through to super.onPause()"); |
| 2677 | } |
| 2678 | |
| 2679 | } catch (SuperNotCalledException e) { |
| 2680 | throw e; |
| 2681 | |
| 2682 | } catch (Exception e) { |
| 2683 | if (!mInstrumentation.onException(r.activity, e)) { |
| 2684 | throw new RuntimeException( |
| 2685 | "Unable to pause activity " |
| 2686 | + r.intent.getComponent().toShortString() |
| 2687 | + ": " + e.toString(), e); |
| 2688 | } |
| 2689 | } |
| 2690 | r.paused = true; |
| 2691 | } |
| 2692 | } else { |
| 2693 | // If there was an error, for any reason, tell the activity |
| 2694 | // manager to stop us. |
| 2695 | try { |
| 2696 | ActivityManagerNative.getDefault() |
Wale Ogunwale | ba7881c | 2015-08-01 19:28:29 -0700 | [diff] [blame] | 2697 | .finishActivity(r.token, Activity.RESULT_CANCELED, null, |
| 2698 | Activity.DONT_FINISH_TASK_WITH_ACTIVITY); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2699 | } catch (RemoteException ex) { |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 2700 | // Ignore |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2701 | } |
| 2702 | } |
| 2703 | } |
| 2704 | |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 2705 | private void reportSizeConfigurations(ActivityClientRecord r) { |
| 2706 | Configuration[] configurations = r.activity.getResources().getSizeConfigurations(); |
| 2707 | if (configurations == null) { |
| 2708 | return; |
| 2709 | } |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 2710 | SparseIntArray horizontal = new SparseIntArray(); |
| 2711 | SparseIntArray vertical = new SparseIntArray(); |
| 2712 | SparseIntArray smallest = new SparseIntArray(); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 2713 | for (int i = configurations.length - 1; i >= 0; i--) { |
| 2714 | Configuration config = configurations[i]; |
| 2715 | if (config.screenHeightDp != Configuration.SCREEN_HEIGHT_DP_UNDEFINED) { |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 2716 | vertical.put(config.screenHeightDp, 0); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 2717 | } |
| 2718 | if (config.screenWidthDp != Configuration.SCREEN_WIDTH_DP_UNDEFINED) { |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 2719 | horizontal.put(config.screenWidthDp, 0); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 2720 | } |
| 2721 | if (config.smallestScreenWidthDp != Configuration.SMALLEST_SCREEN_WIDTH_DP_UNDEFINED) { |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 2722 | smallest.put(config.smallestScreenWidthDp, 0); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 2723 | } |
| 2724 | } |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 2725 | try { |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 2726 | ActivityManagerNative.getDefault().reportSizeConfigurations(r.token, |
| 2727 | horizontal.copyKeys(), vertical.copyKeys(), smallest.copyKeys()); |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 2728 | } catch (RemoteException ex) { |
| 2729 | } |
| 2730 | |
| 2731 | } |
| 2732 | |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 2733 | private void deliverNewIntents(ActivityClientRecord r, List<ReferrerIntent> intents) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2734 | final int N = intents.size(); |
| 2735 | for (int i=0; i<N; i++) { |
Dianne Hackborn | a01a0fa | 2014-12-02 10:33:14 -0800 | [diff] [blame] | 2736 | ReferrerIntent intent = intents.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2737 | intent.setExtrasClassLoader(r.activity.getClassLoader()); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 2738 | intent.prepareToEnterProcess(); |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 2739 | r.activity.mFragments.noteStateNotSaved(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2740 | mInstrumentation.callActivityOnNewIntent(r.activity, intent); |
| 2741 | } |
| 2742 | } |
| 2743 | |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 2744 | public final void performNewIntents(IBinder token, List<ReferrerIntent> intents) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2745 | ActivityClientRecord r = mActivities.get(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2746 | if (r != null) { |
| 2747 | final boolean resumed = !r.paused; |
| 2748 | if (resumed) { |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 2749 | r.activity.mTemporaryPause = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2750 | mInstrumentation.callActivityOnPause(r.activity); |
| 2751 | } |
| 2752 | deliverNewIntents(r, intents); |
| 2753 | if (resumed) { |
Dianne Hackborn | b46ed76 | 2011-06-02 18:33:15 -0700 | [diff] [blame] | 2754 | r.activity.performResume(); |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 2755 | r.activity.mTemporaryPause = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2756 | } |
| 2757 | } |
| 2758 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2759 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 2760 | private void handleNewIntent(NewIntentData data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2761 | performNewIntents(data.token, data.intents); |
| 2762 | } |
| 2763 | |
Adam Skory | dfc7fd7 | 2013-08-05 19:23:41 -0700 | [diff] [blame] | 2764 | public void handleRequestAssistContextExtras(RequestAssistContextExtras cmd) { |
Dianne Hackborn | 782d498 | 2015-07-08 17:36:37 -0700 | [diff] [blame] | 2765 | if (mLastAssistStructure != null) { |
| 2766 | AssistStructure structure = mLastAssistStructure.get(); |
| 2767 | if (structure != null) { |
| 2768 | structure.clearSendChannel(); |
| 2769 | } |
| 2770 | } |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 2771 | Bundle data = new Bundle(); |
Dianne Hackborn | 09d57fe | 2015-05-27 18:05:52 -0700 | [diff] [blame] | 2772 | AssistStructure structure = null; |
| 2773 | AssistContent content = new AssistContent(); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 2774 | ActivityClientRecord r = mActivities.get(cmd.activityToken); |
Dianne Hackborn | a3acdb3 | 2015-06-08 17:07:40 -0700 | [diff] [blame] | 2775 | Uri referrer = null; |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 2776 | if (r != null) { |
| 2777 | r.activity.getApplication().dispatchOnProvideAssistData(r.activity, data); |
| 2778 | r.activity.onProvideAssistData(data); |
Dianne Hackborn | a3acdb3 | 2015-06-08 17:07:40 -0700 | [diff] [blame] | 2779 | referrer = r.activity.onProvideReferrer(); |
Dianne Hackborn | a83ce1d | 2015-03-11 15:16:13 -0700 | [diff] [blame] | 2780 | if (cmd.requestType == ActivityManager.ASSIST_CONTEXT_FULL) { |
Dianne Hackborn | 09d57fe | 2015-05-27 18:05:52 -0700 | [diff] [blame] | 2781 | structure = new AssistStructure(r.activity); |
Adam Skory | 4aaed14 | 2015-04-22 11:29:31 -0600 | [diff] [blame] | 2782 | Intent activityIntent = r.activity.getIntent(); |
Dianne Hackborn | 09d57fe | 2015-05-27 18:05:52 -0700 | [diff] [blame] | 2783 | if (activityIntent != null && (r.window == null || |
| 2784 | (r.window.getAttributes().flags |
| 2785 | & WindowManager.LayoutParams.FLAG_SECURE) == 0)) { |
Adam Skory | 4aaed14 | 2015-04-22 11:29:31 -0600 | [diff] [blame] | 2786 | Intent intent = new Intent(activityIntent); |
| 2787 | intent.setFlags(intent.getFlags() & ~(Intent.FLAG_GRANT_WRITE_URI_PERMISSION |
| 2788 | | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION)); |
| 2789 | intent.removeUnsafeExtras(); |
Adam Skory | cd70c64 | 2015-06-05 11:41:55 -0600 | [diff] [blame] | 2790 | content.setDefaultIntent(intent); |
Adam Skory | 4aaed14 | 2015-04-22 11:29:31 -0600 | [diff] [blame] | 2791 | } else { |
Adam Skory | cd70c64 | 2015-06-05 11:41:55 -0600 | [diff] [blame] | 2792 | content.setDefaultIntent(new Intent()); |
Adam Skory | 4aaed14 | 2015-04-22 11:29:31 -0600 | [diff] [blame] | 2793 | } |
Dianne Hackborn | a83ce1d | 2015-03-11 15:16:13 -0700 | [diff] [blame] | 2794 | r.activity.onProvideAssistContent(content); |
Dianne Hackborn | a83ce1d | 2015-03-11 15:16:13 -0700 | [diff] [blame] | 2795 | } |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 2796 | } |
Dianne Hackborn | 09d57fe | 2015-05-27 18:05:52 -0700 | [diff] [blame] | 2797 | if (structure == null) { |
| 2798 | structure = new AssistStructure(); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 2799 | } |
Dianne Hackborn | 782d498 | 2015-07-08 17:36:37 -0700 | [diff] [blame] | 2800 | mLastAssistStructure = new WeakReference<>(structure); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 2801 | IActivityManager mgr = ActivityManagerNative.getDefault(); |
| 2802 | try { |
Dianne Hackborn | a3acdb3 | 2015-06-08 17:07:40 -0700 | [diff] [blame] | 2803 | mgr.reportAssistContextExtras(cmd.requestToken, data, structure, content, referrer); |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 2804 | } catch (RemoteException e) { |
| 2805 | } |
| 2806 | } |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 2807 | |
| 2808 | public void handleTranslucentConversionComplete(IBinder token, boolean drawComplete) { |
| 2809 | ActivityClientRecord r = mActivities.get(token); |
| 2810 | if (r != null) { |
| 2811 | r.activity.onTranslucentConversionComplete(drawComplete); |
| 2812 | } |
| 2813 | } |
| 2814 | |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 2815 | public void onNewActivityOptions(IBinder token, ActivityOptions options) { |
| 2816 | ActivityClientRecord r = mActivities.get(token); |
| 2817 | if (r != null) { |
| 2818 | r.activity.onNewActivityOptions(options); |
| 2819 | } |
| 2820 | } |
| 2821 | |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 2822 | public void handleCancelVisibleBehind(IBinder token) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 2823 | ActivityClientRecord r = mActivities.get(token); |
| 2824 | if (r != null) { |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 2825 | mSomeActivitiesChanged = true; |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 2826 | final Activity activity = r.activity; |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 2827 | if (activity.mVisibleBehind) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 2828 | activity.mCalled = false; |
Jose Lima | fcf7083 | 2014-08-27 23:09:05 -0700 | [diff] [blame] | 2829 | activity.onVisibleBehindCanceled(); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 2830 | // Tick, tick, tick. The activity has 500 msec to return or it will be destroyed. |
| 2831 | if (!activity.mCalled) { |
| 2832 | throw new SuperNotCalledException("Activity " + activity.getLocalClassName() + |
Jose Lima | fcf7083 | 2014-08-27 23:09:05 -0700 | [diff] [blame] | 2833 | " did not call through to super.onVisibleBehindCanceled()"); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 2834 | } |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 2835 | activity.mVisibleBehind = false; |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 2836 | } |
| 2837 | } |
| 2838 | try { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 2839 | ActivityManagerNative.getDefault().backgroundResourcesReleased(token); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 2840 | } catch (RemoteException e) { |
| 2841 | } |
| 2842 | } |
| 2843 | |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 2844 | public void handleOnBackgroundVisibleBehindChanged(IBinder token, boolean visible) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 2845 | ActivityClientRecord r = mActivities.get(token); |
| 2846 | if (r != null) { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 2847 | r.activity.onBackgroundVisibleBehindChanged(visible); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 2848 | } |
| 2849 | } |
| 2850 | |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 2851 | public void handleInstallProvider(ProviderInfo info) { |
Jeff Sharkey | bb2e2ca | 2014-10-23 11:42:31 -0700 | [diff] [blame] | 2852 | final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); |
| 2853 | try { |
| 2854 | installContentProviders(mInitialApplication, Lists.newArrayList(info)); |
| 2855 | } finally { |
| 2856 | StrictMode.setThreadPolicy(oldPolicy); |
| 2857 | } |
Jeff Sharkey | dd97f42 | 2013-10-08 17:01:30 -0700 | [diff] [blame] | 2858 | } |
| 2859 | |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 2860 | private void handleEnterAnimationComplete(IBinder token) { |
| 2861 | ActivityClientRecord r = mActivities.get(token); |
| 2862 | if (r != null) { |
Filip Gruszczynski | 6eafa90 | 2014-11-14 14:24:37 -0800 | [diff] [blame] | 2863 | r.activity.dispatchEnterAnimationComplete(); |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 2864 | } |
| 2865 | } |
| 2866 | |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 2867 | private void handleStartBinderTracking() { |
| 2868 | Binder.enableTracing(); |
| 2869 | } |
| 2870 | |
| 2871 | private void handleStopBinderTrackingAndDump(ParcelFileDescriptor fd) { |
| 2872 | try { |
| 2873 | Binder.disableTracing(); |
| 2874 | Binder.getTransactionTracker().writeTracesToFile(fd); |
| 2875 | } finally { |
| 2876 | IoUtils.closeQuietly(fd); |
| 2877 | Binder.getTransactionTracker().clearTraces(); |
| 2878 | } |
| 2879 | } |
| 2880 | |
Wale Ogunwale | 3b93a4d | 2016-01-29 17:46:53 -0800 | [diff] [blame] | 2881 | private void handleMultiWindowChanged(IBinder token, boolean inMultiWindow) { |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 2882 | final ActivityClientRecord r = mActivities.get(token); |
| 2883 | if (r != null) { |
Wale Ogunwale | 3b93a4d | 2016-01-29 17:46:53 -0800 | [diff] [blame] | 2884 | r.activity.onMultiWindowChanged(inMultiWindow); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 2885 | } |
| 2886 | } |
| 2887 | |
Wale Ogunwale | 3b93a4d | 2016-01-29 17:46:53 -0800 | [diff] [blame] | 2888 | private void handlePictureInPictureChanged(IBinder token, boolean inPip) { |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 2889 | final ActivityClientRecord r = mActivities.get(token); |
| 2890 | if (r != null) { |
Wale Ogunwale | 3b93a4d | 2016-01-29 17:46:53 -0800 | [diff] [blame] | 2891 | r.activity.onPictureInPictureChanged(inPip); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 2892 | } |
| 2893 | } |
| 2894 | |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 2895 | private void handleLocalVoiceInteractionStarted(IBinder token, IVoiceInteractor interactor) { |
| 2896 | final ActivityClientRecord r = mActivities.get(token); |
| 2897 | if (r != null) { |
| 2898 | r.voiceInteractor = interactor; |
| 2899 | r.activity.setVoiceInteractor(interactor); |
| 2900 | if (interactor == null) { |
| 2901 | r.activity.onLocalVoiceInteractionStopped(); |
| 2902 | } else { |
| 2903 | r.activity.onLocalVoiceInteractionStarted(); |
| 2904 | } |
| 2905 | } |
| 2906 | } |
| 2907 | |
Brad Fitzpatrick | bfb1919 | 2010-10-29 15:25:44 -0700 | [diff] [blame] | 2908 | private static final ThreadLocal<Intent> sCurrentBroadcastIntent = new ThreadLocal<Intent>(); |
| 2909 | |
| 2910 | /** |
| 2911 | * Return the Intent that's currently being handled by a |
| 2912 | * BroadcastReceiver on this thread, or null if none. |
| 2913 | * @hide |
| 2914 | */ |
| 2915 | public static Intent getIntentBeingBroadcast() { |
| 2916 | return sCurrentBroadcastIntent.get(); |
| 2917 | } |
| 2918 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 2919 | private void handleReceiver(ReceiverData data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2920 | // If we are getting ready to gc after going to the background, well |
| 2921 | // we are back active so skip it. |
| 2922 | unscheduleGcIdler(); |
| 2923 | |
| 2924 | String component = data.intent.getComponent().getClassName(); |
| 2925 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 2926 | LoadedApk packageInfo = getPackageInfoNoCheck( |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2927 | data.info.applicationInfo, data.compatInfo); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2928 | |
| 2929 | IActivityManager mgr = ActivityManagerNative.getDefault(); |
| 2930 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 2931 | BroadcastReceiver receiver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2932 | try { |
| 2933 | java.lang.ClassLoader cl = packageInfo.getClassLoader(); |
| 2934 | data.intent.setExtrasClassLoader(cl); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 2935 | data.intent.prepareToEnterProcess(); |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 2936 | data.setExtrasClassLoader(cl); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2937 | receiver = (BroadcastReceiver)cl.loadClass(component).newInstance(); |
| 2938 | } catch (Exception e) { |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 2939 | if (DEBUG_BROADCAST) Slog.i(TAG, |
| 2940 | "Finishing failed broadcast to " + data.intent.getComponent()); |
| 2941 | data.sendFinished(mgr); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2942 | throw new RuntimeException( |
| 2943 | "Unable to instantiate receiver " + component |
| 2944 | + ": " + e.toString(), e); |
| 2945 | } |
| 2946 | |
| 2947 | try { |
Dianne Hackborn | 0be1f78 | 2009-11-09 12:30:12 -0800 | [diff] [blame] | 2948 | Application app = packageInfo.makeApplication(false, mInstrumentation); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 2949 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2950 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2951 | TAG, "Performing receive of " + data.intent |
| 2952 | + ": app=" + app |
| 2953 | + ", appName=" + app.getPackageName() |
| 2954 | + ", pkg=" + packageInfo.getPackageName() |
| 2955 | + ", comp=" + data.intent.getComponent().toShortString() |
| 2956 | + ", dir=" + packageInfo.getAppDir()); |
| 2957 | |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 2958 | ContextImpl context = (ContextImpl)app.getBaseContext(); |
Brad Fitzpatrick | bfb1919 | 2010-10-29 15:25:44 -0700 | [diff] [blame] | 2959 | sCurrentBroadcastIntent.set(data.intent); |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 2960 | receiver.setPendingResult(data); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2961 | receiver.onReceive(context.getReceiverRestrictedContext(), |
| 2962 | data.intent); |
| 2963 | } catch (Exception e) { |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 2964 | if (DEBUG_BROADCAST) Slog.i(TAG, |
| 2965 | "Finishing failed broadcast to " + data.intent.getComponent()); |
| 2966 | data.sendFinished(mgr); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2967 | if (!mInstrumentation.onException(receiver, e)) { |
| 2968 | throw new RuntimeException( |
| 2969 | "Unable to start receiver " + component |
| 2970 | + ": " + e.toString(), e); |
| 2971 | } |
Brad Fitzpatrick | bfb1919 | 2010-10-29 15:25:44 -0700 | [diff] [blame] | 2972 | } finally { |
| 2973 | sCurrentBroadcastIntent.set(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2974 | } |
| 2975 | |
Dianne Hackborn | e829fef | 2010-10-26 17:44:01 -0700 | [diff] [blame] | 2976 | if (receiver.getPendingResult() != null) { |
| 2977 | data.finish(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2978 | } |
| 2979 | } |
| 2980 | |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 2981 | // Instantiate a BackupAgent and tell it that it's alive |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 2982 | private void handleCreateBackupAgent(CreateBackupAgentData data) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 2983 | if (DEBUG_BACKUP) Slog.v(TAG, "handleCreateBackupAgent: " + data); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 2984 | |
Christopher Tate | 346acb1 | 2012-10-15 19:20:25 -0700 | [diff] [blame] | 2985 | // Sanity check the requested target package's uid against ours |
| 2986 | try { |
| 2987 | PackageInfo requestedPackage = getPackageManager().getPackageInfo( |
| 2988 | data.appInfo.packageName, 0, UserHandle.myUserId()); |
| 2989 | if (requestedPackage.applicationInfo.uid != Process.myUid()) { |
| 2990 | Slog.w(TAG, "Asked to instantiate non-matching package " |
| 2991 | + data.appInfo.packageName); |
| 2992 | return; |
| 2993 | } |
| 2994 | } catch (RemoteException e) { |
| 2995 | Slog.e(TAG, "Can't reach package manager", e); |
| 2996 | return; |
| 2997 | } |
| 2998 | |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 2999 | // no longer idle; we have backup work to do |
| 3000 | unscheduleGcIdler(); |
| 3001 | |
| 3002 | // instantiate the BackupAgent class named in the manifest |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 3003 | LoadedApk packageInfo = getPackageInfoNoCheck(data.appInfo, data.compatInfo); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3004 | String packageName = packageInfo.mPackageName; |
Christopher Tate | 346acb1 | 2012-10-15 19:20:25 -0700 | [diff] [blame] | 3005 | if (packageName == null) { |
| 3006 | Slog.d(TAG, "Asked to create backup agent for nonexistent package"); |
| 3007 | return; |
| 3008 | } |
| 3009 | |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3010 | String classname = data.appInfo.backupAgentName; |
Christopher Tate | 79ec80d | 2011-06-24 14:58:49 -0700 | [diff] [blame] | 3011 | // full backup operation but no app-supplied agent? use the default implementation |
| 3012 | if (classname == null && (data.backupMode == IApplicationThread.BACKUP_MODE_FULL |
| 3013 | || data.backupMode == IApplicationThread.BACKUP_MODE_RESTORE_FULL)) { |
Christopher Tate | 4a627c7 | 2011-04-01 14:43:32 -0700 | [diff] [blame] | 3014 | classname = "android.app.backup.FullBackupAgent"; |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3015 | } |
Christopher Tate | 4a627c7 | 2011-04-01 14:43:32 -0700 | [diff] [blame] | 3016 | |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3017 | try { |
Christopher Tate | d1475e0 | 2009-07-09 15:36:17 -0700 | [diff] [blame] | 3018 | IBinder binder = null; |
Christopher Tate | 2e40d11 | 2014-07-15 12:37:38 -0700 | [diff] [blame] | 3019 | BackupAgent agent = mBackupAgents.get(packageName); |
| 3020 | if (agent != null) { |
| 3021 | // reusing the existing instance |
| 3022 | if (DEBUG_BACKUP) { |
| 3023 | Slog.v(TAG, "Reusing existing agent instance"); |
Christopher Tate | d1475e0 | 2009-07-09 15:36:17 -0700 | [diff] [blame] | 3024 | } |
Christopher Tate | 2e40d11 | 2014-07-15 12:37:38 -0700 | [diff] [blame] | 3025 | binder = agent.onBind(); |
| 3026 | } else { |
| 3027 | try { |
| 3028 | if (DEBUG_BACKUP) Slog.v(TAG, "Initializing agent class " + classname); |
| 3029 | |
| 3030 | java.lang.ClassLoader cl = packageInfo.getClassLoader(); |
| 3031 | agent = (BackupAgent) cl.loadClass(classname).newInstance(); |
| 3032 | |
| 3033 | // set up the agent's context |
| 3034 | ContextImpl context = ContextImpl.createAppContext(this, packageInfo); |
| 3035 | context.setOuterContext(agent); |
| 3036 | agent.attach(context); |
| 3037 | |
| 3038 | agent.onCreate(); |
| 3039 | binder = agent.onBind(); |
| 3040 | mBackupAgents.put(packageName, agent); |
| 3041 | } catch (Exception e) { |
| 3042 | // If this is during restore, fail silently; otherwise go |
| 3043 | // ahead and let the user see the crash. |
| 3044 | Slog.e(TAG, "Agent threw during creation: " + e); |
| 3045 | if (data.backupMode != IApplicationThread.BACKUP_MODE_RESTORE |
| 3046 | && data.backupMode != IApplicationThread.BACKUP_MODE_RESTORE_FULL) { |
| 3047 | throw e; |
| 3048 | } |
| 3049 | // falling through with 'binder' still null |
| 3050 | } |
Christopher Tate | d1475e0 | 2009-07-09 15:36:17 -0700 | [diff] [blame] | 3051 | } |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3052 | |
| 3053 | // tell the OS that we're live now |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3054 | try { |
| 3055 | ActivityManagerNative.getDefault().backupAgentCreated(packageName, binder); |
| 3056 | } catch (RemoteException e) { |
| 3057 | // nothing to do. |
| 3058 | } |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3059 | } catch (Exception e) { |
| 3060 | throw new RuntimeException("Unable to create BackupAgent " |
Christopher Tate | 4a627c7 | 2011-04-01 14:43:32 -0700 | [diff] [blame] | 3061 | + classname + ": " + e.toString(), e); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3062 | } |
| 3063 | } |
| 3064 | |
| 3065 | // Tear down a BackupAgent |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3066 | private void handleDestroyBackupAgent(CreateBackupAgentData data) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3067 | if (DEBUG_BACKUP) Slog.v(TAG, "handleDestroyBackupAgent: " + data); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3068 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 3069 | LoadedApk packageInfo = getPackageInfoNoCheck(data.appInfo, data.compatInfo); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3070 | String packageName = packageInfo.mPackageName; |
| 3071 | BackupAgent agent = mBackupAgents.get(packageName); |
| 3072 | if (agent != null) { |
| 3073 | try { |
| 3074 | agent.onDestroy(); |
| 3075 | } catch (Exception e) { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 3076 | 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] | 3077 | e.printStackTrace(); |
| 3078 | } |
| 3079 | mBackupAgents.remove(packageName); |
| 3080 | } else { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 3081 | Slog.w(TAG, "Attempt to destroy unknown backup agent " + data); |
Christopher Tate | 181fafa | 2009-05-14 11:12:14 -0700 | [diff] [blame] | 3082 | } |
| 3083 | } |
| 3084 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3085 | private void handleCreateService(CreateServiceData data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3086 | // If we are getting ready to gc after going to the background, well |
| 3087 | // we are back active so skip it. |
| 3088 | unscheduleGcIdler(); |
| 3089 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3090 | LoadedApk packageInfo = getPackageInfoNoCheck( |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 3091 | data.info.applicationInfo, data.compatInfo); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3092 | Service service = null; |
| 3093 | try { |
| 3094 | java.lang.ClassLoader cl = packageInfo.getClassLoader(); |
| 3095 | service = (Service) cl.loadClass(data.info.name).newInstance(); |
| 3096 | } catch (Exception e) { |
| 3097 | if (!mInstrumentation.onException(service, e)) { |
| 3098 | throw new RuntimeException( |
| 3099 | "Unable to instantiate service " + data.info.name |
| 3100 | + ": " + e.toString(), e); |
| 3101 | } |
| 3102 | } |
| 3103 | |
| 3104 | try { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3105 | 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] | 3106 | |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 3107 | ContextImpl context = ContextImpl.createAppContext(this, packageInfo); |
| 3108 | context.setOuterContext(service); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3109 | |
Dianne Hackborn | 0be1f78 | 2009-11-09 12:30:12 -0800 | [diff] [blame] | 3110 | Application app = packageInfo.makeApplication(false, mInstrumentation); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3111 | service.attach(context, this, data.info.name, data.token, app, |
| 3112 | ActivityManagerNative.getDefault()); |
| 3113 | service.onCreate(); |
| 3114 | mServices.put(data.token, service); |
| 3115 | try { |
Dianne Hackborn | f6f9f2d | 2009-08-21 16:26:03 -0700 | [diff] [blame] | 3116 | ActivityManagerNative.getDefault().serviceDoneExecuting( |
Dianne Hackborn | 455625e | 2015-01-21 09:55:13 -0800 | [diff] [blame] | 3117 | data.token, SERVICE_DONE_EXECUTING_ANON, 0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3118 | } catch (RemoteException e) { |
| 3119 | // nothing to do. |
| 3120 | } |
| 3121 | } catch (Exception e) { |
| 3122 | if (!mInstrumentation.onException(service, e)) { |
| 3123 | throw new RuntimeException( |
| 3124 | "Unable to create service " + data.info.name |
| 3125 | + ": " + e.toString(), e); |
| 3126 | } |
| 3127 | } |
| 3128 | } |
| 3129 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3130 | private void handleBindService(BindServiceData data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3131 | Service s = mServices.get(data.token); |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 3132 | if (DEBUG_SERVICE) |
| 3133 | Slog.v(TAG, "handleBindService s=" + s + " rebind=" + data.rebind); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3134 | if (s != null) { |
| 3135 | try { |
| 3136 | data.intent.setExtrasClassLoader(s.getClassLoader()); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 3137 | data.intent.prepareToEnterProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3138 | try { |
| 3139 | if (!data.rebind) { |
| 3140 | IBinder binder = s.onBind(data.intent); |
| 3141 | ActivityManagerNative.getDefault().publishService( |
| 3142 | data.token, data.intent, binder); |
| 3143 | } else { |
| 3144 | s.onRebind(data.intent); |
| 3145 | ActivityManagerNative.getDefault().serviceDoneExecuting( |
Dianne Hackborn | 455625e | 2015-01-21 09:55:13 -0800 | [diff] [blame] | 3146 | data.token, SERVICE_DONE_EXECUTING_ANON, 0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3147 | } |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 3148 | ensureJitEnabled(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3149 | } catch (RemoteException ex) { |
| 3150 | } |
| 3151 | } catch (Exception e) { |
| 3152 | if (!mInstrumentation.onException(s, e)) { |
| 3153 | throw new RuntimeException( |
| 3154 | "Unable to bind to service " + s |
| 3155 | + " with " + data.intent + ": " + e.toString(), e); |
| 3156 | } |
| 3157 | } |
| 3158 | } |
| 3159 | } |
| 3160 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3161 | private void handleUnbindService(BindServiceData data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3162 | Service s = mServices.get(data.token); |
| 3163 | if (s != null) { |
| 3164 | try { |
| 3165 | data.intent.setExtrasClassLoader(s.getClassLoader()); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 3166 | data.intent.prepareToEnterProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3167 | boolean doRebind = s.onUnbind(data.intent); |
| 3168 | try { |
| 3169 | if (doRebind) { |
| 3170 | ActivityManagerNative.getDefault().unbindFinished( |
| 3171 | data.token, data.intent, doRebind); |
| 3172 | } else { |
| 3173 | ActivityManagerNative.getDefault().serviceDoneExecuting( |
Dianne Hackborn | 455625e | 2015-01-21 09:55:13 -0800 | [diff] [blame] | 3174 | data.token, SERVICE_DONE_EXECUTING_ANON, 0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3175 | } |
| 3176 | } catch (RemoteException ex) { |
| 3177 | } |
| 3178 | } catch (Exception e) { |
| 3179 | if (!mInstrumentation.onException(s, e)) { |
| 3180 | throw new RuntimeException( |
| 3181 | "Unable to unbind to service " + s |
| 3182 | + " with " + data.intent + ": " + e.toString(), e); |
| 3183 | } |
| 3184 | } |
| 3185 | } |
| 3186 | } |
| 3187 | |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 3188 | private void handleDumpService(DumpComponentInfo info) { |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3189 | final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); |
| 3190 | try { |
| 3191 | Service s = mServices.get(info.token); |
| 3192 | if (s != null) { |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 3193 | PrintWriter pw = new FastPrintWriter(new FileOutputStream( |
| 3194 | info.fd.getFileDescriptor())); |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3195 | s.dump(info.fd.getFileDescriptor(), pw, info.args); |
| 3196 | pw.flush(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3197 | } |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3198 | } finally { |
| 3199 | IoUtils.closeQuietly(info.fd); |
| 3200 | StrictMode.setThreadPolicy(oldPolicy); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3201 | } |
| 3202 | } |
| 3203 | |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 3204 | private void handleDumpActivity(DumpComponentInfo info) { |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3205 | final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); |
| 3206 | try { |
| 3207 | ActivityClientRecord r = mActivities.get(info.token); |
| 3208 | if (r != null && r.activity != null) { |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 3209 | PrintWriter pw = new FastPrintWriter(new FileOutputStream( |
| 3210 | info.fd.getFileDescriptor())); |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3211 | r.activity.dump(info.prefix, info.fd.getFileDescriptor(), pw, info.args); |
| 3212 | pw.flush(); |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 3213 | } |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3214 | } finally { |
| 3215 | IoUtils.closeQuietly(info.fd); |
| 3216 | StrictMode.setThreadPolicy(oldPolicy); |
Dianne Hackborn | 625ac27 | 2010-09-17 18:29:22 -0700 | [diff] [blame] | 3217 | } |
| 3218 | } |
| 3219 | |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 3220 | private void handleDumpProvider(DumpComponentInfo info) { |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3221 | final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); |
| 3222 | try { |
| 3223 | ProviderClientRecord r = mLocalProviders.get(info.token); |
| 3224 | if (r != null && r.mLocalProvider != null) { |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 3225 | PrintWriter pw = new FastPrintWriter(new FileOutputStream( |
| 3226 | info.fd.getFileDescriptor())); |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3227 | r.mLocalProvider.dump(info.fd.getFileDescriptor(), pw, info.args); |
| 3228 | pw.flush(); |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 3229 | } |
Jeff Sharkey | e861b42 | 2012-03-01 20:59:22 -0800 | [diff] [blame] | 3230 | } finally { |
| 3231 | IoUtils.closeQuietly(info.fd); |
| 3232 | StrictMode.setThreadPolicy(oldPolicy); |
Marco Nelissen | 18cb287 | 2011-11-15 11:19:53 -0800 | [diff] [blame] | 3233 | } |
| 3234 | } |
| 3235 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3236 | private void handleServiceArgs(ServiceArgsData data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3237 | Service s = mServices.get(data.token); |
| 3238 | if (s != null) { |
| 3239 | try { |
| 3240 | if (data.args != null) { |
| 3241 | data.args.setExtrasClassLoader(s.getClassLoader()); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 3242 | data.args.prepareToEnterProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3243 | } |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 3244 | int res; |
| 3245 | if (!data.taskRemoved) { |
| 3246 | res = s.onStartCommand(data.args, data.flags, data.startId); |
| 3247 | } else { |
| 3248 | s.onTaskRemoved(data.args); |
| 3249 | res = Service.START_TASK_REMOVED_COMPLETE; |
| 3250 | } |
Brad Fitzpatrick | 333b8cb | 2010-08-26 12:04:57 -0700 | [diff] [blame] | 3251 | |
| 3252 | QueuedWork.waitToFinish(); |
| 3253 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3254 | try { |
Dianne Hackborn | f6f9f2d | 2009-08-21 16:26:03 -0700 | [diff] [blame] | 3255 | ActivityManagerNative.getDefault().serviceDoneExecuting( |
Dianne Hackborn | 455625e | 2015-01-21 09:55:13 -0800 | [diff] [blame] | 3256 | data.token, SERVICE_DONE_EXECUTING_START, data.startId, res); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3257 | } catch (RemoteException e) { |
| 3258 | // nothing to do. |
| 3259 | } |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 3260 | ensureJitEnabled(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3261 | } catch (Exception e) { |
| 3262 | if (!mInstrumentation.onException(s, e)) { |
| 3263 | throw new RuntimeException( |
| 3264 | "Unable to start service " + s |
| 3265 | + " with " + data.args + ": " + e.toString(), e); |
| 3266 | } |
| 3267 | } |
| 3268 | } |
| 3269 | } |
| 3270 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3271 | private void handleStopService(IBinder token) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3272 | Service s = mServices.remove(token); |
| 3273 | if (s != null) { |
| 3274 | try { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3275 | if (localLOGV) Slog.v(TAG, "Destroying service " + s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3276 | s.onDestroy(); |
| 3277 | Context context = s.getBaseContext(); |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 3278 | if (context instanceof ContextImpl) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3279 | final String who = s.getClassName(); |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 3280 | ((ContextImpl) context).scheduleFinalCleanup(who, "Service"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3281 | } |
Brad Fitzpatrick | 333b8cb | 2010-08-26 12:04:57 -0700 | [diff] [blame] | 3282 | |
| 3283 | QueuedWork.waitToFinish(); |
| 3284 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3285 | try { |
Dianne Hackborn | f6f9f2d | 2009-08-21 16:26:03 -0700 | [diff] [blame] | 3286 | ActivityManagerNative.getDefault().serviceDoneExecuting( |
Dianne Hackborn | 455625e | 2015-01-21 09:55:13 -0800 | [diff] [blame] | 3287 | token, SERVICE_DONE_EXECUTING_STOP, 0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3288 | } catch (RemoteException e) { |
| 3289 | // nothing to do. |
Craig Mautner | 66c4a82 | 2015-01-16 12:48:16 -0800 | [diff] [blame] | 3290 | Slog.i(TAG, "handleStopService: unable to execute serviceDoneExecuting for " |
| 3291 | + token, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3292 | } |
| 3293 | } catch (Exception e) { |
| 3294 | if (!mInstrumentation.onException(s, e)) { |
| 3295 | throw new RuntimeException( |
| 3296 | "Unable to stop service " + s |
| 3297 | + ": " + e.toString(), e); |
| 3298 | } |
Craig Mautner | 66c4a82 | 2015-01-16 12:48:16 -0800 | [diff] [blame] | 3299 | Slog.i(TAG, "handleStopService: exception for " + token, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3300 | } |
Craig Mautner | 9776ad4 | 2015-01-15 14:38:39 -0800 | [diff] [blame] | 3301 | } else { |
| 3302 | Slog.i(TAG, "handleStopService: token=" + token + " not found."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3303 | } |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3304 | //Slog.i(TAG, "Running services: " + mServices); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3305 | } |
| 3306 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3307 | public final ActivityClientRecord performResumeActivity(IBinder token, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3308 | boolean clearHide) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3309 | ActivityClientRecord r = mActivities.get(token); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3310 | if (localLOGV) Slog.v(TAG, "Performing resume of " + r |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3311 | + " finished=" + r.activity.mFinished); |
| 3312 | if (r != null && !r.activity.mFinished) { |
| 3313 | if (clearHide) { |
| 3314 | r.hideForNow = false; |
| 3315 | r.activity.mStartedActivity = false; |
| 3316 | } |
| 3317 | try { |
Dianne Hackborn | 6bdd3a1 | 2015-08-05 15:01:28 -0700 | [diff] [blame] | 3318 | r.activity.onStateNotSaved(); |
Dianne Hackborn | 689586d | 2012-10-01 18:23:04 -0700 | [diff] [blame] | 3319 | r.activity.mFragments.noteStateNotSaved(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3320 | if (r.pendingIntents != null) { |
| 3321 | deliverNewIntents(r, r.pendingIntents); |
| 3322 | r.pendingIntents = null; |
| 3323 | } |
| 3324 | if (r.pendingResults != null) { |
| 3325 | deliverResults(r, r.pendingResults); |
| 3326 | r.pendingResults = null; |
| 3327 | } |
| 3328 | r.activity.performResume(); |
| 3329 | |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 3330 | EventLog.writeEvent(LOG_AM_ON_RESUME_CALLED, |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 3331 | UserHandle.myUserId(), r.activity.getComponentName().getClassName()); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3332 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3333 | r.paused = false; |
| 3334 | r.stopped = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3335 | r.state = null; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3336 | r.persistentState = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3337 | } catch (Exception e) { |
| 3338 | if (!mInstrumentation.onException(r.activity, e)) { |
| 3339 | throw new RuntimeException( |
| 3340 | "Unable to resume activity " |
| 3341 | + r.intent.getComponent().toShortString() |
| 3342 | + ": " + e.toString(), e); |
| 3343 | } |
| 3344 | } |
| 3345 | } |
| 3346 | return r; |
| 3347 | } |
| 3348 | |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 3349 | static final void cleanUpPendingRemoveWindows(ActivityClientRecord r, boolean force) { |
| 3350 | if (r.mPreserveWindow && !force) { |
| 3351 | return; |
| 3352 | } |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 3353 | if (r.mPendingRemoveWindow != null) { |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 3354 | r.mPendingRemoveWindowManager.removeViewImmediate( |
| 3355 | r.mPendingRemoveWindow.getDecorView()); |
| 3356 | IBinder wtoken = r.mPendingRemoveWindow.getDecorView().getWindowToken(); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 3357 | if (wtoken != null) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 3358 | WindowManagerGlobal.getInstance().closeAll(wtoken, |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 3359 | r.activity.getClass().getName(), "Activity"); |
| 3360 | } |
| 3361 | } |
| 3362 | r.mPendingRemoveWindow = null; |
| 3363 | r.mPendingRemoveWindowManager = null; |
| 3364 | } |
| 3365 | |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 3366 | final void handleResumeActivity(IBinder token, |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 3367 | boolean clearHide, boolean isForward, boolean reallyResume, int seq) { |
| 3368 | ActivityClientRecord r = mActivities.get(token); |
| 3369 | if (!checkAndUpdateLifecycleSeq(seq, r, "resumeActivity")) { |
| 3370 | return; |
| 3371 | } |
| 3372 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3373 | // If we are getting ready to gc after going to the background, well |
| 3374 | // we are back active so skip it. |
| 3375 | unscheduleGcIdler(); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3376 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3377 | |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 3378 | // TODO Push resumeArgs into the activity for consideration |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 3379 | r = performResumeActivity(token, clearHide); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3380 | |
| 3381 | if (r != null) { |
| 3382 | final Activity a = r.activity; |
| 3383 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3384 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3385 | TAG, "Resume " + r + " started activity: " + |
| 3386 | a.mStartedActivity + ", hideForNow: " + r.hideForNow |
| 3387 | + ", finished: " + a.mFinished); |
| 3388 | |
| 3389 | final int forwardBit = isForward ? |
| 3390 | WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION : 0; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3391 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3392 | // If the window hasn't yet been added to the window manager, |
| 3393 | // and this guy didn't finish itself or start another activity, |
| 3394 | // then go ahead and add the window. |
Dianne Hackborn | 061d58a | 2010-03-12 15:07:06 -0800 | [diff] [blame] | 3395 | boolean willBeVisible = !a.mStartedActivity; |
| 3396 | if (!willBeVisible) { |
| 3397 | try { |
| 3398 | willBeVisible = ActivityManagerNative.getDefault().willActivityBeVisible( |
| 3399 | a.getActivityToken()); |
| 3400 | } catch (RemoteException e) { |
| 3401 | } |
| 3402 | } |
| 3403 | if (r.window == null && !a.mFinished && willBeVisible) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3404 | r.window = r.activity.getWindow(); |
| 3405 | View decor = r.window.getDecorView(); |
| 3406 | decor.setVisibility(View.INVISIBLE); |
| 3407 | ViewManager wm = a.getWindowManager(); |
| 3408 | WindowManager.LayoutParams l = r.window.getAttributes(); |
| 3409 | a.mDecor = decor; |
| 3410 | l.type = WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
| 3411 | l.softInputMode |= forwardBit; |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 3412 | if (r.mPreserveWindow) { |
| 3413 | a.mWindowAdded = true; |
| 3414 | r.mPreserveWindow = false; |
| 3415 | } |
| 3416 | if (a.mVisibleFromClient && !a.mWindowAdded) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3417 | a.mWindowAdded = true; |
| 3418 | wm.addView(decor, l); |
| 3419 | } |
| 3420 | |
| 3421 | // If the window has already been added, but during resume |
| 3422 | // we started another activity, then don't yet make the |
Dianne Hackborn | 061d58a | 2010-03-12 15:07:06 -0800 | [diff] [blame] | 3423 | // window visible. |
| 3424 | } else if (!willBeVisible) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3425 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3426 | TAG, "Launch " + r + " mStartedActivity set"); |
| 3427 | r.hideForNow = true; |
| 3428 | } |
| 3429 | |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 3430 | // Get rid of anything left hanging around. |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 3431 | cleanUpPendingRemoveWindows(r, false /* force */); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 3432 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3433 | // The window is now visible if it has been added, we are not |
| 3434 | // simply finishing, and we are not starting another activity. |
Dianne Hackborn | 061d58a | 2010-03-12 15:07:06 -0800 | [diff] [blame] | 3435 | if (!r.activity.mFinished && willBeVisible |
Dianne Hackborn | c1e605e | 2009-09-25 17:18:15 -0700 | [diff] [blame] | 3436 | && r.activity.mDecor != null && !r.hideForNow) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3437 | if (r.newConfig != null) { |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 3438 | r.tmpConfig.setTo(r.newConfig); |
| 3439 | if (r.overrideConfig != null) { |
| 3440 | r.tmpConfig.updateFrom(r.overrideConfig); |
| 3441 | } |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3442 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Resuming activity " |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 3443 | + r.activityInfo.name + " with newConfig " + r.tmpConfig); |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 3444 | performConfigurationChanged(r.activity, r.tmpConfig, REPORT_TO_ACTIVITY); |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 3445 | freeTextLayoutCachesIfNeeded(r.activity.mCurrentConfig.diff(r.tmpConfig)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3446 | r.newConfig = null; |
| 3447 | } |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3448 | if (localLOGV) Slog.v(TAG, "Resuming " + r + " with isForward=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3449 | + isForward); |
| 3450 | WindowManager.LayoutParams l = r.window.getAttributes(); |
| 3451 | if ((l.softInputMode |
| 3452 | & WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) |
| 3453 | != forwardBit) { |
| 3454 | l.softInputMode = (l.softInputMode |
| 3455 | & (~WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION)) |
| 3456 | | forwardBit; |
Dianne Hackborn | c1e605e | 2009-09-25 17:18:15 -0700 | [diff] [blame] | 3457 | if (r.activity.mVisibleFromClient) { |
| 3458 | ViewManager wm = a.getWindowManager(); |
| 3459 | View decor = r.window.getDecorView(); |
| 3460 | wm.updateViewLayout(decor, l); |
| 3461 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3462 | } |
| 3463 | r.activity.mVisibleFromServer = true; |
| 3464 | mNumVisibleActivities++; |
| 3465 | if (r.activity.mVisibleFromClient) { |
| 3466 | r.activity.makeVisible(); |
| 3467 | } |
| 3468 | } |
| 3469 | |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 3470 | if (!r.onlyLocalRequest) { |
| 3471 | r.nextIdle = mNewActivities; |
| 3472 | mNewActivities = r; |
| 3473 | if (localLOGV) Slog.v( |
| 3474 | TAG, "Scheduling idle handler for " + r); |
| 3475 | Looper.myQueue().addIdleHandler(new Idler()); |
| 3476 | } |
| 3477 | r.onlyLocalRequest = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3478 | |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 3479 | // Tell the activity manager we have resumed. |
| 3480 | if (reallyResume) { |
| 3481 | try { |
| 3482 | ActivityManagerNative.getDefault().activityResumed(token); |
| 3483 | } catch (RemoteException ex) { |
| 3484 | } |
| 3485 | } |
| 3486 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3487 | } else { |
| 3488 | // If an exception was thrown when trying to resume, then |
| 3489 | // just end this activity. |
| 3490 | try { |
| 3491 | ActivityManagerNative.getDefault() |
Wale Ogunwale | ba7881c | 2015-08-01 19:28:29 -0700 | [diff] [blame] | 3492 | .finishActivity(token, Activity.RESULT_CANCELED, null, |
| 3493 | Activity.DONT_FINISH_TASK_WITH_ACTIVITY); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3494 | } catch (RemoteException ex) { |
| 3495 | } |
| 3496 | } |
| 3497 | } |
| 3498 | |
| 3499 | private int mThumbnailWidth = -1; |
| 3500 | private int mThumbnailHeight = -1; |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3501 | private Bitmap mAvailThumbnailBitmap = null; |
| 3502 | private Canvas mThumbnailCanvas = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3503 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3504 | private Bitmap createThumbnailBitmap(ActivityClientRecord r) { |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3505 | Bitmap thumbnail = mAvailThumbnailBitmap; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3506 | try { |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3507 | if (thumbnail == null) { |
| 3508 | int w = mThumbnailWidth; |
| 3509 | int h; |
| 3510 | if (w < 0) { |
| 3511 | Resources res = r.activity.getResources(); |
Winson Chung | 6784f1c | 2014-05-22 11:22:41 -0700 | [diff] [blame] | 3512 | int wId = com.android.internal.R.dimen.thumbnail_width; |
| 3513 | int hId = com.android.internal.R.dimen.thumbnail_height; |
Winson Chung | fd08622 | 2014-05-13 15:49:42 -0700 | [diff] [blame] | 3514 | mThumbnailWidth = w = res.getDimensionPixelSize(wId); |
| 3515 | mThumbnailHeight = h = res.getDimensionPixelSize(hId); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3516 | } else { |
| 3517 | h = mThumbnailHeight; |
| 3518 | } |
| 3519 | |
| 3520 | // On platforms where we don't want thumbnails, set dims to (0,0) |
| 3521 | if ((w > 0) && (h > 0)) { |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 3522 | thumbnail = Bitmap.createBitmap(r.activity.getResources().getDisplayMetrics(), |
| 3523 | w, h, THUMBNAIL_FORMAT); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3524 | thumbnail.eraseColor(0); |
| 3525 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3526 | } |
| 3527 | |
Dianne Hackborn | fb3806d | 2010-12-09 13:14:12 -0800 | [diff] [blame] | 3528 | if (thumbnail != null) { |
| 3529 | Canvas cv = mThumbnailCanvas; |
| 3530 | if (cv == null) { |
| 3531 | mThumbnailCanvas = cv = new Canvas(); |
| 3532 | } |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 3533 | |
Dianne Hackborn | fb3806d | 2010-12-09 13:14:12 -0800 | [diff] [blame] | 3534 | cv.setBitmap(thumbnail); |
| 3535 | if (!r.activity.onCreateThumbnail(thumbnail, cv)) { |
| 3536 | mAvailThumbnailBitmap = thumbnail; |
| 3537 | thumbnail = null; |
| 3538 | } |
Dianne Hackborn | 6311d0a | 2011-08-02 16:37:58 -0700 | [diff] [blame] | 3539 | cv.setBitmap(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3540 | } |
Jim Miller | 0b2a6d0 | 2010-07-13 18:01:29 -0700 | [diff] [blame] | 3541 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3542 | } catch (Exception e) { |
| 3543 | if (!mInstrumentation.onException(r.activity, e)) { |
| 3544 | throw new RuntimeException( |
| 3545 | "Unable to create thumbnail of " |
| 3546 | + r.intent.getComponent().toShortString() |
| 3547 | + ": " + e.toString(), e); |
| 3548 | } |
| 3549 | thumbnail = null; |
| 3550 | } |
| 3551 | |
| 3552 | return thumbnail; |
| 3553 | } |
| 3554 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3555 | private void handlePauseActivity(IBinder token, boolean finished, |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 3556 | boolean userLeaving, int configChanges, boolean dontReport, int seq) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3557 | ActivityClientRecord r = mActivities.get(token); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 3558 | if (!checkAndUpdateLifecycleSeq(seq, r, "pauseActivity")) { |
| 3559 | return; |
| 3560 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3561 | if (r != null) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3562 | //Slog.v(TAG, "userLeaving=" + userLeaving + " handling pause of " + r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3563 | if (userLeaving) { |
| 3564 | performUserLeavingActivity(r); |
| 3565 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3566 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3567 | r.activity.mConfigChangeFlags |= configChanges; |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3568 | performPauseActivity(token, finished, r.isPreHoneycomb()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3569 | |
Dianne Hackborn | aa93bcd | 2010-10-27 13:57:00 -0700 | [diff] [blame] | 3570 | // Make sure any pending writes are now committed. |
Dianne Hackborn | 5d9d03a | 2011-01-24 13:15:09 -0800 | [diff] [blame] | 3571 | if (r.isPreHoneycomb()) { |
| 3572 | QueuedWork.waitToFinish(); |
| 3573 | } |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 3574 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3575 | // Tell the activity manager we have paused. |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 3576 | if (!dontReport) { |
| 3577 | try { |
| 3578 | ActivityManagerNative.getDefault().activityPaused(token); |
| 3579 | } catch (RemoteException ex) { |
| 3580 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3581 | } |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3582 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3583 | } |
| 3584 | } |
| 3585 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3586 | final void performUserLeavingActivity(ActivityClientRecord r) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3587 | mInstrumentation.callActivityOnUserLeaving(r.activity); |
| 3588 | } |
| 3589 | |
| 3590 | final Bundle performPauseActivity(IBinder token, boolean finished, |
| 3591 | boolean saveState) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3592 | ActivityClientRecord r = mActivities.get(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3593 | return r != null ? performPauseActivity(r, finished, saveState) : null; |
| 3594 | } |
| 3595 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3596 | final Bundle performPauseActivity(ActivityClientRecord r, boolean finished, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3597 | boolean saveState) { |
| 3598 | if (r.paused) { |
| 3599 | if (r.activity.mFinished) { |
| 3600 | // If we are finishing, we won't call onResume() in certain cases. |
| 3601 | // So here we likewise don't want to call onPause() if the activity |
| 3602 | // isn't resumed. |
| 3603 | return null; |
| 3604 | } |
| 3605 | RuntimeException e = new RuntimeException( |
| 3606 | "Performing pause of activity that is not resumed: " |
| 3607 | + r.intent.getComponent().toShortString()); |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 3608 | Slog.e(TAG, e.getMessage(), e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3609 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3610 | if (finished) { |
| 3611 | r.activity.mFinished = true; |
| 3612 | } |
| 3613 | try { |
| 3614 | // Next have the activity save its current state and managed dialogs... |
| 3615 | if (!r.activity.mFinished && saveState) { |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3616 | callCallActivityOnSaveInstanceState(r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3617 | } |
| 3618 | // Now we are idle. |
| 3619 | r.activity.mCalled = false; |
| 3620 | mInstrumentation.callActivityOnPause(r.activity); |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 3621 | EventLog.writeEvent(LOG_AM_ON_PAUSE_CALLED, UserHandle.myUserId(), |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 3622 | r.activity.getComponentName().getClassName()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3623 | if (!r.activity.mCalled) { |
| 3624 | throw new SuperNotCalledException( |
| 3625 | "Activity " + r.intent.getComponent().toShortString() + |
| 3626 | " did not call through to super.onPause()"); |
| 3627 | } |
| 3628 | |
| 3629 | } catch (SuperNotCalledException e) { |
| 3630 | throw e; |
| 3631 | |
| 3632 | } catch (Exception e) { |
| 3633 | if (!mInstrumentation.onException(r.activity, e)) { |
| 3634 | throw new RuntimeException( |
| 3635 | "Unable to pause activity " |
| 3636 | + r.intent.getComponent().toShortString() |
| 3637 | + ": " + e.toString(), e); |
| 3638 | } |
| 3639 | } |
| 3640 | r.paused = true; |
Jeff Hamilton | 52d3203 | 2011-01-08 15:31:26 -0600 | [diff] [blame] | 3641 | |
| 3642 | // Notify any outstanding on paused listeners |
| 3643 | ArrayList<OnActivityPausedListener> listeners; |
| 3644 | synchronized (mOnPauseListeners) { |
| 3645 | listeners = mOnPauseListeners.remove(r.activity); |
| 3646 | } |
| 3647 | int size = (listeners != null ? listeners.size() : 0); |
| 3648 | for (int i = 0; i < size; i++) { |
| 3649 | listeners.get(i).onPaused(r.activity); |
| 3650 | } |
| 3651 | |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3652 | return !r.activity.mFinished && saveState ? r.state : null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3653 | } |
| 3654 | |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3655 | final void performStopActivity(IBinder token, boolean saveState) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3656 | ActivityClientRecord r = mActivities.get(token); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3657 | performStopActivityInner(r, null, false, saveState); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3658 | } |
| 3659 | |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 3660 | private static class StopInfo implements Runnable { |
| 3661 | ActivityClientRecord activity; |
| 3662 | Bundle state; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3663 | PersistableBundle persistentState; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3664 | CharSequence description; |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 3665 | |
| 3666 | @Override public void run() { |
| 3667 | // Tell activity manager we have been stopped. |
| 3668 | try { |
| 3669 | if (DEBUG_MEMORY_TRIM) Slog.v(TAG, "Reporting activity stopped: " + activity); |
| 3670 | ActivityManagerNative.getDefault().activityStopped( |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3671 | activity.token, state, persistentState, description); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 3672 | } catch (RemoteException ex) { |
| 3673 | } |
| 3674 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3675 | } |
| 3676 | |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 3677 | private static final class ProviderRefCount { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 3678 | public final IActivityManager.ContentProviderHolder holder; |
| 3679 | public final ProviderClientRecord client; |
| 3680 | public int stableCount; |
| 3681 | public int unstableCount; |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 3682 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 3683 | // When this is set, the stable and unstable ref counts are 0 and |
| 3684 | // we have a pending operation scheduled to remove the ref count |
| 3685 | // from the activity manager. On the activity manager we are still |
| 3686 | // holding an unstable ref, though it is not reflected in the counts |
| 3687 | // here. |
| 3688 | public boolean removePending; |
| 3689 | |
| 3690 | ProviderRefCount(IActivityManager.ContentProviderHolder inHolder, |
| 3691 | ProviderClientRecord inClient, int sCount, int uCount) { |
| 3692 | holder = inHolder; |
| 3693 | client = inClient; |
| 3694 | stableCount = sCount; |
| 3695 | unstableCount = uCount; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3696 | } |
| 3697 | } |
| 3698 | |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3699 | /** |
| 3700 | * Core implementation of stopping an activity. Note this is a little |
| 3701 | * tricky because the server's meaning of stop is slightly different |
| 3702 | * than our client -- for the server, stop means to save state and give |
| 3703 | * it the result when it is done, but the window may still be visible. |
| 3704 | * For the client, we want to call onStop()/onStart() to indicate when |
| 3705 | * the activity's UI visibillity changes. |
| 3706 | */ |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3707 | private void performStopActivityInner(ActivityClientRecord r, |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3708 | StopInfo info, boolean keepShown, boolean saveState) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3709 | if (localLOGV) Slog.v(TAG, "Performing stop of " + r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3710 | if (r != null) { |
| 3711 | if (!keepShown && r.stopped) { |
| 3712 | if (r.activity.mFinished) { |
| 3713 | // If we are finishing, we won't call onResume() in certain |
| 3714 | // cases. So here we likewise don't want to call onStop() |
| 3715 | // if the activity isn't resumed. |
| 3716 | return; |
| 3717 | } |
| 3718 | RuntimeException e = new RuntimeException( |
| 3719 | "Performing stop of activity that is not resumed: " |
| 3720 | + r.intent.getComponent().toShortString()); |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 3721 | Slog.e(TAG, e.getMessage(), e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3722 | } |
| 3723 | |
| 3724 | if (info != null) { |
| 3725 | try { |
| 3726 | // First create a thumbnail for the activity... |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3727 | // For now, don't create the thumbnail here; we are |
| 3728 | // doing that by doing a screen snapshot. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3729 | info.description = r.activity.onCreateDescription(); |
| 3730 | } catch (Exception e) { |
| 3731 | if (!mInstrumentation.onException(r.activity, e)) { |
| 3732 | throw new RuntimeException( |
| 3733 | "Unable to save state of activity " |
| 3734 | + r.intent.getComponent().toShortString() |
| 3735 | + ": " + e.toString(), e); |
| 3736 | } |
| 3737 | } |
| 3738 | } |
| 3739 | |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3740 | // Next have the activity save its current state and managed dialogs... |
| 3741 | if (!r.activity.mFinished && saveState) { |
| 3742 | if (r.state == null) { |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3743 | callCallActivityOnSaveInstanceState(r); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3744 | } |
| 3745 | } |
| 3746 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3747 | if (!keepShown) { |
| 3748 | try { |
| 3749 | // Now we are idle. |
| 3750 | r.activity.performStop(); |
| 3751 | } catch (Exception e) { |
| 3752 | if (!mInstrumentation.onException(r.activity, e)) { |
| 3753 | throw new RuntimeException( |
| 3754 | "Unable to stop activity " |
| 3755 | + r.intent.getComponent().toShortString() |
| 3756 | + ": " + e.toString(), e); |
| 3757 | } |
| 3758 | } |
| 3759 | r.stopped = true; |
| 3760 | } |
| 3761 | |
| 3762 | r.paused = true; |
| 3763 | } |
| 3764 | } |
| 3765 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3766 | private void updateVisibility(ActivityClientRecord r, boolean show) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3767 | View v = r.activity.mDecor; |
| 3768 | if (v != null) { |
| 3769 | if (show) { |
| 3770 | if (!r.activity.mVisibleFromServer) { |
| 3771 | r.activity.mVisibleFromServer = true; |
| 3772 | mNumVisibleActivities++; |
| 3773 | if (r.activity.mVisibleFromClient) { |
| 3774 | r.activity.makeVisible(); |
| 3775 | } |
| 3776 | } |
| 3777 | if (r.newConfig != null) { |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 3778 | r.tmpConfig.setTo(r.newConfig); |
| 3779 | if (r.overrideConfig != null) { |
| 3780 | r.tmpConfig.updateFrom(r.overrideConfig); |
| 3781 | } |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3782 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Updating activity vis " |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 3783 | + r.activityInfo.name + " with new config " + r.tmpConfig); |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 3784 | performConfigurationChanged(r.activity, r.tmpConfig, REPORT_TO_ACTIVITY); |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 3785 | freeTextLayoutCachesIfNeeded(r.activity.mCurrentConfig.diff(r.tmpConfig)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3786 | r.newConfig = null; |
| 3787 | } |
| 3788 | } else { |
| 3789 | if (r.activity.mVisibleFromServer) { |
| 3790 | r.activity.mVisibleFromServer = false; |
| 3791 | mNumVisibleActivities--; |
| 3792 | v.setVisibility(View.INVISIBLE); |
| 3793 | } |
| 3794 | } |
| 3795 | } |
| 3796 | } |
| 3797 | |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 3798 | private void handleStopActivity(IBinder token, boolean show, int configChanges, int seq) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3799 | ActivityClientRecord r = mActivities.get(token); |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 3800 | if (!checkAndUpdateLifecycleSeq(seq, r, "stopActivity")) { |
| 3801 | return; |
| 3802 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3803 | r.activity.mConfigChangeFlags |= configChanges; |
| 3804 | |
| 3805 | StopInfo info = new StopInfo(); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3806 | performStopActivityInner(r, info, show, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3807 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3808 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3809 | TAG, "Finishing stop of " + r + ": show=" + show |
| 3810 | + " win=" + r.window); |
| 3811 | |
| 3812 | updateVisibility(r, show); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 3813 | |
Dianne Hackborn | 5d9d03a | 2011-01-24 13:15:09 -0800 | [diff] [blame] | 3814 | // Make sure any pending writes are now committed. |
| 3815 | if (!r.isPreHoneycomb()) { |
| 3816 | QueuedWork.waitToFinish(); |
| 3817 | } |
| 3818 | |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 3819 | // Schedule the call to tell the activity manager we have |
| 3820 | // stopped. We don't do this immediately, because we want to |
| 3821 | // have a chance for any other pending work (in particular memory |
| 3822 | // trim requests) to complete before you tell the activity |
| 3823 | // manager to proceed and allow us to go fully into the background. |
| 3824 | info.activity = r; |
| 3825 | info.state = r.state; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3826 | info.persistentState = r.persistentState; |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 3827 | mH.post(info); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3828 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3829 | } |
| 3830 | |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 3831 | private static boolean checkAndUpdateLifecycleSeq(int seq, ActivityClientRecord r, |
| 3832 | String action) { |
| 3833 | if (r == null) { |
| 3834 | return true; |
| 3835 | } |
| 3836 | if (seq < r.lastProcessedSeq) { |
| 3837 | if (DEBUG_ORDER) Slog.d(TAG, action + " for " + r + " ignored, because seq=" + seq |
| 3838 | + " < mCurrentLifecycleSeq=" + r.lastProcessedSeq); |
| 3839 | return false; |
| 3840 | } |
| 3841 | r.lastProcessedSeq = seq; |
| 3842 | return true; |
| 3843 | } |
| 3844 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3845 | final void performRestartActivity(IBinder token) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3846 | ActivityClientRecord r = mActivities.get(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3847 | if (r.stopped) { |
| 3848 | r.activity.performRestart(); |
| 3849 | r.stopped = false; |
| 3850 | } |
| 3851 | } |
| 3852 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3853 | private void handleWindowVisibility(IBinder token, boolean show) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3854 | ActivityClientRecord r = mActivities.get(token); |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 3855 | |
Dianne Hackborn | bfddc0f | 2010-12-14 11:28:01 -0800 | [diff] [blame] | 3856 | if (r == null) { |
| 3857 | Log.w(TAG, "handleWindowVisibility: no activity for token " + token); |
| 3858 | return; |
| 3859 | } |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 3860 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3861 | if (!show && !r.stopped) { |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 3862 | performStopActivityInner(r, null, show, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3863 | } else if (show && r.stopped) { |
| 3864 | // If we are getting ready to gc after going to the background, well |
| 3865 | // we are back active so skip it. |
| 3866 | unscheduleGcIdler(); |
| 3867 | |
| 3868 | r.activity.performRestart(); |
| 3869 | r.stopped = false; |
| 3870 | } |
| 3871 | if (r.activity.mDecor != null) { |
Joe Onorato | 43a1765 | 2011-04-06 19:22:23 -0700 | [diff] [blame] | 3872 | if (false) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3873 | TAG, "Handle window " + r + " visibility: " + show); |
| 3874 | updateVisibility(r, show); |
| 3875 | } |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3876 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3877 | } |
| 3878 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3879 | private void handleSleeping(IBinder token, boolean sleeping) { |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 3880 | ActivityClientRecord r = mActivities.get(token); |
| 3881 | |
| 3882 | if (r == null) { |
Dianne Hackborn | 842e04b | 2011-01-22 13:00:12 -0800 | [diff] [blame] | 3883 | Log.w(TAG, "handleSleeping: no activity for token " + token); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 3884 | return; |
| 3885 | } |
| 3886 | |
| 3887 | if (sleeping) { |
Dianne Hackborn | 842e04b | 2011-01-22 13:00:12 -0800 | [diff] [blame] | 3888 | if (!r.stopped && !r.isPreHoneycomb()) { |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 3889 | try { |
| 3890 | // Now we are idle. |
| 3891 | r.activity.performStop(); |
| 3892 | } catch (Exception e) { |
| 3893 | if (!mInstrumentation.onException(r.activity, e)) { |
| 3894 | throw new RuntimeException( |
| 3895 | "Unable to stop activity " |
| 3896 | + r.intent.getComponent().toShortString() |
| 3897 | + ": " + e.toString(), e); |
| 3898 | } |
| 3899 | } |
| 3900 | r.stopped = true; |
| 3901 | } |
Dianne Hackborn | 5d9d03a | 2011-01-24 13:15:09 -0800 | [diff] [blame] | 3902 | |
| 3903 | // Make sure any pending writes are now committed. |
| 3904 | if (!r.isPreHoneycomb()) { |
| 3905 | QueuedWork.waitToFinish(); |
| 3906 | } |
| 3907 | |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 3908 | // Tell activity manager we slept. |
| 3909 | try { |
| 3910 | ActivityManagerNative.getDefault().activitySlept(r.token); |
| 3911 | } catch (RemoteException ex) { |
| 3912 | } |
| 3913 | } else { |
| 3914 | if (r.stopped && r.activity.mVisibleFromServer) { |
| 3915 | r.activity.performRestart(); |
| 3916 | r.stopped = false; |
| 3917 | } |
| 3918 | } |
| 3919 | } |
| 3920 | |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 3921 | private void handleSetCoreSettings(Bundle coreSettings) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 3922 | synchronized (mResourcesManager) { |
Svetoslav Ganov | 9aa597e | 2011-03-03 18:17:41 -0800 | [diff] [blame] | 3923 | mCoreSettings = coreSettings; |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 3924 | } |
Jon Miranda | 836c0a8 | 2014-08-11 12:32:26 -0700 | [diff] [blame] | 3925 | onCoreSettingsChange(); |
| 3926 | } |
| 3927 | |
| 3928 | private void onCoreSettingsChange() { |
| 3929 | boolean debugViewAttributes = |
| 3930 | mCoreSettings.getInt(Settings.Global.DEBUG_VIEW_ATTRIBUTES, 0) != 0; |
| 3931 | if (debugViewAttributes != View.mDebugViewAttributes) { |
| 3932 | View.mDebugViewAttributes = debugViewAttributes; |
| 3933 | |
| 3934 | // request all activities to relaunch for the changes to take place |
| 3935 | for (Map.Entry<IBinder, ActivityClientRecord> entry : mActivities.entrySet()) { |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 3936 | requestRelaunchActivity(entry.getKey(), null, null, 0, false, null, null, false, |
| 3937 | false /* preserveWindow */); |
Jon Miranda | 836c0a8 | 2014-08-11 12:32:26 -0700 | [diff] [blame] | 3938 | } |
| 3939 | } |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 3940 | } |
| 3941 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 3942 | private void handleUpdatePackageCompatibilityInfo(UpdateCompatibilityData data) { |
| 3943 | LoadedApk apk = peekPackageInfo(data.pkg, false); |
| 3944 | if (apk != null) { |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 3945 | apk.setCompatibilityInfo(data.info); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 3946 | } |
| 3947 | apk = peekPackageInfo(data.pkg, true); |
| 3948 | if (apk != null) { |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 3949 | apk.setCompatibilityInfo(data.info); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 3950 | } |
| 3951 | handleConfigurationChanged(mConfiguration, data.info); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 3952 | WindowManagerGlobal.getInstance().reportNewConfiguration(mConfiguration); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 3953 | } |
| 3954 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3955 | private void deliverResults(ActivityClientRecord r, List<ResultInfo> results) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3956 | final int N = results.size(); |
| 3957 | for (int i=0; i<N; i++) { |
| 3958 | ResultInfo ri = results.get(i); |
| 3959 | try { |
| 3960 | if (ri.mData != null) { |
| 3961 | ri.mData.setExtrasClassLoader(r.activity.getClassLoader()); |
Nicolas Prevot | d1c99b1 | 2014-07-04 16:56:17 +0100 | [diff] [blame] | 3962 | ri.mData.prepareToEnterProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3963 | } |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3964 | if (DEBUG_RESULTS) Slog.v(TAG, |
Chris Tate | 8a7dc17 | 2009-03-24 20:11:42 -0700 | [diff] [blame] | 3965 | "Delivering result to activity " + r + " : " + ri); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3966 | r.activity.dispatchActivityResult(ri.mResultWho, |
| 3967 | ri.mRequestCode, ri.mResultCode, ri.mData); |
| 3968 | } catch (Exception e) { |
| 3969 | if (!mInstrumentation.onException(r.activity, e)) { |
| 3970 | throw new RuntimeException( |
| 3971 | "Failure delivering result " + ri + " to activity " |
| 3972 | + r.intent.getComponent().toShortString() |
| 3973 | + ": " + e.toString(), e); |
| 3974 | } |
| 3975 | } |
| 3976 | } |
| 3977 | } |
| 3978 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3979 | private void handleSendResult(ResultData res) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3980 | ActivityClientRecord r = mActivities.get(res.token); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 3981 | 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] | 3982 | if (r != null) { |
| 3983 | final boolean resumed = !r.paused; |
| 3984 | if (!r.activity.mFinished && r.activity.mDecor != null |
| 3985 | && r.hideForNow && resumed) { |
| 3986 | // We had hidden the activity because it started another |
| 3987 | // one... we have gotten a result back and we are not |
| 3988 | // paused, so make sure our window is visible. |
| 3989 | updateVisibility(r, true); |
| 3990 | } |
| 3991 | if (resumed) { |
| 3992 | try { |
| 3993 | // Now we are idle. |
| 3994 | r.activity.mCalled = false; |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 3995 | r.activity.mTemporaryPause = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3996 | mInstrumentation.callActivityOnPause(r.activity); |
| 3997 | if (!r.activity.mCalled) { |
| 3998 | throw new SuperNotCalledException( |
| 3999 | "Activity " + r.intent.getComponent().toShortString() |
| 4000 | + " did not call through to super.onPause()"); |
| 4001 | } |
| 4002 | } catch (SuperNotCalledException e) { |
| 4003 | throw e; |
| 4004 | } catch (Exception e) { |
| 4005 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4006 | throw new RuntimeException( |
| 4007 | "Unable to pause activity " |
| 4008 | + r.intent.getComponent().toShortString() |
| 4009 | + ": " + e.toString(), e); |
| 4010 | } |
| 4011 | } |
| 4012 | } |
| 4013 | deliverResults(r, res.results); |
| 4014 | if (resumed) { |
Dianne Hackborn | b46ed76 | 2011-06-02 18:33:15 -0700 | [diff] [blame] | 4015 | r.activity.performResume(); |
Dianne Hackborn | fb3cffe | 2010-10-25 17:08:56 -0700 | [diff] [blame] | 4016 | r.activity.mTemporaryPause = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4017 | } |
| 4018 | } |
| 4019 | } |
| 4020 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4021 | public final ActivityClientRecord performDestroyActivity(IBinder token, boolean finishing) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4022 | return performDestroyActivity(token, finishing, 0, false); |
| 4023 | } |
| 4024 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 4025 | private ActivityClientRecord performDestroyActivity(IBinder token, boolean finishing, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4026 | int configChanges, boolean getNonConfigInstance) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4027 | ActivityClientRecord r = mActivities.get(token); |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4028 | Class<? extends Activity> activityClass = null; |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4029 | if (localLOGV) Slog.v(TAG, "Performing finish of " + r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4030 | if (r != null) { |
Brad Fitzpatrick | 5f8b5c1 | 2011-01-20 15:12:08 -0800 | [diff] [blame] | 4031 | activityClass = r.activity.getClass(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4032 | r.activity.mConfigChangeFlags |= configChanges; |
| 4033 | if (finishing) { |
| 4034 | r.activity.mFinished = true; |
| 4035 | } |
| 4036 | if (!r.paused) { |
| 4037 | try { |
| 4038 | r.activity.mCalled = false; |
| 4039 | mInstrumentation.callActivityOnPause(r.activity); |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 4040 | EventLog.writeEvent(LOG_AM_ON_PAUSE_CALLED, UserHandle.myUserId(), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4041 | r.activity.getComponentName().getClassName()); |
| 4042 | if (!r.activity.mCalled) { |
| 4043 | throw new SuperNotCalledException( |
Mitsuru Oshima | d9aef73 | 2009-06-16 20:20:50 -0700 | [diff] [blame] | 4044 | "Activity " + safeToComponentShortString(r.intent) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4045 | + " did not call through to super.onPause()"); |
| 4046 | } |
| 4047 | } catch (SuperNotCalledException e) { |
| 4048 | throw e; |
| 4049 | } catch (Exception e) { |
| 4050 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4051 | throw new RuntimeException( |
| 4052 | "Unable to pause activity " |
Mitsuru Oshima | d9aef73 | 2009-06-16 20:20:50 -0700 | [diff] [blame] | 4053 | + safeToComponentShortString(r.intent) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4054 | + ": " + e.toString(), e); |
| 4055 | } |
| 4056 | } |
| 4057 | r.paused = true; |
| 4058 | } |
| 4059 | if (!r.stopped) { |
| 4060 | try { |
| 4061 | r.activity.performStop(); |
| 4062 | } catch (SuperNotCalledException e) { |
| 4063 | throw e; |
| 4064 | } catch (Exception e) { |
| 4065 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4066 | throw new RuntimeException( |
| 4067 | "Unable to stop activity " |
Mitsuru Oshima | d9aef73 | 2009-06-16 20:20:50 -0700 | [diff] [blame] | 4068 | + safeToComponentShortString(r.intent) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4069 | + ": " + e.toString(), e); |
| 4070 | } |
| 4071 | } |
| 4072 | r.stopped = true; |
| 4073 | } |
| 4074 | if (getNonConfigInstance) { |
| 4075 | try { |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 4076 | r.lastNonConfigurationInstances |
| 4077 | = r.activity.retainNonConfigurationInstances(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4078 | } catch (Exception e) { |
| 4079 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4080 | throw new RuntimeException( |
| 4081 | "Unable to retain activity " |
| 4082 | + r.intent.getComponent().toShortString() |
| 4083 | + ": " + e.toString(), e); |
| 4084 | } |
| 4085 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4086 | } |
| 4087 | try { |
| 4088 | r.activity.mCalled = false; |
Dianne Hackborn | 2dedce6 | 2010-04-15 14:45:25 -0700 | [diff] [blame] | 4089 | mInstrumentation.callActivityOnDestroy(r.activity); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4090 | if (!r.activity.mCalled) { |
| 4091 | throw new SuperNotCalledException( |
Mitsuru Oshima | d9aef73 | 2009-06-16 20:20:50 -0700 | [diff] [blame] | 4092 | "Activity " + safeToComponentShortString(r.intent) + |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4093 | " did not call through to super.onDestroy()"); |
| 4094 | } |
| 4095 | if (r.window != null) { |
| 4096 | r.window.closeAllPanels(); |
| 4097 | } |
| 4098 | } catch (SuperNotCalledException e) { |
| 4099 | throw e; |
| 4100 | } catch (Exception e) { |
| 4101 | if (!mInstrumentation.onException(r.activity, e)) { |
| 4102 | throw new RuntimeException( |
Mitsuru Oshima | d9aef73 | 2009-06-16 20:20:50 -0700 | [diff] [blame] | 4103 | "Unable to destroy activity " + safeToComponentShortString(r.intent) |
| 4104 | + ": " + e.toString(), e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4105 | } |
| 4106 | } |
| 4107 | } |
| 4108 | mActivities.remove(token); |
Brad Fitzpatrick | 5f8b5c1 | 2011-01-20 15:12:08 -0800 | [diff] [blame] | 4109 | StrictMode.decrementExpectedActivityCount(activityClass); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4110 | return r; |
| 4111 | } |
| 4112 | |
Mitsuru Oshima | d9aef73 | 2009-06-16 20:20:50 -0700 | [diff] [blame] | 4113 | private static String safeToComponentShortString(Intent intent) { |
| 4114 | ComponentName component = intent.getComponent(); |
| 4115 | return component == null ? "[Unknown]" : component.toShortString(); |
| 4116 | } |
| 4117 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 4118 | private void handleDestroyActivity(IBinder token, boolean finishing, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4119 | int configChanges, boolean getNonConfigInstance) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4120 | ActivityClientRecord r = performDestroyActivity(token, finishing, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4121 | configChanges, getNonConfigInstance); |
| 4122 | if (r != null) { |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4123 | cleanUpPendingRemoveWindows(r, finishing); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4124 | WindowManager wm = r.activity.getWindowManager(); |
| 4125 | View v = r.activity.mDecor; |
| 4126 | if (v != null) { |
| 4127 | if (r.activity.mVisibleFromServer) { |
| 4128 | mNumVisibleActivities--; |
| 4129 | } |
| 4130 | IBinder wtoken = v.getWindowToken(); |
| 4131 | if (r.activity.mWindowAdded) { |
Filip Gruszczynski | 14418da | 2015-10-04 16:43:48 -0700 | [diff] [blame] | 4132 | if (r.onlyLocalRequest || r.mPreserveWindow) { |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4133 | // Hold off on removing this until the new activity's |
| 4134 | // window is being added. |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4135 | r.mPendingRemoveWindow = r.window; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4136 | r.mPendingRemoveWindowManager = wm; |
Filip Gruszczynski | 14418da | 2015-10-04 16:43:48 -0700 | [diff] [blame] | 4137 | if (r.mPreserveWindow) { |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4138 | // We can only keep the part of the view hierarchy that we control, |
| 4139 | // everything else must be removed, because it might not be able to |
| 4140 | // behave properly when activity is relaunching. |
| 4141 | r.window.clearContentView(); |
| 4142 | } |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4143 | } else { |
| 4144 | wm.removeViewImmediate(v); |
| 4145 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4146 | } |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4147 | if (wtoken != null && r.mPendingRemoveWindow == null) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 4148 | WindowManagerGlobal.getInstance().closeAll(wtoken, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4149 | r.activity.getClass().getName(), "Activity"); |
| 4150 | } |
| 4151 | r.activity.mDecor = null; |
| 4152 | } |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4153 | if (r.mPendingRemoveWindow == null) { |
| 4154 | // If we are delaying the removal of the activity window, then |
| 4155 | // we can't clean up all windows here. Note that we can't do |
| 4156 | // so later either, which means any windows that aren't closed |
| 4157 | // by the app will leak. Well we try to warning them a lot |
| 4158 | // about leaking windows, because that is a bug, so if they are |
| 4159 | // using this recreate facility then they get to live with leaks. |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 4160 | WindowManagerGlobal.getInstance().closeAll(token, |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4161 | r.activity.getClass().getName(), "Activity"); |
| 4162 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4163 | |
| 4164 | // Mocked out contexts won't be participating in the normal |
| 4165 | // process lifecycle, but if we're running with a proper |
| 4166 | // ApplicationContext we need to have it tear down things |
| 4167 | // cleanly. |
| 4168 | Context c = r.activity.getBaseContext(); |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 4169 | if (c instanceof ContextImpl) { |
| 4170 | ((ContextImpl) c).scheduleFinalCleanup( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4171 | r.activity.getClass().getName(), "Activity"); |
| 4172 | } |
| 4173 | } |
| 4174 | if (finishing) { |
| 4175 | try { |
| 4176 | ActivityManagerNative.getDefault().activityDestroyed(token); |
| 4177 | } catch (RemoteException ex) { |
| 4178 | // If the system process has died, it's game over for everyone. |
| 4179 | } |
| 4180 | } |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4181 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4182 | } |
| 4183 | |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4184 | /** |
| 4185 | * @param preserveWindow Whether the activity should try to reuse the window it created, |
| 4186 | * including the decor view after the relaunch. |
| 4187 | */ |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4188 | public final void requestRelaunchActivity(IBinder token, |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 4189 | List<ResultInfo> pendingResults, List<ReferrerIntent> pendingNewIntents, |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4190 | int configChanges, boolean notResumed, Configuration config, |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4191 | Configuration overrideConfig, boolean fromServer, boolean preserveWindow) { |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4192 | ActivityClientRecord target = null; |
| 4193 | |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4194 | synchronized (mResourcesManager) { |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4195 | for (int i=0; i<mRelaunchingActivities.size(); i++) { |
| 4196 | ActivityClientRecord r = mRelaunchingActivities.get(i); |
| 4197 | if (r.token == token) { |
| 4198 | target = r; |
| 4199 | if (pendingResults != null) { |
| 4200 | if (r.pendingResults != null) { |
| 4201 | r.pendingResults.addAll(pendingResults); |
| 4202 | } else { |
| 4203 | r.pendingResults = pendingResults; |
| 4204 | } |
| 4205 | } |
| 4206 | if (pendingNewIntents != null) { |
| 4207 | if (r.pendingIntents != null) { |
| 4208 | r.pendingIntents.addAll(pendingNewIntents); |
| 4209 | } else { |
| 4210 | r.pendingIntents = pendingNewIntents; |
| 4211 | } |
| 4212 | } |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4213 | |
| 4214 | // For each relaunch request, activity manager expects an answer |
| 4215 | if (!r.onlyLocalRequest && fromServer) { |
| 4216 | try { |
| 4217 | ActivityManagerNative.getDefault().activityRelaunched(token); |
| 4218 | } catch (RemoteException e) { |
| 4219 | e.printStackTrace(); |
| 4220 | } |
| 4221 | } |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4222 | break; |
| 4223 | } |
| 4224 | } |
| 4225 | |
| 4226 | if (target == null) { |
| 4227 | target = new ActivityClientRecord(); |
| 4228 | target.token = token; |
| 4229 | target.pendingResults = pendingResults; |
| 4230 | target.pendingIntents = pendingNewIntents; |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4231 | target.mPreserveWindow = preserveWindow; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4232 | if (!fromServer) { |
Wale Ogunwale | 32ebbd8 | 2016-01-26 08:47:20 -0800 | [diff] [blame] | 4233 | ActivityClientRecord existing = mActivities.get(token); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4234 | if (existing != null) { |
| 4235 | target.startsNotResumed = existing.paused; |
Wale Ogunwale | 93f543c | 2015-02-17 16:55:03 -0800 | [diff] [blame] | 4236 | target.overrideConfig = existing.overrideConfig; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4237 | } |
| 4238 | target.onlyLocalRequest = true; |
| 4239 | } |
| 4240 | mRelaunchingActivities.add(target); |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 4241 | sendMessage(H.RELAUNCH_ACTIVITY, target); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4242 | } |
| 4243 | |
| 4244 | if (fromServer) { |
| 4245 | target.startsNotResumed = notResumed; |
| 4246 | target.onlyLocalRequest = false; |
| 4247 | } |
| 4248 | if (config != null) { |
| 4249 | target.createdConfig = config; |
| 4250 | } |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 4251 | if (overrideConfig != null) { |
| 4252 | target.overrideConfig = overrideConfig; |
| 4253 | } |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4254 | target.pendingConfigChanges |= configChanges; |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 4255 | target.relaunchSeq = getLifecycleSeq(); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4256 | } |
Wale Ogunwale | 32ebbd8 | 2016-01-26 08:47:20 -0800 | [diff] [blame] | 4257 | if (DEBUG_ORDER) Slog.d(TAG, "relaunchActivity " + ActivityThread.this |
| 4258 | + " operation received seq: " + target.relaunchSeq); |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4259 | } |
| 4260 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 4261 | private void handleRelaunchActivity(ActivityClientRecord tmp) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4262 | // If we are getting ready to gc after going to the background, well |
| 4263 | // we are back active so skip it. |
| 4264 | unscheduleGcIdler(); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4265 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4266 | |
| 4267 | Configuration changedConfig = null; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4268 | int configChanges = 0; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4269 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4270 | // First: make sure we have the most recent configuration and most |
| 4271 | // recent version of the activity, or skip it if some previous call |
| 4272 | // had taken a more recent version. |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4273 | synchronized (mResourcesManager) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4274 | int N = mRelaunchingActivities.size(); |
| 4275 | IBinder token = tmp.token; |
| 4276 | tmp = null; |
| 4277 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4278 | ActivityClientRecord r = mRelaunchingActivities.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4279 | if (r.token == token) { |
| 4280 | tmp = r; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4281 | configChanges |= tmp.pendingConfigChanges; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4282 | mRelaunchingActivities.remove(i); |
| 4283 | i--; |
| 4284 | N--; |
| 4285 | } |
| 4286 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4287 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4288 | if (tmp == null) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4289 | 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] | 4290 | return; |
| 4291 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4292 | |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4293 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Relaunching activity " |
| 4294 | + tmp.token + " with configChanges=0x" |
| 4295 | + Integer.toHexString(configChanges)); |
| 4296 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4297 | if (mPendingConfiguration != null) { |
| 4298 | changedConfig = mPendingConfiguration; |
| 4299 | mPendingConfiguration = null; |
| 4300 | } |
| 4301 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4302 | |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 4303 | if (tmp.lastProcessedSeq > tmp.relaunchSeq) { |
| 4304 | Slog.wtf(TAG, "For some reason target: " + tmp + " has lower sequence: " |
| 4305 | + tmp.relaunchSeq + " than current sequence: " + tmp.lastProcessedSeq); |
| 4306 | } else { |
| 4307 | tmp.lastProcessedSeq = tmp.relaunchSeq; |
| 4308 | } |
Dianne Hackborn | 871ecdc | 2009-12-11 15:24:33 -0800 | [diff] [blame] | 4309 | if (tmp.createdConfig != null) { |
| 4310 | // If the activity manager is passing us its current config, |
| 4311 | // assume that is really what we want regardless of what we |
| 4312 | // may have pending. |
| 4313 | if (mConfiguration == null |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4314 | || (tmp.createdConfig.isOtherSeqNewer(mConfiguration) |
| 4315 | && mConfiguration.diff(tmp.createdConfig) != 0)) { |
| 4316 | if (changedConfig == null |
| 4317 | || tmp.createdConfig.isOtherSeqNewer(changedConfig)) { |
| 4318 | changedConfig = tmp.createdConfig; |
| 4319 | } |
Dianne Hackborn | 871ecdc | 2009-12-11 15:24:33 -0800 | [diff] [blame] | 4320 | } |
| 4321 | } |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 4322 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4323 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Relaunching activity " |
Dianne Hackborn | dc6b635 | 2009-09-30 14:20:09 -0700 | [diff] [blame] | 4324 | + tmp.token + ": changedConfig=" + changedConfig); |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 4325 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4326 | // If there was a pending configuration change, execute it first. |
| 4327 | if (changedConfig != null) { |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 4328 | mCurDefaultDisplayDpi = changedConfig.densityDpi; |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 4329 | updateDefaultDensity(); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4330 | handleConfigurationChanged(changedConfig, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4331 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4332 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 4333 | ActivityClientRecord r = mActivities.get(tmp.token); |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4334 | 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] | 4335 | if (r == null) { |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4336 | if (!tmp.onlyLocalRequest) { |
| 4337 | try { |
| 4338 | ActivityManagerNative.getDefault().activityRelaunched(tmp.token); |
| 4339 | } catch (RemoteException e) { |
| 4340 | // If the system process has died, it's game over for everyone. |
| 4341 | } |
| 4342 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4343 | return; |
| 4344 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4345 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4346 | r.activity.mConfigChangeFlags |= configChanges; |
Dianne Hackborn | 30c9bd8 | 2010-12-01 16:07:40 -0800 | [diff] [blame] | 4347 | r.onlyLocalRequest = tmp.onlyLocalRequest; |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4348 | r.mPreserveWindow = tmp.mPreserveWindow; |
Filip Gruszczynski | db5dec2 | 2015-10-11 15:17:48 -0700 | [diff] [blame] | 4349 | r.lastProcessedSeq = tmp.lastProcessedSeq; |
| 4350 | r.relaunchSeq = tmp.relaunchSeq; |
Christopher Tate | b70f3df | 2009-04-07 16:07:59 -0700 | [diff] [blame] | 4351 | Intent currentIntent = r.activity.mIntent; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4352 | |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4353 | r.activity.mChangingConfigurations = true; |
| 4354 | |
Robert Carr | 23fa16b | 2016-01-13 13:19:58 -0800 | [diff] [blame] | 4355 | // If we are preserving the main window across relaunches we would also like to preserve |
| 4356 | // the children. However the client side view system does not support preserving |
| 4357 | // the child views so we notify the window manager to expect these windows to |
| 4358 | // be replaced and defer requests to destroy or hide them. This way we can achieve |
| 4359 | // visual continuity. It's important that we do this here prior to pause and destroy |
| 4360 | // as that is when we may hide or remove the child views. |
| 4361 | try { |
| 4362 | if (r.mPreserveWindow) { |
| 4363 | WindowManagerGlobal.getWindowSession().prepareToReplaceChildren(r.token); |
| 4364 | } |
| 4365 | } catch (RemoteException e) { |
| 4366 | // If the system process has died, it's game over for everyone. |
| 4367 | } |
| 4368 | |
| 4369 | |
Dianne Hackborn | e2b0480 | 2010-12-09 09:24:55 -0800 | [diff] [blame] | 4370 | // Need to ensure state is saved. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4371 | if (!r.paused) { |
Dianne Hackborn | e2b0480 | 2010-12-09 09:24:55 -0800 | [diff] [blame] | 4372 | performPauseActivity(r.token, false, r.isPreHoneycomb()); |
| 4373 | } |
| 4374 | if (r.state == null && !r.stopped && !r.isPreHoneycomb()) { |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 4375 | callCallActivityOnSaveInstanceState(r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4376 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4377 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4378 | handleDestroyActivity(r.token, false, configChanges, true); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4379 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4380 | r.activity = null; |
| 4381 | r.window = null; |
| 4382 | r.hideForNow = false; |
| 4383 | r.nextIdle = null; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4384 | // Merge any pending results and pending intents; don't just replace them |
| 4385 | if (tmp.pendingResults != null) { |
| 4386 | if (r.pendingResults == null) { |
| 4387 | r.pendingResults = tmp.pendingResults; |
| 4388 | } else { |
| 4389 | r.pendingResults.addAll(tmp.pendingResults); |
| 4390 | } |
| 4391 | } |
| 4392 | if (tmp.pendingIntents != null) { |
| 4393 | if (r.pendingIntents == null) { |
| 4394 | r.pendingIntents = tmp.pendingIntents; |
| 4395 | } else { |
| 4396 | r.pendingIntents.addAll(tmp.pendingIntents); |
| 4397 | } |
| 4398 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4399 | r.startsNotResumed = tmp.startsNotResumed; |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 4400 | r.overrideConfig = tmp.overrideConfig; |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4401 | |
Christopher Tate | b70f3df | 2009-04-07 16:07:59 -0700 | [diff] [blame] | 4402 | handleLaunchActivity(r, currentIntent); |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4403 | |
| 4404 | if (!tmp.onlyLocalRequest) { |
| 4405 | try { |
| 4406 | ActivityManagerNative.getDefault().activityRelaunched(r.token); |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 4407 | if (r.window != null) { |
| 4408 | r.window.reportActivityRelaunched(); |
| 4409 | } |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4410 | } catch (RemoteException e) { |
| 4411 | // If the system process has died, it's game over for everyone. |
| 4412 | } |
| 4413 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4414 | } |
| 4415 | |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 4416 | private void callCallActivityOnSaveInstanceState(ActivityClientRecord r) { |
| 4417 | r.state = new Bundle(); |
| 4418 | r.state.setAllowFds(false); |
| 4419 | if (r.isPersistable()) { |
| 4420 | r.persistentState = new PersistableBundle(); |
| 4421 | mInstrumentation.callActivityOnSaveInstanceState(r.activity, r.state, |
| 4422 | r.persistentState); |
| 4423 | } else { |
| 4424 | mInstrumentation.callActivityOnSaveInstanceState(r.activity, r.state); |
| 4425 | } |
| 4426 | } |
| 4427 | |
Dianne Hackborn | 73c1416 | 2012-09-19 15:45:06 -0700 | [diff] [blame] | 4428 | ArrayList<ComponentCallbacks2> collectComponentCallbacks( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4429 | boolean allActivities, Configuration newConfig) { |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 4430 | ArrayList<ComponentCallbacks2> callbacks |
| 4431 | = new ArrayList<ComponentCallbacks2>(); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4432 | |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4433 | synchronized (mResourcesManager) { |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 4434 | final int NAPP = mAllApplications.size(); |
| 4435 | for (int i=0; i<NAPP; i++) { |
Dianne Hackborn | 73c1416 | 2012-09-19 15:45:06 -0700 | [diff] [blame] | 4436 | callbacks.add(mAllApplications.get(i)); |
| 4437 | } |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 4438 | final int NACT = mActivities.size(); |
| 4439 | for (int i=0; i<NACT; i++) { |
| 4440 | ActivityClientRecord ar = mActivities.valueAt(i); |
| 4441 | Activity a = ar.activity; |
| 4442 | if (a != null) { |
| 4443 | Configuration thisConfig = applyConfigCompatMainThread( |
| 4444 | mCurDefaultDisplayDpi, newConfig, |
| 4445 | ar.packageInfo.getCompatibilityInfo()); |
| 4446 | if (!ar.activity.mFinished && (allActivities || !ar.paused)) { |
| 4447 | // If the activity is currently resumed, its configuration |
| 4448 | // needs to change right now. |
| 4449 | callbacks.add(a); |
| 4450 | } else if (thisConfig != null) { |
| 4451 | // Otherwise, we will tell it about the change |
| 4452 | // the next time it is resumed or shown. Note that |
| 4453 | // the activity manager may, before then, decide the |
| 4454 | // activity needs to be destroyed to handle its new |
| 4455 | // configuration. |
| 4456 | if (DEBUG_CONFIGURATION) { |
| 4457 | Slog.v(TAG, "Setting activity " |
| 4458 | + ar.activityInfo.name + " newConfig=" + thisConfig); |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 4459 | } |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 4460 | ar.newConfig = thisConfig; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4461 | } |
| 4462 | } |
| 4463 | } |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 4464 | final int NSVC = mServices.size(); |
| 4465 | for (int i=0; i<NSVC; i++) { |
| 4466 | callbacks.add(mServices.valueAt(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4467 | } |
| 4468 | } |
| 4469 | synchronized (mProviderMap) { |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 4470 | final int NPRV = mLocalProviders.size(); |
| 4471 | for (int i=0; i<NPRV; i++) { |
| 4472 | callbacks.add(mLocalProviders.valueAt(i).mLocalProvider); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4473 | } |
| 4474 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4475 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4476 | return callbacks; |
| 4477 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4478 | |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 4479 | private static void performConfigurationChanged(ComponentCallbacks2 cb, Configuration config, |
| 4480 | boolean reportToActivity) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4481 | // Only for Activity objects, check that they actually call up to their |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 4482 | // superclass implementation. ComponentCallbacks2 is an interface, so |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4483 | // we check the runtime type and act accordingly. |
| 4484 | Activity activity = (cb instanceof Activity) ? (Activity) cb : null; |
| 4485 | if (activity != null) { |
| 4486 | activity.mCalled = false; |
| 4487 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4488 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4489 | boolean shouldChangeConfig = false; |
| 4490 | if ((activity == null) || (activity.mCurrentConfig == null)) { |
| 4491 | shouldChangeConfig = true; |
| 4492 | } else { |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4493 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4494 | // If the new config is the same as the config this Activity |
| 4495 | // is already running with then don't bother calling |
| 4496 | // onConfigurationChanged |
| 4497 | int diff = activity.mCurrentConfig.diff(config); |
| 4498 | if (diff != 0) { |
Wale Ogunwale | 14e811f | 2015-12-14 15:04:22 -0800 | [diff] [blame] | 4499 | // If this activity doesn't handle any of the config changes then don't bother |
| 4500 | // calling onConfigurationChanged as we're going to destroy it. |
| 4501 | // Except in the case where the configuration changed on the activity manager side, |
| 4502 | // but wasn't big enough to cause a resource change so the activity wasn't destroyed. |
| 4503 | // In this case we still want to change the configuration of the activity but not |
| 4504 | // report it to the app. |
| 4505 | if ((~activity.mActivityInfo.getRealConfigChanged() & diff) == 0 |
| 4506 | || !reportToActivity) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4507 | shouldChangeConfig = true; |
| 4508 | } |
| 4509 | } |
| 4510 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4511 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4512 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Config callback " + cb |
Dianne Hackborn | dc6b635 | 2009-09-30 14:20:09 -0700 | [diff] [blame] | 4513 | + ": shouldChangeConfig=" + shouldChangeConfig); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4514 | if (shouldChangeConfig) { |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 4515 | if (reportToActivity) { |
| 4516 | cb.onConfigurationChanged(config); |
| 4517 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4518 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4519 | if (activity != null) { |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 4520 | if (reportToActivity && !activity.mCalled) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4521 | throw new SuperNotCalledException( |
| 4522 | "Activity " + activity.getLocalClassName() + |
| 4523 | " did not call through to super.onConfigurationChanged()"); |
| 4524 | } |
| 4525 | activity.mConfigChangeFlags = 0; |
| 4526 | activity.mCurrentConfig = new Configuration(config); |
| 4527 | } |
| 4528 | } |
| 4529 | } |
| 4530 | |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 4531 | public final void applyConfigurationToResources(Configuration config) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4532 | synchronized (mResourcesManager) { |
| 4533 | mResourcesManager.applyConfigurationToResourcesLocked(config, null); |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 4534 | } |
| 4535 | } |
| 4536 | |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 4537 | final Configuration applyCompatConfiguration(int displayDensity) { |
Dianne Hackborn | 836e262 | 2011-10-04 18:32:39 -0700 | [diff] [blame] | 4538 | Configuration config = mConfiguration; |
| 4539 | if (mCompatConfiguration == null) { |
| 4540 | mCompatConfiguration = new Configuration(); |
| 4541 | } |
| 4542 | mCompatConfiguration.setTo(mConfiguration); |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4543 | if (mResourcesManager.applyCompatConfiguration(displayDensity, mCompatConfiguration)) { |
Dianne Hackborn | 836e262 | 2011-10-04 18:32:39 -0700 | [diff] [blame] | 4544 | config = mCompatConfiguration; |
| 4545 | } |
| 4546 | return config; |
| 4547 | } |
| 4548 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4549 | final void handleConfigurationChanged(Configuration config, CompatibilityInfo compat) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4550 | |
Fabrice Di Meglio | 30ca5cd | 2012-05-07 17:45:44 -0700 | [diff] [blame] | 4551 | int configDiff = 0; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4552 | |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4553 | synchronized (mResourcesManager) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4554 | if (mPendingConfiguration != null) { |
| 4555 | if (!mPendingConfiguration.isOtherSeqNewer(config)) { |
| 4556 | config = mPendingConfiguration; |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 4557 | mCurDefaultDisplayDpi = config.densityDpi; |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 4558 | updateDefaultDensity(); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4559 | } |
| 4560 | mPendingConfiguration = null; |
| 4561 | } |
| 4562 | |
| 4563 | if (config == null) { |
| 4564 | return; |
| 4565 | } |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 4566 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4567 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Handle configuration changed: " |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4568 | + config); |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4569 | |
| 4570 | mResourcesManager.applyConfigurationToResourcesLocked(config, compat); |
| 4571 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4572 | if (mConfiguration == null) { |
| 4573 | mConfiguration = new Configuration(); |
| 4574 | } |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4575 | if (!mConfiguration.isOtherSeqNewer(config) && compat == null) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4576 | return; |
| 4577 | } |
Alan Viverette | e54d245 | 2015-05-06 10:41:43 -0700 | [diff] [blame] | 4578 | |
| 4579 | configDiff = mConfiguration.updateFrom(config); |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 4580 | config = applyCompatConfiguration(mCurDefaultDisplayDpi); |
Alan Viverette | 395cd01 | 2015-08-11 17:27:04 -0400 | [diff] [blame] | 4581 | |
| 4582 | final Theme systemTheme = getSystemContext().getTheme(); |
| 4583 | if ((systemTheme.getChangingConfigurations() & configDiff) != 0) { |
| 4584 | systemTheme.rebase(); |
| 4585 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4586 | } |
Dianne Hackborn | 73c1416 | 2012-09-19 15:45:06 -0700 | [diff] [blame] | 4587 | |
| 4588 | ArrayList<ComponentCallbacks2> callbacks = collectComponentCallbacks(false, config); |
| 4589 | |
Fabrice Di Meglio | 30ca5cd | 2012-05-07 17:45:44 -0700 | [diff] [blame] | 4590 | freeTextLayoutCachesIfNeeded(configDiff); |
| 4591 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4592 | if (callbacks != null) { |
| 4593 | final int N = callbacks.size(); |
| 4594 | for (int i=0; i<N; i++) { |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 4595 | performConfigurationChanged(callbacks.get(i), config, REPORT_TO_ACTIVITY); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4596 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4597 | } |
| 4598 | } |
| 4599 | |
Romain Guy | 46bfc48 | 2013-08-16 18:38:29 -0700 | [diff] [blame] | 4600 | static void freeTextLayoutCachesIfNeeded(int configDiff) { |
Fabrice Di Meglio | 30ca5cd | 2012-05-07 17:45:44 -0700 | [diff] [blame] | 4601 | if (configDiff != 0) { |
| 4602 | // Ask text layout engine to free its caches if there is a locale change |
| 4603 | boolean hasLocaleConfigChange = ((configDiff & ActivityInfo.CONFIG_LOCALE) != 0); |
| 4604 | if (hasLocaleConfigChange) { |
| 4605 | Canvas.freeTextLayoutCaches(); |
| 4606 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Cleared TextLayout Caches"); |
| 4607 | } |
| 4608 | } |
| 4609 | } |
| 4610 | |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 4611 | final void handleActivityConfigurationChanged(ActivityConfigChangeData data, |
| 4612 | boolean reportToActivity) { |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 4613 | ActivityClientRecord r = mActivities.get(data.activityToken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4614 | if (r == null || r.activity == null) { |
| 4615 | return; |
| 4616 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4617 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4618 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Handle activity config changed: " |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 4619 | + r.activityInfo.name + ", with callback=" + reportToActivity); |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 4620 | |
| 4621 | r.tmpConfig.setTo(mCompatConfiguration); |
| 4622 | if (data.overrideConfig != null) { |
| 4623 | r.overrideConfig = data.overrideConfig; |
| 4624 | r.tmpConfig.updateFrom(data.overrideConfig); |
| 4625 | } |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 4626 | performConfigurationChanged(r.activity, r.tmpConfig, reportToActivity); |
Fabrice Di Meglio | 30ca5cd | 2012-05-07 17:45:44 -0700 | [diff] [blame] | 4627 | |
| 4628 | freeTextLayoutCachesIfNeeded(r.activity.mCurrentConfig.diff(mCompatConfiguration)); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4629 | |
| 4630 | mSomeActivitiesChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4631 | } |
| 4632 | |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 4633 | final void handleProfilerControl(boolean start, ProfilerInfo profilerInfo, int profileType) { |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 4634 | if (start) { |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 4635 | try { |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 4636 | switch (profileType) { |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 4637 | default: |
| 4638 | mProfiler.setProfiler(profilerInfo); |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 4639 | mProfiler.startProfiling(); |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 4640 | break; |
| 4641 | } |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 4642 | } catch (RuntimeException e) { |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 4643 | Slog.w(TAG, "Profiling failed on path " + profilerInfo.profileFile |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 4644 | + " -- can the process access this path?"); |
Dianne Hackborn | 9c8dd55 | 2009-06-23 19:22:52 -0700 | [diff] [blame] | 4645 | } finally { |
| 4646 | try { |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 4647 | profilerInfo.profileFd.close(); |
Dianne Hackborn | 9c8dd55 | 2009-06-23 19:22:52 -0700 | [diff] [blame] | 4648 | } catch (IOException e) { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 4649 | Slog.w(TAG, "Failure closing profile fd", e); |
Dianne Hackborn | 9c8dd55 | 2009-06-23 19:22:52 -0700 | [diff] [blame] | 4650 | } |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 4651 | } |
| 4652 | } else { |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 4653 | switch (profileType) { |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 4654 | default: |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 4655 | mProfiler.stopProfiling(); |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 4656 | break; |
Romain Guy | 7eabe55 | 2011-07-21 14:56:34 -0700 | [diff] [blame] | 4657 | } |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 4658 | } |
| 4659 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4660 | |
Andreas Gampe | 4c79fea | 2016-01-28 20:11:41 -0800 | [diff] [blame] | 4661 | /** |
| 4662 | * Public entrypoint to stop profiling. This is required to end profiling when the app crashes, |
| 4663 | * so that profiler data won't be lost. |
| 4664 | * |
| 4665 | * @hide |
| 4666 | */ |
| 4667 | public void stopProfiling() { |
| 4668 | mProfiler.stopProfiling(); |
| 4669 | } |
| 4670 | |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 4671 | static final void handleDumpHeap(boolean managed, DumpHeapData dhd) { |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 4672 | if (managed) { |
| 4673 | try { |
| 4674 | Debug.dumpHprofData(dhd.path, dhd.fd.getFileDescriptor()); |
| 4675 | } catch (IOException e) { |
| 4676 | Slog.w(TAG, "Managed heap dump failed on path " + dhd.path |
| 4677 | + " -- can the process access this path?"); |
| 4678 | } finally { |
| 4679 | try { |
| 4680 | dhd.fd.close(); |
| 4681 | } catch (IOException e) { |
| 4682 | Slog.w(TAG, "Failure closing profile fd", e); |
| 4683 | } |
| 4684 | } |
| 4685 | } else { |
Andy McFadden | 06a6b55 | 2010-07-13 16:28:09 -0700 | [diff] [blame] | 4686 | Debug.dumpNativeHeap(dhd.fd.getFileDescriptor()); |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 4687 | } |
Dianne Hackborn | b9a5e4a | 2015-03-03 17:04:12 -0800 | [diff] [blame] | 4688 | try { |
| 4689 | ActivityManagerNative.getDefault().dumpHeapFinished(dhd.path); |
| 4690 | } catch (RemoteException e) { |
| 4691 | } |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 4692 | } |
| 4693 | |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 4694 | final void handleDispatchPackageBroadcast(int cmd, String[] packages) { |
| 4695 | boolean hasPkgInfo = false; |
| 4696 | if (packages != null) { |
mark_chen | 89764e3 | 2014-12-12 15:38:48 +0800 | [diff] [blame] | 4697 | synchronized (mResourcesManager) { |
| 4698 | for (int i=packages.length-1; i>=0; i--) { |
| 4699 | //Slog.i(TAG, "Cleaning old package: " + packages[i]); |
| 4700 | if (!hasPkgInfo) { |
| 4701 | WeakReference<LoadedApk> ref; |
| 4702 | ref = mPackages.get(packages[i]); |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 4703 | if (ref != null && ref.get() != null) { |
| 4704 | hasPkgInfo = true; |
mark_chen | 89764e3 | 2014-12-12 15:38:48 +0800 | [diff] [blame] | 4705 | } else { |
| 4706 | ref = mResourcePackages.get(packages[i]); |
| 4707 | if (ref != null && ref.get() != null) { |
| 4708 | hasPkgInfo = true; |
| 4709 | } |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 4710 | } |
| 4711 | } |
mark_chen | 89764e3 | 2014-12-12 15:38:48 +0800 | [diff] [blame] | 4712 | mPackages.remove(packages[i]); |
| 4713 | mResourcePackages.remove(packages[i]); |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 4714 | } |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 4715 | } |
| 4716 | } |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 4717 | ApplicationPackageManager.handlePackageBroadcast(cmd, packages, |
Dianne Hackborn | 4416c3d | 2010-05-04 17:22:49 -0700 | [diff] [blame] | 4718 | hasPkgInfo); |
| 4719 | } |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 4720 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4721 | final void handleLowMemory() { |
Dianne Hackborn | 73c1416 | 2012-09-19 15:45:06 -0700 | [diff] [blame] | 4722 | ArrayList<ComponentCallbacks2> callbacks = collectComponentCallbacks(true, null); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4723 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4724 | final int N = callbacks.size(); |
| 4725 | for (int i=0; i<N; i++) { |
| 4726 | callbacks.get(i).onLowMemory(); |
| 4727 | } |
| 4728 | |
Chris Tate | ce22905 | 2009-03-25 16:44:52 -0700 | [diff] [blame] | 4729 | // Ask SQLite to free up as much memory as it can, mostly from its page caches. |
| 4730 | if (Process.myUid() != Process.SYSTEM_UID) { |
| 4731 | int sqliteReleased = SQLiteDatabase.releaseMemory(); |
| 4732 | EventLog.writeEvent(SQLITE_MEM_RELEASED_EVENT_LOG_TAG, sqliteReleased); |
| 4733 | } |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 4734 | |
Mike Reed | caf0df1 | 2009-04-27 14:32:05 -0400 | [diff] [blame] | 4735 | // Ask graphics to free up as much as possible (font/image caches) |
| 4736 | Canvas.freeCaches(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4737 | |
Fabrice Di Meglio | 30ca5cd | 2012-05-07 17:45:44 -0700 | [diff] [blame] | 4738 | // Ask text layout engine to free also as much as possible |
| 4739 | Canvas.freeTextLayoutCaches(); |
| 4740 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4741 | BinderInternal.forceGc("mem"); |
| 4742 | } |
| 4743 | |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 4744 | final void handleTrimMemory(int level) { |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 4745 | if (DEBUG_MEMORY_TRIM) Slog.v(TAG, "Trimming memory to level: " + level); |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 4746 | |
Dianne Hackborn | 73c1416 | 2012-09-19 15:45:06 -0700 | [diff] [blame] | 4747 | ArrayList<ComponentCallbacks2> callbacks = collectComponentCallbacks(true, null); |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 4748 | |
| 4749 | final int N = callbacks.size(); |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 4750 | for (int i = 0; i < N; i++) { |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 4751 | callbacks.get(i).onTrimMemory(level); |
| 4752 | } |
Romain Guy | 19f86e8 | 2012-04-23 15:19:07 -0700 | [diff] [blame] | 4753 | |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 4754 | WindowManagerGlobal.getInstance().trimMemory(level); |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 4755 | } |
| 4756 | |
Jeff Sharkey | e1d330a | 2012-05-02 13:46:21 -0700 | [diff] [blame] | 4757 | private void setupGraphicsSupport(LoadedApk info, File cacheDir) { |
Dianne Hackborn | a0c283e | 2012-02-09 10:47:01 -0800 | [diff] [blame] | 4758 | if (Process.isIsolated()) { |
| 4759 | // Isolated processes aren't going to do UI. |
| 4760 | return; |
| 4761 | } |
Romain Guy | a958265 | 2011-11-10 14:20:10 -0800 | [diff] [blame] | 4762 | try { |
| 4763 | int uid = Process.myUid(); |
| 4764 | String[] packages = getPackageManager().getPackagesForUid(uid); |
| 4765 | |
| 4766 | // If there are several packages in this application we won't |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 4767 | // initialize the graphics disk caches |
Dianne Hackborn | a0c283e | 2012-02-09 10:47:01 -0800 | [diff] [blame] | 4768 | if (packages != null && packages.length == 1) { |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 4769 | ThreadedRenderer.setupDiskCache(cacheDir); |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 4770 | RenderScriptCacheDir.setupDiskCache(cacheDir); |
Romain Guy | a958265 | 2011-11-10 14:20:10 -0800 | [diff] [blame] | 4771 | } |
| 4772 | } catch (RemoteException e) { |
| 4773 | // Ignore |
| 4774 | } |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 4775 | } |
| 4776 | |
Calin Juravle | d96d2dd | 2016-02-02 23:28:39 +0000 | [diff] [blame] | 4777 | // Keep in sync with installd (frameworks/native/cmds/installd/commands.cpp). |
| 4778 | private static File getPrimaryProfileFile(String packageName) { |
| 4779 | return new File("/data/misc/profiles/cur/" + UserHandle.myUserId() + |
| 4780 | "/" + packageName + "/primary.prof"); |
| 4781 | } |
| 4782 | |
Calin Juravle | 6905239 | 2015-12-17 17:06:49 +0200 | [diff] [blame] | 4783 | private static void setupJitProfileSupport(LoadedApk loadedApk, File cacheDir) { |
Calin Juravle | db4a79a | 2015-12-23 18:55:08 +0200 | [diff] [blame] | 4784 | if (!SystemProperties.getBoolean("dalvik.vm.usejitprofiles", false)) { |
| 4785 | return; |
| 4786 | } |
Calin Juravle | 6905239 | 2015-12-17 17:06:49 +0200 | [diff] [blame] | 4787 | final ApplicationInfo appInfo = loadedApk.getApplicationInfo(); |
Calin Juravle | 6905239 | 2015-12-17 17:06:49 +0200 | [diff] [blame] | 4788 | final List<String> codePaths = new ArrayList<>(); |
| 4789 | if ((appInfo.flags & ApplicationInfo.FLAG_HAS_CODE) != 0) { |
| 4790 | codePaths.add(appInfo.sourceDir); |
| 4791 | } |
| 4792 | if (appInfo.splitSourceDirs != null) { |
| 4793 | Collections.addAll(codePaths, appInfo.splitSourceDirs); |
| 4794 | } |
| 4795 | |
| 4796 | if (codePaths.isEmpty()) { |
| 4797 | // If there are no code paths there's no need to setup a profile file and register with |
| 4798 | // the runtime, |
| 4799 | return; |
| 4800 | } |
| 4801 | |
Calin Juravle | d96d2dd | 2016-02-02 23:28:39 +0000 | [diff] [blame] | 4802 | final File profileFile = getPrimaryProfileFile(loadedApk.mPackageName); |
Calin Juravle | 6905239 | 2015-12-17 17:06:49 +0200 | [diff] [blame] | 4803 | if (!profileFile.exists()) { |
| 4804 | FileDescriptor fd = null; |
| 4805 | try { |
| 4806 | final int permissions = 0600; // read-write for user. |
| 4807 | fd = Os.open(profileFile.getAbsolutePath(), OsConstants.O_CREAT, permissions); |
| 4808 | Os.fchmod(fd, permissions); |
| 4809 | Os.fchown(fd, appInfo.uid, appInfo.uid); |
| 4810 | } catch (ErrnoException e) { |
Calin Juravle | d96d2dd | 2016-02-02 23:28:39 +0000 | [diff] [blame] | 4811 | Log.v(TAG, "Unable to create jit profile file " + profileFile, e); |
Calin Juravle | 6905239 | 2015-12-17 17:06:49 +0200 | [diff] [blame] | 4812 | try { |
| 4813 | Os.unlink(profileFile.getAbsolutePath()); |
| 4814 | } catch (ErrnoException unlinkErr) { |
| 4815 | Log.v(TAG, "Unable to unlink jit profile file " + profileFile, unlinkErr); |
| 4816 | } |
| 4817 | return; |
| 4818 | } finally { |
| 4819 | IoUtils.closeQuietly(fd); |
| 4820 | } |
| 4821 | } |
| 4822 | |
| 4823 | VMRuntime.registerAppInfo(profileFile.getAbsolutePath(), appInfo.dataDir, |
| 4824 | codePaths.toArray(new String[codePaths.size()])); |
| 4825 | } |
| 4826 | |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 4827 | private void updateDefaultDensity() { |
Alan Viverette | 2ac46f1 | 2016-02-04 16:58:14 -0500 | [diff] [blame] | 4828 | final int densityDpi = mCurDefaultDisplayDpi; |
| 4829 | if (!mDensityCompatMode |
| 4830 | && densityDpi != Configuration.DENSITY_DPI_UNDEFINED |
| 4831 | && densityDpi != DisplayMetrics.DENSITY_DEVICE) { |
| 4832 | DisplayMetrics.DENSITY_DEVICE = densityDpi; |
| 4833 | Bitmap.setDefaultDensity(densityDpi); |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 4834 | } |
| 4835 | } |
| 4836 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 4837 | private void handleBindApplication(AppBindData data) { |
Man Cao | cfa78b2 | 2015-06-11 20:14:34 -0700 | [diff] [blame] | 4838 | if (data.trackAllocation) { |
| 4839 | DdmVmInternal.enableRecentAllocations(true); |
| 4840 | } |
| 4841 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4842 | mBoundApplication = data; |
| 4843 | mConfiguration = new Configuration(data.config); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 4844 | mCompatConfiguration = new Configuration(data.config); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4845 | |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 4846 | mProfiler = new Profiler(); |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 4847 | if (data.initProfilerInfo != null) { |
| 4848 | mProfiler.profileFile = data.initProfilerInfo.profileFile; |
| 4849 | mProfiler.profileFd = data.initProfilerInfo.profileFd; |
| 4850 | mProfiler.samplingInterval = data.initProfilerInfo.samplingInterval; |
| 4851 | mProfiler.autoStopProfiler = data.initProfilerInfo.autoStopProfiler; |
| 4852 | } |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 4853 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4854 | // send up app name; do this *before* waiting for debugger |
Christopher Tate | 8ee038d | 2009-11-06 11:30:20 -0800 | [diff] [blame] | 4855 | Process.setArgV0(data.processName); |
Siva Velusamy | d693dfa | 2012-09-10 14:36:58 -0700 | [diff] [blame] | 4856 | android.ddm.DdmHandleAppName.setAppName(data.processName, |
| 4857 | UserHandle.myUserId()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4858 | |
Dianne Hackborn | 5d927c2 | 2011-09-02 12:22:18 -0700 | [diff] [blame] | 4859 | if (data.persistent) { |
| 4860 | // Persistent processes on low-memory devices do not get to |
| 4861 | // use hardware accelerated drawing, since this can add too much |
| 4862 | // overhead to the process. |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 4863 | if (!ActivityManager.isHighEndGfx()) { |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 4864 | ThreadedRenderer.disable(false); |
Dianne Hackborn | 5d927c2 | 2011-09-02 12:22:18 -0700 | [diff] [blame] | 4865 | } |
| 4866 | } |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 4867 | |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 4868 | if (mProfiler.profileFd != null) { |
| 4869 | mProfiler.startProfiling(); |
Dianne Hackborn | 62f20ec | 2011-08-15 17:40:28 -0700 | [diff] [blame] | 4870 | } |
| 4871 | |
Joe Onorato | d630f10 | 2011-03-17 18:42:26 -0700 | [diff] [blame] | 4872 | // If the app is Honeycomb MR1 or earlier, switch its AsyncTask |
| 4873 | // implementation to use the pool executor. Normally, we use the |
| 4874 | // serialized executor as the default. This has to happen in the |
| 4875 | // main thread so the main looper is set right. |
Dianne Hackborn | 81e9276 | 2011-10-09 16:00:21 -0700 | [diff] [blame] | 4876 | if (data.appInfo.targetSdkVersion <= android.os.Build.VERSION_CODES.HONEYCOMB_MR1) { |
Joe Onorato | d630f10 | 2011-03-17 18:42:26 -0700 | [diff] [blame] | 4877 | AsyncTask.setDefaultExecutor(AsyncTask.THREAD_POOL_EXECUTOR); |
| 4878 | } |
| 4879 | |
Dianne Hackborn | 7895bc2 | 2014-09-05 15:09:03 -0700 | [diff] [blame] | 4880 | Message.updateCheckRecycle(data.appInfo.targetSdkVersion); |
| 4881 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4882 | /* |
| 4883 | * Before spawning a new process, reset the time zone to be the system time zone. |
| 4884 | * This needs to be done because the system time zone could have changed after the |
| 4885 | * the spawning of this process. Without doing this this process would have the incorrect |
| 4886 | * system time zone. |
| 4887 | */ |
| 4888 | TimeZone.setDefault(null); |
| 4889 | |
| 4890 | /* |
Seigo Nonaka | cada57a | 2016-01-22 17:22:11 +0900 | [diff] [blame] | 4891 | * Initialize the default locales in this process for the reasons we set the time zone. |
Roozbeh Pournader | 834641b | 2016-01-23 22:34:57 -0800 | [diff] [blame] | 4892 | * |
| 4893 | * We do this through ResourcesManager, since we need to do locale negotiation. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4894 | */ |
Roozbeh Pournader | 834641b | 2016-01-23 22:34:57 -0800 | [diff] [blame] | 4895 | mResourcesManager.setDefaultLocalesLocked(data.config.getLocales()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4896 | |
Suchi Amalapurapu | c984329 | 2009-06-24 17:02:25 -0700 | [diff] [blame] | 4897 | /* |
| 4898 | * Update the system configuration since its preloaded and might not |
| 4899 | * reflect configuration changes. The configuration object passed |
| 4900 | * in AppBindData can be safely assumed to be up to date |
| 4901 | */ |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 4902 | mResourcesManager.applyConfigurationToResourcesLocked(data.config, data.compatInfo); |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 4903 | mCurDefaultDisplayDpi = data.config.densityDpi; |
| 4904 | applyCompatConfiguration(mCurDefaultDisplayDpi); |
Suchi Amalapurapu | c984329 | 2009-06-24 17:02:25 -0700 | [diff] [blame] | 4905 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4906 | data.info = getPackageInfoNoCheck(data.appInfo, data.compatInfo); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4907 | |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 4908 | /** |
| 4909 | * Switch this process to density compatibility mode if needed. |
| 4910 | */ |
| 4911 | if ((data.appInfo.flags&ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES) |
| 4912 | == 0) { |
| 4913 | mDensityCompatMode = true; |
| 4914 | Bitmap.setDefaultDensity(DisplayMetrics.DENSITY_DEFAULT); |
| 4915 | } |
| 4916 | updateDefaultDensity(); |
| 4917 | |
Narayan Kamath | ccb2a086 | 2013-12-19 14:49:36 +0000 | [diff] [blame] | 4918 | final boolean is24Hr = "24".equals(mCoreSettings.getString(Settings.System.TIME_12_24)); |
| 4919 | DateFormat.set24HourTimePref(is24Hr); |
| 4920 | |
Jon Miranda | 836c0a8 | 2014-08-11 12:32:26 -0700 | [diff] [blame] | 4921 | View.mDebugViewAttributes = |
| 4922 | mCoreSettings.getInt(Settings.Global.DEBUG_VIEW_ATTRIBUTES, 0) != 0; |
| 4923 | |
Dianne Hackborn | 96e240f | 2009-07-26 17:42:30 -0700 | [diff] [blame] | 4924 | /** |
Brad Fitzpatrick | 438d059 | 2010-06-10 12:19:19 -0700 | [diff] [blame] | 4925 | * For system applications on userdebug/eng builds, log stack |
| 4926 | * traces of disk and network access to dropbox for analysis. |
| 4927 | */ |
Brad Fitzpatrick | ad13b98 | 2010-07-14 12:35:53 -0700 | [diff] [blame] | 4928 | if ((data.appInfo.flags & |
| 4929 | (ApplicationInfo.FLAG_SYSTEM | |
Brad Fitzpatrick | 50d66f9 | 2010-09-13 21:29:05 -0700 | [diff] [blame] | 4930 | ApplicationInfo.FLAG_UPDATED_SYSTEM_APP)) != 0) { |
| 4931 | StrictMode.conditionallyEnableDebugLogging(); |
Brad Fitzpatrick | 438d059 | 2010-06-10 12:19:19 -0700 | [diff] [blame] | 4932 | } |
| 4933 | |
| 4934 | /** |
Jeff Sharkey | 344744b | 2016-01-28 19:03:30 -0700 | [diff] [blame] | 4935 | * For apps targetting Honeycomb or later, we don't allow network usage |
| 4936 | * on the main event loop / UI thread. This is what ultimately throws |
| 4937 | * {@link NetworkOnMainThreadException}. |
Brad Fitzpatrick | b6e1841 | 2010-10-28 14:50:05 -0700 | [diff] [blame] | 4938 | */ |
Jeff Sharkey | 344744b | 2016-01-28 19:03:30 -0700 | [diff] [blame] | 4939 | if (data.appInfo.targetSdkVersion >= Build.VERSION_CODES.HONEYCOMB) { |
Brad Fitzpatrick | b6e1841 | 2010-10-28 14:50:05 -0700 | [diff] [blame] | 4940 | StrictMode.enableDeathOnNetwork(); |
| 4941 | } |
| 4942 | |
Jeff Sharkey | 344744b | 2016-01-28 19:03:30 -0700 | [diff] [blame] | 4943 | /** |
| 4944 | * For apps targetting N or later, we don't allow file:// Uri exposure. |
| 4945 | * This is what ultimately throws {@link FileUriExposedException}. |
| 4946 | */ |
| 4947 | if (data.appInfo.targetSdkVersion >= Build.VERSION_CODES.N) { |
Thierry Strudel | e60b28d | 2016-02-25 02:14:16 +0000 | [diff] [blame] | 4948 | StrictMode.enableDeathOnFileUriExposure(); |
Jeff Sharkey | 344744b | 2016-01-28 19:03:30 -0700 | [diff] [blame] | 4949 | } |
| 4950 | |
Alex Klyubin | f9034cc | 2015-02-12 11:43:09 -0800 | [diff] [blame] | 4951 | NetworkSecurityPolicy.getInstance().setCleartextTrafficPermitted( |
| 4952 | (data.appInfo.flags & ApplicationInfo.FLAG_USES_CLEARTEXT_TRAFFIC) != 0); |
| 4953 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4954 | if (data.debugMode != IApplicationThread.DEBUG_OFF) { |
| 4955 | // XXX should have option to change the port. |
| 4956 | Debug.changeDebugPort(8100); |
| 4957 | if (data.debugMode == IApplicationThread.DEBUG_WAIT) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4958 | Slog.w(TAG, "Application " + data.info.getPackageName() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4959 | + " is waiting for the debugger on port 8100..."); |
| 4960 | |
| 4961 | IActivityManager mgr = ActivityManagerNative.getDefault(); |
| 4962 | try { |
| 4963 | mgr.showWaitingForDebugger(mAppThread, true); |
| 4964 | } catch (RemoteException ex) { |
| 4965 | } |
| 4966 | |
| 4967 | Debug.waitForDebugger(); |
| 4968 | |
| 4969 | try { |
| 4970 | mgr.showWaitingForDebugger(mAppThread, false); |
| 4971 | } catch (RemoteException ex) { |
| 4972 | } |
| 4973 | |
| 4974 | } else { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 4975 | Slog.w(TAG, "Application " + data.info.getPackageName() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4976 | + " can be debugged on port 8100..."); |
| 4977 | } |
| 4978 | } |
| 4979 | |
Jamie Gennis | f9c7d6b | 2013-03-25 14:18:25 -0700 | [diff] [blame] | 4980 | // Allow application-generated systrace messages if we're debuggable. |
Rahul Chaturvedi | 52613f9 | 2015-06-17 23:54:08 -0400 | [diff] [blame] | 4981 | boolean isAppDebuggable = (data.appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0; |
| 4982 | Trace.setAppTracingAllowed(isAppDebuggable); |
| 4983 | if (isAppDebuggable && data.enableBinderTracking) { |
| 4984 | Binder.enableTracing(); |
| 4985 | } |
Jamie Gennis | f9c7d6b | 2013-03-25 14:18:25 -0700 | [diff] [blame] | 4986 | |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 4987 | /** |
| 4988 | * Initialize the default http proxy in this process for the reasons we set the time zone. |
| 4989 | */ |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 4990 | final IBinder b = ServiceManager.getService(Context.CONNECTIVITY_SERVICE); |
Dianne Hackborn | d4d32c5 | 2011-11-08 17:33:59 -0800 | [diff] [blame] | 4991 | if (b != null) { |
| 4992 | // In pre-boot mode (doing initial launch to collect password), not |
| 4993 | // all system is up. This includes the connectivity service, so don't |
| 4994 | // crash if we can't get it. |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 4995 | final IConnectivityManager service = IConnectivityManager.Stub.asInterface(b); |
Dianne Hackborn | d4d32c5 | 2011-11-08 17:33:59 -0800 | [diff] [blame] | 4996 | try { |
Paul Jensen | cee9b51 | 2015-05-06 07:32:40 -0400 | [diff] [blame] | 4997 | final ProxyInfo proxyInfo = service.getProxyForNetwork(null); |
Jason Monk | 207900c | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 4998 | Proxy.setHttpProxySystemProperty(proxyInfo); |
Dianne Hackborn | d4d32c5 | 2011-11-08 17:33:59 -0800 | [diff] [blame] | 4999 | } catch (RemoteException e) {} |
| 5000 | } |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 5001 | |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 5002 | // Instrumentation info affects the class loader, so load it before |
| 5003 | // setting up the app context. |
| 5004 | final InstrumentationInfo ii; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5005 | if (data.instrumentationName != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5006 | try { |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 5007 | ii = new ApplicationPackageManager(null, getPackageManager()) |
| 5008 | .getInstrumentationInfo(data.instrumentationName, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5009 | } catch (PackageManager.NameNotFoundException e) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5010 | throw new RuntimeException( |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 5011 | "Unable to find instrumentation info for: " + data.instrumentationName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5012 | } |
| 5013 | |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 5014 | mInstrumentationPackageName = ii.packageName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5015 | mInstrumentationAppDir = ii.sourceDir; |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 5016 | mInstrumentationSplitAppDirs = ii.splitSourceDirs; |
| 5017 | mInstrumentationLibDir = ii.nativeLibraryDir; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5018 | mInstrumentedAppDir = data.info.getAppDir(); |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 5019 | mInstrumentedSplitAppDirs = data.info.getSplitAppDirs(); |
| 5020 | mInstrumentedLibDir = data.info.getLibDir(); |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 5021 | } else { |
| 5022 | ii = null; |
| 5023 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5024 | |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 5025 | final ContextImpl appContext = ContextImpl.createAppContext(this, data.info); |
Jeff Sharkey | e6cb097 | 2016-02-01 09:59:12 -0700 | [diff] [blame] | 5026 | if (!Process.isIsolated() && !"android".equals(appContext.getPackageName())) { |
Jeff Sharkey | e84bdd3 | 2016-02-08 12:16:00 -0700 | [diff] [blame] | 5027 | // This cache location probably points at credential-encrypted |
| 5028 | // storage which may not be accessible yet; assign it anyway instead |
| 5029 | // of pointing at device-encrypted storage. |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 5030 | final File cacheDir = appContext.getCacheDir(); |
| 5031 | if (cacheDir != null) { |
| 5032 | // Provide a usable directory for temporary files |
| 5033 | System.setProperty("java.io.tmpdir", cacheDir.getAbsolutePath()); |
| 5034 | } else { |
| 5035 | Log.v(TAG, "Unable to initialize \"java.io.tmpdir\" property " |
| 5036 | + "due to missing cache directory"); |
| 5037 | } |
Alan Viverette | 346296b | 2015-09-01 13:08:05 -0400 | [diff] [blame] | 5038 | |
Jeff Sharkey | e84bdd3 | 2016-02-08 12:16:00 -0700 | [diff] [blame] | 5039 | // Setup a location to store generated/compiled graphics code and |
| 5040 | // JIT profiling data. Note that this data is stored in a |
| 5041 | // device-encrypted storage area, so these caches must never contain |
| 5042 | // user sensitive user data. |
| 5043 | final Context deviceContext = appContext.createDeviceEncryptedStorageContext(); |
| 5044 | final File codeCacheDir = deviceContext.getCodeCacheDir(); |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 5045 | if (codeCacheDir != null) { |
| 5046 | setupGraphicsSupport(data.info, codeCacheDir); |
Calin Juravle | c74d338 | 2016-01-07 12:15:36 +0000 | [diff] [blame] | 5047 | setupJitProfileSupport(data.info, codeCacheDir); |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 5048 | } else { |
Calin Juravle | c74d338 | 2016-01-07 12:15:36 +0000 | [diff] [blame] | 5049 | Log.e(TAG, "Unable to setupGraphicsSupport and setupJitProfileSupport " + |
| 5050 | "due to missing code-cache directory"); |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 5051 | } |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 5052 | |
Michael Lentine | 2ba303f | 2016-02-01 20:44:34 -0600 | [diff] [blame] | 5053 | // Add the lib dir path to hardware renderer so that vulkan layers |
| 5054 | // can be searched for within that directory. |
| 5055 | ThreadedRenderer.setLibDir(data.info.getLibDir()); |
| 5056 | } |
Michael Lentine | 03d8f768 | 2016-01-31 15:37:11 -0600 | [diff] [blame] | 5057 | |
Chad Brubaker | 78d4712 | 2015-11-17 22:26:58 -0800 | [diff] [blame] | 5058 | // Install the Network Security Config Provider. This must happen before the application |
| 5059 | // code is loaded to prevent issues with instances of TLS objects being created before |
| 5060 | // the provider is installed. |
| 5061 | NetworkSecurityConfigProvider.install(appContext); |
| 5062 | |
Alan Viverette | 2107d69 | 2015-09-03 14:55:27 -0400 | [diff] [blame] | 5063 | // Continue loading instrumentation. |
| 5064 | if (ii != null) { |
Alan Viverette | 346296b | 2015-09-01 13:08:05 -0400 | [diff] [blame] | 5065 | final ApplicationInfo instrApp = new ApplicationInfo(); |
Jeff Sharkey | 1544779 | 2015-11-05 16:18:51 -0800 | [diff] [blame] | 5066 | ii.copyTo(instrApp); |
Fyodor Kupolov | af38b8e | 2015-12-02 16:16:07 -0800 | [diff] [blame] | 5067 | instrApp.initForUser(UserHandle.myUserId()); |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 5068 | final LoadedApk pi = getPackageInfo(instrApp, data.compatInfo, |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 5069 | appContext.getClassLoader(), false, true, false); |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 5070 | final ContextImpl instrContext = ContextImpl.createAppContext(this, pi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5071 | |
| 5072 | try { |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 5073 | final ClassLoader cl = instrContext.getClassLoader(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5074 | mInstrumentation = (Instrumentation) |
| 5075 | cl.loadClass(data.instrumentationName.getClassName()).newInstance(); |
| 5076 | } catch (Exception e) { |
| 5077 | throw new RuntimeException( |
| 5078 | "Unable to instantiate instrumentation " |
| 5079 | + data.instrumentationName + ": " + e.toString(), e); |
| 5080 | } |
| 5081 | |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 5082 | final ComponentName component = new ComponentName(ii.packageName, ii.name); |
| 5083 | mInstrumentation.init(this, instrContext, appContext, component, |
| 5084 | data.instrumentationWatcher, data.instrumentationUiAutomationConnection); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5085 | |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 5086 | if (mProfiler.profileFile != null && !ii.handleProfiling |
| 5087 | && mProfiler.profileFd == null) { |
| 5088 | mProfiler.handlingProfiling = true; |
Alan Viverette | be64eae | 2015-09-03 14:56:04 -0400 | [diff] [blame] | 5089 | final File file = new File(mProfiler.profileFile); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5090 | file.getParentFile().mkdirs(); |
| 5091 | Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024); |
| 5092 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5093 | } else { |
| 5094 | mInstrumentation = new Instrumentation(); |
| 5095 | } |
| 5096 | |
Dianne Hackborn | 3b81bc1 | 2011-01-15 11:50:52 -0800 | [diff] [blame] | 5097 | if ((data.appInfo.flags&ApplicationInfo.FLAG_LARGE_HEAP) != 0) { |
Dianne Hackborn | de39851 | 2011-01-18 18:45:21 -0800 | [diff] [blame] | 5098 | dalvik.system.VMRuntime.getRuntime().clearGrowthLimit(); |
Mathieu Chartier | 24cee07 | 2015-01-08 14:42:20 -0800 | [diff] [blame] | 5099 | } else { |
| 5100 | // Small heap, clamp to the current growth limit and let the heap release |
| 5101 | // pages after the growth limit to the non growth limit capacity. b/18387825 |
| 5102 | dalvik.system.VMRuntime.getRuntime().clampGrowthLimit(); |
Dianne Hackborn | 3b81bc1 | 2011-01-15 11:50:52 -0800 | [diff] [blame] | 5103 | } |
| 5104 | |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 5105 | // Allow disk access during application and provider setup. This could |
Jeff Sharkey | 7c50167 | 2012-02-28 12:08:37 -0800 | [diff] [blame] | 5106 | // block processing ordered broadcasts, but later processing would |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 5107 | // probably end up doing the same disk access. |
Jeff Sharkey | 7c50167 | 2012-02-28 12:08:37 -0800 | [diff] [blame] | 5108 | final StrictMode.ThreadPolicy savedPolicy = StrictMode.allowThreadDiskWrites(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5109 | try { |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 5110 | // If the app is being launched for full backup or restore, bring it up in |
| 5111 | // a restricted environment with the base application class. |
| 5112 | Application app = data.info.makeApplication(data.restrictedBackupMode, null); |
| 5113 | mInitialApplication = app; |
Jeff Sharkey | 7c50167 | 2012-02-28 12:08:37 -0800 | [diff] [blame] | 5114 | |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 5115 | // don't bring up providers in restricted mode; they may depend on the |
| 5116 | // app's custom Application class |
| 5117 | if (!data.restrictedBackupMode) { |
| 5118 | List<ProviderInfo> providers = data.providers; |
| 5119 | if (providers != null) { |
| 5120 | installContentProviders(app, providers); |
| 5121 | // For process that contains content providers, we want to |
| 5122 | // ensure that the JIT is enabled "at some point". |
| 5123 | mH.sendEmptyMessageDelayed(H.ENABLE_JIT, 10*1000); |
| 5124 | } |
| 5125 | } |
| 5126 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5127 | // Do this after providers, since instrumentation tests generally start their |
| 5128 | // test thread at this point, and we don't want that racing. |
| 5129 | try { |
| 5130 | mInstrumentation.onCreate(data.instrumentationArgs); |
| 5131 | } |
| 5132 | catch (Exception e) { |
| 5133 | throw new RuntimeException( |
| 5134 | "Exception thrown in onCreate() of " |
| 5135 | + data.instrumentationName + ": " + e.toString(), e); |
| 5136 | } |
| 5137 | |
Jeff Sharkey | 6bff62c | 2012-02-29 12:26:36 -0800 | [diff] [blame] | 5138 | try { |
| 5139 | mInstrumentation.callApplicationOnCreate(app); |
| 5140 | } catch (Exception e) { |
| 5141 | if (!mInstrumentation.onException(app, e)) { |
| 5142 | throw new RuntimeException( |
| 5143 | "Unable to create application " + app.getClass().getName() |
| 5144 | + ": " + e.toString(), e); |
| 5145 | } |
| 5146 | } |
| 5147 | } finally { |
| 5148 | StrictMode.setThreadPolicy(savedPolicy); |
| 5149 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5150 | } |
| 5151 | |
| 5152 | /*package*/ final void finishInstrumentation(int resultCode, Bundle results) { |
| 5153 | IActivityManager am = ActivityManagerNative.getDefault(); |
Jeff Sharkey | 3ad9d00 | 2011-09-15 15:51:54 -0700 | [diff] [blame] | 5154 | if (mProfiler.profileFile != null && mProfiler.handlingProfiling |
| 5155 | && mProfiler.profileFd == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5156 | Debug.stopMethodTracing(); |
| 5157 | } |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 5158 | //Slog.i(TAG, "am: " + ActivityManagerNative.getDefault() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5159 | // + ", app thr: " + mAppThread); |
| 5160 | try { |
| 5161 | am.finishInstrumentation(mAppThread, resultCode, results); |
| 5162 | } catch (RemoteException ex) { |
| 5163 | } |
| 5164 | } |
| 5165 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 5166 | private void installContentProviders( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5167 | Context context, List<ProviderInfo> providers) { |
| 5168 | final ArrayList<IActivityManager.ContentProviderHolder> results = |
| 5169 | new ArrayList<IActivityManager.ContentProviderHolder>(); |
| 5170 | |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 5171 | for (ProviderInfo cpi : providers) { |
Dianne Hackborn | 40e9f29 | 2012-11-27 19:12:23 -0800 | [diff] [blame] | 5172 | if (DEBUG_PROVIDER) { |
| 5173 | StringBuilder buf = new StringBuilder(128); |
| 5174 | buf.append("Pub "); |
| 5175 | buf.append(cpi.authority); |
| 5176 | buf.append(": "); |
| 5177 | buf.append(cpi.name); |
| 5178 | Log.i(TAG, buf.toString()); |
| 5179 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5180 | IActivityManager.ContentProviderHolder cph = installProvider(context, null, cpi, |
| 5181 | false /*noisy*/, true /*noReleaseNeeded*/, true /*stable*/); |
| 5182 | if (cph != null) { |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5183 | cph.noReleaseNeeded = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5184 | results.add(cph); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5185 | } |
| 5186 | } |
| 5187 | |
| 5188 | try { |
| 5189 | ActivityManagerNative.getDefault().publishContentProviders( |
| 5190 | getApplicationThread(), results); |
| 5191 | } catch (RemoteException ex) { |
| 5192 | } |
| 5193 | } |
| 5194 | |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 5195 | public final IContentProvider acquireProvider( |
| 5196 | Context c, String auth, int userId, boolean stable) { |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 5197 | final IContentProvider provider = acquireExistingProvider(c, auth, userId, stable); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5198 | if (provider != null) { |
| 5199 | return provider; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5200 | } |
| 5201 | |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 5202 | // There is a possible race here. Another thread may try to acquire |
| 5203 | // the same provider at the same time. When this happens, we want to ensure |
| 5204 | // that the first one wins. |
| 5205 | // Note that we cannot hold the lock while acquiring and installing the |
| 5206 | // provider since it might take a long time to run and it could also potentially |
| 5207 | // 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] | 5208 | IActivityManager.ContentProviderHolder holder = null; |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 5209 | try { |
| 5210 | holder = ActivityManagerNative.getDefault().getContentProvider( |
| 5211 | getApplicationThread(), auth, userId, stable); |
| 5212 | } catch (RemoteException ex) { |
Wale Ogunwale | 67fe0a4 | 2015-04-24 14:44:54 -0700 | [diff] [blame] | 5213 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5214 | if (holder == null) { |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 5215 | 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] | 5216 | return null; |
| 5217 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5218 | |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5219 | // Install provider will increment the reference count for us, and break |
| 5220 | // any ties in the race. |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5221 | holder = installProvider(c, holder, holder.info, |
| 5222 | true /*noisy*/, holder.noReleaseNeeded, stable); |
| 5223 | return holder.provider; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5224 | } |
| 5225 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5226 | private final void incProviderRefLocked(ProviderRefCount prc, boolean stable) { |
| 5227 | if (stable) { |
| 5228 | prc.stableCount += 1; |
| 5229 | if (prc.stableCount == 1) { |
| 5230 | // We are acquiring a new stable reference on the provider. |
| 5231 | int unstableDelta; |
| 5232 | if (prc.removePending) { |
| 5233 | // We have a pending remove operation, which is holding the |
| 5234 | // last unstable reference. At this point we are converting |
| 5235 | // that unstable reference to our new stable reference. |
| 5236 | unstableDelta = -1; |
| 5237 | // Cancel the removal of the provider. |
| 5238 | if (DEBUG_PROVIDER) { |
| 5239 | Slog.v(TAG, "incProviderRef: stable " |
| 5240 | + "snatched provider from the jaws of death"); |
| 5241 | } |
| 5242 | prc.removePending = false; |
Guobin Zhang | 9e3e5266 | 2013-03-21 13:57:11 +0800 | [diff] [blame] | 5243 | // There is a race! It fails to remove the message, which |
| 5244 | // will be handled in completeRemoveProvider(). |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5245 | mH.removeMessages(H.REMOVE_PROVIDER, prc); |
| 5246 | } else { |
| 5247 | unstableDelta = 0; |
| 5248 | } |
| 5249 | try { |
| 5250 | if (DEBUG_PROVIDER) { |
| 5251 | Slog.v(TAG, "incProviderRef Now stable - " |
| 5252 | + prc.holder.info.name + ": unstableDelta=" |
| 5253 | + unstableDelta); |
| 5254 | } |
| 5255 | ActivityManagerNative.getDefault().refContentProvider( |
| 5256 | prc.holder.connection, 1, unstableDelta); |
| 5257 | } catch (RemoteException e) { |
| 5258 | //do nothing content provider object is dead any way |
| 5259 | } |
| 5260 | } |
| 5261 | } else { |
| 5262 | prc.unstableCount += 1; |
| 5263 | if (prc.unstableCount == 1) { |
| 5264 | // We are acquiring a new unstable reference on the provider. |
| 5265 | if (prc.removePending) { |
| 5266 | // Oh look, we actually have a remove pending for the |
| 5267 | // provider, which is still holding the last unstable |
| 5268 | // reference. We just need to cancel that to take new |
| 5269 | // ownership of the reference. |
| 5270 | if (DEBUG_PROVIDER) { |
| 5271 | Slog.v(TAG, "incProviderRef: unstable " |
| 5272 | + "snatched provider from the jaws of death"); |
| 5273 | } |
| 5274 | prc.removePending = false; |
| 5275 | mH.removeMessages(H.REMOVE_PROVIDER, prc); |
| 5276 | } else { |
| 5277 | // First unstable ref, increment our count in the |
| 5278 | // activity manager. |
| 5279 | try { |
| 5280 | if (DEBUG_PROVIDER) { |
| 5281 | Slog.v(TAG, "incProviderRef: Now unstable - " |
| 5282 | + prc.holder.info.name); |
| 5283 | } |
| 5284 | ActivityManagerNative.getDefault().refContentProvider( |
| 5285 | prc.holder.connection, 0, 1); |
| 5286 | } catch (RemoteException e) { |
| 5287 | //do nothing content provider object is dead any way |
| 5288 | } |
| 5289 | } |
| 5290 | } |
| 5291 | } |
| 5292 | } |
| 5293 | |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 5294 | public final IContentProvider acquireExistingProvider( |
| 5295 | Context c, String auth, int userId, boolean stable) { |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5296 | synchronized (mProviderMap) { |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 5297 | final ProviderKey key = new ProviderKey(auth, userId); |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 5298 | final ProviderClientRecord pr = mProviderMap.get(key); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5299 | if (pr == null) { |
| 5300 | return null; |
| 5301 | } |
| 5302 | |
| 5303 | IContentProvider provider = pr.mProvider; |
| 5304 | IBinder jBinder = provider.asBinder(); |
Dianne Hackborn | c428aae | 2012-10-03 16:38:22 -0700 | [diff] [blame] | 5305 | if (!jBinder.isBinderAlive()) { |
| 5306 | // The hosting process of the provider has died; we can't |
| 5307 | // use this one. |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 5308 | Log.i(TAG, "Acquiring provider " + auth + " for user " + userId |
Dianne Hackborn | c428aae | 2012-10-03 16:38:22 -0700 | [diff] [blame] | 5309 | + ": existing object's process dead"); |
| 5310 | handleUnstableProviderDiedLocked(jBinder, true); |
| 5311 | return null; |
| 5312 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5313 | |
| 5314 | // Only increment the ref count if we have one. If we don't then the |
| 5315 | // provider is not reference counted and never needs to be released. |
Dianne Hackborn | cca1f0e | 2010-09-26 18:34:53 -0700 | [diff] [blame] | 5316 | ProviderRefCount prc = mProviderRefCountMap.get(jBinder); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5317 | if (prc != null) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5318 | incProviderRefLocked(prc, stable); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5319 | } |
| 5320 | return provider; |
| 5321 | } |
Dianne Hackborn | cca1f0e | 2010-09-26 18:34:53 -0700 | [diff] [blame] | 5322 | } |
| 5323 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5324 | public final boolean releaseProvider(IContentProvider provider, boolean stable) { |
| 5325 | if (provider == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5326 | return false; |
| 5327 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5328 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5329 | IBinder jBinder = provider.asBinder(); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5330 | synchronized (mProviderMap) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5331 | ProviderRefCount prc = mProviderRefCountMap.get(jBinder); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5332 | if (prc == null) { |
| 5333 | // 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] | 5334 | return false; |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5335 | } |
| 5336 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5337 | boolean lastRef = false; |
| 5338 | if (stable) { |
| 5339 | if (prc.stableCount == 0) { |
| 5340 | if (DEBUG_PROVIDER) Slog.v(TAG, |
| 5341 | "releaseProvider: stable ref count already 0, how?"); |
| 5342 | return false; |
| 5343 | } |
| 5344 | prc.stableCount -= 1; |
| 5345 | if (prc.stableCount == 0) { |
| 5346 | // What we do at this point depends on whether there are |
| 5347 | // any unstable refs left: if there are, we just tell the |
| 5348 | // activity manager to decrement its stable count; if there |
| 5349 | // aren't, we need to enqueue this provider to be removed, |
| 5350 | // and convert to holding a single unstable ref while |
| 5351 | // doing so. |
| 5352 | lastRef = prc.unstableCount == 0; |
| 5353 | try { |
| 5354 | if (DEBUG_PROVIDER) { |
| 5355 | Slog.v(TAG, "releaseProvider: No longer stable w/lastRef=" |
| 5356 | + lastRef + " - " + prc.holder.info.name); |
| 5357 | } |
| 5358 | ActivityManagerNative.getDefault().refContentProvider( |
| 5359 | prc.holder.connection, -1, lastRef ? 1 : 0); |
| 5360 | } catch (RemoteException e) { |
| 5361 | //do nothing content provider object is dead any way |
| 5362 | } |
| 5363 | } |
| 5364 | } else { |
| 5365 | if (prc.unstableCount == 0) { |
| 5366 | if (DEBUG_PROVIDER) Slog.v(TAG, |
| 5367 | "releaseProvider: unstable ref count already 0, how?"); |
| 5368 | return false; |
| 5369 | } |
| 5370 | prc.unstableCount -= 1; |
| 5371 | if (prc.unstableCount == 0) { |
| 5372 | // If this is the last reference, we need to enqueue |
| 5373 | // this provider to be removed instead of telling the |
| 5374 | // activity manager to remove it at this point. |
| 5375 | lastRef = prc.stableCount == 0; |
| 5376 | if (!lastRef) { |
| 5377 | try { |
| 5378 | if (DEBUG_PROVIDER) { |
| 5379 | Slog.v(TAG, "releaseProvider: No longer unstable - " |
| 5380 | + prc.holder.info.name); |
| 5381 | } |
| 5382 | ActivityManagerNative.getDefault().refContentProvider( |
| 5383 | prc.holder.connection, 0, -1); |
| 5384 | } catch (RemoteException e) { |
| 5385 | //do nothing content provider object is dead any way |
| 5386 | } |
| 5387 | } |
| 5388 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5389 | } |
| 5390 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5391 | if (lastRef) { |
| 5392 | if (!prc.removePending) { |
| 5393 | // Schedule the actual remove asynchronously, since we don't know the context |
| 5394 | // this will be called in. |
| 5395 | // TODO: it would be nice to post a delayed message, so |
| 5396 | // if we come back and need the same provider quickly |
| 5397 | // we will still have it available. |
| 5398 | if (DEBUG_PROVIDER) { |
| 5399 | Slog.v(TAG, "releaseProvider: Enqueueing pending removal - " |
| 5400 | + prc.holder.info.name); |
| 5401 | } |
| 5402 | prc.removePending = true; |
| 5403 | Message msg = mH.obtainMessage(H.REMOVE_PROVIDER, prc); |
| 5404 | mH.sendMessage(msg); |
| 5405 | } else { |
| 5406 | Slog.w(TAG, "Duplicate remove pending of provider " + prc.holder.info.name); |
| 5407 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5408 | } |
| 5409 | return true; |
| 5410 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5411 | } |
| 5412 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5413 | final void completeRemoveProvider(ProviderRefCount prc) { |
| 5414 | synchronized (mProviderMap) { |
| 5415 | if (!prc.removePending) { |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5416 | // There was a race! Some other client managed to acquire |
| 5417 | // the provider before the removal was completed. |
| 5418 | // Abort the removal. We will do it later. |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5419 | if (DEBUG_PROVIDER) Slog.v(TAG, "completeRemoveProvider: lost the race, " |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5420 | + "provider still in use"); |
| 5421 | return; |
| 5422 | } |
| 5423 | |
Guobin Zhang | 9e3e5266 | 2013-03-21 13:57:11 +0800 | [diff] [blame] | 5424 | // More complicated race!! Some client managed to acquire the |
| 5425 | // provider and release it before the removal was completed. |
| 5426 | // Continue the removal, and abort the next remove message. |
| 5427 | prc.removePending = false; |
| 5428 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5429 | final IBinder jBinder = prc.holder.provider.asBinder(); |
| 5430 | ProviderRefCount existingPrc = mProviderRefCountMap.get(jBinder); |
| 5431 | if (existingPrc == prc) { |
| 5432 | mProviderRefCountMap.remove(jBinder); |
| 5433 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5434 | |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 5435 | for (int i=mProviderMap.size()-1; i>=0; i--) { |
| 5436 | ProviderClientRecord pr = mProviderMap.valueAt(i); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5437 | IBinder myBinder = pr.mProvider.asBinder(); |
| 5438 | if (myBinder == jBinder) { |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 5439 | mProviderMap.removeAt(i); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5440 | } |
| 5441 | } |
| 5442 | } |
| 5443 | |
| 5444 | try { |
| 5445 | if (DEBUG_PROVIDER) { |
| 5446 | Slog.v(TAG, "removeProvider: Invoking ActivityManagerNative." |
| 5447 | + "removeContentProvider(" + prc.holder.info.name + ")"); |
| 5448 | } |
| 5449 | ActivityManagerNative.getDefault().removeContentProvider( |
| 5450 | prc.holder.connection, false); |
| 5451 | } catch (RemoteException e) { |
| 5452 | //do nothing content provider object is dead any way |
| 5453 | } |
| 5454 | } |
| 5455 | |
| 5456 | final void handleUnstableProviderDied(IBinder provider, boolean fromClient) { |
Dianne Hackborn | c428aae | 2012-10-03 16:38:22 -0700 | [diff] [blame] | 5457 | synchronized (mProviderMap) { |
| 5458 | handleUnstableProviderDiedLocked(provider, fromClient); |
| 5459 | } |
| 5460 | } |
| 5461 | |
| 5462 | final void handleUnstableProviderDiedLocked(IBinder provider, boolean fromClient) { |
| 5463 | ProviderRefCount prc = mProviderRefCountMap.get(provider); |
| 5464 | if (prc != null) { |
| 5465 | if (DEBUG_PROVIDER) Slog.v(TAG, "Cleaning up dead provider " |
| 5466 | + provider + " " + prc.holder.info.name); |
| 5467 | mProviderRefCountMap.remove(provider); |
You Kim | bc74de6 | 2013-10-01 00:13:26 +0900 | [diff] [blame] | 5468 | for (int i=mProviderMap.size()-1; i>=0; i--) { |
| 5469 | ProviderClientRecord pr = mProviderMap.valueAt(i); |
| 5470 | if (pr != null && pr.mProvider.asBinder() == provider) { |
| 5471 | Slog.i(TAG, "Removing dead content provider:" + pr.mProvider.toString()); |
| 5472 | mProviderMap.removeAt(i); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5473 | } |
Dianne Hackborn | c428aae | 2012-10-03 16:38:22 -0700 | [diff] [blame] | 5474 | } |
You Kim | bc74de6 | 2013-10-01 00:13:26 +0900 | [diff] [blame] | 5475 | |
Dianne Hackborn | c428aae | 2012-10-03 16:38:22 -0700 | [diff] [blame] | 5476 | if (fromClient) { |
| 5477 | // We found out about this due to execution in our client |
| 5478 | // code. Tell the activity manager about it now, to ensure |
| 5479 | // that the next time we go to do anything with the provider |
| 5480 | // it knows it is dead (so we don't race with its death |
| 5481 | // notification). |
| 5482 | try { |
| 5483 | ActivityManagerNative.getDefault().unstableProviderDied( |
| 5484 | prc.holder.connection); |
| 5485 | } catch (RemoteException e) { |
| 5486 | //do nothing content provider object is dead any way |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5487 | } |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 5488 | } |
| 5489 | } |
| 5490 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5491 | |
Jeff Sharkey | 7aa7601 | 2013-09-30 14:26:27 -0700 | [diff] [blame] | 5492 | final void appNotRespondingViaProvider(IBinder provider) { |
| 5493 | synchronized (mProviderMap) { |
| 5494 | ProviderRefCount prc = mProviderRefCountMap.get(provider); |
| 5495 | if (prc != null) { |
| 5496 | try { |
| 5497 | ActivityManagerNative.getDefault() |
| 5498 | .appNotRespondingViaProvider(prc.holder.connection); |
| 5499 | } catch (RemoteException e) { |
| 5500 | } |
| 5501 | } |
| 5502 | } |
| 5503 | } |
| 5504 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5505 | private ProviderClientRecord installProviderAuthoritiesLocked(IContentProvider provider, |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 5506 | ContentProvider localProvider, IActivityManager.ContentProviderHolder holder) { |
Andreas Gampe | 18e99c1 | 2015-03-06 15:29:06 -0800 | [diff] [blame] | 5507 | final String auths[] = holder.info.authority.split(";"); |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 5508 | final int userId = UserHandle.getUserId(holder.info.applicationInfo.uid); |
| 5509 | |
| 5510 | final ProviderClientRecord pcr = new ProviderClientRecord( |
| 5511 | auths, provider, localProvider, holder); |
| 5512 | for (String auth : auths) { |
| 5513 | final ProviderKey key = new ProviderKey(auth, userId); |
| 5514 | final ProviderClientRecord existing = mProviderMap.get(key); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5515 | if (existing != null) { |
| 5516 | Slog.w(TAG, "Content provider " + pcr.mHolder.info.name |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 5517 | + " already published as " + auth); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5518 | } else { |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 5519 | mProviderMap.put(key, pcr); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5520 | } |
| 5521 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5522 | return pcr; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5523 | } |
| 5524 | |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5525 | /** |
| 5526 | * Installs the provider. |
| 5527 | * |
| 5528 | * Providers that are local to the process or that come from the system server |
| 5529 | * may be installed permanently which is indicated by setting noReleaseNeeded to true. |
| 5530 | * Other remote providers are reference counted. The initial reference count |
| 5531 | * for all reference counted providers is one. Providers that are not reference |
| 5532 | * counted do not have a reference count (at all). |
| 5533 | * |
| 5534 | * This method detects when a provider has already been installed. When this happens, |
| 5535 | * it increments the reference count of the existing provider (if appropriate) |
| 5536 | * and returns the existing provider. This can happen due to concurrent |
| 5537 | * attempts to acquire the same provider. |
| 5538 | */ |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5539 | private IActivityManager.ContentProviderHolder installProvider(Context context, |
| 5540 | IActivityManager.ContentProviderHolder holder, ProviderInfo info, |
| 5541 | boolean noisy, boolean noReleaseNeeded, boolean stable) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5542 | ContentProvider localProvider = null; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5543 | IContentProvider provider; |
Dianne Hackborn | 5f48fca | 2012-05-30 11:06:31 -0700 | [diff] [blame] | 5544 | if (holder == null || holder.provider == null) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5545 | if (DEBUG_PROVIDER || noisy) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 5546 | Slog.d(TAG, "Loading provider " + info.authority + ": " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5547 | + info.name); |
| 5548 | } |
| 5549 | Context c = null; |
| 5550 | ApplicationInfo ai = info.applicationInfo; |
| 5551 | if (context.getPackageName().equals(ai.packageName)) { |
| 5552 | c = context; |
| 5553 | } else if (mInitialApplication != null && |
| 5554 | mInitialApplication.getPackageName().equals(ai.packageName)) { |
| 5555 | c = mInitialApplication; |
| 5556 | } else { |
| 5557 | try { |
| 5558 | c = context.createPackageContext(ai.packageName, |
| 5559 | Context.CONTEXT_INCLUDE_CODE); |
| 5560 | } catch (PackageManager.NameNotFoundException e) { |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 5561 | // Ignore |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5562 | } |
| 5563 | } |
| 5564 | if (c == null) { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 5565 | Slog.w(TAG, "Unable to get context for package " + |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5566 | ai.packageName + |
| 5567 | " while loading content provider " + |
| 5568 | info.name); |
| 5569 | return null; |
| 5570 | } |
| 5571 | try { |
| 5572 | final java.lang.ClassLoader cl = c.getClassLoader(); |
| 5573 | localProvider = (ContentProvider)cl. |
| 5574 | loadClass(info.name).newInstance(); |
| 5575 | provider = localProvider.getIContentProvider(); |
| 5576 | if (provider == null) { |
Dianne Hackborn | c9421ba | 2010-03-11 22:23:46 -0800 | [diff] [blame] | 5577 | Slog.e(TAG, "Failed to instantiate class " + |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5578 | info.name + " from sourceDir " + |
| 5579 | info.applicationInfo.sourceDir); |
| 5580 | return null; |
| 5581 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5582 | if (DEBUG_PROVIDER) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5583 | TAG, "Instantiating local provider " + info.name); |
| 5584 | // XXX Need to create the correct context for this provider. |
| 5585 | localProvider.attachInfo(c, info); |
| 5586 | } catch (java.lang.Exception e) { |
| 5587 | if (!mInstrumentation.onException(null, e)) { |
| 5588 | throw new RuntimeException( |
| 5589 | "Unable to get provider " + info.name |
| 5590 | + ": " + e.toString(), e); |
| 5591 | } |
| 5592 | return null; |
| 5593 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5594 | } else { |
| 5595 | provider = holder.provider; |
| 5596 | 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] | 5597 | + info.name); |
| 5598 | } |
| 5599 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5600 | IActivityManager.ContentProviderHolder retHolder; |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5601 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5602 | synchronized (mProviderMap) { |
| 5603 | if (DEBUG_PROVIDER) Slog.v(TAG, "Checking to add " + provider |
| 5604 | + " / " + info.name); |
| 5605 | IBinder jBinder = provider.asBinder(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5606 | if (localProvider != null) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5607 | ComponentName cname = new ComponentName(info.packageName, info.name); |
| 5608 | ProviderClientRecord pr = mLocalProvidersByName.get(cname); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5609 | if (pr != null) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5610 | if (DEBUG_PROVIDER) { |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5611 | Slog.v(TAG, "installProvider: lost the race, " |
| 5612 | + "using existing local provider"); |
| 5613 | } |
| 5614 | provider = pr.mProvider; |
| 5615 | } else { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5616 | holder = new IActivityManager.ContentProviderHolder(info); |
| 5617 | holder.provider = provider; |
| 5618 | holder.noReleaseNeeded = true; |
| 5619 | pr = installProviderAuthoritiesLocked(provider, localProvider, holder); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5620 | mLocalProviders.put(jBinder, pr); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5621 | mLocalProvidersByName.put(cname, pr); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5622 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5623 | retHolder = pr.mHolder; |
| 5624 | } else { |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5625 | ProviderRefCount prc = mProviderRefCountMap.get(jBinder); |
| 5626 | if (prc != null) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5627 | if (DEBUG_PROVIDER) { |
| 5628 | Slog.v(TAG, "installProvider: lost the race, updating ref count"); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5629 | } |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 5630 | // We need to transfer our new reference to the existing |
| 5631 | // ref count, releasing the old one... but only if |
| 5632 | // release is needed (that is, it is not running in the |
| 5633 | // system process). |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5634 | if (!noReleaseNeeded) { |
| 5635 | incProviderRefLocked(prc, stable); |
Wale Ogunwale | 1d64612 | 2015-04-24 14:45:14 -0700 | [diff] [blame] | 5636 | try { |
| 5637 | ActivityManagerNative.getDefault().removeContentProvider( |
| 5638 | holder.connection, stable); |
| 5639 | } catch (RemoteException e) { |
| 5640 | //do nothing content provider object is dead any way |
| 5641 | } |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5642 | } |
| 5643 | } else { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5644 | ProviderClientRecord client = installProviderAuthoritiesLocked( |
| 5645 | provider, localProvider, holder); |
| 5646 | if (noReleaseNeeded) { |
| 5647 | prc = new ProviderRefCount(holder, client, 1000, 1000); |
| 5648 | } else { |
| 5649 | prc = stable |
| 5650 | ? new ProviderRefCount(holder, client, 1, 0) |
| 5651 | : new ProviderRefCount(holder, client, 0, 1); |
| 5652 | } |
| 5653 | mProviderRefCountMap.put(jBinder, prc); |
Jeff Brown | ddaa9ac | 2011-11-11 20:16:14 -0800 | [diff] [blame] | 5654 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5655 | retHolder = prc.holder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5656 | } |
| 5657 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 5658 | |
| 5659 | return retHolder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5660 | } |
| 5661 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 5662 | private void attach(boolean system) { |
Jeff Sharkey | 66a017b | 2013-01-17 18:18:22 -0800 | [diff] [blame] | 5663 | sCurrentActivityThread = this; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5664 | mSystemThread = system; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5665 | if (!system) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 5666 | ViewRootImpl.addFirstDrawHandler(new Runnable() { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 5667 | @Override |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 5668 | public void run() { |
| 5669 | ensureJitEnabled(); |
| 5670 | } |
| 5671 | }); |
Siva Velusamy | d693dfa | 2012-09-10 14:36:58 -0700 | [diff] [blame] | 5672 | android.ddm.DdmHandleAppName.setAppName("<pre-initialized>", |
| 5673 | UserHandle.myUserId()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5674 | RuntimeInit.setApplicationObject(mAppThread.asBinder()); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 5675 | final IActivityManager mgr = ActivityManagerNative.getDefault(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5676 | try { |
| 5677 | mgr.attachApplication(mAppThread); |
| 5678 | } catch (RemoteException ex) { |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 5679 | // Ignore |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5680 | } |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 5681 | // Watch for getting close to heap limit. |
| 5682 | BinderInternal.addGcWatcher(new Runnable() { |
| 5683 | @Override public void run() { |
| 5684 | if (!mSomeActivitiesChanged) { |
| 5685 | return; |
| 5686 | } |
| 5687 | Runtime runtime = Runtime.getRuntime(); |
| 5688 | long dalvikMax = runtime.maxMemory(); |
| 5689 | long dalvikUsed = runtime.totalMemory() - runtime.freeMemory(); |
| 5690 | if (dalvikUsed > ((3*dalvikMax)/4)) { |
| 5691 | if (DEBUG_MEMORY_TRIM) Slog.d(TAG, "Dalvik max=" + (dalvikMax/1024) |
| 5692 | + " total=" + (runtime.totalMemory()/1024) |
| 5693 | + " used=" + (dalvikUsed/1024)); |
| 5694 | mSomeActivitiesChanged = false; |
| 5695 | try { |
| 5696 | mgr.releaseSomeActivities(mAppThread); |
| 5697 | } catch (RemoteException e) { |
| 5698 | } |
| 5699 | } |
| 5700 | } |
| 5701 | }); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5702 | } else { |
| 5703 | // Don't set application object here -- if the system crashes, |
| 5704 | // 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] | 5705 | android.ddm.DdmHandleAppName.setAppName("system_process", |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 5706 | UserHandle.myUserId()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5707 | try { |
| 5708 | mInstrumentation = new Instrumentation(); |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 5709 | ContextImpl context = ContextImpl.createAppContext( |
| 5710 | this, getSystemContext().mPackageInfo); |
Jeff Brown | 7fc8e35 | 2014-09-16 18:06:47 -0700 | [diff] [blame] | 5711 | mInitialApplication = context.mPackageInfo.makeApplication(true, null); |
| 5712 | mInitialApplication.onCreate(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5713 | } catch (Exception e) { |
| 5714 | throw new RuntimeException( |
| 5715 | "Unable to instantiate Application():" + e.toString(), e); |
| 5716 | } |
| 5717 | } |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 5718 | |
| 5719 | // add dropbox logging to libcore |
| 5720 | DropBox.setReporter(new DropBoxReporter()); |
| 5721 | |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 5722 | ViewRootImpl.addConfigCallback(new ComponentCallbacks2() { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 5723 | @Override |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5724 | public void onConfigurationChanged(Configuration newConfig) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 5725 | synchronized (mResourcesManager) { |
Dianne Hackborn | ae07816 | 2010-03-18 11:29:37 -0700 | [diff] [blame] | 5726 | // We need to apply this change to the resources |
| 5727 | // immediately, because upon returning the view |
| 5728 | // hierarchy will be informed about it. |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 5729 | if (mResourcesManager.applyConfigurationToResourcesLocked(newConfig, null)) { |
Dianne Hackborn | ae07816 | 2010-03-18 11:29:37 -0700 | [diff] [blame] | 5730 | // This actually changed the resources! Tell |
| 5731 | // everyone about it. |
| 5732 | if (mPendingConfiguration == null || |
| 5733 | mPendingConfiguration.isOtherSeqNewer(newConfig)) { |
| 5734 | mPendingConfiguration = newConfig; |
Tim Murray | e1e6c66 | 2015-04-07 13:24:14 -0700 | [diff] [blame] | 5735 | |
Jeff Brown | 9ef0997 | 2013-10-15 20:49:59 -0700 | [diff] [blame] | 5736 | sendMessage(H.CONFIGURATION_CHANGED, newConfig); |
Dianne Hackborn | ae07816 | 2010-03-18 11:29:37 -0700 | [diff] [blame] | 5737 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5738 | } |
| 5739 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5740 | } |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 5741 | @Override |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5742 | public void onLowMemory() { |
| 5743 | } |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 5744 | @Override |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 5745 | public void onTrimMemory(int level) { |
| 5746 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5747 | }); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5748 | } |
| 5749 | |
Romain Guy | 5e9120d | 2012-01-30 12:17:22 -0800 | [diff] [blame] | 5750 | public static ActivityThread systemMain() { |
Alan Viverette | 5e1565e | 2014-07-29 16:14:25 -0700 | [diff] [blame] | 5751 | // The system process on low-memory devices do not get to use hardware |
| 5752 | // accelerated drawing, since this can add too much overhead to the |
| 5753 | // process. |
| 5754 | if (!ActivityManager.isHighEndGfx()) { |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 5755 | ThreadedRenderer.disable(true); |
John Reck | 73840ea | 2014-09-22 07:39:18 -0700 | [diff] [blame] | 5756 | } else { |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 5757 | ThreadedRenderer.enableForegroundTrimming(); |
Alan Viverette | 5e1565e | 2014-07-29 16:14:25 -0700 | [diff] [blame] | 5758 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5759 | ActivityThread thread = new ActivityThread(); |
| 5760 | thread.attach(true); |
| 5761 | return thread; |
| 5762 | } |
| 5763 | |
Jeff Brown | 10e8971 | 2011-07-08 18:52:57 -0700 | [diff] [blame] | 5764 | public final void installSystemProviders(List<ProviderInfo> providers) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5765 | if (providers != null) { |
Jeff Brown | 10e8971 | 2011-07-08 18:52:57 -0700 | [diff] [blame] | 5766 | installContentProviders(mInitialApplication, providers); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5767 | } |
| 5768 | } |
| 5769 | |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 5770 | public int getIntCoreSetting(String key, int defaultValue) { |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 5771 | synchronized (mResourcesManager) { |
Svetoslav Ganov | 9aa597e | 2011-03-03 18:17:41 -0800 | [diff] [blame] | 5772 | if (mCoreSettings != null) { |
| 5773 | return mCoreSettings.getInt(key, defaultValue); |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 5774 | } |
Craig Mautner | 88c0589 | 2013-06-28 09:47:45 -0700 | [diff] [blame] | 5775 | return defaultValue; |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 5776 | } |
| 5777 | } |
| 5778 | |
Geremy Condra | 69689a7 | 2012-09-11 16:57:17 -0700 | [diff] [blame] | 5779 | private static class EventLoggingReporter implements EventLogger.Reporter { |
| 5780 | @Override |
| 5781 | public void report (int code, Object... list) { |
| 5782 | EventLog.writeEvent(code, list); |
| 5783 | } |
| 5784 | } |
| 5785 | |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 5786 | private class DropBoxReporter implements DropBox.Reporter { |
| 5787 | |
| 5788 | private DropBoxManager dropBox; |
| 5789 | |
Narayan Kamath | 7f06224 | 2015-04-08 13:24:13 +0100 | [diff] [blame] | 5790 | public DropBoxReporter() {} |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 5791 | |
| 5792 | @Override |
| 5793 | public void addData(String tag, byte[] data, int flags) { |
Narayan Kamath | 7f06224 | 2015-04-08 13:24:13 +0100 | [diff] [blame] | 5794 | ensureInitialized(); |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 5795 | dropBox.addData(tag, data, flags); |
| 5796 | } |
| 5797 | |
| 5798 | @Override |
| 5799 | public void addText(String tag, String data) { |
Narayan Kamath | 7f06224 | 2015-04-08 13:24:13 +0100 | [diff] [blame] | 5800 | ensureInitialized(); |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 5801 | dropBox.addText(tag, data); |
| 5802 | } |
Narayan Kamath | 7f06224 | 2015-04-08 13:24:13 +0100 | [diff] [blame] | 5803 | |
| 5804 | private synchronized void ensureInitialized() { |
| 5805 | if (dropBox == null) { |
| 5806 | dropBox = (DropBoxManager) getSystemContext().getSystemService(Context.DROPBOX_SERVICE); |
| 5807 | } |
| 5808 | } |
Geremy Condra | b7faaf4 | 2012-09-19 18:07:42 -0700 | [diff] [blame] | 5809 | } |
| 5810 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 5811 | public static void main(String[] args) { |
Narayan Kamath | fbb32f6 | 2015-06-12 15:34:35 +0100 | [diff] [blame] | 5812 | Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "ActivityThreadMain"); |
Bob Lee | e540833 | 2009-09-04 18:31:17 -0700 | [diff] [blame] | 5813 | SamplingProfilerIntegration.start(); |
| 5814 | |
Brad Fitzpatrick | 4d9e6d2 | 2010-11-15 08:49:51 -0800 | [diff] [blame] | 5815 | // CloseGuard defaults to true and can be quite spammy. We |
| 5816 | // disable it here, but selectively enable it later (via |
| 5817 | // StrictMode) on debug builds, but using DropBox, not logs. |
| 5818 | CloseGuard.setEnabled(false); |
| 5819 | |
Jeff Sharkey | b049e21 | 2012-09-07 23:16:01 -0700 | [diff] [blame] | 5820 | Environment.initForCurrentUser(); |
| 5821 | |
Geremy Condra | 69689a7 | 2012-09-11 16:57:17 -0700 | [diff] [blame] | 5822 | // Set the reporter for event logging in libcore |
| 5823 | EventLogger.setReporter(new EventLoggingReporter()); |
| 5824 | |
Alex Klyubin | 4812563 | 2015-04-29 13:16:30 -0700 | [diff] [blame] | 5825 | AndroidKeyStoreProvider.install(); |
Kenny Root | 8b51475 | 2013-02-04 09:35:16 -0800 | [diff] [blame] | 5826 | |
Robin Lee | 3d076af | 2014-04-25 14:57:49 +0100 | [diff] [blame] | 5827 | // Make sure TrustedCertificateStore looks in the right place for CA certificates |
| 5828 | final File configDir = Environment.getUserConfigDirectory(UserHandle.myUserId()); |
| 5829 | TrustedCertificateStore.setDefaultUserDirectory(configDir); |
| 5830 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5831 | Process.setArgV0("<pre-initialized>"); |
| 5832 | |
| 5833 | Looper.prepareMainLooper(); |
| 5834 | |
| 5835 | ActivityThread thread = new ActivityThread(); |
| 5836 | thread.attach(false); |
| 5837 | |
Vairavan Srinivasan | 7335cfd | 2012-08-18 18:36:03 -0700 | [diff] [blame] | 5838 | if (sMainThreadHandler == null) { |
| 5839 | sMainThreadHandler = thread.getHandler(); |
| 5840 | } |
| 5841 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 5842 | if (false) { |
| 5843 | Looper.myLooper().setMessageLogging(new |
| 5844 | LogPrinter(Log.DEBUG, "ActivityThread")); |
| 5845 | } |
| 5846 | |
Narayan Kamath | fbb32f6 | 2015-06-12 15:34:35 +0100 | [diff] [blame] | 5847 | // End of event ActivityThreadMain. |
| 5848 | Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5849 | Looper.loop(); |
| 5850 | |
Jeff Brown | 10e8971 | 2011-07-08 18:52:57 -0700 | [diff] [blame] | 5851 | throw new RuntimeException("Main thread loop unexpectedly exited"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5852 | } |
| 5853 | } |