PowerTest.java revision 8274a0e53630f80ab356f69ddad895ed9638574e
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("Cheek events don't poke") { 85 public void run() { 86 mPokeState |= LocalPowerManager.POKE_LOCK_IGNORE_CHEEK_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("Cheek events poke") { 96 public void run() { 97 mPokeState &= ~LocalPowerManager.POKE_LOCK_IGNORE_CHEEK_EVENTS; 98 try { 99 mPowerManager.setPokeLock(mPokeState, mPokeToken, TAG); 100 } catch (RemoteException e) { 101 throw new RuntimeException(e); 102 } 103 } 104 }, 105 new Test("Touch and Cheek events don't poke") { 106 public void run() { 107 mPokeState |= LocalPowerManager.POKE_LOCK_IGNORE_TOUCH_AND_CHEEK_EVENTS; 108 try { 109 mPowerManager.setPokeLock(mPokeState, mPokeToken, TAG); 110 } catch (RemoteException e) { 111 throw new RuntimeException(e); 112 } 113 } 114 }, 115 new Test("Touch and Cheek events poke") { 116 public void run() { 117 mPokeState &= ~LocalPowerManager.POKE_LOCK_IGNORE_TOUCH_AND_CHEEK_EVENTS; 118 try { 119 mPowerManager.setPokeLock(mPokeState, mPokeToken, TAG); 120 } catch (RemoteException e) { 121 throw new RuntimeException(e); 122 } 123 } 124 }, 125 new Test("Short timeout") { 126 public void run() { 127 mPokeState &= ~LocalPowerManager.POKE_LOCK_TIMEOUT_MASK; 128 mPokeState |= LocalPowerManager.POKE_LOCK_SHORT_TIMEOUT; 129 try { 130 mPowerManager.setPokeLock(mPokeState, mPokeToken, TAG); 131 } catch (RemoteException e) { 132 throw new RuntimeException(e); 133 } 134 } 135 }, 136 new Test("Medium timeout") { 137 public void run() { 138 mPokeState &= ~LocalPowerManager.POKE_LOCK_TIMEOUT_MASK; 139 mPokeState |= LocalPowerManager.POKE_LOCK_MEDIUM_TIMEOUT; 140 try { 141 mPowerManager.setPokeLock(mPokeState, mPokeToken, TAG); 142 } catch (RemoteException e) { 143 throw new RuntimeException(e); 144 } 145 } 146 }, 147 new Test("Normal timeout") { 148 public void run() { 149 mPokeState &= ~LocalPowerManager.POKE_LOCK_TIMEOUT_MASK; 150 try { 151 mPowerManager.setPokeLock(mPokeState, mPokeToken, TAG); 152 } catch (RemoteException e) { 153 throw new RuntimeException(e); 154 } 155 } 156 }, 157 new Test("Illegal timeout") { 158 public void run() { 159 mPokeState |= LocalPowerManager.POKE_LOCK_SHORT_TIMEOUT 160 | LocalPowerManager.POKE_LOCK_MEDIUM_TIMEOUT; 161 try { 162 mPowerManager.setPokeLock(mPokeState, mPokeToken, TAG); 163 } catch (RemoteException e) { 164 throw new RuntimeException(e); 165 } 166 } 167 }, 168 }; 169} 170