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
tag()39     protected String tag() {
40         return TAG;
41     }
42 
43     @Override
tests()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 (RELEASE_FLAG_WAIT_FOR_NO_PROXIMITY") {
81             public void run() {
82                 mProx.release(PowerManager.RELEASE_FLAG_WAIT_FOR_NO_PROXIMITY);
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 " +
97                 "(RELEASE_FLAG_WAIT_FOR_NO_PROXIMITY)") {
98             public void run() {
99                 mProx.acquire();
100                 mHandler.postDelayed(new Runnable() {
101                     @Override
102                     public void run() {
103                         mProx.release(PowerManager.RELEASE_FLAG_WAIT_FOR_NO_PROXIMITY);
104                     }
105                 }, 5000);
106             }
107         },
108     };
109 }
110