PowerTest.java revision 9630704ed3b265f008a8f64ec60a33cf9dcd3345
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.os.Binder; 20import android.os.IBinder; 21import android.os.IPowerManager; 22import android.content.ComponentName; 23import android.content.pm.PackageManager; 24import android.os.RemoteException; 25import android.os.Handler; 26import android.os.LocalPowerManager; 27import android.os.ServiceManager; 28import android.os.PowerManager; 29 30public class PowerTest extends TestActivity 31{ 32 private final static String TAG = "PowerTest"; 33 IPowerManager mPowerManager; 34 int mPokeState = 0; 35 IBinder mPokeToken = new Binder(); 36 Handler mHandler = new Handler(); 37 PowerManager mPm; 38 PowerManager.WakeLock mProx; 39 40 @Override 41 protected String tag() { 42 return TAG; 43 } 44 45 @Override 46 protected Test[] tests() { 47 mPowerManager = IPowerManager.Stub.asInterface(ServiceManager.getService("power")); 48 mPm = (PowerManager)getSystemService("power"); 49 mProx = mPm.newWakeLock(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK, "PowerTest-prox"); 50 51 return mTests; 52 } 53 private Test[] mTests = new Test[] { 54 new Test("Enable settings widget") { 55 public void run() { 56 PackageManager pm = getPackageManager(); 57 pm.setComponentEnabledSetting(new ComponentName("com.android.settings", 58 "com.android.settings.widget.SettingsAppWidgetProvider"), 59 PackageManager.COMPONENT_ENABLED_STATE_ENABLED, 0); 60 61 } 62 }, 63 new Test("Disable settings widget") { 64 public void run() { 65 PackageManager pm = getPackageManager(); 66 pm.setComponentEnabledSetting(new ComponentName("com.android.settings", 67 "com.android.settings.widget.SettingsAppWidgetProvider"), 68 PackageManager.COMPONENT_ENABLED_STATE_DISABLED, 0); 69 70 } 71 }, 72 new Test("Enable proximity") { 73 public void run() { 74 mProx.acquire(); 75 } 76 }, 77 new Test("Disable proximity") { 78 public void run() { 79 mProx.release(); 80 } 81 }, 82 new Test("Disable proximity (WAIT_FOR_PROXIMITY_NEGATIVE)") { 83 public void run() { 84 mProx.release(PowerManager.WAIT_FOR_PROXIMITY_NEGATIVE); 85 } 86 }, 87 new Test("Enable proximity, wait 5 seconds then disable") { 88 public void run() { 89 mProx.acquire(); 90 mHandler.postDelayed(new Runnable() { 91 @Override 92 public void run() { 93 mProx.release(); 94 } 95 }, 5000); 96 } 97 }, 98 new Test("Enable proximity, wait 5 seconds then disable (WAIT_FOR_PROXIMITY_NEGATIVE)") { 99 public void run() { 100 mProx.acquire(); 101 mHandler.postDelayed(new Runnable() { 102 @Override 103 public void run() { 104 mProx.release(PowerManager.WAIT_FOR_PROXIMITY_NEGATIVE); 105 } 106 }, 5000); 107 } 108 }, 109 new Test("Touch events don't poke") { 110 public void run() { 111 mPokeState |= LocalPowerManager.POKE_LOCK_IGNORE_TOUCH_EVENTS; 112 try { 113 mPowerManager.setPokeLock(mPokeState, mPokeToken, TAG); 114 } catch (RemoteException e) { 115 throw new RuntimeException(e); 116 } 117 } 118 }, 119 120 new Test("Touch events poke") { 121 public void run() { 122 mPokeState &= ~LocalPowerManager.POKE_LOCK_IGNORE_TOUCH_EVENTS; 123 try { 124 mPowerManager.setPokeLock(mPokeState, mPokeToken, TAG); 125 } catch (RemoteException e) { 126 throw new RuntimeException(e); 127 } 128 } 129 }, 130 new Test("Short timeout") { 131 public void run() { 132 mPokeState &= ~LocalPowerManager.POKE_LOCK_TIMEOUT_MASK; 133 mPokeState |= LocalPowerManager.POKE_LOCK_SHORT_TIMEOUT; 134 try { 135 mPowerManager.setPokeLock(mPokeState, mPokeToken, TAG); 136 } catch (RemoteException e) { 137 throw new RuntimeException(e); 138 } 139 } 140 }, 141 new Test("Medium timeout") { 142 public void run() { 143 mPokeState &= ~LocalPowerManager.POKE_LOCK_TIMEOUT_MASK; 144 mPokeState |= LocalPowerManager.POKE_LOCK_MEDIUM_TIMEOUT; 145 try { 146 mPowerManager.setPokeLock(mPokeState, mPokeToken, TAG); 147 } catch (RemoteException e) { 148 throw new RuntimeException(e); 149 } 150 } 151 }, 152 new Test("Normal timeout") { 153 public void run() { 154 mPokeState &= ~LocalPowerManager.POKE_LOCK_TIMEOUT_MASK; 155 try { 156 mPowerManager.setPokeLock(mPokeState, mPokeToken, TAG); 157 } catch (RemoteException e) { 158 throw new RuntimeException(e); 159 } 160 } 161 }, 162 new Test("Illegal timeout") { 163 public void run() { 164 mPokeState |= LocalPowerManager.POKE_LOCK_SHORT_TIMEOUT 165 | LocalPowerManager.POKE_LOCK_MEDIUM_TIMEOUT; 166 try { 167 mPowerManager.setPokeLock(mPokeState, mPokeToken, TAG); 168 } catch (RemoteException e) { 169 throw new RuntimeException(e); 170 } 171 } 172 }, 173 }; 174} 175