forked from mateor/OpenPDroidPatches
-
Notifications
You must be signed in to change notification settings - Fork 24
Open
Description
Hey guys (@ALL OPD/PD2.0 DEVS),
I'm currently trying to learn smali and how to handle with it.
I do that because I will port PD2.0/OPD to Stock ROMs, and I think it is possible.
The last few days I spent a lot of time to understand how to include the PD framework to the original stock framework and yeah, I believe I found a good solution for that.
But to make it easier and possible for me to port PDroid to Stock ROMs it is neccessary trying to follow following "rules":
- If you want to insert code in the framework, put as much code as you can into your OWN methods
- Try to use not so much parameters for one method (good parameter count should be smaller or equal 3)
- Don't blow up the framework methods with your own stuff
- hold the lines at a minimum level if you insert code in the framework which is out of your own methods
- try to use not so much variables
Example (an old piece of code, please ignore style or whatever, just try to understand what I mean):
Bad way:
public void startActivity (Context who, IBinder contextThread, IBinder token, Activity target, Intent intent, int requestCode, Bundle options) {
// BEGIN PRIVACY
boolean isAllowed = true;
try{
Log.i("PrivacyContext","now we are in execStartActivity() from package: " + who.getPackageName());
if(intent.getAction().equals(Intent.ACTION_CALL) || intent.getAction().equals(Intent.ACTION_DIAL)){
Log.i("PrivacyContext","package: " + who.getPackageName() + " tries to take a phone call");
if(pSetMan == null) pSetMan = new PrivacySettingsManager(who, IPrivacySettingsManager.Stub.asInterface(ServiceManager.getService("privacy")));
PrivacySettings settings = pSetMan.getSettings(who.getPackageName(), -1);
if(pSetMan != null && settings != null && settings.getPhoneCallSetting() != PrivacySettings.REAL){ //is not allowed
//test if broadcasting works!
final Context tmp = who;
isAllowed = false;
new Thread(new Runnable() {
public void run() {
try{
Thread.sleep(1000); //wait 1 Second
}
catch(Exception e){
//nothing here
}
Intent privacy = new Intent("android.privacy.BLOCKED_PHONE_CALL");
Bundle extras = new Bundle();
extras.putString("packageName", tmp.getPackageName());
extras.putInt("phoneState", TelephonyManager.CALL_STATE_IDLE);
privacy.putExtras(extras);
tmp.sendBroadcast(privacy);
Log.i("PrivacyContext","sent privacy intent");
}
}).start();
pSetMan.notification(who.getPackageName(), 0, PrivacySettings.EMPTY, PrivacySettings.DATA_PHONE_CALL, null, settings);
}
else{ //is allowed
isAllowed = true;
pSetMan.notification(who.getPackageName(), 0, PrivacySettings.REAL, PrivacySettings.DATA_PHONE_CALL, null, settings);
}
}
}
catch(Exception e){
e.printStackTrace();
if(who != null)
Log.i("PrivacyContext","got exception while trying to resolve intents for package: " + who.getPackageName());
else
Log.i("PrivacyContext","got exception while trying to resolve intents for unknown package");
}
// END PRIVACY
........
}Better solution:
public void startActivity (Context who, IBinder contextThread, IBinder token, Activity target, Intent intent, int requestCode, Bundle options) {
// BEGIN PRIVACY
boolean isAllowed = enforcePrivacyPermissions(params..);
........
// END PRIVACY
}
private boolean enforePrivacyPermissions(params...) {
boolean isAllowed = true;
try{
Log.i("PrivacyContext","now we are in execStartActivity() from package: " + who.getPackageName());
if(intent.getAction().equals(Intent.ACTION_CALL) || intent.getAction().equals(Intent.ACTION_DIAL)){
Log.i("PrivacyContext","package: " + who.getPackageName() + " tries to take a phone call");
if(pSetMan == null) pSetMan = new PrivacySettingsManager(who, IPrivacySettingsManager.Stub.asInterface(ServiceManager.getService("privacy")));
PrivacySettings settings = pSetMan.getSettings(who.getPackageName(), -1);
if(pSetMan != null && settings != null && settings.getPhoneCallSetting() != PrivacySettings.REAL){ //is not allowed
//test if broadcasting works!
final Context tmp = who;
isAllowed = false;
new Thread(new Runnable() {
public void run() {
try{
Thread.sleep(1000); //wait 1 Second
}
catch(Exception e){
//nothing here
}
Intent privacy = new Intent("android.privacy.BLOCKED_PHONE_CALL");
Bundle extras = new Bundle();
extras.putString("packageName", tmp.getPackageName());
extras.putInt("phoneState", TelephonyManager.CALL_STATE_IDLE);
privacy.putExtras(extras);
tmp.sendBroadcast(privacy);
Log.i("PrivacyContext","sent privacy intent");
}
}).start();
pSetMan.notification(who.getPackageName(), 0, PrivacySettings.EMPTY, PrivacySettings.DATA_PHONE_CALL, null, settings);
}
else{ //is allowed
isAllowed = true;
pSetMan.notification(who.getPackageName(), 0, PrivacySettings.REAL, PrivacySettings.DATA_PHONE_CALL, null, settings);
}
}
}
catch(Exception e){
e.printStackTrace();
if(who != null)
Log.i("PrivacyContext","got exception while trying to resolve intents for package: " + who.getPackageName());
else
Log.i("PrivacyContext","got exception while trying to resolve intents for unknown package");
}
return isAllowed;
}Metadata
Metadata
Assignees
Labels
No labels