Make prefs coherent, rename them, and rename SystemPermissionInstaller to SystemInstaller

This commit is contained in:
Dominik Schürmann 2014-05-12 18:59:03 +02:00
parent 1491f7318f
commit acd3137cbc
7 changed files with 77 additions and 20 deletions

View File

@ -28,12 +28,12 @@
<string name="notify_off">Do not notify of any updates</string> <string name="notify_off">Do not notify of any updates</string>
<string name="update_history">Update history</string> <string name="update_history">Update history</string>
<string name="update_history_summ">Days to consider apps new or recent: %s</string> <string name="update_history_summ">Days to consider apps new or recent: %s</string>
<string name="root_installer">Root access for app installations</string> <string name="root_installer">Install using root access</string>
<string name="root_installer_on">Root access is used to install/delete/update applications</string> <string name="root_installer_on">Request root access to install, update, and remove packages</string>
<string name="root_installer_off">Do not request root access to install/delete/update applications</string> <string name="root_installer_off">Do not request root access to install, update, and remove packages</string>
<string name="system_installer">Use system permissions for app installations</string> <string name="system_installer">Install using system-permissions</string>
<string name="system_installer_on">F-Droid tries to use system permissions to install/delete/update applications (only possible when installed as system-app)</string> <string name="system_installer_on">Use system permissions to install, update, and remove packages</string>
<string name="system_installer_off">F-Droid does not try to use system permissions to install/delete/update applications (only possible when installed as system-app)</string> <string name="system_installer_off">Do not use system permissions to install, update, and remove packages</string>
<string name="search_results">Search Results</string> <string name="search_results">Search Results</string>
<string name="app_details">App Details</string> <string name="app_details">App Details</string>
@ -275,5 +275,7 @@
<string name="update_all">Update all</string> <string name="update_all">Update all</string>
<string name="installer_error_title">(De-)Installation Error</string> <string name="installer_error_title">(De-)Installation Error</string>
<string name="installer_error_body">The (de-)installation failed. If you are using root access, try disabling this setting!</string> <string name="installer_error_body">The (de-)installation failed. If you are using root access, try disabling this setting!</string>
<string name="system_permission_denied_title">System permissions denied</string>
<string name="system_permission_denied_body">This option is only available when F-Droid is installed as a system-app.</string>
</resources> </resources>

View File

@ -54,7 +54,7 @@
android:defaultValue="false" android:defaultValue="false"
android:key="rootInstaller" /> android:key="rootInstaller" />
<CheckBoxPreference android:title="@string/system_installer" <CheckBoxPreference android:title="@string/system_installer"
android:defaultValue="true" android:defaultValue="false"
android:key="systemInstaller" /> android:key="systemInstaller" />
</PreferenceCategory> </PreferenceCategory>
</PreferenceScreen> </PreferenceScreen>

View File

@ -43,7 +43,7 @@ public class Preferences implements SharedPreferences.OnSharedPreferenceChangeLi
private static final boolean DEFAULT_ROOTED = true; private static final boolean DEFAULT_ROOTED = true;
private static final int DEFAULT_UPD_HISTORY = 14; private static final int DEFAULT_UPD_HISTORY = 14;
private static final boolean DEFAULT_ROOT_INSTALLER = false; private static final boolean DEFAULT_ROOT_INSTALLER = false;
private static final boolean DEFAULT_SYSTEM_INSTALLER = true; private static final boolean DEFAULT_SYSTEM_INSTALLER = false;
private boolean compactLayout = DEFAULT_COMPACT_LAYOUT; private boolean compactLayout = DEFAULT_COMPACT_LAYOUT;
private boolean filterAppsRequiringRoot = DEFAULT_ROOTED; private boolean filterAppsRequiringRoot = DEFAULT_ROOTED;

View File

@ -35,6 +35,7 @@ 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;
import org.fdroid.fdroid.installer.CheckRootAsyncTask.CheckRootCallback; import org.fdroid.fdroid.installer.CheckRootAsyncTask.CheckRootCallback;
import org.fdroid.fdroid.installer.Installer;
public class PreferencesActivity extends PreferenceActivity implements public class PreferencesActivity extends PreferenceActivity implements
OnSharedPreferenceChangeListener { OnSharedPreferenceChangeListener {
@ -217,13 +218,59 @@ public class PreferencesActivity extends PreferenceActivity implements
return true; return true;
} }
}); });
}
/**
* Initializes SystemInstaller preference, which can only be enabled when F-Droid is installed as a system-app
*/
protected void initSystemInstallerPreference() {
CheckBoxPreference pref = (CheckBoxPreference) findPreference(Preferences.PREF_SYSTEM_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()) {
if (Installer.hasSystemPermissions(PreferencesActivity.this, PreferencesActivity.this.getPackageManager())) {
// system-permission are granted, i.e. F-Droid is a system-app
SharedPreferences.Editor editor = pref.getSharedPreferences().edit();
editor.putBoolean(Preferences.PREF_SYSTEM_INSTALLER, true);
editor.commit();
pref.setChecked(true);
} else {
// system-permission not available
SharedPreferences.Editor editor = pref.getSharedPreferences().edit();
editor.putBoolean(Preferences.PREF_SYSTEM_INSTALLER, false);
editor.commit();
pref.setChecked(false);
AlertDialog.Builder alertBuilder = new AlertDialog.Builder(PreferencesActivity.this);
alertBuilder.setTitle(R.string.system_permission_denied_title);
alertBuilder.setMessage(PreferencesActivity.this.getString(R.string.system_permission_denied_body));
alertBuilder.setNeutralButton(android.R.string.ok, null);
alertBuilder.create().show();
}
} else {
SharedPreferences.Editor editor = pref.getSharedPreferences().edit();
editor.putBoolean(Preferences.PREF_SYSTEM_INSTALLER, false);
editor.commit();
pref.setChecked(false);
}
return true;
}
});
} }
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
getPreferenceScreen().getSharedPreferences() getPreferenceScreen().getSharedPreferences()
.registerOnSharedPreferenceChangeListener(this); .registerOnSharedPreferenceChangeListener(this);
@ -232,11 +279,13 @@ public class PreferencesActivity extends PreferenceActivity implements
} }
initRootInstallerPreference(); initRootInstallerPreference();
initSystemInstallerPreference();
} }
@Override @Override
protected void onPause() { protected void onPause() {
super.onPause(); super.onPause();
getPreferenceScreen().getSharedPreferences() getPreferenceScreen().getSharedPreferences()
.unregisterOnSharedPreferenceChangeListener(this); .unregisterOnSharedPreferenceChangeListener(this);
} }

View File

@ -121,6 +121,8 @@ public class DefaultInstallerSdk14 extends Installer {
mCallback.onError(InstallerCallback.OPERATION_DELETE, mCallback.onError(InstallerCallback.OPERATION_DELETE,
InstallerCallback.ERROR_CODE_CANCELED); InstallerCallback.ERROR_CODE_CANCELED);
} else { } else {
// UninstallAppProgress actually returns
// Activity.RESULT_FIRST_USER if something breaks
mCallback.onError(InstallerCallback.OPERATION_DELETE, mCallback.onError(InstallerCallback.OPERATION_DELETE,
InstallerCallback.ERROR_CODE_OTHER); InstallerCallback.ERROR_CODE_OTHER);
} }

View File

@ -118,16 +118,20 @@ abstract public class Installer {
} }
} }
// system permissions and pref enabled -> SystemPermissionInstaller // system permissions and pref enabled -> SystemInstaller
boolean isSystemInstallerEnabled = Preferences.get().isSystemInstallerEnabled(); boolean isSystemInstallerEnabled = Preferences.get().isSystemInstallerEnabled();
if (isSystemInstallerEnabled && hasSystemPermissions(activity, pm)) { if (isSystemInstallerEnabled) {
Log.d(TAG, "system permissions -> SystemPermissionInstaller"); if (hasSystemPermissions(activity, pm)) {
Log.d(TAG, "system permissions -> SystemInstaller");
try { try {
return new SystemPermissionInstaller(activity, pm, callback); return new SystemInstaller(activity, pm, callback);
} catch (AndroidNotCompatibleException e) { } catch (AndroidNotCompatibleException e) {
Log.e(TAG, "Android not compatible with SystemPermissionInstaller!", e); Log.e(TAG, "Android not compatible with SystemInstaller!", e);
}
} }
} else {
Log.e(TAG, "SystemInstaller is enabled in prefs, but system-perms are not granted!");
} }
// Fallback -> DefaultInstaller // Fallback -> DefaultInstaller
@ -170,14 +174,14 @@ abstract public class Installer {
if (hasSystemPermissions(context, pm)) { if (hasSystemPermissions(context, pm)) {
// we have system permissions! // we have system permissions!
return new SystemPermissionInstaller(context, pm, callback); return new SystemInstaller(context, pm, callback);
} else { } else {
// nope! // nope!
throw new AndroidNotCompatibleException(); throw new AndroidNotCompatibleException();
} }
} }
private static boolean hasSystemPermissions(Context context, PackageManager pm) { public static boolean hasSystemPermissions(Context context, PackageManager pm) {
int checkInstallPermission = int checkInstallPermission =
pm.checkPermission(permission.INSTALL_PACKAGES, context.getPackageName()); pm.checkPermission(permission.INSTALL_PACKAGES, context.getPackageName());
int checkDeletePermission = int checkDeletePermission =

View File

@ -56,14 +56,14 @@ import android.util.Log;
* https://android.googlesource.com/platform * https://android.googlesource.com/platform
* /frameworks/base/+/ccbf84f44c9e6a5ed3c08673614826bb237afc54 * /frameworks/base/+/ccbf84f44c9e6a5ed3c08673614826bb237afc54
*/ */
public class SystemPermissionInstaller extends Installer { public class SystemInstaller extends Installer {
private PackageInstallObserver mInstallObserver; private PackageInstallObserver mInstallObserver;
private PackageDeleteObserver mDeleteObserver; private PackageDeleteObserver mDeleteObserver;
private Method mInstallMethod; private Method mInstallMethod;
private Method mDeleteMethod; private Method mDeleteMethod;
public SystemPermissionInstaller(Context context, PackageManager pm, public SystemInstaller(Context context, PackageManager pm,
InstallerCallback callback) throws AndroidNotCompatibleException { InstallerCallback callback) throws AndroidNotCompatibleException {
super(context, pm, callback); super(context, pm, callback);