use of org.fdroid.fdroid.Preferences in project fdroidclient by f-droid.
the class PreferencesFragment method initPrivilegedInstallerPreference.
/**
* Initializes SystemInstaller preference, which can only be enabled when F-Droid is installed as a system-app
*/
private void initPrivilegedInstallerPreference() {
final CheckBoxPreference pref = (CheckBoxPreference) findPreference(Preferences.PREF_PRIVILEGED_INSTALLER);
// this preference.
if (pref == null) {
return;
}
Preferences p = Preferences.get();
boolean enabled = p.isPrivilegedInstallerEnabled();
boolean installed = PrivilegedInstaller.isExtensionInstalledCorrectly(getActivity()) == PrivilegedInstaller.IS_EXTENSION_INSTALLED_YES;
// way to easily install from here.
if (Build.VERSION.SDK_INT > 19 && !installed) {
PreferenceCategory other = (PreferenceCategory) findPreference("pref_category_other");
if (pref != null) {
other.removePreference(pref);
}
} else {
pref.setEnabled(installed);
pref.setDefaultValue(installed);
pref.setChecked(enabled && installed);
pref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
SharedPreferences.Editor editor = pref.getSharedPreferences().edit();
if (pref.isChecked()) {
editor.remove(Preferences.PREF_PRIVILEGED_INSTALLER);
} else {
editor.putBoolean(Preferences.PREF_PRIVILEGED_INSTALLER, false);
}
editor.apply();
return true;
}
});
}
}
use of org.fdroid.fdroid.Preferences in project fdroidclient by f-droid.
the class MainActivity method initialRepoUpdateIfRequired.
/**
* The first time the app is run, we will have an empty app list. To deal with this, we will
* attempt to update with the default repo. However, if we have tried this at least once, then
* don't try to do it automatically again.
*/
private void initialRepoUpdateIfRequired() {
Preferences prefs = Preferences.get();
if (!prefs.hasTriedEmptyUpdate()) {
Utils.debugLog(TAG, "We haven't done an update yet. Forcing repo update.");
prefs.setTriedEmptyUpdate(true);
UpdateService.updateNow(this);
}
}
use of org.fdroid.fdroid.Preferences in project fdroidclient by f-droid.
the class PreferencesFragment method initPrivilegedInstallerPreference.
/**
* Initializes SystemInstaller preference, which can only be enabled when F-Droid is installed as a system-app
*/
private void initPrivilegedInstallerPreference() {
final CheckBoxPreference pref = (CheckBoxPreference) findPreference(Preferences.PREF_PRIVILEGED_INSTALLER);
// this preference.
if (pref == null) {
return;
}
Preferences p = Preferences.get();
boolean enabled = p.isPrivilegedInstallerEnabled();
boolean installed = PrivilegedInstaller.isExtensionInstalledCorrectly(getActivity()) == PrivilegedInstaller.IS_EXTENSION_INSTALLED_YES;
// way to easily install from here.
if (Build.VERSION.SDK_INT > 19 && !installed) {
if (pref != null) {
otherPrefGroup.removePreference(pref);
}
} else {
pref.setEnabled(installed);
pref.setDefaultValue(installed);
pref.setChecked(enabled && installed);
pref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
SharedPreferences.Editor editor = pref.getSharedPreferences().edit();
if (pref.isChecked()) {
editor.remove(Preferences.PREF_PRIVILEGED_INSTALLER);
} else {
editor.putBoolean(Preferences.PREF_PRIVILEGED_INSTALLER, false);
}
editor.apply();
return true;
}
});
}
}
use of org.fdroid.fdroid.Preferences in project fdroidclient by f-droid.
the class PanicResponderActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
if (!Panic.isTriggerIntent(intent)) {
finish();
return;
}
// received intent from panic app
Log.i(TAG, "Received Panic Trigger...");
final Preferences preferences = Preferences.get();
boolean receivedTriggerFromConnectedApp = PanicResponder.receivedTriggerFromConnectedApp(this);
final boolean runningAppUninstalls = PrivilegedInstaller.isDefault(this);
ArrayList<String> wipeList = new ArrayList<>(preferences.getPanicWipeSet());
preferences.setPanicWipeSet(Collections.<String>emptySet());
preferences.setPanicTmpSelectedSet(Collections.<String>emptySet());
if (receivedTriggerFromConnectedApp && runningAppUninstalls && wipeList.size() > 0) {
// if this app (e.g. F-Droid) is to be deleted, do it last
if (wipeList.contains(getPackageName())) {
wipeList.remove(getPackageName());
wipeList.add(getPackageName());
}
final Context context = this;
final CountDownLatch latch = new CountDownLatch(1);
final LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
final String lastToUninstall = wipeList.get(wipeList.size() - 1);
final BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
switch((intent.getAction())) {
case Installer.ACTION_UNINSTALL_INTERRUPTED:
case Installer.ACTION_UNINSTALL_COMPLETE:
latch.countDown();
break;
}
}
};
lbm.registerReceiver(receiver, Installer.getUninstallIntentFilter(lastToUninstall));
for (String packageName : wipeList) {
InstalledApp installedApp = InstalledAppProvider.Helper.findByPackageName(context, packageName);
InstallerService.uninstall(context, new Apk(installedApp));
}
// wait for apps to uninstall before triggering final responses
new Thread() {
@Override
public void run() {
try {
latch.await(10, TimeUnit.MINUTES);
} catch (InterruptedException e) {
// ignored
}
lbm.unregisterReceiver(receiver);
if (preferences.panicResetRepos()) {
resetRepos(context);
}
if (preferences.panicHide()) {
HidingManager.hide(context);
}
if (preferences.panicExit()) {
exitAndClear();
}
}
}.start();
} else if (receivedTriggerFromConnectedApp) {
if (preferences.panicResetRepos()) {
resetRepos(this);
}
// Performing destructive panic response
if (preferences.panicHide()) {
Log.i(TAG, "Hiding app...");
HidingManager.hide(this);
}
}
// exit and clear, if not deactivated
if (!runningAppUninstalls && preferences.panicExit()) {
exitAndClear();
}
finish();
}
use of org.fdroid.fdroid.Preferences in project fdroidclient by f-droid.
the class PanicResponderActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
if (intent == null || !Panic.isTriggerIntent(intent)) {
finish();
return;
}
// received intent from panic app
Log.i(TAG, "Received Panic Trigger...");
Preferences preferences = Preferences.get();
if (PanicResponder.receivedTriggerFromConnectedApp(this)) {
Log.i(TAG, "Panic Trigger came from connected app");
// Performing destructive panic responses
if (preferences.panicHide()) {
Log.i(TAG, "Hiding app...");
HidingManager.hide(this);
}
}
// exit and clear, if not deactivated
if (preferences.panicExit()) {
ExitActivity.exitAndRemoveFromRecentApps(this);
if (Build.VERSION.SDK_INT >= 21) {
finishAndRemoveTask();
}
}
finish();
}
Aggregations