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