Skip to content

Commit

Permalink
[#52317] android-client: Reconnect the WebSocket after device is unau…
Browse files Browse the repository at this point in the history
…thorized

Management WS reconnections were handled incorrectly, and if a device was
unauthorized the reconnect would never happen until the app is restarted.
  • Loading branch information
lkedziora committed Dec 8, 2023
1 parent 8bc096c commit 1a4b9f9
Showing 1 changed file with 7 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,8 @@ public ManagementClient(Utils utils, IDeviceTokenProvider tokenProvider) {
new Thread(this::reconnectThread).start();
}

private void connectToWs() {
String token;
try {
token = mTokenProvider.fetchDeviceToken();
} catch (DeviceUnauthorizedException | ServerConnectionException e) {
Log.w(TAG, "Cannot connect to management WebSocket - device unauthorized");
return;
}

private void connectToWs() throws DeviceUnauthorizedException, ServerConnectionException {
String token = mTokenProvider.fetchDeviceToken();
Request request = new Request.Builder()
.url(mServerAddress + "/api/v1/devices/ws")
.header("Authorization", "Bearer token=" + token)
Expand Down Expand Up @@ -143,8 +136,11 @@ private void reconnectThread() {
// Connect to the WS
try {
connectToWs();
} catch (Exception e) {
Log.e(TAG, "Exception when connecting to the management WebSocket", e);
} catch (ServerConnectionException e) {
Log.e(TAG, "Cannot connect to the management WebSocket - server connection failed");
continue;
} catch (DeviceUnauthorizedException e) {
Log.e(TAG, "Cannot connect to the management WebSocket - device unauthorized");
continue;
}

Expand Down

0 comments on commit 1a4b9f9

Please sign in to comment.