• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.annotation.Nullable;
20 import android.app.IWallpaperManager;
21 import android.os.RemoteException;
22 import android.util.Log;
23 
24 import com.android.systemui.doze.dagger.DozeScope;
25 import com.android.systemui.statusbar.notification.stack.StackStateAnimator;
26 import com.android.systemui.statusbar.phone.BiometricUnlockController;
27 import com.android.systemui.statusbar.phone.DozeParameters;
28 
29 import java.io.PrintWriter;
30 
31 import javax.inject.Inject;
32 
33 /**
34  * Propagates doze state to wallpaper engine.
35  */
36 @DozeScope
37 public class DozeWallpaperState implements DozeMachine.Part {
38 
39     private static final String TAG = "DozeWallpaperState";
40     private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
41 
42     @Nullable
43     private final IWallpaperManager mWallpaperManagerService;
44     private final DozeParameters mDozeParameters;
45     private final BiometricUnlockController mBiometricUnlockController;
46     private boolean mIsAmbientMode;
47 
48     @Inject
DozeWallpaperState( @ullable IWallpaperManager wallpaperManagerService, BiometricUnlockController biometricUnlockController, DozeParameters parameters)49     public DozeWallpaperState(
50             @Nullable IWallpaperManager wallpaperManagerService,
51             BiometricUnlockController biometricUnlockController,
52             DozeParameters parameters) {
53         mWallpaperManagerService = wallpaperManagerService;
54         mBiometricUnlockController = biometricUnlockController;
55         mDozeParameters = parameters;
56     }
57 
58     @Override
transitionTo(DozeMachine.State oldState, DozeMachine.State newState)59     public void transitionTo(DozeMachine.State oldState, DozeMachine.State newState) {
60         final boolean isAmbientMode;
61         switch (newState) {
62             case DOZE:
63             case DOZE_AOD:
64             case DOZE_AOD_DOCKED:
65             case DOZE_AOD_PAUSING:
66             case DOZE_AOD_PAUSED:
67             case DOZE_REQUEST_PULSE:
68             case DOZE_PULSE_DONE:
69             case DOZE_PULSING:
70                 isAmbientMode = true;
71                 break;
72             case DOZE_PULSING_BRIGHT:
73             default:
74                 isAmbientMode = false;
75         }
76         final boolean animated;
77         if (isAmbientMode) {
78             animated = mDozeParameters.shouldControlScreenOff();
79         } else {
80             boolean wakingUpFromPulse = oldState == DozeMachine.State.DOZE_PULSING
81                     && newState == DozeMachine.State.FINISH;
82             boolean fastDisplay = !mDozeParameters.getDisplayNeedsBlanking();
83             animated = (fastDisplay && !mBiometricUnlockController.unlockedByWakeAndUnlock())
84                     || wakingUpFromPulse;
85         }
86 
87         if (isAmbientMode != mIsAmbientMode) {
88             mIsAmbientMode = isAmbientMode;
89             if (mWallpaperManagerService != null) {
90                 try {
91                     long duration = animated ? StackStateAnimator.ANIMATION_DURATION_WAKEUP : 0L;
92                     if (DEBUG) {
93                         Log.i(TAG, "AOD wallpaper state changed to: " + mIsAmbientMode
94                             + ", animationDuration: " + duration);
95                     }
96                     mWallpaperManagerService.setInAmbientMode(mIsAmbientMode, duration);
97                 } catch (RemoteException e) {
98                     // Cannot notify wallpaper manager service, but it's fine, let's just skip it.
99                     Log.w(TAG, "Cannot notify state to WallpaperManagerService: " + mIsAmbientMode);
100                 }
101             }
102         }
103     }
104 
105     @Override
dump(PrintWriter pw)106     public void dump(PrintWriter pw) {
107         pw.println("DozeWallpaperState:");
108         pw.println(" isAmbientMode: " + mIsAmbientMode);
109         pw.println(" hasWallpaperService: " + (mWallpaperManagerService != null));
110     }
111 }
112