Java Code Examples for org.chromium.components.location.LocationUtils#hasAndroidLocationPermission()

The following examples show how to use org.chromium.components.location.LocationUtils#hasAndroidLocationPermission() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PhysicalWeb.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Start the Physical Web feature.
 * At the moment, this only enables URL discovery over BLE.
 */
public static void startPhysicalWeb() {
    // Only subscribe to Nearby if we have the location permission.
    LocationUtils locationUtils = LocationUtils.getInstance();
    if (locationUtils.hasAndroidLocationPermission()
            && locationUtils.isSystemLocationSettingEnabled()) {
        new NearbyBackgroundSubscription(NearbySubscription.SUBSCRIBE, new Runnable() {
            @Override
            public void run() {
                // We need to clear the list of nearby URLs so that they can be repopulated by
                // the new subscription, but we don't know whether we are already subscribed, so
                // we need to pass a callback so that we can clear as soon as we are
                // resubscribed.
                UrlManager.getInstance().clearNearbyUrls();
            }
        }).run();
    }
}
 
Example 2
Source File: LocationSettings.java    From delion with Apache License 2.0 5 votes vote down vote up
@CalledByNative
private static boolean canSitesRequestLocationPermission(WebContents webContents) {
    ContentViewCore cvc = ContentViewCore.fromWebContents(webContents);
    if (cvc == null) return false;
    WindowAndroid windowAndroid = cvc.getWindowAndroid();
    if (windowAndroid == null) return false;
    Context context = windowAndroid.getApplicationContext();

    LocationUtils locationUtils = LocationUtils.getInstance();
    if (!locationUtils.isSystemLocationSettingEnabled(context)) return false;

    return locationUtils.hasAndroidLocationPermission(context)
            || windowAndroid.canRequestPermission(Manifest.permission.ACCESS_FINE_LOCATION);
}
 
Example 3
Source File: ListUrlsActivity.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
protected void onStart() {
    super.onStart();
    UrlManager.getInstance().addObserver(this);
    // Only connect so that we can subscribe to Nearby if we have the location permission.
    LocationUtils locationUtils = LocationUtils.getInstance();
    if (locationUtils.hasAndroidLocationPermission()
            && locationUtils.isSystemLocationSettingEnabled()) {
        mNearbyForegroundSubscription.connect();
    }
}
 
Example 4
Source File: LocationSettings.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@CalledByNative
private static boolean canSitesRequestLocationPermission(WebContents webContents) {
    ContentViewCore cvc = ContentViewCore.fromWebContents(webContents);
    if (cvc == null) return false;
    WindowAndroid windowAndroid = cvc.getWindowAndroid();
    if (windowAndroid == null) return false;

    LocationUtils locationUtils = LocationUtils.getInstance();
    if (!locationUtils.isSystemLocationSettingEnabled()) return false;

    return locationUtils.hasAndroidLocationPermission()
            || windowAndroid.canRequestPermission(Manifest.permission.ACCESS_FINE_LOCATION);
}
 
Example 5
Source File: PhysicalWeb.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Checks if this device should have Physical Web automatically enabled.
 */
private static boolean shouldAutoEnablePhysicalWeb() {
    LocationUtils locationUtils = LocationUtils.getInstance();
    return locationUtils.isSystemLocationSettingEnabled()
            && locationUtils.hasAndroidLocationPermission()
            && TemplateUrlService.getInstance().isDefaultSearchEngineGoogle()
            && !Profile.getLastUsedProfile().isOffTheRecord();
}
 
Example 6
Source File: PhysicalWeb.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Examines the environment in order to decide whether we should begin or end a scan.
 */
public static void updateScans() {
    LocationUtils locationUtils = LocationUtils.getInstance();
    if (!locationUtils.hasAndroidLocationPermission()
            || !locationUtils.isSystemLocationSettingEnabled()
            || !isPhysicalWebPreferenceEnabled()) {
        new NearbyBackgroundSubscription(NearbySubscription.UNSUBSCRIBE).run();
        return;
    }

    new NearbyBackgroundSubscription(NearbySubscription.SUBSCRIBE).run();
}
 
Example 7
Source File: PhysicalWebDiagnosticsPage.java    From delion with Apache License 2.0 4 votes vote down vote up
private void appendPrerequisitesReport(StringBuilder sb) {
    boolean isSdkVersionCorrect = isSdkVersionCorrect();
    boolean isDataConnectionActive = Utils.isDataConnectionActive(mContext);
    int bluetoothStatus = Utils.getBluetoothEnabledStatus(mContext);
    LocationUtils locationUtils = LocationUtils.getInstance();
    boolean isLocationServicesEnabled = locationUtils.isSystemLocationSettingEnabled(mContext);
    boolean isLocationPermissionGranted = locationUtils.hasAndroidLocationPermission(mContext);
    boolean isPreferenceEnabled = PhysicalWeb.isPhysicalWebPreferenceEnabled(mContext);
    boolean isOnboarding = PhysicalWeb.isOnboarding(mContext);

    int prerequisitesResult = Utils.RESULT_SUCCESS;
    if (!isSdkVersionCorrect
            || !isDataConnectionActive
            || bluetoothStatus == Utils.RESULT_FAILURE
            || !isLocationServicesEnabled
            || !isLocationPermissionGranted
            || !isPreferenceEnabled) {
        prerequisitesResult = Utils.RESULT_FAILURE;
    } else if (bluetoothStatus == Utils.RESULT_INDETERMINATE) {
        prerequisitesResult = Utils.RESULT_INDETERMINATE;
    }

    sb.append("<h2>Status</h2>");

    sb.append("Physical Web is ");
    appendResult(sb, prerequisitesResult != Utils.RESULT_FAILURE, "ON", "OFF");

    sb.append("<h2>Prerequisites</h2>");

    sb.append("Android SDK version: ");
    appendResult(sb, isSdkVersionCorrect, "Compatible", "Incompatible");

    sb.append("Data connection: ");
    appendResult(sb, isDataConnectionActive, "Connected", "Not connected");

    sb.append("Location services: ");
    appendResult(sb, isLocationServicesEnabled, "Enabled", "Disabled");

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        sb.append("Location app permission: ");
        appendResult(sb, isLocationPermissionGranted, "Granted", "Not granted");
    }

    sb.append("Physical Web privacy settings: ");
    String preferenceDisabledMessage = (isOnboarding ? "Default (off)" : "Off");
    appendResult(sb, isPreferenceEnabled, "On", preferenceDisabledMessage);

    sb.append("Bluetooth: ");
    appendResult(sb, bluetoothStatus, "Enabled", "Disabled", "Unknown");

    // Append instructions for how to verify Bluetooth is enabled when we are unable to check
    // programmatically.
    if (bluetoothStatus == Utils.RESULT_INDETERMINATE) {
        sb.append("<br/>To verify Bluetooth is enabled on this device, check that the "
                + "Bluetooth icon is shown in the status bar.");
    }
}
 
Example 8
Source File: PhysicalWebDiagnosticsPage.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
private void appendPrerequisitesReport(StringBuilder sb) {
    boolean isSdkVersionCorrect = isSdkVersionCorrect();
    boolean isDataConnectionActive = Utils.isDataConnectionActive();
    int bluetoothStatus = Utils.getBluetoothEnabledStatus();
    LocationUtils locationUtils = LocationUtils.getInstance();
    boolean isLocationServicesEnabled = locationUtils.isSystemLocationSettingEnabled();
    boolean isLocationPermissionGranted = locationUtils.hasAndroidLocationPermission();
    boolean isPreferenceEnabled = PhysicalWeb.isPhysicalWebPreferenceEnabled();
    boolean isOnboarding = PhysicalWeb.isOnboarding();

    int prerequisitesResult = Utils.RESULT_SUCCESS;
    if (!isSdkVersionCorrect
            || !isDataConnectionActive
            || bluetoothStatus == Utils.RESULT_FAILURE
            || !isLocationServicesEnabled
            || !isLocationPermissionGranted
            || !isPreferenceEnabled) {
        prerequisitesResult = Utils.RESULT_FAILURE;
        mLaunchButton.setEnabled(false);
    } else if (bluetoothStatus == Utils.RESULT_INDETERMINATE) {
        prerequisitesResult = Utils.RESULT_INDETERMINATE;
        mLaunchButton.setEnabled(false);
    }

    sb.append("<h2>Status</h2>");

    sb.append("Physical Web is ");
    appendResult(sb, prerequisitesResult != Utils.RESULT_FAILURE, "ON", "OFF");

    sb.append("<h2>Prerequisites</h2>");

    sb.append("Android SDK version: ");
    appendResult(sb, isSdkVersionCorrect, "Compatible", "Incompatible");

    sb.append("Data connection: ");
    appendResult(sb, isDataConnectionActive, "Connected", "Not connected");

    sb.append("Location services: ");
    appendResult(sb, isLocationServicesEnabled, "Enabled", "Disabled");

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        sb.append("Location app permission: ");
        appendResult(sb, isLocationPermissionGranted, "Granted", "Not granted");
    }

    sb.append("Physical Web privacy settings: ");
    String preferenceDisabledMessage = (isOnboarding ? "Default (off)" : "Off");
    appendResult(sb, isPreferenceEnabled, "On", preferenceDisabledMessage);

    sb.append("Bluetooth: ");
    appendResult(sb, bluetoothStatus, "Enabled", "Disabled", "Unknown");

    // Append instructions for how to verify Bluetooth is enabled when we are unable to check
    // programmatically.
    if (bluetoothStatus == Utils.RESULT_INDETERMINATE) {
        sb.append("<br/>To verify Bluetooth is enabled on this device, check that the "
                + "Bluetooth icon is shown in the status bar.");
    }
}
 
Example 9
Source File: ChromeBluetoothAdapter.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * @return true if Chromium has permission to scan for Bluetooth devices and location services
 * are on.
 */
private boolean canScan() {
    LocationUtils locationUtils = LocationUtils.getInstance();
    return locationUtils.hasAndroidLocationPermission()
            && locationUtils.isSystemLocationSettingEnabled();
}
 
Example 10
Source File: PhysicalWebDiagnosticsPage.java    From 365browser with Apache License 2.0 4 votes vote down vote up
private void appendPrerequisitesReport(StringBuilder sb) {
    boolean isSdkVersionCorrect = isSdkVersionCorrect();
    boolean isDataConnectionActive = Utils.isDataConnectionActive();
    int bluetoothStatus = Utils.getBluetoothEnabledStatus();
    LocationUtils locationUtils = LocationUtils.getInstance();
    boolean isLocationServicesEnabled = locationUtils.isSystemLocationSettingEnabled();
    boolean isLocationPermissionGranted = locationUtils.hasAndroidLocationPermission();
    boolean isPreferenceEnabled = PhysicalWeb.isPhysicalWebPreferenceEnabled();
    boolean isOnboarding = PhysicalWeb.isOnboarding();

    int prerequisitesResult = Utils.RESULT_SUCCESS;
    if (!isSdkVersionCorrect
            || !isDataConnectionActive
            || bluetoothStatus == Utils.RESULT_FAILURE
            || !isLocationServicesEnabled
            || !isLocationPermissionGranted
            || !isPreferenceEnabled) {
        prerequisitesResult = Utils.RESULT_FAILURE;
        mLaunchButton.setEnabled(false);
    } else if (bluetoothStatus == Utils.RESULT_INDETERMINATE) {
        prerequisitesResult = Utils.RESULT_INDETERMINATE;
        mLaunchButton.setEnabled(false);
    }

    sb.append("<h2>Status</h2>");

    sb.append("Physical Web is ");
    appendResult(sb, prerequisitesResult != Utils.RESULT_FAILURE, "ON", "OFF");

    sb.append("<h2>Prerequisites</h2>");

    sb.append("Android SDK version: ");
    appendResult(sb, isSdkVersionCorrect, "Compatible", "Incompatible");

    sb.append("Data connection: ");
    appendResult(sb, isDataConnectionActive, "Connected", "Not connected");

    sb.append("Location services: ");
    appendResult(sb, isLocationServicesEnabled, "Enabled", "Disabled");

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        sb.append("Location app permission: ");
        appendResult(sb, isLocationPermissionGranted, "Granted", "Not granted");
    }

    sb.append("Physical Web privacy settings: ");
    String preferenceDisabledMessage = (isOnboarding ? "Default (off)" : "Off");
    appendResult(sb, isPreferenceEnabled, "On", preferenceDisabledMessage);

    sb.append("Bluetooth: ");
    appendResult(sb, bluetoothStatus, "Enabled", "Disabled", "Unknown");

    // Append instructions for how to verify Bluetooth is enabled when we are unable to check
    // programmatically.
    if (bluetoothStatus == Utils.RESULT_INDETERMINATE) {
        sb.append("<br/>To verify Bluetooth is enabled on this device, check that the "
                + "Bluetooth icon is shown in the status bar.");
    }
}