Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,804,884 Members 52,613 Now Online
XDA Developers Android and Mobile Development Forum

Applying changes without [soft-]rebooting

Tip us?
 
WisdomSky
Old
(Last edited by WisdomSky; 25th June 2014 at 09:55 AM.)
#1  
WisdomSky's Avatar
Senior Member - OP
Thanks Meter 633
Posts: 145
Join Date: May 2013
Location: In your mind

 
DONATE TO ME
Question Applying changes without [soft-]rebooting

Hi, I've been gone for a long long time and just came back with a new module.

I have seen that some other modules can actually apply the changes immediately without the need of doing a soft-reboot or full reboot. That is new to me. Maybe I missed it during those times when I'm not around.

So I want to ask the masters about this technique. How do you implement it. Or is there a xposed method which is reponsible for this?

I'm trying to apply changes to resources of a package.

I hope someone can explain to me how to implement it.

Thanks in advance!

Projects Featured in XDA Portal:
- WisdomSky Xploit: customize statusbar and clock color
- ResXploit: theme android without decompiling apks

UPCOMING PROJECT:
ROM++: Your ROM's OTA update solutions...
 
GermainZ
Old
#2  
GermainZ's Avatar
Forum Moderator / Recognized Developer
Thanks Meter 6,355
Posts: 5,450
Join Date: Aug 2012
Usual scenario:
Code:
<load preferences>
<hook method>
    <do something inside the method using the loaded preferences>
Dynamically:
Code:
<initialize XSharedPreferences>
<hook method>
    <reload preferences using XSharedPreferences.reload() and getting the preferences directly>
    <do something inside the method using the loaded preferences>
You can also use broadcasts, if possible.
The Following User Says Thank You to GermainZ For This Useful Post: [ Click to Expand ]
 
WisdomSky
Old
#3  
WisdomSky's Avatar
Senior Member - OP
Thanks Meter 633
Posts: 145
Join Date: May 2013
Location: In your mind

 
DONATE TO ME
Quote:
Originally Posted by GermainZ View Post
Usual scenario:
Code:
<load preferences>
<hook method>
    <do something inside the method using the loaded preferences>
Dynamically:
Code:
<initialize XSharedPreferences>
<hook method>
    <reload preferences using XSharedPreferences.reload() and getting the preferences directly>
    <do something inside the method using the loaded preferences>
You can also use broadcasts, if possible.
sorry but the idea really can't sink into my mind... maybe I need some actual code... but anyway sir, by using XSharedPreferences, does it mean that all inputs must be saved in a prefs file?

This module I've made does not actually utilize SharedPrreferences, but store them inside the files dir using getFilesDir() for some reason...

Projects Featured in XDA Portal:
- WisdomSky Xploit: customize statusbar and clock color
- ResXploit: theme android without decompiling apks

UPCOMING PROJECT:
ROM++: Your ROM's OTA update solutions...
 
GermainZ
Old
#4  
GermainZ's Avatar
Forum Moderator / Recognized Developer
Thanks Meter 6,355
Posts: 5,450
Join Date: Aug 2012
Quote:
Originally Posted by WisdomSky View Post
sorry but the idea really can't sink into my mind... maybe I need some actual code... but anyway sir, by using XSharedPreferences, does it mean that all inputs must be saved in a prefs file?

This module I've made does not actually utilize SharedPrreferences, but store them inside the files dir using getFilesDir() for some reason...
Well in that case you'd just read the preferences before applying them. In some cases (resources replacements), I don't think it's possible, but if you're hooking a module to change a TextView's color for example:
Code:
beforeHookedMethod:
    int textColor = getTextColor(); // load the preference inside the method
    TextView textView = ;
    textView.setTextColor(textColor); // apply the preference
I might be able to give you an actual example if you explain what you're doing exactly, but as I said I don't think it's possible for resource replacements (which I guess is what you're doing).
The Following User Says Thank You to GermainZ For This Useful Post: [ Click to Expand ]
 
WisdomSky
Old
(Last edited by WisdomSky; 25th June 2014 at 01:57 PM.)
#5  
WisdomSky's Avatar
Senior Member - OP
Thanks Meter 633
Posts: 145
Join Date: May 2013
Location: In your mind

 
DONATE TO ME
Quote:
Originally Posted by GermainZ View Post
Well in that case you'd just read the preferences before applying them. In some cases (resources replacements), I don't think it's possible, but if you're hooking a module to change a TextView's color for example:
Code:
beforeHookedMethod:
    int textColor = getTextColor(); // load the preference inside the method
    TextView textView = …;
    textView.setTextColor(textColor); // apply the preference
I might be able to give you an actual example if you explain what you're doing exactly, but as I said I don't think it's possible for resource replacements (which I guess is what you're doing).
When a user has selected a package, a new directory under its package name will be created inside the files dir of my app, and when the user has applied a replacement to a certain resource a new directory will be created inside the directory created a while ago. and then inside this directory is where a new file is created and the filename will be the resource name and the content of the file is just a single line plain text which is the replacement value.

so if you can see it, there is a heirarchy of directories...

under the files dir... it could look like this...

[dir]files
-----[dir]com.package.name
----------[dir]string
---------------[file]app_name
----------[dir]drawable
---------------[file]ic_launcher

by using this pattern, I can write something that will loop through the files dir... get the package name, then get the resource type, then get the resource name and finally get its value by reading the content. And now we all have the needed arguments to pass to the setReplacement method...

but since you said that it is not applicable to resource replacements, then there's really no hope.

Projects Featured in XDA Portal:
- WisdomSky Xploit: customize statusbar and clock color
- ResXploit: theme android without decompiling apks

UPCOMING PROJECT:
ROM++: Your ROM's OTA update solutions...
 
GermainZ
Old
#6  
GermainZ's Avatar
Forum Moderator / Recognized Developer
Thanks Meter 6,355
Posts: 5,450
Join Date: Aug 2012
Quote:
Originally Posted by WisdomSky View Post
but since you said that it is not applicable to resource replacements, then there's really no hope.
I might be wrong as I'm not too familiar with replacing resources. Where are you replacing the resources? Also, can wee see a (simplified/pseudo-code, maybe) code snippet of you doing so?
 
rovo89
Old
#7  
rovo89's Avatar
Senior Recognized Developer
Thanks Meter 14,069
Posts: 2,367
Join Date: Jan 2012
The problem with resources is that the app/system will usually load resources just once, or at least only at certain spots of the code. So even if you set a new replacement, it won't come into effect immediately, but only when the app/system decides loads it again. Same for removed replacements.
Tired of updating your mod for every new ROM release?
You want give users the possibility to combine different mods without creating tons of different files for all possible combinations?
Then have a look at my Xposed framework - modifications without APK changes!
 
Falseclock
Old
(Last edited by Falseclock; 28th June 2014 at 06:04 PM.)
#8  
Falseclock's Avatar
Senior Member
Thanks Meter 299
Posts: 504
Join Date: Jun 2012
Location: Almaty

 
DONATE TO ME
Quote:
Originally Posted by WisdomSky View Post
I hope someone can explain to me how to implement it.

Thanks in advance!
If you module hooks Activity, Service or any other context application, you can store settings not with Shared Preferences, but in system settings database and use ContextResolver to get information from database.

and of course use <uses-permission android:name="android.permission.WRITE_SETTINGS" />

Here is an example:

Code:
		findAndHookMethod("com.android.phone.PhoneApp", paramLoadPackageParam.classLoader, "onCreate", new XC_MethodHook()
		{
			protected void beforeHookedMethod(MethodHookParam param) throws Throwable
			{
				ContentResolver cr = (ContentResolver) XposedHelpers.callMethod(param.thisObject, "getContentResolver");
				Class <?> Features = XposedHelpers.findClass("com.android.phone.HtcFeatureList", paramLoadPackageParam.classLoader);

				boolean CallRecording = Misc.toBoolean(Settings.System.getInt(cr, Const.TWEAK_CALL_REC, 0));

				if (CallRecording)
				{
					XposedHelpers.setStaticBooleanField(Features, "FEATURE_SUPPORT_VOICE_RECORDING", true);
				}
			}
		});
More look here https://github.com/Falseclock/HtcOne.../Recorder.java

It is possible also to implement for resources, but you have always lookup views by identifier, load your application resources, redraw drawables, strings, etc. AND THIS IS BATTERY COST EFFICIENT method.

Other way - store replaced drawables for example in static variables and do not redraw every time. But there will be a huge code if you are replacing a lot of resources.

here is another example

Code:
public static Drawable Background;

		findAndHookMethod(packageName + ".ui.ConversationListBaseAdapter", paramLoadPackageParam.classLoader, "bind", "android.view.View", "android.content.Context", packageName + ".ui.ConversationHeader", new XC_MethodHook()
		{
			protected void afterHookedMethod(MethodHookParam param) throws Throwable
			{
				boolean isRead = (Boolean) XposedHelpers.callMethod(param.args[2], "isRead");
				View row = (View) param.args[0];

				if (Background == null)
				{
					Background = row.getBackground();
					if (Background == null)
					{
						Background = new ColorDrawable(row.getContext().getResources().getColor(android.R.color.transparent));
					}
				}

				if (isRead == false)
				{
					XModuleResources modRes = XModuleResources.createInstance(XMain.MODULE_PATH, null);

					row.setBackgroundDrawable(modRes.getDrawable(R.drawable.list_background_unread));
				} else
				{
					row.setBackgroundDrawable(Background);
				}
			}
		});
 
GermainZ
Old
#9  
GermainZ's Avatar
Forum Moderator / Recognized Developer
Thanks Meter 6,355
Posts: 5,450
Join Date: Aug 2012
Quote:
Originally Posted by Falseclock View Post
If you module hooks Activity, Service or any other context application, you can store settings not with Shared Preferences, but in system settings database and use ContextResolver to get information from database.

and of course use <uses-permission android:name="android.permission.WRITE_SETTINGS" />

Here is an example:
Ideally, all traces of an Xposed module should be removed when it's uninstalled, IMO. This goes against that.
 
Falseclock
Old
#10  
Falseclock's Avatar
Senior Member
Thanks Meter 299
Posts: 504
Join Date: Jun 2012
Location: Almaty

 
DONATE TO ME
Quote:
Originally Posted by GermainZ View Post
Ideally, all traces of an Xposed module should be removed when it's uninstalled, IMO. This goes against that.
Ideally yes, but there are some tweak/mods requires fast settings change and immediate apply without restart. Otherwise such mods are not usable.

I do such only for special mods. All other mods are stored in shared preferences.

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes