Add work/personal profile tab for storage page
- Add ProfileSelectStorageFragment
- Check featureFlag in SecondaryUserController to decide show/hide
workprofile item StorageDashboardFragment
Bug: 141601408
Test: manual
Change-Id: I97762d3b1a4985e2b186b34fc37c7976c2f69224
diff --git a/res/layout/profile_select_tablayout.xml b/res/layout/profile_select_tablayout.xml
index afacaae..4712c1d 100644
--- a/res/layout/profile_select_tablayout.xml
+++ b/res/layout/profile_select_tablayout.xml
@@ -22,21 +22,27 @@
android:layout_height="match_parent"
android:orientation="vertical">
+ <com.google.android.material.tabs.TabLayout
+ android:background="@android:color/transparent"
+ android:id="@+id/tabs"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ app:tabMaxWidth="0dp"
+ app:tabGravity="fill"
+ app:tabMode="fixed"
+ app:tabIndicatorFullWidth="false"
+ app:tabIndicatorColor="@*android:color/accent_device_default"
+ app:tabSelectedTextColor="@*android:color/accent_device_default"
+ app:tabTextColor="?android:attr/textColorSecondary" />
+ <View
+ android:layout_width="match_parent"
+ android:layout_height="1dp"
+ android:background="?android:attr/listDivider"/>
+
<androidx.viewpager.widget.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent">
- <com.google.android.material.tabs.TabLayout
- android:background="@android:color/transparent"
- android:id="@+id/tabs"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- app:tabMaxWidth="0dp"
- app:tabGravity="fill"
- app:tabMode="fixed"
- app:tabIndicatorColor="@*android:color/accent_device_default"
- app:tabSelectedTextColor="@*android:color/accent_device_default"
- app:tabTextColor="?android:attr/textColorSecondary" />
</androidx.viewpager.widget.ViewPager>
</LinearLayout>
diff --git a/src/com/android/settings/dashboard/profileselector/ProfileFragmentBridge.java b/src/com/android/settings/dashboard/profileselector/ProfileFragmentBridge.java
index 1a1a3e6..047f740 100644
--- a/src/com/android/settings/dashboard/profileselector/ProfileFragmentBridge.java
+++ b/src/com/android/settings/dashboard/profileselector/ProfileFragmentBridge.java
@@ -19,9 +19,8 @@
import android.util.ArrayMap;
import com.android.settings.accounts.AccountDashboardFragment;
-import com.android.settings.accounts.AccountProfileSelectFragment;
import com.android.settings.applications.manageapplications.ManageApplications;
-import com.android.settings.applications.manageapplications.ProfileSelectManageApplications;
+import com.android.settings.deviceinfo.StorageDashboardFragment;
import java.util.Map;
@@ -39,8 +38,10 @@
static {
FRAGMENT_MAP = new ArrayMap<>();
FRAGMENT_MAP.put(AccountDashboardFragment.class.getName(),
- AccountProfileSelectFragment.class.getName());
+ ProfileSelectAccountFragment.class.getName());
FRAGMENT_MAP.put(ManageApplications.class.getName(),
ProfileSelectManageApplications.class.getName());
+ FRAGMENT_MAP.put(StorageDashboardFragment.class.getName(),
+ ProfileSelectStorageFragment.class.getName());
}
}
diff --git a/src/com/android/settings/accounts/AccountProfileSelectFragment.java b/src/com/android/settings/dashboard/profileselector/ProfileSelectAccountFragment.java
similarity index 77%
rename from src/com/android/settings/accounts/AccountProfileSelectFragment.java
rename to src/com/android/settings/dashboard/profileselector/ProfileSelectAccountFragment.java
index 128596d..ac67b58 100644
--- a/src/com/android/settings/accounts/AccountProfileSelectFragment.java
+++ b/src/com/android/settings/dashboard/profileselector/ProfileSelectAccountFragment.java
@@ -14,15 +14,16 @@
* limitations under the License.
*/
-package com.android.settings.accounts;
+package com.android.settings.dashboard.profileselector;
import androidx.fragment.app.Fragment;
-import com.android.settings.dashboard.profileselector.ProfileSelectFragment;
+import com.android.settings.accounts.AccountPersonalDashboardFragment;
+import com.android.settings.accounts.AccountWorkProfileDashboardFragment;
/**
* Account Setting page for personal/managed profile.
*/
-public class AccountProfileSelectFragment extends ProfileSelectFragment {
+public class ProfileSelectAccountFragment extends ProfileSelectFragment {
@Override
public Fragment[] getFragments() {
diff --git a/src/com/android/settings/dashboard/profileselector/ProfileSelectFragment.java b/src/com/android/settings/dashboard/profileselector/ProfileSelectFragment.java
index 96eace8..323e3cd 100644
--- a/src/com/android/settings/dashboard/profileselector/ProfileSelectFragment.java
+++ b/src/com/android/settings/dashboard/profileselector/ProfileSelectFragment.java
@@ -30,6 +30,8 @@
import com.android.settings.R;
import com.android.settings.core.InstrumentedFragment;
+import com.google.android.material.tabs.TabLayout;
+
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -69,6 +71,8 @@
mContentView = inflater.inflate(R.layout.profile_select_tablayout, null /* root */);
final ViewPager viewPager = mContentView.findViewById(R.id.view_pager);
viewPager.setAdapter(new ViewPagerAdapter(this));
+ final TabLayout tabs = mContentView.findViewById(R.id.tabs);
+ tabs.setupWithViewPager(viewPager);
return mContentView;
}
diff --git a/src/com/android/settings/applications/manageapplications/ProfileSelectManageApplications.java b/src/com/android/settings/dashboard/profileselector/ProfileSelectManageApplications.java
similarity index 87%
rename from src/com/android/settings/applications/manageapplications/ProfileSelectManageApplications.java
rename to src/com/android/settings/dashboard/profileselector/ProfileSelectManageApplications.java
index dc53e18..7290258 100644
--- a/src/com/android/settings/applications/manageapplications/ProfileSelectManageApplications.java
+++ b/src/com/android/settings/dashboard/profileselector/ProfileSelectManageApplications.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.settings.applications.manageapplications;
+package com.android.settings.dashboard.profileselector;
import static com.android.settings.applications.manageapplications.ManageApplications.EXTRA_PERSONAL_ONLY;
import static com.android.settings.applications.manageapplications.ManageApplications.EXTRA_WORK_ONLY;
@@ -23,10 +23,10 @@
import androidx.fragment.app.Fragment;
-import com.android.settings.dashboard.profileselector.ProfileSelectFragment;
+import com.android.settings.applications.manageapplications.ManageApplications;
/**
- * Application Setting page for work profile.
+ * Application Setting page for personal/managed profile.
*/
public class ProfileSelectManageApplications extends ProfileSelectFragment {
@@ -41,7 +41,7 @@
personalOnly.putBoolean(EXTRA_PERSONAL_ONLY, true);
final Fragment personalFragment = new ManageApplications();
personalFragment.setArguments(personalOnly);
- return new Fragment[] {
+ return new Fragment[]{
personalFragment, //0
workFragment
};
diff --git a/src/com/android/settings/dashboard/profileselector/ProfileSelectStorageFragment.java b/src/com/android/settings/dashboard/profileselector/ProfileSelectStorageFragment.java
new file mode 100644
index 0000000..c7e4fd8
--- /dev/null
+++ b/src/com/android/settings/dashboard/profileselector/ProfileSelectStorageFragment.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.dashboard.profileselector;
+
+import android.content.pm.UserInfo;
+import android.os.Bundle;
+import android.os.UserManager;
+import android.os.storage.VolumeInfo;
+
+import androidx.fragment.app.Fragment;
+
+import com.android.settings.deviceinfo.StorageDashboardFragment;
+import com.android.settings.deviceinfo.StorageProfileFragment;
+
+/**
+ * Storage Setting page for personal/managed profile.
+ */
+public class ProfileSelectStorageFragment extends ProfileSelectFragment {
+ @Override
+ public Fragment[] getFragments() {
+
+ final Bundle storageBundle = new Bundle();
+ storageBundle.putString(VolumeInfo.EXTRA_VOLUME_ID, VolumeInfo.ID_PRIVATE_INTERNAL);
+
+ final Fragment storageDashboardFragment = new StorageDashboardFragment();
+ storageDashboardFragment.setArguments(storageBundle);
+
+ UserInfo targetUser = null;
+ for (UserInfo info : UserManager.get(getActivity()).getUsers()) {
+ if (!info.isPrimary()) {
+ targetUser = info;
+ break;
+ }
+ }
+ // TODO(b/143330969): Need to think about more profile users case
+ if (targetUser != null) {
+ storageBundle.putInt(StorageProfileFragment.USER_ID_EXTRA, targetUser.id);
+ }
+ final Fragment storageProfileFragment = new StorageProfileFragment();
+ storageProfileFragment.setArguments(storageBundle);
+
+ return new Fragment[]{
+ storageDashboardFragment,
+ storageProfileFragment
+ };
+ }
+}
+
diff --git a/src/com/android/settings/deviceinfo/storage/SecondaryUserController.java b/src/com/android/settings/deviceinfo/storage/SecondaryUserController.java
index c78d108..f6a989f 100644
--- a/src/com/android/settings/deviceinfo/storage/SecondaryUserController.java
+++ b/src/com/android/settings/deviceinfo/storage/SecondaryUserController.java
@@ -20,6 +20,7 @@
import android.content.pm.UserInfo;
import android.graphics.drawable.Drawable;
import android.os.UserManager;
+import android.util.FeatureFlagUtils;
import android.util.SparseArray;
import androidx.annotation.NonNull;
@@ -29,6 +30,7 @@
import androidx.preference.PreferenceScreen;
import com.android.settings.Utils;
+import com.android.settings.core.FeatureFlags;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.deviceinfo.StorageItemPreference;
import com.android.settingslib.core.AbstractPreferenceController;
@@ -66,7 +68,12 @@
*/
public static List<AbstractPreferenceController> getSecondaryUserControllers(
Context context, UserManager userManager) {
+
List<AbstractPreferenceController> controllers = new ArrayList<>();
+ if (FeatureFlagUtils.isEnabled(context, FeatureFlags.PERSONAL_WORK_PROFILE)) {
+ controllers.add(new NoSecondaryUserController(context));
+ return controllers;
+ }
UserInfo primaryUser = userManager.getPrimaryUser();
boolean addedUser = false;
List<UserInfo> infos = userManager.getUsers();