1 /* 2 * Copyright (C) 2018 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.car.settings.profiles; 18 19 import android.content.Context; 20 import android.content.Intent; 21 import android.content.pm.UserInfo; 22 import android.provider.Settings; 23 24 import androidx.annotation.XmlRes; 25 26 import com.android.car.settings.R; 27 import com.android.car.settings.accounts.AccountGroupPreferenceController; 28 import com.android.car.settings.accounts.AccountListPreferenceController; 29 import com.android.car.settings.accounts.AddAccountPreferenceController; 30 import com.android.car.settings.search.CarBaseSearchIndexProvider; 31 import com.android.settingslib.search.SearchIndexable; 32 33 /** 34 * Shows details for a user with the ability to remove user and edit current user. 35 */ 36 @SearchIndexable 37 public class ProfileDetailsFragment extends ProfileDetailsBaseFragment { 38 39 /** Creates instance of ProfileDetailsFragment. */ newInstance(int userId)40 public static ProfileDetailsFragment newInstance(int userId) { 41 return (ProfileDetailsFragment) addUserIdToFragmentArguments( 42 new ProfileDetailsFragment(), userId); 43 } 44 45 @Override 46 @XmlRes getPreferenceScreenResId()47 protected int getPreferenceScreenResId() { 48 return R.xml.profile_details_fragment; 49 } 50 51 @Override onAttach(Context context)52 public void onAttach(Context context) { 53 super.onAttach(context); 54 UserInfo userInfo = getUserInfo(); 55 use(ProfileDetailsHeaderPreferenceController.class, 56 R.string.pk_profile_details_header).setUserInfo(userInfo); 57 use(ProfileDetailsActionButtonsPreferenceController.class, 58 R.string.pk_profile_details_action_buttons).setUserInfo(userInfo); 59 use(AccountGroupPreferenceController.class, 60 R.string.pk_account_group).setUserInfo(userInfo); 61 use(ProfileDetailsDeletePreferenceController.class, 62 R.string.pk_profile_details_delete).setUserInfo(userInfo); 63 use(ProfileDetailsEndSessionPreferenceController.class, 64 R.string.pk_profile_details_end_session).setUserInfo(userInfo); 65 66 // Accounts information 67 Intent activityIntent = requireActivity().getIntent(); 68 String[] authorities = activityIntent.getStringArrayExtra(Settings.EXTRA_AUTHORITIES); 69 String[] accountTypes = activityIntent.getStringArrayExtra(Settings.EXTRA_ACCOUNT_TYPES); 70 if (authorities != null || accountTypes != null) { 71 use(AccountListPreferenceController.class, R.string.pk_account_list) 72 .setAuthorities(authorities); 73 use(AddAccountPreferenceController.class, R.string.pk_account_settings_add) 74 .setAuthorities(authorities).setAccountTypes(accountTypes); 75 } 76 } 77 78 @Override getTitleText()79 protected String getTitleText() { 80 return getString(R.string.profiles_and_accounts_settings_title); 81 } 82 83 /** 84 * Data provider for Settings Search. 85 */ 86 public static final CarBaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = 87 new CarBaseSearchIndexProvider(R.xml.profile_details_fragment, 88 Settings.ACTION_USER_SETTINGS); 89 } 90