This source file includes following definitions.
- createRegisterIntent
- createRegisterIntent
- isStop
- isRegisteredTypesChange
- getRegisteredObjectIds
package org.chromium.sync.notifier;
import android.accounts.Account;
import android.content.Intent;
import com.google.common.base.Preconditions;
import com.google.ipc.invalidation.external.client.types.ObjectId;
import com.google.protos.ipc.invalidation.Types;
import org.chromium.base.CollectionUtil;
import org.chromium.sync.internal_api.pub.base.ModelType;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
public class InvalidationIntentProtocol {
public static final String ACTION_REGISTER =
"org.chromium.sync.notifier.ACTION_REGISTER_TYPES";
public static final String EXTRA_ACCOUNT = "account";
public static final String EXTRA_REGISTERED_TYPES = "registered_types";
public static final String EXTRA_REGISTERED_OBJECT_SOURCES = "registered_object_sources";
public static final String EXTRA_REGISTERED_OBJECT_NAMES = "registered_object_names";
public static final String EXTRA_STOP = "stop";
public static Intent createRegisterIntent(Account account,
boolean allTypes, Set<ModelType> types) {
Intent registerIntent = new Intent(ACTION_REGISTER);
String[] selectedTypesArray;
if (allTypes) {
selectedTypesArray = new String[]{ModelType.ALL_TYPES_TYPE};
} else {
selectedTypesArray = new String[types.size()];
int pos = 0;
for (ModelType type : types) {
selectedTypesArray[pos++] = type.name();
}
}
registerIntent.putStringArrayListExtra(EXTRA_REGISTERED_TYPES,
CollectionUtil.newArrayList(selectedTypesArray));
registerIntent.putExtra(EXTRA_ACCOUNT, account);
return registerIntent;
}
public static Intent createRegisterIntent(Account account, int[] objectSources,
String[] objectNames) {
Preconditions.checkArgument(objectSources.length == objectNames.length,
"objectSources and objectNames must have the same length");
ArrayList<Integer> sources = new ArrayList<Integer>();
ArrayList<String> names = new ArrayList<String>();
for (int i = 0; i < objectSources.length; i++) {
if (objectSources[i] != Types.ObjectSource.Type.CHROME_SYNC.getNumber()) {
sources.add(objectSources[i]);
names.add(objectNames[i]);
}
}
Intent registerIntent = new Intent(ACTION_REGISTER);
registerIntent.putIntegerArrayListExtra(EXTRA_REGISTERED_OBJECT_SOURCES, sources);
registerIntent.putStringArrayListExtra(EXTRA_REGISTERED_OBJECT_NAMES, names);
registerIntent.putExtra(EXTRA_ACCOUNT, account);
return registerIntent;
}
public static boolean isStop(Intent intent) {
return intent.getBooleanExtra(EXTRA_STOP, false);
}
public static boolean isRegisteredTypesChange(Intent intent) {
return intent.hasExtra(EXTRA_REGISTERED_TYPES) ||
intent.hasExtra(EXTRA_REGISTERED_OBJECT_SOURCES);
}
public static Set<ObjectId> getRegisteredObjectIds(Intent intent) {
ArrayList<Integer> objectSources =
intent.getIntegerArrayListExtra(EXTRA_REGISTERED_OBJECT_SOURCES);
ArrayList<String> objectNames =
intent.getStringArrayListExtra(EXTRA_REGISTERED_OBJECT_NAMES);
if (objectSources == null || objectNames == null ||
objectSources.size() != objectNames.size()) {
return null;
}
Set<ObjectId> objectIds = new HashSet<ObjectId>(objectSources.size());
for (int i = 0; i < objectSources.size(); i++) {
objectIds.add(ObjectId.newInstance(
objectSources.get(i), objectNames.get(i).getBytes()));
}
return objectIds;
}
private InvalidationIntentProtocol() {
}
}