Search in sources :

Example 1 with InstalledApp

use of org.fdroid.fdroid.data.InstalledApp 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 2 with InstalledApp

use of org.fdroid.fdroid.data.InstalledApp in project fdroidclient by f-droid.

the class LocalRepoManager method addApp.

public void addApp(Context context, String packageName) {
    App app = null;
    try {
        InstalledApp installedApp = InstalledAppProvider.Helper.findByPackageName(context, packageName);
        app = App.getInstance(context, pm, installedApp, packageName);
        if (app == null || !app.isValid()) {
            return;
        }
    } catch (PackageManager.NameNotFoundException | CertificateEncodingException | IOException e) {
        Log.e(TAG, "Error adding app to local repo", e);
        return;
    }
    Utils.debugLog(TAG, "apps.put: " + packageName);
    apps.put(packageName, app);
}
Also used : InstalledApp(org.fdroid.fdroid.data.InstalledApp) FDroidApp(org.fdroid.fdroid.FDroidApp) App(org.fdroid.fdroid.data.App) CertificateEncodingException(java.security.cert.CertificateEncodingException) IOException(java.io.IOException) InstalledApp(org.fdroid.fdroid.data.InstalledApp)

Aggregations

InstalledApp (org.fdroid.fdroid.data.InstalledApp)2 BroadcastReceiver (android.content.BroadcastReceiver)1 Context (android.content.Context)1 Intent (android.content.Intent)1 LocalBroadcastManager (androidx.localbroadcastmanager.content.LocalBroadcastManager)1 IOException (java.io.IOException)1 CertificateEncodingException (java.security.cert.CertificateEncodingException)1 ArrayList (java.util.ArrayList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 FDroidApp (org.fdroid.fdroid.FDroidApp)1 Preferences (org.fdroid.fdroid.Preferences)1 Apk (org.fdroid.fdroid.data.Apk)1 App (org.fdroid.fdroid.data.App)1