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

Commit f9ba65ac authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Switch display control betw. Android and Sidekick"

parents dceb42a1 bc839a39
Loading
Loading
Loading
Loading
+56 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2017 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.
 */

package android.hardware.sidekick;


/**
 * Sidekick local system service interface.
 *
 * @hide Only for use within the system server, and maybe by Clockwork Home.
 */
public abstract class SidekickInternal {

    /**
     * Tell Sidekick to reset back to newly-powered-on state.
     *
     * @return true on success (Sidekick is reset), false if Sidekick is not
     * available (failed or not present). Either way, upon return Sidekick is
     * guaranteed not to be controlling the display.
     */
    public abstract boolean reset();

    /**
     * Tell Sidekick it can start controlling the display.
     *
     * SidekickServer may choose not to actually control the display, if it's been told
     * via other channels to leave the previous image on the display (same as SUSPEND in
     * a non-Sidekick system).
     *
     * @param displayState - one of Display.STATE_DOZE_SUSPEND, Display.STATE_ON_SUSPEND
     * @return true on success, false on failure (no sidekick available)
     */
    public abstract boolean startDisplayControl(int displayState);

    /**
     * Tell Sidekick it must stop controlling the display.
     *
     * No return code because this must always succeed - after return, Sidekick
     * is guaranteed to not be controlling the display.
     */
    public abstract void endDisplayControl();

}
+29 −2
Original line number Original line Diff line number Diff line
@@ -22,6 +22,7 @@ import com.android.server.lights.Light;
import com.android.server.lights.LightsManager;
import com.android.server.lights.LightsManager;


import android.content.Context;
import android.content.Context;
import android.hardware.sidekick.SidekickInternal;
import android.os.Build;
import android.os.Build;
import android.os.Handler;
import android.os.Handler;
import android.os.IBinder;
import android.os.IBinder;
@@ -35,7 +36,6 @@ import android.view.Display;
import android.view.DisplayEventReceiver;
import android.view.DisplayEventReceiver;
import android.view.Surface;
import android.view.Surface;
import android.view.SurfaceControl;
import android.view.SurfaceControl;

import java.io.PrintWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Arrays;
@@ -170,6 +170,8 @@ final class LocalDisplayAdapter extends DisplayAdapter {
        private int mActiveColorMode;
        private int mActiveColorMode;
        private boolean mActiveColorModeInvalid;
        private boolean mActiveColorModeInvalid;
        private Display.HdrCapabilities mHdrCapabilities;
        private Display.HdrCapabilities mHdrCapabilities;
        private boolean mSidekickActive;
        private SidekickInternal mSidekickInternal;


        private  SurfaceControl.PhysicalDisplayInfo mDisplayInfos[];
        private  SurfaceControl.PhysicalDisplayInfo mDisplayInfos[];


@@ -181,6 +183,7 @@ final class LocalDisplayAdapter extends DisplayAdapter {
            updatePhysicalDisplayInfoLocked(physicalDisplayInfos, activeDisplayInfo,
            updatePhysicalDisplayInfoLocked(physicalDisplayInfos, activeDisplayInfo,
                    colorModes, activeColorMode);
                    colorModes, activeColorMode);
            updateColorModesLocked(colorModes, activeColorMode);
            updateColorModesLocked(colorModes, activeColorMode);
            mSidekickInternal = LocalServices.getService(SidekickInternal.class);
            if (mBuiltInDisplayId == SurfaceControl.BUILT_IN_DISPLAY_ID_MAIN) {
            if (mBuiltInDisplayId == SurfaceControl.BUILT_IN_DISPLAY_ID_MAIN) {
                LightsManager lights = LocalServices.getService(LightsManager.class);
                LightsManager lights = LocalServices.getService(LightsManager.class);
                mBacklight = lights.getLight(LightsManager.LIGHT_ID_BACKLIGHT);
                mBacklight = lights.getLight(LightsManager.LIGHT_ID_BACKLIGHT);
@@ -510,16 +513,40 @@ final class LocalDisplayAdapter extends DisplayAdapter {
                                    + ", state=" + Display.stateToString(state) + ")");
                                    + ", state=" + Display.stateToString(state) + ")");
                        }
                        }


                        // We must tell sidekick to stop controlling the display before we
                        // can change its power mode, so do that first.
                        if (mSidekickActive) {
                            Trace.traceBegin(Trace.TRACE_TAG_POWER,
                                    "SidekickInternal#endDisplayControl");
                            try {
                                mSidekickInternal.endDisplayControl();
                            } finally {
                                Trace.traceEnd(Trace.TRACE_TAG_POWER);
                            }
                            mSidekickActive = false;
                        }
                        final int mode = getPowerModeForState(state);
                        Trace.traceBegin(Trace.TRACE_TAG_POWER, "setDisplayState("
                        Trace.traceBegin(Trace.TRACE_TAG_POWER, "setDisplayState("
                                + "id=" + displayId
                                + "id=" + displayId
                                + ", state=" + Display.stateToString(state) + ")");
                                + ", state=" + Display.stateToString(state) + ")");
                        try {
                        try {
                            final int mode = getPowerModeForState(state);
                            SurfaceControl.setDisplayPowerMode(token, mode);
                            SurfaceControl.setDisplayPowerMode(token, mode);
                            Trace.traceCounter(Trace.TRACE_TAG_POWER, "DisplayPowerMode", mode);
                            Trace.traceCounter(Trace.TRACE_TAG_POWER, "DisplayPowerMode", mode);
                        } finally {
                        } finally {
                            Trace.traceEnd(Trace.TRACE_TAG_POWER);
                            Trace.traceEnd(Trace.TRACE_TAG_POWER);
                        }
                        }
                        // If we're entering a suspended (but not OFF) power state and we
                        // have a sidekick available, tell it now that it can take control.
                        if (Display.isSuspendedState(state) && state != Display.STATE_OFF
                                && mSidekickInternal != null && !mSidekickActive) {
                            Trace.traceBegin(Trace.TRACE_TAG_POWER,
                                    "SidekickInternal#startDisplayControl");
                            try {
                                mSidekickActive = mSidekickInternal.startDisplayControl(state);
                            } finally {
                                Trace.traceEnd(Trace.TRACE_TAG_POWER);
                            }
                        }
                    }
                    }


                    private void setDisplayBrightness(int brightness) {
                    private void setDisplayBrightness(int brightness) {
+9 −0
Original line number Original line Diff line number Diff line
@@ -193,6 +193,8 @@ public final class SystemServer {
            "com.google.android.clockwork.ThermalObserver";
            "com.google.android.clockwork.ThermalObserver";
    private static final String WEAR_CONNECTIVITY_SERVICE_CLASS =
    private static final String WEAR_CONNECTIVITY_SERVICE_CLASS =
            "com.google.android.clockwork.connectivity.WearConnectivityService";
            "com.google.android.clockwork.connectivity.WearConnectivityService";
    private static final String WEAR_SIDEKICK_SERVICE_CLASS =
            "com.google.android.clockwork.sidekick.SidekickService";
    private static final String WEAR_DISPLAY_SERVICE_CLASS =
    private static final String WEAR_DISPLAY_SERVICE_CLASS =
            "com.google.android.clockwork.display.WearDisplayService";
            "com.google.android.clockwork.display.WearDisplayService";
    private static final String WEAR_LEFTY_SERVICE_CLASS =
    private static final String WEAR_LEFTY_SERVICE_CLASS =
@@ -559,6 +561,13 @@ public final class SystemServer {
        mSystemServiceManager.startService(LightsService.class);
        mSystemServiceManager.startService(LightsService.class);
        traceEnd();
        traceEnd();


        traceBeginAndSlog("StartSidekickService");
        // Package manager isn't started yet; need to use SysProp not hardware feature
        if (SystemProperties.getBoolean("config.enable_sidekick_graphics", false)) {
            mSystemServiceManager.startService(WEAR_SIDEKICK_SERVICE_CLASS);
        }
        traceEnd();

        // Display manager is needed to provide display metrics before package manager
        // Display manager is needed to provide display metrics before package manager
        // starts up.
        // starts up.
        traceBeginAndSlog("StartDisplayManager");
        traceBeginAndSlog("StartDisplayManager");