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

Commit b5686d55 authored by Jeff Brown's avatar Jeff Brown Committed by Android Git Automerger
Browse files

am 3d110b23: Make WallpaperService watch the actual display state.

* commit '3d110b23':
  Make WallpaperService watch the actual display state.
parents 6d0e8711 3d110b23
Loading
Loading
Loading
Loading
+37 −31
Original line number Original line Diff line number Diff line
@@ -23,6 +23,7 @@ import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.util.TypedValue;
import android.view.ViewRootImpl;
import android.view.ViewRootImpl;
import android.view.WindowInsets;
import android.view.WindowInsets;

import com.android.internal.R;
import com.android.internal.R;
import com.android.internal.os.HandlerCaller;
import com.android.internal.os.HandlerCaller;
import com.android.internal.view.BaseIWindow;
import com.android.internal.view.BaseIWindow;
@@ -32,18 +33,17 @@ import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
import android.annotation.SdkConstant.SdkConstantType;
import android.app.Service;
import android.app.Service;
import android.app.WallpaperManager;
import android.app.WallpaperManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Context;
import android.content.Intent;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Configuration;
import android.content.res.Configuration;
import android.graphics.PixelFormat;
import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.graphics.Rect;
import android.hardware.display.DisplayManager;
import android.hardware.display.DisplayManager.DisplayListener;
import android.os.Bundle;
import android.os.Bundle;
import android.os.IBinder;
import android.os.IBinder;
import android.os.Looper;
import android.os.Looper;
import android.os.Message;
import android.os.Message;
import android.os.PowerManager;
import android.os.RemoteException;
import android.os.RemoteException;
import android.util.Log;
import android.util.Log;
import android.view.Display;
import android.view.Display;
@@ -139,7 +139,6 @@ public abstract class WallpaperService extends Service {
        
        
        boolean mInitializing = true;
        boolean mInitializing = true;
        boolean mVisible;
        boolean mVisible;
        boolean mScreenOn = true;
        boolean mReportedVisible;
        boolean mReportedVisible;
        boolean mDestroyed;
        boolean mDestroyed;
        
        
@@ -192,18 +191,8 @@ public abstract class WallpaperService extends Service {
        boolean mPendingSync;
        boolean mPendingSync;
        MotionEvent mPendingMove;
        MotionEvent mPendingMove;


        final BroadcastReceiver mReceiver = new BroadcastReceiver() {
        DisplayManager mDisplayManager;
            @Override
        Display mDisplay;
            public void onReceive(Context context, Intent intent) {
                if (Intent.ACTION_SCREEN_ON.equals(intent.getAction())) {
                    mScreenOn = true;
                    reportVisibility();
                } else if (Intent.ACTION_SCREEN_OFF.equals(intent.getAction())) {
                    mScreenOn = false;
                    reportVisibility();
                }
            }
        };


        final BaseSurfaceHolder mSurfaceHolder = new BaseSurfaceHolder() {
        final BaseSurfaceHolder mSurfaceHolder = new BaseSurfaceHolder() {
            {
            {
@@ -536,8 +525,8 @@ public abstract class WallpaperService extends Service {
            out.print(prefix); out.print("mInitializing="); out.print(mInitializing);
            out.print(prefix); out.print("mInitializing="); out.print(mInitializing);
                    out.print(" mDestroyed="); out.println(mDestroyed);
                    out.print(" mDestroyed="); out.println(mDestroyed);
            out.print(prefix); out.print("mVisible="); out.print(mVisible);
            out.print(prefix); out.print("mVisible="); out.print(mVisible);
                    out.print(" mScreenOn="); out.print(mScreenOn);
                    out.print(" mReportedVisible="); out.println(mReportedVisible);
                    out.print(" mReportedVisible="); out.println(mReportedVisible);
            out.print(prefix); out.print("mDisplay="); out.println(mDisplay);
            out.print(prefix); out.print("mCreated="); out.print(mCreated);
            out.print(prefix); out.print("mCreated="); out.print(mCreated);
                    out.print(" mSurfaceCreated="); out.print(mSurfaceCreated);
                    out.print(" mSurfaceCreated="); out.print(mSurfaceCreated);
                    out.print(" mIsCreating="); out.print(mIsCreating);
                    out.print(" mIsCreating="); out.print(mIsCreating);
@@ -876,12 +865,9 @@ public abstract class WallpaperService extends Service {
            
            
            mWindow.setSession(mSession);
            mWindow.setSession(mSession);


            mScreenOn = ((PowerManager)getSystemService(Context.POWER_SERVICE)).isScreenOn();
            mDisplayManager = (DisplayManager)getSystemService(Context.DISPLAY_SERVICE);

            mDisplayManager.registerDisplayListener(mDisplayListener, mCaller.getHandler());
            IntentFilter filter = new IntentFilter();
            mDisplay = mDisplayManager.getDisplay(Display.DEFAULT_DISPLAY);
            filter.addAction(Intent.ACTION_SCREEN_ON);
            filter.addAction(Intent.ACTION_SCREEN_OFF);
            registerReceiver(mReceiver, filter);


            if (DEBUG) Log.v(TAG, "onCreate(): " + this);
            if (DEBUG) Log.v(TAG, "onCreate(): " + this);
            onCreate(mSurfaceHolder);
            onCreate(mSurfaceHolder);
@@ -921,7 +907,8 @@ public abstract class WallpaperService extends Service {


        void reportVisibility() {
        void reportVisibility() {
            if (!mDestroyed) {
            if (!mDestroyed) {
                boolean visible = mVisible && mScreenOn;
                boolean visible = mVisible
                        & mDisplay != null && mDisplay.getState() != Display.STATE_OFF;
                if (mReportedVisible != visible) {
                if (mReportedVisible != visible) {
                    mReportedVisible = visible;
                    mReportedVisible = visible;
                    if (DEBUG) Log.v(TAG, "onVisibilityChanged(" + visible
                    if (DEBUG) Log.v(TAG, "onVisibilityChanged(" + visible
@@ -1025,6 +1012,10 @@ public abstract class WallpaperService extends Service {
            
            
            mDestroyed = true;
            mDestroyed = true;


            if (mDisplayManager != null) {
                mDisplayManager.unregisterDisplayListener(mDisplayListener);
            }

            if (mVisible) {
            if (mVisible) {
                mVisible = false;
                mVisible = false;
                if (DEBUG) Log.v(TAG, "onVisibilityChanged(false): " + this);
                if (DEBUG) Log.v(TAG, "onVisibilityChanged(false): " + this);
@@ -1036,8 +1027,6 @@ public abstract class WallpaperService extends Service {
            if (DEBUG) Log.v(TAG, "onDestroy(): " + this);
            if (DEBUG) Log.v(TAG, "onDestroy(): " + this);
            onDestroy();
            onDestroy();


            unregisterReceiver(mReceiver);
            
            if (mCreated) {
            if (mCreated) {
                try {
                try {
                    if (DEBUG) Log.v(TAG, "Removing window and destroying surface "
                    if (DEBUG) Log.v(TAG, "Removing window and destroying surface "
@@ -1062,6 +1051,23 @@ public abstract class WallpaperService extends Service {
                }
                }
            }
            }
        }
        }

        private final DisplayListener mDisplayListener = new DisplayListener() {
            @Override
            public void onDisplayChanged(int displayId) {
                if (mDisplay.getDisplayId() == displayId) {
                    reportVisibility();
                }
            }

            @Override
            public void onDisplayRemoved(int displayId) {
            }

            @Override
            public void onDisplayAdded(int displayId) {
            }
        };
    }
    }


    class IWallpaperEngineWrapper extends IWallpaperEngine.Stub
    class IWallpaperEngineWrapper extends IWallpaperEngine.Stub
+4 −0
Original line number Original line Diff line number Diff line
@@ -49,6 +49,10 @@ public class HandlerCaller {
        mCallback = callback;
        mCallback = callback;
    }
    }


    public Handler getHandler() {
        return mH;
    }

    public void executeOrSendMessage(Message msg) {
    public void executeOrSendMessage(Message msg) {
        // If we are calling this from the main thread, then we can call
        // If we are calling this from the main thread, then we can call
        // right through.  Otherwise, we need to send the message to the
        // right through.  Otherwise, we need to send the message to the