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

The following examples show how to use com.google.ipc.invalidation.ticl.android2.ProtocolIntents. 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: 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 #2
Source File: AndroidListener.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/** Tries to handle a start intent. Returns {@code true} iff the intent is a start intent. */
private boolean tryHandleStartIntent(Intent intent) {
  StartCommand command = AndroidListenerIntents.findStartCommand(intent);
  if ((command == null) || !AndroidListenerProtos.isValidStartCommand(command)) {
    return false;
  }
  // Reset the state so that we make no assumptions about desired registrations and can ignore
  // messages directed at the wrong instance.
  state = new AndroidListenerState(initialMaxDelayMs, maxDelayFactor);
  boolean skipStartForTest = false;
  Intent startIntent = ProtocolIntents.InternalDowncalls.newCreateClientIntent(
      command.getClientType(), command.getClientName().toByteArray(),
      ClientConfigP.getDefaultInstance(), skipStartForTest);
  AndroidListenerIntents.issueTiclIntent(getApplicationContext(), startIntent);
  return true;
}
 
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: AndroidListener.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/** Tries to handle a start intent. Returns {@code true} iff the intent is a start intent. */
private boolean tryHandleStartIntent(Intent intent) {
  StartCommand command = AndroidListenerIntents.findStartCommand(intent);
  if ((command == null) || !AndroidListenerProtos.isValidStartCommand(command)) {
    return false;
  }
  // Reset the state so that we make no assumptions about desired registrations and can ignore
  // messages directed at the wrong instance.
  state = new AndroidListenerState(initialMaxDelayMs, maxDelayFactor);
  boolean skipStartForTest = false;
  Intent startIntent = ProtocolIntents.InternalDowncalls.newCreateClientIntent(
      command.getClientType(), command.getClientName().toByteArray(),
      ClientConfigP.getDefaultInstance(), skipStartForTest);
  AndroidListenerIntents.issueTiclIntent(getApplicationContext(), startIntent);
  return true;
}
 
Example #5
Source File: GcmUpstreamSenderService.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
protected void onHandleIntent(Intent intent) {
  if (AndroidChannelPreferences.getGcmChannelType(this) != GcmChannelType.GCM_UPSTREAM) {
    logger.warning("Incorrect channel type for using GCM Upstream");
    return;
  }
  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.MESSAGE_SENDER_SVC_GCM_REGID_CHANGE)) {
    handleGcmRegIdChange();
  } else {
    logger.warning("Ignoring intent: %s", intent);
  }
}
 
Example #6
Source File: AndroidListener.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Tries to handle a background invalidation intent. Returns {@code true} iff the intent is a
 * background invalidation intent.
 */
private boolean tryHandleBackgroundInvalidationsIntent(Intent intent) {
  byte[] data = intent.getByteArrayExtra(ProtocolIntents.BACKGROUND_INVALIDATION_KEY);
  if (data == null) {
    return false;
  }
  try {
    InvalidationMessage invalidationMessage = InvalidationMessage.parseFrom(data);
    List<Invalidation> invalidations = new ArrayList<Invalidation>();
    for (InvalidationP invalidation : invalidationMessage.getInvalidation()) {
      invalidations.add(ProtoWrapperConverter.convertFromInvalidationProto(invalidation));
    }
    backgroundInvalidateForInternalUse(invalidations);
  } catch (ValidationException exception) {
    logger.info("Failed to parse background invalidation intent payload: %s",
        exception.getMessage());
  }
  return false;
}
 
Example #7
Source File: AndroidListener.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/** Tries to handle a start intent. Returns {@code true} iff the intent is a start intent. */
private boolean tryHandleStartIntent(Intent intent) {
  StartCommand command = AndroidListenerIntents.findStartCommand(intent);
  if ((command == null) || !AndroidListenerProtos.isValidStartCommand(command)) {
    return false;
  }
  // Reset the state so that we make no assumptions about desired registrations and can ignore
  // messages directed at the wrong instance.
  state = new AndroidListenerState(initialMaxDelayMs, maxDelayFactor);
  boolean skipStartForTest = false;
  ClientConfigP clientConfig = InvalidationClientCore.createConfig();
  if (command.getAllowSuppression() != clientConfig.getAllowSuppression()) {
    ClientConfigP.Builder clientConfigBuilder = clientConfig.toBuilder();
    clientConfigBuilder.allowSuppression = command.getAllowSuppression();
    clientConfig = clientConfigBuilder.build();
  }
  Intent startIntent = ProtocolIntents.InternalDowncalls.newCreateClientIntent(
      command.getClientType(), command.getClientName(), clientConfig, skipStartForTest);
  AndroidListenerIntents.issueTiclIntent(getApplicationContext(), startIntent);
  return true;
}
 
Example #8
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 #9
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 #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: 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 #12
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 #13
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 #14
Source File: AndroidNetworkChannel.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void sendMessage(byte[] outgoingMessage) {
  Intent intent = ProtocolIntents.newOutboundMessageIntent(outgoingMessage);
  intent.setClassName(context, AndroidMessageSenderService.class.getName());
  context.startService(intent);
}
 
Example #15
Source File: AndroidNetworkChannel.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void sendMessage(byte[] outgoingMessage) {
  Intent intent = ProtocolIntents.newOutboundMessageIntent(outgoingMessage);
  intent.setClassName(context, AndroidMessageSenderService.class.getName());
  context.startService(intent);
}
 
Example #16
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 #17
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 #18
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);
}