PowerTest.java revision f013e1afd1e68af5e3b868c26a653bbfb39538f8
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 53 @Override 54 protected String tag() { 55 return TAG; 56 } 57 58 @Override 59 protected Test[] tests() { 60 mPowerManager = IPowerManager.Stub.asInterface(ServiceManager.getService("power")); 61 62 return mTests; 63 } 64 private Test[] mTests = new Test[] { 65 new Test("Touch events don't poke") { 66 public void run() { 67 mPokeState |= LocalPowerManager.POKE_LOCK_IGNORE_CHEEK_EVENTS; 68 try { 69 mPowerManager.setPokeLock(mPokeState, mPokeToken, TAG); 70 } catch (RemoteException e) { 71 throw new RuntimeException(e); 72 } 73 } 74 }, 75 new Test("Touch events poke") { 76 public void run() { 77 mPokeState &= ~LocalPowerManager.POKE_LOCK_IGNORE_CHEEK_EVENTS; 78 try { 79 mPowerManager.setPokeLock(mPokeState, mPokeToken, TAG); 80 } catch (RemoteException e) { 81 throw new RuntimeException(e); 82 } 83 } 84 }, 85 new Test("Short timeout") { 86 public void run() { 87 mPokeState &= ~LocalPowerManager.POKE_LOCK_TIMEOUT_MASK; 88 mPokeState |= LocalPowerManager.POKE_LOCK_SHORT_TIMEOUT; 89 try { 90 mPowerManager.setPokeLock(mPokeState, mPokeToken, TAG); 91 } catch (RemoteException e) { 92 throw new RuntimeException(e); 93 } 94 } 95 }, 96 new Test("Medium timeout") { 97 public void run() { 98 mPokeState &= ~LocalPowerManager.POKE_LOCK_TIMEOUT_MASK; 99 mPokeState |= LocalPowerManager.POKE_LOCK_MEDIUM_TIMEOUT; 100 try { 101 mPowerManager.setPokeLock(mPokeState, mPokeToken, TAG); 102 } catch (RemoteException e) { 103 throw new RuntimeException(e); 104 } 105 } 106 }, 107 new Test("Normal timeout") { 108 public void run() { 109 mPokeState &= ~LocalPowerManager.POKE_LOCK_TIMEOUT_MASK; 110 try { 111 mPowerManager.setPokeLock(mPokeState, mPokeToken, TAG); 112 } catch (RemoteException e) { 113 throw new RuntimeException(e); 114 } 115 } 116 }, 117 new Test("Illegal timeout") { 118 public void run() { 119 mPokeState |= LocalPowerManager.POKE_LOCK_SHORT_TIMEOUT 120 | LocalPowerManager.POKE_LOCK_MEDIUM_TIMEOUT; 121 try { 122 mPowerManager.setPokeLock(mPokeState, mPokeToken, TAG); 123 } catch (RemoteException e) { 124 throw new RuntimeException(e); 125 } 126 } 127 }, 128 }; 129} 130