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 MEDIA_VOLUME_SLIDER_URI = new Uri.Builder() 107 .scheme(ContentResolver.SCHEME_CONTENT) 108 .authority(AUTHORITY) 109 .appendPath("media_volume_slider") 110 .build(); 111 112 public static final Uri MEDIA_VOLUME_SLIDER_WITHOUT_ICON_URI = new Uri.Builder() 113 .scheme(ContentResolver.SCHEME_CONTENT) 114 .authority(AUTHORITY) 115 .appendPath("media_volume_slider_without_icon") 116 .build(); 117 118 public static final Uri CALL_VOLUME_SLIDER_URI = new Uri.Builder() 119 .scheme(ContentResolver.SCHEME_CONTENT) 120 .authority(AUTHORITY) 121 .appendPath("call_volume_slider") 122 .build(); 123 124 public static final Uri NAVIGATION_VOLUME_SLIDER_URI = new Uri.Builder() 125 .scheme(ContentResolver.SCHEME_CONTENT) 126 .authority(AUTHORITY) 127 .appendPath("navigation_volume_slider") 128 .build(); 129 // End Uris 130 131 @VisibleForTesting 132 static final Map<Uri, Class<? extends SettingsQCItem>> sUriToQC = createUriToQCMap(); 133 createUriToQCMap()134 private static Map<Uri, Class<? extends SettingsQCItem>> createUriToQCMap() { 135 Map<Uri, Class<? extends SettingsQCItem>> map = new ArrayMap<>(); 136 137 map.put(BLUETOOTH_SWITCH_URI, BluetoothSwitch.class); 138 map.put(PAIRED_BLUETOOTH_DEVICES_URI, PairedBluetoothDevices.class); 139 map.put(WIFI_TILE_URI, WifiTile.class); 140 map.put(HOTSPOT_TILE_URI, HotspotTile.class); 141 map.put(MOBILE_DATA_TILE_URI, MobileDataTile.class); 142 map.put(WIFI_ROW_URI, WifiRow.class); 143 map.put(HOTSPOT_ROW_URI, HotspotRow.class); 144 map.put(HOTSPOT_ROW_WITH_ACTION_URI, HotspotRowWithAction.class); 145 map.put(MOBILE_DATA_ROW_URI, MobileDataRow.class); 146 map.put(BRIGHTNESS_SLIDER_URI, BrightnessSlider.class); 147 map.put(BRIGHTNESS_SLIDER_WITH_ICON_URI, BrightnessSliderWithIcon.class); 148 map.put(ADAPTIVE_BRIGHTNESS_SWITCH_URI, AdaptiveBrightnessSwitch.class); 149 map.put(MEDIA_VOLUME_SLIDER_URI, MediaVolumeSlider.class); 150 map.put(MEDIA_VOLUME_SLIDER_WITHOUT_ICON_URI, MediaVolumeSliderWithoutIcon.class); 151 map.put(CALL_VOLUME_SLIDER_URI, CallVolumeSlider.class); 152 map.put(NAVIGATION_VOLUME_SLIDER_URI, NavigationVolumeSlider.class); 153 154 return map; 155 } 156 157 /** 158 * Returns the relevant {@link SettingsQCItem} class that corresponds to the provided uri. 159 */ getQCClassByUri(Uri uri)160 public static Class<? extends SettingsQCItem> getQCClassByUri(Uri uri) { 161 return sUriToQC.get(removeParameterFromUri(uri)); 162 } 163 164 /** 165 * Returns a uri without its parameters (or null if the provided uri is null). 166 */ removeParameterFromUri(Uri uri)167 public static Uri removeParameterFromUri(Uri uri) { 168 return uri != null ? uri.buildUpon().clearQuery().build() : null; 169 } 170 171 /** 172 * Returns {@code true} if the provided uri is a valid QCItem Uri handled by 173 * {@link SettingsQCRegistry}. 174 */ isValidUri(Uri uri)175 public static boolean isValidUri(Uri uri) { 176 return sUriToQC.containsKey(removeParameterFromUri(uri)); 177 } 178 179 /** 180 * Returns {@code true} if the provided action is a valid intent action handled by 181 * {@link SettingsQCRegistry}. 182 */ isValidAction(String action)183 public static boolean isValidAction(String action) { 184 return isValidUri(Uri.parse(action)); 185 } 186 } 187