diff options
author | Charles Chen <charlesccchen@google.com> | 2023-06-06 14:37:08 +0800 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-09-15 21:17:37 +0000 |
commit | 4770073be337349eb81f28b17f59eab0ddfed6dc (patch) | |
tree | c3672a5ad5951f234fc6248d39bb5eb466c39b06 | |
parent | b091aa67982efe8386f2cc257e2edee5f3efb048 (diff) | |
download | base-4770073be337349eb81f28b17f59eab0ddfed6dc.tar.gz |
Fallback to default display if initial one is detached
Test: atest WindowContextTests
Fixes: 285630617
(cherry picked from commit 7d860098f5c585c96ce29b199b36f7c82b938249)
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:01bd9ec4ceb5da65235d0840c723d9b422168850)
Merged-In: I196bab294c182230edda54241f7b725f44f05570
Change-Id: I196bab294c182230edda54241f7b725f44f05570
-rw-r--r-- | core/java/android/window/WindowProviderService.java | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/core/java/android/window/WindowProviderService.java b/core/java/android/window/WindowProviderService.java index f2ae973500af..611da3cec5c6 100644 --- a/core/java/android/window/WindowProviderService.java +++ b/core/java/android/window/WindowProviderService.java @@ -34,6 +34,7 @@ import android.content.res.Configuration; import android.hardware.display.DisplayManager; import android.os.Bundle; import android.os.IBinder; +import android.util.Log; import android.view.Display; import android.view.WindowManager; import android.view.WindowManager.LayoutParams.WindowType; @@ -52,6 +53,8 @@ import android.view.WindowManagerImpl; @UiContext public abstract class WindowProviderService extends Service implements WindowProvider { + private static final String TAG = WindowProviderService.class.getSimpleName(); + private final Bundle mOptions; private final WindowTokenClient mWindowToken = new WindowTokenClient(); private final WindowContextController mController = new WindowContextController(mWindowToken); @@ -194,8 +197,16 @@ public abstract class WindowProviderService extends Service implements WindowPro public final Context createServiceBaseContext(ActivityThread mainThread, LoadedApk packageInfo) { final Context context = super.createServiceBaseContext(mainThread, packageInfo); - final Display display = context.getSystemService(DisplayManager.class) - .getDisplay(getInitialDisplayId()); + final DisplayManager displayManager = context.getSystemService(DisplayManager.class); + final int initialDisplayId = getInitialDisplayId(); + Display display = displayManager.getDisplay(initialDisplayId); + // Fallback to use the default display if the initial display to start WindowProviderService + // is detached. + if (display == null) { + Log.e(TAG, "Display with id " + initialDisplayId + " not found, falling back to " + + "DEFAULT_DISPLAY"); + display = displayManager.getDisplay(DEFAULT_DISPLAY); + } return context.createTokenContext(mWindowToken, display); } |