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

The following examples show how to use org.chromium.chrome.browser.externalauth.ExternalAuthUtils. 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 File: IntentHandler.java    From 365browser with 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 #2
Source File: ChromeVersionInfo.java    From 365browser with 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 #3
Source File: ChromeWebApkHost.java    From 365browser with 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 File: IntentHandler.java    From delion with 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 #5
Source File: IntentHandler.java    From AndroidChromium with 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 #6
Source File: SigninManager.java    From delion with 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 File: ForcedSigninProcessor.java    From 365browser with 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 #8
Source File: ChromeGoogleApiClientImpl.java    From 365browser with 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 #9
Source File: ChromeGoogleApiClientImpl.java    From 365browser with 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 #10
Source File: ChromeBrowserProvider.java    From 365browser with 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 #11
Source File: AccountSigninView.java    From 365browser with 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 #12
Source File: SigninManager.java    From 365browser with 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 #13
Source File: ChromeGoogleApiClientImpl.java    From AndroidChromium with 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 #14
Source File: ChromeGoogleApiClientImpl.java    From AndroidChromium with 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 #15
Source File: ChromeBrowserProvider.java    From AndroidChromium with 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 #16
Source File: AccountSigninView.java    From AndroidChromium with 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 #17
Source File: SigninManager.java    From AndroidChromium with 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 #18
Source File: ChromeBrowserProvider.java    From delion with 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 #19
Source File: ChromeGoogleApiClientImpl.java    From delion with 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 File: ChromeGoogleApiClientImpl.java    From delion with 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 #21
Source File: SnippetsLauncher.java    From 365browser with Apache License 2.0 4 votes vote down vote up
private boolean canUseGooglePlayServices() {
    return ExternalAuthUtils.getInstance().canUseGooglePlayServices(
            ContextUtils.getApplicationContext(), new UserRecoverableErrorHandler.Silent());
}
 
Example #22
Source File: ChromeApplication.java    From delion with 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 #23
Source File: SnippetsLauncher.java    From delion with Apache License 2.0 4 votes vote down vote up
private boolean canUseGooglePlayServices(Context context) {
    return ExternalAuthUtils.getInstance().canUseGooglePlayServices(
            context, new UserRecoverableErrorHandler.Silent());
}
 
Example #24
Source File: BackgroundSyncLauncher.java    From delion with 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 #25
Source File: ChromePrerenderService.java    From 365browser with 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 #26
Source File: BackgroundSyncLauncher.java    From 365browser with Apache License 2.0 4 votes vote down vote up
private static boolean canUseGooglePlayServices() {
    return ExternalAuthUtils.getInstance().canUseGooglePlayServices(
            ContextUtils.getApplicationContext(), new UserRecoverableErrorHandler.Silent());
}
 
Example #27
Source File: AppHooks.java    From 365browser with 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 #28
Source File: ChromePrerenderService.java    From delion with 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 #29
Source File: SnippetsLauncher.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
private boolean canUseGooglePlayServices(Context context) {
    return ExternalAuthUtils.getInstance().canUseGooglePlayServices(
            context, new UserRecoverableErrorHandler.Silent());
}
 
Example #30
Source File: ChromeApplication.java    From AndroidChromium with 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();
}