public void showIndicator(View parent, Rect touchBounds) { if (isShowing()) { mPopupView.mMarker.animateOpen(); return; } IBinder windowToken = parent.getWindowToken(); if (windowToken != null) { WindowManager.LayoutParams p = createPopupLayout(windowToken); p.gravity = Gravity.TOP | GravityCompat.START; updateLayoutParamsForPosiion(parent, p, touchBounds.bottom); mShowing = true; translateViewIntoPosition(touchBounds.centerX()); invokePopup(p); } }
@Override public void onHook(ClassLoader classLoader) throws Throwable { //其实有其他的hook点,比如InputMethodManager的sInstance,初始化的时候可以将代理的IInputMethodManager传进构造函数 //现在的这种方式是从获取Binder代理对象的唯一入口ServiceManager开始hook,方便以后hook其他服务 ServiceManagerHook serviceManagerHook = new ServiceManagerHook(mContext, Context.INPUT_METHOD_SERVICE); serviceManagerHook.onHook(classLoader); Object originBinder = serviceManagerHook.getOriginObj(); if (originBinder instanceof IBinder) { mOriginObj = IInputMethodManagerCompat.asInterface((IBinder) originBinder); Object proxyInputMethodInterface = ReflectUtil.makeProxy(classLoader, mOriginObj.getClass(), this); serviceManagerHook.setProxyIInterface(proxyInputMethodInterface); //若hook之前调用过 mContext.getSystemService(Context.INPUT_METHOD_SERVICE) // 则在SystemServiceRegistry中会有缓存,清理缓存后重建才会拿到我们hook的代理 clearCachedService(); //rebuild cache mContext.getSystemService(Context.INPUT_METHOD_SERVICE); } }
@Override public void onServiceConnected(ComponentName name, IBinder service) { Log.d(TAG, "onServiceConnected: " + name.flattenToShortString() + ", " + service.toString()); mUpnpService = (AndroidUpnpService) service; Device device = mUpnpService.getRegistry().getDevice(new UDN(mDeviceUdn), false); mContentDirectoryService = device.findService(new UDAServiceType("ContentDirectory")); if (mContentDirectoryService == null) { throw new IllegalStateException("Unable to find ContentDirectory service for device " + mDeviceUdn); } mDeviceName = (device.getDetails() != null && device.getDetails().getFriendlyName() != null) ? device.getDetails().getFriendlyName() : device.getDisplayString(); selectContainer(mCurrentContainer); }
private void insertConnectionToRecords(ServiceRecord sr, ProcessBindRecord b, IServiceConnection connection, int flags) { ConnectionBindRecord c = new ConnectionBindRecord(b, connection, flags); IBinder binder = connection.asBinder(); // ServiceRecord.connections<Map - Key:IBinder> ArrayList<ConnectionBindRecord> clist = sr.connections.get(binder); if (clist == null) { clist = new ArrayList<>(); sr.connections.put(binder, clist); } clist.add(c); // ProcessBindRecord.connections<List> b.connections.add(c); // ProcessRecord.connections<List> b.client.connections.add(c); // PluginServiceServer.mServiceConnections<Map - Key:IBinder> clist = mServiceConnections.get(binder); if (clist == null) { clist = new ArrayList<>(); mServiceConnections.put(binder, clist); } clist.add(c); }
@Override public Object afterCall(Object who, Method method, Object[] args, Object result) throws Throwable { IBinder token = (IBinder) args[0]; ActivityClientRecord r = VActivityManager.get().getActivityRecord(token); boolean taskRemoved = VActivityManager.get().onActivityDestroy(token); if (!taskRemoved && r != null && r.activity != null && r.info.getThemeResource() != 0) { try { TypedValue out = new TypedValue(); Resources.Theme theme = r.activity.getResources().newTheme(); theme.applyStyle(r.info.getThemeResource(), true); if (theme.resolveAttribute(android.R.attr.windowAnimationStyle, out, true)) { TypedArray array = theme.obtainStyledAttributes(out.data, new int[]{ android.R.attr.activityCloseEnterAnimation, android.R.attr.activityCloseExitAnimation }); r.activity.overridePendingTransition(array.getResourceId(0, 0), array.getResourceId(1, 0)); array.recycle(); } } catch (Throwable e) { e.printStackTrace(); } } return super.afterCall(who, method, args, result); }
private void realStartActivitiesLocked(IBinder resultTo, Intent[] intents, String[] resolvedTypes, Bundle options) { Class<?>[] types = IActivityManager.startActivities.paramList(); Object[] args = new Object[types.length]; if (types[0] == IApplicationThread.TYPE) { args[0] = ActivityThread.getApplicationThread.call(VirtualCore.mainThread()); } int pkgIndex = ArrayUtils.protoIndexOf(types, String.class); int intentsIndex = ArrayUtils.protoIndexOf(types, Intent[].class); int resultToIndex = ArrayUtils.protoIndexOf(types, IBinder.class, 2); int optionsIndex = ArrayUtils.protoIndexOf(types, Bundle.class); int resolvedTypesIndex = intentsIndex + 1; if (pkgIndex != -1) { args[pkgIndex] = VirtualCore.get().getHostPkg(); } args[intentsIndex] = intents; args[resultToIndex] = resultTo; args[resolvedTypesIndex] = resolvedTypes; args[optionsIndex] = options; ClassUtils.fixArgs(types, args); IActivityManager.startActivities.call(ActivityManagerNative.getDefault.call(), (Object[]) args); }
@Override public void onServiceConnected(ComponentName name, IBinder service) { // Ignore this call if we disconnected in the meantime. if (mContext == null) return; mService = new Messenger(service); mComponentName = name; try { Message registerClientMessage = Message.obtain( null, REQUEST_REGISTER_CLIENT); registerClientMessage.replyTo = mMessenger; Bundle b = mGsaHelper.getBundleForRegisteringGSAClient(mContext); registerClientMessage.setData(b); registerClientMessage.getData().putString( KEY_GSA_PACKAGE_NAME, mContext.getPackageName()); mService.send(registerClientMessage); // Send prepare overlay message if there is a pending GSA context. } catch (RemoteException e) { Log.w(SERVICE_CONNECTION_TAG, "GSAServiceConnection - remote call failed", e); } }
@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; } } }; } }; }
void onActivityCreated(ProcessRecord targetApp, ComponentName component, ComponentName caller, IBinder token, Intent taskRoot, String affinity, int taskId, int launchMode, int flags) { synchronized (mHistory) { optimizeTasksLocked(); TaskRecord task = mHistory.get(taskId); if (task == null) { task = new TaskRecord(taskId, targetApp.userId, affinity, taskRoot); mHistory.put(taskId, task); } ActivityRecord record = new ActivityRecord(task, component, caller, token, targetApp.userId, targetApp, launchMode, flags, affinity); synchronized (task.activities) { task.activities.add(record); } } }
private ActivityRecord findActivityByToken(int userId, IBinder token) { ActivityRecord target = null; if (token != null) { for (int i = 0; i < this.mHistory.size(); i++) { TaskRecord task = this.mHistory.valueAt(i); if (task.userId != userId) { continue; } synchronized (task.activities) { for (ActivityRecord r : task.activities) { if (r.token == token) { target = r; } } } } } return target; }
@Override public void onServiceConnected(ComponentName name, IBinder service) { if (!(service instanceof JobService.Binder)) { Log.w(LOG_TAG, "Unknown service connected: " + service); stopJob(this, false); return; } binder = (JobService.Binder) service; if (!binder.startJob(toLocalParameters(params), JobSchedulerJobService.this)) { stopJob(this, false); } }
@Override public void onServiceConnected(ComponentName name, IBinder service) { LocalJettyService.JettyBinder jettyBinder = (LocalJettyService.JettyBinder) service; jettyService = jettyBinder.getService(); Server server = jettyService.getServer(); if(server==null||!server.getState().equals("STARTED")) { LogUtils.d(ConstantValues.LOG_PREFIX+"jetty 未启动,开始启动..."); jettyService.startJetty(); }else { LogUtils.d(ConstantValues.LOG_PREFIX+"jetty 已启动"); } }
public static void hookService(Context context) { IBinder clipboardService = ServiceManager.getService(Context.CLIPBOARD_SERVICE); String IClipboard = "android.content.IClipboard"; if (clipboardService != null) { IBinder hookClipboardService = (IBinder) Proxy.newProxyInstance(clipboardService.getClass().getClassLoader(), clipboardService.getClass().getInterfaces(), new ServiceHook(clipboardService, IClipboard, true, new ClipboardHookHandler())); ServiceManager.setService(Context.CLIPBOARD_SERVICE, hookClipboardService); } else { Log.e(TAG, "ClipboardService hook failed!"); } }
@Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { IBinder binder = getService(selection); BinderCusrsor binderCursor = BinderCusrsor.create(binder); return binderCursor; }
public void onActivityResumed(Activity activity) { IBinder token = mirror.android.app.Activity.mToken.get(activity); try { getService().onActivityResumed(VUserHandle.myUserId(), token); } catch (RemoteException e) { e.printStackTrace(); } }
@Override public void onServiceConnected(ComponentName name, IBinder service) { HSinterface = (HSInterface) service; int i = 2; while (i > 0) { i--; int ret = HSinterface.init(); if (ret == 1) { i = 0; WritableMap result = new WritableNativeMap(); String sam = HSinterface.GetSAM(); result.putString("code", "1"); result.putString("sam", sam); mPromise.resolve(result); return; } else { try { Thread.sleep(200); } catch (InterruptedException e) { e.printStackTrace(); mPromise.reject("0", "connect failed"); } continue; } } mPromise.reject("0", "connect failed"); }
@Override public void installBinder(String name, IBinder binder) throws RemoteException { if (LOG) { LogDebug.d(PLUGIN_TAG, "install binder: n=" + name + " b=" + binder); } synchronized (PluginProcessMain.sBinders) { if (binder != null) { PluginProcessMain.sBinders.put(name, binder); binder.linkToDeath(new BinderDied(name, binder), 0); } else { PluginProcessMain.sBinders.remove(name); } } }
public final int startActivity$Pr(IApplicationThread caller, String callingPackage, Intent intent, String resolvedType, IBinder resultTo, String resultWho, int requestCode, int startFlags, String profileFile, ParcelFileDescriptor profileFd, Bundle options) { throw new UnsupportedOperationException(); }
public boolean shouldSwitchToOtherInputMethods() { // TODO: Revisit here to reorganize the settings. Probably we can/should use different // strategy once the implementation of // {@link InputMethodManager#shouldOfferSwitchingToNextInputMethod} is defined well. final boolean fallbackValue = mSettings.getCurrent().mIncludesOtherImesInLanguageSwitchList; final IBinder token = getWindow().getWindow().getAttributes().token; if (token == null) { return fallbackValue; } return mRichImm.shouldOfferSwitchingToNextInputMethod(token, fallbackValue); }
private void HideSoftInput(IBinder token) { if (token != null) { InputMethodManager manager = (InputMethodManager) activity.getSystemService(activity.INPUT_METHOD_SERVICE); manager.hideSoftInputFromWindow(token, InputMethodManager.HIDE_NOT_ALWAYS); } }
@Override public void onServiceConnected(ComponentName name, IBinder service) { if (service instanceof TcpServerService.TcpServerBinder && mServerState == SERVER_STARTED) { TcpServerService.TcpServerBinder binder = (TcpServerService.TcpServerBinder) service; binder.setListener(getServerServiceListener()); binder.startServer(); } }
private static Object getHardwareService() { Class<?> serviceManagerClass = maybeForName("android.os.ServiceManager"); if (serviceManagerClass == null) { return null; } Method getServiceMethod = maybeGetMethod(serviceManagerClass, "getService", String.class); if (getServiceMethod == null) { return null; } Object hardwareService = invoke(getServiceMethod, null, "hardware"); if (hardwareService == null) { return null; } Class<?> iHardwareServiceStubClass = maybeForName("android.os.IHardwareService$Stub"); if (iHardwareServiceStubClass == null) { return null; } Method asInterfaceMethod = maybeGetMethod(iHardwareServiceStubClass, "asInterface", IBinder.class); if (asInterfaceMethod == null) { return null; } return invoke(asInterfaceMethod, null, hardwareService); }
@Override public IBinder onBind(Intent mIntent) { IBinder mIBinder = super.onBind(mIntent); Log.i(TAG, "onBind"); isNotificationAccessEnabled = true; try { server = new Server(this); server.start(); } catch (Exception e) { Log.e(TAG, "Error during bind", e); } return mIBinder; }
@Override public IBinder onBind(Intent intent) { Log.d(TAG, "in onBind()"); // Called when the App comes to the foreground and binds with this service. stopForeground(true); changingConfiguration = false; return iBinder; }
/** * @param mActivity * @param token */ private void hideSoftInput(Activity mActivity, IBinder token) { if (token != null) { InputMethodManager im = (InputMethodManager) mActivity.getSystemService(Context.INPUT_METHOD_SERVICE); im.hideSoftInputFromWindow(token, InputMethodManager.HIDE_NOT_ALWAYS); } }
private WindowManager.LayoutParams createPopupLayout(IBinder token) { WindowManager.LayoutParams p = new WindowManager.LayoutParams(); p.gravity = Gravity.START | Gravity.TOP; p.width = ViewGroup.LayoutParams.MATCH_PARENT; p.height = ViewGroup.LayoutParams.MATCH_PARENT; p.format = PixelFormat.TRANSLUCENT; p.flags = computeFlags(p.flags); p.type = WindowManager.LayoutParams.TYPE_APPLICATION_PANEL; p.token = token; p.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN; p.setTitle("DiscreteSeekBar Indicator:" + Integer.toHexString(hashCode())); return p; }
private void realStartActivityLocked(IBinder resultTo, Intent intent, String resultWho, int requestCode, Bundle options) { Class<?>[] types = mirror.android.app.IActivityManager.startActivity.paramList(); Object[] args = new Object[types.length]; if (types[0] == IApplicationThread.TYPE) { args[0] = ActivityThread.getApplicationThread.call(VirtualCore.mainThread()); } int intentIndex = ArrayUtils.protoIndexOf(types, Intent.class); int resultToIndex = ArrayUtils.protoIndexOf(types, IBinder.class, 2); int optionsIndex = ArrayUtils.protoIndexOf(types, Bundle.class); int resolvedTypeIndex = intentIndex + 1; int resultWhoIndex = resultToIndex + 1; int requestCodeIndex = resultToIndex + 2; args[intentIndex] = intent; args[resultToIndex] = resultTo; args[resultWhoIndex] = resultWho; args[requestCodeIndex] = requestCode; if (optionsIndex != -1) { args[optionsIndex] = options; } args[resolvedTypeIndex] = intent.getType(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { args[intentIndex - 1] = VirtualCore.get().getHostPkg(); } ClassUtils.fixArgs(types, args); mirror.android.app.IActivityManager.startActivity.call(ActivityManagerNative.getDefault.call(), (Object[]) args); }
public static IResultReceiver asInterface(IBinder obj) { if (obj == null) { return null; } IInterface iin = obj.queryLocalInterface(DESCRIPTOR); if (iin == null || !(iin instanceof IResultReceiver)) { return new Proxy(obj); } return (IResultReceiver) iin; }
/** * Just like {@link BundleCompat#getBinder()}, but doesn't throw exceptions. */ public static IBinder safeGetBinder(Bundle bundle, String name) { if (bundle == null) return null; try { return BundleCompat.getBinder(bundle, name); } catch (Throwable t) { // Catches un-parceling exceptions. Log.e(TAG, "getBinder failed on bundle " + bundle); return null; } }
@Nullable @Override public IBinder onBind(Intent intent) { if (localBinder == null) { localBinder = new LocalBinder(); } return localBinder; }
public static IBinder getBinder(Bundle bundle, String key) { if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { return bundle.getBinder(key); } else { try { return (IBinder) ReflectUtil.invoke(Bundle.class, bundle, "getIBinder", key); } catch (Exception e) { } return null; } }
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)); } }
public void sendActivityResult(IBinder resultTo, String resultWho, int requestCode) { ActivityClientRecord r = mActivities.get(resultTo); if (r != null && r.activity != null) { Object mainThread = VirtualCore.mainThread(); ActivityThread.sendActivityResult.call(mainThread, resultTo, resultWho, requestCode, 0, null); } }
public final int startActivity(IApplicationThread caller, String callingPackage, Intent intent, String resolvedType, IBinder resultTo, String resultWho, int requestCode, int startFlags, ProfilerInfo profilerInfo, Bundle bOptions) { return PreventRunningUtils.onStartActivity( startActivity$Pr(caller, callingPackage, intent, resolvedType, resultTo, resultWho, requestCode, startFlags, profilerInfo, bOptions), caller, callingPackage, intent); }
@Override public void onServiceConnected(ComponentName name, IBinder service) { mBinder = (TimekeepingService.TimeBinder) service; mServiceBound = true; }
@Override public IBinder onBind(Intent intent) { return null; }
@Override public void addPendingIntent(IBinder binder, String creator) { mPendingIntents.addPendingIntent(binder, creator); }
private void closeKeyboard(Context context, IBinder windowToken) { InputMethodManager inputMethodManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); inputMethodManager.hideSoftInputFromWindow(windowToken, 0); }
@Override public IBinder onBind(Intent intent) { initHander(); return mMessenger.getBinder(); }