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
This commit is contained in:
Mill Chen
2022-05-04 18:36:03 +08:00
parent 301ff2fec1
commit 2379385a09

View File

@@ -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<AppEntry> getAllApps() {
synchronized (mEntriesMap) {
return new ArrayList<>(mAppEntries);