Commit 4c4de275 by Razvan Cristian Lung

fix lint warning and add Android Pie specific implementation for getting

the locations service status
parent 33de6dd7
...@@ -7,11 +7,14 @@ import android.content.Context; ...@@ -7,11 +7,14 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageInfo; import android.content.pm.PackageInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.location.LocationManager;
import android.os.Build; import android.os.Build;
import android.provider.Settings; import android.provider.Settings;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
...@@ -54,6 +57,7 @@ public class PermissionHandlerPlugin implements MethodCallHandler { ...@@ -54,6 +57,7 @@ public class PermissionHandlerPlugin implements MethodCallHandler {
this.mRegistrar = mRegistrar; this.mRegistrar = mRegistrar;
} }
@Retention(RetentionPolicy.SOURCE)
@IntDef({ @IntDef({
PERMISSION_GROUP_CALENDAR, PERMISSION_GROUP_CALENDAR,
PERMISSION_GROUP_CAMERA, PERMISSION_GROUP_CAMERA,
...@@ -82,6 +86,7 @@ public class PermissionHandlerPlugin implements MethodCallHandler { ...@@ -82,6 +86,7 @@ public class PermissionHandlerPlugin implements MethodCallHandler {
private static final int PERMISSION_STATUS_RESTRICTED = 3; private static final int PERMISSION_STATUS_RESTRICTED = 3;
private static final int PERMISSION_STATUS_UNKNOWN = 4; private static final int PERMISSION_STATUS_UNKNOWN = 4;
@Retention(RetentionPolicy.SOURCE)
@IntDef({ @IntDef({
PERMISSION_STATUS_DENIED, PERMISSION_STATUS_DENIED,
PERMISSION_STATUS_DISABLED, PERMISSION_STATUS_DISABLED,
...@@ -99,6 +104,7 @@ public class PermissionHandlerPlugin implements MethodCallHandler { ...@@ -99,6 +104,7 @@ public class PermissionHandlerPlugin implements MethodCallHandler {
private static final int SERVICE_STATUS_NOT_APPLICABLE = 2; private static final int SERVICE_STATUS_NOT_APPLICABLE = 2;
private static final int SERVICE_STATUS_UNKNOWN = 3; private static final int SERVICE_STATUS_UNKNOWN = 3;
@Retention(RetentionPolicy.SOURCE)
@IntDef({ @IntDef({
SERVICE_STATUS_DISABLED, SERVICE_STATUS_DISABLED,
SERVICE_STATUS_ENABLED, SERVICE_STATUS_ENABLED,
...@@ -199,8 +205,7 @@ public class PermissionHandlerPlugin implements MethodCallHandler { ...@@ -199,8 +205,7 @@ public class PermissionHandlerPlugin implements MethodCallHandler {
} }
mResult = result; mResult = result;
//noinspection unchecked final List<Integer> permissions = call.arguments();
final List<Integer> permissions = (List<Integer>) call.arguments;
requestPermissions(permissions); requestPermissions(permissions);
break; break;
case "shouldShowRequestPermissionRationale": { case "shouldShowRequestPermissionRationale": {
...@@ -571,23 +576,28 @@ public class PermissionHandlerPlugin implements MethodCallHandler { ...@@ -571,23 +576,28 @@ public class PermissionHandlerPlugin implements MethodCallHandler {
return false; return false;
} }
@SuppressWarnings("deprecation")
private boolean isLocationServiceEnabled(Context context) { private boolean isLocationServiceEnabled(Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
final LocationManager locationManager = context.getSystemService(LocationManager.class);
if (locationManager == null) {
return false;
}
return locationManager.isLocationEnabled();
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
final int locationMode; final int locationMode;
final String locationProviders;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
try { try {
locationMode = Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.LOCATION_MODE); locationMode = Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.LOCATION_MODE);
} catch (Settings.SettingNotFoundException e) { } catch (Settings.SettingNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
return false; return false;
} }
return locationMode != Settings.Secure.LOCATION_MODE_OFF; return locationMode != Settings.Secure.LOCATION_MODE_OFF;
} else { } else {
locationProviders = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED); final String locationProviders = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
return !TextUtils.isEmpty(locationProviders); return !TextUtils.isEmpty(locationProviders);
} }
} }
......
...@@ -49,7 +49,7 @@ class ServiceStatus { ...@@ -49,7 +49,7 @@ class ServiceStatus {
static const ServiceStatus disabled = ServiceStatus._(0); static const ServiceStatus disabled = ServiceStatus._(0);
/// The service for the supplied permission group is enabled. /// The service for the supplied permission group is enabled.
static const ServiceStatus enable = ServiceStatus._(1); static const ServiceStatus enabled = ServiceStatus._(1);
/// There is no service for the supplied permission group. /// There is no service for the supplied permission group.
static const ServiceStatus notApplicable = ServiceStatus._(2); static const ServiceStatus notApplicable = ServiceStatus._(2);
...@@ -59,14 +59,14 @@ class ServiceStatus { ...@@ -59,14 +59,14 @@ class ServiceStatus {
static const List<ServiceStatus> values = <ServiceStatus>[ static const List<ServiceStatus> values = <ServiceStatus>[
disabled, disabled,
enable, enabled,
notApplicable, notApplicable,
unknown, unknown,
]; ];
static const List<String> _names = <String>[ static const List<String> _names = <String>[
'disabled', 'disabled',
'enable', 'enabled',
'notApplicable', 'notApplicable',
'unknown', 'unknown',
]; ];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment