Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bb754aee authored by Oleg Blinnikov's avatar Oleg Blinnikov
Browse files

Connected display hotplug error notification

Show notification for connected display error.

Test: atest DisplayNotificationManagerTest DisplayManagerServiceTest LocalDisplayAdapterTest
Change-Id: Ib58f5f3811b4bd5b1c4092c9826bac749beace06
Bug: 283461472
parent c00a4c0a
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
<!--
Copyright (C) 2023 The Android Open Source Project

   Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

         http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="24dp"
        android:height="24dp"
        android:viewportWidth="20"
        android:viewportHeight="20">
    <path
        android:pathData="M15.333,5.333V4.667C15.333,4.3 15.033,4 14.667,4L13.333,4C12.967,4 12.667,4.3 12.667,4.667V5.333H12V8C12,8.367 12.3,8.667 12.667,8.667H13.333L13.333,13.333C13.333,14.067 12.733,14.667 12,14.667C11.267,14.667 10.667,14.067 10.667,13.333L10.667,11.333V6.667C10.667,5.193 9.473,4 8,4C6.527,4 5.333,5.193 5.333,6.667L5.333,11.333H4.667C4.3,11.333 4,11.633 4,12L4,14.667H4.667V15.333C4.667,15.7 4.967,16 5.333,16H6.667C7.033,16 7.333,15.7 7.333,15.333V14.667H8L8,12C8,11.633 7.7,11.333 7.333,11.333H6.667L6.667,6.667C6.667,5.933 7.267,5.333 8,5.333C8.733,5.333 9.333,5.933 9.333,6.667V11.333L9.333,13.333C9.333,14.807 10.527,16 12,16C13.473,16 14.667,14.807 14.667,13.333L14.667,8.667H15.333C15.7,8.667 16,8.367 16,8V5.333H15.333Z"
        android:fillColor="#FFFFFFFF"
        android:fillType="evenOdd"/>
</vector>

+8 −0
Original line number Diff line number Diff line
@@ -826,6 +826,9 @@
         security policy. [CHAR_LIMIT=NONE]-->
    <string name="notification_channel_accessibility_security_policy">Accessibility usage</string>

    <!-- Text shown when viewing channel settings for notifications related to displays -->
    <string name="notification_channel_display">Display</string>

    <!-- Label for foreground service notification when one app is running.
    [CHAR LIMIT=NONE BACKUP_MESSAGE_ID=6826789589341671842] -->
    <string name="foreground_service_app_in_background"><xliff:g id="app_name">%1$s</xliff:g> is
@@ -6290,6 +6293,11 @@ ul.</string>
    <!-- Toast message that is shown when the user mutes the microphone from the keyboard. [CHAR LIMIT=TOAST] -->
    <string name="mic_access_off_toast">Microphone is blocked</string>

    <!-- Title of connected display unavailable notifications. [CHAR LIMIT=NONE] -->
    <string name="connected_display_unavailable_notification_title">Can\'t mirror to display</string>
    <!-- Content of connected display unavailable notification. [CHAR LIMIT=NONE] -->
    <string name="connected_display_unavailable_notification_content">Use a different cable and try again</string>

    <!-- Name of concurrent display notifications. [CHAR LIMIT=NONE] -->
    <string name="concurrent_display_notification_name">Dual screen</string>
    <!-- Title of concurrent display active notification. [CHAR LIMIT=NONE] -->
+4 −0
Original line number Diff line number Diff line
@@ -1997,6 +1997,7 @@
  <java-symbol type="drawable" name="stat_sys_throttled" />
  <java-symbol type="drawable" name="vpn_connected" />
  <java-symbol type="drawable" name="vpn_disconnected" />
  <java-symbol type="drawable" name="usb_cable_unknown_issue" />
  <java-symbol type="id" name="ask_checkbox" />
  <java-symbol type="id" name="compat_checkbox" />
  <java-symbol type="id" name="original_app_icon" />
@@ -3811,6 +3812,7 @@
  <java-symbol type="string" name="notification_channel_do_not_disturb" />
  <java-symbol type="string" name="notification_channel_accessibility_magnification" />
  <java-symbol type="string" name="notification_channel_accessibility_security_policy" />
  <java-symbol type="string" name="notification_channel_display" />
  <java-symbol type="string" name="config_defaultAutofillService" />
  <java-symbol type="string" name="config_defaultFieldClassificationService" />
  <java-symbol type="string" name="config_defaultOnDeviceSpeechRecognitionService" />
@@ -5064,6 +5066,8 @@
  <java-symbol type="array" name="device_state_notification_thermal_contents"/>
  <java-symbol type="array" name="device_state_notification_power_save_titles"/>
  <java-symbol type="array" name="device_state_notification_power_save_contents"/>
  <java-symbol type="string" name="connected_display_unavailable_notification_title"/>
  <java-symbol type="string" name="connected_display_unavailable_notification_content"/>
  <java-symbol type="string" name="concurrent_display_notification_name"/>
  <java-symbol type="string" name="concurrent_display_notification_active_title"/>
  <java-symbol type="string" name="concurrent_display_notification_active_content"/>
+14 −3
Original line number Diff line number Diff line
@@ -160,6 +160,7 @@ import com.android.server.display.feature.DeviceConfigParameterProvider;
import com.android.server.display.feature.DisplayManagerFlags;
import com.android.server.display.layout.Layout;
import com.android.server.display.mode.DisplayModeDirector;
import com.android.server.display.notifications.DisplayNotificationManager;
import com.android.server.display.utils.SensorUtils;
import com.android.server.input.InputManagerInternal;
import com.android.server.utils.FoldSettingProvider;
@@ -522,6 +523,8 @@ public final class DisplayManagerService extends SystemService {

    private final DisplayManagerFlags mFlags;

    private final DisplayNotificationManager mDisplayNotificationManager;

    /**
     * Applications use {@link android.view.Display#getRefreshRate} and
     * {@link android.view.Display.Mode#getRefreshRate} to know what is the display refresh rate.
@@ -555,6 +558,7 @@ public final class DisplayManagerService extends SystemService {
        mInjector = injector;
        mContext = context;
        mFlags = injector.getFlags();
        mDisplayNotificationManager = new DisplayNotificationManager(mFlags, mContext);
        mHandler = new DisplayManagerHandler(DisplayThread.get().getLooper());
        mUiHandler = UiThread.getHandler();
        mDisplayDeviceRepo = new DisplayDeviceRepository(mSyncRoot, mPersistentDataStore);
@@ -650,6 +654,7 @@ public final class DisplayManagerService extends SystemService {
            }
            mDisplayModeDirector.onBootCompleted();
            mLogicalDisplayMapper.onBootCompleted();
            mDisplayNotificationManager.onBootCompleted();
        }
    }

@@ -784,6 +789,10 @@ public final class DisplayManagerService extends SystemService {
        }
    }

    DisplayNotificationManager getDisplayNotificationManager() {
        return mDisplayNotificationManager;
    }

    private void loadStableDisplayValuesLocked() {
        final Point size = mPersistentDataStore.getStableDisplaySize();
        if (size.x > 0 && size.y > 0) {
@@ -1776,7 +1785,8 @@ public final class DisplayManagerService extends SystemService {
        synchronized (mSyncRoot) {
            // main display adapter
            registerDisplayAdapterLocked(mInjector.getLocalDisplayAdapter(mSyncRoot, mContext,
                    mHandler, mDisplayDeviceRepo, mFlags));
                    mHandler, mDisplayDeviceRepo, mFlags,
                    mDisplayNotificationManager));

            // Standalone VR devices rely on a virtual display as their primary display for
            // 2D UI. We register virtual display adapter along side the main display adapter
@@ -3191,9 +3201,10 @@ public final class DisplayManagerService extends SystemService {

        LocalDisplayAdapter getLocalDisplayAdapter(SyncRoot syncRoot, Context context,
                Handler handler, DisplayAdapter.Listener displayAdapterListener,
                DisplayManagerFlags flags) {
                DisplayManagerFlags flags,
                DisplayNotificationManager displayNotificationManager) {
            return new LocalDisplayAdapter(syncRoot, context, handler, displayAdapterListener,
                    flags);
                    flags, displayNotificationManager);
        }

        long getDefaultDisplayDelayTimeout() {
+36 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import java.util.Arrays;

class DisplayManagerShellCommand extends ShellCommand {
    private static final String TAG = "DisplayManagerShellCommand";
    private static final String NOTIFICATION_TYPES = "on-hotplug-error";

    private final DisplayManagerService mService;
    private final DisplayManagerFlags mFlags;
@@ -46,6 +47,10 @@ class DisplayManagerShellCommand extends ShellCommand {
        }
        final PrintWriter pw = getOutPrintWriter();
        switch(cmd) {
            case "show-notification":
                return showNotification();
            case "cancel-notifications":
                return cancelNotifications();
            case "set-brightness":
                return setBrightness();
            case "reset-brightness-configuration":
@@ -102,6 +107,10 @@ class DisplayManagerShellCommand extends ShellCommand {
        pw.println("  help");
        pw.println("    Print this help text.");
        pw.println();
        pw.println("  show-notification NOTIFICATION_TYPE");
        pw.println("    Show notification for one of the following types: " + NOTIFICATION_TYPES);
        pw.println("  cancel-notifications");
        pw.println("    Cancel notifications.");
        pw.println("  set-brightness BRIGHTNESS");
        pw.println("    Sets the current brightness to BRIGHTNESS (a number between 0 and 1).");
        pw.println("  reset-brightness-configuration");
@@ -172,6 +181,33 @@ class DisplayManagerShellCommand extends ShellCommand {
        return 0;
    }

    private int showNotification() {
        final String notificationType = getNextArg();
        if (notificationType == null) {
            getErrPrintWriter().println("Error: no notificationType specified, use one of: "
                                                + NOTIFICATION_TYPES);
            return 1;
        }

        switch(notificationType) {
            case "on-hotplug-error":
                mService.getDisplayNotificationManager().onHotplugConnectionError();
                break;
            default:
                getErrPrintWriter().println(
                        "Error: unexpected notification type=" + notificationType + ", use one of: "
                                + NOTIFICATION_TYPES);
                return 1;
        }

        return 0;
    }

    private int cancelNotifications() {
        mService.getDisplayNotificationManager().cancelNotifications();
        return 0;
    }

    private int setBrightness() {
        String brightnessText = getNextArg();
        if (brightnessText == null) {
Loading