summaryrefslogtreecommitdiffstats
path: root/sync/android
diff options
context:
space:
mode:
authoryfriedman@chromium.org <yfriedman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-23 22:22:44 +0000
committeryfriedman@chromium.org <yfriedman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-23 22:22:44 +0000
commit8825d7db668ce164006ca54b21a966fdafda8a7a (patch)
treea35e73096e64a9d829e6fc2a86c22bba3b8d03ae /sync/android
parent7b63a29febcb2a3277a19d55ac5a981c45faf9f8 (diff)
downloadchromium_src-8825d7db668ce164006ca54b21a966fdafda8a7a.zip
chromium_src-8825d7db668ce164006ca54b21a966fdafda8a7a.tar.gz
chromium_src-8825d7db668ce164006ca54b21a966fdafda8a7a.tar.bz2
[Android] Hardcode InvalidationService as the Ticl service.
Adding this extra level of indirection through the app manifest was needed to migrate to tango V2. It's no longer necessary and can cause the main thread to sleep while accessing fields from package manager. BUG=138506 NOTRY=true Review URL: https://chromiumcodereview.appspot.com/15337006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@201900 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sync/android')
-rw-r--r--sync/android/java/src/org/chromium/sync/notifier/InvalidationController.java93
-rw-r--r--sync/android/javatests/src/org/chromium/sync/notifier/InvalidationControllerTest.java9
2 files changed, 4 insertions, 98 deletions
diff --git a/sync/android/java/src/org/chromium/sync/notifier/InvalidationController.java b/sync/android/java/src/org/chromium/sync/notifier/InvalidationController.java
index aa6b3d3..b912599 100644
--- a/sync/android/java/src/org/chromium/sync/notifier/InvalidationController.java
+++ b/sync/android/java/src/org/chromium/sync/notifier/InvalidationController.java
@@ -7,10 +7,6 @@ package org.chromium.sync.notifier;
import android.accounts.Account;
import android.content.Context;
import android.content.Intent;
-import android.content.pm.ApplicationInfo;
-import android.content.pm.PackageManager;
-import android.content.pm.PackageManager.NameNotFoundException;
-import android.util.Log;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
@@ -19,11 +15,8 @@ import com.google.common.collect.Lists;
import org.chromium.base.ActivityStatus;
import org.chromium.sync.internal_api.pub.base.ModelType;
-import java.util.HashSet;
import java.util.Set;
-import javax.annotation.Nullable;
-
/**
* Controller used to send start, stop, and registration-change commands to the invalidation
* client library used by Sync.
@@ -93,18 +86,6 @@ public class InvalidationController implements ActivityStatus.StateListener {
}
}
- /**
- * Name of the manifest application metadata property specifying the name of the class
- * implementing the invalidation client.
- */
- private static final String IMPLEMENTING_CLASS_MANIFEST_PROPERTY =
- "org.chromium.sync.notifier.IMPLEMENTING_CLASS_NAME";
-
- /**
- * Logging tag.
- */
- private static final String TAG = InvalidationController.class.getSimpleName();
-
private static final Object LOCK = new Object();
private static InvalidationController sInstance;
@@ -124,31 +105,13 @@ public class InvalidationController implements ActivityStatus.StateListener {
typesToRegister.remove(ModelType.PROXY_TABS);
Intent registerIntent = IntentProtocol.createRegisterIntent(account, allTypes,
typesToRegister);
- setDestinationClassName(registerIntent);
+ registerIntent.setClass(mContext, InvalidationService.class);
mContext.startService(registerIntent);
}
/**
* Reads all stored preferences and calls
* {@link #setRegisteredTypes(android.accounts.Account, boolean, java.util.Set)} with the stored
- * values. It can be used on startup of Chrome to ensure we always have a consistent set of
- * registrations.
- */
- @Deprecated
- public void refreshRegisteredTypes() {
- InvalidationPreferences invalidationPreferences = new InvalidationPreferences(mContext);
- Set<String> savedSyncedTypes = invalidationPreferences.getSavedSyncedTypes();
- Account account = invalidationPreferences.getSavedSyncedAccount();
- boolean allTypes = savedSyncedTypes != null &&
- savedSyncedTypes.contains(ModelType.ALL_TYPES_TYPE);
- Set<ModelType> modelTypes = savedSyncedTypes == null ?
- new HashSet<ModelType>() : ModelType.syncTypesToModelTypes(savedSyncedTypes);
- setRegisteredTypes(account, allTypes, modelTypes);
- }
-
- /**
- * Reads all stored preferences and calls
- * {@link #setRegisteredTypes(android.accounts.Account, boolean, java.util.Set)} with the stored
* values, refreshing the set of types with {@code types}. It can be used on startup of Chrome
* to ensure we always have a set of registrations consistent with the native code.
* @param types Set of types for which to register.
@@ -166,7 +129,7 @@ public class InvalidationController implements ActivityStatus.StateListener {
* Starts the invalidation client.
*/
public void start() {
- Intent intent = setDestinationClassName(new Intent());
+ Intent intent = new Intent(mContext, InvalidationService.class);
mContext.startService(intent);
}
@@ -174,7 +137,7 @@ public class InvalidationController implements ActivityStatus.StateListener {
* Stops the invalidation client.
*/
public void stop() {
- Intent intent = setDestinationClassName(new Intent());
+ Intent intent = new Intent(mContext, InvalidationService.class);
intent.putExtra(IntentProtocol.EXTRA_STOP, true);
mContext.startService(intent);
}
@@ -201,19 +164,6 @@ public class InvalidationController implements ActivityStatus.StateListener {
}
/**
- * Returns the singleton instance that will use {@code context} to issue intents.
- *
- * This method is only kept until the downstream callers of this method have been changed to use
- * {@link InvalidationController#get(android.content.Context)}.
- *
- * TODO(nyquist) Remove this method.
- */
- @Deprecated
- public static InvalidationController newInstance(Context context) {
- return get(context);
- }
-
- /**
* Creates an instance using {@code context} to send intents.
*/
@VisibleForTesting
@@ -222,43 +172,6 @@ public class InvalidationController implements ActivityStatus.StateListener {
ActivityStatus.registerStateListener(this);
}
- /**
- * Sets the destination class name of {@code intent} to the value given by the manifest
- * property named {@link #IMPLEMENTING_CLASS_MANIFEST_PROPERTY}. If no such property exists or
- * its value is null, takes no action.
- *
- * @return {@code intent}
- */
- private Intent setDestinationClassName(Intent intent) {
- String className = getDestinationClassName(mContext);
- if (className != null) {
- intent.setClassName(mContext, className);
- }
- return intent;
- }
-
- @VisibleForTesting
- @Nullable static String getDestinationClassName(Context context) {
- ApplicationInfo appInfo;
- try {
- // Fetch application info and read the appropriate metadata element.
- appInfo = context.getPackageManager().getApplicationInfo(context.getPackageName(),
- PackageManager.GET_META_DATA);
- String className = null;
- if (appInfo.metaData != null) {
- className = appInfo.metaData.getString(IMPLEMENTING_CLASS_MANIFEST_PROPERTY);
- }
- if (className == null) {
- Log.wtf(TAG, "No value for " + IMPLEMENTING_CLASS_MANIFEST_PROPERTY
- + " in manifest; sync notifications will not work");
- }
- return className;
- } catch (NameNotFoundException exception) {
- Log.wtf(TAG, "Cannot read own application info", exception);
- }
- return null;
- }
-
@Override
public void onActivityStateChange(int newState) {
if (SyncStatusHelper.get(mContext).isSyncEnabled()) {
diff --git a/sync/android/javatests/src/org/chromium/sync/notifier/InvalidationControllerTest.java b/sync/android/javatests/src/org/chromium/sync/notifier/InvalidationControllerTest.java
index 90d4db9..76ddd49 100644
--- a/sync/android/javatests/src/org/chromium/sync/notifier/InvalidationControllerTest.java
+++ b/sync/android/javatests/src/org/chromium/sync/notifier/InvalidationControllerTest.java
@@ -285,19 +285,12 @@ public class InvalidationControllerTest extends InstrumentationTestCase {
assertEquals(mContext.getPackageName(), mController.getContractAuthority());
}
- @SmallTest
- @Feature({"Sync"})
- public void testGetIntentDestination() {
- assertEquals("org.chromium.sync.notifier.TEST_VALUE",
- InvalidationController.getDestinationClassName(mContext));
- }
-
/**
* Asserts that {@code intent} is destined for the correct component.
*/
private static void validateIntentComponent(Intent intent) {
assertNotNull(intent.getComponent());
- assertEquals("org.chromium.sync.notifier.TEST_VALUE",
+ assertEquals(InvalidationService.class.getName(),
intent.getComponent().getClassName());
}