com.google.ipc.invalidation.ticl.android2.channel.AndroidChannelConstants.AuthTokenConstants Java Examples

The following examples show how to use com.google.ipc.invalidation.ticl.android2.channel.AndroidChannelConstants.AuthTokenConstants. 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: AndroidListener.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Tries to handle a request for an authorization token. Returns {@code true} iff the intent is
 * an auth token request.
 */
private boolean tryHandleAuthTokenRequestIntent(Intent intent) {
  if (!AndroidListenerIntents.isAuthTokenRequest(intent)) {
    return false;
  }
  Context context = getApplicationContext();

  // Check for invalid auth token. Subclass may have to invalidate it if it exists in the call
  // to getNewAuthToken.
  String invalidAuthToken = intent.getStringExtra(
      AuthTokenConstants.EXTRA_INVALIDATE_AUTH_TOKEN);
  // Intent also includes a pending intent that we can use to pass back our response.
  PendingIntent pendingIntent = intent.getParcelableExtra(
      AuthTokenConstants.EXTRA_PENDING_INTENT);
  if (pendingIntent == null) {
    logger.warning("Authorization request without pending intent extra.");
  } else {
    // Delegate to client application to figure out what the new token should be and the auth
    // type.
    requestAuthToken(pendingIntent, invalidAuthToken);
  }
  return true;
}
 
Example #2
Source File: AndroidMessageSenderService.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Handles an intent received from the application that contains both a message to send and
 * an auth token and type to use when sending it. This is called when the reply to the intent
 * sent in {@link #requestAuthTokenForMessage(byte[], String)} is received.
 */
private void handleAuthTokenResponse(Intent intent) {
  if (!(intent.hasExtra(AuthTokenConstants.EXTRA_STORED_MESSAGE)
          && intent.hasExtra(AuthTokenConstants.EXTRA_AUTH_TOKEN)
          && intent.hasExtra(AuthTokenConstants.EXTRA_AUTH_TOKEN_TYPE)
          && intent.hasExtra(AuthTokenConstants.EXTRA_IS_RETRY))) {
    logger.warning(
        "auth-token-response intent missing fields: %s, %s", intent, intent.getExtras());
    return;
  }
  boolean isRetryForInvalidAuthToken =
      intent.getBooleanExtra(AuthTokenConstants.EXTRA_IS_RETRY, false);
  deliverOutboundMessage(
      intent.getByteArrayExtra(AuthTokenConstants.EXTRA_STORED_MESSAGE),
      intent.getStringExtra(AuthTokenConstants.EXTRA_AUTH_TOKEN),
      intent.getStringExtra(AuthTokenConstants.EXTRA_AUTH_TOKEN_TYPE),
      isRetryForInvalidAuthToken);
}
 
Example #3
Source File: AndroidListener.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Tries to handle a request for an authorization token. Returns {@code true} iff the intent is
 * an auth token request.
 */
private boolean tryHandleAuthTokenRequestIntent(Intent intent) {
  if (!AndroidListenerIntents.isAuthTokenRequest(intent)) {
    return false;
  }

  // Check for invalid auth token. Subclass may have to invalidate it if it exists in the call
  // to getNewAuthToken.
  String invalidAuthToken = intent.getStringExtra(
      AuthTokenConstants.EXTRA_INVALIDATE_AUTH_TOKEN);
  // Intent also includes a pending intent that we can use to pass back our response.
  PendingIntent pendingIntent = intent.getParcelableExtra(
      AuthTokenConstants.EXTRA_PENDING_INTENT);
  if (pendingIntent == null) {
    logger.warning("Authorization request without pending intent extra.");
  } else {
    // Delegate to client application to figure out what the new token should be and the auth
    // type.
    requestAuthToken(pendingIntent, invalidAuthToken);
  }
  return true;
}
 
Example #4
Source File: AndroidMessageSenderService.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Handles an intent received from the application that contains both a message to send and
 * an auth token and type to use when sending it. This is called when the reply to the intent
 * sent in {@link #requestAuthTokenForMessage(byte[], String)} is received.
 */
private void handleAuthTokenResponse(Intent intent) {
  if (!(intent.hasExtra(AuthTokenConstants.EXTRA_STORED_MESSAGE)
      && intent.hasExtra(AuthTokenConstants.EXTRA_AUTH_TOKEN)
      && intent.hasExtra(AuthTokenConstants.EXTRA_AUTH_TOKEN_TYPE)
      && intent.hasExtra(AuthTokenConstants.EXTRA_IS_RETRY))) {
    logger.warning("auth-token-response intent missing fields: %s, %s",
        intent, intent.getExtras());
    return;
  }
  boolean isRetryForInvalidAuthToken =
      intent.getBooleanExtra(AuthTokenConstants.EXTRA_IS_RETRY, false);
  deliverOutboundMessage(
      intent.getByteArrayExtra(AuthTokenConstants.EXTRA_STORED_MESSAGE),
      intent.getStringExtra(AuthTokenConstants.EXTRA_AUTH_TOKEN),
      intent.getStringExtra(AuthTokenConstants.EXTRA_AUTH_TOKEN_TYPE),
      isRetryForInvalidAuthToken);
}
 
Example #5
Source File: AndroidMessageSenderService.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
protected void onHandleIntent(Intent intent) {
  if (intent == null) {
    return;
  }

  if (intent.hasExtra(ProtocolIntents.OUTBOUND_MESSAGE_KEY)) {
    // Request from the Ticl service to send a message.
    handleOutboundMessage(intent.getByteArrayExtra(ProtocolIntents.OUTBOUND_MESSAGE_KEY));
  } else if (intent.hasExtra(AndroidChannelConstants.AuthTokenConstants.EXTRA_AUTH_TOKEN)) {
    // Reply from the app with an auth token and a message to send.
    handleAuthTokenResponse(intent);
  } else if (intent.hasExtra(AndroidChannelConstants.MESSAGE_SENDER_SVC_GCM_REGID_CHANGE)) {
    handleGcmRegIdChange();
  } else {
    logger.warning("Ignoring intent: %s", intent);
  }
}
 
Example #6
Source File: AndroidListener.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Tries to handle a request for an authorization token. Returns {@code true} iff the intent is
 * an auth token request.
 */
private boolean tryHandleAuthTokenRequestIntent(Intent intent) {
  if (!AndroidListenerIntents.isAuthTokenRequest(intent)) {
    return false;
  }
  Context context = getApplicationContext();

  // Check for invalid auth token. Subclass may have to invalidate it if it exists in the call
  // to getNewAuthToken.
  String invalidAuthToken = intent.getStringExtra(
      AuthTokenConstants.EXTRA_INVALIDATE_AUTH_TOKEN);
  // Intent also includes a pending intent that we can use to pass back our response.
  PendingIntent pendingIntent = intent.getParcelableExtra(
      AuthTokenConstants.EXTRA_PENDING_INTENT);
  if (pendingIntent == null) {
    logger.warning("Authorization request without pending intent extra.");
  } else {
    // Delegate to client application to figure out what the new token should be and the auth
    // type.
    requestAuthToken(pendingIntent, invalidAuthToken);
  }
  return true;
}
 
Example #7
Source File: AndroidMessageSenderService.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Handles an intent received from the application that contains both a message to send and
 * an auth token and type to use when sending it. This is called when the reply to the intent
 * sent in {@link #requestAuthTokenForMessage(byte[], String)} is received.
 */
private void handleAuthTokenResponse(Intent intent) {
  if (!(intent.hasExtra(AuthTokenConstants.EXTRA_STORED_MESSAGE)
      && intent.hasExtra(AuthTokenConstants.EXTRA_AUTH_TOKEN)
      && intent.hasExtra(AuthTokenConstants.EXTRA_AUTH_TOKEN_TYPE)
      && intent.hasExtra(AuthTokenConstants.EXTRA_IS_RETRY))) {
    logger.warning("auth-token-response intent missing fields: %s, %s",
        intent, intent.getExtras());
    return;
  }
  boolean isRetryForInvalidAuthToken =
      intent.getBooleanExtra(AuthTokenConstants.EXTRA_IS_RETRY, false);
  deliverOutboundMessage(
      intent.getByteArrayExtra(AuthTokenConstants.EXTRA_STORED_MESSAGE),
      intent.getStringExtra(AuthTokenConstants.EXTRA_AUTH_TOKEN),
      intent.getStringExtra(AuthTokenConstants.EXTRA_AUTH_TOKEN_TYPE),
      isRetryForInvalidAuthToken);
}
 
Example #8
Source File: AndroidListenerIntents.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Given an authorization token request intent and authorization information ({@code authToken}
 * and {@code authType}) issues a response.
 */
static void issueAuthTokenResponse(Context context, PendingIntent pendingIntent, String authToken,
    String authType) {
  Intent responseIntent = new Intent()
      .putExtra(AuthTokenConstants.EXTRA_AUTH_TOKEN, authToken)
      .putExtra(AuthTokenConstants.EXTRA_AUTH_TOKEN_TYPE, authType);
  try {
    pendingIntent.send(context, 0, responseIntent);
  } catch (CanceledException exception) {
    logger.warning("Canceled auth request: %s", exception);
  }
}
 
Example #9
Source File: AndroidListenerIntents.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Given an authorization token request intent and authorization information ({@code authToken}
 * and {@code authType}) issues a response.
 */
static void issueAuthTokenResponse(Context context, PendingIntent pendingIntent, String authToken,
    String authType) {
  Intent responseIntent = new Intent()
      .putExtra(AuthTokenConstants.EXTRA_AUTH_TOKEN, authToken)
      .putExtra(AuthTokenConstants.EXTRA_AUTH_TOKEN_TYPE, authType);
  try {
    pendingIntent.send(context, 0, responseIntent);
  } catch (CanceledException exception) {
    logger.warning("Canceled auth request: %s", exception);
  }
}
 
Example #10
Source File: AndroidMessageSenderService.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected void onHandleIntent(Intent intent) {
  if (intent.hasExtra(ProtocolIntents.OUTBOUND_MESSAGE_KEY)) {
    // Request from the Ticl service to send a message.
    handleOutboundMessage(intent.getByteArrayExtra(ProtocolIntents.OUTBOUND_MESSAGE_KEY));
  } else if (intent.hasExtra(AndroidChannelConstants.AuthTokenConstants.EXTRA_AUTH_TOKEN)) {
    // Reply from the app with an auth token and a message to send.
    handleAuthTokenResponse(intent);
  } else if (intent.hasExtra(AndroidChannelConstants.MESSAGE_SENDER_SVC_GCM_REGID_CHANGE)) {
    handleGcmRegIdChange();
  } else {
    logger.warning("Ignoring intent: %s", intent);
  }
}
 
Example #11
Source File: AndroidMessageSenderService.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Requests an auth token from the application to use to send {@code message} to the data
 * center.
 * <p>
 * If not {@code null}, {@code invalidAuthToken} is an auth token that was previously
 * found to be invalid. The intent sent to the application to request the new token will include
 * the invalid token so that the application can invalidate it in the {@code AccountManager}.
 */
private void requestAuthTokenForMessage(byte[] message, String invalidAuthToken) {
  /*
   * Send an intent requesting an auth token. This intent will contain a pending intent
   * that the recipient can use to send back the token (by attaching the token as a string
   * extra). That pending intent will also contain the message that we were just asked to send,
   * so that it will be echoed back to us with the token. This avoids our having to persist
   * the message while waiting for the token.
   */

  // This is the intent that the application will send back to us (the pending intent allows
  // it to send the intent). It contains the stored message. We require that it be delivered to
  // this class only, as a security check.
  Intent tokenResponseIntent = new Intent(this, getClass());
  tokenResponseIntent.putExtra(AuthTokenConstants.EXTRA_STORED_MESSAGE, message);

  // If we have an invalid auth token, set a bit in the intent that the application will send
  // back to us. This will let us know that it is a retry; if sending subsequently fails again,
  // we will not do any further retries.
  tokenResponseIntent.putExtra(AuthTokenConstants.EXTRA_IS_RETRY, invalidAuthToken != null);

  // The pending intent allows the application to send us the tokenResponseIntent.
  PendingIntent pendingIntent = PendingIntent.getService(
      this, message.hashCode(), tokenResponseIntent, PendingIntent.FLAG_ONE_SHOT);

  // We send the pending intent as an extra in a normal intent to the application. We require that
  // the intent be delivered only within this package, as a security check. The application must
  // define a service with an intent filter that matches the ACTION_REQUEST_AUTH_TOKEN in order
  // to receive this intent.
  Intent requestTokenIntent = new Intent(AuthTokenConstants.ACTION_REQUEST_AUTH_TOKEN);
  requestTokenIntent.setPackage(getPackageName());
  requestTokenIntent.putExtra(AuthTokenConstants.EXTRA_PENDING_INTENT, pendingIntent);
  if (invalidAuthToken != null) {
    requestTokenIntent.putExtra(AuthTokenConstants.EXTRA_INVALIDATE_AUTH_TOKEN, invalidAuthToken);
  }
  startService(requestTokenIntent);
}
 
Example #12
Source File: AndroidListenerIntents.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Given an authorization token request intent and authorization information ({@code authToken}
 * and {@code authType}) issues a response.
 */
static void issueAuthTokenResponse(Context context, PendingIntent pendingIntent, String authToken,
    String authType) {
  Intent responseIntent = new Intent()
      .putExtra(AuthTokenConstants.EXTRA_AUTH_TOKEN, authToken)
      .putExtra(AuthTokenConstants.EXTRA_AUTH_TOKEN_TYPE, authType);
  try {
    pendingIntent.send(context, 0, responseIntent);
  } catch (CanceledException exception) {
    logger.warning("Canceled auth request: %s", exception);
  }
}
 
Example #13
Source File: AndroidMessageSenderService.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected void onHandleIntent(Intent intent) {
  if (intent.hasExtra(ProtocolIntents.OUTBOUND_MESSAGE_KEY)) {
    // Request from the Ticl service to send a message.
    handleOutboundMessage(intent.getByteArrayExtra(ProtocolIntents.OUTBOUND_MESSAGE_KEY));
  } else if (intent.hasExtra(AndroidChannelConstants.AuthTokenConstants.EXTRA_AUTH_TOKEN)) {
    // Reply from the app with an auth token and a message to send.
    handleAuthTokenResponse(intent);
  } else if (intent.hasExtra(AndroidChannelConstants.MESSAGE_SENDER_SVC_GCM_REGID_CHANGE)) {
    handleGcmRegIdChange();
  } else {
    logger.warning("Ignoring intent: %s", intent);
  }
}
 
Example #14
Source File: AndroidMessageSenderService.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Requests an auth token from the application to use to send {@code message} to the data
 * center.
 * <p>
 * If not {@code null}, {@code invalidAuthToken} is an auth token that was previously
 * found to be invalid. The intent sent to the application to request the new token will include
 * the invalid token so that the application can invalidate it in the {@code AccountManager}.
 */
private void requestAuthTokenForMessage(byte[] message, String invalidAuthToken) {
  /*
   * Send an intent requesting an auth token. This intent will contain a pending intent
   * that the recipient can use to send back the token (by attaching the token as a string
   * extra). That pending intent will also contain the message that we were just asked to send,
   * so that it will be echoed back to us with the token. This avoids our having to persist
   * the message while waiting for the token.
   */

  // This is the intent that the application will send back to us (the pending intent allows
  // it to send the intent). It contains the stored message. We require that it be delivered to
  // this class only, as a security check.
  Intent tokenResponseIntent = new Intent(this, getClass());
  tokenResponseIntent.putExtra(AuthTokenConstants.EXTRA_STORED_MESSAGE, message);

  // If we have an invalid auth token, set a bit in the intent that the application will send
  // back to us. This will let us know that it is a retry; if sending subsequently fails again,
  // we will not do any further retries.
  tokenResponseIntent.putExtra(AuthTokenConstants.EXTRA_IS_RETRY, invalidAuthToken != null);

  // The pending intent allows the application to send us the tokenResponseIntent.
  PendingIntent pendingIntent = PendingIntent.getService(
      this, message.hashCode(), tokenResponseIntent, PendingIntent.FLAG_ONE_SHOT);

  // We send the pending intent as an extra in a normal intent to the application. We require that
  // the intent be delivered only within this package, as a security check. The application must
  // define a service with an intent filter that matches the ACTION_REQUEST_AUTH_TOKEN in order
  // to receive this intent.
  Intent requestTokenIntent = new Intent(AuthTokenConstants.ACTION_REQUEST_AUTH_TOKEN);
  requestTokenIntent.setPackage(getPackageName());
  requestTokenIntent.putExtra(AuthTokenConstants.EXTRA_PENDING_INTENT, pendingIntent);
  if (invalidAuthToken != null) {
    requestTokenIntent.putExtra(AuthTokenConstants.EXTRA_INVALIDATE_AUTH_TOKEN, invalidAuthToken);
  }
  startService(requestTokenIntent);
}
 
Example #15
Source File: AndroidListenerIntents.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/** Returns {@code true} iff the given intent is an authorization token request. */
static boolean isAuthTokenRequest(Intent intent) {
  return AuthTokenConstants.ACTION_REQUEST_AUTH_TOKEN.equals(intent.getAction());
}
 
Example #16
Source File: AndroidListenerIntents.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/** Returns {@code true} iff the given intent is an authorization token request. */
static boolean isAuthTokenRequest(Intent intent) {
  return AuthTokenConstants.ACTION_REQUEST_AUTH_TOKEN.equals(intent.getAction());
}
 
Example #17
Source File: AndroidListenerIntents.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/** Returns {@code true} iff the given intent is an authorization token request. */
static boolean isAuthTokenRequest(Intent intent) {
  return AuthTokenConstants.ACTION_REQUEST_AUTH_TOKEN.equals(intent.getAction());
}
 
Example #18
Source File: AndroidMessageSenderService.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * Requests an auth token from the application to use to send {@code message} to the data
 * center.
 * <p>
 * If not {@code null}, {@code invalidAuthToken} is an auth token that was previously
 * found to be invalid. The intent sent to the application to request the new token will include
 * the invalid token so that the application can invalidate it in the {@code AccountManager}.
 */
private void requestAuthTokenForMessage(byte[] message, String invalidAuthToken) {
  /*
   * Send an intent requesting an auth token. This intent will contain a pending intent
   * that the recipient can use to send back the token (by attaching the token as a string
   * extra). That pending intent will also contain the message that we were just asked to send,
   * so that it will be echoed back to us with the token. This avoids our having to persist
   * the message while waiting for the token.
   */

  // This is the intent that the application will send back to us (the pending intent allows
  // it to send the intent). It contains the stored message. We require that it be delivered to
  // this class only, as a security check.
  Intent tokenResponseIntent = new Intent(this, getClass());
  tokenResponseIntent.putExtra(AuthTokenConstants.EXTRA_STORED_MESSAGE, message);

  // If we have an invalid auth token, set a bit in the intent that the application will send
  // back to us. This will let us know that it is a retry; if sending subsequently fails again,
  // we will not do any further retries.
  tokenResponseIntent.putExtra(AuthTokenConstants.EXTRA_IS_RETRY, invalidAuthToken != null);

  // The pending intent allows the application to send us the tokenResponseIntent.
  PendingIntent pendingIntent = PendingIntent.getService(
      this, Arrays.hashCode(message), tokenResponseIntent, PendingIntent.FLAG_ONE_SHOT);

  // We send the pending intent as an extra in a normal intent to the application. The
  // invalidation listener service must handle AUTH_TOKEN_REQUEST intents.
  Intent requestTokenIntent = new Intent(AuthTokenConstants.ACTION_REQUEST_AUTH_TOKEN);
  requestTokenIntent.putExtra(AuthTokenConstants.EXTRA_PENDING_INTENT, pendingIntent);
  if (invalidAuthToken != null) {
    requestTokenIntent.putExtra(AuthTokenConstants.EXTRA_INVALIDATE_AUTH_TOKEN, invalidAuthToken);
  }
  String simpleListenerClass =
      new AndroidTiclManifest(getApplicationContext()).getListenerServiceClass();
  requestTokenIntent.setClassName(getApplicationContext(), simpleListenerClass);
  try {
    startService(requestTokenIntent);
  } catch (SecurityException | IllegalStateException exception) {
    logger.warning("unable to request auth token: %s", exception);
  }
}