2025년 3월 27일부터 AOSP를 빌드하고 기여하려면 aosp-main
대신 android-latest-release
를 사용하는 것이 좋습니다. 자세한 내용은 AOSP 변경사항을 참고하세요.
자동차 설정 재정렬
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
대부분의 경우 설정 계층 구조 재정렬은 비교적 간단한 작업이며 일반적으로 관련 환경설정과 PreferenceController
를 다른 XML 파일로 이동하는 작업으로 구성됩니다. PreferenceController
에서 use(...)
를 사용하면 이전 SettingsFragment
에서 삭제한 후 새 SettingsFragment
에 추가해야 합니다.
이 페이지에서는 설정을 재정렬하는 예를 제공하여 발생할 수 있는 상황을 검토합니다.
기본 환경설정 이동
이 예에서는 한 환경설정 화면에서 다른 환경설정 화면으로 환경설정을 이동하는 방법을 설명합니다. 여기서 환경설정에는 기본 환경설정 컨트롤러만 있습니다. 이 예에서 개발자는 단위 환경설정을 홈페이지 환경설정 화면에서 시스템 환경설정 화면으로 이동합니다. 이렇게 하려면 다음 XML을 homepage_fragment.xml
에서 system_settings_fragment.xml
의 적절한 위치로 이동합니다.
<Preference
android:icon="@drawable/ic_settings_units"
android:key="@string/pk_units_settings_entry"
android:title="@string/units_settings"
settings:controller="com.android.car.settings.common.DefaultRestrictionsPreferenceController">
<intent android:targetPackage="com.android.car.settings"
android:targetClass="com.android.car.settings.common.CarSettingActivities$UnitsSettingsActivity"/>
</Preference>
use(...)를 사용하는 환경설정 이동
다음은 데이터 경고 및 제한 프래그먼트의 모든 환경설정을 한 레벨 위인 데이터 사용량 프래그먼트로 이동하는 좀 더 복잡한 예를 살펴보겠습니다. 데이터 사용량 프래그먼트는 use
메서드를 포함하도록 DataWarningAndLimitFragment.java
를 업데이트하여 생성 후 환경설정 컨트롤러에 정보를 전달합니다.
- 관련 XML을
data_usage_fragment.xml
의 원하는 위치로 이동합니다.<Preference
android:key="@string/pk_data_usage_cycle"
android:title="@string/app_usage_cycle"
settings:controller="com.android.car.settings.datausage.CycleResetDayOfMonthPickerPreferenceController"/>
<com.android.car.settings.common.LogicalPreferenceGroup
android:key="@string/pk_data_warning_group"
settings:controller="com.android.car.settings.datausage.DataWarningPreferenceController">
<SwitchPreference
android:key="@string/pk_data_set_warning"
android:title="@string/set_data_warning"/>
<Preference
android:key="@string/pk_data_warning"
android:title="@string/data_warning"/>
</com.android.car.settings.common.LogicalPreferenceGroup>
<com.android.car.settings.common.LogicalPreferenceGroup
android:key="@string/pk_data_limit_group"
settings:controller="com.android.car.settings.datausage.DataLimitPreferenceController">
<SwitchPreference
android:key="@string/pk_data_set_limit"
android:title="@string/set_data_limit"/>
<Preference
android:key="@string/pk_data_limit"
android:title="@string/data_limit"/>
</com.android.car.settings.common.LogicalPreferenceGroup>
DataWarningAndLimitFragment.java
에서 use
메서드의 사용 방법을 결정합니다.@Override
public void onAttach(Context context) {
super.onAttach(context);
mPolicyEditor = new NetworkPolicyEditor(NetworkPolicyManager.from(context));
mNetworkTemplate = getArguments().getParcelable(
NetworkPolicyManager.EXTRA_NETWORK_TEMPLATE);
if (mNetworkTemplate == null) {
mTelephonyManager = context.getSystemService(TelephonyManager.class);
mSubscriptionManager = context.getSystemService(SubscriptionManager.class);
mNetworkTemplate = DataUsageUtils.getMobileNetworkTemplate(mTelephonyManager,
DataUsageUtils.getDefaultSubscriptionId(mSubscriptionManager));
}
// Loads the current policies to the policy editor cache.
mPolicyEditor.read();
List<DataWarningAndLimitBasePreferenceController> preferenceControllers =
Arrays.asList(
use(CycleResetDayOfMonthPickerPreferenceController.class,
R.string.pk_data_usage_cycle),
use(DataWarningPreferenceController.class, R.string.pk_data_warning_group),
use(DataLimitPreferenceController.class, R.string.pk_data_limit_group));
for (DataWarningAndLimitBasePreferenceController preferenceController :
preferenceControllers) {
preferenceController.setNetworkPolicyEditor(mPolicyEditor);
preferenceController.setNetworkTemplate(mNetworkTemplate);
}
}
이 경우 use
메서드는 환경설정 컨트롤러의 네트워크 정책 편집기 및 네트워크 템플릿을 설정합니다. 이 예에서는 모든 환경설정을 이동하고 onAttach
메서드의 모든 코드가 이러한 환경설정 매개변수를 설정하는 것과 관련이 있으므로 전체 메서드 콘텐츠를 새 프래그먼트로 복사하는 것이 적절할 수 있습니다. 그러나 이는 특정 환경설정에 따라 달라집니다. 관련 인스턴스 변수도 이동해야 합니다.
그러나 문제가 있습니다. 원본 프래그먼트는 NetworkPolicyManager.EXTRA_NETWORK_TEMPLATE
이 인수로 전달될 것으로 예상했습니다. 이 인수는 제공된 경우 인텐트에서 활동으로 전달되어야 합니다.
필요한 이 정보를 가져오려면 newInstance
메서드를 만들어 있는 경우 템플릿을 전달하고(없으면 null 전달) DataUsageFragment
의 활동을 업데이트하거나 getActivity().getIntent()
를 사용하여 onAttach
메서드에서 직접 인텐트 정보를 가져옵니다. 어느 경우든 위에서 실행한 것처럼 이 메서드에 필요한 정보를 전달할 수 있습니다.
- 이전 프래그먼트와 XML 파일을 정리하기 전에 이전 프래그먼트에서 다른 종속 항목이나 예상되는 인텐트 작업을 식별합니다. 이 경우 오버레이 구성 값이 이전 활동을 가리키며 이전 활동은 올바른 활동을 가리키도록 업데이트해야 합니다.
계층 구조에 환경설정 화면 추가
계층 구조에 새 환경설정 화면을 추가하려면 자동차 설정 추가를 참고하세요.
새 환경설정 화면을 만든 후 위의 예를 사용하여 환경설정 계층 구조를 원하는 대로 재정렬합니다.
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-08-02(UTC)
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["필요한 정보가 없음","missingTheInformationINeed","thumb-down"],["너무 복잡함/단계 수가 너무 많음","tooComplicatedTooManySteps","thumb-down"],["오래됨","outOfDate","thumb-down"],["번역 문제","translationIssue","thumb-down"],["샘플/코드 문제","samplesCodeIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-08-02(UTC)"],[],[],null,["# Rearrange Car Settings\n\nFor the most part, rearranging the Settings hierarchy is relatively\nstraightforward and typically consists of moving the relevant preference and\n`PreferenceController` to a different XML file. If the\n`PreferenceController` uses `use(...)`, be sure to remove\nit from the previous `SettingsFragment` and add it to the new\n`SettingsFragment`.\n\nThis page provides examples for reordering Settings to review situations that\nmay occur.\n\nMove a basic preference\n-----------------------\n\nThis example explains how to move a preference from one preference screen to another,\nin which the preference has just a default preference controller. In this example, you\nmove the Units preference from the Homepage preference screen into the System preference\nscreen. To do so, move following XML from `homepage_fragment.xml` into the\nappropriate location in `system_settings_fragment.xml`: \n\n```transact-sql\n\u003cPreference\n android:icon=\"@drawable/ic_settings_units\"\n android:key=\"@string/pk_units_settings_entry\"\n android:title=\"@string/units_settings\"\n settings:controller=\"com.android.car.settings.common.DefaultRestrictionsPreferenceController\"\u003e\n \u003cintent android:targetPackage=\"com.android.car.settings\"\n android:targetClass=\"com.android.car.settings.common.CarSettingActivities$UnitsSettingsActivity\"/\u003e\n \u003c/Preference\u003e\n```\n\nMove a preference that uses use(...)\n------------------------------------\n\nConsider the following more complex example that moves all the preferences\nin the Data Warning \\& Limit fragment up one level into the Data Usage fragment, which\nupdates `DataWarningAndLimitFragment.java` to include the `use` method\nto pass information into the preference controllers after construction.\n\n1. Move the relevant XML to the desired location in `data_usage_fragment.xml`: \n\n ```transact-sql\n \u003cPreference\n android:key=\"@string/pk_data_usage_cycle\"\n android:title=\"@string/app_usage_cycle\"\n settings:controller=\"com.android.car.settings.datausage.CycleResetDayOfMonthPickerPreferenceController\"/\u003e\n \u003ccom.android.car.settings.common.LogicalPreferenceGroup\n android:key=\"@string/pk_data_warning_group\"\n settings:controller=\"com.android.car.settings.datausage.DataWarningPreferenceController\"\u003e\n \u003cSwitchPreference\n android:key=\"@string/pk_data_set_warning\"\n android:title=\"@string/set_data_warning\"/\u003e\n \u003cPreference\n android:key=\"@string/pk_data_warning\"\n android:title=\"@string/data_warning\"/\u003e\n \u003c/com.android.car.settings.common.LogicalPreferenceGroup\u003e\n \u003ccom.android.car.settings.common.LogicalPreferenceGroup\n android:key=\"@string/pk_data_limit_group\"\n settings:controller=\"com.android.car.settings.datausage.DataLimitPreferenceController\"\u003e\n \u003cSwitchPreference\n android:key=\"@string/pk_data_set_limit\"\n android:title=\"@string/set_data_limit\"/\u003e\n \u003cPreference\n android:key=\"@string/pk_data_limit\"\n android:title=\"@string/data_limit\"/\u003e\n \u003c/com.android.car.settings.common.LogicalPreferenceGroup\u003e\n ```\n2. In `DataWarningAndLimitFragment.java`, determine how the `use` method is used. \n\n ```transact-sql\n @Override\n public void onAttach(Context context) {\n super.onAttach(context);\n\n mPolicyEditor = new NetworkPolicyEditor(NetworkPolicyManager.from(context));\n mNetworkTemplate = getArguments().getParcelable(\n NetworkPolicyManager.EXTRA_NETWORK_TEMPLATE);\n if (mNetworkTemplate == null) {\n mTelephonyManager = context.getSystemService(TelephonyManager.class);\n mSubscriptionManager = context.getSystemService(SubscriptionManager.class);\n mNetworkTemplate = DataUsageUtils.getMobileNetworkTemplate(mTelephonyManager,\n DataUsageUtils.getDefaultSubscriptionId(mSubscriptionManager));\n }\n\n // Loads the current policies to the policy editor cache.\n mPolicyEditor.read();\n\n List\u003cDataWarningAndLimitBasePreferenceController\u003e preferenceControllers =\n Arrays.asList(\n use(CycleResetDayOfMonthPickerPreferenceController.class,\n R.string.pk_data_usage_cycle),\n use(DataWarningPreferenceController.class, R.string.pk_data_warning_group),\n use(DataLimitPreferenceController.class, R.string.pk_data_limit_group));\n\n for (DataWarningAndLimitBasePreferenceController preferenceController :\n preferenceControllers) {\n preferenceController.setNetworkPolicyEditor(mPolicyEditor);\n preferenceController.setNetworkTemplate(mNetworkTemplate);\n }\n }\n ```\n\n In this case, the `use` method sets the network policy editor\n and network template for the preference controllers. Because this example moves all\n the preferences and all the code in the `onAttach` method is relevant to\n setting these preference parameters, it would be appropriate to copy over the entire\n method contents into the new fragment. However, this varies depending on the\n specific preference. You need to also move over the relevant instance variables.\n\n However, there is a complication. The original fragment expected\n `NetworkPolicyManager.EXTRA_NETWORK_TEMPLATE` to be\n passed in as an argument, which should come in from the intent to the activity\n (when provided).\n\n To get this needed information, either create a `newInstance`\n method and pass in the template when present (otherwise pass in null) and then\n update the activity for the `DataUsageFragment` or get the intent\n information directly in the `onAttach` method by using\n `getActivity().getIntent()`. In either case, you can pass in the\n needed information for this method as you did above.\n3. Identify any other dependencies or expected intent actions in the old fragment before cleaning up the old fragments and XML files. In this case, an [overlay\n config value](https://android.googlesource.com/platform/packages/services/Car/+/refs/heads/android11-release/car_product/overlay/frameworks/base/core/res/res/values/config.xml#98) points to the old activity, which must be updated to point to the correct activity.\n\nAdd a preference screen to the hierarchy\n----------------------------------------\n\nTo add a new preference screen to the hierarchy, see [Add Car Settings](/docs/automotive/hmi/car_settings/add_car_settings).\n\nAfter creating the new preference screen, use the examples above to rearrange the\npreference hierarchy as desired."]]