类android.os.IInterface源码实例Demo

下面列出了怎么用android.os.IInterface的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: Noyze   文件: PopupWindowManager.java
/** 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;
       }
}
 
/**
 * 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);
        }
    }
}
 
源代码3 项目: android_9.0.0_r45   文件: VrManagerService.java
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);
        }
    });
}
 
源代码4 项目: Noyze   文件: AudioHelper.java
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;
}
 
源代码5 项目: Noyze   文件: ReflectionUtils.java
/**
  * 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;
 }
 
源代码6 项目: DoraemonKit   文件: BinderHookHandler.java
@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);
    }
}
 
源代码7 项目: Noyze   文件: AudioHelper.java
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();
}
 
源代码8 项目: springreplugin   文件: ServiceWrapper.java
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);
}
 
源代码9 项目: Noyze   文件: AudioHelper.java
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);
}
 
源代码10 项目: container   文件: ProxyServiceFactory.java
@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;
					}
				}
			};
		}
	};
}
 
源代码11 项目: container   文件: ProxyServiceFactory.java
@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;
					}
				}
			};
		}
	};
}
 
源代码12 项目: Noyze   文件: PopupWindowManager.java
/** 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;
       }
}
 
源代码13 项目: android_9.0.0_r45   文件: ManagedServices.java
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;
}
 
源代码14 项目: android_9.0.0_r45   文件: ManagedServices.java
protected boolean isServiceTokenValidLocked(IInterface service) {
    if (service == null) {
        return false;
    }
    ManagedServiceInfo info = getServiceFromTokenLocked(service);
    if (info != null) {
        return true;
    }
    return false;
}
 
源代码15 项目: android_9.0.0_r45   文件: ManagedServices.java
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());
}
 
源代码16 项目: android_9.0.0_r45   文件: ManagedServices.java
public void registerService(IInterface service, ComponentName component, int userid) {
    checkNotNull(service);
    ManagedServiceInfo info = registerServiceImpl(service, component, userid);
    if (info != null) {
        onServiceAdded(info);
    }
}
 
源代码17 项目: container   文件: VActivityManager.java
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);
    }
}
 
源代码18 项目: android_9.0.0_r45   文件: ManagedServices.java
/**
 * 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);
    }
}
 
源代码19 项目: Telegram   文件: ICustomTabsService.java
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));
    }
}
 
源代码20 项目: android_9.0.0_r45   文件: GeofenceHardwareImpl.java
/**
 * 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();
  }
}
 
源代码21 项目: TelePlus-Android   文件: ICustomTabsService.java
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));
    }
}
 
源代码22 项目: Telegram-FOSS   文件: ICustomTabsService.java
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));
    }
}
 
源代码23 项目: TelePlus-Android   文件: ICustomTabsCallback.java
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));
    }
}
 
源代码24 项目: deagle   文件: Services.java
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);
}
 
源代码25 项目: TelePlus-Android   文件: ICustomTabsService.java
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));
    }
}
 
源代码26 项目: travelguide   文件: ILicenseResultListener.java
/**
 * 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);
}
 
源代码27 项目: text_converter   文件: ILicenseResultListener.java
/**
 * 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);
}
 
源代码28 项目: letv   文件: IApkManager.java
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;
}
 
源代码29 项目: Noyze   文件: PopupWindowManager.java
/** @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;
}
 
源代码30 项目: letv   文件: IDownloadService.java
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;
}
 
 类所在包
 类方法
 同包方法