org.chromium.components.location.LocationUtils Java Examples

The following examples show how to use org.chromium.components.location.LocationUtils. 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: PhysicalWebUma.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Calculate a Physical Web state.
 * The Physical Web state includes:
 * - The location provider
 * - The location permission
 * - The bluetooth status
 * - The data connection status
 * - The Physical Web preference status
 */
public static void recordPhysicalWebState(Context context, String actionName) {
    LocationUtils locationUtils = LocationUtils.getInstance();
    handleEnum(context, createStateString(LOCATION_SERVICES, actionName),
            locationUtils.isSystemLocationSettingEnabled(context) ? 1 : 0, BOOLEAN_BOUNDARY);
    handleEnum(context, createStateString(LOCATION_PERMISSION, actionName),
            locationUtils.hasAndroidLocationPermission(context) ? 1 : 0, BOOLEAN_BOUNDARY);
    handleEnum(context, createStateString(BLUETOOTH, actionName),
            Utils.getBluetoothEnabledStatus(context), TRISTATE_BOUNDARY);
    handleEnum(context, createStateString(DATA_CONNECTION, actionName),
            Utils.isDataConnectionActive(context) ? 1 : 0, BOOLEAN_BOUNDARY);
    int preferenceState = 2;
    if (!PhysicalWeb.isOnboarding(context)) {
        preferenceState = PhysicalWeb.isPhysicalWebPreferenceEnabled(context) ? 1 : 0;
    }
    handleEnum(context, createStateString(PREFERENCE, actionName),
            preferenceState, TRISTATE_BOUNDARY);
}
 
Example #2
Source File: LocationSettings.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@CalledByNative
private static void promptToEnableSystemLocationSetting(
        @LocationSettingsDialogContext int promptContext, WebContents webContents,
        final long nativeCallback) {
    WindowAndroid window = webContents.getTopLevelNativeWindow();
    if (window == null) {
        nativeOnLocationSettingsDialogOutcome(
                nativeCallback, LocationSettingsDialogOutcome.NO_PROMPT);
        return;
    }
    LocationUtils.getInstance().promptToEnableSystemLocationSetting(
            promptContext, window, new Callback<Integer>() {
                @Override
                public void onResult(Integer result) {
                    nativeOnLocationSettingsDialogOutcome(nativeCallback, result);
                }
            });
}
 
Example #3
Source File: BluetoothChooserDialog.java    From delion with Apache License 2.0 6 votes vote down vote up
@CalledByNative
private static BluetoothChooserDialog create(WindowAndroid windowAndroid, String origin,
        int securityLevel, long nativeBluetoothChooserDialogPtr) {
    if (!LocationUtils.getInstance().hasAndroidLocationPermission(
                windowAndroid.getActivity().get())
            && !windowAndroid.canRequestPermission(
                       Manifest.permission.ACCESS_COARSE_LOCATION)) {
        // If we can't even ask for enough permission to scan for Bluetooth devices, don't open
        // the dialog.
        return null;
    }
    BluetoothChooserDialog dialog = new BluetoothChooserDialog(
            windowAndroid, origin, securityLevel, nativeBluetoothChooserDialogPtr);
    dialog.show();
    return dialog;
}
 
Example #4
Source File: SearchEngineAdapter.java    From 365browser with Apache License 2.0 6 votes vote down vote up
private void onLocationLinkClicked() {
    mIsLocationPermissionChanged = true;
    if (!LocationUtils.getInstance().isSystemLocationSettingEnabled()) {
        mContext.startActivity(LocationUtils.getInstance().getSystemLocationSettingsIntent());
    } else {
        Intent settingsIntent = PreferencesLauncher.createIntentForSettingsPage(
                mContext, SingleWebsitePreferences.class.getName());
        String url = TemplateUrlService.getInstance().getSearchEngineUrlFromTemplateUrl(
                toKeyword(mSelectedSearchEnginePosition));
        Bundle fragmentArgs = SingleWebsitePreferences.createFragmentArgsForSite(url);
        fragmentArgs.putBoolean(SingleWebsitePreferences.EXTRA_LOCATION,
                locationEnabled((TemplateUrl) getItem(mSelectedSearchEnginePosition)));
        settingsIntent.putExtra(Preferences.EXTRA_SHOW_FRAGMENT_ARGUMENTS, fragmentArgs);
        mContext.startActivity(settingsIntent);
    }
}
 
Example #5
Source File: SearchEngineAdapter.java    From delion with Apache License 2.0 6 votes vote down vote up
private void onLocationLinkClicked() {
    if (!LocationUtils.getInstance().isSystemLocationSettingEnabled(mContext)) {
        mContext.startActivity(LocationUtils.getInstance().getSystemLocationSettingsIntent());
    } else {
        Intent settingsIntent = PreferencesLauncher.createIntentForSettingsPage(
                mContext, SingleWebsitePreferences.class.getName());
        String url = TemplateUrlService.getInstance().getSearchEngineUrlFromTemplateUrl(
                toIndex(mSelectedSearchEnginePosition));
        Bundle fragmentArgs = SingleWebsitePreferences.createFragmentArgsForSite(url);
        fragmentArgs.putBoolean(SingleWebsitePreferences.EXTRA_LOCATION,
                locationEnabled(mSelectedSearchEnginePosition, true));
        settingsIntent.putExtra(Preferences.EXTRA_SHOW_FRAGMENT_ARGUMENTS, fragmentArgs);
        mContext.startActivity(settingsIntent);
    }
    mCallback.onDismissDialog();
}
 
Example #6
Source File: PhysicalWebUma.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Calculate a Physical Web state.
 * The Physical Web state includes:
 * - The location provider
 * - The location permission
 * - The bluetooth status
 * - The data connection status
 * - The Physical Web preference status
 */
public static void recordPhysicalWebState(String actionName) {
    LocationUtils locationUtils = LocationUtils.getInstance();
    handleEnum(createStateString(LOCATION_SERVICES, actionName),
            locationUtils.isSystemLocationSettingEnabled() ? 1 : 0, BOOLEAN_BOUNDARY);
    handleEnum(createStateString(LOCATION_PERMISSION, actionName),
            locationUtils.hasAndroidLocationPermission() ? 1 : 0, BOOLEAN_BOUNDARY);
    handleEnum(createStateString(BLUETOOTH, actionName),
            Utils.getBluetoothEnabledStatus(), TRISTATE_BOUNDARY);
    handleEnum(createStateString(DATA_CONNECTION, actionName),
            Utils.isDataConnectionActive() ? 1 : 0, BOOLEAN_BOUNDARY);
    int preferenceState = 2;
    if (!PhysicalWeb.isOnboarding()) {
        preferenceState = PhysicalWeb.isPhysicalWebPreferenceEnabled() ? 1 : 0;
    }
    handleEnum(createStateString(PREFERENCE, actionName),
            preferenceState, TRISTATE_BOUNDARY);
}
 
Example #7
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 #8
Source File: PhysicalWebUma.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Calculate a Physical Web state.
 * The Physical Web state includes:
 * - The location provider
 * - The location permission
 * - The bluetooth status
 * - The data connection status
 * - The Physical Web preference status
 */
public static void recordPhysicalWebState(Context context, String actionName) {
    LocationUtils locationUtils = LocationUtils.getInstance();
    handleEnum(context, createStateString(LOCATION_SERVICES, actionName),
            locationUtils.isSystemLocationSettingEnabled() ? 1 : 0, BOOLEAN_BOUNDARY);
    handleEnum(context, createStateString(LOCATION_PERMISSION, actionName),
            locationUtils.hasAndroidLocationPermission() ? 1 : 0, BOOLEAN_BOUNDARY);
    handleEnum(context, createStateString(BLUETOOTH, actionName),
            Utils.getBluetoothEnabledStatus(), TRISTATE_BOUNDARY);
    handleEnum(context, createStateString(DATA_CONNECTION, actionName),
            Utils.isDataConnectionActive() ? 1 : 0, BOOLEAN_BOUNDARY);
    int preferenceState = 2;
    if (!PhysicalWeb.isOnboarding()) {
        preferenceState = PhysicalWeb.isPhysicalWebPreferenceEnabled() ? 1 : 0;
    }
    handleEnum(context, createStateString(PREFERENCE, actionName),
            preferenceState, TRISTATE_BOUNDARY);
}
 
Example #9
Source File: SearchEngineAdapter.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
private void onLocationLinkClicked() {
    if (!LocationUtils.getInstance().isSystemLocationSettingEnabled()) {
        mContext.startActivity(LocationUtils.getInstance().getSystemLocationSettingsIntent());
    } else {
        Intent settingsIntent = PreferencesLauncher.createIntentForSettingsPage(
                mContext, SingleWebsitePreferences.class.getName());
        String url = TemplateUrlService.getInstance().getSearchEngineUrlFromTemplateUrl(
                toIndex(mSelectedSearchEnginePosition));
        Bundle fragmentArgs = SingleWebsitePreferences.createFragmentArgsForSite(url);
        fragmentArgs.putBoolean(SingleWebsitePreferences.EXTRA_LOCATION,
                locationEnabled(mSelectedSearchEnginePosition, true));
        settingsIntent.putExtra(Preferences.EXTRA_SHOW_FRAGMENT_ARGUMENTS, fragmentArgs);
        mContext.startActivity(settingsIntent);
    }
}
 
Example #10
Source File: BluetoothChooserDialog.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@CalledByNative
private static BluetoothChooserDialog create(WindowAndroid windowAndroid, String origin,
        int securityLevel, long nativeBluetoothChooserDialogPtr) {
    if (!LocationUtils.getInstance().hasAndroidLocationPermission()
            && !windowAndroid.canRequestPermission(
                       Manifest.permission.ACCESS_COARSE_LOCATION)) {
        // If we can't even ask for enough permission to scan for Bluetooth devices, don't open
        // the dialog.
        return null;
    }
    BluetoothChooserDialog dialog = new BluetoothChooserDialog(
            windowAndroid, origin, securityLevel, nativeBluetoothChooserDialogPtr);
    dialog.show();
    return dialog;
}
 
Example #11
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 #12
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 #13
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 #14
Source File: BluetoothChooserDialog.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@CalledByNative
private static BluetoothChooserDialog create(WindowAndroid windowAndroid, String origin,
        int securityLevel, long nativeBluetoothChooserDialogPtr) {
    if (!LocationUtils.getInstance().hasAndroidLocationPermission()
            && !windowAndroid.canRequestPermission(
                       Manifest.permission.ACCESS_COARSE_LOCATION)) {
        // If we can't even ask for enough permission to scan for Bluetooth devices, don't open
        // the dialog.
        return null;
    }
    BluetoothChooserDialog dialog = new BluetoothChooserDialog(
            windowAndroid, origin, securityLevel, nativeBluetoothChooserDialogPtr);
    dialog.show();
    return dialog;
}
 
Example #15
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 #16
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 #17
Source File: LocationSettings.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * Returns true if location is enabled system-wide and the Chrome location setting is enabled.
 */
public boolean areAllLocationSettingsEnabled() {
    return isChromeLocationSettingEnabled()
            && LocationUtils.getInstance().isSystemLocationSettingEnabled();
}
 
Example #18
Source File: BluetoothChooserDialog.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
private boolean checkLocationServicesAndPermission() {
    final boolean havePermission = LocationUtils.getInstance().hasAndroidLocationPermission();
    final boolean locationServicesOn =
            LocationUtils.getInstance().isSystemLocationSettingEnabled();

    if (!havePermission
            && !mWindowAndroid.canRequestPermission(
                       Manifest.permission.ACCESS_COARSE_LOCATION)) {
        // Immediately close the dialog because the user has asked Chrome not to request the
        // location permission.
        finishDialog(DIALOG_FINISHED_DENIED_PERMISSION, "");
        return false;
    }

    // Compute the message to show the user.
    final SpanInfo permissionSpan = new SpanInfo("<permission_link>", "</permission_link>",
            new BluetoothClickableSpan(LinkType.REQUEST_LOCATION_PERMISSION, mActivity));
    final SpanInfo servicesSpan = new SpanInfo("<services_link>", "</services_link>",
            new BluetoothClickableSpan(LinkType.REQUEST_LOCATION_SERVICES, mActivity));
    final SpannableString needLocationMessage;
    if (havePermission) {
        if (locationServicesOn) {
            // We don't need to request anything.
            return true;
        } else {
            needLocationMessage = SpanApplier.applySpans(
                    mActivity.getString(R.string.bluetooth_need_location_services_on),
                    servicesSpan);
        }
    } else {
        if (locationServicesOn) {
            needLocationMessage = SpanApplier.applySpans(
                    mActivity.getString(R.string.bluetooth_need_location_permission),
                    permissionSpan);
        } else {
            needLocationMessage = SpanApplier.applySpans(
                    mActivity.getString(
                            R.string.bluetooth_need_location_permission_and_services_on),
                    permissionSpan, servicesSpan);
        }
    }

    SpannableString needLocationStatus = SpanApplier.applySpans(
            mActivity.getString(R.string.bluetooth_need_location_permission_help),
            new SpanInfo("<link>", "</link>",
                    new BluetoothClickableSpan(
                                 LinkType.NEED_LOCATION_PERMISSION_HELP, mActivity)));

    mItemChooserDialog.setErrorState(needLocationMessage, needLocationStatus);
    return false;
}
 
Example #19
Source File: BluetoothChooserDialog.java    From delion with Apache License 2.0 4 votes vote down vote up
private boolean checkLocationServicesAndPermission() {
    final boolean havePermission =
            LocationUtils.getInstance().hasAndroidLocationPermission(mActivity);
    final boolean locationServicesOn =
            LocationUtils.getInstance().isSystemLocationSettingEnabled(mActivity);

    if (!havePermission
            && !mWindowAndroid.canRequestPermission(
                       Manifest.permission.ACCESS_COARSE_LOCATION)) {
        // Immediately close the dialog because the user has asked Chrome not to request the
        // location permission.
        finishDialog(DIALOG_FINISHED_DENIED_PERMISSION, "");
        return false;
    }

    // Compute the message to show the user.
    final SpanInfo permissionSpan = new SpanInfo("<permission_link>", "</permission_link>",
            new BluetoothClickableSpan(LinkType.REQUEST_LOCATION_PERMISSION, mActivity));
    final SpanInfo servicesSpan = new SpanInfo("<services_link>", "</services_link>",
            new BluetoothClickableSpan(LinkType.REQUEST_LOCATION_SERVICES, mActivity));
    final SpannableString needLocationMessage;
    if (havePermission) {
        if (locationServicesOn) {
            // We don't need to request anything.
            return true;
        } else {
            needLocationMessage = SpanApplier.applySpans(
                    mActivity.getString(R.string.bluetooth_need_location_services_on),
                    servicesSpan);
        }
    } else {
        if (locationServicesOn) {
            needLocationMessage = SpanApplier.applySpans(
                    mActivity.getString(R.string.bluetooth_need_location_permission),
                    permissionSpan);
        } else {
            needLocationMessage = SpanApplier.applySpans(
                    mActivity.getString(
                            R.string.bluetooth_need_location_permission_and_services_on),
                    permissionSpan, servicesSpan);
        }
    }

    SpannableString needLocationStatus = SpanApplier.applySpans(
            mActivity.getString(R.string.bluetooth_need_location_permission_help),
            new SpanInfo("<link>", "</link>",
                    new BluetoothClickableSpan(
                                 LinkType.NEED_LOCATION_PERMISSION_HELP, mActivity)));

    mItemChooserDialog.setErrorState(needLocationMessage, needLocationStatus);
    return false;
}
 
Example #20
Source File: LocationSettings.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@CalledByNative
private static boolean canPromptToEnableSystemLocationSetting() {
    return LocationUtils.getInstance().canPromptToEnableSystemLocationSetting();
}
 
Example #21
Source File: LocationSettings.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@CalledByNative
private static boolean isSystemLocationSettingEnabled() {
    return LocationUtils.getInstance().isSystemLocationSettingEnabled();
}
 
Example #22
Source File: LocationSettings.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@CalledByNative
private static boolean hasAndroidLocationPermission() {
    return LocationUtils.getInstance().hasAndroidLocationPermission();
}
 
Example #23
Source File: LocationCategory.java    From delion with Apache License 2.0 4 votes vote down vote up
@Override
protected boolean enabledGlobally() {
    return LocationUtils.getInstance().isSystemLocationSettingEnabled(
            ContextUtils.getApplicationContext());
}
 
Example #24
Source File: LocationCategory.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@Override
protected Intent getIntentToEnableOsGlobalPermission(Context context) {
    if (enabledGlobally()) return null;
    return LocationUtils.getInstance().getSystemLocationSettingsIntent();
}
 
Example #25
Source File: LocationCategory.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@Override
protected boolean enabledGlobally() {
    return LocationUtils.getInstance().isSystemLocationSettingEnabled();
}
 
Example #26
Source File: LocationCategory.java    From delion with Apache License 2.0 4 votes vote down vote up
@Override
protected Intent getIntentToEnableOsGlobalPermission(Context context) {
    if (enabledGlobally()) return null;
    return LocationUtils.getInstance().getSystemLocationSettingsIntent();
}
 
Example #27
Source File: BluetoothChooserDialog.java    From 365browser with Apache License 2.0 4 votes vote down vote up
private boolean checkLocationServicesAndPermission() {
    final boolean havePermission = LocationUtils.getInstance().hasAndroidLocationPermission();
    final boolean locationServicesOn =
            LocationUtils.getInstance().isSystemLocationSettingEnabled();

    if (!havePermission
            && !mWindowAndroid.canRequestPermission(
                       Manifest.permission.ACCESS_COARSE_LOCATION)) {
        // Immediately close the dialog because the user has asked Chrome not to request the
        // location permission.
        finishDialog(DIALOG_FINISHED_DENIED_PERMISSION, "");
        return false;
    }

    // Compute the message to show the user.
    final SpanInfo permissionSpan = new SpanInfo("<permission_link>", "</permission_link>",
            new BluetoothClickableSpan(LinkType.REQUEST_LOCATION_PERMISSION, mActivity));
    final SpanInfo servicesSpan = new SpanInfo("<services_link>", "</services_link>",
            new BluetoothClickableSpan(LinkType.REQUEST_LOCATION_SERVICES, mActivity));
    final SpannableString needLocationMessage;
    if (havePermission) {
        if (locationServicesOn) {
            // We don't need to request anything.
            return true;
        } else {
            needLocationMessage = SpanApplier.applySpans(
                    mActivity.getString(R.string.bluetooth_need_location_services_on),
                    servicesSpan);
        }
    } else {
        if (locationServicesOn) {
            needLocationMessage = SpanApplier.applySpans(
                    mActivity.getString(R.string.bluetooth_need_location_permission),
                    permissionSpan);
        } else {
            needLocationMessage = SpanApplier.applySpans(
                    mActivity.getString(
                            R.string.bluetooth_need_location_permission_and_services_on),
                    permissionSpan, servicesSpan);
        }
    }

    SpannableString needLocationStatus = SpanApplier.applySpans(
            mActivity.getString(R.string.bluetooth_need_location_permission_help),
            new SpanInfo("<link>", "</link>",
                    new BluetoothClickableSpan(
                                 LinkType.NEED_LOCATION_PERMISSION_HELP, mActivity)));

    mItemChooserDialog.setErrorState(needLocationMessage, needLocationStatus);
    return false;
}
 
Example #28
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.");
    }
}
 
Example #29
Source File: LocationSettings.java    From delion with Apache License 2.0 4 votes vote down vote up
/**
 * Returns true if location is enabled system-wide and the Chrome location setting is enabled.
 */
public boolean areAllLocationSettingsEnabled() {
    return isChromeLocationSettingEnabled()
            && LocationUtils.getInstance().isSystemLocationSettingEnabled(mContext);
}
 
Example #30
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.");
    }
}