Add CredentialInstaller.

This commit is contained in:
Hung-ying Tyan
2009-09-28 10:14:18 +08:00
parent a38a1a77ab
commit 70cef693d1
4 changed files with 85 additions and 10 deletions

View File

@@ -313,13 +313,20 @@
<action android:name="android.settings.SECURITY_SETTINGS" />
<action android:name="android.settings.LOCATION_SOURCE_SETTINGS" />
<action android:name="android.credentials.UNLOCK" />
<action android:name="android.credentials.SYSTEM_INSTALL" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.VOICE_LAUNCH" />
<category android:name="com.android.settings.SHORTCUT" />
</intent-filter>
</activity>
<activity android:name="CredentialInstaller"
android:label="@string/credential_installer_activity_title">
<intent-filter>
<action android:name="android.credentials.SYSTEM_INSTALL" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="PrivacySettings"
android:label="@string/privacy_settings_title"
android:configChanges="orientation|keyboardHidden"

View File

@@ -1907,6 +1907,9 @@ found in the list of installed applications.</string>
<string name="gadget_toggle_wifi">Updating Wi-Fi setting</string>
<string name="gadget_toggle_bluetooth">Updating Bluetooth setting</string>
<!-- credential installer title -->
<string name="credential_installer_activity_title">Credential installer</string>
<string name="vpn_settings_activity_title">VPN settings</string>
<!-- Title of VPN connect dialog -->

View File

@@ -0,0 +1,73 @@
/*
* 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 com.android.settings;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.security.Credentials;
import android.security.KeyStore;
import android.util.Log;
/**
* Installs credentials to the system keystore. It reacts to the
* {@link Credentials#SYSTEM_INSTALL_ACTION} intent. All the key-value pairs in
* the intent are installed to the system keystore. For security reason, the
* current implementation limits that only com.android.certinstaller can use
* this service.
*/
public class CredentialInstaller extends Activity {
private static final String TAG = "CredentialInstaller";
private KeyStore mKeyStore = KeyStore.getInstance();
private boolean mUnlocking = false;
@Override
protected void onResume() {
super.onResume();
if (!"com.android.certinstaller".equals(getCallingPackage())) finish();
if (!isKeyStoreLocked()) {
install();
finish();
} else if (!mUnlocking) {
mUnlocking = true;
Credentials.getInstance().unlock(this);
} else {
finish();
}
}
private void install() {
Intent intent = getIntent();
Bundle bundle = (intent == null) ? null : intent.getExtras();
if (bundle == null) return;
for (String key : bundle.keySet()) {
byte[] data = bundle.getByteArray(key);
if (data == null) continue;
boolean success = mKeyStore.put(key.getBytes(), data);
Log.v(TAG, "install " + key + ": " + data.length + " success? " + success);
if (!success) return;
}
setResult(RESULT_OK);
}
private boolean isKeyStoreLocked() {
return (mKeyStore.test() != KeyStore.NO_ERROR);
}
}

View File

@@ -380,9 +380,6 @@ public class SecuritySettings extends PreferenceActivity {
mExternalIntent = intent;
showCstorDialog(mState == KeyStore.UNINITIALIZED
? CSTOR_INIT_DIALOG : CSTOR_UNLOCK_DIALOG);
} else if (Credentials.SYSTEM_INSTALL_ACTION.equals(action)) {
mExternalIntent = intent;
// TODO: unlock and install.
}
}
@@ -460,15 +457,10 @@ public class SecuritySettings extends PreferenceActivity {
removeDialog(mDialogId);
if (mExternalIntent != null) {
if (Credentials.SYSTEM_INSTALL_ACTION.equals(
mExternalIntent.getAction())) {
// TODO: install if unlocked.
} else {
finish();
}
}
}
}
// returns false if there is no error.
private boolean checkError(int error) {