Search in sources :

Example 21 with IInterface

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

the class ProviderHook method createProxy.

public static IInterface createProxy(boolean external, String authority, IInterface provider) {
    if (provider instanceof Proxy && Proxy.getInvocationHandler(provider) instanceof ProviderHook) {
        return provider;
    }
    ProviderHook.HookFetcher fetcher = ProviderHook.fetchHook(authority);
    if (fetcher != null) {
        ProviderHook hook = fetcher.fetch(external, provider);
        IInterface proxyProvider = ProviderHook.createProxy(provider, hook);
        if (proxyProvider != null) {
            provider = proxyProvider;
        }
    }
    return provider;
}
Also used : Proxy(java.lang.reflect.Proxy) IInterface(android.os.IInterface)

Example 22 with IInterface

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

the class PackageManagerPatch method inject.

@Override
public void inject() throws Throwable {
    final IInterface hookedPM = getHookDelegate().getProxyInterface();
    ActivityThread.sPackageManager.set(hookedPM);
    HookBinderDelegate pmHookBinder = new HookBinderDelegate(getHookDelegate().getBaseInterface());
    pmHookBinder.copyHooks(getHookDelegate());
    pmHookBinder.replaceService("package");
}
Also used : IInterface(android.os.IInterface) HookBinderDelegate(com.lody.virtual.client.hook.base.HookBinderDelegate)

Example 23 with IInterface

use of android.os.IInterface in project platform_frameworks_base by android.

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 24 with IInterface

use of android.os.IInterface in project platform_frameworks_base by android.

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);
        if (!mVrModeEnabled && !enabled) {
            // Disabled -> Disabled transition does nothing.
            return validUserComponent;
        }
        String oldVrServicePackage = mCurrentVrService != null ? mCurrentVrService.getComponent().getPackageName() : null;
        final int oldUserId = mCurrentVrModeUser;
        // Always send mode change events.
        changeVrModeLocked(enabled);
        if (!enabled || !validUserComponent) {
            // Unbind whatever is running
            if (mCurrentVrService != null) {
                Slog.i(TAG, "Disconnecting " + mCurrentVrService.getComponent() + " for user " + mCurrentVrService.getUserId());
                mCurrentVrService.disconnect();
                mCurrentVrService = null;
            }
        } else {
            if (mCurrentVrService != null) {
                // Unbind any running service that doesn't match the component/user selection
                if (mCurrentVrService.disconnectIfNotMatching(component, userId)) {
                    Slog.i(TAG, "Disconnecting " + mCurrentVrService.getComponent() + " for user " + mCurrentVrService.getUserId());
                    createAndConnectService(component, userId);
                    sendUpdatedCaller = true;
                }
            // The service with the correct component/user is bound
            } else {
                // Nothing was previously running, bind a new service
                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);
                }
            });
        }
        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 25 with IInterface

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

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);
        }
    }
}
Also used : ServiceConnection(android.content.ServiceConnection) IBinder(android.os.IBinder) UserHandle(android.os.UserHandle) IInterface(android.os.IInterface) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) ComponentName(android.content.ComponentName) PendingIntent(android.app.PendingIntent) RemoteException(android.os.RemoteException)

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