@@ -168,12 +168,16 @@ private void initializeData() {
168168 Set <String > currentScopePackages = scopePackages != null
169169 ? new LinkedHashSet <>(scopePackages )
170170 : new LinkedHashSet <>();
171+ Set <String > installedScopePackages = ScopeManager .filterInstalledScopePackages (
172+ this ,
173+ currentScopePackages
174+ );
171175
172176 List <AppData > loadedData = mAppDataManager .getAppInfo (MODE_SCOPE );
173177 loadedData = prepareScopeModeData (new ArrayList <>(loadedData ));
174178 Set <String > availableScopePackages = collectScopePackages (loadedData );
175179 Set <String > sanitizedScopePackages = ScopeManager .filterScopePackages (
176- currentScopePackages ,
180+ installedScopePackages ,
177181 availableScopePackages
178182 );
179183
@@ -182,7 +186,7 @@ private void initializeData() {
182186 mAvailableScopePackages .clear ();
183187 mAvailableScopePackages .addAll (availableScopePackages );
184188
185- cleanupUnavailableScopePackages (currentScopePackages , sanitizedScopePackages );
189+ cleanupUnavailableScopePackages (currentScopePackages , installedScopePackages );
186190
187191 List <AppData > processedData = processAppData (new ArrayList <>(loadedData ));
188192 mHandler .post (() -> displayAppData (processedData ));
@@ -301,12 +305,21 @@ private Set<String> collectScopePackages(List<AppData> data) {
301305 return packages ;
302306 }
303307
304- private void cleanupUnavailableScopePackages (Set <String > currentScopePackages , Set <String > sanitizedScopePackages ) {
305- if (currentScopePackages == null || currentScopePackages .equals (sanitizedScopePackages )) {
308+ private void cleanupUnavailableScopePackages (Set <String > currentScopePackages , Set <String > installedScopePackages ) {
309+ if (currentScopePackages == null ) {
310+ return ;
311+ }
312+
313+ Set <String > cleanupSource = new LinkedHashSet <>(currentScopePackages );
314+ Set <String > cleanupTarget = new LinkedHashSet <>(installedScopePackages );
315+ cleanupSource .remove (SYSTEM_SCOPE_PACKAGE );
316+ cleanupTarget .remove (SYSTEM_SCOPE_PACKAGE );
317+
318+ if (cleanupSource .equals (cleanupTarget )) {
306319 return ;
307320 }
308321
309- ScopeManager .applyScopeDiffAsync (this , currentScopePackages , sanitizedScopePackages , (success , message ) -> {
322+ ScopeManager .applyScopeDiffAsync (this , cleanupSource , cleanupTarget , (success , message ) -> {
310323 if (success ) {
311324 AndroidLog .i (TAG , "cleanupUnavailableScopePackages: removed uninstalled scope entries" );
312325 return ;
@@ -366,7 +379,7 @@ private void applyScopeSelection() {
366379 currentSelected = new LinkedHashSet <>(mCurrentScopePackages );
367380 }
368381
369- Set <String > targetSelected = ScopeManager .filterScopePackages ( currentSelected , mAvailableScopePackages );
382+ Set <String > targetSelected = ScopeManager .filterInstalledScopePackages ( this , currentSelected );
370383 targetSelected .removeAll (mSelectableScopePackages );
371384 targetSelected .addAll (ScopeManager .normalizeScopePackages (mAppListAdapter .getSelectedPackages ()));
372385
0 commit comments