Home | History | Annotate | Download | only in statusbartest
      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 
     17 package com.android.statusbartest;
     18 
     19 import android.app.ListActivity;
     20 import android.app.Notification;
     21 import android.app.NotificationManager;
     22 import android.widget.ArrayAdapter;
     23 import android.view.View;
     24 import android.os.Binder;
     25 import android.os.IBinder;
     26 import android.os.IPowerManager;
     27 import android.widget.ListView;
     28 import android.content.Intent;
     29 import android.content.ComponentName;
     30 import android.content.pm.PackageManager;
     31 import android.app.Notification;
     32 import android.app.NotificationManager;
     33 import android.app.StatusBarManager;
     34 import android.os.RemoteException;
     35 import android.os.Vibrator;
     36 import android.os.Bundle;
     37 import android.os.Handler;
     38 import android.os.LocalPowerManager;
     39 import android.os.ServiceManager;
     40 import android.util.Log;
     41 import android.net.Uri;
     42 import android.os.SystemClock;
     43 import android.widget.RemoteViews;
     44 import android.widget.Toast;
     45 import android.os.PowerManager;
     46 
     47 public class PowerTest extends TestActivity
     48 {
     49     private final static String TAG = "PowerTest";
     50     IPowerManager mPowerManager;
     51     int mPokeState = 0;
     52     IBinder mPokeToken = new Binder();
     53     Handler mHandler = new Handler();
     54     PowerManager mPm;
     55     PowerManager.WakeLock mProx;
     56 
     57     @Override
     58     protected String tag() {
     59         return TAG;
     60     }
     61 
     62     @Override
     63     protected Test[] tests() {
     64         mPowerManager = IPowerManager.Stub.asInterface(ServiceManager.getService("power"));
     65         mPm = (PowerManager)getSystemService("power");
     66         mProx = mPm.newWakeLock(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK, "PowerTest-prox");
     67 
     68         return mTests;
     69     }
     70     private Test[] mTests = new Test[] {
     71         new Test("Enable settings widget") {
     72             public void run() {
     73                 PackageManager pm = getPackageManager();
     74                 pm.setComponentEnabledSetting(new ComponentName("com.android.settings",
     75                             "com.android.settings.widget.SettingsAppWidgetProvider"),
     76                         PackageManager.COMPONENT_ENABLED_STATE_ENABLED, 0);
     77 
     78             }
     79         },
     80         new Test("Disable settings widget") {
     81             public void run() {
     82                 PackageManager pm = getPackageManager();
     83                 pm.setComponentEnabledSetting(new ComponentName("com.android.settings",
     84                             "com.android.settings.widget.SettingsAppWidgetProvider"),
     85                         PackageManager.COMPONENT_ENABLED_STATE_DISABLED, 0);
     86 
     87             }
     88         },
     89         new Test("Enable proximity") {
     90             public void run() {
     91                 mProx.acquire();
     92             }
     93         },
     94         new Test("Disable proximity") {
     95             public void run() {
     96                 mProx.release();
     97             }
     98         },
     99         new Test("Disable proximity (WAIT_FOR_PROXIMITY_NEGATIVE)") {
    100             public void run() {
    101                 mProx.release(PowerManager.WAIT_FOR_PROXIMITY_NEGATIVE);
    102             }
    103         },
    104         new Test("Touch events don't poke") {
    105             public void run() {
    106                 mPokeState |= LocalPowerManager.POKE_LOCK_IGNORE_TOUCH_EVENTS;
    107                 try {
    108                     mPowerManager.setPokeLock(mPokeState, mPokeToken, TAG);
    109                 } catch (RemoteException e) {
    110                     throw new RuntimeException(e);
    111                 }
    112             }
    113         },
    114 
    115         new Test("Touch events poke") {
    116             public void run() {
    117                 mPokeState &= ~LocalPowerManager.POKE_LOCK_IGNORE_TOUCH_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