Java Code Examples for com.google.ipc.invalidation.ticl.android2.channel.AndroidChannelConstants.AuthTokenConstants#ACTION_REQUEST_AUTH_TOKEN

The following examples show how to use com.google.ipc.invalidation.ticl.android2.channel.AndroidChannelConstants.AuthTokenConstants#ACTION_REQUEST_AUTH_TOKEN . 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: 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 2
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 3
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);
  }
}