From 2379385a09f5ef590681c51caa7ab4cced01cf87 Mon Sep 17 00:00:00 2001 From: Mill Chen Date: Wed, 4 May 2022 18:36:03 +0800 Subject: [PATCH] Add new methods to activate/deactivate session Currently the way that identifies an active session of ApplicationsState is checking a variable. However the variable is binding with a task that loads all apps. There is no appropriate way if a class that implements Callbacks just needs to receive the callback without loading all apps. The current methods might trigger the task that loads all apps several times if we would like to activate a session. This CL is to add seperate ways that enable/disable a class that implements Callbacks to receive the callback call. Bug: 222985623 Test: manual test Change-Id: I46c7143ddf220cbe7c50ee124aabe63f75be03ee --- .../applications/ApplicationsState.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/packages/SettingsLib/src/com/android/settingslib/applications/ApplicationsState.java b/packages/SettingsLib/src/com/android/settingslib/applications/ApplicationsState.java index fdb06072bbd10..6b9daa35f9ca7 100644 --- a/packages/SettingsLib/src/com/android/settingslib/applications/ApplicationsState.java +++ b/packages/SettingsLib/src/com/android/settingslib/applications/ApplicationsState.java @@ -863,6 +863,30 @@ public class ApplicationsState { } } + /** + * Activate session to enable a class that implements Callbacks to receive the callback. + */ + public void activateSession() { + synchronized (mEntriesMap) { + if (!mResumed) { + mResumed = true; + mSessionsChanged = true; + } + } + } + + /** + * Deactivate session to disable a class that implements Callbacks to get the callback. + */ + public void deactivateSession() { + synchronized (mEntriesMap) { + if (mResumed) { + mResumed = false; + mSessionsChanged = true; + } + } + } + public ArrayList getAllApps() { synchronized (mEntriesMap) { return new ArrayList<>(mAppEntries);