summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Aditya <adityasngh@google.com> 2024-02-13 13:17:42 +0000
committer Aditya <adityasngh@google.com> 2024-02-29 08:26:54 +0000
commite8cc1dbbd0ea696afd06ccf1bf717c9a07c1934a (patch)
tree360329010c2f315771584cd2f15607d81b0dfaa5
parentc069989503f0f95c93624b49b304a3892a990b52 (diff)
Fixing bugs related to pausing of private space.
Added variables to store state of the initial stack and the last selected user in BaseActivity, which is used in DirectoryFragment to reset the stack if the last selected user befor pausing of the private space happened to be private user itself. Bug: 325010006 Bug: 323589103 Bug: 324999992 Test: atest unit test Change-Id: I398f9f4d2ac0bd24f9f457fdff4b5a965cd6f67c
-rw-r--r--src/com/android/documentsui/BaseActivity.java37
-rw-r--r--src/com/android/documentsui/DocumentsApplication.java6
-rw-r--r--src/com/android/documentsui/MultiRootDocumentsLoader.java6
-rw-r--r--src/com/android/documentsui/NavigationViewManager.java3
-rw-r--r--src/com/android/documentsui/ProfileTabs.java9
-rw-r--r--src/com/android/documentsui/dirlist/DirectoryFragment.java12
-rw-r--r--src/com/android/documentsui/files/FilesActivity.java2
-rw-r--r--src/com/android/documentsui/picker/PickActivity.java2
-rw-r--r--src/com/android/documentsui/roots/ProvidersCache.java4
9 files changed, 50 insertions, 31 deletions
diff --git a/src/com/android/documentsui/BaseActivity.java b/src/com/android/documentsui/BaseActivity.java
index 1e9c5fde0..9e38303e1 100644
--- a/src/com/android/documentsui/BaseActivity.java
+++ b/src/com/android/documentsui/BaseActivity.java
@@ -54,6 +54,7 @@ import com.android.documentsui.AbstractActionHandler.CommonAddons;
import com.android.documentsui.Injector.Injected;
import com.android.documentsui.NavigationViewManager.Breadcrumb;
import com.android.documentsui.base.DocumentInfo;
+import com.android.documentsui.base.DocumentStack;
import com.android.documentsui.base.EventHandler;
import com.android.documentsui.base.RootInfo;
import com.android.documentsui.base.Shared;
@@ -87,6 +88,7 @@ public abstract class BaseActivity
extends AppCompatActivity implements CommonAddons, NavigationViewManager.Environment {
private static final String BENCHMARK_TESTING_PACKAGE = "com.android.documentsui.appperftests";
+ private static final String TAG = "BaseActivity";
protected SearchViewManager mSearchManager;
protected AppsRowManager mAppsRowManager;
@@ -118,10 +120,25 @@ public abstract class BaseActivity
private PreferencesMonitor mPreferencesMonitor;
- private boolean mHasProfileBecomeUnavailable = false;
+ private final DocumentStack mInitialStack = new DocumentStack();
+ private UserId mLastSelectedUser = null;
- public void setHasProfileBecomeUnavailable(boolean hasProfileBecomeUnavailable) {
- mHasProfileBecomeUnavailable = hasProfileBecomeUnavailable;
+ protected void setInitialStack(DocumentStack stack) {
+ if (mInitialStack.isInitialized()) {
+ if (DEBUG) {
+ Log.d(TAG, "Initial stack already initialised. " + mInitialStack.isInitialized());
+ }
+ return;
+ }
+ mInitialStack.reset(stack);
+ }
+
+ public DocumentStack getInitialStack() {
+ return mInitialStack;
+ }
+
+ public UserId getLastSelectedUser() {
+ return mLastSelectedUser;
}
public BaseActivity(@LayoutRes int layoutId, String tag) {
@@ -345,9 +362,7 @@ public abstract class BaseActivity
// When a profile with user property SHOW_IN_QUIET_MODE_HIDDEN is currently
// selected, and it becomes unavailable, we reset the roots to recents.
// We do not reset it to recents when pick activity is due to ACTION_CREATE_DOCUMENT
- mInjector.actions.loadCrossProfileRoot(
- (mHasProfileBecomeUnavailable && mState.action != State.ACTION_CREATE)
- ? getRecentsRoot() : getCurrentRoot(), userId);
+ mInjector.actions.loadCrossProfileRoot(getCurrentRoot(), userId);
}
});
@@ -398,6 +413,12 @@ public abstract class BaseActivity
}
@Override
+ protected void onPause() {
+ super.onPause();
+ mLastSelectedUser = getSelectedUser();
+ }
+
+ @Override
public boolean onCreateOptionsMenu(Menu menu) {
boolean showMenu = super.onCreateOptionsMenu(menu);
@@ -902,10 +923,6 @@ public abstract class BaseActivity
}
}
- public RootInfo getRecentsRoot() {
- return mProviders.generateRecentsRoot(getSelectedUser());
- }
-
@Override
public DocumentInfo getCurrentDirectory() {
return mState.stack.peek();
diff --git a/src/com/android/documentsui/DocumentsApplication.java b/src/com/android/documentsui/DocumentsApplication.java
index c5be4149b..84e4754c8 100644
--- a/src/com/android/documentsui/DocumentsApplication.java
+++ b/src/com/android/documentsui/DocumentsApplication.java
@@ -262,13 +262,15 @@ public class DocumentsApplication extends Application {
final String packageName = data.getSchemeSpecificPart();
mProviders.updatePackageAsync(UserId.DEFAULT_USER, packageName);
} else if (PROFILE_FILTER_ACTIONS.contains(action)) {
- // After we have reloaded roots. Resend the broadcast locally so the other
- // components can reload properly after roots are updated.
+ // Make the changes to UserManagerState object before calling providers updateAsync
+ // so that providers for all the users are loaded
if (getConfigStore().isPrivateSpaceInDocsUIEnabled()) {
UserHandle userHandle = intent.getParcelableExtra(Intent.EXTRA_USER);
UserId userId = UserId.of(userHandle);
getUserManagerState(context).onProfileActionStatusChange(action, userId);
}
+ // After we have reloaded roots. Resend the broadcast locally so the other
+ // components can reload properly after roots are updated.
mProviders.updateAsync(/* forceRefreshAll= */ true,
() -> LocalBroadcastManager.getInstance(context).sendBroadcast(intent));
} else {
diff --git a/src/com/android/documentsui/MultiRootDocumentsLoader.java b/src/com/android/documentsui/MultiRootDocumentsLoader.java
index f450814b9..db78daa48 100644
--- a/src/com/android/documentsui/MultiRootDocumentsLoader.java
+++ b/src/com/android/documentsui/MultiRootDocumentsLoader.java
@@ -59,7 +59,7 @@ import java.util.concurrent.Executor;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
-/*
+/**
* The abstract class to query multiple roots from {@link android.provider.DocumentsProvider}
* and return the combined result.
*/
@@ -88,7 +88,7 @@ public abstract class MultiRootDocumentsLoader extends AsyncTaskLoader<Directory
private LockingContentObserver mObserver;
@GuardedBy("mTasks")
- /** A authority -> QueryTask map */
+ /* A authority -> QueryTask map */
private final Map<String, QueryTask> mTasks = new HashMap<>();
private CountDownLatch mFirstPassLatch;
@@ -96,7 +96,7 @@ public abstract class MultiRootDocumentsLoader extends AsyncTaskLoader<Directory
private DirectoryResult mResult;
- /*
+ /**
* Create the loader to query roots from {@link android.provider.DocumentsProvider}.
*
* @param context the context
diff --git a/src/com/android/documentsui/NavigationViewManager.java b/src/com/android/documentsui/NavigationViewManager.java
index 21112ffbb..cd19b650b 100644
--- a/src/com/android/documentsui/NavigationViewManager.java
+++ b/src/com/android/documentsui/NavigationViewManager.java
@@ -71,7 +71,8 @@ public class NavigationViewManager implements AppBarLayout.OnOffsetChangedListen
private final ConfigStore mConfigStore;
private boolean mIsActionModeActivated = false;
- private @ColorRes int mDefaultStatusBarColorResId;
+ @ColorRes
+ private int mDefaultStatusBarColorResId;
public NavigationViewManager(
BaseActivity activity,
diff --git a/src/com/android/documentsui/ProfileTabs.java b/src/com/android/documentsui/ProfileTabs.java
index d096d59db..b692c7ada 100644
--- a/src/com/android/documentsui/ProfileTabs.java
+++ b/src/com/android/documentsui/ProfileTabs.java
@@ -128,13 +128,8 @@ public class ProfileTabs implements ProfileTabsAddons {
// Update the layout according to the current root if necessary.
// Make sure we do not invoke callback. Otherwise, it is likely to cause infinite loop.
mTabs.removeOnTabSelectedListener(mOnTabSelectedListener);
- if (!mUserIds.contains(currentRoot.userId)) {
- mTabs.addOnTabSelectedListener(mOnTabSelectedListener);
- mTabs.selectTab(mTabs.getTabAt(mUserIds.indexOf(UserId.CURRENT_USER)));
- } else {
- mTabs.selectTab(mTabs.getTabAt(mUserIds.indexOf(currentRoot.userId)));
- mTabs.addOnTabSelectedListener(mOnTabSelectedListener);
- }
+ mTabs.selectTab(mTabs.getTabAt(mUserIds.indexOf(currentRoot.userId)));
+ mTabs.addOnTabSelectedListener(mOnTabSelectedListener);
}
mTabsContainer.setVisibility(shouldShow() ? View.VISIBLE : View.GONE);
diff --git a/src/com/android/documentsui/dirlist/DirectoryFragment.java b/src/com/android/documentsui/dirlist/DirectoryFragment.java
index 32f3683e3..bf54e25fd 100644
--- a/src/com/android/documentsui/dirlist/DirectoryFragment.java
+++ b/src/com/android/documentsui/dirlist/DirectoryFragment.java
@@ -246,7 +246,6 @@ public class DirectoryFragment extends Fragment implements SwipeRefreshLayout.On
} else {
profileStatusReceiverPreV(intent, action);
}
-
}
private void profileStatusReceiverPostV(Intent intent, String action) {
@@ -310,16 +309,17 @@ public class DirectoryFragment extends Fragment implements SwipeRefreshLayout.On
private void onHiddenProfileStatusChange(String action, UserId userId) {
if (Intent.ACTION_PROFILE_UNAVAILABLE.equals(action)) {
- mActivity.setHasProfileBecomeUnavailable(true);
if (mProviderTestRunnable != null) {
mHandler.removeCallbacks(mProviderTestRunnable);
mProviderTestRunnable = null;
}
- while (mState.stack.size() > 0) {
- mState.stack.pop();
+ if (!mActivity.isSearchExpanded()) {
+ if (mActivity.getLastSelectedUser() != null
+ && mActivity.getLastSelectedUser().equals(userId)) {
+ mState.stack.reset(mActivity.getInitialStack());
+ }
+ mActivity.refreshCurrentRootAndDirectory(AnimationView.ANIM_NONE);
}
- mActivity.updateNavigator();
- mActivity.setHasProfileBecomeUnavailable(false);
} else {
checkUriAndScheduleCheckIfNeeded(userId);
}
diff --git a/src/com/android/documentsui/files/FilesActivity.java b/src/com/android/documentsui/files/FilesActivity.java
index 709938174..7a53e5361 100644
--- a/src/com/android/documentsui/files/FilesActivity.java
+++ b/src/com/android/documentsui/files/FilesActivity.java
@@ -352,6 +352,8 @@ public class FilesActivity extends BaseActivity implements AbstractActionHandler
final RootInfo root = getCurrentRoot();
final DocumentInfo cwd = getCurrentDirectory();
+ setInitialStack(mState.stack);
+
assert (!mSearchManager.isSearching());
if (mState.stack.isRecents()) {
diff --git a/src/com/android/documentsui/picker/PickActivity.java b/src/com/android/documentsui/picker/PickActivity.java
index 8ba48dbdd..c14c8b8a9 100644
--- a/src/com/android/documentsui/picker/PickActivity.java
+++ b/src/com/android/documentsui/picker/PickActivity.java
@@ -358,6 +358,8 @@ public class PickActivity extends BaseActivity implements ActionHandler.Addons {
final RootInfo root = getCurrentRoot();
final DocumentInfo cwd = getCurrentDirectory();
+ setInitialStack(mState.stack);
+
if (mState.stack.isRecents()) {
DirectoryFragment.showRecentsOpen(fm, anim);
diff --git a/src/com/android/documentsui/roots/ProvidersCache.java b/src/com/android/documentsui/roots/ProvidersCache.java
index 675058451..15089a6a5 100644
--- a/src/com/android/documentsui/roots/ProvidersCache.java
+++ b/src/com/android/documentsui/roots/ProvidersCache.java
@@ -127,7 +127,7 @@ public class ProvidersCache implements ProvidersAccess, LookupApplicationName {
/**
* Generates recent root for the provided user id
*/
- public RootInfo generateRecentsRoot(UserId rootUserId) {
+ private RootInfo generateRecentsRoot(UserId rootUserId) {
return new RootInfo() {{
// Special root for recents
userId = rootUserId;
@@ -537,7 +537,7 @@ public class ProvidersCache implements ProvidersAccess, LookupApplicationName {
final long start = SystemClock.elapsedRealtime();
- List<UserId> userIds = getUserIds();
+ List<UserId> userIds = new ArrayList<>(getUserIds());
for (UserId userId : userIds) {
final RootInfo recents = createOrGetRecentsRoot(userId);
synchronized (mLock) {