1818
1919import android .app .admin .DevicePolicyManager ;
2020import android .content .Context ;
21+ import android .content .Intent ;
2122import android .content .res .Configuration ;
2223import android .content .res .Resources ;
24+ import android .database .ContentObserver ;
2325import android .graphics .Canvas ;
2426import android .graphics .Color ;
2527import android .graphics .Paint ;
2628import android .graphics .PixelFormat ;
2729import android .graphics .Point ;
2830import android .os .Handler ;
2931import android .os .Looper ;
32+ import android .os .PowerManager ;
3033import android .os .RemoteException ;
34+ import android .os .SystemClock ;
35+ import android .os .UserHandle ;
3136import android .provider .Settings ;
37+ import android .net .Uri ;
3238import android .view .Display ;
3339import android .view .Gravity ;
3440import android .view .MotionEvent ;
5460import java .util .TimerTask ;
5561
5662public class FODCircleView extends ImageView implements ConfigurationListener {
63+ private static final String DOZE_INTENT = "com.android.systemui.doze.pulse" ;
64+
5765 private final int mPositionX ;
5866 private final int mPositionY ;
5967 private final int mSize ;
@@ -75,6 +83,14 @@ public class FODCircleView extends ImageView implements ConfigurationListener {
7583 private boolean mIsDreaming ;
7684 private boolean mIsCircleShowing ;
7785
86+ private boolean mDozeEnabled ;
87+ private boolean mFodGestureEnable ;
88+ private boolean mPressPending ;
89+ private boolean mScreenTurnedOn ;
90+
91+ private PowerManager mPowerManager ;
92+ private PowerManager .WakeLock mWakeLock ;
93+
7894 private Handler mHandler ;
7995
8096 private final ImageView mPressedView ;
@@ -87,12 +103,26 @@ public class FODCircleView extends ImageView implements ConfigurationListener {
87103 new IFingerprintInscreenCallback .Stub () {
88104 @ Override
89105 public void onFingerDown () {
90- mHandler .post (() -> showCircle ());
106+ if (mFodGestureEnable && !mScreenTurnedOn ) {
107+ if (mDozeEnabled ) {
108+ mHandler .post (() -> mContext .sendBroadcast (new Intent (DOZE_INTENT )));
109+ } else {
110+ mWakeLock .acquire (3000 );
111+ mHandler .post (() -> mPowerManager .wakeUp (SystemClock .uptimeMillis (),
112+ PowerManager .WAKE_REASON_GESTURE , FODCircleView .class .getSimpleName ()));
113+ }
114+ mPressPending = true ;
115+ } else {
116+ mHandler .post (() -> showCircle ());
117+ }
91118 }
92119
93120 @ Override
94121 public void onFingerUp () {
95122 mHandler .post (() -> hideCircle ());
123+ if (mFodGestureEnable && mPressPending ) {
124+ mPressPending = false ;
125+ }
96126 }
97127 };
98128
@@ -131,16 +161,67 @@ public void onStartedGoingToSleep(int why) {
131161 hide ();
132162 }
133163
164+ @ Override
165+ public void onScreenTurnedOff () {
166+ mScreenTurnedOn = false ;
167+ if (mFodGestureEnable ){
168+ hideCircle ();
169+ }else {
170+ hide ();
171+ }
172+ }
173+
134174 @ Override
135175 public void onScreenTurnedOn () {
136- if (mUpdateMonitor .isFingerprintDetectionRunning ()) {
176+ if (! mFodGestureEnable && mUpdateMonitor .isFingerprintDetectionRunning ()) {
137177 show ();
138178 }
179+ if (mFodGestureEnable && mPressPending ) {
180+ mHandler .post (() -> showCircle ());
181+ mPressPending = false ;
182+ }
183+ mScreenTurnedOn = true ;
139184 }
140185 };
141186
187+ private class FodGestureSettingsObserver extends ContentObserver {
188+ FodGestureSettingsObserver (Context context , Handler handler ) {
189+ super (handler );
190+ }
191+
192+ void registerListener () {
193+ mContext .getContentResolver ().registerContentObserver (
194+ Settings .Secure .getUriFor (
195+ Settings .Secure .DOZE_ENABLED ),
196+ false , this , UserHandle .USER_ALL );
197+ mContext .getContentResolver ().registerContentObserver (
198+ Settings .System .getUriFor (
199+ Settings .System .FOD_GESTURE ),
200+ false , this , UserHandle .USER_ALL );
201+ updateSettings ();
202+ }
203+
204+ @ Override
205+ public void onChange (boolean selfChange , Uri uri ) {
206+ super .onChange (selfChange , uri );
207+ updateSettings ();
208+ }
209+
210+ public void updateSettings () {
211+ mDozeEnabled = Settings .Secure .getIntForUser (
212+ mContext .getContentResolver (),
213+ Settings .Secure .DOZE_ENABLED , 1 ,
214+ UserHandle .USER_CURRENT ) == 1 ;
215+ mFodGestureEnable = Settings .System .getIntForUser (
216+ mContext .getContentResolver (),
217+ Settings .System .FOD_GESTURE , 1 ,
218+ UserHandle .USER_CURRENT ) == 1 ;
219+ }
220+ }
221+
142222 private boolean mCutoutMasked ;
143223 private int mStatusbarHeight ;
224+ private FodGestureSettingsObserver mFodGestureSettingsObserver ;
144225
145226 public FODCircleView (Context context ) {
146227 super (context );
@@ -169,6 +250,10 @@ public FODCircleView(Context context) {
169250 mPaintFingerprintBackground .setColor (res .getColor (R .color .config_fodColorBackground ));
170251 mPaintFingerprintBackground .setAntiAlias (true );
171252
253+ mPowerManager = context .getSystemService (PowerManager .class );
254+ mWakeLock = mPowerManager .newWakeLock (PowerManager .PARTIAL_WAKE_LOCK ,
255+ FODCircleView .class .getSimpleName ());
256+
172257 mWindowManager = context .getSystemService (WindowManager .class );
173258
174259 mNavigationBarSize = res .getDimensionPixelSize (R .dimen .navigation_bar_size );
@@ -213,7 +298,13 @@ protected void onDraw(Canvas canvas) {
213298
214299 mUpdateMonitor = Dependency .get (KeyguardUpdateMonitor .class );
215300 mUpdateMonitor .registerCallback (mMonitorCallback );
216-
301+
302+ if (context .getResources ().getBoolean (
303+ com .android .internal .R .bool .config_supportsScreenOffInDisplayFingerprint )){
304+ mFodGestureSettingsObserver = new FodGestureSettingsObserver (context , mHandler );
305+ mFodGestureSettingsObserver .registerListener ();
306+ }
307+
217308 updateCutoutFlags ();
218309 Dependency .get (ConfigurationController .class ).addCallback (this );
219310 }
@@ -329,7 +420,7 @@ public void hideCircle() {
329420 }
330421
331422 public void show () {
332- if (!mUpdateMonitor .isScreenOn ()) {
423+ if (!mFodGestureEnable && ! mUpdateMonitor .isScreenOn ()) {
333424 // Keyguard is shown just after screen turning off
334425 return ;
335426 }
0 commit comments