1 /* 2 * Copyright (C) 2021 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.qc; 18 19 import android.content.ContentResolver; 20 import android.net.Uri; 21 import android.util.ArrayMap; 22 23 import androidx.annotation.VisibleForTesting; 24 25 import java.util.Map; 26 27 /** 28 * Registry of valid Quick Control Uris provided by CarSettings. 29 */ 30 public class SettingsQCRegistry { 31 public static final String AUTHORITY = "com.android.car.settings.qc"; 32 33 // Start Uris 34 public static final Uri BLUETOOTH_SWITCH_URI = new Uri.Builder() 35 .scheme(ContentResolver.SCHEME_CONTENT) 36 .authority(AUTHORITY) 37 .appendPath("bluetooth_switch") 38 .build(); 39 40 public static final Uri PAIRED_BLUETOOTH_DEVICES_URI = new Uri.Builder() 41 .scheme(ContentResolver.SCHEME_CONTENT) 42 .authority(AUTHORITY) 43 .appendPath("paired_bluetooth_devices") 44 .build(); 45 46 public static final Uri WIFI_TILE_URI = new Uri.Builder() 47 .scheme(ContentResolver.SCHEME_CONTENT) 48 .authority(AUTHORITY) 49 .appendPath("wifi_tile") 50 .build(); 51 52 public static final Uri HOTSPOT_TILE_URI = new Uri.Builder() 53 .scheme(ContentResolver.SCHEME_CONTENT) 54 .authority(AUTHORITY) 55 .appendPath("hotspot_tile") 56 .build(); 57 58 public static final Uri MOBILE_DATA_TILE_URI = new Uri.Builder() 59 .scheme(ContentResolver.SCHEME_CONTENT) 60 .authority(AUTHORITY) 61 .appendPath("mobile_data_tile") 62 .build(); 63 64 public static final Uri WIFI_ROW_URI = new Uri.Builder() 65 .scheme(ContentResolver.SCHEME_CONTENT) 66 .authority(AUTHORITY) 67 .appendPath("wifi_row") 68 .build(); 69 70 public static final Uri HOTSPOT_ROW_URI = new Uri.Builder() 71 .scheme(ContentResolver.SCHEME_CONTENT) 72 .authority(AUTHORITY) 73 .appendPath("hotspot_row") 74 .build(); 75 76 public static final Uri HOTSPOT_ROW_WITH_ACTION_URI = new Uri.Builder() 77 .scheme(ContentResolver.SCHEME_CONTENT) 78 .authority(AUTHORITY) 79 .appendPath("hotspot_row_with_action") 80 .build(); 81 82 public static final Uri MOBILE_DATA_ROW_URI = new Uri.Builder() 83 .scheme(ContentResolver.SCHEME_CONTENT) 84 .authority(AUTHORITY) 85 .appendPath("mobile_data_row") 86 .build(); 87 88 public static final Uri BRIGHTNESS_SLIDER_URI = new Uri.Builder() 89 .scheme(ContentResolver.SCHEME_CONTENT) 90 .authority(AUTHORITY) 91 .appendPath("brightness_slider") 92 .build(); 93 94 public static final Uri BRIGHTNESS_SLIDER_WITH_ICON_URI = new Uri.Builder() 95 .scheme(ContentResolver.SCHEME_CONTENT) 96 .authority(AUTHORITY) 97 .appendPath("brightness_slider_with_icon") 98 .build(); 99 100 public static final Uri ADAPTIVE_BRIGHTNESS_SWITCH_URI = new Uri.Builder() 101 .scheme(ContentResolver.SCHEME_CONTENT) 102 .authority(AUTHORITY) 103 .appendPath("adaptive_brightness_switch") 104 .build(); 105 106 public static final Uri THEME_TOGGLE_URI = new Uri.Builder() 107 .scheme(ContentResolver.SCHEME_CONTENT) 108 .authority(AUTHORITY) 109 .appendPath("theme_toggle") 110 .build(); 111 112 public static final Uri MEDIA_AUDIO_SELECTOR_URI = new Uri.Builder() 113 .scheme(ContentResolver.SCHEME_CONTENT) 114 .authority(AUTHORITY) 115 .appendPath("media_audio_selector") 116 .build(); 117 118 public static final Uri MEDIA_VOLUME_SLIDER_URI = new Uri.Builder() 119 .scheme(ContentResolver.SCHEME_CONTENT) 120 .authority(AUTHORITY) 121 .appendPath("media_volume_slider") 122 .build(); 123 124 public static final Uri MEDIA_VOLUME_SLIDER_WITHOUT_ICON_URI = new Uri.Builder() 125 .scheme(ContentResolver.SCHEME_CONTENT) 126 .authority(AUTHORITY) 127 .appendPath("media_volume_slider_without_icon") 128 .build(); 129 130 public static final Uri CALL_VOLUME_SLIDER_URI = new Uri.Builder() 131 .scheme(ContentResolver.SCHEME_CONTENT) 132 .authority(AUTHORITY) 133 .appendPath("call_volume_slider") 134 .build(); 135 136 public static final Uri NAVIGATION_VOLUME_SLIDER_URI = new Uri.Builder() 137 .scheme(ContentResolver.SCHEME_CONTENT) 138 .authority(AUTHORITY) 139 .appendPath("navigation_volume_slider") 140 .build(); 141 public static final Uri DEBUG_DRIVING_MODE_URI = new Uri.Builder() 142 .scheme(ContentResolver.SCHEME_CONTENT) 143 .authority(AUTHORITY) 144 .appendPath("debug_driving_mode_toggle") 145 .build(); 146 public static final Uri DEBUG_LAYOUT_BOUNDS_URI = new Uri.Builder() 147 .scheme(ContentResolver.SCHEME_CONTENT) 148 .authority(AUTHORITY) 149 .appendPath("debug_layout_bounds_toggle") 150 .build(); 151 152 public static final Uri DEBUG_FORCE_RTL_URI = new Uri.Builder() 153 .scheme(ContentResolver.SCHEME_CONTENT) 154 .authority(AUTHORITY) 155 .appendPath("debug_force_rtl_toggle") 156 .build(); 157 158 public static final Uri DEBUG_CUSTOMIZATION_OVERLAY_URI = new Uri.Builder() 159 .scheme(ContentResolver.SCHEME_CONTENT) 160 .authority(AUTHORITY) 161 .appendPath("debug_customization_overlay_toggle") 162 .build(); 163 164 // End Uris 165 166 @VisibleForTesting 167 static final Map<Uri, Class<? extends SettingsQCItem>> sUriToQC = createUriToQCMap(); 168 createUriToQCMap()169 private static Map<Uri, Class<? extends SettingsQCItem>> createUriToQCMap() { 170 Map<Uri, Class<? extends SettingsQCItem>> map = new ArrayMap<>(); 171 172 map.put(BLUETOOTH_SWITCH_URI, BluetoothSwitch.class); 173 map.put(PAIRED_BLUETOOTH_DEVICES_URI, PairedBluetoothDevices.class); 174 map.put(WIFI_TILE_URI, WifiTile.class); 175 map.put(HOTSPOT_TILE_URI, HotspotTile.class); 176 map.put(MOBILE_DATA_TILE_URI, MobileDataTile.class); 177 map.put(WIFI_ROW_URI, WifiRow.class); 178 map.put(HOTSPOT_ROW_URI, HotspotRow.class); 179 map.put(HOTSPOT_ROW_WITH_ACTION_URI, HotspotRowWithAction.class); 180 map.put(MOBILE_DATA_ROW_URI, MobileDataRow.class); 181 map.put(BRIGHTNESS_SLIDER_URI, BrightnessSlider.class); 182 map.put(BRIGHTNESS_SLIDER_WITH_ICON_URI, BrightnessSliderWithIcon.class); 183 map.put(ADAPTIVE_BRIGHTNESS_SWITCH_URI, AdaptiveBrightnessSwitch.class); 184 map.put(THEME_TOGGLE_URI, ThemeToggle.class); 185 map.put(MEDIA_AUDIO_SELECTOR_URI, MediaAudioSelectorRow.class); 186 map.put(MEDIA_VOLUME_SLIDER_URI, MediaVolumeSlider.class); 187 map.put(MEDIA_VOLUME_SLIDER_WITHOUT_ICON_URI, MediaVolumeSliderWithoutIcon.class); 188 map.put(CALL_VOLUME_SLIDER_URI, CallVolumeSlider.class); 189 map.put(NAVIGATION_VOLUME_SLIDER_URI, NavigationVolumeSlider.class); 190 map.put(DEBUG_DRIVING_MODE_URI, DebugDriveModeRow.class); 191 map.put(DEBUG_LAYOUT_BOUNDS_URI, DebugLayoutBoundsRow.class); 192 map.put(DEBUG_FORCE_RTL_URI, DebugForceRTLRow.class); 193 map.put(DEBUG_CUSTOMIZATION_OVERLAY_URI, DebugCustomizationOverlayRow.class); 194 195 return map; 196 } 197 198 /** 199 * Returns the relevant {@link SettingsQCItem} class that corresponds to the provided uri. 200 */ getQCClassByUri(Uri uri)201 public static Class<? extends SettingsQCItem> getQCClassByUri(Uri uri) { 202 return sUriToQC.get(removeParameterFromUri(uri)); 203 } 204 205 /** 206 * Returns a uri without its parameters (or null if the provided uri is null). 207 */ removeParameterFromUri(Uri uri)208 public static Uri removeParameterFromUri(Uri uri) { 209 return uri != null ? uri.buildUpon().clearQuery().build() : null; 210 } 211 212 /** 213 * Returns {@code true} if the provided uri is a valid QCItem Uri handled by 214 * {@link SettingsQCRegistry}. 215 */ isValidUri(Uri uri)216 public static boolean isValidUri(Uri uri) { 217 return sUriToQC.containsKey(removeParameterFromUri(uri)); 218 } 219 220 /** 221 * Returns {@code true} if the provided action is a valid intent action handled by 222 * {@link SettingsQCRegistry}. 223 */ isValidAction(String action)224 public static boolean isValidAction(String action) { 225 return isValidUri(Uri.parse(action)); 226 } 227 } 228