From 3e6251dedc92654476c70bdc413f24a4b31ce6a4 Mon Sep 17 00:00:00 2001 From: Brian Carlstrom Date: Mon, 11 Apr 2011 09:05:06 -0700 Subject: Adding KeyChainService and KeyChainActivity Change-Id: I6c862d3e687cf80fb882966adb3245f2244244fe --- support/Android.mk | 29 +++++++++ support/AndroidManifest.xml | 27 +++++++++ .../tests/support/IKeyChainServiceTestSupport.aidl | 38 ++++++++++++ .../tests/support/KeyChainServiceTestSupport.java | 69 ++++++++++++++++++++++ 4 files changed, 163 insertions(+) create mode 100644 support/Android.mk create mode 100644 support/AndroidManifest.xml create mode 100644 support/src/com/android/keychain/tests/support/IKeyChainServiceTestSupport.aidl create mode 100644 support/src/com/android/keychain/tests/support/KeyChainServiceTestSupport.java (limited to 'support') diff --git a/support/Android.mk b/support/Android.mk new file mode 100644 index 0000000..1860584 --- /dev/null +++ b/support/Android.mk @@ -0,0 +1,29 @@ +# Copyright 2011, 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) +LOCAL_MODULE_TAGS := tests +LOCAL_SRC_FILES := src/com/android/keychain/tests/support/IKeyChainServiceTestSupport.aidl +LOCAL_MODULE := com.android.keychain.tests.support +include $(BUILD_STATIC_JAVA_LIBRARY) + +include $(CLEAR_VARS) +LOCAL_MODULE_TAGS := tests +LOCAL_SRC_FILES := $(call all-java-files-under, src) +LOCAL_PACKAGE_NAME := KeyChainTestsSupport +LOCAL_STATIC_JAVA_LIBRARIES := com.android.keychain.tests.support +LOCAL_CERTIFICATE := platform +include $(BUILD_PACKAGE) diff --git a/support/AndroidManifest.xml b/support/AndroidManifest.xml new file mode 100644 index 0000000..934660a --- /dev/null +++ b/support/AndroidManifest.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + diff --git a/support/src/com/android/keychain/tests/support/IKeyChainServiceTestSupport.aidl b/support/src/com/android/keychain/tests/support/IKeyChainServiceTestSupport.aidl new file mode 100644 index 0000000..cb03429 --- /dev/null +++ b/support/src/com/android/keychain/tests/support/IKeyChainServiceTestSupport.aidl @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2011 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.keychain.tests.support; + +import android.accounts.Account; + +/** + * Service that runs as the system user for the use of the + * KeyChainServiceTest which needs to run as a regular app user, but + * needs to automate some steps only permissable to the system + * user. The KeyChainService itself runs as the keychain user and + * cannot do these steps itself. In a real application, they user is + * prompted to perform these steps via the + * com.android.credentials.UNLOCK Intent and + * GrantCredentialsPermissionActivity. + * + * @hide + */ +interface IKeyChainServiceTestSupport { + boolean keystoreReset(); + boolean keystorePassword(String oldPassword, String newPassword); + boolean keystorePut(in byte[] key, in byte[] value); + void revokeAppPermission(in Account account, String authTokenType, int uid); + void grantAppPermission(in Account account, String authTokenType, int uid); +} diff --git a/support/src/com/android/keychain/tests/support/KeyChainServiceTestSupport.java b/support/src/com/android/keychain/tests/support/KeyChainServiceTestSupport.java new file mode 100644 index 0000000..46ef6f8 --- /dev/null +++ b/support/src/com/android/keychain/tests/support/KeyChainServiceTestSupport.java @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2011 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.keychain.tests.support; + +import android.accounts.Account; +import android.accounts.AccountManagerService; +import android.app.Service; +import android.content.Intent; +import android.os.IBinder; +import android.security.KeyStore; +import android.util.Log; + +public class KeyChainServiceTestSupport extends Service { + + private static final String TAG = "KeyChainServiceTestSupport"; + + private final Object mServiceLock = new Object(); + private IKeyChainServiceTestSupport mService; + private boolean mIsBound; + + private final KeyStore mKeyStore = KeyStore.getInstance(); + private final AccountManagerService accountManagerService + = AccountManagerService.getSingleton(); + + private final IKeyChainServiceTestSupport.Stub mIKeyChainServiceTestSupport + = new IKeyChainServiceTestSupport.Stub() { + @Override public boolean keystoreReset() { + Log.d(TAG, "keystoreReset"); + return mKeyStore.reset(); + } + @Override public boolean keystorePassword(String oldPassword, String newPassword) { + Log.d(TAG, "keystorePassword"); + return mKeyStore.password(oldPassword, newPassword); + } + @Override public boolean keystorePut(byte[] key, byte[] value) { + Log.d(TAG, "keystorePut"); + return mKeyStore.put(key, value); + } + @Override public void revokeAppPermission(Account account, String authTokenType, int uid) { + Log.d(TAG, "revokeAppPermission"); + accountManagerService.revokeAppPermission(account, authTokenType, uid); + } + @Override public void grantAppPermission(Account account, String authTokenType, int uid) { + Log.d(TAG, "grantAppPermission"); + accountManagerService.grantAppPermission(account, authTokenType, uid); + } + }; + + @Override public IBinder onBind(Intent intent) { + if (IKeyChainServiceTestSupport.class.getName().equals(intent.getAction())) { + return mIKeyChainServiceTestSupport; + } + return null; + } +} -- cgit v1.2.3