PowerTest.java revision 1a542c7b8ed0be049869a12d1e01e2604d052ac2
1/* 2 * Copyright (C) 2008 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.statusbartest; 18 19import android.app.ListActivity; 20import android.app.Notification; 21import android.app.NotificationManager; 22import android.widget.ArrayAdapter; 23import android.view.View; 24import android.os.Binder; 25import android.os.IBinder; 26import android.os.IPowerManager; 27import android.widget.ListView; 28import android.content.Intent; 29import android.app.Notification; 30import android.app.NotificationManager; 31import android.app.StatusBarManager; 32import android.os.RemoteException; 33import android.os.Vibrator; 34import android.os.Bundle; 35import android.os.Handler; 36import android.os.LocalPowerManager; 37import android.os.ServiceManager; 38import android.util.Log; 39import android.net.Uri; 40import android.os.SystemClock; 41import android.widget.RemoteViews; 42import android.widget.Toast; 43import android.os.PowerManager; 44 45public class PowerTest extends TestActivity 46{ 47 private final static String TAG = "PowerTest"; 48 IPowerManager mPowerManager; 49 int mPokeState = 0; 50 IBinder mPokeToken = new Binder(); 51 Handler mHandler = new Handler(); 52 PowerManager mPm; 53 PowerManager.WakeLock mProx; 54 55 @Override 56 protected String tag() { 57 return TAG; 58 } 59 60 @Override 61 protected Test[] tests() { 62 mPowerManager = IPowerManager.Stub.asInterface(ServiceManager.getService("power")); 63 mPm = (PowerManager)getSystemService("power"); 64 mProx = mPm.newWakeLock(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK, "PowerTest-prox"); 65 66 return mTests; 67 } 68 private Test[] mTests = new Test[] { 69 new Test("Enable proximity") { 70 public void run() { 71 mProx.acquire(); 72 } 73 }, 74 new Test("Disable proximity") { 75 public void run() { 76 mProx.release(); 77 } 78 }, 79 new Test("Disable proximity (WAIT_FOR_PROXIMITY_NEGATIVE)") { 80 public void run() { 81 mProx.release(PowerManager.WAIT_FOR_PROXIMITY_NEGATIVE); 82 } 83 }, 84 new Test("Touch events don't poke") { 85 public void run() { 86 mPokeState |= LocalPowerManager.POKE_LOCK_IGNORE_TOUCH_EVENTS; 87 try { 88 mPowerManager.setPokeLock(mPokeState, mPokeToken, TAG); 89 } catch (RemoteException e) { 90 throw new RuntimeException(e); 91 } 92 } 93 }, 94 95 new Test("Touch events poke") { 96 public void run() { 97 mPokeState &= ~LocalPowerManager.POKE_LOCK_IGNORE_TOUCH_EVENTS; 98 try { 99 mPowerManager.setPokeLock(mPokeState, mPokeToken, TAG); 100 } catch (RemoteException e) { 101 throw new RuntimeException(e); 102 } 103 } 104 }, 105 new Test("Short timeout") { 106 public void run() { 107 mPokeState &= ~LocalPowerManager.POKE_LOCK_TIMEOUT_MASK; 108 mPokeState |= LocalPowerManager.POKE_LOCK_SHORT_TIMEOUT; 109 try { 110 mPowerManager.setPokeLock(mPokeState, mPokeToken, TAG); 111 } catch (RemoteException e) { 112 throw new RuntimeException(e); 113 } 114 } 115 }, 116 new Test("Medium timeout") { 117 public void run() { 118 mPokeState &= ~LocalPowerManager.POKE_LOCK_TIMEOUT_MASK; 119 mPokeState |= LocalPowerManager.POKE_LOCK_MEDIUM_TIMEOUT; 120 try { 121 mPowerManager.setPokeLock(mPokeState, mPokeToken, TAG); 122 } catch (RemoteException e) { 123 throw new RuntimeException(e); 124 } 125 } 126 }, 127 new Test("Normal timeout") { 128 public void run() { 129 mPokeState &= ~LocalPowerManager.POKE_LOCK_TIMEOUT_MASK; 130 try { 131 mPowerManager.setPokeLock(mPokeState, mPokeToken, TAG); 132 } catch (RemoteException e) { 133 throw new RuntimeException(e); 134 } 135 } 136 }, 137 new Test("Illegal timeout") { 138 public void run() { 139 mPokeState |= LocalPowerManager.POKE_LOCK_SHORT_TIMEOUT 140 | LocalPowerManager.POKE_LOCK_MEDIUM_TIMEOUT; 141 try { 142 mPowerManager.setPokeLock(mPokeState, mPokeToken, TAG); 143 } catch (RemoteException e) { 144 throw new RuntimeException(e); 145 } 146 } 147 }, 148 }; 149} 150