Add tablayout for work/personal profile
- Add Tablayout in ProfileSelectFragment - Add AccountWorkProfileDashboardFragment inherited from ProfileSelectFragment - Add ProfileFragmentBridge to convert AccountDashboardFragment to AccountProfileSelectFragment - Use flag settings_work_profile to guard the new fragment Bug: 141601408 Test: Settings->developer options->feature flags-> turn settings_work_profile on/off, then go to settings->account to see if UI is changed. Change-Id: Ifb32c22cdeab69c51517664081cacf4a401c46a1
This commit is contained in:
42
res/layout/profile_select_tablayout.xml
Normal file
42
res/layout/profile_select_tablayout.xml
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
<!--
|
||||||
|
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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:theme="@style/Theme.MaterialComponents.DayNight"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<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>
|
42
res/xml/accounts_personal_dashboard_settings.xml
Normal file
42
res/xml/accounts_personal_dashboard_settings.xml
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<PreferenceScreen
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:settings="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:key="user_and_account_settings_screen"
|
||||||
|
android:title="@string/account_dashboard_title"
|
||||||
|
settings:keywords="@string/keywords_accounts">
|
||||||
|
|
||||||
|
<PreferenceCategory
|
||||||
|
android:key="dashboard_tile_placeholder"
|
||||||
|
android:order="30"/>
|
||||||
|
|
||||||
|
<SwitchPreference
|
||||||
|
android:key="auto_sync_account_data"
|
||||||
|
android:title="@string/auto_sync_account_title"
|
||||||
|
android:summary="@string/auto_sync_account_summary"
|
||||||
|
android:order="100"
|
||||||
|
settings:allowDividerAbove="true"/>
|
||||||
|
|
||||||
|
<SwitchPreference
|
||||||
|
android:key="auto_sync_personal_account_data"
|
||||||
|
android:title="@string/account_settings_menu_auto_sync_personal"
|
||||||
|
android:summary="@string/auto_sync_account_summary"
|
||||||
|
android:order="110"/>
|
||||||
|
|
||||||
|
</PreferenceScreen>
|
42
res/xml/accounts_work_dashboard_settings.xml
Normal file
42
res/xml/accounts_work_dashboard_settings.xml
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<PreferenceScreen
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:settings="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:key="user_and_account_settings_screen"
|
||||||
|
android:title="@string/account_dashboard_title"
|
||||||
|
settings:keywords="@string/keywords_accounts">
|
||||||
|
|
||||||
|
<PreferenceCategory
|
||||||
|
android:key="dashboard_tile_placeholder"
|
||||||
|
android:order="30"/>
|
||||||
|
|
||||||
|
<SwitchPreference
|
||||||
|
android:key="auto_sync_account_data"
|
||||||
|
android:title="@string/auto_sync_account_title"
|
||||||
|
android:summary="@string/auto_sync_account_summary"
|
||||||
|
android:order="100"
|
||||||
|
settings:allowDividerAbove="true"/>
|
||||||
|
|
||||||
|
<SwitchPreference
|
||||||
|
android:key="auto_sync_work_account_data"
|
||||||
|
android:title="@string/account_settings_menu_auto_sync_work"
|
||||||
|
android:summary="@string/auto_sync_account_summary"
|
||||||
|
android:order="110"/>
|
||||||
|
|
||||||
|
</PreferenceScreen>
|
@@ -35,6 +35,7 @@ import android.os.Bundle;
|
|||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
import android.util.FeatureFlagUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
@@ -52,11 +53,13 @@ import androidx.preference.PreferenceManager;
|
|||||||
import com.android.internal.util.ArrayUtils;
|
import com.android.internal.util.ArrayUtils;
|
||||||
import com.android.settings.Settings.WifiSettingsActivity;
|
import com.android.settings.Settings.WifiSettingsActivity;
|
||||||
import com.android.settings.applications.manageapplications.ManageApplications;
|
import com.android.settings.applications.manageapplications.ManageApplications;
|
||||||
|
import com.android.settings.core.FeatureFlags;
|
||||||
import com.android.settings.core.OnActivityResultListener;
|
import com.android.settings.core.OnActivityResultListener;
|
||||||
import com.android.settings.core.SettingsBaseActivity;
|
import com.android.settings.core.SettingsBaseActivity;
|
||||||
import com.android.settings.core.SubSettingLauncher;
|
import com.android.settings.core.SubSettingLauncher;
|
||||||
import com.android.settings.core.gateway.SettingsGateway;
|
import com.android.settings.core.gateway.SettingsGateway;
|
||||||
import com.android.settings.dashboard.DashboardFeatureProvider;
|
import com.android.settings.dashboard.DashboardFeatureProvider;
|
||||||
|
import com.android.settings.dashboard.profileselector.ProfileFragmentBridge;
|
||||||
import com.android.settings.homepage.TopLevelSettings;
|
import com.android.settings.homepage.TopLevelSettings;
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
import com.android.settings.wfd.WifiDisplaySettings;
|
import com.android.settings.wfd.WifiDisplaySettings;
|
||||||
@@ -565,7 +568,15 @@ public class SettingsActivity extends SettingsBaseActivity
|
|||||||
throw new IllegalArgumentException("Invalid fragment for this activity: "
|
throw new IllegalArgumentException("Invalid fragment for this activity: "
|
||||||
+ fragmentName);
|
+ fragmentName);
|
||||||
}
|
}
|
||||||
Fragment f = Fragment.instantiate(this, fragmentName, args);
|
Fragment f = null;
|
||||||
|
if (FeatureFlagUtils.isEnabled(this, FeatureFlags.PERSONAL_WORK_PROFILE)
|
||||||
|
&& UserManager.get(this).getUserProfiles().size() > 1
|
||||||
|
&& ProfileFragmentBridge.FRAGMENT_MAP.get(fragmentName) != null) {
|
||||||
|
f = Fragment.instantiate(this, ProfileFragmentBridge.FRAGMENT_MAP.get(fragmentName),
|
||||||
|
args);
|
||||||
|
} else {
|
||||||
|
f = Fragment.instantiate(this, fragmentName, args);
|
||||||
|
}
|
||||||
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
|
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
|
||||||
transaction.replace(R.id.main_content, f);
|
transaction.replace(R.id.main_content, f);
|
||||||
if (titleResId > 0) {
|
if (titleResId > 0) {
|
||||||
|
@@ -23,6 +23,7 @@ import android.content.Context;
|
|||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.SettingsPreferenceFragment;
|
import com.android.settings.SettingsPreferenceFragment;
|
||||||
import com.android.settings.dashboard.DashboardFragment;
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
|
import com.android.settings.dashboard.profileselector.ProfileSelectFragment;
|
||||||
import com.android.settings.search.BaseSearchIndexProvider;
|
import com.android.settings.search.BaseSearchIndexProvider;
|
||||||
import com.android.settings.users.AutoSyncDataPreferenceController;
|
import com.android.settings.users.AutoSyncDataPreferenceController;
|
||||||
import com.android.settings.users.AutoSyncPersonalDataPreferenceController;
|
import com.android.settings.users.AutoSyncPersonalDataPreferenceController;
|
||||||
@@ -70,7 +71,8 @@ public class AccountDashboardFragment extends DashboardFragment {
|
|||||||
final List<AbstractPreferenceController> controllers = new ArrayList<>();
|
final List<AbstractPreferenceController> controllers = new ArrayList<>();
|
||||||
|
|
||||||
final AccountPreferenceController accountPrefController =
|
final AccountPreferenceController accountPrefController =
|
||||||
new AccountPreferenceController(context, parent, authorities);
|
new AccountPreferenceController(context, parent, authorities,
|
||||||
|
ProfileSelectFragment.ALL);
|
||||||
if (parent != null) {
|
if (parent != null) {
|
||||||
parent.getSettingsLifecycle().addObserver(accountPrefController);
|
parent.getSettingsLifecycle().addObserver(accountPrefController);
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,97 @@
|
|||||||
|
/*
|
||||||
|
* 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.accounts;
|
||||||
|
|
||||||
|
import static android.provider.Settings.EXTRA_AUTHORITIES;
|
||||||
|
|
||||||
|
import android.app.settings.SettingsEnums;
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.SettingsPreferenceFragment;
|
||||||
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
|
import com.android.settings.dashboard.profileselector.ProfileSelectFragment;
|
||||||
|
import com.android.settings.users.AutoSyncDataPreferenceController;
|
||||||
|
import com.android.settings.users.AutoSyncPersonalDataPreferenceController;
|
||||||
|
import com.android.settingslib.core.AbstractPreferenceController;
|
||||||
|
import com.android.settingslib.search.SearchIndexable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Account Setting page for personal profile.
|
||||||
|
*/
|
||||||
|
@SearchIndexable
|
||||||
|
public class AccountPersonalDashboardFragment extends DashboardFragment {
|
||||||
|
|
||||||
|
private static final String TAG = "AccountPersonalFrag";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMetricsCategory() {
|
||||||
|
return SettingsEnums.ACCOUNT;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getLogTag() {
|
||||||
|
return TAG;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int getPreferenceScreenResId() {
|
||||||
|
return R.xml.accounts_personal_dashboard_settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getHelpResource() {
|
||||||
|
return R.string.help_url_user_and_account_dashboard;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
|
||||||
|
final String[] authorities = getIntent().getStringArrayExtra(EXTRA_AUTHORITIES);
|
||||||
|
return buildPreferenceControllers(context, this /* parent */, authorities);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
|
||||||
|
SettingsPreferenceFragment parent, String[] authorities) {
|
||||||
|
final List<AbstractPreferenceController> controllers = new ArrayList<>();
|
||||||
|
|
||||||
|
final AccountPreferenceController accountPrefController =
|
||||||
|
new AccountPreferenceController(context, parent, authorities,
|
||||||
|
ProfileSelectFragment.PERSONAL);
|
||||||
|
if (parent != null) {
|
||||||
|
parent.getSettingsLifecycle().addObserver(accountPrefController);
|
||||||
|
}
|
||||||
|
controllers.add(accountPrefController);
|
||||||
|
controllers.add(new AutoSyncDataPreferenceController(context, parent));
|
||||||
|
controllers.add(new AutoSyncPersonalDataPreferenceController(context, parent));
|
||||||
|
return controllers;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: b/141601408. After featureFlag settings_work_profile is launched, unmark this
|
||||||
|
// public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||||
|
// new BaseSearchIndexProvider(R.xml.accounts_personal_dashboard_settings) {
|
||||||
|
//
|
||||||
|
// @Override
|
||||||
|
// public List<AbstractPreferenceController> createPreferenceControllers(
|
||||||
|
// Context context) {
|
||||||
|
// return buildPreferenceControllers(
|
||||||
|
// context, null /* parent */, null /* authorities*/);
|
||||||
|
// }
|
||||||
|
// };
|
||||||
|
}
|
@@ -53,8 +53,8 @@ import com.android.settings.SettingsPreferenceFragment;
|
|||||||
import com.android.settings.Utils;
|
import com.android.settings.Utils;
|
||||||
import com.android.settings.core.PreferenceControllerMixin;
|
import com.android.settings.core.PreferenceControllerMixin;
|
||||||
import com.android.settings.core.SubSettingLauncher;
|
import com.android.settings.core.SubSettingLauncher;
|
||||||
|
import com.android.settings.dashboard.profileselector.ProfileSelectFragment;
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
import com.android.settingslib.search.SearchIndexableRaw;
|
|
||||||
import com.android.settingslib.RestrictedPreference;
|
import com.android.settingslib.RestrictedPreference;
|
||||||
import com.android.settingslib.accounts.AuthenticatorHelper;
|
import com.android.settingslib.accounts.AuthenticatorHelper;
|
||||||
import com.android.settingslib.core.AbstractPreferenceController;
|
import com.android.settingslib.core.AbstractPreferenceController;
|
||||||
@@ -62,6 +62,7 @@ import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
|||||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||||
import com.android.settingslib.core.lifecycle.events.OnPause;
|
import com.android.settingslib.core.lifecycle.events.OnPause;
|
||||||
import com.android.settingslib.core.lifecycle.events.OnResume;
|
import com.android.settingslib.core.lifecycle.events.OnResume;
|
||||||
|
import com.android.settingslib.search.SearchIndexableRaw;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -81,8 +82,8 @@ public class AccountPreferenceController extends AbstractPreferenceController
|
|||||||
|
|
||||||
private UserManager mUm;
|
private UserManager mUm;
|
||||||
private SparseArray<ProfileData> mProfiles = new SparseArray<ProfileData>();
|
private SparseArray<ProfileData> mProfiles = new SparseArray<ProfileData>();
|
||||||
private ManagedProfileBroadcastReceiver mManagedProfileBroadcastReceiver
|
private ManagedProfileBroadcastReceiver mManagedProfileBroadcastReceiver =
|
||||||
= new ManagedProfileBroadcastReceiver();
|
new ManagedProfileBroadcastReceiver();
|
||||||
private Preference mProfileNotAvailablePreference;
|
private Preference mProfileNotAvailablePreference;
|
||||||
private String[] mAuthorities;
|
private String[] mAuthorities;
|
||||||
private int mAuthoritiesCount = 0;
|
private int mAuthoritiesCount = 0;
|
||||||
@@ -90,6 +91,7 @@ public class AccountPreferenceController extends AbstractPreferenceController
|
|||||||
private int mAccountProfileOrder = ORDER_ACCOUNT_PROFILES;
|
private int mAccountProfileOrder = ORDER_ACCOUNT_PROFILES;
|
||||||
private AccountRestrictionHelper mHelper;
|
private AccountRestrictionHelper mHelper;
|
||||||
private MetricsFeatureProvider mMetricsFeatureProvider;
|
private MetricsFeatureProvider mMetricsFeatureProvider;
|
||||||
|
private @ProfileSelectFragment.ProfileType int mType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds data related to the accounts belonging to one profile.
|
* Holds data related to the accounts belonging to one profile.
|
||||||
@@ -130,13 +132,14 @@ public class AccountPreferenceController extends AbstractPreferenceController
|
|||||||
}
|
}
|
||||||
|
|
||||||
public AccountPreferenceController(Context context, SettingsPreferenceFragment parent,
|
public AccountPreferenceController(Context context, SettingsPreferenceFragment parent,
|
||||||
String[] authorities) {
|
String[] authorities, @ProfileSelectFragment.ProfileType int type) {
|
||||||
this(context, parent, authorities, new AccountRestrictionHelper(context));
|
this(context, parent, authorities, new AccountRestrictionHelper(context), type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
AccountPreferenceController(Context context, SettingsPreferenceFragment parent,
|
AccountPreferenceController(Context context, SettingsPreferenceFragment parent,
|
||||||
String[] authorities, AccountRestrictionHelper helper) {
|
String[] authorities, AccountRestrictionHelper helper,
|
||||||
|
@ProfileSelectFragment.ProfileType int type) {
|
||||||
super(context);
|
super(context);
|
||||||
mUm = (UserManager) context.getSystemService(Context.USER_SERVICE);
|
mUm = (UserManager) context.getSystemService(Context.USER_SERVICE);
|
||||||
mAuthorities = authorities;
|
mAuthorities = authorities;
|
||||||
@@ -147,6 +150,7 @@ public class AccountPreferenceController extends AbstractPreferenceController
|
|||||||
final FeatureFactory featureFactory = FeatureFactory.getFactory(mContext);
|
final FeatureFactory featureFactory = FeatureFactory.getFactory(mContext);
|
||||||
mMetricsFeatureProvider = featureFactory.getMetricsFeatureProvider();
|
mMetricsFeatureProvider = featureFactory.getMetricsFeatureProvider();
|
||||||
mHelper = helper;
|
mHelper = helper;
|
||||||
|
mType = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -277,7 +281,13 @@ public class AccountPreferenceController extends AbstractPreferenceController
|
|||||||
List<UserInfo> profiles = mUm.getProfiles(UserHandle.myUserId());
|
List<UserInfo> profiles = mUm.getProfiles(UserHandle.myUserId());
|
||||||
final int profilesCount = profiles.size();
|
final int profilesCount = profiles.size();
|
||||||
for (int i = 0; i < profilesCount; i++) {
|
for (int i = 0; i < profilesCount; i++) {
|
||||||
|
if (profiles.get(i).isManagedProfile()
|
||||||
|
&& (mType & ProfileSelectFragment.WORK) != 0) {
|
||||||
updateProfileUi(profiles.get(i));
|
updateProfileUi(profiles.get(i));
|
||||||
|
} else if (!profiles.get(i).isManagedProfile()
|
||||||
|
&& (mType & ProfileSelectFragment.PERSONAL) != 0) {
|
||||||
|
updateProfileUi(profiles.get(i));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cleanUpPreferences();
|
cleanUpPreferences();
|
||||||
@@ -310,7 +320,8 @@ public class AccountPreferenceController extends AbstractPreferenceController
|
|||||||
final ProfileData profileData = new ProfileData();
|
final ProfileData profileData = new ProfileData();
|
||||||
profileData.userInfo = userInfo;
|
profileData.userInfo = userInfo;
|
||||||
AccessiblePreferenceCategory preferenceGroup =
|
AccessiblePreferenceCategory preferenceGroup =
|
||||||
mHelper.createAccessiblePreferenceCategory(mParent.getPreferenceManager().getContext());
|
mHelper.createAccessiblePreferenceCategory(
|
||||||
|
mParent.getPreferenceManager().getContext());
|
||||||
preferenceGroup.setOrder(mAccountProfileOrder++);
|
preferenceGroup.setOrder(mAccountProfileOrder++);
|
||||||
if (isSingleProfile()) {
|
if (isSingleProfile()) {
|
||||||
preferenceGroup.setTitle(context.getString(R.string.account_for_section_header,
|
preferenceGroup.setTitle(context.getString(R.string.account_for_section_header,
|
||||||
|
@@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* 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.accounts;
|
||||||
|
import androidx.fragment.app.Fragment;
|
||||||
|
|
||||||
|
import com.android.settings.dashboard.profileselector.ProfileSelectFragment;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Account Setting page for personal/managed profile.
|
||||||
|
*/
|
||||||
|
public class AccountProfileSelectFragment extends ProfileSelectFragment {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Fragment[] getFragments() {
|
||||||
|
return new Fragment[] {
|
||||||
|
new AccountPersonalDashboardFragment(),
|
||||||
|
new AccountWorkProfileDashboardFragment()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,97 @@
|
|||||||
|
/*
|
||||||
|
* 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.accounts;
|
||||||
|
|
||||||
|
import static android.provider.Settings.EXTRA_AUTHORITIES;
|
||||||
|
|
||||||
|
import android.app.settings.SettingsEnums;
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.SettingsPreferenceFragment;
|
||||||
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
|
import com.android.settings.dashboard.profileselector.ProfileSelectFragment;
|
||||||
|
import com.android.settings.users.AutoSyncDataPreferenceController;
|
||||||
|
import com.android.settings.users.AutoSyncWorkDataPreferenceController;
|
||||||
|
import com.android.settingslib.core.AbstractPreferenceController;
|
||||||
|
import com.android.settingslib.search.SearchIndexable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Account Setting page for work profile.
|
||||||
|
*/
|
||||||
|
@SearchIndexable
|
||||||
|
public class AccountWorkProfileDashboardFragment extends DashboardFragment {
|
||||||
|
|
||||||
|
private static final String TAG = "AccountWorkProfileFrag";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMetricsCategory() {
|
||||||
|
return SettingsEnums.ACCOUNT;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getLogTag() {
|
||||||
|
return TAG;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int getPreferenceScreenResId() {
|
||||||
|
return R.xml.accounts_work_dashboard_settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getHelpResource() {
|
||||||
|
return R.string.help_url_user_and_account_dashboard;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
|
||||||
|
final String[] authorities = getIntent().getStringArrayExtra(EXTRA_AUTHORITIES);
|
||||||
|
return buildPreferenceControllers(context, this /* parent */, authorities);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
|
||||||
|
SettingsPreferenceFragment parent, String[] authorities) {
|
||||||
|
final List<AbstractPreferenceController> controllers = new ArrayList<>();
|
||||||
|
|
||||||
|
final AccountPreferenceController accountPrefController =
|
||||||
|
new AccountPreferenceController(context, parent, authorities,
|
||||||
|
ProfileSelectFragment.WORK);
|
||||||
|
if (parent != null) {
|
||||||
|
parent.getSettingsLifecycle().addObserver(accountPrefController);
|
||||||
|
}
|
||||||
|
controllers.add(accountPrefController);
|
||||||
|
controllers.add(new AutoSyncDataPreferenceController(context, parent));
|
||||||
|
controllers.add(new AutoSyncWorkDataPreferenceController(context, parent));
|
||||||
|
return controllers;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: b/141601408. After featureFlag settings_work_profile is launched, unmark this
|
||||||
|
// public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||||
|
// new BaseSearchIndexProvider(R.xml.accounts_work_dashboard_settings) {
|
||||||
|
//
|
||||||
|
// @Override
|
||||||
|
// public List<AbstractPreferenceController> createPreferenceControllers(
|
||||||
|
// Context context) {
|
||||||
|
// return buildPreferenceControllers(
|
||||||
|
// context, null /* parent */, null /* authorities*/);
|
||||||
|
// }
|
||||||
|
// };
|
||||||
|
}
|
@@ -27,4 +27,5 @@ public class FeatureFlags {
|
|||||||
public static final String NETWORK_INTERNET_V2 = "settings_network_and_internet_v2";
|
public static final String NETWORK_INTERNET_V2 = "settings_network_and_internet_v2";
|
||||||
public static final String WIFI_DETAILS_DATAUSAGE_HEADER =
|
public static final String WIFI_DETAILS_DATAUSAGE_HEADER =
|
||||||
"settings_wifi_details_datausage_header";
|
"settings_wifi_details_datausage_header";
|
||||||
|
public static final String PERSONAL_WORK_PROFILE = "settings_work_profile";
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* 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.util.ArrayMap;
|
||||||
|
|
||||||
|
import com.android.settings.accounts.AccountDashboardFragment;
|
||||||
|
import com.android.settings.accounts.AccountProfileSelectFragment;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A registry to keep track of which page and its own profile selection page.
|
||||||
|
*/
|
||||||
|
public class ProfileFragmentBridge {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Map from parent fragment to category key. The parent fragment hosts child with
|
||||||
|
* category_key.
|
||||||
|
*/
|
||||||
|
public static final Map<String, String> FRAGMENT_MAP;
|
||||||
|
|
||||||
|
static {
|
||||||
|
FRAGMENT_MAP = new ArrayMap<>();
|
||||||
|
FRAGMENT_MAP.put(AccountDashboardFragment.class.getName(),
|
||||||
|
AccountProfileSelectFragment.class.getName());
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,116 @@
|
|||||||
|
/*
|
||||||
|
* 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.annotation.IntDef;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
import androidx.fragment.app.Fragment;
|
||||||
|
import androidx.fragment.app.FragmentStatePagerAdapter;
|
||||||
|
import androidx.viewpager.widget.ViewPager;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.core.InstrumentedFragment;
|
||||||
|
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base fragment class for per profile settings.
|
||||||
|
*/
|
||||||
|
public abstract class ProfileSelectFragment extends InstrumentedFragment {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Denotes the profile type.
|
||||||
|
*/
|
||||||
|
@Retention(RetentionPolicy.SOURCE)
|
||||||
|
@IntDef({PERSONAL, WORK, ALL})
|
||||||
|
public @interface ProfileType {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* It is personal work profile.
|
||||||
|
*/
|
||||||
|
public static final int PERSONAL = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* It is work profile
|
||||||
|
*/
|
||||||
|
public static final int WORK = 1 << 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* It is personal and work profile
|
||||||
|
*/
|
||||||
|
public static final int ALL = PERSONAL | WORK;
|
||||||
|
|
||||||
|
private View mContentView;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
|
Bundle savedInstanceState) {
|
||||||
|
mContentView = inflater.inflate(R.layout.profile_select_tablayout, null /* root */);
|
||||||
|
final ViewPager viewPager = mContentView.findViewById(R.id.view_pager);
|
||||||
|
viewPager.setAdapter(new ViewPagerAdapter(this));
|
||||||
|
return mContentView;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMetricsCategory() {
|
||||||
|
return METRICS_CATEGORY_UNKNOWN;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an array of {@link Fragment} to display in the
|
||||||
|
* {@link com.google.android.material.tabs.TabLayout}
|
||||||
|
*/
|
||||||
|
public abstract Fragment[] getFragments();
|
||||||
|
|
||||||
|
static class ViewPagerAdapter extends FragmentStatePagerAdapter {
|
||||||
|
|
||||||
|
private final Fragment[] mChildFragments;
|
||||||
|
private final Context mContext;
|
||||||
|
|
||||||
|
ViewPagerAdapter(ProfileSelectFragment fragment) {
|
||||||
|
super(fragment.getActivity().getSupportFragmentManager());
|
||||||
|
mContext = fragment.getContext();
|
||||||
|
mChildFragments = fragment.getFragments();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Fragment getItem(int position) {
|
||||||
|
return mChildFragments[position];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getCount() {
|
||||||
|
return mChildFragments.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CharSequence getPageTitle(int position) {
|
||||||
|
if (position == 0) {
|
||||||
|
return mContext.getString(R.string.category_personal);
|
||||||
|
} else {
|
||||||
|
return mContext.getString(R.string.category_work);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -46,6 +46,7 @@ import androidx.preference.PreferenceScreen;
|
|||||||
import com.android.settings.AccessiblePreferenceCategory;
|
import com.android.settings.AccessiblePreferenceCategory;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.SettingsPreferenceFragment;
|
import com.android.settings.SettingsPreferenceFragment;
|
||||||
|
import com.android.settings.dashboard.profileselector.ProfileSelectFragment;
|
||||||
import com.android.settings.testutils.shadow.ShadowAccountManager;
|
import com.android.settings.testutils.shadow.ShadowAccountManager;
|
||||||
import com.android.settings.testutils.shadow.ShadowContentResolver;
|
import com.android.settings.testutils.shadow.ShadowContentResolver;
|
||||||
import com.android.settingslib.search.SearchIndexableRaw;
|
import com.android.settingslib.search.SearchIndexableRaw;
|
||||||
@@ -96,7 +97,8 @@ public class AccountPreferenceControllerTest {
|
|||||||
when(mAccountManager.getAuthenticatorTypesAsUser(anyInt()))
|
when(mAccountManager.getAuthenticatorTypesAsUser(anyInt()))
|
||||||
.thenReturn(new AuthenticatorDescription[0]);
|
.thenReturn(new AuthenticatorDescription[0]);
|
||||||
when(mAccountManager.getAccountsAsUser(anyInt())).thenReturn(new Account[0]);
|
when(mAccountManager.getAccountsAsUser(anyInt())).thenReturn(new Account[0]);
|
||||||
mController = new AccountPreferenceController(mContext, mFragment, null, mAccountHelper);
|
mController = new AccountPreferenceController(mContext, mFragment, null, mAccountHelper,
|
||||||
|
ProfileSelectFragment.ALL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
|
Reference in New Issue
Block a user