• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.android.nfc;
2 
3 import android.app.KeyguardManager;
4 import android.content.Context;
5 import android.os.PowerManager;
6 
7 /**
8  * Helper class for determining the current screen state for NFC activities.
9  */
10 class ScreenStateHelper {
11 
12     static final int SCREEN_STATE_UNKNOWN = 0x00;
13     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;
17 
18     //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;
22 
23     private final PowerManager mPowerManager;
24     private final KeyguardManager mKeyguardManager;
25 
ScreenStateHelper(Context context)26     ScreenStateHelper(Context context) {
27         mKeyguardManager = (KeyguardManager)
28                 context.getSystemService(Context.KEYGUARD_SERVICE);
29         mPowerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
30     }
31 
checkScreenState()32     int checkScreenState() {
33         //TODO: fix deprecated api
34         if (!mPowerManager.isScreenOn()) {
35             if(mKeyguardManager.isKeyguardLocked()) {
36                 return SCREEN_STATE_OFF_LOCKED;
37             } else {
38                 return SCREEN_STATE_OFF_UNLOCKED;
39             }
40         } 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      */
screenStateToString(int screenState)50     static String screenStateToString(int screenState) {
51         switch (screenState) {
52             case SCREEN_STATE_OFF_LOCKED:
53                 return "OFF_LOCKED";
54             case SCREEN_STATE_ON_LOCKED:
55                 return "ON_LOCKED";
56             case SCREEN_STATE_ON_UNLOCKED:
57                 return "ON_UNLOCKED";
58             case SCREEN_STATE_OFF_UNLOCKED:
59                 return "OFF_UNLOCKED";
60             default:
61                 return "UNKNOWN";
62         }
63     }
64 }
65