com.google.ipc.invalidation.ticl.android2.AndroidTiclManifest Java Examples

The following examples show how to use com.google.ipc.invalidation.ticl.android2.AndroidTiclManifest. 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: AndroidNetworkChannel.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public void sendMessage(byte[] outgoingMessage) {
  Intent intent = ProtocolIntents.newOutboundMessageIntent(outgoingMessage);

  // Select the sender service to use for upstream message.
  if (AndroidChannelPreferences.getGcmChannelType(context) == GcmChannelType.GCM_UPSTREAM){
    String upstreamServiceClass = new AndroidTiclManifest(context).getGcmUpstreamServiceClass();
    if (upstreamServiceClass == null || upstreamServiceClass.isEmpty()) {
      logger.warning("GcmUpstreamSenderService class not found.");
      return;
    }
    intent.setClassName(context, upstreamServiceClass);
  } else {
    intent.setClassName(context, AndroidMessageSenderService.class.getName());
  }
  try {
    context.startService(intent);
  } catch (IllegalStateException exception) {
    logger.warning("Unable to send message: %s", exception);
  }
}
 
Example #2
Source File: AndroidMessageReceiverService.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
protected void onRegistered(String registrationId) {
  // Inform the sender service that the registration id has changed. If the sender service
  // had buffered a message because no registration id was previously available, this intent
  // will cause it to send that message.
  Intent sendBuffered = new Intent();
  final String ignoredData = "";
  sendBuffered.putExtra(AndroidChannelConstants.MESSAGE_SENDER_SVC_GCM_REGID_CHANGE, ignoredData);
  sendBuffered.setClass(this, AndroidMessageSenderService.class);
  startService(sendBuffered);

  // Inform the Ticl service that the registration id has changed. This will cause it to send
  // a message to the data center and update the GCM registration id stored at the data center.
  Intent updateServer = ProtocolIntents.InternalDowncalls.newNetworkAddrChangeIntent();
  updateServer.setClassName(this, new AndroidTiclManifest(this).getTiclServiceClass());
  startService(updateServer);
}
 
Example #3
Source File: AndroidMessageReceiverService.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
protected void onRegistered(String registrationId) {
  // Inform the sender service that the registration id has changed. If the sender service
  // had buffered a message because no registration id was previously available, this intent
  // will cause it to send that message.
  Intent sendBuffered = new Intent();
  final String ignoredData = "";
  sendBuffered.putExtra(AndroidChannelConstants.MESSAGE_SENDER_SVC_GCM_REGID_CHANGE, ignoredData);
  sendBuffered.setClass(this, AndroidMessageSenderService.class);
  startService(sendBuffered);

  // Inform the Ticl service that the registration id has changed. This will cause it to send
  // a message to the data center and update the GCM registration id stored at the data center.
  Intent updateServer = ProtocolIntents.InternalDowncalls.newNetworkAddrChangeIntent();
  updateServer.setClassName(this, new AndroidTiclManifest(this).getTiclServiceClass());
  startService(updateServer);
}
 
Example #4
Source File: AndroidListenerIntents.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Issues the given {@code intent} to the TICL service class registered in the {@code context}.
 */
static void issueTiclIntent(Context context, Intent intent) {
  try {
    context.startService(intent.setClassName(context,
        new AndroidTiclManifest(context).getTiclServiceClass()));
  } catch (IllegalStateException exception) {
    logger.info("Unable to deliver ticl intent: %s", exception);
  }
}
 
Example #5
Source File: AndroidMessageReceiverService.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected void onMessage(Intent intent) {
  // Forward the message to the Ticl service.
  if (intent.hasExtra(C2dmConstants.CONTENT_PARAM)) {
    String content = intent.getStringExtra(C2dmConstants.CONTENT_PARAM);
    byte[] msgBytes = Base64.decode(content, Base64.URL_SAFE);
    try {
      // Look up the name of the Ticl service class from the manifest.
      String serviceClass = new AndroidTiclManifest(this).getTiclServiceClass();
      AddressedAndroidMessage addrMessage = AddressedAndroidMessage.parseFrom(msgBytes);
      Intent msgIntent =
          ProtocolIntents.InternalDowncalls.newServerMessageIntent(addrMessage.getMessage());
      msgIntent.setClassName(this, serviceClass);
      startService(msgIntent);
    } catch (InvalidProtocolBufferException exception) {
      logger.warning("Failed parsing inbound message: %s", exception);
    }
  } else {
    logger.fine("GCM Intent has no message content: %s", intent);
  }

  // Store the echo token.
  String echoToken = intent.getStringExtra(C2dmConstants.ECHO_PARAM);
  if (echoToken != null) {
    AndroidChannelPreferences.setEchoToken(this, echoToken);
  }
}
 
Example #6
Source File: AndroidMessageReceiverService.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected void onMessage(Intent intent) {
  // Forward the message to the Ticl service.
  if (intent.hasExtra(C2dmConstants.CONTENT_PARAM)) {
    String content = intent.getStringExtra(C2dmConstants.CONTENT_PARAM);
    byte[] msgBytes = Base64.decode(content, Base64.URL_SAFE);
    try {
      // Look up the name of the Ticl service class from the manifest.
      String serviceClass = new AndroidTiclManifest(this).getTiclServiceClass();
      AddressedAndroidMessage addrMessage = AddressedAndroidMessage.parseFrom(msgBytes);
      Intent msgIntent =
          ProtocolIntents.InternalDowncalls.newServerMessageIntent(addrMessage.getMessage());
      msgIntent.setClassName(this, serviceClass);
      startService(msgIntent);
    } catch (InvalidProtocolBufferException exception) {
      logger.warning("Failed parsing inbound message: %s", exception);
    }
  } else {
    logger.fine("GCM Intent has no message content: %s", intent);
  }

  // Store the echo token.
  String echoToken = intent.getStringExtra(C2dmConstants.ECHO_PARAM);
  if (echoToken != null) {
    AndroidChannelPreferences.setEchoToken(this, echoToken);
  }
}
 
Example #7
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);
  }
}
 
Example #8
Source File: AndroidListenerIntents.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/** Sets the appropriate class for {@link AndroidListener} service intents. */
static Intent setAndroidListenerClass(Context context, Intent intent) {
  String simpleListenerClass = new AndroidTiclManifest(context).getListenerServiceClass();
  return intent.setClassName(context, simpleListenerClass);
}
 
Example #9
Source File: AndroidListenerIntents.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * Issues the given {@code intent} to the TICL service class registered in the {@code context}.
 */
static void issueTiclIntent(Context context, Intent intent) {
  context.startService(intent.setClassName(context,
      new AndroidTiclManifest(context).getTiclServiceClass()));
}
 
Example #10
Source File: AndroidListenerIntents.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/** Sets the appropriate class for {@link AndroidListener} service intents. */
static Intent setAndroidListenerClass(Context context, Intent intent) {
  String simpleListenerClass = new AndroidTiclManifest(context).getListenerServiceClass();
  return intent.setClassName(context, simpleListenerClass);
}
 
Example #11
Source File: AndroidListenerIntents.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * Issues the given {@code intent} to the TICL service class registered in the {@code context}.
 */
static void issueTiclIntent(Context context, Intent intent) {
  context.startService(intent.setClassName(context,
      new AndroidTiclManifest(context).getTiclServiceClass()));
}
 
Example #12
Source File: AndroidListenerIntents.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/** Sets the appropriate class for {@link AndroidListener} service intents. */
static Intent setAndroidListenerClass(Context context, Intent intent) {
  String simpleListenerClass = new AndroidTiclManifest(context).getListenerServiceClass();
  return intent.setClassName(context, simpleListenerClass);
}
 
Example #13
Source File: AndroidClientFactory.java    From 365browser with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a new client.
 * <p>
 * REQUIRES: no client exist, or a client exists with the same type and name as provided. In
 * the latter case, this call is a no-op.
 *
 * @param context Android system context
 * @param clientType type of the client to create
 * @param clientName name of the client to create
 */
public static void createClient(Context context, int clientType, byte[] clientName) {
  ClientConfigP config = InvalidationClientCore.createConfig();
  Intent intent = ProtocolIntents.InternalDowncalls.newCreateClientIntent(
      clientType, Bytes.fromByteArray(clientName), config, false);
  intent.setClassName(context, new AndroidTiclManifest(context).getTiclServiceClass());
  context.startService(intent);
}
 
Example #14
Source File: AndroidClientFactory.java    From android-chromium with BSD 2-Clause "Simplified" License 3 votes vote down vote up
/**
 * Creates a new client.
 * <p>
 * REQUIRES: no client exist, or a client exists with the same type and name as provided. In
 * the latter case, this call is a no-op.
 *
 * @param context Android system context
 * @param clientType type of the client to create
 * @param clientName name of the client to create
 */
public static void createClient(Context context, ClientType.Type clientType, byte[] clientName) {
  ClientConfigP config = InvalidationClientCore.createConfig().build();
  Intent intent = ProtocolIntents.InternalDowncalls.newCreateClientIntent(
      clientType.getNumber(), clientName, config, false);
  intent.setClassName(context, new AndroidTiclManifest(context).getTiclServiceClass());
  context.startService(intent);
}
 
Example #15
Source File: AndroidClientFactory.java    From android-chromium with BSD 2-Clause "Simplified" License 3 votes vote down vote up
/**
 * Creates a new client.
 * <p>
 * REQUIRES: no client exist, or a client exists with the same type and name as provided. In
 * the latter case, this call is a no-op.
 *
 * @param context Android system context
 * @param clientType type of the client to create
 * @param clientName name of the client to create
 */
public static void createClient(Context context, ClientType.Type clientType, byte[] clientName) {
  ClientConfigP config = InvalidationClientCore.createConfig().build();
  Intent intent = ProtocolIntents.InternalDowncalls.newCreateClientIntent(
      clientType.getNumber(), clientName, config, false);
  intent.setClassName(context, new AndroidTiclManifest(context).getTiclServiceClass());
  context.startService(intent);
}