Java Code Examples for org.chromium.base.PackageUtils

The following examples show how to use org.chromium.base.PackageUtils. These examples are extracted from open source projects. 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 Project: delion   Source File: ExternalDataUseObserver.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Checks if the control app is installed or uninstalled and notifies {@link
 * #ExternalDataUseObserverBridge} if there is change of installation state.
 */
private void checkAndNotifyPackageInstallState() {
    // Check if native object is destroyed. This may happen at the time of Chromium
    // shutdown.
    if (mNativeExternalDataUseObserverBridge == 0) {
        return;
    }
    if (TextUtils.isEmpty(mControlAppPackageName)) {
        return;
    }
    boolean isControlAppInstalled =
            PackageUtils.getPackageVersion(
                    ContextUtils.getApplicationContext(), mControlAppPackageName)
            != -1;
    if (isControlAppInstalled != mInstalled) {
        mInstalled = isControlAppInstalled;
        nativeOnControlAppInstallStateChange(
                mNativeExternalDataUseObserverBridge, mInstalled);
    }
}
 
Example 2
Source Project: AndroidChromium   Source File: ExternalDataUseObserver.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Checks if the control app is installed or uninstalled and notifies {@link
 * #ExternalDataUseObserverBridge} if there is change of installation state.
 */
private void checkAndNotifyPackageInstallState() {
    // Check if native object is destroyed. This may happen at the time of Chromium
    // shutdown.
    if (mNativeExternalDataUseObserverBridge == 0) {
        return;
    }
    if (TextUtils.isEmpty(mControlAppPackageName)) {
        return;
    }
    boolean isControlAppInstalled =
            PackageUtils.getPackageVersion(
                    ContextUtils.getApplicationContext(), mControlAppPackageName)
            != -1;
    if (isControlAppInstalled != mInstalled) {
        mInstalled = isControlAppInstalled;
        nativeOnControlAppInstallStateChange(
                mNativeExternalDataUseObserverBridge, mInstalled);
    }
}
 
Example 3
Source Project: 365browser   Source File: ExternalDataUseObserver.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Checks if the control app is installed or uninstalled and notifies {@link
 * #ExternalDataUseObserverBridge} if there is change of installation state.
 */
private void checkAndNotifyPackageInstallState() {
    // Check if native object is destroyed. This may happen at the time of Chromium
    // shutdown.
    if (mNativeExternalDataUseObserverBridge == 0) {
        return;
    }
    if (TextUtils.isEmpty(mControlAppPackageName)) {
        return;
    }
    boolean isControlAppInstalled =
            PackageUtils.getPackageVersion(
                    ContextUtils.getApplicationContext(), mControlAppPackageName)
            != -1;
    if (isControlAppInstalled != mInstalled) {
        mInstalled = isControlAppInstalled;
        nativeOnControlAppInstallStateChange(
                mNativeExternalDataUseObserverBridge, mInstalled);
    }
}
 
Example 4
Source Project: 365browser   Source File: LGEmailActionModeWorkaround.java    License: Apache License 2.0 6 votes vote down vote up
private static boolean shouldAllowActionModeDestroyOnNonUiThread(Context context) {
    String appName = context.getPackageName();
    int versionCode = PackageUtils.getPackageVersion(context, appName);
    int appTargetSdkVersion = context.getApplicationInfo().targetSdkVersion;
    if (versionCode == -1) return false;

    if (appTargetSdkVersion < Build.VERSION_CODES.M
            || appTargetSdkVersion > Build.VERSION_CODES.N) {
        return false;
    }

    final String lgeMailPackageId = "com.lge.email";
    if (!lgeMailPackageId.equals(appName)) return false;
    if (versionCode > LGEmailWorkaroundMaxVersion) return false;

    Log.w(TAG, "Working around action mode LG Email bug in WebView (http://crbug.com/651706). "
            + "APK name: " + lgeMailPackageId + ", versionCode: "
            + versionCode);
    return true;
}
 
Example 5
Source Project: delion   Source File: AccessibilityUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Checks to see if an old version of TalkBack is running that Chrome doesn't support,
 * and if so, shows an alert dialog prompting the user to update the app.
 * @param context A {@link Context} instance.
 * @return        True if the dialog was shown.
 */
public static boolean showWarningIfOldTalkbackRunning(Context context) {
    AccessibilityManager manager = (AccessibilityManager)
            context.getSystemService(Context.ACCESSIBILITY_SERVICE);
    if (manager == null) return false;

    boolean isTalkbackRunning = false;
    try {
        List<AccessibilityServiceInfo> services =
                manager.getEnabledAccessibilityServiceList(
                        AccessibilityServiceInfo.FEEDBACK_SPOKEN);
        for (AccessibilityServiceInfo service : services) {
            if (service.getId().contains(TALKBACK_PACKAGE_NAME)) isTalkbackRunning = true;
        }
    } catch (NullPointerException e) {
        // getEnabledAccessibilityServiceList() can throw an NPE due to a bad
        // AccessibilityService.
    }
    if (!isTalkbackRunning) return false;

    if (PackageUtils.getPackageVersion(context, TALKBACK_PACKAGE_NAME) < MIN_TALKBACK_VERSION
            && !sOldTalkBackVersionAlertShown) {
        showOldTalkbackVersionAlertOnce(context);
        return true;
    }

    return false;
}
 
Example 6
Source Project: AndroidChromium   Source File: AccessibilityUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Checks to see if an old version of TalkBack is running that Chrome doesn't support,
 * and if so, shows an alert dialog prompting the user to update the app.
 * @param context A {@link Context} instance.
 * @return        True if the dialog was shown.
 */
public static boolean showWarningIfOldTalkbackRunning(Context context) {
    AccessibilityManager manager = (AccessibilityManager)
            context.getSystemService(Context.ACCESSIBILITY_SERVICE);
    if (manager == null) return false;

    boolean isTalkbackRunning = false;
    try {
        List<AccessibilityServiceInfo> services =
                manager.getEnabledAccessibilityServiceList(
                        AccessibilityServiceInfo.FEEDBACK_SPOKEN);
        for (AccessibilityServiceInfo service : services) {
            if (service.getId().contains(TALKBACK_PACKAGE_NAME)) isTalkbackRunning = true;
        }
    } catch (NullPointerException e) {
        // getEnabledAccessibilityServiceList() can throw an NPE due to a bad
        // AccessibilityService.
    }
    if (!isTalkbackRunning) return false;

    if (PackageUtils.getPackageVersion(context, TALKBACK_PACKAGE_NAME) < MIN_TALKBACK_VERSION
            && !sOldTalkBackVersionAlertShown) {
        showOldTalkbackVersionAlertOnce(context);
        return true;
    }

    return false;
}
 
Example 7
Source Project: 365browser   Source File: VrCoreVersionCheckerImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public int getVrCoreCompatibility() {
    // Supported Build version is determined by the webvr cardboard support feature.
    // Default is KITKAT unless specified via server side finch config.
    if (Build.VERSION.SDK_INT < ChromeFeatureList.getFieldTrialParamByFeatureAsInt(
                                        ChromeFeatureList.WEBVR_CARDBOARD_SUPPORT,
                                        MIN_SDK_VERSION_PARAM_NAME,
                                        Build.VERSION_CODES.KITKAT)) {
        return VrCoreVersionChecker.VR_NOT_SUPPORTED;
    }
    try {
        String vrCoreSdkLibraryVersionString = VrCoreUtils.getVrCoreSdkLibraryVersion(
                ContextUtils.getApplicationContext());
        Version vrCoreSdkLibraryVersion = Version.parse(vrCoreSdkLibraryVersionString);
        Version targetSdkLibraryVersion =
                Version.parse(com.google.vr.ndk.base.BuildConstants.VERSION);
        if (!vrCoreSdkLibraryVersion.isAtLeast(targetSdkLibraryVersion)) {
            return VrCoreVersionChecker.VR_OUT_OF_DATE;
        }
        return VrCoreVersionChecker.VR_READY;
    } catch (VrCoreNotAvailableException e) {
        Log.i(TAG, "Unable to find VrCore.");
        // Old versions of VrCore are not integrated with the sdk library version check and will
        // trigger this exception even though VrCore is installed.
        // Double check package manager to make sure we are not telling user to install
        // when it should just be an update.
        if (PackageUtils.getPackageVersion(
                    ContextUtils.getApplicationContext(), VR_CORE_PACKAGE_ID)
                != -1) {
            return VrCoreVersionChecker.VR_OUT_OF_DATE;
        }
        return VrCoreVersionChecker.VR_NOT_AVAILABLE;
    }
}
 
Example 8
Source Project: 365browser   Source File: AccessibilityUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Checks to see if an old version of TalkBack is running that Chrome doesn't support,
 * and if so, shows an alert dialog prompting the user to update the app.
 * @param context A {@link Context} instance.
 * @return        True if the dialog was shown.
 */
public static boolean showWarningIfOldTalkbackRunning(Context context) {
    AccessibilityManager manager = (AccessibilityManager)
            context.getSystemService(Context.ACCESSIBILITY_SERVICE);
    if (manager == null) return false;

    boolean isTalkbackRunning = false;
    try {
        List<AccessibilityServiceInfo> services =
                manager.getEnabledAccessibilityServiceList(
                        AccessibilityServiceInfo.FEEDBACK_SPOKEN);
        for (AccessibilityServiceInfo service : services) {
            if (service.getId().contains(TALKBACK_PACKAGE_NAME)) isTalkbackRunning = true;
        }
    } catch (NullPointerException e) {
        // getEnabledAccessibilityServiceList() can throw an NPE due to a bad
        // AccessibilityService.
    }
    if (!isTalkbackRunning) return false;

    if (PackageUtils.getPackageVersion(context, TALKBACK_PACKAGE_NAME) < MIN_TALKBACK_VERSION
            && !sOldTalkBackVersionAlertShown) {
        showOldTalkbackVersionAlertOnce(context);
        return true;
    }

    return false;
}
 
Example 9
Source Project: 365browser   Source File: SpeechRecognition.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * This method must be called before any instance of SpeechRecognition can be created. It will
 * query Android's package manager to find a suitable speech recognition provider that supports
 * continuous recognition.
 */
// TODO(crbug.com/635567): Fix this properly.
@SuppressLint("WrongConstant")
public static boolean initialize(Context context) {
    if (!SpeechRecognizer.isRecognitionAvailable(context)) return false;

    PackageManager pm = context.getPackageManager();
    Intent intent = new Intent(RecognitionService.SERVICE_INTERFACE);
    final List<ResolveInfo> list = pm.queryIntentServices(intent, PackageManager.GET_SERVICES);

    for (ResolveInfo resolve : list) {
        ServiceInfo service = resolve.serviceInfo;

        if (!service.packageName.equals(PROVIDER_PACKAGE_NAME)) continue;

        if (PackageUtils.getPackageVersion(context, service.packageName)
                < PROVIDER_MIN_VERSION) {
            continue;
        }

        sRecognitionProvider = new ComponentName(service.packageName, service.name);

        return true;
    }

    // If we reach this point, we failed to find a suitable recognition provider.
    return false;
}
 
Example 10
Source Project: delion   Source File: GSAState.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Check whether the given package meets min requirements for using full document mode.
 * @param packageName The package name we are inquiring about.
 * @param minVersion The minimum version for the package to be.
 * @return Whether the package exists on the device and its version is higher than the minimum
 *         required version.
 */
private boolean isPackageAboveVersion(String packageName, int minVersion) {
    return PackageUtils.getPackageVersion(mContext, packageName) >= minVersion;
}
 
Example 11
Source Project: AndroidChromium   Source File: GSAState.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Check whether the given package meets min requirements for using full document mode.
 * @param packageName The package name we are inquiring about.
 * @param minVersion The minimum version for the package to be.
 * @return Whether the package exists on the device and its version is higher than the minimum
 *         required version.
 */
private boolean isPackageAboveVersion(String packageName, int minVersion) {
    return PackageUtils.getPackageVersion(mContext, packageName) >= minVersion;
}
 
Example 12
Source Project: 365browser   Source File: GSAState.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Check whether the given package meets min requirements for using full document mode.
 * @param packageName The package name we are inquiring about.
 * @param minVersion The minimum version for the package to be.
 * @return Whether the package exists on the device and its version is higher than the minimum
 *         required version.
 */
private boolean isPackageAboveVersion(String packageName, int minVersion) {
    return PackageUtils.getPackageVersion(mContext, packageName) >= minVersion;
}