diff options
Diffstat (limited to 'tests')
43 files changed, 854 insertions, 1043 deletions
diff --git a/tests/BatteryWaster/res/layout/battery_waster.xml b/tests/BatteryWaster/res/layout/battery_waster.xml index e1cb6bf..57a5b55 100644 --- a/tests/BatteryWaster/res/layout/battery_waster.xml +++ b/tests/BatteryWaster/res/layout/battery_waster.xml @@ -25,11 +25,23 @@ android:layout_height="wrap_content" android:layout_marginLeft="25dp" android:layout_marginTop="25dp" + android:saveEnabled="false" android:textSize="18sp" android:textColor="#ffffffff" android:text="@string/waste_away" /> + <CheckBox android:id="@+id/checkbox_wake" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_marginLeft="25dp" + android:layout_marginTop="25dp" + android:saveEnabled="false" + android:textSize="18sp" + android:textColor="#ffffffff" + android:text="@string/wake_away" + /> + <ScrollView android:id="@+id/scroll" android:layout_width="match_parent" android:layout_height="0px" diff --git a/tests/BatteryWaster/res/values/strings.xml b/tests/BatteryWaster/res/values/strings.xml index 46c5fa1..a3b849a 100644 --- a/tests/BatteryWaster/res/values/strings.xml +++ b/tests/BatteryWaster/res/values/strings.xml @@ -18,5 +18,7 @@ <string name="waste_away">Discharge my battery!</string> + <string name="wake_away">Keep my device awake!</string> + </resources> diff --git a/tests/BatteryWaster/src/com/android/batterywaster/BatteryWaster.java b/tests/BatteryWaster/src/com/android/batterywaster/BatteryWaster.java index 8ea7e00..48c4520 100644 --- a/tests/BatteryWaster/src/com/android/batterywaster/BatteryWaster.java +++ b/tests/BatteryWaster/src/com/android/batterywaster/BatteryWaster.java @@ -39,8 +39,11 @@ public class BatteryWaster extends Activity { DateFormat mDateFormat; IntentFilter mFilter; PowerManager.WakeLock mWakeLock; + PowerManager.WakeLock mPartialWakeLock; SpinThread mThread; + boolean mWasting, mWaking; + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -50,6 +53,7 @@ public class BatteryWaster extends Activity { setContentView(R.layout.battery_waster); findViewById(R.id.checkbox).setOnClickListener(mClickListener); + findViewById(R.id.checkbox_wake).setOnClickListener(mWakeClickListener); mLog = (TextView)findViewById(R.id.log); mDateFormat = DateFormat.getInstance(); @@ -63,13 +67,27 @@ public class BatteryWaster extends Activity { PowerManager pm = (PowerManager)getSystemService(POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "BatteryWaster"); mWakeLock.setReferenceCounted(false); + mPartialWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "BatteryWaster"); + mPartialWakeLock.setReferenceCounted(false); } @Override public void onPause() { + super.onPause(); stopRunning(); } + @Override + public void onDestroy() { + super.onDestroy(); + if (mWakeLock.isHeld()) { + mWakeLock.release(); + } + if (mPartialWakeLock.isHeld()) { + mPartialWakeLock.release(); + } + } + View.OnClickListener mClickListener = new View.OnClickListener() { public void onClick(View v) { CheckBox checkbox = (CheckBox)v; @@ -81,23 +99,63 @@ public class BatteryWaster extends Activity { } }; + View.OnClickListener mWakeClickListener = new View.OnClickListener() { + public void onClick(View v) { + CheckBox checkbox = (CheckBox)v; + if (checkbox.isChecked()) { + mWaking = true; + updateWakeLock(); + } else { + mWaking = false; + updateWakeLock(); + } + } + }; + void startRunning() { - log("Start"); - registerReceiver(mReceiver, mFilter); - mWakeLock.acquire(); - if (mThread == null) { - mThread = new SpinThread(); - mThread.start(); + if (!mWasting) { + log("Start"); + registerReceiver(mReceiver, mFilter); + mWasting = true; + updateWakeLock(); + if (mThread == null) { + mThread = new SpinThread(); + mThread.start(); + } } } void stopRunning() { - log("Stop"); - unregisterReceiver(mReceiver); - mWakeLock.release(); - if (mThread != null) { - mThread.quit(); - mThread = null; + if (mWasting) { + log("Stop"); + unregisterReceiver(mReceiver); + mWasting = false; + updateWakeLock(); + if (mThread != null) { + mThread.quit(); + mThread = null; + } + } + } + + void updateWakeLock() { + if (mWasting) { + if (!mWakeLock.isHeld()) { + mWakeLock.acquire(); + } + } else { + if (mWakeLock.isHeld()) { + mWakeLock.release(); + } + } + if (mWaking) { + if (!mPartialWakeLock.isHeld()) { + mPartialWakeLock.acquire(); + } + } else { + if (mPartialWakeLock.isHeld()) { + mPartialWakeLock.release(); + } } } diff --git a/tests/CoreTests/android/Android.mk b/tests/CoreTests/android/Android.mk index 012e5eb..5abfc88 100644 --- a/tests/CoreTests/android/Android.mk +++ b/tests/CoreTests/android/Android.mk @@ -6,7 +6,7 @@ LOCAL_MODULE_TAGS := tests LOCAL_SRC_FILES := \ $(call all-subdir-java-files) -LOCAL_JAVA_LIBRARIES := android.test.runner +LOCAL_JAVA_LIBRARIES := android.test.runner bouncycastle LOCAL_PACKAGE_NAME := CoreTests diff --git a/tests/CoreTests/android/core/CryptoTest.java b/tests/CoreTests/android/core/CryptoTest.java deleted file mode 100644 index e6e50ec..0000000 --- a/tests/CoreTests/android/core/CryptoTest.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright (C) 2008 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.core; - -import junit.framework.Assert; -import junit.framework.TestCase; - -import org.apache.harmony.xnet.provider.jsse.OpenSSLMessageDigest; -import org.bouncycastle.crypto.Digest; -import org.bouncycastle.crypto.ExtendedDigest; -import org.bouncycastle.crypto.digests.MD4Digest; -import org.bouncycastle.crypto.digests.MD5Digest; -import org.bouncycastle.crypto.digests.SHA1Digest; -import android.test.suitebuilder.annotation.LargeTest; -import android.test.suitebuilder.annotation.MediumTest; - -/** - * Implements unit tests for our JNI wrapper around OpenSSL. We use the - * existing Bouncy Castle implementation as our test oracle. - */ -public class CryptoTest extends TestCase { - - /** - * Processes the two given message digests for the same data and checks - * the results. Requirement is that the results must be equal, the digest - * implementations must have the same properties, and the new implementation - * must be faster than the old one. - * - * @param oldDigest The old digest implementation, provided by Bouncy Castle - * @param newDigest The new digest implementation, provided by OpenSSL - */ - public void doTestMessageDigest(Digest oldDigest, Digest newDigest) { - final int ITERATIONS = 10; - - byte[] data = new byte[1024]; - - byte[] oldHash = new byte[oldDigest.getDigestSize()]; - byte[] newHash = new byte[newDigest.getDigestSize()]; - - Assert.assertEquals("Hash names must be equal", oldDigest.getAlgorithmName(), newDigest.getAlgorithmName()); - Assert.assertEquals("Hash sizes must be equal", oldHash.length, newHash.length); - Assert.assertEquals("Hash block sizes must be equal", ((ExtendedDigest)oldDigest).getByteLength(), ((ExtendedDigest)newDigest).getByteLength()); - for (int i = 0; i < data.length; i++) { - data[i] = (byte)i; - } - - long oldTime = 0; - long newTime = 0; - - for (int j = 0; j < ITERATIONS; j++) { - long t0 = System.currentTimeMillis(); - for (int i = 0; i < 4; i++) { - oldDigest.update(data, 0, data.length); - } - int oldLength = oldDigest.doFinal(oldHash, 0); - long t1 = System.currentTimeMillis(); - - oldTime = oldTime + (t1 - t0); - - long t2 = System.currentTimeMillis(); - for (int i = 0; i < 4; i++) { - newDigest.update(data, 0, data.length); - } - int newLength = newDigest.doFinal(newHash, 0); - long t3 = System.currentTimeMillis(); - - newTime = newTime + (t3 - t2); - - Assert.assertEquals("Hash sizes must be equal", oldLength, newLength); - - for (int i = 0; i < oldLength; i++) { - Assert.assertEquals("Hashes[" + i + "] must be equal", oldHash[i], newHash[i]); - } - } - - android.util.Log.d("CryptoTest", "Time for " + ITERATIONS + " x old hash processing: " + oldTime + " ms"); - android.util.Log.d("CryptoTest", "Time for " + ITERATIONS + " x new hash processing: " + newTime + " ms"); - - // Assert.assertTrue("New hash should be faster", newTime < oldTime); - } - - /** - * Tests the MD4 implementation. - */ - @MediumTest - public void testMD4() { - Digest oldDigest = new MD4Digest(); - Digest newDigest = OpenSSLMessageDigest.getInstance("MD4"); - doTestMessageDigest(oldDigest, newDigest); - } - - /** - * Tests the MD5 implementation. - */ - @MediumTest - public void testMD5() { - Digest oldDigest = new MD5Digest(); - Digest newDigest = OpenSSLMessageDigest.getInstance("MD5"); - doTestMessageDigest(oldDigest, newDigest); - } - - /** - * Tests the SHA-1 implementation. - */ - @MediumTest - public void testSHA1() { - Digest oldDigest = new SHA1Digest(); - Digest newDigest = OpenSSLMessageDigest.getInstance("SHA-1"); - doTestMessageDigest(oldDigest, newDigest); - } - -} diff --git a/tests/CoreTests/android/core/SSLPerformanceTest.java b/tests/CoreTests/android/core/SSLPerformanceTest.java index e2bd9c5..fd87e89 100644 --- a/tests/CoreTests/android/core/SSLPerformanceTest.java +++ b/tests/CoreTests/android/core/SSLPerformanceTest.java @@ -19,8 +19,8 @@ package android.core; import android.test.AndroidTestCase; import android.os.Debug; import org.apache.harmony.xnet.provider.jsse.FileClientSessionCache; +import org.apache.harmony.xnet.provider.jsse.OpenSSLContextImpl; import org.apache.harmony.xnet.provider.jsse.SSLClientSessionCache; -import org.apache.harmony.xnet.provider.jsse.SSLContextImpl; import org.apache.http.conn.scheme.SchemeRegistry; import org.apache.http.conn.scheme.Scheme; import org.apache.http.conn.ClientConnectionManager; @@ -189,14 +189,14 @@ public class SSLPerformanceTest extends AndroidTestCase { public void testEngineInit() throws IOException, KeyManagementException { Stopwatch stopwatch = new Stopwatch(); - new SSLContextImpl().engineInit(null, null, null); + new OpenSSLContextImpl().engineInit(null, null, null); stopwatch.stop(); } public void testWebRequestWithoutCache() throws IOException, KeyManagementException { - SSLContextImpl sslContext = new SSLContextImpl(); + OpenSSLContextImpl sslContext = new OpenSSLContextImpl(); sslContext.engineInit(null, null, null); Stopwatch stopwatch = new Stopwatch(); @@ -210,7 +210,7 @@ public class SSLPerformanceTest extends AndroidTestCase { KeyManagementException { deleteDirectory(); - SSLContextImpl sslContext = new SSLContextImpl(); + OpenSSLContextImpl sslContext = new OpenSSLContextImpl(); sslContext.engineInit(null, null, null, FileClientSessionCache.usingDirectory(getCacheDirectory()), null); @@ -234,7 +234,7 @@ public class SSLPerformanceTest extends AndroidTestCase { KeyManagementException { deleteDirectory(); - SSLContextImpl sslContext = new SSLContextImpl(); + OpenSSLContextImpl sslContext = new OpenSSLContextImpl(); sslContext.engineInit(null, null, null); // Make sure www.google.com is in the cache. @@ -247,7 +247,7 @@ public class SSLPerformanceTest extends AndroidTestCase { stopwatch.stop(); } - private void getVerisignDotCom(SSLContextImpl sslContext) + private void getVerisignDotCom(OpenSSLContextImpl sslContext) throws IOException { SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("https", diff --git a/tests/CoreTests/android/core/SSLSocketTest.java b/tests/CoreTests/android/core/SSLSocketTest.java index 088fa8c..021df80 100644 --- a/tests/CoreTests/android/core/SSLSocketTest.java +++ b/tests/CoreTests/android/core/SSLSocketTest.java @@ -19,9 +19,9 @@ package android.core; import junit.framework.TestCase; import org.apache.commons.codec.binary.Base64; -import org.apache.harmony.xnet.provider.jsse.SSLContextImpl; -import org.apache.harmony.xnet.provider.jsse.SSLClientSessionCache; import org.apache.harmony.xnet.provider.jsse.FileClientSessionCache; +import org.apache.harmony.xnet.provider.jsse.OpenSSLContextImpl; +import org.apache.harmony.xnet.provider.jsse.SSLClientSessionCache; import java.io.ByteArrayInputStream; import java.io.DataInputStream; @@ -907,7 +907,7 @@ public class SSLSocketTest extends TestCase { */ public void testClientSessionCaching() throws IOException, KeyManagementException { - SSLContextImpl context = new SSLContextImpl(); + OpenSSLContextImpl context = new OpenSSLContextImpl(); // Cache size = 2. FakeClientSessionCache fakeCache = new FakeClientSessionCache(); @@ -997,7 +997,7 @@ public class SSLSocketTest extends TestCase { public void testFileBasedClientSessionCache() throws IOException, KeyManagementException { - SSLContextImpl context = new SSLContextImpl(); + OpenSSLContextImpl context = new OpenSSLContextImpl(); String tmpDir = System.getProperty("java.io.tmpdir"); if (tmpDir == null) { fail("Please set 'java.io.tmpdir' system property."); diff --git a/tests/DpiTest/Android.mk b/tests/DpiTest/Android.mk index 3596c39..5463a17 100644 --- a/tests/DpiTest/Android.mk +++ b/tests/DpiTest/Android.mk @@ -7,4 +7,6 @@ LOCAL_PACKAGE_NAME := DensityTest LOCAL_MODULE_TAGS := tests +LOCAL_AAPT_FLAGS = -c 120dpi -c 240dpi -c 160dpi + include $(BUILD_PACKAGE) diff --git a/tests/DpiTest/res/values-xlarge-long/strings.xml b/tests/DpiTest/res/values-xlarge-long/strings.xml new file mode 100644 index 0000000..86ab660 --- /dev/null +++ b/tests/DpiTest/res/values-xlarge-long/strings.xml @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2007 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. +--> + +<resources> + <string name="act_title">DpiTest: XLarge Long</string> +</resources> diff --git a/tests/DpiTest/res/values-xlarge-notlong/strings.xml b/tests/DpiTest/res/values-xlarge-notlong/strings.xml new file mode 100644 index 0000000..1eebbf4 --- /dev/null +++ b/tests/DpiTest/res/values-xlarge-notlong/strings.xml @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2007 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. +--> + +<resources> + <string name="act_title">DpiTest: XLarge NotLong</string> +</resources> diff --git a/tests/DpiTest/res/values-xlarge/strings.xml b/tests/DpiTest/res/values-xlarge/strings.xml new file mode 100644 index 0000000..7e5d4b0 --- /dev/null +++ b/tests/DpiTest/res/values-xlarge/strings.xml @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2007 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. +--> + +<resources> + <string name="act_title">DpiTest: XLarge</string> +</resources> diff --git a/tests/DpiTest/src/com/google/android/test/dpi/DpiTestActivity.java b/tests/DpiTest/src/com/google/android/test/dpi/DpiTestActivity.java index cde2c71..6192a3c 100644 --- a/tests/DpiTest/src/com/google/android/test/dpi/DpiTestActivity.java +++ b/tests/DpiTest/src/com/google/android/test/dpi/DpiTestActivity.java @@ -56,7 +56,8 @@ public class DpiTestActivity extends Activity { ApplicationInfo ai = app.getPackageManager().getApplicationInfo( "com.google.android.test.dpi", 0); if (noCompat) { - ai.flags |= ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS + ai.flags |= ApplicationInfo.FLAG_SUPPORTS_XLARGE_SCREENS + | ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS | ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS | ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS | ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS diff --git a/tests/FixVibrateSetting/Android.mk b/tests/FixVibrateSetting/Android.mk new file mode 100644 index 0000000..2a88e5a --- /dev/null +++ b/tests/FixVibrateSetting/Android.mk @@ -0,0 +1,11 @@ +LOCAL_PATH:= $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_MODULE_TAGS := optional + +LOCAL_SRC_FILES := $(call all-subdir-java-files) + +LOCAL_PACKAGE_NAME := FixVibrateSetting +LOCAL_CERTIFICATE := platform + +include $(BUILD_PACKAGE) diff --git a/tests/FixVibrateSetting/AndroidManifest.xml b/tests/FixVibrateSetting/AndroidManifest.xml new file mode 100644 index 0000000..007d682 --- /dev/null +++ b/tests/FixVibrateSetting/AndroidManifest.xml @@ -0,0 +1,14 @@ +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.android.fixvibratesetting"> + <uses-permission android:name="android.permission.VIBRATE" /> + + <application> + <activity android:name="FixVibrateSetting" android:label="@string/app_label"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="android.intent.category.DEFAULT" /> + <category android:name="android.intent.category.LAUNCHER" /> + </intent-filter> + </activity> + </application> +</manifest> diff --git a/tests/FixVibrateSetting/res/drawable-hdpi/stat_sys_warning.png b/tests/FixVibrateSetting/res/drawable-hdpi/stat_sys_warning.png Binary files differnew file mode 100644 index 0000000..37c8853 --- /dev/null +++ b/tests/FixVibrateSetting/res/drawable-hdpi/stat_sys_warning.png diff --git a/tests/FixVibrateSetting/res/drawable-mdpi/stat_sys_warning.png b/tests/FixVibrateSetting/res/drawable-mdpi/stat_sys_warning.png Binary files differnew file mode 100644 index 0000000..be00f47 --- /dev/null +++ b/tests/FixVibrateSetting/res/drawable-mdpi/stat_sys_warning.png diff --git a/tests/FixVibrateSetting/res/layout/fix_vibrate.xml b/tests/FixVibrateSetting/res/layout/fix_vibrate.xml new file mode 100644 index 0000000..c505e65 --- /dev/null +++ b/tests/FixVibrateSetting/res/layout/fix_vibrate.xml @@ -0,0 +1,46 @@ +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical" + > + + <TextView android:id="@+id/current_setting" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="left" + android:layout_marginTop="30dp" + android:layout_marginBottom="50dp" + android:paddingLeft="8dp" + android:paddingTop="4dp" + android:textSize="20sp" + android:textColor="#ffffffff" + /> + + <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:gravity="center" + android:orientation="horizontal" + > + <Button android:id="@+id/fix" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/fix" + /> + + <Button android:id="@+id/unfix" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/unfix" + /> + </LinearLayout> + + <Button android:id="@+id/test" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center" + android:text="@string/test" + /> + +</LinearLayout> + diff --git a/tests/FixVibrateSetting/res/values/strings.xml b/tests/FixVibrateSetting/res/values/strings.xml new file mode 100644 index 0000000..269cef3 --- /dev/null +++ b/tests/FixVibrateSetting/res/values/strings.xml @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2007 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. +--> + +<resources> + <string name="app_label">Fix Vibrate</string> + <string name="title">Fix vibrate setting</string> + <string name="current_setting">"Ringer: %1$s\nNotification: %2$s"</string> + <string name="fix">Fix the setting</string> + <string name="unfix">Break the setting</string> + <string name="test">Test the setting</string> +</resources> + diff --git a/tests/FixVibrateSetting/src/com/android/fixvibratesetting/FixVibrateSetting.java b/tests/FixVibrateSetting/src/com/android/fixvibratesetting/FixVibrateSetting.java new file mode 100644 index 0000000..947ea78 --- /dev/null +++ b/tests/FixVibrateSetting/src/com/android/fixvibratesetting/FixVibrateSetting.java @@ -0,0 +1,123 @@ +/* + * Copyright (C) 2008 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 com.android.fixvibratesetting; + +import android.app.Activity; +import android.app.Notification; +import android.app.NotificationManager; +import android.app.PendingIntent; +import android.content.Intent; +import android.media.AudioManager; +import android.util.Log; +import android.view.View; +import android.widget.TextView; +import android.os.Bundle; + +public class FixVibrateSetting extends Activity implements View.OnClickListener +{ + AudioManager mAudioManager; + NotificationManager mNotificationManager; + TextView mCurrentSetting; + View mFix; + View mUnfix; + View mTest; + + @Override + public void onCreate(Bundle icicle) { + super.onCreate(icicle); + + setContentView(R.layout.fix_vibrate); + + mAudioManager = (AudioManager)getSystemService(AUDIO_SERVICE); + mNotificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); + + mCurrentSetting = (TextView)findViewById(R.id.current_setting); + + mFix = findViewById(R.id.fix); + mFix.setOnClickListener(this); + + mUnfix = findViewById(R.id.unfix); + mUnfix.setOnClickListener(this); + + mTest = findViewById(R.id.test); + mTest.setOnClickListener(this); + } + + @Override + public void onResume() { + super.onResume(); + + update(); + } + + private String getSettingValue(int vibrateType) { + int setting = mAudioManager.getVibrateSetting(vibrateType); + switch (setting) { + case AudioManager.VIBRATE_SETTING_OFF: + return "off"; + case AudioManager.VIBRATE_SETTING_ON: + return "on"; + case AudioManager.VIBRATE_SETTING_ONLY_SILENT: + return "silent-only"; + default: + return "unknown"; + } + } + + public void onClick(View v) { + if (v == mFix) { + fix(); + update(); + } else if (v == mUnfix) { + unfix(); + update(); + } else if (v == mTest) { + test(); + update(); + } + } + + private void update() { + String ringer = getSettingValue(AudioManager.VIBRATE_TYPE_RINGER); + String notification = getSettingValue(AudioManager.VIBRATE_TYPE_NOTIFICATION); + String text = getString(R.string.current_setting, ringer, notification); + mCurrentSetting.setText(text); + } + + private void fix() { + mAudioManager.setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION, + AudioManager.VIBRATE_SETTING_ON); + } + + private void unfix() { + mAudioManager.setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION, + AudioManager.VIBRATE_SETTING_OFF); + } + + private void test() { + Notification n = new Notification(R.drawable.stat_sys_warning, "Test notification", + System.currentTimeMillis()); + Intent intent = new Intent(this, FixVibrateSetting.class); + PendingIntent pending = PendingIntent.getActivity(this, 0, intent, 0); + n.setLatestEventInfo(this, "Test notification", "Test notification", pending); + + n.vibrate = new long[] { 0, 700, 500, 1000 }; + n.flags |= Notification.FLAG_AUTO_CANCEL; + mNotificationManager.notify(1, n); + } +} + diff --git a/tests/LargeAssetTest/Android.mk b/tests/LargeAssetTest/Android.mk new file mode 100644 index 0000000..cb7f01b --- /dev/null +++ b/tests/LargeAssetTest/Android.mk @@ -0,0 +1,11 @@ +LOCAL_PATH:= $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_MODULE_TAGS := optional + +LOCAL_SRC_FILES := $(call all-subdir-java-files) + +LOCAL_PACKAGE_NAME := LargeAssetTest +LOCAL_CERTIFICATE := platform + +include $(BUILD_PACKAGE) diff --git a/tests/LargeAssetTest/AndroidManifest.xml b/tests/LargeAssetTest/AndroidManifest.xml new file mode 100644 index 0000000..c86118e --- /dev/null +++ b/tests/LargeAssetTest/AndroidManifest.xml @@ -0,0 +1,28 @@ +<!-- Copyright (C) 2010 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. +--> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.android.largeassettest"> + + <application> + <activity android:name="LargeAssetTest" android:label="Large Asset Test"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="android.intent.category.DEFAULT" /> + <category android:name="android.intent.category.LAUNCHER" /> + </intent-filter> + </activity> + </application> + +</manifest> diff --git a/tests/LargeAssetTest/assets/million-ints b/tests/LargeAssetTest/assets/million-ints Binary files differnew file mode 100644 index 0000000..0607de1 --- /dev/null +++ b/tests/LargeAssetTest/assets/million-ints diff --git a/tests/LargeAssetTest/res/layout/lat.xml b/tests/LargeAssetTest/res/layout/lat.xml new file mode 100644 index 0000000..eda7b82 --- /dev/null +++ b/tests/LargeAssetTest/res/layout/lat.xml @@ -0,0 +1,52 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2010 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. +--> + +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical" + > + + <TextView + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_marginTop="25dp" + android:textColor="#ffffffff" + android:text="@string/prompt" + /> + + <TextView android:id="@+id/result" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_weight="1" + android:layout_marginTop="25dp" + android:textSize="24sp" + android:textColor="#ffffffff" + /> + + <Button android:id="@+id/validate" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/button_text" /> + + <TextView + android:layout_height="wrap_content" + android:layout_width="match_parent" + android:layout_weight="1" + /> +</LinearLayout> + + diff --git a/tests/LargeAssetTest/res/values/strings.xml b/tests/LargeAssetTest/res/values/strings.xml new file mode 100644 index 0000000..54478fa --- /dev/null +++ b/tests/LargeAssetTest/res/values/strings.xml @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2010 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. +--> + +<resources> + + <string name="prompt">Click the button below to read and validate the large binary asset.</string> + <string name="button_text">Validate the asset</string> + +</resources> + diff --git a/tests/LargeAssetTest/src/com/android/largeassettest/LargeAssetTest.java b/tests/LargeAssetTest/src/com/android/largeassettest/LargeAssetTest.java new file mode 100644 index 0000000..e3a9cf4 --- /dev/null +++ b/tests/LargeAssetTest/src/com/android/largeassettest/LargeAssetTest.java @@ -0,0 +1,104 @@ +/* + * Copyright (C) 2006 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 com.android.largeassettest; + +import android.app.Activity; +import android.content.Context; +import android.content.res.AssetManager; +import android.os.AsyncTask; +import android.os.Bundle; +import android.util.Log; +import android.view.View; +import android.widget.Button; +import android.widget.TextView; + +import java.io.InputStream; +import java.io.IOException; + +/** + * Skeleton to test large-asset handling. The asset in question is one million + * four-byte integers, in ascending numeric order. + */ +public class LargeAssetTest extends Activity { + Button mValidateButton; + TextView mResultText; + Validator mValidateThread; + + @Override + protected void onCreate(Bundle icicle) { + super.onCreate(icicle); + setContentView(R.layout.lat); + + mResultText = (TextView) findViewById(R.id.result); + mValidateButton = (Button) findViewById(R.id.validate); + + mValidateButton.setOnClickListener(mClickListener); + } + + View.OnClickListener mClickListener = new View.OnClickListener() { + public void onClick(View v) { + mValidateButton.setEnabled(false); + mValidateThread = new Validator(); + mValidateThread.execute(LargeAssetTest.this.getAssets()); + } + }; + + /** + * Validation happens in a separate thread + */ + class Validator extends AsyncTask<AssetManager, Integer, Boolean> { + static final String TAG = "Validator"; + + @Override + protected Boolean doInBackground(AssetManager... params) { + AssetManager am = params[0]; + try { + InputStream is = am.open("million-ints", AssetManager.ACCESS_STREAMING); + byte[] buf = new byte[4]; + + for (int i = 0; i < 1000000; i++) { + int num = is.read(buf, 0, 4); + if (num != 4) { + Log.e(TAG, "Wanted 4 bytes but read " + num); + return false; + } + // the byte array is stored in the asset in little-endian order + int value = (buf[3] << 24) + ((buf[2] & 0xFF) << 16) + + ((buf[1] & 0xFF) << 8) + (buf[0] & 0xFF); + if (value != i) { + Log.e(TAG, "Mismatch: index " + i + " : value " + value); + return false; + } + } + + is.close(); + } catch (IOException e) { + Log.w(TAG, "Couldn't open asset", e); + return false; + } + Log.i(TAG, "Finished, reporting valid"); + return true; + } + + @Override + protected void onPostExecute(Boolean result) { + CharSequence text = (result) ? "Valid!" : "NOT VALID"; + mResultText.setText(text); + mValidateButton.setEnabled(true); + } + } +} diff --git a/tests/StatusBar/Android.mk b/tests/StatusBar/Android.mk index 18fcad0..502657f 100644 --- a/tests/StatusBar/Android.mk +++ b/tests/StatusBar/Android.mk @@ -8,4 +8,6 @@ LOCAL_SRC_FILES := $(call all-subdir-java-files) LOCAL_PACKAGE_NAME := StatusBarTest LOCAL_CERTIFICATE := platform +LOCAL_PROGUARD_ENABLED := disabled + include $(BUILD_PACKAGE) diff --git a/tests/StatusBar/AndroidManifest.xml b/tests/StatusBar/AndroidManifest.xml index 21fb951..c1ca618 100644 --- a/tests/StatusBar/AndroidManifest.xml +++ b/tests/StatusBar/AndroidManifest.xml @@ -35,5 +35,7 @@ <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> + <activity android:name="TestAlertActivity" android:theme="@android:style/Theme.Dialog"> + </activity> </application> </manifest> diff --git a/tests/StatusBar/res/drawable-hdpi/stat_sys_phone.png b/tests/StatusBar/res/drawable-hdpi/stat_sys_phone.png Binary files differnew file mode 100644 index 0000000..9815553 --- /dev/null +++ b/tests/StatusBar/res/drawable-hdpi/stat_sys_phone.png diff --git a/tests/StatusBar/res/drawable-mdpi/stat_sys_phone.png b/tests/StatusBar/res/drawable-mdpi/stat_sys_phone.png Binary files differnew file mode 100644 index 0000000..402abc7 --- /dev/null +++ b/tests/StatusBar/res/drawable-mdpi/stat_sys_phone.png diff --git a/tests/StatusBar/res/layout/test_alert.xml b/tests/StatusBar/res/layout/test_alert.xml new file mode 100644 index 0000000..325146c --- /dev/null +++ b/tests/StatusBar/res/layout/test_alert.xml @@ -0,0 +1,57 @@ +<?xml version="1.0" encoding="utf-8"?> +<LinearLayout + xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:gravity="center"> + + <LinearLayout + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center" + android:gravity="center_horizontal" + android:orientation="vertical" + > + + <TextView android:id="@+id/alertTitle" + style="?android:attr/textAppearanceLarge" + android:padding="5dip" + android:singleLine="true" + android:ellipsize="end" + android:gravity="center" + android:layout_width="match_parent" + android:layout_height="wrap_content" /> + + <LinearLayout + android:layout_width="wrap_content" + android:layout_height="wrap_content" + style="@android:style/ButtonBar"> + + <Button + android:id="@+id/snooze" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_weight="3" + android:onClick="dismiss" + android:text="Snooze" /> + + <!-- blank stretchable view --> + <View + android:layout_width="2dip" + android:layout_height="2dip" + android:layout_gravity="fill_horizontal" + android:layout_weight="1"/> + + <Button + android:id="@+id/dismiss" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_weight="3" + android:onClick="dismiss" + android:text="Dismiss" /> + + </LinearLayout> + + </LinearLayout> + +</LinearLayout> diff --git a/tests/StatusBar/src/com/android/statusbartest/NotificationTestList.java b/tests/StatusBar/src/com/android/statusbartest/NotificationTestList.java index 9ed5156..37976ee 100644 --- a/tests/StatusBar/src/com/android/statusbartest/NotificationTestList.java +++ b/tests/StatusBar/src/com/android/statusbartest/NotificationTestList.java @@ -39,6 +39,7 @@ public class NotificationTestList extends TestActivity Vibrator mVibrator = new Vibrator(); Handler mHandler = new Handler(); + long mActivityCreateTime = System.currentTimeMillis(); long mChronometerBase = 0; @Override @@ -118,19 +119,49 @@ public class NotificationTestList extends TestActivity } }, - new Test("Bad resource #2") { - public void run() - { - Notification n = new Notification(NotificationTestList.this, - R.drawable.ic_statusbar_missedcall, - null, System.currentTimeMillis()-(1000*60*60*24), - "(453) 123-2328", - "", null); + new Test("Bad Icon #1 (when=create)") { + public void run() { + Notification n = new Notification(R.layout.chrono_notification /* not an icon */, + null, mActivityCreateTime); + n.setLatestEventInfo(NotificationTestList.this, "Persistent #1", + "This is the same notification!!!", makeIntent()); + mNM.notify(1, n); + } + }, + + new Test("Bad Icon #1 (when=now)") { + public void run() { + Notification n = new Notification(R.layout.chrono_notification /* not an icon */, + null, System.currentTimeMillis()); + n.setLatestEventInfo(NotificationTestList.this, "Persistent #1", + "This is the same notification!!!", makeIntent()); + mNM.notify(1, n); + } + }, + + new Test("Bad resource #1 (when=create)") { + public void run() { + Notification n = new Notification(R.drawable.icon2, + null, mActivityCreateTime); + n.setLatestEventInfo(NotificationTestList.this, "Persistent #1", + "This is the same notification!!!", makeIntent()); n.contentView.setInt(1 /*bogus*/, "bogus method", 666); - mNM.notify(2, n); + mNM.notify(1, n); } }, + new Test("Bad resource #1 (when=now)") { + public void run() { + Notification n = new Notification(R.drawable.icon2, + null, System.currentTimeMillis()); + n.setLatestEventInfo(NotificationTestList.this, "Persistent #1", + "This is the same notification!!!", makeIntent()); + n.contentView.setInt(1 /*bogus*/, "bogus method", 666); + mNM.notify(1, n); + } + }, + + new Test("Bad resource #3") { public void run() { @@ -177,7 +208,7 @@ public class NotificationTestList extends TestActivity R.drawable.icon4, null, System.currentTimeMillis(), "Stress - Latest", "Notify me!!!", null); - n.flags |= Notification.FLAG_ONGOING_EVENT; + //n.flags |= Notification.FLAG_ONGOING_EVENT; mNM.notify(1, n); } } @@ -407,7 +438,7 @@ public class NotificationTestList extends TestActivity new Test("Persistent #1") { public void run() { Notification n = new Notification(R.drawable.icon1, "tick tick tick", - System.currentTimeMillis()); + mActivityCreateTime); n.setLatestEventInfo(NotificationTestList.this, "Persistent #1", "This is a notification!!!", makeIntent()); mNM.notify(1, n); @@ -467,6 +498,16 @@ public class NotificationTestList extends TestActivity } }, + new Test("Persistent #1 - different icon") { + public void run() { + Notification n = new Notification(R.drawable.icon2, null, + mActivityCreateTime); + n.setLatestEventInfo(NotificationTestList.this, "Persistent #1", + "This is the same notification!!!", makeIntent()); + mNM.notify(1, n); + } + }, + new Test("Chronometer Start") { public void run() { Notification n = new Notification(R.drawable.icon2, "me me me me", @@ -592,6 +633,20 @@ public class NotificationTestList extends TestActivity } }, + new Test("Ticker") { + public void run() { + Notification not = new Notification( + R.drawable.app_gmail, + "New mail from joeo@example.com, on the topic of very long ticker texts", + System.currentTimeMillis()); + not.setLatestEventInfo(NotificationTestList.this, + "A new message awaits", + "The contents are very interesting and important", + makeIntent()); + mNM.notify(1, not); + } + }, + new Test("Crash") { public void run() { @@ -619,9 +674,7 @@ public class NotificationTestList extends TestActivity private PendingIntent makeIntent() { Intent intent = new Intent(Intent.ACTION_MAIN); - intent.setComponent(new android.content.ComponentName( - "com.android.contacts", - "com.android.contacts.ContactsActivity")); + intent.addCategory(Intent.CATEGORY_HOME); return PendingIntent.getActivity(this, 0, intent, 0); } diff --git a/tests/StatusBar/src/com/android/statusbartest/StatusBarTest.java b/tests/StatusBar/src/com/android/statusbartest/StatusBarTest.java index 06506fb..b665d2f 100644 --- a/tests/StatusBar/src/com/android/statusbartest/StatusBarTest.java +++ b/tests/StatusBar/src/com/android/statusbartest/StatusBarTest.java @@ -23,6 +23,7 @@ import android.widget.ArrayAdapter; import android.view.View; import android.widget.ListView; import android.content.Intent; +import android.app.PendingIntent; import android.app.Notification; import android.app.NotificationManager; import android.app.StatusBarManager; @@ -35,6 +36,8 @@ import android.os.SystemClock; import android.widget.RemoteViews; import android.widget.Toast; import android.os.PowerManager; +import android.view.Window; +import android.view.WindowManager; public class StatusBarTest extends TestActivity { @@ -57,6 +60,56 @@ public class StatusBarTest extends TestActivity } private Test[] mTests = new Test[] { + new Test("Hide") { + public void run() { + Window win = getWindow(); + WindowManager.LayoutParams winParams = win.getAttributes(); + winParams.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN; + win.setAttributes(winParams); + } + }, + new Test("Show") { + public void run() { + Window win = getWindow(); + WindowManager.LayoutParams winParams = win.getAttributes(); + winParams.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN; + win.setAttributes(winParams); + } + }, + new Test("Immersive: Enter") { + public void run() { + setImmersive(true); + } + }, + new Test("Immersive: Exit") { + public void run() { + setImmersive(false); + } + }, + new Test("Priority notification") { + public void run() { + Notification not = new Notification(StatusBarTest.this, + R.drawable.stat_sys_phone, + "Incoming call from: Imperious Leader", + System.currentTimeMillis()-(1000*60*60*24), + "Imperious Leader", + "(888) 555-5038", + null + ); + not.flags |= Notification.FLAG_HIGH_PRIORITY; + Intent fullScreenIntent = new Intent(StatusBarTest.this, TestAlertActivity.class); + int id = (int)System.currentTimeMillis(); // XXX HAX + fullScreenIntent.putExtra("id", id); + not.fullScreenIntent = PendingIntent.getActivity( + StatusBarTest.this, + 0, + fullScreenIntent, + PendingIntent.FLAG_CANCEL_CURRENT); + // if you tap on it you should get the original alert box + not.contentIntent = not.fullScreenIntent; + mNotificationManager.notify(id, not); + } + }, new Test("Disable Alerts") { public void run() { mStatusBarManager.disable(StatusBarManager.DISABLE_NOTIFICATION_ALERTS); @@ -134,13 +187,9 @@ public class StatusBarTest extends TestActivity }, 3000); } }, - new Test("Expand in 3 sec.") { + new Test("Expand") { public void run() { - mHandler.postDelayed(new Runnable() { - public void run() { - mStatusBarManager.expand(); - } - }, 3000); + mStatusBarManager.expand(); } }, new Test("Expand in 3 sec.") { @@ -161,13 +210,21 @@ public class StatusBarTest extends TestActivity }, 3000); } }, - new Test("Toggle in 3 sec.") { + new Test("More icons") { public void run() { - mHandler.postDelayed(new Runnable() { - public void run() { - mStatusBarManager.toggle(); - } - }, 3000); + for (String slot: new String[] { + "sync_failing", + "gps", + "bluetooth", + "tty", + "speakerphone", + "mute", + "wifi", + "alarm_clock", + "secure", + }) { + mStatusBarManager.setIconVisibility(slot, true); + } } }, }; diff --git a/tests/StatusBar/src/com/android/statusbartest/TestAlertActivity.java b/tests/StatusBar/src/com/android/statusbartest/TestAlertActivity.java new file mode 100644 index 0000000..f5876d0 --- /dev/null +++ b/tests/StatusBar/src/com/android/statusbartest/TestAlertActivity.java @@ -0,0 +1,37 @@ +package com.android.statusbartest; + +import android.app.Activity; +import android.app.NotificationManager; +import android.content.Intent; +import android.os.Bundle; +import android.util.Log; +import android.view.View; + +public class TestAlertActivity extends Activity { + int mId; + + @Override + public void onResume() { + super.onResume(); + Log.d("StatusBarTest", "TestAlertActivity.onResume"); + Intent intent = getIntent(); + mId = intent.getIntExtra("id", -1); + Log.d("StatusBarTest", "Remembering notification id=" + mId); + setContentView(R.layout.test_alert); + } + + @Override + public void onPause() { + super.onPause(); + Log.d("StatusBarTest", "onPause: Canceling notification id=" + mId); + NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); + nm.cancel(mId); + finish(); + } + + @SuppressWarnings({"UnusedDeclaration"}) + public void dismiss(View v) { + Log.d("StatusBarTest", "TestAlertActivity.dismiss"); + finish(); + } +} diff --git a/tests/appwidgets/AppWidgetProviderTest/res/layout/test_appwidget2.xml b/tests/appwidgets/AppWidgetProviderTest/res/layout/test_appwidget2.xml new file mode 100644 index 0000000..abc6f59 --- /dev/null +++ b/tests/appwidgets/AppWidgetProviderTest/res/layout/test_appwidget2.xml @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2006 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. +--> + +<TextView xmlns:android="http://schemas.android.com/apk/res/android" + android:id="@+id/oh_hai_text" + android:layout_width="150dp" + android:layout_height="150dp" + android:text="@string/appwidget_view_title" + android:background="#8fff" + android:textColor="#000" + android:textStyle="bold" +/> + diff --git a/tests/appwidgets/AppWidgetProviderTest/src/com/android/tests/appwidgetprovider/TestAppWidgetProvider.java b/tests/appwidgets/AppWidgetProviderTest/src/com/android/tests/appwidgetprovider/TestAppWidgetProvider.java index 418be65..d9c0110 100644 --- a/tests/appwidgets/AppWidgetProviderTest/src/com/android/tests/appwidgetprovider/TestAppWidgetProvider.java +++ b/tests/appwidgets/AppWidgetProviderTest/src/com/android/tests/appwidgetprovider/TestAppWidgetProvider.java @@ -41,6 +41,7 @@ public class TestAppWidgetProvider extends BroadcastReceiver { Log.d(TAG, "DISABLED"); } else if (AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(action)) { + if (true) return; Log.d(TAG, "UPDATE"); Bundle extras = intent.getExtras(); int[] appWidgetIds = extras.getIntArray(AppWidgetManager.EXTRA_APPWIDGET_IDS); diff --git a/tests/framework-tests/Android.mk b/tests/framework-tests/Android.mk deleted file mode 100644 index 5053e7d..0000000 --- a/tests/framework-tests/Android.mk +++ /dev/null @@ -1 +0,0 @@ -include $(call all-subdir-makefiles) diff --git a/tests/framework-tests/README b/tests/framework-tests/README deleted file mode 100644 index 7b46b25..0000000 --- a/tests/framework-tests/README +++ /dev/null @@ -1,5 +0,0 @@ -This package contains tests which need to access package-private members in the framework code. -To do this, the tests must be loaded in the same class loader as the classes which they are -testing. This package is loaded in the boot classpath. - -Run these tests via AndroidTests -> FrameworkTests. diff --git a/tests/framework-tests/src/Android.mk b/tests/framework-tests/src/Android.mk deleted file mode 100644 index 54e33a4..0000000 --- a/tests/framework-tests/src/Android.mk +++ /dev/null @@ -1,10 +0,0 @@ -LOCAL_PATH := $(call my-dir) -include $(CLEAR_VARS) - -LOCAL_SRC_FILES := $(call all-subdir-java-files) - -LOCAL_MODULE := framework-tests - -LOCAL_JAVA_LIBRARIES := android.policy_phone android.test.runner - -include $(BUILD_JAVA_LIBRARY) diff --git a/tests/framework-tests/src/android/test/FrameworkTests.java b/tests/framework-tests/src/android/test/FrameworkTests.java deleted file mode 100644 index cb3f493..0000000 --- a/tests/framework-tests/src/android/test/FrameworkTests.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (C) 2007 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.test; - -import com.android.internal.os.LoggingPrintStreamTest; -import junit.framework.TestSuite; -import com.android.internal.http.multipart.MultipartTest; -import com.android.internal.policy.impl.LockPatternKeyguardViewTest; - -/** - * Tests that are loaded in the boot classpath along with the Android framework - * classes. This enables you to access package-private members in the framework - * classes; doing so is not possible when the test classes are loaded in an - * application classloader. - */ -public class FrameworkTests { - public static TestSuite suite() { - TestSuite suite = new TestSuite(FrameworkTests.class.getName()); - - suite.addTestSuite(MultipartTest.class); - suite.addTestSuite(LoggingPrintStreamTest.class); - suite.addTestSuite(LockPatternKeyguardViewTest.class); - - return suite; - } -} diff --git a/tests/framework-tests/src/android/text/PackedIntVectorTest.java b/tests/framework-tests/src/android/text/PackedIntVectorTest.java deleted file mode 100644 index 78cdee9..0000000 --- a/tests/framework-tests/src/android/text/PackedIntVectorTest.java +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright (C) 2007 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.text; - -import android.text.PackedIntVector; -import junit.framework.TestCase; - -/** - * PackedIntVectorTest tests the features of android.util.PackedIntVector. - */ -public class PackedIntVectorTest extends TestCase { - - public void testBasic() throws Exception { - for (int width = 0; width < 10; width++) { - PackedIntVector p = new PackedIntVector(width); - int[] ins = new int[width]; - - for (int height = width * 2; height < width * 4; height++) { - assertEquals(p.width(), width); - - // Test adding rows. - - for (int i = 0; i < height; i++) { - int at; - - if (i % 2 == 0) { - at = i; - } else { - at = p.size() - i; - } - - for (int j = 0; j < width; j++) { - ins[j] = i + j; - } - - if (i == height / 2) { - p.insertAt(at, null); - } else { - p.insertAt(at, ins); - } - - assertEquals(p.size(), i + 1); - - for (int j = 0; j < width; j++) { - if (i == height / 2) { - assertEquals(0, p.getValue(at, j)); - } else { - assertEquals(p.getValue(at, j), i + j); - } - } - } - - // Test setting values. - - for (int i = 0; i < height; i++) { - for (int j = 0; j < width; j++) { - p.setValue(i, j, i * j); - - assertEquals(p.getValue(i, j), i * j); - } - } - - // Test offsetting values. - - for (int j = 0; j < width; j++) { - p.adjustValuesBelow(j * 2, j, j + 27); - } - - for (int i = 0; i < height; i++) { - for (int j = 0; j < width; j++) { - int expect = i * j; - - if (i >= j * 2) { - expect += j + 27; - } - - assertEquals(p.getValue(i, j), expect); - } - } - - for (int j = 0; j < width; j++) { - p.adjustValuesBelow(j, j, j * j + 14); - } - - for (int i = 0; i < height; i++) { - for (int j = 0; j < width; j++) { - int expect = i * j; - - if (i >= j * 2) { - expect += j + 27; - } - if (i >= j) { - expect += j * j + 14; - } - - assertEquals(p.getValue(i, j), expect); - } - } - - // Test undoing offsets. - - for (int j = 0; j < width; j++) { - p.adjustValuesBelow(j * 2, j, -(j + 27)); - p.adjustValuesBelow(j, j, -(j * j + 14)); - } - - for (int i = 0; i < height; i++) { - for (int j = 0; j < width; j++) { - assertEquals(p.getValue(i, j), i * j); - } - } - - // Test deleting rows. - - while (p.size() > 0) { - int osize = p.size(); - int del = osize / 3; - - if (del == 0) { - del = 1; - } - - int at = (osize - del) / 2; - p.deleteAt(at, del); - - assertEquals(p.size(), osize - del); - - for (int i = 0; i < at; i++) { - for (int j = 0; j < width; j++) { - assertEquals(p.getValue(i, j), i * j); - } - } - - for (int i = at; i < p.size(); i++) { - for (int j = 0; j < width; j++) { - assertEquals(p.getValue(i, j), (i + height - p.size()) * j); - } - } - } - - assertEquals(0, p.size()); - } - } - } -} diff --git a/tests/framework-tests/src/com/android/internal/http/multipart/MultipartTest.java b/tests/framework-tests/src/com/android/internal/http/multipart/MultipartTest.java deleted file mode 100644 index 32e13a7..0000000 --- a/tests/framework-tests/src/com/android/internal/http/multipart/MultipartTest.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (C) 2008 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 com.android.internal.http.multipart; - -import junit.framework.TestCase; -import org.apache.http.Header; -import org.apache.http.util.EncodingUtils; - -import java.io.BufferedWriter; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileWriter; - -public class MultipartTest extends TestCase { - - public void testParts() throws Exception { - StringBuffer filebuffer = new StringBuffer(); - String filepartStr = "this is file part"; - filebuffer.append(filepartStr); - File upload = File.createTempFile("Multipart", "test"); - - FileWriter outFile = new FileWriter(upload); - BufferedWriter out = new BufferedWriter(outFile); - try { - out.write(filebuffer.toString()); - out.flush(); - } finally { - out.close(); - } - - Part[] parts = new Part[3]; - parts[0] = new StringPart("stringpart", "PART1!!"); - parts[1] = new FilePart(upload.getName(), upload); - parts[2] = new StringPart("stringpart", "PART2!!"); - - MultipartEntity me = new MultipartEntity(parts); - ByteArrayOutputStream os = new ByteArrayOutputStream(); - me.writeTo(os); - Header h = me.getContentType(); - String boundry = EncodingUtils.getAsciiString(me.getMultipartBoundary()); - StringBuffer contentType = new StringBuffer("multipart/form-data"); - contentType.append("; boundary="); - contentType.append(boundry); - assertEquals("Multipart content type error", contentType.toString(), h.getValue()); - final String CRLF = "\r\n"; - StringBuffer output = new StringBuffer(); - - output.append("--"); - output.append(boundry); - output.append(CRLF); - - output.append("Content-Disposition: form-data; name=\"stringpart\""); - output.append(CRLF); - output.append("Content-Type: text/plain; charset=US-ASCII"); - output.append(CRLF); - output.append("Content-Transfer-Encoding: 8bit"); - output.append(CRLF); - output.append(CRLF); - output.append("PART1!!"); - output.append(CRLF); - - output.append("--"); - output.append(boundry); - output.append(CRLF); - - output.append("Content-Disposition: form-data; name=\""); - output.append(upload.getName()); - output.append("\"; filename=\""); - output.append(upload.getName()); - output.append("\""); - - output.append(CRLF); - output.append("Content-Type: application/octet-stream; charset=ISO-8859-1"); - output.append(CRLF); - output.append("Content-Transfer-Encoding: binary"); - output.append(CRLF); - output.append(CRLF); - output.append(filepartStr); - output.append(CRLF); - - output.append("--"); - output.append(boundry); - output.append(CRLF); - - output.append("Content-Disposition: form-data; name=\"stringpart\""); - output.append(CRLF); - output.append("Content-Type: text/plain; charset=US-ASCII"); - output.append(CRLF); - output.append("Content-Transfer-Encoding: 8bit"); - output.append(CRLF); - output.append(CRLF); - output.append("PART2!!"); - output.append(CRLF); - - output.append("--"); - output.append(boundry); - output.append("--"); - output.append(CRLF); - // System.out.print(output.toString()); - assertEquals("Multipart content error", output.toString(), os.toString()); - - // System.out.print(os.toString()); - } -} diff --git a/tests/framework-tests/src/com/android/internal/os/LoggingPrintStreamTest.java b/tests/framework-tests/src/com/android/internal/os/LoggingPrintStreamTest.java deleted file mode 100644 index 4d016d1..0000000 --- a/tests/framework-tests/src/com/android/internal/os/LoggingPrintStreamTest.java +++ /dev/null @@ -1,184 +0,0 @@ -/* - * Copyright (C) 2008 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 com.android.internal.os; - -import junit.framework.TestCase; - -import java.io.PrintWriter; -import java.io.StringWriter; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -public class LoggingPrintStreamTest extends TestCase { - - TestPrintStream out = new TestPrintStream(); - - public void testPrintException() { - @SuppressWarnings("ThrowableInstanceNeverThrown") - Throwable t = new Throwable("Ignore me."); - - StringWriter sout = new StringWriter(); - t.printStackTrace(new PrintWriter(sout)); - - t.printStackTrace(out); - // t.printStackTrace(); - - String[] lines = sout.toString().split("\\n"); - assertEquals(Arrays.asList(lines), out.lines); - } - - public void testPrintObject() { - Object o = new Object(); - out.print(4); - out.print(o); - out.print(2); - out.flush(); - assertEquals(Arrays.asList("4" + o + "2"), out.lines); - } - - public void testPrintlnObject() { - Object o = new Object(); - out.print(4); - out.println(o); - out.print(2); - out.flush(); - assertEquals(Arrays.asList("4" + o, "2"), out.lines); - } - - public void testPrintf() { - out.printf("Name: %s\nEmployer: %s", "Bob", "Google"); - assertEquals(Arrays.asList("Name: Bob"), out.lines); - out.flush(); - assertEquals(Arrays.asList("Name: Bob", "Employer: Google"), out.lines); - } - - public void testPrintInt() { - out.print(4); - out.print(2); - assertTrue(out.lines.isEmpty()); - out.flush(); - assertEquals(Collections.singletonList("42"), out.lines); - } - - public void testPrintlnInt() { - out.println(4); - out.println(2); - assertEquals(Arrays.asList("4", "2"), out.lines); - } - - public void testPrintCharArray() { - out.print("Foo\nBar\nTee".toCharArray()); - assertEquals(Arrays.asList("Foo", "Bar"), out.lines); - out.flush(); - assertEquals(Arrays.asList("Foo", "Bar", "Tee"), out.lines); - } - - public void testPrintString() { - out.print("Foo\nBar\nTee"); - assertEquals(Arrays.asList("Foo", "Bar"), out.lines); - out.flush(); - assertEquals(Arrays.asList("Foo", "Bar", "Tee"), out.lines); - } - - public void testPrintlnCharArray() { - out.println("Foo\nBar\nTee".toCharArray()); - assertEquals(Arrays.asList("Foo", "Bar", "Tee"), out.lines); - } - - public void testPrintlnString() { - out.println("Foo\nBar\nTee"); - assertEquals(Arrays.asList("Foo", "Bar", "Tee"), out.lines); - } - - public void testPrintlnStringWithBufferedData() { - out.print(5); - out.println("Foo\nBar\nTee"); - assertEquals(Arrays.asList("5Foo", "Bar", "Tee"), out.lines); - } - - public void testAppend() { - out.append("Foo\n") - .append('4') - .append('\n') - .append("Bar", 1, 2) - .append('\n'); - assertEquals(Arrays.asList("Foo", "4", "a"), out.lines); - } - - public void testMultiByteCharactersSpanningBuffers() throws Exception { - // assume 3*1000 bytes won't fit in LoggingPrintStream's internal buffer - StringBuilder builder = new StringBuilder(); - for (int i = 0; i < 1000; i++) { - builder.append("\u20AC"); // a Euro character; 3 bytes in UTF-8 - } - String expected = builder.toString(); - - out.write(expected.getBytes("UTF-8")); - out.flush(); - assertEquals(Arrays.asList(expected), out.lines); - } - - public void testWriteOneByteAtATimeMultibyteCharacters() throws Exception { - String expected = " \u20AC \u20AC \u20AC \u20AC "; - for (byte b : expected.getBytes()) { - out.write(b); - } - out.flush(); - assertEquals(Arrays.asList(expected), out.lines); - } - - public void testWriteByteArrayAtATimeMultibyteCharacters() throws Exception { - String expected = " \u20AC \u20AC \u20AC \u20AC "; - out.write(expected.getBytes()); - out.flush(); - assertEquals(Arrays.asList(expected), out.lines); - } - - public void testWriteWithOffsetsMultibyteCharacters() throws Exception { - String expected = " \u20AC \u20AC \u20AC \u20AC "; - byte[] bytes = expected.getBytes(); - int i = 0; - while (i < bytes.length - 5) { - out.write(bytes, i, 5); - i += 5; - } - out.write(bytes, i, bytes.length - i); - out.flush(); - assertEquals(Arrays.asList(expected), out.lines); - } - - public void testWriteFlushesOnNewlines() throws Exception { - String a = " \u20AC \u20AC "; - String b = " \u20AC \u20AC "; - String c = " "; - String toWrite = a + "\n" + b + "\n" + c; - out.write(toWrite.getBytes()); - out.flush(); - assertEquals(Arrays.asList(a, b, c), out.lines); - } - - static class TestPrintStream extends LoggingPrintStream { - - final List<String> lines = new ArrayList<String>(); - - protected void log(String line) { - lines.add(line); - } - } -} diff --git a/tests/framework-tests/src/com/android/internal/policy/impl/LockPatternKeyguardViewTest.java b/tests/framework-tests/src/com/android/internal/policy/impl/LockPatternKeyguardViewTest.java deleted file mode 100644 index 1e57bd2..0000000 --- a/tests/framework-tests/src/com/android/internal/policy/impl/LockPatternKeyguardViewTest.java +++ /dev/null @@ -1,350 +0,0 @@ -/* - * Copyright (C) 2008 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 com.android.internal.policy.impl; - -import android.content.Context; -import com.android.internal.telephony.IccCard; -import android.content.res.Configuration; -import android.test.AndroidTestCase; -import android.view.View; -import android.view.KeyEvent; -import com.android.internal.widget.LockPatternUtils; -import com.google.android.collect.Lists; - -import java.util.List; - -/** - * Tests for {@link com.android.internal.policy.impl.LockPatternKeyguardView}, - * which handles the management of screens while the keyguard is showing. - */ -public class LockPatternKeyguardViewTest extends AndroidTestCase { - private MockUpdateMonitor mUpdateMonitor; - private LockPatternUtils mLockPatternUtils; - private TestableLockPatternKeyguardView mLPKV; - private MockKeyguardCallback mKeyguardViewCallback; - - private static class MockUpdateMonitor extends KeyguardUpdateMonitor { - - public IccCard.State simState = IccCard.State.READY; - - private MockUpdateMonitor(Context context) { - super(context); - } - - @Override - public IccCard.State getSimState() { - return simState; - } - } - - private static class MockLockPatternUtils extends LockPatternUtils { - boolean isLockPatternEnabled = true; - public boolean isPermanentlyLocked = false; - - public MockLockPatternUtils() { - super(null); - } - - @Override - public boolean isLockPatternEnabled() { - return isLockPatternEnabled; - } - - @Override - public void setLockPatternEnabled(boolean lockPatternEnabled) { - isLockPatternEnabled = lockPatternEnabled; - } - - @Override - public boolean isPermanentlyLocked() { - return isPermanentlyLocked; - } - - public void setPermanentlyLocked(boolean permanentlyLocked) { - isPermanentlyLocked = permanentlyLocked; - } - } - - private static class MockKeyguardScreen extends View implements KeyguardScreen { - - private int mOnPauseCount = 0; - private int mOnResumeCount = 0; - private int mCleanupCount = 0; - - private MockKeyguardScreen(Context context) { - super(context); - setFocusable(true); - } - - /** {@inheritDoc} */ - public boolean needsInput() { - return false; - } - - /** {@inheritDoc} */ - public void onPause() { - mOnPauseCount++; - } - - /** {@inheritDoc} */ - public void onResume() { - mOnResumeCount++; - } - - /** {@inheritDoc} */ - public void cleanUp() { - mCleanupCount++; - } - - public int getOnPauseCount() { - return mOnPauseCount; - } - - public int getOnResumeCount() { - return mOnResumeCount; - } - - public int getCleanupCount() { - return mCleanupCount; - } - } - - /** - * Allows us to inject the lock and unlock views to simulate their behavior - * and detect their creation. - */ - private static class TestableLockPatternKeyguardView extends LockPatternKeyguardView { - private List<MockKeyguardScreen> mInjectedLockScreens; - private List<MockKeyguardScreen> mInjectedUnlockScreens; - - - - private TestableLockPatternKeyguardView(Context context, KeyguardUpdateMonitor updateMonitor, - LockPatternUtils lockPatternUtils, KeyguardWindowController controller) { - super(context, updateMonitor, lockPatternUtils, controller); - } - - @Override - View createLockScreen() { - final MockKeyguardScreen newView = new MockKeyguardScreen(getContext()); - if (mInjectedLockScreens == null) mInjectedLockScreens = Lists.newArrayList(); - mInjectedLockScreens.add(newView); - return newView; - } - - @Override - View createUnlockScreenFor(UnlockMode unlockMode) { - final MockKeyguardScreen newView = new MockKeyguardScreen(getContext()); - if (mInjectedUnlockScreens == null) mInjectedUnlockScreens = Lists.newArrayList(); - mInjectedUnlockScreens.add(newView); - return newView; - } - - public List<MockKeyguardScreen> getInjectedLockScreens() { - return mInjectedLockScreens; - } - - public List<MockKeyguardScreen> getInjectedUnlockScreens() { - return mInjectedUnlockScreens; - } - } - - private static class MockKeyguardCallback implements KeyguardViewCallback { - - private int mPokeWakelockCount = 0; - private int mKeyguardDoneCount = 0; - - public void pokeWakelock() { - mPokeWakelockCount++; - } - - public void pokeWakelock(int millis) { - mPokeWakelockCount++; - } - - public void keyguardDone(boolean authenticated) { - mKeyguardDoneCount++; - } - - public void keyguardDoneDrawing() { - - } - - public int getPokeWakelockCount() { - return mPokeWakelockCount; - } - - public int getKeyguardDoneCount() { - return mKeyguardDoneCount; - } - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - mUpdateMonitor = new MockUpdateMonitor(getContext()); - mLockPatternUtils = new MockLockPatternUtils(); - - mLPKV = new TestableLockPatternKeyguardView(getContext(), mUpdateMonitor, - mLockPatternUtils, new KeyguardWindowController() { - public void setNeedsInput(boolean needsInput) { - } - }); - mKeyguardViewCallback = new MockKeyguardCallback(); - mLPKV.setCallback(mKeyguardViewCallback); - } - - public void testStateAfterCreatedWhileScreenOff() { - - assertEquals(1, mLPKV.getInjectedLockScreens().size()); - assertEquals(1, mLPKV.getInjectedUnlockScreens().size()); - - MockKeyguardScreen lockScreen = mLPKV.getInjectedLockScreens().get(0); - MockKeyguardScreen unlockScreen = mLPKV.getInjectedUnlockScreens().get(0); - - assertEquals(0, lockScreen.getOnPauseCount()); - assertEquals(0, lockScreen.getOnResumeCount()); - assertEquals(0, lockScreen.getCleanupCount()); - - assertEquals(0, unlockScreen.getOnPauseCount()); - assertEquals(0, unlockScreen.getOnResumeCount()); - assertEquals(0, unlockScreen.getCleanupCount()); - - assertEquals(0, mKeyguardViewCallback.getPokeWakelockCount()); - assertEquals(0, mKeyguardViewCallback.getKeyguardDoneCount()); - } - - public void testWokenByNonMenuKey() { - mLPKV.wakeWhenReadyTq(0); - - // should have poked the wakelock to turn on the screen - assertEquals(1, mKeyguardViewCallback.getPokeWakelockCount()); - - // shouldn't be any additional views created - assertEquals(1, mLPKV.getInjectedLockScreens().size()); - assertEquals(1, mLPKV.getInjectedUnlockScreens().size()); - MockKeyguardScreen lockScreen = mLPKV.getInjectedLockScreens().get(0); - MockKeyguardScreen unlockScreen = mLPKV.getInjectedUnlockScreens().get(0); - - // lock screen should be only visible one - assertEquals(View.VISIBLE, lockScreen.getVisibility()); - assertEquals(View.GONE, unlockScreen.getVisibility()); - - // on resume not called until screen turns on - assertEquals(0, lockScreen.getOnPauseCount()); - assertEquals(0, lockScreen.getOnResumeCount()); - assertEquals(0, lockScreen.getCleanupCount()); - - assertEquals(0, unlockScreen.getOnPauseCount()); - assertEquals(0, unlockScreen.getOnResumeCount()); - assertEquals(0, unlockScreen.getCleanupCount()); - - // simulate screen turning on - mLPKV.onScreenTurnedOn(); - - assertEquals(0, lockScreen.getOnPauseCount()); - assertEquals(1, lockScreen.getOnResumeCount()); - assertEquals(0, lockScreen.getCleanupCount()); - - assertEquals(0, unlockScreen.getOnPauseCount()); - assertEquals(0, unlockScreen.getOnResumeCount()); - assertEquals(0, unlockScreen.getCleanupCount()); - } - - public void testWokenByMenuKeyWhenPatternSet() { - assertEquals(true, mLockPatternUtils.isLockPatternEnabled()); - - mLPKV.wakeWhenReadyTq(KeyEvent.KEYCODE_MENU); - - // should have poked the wakelock to turn on the screen - assertEquals(1, mKeyguardViewCallback.getPokeWakelockCount()); - - // shouldn't be any additional views created - assertEquals(1, mLPKV.getInjectedLockScreens().size()); - assertEquals(1, mLPKV.getInjectedUnlockScreens().size()); - MockKeyguardScreen lockScreen = mLPKV.getInjectedLockScreens().get(0); - MockKeyguardScreen unlockScreen = mLPKV.getInjectedUnlockScreens().get(0); - - // unlock screen should be only visible one - assertEquals(View.GONE, lockScreen.getVisibility()); - assertEquals(View.VISIBLE, unlockScreen.getVisibility()); - } - - public void testScreenRequestsRecreation() { - mLPKV.wakeWhenReadyTq(0); - mLPKV.onScreenTurnedOn(); - - assertEquals(1, mLPKV.getInjectedLockScreens().size()); - assertEquals(1, mLPKV.getInjectedUnlockScreens().size()); - MockKeyguardScreen lockScreen = mLPKV.getInjectedLockScreens().get(0); - - assertEquals(0, lockScreen.getOnPauseCount()); - assertEquals(1, lockScreen.getOnResumeCount()); - - // simulate screen asking to be recreated - mLPKV.mKeyguardScreenCallback.recreateMe(new Configuration()); - - // should have been recreated - assertEquals(2, mLPKV.getInjectedLockScreens().size()); - assertEquals(2, mLPKV.getInjectedUnlockScreens().size()); - - // both old screens should have been cleaned up - assertEquals(1, mLPKV.getInjectedLockScreens().get(0).getCleanupCount()); - assertEquals(1, mLPKV.getInjectedUnlockScreens().get(0).getCleanupCount()); - - // old lock screen should have been paused - assertEquals(1, mLPKV.getInjectedLockScreens().get(0).getOnPauseCount()); - assertEquals(0, mLPKV.getInjectedUnlockScreens().get(0).getOnPauseCount()); - - // new lock screen should have been resumed - assertEquals(1, mLPKV.getInjectedLockScreens().get(1).getOnResumeCount()); - assertEquals(0, mLPKV.getInjectedUnlockScreens().get(1).getOnResumeCount()); - } - - public void testMenuDoesntGoToUnlockScreenOnWakeWhenPukLocked() { - // PUK locked - mUpdateMonitor.simState = IccCard.State.PUK_REQUIRED; - - // wake by menu - mLPKV.wakeWhenReadyTq(KeyEvent.KEYCODE_MENU); - - assertEquals(1, mLPKV.getInjectedLockScreens().size()); - assertEquals(1, mLPKV.getInjectedUnlockScreens().size()); - MockKeyguardScreen lockScreen = mLPKV.getInjectedLockScreens().get(0); - MockKeyguardScreen unlockScreen = mLPKV.getInjectedUnlockScreens().get(0); - - // lock screen should be only visible one - assertEquals(View.VISIBLE, lockScreen.getVisibility()); - assertEquals(View.GONE, unlockScreen.getVisibility()); - } - - public void testMenuGoesToLockScreenWhenDeviceNotSecure() { - mLockPatternUtils.setLockPatternEnabled(false); - - // wake by menu - mLPKV.wakeWhenReadyTq(KeyEvent.KEYCODE_MENU); - - assertEquals(1, mLPKV.getInjectedLockScreens().size()); - assertEquals(1, mLPKV.getInjectedUnlockScreens().size()); - MockKeyguardScreen lockScreen = mLPKV.getInjectedLockScreens().get(0); - MockKeyguardScreen unlockScreen = mLPKV.getInjectedUnlockScreens().get(0); - - // lock screen should be only visible one - assertEquals(View.VISIBLE, lockScreen.getVisibility()); - assertEquals(View.GONE, unlockScreen.getVisibility()); - } -} |