use of android.os.IInterface in project XPrivacy by M66B.
the class XLocationManager method proxyLocationListener.
private void proxyLocationListener(XParam param, int arg, Class<?> interfaze, boolean client) throws Throwable {
if (param.args.length > arg)
if (param.args[arg] instanceof PendingIntent)
param.setResult(null);
else if (param.args[arg] != null && param.thisObject != null) {
if (client) {
Object key = param.args[arg];
synchronized (mMapProxy) {
// Reuse existing proxy
if (mMapProxy.containsKey(key)) {
Util.log(this, Log.INFO, "Reuse existing proxy uid=" + Binder.getCallingUid());
param.args[arg] = mMapProxy.get(key);
return;
}
// Already proxied
if (mMapProxy.containsValue(key)) {
Util.log(this, Log.INFO, "Already proxied uid=" + Binder.getCallingUid());
return;
}
}
// Create proxy
Util.log(this, Log.INFO, "Creating proxy uid=" + Binder.getCallingUid());
Object proxy = new ProxyLocationListener(Binder.getCallingUid(), (LocationListener) param.args[arg]);
// Use proxy
synchronized (mMapProxy) {
mMapProxy.put(key, proxy);
}
param.args[arg] = proxy;
} else {
// Create proxy
ClassLoader cl = param.thisObject.getClass().getClassLoader();
InvocationHandler ih = new OnLocationChangedHandler(Binder.getCallingUid(), param.args[arg]);
Object proxy = Proxy.newProxyInstance(cl, new Class<?>[] { interfaze }, ih);
Object key = param.args[arg];
if (key instanceof IInterface)
key = ((IInterface) key).asBinder();
// Use proxy
synchronized (mMapProxy) {
mMapProxy.put(key, proxy);
}
param.args[arg] = proxy;
}
}
}
use of android.os.IInterface in project platform_frameworks_base by android.
the class ManagedApplicationService method connect.
/**
* Asynchronously bind to the application service if not bound.
*/
public void connect() {
synchronized (mLock) {
if (mConnection != null || mPendingConnection != null) {
// We're already connected or are trying to connect
return;
}
final PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, new Intent(mSettingsAction), 0);
final Intent intent = new Intent().setComponent(mComponent).putExtra(Intent.EXTRA_CLIENT_LABEL, mClientLabel).putExtra(Intent.EXTRA_CLIENT_INTENT, pendingIntent);
final ServiceConnection serviceConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
IInterface iface = null;
PendingEvent pendingEvent = null;
synchronized (mLock) {
if (mPendingConnection == this) {
// No longer pending, remove from pending connection
mPendingConnection = null;
mConnection = this;
} else {
// Service connection wasn't pending, must have been disconnected
mContext.unbindService(this);
return;
}
try {
iBinder.linkToDeath(mDeathRecipient, 0);
mBoundInterface = mChecker.asInterface(iBinder);
if (!mChecker.checkType(mBoundInterface)) {
// Received an invalid binder, disconnect
mContext.unbindService(this);
mBoundInterface = null;
}
iface = mBoundInterface;
pendingEvent = mPendingEvent;
mPendingEvent = null;
} catch (RemoteException e) {
// DOA
Slog.w(TAG, "Unable to bind service: " + intent, e);
mBoundInterface = null;
}
}
if (iface != null && pendingEvent != null) {
try {
pendingEvent.runEvent(iface);
} catch (RuntimeException | RemoteException ex) {
Slog.e(TAG, "Received exception from user service: ", ex);
}
}
}
@Override
public void onServiceDisconnected(ComponentName componentName) {
Slog.w(TAG, "Service disconnected: " + intent);
mConnection = null;
mBoundInterface = null;
}
};
mPendingConnection = serviceConnection;
try {
if (!mContext.bindServiceAsUser(intent, serviceConnection, Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE, new UserHandle(mUserId))) {
Slog.w(TAG, "Unable to bind service: " + intent);
}
} catch (SecurityException e) {
Slog.w(TAG, "Unable to bind service: " + intent, e);
}
}
}
use of android.os.IInterface in project VirtualApp by asLody.
the class StartService method call.
@Override
public Object call(Object who, Method method, Object... args) throws Throwable {
IInterface appThread = (IInterface) args[0];
Intent service = (Intent) args[1];
String resolvedType = (String) args[2];
if (service.getComponent() != null && getHostPkg().equals(service.getComponent().getPackageName())) {
// for server process
return method.invoke(who, args);
}
int userId = VUserHandle.myUserId();
if (service.getBooleanExtra("_VA_|_from_inner_", false)) {
service = service.getParcelableExtra("_VA_|_intent_");
userId = service.getIntExtra("_VA_|_user_id_", userId);
} else {
if (isServerProcess()) {
userId = service.getIntExtra("_VA_|_user_id_", VUserHandle.USER_NULL);
}
}
service.setDataAndType(service.getData(), resolvedType);
ServiceInfo serviceInfo = VirtualCore.get().resolveServiceInfo(service, VUserHandle.myUserId());
if (serviceInfo != null) {
return VActivityManager.get().startService(appThread, service, resolvedType, userId);
}
return method.invoke(who, args);
}
use of android.os.IInterface in project VirtualApp by asLody.
the class StopService method call.
@Override
public Object call(Object who, Method method, Object... args) throws Throwable {
IInterface caller = (IInterface) args[0];
Intent intent = (Intent) args[1];
String resolvedType = (String) args[2];
intent.setDataAndType(intent.getData(), resolvedType);
ComponentName componentName = intent.getComponent();
PackageManager pm = VirtualCore.getPM();
if (componentName == null) {
ResolveInfo resolveInfo = pm.resolveService(intent, 0);
if (resolveInfo != null && resolveInfo.serviceInfo != null) {
componentName = new ComponentName(resolveInfo.serviceInfo.packageName, resolveInfo.serviceInfo.name);
}
}
if (componentName != null && !getHostPkg().equals(componentName.getPackageName())) {
return VActivityManager.get().stopService(caller, intent, resolvedType);
}
return method.invoke(who, args);
}
use of android.os.IInterface in project VirtualApp by asLody.
the class StubBinder method queryLocalInterface.
/**
* Anti the Proguard.
*
* Search the AidlClass.Stub.asInterface(IBinder) method by the StackTrace.
*
*/
@Override
public IInterface queryLocalInterface(String descriptor) {
if (mInterface == null) {
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
if (stackTrace == null || stackTrace.length <= 1) {
return null;
}
Class<?> aidlType = null;
IInterface targetInterface = null;
for (StackTraceElement element : stackTrace) {
if (element.isNativeMethod()) {
continue;
}
try {
Method method = mClassLoader.loadClass(element.getClassName()).getDeclaredMethod(element.getMethodName(), IBinder.class);
if ((method.getModifiers() & Modifier.STATIC) != 0) {
method.setAccessible(true);
Class<?> returnType = method.getReturnType();
if (returnType.isInterface() && IInterface.class.isAssignableFrom(returnType)) {
aidlType = returnType;
targetInterface = (IInterface) method.invoke(null, mBase);
}
}
} catch (Exception e) {
// go to the next cycle
}
}
if (aidlType == null || targetInterface == null) {
return null;
}
InvocationHandler handler = createHandler(aidlType, targetInterface);
mInterface = (IInterface) Proxy.newProxyInstance(mClassLoader, new Class[] { aidlType }, handler);
}
return mInterface;
}
Aggregations