lineage_patches_unified/patches_wephone/frameworks_base/0001-add-presentation-on-external-display.patch

154 lines
6.3 KiB
Diff

From 8765b97c6f66d449a4cee746abf015553877a153 Mon Sep 17 00:00:00 2001
From: Nehemiah of Zebulun <nehemiah-zb@mezimmah.net>
Date: Wed, 24 Jan 2024 15:25:52 -0500
Subject: [PATCH] add presentation on external display
Change-Id: I83ecae9888cec97a806bda9b5f9580724455d8cd
---
.../keyguard/KeyguardDisplayManager.java | 24 ------
.../com/android/systemui/SystemUIService.java | 81 +++++++++++++++++++
2 files changed, 81 insertions(+), 24 deletions(-)
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardDisplayManager.java b/packages/SystemUI/src/com/android/keyguard/KeyguardDisplayManager.java
index d6fabd63420..26d08af339c 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardDisplayManager.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardDisplayManager.java
@@ -121,30 +121,6 @@ public class KeyguardDisplayManager {
* was already there.
*/
private boolean showPresentation(Display display) {
- if (!isKeyguardShowable(display)) return false;
- if (DEBUG) Log.i(TAG, "Keyguard enabled on display: " + display);
- final int displayId = display.getDisplayId();
- Presentation presentation = mPresentations.get(displayId);
- if (presentation == null) {
- final Presentation newPresentation = new KeyguardPresentation(mContext, display,
- mInjectableInflater.injectable(LayoutInflater.from(mContext)));
- newPresentation.setOnDismissListener(dialog -> {
- if (newPresentation.equals(mPresentations.get(displayId))) {
- mPresentations.remove(displayId);
- }
- });
- presentation = newPresentation;
- try {
- presentation.show();
- } catch (WindowManager.InvalidDisplayException ex) {
- Log.w(TAG, "Invalid display:", ex);
- presentation = null;
- }
- if (presentation != null) {
- mPresentations.append(displayId, presentation);
- return true;
- }
- }
return false;
}
diff --git a/packages/SystemUI/src/com/android/systemui/SystemUIService.java b/packages/SystemUI/src/com/android/systemui/SystemUIService.java
index c56bab290ce..36fbf91189b 100644
--- a/packages/SystemUI/src/com/android/systemui/SystemUIService.java
+++ b/packages/SystemUI/src/com/android/systemui/SystemUIService.java
@@ -39,6 +39,20 @@ import java.io.PrintWriter;
import javax.inject.Inject;
+import android.widget.LinearLayout;
+import android.widget.LinearLayout.LayoutParams;
+import android.widget.TextClock;
+import android.util.TypedValue;
+import android.util.Log;
+import android.os.Bundle;
+import android.content.Context;
+import android.app.Presentation;
+import android.view.Display;
+import android.graphics.Color;
+import android.view.View;
+import android.view.Window;
+import android.media.MediaRouter;
+
public class SystemUIService extends Service {
private final Handler mMainHandler;
@@ -101,6 +115,18 @@ public class SystemUIService extends Service {
startServiceAsUser(
new Intent(getApplicationContext(), SystemUIAuxiliaryDumpService.class),
UserHandle.SYSTEM);
+ try {
+ MediaRouter mediaRouter = (MediaRouter) getSystemService(Context.MEDIA_ROUTER_SERVICE);
+ MediaRouter.RouteInfo selectedRoute = mediaRouter.getSelectedRoute(1);
+ Display presentationDisplay = selectedRoute != null ? selectedRoute.getPresentationDisplay() : null;
+ PresentationScreen mPresentation = new PresentationScreen(this, presentationDisplay);
+ Log.i("SystemUIService", "Showing presentation on display: " + presentationDisplay);
+ mPresentation.requestWindowFeature(Window.FEATURE_NO_TITLE);
+ mPresentation.show();
+ Log.i("SystemUIService", "Showing presentation.");
+ } catch (Exception e) {
+ Log.w("SystemUIService", "Couldn't show presentation! Display was removed in the meantime.", e);
+ }
}
@Override
@@ -122,4 +148,59 @@ public class SystemUIService extends Service {
mDumpHandler.dump(fd, pw, massagedArgs);
}
+
+ static final class PresentationScreen extends Presentation {
+ private Context mOuterContext;
+
+ PresentationScreen(Context context, Display display) {
+ super(context, display, R.style.Theme_SystemUI_KeyguardPresentation);
+ setCancelable(false);
+ mOuterContext = context;
+ }
+
+ @Override
+ public void cancel() {
+ // Do not allow anything to cancel KeyguardPresetation except KeyguardDisplayManager.
+ }
+
+ @Override
+ public void onDetachedFromWindow() {
+ }
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ LinearLayout mLayout = new LinearLayout(mOuterContext);
+ mLayout.setLayoutParams(new LayoutParams(96, 96));
+ mLayout.setOrientation(LinearLayout.VERTICAL);
+ mLayout.setBackgroundColor(Color.BLACK);
+
+ LayoutParams mClockParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
+
+ TextClock mEmptyClock = new TextClock(mOuterContext);
+ mEmptyClock.setLayoutParams(mClockParams);
+ mEmptyClock.setTextSize(TypedValue.COMPLEX_UNIT_SP, 10);
+ mEmptyClock.setVisibility(View.INVISIBLE);
+ mLayout.addView(mEmptyClock);
+
+ TextClock mTextClock = new TextClock(mOuterContext);
+ mTextClock.setLayoutParams(mClockParams);
+ mTextClock.setFormat12Hour("hh:mm");
+ mTextClock.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
+ mTextClock.setTextColor(Color.WHITE);
+ mTextClock.setTextSize(TypedValue.COMPLEX_UNIT_SP, 22);
+ mLayout.addView(mTextClock);
+
+ TextClock mDateClock = new TextClock(mOuterContext);
+ mDateClock.setLayoutParams(mClockParams);
+ mDateClock.setFormat12Hour("EEE, MMMM dd");
+ mDateClock.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
+ mDateClock.setTextColor(Color.WHITE);
+ mDateClock.setTextSize(TypedValue.COMPLEX_UNIT_SP, 10);
+ mLayout.addView(mDateClock);
+
+ setContentView(mLayout);
+ }
+ }
}
--
2.39.2