Skip to content

Commit

Permalink
feat(filog): handle exception error to the bluetooth
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Del Pino <idelpino@teclib.com>
  • Loading branch information
Ivan Del Pino authored and rafaelje committed Oct 1, 2018
1 parent 7446242 commit c13f173
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ public class CommonErrorType {
public static final int BIOS_SYSTEM_SERIAL = 208;
public static final int BIOS_SERIAL_PRIVATE = 209;
public static final int BIOS_CPU_SERIAL = 210;
}

/* Bluetooth */
public static final int BLUETOOTH_HARDWARE_ADDRESS = 201;
public static final int BLUETOOTH_NAME = 202;
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import android.bluetooth.BluetoothAdapter;
import android.content.Context;

import org.flyve.inventory.CommonErrorType;
import org.flyve.inventory.FILog;

/**
Expand All @@ -50,8 +51,9 @@ public class Bluetooth extends Categories {
*/
private static final long serialVersionUID = 3252750764653173048L;
private BluetoothAdapter adapter;
private final Context context;

/**
/**
* Indicates whether some other object is "equal to" this one
* @param Object obj the reference object with which to compare
* @return boolean true if the object is the same as the one given in argument
Expand Down Expand Up @@ -84,6 +86,8 @@ public int hashCode() {
public Bluetooth(Context xCtx) {
super(xCtx);

context = xCtx;

adapter = BluetoothAdapter.getDefaultAdapter();

if(adapter != null) {
Expand All @@ -107,15 +111,27 @@ public Bluetooth(Context xCtx) {
* @return string with the hardware address
*/
public String getHardwareAddress() {
return adapter.getAddress();
String address = "N/A";
try {
address = adapter.getAddress();
} catch (Exception ex) {
FILog.e(FILog.getMessage(context, CommonErrorType.BLUETOOTH_HARDWARE_ADDRESS, ex.getMessage()));
}
return address;
}

/**
* Get the adapter name
* @return string the name of the adapter
*/
public String getName() {
return adapter.getName();
String name = "N/A";
try {
name = adapter.getName();
} catch (Exception ex) {
FILog.e(FILog.getMessage(context, CommonErrorType.BLUETOOTH_NAME, ex.getMessage()));
}
return name;
}

}

0 comments on commit c13f173

Please sign in to comment.