123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330 |
- package com.epson.mobilephone.common.ble;
- import android.app.Activity;
- import android.app.AlertDialog;
- import android.content.Context;
- import android.content.DialogInterface;
- import android.content.Intent;
- import android.os.AsyncTask;
- import android.os.Handler;
- import android.os.HandlerThread;
- import com.epson.mobilephone.common.EpLog;
- import com.epson.mobilephone.common.ble.util.BLEUtility;
- import com.epson.mobilephone.common.ble.util.ScannedDevice;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.concurrent.CancellationException;
- import java.util.concurrent.ExecutionException;
- import java.util.concurrent.TimeUnit;
- import java.util.concurrent.TimeoutException;
- public class BleAsyncTask extends AsyncTask<Void, Void, Boolean> {
- private static AlertDialog dialog = null;
- private static HandlerThread handlerThread = null;
- private static boolean mStop = false;
- private static BleAsyncTask mTask;
- private static Runnable mTimeOutTask;
- private BleScanWork mBleWork = null;
- private BLEUtility.BleWorkCallback mCallBack = null;
- private List<ScannedDevice> mDevicelist = null;
- private Boolean mFind = false;
- private long mTimeOut = -1;
- private long mTimeOutScan = -1;
- private Activity m_Activity;
- public static void setStop(boolean z) {
- EpLog.m69d("mStop " + z);
- mStop = z;
- if (z) {
- EpLog.m69d("★ stopScan");
- BleScanWork.getInstace().stopScan();
- if (mTimeOutTask != null) {
- mTimeOutTask = null;
- BleAsyncTask bleAsyncTask = mTask;
- if (bleAsyncTask != null) {
- bleAsyncTask.cancel(true);
- }
- }
- }
- }
- public BleAsyncTask(Activity activity) {
- mTimeOutTask = new Runnable() {
- public void run() {
- try {
- BleAsyncTask.this.get(BleAsyncTask.this.mTimeOut, TimeUnit.MILLISECONDS);
- } catch (InterruptedException unused) {
- EpLog.m71e("InterruptedException");
- } catch (ExecutionException unused2) {
- EpLog.m71e("ExecutionException");
- } catch (TimeoutException unused3) {
- EpLog.m77i("Running task has timed out!!");
- if (BleAsyncTask.this.mBleWork != null) {
- BleAsyncTask.this.mBleWork.stopScan();
- }
- BleAsyncTask.mTask.cancel(true);
- } catch (CancellationException unused4) {
- EpLog.m71e("CancellationException");
- }
- }
- };
- this.m_Activity = activity;
- this.mTimeOut = (long) (BleWork.getScanAdvertisingPacketTimeout() + 2000);
- this.mTimeOutScan = -1;
- }
- public BleAsyncTask(Activity activity, BLEUtility.BleWorkCallback bleWorkCallback, int i) {
- mTimeOutTask = new Runnable() {
- public void run() {
- try {
- BleAsyncTask.this.get(BleAsyncTask.this.mTimeOut, TimeUnit.MILLISECONDS);
- } catch (InterruptedException unused) {
- EpLog.m71e("InterruptedException");
- } catch (ExecutionException unused2) {
- EpLog.m71e("ExecutionException");
- } catch (TimeoutException unused3) {
- EpLog.m77i("Running task has timed out!!");
- if (BleAsyncTask.this.mBleWork != null) {
- BleAsyncTask.this.mBleWork.stopScan();
- }
- BleAsyncTask.mTask.cancel(true);
- } catch (CancellationException unused4) {
- EpLog.m71e("CancellationException");
- }
- }
- };
- this.m_Activity = activity;
- this.mTimeOut = (long) (i + 2000);
- this.mTimeOutScan = (long) i;
- this.mCallBack = bleWorkCallback;
- }
- protected void onPreExecute() {
- super.onPreExecute();
- this.mBleWork = BleScanWork.getInstace();
- }
- /* access modifiers changed from: protected */
- /* JADX WARNING: Removed duplicated region for block: B:14:0x0072 */
- /* JADX WARNING: Removed duplicated region for block: B:26:0x00ac A[EDGE_INSN: B:26:0x00ac->B:24:0x00ac ?: BREAK , SYNTHETIC] */
- /* Code decompiled incorrectly, please refer to instructions dump. */
- public java.lang.Boolean doInBackground(java.lang.Void... r5) {
- /*
- r4 = this;
- java.lang.StringBuilder r5 = new java.lang.StringBuilder
- r5.<init>()
- java.lang.String r0 = "mStop "
- r5.append(r0)
- boolean r0 = mStop
- r5.append(r0)
- java.lang.String r5 = r5.toString()
- com.epson.mobilephone.common.EpLog.m77i(r5)
- boolean r5 = mStop
- if (r5 == 0) goto L_0x001d
- java.lang.Boolean r5 = r4.mFind
- return r5
- L_0x001d:
- java.lang.Thread r5 = java.lang.Thread.currentThread()
- java.lang.String r0 = "BleAsyncTask"
- r5.setName(r0)
- com.epson.mobilephone.common.EpLog.m68d()
- java.lang.Thread r5 = java.lang.Thread.currentThread()
- java.lang.String r5 = r5.getName()
- com.epson.mobilephone.common.EpLog.m77i(r5)
- mTask = r4
- long r0 = r4.mTimeOut
- r2 = 0
- int r5 = (r0 > r2 ? 1 : (r0 == r2 ? 0 : -1))
- if (r5 <= 0) goto L_0x0048
- java.lang.Thread r5 = new java.lang.Thread
- java.lang.Runnable r0 = mTimeOutTask
- r5.<init>(r0)
- r5.start()
- L_0x0048:
- com.epson.mobilephone.common.ble.BleScanWork r5 = r4.mBleWork
- android.app.Activity r0 = r4.m_Activity
- boolean r5 = r5.init_scan(r0)
- if (r5 != 0) goto L_0x005a
- java.lang.String r5 = "BLE is not available !!"
- com.epson.mobilephone.common.EpLog.m82w(r5)
- java.lang.Boolean r5 = r4.mFind
- return r5
- L_0x005a:
- java.lang.String r5 = "BLE is available!!"
- com.epson.mobilephone.common.EpLog.m77i(r5)
- com.epson.mobilephone.common.ble.BleScanWork r5 = r4.mBleWork
- com.epson.mobilephone.common.ble.BleAsyncTask$2 r0 = new com.epson.mobilephone.common.ble.BleAsyncTask$2
- r0.<init>()
- com.epson.mobilephone.common.ble.BleAsyncTask$3 r1 = new com.epson.mobilephone.common.ble.BleAsyncTask$3
- r1.<init>()
- r5.search(r0, r1)
- L_0x006e:
- boolean r5 = mStop
- if (r5 != 0) goto L_0x00ac
- java.lang.StringBuilder r5 = new java.lang.StringBuilder
- r5.<init>()
- java.lang.String r0 = "生きてるんです. mStop = "
- r5.append(r0)
- boolean r0 = mStop
- r5.append(r0)
- java.lang.String r5 = r5.toString()
- com.epson.mobilephone.common.EpLog.m69d(r5)
- r0 = 2000(0x7d0, double:9.88E-321)
- java.lang.Thread.sleep(r0) // Catch:{ InterruptedException -> 0x008e }
- goto L_0x0093
- L_0x008e:
- java.lang.String r5 = "InterruptedException"
- com.epson.mobilephone.common.EpLog.m71e((java.lang.String) r5)
- L_0x0093:
- boolean r5 = r4.isCancelled()
- if (r5 != 0) goto L_0x009d
- boolean r5 = mStop
- if (r5 == 0) goto L_0x006e
- L_0x009d:
- java.lang.String r5 = "死にます"
- com.epson.mobilephone.common.EpLog.m69d(r5)
- java.lang.String r5 = "★ stopScan"
- com.epson.mobilephone.common.EpLog.m69d(r5)
- com.epson.mobilephone.common.ble.BleScanWork r5 = r4.mBleWork
- r5.stopScan()
- L_0x00ac:
- java.lang.StringBuilder r5 = new java.lang.StringBuilder
- r5.<init>()
- java.lang.String r0 = "見つかった? "
- r5.append(r0)
- java.lang.Boolean r0 = r4.mFind
- r5.append(r0)
- java.lang.String r5 = r5.toString()
- com.epson.mobilephone.common.EpLog.m69d(r5)
- java.lang.Boolean r5 = r4.mFind
- return r5
- */
- throw new UnsupportedOperationException("Method not decompiled: com.epson.mobilephone.common.ble.BleAsyncTask.doInBackground(java.lang.Void[]):java.lang.Boolean");
- }
- protected void onPostExecute(Boolean bool) {
- super.onPostExecute(bool);
- EpLog.m69d("" + bool);
- }
- private void showAdvanceToSettingDialog() {
- if (this.mCallBack != null) {
- this.mDevicelist = this.mBleWork.getScannedDeviceList();
- ArrayList arrayList = new ArrayList();
- for (ScannedDevice next : this.mDevicelist) {
- arrayList.add(new ScannedDevice(next.getDevice(), next.getRssi(), next.getDisplayName(), next.getHardwareType()));
- }
- EpLog.m69d(" ★ mDevicelist " + arrayList.size());
- this.mCallBack.call(arrayList);
- return;
- }
- dialog = new AlertDialog.Builder(this.m_Activity).setCancelable(false).setMessage(this.m_Activity.getString(R.string.BLE_find_unconfigured_printer_title)).setPositiveButton(this.m_Activity.getString(R.string.BLE_find_unconfigured_printer_setup_button), new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialogInterface, int i) {
- EpLog.m69d("★ stopScan");
- BleAsyncTask.this.mBleWork.stopScan();
- BleAsyncTask bleAsyncTask = BleAsyncTask.this;
- List unused = bleAsyncTask.mDevicelist = bleAsyncTask.mBleWork.getScannedDeviceList();
- ArrayList arrayList = new ArrayList();
- for (ScannedDevice scannedDevice : BleAsyncTask.this.mDevicelist) {
- arrayList.add(new ScannedDevice(scannedDevice.getDevice(), scannedDevice.getRssi(), scannedDevice.getDisplayName(), scannedDevice.getHardwareType()));
- }
- Intent intent = new Intent(BleAsyncTask.this.m_Activity.getApplicationContext(), BleWorkActivity.class);
- intent.putParcelableArrayListExtra(ScannedDevice.TYPE, arrayList);
- BleAsyncTask.this.m_Activity.startActivity(intent);
- }
- }).setNegativeButton(this.m_Activity.getString(R.string.BLE_find_unconfigured_printer_not_now_button), new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialogInterface, int i) {
- EpLog.m69d("★ stopScan");
- BleAsyncTask.this.mBleWork.stopScan();
- BleAsyncTask.setStop(true);
- }
- }).create();
- dialog.show();
- }
- protected void onCancelled(Boolean bool) {
- super.onCancelled(bool);
- EpLog.m69d("死にました。 " + bool);
- }
- protected void onCancelled() {
- super.onCancelled();
- }
- public BleAsyncTask setTimeOut(long j) {
- this.mTimeOut = j;
- return this;
- }
- public static void blePrinterCheck(Context context) {
- setStop(false);
- EpLog.m76i();
- AlertDialog alertDialog = dialog;
- if (alertDialog == null || !alertDialog.isShowing()) {
- final Activity activity = (Activity) context;
- if (BLEUtility.isThreadAlive("bleCheck")) {
- EpLog.m69d("isAlive bleCheck");
- } else if (handlerThread != null) {
- EpLog.m71e("handlerThread != null ");
- } else {
- EpLog.m77i("★ handlerThread start ");
- handlerThread = new HandlerThread("bleCheck");
- handlerThread.start();
- new Handler(handlerThread.getLooper()).postDelayed(new Runnable() {
- public void run() {
- EpLog.m77i(" 0 handlerThread run !!!!");
- BleAsyncTask.handlerThread.quitSafely();
- new BleAsyncTask(activity).execute(new Void[0]);
- }
- }, 500);
- }
- }
- }
- public static void blePrinterCheck(Context context, final BLEUtility.BleWorkCallback bleWorkCallback) {
- setStop(false);
- EpLog.m76i();
- final Activity activity = (Activity) context;
- if (BLEUtility.isThreadAlive("bleCheck")) {
- EpLog.m69d(" ‼ isAlive bleCheck");
- return;
- }
- EpLog.m77i("handlerThread");
- handlerThread = new HandlerThread("bleCheck");
- handlerThread.start();
- new Handler(handlerThread.getLooper()).postDelayed(new Runnable() {
- public void run() {
- EpLog.m77i(" handlerThread run !!!!");
- BleAsyncTask.handlerThread.quitSafely();
- new BleAsyncTask(activity, bleWorkCallback, BleWork.getScanAdvertisingPacketTimeout()).execute(new Void[0]);
- }
- }, 1000);
- }
- public static void blePrinterCheckStop() {
- EpLog.m76i();
- if (handlerThread != null) {
- setStop(true);
- handlerThread.quitSafely();
- handlerThread = null;
- AlertDialog alertDialog = dialog;
- if (alertDialog != null && alertDialog.isShowing()) {
- dialog.dismiss();
- }
- Thread thread = BLEUtility.getThread("bleCheck");
- if (thread != null && thread.isAlive()) {
- EpLog.m77i("interrupt");
- thread.interrupt();
- try {
- EpLog.m77i("join");
- thread.join(50);
- } catch (InterruptedException e) {
- EpLog.m71e(e.getMessage());
- }
- }
- } else {
- EpLog.m77i("handlerThread NULL return !!");
- }
- }
- }
|