// 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.bluetooth; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.net.Uri; import android.os.Handler; import android.os.Looper; import com.olio.communication.actions.AndroidAction; import com.olio.communication.actions.MediaAction; import com.olio.communication.actions.WebAction; import com.olio.communication.bluetooth.BluetoothConnection; import com.olio.communication.bluetooth.BluetoothMessageListener; import com.olio.communication.bluetooth.BluetoothStatusHandler; import com.olio.communication.messages.Message; import com.olio.communication.messages.MessageBuilder; import com.olio.communication.messages.MessageConstants; import com.olio.communication.messages.files.ChunkRequest; import com.olio.communication.messages.files.TransferStatus; import com.olio.communication.messages.unit.WatchProfile; import com.olio.communication.notifications.Utilities; import com.olio.communication.notifications.new_notifications.StreamItemBuilder; import com.olio.data.object.analytics.AnalyticsPayload; import com.olio.data.object.transfer.FileTransfer; import com.olio.data.object.transfer.FileTransferObserver; import com.olio.data.object.unit.DeviceStatus; import com.olio.olios.model.SerializedUnitRecordMessagePayload; import com.olio.olios.model.SerializedUserRecordMessagePayload; import com.olio.phone_state.OlioTimeBuilder; import com.olio.phone_state.OlioTimeRequest; import com.olio.state.DoNotDisturb; import com.olio.state.RetailMode; import com.olio.util.ALog; import com.olio.util.RecoveryTimer; import com.olio.util.SharedUtils; import com.oliodevices.assist.app.api.OlioApi; import com.oliodevices.assist.app.api.UserManager; import com.oliodevices.assist.app.controller.WatchAnalytics; import com.oliodevices.assist.app.core.OlioApplication; import com.oliodevices.assist.app.detectors.BroadcastDelegate; import com.oliodevices.assist.app.detectors.firmware.FirmwareUpdateHelper; import com.oliodevices.assist.app.detectors.status_bar_detectors.NotificationHandlerService; import java.nio.ByteBuffer; import java.util.Calendar; import java.util.Date; import java.util.Objects; import java.util.TimeZone; public class BluetoothMessageManager implements BluetoothMessageListener { private class RetailModeUnpairingHandler implements com.oliodevices.assist.app.fragments.ConfigWatchFragment.ConfigWatchCallbacks { final BluetoothMessageManager this$0; public BluetoothDevice getDevice(String s) { return BluetoothAdapter.getDefaultAdapter().getRemoteDevice(s); } public void handleUnpairing() { } public void onAddTimeZone() { } public void onChangeName(String s) { } private RetailModeUnpairingHandler() { this$0 = BluetoothMessageManager.this; super(); } } public static final String ACTION_WATCH_VERSION_RECEIVED = "com.oliodevices.assist.intent.action.WATCH_VERSION"; public static final String EXTRA_WATCH_FIRMWARE_NAME = "watch_fw_name"; public static final String EXTRA_WATCH_FIRMWARE_VERSION = "watch_fw_version"; private static final int MESSAGE_VERSION = 2; private static final String TAG = "BluetoothMessageManager Tag"; private BluetoothConnection bluetoothConnection; BluetoothStatusHandler bluetoothStatusHandler; private BroadcastReceiver bluetoothStatusReceiver; private boolean connected; private Context context; byte currentBytes[]; private String deviceAddress; boolean isInitialized; private boolean loaderByPassFlag; private RecoveryTimer mTimer; private Handler mainLoopHandler; private BroadcastReceiver screenStateReceiver; boolean starting; public BluetoothMessageManager(BluetoothDevice bluetoothdevice, Context context1) { loaderByPassFlag = true; isInitialized = false; currentBytes = new byte[0]; connected = false; starting = false; if (bluetoothdevice != null) { deviceAddress = bluetoothdevice.getAddress(); } context = context1; bluetoothStatusHandler = new BluetoothStatusHandler(this, context1); } private void checkFirmwareCompatibility(WatchProfile watchprofile) { if (1 > SharedUtils.getBuildNumberFromVersionString(watchprofile.getFirmwareVersion())) { watchprofile = (new MessageBuilder()).setPayload((new StreamItemBuilder()).setNotificationId("com.olio.forceUpdate").setNotificationCategory(com.olio.communication.notifications.NotificationFilters.Category.LATER).setOverviewTopText(context.getString(0x7f0600b7)).setDetailTitle(context.getString(0x7f0600b6)).setDetailText(context.getString(0x7f0600b5)).build()).build(); (new BroadcastDelegate(context)).sendMessage(watchprofile); } } private ByteBuffer getMessageBufferWithExtraInfo(byte abyte0[]) { int i = abyte0.length; ByteBuffer bytebuffer = ByteBuffer.allocate(MessageConstants.MESSAGE_VERSION_SIZE.intValue() + MessageConstants.MESSAGE_LENGTH_INFO_SIZE.intValue() + i); bytebuffer.put((byte)2); bytebuffer.putInt(i); bytebuffer.put(abyte0); return bytebuffer; } private void messageReceived(byte abyte0[]) { ALog.v((new StringBuilder()).append("MESSAGERECEIVED: Received ").append(abyte0.length).append(" bytes").toString(), new Object[0]); currentBytes = Utilities.concatenateArrays(new byte[][] { currentBytes, abyte0 }); do { ALog.v("assume capacity is NOT sufficient", new Object[0]); byte byte0 = 0; abyte0 = ByteBuffer.wrap(currentBytes); byte byte1 = abyte0.get(); if (byte1 == 2) { int i = abyte0.getInt(); ALog.v("messageLength = %d .... currentBytesBuffer.length = %d", new Object[] { Integer.valueOf(i), Integer.valueOf(abyte0.capacity()) }); if (abyte0.capacity() - MessageConstants.MESSAGE_PREQUEL_SIZE.intValue() >= i) { byte1 = 1; ALog.v("buffer capacity sufficient", new Object[0]); byte abyte1[] = ByteBuffer.allocate(i).array(); abyte0.get(abyte1); Message message = (Message)Utilities.decode(abyte1); currentBytes = ByteBuffer.allocate(abyte0.capacity() - abyte0.position()).array(); abyte0.get(currentBytes); ALog.v("There's %d leftover bytes in the buffer", new Object[] { Integer.valueOf(currentBytes.length) }); byte0 = byte1; if (message != null) { message.setDestination("watch"); ALog.v("processing current message", new Object[0]); onMessageReceived(message); byte0 = byte1; } } } else { currentBytes = new byte[0]; ALog.e("Current message's version(%s) doesn't match the received version(%s)", new Object[] { Integer.valueOf(2), Integer.valueOf(byte1) }); } } while (currentBytes.length > MessageConstants.MESSAGE_PREQUEL_SIZE.intValue() && byte0 != 0); } private void onMessageReceived(Message message) { if (message != null) goto _L2; else goto _L1 _L1: ALog.v("decodedMessage is null", new Object[0]); _L13: return; _L2: if (com/olio/communication/actions/AndroidAction.isInstance(message.getPayload())) { message = (AndroidAction)message.getPayload(); ALog.v("Received AndroidAction %s", new Object[] { message.getBroadcastFilter() }); Intent intent = new Intent(NotificationHandlerService.NOTIFICATION_DETECTOR_INTENT_FILTER); intent.putExtra("notification_action", message); context.sendBroadcast(intent); return; } if (com/olio/communication/actions/WebAction.isInstance(message.getPayload())) { message = (WebAction)message.getPayload(); ALog.v("Received WebAction for url %s", new Object[] { message.getUrl() }); Intent intent1 = new Intent("com.oliodevices.WebActionListener"); intent1.putExtra("NOTIFICATION_EXTRA", message); context.sendBroadcast(intent1); intent1 = new Intent(NotificationHandlerService.NOTIFICATION_DETECTOR_INTENT_FILTER); intent1.putExtra("notification_action", message); context.sendBroadcast(intent1); return; } if (message.getPayload() instanceof ChunkRequest) { message = (ChunkRequest)message.getPayload(); ALog.v((new StringBuilder()).append("Received ChunkRequest for: ").append(message.getFileIdentifier()).toString(), new Object[0]); Intent intent2 = new Intent("com.olio.bluetooth_host.transfer_manager.intent_filter"); intent2.putExtra("CHUNK_REQUEST_EXTRA", message); context.sendBroadcast(intent2); return; } if (!(message.getPayload() instanceof TransferStatus)) goto _L4; else goto _L3 _L3: TransferStatus transferstatus; FileTransfer filetransfer; Object obj; ALog.v("Received TransferStatus", new Object[0]); transferstatus = (TransferStatus)message.getPayload(); OlioApi.getInstance().updateTransferStatusSetting(transferstatus); obj = FirmwareUpdateHelper.getInstance(); filetransfer = ((FirmwareUpdateHelper) (obj)).getFirmwareTransfer(); message = ""; static class _cls5 { static final int $SwitchMap$com$olio$communication$messages$files$TransferStatus$TransferStatusActivity[]; static { $SwitchMap$com$olio$communication$messages$files$TransferStatus$TransferStatusActivity = new int[com.olio.communication.messages.files.TransferStatus.TransferStatusActivity.values().length]; try { $SwitchMap$com$olio$communication$messages$files$TransferStatus$TransferStatusActivity[com.olio.communication.messages.files.TransferStatus.TransferStatusActivity.STARTED.ordinal()] = 1; } catch (NoSuchFieldError nosuchfielderror5) { } try { $SwitchMap$com$olio$communication$messages$files$TransferStatus$TransferStatusActivity[com.olio.communication.messages.files.TransferStatus.TransferStatusActivity.NOT_STARTED.ordinal()] = 2; } catch (NoSuchFieldError nosuchfielderror4) { } try { $SwitchMap$com$olio$communication$messages$files$TransferStatus$TransferStatusActivity[com.olio.communication.messages.files.TransferStatus.TransferStatusActivity.DOWNLOADING.ordinal()] = 3; } catch (NoSuchFieldError nosuchfielderror3) { } try { $SwitchMap$com$olio$communication$messages$files$TransferStatus$TransferStatusActivity[com.olio.communication.messages.files.TransferStatus.TransferStatusActivity.PAUSED.ordinal()] = 4; } catch (NoSuchFieldError nosuchfielderror2) { } try { $SwitchMap$com$olio$communication$messages$files$TransferStatus$TransferStatusActivity[com.olio.communication.messages.files.TransferStatus.TransferStatusActivity.DOWNLOADED.ordinal()] = 5; } catch (NoSuchFieldError nosuchfielderror1) { } try { $SwitchMap$com$olio$communication$messages$files$TransferStatus$TransferStatusActivity[com.olio.communication.messages.files.TransferStatus.TransferStatusActivity.APPLIED.ordinal()] = 6; } catch (NoSuchFieldError nosuchfielderror) { return; } } } _cls5..SwitchMap.com.olio.communication.messages.files.TransferStatus.TransferStatusActivity[transferstatus.getStatus().ordinal()]; JVM INSTR tableswitch 1 6: default 356 // 1 443 // 2 450 // 3 457 // 4 464 // 5 530 // 6 581; goto _L5 _L6 _L7 _L8 _L9 _L10 _L11 _L5: message = (new StringBuilder()).append(message).append(" - ").toString(); message = (new StringBuilder()).append(message).append(String.valueOf(transferstatus.getProgress())).toString(); ALog.v((new StringBuilder()).append(transferstatus.toString()).append(message).toString(), new Object[0]); OlioApplication.getApplication().reportWatchTracking(transferstatus.getVersion(), message, 0); return; _L6: message = "STARTED"; continue; /* Loop/switch isn't completed */ _L7: message = "NOT_STARTED"; continue; /* Loop/switch isn't completed */ _L8: message = "DOWNLOADING"; continue; /* Loop/switch isn't completed */ _L9: String s = "PAUSED"; message = s; if (filetransfer != null) { message = s; if (filetransfer.getStatus() == 1) { ((FirmwareUpdateHelper) (obj)).updateFirmwareTransfer(3, filetransfer.getBytesTransferred(), SharedUtils.getPauseReasonFromTransferStatus(transferstatus)); obj = filetransfer.getObserver(); message = s; if (obj != null) { ((FileTransferObserver) (obj)).downloadProgress(filetransfer); message = s; } } } continue; /* Loop/switch isn't completed */ _L10: String s1 = "DOWNLOADED"; message = s1; if (filetransfer != null) { ((FirmwareUpdateHelper) (obj)).updateFirmwareTransfer(4, filetransfer.getFileSize()); message = filetransfer.getObserver(); if (message != null) { message.transferComplete(filetransfer); } ((FirmwareUpdateHelper) (obj)).removeFirmwareTransfer(); message = s1; } continue; /* Loop/switch isn't completed */ _L11: message = "APPLIED"; if (true) goto _L5; else goto _L4 _L4: if (message.getPayload() instanceof WatchProfile) { ALog.d("Received WatchProfile", new Object[0]); message = (WatchProfile)message.getPayload(); message.save(context.getContentResolver()); OlioApi.getInstance().updateWatchProfileSetting(message); checkFirmwareCompatibility(message); context.sendStickyBroadcast((new Intent("com.oliodevices.assist.intent.action.WATCH_VERSION")).putExtra("watch_fw_version", message.getFirmwareVersion()).putExtra("watch_fw_name", message.getFirmwareName())); return; } if (!(message.getPayload() instanceof SerializedUnitRecordMessagePayload)) { break; /* Loop/switch isn't completed */ } message = (SerializedUnitRecordMessagePayload)message.getPayload(); ALog.v("Received SerializedUnitRecordMessagePayload: %s", new Object[] { message }); message.applyObjectSync(context.getContentResolver()); if (loaderByPassFlag && (message instanceof DeviceStatus)) { context.sendStickyBroadcast((new Intent("com.oliodevices.assist.intent.action.UPDATE_BATTERY")).putExtra("battery_level", ((DeviceStatus)message).getBatteryLevel()).putExtra("battery_charge_indicator", ((DeviceStatus)message).isCharging())); return; } if (true) goto _L13; else goto _L12 _L12: if (!(message.getPayload() instanceof SerializedUserRecordMessagePayload)) { break; /* Loop/switch isn't completed */ } message = (SerializedUserRecordMessagePayload)message.getPayload(); ALog.d("Received SerializedUserRecordMessagePayload: %s", new Object[] { message }); message.applyObjectSync(context.getContentResolver()); if (loaderByPassFlag && (message instanceof DoNotDisturb)) { context.sendStickyBroadcast((new Intent("com.oliodevices.assist.intent.action.UPDATE_DND")).putExtra("dnd_state", ((DoNotDisturb)message).isEnabled())); return; } if (true) goto _L13; else goto _L14 _L14: if (message.getPayload() instanceof OlioTimeRequest) { ALog.d((new StringBuilder()).append("OlioTime request received at ").append((new Date(System.currentTimeMillis())).toString()).toString(), new Object[0]); message = (OlioTimeRequest)message.getPayload(); ALog.d((new StringBuilder()).append("OlioTime request time = ").append((new Date(message.getRequestTimeSent().longValue())).toString()).toString(), new Object[0]); ALog.d((new StringBuilder()).append("OlioTime setting time to ").append((new Date()).toString()).toString(), new Object[0]); message = (new MessageBuilder()).setAction(com.olio.communication.messages.Message.Action.CREATE_OR_UPDATE).setPayload((new OlioTimeBuilder()).setTime(new Date()).setTimeZone(Calendar.getInstance().getTimeZone().getID()).setTimeRequested(message.getRequestTimeSent()).build()).build(); (new BroadcastDelegate(context)).sendMessage(message); return; } if (message.getPayload() instanceof MediaAction) { message = (MediaAction)message.getPayload(); ALog.d((new StringBuilder()).append("Received MediaAction: ").append(message).toString(), new Object[0]); Intent intent3 = new Intent(NotificationHandlerService.MEDIA_ACTION_INTENT_FILTER); intent3.putExtra("notification_action", message); context.sendBroadcast(intent3); return; } if (message.getPayload() instanceof AnalyticsPayload) { message = (AnalyticsPayload)message.getPayload(); ALog.v("Received AnalyticsPayload", new Object[0]); WatchAnalytics.getInstance().initialize(context).handleAnalytics(message); return; } if (!(message.getPayload() instanceof RetailMode) && message.getPayload() != null) { ALog.d((new StringBuilder()).append("Received a message of type: ").append(message.getPayload().getClass().getSimpleName()).toString(), new Object[0]); return; } if (true) goto _L13; else goto _L15 _L15: } private void startConnectionIfNotStarted() { BluetoothAdapter bluetoothadapter = BluetoothAdapter.getDefaultAdapter(); if (bluetoothConnection != null && bluetoothConnection.getState() == 0 && bluetoothadapter.isEnabled()) { bluetoothConnection.start(); } } private void startListening() { this; JVM INSTR monitorenter ; if (!starting) goto _L2; else goto _L1 _L1: ALog.d("startListing failed - already starting", new Object[0]); _L4: this; JVM INSTR monitorexit ; return; _L2: ALog.d("startListing succeeded", new Object[0]); starting = true; stopWatchDog(); mainLoopHandler.postDelayed(new Runnable() { final BluetoothMessageManager this$0; public void run() { ALog.d("startListing postDelayed. Starting", new Object[0]); startConnectionIfNotStarted(); startWatchDog(); starting = false; } { this$0 = BluetoothMessageManager.this; super(); } }, 2000L); if (true) goto _L4; else goto _L3 _L3: Exception exception; exception; throw exception; } public void connectionChanged(int i) { if (i == 0) { startListening(); if (connected) { connected = false; OlioApplication.getApplication().reportWatchTracking("Disconnected", UserManager.getInstance().getEmailForAnalytics(), 0); } currentBytes = new byte[0]; } else if (i == 3 && !connected) { connected = true; OlioApplication.getApplication().reportWatchTracking("Connected", UserManager.getInstance().getEmailForAnalytics(), 0); return; } } public void destroy() { if (screenStateReceiver != null) { context.unregisterReceiver(screenStateReceiver); screenStateReceiver = null; } if (mTimer != null) { mTimer.dispose(); mTimer = null; } if (bluetoothStatusReceiver != null) { context.unregisterReceiver(bluetoothStatusReceiver); bluetoothStatusReceiver = null; } if (bluetoothConnection != null) { bluetoothConnection.stop(); bluetoothConnection = null; } isInitialized = false; } public void initialize() { if (isInitialized) { ALog.e("Initializing BluetoothMessageManager twice. Bad.", new Object[0]); return; } isInitialized = true; mainLoopHandler = new Handler(Looper.getMainLooper()); if (mTimer == null) { mTimer = new RecoveryTimer("BluetoothMessageManager"); mTimer.init(context, mainLoopHandler); } bluetoothConnection = new BluetoothConnection(context, bluetoothStatusHandler); bluetoothConnection.start(); startWatchDog(); screenStateReceiver = new BroadcastReceiver() { final BluetoothMessageManager this$0; public void onReceive(Context context1, Intent intent) { if ("android.intent.action.SCREEN_ON".equals(intent.getAction())) { ALog.d("Screen turned on, starting connection", new Object[0]); startConnectionIfNotStarted(); } } { this$0 = BluetoothMessageManager.this; super(); } }; IntentFilter intentfilter = new IntentFilter(); intentfilter.addAction("android.intent.action.SCREEN_ON"); context.registerReceiver(screenStateReceiver, intentfilter); bluetoothStatusReceiver = new BroadcastReceiver() { final BluetoothMessageManager this$0; public void onReceive(Context context1, Intent intent) { if (!"android.bluetooth.adapter.action.STATE_CHANGED".equals(intent.getAction())) goto _L2; else goto _L1 _L1: intent.getIntExtra("android.bluetooth.adapter.extra.STATE", 0x80000000); JVM INSTR tableswitch 12 12: default 40 // 12 41; goto _L2 _L3 _L2: return; _L3: startListening(); return; } { this$0 = BluetoothMessageManager.this; super(); } }; intentfilter = new IntentFilter("android.bluetooth.adapter.action.STATE_CHANGED"); context.registerReceiver(bluetoothStatusReceiver, intentfilter); } public void messageReceived(Message message) { } public void readBytes(byte abyte0[]) { messageReceived(abyte0); } public void resetBluetooth(String s) { if (Objects.equals(deviceAddress, s)) { return; } else { deviceAddress = s; bluetoothConnection.stop(); bluetoothConnection.start(); startWatchDog(); return; } } public void sendFile(Uri uri) { ALog.d("Sending file uri: %s", new Object[] { uri.toString() }); Intent intent = new Intent("android.intent.action.SEND"); intent.setType("application/zip"); intent.setComponent(new ComponentName("com.android.bluetooth", "com.android.bluetooth.opp.BluetoothOppLauncherActivity")); context.grantUriPermission("com.android.bluetooth", uri, 3); intent.putExtra("android.intent.extra.STREAM", uri); intent.addFlags(0x10000000); context.startActivity(intent); } public void sendMessage(Message message) { message = getMessageBufferWithExtraInfo(Utilities.encodeWithSerialization(message)); bluetoothConnection.write(message.array()); } public void startWatchDog() { if (mTimer != null) { mTimer.startOrRestart(1000L, 0x186a0L, new Runnable() { final BluetoothMessageManager this$0; public void run() { startConnectionIfNotStarted(); } { this$0 = BluetoothMessageManager.this; super(); } }); } } public void stopWatchDog() { if (mTimer != null) { mTimer.cancel(); } } public void wroteBytes(byte abyte0[]) { ALog.v((new StringBuilder()).append("Wrote bytes: ").append(new String(abyte0)).toString(), new Object[0]); } }