Search in sources :

Example 1 with Preferences

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;
            }
        });
    }
}
Also used : CheckBoxPreference(android.preference.CheckBoxPreference) PreferenceCategory(android.preference.PreferenceCategory) AppCompatListPreference(com.geecko.QuickLyric.view.AppCompatListPreference) CheckBoxPreference(android.preference.CheckBoxPreference) EditTextPreference(android.preference.EditTextPreference) ListPreference(android.preference.ListPreference) Preference(android.preference.Preference) Preferences(org.fdroid.fdroid.Preferences) SharedPreferences(android.content.SharedPreferences)

Example 2 with Preferences

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);
    }
}
Also used : Preferences(org.fdroid.fdroid.Preferences)

Example 3 with Preferences

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;
            }
        });
    }
}
Also used : CheckBoxPreference(androidx.preference.CheckBoxPreference) CheckBoxPreference(androidx.preference.CheckBoxPreference) SeekBarPreference(androidx.preference.SeekBarPreference) EditTextPreference(androidx.preference.EditTextPreference) Preference(androidx.preference.Preference) ListPreference(androidx.preference.ListPreference) Preferences(org.fdroid.fdroid.Preferences) SharedPreferences(android.content.SharedPreferences)

Example 4 with Preferences

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();
}
Also used : Context(android.content.Context) ArrayList(java.util.ArrayList) Intent(android.content.Intent) CountDownLatch(java.util.concurrent.CountDownLatch) BroadcastReceiver(android.content.BroadcastReceiver) LocalBroadcastManager(androidx.localbroadcastmanager.content.LocalBroadcastManager) InstalledApp(org.fdroid.fdroid.data.InstalledApp) Preferences(org.fdroid.fdroid.Preferences) Apk(org.fdroid.fdroid.data.Apk)

Example 5 with Preferences

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();
}
Also used : Intent(android.content.Intent) Preferences(org.fdroid.fdroid.Preferences)

Aggregations

Preferences (org.fdroid.fdroid.Preferences)6 SharedPreferences (android.content.SharedPreferences)3 Intent (android.content.Intent)2 CheckBoxPreference (androidx.preference.CheckBoxPreference)2 EditTextPreference (androidx.preference.EditTextPreference)2 ListPreference (androidx.preference.ListPreference)2 Preference (androidx.preference.Preference)2 SeekBarPreference (androidx.preference.SeekBarPreference)2 BroadcastReceiver (android.content.BroadcastReceiver)1 Context (android.content.Context)1 CheckBoxPreference (android.preference.CheckBoxPreference)1 EditTextPreference (android.preference.EditTextPreference)1 ListPreference (android.preference.ListPreference)1 Preference (android.preference.Preference)1 PreferenceCategory (android.preference.PreferenceCategory)1 LocalBroadcastManager (androidx.localbroadcastmanager.content.LocalBroadcastManager)1 PreferenceCategory (androidx.preference.PreferenceCategory)1 LinearSmoothScroller (androidx.recyclerview.widget.LinearSmoothScroller)1 AppCompatListPreference (com.geecko.QuickLyric.view.AppCompatListPreference)1 ArrayList (java.util.ArrayList)1