Search in sources :

Example 61 with ServiceInfo

use of android.content.pm.ServiceInfo in project DroidPlugin by DroidPluginTeam.

the class IActivityManagerHookHandle method replaceFirstServiceIntentOfArgs.

private static ServiceInfo replaceFirstServiceIntentOfArgs(Object[] args) throws RemoteException {
    int intentOfArgIndex = findFirstIntentIndexInArgs(args);
    if (args != null && args.length > 1 && intentOfArgIndex >= 0) {
        Intent intent = (Intent) args[intentOfArgIndex];
        ServiceInfo serviceInfo = resolveService(intent);
        if (serviceInfo != null && isPackagePlugin(serviceInfo.packageName)) {
            ServiceInfo proxyService = selectProxyService(intent);
            if (proxyService != null) {
                Intent newIntent = new Intent();
                //FIXBUG:https://github.com/Qihoo360/DroidPlugin/issues/122
                //如果插件中有两个Service:ServiceA和ServiceB,在bind ServiceA的时候会调用ServiceA的onBind并返回其IBinder对象,
                // 但是再次bind ServiceA的时候还是会返回ServiceA的IBinder对象,这是因为插件系统对多个Service使用了同一个StubService
                // 来代理,而系统对StubService的IBinder做了缓存的问题。这里设置一个Action则会穿透这种缓存。
                newIntent.setAction(proxyService.name + new Random().nextInt());
                newIntent.setClassName(proxyService.packageName, proxyService.name);
                newIntent.putExtra(Env.EXTRA_TARGET_INTENT, intent);
                newIntent.setFlags(intent.getFlags());
                args[intentOfArgIndex] = newIntent;
                return serviceInfo;
            }
        }
    }
    return null;
}
Also used : ServiceInfo(android.content.pm.ServiceInfo) Random(java.util.Random) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent)

Example 62 with ServiceInfo

use of android.content.pm.ServiceInfo in project DroidPlugin by DroidPluginTeam.

the class PluginPackageParser method getServiceInfo.

public ServiceInfo getServiceInfo(ComponentName className, int flags) throws Exception {
    Object data;
    synchronized (mServiceObjCache) {
        data = mServiceObjCache.get(className);
    }
    if (data != null) {
        ServiceInfo serviceInfo = mParser.generateServiceInfo(data, flags);
        fixApplicationInfo(serviceInfo.applicationInfo);
        if (TextUtils.isEmpty(serviceInfo.processName)) {
            serviceInfo.processName = serviceInfo.packageName;
        }
        return serviceInfo;
    }
    return null;
}
Also used : ServiceInfo(android.content.pm.ServiceInfo)

Example 63 with ServiceInfo

use of android.content.pm.ServiceInfo 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 64 with ServiceInfo

use of android.content.pm.ServiceInfo 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 65 with ServiceInfo

use of android.content.pm.ServiceInfo in project DroidPlugin by DroidPluginTeam.

the class ServcesManager method stopService.

public int stopService(Context context, Intent intent) throws Exception {
    ServiceInfo targetInfo = PluginManager.getInstance().resolveServiceInfo(intent, 0);
    if (targetInfo != null) {
        handleOnUnbindOne(intent);
        handleOnDestroyOne(targetInfo);
        return 1;
    }
    return 0;
}
Also used : ServiceInfo(android.content.pm.ServiceInfo)

Aggregations

ServiceInfo (android.content.pm.ServiceInfo)238 ResolveInfo (android.content.pm.ResolveInfo)120 Intent (android.content.Intent)99 ComponentName (android.content.ComponentName)96 PackageManager (android.content.pm.PackageManager)62 RemoteException (android.os.RemoteException)48 PendingIntent (android.app.PendingIntent)37 ApplicationInfo (android.content.pm.ApplicationInfo)35 AccessibilityServiceInfo (android.accessibilityservice.AccessibilityServiceInfo)32 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)29 IOException (java.io.IOException)28 ArrayList (java.util.ArrayList)27 InputMethodInfo (android.view.inputmethod.InputMethodInfo)21 PackageInfo (android.content.pm.PackageInfo)18 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)16 Service (android.app.Service)13 Point (android.graphics.Point)11 SpellCheckerInfo (android.view.textservice.SpellCheckerInfo)11 ArraySet (android.util.ArraySet)10 ActivityInfo (android.content.pm.ActivityInfo)9