Add root access preference
This commit is contained in:
parent
7ed69c93fc
commit
c4e7e617b2
@ -235,5 +235,8 @@
|
|||||||
<string name="Security">Security</string>
|
<string name="Security">Security</string>
|
||||||
<string name="System">System</string>
|
<string name="System">System</string>
|
||||||
<string name="Wallpaper">Wallpaper</string>
|
<string name="Wallpaper">Wallpaper</string>
|
||||||
|
|
||||||
|
<string name="requesting_root_access_title">Root access</string>
|
||||||
|
<string name="requesting_root_access_body">Requesting root access…</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -20,6 +20,7 @@ package org.fdroid.fdroid;
|
|||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
|
import android.preference.Preference.OnPreferenceClickListener;
|
||||||
import android.preference.PreferenceActivity;
|
import android.preference.PreferenceActivity;
|
||||||
import android.preference.CheckBoxPreference;
|
import android.preference.CheckBoxPreference;
|
||||||
import android.preference.EditTextPreference;
|
import android.preference.EditTextPreference;
|
||||||
@ -27,15 +28,16 @@ import android.preference.ListPreference;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
|
||||||
import android.support.v4.app.NavUtils;
|
import android.support.v4.app.NavUtils;
|
||||||
|
|
||||||
import org.fdroid.fdroid.Preferences;
|
import org.fdroid.fdroid.Preferences;
|
||||||
import org.fdroid.fdroid.compat.ActionBarCompat;
|
import org.fdroid.fdroid.compat.ActionBarCompat;
|
||||||
|
import org.fdroid.fdroid.installer.CheckRootAsyncTask;
|
||||||
|
import org.fdroid.fdroid.installer.CheckRootAsyncTask.CheckRootCallback;
|
||||||
|
|
||||||
public class PreferencesActivity extends PreferenceActivity implements
|
public class PreferencesActivity extends PreferenceActivity implements
|
||||||
OnSharedPreferenceChangeListener {
|
OnSharedPreferenceChangeListener {
|
||||||
|
|
||||||
public static final int RESULT_RESTART = 4;
|
public static final int RESULT_RESTART = 4;
|
||||||
private int result = 0;
|
private int result = 0;
|
||||||
|
|
||||||
@ -155,6 +157,56 @@ public class PreferencesActivity extends PreferenceActivity implements
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes RootInstaller preference. This method ensures that the preference can only be enabled
|
||||||
|
* when the user grants access to F-Droid.
|
||||||
|
*/
|
||||||
|
protected void initRootInstallerPreference() {
|
||||||
|
CheckBoxPreference pref = (CheckBoxPreference)findPreference(Preferences.PREF_ROOT_INSTALLER);
|
||||||
|
|
||||||
|
// we are handling persistence ourself!
|
||||||
|
pref.setPersistent(false);
|
||||||
|
|
||||||
|
pref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onPreferenceClick(Preference preference) {
|
||||||
|
final CheckBoxPreference pref = (CheckBoxPreference) preference;
|
||||||
|
|
||||||
|
if (pref.isChecked()) {
|
||||||
|
CheckRootAsyncTask checkTask = new CheckRootAsyncTask(PreferencesActivity.this, new CheckRootCallback() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRootCheck(boolean rootGranted) {
|
||||||
|
if (rootGranted) {
|
||||||
|
// root access granted
|
||||||
|
SharedPreferences.Editor editor = pref.getSharedPreferences().edit();
|
||||||
|
editor.putBoolean(Preferences.PREF_ROOT_INSTALLER, true);
|
||||||
|
editor.commit();
|
||||||
|
pref.setChecked(true);
|
||||||
|
} else {
|
||||||
|
// root access disallowed
|
||||||
|
SharedPreferences.Editor editor = pref.getSharedPreferences().edit();
|
||||||
|
editor.putBoolean(Preferences.PREF_ROOT_INSTALLER, false);
|
||||||
|
editor.commit();
|
||||||
|
pref.setChecked(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
checkTask.execute();
|
||||||
|
} else {
|
||||||
|
SharedPreferences.Editor editor = pref.getSharedPreferences().edit();
|
||||||
|
editor.putBoolean(Preferences.PREF_ROOT_INSTALLER, false);
|
||||||
|
editor.commit();
|
||||||
|
pref.setChecked(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
@ -166,6 +218,8 @@ public class PreferencesActivity extends PreferenceActivity implements
|
|||||||
for (String key : summariesToUpdate) {
|
for (String key : summariesToUpdate) {
|
||||||
updateSummary(key, false);
|
updateSummary(key, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
initRootInstallerPreference();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
74
src/org/fdroid/fdroid/installer/CheckRootAsyncTask.java
Normal file
74
src/org/fdroid/fdroid/installer/CheckRootAsyncTask.java
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2014 Dominik Schürmann <dominik@dominikschuermann.de>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 3
|
||||||
|
* of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.fdroid.fdroid.installer;
|
||||||
|
|
||||||
|
import org.fdroid.fdroid.R;
|
||||||
|
|
||||||
|
import eu.chainfire.libsuperuser.Shell;
|
||||||
|
import android.app.ProgressDialog;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.AsyncTask;
|
||||||
|
|
||||||
|
public class CheckRootAsyncTask extends AsyncTask<Void, Void, Boolean> {
|
||||||
|
|
||||||
|
ProgressDialog mDialog;
|
||||||
|
Context mContext;
|
||||||
|
CheckRootCallback mCallback;
|
||||||
|
|
||||||
|
public interface CheckRootCallback {
|
||||||
|
public void onRootCheck(boolean rootGranted);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CheckRootAsyncTask(Context context, CheckRootCallback callback) {
|
||||||
|
super();
|
||||||
|
this.mContext = context;
|
||||||
|
this.mCallback = callback;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPreExecute() {
|
||||||
|
super.onPreExecute();
|
||||||
|
|
||||||
|
mDialog = new ProgressDialog(mContext);
|
||||||
|
mDialog.setTitle(R.string.requesting_root_access_title);
|
||||||
|
mDialog.setMessage(mContext.getString(R.string.requesting_root_access_body));
|
||||||
|
mDialog.setIndeterminate(true);
|
||||||
|
mDialog.setCancelable(false);
|
||||||
|
mDialog.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Boolean doInBackground(Void... params) {
|
||||||
|
|
||||||
|
boolean suAvailable = Shell.SU.available();
|
||||||
|
|
||||||
|
return suAvailable;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(Boolean result) {
|
||||||
|
super.onPostExecute(result);
|
||||||
|
|
||||||
|
mDialog.dismiss();
|
||||||
|
|
||||||
|
mCallback.onRootCheck(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -93,7 +93,7 @@ abstract public class Installer {
|
|||||||
* Creates a new Installer for installing/deleting processes starting from
|
* Creates a new Installer for installing/deleting processes starting from
|
||||||
* an Activity
|
* an Activity
|
||||||
*
|
*
|
||||||
* @param context
|
* @param activity
|
||||||
* @param pm
|
* @param pm
|
||||||
* @param callback
|
* @param callback
|
||||||
* @return
|
* @return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user