public class BluetoothMedic extends Object
BluetoothMedic medic = BluetoothMedic.getInstance();
medic.enablePowerCycleOnFailures(context);
medic.enablePeriodicTests(context, BluetoothMedic.SCAN_TEST | BluetoothMedic.TRANSMIT_TEST);
To set up in a manual way:
BluetoothMedic medic = BluetoothMedic.getInstance();
medic.enablePowerCycleOnFailures(context);
if (!medic.runScanTest(context)) {
// Bluetooth stack is in a bad state
}
if (!medic.runTransmitterTest(context)) {
// Bluetooth stack is in a bad state
}| Modifier and Type | Field and Description |
|---|---|
static int |
NO_TEST
Indicates that no test should be run by the BluetoothTestJob
|
static int |
SCAN_TEST
Indicates that the bluetooth scan test should be run by the BluetoothTestJob
|
static int |
TRANSMIT_TEST
Indicates that the transmitter test should be run by the BluetoothTestJob
|
| Modifier and Type | Method and Description |
|---|---|
void |
enablePeriodicTests(Context context,
int testType)
Calling this method starts a scheduled job that will run tests of the specified type to
make sure bluetooth is OK and cycle power to bluetooth if needed and configured by
enablePowerCycleOnFailures
|
void |
enablePowerCycleOnFailures(Context context)
If set to true, bluetooth will be power cycled on any tests run that determine bluetooth is
in a bad state.
|
static BluetoothMedic |
getInstance()
Get a singleton instance of the BluetoothMedic
|
boolean |
runScanTest(Context context)
Starts up a brief blueooth scan with the intent of seeing if it results in an error condition
indicating the bluetooth stack may be in a bad state.
|
boolean |
runTransmitterTest(Context context)
Starts up a beacon transmitter with the intent of seeing if it results in an error condition
indicating the bluetooth stack may be in a bad state.
|
void |
setNotificationsEnabled(boolean enabled,
int icon)
Configure whether to send user-visible notification warnings when bluetooth power is cycled.
|
public static final int NO_TEST
public static final int TRANSMIT_TEST
public static final int SCAN_TEST
public static BluetoothMedic getInstance()
@RequiresApi(value=21) public void enablePowerCycleOnFailures(Context context)
context - @RequiresApi(value=21) public void enablePeriodicTests(Context context, int testType)
context - testType - e.g. BluetoothMedic.TRANSMIT_TEST | BluetoothMedic.SCAN_TEST@RequiresApi(value=21) public boolean runScanTest(Context context)
@RequiresApi(value=21) public boolean runTransmitterTest(Context context)
@RequiresApi(value=21)
public void setNotificationsEnabled(boolean enabled,
int icon)
enabled - if true, a user-visible notification is sent to tell the user whenicon - the icon drawable to use in notifications (e.g. R.drawable.notification_icon)