use of android.app.Service in project DroidPlugin by DroidPluginTeam.
the class ServcesManager method handleCreateServiceOne.
//这个需要适配,目前只是适配android api 21
private void handleCreateServiceOne(Context hostContext, Intent stubIntent, ServiceInfo info) throws Exception {
// CreateServiceData data = new CreateServiceData();
// data.token = fakeToken;// IBinder
// data.info =; //ServiceInfo
// data.compatInfo =; //CompatibilityInfo
// data.intent =; //Intent
// activityThread.handleCreateServiceOne(data);
// service = activityThread.mTokenServices.get(fakeToken);
// activityThread.mTokenServices.remove(fakeToken);
ResolveInfo resolveInfo = hostContext.getPackageManager().resolveService(stubIntent, 0);
ServiceInfo stubInfo = resolveInfo != null ? resolveInfo.serviceInfo : null;
PluginManager.getInstance().reportMyProcessName(stubInfo.processName, info.processName, info.packageName);
PluginProcessManager.preLoadApk(hostContext, info);
Object activityThread = ActivityThreadCompat.currentActivityThread();
IBinder fakeToken = new MyFakeIBinder();
Class CreateServiceData = Class.forName(ActivityThreadCompat.activityThreadClass().getName() + "$CreateServiceData");
Constructor init = CreateServiceData.getDeclaredConstructor();
if (!init.isAccessible()) {
init.setAccessible(true);
}
Object data = init.newInstance();
FieldUtils.writeField(data, "token", fakeToken);
FieldUtils.writeField(data, "info", info);
if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) {
FieldUtils.writeField(data, "compatInfo", CompatibilityInfoCompat.DEFAULT_COMPATIBILITY_INFO());
}
Method method = activityThread.getClass().getDeclaredMethod("handleCreateService", CreateServiceData);
if (!method.isAccessible()) {
method.setAccessible(true);
}
method.invoke(activityThread, data);
Object mService = FieldUtils.readField(activityThread, "mServices");
Service service = (Service) MethodUtils.invokeMethod(mService, "get", fakeToken);
MethodUtils.invokeMethod(mService, "remove", fakeToken);
mTokenServices.put(fakeToken, service);
mNameService.put(info.name, service);
if (stubInfo != null) {
PluginManager.getInstance().onServiceCreated(stubInfo, info);
}
}
use of android.app.Service in project DroidPlugin by DroidPluginTeam.
the class ServcesManager method onUnbind.
public boolean onUnbind(Intent intent) throws Exception {
Intent targetIntent = intent.getParcelableExtra(Env.EXTRA_TARGET_INTENT);
if (targetIntent != null) {
ServiceInfo info = PluginManager.getInstance().resolveServiceInfo(targetIntent, 0);
Service service = mNameService.get(info.name);
if (service != null) {
return handleOnUnbindOne(targetIntent);
}
}
return false;
}
use of android.app.Service in project DroidPlugin by DroidPluginTeam.
the class ServcesManager method stopServiceToken.
public boolean stopServiceToken(ComponentName cn, IBinder token, int startId) throws Exception {
Service service = mTokenServices.get(token);
if (service != null) {
Integer lastId = mServiceTaskIds.get(token);
if (lastId == null) {
return false;
}
if (startId != lastId) {
return false;
}
Intent intent = new Intent();
intent.setComponent(cn);
ServiceInfo info = PluginManager.getInstance().resolveServiceInfo(intent, 0);
if (info != null) {
handleOnUnbindOne(intent);
handleOnDestroyOne(info);
return true;
}
}
return false;
}
use of android.app.Service in project DroidPlugin by DroidPluginTeam.
the class ServcesManager method handleOnDestroyOne.
private void handleOnDestroyOne(ServiceInfo targetInfo) {
Service service = mNameService.get(targetInfo.name);
if (service != null) {
service.onDestroy();
mNameService.remove(targetInfo.name);
Object token = findTokenByService(service);
mTokenServices.remove(token);
mServiceTaskIds.remove(token);
service = null;
QueuedWorkCompat.waitToFinish();
PluginManager.getInstance().onServiceDestory(null, targetInfo);
}
QueuedWorkCompat.waitToFinish();
}
use of android.app.Service in project roboguice by roboguice.
the class DefaultRoboModule method configure.
/**
* Configure this module to define Android related bindings.
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
protected void configure() {
final Provider<Context> contextProvider = getProvider(Context.class);
final EventListenerThreadingDecorator observerThreadingDecorator = new EventListenerThreadingDecorator();
// Singletons
bind(ViewListener.class).toInstance(viewListener);
// ContextSingleton bindings
bindScope(ContextSingleton.class, contextScope);
//we need to super bind as we inject the scope by code only, not by annotations
superbind(ContextScope.class).toInstance(contextScope);
bind(AssetManager.class).toProvider(AssetManagerProvider.class);
bind(Context.class).toProvider(NullProvider.<Context>instance()).in(ContextSingleton.class);
bind(Activity.class).toProvider(NullProvider.<Activity>instance()).in(ContextSingleton.class);
bind(RoboActivity.class).toProvider(NullProvider.<RoboActivity>instance()).in(ContextSingleton.class);
bind(Service.class).toProvider(NullProvider.<Service>instance()).in(ContextSingleton.class);
bind(RoboService.class).toProvider(NullProvider.<RoboService>instance()).in(ContextSingleton.class);
// Sundry Android Classes
bind(SharedPreferences.class).toProvider(SharedPreferencesProvider.class);
bind(Resources.class).toProvider(ResourcesProvider.class);
bind(ContentResolver.class).toProvider(ContentResolverProvider.class);
bind(Application.class).toInstance(application);
bind(EventListenerThreadingDecorator.class).toInstance(observerThreadingDecorator);
bind(EventManager.class).annotatedWith(Names.named(GLOBAL_EVENT_MANAGER_NAME)).to(EventManager.class).asEagerSingleton();
bind(Handler.class).toProvider(HandlerProvider.class);
// System Services
for (Entry<Class, String> entry : mapSystemSericeClassToName.entrySet()) {
bindSystemService(entry.getKey(), entry.getValue());
}
// System Services that must be scoped to current context
bind(LayoutInflater.class).toProvider(new ContextScopedSystemServiceProvider<LayoutInflater>(contextProvider, Context.LAYOUT_INFLATER_SERVICE));
bind(SearchManager.class).toProvider(new ContextScopedSystemServiceProvider<SearchManager>(contextProvider, Context.SEARCH_SERVICE));
// Android Resources, Views and extras require special handling
if (hasInjectionPointsForAnnotation(InjectResource.class)) {
bindListener(Matchers.any(), resourceListener);
}
if (hasInjectionPointsForAnnotation(InjectExtra.class)) {
final ExtrasListener extrasListener = new ExtrasListener(contextProvider);
bindListener(Matchers.any(), extrasListener);
}
//should be bound only if we use InjectView or InjectFragment
bindListener(Matchers.any(), viewListener);
final PreferenceListener preferenceListener = new PreferenceListener(contextProvider, application);
superbind(PreferenceListener.class).toInstance(preferenceListener);
if (hasInjectionPointsForAnnotation(InjectPreference.class)) {
bindListener(Matchers.any(), preferenceListener);
}
//should always be bound as ContentViewListener relies on event system
bindListener(Matchers.any(), new ObservesTypeListener(getProvider(EventManager.class), observerThreadingDecorator));
requestInjection(observerThreadingDecorator);
if (isInjectable(Ln.class)) {
bind(LnInterface.class).to(LnImpl.class);
//should this be placed in if statement ?
requestStaticInjection(Ln.class);
}
bindDynamicBindings();
}
Aggregations