Search in sources :

Example 16 with IInterface

use of android.os.IInterface in project android_frameworks_base by ResurrectionRemix.

the class ManagedServices method registerServiceLocked.

private void registerServiceLocked(final ComponentName name, final int userid, final boolean isSystem) {
    if (DEBUG)
        Slog.v(TAG, "registerService: " + name + " u=" + userid);
    final String servicesBindingTag = name.toString() + "/" + userid;
    if (mServicesBinding.contains(servicesBindingTag)) {
        // stop registering this thing already! we're working on it
        return;
    }
    mServicesBinding.add(servicesBindingTag);
    final int N = mServices.size();
    for (int i = N - 1; i >= 0; i--) {
        final ManagedServiceInfo info = mServices.get(i);
        if (name.equals(info.component) && info.userid == userid) {
            // cut old connections
            if (DEBUG)
                Slog.v(TAG, "    disconnecting old " + getCaption() + ": " + info.service);
            removeServiceLocked(i);
            if (info.connection != null) {
                mContext.unbindService(info.connection);
            }
        }
    }
    Intent intent = new Intent(mConfig.serviceInterface);
    intent.setComponent(name);
    intent.putExtra(Intent.EXTRA_CLIENT_LABEL, mConfig.clientLabel);
    final PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, new Intent(mConfig.settingsAction), 0);
    intent.putExtra(Intent.EXTRA_CLIENT_INTENT, pendingIntent);
    ApplicationInfo appInfo = null;
    try {
        appInfo = mContext.getPackageManager().getApplicationInfo(name.getPackageName(), 0);
    } catch (NameNotFoundException e) {
    // Ignore if the package doesn't exist we won't be able to bind to the service.
    }
    final int targetSdkVersion = appInfo != null ? appInfo.targetSdkVersion : Build.VERSION_CODES.BASE;
    try {
        if (DEBUG)
            Slog.v(TAG, "binding: " + intent);
        ServiceConnection serviceConnection = new ServiceConnection() {

            IInterface mService;

            @Override
            public void onServiceConnected(ComponentName name, IBinder binder) {
                boolean added = false;
                ManagedServiceInfo info = null;
                synchronized (mMutex) {
                    mServicesBinding.remove(servicesBindingTag);
                    try {
                        mService = asInterface(binder);
                        info = newServiceInfo(mService, name, userid, isSystem, this, targetSdkVersion);
                        binder.linkToDeath(info, 0);
                        added = mServices.add(info);
                    } catch (RemoteException e) {
                    // already dead
                    }
                }
                if (added) {
                    onServiceAdded(info);
                }
            }

            @Override
            public void onServiceDisconnected(ComponentName name) {
                Slog.v(TAG, getCaption() + " connection lost: " + name);
            }
        };
        if (!mContext.bindServiceAsUser(intent, serviceConnection, BIND_AUTO_CREATE | BIND_FOREGROUND_SERVICE | BIND_ALLOW_WHITELIST_MANAGEMENT, new UserHandle(userid))) {
            mServicesBinding.remove(servicesBindingTag);
            Slog.w(TAG, "Unable to bind " + getCaption() + " service: " + intent);
            return;
        }
    } catch (SecurityException ex) {
        Slog.e(TAG, "Unable to bind " + getCaption() + " service: " + intent, ex);
        return;
    }
}
Also used : ServiceConnection(android.content.ServiceConnection) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) ApplicationInfo(android.content.pm.ApplicationInfo) IInterface(android.os.IInterface) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) IBinder(android.os.IBinder) UserHandle(android.os.UserHandle) ComponentName(android.content.ComponentName) PendingIntent(android.app.PendingIntent) RemoteException(android.os.RemoteException)

Example 17 with IInterface

use of android.os.IInterface in project android_frameworks_base by ResurrectionRemix.

the class VrManagerService method updateCurrentVrServiceLocked.

/**
     * Send VR mode changes (if the mode state has changed), and update the bound/unbound state of
     * the currently selected VR listener service.  If the component selected for the VR listener
     * service has changed, unbind the previous listener and bind the new listener (if enabled).
     * <p/>
     * Note: Must be called while holding {@code mLock}.
     *
     * @param enabled new state for VR mode.
     * @param component new component to be bound as a VR listener.
     * @param userId user owning the component to be bound.
     * @param calling the component currently using VR mode, or null to leave unchanged.
     *
     * @return {@code true} if the component/user combination specified is valid.
     */
private boolean updateCurrentVrServiceLocked(boolean enabled, @NonNull ComponentName component, int userId, ComponentName calling) {
    boolean sendUpdatedCaller = false;
    final long identity = Binder.clearCallingIdentity();
    try {
        boolean validUserComponent = (mComponentObserver.isValid(component, userId) == EnabledComponentsObserver.NO_ERROR);
        boolean goingIntoVrMode = validUserComponent && enabled;
        if (!mVrModeEnabled && !goingIntoVrMode) {
            // Disabled -> Disabled transition does nothing.
            return validUserComponent;
        }
        String oldVrServicePackage = mCurrentVrService != null ? mCurrentVrService.getComponent().getPackageName() : null;
        final int oldUserId = mCurrentVrModeUser;
        // Notify system services and VR HAL of mode change.
        changeVrModeLocked(goingIntoVrMode);
        boolean nothingChanged = false;
        if (!goingIntoVrMode) {
            // Not going into VR mode, unbind whatever is running
            if (mCurrentVrService != null) {
                Slog.i(TAG, "Leaving VR mode, disconnecting " + mCurrentVrService.getComponent() + " for user " + mCurrentVrService.getUserId());
                mCurrentVrService.disconnect();
                mCurrentVrService = null;
            } else {
                nothingChanged = true;
            }
        } else {
            // Going into VR mode
            if (mCurrentVrService != null) {
                // selection.
                if (mCurrentVrService.disconnectIfNotMatching(component, userId)) {
                    Slog.i(TAG, "VR mode component changed to " + component + ", disconnecting " + mCurrentVrService.getComponent() + " for user " + mCurrentVrService.getUserId());
                    createAndConnectService(component, userId);
                    sendUpdatedCaller = true;
                } else {
                    nothingChanged = true;
                }
            // The service with the correct component/user is already bound, do nothing.
            } else {
                // Nothing was previously running, bind a new service for the latest
                // component/user selection.
                createAndConnectService(component, userId);
                sendUpdatedCaller = true;
            }
        }
        if (calling != null && !Objects.equals(calling, mCurrentVrModeComponent)) {
            mCurrentVrModeComponent = calling;
            sendUpdatedCaller = true;
        }
        if (mCurrentVrModeUser != userId) {
            mCurrentVrModeUser = userId;
            sendUpdatedCaller = true;
        }
        String newVrServicePackage = mCurrentVrService != null ? mCurrentVrService.getComponent().getPackageName() : null;
        final int newUserId = mCurrentVrModeUser;
        // Update AppOps settings that change state when entering/exiting VR mode, or changing
        // the current VrListenerService.
        updateDependentAppOpsLocked(newVrServicePackage, newUserId, oldVrServicePackage, oldUserId);
        if (mCurrentVrService != null && sendUpdatedCaller) {
            final ComponentName c = mCurrentVrModeComponent;
            mCurrentVrService.sendEvent(new PendingEvent() {

                @Override
                public void runEvent(IInterface service) throws RemoteException {
                    IVrListener l = (IVrListener) service;
                    l.focusedActivityChanged(c);
                }
            });
        }
        if (!nothingChanged) {
            logStateLocked();
        }
        return validUserComponent;
    } finally {
        Binder.restoreCallingIdentity(identity);
    }
}
Also used : PendingEvent(com.android.server.utils.ManagedApplicationService.PendingEvent) IInterface(android.os.IInterface) ComponentName(android.content.ComponentName) IVrListener(android.service.vr.IVrListener) RemoteException(android.os.RemoteException)

Example 18 with IInterface

use of android.os.IInterface in project VirtualApp by asLody.

the class BindService method call.

@Override
public Object call(Object who, Method method, Object... args) throws Throwable {
    IInterface caller = (IInterface) args[0];
    IBinder token = (IBinder) args[1];
    Intent service = (Intent) args[2];
    String resolvedType = (String) args[3];
    IServiceConnection conn = (IServiceConnection) args[4];
    int flags = (int) args[5];
    int userId = VUserHandle.myUserId();
    if (isServerProcess()) {
        userId = service.getIntExtra("_VA_|_user_id_", VUserHandle.USER_NULL);
    }
    if (userId == VUserHandle.USER_NULL) {
        return method.invoke(who, args);
    }
    ServiceInfo serviceInfo = VirtualCore.get().resolveServiceInfo(service, userId);
    if (serviceInfo != null) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            service.setComponent(new ComponentName(serviceInfo.packageName, serviceInfo.name));
        }
        conn = ServiceConnectionDelegate.getDelegate(conn);
        return VActivityManager.get().bindService(caller.asBinder(), token, service, resolvedType, conn, flags, userId);
    }
    return method.invoke(who, args);
}
Also used : IServiceConnection(android.app.IServiceConnection) ServiceInfo(android.content.pm.ServiceInfo) IBinder(android.os.IBinder) IInterface(android.os.IInterface) Intent(android.content.Intent) ComponentName(android.content.ComponentName)

Example 19 with IInterface

use of android.os.IInterface in project VirtualApp by asLody.

the class RegisterReceiver method call.

@Override
public Object call(Object who, Method method, Object... args) throws Throwable {
    HookUtils.replaceFirstAppPkg(args);
    args[IDX_RequiredPermission] = null;
    IntentFilter filter = (IntentFilter) args[IDX_IntentFilter];
    IntentFilter backupFilter = new IntentFilter(filter);
    protectIntentFilter(filter);
    if (args.length > IDX_IIntentReceiver && IIntentReceiver.class.isInstance(args[IDX_IIntentReceiver])) {
        final IInterface old = (IInterface) args[IDX_IIntentReceiver];
        if (!IIntentReceiverProxy.class.isInstance(old)) {
            final IBinder token = old.asBinder();
            if (token != null) {
                token.linkToDeath(new IBinder.DeathRecipient() {

                    @Override
                    public void binderDied() {
                        token.unlinkToDeath(this, 0);
                        mProxyIIntentReceivers.remove(token);
                    }
                }, 0);
                IIntentReceiver proxyIIntentReceiver = mProxyIIntentReceivers.get(token);
                if (proxyIIntentReceiver == null) {
                    proxyIIntentReceiver = new IIntentReceiverProxy(old);
                    mProxyIIntentReceivers.put(token, proxyIIntentReceiver);
                }
                WeakReference mDispatcher = LoadedApk.ReceiverDispatcher.InnerReceiver.mDispatcher.get(old);
                if (mDispatcher != null) {
                    LoadedApk.ReceiverDispatcher.mIIntentReceiver.set(mDispatcher.get(), proxyIIntentReceiver);
                    args[IDX_IIntentReceiver] = proxyIIntentReceiver;
                }
            }
        }
    }
    Object res = method.invoke(who, args);
    Intent intent = VActivityManager.get().dispatchStickyBroadcast(backupFilter);
    if (intent != null) {
        return intent;
    }
    return res;
}
Also used : IntentFilter(android.content.IntentFilter) IBinder(android.os.IBinder) WeakReference(java.lang.ref.WeakReference) IInterface(android.os.IInterface) IIntentReceiver(android.content.IIntentReceiver) Intent(android.content.Intent)

Example 20 with IInterface

use of android.os.IInterface in project VirtualApp by asLody.

the class DisplayPatch method isEnvBad.

@Override
public boolean isEnvBad() {
    Object dmg = DisplayManagerGlobal.getInstance.call();
    IInterface mDm = DisplayManagerGlobal.mDm.get(dmg);
    return mDm != getHookDelegate().getProxyInterface();
}
Also used : IInterface(android.os.IInterface)

Aggregations

IInterface (android.os.IInterface)28 RemoteException (android.os.RemoteException)16 ComponentName (android.content.ComponentName)15 Intent (android.content.Intent)14 IBinder (android.os.IBinder)12 PendingIntent (android.app.PendingIntent)11 ServiceConnection (android.content.ServiceConnection)9 UserHandle (android.os.UserHandle)9 ApplicationInfo (android.content.pm.ApplicationInfo)5 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)5 IVrListener (android.service.vr.IVrListener)4 PendingEvent (com.android.server.utils.ManagedApplicationService.PendingEvent)4 ServiceInfo (android.content.pm.ServiceInfo)3 ProviderInfo (android.content.pm.ProviderInfo)2 InvocationHandler (java.lang.reflect.InvocationHandler)2 IServiceConnection (android.app.IServiceConnection)1 ContentProviderClient (android.content.ContentProviderClient)1 ContentResolver (android.content.ContentResolver)1 IIntentReceiver (android.content.IIntentReceiver)1 IntentFilter (android.content.IntentFilter)1