NfcTagUtils.java 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. package com.epson.mobilephone.common.wifidirect;
  2. import android.annotation.SuppressLint;
  3. import android.app.Activity;
  4. import android.app.PendingIntent;
  5. import android.content.Context;
  6. import android.content.Intent;
  7. import android.content.IntentFilter;
  8. import android.nfc.NdefMessage;
  9. import android.nfc.NdefRecord;
  10. import android.nfc.NfcAdapter;
  11. import android.os.Build;
  12. import android.os.Parcel;
  13. import android.os.Parcelable;
  14. import org.opencv.videoio.Videoio;
  15. import java.util.Arrays;
  16. import epson.print.MyPrinter;
  17. public class NfcTagUtils {
  18. private static final String FIXEDTAG_EPS_V1 = "EPS_V1";
  19. private static final String FIXEDTAG_EPS_V2 = "EPS_V2";
  20. private static final String ID_CL = "CL";
  21. private static final String ID_EPSON = "EPSON";
  22. private static final String ID_MACADDRESS = "MAC_ADDRESS";
  23. private static final String MIME_TEXTPLAIN = "text/plain";
  24. private static final String PREFIX_FIXEDTAG = "EPS_V";
  25. private static final String PREFIX_TAGWITHNTERFACE = "EPS_I";
  26. private static final String TAG = "NfcTagUtils";
  27. private static final String TYPE_ANDROID_COM_PKG = "android.com:pkg";
  28. public static final int VIBE_TIME = 100;
  29. public static class EpsonNfcConnectInfo implements Parcelable {
  30. public static final Parcelable.Creator<EpsonNfcConnectInfo> CREATOR = new Parcelable.Creator<EpsonNfcConnectInfo>() {
  31. public EpsonNfcConnectInfo createFromParcel(Parcel parcel) {
  32. return new EpsonNfcConnectInfo(parcel);
  33. }
  34. public EpsonNfcConnectInfo[] newArray(int i) {
  35. return new EpsonNfcConnectInfo[i];
  36. }
  37. };
  38. public String aarPackageName;
  39. public String initialpassword;
  40. public String ipAddressV4;
  41. public String ipAddressV4SimpleAP;
  42. public String macAdress;
  43. public String macAdressP2P;
  44. public String password;
  45. public int printerStatus;
  46. public String ssid;
  47. public String tagVersion;
  48. public int describeContents() {
  49. return 0;
  50. }
  51. public EpsonNfcConnectInfo() {
  52. }
  53. private EpsonNfcConnectInfo(Parcel parcel) {
  54. macAdress = parcel.readString();
  55. macAdressP2P = parcel.readString();
  56. ssid = parcel.readString();
  57. password = parcel.readString();
  58. initialpassword = parcel.readString();
  59. aarPackageName = parcel.readString();
  60. tagVersion = parcel.readString();
  61. ipAddressV4 = parcel.readString();
  62. ipAddressV4SimpleAP = parcel.readString();
  63. printerStatus = parcel.readInt();
  64. }
  65. public void writeToParcel(Parcel parcel, int i) {
  66. parcel.writeString(macAdress);
  67. parcel.writeString(macAdressP2P);
  68. parcel.writeString(ssid);
  69. parcel.writeString(password);
  70. parcel.writeString(initialpassword);
  71. parcel.writeString(aarPackageName);
  72. parcel.writeString(tagVersion);
  73. parcel.writeString(ipAddressV4);
  74. parcel.writeString(ipAddressV4SimpleAP);
  75. parcel.writeInt(printerStatus);
  76. }
  77. public boolean isTagWithInterface() {
  78. String str = tagVersion;
  79. return str != null && str.startsWith(NfcTagUtils.PREFIX_TAGWITHNTERFACE);
  80. }
  81. public boolean hasOwnAAR(Context context) {
  82. return context.getPackageName().equals(aarPackageName);
  83. }
  84. }
  85. public static boolean isNeedChangePrinter(Context context, String str, EpsonNfcConnectInfo epsonNfcConnectInfo) {
  86. String macAddressFromPrinterId = NfcMacAddrUtils.getMacAddressFromPrinterId(str);
  87. if (macAddressFromPrinterId == null) {
  88. return true;
  89. }
  90. if (macAddressFromPrinterId.equals(epsonNfcConnectInfo.macAdress)) {
  91. MyPrinter curPrinter = MyPrinter.getCurPrinter(context);
  92. if (3 != curPrinter.getLocation() || curPrinter.getIp().equals(epsonNfcConnectInfo.ipAddressV4)) {
  93. return false;
  94. }
  95. return true;
  96. }
  97. String connectInfo = WiFiDirectManager.getConnectInfo(context, WiFiDirectManager.DEVICE_TYPE_PRINTER);
  98. if (connectInfo != null && connectInfo.equals(epsonNfcConnectInfo.ssid)) {
  99. String str2 = epsonNfcConnectInfo.ssid;
  100. if (!isExistSimpleApDisabled(context, str2) && !isExistSimpleApNormal(context, str2)) {
  101. return true;
  102. }
  103. return false;
  104. }
  105. return true;
  106. }
  107. @SuppressLint({"NewApi"})
  108. public static void enableForegroundDispatch(Activity activity, IntentFilter[] intentFilterArr, String[][] strArr) {
  109. NfcAdapter defaultAdapter;
  110. if (Build.VERSION.SDK_INT >= 14 && (defaultAdapter = NfcAdapter.getDefaultAdapter(activity)) != null) {
  111. defaultAdapter.enableForegroundDispatch(activity, PendingIntent.getActivity(activity, 0, new Intent(activity, activity.getClass()).addFlags(Videoio.CAP_INTELPERC_DEPTH_GENERATOR), 0), intentFilterArr, strArr);
  112. }
  113. }
  114. @SuppressLint({"NewApi"})
  115. public static void disableForegroundDispatch(Activity activity) {
  116. NfcAdapter defaultAdapter;
  117. if (Build.VERSION.SDK_INT >= 14 && (defaultAdapter = NfcAdapter.getDefaultAdapter(activity)) != null) {
  118. defaultAdapter.disableForegroundDispatch(activity);
  119. }
  120. }
  121. /* JADX WARNING: Code restructure failed: missing block: B:5:0x0010, code lost:
  122. r4 = (android.nfc.NdefMessage) r4[0];
  123. */
  124. @android.annotation.SuppressLint({"NewApi"})
  125. /* Code decompiled incorrectly, please refer to instructions dump. */
  126. public static com.epson.mobilephone.common.wifidirect.NfcTagUtils.EpsonNfcConnectInfo parseNECTag(android.content.Context r3, android.content.Intent r4) {
  127. /*
  128. int r0 = android.os.Build.VERSION.SDK_INT
  129. r1 = 0
  130. r2 = 14
  131. if (r0 < r2) goto L_0x0062
  132. java.lang.String r0 = "android.nfc.extra.NDEF_MESSAGES"
  133. android.os.Parcelable[] r4 = r4.getParcelableArrayExtra(r0)
  134. if (r4 != 0) goto L_0x0010
  135. return r1
  136. L_0x0010:
  137. r0 = 0
  138. r4 = r4[r0]
  139. android.nfc.NdefMessage r4 = (android.nfc.NdefMessage) r4
  140. java.lang.String r0 = "EPSON"
  141. byte[] r0 = r0.getBytes()
  142. android.nfc.NdefRecord r0 = findNdefMessage(r0, r4)
  143. if (r0 != 0) goto L_0x0022
  144. return r1
  145. L_0x0022:
  146. java.lang.String r2 = new java.lang.String
  147. byte[] r0 = r0.getPayload()
  148. r2.<init>(r0)
  149. java.lang.String r0 = "EPS_V"
  150. boolean r0 = r2.startsWith(r0)
  151. if (r0 == 0) goto L_0x0038
  152. com.epson.mobilephone.common.wifidirect.NfcTagUtils$EpsonNfcConnectInfo r0 = parseNECTagFixed(r2, r4)
  153. goto L_0x0044
  154. L_0x0038:
  155. java.lang.String r0 = "EPS_I"
  156. boolean r0 = r2.startsWith(r0)
  157. if (r0 == 0) goto L_0x0061
  158. com.epson.mobilephone.common.wifidirect.NfcTagUtils$EpsonNfcConnectInfo r0 = parseNECTagWithInterface(r2, r4)
  159. L_0x0044:
  160. if (r0 != 0) goto L_0x0047
  161. return r1
  162. L_0x0047:
  163. java.lang.String r4 = getAARPackageName(r4)
  164. r0.aarPackageName = r4
  165. java.lang.String r4 = "vibrator"
  166. java.lang.Object r3 = r3.getSystemService(r4)
  167. android.os.Vibrator r3 = (android.os.Vibrator) r3
  168. boolean r4 = r3.hasVibrator()
  169. if (r4 == 0) goto L_0x0060
  170. r1 = 100
  171. r3.vibrate(r1)
  172. L_0x0060:
  173. return r0
  174. L_0x0061:
  175. return r1
  176. L_0x0062:
  177. return r1
  178. */
  179. throw new UnsupportedOperationException("Method not decompiled: com.epson.mobilephone.common.wifidirect.NfcTagUtils.parseNECTag(android.content.Context, android.content.Intent):com.epson.mobilephone.common.wifidirect.NfcTagUtils$EpsonNfcConnectInfo");
  180. }
  181. /* JADX WARNING: Removed duplicated region for block: B:19:0x0083 */
  182. /* JADX WARNING: Removed duplicated region for block: B:20:0x008c */
  183. /* JADX WARNING: Removed duplicated region for block: B:23:0x009a */
  184. /* JADX WARNING: Removed duplicated region for block: B:24:0x00a5 */
  185. @android.annotation.SuppressLint({"NewApi"})
  186. /* Code decompiled incorrectly, please refer to instructions dump. */
  187. public static com.epson.mobilephone.common.wifidirect.NfcTagUtils.EpsonNfcConnectInfo parseNECTagFixed(java.lang.String r5, android.nfc.NdefMessage r6) {
  188. /*
  189. java.lang.String r0 = "MAC_ADDRESS"
  190. byte[] r0 = r0.getBytes()
  191. android.nfc.NdefRecord r0 = findNdefMessage(r0, r6)
  192. r1 = 0
  193. if (r0 != 0) goto L_0x000e
  194. return r1
  195. L_0x000e:
  196. short r2 = r0.getTnf()
  197. r3 = 2
  198. if (r3 != r2) goto L_0x00bb
  199. java.lang.String r2 = "text/plain"
  200. byte[] r2 = r2.getBytes()
  201. byte[] r4 = r0.getType()
  202. boolean r2 = java.util.Arrays.equals(r2, r4)
  203. if (r2 != 0) goto L_0x0027
  204. goto L_0x00bb
  205. L_0x0027:
  206. java.lang.String r2 = new java.lang.String
  207. byte[] r0 = r0.getPayload()
  208. r2.<init>(r0)
  209. java.lang.String r0 = "CL"
  210. byte[] r0 = r0.getBytes()
  211. android.nfc.NdefRecord r6 = findNdefMessage(r0, r6)
  212. r0 = 1
  213. if (r6 == 0) goto L_0x0065
  214. short r4 = r6.getTnf()
  215. if (r3 != r4) goto L_0x0065
  216. java.lang.String r3 = "text/plain"
  217. byte[] r3 = r3.getBytes()
  218. byte[] r4 = r6.getType()
  219. boolean r3 = java.util.Arrays.equals(r3, r4)
  220. if (r3 != r0) goto L_0x0065
  221. java.lang.String r3 = new java.lang.String // Catch:{ NumberFormatException -> 0x0065 }
  222. byte[] r6 = r6.getPayload() // Catch:{ NumberFormatException -> 0x0065 }
  223. r3.<init>(r6) // Catch:{ NumberFormatException -> 0x0065 }
  224. java.lang.Integer r6 = java.lang.Integer.valueOf(r3) // Catch:{ NumberFormatException -> 0x0065 }
  225. int r6 = r6.intValue() // Catch:{ NumberFormatException -> 0x0065 }
  226. goto L_0x0066
  227. L_0x0065:
  228. r6 = 0
  229. L_0x0066:
  230. com.epson.mobilephone.common.wifidirect.NfcTagUtils$EpsonNfcConnectInfo r3 = new com.epson.mobilephone.common.wifidirect.NfcTagUtils$EpsonNfcConnectInfo
  231. r3.<init>()
  232. r3.tagVersion = r5
  233. java.util.Locale r4 = java.util.Locale.US
  234. java.lang.String r4 = r2.toUpperCase(r4)
  235. r3.macAdress = r4
  236. java.lang.String r4 = com.epson.mobilephone.common.wifidirect.NfcMacAddrUtils.getMacAddressP2P(r2)
  237. r3.macAdressP2P = r4
  238. java.lang.String r4 = com.epson.mobilephone.common.wifidirect.NfcMacAddrUtils.getSSIDFromMacAddress(r2)
  239. r3.ssid = r4
  240. if (r6 < r0) goto L_0x008c
  241. char[] r6 = com.epson.mobilephone.common.wifidirect.NfcMacAddrUtils.acCharacterTblPassphraseCL1
  242. java.lang.String r6 = com.epson.mobilephone.common.wifidirect.NfcMacAddrUtils.getPassFormMacAddress(r2, r6)
  243. r3.password = r6
  244. goto L_0x0094
  245. L_0x008c:
  246. char[] r6 = com.epson.mobilephone.common.wifidirect.NfcMacAddrUtils.acCharacterTblPassphrase
  247. java.lang.String r6 = com.epson.mobilephone.common.wifidirect.NfcMacAddrUtils.getPassFormMacAddress(r2, r6)
  248. r3.password = r6
  249. L_0x0094:
  250. boolean r6 = IsCraigDempsey(r2)
  251. if (r6 != r0) goto L_0x00a5
  252. java.lang.String r5 = "000048D400E6"
  253. char[] r6 = com.epson.mobilephone.common.wifidirect.NfcMacAddrUtils.acCharacterTblPassphraseCL1
  254. java.lang.String r5 = com.epson.mobilephone.common.wifidirect.NfcMacAddrUtils.getPassFormMacAddress(r5, r6)
  255. r3.initialpassword = r5
  256. goto L_0x00ba
  257. L_0x00a5:
  258. java.lang.String r6 = "EPS_V1"
  259. boolean r5 = r5.equals(r6)
  260. if (r5 != r0) goto L_0x00b8
  261. java.lang.String r5 = "000048D400E6"
  262. char[] r6 = com.epson.mobilephone.common.wifidirect.NfcMacAddrUtils.acCharacterTblPassphrase
  263. java.lang.String r5 = com.epson.mobilephone.common.wifidirect.NfcMacAddrUtils.getPassFormMacAddress(r5, r6)
  264. r3.initialpassword = r5
  265. goto L_0x00ba
  266. L_0x00b8:
  267. r3.initialpassword = r1
  268. L_0x00ba:
  269. return r3
  270. L_0x00bb:
  271. return r1
  272. */
  273. throw new UnsupportedOperationException("Method not decompiled: com.epson.mobilephone.common.wifidirect.NfcTagUtils.parseNECTagFixed(java.lang.String, android.nfc.NdefMessage):com.epson.mobilephone.common.wifidirect.NfcTagUtils$EpsonNfcConnectInfo");
  274. }
  275. @SuppressLint({"NewApi"})
  276. public static EpsonNfcConnectInfo parseNECTagWithInterface(String str, NdefMessage ndefMessage) {
  277. NdefRecord[] records = ndefMessage.getRecords();
  278. if (records.length <= 1) {
  279. return null;
  280. }
  281. byte[] payload = records[1].getPayload();
  282. NfcTagParser nfcTagParser = new NfcTagParser();
  283. if (!nfcTagParser.parseTag(payload)) {
  284. return null;
  285. }
  286. EpsonNfcConnectInfo epsonNfcConnectInfo = new EpsonNfcConnectInfo();
  287. epsonNfcConnectInfo.tagVersion = str;
  288. epsonNfcConnectInfo.macAdress = nfcTagParser.getMacAddress();
  289. if (epsonNfcConnectInfo.macAdress != null) {
  290. epsonNfcConnectInfo.macAdressP2P = NfcMacAddrUtils.getMacAddressP2P(epsonNfcConnectInfo.macAdress);
  291. }
  292. epsonNfcConnectInfo.ssid = nfcTagParser.getSSID();
  293. epsonNfcConnectInfo.password = nfcTagParser.getPassWord();
  294. epsonNfcConnectInfo.ipAddressV4 = nfcTagParser.getIPAddressV4();
  295. epsonNfcConnectInfo.ipAddressV4SimpleAP = nfcTagParser.getIPAddressV4SimpleAP();
  296. epsonNfcConnectInfo.printerStatus = nfcTagParser.getPrinterStatus();
  297. return epsonNfcConnectInfo;
  298. }
  299. @SuppressLint({"NewApi"})
  300. public static NdefRecord findNdefMessage(byte[] bArr, NdefMessage ndefMessage) {
  301. for (NdefRecord ndefRecord : ndefMessage.getRecords()) {
  302. if (Arrays.equals(bArr, ndefRecord.getId())) {
  303. return ndefRecord;
  304. }
  305. }
  306. return null;
  307. }
  308. @SuppressLint({"NewApi"})
  309. public static String getAARPackageName(NdefMessage ndefMessage) {
  310. for (NdefRecord ndefRecord : ndefMessage.getRecords()) {
  311. if (4 == ndefRecord.getTnf() && Arrays.equals(TYPE_ANDROID_COM_PKG.getBytes(), ndefRecord.getType())) {
  312. return new String(ndefRecord.getPayload());
  313. }
  314. }
  315. return null;
  316. }
  317. public static boolean IsCraigDempsey(String str) {
  318. if (str == null || str.length() != 12) {
  319. return false;
  320. }
  321. byte[] macAdressBytes = NfcMacAddrUtils.getMacAdressBytes(str);
  322. if (!str.startsWith("9CAED3")) {
  323. return false;
  324. }
  325. long j = (((long) macAdressBytes[5]) & 255) + ((((long) macAdressBytes[4]) & 255) << 8) + ((255 & ((long) macAdressBytes[3])) << 16);
  326. if (11960320 > j || 13836287 < j) {
  327. return false;
  328. }
  329. return true;
  330. }
  331. public static boolean isExistSimpleApDisabled(Context context, String str) {
  332. EPLog.d(TAG, "isExistSimpleApDisabled()");
  333. return WiFiUtils.getInstance(context).getExistSimpleApDisabled(str) != -1;
  334. }
  335. public static boolean isExistSimpleApNormal(Context context, String str) {
  336. EPLog.d(TAG, "isExistSimpleApNormal()");
  337. return WiFiUtils.getInstance(context).getNetworkId(str) != -1;
  338. }
  339. }