blob: 846b2933d35afe2259181de432af1fee83a406c9 [file] [log] [blame]
nxpandroid64fd68c2015-09-23 16:45:15 +05301/******************************************************************************
nxf500513a018e72019-04-23 17:11:41 +05302*
3* Licensed under the Apache License, Version 2.0 (the "License");
4* you may not use this file except in compliance with the License.
5* You may obtain a copy of the License at
6*
7* http://www.apache.org/licenses/LICENSE-2.0
8*
9* Unless required by applicable law or agreed to in writing, software
10* distributed under the License is distributed on an "AS IS" BASIS,
11* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12* See the License for the specific language governing permissions and
13* limitations under the License.
14*
nxf3542176b09732019-05-13 16:01:38 +053015* Copyright 2018-2019 NXP
nxf500513a018e72019-04-23 17:11:41 +053016*
17******************************************************************************/
nxpandroid64fd68c2015-09-23 16:45:15 +053018
19package com.android.nfc.dhimpl;
20
21import android.content.Context;
22import android.content.SharedPreferences;
nxf500513a018e72019-04-23 17:11:41 +053023import android.util.Log;
nxpandroid64fd68c2015-09-23 16:45:15 +053024
25/**
26 * Native interface to the NFC Secure Element functions
27 *
28 * {@hide}
29 */
30public class NativeNfcSecureElement {
31
32 static final String PREF_SE_WIRED = "se_wired";
nxpandroid64fd68c2015-09-23 16:45:15 +053033 private final Context mContext;
34
35 SharedPreferences mPrefs;
36 SharedPreferences.Editor mPrefsEditor;
37
38 public NativeNfcSecureElement(Context context) {
39 mContext = context;
40
41 mPrefs = mContext.getSharedPreferences(NativeNfcManager.PREF, Context.MODE_PRIVATE);
42 mPrefsEditor = mPrefs.edit();
43 }
44
nxf500513a018e72019-04-23 17:11:41 +053045 private native int doNativeOpenSecureElementConnection();
nxpandroid64fd68c2015-09-23 16:45:15 +053046
nxf500513a018e72019-04-23 17:11:41 +053047 public int doOpenSecureElementConnection() {
nxpandroid64fd68c2015-09-23 16:45:15 +053048 mPrefsEditor.putBoolean(PREF_SE_WIRED, true);
49 mPrefsEditor.apply();
50
nxf500513a018e72019-04-23 17:11:41 +053051 return doNativeOpenSecureElementConnection();
nxpandroid64fd68c2015-09-23 16:45:15 +053052 }
53
54 private native boolean doNativeDisconnectSecureElementConnection(int handle);
55
56 public boolean doDisconnect(int handle) {
57 mPrefsEditor.putBoolean(PREF_SE_WIRED, false);
58 mPrefsEditor.apply();
59
60 return doNativeDisconnectSecureElementConnection(handle);
61 }
62
63 //TODO: Just stub for compilation
64 public boolean doReset(int handle) {
Anil Hiranniahc1805912019-05-15 21:49:59 +053065 return doResetForEseCosUpdate(handle);
nxpandroid64fd68c2015-09-23 16:45:15 +053066 }
67
68
69 //TODO: Just stub for compilation
70 public byte[] doGetAtr (int handle) {
nxpandroid64fd68c2015-09-23 16:45:15 +053071 return doNativeGetAtr(handle);
72 }
73
74 private native byte[] doNativeGetAtr(int handle);
Anil Hiranniahc1805912019-05-15 21:49:59 +053075 private native boolean doResetForEseCosUpdate(int handle);
nxpandroid64fd68c2015-09-23 16:45:15 +053076 public native byte[] doTransceive(int handle, byte[] data);
77
nxpandroid64fd68c2015-09-23 16:45:15 +053078}