Hi, I have xposed module which makes statusbar icons smaller.
PHP:
XposedHelpers.findAndHookMethod("com.android.systemui.statusbar.StatusBarIconView", lpparam.classLoader, "getIconMz", Context.class, "com.android.internal.statusbar.StatusBarIcon", new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
super.afterHookedMethod(param);
context = (Context) param.args[0];
...
param.setResult(scaleIcon(context, (Drawable) param.getResult(), scale));
} });
This is the scaling function:
PHP:
public static BitmapDrawable scaleIcon(Context ctx, Drawable icon, int scale){
Bitmap src = ((BitmapDrawable) icon).getBitmap();
Bitmap dest = Bitmap.createScaledBitmap(src, scale, scale, true);
return new BitmapDrawable(context.getResources(), dest);
}
And since I'm not recycling any resource I got a question. What will be with memory?
Is memory for Bitmaps being reused or is it just accumulating?
If I try to recycle any resource I got "Canvas: trying to use a recycled bitmap" error in log and watch statusbar FC.
I've red this article but still have a doubt about memory...
Thanks in advance.
Related
We are working with a Galaxy S3 (Android 4.1.1). We are able to get the activity from param.thisObject and change the title by getting the activity and calling setTitle(), but when we want to start a new activity, the activity doesn't start. Does anyone know how to spawn a new activity?
Our code is building off of SmileyClock in the tutorial.
Main.java
---------------------------------------------------------------------------------------------------------------------------------------------------------------
package com.example.SmileyClock;
import static de.robv.android.xposed.XposedHelpers.findAndHookMethod;
import android.aMain.javapp.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import de.robv.android.xposed.IXposedHookLoadPackage;
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XSharedPreferences;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.callbacks.XC_LoadPackage.LoadPackageParam;
public class Main implements IXposedHookLoadPackage {
@override
public void handleLoadPackage(LoadPackageParam lpparam) throws Throwable {
// TODO Auto-generated method stub
if (!lpparam.packageName.equals("com.android.phone"))//check if the package being loaded is systemUI
return;
//All code here is only called if it is indeed SystemUI
findAndHookMethod("com.android.phone.EmergencyDialer", lpparam.classLoader, "placeCall", new XC_MethodHook() {
@override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
Activity emergencyDialer = (Activity) param.thisObject;
emergencyDialer.setTitle("Title has been changed!");
Intent newIntent = new Intent(emergencyDialer, BlackScreenActivity.class);
newIntent.addFlgags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
emergencyDialer.startActivity(newIntent);
Activity emergencyDialer = (Activity) param.thisObject;
Object[] args = param.args;
View view = (View) args[0];
emergencyDialer.setTitle("" + view.getId());
Intent newIntent = new Intent(Intent.ACTION_VIEW, null, emergencyDialer, BlackScreenActivity.class);
emergencyDialer.startActivity(newIntent);
}
});
}
}
BlackScreenActivity.java
---------------------------------------------------------------------------------------------------------------------------------------------------------------
package com.example.SmileyClock;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;
import android.view.WindowManager;
public class BlackScreenActivity extends Activity {
@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_black_screen);
//Remove title bar
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
//Remove notification bar
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
//set content view AFTER ABOVE sequence (to avoid crash)
this.setContentView(R.layout.activity_black_screen);
try {
Thread.sleep(3000);
finish();
Log.v("Xposed", "Sleep is done");
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Log.v("ERROR CATCH THING", e.toString());
}
}
@override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.black_screen, menu);
return true;
}
@override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Does anyone know where I can find code handling the current live wallpaper engine / view? I am trying to extract the live wallpaper for further processing (e.g. blurring).
I already found an entrance point: If the LWP used the standard com.android.internal.view.BaseSurfaceHolder supplied by the base class android.service.wallpaper.WallpaperService.Engine i can hook into lockCanvas and unlockCanvas to grab the image. But most LWPs do not use this, so I need another (more general) solution.
I thought about hooking all subclasses of android.service.wallpaper.WallpaperService, but AFAIK that's not possible without loading every single class and check if it's a subclass.
Any ideas?
Implementation for reference:
Code:
public class Hook implements IXposedHookLoadPackage {
@Override
public void handleLoadPackage(XC_LoadPackage.LoadPackageParam loadPackageParam) throws Throwable {
final Class<?> engingeClass = findClass("android.service.wallpaper.WallpaperService.Engine", loadPackageParam.classLoader);
final String packageName = loadPackageParam.packageName;
final Class<?> surfaceHolderClass = findClass("com.android.internal.view.BaseSurfaceHolder",loadPackageParam.classLoader);
findAndHookMethod(engingeClass, "getSurfaceHolder", new XC_MethodHook() {
private boolean isFirstCall = true;
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
Field field = findField(param.thisObject.getClass(), "this$0");
WallpaperService service = (WallpaperService) field.get(param.thisObject);
WallpaperManager wallpaperManager = WallpaperManager.getInstance(service);
if (isFirstCall && wallpaperManager.getWallpaperInfo().getPackageName().equals(packageName)) {
isFirstCall = false;
XposedBridge.log("Got context. Set up hooks...");
hook(surfaceHolderClass,service);
}
}
});
}
Bitmap bitmap;
Canvas internalCanvas;
Canvas originalCanvas;
private void hook(Class<?> clazz, final Context context) {
hookAllMethods(clazz, "lockCanvas", new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
originalCanvas = (Canvas) param.getResult();
bitmap = Bitmap.createBitmap(originalCanvas.getWidth(),originalCanvas.getHeight(), Bitmap.Config.ARGB_8888);
internalCanvas = new Canvas(bitmap);
param.setResult(internalCanvas);
XposedBridge.log("Locked Canvas");
}
});
findAndHookMethod(clazz, "unlockCanvasAndPost", Canvas.class, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
originalCanvas.drawBitmap(bitmap,0,0,null);
param.args[0] = originalCanvas;
Intent intent = new Intent("com.faendir.lwpextractor.WALLPAPER_CHANGE");
ByteArrayOutputStream bs = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG,100,bs);
intent.putExtra("bmp",bs.toByteArray());
context.sendBroadcast(intent, "com.faendir.lwpextractor.RECEIVE_WALLPAPER_CHANGE");
XposedBridge.log("Unlocked Canvas");
}
});
}
}
[this post is a copy of http://forum.xda-developers.com/xposed/modules/extract-live-wallpaper-t3260128, now posted here, because @Spott07 pointed out it would fit better]
Hello guys!
I'm learning to create Xposed modules and have a nice idea .
I'm just in the begining and I face a problem.
I'm trying to move the Google search bar in the Recent's window, this is my code:
Code:
public class Main implements IXposedHookLoadPackage {
@Override
public void handleLoadPackage(final LoadPackageParam loadPackageParam) throws Throwable {
if (!loadPackageParam.packageName.equals("com.android.systemui"))//check if the package being loaded is systemUI
return;
findAndHookMethod("com.android.systemui.recents.RecentsActivity", loadPackageParam.classLoader, "addSearchBarAppWidgetView", new XC_MethodHook() {
@Override
protected void afterHookedMethod(XC_MethodHook.MethodHookParam param) throws Throwable {
AppWidgetHostView newSearchBar = (AppWidgetHostView) param.thisObject;
newSearchBar.setPadding(0,0,0,100);
}
});
}
}
but it ain't working for some reason.
Help?
Also, I don't really know how to control the views already exists in the code of Google.
I guess the problem is that I don't takeover Google's search bar but create one of my own, that does not show.
Wassupdog said:
Hello guys!
I'm learning to create Xposed modules and have a nice idea .
I'm just in the begining and I face a problem.
I'm trying to move the Google search bar in the Recent's window, this is my code:
Code:
public class Main implements IXposedHookLoadPackage {
@Override
public void handleLoadPackage(final LoadPackageParam loadPackageParam) throws Throwable {
if (!loadPackageParam.packageName.equals("com.android.systemui"))//check if the package being loaded is systemUI
return;
findAndHookMethod("com.android.systemui.recents.RecentsActivity", loadPackageParam.classLoader, "addSearchBarAppWidgetView", new XC_MethodHook() {
@Override
protected void afterHookedMethod(XC_MethodHook.MethodHookParam param) throws Throwable {
AppWidgetHostView newSearchBar = (AppWidgetHostView) param.thisObject;
newSearchBar.setPadding(0,0,0,100);
}
});
}
}
but it ain't working for some reason.
Help?
Also, I don't really know how to control the views already exists in the code of Google.
I guess the problem is that I don't takeover Google's search bar but create one of my own, that does not show.
Click to expand...
Click to collapse
I think that your code isn't doing anything. I'm not surprised it isn't working
What is
Wassupdog said:
Hello guys!
I'm learning to create Xposed modules and have a nice idea .
I'm just in the begining and I face a problem.
I'm trying to move the Google search bar in the Recent's window, this is my code:
Code:
public class Main implements IXposedHookLoadPackage {
@Override
public void handleLoadPackage(final LoadPackageParam loadPackageParam) throws Throwable {
if (!loadPackageParam.packageName.equals("com.android.systemui"))//check if the package being loaded is systemUI
return;
findAndHookMethod("com.android.systemui.recents.RecentsActivity", loadPackageParam.classLoader, "addSearchBarAppWidgetView", new XC_MethodHook() {
@Override
protected void afterHookedMethod(XC_MethodHook.MethodHookParam param) throws Throwable {
AppWidgetHostView newSearchBar = (AppWidgetHostView) param.thisObject;
newSearchBar.setPadding(0,0,0,100);
}
});
}
}
but it ain't working for some reason.
Help?
Also, I don't really know how to control the views already exists in the code of Google.
I guess the problem is that I don't takeover Google's search bar but create one of my own, that does not show.
Click to expand...
Click to collapse
After a }, is ).
Please Check your Code.
Hello, I have made this code
Link : http://hastebin.com/hiyupafibi.java
Duplicated here :
Code:
//In my module, I have this activity MainActivity, which has a function to generate random number
private int randomNumber() {
return (new Random()).nextInt(3);
}
//Toast this random number somewhere in the main activity
Toast.makeText(MainActivity.this, " " + randomNumber(), Toast.LENGTH_LONG).show();
//In XposedMod, make a hook
public class XposedMod implements IXposedHookLoadPackage {
private TextView tv;
public static final String PACKAGE_NAME = ".......";
@Override
public void handleLoadPackage(LoadPackageParam lpparam) throws Throwable {
if (lpparam.packageName.equals(PACKAGE_NAME)) {
Class<?> MainActivityClass = XposedHelpers.findClass(PACKAGE_NAME + ".MainActivity", lpparam.classLoader);
XposedHelpers.findAndHookMethod(MainActivityClass, "randomNumber", new XC_MethodReplacement() {
@Override
protected Object replaceHookedMethod(MethodHookParam methodHookParam) throws Throwable {
try {
tv.setText("No NPE");
return 45;
} catch (NullPointerException e) {
return 44;
}
}
});
} else if (lpparam.packageName.equals("com.android.systemui")) {
Class<?> someClass = XposedHelpers.findClass("com.android.systemui.SomeClass", lpparam.classLoader);
XposedHelpers.findAndHookMethod(someClass, "someMethod", Context.class, new XC_MethodHook() {
@Override
protected Object beforeHookedMethod(MethodHookParam methodHookParam) throws Throwable {
tv = new TextView((Context) param.args[0]);
if (tv==null)
XposedBridge.log("tv is null, apologies!");
}
});
}
}
}
Everytime that toast is supposed to be shown, I get the answer to be 44 (that is, tv is null), but that should not be the case, because the log statement when tv is null is not shown. What am I doing wrong?
Thanks for the help, I appreciate it.
Cheers!
Hi,
I have hooked into afterHookedMethod to read some fields from an object but I'm getting java.lang.NoSuchFieldError and I don't understand why.
Say I have these files:
Code:
package com.android.demo;
public class Bar {
public boolean mBoolean;
public Bar() {
mBoolean = false;
}
}
Code:
package com.android.sample;
public class Foo {
Bar getBar() {
Bar bar = new Bar();
bar.mBoolean = true;
return bar;
}
}
And my Xposed hook:
Code:
findAndHookMethod(
"com.android.sample",
lpparam.classLoader,
"getBar",
new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
// This is supposed to be `bar`, right?
Object result = param.getResult();
// Throws java.lang.NoSuchFieldError: com.android.demo.Bar#mBoolean
Log.d(TAG, "mBoolean: " + String.valueOf(getBooleanField(result, "mBoolean")));
// In the end this is what I'm trying to do...
//setBooleanField(result, "mBoolean", false);
//Log.d(TAG, "mBoolean: " + String.valueOf(getBooleanField(result, "mBoolean")));
//param.setResult(result);
}
}
);
One thing that I should mention is that the real code I'm trying to change is obfuscated with Proguard. But I decoded it and looked for the method name - which was just "f" and use that instead of "getBar". I know I got the method name right because the error outputs the package name and class name correctly for the result object which is not obfuscated. And I'm sure this object has many public fields, but I can't access (or change for that matter) any of them without an exception being thrown.
What am I missing?
Whenever I've used this method, the first parameter has been the instance of the class (param.thisObject). I'm curious to know if it's possible to make it work the way you're trying to do with param.getResult().
But if you hook the constructor of the Bar class and try getObjectField with (param.thisObject, mBoolean) it should work.
PunchUp said:
Whenever I've used this method, the first parameter has been the instance of the class (param.thisObject). I'm curious to know if it's possible to make it work the way you're trying to do with param.getResult().
But if you hook the constructor of the Bar class and try getObjectField with (param.thisObject, mBoolean) it should work.
Click to expand...
Click to collapse
Maybe, but I'm not sure that allows me to achieve my end goal...
To be more specific, I'm trying to change the result of this:
https://github.com/android/platform...rc/com/android/email/SecurityPolicy.java#L120
Tried something simpler:
Code:
findAndHookMethod(
"com.android.emailcommon.provider.Policy",
lpparam.classLoader,
"a",
"android.database.Cursor",
new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
Log.d(TAG, "mPasswordMode = " +
String.valueOf(XposedHelpers.getIntField(param.thisObject, "mPasswordMode")));
}
}
);
Got this:
Code:
06-28 21:45:11.133 7201-7824/? E/Xposed: java.lang.NoSuchFieldError: com.android.emailcommon.provider.Policy#mPasswordMode
I don't understand what I'm missing...
I feel like an idiot...
I've been focusing on the methods and the fact that they are obfuscated that I forgot that the instance variables also are obfuscated.
It makes perfect sense now why none of this was working... Back to the drawing board.
Great Your question made me learn something new
PunchUp said:
Great Your question made me learn something new
Click to expand...
Click to collapse
Cool But what was that?
Save