Loading core/java/android/content/pm/RegisteredServicesCache.java +31 −2 Original line number Diff line number Diff line Loading @@ -166,7 +166,15 @@ public abstract class RegisteredServicesCache<V> { @UnsupportedAppUsage public RegisteredServicesCache(Context context, String interfaceName, String metaDataName, String attributeName, XmlSerializerAndParser<V> serializerAndParser) { mContext = context; this(new Injector<V>(context), interfaceName, metaDataName, attributeName, serializerAndParser); } /** Provides the basic functionality for unit tests. */ @VisibleForTesting public RegisteredServicesCache(Injector<V> injector, String interfaceName, String metaDataName, String attributeName, XmlSerializerAndParser<V> serializerAndParser) { mContext = injector.getContext(); mInterfaceName = interfaceName; mMetaDataName = metaDataName; mAttributesName = attributeName; Loading @@ -184,7 +192,7 @@ public abstract class RegisteredServicesCache<V> { if (isCore) { intentFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY); } mBackgroundHandler = BackgroundThread.getHandler(); mBackgroundHandler = injector.getBackgroundHandler(); mContext.registerReceiverAsUser( mPackageReceiver, UserHandle.ALL, intentFilter, null, mBackgroundHandler); Loading Loading @@ -918,4 +926,25 @@ public abstract class RegisteredServicesCache<V> { return null; } } /** * Point of injection for test dependencies. * @param <V> The type of the value. */ @VisibleForTesting public static class Injector<V> { private final Context mContext; public Injector(Context context) { mContext = context; } public Context getContext() { return mContext; } public Handler getBackgroundHandler() { return BackgroundThread.getHandler(); } } } core/tests/coretests/src/android/content/pm/RegisteredServicesCacheTest.java +6 −0 Original line number Diff line number Diff line Loading @@ -245,6 +245,12 @@ public class RegisteredServicesCacheTest extends AndroidTestCase { SERVICE_INTERFACE, SERVICE_META_DATA, ATTRIBUTES_NAME, new TestSerializer()); } TestServicesCache(Injector<TestServiceType> injector, XmlSerializerAndParser<TestServiceType> serializerAndParser) { super(injector, SERVICE_INTERFACE, SERVICE_META_DATA, ATTRIBUTES_NAME, serializerAndParser); } @Override public TestServiceType parseServiceAttributes(Resources res, String packageName, AttributeSet attrs) { Loading Loading
core/java/android/content/pm/RegisteredServicesCache.java +31 −2 Original line number Diff line number Diff line Loading @@ -166,7 +166,15 @@ public abstract class RegisteredServicesCache<V> { @UnsupportedAppUsage public RegisteredServicesCache(Context context, String interfaceName, String metaDataName, String attributeName, XmlSerializerAndParser<V> serializerAndParser) { mContext = context; this(new Injector<V>(context), interfaceName, metaDataName, attributeName, serializerAndParser); } /** Provides the basic functionality for unit tests. */ @VisibleForTesting public RegisteredServicesCache(Injector<V> injector, String interfaceName, String metaDataName, String attributeName, XmlSerializerAndParser<V> serializerAndParser) { mContext = injector.getContext(); mInterfaceName = interfaceName; mMetaDataName = metaDataName; mAttributesName = attributeName; Loading @@ -184,7 +192,7 @@ public abstract class RegisteredServicesCache<V> { if (isCore) { intentFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY); } mBackgroundHandler = BackgroundThread.getHandler(); mBackgroundHandler = injector.getBackgroundHandler(); mContext.registerReceiverAsUser( mPackageReceiver, UserHandle.ALL, intentFilter, null, mBackgroundHandler); Loading Loading @@ -918,4 +926,25 @@ public abstract class RegisteredServicesCache<V> { return null; } } /** * Point of injection for test dependencies. * @param <V> The type of the value. */ @VisibleForTesting public static class Injector<V> { private final Context mContext; public Injector(Context context) { mContext = context; } public Context getContext() { return mContext; } public Handler getBackgroundHandler() { return BackgroundThread.getHandler(); } } }
core/tests/coretests/src/android/content/pm/RegisteredServicesCacheTest.java +6 −0 Original line number Diff line number Diff line Loading @@ -245,6 +245,12 @@ public class RegisteredServicesCacheTest extends AndroidTestCase { SERVICE_INTERFACE, SERVICE_META_DATA, ATTRIBUTES_NAME, new TestSerializer()); } TestServicesCache(Injector<TestServiceType> injector, XmlSerializerAndParser<TestServiceType> serializerAndParser) { super(injector, SERVICE_INTERFACE, SERVICE_META_DATA, ATTRIBUTES_NAME, serializerAndParser); } @Override public TestServiceType parseServiceAttributes(Resources res, String packageName, AttributeSet attrs) { Loading