Is there a way to use System context from non system app?
I try to create xposed module that enable double-tap to sleep in my specific app (the app is for G3 smart case only, so I try to mimic LG's stock Quick Circle apps).
I tried to override PowerManager.gotoSleep that will do
[CODEjava] mService.gotoSleep(time, GO_TO_SLEEP_REASON_DEVICE_ADMIN)[/CODE]
but it seem that the GO_TO_SLEEP_REASON_USER isn't the problem.
can I save the context of a system app for later use? using this code, context somewhy is null...
Java:
public class XposedModule implements IXposedHookLoadPackage {
static Context context;
[user=439709]@override[/user]
public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
if (lpparam.packageName.equals("com.yoavst.quickapps")) {
findAndHookMethod("com.yoavst.quickapps.DoubleTapper", lpparam.classLoader, "onDoubleTap", Context.class, MotionEvent.class, new XC_MethodHook() {
[user=439709]@override[/user]
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
XposedBridge.log("onDoubleTap After; context: " + (context == null ? "null" : "notNull"));
if (context != null) {
PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
powerManager.goToSleep(((MotionEvent) param.args[1]).getEventTime());
}
}
});
} else if (lpparam.packageName.equals("com.android.systemui")) {
findAndHookMethod("com.android.systemui.SystemUIService", lpparam.classLoader, "onCreate", new XC_MethodHook() {
[user=439709]@override[/user]
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
// this will be called before the clock was updated by the original method
}
[user=439709]@override[/user]
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
XposedBridge.log("hooking onCreate: " + (param.thisObject == null ? "null" :"not Null"));
context = (Service) param.thisObject;
XposedBridge.log("context: " + (context == null ? "null" :"not Null"));
}
});
}
}
}
You could call AndroidAppHelper.currentApplication() if you need any context — it doesn't look you need the system's context anyway..
GermainZ said:
You could call AndroidAppHelper.currentApplication() if you need any context — it doesn't look you need the system's context anyway..
Click to expand...
Click to collapse
I need the context of an app with DEVICE_POWER permission (level 2 permission).
Oh, wait — your code won't work at all the way you expect it to work. Keep in mind the hooked code is running in the hooked app's process, so even though you set "context" in com.android.systemui, the "context" variable is still null in the "com.yoavst.quickapps" process (and will *always* be null).
You probably want to send a broadcast from your app instead, and register a BroadcastReceiver somewhere in SystemUI to handle it.
@yoavst you need to use a Device Policy Manager that will allow you to turn off the display. Doesn't even require root or xposed.
Related
How to hook a onReceive method which is inside BroadcastReceiver?
Code:
public class RecentsActivity extends Activity
{
mIntentReceiver = new BroadcastReceiver()
{
public void onReceive(Context context, Intent intent)
{
...
}
};
}
I want to get my hook called when onReceive is invoked.
Anyone know?
mIntentReceiver is registered within onCreate method, so...
PHP:
XposedHelpers.findAndHookMethod(RecentsActivity.class, "onCreate", Bundle.class, new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
// get the field
final BroadcastReceiver mIntentReceiver = (BroadcastReceiver) XposedHelpers.getObjectField(param.thisObject, "mIntentReceiver");
// hook its class
XposedHelpers.findAndHookMethod(mIntentReceiver.getClass(), "onReceive", Context.class, Intent.class, new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
// check it !!!
BroadcastReceiver thiz = (BroadcastReceiver) param.thisObject;
if (thiz == mIntentReceiver) {
// get parameters
Context context = (Context) param.args[0];
Intent intent = (Intent) param.args[1];
// do your job...
}
}
});
}
});
Hope that helps you!!
Hi all,
I tried (partially succesful) to shift the status bar to the bottom of the screen. Unfortunatelly a black rectangle at the former statusbar position stays and keeps the apps away to use the full space (see picture below).
Here is my code so far:
Code:
public void handleLoadPackage(final LoadPackageParam lpparam) throws Throwable {
if (!lpparam.packageName.equals("com.android.systemui"))
return;
else {
XposedHelpers.findAndHookMethod("com.android.systemui.statusbar.phone.PhoneStatusBar", lpparam.classLoader, "getStatusBarGravity", new XC_MethodReplacement() {
@Override
protected Object replaceHookedMethod(MethodHookParam param) {
return Gravity.BOTTOM | Gravity.FILL_HORIZONTAL;
}
});
XposedHelpers.findAndHookMethod("com.android.systemui.statusbar.phone.PhoneStatusBar", lpparam.classLoader, "getStatusBarHeight", new XC_MethodReplacement() {
@Override
protected Object replaceHookedMethod(MethodHookParam param) {
return 65;
}
});
}
I tried already to override the resource "status_bar_height" with "0", but without success (Not found):
Code:
@Override
public void initZygote(StartupParam startupParam) throws Throwable {
String MODULE_PATH = startupParam.modulePath;
XModuleResources modRes = XModuleResources.createInstance(MODULE_PATH, null);
XResources.setSystemWideReplacement("android", "dimension", "status_bar_height", modRes.fwd(R.dimen.my_height));
}
The XPosed-Modul Dimension Editor also doesn't work by the way.
Maybe I could somehow make some magic in the PhoneWindowManager.java to let the apps fill till the screen top, but I don't know how:
https://github.com/DirtyUnicorns-Ki.../internal/policy/impl/PhoneWindowManager.java
Further information: Dirty Unicorn ROM for Galaxy Note N7000 KitKat.
Thank you very much!
I have searched relative keyword such as `sensor` in the repo, but could not find the answer.
I want to hook the step counter's sensor to do some auto-testing jobs on a health-kit app. Basically, we could get the steps by listening the SensorManager, the demo code would be
Code:
public class StepsActivity extends Activity implements SensorEventListener {
private SensorManager sensorManager;
private TextView count;
boolean activityRunning;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_steps);
count = (TextView) findViewById(R.id.count);
sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
}
@Override
protected void onResume() {
super.onResume();
activityRunning = true;
Sensor countSensor = sensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER);
if (countSensor != null) {
sensorManager.registerListener(this, countSensor, SensorManager.SENSOR_DELAY_UI);
} else {
Toast.makeText(this, "Count sensor not available!", Toast.LENGTH_LONG).show();
}
}
@Override
protected void onPause() {
super.onPause();
activityRunning = false;
}
@Override
public void onSensorChanged(SensorEvent event) {
if (activityRunning) {
count.setText(String.valueOf(event.values[0]));
}
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
}
I've read the tutorial, I know we could hook a specific function in a specific class, such as
Code:
findAndHookMethod("com.android.systemui.statusbar.policy.Clock", lpparam.classLoader, "updateClock", new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
TextView tv = (TextView) param.thisObject;
String text = tv.getText().toString();
tv.setText("time is:"+text);
tv.setTextColor(Color.RED);
}
});
But I'm wondering how to hook the data on system sensor?
I got the answer from github user townbull right now
I'm still a new user here and I was not permitted to publish external link here.
/XposedExp/blob/master/src/com/samsung/xposedexp/SensorHooks.java
coom said:
I got the answer from github user townbull right now
I'm still a new user here and I was not permitted to publish external link here.
/XposedExp/blob/master/src/com/samsung/xposedexp/SensorHooks.java
Click to expand...
Click to collapse
hi,i found that code is about samsung,what about nexus5 or other phone?
Hi,
I am trying to analyze an application(obfuscated with dexguard) which uses DexFile to load classes during runtime.
To list out what all classes the application call, I use the following Xposed code - (that's because the code is obfuscated and we cannot search for DexFile on the decompiled code).
Code:
findAndHookMethod("java.lang.ClassLoader", lpparam.classLoader, "loadClass", String.class, new XC_MethodHook() {
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
String classname = (String) param.args[0];
XposedBridge.log("Class Called - " + classname + " " + i++);
}
This lists all the classes and I see that the application calls "dalvik.system.DexFile". I used the following code to hook into DexFile constructor -
Code:
Constructor<?> constructDexFile = findConstructorExact(dalvik.system.DexFile.class, String.class);
XposedBridge.hookMethod(constructDexFile, new XC_MethodHook(XCallback.PRIORITY_HIGHEST) {
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
XposedBridge.log("DexFile Class 1 called");
}
});
Constructor<?> constructDexFile1 = findConstructorExact(dalvik.system.DexFile.class, File.class);
XposedBridge.hookMethod(constructDexFile1, new XC_MethodHook(XCallback.PRIORITY_HIGHEST) {
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
XposedBridge.log("DexFile Class 2 called");
}
});
Analyzing the log output, I see no trace of DexFile constructor being called.
Can someone help me out on how to analyze such application?
Hi,
I'm trying to hook some of the Android APIs in my module. I have a simple app consists of two activities (MyActivity, DisplayMessageActivity) and one service (LocationService). "MyActivity" starts "LocationService" using the following code:
Intent intent = new Intent(getApplicationContext(), LocationService.class);
startService(intent);
"MyActivity" can also start "DisplayMessageActivity" by pressing a button using the following code:
Intent intent = new Intent(this, DisplayMessageActivity.class);
startActivity(intent);
In the "LocationService", I register a GPS location listener at the start of service, which will update the "DisplayMessageActivity" upon change in the location or provider status as follows:
public int onStartCommand(Intent intent, int flags, int startId) {
LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
Intent intent1 = new Intent(getApplicationContext(), DisplayMessageActivity.class);
intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent1);
}
public void onStatusChanged(Location location) {
Intent intent1 = new Intent(getApplicationContext(), DisplayMessageActivity.class);
intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent1);
}
public void onProviderEnabled(Location location) {
Intent intent1 = new Intent(getApplicationContext(), DisplayMessageActivity.class);
intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent1);
}
public void onProviderDisabled(Location location) {
Intent intent1 = new Intent(getApplicationContext(), DisplayMessageActivity.class);
intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent1);
};
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000, 0, locationListener);
return Service.START_NOT_STICKY;
}
I hooked the method "startActivity" in my module as follows:
XposedHelpers.findAndHookMethod("android.app.Activity", lpparam.classLoader, "startActivity", android.content.Intent.class, new XC_MethodHook() {
@override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
Intent intent = (Intent) param.args[0];
String destination = intent.getComponent().getClassName().split(lpparam.packageName+".")[1];
XposedBridge.log("(Intent,"+destination+")");
}
});
The module successfully logs the invocation of "startActivity" when I press the button (starting "DisplayMessageActivity" from "MyActivity"). But when "startActivity" is invoked from the service, the module does not log the invocation. I'm new to Xposed and I'm not sure why this is happening. Is this because the "startActivity" is called from a background service? What can I do to resolve the issue?
I really appreciate your help
You can go to rovo89's Github for help, he is keen at helping other's development.
You are hooking on startActivity method of android.app.Activity class.
This method is specific for Activity class only as it overrides startActivity from super class (ContextWrapper and Context which is abstract). Calling startActivity within Service class is like calling completely different method that's why your hook won't work here.
To be able to cover both cases, you will have to hook on lower level in class hierarchy.
Probably the best would be to hook onto startActivity(Intent intent, Bundle bundle) of ContextWrapper class as it is sure all calls made from either Activity or Service will go this path.
So
Code:
XposedHelpers.findAndHookMethod("android.content.ContextWrapper", lpparam.classLoader, "startActivity", Intent.class, Bundle.class, new XC_MethodHook() {
....
}