Skip to content

Commit

Permalink
fix(network): get rid of obsolete bleState (no 'incompatible' state a…
Browse files Browse the repository at this point in the history
…nymore)
  • Loading branch information
aeddi committed Apr 10, 2019
1 parent 6c7dca6 commit b295b2a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 31 deletions.
Expand Up @@ -25,6 +25,10 @@
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public class ConnectivityUpdateHandler extends BroadcastReceiver {
private static String TAG = "connectivity_update_handler";
private static final short
STATE_ON = 1,
STATE_OFF = 2;


ConnectivityUpdateHandler(ReactApplicationContext reactContext) {
super();
Expand Down Expand Up @@ -53,10 +57,6 @@ public void onReceive(Context context, Intent intent) {
}

private static final void updateConnectivity(Context context) {
final short
STATE_ON = 1,
STATE_OFF = 2;

ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
Network currentNet;
NetworkCapabilities currentNetCap;
Expand Down Expand Up @@ -212,10 +212,6 @@ private static final String getTypeString(Context context) {
}

private static final void updateBLE(int state) {
final short
STATE_ON = 1,
STATE_OFF = 2;

if(isBleAdvAndScanCompatible() && state == BluetoothAdapter.STATE_ON)
Core.updateBluetoothState(STATE_ON);
else if(state == BluetoothAdapter.STATE_OFF)
Expand Down
8 changes: 4 additions & 4 deletions core/network/state/notifee.go
Expand Up @@ -15,7 +15,7 @@ type Notifee interface {
HandleTrustedChange(State)
HandleNetTypeChange(NetType)
HandleCellTypeChange(CellType)
HandleBluetoothChange(BleState)
HandleBluetoothChange(State)
}

type notifier struct {
Expand All @@ -35,7 +35,7 @@ func (nr *notifier) notifyConnectivityChange(cs ConnectivityState) {
zap.String("Trusted", StateToString(cs.Trusted)),
zap.String("Network", NetTypeToString(cs.Network)),
zap.String("Cellular", CellTypeToString(cs.Cellular)),
zap.String("Bluetooth", BleStateToString(cs.Bluetooth)),
zap.String("Bluetooth", StateToString(cs.Bluetooth)),
)
for _, notifee := range nr.notifees {
notifee.HandleConnectivityChange(cs)
Expand Down Expand Up @@ -132,10 +132,10 @@ func (nr *notifier) notifyCellTypeChange(c CellType) {
nr.lock.Unlock()
}

func (nr *notifier) notifyBluetoothChange(b BleState) {
func (nr *notifier) notifyBluetoothChange(b State) {
nr.lock.Lock()

logger().Debug("notify bluetooth state change:", zap.String("new state", BleStateToString(b)))
logger().Debug("notify bluetooth state change:", zap.String("new state", StateToString(b)))
for _, notifee := range nr.notifees {
notifee.HandleBluetoothChange(b)
}
Expand Down
17 changes: 1 addition & 16 deletions core/network/state/state.go
Expand Up @@ -21,10 +21,6 @@ const (
Cell2G CellType = 2
Cell3G CellType = 3
Cell4G CellType = 4

UnknownBleState BleState = 0
BleOn BleState = 1
BleOff BleState = 2
)

type ConnectivityState struct {
Expand All @@ -36,7 +32,7 @@ type ConnectivityState struct {
Trusted State
Network NetType
Cellular CellType
Bluetooth BleState
Bluetooth State
}

func StateToString(s State) string {
Expand Down Expand Up @@ -79,14 +75,3 @@ func CellTypeToString(c CellType) string {
return "unknown"
}
}

func BleStateToString(b BleState) string {
switch b {
case BleOn:
return "on"
case BleOff:
return "off"
default:
return "unknown"
}
}
6 changes: 3 additions & 3 deletions core/network/state/updater.go
Expand Up @@ -105,9 +105,9 @@ func (nu *NetworkUpdater) UpdateConnectivityState(connState string) {
func (nu *NetworkUpdater) UpdateBluetoothState(bleState int) {
nu.lock.Lock()

if BleState(bleState) != nu.state.Bluetooth {
nu.state.Bluetooth = BleState(bleState)
nu.notif.notifyBluetoothChange(BleState(bleState))
if State(bleState) != nu.state.Bluetooth {
nu.state.Bluetooth = State(bleState)
nu.notif.notifyBluetoothChange(State(bleState))
nu.notif.notifyConnectivityChange(nu.state)
}

Expand Down

0 comments on commit b295b2a

Please sign in to comment.