Skip to content

Commit 4314d9d

Browse files
committed
Remove inner class ServicePermissionUtil in AndroidTool
1 parent 647c5d9 commit 4314d9d

3 files changed

Lines changed: 23 additions & 23 deletions

File tree

android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public void onSdlEnabled(Context context, Intent intent) {
3535
PendingIntent pendingIntent = (PendingIntent) intent.getParcelableExtra(TransportConstants.PENDING_INTENT_EXTRA);
3636
if (pendingIntent != null) {
3737
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
38-
if (!AndroidTools.ServicePermissionUtil.hasForegroundServiceTypePermission(context)) {
38+
if (!AndroidTools.hasForegroundServiceTypePermission(context)) {
3939
requestUsbAccessory(context);
4040
storedIntent = intent;
4141
storedContext = context;
@@ -82,7 +82,7 @@ public String getSdlServiceName() {
8282
public void onReceive(Context context, Intent intent) {
8383
String action = intent.getAction();
8484
if (ACTION_USB_PERMISSION.equals(action) && storedContext != null && storedIntent != null && pendingIntent != null) {
85-
if (AndroidTools.ServicePermissionUtil.hasForegroundServiceTypePermission(storedContext)) {
85+
if (AndroidTools.hasForegroundServiceTypePermission(storedContext)) {
8686
try {
8787
pendingIntent.send(storedContext, 0, storedIntent);
8888
} catch (PendingIntent.CanceledException e) {

android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ public void handleMessage(Message msg) {
864864
if (parcelFileDescriptor != null) {
865865
// Added requirements with Android 14, Checking if we have proper permission to enter the foreground for Foreground service type connectedDevice.
866866
// If we do not have permission to enter the Foreground, we pass off hosting the RouterService to another app.
867-
if (!AndroidTools.ServicePermissionUtil.hasForegroundServiceTypePermission(service.getApplicationContext())) {
867+
if (!AndroidTools.hasForegroundServiceTypePermission(service.getApplicationContext())) {
868868
service.deployNextRouterService(parcelFileDescriptor);
869869
acknowledgeUSBAccessoryReceived(msg);
870870
return;

android/sdl_android/src/main/java/com/smartdevicelink/util/AndroidTools.java

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -397,30 +397,30 @@ public static void saveVehicleType(Context context, VehicleType vehicleType, Str
397397
}
398398
}
399399

400-
public static class ServicePermissionUtil {
401-
public static boolean hasUsbAccessoryPermission(Context context) {
402-
UsbManager manager = (UsbManager) context.getSystemService(Context.USB_SERVICE);
403-
if (manager == null || manager.getAccessoryList() == null) {
404-
return false;
405-
}
406-
for (final UsbAccessory usbAccessory : manager.getAccessoryList()) {
407-
if (manager.hasPermission(usbAccessory)) {
408-
return true;
409-
}
410-
}
400+
public static boolean hasUsbAccessoryPermission(Context context) {
401+
UsbManager manager = (UsbManager) context.getSystemService(Context.USB_SERVICE);
402+
if (manager == null || manager.getAccessoryList() == null) {
411403
return false;
412404
}
413-
414-
public static boolean checkPermission(Context applicationContext, String permission) {
415-
return PackageManager.PERMISSION_GRANTED == ContextCompat.checkSelfPermission(applicationContext, permission);
416-
}
417-
418-
public static boolean hasForegroundServiceTypePermission(Context context) {
419-
// if Build is less than Android 14, we don't need either permission to enter the foreground.
420-
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
405+
for (final UsbAccessory usbAccessory : manager.getAccessoryList()) {
406+
if (manager.hasPermission(usbAccessory)) {
421407
return true;
422408
}
423-
return ServicePermissionUtil.checkPermission(context, Manifest.permission.BLUETOOTH_CONNECT) || ServicePermissionUtil.hasUsbAccessoryPermission(context);
424409
}
410+
return false;
411+
}
412+
413+
public static boolean checkPermission(Context applicationContext, String permission) {
414+
return PackageManager.PERMISSION_GRANTED == ContextCompat.checkSelfPermission(applicationContext, permission);
415+
}
416+
417+
public static boolean hasForegroundServiceTypePermission(Context context) {
418+
// if Build is less than Android 14, we don't need either permission to enter the
419+
// foreground.
420+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
421+
return true;
422+
}
423+
return checkPermission(context,
424+
Manifest.permission.BLUETOOTH_CONNECT) || hasUsbAccessoryPermission(context);
425425
}
426426
}

0 commit comments

Comments
 (0)