BleWork.java 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331
  1. package com.epson.mobilephone.common.ble;
  2. import android.app.Activity;
  3. import android.bluetooth.BluetoothAdapter;
  4. import android.bluetooth.BluetoothDevice;
  5. import android.bluetooth.BluetoothGatt;
  6. import android.bluetooth.BluetoothGattCallback;
  7. import android.bluetooth.BluetoothGattCharacteristic;
  8. import android.bluetooth.BluetoothGattDescriptor;
  9. import android.bluetooth.BluetoothGattService;
  10. import android.bluetooth.BluetoothManager;
  11. import android.content.Context;
  12. import android.os.AsyncTask;
  13. import android.os.Build;
  14. import android.os.Handler;
  15. import com.epson.mobilephone.common.ble.util.BLEUtility;
  16. import com.epson.mobilephone.common.ble.util.BLEUuid;
  17. import com.epson.mobilephone.common.ble.util.ScannedDevice;
  18. import com.epson.mobilephone.common.escpr.EscprLib;
  19. import com.epson.mobilephone.common.escpr.MIBCommand;
  20. import com.epson.mobilephone.common.wifidirect.ActivityRequestLocationPermission;
  21. import com.epson.mobilephone.common.wifidirect.WiFiDirectManager;
  22. import com.epson.mobilephone.common.wifidirect.WiFiNetworkManager;
  23. import com.evernote.edam.limits.Constants;
  24. import java.nio.ByteBuffer;
  25. import java.nio.charset.Charset;
  26. import java.util.ArrayList;
  27. import java.util.List;
  28. import java.util.Map;
  29. import java.util.Objects;
  30. import java.util.UUID;
  31. import java.util.concurrent.TimeUnit;
  32. import epson.print.IprintApplication;
  33. import epson.print.MyPrinter;
  34. public class BleWork {
  35. private static final int EPS_COMM_BID = 2;
  36. private static final int GATT_DELAY = 0;
  37. private static final int GATT_DELAY2 = 500;
  38. private static final int RETRY_NUMS = 3;
  39. private static final int SCAN_ADVERTISING_PACKET_TIMEOUT = 10000;
  40. Handler handlerRead;
  41. Handler handlerWrite;
  42. private BluetoothAdapter mBTAdapter;
  43. /* access modifiers changed from: private */
  44. @Nullable
  45. public BluetoothGatt mConnGatt;
  46. private Context mContext;
  47. private BluetoothDevice mDevice;
  48. private String mDeviceMacAddress;
  49. private String mDevicePassword;
  50. private final byte[] mEngineID;
  51. private EscprLib mEscprlib;
  52. /* access modifiers changed from: private */
  53. @Nullable
  54. public BLEUtility.BleWorkCallback mFailed;
  55. private BluetoothGattCallback mGattcallback;
  56. private boolean mInSequence;
  57. private byte mIndex;
  58. /* access modifiers changed from: private */
  59. @NonNull
  60. public MIBCommand mMibCommand;
  61. private boolean mReconnect;
  62. /* access modifiers changed from: private */
  63. @Nullable
  64. public BLEUtility.BleWorkCallback mResposne;
  65. private int mRetry;
  66. private String mSSID;
  67. private String mSSIDPassword;
  68. private short mSecurityType;
  69. private ScannedDevice mSelectItem;
  70. public jobSequence mSequence;
  71. @Nullable
  72. private BLEUtility.BleWorkCallback mSequenceCallbackFailed;
  73. /* access modifiers changed from: private */
  74. @Nullable
  75. public BLEUtility.BleWorkCallback mSequenceCallbackSuccess;
  76. /* access modifiers changed from: private */
  77. @NonNull
  78. public List<String> mSsidLis;
  79. public int mStatus;
  80. /* access modifiers changed from: private */
  81. @Nullable
  82. public BLEUtility.BleWorkCallback mSuccess;
  83. private long mTimeOut;
  84. public enum jobSequence {
  85. UNINITIALIZED,
  86. DISCONNECTED,
  87. FAILED,
  88. INITIALIZE,
  89. GET_VERSION,
  90. CHECK_SSID,
  91. SET_PASSWORD,
  92. MIB_GET_MACADDRESS,
  93. MIB_GET_SSID_LIST,
  94. MIB_SET_SSID,
  95. MIB_SET_SECURITY_TYPE,
  96. MIB_SEC_LOGIN,
  97. MIB_SEC_SET_PASS,
  98. MIB_SEC_LOGOUT,
  99. MIB_REBOOT_NW,
  100. COMPLETION,
  101. MIB_SEC_SKIP,
  102. AFTER_SETTING_PASSWORD,
  103. BEFORE_CHECK_SSID
  104. }
  105. public static int getScanAdvertisingPacketTimeout() {
  106. return 10000;
  107. }
  108. private void showStatus(String str, int i) {
  109. }
  110. static /* synthetic */ int access$508(BleWork bleWork) {
  111. int i = bleWork.mRetry;
  112. bleWork.mRetry = i + 1;
  113. return i;
  114. }
  115. @NonNull
  116. public List<String> getSsidLis() {
  117. return mSsidLis;
  118. }
  119. public void setSSID(String str) {
  120. mSSID = str;
  121. }
  122. public void setRetryFinish() {
  123. mRetry = 3;
  124. }
  125. public String getSSID() {
  126. return mSSID;
  127. }
  128. public synchronized void setSecurityType(short s) {
  129. mSecurityType = s;
  130. }
  131. public synchronized short getSecurityType() {
  132. return mSecurityType;
  133. }
  134. public void setSSIDPassword(String str) {
  135. mSSIDPassword = str;
  136. }
  137. public String getSSIDPassword() {
  138. String str = mSSIDPassword;
  139. return str != null ? str : "";
  140. }
  141. public void setTimeOut(long j) {
  142. mTimeOut = j;
  143. }
  144. public String getDeviceMacAddress() {
  145. String str = mDeviceMacAddress;
  146. if (str == null) {
  147. return "";
  148. }
  149. return str.replace("\"", "");
  150. }
  151. public String getDeviceName() {
  152. return mSelectItem.getDisplayName();
  153. }
  154. private BleWork() {
  155. mSuccess = null;
  156. mFailed = null;
  157. mSequenceCallbackSuccess = null;
  158. mSequenceCallbackFailed = null;
  159. mResposne = null;
  160. mSsidLis = new ArrayList();
  161. mTimeOut = -1;
  162. mEscprlib = EscprLib.getInstance();
  163. mMibCommand = new MIBCommand();
  164. mIndex = 0;
  165. mInSequence = false;
  166. mEngineID = mEscprlib.getEngineId(IprintApplication.getInstance());
  167. mReconnect = false;
  168. mSequence = jobSequence.UNINITIALIZED;
  169. mGattcallback = null;
  170. if (mGattcallback != null) {
  171. EPLog.e("mGattcallback != null");
  172. }
  173. mGattcallback = new BluetoothGattCallback() {
  174. public void onMtuChanged(BluetoothGatt bluetoothGatt, int i, int i2) {
  175. super.onMtuChanged(bluetoothGatt, i, i2);
  176. EPLog.i("onMtuChanged " + i);
  177. }
  178. public void onDescriptorWrite(BluetoothGatt bluetoothGatt, BluetoothGattDescriptor bluetoothGattDescriptor, int i) {
  179. super.onDescriptorWrite(bluetoothGatt, bluetoothGattDescriptor, i);
  180. showStatus("DescriptorWrite", i);
  181. if (i != 0) {
  182. sequenceError();
  183. } else if (BleWork.mResposne != null) {
  184. BleWork.mResposne.call(bluetoothGattDescriptor);
  185. }
  186. }
  187. public void onConnectionStateChange(BluetoothGatt bluetoothGatt, int i, int i2) {
  188. EPLog.i("status = " + i + " newState = " + i2);
  189. if (i == 0 && i2 == 2) {
  190. EPLog.i("STATE_CONNECTED -- " + BleWork.mSequence);
  191. BleWork bleWork = BleWork.this;
  192. bleWork.mStatus = i2;
  193. if (bleWork.mConnGatt == null) {
  194. EPLog.e("mConnGatt NULL !");
  195. }
  196. if (bluetoothGatt == null) {
  197. EPLog.e("gatt NULL !");
  198. }
  199. BluetoothGatt unused = BleWork.mConnGatt = bluetoothGatt;
  200. handlerWrite.removeCallbacks((Runnable) null);
  201. handlerWrite.postDelayed(new Runnable() {
  202. public void run() {
  203. EPLog.i("discoverServices");
  204. try {
  205. if (!((BluetoothGatt) Objects.requireNonNull(BleWork.mConnGatt)).discoverServices()) {
  206. EPLog.e("discoverServices error");
  207. }
  208. } catch (NullPointerException unused) {
  209. EPLog.e("mConnGatt NULL !");
  210. }
  211. }
  212. }, 500);
  213. } else if (i != 0 || i2 == 0) {
  214. EPLog.i("STATE_DISCONNECTED " + BleWork.mSequence + " mReconnect = " + BleWork.mReconnect + " mRetry " + BleWork.mRetry);
  215. if (!BleWork.mReconnect && BleWork.mSequence == jobSequence.UNINITIALIZED) {
  216. failedProcessing();
  217. } else if (BleWork.mReconnect || BleWork.mSequence == jobSequence.UNINITIALIZED || BleWork.mSequence == jobSequence.MIB_REBOOT_NW || BleWork.mSequence == jobSequence.DISCONNECTED || BleWork.mSequence == jobSequence.MIB_SET_SSID || BleWork.mSequence == jobSequence.AFTER_SETTING_PASSWORD) {
  218. EPLog.d("★ stopScan");
  219. BleScanWork.getInstace().stopScan();
  220. BleWork bleWork2 = BleWork.this;
  221. bleWork2.mStatus = i2;
  222. if ((bleWork2.mSequence == jobSequence.AFTER_SETTING_PASSWORD || BleWork.mSequence == jobSequence.BEFORE_CHECK_SSID || BleWork.mSequence == jobSequence.MIB_SET_SSID || BleWork.mSequence == jobSequence.MIB_REBOOT_NW) && !BleWork.mReconnect) {
  223. if (BleWork.mSequence == jobSequence.MIB_REBOOT_NW) {
  224. gattClose();
  225. }
  226. EPLog.i(" BREAK ★ mSequence " + BleWork.mSequence);
  227. return;
  228. }
  229. gattClose();
  230. if (BleWork.mSequence != jobSequence.UNINITIALIZED && !BleWork.mReconnect) {
  231. return;
  232. }
  233. if (BleWork.mRetry < 3) {
  234. try {
  235. TimeUnit.SECONDS.sleep(5);
  236. } catch (InterruptedException e) {
  237. e.printStackTrace();
  238. }
  239. EPLog.m82w("retry " + BleWork.mRetry);
  240. BleWork.access$508(BleWork.this);
  241. EPLog.e("init");
  242. boolean unused2 = init();
  243. return;
  244. }
  245. failedProcessing();
  246. } else {
  247. failedProcessing();
  248. }
  249. } else if (i2 == 1) {
  250. EPLog.i("STATE_CONNECTING");
  251. } else if (i2 == 3) {
  252. EPLog.i("STATE_DISCONNECTING");
  253. }
  254. }
  255. public void onServicesDiscovered(BluetoothGatt bluetoothGatt, int i) {
  256. EPLog.i();
  257. try {
  258. for (BluetoothGattService next : bluetoothGatt.getServices()) {
  259. if (next != null) {
  260. if (next.getUuid() != null) {
  261. if (BLEUuid.SERVICE_SNMP.equalsIgnoreCase(next.getUuid().toString())) {
  262. EPLog.i("発見!! EPSON SNMP サービス");
  263. for (Map.Entry next2 : BLEUuid.GattCharsMap.entrySet()) {
  264. next2.setValue(next.getCharacteristic(UUID.fromString((String) next2.getKey())));
  265. }
  266. if (!BLEUuid.GattCharsMap.containsValue((Object) null)) {
  267. boolean unused = BleWork.mReconnect = false;
  268. BleWork.mSequenceCallbackSuccess.call(BleWork.mSequence);
  269. new NotifySetThread().execute(new Void[0]);
  270. } else {
  271. throw new BleException(1, "getCharacteristic Error !");
  272. }
  273. } else {
  274. continue;
  275. }
  276. }
  277. }
  278. }
  279. } catch (BleException e) {
  280. EPLog.e(e.getMessage());
  281. e.printStackTrace();
  282. failedProcessing();
  283. }
  284. }
  285. public void onCharacteristicChanged(BluetoothGatt bluetoothGatt, @NonNull BluetoothGattCharacteristic bluetoothGattCharacteristic) {
  286. super.onCharacteristicChanged(bluetoothGatt, bluetoothGattCharacteristic);
  287. EPLog.d("onCharacteristicChanged");
  288. if (BLEUuid.CHAR_SNMP_STATUS_STRING.equals(bluetoothGattCharacteristic.getUuid().toString())) {
  289. Short valueOf = Short.valueOf(bluetoothGattCharacteristic.getIntValue(17, 0).shortValue());
  290. String sh = valueOf.toString();
  291. if (valueOf.shortValue() == 0) {
  292. EPLog.i("[Notify]SNMP Status" + sh);
  293. characteristicRead();
  294. return;
  295. }
  296. EPLog.e("[Notify]SNMP Status" + sh);
  297. failedProcessing();
  298. } else if (BLEUuid.CHAR_SECURITY_TYPE_STRING.equals(bluetoothGattCharacteristic.getUuid().toString())) {
  299. Short valueOf2 = Short.valueOf(bluetoothGattCharacteristic.getIntValue(17, 0).shortValue());
  300. setSecurityType(valueOf2.shortValue());
  301. String sh2 = valueOf2.toString();
  302. EPLog.i("[Notify]Security Type " + sh2);
  303. if (valueOf2.shortValue() <= 0) {
  304. BleWork.mSsidLis.clear();
  305. getSSIDList();
  306. } else if (BleWork.mSequenceCallbackSuccess != null) {
  307. BleWork.mSequenceCallbackSuccess.call(BleWork.mSequence);
  308. }
  309. } else {
  310. String sh3 = Short.valueOf(bluetoothGattCharacteristic.getIntValue(17, 0).shortValue()).toString();
  311. EPLog.e("[Notify]unKnown type" + sh3);
  312. }
  313. }
  314. public void onCharacteristicRead(BluetoothGatt bluetoothGatt, @NonNull BluetoothGattCharacteristic bluetoothGattCharacteristic, int i) {
  315. showStatus("Read", i);
  316. if (i == 0) {
  317. readCharacteristicData(bluetoothGattCharacteristic);
  318. } else {
  319. byte unused = BleWork.mIndex = (byte) 0;
  320. }
  321. }
  322. /* JADX WARNING: Can't fix incorrect switch cases order */
  323. /* Code decompiled incorrectly, please refer to instructions dump. */
  324. private void readCharacteristicData(@android.support.annotation.NonNull android.bluetooth.BluetoothGattCharacteristic r7) {
  325. /*
  326. r6 = this;
  327. java.util.UUID r0 = r7.getUuid()
  328. java.lang.String r0 = r0.toString()
  329. if (r0 != 0) goto L_0x0011
  330. java.lang.String r7 = "characteristic NULL !!"
  331. com.epson.mobilephone.common.EPLog.e((java.lang.String) r7)
  332. goto L_0x03a1
  333. L_0x0011:
  334. java.lang.String r0 = r0.toLowerCase()
  335. int r1 = r0.hashCode()
  336. r2 = -1
  337. r3 = 1
  338. r4 = 0
  339. switch(r1) {
  340. case -929193779: goto L_0x0048;
  341. case -881344628: goto L_0x003e;
  342. case 593366729: goto L_0x0034;
  343. case 641215880: goto L_0x002a;
  344. case 1286468426: goto L_0x0020;
  345. default: goto L_0x001f;
  346. }
  347. L_0x001f:
  348. goto L_0x0052
  349. L_0x0020:
  350. java.lang.String r1 = "802a0002-4ef4-4e59-b573-2bed4a4ac158"
  351. boolean r0 = r0.equals(r1)
  352. if (r0 == 0) goto L_0x0052
  353. r0 = 3
  354. goto L_0x0053
  355. L_0x002a:
  356. java.lang.String r1 = "00002a25-0000-1000-8000-00805f9b34fb"
  357. boolean r0 = r0.equals(r1)
  358. if (r0 == 0) goto L_0x0052
  359. r0 = 1
  360. goto L_0x0053
  361. L_0x0034:
  362. java.lang.String r1 = "802a0001-4ef4-4e59-b573-2bed4a4ac158"
  363. boolean r0 = r0.equals(r1)
  364. if (r0 == 0) goto L_0x0052
  365. r0 = 2
  366. goto L_0x0053
  367. L_0x003e:
  368. java.lang.String r1 = "00002a29-0000-1000-8000-00805f9b34fb"
  369. boolean r0 = r0.equals(r1)
  370. if (r0 == 0) goto L_0x0052
  371. r0 = 0
  372. goto L_0x0053
  373. L_0x0048:
  374. java.lang.String r1 = "802a0005-4ef4-4e59-b573-2bed4a4ac158"
  375. boolean r0 = r0.equals(r1)
  376. if (r0 == 0) goto L_0x0052
  377. r0 = 4
  378. goto L_0x0053
  379. L_0x0052:
  380. r0 = -1
  381. L_0x0053:
  382. r1 = 18
  383. switch(r0) {
  384. case 0: goto L_0x0389;
  385. case 1: goto L_0x0370;
  386. case 2: goto L_0x032e;
  387. case 3: goto L_0x02bd;
  388. case 4: goto L_0x005a;
  389. default: goto L_0x0058;
  390. }
  391. L_0x0058:
  392. goto L_0x03a1
  393. L_0x005a:
  394. byte[] r7 = r7.getValue()
  395. com.epson.mobilephone.common.ble.BleWork r0 = com.epson.mobilephone.common.ble.BleWork.this
  396. com.epson.mobilephone.common.escpr.MIBCommand r0 = r0.mMibCommand
  397. com.epson.mobilephone.common.escpr.MIBDataBlock r0 = r0.commandBlock
  398. int r1 = r7.length
  399. r0.bufSize = r1
  400. r0 = 0
  401. L_0x006a:
  402. com.epson.mobilephone.common.ble.BleWork r1 = com.epson.mobilephone.common.ble.BleWork.this
  403. com.epson.mobilephone.common.escpr.MIBCommand r1 = r1.mMibCommand
  404. com.epson.mobilephone.common.escpr.MIBDataBlock r1 = r1.commandBlock
  405. int r1 = r1.bufSize
  406. if (r0 >= r1) goto L_0x0087
  407. com.epson.mobilephone.common.ble.BleWork r1 = com.epson.mobilephone.common.ble.BleWork.this
  408. com.epson.mobilephone.common.escpr.MIBCommand r1 = r1.mMibCommand
  409. com.epson.mobilephone.common.escpr.MIBDataBlock r1 = r1.commandBlock
  410. byte[] r1 = r1.buf
  411. byte r5 = r7[r0]
  412. r1[r0] = r5
  413. int r0 = r0 + 1
  414. goto L_0x006a
  415. L_0x0087:
  416. com.epson.mobilephone.common.ble.BleWork r7 = com.epson.mobilephone.common.ble.BleWork.this
  417. boolean r7 = r7.mInSequence
  418. if (r7 == 0) goto L_0x00e7
  419. com.epson.mobilephone.common.ble.BleWork r7 = com.epson.mobilephone.common.ble.BleWork.this
  420. com.epson.mobilephone.common.escpr.EscprLib r7 = r7.mEscprlib
  421. com.epson.mobilephone.common.ble.BleWork r0 = com.epson.mobilephone.common.ble.BleWork.this
  422. com.epson.mobilephone.common.escpr.MIBCommand r0 = r0.mMibCommand
  423. java.lang.String r7 = r7.mibParseResponseAsStr(r0)
  424. boolean r0 = r7.isEmpty()
  425. if (r0 == 0) goto L_0x00c3
  426. java.lang.String r7 = "[Read]SNMP Response :end!"
  427. com.epson.mobilephone.common.EPLog.i(r7)
  428. com.epson.mobilephone.common.ble.BleWork r7 = com.epson.mobilephone.common.ble.BleWork.this
  429. boolean unused = r7.mInSequence = r4
  430. com.epson.mobilephone.common.ble.BleWork r7 = com.epson.mobilephone.common.ble.BleWork.this
  431. byte unused = r7.mIndex = r4
  432. com.epson.mobilephone.common.ble.BleWork r7 = com.epson.mobilephone.common.ble.BleWork.this
  433. com.epson.mobilephone.common.ble.util.BLEUtility$BleWorkCallback r7 = r7.mSequenceCallbackSuccess
  434. com.epson.mobilephone.common.ble.BleWork r0 = com.epson.mobilephone.common.ble.BleWork.this
  435. com.epson.mobilephone.common.ble.BleWork$jobSequence r0 = r0.mSequence
  436. r7.call(r0)
  437. goto L_0x03a1
  438. L_0x00c3:
  439. java.lang.StringBuilder r0 = new java.lang.StringBuilder
  440. r0.<init>()
  441. java.lang.String r1 = "[Read]SNMP Response :"
  442. r0.append(r1)
  443. r0.append(r7)
  444. java.lang.String r0 = r0.toString()
  445. com.epson.mobilephone.common.EPLog.i(r0)
  446. com.epson.mobilephone.common.ble.BleWork r0 = com.epson.mobilephone.common.ble.BleWork.this
  447. java.util.List r0 = r0.mSsidLis
  448. r0.add(r7)
  449. com.epson.mobilephone.common.ble.BleWork r7 = com.epson.mobilephone.common.ble.BleWork.this
  450. r7.getSSIDList()
  451. goto L_0x03a1
  452. L_0x00e7:
  453. java.lang.StringBuilder r7 = new java.lang.StringBuilder
  454. r7.<init>()
  455. java.lang.String r0 = "mSequence "
  456. r7.append(r0)
  457. com.epson.mobilephone.common.ble.BleWork r0 = com.epson.mobilephone.common.ble.BleWork.this
  458. com.epson.mobilephone.common.ble.BleWork$jobSequence r0 = r0.mSequence
  459. r7.append(r0)
  460. java.lang.String r7 = r7.toString()
  461. com.epson.mobilephone.common.EPLog.i(r7)
  462. int[] r7 = com.epson.mobilephone.common.ble.BleWork.C10195.$SwitchMap$com$epson$mobilephone$common$ble$BleWork$jobSequence
  463. com.epson.mobilephone.common.ble.BleWork r0 = com.epson.mobilephone.common.ble.BleWork.this
  464. com.epson.mobilephone.common.ble.BleWork$jobSequence r0 = r0.mSequence
  465. int r0 = r0.ordinal()
  466. r7 = r7[r0]
  467. switch(r7) {
  468. case 1: goto L_0x026e;
  469. case 2: goto L_0x0226;
  470. case 3: goto L_0x019f;
  471. case 4: goto L_0x019f;
  472. case 5: goto L_0x019f;
  473. case 6: goto L_0x0110;
  474. case 7: goto L_0x0110;
  475. case 8: goto L_0x0110;
  476. default: goto L_0x010e;
  477. }
  478. L_0x010e:
  479. goto L_0x03a1
  480. L_0x0110:
  481. int[] r7 = new int[r3]
  482. r7[r4] = r2
  483. com.epson.mobilephone.common.ble.BleWork r0 = com.epson.mobilephone.common.ble.BleWork.this
  484. com.epson.mobilephone.common.escpr.EscprLib r0 = r0.mEscprlib
  485. com.epson.mobilephone.common.ble.BleWork r1 = com.epson.mobilephone.common.ble.BleWork.this
  486. com.epson.mobilephone.common.escpr.MIBCommand r1 = r1.mMibCommand
  487. int r0 = r0.mibParseResponseAsInt(r1, r7)
  488. if (r0 != 0) goto L_0x0198
  489. java.lang.StringBuilder r0 = new java.lang.StringBuilder
  490. r0.<init>()
  491. java.lang.String r1 = "[Read]SNMP Response :sucess mSequence "
  492. r0.append(r1)
  493. com.epson.mobilephone.common.ble.BleWork r1 = com.epson.mobilephone.common.ble.BleWork.this
  494. com.epson.mobilephone.common.ble.BleWork$jobSequence r1 = r1.mSequence
  495. r0.append(r1)
  496. java.lang.String r1 = " val:"
  497. r0.append(r1)
  498. r7 = r7[r4]
  499. r0.append(r7)
  500. java.lang.String r7 = r0.toString()
  501. com.epson.mobilephone.common.EPLog.i(r7)
  502. com.epson.mobilephone.common.ble.BleWork r7 = com.epson.mobilephone.common.ble.BleWork.this
  503. com.epson.mobilephone.common.ble.BleWork$jobSequence r7 = r7.mSequence
  504. com.epson.mobilephone.common.ble.BleWork$jobSequence r0 = com.epson.mobilephone.common.ble.BleWork.jobSequence.MIB_SEC_SKIP
  505. if (r7 != r0) goto L_0x0157
  506. com.epson.mobilephone.common.ble.BleWork r7 = com.epson.mobilephone.common.ble.BleWork.this
  507. com.epson.mobilephone.common.ble.BleWork$jobSequence r0 = com.epson.mobilephone.common.ble.BleWork.jobSequence.MIB_SEC_LOGOUT
  508. r7.mSequence = r0
  509. goto L_0x0166
  510. L_0x0157:
  511. com.epson.mobilephone.common.ble.BleWork r7 = com.epson.mobilephone.common.ble.BleWork.this
  512. com.epson.mobilephone.common.ble.BleWork$jobSequence r7 = r7.mSequence
  513. com.epson.mobilephone.common.ble.BleWork$jobSequence r0 = com.epson.mobilephone.common.ble.BleWork.jobSequence.MIB_REBOOT_NW
  514. if (r7 != r0) goto L_0x0166
  515. com.epson.mobilephone.common.ble.BleWork r7 = com.epson.mobilephone.common.ble.BleWork.this
  516. boolean unused = r7.mReconnect = r4
  517. goto L_0x03a1
  518. L_0x0166:
  519. r6.IncrementSequence()
  520. java.lang.StringBuilder r7 = new java.lang.StringBuilder
  521. r7.<init>()
  522. java.lang.String r0 = "mSequence "
  523. r7.append(r0)
  524. com.epson.mobilephone.common.ble.BleWork r0 = com.epson.mobilephone.common.ble.BleWork.this
  525. com.epson.mobilephone.common.ble.BleWork$jobSequence r0 = r0.mSequence
  526. r7.append(r0)
  527. java.lang.String r7 = r7.toString()
  528. com.epson.mobilephone.common.EPLog.i(r7)
  529. com.epson.mobilephone.common.ble.BleWork r7 = com.epson.mobilephone.common.ble.BleWork.this
  530. com.epson.mobilephone.common.ble.BleWork$jobSequence r7 = r7.mSequence
  531. int r7 = r7.ordinal()
  532. com.epson.mobilephone.common.ble.BleWork$jobSequence r0 = com.epson.mobilephone.common.ble.BleWork.jobSequence.MIB_REBOOT_NW
  533. int r0 = r0.ordinal()
  534. if (r7 > r0) goto L_0x03a1
  535. com.epson.mobilephone.common.ble.BleWork r7 = com.epson.mobilephone.common.ble.BleWork.this
  536. r7.setSSIDWork()
  537. goto L_0x03a1
  538. L_0x0198:
  539. java.lang.String r7 = "[Read]SNMP Response :error "
  540. com.epson.mobilephone.common.EPLog.e((java.lang.String) r7)
  541. goto L_0x03a1
  542. L_0x019f:
  543. java.lang.StringBuilder r7 = new java.lang.StringBuilder
  544. r7.<init>()
  545. java.lang.String r0 = "mibIdentifier requestId = "
  546. r7.append(r0)
  547. com.epson.mobilephone.common.ble.BleWork r0 = com.epson.mobilephone.common.ble.BleWork.this
  548. com.epson.mobilephone.common.escpr.MIBCommand r0 = r0.mMibCommand
  549. com.epson.mobilephone.common.escpr.MIBIdentifier r0 = r0.mibIdentifier
  550. int r0 = r0.requestId
  551. r7.append(r0)
  552. java.lang.String r7 = r7.toString()
  553. com.epson.mobilephone.common.EPLog.d(r7)
  554. com.epson.mobilephone.common.ble.BleWork r7 = com.epson.mobilephone.common.ble.BleWork.this
  555. com.epson.mobilephone.common.escpr.EscprLib r7 = r7.mEscprlib
  556. com.epson.mobilephone.common.ble.BleWork r0 = com.epson.mobilephone.common.ble.BleWork.this
  557. com.epson.mobilephone.common.escpr.MIBCommand r0 = r0.mMibCommand
  558. com.epson.mobilephone.common.ble.BleWork r1 = com.epson.mobilephone.common.ble.BleWork.this
  559. byte[] r1 = r1.mEngineID
  560. int r7 = r7.mibParseSecResponse(r0, r1)
  561. java.lang.StringBuilder r0 = new java.lang.StringBuilder
  562. r0.<init>()
  563. java.lang.String r1 = "mSequence "
  564. r0.append(r1)
  565. com.epson.mobilephone.common.ble.BleWork r1 = com.epson.mobilephone.common.ble.BleWork.this
  566. com.epson.mobilephone.common.ble.BleWork$jobSequence r1 = r1.mSequence
  567. r0.append(r1)
  568. java.lang.String r1 = " ret = "
  569. r0.append(r1)
  570. r0.append(r7)
  571. java.lang.String r0 = r0.toString()
  572. com.epson.mobilephone.common.EPLog.i(r0)
  573. if (r7 == 0) goto L_0x01fc
  574. java.lang.String r7 = "[Read]SNMP Response :end!"
  575. com.epson.mobilephone.common.EPLog.i(r7)
  576. goto L_0x03a1
  577. L_0x01fc:
  578. r6.IncrementSequence()
  579. java.lang.StringBuilder r0 = new java.lang.StringBuilder
  580. r0.<init>()
  581. java.lang.String r1 = "[Read]SNMP Response :"
  582. r0.append(r1)
  583. r0.append(r7)
  584. java.lang.String r7 = " mSequence "
  585. r0.append(r7)
  586. com.epson.mobilephone.common.ble.BleWork r7 = com.epson.mobilephone.common.ble.BleWork.this
  587. com.epson.mobilephone.common.ble.BleWork$jobSequence r7 = r7.mSequence
  588. r0.append(r7)
  589. java.lang.String r7 = r0.toString()
  590. com.epson.mobilephone.common.EPLog.i(r7)
  591. com.epson.mobilephone.common.ble.BleWork r7 = com.epson.mobilephone.common.ble.BleWork.this
  592. r7.setSSIDWork()
  593. goto L_0x03a1
  594. L_0x0226:
  595. com.epson.mobilephone.common.ble.BleWork r7 = com.epson.mobilephone.common.ble.BleWork.this
  596. com.epson.mobilephone.common.escpr.EscprLib r7 = r7.mEscprlib
  597. com.epson.mobilephone.common.ble.BleWork r0 = com.epson.mobilephone.common.ble.BleWork.this
  598. com.epson.mobilephone.common.escpr.MIBCommand r0 = r0.mMibCommand
  599. java.lang.String r7 = r7.mibParseResponseAsStr(r0)
  600. boolean r0 = r7.isEmpty()
  601. r0 = r0 ^ r3
  602. if (r0 != 0) goto L_0x0244
  603. java.lang.String r7 = "[Read]SNMP Response :end!"
  604. com.epson.mobilephone.common.EPLog.i(r7)
  605. goto L_0x03a1
  606. L_0x0244:
  607. r6.IncrementSequence()
  608. java.lang.StringBuilder r0 = new java.lang.StringBuilder
  609. r0.<init>()
  610. java.lang.String r1 = "[Read]SNMP Response :"
  611. r0.append(r1)
  612. r0.append(r7)
  613. java.lang.String r7 = " mSequence "
  614. r0.append(r7)
  615. com.epson.mobilephone.common.ble.BleWork r7 = com.epson.mobilephone.common.ble.BleWork.this
  616. com.epson.mobilephone.common.ble.BleWork$jobSequence r7 = r7.mSequence
  617. r0.append(r7)
  618. java.lang.String r7 = r0.toString()
  619. com.epson.mobilephone.common.EPLog.i(r7)
  620. com.epson.mobilephone.common.ble.BleWork r7 = com.epson.mobilephone.common.ble.BleWork.this
  621. r7.setSSIDWork()
  622. goto L_0x03a1
  623. L_0x026e:
  624. com.epson.mobilephone.common.ble.BleWork r7 = com.epson.mobilephone.common.ble.BleWork.this
  625. com.epson.mobilephone.common.escpr.EscprLib r7 = r7.mEscprlib
  626. com.epson.mobilephone.common.ble.BleWork r0 = com.epson.mobilephone.common.ble.BleWork.this
  627. com.epson.mobilephone.common.escpr.MIBCommand r0 = r0.mMibCommand
  628. java.lang.String r7 = r7.mibParseResponseAsMacaddress(r0)
  629. boolean r0 = r7.isEmpty()
  630. if (r0 != 0) goto L_0x02b6
  631. com.epson.mobilephone.common.ble.BleWork r0 = com.epson.mobilephone.common.ble.BleWork.this
  632. java.lang.String unused = r0.mDeviceMacAddress = r7
  633. com.epson.mobilephone.common.ble.BleWork r0 = com.epson.mobilephone.common.ble.BleWork.this
  634. com.epson.mobilephone.common.ble.BleWork$jobSequence r1 = com.epson.mobilephone.common.ble.BleWork.jobSequence.MIB_SET_SSID
  635. r0.mSequence = r1
  636. java.lang.StringBuilder r0 = new java.lang.StringBuilder
  637. r0.<init>()
  638. java.lang.String r1 = "[Read]SNMP Response :sucess:MacAddress ★"
  639. r0.append(r1)
  640. r0.append(r7)
  641. java.lang.String r7 = "★ mSequence "
  642. r0.append(r7)
  643. com.epson.mobilephone.common.ble.BleWork r7 = com.epson.mobilephone.common.ble.BleWork.this
  644. com.epson.mobilephone.common.ble.BleWork$jobSequence r7 = r7.mSequence
  645. r0.append(r7)
  646. java.lang.String r7 = r0.toString()
  647. com.epson.mobilephone.common.EPLog.i(r7)
  648. com.epson.mobilephone.common.ble.BleWork r7 = com.epson.mobilephone.common.ble.BleWork.this
  649. r7.setSSIDWork()
  650. goto L_0x03a1
  651. L_0x02b6:
  652. java.lang.String r7 = "[Read]SNMP Response :failed"
  653. com.epson.mobilephone.common.EPLog.e((java.lang.String) r7)
  654. goto L_0x03a1
  655. L_0x02bd:
  656. java.lang.Integer r7 = r7.getIntValue(r1, r4)
  657. java.lang.String r7 = r7.toString()
  658. java.lang.StringBuilder r0 = new java.lang.StringBuilder
  659. r0.<init>()
  660. java.lang.String r1 = "[Read]Version "
  661. r0.append(r1)
  662. r0.append(r7)
  663. java.lang.String r7 = r0.toString()
  664. com.epson.mobilephone.common.EPLog.i(r7)
  665. com.epson.mobilephone.common.ble.BleWork r7 = com.epson.mobilephone.common.ble.BleWork.this
  666. java.lang.String r7 = r7.mSSID
  667. if (r7 == 0) goto L_0x03a1
  668. com.epson.mobilephone.common.ble.BleWork r7 = com.epson.mobilephone.common.ble.BleWork.this
  669. java.lang.String r7 = r7.mSSID
  670. boolean r7 = r7.isEmpty()
  671. if (r7 != 0) goto L_0x03a1
  672. r6.IncrementSequence()
  673. java.lang.String r7 = " @@ checkSSID @@ "
  674. com.epson.mobilephone.common.EPLog.d(r7)
  675. com.epson.mobilephone.common.ble.BleWork r7 = com.epson.mobilephone.common.ble.BleWork.this
  676. android.bluetooth.BluetoothGatt r7 = r7.mConnGatt
  677. if (r7 != 0) goto L_0x0302
  678. java.lang.String r7 = "mConnGatt NULL !"
  679. com.epson.mobilephone.common.EPLog.e((java.lang.String) r7)
  680. L_0x0302:
  681. com.epson.mobilephone.common.ble.BleWork r7 = com.epson.mobilephone.common.ble.BleWork.this
  682. short r7 = r7.getSecurityType()
  683. r0 = 255(0xff, float:3.57E-43)
  684. if (r7 != r0) goto L_0x0328
  685. java.lang.String r7 = " skip "
  686. com.epson.mobilephone.common.EPLog.d(r7)
  687. com.epson.mobilephone.common.ble.BleWork r7 = com.epson.mobilephone.common.ble.BleWork.this
  688. com.epson.mobilephone.common.ble.util.BLEUtility$BleWorkCallback r7 = r7.mSequenceCallbackSuccess
  689. if (r7 == 0) goto L_0x03a1
  690. com.epson.mobilephone.common.ble.BleWork r7 = com.epson.mobilephone.common.ble.BleWork.this
  691. com.epson.mobilephone.common.ble.util.BLEUtility$BleWorkCallback r7 = r7.mSequenceCallbackSuccess
  692. com.epson.mobilephone.common.ble.BleWork r0 = com.epson.mobilephone.common.ble.BleWork.this
  693. com.epson.mobilephone.common.ble.BleWork$jobSequence r0 = r0.mSequence
  694. r7.call(r0)
  695. goto L_0x03a1
  696. L_0x0328:
  697. com.epson.mobilephone.common.ble.BleWork r7 = com.epson.mobilephone.common.ble.BleWork.this
  698. r7.checkSSID()
  699. goto L_0x03a1
  700. L_0x032e:
  701. java.lang.Integer r7 = r7.getIntValue(r1, r4)
  702. short r7 = r7.shortValue()
  703. java.lang.Short r7 = java.lang.Short.valueOf(r7)
  704. java.lang.String r0 = r7.toString()
  705. java.lang.StringBuilder r1 = new java.lang.StringBuilder
  706. r1.<init>()
  707. java.lang.String r2 = "802a0001-4ef4-4e59-b573-2bed4a4ac158\n[Read]Password "
  708. r1.append(r2)
  709. r1.append(r0)
  710. java.lang.String r0 = r1.toString()
  711. com.epson.mobilephone.common.EPLog.i(r0)
  712. short r7 = r7.shortValue()
  713. r0 = 65535(0xffff, float:9.1834E-41)
  714. if (r7 != r0) goto L_0x0367
  715. java.lang.String r7 = "password error !"
  716. com.epson.mobilephone.common.EPLog.e((java.lang.String) r7)
  717. com.epson.mobilephone.common.ble.BleWork r7 = com.epson.mobilephone.common.ble.BleWork.this
  718. com.epson.mobilephone.common.ble.BleWork$jobSequence r0 = com.epson.mobilephone.common.ble.BleWork.jobSequence.FAILED
  719. r7.mSequence = r0
  720. goto L_0x03a1
  721. L_0x0367:
  722. r6.IncrementSequence()
  723. com.epson.mobilephone.common.ble.BleWork r7 = com.epson.mobilephone.common.ble.BleWork.this
  724. r7.checkVersion()
  725. goto L_0x03a1
  726. L_0x0370:
  727. java.lang.String r7 = r7.getStringValue(r4)
  728. java.lang.StringBuilder r0 = new java.lang.StringBuilder
  729. r0.<init>()
  730. java.lang.String r1 = "00002a29-0000-1000-8000-00805f9b34fb\n[Read]Serial Number "
  731. r0.append(r1)
  732. r0.append(r7)
  733. java.lang.String r7 = r0.toString()
  734. com.epson.mobilephone.common.EPLog.i(r7)
  735. goto L_0x03a1
  736. L_0x0389:
  737. java.lang.String r7 = r7.getStringValue(r4)
  738. java.lang.StringBuilder r0 = new java.lang.StringBuilder
  739. r0.<init>()
  740. java.lang.String r1 = "00002a29-0000-1000-8000-00805f9b34fb\n[Read]Manufacturer Name "
  741. r0.append(r1)
  742. r0.append(r7)
  743. java.lang.String r7 = r0.toString()
  744. com.epson.mobilephone.common.EPLog.i(r7)
  745. L_0x03a1:
  746. return
  747. */
  748. throw new UnsupportedOperationException("Method not decompiled: com.epson.mobilephone.common.ble.BleWork.C10141.readCharacteristicData(android.bluetooth.BluetoothGattCharacteristic):void");
  749. }
  750. private void IncrementSequence() {
  751. int ordinal = BleWork.mSequence.ordinal();
  752. jobSequence[] values = jobSequence.values();
  753. BleWork.mSequence = values[ordinal + 1];
  754. EPLog.i("ΔΔ mSequence = " + BleWork.mSequence);
  755. }
  756. public void onCharacteristicWrite(BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic bluetoothGattCharacteristic, int i) {
  757. showStatus("Write", i);
  758. if (i != 0) {
  759. byte unused = BleWork.mIndex = (byte) 0;
  760. if (BleWork.mSequence == jobSequence.INITIALIZE) {
  761. failedProcessing();
  762. } else if (BleWork.mSequence == jobSequence.MIB_REBOOT_NW) {
  763. if (BleWork.mSuccess != null) {
  764. BleWork.mSuccess.call(BleWork.mSequence);
  765. }
  766. } else if (BleWork.mFailed != null) {
  767. BleWork.mFailed.call(BleWork.mSequence);
  768. }
  769. } else if (BleWork.mSequence == jobSequence.INITIALIZE) {
  770. characteristicRead();
  771. } else if (BleWork.mSequence == jobSequence.MIB_REBOOT_NW && BleWork.mSuccess != null) {
  772. BleWork.mSuccess.call(BleWork.mSequence);
  773. }
  774. }
  775. private void notifySet(@NonNull BluetoothGattCharacteristic bluetoothGattCharacteristic) {
  776. if (!BleWork.mConnGatt.setCharacteristicNotification(bluetoothGattCharacteristic, true)) {
  777. EPLog.e("Notification set ERROR");
  778. }
  779. BluetoothGattDescriptor descriptor = bluetoothGattCharacteristic.getDescriptor(UUID.fromString(BLEUuid.CLIENT_CHARACTERISTIC_CONFIG));
  780. descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
  781. EPLog.i("notify set");
  782. if (!BleWork.mConnGatt.writeDescriptor(descriptor)) {
  783. EPLog.e("Notification write ERROR");
  784. }
  785. }
  786. };
  787. handlerRead = new Handler();
  788. handlerWrite = new Handler();
  789. }
  790. @NonNull
  791. public static BleWork getInstace() {
  792. return SingletonHolder.INSTANCE;
  793. }
  794. private static final class SingletonHolder {
  795. private static final BleWork INSTANCE = new BleWork();
  796. private SingletonHolder() {
  797. }
  798. }
  799. public void resetSequence() {
  800. mSequence = jobSequence.UNINITIALIZED;
  801. mDevice = null;
  802. mSSIDPassword = null;
  803. mSsidLis.clear();
  804. mReconnect = false;
  805. mConnGatt = null;
  806. }
  807. @NonNull
  808. public static String getSSID(@NonNull Context context) {
  809. String curSSID = WiFiDirectManager.getCurSSID(context);
  810. EPLog.i("" + curSSID);
  811. return (curSSID == null || curSSID.equals("<unknown ssid>")) ? "" : curSSID;
  812. }
  813. public static boolean chechSSIDforBle(@NonNull Context context) {
  814. if (Build.VERSION.SDK_INT <= 28 || ActivityRequestLocationPermission.canAccessWiFiInfo(context, 4)) {
  815. return !getSSID(context).isEmpty() && !WiFiDirectManager.isSimpleAP(context);
  816. }
  817. return WiFiNetworkManager.getInsetance(context).isWiFiValidated();
  818. }
  819. public static boolean isStartBleProcess(@NonNull Context context, Boolean bool) {
  820. BluetoothAdapter adapter;
  821. BluetoothManager manager = BLEUtility.getManager(context);
  822. if ((manager != null && ((adapter = manager.getAdapter()) == null || !adapter.isEnabled())) || !BLEUtility.isBLESupported(context)) {
  823. return false;
  824. }
  825. if ((!bool.booleanValue() || MyPrinter.getCurPrinter(context).getName() == null) && chechSSIDforBle(context)) {
  826. return true;
  827. }
  828. return false;
  829. }
  830. private void setSequenceCallback(BLEUtility.BleWorkCallback bleWorkCallback, BLEUtility.BleWorkCallback bleWorkCallback2) {
  831. mSequenceCallbackSuccess = bleWorkCallback;
  832. mSequenceCallbackFailed = bleWorkCallback2;
  833. }
  834. private void setNotifyCallback(BLEUtility.BleWorkCallback bleWorkCallback) {
  835. mResposne = bleWorkCallback;
  836. }
  837. private void setSSID(BLEUtility.BleWorkCallback bleWorkCallback, BLEUtility.BleWorkCallback bleWorkCallback2) {
  838. mSuccess = bleWorkCallback;
  839. mFailed = bleWorkCallback2;
  840. mSequence = jobSequence.MIB_GET_MACADDRESS;
  841. setSSIDWork();
  842. }
  843. public void disconnect(boolean z) {
  844. EPLog.i("mSequence == " + mSequence + ":: " + mStatus);
  845. mSequence = z ? jobSequence.DISCONNECTED : mSequence;
  846. if (mConnGatt != null) {
  847. int i = mStatus;
  848. if (!(i == 3 || i == 0)) {
  849. EPLog.d(" !! mConnGatt disconnect");
  850. mConnGatt.disconnect();
  851. }
  852. EPLog.d(" !! mConnGatt close " + mSequence + " " + mStatus);
  853. mReconnect = false;
  854. if (z) {
  855. gattClose();
  856. }
  857. }
  858. }
  859. private void gattClose() {
  860. EPLog.d(" !! mConnGatt close");
  861. BluetoothGatt bluetoothGatt = mConnGatt;
  862. if (bluetoothGatt != null) {
  863. bluetoothGatt.close();
  864. mConnGatt = null;
  865. }
  866. }
  867. public void disconnect() {
  868. disconnect(true);
  869. }
  870. public void connect() {
  871. EPLog.i("再接続");
  872. mReconnect = true;
  873. mRetry = 0;
  874. EPLog.e("init");
  875. init();
  876. }
  877. private void setSSIDWork() {
  878. ((Activity) mContext).runOnUiThread(new Runnable() {
  879. public void run() {
  880. startSetSSID();
  881. }
  882. });
  883. }
  884. private void notifySet(@NonNull BluetoothGattCharacteristic bluetoothGattCharacteristic) {
  885. if (!mConnGatt.setCharacteristicNotification(bluetoothGattCharacteristic, true)) {
  886. EPLog.e("Notification set ERROR");
  887. }
  888. BluetoothGattDescriptor descriptor = bluetoothGattCharacteristic.getDescriptor(UUID.fromString(BLEUuid.CLIENT_CHARACTERISTIC_CONFIG));
  889. descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
  890. EPLog.i("notify set");
  891. if (!mConnGatt.writeDescriptor(descriptor)) {
  892. EPLog.e(" writeDescriptor ERROR");
  893. }
  894. }
  895. public class NotifySetThread extends AsyncTask<Void, Void, Boolean> {
  896. boolean stop;
  897. boolean success;
  898. private NotifySetThread() {
  899. stop = false;
  900. success = false;
  901. }
  902. protected void onPreExecute() {
  903. super.onPreExecute();
  904. EPLog.i();
  905. try {
  906. Thread.sleep(500);
  907. } catch (InterruptedException e) {
  908. e.printStackTrace();
  909. }
  910. setNotifyCallback(new BLEUtility.BleWorkCallback() {
  911. public void call(@NonNull Object obj) {
  912. EPLog.i(" -- NotifySetThread call");
  913. BluetoothGattCharacteristic bluetoothGattCharacteristic = BLEUuid.GattCharsMap.get(BLEUuid.CHAR_SECURITY_TYPE_STRING);
  914. BluetoothGattCharacteristic bluetoothGattCharacteristic2 = BLEUuid.GattCharsMap.get(BLEUuid.CHAR_SNMP_STATUS_STRING);
  915. BluetoothGattDescriptor bluetoothGattDescriptor = (BluetoothGattDescriptor) obj;
  916. if (bluetoothGattCharacteristic == bluetoothGattDescriptor.getCharacteristic()) {
  917. notifySet(bluetoothGattCharacteristic2);
  918. } else if (bluetoothGattCharacteristic2 == bluetoothGattDescriptor.getCharacteristic()) {
  919. NotifySetThread notifySetThread = NotifySetThread.this;
  920. notifySetThread.stop = true;
  921. notifySetThread.success = true;
  922. } else {
  923. stop = true;
  924. }
  925. }
  926. });
  927. }
  928. /* access modifiers changed from: protected */
  929. @Nullable
  930. public Boolean doInBackground(Void... voidArr) {
  931. notifySet(BLEUuid.GattCharsMap.get(BLEUuid.CHAR_SECURITY_TYPE_STRING));
  932. long currentTimeMillis = System.currentTimeMillis();
  933. while (System.currentTimeMillis() - currentTimeMillis <= 30000) {
  934. try {
  935. Thread.sleep(100);
  936. } catch (InterruptedException e) {
  937. e.printStackTrace();
  938. if (stop) {
  939. }
  940. }
  941. if (stop) {
  942. EPLog.i(" set ended ");
  943. EPLog.i();
  944. return Boolean.valueOf(success);
  945. }
  946. }
  947. EPLog.e(" set failed! ");
  948. return false;
  949. }
  950. protected void onPostExecute(Boolean bool) {
  951. super.onPostExecute(bool);
  952. if (bool.booleanValue()) {
  953. try {
  954. TimeUnit.MILLISECONDS.sleep(500);
  955. } catch (InterruptedException e) {
  956. e.printStackTrace();
  957. }
  958. BleWork.mSequence = jobSequence.INITIALIZE;
  959. checkPassword();
  960. return;
  961. }
  962. EPLog.e("setNotify");
  963. failedProcessing();
  964. }
  965. }
  966. private void characteristicRead() {
  967. EPLog.i("read " + mSequence);
  968. if (mSequence != jobSequence.MIB_REBOOT_NW) {
  969. final int[] iArr = {0};
  970. handlerRead.postDelayed(new Runnable() {
  971. public void run() {
  972. switch (C10195.$SwitchMap$com$epson$mobilephone$common$ble$BleWork$jobSequence[BleWork.mSequence.ordinal()]) {
  973. case 1:
  974. case 2:
  975. case 3:
  976. case 4:
  977. case 5:
  978. case 6:
  979. case 7:
  980. case 8:
  981. case 11:
  982. try {
  983. if (!((BluetoothGatt) Objects.requireNonNull(BleWork.mConnGatt)).readCharacteristic(BLEUuid.GattCharsMap.get(BLEUuid.CHAR_SNMP_RESPONSE_STRING))) {
  984. int[] iArr = iArr;
  985. int i = iArr[0] + 1;
  986. iArr[0] = i;
  987. if (i < 3) {
  988. EPLog.e("FALSE !! retry " + iArr[0]);
  989. handlerRead.removeCallbacks((Runnable) null);
  990. handlerRead.postDelayed(this, (long) (iArr[0] * 500));
  991. return;
  992. }
  993. EPLog.e("FALSE !!!");
  994. sequenceError();
  995. return;
  996. }
  997. return;
  998. } catch (NullPointerException unused) {
  999. EPLog.e("mConnGatt NULL !");
  1000. return;
  1001. }
  1002. case 9:
  1003. if (!BleWork.mConnGatt.readCharacteristic(BLEUuid.GattCharsMap.get(BLEUuid.CHAR_PASSWORD_STRING))) {
  1004. EPLog.e("FALSE !! ");
  1005. return;
  1006. }
  1007. return;
  1008. case 10:
  1009. if (!BleWork.mConnGatt.readCharacteristic(BLEUuid.GattCharsMap.get(BLEUuid.CHAR_VERSION_STRING))) {
  1010. EPLog.e("FALSE !! ");
  1011. return;
  1012. }
  1013. return;
  1014. default:
  1015. return;
  1016. }
  1017. }
  1018. }, 0);
  1019. }
  1020. }
  1021. private boolean init() {
  1022. int i;
  1023. mEscprlib.epsWrapperInitDriver(mContext.getApplicationContext(), 2);
  1024. if (!BLEUtility.isBLESupported(mContext)) {
  1025. return false;
  1026. }
  1027. BluetoothManager manager = BLEUtility.getManager(mContext);
  1028. if (manager != null) {
  1029. mBTAdapter = manager.getAdapter();
  1030. }
  1031. if (mBTAdapter == null) {
  1032. return false;
  1033. }
  1034. if (mDevice == null) {
  1035. mDevice = mSelectItem.getDevice();
  1036. if (mDevice == null) {
  1037. EPLog.e("mDevice is null !!!");
  1038. return false;
  1039. }
  1040. }
  1041. byte[] hardwareType = mSelectItem.getHardwareType();
  1042. if (hardwareType.length >= 3) {
  1043. i = 4096 - ByteBuffer.wrap(new byte[]{0, 0, hardwareType[2], hardwareType[1]}).getInt();
  1044. } else {
  1045. i = Constants.EDAM_APPLICATIONDATA_ENTRY_LEN_MAX;
  1046. }
  1047. EPLog.d("password = " + i);
  1048. mDevicePassword = String.valueOf(i);
  1049. if (mConnGatt == null && mStatus == 0) {
  1050. EPLog.i("connectGatt");
  1051. mConnGatt = mDevice.connectGatt(mContext, false, mGattcallback);
  1052. mStatus = 1;
  1053. if (!mReconnect) {
  1054. mSequence = jobSequence.UNINITIALIZED;
  1055. }
  1056. } else if (mConnGatt != null) {
  1057. EPLog.i("re-connect and re-discover Services");
  1058. mConnGatt.close();
  1059. mConnGatt = mDevice.connectGatt(mContext, false, mGattcallback);
  1060. mConnGatt.connect();
  1061. mConnGatt.discoverServices();
  1062. if (!mReconnect) {
  1063. mSequence = jobSequence.INITIALIZE;
  1064. }
  1065. } else {
  1066. EPLog.i(" STATE_CONNECTING");
  1067. mConnGatt = mDevice.connectGatt(mContext, false, mGattcallback);
  1068. mStatus = 1;
  1069. if (!mReconnect) {
  1070. mSequence = jobSequence.DISCONNECTED;
  1071. }
  1072. }
  1073. return true;
  1074. }
  1075. public boolean init(@NonNull Context context, @NonNull ScannedDevice scannedDevice) {
  1076. mContext = context;
  1077. mSelectItem = scannedDevice;
  1078. mRetry = 0;
  1079. mSequence = jobSequence.UNINITIALIZED;
  1080. setSecurityType(0);
  1081. mReconnect = true;
  1082. mSSID = getSSID(mContext);
  1083. EPLog.i(mSSID);
  1084. EPLog.e("init");
  1085. return init();
  1086. }
  1087. public void checkPassword() {
  1088. EPLog.i();
  1089. String str = mDevicePassword;
  1090. if (!str.isEmpty()) {
  1091. BluetoothGattCharacteristic bluetoothGattCharacteristic = BLEUuid.GattCharsMap.get(BLEUuid.CHAR_PASSWORD_STRING);
  1092. bluetoothGattCharacteristic.setValue(Short.parseShort(str), 18, 0);
  1093. EPLog.i("Password write :" + str);
  1094. gattWriteCharacter(bluetoothGattCharacteristic);
  1095. }
  1096. }
  1097. private void gattWriteCharacter(final BluetoothGattCharacteristic bluetoothGattCharacteristic) {
  1098. final int[] iArr = {0};
  1099. handlerWrite.removeCallbacks((Runnable) null);
  1100. handlerWrite.postDelayed(new Runnable() {
  1101. public void run() {
  1102. if (BleWork.mConnGatt == null) {
  1103. EPLog.e("mConnGatt NULL !");
  1104. }
  1105. if (bluetoothGattCharacteristic == null) {
  1106. EPLog.e("characteristic NULL !");
  1107. }
  1108. try {
  1109. if (!((BluetoothGatt) Objects.requireNonNull(BleWork.mConnGatt)).writeCharacteristic(bluetoothGattCharacteristic)) {
  1110. int[] iArr = iArr;
  1111. int i = iArr[0] + 1;
  1112. iArr[0] = i;
  1113. if (i <= 3) {
  1114. EPLog.e("writeCharacteristic error ! retry " + iArr[0]);
  1115. handlerWrite.removeCallbacks((Runnable) null);
  1116. handlerWrite.postDelayed(this, (long) (iArr[0] * 500));
  1117. return;
  1118. }
  1119. EPLog.e("writeCharacteristic error !! retry failed !!");
  1120. failedProcessing();
  1121. }
  1122. } catch (NullPointerException unused) {
  1123. EPLog.e("mConnGatt NULL !");
  1124. }
  1125. }
  1126. }, 0);
  1127. }
  1128. public void checkVersion() {
  1129. characteristicRead();
  1130. }
  1131. public void getSSIDList() {
  1132. mInSequence = true;
  1133. mSequence = jobSequence.MIB_GET_SSID_LIST;
  1134. EscprLib escprLib = mEscprlib;
  1135. MIBCommand mIBCommand = mMibCommand;
  1136. byte b = (byte) (mIndex + 1);
  1137. mIndex = b;
  1138. int mibGetESSIDList = escprLib.mibGetESSIDList(mIBCommand, b);
  1139. if (mibGetESSIDList != 0) {
  1140. EPLog.e("mibGetESSIDList ret = " + mibGetESSIDList);
  1141. return;
  1142. }
  1143. byte[] bArr = new byte[mMibCommand.commandBlock.bufSize];
  1144. System.arraycopy(mMibCommand.commandBlock.buf, 0, bArr, 0, mMibCommand.commandBlock.bufSize);
  1145. BluetoothGattCharacteristic bluetoothGattCharacteristic = BLEUuid.GattCharsMap.get(BLEUuid.CHAR_SNMP_REQUEST_STRING);
  1146. bluetoothGattCharacteristic.setValue(bArr);
  1147. gattWriteCharacter(bluetoothGattCharacteristic);
  1148. }
  1149. private void checkSSID() {
  1150. try {
  1151. TimeUnit.SECONDS.sleep(1);
  1152. } catch (InterruptedException e) {
  1153. e.printStackTrace();
  1154. }
  1155. byte[] bytes = mSSID.getBytes(Charset.forName("UTF8"));
  1156. BluetoothGattCharacteristic bluetoothGattCharacteristic = BLEUuid.GattCharsMap.get(BLEUuid.CHAR_SSID_STRING);
  1157. bluetoothGattCharacteristic.setValue(bytes);
  1158. EPLog.i("SSID write :" + mSSID);
  1159. gattWriteCharacter(bluetoothGattCharacteristic);
  1160. }
  1161. public void setSSIDType() {
  1162. mSequence = jobSequence.CHECK_SSID;
  1163. if (mConnGatt == null) {
  1164. EPLog.e("mConnGatt NULL !");
  1165. }
  1166. checkSSID();
  1167. }
  1168. private void startSetSSID() {
  1169. int i;
  1170. EPLog.i("mSequence = " + mSequence + " mSSID = " + mSSID);
  1171. mInSequence = false;
  1172. String str = "";
  1173. String str2 = "";
  1174. switch (mSequence) {
  1175. case MIB_GET_MACADDRESS:
  1176. str = "epsGetMacAddress";
  1177. str2 = "mibGetMacadress";
  1178. i = mEscprlib.mibGetMacadress(mMibCommand);
  1179. break;
  1180. case MIB_SET_SSID:
  1181. str = "epsWlanConfSSID";
  1182. str2 = "mibSetSSID";
  1183. EPLog.i("mSSID " + mSSID);
  1184. if (!mSSID.isEmpty()) {
  1185. i = mEscprlib.mibSetSSID(mMibCommand, mSSID);
  1186. break;
  1187. } else {
  1188. EPLog.m82w("set SSID : empty");
  1189. return;
  1190. }
  1191. case MIB_SEC_LOGIN:
  1192. str = "epsAdminMibAccessLoginOperation";
  1193. str2 = "mibSecLogin ";
  1194. if (mEngineID == null) {
  1195. EPLog.e("mEngineID");
  1196. failedProcessing();
  1197. }
  1198. i = mEscprlib.mibSecLogin(mMibCommand, mEngineID);
  1199. break;
  1200. case MIB_SEC_SET_PASS:
  1201. str = "epsWlanCommonPassPhrase";
  1202. str2 = "mibSecSetPass ";
  1203. String str3 = mSSIDPassword;
  1204. EPLog.i("mSSIDPassword " + mSSIDPassword);
  1205. if (str3.isEmpty()) {
  1206. EPLog.m82w("SSIDPassword is empty");
  1207. }
  1208. if (mEngineID == null) {
  1209. EPLog.e("mEngineID");
  1210. failedProcessing();
  1211. }
  1212. i = mEscprlib.mibSecSetPassword(mMibCommand, mEngineID, str3);
  1213. break;
  1214. case MIB_SEC_LOGOUT:
  1215. str = "epsAdminMibAccessLogOutOperation";
  1216. str2 = "mibSecLogout ";
  1217. if (mEngineID == null) {
  1218. EPLog.e("mEngineID");
  1219. failedProcessing();
  1220. }
  1221. i = mEscprlib.mibSecLogout(mMibCommand, mEngineID);
  1222. break;
  1223. case MIB_SET_SECURITY_TYPE:
  1224. str = "epsWlanSecurityType";
  1225. str2 = "mibSetSecurityType ";
  1226. if (mSSIDPassword == null) {
  1227. mSSIDPassword = "";
  1228. }
  1229. int i2 = mSSIDPassword.isEmpty() ? 0 : 255;
  1230. EPLog.i("MIB_SET_SECURITY_TYPE SecurityType = " + i2);
  1231. int mibSetSecurityType = mEscprlib.mibSetSecurityType(mMibCommand, i2);
  1232. if (i2 == 0) {
  1233. mSequence = jobSequence.MIB_SEC_SKIP;
  1234. }
  1235. i = mibSetSecurityType;
  1236. break;
  1237. case MIB_REBOOT_NW:
  1238. str = "epsBluetoothOperationSetupEnd";
  1239. str2 = "mibRebootNW ";
  1240. i = mEscprlib.mibRebootNWwithBLE(mMibCommand);
  1241. break;
  1242. default:
  1243. i = 0;
  1244. break;
  1245. }
  1246. if (i != 0) {
  1247. EPLog.e(str2 + " ret = " + i);
  1248. sequenceError();
  1249. return;
  1250. }
  1251. byte[] bArr = new byte[mMibCommand.commandBlock.bufSize];
  1252. System.arraycopy(mMibCommand.commandBlock.buf, 0, bArr, 0, mMibCommand.commandBlock.bufSize);
  1253. EPLog.i("SNMP Request write :" + str + " mSequence " + mSequence);
  1254. BluetoothGattCharacteristic bluetoothGattCharacteristic = BLEUuid.GattCharsMap.get(BLEUuid.CHAR_SNMP_REQUEST_STRING);
  1255. bluetoothGattCharacteristic.setValue(bArr);
  1256. gattWriteCharacter(bluetoothGattCharacteristic);
  1257. }
  1258. private void sequenceError() {
  1259. failedProcessing();
  1260. }
  1261. private void failedProcessing() {
  1262. disconnect();
  1263. if (mSequenceCallbackFailed != null) {
  1264. EPLog.e(" " + mSequence);
  1265. mSequenceCallbackFailed.call(mSequence);
  1266. }
  1267. }
  1268. }