Secure Element access implementation
Change-Id: I907e6771ecc5babe895115c3a49288fa2144a187
This commit is contained in:
committed by
Jeff Hamilton
parent
6be655c768
commit
9024564107
@@ -123,6 +123,7 @@ LOCAL_SRC_FILES += \
|
||||
core/java/android/nfc/INfcTag.aidl \
|
||||
core/java/android/nfc/IP2pInitiator.aidl \
|
||||
core/java/android/nfc/IP2pTarget.aidl \
|
||||
core/java/android/nfc/INfcSecureElement.aidl \
|
||||
core/java/android/os/IHardwareService.aidl \
|
||||
core/java/android/os/IMessenger.aidl \
|
||||
core/java/android/os/INetworkManagementService.aidl \
|
||||
|
||||
@@ -24,6 +24,7 @@ import android.nfc.ILlcpConnectionlessSocket;
|
||||
import android.nfc.INfcTag;
|
||||
import android.nfc.IP2pTarget;
|
||||
import android.nfc.IP2pInitiator;
|
||||
import android.nfc.INfcSecureElement;
|
||||
|
||||
/**
|
||||
* @hide
|
||||
@@ -36,6 +37,7 @@ interface INfcAdapter
|
||||
INfcTag getNfcTagInterface();
|
||||
IP2pTarget getP2pTargetInterface();
|
||||
IP2pInitiator getP2pInitiatorInterface();
|
||||
INfcSecureElement getNfcSecureElementInterface();
|
||||
|
||||
// NfcAdapter-class related methods
|
||||
boolean isEnabled();
|
||||
|
||||
28
core/java/android/nfc/INfcSecureElement.aidl
Executable file
28
core/java/android/nfc/INfcSecureElement.aidl
Executable file
@@ -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.
|
||||
*/
|
||||
|
||||
package android.nfc;
|
||||
|
||||
/**
|
||||
* {@hide}
|
||||
*/
|
||||
interface INfcSecureElement {
|
||||
int openSecureElementConnection();
|
||||
int closeSecureElementConnection(int nativeHandle);
|
||||
byte[] exchangeAPDU(int nativeHandle, in byte[] data);
|
||||
int[] getSecureElementTechList(int nativeHandle);
|
||||
byte[] getSecureElementUid(int nativeHandle);
|
||||
}
|
||||
@@ -1,12 +1,17 @@
|
||||
/*
|
||||
* 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.
|
||||
* 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.nfc;
|
||||
@@ -354,4 +359,17 @@ public final class NfcAdapter {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an Nfc Secure Element Connection
|
||||
* @hide
|
||||
*/
|
||||
public NfcSecureElement createNfcSecureElementConnection() {
|
||||
try {
|
||||
return new NfcSecureElement(mService.getNfcSecureElementInterface());
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, "createNfcSecureElementConnection failed", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
138
core/java/android/nfc/NfcSecureElement.java
Executable file
138
core/java/android/nfc/NfcSecureElement.java
Executable file
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
* 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.nfc;
|
||||
|
||||
import android.nfc.technology.TagTechnology;
|
||||
import android.os.RemoteException;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
//import android.util.Log;
|
||||
|
||||
/**
|
||||
* This class provides the primary API for managing all aspects Secure Element.
|
||||
* Get an instance of this class by calling
|
||||
* Context.getSystemService(Context.NFC_SERVICE).
|
||||
* @hide
|
||||
*/
|
||||
public final class NfcSecureElement {
|
||||
|
||||
private static final String TAG = "NfcSecureElement";
|
||||
|
||||
private INfcSecureElement mService;
|
||||
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
public NfcSecureElement(INfcSecureElement mSecureElementService) {
|
||||
mService = mSecureElementService;
|
||||
}
|
||||
|
||||
public int openSecureElementConnection(String seType) throws IOException {
|
||||
if (seType.equals("SmartMX")) {
|
||||
try {
|
||||
int handle = mService.openSecureElementConnection();
|
||||
// Handle potential errors
|
||||
if (handle != 0) {
|
||||
return handle;
|
||||
} else {
|
||||
throw new IOException("SmartMX connection not allowed");
|
||||
}
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, "RemoteException in openSecureElementConnection(): ", e);
|
||||
return 0;
|
||||
}
|
||||
|
||||
} else if (seType.equals("UICC")) {
|
||||
return 0;
|
||||
} else {
|
||||
throw new IOException("Wrong Secure Element type");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public byte [] exchangeAPDU(int handle,byte [] data) throws IOException {
|
||||
|
||||
|
||||
// Perform exchange APDU
|
||||
try {
|
||||
byte[] response = mService.exchangeAPDU(handle, data);
|
||||
// Handle potential errors
|
||||
if (response == null) {
|
||||
throw new IOException("Exchange APDU failed");
|
||||
}
|
||||
return response;
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, "RemoteException in exchangeAPDU(): ", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void closeSecureElementConnection(int handle) throws IOException {
|
||||
|
||||
try {
|
||||
int status = mService.closeSecureElementConnection(handle);
|
||||
// Handle potential errors
|
||||
if (ErrorCodes.isError(status)) {
|
||||
throw new IOException("Error during the conection close");
|
||||
};
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, "RemoteException in closeSecureElement(): ", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns target type. constants.
|
||||
*
|
||||
* @return Secure Element technology type. The possible values are defined in
|
||||
* {@link TagTechnology}
|
||||
*
|
||||
*/
|
||||
public int[] getSecureElementTechList(int handle) throws IOException {
|
||||
try {
|
||||
return mService.getSecureElementTechList(handle);
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, "RemoteException in getType(): ", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns Secure Element UID.
|
||||
*
|
||||
* @return Secure Element UID.
|
||||
*/
|
||||
public byte[] getSecureElementUid(int handle) throws IOException {
|
||||
|
||||
byte[] uid = null;
|
||||
try {
|
||||
uid = mService.getSecureElementUid(handle);
|
||||
// Handle potential errors
|
||||
if (uid == null) {
|
||||
throw new IOException("Get Secure Element UID failed");
|
||||
}
|
||||
return uid;
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, "RemoteException in getType(): ", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user