nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | /****************************************************************************** |
| 17 | * |
| 18 | * The original Work has been changed by NXP Semiconductors. |
| 19 | * |
| 20 | * Copyright (C) 2015 NXP Semiconductors |
| 21 | * |
| 22 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 23 | * you may not use this file except in compliance with the License. |
| 24 | * You may obtain a copy of the License at |
| 25 | * |
| 26 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 27 | * |
| 28 | * Unless required by applicable law or agreed to in writing, software |
| 29 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 31 | * See the License for the specific language governing permissions and |
| 32 | * limitations under the License. |
| 33 | * |
| 34 | ******************************************************************************/ |
| 35 | |
| 36 | package com.android.nfc.dhimpl; |
| 37 | |
| 38 | import android.content.Context; |
| 39 | import android.content.SharedPreferences; |
| 40 | |
| 41 | |
| 42 | /** |
| 43 | * Native interface to the NFC Secure Element functions |
| 44 | * |
| 45 | * {@hide} |
| 46 | */ |
| 47 | public class NativeNfcSecureElement { |
| 48 | |
| 49 | static final String PREF_SE_WIRED = "se_wired"; |
| 50 | |
| 51 | private final Context mContext; |
| 52 | |
| 53 | SharedPreferences mPrefs; |
| 54 | SharedPreferences.Editor mPrefsEditor; |
| 55 | |
| 56 | public NativeNfcSecureElement(Context context) { |
| 57 | mContext = context; |
| 58 | |
| 59 | mPrefs = mContext.getSharedPreferences(NativeNfcManager.PREF, Context.MODE_PRIVATE); |
| 60 | mPrefsEditor = mPrefs.edit(); |
| 61 | } |
| 62 | |
nxpandroid | 7d44e57 | 2016-08-01 19:11:04 +0530 | [diff] [blame^] | 63 | private native int doNativeOpenSecureElementConnection(int seId); |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 64 | |
nxpandroid | 7d44e57 | 2016-08-01 19:11:04 +0530 | [diff] [blame^] | 65 | public int doOpenSecureElementConnection(int seId) { |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 66 | mPrefsEditor.putBoolean(PREF_SE_WIRED, true); |
| 67 | mPrefsEditor.apply(); |
| 68 | |
nxpandroid | 7d44e57 | 2016-08-01 19:11:04 +0530 | [diff] [blame^] | 69 | return doNativeOpenSecureElementConnection(seId); |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | private native boolean doNativeDisconnectSecureElementConnection(int handle); |
| 73 | |
| 74 | public boolean doDisconnect(int handle) { |
| 75 | mPrefsEditor.putBoolean(PREF_SE_WIRED, false); |
| 76 | mPrefsEditor.apply(); |
| 77 | |
| 78 | return doNativeDisconnectSecureElementConnection(handle); |
| 79 | } |
| 80 | |
| 81 | //TODO: Just stub for compilation |
| 82 | public boolean doReset(int handle) { |
| 83 | //return false; |
| 84 | return doNativeResetSecureElement(handle); |
| 85 | } |
| 86 | |
| 87 | |
| 88 | //TODO: Just stub for compilation |
| 89 | public byte[] doGetAtr (int handle) { |
| 90 | |
| 91 | return doNativeGetAtr(handle); |
| 92 | } |
| 93 | |
| 94 | private native byte[] doNativeGetAtr(int handle); |
| 95 | private native boolean doNativeResetSecureElement(int handle); |
| 96 | public native byte[] doTransceive(int handle, byte[] data); |
| 97 | |
| 98 | public native int[] doGetTechList(int handle); |
| 99 | |
| 100 | public native byte [] doGetUid(int handle); |
| 101 | } |