Search in sources :

Example 1 with LocationUtils

use of org.chromium.components.location.LocationUtils in project AndroidChromium by JackyAndroid.

the class ListUrlsActivity method onStart.

@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();
    }
}
Also used : LocationUtils(org.chromium.components.location.LocationUtils)

Example 2 with LocationUtils

use of org.chromium.components.location.LocationUtils in project AndroidChromium by JackyAndroid.

the class PhysicalWebDiagnosticsPage method appendPrerequisitesReport.

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;
    } 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");
    // 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.");
    }
}
Also used : LocationUtils(org.chromium.components.location.LocationUtils)

Example 3 with LocationUtils

use of org.chromium.components.location.LocationUtils in project AndroidChromium by JackyAndroid.

the class PhysicalWebUma method recordPhysicalWebState.

/**
     * 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);
}
Also used : LocationUtils(org.chromium.components.location.LocationUtils)

Example 4 with LocationUtils

use of org.chromium.components.location.LocationUtils in project AndroidChromium by JackyAndroid.

the class LocationSettings method canSitesRequestLocationPermission.

@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);
}
Also used : LocationUtils(org.chromium.components.location.LocationUtils) ContentViewCore(org.chromium.content.browser.ContentViewCore) WindowAndroid(org.chromium.ui.base.WindowAndroid) CalledByNative(org.chromium.base.annotations.CalledByNative)

Example 5 with LocationUtils

use of org.chromium.components.location.LocationUtils in project AndroidChromium by JackyAndroid.

the class WebsiteSettingsPopup method addReadOnlyPermissionSection.

private void addReadOnlyPermissionSection(PageInfoPermissionEntry permission) {
    View permissionRow = LayoutInflater.from(mContext).inflate(R.layout.website_settings_permission_row, null);
    ImageView permissionIcon = (ImageView) permissionRow.findViewById(R.id.website_settings_permission_icon);
    permissionIcon.setImageResource(getImageResourceForPermission(permission.type));
    if (permission.setting == ContentSetting.ALLOW) {
        int warningTextResource = 0;
        // If warningTextResource is non-zero, then the view must be tagged with either
        // permission_intent_override or permission_type.
        LocationUtils locationUtils = LocationUtils.getInstance();
        if (permission.type == ContentSettingsType.CONTENT_SETTINGS_TYPE_GEOLOCATION && !locationUtils.isSystemLocationSettingEnabled()) {
            warningTextResource = R.string.page_info_android_location_blocked;
            permissionRow.setTag(R.id.permission_intent_override, locationUtils.getSystemLocationSettingsIntent());
        } else if (!hasAndroidPermission(permission.type)) {
            warningTextResource = R.string.page_info_android_permission_blocked;
            permissionRow.setTag(R.id.permission_type, PrefServiceBridge.getAndroidPermissionForContentSetting(permission.type));
        }
        if (warningTextResource != 0) {
            TextView permissionUnavailable = (TextView) permissionRow.findViewById(R.id.website_settings_permission_unavailable_message);
            permissionUnavailable.setVisibility(View.VISIBLE);
            permissionUnavailable.setText(warningTextResource);
            permissionIcon.setImageResource(R.drawable.exclamation_triangle);
            permissionIcon.setColorFilter(ApiCompatibilityUtils.getColor(mContext.getResources(), R.color.website_settings_popup_text_link));
            permissionRow.setOnClickListener(this);
        }
    }
    TextView permissionStatus = (TextView) permissionRow.findViewById(R.id.website_settings_permission_status);
    SpannableStringBuilder builder = new SpannableStringBuilder();
    SpannableString nameString = new SpannableString(permission.name);
    final StyleSpan boldSpan = new StyleSpan(android.graphics.Typeface.BOLD);
    nameString.setSpan(boldSpan, 0, nameString.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
    builder.append(nameString);
    // en-dash.
    builder.append(" – ");
    String status_text = "";
    switch(permission.setting) {
        case ALLOW:
            status_text = mContext.getString(R.string.page_info_permission_allowed);
            break;
        case BLOCK:
            status_text = mContext.getString(R.string.page_info_permission_blocked);
            break;
        default:
            assert false : "Invalid setting " + permission.setting + " for permission " + permission.type;
    }
    builder.append(status_text);
    permissionStatus.setText(builder);
    mPermissionsList.addView(permissionRow);
}
Also used : LocationUtils(org.chromium.components.location.LocationUtils) SpannableString(android.text.SpannableString) StyleSpan(android.text.style.StyleSpan) TextView(android.widget.TextView) AppCompatTextView(android.support.v7.widget.AppCompatTextView) ImageView(android.widget.ImageView) SpannableString(android.text.SpannableString) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) AppCompatTextView(android.support.v7.widget.AppCompatTextView) ScrollView(android.widget.ScrollView) SpannableStringBuilder(android.text.SpannableStringBuilder)

Aggregations

LocationUtils (org.chromium.components.location.LocationUtils)5 AppCompatTextView (android.support.v7.widget.AppCompatTextView)1 SpannableString (android.text.SpannableString)1 SpannableStringBuilder (android.text.SpannableStringBuilder)1 StyleSpan (android.text.style.StyleSpan)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 ScrollView (android.widget.ScrollView)1 TextView (android.widget.TextView)1 CalledByNative (org.chromium.base.annotations.CalledByNative)1 ContentViewCore (org.chromium.content.browser.ContentViewCore)1 WindowAndroid (org.chromium.ui.base.WindowAndroid)1