Unable to click or scroll below overlay on Android 12 - android

my application helps testers to find inconsistencies in layouts and makes it easier to work with the UI part using the grid layout overlay. but since android 12 (31 sdk) all clicks are suppressed by the system because they are "untrusted touch"
have any ideas?
P.S. in the article on medium it is suggested to use one of the approaches: Bubbles, Picture-in-Picture, Notifications, but this is not suitable for the gridlayout approach
link to untrusted touch android doc
Code example:
private fun showGrid() {
val overlayFlag = if (Build.VERSION.SDK_INT >= 26)
WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY
else WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY
params = WindowManager.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT,
overlayFlag,
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE or
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT
)
windowManager = getSystemService(Context.WINDOW_SERVICE) as WindowManager
gridOverlay = GridOverlay(this, prefHelper.gridColor, prefHelper.gridSize)
gridOverlay?.alpha = prefHelper.gridAlpha
windowManager!!.addView(gridOverlay, params)
}
InputManager , maximumObscuringOpacityForTouch didn't solve the problem
other flags in the WindowManager also did not help.
what can be done according to the android documentation is using the Accessibility service, but this is not our approach as I don't want to be banned by Google because of using Accessibility service not for its intended purpose.

Related

Unable to click the below overlay on Android 12

I have an App on the play store. This app basically creates an overlay on top of all the apps with some colors, It works perfectly for anything below Android 12. But, since Android 12 it no longer works. I can still interact with my application, but once minimized I no longer can click on anything or change anything at all. I have to restart the device to close the application.
val params = WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT,
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O)
WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY
else WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
or WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
or WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
or WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
PixelFormat.TRANSLUCENT
)
This is how I create the overlay on top. I checked the documentation, but could not find any information. I will be grateful if I can get any help and suggestions to fix this issue.
Set alpha to window manager params, its works for me.
Try below snippet code:
if (Build.VERSION.SDK_INT >= 31)
{
params.alpha = 0.8f;
}

Show views above lockscreen using window manager in Android O?

My app shows views above the lockscreen, until now I used the following code:
windowParams = new WindowManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.TYPE_SYSTEM_ALERT, 65794, -2);
windowParams.type = Utils.isSamsung(getApplicationContext()) ? WindowManager.LayoutParams.TYPE_TOAST : WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
windowManager.addView(frameLayout, windowParams);
This code doesn't seem to work anymore on Android O, instead, now the lockscreen is shown above the view, and the view only becomes visible after the user swipes away the lockscreen.
Granted, it could just be a bug since Android O is still in beta, but it's also possible that I missed one of Googles notes about "what's new in O".
It's no longer possible to draw over the lockscreen and other important UI elements (status bar, etc), Google removed this feature in Android O.
Source:
https://issuetracker.google.com/issues/36574245

WebView performs slowly when it is attached to WindowManager android

I'm creating an app shows HTML5 video, for studying android programming, that uses Floating WebView.
It performs very choppy even on device that has upgraded WebView.
(I'm using lollipop-powered Nexus 5)
While it is attached on Activity(not floating) it performs buttery smooth.
Even if it is floating, it performs smoothly when any WebView is placed on Current Activity.
But if there's no WebViews on current activity like launcher, it performs very slow and jittery.
Here is part of code what I'm using:
WindowManager windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
WebView = new WebView();
WindowManager.LayoutParams paramsRL = new WindowManager.LayoutParams(
800,
450,
WindowManager.LayoutParams.TYPE_PHONE,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
PixelFormat.TRANSLUCENT);
paramsRL.gravity = Gravity.TOP | Gravity.LEFT;
webView.setWebChromeClient(new WebChromeClient());
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
webView.loadUrl("html5_video_page_URL_here");
windowManager.addView(webView,paramsRL);
Is there any workaround to get around this problem?
EDIT
Added a video explains this behavior: http://youtu.be/BPDxzRRO1N8
while attached to an activity, it performs buttery smooth: http://youtu.be/aQcJRPCZWYs
on Kitkat, at least Samsung Galaxy's, it behaves buttery smooth: http://youtu.be/7Dw0tJ67eJw
I've also filed a bug at
https://code.google.com/p/chromium/issues/detail?id=460440
You can add
webView.setLayerType(WebView.LAYER_TYPE_HARDWARE, null);
Hope help you
I've been working on a application with a floating video player and I had the same issue. I didn't find the root cause of the problem but I got rid of this issue.
I have an activity that starts the Floating Video Player (basically a service that uses the TYPE_SYSTEM_ALERT type), when I added a notification player started by the Activity as well (similar to the one used by Spotify), the issue disappeared.
As I said I wasn't able to determine the root cause of the issue, but it seems that as long as the activity or something started by the activity is "active" (I'm using the term active loosely), the issue will no happen and the Webview will behave as expected.

Invalid display resolution while using TYPE_SYSTEM_ALERT of WindowManager

I'm using WindowManager.LayoutParams class using TYPE_SYSTEM_ALERT to get an activity on top of everything. Everything is working fine except the display resolution which appears to be magnified, and therefore I'm not able to see the full content of the layout.
Here is the screenshot
Layout Snapshot
(Extremely sorry for not uploading the image directly due to my low reputation as I'm new to StackOverflow)
My code for WindowManager.LayoutParams is
final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
PixelFormat.TRANSLUCENT);
params.gravity = Gravity.RIGHT | Gravity.TOP;
wm = (WindowManager) getApplicationContext()
.getSystemService(Context.WINDOW_SERVICE);
mTopView = (ViewGroup) getLayoutInflater().inflate(R.layout.block_device, null);
getWindow().setAttributes(params);
wm.addView(mTopView, params);
I also tried WRAP_CONTENT instead of FLAG_FULLSCREEN, but it showed an IllegalStateException that ActionBarView can only be used with MatchParent.
Any fixes that I can try out???
In 5.1 as part of extra security system_alert kind of dialog, which writes on top of another application is UI is deprecated. In my application I had one activity which had system_alert dialog it was working until 5.0 but in 5.1 not working (after android.permission.SYSTEM_ALERT_WINDOW permission also its not working). I referred androidxref U can see in the following link http://androidxref.com/5.1.1_r6/xref/frameworks/base/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java#1639
They will check and throw the exception if app is trying to write on the window of other application
Finally we had to redesign the application to not use System alert kind of dialog
Refer the following code snippet for sample code...
String message = getString(R.string.progress_message);
mProgressDialog = new ProgressDialog(this);
mProgressDialog.setTitle(R.string.progress_title_message);
mProgressDialog.setMessage(message);
mProgressDialog.setProgressStyle(mProgressDialog.STYLE_HORIZONTAL);
mProgressDialog.setProgress(0);
mProgressDialog.setCancelable(false);
mProgressDialog.setMax(100);
mProgressDialog.show();`

Typing on an EditText without disturbing ongoing activity?

So I am making a sticky note sorta thing that always appears on top and user can press on it to type on it. So here is my working code:
mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
LayoutInflater layoutInflater =
(LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
myView = layoutInflater.inflate(R.layout.notepad, null ); //notepad.xml contains the EditText
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON,
PixelFormat.TRANSLUCENT);
mWindowManager.addView(myView, params);
The problem is that when I use the flag TYPE_SYSTEM_OVERLAY, I can't get focus to type on the EditText. Alternate would be to use TYPE_SYSTEM_ALERT and I can use the EditText to type on, but then the entire background would freeze. How can I allow the user to type without interrupting background activity (aka game, video, scrolling thru Facebook etc)
There is an opensource library for that. Its called the standOut library. Have a look.
It may help you.

Categories

Resources