private boolean verifyLocationSettings()

in niap-cc/Permissions/Companion/app/src/main/java/com/android/certifications/niap/permissions/companion/MainActivity.java [160:213]


    private boolean verifyLocationSettings() {
        LocationSettingsRequest locationSettingsRequest =
                new LocationSettingsRequest.Builder().addLocationRequest(mLocationRequest).build();
        Task<LocationSettingsResponse> result = LocationServices.getSettingsClient(
                this).checkLocationSettings(locationSettingsRequest);
        try {
            Tasks.await(result, 10, TimeUnit.SECONDS);
            Log.d(TAG, "Location settings indicate location should be available");
            return true;
        } catch (ExecutionException e) {
            // An ExecutionException indicates that GMS is not properly configured to support this
            // location request. If the cause of the exception is a ResolveableApiException then
            // the resolution from the exception can be used to prompt the user to configure GMS.
            Throwable exceptionCause = e.getCause();
            if (exceptionCause != null && exceptionCause instanceof ApiException) {
                ApiException apiException = (ApiException) exceptionCause;
                switch (apiException.getStatusCode()) {
                    case LocationSettingsStatusCodes
                            .RESOLUTION_REQUIRED:
                        if (apiException instanceof ResolvableApiException) {
                            ResolvableApiException resolvableApiException =
                                    (ResolvableApiException) apiException;
                            try {
                                resolvableApiException.startResolutionForResult(this,
                                        REQUEST_LOCATION_SETTINGS);
                            } catch (IntentSender.SendIntentException intentException) {
                                Log.d(TAG,
                                        "Caught a SendIntentException attempting to launch the "
                                                + "Settings page");
                            }
                        } else {
                            Log.d(TAG,
                                    "Settings resolution is required to access location, but "
                                            + "Exception is not an instanceof "
                                            + "ResolvableApiException");
                        }
                        break;
                    case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
                        Log.d(TAG,
                                "Settings resolution is required to access location, but the "
                                        + "change is unavailable from this app");
                        break;
                    default:
                        Log.d(TAG, "Received unknown status code " + apiException.getStatusCode()
                                + " from exception: ", e);
                }
            } else {
                Log.d(TAG, "Caught an ExecutionException verifying the location settings: ", e);
            }
        } catch (TimeoutException | InterruptedException e) {
            Log.d(TAG, "An exception was caught verifying the location settings: ", e);
        }
        return false;
    }