Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Boss Key Detection Method #20

Merged
merged 2 commits into from
Oct 10, 2021
Merged

Added Boss Key Detection Method #20

merged 2 commits into from
Oct 10, 2021

Conversation

sweenwolf
Copy link
Contributor

No description provided.

Copy link
Owner

@virresh virresh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finally got some time to dive into the actual logic.
I'm seeing some crashes. Mentioned my concern at the apt line number.

builder.setNegativeButton("NO", (dialog, whichButton) -> dialog.dismiss());
AlertDialog alert = builder.create();
alert.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
alert.show();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not able to wrap my head around this. I get a android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running? error once I get past a permission not allowed for this window type (by modifying line 64 to use TYPE_TOAST).

I feel that the error is correct in it's right, so asking here to clarify. From my understanding:

  1. We capture every key event and create an instance of the KeyDetection Activity. Since this is created directly via constructor no lifecycle methods are called/managed.
  2. When the activity is actually created, the static field stores Activity reference. This reference is now used by another object instance created when a new keypress is sent. This means we are accessing the activity from a completely different instance of the same class.
  3. Now, when we try to access the window and set type of this alert created with the earlier activity context, the layout manager thinks activity is stopped because it's not matching the callee's context (callee is on the thread belonging to the accessibility service). Window Manager bails out crashing the whole party during dialog creation.

I think we cannot use alert.getWindow().setType()
Would like to gain some clarity over why are we using this?
And did you encounter crashes while testing this locally?

Another thing I thought about was sending each event to a new object might be a recipe for disaster, but since most of the codebase is hacky, I'm okay with this hack xD

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using stock emulator with API level 28 here

Copy link
Contributor Author

@sweenwolf sweenwolf Oct 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was using that for Nougat, beacuse i use Firestick 4k, i added an API level check this will solve it. Tested on Android 10.
Had no crashes whatsoever because it was compatible with Nougat.

Copy link
Contributor Author

@sweenwolf sweenwolf Oct 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enabling "Bordered Window" and "Boss key Toggle" will enable scroll mode. (in Mouse Mode)
When the pointer is at any of the side, pressing the same button will scroll the page from center

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the added scroll functionality!
Unfortunately I couldn't get the accessibility service to start on the emulator after this commit

Will debug over the weekend to get to the cause

Copy link
Contributor Author

@sweenwolf sweenwolf Oct 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strange, I tested this on Android TV emulator API 29, its working just fine.
MATVT on AndroidTV Emu - https://youtu.be/5ttWGTRZba8
MATVT in JioTV in Firestick 4k - https://youtu.be/64jIpjBFLPg

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debugged the issue, turns out was a cache invalidation problem at my end.
Code is perfectly fine, Thanks!

@virresh virresh merged commit c29c9fa into virresh:master Oct 10, 2021
@virresh
Copy link
Owner

virresh commented Oct 10, 2021

Thanks a lot for the contributions @sweenwolf
Marking this as hacktoberfest-accepted (good time for OSS contributions in case you're interested)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants