[Q] Start TimerTask in MOD - Xposed General

Hi, all!
I'm developing a module, in which I want to regularly trigger some functions.
So I want to start some TimerTask in Xposed module.
I've tried to put TimerTask code into the initZygote() method, but it lead to infinite booting.
If I put them into the handleLoadPackage() code, it seems breaks functions I initialized in iinitZygote().
It seems that the TimerTask thread "occupys" the running time of main thread.
I also tried ScheduledThreadPoolExecutor, but it doesn't work.
As a green hand for both Android development and Xposed, I have no ideas about this.
Can anyone help me?

You can't have threads in zygote, it'll just boot loop as you've seen.
My advice would be to register, in initZygote, a BroadcastReceiver that does what you want in the onReceive method. Then, make a service for your app, have it run on boot and send the broadcast every X minutes.

Related

Xposed FAQ / Known issues

Where can I find general information on Xposed, e.g. how to install it?
In this thread.
Does this require root access?
Yes, because it replaces a file in /system/bin. Once the framework is installed, it should work without root access.
For which devices/ROMs does it work?
I develop the Xposed framework based on the AOSP sources. I'm personally using CM10.2 on an I9100 (Samsung Galaxy S2, bought in Germany). Basically, it should work on any phone which with a ROM based on Android 4.0 or later and an ARM or x86 processor (this is the processor architecture, almost all smart phones and tablets have either of those). Exceptions might be ROMs which are different from the original Android code in some very internal, central code parts (which don't need to be touched for most theming and enhancement modifications). But this is related to the ROM, not the phone itself.
The modules target higher-level code, so they are more likely to be incompatible with your ROM. Basically, the question is whether the methods and resources which the module modifies are similar on your ROM and on the developer's ROM. Let's say a module needs to modify the result of a certain method call. For this, it needs to specify the exact name and parameters that identify that method. If the in your ROM, an additional parameter has been added, the module can't find the method anymore and won't work. If the method can still be found, it will probably work (unless the rest of the app/ROM has changed too much).
There is not definite answer whether it will work. Just try it (of course, making a nandroid backup before is never a bad idea). If it doesn't work, just disable the module. You might want to inform the module developer (not me!) about this fact and provide details (e.g. a logcat and/or the content of /data/data/de.robv.android.xposed.installer/log/debug.log).
What about Gingerbread? Or any other Android version before 4.0.3?
An experimental version for Gingerbread made by liudongmiao can be found here: http://forum.xda-developers.com/xposed/-t2739034.
Note that I cannot give any support for it, please direct your feedback to @liudongmiao.
Are there known incompatibilities?
There seem to be issues with AOKP nightlies. For more details, please read this post.
There seem to be issues (bootloops) with the Oppo Framework, I don't have a fix yet.
On some HTC One phones with CM11, the System UI force crashes. This seems to be caused by SELinux restrictions. Executing "restorecon /system/bin/app_process" (as root, e.g. with adb shell) should help against the FCs, but Xposed might not work due to other SELinux restrictions. If you have the possibility to disable SELinux enforcing mode, you can try that.
If you are an SELinux expert and would like to help, please contact me.
Apart from that, obviously it won't work if the conditions mention above aren't met, e.g. if your phone isn't rooted or it is running on a pre-ICS ROM.
How can I install it?
See the first post. The framework installation needs to be done only once (and on updates), then it can be used for any modules.
Does Xposed get disabled if I flash a new ROM?
Yes, because the file it modifies, /system/bin/app_process, is part of every ROM and will be overwritten when you flash a ROM. However, as long as you don't wipe data, the Xposed Installer app will still be installed, so you can just click on "install/update" again in the Framework section and reboot.
For CyanogenMod-based ROMs, there is an easy solution: [1] and [2]. This will reactivate Xposed automatically after you flash a new ROM/nightly.
For other ROMs, you can try this one. Be careful, it will disable Xposed again if you flash it twice!
Isn't this insecure?
In a way, yes. With great power comes great risk. On the other hand, other ways of modifying your phone are also open to malicious coding. For more details see this post.
Why do I have to enable a module after installing it? Couldn't you skip this additional step?
This is for security reasons (see the question above). By making you confirm that you want to use a module, apps cannot contain hidden Xposed modules. The same could be done with an additional permission, but I'm not sure if everyone would recognize that and it is harder to implement. As a bonus, this toggle allows you to temporarily disable a modification or to ship an app that contains an optional Xposed module.
How do I develop my own modification using the Xposed framework?
First make sure that Xposed is working fine for you. Then read this extensive tutorial.
Why isn't the Xposed Installer available via Play Store?
I have several reasons for that. I wrote about it in this post. And as I learned, Google does indeed sometimes remove apps which interfere with other apps.
From my point of view, you are free to publish the modules you develop on Play Store (at your own risk - Google might remove them). However, be careful if you plan to get money from them. Paid apps are stored in encrypted containers, which means Xposed can't load them at boot time.
Where can I donate some money to support you?
http://repo.xposed.info/donate
Am I allowed to fork Xposed and publish my own version? What should I consider?
I have written this down in a separate post: http://forum.xda-developers.com/showpost.php?p=46325320&postcount=4372
Can I include Xposed in my ROM?
First of all: One reason why I developed Xposed was to avoid the need to flash anything just for a few small changes. So Xposed is designed to work on top of ROMs, not as a part of them.
That said, I don't forbid you to include it. Here are the conditions:
I won't support you in the process of including it. You'll have to figure out the best way to do it yourself. The easiest way (which will also cause the least problems) is probably to simply put the installer and the modules into /system/app, then your users just need to click the "install/update" button, activate the modules they want and reboot.
There might be ways to really pre-install Xposed so that it's working out of the box, but I don't recommend that. You have to be very careful about file permissions, so there is a good chance it won't work. Again, absolutely no support for this.
I won't support your users with problems which might have been caused by using the included version instead of installing it normally.
When your users report problems which are probably not related to including Xposed in the ROM, please try to give them some support yourself. If you can't find a solution, send them to the correct help thread. For example, this thread is only for the framework. Not for any modules, not even my own.
I expect you to include the latest versions, which are usually the ones working best. I won't support older versions.
Your users must be able to update to the latest version, preferably without installing a new version of your ROM. Again, I won't support older versions.
From the previous point, it follows that you need to include the original APKs, otherwise updating is not possible due to a certificate mismatch. This is even more important since updates are possible from within the app. It also avoids confusion, like users wanting support for any modifications you might have made.
You probably want to include some modules. There are many modules that are not written by myself. Therefore, you need to get permission from the module authors as well. For modules written by myself, the same conditions which you are just reading apply.
Please give proper credit (which includes a link to this thread for the framework). Don't sell it as your own work.
You might have the impression now that I'm not a big fan of including Xposed in a ROM. This impression is correct. It's not too hard to install Xposed and any attempts to pre-install Xposed will just cause additonal support requests.
Why don't you just recommend Xposed in your ROM thread, along with the place where they can download it (this thread) and some instructions how to get the most out of it for your ROM? Give your users some choice!
The following posts list known, confirmed issues of the Xposed framework/installer. The intention is to give more information about the symptoms, the background and possible solutions/workarounds.
I won't add every reported issue here, but only when it's clear (e.g. through analyzed logs) that the problem is indeed an incompatibility with Xposed. It doesn't include module issues and the inability to read and follow instructions.
In case you have found a solution/workaround for one of the issues, please let me know.
ART / Android L / Android Lollipop / Android 5.0
Symptom:
You want to use Xposed and ART. However, as soon as you install Xposed, the runtime is reverted back to Dalvik.
Or you want to install Xposed on Android L, but it displays a message that it's not compatible.
Background:
There is no Xposed support for ART (yet), therefore Xposed automatically reverts the runtime to Dalvik. You can be glad that I implemented this, otherwise you would end up in a bootloop. It's a completely different architecture with pretty much no documentation. Rewriting Xposed for the ART runtime requires understanding the concept, the code structure and many details to know how it works. I have already spent dozens of hours on that and some things are working. But still it's a long way ahead. Don't expect even a test version in the near future. So please don't ask when it will be available - you will surely know when it is ready. I have nothing else to say about that.
Update: ART might be become the default runtime environment in the next Android version. You can read my thoughts about this here.
Update 2: The Android L developer preview is out. Don't try to install Xposed on this ROM! Check here for some explanations and status: http://forum.xda-developers.com/xposed/android-l-support-t2797923
Update 3: An alpha version for Lollipop is available now: http://forum.xda-developers.com/xposed/official-xposed-lollipop-t3030118
Square Enix games (e.g. Final Fantasy) / Puzzles & Dragons
Symptom:
If you have activated Xposed and any module, some Square Enix games (e.g. Final Fantasy) and Puzzles & Dragons don't start anymore.
Background:
I have spent several hours analyzing this issue. Here are my findings: http://forum.xda-developers.com/showpost.php?p=42331031&postcount=1701
Solution:
I don't think I will be able to fix this. Some users reported that it's working after converting Xposed and modules to system apps (but I didn't test it and you have to do this after every update).
Otherwise, you could press the "uninstall" button in the Xposed Installer, reboot, play the game, afterwards press the "install/update" button and reboot again.
Aliyun OS
Symptom:
You experience bootloops after installing Xposed and you find files like /system/framework/core.jex. Typical devices where this happens are THL T100S (with a MediaTek MT6592 processor), THL W200S, CUBOT X6, several ones from Zopo, ...
Background:
These devices ship with ROMs that are based on an incompatible Android fork called "Aliyun OS". These ROMs have a proprietary ahead-of-time compiler called "jazz, which is incompatible with Xposed.
Solution:
No chance of fixing this within Xposed. It was reported that deodexing the ROM and then deleting the /system/framework/*.jex files helps, however you won't get any support for this in the Xposed subforum.
Another possibility might be to disable the JIT compiler by adding "dalvik.vm.execution-mode=int:fast" to /system/build.prop or /data/local.prop (might have an impact on performance). See https://github.com/rovo89/Xposed/issues/14 for details.
MIUI/Dexspy
Symptom:
You experience bootloops after installing Xposed on MIUI. There are references to "Dexspy" in /system/bin/app_process and /system/framework/*.
Background:
There are modified versions of Xposed that have been integrated into some MIUI ROMs. I don't know the details, I don't know if that's still the case for current ROMs, and I don't have the time to follow up on this.
Solution:
Sorry, but I can't support you with this. MIUI is closed-source and in some parts heavily modified from AOSP. I don't have the time to keep track of their changes, and due to some bad handling from their side in the past (forking Xposed without any credit, removing all references to the original project and myself), I'm not very motivated to do so. If you're lucky, Xposed might work on your MIUI ROM. If it doesn't, you'll have to find someone else to look into it. If someone creates a clean patch that doesn't break Xposed on other ROMs, we can talk about including it, but otherwise you'll have to decide between MIUI and Xposed.
Segmentation fault
Symptom:
During the framework installation, you get messages that contain "Segmentation fault". This usually happens on ICS ROMs.
Background:
For some reason, the BusyBox binary that comes with Xposed doesn't work with your ROM.
Solution:
Install the attached app, it contains BusyBox binaries which are compiled with different settings, with all dependencies included in the file. Due to this, the incompatibilities should be gone. These files aren't included by default because they are much larger and not needed by most users.
Resources subclass
Symptom:
You can install Xposed 2.6+ and your phone is still booting afterwards. The version numbers are shown in green in the framework section. However, no modules are working. In the Xposed error log, you find a message like:
Code:
java.lang.ClassCastException: class android.content.res.XResources doesn't extend class x.y.z
You might have a ROM from Huawei, Nubia, ...
Background:
These ROMs use a similar approach as Xposed to theme resources. They create a subclass of Resources which takes care of special handling and return an instances of it from getTopLevelResources(). If Xposed replaced this class with its own XResources implementation, then it would a) break the ROM's additional functionality and b) probably cause crashes if the ROM tries to use this functionality.
Solution:
As a workaround, you can simply disable the resources API in the Xposed Installer settings. Some modules won't work anymore, but most should still work.
Mid-term, I hope that I can build a solution that works with such ROMs as well, however it will take some time.
Huge log file
Symptom:
Your disk space is getting low and you find out that much of it is taken up by Xposed Installer (sometimes several 100 MB). You think that this is a bug in Xposed.
Background:
It's most likely not a bug in the Xposed framework, but a bug or incompatibility of a module. One reason might be the removal of a hack in Xposed 2.6. That hack had a side-effect that some modules relied upon. The might also be other issues, for example the module might simple not be made for your ROM.
In any case, such modules might run into errors frequently and log each of them, causing the huge log files.
Solution:
First, find out which module is causing this. You can check the log file in the Xposed Installer. Somewhere near the top of the exception call stacks (beginning with "at ..."), you can usually find the package name of the module that caused it.
Next, make sure that the module is updated. To be on the safe side, you should update all modules. Then you can clear the log file and reboot.
If there are still issues, please go to the support thread of the module. Check if your ROM is supported and whether somebody else has already reported the issues. If not, post your error.log there and ask the developer to have a look at it.

Xposed Internals & Requirement of Reboots

Is there any reason why de-/activating modules needs a reboot?
If I got it correctly, the modules are loaded in the XposedBridge on start-up of Zygote: github.com/rovo89/XposedBridge/blob/art/app/src/main/java/de/robv/android/xposed/XposedBridge.java#L105
However, can loadModules() be used dynamically, such that a reboot would be not necessary anymore when reinstalling modules?
If it were that simple, don't you think rovo89 and the other Xposed devs would have found a way to do that by now?
Hint: It's probably not as simple as that.

A question regarding Magisk and global settings changes

A few months ago, I upgraded to my phone to 7.1, and for some reason, my carrier disables tethering on my plan for this version. I did some poking around and found this article, which provided the fix. Namely:
setprop net.tethering.noprovisioning=true
settings put global tether_dun_required 0
The next issue I encountered was that these settings would be reverted any time I updated my ROM. Enter Magisk and stangri's tethering module, which addresses the first half of that issue flawlessly. I am, however, left with the second half of the puzzle that needs to be fixed after each flash.
I've tried placing a few simple lines in services.sh to perform a quick check to see what that setting's value is and adjust it as needed, I've tried putting scripts in various places to run on boot, and I've tried anything else I can think of, but it seems I'm not savvy enough to solve this particular problem on my own. So, I turn to you for suggestions. Can I either systemlessly set the value "tether_dun_required" to 0 via a Magisk module or use a Magisk module to place a script that'll run on boot and check the value? If it's even possible, can I get a hint on how it would be done? Thanks in advance.
You should be able to use the General Purpose Boot Scripts that @topjohnwu talks about here: https://forum.xda-developers.com/showpost.php?p=70897029&postcount=12.
Didgeridoohan said:
You should be able to use the General Purpose Boot Scripts that @topjohnwu talks about here: https://forum.xda-developers.com/showpost.php?p=70897029&postcount=12.
Click to expand...
Click to collapse
Hmm, yeah that has potential, but I suspect I'd run into the same problem I've encountered when putting the script into a module. Namely, it doesn't run. Maybe I'm missing something? For testing purposes, I've been keeping it to a single line with the actual command (settings put global tether_dun_required 0), but it doesn't actually do anything.

[TOOL] Samsung Xposed Safe Mode script

Samsung Xposed Safe Mode script v1.0
What does it do?
This is an init.d script which emulates the xposed safe mode where you can press any button during boot, get a vibrate (to know it detected you), and it will disable all your xposed modules. To be used in case of bootloops because of incompatible modules.
This only disables all modules so that you can boot. It does NOT actually uninstall or disable xposed itself.
Why would I need this?
I talked with the developer of xposed for Samsung, wanam, and apparently, xposed safe mode was disabled for Samsung devices due to a Knox issue (if you disabled xposed, Knox will hate you and refuse to boot the phone). This is good, but if you have a bootloop, AND you're on a bootloader locked device, you have NO CHOICE but to wipe your data. Ouch!! That's a heavy penalty for accidentally installing one malfunctioning module!
Or maybe your phone still is bootloader unlocked, but you're running Samsung xposed and safemode is still disabled for you. Then you'd rather have xposed safemode back just for the ease of not having to go through recovery to fix things.
How does it work?
1. Press any of three buttons during boot (volume keys, or home button). You have 10 seconds from bootup to choose to do this.
2. System will give you 2 short vibrates to tell you it detected it.
3. Press any button 4 more times, each time will give you another short vibration.
4. One long vibration will signal to you that xposed has been disabled.
5. The script will automatically reboot your device in 6 seconds. This is because we can't disable xposed, so xposed will STILL load modules on this bootup, which means you'll still see the bootloop momentarily until you reboot.
Great! How do I install it?
This is an init.d script, so you need init.d support in your phone. Obviously, if you have a bootlocked device, you probably don't have init.d support. This is not a guide on how to get init.d support, but I'll offer you a few tips you can use to search yourself.
- install-recovery.sh, since it's called by init.rc during boot, can be hijacked in order to create an init.d system.
- If install-recovery didn't work, SuperSU also includes an su.d directory which is executed at a similar time. Just throw a script in there, or throw a script in there which enables use of the init.d folder (run-parts /system/etc/init.d).
Anyways, here's how you install it:
- Place the script you downloaded into
Code:
/system/etc/init.d
OR
Code:
/system/su.d
Give the script proper permissions for the folder it's in
- For su.d folder, it is root:root 0700 (rwx------)
- For init.d folder, it could be a variety of permissions. My init.d folder runs as a result of su.d, so I gave it same permissions as su.d. If yours doesn't, then you might want to try root:root 0755 (rwxr-xr-x)
- The important point here is to make sure it's at least root user and group, readable and executable, rwxr-xr-x
Will it work on my device?
It should work on any device really, if you follow the simple instructions. But I've only tested it on the ATT S4 (Lollipop 5.0.1), so I can't guarantee it will work on your device. Test it out and see if it works for you! It probably will!
You saved me!
I'm glad to hear that! I love to hear and see a thanks, so make sure to click the thanks button and maybe write a post too!
Bugs and problems
You know how to report bugs and issues. State all relevant information related to the problem; device, problem in clear detail, with reproducible steps, and anything else you might need.
Related custom xposed builds
Here are a list of Samsung custom xposed builds I know this "safe mode problem" to be present in. (Don't forget, this problem is likely to be in any and all Samsung xposed custom builds due to the nature of the Knox problem).
[UNOFFICIAL] Xposed for Samsung Lollipop by arter97
[UNOFFICIAL][5.0][v87.1][03 Dec] Xposed for Samsung Lollipop 5.0.x
[UNOFFICIAL][5.1/6][v87.1][28 Nov]Xposed for Samsung Lollipop/Marshmallow
Disclaimer: As usual, while I've made every attempt to make it perfect, there are no guarantee it will work for you. By using this, you agree not to hold me accountable in case something bad happens to you (or it didn't save your device)! Do your own testing to make sure it works before you actually need to use it in an emergency!
FAQ
It didn't vibrate
You probably have a different device which places the vibrator in a different location. I don't have your device, so maybe you'll need to help me debug and find where the vibrator is located at.
It didn't work!
What happened? Give me some detailed information about exactly what you did, what happened, and the device you're on!
Some possible problems to investigate are:
Does the script have correct user: owner and permissions?
Is your init.d or su.d system even working? Make sure it is first
Nice work!
It should help with incompatible modules leading to a bootloop, but it won't prevent Xposed from loading, the flag "/data/data/de.robv.android.xposed.installer/conf/disabled" is ignored on my Xposed version, done here for a reason, i got many bootloop reports in the past by people accidentally triggering safe mode by physical buttons, leading to Knox refusing to deal with modified binaries.
Fortunately it does not seem to be the same with TouchWiz 7.0, so i will bring it back later for Nougat.
wanam said:
Nice work!
It should help with incompatible modules leading to a bootloop, but it won't prevent Xposed from loading, the flag "/data/data/de.robv.android.xposed.installer/conf/disabled" is ignored on my Xposed version, done here for a reason, i got many bootloop reports in the past by people accidentally triggering safe mode by physical buttons, leading to Knox refusing to deal with modified binaries.
Fortunately it does not seem to be the same with TouchWiz 7.0, so i will bring it back later for Nougat.
Click to expand...
Click to collapse
Thank you!
It certainly will help a lot for disabling incompatible modules. Yes, although it doesn't technically disable xposed itself. It's really great that future versions aren't that way!
I actually thought of creating another script which utilizes back and menu key buttons to actually uninstall xposed from backups (an actual disable xposed script of sorts), but I thought it was too much.

How to reverse a SELinux policy?

Trying to help a friend install an rclone pluing for Kodi, I found out that on my phone I needed to install this module https://github.com/galeksandrp/app-data-file-exec
The module worked and Kodi was able to run a binary in its data directory. Problem is my friend uses an Nvidia Shield and he wants to use official streaming apps too (Netflix, Prime Video, etc.). Rooting is consequently a no-no, otherwise those would fail to play at highest quality.
I've found a possible workaround but to test I need to reverse this policy:
allow * { app_data_file privapp_data_file } file { execute_no_trans }
Which is pretty much all that the module I installed does.
Uninstalling the module did not remove the policy. Kodi keeps on being able to execute the rclone binary. And I need to restore my system to how it was before that policy modification.
Any help? Thanks in advance!
Edit: while waiting for somebody knowledgeable enough I've been searching and searching. I've found this, from here: https://android.googlesource.com/platform/system/sepolicy/+/master/private/app_neverallows.te#58
Code:
# Block calling execve() on files in an apps home directory.
# This is a W^X violation (loading executable code from a writable
# home directory). For compatibility, allow for targetApi <= 28.
# b/112357170
neverallow {
all_untrusted_apps
-untrusted_app_25
-untrusted_app_27
-runas_app
} { app_data_file privapp_data_file }:file execute_no_trans;
But I am unsure how to proceed, since the module does not completely reverse the above, it's more targeted. I wouldn't want to create a situation where normal apps cannot work properly anymore.
gorman42 said:
Trying to help a friend install an rclone pluing for Kodi, I found out that on my phone I needed to install this module https://github.com/galeksandrp/app-data-file-exec
The module worked and Kodi was able to run a binary in its data directory. Problem is my friend uses an Nvidia Shield and he wants to use official streaming apps too (Netflix, Prime Video, etc.). Rooting is consequently a no-no, otherwise those would fail to play at highest quality.
I've found a possible workaround but to test I need to reverse this policy:
allow * { app_data_file privapp_data_file } file { execute_no_trans }
Which is pretty much all that the module I installed does.
Uninstalling the module did not remove the policy. Kodi keeps on being able to execute the rclone binary. And I need to restore my system to how it was before that policy modification.
Any help? Thanks in advance!
Click to expand...
Click to collapse
every custom allow (ie not compiled into the ROM) I apply on my phone, has to be reinstated on boot.
If you have root, its possible that it is being reinstated by something, on every boot. eitehr a Magisk script, a Magisk module or a rooted app.
However, when compiling ROMs, the opposite of "allow" is "deny". I have never tried to add a deny (or revert an allow), and it cant be done without root, so you are back where you started.
Sorry, I probably did not explain myself fully.
I have root and it's absolutely fine for me to keep root on this device. Withouth that policy my rooted device was behaving the same way as Nvidia Shield TV. And I simply want to restore it to the way it was.
This is why I linked to the module, because to me it seems that it simply issues the command I pasted here. But maybe I am missing something. I have unistalled it, I have deleted the files too. But still Kodi is now able to execute binary code in its own data directory, something that on 11 should be not allowed.
If there are termux commands I can use to check the situation, as stated, I have root, I can do whatever is needed to gather more information.
I simply thought that it was enough for me to uninstall the module to revert but that does not appear to be the case. Unless the privilege Kodi is using is saved once and for all on a per app basis. And since Kodi used it once, it remained (it doesn't sound likely but I'm grasping at straws).
I asked mods to move this, if this is not the correct forum to ask for this.
Edit: it was in general questions and answers
Bump? I hope it's allowed.
Could somebody be so kind as to advise where I could post this so as to get an answer? I realize this might be the wrong forum, maybe.
But I have asked already in two different places and I haven't gotten to the bottom of it.
Thanks!
Bump
Bump... :-(
Bump. I hope somebody could at least point me to somewhere where I could ask.
Please?
Bump.

Categories

Resources