android.view.View.AccessibilityDelegate#org.chromium.components.location.LocationUtils源码实例Demo

下面列出了android.view.View.AccessibilityDelegate#org.chromium.components.location.LocationUtils 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: delion   文件: PhysicalWebUma.java
/**
 * 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);
}
 
源代码2 项目: delion   文件: BluetoothChooserDialog.java
@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;
}
 
源代码3 项目: delion   文件: SearchEngineAdapter.java
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();
}
 
源代码4 项目: AndroidChromium   文件: PhysicalWeb.java
/**
 * 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();
    }
}
 
源代码5 项目: AndroidChromium   文件: PhysicalWebUma.java
/**
 * 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);
}
 
源代码6 项目: 365browser   文件: PhysicalWebUma.java
/**
 * 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);
}
 
源代码7 项目: 365browser   文件: SearchEngineAdapter.java
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);
    }
}
 
源代码8 项目: 365browser   文件: LocationSettings.java
@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);
                }
            });
}
 
源代码9 项目: delion   文件: LocationSettings.java
@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);
}
 
源代码10 项目: AndroidChromium   文件: ListUrlsActivity.java
@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();
    }
}
 
源代码11 项目: AndroidChromium   文件: BluetoothChooserDialog.java
@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;
}
 
源代码12 项目: AndroidChromium   文件: SearchEngineAdapter.java
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);
    }
}
 
源代码13 项目: AndroidChromium   文件: LocationSettings.java
@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);
}
 
源代码14 项目: 365browser   文件: PhysicalWeb.java
/**
 * 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();
}
 
源代码15 项目: 365browser   文件: PhysicalWeb.java
/**
 * 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();
}
 
源代码16 项目: 365browser   文件: BluetoothChooserDialog.java
@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;
}
 
源代码17 项目: delion   文件: PhysicalWebDiagnosticsPage.java
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.");
    }
}
 
源代码18 项目: delion   文件: BluetoothChooserDialog.java
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;
}
 
源代码19 项目: delion   文件: LocationCategory.java
@Override
protected boolean enabledGlobally() {
    return LocationUtils.getInstance().isSystemLocationSettingEnabled(
            ContextUtils.getApplicationContext());
}
 
源代码20 项目: delion   文件: LocationCategory.java
@Override
protected Intent getIntentToEnableOsGlobalPermission(Context context) {
    if (enabledGlobally()) return null;
    return LocationUtils.getInstance().getSystemLocationSettingsIntent();
}
 
源代码21 项目: delion   文件: LocationSettings.java
/**
 * Returns true if location is enabled system-wide and the Chrome location setting is enabled.
 */
public boolean areAllLocationSettingsEnabled() {
    return isChromeLocationSettingEnabled()
            && LocationUtils.getInstance().isSystemLocationSettingEnabled(mContext);
}
 
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.");
    }
}
 
源代码23 项目: AndroidChromium   文件: BluetoothChooserDialog.java
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;
}
 
源代码24 项目: AndroidChromium   文件: LocationCategory.java
@Override
protected boolean enabledGlobally() {
    return LocationUtils.getInstance().isSystemLocationSettingEnabled();
}
 
源代码25 项目: AndroidChromium   文件: LocationCategory.java
@Override
protected Intent getIntentToEnableOsGlobalPermission(Context context) {
    if (enabledGlobally()) return null;
    return LocationUtils.getInstance().getSystemLocationSettingsIntent();
}
 
源代码26 项目: AndroidChromium   文件: LocationSettings.java
/**
 * Returns true if location is enabled system-wide and the Chrome location setting is enabled.
 */
public boolean areAllLocationSettingsEnabled() {
    return isChromeLocationSettingEnabled()
            && LocationUtils.getInstance().isSystemLocationSettingEnabled();
}
 
源代码27 项目: 365browser   文件: ChromeBluetoothAdapter.java
/**
 * @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();
}
 
源代码28 项目: 365browser   文件: PhysicalWebDiagnosticsPage.java
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.");
    }
}
 
源代码29 项目: 365browser   文件: BluetoothChooserDialog.java
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;
}
 
源代码30 项目: 365browser   文件: LocationCategory.java
@Override
protected boolean enabledGlobally() {
    return LocationUtils.getInstance().isSystemLocationSettingEnabled();
}