diff options
author | Brett Chabot <brettchabot@android.com> | 2009-11-12 13:35:13 -0800 |
---|---|---|
committer | android-build SharedAccount <android-build@sekiwake.mtv.corp.google.com> | 2009-11-18 18:39:12 -0800 |
commit | 872068b00473098530080b18efe9d068f2d7c50f (patch) | |
tree | 78c7acd889193d76d50c914cab5bdc3e405eaa66 | |
parent | 6c1318fce4816904bcb1dd6bb9ad53f92bfc1510 (diff) | |
download | cts-eclair-sholes-release.tar.gz |
Add receiver to CTS to disable the screen lock.android-sdk-2.0.1_r1android-sdk-2.0.1-docs_r1android-2.0.1_r1eclair-sholes-release
The receiver was added to the existing 'DeviceInfoCollector' apk, and that apk
was renamed to TestDeviceSetup to reflect its new purpose.
This replaces the old method of injecting a menu key event, which no longer
works.
Bug 2099347
Change-Id: Icf0c2ba6e65fb0e401dfcc98468c91bb0c7b521d
-rw-r--r-- | tools/device-setup/Android.mk (renamed from tools/plugin/Android.mk) | 0 | ||||
-rw-r--r-- | tools/device-setup/TestDeviceSetup/Android.mk (renamed from tools/plugin/DeviceInfoCollector/Android.mk) | 4 | ||||
-rw-r--r-- | tools/device-setup/TestDeviceSetup/AndroidManifest.xml (renamed from tools/plugin/DeviceInfoCollector/AndroidManifest.xml) | 16 | ||||
-rw-r--r-- | tools/device-setup/TestDeviceSetup/src/android/tests/getinfo/DeviceInfoActivity.java (renamed from tools/plugin/DeviceInfoCollector/src/android/tests/getinfo/DeviceInfoActivity.java) | 8 | ||||
-rw-r--r-- | tools/device-setup/TestDeviceSetup/src/android/tests/getinfo/DeviceInfoInstrument.java (renamed from tools/plugin/DeviceInfoCollector/src/android/tests/getinfo/DeviceInfoInstrument.java) | 11 | ||||
-rw-r--r-- | tools/device-setup/TestDeviceSetup/src/android/tests/util/DisableKeyguardReceiver.java | 36 | ||||
-rw-r--r-- | tools/host/src/com/android/cts/DeviceManager.java | 3 | ||||
-rw-r--r-- | tools/host/src/com/android/cts/TestDevice.java | 85 | ||||
-rw-r--r-- | tools/host/src/com/android/cts/TestHost.java | 7 |
9 files changed, 132 insertions, 38 deletions
diff --git a/tools/plugin/Android.mk b/tools/device-setup/Android.mk index 0a05aedff50..0a05aedff50 100644 --- a/tools/plugin/Android.mk +++ b/tools/device-setup/Android.mk diff --git a/tools/plugin/DeviceInfoCollector/Android.mk b/tools/device-setup/TestDeviceSetup/Android.mk index 1816649369d..3704be59c51 100644 --- a/tools/plugin/DeviceInfoCollector/Android.mk +++ b/tools/device-setup/TestDeviceSetup/Android.mk @@ -24,7 +24,9 @@ LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS) LOCAL_JAVA_LIBRARIES := android.test.runner -LOCAL_PACKAGE_NAME := DeviceInfoCollector +LOCAL_SDK_VERSION := current + +LOCAL_PACKAGE_NAME := TestDeviceSetup include $(BUILD_PACKAGE) diff --git a/tools/plugin/DeviceInfoCollector/AndroidManifest.xml b/tools/device-setup/TestDeviceSetup/AndroidManifest.xml index 7eacb1ac4f1..d55ecdfa518 100644 --- a/tools/plugin/DeviceInfoCollector/AndroidManifest.xml +++ b/tools/device-setup/TestDeviceSetup/AndroidManifest.xml @@ -16,22 +16,30 @@ --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="android.tests.getinfo"> + package="android.tests.devicesetup"> <uses-permission android:name="android.permission.READ_PHONE_STATE" /> + <uses-permission android:name="android.permission.DISABLE_KEYGUARD" /> <application> <uses-library android:name="android.test.runner" /> - <activity android:name="DeviceInfoActivity" android:label="DeviceInfoActivity"> + <activity android:name="android.tests.getinfo.DeviceInfoActivity" + android:label="DeviceInfoActivity"> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity> + + <receiver android:name="android.tests.util.DisableKeyguardReceiver"> + <intent-filter> + <action android:name="android.tests.util.disablekeyguard" /> + </intent-filter> + </receiver> </application> - <instrumentation android:name=".DeviceInfoInstrument" - android:targetPackage="android.tests.getinfo" + <instrumentation android:name="android.tests.getinfo.DeviceInfoInstrument" + android:targetPackage="android.tests.devicesetup" android:label="app to get info from device"/> </manifest> diff --git a/tools/plugin/DeviceInfoCollector/src/android/tests/getinfo/DeviceInfoActivity.java b/tools/device-setup/TestDeviceSetup/src/android/tests/getinfo/DeviceInfoActivity.java index 94da1cfddbf..e6c0e143967 100644 --- a/tools/plugin/DeviceInfoCollector/src/android/tests/getinfo/DeviceInfoActivity.java +++ b/tools/device-setup/TestDeviceSetup/src/android/tests/getinfo/DeviceInfoActivity.java @@ -16,14 +16,13 @@ package android.tests.getinfo; -import java.util.Locale; - import android.app.Activity; -import android.app.ActivityThread; import android.content.res.Configuration; import android.os.Bundle; import android.widget.TextView; +import java.util.Locale; + /** * Collect device information on target device. @@ -53,8 +52,7 @@ public class DeviceInfoActivity extends Activity { TextView view = new TextView(this); view.setText("hello"); setContentView(view); - ActivityThread t = ActivityThread.currentActivityThread(); - Configuration con = t.getConfiguration(); + Configuration con = getResources().getConfiguration(); String touchScreen = null; if (con.touchscreen == Configuration.TOUCHSCREEN_UNDEFINED) { touchScreen = "undefined"; diff --git a/tools/plugin/DeviceInfoCollector/src/android/tests/getinfo/DeviceInfoInstrument.java b/tools/device-setup/TestDeviceSetup/src/android/tests/getinfo/DeviceInfoInstrument.java index bf6f4dd2fbd..64abfcf52e2 100644 --- a/tools/plugin/DeviceInfoCollector/src/android/tests/getinfo/DeviceInfoInstrument.java +++ b/tools/device-setup/TestDeviceSetup/src/android/tests/getinfo/DeviceInfoInstrument.java @@ -22,6 +22,7 @@ import android.content.Context; import android.content.Intent; import android.os.Build; import android.os.Bundle; +import android.telephony.TelephonyManager; import android.util.DisplayMetrics; import android.view.Display; import android.view.WindowManager; @@ -99,20 +100,22 @@ public class DeviceInfoInstrument extends Instrumentation { waitForIdleSync(); activity.waitForAcitityToFinish(); + TelephonyManager tm = (TelephonyManager) getContext().getSystemService( + Context.TELEPHONY_SERVICE); // network - String network = android.telephony.TelephonyManager.getDefault().getNetworkOperatorName(); + String network = tm.getNetworkOperatorName(); addResult(NETWORK, network); // imei - String imei = android.telephony.TelephonyManager.getDefault().getDeviceId(); + String imei = tm.getDeviceId(); addResult(IMEI, imei); // imsi - String imsi = android.telephony.TelephonyManager.getDefault().getSubscriberId(); + String imsi = tm.getSubscriberId(); addResult(IMSI, imsi); // phone number - String phoneNumber = android.telephony.TelephonyManager.getDefault().getLine1Number(); + String phoneNumber = tm.getLine1Number(); addResult(PHONE_NUMBER, phoneNumber); finish(Activity.RESULT_OK, mResults); diff --git a/tools/device-setup/TestDeviceSetup/src/android/tests/util/DisableKeyguardReceiver.java b/tools/device-setup/TestDeviceSetup/src/android/tests/util/DisableKeyguardReceiver.java new file mode 100644 index 00000000000..3e5012def79 --- /dev/null +++ b/tools/device-setup/TestDeviceSetup/src/android/tests/util/DisableKeyguardReceiver.java @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package android.tests.util; + +import android.app.KeyguardManager; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; + +/** + * A utility receiver to disable the keyguard on devices. + * Intended to be used so UI related tests can be executed successfully. + */ +public class DisableKeyguardReceiver extends BroadcastReceiver { + + @Override + public void onReceive(Context context, Intent intent) { + KeyguardManager keyguardManager = + (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE); + keyguardManager.newKeyguardLock("cts").disableKeyguard(); + } +} diff --git a/tools/host/src/com/android/cts/DeviceManager.java b/tools/host/src/com/android/cts/DeviceManager.java index 9dd292ab9e3..b92128ad4c9 100644 --- a/tools/host/src/com/android/cts/DeviceManager.java +++ b/tools/host/src/com/android/cts/DeviceManager.java @@ -354,9 +354,6 @@ public class DeviceManager implements IDeviceChangeListener { } attempts += 1; } - // dismiss the screen lock by sending a MENU key event - // TODO: this command isn't going to work on a user device, seems like its not needed - executeCommand("adb -s " + deviceSerialNumber + " shell input keyevent 82"); } } diff --git a/tools/host/src/com/android/cts/TestDevice.java b/tools/host/src/com/android/cts/TestDevice.java index dd53a7ffa50..2146b1ee11c 100644 --- a/tools/host/src/com/android/cts/TestDevice.java +++ b/tools/host/src/com/android/cts/TestDevice.java @@ -21,6 +21,7 @@ import com.android.ddmlib.ClientData; import com.android.ddmlib.IDevice; import com.android.ddmlib.IShellOutputReceiver; import com.android.ddmlib.MultiLineReceiver; +import com.android.ddmlib.NullOutputReceiver; import com.android.ddmlib.RawImage; import com.android.ddmlib.SyncService; import com.android.ddmlib.SyncService.ISyncProgressMonitor; @@ -50,7 +51,8 @@ import java.util.regex.Pattern; * </ul> */ public class TestDevice implements DeviceObserver { - private static final String GET_INFO_APP_PACKAGE_NAME = "android.tests.getinfo"; + private static final String DEVICE_SETUP_APK = "TestDeviceSetup"; + private static final String DEVICE_SETUP_APP_PACKAGE_NAME = "android.tests.devicesetup"; private static final String DEFAULT_TEST_RUNNER_NAME = "android.test.InstrumentationTestRunner"; private static final String ACTION_INSTALL = "install"; @@ -144,7 +146,10 @@ public class TestDevice implements DeviceObserver { } /** - * get the information of this device + * Gets this device's information. + * + * Assumes that the test device setup apk is already installed. + * See {@link #installDeviceSetupApp()}. * * @return information of this device. */ @@ -160,6 +165,24 @@ public class TestDevice implements DeviceObserver { } /** + * Attempt to disable the screen guard on device. + * + * Assumes the test device setup apk is already installed. + * See {@link #installDeviceSetupApp()}. + * + * Note: uninstalling the device setup app {@link #uninstallDeviceSetupApp()} will re-enable + * keyguard. + * + * @throws DeviceDisconnectedException + */ + public void disableKeyguard () throws DeviceDisconnectedException { + final String commandStr = "am broadcast -a android.tests.util.disablekeyguard"; + Log.d(commandStr); + + executeShellCommand(commandStr, new NullOutputReceiver()); + } + + /** * Return the Device instance associated with this TestDevice. */ public IDevice getDevice() { @@ -246,20 +269,51 @@ public class TestDevice implements DeviceObserver { } /** - * Run device information collector apk to got the device info. + * Run device information collector command to got the device info. */ private void genDeviceInfo() throws DeviceDisconnectedException, InvalidNameSpaceException, InvalidApkPathException { - String apkName = "DeviceInfoCollector"; + mDeviceInfo.set(DeviceParameterCollector.SERIAL_NUMBER, getSerialNumber()); + // run shell command to run device information collector + Log.d("run device information collector"); + runDeviceInfoCollectorCommand(); + waitForCommandFinish(); + } + + /** + * Uninstall the device setup apk from device. + * + * See {@link #installDeviceSetupApp} + * + * @throws DeviceDisconnectedException + * @throws InvalidNameSpaceException + */ + public void uninstallDeviceSetupApp() throws DeviceDisconnectedException, + InvalidNameSpaceException { + // reset device observer + DeviceObserver tmpDeviceObserver = mDeviceObserver; + mDeviceObserver = this; + Log.d("uninstall get info ..."); + uninstallAPK(DEVICE_SETUP_APP_PACKAGE_NAME); + waitForCommandFinish(); + Log.d("uninstall device information collector successfully"); + mDeviceObserver = tmpDeviceObserver; + } - String apkPath = HostConfig.getInstance().getCaseRepository().getApkPath(apkName); + /** + * Install the device setup apk on the device. + * + * @throws DeviceDisconnectedException + * @throws InvalidApkPathException + */ + public void installDeviceSetupApp() throws DeviceDisconnectedException, InvalidApkPathException { + String apkPath = HostConfig.getInstance().getCaseRepository().getApkPath(DEVICE_SETUP_APK); if (!HostUtils.isFileExist(apkPath)) { Log.e("File doesn't exist: " + apkPath, null); return; } - mDeviceInfo.set(DeviceParameterCollector.SERIAL_NUMBER, getSerialNumber()); - Log.d("installing " + apkName + " apk"); + Log.d("installing " + DEVICE_SETUP_APK + " apk"); mObjectSync = new ObjectSync(); // reset device observer @@ -269,16 +323,6 @@ public class TestDevice implements DeviceObserver { Log.d("install get info ..."); installAPK(apkPath); waitForCommandFinish(); - - // run shell command to run device information collector - Log.d("run device information collector"); - runDeviceInfoCollectorCommand(); - waitForCommandFinish(); - - Log.d("uninstall get info ..."); - uninstallAPK(GET_INFO_APP_PACKAGE_NAME); - waitForCommandFinish(); - Log.d("uninstall device information collector successfully"); mDeviceObserver = tmpDeviceObserver; } @@ -286,8 +330,9 @@ public class TestDevice implements DeviceObserver { * Run command to collect device info. */ private void runDeviceInfoCollectorCommand() throws DeviceDisconnectedException { - final String commandStr = "am instrument -w -e bundle" - + " true android.tests.getinfo/.DeviceInfoInstrument"; + final String commandStr = "am instrument -w -e bundle true " + + String.format("%s/android.tests.getinfo.DeviceInfoInstrument", + DEVICE_SETUP_APP_PACKAGE_NAME); Log.d(commandStr); mPackageActionTimer.start(ACTION_GET_DEV_INFO, this); @@ -1545,6 +1590,8 @@ public class TestDevice implements DeviceObserver { final LogReceiver logReceiver) throws DeviceDisconnectedException { if (mStatus == STATUS_OFFLINE) { + Log.d(String.format("device %s is offline when attempting to execute %s", + getSerialNumber(), cmd)); throw new DeviceDisconnectedException(getSerialNumber()); } diff --git a/tools/host/src/com/android/cts/TestHost.java b/tools/host/src/com/android/cts/TestHost.java index 7d86ffec8c8..90dc97f30d9 100644 --- a/tools/host/src/com/android/cts/TestHost.java +++ b/tools/host/src/com/android/cts/TestHost.java @@ -458,11 +458,12 @@ public class TestHost extends XMLResourceHandler implements SessionObserver { TestDevice device = sDeviceManager.allocateFreeDeviceById(deviceId); TestSessionLog sessionLog = ts.getSessionLog(); ts.setTestDevice(device); - - sessionLog.setDeviceInfo(device.getDeviceInfo()); + ts.getDevice().installDeviceSetupApp(); + sessionLog.setDeviceInfo(ts.getDevice().getDeviceInfo()); boolean finish = false; while (!finish) { + ts.getDevice().disableKeyguard(); try { switch (type) { case RUN_SINGLE_TEST: @@ -498,6 +499,8 @@ public class TestHost extends XMLResourceHandler implements SessionObserver { if (HostConfig.getMaxTestCount() > 0) { sDeviceManager.resetTestDevice(ts.getDevice()); } + + ts.getDevice().uninstallDeviceSetupApp(); } /** |