diff options
author | Jack Yu <jackcwyu@google.com> | 2019-12-17 16:18:28 +0800 |
---|---|---|
committer | Jack Yu <jackcwyu@google.com> | 2020-01-21 23:15:02 +0000 |
commit | d938b46d553074363765fc7a6920cf90a67e8e81 (patch) | |
tree | 104e98731a3c3e418c8bbb995a838f6ee707402f | |
parent | ccf7c818c450a1fd40cac47bde54f445aaf3b3a4 (diff) | |
download | SecureElement-d938b46d553074363765fc7a6920cf90a67e8e81.tar.gz |
Add support for secure_element HAL 1.2
Test: manual
Bug: 142495673
Change-Id: I1338a2a11cc60fa50b1c8dd8e75022af9ea1b0a1
-rw-r--r-- | Android.bp | 3 | ||||
-rw-r--r-- | src/com/android/se/Terminal.java | 61 |
2 files changed, 52 insertions, 12 deletions
@@ -4,7 +4,8 @@ android_app { platform_apis: true, certificate: "platform", static_libs: ["android.hardware.secure_element-V1.0-java", - "android.hardware.secure_element-V1.1-java"], + "android.hardware.secure_element-V1.1-java", + "android.hardware.secure_element-V1.2-java"], optimize: { enabled: false, }, diff --git a/src/com/android/se/Terminal.java b/src/com/android/se/Terminal.java index c248c89..5c71e0f 100644 --- a/src/com/android/se/Terminal.java +++ b/src/com/android/se/Terminal.java @@ -75,6 +75,7 @@ public class Terminal { private static final int EVENT_GET_HAL = 1; private ISecureElement mSEHal; + private android.hardware.secure_element.V1_2.ISecureElement mSEHal12; /** For each Terminal there will be one AccessController object. */ private AccessControlEnforcer mAccessControlEnforcer; @@ -189,25 +190,33 @@ public class Terminal { * @throws RemoteException if there is a failure communicating with the remote */ public void initialize(boolean retryOnFail) throws NoSuchElementException, RemoteException { + android.hardware.secure_element.V1_1.ISecureElement mSEHal11 = null; synchronized (mLock) { - android.hardware.secure_element.V1_1.ISecureElement seHal11 = null; try { - seHal11 = - android.hardware.secure_element.V1_1.ISecureElement.getService(mName, + mSEHal = mSEHal11 = mSEHal12 = + android.hardware.secure_element.V1_2.ISecureElement.getService(mName, retryOnFail); } catch (Exception e) { - Log.d(mTag, "SE Hal V1.1 is not supported"); + Log.d(mTag, "SE Hal V1.2 is not supported"); } + if (mSEHal12 == null) { + try { + mSEHal = mSEHal11 = + android.hardware.secure_element.V1_1.ISecureElement.getService(mName, + retryOnFail); + } catch (Exception e) { + Log.d(mTag, "SE Hal V1.1 is not supported"); + } - if (seHal11 == null) { - mSEHal = ISecureElement.getService(mName, retryOnFail); - if (mSEHal == null) { - throw new NoSuchElementException("No HAL is provided for " + mName); + if (mSEHal11 == null) { + mSEHal = ISecureElement.getService(mName, retryOnFail); + if (mSEHal == null) { + throw new NoSuchElementException("No HAL is provided for " + mName); + } } } - if (seHal11 != null) { - mSEHal = seHal11; - seHal11.init_1_1(mHalCallback11); + if (mSEHal11 != null || mSEHal12 != null) { + mSEHal11.init_1_1(mHalCallback11); } else { mSEHal.init(mHalCallback); } @@ -660,6 +669,31 @@ public class Terminal { } /** + * Reset the Secure Element. Return true if success, false otherwise. + */ + public boolean reset() { + if (mSEHal12 == null) { + return false; + } + mContext.enforceCallingOrSelfPermission( + android.Manifest.permission.SECURE_ELEMENT_PRIVILEGED, + "Need SECURE_ELEMENT_PRIVILEGED permission"); + + try { + byte status = mSEHal12.reset(); + // Successfully trigger reset. HAL service should send onStateChange + // after secure element reset and initialization process complete + if (status == SecureElementStatus.SUCCESS) { + return true; + } + Log.e(mTag, "Error reseting terminal " + mName); + } catch (RemoteException e) { + Log.e(mTag, "Exception in reset()" + e); + } + return false; + } + + /** * Initialize the Access Control and set up the channel access. */ private ChannelAccess setUpChannelAccess(byte[] aid, String packageName, int pid) @@ -828,5 +862,10 @@ public class Terminal { Terminal getTerminal() { return Terminal.this; } + + @Override + public boolean reset() { + return Terminal.this.reset(); + } } } |