Welcome to XDA

Search to go directly to your device's forum

Register an account

Unlock full posting privileges

Ask a question

No registration required
Post Reply

Question Applying changes without [soft-]rebooting

OP WisdomSky

25th June 2014, 10:53 AM   |  #1  
WisdomSky's Avatar
OP Senior Member
Flag In your mind
Thanks Meter: 660
 
149 posts
Join Date:Joined: May 2013
Donate to Me
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!
Last edited by WisdomSky; 25th June 2014 at 10:55 AM.
25th June 2014, 12:33 PM   |  #2  
GermainZ's Avatar
Forum Moderator / Recognized Developer / XDA Portal Team
Thanks Meter: 7,330
 
5,909 posts
Join Date:Joined: Aug 2012
Donate to Me
More
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: [ View ]
25th June 2014, 01:54 PM   |  #3  
WisdomSky's Avatar
OP Senior Member
Flag In your mind
Thanks Meter: 660
 
149 posts
Join Date:Joined: May 2013
Donate to Me
Quote:
Originally Posted by GermainZ

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...
25th June 2014, 02:02 PM   |  #4  
GermainZ's Avatar
Forum Moderator / Recognized Developer / XDA Portal Team
Thanks Meter: 7,330
 
5,909 posts
Join Date:Joined: Aug 2012
Donate to Me
More
Quote:
Originally Posted by WisdomSky

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: [ View ]
25th June 2014, 02:53 PM   |  #5  
WisdomSky's Avatar
OP Senior Member
Flag In your mind
Thanks Meter: 660
 
149 posts
Join Date:Joined: May 2013
Donate to Me
Quote:
Originally Posted by GermainZ

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.
Last edited by WisdomSky; 25th June 2014 at 02:57 PM.
25th June 2014, 03:08 PM   |  #6  
GermainZ's Avatar
Forum Moderator / Recognized Developer / XDA Portal Team
Thanks Meter: 7,330
 
5,909 posts
Join Date:Joined: Aug 2012
Donate to Me
More
Quote:
Originally Posted by WisdomSky

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?
27th June 2014, 06:38 PM   |  #7  
rovo89's Avatar
Senior Recognized Developer
Thanks Meter: 15,301
 
2,386 posts
Join Date:Joined: Jan 2012
More
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.
28th June 2014, 06:50 PM   |  #8  
Falseclock's Avatar
Senior Member
Flag Almaty
Thanks Meter: 318
 
517 posts
Join Date:Joined: Jun 2012
Donate to Me
More
Quote:
Originally Posted by WisdomSky

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);
				}
			}
		});
Last edited by Falseclock; 28th June 2014 at 07:04 PM.
28th June 2014, 07:00 PM   |  #9  
GermainZ's Avatar
Forum Moderator / Recognized Developer / XDA Portal Team
Thanks Meter: 7,330
 
5,909 posts
Join Date:Joined: Aug 2012
Donate to Me
More
Quote:
Originally Posted by Falseclock

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.
28th June 2014, 07:09 PM   |  #10  
Falseclock's Avatar
Senior Member
Flag Almaty
Thanks Meter: 318
 
517 posts
Join Date:Joined: Jun 2012
Donate to Me
More
Quote:
Originally Posted by GermainZ

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.

Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes