Java Code Examples for org.chromium.chrome.browser.externalauth.ExternalAuthUtils

The following examples show how to use org.chromium.chrome.browser.externalauth.ExternalAuthUtils. 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: IntentHandler.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @param intent An Intent to be checked.
 * @param context A context.
 * @return Whether an intent originates from Chrome or a first-party app.
 */
public static boolean isIntentChromeOrFirstParty(Intent intent, Context context) {
    if (intent == null) return false;

    PendingIntent token = fetchAuthenticationTokenFromIntent(intent);
    if (token == null) return false;

    // Do not ignore a valid URL Intent if the sender is Chrome. (If the PendingIntents are
    // equal, we know that the sender was us.)
    if (isChromeToken(token, context)) {
        return true;
    }
    if (ExternalAuthUtils.getInstance().isGoogleSigned(
                context, ApiCompatibilityUtils.getCreatorPackage(token))) {
        return true;
    }
    return false;
}
 
Example 2
Source Project: AndroidChromium   Source File: IntentHandler.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @param intent An Intent to be checked.
 * @param context A context.
 * @return Whether an intent originates from Chrome or a first-party app.
 */
public static boolean isIntentChromeOrFirstParty(Intent intent, Context context) {
    if (intent == null) return false;

    PendingIntent token = fetchAuthenticationTokenFromIntent(intent);
    if (token == null) return false;

    // Do not ignore a valid URL Intent if the sender is Chrome. (If the PendingIntents are
    // equal, we know that the sender was us.)
    if (isChromeToken(token, context)) {
        return true;
    }
    if (ExternalAuthUtils.getInstance().isGoogleSigned(
                context, ApiCompatibilityUtils.getCreatorPackage(token))) {
        return true;
    }
    return false;
}
 
Example 3
Source Project: 365browser   Source File: ChromeWebApkHost.java    License: Apache License 2.0 6 votes vote down vote up
/** Computes the GooglePlayInstallState. */
private static int computeGooglePlayInstallState() {
    if (!ExternalAuthUtils.getInstance().canUseGooglePlayServices(
                ContextUtils.getApplicationContext(),
                new UserRecoverableErrorHandler.Silent())) {
        return GooglePlayInstallState.NO_PLAY_SERVICES;
    }

    GooglePlayWebApkInstallDelegate delegate =
            AppHooks.get().getGooglePlayWebApkInstallDelegate();
    if (delegate == null) {
        return GooglePlayInstallState.DISABLED_OTHER;
    }

    return GooglePlayInstallState.SUPPORTED;
}
 
Example 4
Source Project: 365browser   Source File: ChromeVersionInfo.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Returns info about the Google Play services setup for Chrome and the device.
 *
 * Contains the version number of the SDK Chrome was built with and the one for the installed
 * Play Services app. It also contains whether First Party APIs are available.
 */
@CalledByNative
public static String getGmsInfo() {
    Context context = ContextUtils.getApplicationContext();

    final long sdkVersion = GoogleApiAvailability.GOOGLE_PLAY_SERVICES_VERSION_CODE;
    final long installedGmsVersion = getPlayServicesApkVersionNumber(context);

    final String accessType;
    UserRecoverableErrorHandler handler = new UserRecoverableErrorHandler.Silent();
    if (ExternalAuthUtils.getInstance().canUseFirstPartyGooglePlayServices(context, handler)) {
        accessType = "1p";
    } else if (ExternalAuthUtils.getInstance().canUseGooglePlayServices(context, handler)) {
        accessType = "3p";
    } else {
        accessType = "none";
    }

    return String.format(Locale.US,
            "SDK=%s; Installed=%s; Access=%s", sdkVersion, installedGmsVersion, accessType);
}
 
Example 5
Source Project: 365browser   Source File: IntentHandler.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @param intent An Intent to be checked.
 * @return Whether an intent originates from Chrome or a first-party app.
 */
public static boolean isIntentChromeOrFirstParty(Intent intent) {
    if (intent == null) return false;

    PendingIntent token = fetchAuthenticationTokenFromIntent(intent);
    if (token == null) return false;

    // Do not ignore a valid URL Intent if the sender is Chrome. (If the PendingIntents are
    // equal, we know that the sender was us.)
    if (isChromeToken(token)) {
        return true;
    }
    if (ExternalAuthUtils.getInstance().isGoogleSigned(
                ApiCompatibilityUtils.getCreatorPackage(token))) {
        return true;
    }
    return false;
}
 
Example 6
Source Project: delion   Source File: SigninManager.java    License: Apache License 2.0 5 votes vote down vote up
private void progressSignInFlowSeedSystemAccounts() {
    if (AccountTrackerService.get(mContext).checkAndSeedSystemAccounts()) {
        progressSignInFlowCheckPolicy();
    } else if (AccountIdProvider.getInstance().canBeUsed(mContext)) {
        mSignInState.blockedOnAccountSeeding = true;
    } else {
        Activity activity = mSignInState.activity;
        UserRecoverableErrorHandler errorHandler = activity != null
                ? new UserRecoverableErrorHandler.ModalDialog(activity)
                : new UserRecoverableErrorHandler.SystemNotification();
        ExternalAuthUtils.getInstance().canUseGooglePlayServices(mContext, errorHandler);
        Log.w(TAG, "Cancelling the sign-in process as Google Play services is unavailable");
        abortSignIn();
    }
}
 
Example 7
Source Project: delion   Source File: ChromeBrowserProvider.java    License: Apache License 2.0 5 votes vote down vote up
private boolean hasPermission(String permission) {
    boolean isSystemOrGoogleCaller = ExternalAuthUtils.getInstance().isCallerValid(
            getContext(), ExternalAuthUtils.FLAG_SHOULD_BE_GOOGLE_SIGNED
                    | ExternalAuthUtils.FLAG_SHOULD_BE_SYSTEM);
    if (isSystemOrGoogleCaller) return true;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        return getContext().checkCallingOrSelfPermission(
                getReadWritePermissionNameForBookmarkFolders())
                == PackageManager.PERMISSION_GRANTED;
    } else {
        return getContext().checkCallingOrSelfPermission(permission)
                == PackageManager.PERMISSION_GRANTED;
    }
}
 
Example 8
Source Project: delion   Source File: ChromeGoogleApiClientImpl.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @param context its application context will be exposed through
 *            {@link #getApplicationContext()}.
 * @param client will be exposed through {@link #getApiClient()}.
 * @param requireFirstPartyBuild true if the given client can only be used in a first-party
 *            build.
 */
public ChromeGoogleApiClientImpl(Context context, GoogleApiClient client,
        boolean requireFirstPartyBuild) {
    mApplicationContext = context.getApplicationContext();
    mClient = client;
    if (requireFirstPartyBuild
            && !ExternalAuthUtils.getInstance().isChromeGoogleSigned(mApplicationContext)) {
        throw new IllegalStateException("GoogleApiClient requires first-party build");
    }
}
 
Example 9
Source Project: delion   Source File: ChromeGoogleApiClientImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean isGooglePlayServicesAvailable() {
    TraceEvent.begin("ChromeGoogleApiClientImpl:isGooglePlayServicesAvailable");
    try {
        return ExternalAuthUtils.getInstance().canUseGooglePlayServices(
                mApplicationContext, new UserRecoverableErrorHandler.Silent());
    } finally {
        TraceEvent.end("ChromeGoogleApiClientImpl:isGooglePlayServicesAvailable");
    }
}
 
Example 10
Source Project: AndroidChromium   Source File: SigninManager.java    License: Apache License 2.0 5 votes vote down vote up
private void progressSignInFlowSeedSystemAccounts() {
    if (AccountTrackerService.get(mContext).checkAndSeedSystemAccounts()) {
        progressSignInFlowCheckPolicy();
    } else if (AccountIdProvider.getInstance().canBeUsed(mContext)) {
        mSignInState.blockedOnAccountSeeding = true;
    } else {
        Activity activity = mSignInState.activity;
        UserRecoverableErrorHandler errorHandler = activity != null
                ? new UserRecoverableErrorHandler.ModalDialog(activity)
                : new UserRecoverableErrorHandler.SystemNotification();
        ExternalAuthUtils.getInstance().canUseGooglePlayServices(mContext, errorHandler);
        Log.w(TAG, "Cancelling the sign-in process as Google Play services is unavailable");
        abortSignIn();
    }
}
 
Example 11
Source Project: AndroidChromium   Source File: AccountSigninView.java    License: Apache License 2.0 5 votes vote down vote up
private boolean checkGooglePlayServicesAvailable() {
    ExternalAuthUtils extAuthUtils = ExternalAuthUtils.getInstance();
    if (mGooglePlayServicesUpdateErrorHandler == null) {
        mGooglePlayServicesUpdateErrorHandler = new UserRecoverableErrorHandler.ModalDialog(
                mDelegate.getActivity());
    }
    int resultCode = extAuthUtils.canUseGooglePlayServicesResultCode(
            getContext(), mGooglePlayServicesUpdateErrorHandler);
    if (extAuthUtils.isGooglePlayServicesUpdateRequiredError(resultCode)) {
        mIsGooglePlayServicesOutOfDate = true;
    }
    return resultCode == ConnectionResult.SUCCESS;
}
 
Example 12
Source Project: AndroidChromium   Source File: ChromeBrowserProvider.java    License: Apache License 2.0 5 votes vote down vote up
private boolean hasPermission(String permission) {
    boolean isSystemOrGoogleCaller = ExternalAuthUtils.getInstance().isCallerValid(
            getContext(), ExternalAuthUtils.FLAG_SHOULD_BE_GOOGLE_SIGNED
                    | ExternalAuthUtils.FLAG_SHOULD_BE_SYSTEM);
    if (isSystemOrGoogleCaller) return true;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        return getContext().checkCallingOrSelfPermission(
                getReadWritePermissionNameForBookmarkFolders())
                == PackageManager.PERMISSION_GRANTED;
    } else {
        return getContext().checkCallingOrSelfPermission(permission)
                == PackageManager.PERMISSION_GRANTED;
    }
}
 
Example 13
Source Project: AndroidChromium   Source File: ChromeGoogleApiClientImpl.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @param context its application context will be exposed through
 *            {@link #getApplicationContext()}.
 * @param client will be exposed through {@link #getApiClient()}.
 * @param requireFirstPartyBuild true if the given client can only be used in a first-party
 *            build.
 */
public ChromeGoogleApiClientImpl(Context context, GoogleApiClient client,
        boolean requireFirstPartyBuild) {
    mApplicationContext = context.getApplicationContext();
    mClient = client;
    if (requireFirstPartyBuild
            && !ExternalAuthUtils.getInstance().isChromeGoogleSigned(mApplicationContext)) {
        throw new IllegalStateException("GoogleApiClient requires first-party build");
    }
}
 
Example 14
Source Project: AndroidChromium   Source File: ChromeGoogleApiClientImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean isGooglePlayServicesAvailable() {
    TraceEvent.begin("ChromeGoogleApiClientImpl:isGooglePlayServicesAvailable");
    try {
        return ExternalAuthUtils.getInstance().canUseGooglePlayServices(
                mApplicationContext, new UserRecoverableErrorHandler.Silent());
    } finally {
        TraceEvent.end("ChromeGoogleApiClientImpl:isGooglePlayServicesAvailable");
    }
}
 
Example 15
Source Project: 365browser   Source File: SigninManager.java    License: Apache License 2.0 5 votes vote down vote up
private void progressSignInFlowSeedSystemAccounts() {
    if (AccountTrackerService.get().checkAndSeedSystemAccounts()) {
        progressSignInFlowCheckPolicy();
    } else if (AccountIdProvider.getInstance().canBeUsed()) {
        mSignInState.blockedOnAccountSeeding = true;
    } else {
        Activity activity = mSignInState.activity;
        UserRecoverableErrorHandler errorHandler = activity != null
                ? new UserRecoverableErrorHandler.ModalDialog(activity, !isForceSigninEnabled())
                : new UserRecoverableErrorHandler.SystemNotification();
        ExternalAuthUtils.getInstance().canUseGooglePlayServices(mContext, errorHandler);
        Log.w(TAG, "Cancelling the sign-in process as Google Play services is unavailable");
        abortSignIn();
    }
}
 
Example 16
Source Project: 365browser   Source File: AccountSigninView.java    License: Apache License 2.0 5 votes vote down vote up
private boolean checkGooglePlayServicesAvailable() {
    ExternalAuthUtils extAuthUtils = ExternalAuthUtils.getInstance();
    if (mGooglePlayServicesUpdateErrorHandler == null) {
        boolean cancelable = !SigninManager.get(getContext()).isForceSigninEnabled();
        mGooglePlayServicesUpdateErrorHandler = new UserRecoverableErrorHandler.ModalDialog(
                mDelegate.getActivity(), cancelable);
    }
    int resultCode = extAuthUtils.canUseGooglePlayServicesResultCode(
            getContext(), mGooglePlayServicesUpdateErrorHandler);
    if (extAuthUtils.isGooglePlayServicesUpdateRequiredError(resultCode)) {
        mIsGooglePlayServicesOutOfDate = true;
    }
    return resultCode == ConnectionResult.SUCCESS;
}
 
Example 17
Source Project: 365browser   Source File: ChromeBrowserProvider.java    License: Apache License 2.0 5 votes vote down vote up
private boolean hasPermission(String permission) {
    boolean isSystemOrGoogleCaller = ExternalAuthUtils.getInstance().isCallerValid(
            getContext(), ExternalAuthUtils.FLAG_SHOULD_BE_GOOGLE_SIGNED
                    | ExternalAuthUtils.FLAG_SHOULD_BE_SYSTEM);
    if (isSystemOrGoogleCaller) return true;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        return getContext().checkCallingOrSelfPermission(
                getReadWritePermissionNameForBookmarkFolders())
                == PackageManager.PERMISSION_GRANTED;
    } else {
        return getContext().checkCallingOrSelfPermission(permission)
                == PackageManager.PERMISSION_GRANTED;
    }
}
 
Example 18
Source Project: 365browser   Source File: ChromeGoogleApiClientImpl.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @param context its application context will be exposed through
 *            {@link #getApplicationContext()}.
 * @param client will be exposed through {@link #getApiClient()}.
 * @param requireFirstPartyBuild true if the given client can only be used in a first-party
 *            build.
 */
public ChromeGoogleApiClientImpl(Context context, GoogleApiClient client,
        boolean requireFirstPartyBuild) {
    mApplicationContext = context.getApplicationContext();
    mClient = client;
    if (requireFirstPartyBuild && !ExternalAuthUtils.getInstance().isChromeGoogleSigned()) {
        throw new IllegalStateException("GoogleApiClient requires first-party build");
    }
}
 
Example 19
Source Project: 365browser   Source File: ChromeGoogleApiClientImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean isGooglePlayServicesAvailable() {
    TraceEvent.begin("ChromeGoogleApiClientImpl:isGooglePlayServicesAvailable");
    try {
        return ExternalAuthUtils.getInstance().canUseGooglePlayServices(
                mApplicationContext, new UserRecoverableErrorHandler.Silent());
    } finally {
        TraceEvent.end("ChromeGoogleApiClientImpl:isGooglePlayServicesAvailable");
    }
}
 
Example 20
Source Project: 365browser   Source File: ForcedSigninProcessor.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * If forced signin is required by policy, check that Google Play Services is available, and
 * show a non-cancelable dialog otherwise.
 * @param activity The activity for which to show the dialog.
 */
// TODO(bauerb): Once external dependencies reliably use policy to force sign-in,
// consider removing the child account / EDU checks.
public static void checkCanSignIn(final ChromeActivity activity) {
    final Context appContext = activity.getApplicationContext();
    if (SigninManager.get(appContext).isForceSigninEnabled()) {
        ExternalAuthUtils.getInstance().canUseGooglePlayServices(appContext,
                new UserRecoverableErrorHandler.ModalDialog(activity, false));
    }
}
 
Example 21
Source Project: delion   Source File: ChromeApplication.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * @return An instance of ExternalAuthUtils to be installed as a singleton.
 */
public ExternalAuthUtils createExternalAuthUtils() {
    return new ExternalAuthUtils();
}
 
Example 22
Source Project: delion   Source File: SnippetsLauncher.java    License: Apache License 2.0 4 votes vote down vote up
private boolean canUseGooglePlayServices(Context context) {
    return ExternalAuthUtils.getInstance().canUseGooglePlayServices(
            context, new UserRecoverableErrorHandler.Silent());
}
 
Example 23
Source Project: delion   Source File: BackgroundSyncLauncher.java    License: Apache License 2.0 4 votes vote down vote up
private static boolean canUseGooglePlayServices(Context context) {
    return ExternalAuthUtils.getInstance().canUseGooglePlayServices(
            context, new UserRecoverableErrorHandler.Silent());
}
 
Example 24
Source Project: delion   Source File: ChromePrerenderService.java    License: Apache License 2.0 4 votes vote down vote up
IncomingHandler(Context context) {
    super(context, ChromeVersionInfo.isLocalBuild()
            ? 0 : ExternalAuthUtils.FLAG_SHOULD_BE_GOOGLE_SIGNED);
}
 
Example 25
Source Project: AndroidChromium   Source File: ChromeApplication.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * @return An instance of ExternalAuthUtils to be installed as a singleton.
 */
public ExternalAuthUtils createExternalAuthUtils() {
    return new ExternalAuthUtils();
}
 
Example 26
Source Project: AndroidChromium   Source File: SigninManager.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * @return Whether true if the current user is not demo user and the user has a reasonable
 *         Google Play Services installed.
 */
public boolean isSigninSupported() {
    return !ApiCompatibilityUtils.isDemoUser(mContext)
            && !ExternalAuthUtils.getInstance().isGooglePlayServicesMissing(mContext);
}
 
Example 27
Source Project: AndroidChromium   Source File: SnippetsLauncher.java    License: Apache License 2.0 4 votes vote down vote up
private boolean canUseGooglePlayServices(Context context) {
    return ExternalAuthUtils.getInstance().canUseGooglePlayServices(
            context, new UserRecoverableErrorHandler.Silent());
}
 
Example 28
Source Project: AndroidChromium   Source File: BackgroundSyncLauncher.java    License: Apache License 2.0 4 votes vote down vote up
private static boolean canUseGooglePlayServices(Context context) {
    return ExternalAuthUtils.getInstance().canUseGooglePlayServices(
            context, new UserRecoverableErrorHandler.Silent());
}
 
Example 29
Source Project: AndroidChromium   Source File: ChromePrerenderService.java    License: Apache License 2.0 4 votes vote down vote up
IncomingHandler(Context context) {
    super(context, ChromeVersionInfo.isLocalBuild()
            ? 0 : ExternalAuthUtils.FLAG_SHOULD_BE_GOOGLE_SIGNED);
}
 
Example 30
Source Project: 365browser   Source File: SigninManager.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * @return Whether true if the current user is not demo user and the user has a reasonable
 *         Google Play Services installed.
 */
public boolean isSigninSupported() {
    return !ApiCompatibilityUtils.isDemoUser(mContext)
            && !ExternalAuthUtils.getInstance().isGooglePlayServicesMissing(mContext);
}