• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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 
18 package com.android.car.settings.system;
19 
20 import android.content.Context;
21 import android.content.Intent;
22 import android.content.pm.PackageManager;
23 import android.os.Build;
24 import android.os.Bundle;
25 
26 import androidx.car.widget.ListItem;
27 import androidx.car.widget.ListItemProvider;
28 import androidx.car.widget.TextListItem;
29 
30 import com.android.car.settings.R;
31 import com.android.car.settings.common.ExtraSettingsLoader;
32 import com.android.car.settings.common.ListItemSettingsFragment;
33 import com.android.car.settingslib.language.LanguagePickerUtils;
34 import com.android.internal.app.LocaleHelper;
35 
36 import java.util.ArrayList;
37 import java.util.Collection;
38 import java.util.Locale;
39 import java.util.Map;
40 
41 /**
42  * Shows basic info about the system and provide some actions like update, reset etc.
43  */
44 public class SystemSettingsFragment extends ListItemSettingsFragment {
45 
46     // Copied from hidden version in android.provider.Settings
47     private static final String ACTION_SYSTEM_UPDATE_SETTINGS =
48             "android.settings.SYSTEM_UPDATE_SETTINGS";
49 
50     private static final String ACTION_SETTING_VIEW_LICENSE =
51             "android.settings.WEBVIEW_LICENSE";
52 
53     private ListItemProvider mItemProvider;
54 
getInstance()55     public static SystemSettingsFragment getInstance() {
56         SystemSettingsFragment systemSettingsFragment = new SystemSettingsFragment();
57         Bundle bundle = ListItemSettingsFragment.getBundle();
58         bundle.putInt(EXTRA_TITLE_ID, R.string.system_setting_title);
59         systemSettingsFragment.setArguments(bundle);
60         return systemSettingsFragment;
61     }
62 
63     @Override
onActivityCreated(Bundle savedInstanceState)64     public void onActivityCreated(Bundle savedInstanceState) {
65         mItemProvider = new ListItemProvider.ListProvider(getListItems());
66         // super.onActivityCreated() will need itemProvider, so call it after the provider
67         // is initialized.
68         super.onActivityCreated(savedInstanceState);
69     }
70 
71     @Override
getItemProvider()72     public ListItemProvider getItemProvider() {
73         return mItemProvider;
74     }
75 
getListItems()76     private ArrayList<ListItem> getListItems() {
77         ArrayList<ListItem> lineItems = new ArrayList<>();
78 
79         lineItems.add(createLanguageListItem());
80         lineItems.addAll(createSystemUpdateListItems());
81         lineItems.add(createAboutSystemListItem());
82         lineItems.add(createLegalInfoListItem());
83 
84         return lineItems;
85     }
86 
createLanguageListItem()87     private TextListItem createLanguageListItem() {
88         Context context = getContext();
89         TextListItem languageItem = new TextListItem(context);
90         languageItem.setTitle(context.getString(R.string.language_settings));
91         Locale locale = LanguagePickerUtils.getConfiguredLocale();
92         languageItem.setBody(LocaleHelper.getDisplayName(locale, locale, /* sentenceCase= */ true));
93         languageItem.setPrimaryActionIcon(
94                 R.drawable.ic_language, /* useLargeIcon= */ false);
95         languageItem.setSupplementalIcon(R.drawable.ic_chevron_right, /* showDivider= */ false);
96         languageItem.setOnClickListener(
97                 v -> getFragmentController().launchFragment(LanguagePickerFragment.newInstance()));
98         return languageItem;
99     }
100 
createSystemUpdateListItems()101     private Collection<ListItem> createSystemUpdateListItems() {
102         Collection<ListItem> collection = new ArrayList<>();
103         Context context = getContext();
104 
105         Intent settingsIntent = new Intent(ACTION_SYSTEM_UPDATE_SETTINGS);
106         PackageManager packageManager = context.getPackageManager();
107         if (settingsIntent.resolveActivity(packageManager) != null) {
108             collection.add(new SystemUpdatesListItem(context, settingsIntent));
109         }
110 
111         ExtraSettingsLoader extraSettingLoader = new ExtraSettingsLoader(context);
112         Map<String, Collection<ListItem>> extraSettings = extraSettingLoader.load();
113         collection.addAll(extraSettings.get(ExtraSettingsLoader.SYSTEM_CATEGORY));
114         return collection;
115     }
116 
createAboutSystemListItem()117     private TextListItem createAboutSystemListItem() {
118         Context context = getContext();
119         TextListItem aboutSystemItem = new TextListItem(context);
120         aboutSystemItem.setTitle(context.getString(R.string.about_settings));
121         aboutSystemItem.setBody(
122                 context.getString(R.string.about_summary, Build.VERSION.RELEASE));
123         aboutSystemItem.setPrimaryActionIcon(
124                 R.drawable.ic_settings_about, /* useLargeIcon= */ false);
125         aboutSystemItem.setSupplementalIcon(R.drawable.ic_chevron_right, /* showDivider= */ false);
126         aboutSystemItem.setOnClickListener(
127                 v -> getFragmentController().launchFragment(AboutSettingsFragment.getInstance()));
128         return aboutSystemItem;
129     }
130 
createLegalInfoListItem()131     private TextListItem createLegalInfoListItem() {
132         Context context = getContext();
133         TextListItem legalInfoItem = new TextListItem(context);
134         legalInfoItem.setTitle(context.getString(R.string.legal_information));
135         legalInfoItem.setPrimaryActionIcon(
136                 R.drawable.ic_settings_about, /* useLargeIcon= */ false);
137         legalInfoItem.setSupplementalIcon(R.drawable.ic_chevron_right, /* showDivider= */ false);
138         legalInfoItem.setOnClickListener(v -> {
139             Intent intent = new Intent();
140             intent.setAction(ACTION_SETTING_VIEW_LICENSE);
141             context.startActivity(intent);
142         });
143         return legalInfoItem;
144     }
145 }
146