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;
}
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;
}
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);
}
}
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;
}
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;
}
Aggregations