下面列出了android.view.View.AccessibilityDelegate#org.chromium.components.location.LocationUtils 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* 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);
}
@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;
}
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();
}
/**
* 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();
}
}
/**
* 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);
}
/**
* 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);
}
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);
}
}
@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);
}
});
}
@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);
}
@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();
}
}
@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;
}
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);
}
}
@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);
}
/**
* 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();
}
/**
* 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();
}
@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;
}
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.");
}
}
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;
}
@Override
protected boolean enabledGlobally() {
return LocationUtils.getInstance().isSystemLocationSettingEnabled(
ContextUtils.getApplicationContext());
}
@Override
protected Intent getIntentToEnableOsGlobalPermission(Context context) {
if (enabledGlobally()) return null;
return LocationUtils.getInstance().getSystemLocationSettingsIntent();
}
/**
* 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.");
}
}
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;
}
@Override
protected boolean enabledGlobally() {
return LocationUtils.getInstance().isSystemLocationSettingEnabled();
}
@Override
protected Intent getIntentToEnableOsGlobalPermission(Context context) {
if (enabledGlobally()) return null;
return LocationUtils.getInstance().getSystemLocationSettingsIntent();
}
/**
* Returns true if location is enabled system-wide and the Chrome location setting is enabled.
*/
public boolean areAllLocationSettingsEnabled() {
return isChromeLocationSettingEnabled()
&& LocationUtils.getInstance().isSystemLocationSettingEnabled();
}
/**
* @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();
}
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.");
}
}
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;
}
@Override
protected boolean enabledGlobally() {
return LocationUtils.getInstance().isSystemLocationSettingEnabled();
}