Merge changes Ic768f57f,I6f1396ca into udc-mainline-prod

* changes:
  Fix for loss of `Recents` content from private tab on flag change.
  Fixing profile badge themes for various grid and list holders.
diff --git a/res/layout-sw720dp/item_doc_list.xml b/res/layout-sw720dp/item_doc_list.xml
index 4b2b371..3013f31 100644
--- a/res/layout-sw720dp/item_doc_list.xml
+++ b/res/layout-sw720dp/item_doc_list.xml
@@ -101,6 +101,7 @@
                     android:layout_marginEnd="@dimen/briefcase_icon_margin"
                     android:layout_gravity="center_vertical"
                     android:src="@drawable/ic_briefcase"
+                    android:tint="?android:attr/colorAccent"
                     android:contentDescription="@string/a11y_work"/>
 
                 <TextView
diff --git a/res/layout/item_dir_grid.xml b/res/layout/item_dir_grid.xml
index 423aba0..bd690d4 100644
--- a/res/layout/item_dir_grid.xml
+++ b/res/layout/item_dir_grid.xml
@@ -86,6 +86,7 @@
                 android:layout_width="@dimen/briefcase_icon_size"
                 android:layout_marginEnd="@dimen/briefcase_icon_margin"
                 android:src="@drawable/ic_briefcase"
+                android:tint="?android:attr/colorAccent"
                 android:contentDescription="@string/a11y_work"/>
 
             <TextView
diff --git a/res/layout/item_doc_grid.xml b/res/layout/item_doc_grid.xml
index d0b0ee3..d654571 100644
--- a/res/layout/item_doc_grid.xml
+++ b/res/layout/item_doc_grid.xml
@@ -154,6 +154,7 @@
                         android:layout_alignBottom="@android:id/title"
                         android:gravity="center_vertical"
                         android:src="@drawable/ic_briefcase"
+                        android:tint="?android:attr/colorAccent"
                         android:contentDescription="@string/a11y_work"/>
 
                     <TextView
diff --git a/res/layout/item_doc_list.xml b/res/layout/item_doc_list.xml
index 026c6ef..77494a2 100644
--- a/res/layout/item_doc_list.xml
+++ b/res/layout/item_doc_list.xml
@@ -98,6 +98,7 @@
               android:layout_marginEnd="@dimen/briefcase_icon_margin"
               android:layout_gravity="center_vertical"
               android:src="@drawable/ic_briefcase"
+              android:tint="?android:attr/colorAccent"
               android:contentDescription="@string/a11y_work" />
 
           <TextView
diff --git a/res/layout/item_photo_grid.xml b/res/layout/item_photo_grid.xml
index cb2c40c..4581d3d 100644
--- a/res/layout/item_photo_grid.xml
+++ b/res/layout/item_photo_grid.xml
@@ -116,6 +116,7 @@
                 android:layout_height="@dimen/briefcase_icon_size_photo"
                 android:layout_width="@dimen/briefcase_icon_size_photo"
                 android:src="@drawable/ic_briefcase_white"
+                android:tint="?android:attr/colorAccent"
                 android:padding="5dp"
                 android:background="@drawable/circle_button_background"
                 android:layout_gravity="center"
diff --git a/src/com/android/documentsui/DocumentsApplication.java b/src/com/android/documentsui/DocumentsApplication.java
index db7b3f9..92aa3f7 100644
--- a/src/com/android/documentsui/DocumentsApplication.java
+++ b/src/com/android/documentsui/DocumentsApplication.java
@@ -28,6 +28,7 @@
 import android.content.om.OverlayManager;
 import android.net.Uri;
 import android.os.RemoteException;
+import android.os.UserHandle;
 import android.text.format.DateUtils;
 import android.util.Log;
 
@@ -47,7 +48,6 @@
 import com.google.common.collect.Lists;
 
 import java.util.List;
-import java.util.Objects;
 
 import javax.annotation.concurrent.GuardedBy;
 
@@ -83,7 +83,20 @@
     private Lookup<String, String> mFileTypeLookup;
 
     public static ProvidersCache getProvidersCache(Context context) {
-        return ((DocumentsApplication) context.getApplicationContext()).mProviders;
+        ProvidersCache providers =
+                ((DocumentsApplication) context.getApplicationContext()).mProviders;
+        final ConfigStore configStore = getConfigStore(context);
+        // When private space in DocsUI is enabled then ProvidersCache should use UserManagerState
+        // else it should use UserIdManager. The following if-check will ensure the construction of
+        // a new ProvidersCache instance whenever there is a mismatch in this.
+        if (configStore.isPrivateSpaceInDocsUIEnabled()
+                != providers.isProvidersCacheUsingUserManagerState()) {
+            providers = configStore.isPrivateSpaceInDocsUIEnabled()
+                    ? new ProvidersCache(context, getUserManagerState(context), configStore)
+                    : new ProvidersCache(context, getUserIdManager(context), configStore);
+            ((DocumentsApplication) context.getApplicationContext()).mProviders = providers;
+        }
+        return providers;
     }
 
     public static ThumbnailCache getThumbnailCache(Context context) {
@@ -111,7 +124,13 @@
     }
 
     public static UserIdManager getUserIdManager(Context context) {
-        return ((DocumentsApplication) context.getApplicationContext()).mUserIdManager;
+        UserIdManager userIdManager =
+                ((DocumentsApplication) context.getApplicationContext()).mUserIdManager;
+        if (userIdManager == null) {
+            userIdManager = UserIdManager.create(context);
+            ((DocumentsApplication) context.getApplicationContext()).mUserIdManager = userIdManager;
+        }
+        return userIdManager;
     }
 
     /**
@@ -119,9 +138,14 @@
      * cross profile access, label and badge associated with these userIds.
      */
     public static UserManagerState getUserManagerState(Context context) {
-        return Objects.requireNonNullElseGet(
-                ((DocumentsApplication) context.getApplicationContext()).mUserManagerState,
-                () -> UserManagerState.create(context));
+        UserManagerState userManagerState =
+                ((DocumentsApplication) context.getApplicationContext()).mUserManagerState;
+        if (userManagerState == null && getConfigStore(context).isPrivateSpaceInDocsUIEnabled()) {
+            userManagerState = UserManagerState.create(context);
+            ((DocumentsApplication) context.getApplicationContext()).mUserManagerState =
+                    userManagerState;
+        }
+        return userManagerState;
     }
 
     public static DragAndDropManager getDragAndDropManager(Context context) {
@@ -133,14 +157,6 @@
     }
 
     /**
-     * Set {@link #mUserManagerState} as null onDestroy of BaseActivity so that new session uses new
-     * instance of {@link #mUserManagerState}
-     */
-    public static void invalidateUserManagerState(Context context) {
-        ((DocumentsApplication) context.getApplicationContext()).mUserManagerState = null;
-    }
-
-    /**
      * Retrieve {@link ConfigStore} instance to access feature flags in production code.
      */
     public static synchronized ConfigStore getConfigStore(Context context) {
@@ -151,6 +167,22 @@
     }
 
     /**
+     * Set {@link #mProviders} as null onDestroy of BaseActivity so that new session uses new
+     * instance of {@link #mProviders}
+     */
+    public static void invalidateProvidersCache(Context context) {
+        ((DocumentsApplication) context.getApplicationContext()).mProviders = null;
+    }
+
+    /**
+     * Set {@link #mUserManagerState} as null onDestroy of BaseActivity so that new session uses new
+     * instance of {@link #mUserManagerState}
+     */
+    public static void invalidateUserManagerState(Context context) {
+        ((DocumentsApplication) context.getApplicationContext()).mUserManagerState = null;
+    }
+
+    /**
      * Set {@link #sConfigStore} as null onDestroy of BaseActivity so that new session uses new
      * instance of {@link #sConfigStore}
      */
@@ -189,13 +221,13 @@
             mUserManagerState = UserManagerState.create(this);
             mUserIdManager = null;
             synchronized (DocumentsApplication.class) {
-                mProviders = new ProvidersCache(this, mUserManagerState, sConfigStore);
+                mProviders = new ProvidersCache(this, mUserManagerState, getConfigStore(this));
             }
         } else {
             mUserManagerState = null;
             mUserIdManager = UserIdManager.create(this);
             synchronized (DocumentsApplication.class) {
-                mProviders = new ProvidersCache(this, mUserIdManager, sConfigStore);
+                mProviders = new ProvidersCache(this, mUserIdManager, getConfigStore(this));
             }
         }
 
@@ -258,6 +290,11 @@
             } 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.
+                if (getConfigStore(context).isPrivateSpaceInDocsUIEnabled()) {
+                    UserHandle userHandle = intent.getParcelableExtra(Intent.EXTRA_USER);
+                    UserId userId = UserId.of(userHandle);
+                    getUserManagerState(context).onProfileActionStatusChange(action, userId);
+                }
                 mProviders.updateAsync(/* forceRefreshAll= */ true,
                         () -> LocalBroadcastManager.getInstance(context).sendBroadcast(intent));
             } else {
diff --git a/src/com/android/documentsui/dirlist/DirectoryFragment.java b/src/com/android/documentsui/dirlist/DirectoryFragment.java
index 3d47a32..32f3683 100644
--- a/src/com/android/documentsui/dirlist/DirectoryFragment.java
+++ b/src/com/android/documentsui/dirlist/DirectoryFragment.java
@@ -91,7 +91,6 @@
 import com.android.documentsui.R;
 import com.android.documentsui.ThumbnailCache;
 import com.android.documentsui.TimeoutTask;
-import com.android.documentsui.UserManagerState;
 import com.android.documentsui.base.DocumentFilters;
 import com.android.documentsui.base.DocumentInfo;
 import com.android.documentsui.base.DocumentStack;
@@ -310,8 +309,6 @@
     }
 
     private void onHiddenProfileStatusChange(String action, UserId userId) {
-        UserManagerState userManagerState = DocumentsApplication.getUserManagerState(mActivity);
-        userManagerState.onProfileActionStatusChange(action, userId);
         if (Intent.ACTION_PROFILE_UNAVAILABLE.equals(action)) {
             mActivity.setHasProfileBecomeUnavailable(true);
             if (mProviderTestRunnable != null) {
diff --git a/src/com/android/documentsui/roots/ProvidersCache.java b/src/com/android/documentsui/roots/ProvidersCache.java
index 317daab..080b729 100644
--- a/src/com/android/documentsui/roots/ProvidersCache.java
+++ b/src/com/android/documentsui/roots/ProvidersCache.java
@@ -142,6 +142,10 @@
         mConfigStore = configStore;
     }
 
+    public boolean isProvidersCacheUsingUserManagerState() {
+        return mUserManagerState != null;
+    }
+
     /**
      * Generates recent root for the provided user id
      */