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.car.settings.accounts; 18 19 import android.accounts.Account; 20 import android.car.drivingstate.CarUxRestrictions; 21 import android.content.Context; 22 import android.os.Bundle; 23 24 import androidx.annotation.CallSuper; 25 import androidx.preference.Preference; 26 27 import com.android.car.settings.common.ExtraSettingsPreferenceController; 28 import com.android.car.settings.common.FragmentController; 29 30 import java.util.Map; 31 32 /** 33 * Injects preferences from other system applications at a placeholder location into the account 34 * details fragment. This class is and extension of {@link ExtraSettingsPreferenceController} which 35 * is needed to check what all preferences to show in the account details page. 36 */ 37 public class AccountDetailsSettingController extends ExtraSettingsPreferenceController { 38 39 private static final String METADATA_IA_ACCOUNT = "com.android.settings.ia.account"; 40 private Account mAccount; 41 AccountDetailsSettingController(Context context, String preferenceKey, FragmentController fragmentController, CarUxRestrictions restrictionInfo)42 public AccountDetailsSettingController(Context context, String preferenceKey, 43 FragmentController fragmentController, CarUxRestrictions restrictionInfo) { 44 super(context, preferenceKey, fragmentController, restrictionInfo); 45 } 46 47 /** Sets the account that the preferences are being shown for. */ setAccount(Account account)48 public void setAccount(Account account) { 49 mAccount = account; 50 } 51 52 @Override 53 @CallSuper checkInitialized()54 protected void checkInitialized() { 55 if (mAccount == null) { 56 throw new IllegalStateException( 57 "AccountDetailsSettingController must be initialized by calling " 58 + "setAccount(Account)"); 59 } 60 } 61 62 @Override 63 @CallSuper addExtraSettings(Map<Preference, Bundle> preferenceBundleMap)64 protected void addExtraSettings(Map<Preference, Bundle> preferenceBundleMap) { 65 for (Preference setting : preferenceBundleMap.keySet()) { 66 if (mAccount != null && !mAccount.type.equals( 67 preferenceBundleMap.get(setting).getString(METADATA_IA_ACCOUNT))) { 68 continue; 69 } 70 getPreference().addPreference(setting); 71 } 72 } 73 } 74