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.os.Binder;
     20 import android.os.IBinder;
     21 import android.os.IPowerManager;
     22 import android.content.ComponentName;
     23 import android.content.pm.PackageManager;
     24 import android.os.Handler;
     25 import android.os.ServiceManager;
     26 import android.os.PowerManager;
     27 
     28 public class PowerTest extends TestActivity
     29 {
     30     private final static String TAG = "PowerTest";
     31     IPowerManager mPowerManager;
     32     int mPokeState = 0;
     33     IBinder mPokeToken = new Binder();
     34     Handler mHandler = new Handler();
     35     PowerManager mPm;
     36     PowerManager.WakeLock mProx;
     37 
     38     @Override
     39     protected String tag() {
     40         return TAG;
     41     }
     42 
     43     @Override
     44     protected Test[] tests() {
     45         mPowerManager = IPowerManager.Stub.asInterface(ServiceManager.getService("power"));
     46         mPm = (PowerManager)getSystemService("power");
     47         mProx = mPm.newWakeLock(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK, "PowerTest-prox");
     48 
     49         return mTests;
     50     }
     51     private Test[] mTests = new Test[] {
     52         new Test("Enable settings widget") {
     53             public void run() {
     54                 PackageManager pm = getPackageManager();
     55                 pm.setComponentEnabledSetting(new ComponentName("com.android.settings",
     56                             "com.android.settings.widget.SettingsAppWidgetProvider"),
     57                         PackageManager.COMPONENT_ENABLED_STATE_ENABLED, 0);
     58 
     59             }
     60         },
     61         new Test("Disable settings widget") {
     62             public void run() {
     63                 PackageManager pm = getPackageManager();
     64                 pm.setComponentEnabledSetting(new ComponentName("com.android.settings",
     65                             "com.android.settings.widget.SettingsAppWidgetProvider"),
     66                         PackageManager.COMPONENT_ENABLED_STATE_DISABLED, 0);
     67 
     68             }
     69         },
     70         new Test("Enable proximity") {
     71             public void run() {
     72                 mProx.acquire();
     73             }
     74         },
     75         new Test("Disable proximity") {
     76             public void run() {
     77                 mProx.release();
     78             }
     79         },
     80         new Test("Disable proximity (WAIT_FOR_PROXIMITY_NEGATIVE)") {
     81             public void run() {
     82                 mProx.release(PowerManager.WAIT_FOR_PROXIMITY_NEGATIVE);
     83             }
     84         },
     85         new Test("Enable proximity, wait 5 seconds then disable") {
     86             public void run() {
     87                 mProx.acquire();
     88                 mHandler.postDelayed(new Runnable() {
     89                     @Override
     90                     public void run() {
     91                         mProx.release();
     92                     }
     93                 }, 5000);
     94             }
     95         },
     96         new Test("Enable proximity, wait 5 seconds then disable  (WAIT_FOR_PROXIMITY_NEGATIVE)") {
     97             public void run() {
     98                 mProx.acquire();
     99                 mHandler.postDelayed(new Runnable() {
    100                     @Override
    101                     public void run() {
    102                         mProx.release(PowerManager.WAIT_FOR_PROXIMITY_NEGATIVE);
    103                     }
    104                 }, 5000);
    105             }
    106         },
    107     };
    108 }
    109