Skip to content

Commit

Permalink
Fixed rotation on settings activity. Issue #15
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteckler committed Sep 4, 2014
1 parent 20dd1b4 commit fc4c74e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
public class SettingsActivity extends Activity {

private static final String TAG = "NlpUnbounceSettings: ";

IabHelper mHelper;

@Override
Expand All @@ -31,6 +32,20 @@ public void onCreate(Bundle savedInstanceState) {
if (savedInstanceState == null)
getFragmentManager().beginTransaction().replace(android.R.id.content,
new PrefsFragment()).commit();

//Setup donations
//Normally we would secure this key, but we're not licensing this app.
String base64billing = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxwicOx54j03qBil36upqYab0uBWnf+WjoSRNOaTD9mkqj9bLM465gZlDXhutMZ+n5RlHUqmxl7jwH9KyYGTbwFqCxbLMCwR4oDhXVhX4fS6iggoHY7Ek6EzMT79x2XwCDg1pdQmX9d9TYRp32Sw2E+yg2uZKSPW29ikfdcmfkHcdCWrjFSuMJpC14R3d9McWQ7sg42eQq2spIuSWtP8ARGtj1M8eLVxgkQpXWrk9ijPgVcAbNZYWT9ndIZoKPg7VJVvzzAUNK/YOb+BzRurqJ42vCZy1+K+E4EUtmg/fxawHfXLZ3F/gNwictZO9fv1PYHPMa0sezSNVFAcm0yP1BwIDAQAB";
mHelper = new IabHelper(SettingsActivity.this, base64billing);
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
public void onIabSetupFinished(IabResult result)
{
if (!result.isSuccess()) {
Log.d(TAG, "In-app Billing setup failed: " + result);
}
}
});

}

@Override
Expand Down Expand Up @@ -72,8 +87,7 @@ public void onConsumeFinished(Purchase purchase, IabResult result) {
}};
};

@SuppressLint("ValidFragment")
public class PrefsFragment extends PreferenceFragment
public static class PrefsFragment extends PreferenceFragment
implements SharedPreferences.OnSharedPreferenceChangeListener {


Expand Down Expand Up @@ -102,20 +116,6 @@ public void onCreate(Bundle savedInstanceState) {
onSharedPreferenceChanged(sharedPref, "NlpCollectorWakeLock_blocked");
onSharedPreferenceChanged(sharedPref, "debug_logging");

//Setup donations
//Normally we would secure this key, but we're not licensing this app.
String base64billing = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxwicOx54j03qBil36upqYab0uBWnf+WjoSRNOaTD9mkqj9bLM465gZlDXhutMZ+n5RlHUqmxl7jwH9KyYGTbwFqCxbLMCwR4oDhXVhX4fS6iggoHY7Ek6EzMT79x2XwCDg1pdQmX9d9TYRp32Sw2E+yg2uZKSPW29ikfdcmfkHcdCWrjFSuMJpC14R3d9McWQ7sg42eQq2spIuSWtP8ARGtj1M8eLVxgkQpXWrk9ijPgVcAbNZYWT9ndIZoKPg7VJVvzzAUNK/YOb+BzRurqJ42vCZy1+K+E4EUtmg/fxawHfXLZ3F/gNwictZO9fv1PYHPMa0sezSNVFAcm0yP1BwIDAQAB";
SettingsActivity.this.mHelper = new IabHelper(SettingsActivity.this, base64billing);
SettingsActivity.this.mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
public void onIabSetupFinished(IabResult result)
{
if (!result.isSuccess()) {
Log.d(TAG, "In-app Billing setup failed: " + result);
}
}
});


//Hook up the custom clicks
Preference pref = (Preference) findPreference("ALARM_WAKEUP_LOCATOR_blocked");
pref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
Expand Down Expand Up @@ -165,7 +165,7 @@ public boolean onPreferenceClick(Preference preference) {
pref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
mHelper.launchPurchaseFlow(SettingsActivity.this, "donate_1", 1, SettingsActivity.this.mPurchaseFinishedListener, "1");
((SettingsActivity)getActivity()).mHelper.launchPurchaseFlow(getActivity(), "donate_1", 1, ((SettingsActivity)getActivity()).mPurchaseFinishedListener, "1");
return true;
}
});
Expand All @@ -174,7 +174,7 @@ public boolean onPreferenceClick(Preference preference) {
pref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
mHelper.launchPurchaseFlow(SettingsActivity.this, "donate_5", 5, SettingsActivity.this.mPurchaseFinishedListener, "5");
((SettingsActivity)getActivity()).mHelper.launchPurchaseFlow(getActivity(), "donate_5", 5, ((SettingsActivity)getActivity()).mPurchaseFinishedListener, "5");
return true;
}
});
Expand All @@ -183,7 +183,7 @@ public boolean onPreferenceClick(Preference preference) {
pref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
mHelper.launchPurchaseFlow(SettingsActivity.this, "donate_10", 10, SettingsActivity.this.mPurchaseFinishedListener, "10");
((SettingsActivity)getActivity()).mHelper.launchPurchaseFlow(getActivity(), "donate_10", 10, ((SettingsActivity)getActivity()).mPurchaseFinishedListener, "10");
return true;
}
});
Expand Down
18 changes: 16 additions & 2 deletions app/src/main/java/com/ryansteckler/nlpunbounce/nlpFix.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,21 @@ public void handleLoadPackage(LoadPackageParam lpparam) throws Throwable {
hookAlarms(lpparam, prefs);
hookWakeLocks(lpparam, prefs);


// findAndHookMethod("android.util.Slog", lpparam.classLoader, "d", String.class, String.class, new XC_MethodHook() {
// @Override
// protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
// String tag = (String)param.args[1];
// if (tag.contains("NlpWakeLock") && tag.contains("acquireWL")) {
// //stack trace?
// new Exception().printStackTrace();
// debugLog(prefs, "FOUND NLPWAKELOCK: " + tag);
// }
//
//// debugLog(prefs, "Wakelock params: " + param.args[0] + ", " + param.args[1] + ", " + param.args[2] + ", " + param.args[3] + ", " + param.args[4] + ", " + param.args[5] + ", " + param.args[6]);
// }
// });

}
}

Expand Down Expand Up @@ -110,12 +125,11 @@ else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1 &&
}
}

private void try19To20WakeLockHook(final LoadPackageParam lpparam, final XSharedPreferences prefs) {
private void try19To20WakeLockHook(LoadPackageParam lpparam, final XSharedPreferences prefs) {
findAndHookMethod("com.android.server.power.PowerManagerService", lpparam.classLoader, "acquireWakeLockInternal", android.os.IBinder.class, int.class, String.class, String.class, android.os.WorkSource.class, int.class, int.class, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {

// debugLog(prefs, "Wakelock params: " + param.args[0] + ", " + param.args[1] + ", " + param.args[2] + ", " + param.args[3] + ", " + param.args[4] + ", " + param.args[5] + ", " + param.args[6]);
String wakeLockName = (String)param.args[2];
handleWakeLock(param, prefs, wakeLockName);
}
Expand Down

0 comments on commit fc4c74e

Please sign in to comment.