Skip to content

Commit efd43bd

Browse files
author
Jeff Brown
committed
Force activities to run on the second display for testing.
This is a simple hack for testing and development purposes. It makes the framework place the main window of an activity on to a secondary display instead of on the default display. Set the "debug.second-display.pkg" to a substring of the package name of the activity that you want to have show up on the secondary display, such as "com.example.android.apis" Bug: 7183618 Change-Id: I0a9e7f27c8ff253253b9de57d4bc49f31d95a0e2
1 parent e87bf03 commit efd43bd

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

core/java/android/app/ActivityThread.java

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
import android.os.ServiceManager;
6666
import android.os.StrictMode;
6767
import android.os.SystemClock;
68+
import android.os.SystemProperties;
6869
import android.os.Trace;
6970
import android.os.UserHandle;
7071
import android.util.AndroidRuntimeException;
@@ -2089,9 +2090,7 @@ private Activity performLaunchActivity(ActivityClientRecord r, Intent customInte
20892090
+ ", dir=" + r.packageInfo.getAppDir());
20902091

20912092
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);
20952094
CharSequence title = r.activityInfo.loadLabel(appContext.getPackageManager());
20962095
Configuration config = new Configuration(mCompatConfiguration);
20972096
if (DEBUG_CONFIGURATION) Slog.v(TAG, "Launching activity "
@@ -2156,6 +2155,31 @@ private Activity performLaunchActivity(ActivityClientRecord r, Intent customInte
21562155
return activity;
21572156
}
21582157

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+
21592183
private void handleLaunchActivity(ActivityClientRecord r, Intent customIntent) {
21602184
// If we are getting ready to gc after going to the background, well
21612185
// we are back active so skip it.

0 commit comments

Comments
 (0)