1 /* 2 * Copyright (C) 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.settings.accounts; 18 19 import static android.provider.Settings.EXTRA_AUTHORITIES; 20 21 import static com.android.settings.accounts.AccountDashboardFragment.buildAutofillPreferenceControllers; 22 23 import android.app.settings.SettingsEnums; 24 import android.content.Context; 25 26 import com.android.settings.R; 27 import com.android.settings.SettingsPreferenceFragment; 28 import com.android.settings.applications.autofill.PasswordsPreferenceController; 29 import com.android.settings.dashboard.DashboardFragment; 30 import com.android.settings.dashboard.profileselector.ProfileSelectFragment; 31 import com.android.settings.users.AutoSyncDataPreferenceController; 32 import com.android.settings.users.AutoSyncWorkDataPreferenceController; 33 import com.android.settingslib.core.AbstractPreferenceController; 34 35 import java.util.ArrayList; 36 import java.util.List; 37 38 /** 39 * Account Setting page for work profile. 40 */ 41 public class AccountWorkProfileDashboardFragment extends DashboardFragment { 42 43 private static final String TAG = "AccountWorkProfileFrag"; 44 45 @Override getMetricsCategory()46 public int getMetricsCategory() { 47 return SettingsEnums.ACCOUNT_WORK; 48 } 49 50 @Override getLogTag()51 protected String getLogTag() { 52 return TAG; 53 } 54 55 @Override getPreferenceScreenResId()56 protected int getPreferenceScreenResId() { 57 return R.xml.accounts_work_dashboard_settings; 58 } 59 60 @Override getHelpResource()61 public int getHelpResource() { 62 return R.string.help_url_user_and_account_dashboard; 63 } 64 65 @Override onAttach(Context context)66 public void onAttach(Context context) { 67 super.onAttach(context); 68 getSettingsLifecycle().addObserver(use(PasswordsPreferenceController.class)); 69 } 70 71 @Override createPreferenceControllers(Context context)72 protected List<AbstractPreferenceController> createPreferenceControllers(Context context) { 73 final List<AbstractPreferenceController> controllers = new ArrayList<>(); 74 buildAutofillPreferenceControllers(context, controllers); 75 final String[] authorities = getIntent().getStringArrayExtra(EXTRA_AUTHORITIES); 76 buildAccountPreferenceControllers(context, this /* parent */, authorities, controllers); 77 return controllers; 78 } 79 buildAccountPreferenceControllers( Context context, SettingsPreferenceFragment parent, String[] authorities, List<AbstractPreferenceController> controllers)80 private static void buildAccountPreferenceControllers( 81 Context context, SettingsPreferenceFragment parent, String[] authorities, 82 List<AbstractPreferenceController> controllers) { 83 final AccountPreferenceController accountPrefController = 84 new AccountPreferenceController(context, parent, authorities, 85 ProfileSelectFragment.ProfileType.WORK); 86 if (parent != null) { 87 parent.getSettingsLifecycle().addObserver(accountPrefController); 88 } 89 controllers.add(accountPrefController); 90 controllers.add(new AutoSyncDataPreferenceController(context, parent)); 91 controllers.add(new AutoSyncWorkDataPreferenceController(context, parent)); 92 } 93 94 // TODO: b/141601408. After featureFlag settings_work_profile is launched, unmark this 95 // public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = 96 // new BaseSearchIndexProvider(R.xml.accounts_work_dashboard_settings) { 97 // 98 // @Override 99 // public List<AbstractPreferenceController> createPreferenceControllers( 100 // Context context) { 101 // ..Add autofill here too.. 102 // return buildPreferenceControllers( 103 // context, null /* parent */, null /* authorities*/); 104 // } 105 // }; 106 } 107