diff options
author | Brett Chabot <brettchabot@android.com> | 2010-06-16 14:39:41 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2010-06-16 14:39:41 -0700 |
commit | c95812e6cacaa14748c81323bac6561453991a24 (patch) | |
tree | 300739d99c954c01025a97858bc999ff547cc845 /policy | |
parent | f897b443fed5c88c6b12e3fa1da72f231db67673 (diff) | |
parent | be81f4f15dad6d690efcab1973d1e174ce3b001b (diff) | |
download | frameworks_base-c95812e6cacaa14748c81323bac6561453991a24.zip frameworks_base-c95812e6cacaa14748c81323bac6561453991a24.tar.gz frameworks_base-c95812e6cacaa14748c81323bac6561453991a24.tar.bz2 |
Merge "Move out all framework-tests classes." into gingerbread
Diffstat (limited to 'policy')
-rw-r--r-- | policy/Android.mk | 6 | ||||
-rw-r--r-- | policy/src/com/android/internal/policy/impl/AccountUnlockScreen.java (renamed from policy/com/android/internal/policy/impl/AccountUnlockScreen.java) | 0 | ||||
-rw-r--r-- | policy/src/com/android/internal/policy/impl/GlobalActions.java (renamed from policy/com/android/internal/policy/impl/GlobalActions.java) | 0 | ||||
-rw-r--r-- | policy/src/com/android/internal/policy/impl/IconUtilities.java (renamed from policy/com/android/internal/policy/impl/IconUtilities.java) | 0 | ||||
-rw-r--r-- | policy/src/com/android/internal/policy/impl/KeyguardScreen.java (renamed from policy/com/android/internal/policy/impl/KeyguardScreen.java) | 0 | ||||
-rw-r--r-- | policy/src/com/android/internal/policy/impl/KeyguardScreenCallback.java (renamed from policy/com/android/internal/policy/impl/KeyguardScreenCallback.java) | 0 | ||||
-rw-r--r-- | policy/src/com/android/internal/policy/impl/KeyguardUpdateMonitor.java (renamed from policy/com/android/internal/policy/impl/KeyguardUpdateMonitor.java) | 0 | ||||
-rw-r--r-- | policy/src/com/android/internal/policy/impl/KeyguardViewBase.java (renamed from policy/com/android/internal/policy/impl/KeyguardViewBase.java) | 0 | ||||
-rw-r--r-- | policy/src/com/android/internal/policy/impl/KeyguardViewCallback.java (renamed from policy/com/android/internal/policy/impl/KeyguardViewCallback.java) | 0 | ||||
-rw-r--r-- | policy/src/com/android/internal/policy/impl/KeyguardViewManager.java (renamed from policy/com/android/internal/policy/impl/KeyguardViewManager.java) | 0 | ||||
-rw-r--r-- | policy/src/com/android/internal/policy/impl/KeyguardViewMediator.java (renamed from policy/com/android/internal/policy/impl/KeyguardViewMediator.java) | 0 | ||||
-rw-r--r-- | policy/src/com/android/internal/policy/impl/KeyguardViewProperties.java (renamed from policy/com/android/internal/policy/impl/KeyguardViewProperties.java) | 0 | ||||
-rw-r--r-- | policy/src/com/android/internal/policy/impl/KeyguardWindowController.java (renamed from policy/com/android/internal/policy/impl/KeyguardWindowController.java) | 0 | ||||
-rw-r--r-- | policy/src/com/android/internal/policy/impl/LockPatternKeyguardView.java (renamed from policy/com/android/internal/policy/impl/LockPatternKeyguardView.java) | 0 | ||||
-rw-r--r-- | policy/src/com/android/internal/policy/impl/LockPatternKeyguardViewProperties.java (renamed from policy/com/android/internal/policy/impl/LockPatternKeyguardViewProperties.java) | 0 | ||||
-rw-r--r-- | policy/src/com/android/internal/policy/impl/LockScreen.java (renamed from policy/com/android/internal/policy/impl/LockScreen.java) | 0 | ||||
-rw-r--r-- | policy/src/com/android/internal/policy/impl/PasswordUnlockScreen.java (renamed from policy/com/android/internal/policy/impl/PasswordUnlockScreen.java) | 0 | ||||
-rw-r--r-- | policy/src/com/android/internal/policy/impl/PatternUnlockScreen.java (renamed from policy/com/android/internal/policy/impl/PatternUnlockScreen.java) | 0 | ||||
-rw-r--r-- | policy/src/com/android/internal/policy/impl/PhoneLayoutInflater.java (renamed from policy/com/android/internal/policy/impl/PhoneLayoutInflater.java) | 0 | ||||
-rw-r--r-- | policy/src/com/android/internal/policy/impl/PhoneWindow.java (renamed from policy/com/android/internal/policy/impl/PhoneWindow.java) | 0 | ||||
-rwxr-xr-x | policy/src/com/android/internal/policy/impl/PhoneWindowManager.java (renamed from policy/com/android/internal/policy/impl/PhoneWindowManager.java) | 0 | ||||
-rw-r--r-- | policy/src/com/android/internal/policy/impl/Policy.java (renamed from policy/com/android/internal/policy/impl/Policy.java) | 0 | ||||
-rw-r--r-- | policy/src/com/android/internal/policy/impl/PowerDialog.java (renamed from policy/com/android/internal/policy/impl/PowerDialog.java) | 0 | ||||
-rw-r--r-- | policy/src/com/android/internal/policy/impl/RecentApplicationsBackground.java (renamed from policy/com/android/internal/policy/impl/RecentApplicationsBackground.java) | 0 | ||||
-rw-r--r-- | policy/src/com/android/internal/policy/impl/RecentApplicationsDialog.java (renamed from policy/com/android/internal/policy/impl/RecentApplicationsDialog.java) | 0 | ||||
-rw-r--r-- | policy/src/com/android/internal/policy/impl/ShortcutManager.java (renamed from policy/com/android/internal/policy/impl/ShortcutManager.java) | 0 | ||||
-rw-r--r-- | policy/src/com/android/internal/policy/impl/SimUnlockScreen.java (renamed from policy/com/android/internal/policy/impl/SimUnlockScreen.java) | 0 | ||||
-rw-r--r-- | policy/src/com/android/internal/policy/impl/package.html (renamed from policy/com/android/internal/policy/impl/package.html) | 0 | ||||
-rw-r--r-- | policy/tests/Android.mk | 29 | ||||
-rw-r--r-- | policy/tests/AndroidManifest.xml | 31 | ||||
-rw-r--r-- | policy/tests/src/com/android/internal/policy/impl/LockPatternKeyguardViewTest.java | 350 |
31 files changed, 414 insertions, 2 deletions
diff --git a/policy/Android.mk b/policy/Android.mk index a887142..47d8fb8 100644 --- a/policy/Android.mk +++ b/policy/Android.mk @@ -4,9 +4,11 @@ LOCAL_PATH:= $(call my-dir) # ============================================================ include $(CLEAR_VARS) -LOCAL_SRC_FILES := \ - $(call all-subdir-java-files) +LOCAL_SRC_FILES := $(call all-java-files-under, src) LOCAL_MODULE := android.policy include $(BUILD_JAVA_LIBRARY) + +# additionally, build unit tests in a separate .apk +include $(call all-makefiles-under,$(LOCAL_PATH)) diff --git a/policy/com/android/internal/policy/impl/AccountUnlockScreen.java b/policy/src/com/android/internal/policy/impl/AccountUnlockScreen.java index 840c5e1..840c5e1 100644 --- a/policy/com/android/internal/policy/impl/AccountUnlockScreen.java +++ b/policy/src/com/android/internal/policy/impl/AccountUnlockScreen.java diff --git a/policy/com/android/internal/policy/impl/GlobalActions.java b/policy/src/com/android/internal/policy/impl/GlobalActions.java index 1f06dcc..1f06dcc 100644 --- a/policy/com/android/internal/policy/impl/GlobalActions.java +++ b/policy/src/com/android/internal/policy/impl/GlobalActions.java diff --git a/policy/com/android/internal/policy/impl/IconUtilities.java b/policy/src/com/android/internal/policy/impl/IconUtilities.java index 99055cf..99055cf 100644 --- a/policy/com/android/internal/policy/impl/IconUtilities.java +++ b/policy/src/com/android/internal/policy/impl/IconUtilities.java diff --git a/policy/com/android/internal/policy/impl/KeyguardScreen.java b/policy/src/com/android/internal/policy/impl/KeyguardScreen.java index bbb6875..bbb6875 100644 --- a/policy/com/android/internal/policy/impl/KeyguardScreen.java +++ b/policy/src/com/android/internal/policy/impl/KeyguardScreen.java diff --git a/policy/com/android/internal/policy/impl/KeyguardScreenCallback.java b/policy/src/com/android/internal/policy/impl/KeyguardScreenCallback.java index a843603..a843603 100644 --- a/policy/com/android/internal/policy/impl/KeyguardScreenCallback.java +++ b/policy/src/com/android/internal/policy/impl/KeyguardScreenCallback.java diff --git a/policy/com/android/internal/policy/impl/KeyguardUpdateMonitor.java b/policy/src/com/android/internal/policy/impl/KeyguardUpdateMonitor.java index b225e56..b225e56 100644 --- a/policy/com/android/internal/policy/impl/KeyguardUpdateMonitor.java +++ b/policy/src/com/android/internal/policy/impl/KeyguardUpdateMonitor.java diff --git a/policy/com/android/internal/policy/impl/KeyguardViewBase.java b/policy/src/com/android/internal/policy/impl/KeyguardViewBase.java index 9dcbcb6..9dcbcb6 100644 --- a/policy/com/android/internal/policy/impl/KeyguardViewBase.java +++ b/policy/src/com/android/internal/policy/impl/KeyguardViewBase.java diff --git a/policy/com/android/internal/policy/impl/KeyguardViewCallback.java b/policy/src/com/android/internal/policy/impl/KeyguardViewCallback.java index b376d65..b376d65 100644 --- a/policy/com/android/internal/policy/impl/KeyguardViewCallback.java +++ b/policy/src/com/android/internal/policy/impl/KeyguardViewCallback.java diff --git a/policy/com/android/internal/policy/impl/KeyguardViewManager.java b/policy/src/com/android/internal/policy/impl/KeyguardViewManager.java index ba1d7f5..ba1d7f5 100644 --- a/policy/com/android/internal/policy/impl/KeyguardViewManager.java +++ b/policy/src/com/android/internal/policy/impl/KeyguardViewManager.java diff --git a/policy/com/android/internal/policy/impl/KeyguardViewMediator.java b/policy/src/com/android/internal/policy/impl/KeyguardViewMediator.java index 88203c3..88203c3 100644 --- a/policy/com/android/internal/policy/impl/KeyguardViewMediator.java +++ b/policy/src/com/android/internal/policy/impl/KeyguardViewMediator.java diff --git a/policy/com/android/internal/policy/impl/KeyguardViewProperties.java b/policy/src/com/android/internal/policy/impl/KeyguardViewProperties.java index bda08eb..bda08eb 100644 --- a/policy/com/android/internal/policy/impl/KeyguardViewProperties.java +++ b/policy/src/com/android/internal/policy/impl/KeyguardViewProperties.java diff --git a/policy/com/android/internal/policy/impl/KeyguardWindowController.java b/policy/src/com/android/internal/policy/impl/KeyguardWindowController.java index 4ad48fb..4ad48fb 100644 --- a/policy/com/android/internal/policy/impl/KeyguardWindowController.java +++ b/policy/src/com/android/internal/policy/impl/KeyguardWindowController.java diff --git a/policy/com/android/internal/policy/impl/LockPatternKeyguardView.java b/policy/src/com/android/internal/policy/impl/LockPatternKeyguardView.java index 27706ef..27706ef 100644 --- a/policy/com/android/internal/policy/impl/LockPatternKeyguardView.java +++ b/policy/src/com/android/internal/policy/impl/LockPatternKeyguardView.java diff --git a/policy/com/android/internal/policy/impl/LockPatternKeyguardViewProperties.java b/policy/src/com/android/internal/policy/impl/LockPatternKeyguardViewProperties.java index ed5a058..ed5a058 100644 --- a/policy/com/android/internal/policy/impl/LockPatternKeyguardViewProperties.java +++ b/policy/src/com/android/internal/policy/impl/LockPatternKeyguardViewProperties.java diff --git a/policy/com/android/internal/policy/impl/LockScreen.java b/policy/src/com/android/internal/policy/impl/LockScreen.java index a5ef1fa..a5ef1fa 100644 --- a/policy/com/android/internal/policy/impl/LockScreen.java +++ b/policy/src/com/android/internal/policy/impl/LockScreen.java diff --git a/policy/com/android/internal/policy/impl/PasswordUnlockScreen.java b/policy/src/com/android/internal/policy/impl/PasswordUnlockScreen.java index 39f2917..39f2917 100644 --- a/policy/com/android/internal/policy/impl/PasswordUnlockScreen.java +++ b/policy/src/com/android/internal/policy/impl/PasswordUnlockScreen.java diff --git a/policy/com/android/internal/policy/impl/PatternUnlockScreen.java b/policy/src/com/android/internal/policy/impl/PatternUnlockScreen.java index 418e243..418e243 100644 --- a/policy/com/android/internal/policy/impl/PatternUnlockScreen.java +++ b/policy/src/com/android/internal/policy/impl/PatternUnlockScreen.java diff --git a/policy/com/android/internal/policy/impl/PhoneLayoutInflater.java b/policy/src/com/android/internal/policy/impl/PhoneLayoutInflater.java index 6bf4beb..6bf4beb 100644 --- a/policy/com/android/internal/policy/impl/PhoneLayoutInflater.java +++ b/policy/src/com/android/internal/policy/impl/PhoneLayoutInflater.java diff --git a/policy/com/android/internal/policy/impl/PhoneWindow.java b/policy/src/com/android/internal/policy/impl/PhoneWindow.java index 0cb0efc..0cb0efc 100644 --- a/policy/com/android/internal/policy/impl/PhoneWindow.java +++ b/policy/src/com/android/internal/policy/impl/PhoneWindow.java diff --git a/policy/com/android/internal/policy/impl/PhoneWindowManager.java b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java index a01e25b..a01e25b 100755 --- a/policy/com/android/internal/policy/impl/PhoneWindowManager.java +++ b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java diff --git a/policy/com/android/internal/policy/impl/Policy.java b/policy/src/com/android/internal/policy/impl/Policy.java index 17f3e91..17f3e91 100644 --- a/policy/com/android/internal/policy/impl/Policy.java +++ b/policy/src/com/android/internal/policy/impl/Policy.java diff --git a/policy/com/android/internal/policy/impl/PowerDialog.java b/policy/src/com/android/internal/policy/impl/PowerDialog.java index de35bd7..de35bd7 100644 --- a/policy/com/android/internal/policy/impl/PowerDialog.java +++ b/policy/src/com/android/internal/policy/impl/PowerDialog.java diff --git a/policy/com/android/internal/policy/impl/RecentApplicationsBackground.java b/policy/src/com/android/internal/policy/impl/RecentApplicationsBackground.java index 7c99e87..7c99e87 100644 --- a/policy/com/android/internal/policy/impl/RecentApplicationsBackground.java +++ b/policy/src/com/android/internal/policy/impl/RecentApplicationsBackground.java diff --git a/policy/com/android/internal/policy/impl/RecentApplicationsDialog.java b/policy/src/com/android/internal/policy/impl/RecentApplicationsDialog.java index 9608b9a..9608b9a 100644 --- a/policy/com/android/internal/policy/impl/RecentApplicationsDialog.java +++ b/policy/src/com/android/internal/policy/impl/RecentApplicationsDialog.java diff --git a/policy/com/android/internal/policy/impl/ShortcutManager.java b/policy/src/com/android/internal/policy/impl/ShortcutManager.java index d86ac44..d86ac44 100644 --- a/policy/com/android/internal/policy/impl/ShortcutManager.java +++ b/policy/src/com/android/internal/policy/impl/ShortcutManager.java diff --git a/policy/com/android/internal/policy/impl/SimUnlockScreen.java b/policy/src/com/android/internal/policy/impl/SimUnlockScreen.java index 5518e11..5518e11 100644 --- a/policy/com/android/internal/policy/impl/SimUnlockScreen.java +++ b/policy/src/com/android/internal/policy/impl/SimUnlockScreen.java diff --git a/policy/com/android/internal/policy/impl/package.html b/policy/src/com/android/internal/policy/impl/package.html index c9f96a6..c9f96a6 100644 --- a/policy/com/android/internal/policy/impl/package.html +++ b/policy/src/com/android/internal/policy/impl/package.html diff --git a/policy/tests/Android.mk b/policy/tests/Android.mk new file mode 100644 index 0000000..ffb60b1 --- /dev/null +++ b/policy/tests/Android.mk @@ -0,0 +1,29 @@ +# Copyright 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. + +LOCAL_PATH:= $(call my-dir) +include $(CLEAR_VARS) + +# We only want this apk build for tests. +LOCAL_MODULE_TAGS := tests + +LOCAL_JAVA_LIBRARIES := android.policy android.test.runner + +# Include all test java files. +LOCAL_SRC_FILES := $(call all-java-files-under, src) + +LOCAL_PACKAGE_NAME := FrameworkPolicyTests + +include $(BUILD_PACKAGE) + diff --git a/policy/tests/AndroidManifest.xml b/policy/tests/AndroidManifest.xml new file mode 100644 index 0000000..dbdabfa --- /dev/null +++ b/policy/tests/AndroidManifest.xml @@ -0,0 +1,31 @@ +<?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. +--> + +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.android.frameworks.policy.tests"> + + <application> + <uses-library android:name="android.test.runner" /> + </application> + + <uses-permission android:name="android.permission.GET_ACCOUNTS" /> + <uses-permission android:name="android.permission.MANAGE_ACCOUNTS" /> + + <instrumentation + android:name="android.test.InstrumentationTestRunner" + android:targetPackage="com.android.frameworks.policy.tests" + android:label="Framework policy tests" /> +</manifest> diff --git a/policy/tests/src/com/android/internal/policy/impl/LockPatternKeyguardViewTest.java b/policy/tests/src/com/android/internal/policy/impl/LockPatternKeyguardViewTest.java new file mode 100644 index 0000000..bdfe652 --- /dev/null +++ b/policy/tests/src/com/android/internal/policy/impl/LockPatternKeyguardViewTest.java @@ -0,0 +1,350 @@ +/* + * 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(Context context) { + super(context); + } + + @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(getContext()); + + 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()); + } +} |