diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser index d1f0797..d4d5345 100644 Binary files a/.idea/caches/build_file_checksums.ser and b/.idea/caches/build_file_checksums.ser differ diff --git a/app/build.gradle b/app/build.gradle index 759f972..dd1ec2b 100755 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,11 +1,11 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 28 + compileSdkVersion 29 defaultConfig { applicationId "inc.osips.bleproject" minSdkVersion 21 - targetSdkVersion 28 + targetSdkVersion 29 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" diff --git a/app/src/main/java/inc/osips/bleproject/presenter/RemoteControllerPresenter.java b/app/src/main/java/inc/osips/bleproject/presenter/RemoteControllerPresenter.java index 851f008..fdb059d 100644 --- a/app/src/main/java/inc/osips/bleproject/presenter/RemoteControllerPresenter.java +++ b/app/src/main/java/inc/osips/bleproject/presenter/RemoteControllerPresenter.java @@ -49,30 +49,29 @@ public RemoteControllerPresenter(final ControllerViewInterface viewInterface, St DeviceConnectionFactory factory = DeviceConnectionFactory.withContext(viewInterface.getControlContext()); try { - builder = factory.establishConnectionWithDeviceOf(type, device); - } catch (IoTCommException e) { - Log.e(TAG, "RemoteControllerPresenter: ",e ); - e.printStackTrace(); - } - - if (device instanceof BluetoothDevice && type.equalsIgnoreCase(Constants.BLE)){ - Log.i("Connection type", builder.getDeviceType()); - this.deviceName = ((BluetoothDevice) device).getName(); - //viewInterface.getUUIDFromPopUp(); - intent = new Intent(activity, BleGattService.class); - deviceConnector = builder.build(); - if (!ServiceUtil.isAnyRemoteConnectionServiceRunningAPI16(viewInterface.getControlContext())) - bindBleService(); - }else if (device instanceof WifiP2pDevice && type.equalsIgnoreCase(Constants.P2P)) { - Log.i("Connection", builder.getDeviceType()); - if (builder !=null){ + builder = factory.getDeviceConnectionBuilder(type, device); + if (device instanceof BluetoothDevice && type.equalsIgnoreCase(Constants.BLE)){ + Log.i("Connection type", builder.getDeviceType()); + this.deviceName = ((BluetoothDevice) device).getName(); + //viewInterface.getUUIDFromPopUp(); + intent = new Intent(activity, BleGattService.class); deviceConnector = builder.build(); - - intent = new Intent(activity, P2pDataTransferService.class); - if(!ServiceUtil.isAnyRemoteConnectionServiceRunningAPI16(viewInterface.getControlContext())) + if (!ServiceUtil.isAnyRemoteConnectionServiceRunningAPI16(viewInterface.getControlContext())) bindBleService(); + }else if (device instanceof WifiP2pDevice && type.equalsIgnoreCase(Constants.P2P)) { + Log.i("Connection", builder.getDeviceType()); + if (builder !=null){ + deviceConnector = builder.build(); + + intent = new Intent(activity, P2pDataTransferService.class); + if(!ServiceUtil.isAnyRemoteConnectionServiceRunningAPI16(viewInterface.getControlContext())) + bindBleService(); + } + this.deviceName = ((WifiP2pDevice) device).deviceName; } - this.deviceName = ((WifiP2pDevice) device).deviceName; + } catch (IoTCommException e) { + Log.e(TAG, "RemoteControllerPresenter: ",e ); + e.printStackTrace(); } } diff --git a/iot_wireless_communication/src/main/java/inc/osips/iot_wireless_communication/wireless_comms_module/remote_comms/DeviceConnectionFactory.java b/iot_wireless_communication/src/main/java/inc/osips/iot_wireless_communication/wireless_comms_module/remote_comms/DeviceConnectionFactory.java index 1ad8d0a..3972bbd 100644 --- a/iot_wireless_communication/src/main/java/inc/osips/iot_wireless_communication/wireless_comms_module/remote_comms/DeviceConnectionFactory.java +++ b/iot_wireless_communication/src/main/java/inc/osips/iot_wireless_communication/wireless_comms_module/remote_comms/DeviceConnectionFactory.java @@ -1,7 +1,9 @@ package inc.osips.iot_wireless_communication.wireless_comms_module.remote_comms; import android.app.Activity; +import android.bluetooth.BluetoothDevice; import android.content.Context; +import android.net.wifi.p2p.WifiP2pDevice; import android.os.Parcelable; import android.text.TextUtils; @@ -30,7 +32,7 @@ public synchronized static DeviceConnectionFactory withContext(@NonNull Context } return factory_instance; } - public Builder establishConnectionWithDeviceOf(@NonNull String connectionType, @NonNull Parcelable device) throws IoTCommException { + public Builder getDeviceConnectionBuilder(@NonNull String connectionType, @NonNull Parcelable device) throws IoTCommException { if(TextUtils.isEmpty(connectionType))return null; @@ -57,7 +59,13 @@ private Builder(Context activity, Parcelable device) { abstract public WirelessDeviceConnector build(); abstract public DeviceConnectionFactory.Builder setDeviceUniqueID(String UUID_IP); - abstract public String getDeviceType(); + public String getDeviceType() throws IoTCommException{ + if(device instanceof BluetoothDevice){ + return Constants.BLE; + }else if (device instanceof WifiP2pDevice) return Constants.P2P; + + else throw new IoTCommException("This Parcelable object is not recognised", "Error!"); + } abstract public Builder setConnectionTimeOut(int timeOut); abstract public Builder setMaxTransmissionUnit(int size); } @@ -83,12 +91,6 @@ public Builder setDeviceUniqueID(@Nullable String ip) { return this; } - @Override - public String getDeviceType() { - return Constants.P2P; - } - - @Override public Builder setConnectionTimeOut(int timeOut) { this.timeOut = timeOut; @@ -120,12 +122,6 @@ public Builder setDeviceUniqueID(@Nullable String UUID) { return this; } - @Override - public String getDeviceType() { - return Constants.BLE; - } - - @Override public Builder setConnectionTimeOut(int timeOut) { return this; diff --git a/iot_wireless_communication/src/main/java/inc/osips/iot_wireless_communication/wireless_comms_module/remote_comms/p2p_comms/P2pConnection.java b/iot_wireless_communication/src/main/java/inc/osips/iot_wireless_communication/wireless_comms_module/remote_comms/p2p_comms/P2pConnection.java index 0fe1346..1f21c10 100644 --- a/iot_wireless_communication/src/main/java/inc/osips/iot_wireless_communication/wireless_comms_module/remote_comms/p2p_comms/P2pConnection.java +++ b/iot_wireless_communication/src/main/java/inc/osips/iot_wireless_communication/wireless_comms_module/remote_comms/p2p_comms/P2pConnection.java @@ -34,7 +34,6 @@ public class P2pConnection implements WirelessDeviceConnector { public P2pConnection(@NonNull Context context, @NonNull final Parcelable p2pDevice, int time_out) { this.p2pDevice = (WifiP2pDevice) p2pDevice; this.context = context; - if (time_out>1000) this.TIME_OUT = time_out; initializeServerSocket();