1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License 15 */ 16 17 package com.android.systemui.doze; 18 19 import android.app.IWallpaperManager; 20 import android.content.Context; 21 import android.os.RemoteException; 22 import android.os.ServiceManager; 23 import android.util.Log; 24 25 import com.android.internal.annotations.VisibleForTesting; 26 import com.android.keyguard.KeyguardUpdateMonitor; 27 import com.android.keyguard.KeyguardUpdateMonitorCallback; 28 import com.android.systemui.statusbar.phone.DozeParameters; 29 30 import java.io.PrintWriter; 31 32 /** 33 * Propagates doze state to wallpaper engine. 34 */ 35 public class DozeWallpaperState implements DozeMachine.Part { 36 37 private static final String TAG = "DozeWallpaperState"; 38 private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); 39 40 private final IWallpaperManager mWallpaperManagerService; 41 private boolean mIsAmbientMode; 42 private final DozeParameters mDozeParameters; 43 44 public DozeWallpaperState(Context context) { 45 this(IWallpaperManager.Stub.asInterface( 46 ServiceManager.getService(Context.WALLPAPER_SERVICE)), 47 DozeParameters.getInstance(context)); 48 } 49 50 @VisibleForTesting 51 DozeWallpaperState(IWallpaperManager wallpaperManagerService, DozeParameters parameters) { 52 mWallpaperManagerService = wallpaperManagerService; 53 mDozeParameters = parameters; 54 } 55 56 @Override 57 public void transitionTo(DozeMachine.State oldState, DozeMachine.State newState) { 58 final boolean isAmbientMode; 59 switch (newState) { 60 case DOZE: 61 case DOZE_AOD: 62 case DOZE_AOD_PAUSING: 63 case DOZE_AOD_PAUSED: 64 case DOZE_REQUEST_PULSE: 65 case DOZE_PULSING: 66 case DOZE_PULSE_DONE: 67 isAmbientMode = true; 68 break; 69 default: 70 isAmbientMode = false; 71 } 72 73 final boolean animated; 74 if (isAmbientMode) { 75 animated = mDozeParameters.shouldControlScreenOff(); 76 } else { 77 boolean wakingUpFromPulse = oldState == DozeMachine.State.DOZE_PULSING 78 && newState == DozeMachine.State.FINISH; 79 animated = !mDozeParameters.getDisplayNeedsBlanking() || wakingUpFromPulse; 80 } 81 82 if (isAmbientMode != mIsAmbientMode) { 83 mIsAmbientMode = isAmbientMode; 84 try { 85 if (DEBUG) { 86 Log.i(TAG, "AOD wallpaper state changed to: " + mIsAmbientMode 87 + ", animated: " + animated); 88 } 89 mWallpaperManagerService.setInAmbientMode(mIsAmbientMode, animated); 90 } catch (RemoteException e) { 91 // Cannot notify wallpaper manager service, but it's fine, let's just skip it. 92 Log.w(TAG, "Cannot notify state to WallpaperManagerService: " + mIsAmbientMode); 93 } 94 } 95 } 96 97 @Override 98 public void dump(PrintWriter pw) { 99 pw.println("DozeWallpaperState:"); 100 pw.println(" isAmbientMode: " + mIsAmbientMode); 101 } 102 } 103