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 = 0;
13     static final int SCREEN_STATE_OFF = 1;
14     static final int SCREEN_STATE_ON_LOCKED = 2;
15     static final int SCREEN_STATE_ON_UNLOCKED = 3;
16 
17     private final PowerManager mPowerManager;
18     private final KeyguardManager mKeyguardManager;
19 
ScreenStateHelper(Context context)20     ScreenStateHelper(Context context) {
21         mKeyguardManager = (KeyguardManager)
22                 context.getSystemService(Context.KEYGUARD_SERVICE);
23         mPowerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
24     }
25 
checkScreenState()26     int checkScreenState() {
27         //TODO: fix deprecated api
28         if (!mPowerManager.isScreenOn()) {
29             return SCREEN_STATE_OFF;
30         } else if (mKeyguardManager.isKeyguardLocked()) {
31             return SCREEN_STATE_ON_LOCKED;
32         } else {
33             return SCREEN_STATE_ON_UNLOCKED;
34         }
35     }
36 
37     /**
38      * For debugging only - no i18n
39      */
screenStateToString(int screenState)40     static String screenStateToString(int screenState) {
41         switch (screenState) {
42             case SCREEN_STATE_OFF:
43                 return "OFF";
44             case SCREEN_STATE_ON_LOCKED:
45                 return "ON_LOCKED";
46             case SCREEN_STATE_ON_UNLOCKED:
47                 return "ON_UNLOCKED";
48             default:
49                 return "UNKNOWN";
50         }
51     }
52 }
53