@@ -416,23 +416,21 @@ private void filterItemsByQuery(@NonNull List<ApplicationItem> applicationItems)
416416 private void filterItemsByFlags () {
417417 synchronized (mApplicationItems ) {
418418 List <ApplicationItem > candidateApplicationItems = new ArrayList <>();
419- List < FilterOption > profileFilterOptions = new ArrayList <>() ;
419+ FilterItem profileFilterItem = null ;
420420 if (mFilterProfileName != null ) {
421421 String profileId = ProfileManager .getProfileIdCompat (mFilterProfileName );
422422 Path profilePath = ProfileManager .findProfilePathById (profileId );
423423 try {
424424 BaseProfile profile = BaseProfile .fromPath (profilePath );
425425 if (profile instanceof AppsProfile ) {
426426 AppsProfile appsProfile = (AppsProfile ) profile ;
427+ profileFilterItem = new FilterItem ();
427428 PackageNameOption option = new PackageNameOption ();
428429 option .setKeyValue ("eq_any" , TextUtils .join ("\n " , appsProfile .packages ));
429- profileFilterOptions . add (option );
430+ profileFilterItem . addFilterOption (option );
430431 } else if (profile instanceof AppsFilterProfile ) {
431432 AppsFilterProfile filterProfile = (AppsFilterProfile ) profile ;
432- FilterItem filterItem = filterProfile .getFilterItem ();
433- for (int i = 0 ; i < filterItem .getSize (); ++i ) {
434- profileFilterOptions .add (filterItem .getFilterOptionAt (i ));
435- }
433+ profileFilterItem = filterProfile .getFilterItem ();
436434 }
437435 } catch (IOException | JSONException e ) {
438436 e .printStackTrace ();
@@ -447,7 +445,7 @@ private void filterItemsByFlags() {
447445 }
448446 }
449447 // Other filters
450- if (profileFilterOptions . isEmpty () && mFilterFlags == MainListOptions .FILTER_NO_FILTER ) {
448+ if (profileFilterItem == null && mFilterFlags == MainListOptions .FILTER_NO_FILTER ) {
451449 if (!TextUtils .isEmpty (mSearchQuery )) {
452450 filterItemsByQuery (candidateApplicationItems );
453451 } else {
@@ -456,11 +454,10 @@ private void filterItemsByFlags() {
456454 } else {
457455 List <ApplicationItem > filteredApplicationItems = new ArrayList <>();
458456 FilterItem filterItem = MainListOptions .getFilterItemFromFlags (mFilterFlags );
459- for (FilterOption filterOption : profileFilterOptions ) {
460- filterItem .addFilterOption (filterOption );
461- }
457+ boolean needUsage = (profileFilterItem != null && profileFilterItem .getTimesUsageInfoUsed () > 0 ) || (filterItem .getTimesUsageInfoUsed () > 0 );
458+ boolean needRunning = (profileFilterItem != null && profileFilterItem .getTimesRunningOptionUsed () > 0 ) || (filterItem .getTimesRunningOptionUsed () > 0 );
462459 Map <String , PackageUsageInfo > packageUsageInfoList = new HashMap <>();
463- if (filterItem . getTimesUsageInfoUsed () > 0 ) {
460+ if (needUsage ) {
464461 boolean hasUsageAccess = FeatureController .isUsageAccessEnabled () && SelfPermissions .checkUsageStatsPermission ();
465462 if (hasUsageAccess ) {
466463 TimeInterval interval = UsageUtils .getLastWeek ();
@@ -490,7 +487,7 @@ private void filterItemsByFlags() {
490487 }
491488 }
492489 HashSet <String > runningPackages = new HashSet <>();
493- if (filterItem . getTimesRunningOptionUsed () > 0 ) {
490+ if (needRunning ) {
494491 for (ActivityManager .RunningAppProcessInfo info : ActivityManagerCompat .getRunningAppProcesses ()) {
495492 if (info .pkgList != null ) {
496493 runningPackages .addAll (Arrays .asList (info .pkgList ));
@@ -501,15 +498,19 @@ private void filterItemsByFlags() {
501498 item .setPackageUsageInfo (packageUsageInfoList .get (item .packageName ));
502499 item .setRunning (runningPackages .contains (item .packageName ));
503500 }
504- List <FilterItem .FilteredItemInfo <ApplicationItem >> result = filterItem .getFilteredList (candidateApplicationItems );
505- for (FilterItem .FilteredItemInfo <ApplicationItem > item : result ) {
506- if ((mFilterFlags & MainListOptions .FILTER_APPS_WITH_SPLITS ) != 0 && !item .info .hasSplits ) {
501+ List <ApplicationItem > result = filterItem .getFilteredAppInfoList (candidateApplicationItems );
502+ if (profileFilterItem != null ) {
503+ // Filter profile
504+ result = profileFilterItem .getFilteredAppInfoList (result );
505+ }
506+ for (ApplicationItem item : result ) {
507+ if ((mFilterFlags & MainListOptions .FILTER_APPS_WITH_SPLITS ) != 0 && !item .hasSplits ) {
507508 continue ;
508509 }
509- if ((mFilterFlags & MainListOptions .FILTER_APPS_WITH_SAF ) != 0 && !item .info . usesSaf ) {
510+ if ((mFilterFlags & MainListOptions .FILTER_APPS_WITH_SAF ) != 0 && !item .usesSaf ) {
510511 continue ;
511512 }
512- filteredApplicationItems .add (item . info );
513+ filteredApplicationItems .add (item );
513514 }
514515 if (!TextUtils .isEmpty (mSearchQuery )) {
515516 filterItemsByQuery (filteredApplicationItems );
0 commit comments