Skip to content

Commit

Permalink
Small changes
Browse files Browse the repository at this point in the history
Make compatible with (Samsung phones with) Android 4.2.2
  • Loading branch information
OXINARF committed May 28, 2013
1 parent 9219642 commit bdcec54
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 61 deletions.
6 changes: 3 additions & 3 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="pt.oxinarf.simnumberchanger"
android:versionCode="1"
android:versionName="1.0" >
android:versionCode="2"
android:versionName="1.1" >

<uses-sdk
android:minSdkVersion="15"
Expand All @@ -15,7 +15,7 @@
android:label="@string/app_name" >

<meta-data android:value="true" android:name="xposedmodule"/>
<meta-data android:value="2.0*" android:name="xposedminversion"/>
<meta-data android:value="2.1.0*" android:name="xposedminversion"/>
<meta-data android:name="xposeddescription" android:value="Sets SIM card phone number"/>

<activity
Expand Down
130 changes: 72 additions & 58 deletions src/pt/oxinarf/simnumberchanger/XposedMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,87 +2,101 @@

import java.io.File;

import android.app.AndroidAppHelper;
import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Environment;
import android.telephony.TelephonyManager;
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.XposedHelpers;
import de.robv.android.xposed.XposedHelpers.ClassNotFoundError;
import de.robv.android.xposed.callbacks.XC_LoadPackage.LoadPackageParam;

public class XposedMod implements IXposedHookLoadPackage {

private static SharedPreferences prefs;

private static final String MY_PACKAGE_NAME = XposedMod.class.getPackage().getName();

private static Object phone;

private static String number;

private static TelephonyManager tm;

private final String MY_PACKAGE_NAME = XposedMod.class.getPackage().getName();

@Override
public void handleLoadPackage(LoadPackageParam lpparam) throws Throwable {
if (lpparam.packageName.equals("com.android.phone")) {
XposedHelpers.findAndHookMethod("com.android.phone.PhoneApp", lpparam.classLoader, "onCreate", new XC_MethodHook() {
Class<?> hookClass;

try {
hookClass = XposedHelpers.findClass("com.android.phone.PhoneGlobals", lpparam.classLoader);
}
catch (ClassNotFoundError e) {
try {
hookClass = XposedHelpers.findClass("com.android.phone.PhoneApp", lpparam.classLoader);
}
catch (ClassNotFoundError ex) {
XposedBridge.log("Classes don't exist - version not supported");
return;
}
}

File prefFile = new File(Environment.getDataDirectory(), "data/" + MY_PACKAGE_NAME + "/shared_prefs/" + "MainActivity.xml");

XSharedPreferences prefs;

if (prefFile.exists())
prefs = new XSharedPreferences(MY_PACKAGE_NAME, "MainActivity");
else
return;

@Override
final String number = prefs.getString("number", null);

if(number == null)
return;

XposedHelpers.findAndHookMethod(hookClass, "onCreate", new XC_MethodHook() { @Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
File prefFile = new File(Environment.getDataDirectory(), "data/" + MY_PACKAGE_NAME + "/shared_prefs/" + "MainActivity.xml");

if (prefFile.exists())
prefs = AndroidAppHelper.getSharedPreferencesForPackage(MY_PACKAGE_NAME, "MainActivity", Context.MODE_PRIVATE);
else
return;

number = prefs.getString("number", null);

if(number == null)
final Object phone;

try {
phone = XposedHelpers.getObjectField(param.thisObject, "phone");
}
catch (NoSuchFieldError ex) {
XposedBridge.log("Field 'phone' doesn't exist - version not supported");
return;

phone = XposedHelpers.getObjectField(param.thisObject, "phone");

}

if(phone == null) {
XposedBridge.log("Phone was null, it wasn't supposed!");
return;
}
tm = (TelephonyManager) ((Application) param.thisObject).getSystemService("phone");

final TelephonyManager tm = (TelephonyManager) ((Context) param.thisObject).getSystemService("phone");

new Thread(new Runnable() {
public void run() {
for(int simState = tm.getSimState(); simState != TelephonyManager.SIM_STATE_READY; simState = tm.getSimState()) {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {}
}

String tag = (String) XposedHelpers.callMethod(phone, "getLine1AlphaTag");
if(tag == null || tag.isEmpty() || tag.trim().equals("")) {
tag = "Line 1";
XposedBridge.log("Tag was empty - Line 1 now");
}

String actualNumber = (String) XposedHelpers.callMethod(phone, "getLine1Number");
XposedBridge.log("Actual Number is: " + actualNumber);
if(number.equals(actualNumber))
return;
XposedBridge.log("Going to write SIM number (" + number + ") now!");
XposedHelpers.callMethod(phone, "setLine1Number", tag, number, null);
}
public void run() {

for(int simState = tm.getSimState(); simState != TelephonyManager.SIM_STATE_READY; simState = tm.getSimState()) {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {}
}

String tag = (String) XposedHelpers.callMethod(phone, "getLine1AlphaTag");

if(tag == null || tag.isEmpty() || tag.trim().equals("")) {
tag = "Line 1";
XposedBridge.log("Tag was empty - 'Line 1' now");
}

String actualNumber = (String) XposedHelpers.callMethod(phone, "getLine1Number");

XposedBridge.log("Actual Number is: " + actualNumber);

if(number.equals(actualNumber))
return;

XposedBridge.log("Going to write SIM number (" + number + ") now!");

XposedHelpers.callMethod(phone, "setLine1Number", tag, number, null);
}
}).start();
}
}
});
}
}
Expand Down

0 comments on commit bdcec54

Please sign in to comment.