Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@

import android.app.ActivityManager;
import android.app.ActivityManager.RunningServiceInfo;
import android.app.ForegroundServiceStartNotAllowedException;
import android.app.ServiceStartNotAllowedException;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothProfile;
Expand Down Expand Up @@ -282,8 +284,8 @@ private static void startRouterService(Context context, ComponentName componentN
restart.putExtra(LOCAL_ROUTER_SERVICE_DID_START_OWN, true);
context.sendBroadcast(restart);

} catch (SecurityException e) {
DebugTool.logError(TAG, "Security exception, process is bad");
} catch (SecurityException | IllegalStateException e) {
handleStartServiceException(e);
}
}

Expand Down Expand Up @@ -478,9 +480,8 @@ protected static void pingRouterService(Context context, String packageName, Str
} else {
context.startService(intent);
}
} catch (SecurityException e) {
DebugTool.logError(TAG, "Security exception, process is bad");
// This service could not be started
} catch (SecurityException | IllegalStateException e) {
handleStartServiceException(e);
}
}

Expand Down Expand Up @@ -599,6 +600,22 @@ private static boolean isBluetoothConnected() {
return false;
}

private static void handleStartServiceException(Exception e) {
if (e instanceof SecurityException) {
DebugTool.logError(TAG, "Security exception, process is bad");
return;
} else if (Build.VERSION.SDK_INT > Build.VERSION_CODES.R) {
if (e instanceof ForegroundServiceStartNotAllowedException) {
DebugTool.logError(TAG, "Not allowed to start service in foreground");
return;
} else if (e instanceof ServiceStartNotAllowedException) {
DebugTool.logError(TAG, "Not allowed to start service in current state");
return;
}
}
DebugTool.logError(TAG, "Unable to start service for unknown reason");
}


private static SdlDeviceListener getSdlDeviceListener(Context context, BluetoothDevice bluetoothDevice) {

Expand Down