// 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.olio.communication.bluetooth; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothServerSocket; import android.bluetooth.BluetoothSocket; import android.content.Context; import android.os.Bundle; import android.os.Handler; import android.os.Message; import com.olio.data.object.analytics.DumpsysBatteryStatsHelper; import com.olio.util.ALog; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.Arrays; import java.util.UUID; public class BluetoothConnection { private class AcceptThread extends Thread { private String mSocketType; private final BluetoothServerSocket mmServerSocket; final BluetoothConnection this$0; public void cancel() { ALog.d((new StringBuilder()).append("Socket Type").append(mSocketType).append("cancel ").append(this).toString(), new Object[0]); if (mmServerSocket != null) { mmServerSocket.close(); return; } try { ALog.e("Null pointer in BluetoothConnection AcceptThread thread. Probably disconnection.", new Object[0]); return; } catch (IOException ioexception) { ALog.e((new StringBuilder()).append("Socket Type").append(mSocketType).append("close() of server failed").toString(), ioexception, new Object[0]); } return; } public void run() { ALog.d((new StringBuilder()).append("Socket Type: ").append(mSocketType).append("BEGIN mAcceptThread").append(this).toString(), new Object[0]); setName((new StringBuilder()).append("AcceptThread").append(mSocketType).toString()); if (mmServerSocket == null) { ALog.w("Server socket could not be created.", new Object[0]); connectionFailed(); return; } _L4: if (mState == 3) goto _L2; else goto _L1 _L1: Object obj1 = mmServerSocket.accept(); if (obj1 == null) goto _L4; else goto _L3 _L3: BluetoothConnection bluetoothconnection = BluetoothConnection.this; bluetoothconnection; JVM INSTR monitorenter ; mState; JVM INSTR tableswitch 0 4: default 340 // 0 305 // 1 286 // 2 160 // 3 305 // 4 286; goto _L5 _L6 _L7 _L5 _L6 _L7 obj1; goto _L8 _L5: if (true) goto _L4; else goto _L9 _L9: _L8: bluetoothconnection; JVM INSTR monitorexit ; throw obj1; Object obj; obj; ALog.e((new StringBuilder()).append("Socket Type: ").append(mSocketType).append("accept() failed").toString(), ((Throwable) (obj)), new Object[0]); if (mState != 3 && mState != 1) { connectionFailed(); } _L2: ALog.i((new StringBuilder()).append("END mAcceptThread, socket Type: ").append(mSocketType).toString(), new Object[0]); return; obj; ALog.e("Null pointer in BluetoothConnection Accept Thread. Probably disconnection.", ((Throwable) (obj)), new Object[0]); connectionFailed(); goto _L2 _L7: connected(((BluetoothSocket) (obj1)), ((BluetoothSocket) (obj1)).getRemoteDevice(), mSocketType); goto _L4 _L6: ((BluetoothSocket) (obj1)).close(); goto _L4 Object obj2; obj2; ALog.e("Could not close unwanted socket", ((Throwable) (obj2)), new Object[0]); goto _L4 obj2; ALog.e("Null pointer in BluetoothConnection AcceptThread thread. Probably disconnection.", ((Throwable) (obj2)), new Object[0]); goto _L4 } public AcceptThread(boolean flag) { this$0 = BluetoothConnection.this; super(); Object obj = null; String s; if (flag) { s = "Secure"; } else { s = "Insecure"; } mSocketType = s; try { bluetoothconnection = mAdapter.listenUsingRfcommWithServiceRecord("BluetoothChatSecure", BluetoothConnection.MY_UUID_SECURE); } // Misplaced declaration of an exception variable catch (BluetoothConnection bluetoothconnection) { ALog.e((new StringBuilder()).append("Socket Type: ").append(mSocketType).append("listen() failed").toString(), BluetoothConnection.this, new Object[0]); bluetoothconnection = obj; } // Misplaced declaration of an exception variable catch (BluetoothConnection bluetoothconnection) { ALog.e("Null pointer in BluetoothConnection AcceptThread thread. Probably disconnection.", BluetoothConnection.this, new Object[0]); bluetoothconnection = obj; } mmServerSocket = BluetoothConnection.this; } } private class ConnectThread extends Thread { private String mSocketType; private final BluetoothDevice mmDevice; private final BluetoothSocket mmSocket; final BluetoothConnection this$0; public void cancel() { try { mmSocket.close(); return; } catch (IOException ioexception) { ALog.e((new StringBuilder()).append("close() of connect ").append(mSocketType).append(" socket failed").toString(), ioexception, new Object[0]); return; } catch (NullPointerException nullpointerexception) { ALog.e("Null pointer in BluetoothConnection Connect thread. Probably disconnection.", nullpointerexception, new Object[0]); } } public void run() { ALog.i((new StringBuilder()).append("BEGIN mConnectThread SocketType:").append(mSocketType).toString(), new Object[0]); setName((new StringBuilder()).append("ConnectThread").append(mSocketType).toString()); if (mmSocket != null) goto _L2; else goto _L1 _L1: connectionFailed(); _L4: return; _L2: mAdapter.cancelDiscovery(); if (mmSocket.isConnected()) goto _L4; else goto _L3 _L3: DumpsysBatteryStatsHelper.getInstance().log("bt_update=bt3_disconnected +bt3_socket_connect", new Object[0]); mmSocket.connect(); DumpsysBatteryStatsHelper.getInstance().log("-bt3_socket_connect", new Object[0]); synchronized (BluetoothConnection.this) { mConnectThread = null; } connected(mmSocket, mmDevice, mSocketType); return; obj; mmSocket.close(); _L5: connectionFailed(); DumpsysBatteryStatsHelper.getInstance().log("-bt3_socket_connect", new Object[0]); return; obj; ALog.e((new StringBuilder()).append("unable to close() ").append(mSocketType).append(" socket during connection failure").toString(), ((Throwable) (obj)), new Object[0]); goto _L5 obj; DumpsysBatteryStatsHelper.getInstance().log("-bt3_socket_connect", new Object[0]); throw obj; obj; ALog.e("Null pointer in BluetoothConnection Connectthread. Probably disconnection.", ((Throwable) (obj)), new Object[0]); connectionFailed(); DumpsysBatteryStatsHelper.getInstance().log("-bt3_socket_connect", new Object[0]); return; exception; obj; JVM INSTR monitorexit ; throw exception; } public ConnectThread(BluetoothDevice bluetoothdevice) { this$0 = BluetoothConnection.this; super(); mmDevice = bluetoothdevice; bluetoothconnection = null; mSocketType = "Secure"; bluetoothdevice = bluetoothdevice.createRfcommSocketToServiceRecord(BluetoothConnection.MY_UUID_SECURE); bluetoothconnection = bluetoothdevice; _L2: mmSocket = BluetoothConnection.this; return; bluetoothdevice; ALog.e((new StringBuilder()).append("Socket Type: ").append(mSocketType).append("create() failed").toString(), bluetoothdevice, new Object[0]); continue; /* Loop/switch isn't completed */ bluetoothdevice; ALog.e("Null pointer in BluetoothConnection ConnectThread thread. Probably disconnection.", bluetoothdevice, new Object[0]); if (true) goto _L2; else goto _L1 _L1: } } private class ConnectedThread extends Thread { private final InputStream mmInStream; private final OutputStream mmOutStream; private final BluetoothSocket mmSocket; final BluetoothConnection this$0; public void cancel() { try { mmSocket.close(); return; } catch (IOException ioexception) { ALog.e("close() of connect socket failed", ioexception, new Object[0]); return; } catch (NullPointerException nullpointerexception) { ALog.e("Null pointer in BluetoothConnection Connected thread. Probably disconnection.", nullpointerexception, new Object[0]); } } public void run() { ALog.i("BEGIN mConnectedThread", new Object[0]); byte abyte0[] = new byte[2048]; if (mmInStream == null || mmOutStream == null) { connectionFailed(); return; } try { do { int i = mmInStream.read(abyte0); byte abyte1[] = Arrays.copyOf(abyte0, i); ALog.v((new StringBuilder()).append("Read ").append(i).append(" bytes from device: ").append(mmSocket.getRemoteDevice().getName()).append(" at address: ").append(mmSocket.getRemoteDevice().getAddress()).toString(), new Object[0]); mHandler.obtainMessage(2, i, -1, abyte1).sendToTarget(); } while (true); } catch (IOException ioexception) { ALog.e("disconnected", ioexception, new Object[0]); connectionFailed(); return; } catch (NullPointerException nullpointerexception) { ALog.e("Null pointer in BluetoothConnection Connected thread. Probably disconnection.", nullpointerexception, new Object[0]); } connectionFailed(); } public boolean write(byte abyte0[]) { try { mmOutStream.write(abyte0); ALog.v((new StringBuilder()).append("Wrote: ").append(abyte0.length).append(" bytes to device: ").append(mmSocket.getRemoteDevice().getName()).append("at address: ").append(mmSocket.getRemoteDevice().getAddress()).toString(), new Object[0]); } // Misplaced declaration of an exception variable catch (byte abyte0[]) { ALog.e("Exception during write", abyte0, new Object[0]); return false; } // Misplaced declaration of an exception variable catch (byte abyte0[]) { ALog.e("Null pointer in BluetoothConnection Connected thread. Probably disconnection.", abyte0, new Object[0]); return false; } return true; } public ConnectedThread(BluetoothSocket bluetoothsocket, String s) { BluetoothConnection bluetoothconnection1; Object obj; this$0 = BluetoothConnection.this; super(); ALog.d((new StringBuilder()).append("create ConnectedThread: ").append(s).toString(), new Object[0]); mmSocket = bluetoothsocket; bluetoothconnection1 = null; s = null; obj = null; bluetoothconnection = bluetoothsocket.getInputStream(); s = BluetoothConnection.this; bluetoothconnection1 = BluetoothConnection.this; try { bluetoothsocket = bluetoothsocket.getOutputStream(); } // Misplaced declaration of an exception variable catch (BluetoothConnection bluetoothconnection) { ALog.e("temp sockets not created", BluetoothConnection.this, new Object[0]); bluetoothconnection = s; bluetoothsocket = obj; } // Misplaced declaration of an exception variable catch (BluetoothConnection bluetoothconnection) { ALog.e("Null pointer in BluetoothConnection Connected thread. Probably disconnection.", BluetoothConnection.this, new Object[0]); bluetoothconnection = bluetoothconnection1; bluetoothsocket = obj; } mmInStream = BluetoothConnection.this; mmOutStream = bluetoothsocket; return; } } private static final boolean D = true; public static final String DEVICE = "device"; public static final String DEVICE_ADDRESS = "device_address"; public static final String DEVICE_NAME = "device_name"; public static final int MESSAGE_READ = 2; public static final int MESSAGE_STATE_CHANGE = 1; public static final int MESSAGE_WRITE = 3; private static final UUID MY_UUID_SECURE = UUID.fromString("11e63bf3-6baa-47d9-b31d-6045138c9add"); private static final String NAME_SECURE = "BluetoothChatSecure"; public static final int STATE_CONNECTED = 3; public static final int STATE_CONNECTING = 1; public static final int STATE_LISTEN = 4; public static final int STATE_NONE = 0; private static final String TAG = "BluetoothConnection"; public static final String TOAST = "toast"; private static boolean exists = false; private final BluetoothAdapter mAdapter = BluetoothAdapter.getDefaultAdapter(); private String mAddress; private ConnectThread mConnectThread; private ConnectedThread mConnectedThread; private final Handler mHandler; private AcceptThread mSecureAcceptThread; private int mState; public BluetoothConnection(Context context, Handler handler) { if (exists) { ALog.e("BluetoothConnection already exists and state is %d", new Object[] { Integer.valueOf(mState) }); } exists = true; mState = 0; mHandler = handler; } private void connectionFailed() { ALog.d("connectionFailed Called", new Object[0]); stop(); } private void setState(int i) { this; JVM INSTR monitorenter ; Message message; ALog.d((new StringBuilder()).append("setState() ").append(mState).append(" -> ").append(i).toString(), new Object[0]); mState = i; message = mHandler.obtainMessage(1, i, -1); if (i != 3) { break MISSING_BLOCK_LABEL_103; } BluetoothDevice bluetoothdevice = getConnectedDevice(); Bundle bundle = new Bundle(); bundle.putString("device_name", bluetoothdevice.getName()); bundle.putString("device_address", bluetoothdevice.getAddress()); message.setData(bundle); message.sendToTarget(); this; JVM INSTR monitorexit ; return; Exception exception; exception; throw exception; } public void connect(BluetoothDevice bluetoothdevice) { this; JVM INSTR monitorenter ; int i; ALog.d((new StringBuilder()).append("connect to: ").append(bluetoothdevice).toString(), new Object[0]); if (mState == 1 && mConnectThread != null) { mConnectThread.cancel(); mConnectThread = null; } i = mState; if (i != 3) goto _L2; else goto _L1 _L1: this; JVM INSTR monitorexit ; return; _L2: mAddress = bluetoothdevice.getAddress(); if (mConnectedThread != null) { mConnectedThread.cancel(); mConnectedThread = null; } mConnectThread = new ConnectThread(bluetoothdevice); mConnectThread.start(); setState(1); if (true) goto _L1; else goto _L3 _L3: bluetoothdevice; throw bluetoothdevice; } public void connected(BluetoothSocket bluetoothsocket, BluetoothDevice bluetoothdevice, String s) { this; JVM INSTR monitorenter ; ALog.d((new StringBuilder()).append("connected, Socket Type:").append(s).toString(), new Object[0]); if (mConnectThread != null) { mConnectThread.cancel(); mConnectThread = null; } if (mConnectedThread != null) { mConnectedThread.cancel(); mConnectedThread = null; } if (mSecureAcceptThread != null) { mSecureAcceptThread.cancel(); mSecureAcceptThread = null; } mConnectedThread = new ConnectedThread(bluetoothsocket, s); mConnectedThread.start(); setState(3); this; JVM INSTR monitorexit ; return; bluetoothsocket; throw bluetoothsocket; } public BluetoothDevice getConnectedDevice() { if (mConnectedThread != null) { BluetoothSocket bluetoothsocket = mConnectedThread.mmSocket; if (bluetoothsocket != null) { return bluetoothsocket.getRemoteDevice(); } } return null; } public int getState() { this; JVM INSTR monitorenter ; int i = mState; this; JVM INSTR monitorexit ; return i; Exception exception; exception; throw exception; } public void start() { this; JVM INSTR monitorenter ; ALog.d("start", new Object[0]); if (mConnectThread != null) { mConnectThread.cancel(); mConnectThread = null; } if (mConnectedThread != null) { mConnectedThread.cancel(); mConnectedThread = null; } setState(4); if (mSecureAcceptThread == null) { mSecureAcceptThread = new AcceptThread(true); mSecureAcceptThread.start(); } this; JVM INSTR monitorexit ; return; Exception exception; exception; throw exception; } public void stop() { this; JVM INSTR monitorenter ; ALog.d("BluetoothConnection: stop", new Object[0]); if (mConnectThread != null) { mConnectThread.cancel(); mConnectThread = null; } if (mConnectedThread != null) { mConnectedThread.cancel(); mConnectedThread = null; } if (mSecureAcceptThread != null) { mSecureAcceptThread.cancel(); mSecureAcceptThread = null; } setState(0); this; JVM INSTR monitorexit ; return; Exception exception; exception; throw exception; } public boolean write(byte abyte0[]) { this; JVM INSTR monitorenter ; if (mState == 3) { break MISSING_BLOCK_LABEL_14; } this; JVM INSTR monitorexit ; return false; ConnectedThread connectedthread = mConnectedThread; this; JVM INSTR monitorexit ; return connectedthread.write(abyte0); abyte0; this; JVM INSTR monitorexit ; throw abyte0; } /* static ConnectThread access$502(BluetoothConnection bluetoothconnection, ConnectThread connectthread) { bluetoothconnection.mConnectThread = connectthread; return connectthread; } */ }