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 import android.credentials.CredentialManager; 26 27 import com.android.settings.R; 28 import com.android.settings.applications.autofill.PasswordsPreferenceController; 29 import com.android.settings.applications.credentials.CredentialManagerPreferenceController; 30 import com.android.settings.dashboard.DashboardFragment; 31 import com.android.settings.dashboard.profileselector.ProfileSelectFragment; 32 import com.android.settings.users.AutoSyncDataPreferenceController; 33 import com.android.settings.users.AutoSyncPersonalDataPreferenceController; 34 import com.android.settingslib.core.AbstractPreferenceController; 35 36 import java.util.ArrayList; 37 import java.util.List; 38 39 /** Account Setting page for personal profile. */ 40 public class AccountPersonalDashboardFragment extends DashboardFragment { 41 private static final String TAG = "AccountPersonalFrag"; 42 43 @Override getMetricsCategory()44 public int getMetricsCategory() { 45 return SettingsEnums.ACCOUNT_PERSONAL; 46 } 47 48 @Override getLogTag()49 protected String getLogTag() { 50 return TAG; 51 } 52 53 @Override getPreferenceScreenResId()54 protected int getPreferenceScreenResId() { 55 if (this.getContext() != null && CredentialManager.isServiceEnabled(this.getContext())) { 56 return R.xml.accounts_personal_dashboard_settings_credman; 57 } 58 return R.xml.accounts_personal_dashboard_settings; 59 } 60 61 @Override getHelpResource()62 public int getHelpResource() { 63 return R.string.help_url_user_and_account_dashboard; 64 } 65 66 @Override onAttach(Context context)67 public void onAttach(Context context) { 68 super.onAttach(context); 69 if (CredentialManager.isServiceEnabled(context)) { 70 CredentialManagerPreferenceController cmpp = 71 use(CredentialManagerPreferenceController.class); 72 CredentialManagerPreferenceController.Delegate delegate = 73 new CredentialManagerPreferenceController.Delegate() { 74 public void setActivityResult(int resultCode) { 75 getActivity().setResult(resultCode); 76 } 77 public void forceDelegateRefresh() { 78 forceUpdatePreferences(); 79 } 80 }; 81 cmpp.init(this, getFragmentManager(), 82 getIntent(), delegate, /*isWorkProfile=*/false, /*isPrivateSpace=*/ false); 83 } else { 84 getSettingsLifecycle().addObserver(use(PasswordsPreferenceController.class)); 85 } 86 } 87 88 @Override createPreferenceControllers(Context context)89 protected List<AbstractPreferenceController> createPreferenceControllers(Context context) { 90 final List<AbstractPreferenceController> controllers = new ArrayList<>(); 91 buildAutofillPreferenceControllers( 92 context, controllers, /*isWorkProfile=*/ false, /*isPrivateSpace=*/ false); 93 final String[] authorities = getIntent().getStringArrayExtra(EXTRA_AUTHORITIES); 94 buildAccountPreferenceControllers(context, this /* parent */, authorities, controllers); 95 return controllers; 96 } 97 buildAccountPreferenceControllers( Context context, DashboardFragment parent, String[] authorities, List<AbstractPreferenceController> controllers)98 private static void buildAccountPreferenceControllers( 99 Context context, 100 DashboardFragment parent, 101 String[] authorities, 102 List<AbstractPreferenceController> controllers) { 103 final AccountPreferenceController accountPrefController = 104 new AccountPreferenceController( 105 context, parent, authorities, ProfileSelectFragment.ProfileType.PERSONAL); 106 if (parent != null) { 107 parent.getSettingsLifecycle().addObserver(accountPrefController); 108 } 109 controllers.add(accountPrefController); 110 controllers.add(new AutoSyncDataPreferenceController(context, parent)); 111 controllers.add(new AutoSyncPersonalDataPreferenceController(context, parent)); 112 } 113 114 // TODO: b/141601408. After featureFlag settings_work_profile is launched, unmark this 115 // public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = 116 // new BaseSearchIndexProvider(R.xml.accounts_personal_dashboard_settings) { 117 // 118 // @Override 119 // public List<AbstractPreferenceController> createPreferenceControllers( 120 // Context context) { 121 // ..Add autofill here too.. 122 // return buildPreferenceControllers( 123 // context, null /* parent */, null /* authorities*/); 124 // } 125 // }; 126 } 127