Search in sources :

Example 6 with Service

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);
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) ServiceInfo(android.content.pm.ServiceInfo) IBinder(android.os.IBinder) Constructor(java.lang.reflect.Constructor) Service(android.app.Service) Method(java.lang.reflect.Method)

Example 7 with Service

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;
}
Also used : ServiceInfo(android.content.pm.ServiceInfo) Service(android.app.Service) Intent(android.content.Intent)

Example 8 with Service

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;
}
Also used : ServiceInfo(android.content.pm.ServiceInfo) Service(android.app.Service) Intent(android.content.Intent)

Example 9 with Service

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();
}
Also used : Service(android.app.Service)

Example 10 with Service

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();
}
Also used : RoboService(roboguice.service.RoboService) ViewListener(roboguice.inject.ViewListener) RoboActivity(roboguice.activity.RoboActivity) Activity(android.app.Activity) ContentResolver(android.content.ContentResolver) RoboActivity(roboguice.activity.RoboActivity) Context(android.content.Context) ObservesTypeListener(roboguice.event.ObservesTypeListener) AssetManager(android.content.res.AssetManager) EventManager(roboguice.event.EventManager) EventListenerThreadingDecorator(roboguice.event.eventListener.factory.EventListenerThreadingDecorator) SharedPreferences(android.content.SharedPreferences) SearchManager(android.app.SearchManager) ExtrasListener(roboguice.inject.ExtrasListener) ContextScope(roboguice.inject.ContextScope) Service(android.app.Service) RoboService(roboguice.service.RoboService) Handler(android.os.Handler) PreferenceListener(roboguice.inject.PreferenceListener) LnInterface(roboguice.util.LnInterface) LayoutInflater(android.view.LayoutInflater) Resources(android.content.res.Resources) Application(android.app.Application)

Aggregations

Service (android.app.Service)24 ServiceInfo (android.content.pm.ServiceInfo)12 Intent (android.content.Intent)8 Handler (android.os.Handler)3 SyncService (com.onesignal.SyncService)3 EventManager (roboguice.event.EventManager)3 Activity (android.app.Activity)2 Application (android.app.Application)2 IntentService (android.app.IntentService)2 Context (android.content.Context)2 Configuration (android.content.res.Configuration)2 IBinder (android.os.IBinder)2 Injector (com.google.inject.Injector)2 Test (org.junit.Test)2 SuppressLint (android.annotation.SuppressLint)1 AlarmManager (android.app.AlarmManager)1 Notification (android.app.Notification)1 NotificationManager (android.app.NotificationManager)1 SearchManager (android.app.SearchManager)1 BroadcastReceiver (android.content.BroadcastReceiver)1