rhodes 3.0.0 → 3.0.1.beta.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. data/CHANGELOG +4 -0
  2. data/Rakefile +9 -2
  3. data/doc/application.txt +1 -1
  4. data/doc/build.txt +49 -70
  5. data/doc/device-caps.txt +22 -97
  6. data/doc/extensions.txt +1 -1
  7. data/doc/nfc.txt +542 -0
  8. data/doc/rhom.txt +7 -5
  9. data/doc/simulator.txt +116 -0
  10. data/doc/ui.txt +1 -1
  11. data/lib/build/jake.rb +5 -5
  12. data/lib/extensions/debugger/debugger.rb +63 -35
  13. data/lib/extensions/nfc/ext/nfc/platform/android/AndroidManifest.xml +8 -6
  14. data/lib/extensions/nfc/ext/nfc/platform/android/jni/src/nfc.cpp +1070 -249
  15. data/lib/extensions/nfc/ext/nfc/platform/android/res/xml/filter_nfc.xml +1 -5
  16. data/lib/extensions/nfc/ext/nfc/platform/android/src/com/rhomobile/nfc/Nfc.java +894 -72
  17. data/lib/extensions/nfc/ext/nfc/platform/android/src/com/rhomobile/nfc/NfcActivity.java +82 -18
  18. data/lib/extensions/nfc/ext/nfc/platform/android/src/com/rhomobile/nfc/NfcMessage.java +65 -0
  19. data/lib/extensions/nfc/ext/nfc/platform/android/src/com/rhomobile/nfc/NfcRecord.java +88 -24
  20. data/lib/extensions/nfc/ext/nfc/platform/android/src/com/rhomobile/nfc/NfcTechActivity.java +3 -0
  21. data/lib/extensions/nfc/ext/nfc/shared/ruby/nfc.i +204 -3
  22. data/lib/extensions/nfc/ext/nfc/shared/ruby/nfc_wrap.c +1047 -5
  23. data/lib/extensions/nfc/nfc.rb +635 -91
  24. data/lib/extensions/rhoxml/rexml/encodings/CP-1252.rb +103 -0
  25. data/lib/extensions/rhoxml/rexml/encodings/ISO-8859-1.rb +7 -0
  26. data/lib/framework/dateME.rb +26 -0
  27. data/lib/framework/rho/render.rb +21 -9
  28. data/lib/framework/rho/rho.rb +12 -0
  29. data/lib/framework/rho/rhoevent_bb.rb +3 -0
  30. data/lib/framework/rho/rhoevent_c.rb +3 -0
  31. data/lib/framework/rhodes.rb +1 -1
  32. data/lib/framework/rhom/rhom_db_adapter.rb +9 -9
  33. data/lib/framework/rhosystem.rb +17 -0
  34. data/lib/framework/stringio.rb +18 -0
  35. data/lib/framework/version.rb +1 -1
  36. data/lib/rhodes.rb +1 -1
  37. data/platform/android/Rhodes/AndroidManifest.xml +2 -2
  38. data/platform/android/Rhodes/res/xml/filter_nfc.xml +1 -5
  39. data/platform/android/Rhodes/src/com/rhomobile/rhodes/BaseActivity.java +0 -2
  40. data/platform/android/Rhodes/src/com/rhomobile/rhodes/PushReceiver.java +10 -6
  41. data/platform/android/Rhodes/src/com/rhomobile/rhodes/RhoCryptImpl.java +29 -18
  42. data/platform/android/Rhodes/src/com/rhomobile/rhodes/RhodesActivity.java +67 -12
  43. data/platform/android/Rhodes/src/com/rhomobile/rhodes/RhodesActivityListener.java +14 -0
  44. data/platform/android/Rhodes/src/com/rhomobile/rhodes/RhodesApplication.java +102 -28
  45. data/platform/android/Rhodes/src/com/rhomobile/rhodes/RhodesService.java +35 -66
  46. data/platform/android/Rhodes/src/com/rhomobile/rhodes/WebView.java +5 -5
  47. data/platform/android/Rhodes/src/com/rhomobile/rhodes/alert/Alert.java +69 -41
  48. data/platform/android/Rhodes/src/com/rhomobile/rhodes/alert/PopupActivity.java +7 -5
  49. data/platform/android/Rhodes/src/com/rhomobile/rhodes/util/PerformOnUiThread.java +68 -35
  50. data/platform/android/build/RhodesSRC_build.files +1 -0
  51. data/platform/android/build/android.rake +2 -2
  52. data/platform/bb/RubyVM/src/com/rho/RhoConf.java +1 -0
  53. data/platform/bb/RubyVM/src/com/rho/db/DBAdapter.java +18 -6
  54. data/platform/bb/build/bb.rake +1 -1
  55. data/platform/bb/rhodes/src/rhomobile/RhodesApplication.java +5 -4
  56. data/platform/iphone/Classes/SimpleMainView.m +1 -1
  57. data/platform/iphone/Info.plist +1 -1
  58. data/platform/shared/common/RhodesApp.cpp +9 -3
  59. data/platform/shared/curl/lib/rhossl.c +5 -2
  60. data/platform/shared/db/DBAdapter.cpp +9 -0
  61. data/platform/shared/net/CURLNetRequest.cpp +8 -3
  62. data/platform/shared/net/iphone/sslimpl.cpp +3 -2
  63. data/platform/shared/net/ssl.cpp +8 -0
  64. data/platform/shared/ruby/ext/rho/rhoruby.c +10 -0
  65. data/platform/shared/ruby/ext/rho/rhoruby.h +1 -0
  66. data/platform/shared/ruby/ext/sqlite3_api/sqlite3_api_wrap.c +3 -4
  67. data/platform/win32/RhoSimulator/QtCore4.dll +0 -0
  68. data/platform/win32/RhoSimulator/QtGui4.dll +0 -0
  69. data/platform/win32/RhoSimulator/QtNetwork4.dll +0 -0
  70. data/platform/win32/RhoSimulator/QtWebKit4.dll +0 -0
  71. data/platform/win32/RhoSimulator/RhoSimulator.exe +0 -0
  72. data/platform/win32/RhoSimulator/imageformats/qgif4.dll +0 -0
  73. data/platform/win32/RhoSimulator/imageformats/qico4.dll +0 -0
  74. data/platform/win32/RhoSimulator/imageformats/qjpeg4.dll +0 -0
  75. data/platform/win32/RhoSimulator/imageformats/qmng4.dll +0 -0
  76. data/platform/win32/RhoSimulator/imageformats/qsvg4.dll +0 -0
  77. data/platform/win32/RhoSimulator/imageformats/qtiff4.dll +0 -0
  78. data/platform/win32/RhoSimulator/libeay32.dll +0 -0
  79. data/platform/win32/RhoSimulator/ssleay32.dll +0 -0
  80. data/platform/wm/build/wm.rake +27 -3
  81. data/platform/wm/rhodes/Rhodes.cpp +4 -0
  82. data/platform/wm/rhodes/emulator/MainWindowCallback.h +1 -0
  83. data/platform/wm/rhodes/emulator/MainWindowProxy.cpp +3 -1
  84. data/platform/wm/rhodes/emulator/MainWindowQt.cpp +23 -12
  85. data/platform/wm/rhodes/emulator/MainWindowQt.h +5 -1
  86. data/platform/wm/rhodes/emulator/QtMainWindow.cpp +39 -6
  87. data/platform/wm/rhodes/emulator/QtMainWindow.h +1 -1
  88. data/platform/wm/rhodes/rho/rubyext/SystemImpl.cpp +5 -0
  89. data/platform/wp7/IronRuby/{Bin → bin}/Silverlight3Release/IronRuby.Libraries.dll +0 -0
  90. data/platform/wp7/IronRuby/{Bin → bin}/Silverlight3Release/IronRuby.dll +0 -0
  91. data/platform/wp7/IronRuby/bin/Silverlight3Release/Microsoft.Dynamic.dll +0 -0
  92. data/platform/wp7/IronRuby/{Bin → bin}/Silverlight3Release/Microsoft.Scripting.Core.dll +0 -0
  93. data/platform/wp7/IronRuby/{Bin → bin}/Silverlight3Release/Microsoft.Scripting.dll +0 -0
  94. data/platform/wp7/RhoAppRunner/Program.cs +2 -2
  95. data/platform/wp7/RhoRubyLib/RhoRuby.cs +8 -0
  96. data/platform/wp7/RhoRubyLib/common/RhodesApp.cs +29 -7
  97. data/platform/wp7/RhoRubyLib/db/DBAdapter.cs +5 -2
  98. data/platform/wp7/RhoRubyLib/logging/RhoLogger.cs +12 -0
  99. data/platform/wp7/RhoRubyLib/net/HttpServer.cs +2 -0
  100. data/platform/wp7/RhoRubyLib/net/NetRequest.cs +1 -1
  101. data/platform/wp7/RhoRubyLib/rubyext/RhoAsyncHttp.cs +52 -7
  102. data/platform/wp7/RhoRubyLib/rubyext/RhoDatabase.cs +85 -18
  103. data/platform/wp7/RhoRubyLib/rubyext/RhoJSON.cs +38 -3
  104. data/platform/wp7/RhoRubyLib/rubyext/RhoKernelOps.cs +27 -2
  105. data/platform/wp7/RhoRubyLib/rubyext/RhoNativeBar.cs +111 -15
  106. data/platform/wp7/RhoRubyLib/rubyext/RhoSyncEngine.cs +330 -55
  107. data/platform/wp7/RhoRubyLib/rubyext/RhoWebView.cs +61 -4
  108. data/platform/wp7/build/wp.rake +89 -72
  109. data/platform/wp7/rhodes/App.xaml.cs +1 -1
  110. data/rakefile.rb +9 -2
  111. data/rhodes.gemspec +1 -3
  112. data/spec/phone_spec/app/spec/asynchttp_spec.rb +7 -9
  113. data/spec/phone_spec/app/spec/uri_spec.rb +75 -0
  114. data/spec/phone_spec/app/spec_runner.rb +4 -0
  115. metadata +21 -15
  116. data/Manifest.txt +0 -6403
  117. data/platform/win32/RhoSimulator/codecs/qcncodecs4.dll +0 -0
  118. data/platform/win32/RhoSimulator/codecs/qjpcodecs4.dll +0 -0
  119. data/platform/win32/RhoSimulator/codecs/qkrcodecs4.dll +0 -0
  120. data/platform/win32/RhoSimulator/codecs/qtwcodecs4.dll +0 -0
  121. data/platform/wp7/IronRuby/Bin/Silverlight3Release/Microsoft.Dynamic.dll +0 -0
@@ -4,10 +4,6 @@
4
4
  <tech>android.nfc.tech.MifareClassic</tech>
5
5
  </tech-list>
6
6
  <tech-list>
7
- <tech>android.nfc.tech.MifareUltralight</tech>
8
- </tech-list>
9
- <tech-list>
10
- <tech>android.nfc.tech.MifareClassic</tech>
11
- <tech>android.nfc.tech.MifareUltralight</tech>
7
+ <tech>android.nfc.tech.Ndef</tech>
12
8
  </tech-list>
13
9
  </resources>
@@ -1,36 +1,56 @@
1
1
  package com.rhomobile.nfc;
2
2
 
3
3
  import java.io.IOException;
4
+ import java.util.ArrayList;
5
+ import java.util.Hashtable;
6
+ import java.util.Iterator;
7
+ import java.util.Map;
8
+ import java.util.Set;
4
9
 
5
10
  import android.app.Activity;
11
+ import android.app.PendingIntent;
6
12
  import android.content.BroadcastReceiver;
7
13
  import android.content.Context;
8
14
  import android.content.Intent;
15
+ import android.content.IntentFilter;
16
+ import android.net.Uri;
17
+ import android.nfc.FormatException;
9
18
  import android.nfc.NdefMessage;
10
19
  import android.nfc.NdefRecord;
11
20
  import android.nfc.NfcAdapter;
21
+ import android.nfc.NfcManager;
12
22
  import android.nfc.Tag;
23
+ import android.nfc.tech.IsoDep;
13
24
  import android.nfc.tech.MifareClassic;
14
25
  import android.nfc.tech.MifareUltralight;
26
+ import android.nfc.tech.Ndef;
27
+ import android.nfc.tech.NdefFormatable;
28
+ import android.nfc.tech.NfcA;
29
+ import android.nfc.tech.NfcB;
30
+ import android.nfc.tech.NfcF;
31
+ import android.nfc.tech.NfcV;
32
+ import android.nfc.tech.TagTechnology;
15
33
  import android.os.Build;
16
34
  import android.os.Bundle;
17
35
  import android.os.Parcelable;
18
36
  import android.util.Log;
19
37
 
20
- import com.rhomobile.rhodes.PushService;
21
38
  import com.rhomobile.rhodes.RhodesActivity;
39
+ import com.rhomobile.rhodes.RhodesActivityListener;
22
40
  import com.rhomobile.rhodes.RhodesService;
23
41
  import com.rhomobile.rhodes.Utils;
42
+ import com.rhomobile.rhodes.util.PerformOnUiThread;
24
43
 
25
- public class Nfc {
44
+ public class Nfc implements RhodesActivityListener {
26
45
 
27
-
28
46
  private static final String TAG = Nfc.class.getSimpleName();
29
47
 
30
48
  private static boolean ourIsEnable = false;
31
49
  private static String ourCallback = null;
32
50
  private static String ourTechCallback = null;
33
51
 
52
+ private static NdefMessage ourP2PNdefMessage = null;
53
+
34
54
  private static Nfc ourInstance = null;
35
55
 
36
56
  private static native void callCallback(String callback_url, NfcMessagePack msgpack);
@@ -38,12 +58,56 @@ public class Nfc {
38
58
 
39
59
  private static Tag ourTag = null;
40
60
 
41
-
42
61
  private MifareClassic mMifareClassic = null;
43
62
  private MifareUltralight mMifareUltralight = null;
63
+ private Ndef mNdef = null;
64
+ private NfcA mNfcA = null;
65
+ private IsoDep mIsoDep = null;
66
+ private NdefFormatable mNdefFormatable = null;
67
+ private NfcB mNfcB = null;
68
+ private NfcF mNfcF = null;
69
+ private NfcV mNfcV = null;
70
+ private ArrayList<String> mTechList = null;
71
+ private Hashtable<String,TagTechnology> mTechs = null;
72
+
73
+ private static final boolean isLogging = false;
74
+
75
+ private static native void logNative(String msg);
44
76
 
45
- private String[] mTechList = null;
46
77
 
78
+ private static NdefMessage[] ourApplicationStartupMessages = null;
79
+ private static Tag ourApplicationStartupTag = null;
80
+
81
+ public static void setApplicationStartupIntent(Intent intent) {
82
+ getInstance().onNewIntent(null, intent, true);
83
+ }
84
+
85
+ public static void performOpenApplicationTag() {
86
+ PerformOnUiThread.exec(new Runnable() {
87
+ public void run() {
88
+ if (ourApplicationStartupMessages != null) {
89
+ getInstance().onReceiveMessages(ourApplicationStartupMessages);
90
+ ourApplicationStartupMessages = null;
91
+ }
92
+ if (ourApplicationStartupTag != null) {
93
+ getInstance().onReceiveTag(ourApplicationStartupTag);
94
+ ourApplicationStartupTag = null;
95
+ }
96
+ }
97
+ }, 100);
98
+ }
99
+
100
+
101
+ public static void log(String msg) {
102
+ //logNative(msg);
103
+ if (isLogging) {
104
+ Utils.platformLog(TAG, msg);
105
+ }
106
+ }
107
+
108
+ public static void loge(String msg) {
109
+ Utils.platformLog(TAG, msg);
110
+ }
47
111
 
48
112
  public static Nfc getInstance() {
49
113
  if (ourInstance == null) {
@@ -86,9 +150,182 @@ public class Nfc {
86
150
  }
87
151
 
88
152
  public static void setEnable(int enable) {
153
+ log(" $$$$$$$$$ setEnable() START() ");
154
+ boolean oldEnable = ourIsEnable;
89
155
  ourIsEnable = (enable != 0);
156
+ if ((oldEnable == false) && (ourIsEnable == true)) {
157
+ RhodesActivity.safeGetInstance().addRhodesActivityListener(getInstance());
158
+ PerformOnUiThread.exec( new Runnable() {
159
+ public void run() {
160
+ if (RhodesActivity.safeGetInstance().isForegroundNow()) {
161
+ getInstance().onResume(RhodesActivity.safeGetInstance());
162
+ }
163
+ }
164
+ });
165
+ }
166
+ if ((oldEnable == true) && (ourIsEnable == false)) {
167
+ RhodesActivity.safeGetInstance().removeRhodesActivityListener(getInstance());
168
+ PerformOnUiThread.exec( new Runnable() {
169
+ public void run() {
170
+ if (RhodesActivity.safeGetInstance().isForegroundNow()) {
171
+ getInstance().onPause(RhodesActivity.safeGetInstance());
172
+ }
173
+ }
174
+ });
175
+ }
176
+ log(" $$$$$$$$$ setEnable() FINISH() ");
177
+ }
178
+
179
+ public void onPause(RhodesActivity activity) {
180
+ log(" $$$$$$$$$ onPause() ");
181
+ NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(RhodesActivity.getContext());
182
+ if (nfcAdapter != null) {
183
+ nfcAdapter.disableForegroundDispatch(activity);
184
+ nfcAdapter.disableForegroundNdefPush(activity);
185
+ }
186
+ }
187
+
188
+ public void onResume(RhodesActivity activity) {
189
+ log(" $$$$$$$$$ onResume() ");
190
+ NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(RhodesActivity.getContext());
191
+ if (nfcAdapter != null) {
192
+ IntentFilter[] filters = new IntentFilter[1];
193
+ filters[0] = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
194
+
195
+ PendingIntent intent =
196
+ PendingIntent.getActivity(activity, 0,
197
+ new Intent(activity, activity.getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP),
198
+ 0);
199
+
200
+ nfcAdapter.enableForegroundDispatch(activity, intent, null, null);
201
+ if (ourP2PNdefMessage != null) {
202
+ nfcAdapter.enableForegroundNdefPush(activity, ourP2PNdefMessage);
203
+ }
204
+ }
205
+ }
206
+
207
+ public void onNewIntent(RhodesActivity activity, Intent intent, boolean postpone) {
208
+ String action = intent.getAction();
209
+
210
+ log(" $$$$$$$$$ onNewIntent !!! Action = "+action);
211
+
212
+ if (NfcAdapter.ACTION_TAG_DISCOVERED.equals(action)) {
213
+ log("ACTION_TAG_DISCOVERED !");
214
+ Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
215
+ NdefMessage[] msgs;
216
+ if (rawMsgs != null) {
217
+ log(" Found rawMessages from Intent !");
218
+ msgs = new NdefMessage[rawMsgs.length];
219
+ for (int i = 0; i < rawMsgs.length; i++) {
220
+ msgs[i] = (NdefMessage) rawMsgs[i];
221
+ }
222
+ } else {
223
+ // Unknown tag type
224
+ log(" Intent not have any Messages !");
225
+ byte[] empty = new byte[] {};
226
+ NdefRecord record = new NdefRecord(NdefRecord.TNF_UNKNOWN, empty, empty, empty);
227
+ NdefMessage msg = new NdefMessage(new NdefRecord[] {record});
228
+ msgs = new NdefMessage[] {msg};
229
+ }
230
+ if (postpone) {
231
+ ourApplicationStartupMessages = msgs;
232
+ }
233
+ else {
234
+ getInstance().onReceiveMessages(msgs);
235
+ }
236
+ Tag tag = (Tag)intent.getExtras().get(NfcAdapter.EXTRA_TAG);
237
+ if (tag != null) {
238
+ log(" Tag found in extars ! ");
239
+ if (postpone) {
240
+ ourApplicationStartupTag = tag;
241
+ }
242
+ else {
243
+ getInstance().onReceiveTag(tag);
244
+ }
245
+ }
246
+ else {
247
+ log(" Tag not found in extars ! ");
248
+ }
249
+ }
250
+ if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)) {
251
+ log("ACTION_NDEF_DISCOVERED !");
252
+ Uri u = intent.getData();
253
+
254
+ if (u != null) {
255
+ log(" Data = "+u.toString());
256
+ }
257
+ else {
258
+ log(" Data = NULL");
259
+ }
260
+ String t = intent.getType();
261
+ if (t != null) {
262
+ log(" Type = "+t);
263
+ }
264
+ else {
265
+ log(" Type is NULL= ");
266
+ }
267
+
268
+ Tag tag = (Tag)intent.getExtras().get(NfcAdapter.EXTRA_TAG);
269
+ if (tag != null) {
270
+ log(" Tag found in extars ! ");
271
+ }
272
+ else {
273
+ log(" Tag not found in extars ! ");
274
+ }
275
+
276
+
277
+ Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
278
+ NdefMessage[] msgs;
279
+ if (rawMsgs != null) {
280
+ msgs = new NdefMessage[rawMsgs.length];
281
+ for (int i = 0; i < rawMsgs.length; i++) {
282
+ msgs[i] = (NdefMessage) rawMsgs[i];
283
+ }
284
+ } else {
285
+ // Unknown tag type
286
+ log(" Unknown Tag type !!!");
287
+ byte[] empty = new byte[] {};
288
+ NdefRecord record = new NdefRecord(NdefRecord.TNF_UNKNOWN, empty, empty, empty);
289
+ NdefMessage msg = new NdefMessage(new NdefRecord[] {record});
290
+ msgs = new NdefMessage[] {msg};
291
+ }
292
+ if (postpone) {
293
+ ourApplicationStartupMessages = msgs;
294
+ }
295
+ else {
296
+ getInstance().onReceiveMessages(msgs);
297
+ }
298
+
299
+ if (tag != null) {
300
+ if (postpone) {
301
+ ourApplicationStartupTag = tag;
302
+ }
303
+ else {
304
+ getInstance().onReceiveTag(tag);
305
+ }
306
+ }
307
+ }
308
+ if (NfcAdapter.ACTION_TECH_DISCOVERED.equals(action)) {
309
+ log("ACTION_TECH_DISCOVERED !");
310
+ Tag tag = (Tag)intent.getExtras().get(NfcAdapter.EXTRA_TAG);
311
+ if (tag != null) {
312
+ if (postpone) {
313
+ ourApplicationStartupTag = tag;
314
+ }
315
+ else {
316
+ getInstance().onReceiveTag(tag);
317
+ }
318
+ }
319
+ }
320
+ }
321
+
322
+ public void onNewIntent(RhodesActivity activity, Intent intent) {
323
+ onNewIntent(activity, intent, false);
90
324
  }
91
325
 
326
+
327
+
328
+
92
329
  public static void setCallback(String callback) {
93
330
  ourCallback = callback;
94
331
  }
@@ -106,65 +343,112 @@ public class Nfc {
106
343
 
107
344
 
108
345
  public void onReceiveTag(Tag tag) {
346
+ //if (!ourIsEnable) {
347
+ // return;
348
+ //}
349
+
350
+ log("onReceiveTag()");
109
351
  if (tag == null) {
110
352
  return;
111
353
  }
112
354
 
113
355
  ourTag = tag;
114
356
 
115
- int count = 0;
357
+ mTechs = new Hashtable<String,TagTechnology>();
358
+ mTechList = new ArrayList<String>();
359
+
116
360
  mMifareClassic = MifareClassic.get(tag);
117
361
  mMifareUltralight = MifareUltralight.get(tag);
118
-
362
+ mNdef = Ndef.get(tag);
363
+ mNfcA = NfcA.get(tag);
364
+ mIsoDep = IsoDep.get(tag);
365
+ mNdefFormatable = NdefFormatable.get(tag);
366
+ mNfcB = NfcB.get(tag);
367
+ mNfcF = NfcF.get(tag);
368
+ mNfcV = NfcV.get(tag);
369
+
119
370
  if (mMifareClassic != null) {
120
- count++;
371
+ mTechs.put("MifareClassic", mMifareClassic);
372
+ if (isLogging) {
373
+ log(" MifareClassic found !");
374
+ log(" MifareClassic.block_count() = "+String.valueOf(mMifareClassic.getBlockCount()));
375
+ log(" MifareClassic.sector_count() = "+String.valueOf(mMifareClassic.getSectorCount()));
376
+ log(" MifareClassic.size() = "+String.valueOf(mMifareClassic.getSize()));
377
+ }
121
378
  }
122
379
  if (mMifareUltralight != null) {
123
- count++;
380
+ mTechs.put("MifareUltralight", mMifareClassic);
124
381
  }
125
- mTechList = new String[count];
126
-
127
- count = 0;
128
- if (mMifareClassic != null) {
129
- mTechList[count++] = "MifareClassic";
382
+ if (mNdef != null) {
383
+ mTechs.put("Ndef", mNdef);
130
384
  }
131
- if (mMifareUltralight != null) {
132
- mTechList[count++] = "MifareUltralight";
385
+ if (mNfcA != null) {
386
+ mTechs.put("NfcA", mNfcA);
387
+ }
388
+ if (mIsoDep != null) {
389
+ mTechs.put("IsoDep", mIsoDep);
390
+ }
391
+ if (mNdefFormatable != null) {
392
+ mTechs.put("NdefFormatable", mNdefFormatable);
393
+ }
394
+ if (mNfcB != null) {
395
+ mTechs.put("NfcB", mNfcB);
396
+ }
397
+ if (mNfcF != null) {
398
+ mTechs.put("NfcF", mNfcF);
399
+ }
400
+ if (mNfcV != null) {
401
+ mTechs.put("NfcV", mNfcV);
402
+ }
403
+
404
+ Set<String> keys = mTechs.keySet();
405
+ Iterator<String> iterator = keys.iterator();
406
+ while (iterator.hasNext()) {
407
+ String key = iterator.next();
408
+ mTechList.add(key);
133
409
  }
134
410
 
135
- Utils.platformLog(TAG, "NFC TAG Tech Received ! Service started = "+String.valueOf(isRhodesApplicationRun()));
411
+ log("NFC TAG Tech Received ! Service started = "+String.valueOf(isRhodesApplicationRun()));
136
412
 
137
413
  if (isRhodesApplicationRun()) {
138
414
  if (ourIsEnable) {
139
415
  if (ourTechCallback != null) {
140
416
  if (ourTechCallback.length() > 0) {
417
+ log("call Tech callback !");
141
418
  callTechCallback(ourTechCallback, "discovered");
142
419
  }
143
420
  else {
144
- Utils.platformLog(TAG, "Nfc callback is empty");
421
+ log("Nfc callback is empty");
145
422
  }
146
423
  }
147
424
  else {
148
- Utils.platformLog(TAG, "Nfc callback is null");
425
+ log("Nfc callback is null");
149
426
  }
150
427
  }
151
428
  else {
152
- Utils.platformLog(TAG, "Nfc is not enabled");
429
+ log("Nfc is not enabled");
153
430
  }
154
431
  }
432
+ else {
433
+ log("Rhodes application is not runned");
434
+ }
155
435
 
156
436
  }
157
437
 
158
438
  public void onReceiveMessages(NdefMessage[] msgs) {
439
+ //if (!ourIsEnable) {
440
+ // return;
441
+ //}
442
+ log("onReceiveMessages()");
159
443
  if (msgs == null || msgs.length == 0) {
160
444
  return;
161
445
  }
162
446
 
163
- Utils.platformLog(TAG, "NFC TAG Received ! Service started = "+String.valueOf(isRhodesApplicationRun()));
447
+ log("NFC TAG(with NDE Messages) Received ! Service started = "+String.valueOf(isRhodesApplicationRun()));
164
448
 
165
449
  NfcMessagePack pack = new NfcMessagePack(msgs);
166
450
 
167
- Utils.platformLog(TAG, "Message Pack created");
451
+ log("Message Pack created");
168
452
  if (isRhodesApplicationRun()) {
169
453
  if (ourIsEnable) {
170
454
  if (ourCallback != null) {
@@ -172,18 +456,17 @@ public class Nfc {
172
456
  callCallback(ourCallback, pack);
173
457
  }
174
458
  else {
175
- Utils.platformLog(TAG, "Nfc callback is empty");
459
+ log("Nfc callback is empty");
176
460
  }
177
461
  }
178
462
  else {
179
- Utils.platformLog(TAG, "Nfc callback is null");
463
+ log("Nfc callback is null");
180
464
  }
181
465
  }
182
466
  else {
183
- Utils.platformLog(TAG, "Nfc is not enabled");
467
+ log("Nfc is not enabled");
184
468
  }
185
469
  }
186
-
187
470
  }
188
471
 
189
472
 
@@ -196,94 +479,633 @@ public class Nfc {
196
479
  }
197
480
 
198
481
  public static int get_tech_list_count() {
199
- return getInstance().mTechList.length;
482
+ return getInstance().mTechList.size();
200
483
  }
201
484
 
202
485
  public static String get_tech_list(int index) {
203
- return getInstance().mTechList[index];
486
+ return getInstance().mTechList.get(index);
204
487
  }
488
+
205
489
 
206
490
  public static void tech_connect(String tech_name) {
207
- if (tech_name.equals("MifareClassic")) {
491
+ log("tech_connect("+tech_name+") START");
492
+ if (getInstance().mTechs == null) {
493
+ log(" tech list is empty");
494
+ return;
495
+ }
496
+ TagTechnology tech = getInstance().mTechs.get(tech_name);
497
+ if (tech == null) {
498
+ log(" tech is not supported by current Tag");
499
+ return;
500
+ }
501
+ try {
502
+ tech.connect();
503
+ } catch (IOException e) {
504
+ loge("Exception in tech_connect()");
505
+ e.printStackTrace();
506
+ }
507
+ log("tech_connect("+tech_name+") FINISH");
508
+ }
509
+
510
+ public static void tech_close(String tech_name) {
511
+ if (getInstance().mTechs == null) {
512
+ return;
513
+ }
514
+ TagTechnology tech = getInstance().mTechs.get(tech_name);
515
+ if (tech == null) {
516
+ return;
517
+ }
518
+ try {
519
+ tech.close();
520
+ } catch (IOException e) {
521
+ loge("Exception in tech_close()");
522
+ e.printStackTrace();
523
+ }
524
+ }
525
+
526
+ public static int tech_is_connected(String tech_name) {
527
+ if (getInstance().mTechs == null) {
528
+ log ("tech_is_connected("+tech_name+") return FALSE because tech list is empty");
529
+ return 0;
530
+ }
531
+ TagTechnology tech = getInstance().mTechs.get(tech_name);
532
+ if (tech == null) {
533
+ log ("tech_is_connected("+tech_name+") return FALSE because tech is not supported");
534
+ return 0;
535
+ }
536
+ if (tech.isConnected()) {
537
+ log ("tech_is_connected("+tech_name+") return TRUE");
538
+ return 1;
539
+ }
540
+ log ("tech_is_connected("+tech_name+") return FALSE");
541
+ return 0;
542
+ }
543
+
544
+ public static int tech_MifareClassic_get_size() {
545
+ if (getInstance().mMifareClassic != null)
546
+ return getInstance().mMifareClassic.getSize();
547
+ return 0;
548
+ }
549
+
550
+ public static int tech_MifareClassic_get_block_count() {
551
+ if (getInstance().mMifareClassic != null)
552
+ return getInstance().mMifareClassic.getBlockCount();
553
+ return 0;
554
+ }
555
+
556
+ public static int tech_MifareClassic_get_sector_count() {
557
+ if (getInstance().mMifareClassic != null)
558
+ return getInstance().mMifareClassic.getSectorCount();
559
+ return 0;
560
+ }
561
+
562
+ public static int tech_MifareClassic_get_blocks_in_sector_count(int index) {
563
+ if (getInstance().mMifareClassic != null)
564
+ return getInstance().mMifareClassic.getBlockCountInSector(index);
565
+ return 0;
566
+ }
567
+
568
+ public static int tech_MifareClassic_get_type() {
569
+ if (getInstance().mMifareClassic != null)
570
+ return getInstance().mMifareClassic.getType();
571
+ return -2;
572
+ }
573
+
574
+ public static byte[] tech_MifareClassic_transceive(byte[] data) {
575
+ log ("tech_MifareClassic_transceive() START");
576
+
577
+ if (getInstance().mMifareClassic == null) {
578
+ log (" MifareClassic is not supported in current Tag");
579
+ return null;
580
+ }
581
+ byte[] result = null;
582
+ try {
583
+ result = getInstance().mMifareClassic.transceive(data);
584
+ } catch (IOException e) {
585
+ loge(" Exception in tech_MifareClassic_transceive()");
586
+ e.printStackTrace();
587
+ }
588
+ log("tech_MifareClassic_transceive() FINISH");
589
+ return result;
590
+ }
591
+
592
+ public static byte[] tag_get_id() {
593
+ if (ourTag == null) {
594
+ return null;
595
+ }
596
+ return ourTag.getId();
597
+ }
598
+
599
+
600
+ public static int tech_MifareClassic_sector_to_block(int index) {
601
+ if (getInstance().mMifareClassic != null)
602
+ return getInstance().mMifareClassic.sectorToBlock(index);
603
+ return 0;
604
+ }
605
+
606
+ public static int tech_MifareClassic_authenticate_sector_with_key_A(int index, byte[] key) {
607
+ if (getInstance().mMifareClassic != null) {
208
608
  try {
209
- if (getInstance().mMifareClassic != null)
210
- getInstance().mMifareClassic.connect();
211
- } catch (IOException e) {
212
- // TODO Auto-generated catch block
213
- e.printStackTrace();
609
+ boolean auth = getInstance().mMifareClassic.authenticateSectorWithKeyA(index, key);
610
+ if (auth) {
611
+ return 1;
612
+ }
613
+ }
614
+ catch (IOException e) {
615
+ loge("IOException in tech_MifareClassic_authenticate_sector_with_key_A()");
214
616
  }
215
617
  }
216
- if (tech_name.equals("MifareUltralight")) {
618
+ return 0;
619
+ }
620
+
621
+ public static int tech_MifareClassic_authenticate_sector_with_key_B(int index, byte[] key) {
622
+ if (getInstance().mMifareClassic != null) {
217
623
  try {
218
- if (getInstance().mMifareUltralight != null)
219
- getInstance().mMifareUltralight.connect();
220
- } catch (IOException e) {
221
- // TODO Auto-generated catch block
222
- e.printStackTrace();
624
+ boolean auth = getInstance().mMifareClassic.authenticateSectorWithKeyB(index, key);
625
+ if (auth) {
626
+ return 1;
627
+ }
628
+ }
629
+ catch (IOException e) {
630
+ loge("IOException in tech_MifareClassic_authenticate_sector_with_key_B()");
223
631
  }
224
632
  }
633
+ return 0;
634
+ }
635
+
636
+ public static void tech_MifareClassic_write_block(int index, byte[] block) {
637
+ log ("tech_MifareClassic_write_block("+String.valueOf(index)+") START");
638
+
639
+ if (getInstance().mMifareClassic == null) {
640
+ log (" MifareClassic is not supported in current Tag");
641
+ return;
642
+ }
643
+ try {
644
+ getInstance().mMifareClassic.writeBlock(index, block);
645
+ } catch (IOException e) {
646
+ loge(" Exception in tech_MifareClassic_write_block("+String.valueOf(index)+")");
647
+ e.printStackTrace();
648
+ }
649
+ log("tech_MifareClassic_read_block("+String.valueOf(index)+") FINISH");
650
+
225
651
  }
226
652
 
227
- public static void tech_close(String tech_name) {
228
- if (tech_name.equals("MifareClassic")) {
653
+ public static int tech_MifareClassic_read_block(int index, byte[] block) {
654
+ log ("tech_MifareClassic_read_block("+String.valueOf(index)+") START");
655
+
656
+ int i;
657
+ for (i = 0; i < 16; i++) {
658
+ block[i] = 0;
659
+ }
660
+
661
+ if (getInstance().mMifareClassic == null) {
662
+ log (" MifareClassic is not supported in current Tag");
663
+ return 0;
664
+ }
665
+ byte[] readed_block = null;
666
+ try {
667
+ readed_block = getInstance().mMifareClassic.readBlock(index);
668
+ } catch (IOException e) {
669
+ loge(" Exception in tech_MifareClassic_read_block("+String.valueOf(index)+")");
670
+ e.printStackTrace();
671
+ }
672
+ if (readed_block == null) {
673
+ log (" null array returned !");
674
+ return 0;
675
+ }
676
+ StringBuffer s = new StringBuffer();
677
+ s.append(" block is : ");
678
+ for (i = 0; (i < readed_block.length) && (i < block.length); i++) {
679
+ block[i] = readed_block[i];
680
+ s.append(block[i]);
681
+ s.append(":");
682
+ }
683
+ log(s.toString());
684
+ log("tech_MifareClassic_read_block("+String.valueOf(index)+") FINISH");
685
+ return 1;
686
+ }
687
+
688
+
689
+
690
+ public static int tech_Ndef_get_max_size() {
691
+ if (getInstance().mNdef != null)
692
+ return getInstance().mNdef.getMaxSize();
693
+ return 0;
694
+ }
695
+
696
+ public static String tech_Ndef_get_type() {
697
+ if (getInstance().mNdef != null)
698
+ return getInstance().mNdef.getType();
699
+ return null;
700
+ }
701
+
702
+ public static int tech_Ndef_is_writable() {
703
+ int res = 0;
704
+ if (getInstance().mNdef != null)
705
+ if (getInstance().mNdef.isWritable()) {
706
+ res = 1;
707
+ }
708
+ return res;
709
+ }
710
+
711
+ public static int tech_Ndef_can_make_read_only() {
712
+ int res = 0;
713
+ if (getInstance().mNdef != null)
714
+ if (getInstance().mNdef.canMakeReadOnly()) {
715
+ res = 1;
716
+ }
717
+ return res;
718
+ }
719
+
720
+ public static int tech_Ndef_make_read_only() {
721
+ int res = 0;
722
+ if (getInstance().mNdef != null)
229
723
  try {
230
- if (getInstance().mMifareClassic != null)
231
- getInstance().mMifareClassic.close();
724
+ if (getInstance().mNdef.makeReadOnly()) {
725
+ res = 1;
726
+ }
232
727
  } catch (IOException e) {
233
- // TODO Auto-generated catch block
728
+ loge(" Exception in tech_Ndef_make_read_only()");
234
729
  e.printStackTrace();
235
730
  }
731
+ return res;
732
+ }
733
+
734
+ public static void tech_Ndef_write_Nde_message(byte[] message) {
735
+ /*
736
+ if (message != null) {
737
+ Utils.platformLog("MSG", " ID = "+message.toString());
738
+
739
+ StringBuffer s = new StringBuffer();
740
+ s.append(" Message is ["+String.valueOf(message.length)+"] : ");
741
+ int i;
742
+ for (i = 0; i < message.length; i++) {
743
+ s.append(message[i]);
744
+ s.append(":");
745
+ }
746
+ Utils.platformLog("MSG", s.toString());
747
+
748
+
749
+ }
750
+ else {
751
+ Utils.platformLog("MSG", " message is NULL !!!");
752
+ }
753
+ */
754
+ try {
755
+ NdefMessage m = new NdefMessage(message);
756
+ if (getInstance().mNdef != null) {
757
+ getInstance().mNdef.writeNdefMessage(m);
758
+ }
759
+ } catch (FormatException e) {
760
+ loge("Format exception in tech_Ndef_write_Nde_message()");
761
+ e.printStackTrace();
762
+ } catch (IOException e) {
763
+ loge("IO exception in tech_Ndef_write_Nde_message()");
764
+ e.printStackTrace();
236
765
  }
237
- if (tech_name.equals("MifareUltralight")) {
766
+ }
767
+
768
+ public static byte[] tech_Ndef_read_Nde_message() {
769
+ NdefMessage m = null;
770
+ if (getInstance().mNdef != null) {
238
771
  try {
239
- if (getInstance().mMifareUltralight != null)
240
- getInstance().mMifareUltralight.close();
772
+ m = getInstance().mNdef.getNdefMessage();
241
773
  } catch (IOException e) {
242
- // TODO Auto-generated catch block
774
+ loge("IO exception in tech_Ndef_read_Nde_message()");
775
+ e.printStackTrace();
776
+ } catch (FormatException e) {
777
+ loge("Format exception in tech_Ndef_read_Nde_message()");
243
778
  e.printStackTrace();
244
779
  }
245
780
  }
781
+ if (m != null) {
782
+ return m.toByteArray();
783
+ }
784
+ return null;
246
785
  }
247
-
248
- public static int tech_is_connected(String tech_name) {
249
- if (tech_name.equals("MifareClassic")) {
250
- if (getInstance().mMifareClassic != null)
251
- if (getInstance().mMifareClassic.isConnected() )
252
- return 1;
786
+
787
+ public static byte[] tech_NfcA_get_Atqa() {
788
+ if (getInstance().mNfcA != null) {
789
+ return getInstance().mNfcA.getAtqa();
253
790
  }
254
- if (tech_name.equals("MifareUltralight")) {
255
- if (getInstance().mMifareUltralight != null)
256
- if (getInstance().mMifareUltralight.isConnected() )
257
- return 1;
791
+ return null;
792
+ }
793
+
794
+ public static int tech_NfcA_get_Sak() {
795
+ if (getInstance().mNfcA != null) {
796
+ return getInstance().mNfcA.getSak();
258
797
  }
259
798
  return 0;
260
799
  }
261
-
262
- public static int tech_MifareClassic_get_size() {
800
+
801
+ public static byte[] tech_NfcA_transceive(byte[] data) {
802
+ if (getInstance().mNfcA == null) {
803
+ log (" mNfcA is not supported in current Tag");
804
+ return null;
805
+ }
806
+ byte[] result = null;
807
+ try {
808
+ result = getInstance().mNfcA.transceive(data);
809
+ } catch (IOException e) {
810
+ loge(" Exception in tech_NfcA_transceive()");
811
+ e.printStackTrace();
812
+ }
813
+ return result;
814
+ }
815
+
816
+
817
+ public static byte[] tech_IsoDep_get_hi_layer_responce() {
818
+ if (getInstance().mIsoDep != null) {
819
+ return getInstance().mIsoDep.getHiLayerResponse();
820
+ }
821
+ return null;
822
+ }
823
+
824
+ public static byte[] tech_IsoDep_get_historical_bytes() {
825
+ if (getInstance().mIsoDep != null) {
826
+ return getInstance().mIsoDep.getHistoricalBytes();
827
+ }
828
+ return null;
829
+ }
830
+
831
+ public static void tech_IsoDep_set_timeout(int timeout) {
832
+ if (getInstance().mIsoDep != null) {
833
+ getInstance().mIsoDep.setTimeout(timeout);
834
+ }
835
+ }
836
+
837
+ public static byte[] tech_IsoDep_transceive(byte[] data) {
838
+ if (getInstance().mIsoDep == null) {
839
+ log (" IsoDep is not supported in current Tag");
840
+ return null;
841
+ }
842
+ byte[] result = null;
843
+ try {
844
+ result = getInstance().mIsoDep.transceive(data);
845
+ } catch (IOException e) {
846
+ loge(" Exception in tech_mIsoDep_transceive()");
847
+ e.printStackTrace();
848
+ }
849
+ return result;
850
+ }
851
+
852
+ public static void tech_NdefFormatable_format(byte[] ndef_message_byte_array) {
853
+ try {
854
+ NdefMessage m = new NdefMessage(ndef_message_byte_array);
855
+ if (getInstance().mNdefFormatable != null) {
856
+ getInstance().mNdefFormatable.format(m);
857
+ }
858
+ } catch (FormatException e) {
859
+ loge("Format exception in tech_NdefFormatable_format()");
860
+ e.printStackTrace();
861
+ } catch (IOException e) {
862
+ loge("IO exception in tech_NdefFormatable_format()");
863
+ e.printStackTrace();
864
+ }
865
+ }
866
+
867
+ public static void tech_NdefFormatable_format_read_only(byte[] ndef_message_byte_array) {
868
+ try {
869
+ NdefMessage m = new NdefMessage(ndef_message_byte_array);
870
+ if (getInstance().mNdefFormatable != null) {
871
+ getInstance().mNdefFormatable.formatReadOnly(m);
872
+ }
873
+ } catch (FormatException e) {
874
+ loge("Format exception in tech_NdefFormatable_format_read_only()");
875
+ e.printStackTrace();
876
+ } catch (IOException e) {
877
+ loge("IO exception in tech_NdefFormatable_format_read_only()");
878
+ e.printStackTrace();
879
+ }
880
+ }
881
+
882
+ public static byte[] tech_NfcB_get_application_data() {
883
+ if (getInstance().mNfcB != null) {
884
+ return getInstance().mNfcB.getApplicationData();
885
+ }
886
+ return null;
887
+ }
888
+
889
+ public static byte[] tech_NfcB_get_protocol_info() {
890
+ if (getInstance().mNfcB != null) {
891
+ return getInstance().mNfcB.getProtocolInfo();
892
+ }
893
+ return null;
894
+ }
895
+
896
+ public static byte[] tech_NfcB_transceive(byte[] data) {
897
+ if (getInstance().mNfcB == null) {
898
+ log (" NfcB is not supported in current Tag");
899
+ return null;
900
+ }
901
+ byte[] result = null;
902
+ try {
903
+ result = getInstance().mNfcB.transceive(data);
904
+ } catch (IOException e) {
905
+ loge(" Exception in tech_NfcB_transceive()");
906
+ e.printStackTrace();
907
+ }
908
+ return result;
909
+ }
910
+
911
+ public static byte[] tech_NfcF_get_manufacturer() {
912
+ if (getInstance().mNfcF != null) {
913
+ return getInstance().mNfcF.getManufacturer();
914
+ }
915
+ return null;
916
+ }
917
+
918
+ public static byte[] tech_NfcF_get_system_code() {
919
+ if (getInstance().mNfcF != null) {
920
+ return getInstance().mNfcF.getSystemCode();
921
+ }
922
+ return null;
923
+ }
924
+
925
+ public static byte[] tech_NfcF_transceive(byte[] data) {
926
+ if (getInstance().mNfcF == null) {
927
+ log (" NfcF is not supported in current Tag");
928
+ return null;
929
+ }
930
+ byte[] result = null;
931
+ try {
932
+ result = getInstance().mNfcF.transceive(data);
933
+ } catch (IOException e) {
934
+ loge(" Exception in tech_NfcF_transceive()");
935
+ e.printStackTrace();
936
+ }
937
+ return result;
938
+ }
939
+
940
+ public static int tech_NfcV_get_dsf_id() {
941
+ if (getInstance().mNfcV != null) {
942
+ return getInstance().mNfcV.getDsfId();
943
+ }
263
944
  return 0;
264
945
  }
265
-
266
- public static void tech_MifareClassic_write_block(int index, byte[] block) {
267
-
946
+
947
+ public static int tech_NfcV_get_responce_flags() {
948
+ if (getInstance().mNfcV != null) {
949
+ return getInstance().mNfcV.getResponseFlags();
950
+ }
951
+ return 0;
268
952
  }
269
-
270
- public static void tech_MifareClassic_read_block(int index, byte[] block) {
271
-
953
+
954
+ public static byte[] tech_NfcV_transceive(byte[] data) {
955
+ if (getInstance().mNfcV == null) {
956
+ log (" NfcV is not supported in current Tag");
957
+ return null;
958
+ }
959
+ byte[] result = null;
960
+ try {
961
+ result = getInstance().mNfcV.transceive(data);
962
+ } catch (IOException e) {
963
+ loge(" Exception in tech_NfcV_transceive()");
964
+ e.printStackTrace();
965
+ }
966
+ return result;
272
967
  }
273
968
 
969
+
970
+ public static NfcRecord convert_byte_array_to_NdeRecord_hash(byte[] array) {
971
+ return new NfcRecord(array);
972
+ }
274
973
 
275
- public static int tech_MifareUltralight_get_size() {
276
- return 0;
974
+ public static byte[] convert_NdeRecord_hash_to_byte_array(byte[] id, byte[] payload, int tnf, byte[] type) {
975
+ NfcRecord r = new NfcRecord((short)tnf, type, id, payload);
976
+ return r.getByteArray();
977
+ }
978
+
979
+ public static NfcMessage convert_NdeMessage_byte_array_to_NdeRecords_array(byte[] array) {
980
+ return new NfcMessage(array);
981
+ }
982
+
983
+ public static NfcMessage make_empty_NfcMessage() {
984
+ return new NfcMessage();
985
+ }
986
+
987
+ public static NfcRecord make_NfcRecord(byte[] id, byte[] payload, int tnf, byte[] type) {
988
+ return new NfcRecord((short)tnf, type, id, payload);
277
989
  }
278
990
 
991
+ public static String make_string_from_payload(byte[] payload, int tnf, byte[] type) {
992
+ return NfcRecord.makePayloadString((short)tnf, type, payload, null);
993
+ }
994
+
995
+ public static byte[] make_payload_with_absolute_uri(String str) {
996
+ return str.getBytes();
997
+ }
998
+
999
+ public static byte[] make_payload_with_well_known_text(String language, String str) {
1000
+ byte[] b_lang = language.getBytes();
1001
+ byte[] b_str = str.getBytes();
1002
+ byte[] result = new byte[b_lang.length + b_str.length+1];
1003
+
1004
+ result[0] = (byte)b_lang.length;
1005
+ int i;
1006
+ for (i = 0; i < b_lang.length; i++) {
1007
+ result[1+i] = b_lang[i];
1008
+ }
1009
+ for (i = 0; i < b_str.length; i++) {
1010
+ result[1+b_lang.length+i] = b_str[i];
1011
+ }
1012
+ return result;
1013
+ }
1014
+
1015
+ public static byte[] make_payload_with_well_known_uri(int prefix, String str) {
1016
+ byte[] b_str = str.getBytes();
1017
+ byte[] result = new byte[1+b_str.length];
1018
+
1019
+ result[0] = (byte)prefix;
1020
+ int i;
1021
+ for (i = 0; i < b_str.length; i++) {
1022
+ result[1+i] = b_str[i];
1023
+ }
1024
+ return result;
1025
+ }
1026
+
1027
+ public static void p2p_enable_foreground_nde_push(byte[] nde_message_byte_array) {
1028
+ ourP2PNdefMessage = null;
1029
+ try {
1030
+ ourP2PNdefMessage = new NdefMessage(nde_message_byte_array);
1031
+ } catch (FormatException e) {
1032
+ loge("Format Exception during prepare NdefMessage in p2p_enable_foreground_nde_push() !");
1033
+ e.printStackTrace();
1034
+ }
1035
+ if ((ourP2PNdefMessage != null) && (ourIsEnable)) {
1036
+ if (RhodesActivity.safeGetInstance().isForegroundNow()) {
1037
+ PerformOnUiThread.exec( new Runnable() {
1038
+ public void run() {
1039
+ if (RhodesActivity.safeGetInstance().isForegroundNow()) {
1040
+ NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(RhodesActivity.getContext());
1041
+ nfcAdapter.enableForegroundNdefPush(RhodesActivity.safeGetInstance(), ourP2PNdefMessage);
1042
+ }
1043
+ }
1044
+ });
1045
+ }
1046
+ }
1047
+ }
1048
+
1049
+ public static void p2p_disable_foreground_nde_push() {
1050
+ ourP2PNdefMessage = null;
1051
+ PerformOnUiThread.exec( new Runnable() {
1052
+ public void run() {
1053
+ if (RhodesActivity.safeGetInstance().isForegroundNow()) {
1054
+ NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(RhodesActivity.getContext());
1055
+ nfcAdapter.disableForegroundNdefPush(RhodesActivity.safeGetInstance());
1056
+ }
1057
+ }
1058
+ });
1059
+ }
1060
+
279
1061
  public static void tech_MifareUltralight_write_page(int index, byte[] page) {
280
-
1062
+ if (getInstance().mMifareUltralight == null) {
1063
+ log (" MifareUltralight is not supported in current Tag");
1064
+ return;
1065
+ }
1066
+ try {
1067
+ getInstance().mMifareUltralight.writePage(index, page);
1068
+ } catch (IOException e) {
1069
+ loge(" Exception in tech_MifareUltralight_write_page("+String.valueOf(index)+")");
1070
+ e.printStackTrace();
1071
+ }
281
1072
  }
282
1073
 
283
- public static void tech_MifareUltralight_read_pages(int index, byte[] pages) {
284
-
1074
+ public static byte[] tech_MifareUltralight_read_pages(int index) {
1075
+ byte[] result = null;
1076
+ if (getInstance().mMifareUltralight == null) {
1077
+ log (" MifareUltralight is not supported in current Tag");
1078
+ return null;
1079
+ }
1080
+ try {
1081
+ result = getInstance().mMifareUltralight.readPages(index);
1082
+ } catch (IOException e) {
1083
+ loge(" Exception in tech_MifareUltralight_read_pages("+String.valueOf(index)+")");
1084
+ e.printStackTrace();
1085
+ }
1086
+ return result;
285
1087
  }
286
1088
 
1089
+ public static int tech_MifareUltralight_get_type() {
1090
+ if (getInstance().mMifareUltralight != null)
1091
+ return getInstance().mMifareUltralight.getType();
1092
+ return -2;
1093
+ }
1094
+
1095
+ public static byte[] tech_MifareUltralight_transceive(byte[] data) {
1096
+ if (getInstance().mMifareUltralight == null) {
1097
+ log (" MifareUltralight is not supported in current Tag");
1098
+ return null;
1099
+ }
1100
+ byte[] result = null;
1101
+ try {
1102
+ result = getInstance().mMifareUltralight.transceive(data);
1103
+ } catch (IOException e) {
1104
+ loge(" Exception in tech_MifareUltralight_transceive()");
1105
+ e.printStackTrace();
1106
+ }
1107
+ return result;
1108
+ }
287
1109
 
288
1110
 
289
1111