Search in sources :

Example 1 with VersionedPackage

use of android.content.pm.VersionedPackage in project robolectric by robolectric.

the class RollbackInfoBuilderTest method build.

@Test
public void build() {
    VersionedPackage packageRolledBackFrom = new VersionedPackage("test_package", 123);
    VersionedPackage packageRolledBackTo = new VersionedPackage("test_package", 345);
    PackageRollbackInfo packageRollbackInfo = PackageRollbackInfoBuilder.newBuilder().setPackageRolledBackFrom(packageRolledBackFrom).setPackageRolledBackTo(packageRolledBackTo).build();
    RollbackInfo rollbackInfo = RollbackInfoBuilder.newBuilder().setRollbackId(1).setPackages(ImmutableList.of(packageRollbackInfo)).setIsStaged(true).setCausePackages(ImmutableList.of(packageRolledBackFrom)).setCommittedSessionId(10).build();
    assertThat(rollbackInfo).isNotNull();
    assertThat(rollbackInfo.getRollbackId()).isEqualTo(1);
    assertThat(rollbackInfo.getPackages()).containsExactly(packageRollbackInfo);
    assertThat(rollbackInfo.isStaged()).isTrue();
    assertThat(rollbackInfo.getCausePackages()).containsExactly(packageRolledBackFrom);
    assertThat(rollbackInfo.getCommittedSessionId()).isEqualTo(10);
}
Also used : RollbackInfo(android.content.rollback.RollbackInfo) PackageRollbackInfo(android.content.rollback.PackageRollbackInfo) VersionedPackage(android.content.pm.VersionedPackage) PackageRollbackInfo(android.content.rollback.PackageRollbackInfo) Test(org.junit.Test)

Example 2 with VersionedPackage

use of android.content.pm.VersionedPackage in project android_packages_apps_Settings by omnirom.

the class BridgedAppsPreferenceController method onRebuildComplete.

@Override
public void onRebuildComplete(ArrayList<AppEntry> apps) {
    if (apps == null) {
        return;
    }
    mNlf = mNm.getListenerFilter(mCn, mUserId);
    // Create apps key set for removing useless preferences
    final Set<String> appsKeySet = new TreeSet<>();
    // Add or update preferences
    final int N = apps.size();
    for (int i = 0; i < N; i++) {
        final AppEntry entry = apps.get(i);
        final String prefKey = entry.info.packageName + "|" + entry.info.uid;
        appsKeySet.add(prefKey);
        CheckBoxPreference preference = mScreen.findPreference(prefKey);
        if (preference == null) {
            preference = new CheckBoxPreference(mScreen.getContext());
            preference.setIcon(entry.icon);
            preference.setTitle(entry.label);
            preference.setKey(prefKey);
            mScreen.addPreference(preference);
        }
        preference.setOrder(i);
        preference.setChecked(mNlf.isPackageAllowed(new VersionedPackage(entry.info.packageName, entry.info.uid)));
        preference.setOnPreferenceChangeListener(this::onPreferenceChange);
    }
    // Remove preferences that are no longer existing in the updated list of apps
    removeUselessPrefs(appsKeySet);
}
Also used : AppEntry(com.android.settingslib.applications.ApplicationsState.AppEntry) CheckBoxPreference(androidx.preference.CheckBoxPreference) TreeSet(java.util.TreeSet) VersionedPackage(android.content.pm.VersionedPackage)

Example 3 with VersionedPackage

use of android.content.pm.VersionedPackage in project android_packages_apps_Settings by omnirom.

the class BridgedAppsPreferenceController method onPreferenceChange.

public boolean onPreferenceChange(Preference preference, Object newValue) {
    if (preference instanceof CheckBoxPreference) {
        String packageName = preference.getKey().substring(0, preference.getKey().indexOf("|"));
        int uid = Integer.parseInt(preference.getKey().substring(preference.getKey().indexOf("|") + 1));
        boolean allowlisted = newValue == Boolean.TRUE;
        mNlf = mNm.getListenerFilter(mCn, mUserId);
        if (allowlisted) {
            mNlf.removePackage(new VersionedPackage(packageName, uid));
        } else {
            mNlf.addPackage(new VersionedPackage(packageName, uid));
        }
        mNm.setListenerFilter(mCn, mUserId, mNlf);
        return true;
    }
    return false;
}
Also used : CheckBoxPreference(androidx.preference.CheckBoxPreference) VersionedPackage(android.content.pm.VersionedPackage)

Example 4 with VersionedPackage

use of android.content.pm.VersionedPackage in project android_packages_apps_Settings by omnirom.

the class BridgedAppsPreferenceControllerTest method onPreferenceChange_false.

@Test
public void onPreferenceChange_false() {
    VersionedPackage vp = new VersionedPackage("pkg", 10567);
    ArraySet<VersionedPackage> vps = new ArraySet<>();
    vps.add(vp);
    NotificationListenerFilter nlf = new NotificationListenerFilter(FLAG_FILTER_TYPE_ONGOING | FLAG_FILTER_TYPE_CONVERSATIONS, vps);
    when(mNm.isNotificationListenerAccessGranted(mCn)).thenReturn(true);
    when(mNm.getListenerFilter(mCn, 0)).thenReturn(nlf);
    CheckBoxPreference pref = new CheckBoxPreference(mContext);
    pref.setKey("pkg|567");
    mController.onPreferenceChange(pref, false);
    ArgumentCaptor<NotificationListenerFilter> captor = ArgumentCaptor.forClass(NotificationListenerFilter.class);
    verify(mNm).setListenerFilter(eq(mCn), eq(0), captor.capture());
    assertThat(captor.getValue().getDisallowedPackages()).contains(new VersionedPackage("pkg", 567));
    assertThat(captor.getValue().getDisallowedPackages()).contains(new VersionedPackage("pkg", 10567));
}
Also used : ArraySet(android.util.ArraySet) CheckBoxPreference(androidx.preference.CheckBoxPreference) VersionedPackage(android.content.pm.VersionedPackage) NotificationListenerFilter(android.service.notification.NotificationListenerFilter) Test(org.junit.Test)

Example 5 with VersionedPackage

use of android.content.pm.VersionedPackage in project android_packages_apps_Settings by omnirom.

the class BridgedAppsPreferenceControllerTest method onPreferenceChange_true.

@Test
public void onPreferenceChange_true() {
    VersionedPackage vp = new VersionedPackage("pkg", 567);
    VersionedPackage vp2 = new VersionedPackage("pkg", 10567);
    ArraySet<VersionedPackage> vps = new ArraySet<>();
    vps.add(vp);
    vps.add(vp2);
    NotificationListenerFilter nlf = new NotificationListenerFilter(FLAG_FILTER_TYPE_ONGOING | FLAG_FILTER_TYPE_CONVERSATIONS, vps);
    when(mNm.isNotificationListenerAccessGranted(mCn)).thenReturn(true);
    when(mNm.getListenerFilter(mCn, 0)).thenReturn(nlf);
    CheckBoxPreference pref = new CheckBoxPreference(mContext);
    pref.setKey("pkg|567");
    mController.onPreferenceChange(pref, true);
    ArgumentCaptor<NotificationListenerFilter> captor = ArgumentCaptor.forClass(NotificationListenerFilter.class);
    verify(mNm).setListenerFilter(eq(mCn), eq(0), captor.capture());
    assertThat(captor.getValue().getDisallowedPackages().size()).isEqualTo(1);
    assertThat(captor.getValue().getDisallowedPackages()).contains(new VersionedPackage("pkg", 10567));
}
Also used : ArraySet(android.util.ArraySet) CheckBoxPreference(androidx.preference.CheckBoxPreference) VersionedPackage(android.content.pm.VersionedPackage) NotificationListenerFilter(android.service.notification.NotificationListenerFilter) Test(org.junit.Test)

Aggregations

VersionedPackage (android.content.pm.VersionedPackage)5 CheckBoxPreference (androidx.preference.CheckBoxPreference)4 Test (org.junit.Test)3 NotificationListenerFilter (android.service.notification.NotificationListenerFilter)2 ArraySet (android.util.ArraySet)2 PackageRollbackInfo (android.content.rollback.PackageRollbackInfo)1 RollbackInfo (android.content.rollback.RollbackInfo)1 AppEntry (com.android.settingslib.applications.ApplicationsState.AppEntry)1 TreeSet (java.util.TreeSet)1