1 /* 2 * Copyright (C) 2023 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.companiondevicemanager; 18 19 import static android.companion.AssociationRequest.DEVICE_PROFILE_APP_STREAMING; 20 import static android.companion.AssociationRequest.DEVICE_PROFILE_AUTOMOTIVE_PROJECTION; 21 import static android.companion.AssociationRequest.DEVICE_PROFILE_COMPUTER; 22 import static android.companion.AssociationRequest.DEVICE_PROFILE_GLASSES; 23 import static android.companion.AssociationRequest.DEVICE_PROFILE_NEARBY_DEVICE_STREAMING; 24 import static android.companion.AssociationRequest.DEVICE_PROFILE_WATCH; 25 import static android.os.Build.VERSION_CODES.UPSIDE_DOWN_CAKE; 26 27 import static java.util.Collections.unmodifiableMap; 28 import static java.util.Collections.unmodifiableSet; 29 30 import android.companion.virtual.flags.Flags; 31 import android.os.Build; 32 import android.util.ArrayMap; 33 import android.util.ArraySet; 34 35 import java.util.Arrays; 36 import java.util.Collections; 37 import java.util.List; 38 import java.util.Map; 39 import java.util.Set; 40 41 /** 42 * A class contains maps that have deviceProfile as the key and resourceId as the value 43 * for the corresponding profile. 44 */ 45 final class CompanionDeviceResources { 46 47 // Permission resources 48 private static final int PERMISSION_NOTIFICATION_LISTENER_ACCESS = 0; 49 private static final int PERMISSION_STORAGE = 1; 50 private static final int PERMISSION_APP_STREAMING = 2; 51 private static final int PERMISSION_PHONE = 3; 52 private static final int PERMISSION_SMS = 4; 53 private static final int PERMISSION_CONTACTS = 5; 54 private static final int PERMISSION_CALENDAR = 6; 55 private static final int PERMISSION_NEARBY_DEVICES = 7; 56 private static final int PERMISSION_NEARBY_DEVICE_STREAMING = 8; 57 private static final int PERMISSION_MICROPHONE = 9; 58 private static final int PERMISSION_CALL_LOGS = 10; 59 // Notification Listener Access & POST_NOTIFICATION permission 60 private static final int PERMISSION_NOTIFICATIONS = 11; 61 private static final int PERMISSION_CHANGE_MEDIA_OUTPUT = 12; 62 63 static final Map<Integer, Integer> PERMISSION_TITLES; 64 static { 65 final Map<Integer, Integer> map = new ArrayMap<>(); map.put(PERMISSION_NOTIFICATION_LISTENER_ACCESS, R.string.permission_notifications)66 map.put(PERMISSION_NOTIFICATION_LISTENER_ACCESS, R.string.permission_notifications); map.put(PERMISSION_STORAGE, R.string.permission_storage)67 map.put(PERMISSION_STORAGE, R.string.permission_storage); map.put(PERMISSION_APP_STREAMING, R.string.permission_app_streaming)68 map.put(PERMISSION_APP_STREAMING, R.string.permission_app_streaming); map.put(PERMISSION_PHONE, R.string.permission_phone)69 map.put(PERMISSION_PHONE, R.string.permission_phone); map.put(PERMISSION_SMS, R.string.permission_sms)70 map.put(PERMISSION_SMS, R.string.permission_sms); map.put(PERMISSION_CONTACTS, R.string.permission_contacts)71 map.put(PERMISSION_CONTACTS, R.string.permission_contacts); map.put(PERMISSION_CALENDAR, R.string.permission_calendar)72 map.put(PERMISSION_CALENDAR, R.string.permission_calendar); map.put(PERMISSION_NEARBY_DEVICES, R.string.permission_nearby_devices)73 map.put(PERMISSION_NEARBY_DEVICES, R.string.permission_nearby_devices); map.put(PERMISSION_NEARBY_DEVICE_STREAMING, R.string.permission_nearby_device_streaming)74 map.put(PERMISSION_NEARBY_DEVICE_STREAMING, R.string.permission_nearby_device_streaming); map.put(PERMISSION_MICROPHONE, R.string.permission_microphone)75 map.put(PERMISSION_MICROPHONE, R.string.permission_microphone); map.put(PERMISSION_CALL_LOGS, R.string.permission_call_logs)76 map.put(PERMISSION_CALL_LOGS, R.string.permission_call_logs); map.put(PERMISSION_NOTIFICATIONS, R.string.permission_notifications)77 map.put(PERMISSION_NOTIFICATIONS, R.string.permission_notifications); map.put(PERMISSION_CHANGE_MEDIA_OUTPUT, R.string.permission_media_routing_control)78 map.put(PERMISSION_CHANGE_MEDIA_OUTPUT, R.string.permission_media_routing_control); 79 PERMISSION_TITLES = unmodifiableMap(map); 80 } 81 82 static final Map<Integer, Integer> PERMISSION_SUMMARIES; 83 static { 84 final Map<Integer, Integer> map = new ArrayMap<>(); map.put(PERMISSION_NOTIFICATION_LISTENER_ACCESS, R.string.permission_notification_listener_access_summary)85 map.put(PERMISSION_NOTIFICATION_LISTENER_ACCESS, 86 R.string.permission_notification_listener_access_summary); map.put(PERMISSION_STORAGE, R.string.permission_storage_summary)87 map.put(PERMISSION_STORAGE, R.string.permission_storage_summary); map.put(PERMISSION_APP_STREAMING, R.string.permission_app_streaming_summary)88 map.put(PERMISSION_APP_STREAMING, R.string.permission_app_streaming_summary); map.put(PERMISSION_PHONE, R.string.permission_phone_summary)89 map.put(PERMISSION_PHONE, R.string.permission_phone_summary); map.put(PERMISSION_SMS, R.string.permission_sms_summary)90 map.put(PERMISSION_SMS, R.string.permission_sms_summary); map.put(PERMISSION_CONTACTS, R.string.permission_contacts_summary)91 map.put(PERMISSION_CONTACTS, R.string.permission_contacts_summary); map.put(PERMISSION_CALENDAR, R.string.permission_calendar_summary)92 map.put(PERMISSION_CALENDAR, R.string.permission_calendar_summary); map.put(PERMISSION_NEARBY_DEVICES, R.string.permission_nearby_devices_summary)93 map.put(PERMISSION_NEARBY_DEVICES, R.string.permission_nearby_devices_summary); map.put(PERMISSION_NEARBY_DEVICE_STREAMING, R.string.permission_nearby_device_streaming_summary)94 map.put(PERMISSION_NEARBY_DEVICE_STREAMING, 95 R.string.permission_nearby_device_streaming_summary); map.put(PERMISSION_MICROPHONE, R.string.permission_microphone_summary)96 map.put(PERMISSION_MICROPHONE, R.string.permission_microphone_summary); map.put(PERMISSION_CALL_LOGS, R.string.permission_call_logs_summary)97 map.put(PERMISSION_CALL_LOGS, R.string.permission_call_logs_summary); map.put(PERMISSION_NOTIFICATIONS, R.string.permission_notifications_summary)98 map.put(PERMISSION_NOTIFICATIONS, R.string.permission_notifications_summary); map.put(PERMISSION_CHANGE_MEDIA_OUTPUT, R.string.permission_media_routing_control_summary)99 map.put(PERMISSION_CHANGE_MEDIA_OUTPUT, R.string.permission_media_routing_control_summary); 100 PERMISSION_SUMMARIES = unmodifiableMap(map); 101 } 102 103 static final Map<Integer, Integer> PERMISSION_ICONS; 104 static { 105 final Map<Integer, Integer> map = new ArrayMap<>(); map.put(PERMISSION_NOTIFICATION_LISTENER_ACCESS, R.drawable.ic_permission_notifications)106 map.put(PERMISSION_NOTIFICATION_LISTENER_ACCESS, R.drawable.ic_permission_notifications); map.put(PERMISSION_STORAGE, R.drawable.ic_permission_storage)107 map.put(PERMISSION_STORAGE, R.drawable.ic_permission_storage); map.put(PERMISSION_APP_STREAMING, R.drawable.ic_permission_app_streaming)108 map.put(PERMISSION_APP_STREAMING, R.drawable.ic_permission_app_streaming); map.put(PERMISSION_PHONE, R.drawable.ic_permission_phone)109 map.put(PERMISSION_PHONE, R.drawable.ic_permission_phone); map.put(PERMISSION_SMS, R.drawable.ic_permission_sms)110 map.put(PERMISSION_SMS, R.drawable.ic_permission_sms); map.put(PERMISSION_CONTACTS, R.drawable.ic_permission_contacts)111 map.put(PERMISSION_CONTACTS, R.drawable.ic_permission_contacts); map.put(PERMISSION_CALENDAR, R.drawable.ic_permission_calendar)112 map.put(PERMISSION_CALENDAR, R.drawable.ic_permission_calendar); map.put(PERMISSION_NEARBY_DEVICES, R.drawable.ic_permission_nearby_devices)113 map.put(PERMISSION_NEARBY_DEVICES, R.drawable.ic_permission_nearby_devices); map.put(PERMISSION_NEARBY_DEVICE_STREAMING, R.drawable.ic_permission_nearby_device_streaming)114 map.put(PERMISSION_NEARBY_DEVICE_STREAMING, 115 R.drawable.ic_permission_nearby_device_streaming); map.put(PERMISSION_MICROPHONE, R.drawable.ic_permission_microphone)116 map.put(PERMISSION_MICROPHONE, R.drawable.ic_permission_microphone); map.put(PERMISSION_CALL_LOGS, R.drawable.ic_permission_call_logs)117 map.put(PERMISSION_CALL_LOGS, R.drawable.ic_permission_call_logs); map.put(PERMISSION_NOTIFICATIONS, R.drawable.ic_permission_notifications)118 map.put(PERMISSION_NOTIFICATIONS, R.drawable.ic_permission_notifications); map.put(PERMISSION_CHANGE_MEDIA_OUTPUT, R.drawable.ic_permission_media_routing_control)119 map.put(PERMISSION_CHANGE_MEDIA_OUTPUT, R.drawable.ic_permission_media_routing_control); 120 PERMISSION_ICONS = unmodifiableMap(map); 121 } 122 123 // Profile resources 124 static final Map<String, Integer> PROFILE_TITLES; 125 static { 126 final Map<String, Integer> map = new ArrayMap<>(); 127 if (Flags.interactiveScreenMirror()) { map.put(DEVICE_PROFILE_APP_STREAMING, R.string.title_app_streaming_with_mirroring)128 map.put(DEVICE_PROFILE_APP_STREAMING, R.string.title_app_streaming_with_mirroring); 129 } else { map.put(DEVICE_PROFILE_APP_STREAMING, R.string.title_app_streaming)130 map.put(DEVICE_PROFILE_APP_STREAMING, R.string.title_app_streaming); 131 } map.put(DEVICE_PROFILE_AUTOMOTIVE_PROJECTION, R.string.title_automotive_projection)132 map.put(DEVICE_PROFILE_AUTOMOTIVE_PROJECTION, R.string.title_automotive_projection); map.put(DEVICE_PROFILE_COMPUTER, R.string.title_computer)133 map.put(DEVICE_PROFILE_COMPUTER, R.string.title_computer); 134 if (Flags.interactiveScreenMirror()) { map.put(DEVICE_PROFILE_NEARBY_DEVICE_STREAMING, R.string.title_nearby_device_streaming_with_mirroring)135 map.put(DEVICE_PROFILE_NEARBY_DEVICE_STREAMING, 136 R.string.title_nearby_device_streaming_with_mirroring); 137 } else { map.put(DEVICE_PROFILE_NEARBY_DEVICE_STREAMING, R.string.title_nearby_device_streaming)138 map.put(DEVICE_PROFILE_NEARBY_DEVICE_STREAMING, R.string.title_nearby_device_streaming); 139 } map.put(DEVICE_PROFILE_WATCH, R.string.confirmation_title)140 map.put(DEVICE_PROFILE_WATCH, R.string.confirmation_title); map.put(DEVICE_PROFILE_GLASSES, R.string.confirmation_title_glasses)141 map.put(DEVICE_PROFILE_GLASSES, R.string.confirmation_title_glasses); map.put(null, R.string.confirmation_title)142 map.put(null, R.string.confirmation_title); 143 144 PROFILE_TITLES = unmodifiableMap(map); 145 } 146 147 static final Map<String, Integer> PROFILE_SUMMARIES; 148 static { 149 final Map<String, Integer> map = new ArrayMap<>(); map.put(DEVICE_PROFILE_WATCH, R.string.summary_watch)150 map.put(DEVICE_PROFILE_WATCH, R.string.summary_watch); map.put(DEVICE_PROFILE_GLASSES, R.string.summary_glasses)151 map.put(DEVICE_PROFILE_GLASSES, R.string.summary_glasses); 152 if (Flags.interactiveScreenMirror()) { map.put(DEVICE_PROFILE_APP_STREAMING, R.string.summary_app_streaming)153 map.put(DEVICE_PROFILE_APP_STREAMING, R.string.summary_app_streaming); map.put(DEVICE_PROFILE_NEARBY_DEVICE_STREAMING, R.string.summary_nearby_device_streaming)154 map.put(DEVICE_PROFILE_NEARBY_DEVICE_STREAMING, 155 R.string.summary_nearby_device_streaming); 156 } map.put(null, R.string.summary_generic)157 map.put(null, R.string.summary_generic); 158 159 PROFILE_SUMMARIES = unmodifiableMap(map); 160 } 161 162 static final Map<String, List<Integer>> PROFILE_PERMISSIONS; 163 static { 164 final Map<String, List<Integer>> map = new ArrayMap<>(); map.put(DEVICE_PROFILE_COMPUTER, Arrays.asList( PERMISSION_NOTIFICATION_LISTENER_ACCESS, PERMISSION_STORAGE))165 map.put(DEVICE_PROFILE_COMPUTER, Arrays.asList( 166 PERMISSION_NOTIFICATION_LISTENER_ACCESS, PERMISSION_STORAGE)); 167 if (Flags.interactiveScreenMirror()) { map.put(DEVICE_PROFILE_APP_STREAMING, Collections.emptyList())168 map.put(DEVICE_PROFILE_APP_STREAMING, Collections.emptyList()); map.put(DEVICE_PROFILE_NEARBY_DEVICE_STREAMING, Collections.emptyList())169 map.put(DEVICE_PROFILE_NEARBY_DEVICE_STREAMING, Collections.emptyList()); 170 } else { map.put(DEVICE_PROFILE_APP_STREAMING, Arrays.asList(PERMISSION_APP_STREAMING))171 map.put(DEVICE_PROFILE_APP_STREAMING, Arrays.asList(PERMISSION_APP_STREAMING)); map.put(DEVICE_PROFILE_NEARBY_DEVICE_STREAMING, Arrays.asList(PERMISSION_NEARBY_DEVICE_STREAMING))172 map.put(DEVICE_PROFILE_NEARBY_DEVICE_STREAMING, 173 Arrays.asList(PERMISSION_NEARBY_DEVICE_STREAMING)); 174 } 175 if (Build.VERSION.SDK_INT > UPSIDE_DOWN_CAKE) { map.put(DEVICE_PROFILE_WATCH, Arrays.asList(PERMISSION_NOTIFICATIONS, PERMISSION_PHONE, PERMISSION_CALL_LOGS, PERMISSION_SMS, PERMISSION_CONTACTS, PERMISSION_CALENDAR, PERMISSION_NEARBY_DEVICES, PERMISSION_CHANGE_MEDIA_OUTPUT))176 map.put(DEVICE_PROFILE_WATCH, Arrays.asList(PERMISSION_NOTIFICATIONS, PERMISSION_PHONE, 177 PERMISSION_CALL_LOGS, PERMISSION_SMS, PERMISSION_CONTACTS, PERMISSION_CALENDAR, 178 PERMISSION_NEARBY_DEVICES, PERMISSION_CHANGE_MEDIA_OUTPUT)); 179 } else { map.put(DEVICE_PROFILE_WATCH, Arrays.asList(PERMISSION_NOTIFICATION_LISTENER_ACCESS, PERMISSION_PHONE, PERMISSION_CALL_LOGS, PERMISSION_SMS, PERMISSION_CONTACTS, PERMISSION_CALENDAR, PERMISSION_NEARBY_DEVICES))180 map.put(DEVICE_PROFILE_WATCH, Arrays.asList(PERMISSION_NOTIFICATION_LISTENER_ACCESS, 181 PERMISSION_PHONE, PERMISSION_CALL_LOGS, PERMISSION_SMS, PERMISSION_CONTACTS, 182 PERMISSION_CALENDAR, PERMISSION_NEARBY_DEVICES)); 183 } map.put(DEVICE_PROFILE_GLASSES, Arrays.asList(PERMISSION_NOTIFICATION_LISTENER_ACCESS, PERMISSION_PHONE, PERMISSION_SMS, PERMISSION_CONTACTS, PERMISSION_MICROPHONE, PERMISSION_NEARBY_DEVICES))184 map.put(DEVICE_PROFILE_GLASSES, Arrays.asList(PERMISSION_NOTIFICATION_LISTENER_ACCESS, 185 PERMISSION_PHONE, PERMISSION_SMS, PERMISSION_CONTACTS, PERMISSION_MICROPHONE, 186 PERMISSION_NEARBY_DEVICES)); 187 188 PROFILE_PERMISSIONS = unmodifiableMap(map); 189 } 190 191 static final Map<String, Integer> PROFILE_NAMES; 192 static { 193 final Map<String, Integer> map = new ArrayMap<>(); map.put(DEVICE_PROFILE_WATCH, R.string.profile_name_watch)194 map.put(DEVICE_PROFILE_WATCH, R.string.profile_name_watch); map.put(DEVICE_PROFILE_GLASSES, R.string.profile_name_glasses)195 map.put(DEVICE_PROFILE_GLASSES, R.string.profile_name_glasses); map.put(null, R.string.profile_name_generic)196 map.put(null, R.string.profile_name_generic); 197 198 PROFILE_NAMES = unmodifiableMap(map); 199 } 200 201 static final Map<String, Integer> PROFILE_ICONS; 202 static { 203 final Map<String, Integer> map = new ArrayMap<>(); map.put(DEVICE_PROFILE_WATCH, R.drawable.ic_watch)204 map.put(DEVICE_PROFILE_WATCH, R.drawable.ic_watch); map.put(DEVICE_PROFILE_GLASSES, R.drawable.ic_glasses)205 map.put(DEVICE_PROFILE_GLASSES, R.drawable.ic_glasses); map.put(null, R.drawable.ic_device_other)206 map.put(null, R.drawable.ic_device_other); 207 208 PROFILE_ICONS = unmodifiableMap(map); 209 } 210 211 static final Set<String> SUPPORTED_PROFILES; 212 static { 213 final Set<String> set = new ArraySet<>(); 214 set.add(DEVICE_PROFILE_WATCH); 215 set.add(DEVICE_PROFILE_GLASSES); 216 set.add(null); 217 218 SUPPORTED_PROFILES = unmodifiableSet(set); 219 } 220 221 static final Set<String> SUPPORTED_SELF_MANAGED_PROFILES; 222 static { 223 final Set<String> set = new ArraySet<>(); 224 set.add(DEVICE_PROFILE_APP_STREAMING); 225 set.add(DEVICE_PROFILE_COMPUTER); 226 set.add(DEVICE_PROFILE_AUTOMOTIVE_PROJECTION); 227 set.add(DEVICE_PROFILE_NEARBY_DEVICE_STREAMING); 228 set.add(null); 229 230 SUPPORTED_SELF_MANAGED_PROFILES = unmodifiableSet(set); 231 } 232 } 233