use of androidx.preference.CheckBoxPreference 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);
}
use of androidx.preference.CheckBoxPreference 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;
}
use of androidx.preference.CheckBoxPreference in project android_packages_apps_Settings by omnirom.
the class RestrictedAppDetails method refreshUi.
@VisibleForTesting
void refreshUi() {
mRestrictedAppListGroup.removeAll();
final Context context = getPrefContext();
final SparseLongArray timestampArray = mBatteryDatabaseManager.queryActionTime(AnomalyDatabaseHelper.ActionType.RESTRICTION);
final long now = System.currentTimeMillis();
for (int i = 0, size = mAppInfos.size(); i < size; i++) {
final CheckBoxPreference checkBoxPreference = new AppCheckBoxPreference(context);
final AppInfo appInfo = mAppInfos.get(i);
try {
final ApplicationInfo applicationInfo = mPackageManager.getApplicationInfoAsUser(appInfo.packageName, 0, /* flags */
UserHandle.getUserId(appInfo.uid));
checkBoxPreference.setChecked(mBatteryUtils.isForceAppStandbyEnabled(appInfo.uid, appInfo.packageName));
checkBoxPreference.setTitle(mPackageManager.getApplicationLabel(applicationInfo));
checkBoxPreference.setIcon(Utils.getBadgedIcon(mIconDrawableFactory, mPackageManager, appInfo.packageName, UserHandle.getUserId(appInfo.uid)));
checkBoxPreference.setKey(getKeyFromAppInfo(appInfo));
checkBoxPreference.setOnPreferenceChangeListener((pref, value) -> {
final BatteryTipDialogFragment fragment = createDialogFragment(appInfo, (Boolean) value);
fragment.setTargetFragment(this, 0);
fragment.show(getFragmentManager(), TAG);
mMetricsFeatureProvider.action(getContext(), SettingsEnums.ACTION_APP_RESTRICTED_LIST_UNCHECKED, appInfo.packageName);
return false;
});
final long timestamp = timestampArray.get(appInfo.uid, TIME_NULL);
if (timestamp != TIME_NULL) {
checkBoxPreference.setSummary(getString(R.string.restricted_app_time_summary, StringUtil.formatRelativeTime(context, now - timestamp, false)));
}
final CharSequence test = checkBoxPreference.getSummaryOn();
mRestrictedAppListGroup.addPreference(checkBoxPreference);
} catch (PackageManager.NameNotFoundException e) {
Log.e(TAG, "Can't find package: " + appInfo.packageName);
}
}
}
use of androidx.preference.CheckBoxPreference 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));
}
use of androidx.preference.CheckBoxPreference in project android_packages_apps_Settings by omnirom.
the class BridgedAppsPreferenceControllerTest method onRebuildComplete_buildsSetting.
@Test
public void onRebuildComplete_buildsSetting() {
when(mNm.isNotificationListenerAccessGranted(mCn)).thenReturn(true);
when(mNm.getListenerFilter(mCn, 0)).thenReturn(new NotificationListenerFilter());
ArrayList<ApplicationsState.AppEntry> entries = new ArrayList<>();
entries.add(mAppEntry);
mController.onRebuildComplete(entries);
CheckBoxPreference actual = mScreen.findPreference("pkg|12300");
assertThat(actual.isChecked()).isTrue();
assertThat(actual.getTitle()).isEqualTo("hi");
assertThat(actual.getIcon()).isEqualTo(mAppEntry.icon);
}
Aggregations