blob: 92ba1687cdf643baf27c22ffd03e6bad63dda4ab [file] [log] [blame]
nxpandroid64fd68c2015-09-23 16:45:15 +05301package com.android.nfc;
2
3import android.app.KeyguardManager;
4import android.content.Context;
5import android.os.PowerManager;
6
7/**
8 * Helper class for determining the current screen state for NFC activities.
9 */
10class ScreenStateHelper {
11
nxf500513a018e72019-04-23 17:11:41 +053012 static final int SCREEN_STATE_UNKNOWN = 0x00;
nxpandroid6fd9cdb2017-07-12 18:25:41 +053013 static final int SCREEN_STATE_OFF_UNLOCKED = 0x01;
14 static final int SCREEN_STATE_OFF_LOCKED = 0x02;
15 static final int SCREEN_STATE_ON_LOCKED = 0x04;
16 static final int SCREEN_STATE_ON_UNLOCKED = 0x08;
nxpandroid64fd68c2015-09-23 16:45:15 +053017
nxpandroide66eb092017-07-12 21:36:08 +053018 //Polling mask
19 static final int SCREEN_POLLING_TAG_MASK = 0x10;
20 static final int SCREEN_POLLING_P2P_MASK = 0x20;
21 static final int SCREEN_POLLING_READER_MASK = 0x40;
nxpandroid64fd68c2015-09-23 16:45:15 +053022
23 private final PowerManager mPowerManager;
24 private final KeyguardManager mKeyguardManager;
25
26 ScreenStateHelper(Context context) {
27 mKeyguardManager = (KeyguardManager)
28 context.getSystemService(Context.KEYGUARD_SERVICE);
29 mPowerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
30 }
31
32 int checkScreenState() {
33 //TODO: fix deprecated api
34 if (!mPowerManager.isScreenOn()) {
nxpandroid6fd9cdb2017-07-12 18:25:41 +053035 if(mKeyguardManager.isKeyguardLocked()) {
36 return SCREEN_STATE_OFF_LOCKED;
37 } else {
38 return SCREEN_STATE_OFF_UNLOCKED;
39 }
nxpandroid64fd68c2015-09-23 16:45:15 +053040 } else if (mKeyguardManager.isKeyguardLocked()) {
41 return SCREEN_STATE_ON_LOCKED;
42 } else {
43 return SCREEN_STATE_ON_UNLOCKED;
44 }
45 }
46
47 /**
48 * For debugging only - no i18n
49 */
50 static String screenStateToString(int screenState) {
51 switch (screenState) {
nxpandroid6fd9cdb2017-07-12 18:25:41 +053052 case SCREEN_STATE_OFF_LOCKED:
53 return "OFF_LOCKED";
nxpandroid64fd68c2015-09-23 16:45:15 +053054 case SCREEN_STATE_ON_LOCKED:
55 return "ON_LOCKED";
56 case SCREEN_STATE_ON_UNLOCKED:
57 return "ON_UNLOCKED";
nxpandroid6fd9cdb2017-07-12 18:25:41 +053058 case SCREEN_STATE_OFF_UNLOCKED:
59 return "OFF_UNLOCKED";
nxpandroid64fd68c2015-09-23 16:45:15 +053060 default:
61 return "UNKNOWN";
62 }
63 }
64}