Search in sources :

Example 16 with Apk

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

the class KnownVulnAppListItemController method onActionButtonPressed.

@Override
protected void onActionButtonPressed(@NonNull App app) {
    Apk installedApk = app.getInstalledApk(activity);
    if (installedApk == null) {
        throw new IllegalStateException("Tried to update or uninstall app with known vulnerability but it doesn't seem to be installed");
    }
    Apk suggestedApk = ApkProvider.Helper.findSuggestedApk(activity, app);
    if (shouldUpgradeInsteadOfUninstall(app, suggestedApk)) {
        LocalBroadcastManager manager = LocalBroadcastManager.getInstance(activity);
        manager.registerReceiver(installReceiver, Installer.getInstallIntentFilter(suggestedApk.getCanonicalUrl()));
        InstallManagerService.queue(activity, app, suggestedApk);
    } else {
        LocalBroadcastManager manager = LocalBroadcastManager.getInstance(activity);
        manager.registerReceiver(installReceiver, Installer.getUninstallIntentFilter(app.packageName));
        InstallerService.uninstall(activity, installedApk);
    }
}
Also used : Apk(org.fdroid.fdroid.data.Apk) LocalBroadcastManager(androidx.localbroadcastmanager.content.LocalBroadcastManager)

Example 17 with Apk

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

the class KnownVulnAppListItemController method getCurrentViewState.

@NonNull
@Override
protected AppListItemState getCurrentViewState(@NonNull App app, @Nullable AppUpdateStatusManager.AppUpdateStatus appStatus) {
    String mainText;
    String actionButtonText;
    Apk suggestedApk = ApkProvider.Helper.findSuggestedApk(activity, app);
    if (shouldUpgradeInsteadOfUninstall(app, suggestedApk)) {
        mainText = activity.getString(R.string.updates__app_with_known_vulnerability__prompt_upgrade, app.name);
        actionButtonText = activity.getString(R.string.menu_upgrade);
    } else {
        mainText = activity.getString(R.string.updates__app_with_known_vulnerability__prompt_uninstall, app.name);
        actionButtonText = activity.getString(R.string.menu_uninstall);
    }
    return new AppListItemState(app).setMainText(mainText).showActionButton(actionButtonText).showSecondaryButton(activity.getString(R.string.updates__app_with_known_vulnerability__ignore));
}
Also used : AppListItemState(org.fdroid.fdroid.views.apps.AppListItemState) Apk(org.fdroid.fdroid.data.Apk) NonNull(androidx.annotation.NonNull)

Example 18 with Apk

use of org.fdroid.fdroid.data.Apk 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 19 with Apk

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

the class ApkVerifierTest method testWithPrefix.

@Test
public void testWithPrefix() {
    Apk apk = new Apk();
    apk.packageName = "org.fdroid.permissions.sdk14";
    apk.targetSdkVersion = 14;
    TreeSet<String> expectedSet = new TreeSet<>(Arrays.asList("android.permission.AUTHENTICATE_ACCOUNTS", "android.permission.MANAGE_ACCOUNTS", "android.permission.READ_PROFILE", "android.permission.WRITE_PROFILE", "android.permission.GET_ACCOUNTS", "android.permission.READ_CONTACTS", "android.permission.WRITE_CONTACTS", "android.permission.WRITE_EXTERNAL_STORAGE", "android.permission.READ_EXTERNAL_STORAGE", "android.permission.INTERNET", "android.permission.ACCESS_NETWORK_STATE", "android.permission.NFC", "android.permission.READ_SYNC_SETTINGS", "android.permission.WRITE_SYNC_SETTINGS", // implied-permission!
    "android.permission.WRITE_CALL_LOG", // implied-permission!
    "android.permission.READ_CALL_LOG"));
    if (Build.VERSION.SDK_INT >= 29) {
        expectedSet.add("android.permission.ACCESS_MEDIA_LOCATION");
    }
    apk.requestedPermissions = expectedSet.toArray(new String[0]);
    Uri uri = Uri.fromFile(sdk14Apk);
    ApkVerifier apkVerifier = new ApkVerifier(instrumentation.getContext(), uri, apk);
    try {
        apkVerifier.verifyApk();
    } catch (ApkVerifier.ApkVerificationException | ApkVerifier.ApkPermissionUnequalException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : TreeSet(java.util.TreeSet) Apk(org.fdroid.fdroid.data.Apk) Uri(android.net.Uri) FileCompatTest(org.fdroid.fdroid.compat.FileCompatTest) Test(org.junit.Test)

Example 20 with Apk

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

the class ApkVerifierTest method testWithMinMax.

@Test(expected = ApkVerifier.ApkPermissionUnequalException.class)
public void testWithMinMax() throws ApkVerifier.ApkPermissionUnequalException, ApkVerifier.ApkVerificationException {
    Apk apk = new Apk();
    apk.packageName = "org.fdroid.permissions.minmax";
    apk.targetSdkVersion = 24;
    ArrayList<String> permissionsList = new ArrayList<>();
    permissionsList.add("android.permission.READ_CALENDAR");
    if (Build.VERSION.SDK_INT <= 18) {
        permissionsList.add("android.permission.WRITE_EXTERNAL_STORAGE");
    }
    if (Build.VERSION.SDK_INT >= 23) {
        permissionsList.add("android.permission.ACCESS_FINE_LOCATION");
    }
    apk.requestedPermissions = permissionsList.toArray(new String[permissionsList.size()]);
    Uri uri = Uri.fromFile(minMaxApk);
    ApkVerifier apkVerifier = new ApkVerifier(instrumentation.getContext(), uri, apk);
    apkVerifier.verifyApk();
    permissionsList.add("ADDITIONAL_PERMISSION");
    apk.requestedPermissions = permissionsList.toArray(new String[permissionsList.size()]);
    apkVerifier.verifyApk();
}
Also used : ArrayList(java.util.ArrayList) Apk(org.fdroid.fdroid.data.Apk) Uri(android.net.Uri) FileCompatTest(org.fdroid.fdroid.compat.FileCompatTest) Test(org.junit.Test)

Aggregations

Apk (org.fdroid.fdroid.data.Apk)63 Test (org.junit.Test)17 Uri (android.net.Uri)16 File (java.io.File)12 Intent (android.content.Intent)11 App (org.fdroid.fdroid.data.App)10 Repo (org.fdroid.fdroid.data.Repo)10 ArrayList (java.util.ArrayList)8 PendingIntent (android.app.PendingIntent)7 Context (android.content.Context)7 PackageInfo (android.content.pm.PackageInfo)7 FileCompatTest (org.fdroid.fdroid.compat.FileCompatTest)7 BroadcastReceiver (android.content.BroadcastReceiver)6 PackageManager (android.content.pm.PackageManager)5 IOException (java.io.IOException)4 HashSet (java.util.HashSet)4 FDroidProviderTest (org.fdroid.fdroid.data.FDroidProviderTest)4 LocalBroadcastManager (androidx.localbroadcastmanager.content.LocalBroadcastManager)3 RepoDetails (org.fdroid.fdroid.mock.RepoDetails)3 SuppressLint (android.annotation.SuppressLint)2