Android - Keyline Pushing's Grid on top of other applications

   Keyline pushing displays a Grid on top of other applications for UI testing. This is really useful for designers working with material design. The approach of displaying content on top of other applications and yet be able to control the actual application (behind the grid) is cool.





     Users can notice a notification. This is most likely a result of a foreground service started by the application. This makes sense as the Grid has to stay alive even when the application is backgrounded and other applications are in focus. The actual grid is shown on a separate window most likely using public API, TYPE_SYSTEM_ALERT, TYPE_SYSTEM_OVERLAY, TYPE_SYSTEM_DIALOG or TYPE_SYSTEM_ERROR. This is why the app has a permission request claiming that it can draw on top of other applications. The next question is as to how the touch events are actually relayed to the foreground application underneath the grid? The grid is some kind of custom view or bitmap hosted by a window. How is this window not intercepting the touch events? Turns out, this is requested by a window flags like FLAG_NOT_TOUCHABLE and FLAG_NOT_FOCUSABLE. Further, the system window doesn't have a background color and this is most likely requested via translucent pixel format.

        WindowManager.LayoutParams params = new WindowManager.LayoutParams();
        params.height = WindowManager.LayoutParams.MATCH_PARENT;
        params.width = WindowManager.LayoutParams.MATCH_PARENT;
        params.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
        params.format = PixelFormat.TRANSLUCENT;
        params.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;

        final WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);

        wm.addView( view, params);

No comments: