Exemplo n.º 1
0
  /**
   * Starts the sign-in flow, and executes the callback when ready to proceed.
   *
   * <p>This method checks with the native side whether the account has management enabled, and may
   * present a dialog to the user to confirm sign-in. The callback is invoked once these processes
   * and the common sign-in initialization complete.
   *
   * @param activity The context to use for the operation.
   * @param account The account to sign in to.
   * @param passive If passive is true then this operation should not interact with the user.
   * @param callback The Observer to notify when the sign-in process is finished.
   */
  public void startSignIn(
      Activity activity, final Account account, boolean passive, final Observer observer) {
    assert mSignInActivity == null;
    assert mSignInAccount == null;
    assert mSignInObserver == null;
    mSignInActivity = activity;
    mSignInAccount = account;
    mSignInObserver = observer;
    mPassive = passive;

    if (!nativeShouldLoadPolicyForUser(account.name)) {
      // Proceed with the sign-in flow without checking for policy if it can be determined
      // that this account can't have management enabled based on the username.
      doSignIn();
      return;
    }

    Log.d(TAG, "Checking if account has policy management enabled");
    // This will call back to onPolicyCheckedBeforeSignIn.
    nativeCheckPolicyBeforeSignIn(mNativeSigninManagerAndroid, account.name);
  }
Exemplo n.º 2
0
 @CalledByNative
 private void onPolicyFetchedBeforeSignIn() {
   // Policy has been fetched for the user and is being enforced; features like sync may now
   // be disabled by policy, and the rest of the sign-in flow can be resumed.
   doSignIn();
 }
Exemplo n.º 3
0
  @CalledByNative
  private void onPolicyCheckedBeforeSignIn(String managementDomain) {
    if (managementDomain == null) {
      Log.d(TAG, "Account doesn't have policy");
      doSignIn();
      return;
    }

    if (mSignInActivity.isDestroyed()) {
      // The activity is no longer running, cancel sign in.
      cancelSignIn();
      return;
    }

    if (mPassive) {
      // If this is a passive interaction (e.g. auto signin) then don't show the confirmation
      // dialog.
      nativeFetchPolicyBeforeSignIn(mNativeSigninManagerAndroid);
      return;
    }

    Log.d(TAG, "Account has policy management");
    AlertDialog.Builder builder = new AlertDialog.Builder(mSignInActivity);
    builder.setTitle(R.string.policy_dialog_title);
    builder.setMessage(
        mContext.getResources().getString(R.string.policy_dialog_message, managementDomain));
    builder.setPositiveButton(
        R.string.policy_dialog_proceed,
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int id) {
            Log.d(TAG, "Accepted policy management, proceeding with sign-in");
            // This will call back to onPolicyFetchedBeforeSignIn.
            nativeFetchPolicyBeforeSignIn(mNativeSigninManagerAndroid);
            mPolicyConfirmationDialog = null;
          }
        });
    builder.setNegativeButton(
        R.string.policy_dialog_cancel,
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int id) {
            Log.d(TAG, "Cancelled sign-in");
            cancelSignIn();
            mPolicyConfirmationDialog = null;
          }
        });
    builder.setOnDismissListener(
        new DialogInterface.OnDismissListener() {
          @Override
          public void onDismiss(DialogInterface dialog) {
            if (mPolicyConfirmationDialog != null) {
              Log.d(TAG, "Policy dialog dismissed, cancelling sign-in.");
              cancelSignIn();
              mPolicyConfirmationDialog = null;
            }
          }
        });
    mPolicyConfirmationDialog = builder.create();
    mPolicyConfirmationDialog.show();
  }