Galaxy S3 ver 4.1.1 - Trying to start Activity from Emergency Dialer after placeCall - Xposed Framework Development

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);
}
}

Related

[App] QuickSnap - Makes up for no hardware camera button

Very simple application that makes up (slightly) for not having a dedicated camera button.
Install the app, put a shortcut to it on your homepage. Shortcut will open (as quickly as possible) a preview window. Tapping anywhere on the screen will take a photo. Back button to exit.
QuickSnapNoAutofocus.apk - Takes pictures instantly, but you need a steady hand or your picture will be blurred!
QuickSnapAutoFocus.apk - Takes pictures using autofocus, so there is a delay while it focuses, but the pictures can't be blurred.
Saves the images to internal sd card as $DT.jpg on a seperate thread. Multiple taps on the screen to take lots of pictures quickly. (Supports multitouch! )
Source is in the next post - if anybody knows how to override the home or power button, give a shout!
Code:
package com.rc.QuickSnap;
import java.io.FileOutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import android.app.Activity;
import android.hardware.Camera;
import android.hardware.Camera.AutoFocusCallback;
import android.hardware.Camera.PictureCallback;
import android.hardware.Camera.ShutterCallback;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceHolder.Callback;
import android.view.SurfaceView;
public class QuickSnap extends Activity {
Camera cam;
ExecutorService executorService;
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss");
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
@Override
protected void onPause() {
super.onPause();
try {
cam.stopPreview();
} catch (Exception ex) {
ex.printStackTrace();
}
try {
cam.release();
} catch (Exception ex) {
ex.printStackTrace();
}
try {
executorService.shutdown();
} catch (Exception ex) {
ex.printStackTrace();
}
}
@Override
protected void onResume() {
super.onResume();
executorService = Executors.newSingleThreadExecutor();
try {
SurfaceView surface = (SurfaceView) findViewById(R.id.surface);
SurfaceHolder sh = surface.getHolder();
sh.setKeepScreenOn(true);
sh.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
sh.addCallback(new Callback() {
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
Log.i("QuickSnap", "surfaceDestroyed");
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
Log.i("QuickSnap", "surfaceCreated");
try {
cam = Camera.open();
cam.setPreviewDisplay(holder);
cam.startPreview();
} catch (Exception ex) {
ex.printStackTrace();
}
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
Log.i("QuickSnap", "surfaceChanged");
try {
cam.setPreviewDisplay(holder);
} catch (Exception ex) {
ex.printStackTrace();
}
}
});
} catch (Exception ex) {
ex.printStackTrace();
}
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
Log.i("QuickSnap", "TouchEvent");
cam.autoFocus(new AutoFocusCallback() {
@Override
public void onAutoFocus(boolean success, Camera camera) {
cam.takePicture(new ShutterCallback() {
@Override
public void onShutter() {
Log.i("QuickSnap", "Shutter");
}
}, null, new PictureCallback() {
@Override
public void onPictureTaken(byte[] data, Camera camera) {
Log.i("QuickSnap", "JPEG");
final byte[] finaldata = data;
executorService.submit(new Runnable() {
@Override
public void run() {
try {
FileOutputStream fileOutputStream = new FileOutputStream("/sdcard/" + sdf.format(new Date()) + ".jpg");
fileOutputStream.write(finaldata);
fileOutputStream.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
});
camera.startPreview();
}
});
}
});
}
return true;
}
}
thx a lot !!
Looks great, gotta try. Thanks!
Has anyone got a mod that takes control of the Vol+ key for use with a camera?

Closing gps in gps event handler - endless loop

In my application when I get position latitude and longitude from GPS, I am downloading bing map to a picture box. I've been trying now to protect my application in case there is no internet connection. I've done that in the GetMap function and it works fine. After that I want to close gps - the problem is that I'm trying to do that in gps event handler - it is so because I update the picture box constantly:
Code:
void UpdateData(object sender, System.EventArgs args)
{
menuGPS.Text = "Enable GPS";
menuZoom.Enabled = false;
menuView.Enabled = false;
}
void gps_LocationChanged(object sender, Microsoft.WindowsMobile.Samples.Location.LocationChangedEventArgs args)
{
if (args.Position.LatitudeValid && args.Position.LongitudeValid)
{
if (isCameraEnabled == false)
{
try
{
pbMap.Invoke((UpdateMap)delegate()
{
pbMap.Image = bingMap.GetMap(args.Position.Latitude,
args.Position.Longitude,
zoom,
mapStyle);
});
if (pbMap.Image == null)
{
Invoke(updateDataHandler);
gpsData.gps.LocationChanged -= gps_LocationChanged;
gpsData.closeGPS();
}
}
catch (ArgumentException ex)
{
MessageBox.Show("An error has occured:" + ex.Message , "Error");
}
}
else
{
}
}
}
So after the gpsData.gps.LocationChanged -= gps_LocationChanged; and gpsData.closeGPS(); are being called in the event handler the gps gets stuck in the WaitForGpsEvents() method in GPS.cs in the while loop because bool lisening value is not changed to false.
If I put gpsData.gps.LocationChanged -= gps_LocationChanged; and gpsData.closeGPS(); to the void UpdateData(object sender, System.EventArgs args) then it stops in the Close() method on the lock condition:
// block until our event thread is finished before
// we close our native event handles
lock (this)
How can I close the GPS?

XClasses - A Xposed Library

Hello guys,
I want to share my library XClasses.
My idea was to see every XClass as an extension of the original class.
My aim was to improve the user experience during the development.
Also I wanted to increase the readability of xposed code.
So it's nothing special.
It's just my personal opinion how readable code should look like.
A small example:
Code:
public class XposedMain implements IXposedHookLoadPackage
{
@Override
public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam)
throws Throwable {
if(lpparam.packageName.equals("com.android.systemui"))
{
XposedHelpers.findAndHookMethod(TextView.class, "setText", CharSequence.class, TextView.BufferType.class, boolean.class, int.class, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param)
throws Throwable {
TextView tv = (TextView)param.thisObject;
CharSequence text = (CharSequence)param.args[0];
TextView.BufferType type = (TextView.BufferType)param.args[1];
boolean notifyBefore = (Boolean)param.args[2];
int oldlen = (Integer)param.args[3];
XposedBridge.log("setText "+text+" with size "+tv.getTextSize());
}
});
}
}
}
The same code with XClasses:
Code:
// class 1
public class XposedMain implements IXposedHookLoadPackage
{
@Override
public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam)
throws Throwable {
if(lpparam.packageName.equals("com.android.systemui"))
{
setup(lpparam.classLoader);
hook(XTextView.class);
}
}
}
// class 2
public class XTextView
extends AbstractXClass<TextView>
{
public static String getOriginalClassName() { return TextView.class.getCanonicalName(); }
public XTextView(TextView objectThis) { super(objectThis); }
@BeforeOriginalMethod
private void setText_Before(CharSequence text, TextView.BufferType type,
boolean notifyBefore, int oldlen) throws Throwable {
XposedBridge.log("setText "+text+" with size "+getThis().getTextSize());
}
}
If you would like to know more you should visit the following site: https://github.com/seebye/XClasses
Regards,
Seebye

[Q] Extract live wallpaper

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]

[Q] How to use a variable from one hook in another? (Why is this an NPE?)

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!

Categories

Resources