M7350v1_en_gpl

This commit is contained in:
T
2024-09-09 08:52:07 +00:00
commit f9cc65cfda
65988 changed files with 26357421 additions and 0 deletions
+15
View File
@@ -0,0 +1,15 @@
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
# We only want this apk build for tests.
LOCAL_MODULE_TAGS := tests
LOCAL_CERTIFICATE := platform
LOCAL_JAVA_LIBRARIES := android.test.runner
# Include all test java files.
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_PACKAGE_NAME := KeyStoreTests
include $(BUILD_PACKAGE)
+29
View File
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2009 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="android.security.tests"
android:sharedUserId="android.uid.system">
<application>
<uses-library android:name="android.test.runner" />
</application>
<instrumentation android:name=".KeyStoreTestRunner"
android:targetPackage="android.security.tests"
android:label="KeyStore Tests">
</instrumentation>
</manifest>
+146
View File
@@ -0,0 +1,146 @@
/*
* Copyright (C) 2009 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.security.tests;
import android.app.Activity;
import android.security.KeyStore;
import android.test.ActivityUnitTestCase;
import android.test.suitebuilder.annotation.MediumTest;
/**
* Junit / Instrumentation test case for KeyStore class
*
* Running the test suite:
*
* adb shell am instrument -w android.security.tests/.KeyStoreTestRunner
*/
@MediumTest
public class KeyStoreTest extends ActivityUnitTestCase<Activity> {
private static final String TEST_PASSWD = "12345678";
private static final String TEST_EMPTY_PASSWD = "";
private static final String TEST_SHORT_PASSWD = "short";
private static final String TEST_PASSWD2 = "87654321";
private static final String TEST_KEYNAME = "testkey";
private static final String TEST_KEYNAME1 = "testkey1";
private static final String TEST_KEYNAME2 = "testkey2";
private static final String TEST_KEYVALUE = "test value";
// "Hello, World" in Chinese
private static final String TEST_I18N = "\u4F60\u597D, \u4E16\u754C";
private KeyStore mKeyStore = null;
public KeyStoreTest() {
super(Activity.class);
}
@Override
protected void setUp() throws Exception {
mKeyStore = KeyStore.getInstance();
if (mKeyStore.test() != KeyStore.UNINITIALIZED) mKeyStore.reset();
assertEquals(KeyStore.UNINITIALIZED, mKeyStore.test());
super.setUp();
}
@Override
protected void tearDown() throws Exception {
mKeyStore.reset();
super.tearDown();
}
public void testTest() throws Exception {
assertEquals(KeyStore.UNINITIALIZED, mKeyStore.test());
}
public void testPassword() throws Exception {
//assertFalse(mKeyStore.password(TEST_EMPTY_PASSWD));
//assertFalse(mKeyStore.password(TEST_SHORT_PASSWD));
assertTrue(mKeyStore.password(TEST_PASSWD));
assertEquals(KeyStore.NO_ERROR, mKeyStore.test());
assertFalse(mKeyStore.password(TEST_PASSWD2, TEST_PASSWD2));
//assertFalse(mKeyStore.password(TEST_PASSWD, TEST_SHORT_PASSWD));
assertTrue(mKeyStore.password(TEST_PASSWD, TEST_PASSWD2));
}
public void testPut() throws Exception {
assertFalse(mKeyStore.put(TEST_KEYNAME, TEST_KEYVALUE));
assertFalse(mKeyStore.contains(TEST_KEYNAME));
mKeyStore.password(TEST_PASSWD);
assertTrue(mKeyStore.put(TEST_KEYNAME, TEST_KEYVALUE));
}
public void testI18n() throws Exception {
assertFalse(mKeyStore.put(TEST_I18N, TEST_I18N));
assertFalse(mKeyStore.contains(TEST_I18N));
mKeyStore.password(TEST_I18N);
assertTrue(mKeyStore.put(TEST_I18N, TEST_I18N));
assertTrue(mKeyStore.contains(TEST_I18N));
}
public void testDelete() throws Exception {
assertTrue(mKeyStore.delete(TEST_KEYNAME));
mKeyStore.password(TEST_PASSWD);
assertTrue(mKeyStore.delete(TEST_KEYNAME));
mKeyStore.put(TEST_KEYNAME, TEST_KEYVALUE);
assertTrue(mKeyStore.delete(TEST_KEYNAME));
}
public void testContains() throws Exception {
assertFalse(mKeyStore.contains(TEST_KEYNAME));
mKeyStore.password(TEST_PASSWD);
assertFalse(mKeyStore.contains(TEST_KEYNAME));
mKeyStore.put(TEST_KEYNAME, TEST_KEYVALUE);
assertTrue(mKeyStore.contains(TEST_KEYNAME));
}
public void testSaw() throws Exception {
String[] results = mKeyStore.saw(TEST_KEYNAME);
assertEquals(0, results.length);
mKeyStore.password(TEST_PASSWD);
mKeyStore.put(TEST_KEYNAME1, TEST_KEYVALUE);
mKeyStore.put(TEST_KEYNAME2, TEST_KEYVALUE);
results = mKeyStore.saw(TEST_KEYNAME);
assertEquals(2, results.length);
}
public void testLock() throws Exception {
assertFalse(mKeyStore.lock());
mKeyStore.password(TEST_PASSWD);
assertEquals(KeyStore.NO_ERROR, mKeyStore.test());
assertTrue(mKeyStore.lock());
assertEquals(KeyStore.LOCKED, mKeyStore.test());
}
public void testUnlock() throws Exception {
mKeyStore.password(TEST_PASSWD);
assertEquals(KeyStore.NO_ERROR, mKeyStore.test());
mKeyStore.lock();
assertFalse(mKeyStore.unlock(TEST_PASSWD2));
assertTrue(mKeyStore.unlock(TEST_PASSWD));
}
}
@@ -0,0 +1,48 @@
/*
* Copyright (C) 2009 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.security.tests;
import junit.framework.TestSuite;
import android.test.InstrumentationTestRunner;
import android.test.InstrumentationTestSuite;
/**
* Instrumentation Test Runner for all KeyStore unit tests.
*
* Running all tests:
*
* runtest keystore-unit
* or
* adb shell am instrument -w android.security.tests/.KeyStoreTestRunner
*/
public class KeyStoreTestRunner extends InstrumentationTestRunner {
@Override
public TestSuite getAllTests() {
TestSuite suite = new InstrumentationTestSuite(this);
suite.addTestSuite(android.security.tests.KeyStoreTest.class);
suite.addTestSuite(android.security.tests.SystemKeyStoreTest.class);
return suite;
}
@Override
public ClassLoader getLoader() {
return KeyStoreTestRunner.class.getClassLoader();
}
}
@@ -0,0 +1,86 @@
/*
* 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.
*/
package android.security.tests;
import android.app.Activity;
import android.security.SystemKeyStore;
import android.test.ActivityUnitTestCase;
import android.test.suitebuilder.annotation.MediumTest;
/**
* Junit / Instrumentation test case for KeyStore class
*
* Running the test suite:
*
* adb shell am instrument -w android.security.tests/.KeyStoreTestRunner
*/
@MediumTest
public class SystemKeyStoreTest extends ActivityUnitTestCase<Activity> {
private static final String keyName = "TestKey";
private static final String keyName2 = "TestKey2";
private SystemKeyStore mSysKeyStore = null;
public SystemKeyStoreTest() {
super(Activity.class);
}
@Override
protected void setUp() throws Exception {
mSysKeyStore = SystemKeyStore.getInstance();
try {
mSysKeyStore.deleteKey(keyName);
mSysKeyStore.deleteKey(keyName2);
} catch (Exception e) { }
super.setUp();
}
@Override
protected void tearDown() throws Exception {
try {
mSysKeyStore.deleteKey(keyName);
mSysKeyStore.deleteKey(keyName2);
} catch (Exception e) { }
super.tearDown();
}
public void testBasicAccess() throws Exception {
try {
byte[] newKey = mSysKeyStore.generateNewKey(128, "AES", keyName);
assertNotNull(newKey);
byte[] recKey = mSysKeyStore.retrieveKey(keyName);
assertEquals(newKey.length, recKey.length);
for (int i = 0; i < newKey.length; i++) {
assertEquals(newKey[i], recKey[i]);
}
mSysKeyStore.deleteKey(keyName);
byte[] nullKey = mSysKeyStore.retrieveKey(keyName);
assertNull(nullKey);
String newKeyStr = mSysKeyStore.generateNewKeyHexString(128, "AES", keyName2);
assertNotNull(newKeyStr);
String recKeyStr = mSysKeyStore.retrieveKeyHexString(keyName2);
assertEquals(newKeyStr, recKeyStr);
mSysKeyStore.deleteKey(keyName2);
String nullKey2 = mSysKeyStore.retrieveKeyHexString(keyName2);
assertNull(nullKey2);
} catch (Exception e) {
fail();
}
}
}