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

Commit a35b7699 authored by Yuncheol Heo's avatar Yuncheol Heo
Browse files

Revert "Use the existing wallpaper command API to send wake/sleep events to the wallpaper."

This reverts commit bde98075.

Reason for revert: b/185615919

Change-Id: I4906f109de478361790e459c117bd5d6a88a778c
parent bde98075
Loading
Loading
Loading
Loading
+0 −14
Original line number Diff line number Diff line
@@ -190,18 +190,4 @@ interface IWallpaperManager {
     * Called from SystemUI when it shows the AoD UI.
     */
    oneway void setInAmbientMode(boolean inAmbientMode, long animationDuration);

    /**
     * Called from SystemUI when the device is waking up.
     *
     * @hide
     */
    oneway void notifyWakingUp(int x, int y, in Bundle extras);

    /**
     * Called from SystemUI when the device is going to sleep.
     *
     * @hide
     */
    void notifyGoingToSleep(int x, int y, in Bundle extras);
}
+0 −24
Original line number Diff line number Diff line
@@ -189,30 +189,6 @@ public class WallpaperManager {
     */
    public static final String COMMAND_DROP = "android.home.drop";

    /**
     * Command for {@link #sendWallpaperCommand}: reported by System UI when the device is waking
     * up. The x and y arguments are a location (possibly very roughly) corresponding to the action
     * that caused the device to wake up. For example, if the power button was pressed, this will be
     * the location on the screen nearest the power button.
     *
     * If the location is unknown or not applicable, x and y will be -1.
     *
     * @hide
     */
    public static final String COMMAND_WAKING_UP = "android.wallpaper.wakingup";

    /**
     * Command for {@link #sendWallpaperCommand}: reported by System UI when the device is going to
     * sleep. The x and y arguments are a location (possibly very roughly) corresponding to the
     * action that caused the device to go to sleep. For example, if the power button was pressed,
     * this will be the location on the screen nearest the power button.
     *
     * If the location is unknown or not applicable, x and y will be -1.
     *
     * @hide
     */
    public static final String COMMAND_GOING_TO_SLEEP = "android.wallpaper.goingtosleep";

    /**
     * Command for {@link #sendWallpaperCommand}: reported when the wallpaper that was already
     * set is re-applied by the user.
+2 −101
Original line number Diff line number Diff line
@@ -17,20 +17,10 @@
package com.android.systemui.keyguard;

import android.annotation.IntDef;
import android.app.IWallpaperManager;
import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Point;
import android.os.Bundle;
import android.os.PowerManager;
import android.os.RemoteException;
import android.os.Trace;
import android.util.DisplayMetrics;

import androidx.annotation.Nullable;

import com.android.systemui.Dumpable;
import com.android.systemui.R;
import com.android.systemui.dagger.SysUISingleton;

import java.io.FileDescriptor;
@@ -41,7 +31,7 @@ import java.lang.annotation.RetentionPolicy;
import javax.inject.Inject;

/**
 * Tracks the wakefulness lifecycle, including why we're waking or sleeping.
 * Tracks the wakefulness lifecycle.
 */
@SysUISingleton
public class WakefulnessLifecycle extends Lifecycle<WakefulnessLifecycle.Observer> implements
@@ -61,30 +51,13 @@ public class WakefulnessLifecycle extends Lifecycle<WakefulnessLifecycle.Observe
    public static final int WAKEFULNESS_AWAKE = 2;
    public static final int WAKEFULNESS_GOING_TO_SLEEP = 3;

    private final Context mContext;
    private final DisplayMetrics mDisplayMetrics;
    private final IWallpaperManager mWallpaperManagerService;

    private int mWakefulness = WAKEFULNESS_ASLEEP;

    private @PowerManager.WakeReason int mLastWakeReason = PowerManager.WAKE_REASON_UNKNOWN;

    @Nullable
    private Point mLastWakeOriginLocation = null;

    private @PowerManager.GoToSleepReason int mLastSleepReason =
            PowerManager.GO_TO_SLEEP_REASON_MIN;

    @Nullable
    private Point mLastSleepOriginLocation = null;

    @Inject
    public WakefulnessLifecycle(
            Context context,
            @Nullable IWallpaperManager wallpaperManagerService) {
        mContext = context;
        mDisplayMetrics = context.getResources().getDisplayMetrics();
        mWallpaperManagerService = wallpaperManagerService;
    public WakefulnessLifecycle() {
    }

    public @Wakefulness int getWakefulness() {
@@ -112,15 +85,6 @@ public class WakefulnessLifecycle extends Lifecycle<WakefulnessLifecycle.Observe
        }
        setWakefulness(WAKEFULNESS_WAKING);
        mLastWakeReason = pmWakeReason;
        updateLastWakeOriginLocation();

        try {
            mWallpaperManagerService.notifyWakingUp(
                    mLastWakeOriginLocation.x, mLastWakeOriginLocation.y, new Bundle());
        } catch (RemoteException e) {
            e.printStackTrace();
        }

        dispatch(Observer::onStartedWakingUp);
    }

@@ -138,15 +102,6 @@ public class WakefulnessLifecycle extends Lifecycle<WakefulnessLifecycle.Observe
        }
        setWakefulness(WAKEFULNESS_GOING_TO_SLEEP);
        mLastSleepReason = pmSleepReason;
        updateLastSleepOriginLocation();

        try {
            mWallpaperManagerService.notifyGoingToSleep(
                    mLastSleepOriginLocation.x, mLastSleepOriginLocation.y, new Bundle());
        } catch (RemoteException e) {
            e.printStackTrace();
        }

        dispatch(Observer::onStartedGoingToSleep);
    }

@@ -169,60 +124,6 @@ public class WakefulnessLifecycle extends Lifecycle<WakefulnessLifecycle.Observe
        Trace.traceCounter(Trace.TRACE_TAG_APP, "wakefulness", wakefulness);
    }

    private void updateLastWakeOriginLocation() {
        mLastWakeOriginLocation = null;

        switch (mLastWakeReason) {
            case PowerManager.WAKE_REASON_POWER_BUTTON:
                mLastWakeOriginLocation = getPowerButtonOrigin();
                break;
            default:
                mLastWakeOriginLocation = getDefaultWakeSleepOrigin();
                break;
        }
    }

    private void updateLastSleepOriginLocation() {
        mLastSleepOriginLocation = null;

        switch (mLastSleepReason) {
            case PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON:
                mLastSleepOriginLocation = getPowerButtonOrigin();
                break;
            default:
                mLastSleepOriginLocation = getDefaultWakeSleepOrigin();
                break;
        }
    }

    /**
     * Returns the point on the screen closest to the physical power button.
     */
    private Point getPowerButtonOrigin() {
        final boolean isPortrait = mContext.getResources().getConfiguration().orientation
                == Configuration.ORIENTATION_PORTRAIT;

        if (isPortrait) {
            return new Point(
                    mDisplayMetrics.widthPixels,
                    mContext.getResources().getDimensionPixelSize(
                            R.dimen.physical_power_button_center_screen_location_y));
        } else {
            return new Point(
                    mContext.getResources().getDimensionPixelSize(
                            R.dimen.physical_power_button_center_screen_location_y),
                    mDisplayMetrics.heightPixels);
        }
    }

    /**
     * Returns the point on the screen used as the default origin for wake/sleep events. This is the
     * middle-bottom of the screen.
     */
    private Point getDefaultWakeSleepOrigin() {
        return new Point(mDisplayMetrics.widthPixels / 2, mDisplayMetrics.heightPixels);
    }

    public interface Observer {
        default void onStartedWakingUp() {}
        default void onFinishedWakingUp() {}
+1 −5
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;

import android.app.IWallpaperManager;
import android.os.PowerManager;
import android.testing.AndroidTestingRunner;

@@ -44,12 +43,9 @@ public class WakefulnessLifecycleTest extends SysuiTestCase {
    private WakefulnessLifecycle mWakefulness;
    private WakefulnessLifecycle.Observer mWakefulnessObserver;

    private IWallpaperManager mWallpaperManager;

    @Before
    public void setUp() throws Exception {
        mWallpaperManager = mock(IWallpaperManager.class);
        mWakefulness = new WakefulnessLifecycle(mContext, mWallpaperManager);
        mWakefulness = new WakefulnessLifecycle();
        mWakefulnessObserver = mock(WakefulnessLifecycle.Observer.class);
        mWakefulness.addObserver(mWakefulnessObserver);
    }
+1 −4
Original line number Diff line number Diff line
@@ -38,7 +38,6 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import android.app.IWallpaperManager;
import android.app.Notification;
import android.app.StatusBarManager;
import android.app.trust.TrustManager;
@@ -266,7 +265,6 @@ public class StatusBarTest extends SysuiTestCase {
    @Mock private OngoingCallController mOngoingCallController;
    @Mock private TunerService mTunerService;
    @Mock private FeatureFlags mFeatureFlags;
    @Mock private IWallpaperManager mWallpaperManager;
    private ShadeController mShadeController;
    private FakeExecutor mUiBgExecutor = new FakeExecutor(new FakeSystemClock());
    private InitController mInitController = new InitController();
@@ -325,8 +323,7 @@ public class StatusBarTest extends SysuiTestCase {

        when(mRemoteInputManager.getController()).thenReturn(mRemoteInputController);

        WakefulnessLifecycle wakefulnessLifecycle =
                new WakefulnessLifecycle(mContext, mWallpaperManager);
        WakefulnessLifecycle wakefulnessLifecycle = new WakefulnessLifecycle();
        wakefulnessLifecycle.dispatchStartedWakingUp(PowerManager.WAKE_REASON_UNKNOWN);
        wakefulnessLifecycle.dispatchFinishedWakingUp();

Loading