diff --git a/app/src/main/java/info/zamojski/soft/towercollector/MainActivity.java b/app/src/main/java/info/zamojski/soft/towercollector/MainActivity.java index becdfb9..05f46d7 100644 --- a/app/src/main/java/info/zamojski/soft/towercollector/MainActivity.java +++ b/app/src/main/java/info/zamojski/soft/towercollector/MainActivity.java @@ -881,14 +881,24 @@ private void startCollectorServiceWithCheck() { return; } if (PermissionUtils.isNotificationPermissionRequired()) { - MainActivityPermissionsDispatcher.startCollectorServiceApi33WithPermissionCheck(MainActivity.this); + if (PermissionUtils.isForegroundServicePermissionAware()) { + MainActivityPermissionsDispatcher.startCollectorServiceApi34WithPermissionCheck(MainActivity.this); + } else { + MainActivityPermissionsDispatcher.startCollectorServiceApi33WithPermissionCheck(MainActivity.this); + } } else { MainActivityPermissionsDispatcher.startCollectorServiceWithPermissionCheck(MainActivity.this); } } - @TargetApi(Build.VERSION_CODES.TIRAMISU) + @TargetApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE) @NeedsPermission({Manifest.permission.POST_NOTIFICATIONS, Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.FOREGROUND_SERVICE_LOCATION, Manifest.permission.READ_PHONE_STATE}) + void startCollectorServiceApi34() { + startCollectorServiceInternal(); + } + + @TargetApi(Build.VERSION_CODES.TIRAMISU) + @NeedsPermission({Manifest.permission.POST_NOTIFICATIONS, Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.READ_PHONE_STATE}) void startCollectorServiceApi33() { startCollectorServiceInternal(); } @@ -920,8 +930,14 @@ private void startCollectorServiceInternal() { } } - @TargetApi(Build.VERSION_CODES.TIRAMISU) + @TargetApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE) @OnShowRationale({Manifest.permission.POST_NOTIFICATIONS, Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.FOREGROUND_SERVICE_LOCATION, Manifest.permission.READ_PHONE_STATE}) + void onStartCollectorShowRationaleApi34(PermissionRequest request) { + onStartCollectorShowRationaleInternal(request); + } + + @TargetApi(Build.VERSION_CODES.TIRAMISU) + @OnShowRationale({Manifest.permission.POST_NOTIFICATIONS, Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.READ_PHONE_STATE}) void onStartCollectorShowRationaleApi33(PermissionRequest request) { onStartCollectorShowRationaleInternal(request); } @@ -935,8 +951,14 @@ private void onStartCollectorShowRationaleInternal(PermissionRequest request) { onShowRationale(request, GpsUtils.isPreciseLocationAware() ? R.string.permission_collector_rationale_api31_message : R.string.permission_collector_rationale_message); } - @TargetApi(Build.VERSION_CODES.TIRAMISU) + @TargetApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE) @OnPermissionDenied({Manifest.permission.POST_NOTIFICATIONS, Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.FOREGROUND_SERVICE_LOCATION, Manifest.permission.READ_PHONE_STATE}) + void onStartCollectorPermissionDeniedApi34() { + onStartCollectorPermissionDeniedInternal(); + } + + @TargetApi(Build.VERSION_CODES.TIRAMISU) + @OnPermissionDenied({Manifest.permission.POST_NOTIFICATIONS, Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.READ_PHONE_STATE}) void onStartCollectorPermissionDeniedApi33() { onStartCollectorPermissionDeniedInternal(); } @@ -950,8 +972,14 @@ private void onStartCollectorPermissionDeniedInternal() { onPermissionDenied(R.string.permission_collector_denied_message); } - @TargetApi(Build.VERSION_CODES.TIRAMISU) + @TargetApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE) @OnNeverAskAgain({Manifest.permission.POST_NOTIFICATIONS, Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.FOREGROUND_SERVICE_LOCATION, Manifest.permission.READ_PHONE_STATE}) + void onStartCollectorNeverAskAgainApi34() { + onStartCollectorNeverAskAgainInternal(); + } + + @TargetApi(Build.VERSION_CODES.TIRAMISU) + @OnNeverAskAgain({Manifest.permission.POST_NOTIFICATIONS, Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.READ_PHONE_STATE}) void onStartCollectorNeverAskAgainApi33() { onStartCollectorNeverAskAgainInternal(); } diff --git a/app/src/main/java/info/zamojski/soft/towercollector/utils/PermissionUtils.java b/app/src/main/java/info/zamojski/soft/towercollector/utils/PermissionUtils.java index e49c841..fc90bc0 100644 --- a/app/src/main/java/info/zamojski/soft/towercollector/utils/PermissionUtils.java +++ b/app/src/main/java/info/zamojski/soft/towercollector/utils/PermissionUtils.java @@ -46,7 +46,7 @@ public static boolean isNotificationPermissionRequired() { } public static boolean isForegroundServicePermissionAware() { - return Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; // TODO: should be Build.VERSION_CODES.UPSIDE_DOWN_CAKE but I recall there were issues on Android 12 as well + return Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE; } public static String getAppPermissions() {