|
65 | 65 | import android.os.ServiceManager; |
66 | 66 | import android.os.StrictMode; |
67 | 67 | import android.os.SystemClock; |
| 68 | +import android.os.SystemProperties; |
68 | 69 | import android.os.Trace; |
69 | 70 | import android.os.UserHandle; |
70 | 71 | import android.util.AndroidRuntimeException; |
@@ -2089,9 +2090,7 @@ private Activity performLaunchActivity(ActivityClientRecord r, Intent customInte |
2089 | 2090 | + ", dir=" + r.packageInfo.getAppDir()); |
2090 | 2091 |
|
2091 | 2092 | if (activity != null) { |
2092 | | - ContextImpl appContext = new ContextImpl(); |
2093 | | - appContext.init(r.packageInfo, r.token, this); |
2094 | | - appContext.setOuterContext(activity); |
| 2093 | + Context appContext = createBaseContextForActivity(r, activity); |
2095 | 2094 | CharSequence title = r.activityInfo.loadLabel(appContext.getPackageManager()); |
2096 | 2095 | Configuration config = new Configuration(mCompatConfiguration); |
2097 | 2096 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Launching activity " |
@@ -2156,6 +2155,31 @@ private Activity performLaunchActivity(ActivityClientRecord r, Intent customInte |
2156 | 2155 | return activity; |
2157 | 2156 | } |
2158 | 2157 |
|
| 2158 | + private Context createBaseContextForActivity(ActivityClientRecord r, |
| 2159 | + final Activity activity) { |
| 2160 | + ContextImpl appContext = new ContextImpl(); |
| 2161 | + appContext.init(r.packageInfo, r.token, this); |
| 2162 | + appContext.setOuterContext(activity); |
| 2163 | + |
| 2164 | + // For debugging purposes, if the activity's package name contains the value of |
| 2165 | + // the "debug.use-second-display" system property as a substring, then show |
| 2166 | + // its content on a secondary display if there is one. |
| 2167 | + Context baseContext = appContext; |
| 2168 | + String pkgName = SystemProperties.get("debug.second-display.pkg"); |
| 2169 | + if (pkgName != null && !pkgName.isEmpty() |
| 2170 | + && r.packageInfo.mPackageName.contains(pkgName)) { |
| 2171 | + DisplayManagerGlobal dm = DisplayManagerGlobal.getInstance(); |
| 2172 | + for (int displayId : dm.getDisplayIds()) { |
| 2173 | + if (displayId != Display.DEFAULT_DISPLAY) { |
| 2174 | + Display display = dm.getRealDisplay(displayId); |
| 2175 | + baseContext = appContext.createDisplayContext(display); |
| 2176 | + break; |
| 2177 | + } |
| 2178 | + } |
| 2179 | + } |
| 2180 | + return baseContext; |
| 2181 | + } |
| 2182 | + |
2159 | 2183 | private void handleLaunchActivity(ActivityClientRecord r, Intent customIntent) { |
2160 | 2184 | // If we are getting ready to gc after going to the background, well |
2161 | 2185 | // we are back active so skip it. |
|
0 commit comments