// Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov. // Jad home page: http://www.geocities.com/kpdus/jad.html // Decompiler options: braces fieldsfirst space lnc package com.oliodevices.assist.app.fragments; import android.app.Activity; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.content.BroadcastReceiver; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.IntentFilter; import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; import android.support.v4.app.FragmentActivity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.Button; import android.widget.ListView; import butterknife.ButterKnife; import com.olio.state.Unit; import com.olio.util.ALog; import com.oliodevices.assist.app.activities.SetupActivityCallbacks; import com.oliodevices.assist.app.adapters.DeviceListAdapter; import com.oliodevices.assist.app.api.ApiResultCallback; import com.oliodevices.assist.app.api.OlioApi; import com.oliodevices.assist.app.api.UserManager; import com.oliodevices.assist.app.core.OlioApplication; import com.oliodevices.assist.app.core.Utils; import java.lang.annotation.Annotation; import java.util.ArrayList; import java.util.Iterator; import java.util.Objects; import java.util.Set; import retrofit.RetrofitError; import retrofit.client.Response; // Referenced classes of package com.oliodevices.assist.app.fragments: // SetupBaseFragment, TitleChanger public class SetupConnectFragment extends SetupBaseFragment implements TitleChanger { private static interface BoundState extends Annotation { } private static final String OLIO_MAC_PREFIX = "B0:C5:CA:D"; public static final int STATE_CONNECT = 2; public static final int STATE_FAIL = 3; public static final int STATE_IDLE = 0; public static final int STATE_REQUEST = 1; private AsyncTask mGetDataTask; private DeviceListAdapter mListAdapter; private int mPairState; private final BroadcastReceiver mReceiver = new BroadcastReceiver() { final SetupConnectFragment this$0; public void onReceive(Context context, Intent intent) { context = intent.getAction(); if (!"android.bluetooth.device.action.FOUND".equals(context)) goto _L2; else goto _L1 _L1: BluetoothDevice bluetoothdevice; int i; bluetoothdevice = (BluetoothDevice)intent.getParcelableExtra("android.bluetooth.device.extra.DEVICE"); i = bluetoothdevice.getType(); context = "Unknown"; i; JVM INSTR tableswitch 1 3: default 64 // 1 113 // 2 107 // 3 119; goto _L3 _L4 _L5 _L6 _L3: ALog.d("BT %s device: %s (%s)", new Object[] { context, bluetoothdevice.getAddress(), bluetoothdevice.getName() }); if (bluetoothdevice.getAddress().startsWith("B0:C5:CA:D")) goto _L8; else goto _L7 _L7: return; _L5: context = "LE"; continue; /* Loop/switch isn't completed */ _L4: context = "Legacy"; continue; /* Loop/switch isn't completed */ _L6: context = "Dual"; continue; /* Loop/switch isn't completed */ _L8: short word0 = intent.getShortExtra("android.bluetooth.device.extra.RSSI", (short)-32768); mListAdapter.add(bluetoothdevice); mListAdapter.setRssiForDevice(bluetoothdevice, word0); return; _L2: if (!"android.bluetooth.device.action.BOND_STATE_CHANGED".equals(context)) { break; /* Loop/switch isn't completed */ } context = (BluetoothDevice)intent.getParcelableExtra("android.bluetooth.device.extra.DEVICE"); if (mSelectedDevice == null || !Objects.equals(mSelectedDevice.getAddress(), context.getAddress())) goto _L7; else goto _L9 _L9: int j = intent.getIntExtra("android.bluetooth.device.extra.BOND_STATE", 0); int k = intent.getIntExtra("android.bluetooth.device.extra.PREVIOUS_BOND_STATE", 0); switch (j) { case 11: // '\013' default: return; case 10: // '\n' if (k == 11) { if (isResumed()) { mSelectedDevice = null; ALog.d("Bond state changed: Bonding to None", new Object[0]); showConnectionFailureMessage(0x7f060137); mPairState = 0; return; } else { mPairState = 3; return; } } break; case 12: // '\f' confirmBond(context); return; } if (true) goto _L7; else goto _L10 _L10: if (!"android.bluetooth.adapter.action.STATE_CHANGED".equals(context)) { continue; /* Loop/switch isn't completed */ } if (intent.getIntExtra("android.bluetooth.adapter.extra.STATE", 0) != 12) goto _L7; else goto _L11 _L11: findDevices(); return; if (!"android.bluetooth.adapter.action.DISCOVERY_FINISHED".equals(context) || mPairState == 1) goto _L7; else goto _L12 _L12: cancelDiscovery(); return; if (true) goto _L3; else goto _L13 _L13: } { this$0 = SetupConnectFragment.this; super(); } }; Button mScanAgainButton; private BluetoothDevice mSelectedDevice; public SetupConnectFragment() { mPairState = 0; } private void cancelDiscovery() { BluetoothAdapter bluetoothadapter = BluetoothAdapter.getDefaultAdapter(); if (mCallbacks != null) { mCallbacks.hideProgress(); } mScanAgainButton.setVisibility(0); if (bluetoothadapter.isDiscovering()) { bluetoothadapter.cancelDiscovery(); } } private void claimUnit() { final FragmentActivity context = getActivity(); OlioApi.getInstance().claimUnit(mSelectedDevice.getAddress(), new ApiResultCallback() { final SetupConnectFragment this$0; final Context val$context; public void failure(RetrofitError retrofiterror) { if (retrofiterror != null && retrofiterror.getKind() == retrofit.RetrofitError.Kind.NETWORK) { if (isAdded()) { (new android.app.AlertDialog.Builder(context)).setTitle(0x7f060098).setMessage(0x7f060126).setCancelable(true).setNegativeButton(0x1040000, null).setPositiveButton(0x104000a, new android.content.DialogInterface.OnClickListener() { final _cls4 this$1; public void onClick(DialogInterface dialoginterface, int i) { claimUnit(); } { this$1 = _cls4.this; super(); } }).show(); return; } ALog.w("Fragment appears to be detached from Activity", new Object[0]); mSelectedDevice = null; if (mCallbacks != null) { mCallbacks.goToScreen(9); } mPairState = 0; return; } if (retrofiterror == null || retrofiterror.getResponse() == null) { mSelectedDevice = null; if (mCallbacks != null) { mCallbacks.goToScreen(9); } mPairState = 0; return; } switch (retrofiterror.getResponse().getStatus()) { default: mSelectedDevice = null; showConnectionFailureMessage(0x7f060148); mPairState = 0; return; case 401: mPairState = 0; break; } showCompleteRegistrationMessage(0x7f06006c, 0x7f06006b, 0x7f060071, 0x7f060070); } public void success(Unit unit) { if (!isAdded()) { break MISSING_BLOCK_LABEL_126; } UserManager.getInstance().updateUnitId(mSelectedDevice.getAddress()); unit.setUnitId(unit.getId()); unit.save(getActivity().getContentResolver()); if (mSelectedDevice.getBondState() != 12) goto _L2; else goto _L1 _L1: Utils.startServices(context); mCallbacks.goToScreen(8); _L4: return; _L2: registerReceiver("android.bluetooth.device.action.BOND_STATE_CHANGED"); if (mSelectedDevice.createBond()) goto _L4; else goto _L3 _L3: ALog.d("createBond failed", new Object[0]); showConnectionFailureMessage(0x7f060137); return; ALog.w("Fragment appears to be detached from Activity", new Object[0]); return; } public volatile void success(Object obj) { success((Unit)obj); } { this$0 = SetupConnectFragment.this; context = context1; super(); } }); } private void confirmBond(final BluetoothDevice device) { mGetDataTask = (new AsyncTask() { final SetupConnectFragment this$0; final BluetoothDevice val$device; protected volatile Object doInBackground(Object aobj[]) { return doInBackground((Void[])aobj); } protected transient Void doInBackground(Void avoid[]) { if (!isCancelled()) { long l = System.currentTimeMillis(); while (device.getBondState() != 12 && l + 2000L < System.currentTimeMillis()) { try { ALog.d("%s not bonded", new Object[] { device.getAddress() }); Thread.sleep(500L); } // Misplaced declaration of an exception variable catch (Void avoid[]) { ALog.e("Cannot put thread to sleep", avoid, new Object[0]); } } } return null; } protected volatile void onPostExecute(Object obj) { onPostExecute((Void)obj); } protected void onPostExecute(Void void1) { if (device.getBondState() != 12) { if (isResumed()) { ALog.d("%s not bonded, failing", new Object[] { device.getAddress() }); showConnectionFailureMessage(0x7f060137); mPairState = 0; } else { mPairState = 3; } OlioApplication.getApplication().reportWatchTracking("PairingFailed", UserManager.getInstance().getEmailForAnalytics(), 0); } else { if (isResumed()) { ALog.d("%s bonded", new Object[] { device.getAddress() }); mCallbacks.goToScreen(8); mPairState = 0; } else { mPairState = 2; } OlioApplication.getApplication().reportWatchTracking("Paired", UserManager.getInstance().getEmailForAnalytics(), 0); if (isResumed()) { Utils.startServices(getActivity()); return; } } } { this$0 = SetupConnectFragment.this; device = bluetoothdevice; super(); } }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Void[0]); } private void findDevices() { mCallbacks.showProgress(false); mScanAgainButton.setVisibility(8); registerReceiver("android.bluetooth.device.action.FOUND"); registerReceiver("android.bluetooth.adapter.action.DISCOVERY_FINISHED"); BluetoothAdapter bluetoothadapter = BluetoothAdapter.getDefaultAdapter(); if (bluetoothadapter.isDiscovering()) { bluetoothadapter.cancelDiscovery(); } Iterator iterator = bluetoothadapter.getBondedDevices().iterator(); do { if (!iterator.hasNext()) { break; } BluetoothDevice bluetoothdevice = (BluetoothDevice)iterator.next(); if (bluetoothdevice.getAddress().startsWith("B0:C5:CA:D")) { mListAdapter.add(bluetoothdevice); } } while (true); bluetoothadapter.startDiscovery(); } private void initializeView(View view) { mListAdapter = new DeviceListAdapter(getActivity(), new ArrayList()); view = (ListView)ButterKnife.findById(view, 0x7f0d0166); view.setAdapter(mListAdapter); view.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() { final SetupConnectFragment this$0; public void onItemClick(AdapterView adapterview, View view1, int i, long l) { pairUnit((BluetoothDevice)mListAdapter.getItem(i)); } { this$0 = SetupConnectFragment.this; super(); } }); } private void pairUnit(BluetoothDevice bluetoothdevice) { mPairState = 1; cancelDiscovery(); mSelectedDevice = bluetoothdevice; claimUnit(); } private void registerReceiver(String s) { getActivity().registerReceiver(mReceiver, new IntentFilter(s)); } private void showCompleteRegistrationMessage(int i, int j, int k, int l) { if (getActivity() != null) { (new android.app.AlertDialog.Builder(getActivity())).setTitle(i).setMessage(j).setCancelable(false).setNegativeButton(l, new android.content.DialogInterface.OnClickListener() { final SetupConnectFragment this$0; public void onClick(DialogInterface dialoginterface, int i1) { getActivity().finish(); } { this$0 = SetupConnectFragment.this; super(); } }).setPositiveButton(k, new android.content.DialogInterface.OnClickListener() { final SetupConnectFragment this$0; public void onClick(DialogInterface dialoginterface, int i1) { dialoginterface = String.format(getString(0x7f06006e), new Object[] { mSelectedDevice.getAddress() }); Intent intent = new Intent("android.intent.action.SENDTO"); intent.setData(Uri.parse("mailto:")); intent.putExtra("android.intent.extra.EMAIL", new String[] { getString(0x7f06006d) }); intent.putExtra("android.intent.extra.SUBJECT", getString(0x7f06006f)); intent.putExtra("android.intent.extra.TEXT", dialoginterface); if (intent.resolveActivity(getActivity().getPackageManager()) != null) { startActivity(intent); } mSelectedDevice = null; } { this$0 = SetupConnectFragment.this; super(); } }).show(); return; } else { ALog.e("Can't show alert. Fragment is not attached.", new Object[0]); return; } } private void showConnectionFailureMessage(int i) { if (getActivity() != null && mCallbacks != null) { (new android.app.AlertDialog.Builder(getActivity())).setTitle(0x7f060098).setMessage(i).setCancelable(false).setPositiveButton(0x104000a, new android.content.DialogInterface.OnClickListener() { final SetupConnectFragment this$0; public void onClick(DialogInterface dialoginterface, int j) { if (mCallbacks != null) { mCallbacks.goToScreen(9); } } { this$0 = SetupConnectFragment.this; super(); } }).show(); return; } else { ALog.e("Can't show alert. Fragment is not attached. %d", new Object[] { Integer.valueOf(i) }); return; } } public int getPageNumber() { return 3; } public int getPairState() { return mPairState; } public int getTitleId() { return 0x7f060097; } public boolean isSkipConfirmationNeeded() { cancelDiscovery(); return true; } public boolean isSkipVisible() { return true; } public View onCreateView(LayoutInflater layoutinflater, ViewGroup viewgroup, Bundle bundle) { layoutinflater = layoutinflater.inflate(0x7f030045, viewgroup, false); ButterKnife.inject(this, layoutinflater); initializeView(layoutinflater); return layoutinflater; } public void onDestroy() { super.onDestroy(); try { getActivity().unregisterReceiver(mReceiver); return; } catch (IllegalArgumentException illegalargumentexception) { ALog.d("BroadcastReceiver was not previously registered", new Object[0]); } } public void onDetach() { if (mGetDataTask != null) { mGetDataTask.cancel(true); } super.onDetach(); } public void onPause() { super.onPause(); cancelDiscovery(); } public void onResume() { super.onResume(); if (mSelectedDevice == null) goto _L2; else goto _L1 _L1: mPairState; JVM INSTR tableswitch 2 3: default 36 // 2 79 // 3 57; goto _L3 _L4 _L5 _L3: if (BluetoothAdapter.getDefaultAdapter().isEnabled()) { if (mPairState == 0) { findDevices(); } return; } else { startActivity(new Intent("android.bluetooth.adapter.action.REQUEST_ENABLE")); registerReceiver("android.bluetooth.adapter.action.STATE_CHANGED"); return; } _L5: mSelectedDevice = null; mPairState = 0; mCallbacks.goToScreen(9); return; _L4: mPairState = 0; mCallbacks.goToScreen(8); return; _L2: mPairState = 0; goto _L3 } public void onScanAgain() { mListAdapter.clear(); findDevices(); } public void setActivityTitle(Activity activity) { activity.setTitle(0x7f060097); } /* static BluetoothDevice access$102(SetupConnectFragment setupconnectfragment, BluetoothDevice bluetoothdevice) { setupconnectfragment.mSelectedDevice = bluetoothdevice; return bluetoothdevice; } */ /* static int access$402(SetupConnectFragment setupconnectfragment, int i) { setupconnectfragment.mPairState = i; return i; } */ }