Search in sources :

Example 11 with LocalBroadcastManager

use of androidx.localbroadcastmanager.content.LocalBroadcastManager in project fdroidclient by f-droid.

the class AppListItemController method bindModel.

public void bindModel(@NonNull App app) {
    currentApp = app;
    if (actionButton != null)
        actionButton.setEnabled(true);
    Utils.setIconFromRepoOrPM(app, icon, activity);
    // Figures out the current install/update/download/etc status for the app we are viewing.
    // Then, asks the view to update itself to reflect this status.
    Iterator<AppUpdateStatus> statuses = AppUpdateStatusManager.getInstance(activity).getByPackageName(app.packageName).iterator();
    if (statuses.hasNext()) {
        AppUpdateStatus status = statuses.next();
        updateAppStatus(app, status);
    } else {
        updateAppStatus(app, null);
    }
    final LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(activity.getApplicationContext());
    broadcastManager.unregisterReceiver(onStatusChanged);
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(AppUpdateStatusManager.BROADCAST_APPSTATUS_ADDED);
    intentFilter.addAction(AppUpdateStatusManager.BROADCAST_APPSTATUS_REMOVED);
    intentFilter.addAction(AppUpdateStatusManager.BROADCAST_APPSTATUS_CHANGED);
    broadcastManager.registerReceiver(onStatusChanged, intentFilter);
}
Also used : IntentFilter(android.content.IntentFilter) AppUpdateStatus(org.fdroid.fdroid.AppUpdateStatusManager.AppUpdateStatus) LocalBroadcastManager(androidx.localbroadcastmanager.content.LocalBroadcastManager)

Example 12 with LocalBroadcastManager

use of androidx.localbroadcastmanager.content.LocalBroadcastManager 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 13 with LocalBroadcastManager

use of androidx.localbroadcastmanager.content.LocalBroadcastManager 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 14 with LocalBroadcastManager

use of androidx.localbroadcastmanager.content.LocalBroadcastManager in project android_packages_apps_Settings by omnirom.

the class SurveyMixinTest method onPause_removesReceiverIfPreviouslySet.

@Test
public void onPause_removesReceiverIfPreviouslySet() {
    // Pretend there is a survey in memory
    when(mProvider.getSurveyExpirationDate(any(), any())).thenReturn(-1L);
    // Pretend we are an activity that starts and stops
    FragmentActivity temp = Robolectric.setupActivity(FragmentActivity.class);
    when(mFragment.getActivity()).thenReturn(temp);
    when(mProvider.createAndRegisterReceiver(any())).thenReturn(mReceiver);
    LocalBroadcastManager manager = LocalBroadcastManager.getInstance(temp);
    SurveyMixin mixin = new SurveyMixin(mFragment, FAKE_KEY);
    mixin.onResume();
    manager.registerReceiver(mReceiver, new IntentFilter());
    mixin.onPause();
    // Verify we remove the receiver
    HashMap<BroadcastReceiver, ArrayList<IntentFilter>> map = ReflectionHelpers.getField(manager, "mReceivers");
    assertThat(map.containsKey(mReceiver)).isFalse();
}
Also used : FragmentActivity(androidx.fragment.app.FragmentActivity) IntentFilter(android.content.IntentFilter) ArrayList(java.util.ArrayList) BroadcastReceiver(android.content.BroadcastReceiver) LocalBroadcastManager(androidx.localbroadcastmanager.content.LocalBroadcastManager) Test(org.junit.Test)

Example 15 with LocalBroadcastManager

use of androidx.localbroadcastmanager.content.LocalBroadcastManager in project Gadgetbridge by Freeyourgadget.

the class WatchXPlusDeviceSupport method dispose.

@Override
public void dispose() {
    LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(getContext());
    broadcastManager.unregisterReceiver(broadcastReceiver);
    super.dispose();
}
Also used : LocalBroadcastManager(androidx.localbroadcastmanager.content.LocalBroadcastManager)

Aggregations

LocalBroadcastManager (androidx.localbroadcastmanager.content.LocalBroadcastManager)30 IntentFilter (android.content.IntentFilter)15 BroadcastReceiver (android.content.BroadcastReceiver)9 Intent (android.content.Intent)8 Context (android.content.Context)7 ArrayList (java.util.ArrayList)4 Bundle (android.os.Bundle)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 Apk (org.fdroid.fdroid.data.Apk)3 Uri (android.net.Uri)2 FragmentActivity (androidx.fragment.app.FragmentActivity)2 Test (org.junit.Test)2 SuppressLint (android.annotation.SuppressLint)1 PendingIntent (android.app.PendingIntent)1 BluetoothDevice (android.bluetooth.BluetoothDevice)1 Handler (android.os.Handler)1 HandlerThread (android.os.HandlerThread)1 Message (android.os.Message)1 ScrollView (android.widget.ScrollView)1 FirebaseCrashlytics (com.google.firebase.crashlytics.FirebaseCrashlytics)1