public static Bitmap screenshot(IWindowManager wm, Point point) throws Exception { String surfaceClassName; if (Build.VERSION.SDK_INT <= 17) { surfaceClassName = "android.view.Surface"; } else { surfaceClassName = "android.view.SurfaceControl"; } Bitmap b = (Bitmap) Class .forName(surfaceClassName) .getDeclaredMethod("screenshot", new Class[]{Integer.TYPE, Integer.TYPE}) .invoke(null, new Object[]{Integer.valueOf(point.x), Integer.valueOf(point.y)}); // int rotation = wm.getRotation(); // if (rotation == 0) { // return b; // } // Matrix m = new Matrix(); // if (rotation == 1) { // m.postRotate(-90.0f); // } else if (rotation == 2) { // m.postRotate(-180.0f); // } else if (rotation == 3) { // m.postRotate(-270.0f); // } // return Bitmap.createBitmap(b, 0, 0, size.x, size.y, m, false); return b; }
public static Point getCurrentDisplaySize(boolean rotate) { int v5; IWindowManager v8; try { Method v4 = Class.forName("android.os.ServiceManager").getDeclaredMethod("getService", String .class); Point v1 = new Point(); // if(Build.VERSION.SDK_INT >= 18) { v8 = IWindowManager.Stub.asInterface((IBinder) v4.invoke(null, "window")); v8.getBaseDisplaySize(0, v1); // v5 = v8.getRotation(); // } // else if(Build.VERSION.SDK_INT == 17) { // DisplayInfo v0 = android.hardware.display.IDisplayManager.Stub.asInterface(v4.invoke( // null, "display")).getDisplayInfo(0); // v1.x = DisplayInfo.class.getDeclaredField("logicalWidth").get(v0).intValue(); // v1.y = DisplayInfo.class.getDeclaredField("logicalHeight").get(v0).intValue(); // v5 = DisplayInfo.class.getDeclaredField("rotation").get(v0).intValue(); // } // else { // v8 = Stub.asInterface(v4.invoke(null, "window")); // v8.getRealDisplaySize(v1); // v5 = v8.getRotation(); // } // // if((rotate) && (v5 == 1 || v5 == 3)) { // int v7 = v1.x; // v1.x = v1.y; // v1.y = v7; // } return v1; } catch (Exception v3) { throw new AssertionError(v3); } }
public static Bitmap screenshot(IWindowManager wm) throws Exception { String surfaceClassName; Point size = SurfaceControlVirtualDisplayFactory.getCurrentDisplaySize(false); if (Build.VERSION.SDK_INT <= 17) { surfaceClassName = "android.view.Surface"; } else { surfaceClassName = "android.view.SurfaceControl"; } Bitmap b = (Bitmap) Class.forName(surfaceClassName).getDeclaredMethod("screenshot", new Class[]{Integer.TYPE, Integer.TYPE}).invoke(null, new Object[]{Integer.valueOf(size.x), Integer.valueOf(size.y)}); // int rotation = wm.getRotation(); // if (rotation == 0) { // return b; // } // Matrix m = new Matrix(); // if (rotation == 1) { // m.postRotate(-90.0f); // } else if (rotation == 2) { // m.postRotate(-180.0f); // } else if (rotation == 3) { // m.postRotate(-270.0f); // } // return Bitmap.createBitmap(b, 0, 0, size.x, size.y, m, false); return b; // return small(b); }
public static Point getCurrentDisplaySize(boolean rotate) { try { Method getServiceMethod = Class.forName("android.os.ServiceManager").getDeclaredMethod("getService", new Class[]{String.class}); Point displaySize = new Point(); IWindowManager wm; int rotation; if (VERSION.SDK_INT >= 18) { wm = Stub.asInterface((IBinder) getServiceMethod.invoke(null, new Object[]{"window"})); wm.getInitialDisplaySize(0, displaySize); rotation = wm.getRotation(); } else if (VERSION.SDK_INT == 17) { DisplayInfo di = IDisplayManager.Stub.asInterface((IBinder) getServiceMethod.invoke(null, new Object[]{"display"})).getDisplayInfo(0); displaySize.x = ((Integer) DisplayInfo.class.getDeclaredField("logicalWidth").get(di)).intValue(); displaySize.y = ((Integer) DisplayInfo.class.getDeclaredField("logicalHeight").get(di)).intValue(); rotation = ((Integer) DisplayInfo.class.getDeclaredField("rotation").get(di)).intValue(); } else { wm = Stub.asInterface((IBinder) getServiceMethod.invoke(null, new Object[]{"window"})); wm.getRealDisplaySize(displaySize); rotation = wm.getRotation(); } if ((rotate && rotation == 1) || rotation == 3) { int swap = displaySize.x; displaySize.x = displaySize.y; displaySize.y = swap; } return displaySize; } catch (Exception e) { throw new AssertionError(e); } }
/** * Force the global system in or out of touch mode. This can be used if * your instrumentation relies on the UI being in one more or the other * when it starts. * * @param inTouch Set to true to be in touch mode, false to be in * focus mode. */ public void setInTouchMode(boolean inTouch) { try { IWindowManager.Stub.asInterface( ServiceManager.getService("window")).setInTouchMode(inTouch); } catch (RemoteException e) { // Shouldn't happen! } }
AnonymousClass5(IWindowManager iWindowManager) { this.val$wm = iWindowManager; }
public InjectionManager(Context c) { if(Integer.valueOf(android.os.Build.VERSION.SDK_INT) < android.os.Build.VERSION_CODES.JELLY_BEAN) { mWmbinder = ServiceManager.getService( INTERNAL_SERVICE_PRE_JELLY ); mWinMan = IWindowManager.Stub.asInterface( mWmbinder ); printDeclaredMethods(mWinMan.getClass()); //TODO: Implement full injection support for pre Jelly Bean solutions } else { mInputManager = c.getSystemService(Context.INPUT_SERVICE); try { //printDeclaredMethods(mInputManager.getClass()); //Unveil hidden methods mInjectEventMethod = mInputManager.getClass().getDeclaredMethod("injectInputEvent", new Class[] { InputEvent.class, Integer.TYPE }); mInjectEventMethod.setAccessible(true); Field eventAsync = mInputManager.getClass().getDeclaredField("INJECT_INPUT_EVENT_MODE_ASYNC"); Field eventResult = mInputManager.getClass().getDeclaredField("INJECT_INPUT_EVENT_MODE_WAIT_FOR_RESULT"); Field eventFinish = mInputManager.getClass().getDeclaredField("INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH"); eventAsync.setAccessible(true); eventResult.setAccessible(true); eventFinish.setAccessible(true); INJECT_INPUT_EVENT_MODE_ASYNC = eventAsync.getInt(mInputManager.getClass()); INJECT_INPUT_EVENT_MODE_WAIT_FOR_RESULT = eventResult.getInt(mInputManager.getClass()); INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH = eventFinish.getInt(mInputManager.getClass()); } catch (NoSuchMethodException nsme) { Log.e(TAG, "Critical methods not available"); } catch (NoSuchFieldException nsfe) { Log.e(TAG, "Critical fields not available"); } catch (IllegalAccessException iae) { Log.e(TAG, "Critical fields not accessable"); } } }
private static void init() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException { Method getServiceMethod = Class.forName("android.os.ServiceManager").getDeclaredMethod("getService", new Class[]{String.class}); wm = IWindowManager.Stub.asInterface((IBinder) getServiceMethod.invoke(null, new Object[]{"window"})); im = (InputManager) InputManager.class.getDeclaredMethod("getInstance", new Class[0]).invoke(null, new Object[0]); MotionEvent.class.getDeclaredMethod("obtain", new Class[0]).setAccessible(true); injectInputEventMethod = InputManager.class.getMethod("injectInputEvent", new Class[]{InputEvent.class, Integer.TYPE}); }