android.os.IInterface Java Examples

The following examples show how to use android.os.IInterface. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: Noyze   Author: Tombarr   File: PopupWindowManager.java    License: Apache License 2.0 6 votes vote down vote up
/** Register an {@link IRotationWatcher} with IWindowManager. */
protected static boolean watchRotations(IRotationWatcher watcher, final boolean watch) {
	// NOTE: removeRotationWatcher is only available on Android 4.3 (API 18) and 4.4 (API 19 & 20).
	final String methodName = ((watch) ? "watchRotation" : "removeRotationWatcher" );
	final IInterface mWM = getIWindowManager();
       if (null == mWM) return false;
       
       try {
           Method mMethod = mWM.getClass().getDeclaredMethod(
           	methodName, new Class[]{ IRotationWatcher.class });
           if (mMethod == null) return false;
           mMethod.setAccessible(true);
           mMethod.invoke(mWM, watcher);

           return true;
       } catch (Throwable t) {
           Log.e(TAG, "Cannot register " + IRotationWatcher.class.getSimpleName() , t);
           return false;
       }
}
 
Example #2
Source Project: android_9.0.0_r45   Author: lulululbj   File: ManagedApplicationService.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Send an event to run as soon as the binder interface is available.
 *
 * @param event a {@link PendingEvent} to send.
 */
public void sendEvent(@NonNull PendingEvent event) {
    IInterface iface;
    synchronized (mLock) {
        iface = mBoundInterface;
        if (iface == null) {
            mPendingEvent = event;
        }
    }

    if (iface != null) {
        try {
            event.runEvent(iface);
        } catch (RuntimeException | RemoteException ex) {
            Slog.e(TAG, "Received exception from user service: ", ex);
        }
    }
}
 
Example #3
Source Project: android_9.0.0_r45   Author: lulululbj   File: VrManagerService.java    License: Apache License 2.0 6 votes vote down vote up
private void callFocusedActivityChangedLocked() {
    final ComponentName c = mCurrentVrModeComponent;
    final boolean b = mRunning2dInVr;
    final int pid = mVrAppProcessId;
    mCurrentVrService.sendEvent(new PendingEvent() {
        @Override
        public void runEvent(IInterface service) throws RemoteException {
            // Under specific (and unlikely) timing scenarios, when VrCore
            // crashes and is rebound, focusedActivityChanged() may be
            // called a 2nd time with the same arguments. IVrListeners
            // should make sure to handle that scenario gracefully.
            IVrListener l = (IVrListener) service;
            l.focusedActivityChanged(c, b, pid);
        }
    });
}
 
Example #4
Source Project: Noyze   Author: Tombarr   File: AudioHelper.java    License: Apache License 2.0 6 votes vote down vote up
public static boolean _dispatchMediaKeyEvent(KeyEvent event) {
    try {
        IInterface service = getService();
        if (null == mDispatchMediaKeyEvent)
            mDispatchMediaKeyEvent = service.getClass().getDeclaredMethod(
                    "dispatchMediaKeyEvent", KeyEvent.class);
        if (null != mDispatchMediaKeyEvent) {
            mDispatchMediaKeyEvent.setAccessible(true);
            mDispatchMediaKeyEvent.invoke(service, event);
            return true;
        }
    } catch (Throwable t) {
        LOGE(TAG, "Error dispatchMediaKeyEvent()", t);
    }
    return false;
}
 
Example #5
Source Project: Noyze   Author: Tombarr   File: ReflectionUtils.java    License: Apache License 2.0 6 votes vote down vote up
/**
  * ServiceManager.getService(String name)
  * Obtains an {@link IBinder} reference of a system service.
  */
 public static IBinder getService(String name) {
     try {
     	final IInterface mService = ReflectionUtils.getIServiceManager();
Method mMethod = mService.getClass().getDeclaredMethod(
	"getService", new Class[] { String.class });

if (mMethod == null) return null;
mMethod.setAccessible(true);
return (IBinder) mMethod.invoke(mService, name);        	
     } catch (Throwable e) {
         LogUtils.LOGE("Reflection", "Error accessing ServiceManager.getService().", e);
     }
     
     return null;
 }
 
Example #6
Source Project: DoraemonKit   Author: didi   File: BinderHookHandler.java    License: Apache License 2.0 6 votes vote down vote up
@Override
@SuppressLint("PrivateApi")
public Object invoke(Object proxy, Method method, Object[] args) throws InvocationTargetException, IllegalAccessException {
    switch (method.getName()) {
        case "queryLocalInterface":
            Class iManager;
            try {
                iManager = Class.forName(String.valueOf(args[0]));
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
                return method.invoke(mOriginService, args);
            }
            ClassLoader classLoader = mOriginService.getClass().getClassLoader();
            Class[] interfaces = new Class[]{IInterface.class, IBinder.class, iManager};
            return Proxy.newProxyInstance(classLoader, interfaces, mHooker);
        default:
            return method.invoke(mOriginService, args);
    }
}
 
Example #7
Source Project: Noyze   Author: Tombarr   File: AudioHelper.java    License: Apache License 2.0 6 votes vote down vote up
public static Object _iaudioServiceMethod(String methodName, Object[] vals) {
    try {
        IInterface service = getService();
        if (null != service) {
            String methodMapName = methodMapName(service.getClass(), methodName);
            if (!shouldTryMethod(methodMapName)) return null;
            boolean hadMethod = mMethodMap.containsKey(methodMapName);
            Method bMethod = (hadMethod) ? mMethodMap.get(methodMapName) :
                    service.getClass().getDeclaredMethod(methodName, fromObjects(vals));
            if (null != bMethod) {
                bMethod.setAccessible(true);
                if (!hadMethod) mMethodMap.put(methodMapName, bMethod);
                Object ret = bMethod.invoke(service, vals);
                mMethodSuccessMap.put(methodMapName, null != ret);
                if (null != ret) return ret;
            }
        }
    } catch (Throwable t) {
        LOGE(TAG, "Error invoking AudioService#" + methodName, t);
        return null;
    }
    return new Object();
}
 
Example #8
Source Project: springreplugin   Author: wangyupeng1-iri   File: ServiceWrapper.java    License: Apache License 2.0 6 votes vote down vote up
public static IBinder factory(Context context, String name, IBinder binder) {
    String descriptor = null;
    try {
        descriptor = binder.getInterfaceDescriptor();
    } catch (RemoteException e) {
        if (DEBUG) {
            Log.d(TAG, "getInterfaceDescriptor()", e);
        }
    }
    android.os.IInterface iin = binder.queryLocalInterface(descriptor);
    if (iin != null) {
        /**
         * If the requested interface has local implementation, meaning that
         * it's living in the same process as the one who requests for it,
         * return the binder directly since in such cases our wrapper does
         * not help in any way.
         */
        return binder;
    }
    return new ServiceWrapper(context, name, binder);
}
 
Example #9
Source Project: Noyze   Author: Tombarr   File: AudioHelper.java    License: Apache License 2.0 6 votes vote down vote up
public void closeSystemDialogs(Context context, String reason) {
    LOGI(TAG, "closeSystemDialogs(" + reason + ')');
    IInterface wm = PopupWindowManager.getIWindowManager();
    try {
        if (null == wmCsd)
            wmCsd = wm.getClass().getDeclaredMethod("closeSystemDialogs", String.class);
        if (null != wmCsd) {
            wmCsd.setAccessible(true);
            wmCsd.invoke(wm, reason);
            return;
        }
    } catch (Throwable t) {
        LOGE(TAG, "Could not invoke IWindowManager#closeSystemDialogs");
    }

    // Backup is to send the intent ourselves.
    Intent intent = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
    intent.putExtra("reason", reason);
    context.sendBroadcast(intent);
}
 
Example #10
Source Project: container   Author: codehz   File: ProxyServiceFactory.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public IBinder getService(final Context context, ClassLoader classLoader, IBinder binder) {
	return new StubBinder(classLoader, binder) {
		@Override
		public InvocationHandler createHandler(Class<?> interfaceClass, final IInterface base) {
			return new InvocationHandler() {
				@Override
				public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
					try {
						return method.invoke(base, args);
					} catch (InvocationTargetException e) {
						if (e.getCause() != null) {
							throw e.getCause();
						}
						throw e;
					}
				}
			};
		}
	};
}
 
Example #11
Source Project: container   Author: codehz   File: ProxyServiceFactory.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public IBinder getService(final Context context, ClassLoader classLoader, IBinder binder) {
	return new StubBinder(classLoader, binder) {
		@Override
		public InvocationHandler createHandler(Class<?> interfaceClass, final IInterface base) {
			return new InvocationHandler() {
				@Override
				public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
					try {
						return method.invoke(base, args);
					} catch (InvocationTargetException e) {
						if (e.getCause() != null) {
							throw e.getCause();
						}
						throw e;
					}
				}
			};
		}
	};
}
 
Example #12
Source Project: Noyze   Author: Tombarr   File: PopupWindowManager.java    License: Apache License 2.0 6 votes vote down vote up
/** Register an {@link IRotationWatcher} with IWindowManager. */
protected static boolean watchRotations(IRotationWatcher watcher, final boolean watch) {
	// NOTE: removeRotationWatcher is only available on Android 4.3 (API 18) and 4.4 (API 19 & 20).
	final String methodName = ((watch) ? "watchRotation" : "removeRotationWatcher" );
	final IInterface mWM = getIWindowManager();
       if (null == mWM) return false;
       
       try {
           Method mMethod = mWM.getClass().getDeclaredMethod(
           	methodName, new Class[]{ IRotationWatcher.class });
           if (mMethod == null) return false;
           mMethod.setAccessible(true);
           mMethod.invoke(mWM, watcher);

           return true;
       } catch (Throwable t) {
           Log.e(TAG, "Cannot register " + IRotationWatcher.class.getSimpleName() , t);
           return false;
       }
}
 
Example #13
Source Project: android_9.0.0_r45   Author: lulululbj   File: ManagedServices.java    License: Apache License 2.0 5 votes vote down vote up
private ManagedServiceInfo getServiceFromTokenLocked(IInterface service) {
    if (service == null) {
        return null;
    }
    final IBinder token = service.asBinder();
    final int N = mServices.size();
    for (int i = 0; i < N; i++) {
        final ManagedServiceInfo info = mServices.get(i);
        if (info.service.asBinder() == token) return info;
    }
    return null;
}
 
Example #14
Source Project: android_9.0.0_r45   Author: lulululbj   File: ManagedServices.java    License: Apache License 2.0 5 votes vote down vote up
protected boolean isServiceTokenValidLocked(IInterface service) {
    if (service == null) {
        return false;
    }
    ManagedServiceInfo info = getServiceFromTokenLocked(service);
    if (info != null) {
        return true;
    }
    return false;
}
 
Example #15
Source Project: android_9.0.0_r45   Author: lulululbj   File: ManagedServices.java    License: Apache License 2.0 5 votes vote down vote up
protected ManagedServiceInfo checkServiceTokenLocked(IInterface service) {
    checkNotNull(service);
    ManagedServiceInfo info = getServiceFromTokenLocked(service);
    if (info != null) {
        return info;
    }
    throw new SecurityException("Disallowed call from unknown " + getCaption() + ": "
            + service + " " + service.getClass());
}
 
Example #16
Source Project: android_9.0.0_r45   Author: lulululbj   File: ManagedServices.java    License: Apache License 2.0 5 votes vote down vote up
public void registerService(IInterface service, ComponentName component, int userid) {
    checkNotNull(service);
    ManagedServiceInfo info = registerServiceImpl(service, component, userid);
    if (info != null) {
        onServiceAdded(info);
    }
}
 
Example #17
Source Project: container   Author: codehz   File: VActivityManager.java    License: GNU General Public License v3.0 5 votes vote down vote up
public ComponentName startService(IInterface caller, Intent service, String resolvedType, int userId) {
    try {
        return getService().startService(caller != null ? caller.asBinder() : null, service, resolvedType, userId);
    } catch (RemoteException e) {
        return VirtualRuntime.crash(e);
    }
}
 
Example #18
Source Project: android_9.0.0_r45   Author: lulululbj   File: ManagedServices.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Removes a service from the list and unbinds.
 */
private void unregisterServiceImpl(IInterface service, int userid) {
    ManagedServiceInfo info = removeServiceImpl(service, userid);
    if (info != null && info.connection != null && !info.isGuest(this)) {
        mContext.unbindService(info.connection);
    }
}
 
Example #19
Source Project: Telegram   Author: DrKLO   File: ICustomTabsService.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static ICustomTabsService asInterface(IBinder obj) {
    if(obj == null) {
        return null;
    } else {
        IInterface iin = obj.queryLocalInterface("android.support.customtabs.ICustomTabsService");
        return (iin != null && iin instanceof ICustomTabsService?(ICustomTabsService)iin:new ICustomTabsService.Stub.Proxy(obj));
    }
}
 
Example #20
Source Project: android_9.0.0_r45   Author: lulululbj   File: GeofenceHardwareImpl.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Compares the underlying Binder of the given two IInterface objects and returns true if
 * they equals. null values are accepted.
 */
private boolean binderEquals(IInterface left, IInterface right) {
  if (left == null) {
    return right == null;
  } else {
    return right == null ? false : left.asBinder() == right.asBinder();
  }
}
 
Example #21
Source Project: TelePlus-Android   Author: TelePlusDev   File: ICustomTabsService.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static ICustomTabsService asInterface(IBinder obj) {
    if(obj == null) {
        return null;
    } else {
        IInterface iin = obj.queryLocalInterface("android.support.customtabs.ICustomTabsService");
        return (iin != null && iin instanceof ICustomTabsService?(ICustomTabsService)iin:new ICustomTabsService.Stub.Proxy(obj));
    }
}
 
Example #22
Source Project: Telegram-FOSS   Author: Telegram-FOSS-Team   File: ICustomTabsService.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static ICustomTabsService asInterface(IBinder obj) {
    if(obj == null) {
        return null;
    } else {
        IInterface iin = obj.queryLocalInterface("android.support.customtabs.ICustomTabsService");
        return (iin != null && iin instanceof ICustomTabsService?(ICustomTabsService)iin:new ICustomTabsService.Stub.Proxy(obj));
    }
}
 
Example #23
Source Project: TelePlus-Android   Author: TelePlusDev   File: ICustomTabsCallback.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static ICustomTabsCallback asInterface(IBinder obj) {
    if(obj == null) {
        return null;
    } else {
        IInterface iin = obj.queryLocalInterface("android.support.customtabs.ICustomTabsCallback");
        return (iin != null && iin instanceof ICustomTabsCallback?(ICustomTabsCallback)iin:new ICustomTabsCallback.Stub.Proxy(obj));
    }
}
 
Example #24
Source Project: deagle   Author: oasisfeng   File: Services.java    License: Apache License 2.0 5 votes vote down vote up
public static <I extends IInterface> void register(final Class<I> service_interface, final I instance) {
	final IInterface existent = sRegistry.get(service_interface);
	if (existent != null) {
		if (existent == instance) return;
		throw new IllegalStateException(service_interface + " was already registered with " + existent.getClass());
	}
	sRegistry.put(service_interface, instance);
}
 
Example #25
Source Project: TelePlus-Android   Author: TelePlusDev   File: ICustomTabsService.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static ICustomTabsService asInterface(IBinder obj) {
    if(obj == null) {
        return null;
    } else {
        IInterface iin = obj.queryLocalInterface("android.support.customtabs.ICustomTabsService");
        return (iin != null && iin instanceof ICustomTabsService?(ICustomTabsService)iin:new ICustomTabsService.Stub.Proxy(obj));
    }
}
 
Example #26
Source Project: travelguide   Author: mapsme   File: ILicenseResultListener.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Cast an IBinder object into an ILicenseResultListener interface,
 * generating a proxy if needed.
 */
public static com.google.android.vending.licensing.ILicenseResultListener asInterface(android.os.IBinder obj)
{
if ((obj==null)) {
return null;
}
android.os.IInterface iin = (android.os.IInterface)obj.queryLocalInterface(DESCRIPTOR);
if (((iin!=null)&&(iin instanceof com.google.android.vending.licensing.ILicenseResultListener))) {
return ((com.google.android.vending.licensing.ILicenseResultListener)iin);
}
return new com.google.android.vending.licensing.ILicenseResultListener.Stub.Proxy(obj);
}
 
Example #27
Source Project: text_converter   Author: tranleduy2000   File: ILicenseResultListener.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Cast an IBinder object into an ILicenseResultListener interface,
 * generating a proxy if needed.
 */
public static com.google.android.vending.licensing.ILicenseResultListener asInterface(android.os.IBinder obj)
{
if ((obj==null)) {
return null;
}
android.os.IInterface iin = (android.os.IInterface)obj.queryLocalInterface(DESCRIPTOR);
if (((iin!=null)&&(iin instanceof com.google.android.vending.licensing.ILicenseResultListener))) {
return ((com.google.android.vending.licensing.ILicenseResultListener)iin);
}
return new com.google.android.vending.licensing.ILicenseResultListener.Stub.Proxy(obj);
}
 
Example #28
Source Project: letv   Author: JackChan1999   File: IApkManager.java    License: Apache License 2.0 5 votes vote down vote up
public static IApkManager asInterface(IBinder obj) {
    if (obj == null) {
        return null;
    }
    IInterface iin = obj.queryLocalInterface(DESCRIPTOR);
    if (iin == null || !(iin instanceof IApkManager)) {
        return new Proxy(obj);
    }
    return (IApkManager) iin;
}
 
Example #29
Source Project: Noyze   Author: Tombarr   File: PopupWindowManager.java    License: Apache License 2.0 5 votes vote down vote up
/** @return An instance of android.view.IWindowManager. */
public synchronized static IInterface getIWindowManager() {
	if (null == iWindowManager) {
		iWindowManager = ReflectionUtils.getIInterface(
                   Context.WINDOW_SERVICE, "android.view.IWindowManager$Stub");
	}
	return iWindowManager;
}
 
Example #30
Source Project: letv   Author: JackChan1999   File: IDownloadService.java    License: Apache License 2.0 5 votes vote down vote up
public static IDownloadService asInterface(IBinder obj) {
    if (obj == null) {
        return null;
    }
    IInterface iin = obj.queryLocalInterface(DESCRIPTOR);
    if (iin == null || !(iin instanceof IDownloadService)) {
        return new Proxy(obj);
    }
    return (IDownloadService) iin;
}