Skip to content

Commit

Permalink
Removed all debugging from DAIRemote App (#126)
Browse files Browse the repository at this point in the history
* Removed all debugging from DAIRemote App.
  • Loading branch information
Fahim-zzz authored Dec 2, 2024
1 parent 106ad29 commit 9ef80af
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public void onBackPressed() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
int itemId = item.getItemId();
Log.d("Navigation", "Item selected: " + itemId);

if (itemId == R.id.nav_remote) {
if (ConnectionManager.GetConnectionEstablished()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.example.dairemote_app;

import android.os.Build;
import android.util.Log;

import java.io.IOException;
import java.net.DatagramPacket;
Expand Down Expand Up @@ -59,9 +58,7 @@ public ConnectionManager(String serverAddress) {
try {
SetServerAddress(serverAddress);
SetServerAddress(InetAddress.getByName(GetServerAddress()));
} catch (Exception e) {
e.printStackTrace();
Log.e("ConnectionManager", "Error getting serverAddr by Name: " + e.getMessage());
} catch (Exception ignored) {
}

this.executorService = Executors.newCachedThreadPool();
Expand Down Expand Up @@ -197,7 +194,6 @@ public static void HostSearch(String message) {

SetServerResponse(new String(receivePacket.getData()).trim());
String serverIp = receivePacket.getAddress().getHostAddress();
Log.i("ConnectionManager", "Response from server: " + GetServerResponse() + " at " + serverIp);

if (GetServerResponse().contains("Hello, I'm")) {
hosts.add(serverIp);
Expand All @@ -219,9 +215,7 @@ public static void HostSearch(String message) {
} else {
hostHandler.onError("No hosts found");
}
} catch (SocketException e) {
e.printStackTrace();
Log.e("ConnectionManager", "Error initializing DatagramSocket: " + e.getMessage());
} catch (SocketException ignored) {
} catch (UnknownHostException e) {
throw new RuntimeException(e);
} catch (IOException e) {
Expand All @@ -237,11 +231,7 @@ public void WaitForResponse(int timeout) {
udpSocket.setSoTimeout(75);

SetServerResponse(new String(receivePacket.getData(), 0, receivePacket.getLength()));
} catch (SocketTimeoutException e) {
Log.i("ConnectionManager", "No response received within the timeout: " + e.getMessage());
SetServerResponse("");
} catch (Exception e) {
Log.e("ConnectionManager", "Error waiting for response: " + e.getMessage());
} catch (Exception ignored) {
SetServerResponse("");
}
}
Expand All @@ -253,20 +243,16 @@ public boolean InitializeConnection() {
while (GetServerResponse().isEmpty()) {
try {
SendData("Connection requested by " + GetDeviceName(), GetInetAddress());
} catch (Exception e) {
e.printStackTrace();
Log.e("ConnectionManager", "Error connecting from InitializeConnection(): " + e.getMessage());
} catch (Exception ignored) {
}
broadcastCount += 1;
if (broadcastCount > 5) {
Log.e("ConnectionManager", "Timed out waiting for connection response, aborting...");
return false;
} else {
// Updates serverResponse else times out and throws socket exception
try {
WaitForResponse(5000);
} catch (Exception e) {
Log.i("ConnectionManager", "Connection initialization timeout: " + broadcastCount);
} catch (Exception ignored) {
}
}

Expand All @@ -279,7 +265,6 @@ public boolean FinishConnection() {
if (GetServerResponse().equalsIgnoreCase("Wait")) {
SetServerResponse("");
while (GetServerResponse().isEmpty()) {
Log.i("ConnectionManager", "Waiting for approval...");
WaitForResponse(10000);
approvalTimeout += 1;
if(approvalTimeout > 5) {
Expand All @@ -293,16 +278,13 @@ public boolean FinishConnection() {
return true;
} else if (GetServerResponse().equalsIgnoreCase("Connection attempt declined.")) {
ResetConnectionManager();
Log.e("ConnectionManager", "Denied connection");
}
SetServerResponse("");
} else if (GetServerResponse().equalsIgnoreCase("Approved")) {
ShutdownHostSearchInBackground();
ConnectionMonitor.GetInstance(MainActivity.connectionManager);
SetConnectionEstablished(true);
return true;
} else {
Log.e("ConnectionManager", "No response to broadcast.");
}
return false;
}
Expand All @@ -325,33 +307,26 @@ public boolean SendHostMessage(String msg) {
public void SendMessage(String message) {
try {
SendData(message, GetInetAddress());
} catch (Exception e) {
e.printStackTrace();
Log.e("ConnectionManager", "Error sending message from sendMessage(String message): " + e.getMessage());
} catch (Exception ignored) {
}
}

public boolean HostRequester(String replyCondition, String sendMessage, InetAddress inetAddress, String logTag, String subject) {
public boolean HostRequester(String replyCondition, String sendMessage, InetAddress inetAddress) {
SetServerResponse("");
int broadcastCount = 0;
while (!GetServerResponse().startsWith(replyCondition)) {
try {
SendData(sendMessage, inetAddress);
Log.d(logTag, "Attempting to retrieve host " + subject);
} catch (Exception e) {
e.printStackTrace();
Log.e(logTag, "Error retrieving host " + subject + ": " + e.getMessage());
} catch (Exception ignored) {
}
broadcastCount += 1;
if (broadcastCount > 5) {
Log.e(logTag, "Timed out waiting for host " + subject + ", aborting...");
return false;
} else {
// Updates serverResponse else times out and throws socket exception
try {
WaitForResponse(5000);
} catch (Exception e) {
Log.i(logTag, "Host " + subject + " list timeout: " + broadcastCount);
} catch (Exception ignored) {
}
}

Expand All @@ -361,7 +336,7 @@ public boolean HostRequester(String replyCondition, String sendMessage, InetAddr
}

public boolean RequestHostName() {
if(HostRequester("HostName", "HOST Name", GetInetAddress(), "ConnectionManagerHost", "host name")) {
if(HostRequester("HostName", "HOST Name", GetInetAddress())) {
SetHostName(GetHostRequesterResponse());
return true;
}
Expand All @@ -370,7 +345,7 @@ public boolean RequestHostName() {

// Retrieve audio devices from host
public boolean RequestHostAudioDevices() {
if(HostRequester("AudioDevices", "AUDIO Devices", GetInetAddress(), "ConnectionManagerAudio", "audio devices")) {
if(HostRequester("AudioDevices", "AUDIO Devices", GetInetAddress())) {
SetHostAudioList(GetHostRequesterResponse());
return true;
}
Expand All @@ -379,15 +354,14 @@ public boolean RequestHostAudioDevices() {

// Retrieve display profiles from host
public boolean RequestHostDisplayProfiles() {
if(HostRequester("DisplayProfiles", "DISPLAY Profiles", GetInetAddress(), "ConnectionManagerDisplays", "display profiles")) {
if(HostRequester("DisplayProfiles", "DISPLAY Profiles", GetInetAddress())) {
SetHostDisplayProfilesList(GetHostRequesterResponse());
return true;
}
return false;
}

public void ResetConnectionManager() {
Log.e("ConnectionManager", "Resetting ConnectionManager");
StopExecServices(executorService);
SetConnectionEstablished(false);
SetServerResponse(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import android.os.Handler;
import android.os.Looper;
import android.util.Log;

import java.net.DatagramSocket;
import java.util.concurrent.CompletableFuture;
Expand Down Expand Up @@ -90,7 +89,6 @@ public void StartHeartbeat(int delay) {

public boolean SendHeartbeat() {
if (heartbeatExecutorService.isShutdown()) {
Log.e("ConnectionMonitor", "Heartbeat service is not running, cannot send heartbeat.");
return false;
}

Expand All @@ -102,13 +100,9 @@ public boolean SendHeartbeat() {
SetHeartbeatResponse(GetHeartbeatSocket().WaitForResponse(3000));

if (GetHeartbeatResponse().equalsIgnoreCase("HeartBeat Ack")) {
Log.d("ConnectionManager", "Received heartbeat response: " + GetHeartbeatResponse());
return true;
}
Log.e("ConnectionManager", "heartbeat was not acknowledged, response was: " + GetHeartbeatResponse());
} catch (Exception e) {
e.printStackTrace();
Log.e("ConnectionMonitor", "Error sending message from sendMessage(String message): " + e.getMessage());
} catch (Exception ignored) {
}
return false;
}, heartbeatExecutorService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public void onBackPressed() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
int itemId = item.getItemId();
Log.d("Navigation", "Item selected: " + itemId);

if (itemId == R.id.nav_remote) {
if (ConnectionManager.GetConnectionEstablished()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,6 @@ public void onTextChanged(CharSequence s, int start, int before, int count) {
MessageHost("KEYBOARD_WRITE " + addedChar);
} else {
toolbar.AppendKeyCombination(addedChar);
Log.i("KeyCombination", toolbar.GetKeyCombination().toString());
}
toolbar.GetKeyboardTextView().append(String.valueOf(addedChar));
}
Expand Down Expand Up @@ -553,7 +552,6 @@ public void extraToolbarOnClick(View view) {
toolbar.AddParentheses();

MessageHost("KEYBOARD_WRITE " + toolbar.GetKeyCombination());
Log.i("KeyboardToolbar", "KEYBOARD_WRITE " + toolbar.GetKeyCombination());

ResetKeyboardModifiers();

Expand All @@ -570,10 +568,8 @@ public void extraToolbarOnClick(View view) {
toolbar.GetKeyboardTextView().append(msg);
} else if (audio) {
MessageHost("AUDIO " + msg);
Log.i("KeyboardToolbar", "AUDIO " + msg);
} else if (!msg.isEmpty()) {
MessageHost("KEYBOARD_WRITE " + msg);
Log.i("KeyboardToolbar", "KEYBOARD_WRITE " + msg);
}
}

Expand Down Expand Up @@ -617,7 +613,6 @@ protected void onResume() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
int itemId = item.getItemId();
Log.d("Navigation", "Item selected: " + itemId);

if (itemId == R.id.nav_remote) {
// Current page, do nothing
Expand Down Expand Up @@ -731,25 +726,21 @@ protected void onPostExecute(Boolean result) {
// Load audio devices on recycler
String devicesPart = parts[0].substring("AudioDevices: ".length());
List<String> deviceList = Arrays.asList(devicesPart.split(","));
Log.d("InteractionPageAudio", "Audio devices: " + deviceList);

if (deviceList.isEmpty() || deviceList.get(0).isEmpty()) {
List<String> placeholder = Collections.singletonList("No audio devices");
UpdateAudioDevices(placeholder);
} else {
UpdateAudioDevices(deviceList);
Log.d("InteractionPageAudio", "Audio default device: " + parts[2].substring("DefaultAudioDevice: ".length()));
SetAudioDeviceDefault(parts[2].substring("DefaultAudioDevice: ".length()));

// Set seekbar to current host volume
String volumePart = parts[1].substring("Volume: ".length());
Log.d("InteractionPageAudio", "Volume: " + Integer.parseInt(volumePart));
volumeSlider.setProgress(Integer.parseInt(volumePart));
currentVolume.setText(volumePart);

// Get host's current mute status
String muteStatus = parts[3].substring("Mute: ".length());
Log.d("InteractionPageAudio", "Mute: " + muteStatus);
if(muteStatus.equalsIgnoreCase("true")) {
audioMuted = true;
audioToggleMuteButton.setColorFilter(getColor(R.color.black));
Expand All @@ -760,11 +751,7 @@ protected void onPostExecute(Boolean result) {
currentVolume.setTextColor(getColor(R.color.grey));
}
}
} else {
Log.e("InteractionPageAudio", "Unexpected response format: " + response);
}
} else {
Log.e("InteractionPageAudio", "Unexpected response format: " + response);
}
}
isRequestAudioDevicesTaskRunning = false;
Expand Down Expand Up @@ -794,11 +781,8 @@ protected void onPostExecute(Boolean result) {
List<String> placeholder = Collections.singletonList("No display profiles");
UpdateDisplayProfiles(placeholder);
} else {
Log.d("InteractionPageDisplays", "Display Profiles: " + deviceList);
UpdateDisplayProfiles(deviceList);
}
} else {
Log.e("InteractionPageDisplays", "Unexpected response format: " + response);
}
}
isRequestDisplayProfilesTaskRunning = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ public void onHostFound(List<String> serverIps) {
if (serverIps.isEmpty()) {
return;
}
Log.i("MainActivity", "Hosts found: " + serverIps);

//!! Implement logic to select the host
String selectedHost = serverIps.get(0);
Expand All @@ -147,7 +146,6 @@ public void onHostFound(List<String> serverIps) {
@Override
public void onError(String error) {
runOnUiThread(() -> connectionProgress.setVisibility(View.GONE));
Log.e("MainActivity", "Error during host search: " + error);
notifyUser(MainActivity.this, "No hosts found");
runOnUiThread(() -> {
builderTitleMsg(builder, "No Hosts Found", "No available hosts were found. Please add a server host manually.");
Expand Down Expand Up @@ -181,7 +179,6 @@ public void onBackPressed() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
int itemId = item.getItemId();
Log.i("MainActivity", "Item selected: " + itemId);

if (itemId == R.id.nav_remote) {
if (ConnectionManager.GetConnectionEstablished()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ public boolean PriorConnectionEstablishedCheck(String host) {
// Stop the current connection before attempting a new one
MainActivity.connectionManager.Shutdown();
} else {
Log.d("TEST", "Already connected");
InitiateInteractionPage("Already connected");
}
return true;
Expand Down Expand Up @@ -205,7 +204,6 @@ public void onHostFound(List<String> hosts) {

@Override
public void onError(String error) {
Log.e("ServersPage", "No hosts available: " + error);
}
}, "Hello, DAIRemote");

Expand Down Expand Up @@ -248,7 +246,6 @@ public void onBackPressed() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
int itemId = item.getItemId();
Log.d("Navigation", "Item selected: " + itemId);

if (itemId == R.id.nav_remote) {
if (ConnectionManager.GetConnectionEstablished()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public void SetSocket() {
try {
socket = new DatagramSocket();
} catch (SocketException e) {
Log.e("SocketManager", "Socket creation failed: " + e.getMessage());
throw new RuntimeException(e);
}
}
Expand Down Expand Up @@ -72,10 +71,7 @@ public String WaitForResponse(int timeout) {
GetSocket().setSoTimeout(75);

return new String(GetPacket().getData(), 0, GetPacket().getLength());
} catch (SocketTimeoutException e) {
Log.i("ConnectionManager", "No response received within the timeout: " + e.getMessage());
} catch (Exception e) {
Log.e("ConnectionManager", "Error waiting for response: " + e.getMessage());
} catch (Exception ignored) {
}
return "";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,10 @@ public void ShowCurrentStep(String title, String message, String positive, Strin

public void showNextStep() {
setCurrentStep(getCurrentStep() + 1);
Log.d("InteractiveTutorial", "Starting next step");
showSteps(getCurrentStep());
}

public void showSteps(int step) {
Log.i("InteractiveTutorial", "Show step: " + step);
switch (step) {
case 0:
ShowStartStep("Interactive Tutorial",
Expand Down Expand Up @@ -190,7 +188,6 @@ public void showSteps(int step) {

break;
default:
Log.d("InteractiveTutorial", "Invalid step");
break;
}
}
Expand Down

0 comments on commit 9ef80af

Please sign in to comment.