Skip to content

Commit 518e3f5

Browse files
committed
Pass a context into getSuVersion() instead of keeping one around static in Su
1 parent be885ec commit 518e3f5

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/com/noshufou/android/su/Su.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class Su extends TabActivity {
2929
private static final int PACKAGE_UNINSTALL = 1;
3030
private static final int SEND_REPORT = 2;
3131

32-
private static Context mContext;
32+
private Context mContext;
3333
private String mMaliciousAppPackage = "";
3434

3535
@Override
@@ -89,7 +89,7 @@ private void firstRun() {
8989
}
9090
Log.d(TAG, "First run for version " + versionCode);
9191

92-
String suVer = getSuVersion();
92+
String suVer = getSuVersion(this);
9393
Log.d(TAG, "su version: " + suVer);
9494
new Updater(this, suVer).doUpdate();
9595

@@ -155,7 +155,7 @@ public void onClick(DialogInterface dialog, int which) {
155155
}
156156
}
157157

158-
public static String getSuVersion()
158+
public static String getSuVersion(Context context)
159159
{
160160
Process process = null;
161161
try {
@@ -172,13 +172,13 @@ public static String getSuVersion()
172172
}
173173
counter++;
174174
}
175-
return " " + mContext.getString(R.string.su_original);
175+
return " " + context.getString(R.string.su_original);
176176
} finally {
177177
stdInput.close();
178178
}
179179
} catch (IOException e) {
180180
Log.e(TAG, "Call to su failed. Perhaps the wrong version of su is present", e);
181-
return " " + mContext.getString(R.string.su_original);
181+
return " " + context.getString(R.string.su_original);
182182
} catch (InterruptedException e) {
183183
Log.e(TAG, "Call to su failed.", e);
184184
return " ...";

src/com/noshufou/android/su/SuPreferences.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.noshufou.android.su;
22

3+
import android.content.Context;
34
import android.content.SharedPreferences;
45
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
56
import android.content.pm.PackageInfo;
@@ -15,11 +16,15 @@
1516
public class SuPreferences extends PreferenceActivity implements OnSharedPreferenceChangeListener,
1617
OnPreferenceClickListener {
1718
// private static final String TAG = "Su.SuPreferences";
19+
20+
private Context mContext;
1821

1922
@Override
2023
protected void onCreate(Bundle savedInstanceState) {
2124
super.onCreate(savedInstanceState);
2225
addPreferencesFromResource(R.xml.preferences);
26+
27+
mContext = this;
2328

2429
Preference versionPreference = getPreferenceScreen().findPreference("pref_version");
2530
versionPreference.setTitle(getString(R.string.pref_version_title, getSuperuserVersion()));
@@ -61,7 +66,7 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
6166
public boolean onPreferenceClick(Preference preference) {
6267
if (preference.getKey().equals("pref_bin_version")) {
6368
Toast.makeText(this, R.string.checking, Toast.LENGTH_SHORT).show();
64-
new Updater(this, Su.getSuVersion()).doUpdate();
69+
new Updater(this, Su.getSuVersion(mContext)).doUpdate();
6570
return true;
6671
} else if (preference.getKey().equals("pref_clear_log")) {
6772
DBHelper db = new DBHelper(this);
@@ -98,7 +103,7 @@ private class ShowBinVersion extends AsyncTask<String, Integer, Boolean> {
98103

99104
@Override
100105
protected Boolean doInBackground(String... params) {
101-
suVersion = Su.getSuVersion();
106+
suVersion = Su.getSuVersion(mContext);
102107
return null;
103108
}
104109

0 commit comments

Comments
 (0)