Code example for PowerManager

Methods: newWakeLock

0
 
    public DockObserver(Context context) {
        mContext = context;
 
        mPowerManager = (PowerManager)mContext.getSystemService(Context.POWER_SERVICE);
        mWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
 
        init();  // set initial status 
        startObserving(DOCK_UEVENT_MATCH);
    } 
 
    @Override 
    public void onUEvent(UEventObserver.UEvent event) {
        if (Log.isLoggable(TAG, Log.VERBOSE)) {
            Slog.v(TAG, "Dock UEVENT: " + event.toString());
        } 
 
        synchronized (mLock) {
            try { 
                int newState = Integer.parseInt(event.get("SWITCH_STATE"));
                if (newState != mDockState) {