Loading core/java/android/service/wallpaper/WallpaperService.java +37 −31 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import android.util.DisplayMetrics; import android.util.TypedValue; import android.view.ViewRootImpl; import android.view.WindowInsets; import com.android.internal.R; import com.android.internal.os.HandlerCaller; import com.android.internal.view.BaseIWindow; Loading @@ -32,18 +33,17 @@ import android.annotation.SdkConstant; import android.annotation.SdkConstant.SdkConstantType; import android.app.Service; import android.app.WallpaperManager; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.res.Configuration; import android.graphics.PixelFormat; import android.graphics.Rect; import android.hardware.display.DisplayManager; import android.hardware.display.DisplayManager.DisplayListener; import android.os.Bundle; import android.os.IBinder; import android.os.Looper; import android.os.Message; import android.os.PowerManager; import android.os.RemoteException; import android.util.Log; import android.view.Display; Loading Loading @@ -139,7 +139,6 @@ public abstract class WallpaperService extends Service { boolean mInitializing = true; boolean mVisible; boolean mScreenOn = true; boolean mReportedVisible; boolean mDestroyed; Loading Loading @@ -192,18 +191,8 @@ public abstract class WallpaperService extends Service { boolean mPendingSync; MotionEvent mPendingMove; final BroadcastReceiver mReceiver = new BroadcastReceiver() { @Override 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(); } } }; DisplayManager mDisplayManager; Display mDisplay; final BaseSurfaceHolder mSurfaceHolder = new BaseSurfaceHolder() { { Loading Loading @@ -536,8 +525,8 @@ public abstract class WallpaperService extends Service { out.print(prefix); out.print("mInitializing="); out.print(mInitializing); out.print(" mDestroyed="); out.println(mDestroyed); out.print(prefix); out.print("mVisible="); out.print(mVisible); out.print(" mScreenOn="); out.print(mScreenOn); 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(" mSurfaceCreated="); out.print(mSurfaceCreated); out.print(" mIsCreating="); out.print(mIsCreating); Loading Loading @@ -876,12 +865,9 @@ public abstract class WallpaperService extends Service { mWindow.setSession(mSession); mScreenOn = ((PowerManager)getSystemService(Context.POWER_SERVICE)).isScreenOn(); IntentFilter filter = new IntentFilter(); filter.addAction(Intent.ACTION_SCREEN_ON); filter.addAction(Intent.ACTION_SCREEN_OFF); registerReceiver(mReceiver, filter); mDisplayManager = (DisplayManager)getSystemService(Context.DISPLAY_SERVICE); mDisplayManager.registerDisplayListener(mDisplayListener, mCaller.getHandler()); mDisplay = mDisplayManager.getDisplay(Display.DEFAULT_DISPLAY); if (DEBUG) Log.v(TAG, "onCreate(): " + this); onCreate(mSurfaceHolder); Loading Loading @@ -921,7 +907,8 @@ public abstract class WallpaperService extends Service { void reportVisibility() { if (!mDestroyed) { boolean visible = mVisible && mScreenOn; boolean visible = mVisible & mDisplay != null && mDisplay.getState() != Display.STATE_OFF; if (mReportedVisible != visible) { mReportedVisible = visible; if (DEBUG) Log.v(TAG, "onVisibilityChanged(" + visible Loading Loading @@ -1025,6 +1012,10 @@ public abstract class WallpaperService extends Service { mDestroyed = true; if (mDisplayManager != null) { mDisplayManager.unregisterDisplayListener(mDisplayListener); } if (mVisible) { mVisible = false; if (DEBUG) Log.v(TAG, "onVisibilityChanged(false): " + this); Loading @@ -1036,8 +1027,6 @@ public abstract class WallpaperService extends Service { if (DEBUG) Log.v(TAG, "onDestroy(): " + this); onDestroy(); unregisterReceiver(mReceiver); if (mCreated) { try { if (DEBUG) Log.v(TAG, "Removing window and destroying surface " Loading @@ -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 Loading core/java/com/android/internal/os/HandlerCaller.java +4 −0 Original line number Diff line number Diff line Loading @@ -49,6 +49,10 @@ public class HandlerCaller { mCallback = callback; } public Handler getHandler() { return mH; } public void executeOrSendMessage(Message msg) { // If we are calling this from the main thread, then we can call // right through. Otherwise, we need to send the message to the Loading Loading
core/java/android/service/wallpaper/WallpaperService.java +37 −31 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import android.util.DisplayMetrics; import android.util.TypedValue; import android.view.ViewRootImpl; import android.view.WindowInsets; import com.android.internal.R; import com.android.internal.os.HandlerCaller; import com.android.internal.view.BaseIWindow; Loading @@ -32,18 +33,17 @@ import android.annotation.SdkConstant; import android.annotation.SdkConstant.SdkConstantType; import android.app.Service; import android.app.WallpaperManager; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.res.Configuration; import android.graphics.PixelFormat; import android.graphics.Rect; import android.hardware.display.DisplayManager; import android.hardware.display.DisplayManager.DisplayListener; import android.os.Bundle; import android.os.IBinder; import android.os.Looper; import android.os.Message; import android.os.PowerManager; import android.os.RemoteException; import android.util.Log; import android.view.Display; Loading Loading @@ -139,7 +139,6 @@ public abstract class WallpaperService extends Service { boolean mInitializing = true; boolean mVisible; boolean mScreenOn = true; boolean mReportedVisible; boolean mDestroyed; Loading Loading @@ -192,18 +191,8 @@ public abstract class WallpaperService extends Service { boolean mPendingSync; MotionEvent mPendingMove; final BroadcastReceiver mReceiver = new BroadcastReceiver() { @Override 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(); } } }; DisplayManager mDisplayManager; Display mDisplay; final BaseSurfaceHolder mSurfaceHolder = new BaseSurfaceHolder() { { Loading Loading @@ -536,8 +525,8 @@ public abstract class WallpaperService extends Service { out.print(prefix); out.print("mInitializing="); out.print(mInitializing); out.print(" mDestroyed="); out.println(mDestroyed); out.print(prefix); out.print("mVisible="); out.print(mVisible); out.print(" mScreenOn="); out.print(mScreenOn); 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(" mSurfaceCreated="); out.print(mSurfaceCreated); out.print(" mIsCreating="); out.print(mIsCreating); Loading Loading @@ -876,12 +865,9 @@ public abstract class WallpaperService extends Service { mWindow.setSession(mSession); mScreenOn = ((PowerManager)getSystemService(Context.POWER_SERVICE)).isScreenOn(); IntentFilter filter = new IntentFilter(); filter.addAction(Intent.ACTION_SCREEN_ON); filter.addAction(Intent.ACTION_SCREEN_OFF); registerReceiver(mReceiver, filter); mDisplayManager = (DisplayManager)getSystemService(Context.DISPLAY_SERVICE); mDisplayManager.registerDisplayListener(mDisplayListener, mCaller.getHandler()); mDisplay = mDisplayManager.getDisplay(Display.DEFAULT_DISPLAY); if (DEBUG) Log.v(TAG, "onCreate(): " + this); onCreate(mSurfaceHolder); Loading Loading @@ -921,7 +907,8 @@ public abstract class WallpaperService extends Service { void reportVisibility() { if (!mDestroyed) { boolean visible = mVisible && mScreenOn; boolean visible = mVisible & mDisplay != null && mDisplay.getState() != Display.STATE_OFF; if (mReportedVisible != visible) { mReportedVisible = visible; if (DEBUG) Log.v(TAG, "onVisibilityChanged(" + visible Loading Loading @@ -1025,6 +1012,10 @@ public abstract class WallpaperService extends Service { mDestroyed = true; if (mDisplayManager != null) { mDisplayManager.unregisterDisplayListener(mDisplayListener); } if (mVisible) { mVisible = false; if (DEBUG) Log.v(TAG, "onVisibilityChanged(false): " + this); Loading @@ -1036,8 +1027,6 @@ public abstract class WallpaperService extends Service { if (DEBUG) Log.v(TAG, "onDestroy(): " + this); onDestroy(); unregisterReceiver(mReceiver); if (mCreated) { try { if (DEBUG) Log.v(TAG, "Removing window and destroying surface " Loading @@ -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 Loading
core/java/com/android/internal/os/HandlerCaller.java +4 −0 Original line number Diff line number Diff line Loading @@ -49,6 +49,10 @@ public class HandlerCaller { mCallback = callback; } public Handler getHandler() { return mH; } public void executeOrSendMessage(Message msg) { // If we are calling this from the main thread, then we can call // right through. Otherwise, we need to send the message to the Loading