diff --git a/res/layout/profile_select_tablayout.xml b/res/layout/profile_select_tablayout.xml index afacaaedfec..4712c1d20f5 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"> + + + - diff --git a/src/com/android/settings/dashboard/profileselector/ProfileFragmentBridge.java b/src/com/android/settings/dashboard/profileselector/ProfileFragmentBridge.java index 1a1a3e63aab..047f740b3c4 100644 --- a/src/com/android/settings/dashboard/profileselector/ProfileFragmentBridge.java +++ b/src/com/android/settings/dashboard/profileselector/ProfileFragmentBridge.java @@ -19,9 +19,8 @@ package com.android.settings.dashboard.profileselector; 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 @@ public class ProfileFragmentBridge { 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 78% rename from src/com/android/settings/accounts/AccountProfileSelectFragment.java rename to src/com/android/settings/dashboard/profileselector/ProfileSelectAccountFragment.java index 128596d599d..ac67b586fa3 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 96eace8da62..323e3cd6ffb 100644 --- a/src/com/android/settings/dashboard/profileselector/ProfileSelectFragment.java +++ b/src/com/android/settings/dashboard/profileselector/ProfileSelectFragment.java @@ -30,6 +30,8 @@ import androidx.viewpager.widget.ViewPager; 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 @@ public abstract class ProfileSelectFragment extends InstrumentedFragment { 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 dc53e1894a4..729025810e2 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 android.os.Bundle; 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 @@ public class ProfileSelectManageApplications extends ProfileSelectFragment { 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 00000000000..c7e4fd8159c --- /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 c78d108ab07..f6a989fe512 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.Context; 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.PreferenceGroup; 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 class SecondaryUserController extends AbstractPreferenceController implem */ public static List getSecondaryUserControllers( Context context, UserManager userManager) { + List 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 infos = userManager.getUsers();