1/* 2 * Copyright (C) 2013 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.android.testing.alarmservice; 18 19import android.content.Context; 20import android.os.PowerManager; 21import android.os.PowerManager.WakeLock; 22import android.util.Log; 23 24/** 25 * A singleton used for controlling and sharing of states/wakelocks 26 * 27 */ 28public class WakeUpController { 29 30 private static final String LOG_TAG = WakeUpController.class.getName(); 31 private static WakeUpController mController = null; 32 private WakeLock mWakeLock = null; 33 private Object mWakeSync = new Object(); 34 35 private WakeUpController() { 36 Log.i(LOG_TAG, "Created instance: 0x" + Integer.toHexString(this.hashCode())); 37 } 38 39 public static synchronized WakeUpController getController() { 40 if (mController == null) { 41 mController = new WakeUpController(); 42 } 43 return mController; 44 } 45 46 public WakeLock getWakeLock() { 47 if (mWakeLock == null) { 48 PowerManager pm = 49 (PowerManager) AlarmService.sContext.getSystemService(Context.POWER_SERVICE); 50 mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "testing-alarmservice"); 51 Log.i(LOG_TAG, "Create wakelock: 0x" + Integer.toHexString(mWakeLock.hashCode())); 52 } 53 return mWakeLock; 54 } 55 56 public Object getWakeSync() { 57 return mWakeSync; 58 } 59} 60