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 package com.android.settings.dashboard;
18 
19 import android.util.ArrayMap;
20 
21 import com.android.settings.DisplaySettings;
22 import com.android.settings.LegalSettings;
23 import com.android.settings.accounts.AccountDashboardFragment;
24 import com.android.settings.accounts.AccountDetailDashboardFragment;
25 import com.android.settings.applications.AppDashboardFragment;
26 import com.android.settings.applications.specialaccess.SpecialAccessSettings;
27 import com.android.settings.communal.CommunalDashboardFragment;
28 import com.android.settings.connecteddevice.AdvancedConnectedDeviceDashboardFragment;
29 import com.android.settings.connecteddevice.ConnectedDeviceDashboardFragment;
30 import com.android.settings.development.DevelopmentSettingsDashboardFragment;
31 import com.android.settings.deviceinfo.StorageDashboardFragment;
32 import com.android.settings.deviceinfo.aboutphone.MyDeviceInfoFragment;
33 import com.android.settings.display.NightDisplaySettings;
34 import com.android.settings.emergency.EmergencyDashboardFragment;
35 import com.android.settings.enterprise.EnterprisePrivacySettings;
36 import com.android.settings.fuelgauge.SmartBatterySettings;
37 import com.android.settings.fuelgauge.batterysaver.BatterySaverSettings;
38 import com.android.settings.fuelgauge.batteryusage.PowerUsageSummary;
39 import com.android.settings.gestures.GestureSettings;
40 import com.android.settings.homepage.TopLevelSettings;
41 import com.android.settings.network.NetworkDashboardFragment;
42 import com.android.settings.notification.ConfigureNotificationSettings;
43 import com.android.settings.notification.SoundSettings;
44 import com.android.settings.notification.zen.ZenModeSettings;
45 import com.android.settings.privacy.PrivacyDashboardFragment;
46 import com.android.settings.safetycenter.MoreSecurityPrivacyFragment;
47 import com.android.settings.security.LockscreenDashboardFragment;
48 import com.android.settings.security.SecurityAdvancedSettings;
49 import com.android.settings.security.SecuritySettings;
50 import com.android.settings.system.SystemDashboardFragment;
51 import com.android.settingslib.drawer.CategoryKey;
52 
53 import java.util.Map;
54 
55 /**
56  * A registry to keep track of which page hosts which category.
57  */
58 public class DashboardFragmentRegistry {
59 
60     /**
61      * Map from parent fragment to category key. The parent fragment hosts child with
62      * category_key.
63      */
64     public static final Map<String, String> PARENT_TO_CATEGORY_KEY_MAP;
65 
66     /**
67      * Map from category_key to parent. This is a helper to look up which fragment hosts the
68      * category_key.
69      */
70     public static final Map<String, String> CATEGORY_KEY_TO_PARENT_MAP;
71 
72     static {
73         PARENT_TO_CATEGORY_KEY_MAP = new ArrayMap<>();
TopLevelSettings.class.getName()74         PARENT_TO_CATEGORY_KEY_MAP.put(TopLevelSettings.class.getName(),
75                 CategoryKey.CATEGORY_HOMEPAGE);
76         PARENT_TO_CATEGORY_KEY_MAP.put(
NetworkDashboardFragment.class.getName()77                 NetworkDashboardFragment.class.getName(), CategoryKey.CATEGORY_NETWORK);
ConnectedDeviceDashboardFragment.class.getName()78         PARENT_TO_CATEGORY_KEY_MAP.put(ConnectedDeviceDashboardFragment.class.getName(),
79                 CategoryKey.CATEGORY_CONNECT);
AdvancedConnectedDeviceDashboardFragment.class.getName()80         PARENT_TO_CATEGORY_KEY_MAP.put(AdvancedConnectedDeviceDashboardFragment.class.getName(),
81                 CategoryKey.CATEGORY_DEVICE);
AppDashboardFragment.class.getName()82         PARENT_TO_CATEGORY_KEY_MAP.put(AppDashboardFragment.class.getName(),
83                 CategoryKey.CATEGORY_APPS);
PowerUsageSummary.class.getName()84         PARENT_TO_CATEGORY_KEY_MAP.put(PowerUsageSummary.class.getName(),
85                 CategoryKey.CATEGORY_BATTERY);
DisplaySettings.class.getName()86         PARENT_TO_CATEGORY_KEY_MAP.put(DisplaySettings.class.getName(),
87                 CategoryKey.CATEGORY_DISPLAY);
EmergencyDashboardFragment.class.getName()88         PARENT_TO_CATEGORY_KEY_MAP.put(EmergencyDashboardFragment.class.getName(),
89                 CategoryKey.CATEGORY_EMERGENCY);
SoundSettings.class.getName()90         PARENT_TO_CATEGORY_KEY_MAP.put(SoundSettings.class.getName(),
91                 CategoryKey.CATEGORY_SOUND);
StorageDashboardFragment.class.getName()92         PARENT_TO_CATEGORY_KEY_MAP.put(StorageDashboardFragment.class.getName(),
93                 CategoryKey.CATEGORY_STORAGE);
SecuritySettings.class.getName()94         PARENT_TO_CATEGORY_KEY_MAP.put(SecuritySettings.class.getName(),
95                 CategoryKey.CATEGORY_SECURITY);
SecurityAdvancedSettings.class.getName()96         PARENT_TO_CATEGORY_KEY_MAP.put(SecurityAdvancedSettings.class.getName(),
97                 CategoryKey.CATEGORY_SECURITY_ADVANCED_SETTINGS);
AccountDetailDashboardFragment.class.getName()98         PARENT_TO_CATEGORY_KEY_MAP.put(AccountDetailDashboardFragment.class.getName(),
99                 CategoryKey.CATEGORY_ACCOUNT_DETAIL);
AccountDashboardFragment.class.getName()100         PARENT_TO_CATEGORY_KEY_MAP.put(AccountDashboardFragment.class.getName(),
101                 CategoryKey.CATEGORY_ACCOUNT);
102         PARENT_TO_CATEGORY_KEY_MAP.put(
SystemDashboardFragment.class.getName()103                 SystemDashboardFragment.class.getName(), CategoryKey.CATEGORY_SYSTEM);
104         // TODO(b/242680328) Tie new category key to LanguageSettings and KeyboardSettings page
DevelopmentSettingsDashboardFragment.class.getName()105         PARENT_TO_CATEGORY_KEY_MAP.put(DevelopmentSettingsDashboardFragment.class.getName(),
106                 CategoryKey.CATEGORY_SYSTEM_DEVELOPMENT);
ConfigureNotificationSettings.class.getName()107         PARENT_TO_CATEGORY_KEY_MAP.put(ConfigureNotificationSettings.class.getName(),
108                 CategoryKey.CATEGORY_NOTIFICATIONS);
LockscreenDashboardFragment.class.getName()109         PARENT_TO_CATEGORY_KEY_MAP.put(LockscreenDashboardFragment.class.getName(),
110                 CategoryKey.CATEGORY_SECURITY_LOCKSCREEN);
ZenModeSettings.class.getName()111         PARENT_TO_CATEGORY_KEY_MAP.put(ZenModeSettings.class.getName(),
112                 CategoryKey.CATEGORY_DO_NOT_DISTURB);
GestureSettings.class.getName()113         PARENT_TO_CATEGORY_KEY_MAP.put(GestureSettings.class.getName(),
114                 CategoryKey.CATEGORY_GESTURES);
NightDisplaySettings.class.getName()115         PARENT_TO_CATEGORY_KEY_MAP.put(NightDisplaySettings.class.getName(),
116                 CategoryKey.CATEGORY_NIGHT_DISPLAY);
PrivacyDashboardFragment.class.getName()117         PARENT_TO_CATEGORY_KEY_MAP.put(PrivacyDashboardFragment.class.getName(),
118                 CategoryKey.CATEGORY_PRIVACY);
EnterprisePrivacySettings.class.getName()119         PARENT_TO_CATEGORY_KEY_MAP.put(EnterprisePrivacySettings.class.getName(),
120                 CategoryKey.CATEGORY_ENTERPRISE_PRIVACY);
LegalSettings.class.getName()121         PARENT_TO_CATEGORY_KEY_MAP.put(LegalSettings.class.getName(),
122                 CategoryKey.CATEGORY_ABOUT_LEGAL);
MyDeviceInfoFragment.class.getName()123         PARENT_TO_CATEGORY_KEY_MAP.put(MyDeviceInfoFragment.class.getName(),
124                 CategoryKey.CATEGORY_MY_DEVICE_INFO);
BatterySaverSettings.class.getName()125         PARENT_TO_CATEGORY_KEY_MAP.put(BatterySaverSettings.class.getName(),
126                 CategoryKey.CATEGORY_BATTERY_SAVER_SETTINGS);
SmartBatterySettings.class.getName()127         PARENT_TO_CATEGORY_KEY_MAP.put(SmartBatterySettings.class.getName(),
128                 CategoryKey.CATEGORY_SMART_BATTERY_SETTINGS);
CommunalDashboardFragment.class.getName()129         PARENT_TO_CATEGORY_KEY_MAP.put(CommunalDashboardFragment.class.getName(),
130                 CategoryKey.CATEGORY_COMMUNAL_SETTINGS);
SpecialAccessSettings.class.getName()131         PARENT_TO_CATEGORY_KEY_MAP.put(SpecialAccessSettings.class.getName(),
132                 CategoryKey.CATEGORY_SPECIAL_APP_ACCESS);
MoreSecurityPrivacyFragment.class.getName()133         PARENT_TO_CATEGORY_KEY_MAP.put(MoreSecurityPrivacyFragment.class.getName(),
134                 CategoryKey.CATEGORY_MORE_SECURITY_PRIVACY_SETTINGS);
135 
136         CATEGORY_KEY_TO_PARENT_MAP = new ArrayMap<>(PARENT_TO_CATEGORY_KEY_MAP.size());
137 
138         for (Map.Entry<String, String> parentToKey : PARENT_TO_CATEGORY_KEY_MAP.entrySet()) {
parentToKey.getKey()139             CATEGORY_KEY_TO_PARENT_MAP.put(parentToKey.getValue(), parentToKey.getKey());
140         }
141 
142         // For injection index, redirect CATEGORY_ACCOUNT_DETAIL to AccountDashboardFragment.
CATEGORY_KEY_TO_PARENT_MAP.put(CategoryKey.CATEGORY_ACCOUNT_DETAIL, AccountDashboardFragment.class.getName())143         CATEGORY_KEY_TO_PARENT_MAP.put(CategoryKey.CATEGORY_ACCOUNT_DETAIL,
144                 AccountDashboardFragment.class.getName());
145     }
146 }
147